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

Annotation of /trunk/Src/wptKeyEditCB.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 68 - (hide annotations)
Sat Nov 5 12:00:55 2005 UTC (19 years, 3 months ago) by twoaday
File size: 19561 byte(s)
More minor changes to avoid GCC warnings.


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26