2 # $Id: ud-fingerserv,v 1.2 1999/10/05 02:54:29 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',
22 'ircnick' => 'IRC nickname'
25 my @summarykeys = ('cn', 'mn', 'sn', 'ircnick', 'keyfingerprint', 'key');
27 my ($ldap, $mesg, $dn, $entries, $data, %output, $key, $hostlist, $hostdetails, $selected, %summary);
29 $ldap->unbind if (defined($ldap));
32 $SIG{__DIE__} = \&DieHandler;
34 $ldap = Net::LDAP->new($config{ldaphost}) || &Util::HTMLError($!);
38 my $server = IO::Socket::INET->new(Proto => 'tcp',
39 LocalPort => 'finger(79)',
43 die "Cannot listen on finger port" unless $server;
44 print "[Server listening for connections]\n";
46 my ($mesg, %entries, $dn, $key);
49 while ($client = $server->accept()) {
50 $client->autoflush(1);
51 my $hostinfo = gethostbyaddr($client->peeraddr, AF_INET);
52 printf "[Connect from %s]\n", $hostinfo || $client->peerhost;
53 my $query = <$client>;
54 $query =~ s/[^\/,0-9a-z]//gi; # be paranoid about input
55 my ($uid, $fields) = split(/\//, $query, 2);
57 print "Looking up $uid at $config{basedn}, uid=$uid\n";
59 $mesg = $ldap->search(base => $config{basedn}, filter => "uid=$uid");
60 $mesg->code && die $mesg->error;
61 $entries = $mesg->as_struct;
63 foreach $dn (sort {$entries->{$a}->{sn}->[0] <=> $entries->{$b}->{sn}->[0]} keys(%$entries)) {
64 $data = $entries->{$dn};
67 foreach (@{$data->{keyfingerprint}}) {
68 push (@{$data->{key}}, "\n".&Util::FetchKey($_));
71 print $client "$dn\n";
73 foreach $key (@summarykeys) {
74 foreach (@{$data->{$key}}) {
75 print $client "$attrs{$key}: ";
81 foreach $key (split(/,/, $fields)) {
82 foreach (@{$data->{$key}}) {
83 print $client "$attrs{$key}: ";