From 49829c29e541546084950b8a153067db371d101a Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Mon, 8 Aug 2016 18:40:03 -0400 Subject: [PATCH] Cleanup initialization of libgcrypt. * common/init.c (init_common_subsystems): Initialize libgcrypt. * dirmngr/Makefile.am (dirmngr_ldap): Link with libgcrypt. -- Most other modules already call gcry_check_version() after init_common_subsystems() so may as well move initialization of libgcrypt to here. Also fixes a warning in the system log from gpgconf --homedir. Signed-off-by: Ben Kibbey --- agent/gpg-agent.c | 8 -------- agent/protect-tool.c | 7 ------- common/init.c | 8 ++++++++ dirmngr/Makefile.am | 4 ++-- dirmngr/dirmngr.c | 4 ---- g10/gpg.c | 8 -------- g10/gpgv.c | 5 ----- g13/g13-syshelp.c | 5 ----- g13/g13.c | 5 ----- kbx/kbxutil.c | 8 -------- scd/scdaemon.c | 8 -------- sm/gpgsm.c | 3 --- tools/gpg-check-pattern.c | 7 ------- tools/symcryptrun.c | 5 ----- 14 files changed, 10 insertions(+), 75 deletions(-) diff --git a/agent/gpg-agent.c b/agent/gpg-agent.c index 8d6ecfc8e..b8a5a3e07 100644 --- a/agent/gpg-agent.c +++ b/agent/gpg-agent.c @@ -764,14 +764,6 @@ main (int argc, char **argv ) npth_init (); - /* Check that the libraries are suitable. Do it here because - the option parsing may need services of the library. */ - if (!gcry_check_version (NEED_LIBGCRYPT_VERSION) ) - { - log_fatal( _("%s is too old (need %s, have %s)\n"), "libgcrypt", - NEED_LIBGCRYPT_VERSION, gcry_check_version (NULL) ); - } - malloc_hooks.malloc = gcry_malloc; malloc_hooks.realloc = gcry_realloc; malloc_hooks.free = gcry_free; diff --git a/agent/protect-tool.c b/agent/protect-tool.c index c2bf87d4a..f41cc0b5f 100644 --- a/agent/protect-tool.c +++ b/agent/protect-tool.c @@ -566,16 +566,9 @@ main (int argc, char **argv ) i18n_init (); init_common_subsystems (&argc, &argv); - if (!gcry_check_version (NEED_LIBGCRYPT_VERSION) ) - { - log_fatal( _("%s is too old (need %s, have %s)\n"), "libgcrypt", - NEED_LIBGCRYPT_VERSION, gcry_check_version (NULL) ); - } - setup_libgcrypt_logging (); gcry_control (GCRYCTL_INIT_SECMEM, 16384, 0); - pargs.argc = &argc; pargs.argv = &argv; pargs.flags= 1; /* (do not remove the args) */ diff --git a/common/init.c b/common/init.c index c406ffe58..591c85468 100644 --- a/common/init.c +++ b/common/init.c @@ -47,7 +47,9 @@ # include /* For _assuan_w32ce_finish_pipe. */ #endif +#include #include "util.h" +#include "i18n.h" /* This object is used to register memory cleanup functions. Technically they are not needed but they can avoid frequent @@ -186,6 +188,12 @@ _init_common_subsystems (gpg_err_source_t errsource, int *argcp, char ***argvp) atexit (sleep_on_exit); #endif + if (!gcry_check_version (NEED_LIBGCRYPT_VERSION)) + { + log_fatal (_("%s is too old (need %s, have %s)\n"), "libgcrypt", + NEED_LIBGCRYPT_VERSION, gcry_check_version (NULL)); + } + /* Initialize the Estream library. */ gpgrt_init (); gpgrt_set_alloc_func (gcry_realloc); diff --git a/dirmngr/Makefile.am b/dirmngr/Makefile.am index aaa905089..64bc05868 100644 --- a/dirmngr/Makefile.am +++ b/dirmngr/Makefile.am @@ -94,8 +94,8 @@ dirmngr_ldap_SOURCES = dirmngr_ldap.c $(ldap_url) dirmngr_ldap_CFLAGS = $(GPG_ERROR_CFLAGS) $(LIBGCRYPT_CFLAGS) dirmngr_ldap_LDFLAGS = dirmngr_ldap_LDADD = $(libcommon) no-libgcrypt.o \ - $(GPG_ERROR_LIBS) $(LDAPLIBS) $(LBER_LIBS) $(LIBINTL) \ - $(LIBICONV) + $(GPG_ERROR_LIBS) $(LIBGCRYPT_LIBS) $(LDAPLIBS) \ + $(LBER_LIBS) $(LIBINTL) $(LIBICONV) endif dirmngr_client_SOURCES = dirmngr-client.c diff --git a/dirmngr/dirmngr.c b/dirmngr/dirmngr.c index 7e629db96..007fa1002 100644 --- a/dirmngr/dirmngr.c +++ b/dirmngr/dirmngr.c @@ -755,10 +755,6 @@ main (int argc, char **argv) /* Check that the libraries are suitable. Do it here because the option parsing may need services of the libraries. */ - - if (!gcry_check_version (NEED_LIBGCRYPT_VERSION) ) - 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( _("%s is too old (need %s, have %s)\n"), "libksba", NEED_KSBA_VERSION, ksba_check_version (NULL) ); diff --git a/g10/gpg.c b/g10/gpg.c index b33b61b7c..91f34720f 100644 --- a/g10/gpg.c +++ b/g10/gpg.c @@ -2201,14 +2201,6 @@ main (int argc, char **argv) i18n_init(); init_common_subsystems (&argc, &argv); - /* Check that the libraries are suitable. Do it right here because 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"), - NEED_LIBGCRYPT_VERSION, gcry_check_version (NULL) ); - } - /* Use our own logging handler for Libcgrypt. */ setup_libgcrypt_logging (); diff --git a/g10/gpgv.c b/g10/gpgv.c index 59edbb978..729fcf843 100644 --- a/g10/gpgv.c +++ b/g10/gpgv.c @@ -155,11 +155,6 @@ main( int argc, char **argv ) i18n_init(); init_common_subsystems (&argc, &argv); - if (!gcry_check_version (NEED_LIBGCRYPT_VERSION) ) - { - log_fatal ( _("%s is too old (need %s, have %s)\n"), "libgcrypt", - NEED_LIBGCRYPT_VERSION, gcry_check_version (NULL) ); - } gcry_control (GCRYCTL_DISABLE_SECMEM, 0); gnupg_init_signals (0, NULL); diff --git a/g13/g13-syshelp.c b/g13/g13-syshelp.c index f3c20f59d..0bb34dacb 100644 --- a/g13/g13-syshelp.c +++ b/g13/g13-syshelp.c @@ -250,11 +250,6 @@ main ( int argc, char **argv) i18n_init (); init_common_subsystems (&argc, &argv); - /* Check that the Libgcrypt is suitable. */ - if (!gcry_check_version (NEED_LIBGCRYPT_VERSION) ) - log_fatal (_("%s is too old (need %s, have %s)\n"), "libgcrypt", - NEED_LIBGCRYPT_VERSION, gcry_check_version (NULL) ); - /* Take extra care of the random pool. */ gcry_control (GCRYCTL_USE_SECURE_RNDPOOL); diff --git a/g13/g13.c b/g13/g13.c index 0499a1879..082edc9a4 100644 --- a/g13/g13.c +++ b/g13/g13.c @@ -372,11 +372,6 @@ main ( int argc, char **argv) npth_init (); - /* Check that the Libgcrypt is suitable. */ - if (!gcry_check_version (NEED_LIBGCRYPT_VERSION) ) - log_fatal (_("%s is too old (need %s, have %s)\n"), "libgcrypt", - NEED_LIBGCRYPT_VERSION, gcry_check_version (NULL) ); - /* Take extra care of the random pool. */ gcry_control (GCRYCTL_USE_SECURE_RNDPOOL); diff --git a/kbx/kbxutil.c b/kbx/kbxutil.c index d55a11871..e452b4de5 100644 --- a/kbx/kbxutil.c +++ b/kbx/kbxutil.c @@ -460,14 +460,6 @@ main( int argc, char **argv ) i18n_init (); init_common_subsystems (&argc, &argv); - /* Check that the libraries are suitable. Do it here because - the option parsing may need services of the library. */ - if (!gcry_check_version (NEED_LIBGCRYPT_VERSION) ) - { - 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); /*create_dotlock(NULL); register locking cleanup */ diff --git a/scd/scdaemon.c b/scd/scdaemon.c index 7dbb9c745..263d9bd5b 100644 --- a/scd/scdaemon.c +++ b/scd/scdaemon.c @@ -424,14 +424,6 @@ main (int argc, char **argv ) npth_init (); - /* Check that the libraries are suitable. Do it here because - the option parsing may need services of the library */ - if (!gcry_check_version (NEED_LIBGCRYPT_VERSION) ) - { - log_fatal (_("%s is too old (need %s, have %s)\n"), "libgcrypt", - NEED_LIBGCRYPT_VERSION, gcry_check_version (NULL) ); - } - ksba_set_malloc_hooks (gcry_malloc, gcry_realloc, gcry_free); malloc_hooks.malloc = gcry_malloc; diff --git a/sm/gpgsm.c b/sm/gpgsm.c index b64072e83..42b6706de 100644 --- a/sm/gpgsm.c +++ b/sm/gpgsm.c @@ -938,9 +938,6 @@ 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 (_("%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 (_("%s is too old (need %s, have %s)\n"), "libksba", NEED_KSBA_VERSION, ksba_check_version (NULL) ); diff --git a/tools/gpg-check-pattern.c b/tools/gpg-check-pattern.c index 37283a1d4..aa228a737 100644 --- a/tools/gpg-check-pattern.c +++ b/tools/gpg-check-pattern.c @@ -171,13 +171,6 @@ main (int argc, char **argv ) i18n_init (); init_common_subsystems (&argc, &argv); - /* We need Libgcrypt for hashing. */ - if (!gcry_check_version (NEED_LIBGCRYPT_VERSION) ) - { - log_fatal ( _("%s is too old (need %s, have %s)\n"), "libgcrypt", - NEED_LIBGCRYPT_VERSION, gcry_check_version (NULL) ); - } - setup_libgcrypt_logging (); gcry_control (GCRYCTL_INIT_SECMEM, 4096, 0); diff --git a/tools/symcryptrun.c b/tools/symcryptrun.c index 3732b39b8..5c1f0da1b 100644 --- a/tools/symcryptrun.c +++ b/tools/symcryptrun.c @@ -998,11 +998,6 @@ main (int argc, char **argv) log_set_file (logfile); gcry_control (GCRYCTL_SUSPEND_SECMEM_WARN); - if (!gcry_check_version (NEED_LIBGCRYPT_VERSION) ) - { - log_fatal (_("%s is too old (need %s, have %s)\n"), "libgcrypt", - NEED_LIBGCRYPT_VERSION, gcry_check_version (NULL) ); - } setup_libgcrypt_logging (); gcry_control (GCRYCTL_INIT_SECMEM, 16384, 0);