GNUPG-1-9-BRANCH gnupg (9 files)

cvs user wk cvs at cvs.gnupg.org
Sat May 21 20:29:01 CEST 2005


    Date: Saturday, May 21, 2005 @ 20:49:00
  Author: wk
    Path: /cvs/gnupg/gnupg
     Tag: GNUPG-1-9-BRANCH

Modified: NEWS TODO agent/ChangeLog agent/agent.h agent/call-scd.c
          agent/gpg-agent.c scd/ChangeLog scd/app-openpgp.c scd/scdaemon.c

* call-scd.c (start_scd): Don't test for an alive scdaemon here.
(agent_scd_check_aliveness): New.
* gpg-agent.c (handle_tick): Test for an alive scdaemon.
(handle_signal): Print thread info on SIGUSR1.

* scdaemon.c (handle_signal): Print thread info on SIGUSR1.


-------------------+
 NEWS              |    5 +++
 TODO              |   15 +++++++++
 agent/ChangeLog   |    7 ++++
 agent/agent.h     |    1 
 agent/call-scd.c  |   81 +++++++++++++++++++++++++++++++++++++---------------
 agent/gpg-agent.c |    8 ++++-
 scd/ChangeLog     |    4 ++
 scd/app-openpgp.c |    4 +-
 scd/scdaemon.c    |    3 +
 9 files changed, 102 insertions(+), 26 deletions(-)


Index: gnupg/NEWS
diff -u gnupg/NEWS:1.165.2.70 gnupg/NEWS:1.165.2.71
--- gnupg/NEWS:1.165.2.70	Wed May 18 12:48:06 2005
+++ gnupg/NEWS	Sat May 21 20:49:00 2005
@@ -1,6 +1,11 @@
 Noteworthy changes in version 1.9.17
 -------------------------------------------------
 
+ * gpg-connect-agent has now features to handle Assuan INQUIRE
+   commands.
+
+ * Internal changes for OpenPGP cards. New Assuan command WRITEKEY.
+
  * GNU Pth is now a hard requirement.
 
  * [scdaemon] Support for OpenSC has been removed.  Instead a new and
Index: gnupg/TODO
diff -u gnupg/TODO:1.165.2.41 gnupg/TODO:1.165.2.42
--- gnupg/TODO:1.165.2.41	Wed May 18 12:48:06 2005
+++ gnupg/TODO	Sat May 21 20:49:00 2005
@@ -67,6 +67,11 @@
 * sm/export.c
 ** Return an error code or a status info per user ID.
 
+* scd/tlv.c
+  The parse_sexp fucntion should not go into this file.  Check whether
+  we can change all S-expression handling code to make use of this
+  function.
+
 * tests
 ** Makefile.am
   We use printf(1) to setup the library path, this is not portable.
@@ -89,3 +94,13 @@
     This means we can't reread a configuration
 ** No card status notifications.
 
+
+
+* IMPORTANT:
+  Check that the PIN cache is cleared after failed card operations.
+  After receiving a HUP gpg-agent should set a flag to kill scdaemon
+  as soon as possible, w/o that scdaemon will continue running as a
+  zombie and gpg-agent won't be able to fire up a new one.
+  Implement an scd/agent option to wait for a card.
+
+
Index: gnupg/agent/ChangeLog
diff -u gnupg/agent/ChangeLog:1.59.2.79 gnupg/agent/ChangeLog:1.59.2.80
--- gnupg/agent/ChangeLog:1.59.2.79	Fri May 20 22:39:36 2005
+++ gnupg/agent/ChangeLog	Sat May 21 20:49:00 2005
@@ -1,3 +1,10 @@
+2005-05-21  Werner Koch  <wk at g10code.com>
+
+	* call-scd.c (start_scd): Don't test for an alive scdaemon here.
+	(agent_scd_check_aliveness): New.
+	* gpg-agent.c (handle_tick): Test for an alive scdaemon.
+	(handle_signal): Print thread info on SIGUSR1.
+
 2005-05-20  Werner Koch  <wk at g10code.com>
 
 	* protect-tool.c: New option --canonical.
Index: gnupg/agent/agent.h
diff -u gnupg/agent/agent.h:1.32.2.19 gnupg/agent/agent.h:1.32.2.20
--- gnupg/agent/agent.h:1.32.2.19	Wed May 18 12:48:06 2005
+++ gnupg/agent/agent.h	Sat May 21 20:49:00 2005
@@ -247,6 +247,7 @@
 
 /*-- call-scd.c --*/
 void initialize_module_call_scd (void);
+void agent_scd_check_aliveness (void);
 int agent_reset_scd (ctrl_t ctrl);
 int agent_card_learn (ctrl_t ctrl,
                       void (*kpinfo_cb)(void*, const char *),
Index: gnupg/agent/call-scd.c
diff -u gnupg/agent/call-scd.c:1.13.2.15 gnupg/agent/call-scd.c:1.13.2.16
--- gnupg/agent/call-scd.c:1.13.2.15	Fri May 20 22:39:36 2005
+++ gnupg/agent/call-scd.c	Sat May 21 20:49:00 2005
@@ -185,26 +185,15 @@
     }
   ctrl->scd_local->locked++;
 
-  /* If we already have a context, we better do a sanity check now to
-     see whether it has accidently died.  This avoids annoying
-     timeouts and hung connections. */
   if (ctrl->scd_local->ctx)
-    {
-      pid_t pid;
-#ifndef HAVE_W32_SYSTEM 
-      pid = assuan_get_pid (ctrl->scd_local->ctx);
-      if (pid != (pid_t)(-1) && pid
-          && ((rc=waitpid (pid, NULL, WNOHANG))==-1 || (rc == pid)) )
-        {
-          assuan_disconnect (ctrl->scd_local->ctx);
-          ctrl->scd_local->ctx = NULL;
-        }
-      else
-#endif
-        return 0; /* Okay, the context is fine. */
-    }
+    return 0; /* Okay, the context is fine.  We used to test for an
+                 alive context here and do an disconnect.  How that we
+                 have a ticker function to check for it, it is easier
+                 not to check here but to let the connection run on an
+                 error instead. */
 
-  /* We need to protect the lowwing code. */
+
+  /* We need to protect the following code. */
   if (!pth_mutex_acquire (&start_scd_lock, 0, NULL))
     {
       log_error ("failed to acquire the start_scd lock: %s\n",
@@ -350,6 +339,50 @@
 }
 
 
+/* Check whether the Scdaemon is still alive and clean it up if not. */
+void
+agent_scd_check_aliveness (void)
+{
+  pid_t pid;
+  int rc;
+
+  /* We can do so only if there is no more active primary connection.
+     With an active primary connection, this is all no problem because
+     with the end of gpg-agent's session a disconnect is send and the
+     this function will be used at a later time. */
+  if (!primary_scd_ctx || !primary_scd_ctx_reusable)
+    return;
+
+  if (!pth_mutex_acquire (&start_scd_lock, 0, NULL))
+    {
+      log_error ("failed to acquire the start_scd lock while"
+                 " doing an aliveness check: %s\n",
+                 strerror (errno));
+      return;
+    }
+
+  if (primary_scd_ctx && primary_scd_ctx_reusable)
+    {
+      pid = assuan_get_pid (primary_scd_ctx);
+      if (pid != (pid_t)(-1) && pid
+          && ((rc=waitpid (pid, NULL, WNOHANG))==-1 || (rc == pid)) )
+        {
+          /* Okay, scdaemon died.  Disconnect the primary connection now
+             but take care that it won't do another wait. */
+          assuan_set_flag (primary_scd_ctx, ASSUAN_NO_WAITPID, 1);
+          assuan_disconnect (primary_scd_ctx);
+          primary_scd_ctx = NULL;
+          primary_scd_ctx_reusable = 0;
+          xfree (socket_name);
+          socket_name = NULL;
+        }
+    }
+
+  if (!pth_mutex_release (&start_scd_lock))
+    log_error ("failed to release the start_scd lock while"
+               " doing the aliveness check: %s\n", strerror (errno));
+}
+
 
 /* Reset the SCD if it has been used. */
 int
@@ -359,15 +392,19 @@
     {
       if (ctrl->scd_local->ctx)
         {
-          /* We can't disconnect the primary context becuase libassuan
+          /* We can't disconnect the primary context because libassuan
              does a waitpid on it and thus the system would hang.
              Instead we send a reset and keep that connection for
              reuse. */
           if (ctrl->scd_local->ctx == primary_scd_ctx)
             {
-              if (!assuan_transact (primary_scd_ctx, "RESET",
-                                    NULL, NULL, NULL, NULL, NULL, NULL))
-                primary_scd_ctx_reusable = 1;
+              /* The RESET may fail for example if the scdaemon has
+                 already been terminated.  We need to set the reusable
+                 flag anyway to make sure that the aliveness check can
+                 clean it up. */
+              assuan_transact (primary_scd_ctx, "RESET",
+                               NULL, NULL, NULL, NULL, NULL, NULL);
+              primary_scd_ctx_reusable = 1;
             }
           else
             assuan_disconnect (ctrl->scd_local->ctx);
Index: gnupg/agent/gpg-agent.c
diff -u gnupg/agent/gpg-agent.c:1.31.2.37 gnupg/agent/gpg-agent.c:1.31.2.38
--- gnupg/agent/gpg-agent.c:1.31.2.37	Wed May 18 12:48:06 2005
+++ gnupg/agent/gpg-agent.c	Sat May 21 20:49:00 2005
@@ -1270,6 +1270,11 @@
 static void
 handle_tick (void)
 {
+  /* Check whether the scdaemon has dies and cleanup in this case. */
+  agent_scd_check_aliveness ();
+
+  /* If we are running as a child of another process, check whether
+     the parent is still alive and shutdwon if now. */
 #ifndef HAVE_W32_SYSTEM
   if (parent_pid != (pid_t)(-1))
     {
@@ -1301,7 +1306,8 @@
       break;
       
     case SIGUSR1:
-      log_info ("SIGUSR1 received - no action defined\n");
+      log_info ("SIGUSR1 received - printing internal information:\n");
+      pth_ctrl (PTH_CTRL_DUMPSTATE, log_get_stream ());
       break;
       
     case SIGUSR2:
Index: gnupg/scd/ChangeLog
diff -u gnupg/scd/ChangeLog:1.25.2.78 gnupg/scd/ChangeLog:1.25.2.79
--- gnupg/scd/ChangeLog:1.25.2.78	Fri May 20 22:39:36 2005
+++ gnupg/scd/ChangeLog	Sat May 21 20:49:00 2005
@@ -1,3 +1,7 @@
+2005-05-21  Werner Koch  <wk at g10code.com>
+
+	* scdaemon.c (handle_signal): Print thread info on SIGUSR1.
+
 2005-05-20  Werner Koch  <wk at g10code.com>
 
 	* ccid-driver.c: Replaced macro DEBUG_T1 by a new debug level.
Index: gnupg/scd/app-openpgp.c
diff -u gnupg/scd/app-openpgp.c:1.9.2.33 gnupg/scd/app-openpgp.c:1.9.2.34
--- gnupg/scd/app-openpgp.c:1.9.2.33	Fri May 20 22:39:35 2005
+++ gnupg/scd/app-openpgp.c	Sat May 21 20:49:00 2005
@@ -17,7 +17,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  *
- * $Id: app-openpgp.c,v 1.9.2.33 2005/05/20 20:39:35 wk Exp $
+ * $Id: app-openpgp.c,v 1.9.2.34 2005/05/21 18:49:00 wk Exp $
  */
 
 #include <config.h>
@@ -1634,7 +1634,7 @@
         log_info ("protected-private-key passed to writekey\n");
       else if (toklen == 20 && !memcmp ("shadowed-private-key", tok, toklen))
         log_info ("shadowed-private-key passed to writekey\n");
-      err = gpg_error (GPG_ERR_BAD_KEY);
+      err = gpg_error (GPG_ERR_BAD_SECKEY);
       goto leave;
     }
   if ((err = parse_sexp (&buf, &buflen, &depth, &tok, &toklen)))
Index: gnupg/scd/scdaemon.c
diff -u gnupg/scd/scdaemon.c:1.12.2.28 gnupg/scd/scdaemon.c:1.12.2.29
--- gnupg/scd/scdaemon.c:1.12.2.28	Fri May 20 22:39:35 2005
+++ gnupg/scd/scdaemon.c	Sat May 21 20:49:00 2005
@@ -807,7 +807,8 @@
       break;
       
     case SIGUSR1:
-      log_info ("SIGUSR1 received - no action defined\n");
+      log_info ("SIGUSR1 received - printing internal information:\n");
+      pth_ctrl (PTH_CTRL_DUMPSTATE, log_get_stream ());
       break;
 
     case SIGUSR2:




More information about the Gnupg-commits mailing list