#!/usr/bin/perl
# You'll need to add this line to /etc/inetd.conf
# ident	stream	tcp	nowait	nobody	/usr/local/irc/identd.pl  identd.pl
use strict;
use Socket;

# Path to ident file created by CGI:IRC
my $identfile="/path/";
# Your real identd program (this still needs some work...)
my $identprog="/usr/sbin/identd";

my($in,$local,$remote,$userid);
sysread(STDIN,$in,128);
($local,$remote)=split(/[\,\r\n{*}]/,$in);
if(!($remote =~ /^([ \d])+$/)) { $remote=0; }
if(!($local =~ /^([ \d])+$/)) { $local=0; }
if($remote<1 || $remote>65535 || $local<1 || $local>65535) {
   ret("$local,$remote : ERROR : INVALID-PORT")
}

open(IDENTD, "$identfile");
while(<IDENTD>){
   my ($a,$b,$c)=split(/:/,$_,3);
   if($a eq $local and $b eq $remote){
	  ret("$local, $remote : USERID : UNIX : $c");
   }
}
close(IDENTD);

exec("$identprog") or ret("$local,$remote : ERROR : NO-USER");

sub ret{
   print shift,"\r\n";
   exit
}

