/[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 28 by twoaday, Thu Oct 20 12:35:59 2005 UTC revision 207 by twoaday, Fri Apr 28 10:28:24 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.
6   *   *
7   * WinPT is free software; you can redistribute it and/or   * WinPT is free software; you can redistribute it and/or
8   * modify it under the terms of the GNU General Public License   * modify it under the terms of the GNU General Public License
9   * as published by the Free Software Foundation; either version 2   * as published by the Free Software Foundation; either version 2
10   * of the License, or (at your option) any later version.   * of the License, or (at your option) any later version.
11   *     *  
12   * WinPT is distributed in the hope that it will be useful,   * WinPT is distributed in the hope that it will be useful,
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.
16   *   *
17   * You should have received a copy of the GNU General Public License   * You should have received a copy of the GNU General Public License
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  #include <stdio.h>  
22  #include <string.h>  #ifdef HAVE_CONFIG_H
23  #include <stdlib.h>  #include <config.h>
24  #include <assert.h>  #endif
25  #include <windows.h>  
26    #include <stdio.h>
27  #include "gpgme.h"  #include <string.h>
28  #include "wptCommonCtl.h"  #include <stdlib.h>
29  #include "wptContext.h"  #include <assert.h>
30  #include "wptKeyEdit.h"  #include <windows.h>
31  #include "wptErrors.h"  
32    #include "gpgme.h"
33    #include "wptCommonCtl.h"
34  /* 'keyserver' command handler. */  #include "wptContext.h"
35  static const char*  #include "wptKeyEdit.h"
36  cmd_keyserv_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)  #include "wptErrors.h"
37  {  
38      static char buf[32];  /* Possible errors for the edit key operation. */
39    enum editkey_error_t {
40      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {      EDITKEY_ERR_ALREADY_SIGNED = 1,
41          ctx->cmd_sent = 1;      EDITKEY_ERR_BAD_PASSPHRASE = 2
42          sprintf (buf, "uid %d", ctx->uid_index);  };
43          return buf;  
44      }  typedef gpgme_status_code_t status_code_t;
45      if (!strcmp (key, "keyedit.prompt") && !ctx->cnt) {  
46          ctx->cnt = 1;  /* 'notation' command handler. */
47          return "keyserver";  static const char*
48      }  cmd_notation_handler (GpgKeyEdit *ctx, status_code_t code, const char *key)
49      if (!strcmp (key, "keyedit.add_keyserver"))  {
50          return ctx->url;      static char buf[32];
51      if ( !strcmp (key, "keyedit.confirm_keyserver"))  
52          return "Y";      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {
53      if (!strcmp (key, "passphrase.enter"))          int uid = ctx->getUseridIndex ();
54          return ctx->pass;          ctx->cmd_sent = 1;
55      if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 1) {          if (uid != -1) {
56          ctx->reset ();              sprintf (buf, "uid %d", ctx->getUseridIndex ());
57          return "save";              return buf;
58      }          }
59        }
60      return NULL;      if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 0) {
61  }          ctx->cnt = 1;
62            return "notation";
63        }
64  static const char*      if (!strcmp (key, "keyedit.add_notation"))
65  cmd_sign_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)          return ctx->notation;
66  {      if (!strcmp (key, "passphrase.enter"))
67      static char buf[32];          return ctx->pass;
68    
69      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {      return NULL;
70          ctx->cmd_sent = 1;  }
71          switch (ctx->getType ()) {  
72          case GPG_EDITKEY_SIGN: return "sign";  
73          case GPG_EDITKEY_TSIGN: return "tsign";  /* 'keyserver' command handler. */
74          case GPG_EDITKEY_LSIGN: return "lsign";  static const char*
75          case GPG_EDITKEY_NRSIGN: return"nrsign";  cmd_keyserv_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)
76          case GPG_EDITKEY_NRLSIGN: return "nrlsign";  {
77          }      static char buf[32];
78      }  
79      if (!strcmp (key, "sign_uid.class")) {      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {
80          sprintf (buf, "%d", ctx->sig_class);          int uid = ctx->getUseridIndex ();
81          return buf;          ctx->cmd_sent = 1;
82      }          if (uid != -1) {
83      if (!strcmp (key, "sign_uid.expire"))              sprintf (buf, "uid %d", ctx->getUseridIndex ());
84          return "Y"; /* the sig expires when the key expires */              return buf;
85      if (!strcmp (key, "siggen.valid"))          }
86          return ctx->exp_date;      }
87      if (!strcmp (key, "trustsig_prompt.trust_value")) {      if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 0) {
88          sprintf (buf, "%d", ctx->trust_id);          ctx->cnt = 1;
89          return buf;          return "keyserver";
90      }      }
91      if (!strcmp (key, "trustsig_prompt.trust_depth"))      if (!strcmp (key, "keyedit.add_keyserver"))
92          return ""; /* fixme */          return ctx->url;
93      if (!strcmp (key, "trustsig_prompt.trust_regexp"))      if (!strcmp (key, "keyedit.confirm_keyserver"))
94          return ""; /* fixme */          return "Y";
95      if (!strcmp (key, "sign_uid.local_promote_okay" ) )      if (!strcmp (key, "passphrase.enter"))
96          return "Y";          return ctx->pass;
97      if (!strcmp (key, "sign_uid.okay" ) )      if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 1) {
98          return "Y";          ctx->reset ();
99      if (!strcmp (key, "keyedit.sign_all.okay"))          return "save";
100          return "Y";      }
101      if (!strcmp ( key, "passphrase.enter"))  
102          return ctx->pass;      return NULL;
103      if (!strcmp (key, "keyedit.prompt")) {  }
104          ctx->reset ();  
105          return "save";  
106      }  /* 'sign' command handler. */
107        static const char*
108      return NULL;  cmd_sign_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)
109  }  {
110        static char buf[32];
111  /* 'trust' command handler. */  
112  static const char*      if (ctx->getUseridIndex () != -1 &&
113  cmd_trust_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)          ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
114  {          ctx->cnt++;
115      static char buf[4];          sprintf (buf, "uid %d", ctx->getUseridIndex ());
116            return buf;
117      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {      }
118          ctx->cmd_sent = 1;  
119          return "trust";      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {
120      }          ctx->cmd_sent = 1;
121      if (!strcmp (key, "edit_ownertrust.set_ultimate.okay"))          switch (ctx->getType ()) {
122          return "Y";          case GPG_EDITKEY_SIGN:      return "sign";
123      if (!strcmp (key, "edit_ownertrust.value" )) {          case GPG_EDITKEY_TSIGN:     return "tsign";
124          sprintf (buf, "%d", ctx->trust_id);          case GPG_EDITKEY_LSIGN:     return "lsign";
125          return buf;          case GPG_EDITKEY_NRSIGN:    return"nrsign";
126      }          case GPG_EDITKEY_NRLSIGN:   return "nrlsign";
127      if (!strcmp (key, "keyedit.prompt")) {          }
128          ctx->reset ();      }
129          return "save";      if (!strcmp (key, "sign_uid.class")) {
130      }          sprintf (buf, "%d", ctx->sig_class);
131            return buf;
132      return NULL;      }
133  }      if (!strcmp (key, "sign_uid.expire"))
134            return "Y"; /* the sig expires when the key expires */
135        if (!strcmp (key, "siggen.valid"))
136  /* 'adduid' command handler. */          return ctx->exp_date;
137  static const char*      if (!strcmp (key, "trustsig_prompt.trust_value")) {
138  cmd_adduid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)          sprintf (buf, "%d", ctx->trust_id);
139  {          return buf;
140      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {      }
141          ctx->cmd_sent = 1;      if (!strcmp (key, "trustsig_prompt.trust_depth"))
142          return "adduid";          return ""; /* fixme */
143      }      if (!strcmp (key, "trustsig_prompt.trust_regexp"))
144      if (!strcmp (key, "keygen.name"))          return ""; /* fixme */
145          return ctx->name;      if (!strcmp (key, "sign_uid.local_promote_okay" ) )
146      if (!strcmp (key, "keygen.email"))          return "Y";
147          return ctx->email;      if (!strcmp (key, "sign_uid.okay" ) )
148      if (!strcmp (key, "keygen.comment"))          return "Y";
149          return ctx->cmt? ctx->cmt : "";      if (!strcmp (key, "keyedit.sign_all.okay"))
150      if (!strcmp (key, "passphrase.enter"))          return "Y";
151          return ctx->pass;      if (!strcmp ( key, "passphrase.enter"))
152      if( !strcmp (key, "keyedit.prompt")) {          return ctx->pass;
153          ctx->reset ();      if (!strcmp (key, "keyedit.prompt")) {
154          return "save";          ctx->reset ();
155      }          return "save";
156        }
157      return NULL;      
158  }      return NULL;
159    }
160    
161  static const char*  /* 'trust' command handler. */
162  cmd_deluid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key,  static const char*
163                      int *r_step)  cmd_trust_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)
164  {  {
165      static char buf[64];      static char buf[4];
166      int step = *r_step;  
167        if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {
168      if (step == 0 && !strcmp (key, "keyedit.prompt")) {          ctx->cmd_sent = 1;
169          sprintf (buf, "uid %d", ctx->uid_index);          return "trust";
170          *r_step = step = 1;      }
171          return buf;      if (!strcmp (key, "edit_ownertrust.set_ultimate.okay"))
172      }          return "Y";
173      if (step == 1 && !strcmp (key, "keyedit.prompt")) {      if (!strcmp (key, "edit_ownertrust.value" )) {
174          *r_step = step = 2;          sprintf (buf, "%d", ctx->trust_id);
175          return "deluid";          return buf;
176      }      }
177      if (step == 2 && !strcmp (key, "keyedit.remove.uid.okay")) {      if (!strcmp (key, "keyedit.prompt")) {
178          *r_step = step = 3;          ctx->reset ();
179          return "Y";          return "save";
180      }      }
181      if (step == 3 && !strcmp (key, "keyedit.prompt" )) {  
182          *r_step = step = 0;      return NULL;
183          ctx->reset ();  }
184          return "save";  
185      }  
186        /* 'adduid' command handler. */
187      return NULL;  static const char*
188  }  cmd_adduid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)
189    {
190        if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {
191  static const char *          ctx->cmd_sent = 1;
192  cmd_delsig_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char * key,          return "adduid";
193                      int * r_step)      }
194  {      if (!strcmp (key, "keygen.name"))
195      static char buf[64];          return ctx->name;
196      int step = *r_step;      if (!strcmp (key, "keygen.email"))
197            return ctx->email;
198      if (step == 0 && !strcmp (key, "keyedit.prompt")) {      if (!strcmp (key, "keygen.comment"))
199          sprintf (buf, "uid %d", ctx->uid_index);          return ctx->cmt? ctx->cmt : "";
200          *r_step = step = 1;      if (!strcmp (key, "passphrase.enter"))
201          return buf;          return ctx->pass;
202      }      if( !strcmp (key, "keyedit.prompt")) {
203      if (step == 1 && !strcmp (key, "keyedit.prompt")) {          ctx->reset ();
204          *r_step = step = 2;          return "save";
205          return "delsig";      }
206      }  
207      if (!strcmp (key, "keyedit.delsig.unknown") ||      return NULL;
208          !strcmp (key, "keyedit.delsig.valid")) {  }
209          if (++ctx->cnt == ctx->sig_index)  
210              return "Y";  
211          else  static const char*
212              return "N";  cmd_deluid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
213      }                      const char *key)
214      if (ctx->sig_index == 0 &&  {
215          !strcmp (key, "keyedit.delsig.selfsig"))      static char buf[64];
216          return "Y";  
217      if (step == 2 && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
218          *r_step = step = 0;          sprintf (buf, "uid %d", ctx->getUseridIndex ());
219          ctx->reset ();          ctx->cnt = 1;
220          return "save";          return buf;
221      }      }
222      return NULL;      if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) {
223  }          ctx->cnt = 2;
224            return "deluid";
225        }
226  /* 'delkey' command handler. */      if (ctx->cnt == 2 && !strcmp (key, "keyedit.remove.uid.okay")) {
227  static const char*          ctx->cnt = 3;
228  cmd_delkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,          return "Y";
229                      const char *key, int *r_step )      }
230  {      if (ctx->cnt == 3 && !strcmp (key, "keyedit.prompt" )) {
231      static char buf[64];          ctx->reset ();
232      int step = *r_step;          return "save";
233        }
234      if (step == 0 && !strcmp (key, "keyedit.prompt")) {      
235          sprintf (buf, "key %d", ctx->key_index);      return NULL;
236          *r_step = step = 1;  }
237          return buf;  
238      }  
239      if (step == 1 && !strcmp (key, "keyedit.prompt")) {  static const char*
240          *r_step = step = 2;  cmd_delsig_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)
241          return "delkey";  {
242      }      static char buf[64];
243      if (step == 2 && !strcmp (key, "keyedit.remove.subkey.okay")) {      static int sig_cnt = 0;
244          *r_step = step = 3;  
245          return "Y";      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
246      }          sprintf (buf, "uid %d", ctx->getUseridIndex ());
247      if (step == 3 && !strcmp (key, "keyedit.prompt")) {          ctx->cnt = 1;
248          *r_step = step = 0;          return buf;
249          ctx->reset ();      }
250          return "save";      if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) {
251      }          ctx->cnt = 2;
252            return "delsig";
253      return NULL;      }
254  }      if (!strcmp (key, "keyedit.delsig.unknown") ||
255            !strcmp (key, "keyedit.delsig.valid")) {
256            if (++sig_cnt == ctx->getSigIndex ())
257  /* 'addkey' command handler. */              return "Y";
258  static const char*          else
259  cmd_addkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)              return "N";
260  {      }
261      static char buf[64];      if (!strcmp (key, "keyedit.delsig.selfsig"))
262            return "Y";
263      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 2 && !strcmp (key, "keyedit.prompt")) {
264          ctx->cmd_sent = 1;          sig_cnt = 0;
265          return "addkey";          ctx->reset ();
266      }          return "save";
267        }
268      if (!strcmp (key, "passphrase.enter"))      return NULL;
269          return ctx->pass;  }
270      if (!strcmp (key, "keygen.algo")) {  
271          _snprintf (buf, sizeof buf-1, "%d", ctx->pubkey_algo);  
272          return buf;  /* 'delkey' command handler. */
273      }    static const char*
274      if (!strcmp (key, "keygen.size")) {  cmd_delkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
275          _snprintf (buf, sizeof buf-1, "%d", ctx->pubkey_size);                      const char *key)
276          return buf;  {
277      }      static char buf[64];
278      if (!strcmp (key, "keygen.valid")) {  
279          _snprintf (buf, sizeof buf-1, "%d", ctx->valid);      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
280          return buf;                  sprintf (buf, "key %d", ctx->getKeyIndex ());
281      }          ctx->cnt = 1;
282      if (!strcmp (key, "keyedit.prompt")) {          return buf;
283          ctx->reset ();      }
284          return "save";      if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) {
285      }          ctx->cnt = 2;
286      return NULL;          return "delkey";
287  }      }
288        if (ctx->cnt == 2 && !strcmp (key, "keyedit.remove.subkey.okay")) {
289  /* 'passwd' command handler. */          ctx->cnt = 3;
290  static const char*          return "Y";
291  cmd_passwd_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)      }
292  {      if (ctx->cnt == 3 && !strcmp (key, "keyedit.prompt")) {
293      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {          ctx->reset ();
294          ctx->cmd_sent = 1;          return "save";
295          return "passwd";      }
296      }  
297      if( !strcmp (key, "passphrase.enter") && !ctx->cnt) {      return NULL;
298          ctx->cnt = 1;  }
299          return ctx->pass;  
300      }  
301      if( !strcmp (key, "passphrase.enter" ))  /* 'addkey' command handler. */
302          return ctx->new_pass;  static const char*
303      if( !strcmp (key, "change_passwd.empty.okay" ))  cmd_addkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)
304          return ctx->flags?  "Y" : "N";  {
305      if (!strcmp (key, "keyedit.prompt")) {      static char buf[64];
306          ctx->reset ();  
307          return "save";      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {
308      }          ctx->cmd_sent = 1;
309      return NULL;          return "addkey";
310  }      }
311    
312        if (!strcmp (key, "passphrase.enter"))
313  static const char*          return ctx->pass;
314  cmd_setpref_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char * key)      if (!strcmp (key, "keygen.algo")) {
315  {          _snprintf (buf, sizeof (buf)-1, "%d", ctx->pubkey_algo);
316      static char buf[128];          return buf;
317        }  
318      /* XXX: check the code. */      if (!strcmp (key, "keygen.size")) {
319  #if 0          _snprintf (buf, sizeof (buf)-1, "%d", ctx->pubkey_size);
320      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {          return buf;
321          ctx->cmd_sent = 1;      }
322          return "";      if (!strcmp (key, "keygen.valid")) {
323      }          _snprintf (buf, sizeof (buf)-1, "%d", ctx->getValidDays ());
324      if (!strcmp ( key, "keyedit.prompt") && ctx->u.pref.id == 0) {          return buf;        
325          ctx->u.pref.id++;      }
326          _snprintf (buf, sizeof buf-1, "setpref %s", ctx->u.pref.new_prefs);      if (!strcmp (key, "keyedit.prompt")) {
327          return buf;          ctx->reset ();
328      }          return "save";
329      if (!strcmp ( key, "keyedit.prompt") && ctx->u.pref.id == 1) {      }
330          ctx->u.pref.id++;      return NULL;
331          return "updpref";  }
332      }  
333      if (!strcmp ( key, "keyedit.updpref.okay"))  
334          return "Y";  /* 'passwd' command handler. */
335      if (!strcmp (key, "passphrase.enter"))  static const char*
336          return ctx->u.pref.passwd;  cmd_passwd_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)
337      if (!strcmp (key, "keyedit.prompt") && ctx->u.pref.id == 2) {  {
338          ctx->u.pref.id = 0;      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {
339          ctx->reset ();          ctx->cmd_sent = 1;
340          return "save";          return "passwd";
341      }      }
342  #endif      if (ctx->cnt == 0 && !strcmp (key, "passphrase.enter")) {
343      return NULL;          ctx->cnt = 1;
344  }          return ctx->pass;
345        }
346        if (!strcmp (key, "passphrase.enter" ))
347  /* 'primary' command handler. */          return ctx->new_pass;
348  static const char*      if (!strcmp (key, "change_passwd.empty.okay" ))
349  cmd_primary_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,          return ctx->flags?  "Y" : "N";
350                       const char *key, int *r_step )      if (!strcmp (key, "keyedit.prompt")) {
351  {          ctx->reset ();
352      static char buf[64];          return "save";
353      int step = *r_step;      }
354    
355      if (step == 0 && !strcmp (key, "keyedit.prompt")) {      return NULL;
356          sprintf (buf, "uid %d", ctx->uid_index);  }
357          *r_step = step = 1;  
358          return buf;  
359      }  static const char*
360      if (step == 1 && !strcmp (key, "keyedit.prompt" )) {  cmd_setpref_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char * key)
361          *r_step = step = 2;  {
362          return "primary";      static char buf[128];
363      }  
364      if (step == 2 && !strcmp (key, "passphrase.enter")) {      /* XXX: check the code. */
365          *r_step = step = 3;  #if 0
366          return ctx->pass;      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {
367      }          ctx->cmd_sent = 1;
368      if (step == 3 && !strcmp (key, "keyedit.prompt")) {          return "";
369          *r_step = step = 0;      }
370          ctx->reset ();      if (!strcmp (key, "keyedit.prompt") && ctx->u.pref.id == 0) {
371          return "save";          ctx->u.pref.id++;
372      }          _snprintf (buf, sizeof buf-1, "setpref %s", ctx->u.pref.new_prefs);
373      return NULL;          return buf;
374  }      }
375        if (!strcmp (key, "keyedit.prompt") && ctx->u.pref.id == 1) {
376  /* 'expire' command handler. */          ctx->u.pref.id++;
377  static const char*          return "updpref";
378  cmd_expire_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,      }
379                      const char *key, int *r_step )      if (!strcmp (key, "keyedit.updpref.okay"))
380  {          return "Y";
381      static char buf[64];      if (!strcmp (key, "passphrase.enter"))
382      int step = *r_step;          return ctx->u.pref.passwd;
383        if (!strcmp (key, "keyedit.prompt") && ctx->u.pref.id == 2) {
384      if (step == 0 && !strcmp (key, "keyedit.prompt")) {          ctx->u.pref.id = 0;
385          sprintf (buf, "key %d", ctx->key_index);          ctx->reset ();
386          *r_step = step = 1;          return "save";
387          return buf;      }
388      }  #endif
389      if (step == 1 && !strcmp (key, "keyedit.prompt")) {      return NULL;
390          *r_step = step = 2;  }
391          return "expire";  
392      }  
393      if( step == 2 && !strcmp ( key, "keygen.valid" ) ) {  /* 'primary' command handler. */
394          *r_step = step = 3;  static const char*
395          sprintf (buf, "%d", ctx->valid);  cmd_primary_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
396          return buf;                       const char *key)
397      }  {
398      if (step == 3 && !strcmp (key, "passphrase.enter")) {      static char buf[64];
399          *r_step = step = 4;  
400          return ctx->pass;      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
401      }          sprintf (buf, "uid %d", ctx->getUseridIndex ());
402      if (step == 4 && !strcmp (key, "keyedit.prompt")) {          ctx->cnt = 1;
403          *r_step = step = 0;          return buf;
404          ctx->reset ();      }
405          return "save";      if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt" )) {
406      }          ctx->cnt = 2;
407                return "primary";
408      return NULL;      }
409  }      if (ctx->cnt == 2 && !strcmp (key, "passphrase.enter")) {
410            ctx->cnt = 3;
411            return ctx->pass;
412  /* 'revuid' command handler. */      }
413  const char*      if (ctx->cnt == 3 && !strcmp (key, "keyedit.prompt")) {
414  cmd_revuid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,          ctx->reset ();
415                      const char *key, int *r_step)          return "save";
416  {      }
417      static char buf[32];      return NULL;
418      int step = *r_step;  }
419        
420      if (step == 0 && !strcmp (key, "keyedit.prompt")) {  
421          *r_step = step = 1;  /* 'expire' command handler. */
422          sprintf (buf, "uid %d", ctx->uid_index);  static const char*
423          return buf;  cmd_expire_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
424      }                      const char *key)
425      else if (step == 1 && !strcmp (key, "keyedit.prompt")) {  {
426          *r_step = step = 2;      static char buf[64];
427          return "revuid";  
428      }      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
429      else if (step == 2 && !strcmp (key, "keyedit.revoke.uid.okay")) {          sprintf (buf, "key %d", ctx->getKeyIndex ());
430          *r_step = step = 3;          ctx->cnt = 1;
431          return "Y";          return buf;
432      }      }
433      else if (step == 3 && !strcmp (key, "ask_revocation_reason.code")) {      if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) {
434          *r_step = step = 4;          ctx->cnt = 2;
435          return "4";          return "expire";
436      }      }
437      else if (step == 4 && !strcmp (key, "ask_revocation_reason.text")) {      if (ctx->cnt == 2 && !strcmp (key, "keygen.valid" )) {
438          *r_step = step = 5;          ctx->cnt = 3;
439          return "";          sprintf (buf, "%d", ctx->getValidDays ());
440      }          return buf;
441      else if (step == 5 && !strcmp (key, "ask_revocation_reason.okay")) {      }
442          *r_step = step = 6;      if (ctx->cnt == 3 && !strcmp (key, "passphrase.enter")) {
443          return "Y";          ctx->cnt = 4;
444      }          return ctx->pass;
445      else if (step == 6 && !strcmp (key, "passphrase.enter")) {      }
446          *r_step = step = 7;      if (ctx->cnt == 4 && !strcmp (key, "keyedit.prompt")) {
447          return ctx->pass;          ctx->reset ();
448      }          return "save";
449      else if (step == 7 && !strcmp (key, "keyedit.prompt")) {      }
450          *r_step = step = 0;      
451          ctx->reset ();      return NULL;
452          return "save";  }
453      }  
454      return NULL;  
455  }  /* 'revuid' command handler. */
456    const char*
457    cmd_revuid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
458  const char*                      const char *key)
459  cmd_revsig_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,  {
460                      const char *key, int *r_step)      static char buf[32];
461  {      
462      static char buf[64];      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
463      int step = *r_step;          ctx->cnt = 1;
464                sprintf (buf, "uid %d", ctx->getUseridIndex ());
465      if( step == 0 && !strcmp ( key, "keyedit.prompt" ) ) {          return buf;
466          sprintf( buf, "uid %d", ctx->uid_index);      }
467          *r_step = step = 1;      else if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) {
468          return buf;          ctx->cnt = 2;
469      }          return "revuid";
470      if( step == 1 && !strcmp ( key, "keyedit.prompt" ) ) {      }
471          *r_step = step = 2;      else if (ctx->cnt == 2 && !strcmp (key, "keyedit.revoke.uid.okay")) {
472          return "revsig";          ctx->cnt = 3;
473      }          return "Y";
474      if( step == 2 && !strcmp (key, "ask_revoke_sig.one" ) ) {      }
475          *r_step = step = 3;      else if (ctx->cnt == 3 && !strcmp (key, "ask_revocation_reason.code")) {
476          return "Y";          ctx->cnt = 4;
477      }          return "4";
478      if( step == 3 && !strcmp (key, "ask_revoke_sig.okay" ) ) {      }
479          *r_step = step = 4;      else if (ctx->cnt == 4 && !strcmp (key, "ask_revocation_reason.text")) {
480          return "Y";          ctx->cnt = 5;
481      }          return "";
482      if( step == 4 && !strcmp ( key, "ask_revocation_reason.code" ) ) {      }
483          *r_step = step = 5;      else if (ctx->cnt == 5 && !strcmp (key, "ask_revocation_reason.okay")) {
484          return "0";          ctx->cnt = 6;
485      }          return "Y";
486      if( step == 5 && !strcmp ( key, "ask_revocation_reason.text" ) ) {      }
487          *r_step = step = 6;      else if (ctx->cnt == 6 && !strcmp (key, "passphrase.enter")) {
488          return "";          ctx->cnt = 7;
489      }          return ctx->pass;
490      if( step == 6 && !strcmp (key, "ask_revocation_reason.okay" ) ) {      }
491          *r_step = step = 7;      else if (ctx->cnt == 7 && !strcmp (key, "keyedit.prompt")) {
492          return "Y";          ctx->reset ();
493      }          return "save";
494      if( step == 7 && !strcmp (key, "passphrase.enter" ) ) {      }
495          *r_step = step = 8;      return NULL;
496          return ctx->pass;  }
497      }  
498      if( step == 8 && !strcmp ( key, "keyedit.prompt" ) ) {  
499          *r_step = step = 0;  const char*
500          ctx->reset ();  cmd_revsig_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
501          return "save";                      const char *key)
502      }  {
503            static char buf[64];
504      return NULL;      
505  }      if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt" )) {
506            sprintf( buf, "uid %d", ctx->getUseridIndex ());
507            ctx->cnt = 1;
508  /* 'revoke' command handler. */          return buf;
509  static const char *      }
510  cmd_revkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,      if (ctx->cnt == 1 && !strcmp ( key, "keyedit.prompt" ) ) {
511                      const char * key, int *r_step)          ctx->cnt = 2;
512  {          return "revsig";
513      int step = *r_step;      }
514      static char buf[64];      if (ctx->cnt == 2 && !strcmp (key, "ask_revoke_sig.one" ) ) {
515            ctx->cnt = 3;
516      if( step == 0 && !strcmp ( key, "keyedit.prompt" ) ) {          return "Y";
517          sprintf( buf, "key %d", ctx->key_index);      }
518          *r_step = step = 1;      if (ctx->cnt == 3 && !strcmp (key, "ask_revoke_sig.okay" ) ) {
519          return buf;          ctx->cnt = 4;
520      }          return "Y";
521      if( step == 1 && !strcmp ( key, "keyedit.prompt" ) ) {      }
522          *r_step = step = 2;      if (ctx->cnt == 4 && !strcmp ( key, "ask_revocation_reason.code" ) ) {
523          return "revkey";          ctx->cnt = 5;
524      }          return "0";
525      if( step == 2 && !strcmp (key, "keyedit.revoke.subkey.okay" ) ) {      }
526          *r_step = step = 3;      if (ctx->cnt == 5 && !strcmp ( key, "ask_revocation_reason.text" ) ) {
527          return "Y";          ctx->cnt = 6;
528      }          return "";
529      if( step == 3 &&  !strcmp ( key, "ask_revocation_reason.code" ) ) {      }
530          sprintf( buf, "%d", ctx->reason);      if (ctx->cnt == 6 && !strcmp (key, "ask_revocation_reason.okay" ) ) {
531          *r_step = step = 4;          ctx->cnt = 7;
532          return buf;          return "Y";
533      }      }
534      if( step == 4 && !strcmp ( key, "ask_revocation_reason.text" ) ) {      if (ctx->cnt == 7 && !strcmp (key, "passphrase.enter" ) ) {
535          *r_step = step = 5;          ctx->cnt = 8;
536          return "";          return ctx->pass;
537      }      }
538      if( step == 5 && !strcmp (key, "ask_revocation_reason.okay" ) ) {      if (ctx->cnt == 8 && !strcmp ( key, "keyedit.prompt" ) ) {
539          *r_step = step = 6;          ctx->reset ();
540          return "Y";          return "save";
541      }      }
542      if( step == 6 && !strcmp (key, "passphrase.enter" ) ) {      
543          *r_step = step = 7;      return NULL;
544          return ctx->pass;  }
545      }  
546      if( step == 7 && !strcmp ( key, "keyedit.prompt" ) ) {  
547          *r_step = step = 0;  /* 'revoke' command handler. */
548          ctx->reset ();  static const char *
549          return "save";  cmd_revkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
550      }                      const char *key)
551      return NULL;  {
552  }      static char buf[64];
553    
554        if (ctx->cnt == 0 && !strcmp ( key, "keyedit.prompt" ) ) {
555  /* 'addrevoker' command handler. */          sprintf( buf, "key %d", ctx->getKeyIndex ());
556  static const char *          ctx->cnt = 1;
557  cmd_addrev_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,          return buf;
558                      const char * key, int * r_step)      }
559  {      if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) {
560      int step = *r_step;          ctx->cnt = 2;
561            return "revkey";
562      if (step == 0 && !strcmp (key, "keyedit.prompt")) {      }
563          *r_step = step = 1;      if (ctx->cnt == 2 && !strcmp (key, "keyedit.revoke.subkey.okay")) {
564          return "addrevoker";          ctx->cnt = 3;
565      }          return "Y";
566      if (step == 1 && !strcmp (key, "keyedit.add_revoker")) {      }
567          *r_step = step = 2;      if (ctx->cnt == 3 &&  !strcmp ( key, "ask_revocation_reason.code")) {
568          /* XXX: handle already-signed. */          sprintf( buf, "%d", ctx->reason);
569          return ctx->name;          ctx->cnt = 4;
570      }          return buf;
571      if (step == 2 && !strcmp (key, "keyedit.add_revoker.okay")) {      }
572          *r_step = step = 3;      if (ctx->cnt == 4 && !strcmp (key, "ask_revocation_reason.text")) {
573          return "Y";          ctx->cnt = 5;
574      }          return "";
575      if (step == 3 && !strcmp (key, "passphrase.enter")) {      }
576          *r_step = step = 4;      if (ctx->cnt == 5 && !strcmp (key, "ask_revocation_reason.okay")) {
577          return ctx->pass;          ctx->cnt = 6;
578      }          return "Y";
579      if (step == 4 && !strcmp (key, "keyedit.prompt")) {      }
580          *r_step = step = 0;      if (ctx->cnt == 6 && !strcmp (key, "passphrase.enter")) {
581          ctx->reset ();          ctx->cnt = 7;
582          return "save";          return ctx->pass;
583      }      }
584        if (ctx->cnt == 7 && !strcmp ( key, "keyedit.prompt")) {
585      return NULL;          ctx->reset ();
586  }          return "save";
587        }
588        return NULL;
589  /* 'addphoto' command handler. */  }
590  static const char*  
591  cmd_addphoto_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)  
592  {  /* 'addrevoker' command handler. */
593      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {  static const char *
594          ctx->cmd_sent = 1;  cmd_addrev_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
595          return "addphoto";                      const char *key)
596      }  {
597      if (!strcmp (key, "photoid.jpeg.add"))  
598          return ctx->url;      /* If the isuser already signed the key, send an empty
599      if (!strcmp (key, "photoid.jpeg.size"))             string and jump to quit. */
600          return "Y";      if (ctx->getResult () & EDITKEY_ERR_ALREADY_SIGNED
601      if (!strcmp (key, "passphrase.enter"))          && ctx->cnt != -1 && ctx->cnt != 4) {
602          return ctx->pass;          ctx->cnt = -1;
603      if (!strcmp (key, "keyedit.prompt")) {                return "";
604          ctx->reset ();      }
605          return "save";      if (ctx->cnt == -1) {
606      }          ctx->cnt = 4;
607      return NULL;          return ""; /* empty value to abort. */
608  }      }
609        if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) {
610  /* 'enable' and 'disable' command handler. */          ctx->cnt = 1;
611  static const char *          return "addrevoker";
612  cmd_enable_disable_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,      }
613                              const char * key, int mode)      if (ctx->cnt == 1 && !strcmp (key, "keyedit.add_revoker")) {
614  {          ctx->cnt = 2;
615      if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) {          return ctx->name;
616          ctx->cmd_sent = 1;      }
617          if (mode)      if (ctx->cnt == 2 && !strcmp (key, "keyedit.add_revoker.okay")) {
618              return "disable";          ctx->cnt = 3;
619          return "enable";          return "Y";
620      }      }
621      if (!strcmp (key, "keyedit.prompt")) {      if (ctx->cnt == 3 && !strcmp (key, "passphrase.enter")) {
622          ctx->reset ();          ctx->cnt = 4;
623          return "save";          return ctx->pass;
624      }      }
625      return NULL;      if (ctx->cnt == 4 && !strcmp (key, "keyedit.prompt")) {
626  }          ctx->reset ();
627            return "save";
628        }
629  /* edit key dispatch handler. */  
630  static gpgme_error_t                          return NULL;
631  editkey_command_handler (void *opaque, gpgme_status_code_t code,  }
632                           const char *key, int fd)  
633  {  
634      static int step = 0;  /* 'addphoto' command handler. */
635      const char *out = NULL;  static const char*
636      GpgKeyEdit *ke = (GpgKeyEdit *)opaque;  cmd_addphoto_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key)
637      HANDLE hd = (HANDLE)fd;  {
638      DWORD n;      if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) {
639                ctx->cmd_sent = 1;
640      if (!ke)          return "addphoto";
641          return gpg_error (GPG_ERR_INV_ARG);      }
642        if (!strcmp (key, "photoid.jpeg.add"))
643      /*log_debug ("key=%s code=%d\r\n", key, code);*/          return ctx->url;
644      switch (code) {      if (!strcmp (key, "photoid.jpeg.size"))
645      case GPGME_STATUS_ALREADY_SIGNED:          return "Y";
646          ke->setResult (GPG_EDITRES_ALREADY_SIGNED);      if (!strcmp (key, "passphrase.enter"))
647          break;          return ctx->pass;
648      case GPGME_STATUS_BAD_PASSPHRASE:      if (!strcmp (key, "keyedit.prompt")) {      
649          ke->setResult (GPG_EDITRES_BAD_PASSPHRASE);          ctx->reset ();
650          break;          return "save";
651      }      }
652        return NULL;
653      if (ke->getResult () & GPG_EDITRES_BAD_PASSPHRASE) {  }
654          /* If the entered passphrase is bad, we supply empty  
655             passphrase to abort and send 'quit' as soon as possible. */  
656          if (!strcmp (key, "passphrase.enter"))  static const char*
657              WriteFile (hd, "\n", 1, &n, NULL);  cmd_minimize_handler (GpgKeyEdit *ctx, status_code_t code, const char *key)
658          if (!strcmp (key, "keyedit.prompt"))  {
659              WriteFile (hd, "quit\n", 5, &n, NULL);      if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) {
660      }          ctx->cmd_sent = 1;
661                return "minimize";
662      switch (ke->getType ()) {      }
663      case GPG_EDITKEY_LSIGN:      if (!strcmp (key, "keyedit.prompt")) {
664      case GPG_EDITKEY_SIGN:          ctx->reset ();
665      case GPG_EDITKEY_NRSIGN:          return "save";
666      case GPG_EDITKEY_TSIGN:      }
667      case GPG_EDITKEY_NRLSIGN:  
668          out = cmd_sign_handler (ke, code, key);      return NULL;
669          break;  }
670            
671      case GPG_EDITKEY_TRUST:  /* 'clean' command handler. */
672          out =  cmd_trust_handler (ke, code, key);  static const char*
673          break;  cmd_clean_handler (GpgKeyEdit *ctx, status_code_t code, const char *key)
674            {
675      case GPG_EDITKEY_ADDUID:      if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) {
676          out =  cmd_adduid_handler (ke, code, key);          ctx->cmd_sent = 1;
677          break;          return "clean";
678                }
679      case GPG_EDITKEY_DELUID:      if (!strcmp (key, "keyedit.prompt")) {
680          out =  cmd_deluid_handler (ke, code, key, &step);          ctx->reset ();
681          break;          return "save";
682                }
683      case GPG_EDITKEY_DELSIG:      return NULL;
684          out =  cmd_delsig_handler (ke, code, key, &step);  }
685          break;  
686    
687      case GPG_EDITKEY_DELKEY:  /* 'enable' and 'disable' command handler. */
688          out =  cmd_delkey_handler(ke, code, key, &step );  static const char *
689          break;  cmd_enable_disable_handler (GpgKeyEdit *ctx, gpgme_status_code_t code,
690                                        const char * key, int mode)
691      case GPG_EDITKEY_ADDKEY:  {
692          out =  cmd_addkey_handler (ke, code, key);      if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) {
693          break;          ctx->cmd_sent = 1;
694                    return mode? "disable": "enable";
695      case GPG_EDITKEY_PASSWD:      }
696          out =  cmd_passwd_handler (ke, code, key);      if (!strcmp (key, "keyedit.prompt")) {
697          break;          ctx->reset ();
698                    return "save";
699      case GPG_EDITKEY_PRIMARY:      }
700          out =  cmd_primary_handler (ke, code, key, &step);      return NULL;
701          break;  }
702            
703      case GPG_EDITKEY_EXPIRE:  
704          out =  cmd_expire_handler (ke, code, key, &step);  /* edit key dispatch handler. */
705          break;  static gpgme_error_t                    
706    editkey_command_handler (void *opaque, gpgme_status_code_t code,
707      case GPG_EDITKEY_REVSIG:                           const char *key, int fd)
708          out =  cmd_revsig_handler (ke, code, key, &step);  {
709          break;      const char *out = NULL;
710        GpgKeyEdit *ke = (GpgKeyEdit *)opaque;
711      case GPG_EDITKEY_REVKEY:      HANDLE hd = (HANDLE)fd;
712          out =  cmd_revkey_handler (ke, code, key, &step);      DWORD n;
713          break;      
714                    if (!ke)
715      case GPG_EDITKEY_REVUID:          return gpg_error (GPG_ERR_INV_ARG);
716          out = cmd_revuid_handler (ke, code, key, &step);  
717          break;      /*log_debug ("key=%s code=%d\r\n", key, code);*/
718        switch (code) {
719      case GPG_EDITKEY_ADDREV:      case GPGME_STATUS_ALREADY_SIGNED:
720          out =  cmd_addrev_handler (ke, code, key, &step);          ke->setResult (EDITKEY_ERR_ALREADY_SIGNED);
721          break;          break;
722    
723      case GPG_EDITKEY_ADDPHOTO:      case GPGME_STATUS_BAD_PASSPHRASE:
724          out =  cmd_addphoto_handler (ke, code, key);          ke->setResult (EDITKEY_ERR_BAD_PASSPHRASE);
725          break;          break;
726    
727      case GPG_EDITKEY_ENABLE:      default:
728      case GPG_EDITKEY_DISABLE:          break;
729          out = cmd_enable_disable_handler (ke, code, key,      }
730                                            ke->getType () == GPG_EDITKEY_DISABLE? 1: 0);  
731          break;      if (ke->getResult () & EDITKEY_ERR_BAD_PASSPHRASE) {
732            /* If the entered passphrase is bad, we supply empty
733      case GPG_EDITKEY_SETPREF:             passphrase to abort and send 'quit' as soon as possible. */
734          out =  cmd_setpref_handler (ke, code, key);          if (!strcmp (key, "passphrase.enter"))
735          break;              WriteFile (hd, "\n", 1, &n, NULL);
736            if (!strcmp (key, "keyedit.prompt"))
737      case GPG_EDITKEY_KEYSERV:              WriteFile (hd, "quit\n", 5, &n, NULL);
738          out =  cmd_keyserv_handler (ke, code, key);          ke->reset ();
739          break;          return 0;
740      }      }
741        
742      if (out != NULL) {      switch (ke->getType ()) {
743          /* XXX: check return codes. */      case GPG_EDITKEY_LSIGN:
744          WriteFile (hd, out, strlen (out), &n, NULL);      case GPG_EDITKEY_SIGN:
745          WriteFile (hd, "\n", 1, &n, NULL);      case GPG_EDITKEY_NRSIGN:
746      }      case GPG_EDITKEY_TSIGN:
747      return 0;      case GPG_EDITKEY_NRLSIGN:
748  }          out = cmd_sign_handler (ke, code, key);
749            break;
750            
751  /* Check if a GPG status code occured which marks the      case GPG_EDITKEY_TRUST:
752     current operation as failed.          out =  cmd_trust_handler (ke, code, key);
753     Return value: gpg error constant. */          break;
754  static gpgme_error_t          
755  map_result (GpgKeyEdit *ke)      case GPG_EDITKEY_ADDUID:
756  {          out =  cmd_adduid_handler (ke, code, key);
757      if (!ke->getResult ())          break;
758          return gpg_error (GPG_ERR_NO_ERROR);          
759      if (ke->getResult () & GPG_EDITRES_BAD_PASSPHRASE)      case GPG_EDITKEY_DELUID:
760          return gpg_error (GPG_ERR_BAD_PASSPHRASE);          out =  cmd_deluid_handler (ke, code, key);
761      return 0;          break;
762  }          
763        case GPG_EDITKEY_DELSIG:
764            out =  cmd_delsig_handler (ke, code, key);
765  /* Wrapper around the gpgme edit interface.          break;
766     @ctx context to use.  
767     @key key on which the operation should be performed.      case GPG_EDITKEY_DELKEY:
768     @ek  key edit context.          out =  cmd_delkey_handler(ke, code, key);
769     Return value: 0 on success. */          break;
770  gpgme_error_t          
771  gpg_editkey (gpgme_ctx_t ctx, gpgme_key_t key, GpgKeyEdit *ek)      case GPG_EDITKEY_ADDKEY:
772  {          out =  cmd_addkey_handler (ke, code, key);
773      gpgme_error_t err;          break;
774      gpgme_data_t out;          
775          case GPG_EDITKEY_PASSWD:
776      err = gpgme_data_new (&out);          out =  cmd_passwd_handler (ke, code, key);
777      if (err)          break;
778          return err;          
779      err = gpgme_op_edit (ctx, key, editkey_command_handler, ek, out);      case GPG_EDITKEY_PRIMARY:
780      if (!err)          out =  cmd_primary_handler (ke, code, key);
781          err = map_result (ek);          break;
782            
783      gpgme_data_release (out);      case GPG_EDITKEY_EXPIRE:
784      return err;          out =  cmd_expire_handler (ke, code, key);
785  }          break;
786    
787        case GPG_EDITKEY_REVSIG:
788            out =  cmd_revsig_handler (ke, code, key);
789            break;
790    
791        case GPG_EDITKEY_REVKEY:
792            out =  cmd_revkey_handler (ke, code, key);
793            break;
794                
795        case GPG_EDITKEY_REVUID:
796            out = cmd_revuid_handler (ke, code, key);
797            break;
798    
799        case GPG_EDITKEY_ADDREV:
800            out =  cmd_addrev_handler (ke, code, key);
801            break;
802    
803        case GPG_EDITKEY_ADDPHOTO:
804            out =  cmd_addphoto_handler (ke, code, key);
805            break;
806    
807        case GPG_EDITKEY_NOTATION:
808            out = cmd_notation_handler (ke, code, key);
809            break;
810    
811        case GPG_EDITKEY_MINIMIZE:
812            out = cmd_minimize_handler (ke, code, key);
813            break;
814    
815        case GPG_EDITKEY_CLEAN:
816            out = cmd_clean_handler (ke, code, key);
817            break;
818    
819        case GPG_EDITKEY_ENABLE:
820        case GPG_EDITKEY_DISABLE:
821            n = ke->getType () == GPG_EDITKEY_DISABLE? 1: 0;
822            out = cmd_enable_disable_handler (ke, code, key, n);
823            break;
824    
825        case GPG_EDITKEY_SETPREF:
826            out =  cmd_setpref_handler (ke, code, key);
827            break;
828    
829        case GPG_EDITKEY_KEYSERV:
830            out =  cmd_keyserv_handler (ke, code, key);
831            break;
832        }
833    
834        if (out != NULL) {
835            WriteFile (hd, out, strlen (out), &n, NULL);
836            WriteFile (hd, "\n", 1, &n, NULL);
837        }
838        return 0;
839    }
840    
841    
842    /* Check if a GPG status code occured which marks the
843       current operation as failed.
844       Return value: gpg error constant. */
845    static gpgme_error_t
846    map_result (GpgKeyEdit *ke)
847    {
848        /* XXX Sometimes ALREADY_SIGNED indicates an failure. */
849        if (!ke->getResult ())
850            return gpg_error (GPG_ERR_NO_ERROR);
851        if (ke->getResult () & EDITKEY_ERR_BAD_PASSPHRASE)
852            return gpg_error (GPG_ERR_BAD_PASSPHRASE);
853        return 0;
854    }
855    
856    
857    /* Wrapper around the gpgme edit interface.
858       @ctx context to use.
859       @key key on which the operation should be performed.
860       @ek  key edit context.
861       Return value: 0 on success. */
862    gpgme_error_t
863    gpg_editkey (gpgme_ctx_t ctx, gpgme_key_t key, GpgKeyEdit *ek)
864    {
865        gpgme_error_t err;
866        gpgme_data_t out;
867      
868        err = gpgme_data_new (&out);
869        if (err)
870            return err;
871        err = gpgme_op_edit (ctx, key, editkey_command_handler, ek, out);
872        if (!err)
873            err = map_result (ek);
874    
875        gpgme_data_release (out);
876        return err;
877    }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26