/[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 328 by twoaday, Fri Sep 25 16:07:38 2009 UTC revision 333 by twoaday, Tue Oct 13 10:51:21 2009 UTC
# Line 1  Line 1 
1  /* wptKeyEditCB.cpp - Key edit callback handling  /* wptKeyEditCB.cpp - Key edit callback handling
2   *      Copyright (C) 2005, 2006 Timo Schulz   *      Copyright (C) 2005, 2006, 2009 Timo Schulz
3   *      Copyright (C) 2005 g10 Code GmbH   *      Copyright (C) 2005 g10 Code GmbH
4   *   *
5   * This file is part of WinPT.   * This file is part of WinPT.
# Line 345  cmd_addkey_handler (GpgKeyEdit *ctx, sta Line 345  cmd_addkey_handler (GpgKeyEdit *ctx, sta
345      if (!strcmp (key, "passphrase.enter"))      if (!strcmp (key, "passphrase.enter"))
346          return ctx->pass;          return ctx->pass;
347      if (!strcmp (key, "keygen.algo")) {      if (!strcmp (key, "keygen.algo")) {
348          _snprintf (buf, sizeof (buf)-1, "%d", ctx->pubkey_algo);          _snprintf (buf, DIM (buf)-1, "%d", ctx->pubkey_algo);
349          return buf;          return buf;
350      }        }  
351      if (!strcmp (key, "keygen.size")) {      if (!strcmp (key, "keygen.size")) {
352          _snprintf (buf, sizeof (buf)-1, "%d", ctx->pubkey_size);          _snprintf (buf, DIM (buf)-1, "%d", ctx->pubkey_size);
353          return buf;          return buf;
354      }      }
355      if (!strcmp (key, "keygen.valid")) {      if (!strcmp (key, "keygen.valid")) {
356          _snprintf (buf, sizeof (buf)-1, "%d", ctx->getValidDays ());          _snprintf (buf, DIM (buf)-1, "%d", ctx->getValidDays ());
357          return buf;                  return buf;        
358      }      }
359      if (!strcmp (key, "keyedit.prompt")) {      if (!strcmp (key, "keyedit.prompt")) {
# Line 399  cmd_setpref_handler (GpgKeyEdit *ctx, gp Line 399  cmd_setpref_handler (GpgKeyEdit *ctx, gp
399      static char buf[128] = {0};      static char buf[128] = {0};
400    
401      if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) {      if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) {
402          _snprintf (buf, sizeof (buf)-1, "uid %d", ctx->getUseridIndex ());          _snprintf (buf, DIM (buf)-1, "uid %d", ctx->getUseridIndex ());
403          ctx->cmd_sent = 1;          ctx->cmd_sent = 1;
404          ctx->cnt = 1;          ctx->cnt = 1;
405          return buf;          return buf;
406      }      }
407      if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 1) {      if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 1) {
408          _snprintf (buf, sizeof buf-1, "setpref %s", ctx->new_prefs);          _snprintf (buf, DIM (buf)-1, "setpref %s", ctx->new_prefs);
409          ctx->cnt = 2;          ctx->cnt = 2;
410          return buf;          return buf;
411      }      }
# Line 641  cmd_addrev_handler (GpgKeyEdit *ctx, gpg Line 641  cmd_addrev_handler (GpgKeyEdit *ctx, gpg
641          ctx->cnt = 1;          ctx->cnt = 1;
642          return "addrevoker";          return "addrevoker";
643      }      }
644      if (ctx->cnt == 1 && !strcmp (key, "keyedit.add_revoker")) {      if (!strcmp (key, "keyedit.add_revoker"))  
         ctx->cnt = 2;  
645          return ctx->name;          return ctx->name;
646      }      
647      if (ctx->cnt == 2 && !strcmp (key, "keyedit.add_revoker.okay")) {      if (!strcmp (key, "keyedit.add_revoker.okay"))      
         ctx->cnt = 3;  
648          return "Y";          return "Y";
649      }      
650      if (ctx->cnt == 3 && !strcmp (key, "passphrase.enter")) {      if (!strcmp (key, "passphrase.enter"))      
         ctx->cnt = 4;  
651          return ctx->pass;          return ctx->pass;
652      }  
653      if (ctx->cnt == 4 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt > 0 && !strcmp (key, "keyedit.prompt")) {
654          ctx->reset ();          ctx->reset ();
655          return "save";          return "save";
656      }      }
# Line 751  editkey_command_handler (void *opaque, g Line 748  editkey_command_handler (void *opaque, g
748          ke->setResult (EDITKEY_ERR_ALREADY_SIGNED);          ke->setResult (EDITKEY_ERR_ALREADY_SIGNED);
749          break;          break;
750    
751        //case GPGME_STATUS_GOOD_PASSPHRASE:
752    //      ke->setResult (0);
753    //      break;
754    
755      case GPGME_STATUS_BAD_PASSPHRASE:      case GPGME_STATUS_BAD_PASSPHRASE:
756          log_debug ("editkey_command_handler: bad passphrase\n");          if (!ke->usePassphraseCallback ()) {
757          ke->setResult (EDITKEY_ERR_BAD_PASSPHRASE);              log_debug ("editkey_command_handler: bad passphrase\n");
758                ke->setResult (EDITKEY_ERR_BAD_PASSPHRASE);
759            }
760          break;          break;
761    
762      default:      default:
763          break;          break;
764      }      }
765    
766      if (ke->getResult () & EDITKEY_ERR_BAD_PASSPHRASE) {      /* If the entered passphrase is bad, we supply empty
767          /* If the entered passphrase is bad, we supply empty         passphrase to abort and send 'quit' as soon as possible.
768             passphrase to abort and send 'quit' as soon as possible. */         But this semantic is not used when we use the callback mode. */
769        if (!ke->usePassphraseCallback() &&
770            (ke->getResult () & EDITKEY_ERR_BAD_PASSPHRASE)) {
771            
772          if (!strcmp (key, "passphrase.enter"))          if (!strcmp (key, "passphrase.enter"))
773              WriteFile (hd, "\n", 1, &n, NULL);              WriteFile (hd, "\n", 1, &n, NULL);
774          if (!strcmp (key, "keyedit.prompt"))          if (!strcmp (key, "keyedit.prompt"))
# Line 880  editkey_command_handler (void *opaque, g Line 886  editkey_command_handler (void *opaque, g
886     Return value: gpg error constant. */     Return value: gpg error constant. */
887  static gpgme_error_t  static gpgme_error_t
888  map_result (GpgKeyEdit *ke)  map_result (GpgKeyEdit *ke)
889  {  {    
     /* XXX Sometimes ALREADY_SIGNED indicates an failure. */  
890      if (!ke->getResult ())      if (!ke->getResult ())
891          return gpg_error (GPG_ERR_NO_ERROR);          return gpg_error (GPG_ERR_NO_ERROR);
892      if (ke->getResult () & EDITKEY_ERR_BAD_PASSPHRASE)      if (ke->getResult () & EDITKEY_ERR_BAD_PASSPHRASE)

Legend:
Removed from v.328  
changed lines
  Added in v.333

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26