/[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 207 by twoaday, Fri Apr 28 10:28:24 2006 UTC revision 328 by twoaday, Fri Sep 25 16:07:38 2009 UTC
# Line 13  Line 13 
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * General Public License for more details.   * General Public License for more details.
  *  
  * You should have received a copy of the GNU General Public License  
  * along with WinPT; if not, write to the Free Software Foundation,  
  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  
16   */   */
   
17  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
18  #include <config.h>  #include <config.h>
19  #endif  #endif
# Line 34  Line 29 
29  #include "wptContext.h"  #include "wptContext.h"
30  #include "wptKeyEdit.h"  #include "wptKeyEdit.h"
31  #include "wptErrors.h"  #include "wptErrors.h"
32    #include "wptTypes.h"
33    
34    
35  /* Possible errors for the edit key operation. */  /* Possible errors for the edit key operation. */
36  enum editkey_error_t {  enum editkey_error_t {
# Line 43  enum editkey_error_t { Line 40  enum editkey_error_t {
40    
41  typedef gpgme_status_code_t status_code_t;  typedef gpgme_status_code_t status_code_t;
42    
43    
44  /* 'notation' command handler. */  /* 'notation' command handler. */
45  static const char*  static const char*
46  cmd_notation_handler (GpgKeyEdit *ctx, status_code_t code, const char *key)  cmd_notation_handler (GpgKeyEdit *ctx, status_code_t code, const char *key)
# Line 53  cmd_notation_handler (GpgKeyEdit *ctx, s Line 51  cmd_notation_handler (GpgKeyEdit *ctx, s
51          int uid = ctx->getUseridIndex ();          int uid = ctx->getUseridIndex ();
52          ctx->cmd_sent = 1;          ctx->cmd_sent = 1;
53          if (uid != -1) {          if (uid != -1) {
54              sprintf (buf, "uid %d", ctx->getUseridIndex ());              _snprintf (buf, DIM (buf)-1, "uid %d", ctx->getUseridIndex ());
55              return buf;              return buf;
56          }          }
57      }      }
# Line 80  cmd_keyserv_handler (GpgKeyEdit *ctx, gp Line 78  cmd_keyserv_handler (GpgKeyEdit *ctx, gp
78          int uid = ctx->getUseridIndex ();          int uid = ctx->getUseridIndex ();
79          ctx->cmd_sent = 1;          ctx->cmd_sent = 1;
80          if (uid != -1) {          if (uid != -1) {
81              sprintf (buf, "uid %d", ctx->getUseridIndex ());              _snprintf (buf, DIM (buf)-1, "uid %d", ctx->getUseridIndex ());
82              return buf;              return buf;
83          }          }
84      }      }
# Line 112  cmd_sign_handler (GpgKeyEdit *ctx, gpgme Line 110  cmd_sign_handler (GpgKeyEdit *ctx, gpgme
110      if (ctx->getUseridIndex () != -1 &&      if (ctx->getUseridIndex () != -1 &&
111          ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {          ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
112          ctx->cnt++;          ctx->cnt++;
113          sprintf (buf, "uid %d", ctx->getUseridIndex ());          _snprintf (buf, DIM (buf)-1, "uid %d", ctx->getUseridIndex ());
114          return buf;          return buf;
115      }      }
116    
117      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {
118          ctx->cmd_sent = 1;          ctx->cmd_sent = 1;
119          switch (ctx->getType ()) {          switch (ctx->getType ()) {
120          case GPG_EDITKEY_SIGN:      return "sign";          case GPG_EDITKEY_SIGN:    return "sign";
121          case GPG_EDITKEY_TSIGN:     return "tsign";          case GPG_EDITKEY_TSIGN:   return "tsign";
122          case GPG_EDITKEY_LSIGN:     return "lsign";          case GPG_EDITKEY_LSIGN:   return "lsign";
123          case GPG_EDITKEY_NRSIGN:    return"nrsign";          case GPG_EDITKEY_NRSIGN:  return "nrsign";
124          case GPG_EDITKEY_NRLSIGN:   return "nrlsign";          case GPG_EDITKEY_NRLSIGN: return "nrlsign";
125          }          }
126      }      }
127      if (!strcmp (key, "sign_uid.class")) {      if (!strcmp (key, "sign_uid.class")) {
# Line 133  cmd_sign_handler (GpgKeyEdit *ctx, gpgme Line 131  cmd_sign_handler (GpgKeyEdit *ctx, gpgme
131      if (!strcmp (key, "sign_uid.expire"))      if (!strcmp (key, "sign_uid.expire"))
132          return "Y"; /* the sig expires when the key expires */          return "Y"; /* the sig expires when the key expires */
133      if (!strcmp (key, "siggen.valid"))      if (!strcmp (key, "siggen.valid"))
134          return ctx->exp_date;          return ctx->exp_date? ctx->exp_date : "0";
135      if (!strcmp (key, "trustsig_prompt.trust_value")) {      if (!strcmp (key, "trustsig_prompt.trust_value")) {
136          sprintf (buf, "%d", ctx->trust_id);          sprintf (buf, "%d", ctx->trust_id);
137          return buf;          return buf;
# Line 148  cmd_sign_handler (GpgKeyEdit *ctx, gpgme Line 146  cmd_sign_handler (GpgKeyEdit *ctx, gpgme
146          return "Y";          return "Y";
147      if (!strcmp (key, "keyedit.sign_all.okay"))      if (!strcmp (key, "keyedit.sign_all.okay"))
148          return "Y";          return "Y";
149      if (!strcmp ( key, "passphrase.enter"))      if (!ctx->usePassphraseCallback() && !strcmp (key, "passphrase.enter"))    
150          return ctx->pass;          return ctx->pass;
151      if (!strcmp (key, "keyedit.prompt")) {      if (!strcmp (key, "keyedit.prompt")) {
152          ctx->reset ();          ctx->reset ();
153          return "save";          return "save";
# Line 215  cmd_deluid_handler (GpgKeyEdit *ctx, gpg Line 213  cmd_deluid_handler (GpgKeyEdit *ctx, gpg
213      static char buf[64];      static char buf[64];
214    
215      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
216          sprintf (buf, "uid %d", ctx->getUseridIndex ());          _snprintf (buf, DIM (buf)-1, "uid %d", ctx->getUseridIndex ());
217          ctx->cnt = 1;          ctx->cnt = 1;
218          return buf;          return buf;
219      }      }
# Line 243  cmd_delsig_handler (GpgKeyEdit *ctx, gpg Line 241  cmd_delsig_handler (GpgKeyEdit *ctx, gpg
241      static int sig_cnt = 0;      static int sig_cnt = 0;
242    
243      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
244          sprintf (buf, "uid %d", ctx->getUseridIndex ());          _snprintf (buf, DIM (buf)-1, "uid %d", ctx->getUseridIndex ());
245          ctx->cnt = 1;          ctx->cnt = 1;
246          return buf;          return buf;
247      }      }
# Line 277  cmd_delkey_handler (GpgKeyEdit *ctx, gpg Line 275  cmd_delkey_handler (GpgKeyEdit *ctx, gpg
275      static char buf[64];      static char buf[64];
276    
277      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
278          sprintf (buf, "key %d", ctx->getKeyIndex ());          _snprintf (buf, DIM (buf)-1, "key %d", ctx->getKeyIndex ());
279          ctx->cnt = 1;          ctx->cnt = 1;
280          return buf;          return buf;
281      }      }
# Line 298  cmd_delkey_handler (GpgKeyEdit *ctx, gpg Line 296  cmd_delkey_handler (GpgKeyEdit *ctx, gpg
296  }  }
297    
298    
299    /* 'addcardkey' command handler. */
300    static const char*
301    cmd_addcardkey_handler (GpgKeyEdit *ctx, status_code_t code, const char *key)
302    {
303        static char buf[32];
304    
305        /* XXX: actually we mix up things here, it would be better to
306                implement this in CardEditCB but because the edit-key
307                interface is used, we have to implement it here. */
308        if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {
309            ctx->cmd_sent = 1;
310            return "addcardkey";
311        }
312        if (!strcmp (key, "cardedit.genkeys.subkeytype")) {
313            sprintf (buf, "%d", ctx->getKeyIndex ());
314            return buf;
315        }
316        if (!strcmp (key, "cardedit.genkeys.replace_key"))
317            return "Y"; /* better issue an extra warning? */
318        if (!strcmp (key, "passphrase.adminpin.ask"))
319            return ctx->pass;
320        if (!strcmp (key, "passphrase.pin.ask"))
321            return ctx->new_pass;
322        if (!strcmp (key, "keygen.valid")) {
323            sprintf (buf, "%d", ctx->getValidDays ());
324            return buf;
325        }
326        if (!strcmp (key, "keyedit.prompt")) {
327            ctx->reset ();
328            return "save";
329        }
330        return NULL;
331    }
332    
333    
334  /* 'addkey' command handler. */  /* 'addkey' command handler. */
335  static const char*  static const char*
336  cmd_addkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)  cmd_addkey_handler (GpgKeyEdit *ctx, status_code_t code, const char *key)
337  {  {
338      static char buf[64];      static char buf[64];
339    
# Line 341  cmd_passwd_handler (GpgKeyEdit *ctx, gpg Line 374  cmd_passwd_handler (GpgKeyEdit *ctx, gpg
374      }      }
375      if (ctx->cnt == 0 && !strcmp (key, "passphrase.enter")) {      if (ctx->cnt == 0 && !strcmp (key, "passphrase.enter")) {
376          ctx->cnt = 1;          ctx->cnt = 1;
377            /* it is possible that there is no old passphrase. */
378            if (!ctx->pass && ctx->flags)
379                return "";
380          return ctx->pass;          return ctx->pass;
381      }      }
382      if (!strcmp (key, "passphrase.enter" ))      if (!strcmp (key, "passphrase.enter" ))
# Line 356  cmd_passwd_handler (GpgKeyEdit *ctx, gpg Line 392  cmd_passwd_handler (GpgKeyEdit *ctx, gpg
392  }  }
393    
394    
395    /* 'setpref' command handler. */
396  static const char*  static const char*
397  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)
398  {  {
399      static char buf[128];      static char buf[128] = {0};
400    
401      /* XXX: check the code. */      if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) {
402  #if 0          _snprintf (buf, sizeof (buf)-1, "uid %d", ctx->getUseridIndex ());
     if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {  
403          ctx->cmd_sent = 1;          ctx->cmd_sent = 1;
404          return "";          ctx->cnt = 1;
     }  
     if (!strcmp (key, "keyedit.prompt") && ctx->u.pref.id == 0) {  
         ctx->u.pref.id++;  
         _snprintf (buf, sizeof buf-1, "setpref %s", ctx->u.pref.new_prefs);  
405          return buf;          return buf;
406      }      }
407      if (!strcmp (key, "keyedit.prompt") && ctx->u.pref.id == 1) {      if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 1) {
408          ctx->u.pref.id++;          _snprintf (buf, sizeof buf-1, "setpref %s", ctx->new_prefs);
409          return "updpref";          ctx->cnt = 2;
410            return buf;
411      }      }
412      if (!strcmp (key, "keyedit.updpref.okay"))      if (!strcmp (key, "keyedit.setpref.okay"))
413          return "Y";          return "Y";
414      if (!strcmp (key, "passphrase.enter"))      if (!strcmp (key, "passphrase.enter"))
415          return ctx->u.pref.passwd;          return ctx->pass;
416      if (!strcmp (key, "keyedit.prompt") && ctx->u.pref.id == 2) {      if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 2) {
         ctx->u.pref.id = 0;  
417          ctx->reset ();          ctx->reset ();
418          return "save";          return "save";
419      }      }
420  #endif      return buf;
     return NULL;  
421  }  }
422    
423    
# Line 396  cmd_primary_handler (GpgKeyEdit *ctx, gp Line 427  cmd_primary_handler (GpgKeyEdit *ctx, gp
427                       const char *key)                       const char *key)
428  {  {
429      static char buf[64];      static char buf[64];
430        
431      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
432          sprintf (buf, "uid %d", ctx->getUseridIndex ());          _snprintf (buf, DIM (buf)-1, "uid %d", ctx->getUseridIndex ());
433          ctx->cnt = 1;          ctx->cnt = 1;
434          return buf;          return buf;
435      }      }
# Line 426  cmd_expire_handler (GpgKeyEdit *ctx, gpg Line 457  cmd_expire_handler (GpgKeyEdit *ctx, gpg
457      static char buf[64];      static char buf[64];
458    
459      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
460          sprintf (buf, "key %d", ctx->getKeyIndex ());          _snprintf (buf, DIM (buf)-1, "key %d", ctx->getKeyIndex ());
461          ctx->cnt = 1;          ctx->cnt = 1;
462          return buf;          return buf;
463      }      }
# Line 461  cmd_revuid_handler (GpgKeyEdit *ctx, gpg Line 492  cmd_revuid_handler (GpgKeyEdit *ctx, gpg
492            
493      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
494          ctx->cnt = 1;          ctx->cnt = 1;
495          sprintf (buf, "uid %d", ctx->getUseridIndex ());          _snprintf (buf, DIM (buf)-1, "uid %d", ctx->getUseridIndex ());
496          return buf;          return buf;
497      }      }
498      else if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) {      else if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) {
# Line 503  cmd_revsig_handler (GpgKeyEdit *ctx, gpg Line 534  cmd_revsig_handler (GpgKeyEdit *ctx, gpg
534      static char buf[64];      static char buf[64];
535            
536      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt" )) {      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt" )) {
537          sprintf( buf, "uid %d", ctx->getUseridIndex ());          _snprintf (buf, DIM (buf)-1, "uid %d", ctx->getUseridIndex ());
538          ctx->cnt = 1;          ctx->cnt = 1;
539          return buf;          return buf;
540      }      }
541      if (ctx->cnt == 1 && !strcmp ( key, "keyedit.prompt" ) ) {      if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) {
542          ctx->cnt = 2;          ctx->cnt = 2;
543          return "revsig";          return "revsig";
544      }      }
545      if (ctx->cnt == 2 && !strcmp (key, "ask_revoke_sig.one" ) ) {      if (ctx->cnt == 2 && !strcmp (key, "ask_revoke_sig.one")) {
546          ctx->cnt = 3;          ctx->cnt = 3;
547          return "Y";          return "Y";
548      }      }
549      if (ctx->cnt == 3 && !strcmp (key, "ask_revoke_sig.okay" ) ) {      if (ctx->cnt == 3 && !strcmp (key, "ask_revoke_sig.okay")) {
550          ctx->cnt = 4;          ctx->cnt = 4;
551          return "Y";          return "Y";
552      }      }
553      if (ctx->cnt == 4 && !strcmp ( key, "ask_revocation_reason.code" ) ) {      if (ctx->cnt == 4 && !strcmp (key, "ask_revocation_reason.code")) {
554          ctx->cnt = 5;          ctx->cnt = 5;
555          return "0";          return "0";
556      }      }
557      if (ctx->cnt == 5 && !strcmp ( key, "ask_revocation_reason.text" ) ) {      if (ctx->cnt == 5 && !strcmp (key, "ask_revocation_reason.text" )) {
558          ctx->cnt = 6;          ctx->cnt = 6;
559          return "";          return "";
560      }      }
# Line 535  cmd_revsig_handler (GpgKeyEdit *ctx, gpg Line 566  cmd_revsig_handler (GpgKeyEdit *ctx, gpg
566          ctx->cnt = 8;          ctx->cnt = 8;
567          return ctx->pass;          return ctx->pass;
568      }      }
569      if (ctx->cnt == 8 && !strcmp ( key, "keyedit.prompt" ) ) {      if (ctx->cnt == 8 && !strcmp (key, "keyedit.prompt")) {
570          ctx->reset ();          ctx->reset ();
571          return "save";          return "save";
572      }      }
# Line 552  cmd_revkey_handler (GpgKeyEdit *ctx, gpg Line 583  cmd_revkey_handler (GpgKeyEdit *ctx, gpg
583      static char buf[64];      static char buf[64];
584    
585      if (ctx->cnt == 0 && !strcmp ( key, "keyedit.prompt" ) ) {      if (ctx->cnt == 0 && !strcmp ( key, "keyedit.prompt" ) ) {
586          sprintf( buf, "key %d", ctx->getKeyIndex ());          _snprintf (buf, DIM (buf)-1, "key %d", ctx->getKeyIndex ());
587          ctx->cnt = 1;          ctx->cnt = 1;
588          return buf;          return buf;
589      }      }
# Line 721  editkey_command_handler (void *opaque, g Line 752  editkey_command_handler (void *opaque, g
752          break;          break;
753    
754      case GPGME_STATUS_BAD_PASSPHRASE:      case GPGME_STATUS_BAD_PASSPHRASE:
755            log_debug ("editkey_command_handler: bad passphrase\n");
756          ke->setResult (EDITKEY_ERR_BAD_PASSPHRASE);          ke->setResult (EDITKEY_ERR_BAD_PASSPHRASE);
757          break;          break;
758    
# Line 761  editkey_command_handler (void *opaque, g Line 793  editkey_command_handler (void *opaque, g
793          break;          break;
794                    
795      case GPG_EDITKEY_DELSIG:      case GPG_EDITKEY_DELSIG:
796          out =  cmd_delsig_handler (ke, code, key);          out = cmd_delsig_handler (ke, code, key);
797          break;          break;
798    
799      case GPG_EDITKEY_DELKEY:      case GPG_EDITKEY_DELKEY:
# Line 769  editkey_command_handler (void *opaque, g Line 801  editkey_command_handler (void *opaque, g
801          break;          break;
802                    
803      case GPG_EDITKEY_ADDKEY:      case GPG_EDITKEY_ADDKEY:
804          out =  cmd_addkey_handler (ke, code, key);          out = cmd_addkey_handler (ke, code, key);
805            break;
806    
807        case GPG_EDITKEY_ADDCARDKEY:
808            out = cmd_addcardkey_handler (ke, code, key);
809          break;          break;
810                    
811      case GPG_EDITKEY_PASSWD:      case GPG_EDITKEY_PASSWD:

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26