43 |
|
|
44 |
typedef gpgme_status_code_t status_code_t; |
typedef gpgme_status_code_t status_code_t; |
45 |
|
|
46 |
|
|
47 |
/* 'notation' command handler. */ |
/* 'notation' command handler. */ |
48 |
static const char* |
static const char* |
49 |
cmd_notation_handler (GpgKeyEdit *ctx, status_code_t code, const char *key) |
cmd_notation_handler (GpgKeyEdit *ctx, status_code_t code, const char *key) |
120 |
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
121 |
ctx->cmd_sent = 1; |
ctx->cmd_sent = 1; |
122 |
switch (ctx->getType ()) { |
switch (ctx->getType ()) { |
123 |
case GPG_EDITKEY_SIGN: return "sign"; |
case GPG_EDITKEY_SIGN: return "sign"; |
124 |
case GPG_EDITKEY_TSIGN: return "tsign"; |
case GPG_EDITKEY_TSIGN: return "tsign"; |
125 |
case GPG_EDITKEY_LSIGN: return "lsign"; |
case GPG_EDITKEY_LSIGN: return "lsign"; |
126 |
case GPG_EDITKEY_NRSIGN: return"nrsign"; |
case GPG_EDITKEY_NRSIGN: return "nrsign"; |
127 |
case GPG_EDITKEY_NRLSIGN: return "nrlsign"; |
case GPG_EDITKEY_NRLSIGN: return "nrlsign"; |
128 |
} |
} |
129 |
} |
} |
130 |
if (!strcmp (key, "sign_uid.class")) { |
if (!strcmp (key, "sign_uid.class")) { |
134 |
if (!strcmp (key, "sign_uid.expire")) |
if (!strcmp (key, "sign_uid.expire")) |
135 |
return "Y"; /* the sig expires when the key expires */ |
return "Y"; /* the sig expires when the key expires */ |
136 |
if (!strcmp (key, "siggen.valid")) |
if (!strcmp (key, "siggen.valid")) |
137 |
return ctx->exp_date; |
return ctx->exp_date? ctx->exp_date : "0"; |
138 |
if (!strcmp (key, "trustsig_prompt.trust_value")) { |
if (!strcmp (key, "trustsig_prompt.trust_value")) { |
139 |
sprintf (buf, "%d", ctx->trust_id); |
sprintf (buf, "%d", ctx->trust_id); |
140 |
return buf; |
return buf; |
299 |
} |
} |
300 |
|
|
301 |
|
|
302 |
|
/* 'addcardkey' command handler. */ |
303 |
|
static const char* |
304 |
|
cmd_addcardkey_handler (GpgKeyEdit *ctx, status_code_t code, const char *key) |
305 |
|
{ |
306 |
|
static char buf[32]; |
307 |
|
|
308 |
|
/* XXX: actually we mix up things here, it would be better to |
309 |
|
implement this in CardEditCB but because the edit-key |
310 |
|
interface is used, we have to implement it here. */ |
311 |
|
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
312 |
|
ctx->cmd_sent = 1; |
313 |
|
return "addcardkey"; |
314 |
|
} |
315 |
|
if (!strcmp (key, "cardedit.genkeys.subkeytype")) { |
316 |
|
sprintf (buf, "%d", ctx->getKeyIndex ()); |
317 |
|
return buf; |
318 |
|
} |
319 |
|
if (!strcmp (key, "cardedit.genkeys.replace_key")) |
320 |
|
return "Y"; /* better issue an extra warning? */ |
321 |
|
if (!strcmp (key, "passphrase.adminpin.ask")) |
322 |
|
return ctx->pass; |
323 |
|
if (!strcmp (key, "passphrase.pin.ask")) |
324 |
|
return ctx->new_pass; |
325 |
|
if (!strcmp (key, "keygen.valid")) { |
326 |
|
sprintf (buf, "%d", ctx->getValidDays ()); |
327 |
|
return buf; |
328 |
|
} |
329 |
|
if (!strcmp (key, "keyedit.prompt")) { |
330 |
|
ctx->reset (); |
331 |
|
return "save"; |
332 |
|
} |
333 |
|
return NULL; |
334 |
|
} |
335 |
|
|
336 |
|
|
337 |
/* 'addkey' command handler. */ |
/* 'addkey' command handler. */ |
338 |
static const char* |
static const char* |
339 |
cmd_addkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key) |
cmd_addkey_handler (GpgKeyEdit *ctx, status_code_t code, const char *key) |
340 |
{ |
{ |
341 |
static char buf[64]; |
static char buf[64]; |
342 |
|
|
377 |
} |
} |
378 |
if (ctx->cnt == 0 && !strcmp (key, "passphrase.enter")) { |
if (ctx->cnt == 0 && !strcmp (key, "passphrase.enter")) { |
379 |
ctx->cnt = 1; |
ctx->cnt = 1; |
380 |
|
/* it is possible that there is no old passphrase. */ |
381 |
|
if (!ctx->pass && ctx->flags) |
382 |
|
return ""; |
383 |
return ctx->pass; |
return ctx->pass; |
384 |
} |
} |
385 |
if (!strcmp (key, "passphrase.enter" )) |
if (!strcmp (key, "passphrase.enter" )) |
396 |
|
|
397 |
|
|
398 |
static const char* |
static const char* |
399 |
cmd_setpref_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char * key) |
cmd_setpref_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key) |
400 |
{ |
{ |
401 |
static char buf[128]; |
static char buf[128] = {0}; |
402 |
|
|
403 |
/* XXX: check the code. */ |
if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) { |
404 |
#if 0 |
_snprintf (buf, sizeof (buf)-1, "uid %d", ctx->getUseridIndex ()); |
|
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
|
405 |
ctx->cmd_sent = 1; |
ctx->cmd_sent = 1; |
406 |
return ""; |
ctx->cnt = 1; |
|
} |
|
|
if (!strcmp (key, "keyedit.prompt") && ctx->u.pref.id == 0) { |
|
|
ctx->u.pref.id++; |
|
|
_snprintf (buf, sizeof buf-1, "setpref %s", ctx->u.pref.new_prefs); |
|
407 |
return buf; |
return buf; |
408 |
} |
} |
409 |
if (!strcmp (key, "keyedit.prompt") && ctx->u.pref.id == 1) { |
if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 1) { |
410 |
ctx->u.pref.id++; |
_snprintf (buf, sizeof buf-1, "setpref %s", ctx->new_prefs); |
411 |
return "updpref"; |
ctx->cnt = 2; |
412 |
|
return buf; |
413 |
} |
} |
414 |
if (!strcmp (key, "keyedit.updpref.okay")) |
if (!strcmp (key, "keyedit.setpref.okay")) |
415 |
return "Y"; |
return "Y"; |
416 |
if (!strcmp (key, "passphrase.enter")) |
if (!strcmp (key, "passphrase.enter")) |
417 |
return ctx->u.pref.passwd; |
return ctx->pass; |
418 |
if (!strcmp (key, "keyedit.prompt") && ctx->u.pref.id == 2) { |
if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 2) { |
|
ctx->u.pref.id = 0; |
|
419 |
ctx->reset (); |
ctx->reset (); |
420 |
return "save"; |
return "save"; |
421 |
} |
} |
422 |
#endif |
return buf; |
|
return NULL; |
|
423 |
} |
} |
424 |
|
|
425 |
|
|
429 |
const char *key) |
const char *key) |
430 |
{ |
{ |
431 |
static char buf[64]; |
static char buf[64]; |
432 |
|
|
433 |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
434 |
sprintf (buf, "uid %d", ctx->getUseridIndex ()); |
sprintf (buf, "uid %d", ctx->getUseridIndex ()); |
435 |
ctx->cnt = 1; |
ctx->cnt = 1; |
754 |
break; |
break; |
755 |
|
|
756 |
case GPGME_STATUS_BAD_PASSPHRASE: |
case GPGME_STATUS_BAD_PASSPHRASE: |
757 |
|
log_debug ("editkey_command_handler: bad passphrase\n"); |
758 |
ke->setResult (EDITKEY_ERR_BAD_PASSPHRASE); |
ke->setResult (EDITKEY_ERR_BAD_PASSPHRASE); |
759 |
break; |
break; |
760 |
|
|
795 |
break; |
break; |
796 |
|
|
797 |
case GPG_EDITKEY_DELSIG: |
case GPG_EDITKEY_DELSIG: |
798 |
out = cmd_delsig_handler (ke, code, key); |
out = cmd_delsig_handler (ke, code, key); |
799 |
break; |
break; |
800 |
|
|
801 |
case GPG_EDITKEY_DELKEY: |
case GPG_EDITKEY_DELKEY: |
803 |
break; |
break; |
804 |
|
|
805 |
case GPG_EDITKEY_ADDKEY: |
case GPG_EDITKEY_ADDKEY: |
806 |
out = cmd_addkey_handler (ke, code, key); |
out = cmd_addkey_handler (ke, code, key); |
807 |
|
break; |
808 |
|
|
809 |
|
case GPG_EDITKEY_ADDCARDKEY: |
810 |
|
out = cmd_addcardkey_handler (ke, code, key); |
811 |
break; |
break; |
812 |
|
|
813 |
case GPG_EDITKEY_PASSWD: |
case GPG_EDITKEY_PASSWD: |