/[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 101 by twoaday, Fri Nov 25 10:56:05 2005 UTC revision 260 by twoaday, Wed Aug 16 10:01:30 2006 UTC
# Line 1  Line 1 
1  /* wptKeyEditCB.cpp - Key edit callback handling  /* wptKeyEditCB.cpp - Key edit callback handling
2   *      Copyright (C) 2005 Timo Schulz   *      Copyright (C) 2005, 2006 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 18  Line 18 
18   * along with WinPT; if not, write to the Free Software Foundation,   * along with WinPT; if not, write to the Free Software Foundation,
19   * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA   * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20   */   */
21    
22  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
23  #include <config.h>  #include <config.h>
24  #endif  #endif
25    
26  #include <stdio.h>  #include <stdio.h>
 #include <stdio.h>  
27  #include <string.h>  #include <string.h>
28  #include <stdlib.h>  #include <stdlib.h>
29  #include <assert.h>  #include <assert.h>
# 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    typedef gpgme_status_code_t status_code_t;
45    
46    
47    /* 'notation' command handler. */
48    static const char*
49    cmd_notation_handler (GpgKeyEdit *ctx, status_code_t code, const char *key)
50    {
51        static char buf[32];
52    
53        if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {
54            int uid = ctx->getUseridIndex ();
55            ctx->cmd_sent = 1;
56            if (uid != -1) {
57                sprintf (buf, "uid %d", ctx->getUseridIndex ());
58                return buf;
59            }
60        }
61        if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 0) {
62            ctx->cnt = 1;
63            return "notation";
64        }
65        if (!strcmp (key, "keyedit.add_notation"))
66            return ctx->notation;
67        if (!strcmp (key, "passphrase.enter"))
68            return ctx->pass;
69    
70        return NULL;
71    }
72    
73    
74  /* 'keyserver' command handler. */  /* 'keyserver' command handler. */
75  static const char*  static const char*
# Line 43  cmd_keyserv_handler (GpgKeyEdit *ctx, gp Line 78  cmd_keyserv_handler (GpgKeyEdit *ctx, gp
78      static char buf[32];      static char buf[32];
79    
80      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {
81            int uid = ctx->getUseridIndex ();
82          ctx->cmd_sent = 1;          ctx->cmd_sent = 1;
83          sprintf (buf, "uid %d", ctx->uid_index);          if (uid != -1) {
84          return buf;              sprintf (buf, "uid %d", ctx->getUseridIndex ());
85                return buf;
86            }
87      }      }
88      if (!strcmp (key, "keyedit.prompt") && !ctx->cnt) {      if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 0) {
89          ctx->cnt = 1;          ctx->cnt = 1;
90          return "keyserver";          return "keyserver";
91      }      }
92      if (!strcmp (key, "keyedit.add_keyserver"))      if (!strcmp (key, "keyedit.add_keyserver"))
93          return ctx->url;          return ctx->url;
94      if ( !strcmp (key, "keyedit.confirm_keyserver"))      if (!strcmp (key, "keyedit.confirm_keyserver"))
95          return "Y";          return "Y";
96      if (!strcmp (key, "passphrase.enter"))      if (!strcmp (key, "passphrase.enter"))
97          return ctx->pass;          return ctx->pass;
# Line 66  cmd_keyserv_handler (GpgKeyEdit *ctx, gp Line 104  cmd_keyserv_handler (GpgKeyEdit *ctx, gp
104  }  }
105    
106    
107    /* 'sign' command handler. */
108  static const char*  static const char*
109  cmd_sign_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)  cmd_sign_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)
110  {  {
111      static char buf[32];      static char buf[32];
112    
113        if (ctx->getUseridIndex () != -1 &&
114            ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
115            ctx->cnt++;
116            sprintf (buf, "uid %d", ctx->getUseridIndex ());
117            return buf;
118        }
119    
120      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {
121          ctx->cmd_sent = 1;          ctx->cmd_sent = 1;
122          switch (ctx->getType ()) {          switch (ctx->getType ()) {
123          case GPG_EDITKEY_SIGN: return "sign";          case GPG_EDITKEY_SIGN:    return "sign";
124          case GPG_EDITKEY_TSIGN: return "tsign";          case GPG_EDITKEY_TSIGN:   return "tsign";
125          case GPG_EDITKEY_LSIGN: return "lsign";          case GPG_EDITKEY_LSIGN:   return "lsign";
126          case GPG_EDITKEY_NRSIGN: return"nrsign";          case GPG_EDITKEY_NRSIGN:  return "nrsign";
127          case GPG_EDITKEY_NRLSIGN: return "nrlsign";          case GPG_EDITKEY_NRLSIGN: return "nrlsign";
128          }          }
129      }      }
# Line 88  cmd_sign_handler (GpgKeyEdit *ctx, gpgme Line 134  cmd_sign_handler (GpgKeyEdit *ctx, gpgme
134      if (!strcmp (key, "sign_uid.expire"))      if (!strcmp (key, "sign_uid.expire"))
135          return "Y"; /* the sig expires when the key expires */          return "Y"; /* the sig expires when the key expires */
136      if (!strcmp (key, "siggen.valid"))      if (!strcmp (key, "siggen.valid"))
137          return ctx->exp_date;          return ctx->exp_date? ctx->exp_date : "0";
138      if (!strcmp (key, "trustsig_prompt.trust_value")) {      if (!strcmp (key, "trustsig_prompt.trust_value")) {
139          sprintf (buf, "%d", ctx->trust_id);          sprintf (buf, "%d", ctx->trust_id);
140          return buf;          return buf;
# Line 164  cmd_adduid_handler (GpgKeyEdit *ctx, gpg Line 210  cmd_adduid_handler (GpgKeyEdit *ctx, gpg
210    
211    
212  static const char*  static const char*
213  cmd_deluid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key,  cmd_deluid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
214                      int *r_step)                      const char *key)
215  {  {
216      static char buf[64];      static char buf[64];
     int step = *r_step;  
217    
218      if (step == 0 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
219          sprintf (buf, "uid %d", ctx->uid_index);          sprintf (buf, "uid %d", ctx->getUseridIndex ());
220          *r_step = step = 1;          ctx->cnt = 1;
221          return buf;          return buf;
222      }      }
223      if (step == 1 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) {
224          *r_step = step = 2;          ctx->cnt = 2;
225          return "deluid";          return "deluid";
226      }      }
227      if (step == 2 && !strcmp (key, "keyedit.remove.uid.okay")) {      if (ctx->cnt == 2 && !strcmp (key, "keyedit.remove.uid.okay")) {
228          *r_step = step = 3;          ctx->cnt = 3;
229          return "Y";          return "Y";
230      }      }
231      if (step == 3 && !strcmp (key, "keyedit.prompt" )) {      if (ctx->cnt == 3 && !strcmp (key, "keyedit.prompt" )) {
         *r_step = step = 0;  
232          ctx->reset ();          ctx->reset ();
233          return "save";          return "save";
234      }      }
# Line 193  cmd_deluid_handler (GpgKeyEdit *ctx, gpg Line 237  cmd_deluid_handler (GpgKeyEdit *ctx, gpg
237  }  }
238    
239    
240  static const char *  static const char*
241  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)
                     int * r_step)  
242  {  {
243      static char buf[64];      static char buf[64];
244      int step = *r_step;      static int sig_cnt = 0;
245    
246      if (step == 0 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
247          sprintf (buf, "uid %d", ctx->uid_index);          sprintf (buf, "uid %d", ctx->getUseridIndex ());
248          *r_step = step = 1;          ctx->cnt = 1;
249          return buf;          return buf;
250      }      }
251      if (step == 1 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) {
252          *r_step = step = 2;          ctx->cnt = 2;
253          return "delsig";          return "delsig";
254      }      }
255      if (!strcmp (key, "keyedit.delsig.unknown") ||      if (!strcmp (key, "keyedit.delsig.unknown") ||
256          !strcmp (key, "keyedit.delsig.valid")) {          !strcmp (key, "keyedit.delsig.valid")) {
257          if (++ctx->cnt == ctx->sig_index)          if (++sig_cnt == ctx->getSigIndex ())
258              return "Y";              return "Y";
259          else          else
260              return "N";              return "N";
261      }      }
262      if (ctx->sig_index == 0 &&      if (!strcmp (key, "keyedit.delsig.selfsig"))
         !strcmp (key, "keyedit.delsig.selfsig"))  
263          return "Y";          return "Y";
264      if (step == 2 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 2 && !strcmp (key, "keyedit.prompt")) {
265          *r_step = step = 0;          sig_cnt = 0;
266          ctx->reset ();          ctx->reset ();
267          return "save";          return "save";
268      }      }
# Line 231  cmd_delsig_handler (GpgKeyEdit *ctx, gpg Line 273  cmd_delsig_handler (GpgKeyEdit *ctx, gpg
273  /* 'delkey' command handler. */  /* 'delkey' command handler. */
274  static const char*  static const char*
275  cmd_delkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,  cmd_delkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
276                      const char *key, int *r_step )                      const char *key)
277  {  {
278      static char buf[64];      static char buf[64];
     int step = *r_step;  
279    
280      if (step == 0 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
281          sprintf (buf, "key %d", ctx->key_index);          sprintf (buf, "key %d", ctx->getKeyIndex ());
282          *r_step = step = 1;          ctx->cnt = 1;
283          return buf;          return buf;
284      }      }
285      if (step == 1 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) {
286          *r_step = step = 2;          ctx->cnt = 2;
287          return "delkey";          return "delkey";
288      }      }
289      if (step == 2 && !strcmp (key, "keyedit.remove.subkey.okay")) {      if (ctx->cnt == 2 && !strcmp (key, "keyedit.remove.subkey.okay")) {
290          *r_step = step = 3;          ctx->cnt = 3;
291          return "Y";          return "Y";
292      }      }
293      if (step == 3 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 3 && !strcmp (key, "keyedit.prompt")) {
         *r_step = step = 0;  
294          ctx->reset ();          ctx->reset ();
295          return "save";          return "save";
296      }      }
# Line 259  cmd_delkey_handler (GpgKeyEdit *ctx, gpg Line 299  cmd_delkey_handler (GpgKeyEdit *ctx, gpg
299  }  }
300    
301    
302    /* 'addcardkey' command handler. */
303    static const char*
304    cmd_addcardkey_handler (GpgKeyEdit *ctx, status_code_t code, const char *key)
305    {
306        static char buf[32];
307    
308        /* XXX: actually we mix up things here, it would be better to
309                implement this in CardEditCB but because the edit-key
310                interface is used, we have to implement it here. */
311        if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {
312            ctx->cmd_sent = 1;
313            return "addcardkey";
314        }
315        if (!strcmp (key, "cardedit.genkeys.subkeytype")) {
316            sprintf (buf, "%d", ctx->getKeyIndex ());
317            return buf;
318        }
319        if (!strcmp (key, "cardedit.genkeys.replace_key"))
320            return "Y"; /* better issue an extra warning? */
321        if (!strcmp (key, "passphrase.adminpin.ask"))
322            return ctx->pass;
323        if (!strcmp (key, "passphrase.pin.ask"))
324            return ctx->new_pass;
325        if (!strcmp (key, "keygen.valid")) {
326            sprintf (buf, "%d", ctx->getValidDays ());
327            return buf;
328        }
329        if (!strcmp (key, "keyedit.prompt")) {
330            ctx->reset ();
331            return "save";
332        }
333        return NULL;
334    }
335    
336    
337  /* 'addkey' command handler. */  /* 'addkey' command handler. */
338  static const char*  static const char*
339  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)
340  {  {
341      static char buf[64];      static char buf[64];
342    
# Line 273  cmd_addkey_handler (GpgKeyEdit *ctx, gpg Line 348  cmd_addkey_handler (GpgKeyEdit *ctx, gpg
348      if (!strcmp (key, "passphrase.enter"))      if (!strcmp (key, "passphrase.enter"))
349          return ctx->pass;          return ctx->pass;
350      if (!strcmp (key, "keygen.algo")) {      if (!strcmp (key, "keygen.algo")) {
351          _snprintf (buf, sizeof buf-1, "%d", ctx->pubkey_algo);          _snprintf (buf, sizeof (buf)-1, "%d", ctx->pubkey_algo);
352          return buf;          return buf;
353      }        }  
354      if (!strcmp (key, "keygen.size")) {      if (!strcmp (key, "keygen.size")) {
355          _snprintf (buf, sizeof buf-1, "%d", ctx->pubkey_size);          _snprintf (buf, sizeof (buf)-1, "%d", ctx->pubkey_size);
356          return buf;          return buf;
357      }      }
358      if (!strcmp (key, "keygen.valid")) {      if (!strcmp (key, "keygen.valid")) {
359          _snprintf (buf, sizeof buf-1, "%d", ctx->valid);          _snprintf (buf, sizeof (buf)-1, "%d", ctx->getValidDays ());
360          return buf;                  return buf;        
361      }      }
362      if (!strcmp (key, "keyedit.prompt")) {      if (!strcmp (key, "keyedit.prompt")) {
# Line 291  cmd_addkey_handler (GpgKeyEdit *ctx, gpg Line 366  cmd_addkey_handler (GpgKeyEdit *ctx, gpg
366      return NULL;      return NULL;
367  }  }
368    
369    
370  /* 'passwd' command handler. */  /* 'passwd' command handler. */
371  static const char*  static const char*
372  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)
# Line 299  cmd_passwd_handler (GpgKeyEdit *ctx, gpg Line 375  cmd_passwd_handler (GpgKeyEdit *ctx, gpg
375          ctx->cmd_sent = 1;          ctx->cmd_sent = 1;
376          return "passwd";          return "passwd";
377      }      }
378      if( !strcmp (key, "passphrase.enter") && !ctx->cnt) {      if (ctx->cnt == 0 && !strcmp (key, "passphrase.enter")) {
379          ctx->cnt = 1;          ctx->cnt = 1;
380            /* it is possible that there is no old passphrase. */
381            if (!ctx->pass && ctx->flags)
382                return "";
383          return ctx->pass;          return ctx->pass;
384      }      }
385      if( !strcmp (key, "passphrase.enter" ))      if (!strcmp (key, "passphrase.enter" ))
386          return ctx->new_pass;          return ctx->new_pass;
387      if( !strcmp (key, "change_passwd.empty.okay" ))      if (!strcmp (key, "change_passwd.empty.okay" ))
388          return ctx->flags?  "Y" : "N";          return ctx->flags?  "Y" : "N";
389      if (!strcmp (key, "keyedit.prompt")) {      if (!strcmp (key, "keyedit.prompt")) {
390          ctx->reset ();          ctx->reset ();
391          return "save";          return "save";
392      }      }
393    
394      return NULL;      return NULL;
395  }  }
396    
397    
398  static const char*  static const char*
399  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)
400  {  {
401      /* XXX: check the code. */      static char buf[128] = {0};
402  #if 0  
403      static char buf[128];      if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) {
404      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {          _snprintf (buf, sizeof (buf)-1, "uid %d", ctx->getUseridIndex ());
405          ctx->cmd_sent = 1;          ctx->cmd_sent = 1;
406          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);  
407          return buf;          return buf;
408      }      }
409      if (!strcmp ( key, "keyedit.prompt") && ctx->u.pref.id == 1) {      if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 1) {
410          ctx->u.pref.id++;          _snprintf (buf, sizeof buf-1, "setpref %s", ctx->new_prefs);
411          return "updpref";          ctx->cnt = 2;
412            return buf;
413      }      }
414      if (!strcmp ( key, "keyedit.updpref.okay"))      if (!strcmp (key, "keyedit.setpref.okay"))
415          return "Y";          return "Y";
416      if (!strcmp (key, "passphrase.enter"))      if (!strcmp (key, "passphrase.enter"))
417          return ctx->u.pref.passwd;          return ctx->pass;
418      if (!strcmp (key, "keyedit.prompt") && ctx->u.pref.id == 2) {      if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 2) {
         ctx->u.pref.id = 0;  
419          ctx->reset ();          ctx->reset ();
420          return "save";          return "save";
421      }      }
422  #endif      return buf;
     return NULL;  
423  }  }
424    
425    
426  /* 'primary' command handler. */  /* 'primary' command handler. */
427  static const char*  static const char*
428  cmd_primary_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,  cmd_primary_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
429                       const char *key, int *r_step )                       const char *key)
430  {  {
431      static char buf[64];      static char buf[64];
432      int step = *r_step;      
433        if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
434      if (step == 0 && !strcmp (key, "keyedit.prompt")) {          sprintf (buf, "uid %d", ctx->getUseridIndex ());
435          sprintf (buf, "uid %d", ctx->uid_index);          ctx->cnt = 1;
         *r_step = step = 1;  
436          return buf;          return buf;
437      }      }
438      if (step == 1 && !strcmp (key, "keyedit.prompt" )) {      if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt" )) {
439          *r_step = step = 2;          ctx->cnt = 2;
440          return "primary";          return "primary";
441      }      }
442      if (step == 2 && !strcmp (key, "passphrase.enter")) {      if (ctx->cnt == 2 && !strcmp (key, "passphrase.enter")) {
443          *r_step = step = 3;          ctx->cnt = 3;
444          return ctx->pass;          return ctx->pass;
445      }      }
446      if (step == 3 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 3 && !strcmp (key, "keyedit.prompt")) {
         *r_step = step = 0;  
447          ctx->reset ();          ctx->reset ();
448          return "save";          return "save";
449      }      }
450      return NULL;      return NULL;
451  }  }
452    
453    
454  /* 'expire' command handler. */  /* 'expire' command handler. */
455  static const char*  static const char*
456  cmd_expire_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,  cmd_expire_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
457                      const char *key, int *r_step )                      const char *key)
458  {  {
459      static char buf[64];      static char buf[64];
     int step = *r_step;  
460    
461      if (step == 0 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
462          sprintf (buf, "key %d", ctx->key_index);          sprintf (buf, "key %d", ctx->getKeyIndex ());
463          *r_step = step = 1;          ctx->cnt = 1;
464          return buf;          return buf;
465      }      }
466      if (step == 1 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) {
467          *r_step = step = 2;          ctx->cnt = 2;
468          return "expire";          return "expire";
469      }      }
470      if( step == 2 && !strcmp ( key, "keygen.valid" ) ) {      if (ctx->cnt == 2 && !strcmp (key, "keygen.valid" )) {
471          *r_step = step = 3;          ctx->cnt = 3;
472          sprintf (buf, "%d", ctx->valid);          sprintf (buf, "%d", ctx->getValidDays ());
473          return buf;          return buf;
474      }      }
475      if (step == 3 && !strcmp (key, "passphrase.enter")) {      if (ctx->cnt == 3 && !strcmp (key, "passphrase.enter")) {
476          *r_step = step = 4;          ctx->cnt = 4;
477          return ctx->pass;          return ctx->pass;
478      }      }
479      if (step == 4 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 4 && !strcmp (key, "keyedit.prompt")) {
         *r_step = step = 0;  
480          ctx->reset ();          ctx->reset ();
481          return "save";          return "save";
482      }      }
# Line 416  cmd_expire_handler (GpgKeyEdit *ctx, gpg Line 488  cmd_expire_handler (GpgKeyEdit *ctx, gpg
488  /* 'revuid' command handler. */  /* 'revuid' command handler. */
489  const char*  const char*
490  cmd_revuid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,  cmd_revuid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
491                      const char *key, int *r_step)                      const char *key)
492  {  {
493      static char buf[32];      static char buf[32];
     int step = *r_step;  
494            
495      if (step == 0 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
496          *r_step = step = 1;          ctx->cnt = 1;
497          sprintf (buf, "uid %d", ctx->uid_index);          sprintf (buf, "uid %d", ctx->getUseridIndex ());
498          return buf;          return buf;
499      }      }
500      else if (step == 1 && !strcmp (key, "keyedit.prompt")) {      else if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) {
501          *r_step = step = 2;          ctx->cnt = 2;
502          return "revuid";          return "revuid";
503      }      }
504      else if (step == 2 && !strcmp (key, "keyedit.revoke.uid.okay")) {      else if (ctx->cnt == 2 && !strcmp (key, "keyedit.revoke.uid.okay")) {
505          *r_step = step = 3;          ctx->cnt = 3;
506          return "Y";          return "Y";
507      }      }
508      else if (step == 3 && !strcmp (key, "ask_revocation_reason.code")) {      else if (ctx->cnt == 3 && !strcmp (key, "ask_revocation_reason.code")) {
509          *r_step = step = 4;          ctx->cnt = 4;
510          return "4";          return "4";
511      }      }
512      else if (step == 4 && !strcmp (key, "ask_revocation_reason.text")) {      else if (ctx->cnt == 4 && !strcmp (key, "ask_revocation_reason.text")) {
513          *r_step = step = 5;          ctx->cnt = 5;
514          return "";          return "";
515      }      }
516      else if (step == 5 && !strcmp (key, "ask_revocation_reason.okay")) {      else if (ctx->cnt == 5 && !strcmp (key, "ask_revocation_reason.okay")) {
517          *r_step = step = 6;          ctx->cnt = 6;
518          return "Y";          return "Y";
519      }      }
520      else if (step == 6 && !strcmp (key, "passphrase.enter")) {      else if (ctx->cnt == 6 && !strcmp (key, "passphrase.enter")) {
521          *r_step = step = 7;          ctx->cnt = 7;
522          return ctx->pass;          return ctx->pass;
523      }      }
524      else if (step == 7 && !strcmp (key, "keyedit.prompt")) {      else if (ctx->cnt == 7 && !strcmp (key, "keyedit.prompt")) {
         *r_step = step = 0;  
525          ctx->reset ();          ctx->reset ();
526          return "save";          return "save";
527      }      }
# Line 461  cmd_revuid_handler (GpgKeyEdit *ctx, gpg Line 531  cmd_revuid_handler (GpgKeyEdit *ctx, gpg
531    
532  const char*  const char*
533  cmd_revsig_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,  cmd_revsig_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
534                      const char *key, int *r_step)                      const char *key)
535  {  {
536      static char buf[64];      static char buf[64];
     int step = *r_step;  
537            
538      if( step == 0 && !strcmp ( key, "keyedit.prompt" ) ) {      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt" )) {
539          sprintf( buf, "uid %d", ctx->uid_index);          sprintf( buf, "uid %d", ctx->getUseridIndex ());
540          *r_step = step = 1;          ctx->cnt = 1;
541          return buf;          return buf;
542      }      }
543      if( step == 1 && !strcmp ( key, "keyedit.prompt" ) ) {      if (ctx->cnt == 1 && !strcmp ( key, "keyedit.prompt" ) ) {
544          *r_step = step = 2;          ctx->cnt = 2;
545          return "revsig";          return "revsig";
546      }      }
547      if( step == 2 && !strcmp (key, "ask_revoke_sig.one" ) ) {      if (ctx->cnt == 2 && !strcmp (key, "ask_revoke_sig.one" ) ) {
548          *r_step = step = 3;          ctx->cnt = 3;
549          return "Y";          return "Y";
550      }      }
551      if( step == 3 && !strcmp (key, "ask_revoke_sig.okay" ) ) {      if (ctx->cnt == 3 && !strcmp (key, "ask_revoke_sig.okay" ) ) {
552          *r_step = step = 4;          ctx->cnt = 4;
553          return "Y";          return "Y";
554      }      }
555      if( step == 4 && !strcmp ( key, "ask_revocation_reason.code" ) ) {      if (ctx->cnt == 4 && !strcmp ( key, "ask_revocation_reason.code" ) ) {
556          *r_step = step = 5;          ctx->cnt = 5;
557          return "0";          return "0";
558      }      }
559      if( step == 5 && !strcmp ( key, "ask_revocation_reason.text" ) ) {      if (ctx->cnt == 5 && !strcmp ( key, "ask_revocation_reason.text" ) ) {
560          *r_step = step = 6;          ctx->cnt = 6;
561          return "";          return "";
562      }      }
563      if( step == 6 && !strcmp (key, "ask_revocation_reason.okay" ) ) {      if (ctx->cnt == 6 && !strcmp (key, "ask_revocation_reason.okay" ) ) {
564          *r_step = step = 7;          ctx->cnt = 7;
565          return "Y";          return "Y";
566      }      }
567      if( step == 7 && !strcmp (key, "passphrase.enter" ) ) {      if (ctx->cnt == 7 && !strcmp (key, "passphrase.enter" ) ) {
568          *r_step = step = 8;          ctx->cnt = 8;
569          return ctx->pass;          return ctx->pass;
570      }      }
571      if( step == 8 && !strcmp ( key, "keyedit.prompt" ) ) {      if (ctx->cnt == 8 && !strcmp ( key, "keyedit.prompt" ) ) {
         *r_step = step = 0;  
572          ctx->reset ();          ctx->reset ();
573          return "save";          return "save";
574      }      }
# Line 512  cmd_revsig_handler (GpgKeyEdit *ctx, gpg Line 580  cmd_revsig_handler (GpgKeyEdit *ctx, gpg
580  /* 'revoke' command handler. */  /* 'revoke' command handler. */
581  static const char *  static const char *
582  cmd_revkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,  cmd_revkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
583                      const char * key, int *r_step)                      const char *key)
584  {  {
     int step = *r_step;  
585      static char buf[64];      static char buf[64];
586    
587      if( step == 0 && !strcmp ( key, "keyedit.prompt" ) ) {      if (ctx->cnt == 0 && !strcmp ( key, "keyedit.prompt" ) ) {
588          sprintf( buf, "key %d", ctx->key_index);          sprintf( buf, "key %d", ctx->getKeyIndex ());
589          *r_step = step = 1;          ctx->cnt = 1;
590          return buf;          return buf;
591      }      }
592      if( step == 1 && !strcmp ( key, "keyedit.prompt" ) ) {      if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) {
593          *r_step = step = 2;          ctx->cnt = 2;
594          return "revkey";          return "revkey";
595      }      }
596      if( step == 2 && !strcmp (key, "keyedit.revoke.subkey.okay" ) ) {      if (ctx->cnt == 2 && !strcmp (key, "keyedit.revoke.subkey.okay")) {
597          *r_step = step = 3;          ctx->cnt = 3;
598          return "Y";          return "Y";
599      }      }
600      if( step == 3 &&  !strcmp ( key, "ask_revocation_reason.code" ) ) {      if (ctx->cnt == 3 &&  !strcmp ( key, "ask_revocation_reason.code")) {
601          sprintf( buf, "%d", ctx->reason);          sprintf( buf, "%d", ctx->reason);
602          *r_step = step = 4;          ctx->cnt = 4;
603          return buf;          return buf;
604      }      }
605      if( step == 4 && !strcmp ( key, "ask_revocation_reason.text" ) ) {      if (ctx->cnt == 4 && !strcmp (key, "ask_revocation_reason.text")) {
606          *r_step = step = 5;          ctx->cnt = 5;
607          return "";          return "";
608      }      }
609      if( step == 5 && !strcmp (key, "ask_revocation_reason.okay" ) ) {      if (ctx->cnt == 5 && !strcmp (key, "ask_revocation_reason.okay")) {
610          *r_step = step = 6;          ctx->cnt = 6;
611          return "Y";          return "Y";
612      }      }
613      if( step == 6 && !strcmp (key, "passphrase.enter" ) ) {      if (ctx->cnt == 6 && !strcmp (key, "passphrase.enter")) {
614          *r_step = step = 7;          ctx->cnt = 7;
615          return ctx->pass;          return ctx->pass;
616      }      }
617      if( step == 7 && !strcmp ( key, "keyedit.prompt" ) ) {      if (ctx->cnt == 7 && !strcmp ( key, "keyedit.prompt")) {
         *r_step = step = 0;  
618          ctx->reset ();          ctx->reset ();
619          return "save";          return "save";
620      }      }
# Line 559  cmd_revkey_handler (GpgKeyEdit *ctx, gpg Line 625  cmd_revkey_handler (GpgKeyEdit *ctx, gpg
625  /* 'addrevoker' command handler. */  /* 'addrevoker' command handler. */
626  static const char *  static const char *
627  cmd_addrev_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,  cmd_addrev_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
628                      const char * key, int * r_step)                      const char *key)
629  {  {
     int step = *r_step;  
630    
631      /* If the isuser already signed the key, send an empty      /* If the isuser already signed the key, send an empty
632         string and jump to quit. */             string and jump to quit. */
633      if (ctx->getResult () & GPG_EDITRES_ALREADY_SIGNED      if (ctx->getResult () & EDITKEY_ERR_ALREADY_SIGNED
634          && *r_step != -1 && *r_step != 4) {          && ctx->cnt != -1 && ctx->cnt != 4) {
635          *r_step = step = -1;          ctx->cnt = -1;
636          return "";          return "";
637      }      }
638      if (*r_step == -1) {      if (ctx->cnt == -1) {
639          *r_step = step = 4;          ctx->cnt = 4;
640          return ""; /* empty value to abort. */          return ""; /* empty value to abort. */
641      }      }
642      if (step == 0 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
643          *r_step = step = 1;          ctx->cnt = 1;
644          return "addrevoker";          return "addrevoker";
645      }      }
646      if (step == 1 && !strcmp (key, "keyedit.add_revoker")) {      if (ctx->cnt == 1 && !strcmp (key, "keyedit.add_revoker")) {
647          *r_step = step = 2;          ctx->cnt = 2;
648          return ctx->name;          return ctx->name;
649      }      }
650      if (step == 2 && !strcmp (key, "keyedit.add_revoker.okay")) {      if (ctx->cnt == 2 && !strcmp (key, "keyedit.add_revoker.okay")) {
651          *r_step = step = 3;          ctx->cnt = 3;
652          return "Y";          return "Y";
653      }      }
654      if (step == 3 && !strcmp (key, "passphrase.enter")) {      if (ctx->cnt == 3 && !strcmp (key, "passphrase.enter")) {
655          *r_step = step = 4;          ctx->cnt = 4;
656          return ctx->pass;          return ctx->pass;
657      }      }
658      if (step == 4 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 4 && !strcmp (key, "keyedit.prompt")) {
         *r_step = step = 0;  
659          ctx->reset ();          ctx->reset ();
660          return "save";          return "save";
661      }      }
# Line 621  cmd_addphoto_handler (GpgKeyEdit *ctx, g Line 685  cmd_addphoto_handler (GpgKeyEdit *ctx, g
685      return NULL;      return NULL;
686  }  }
687    
688    
689    static const char*
690    cmd_minimize_handler (GpgKeyEdit *ctx, status_code_t code, const char *key)
691    {
692        if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) {
693            ctx->cmd_sent = 1;
694            return "minimize";
695        }
696        if (!strcmp (key, "keyedit.prompt")) {
697            ctx->reset ();
698            return "save";
699        }
700    
701        return NULL;
702    }
703    
704    /* 'clean' command handler. */
705    static const char*
706    cmd_clean_handler (GpgKeyEdit *ctx, status_code_t code, const char *key)
707    {
708        if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) {
709            ctx->cmd_sent = 1;
710            return "clean";
711        }
712        if (!strcmp (key, "keyedit.prompt")) {
713            ctx->reset ();
714            return "save";
715        }
716        return NULL;
717    }
718    
719    
720  /* 'enable' and 'disable' command handler. */  /* 'enable' and 'disable' command handler. */
721  static const char *  static const char *
722  cmd_enable_disable_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,  cmd_enable_disable_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
# Line 628  cmd_enable_disable_handler (GpgKeyEdit * Line 724  cmd_enable_disable_handler (GpgKeyEdit *
724  {  {
725      if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) {      if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) {
726          ctx->cmd_sent = 1;          ctx->cmd_sent = 1;
727          if (mode)          return mode? "disable": "enable";
             return "disable";  
         return "enable";  
728      }      }
729      if (!strcmp (key, "keyedit.prompt")) {      if (!strcmp (key, "keyedit.prompt")) {
730          ctx->reset ();          ctx->reset ();
# Line 645  static gpgme_error_t Line 739  static gpgme_error_t
739  editkey_command_handler (void *opaque, gpgme_status_code_t code,  editkey_command_handler (void *opaque, gpgme_status_code_t code,
740                           const char *key, int fd)                           const char *key, int fd)
741  {  {
     static int step = 0;  
742      const char *out = NULL;      const char *out = NULL;
743      GpgKeyEdit *ke = (GpgKeyEdit *)opaque;      GpgKeyEdit *ke = (GpgKeyEdit *)opaque;
744      HANDLE hd = (HANDLE)fd;      HANDLE hd = (HANDLE)fd;
# Line 657  editkey_command_handler (void *opaque, g Line 750  editkey_command_handler (void *opaque, g
750      /*log_debug ("key=%s code=%d\r\n", key, code);*/      /*log_debug ("key=%s code=%d\r\n", key, code);*/
751      switch (code) {      switch (code) {
752      case GPGME_STATUS_ALREADY_SIGNED:      case GPGME_STATUS_ALREADY_SIGNED:
753          ke->setResult (GPG_EDITRES_ALREADY_SIGNED);          ke->setResult (EDITKEY_ERR_ALREADY_SIGNED);
754          break;          break;
755    
756      case GPGME_STATUS_BAD_PASSPHRASE:      case GPGME_STATUS_BAD_PASSPHRASE:
757          ke->setResult (GPG_EDITRES_BAD_PASSPHRASE);          log_debug ("editkey_command_handler: bad passphrase\n");
758            ke->setResult (EDITKEY_ERR_BAD_PASSPHRASE);
759          break;          break;
760            
761      default:      default:
762          break;          break;
763      }      }
764    
765      if (ke->getResult () & GPG_EDITRES_BAD_PASSPHRASE) {      if (ke->getResult () & EDITKEY_ERR_BAD_PASSPHRASE) {
766          /* If the entered passphrase is bad, we supply empty          /* If the entered passphrase is bad, we supply empty
767             passphrase to abort and send 'quit' as soon as possible. */             passphrase to abort and send 'quit' as soon as possible. */
768          if (!strcmp (key, "passphrase.enter"))          if (!strcmp (key, "passphrase.enter"))
769              WriteFile (hd, "\n", 1, &n, NULL);              WriteFile (hd, "\n", 1, &n, NULL);
770          if (!strcmp (key, "keyedit.prompt"))          if (!strcmp (key, "keyedit.prompt"))
771              WriteFile (hd, "quit\n", 5, &n, NULL);              WriteFile (hd, "quit\n", 5, &n, NULL);
772            ke->reset ();
773            return 0;
774      }      }
775            
776      switch (ke->getType ()) {      switch (ke->getType ()) {
# Line 694  editkey_command_handler (void *opaque, g Line 791  editkey_command_handler (void *opaque, g
791          break;          break;
792                    
793      case GPG_EDITKEY_DELUID:      case GPG_EDITKEY_DELUID:
794          out =  cmd_deluid_handler (ke, code, key, &step);          out =  cmd_deluid_handler (ke, code, key);
795          break;          break;
796                    
797      case GPG_EDITKEY_DELSIG:      case GPG_EDITKEY_DELSIG:
798          out =  cmd_delsig_handler (ke, code, key, &step);          out = cmd_delsig_handler (ke, code, key);
799          break;          break;
800    
801      case GPG_EDITKEY_DELKEY:      case GPG_EDITKEY_DELKEY:
802          out =  cmd_delkey_handler(ke, code, key, &step );          out =  cmd_delkey_handler(ke, code, key);
803          break;          break;
804                    
805      case GPG_EDITKEY_ADDKEY:      case GPG_EDITKEY_ADDKEY:
806          out =  cmd_addkey_handler (ke, code, key);          out = cmd_addkey_handler (ke, code, key);
807            break;
808    
809        case GPG_EDITKEY_ADDCARDKEY:
810            out = cmd_addcardkey_handler (ke, code, key);
811          break;          break;
812                    
813      case GPG_EDITKEY_PASSWD:      case GPG_EDITKEY_PASSWD:
# Line 714  editkey_command_handler (void *opaque, g Line 815  editkey_command_handler (void *opaque, g
815          break;          break;
816                    
817      case GPG_EDITKEY_PRIMARY:      case GPG_EDITKEY_PRIMARY:
818          out =  cmd_primary_handler (ke, code, key, &step);          out =  cmd_primary_handler (ke, code, key);
819          break;          break;
820                    
821      case GPG_EDITKEY_EXPIRE:      case GPG_EDITKEY_EXPIRE:
822          out =  cmd_expire_handler (ke, code, key, &step);          out =  cmd_expire_handler (ke, code, key);
823          break;          break;
824    
825      case GPG_EDITKEY_REVSIG:      case GPG_EDITKEY_REVSIG:
826          out =  cmd_revsig_handler (ke, code, key, &step);          out =  cmd_revsig_handler (ke, code, key);
827          break;          break;
828    
829      case GPG_EDITKEY_REVKEY:      case GPG_EDITKEY_REVKEY:
830          out =  cmd_revkey_handler (ke, code, key, &step);          out =  cmd_revkey_handler (ke, code, key);
831          break;          break;
832                            
833      case GPG_EDITKEY_REVUID:      case GPG_EDITKEY_REVUID:
834          out = cmd_revuid_handler (ke, code, key, &step);          out = cmd_revuid_handler (ke, code, key);
835          break;          break;
836    
837      case GPG_EDITKEY_ADDREV:      case GPG_EDITKEY_ADDREV:
838          out =  cmd_addrev_handler (ke, code, key, &step);          out =  cmd_addrev_handler (ke, code, key);
839          break;          break;
840    
841      case GPG_EDITKEY_ADDPHOTO:      case GPG_EDITKEY_ADDPHOTO:
842          out =  cmd_addphoto_handler (ke, code, key);          out =  cmd_addphoto_handler (ke, code, key);
843          break;          break;
844    
845        case GPG_EDITKEY_NOTATION:
846            out = cmd_notation_handler (ke, code, key);
847            break;
848    
849        case GPG_EDITKEY_MINIMIZE:
850            out = cmd_minimize_handler (ke, code, key);
851            break;
852    
853        case GPG_EDITKEY_CLEAN:
854            out = cmd_clean_handler (ke, code, key);
855            break;
856    
857      case GPG_EDITKEY_ENABLE:      case GPG_EDITKEY_ENABLE:
858      case GPG_EDITKEY_DISABLE:      case GPG_EDITKEY_DISABLE:
859          out = cmd_enable_disable_handler (ke, code, key,          n = ke->getType () == GPG_EDITKEY_DISABLE? 1: 0;
860                                            ke->getType () == GPG_EDITKEY_DISABLE? 1: 0);          out = cmd_enable_disable_handler (ke, code, key, n);
861          break;          break;
862    
863      case GPG_EDITKEY_SETPREF:      case GPG_EDITKEY_SETPREF:
# Line 757  editkey_command_handler (void *opaque, g Line 870  editkey_command_handler (void *opaque, g
870      }      }
871    
872      if (out != NULL) {      if (out != NULL) {
         /* XXX: check return codes. */  
873          WriteFile (hd, out, strlen (out), &n, NULL);          WriteFile (hd, out, strlen (out), &n, NULL);
874          WriteFile (hd, "\n", 1, &n, NULL);          WriteFile (hd, "\n", 1, &n, NULL);
875      }      }
# Line 774  map_result (GpgKeyEdit *ke) Line 886  map_result (GpgKeyEdit *ke)
886      /* XXX Sometimes ALREADY_SIGNED indicates an failure. */      /* XXX Sometimes ALREADY_SIGNED indicates an failure. */
887      if (!ke->getResult ())      if (!ke->getResult ())
888          return gpg_error (GPG_ERR_NO_ERROR);          return gpg_error (GPG_ERR_NO_ERROR);
889      if (ke->getResult () & GPG_EDITRES_BAD_PASSPHRASE)      if (ke->getResult () & EDITKEY_ERR_BAD_PASSPHRASE)
890          return gpg_error (GPG_ERR_BAD_PASSPHRASE);          return gpg_error (GPG_ERR_BAD_PASSPHRASE);
891      return 0;      return 0;
892  }  }

Legend:
Removed from v.101  
changed lines
  Added in v.260

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26