aboutsummaryrefslogtreecommitdiffstats
path: root/scd/app.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2009-03-24 11:40:57 +0000
committerWerner Koch <[email protected]>2009-03-24 11:40:57 +0000
commitf07e762d688fd560cca57ca1917b66c06782c2d6 (patch)
treef7a2a29a386c9f5ae8f2e8a8a136db9966b7f2c9 /scd/app.c
parentAllow deletion of ephemeral keys. (diff)
downloadgnupg-f07e762d688fd560cca57ca1917b66c06782c2d6.tar.gz
gnupg-f07e762d688fd560cca57ca1917b66c06782c2d6.zip
Better syncronization of several smartcard sessions.
Diffstat (limited to '')
-rw-r--r--scd/app.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/scd/app.c b/scd/app.c
index e66c6cb7a..eb97d846a 100644
--- a/scd/app.c
+++ b/scd/app.c
@@ -173,6 +173,10 @@ application_notify_card_reset (int slot)
/* FIXME: We are ignoring any error value here. */
lock_reader (slot);
+ /* Mark application as non-reusable. */
+ if (lock_table[slot].app)
+ lock_table[slot].app->no_reuse = 1;
+
/* Deallocate a saved application for that slot, so that we won't
try to reuse it. If there is no saved application, set a flag so
that we won't save the current state. */
@@ -241,6 +245,16 @@ select_application (ctrl_t ctrl, int slot, const char *name, app_t *r_app)
return gpg_error (GPG_ERR_CONFLICT);
}
+ /* Don't use a non-reusable marked application. */
+ if (app && app->no_reuse)
+ {
+ unlock_reader (slot);
+ log_info ("lingering application `%s' in use by reader %d"
+ " - can't switch\n",
+ app->apptype? app->apptype:"?", slot);
+ return gpg_error (GPG_ERR_CONFLICT);
+ }
+
/* If we don't have an app, check whether we have a saved
application for that slot. This is useful so that a card does
not get reset even if only one session is using the card - this
@@ -278,7 +292,7 @@ select_application (ctrl_t ctrl, int slot, const char *name, app_t *r_app)
unlock_reader (slot);
return 0; /* Okay: We share that one. */
}
-
+
/* Need to allocate a new one. */
app = xtrycalloc (1, sizeof *app);
if (!app)
@@ -458,7 +472,15 @@ release_application (app_t app)
if (lock_table[slot].last_app)
deallocate_app (lock_table[slot].last_app);
- lock_table[slot].last_app = lock_table[slot].app;
+ if (app->no_reuse)
+ {
+ /* If we shall not re-use the application we can't save it for
+ later use. */
+ deallocate_app (app);
+ lock_table[slot].last_app = NULL;
+ }
+ else
+ lock_table[slot].last_app = lock_table[slot].app;
lock_table[slot].app = NULL;
unlock_reader (slot);
}