Signature fetcher thingy
[mirror/userdir-ldap.git] / ud-fingerserv
index 7060fa4..07466de 100755 (executable)
@@ -1,8 +1,9 @@
 #!/usr/bin/perl
-# $Id: ud-fingerserv,v 1.4 1999/10/16 21:44:30 tausq Exp $
+# $Id: ud-fingerserv,v 1.10 1999/10/17 02:21:48 tausq Exp $
 
 # (c) 1999 Randolph Chung. Licensed under the GPL. <tausq@debian.org>
 
+use lib '/var/www/userdir-ldap/';
 #use lib '/home/randolph/projects/userdir-ldap/web';
 use strict vars;
 #use Apache::Registry;
@@ -16,7 +17,7 @@ use Net::LDAP qw(:all);
 # Global settings...
 my %config = &Util::ReadConfigFile;
 my %opts;
-getopt("iqh", \%opts);
+getopts("iqhv", \%opts);
 my $use_inetd = $config{use_inetd} || $opts{i}; 
 $| = 1;
 
@@ -24,12 +25,13 @@ my %attrs = (
   'cn' => 'First name',
   'mn' => 'Middle name',
   'sn' => 'Last name',
+  'email' => 'Email',
   'keyfingerprint' => 'Fingerprint',
   'key' => 'Key block',
   'ircnick' => 'IRC nickname'
 );
 
-my @summarykeys = ('cn', 'mn', 'sn', 'ircnick', 'keyfingerprint', 'key');
+my @summarykeys = ('cn', 'mn', 'sn', 'email', 'ircnick', 'keyfingerprint', 'key');
 
 $SIG{__DIE__} = \&DieHandler;
 $SIG{INT} = \&DieHandler;
@@ -42,7 +44,7 @@ $SIG{CHLD} = \&Reaper;
 my $ldap = Net::LDAP->new($config{ldaphost}) || die $1; 
 $ldap->bind;
 
-if ($use_inetd == 0) {
+if (!$use_inetd) {
   &log("Binding to port 79") if (defined($opts{v}));
   my $server = IO::Socket::INET->new(Proto => 'tcp', 
                                      LocalPort => 'finger(79)',
@@ -71,7 +73,6 @@ if ($use_inetd == 0) {
     $client->close;
   }
 } else { # inetd
-  $opts{q} = 1; # Temp, until i figure out wth tcpd doesn't pass parameters to this program properly
   &log("inetd mode");
   my $sockaddr = getpeername(STDIN);
   my ($port, $addr) = unpack_sockaddr_in(getpeername(STDIN));
@@ -102,6 +103,11 @@ sub ProcessQuery {
   $query =~ s/[^\/,0-9a-z]//gi; # be paranoid about input
   my ($uid, $fields) = split(/\//, $query, 2);
   
+  if ($uid =~ /^help$/i) {
+    &sendhelp($client);
+    return;
+  }
+  
   &log("Looking up $uid at $config{basedn}, uid=$uid");
 
   $mesg = $ldap->search(base  => $config{basedn}, filter => "uid=$uid");
@@ -115,6 +121,12 @@ sub ProcessQuery {
     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;                            
  
     print $client "$dn\n";
     if (!$fields) {
@@ -152,3 +164,20 @@ sub log {
   my $time = localtime;
   print STDERR "$time $msg\n";
 }
+
+sub sendhelp {
+  my $client = shift;
+  
+  print $client "userdir-ldap finger daemon\n";
+  print $client "--------------------------\n";
+  print $client "finger <uid>[/<attributes>]\@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 current 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";
+}