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