From b93f679049837d9cc59eb617736e8a50fddaaabc Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Tue, 25 Aug 2009 13:05:31 +0000 Subject: [PATCH] configure detect ssl get_compression_methods and ctime_r fix. git-svn-id: file:///svn/unbound/trunk@1780 be551aaa-1e26-0410-a405-d3ace91eadb9 --- compat/ctime_r.c | 30 ++++++++++++++-- config.h.in | 9 +++++ configure | 89 ++++++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 25 ++++++++++++++ daemon/daemon.c | 6 ++++ doc/Changelog | 3 +- 6 files changed, 158 insertions(+), 4 deletions(-) diff --git a/compat/ctime_r.c b/compat/ctime_r.c index 75454d7a3..bdc4baf3d 100644 --- a/compat/ctime_r.c +++ b/compat/ctime_r.c @@ -1,15 +1,39 @@ /* taken from ldns 1.6.1 */ #include "config.h" - #ifdef HAVE_TIME_H #include #endif +#include "util/locks.h" + +/** the lock for ctime buffer */ +static lock_basic_t ctime_lock; +/** has it been inited */ +static int ctime_r_init = 0; + +/** cleanup ctime_r on exit */ +static void +ctime_r_cleanup(void) +{ + if(ctime_r_init) { + ctime_r_init = 0; + lock_basic_destroy(&ctime_lock); + } +} char *ctime_r(const time_t *timep, char *buf) { - /* no thread safety. */ - char* result = ctime(timep); + char* result; + if(!ctime_r_init) { + /* still small race where this init can be done twice, + * which is mostly harmless */ + ctime_r_init = 1; + lock_basic_init(&ctime_lock); + atexit(&ctime_r_cleanup); + } + lock_basic_lock(&ctime_lock); + result = ctime(timep); if(buf && result) strcpy(buf, result); + lock_basic_unlock(&ctime_lock); return result; } diff --git a/config.h.in b/config.h.in index 71c0be288..02962bac5 100644 --- a/config.h.in +++ b/config.h.in @@ -37,6 +37,10 @@ /* Define to 1 if you have the `daemon' function. */ #undef HAVE_DAEMON +/* Define to 1 if you have the declaration of + `SSL_COMP_get_compression_methods', and to 0 if you don't. */ +#undef HAVE_DECL_SSL_COMP_GET_COMPRESSION_METHODS + /* Define to 1 if you have the header file. */ #undef HAVE_DLFCN_H @@ -765,6 +769,11 @@ struct tm *gmtime_r(const time_t *timep, struct tm *result); +#ifndef HAVE_CTIME_R +#define ctime_r unbound_ctime_r +char *ctime_r(const time_t *timep, char *buf); +#endif + #if defined(HAVE_EVENT_H) && !defined(HAVE_EVENT_BASE_ONCE) && (defined(HAVE_PTHREAD) || defined(HAVE_SOLARIS_THREADS)) /* using version of libevent that is not threadsafe. */ # define LIBEVENT_SIGNAL_PROBLEM 1 diff --git a/configure b/configure index 74c5f525e..cd17c6850 100755 --- a/configure +++ b/configure @@ -17812,6 +17812,95 @@ _ACEOF fi done +{ $as_echo "$as_me:$LINENO: checking whether SSL_COMP_get_compression_methods is declared" >&5 +$as_echo_n "checking whether SSL_COMP_get_compression_methods is declared... " >&6; } +if test "${ac_cv_have_decl_SSL_COMP_get_compression_methods+set}" = set; then + $as_echo_n "(cached) " >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +$ac_includes_default +#ifdef HAVE_OPENSSL_ERR_H +#include +#endif + +#ifdef HAVE_OPENSSL_RAND_H +#include +#endif + +#ifdef HAVE_OPENSSL_CONF_H +#include +#endif + +#ifdef HAVE_OPENSSL_ENGINE_H +#include +#endif +#include +#include + + +int +main () +{ +#ifndef SSL_COMP_get_compression_methods + (void) SSL_COMP_get_compression_methods; +#endif + + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" +$as_echo "$ac_try_echo") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_cv_have_decl_SSL_COMP_get_compression_methods=yes +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_cv_have_decl_SSL_COMP_get_compression_methods=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:$LINENO: result: $ac_cv_have_decl_SSL_COMP_get_compression_methods" >&5 +$as_echo "$ac_cv_have_decl_SSL_COMP_get_compression_methods" >&6; } +if test "x$ac_cv_have_decl_SSL_COMP_get_compression_methods" = x""yes; then + +cat >>confdefs.h <<_ACEOF +#define HAVE_DECL_SSL_COMP_GET_COMPRESSION_METHODS 1 +_ACEOF + + +else + cat >>confdefs.h <<_ACEOF +#define HAVE_DECL_SSL_COMP_GET_COMPRESSION_METHODS 0 +_ACEOF + + +fi + + # Check whether --enable-sha2 was given. if test "${enable_sha2+set}" = set; then diff --git a/configure.ac b/configure.ac index 900e4510b..8728053c8 100644 --- a/configure.ac +++ b/configure.ac @@ -363,6 +363,26 @@ ACX_LIB_SSL AC_CHECK_HEADERS([openssl/conf.h],,, [AC_INCLUDES_DEFAULT]) AC_CHECK_HEADERS([openssl/engine.h],,, [AC_INCLUDES_DEFAULT]) AC_CHECK_FUNCS([OPENSSL_config EVP_sha1 EVP_sha256 EVP_sha512]) +AC_CHECK_DECLS([SSL_COMP_get_compression_methods], [], [], [ +AC_INCLUDES_DEFAULT +#ifdef HAVE_OPENSSL_ERR_H +#include +#endif + +#ifdef HAVE_OPENSSL_RAND_H +#include +#endif + +#ifdef HAVE_OPENSSL_CONF_H +#include +#endif + +#ifdef HAVE_OPENSSL_ENGINE_H +#include +#endif +#include +#include +]) AC_ARG_ENABLE(sha2, AC_HELP_STRING([--enable-sha2], [Enable SHA256 and SHA512 RRSIG support, experimental])) case "$enable_sha2" in @@ -691,6 +711,11 @@ AHX_CONFIG_W32_FD_SET_T AHX_CONFIG_IPV6_MIN_MTU [ +#ifndef HAVE_CTIME_R +#define ctime_r unbound_ctime_r +char *ctime_r(const time_t *timep, char *buf); +#endif + #if defined(HAVE_EVENT_H) && !defined(HAVE_EVENT_BASE_ONCE) && (defined(HAVE_PTHREAD) || defined(HAVE_SOLARIS_THREADS)) /* using version of libevent that is not threadsafe. */ # define LIBEVENT_SIGNAL_PROBLEM 1 diff --git a/daemon/daemon.c b/daemon/daemon.c index 16be3534e..6f17c7145 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -63,8 +63,10 @@ static int sig_record_quit = 0; /** How many reload requests happened. */ static int sig_record_reload = 0; +#if HAVE_DECL_SSL_COMP_GET_COMPRESSION_METHODS /** cleaner ssl memory freeup */ static void* comp_meth = NULL; +#endif /** used when no other sighandling happens, so we don't die * when multiple signals in quick succession are sent to us. @@ -175,8 +177,10 @@ daemon_init() (void)ldns_key_EVP_load_gost_id(); #endif OpenSSL_add_all_algorithms(); +#if HAVE_DECL_SSL_COMP_GET_COMPRESSION_METHODS /* grab the COMP method ptr because openssl leaks it */ comp_meth = (void*)SSL_COMP_get_compression_methods(); +#endif (void)SSL_library_init(); #ifdef HAVE_TZSET /* init timezone info while we are not chrooted yet */ @@ -504,7 +508,9 @@ daemon_delete(struct daemon* daemon) free(daemon->env); free(daemon); /* libcrypto cleanup */ +#if HAVE_DECL_SSL_COMP_GET_COMPRESSION_METHODS sk_SSL_COMP_free(comp_meth); +#endif #ifdef HAVE_OPENSSL_CONFIG EVP_cleanup(); ENGINE_cleanup(); diff --git a/doc/Changelog b/doc/Changelog index 50c6c6295..c40313548 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -4,7 +4,8 @@ - autotrust options: add-holddown, del-holddown, keep-missing. - autotrust store revoked status of trust points. - ctime_r compat definition. - - detect yylex_destroy(). + - detect yylex_destroy() in configure. + - detect SSL_get_compression_methods declaration in configure. 24 August 2009: Wouter - cleaner memory allocation on exit. autotrust test routines. -- 2.47.3