From 7f04862c5988ad1653951ec190b26eb706091271 Mon Sep 17 00:00:00 2001 From: wk Date: Wed, 17 Jun 2009 10:19:50 +0000 Subject: [PATCH] Use cancel button in confirmation only if requested. git-svn-id: svn://cvs.gnupg.org/gnupg/trunk@5044 8a63c251-dffc-0310-8ec6-d64dca2275b1 --- agent/ChangeLog | 6 ++++++ agent/agent.h | 2 +- agent/call-pinentry.c | 37 +++++++++++++++++++++++++++---------- agent/command.c | 2 +- agent/divert-scd.c | 2 +- agent/findkey.c | 4 ++-- agent/genkey.c | 2 +- agent/trustlist.c | 4 ++-- 8 files changed, 41 insertions(+), 18 deletions(-) diff --git a/agent/ChangeLog b/agent/ChangeLog index 497083c5..32999095 100644 --- a/agent/ChangeLog +++ b/agent/ChangeLog @@ -1,3 +1,9 @@ +2009-06-17 Werner Koch + + * 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 * learncard.c (send_cert_back): Ignore certain error codes. diff --git a/agent/agent.h b/agent/agent.h index e37485fc..323c1c12 100644 --- a/agent/agent.h +++ b/agent/agent.h @@ -256,7 +256,7 @@ int agent_get_passphrase (ctrl_t ctrl, char **retpass, const char *desc, const char *prompt, const char *errtext, int with_qualitybar); 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_popup_message_start (ctrl_t ctrl, const char *desc, const char *ok_btn); diff --git a/agent/call-pinentry.c b/agent/call-pinentry.c index 41fe6f40..b956ef46 100644 --- a/agent/call-pinentry.c +++ b/agent/call-pinentry.c @@ -850,10 +850,14 @@ agent_get_passphrase (ctrl_t ctrl, /* 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 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 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; char line[ASSUAN_LINELENGTH]; @@ -881,26 +885,39 @@ agent_get_confirmation (ctrl_t ctrl, { snprintf (line, DIM(line)-1, "SETOK %s", ok); 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) return unlock_pinentry (rc); } - if (cancel) + if (notok) { - snprintf (line, DIM(line)-1, "SETNOTOK %s", cancel); - line[DIM(line)-1] = 0; - rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); + /* Try to use the newer NOTOK feature if a cancel button is + requested. If no cacnel button is requested we keep on using + 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) { - snprintf (line, DIM(line)-1, "SETCANCEL %s", cancel); + snprintf (line, DIM(line)-1, "SETCANCEL %s", notok); 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) 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) rc = gpg_err_make (gpg_err_source (rc), GPG_ERR_CANCELED); diff --git a/agent/command.c b/agent/command.c index 01f3ae24..9238a221 100644 --- a/agent/command.c +++ b/agent/command.c @@ -1229,7 +1229,7 @@ cmd_get_confirmation (assuan_context_t ctx, char *line) if (desc) plus_to_blank (desc); - rc = agent_get_confirmation (ctrl, desc, NULL, NULL); + rc = agent_get_confirmation (ctrl, desc, NULL, NULL, 0); if (rc) log_error ("command get_confirmation failed: %s\n", gpg_strerror (rc)); return rc; diff --git a/agent/divert-scd.c b/agent/divert-scd.c index fd8c28b6..4c3db967 100644 --- a/agent/divert-scd.c +++ b/agent/divert-scd.c @@ -97,7 +97,7 @@ ask_for_card (ctrl_t ctrl, const unsigned char *shadow_info, char **r_kid) } else { - rc = agent_get_confirmation (ctrl, desc, NULL, NULL); + rc = agent_get_confirmation (ctrl, desc, NULL, NULL, 0); xfree (desc); } } diff --git a/agent/findkey.c b/agent/findkey.c index 5fe73524..9405342d 100644 --- a/agent/findkey.c +++ b/agent/findkey.c @@ -183,7 +183,7 @@ try_unprotect_cb (struct pin_entry_info_s *pi) if (opt.enforce_passphrase_constraints) { err = agent_get_confirmation (arg->ctrl, desc, - _("Change passphrase"), NULL); + _("Change passphrase"), NULL, 0); if (!err) arg->change_required = 1; } @@ -191,7 +191,7 @@ try_unprotect_cb (struct pin_entry_info_s *pi) { err = agent_get_confirmation (arg->ctrl, desc, _("Change passphrase"), - _("I'll change it later")); + _("I'll change it later"), 0); if (!err) arg->change_required = 1; else if (gpg_err_code (err) == GPG_ERR_CANCELED) diff --git a/agent/genkey.c b/agent/genkey.c index cbddb85d..4bf0dcdc 100644 --- a/agent/genkey.c +++ b/agent/genkey.c @@ -156,7 +156,7 @@ take_this_one_anyway2 (ctrl_t ctrl, const char *desc, const char *anyway_btn) } else err = agent_get_confirmation (ctrl, desc, - anyway_btn, _("Enter new passphrase")); + anyway_btn, _("Enter new passphrase"), 0); return err; } diff --git a/agent/trustlist.c b/agent/trustlist.c index afb94141..a0b23b51 100644 --- a/agent/trustlist.c +++ b/agent/trustlist.c @@ -616,7 +616,7 @@ agent_marktrusted (ctrl_t ctrl, const char *name, const char *fpr, int flag) xfree (nameformatted); return out_of_core (); } - err = agent_get_confirmation (ctrl, desc, _("Yes"), _("No")); + err = agent_get_confirmation (ctrl, desc, _("Yes"), _("No"), 1); xfree (desc); if (!err) 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 to be hit if the fingerprint matches the one of the CA. The 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); if (gpg_err_code (err) == GPG_ERR_NOT_CONFIRMED) yes_i_trust = 0; -- 2.11.4.GIT