[svn] GnuPG - r4338 - in trunk: . agent doc

svn author wk cvs at cvs.gnupg.org
Tue Nov 14 15:53:43 CET 2006


Author: wk
Date: 2006-11-14 15:53:42 +0100 (Tue, 14 Nov 2006)
New Revision: 4338

Modified:
   trunk/TODO
   trunk/agent/ChangeLog
   trunk/agent/agent.h
   trunk/agent/command.c
   trunk/agent/findkey.c
   trunk/agent/gpg-agent.c
   trunk/agent/trustlist.c
   trunk/doc/gpg-agent.texi
Log:
New command GETEVENTCOUNTER.

* command.c (bump_key_eventcounter): New.
(bump_card_eventcounter): New.
(cmd_geteventcounter): New command.
* gpg-agent.c (handle_signal): Call bump_card_eventcounter.
* findkey.c (agent_write_private_key): Call bump_key_eventcounter.
* trustlist.c (agent_reload_trustlist): Ditto.


Modified: trunk/TODO
===================================================================
--- trunk/TODO	2006-11-14 10:23:21 UTC (rev 4337)
+++ trunk/TODO	2006-11-14 14:53:42 UTC (rev 4338)
@@ -35,6 +35,10 @@
 ** Remove the inter-module dependencies between gpgsm and keybox
 ** Add an source_of_key field
 
+* agent/
+** If we detect that a private key has been deleted
+   Bump the key event counter.
+
 * agent/command.c
 ** Make sure that secure memory is used where appropriate
 

Modified: trunk/agent/ChangeLog
===================================================================
--- trunk/agent/ChangeLog	2006-11-14 10:23:21 UTC (rev 4337)
+++ trunk/agent/ChangeLog	2006-11-14 14:53:42 UTC (rev 4338)
@@ -1,3 +1,12 @@
+2006-11-14  Werner Koch  <wk at g10code.com>
+
+	* command.c (bump_key_eventcounter): New.
+	(bump_card_eventcounter): New.
+	(cmd_geteventcounter): New command.
+	* gpg-agent.c (handle_signal): Call bump_card_eventcounter.
+	* findkey.c (agent_write_private_key): Call bump_key_eventcounter.
+	* trustlist.c (agent_reload_trustlist): Ditto.
+
 2006-11-09  Werner Koch  <wk at g10code.com>
 
 	* gpg-agent.c (main): In detached mode connect standard

Modified: trunk/agent/agent.h
===================================================================
--- trunk/agent/agent.h	2006-11-14 10:23:21 UTC (rev 4337)
+++ trunk/agent/agent.h	2006-11-14 14:53:42 UTC (rev 4338)
@@ -182,6 +182,8 @@
 
 /*-- command.c --*/
 gpg_error_t agent_write_status (ctrl_t ctrl, const char *keyword, ...);
+void bump_key_eventcounter (void);
+void bump_card_eventcounter (void);
 void start_command_handler (int, int);
 
 /*-- command-ssh.c --*/

Modified: trunk/agent/command.c
===================================================================
--- trunk/agent/command.c	2006-11-14 10:23:21 UTC (rev 4337)
+++ trunk/agent/command.c	2006-11-14 14:53:42 UTC (rev 4338)
@@ -73,8 +73,30 @@
 static struct putval_item_s *putval_list;
 
 
+
+/* To help polling clients, we keep tarck of the number of certain
+   events.  This structure keeps those counters.  The counters are
+   integers and there should be no problem if they are overflowing as
+   callers need to check only whether a counter changed.  The actual
+   values are not meaningful. */
+struct 
+{
+  /* Incremented if any of the other counters below changed. */
+  unsigned int any;
 
+  /* Incremented if a key is added or removed from the internal privat
+     key database. */
+  unsigned int key; 
 
+  /* Incremented if a change of the card readers stati has been
+     detected. */
+  unsigned int card;
+
+} eventcounter;
+
+
+
+
 
 /* Release the memory buffer MB but first wipe out the used memory. */
 static void
@@ -293,6 +315,62 @@
 
 
 
+/* GETEVENTCOUNTER
+
+   Return a a status line named EVENTCOUNTER with the current values
+   of all event counters.  The values are decimal numbers in the range
+   0 to UINT_MAX and wrapping around to 0.  The actual values should
+   not be relied upon, they shall only be used to detect a change.
+
+   The currently defined counters are:
+
+   ANY  - Incremented with any change of any of the other counters.
+   KEY  - Incremented for added or removed private keys.
+   CARD - Incremented for changes of the card readers stati.
+*/
+static int
+cmd_geteventcounter (assuan_context_t ctx, char *line)
+{
+  ctrl_t ctrl = assuan_get_pointer (ctx);
+  char any_counter[25];
+  char key_counter[25];
+  char card_counter[25];
+
+  snprintf (any_counter, sizeof any_counter, "%u", eventcounter.any);
+  snprintf (key_counter, sizeof key_counter, "%u", eventcounter.key);
+  snprintf (card_counter, sizeof card_counter, "%u", eventcounter.card);
+
+  return agent_write_status (ctrl, "EVENTCOUNTER",
+                             any_counter,
+                             key_counter,
+                             card_counter,
+                             NULL);
+}
+
+
+/* This function should be called once for all key removals or
+   additions.  Thus function is assured not to do any context
+   switches. */
+void
+bump_key_eventcounter (void)
+{
+  eventcounter.key++;
+  eventcounter.any++;
+}
+
+/* This function should be called for all card reader status
+   changes. Thus function is assured not to do any context
+   switches. */
+void
+bump_card_eventcounter (void)
+{
+  eventcounter.card++;
+  eventcounter.any++;
+}
+
+
+
+
 /* ISTRUSTED <hexstring_with_fingerprint>
 
    Return OK when we have an entry with this fingerprint in our
@@ -1281,6 +1359,7 @@
     const char *name;
     int (*handler)(assuan_context_t, char *line);
   } table[] = {
+    { "GETEVENTCOUNTER",cmd_geteventcounter },
     { "ISTRUSTED",      cmd_istrusted },
     { "HAVEKEY",        cmd_havekey },
     { "SIGKEY",         cmd_sigkey },

Modified: trunk/agent/findkey.c
===================================================================
--- trunk/agent/findkey.c	2006-11-14 10:23:21 UTC (rev 4337)
+++ trunk/agent/findkey.c	2006-11-14 14:53:42 UTC (rev 4338)
@@ -117,7 +117,7 @@
       xfree (fname);
       return tmperr;
     }
-
+  bump_key_eventcounter ();
   xfree (fname);
   return 0;
 }

Modified: trunk/agent/gpg-agent.c
===================================================================
--- trunk/agent/gpg-agent.c	2006-11-14 10:23:21 UTC (rev 4337)
+++ trunk/agent/gpg-agent.c	2006-11-14 14:53:42 UTC (rev 4338)
@@ -1400,6 +1400,8 @@
     case SIGUSR2:
       if (opt.verbose)
         log_info ("SIGUSR2 received - checking smartcard status\n");
+      /* Nothing to check right now.  We only increment a counter.  */
+      bump_card_eventcounter ();
       break;
 
     case SIGTERM:

Modified: trunk/agent/trustlist.c
===================================================================
--- trunk/agent/trustlist.c	2006-11-14 10:23:21 UTC (rev 4337)
+++ trunk/agent/trustlist.c	2006-11-14 14:53:42 UTC (rev 4338)
@@ -574,4 +574,5 @@
   trusttable = NULL;
   trusttablesize = 0;
   unlock_trusttable ();
+  bump_key_eventcounter ();
 }

Modified: trunk/doc/gpg-agent.texi
===================================================================
--- trunk/doc/gpg-agent.texi	2006-11-14 10:23:21 UTC (rev 4337)
+++ trunk/doc/gpg-agent.texi	2006-11-14 14:53:42 UTC (rev 4338)
@@ -657,6 +657,7 @@
 * Agent LEARN::           Register a smartcard
 * Agent PASSWD::          Change a Passphrase
 * Agent UPDATESTARTUPTTY:: Change the Standard Display
+* Agent GETEVENTCOUNTER:: Get the Event Counters
 @end menu
 
 @node Agent PKDECRYPT
@@ -1076,6 +1077,31 @@
 ssh-agent protocol to convey this information.
 
 
+ at node Agent GETEVENTCOUNTER
+ at subsection Get the Event Counters
+
+ at example
+  GETEVENTCOUNTER
+ at end example
+
+This function return one status line with the current values of the
+event counters.  The event counters are useful to avoid polling by
+delaying a poll until something has changed.  The values are decimal
+numbers in the range @code{0} to @code{UINT_MAX} and wrapping around to
+0.  The actual values should not be relied upon; they shall only be used
+to detect a change.
+
+The currently defined counters are are:
+ at table @code
+ at item ANY
+Incremented with any change of any of the other counters.
+ at item KEY
+Incremented for added or removed private keys.
+ at item CARD
+Incremented for changes of the card readers stati.
+ at end table
+
+
 @mansect see also
 @ifset isman
 @command{gpg2}(1), 




More information about the Gnupg-commits mailing list