2 # $Id: ud-fingerserv,v 1.3 1999/10/14 04:28:59 tausq Exp $
4 # (c) 1999 Randolph Chung. Licensed under the GPL. <tausq@debian.org>
10 use POSIX qw(:sys_wait_h);
12 use Net::LDAP qw(:all);
15 my %config = &Util::ReadConfigFile;
19 'mn' => 'Middle name',
21 'keyfingerprint' => 'Fingerprint',
23 'ircnick' => 'IRC nickname'
26 my @summarykeys = ('cn', 'mn', 'sn', 'ircnick', 'keyfingerprint', 'key');
28 my ($ldap, $mesg, $dn, $entries, $data, %output, $key, $hostlist, $hostdetails, $selected, %summary);
30 $ldap->unbind if (defined($ldap));
34 1 until (-1 == waitpid(-1, WNOHANG));
35 $SIG{CHLD} = \&Reaper;
38 $SIG{__DIE__} = \&DieHandler;
39 $SIG{CHLD} = \&Reaper;
41 $ldap = Net::LDAP->new($config{ldaphost}) || &Util::HTMLError($!);
45 my $server = IO::Socket::INET->new(Proto => 'tcp',
46 LocalPort => 'finger(79)',
50 die "Cannot listen on finger port" unless $server;
51 print "[Server listening for connections]\n";
53 my ($mesg, %entries, $dn, $key, $pid);
56 while ($client = $server->accept()) {
57 next if $pid = fork; # parent
58 die "fork: $!" unless defined $pid;
61 $client->autoflush(1);
62 my $hostinfo = gethostbyaddr($client->peeraddr, AF_INET);
63 printf "[Connect from %s]\n", $hostinfo || $client->peerhost;
64 my $query = <$client>;
65 $query =~ s/[^\/,0-9a-z]//gi; # be paranoid about input
66 my ($uid, $fields) = split(/\//, $query, 2);
68 # print "Looking up $uid at $config{basedn}, uid=$uid\n";
70 $mesg = $ldap->search(base => $config{basedn}, filter => "uid=$uid");
71 $mesg->code && die $mesg->error;
72 $entries = $mesg->as_struct;
74 foreach $dn (sort {$entries->{$a}->{sn}->[0] <=> $entries->{$b}->{sn}->[0]} keys(%$entries)) {
75 $data = $entries->{$dn};
78 foreach (@{$data->{keyfingerprint}}) {
79 push (@{$data->{key}}, "\n".&Util::FetchKey($_));
82 print $client "$dn\n";
84 foreach $key (@summarykeys) {
85 foreach (@{$data->{$key}}) {
86 print $client "$attrs{$key}: ";
92 foreach $key (split(/,/, $fields)) {
93 foreach (@{$data->{$key}}) {
94 print $client "$attrs{$key}: ";