diff options
author | NIIBE Yutaka <gniibe@fsij.org> | 2021-07-21 08:34:34 +0200 |
---|---|---|
committer | NIIBE Yutaka <gniibe@fsij.org> | 2021-07-21 08:59:03 +0200 |
commit | b436fb6766b400167e5d57ff1116600bb496b04f (patch) | |
tree | a63c34cbf96a4a9fd3078183b8d25545205a9da7 | |
parent | scd: Fix access to list of cards (1/3). (diff) | |
download | gnupg2-b436fb6766b400167e5d57ff1116600bb496b04f.tar.xz gnupg2-b436fb6766b400167e5d57ff1116600bb496b04f.zip |
scd: Fix access to list of cards (2/3).
* scd/app-common.h (card_reset, select_application): Simplify.
* scd/app.c (card_reset, select_application): Simplify.
* scd/command.c (do_reset): Follow the change.
(open_card, open_card_with_request): Follow the change.
--
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
-rw-r--r-- | scd/app-common.h | 4 | ||||
-rw-r--r-- | scd/app.c | 39 | ||||
-rw-r--r-- | scd/command.c | 15 |
3 files changed, 28 insertions, 30 deletions
diff --git a/scd/app-common.h b/scd/app-common.h index d6e6f4c0a..d1b0a9a17 100644 --- a/scd/app-common.h +++ b/scd/app-common.h @@ -255,8 +255,8 @@ void application_notify_card_reset (int slot); gpg_error_t check_application_conflict (card_t card, const char *name, const unsigned char *serialno_bin, size_t serialno_bin_len); -gpg_error_t card_reset (card_t card, ctrl_t ctrl, int send_reset); -gpg_error_t select_application (ctrl_t ctrl, const char *name, card_t *r_app, +gpg_error_t card_reset (card_t card, ctrl_t ctrl); +gpg_error_t select_application (ctrl_t ctrl, const char *name, int scan, const unsigned char *serialno_bin, size_t serialno_bin_len); gpg_error_t select_additional_application (ctrl_t ctrl, const char *name); @@ -503,31 +503,20 @@ check_application_conflict (card_t card, const char *name, gpg_error_t -card_reset (card_t card, ctrl_t ctrl, int send_reset) +card_reset (card_t card, ctrl_t ctrl) { gpg_error_t err = 0; + int sw; - if (send_reset) - { - int sw; - - lock_card (card, ctrl); - sw = apdu_reset (card->slot); - if (sw) - err = gpg_error (GPG_ERR_CARD_RESET); - - card->reset_requested = 1; - unlock_card (card); + lock_card (card, ctrl); + sw = apdu_reset (card->slot); + if (sw) + err = gpg_error (GPG_ERR_CARD_RESET); - scd_kick_the_loop (); - gnupg_sleep (1); - } - else - { - ctrl->card_ctx = NULL; - ctrl->current_apptype = APPTYPE_NONE; - card_unref (card); - } + card->reset_requested = 1; + unlock_card (card); + scd_kick_the_loop (); + gnupg_sleep (1); return err; } @@ -780,17 +769,17 @@ app_new_register (int slot, ctrl_t ctrl, const char *name, * NAME and return its card context. Returns an error code and stores * NULL at R_CARD if no application was found or no card is present. */ gpg_error_t -select_application (ctrl_t ctrl, const char *name, card_t *r_card, +select_application (ctrl_t ctrl, const char *name, int scan, const unsigned char *serialno_bin, size_t serialno_bin_len) { gpg_error_t err = 0; card_t card, card_prev = NULL; - *r_card = NULL; - lock_w_card_list (CARD_LIST_LOCK_UPDATE); + ctrl->card_ctx = NULL; + if (scan || !card_top) { struct dev_list *l; @@ -875,7 +864,7 @@ select_application (ctrl_t ctrl, const char *name, card_t *r_card, { /* Note: We do not use card_ref as we are already locked. */ card->ref_count++; - *r_card = card; + ctrl->card_ctx = card; if (card_prev) { card_prev->next = card->next; diff --git a/scd/command.c b/scd/command.c index cb0dd379a..d45d9da82 100644 --- a/scd/command.c +++ b/scd/command.c @@ -157,7 +157,16 @@ do_reset (ctrl_t ctrl, int send_reset, int keep_lock) card_t card = ctrl->card_ctx; if (card) - card_reset (card, ctrl, IS_LOCKED (ctrl)? 0: send_reset); + { + if (!IS_LOCKED (ctrl) && send_reset) + card_reset (card, ctrl); + else + { + ctrl->card_ctx = NULL; + ctrl->current_apptype = APPTYPE_NONE; + card_unref (card); + } + } /* If we hold a lock, unlock now. */ if (!keep_lock && locked_session && ctrl->server_local == locked_session) @@ -223,7 +232,7 @@ open_card (ctrl_t ctrl) if (ctrl->card_ctx) return 0; - return select_application (ctrl, NULL, &ctrl->card_ctx, 0, NULL, 0); + return select_application (ctrl, NULL, 0, NULL, 0); } /* Explicitly open a card for a specific use of APPTYPE or SERIALNO. @@ -262,7 +271,7 @@ open_card_with_request (ctrl_t ctrl, ctrl->current_apptype = APPTYPE_NONE; card_unref (card); - err = select_application (ctrl, apptypestr, &ctrl->card_ctx, 1, + err = select_application (ctrl, apptypestr, 1, serialno_bin, serialno_bin_len); if (!err && opt_all) err = select_additional_application (ctrl, NULL); |