From f052c72fb728d1bebc41a143c810509a04330629 Mon Sep 17 00:00:00 2001 From: Arran Cudbard-Bell Date: Fri, 25 Apr 2014 23:16:18 +0100 Subject: [PATCH] Work with postgres library versions < 8.4 Closes #609 --- .../drivers/rlm_sql_postgresql/config.h.in | 6 ++ .../drivers/rlm_sql_postgresql/configure | 81 +++++++++++++++++++ .../drivers/rlm_sql_postgresql/configure.ac | 5 +- .../rlm_sql_postgresql/rlm_sql_postgresql.c | 6 +- 4 files changed, 96 insertions(+), 2 deletions(-) diff --git a/src/modules/rlm_sql/drivers/rlm_sql_postgresql/config.h.in b/src/modules/rlm_sql/drivers/rlm_sql_postgresql/config.h.in index 8e728a01b955..866ce58729df 100644 --- a/src/modules/rlm_sql/drivers/rlm_sql_postgresql/config.h.in +++ b/src/modules/rlm_sql/drivers/rlm_sql_postgresql/config.h.in @@ -6,6 +6,12 @@ /* Whether the PGRES_SINGLE_TUPLE constant is defined */ #undef HAVE_PGRES_SINGLE_TUPLE +/* Define to 1 if you have the `PQinitOpenSSL' function. */ +#undef HAVE_PQINITOPENSSL + +/* Define to 1 if you have the `PQinitSSL' function. */ +#undef HAVE_PQINITSSL + /* Define to the address where bug reports for this package should be sent. */ #undef PACKAGE_BUGREPORT diff --git a/src/modules/rlm_sql/drivers/rlm_sql_postgresql/configure b/src/modules/rlm_sql/drivers/rlm_sql_postgresql/configure index 8a57fd4409b1..b29972a7154c 100755 --- a/src/modules/rlm_sql/drivers/rlm_sql_postgresql/configure +++ b/src/modules/rlm_sql/drivers/rlm_sql_postgresql/configure @@ -1428,6 +1428,73 @@ fi as_fn_set_status $ac_retval } # ac_fn_c_try_link + +# ac_fn_c_check_func LINENO FUNC VAR +# ---------------------------------- +# Tests whether FUNC exists, setting the cache variable VAR accordingly +ac_fn_c_check_func () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 +$as_echo_n "checking for $2... " >&6; } +if eval \${$3+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +/* Define $2 to an innocuous variant, in case declares $2. + For example, HP-UX 11i declares gettimeofday. */ +#define $2 innocuous_$2 + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $2 (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif + +#undef $2 + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char $2 (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined __stub_$2 || defined __stub___$2 +choke me +#endif + +int +main () +{ +return $2 (); + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + eval "$3=yes" +else + eval "$3=no" +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +eval ac_res=\$$3 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + +} # ac_fn_c_check_func cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. @@ -3007,6 +3074,20 @@ fi if test "x$ac_cv_lib_pq_PQconnectdb" != "xyes"; then fail="$fail libpq" fi + for ac_func in \ + PQinitOpenSSL \ + PQinitSSL \ + +do : + as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` +ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" +if eval test \"x\$"$as_ac_var"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done targetname=rlm_sql_postgresql else diff --git a/src/modules/rlm_sql/drivers/rlm_sql_postgresql/configure.ac b/src/modules/rlm_sql/drivers/rlm_sql_postgresql/configure.ac index 12ed0bcb67f5..4f9a890ba0dd 100644 --- a/src/modules/rlm_sql/drivers/rlm_sql_postgresql/configure.ac +++ b/src/modules/rlm_sql/drivers/rlm_sql_postgresql/configure.ac @@ -81,7 +81,10 @@ if test x$with_[]modname != xno; then if test "x$ac_cv_lib_pq_PQconnectdb" != "xyes"; then fail="$fail libpq" fi - + AC_CHECK_FUNCS(\ + PQinitOpenSSL \ + PQinitSSL \ + ) targetname=modname else targetname= diff --git a/src/modules/rlm_sql/drivers/rlm_sql_postgresql/rlm_sql_postgresql.c b/src/modules/rlm_sql/drivers/rlm_sql_postgresql/rlm_sql_postgresql.c index 9141988ab939..52600d7eacf1 100644 --- a/src/modules/rlm_sql/drivers/rlm_sql_postgresql/rlm_sql_postgresql.c +++ b/src/modules/rlm_sql/drivers/rlm_sql_postgresql/rlm_sql_postgresql.c @@ -169,11 +169,15 @@ static int sql_init_socket(rlm_sql_handle_t *handle, rlm_sql_config_t *config) { char *dbstring; rlm_sql_postgres_conn_t *conn; -#ifdef HAVE_OPENSSL_CRYPTO_H +#if defined(HAVE_OPENSSL_CRYPTO_H) && (defined(HAVE_PQINITOPENSSL) || defined(HAVE_PQINITSSL)) static bool ssl_init = false; if (!ssl_init) { +#ifdef HAVE_PQINITOPENSSL PQinitOpenSSL(0, 0); +#else + PQinitSSL(0); +#endif ssl_init = true; } #endif