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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26