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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26