summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS2
-rw-r--r--agent/ChangeLog7
-rw-r--r--agent/gpg-agent.c47
-rw-r--r--agent/protect-tool.c24
-rw-r--r--common/ChangeLog7
-rw-r--r--common/miscellaneous.c67
-rw-r--r--common/util.h4
-rw-r--r--kbx/kbxutil.c2
-rw-r--r--po/POTFILES.in1
-rw-r--r--scd/ChangeLog7
-rw-r--r--scd/sc-copykeys.c23
-rw-r--r--scd/scdaemon.c24
-rw-r--r--sm/ChangeLog4
-rw-r--r--sm/gpgsm.c12
-rw-r--r--tools/ChangeLog5
-rw-r--r--tools/symcryptrun.c23
16 files changed, 119 insertions, 140 deletions
diff --git a/NEWS b/NEWS
index 59afa35ea..c05e165bd 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,8 @@ Noteworthy changes in version 2.0.4
* 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)
------------------------------------------------
diff --git a/agent/ChangeLog b/agent/ChangeLog
index aa48c1ebc..5d1ce5d52 100644
--- a/agent/ChangeLog
+++ b/agent/ChangeLog
@@ -1,3 +1,10 @@
+2007-04-20 Werner Koch <wk@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@g10code.com>
* trustlist.c (read_trustfiles): Take a missing trustlist as an
diff --git a/agent/gpg-agent.c b/agent/gpg-agent.c
index 5da308797..1d73dfcd6 100644
--- a/agent/gpg-agent.c
+++ b/agent/gpg-agent.c
@@ -276,48 +276,6 @@ i18n_init (void)
-/* 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 @@ main (int argc, char **argv )
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 @@ main (int argc, char **argv )
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 ();
diff --git a/agent/protect-tool.c b/agent/protect-tool.c
index 937b0ef0c..8496601b5 100644
--- a/agent/protect-tool.c
+++ b/agent/protect-tool.c
@@ -177,25 +177,6 @@ i18n_init (void)
-/* 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 @@ main (int argc, char **argv )
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);
diff --git a/common/ChangeLog b/common/ChangeLog
index e42bebfd4..ab4bec0a4 100644
--- a/common/ChangeLog
+++ b/common/ChangeLog
@@ -1,3 +1,10 @@
+2007-04-20 Werner Koch <wk@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@g10code.com>
* miscellaneous.c (print_hexstring): New.
diff --git a/common/miscellaneous.c b/common/miscellaneous.c
index 498c2ab60..fd1861083 100644
--- a/common/miscellaneous.c
+++ b/common/miscellaneous.c
@@ -23,8 +23,75 @@
#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
diff --git a/common/util.h b/common/util.h
index 2cf6e6cbe..1fc4d2a1e 100644
--- a/common/util.h
+++ b/common/util.h
@@ -171,6 +171,10 @@ void gnupg_rl_initialize (void);
/*-- 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. */
diff --git a/kbx/kbxutil.c b/kbx/kbxutil.c
index 73d10e348..809612f00 100644
--- a/kbx/kbxutil.c
+++ b/kbx/kbxutil.c
@@ -429,7 +429,7 @@ main( int argc, char **argv )
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) );
}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 2ee137fe9..c821a7a78 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -14,6 +14,7 @@ common/http.c
common/simple-pwquery.c
common/sysutils.c
common/yesno.c
+common/miscellaneous.c
g10/armor.c
g10/build-packet.c
diff --git a/scd/ChangeLog b/scd/ChangeLog
index 769ef0a14..c0141c74a 100644
--- a/scd/ChangeLog
+++ b/scd/ChangeLog
@@ -1,3 +1,10 @@
+2007-04-20 Werner Koch <wk@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@g10code.com>
* command.c (cmd_getinfo): New subcommand "reader_list".
diff --git a/scd/sc-copykeys.c b/scd/sc-copykeys.c
index acb3e2d2a..b18311f44 100644
--- a/scd/sc-copykeys.c
+++ b/scd/sc-copykeys.c
@@ -93,25 +93,6 @@ my_strusage (int level)
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 @@ main (int argc, char **argv )
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);*/
diff --git a/scd/scdaemon.c b/scd/scdaemon.c
index 19c656202..b87c0f3e5 100644
--- a/scd/scdaemon.c
+++ b/scd/scdaemon.c
@@ -221,25 +221,6 @@ i18n_init (void)
-/* 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
@@ -355,7 +336,7 @@ main (int argc, char **argv )
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 @@ main (int argc, char **argv )
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 ();
diff --git a/sm/ChangeLog b/sm/ChangeLog
index 20a1556d2..019cd7650 100644
--- a/sm/ChangeLog
+++ b/sm/ChangeLog
@@ -1,3 +1,7 @@
+2007-04-20 Werner Koch <wk@g10code.com>
+
+ * gpgsm.c (main): Parameterize failed versions check messages.
+
2007-04-19 Werner Koch <wk@g10code.com>
* certcheck.c (do_encode_md): Add arg PKEY. Add support for DSA2
diff --git a/sm/gpgsm.c b/sm/gpgsm.c
index 263632c6f..924286f8f 100644
--- a/sm/gpgsm.c
+++ b/sm/gpgsm.c
@@ -768,15 +768,11 @@ main ( int argc, char **argv)
/* 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);
diff --git a/tools/ChangeLog b/tools/ChangeLog
index 7621bae48..e112984d1 100644
--- a/tools/ChangeLog
+++ b/tools/ChangeLog
@@ -1,3 +1,8 @@
+2007-04-20 Werner Koch <wk@g10code.com>
+
+ * symcryptrun.c (my_gcry_logger): Removed.
+ (main): Call setup_libgcrypt_logging.
+
2007-04-03 Werner Koch <wk@g10code.com>
* gpgconf-comp.c: Allow changing of --allow-mark-trusted.
diff --git a/tools/symcryptrun.c b/tools/symcryptrun.c
index 30fe8a92d..b45e356a9 100644
--- a/tools/symcryptrun.c
+++ b/tools/symcryptrun.c
@@ -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 @@ main (int argc, char **argv)
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)