2 # $Id: ud-fingerserv,v 1.1 1999/10/04 06:51:45 tausq Exp $
4 # (c) 1999 Randolph Chung. Licensed under the GPL. <tausq@debian.org>
11 use Net::LDAP qw(:all);
14 my %config = &Util::ReadConfigFile;
18 'mn' => 'Middle name',
20 'keyfingerprint' => 'Fingerprint'
23 my @summarykeys = ('cn', 'mn', 'sn', 'keyfingerprint');
25 my ($ldap, $mesg, $dn, $entries, $data, %output, $key, $hostlist, $hostdetails, $selected, %summary);
27 $ldap->unbind if (defined($ldap));
30 $SIG{__DIE__} = \&DieHandler;
32 $ldap = Net::LDAP->new($config{ldaphost}) || &Util::HTMLError($!);
36 my $server = IO::Socket::INET->new(Proto => 'tcp',
37 LocalPort => 'finger(79)',
41 die "Cannot listen on finger port" unless $server;
42 print "[Server listening for connections]\n";
44 my ($mesg, %entries, $dn, $key);
47 while ($client = $server->accept()) {
48 $client->autoflush(1);
49 my $hostinfo = gethostbyaddr($client->peeraddr, AF_INET);
50 printf "[Connect from %s]\n", $hostinfo || $client->peerhost;
51 my $query = <$client>;
52 $query =~ s/[^\/,0-9a-z]//gi; # be paranoid about input
53 my ($uid, $fields) = split(/\//, $query, 2);
55 print "Looking up $uid at $config{basedn}, uid=$uid\n";
57 $mesg = $ldap->search(base => $config{basedn}, filter => "uid=$uid");
58 $mesg->code && die $mesg->error;
59 $entries = $mesg->as_struct;
61 foreach $dn (sort {$entries->{$a}->{sn}->[0] <=> $entries->{$b}->{sn}->[0]} keys(%$entries)) {
62 $data = $entries->{$dn};
65 foreach $key (@summarykeys) {
66 foreach (@{$data->{$key}}) {
67 print $client "$attrs{$key}: ";
73 foreach $key (split(/,/, $fields)) {
74 foreach (@{$data->{$key}}) {
75 print $client "$attrs{$key}: ";