Patch for scdaemon and reader/smartcard combo devices

Grant Olson kgo at grant-olson.net
Fri Jan 21 02:09:35 CET 2011


On 01/20/2011 07:52 PM, NIIBE Yutaka wrote:
> The patch for scd/command.c couldn't be applied for me.
> 
> What branch are you working?  I have tried your patch to
> STABLE-BRANCH-2-0 and master, but it failed for both cases.
> 

First, thanks for testing this for me.  It's greatly appreciated.

I was working off of STABLE-BRANCH-2-0.  I did just try to re-apply the
patch, and it worked for me.  I'm going to try to attach the patch file
to this email, but I imagine the list server might strip the attachment,
so I'm CC'ing you directly as well.

Here's the transcript where I just re-applied the patch to
STABLE-BRANCH-2-0:

grant at johnsmallberries:~/src/gnupg$ ls 0*
0001-.gitignore.patch
0002-Fix-so-smartcard-reader-card-combos-don-t-break-scda.patch
grant at johnsmallberries:~/src/gnupg$ git status
# On branch scdaemon
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	0001-.gitignore.patch
#	0002-Fix-so-smartcard-reader-card-combos-don-t-break-scda.patch
#	agent/#call-scd.c#
#	agent/.#call-scd.c
#	bar.txt
#	bar.txt.gpg
nothing added to commit but untracked files present (use "git add" to track)
grant at johnsmallberries:~/src/gnupg$ git checkout STABLE-BRANCH-2-0
Switched to branch 'STABLE-BRANCH-2-0'
grant at johnsmallberries:~/src/gnupg$ git log -n1
commit 846d5744078bef2d781c0847cd5686f8c5016b40
Author: Werner Koch <wk at gnupg.org>
Date:   Thu Jan 13 17:04:47 2011 +0100

    Post release updates
grant at johnsmallberries:~/src/gnupg$ git checkout test-patch
error: pathspec 'test-patch' did not match any file(s) known to git.
grant at johnsmallberries:~/src/gnupg$ git checkout -b test-patch
Switched to a new branch 'test-patch'
grant at johnsmallberries:~/src/gnupg$ git log -n1
commit 846d5744078bef2d781c0847cd5686f8c5016b40
Author: Werner Koch <wk at gnupg.org>
Date:   Thu Jan 13 17:04:47 2011 +0100

    Post release updates
grant at johnsmallberries:~/src/gnupg$ git apply
0002-Fix-so-smartcard-reader-card-combos-don-t-break-scda.patch
0002-Fix-so-smartcard-reader-card-combos-don-t-break-scda.patch:57:
trailing whitespace.

warning: 1 line adds whitespace errors.
grant at johnsmallberries:~/src/gnupg$ ^C
grant at johnsmallberries:~/src/gnupg$ ^C
grant at johnsmallberries:~/src/gnupg$ git diff
diff --git a/scd/apdu.c b/scd/apdu.c
index 0fe044c..1bdc673 100644
--- a/scd/apdu.c
+++ b/scd/apdu.c
@@ -769,6 +769,7 @@ pcsc_error_to_sw (long ec)
     case PCSC_E_SHARING_VIOLATION:   rc = SW_HOST_LOCKING_FAILED; break;
     case PCSC_E_NO_SMARTCARD:        rc = SW_HOST_NO_CARD; break;
     case PCSC_W_REMOVED_CARD:        rc = SW_HOST_NO_CARD; break;
+    case PCSC_E_UNKNOWN_READER:      rc = SW_HOST_NO_READER; break;

     case PCSC_E_INVALID_TARGET:
     case PCSC_E_INVALID_VALUE:
@@ -1412,10 +1413,10 @@ reset_pcsc_reader_wrapped (int slot)
     {
       log_error ("PC/SC RESET failed: %s (0x%lx)\n",
                  pcsc_error_string (err), err);
-      /* If the error code is no smart card, we should not considere
+      /* If the error code is no smart card or no reader, we should not
conside
          this a major error and close the wrapper.  */
       sw = pcsc_error_to_sw (err);
-      if (err == PCSC_E_NO_SMARTCARD)
+      if (err == PCSC_E_NO_SMARTCARD || err == PCSC_E_UNKNOWN_READER)
         return sw;
       goto command_failed;
     }
diff --git a/scd/command.c b/scd/command.c
index e2cd1f5..d31d7af 100644
--- a/scd/command.c
+++ b/scd/command.c
@@ -401,6 +401,14 @@ get_reader_slot (void)
     {
       int no_service_flag;
       ss->slot = apdu_open_reader (opt.reader_port, &no_service_flag);
+
+      /* If we still don't have a slot, we have no readers.
+        Invalidate for now until a reader is attached. */
+      if(ss->slot == -1)
+       {
+         ss->valid = 0;
+       }
+
       if (no_service_flag)
         {
           log_info ("no card services - disabling scdaemon\n");
@@ -2192,6 +2200,8 @@ update_reader_status_file (int set_card_removed_flag)
       if (sw_apdu == SW_HOST_NO_READER)
         {
           /* Most likely the _reader_ has been unplugged.  */
+         apdu_close_reader(ss->slot);
+         ss->valid = 0;
           status = 0;
           changed = ss->changed;
         }
grant at johnsmallberries:~/src/gnupg$
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Fix-so-smartcard-reader-card-combos-don-t-break-scda.patch
Type: text/x-patch
Size: 2558 bytes
Desc: not available
URL: </pipermail/attachments/20110120/e302610f/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 565 bytes
Desc: OpenPGP digital signature
URL: </pipermail/attachments/20110120/e302610f/attachment.pgp>


More information about the Gnupg-devel mailing list