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

Annotation of /trunk/Src/wptKeyEditCB.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 36 - (hide annotations)
Thu Oct 27 15:25:13 2005 UTC (19 years, 4 months ago) by werner
File size: 19539 byte(s)
First set of changes to use autotools for building.
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     static char buf[128];
322    
323     /* XXX: check the code. */
324     #if 0
325     if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {
326     ctx->cmd_sent = 1;
327     return "";
328     }
329     if (!strcmp ( key, "keyedit.prompt") && ctx->u.pref.id == 0) {
330     ctx->u.pref.id++;
331     _snprintf (buf, sizeof buf-1, "setpref %s", ctx->u.pref.new_prefs);
332     return buf;
333     }
334     if (!strcmp ( key, "keyedit.prompt") && ctx->u.pref.id == 1) {
335     ctx->u.pref.id++;
336     return "updpref";
337     }
338     if (!strcmp ( key, "keyedit.updpref.okay"))
339     return "Y";
340     if (!strcmp (key, "passphrase.enter"))
341     return ctx->u.pref.passwd;
342     if (!strcmp (key, "keyedit.prompt") && ctx->u.pref.id == 2) {
343     ctx->u.pref.id = 0;
344     ctx->reset ();
345     return "save";
346     }
347     #endif
348     return NULL;
349     }
350    
351    
352     /* 'primary' command handler. */
353     static const char*
354     cmd_primary_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
355     const char *key, int *r_step )
356     {
357     static char buf[64];
358     int step = *r_step;
359    
360     if (step == 0 && !strcmp (key, "keyedit.prompt")) {
361     sprintf (buf, "uid %d", ctx->uid_index);
362     *r_step = step = 1;
363     return buf;
364     }
365     if (step == 1 && !strcmp (key, "keyedit.prompt" )) {
366     *r_step = step = 2;
367     return "primary";
368     }
369     if (step == 2 && !strcmp (key, "passphrase.enter")) {
370     *r_step = step = 3;
371     return ctx->pass;
372     }
373     if (step == 3 && !strcmp (key, "keyedit.prompt")) {
374     *r_step = step = 0;
375     ctx->reset ();
376     return "save";
377     }
378     return NULL;
379     }
380    
381     /* 'expire' command handler. */
382     static const char*
383     cmd_expire_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
384     const char *key, int *r_step )
385     {
386     static char buf[64];
387     int step = *r_step;
388    
389     if (step == 0 && !strcmp (key, "keyedit.prompt")) {
390     sprintf (buf, "key %d", ctx->key_index);
391     *r_step = step = 1;
392     return buf;
393     }
394     if (step == 1 && !strcmp (key, "keyedit.prompt")) {
395     *r_step = step = 2;
396     return "expire";
397     }
398     if( step == 2 && !strcmp ( key, "keygen.valid" ) ) {
399     *r_step = step = 3;
400     sprintf (buf, "%d", ctx->valid);
401     return buf;
402     }
403     if (step == 3 && !strcmp (key, "passphrase.enter")) {
404     *r_step = step = 4;
405     return ctx->pass;
406     }
407     if (step == 4 && !strcmp (key, "keyedit.prompt")) {
408     *r_step = step = 0;
409     ctx->reset ();
410     return "save";
411     }
412    
413     return NULL;
414     }
415    
416    
417     /* 'revuid' command handler. */
418     const char*
419     cmd_revuid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
420     const char *key, int *r_step)
421     {
422     static char buf[32];
423     int step = *r_step;
424    
425     if (step == 0 && !strcmp (key, "keyedit.prompt")) {
426     *r_step = step = 1;
427     sprintf (buf, "uid %d", ctx->uid_index);
428     return buf;
429     }
430     else if (step == 1 && !strcmp (key, "keyedit.prompt")) {
431     *r_step = step = 2;
432     return "revuid";
433     }
434     else if (step == 2 && !strcmp (key, "keyedit.revoke.uid.okay")) {
435     *r_step = step = 3;
436     return "Y";
437     }
438     else if (step == 3 && !strcmp (key, "ask_revocation_reason.code")) {
439     *r_step = step = 4;
440     return "4";
441     }
442     else if (step == 4 && !strcmp (key, "ask_revocation_reason.text")) {
443     *r_step = step = 5;
444     return "";
445     }
446     else if (step == 5 && !strcmp (key, "ask_revocation_reason.okay")) {
447     *r_step = step = 6;
448     return "Y";
449     }
450     else if (step == 6 && !strcmp (key, "passphrase.enter")) {
451     *r_step = step = 7;
452     return ctx->pass;
453     }
454     else if (step == 7 && !strcmp (key, "keyedit.prompt")) {
455     *r_step = step = 0;
456     ctx->reset ();
457     return "save";
458     }
459     return NULL;
460     }
461    
462    
463     const char*
464     cmd_revsig_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
465     const char *key, int *r_step)
466     {
467     static char buf[64];
468     int step = *r_step;
469    
470     if( step == 0 && !strcmp ( key, "keyedit.prompt" ) ) {
471     sprintf( buf, "uid %d", ctx->uid_index);
472     *r_step = step = 1;
473     return buf;
474     }
475     if( step == 1 && !strcmp ( key, "keyedit.prompt" ) ) {
476     *r_step = step = 2;
477     return "revsig";
478     }
479     if( step == 2 && !strcmp (key, "ask_revoke_sig.one" ) ) {
480     *r_step = step = 3;
481     return "Y";
482     }
483     if( step == 3 && !strcmp (key, "ask_revoke_sig.okay" ) ) {
484     *r_step = step = 4;
485     return "Y";
486     }
487     if( step == 4 && !strcmp ( key, "ask_revocation_reason.code" ) ) {
488     *r_step = step = 5;
489     return "0";
490     }
491     if( step == 5 && !strcmp ( key, "ask_revocation_reason.text" ) ) {
492     *r_step = step = 6;
493     return "";
494     }
495     if( step == 6 && !strcmp (key, "ask_revocation_reason.okay" ) ) {
496     *r_step = step = 7;
497     return "Y";
498     }
499     if( step == 7 && !strcmp (key, "passphrase.enter" ) ) {
500     *r_step = step = 8;
501     return ctx->pass;
502     }
503     if( step == 8 && !strcmp ( key, "keyedit.prompt" ) ) {
504     *r_step = step = 0;
505     ctx->reset ();
506     return "save";
507     }
508    
509     return NULL;
510     }
511    
512    
513     /* 'revoke' command handler. */
514     static const char *
515     cmd_revkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
516     const char * key, int *r_step)
517     {
518     int step = *r_step;
519     static char buf[64];
520    
521     if( step == 0 && !strcmp ( key, "keyedit.prompt" ) ) {
522     sprintf( buf, "key %d", ctx->key_index);
523     *r_step = step = 1;
524     return buf;
525     }
526     if( step == 1 && !strcmp ( key, "keyedit.prompt" ) ) {
527     *r_step = step = 2;
528     return "revkey";
529     }
530     if( step == 2 && !strcmp (key, "keyedit.revoke.subkey.okay" ) ) {
531     *r_step = step = 3;
532     return "Y";
533     }
534     if( step == 3 && !strcmp ( key, "ask_revocation_reason.code" ) ) {
535     sprintf( buf, "%d", ctx->reason);
536     *r_step = step = 4;
537     return buf;
538     }
539     if( step == 4 && !strcmp ( key, "ask_revocation_reason.text" ) ) {
540     *r_step = step = 5;
541     return "";
542     }
543     if( step == 5 && !strcmp (key, "ask_revocation_reason.okay" ) ) {
544     *r_step = step = 6;
545     return "Y";
546     }
547     if( step == 6 && !strcmp (key, "passphrase.enter" ) ) {
548     *r_step = step = 7;
549     return ctx->pass;
550     }
551     if( step == 7 && !strcmp ( key, "keyedit.prompt" ) ) {
552     *r_step = step = 0;
553     ctx->reset ();
554     return "save";
555     }
556     return NULL;
557     }
558    
559    
560     /* 'addrevoker' command handler. */
561     static const char *
562     cmd_addrev_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
563     const char * key, int * r_step)
564     {
565     int step = *r_step;
566    
567     if (step == 0 && !strcmp (key, "keyedit.prompt")) {
568     *r_step = step = 1;
569     return "addrevoker";
570     }
571     if (step == 1 && !strcmp (key, "keyedit.add_revoker")) {
572     *r_step = step = 2;
573     /* XXX: handle already-signed. */
574     return ctx->name;
575     }
576     if (step == 2 && !strcmp (key, "keyedit.add_revoker.okay")) {
577     *r_step = step = 3;
578     return "Y";
579     }
580     if (step == 3 && !strcmp (key, "passphrase.enter")) {
581     *r_step = step = 4;
582     return ctx->pass;
583     }
584     if (step == 4 && !strcmp (key, "keyedit.prompt")) {
585     *r_step = step = 0;
586     ctx->reset ();
587     return "save";
588     }
589    
590     return NULL;
591     }
592    
593    
594     /* 'addphoto' command handler. */
595     static const char*
596     cmd_addphoto_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)
597     {
598     if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {
599     ctx->cmd_sent = 1;
600     return "addphoto";
601     }
602     if (!strcmp (key, "photoid.jpeg.add"))
603     return ctx->url;
604     if (!strcmp (key, "photoid.jpeg.size"))
605     return "Y";
606     if (!strcmp (key, "passphrase.enter"))
607     return ctx->pass;
608     if (!strcmp (key, "keyedit.prompt")) {
609     ctx->reset ();
610     return "save";
611     }
612     return NULL;
613     }
614    
615     /* 'enable' and 'disable' command handler. */
616     static const char *
617     cmd_enable_disable_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
618     const char * key, int mode)
619     {
620     if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) {
621     ctx->cmd_sent = 1;
622     if (mode)
623     return "disable";
624     return "enable";
625     }
626     if (!strcmp (key, "keyedit.prompt")) {
627     ctx->reset ();
628     return "save";
629     }
630     return NULL;
631     }
632    
633    
634     /* edit key dispatch handler. */
635     static gpgme_error_t
636     editkey_command_handler (void *opaque, gpgme_status_code_t code,
637     const char *key, int fd)
638     {
639     static int step = 0;
640     const char *out = NULL;
641     GpgKeyEdit *ke = (GpgKeyEdit *)opaque;
642     HANDLE hd = (HANDLE)fd;
643     DWORD n;
644    
645     if (!ke)
646     return gpg_error (GPG_ERR_INV_ARG);
647    
648     /*log_debug ("key=%s code=%d\r\n", key, code);*/
649     switch (code) {
650     case GPGME_STATUS_ALREADY_SIGNED:
651     ke->setResult (GPG_EDITRES_ALREADY_SIGNED);
652     break;
653     case GPGME_STATUS_BAD_PASSPHRASE:
654     ke->setResult (GPG_EDITRES_BAD_PASSPHRASE);
655     break;
656     }
657    
658     if (ke->getResult () & GPG_EDITRES_BAD_PASSPHRASE) {
659     /* 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     WriteFile (hd, "\n", 1, &n, NULL);
663     if (!strcmp (key, "keyedit.prompt"))
664     WriteFile (hd, "quit\n", 5, &n, NULL);
665     }
666    
667     switch (ke->getType ()) {
668     case GPG_EDITKEY_LSIGN:
669     case GPG_EDITKEY_SIGN:
670     case GPG_EDITKEY_NRSIGN:
671     case GPG_EDITKEY_TSIGN:
672     case GPG_EDITKEY_NRLSIGN:
673     out = cmd_sign_handler (ke, code, key);
674     break;
675    
676     case GPG_EDITKEY_TRUST:
677     out = cmd_trust_handler (ke, code, key);
678     break;
679    
680     case GPG_EDITKEY_ADDUID:
681     out = cmd_adduid_handler (ke, code, key);
682     break;
683    
684     case GPG_EDITKEY_DELUID:
685     out = cmd_deluid_handler (ke, code, key, &step);
686     break;
687    
688     case GPG_EDITKEY_DELSIG:
689     out = cmd_delsig_handler (ke, code, key, &step);
690     break;
691    
692     case GPG_EDITKEY_DELKEY:
693     out = cmd_delkey_handler(ke, code, key, &step );
694     break;
695    
696     case GPG_EDITKEY_ADDKEY:
697     out = cmd_addkey_handler (ke, code, key);
698     break;
699    
700     case GPG_EDITKEY_PASSWD:
701     out = cmd_passwd_handler (ke, code, key);
702     break;
703    
704     case GPG_EDITKEY_PRIMARY:
705     out = cmd_primary_handler (ke, code, key, &step);
706     break;
707    
708     case GPG_EDITKEY_EXPIRE:
709     out = cmd_expire_handler (ke, code, key, &step);
710     break;
711    
712     case GPG_EDITKEY_REVSIG:
713     out = cmd_revsig_handler (ke, code, key, &step);
714     break;
715    
716     case GPG_EDITKEY_REVKEY:
717     out = cmd_revkey_handler (ke, code, key, &step);
718     break;
719    
720     case GPG_EDITKEY_REVUID:
721     out = cmd_revuid_handler (ke, code, key, &step);
722     break;
723    
724     case GPG_EDITKEY_ADDREV:
725     out = cmd_addrev_handler (ke, code, key, &step);
726     break;
727    
728     case GPG_EDITKEY_ADDPHOTO:
729     out = cmd_addphoto_handler (ke, code, key);
730     break;
731    
732     case GPG_EDITKEY_ENABLE:
733     case GPG_EDITKEY_DISABLE:
734     out = cmd_enable_disable_handler (ke, code, key,
735     ke->getType () == GPG_EDITKEY_DISABLE? 1: 0);
736     break;
737    
738     case GPG_EDITKEY_SETPREF:
739     out = cmd_setpref_handler (ke, code, key);
740     break;
741    
742     case GPG_EDITKEY_KEYSERV:
743     out = cmd_keyserv_handler (ke, code, key);
744     break;
745     }
746    
747     if (out != NULL) {
748     /* XXX: check return codes. */
749     WriteFile (hd, out, strlen (out), &n, NULL);
750     WriteFile (hd, "\n", 1, &n, NULL);
751     }
752     return 0;
753     }
754    
755    
756     /* Check if a GPG status code occured which marks the
757     current operation as failed.
758     Return value: gpg error constant. */
759     static gpgme_error_t
760     map_result (GpgKeyEdit *ke)
761     {
762     if (!ke->getResult ())
763     return gpg_error (GPG_ERR_NO_ERROR);
764     if (ke->getResult () & GPG_EDITRES_BAD_PASSPHRASE)
765     return gpg_error (GPG_ERR_BAD_PASSPHRASE);
766     return 0;
767     }
768    
769    
770     /* Wrapper around the gpgme edit interface.
771     @ctx context to use.
772     @key key on which the operation should be performed.
773     @ek key edit context.
774     Return value: 0 on success. */
775     gpgme_error_t
776     gpg_editkey (gpgme_ctx_t ctx, gpgme_key_t key, GpgKeyEdit *ek)
777     {
778     gpgme_error_t err;
779     gpgme_data_t out;
780    
781     err = gpgme_data_new (&out);
782     if (err)
783     return err;
784     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     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26