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 |
twoaday |
273 |
/* 'setpref' command handler. */ |
399 |
werner |
36 |
static const char* |
400 |
twoaday |
260 |
cmd_setpref_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key) |
401 |
werner |
36 |
{ |
402 |
twoaday |
220 |
static char buf[128] = {0}; |
403 |
twoaday |
129 |
|
404 |
twoaday |
260 |
if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) { |
405 |
|
|
_snprintf (buf, sizeof (buf)-1, "uid %d", ctx->getUseridIndex ()); |
406 |
werner |
36 |
ctx->cmd_sent = 1; |
407 |
twoaday |
260 |
ctx->cnt = 1; |
408 |
|
|
return buf; |
409 |
werner |
36 |
} |
410 |
twoaday |
260 |
if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 1) { |
411 |
|
|
_snprintf (buf, sizeof buf-1, "setpref %s", ctx->new_prefs); |
412 |
|
|
ctx->cnt = 2; |
413 |
werner |
36 |
return buf; |
414 |
|
|
} |
415 |
twoaday |
260 |
if (!strcmp (key, "keyedit.setpref.okay")) |
416 |
werner |
36 |
return "Y"; |
417 |
|
|
if (!strcmp (key, "passphrase.enter")) |
418 |
twoaday |
260 |
return ctx->pass; |
419 |
|
|
if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 2) { |
420 |
werner |
36 |
ctx->reset (); |
421 |
|
|
return "save"; |
422 |
|
|
} |
423 |
twoaday |
220 |
return buf; |
424 |
werner |
36 |
} |
425 |
|
|
|
426 |
|
|
|
427 |
|
|
/* 'primary' command handler. */ |
428 |
|
|
static const char* |
429 |
twoaday |
200 |
cmd_primary_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
430 |
|
|
const char *key) |
431 |
werner |
36 |
{ |
432 |
|
|
static char buf[64]; |
433 |
twoaday |
260 |
|
434 |
twoaday |
200 |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
435 |
twoaday |
170 |
sprintf (buf, "uid %d", ctx->getUseridIndex ()); |
436 |
twoaday |
200 |
ctx->cnt = 1; |
437 |
werner |
36 |
return buf; |
438 |
|
|
} |
439 |
twoaday |
200 |
if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt" )) { |
440 |
|
|
ctx->cnt = 2; |
441 |
werner |
36 |
return "primary"; |
442 |
|
|
} |
443 |
twoaday |
200 |
if (ctx->cnt == 2 && !strcmp (key, "passphrase.enter")) { |
444 |
|
|
ctx->cnt = 3; |
445 |
werner |
36 |
return ctx->pass; |
446 |
|
|
} |
447 |
twoaday |
200 |
if (ctx->cnt == 3 && !strcmp (key, "keyedit.prompt")) { |
448 |
werner |
36 |
ctx->reset (); |
449 |
|
|
return "save"; |
450 |
|
|
} |
451 |
|
|
return NULL; |
452 |
|
|
} |
453 |
|
|
|
454 |
twoaday |
200 |
|
455 |
werner |
36 |
/* 'expire' command handler. */ |
456 |
|
|
static const char* |
457 |
|
|
cmd_expire_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
458 |
twoaday |
200 |
const char *key) |
459 |
werner |
36 |
{ |
460 |
|
|
static char buf[64]; |
461 |
|
|
|
462 |
twoaday |
200 |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
463 |
twoaday |
170 |
sprintf (buf, "key %d", ctx->getKeyIndex ()); |
464 |
twoaday |
200 |
ctx->cnt = 1; |
465 |
werner |
36 |
return buf; |
466 |
|
|
} |
467 |
twoaday |
200 |
if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) { |
468 |
|
|
ctx->cnt = 2; |
469 |
werner |
36 |
return "expire"; |
470 |
|
|
} |
471 |
twoaday |
200 |
if (ctx->cnt == 2 && !strcmp (key, "keygen.valid" )) { |
472 |
|
|
ctx->cnt = 3; |
473 |
twoaday |
176 |
sprintf (buf, "%d", ctx->getValidDays ()); |
474 |
werner |
36 |
return buf; |
475 |
|
|
} |
476 |
twoaday |
200 |
if (ctx->cnt == 3 && !strcmp (key, "passphrase.enter")) { |
477 |
|
|
ctx->cnt = 4; |
478 |
werner |
36 |
return ctx->pass; |
479 |
|
|
} |
480 |
twoaday |
200 |
if (ctx->cnt == 4 && !strcmp (key, "keyedit.prompt")) { |
481 |
werner |
36 |
ctx->reset (); |
482 |
|
|
return "save"; |
483 |
|
|
} |
484 |
|
|
|
485 |
|
|
return NULL; |
486 |
|
|
} |
487 |
|
|
|
488 |
|
|
|
489 |
|
|
/* 'revuid' command handler. */ |
490 |
|
|
const char* |
491 |
|
|
cmd_revuid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
492 |
twoaday |
200 |
const char *key) |
493 |
werner |
36 |
{ |
494 |
|
|
static char buf[32]; |
495 |
|
|
|
496 |
twoaday |
200 |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
497 |
|
|
ctx->cnt = 1; |
498 |
twoaday |
170 |
sprintf (buf, "uid %d", ctx->getUseridIndex ()); |
499 |
werner |
36 |
return buf; |
500 |
|
|
} |
501 |
twoaday |
200 |
else if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) { |
502 |
|
|
ctx->cnt = 2; |
503 |
werner |
36 |
return "revuid"; |
504 |
|
|
} |
505 |
twoaday |
200 |
else if (ctx->cnt == 2 && !strcmp (key, "keyedit.revoke.uid.okay")) { |
506 |
|
|
ctx->cnt = 3; |
507 |
werner |
36 |
return "Y"; |
508 |
|
|
} |
509 |
twoaday |
200 |
else if (ctx->cnt == 3 && !strcmp (key, "ask_revocation_reason.code")) { |
510 |
|
|
ctx->cnt = 4; |
511 |
werner |
36 |
return "4"; |
512 |
|
|
} |
513 |
twoaday |
200 |
else if (ctx->cnt == 4 && !strcmp (key, "ask_revocation_reason.text")) { |
514 |
|
|
ctx->cnt = 5; |
515 |
werner |
36 |
return ""; |
516 |
|
|
} |
517 |
twoaday |
200 |
else if (ctx->cnt == 5 && !strcmp (key, "ask_revocation_reason.okay")) { |
518 |
|
|
ctx->cnt = 6; |
519 |
werner |
36 |
return "Y"; |
520 |
|
|
} |
521 |
twoaday |
200 |
else if (ctx->cnt == 6 && !strcmp (key, "passphrase.enter")) { |
522 |
|
|
ctx->cnt = 7; |
523 |
werner |
36 |
return ctx->pass; |
524 |
|
|
} |
525 |
twoaday |
200 |
else if (ctx->cnt == 7 && !strcmp (key, "keyedit.prompt")) { |
526 |
werner |
36 |
ctx->reset (); |
527 |
|
|
return "save"; |
528 |
|
|
} |
529 |
|
|
return NULL; |
530 |
|
|
} |
531 |
|
|
|
532 |
|
|
|
533 |
|
|
const char* |
534 |
|
|
cmd_revsig_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
535 |
twoaday |
200 |
const char *key) |
536 |
werner |
36 |
{ |
537 |
|
|
static char buf[64]; |
538 |
|
|
|
539 |
twoaday |
200 |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt" )) { |
540 |
twoaday |
170 |
sprintf( buf, "uid %d", ctx->getUseridIndex ()); |
541 |
twoaday |
200 |
ctx->cnt = 1; |
542 |
werner |
36 |
return buf; |
543 |
|
|
} |
544 |
twoaday |
200 |
if (ctx->cnt == 1 && !strcmp ( key, "keyedit.prompt" ) ) { |
545 |
|
|
ctx->cnt = 2; |
546 |
werner |
36 |
return "revsig"; |
547 |
|
|
} |
548 |
twoaday |
200 |
if (ctx->cnt == 2 && !strcmp (key, "ask_revoke_sig.one" ) ) { |
549 |
|
|
ctx->cnt = 3; |
550 |
werner |
36 |
return "Y"; |
551 |
|
|
} |
552 |
twoaday |
200 |
if (ctx->cnt == 3 && !strcmp (key, "ask_revoke_sig.okay" ) ) { |
553 |
|
|
ctx->cnt = 4; |
554 |
werner |
36 |
return "Y"; |
555 |
|
|
} |
556 |
twoaday |
200 |
if (ctx->cnt == 4 && !strcmp ( key, "ask_revocation_reason.code" ) ) { |
557 |
|
|
ctx->cnt = 5; |
558 |
werner |
36 |
return "0"; |
559 |
|
|
} |
560 |
twoaday |
200 |
if (ctx->cnt == 5 && !strcmp ( key, "ask_revocation_reason.text" ) ) { |
561 |
|
|
ctx->cnt = 6; |
562 |
werner |
36 |
return ""; |
563 |
|
|
} |
564 |
twoaday |
200 |
if (ctx->cnt == 6 && !strcmp (key, "ask_revocation_reason.okay" ) ) { |
565 |
|
|
ctx->cnt = 7; |
566 |
werner |
36 |
return "Y"; |
567 |
|
|
} |
568 |
twoaday |
200 |
if (ctx->cnt == 7 && !strcmp (key, "passphrase.enter" ) ) { |
569 |
|
|
ctx->cnt = 8; |
570 |
werner |
36 |
return ctx->pass; |
571 |
|
|
} |
572 |
twoaday |
200 |
if (ctx->cnt == 8 && !strcmp ( key, "keyedit.prompt" ) ) { |
573 |
werner |
36 |
ctx->reset (); |
574 |
|
|
return "save"; |
575 |
|
|
} |
576 |
|
|
|
577 |
|
|
return NULL; |
578 |
|
|
} |
579 |
|
|
|
580 |
|
|
|
581 |
|
|
/* 'revoke' command handler. */ |
582 |
|
|
static const char * |
583 |
|
|
cmd_revkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
584 |
twoaday |
200 |
const char *key) |
585 |
werner |
36 |
{ |
586 |
|
|
static char buf[64]; |
587 |
|
|
|
588 |
twoaday |
200 |
if (ctx->cnt == 0 && !strcmp ( key, "keyedit.prompt" ) ) { |
589 |
twoaday |
170 |
sprintf( buf, "key %d", ctx->getKeyIndex ()); |
590 |
twoaday |
200 |
ctx->cnt = 1; |
591 |
werner |
36 |
return buf; |
592 |
|
|
} |
593 |
twoaday |
200 |
if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) { |
594 |
|
|
ctx->cnt = 2; |
595 |
werner |
36 |
return "revkey"; |
596 |
|
|
} |
597 |
twoaday |
200 |
if (ctx->cnt == 2 && !strcmp (key, "keyedit.revoke.subkey.okay")) { |
598 |
|
|
ctx->cnt = 3; |
599 |
werner |
36 |
return "Y"; |
600 |
|
|
} |
601 |
twoaday |
200 |
if (ctx->cnt == 3 && !strcmp ( key, "ask_revocation_reason.code")) { |
602 |
werner |
36 |
sprintf( buf, "%d", ctx->reason); |
603 |
twoaday |
200 |
ctx->cnt = 4; |
604 |
werner |
36 |
return buf; |
605 |
|
|
} |
606 |
twoaday |
200 |
if (ctx->cnt == 4 && !strcmp (key, "ask_revocation_reason.text")) { |
607 |
|
|
ctx->cnt = 5; |
608 |
werner |
36 |
return ""; |
609 |
|
|
} |
610 |
twoaday |
200 |
if (ctx->cnt == 5 && !strcmp (key, "ask_revocation_reason.okay")) { |
611 |
|
|
ctx->cnt = 6; |
612 |
werner |
36 |
return "Y"; |
613 |
|
|
} |
614 |
twoaday |
200 |
if (ctx->cnt == 6 && !strcmp (key, "passphrase.enter")) { |
615 |
|
|
ctx->cnt = 7; |
616 |
werner |
36 |
return ctx->pass; |
617 |
|
|
} |
618 |
twoaday |
200 |
if (ctx->cnt == 7 && !strcmp ( key, "keyedit.prompt")) { |
619 |
werner |
36 |
ctx->reset (); |
620 |
|
|
return "save"; |
621 |
|
|
} |
622 |
|
|
return NULL; |
623 |
|
|
} |
624 |
|
|
|
625 |
|
|
|
626 |
|
|
/* 'addrevoker' command handler. */ |
627 |
|
|
static const char * |
628 |
|
|
cmd_addrev_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
629 |
twoaday |
200 |
const char *key) |
630 |
werner |
36 |
{ |
631 |
|
|
|
632 |
twoaday |
101 |
/* If the isuser already signed the key, send an empty |
633 |
twoaday |
119 |
string and jump to quit. */ |
634 |
twoaday |
129 |
if (ctx->getResult () & EDITKEY_ERR_ALREADY_SIGNED |
635 |
twoaday |
200 |
&& ctx->cnt != -1 && ctx->cnt != 4) { |
636 |
|
|
ctx->cnt = -1; |
637 |
twoaday |
101 |
return ""; |
638 |
|
|
} |
639 |
twoaday |
200 |
if (ctx->cnt == -1) { |
640 |
|
|
ctx->cnt = 4; |
641 |
twoaday |
101 |
return ""; /* empty value to abort. */ |
642 |
twoaday |
119 |
} |
643 |
twoaday |
200 |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
644 |
|
|
ctx->cnt = 1; |
645 |
werner |
36 |
return "addrevoker"; |
646 |
|
|
} |
647 |
twoaday |
200 |
if (ctx->cnt == 1 && !strcmp (key, "keyedit.add_revoker")) { |
648 |
|
|
ctx->cnt = 2; |
649 |
werner |
36 |
return ctx->name; |
650 |
|
|
} |
651 |
twoaday |
200 |
if (ctx->cnt == 2 && !strcmp (key, "keyedit.add_revoker.okay")) { |
652 |
|
|
ctx->cnt = 3; |
653 |
werner |
36 |
return "Y"; |
654 |
|
|
} |
655 |
twoaday |
200 |
if (ctx->cnt == 3 && !strcmp (key, "passphrase.enter")) { |
656 |
|
|
ctx->cnt = 4; |
657 |
werner |
36 |
return ctx->pass; |
658 |
|
|
} |
659 |
twoaday |
200 |
if (ctx->cnt == 4 && !strcmp (key, "keyedit.prompt")) { |
660 |
werner |
36 |
ctx->reset (); |
661 |
|
|
return "save"; |
662 |
|
|
} |
663 |
|
|
|
664 |
|
|
return NULL; |
665 |
|
|
} |
666 |
|
|
|
667 |
|
|
|
668 |
|
|
/* 'addphoto' command handler. */ |
669 |
|
|
static const char* |
670 |
|
|
cmd_addphoto_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key) |
671 |
|
|
{ |
672 |
|
|
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
673 |
|
|
ctx->cmd_sent = 1; |
674 |
|
|
return "addphoto"; |
675 |
|
|
} |
676 |
|
|
if (!strcmp (key, "photoid.jpeg.add")) |
677 |
|
|
return ctx->url; |
678 |
|
|
if (!strcmp (key, "photoid.jpeg.size")) |
679 |
|
|
return "Y"; |
680 |
|
|
if (!strcmp (key, "passphrase.enter")) |
681 |
|
|
return ctx->pass; |
682 |
|
|
if (!strcmp (key, "keyedit.prompt")) { |
683 |
|
|
ctx->reset (); |
684 |
|
|
return "save"; |
685 |
|
|
} |
686 |
|
|
return NULL; |
687 |
|
|
} |
688 |
|
|
|
689 |
twoaday |
119 |
|
690 |
twoaday |
207 |
static const char* |
691 |
|
|
cmd_minimize_handler (GpgKeyEdit *ctx, status_code_t code, const char *key) |
692 |
|
|
{ |
693 |
|
|
if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) { |
694 |
|
|
ctx->cmd_sent = 1; |
695 |
|
|
return "minimize"; |
696 |
|
|
} |
697 |
|
|
if (!strcmp (key, "keyedit.prompt")) { |
698 |
|
|
ctx->reset (); |
699 |
|
|
return "save"; |
700 |
|
|
} |
701 |
|
|
|
702 |
|
|
return NULL; |
703 |
|
|
} |
704 |
|
|
|
705 |
twoaday |
119 |
/* 'clean' command handler. */ |
706 |
|
|
static const char* |
707 |
twoaday |
207 |
cmd_clean_handler (GpgKeyEdit *ctx, status_code_t code, const char *key) |
708 |
twoaday |
119 |
{ |
709 |
|
|
if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) { |
710 |
|
|
ctx->cmd_sent = 1; |
711 |
|
|
return "clean"; |
712 |
|
|
} |
713 |
|
|
if (!strcmp (key, "keyedit.prompt")) { |
714 |
|
|
ctx->reset (); |
715 |
|
|
return "save"; |
716 |
|
|
} |
717 |
|
|
return NULL; |
718 |
|
|
} |
719 |
|
|
|
720 |
|
|
|
721 |
werner |
36 |
/* 'enable' and 'disable' command handler. */ |
722 |
|
|
static const char * |
723 |
|
|
cmd_enable_disable_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
724 |
|
|
const char * key, int mode) |
725 |
|
|
{ |
726 |
|
|
if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) { |
727 |
|
|
ctx->cmd_sent = 1; |
728 |
twoaday |
200 |
return mode? "disable": "enable"; |
729 |
werner |
36 |
} |
730 |
|
|
if (!strcmp (key, "keyedit.prompt")) { |
731 |
|
|
ctx->reset (); |
732 |
|
|
return "save"; |
733 |
|
|
} |
734 |
|
|
return NULL; |
735 |
|
|
} |
736 |
|
|
|
737 |
|
|
|
738 |
|
|
/* edit key dispatch handler. */ |
739 |
|
|
static gpgme_error_t |
740 |
|
|
editkey_command_handler (void *opaque, gpgme_status_code_t code, |
741 |
|
|
const char *key, int fd) |
742 |
|
|
{ |
743 |
|
|
const char *out = NULL; |
744 |
|
|
GpgKeyEdit *ke = (GpgKeyEdit *)opaque; |
745 |
|
|
HANDLE hd = (HANDLE)fd; |
746 |
|
|
DWORD n; |
747 |
|
|
|
748 |
|
|
if (!ke) |
749 |
|
|
return gpg_error (GPG_ERR_INV_ARG); |
750 |
|
|
|
751 |
|
|
/*log_debug ("key=%s code=%d\r\n", key, code);*/ |
752 |
|
|
switch (code) { |
753 |
|
|
case GPGME_STATUS_ALREADY_SIGNED: |
754 |
twoaday |
129 |
ke->setResult (EDITKEY_ERR_ALREADY_SIGNED); |
755 |
werner |
36 |
break; |
756 |
twoaday |
119 |
|
757 |
werner |
36 |
case GPGME_STATUS_BAD_PASSPHRASE: |
758 |
twoaday |
220 |
log_debug ("editkey_command_handler: bad passphrase\n"); |
759 |
twoaday |
129 |
ke->setResult (EDITKEY_ERR_BAD_PASSPHRASE); |
760 |
werner |
36 |
break; |
761 |
twoaday |
119 |
|
762 |
twoaday |
68 |
default: |
763 |
|
|
break; |
764 |
werner |
36 |
} |
765 |
|
|
|
766 |
twoaday |
129 |
if (ke->getResult () & EDITKEY_ERR_BAD_PASSPHRASE) { |
767 |
werner |
36 |
/* If the entered passphrase is bad, we supply empty |
768 |
|
|
passphrase to abort and send 'quit' as soon as possible. */ |
769 |
|
|
if (!strcmp (key, "passphrase.enter")) |
770 |
|
|
WriteFile (hd, "\n", 1, &n, NULL); |
771 |
|
|
if (!strcmp (key, "keyedit.prompt")) |
772 |
|
|
WriteFile (hd, "quit\n", 5, &n, NULL); |
773 |
twoaday |
129 |
ke->reset (); |
774 |
|
|
return 0; |
775 |
werner |
36 |
} |
776 |
|
|
|
777 |
|
|
switch (ke->getType ()) { |
778 |
|
|
case GPG_EDITKEY_LSIGN: |
779 |
|
|
case GPG_EDITKEY_SIGN: |
780 |
|
|
case GPG_EDITKEY_NRSIGN: |
781 |
|
|
case GPG_EDITKEY_TSIGN: |
782 |
|
|
case GPG_EDITKEY_NRLSIGN: |
783 |
|
|
out = cmd_sign_handler (ke, code, key); |
784 |
|
|
break; |
785 |
|
|
|
786 |
|
|
case GPG_EDITKEY_TRUST: |
787 |
|
|
out = cmd_trust_handler (ke, code, key); |
788 |
|
|
break; |
789 |
|
|
|
790 |
|
|
case GPG_EDITKEY_ADDUID: |
791 |
|
|
out = cmd_adduid_handler (ke, code, key); |
792 |
|
|
break; |
793 |
|
|
|
794 |
|
|
case GPG_EDITKEY_DELUID: |
795 |
twoaday |
200 |
out = cmd_deluid_handler (ke, code, key); |
796 |
werner |
36 |
break; |
797 |
|
|
|
798 |
|
|
case GPG_EDITKEY_DELSIG: |
799 |
twoaday |
260 |
out = cmd_delsig_handler (ke, code, key); |
800 |
werner |
36 |
break; |
801 |
|
|
|
802 |
|
|
case GPG_EDITKEY_DELKEY: |
803 |
twoaday |
200 |
out = cmd_delkey_handler(ke, code, key); |
804 |
werner |
36 |
break; |
805 |
|
|
|
806 |
|
|
case GPG_EDITKEY_ADDKEY: |
807 |
twoaday |
260 |
out = cmd_addkey_handler (ke, code, key); |
808 |
werner |
36 |
break; |
809 |
twoaday |
260 |
|
810 |
|
|
case GPG_EDITKEY_ADDCARDKEY: |
811 |
|
|
out = cmd_addcardkey_handler (ke, code, key); |
812 |
|
|
break; |
813 |
werner |
36 |
|
814 |
|
|
case GPG_EDITKEY_PASSWD: |
815 |
|
|
out = cmd_passwd_handler (ke, code, key); |
816 |
|
|
break; |
817 |
|
|
|
818 |
|
|
case GPG_EDITKEY_PRIMARY: |
819 |
twoaday |
200 |
out = cmd_primary_handler (ke, code, key); |
820 |
werner |
36 |
break; |
821 |
|
|
|
822 |
|
|
case GPG_EDITKEY_EXPIRE: |
823 |
twoaday |
200 |
out = cmd_expire_handler (ke, code, key); |
824 |
werner |
36 |
break; |
825 |
|
|
|
826 |
|
|
case GPG_EDITKEY_REVSIG: |
827 |
twoaday |
200 |
out = cmd_revsig_handler (ke, code, key); |
828 |
werner |
36 |
break; |
829 |
|
|
|
830 |
|
|
case GPG_EDITKEY_REVKEY: |
831 |
twoaday |
200 |
out = cmd_revkey_handler (ke, code, key); |
832 |
werner |
36 |
break; |
833 |
|
|
|
834 |
|
|
case GPG_EDITKEY_REVUID: |
835 |
twoaday |
200 |
out = cmd_revuid_handler (ke, code, key); |
836 |
werner |
36 |
break; |
837 |
|
|
|
838 |
|
|
case GPG_EDITKEY_ADDREV: |
839 |
twoaday |
200 |
out = cmd_addrev_handler (ke, code, key); |
840 |
werner |
36 |
break; |
841 |
|
|
|
842 |
|
|
case GPG_EDITKEY_ADDPHOTO: |
843 |
|
|
out = cmd_addphoto_handler (ke, code, key); |
844 |
|
|
break; |
845 |
|
|
|
846 |
twoaday |
200 |
case GPG_EDITKEY_NOTATION: |
847 |
|
|
out = cmd_notation_handler (ke, code, key); |
848 |
|
|
break; |
849 |
|
|
|
850 |
twoaday |
207 |
case GPG_EDITKEY_MINIMIZE: |
851 |
|
|
out = cmd_minimize_handler (ke, code, key); |
852 |
|
|
break; |
853 |
|
|
|
854 |
twoaday |
119 |
case GPG_EDITKEY_CLEAN: |
855 |
|
|
out = cmd_clean_handler (ke, code, key); |
856 |
|
|
break; |
857 |
|
|
|
858 |
werner |
36 |
case GPG_EDITKEY_ENABLE: |
859 |
|
|
case GPG_EDITKEY_DISABLE: |
860 |
twoaday |
200 |
n = ke->getType () == GPG_EDITKEY_DISABLE? 1: 0; |
861 |
|
|
out = cmd_enable_disable_handler (ke, code, key, n); |
862 |
werner |
36 |
break; |
863 |
|
|
|
864 |
|
|
case GPG_EDITKEY_SETPREF: |
865 |
|
|
out = cmd_setpref_handler (ke, code, key); |
866 |
|
|
break; |
867 |
|
|
|
868 |
|
|
case GPG_EDITKEY_KEYSERV: |
869 |
|
|
out = cmd_keyserv_handler (ke, code, key); |
870 |
|
|
break; |
871 |
|
|
} |
872 |
|
|
|
873 |
|
|
if (out != NULL) { |
874 |
|
|
WriteFile (hd, out, strlen (out), &n, NULL); |
875 |
|
|
WriteFile (hd, "\n", 1, &n, NULL); |
876 |
|
|
} |
877 |
|
|
return 0; |
878 |
|
|
} |
879 |
|
|
|
880 |
|
|
|
881 |
|
|
/* Check if a GPG status code occured which marks the |
882 |
|
|
current operation as failed. |
883 |
|
|
Return value: gpg error constant. */ |
884 |
|
|
static gpgme_error_t |
885 |
|
|
map_result (GpgKeyEdit *ke) |
886 |
|
|
{ |
887 |
twoaday |
101 |
/* XXX Sometimes ALREADY_SIGNED indicates an failure. */ |
888 |
werner |
36 |
if (!ke->getResult ()) |
889 |
|
|
return gpg_error (GPG_ERR_NO_ERROR); |
890 |
twoaday |
129 |
if (ke->getResult () & EDITKEY_ERR_BAD_PASSPHRASE) |
891 |
werner |
36 |
return gpg_error (GPG_ERR_BAD_PASSPHRASE); |
892 |
|
|
return 0; |
893 |
|
|
} |
894 |
|
|
|
895 |
|
|
|
896 |
|
|
/* Wrapper around the gpgme edit interface. |
897 |
|
|
@ctx context to use. |
898 |
|
|
@key key on which the operation should be performed. |
899 |
|
|
@ek key edit context. |
900 |
|
|
Return value: 0 on success. */ |
901 |
|
|
gpgme_error_t |
902 |
|
|
gpg_editkey (gpgme_ctx_t ctx, gpgme_key_t key, GpgKeyEdit *ek) |
903 |
|
|
{ |
904 |
|
|
gpgme_error_t err; |
905 |
|
|
gpgme_data_t out; |
906 |
|
|
|
907 |
|
|
err = gpgme_data_new (&out); |
908 |
|
|
if (err) |
909 |
|
|
return err; |
910 |
|
|
err = gpgme_op_edit (ctx, key, editkey_command_handler, ek, out); |
911 |
|
|
if (!err) |
912 |
|
|
err = map_result (ek); |
913 |
|
|
|
914 |
|
|
gpgme_data_release (out); |
915 |
|
|
return err; |
916 |
|
|
} |