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

Diff of /trunk/Src/wptKeyEditCB.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 24 by twoaday, Sat Oct 8 10:43:08 2005 UTC revision 25 by twoaday, Wed Oct 12 10:04:26 2005 UTC
# Line 22  Line 22 
22  #include <string.h>  #include <string.h>
23  #include <stdlib.h>  #include <stdlib.h>
24  #include <assert.h>  #include <assert.h>
 #include <io.h>  
25  #include <windows.h>  #include <windows.h>
26    
27  #include "w32gpgme.h"  #include "gpgme.h"
28  #include "wptCommonCtl.h"  #include "wptCommonCtl.h"
29  #include "wptContext.h"  #include "wptContext.h"
30  #include "wptKeyEdit.h"  #include "wptKeyEdit.h"
31  #include "wptErrors.h"  #include "wptErrors.h"
32    
33    
34  /* edit key callback for command 'keyserver' */  /* 'keyserver' command handler. */
35  static const char *  static const char*
36  cmd_keyserv_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)  cmd_keyserv_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)
37  {  {
38        static char buf[32];
39    
40      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {
41          ctx->cmd_sent = 1;          ctx->cmd_sent = 1;
42            sprintf (buf, "uid %d", ctx->uid_index);
43            return buf;
44        }
45        if (!strcmp (key, "keyedit.prompt") && !ctx->cnt) {
46            ctx->cnt = 1;
47          return "keyserver";          return "keyserver";
48      }      }
49      if (!strcmp (key, "keyedit.add_keyserver"))      if (!strcmp (key, "keyedit.add_keyserver"))
# Line 46  cmd_keyserv_handler (GpgKeyEdit *ctx, gp Line 52  cmd_keyserv_handler (GpgKeyEdit *ctx, gp
52          return "Y";          return "Y";
53      if (!strcmp (key, "passphrase.enter"))      if (!strcmp (key, "passphrase.enter"))
54          return ctx->pass;          return ctx->pass;
55      if (!strcmp (key, "keyedit.prompt")) {      if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 1) {
56          ctx->reset ();          ctx->reset ();
57          return "save";          return "save";
58      }      }
# Line 60  cmd_sign_handler (GpgKeyEdit *ctx, gpgme Line 66  cmd_sign_handler (GpgKeyEdit *ctx, gpgme
66  {  {
67      static char buf[32];      static char buf[32];
68    
     if (code == GPGME_STATUS_ALREADY_SIGNED)  
         ctx->setResultValue (GPG_EDITRES_ALREADY_SIGNED);  
   
69      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {
70          ctx->cmd_sent = 1;          ctx->cmd_sent = 1;
71          switch (ctx->type) {          switch (ctx->type) {
# Line 73  cmd_sign_handler (GpgKeyEdit *ctx, gpgme Line 76  cmd_sign_handler (GpgKeyEdit *ctx, gpgme
76          case GPG_EDITKEY_NRLSIGN: return "nrlsign";          case GPG_EDITKEY_NRLSIGN: return "nrlsign";
77          }          }
78      }      }
79      if( !strcmp( key, "sign_uid.class" ) ) {          if (!strcmp (key, "sign_uid.class")) {
80          sprintf( buf, "%d", ctx->sig_class );          sprintf (buf, "%d", ctx->sig_class);
81          return buf;          return buf;
82      }      }
83      if (!strcmp (key, "sign_uid.expire"))      if (!strcmp (key, "sign_uid.expire"))
# Line 89  cmd_sign_handler (GpgKeyEdit *ctx, gpgme Line 92  cmd_sign_handler (GpgKeyEdit *ctx, gpgme
92          return ""; /* fixme */          return ""; /* fixme */
93      if (!strcmp (key, "trustsig_prompt.trust_regexp"))      if (!strcmp (key, "trustsig_prompt.trust_regexp"))
94          return ""; /* fixme */          return ""; /* fixme */
95      if( !strcmp (key, "sign_uid.local_promote_okay" ) )      if (!strcmp (key, "sign_uid.local_promote_okay" ) )
96          return "Y";          return "Y";
97      if( !strcmp (key, "sign_uid.okay" ) )      if (!strcmp (key, "sign_uid.okay" ) )
98          return "Y";          return "Y";
99      if( !strcmp (key, "keyedit.sign_all.okay" ) )      if (!strcmp (key, "keyedit.sign_all.okay"))
100          return "Y";          return "Y";
101      if( !strcmp ( key, "passphrase.enter" ) )      if (!strcmp ( key, "passphrase.enter"))
102          return ctx->pass;          return ctx->pass;
103      if( !strcmp (key, "keyedit.prompt" ) ) {      if (!strcmp (key, "keyedit.prompt")) {
104          ctx->reset ();          ctx->reset ();
105          return "save";          return "save";
106      }      }
# Line 105  cmd_sign_handler (GpgKeyEdit *ctx, gpgme Line 108  cmd_sign_handler (GpgKeyEdit *ctx, gpgme
108      return NULL;      return NULL;
109  }  }
110    
111    /* 'trust' command handler. */
112  static const char*  static const char*
113  cmd_trust_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)  cmd_trust_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)
114  {  {
# Line 130  cmd_trust_handler (GpgKeyEdit *ctx, gpgm Line 133  cmd_trust_handler (GpgKeyEdit *ctx, gpgm
133  }  }
134    
135    
136    /* 'adduid' command handler. */
137  static const char*  static const char*
138  cmd_adduid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)  cmd_adduid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)
139  {  {
# Line 137  cmd_adduid_handler (GpgKeyEdit *ctx, gpg Line 141  cmd_adduid_handler (GpgKeyEdit *ctx, gpg
141          ctx->cmd_sent = 1;          ctx->cmd_sent = 1;
142          return "adduid";          return "adduid";
143      }      }
144      if( !strcmp ( key, "keygen.name" ) )      if (!strcmp (key, "keygen.name"))
145          return ctx->name;          return ctx->name;
146      if( !strcmp (key, "keygen.email" ) )      if (!strcmp (key, "keygen.email"))
147          return ctx->email;          return ctx->email;
148      if( !strcmp ( key, "keygen.comment" ) ) {      if (!strcmp (key, "keygen.comment"))
149          if (ctx->cmt)          return ctx->cmt? ctx->cmt : "";
150              return ctx->cmt;      if (!strcmp (key, "passphrase.enter"))
         return "";  
     }  
     if( !strcmp (key, "passphrase.enter" ) )  
151          return ctx->pass;          return ctx->pass;
152      if( !strcmp (key, "keyedit.prompt" ) ) {      if( !strcmp (key, "keyedit.prompt")) {
153          ctx->reset ();          ctx->reset ();
154          return "save";          return "save";
155      }      }
# Line 164  cmd_deluid_handler (GpgKeyEdit *ctx, gpg Line 165  cmd_deluid_handler (GpgKeyEdit *ctx, gpg
165      static char buf[64];      static char buf[64];
166      int step = *r_step;      int step = *r_step;
167    
168      if( step == 0 && !strcmp (key, "keyedit.prompt" ) ) {      if (step == 0 && !strcmp (key, "keyedit.prompt")) {
169          sprintf (buf, "uid %d", ctx->uid_index);          sprintf (buf, "uid %d", ctx->uid_index);
170          *r_step = step = 1;          *r_step = step = 1;
171          return buf;          return buf;
172      }      }
173      if( step == 1 && !strcmp( key, "keyedit.prompt" ) ) {      if (step == 1 && !strcmp (key, "keyedit.prompt")) {
174          *r_step = step = 2;          *r_step = step = 2;
175          return "deluid";          return "deluid";
176      }      }
177      if( step == 2 && !strcmp ( key, "keyedit.remove.uid.okay" ) ) {      if (step == 2 && !strcmp (key, "keyedit.remove.uid.okay")) {
178          *r_step = step = 3;          *r_step = step = 3;
179          return "Y";          return "Y";
180      }      }
181      if( step == 3 && !strcmp ( key, "keyedit.prompt" ) ) {      if (step == 3 && !strcmp (key, "keyedit.prompt" )) {
182          *r_step = step = 0;          *r_step = step = 0;
183          ctx->reset ();          ctx->reset ();
184          return "save";          return "save";
# Line 222  cmd_delsig_handler (GpgKeyEdit *ctx, gpg Line 223  cmd_delsig_handler (GpgKeyEdit *ctx, gpg
223  }  }
224    
225    
226    /* 'delkey' command handler. */
227  static const char*  static const char*
228  cmd_delkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,  cmd_delkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
229                      const char *key, int *r_step )                      const char *key, int *r_step )
# Line 229  cmd_delkey_handler (GpgKeyEdit *ctx, gpg Line 231  cmd_delkey_handler (GpgKeyEdit *ctx, gpg
231      static char buf[64];      static char buf[64];
232      int step = *r_step;      int step = *r_step;
233    
234      if( step == 0 && !strcmp (key, "keyedit.prompt" ) ) {      if (step == 0 && !strcmp (key, "keyedit.prompt")) {
235          sprintf( buf, "key %d", ctx->key_index);          sprintf (buf, "key %d", ctx->key_index);
236          *r_step = step = 1;          *r_step = step = 1;
237          return buf;          return buf;
238      }      }
239      if( step == 1 && !strcmp (key, "keyedit.prompt" ) ) {      if (step == 1 && !strcmp (key, "keyedit.prompt")) {
240          *r_step = step = 2;          *r_step = step = 2;
241          return "delkey";          return "delkey";
242      }      }
243      if( step == 2 && !strcmp (key, "keyedit.remove.subkey.okay" ) ) {      if (step == 2 && !strcmp (key, "keyedit.remove.subkey.okay")) {
244          *r_step = step = 3;          *r_step = step = 3;
245          return "Y";          return "Y";
246      }      }
247      if( step == 3 && !strcmp (key, "keyedit.prompt" ) ) {      if (step == 3 && !strcmp (key, "keyedit.prompt")) {
248          *r_step = step = 0;          *r_step = step = 0;
249          ctx->reset ();          ctx->reset ();
250          return "save";          return "save";
251      }      }
252        
253      return NULL;      return NULL;
254  }  }
255    
256    
257    /* 'addkey' command handler. */
258  static const char*  static const char*
259  cmd_addkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)  cmd_addkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)
260  {  {
# Line 262  cmd_addkey_handler (GpgKeyEdit *ctx, gpg Line 265  cmd_addkey_handler (GpgKeyEdit *ctx, gpg
265          return "addkey";          return "addkey";
266      }      }
267    
268      if( !strcmp (key, "passphrase.enter" ) )      if (!strcmp (key, "passphrase.enter"))
269          return ctx->pass;          return ctx->pass;
270      if( !strcmp (key, "keygen.algo" ) ) {      if (!strcmp (key, "keygen.algo")) {
271          _snprintf( buf, sizeof buf-1, "%d", ctx->pubkey_algo);          _snprintf (buf, sizeof buf-1, "%d", ctx->pubkey_algo);
272          return buf;          return buf;
273      }        }  
274      if( !strcmp (key, "keygen.size" ) ) {      if (!strcmp (key, "keygen.size")) {
275          _snprintf( buf, sizeof buf-1, "%d", ctx->pubkey_size);          _snprintf (buf, sizeof buf-1, "%d", ctx->pubkey_size);
276          return buf;          return buf;
277      }      }
278      if( !strcmp (key, "keygen.valid" ) ) {      if (!strcmp (key, "keygen.valid")) {
279          _snprintf( buf, sizeof buf-1, "%d", ctx->valid);          _snprintf (buf, sizeof buf-1, "%d", ctx->valid);
280          return buf;                  return buf;        
281      }      }
282      if( !strcmp (key, "keyedit.prompt" ) ) {      if (!strcmp (key, "keyedit.prompt")) {
283          ctx->reset ();          ctx->reset ();
284          return "save";          return "save";
285      }      }
286      return NULL;      return NULL;
287  }  }
288    
289    /* 'passwd' command handler. */
290  static const char*  static const char*
291  cmd_passwd_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)  cmd_passwd_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)
292  {  {
# Line 299  cmd_passwd_handler (GpgKeyEdit *ctx, gpg Line 302  cmd_passwd_handler (GpgKeyEdit *ctx, gpg
302          return ctx->new_pass;          return ctx->new_pass;
303      if( !strcmp (key, "change_passwd.empty.okay" ))      if( !strcmp (key, "change_passwd.empty.okay" ))
304          return ctx->flags?  "Y" : "N";          return ctx->flags?  "Y" : "N";
305      if( !strcmp ( key, "keyedit.prompt" ) ) {      if (!strcmp (key, "keyedit.prompt")) {
306          ctx->reset ();          ctx->reset ();
307          return "save";          return "save";
308      }      }
# Line 307  cmd_passwd_handler (GpgKeyEdit *ctx, gpg Line 310  cmd_passwd_handler (GpgKeyEdit *ctx, gpg
310  }  }
311    
312    
313  static const char *  static const char*
314  cmd_setpref_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char * key)  cmd_setpref_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char * key)
315  {  {
316      static char buf[128];      static char buf[128];
# Line 341  cmd_setpref_handler (GpgKeyEdit *ctx, gp Line 344  cmd_setpref_handler (GpgKeyEdit *ctx, gp
344  }  }
345    
346    
347    /* 'primary' command handler. */
348  static const char*  static const char*
349  cmd_primary_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,  cmd_primary_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
350                       const char *key, int *r_step )                       const char *key, int *r_step )
# Line 348  cmd_primary_handler (GpgKeyEdit *ctx, gp Line 352  cmd_primary_handler (GpgKeyEdit *ctx, gp
352      static char buf[64];      static char buf[64];
353      int step = *r_step;      int step = *r_step;
354    
355      if( step == 0 && !strcmp (key, "keyedit.prompt" ) ) {      if (step == 0 && !strcmp (key, "keyedit.prompt")) {
356          sprintf (buf, "uid %d", ctx->uid_index);          sprintf (buf, "uid %d", ctx->uid_index);
357          *r_step = step = 1;          *r_step = step = 1;
358          return buf;          return buf;
359      }      }
360      if( step == 1 && !strcmp ( key, "keyedit.prompt" ) ) {      if (step == 1 && !strcmp (key, "keyedit.prompt" )) {
361          *r_step = step = 2;          *r_step = step = 2;
362          return "primary";          return "primary";
363      }      }
364      if( step == 2 && !strcmp ( key, "passphrase.enter" ) ) {      if (step == 2 && !strcmp (key, "passphrase.enter")) {
365          *r_step = step = 3;          *r_step = step = 3;
366          return ctx->pass;          return ctx->pass;
367      }      }
368      if( step == 3 && !strcmp (key, "keyedit.prompt" ) ) {      if (step == 3 && !strcmp (key, "keyedit.prompt")) {
369          *r_step = step = 0;          *r_step = step = 0;
370          ctx->reset ();          ctx->reset ();
371          return "save";          return "save";
# Line 369  cmd_primary_handler (GpgKeyEdit *ctx, gp Line 373  cmd_primary_handler (GpgKeyEdit *ctx, gp
373      return NULL;      return NULL;
374  }  }
375    
376    /* 'expire' command handler. */
377  static const char*  static const char*
378  cmd_expire_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,  cmd_expire_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
379                      const char *key, int *r_step )                      const char *key, int *r_step )
# Line 377  cmd_expire_handler (GpgKeyEdit *ctx, gpg Line 381  cmd_expire_handler (GpgKeyEdit *ctx, gpg
381      static char buf[64];      static char buf[64];
382      int step = *r_step;      int step = *r_step;
383    
384      if( step == 0 && !strcmp ( key, "keyedit.prompt" ) ) {      if (step == 0 && !strcmp (key, "keyedit.prompt")) {
385          sprintf(buf, "key %d", ctx->key_index);          sprintf (buf, "key %d", ctx->key_index);
386          *r_step = step = 1;          *r_step = step = 1;
387          return buf;          return buf;
388      }      }
389      if( step == 1 && !strcmp ( key, "keyedit.prompt" ) ) {      if (step == 1 && !strcmp (key, "keyedit.prompt")) {
390          *r_step = step = 2;          *r_step = step = 2;
391          return "expire";          return "expire";
392      }      }
393      if( step == 2 && !strcmp ( key, "keygen.valid" ) ) {      if( step == 2 && !strcmp ( key, "keygen.valid" ) ) {
394          *r_step = step = 3;          *r_step = step = 3;
395          if (ctx->valid) {                  sprintf (buf, "%d", ctx->valid);
396              sprintf (buf, "%d", ctx->valid);          return buf;
             return buf;  
         }  
         else  
             return ctx->exp_date;  
397      }      }
398      if( step == 3 && !strcmp (key, "passphrase.enter" ) ) {      if (step == 3 && !strcmp (key, "passphrase.enter")) {
399          *r_step = step = 4;          *r_step = step = 4;
400          return ctx->pass;          return ctx->pass;
401      }      }
402      if( step == 4 && !strcmp ( key, "keyedit.prompt" ) ) {      if (step == 4 && !strcmp (key, "keyedit.prompt")) {
403          *r_step = step = 0;          *r_step = step = 0;
404          ctx->reset ();          ctx->reset ();
405          return "save";          return "save";
# Line 409  cmd_expire_handler (GpgKeyEdit *ctx, gpg Line 409  cmd_expire_handler (GpgKeyEdit *ctx, gpg
409  }  }
410    
411    
412    /* 'revuid' command handler. */
413    const char*
414    cmd_revuid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
415                        const char *key, int *r_step)
416    {
417        static char buf[32];
418        int step = *r_step;
419        
420        if (step == 0 && !strcmp (key, "keyedit.prompt")) {
421            *r_step = step = 1;
422            sprintf (buf, "uid %d", ctx->uid_index);
423            return buf;
424        }
425        else if (step == 1 && !strcmp (key, "keyedit.prompt")) {
426            *r_step = step = 2;
427            return "revuid";
428        }
429        else if (step == 2 && !strcmp (key, "keyedit.revoke.uid.okay")) {
430            *r_step = step = 3;
431            return "Y";
432        }
433        else if (step == 3 && !strcmp (key, "ask_revocation_reason.code")) {
434            *r_step = step = 4;
435            return "4";
436        }
437        else if (step == 4 && !strcmp (key, "ask_revocation_reason.text")) {
438            *r_step = step = 5;
439            return "";
440        }
441        else if (step == 5 && !strcmp (key, "ask_revocation_reason.okay")) {
442            *r_step = step = 6;
443            return "Y";
444        }
445        else if (step == 6 && !strcmp (key, "passphrase.enter")) {
446            *r_step = step = 7;
447            return ctx->pass;
448        }
449        else if (step == 7 && !strcmp (key, "keyedit.prompt")) {
450            *r_step = step = 0;
451            ctx->reset ();
452            return "save";
453        }
454        return NULL;
455    }
456    
457    
458  const char*  const char*
459  cmd_revsig_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,  cmd_revsig_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
460                      const char *key, int *r_step)                      const char *key, int *r_step)
# Line 439  cmd_revsig_handler (GpgKeyEdit *ctx, gpg Line 485  cmd_revsig_handler (GpgKeyEdit *ctx, gpg
485      }      }
486      if( step == 5 && !strcmp ( key, "ask_revocation_reason.text" ) ) {      if( step == 5 && !strcmp ( key, "ask_revocation_reason.text" ) ) {
487          *r_step = step = 6;          *r_step = step = 6;
488          return "\n";          return "";
489      }      }
490      if( step == 6 && !strcmp (key, "ask_revocation_reason.okay" ) ) {      if( step == 6 && !strcmp (key, "ask_revocation_reason.okay" ) ) {
491          *r_step = step = 7;          *r_step = step = 7;
# Line 459  cmd_revsig_handler (GpgKeyEdit *ctx, gpg Line 505  cmd_revsig_handler (GpgKeyEdit *ctx, gpg
505  }  }
506    
507    
508    /* 'revoke' command handler. */
509  static const char *  static const char *
510  cmd_revkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,  cmd_revkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
511                      const char * key, int *r_step)                      const char * key, int *r_step)
# Line 505  cmd_revkey_handler (GpgKeyEdit *ctx, gpg Line 552  cmd_revkey_handler (GpgKeyEdit *ctx, gpg
552  }  }
553    
554    
555    /* 'addrevoker' command handler. */
556  static const char *  static const char *
557  cmd_addrev_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,  cmd_addrev_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
558                      const char * key, int * r_step)                      const char * key, int * r_step)
559  {  {
560      int step = *r_step;      int step = *r_step;
561    
562      if ((step == 0 /*|| c->result.editk->already_signed*/)      if (step == 0 && !strcmp (key, "keyedit.prompt")) {
         && !strcmp (key, "keyedit.add_revoker")) {  
563          *r_step = step = 1;          *r_step = step = 1;
564            return "addrevoker";
565        }
566        if (step == 1 && !strcmp (key, "keyedit.add_revoker")) {
567            *r_step = step = 2;
568          /* XXX: handle already-signed. */          /* XXX: handle already-signed. */
569          return ctx->name;          return ctx->name;
570      }      }
571      if( step == 1 && !strcmp (key, "keyedit.add_revoker.okay" ) ) {      if (step == 2 && !strcmp (key, "keyedit.add_revoker.okay")) {
572          *r_step = step = 2;          *r_step = step = 3;
573          return "Y";          return "Y";
574      }      }
575      if( step == 2 && !strcmp (key, "passphrase.enter" ) ) {      if (step == 3 && !strcmp (key, "passphrase.enter")) {
576          *r_step = step = 3;          *r_step = step = 4;
577          return ctx->pass;          return ctx->pass;
578      }      }
579      if (step == 3 && !strcmp (key, "keyedit.prompt")) {      if (step == 4 && !strcmp (key, "keyedit.prompt")) {
580          *r_step = step = 0;          *r_step = step = 0;
581          ctx->reset ();          ctx->reset ();
582          return "save";          return "save";
583      }      }
584    
585      return NULL;      return NULL;
586  }  }
587    
588    
589    /* 'addphoto' command handler. */
590  static const char*  static const char*
591  cmd_addphoto_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key,  cmd_addphoto_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)
                       int *r_step )  
592  {  {
593      int step = *r_step;      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {
594            ctx->cmd_sent = 1;
595            return "addphoto";
596        }
597      if (!strcmp (key, "photoid.jpeg.add"))      if (!strcmp (key, "photoid.jpeg.add"))
598          return ctx->url;          return ctx->url;
599      if (!strcmp (key, "photoid.jpeg.size"))      if (!strcmp (key, "photoid.jpeg.size"))
600          return "Y";          return "Y";
601      if (!strcmp (key, "passphrase.enter"))      if (!strcmp (key, "passphrase.enter"))
602          return ctx->pass;          return ctx->pass;
603      if (!strcmp (key, "keyedit.prompt")) {      if (!strcmp (key, "keyedit.prompt")) {      
         *r_step = step = 0;  
604          ctx->reset ();          ctx->reset ();
605          return "save";          return "save";
606      }      }
607      return NULL;      return NULL;
608  }  }
609    
610    /* 'enable' and 'disable' command handler. */
611  static const char *  static const char *
612  cmd_enable_disable_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,  cmd_enable_disable_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
613                              const char * key, int mode)                              const char * key, int mode)
# Line 573  cmd_enable_disable_handler (GpgKeyEdit * Line 626  cmd_enable_disable_handler (GpgKeyEdit *
626  }  }
627    
628    
629    /* edit key dispatch handler. */
   
630  static gpgme_error_t                      static gpgme_error_t                    
631  editkey_command_handler (void *opaque, gpgme_status_code_t code, const char *key, int fd)  editkey_command_handler (void *opaque, gpgme_status_code_t code,
632                             const char *key, int fd)
633  {  {
634      static int step = 0;      static int step = 0;
635      const char *out = NULL;      const char *out = NULL;
# Line 586  editkey_command_handler (void *opaque, g Line 639  editkey_command_handler (void *opaque, g
639            
640      if (!ke)      if (!ke)
641          return gpg_error (GPG_ERR_INV_ARG);          return gpg_error (GPG_ERR_INV_ARG);
642    
643        /*log_debug ("key=%s code=%d\r\n", key, code);*/
644        switch (code) {
645        case GPGME_STATUS_ALREADY_SIGNED:
646            ke->setResultValue (GPG_EDITRES_ALREADY_SIGNED);
647            break;
648        case GPGME_STATUS_BAD_PASSPHRASE:
649            ke->setResultValue (GPG_EDITRES_BAD_PASSPHRASE);
650            break;
651        }
652    
653        if (ke->getResultValue () & GPG_EDITRES_BAD_PASSPHRASE) {
654            /* If the entered passphrase is bad, we supply empty
655               passphrase to abort and send 'quit' as soon as possible. */
656            if (!strcmp (key, "passphrase.enter"))
657                WriteFile (hd, "\n", 1, &n, NULL);
658            if (!strcmp (key, "keyedit.prompt"))
659                WriteFile (hd, "quit\n", 5, &n, NULL);
660        }
661            
662      switch (ke->type) {      switch (ke->type) {
663      case GPG_EDITKEY_LSIGN:      case GPG_EDITKEY_LSIGN:
# Line 598  editkey_command_handler (void *opaque, g Line 670  editkey_command_handler (void *opaque, g
670                    
671      case GPG_EDITKEY_TRUST:      case GPG_EDITKEY_TRUST:
672          out =  cmd_trust_handler (ke, code, key);          out =  cmd_trust_handler (ke, code, key);
         log_debug ("key=%s out=%s\n", key, out);  
673          break;          break;
674                    
675      case GPG_EDITKEY_ADDUID:      case GPG_EDITKEY_ADDUID:
# Line 640  editkey_command_handler (void *opaque, g Line 711  editkey_command_handler (void *opaque, g
711      case GPG_EDITKEY_REVKEY:      case GPG_EDITKEY_REVKEY:
712          out =  cmd_revkey_handler (ke, code, key, &step);          out =  cmd_revkey_handler (ke, code, key, &step);
713          break;          break;
714                
715        case GPG_EDITKEY_REVUID:
716            out = cmd_revuid_handler (ke, code, key, &step);
717            break;
718    
719      case GPG_EDITKEY_ADDREV:      case GPG_EDITKEY_ADDREV:
720          out =  cmd_addrev_handler (ke, code, key, &step);          out =  cmd_addrev_handler (ke, code, key, &step);
721          break;          break;
722    
723      case GPG_EDITKEY_ADDPHOTO:      case GPG_EDITKEY_ADDPHOTO:
724          out =  cmd_addphoto_handler (ke, code, key, &step);          out =  cmd_addphoto_handler (ke, code, key);
725          break;          break;
726    
727      case GPG_EDITKEY_ENABLE:      case GPG_EDITKEY_ENABLE:
728      case GPG_EDITKEY_DISABLE:      case GPG_EDITKEY_DISABLE:
729          out =  cmd_enable_disable_handler (ke, code, key,          out = cmd_enable_disable_handler (ke, code, key,
730                                             ke->type == GPG_EDITKEY_DISABLE? 1: 0);                                            ke->type == GPG_EDITKEY_DISABLE? 1: 0);
731          break;          break;
732    
733      case GPG_EDITKEY_SETPREF:      case GPG_EDITKEY_SETPREF:
# Line 663  editkey_command_handler (void *opaque, g Line 738  editkey_command_handler (void *opaque, g
738          out =  cmd_keyserv_handler (ke, code, key);          out =  cmd_keyserv_handler (ke, code, key);
739          break;          break;
740      }      }
741    
742      if (out != NULL) {      if (out != NULL) {
         WriteFile (hd, out, strlen (out), &n, NULL);      
         WriteFile (hd, "\n", 1, &n, NULL);  
743          /* XXX: check return codes. */          /* XXX: check return codes. */
744            WriteFile (hd, out, strlen (out), &n, NULL);
745            WriteFile (hd, "\n", 1, &n, NULL);
746      }      }
747      return 0;      return 0;
748  }  }
749    
750    
751    /* Check if a GPG status code occured which marks the
752       current operation as failed.
753       Return value: gpg error constant. */
754    static gpgme_error_t
755    map_result (GpgKeyEdit *ke)
756    {
757        if (!ke->getResultValue ())
758            return gpg_error (GPG_ERR_NO_ERROR);
759        if (ke->getResultValue () & GPG_EDITRES_BAD_PASSPHRASE)
760            return gpg_error (GPG_ERR_BAD_PASSPHRASE);
761        return 0;
762    }
763    
764    
765    /* Wrapper around the gpgme edit interface.
766       @ctx context to use.
767       @key key on which the operation should be performed.
768       @ek  key edit context.
769       Return value: 0 on success. */
770  gpgme_error_t  gpgme_error_t
771  gpg_editkey (gpgme_ctx_t ctx, gpgme_key_t key, GpgKeyEdit *ek)  gpg_editkey (gpgme_ctx_t ctx, gpgme_key_t key, GpgKeyEdit *ek)
772  {  {
# Line 682  gpg_editkey (gpgme_ctx_t ctx, gpgme_key_ Line 776  gpg_editkey (gpgme_ctx_t ctx, gpgme_key_
776      err = gpgme_data_new (&out);      err = gpgme_data_new (&out);
777      if (err)      if (err)
778          return err;          return err;
779      err = gpgme_op_edit (ctx, key, editkey_command_handler, ek, out);          err = gpgme_op_edit (ctx, key, editkey_command_handler, ek, out);
780        if (!err)
781            err = map_result (ek);
782    
783      gpgme_data_release (out);      gpgme_data_release (out);
784      return err;      return err;
785  }  }
   

Legend:
Removed from v.24  
changed lines
  Added in v.25

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26