mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-03 12:11:33 +01:00
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>
This commit is contained in:
parent
216945a80e
commit
b436fb6766
@ -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);
|
||||
|
39
scd/app.c
39
scd/app.c
@ -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);
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user