~ubuntu-branches/ubuntu/oneiric/gnupg2/oneiric-updates

« back to all changes in this revision

Viewing changes to keyserver/gpg2keys_mailto.in

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-10-04 10:25:53 UTC
  • mfrom: (5.1.15 intrepid)
  • Revision ID: james.westby@ubuntu.com-20081004102553-fv62pp8dsitxli47
Tags: 2.0.9-3.1
* Non-maintainer upload.
* agent/gpg-agent.c: Deinit the threading library before exec'ing
  the command to run in --daemon mode. And because that still doesn't
  restore the sigprocmask, do that manually. Closes: #499569

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!@PERL@ -w
 
2
 
 
3
# gpg2keys_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="@SENDMAIL@ -t";
 
23
 
 
24
###
 
25
 
 
26
sub VERSION_MESSAGE ()
 
27
{
 
28
    print STDOUT "gpg2keys_mailto (GnuPG) @VERSION@\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
($login,$name)=(getpwuid($<))[0,6];
 
56
 
 
57
$from="$name <$login>";
 
58
 
 
59
while(<STDIN>)
 
60
{
 
61
    last if($_ eq "\n");
 
62
 
 
63
    if(/^COMMAND (\S+)/)
 
64
    {
 
65
        $command=$1;
 
66
    }
 
67
 
 
68
    if(/^OPAQUE (\S+)/)
 
69
    {
 
70
        $address=$1;
 
71
    }
 
72
 
 
73
    if(/^PROGRAM (\S+)/)
 
74
    {
 
75
        $program=$1;
 
76
    }
 
77
 
 
78
    if(/^OPTION (\S+)/)
 
79
    {
 
80
        if($1=~/^verbose$/i)
 
81
        {
 
82
            $verbose++;
 
83
        }
 
84
        elsif($1=~/^no-verbose$/i)
 
85
        {
 
86
            $verbose--;
 
87
        }
 
88
    }
 
89
}
 
90
 
 
91
$program="(unknown)" if(!defined($program));
 
92
 
 
93
if(!defined($address))
 
94
{
 
95
    print STDERR "gpgkeys: no address provided\n";
 
96
    exit(1);
 
97
}
 
98
 
 
99
# decode $address
 
100
 
 
101
($address,$args)=split(/\?/,$address);
 
102
 
 
103
if(defined($args))
 
104
{
 
105
    @pairs = split(/&/, $args);
 
106
    foreach $pair (@pairs)
 
107
    {
 
108
        ($hdr, $val) = split(/=/, $pair);
 
109
        $hdr =~ tr/+/ /;
 
110
        $hdr =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
 
111
        $val =~ tr/+/ /;
 
112
        $val =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
 
113
# we only handle "from" right now
 
114
        if($hdr=~/^from$/i)
 
115
        {
 
116
            $from=$val;
 
117
            last;
 
118
        }
 
119
    }
 
120
}
 
121
 
 
122
while(<STDIN>)
 
123
{
 
124
    last if($_ eq "\n");
 
125
 
 
126
    chomp;
 
127
 
 
128
    push(@keys,$_);
 
129
}
 
130
 
 
131
# Send response
 
132
 
 
133
print "VERSION 1\n";
 
134
print "OPTION OUTOFBAND\n\n";
 
135
 
 
136
# Email keyservers get and search the same way
 
137
 
 
138
if($command=~/get/i || $command=~/search/i)
 
139
{
 
140
    if($command=~/search/i)
 
141
    {
 
142
        print "COUNT 0\n";
 
143
    }
 
144
 
 
145
    foreach $key (@keys)
 
146
    {
 
147
        open(MAIL,"|$sendmail") || die "ERROR: Can't open $sendmail\n";
 
148
        print MAIL "From: $from\n";
 
149
        print MAIL "To: $address\n";
 
150
        if($command=~/get/i)
 
151
        {
 
152
            # mail keyservers don't like long-form keyids
 
153
 
 
154
            if(substr($key,0,2) eq "0x")
 
155
            {
 
156
                $key=substr($key,2);
 
157
            }
 
158
 
 
159
            if(length($key)>8)
 
160
            {
 
161
                $key=substr($key,-8);
 
162
            }
 
163
 
 
164
            print MAIL "Subject: GET 0x$key\n\n";
 
165
        }
 
166
        else
 
167
        {
 
168
            print MAIL "Subject: GET $key\n\n";
 
169
        }
 
170
        print MAIL "GnuPG $program email keyserver request\n";
 
171
        close(MAIL);
 
172
 
 
173
        # Tell GnuPG not to expect a key
 
174
        print "KEY $key OUTOFBAND\n";
 
175
 
 
176
        if($verbose)
 
177
        {
 
178
            print STDERR "gpgkeys: key $key requested from $address\n";
 
179
        }
 
180
    }
 
181
}
 
182
 
 
183
if($command=~/send/i)
 
184
{
 
185
    while(!eof(STDIN))
 
186
    {
 
187
        open(MAIL,"|$sendmail") || die "ERROR: Can't open $sendmail\n";
 
188
        print MAIL "From: $name <$login>\n";
 
189
        print MAIL "To: $address\n";
 
190
        print MAIL "Subject: ADD\n\n";
 
191
 
 
192
        while(<STDIN>)
 
193
        {
 
194
            if(/^KEY (\S+) BEGIN$/)
 
195
            {
 
196
                $key=$1;
 
197
                last;
 
198
            }
 
199
        }
 
200
 
 
201
        while(<STDIN>)
 
202
        {
 
203
            if(/^KEY \S+ END$/)
 
204
            {
 
205
                last;
 
206
            }
 
207
 
 
208
            print MAIL;
 
209
        }
 
210
 
 
211
        close(MAIL);
 
212
 
 
213
        if($verbose)
 
214
        {
 
215
            print STDERR "gpgkeys: key $key sent to $address\n";
 
216
        }
 
217
    }
 
218
}
 
219
 
 
220
 
 
221
# Local Variables: 
 
222
# mode:perl
 
223
# End: