Fixes unreleased locks with pcsc-lite

This is a bug in PCSC-Lite propably won't be fixed, see
https://alioth.debian.org/tracker/index.php?func=detail&aid=315083&group_id=30105&atid=410088

Fixes https://github.com/OpenSC/OpenSC/issues/480
Closes https://github.com/OpenSC/OpenSC/pull/487
This commit is contained in:
Frank Morgner 2015-10-03 12:48:56 +02:00
parent 5e242c5fb2
commit ac65af0669
2 changed files with 10 additions and 3 deletions

View File

@ -576,6 +576,7 @@ if test "${enable_pcsc}" = "yes"; then
CFLAGS="${CFLAGS} ${PCSC_CFLAGS}"
# We must cope with mingw32 that does not have winscard.h mingw64 has it.
AC_CHECK_HEADERS([winscard.h],,[test "${WIN32}" != "yes" && AC_MSG_ERROR([winscard.h is required for pcsc])])
AC_CHECK_HEADERS([pcsclite.h])
CFLAGS="${saved_CFLAGS}"
if test "${with_pcsc_provider}" = "detect"; then

View File

@ -431,8 +431,10 @@ static int pcsc_reconnect(sc_reader_t * reader, DWORD action)
if (check_forced_protocol(reader->ctx, &reader->atr, &tmp))
protocol = tmp;
/* reconnect always unlocks transaction */
#ifndef HAVE_PCSCLITE_H
/* reconnect unlocks transaction everywhere but in PCSC-lite */
priv->locked = 0;
#endif
rv = priv->gpriv->SCardReconnect(priv->pcsc_card,
priv->gpriv->connect_exclusive ? SCARD_SHARE_EXCLUSIVE : SCARD_SHARE_SHARED,
@ -588,17 +590,21 @@ static int pcsc_release(sc_reader_t *reader)
static int pcsc_reset(sc_reader_t *reader, int do_cold_reset)
{
struct pcsc_private_data *priv = GET_PRIV_DATA(reader);
int r;
#ifndef HAVE_PCSCLITE_H
struct pcsc_private_data *priv = GET_PRIV_DATA(reader);
int old_locked = priv->locked;
#endif
r = pcsc_reconnect(reader, do_cold_reset ? SCARD_UNPOWER_CARD : SCARD_RESET_CARD);
if(r != SC_SUCCESS)
return r;
/* pcsc_reconnect unlocks card... try to lock it again if it was locked */
#ifndef HAVE_PCSCLITE_H
/* reconnect unlocks transaction everywhere but in PCSC-lite */
if(old_locked)
r = pcsc_lock(reader);
#endif
return r;
}