diff options
author | Werner Koch <[email protected]> | 2002-06-17 10:11:34 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2002-06-17 10:11:34 +0000 |
commit | 469dc1043df7cba113fedfbd10c1ad4052d9d6ee (patch) | |
tree | 84a2a73d1f9ad60fd6eb2b080efb84f41e72237f /agent/query.c | |
parent | * card-dinsig.c: Documented some stuff from the DIN norm. (diff) | |
download | gnupg-469dc1043df7cba113fedfbd10c1ad4052d9d6ee.tar.gz gnupg-469dc1043df7cba113fedfbd10c1ad4052d9d6ee.zip |
* agent.h: Add a callback function to the pin_entry_info structure.
* query.c (agent_askpin): Use the callback to check for a correct
PIN. Removed the start_err_text argument becuase it is not
anymore needed; changed callers.
* findkey.c (unprotect): Replace our own check loop by a callback.
(try_unprotect_cb): New.
* genkey.c (reenter_compare_cb): New.
(agent_genkey): Use this callback here. Fixed setting of the pi2
variable and a segv in case of an empty PIN.
* divert-scd.c (getpin_cb): Removed some unused stuff and
explained what we still have to change.
Diffstat (limited to '')
-rw-r--r-- | agent/query.c | 56 |
1 files changed, 33 insertions, 23 deletions
diff --git a/agent/query.c b/agent/query.c index af513b819..724bbd57d 100644 --- a/agent/query.c +++ b/agent/query.c @@ -218,13 +218,12 @@ all_digitsp( const char *s) number here and repeat it as long as we have invalid formed numbers. */ int -agent_askpin (const char *desc_text, const char *start_err_text, - struct pin_entry_info_s *pininfo) +agent_askpin (const char *desc_text, struct pin_entry_info_s *pininfo) { int rc; char line[ASSUAN_LINELENGTH]; struct entry_parm_s parm; - const char *errtext = start_err_text; + const char *errtext = NULL; if (opt.batch) return 0; /* fixme: we should return BAD PIN */ @@ -261,14 +260,8 @@ agent_askpin (const char *desc_text, const char *start_err_text, if (errtext) { /* fixme: should we show the try count? It must be translated */ - if (start_err_text) - { - snprintf (line, DIM(line)-1, "SETERROR %s", errtext); - start_err_text = NULL; - } - else - snprintf (line, DIM(line)-1, "SETERROR %s (try %d of %d)", - errtext, pininfo->failed_tries+1, pininfo->max_tries); + snprintf (line, DIM(line)-1, "SETERROR %s (try %d of %d)", + errtext, pininfo->failed_tries+1, pininfo->max_tries); line[DIM(line)-1] = 0; rc = assuan_transact (entry_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); if (rc) @@ -276,25 +269,42 @@ agent_askpin (const char *desc_text, const char *start_err_text, errtext = NULL; } - rc = assuan_transact (entry_ctx, "GETPIN", getpin_cb, &parm, NULL, NULL, NULL, NULL); + rc = assuan_transact (entry_ctx, "GETPIN", getpin_cb, &parm, + NULL, NULL, NULL, NULL); if (rc == ASSUAN_Too_Much_Data) errtext = pininfo->min_digits? trans ("PIN too long") : trans ("Passphrase too long"); else if (rc) return unlock_pinentry (map_assuan_err (rc)); - if (!errtext && !pininfo->min_digits) - return unlock_pinentry (0); /* okay, got a passphrase */ - if (!errtext && !all_digitsp (pininfo->pin)) - errtext = trans ("Invalid characters in PIN"); - if (!errtext && pininfo->max_digits - && strlen (pininfo->pin) > pininfo->max_digits) - errtext = trans ("PIN too long"); - if (!errtext - && strlen (pininfo->pin) < pininfo->min_digits) - errtext = trans ("PIN too short"); + + if (!errtext && pininfo->min_digits) + { + /* do some basic checks on the entered PIN. */ + if (!all_digitsp (pininfo->pin)) + errtext = trans ("Invalid characters in PIN"); + else if (pininfo->max_digits + && strlen (pininfo->pin) > pininfo->max_digits) + errtext = trans ("PIN too long"); + else if (strlen (pininfo->pin) < pininfo->min_digits) + errtext = trans ("PIN too short"); + } + + if (!errtext && pininfo->check_cb) + { + /* More checks by utilizing the optional callback. */ + pininfo->cb_errtext = NULL; + rc = pininfo->check_cb (pininfo); + if (rc == -1 && pininfo->cb_errtext) + errtext = pininfo->cb_errtext; + else if (rc == GNUPG_Bad_Passphrase || rc == GNUPG_Bad_PIN) + errtext = (pininfo->min_digits? trans ("Bad PIN") + : trans ("Bad Passphrase")); + else if (rc) + return unlock_pinentry (map_assuan_err (rc)); + } if (!errtext) - return unlock_pinentry (0); /* okay, got a PIN */ + return unlock_pinentry (0); /* okay, got a PIN or passphrase */ } return unlock_pinentry (pininfo->min_digits? GNUPG_Bad_PIN |