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