home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / lib / gnupg / gpgkeys_mailto < prev   
Encoding:
Text File  |  2013-01-02  |  3.4 KB  |  212 lines

  1. #!/usr/bin/perl -w
  2.  
  3. # gpgkeys_mailto - talk to a email keyserver 
  4. # Copyright (C) 2001, 2002 Free Software Foundation, Inc.
  5. #
  6. # This file is part of GnuPG.
  7. #
  8. # GnuPG is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # GnuPG is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, see <http://www.gnu.org/licenses/>.
  20. use Getopt::Std;
  21. $Getopt::Std::STANDARD_HELP_VERSION=1;
  22. $sendmail="/usr/sbin/sendmail -t";
  23.  
  24. ###
  25.  
  26. sub VERSION_MESSAGE ()
  27. {
  28.     print STDOUT "gpgkeys_mailto (GnuPG) 1.4.10\n";
  29. }
  30.  
  31. sub HELP_MESSAGE ()
  32. {
  33.     print STDOUT <<EOT
  34.  
  35. --help     Print this help
  36. --version  Print the version
  37. -o FILE    Write output to FILE
  38. EOT
  39. }
  40.  
  41.  
  42.  
  43. getopts('o:');
  44.  
  45. if(defined($opt_o))
  46. {
  47.     open(STDOUT,">$opt_o") || die "Can't open output file $opt_o\n";
  48. }
  49.  
  50. if(@ARGV)
  51. {
  52.     open(STDIN,$ARGV[0]) || die "Can't open input file $ARGV[0]\n";
  53. }
  54.  
  55. while(<STDIN>)
  56. {
  57.     last if($_ eq "\n");
  58.  
  59.     if(/^COMMAND (\S+)/)
  60.     {
  61.     $command=$1;
  62.     }
  63.  
  64.     if(/^OPAQUE (\S+)/)
  65.     {
  66.     $address=$1;
  67.     }
  68.  
  69.     if(/^PROGRAM (\S+)/)
  70.     {
  71.     $program=$1;
  72.     }
  73.  
  74.     if(/^OPTION (\S+)/)
  75.     {
  76.     if($1=~/^verbose$/i)
  77.     {
  78.         $verbose++;
  79.     }
  80.     elsif($1=~/^no-verbose$/i)
  81.     {
  82.         $verbose--;
  83.     }
  84.     elsif($1=~/^mail-from=(.+)$/i)
  85.     {
  86.         $from=$1;
  87.     }
  88.     elsif($1=~/^no-mail-from$/i)
  89.     {
  90.         undef $from;
  91.     }
  92.  
  93.     }
  94. }
  95.  
  96. if(!defined($from))
  97. {
  98.     ($login,$name)=(getpwuid($<))[0,6];
  99.     $from="$name <$login>";
  100. }
  101.  
  102. $program="(unknown)" if(!defined($program));
  103.  
  104. if(!defined($address))
  105. {
  106.     print STDERR "gpgkeys: no address provided\n";
  107.     exit(1);
  108. }
  109.  
  110. while(<STDIN>)
  111. {
  112.     last if($_ eq "\n");
  113.  
  114.     chomp;
  115.  
  116.     push(@keys,$_);
  117. }
  118.  
  119. # Send response
  120.  
  121. print "VERSION 1\n";
  122. print "OPTION OUTOFBAND\n\n";
  123.  
  124. # Email keyservers get and search the same way
  125.  
  126. if($command=~/get/i || $command=~/search/i)
  127. {
  128.     if($command=~/search/i)
  129.     {
  130.     print "COUNT 0\n";
  131.     }
  132.  
  133.     foreach $key (@keys)
  134.     {
  135.     open(MAIL,"|$sendmail") || die "ERROR: Can't open $sendmail\n";
  136.     print MAIL "From: $from\n";
  137.     print MAIL "To: $address\n";
  138.     if($command=~/get/i)
  139.     {
  140.         # mail keyservers don't like long-form keyids
  141.  
  142.         if(substr($key,0,2) eq "0x")
  143.         {
  144.         $key=substr($key,2);
  145.         }
  146.  
  147.         if(length($key)>8)
  148.         {
  149.         $key=substr($key,-8);
  150.         }
  151.  
  152.             print MAIL "Subject: GET 0x$key\n\n";
  153.     }
  154.     else
  155.     {
  156.         print MAIL "Subject: GET $key\n\n";
  157.     }
  158.     print MAIL "GnuPG $program email keyserver request\n";
  159.     close(MAIL);
  160.  
  161.     # Tell GnuPG not to expect a key
  162.     print "KEY $key OUTOFBAND\n";
  163.  
  164.     if($verbose)
  165.     {
  166.         print STDERR "gpgkeys: key $key requested from $address\n";
  167.     }
  168.     }
  169. }
  170.  
  171. if($command=~/send/i)
  172. {
  173.     while(!eof(STDIN))
  174.     {
  175.     open(MAIL,"|$sendmail") || die "ERROR: Can't open $sendmail\n";
  176.     print MAIL "From: $name <$login>\n";
  177.     print MAIL "To: $address\n";
  178.     print MAIL "Subject: ADD\n\n";
  179.  
  180.     while(<STDIN>)
  181.     {
  182.         if(/^KEY (\S+) BEGIN$/)
  183.         {
  184.         $key=$1;
  185.         last;
  186.         }
  187.     }
  188.  
  189.     while(<STDIN>)
  190.     {
  191.         if(/^KEY \S+ END$/)
  192.         {
  193.         last;
  194.         }
  195.  
  196.         print MAIL;
  197.     }
  198.  
  199.     close(MAIL);
  200.  
  201.     if($verbose)
  202.     {
  203.         print STDERR "gpgkeys: key $key sent to $address\n";
  204.     }
  205.     }
  206. }
  207.  
  208.  
  209. # Local Variables: 
  210. # mode:perl
  211. # End:
  212.