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