1 |
werner |
36 |
/* wptKeyEditCB.cpp - Key edit callback handling |
2 |
twoaday |
200 |
* Copyright (C) 2005, 2006 Timo Schulz |
3 |
werner |
36 |
* Copyright (C) 2005 g10 Code GmbH |
4 |
|
|
* |
5 |
|
|
* This file is part of WinPT. |
6 |
|
|
* |
7 |
|
|
* WinPT is free software; you can redistribute it and/or |
8 |
|
|
* modify it under the terms of the GNU General Public License |
9 |
|
|
* as published by the Free Software Foundation; either version 2 |
10 |
|
|
* of the License, or (at your option) any later version. |
11 |
|
|
* |
12 |
|
|
* WinPT is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 |
|
|
* General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with WinPT; if not, write to the Free Software Foundation, |
19 |
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
20 |
|
|
*/ |
21 |
twoaday |
119 |
|
22 |
werner |
36 |
#ifdef HAVE_CONFIG_H |
23 |
|
|
#include <config.h> |
24 |
|
|
#endif |
25 |
|
|
|
26 |
|
|
#include <stdio.h> |
27 |
|
|
#include <string.h> |
28 |
|
|
#include <stdlib.h> |
29 |
|
|
#include <assert.h> |
30 |
|
|
#include <windows.h> |
31 |
|
|
|
32 |
|
|
#include "gpgme.h" |
33 |
|
|
#include "wptCommonCtl.h" |
34 |
|
|
#include "wptContext.h" |
35 |
|
|
#include "wptKeyEdit.h" |
36 |
|
|
#include "wptErrors.h" |
37 |
|
|
|
38 |
twoaday |
129 |
/* Possible errors for the edit key operation. */ |
39 |
|
|
enum editkey_error_t { |
40 |
|
|
EDITKEY_ERR_ALREADY_SIGNED = 1, |
41 |
|
|
EDITKEY_ERR_BAD_PASSPHRASE = 2 |
42 |
|
|
}; |
43 |
werner |
36 |
|
44 |
twoaday |
200 |
typedef gpgme_status_code_t status_code_t; |
45 |
|
|
|
46 |
twoaday |
260 |
|
47 |
twoaday |
200 |
/* 'notation' command handler. */ |
48 |
|
|
static const char* |
49 |
|
|
cmd_notation_handler (GpgKeyEdit *ctx, status_code_t code, const char *key) |
50 |
|
|
{ |
51 |
|
|
static char buf[32]; |
52 |
|
|
|
53 |
|
|
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
54 |
|
|
int uid = ctx->getUseridIndex (); |
55 |
|
|
ctx->cmd_sent = 1; |
56 |
|
|
if (uid != -1) { |
57 |
|
|
sprintf (buf, "uid %d", ctx->getUseridIndex ()); |
58 |
|
|
return buf; |
59 |
|
|
} |
60 |
|
|
} |
61 |
|
|
if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 0) { |
62 |
|
|
ctx->cnt = 1; |
63 |
|
|
return "notation"; |
64 |
|
|
} |
65 |
|
|
if (!strcmp (key, "keyedit.add_notation")) |
66 |
|
|
return ctx->notation; |
67 |
|
|
if (!strcmp (key, "passphrase.enter")) |
68 |
|
|
return ctx->pass; |
69 |
|
|
|
70 |
|
|
return NULL; |
71 |
|
|
} |
72 |
|
|
|
73 |
|
|
|
74 |
werner |
36 |
/* 'keyserver' command handler. */ |
75 |
|
|
static const char* |
76 |
|
|
cmd_keyserv_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key) |
77 |
|
|
{ |
78 |
|
|
static char buf[32]; |
79 |
|
|
|
80 |
|
|
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
81 |
twoaday |
181 |
int uid = ctx->getUseridIndex (); |
82 |
werner |
36 |
ctx->cmd_sent = 1; |
83 |
twoaday |
181 |
if (uid != -1) { |
84 |
|
|
sprintf (buf, "uid %d", ctx->getUseridIndex ()); |
85 |
|
|
return buf; |
86 |
|
|
} |
87 |
werner |
36 |
} |
88 |
twoaday |
200 |
if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 0) { |
89 |
werner |
36 |
ctx->cnt = 1; |
90 |
|
|
return "keyserver"; |
91 |
|
|
} |
92 |
|
|
if (!strcmp (key, "keyedit.add_keyserver")) |
93 |
|
|
return ctx->url; |
94 |
twoaday |
181 |
if (!strcmp (key, "keyedit.confirm_keyserver")) |
95 |
werner |
36 |
return "Y"; |
96 |
|
|
if (!strcmp (key, "passphrase.enter")) |
97 |
|
|
return ctx->pass; |
98 |
|
|
if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 1) { |
99 |
|
|
ctx->reset (); |
100 |
|
|
return "save"; |
101 |
|
|
} |
102 |
|
|
|
103 |
|
|
return NULL; |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
|
107 |
twoaday |
119 |
/* 'sign' command handler. */ |
108 |
werner |
36 |
static const char* |
109 |
|
|
cmd_sign_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key) |
110 |
|
|
{ |
111 |
|
|
static char buf[32]; |
112 |
|
|
|
113 |
twoaday |
170 |
if (ctx->getUseridIndex () != -1 && |
114 |
|
|
ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
115 |
|
|
ctx->cnt++; |
116 |
|
|
sprintf (buf, "uid %d", ctx->getUseridIndex ()); |
117 |
|
|
return buf; |
118 |
|
|
} |
119 |
|
|
|
120 |
werner |
36 |
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
121 |
|
|
ctx->cmd_sent = 1; |
122 |
|
|
switch (ctx->getType ()) { |
123 |
twoaday |
225 |
case GPG_EDITKEY_SIGN: return "sign"; |
124 |
|
|
case GPG_EDITKEY_TSIGN: return "tsign"; |
125 |
|
|
case GPG_EDITKEY_LSIGN: return "lsign"; |
126 |
|
|
case GPG_EDITKEY_NRSIGN: return "nrsign"; |
127 |
|
|
case GPG_EDITKEY_NRLSIGN: return "nrlsign"; |
128 |
werner |
36 |
} |
129 |
|
|
} |
130 |
|
|
if (!strcmp (key, "sign_uid.class")) { |
131 |
|
|
sprintf (buf, "%d", ctx->sig_class); |
132 |
|
|
return buf; |
133 |
|
|
} |
134 |
|
|
if (!strcmp (key, "sign_uid.expire")) |
135 |
|
|
return "Y"; /* the sig expires when the key expires */ |
136 |
|
|
if (!strcmp (key, "siggen.valid")) |
137 |
twoaday |
225 |
return ctx->exp_date? ctx->exp_date : "0"; |
138 |
werner |
36 |
if (!strcmp (key, "trustsig_prompt.trust_value")) { |
139 |
|
|
sprintf (buf, "%d", ctx->trust_id); |
140 |
|
|
return buf; |
141 |
|
|
} |
142 |
|
|
if (!strcmp (key, "trustsig_prompt.trust_depth")) |
143 |
|
|
return ""; /* fixme */ |
144 |
|
|
if (!strcmp (key, "trustsig_prompt.trust_regexp")) |
145 |
|
|
return ""; /* fixme */ |
146 |
|
|
if (!strcmp (key, "sign_uid.local_promote_okay" ) ) |
147 |
|
|
return "Y"; |
148 |
|
|
if (!strcmp (key, "sign_uid.okay" ) ) |
149 |
|
|
return "Y"; |
150 |
|
|
if (!strcmp (key, "keyedit.sign_all.okay")) |
151 |
|
|
return "Y"; |
152 |
|
|
if (!strcmp ( key, "passphrase.enter")) |
153 |
|
|
return ctx->pass; |
154 |
|
|
if (!strcmp (key, "keyedit.prompt")) { |
155 |
|
|
ctx->reset (); |
156 |
|
|
return "save"; |
157 |
|
|
} |
158 |
|
|
|
159 |
|
|
return NULL; |
160 |
|
|
} |
161 |
|
|
|
162 |
|
|
/* 'trust' command handler. */ |
163 |
|
|
static const char* |
164 |
|
|
cmd_trust_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key) |
165 |
|
|
{ |
166 |
|
|
static char buf[4]; |
167 |
|
|
|
168 |
|
|
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
169 |
|
|
ctx->cmd_sent = 1; |
170 |
|
|
return "trust"; |
171 |
|
|
} |
172 |
|
|
if (!strcmp (key, "edit_ownertrust.set_ultimate.okay")) |
173 |
|
|
return "Y"; |
174 |
|
|
if (!strcmp (key, "edit_ownertrust.value" )) { |
175 |
|
|
sprintf (buf, "%d", ctx->trust_id); |
176 |
|
|
return buf; |
177 |
|
|
} |
178 |
|
|
if (!strcmp (key, "keyedit.prompt")) { |
179 |
|
|
ctx->reset (); |
180 |
|
|
return "save"; |
181 |
|
|
} |
182 |
|
|
|
183 |
|
|
return NULL; |
184 |
|
|
} |
185 |
|
|
|
186 |
|
|
|
187 |
|
|
/* 'adduid' command handler. */ |
188 |
|
|
static const char* |
189 |
|
|
cmd_adduid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key) |
190 |
|
|
{ |
191 |
|
|
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
192 |
|
|
ctx->cmd_sent = 1; |
193 |
|
|
return "adduid"; |
194 |
|
|
} |
195 |
|
|
if (!strcmp (key, "keygen.name")) |
196 |
|
|
return ctx->name; |
197 |
|
|
if (!strcmp (key, "keygen.email")) |
198 |
|
|
return ctx->email; |
199 |
|
|
if (!strcmp (key, "keygen.comment")) |
200 |
|
|
return ctx->cmt? ctx->cmt : ""; |
201 |
|
|
if (!strcmp (key, "passphrase.enter")) |
202 |
|
|
return ctx->pass; |
203 |
|
|
if( !strcmp (key, "keyedit.prompt")) { |
204 |
|
|
ctx->reset (); |
205 |
|
|
return "save"; |
206 |
|
|
} |
207 |
|
|
|
208 |
|
|
return NULL; |
209 |
|
|
} |
210 |
|
|
|
211 |
|
|
|
212 |
|
|
static const char* |
213 |
twoaday |
200 |
cmd_deluid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
214 |
|
|
const char *key) |
215 |
werner |
36 |
{ |
216 |
|
|
static char buf[64]; |
217 |
|
|
|
218 |
twoaday |
200 |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
219 |
twoaday |
170 |
sprintf (buf, "uid %d", ctx->getUseridIndex ()); |
220 |
twoaday |
200 |
ctx->cnt = 1; |
221 |
werner |
36 |
return buf; |
222 |
|
|
} |
223 |
twoaday |
200 |
if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) { |
224 |
|
|
ctx->cnt = 2; |
225 |
werner |
36 |
return "deluid"; |
226 |
|
|
} |
227 |
twoaday |
200 |
if (ctx->cnt == 2 && !strcmp (key, "keyedit.remove.uid.okay")) { |
228 |
|
|
ctx->cnt = 3; |
229 |
werner |
36 |
return "Y"; |
230 |
|
|
} |
231 |
twoaday |
200 |
if (ctx->cnt == 3 && !strcmp (key, "keyedit.prompt" )) { |
232 |
werner |
36 |
ctx->reset (); |
233 |
|
|
return "save"; |
234 |
|
|
} |
235 |
|
|
|
236 |
|
|
return NULL; |
237 |
|
|
} |
238 |
|
|
|
239 |
|
|
|
240 |
twoaday |
170 |
static const char* |
241 |
twoaday |
200 |
cmd_delsig_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key) |
242 |
werner |
36 |
{ |
243 |
|
|
static char buf[64]; |
244 |
twoaday |
200 |
static int sig_cnt = 0; |
245 |
werner |
36 |
|
246 |
twoaday |
200 |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
247 |
twoaday |
170 |
sprintf (buf, "uid %d", ctx->getUseridIndex ()); |
248 |
twoaday |
200 |
ctx->cnt = 1; |
249 |
werner |
36 |
return buf; |
250 |
|
|
} |
251 |
twoaday |
200 |
if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) { |
252 |
|
|
ctx->cnt = 2; |
253 |
werner |
36 |
return "delsig"; |
254 |
|
|
} |
255 |
|
|
if (!strcmp (key, "keyedit.delsig.unknown") || |
256 |
|
|
!strcmp (key, "keyedit.delsig.valid")) { |
257 |
twoaday |
200 |
if (++sig_cnt == ctx->getSigIndex ()) |
258 |
werner |
36 |
return "Y"; |
259 |
|
|
else |
260 |
|
|
return "N"; |
261 |
|
|
} |
262 |
twoaday |
160 |
if (!strcmp (key, "keyedit.delsig.selfsig")) |
263 |
werner |
36 |
return "Y"; |
264 |
twoaday |
200 |
if (ctx->cnt == 2 && !strcmp (key, "keyedit.prompt")) { |
265 |
|
|
sig_cnt = 0; |
266 |
werner |
36 |
ctx->reset (); |
267 |
|
|
return "save"; |
268 |
|
|
} |
269 |
|
|
return NULL; |
270 |
|
|
} |
271 |
|
|
|
272 |
|
|
|
273 |
|
|
/* 'delkey' command handler. */ |
274 |
|
|
static const char* |
275 |
|
|
cmd_delkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
276 |
twoaday |
200 |
const char *key) |
277 |
werner |
36 |
{ |
278 |
|
|
static char buf[64]; |
279 |
|
|
|
280 |
twoaday |
200 |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
281 |
twoaday |
170 |
sprintf (buf, "key %d", ctx->getKeyIndex ()); |
282 |
twoaday |
200 |
ctx->cnt = 1; |
283 |
werner |
36 |
return buf; |
284 |
|
|
} |
285 |
twoaday |
200 |
if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) { |
286 |
|
|
ctx->cnt = 2; |
287 |
werner |
36 |
return "delkey"; |
288 |
|
|
} |
289 |
twoaday |
200 |
if (ctx->cnt == 2 && !strcmp (key, "keyedit.remove.subkey.okay")) { |
290 |
|
|
ctx->cnt = 3; |
291 |
werner |
36 |
return "Y"; |
292 |
|
|
} |
293 |
twoaday |
200 |
if (ctx->cnt == 3 && !strcmp (key, "keyedit.prompt")) { |
294 |
werner |
36 |
ctx->reset (); |
295 |
|
|
return "save"; |
296 |
|
|
} |
297 |
|
|
|
298 |
|
|
return NULL; |
299 |
|
|
} |
300 |
|
|
|
301 |
|
|
|
302 |
twoaday |
260 |
/* 'addcardkey' command handler. */ |
303 |
|
|
static const char* |
304 |
|
|
cmd_addcardkey_handler (GpgKeyEdit *ctx, status_code_t code, const char *key) |
305 |
|
|
{ |
306 |
|
|
static char buf[32]; |
307 |
|
|
|
308 |
|
|
/* XXX: actually we mix up things here, it would be better to |
309 |
|
|
implement this in CardEditCB but because the edit-key |
310 |
|
|
interface is used, we have to implement it here. */ |
311 |
|
|
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
312 |
|
|
ctx->cmd_sent = 1; |
313 |
|
|
return "addcardkey"; |
314 |
|
|
} |
315 |
|
|
if (!strcmp (key, "cardedit.genkeys.subkeytype")) { |
316 |
|
|
sprintf (buf, "%d", ctx->getKeyIndex ()); |
317 |
|
|
return buf; |
318 |
|
|
} |
319 |
|
|
if (!strcmp (key, "cardedit.genkeys.replace_key")) |
320 |
|
|
return "Y"; /* better issue an extra warning? */ |
321 |
|
|
if (!strcmp (key, "passphrase.adminpin.ask")) |
322 |
|
|
return ctx->pass; |
323 |
|
|
if (!strcmp (key, "passphrase.pin.ask")) |
324 |
|
|
return ctx->new_pass; |
325 |
|
|
if (!strcmp (key, "keygen.valid")) { |
326 |
|
|
sprintf (buf, "%d", ctx->getValidDays ()); |
327 |
|
|
return buf; |
328 |
|
|
} |
329 |
|
|
if (!strcmp (key, "keyedit.prompt")) { |
330 |
|
|
ctx->reset (); |
331 |
|
|
return "save"; |
332 |
|
|
} |
333 |
|
|
return NULL; |
334 |
|
|
} |
335 |
|
|
|
336 |
|
|
|
337 |
werner |
36 |
/* 'addkey' command handler. */ |
338 |
|
|
static const char* |
339 |
twoaday |
260 |
cmd_addkey_handler (GpgKeyEdit *ctx, status_code_t code, const char *key) |
340 |
werner |
36 |
{ |
341 |
|
|
static char buf[64]; |
342 |
|
|
|
343 |
|
|
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
344 |
|
|
ctx->cmd_sent = 1; |
345 |
|
|
return "addkey"; |
346 |
|
|
} |
347 |
|
|
|
348 |
|
|
if (!strcmp (key, "passphrase.enter")) |
349 |
|
|
return ctx->pass; |
350 |
|
|
if (!strcmp (key, "keygen.algo")) { |
351 |
twoaday |
129 |
_snprintf (buf, sizeof (buf)-1, "%d", ctx->pubkey_algo); |
352 |
werner |
36 |
return buf; |
353 |
|
|
} |
354 |
|
|
if (!strcmp (key, "keygen.size")) { |
355 |
twoaday |
129 |
_snprintf (buf, sizeof (buf)-1, "%d", ctx->pubkey_size); |
356 |
werner |
36 |
return buf; |
357 |
|
|
} |
358 |
|
|
if (!strcmp (key, "keygen.valid")) { |
359 |
twoaday |
176 |
_snprintf (buf, sizeof (buf)-1, "%d", ctx->getValidDays ()); |
360 |
werner |
36 |
return buf; |
361 |
|
|
} |
362 |
|
|
if (!strcmp (key, "keyedit.prompt")) { |
363 |
|
|
ctx->reset (); |
364 |
|
|
return "save"; |
365 |
|
|
} |
366 |
|
|
return NULL; |
367 |
|
|
} |
368 |
|
|
|
369 |
twoaday |
200 |
|
370 |
werner |
36 |
/* 'passwd' command handler. */ |
371 |
|
|
static const char* |
372 |
|
|
cmd_passwd_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key) |
373 |
|
|
{ |
374 |
|
|
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
375 |
|
|
ctx->cmd_sent = 1; |
376 |
|
|
return "passwd"; |
377 |
|
|
} |
378 |
twoaday |
200 |
if (ctx->cnt == 0 && !strcmp (key, "passphrase.enter")) { |
379 |
werner |
36 |
ctx->cnt = 1; |
380 |
twoaday |
220 |
/* it is possible that there is no old passphrase. */ |
381 |
|
|
if (!ctx->pass && ctx->flags) |
382 |
|
|
return ""; |
383 |
werner |
36 |
return ctx->pass; |
384 |
|
|
} |
385 |
twoaday |
129 |
if (!strcmp (key, "passphrase.enter" )) |
386 |
werner |
36 |
return ctx->new_pass; |
387 |
twoaday |
129 |
if (!strcmp (key, "change_passwd.empty.okay" )) |
388 |
werner |
36 |
return ctx->flags? "Y" : "N"; |
389 |
|
|
if (!strcmp (key, "keyedit.prompt")) { |
390 |
|
|
ctx->reset (); |
391 |
|
|
return "save"; |
392 |
|
|
} |
393 |
twoaday |
129 |
|
394 |
werner |
36 |
return NULL; |
395 |
|
|
} |
396 |
|
|
|
397 |
|
|
|
398 |
|
|
static const char* |
399 |
twoaday |
260 |
cmd_setpref_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key) |
400 |
werner |
36 |
{ |
401 |
twoaday |
220 |
static char buf[128] = {0}; |
402 |
twoaday |
129 |
|
403 |
twoaday |
260 |
if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) { |
404 |
|
|
_snprintf (buf, sizeof (buf)-1, "uid %d", ctx->getUseridIndex ()); |
405 |
werner |
36 |
ctx->cmd_sent = 1; |
406 |
twoaday |
260 |
ctx->cnt = 1; |
407 |
|
|
return buf; |
408 |
werner |
36 |
} |
409 |
twoaday |
260 |
if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 1) { |
410 |
|
|
_snprintf (buf, sizeof buf-1, "setpref %s", ctx->new_prefs); |
411 |
|
|
ctx->cnt = 2; |
412 |
werner |
36 |
return buf; |
413 |
|
|
} |
414 |
twoaday |
260 |
if (!strcmp (key, "keyedit.setpref.okay")) |
415 |
werner |
36 |
return "Y"; |
416 |
|
|
if (!strcmp (key, "passphrase.enter")) |
417 |
twoaday |
260 |
return ctx->pass; |
418 |
|
|
if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 2) { |
419 |
werner |
36 |
ctx->reset (); |
420 |
|
|
return "save"; |
421 |
|
|
} |
422 |
twoaday |
220 |
return buf; |
423 |
werner |
36 |
} |
424 |
|
|
|
425 |
|
|
|
426 |
|
|
/* 'primary' command handler. */ |
427 |
|
|
static const char* |
428 |
twoaday |
200 |
cmd_primary_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
429 |
|
|
const char *key) |
430 |
werner |
36 |
{ |
431 |
|
|
static char buf[64]; |
432 |
twoaday |
260 |
|
433 |
twoaday |
200 |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
434 |
twoaday |
170 |
sprintf (buf, "uid %d", ctx->getUseridIndex ()); |
435 |
twoaday |
200 |
ctx->cnt = 1; |
436 |
werner |
36 |
return buf; |
437 |
|
|
} |
438 |
twoaday |
200 |
if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt" )) { |
439 |
|
|
ctx->cnt = 2; |
440 |
werner |
36 |
return "primary"; |
441 |
|
|
} |
442 |
twoaday |
200 |
if (ctx->cnt == 2 && !strcmp (key, "passphrase.enter")) { |
443 |
|
|
ctx->cnt = 3; |
444 |
werner |
36 |
return ctx->pass; |
445 |
|
|
} |
446 |
twoaday |
200 |
if (ctx->cnt == 3 && !strcmp (key, "keyedit.prompt")) { |
447 |
werner |
36 |
ctx->reset (); |
448 |
|
|
return "save"; |
449 |
|
|
} |
450 |
|
|
return NULL; |
451 |
|
|
} |
452 |
|
|
|
453 |
twoaday |
200 |
|
454 |
werner |
36 |
/* 'expire' command handler. */ |
455 |
|
|
static const char* |
456 |
|
|
cmd_expire_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
457 |
twoaday |
200 |
const char *key) |
458 |
werner |
36 |
{ |
459 |
|
|
static char buf[64]; |
460 |
|
|
|
461 |
twoaday |
200 |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
462 |
twoaday |
170 |
sprintf (buf, "key %d", ctx->getKeyIndex ()); |
463 |
twoaday |
200 |
ctx->cnt = 1; |
464 |
werner |
36 |
return buf; |
465 |
|
|
} |
466 |
twoaday |
200 |
if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) { |
467 |
|
|
ctx->cnt = 2; |
468 |
werner |
36 |
return "expire"; |
469 |
|
|
} |
470 |
twoaday |
200 |
if (ctx->cnt == 2 && !strcmp (key, "keygen.valid" )) { |
471 |
|
|
ctx->cnt = 3; |
472 |
twoaday |
176 |
sprintf (buf, "%d", ctx->getValidDays ()); |
473 |
werner |
36 |
return buf; |
474 |
|
|
} |
475 |
twoaday |
200 |
if (ctx->cnt == 3 && !strcmp (key, "passphrase.enter")) { |
476 |
|
|
ctx->cnt = 4; |
477 |
werner |
36 |
return ctx->pass; |
478 |
|
|
} |
479 |
twoaday |
200 |
if (ctx->cnt == 4 && !strcmp (key, "keyedit.prompt")) { |
480 |
werner |
36 |
ctx->reset (); |
481 |
|
|
return "save"; |
482 |
|
|
} |
483 |
|
|
|
484 |
|
|
return NULL; |
485 |
|
|
} |
486 |
|
|
|
487 |
|
|
|
488 |
|
|
/* 'revuid' command handler. */ |
489 |
|
|
const char* |
490 |
|
|
cmd_revuid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
491 |
twoaday |
200 |
const char *key) |
492 |
werner |
36 |
{ |
493 |
|
|
static char buf[32]; |
494 |
|
|
|
495 |
twoaday |
200 |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
496 |
|
|
ctx->cnt = 1; |
497 |
twoaday |
170 |
sprintf (buf, "uid %d", ctx->getUseridIndex ()); |
498 |
werner |
36 |
return buf; |
499 |
|
|
} |
500 |
twoaday |
200 |
else if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) { |
501 |
|
|
ctx->cnt = 2; |
502 |
werner |
36 |
return "revuid"; |
503 |
|
|
} |
504 |
twoaday |
200 |
else if (ctx->cnt == 2 && !strcmp (key, "keyedit.revoke.uid.okay")) { |
505 |
|
|
ctx->cnt = 3; |
506 |
werner |
36 |
return "Y"; |
507 |
|
|
} |
508 |
twoaday |
200 |
else if (ctx->cnt == 3 && !strcmp (key, "ask_revocation_reason.code")) { |
509 |
|
|
ctx->cnt = 4; |
510 |
werner |
36 |
return "4"; |
511 |
|
|
} |
512 |
twoaday |
200 |
else if (ctx->cnt == 4 && !strcmp (key, "ask_revocation_reason.text")) { |
513 |
|
|
ctx->cnt = 5; |
514 |
werner |
36 |
return ""; |
515 |
|
|
} |
516 |
twoaday |
200 |
else if (ctx->cnt == 5 && !strcmp (key, "ask_revocation_reason.okay")) { |
517 |
|
|
ctx->cnt = 6; |
518 |
werner |
36 |
return "Y"; |
519 |
|
|
} |
520 |
twoaday |
200 |
else if (ctx->cnt == 6 && !strcmp (key, "passphrase.enter")) { |
521 |
|
|
ctx->cnt = 7; |
522 |
werner |
36 |
return ctx->pass; |
523 |
|
|
} |
524 |
twoaday |
200 |
else if (ctx->cnt == 7 && !strcmp (key, "keyedit.prompt")) { |
525 |
werner |
36 |
ctx->reset (); |
526 |
|
|
return "save"; |
527 |
|
|
} |
528 |
|
|
return NULL; |
529 |
|
|
} |
530 |
|
|
|
531 |
|
|
|
532 |
|
|
const char* |
533 |
|
|
cmd_revsig_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
534 |
twoaday |
200 |
const char *key) |
535 |
werner |
36 |
{ |
536 |
|
|
static char buf[64]; |
537 |
|
|
|
538 |
twoaday |
200 |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt" )) { |
539 |
twoaday |
170 |
sprintf( buf, "uid %d", ctx->getUseridIndex ()); |
540 |
twoaday |
200 |
ctx->cnt = 1; |
541 |
werner |
36 |
return buf; |
542 |
|
|
} |
543 |
twoaday |
200 |
if (ctx->cnt == 1 && !strcmp ( key, "keyedit.prompt" ) ) { |
544 |
|
|
ctx->cnt = 2; |
545 |
werner |
36 |
return "revsig"; |
546 |
|
|
} |
547 |
twoaday |
200 |
if (ctx->cnt == 2 && !strcmp (key, "ask_revoke_sig.one" ) ) { |
548 |
|
|
ctx->cnt = 3; |
549 |
werner |
36 |
return "Y"; |
550 |
|
|
} |
551 |
twoaday |
200 |
if (ctx->cnt == 3 && !strcmp (key, "ask_revoke_sig.okay" ) ) { |
552 |
|
|
ctx->cnt = 4; |
553 |
werner |
36 |
return "Y"; |
554 |
|
|
} |
555 |
twoaday |
200 |
if (ctx->cnt == 4 && !strcmp ( key, "ask_revocation_reason.code" ) ) { |
556 |
|
|
ctx->cnt = 5; |
557 |
werner |
36 |
return "0"; |
558 |
|
|
} |
559 |
twoaday |
200 |
if (ctx->cnt == 5 && !strcmp ( key, "ask_revocation_reason.text" ) ) { |
560 |
|
|
ctx->cnt = 6; |
561 |
werner |
36 |
return ""; |
562 |
|
|
} |
563 |
twoaday |
200 |
if (ctx->cnt == 6 && !strcmp (key, "ask_revocation_reason.okay" ) ) { |
564 |
|
|
ctx->cnt = 7; |
565 |
werner |
36 |
return "Y"; |
566 |
|
|
} |
567 |
twoaday |
200 |
if (ctx->cnt == 7 && !strcmp (key, "passphrase.enter" ) ) { |
568 |
|
|
ctx->cnt = 8; |
569 |
werner |
36 |
return ctx->pass; |
570 |
|
|
} |
571 |
twoaday |
200 |
if (ctx->cnt == 8 && !strcmp ( key, "keyedit.prompt" ) ) { |
572 |
werner |
36 |
ctx->reset (); |
573 |
|
|
return "save"; |
574 |
|
|
} |
575 |
|
|
|
576 |
|
|
return NULL; |
577 |
|
|
} |
578 |
|
|
|
579 |
|
|
|
580 |
|
|
/* 'revoke' command handler. */ |
581 |
|
|
static const char * |
582 |
|
|
cmd_revkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
583 |
twoaday |
200 |
const char *key) |
584 |
werner |
36 |
{ |
585 |
|
|
static char buf[64]; |
586 |
|
|
|
587 |
twoaday |
200 |
if (ctx->cnt == 0 && !strcmp ( key, "keyedit.prompt" ) ) { |
588 |
twoaday |
170 |
sprintf( buf, "key %d", ctx->getKeyIndex ()); |
589 |
twoaday |
200 |
ctx->cnt = 1; |
590 |
werner |
36 |
return buf; |
591 |
|
|
} |
592 |
twoaday |
200 |
if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) { |
593 |
|
|
ctx->cnt = 2; |
594 |
werner |
36 |
return "revkey"; |
595 |
|
|
} |
596 |
twoaday |
200 |
if (ctx->cnt == 2 && !strcmp (key, "keyedit.revoke.subkey.okay")) { |
597 |
|
|
ctx->cnt = 3; |
598 |
werner |
36 |
return "Y"; |
599 |
|
|
} |
600 |
twoaday |
200 |
if (ctx->cnt == 3 && !strcmp ( key, "ask_revocation_reason.code")) { |
601 |
werner |
36 |
sprintf( buf, "%d", ctx->reason); |
602 |
twoaday |
200 |
ctx->cnt = 4; |
603 |
werner |
36 |
return buf; |
604 |
|
|
} |
605 |
twoaday |
200 |
if (ctx->cnt == 4 && !strcmp (key, "ask_revocation_reason.text")) { |
606 |
|
|
ctx->cnt = 5; |
607 |
werner |
36 |
return ""; |
608 |
|
|
} |
609 |
twoaday |
200 |
if (ctx->cnt == 5 && !strcmp (key, "ask_revocation_reason.okay")) { |
610 |
|
|
ctx->cnt = 6; |
611 |
werner |
36 |
return "Y"; |
612 |
|
|
} |
613 |
twoaday |
200 |
if (ctx->cnt == 6 && !strcmp (key, "passphrase.enter")) { |
614 |
|
|
ctx->cnt = 7; |
615 |
werner |
36 |
return ctx->pass; |
616 |
|
|
} |
617 |
twoaday |
200 |
if (ctx->cnt == 7 && !strcmp ( key, "keyedit.prompt")) { |
618 |
werner |
36 |
ctx->reset (); |
619 |
|
|
return "save"; |
620 |
|
|
} |
621 |
|
|
return NULL; |
622 |
|
|
} |
623 |
|
|
|
624 |
|
|
|
625 |
|
|
/* 'addrevoker' command handler. */ |
626 |
|
|
static const char * |
627 |
|
|
cmd_addrev_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
628 |
twoaday |
200 |
const char *key) |
629 |
werner |
36 |
{ |
630 |
|
|
|
631 |
twoaday |
101 |
/* If the isuser already signed the key, send an empty |
632 |
twoaday |
119 |
string and jump to quit. */ |
633 |
twoaday |
129 |
if (ctx->getResult () & EDITKEY_ERR_ALREADY_SIGNED |
634 |
twoaday |
200 |
&& ctx->cnt != -1 && ctx->cnt != 4) { |
635 |
|
|
ctx->cnt = -1; |
636 |
twoaday |
101 |
return ""; |
637 |
|
|
} |
638 |
twoaday |
200 |
if (ctx->cnt == -1) { |
639 |
|
|
ctx->cnt = 4; |
640 |
twoaday |
101 |
return ""; /* empty value to abort. */ |
641 |
twoaday |
119 |
} |
642 |
twoaday |
200 |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
643 |
|
|
ctx->cnt = 1; |
644 |
werner |
36 |
return "addrevoker"; |
645 |
|
|
} |
646 |
twoaday |
200 |
if (ctx->cnt == 1 && !strcmp (key, "keyedit.add_revoker")) { |
647 |
|
|
ctx->cnt = 2; |
648 |
werner |
36 |
return ctx->name; |
649 |
|
|
} |
650 |
twoaday |
200 |
if (ctx->cnt == 2 && !strcmp (key, "keyedit.add_revoker.okay")) { |
651 |
|
|
ctx->cnt = 3; |
652 |
werner |
36 |
return "Y"; |
653 |
|
|
} |
654 |
twoaday |
200 |
if (ctx->cnt == 3 && !strcmp (key, "passphrase.enter")) { |
655 |
|
|
ctx->cnt = 4; |
656 |
werner |
36 |
return ctx->pass; |
657 |
|
|
} |
658 |
twoaday |
200 |
if (ctx->cnt == 4 && !strcmp (key, "keyedit.prompt")) { |
659 |
werner |
36 |
ctx->reset (); |
660 |
|
|
return "save"; |
661 |
|
|
} |
662 |
|
|
|
663 |
|
|
return NULL; |
664 |
|
|
} |
665 |
|
|
|
666 |
|
|
|
667 |
|
|
/* 'addphoto' command handler. */ |
668 |
|
|
static const char* |
669 |
|
|
cmd_addphoto_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key) |
670 |
|
|
{ |
671 |
|
|
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
672 |
|
|
ctx->cmd_sent = 1; |
673 |
|
|
return "addphoto"; |
674 |
|
|
} |
675 |
|
|
if (!strcmp (key, "photoid.jpeg.add")) |
676 |
|
|
return ctx->url; |
677 |
|
|
if (!strcmp (key, "photoid.jpeg.size")) |
678 |
|
|
return "Y"; |
679 |
|
|
if (!strcmp (key, "passphrase.enter")) |
680 |
|
|
return ctx->pass; |
681 |
|
|
if (!strcmp (key, "keyedit.prompt")) { |
682 |
|
|
ctx->reset (); |
683 |
|
|
return "save"; |
684 |
|
|
} |
685 |
|
|
return NULL; |
686 |
|
|
} |
687 |
|
|
|
688 |
twoaday |
119 |
|
689 |
twoaday |
207 |
static const char* |
690 |
|
|
cmd_minimize_handler (GpgKeyEdit *ctx, status_code_t code, const char *key) |
691 |
|
|
{ |
692 |
|
|
if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) { |
693 |
|
|
ctx->cmd_sent = 1; |
694 |
|
|
return "minimize"; |
695 |
|
|
} |
696 |
|
|
if (!strcmp (key, "keyedit.prompt")) { |
697 |
|
|
ctx->reset (); |
698 |
|
|
return "save"; |
699 |
|
|
} |
700 |
|
|
|
701 |
|
|
return NULL; |
702 |
|
|
} |
703 |
|
|
|
704 |
twoaday |
119 |
/* 'clean' command handler. */ |
705 |
|
|
static const char* |
706 |
twoaday |
207 |
cmd_clean_handler (GpgKeyEdit *ctx, status_code_t code, const char *key) |
707 |
twoaday |
119 |
{ |
708 |
|
|
if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) { |
709 |
|
|
ctx->cmd_sent = 1; |
710 |
|
|
return "clean"; |
711 |
|
|
} |
712 |
|
|
if (!strcmp (key, "keyedit.prompt")) { |
713 |
|
|
ctx->reset (); |
714 |
|
|
return "save"; |
715 |
|
|
} |
716 |
|
|
return NULL; |
717 |
|
|
} |
718 |
|
|
|
719 |
|
|
|
720 |
werner |
36 |
/* 'enable' and 'disable' command handler. */ |
721 |
|
|
static const char * |
722 |
|
|
cmd_enable_disable_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
723 |
|
|
const char * key, int mode) |
724 |
|
|
{ |
725 |
|
|
if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) { |
726 |
|
|
ctx->cmd_sent = 1; |
727 |
twoaday |
200 |
return mode? "disable": "enable"; |
728 |
werner |
36 |
} |
729 |
|
|
if (!strcmp (key, "keyedit.prompt")) { |
730 |
|
|
ctx->reset (); |
731 |
|
|
return "save"; |
732 |
|
|
} |
733 |
|
|
return NULL; |
734 |
|
|
} |
735 |
|
|
|
736 |
|
|
|
737 |
|
|
/* edit key dispatch handler. */ |
738 |
|
|
static gpgme_error_t |
739 |
|
|
editkey_command_handler (void *opaque, gpgme_status_code_t code, |
740 |
|
|
const char *key, int fd) |
741 |
|
|
{ |
742 |
|
|
const char *out = NULL; |
743 |
|
|
GpgKeyEdit *ke = (GpgKeyEdit *)opaque; |
744 |
|
|
HANDLE hd = (HANDLE)fd; |
745 |
|
|
DWORD n; |
746 |
|
|
|
747 |
|
|
if (!ke) |
748 |
|
|
return gpg_error (GPG_ERR_INV_ARG); |
749 |
|
|
|
750 |
|
|
/*log_debug ("key=%s code=%d\r\n", key, code);*/ |
751 |
|
|
switch (code) { |
752 |
|
|
case GPGME_STATUS_ALREADY_SIGNED: |
753 |
twoaday |
129 |
ke->setResult (EDITKEY_ERR_ALREADY_SIGNED); |
754 |
werner |
36 |
break; |
755 |
twoaday |
119 |
|
756 |
werner |
36 |
case GPGME_STATUS_BAD_PASSPHRASE: |
757 |
twoaday |
220 |
log_debug ("editkey_command_handler: bad passphrase\n"); |
758 |
twoaday |
129 |
ke->setResult (EDITKEY_ERR_BAD_PASSPHRASE); |
759 |
werner |
36 |
break; |
760 |
twoaday |
119 |
|
761 |
twoaday |
68 |
default: |
762 |
|
|
break; |
763 |
werner |
36 |
} |
764 |
|
|
|
765 |
twoaday |
129 |
if (ke->getResult () & EDITKEY_ERR_BAD_PASSPHRASE) { |
766 |
werner |
36 |
/* If the entered passphrase is bad, we supply empty |
767 |
|
|
passphrase to abort and send 'quit' as soon as possible. */ |
768 |
|
|
if (!strcmp (key, "passphrase.enter")) |
769 |
|
|
WriteFile (hd, "\n", 1, &n, NULL); |
770 |
|
|
if (!strcmp (key, "keyedit.prompt")) |
771 |
|
|
WriteFile (hd, "quit\n", 5, &n, NULL); |
772 |
twoaday |
129 |
ke->reset (); |
773 |
|
|
return 0; |
774 |
werner |
36 |
} |
775 |
|
|
|
776 |
|
|
switch (ke->getType ()) { |
777 |
|
|
case GPG_EDITKEY_LSIGN: |
778 |
|
|
case GPG_EDITKEY_SIGN: |
779 |
|
|
case GPG_EDITKEY_NRSIGN: |
780 |
|
|
case GPG_EDITKEY_TSIGN: |
781 |
|
|
case GPG_EDITKEY_NRLSIGN: |
782 |
|
|
out = cmd_sign_handler (ke, code, key); |
783 |
|
|
break; |
784 |
|
|
|
785 |
|
|
case GPG_EDITKEY_TRUST: |
786 |
|
|
out = cmd_trust_handler (ke, code, key); |
787 |
|
|
break; |
788 |
|
|
|
789 |
|
|
case GPG_EDITKEY_ADDUID: |
790 |
|
|
out = cmd_adduid_handler (ke, code, key); |
791 |
|
|
break; |
792 |
|
|
|
793 |
|
|
case GPG_EDITKEY_DELUID: |
794 |
twoaday |
200 |
out = cmd_deluid_handler (ke, code, key); |
795 |
werner |
36 |
break; |
796 |
|
|
|
797 |
|
|
case GPG_EDITKEY_DELSIG: |
798 |
twoaday |
260 |
out = cmd_delsig_handler (ke, code, key); |
799 |
werner |
36 |
break; |
800 |
|
|
|
801 |
|
|
case GPG_EDITKEY_DELKEY: |
802 |
twoaday |
200 |
out = cmd_delkey_handler(ke, code, key); |
803 |
werner |
36 |
break; |
804 |
|
|
|
805 |
|
|
case GPG_EDITKEY_ADDKEY: |
806 |
twoaday |
260 |
out = cmd_addkey_handler (ke, code, key); |
807 |
werner |
36 |
break; |
808 |
twoaday |
260 |
|
809 |
|
|
case GPG_EDITKEY_ADDCARDKEY: |
810 |
|
|
out = cmd_addcardkey_handler (ke, code, key); |
811 |
|
|
break; |
812 |
werner |
36 |
|
813 |
|
|
case GPG_EDITKEY_PASSWD: |
814 |
|
|
out = cmd_passwd_handler (ke, code, key); |
815 |
|
|
break; |
816 |
|
|
|
817 |
|
|
case GPG_EDITKEY_PRIMARY: |
818 |
twoaday |
200 |
out = cmd_primary_handler (ke, code, key); |
819 |
werner |
36 |
break; |
820 |
|
|
|
821 |
|
|
case GPG_EDITKEY_EXPIRE: |
822 |
twoaday |
200 |
out = cmd_expire_handler (ke, code, key); |
823 |
werner |
36 |
break; |
824 |
|
|
|
825 |
|
|
case GPG_EDITKEY_REVSIG: |
826 |
twoaday |
200 |
out = cmd_revsig_handler (ke, code, key); |
827 |
werner |
36 |
break; |
828 |
|
|
|
829 |
|
|
case GPG_EDITKEY_REVKEY: |
830 |
twoaday |
200 |
out = cmd_revkey_handler (ke, code, key); |
831 |
werner |
36 |
break; |
832 |
|
|
|
833 |
|
|
case GPG_EDITKEY_REVUID: |
834 |
twoaday |
200 |
out = cmd_revuid_handler (ke, code, key); |
835 |
werner |
36 |
break; |
836 |
|
|
|
837 |
|
|
case GPG_EDITKEY_ADDREV: |
838 |
twoaday |
200 |
out = cmd_addrev_handler (ke, code, key); |
839 |
werner |
36 |
break; |
840 |
|
|
|
841 |
|
|
case GPG_EDITKEY_ADDPHOTO: |
842 |
|
|
out = cmd_addphoto_handler (ke, code, key); |
843 |
|
|
break; |
844 |
|
|
|
845 |
twoaday |
200 |
case GPG_EDITKEY_NOTATION: |
846 |
|
|
out = cmd_notation_handler (ke, code, key); |
847 |
|
|
break; |
848 |
|
|
|
849 |
twoaday |
207 |
case GPG_EDITKEY_MINIMIZE: |
850 |
|
|
out = cmd_minimize_handler (ke, code, key); |
851 |
|
|
break; |
852 |
|
|
|
853 |
twoaday |
119 |
case GPG_EDITKEY_CLEAN: |
854 |
|
|
out = cmd_clean_handler (ke, code, key); |
855 |
|
|
break; |
856 |
|
|
|
857 |
werner |
36 |
case GPG_EDITKEY_ENABLE: |
858 |
|
|
case GPG_EDITKEY_DISABLE: |
859 |
twoaday |
200 |
n = ke->getType () == GPG_EDITKEY_DISABLE? 1: 0; |
860 |
|
|
out = cmd_enable_disable_handler (ke, code, key, n); |
861 |
werner |
36 |
break; |
862 |
|
|
|
863 |
|
|
case GPG_EDITKEY_SETPREF: |
864 |
|
|
out = cmd_setpref_handler (ke, code, key); |
865 |
|
|
break; |
866 |
|
|
|
867 |
|
|
case GPG_EDITKEY_KEYSERV: |
868 |
|
|
out = cmd_keyserv_handler (ke, code, key); |
869 |
|
|
break; |
870 |
|
|
} |
871 |
|
|
|
872 |
|
|
if (out != NULL) { |
873 |
|
|
WriteFile (hd, out, strlen (out), &n, NULL); |
874 |
|
|
WriteFile (hd, "\n", 1, &n, NULL); |
875 |
|
|
} |
876 |
|
|
return 0; |
877 |
|
|
} |
878 |
|
|
|
879 |
|
|
|
880 |
|
|
/* Check if a GPG status code occured which marks the |
881 |
|
|
current operation as failed. |
882 |
|
|
Return value: gpg error constant. */ |
883 |
|
|
static gpgme_error_t |
884 |
|
|
map_result (GpgKeyEdit *ke) |
885 |
|
|
{ |
886 |
twoaday |
101 |
/* XXX Sometimes ALREADY_SIGNED indicates an failure. */ |
887 |
werner |
36 |
if (!ke->getResult ()) |
888 |
|
|
return gpg_error (GPG_ERR_NO_ERROR); |
889 |
twoaday |
129 |
if (ke->getResult () & EDITKEY_ERR_BAD_PASSPHRASE) |
890 |
werner |
36 |
return gpg_error (GPG_ERR_BAD_PASSPHRASE); |
891 |
|
|
return 0; |
892 |
|
|
} |
893 |
|
|
|
894 |
|
|
|
895 |
|
|
/* Wrapper around the gpgme edit interface. |
896 |
|
|
@ctx context to use. |
897 |
|
|
@key key on which the operation should be performed. |
898 |
|
|
@ek key edit context. |
899 |
|
|
Return value: 0 on success. */ |
900 |
|
|
gpgme_error_t |
901 |
|
|
gpg_editkey (gpgme_ctx_t ctx, gpgme_key_t key, GpgKeyEdit *ek) |
902 |
|
|
{ |
903 |
|
|
gpgme_error_t err; |
904 |
|
|
gpgme_data_t out; |
905 |
|
|
|
906 |
|
|
err = gpgme_data_new (&out); |
907 |
|
|
if (err) |
908 |
|
|
return err; |
909 |
|
|
err = gpgme_op_edit (ctx, key, editkey_command_handler, ek, out); |
910 |
|
|
if (!err) |
911 |
|
|
err = map_result (ek); |
912 |
|
|
|
913 |
|
|
gpgme_data_release (out); |
914 |
|
|
return err; |
915 |
|
|
} |