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