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

Annotation of /trunk/Src/wptKeyEditCB.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 129 - (hide annotations)
Fri Dec 30 13:56:10 2005 UTC (19 years, 2 months ago) by twoaday
File size: 20544 byte(s)
2005-12-27  Timo Schulz  <ts@g10code.com>
                                                                                
        * wptListView.cpp (listview_set_view): New.
        (listview_del_column): New.
        * wptW32API.cpp (get_locale_date): New.
        (get_menu_state): New.
        (force_foreground_window): New.
        * wptVerifyList.cpp (strtimestamp): Support for
        locale date formats.
        * wptGPGUtil.cpp (gpg_revoke_cert): Handle bad
        passphrases.
        * wptKeyEditCB.cpp (editkey_command_handler): Immediately
        return when a bad passphrase was submitted.
        * wptKeyRevokersDlg.cpp (keyrevokers_dlg_proc): Change
        column order.
        * wptKeylist.cpp (keylist_upd_col): New.
        * wptKeyManagerDlg.cpp (update_ui_items): Deactivate
        'Revocation' for public keys.
        (translate_menu_strings): s/Revoke/Revoke Cert.
        (modify_listview_columns): New.


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26