[PATCH] scd: PC/SC reader selection by partial string match.
NIIBE Yutaka
gniibe at fsij.org
Thu Apr 30 05:50:34 CEST 2015
Hello,
I'm going to push following patch to GnuPG 2.1.x. This fix is
related to the issue 1618 and 1930.
https://bugs.gnupg.org/gnupg/issue1618
https://bugs.gnupg.org/gnupg/issue1930
For 1930, I put a patch for 2.0.x in the bug tracker, but I haven't
got response from the reporter. As I tested with GnuPG 2.1.x, this
patch is now for 2.1.x. I plan to backport to 2.0 (use the one in
issue1930), soon.
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 in 1930. 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.
It works for me with pcscd and libccid on GNU/Linux. The readers
are VASCO DIGIKEY 920 and Gnuk Token.
diff --git a/scd/apdu.c b/scd/apdu.c
index f6cca8c..189fd4a 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;
--
More information about the Gnupg-devel
mailing list