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

scd: PC/SC reader selection by partial string match.

* scd/apdu.c (open_pcsc_reader_direct): Partial string match.
* scd/pcsc-wrapper.c (handle_open): Likewise.

--

(backport from 2.1 commit 01a2a61bc4b34817c4216888265f65d59a33dad3)

The card reader name by PC/SC service might include USB bus,
which varies (on some platform like GNU/Linux).  Thus, it's
better to match partial string.

Original patch was submitted by anstein.  I changed it to fallback to
the first reader if no match found.

GnuPG-bug-id: 1618, 1930
This commit is contained in:
NIIBE Yutaka 2015-04-30 12:36:38 +09:00
parent 43429c7869
commit 3f9f33bbcb
2 changed files with 21 additions and 10 deletions

View File

@ -1870,7 +1870,8 @@ open_pcsc_reader_direct (const char *portstr)
long err;
int slot;
char *list = NULL;
pcsc_dword_t nreader, listlen;
char *rdrname = NULL;
pcsc_dword_t nreader;
char *p;
slot = new_reader_slot ();
@ -1917,24 +1918,27 @@ open_pcsc_reader_direct (const char *portstr)
return -1;
}
listlen = nreader;
p = list;
while (nreader)
{
if (!*p && !p[1])
break;
if (*p)
log_info ("detected reader `%s'\n", p);
log_info ("detected reader `%s'\n", p);
if (nreader < (strlen (p)+1))
{
log_error ("invalid response from pcsc_list_readers\n");
break;
}
if (!rdrname && portstr && !strncmp (p, portstr, strlen (portstr)))
rdrname = p;
nreader -= strlen (p)+1;
p += strlen (p) + 1;
}
reader_table[slot].rdrname = xtrymalloc (strlen (portstr? portstr : list)+1);
if (!rdrname)
rdrname = list;
reader_table[slot].rdrname = xtrystrdup (rdrname);
if (!reader_table[slot].rdrname)
{
log_error ("error allocating memory for reader name\n");
@ -1943,7 +1947,6 @@ open_pcsc_reader_direct (const char *portstr)
unlock_slot (slot);
return -1;
}
strcpy (reader_table[slot].rdrname, portstr? portstr : list);
xfree (list);
list = NULL;

View File

@ -406,8 +406,9 @@ static void
handle_open (unsigned char *argbuf, size_t arglen)
{
long err;
const char * portstr;
const char *portstr;
char *list = NULL;
char *rdrname = NULL;
pcsc_dword_t nreader, atrlen;
char *p;
pcsc_dword_t card_state, card_protocol;
@ -416,7 +417,10 @@ handle_open (unsigned char *argbuf, size_t arglen)
/* Make sure there is only the port string */
if (arglen != strlen ((char*)argbuf))
bad_request ("OPEN");
portstr = (char*)argbuf;
if (arglen == 0)
portstr = NULL;
else
portstr = (char*)argbuf;
if (driver_is_open)
{
@ -466,17 +470,21 @@ handle_open (unsigned char *argbuf, size_t arglen)
fprintf (stderr, PGM": invalid response from pcsc_list_readers\n");
break;
}
if (!rdrname && portstr && !strncmp (p, portstr, strlen (portstr)))
rdrname = p;
nreader -= strlen (p)+1;
p += strlen (p) + 1;
}
current_rdrname = malloc (strlen (portstr && *portstr? portstr:list)+1);
if (!rdrname)
rdrname = list;
current_rdrname = strdup (rdrname);
if (!current_rdrname)
{
fprintf (stderr, PGM": error allocating memory for reader name\n");
exit (1);
}
strcpy (current_rdrname, portstr && *portstr? portstr:list);
free (list);
err = pcsc_connect (pcsc_context,