#!/usr/bin/perl # uidentd 1.2.1 - an auth/ident server implementing most of RFC 1413 # # Copyright (C) 2002-2006 Amir Malik # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # For more information, see: http://www.unoc.net/a/uidentd/ # # ChangeLog # - 1.0 initial release of IPv6-only version # - 1.1 added IPv4 and multiple query support # - 1.2 update header # - 1.2.1 send CRLFs as per RFC; thanks to Thomas Zehetbauer my $MAXQUERIES = 5; # max queries per connection my $MAXTIME = 10; # max seconds per connection $SIG{'ALRM'} = sub { exit }; alarm($MAXTIME); # die on blocking sockets $| = 1; my($port1,$port2); my $i; while() { $i++; chomp(my $line = $_); $line =~ s/\s//g; ($port1,$port2) = split(/,/,$line); if(!$port1 || !$port2) { print "$port1 , $port2 : ERROR : UNKNOWN-ERROR\r\n"; exit; } my $unam = getports("tcp6"); # ipv6 check if($unam) { print "$port1 , $port2 : USERID : UNIX : $unam\r\n"; } else { $unam = getports("tcp"); # ipv4 check if($unam) { print "$port1 , $port2 : USERID : UNIX : $unam\r\n"; } else { print "$port1 , $port2 : ERROR : UNKNOWN-ERROR\r\n"; } } if($i >= $MAXQUERIES) { exit; } } sub getports { my($file) = $_[0]; open(PROC_TCP,") { my($laddr,$lport,$raddr,$rport,$uid) = $proc_tcp =~ /^\s*\S+\: (\S+)\:(\S+)\s+(\S+)\:(\S+)\s+\S+\s+\S+\:\S+\s+\S+\:\S+\s+\S+\s+(\S+)/; $lport = hex($lport); $rport = hex($rport); if($port1 == $lport && $port2 == $rport) { ($unam) = getpwuid($uid); } } close(PROC_TCP); return $unam; }