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