aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2021-05-04 08:38:53 +0000
committerWerner Koch <[email protected]>2021-05-04 08:38:53 +0000
commit9d83bfb639680d3bc756fcfe2b7f83b18bed8dff (patch)
tree493f70c299b81136d0de527993e9346193c9deb9
parentscd: Add string for another PC/SC error code. (diff)
downloadgnupg-9d83bfb639680d3bc756fcfe2b7f83b18bed8dff.tar.gz
gnupg-9d83bfb639680d3bc756fcfe2b7f83b18bed8dff.zip
scd: Fix possible PC/SC removed card problem
* scd/apdu.c (pcsc_cancel): New. (pcsc_init): Load new function. (connect_pcsc_card): Use it after a removed card error. -- Backported-from-master: 8d81fd7c01e8dfacc719ff190f8e364014e32fdf
-rw-r--r--scd/apdu.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/scd/apdu.c b/scd/apdu.c
index ccb5c10b0..6d8d05418 100644
--- a/scd/apdu.c
+++ b/scd/apdu.c
@@ -298,6 +298,7 @@ long (* DLSTDCALL pcsc_establish_context) (pcsc_dword_t scope,
const void *reserved2,
long *r_context);
long (* DLSTDCALL pcsc_release_context) (long context);
+long (* DLSTDCALL pcsc_cancel) (long context);
long (* DLSTDCALL pcsc_list_readers) (long context,
const char *groups,
char *readers, pcsc_dword_t*readerslen);
@@ -840,6 +841,16 @@ connect_pcsc_card (int slot)
if (err != PCSC_E_NO_SMARTCARD)
log_error ("pcsc_connect failed: %s (0x%lx)\n",
pcsc_error_string (err), err);
+ if (err == PCSC_W_REMOVED_CARD && pcsc_cancel)
+ {
+ long err2;
+ err2 = pcsc_cancel (reader_table[slot].pcsc.context);
+ if (err2)
+ log_error ("pcsc_cancel failed: %s (0x%lx)\n",
+ pcsc_error_string (err2), err2);
+ else if (opt.verbose)
+ log_error ("pcsc_cancel succeeded\n");
+ }
}
else
{
@@ -1976,6 +1987,7 @@ apdu_open_one_reader (const char *portstr)
pcsc_establish_context = dlsym (handle, "SCardEstablishContext");
pcsc_release_context = dlsym (handle, "SCardReleaseContext");
+ pcsc_cancel = dlsym (handle, "SCardCancel");
pcsc_list_readers = dlsym (handle, "SCardListReaders");
#if defined(_WIN32) || defined(__CYGWIN__)
if (!pcsc_list_readers)