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:
parent
43429c7869
commit
3f9f33bbcb
15
scd/apdu.c
15
scd/apdu.c
@ -1870,7 +1870,8 @@ open_pcsc_reader_direct (const char *portstr)
|
|||||||
long err;
|
long err;
|
||||||
int slot;
|
int slot;
|
||||||
char *list = NULL;
|
char *list = NULL;
|
||||||
pcsc_dword_t nreader, listlen;
|
char *rdrname = NULL;
|
||||||
|
pcsc_dword_t nreader;
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
slot = new_reader_slot ();
|
slot = new_reader_slot ();
|
||||||
@ -1917,24 +1918,27 @@ open_pcsc_reader_direct (const char *portstr)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
listlen = nreader;
|
|
||||||
p = list;
|
p = list;
|
||||||
while (nreader)
|
while (nreader)
|
||||||
{
|
{
|
||||||
if (!*p && !p[1])
|
if (!*p && !p[1])
|
||||||
break;
|
break;
|
||||||
if (*p)
|
log_info ("detected reader `%s'\n", p);
|
||||||
log_info ("detected reader `%s'\n", p);
|
|
||||||
if (nreader < (strlen (p)+1))
|
if (nreader < (strlen (p)+1))
|
||||||
{
|
{
|
||||||
log_error ("invalid response from pcsc_list_readers\n");
|
log_error ("invalid response from pcsc_list_readers\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (!rdrname && portstr && !strncmp (p, portstr, strlen (portstr)))
|
||||||
|
rdrname = p;
|
||||||
nreader -= strlen (p)+1;
|
nreader -= strlen (p)+1;
|
||||||
p += 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)
|
if (!reader_table[slot].rdrname)
|
||||||
{
|
{
|
||||||
log_error ("error allocating memory for reader name\n");
|
log_error ("error allocating memory for reader name\n");
|
||||||
@ -1943,7 +1947,6 @@ open_pcsc_reader_direct (const char *portstr)
|
|||||||
unlock_slot (slot);
|
unlock_slot (slot);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
strcpy (reader_table[slot].rdrname, portstr? portstr : list);
|
|
||||||
xfree (list);
|
xfree (list);
|
||||||
list = NULL;
|
list = NULL;
|
||||||
|
|
||||||
|
@ -406,8 +406,9 @@ static void
|
|||||||
handle_open (unsigned char *argbuf, size_t arglen)
|
handle_open (unsigned char *argbuf, size_t arglen)
|
||||||
{
|
{
|
||||||
long err;
|
long err;
|
||||||
const char * portstr;
|
const char *portstr;
|
||||||
char *list = NULL;
|
char *list = NULL;
|
||||||
|
char *rdrname = NULL;
|
||||||
pcsc_dword_t nreader, atrlen;
|
pcsc_dword_t nreader, atrlen;
|
||||||
char *p;
|
char *p;
|
||||||
pcsc_dword_t card_state, card_protocol;
|
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 */
|
/* Make sure there is only the port string */
|
||||||
if (arglen != strlen ((char*)argbuf))
|
if (arglen != strlen ((char*)argbuf))
|
||||||
bad_request ("OPEN");
|
bad_request ("OPEN");
|
||||||
portstr = (char*)argbuf;
|
if (arglen == 0)
|
||||||
|
portstr = NULL;
|
||||||
|
else
|
||||||
|
portstr = (char*)argbuf;
|
||||||
|
|
||||||
if (driver_is_open)
|
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");
|
fprintf (stderr, PGM": invalid response from pcsc_list_readers\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (!rdrname && portstr && !strncmp (p, portstr, strlen (portstr)))
|
||||||
|
rdrname = p;
|
||||||
nreader -= strlen (p)+1;
|
nreader -= strlen (p)+1;
|
||||||
p += 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)
|
if (!current_rdrname)
|
||||||
{
|
{
|
||||||
fprintf (stderr, PGM": error allocating memory for reader name\n");
|
fprintf (stderr, PGM": error allocating memory for reader name\n");
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
strcpy (current_rdrname, portstr && *portstr? portstr:list);
|
|
||||||
free (list);
|
free (list);
|
||||||
|
|
||||||
err = pcsc_connect (pcsc_context,
|
err = pcsc_connect (pcsc_context,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user