/[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 129 by twoaday, Fri Dec 30 13:56:10 2005 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 274  cmd_addkey_handler (GpgKeyEdit *ctx, gpg Line 279  cmd_addkey_handler (GpgKeyEdit *ctx, gpg
279      if (!strcmp (key, "passphrase.enter"))      if (!strcmp (key, "passphrase.enter"))
280          return ctx->pass;          return ctx->pass;
281      if (!strcmp (key, "keygen.algo")) {      if (!strcmp (key, "keygen.algo")) {
282          _snprintf (buf, sizeof buf-1, "%d", ctx->pubkey_algo);          _snprintf (buf, sizeof (buf)-1, "%d", ctx->pubkey_algo);
283          return buf;          return buf;
284      }        }  
285      if (!strcmp (key, "keygen.size")) {      if (!strcmp (key, "keygen.size")) {
286          _snprintf (buf, sizeof buf-1, "%d", ctx->pubkey_size);          _snprintf (buf, sizeof (buf)-1, "%d", ctx->pubkey_size);
287          return buf;          return buf;
288      }      }
289      if (!strcmp (key, "keygen.valid")) {      if (!strcmp (key, "keygen.valid")) {
290          _snprintf (buf, sizeof buf-1, "%d", ctx->valid);          _snprintf (buf, sizeof (buf)-1, "%d", ctx->valid);
291          return buf;                  return buf;        
292      }      }
293      if (!strcmp (key, "keyedit.prompt")) {      if (!strcmp (key, "keyedit.prompt")) {
# Line 300  cmd_passwd_handler (GpgKeyEdit *ctx, gpg Line 305  cmd_passwd_handler (GpgKeyEdit *ctx, gpg
305          ctx->cmd_sent = 1;          ctx->cmd_sent = 1;
306          return "passwd";          return "passwd";
307      }      }
308      if( !strcmp (key, "passphrase.enter") && !ctx->cnt) {      if (!ctx->cnt && !strcmp (key, "passphrase.enter")) {
309          ctx->cnt = 1;          ctx->cnt = 1;
310          return ctx->pass;          return ctx->pass;
311      }      }
312      if( !strcmp (key, "passphrase.enter" ))      if (!strcmp (key, "passphrase.enter" ))
313          return ctx->new_pass;          return ctx->new_pass;
314      if( !strcmp (key, "change_passwd.empty.okay" ))      if (!strcmp (key, "change_passwd.empty.okay" ))
315          return ctx->flags?  "Y" : "N";          return ctx->flags?  "Y" : "N";
316      if (!strcmp (key, "keyedit.prompt")) {      if (!strcmp (key, "keyedit.prompt")) {
317          ctx->reset ();          ctx->reset ();
318          return "save";          return "save";
319      }      }
320    
321      return NULL;      return NULL;
322  }  }
323    
# Line 319  cmd_passwd_handler (GpgKeyEdit *ctx, gpg Line 325  cmd_passwd_handler (GpgKeyEdit *ctx, gpg
325  static const char*  static const char*
326  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)
327  {  {
328        static char buf[128];
329    
330      /* XXX: check the code. */      /* XXX: check the code. */
331  #if 0  #if 0
     static char buf[128];  
332      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {
333          ctx->cmd_sent = 1;          ctx->cmd_sent = 1;
334          return "";          return "";
# Line 566  cmd_addrev_handler (GpgKeyEdit *ctx, gpg Line 573  cmd_addrev_handler (GpgKeyEdit *ctx, gpg
573    
574      /* If the isuser already signed the key, send an empty      /* If the isuser already signed the key, send an empty
575             string and jump to quit. */             string and jump to quit. */
576      if (ctx->getResult () & GPG_EDITRES_ALREADY_SIGNED      if (ctx->getResult () & EDITKEY_ERR_ALREADY_SIGNED
577          && *r_step != -1 && *r_step != 4) {          && *r_step != -1 && *r_step != 4) {
578          *r_step = step = -1;          *r_step = step = -1;
579          return "";          return "";
# Line 663  static gpgme_error_t Line 670  static gpgme_error_t
670  editkey_command_handler (void *opaque, gpgme_status_code_t code,  editkey_command_handler (void *opaque, gpgme_status_code_t code,
671                           const char *key, int fd)                           const char *key, int fd)
672  {  {
673      static int step = 0;      static int step = 0; /* XXX use ke->cnt */
674      const char *out = NULL;      const char *out = NULL;
675      GpgKeyEdit *ke = (GpgKeyEdit *)opaque;      GpgKeyEdit *ke = (GpgKeyEdit *)opaque;
676      HANDLE hd = (HANDLE)fd;      HANDLE hd = (HANDLE)fd;
# Line 675  editkey_command_handler (void *opaque, g Line 682  editkey_command_handler (void *opaque, g
682      /*log_debug ("key=%s code=%d\r\n", key, code);*/      /*log_debug ("key=%s code=%d\r\n", key, code);*/
683      switch (code) {      switch (code) {
684      case GPGME_STATUS_ALREADY_SIGNED:      case GPGME_STATUS_ALREADY_SIGNED:
685          ke->setResult (GPG_EDITRES_ALREADY_SIGNED);          ke->setResult (EDITKEY_ERR_ALREADY_SIGNED);
686          break;          break;
687    
688      case GPGME_STATUS_BAD_PASSPHRASE:      case GPGME_STATUS_BAD_PASSPHRASE:
689          ke->setResult (GPG_EDITRES_BAD_PASSPHRASE);          ke->setResult (EDITKEY_ERR_BAD_PASSPHRASE);
690          break;          break;
691    
692      default:      default:
693          break;          break;
694      }      }
695    
696      if (ke->getResult () & GPG_EDITRES_BAD_PASSPHRASE) {      if (ke->getResult () & EDITKEY_ERR_BAD_PASSPHRASE) {
697          /* If the entered passphrase is bad, we supply empty          /* If the entered passphrase is bad, we supply empty
698             passphrase to abort and send 'quit' as soon as possible. */             passphrase to abort and send 'quit' as soon as possible. */
699          if (!strcmp (key, "passphrase.enter"))          if (!strcmp (key, "passphrase.enter"))
700              WriteFile (hd, "\n", 1, &n, NULL);              WriteFile (hd, "\n", 1, &n, NULL);
701          if (!strcmp (key, "keyedit.prompt"))          if (!strcmp (key, "keyedit.prompt"))
702              WriteFile (hd, "quit\n", 5, &n, NULL);              WriteFile (hd, "quit\n", 5, &n, NULL);
703            ke->reset ();
704            step = 0;
705            return 0;
706      }      }
707            
708      switch (ke->getType ()) {      switch (ke->getType ()) {
# Line 797  map_result (GpgKeyEdit *ke) Line 807  map_result (GpgKeyEdit *ke)
807      /* XXX Sometimes ALREADY_SIGNED indicates an failure. */      /* XXX Sometimes ALREADY_SIGNED indicates an failure. */
808      if (!ke->getResult ())      if (!ke->getResult ())
809          return gpg_error (GPG_ERR_NO_ERROR);          return gpg_error (GPG_ERR_NO_ERROR);
810      if (ke->getResult () & GPG_EDITRES_BAD_PASSPHRASE)      if (ke->getResult () & EDITKEY_ERR_BAD_PASSPHRASE)
811          return gpg_error (GPG_ERR_BAD_PASSPHRASE);          return gpg_error (GPG_ERR_BAD_PASSPHRASE);
812      return 0;      return 0;
813  }  }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26