diff options
author | NIIBE Yutaka <[email protected]> | 2017-02-17 02:50:40 +0000 |
---|---|---|
committer | NIIBE Yutaka <[email protected]> | 2017-02-17 02:50:40 +0000 |
commit | 99d4dfe83661d05ef3a20ed04e6cec5647536738 (patch) | |
tree | be9c8926be1a560ea3878ddf9b7e93eea44fc738 /scd/app.c | |
parent | dirmngr,w32: Load all system provided certificates. (diff) | |
download | gnupg-99d4dfe83661d05ef3a20ed04e6cec5647536738.tar.gz gnupg-99d4dfe83661d05ef3a20ed04e6cec5647536738.zip |
scd: Fix RESET command handling (more).
* scd/app-common.h (struct app_ctx_s): Add reset_requested.
* scd/app.c (app_reset): Locking APP, set reset_requested.
(deallocate_app): Release the lock.
(release_application): Add LOCKED_ALREADY argument.
(scd_update_reader_status_file): Hold the lock when accessing APP.
When reset_requested is set, close the reader and deallocate APP.
* scd/command.c (open_card_with_request, cmd_restart): Follow the
change of release_application.
(send_client_notifications): Here it calls release_application holding
the lock.
Signed-off-by: NIIBE Yutaka <[email protected]>
Diffstat (limited to '')
-rw-r--r-- | scd/app.c | 29 |
1 files changed, 21 insertions, 8 deletions
@@ -143,19 +143,23 @@ app_reset (app_t app, ctrl_t ctrl, int send_reset) if (send_reset) { - int sw = apdu_reset (app->slot); + int sw; + + lock_app (app, ctrl); + sw = apdu_reset (app->slot); if (sw) err = gpg_error (GPG_ERR_CARD_RESET); - /* Release the same application which is used by all sessions. */ - send_client_notifications (app, 1); + app->reset_requested = 1; + unlock_app (app); + scd_kick_the_loop (); gnupg_sleep (1); } else { ctrl->app_ctx = NULL; - release_application (app); + release_application (app, 0); } return err; @@ -454,6 +458,8 @@ deallocate_app (app_t app) } xfree (app->serialno); + + unlock_app (app); xfree (app); } @@ -463,7 +469,7 @@ deallocate_app (app_t app) actually deferring the deallocation to allow for a later reuse by a new connection. */ void -release_application (app_t app) +release_application (app_t app, int locked_already) { if (!app) return; @@ -473,12 +479,15 @@ release_application (app_t app) is using the card - this way the PIN cache and other cached data are preserved. */ - lock_app (app, NULL); + if (!locked_already) + lock_app (app, NULL); + if (!app->ref_count) log_bug ("trying to release an already released context\n"); --app->ref_count; - unlock_app (app); + if (!locked_already) + unlock_app (app); } @@ -1019,9 +1028,10 @@ scd_update_reader_status_file (void) int sw; unsigned int status; + lock_app (a, NULL); app_next = a->next; - if (a->ref_count == 0) + if (a->reset_requested) status = 0; else { @@ -1036,6 +1046,7 @@ scd_update_reader_status_file (void) /* Get status failed. Ignore that. */ if (a->periodical_check_needed) periodical_check_needed = 1; + unlock_app (a); continue; } } @@ -1056,12 +1067,14 @@ scd_update_reader_status_file (void) a->card_status = status; if (a->periodical_check_needed) periodical_check_needed = 1; + unlock_app (a); } } else { if (a->periodical_check_needed) periodical_check_needed = 1; + unlock_app (a); } } npth_mutex_unlock (&app_list_lock); |