Package: pcscd Version: 1.8.23-3 Severity: normal Hi,
Consider the following program: -----8<----- #include <stdio.h> #include <PCSC/winscard.h> #include <string.h> #include <unistd.h> int main(int argc, char**argv) { SCARDCONTEXT ctx; LPSTR readers; LPSTR ptr; LPSTR last; DWORD readerlen = SCARD_AUTOALLOCATE; int i = 0; SCARDHANDLE handle; DWORD active; SCardEstablishContext(SCARD_SCOPE_USER, NULL, NULL, &ctx); SCardListReaders(ctx, NULL, (LPSTR)&readers, &readerlen); ptr = readers; while(*ptr) { printf("Reader found: %s\n", ptr); last = ptr; ptr += strlen(ptr) + 1; i++; } if(*readers) { LONG r = SCardConnect(ctx, last, argc > 1 ? SCARD_SHARE_SHARED : SCARD_SHARE_EXCLUSIVE, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &handle, &active); printf("return value from SCardConnect(%s): ", argc > 1 ? "SCARD_SHARE_SHARED" : "SCARD_SHARE_EXCLUSIVE"); switch(r) { #define SRV(name) case SCARD_##name:printf("SCARD_%s\n", #name);break SRV(S_SUCCESS); SRV(E_INVALID_HANDLE); SRV(E_INVALID_PARAMETER); SRV(E_INVALID_VALUE); SRV(E_NO_SERVICE); SRV(E_NO_SMARTCARD); SRV(E_PROTO_MISMATCH); SRV(E_READER_UNAVAILABLE); SRV(E_SHARING_VIOLATION); SRV(E_UNKNOWN_READER); SRV(E_UNSUPPORTED_FEATURE); SRV(F_COMM_ERROR); SRV(F_INTERNAL_ERROR); SRV(W_UNPOWERED_CARD); default: printf("(unknown)"); } sleep(10); } return 0; } ----->8----- When run with a card in the last enumerated reader, the output of that program should be something along these lines: Reader found: Virtual PCD 00 00 Reader found: Virtual PCD 00 01 Reader found: O2 Micro Oz776 00 00 return value from SCardConnect(SCARD_SHARE_EXCLUSIVE): SCARD_S_SUCCESS and then when run from a second terminal while the first is still running: Reader found: Virtual PCD 00 00 Reader found: Virtual PCD 00 01 Reader found: O2 Micro Oz776 00 00 return value from SCardConnect(SCARD_SHARE_EXCLUSIVE): SCARD_E_SHARING_VIOLATION (the two "Virtual PCD" entries are generated by https://github.com/frankmorgner/vsmartcard) This behaviour does usually appear; but sometimes (I haven't figured out when, exactly) the behaviour is different. In that case, the following happens: - First instance: we get SCARD_S_SUCCESS, program sits for 10 seconds - Second instance: the program waits for 10 seconds on the first, then reports SCARD_S_SUCCESS as well While writing this program, I could reproduce it just fine. While trying to update the code so I could rule out the possibility that SCARD_E_SHARING_VIOLATION would only be returned if one program uses SCARD_SHARE_SHARED while the other uses SCARD_SHARE_EXCLUSIVE, however, I restarted pcscd a few times, which caused the problem to become unreproducible. While typing this bug report, I started firefox to look up the above URL, which caused the problem to reappear again; and then running the above test program caused it to go away again... I'm not sure where this is coming from, but would be happy to perform any required debugging steps. -- System Information: Debian Release: buster/sid APT prefers unstable-debug APT policy: (500, 'unstable-debug'), (500, 'unreleased'), (500, 'unstable'), (500, 'testing'), (500, 'stable'), (500, 'oldstable'), (1, 'experimental') Architecture: amd64 (x86_64) Foreign Architectures: i386, m68k, arm64 Kernel: Linux 4.17.0-1-amd64 (SMP w/8 CPU cores) Locale: LANG=nl_BE.UTF-8, LC_CTYPE=nl_BE.UTF-8 (charmap=UTF-8), LANGUAGE=nl_BE.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Init: systemd (via /run/systemd/system) LSM: AppArmor: enabled Versions of packages pcscd depends on: ii libacr38u [pcsc-ifd-handler] 1.7.11-1.1 ii libc6 2.27-5 ii libccid [pcsc-ifd-handler] 1.4.29-2 ii libpcsclite1 1.8.23-3 ii libsystemd0 239-7 ii libudev1 239-7 ii lsb-base 9.20170808 pcscd recommends no packages. Versions of packages pcscd suggests: ii systemd 239-7 -- no debconf information