#!/usr/bin/perl
-# $Id: ud-fingerserv,v 1.2 1999/10/05 02:54:29 tausq Exp $
+# $Id: ud-fingerserv,v 1.3 1999/10/14 04:28:59 tausq Exp $
# (c) 1999 Randolph Chung. Licensed under the GPL. <tausq@debian.org>
use strict vars;
#use Apache::Registry;
use IO::Socket;
+use POSIX qw(:sys_wait_h);
use Util;
use Net::LDAP qw(:all);
$ldap->unbind if (defined($ldap));
}
+sub Reaper {
+ 1 until (-1 == waitpid(-1, WNOHANG));
+ $SIG{CHLD} = \&Reaper;
+}
+
$SIG{__DIE__} = \&DieHandler;
+$SIG{CHLD} = \&Reaper;
$ldap = Net::LDAP->new($config{ldaphost}) || &Util::HTMLError($!);
$mesg;
die "Cannot listen on finger port" unless $server;
print "[Server listening for connections]\n";
-my ($mesg, %entries, $dn, $key);
+my ($mesg, %entries, $dn, $key, $pid);
my $client;
while ($client = $server->accept()) {
+ next if $pid = fork; # parent
+ die "fork: $!" unless defined $pid;
+
+ # child
$client->autoflush(1);
my $hostinfo = gethostbyaddr($client->peeraddr, AF_INET);
printf "[Connect from %s]\n", $hostinfo || $client->peerhost;
$query =~ s/[^\/,0-9a-z]//gi; # be paranoid about input
my ($uid, $fields) = split(/\//, $query, 2);
- print "Looking up $uid at $config{basedn}, uid=$uid\n";
+# print "Looking up $uid at $config{basedn}, uid=$uid\n";
$mesg = $ldap->search(base => $config{basedn}, filter => "uid=$uid");
$mesg->code && die $mesg->error;
}
}
$client->close;
+ exit;
+} continue {
+ $client->close;
}
$ldap->unbind;