/[winpt]/trunk/Src/wptKeyEditCB.cpp
ViewVC logotype

Annotation of /trunk/Src/wptKeyEditCB.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 170 - (hide annotations)
Mon Jan 30 12:42:57 2006 UTC (19 years, 1 month ago) by twoaday
File size: 20762 byte(s)
2006-01-29  Timo Schulz  <ts@g10code.de>
 
        * wptKeyPropsDlg.cpp (keyprops_dlg_proc): Allow to use ESC
        to quit dialog.
        * wptKeysignDlg.cpp (sig_class_dlg_proc): More space for
        translations. Directly return sig class.
        (keysign_dlg_proc): Change msgbox title.
        * wptKeyEdit.cpp (signUserid): New.
        (getUseridIndex): New.
        (getKeyIndex): New.
        (getSigIndex): New.
        (clear): New.
        * wptKeyEditCB.cpp (cmd_sign_handler): Allow to select
        user-id first.
        * wptKeyEditDlgs.cpp (lookup_cmd): New.
        (do_editkey_sign_userid): New.
        (do_init_cmdlist): Differ between key pairs and public keys
        and allowed actions.
        (keyedit_change_ownertrust): Show msgbox on success.
        (get_default_key): New.
        * wptPassphraseDlg.cpp (request_passphrase): Reset @cancel.
         


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26