[svn] GnuPG - r4488 - in trunk: . agent common kbx po scd sm tools

svn author wk cvs at cvs.gnupg.org
Fri Apr 20 18:59:40 CEST 2007


Author: wk
Date: 2007-04-20 18:59:37 +0200 (Fri, 20 Apr 2007)
New Revision: 4488

Modified:
   trunk/NEWS
   trunk/agent/ChangeLog
   trunk/agent/gpg-agent.c
   trunk/agent/protect-tool.c
   trunk/common/ChangeLog
   trunk/common/miscellaneous.c
   trunk/common/util.h
   trunk/kbx/kbxutil.c
   trunk/po/POTFILES.in
   trunk/scd/ChangeLog
   trunk/scd/sc-copykeys.c
   trunk/scd/scdaemon.c
   trunk/sm/ChangeLog
   trunk/sm/gpgsm.c
   trunk/tools/ChangeLog
   trunk/tools/symcryptrun.c
Log:
Improved logging for error orginating from libgcrypt.


Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2007-04-20 10:54:46 UTC (rev 4487)
+++ trunk/NEWS	2007-04-20 16:59:37 UTC (rev 4488)
@@ -7,7 +7,9 @@
  * PKCS#12 import now tries several encodings in case the passphrase
    was not utf-8 encoded.  New option --p12-charset for gpgsm.
 
+ * Improved the libgcrypt logging support in all modules.
 
+
 Noteworthy changes in version 2.0.3 (2007-03-08)
 ------------------------------------------------
 

Modified: trunk/agent/ChangeLog
===================================================================
--- trunk/agent/ChangeLog	2007-04-20 10:54:46 UTC (rev 4487)
+++ trunk/agent/ChangeLog	2007-04-20 16:59:37 UTC (rev 4488)
@@ -1,3 +1,10 @@
+2007-04-20  Werner Koch  <wk at g10code.com>
+
+	* gpg-agent.c (my_gcry_logger, my_gcry_outofcore_handler): Removed.
+	(main): Call the setup_libgcrypt_logging helper.
+	* protect-tool.c (my_gcry_logger): Removed.
+	(main): Call the setup_libgcrypt_logging helper.
+	
 2007-04-03  Werner Koch  <wk at g10code.com>
 
 	* trustlist.c (read_trustfiles): Take a missing trustlist as an

Modified: trunk/agent/gpg-agent.c
===================================================================
--- trunk/agent/gpg-agent.c	2007-04-20 10:54:46 UTC (rev 4487)
+++ trunk/agent/gpg-agent.c	2007-04-20 16:59:37 UTC (rev 4488)
@@ -276,48 +276,6 @@
 
 
 
-/* Used by gcry for logging */
-static void
-my_gcry_logger (void *dummy, int level, const char *fmt, va_list arg_ptr)
-{
-  /* translate the log levels */
-  switch (level)
-    {
-    case GCRY_LOG_CONT: level = JNLIB_LOG_CONT; break;
-    case GCRY_LOG_INFO: level = JNLIB_LOG_INFO; break;
-    case GCRY_LOG_WARN: level = JNLIB_LOG_WARN; break;
-    case GCRY_LOG_ERROR:level = JNLIB_LOG_ERROR; break;
-    case GCRY_LOG_FATAL:level = JNLIB_LOG_FATAL; break;
-    case GCRY_LOG_BUG:  level = JNLIB_LOG_BUG; break;
-    case GCRY_LOG_DEBUG:level = JNLIB_LOG_DEBUG; break;
-    default:            level = JNLIB_LOG_ERROR; break;  
-    }
-  log_logv (level, fmt, arg_ptr);
-}
-
-
-/* This function is called by libgcrypt if it ran out of core and
-   there is no way to return that error to the caller.  We do our own
-   function here to make use of our logging functions. */
-static int
-my_gcry_outofcore_handler ( void *opaque, size_t req_n, unsigned int flags)
-{
-  static int been_here;  /* Used to protect against recursive calls. */
-
-  if (!been_here)
-    {
-      been_here = 1;
-      if ( (flags & 1) )
-        log_fatal (_("out of core in secure memory "
-                     "while allocating %lu bytes"), (unsigned long)req_n);
-      else
-        log_fatal (_("out of core while allocating %lu bytes"),
-                   (unsigned long)req_n);
-    }
-  return 0; /* Let libgcrypt call its own fatal error handler. */
-}
-
-
 /* Setup the debugging.  With the global variable DEBUG_LEVEL set to NULL
    only the active debug flags are propagated to the subsystems.  With
    DEBUG_LEVEL set, a specific set of debug flags is set; thus overriding
@@ -518,7 +476,7 @@
      the option parsing may need services of the library. */
   if (!gcry_check_version (NEED_LIBGCRYPT_VERSION) )
     {
-      log_fatal( _("libgcrypt is too old (need %s, have %s)\n"),
+      log_fatal( _("%s is too old (need %s, have %s)\n"), "libgcrypt",
                  NEED_LIBGCRYPT_VERSION, gcry_check_version (NULL) );
     }
 
@@ -527,8 +485,7 @@
   assuan_set_assuan_log_prefix (log_get_prefix (NULL));
   assuan_set_assuan_err_source (GPG_ERR_SOURCE_DEFAULT);
 
-  gcry_set_log_handler (my_gcry_logger, NULL);
-  gcry_set_outofcore_handler (my_gcry_outofcore_handler, NULL);
+  setup_libgcrypt_logging ();
   gcry_control (GCRYCTL_USE_SECURE_RNDPOOL);
 
   may_coredump = disable_core_dumps ();

Modified: trunk/agent/protect-tool.c
===================================================================
--- trunk/agent/protect-tool.c	2007-04-20 10:54:46 UTC (rev 4487)
+++ trunk/agent/protect-tool.c	2007-04-20 16:59:37 UTC (rev 4488)
@@ -177,25 +177,6 @@
 
 
 
-/* Used by gcry for logging */
-static void
-my_gcry_logger (void *dummy, int level, const char *fmt, va_list arg_ptr)
-{
-  /* translate the log levels */
-  switch (level)
-    {
-    case GCRY_LOG_CONT: level = JNLIB_LOG_CONT; break;
-    case GCRY_LOG_INFO: level = JNLIB_LOG_INFO; break;
-    case GCRY_LOG_WARN: level = JNLIB_LOG_WARN; break;
-    case GCRY_LOG_ERROR:level = JNLIB_LOG_ERROR; break;
-    case GCRY_LOG_FATAL:level = JNLIB_LOG_FATAL; break;
-    case GCRY_LOG_BUG:  level = JNLIB_LOG_BUG; break;
-    case GCRY_LOG_DEBUG:level = JNLIB_LOG_DEBUG; break;
-    default:            level = JNLIB_LOG_ERROR; break;      }
-  log_logv (level, fmt, arg_ptr);
-}
-
-
 /*  static void */
 /*  print_mpi (const char *text, gcry_mpi_t a) */
 /*  { */
@@ -1075,12 +1056,11 @@
 
   if (!gcry_check_version (NEED_LIBGCRYPT_VERSION) )
     {
-      log_fatal( _("libgcrypt is too old (need %s, have %s)\n"),
+      log_fatal( _("%s is too old (need %s, have %s)\n"), "libgcrypt",
                  NEED_LIBGCRYPT_VERSION, gcry_check_version (NULL) );
     }
 
-  gcry_set_log_handler (my_gcry_logger, NULL);
-  
+  setup_libgcrypt_logging ();
   gcry_control (GCRYCTL_INIT_SECMEM, 16384, 0);
 
 

Modified: trunk/common/ChangeLog
===================================================================
--- trunk/common/ChangeLog	2007-04-20 10:54:46 UTC (rev 4487)
+++ trunk/common/ChangeLog	2007-04-20 16:59:37 UTC (rev 4488)
@@ -1,3 +1,10 @@
+2007-04-20  Werner Koch  <wk at g10code.com>
+
+	* miscellaneous.c (my_gcry_logger, my_gcry_outofcore_handler):
+	Moved from gpg-agent to here.
+	(my_gcry_fatalerror_handler): new.
+	(setup_libgcrypt_logging): New.
+
 2007-03-19  Werner Koch  <wk at g10code.com>
 
 	* miscellaneous.c (print_hexstring): New.

Modified: trunk/common/miscellaneous.c
===================================================================
--- trunk/common/miscellaneous.c	2007-04-20 10:54:46 UTC (rev 4487)
+++ trunk/common/miscellaneous.c	2007-04-20 16:59:37 UTC (rev 4488)
@@ -23,10 +23,77 @@
 #include <stdlib.h>
 #include <errno.h>
 
+#define JNLIB_NEED_LOG_LOGV
 #include "util.h"
 #include "iobuf.h"
+#include "i18n.h"
 
 
+/* Used by libgcrypt for logging.  */
+static void
+my_gcry_logger (void *dummy, int level, const char *fmt, va_list arg_ptr)
+{
+  /* Map the log levels.  */
+  switch (level)
+    {
+    case GCRY_LOG_CONT: level = JNLIB_LOG_CONT; break;
+    case GCRY_LOG_INFO: level = JNLIB_LOG_INFO; break;
+    case GCRY_LOG_WARN: level = JNLIB_LOG_WARN; break;
+    case GCRY_LOG_ERROR:level = JNLIB_LOG_ERROR; break;
+    case GCRY_LOG_FATAL:level = JNLIB_LOG_FATAL; break;
+    case GCRY_LOG_BUG:  level = JNLIB_LOG_BUG; break;
+    case GCRY_LOG_DEBUG:level = JNLIB_LOG_DEBUG; break;
+    default:            level = JNLIB_LOG_ERROR; break;  
+    }
+  log_logv (level, fmt, arg_ptr);
+}
+
+
+/* This function is called by libgcrypt on a fatal error.  */
+static void
+my_gcry_fatalerror_handler (void *opaque, int rc, const char *text)
+{
+  log_fatal ("libgcrypt problem: %s\n", text ? text : gpg_strerror (rc));
+  abort ();
+}
+
+
+/* This function is called by libgcrypt if it ran out of core and
+   there is no way to return that error to the caller.  We do our own
+   function here to make use of our logging functions. */
+static int
+my_gcry_outofcore_handler (void *opaque, size_t req_n, unsigned int flags)
+{
+  static int been_here;  /* Used to protect against recursive calls. */
+
+  if (!been_here)
+    {
+      been_here = 1;
+      if ( (flags & 1) )
+        log_fatal (_("out of core in secure memory "
+                     "while allocating %lu bytes"), (unsigned long)req_n);
+      else
+        log_fatal (_("out of core while allocating %lu bytes"),
+                   (unsigned long)req_n);
+    }
+  return 0; /* Let libgcrypt call its own fatal error handler.
+               Actually this will turn out to be
+               my_gcry_fatalerror_handler. */
+}
+
+
+/* Setup libgcrypt to use our own logging functions.  Should be used
+   early at startup. */
+void
+setup_libgcrypt_logging (void)
+{
+  gcry_set_log_handler (my_gcry_logger, NULL);
+  gcry_set_fatalerror_handler (my_gcry_fatalerror_handler, NULL);
+  gcry_set_outofcore_handler (my_gcry_outofcore_handler, NULL);
+}
+
+
+
 /* Decide whether the filename is stdout or a real filename and return
  * an appropriate string.  */
 const char *

Modified: trunk/common/util.h
===================================================================
--- trunk/common/util.h	2007-04-20 10:54:46 UTC (rev 4487)
+++ trunk/common/util.h	2007-04-20 16:59:37 UTC (rev 4488)
@@ -171,6 +171,10 @@
 
 /*-- miscellaneous.c --*/
 
+/* This function is called at startup to tell libgcrypt to use our own
+   logging subsystem. */
+void setup_libgcrypt_logging (void);
+
 /* Same as asprintf but return an allocated buffer suitable to be
    freed using xfree.  This function simply dies on memory failure,
    thus no extra check is required. */

Modified: trunk/kbx/kbxutil.c
===================================================================
--- trunk/kbx/kbxutil.c	2007-04-20 10:54:46 UTC (rev 4487)
+++ trunk/kbx/kbxutil.c	2007-04-20 16:59:37 UTC (rev 4488)
@@ -429,7 +429,7 @@
      the option parsing may need services of the library.  */
   if (!gcry_check_version (NEED_LIBGCRYPT_VERSION) )
     {
-      log_fatal( _("libgcrypt is too old (need %s, have %s)\n"),
+      log_fatal (_("%s is too old (need %s, have %s)\n"), "libgcrypt",
                  NEED_LIBGCRYPT_VERSION, gcry_check_version (NULL) );
     }
 

Modified: trunk/po/POTFILES.in
===================================================================
--- trunk/po/POTFILES.in	2007-04-20 10:54:46 UTC (rev 4487)
+++ trunk/po/POTFILES.in	2007-04-20 16:59:37 UTC (rev 4488)
@@ -14,6 +14,7 @@
 common/simple-pwquery.c
 common/sysutils.c
 common/yesno.c
+common/miscellaneous.c
 
 g10/armor.c
 g10/build-packet.c

Modified: trunk/scd/ChangeLog
===================================================================
--- trunk/scd/ChangeLog	2007-04-20 10:54:46 UTC (rev 4487)
+++ trunk/scd/ChangeLog	2007-04-20 16:59:37 UTC (rev 4488)
@@ -1,3 +1,10 @@
+2007-04-20  Werner Koch  <wk at g10code.com>
+
+	* sc-copykeys.c (my_gcry_logger): Removed.
+	(main): Call setup_libgcrypt_logging helper.
+	* scdaemon.c (my_gcry_logger): Removed.
+	(main): Call setup_libgcrypt_logging helper.
+
 2007-04-03  Werner Koch  <wk at g10code.com>
 
 	* command.c (cmd_getinfo): New subcommand "reader_list".

Modified: trunk/scd/sc-copykeys.c
===================================================================
--- trunk/scd/sc-copykeys.c	2007-04-20 10:54:46 UTC (rev 4487)
+++ trunk/scd/sc-copykeys.c	2007-04-20 16:59:37 UTC (rev 4488)
@@ -93,26 +93,7 @@
   return p;
 }
 
-/* Used by gcry for logging */
-static void
-my_gcry_logger (void *dummy, int level, const char *fmt, va_list arg_ptr)
-{
-  /* translate the log levels */
-  switch (level)
-    {
-    case GCRY_LOG_CONT: level = JNLIB_LOG_CONT; break;
-    case GCRY_LOG_INFO: level = JNLIB_LOG_INFO; break;
-    case GCRY_LOG_WARN: level = JNLIB_LOG_WARN; break;
-    case GCRY_LOG_ERROR:level = JNLIB_LOG_ERROR; break;
-    case GCRY_LOG_FATAL:level = JNLIB_LOG_FATAL; break;
-    case GCRY_LOG_BUG:  level = JNLIB_LOG_BUG; break;
-    case GCRY_LOG_DEBUG:level = JNLIB_LOG_DEBUG; break;
-    default:            level = JNLIB_LOG_ERROR; break;  
-    }
-  log_logv (level, fmt, arg_ptr);
-}
 
-
 int
 main (int argc, char **argv )
 {
@@ -131,11 +112,11 @@
      the option parsing may need services of the library */
   if (!gcry_check_version (NEED_LIBGCRYPT_VERSION) )
     {
-      log_fatal( _("libgcrypt is too old (need %s, have %s)\n"),
+      log_fatal (_("%s is too old (need %s, have %s)\n"), "libgcrypt",
                  NEED_LIBGCRYPT_VERSION, gcry_check_version (NULL) );
     }
 
-  gcry_set_log_handler (my_gcry_logger, NULL);
+  setup_libgcrypt_logging ();
   gcry_control (GCRYCTL_DISABLE_SECMEM, 0); /* FIXME - we want to use it */
   /* FIXME? gcry_control (GCRYCTL_USE_SECURE_RNDPOOL);*/
 

Modified: trunk/scd/scdaemon.c
===================================================================
--- trunk/scd/scdaemon.c	2007-04-20 10:54:46 UTC (rev 4487)
+++ trunk/scd/scdaemon.c	2007-04-20 16:59:37 UTC (rev 4488)
@@ -221,26 +221,7 @@
 
 
 
-/* Used by gcry for logging */
-static void
-my_gcry_logger (void *dummy, int level, const char *fmt, va_list arg_ptr)
-{
-  /* translate the log levels */
-  switch (level)
-    {
-    case GCRY_LOG_CONT: level = JNLIB_LOG_CONT; break;
-    case GCRY_LOG_INFO: level = JNLIB_LOG_INFO; break;
-    case GCRY_LOG_WARN: level = JNLIB_LOG_WARN; break;
-    case GCRY_LOG_ERROR:level = JNLIB_LOG_ERROR; break;
-    case GCRY_LOG_FATAL:level = JNLIB_LOG_FATAL; break;
-    case GCRY_LOG_BUG:  level = JNLIB_LOG_BUG; break;
-    case GCRY_LOG_DEBUG:level = JNLIB_LOG_DEBUG; break;
-    default:            level = JNLIB_LOG_ERROR; break;  
-    }
-  log_logv (level, fmt, arg_ptr);
-}
 
-
 /* Setup the debugging.  With a LEVEL of NULL only the active debug
    flags are propagated to the subsystems.  With LEVEL set, a specific
    set of debug flags is set; thus overriding all flags already
@@ -355,7 +336,7 @@
      the option parsing may need services of the library */
   if (!gcry_check_version (NEED_LIBGCRYPT_VERSION) )
     {
-      log_fatal( _("libgcrypt is too old (need %s, have %s)\n"),
+      log_fatal (_("%s is too old (need %s, have %s)\n"), "libgcrypt",
                  NEED_LIBGCRYPT_VERSION, gcry_check_version (NULL) );
     }
 
@@ -366,8 +347,7 @@
   assuan_set_assuan_log_prefix (log_get_prefix (NULL));
   assuan_set_assuan_err_source (GPG_ERR_SOURCE_DEFAULT);
 
-
-  gcry_set_log_handler (my_gcry_logger, NULL);
+  setup_libgcrypt_logging ();
   gcry_control (GCRYCTL_USE_SECURE_RNDPOOL);
 
   may_coredump = disable_core_dumps ();

Modified: trunk/sm/ChangeLog
===================================================================
--- trunk/sm/ChangeLog	2007-04-20 10:54:46 UTC (rev 4487)
+++ trunk/sm/ChangeLog	2007-04-20 16:59:37 UTC (rev 4488)
@@ -1,3 +1,7 @@
+2007-04-20  Werner Koch  <wk at g10code.com>
+
+	* gpgsm.c (main): Parameterize failed versions check messages.
+
 2007-04-19  Werner Koch  <wk at g10code.com>
 
 	* certcheck.c (do_encode_md): Add arg PKEY.  Add support for DSA2

Modified: trunk/sm/gpgsm.c
===================================================================
--- trunk/sm/gpgsm.c	2007-04-20 10:54:46 UTC (rev 4487)
+++ trunk/sm/gpgsm.c	2007-04-20 16:59:37 UTC (rev 4488)
@@ -768,15 +768,11 @@
   /* Check that the libraries are suitable.  Do it here because the
      option parse may need services of the library */
   if (!gcry_check_version (NEED_LIBGCRYPT_VERSION) )
-    {
-      log_fatal( _("libgcrypt is too old (need %s, have %s)\n"),
-                 NEED_LIBGCRYPT_VERSION, gcry_check_version (NULL) );
-    }
+    log_fatal (_("%s is too old (need %s, have %s)\n"), "libgcrypt", 
+               NEED_LIBGCRYPT_VERSION, gcry_check_version (NULL) );
   if (!ksba_check_version (NEED_KSBA_VERSION) )
-    {
-      log_fatal( _("libksba is too old (need %s, have %s)\n"),
-                 NEED_KSBA_VERSION, ksba_check_version (NULL) );
-    }
+    log_fatal (_("%s is too old (need %s, have %s)\n"), "libksba",
+               NEED_KSBA_VERSION, ksba_check_version (NULL) );
 
 
   gcry_control (GCRYCTL_USE_SECURE_RNDPOOL);

Modified: trunk/tools/ChangeLog
===================================================================
--- trunk/tools/ChangeLog	2007-04-20 10:54:46 UTC (rev 4487)
+++ trunk/tools/ChangeLog	2007-04-20 16:59:37 UTC (rev 4488)
@@ -1,3 +1,8 @@
+2007-04-20  Werner Koch  <wk at g10code.com>
+
+	* symcryptrun.c (my_gcry_logger): Removed.
+	(main): Call setup_libgcrypt_logging.
+
 2007-04-03  Werner Koch  <wk at g10code.com>
 
 	* gpgconf-comp.c: Allow changing of --allow-mark-trusted.

Modified: trunk/tools/symcryptrun.c
===================================================================
--- trunk/tools/symcryptrun.c	2007-04-20 10:54:46 UTC (rev 4487)
+++ trunk/tools/symcryptrun.c	2007-04-20 16:59:37 UTC (rev 4488)
@@ -96,25 +96,6 @@
 #include "../common/simple-pwquery.h"
 
 
-/* Used by gcry for logging */
-static void
-my_gcry_logger (void *dummy, int level, const char *fmt, va_list arg_ptr)
-{
-  /* translate the log levels */
-  switch (level)
-    {
-    case GCRY_LOG_CONT: level = JNLIB_LOG_CONT; break;
-    case GCRY_LOG_INFO: level = JNLIB_LOG_INFO; break;
-    case GCRY_LOG_WARN: level = JNLIB_LOG_WARN; break;
-    case GCRY_LOG_ERROR:level = JNLIB_LOG_ERROR; break;
-    case GCRY_LOG_FATAL:level = JNLIB_LOG_FATAL; break;
-    case GCRY_LOG_BUG:  level = JNLIB_LOG_BUG; break;
-    case GCRY_LOG_DEBUG:level = JNLIB_LOG_DEBUG; break;
-    default:            level = JNLIB_LOG_ERROR; break;      }
-  log_logv (level, fmt, arg_ptr);
-}
-
-
 /* From simple-gettext.c.  */
 
 /* We assume to have `unsigned long int' value with at least 32 bits.  */
@@ -1053,10 +1034,10 @@
   gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN);
   if (!gcry_check_version (NEED_LIBGCRYPT_VERSION) )
     {
-      log_fatal( _("libgcrypt is too old (need %s, have %s)\n"),
+      log_fatal (_("%s is too old (need %s, have %s)\n"), "libgcrypt",
                  NEED_LIBGCRYPT_VERSION, gcry_check_version (NULL) );
     }
-  gcry_set_log_handler (my_gcry_logger, NULL);
+  setup_libgcrypt_logging ();
   gcry_control (GCRYCTL_INIT_SECMEM, 16384, 0);
 
   if (!opt.class)




More information about the Gnupg-commits mailing list