/[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 119 by twoaday, Fri Dec 9 08:04:51 2005 UTC revision 170 by twoaday, Mon Jan 30 12:42:57 2006 UTC
# Line 35  Line 35 
35  #include "wptKeyEdit.h"  #include "wptKeyEdit.h"
36  #include "wptErrors.h"  #include "wptErrors.h"
37    
38    /* 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    
44  /* 'keyserver' command handler. */  /* 'keyserver' command handler. */
45  static const char*  static const char*
# Line 44  cmd_keyserv_handler (GpgKeyEdit *ctx, gp Line 49  cmd_keyserv_handler (GpgKeyEdit *ctx, gp
49    
50      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {
51          ctx->cmd_sent = 1;          ctx->cmd_sent = 1;
52          sprintf (buf, "uid %d", ctx->uid_index);          sprintf (buf, "uid %d", ctx->getUseridIndex ());
53          return buf;          return buf;
54      }      }
55      if (!strcmp (key, "keyedit.prompt") && !ctx->cnt) {      if (!strcmp (key, "keyedit.prompt") && !ctx->cnt) {
# Line 72  cmd_sign_handler (GpgKeyEdit *ctx, gpgme Line 77  cmd_sign_handler (GpgKeyEdit *ctx, gpgme
77  {  {
78      static char buf[32];      static char buf[32];
79    
80        if (ctx->getUseridIndex () != -1 &&
81            ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
82            ctx->cnt++;
83            sprintf (buf, "uid %d", ctx->getUseridIndex ());
84            return buf;
85        }
86    
87      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {
88          ctx->cmd_sent = 1;          ctx->cmd_sent = 1;
89          switch (ctx->getType ()) {          switch (ctx->getType ()) {
# Line 172  cmd_deluid_handler (GpgKeyEdit *ctx, gpg Line 184  cmd_deluid_handler (GpgKeyEdit *ctx, gpg
184      int step = *r_step;      int step = *r_step;
185    
186      if (step == 0 && !strcmp (key, "keyedit.prompt")) {      if (step == 0 && !strcmp (key, "keyedit.prompt")) {
187          sprintf (buf, "uid %d", ctx->uid_index);          sprintf (buf, "uid %d", ctx->getUseridIndex ());
188          *r_step = step = 1;          *r_step = step = 1;
189          return buf;          return buf;
190      }      }
# Line 194  cmd_deluid_handler (GpgKeyEdit *ctx, gpg Line 206  cmd_deluid_handler (GpgKeyEdit *ctx, gpg
206  }  }
207    
208    
209  static const char *  static const char*
210  cmd_delsig_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char * key,  cmd_delsig_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key,
211                      int * r_step)                      int *r_step)
212  {  {
213      static char buf[64];      static char buf[64];
214      int step = *r_step;      int step = *r_step;
215    
216      if (step == 0 && !strcmp (key, "keyedit.prompt")) {      if (step == 0 && !strcmp (key, "keyedit.prompt")) {
217          sprintf (buf, "uid %d", ctx->uid_index);          sprintf (buf, "uid %d", ctx->getUseridIndex ());
218          *r_step = step = 1;          *r_step = step = 1;
219          return buf;          return buf;
220      }      }
# Line 212  cmd_delsig_handler (GpgKeyEdit *ctx, gpg Line 224  cmd_delsig_handler (GpgKeyEdit *ctx, gpg
224      }      }
225      if (!strcmp (key, "keyedit.delsig.unknown") ||      if (!strcmp (key, "keyedit.delsig.unknown") ||
226          !strcmp (key, "keyedit.delsig.valid")) {          !strcmp (key, "keyedit.delsig.valid")) {
227          if (++ctx->cnt == ctx->sig_index)          if (++ctx->cnt == ctx->getSigIndex ())
228              return "Y";              return "Y";
229          else          else
230              return "N";              return "N";
231      }      }
232      if (ctx->sig_index == 0 &&      if (!strcmp (key, "keyedit.delsig.selfsig"))
         !strcmp (key, "keyedit.delsig.selfsig"))  
233          return "Y";          return "Y";
234      if (step == 2 && !strcmp (key, "keyedit.prompt")) {      if (step == 2 && !strcmp (key, "keyedit.prompt")) {
235          *r_step = step = 0;          *r_step = step = 0;
# Line 238  cmd_delkey_handler (GpgKeyEdit *ctx, gpg Line 249  cmd_delkey_handler (GpgKeyEdit *ctx, gpg
249      int step = *r_step;      int step = *r_step;
250    
251      if (step == 0 && !strcmp (key, "keyedit.prompt")) {      if (step == 0 && !strcmp (key, "keyedit.prompt")) {
252          sprintf (buf, "key %d", ctx->key_index);          sprintf (buf, "key %d", ctx->getKeyIndex ());
253          *r_step = step = 1;          *r_step = step = 1;
254          return buf;          return buf;
255      }      }
# Line 274  cmd_addkey_handler (GpgKeyEdit *ctx, gpg Line 285  cmd_addkey_handler (GpgKeyEdit *ctx, gpg
285      if (!strcmp (key, "passphrase.enter"))      if (!strcmp (key, "passphrase.enter"))
286          return ctx->pass;          return ctx->pass;
287      if (!strcmp (key, "keygen.algo")) {      if (!strcmp (key, "keygen.algo")) {
288          _snprintf (buf, sizeof buf-1, "%d", ctx->pubkey_algo);          _snprintf (buf, sizeof (buf)-1, "%d", ctx->pubkey_algo);
289          return buf;          return buf;
290      }        }  
291      if (!strcmp (key, "keygen.size")) {      if (!strcmp (key, "keygen.size")) {
292          _snprintf (buf, sizeof buf-1, "%d", ctx->pubkey_size);          _snprintf (buf, sizeof (buf)-1, "%d", ctx->pubkey_size);
293          return buf;          return buf;
294      }      }
295      if (!strcmp (key, "keygen.valid")) {      if (!strcmp (key, "keygen.valid")) {
296          _snprintf (buf, sizeof buf-1, "%d", ctx->valid);          _snprintf (buf, sizeof (buf)-1, "%d", ctx->valid);
297          return buf;                  return buf;        
298      }      }
299      if (!strcmp (key, "keyedit.prompt")) {      if (!strcmp (key, "keyedit.prompt")) {
# Line 300  cmd_passwd_handler (GpgKeyEdit *ctx, gpg Line 311  cmd_passwd_handler (GpgKeyEdit *ctx, gpg
311          ctx->cmd_sent = 1;          ctx->cmd_sent = 1;
312          return "passwd";          return "passwd";
313      }      }
314      if( !strcmp (key, "passphrase.enter") && !ctx->cnt) {      if (!ctx->cnt && !strcmp (key, "passphrase.enter")) {
315          ctx->cnt = 1;          ctx->cnt = 1;
316          return ctx->pass;          return ctx->pass;
317      }      }
318      if( !strcmp (key, "passphrase.enter" ))      if (!strcmp (key, "passphrase.enter" ))
319          return ctx->new_pass;          return ctx->new_pass;
320      if( !strcmp (key, "change_passwd.empty.okay" ))      if (!strcmp (key, "change_passwd.empty.okay" ))
321          return ctx->flags?  "Y" : "N";          return ctx->flags?  "Y" : "N";
322      if (!strcmp (key, "keyedit.prompt")) {      if (!strcmp (key, "keyedit.prompt")) {
323          ctx->reset ();          ctx->reset ();
324          return "save";          return "save";
325      }      }
326    
327      return NULL;      return NULL;
328  }  }
329    
# Line 319  cmd_passwd_handler (GpgKeyEdit *ctx, gpg Line 331  cmd_passwd_handler (GpgKeyEdit *ctx, gpg
331  static const char*  static const char*
332  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)
333  {  {
334        static char buf[128];
335    
336      /* XXX: check the code. */      /* XXX: check the code. */
337  #if 0  #if 0
     static char buf[128];  
338      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {
339          ctx->cmd_sent = 1;          ctx->cmd_sent = 1;
340          return "";          return "";
# Line 358  cmd_primary_handler (GpgKeyEdit *ctx, gp Line 371  cmd_primary_handler (GpgKeyEdit *ctx, gp
371      int step = *r_step;      int step = *r_step;
372    
373      if (step == 0 && !strcmp (key, "keyedit.prompt")) {      if (step == 0 && !strcmp (key, "keyedit.prompt")) {
374          sprintf (buf, "uid %d", ctx->uid_index);          sprintf (buf, "uid %d", ctx->getUseridIndex ());
375          *r_step = step = 1;          *r_step = step = 1;
376          return buf;          return buf;
377      }      }
# Line 387  cmd_expire_handler (GpgKeyEdit *ctx, gpg Line 400  cmd_expire_handler (GpgKeyEdit *ctx, gpg
400      int step = *r_step;      int step = *r_step;
401    
402      if (step == 0 && !strcmp (key, "keyedit.prompt")) {      if (step == 0 && !strcmp (key, "keyedit.prompt")) {
403          sprintf (buf, "key %d", ctx->key_index);          sprintf (buf, "key %d", ctx->getKeyIndex ());
404          *r_step = step = 1;          *r_step = step = 1;
405          return buf;          return buf;
406      }      }
# Line 424  cmd_revuid_handler (GpgKeyEdit *ctx, gpg Line 437  cmd_revuid_handler (GpgKeyEdit *ctx, gpg
437            
438      if (step == 0 && !strcmp (key, "keyedit.prompt")) {      if (step == 0 && !strcmp (key, "keyedit.prompt")) {
439          *r_step = step = 1;          *r_step = step = 1;
440          sprintf (buf, "uid %d", ctx->uid_index);          sprintf (buf, "uid %d", ctx->getUseridIndex ());
441          return buf;          return buf;
442      }      }
443      else if (step == 1 && !strcmp (key, "keyedit.prompt")) {      else if (step == 1 && !strcmp (key, "keyedit.prompt")) {
# Line 468  cmd_revsig_handler (GpgKeyEdit *ctx, gpg Line 481  cmd_revsig_handler (GpgKeyEdit *ctx, gpg
481      int step = *r_step;      int step = *r_step;
482            
483      if( step == 0 && !strcmp ( key, "keyedit.prompt" ) ) {      if( step == 0 && !strcmp ( key, "keyedit.prompt" ) ) {
484          sprintf( buf, "uid %d", ctx->uid_index);          sprintf( buf, "uid %d", ctx->getUseridIndex ());
485          *r_step = step = 1;          *r_step = step = 1;
486          return buf;          return buf;
487      }      }
# Line 519  cmd_revkey_handler (GpgKeyEdit *ctx, gpg Line 532  cmd_revkey_handler (GpgKeyEdit *ctx, gpg
532      static char buf[64];      static char buf[64];
533    
534      if( step == 0 && !strcmp ( key, "keyedit.prompt" ) ) {      if( step == 0 && !strcmp ( key, "keyedit.prompt" ) ) {
535          sprintf( buf, "key %d", ctx->key_index);          sprintf( buf, "key %d", ctx->getKeyIndex ());
536          *r_step = step = 1;          *r_step = step = 1;
537          return buf;          return buf;
538      }      }
# Line 566  cmd_addrev_handler (GpgKeyEdit *ctx, gpg Line 579  cmd_addrev_handler (GpgKeyEdit *ctx, gpg
579    
580      /* If the isuser already signed the key, send an empty      /* If the isuser already signed the key, send an empty
581             string and jump to quit. */             string and jump to quit. */
582      if (ctx->getResult () & GPG_EDITRES_ALREADY_SIGNED      if (ctx->getResult () & EDITKEY_ERR_ALREADY_SIGNED
583          && *r_step != -1 && *r_step != 4) {          && *r_step != -1 && *r_step != 4) {
584          *r_step = step = -1;          *r_step = step = -1;
585          return "";          return "";
# Line 663  static gpgme_error_t Line 676  static gpgme_error_t
676  editkey_command_handler (void *opaque, gpgme_status_code_t code,  editkey_command_handler (void *opaque, gpgme_status_code_t code,
677                           const char *key, int fd)                           const char *key, int fd)
678  {  {
679      static int step = 0;      static int step = 0; /* XXX use ke->cnt */
680      const char *out = NULL;      const char *out = NULL;
681      GpgKeyEdit *ke = (GpgKeyEdit *)opaque;      GpgKeyEdit *ke = (GpgKeyEdit *)opaque;
682      HANDLE hd = (HANDLE)fd;      HANDLE hd = (HANDLE)fd;
# Line 675  editkey_command_handler (void *opaque, g Line 688  editkey_command_handler (void *opaque, g
688      /*log_debug ("key=%s code=%d\r\n", key, code);*/      /*log_debug ("key=%s code=%d\r\n", key, code);*/
689      switch (code) {      switch (code) {
690      case GPGME_STATUS_ALREADY_SIGNED:      case GPGME_STATUS_ALREADY_SIGNED:
691          ke->setResult (GPG_EDITRES_ALREADY_SIGNED);          ke->setResult (EDITKEY_ERR_ALREADY_SIGNED);
692          break;          break;
693    
694      case GPGME_STATUS_BAD_PASSPHRASE:      case GPGME_STATUS_BAD_PASSPHRASE:
695          ke->setResult (GPG_EDITRES_BAD_PASSPHRASE);          ke->setResult (EDITKEY_ERR_BAD_PASSPHRASE);
696          break;          break;
697    
698      default:      default:
699          break;          break;
700      }      }
701    
702      if (ke->getResult () & GPG_EDITRES_BAD_PASSPHRASE) {      if (ke->getResult () & EDITKEY_ERR_BAD_PASSPHRASE) {
703          /* If the entered passphrase is bad, we supply empty          /* If the entered passphrase is bad, we supply empty
704             passphrase to abort and send 'quit' as soon as possible. */             passphrase to abort and send 'quit' as soon as possible. */
705          if (!strcmp (key, "passphrase.enter"))          if (!strcmp (key, "passphrase.enter"))
706              WriteFile (hd, "\n", 1, &n, NULL);              WriteFile (hd, "\n", 1, &n, NULL);
707          if (!strcmp (key, "keyedit.prompt"))          if (!strcmp (key, "keyedit.prompt"))
708              WriteFile (hd, "quit\n", 5, &n, NULL);              WriteFile (hd, "quit\n", 5, &n, NULL);
709            ke->reset ();
710            step = 0;
711            return 0;
712      }      }
713            
714      switch (ke->getType ()) {      switch (ke->getType ()) {
# Line 797  map_result (GpgKeyEdit *ke) Line 813  map_result (GpgKeyEdit *ke)
813      /* XXX Sometimes ALREADY_SIGNED indicates an failure. */      /* XXX Sometimes ALREADY_SIGNED indicates an failure. */
814      if (!ke->getResult ())      if (!ke->getResult ())
815          return gpg_error (GPG_ERR_NO_ERROR);          return gpg_error (GPG_ERR_NO_ERROR);
816      if (ke->getResult () & GPG_EDITRES_BAD_PASSPHRASE)      if (ke->getResult () & EDITKEY_ERR_BAD_PASSPHRASE)
817          return gpg_error (GPG_ERR_BAD_PASSPHRASE);          return gpg_error (GPG_ERR_BAD_PASSPHRASE);
818      return 0;      return 0;
819  }  }

Legend:
Removed from v.119  
changed lines
  Added in v.170

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26