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 |
4 |
* |
* |
5 |
* This file is part of WinPT. |
* This file is part of WinPT. |
6 |
* |
* |
29 |
#include "wptCommonCtl.h" |
#include "wptCommonCtl.h" |
30 |
#include "wptContext.h" |
#include "wptContext.h" |
31 |
#include "wptKeyEdit.h" |
#include "wptKeyEdit.h" |
32 |
|
#include "wptErrors.h" |
33 |
|
|
34 |
|
|
35 |
/* edit key callback for command 'keyserver' */ |
/* edit key callback for command 'keyserver' */ |
47 |
if (!strcmp (key, "passphrase.enter")) |
if (!strcmp (key, "passphrase.enter")) |
48 |
return ctx->pass; |
return ctx->pass; |
49 |
if (!strcmp (key, "keyedit.prompt")) { |
if (!strcmp (key, "keyedit.prompt")) { |
50 |
ctx->cmd_sent = 0; |
ctx->reset (); |
51 |
return "save"; |
return "save"; |
52 |
} |
} |
53 |
|
|
60 |
{ |
{ |
61 |
static char buf[32]; |
static char buf[32]; |
62 |
|
|
63 |
|
if (code == GPGME_STATUS_ALREADY_SIGNED) |
64 |
|
ctx->setResultValue (GPG_EDITRES_ALREADY_SIGNED); |
65 |
|
|
66 |
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
67 |
ctx->cmd_sent = 1; |
ctx->cmd_sent = 1; |
68 |
switch (ctx->type) { |
switch (ctx->type) { |
98 |
if( !strcmp ( key, "passphrase.enter" ) ) |
if( !strcmp ( key, "passphrase.enter" ) ) |
99 |
return ctx->pass; |
return ctx->pass; |
100 |
if( !strcmp (key, "keyedit.prompt" ) ) { |
if( !strcmp (key, "keyedit.prompt" ) ) { |
101 |
ctx->cmd_sent = 0; |
ctx->reset (); |
102 |
return "save"; |
return "save"; |
103 |
} |
} |
104 |
|
|
122 |
return buf; |
return buf; |
123 |
} |
} |
124 |
if (!strcmp (key, "keyedit.prompt")) { |
if (!strcmp (key, "keyedit.prompt")) { |
125 |
ctx->cmd_sent = 0; |
ctx->reset (); |
126 |
return "save"; |
return "save"; |
127 |
} |
} |
128 |
|
|
149 |
if( !strcmp (key, "passphrase.enter" ) ) |
if( !strcmp (key, "passphrase.enter" ) ) |
150 |
return ctx->pass; |
return ctx->pass; |
151 |
if( !strcmp (key, "keyedit.prompt" ) ) { |
if( !strcmp (key, "keyedit.prompt" ) ) { |
152 |
ctx->cmd_sent = 0; |
ctx->reset (); |
153 |
return "save"; |
return "save"; |
154 |
} |
} |
155 |
|
|
179 |
} |
} |
180 |
if( step == 3 && !strcmp ( key, "keyedit.prompt" ) ) { |
if( step == 3 && !strcmp ( key, "keyedit.prompt" ) ) { |
181 |
*r_step = step = 0; |
*r_step = step = 0; |
182 |
|
ctx->reset (); |
183 |
return "save"; |
return "save"; |
184 |
} |
} |
185 |
|
|
215 |
return "Y"; |
return "Y"; |
216 |
if (step == 2 && !strcmp (key, "keyedit.prompt")) { |
if (step == 2 && !strcmp (key, "keyedit.prompt")) { |
217 |
*r_step = step = 0; |
*r_step = step = 0; |
218 |
|
ctx->reset (); |
219 |
return "save"; |
return "save"; |
220 |
} |
} |
221 |
return NULL; |
return NULL; |
244 |
} |
} |
245 |
if( step == 3 && !strcmp (key, "keyedit.prompt" ) ) { |
if( step == 3 && !strcmp (key, "keyedit.prompt" ) ) { |
246 |
*r_step = step = 0; |
*r_step = step = 0; |
247 |
|
ctx->reset (); |
248 |
return "save"; |
return "save"; |
249 |
} |
} |
250 |
|
|
277 |
return buf; |
return buf; |
278 |
} |
} |
279 |
if( !strcmp (key, "keyedit.prompt" ) ) { |
if( !strcmp (key, "keyedit.prompt" ) ) { |
280 |
ctx->cmd_sent = 0; |
ctx->reset (); |
281 |
return "save"; |
return "save"; |
282 |
} |
} |
283 |
return NULL; |
return NULL; |
300 |
if( !strcmp (key, "change_passwd.empty.okay" )) |
if( !strcmp (key, "change_passwd.empty.okay" )) |
301 |
return ctx->flags? "Y" : "N"; |
return ctx->flags? "Y" : "N"; |
302 |
if( !strcmp ( key, "keyedit.prompt" ) ) { |
if( !strcmp ( key, "keyedit.prompt" ) ) { |
303 |
ctx->cmd_sent = 0; |
ctx->reset (); |
304 |
return "save"; |
return "save"; |
305 |
} |
} |
306 |
return NULL; |
return NULL; |
333 |
return ctx->u.pref.passwd; |
return ctx->u.pref.passwd; |
334 |
if (!strcmp (key, "keyedit.prompt") && ctx->u.pref.id == 2) { |
if (!strcmp (key, "keyedit.prompt") && ctx->u.pref.id == 2) { |
335 |
ctx->u.pref.id = 0; |
ctx->u.pref.id = 0; |
336 |
|
ctx->reset (); |
337 |
return "save"; |
return "save"; |
338 |
} |
} |
339 |
#endif |
#endif |
363 |
} |
} |
364 |
if( step == 3 && !strcmp (key, "keyedit.prompt" ) ) { |
if( step == 3 && !strcmp (key, "keyedit.prompt" ) ) { |
365 |
*r_step = step = 0; |
*r_step = step = 0; |
366 |
|
ctx->reset (); |
367 |
return "save"; |
return "save"; |
368 |
} |
} |
369 |
return NULL; |
return NULL; |
401 |
} |
} |
402 |
if( step == 4 && !strcmp ( key, "keyedit.prompt" ) ) { |
if( step == 4 && !strcmp ( key, "keyedit.prompt" ) ) { |
403 |
*r_step = step = 0; |
*r_step = step = 0; |
404 |
|
ctx->reset (); |
405 |
return "save"; |
return "save"; |
406 |
} |
} |
407 |
|
|
451 |
} |
} |
452 |
if( step == 8 && !strcmp ( key, "keyedit.prompt" ) ) { |
if( step == 8 && !strcmp ( key, "keyedit.prompt" ) ) { |
453 |
*r_step = step = 0; |
*r_step = step = 0; |
454 |
|
ctx->reset (); |
455 |
return "save"; |
return "save"; |
456 |
} |
} |
457 |
|
|
498 |
} |
} |
499 |
if( step == 7 && !strcmp ( key, "keyedit.prompt" ) ) { |
if( step == 7 && !strcmp ( key, "keyedit.prompt" ) ) { |
500 |
*r_step = step = 0; |
*r_step = step = 0; |
501 |
|
ctx->reset (); |
502 |
return "save"; |
return "save"; |
503 |
} |
} |
504 |
return NULL; |
return NULL; |
527 |
} |
} |
528 |
if (step == 3 && !strcmp (key, "keyedit.prompt")) { |
if (step == 3 && !strcmp (key, "keyedit.prompt")) { |
529 |
*r_step = step = 0; |
*r_step = step = 0; |
530 |
|
ctx->reset (); |
531 |
return "save"; |
return "save"; |
532 |
} |
} |
533 |
return NULL; |
return NULL; |
548 |
return ctx->pass; |
return ctx->pass; |
549 |
if (!strcmp (key, "keyedit.prompt")) { |
if (!strcmp (key, "keyedit.prompt")) { |
550 |
*r_step = step = 0; |
*r_step = step = 0; |
551 |
|
ctx->reset (); |
552 |
return "save"; |
return "save"; |
553 |
} |
} |
554 |
return NULL; |
return NULL; |
566 |
return "enable"; |
return "enable"; |
567 |
} |
} |
568 |
if (!strcmp (key, "keyedit.prompt")) { |
if (!strcmp (key, "keyedit.prompt")) { |
569 |
ctx->cmd_sent = 0; |
ctx->reset (); |
570 |
return "save"; |
return "save"; |
571 |
} |
} |
572 |
return NULL; |
return NULL; |
581 |
static int step = 0; |
static int step = 0; |
582 |
const char *out = NULL; |
const char *out = NULL; |
583 |
GpgKeyEdit *ke = (GpgKeyEdit *)opaque; |
GpgKeyEdit *ke = (GpgKeyEdit *)opaque; |
584 |
|
HANDLE hd = (HANDLE)fd; |
585 |
|
DWORD n; |
586 |
|
|
587 |
if (!code || !ke) |
if (!ke) |
588 |
return gpg_error (GPG_ERR_INV_ARG); |
return gpg_error (GPG_ERR_INV_ARG); |
589 |
|
|
590 |
switch (ke->type) { |
switch (ke->type) { |
598 |
|
|
599 |
case GPG_EDITKEY_TRUST: |
case GPG_EDITKEY_TRUST: |
600 |
out = cmd_trust_handler (ke, code, key); |
out = cmd_trust_handler (ke, code, key); |
601 |
|
log_debug ("key=%s out=%s\n", key, out); |
602 |
break; |
break; |
603 |
|
|
604 |
case GPG_EDITKEY_ADDUID: |
case GPG_EDITKEY_ADDUID: |
664 |
break; |
break; |
665 |
} |
} |
666 |
if (out != NULL) { |
if (out != NULL) { |
667 |
write (fd, out, strlen (out)); |
WriteFile (hd, out, strlen (out), &n, NULL); |
668 |
write (fd, "\n", 1); |
WriteFile (hd, "\n", 1, &n, NULL); |
669 |
|
/* XXX: check return codes. */ |
670 |
} |
} |
671 |
return 0; |
return 0; |
672 |
} |
} |
677 |
gpg_editkey (gpgme_ctx_t ctx, gpgme_key_t key, GpgKeyEdit *ek) |
gpg_editkey (gpgme_ctx_t ctx, gpgme_key_t key, GpgKeyEdit *ek) |
678 |
{ |
{ |
679 |
gpgme_error_t err; |
gpgme_error_t err; |
680 |
|
gpgme_data_t out; |
681 |
|
|
682 |
err = gpgme_op_edit (ctx, key, editkey_command_handler, ek, NULL); |
err = gpgme_data_new (&out); |
683 |
|
if (err) |
684 |
|
return err; |
685 |
|
err = gpgme_op_edit (ctx, key, editkey_command_handler, ek, out); |
686 |
|
|
687 |
|
gpgme_data_release (out); |
688 |
return err; |
return err; |
689 |
} |
} |
690 |
|
|