[git] GnuPG - branch, master, updated. gnupg-2.1.0beta1-49-g576de6e

by Werner Koch cvs at cvs.gnupg.org
Tue Jan 25 22:23:44 CET 2011


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU Privacy Guard".

The branch, master has been updated
       via  576de6e539646f021dafff8d4e3327c115a51ad4 (commit)
       via  ca2d3157656d542ceec50607d0b92f13542a0fe7 (commit)
      from  05a3f5639139c14d360da29141108a868fbc3071 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 576de6e539646f021dafff8d4e3327c115a51ad4
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Jan 25 22:03:16 2011 +0100

    Fixed problem with unplugging card readers.
    
    From Grant Olsons's mail to gnupg-devel@:
    
      This is three-quarters NIIBE and one-quarter me, but I though it would
      be easier to have a single complete patch that applies to
      STABLE-BRANCH-2-0 than two patches floating around.
    
      This is basically NIIBE Yatuka's patch here:
    
      http://lists.gnupg.org/pipermail/gnupg-devel/2010-November/025828.html
    
      Plus another check that closes down the reader explicitly if we get a
      SW_HOST_NO_READER error, so that an unplugged reader doesn't hold onto
      the first slot, preventing us from getting to the active plugged reader.

diff --git a/THANKS b/THANKS
index c86fda3..b6dfc40 100644
--- a/THANKS
+++ b/THANKS
@@ -92,6 +92,7 @@ Geoff Keating		   geoffk at ozemail.com.au
 Georg Schwarz              georg.schwarz at iname.com
 Giampaolo Tomassoni        g.tomassoni at libero.it
 Gilbert Fernandes          gilbert_fernandes at hotmail.com
+Grant Olson                kgo at grant-olson net
 Greg Louis		   glouis at dynamicro.on.ca
 Greg Troxel		   gdt at ir.bbn.com
 Gregory Steuck		   steuck at iname.com
diff --git a/scd/ChangeLog b/scd/ChangeLog
index d1e942a..c9f92b4 100644
--- a/scd/ChangeLog
+++ b/scd/ChangeLog
@@ -1,3 +1,10 @@
+2011-01-25  NIIBE Yutaka <gniibe at fsij.org>,
+	    Grant Olson <kgo at grant-olson.net>  (wk)
+
+	* command.c (do_reset, get_reader_slot)
+	(update_reader_status_file): Fix handling of the VALID flag for
+	unplugged readers.
+
 2011-01-25  Werner Koch  <wk at g10code.com>
 
 	From 2.0 branch, 2010-03-17:
diff --git a/scd/command.c b/scd/command.c
index 36aff97..a44378d 100644
--- a/scd/command.c
+++ b/scd/command.c
@@ -309,7 +309,7 @@ do_reset (ctrl_t ctrl, int send_reset)
     {
       if (apdu_reset (slot)) 
         {
-          slot_table[slot].reset_failed = 1;
+          slot_table[slot].valid = 0;
         }
       application_notify_card_reset (slot);
     }
@@ -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");
@@ -2190,6 +2198,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;
         }

commit ca2d3157656d542ceec50607d0b92f13542a0fe7
Author: Werner Koch <wk at gnupg.org>
Date:   Mon May 3 11:10:49 2010 +0000

    Detect non operational readers.
    
    Backport from 2.0.

diff --git a/scd/ChangeLog b/scd/ChangeLog
index 41a0f76..d1e942a 100644
--- a/scd/ChangeLog
+++ b/scd/ChangeLog
@@ -1,3 +1,16 @@
+2011-01-25  Werner Koch  <wk at g10code.com>
+
+	From 2.0 branch, 2010-03-17:
+
+	* command.c (open_card): Return GPG_ERR_NOT_OPERATIONAL if no
+	card services are available.
+	(get_reader_slot): Detect no services status.
+	(cmd_serialno): No reset if there are no services.
+	(scd_command_handler): Stop scdaemon in that case.
+	* apdu.c (pcsc_no_service): New.
+	(open_pcsc_reader_direct): Set it.
+	(apdu_open_reader): Add arg R_NO_SERVICE.
+
 2011-01-05  Werner Koch  <wk at g10code.com>
 
 	* ccid-driver.c (ccid_transceive_secure): Support the gnuk token.
diff --git a/scd/apdu.c b/scd/apdu.c
index 80c933e..dcb0e23 100644
--- a/scd/apdu.c
+++ b/scd/apdu.c
@@ -304,6 +304,9 @@ long (* DLSTDCALL pcsc_transmit) (unsigned long card,
 long (* DLSTDCALL pcsc_set_timeout) (unsigned long context,
                                      unsigned long timeout);
 
+/* Flag set if PC/SC returned the no-service error.  */
+static int pcsc_no_service;
+
 
 /*  Prototypes.  */
 static int pcsc_get_status (int slot, unsigned int *status);
@@ -1504,8 +1507,11 @@ open_pcsc_reader_direct (const char *portstr)
       log_error ("pcsc_establish_context failed: %s (0x%lx)\n",
                  pcsc_error_string (err), err);
       reader_table[slot].used = 0;
+      if (err == 0x8010001d)
+        pcsc_no_service = 1;
       return -1;
     }
+  pcsc_no_service = 0;
 
   err = pcsc_list_readers (reader_table[slot].pcsc.context,
                            NULL, NULL, &nreader);
@@ -2338,14 +2344,18 @@ unlock_slot (int slot)
    error. If PORTSTR is NULL we default to a suitable port (for ctAPI:
    the first USB reader.  For PC/SC the first listed reader). */
 int
-apdu_open_reader (const char *portstr)
+apdu_open_reader (const char *portstr, int *r_no_service)
 {
   static int pcsc_api_loaded, ct_api_loaded;
+  int slot;
+
+  if (r_no_service)
+    *r_no_service = 0;
 
 #ifdef HAVE_LIBUSB
   if (!opt.disable_ccid)
     {
-      int slot, i;
+      int i;
       const char *s;
 
       slot = open_ccid_reader (portstr);
@@ -2475,7 +2485,11 @@ apdu_open_reader (const char *portstr)
       pcsc_api_loaded = 1;
     }
 
-  return open_pcsc_reader (portstr);
+  slot = open_pcsc_reader (portstr);
+  if (slot == -1 && r_no_service && pcsc_no_service)
+    *r_no_service = 1;
+
+  return slot;
 }
 
 
diff --git a/scd/apdu.h b/scd/apdu.h
index c47dea8..d79f8b4 100644
--- a/scd/apdu.h
+++ b/scd/apdu.h
@@ -80,8 +80,8 @@ enum {
 #define APDU_CARD_ACTIVE   (4)    /* Card is active.  */
 
 
-/* Note , that apdu_open_reader returns no status word but -1 on error. */
-int apdu_open_reader (const char *portstr);
+/* Note, that apdu_open_reader returns no status word but -1 on error. */
+int apdu_open_reader (const char *portstr, int *r_no_service);
 int apdu_open_remote_reader (const char *portstr,
                              const unsigned char *cookie, size_t length,
                              int (*readfnc) (void *opaque,
diff --git a/scd/command.c b/scd/command.c
index fa1d46c..36aff97 100644
--- a/scd/command.c
+++ b/scd/command.c
@@ -70,6 +70,10 @@
       && (c)->reader_slot == locked_session->ctrl_backlink->reader_slot)
 
 
+/* Flag indicating that the reader has been disabled.  */
+static int reader_disabled;
+
+
 /* This structure is used to keep track of open readers (slots). */
 struct slot_status_s 
 {
@@ -394,7 +398,15 @@ get_reader_slot (void)
 
   /* Try to open the reader. */
   if (ss->slot == -1)
-    ss->slot = apdu_open_reader (opt.reader_port);
+    {
+      int no_service_flag;
+      ss->slot = apdu_open_reader (opt.reader_port, &no_service_flag);
+      if (no_service_flag)
+        {
+          log_info ("no card services - disabling scdaemon\n");
+          reader_disabled = 1;
+        }
+    }
 
   /* Return the slot_table index.  */
   return 0;
@@ -409,6 +421,9 @@ open_card (ctrl_t ctrl, const char *apptype)
   gpg_error_t err;
   int slot;
 
+  if (reader_disabled)
+    return gpg_error (GPG_ERR_NOT_OPERATIONAL);
+
   /* If we ever got a card not present error code, return that.  Only
      the SERIALNO command and a reset are able to clear from that
      state. */
@@ -441,7 +456,7 @@ open_card (ctrl_t ctrl, const char *apptype)
     slot = get_reader_slot ();
   ctrl->reader_slot = slot;
   if (slot == -1)
-    err = gpg_error (GPG_ERR_CARD);
+    err = gpg_error (reader_disabled? GPG_ERR_NOT_OPERATIONAL: GPG_ERR_CARD);
   else
     {
       /* Fixme: We should move the apdu_connect call to
@@ -495,7 +510,7 @@ cmd_serialno (assuan_context_t ctx, char *line)
   time_t stamp;
 
   /* Clear the remove flag so that the open_card is able to reread it.  */
-  if (ctrl->server_local->card_removed)
+  if (!reader_disabled && ctrl->server_local->card_removed)
     {
       if ( IS_LOCKED (ctrl) )
         return gpg_error (GPG_ERR_LOCKED);
@@ -1993,7 +2008,7 @@ scd_command_handler (ctrl_t ctrl, int fd)
           BUG ();
       sl->next_session = ctrl->server_local->next_session;
     }
-  stopme = ctrl->server_local->stopme;
+  stopme = ctrl->server_local->stopme || reader_disabled;
   xfree (ctrl->server_local);
   ctrl->server_local = NULL;
 
diff --git a/scd/sc-copykeys.c b/scd/sc-copykeys.c
index 615e4b2..b863b01 100644
--- a/scd/sc-copykeys.c
+++ b/scd/sc-copykeys.c
@@ -139,7 +139,7 @@ main (int argc, char **argv )
   if (argc != 1)
     usage (1);
 
-  slot = apdu_open_reader (reader_port);
+  slot = apdu_open_reader (reader_port, NULL);
   if (slot == -1)
     exit (1);
   if (apdu_connect (slot))

-----------------------------------------------------------------------

Summary of changes:
 THANKS            |    1 +
 scd/ChangeLog     |   20 ++++++++++++++++++++
 scd/apdu.c        |   20 +++++++++++++++++---
 scd/apdu.h        |    4 ++--
 scd/command.c     |   35 ++++++++++++++++++++++++++++++-----
 scd/sc-copykeys.c |    2 +-
 6 files changed, 71 insertions(+), 11 deletions(-)


hooks/post-receive
-- 
The GNU Privacy Guard
http://git.gnupg.org




More information about the Gnupg-commits mailing list