1
-- Topal: GPG/GnuPG and Alpine/Pine integration
2
-- Copyright (C) 2001--2008 Phillip J. Brooke
4
-- This program is free software: you can redistribute it and/or modify
5
-- it under the terms of the GNU General Public License version 3 as
6
-- published by the Free Software Foundation.
8
-- This program is distributed in the hope that it will be useful,
9
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
10
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
-- GNU General Public License for more details.
13
-- You should have received a copy of the GNU General Public License
14
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
7
17
with Externals.Simple;
28
25
-- Clean up the error file to remove
29
26
-- `gpg: Invalid passphrase; please try again ...' messages.
30
if ForkExec_Out(Value_Nonempty(Config.Grep_Binary),
27
if ForkExec_Out(Value_Nonempty(Config.Binary(Grep)),
31
28
UBS_Array'(0 => ToUBS("grep"),
33
30
2 => ToUBS("gpg: Invalid passphrase; please try again ..."),
41
38
Output_File : String;
42
39
Err_File : String) return Integer is
43
40
GPG_Return_Value, Tee_Return_Value : Integer;
44
Orig_Err_File : String := Temp_File_Name("origerr");
41
Orig_Err_File : constant String
42
:= Temp_File_Name("origerr");
46
ForkExec2(Value_Nonempty(Config.Gpg_Binary),
44
ForkExec2(Value_Nonempty(Config.Binary(GPGOP)),
48
46
& ToStr(Config.Gpg_Options)
79
77
Output_File : String;
80
78
Err_File : String) return Integer is
81
79
GPG_Return_Value, Tee_Return_Value : Integer;
82
Orig_Err_File : String := Temp_File_Name("origerr");
80
Orig_Err_File : constant String
81
:= Temp_File_Name("origerr");
84
ForkExec2(Value_Nonempty(Config.Gpg_Binary),
83
ForkExec2(Value_Nonempty(Config.Binary(GPGOP)),
86
85
& ToStr(Config.Gpg_Options)
115
114
end GPG_Verify_Tee;
116
function GPGSM_Verify_Tee (Input_File : String;
118
Output_File : String;
119
Err_File : String) return Integer is
120
GPG_Return_Value, Tee_Return_Value : Integer;
121
Orig_Err_File : constant String
122
:= Temp_File_Name("origerr");
124
-- FIXME: gpgsm should be in config
125
ForkExec2(Value_Nonempty(Config.Binary(GPGSM)),
127
& " --disable-crl-checks --output "
134
Value_Nonempty(Config.Binary(Tee)),
138
Merge_StdErr1 => True,
140
if Tee_Return_Value /= 0 then
141
Error("Tee failed! (ff1)");
143
Clean_GPG_Errors(Orig_Err_File, Err_File);
144
-- Let the caller sort out the GPG return value.
145
return GPG_Return_Value;
148
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
149
"Exception raised in Externals.GPG.GPGSM_Verify_Tee");
151
end GPGSM_Verify_Tee;
117
153
function Grep_Sigfile_Digest (Sigfile : in String;
118
154
Number : in String)
119
155
return Integer is
120
156
E1, E2 : Integer;
122
ForkExec2(Value_Nonempty(Config.GPG_Binary),
158
ForkExec2(Value_Nonempty(Config.Binary(GPGOP)),
123
159
UBS_Array'(0 => ToUBS("gpg"),
124
160
1 => ToUBS("--list-packets"),
125
161
2 => ToUBS(Sigfile)),
127
Value_Nonempty(Config.Grep_Binary),
163
Value_Nonempty(Config.Binary(Grep)),
128
164
UBS_Array'(0 => ToUBS("grep"),
129
165
1 => ToUBS("-q"),
130
166
2 => ToUBS("digest algo " & Number)),
191
227
R : Integer; -- The return code from GPG.
193
229
Ada.Text_IO.Put_Line("About to run `gpg " & Args & "'...");
194
R := ForkExec(Value_Nonempty(Config.Gpg_Binary),
230
R := ForkExec(Value_Nonempty(Config.Binary(GPGOP)),
195
231
ToUBS("gpg " & Args));
197
233
Ada.Text_IO.Put_Line("GPG exited successfully...");
222
258
Target : in String) is
223
259
E1, E2, E3 : Integer;
225
ForkExec3_Out(Value_Nonempty(Config.Gpg_Binary),
261
ForkExec3_Out(Value_Nonempty(Config.Binary(GPGOP)),
227
263
& ToStr(Config.Gpg_Options)
228
& " --fingerprint " & Key),
264
& " --with-colons --with-fingerprint --list-keys " & Key),
230
Value_Nonempty(Config.Grep_binary),
266
Value_Nonempty(Config.Binary(Grep)),
231
267
UBS_Array'(0 => ToUBS("grep"),
232
1 => ToUBS("Key fingerprint")),
234
Value_Nonempty(Config.Sed_binary),
270
Value_Nonempty(Config.Binary(Sed)),
235
271
UBS_Array'(0 => ToUBS("sed"),
237
2 => ToUBS("s/.*= //"),
239
4 => ToUBS("s/ //g"),
241
6 => ToUBS("s/^/0x/")),
272
1 => ToUBS("s/^fpr:*://; s/:*$//")),
243
274
Target => Target);
244
275
Debug("Add_Keys_By_Fingerprint: Finished exec's");
261
292
Target : in String) is
262
293
E1, E2, E3 : Integer;
264
ForkExec3_Out(Value_Nonempty(Config.Gpg_Binary),
295
ForkExec3_Out(Value_Nonempty(Config.Binary(GPGOP)),
266
297
& ToStr(Config.Gpg_Options)
267
& " --list-secret-keys "
298
& " --with-colons --with-fingerprint --list-secret-keys " & Key),
270
Value_Nonempty(Config.Grep_Binary),
300
Value_Nonempty(Config.Binary(Grep)),
271
301
UBS_Array'(0 => ToUBS("grep"),
274
Value_Nonempty(Config.Sed_Binary),
304
Value_Nonempty(Config.Binary(Sed)),
275
305
UBS_Array'(0 => ToUBS("sed"),
277
2 => ToUBS("s/^sec *//"),
279
4 => ToUBS("s/ .*$//"),
281
6 => ToUBS("sx^.*/xx")),
306
1 => ToUBS("s/^fpr:*://; s/:*$//")),
283
308
Target => Target);
298
323
procedure Listkey (Key : in String;
299
324
Target : in String) is
301
if ForkExec_Out(Value_Nonempty(Config.Gpg_Binary),
303
& ToStr(Config.Gpg_Options)
306
Target => Target) /= 0 then
307
Error("Problem generating keylist, GPG barfed (ff7)");
327
ForkExec2_Out(File1 => Value_Nonempty(Config.Binary(GPGOP)),
328
Argv1 => ToUBS("gpg "
329
& ToStr(Config.Gpg_Options)
330
& " --with-colons --with-fingerprint --with-fingerprint --list-keys "
333
File2 => Value_Nonempty(Config.Binary(Grep)),
334
Argv2 => UBS_Array'(0 => ToUBS("grep"),
339
Error("Problem generating keylist, GPG barfed (ff7a)");
342
Error("Problem generating keylist, grep barfed (ff7b)");
329
364
& " --list-keys "
332
ForkExec2(Value_Nonempty(Config.Gpg_binary),
367
ForkExec2(Value_Nonempty(Config.Binary(GPGOP)),
335
Value_Nonempty(Config.Less_Binary),
370
Value_Nonempty(Config.Binary(Less)),