Use cancel button in confirmation only if requested.

This commit is contained in:
Werner Koch 2009-06-17 10:19:50 +00:00
parent 5f8acaccc0
commit aa03d8f184
8 changed files with 41 additions and 18 deletions

View File

@ -1,3 +1,9 @@
2009-06-17 Werner Koch <wk@g10code.com>
* call-pinentry.c (agent_get_confirmation): Add arg WITH_CANCEL.
Change all callers.
* trustlist.c (agent_marktrusted): Use WITH_CANCEL
2009-06-09 Werner Koch <wk@g10code.com> 2009-06-09 Werner Koch <wk@g10code.com>
* learncard.c (send_cert_back): Ignore certain error codes. * learncard.c (send_cert_back): Ignore certain error codes.

View File

@ -256,7 +256,7 @@ int agent_get_passphrase (ctrl_t ctrl, char **retpass,
const char *desc, const char *prompt, const char *desc, const char *prompt,
const char *errtext, int with_qualitybar); const char *errtext, int with_qualitybar);
int agent_get_confirmation (ctrl_t ctrl, const char *desc, const char *ok, int agent_get_confirmation (ctrl_t ctrl, const char *desc, const char *ok,
const char *cancel); const char *notokay, int with_cancel);
int agent_show_message (ctrl_t ctrl, const char *desc, const char *ok_btn); int agent_show_message (ctrl_t ctrl, const char *desc, const char *ok_btn);
int agent_popup_message_start (ctrl_t ctrl, int agent_popup_message_start (ctrl_t ctrl,
const char *desc, const char *ok_btn); const char *desc, const char *ok_btn);

View File

@ -850,10 +850,14 @@ agent_get_passphrase (ctrl_t ctrl,
/* Pop up the PIN-entry, display the text and the prompt and ask the /* Pop up the PIN-entry, display the text and the prompt and ask the
user to confirm this. We return 0 for success, ie. the user user to confirm this. We return 0 for success, ie. the user
confirmed it, GPG_ERR_NOT_CONFIRMED for what the text says or an confirmed it, GPG_ERR_NOT_CONFIRMED for what the text says or an
other error. */ other error. If WITH_CANCEL it true an extra cancel button is
displayed to allow the user to easily return a GPG_ERR_CANCELED.
if the Pinentry does not support this, the user can still cancel by
closing the Pinentry window. */
int int
agent_get_confirmation (ctrl_t ctrl, agent_get_confirmation (ctrl_t ctrl,
const char *desc, const char *ok, const char *cancel) const char *desc, const char *ok,
const char *notok, int with_cancel)
{ {
int rc; int rc;
char line[ASSUAN_LINELENGTH]; char line[ASSUAN_LINELENGTH];
@ -881,26 +885,39 @@ agent_get_confirmation (ctrl_t ctrl,
{ {
snprintf (line, DIM(line)-1, "SETOK %s", ok); snprintf (line, DIM(line)-1, "SETOK %s", ok);
line[DIM(line)-1] = 0; line[DIM(line)-1] = 0;
rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); rc = assuan_transact (entry_ctx,
line, NULL, NULL, NULL, NULL, NULL, NULL);
if (rc) if (rc)
return unlock_pinentry (rc); return unlock_pinentry (rc);
} }
if (cancel) if (notok)
{ {
snprintf (line, DIM(line)-1, "SETNOTOK %s", cancel); /* Try to use the newer NOTOK feature if a cancel button is
line[DIM(line)-1] = 0; requested. If no cacnel button is requested we keep on using
rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); the standard cancel. */
if (with_cancel)
{
snprintf (line, DIM(line)-1, "SETNOTOK %s", notok);
line[DIM(line)-1] = 0;
rc = assuan_transact (entry_ctx,
line, NULL, NULL, NULL, NULL, NULL, NULL);
}
else
rc = GPG_ERR_ASS_UNKNOWN_CMD;
if (gpg_err_code (rc) == GPG_ERR_ASS_UNKNOWN_CMD) if (gpg_err_code (rc) == GPG_ERR_ASS_UNKNOWN_CMD)
{ {
snprintf (line, DIM(line)-1, "SETCANCEL %s", cancel); snprintf (line, DIM(line)-1, "SETCANCEL %s", notok);
line[DIM(line)-1] = 0; line[DIM(line)-1] = 0;
rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); rc = assuan_transact (entry_ctx, line,
NULL, NULL, NULL, NULL, NULL, NULL);
} }
if (rc) if (rc)
return unlock_pinentry (rc); return unlock_pinentry (rc);
} }
rc = assuan_transact (entry_ctx, "CONFIRM", NULL, NULL, NULL, NULL, NULL, NULL); rc = assuan_transact (entry_ctx, "CONFIRM",
NULL, NULL, NULL, NULL, NULL, NULL);
if (rc && gpg_err_source (rc) && gpg_err_code (rc) == GPG_ERR_ASS_CANCELED) if (rc && gpg_err_source (rc) && gpg_err_code (rc) == GPG_ERR_ASS_CANCELED)
rc = gpg_err_make (gpg_err_source (rc), GPG_ERR_CANCELED); rc = gpg_err_make (gpg_err_source (rc), GPG_ERR_CANCELED);

View File

@ -1229,7 +1229,7 @@ cmd_get_confirmation (assuan_context_t ctx, char *line)
if (desc) if (desc)
plus_to_blank (desc); plus_to_blank (desc);
rc = agent_get_confirmation (ctrl, desc, NULL, NULL); rc = agent_get_confirmation (ctrl, desc, NULL, NULL, 0);
if (rc) if (rc)
log_error ("command get_confirmation failed: %s\n", gpg_strerror (rc)); log_error ("command get_confirmation failed: %s\n", gpg_strerror (rc));
return rc; return rc;

View File

@ -97,7 +97,7 @@ ask_for_card (ctrl_t ctrl, const unsigned char *shadow_info, char **r_kid)
} }
else else
{ {
rc = agent_get_confirmation (ctrl, desc, NULL, NULL); rc = agent_get_confirmation (ctrl, desc, NULL, NULL, 0);
xfree (desc); xfree (desc);
} }
} }

View File

@ -183,7 +183,7 @@ try_unprotect_cb (struct pin_entry_info_s *pi)
if (opt.enforce_passphrase_constraints) if (opt.enforce_passphrase_constraints)
{ {
err = agent_get_confirmation (arg->ctrl, desc, err = agent_get_confirmation (arg->ctrl, desc,
_("Change passphrase"), NULL); _("Change passphrase"), NULL, 0);
if (!err) if (!err)
arg->change_required = 1; arg->change_required = 1;
} }
@ -191,7 +191,7 @@ try_unprotect_cb (struct pin_entry_info_s *pi)
{ {
err = agent_get_confirmation (arg->ctrl, desc, err = agent_get_confirmation (arg->ctrl, desc,
_("Change passphrase"), _("Change passphrase"),
_("I'll change it later")); _("I'll change it later"), 0);
if (!err) if (!err)
arg->change_required = 1; arg->change_required = 1;
else if (gpg_err_code (err) == GPG_ERR_CANCELED) else if (gpg_err_code (err) == GPG_ERR_CANCELED)

View File

@ -156,7 +156,7 @@ take_this_one_anyway2 (ctrl_t ctrl, const char *desc, const char *anyway_btn)
} }
else else
err = agent_get_confirmation (ctrl, desc, err = agent_get_confirmation (ctrl, desc,
anyway_btn, _("Enter new passphrase")); anyway_btn, _("Enter new passphrase"), 0);
return err; return err;
} }

View File

@ -616,7 +616,7 @@ agent_marktrusted (ctrl_t ctrl, const char *name, const char *fpr, int flag)
xfree (nameformatted); xfree (nameformatted);
return out_of_core (); return out_of_core ();
} }
err = agent_get_confirmation (ctrl, desc, _("Yes"), _("No")); err = agent_get_confirmation (ctrl, desc, _("Yes"), _("No"), 1);
xfree (desc); xfree (desc);
if (!err) if (!err)
yes_i_trust = 1; yes_i_trust = 1;
@ -664,7 +664,7 @@ agent_marktrusted (ctrl_t ctrl, const char *name, const char *fpr, int flag)
/* TRANSLATORS: "Correct" is the label of a button and intended /* TRANSLATORS: "Correct" is the label of a button and intended
to be hit if the fingerprint matches the one of the CA. The to be hit if the fingerprint matches the one of the CA. The
other button is "the default "Cancel" of the Pinentry. */ other button is "the default "Cancel" of the Pinentry. */
err = agent_get_confirmation (ctrl, desc, _("Correct"), _("Wrong")); err = agent_get_confirmation (ctrl, desc, _("Correct"), _("Wrong"), 1);
xfree (desc); xfree (desc);
if (gpg_err_code (err) == GPG_ERR_NOT_CONFIRMED) if (gpg_err_code (err) == GPG_ERR_NOT_CONFIRMED)
yes_i_trust = 0; yes_i_trust = 0;