X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=ud-fingerserv;h=1a944e76bdd76723216948a54ee186ac23cd9f65;hb=186f30d63f9631fbfbda0b56f59d4f0339f8a9d2;hp=c581b3dd5286ef88133f43e11f0a31fd3b0a7698;hpb=f4a89029dd309f07a6a2661e8f79328e15a32ebf;p=mirror%2Fuserdir-ldap.git diff --git a/ud-fingerserv b/ud-fingerserv index c581b3d..1a944e7 100755 --- a/ud-fingerserv +++ b/ud-fingerserv @@ -1,11 +1,12 @@ #!/usr/bin/perl -# $Id: ud-fingerserv,v 1.8 1999/10/17 02:01:28 tausq Exp $ +# $Id: ud-fingerserv,v 1.19 2004/11/18 19:10:57 joey Exp $ # (c) 1999 Randolph Chung. Licensed under the GPL. +# (c) 2004 Martin Schulze. Licensed under the GPL. use lib '/var/www/userdir-ldap/'; +#use lib '/home/randolph/projects/userdir-ldap/web'; use strict vars; -#use Apache::Registry; use IO::Handle; use IO::Socket; use POSIX qw(:sys_wait_h); @@ -27,10 +28,13 @@ my %attrs = ( 'email' => 'Email', 'keyfingerprint' => 'Fingerprint', 'key' => 'Key block', - 'ircnick' => 'IRC nickname' + 'ircnick' => 'IRC nickname', + 'icquin' => 'ICQ UIN', + 'jabberjid' => 'Jabber ID', + 'labeleduri' => 'URL' ); -my @summarykeys = ('cn', 'mn', 'sn', 'email', 'ircnick', 'keyfingerprint', 'key'); +my @summarykeys = ('cn', 'mn', 'sn', 'email', 'labeleduri', 'ircnick', 'icquin', 'jabberjid', 'keyfingerprint', 'key'); $SIG{__DIE__} = \&DieHandler; $SIG{INT} = \&DieHandler; @@ -64,8 +68,8 @@ if (!$use_inetd) { $client->autoflush(1); my $hostinfo = gethostbyaddr($client->peeraddr, AF_INET); &log(sprintf("[Connect from %s]", $hostinfo || $client->peerhost)); - my $query = <$client>; - &ProcessQuery($client, $query); + my $query = &readdata($client); + &ProcessQuery($client, $query) if (defined($query)); $client->close; exit; } continue { @@ -74,10 +78,14 @@ if (!$use_inetd) { } else { # inetd &log("inetd mode"); my $sockaddr = getpeername(STDIN); - my ($port, $addr) = unpack_sockaddr_in(getpeername(STDIN)); - &log(sprintf("[Connect from %s (%s)]", gethostbyaddr($addr, AF_INET), inet_ntoa($addr))); - my $query = ; - &ProcessQuery(\*STDOUT, $query); + if ($sockaddr) { + my ($port, $addr) = unpack_sockaddr_in(getpeername(STDIN)); + &log(sprintf("[Connect from %s (%s)]", gethostbyaddr($addr, AF_INET), inet_ntoa($addr))); + } else { + &log("[Connect via terminal]"); + } + my $query = &readdata(\*STDIN); + &ProcessQuery(\*STDOUT, $query) if (defined($query)); exit; } @@ -102,28 +110,40 @@ sub ProcessQuery { $query =~ s/[^\/,0-9a-z]//gi; # be paranoid about input my ($uid, $fields) = split(/\//, $query, 2); + if (($uid eq "") || ($uid =~ /^help$/i)) { + &sendhelp($client); + return; + } + &log("Looking up $uid at $config{basedn}, uid=$uid"); $mesg = $ldap->search(base => $config{basedn}, filter => "uid=$uid"); $mesg->code && die $mesg->error; $entries = $mesg->as_struct; - + + if ($mesg->count == 0) { + print $client "$uid not found at db.debian.org\n"; + exit 0; + } + foreach $dn (sort {$entries->{$a}->{sn}->[0] <=> $entries->{$b}->{sn}->[0]} keys(%$entries)) { $data = $entries->{$dn}; - $data->{key} = []; - foreach (@{$data->{keyfingerprint}}) { - push (@{$data->{key}}, "\n".&Util::FetchKey($_)); - } - $data->{email}->[0] = sprintf("%s %s %s <%s>", $data->{cn}->[0], $data->{mn}->[0], $data->{sn}->[0], $data->{uid}->[0]."\@$config{emailappend}"); $data->{email}->[0] =~ s/\s+/ /g; + my @keyfingerprint = (); + for (my $i=0; $i <= $#{$data->{'keyfingerprint'}}; $i++) { + push (@keyfingerprint, $data->{keyfingerprint}->[$i]); + $data->{keyfingerprint}->[$i] = &Util::FormatFingerPrint($data->{keyfingerprint}->[$i]); + $data->{keyfingerprint}->[$i] =~ s, , ,; + } print $client "$dn\n"; if (!$fields) { + push (@{$data->{key}}, sprintf ("finger %s/key\@db.debian.org", $uid)); foreach $key (@summarykeys) { foreach (@{$data->{$key}}) { print $client "$attrs{$key}: "; @@ -133,6 +153,11 @@ sub ProcessQuery { } else { # print "$fields\n"; foreach $key (split(/,/, $fields)) { + if ($key eq 'key') { + foreach (@keyfingerprint) { + push (@{$data->{key}}, "\n".&Util::FetchKey($_), 0); + } + } foreach (@{$data->{$key}}) { print $client "$attrs{$key}: "; print $client "$_\n"; @@ -158,3 +183,43 @@ sub log { my $time = localtime; print STDERR "$time $msg\n"; } + +sub readdata { + my $fh = shift; + my $in = undef; + my $out = undef; + my $bytesread = 0; + my $ret; + + my $flags= fcntl($fh, F_GETFL, 0) + or die "Can't get flags for socket: $!\n"; + fcntl($fh, F_SETFL, $flags | O_NONBLOCK) + or die "Can't make socket nonblocking: $!\n"; + + while (($bytesread < 1024) && ($out !~ /\n/)) { + $ret = sysread($fh, $in, 1024); + return undef if (!defined($ret) || ($ret == 0)); + $bytesread += $ret; + $out .= $in; + } + + $out =~ /(.*?)\n/; + return $1; +} + +sub sendhelp { + my $client = shift; + + print $client "userdir-ldap finger daemon\n"; + print $client "--------------------------\n"; + print $client "finger [/]\@db.debian.org\n"; + print $client " where uid is the user id of the user\n"; + print $client " the optional attributes parameter specifies what to return\n"; + print $client " if nothing is specified, all attributes are returned.\n"; + print $client " The following attributes are currently supported:\n"; + foreach (@summarykeys) { + print $client " $_ : $attrs{$_}\n"; + } + print $client " Multiple attributes can be separated by commas, like this:\n"; + print $client " finger tux/email,key\@db.debian.org\n"; +}