summaryrefslogtreecommitdiffstats
path: root/scd
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2015-04-30 05:36:38 +0200
committerNIIBE Yutaka <gniibe@fsij.org>2015-04-30 05:36:38 +0200
commit01a2a61bc4b34817c4216888265f65d59a33dad3 (patch)
tree87b10f3e2d8b37e1af31b7284f48cbe6b6d65e5a /scd
parentcommon: Remove JNLIB from boiler plate (jnlib merge). (diff)
downloadgnupg2-01a2a61bc4b34817c4216888265f65d59a33dad3.tar.xz
gnupg2-01a2a61bc4b34817c4216888265f65d59a33dad3.zip
scd: PC/SC reader selection by partial string match.
* scd/apdu.c (open_pcsc_reader_direct): Partial string match. -- 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. Note that we need to change pcsc-wrapper.c in 2.0 backport. GnuPG-bug-id: 1618, 1930
Diffstat (limited to 'scd')
-rw-r--r--scd/apdu.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/scd/apdu.c b/scd/apdu.c
index f6cca8c7b..189fd4afa 100644
--- a/scd/apdu.c
+++ b/scd/apdu.c
@@ -1911,6 +1911,7 @@ open_pcsc_reader_direct (const char *portstr)
long err;
int slot;
char *list = NULL;
+ char *rdrname = NULL;
pcsc_dword_t nreader;
char *p;
@@ -1963,18 +1964,22 @@ open_pcsc_reader_direct (const char *portstr)
{
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");
@@ -1983,7 +1988,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;