diff options
author | Werner Koch <[email protected]> | 2004-09-20 13:15:37 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2004-09-20 13:15:37 +0000 |
commit | 5576f6ef6c08639638ae09730ea8454bae24da18 (patch) | |
tree | 603a98986c1c8a02a581fd52dc1334a1c80788a6 /g10/cardglue.c | |
parent | (apdu_open_reader): No fallback if a full CCID reader id has been (diff) | |
download | gnupg-5576f6ef6c08639638ae09730ea8454bae24da18.tar.gz gnupg-5576f6ef6c08639638ae09730ea8454bae24da18.zip |
* cardglue.c (open_card): Use shutdown code if possible.
(check_card_serialno): Ditto.
* ccid-driver.c (do_close_reader): Factored some code out from ...
(ccid_close_reader): ..here.
(ccid_shutdown_reader): New.
* apdu.c (apdu_shutdown_reader): New.
(shutdown_ccid_reader): New.
Diffstat (limited to '')
-rw-r--r-- | g10/cardglue.c | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/g10/cardglue.c b/g10/cardglue.c index 7bb3c8488..5faa41bad 100644 --- a/g10/cardglue.c +++ b/g10/cardglue.c @@ -54,7 +54,6 @@ static APP current_app; - /* Create a serialno/fpr string from the serial number and the secret key. caller must free the returned string. There is no error return. [Taken from 1.9's keyid.c]*/ @@ -247,18 +246,25 @@ agent_release_card_info (struct agent_card_info_s *info) static APP open_card (void) { - int slot; + int slot = -1; int rc; APP app; + int did_shutdown = 0; card_close (); + retry: - slot = apdu_open_reader (default_reader_port); - if (slot == -1) + if (did_shutdown) + apdu_reset (slot); + else { - log_error ("card reader not available\n"); - return NULL; + slot = apdu_open_reader (default_reader_port); + if (slot == -1) + { + log_error ("card reader not available\n"); + return NULL; + } } app = xcalloc (1, sizeof *app); @@ -268,11 +274,14 @@ open_card (void) { write_status_text (STATUS_CARDCTRL, "1"); + did_shutdown = !!apdu_shutdown_reader (slot); + if ( cpr_get_answer_okay_cancel ("cardctrl.insert_card.okay", _("Please insert the card and hit return or enter 'c' to cancel: "), 1) ) { - apdu_close_reader (slot); + if (!did_shutdown) + apdu_close_reader (slot); xfree (app); goto retry; } @@ -323,7 +332,7 @@ card_close (void) function return 0 is the present card is okay, -1 if the user selected to insert a new card or an error value. Note that the card context will be closed in all cases except for 0 as return - value. */ + value and if it was possible to merely shutdown the reader. */ static int check_card_serialno (APP app, const char *serialno) { @@ -346,8 +355,12 @@ check_card_serialno (APP app, const char *serialno) if (ask) { char buf[5+32+1]; + int did_shutdown = 0; - card_close (); + if (current_app && !apdu_shutdown_reader (current_app->slot)) + did_shutdown = 1; + else + card_close (); tty_printf (_("Please remove the current card and " "insert the one with the serial number:\n" " %.*s\n"), 32, serialno); @@ -359,7 +372,14 @@ check_card_serialno (APP app, const char *serialno) _("Hit return when ready " "or enter 'c' to cancel: "), 1) ) - return -1; + { + card_close (); + return -1; + } + if (did_shutdown) + apdu_reset (current_app->slot); + else + card_close (); return gpg_error (GPG_ERR_INV_ID); } return 0; |