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

Annotation of /trunk/Src/wptKeyEditCB.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 181 - (hide annotations)
Tue Mar 14 11:01:22 2006 UTC (18 years, 11 months ago) by twoaday
File size: 20845 byte(s)
2006-03-12  Timo Schulz  <ts@g10code.de>
 
        * wptGPG.cpp (gnupg_load_config): Search for 'ask-cert-expire'.
        * wptKeyPropsDlg.cpp (display_key_info): Automatically update
        sym algorithm preferences if needed.
        * wptKeysignDlg.cpp (date_is_today): New.
        (keysign_dlg_proc): Only allow to set cert expire date if
        the option was found.
        * wptGPGPrefsDlg.cpp (gpgprefs_dlg_proc): Allow to set
        'ask-cert-expire'.
         


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26