1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

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
This commit is contained in:
Werner Koch 2021-05-04 10:38:53 +02:00
parent a475bb725b
commit 9d83bfb639
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B

View File

@ -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)