1 From b1b895b2cdc9563398d873023c535763540722ee Mon Sep 17 00:00:00 2001
2 From: Arran Cudbard-Bell <a.cudbardb@freeradius.org>
3 Date: Tue, 4 Feb 2014 17:51:51 +0000
4 Subject: [PATCH] Do proper checks for each individual sqlite_v2 function
7 .../rlm_sql/drivers/rlm_sql_sqlite/config.h.in | 13 +-
8 .../rlm_sql/drivers/rlm_sql_sqlite/configure | 249 +++++++--------------
9 .../rlm_sql/drivers/rlm_sql_sqlite/configure.ac | 14 +-
10 .../drivers/rlm_sql_sqlite/rlm_sql_sqlite.c | 35 ++-
11 4 files changed, 125 insertions(+), 186 deletions(-)
13 diff --git a/src/modules/rlm_sql/drivers/rlm_sql_sqlite/config.h.in b/src/modules/rlm_sql/drivers/rlm_sql_sqlite/config.h.in
14 index 59abf27..f8a686f 100644
15 --- a/src/modules/rlm_sql/drivers/rlm_sql_sqlite/config.h.in
16 +++ b/src/modules/rlm_sql/drivers/rlm_sql_sqlite/config.h.in
18 /* config.h.in. Generated from configure.ac by autoheader. */
20 -/* Define if the SQLite library has v2 API functions */
21 -#undef HAVE_SQLITE_V2_API
22 +/* Define to 1 if you have the `sqlite3_create_function_v2' function. */
23 +#undef HAVE_SQLITE3_CREATE_FUNCTION_V2
25 +/* Define to 1 if you have the `sqlite3_errstr' function. */
26 +#undef HAVE_SQLITE3_ERRSTR
28 +/* Define to 1 if you have the `sqlite3_open_v2' function. */
29 +#undef HAVE_SQLITE3_OPEN_V2
31 +/* Define to 1 if you have the `sqlite3_prepare_v2' function. */
32 +#undef HAVE_SQLITE3_PREPARE_V2
34 /* Define to the address where bug reports for this package should be sent. */
35 #undef PACKAGE_BUGREPORT
36 diff --git a/src/modules/rlm_sql/drivers/rlm_sql_sqlite/configure b/src/modules/rlm_sql/drivers/rlm_sql_sqlite/configure
37 index 8a603af..8c22bb4 100755
38 --- a/src/modules/rlm_sql/drivers/rlm_sql_sqlite/configure
39 +++ b/src/modules/rlm_sql/drivers/rlm_sql_sqlite/configure
40 @@ -1432,6 +1432,73 @@ fi
41 as_fn_set_status $ac_retval
45 +# ac_fn_c_check_func LINENO FUNC VAR
46 +# ----------------------------------
47 +# Tests whether FUNC exists, setting the cache variable VAR accordingly
48 +ac_fn_c_check_func ()
50 + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
51 + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5
52 +$as_echo_n "checking for $2... " >&6; }
53 +if eval \${$3+:} false; then :
54 + $as_echo_n "(cached) " >&6
56 + cat confdefs.h - <<_ACEOF >conftest.$ac_ext
57 +/* end confdefs.h. */
58 +/* Define $2 to an innocuous variant, in case <limits.h> declares $2.
59 + For example, HP-UX 11i <limits.h> declares gettimeofday. */
60 +#define $2 innocuous_$2
62 +/* System header to define __stub macros and hopefully few prototypes,
63 + which can conflict with char $2 (); below.
64 + Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
65 + <limits.h> exists even on freestanding compilers. */
75 +/* Override any GCC internal prototype to avoid an error.
76 + Use char because int might match the return type of a GCC
77 + builtin and then its argument prototype would still apply. */
82 +/* The GNU C library defines this for functions which it implements
83 + to always fail with ENOSYS. Some functions are actually named
84 + something starting with __ and the normal name is an alias. */
85 +#if defined __stub_$2 || defined __stub___$2
97 +if ac_fn_c_try_link "$LINENO"; then :
102 +rm -f core conftest.err conftest.$ac_objext \
103 + conftest$ac_exeext conftest.$ac_ext
106 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
107 +$as_echo "$ac_res" >&6; }
108 + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
110 +} # ac_fn_c_check_func
111 cat >config.log <<_ACEOF
112 This file contains any messages produced by compilers while
113 running configure, to aid debugging if configure makes a mistake.
114 @@ -2804,184 +2871,30 @@ if test "x$smart_lib" != "x"; then
115 SMART_LIBS="$smart_lib $SMART_LIBS"
118 + LDFLAGS="$SMART_LIBS"
119 if test "x$ac_cv_lib_sqlite3_sqlite3_open" != "xyes"
121 { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Sqlite libraries not found. Use --with-sqlite-lib-dir=<path>." >&5
122 $as_echo "$as_me: WARNING: Sqlite libraries not found. Use --with-sqlite-lib-dir=<path>." >&2;}
123 fail="$fail libsqlite3"
127 -sm_lib_safe=`echo "sqlite3" | sed 'y%./+-%__p_%'`
128 -sm_func_safe=`echo "sqlite3_open_v2" | sed 'y%./+-%__p_%'`
134 -if test "x$smart_try_dir" != "x"; then
135 - for try in $smart_try_dir; do
136 - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for sqlite3_open_v2 in -lsqlite3 in $try" >&5
137 -$as_echo_n "checking for sqlite3_open_v2 in -lsqlite3 in $try... " >&6; }
138 - LIBS="-L$try -lsqlite3 $old_LIBS -Wl,-rpath,$try"
139 - cat confdefs.h - <<_ACEOF >conftest.$ac_ext
140 -/* end confdefs.h. */
141 -extern char sqlite3_open_v2();
150 -if ac_fn_c_try_link "$LINENO"; then :
152 - smart_lib="-L$try -lsqlite3 -Wl,-rpath,$try"
153 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
154 -$as_echo "yes" >&6; }
158 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
159 -$as_echo "no" >&6; }
161 -rm -f core conftest.err conftest.$ac_objext \
162 - conftest$ac_exeext conftest.$ac_ext
167 -if test "x$smart_lib" = "x"; then
168 - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for sqlite3_open_v2 in -lsqlite3" >&5
169 -$as_echo_n "checking for sqlite3_open_v2 in -lsqlite3... " >&6; }
170 - LIBS="-lsqlite3 $old_LIBS"
171 - cat confdefs.h - <<_ACEOF >conftest.$ac_ext
172 -/* end confdefs.h. */
173 -extern char sqlite3_open_v2();
182 -if ac_fn_c_try_link "$LINENO"; then :
184 - smart_lib="-lsqlite3"
185 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
186 -$as_echo "yes" >&6; }
189 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
190 -$as_echo "no" >&6; }
192 -rm -f core conftest.err conftest.$ac_objext \
193 - conftest$ac_exeext conftest.$ac_ext
197 -if test "x$smart_lib" = "x"; then
200 -if test "x$LOCATE" != "x"; then
202 - file=libsqlite3${libltdl_cv_shlibext}
204 - for x in `${LOCATE} $file 2>/dev/null`; do
205 - base=`echo $x | sed "s%/${file}%%"`
206 - if test "x$x" = "x$base"; then
210 - dir=`${DIRNAME} $x 2>/dev/null`
211 - exclude=`echo ${dir} | ${GREP} /home`
212 - if test "x$exclude" != "x"; then
216 - already=`echo \$smart_lib_dir ${DIRS} | ${GREP} ${dir}`
217 - if test "x$already" = "x"; then
223 -eval "smart_lib_dir=\"\$smart_lib_dir $DIRS\""
227 -if test "x$LOCATE" != "x"; then
231 - for x in `${LOCATE} $file 2>/dev/null`; do
232 - base=`echo $x | sed "s%/${file}%%"`
233 - if test "x$x" = "x$base"; then
237 - dir=`${DIRNAME} $x 2>/dev/null`
238 - exclude=`echo ${dir} | ${GREP} /home`
239 - if test "x$exclude" != "x"; then
243 - already=`echo \$smart_lib_dir ${DIRS} | ${GREP} ${dir}`
244 - if test "x$already" = "x"; then
250 -eval "smart_lib_dir=\"\$smart_lib_dir $DIRS\""
253 - for try in $smart_lib_dir /usr/local/lib /opt/lib; do
254 - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for sqlite3_open_v2 in -lsqlite3 in $try" >&5
255 -$as_echo_n "checking for sqlite3_open_v2 in -lsqlite3 in $try... " >&6; }
256 - LIBS="-L$try -lsqlite3 $old_LIBS -Wl,-rpath,$try"
257 - cat confdefs.h - <<_ACEOF >conftest.$ac_ext
258 -/* end confdefs.h. */
259 -extern char sqlite3_open_v2();
268 + sqlite3_prepare_v2 \
270 + sqlite3_create_function_v2 \
274 + as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
275 +ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
276 +if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
277 + cat >>confdefs.h <<_ACEOF
278 +#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
280 -if ac_fn_c_try_link "$LINENO"; then :
282 - smart_lib="-L$try -lsqlite3 -Wl,-rpath,$try"
283 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
284 -$as_echo "yes" >&6; }
288 - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
289 -$as_echo "no" >&6; }
291 -rm -f core conftest.err conftest.$ac_objext \
292 - conftest$ac_exeext conftest.$ac_ext
298 -if test "x$smart_lib" != "x"; then
299 - eval "ac_cv_lib_${sm_lib_safe}_${sm_func_safe}=yes"
300 - LIBS="$smart_lib $old_LIBS"
301 - SMART_LIBS="$smart_lib $SMART_LIBS"
304 - if test "x$ac_cv_lib_sqlite3_sqlite3_open_v2" == "xyes"
307 -$as_echo "#define HAVE_SQLITE_V2_API 1" >>confdefs.h
313 diff --git a/src/modules/rlm_sql/drivers/rlm_sql_sqlite/configure.ac b/src/modules/rlm_sql/drivers/rlm_sql_sqlite/configure.ac
314 index 94ab603..601214a 100644
315 --- a/src/modules/rlm_sql/drivers/rlm_sql_sqlite/configure.ac
316 +++ b/src/modules/rlm_sql/drivers/rlm_sql_sqlite/configure.ac
317 @@ -73,16 +73,20 @@ if test x$with_[]modname != xno; then
318 dnl try to link to libsqlite3
319 smart_try_dir="$sqlite_lib_dir"
320 FR_SMART_CHECK_LIB(sqlite3, sqlite3_open)
321 + dnl # Ensure we use the library we just found the rest of the checks
322 + LDFLAGS="$SMART_LIBS"
323 if test "x$ac_cv_lib_sqlite3_sqlite3_open" != "xyes"
325 AC_MSG_WARN([Sqlite libraries not found. Use --with-sqlite-lib-dir=<path>.])
326 fail="$fail libsqlite3"
328 - FR_SMART_CHECK_LIB(sqlite3, sqlite3_open_v2)
329 - if test "x$ac_cv_lib_sqlite3_sqlite3_open_v2" == "xyes"
331 - AC_DEFINE(HAVE_SQLITE_V2_API, [1], [Define if the SQLite library has v2 API functions])
333 + dnl # Add any v2 variants here
335 + sqlite3_prepare_v2 \
337 + sqlite3_create_function_v2 \
342 dnl ############################################################
343 diff --git a/src/modules/rlm_sql/drivers/rlm_sql_sqlite/rlm_sql_sqlite.c b/src/modules/rlm_sql/drivers/rlm_sql_sqlite/rlm_sql_sqlite.c
344 index ba516e0..15dc737 100644
345 --- a/src/modules/rlm_sql/drivers/rlm_sql_sqlite/rlm_sql_sqlite.c
346 +++ b/src/modules/rlm_sql/drivers/rlm_sql_sqlite/rlm_sql_sqlite.c
347 @@ -94,7 +94,7 @@ static int sql_check_error(sqlite3 *db)
351 -#ifdef HAVE_SQLITE_V2_API
352 +#ifdef HAVE_SQLITE3_OPEN_V2
353 static int sql_loadfile(TALLOC_CTX *ctx, sqlite3 *db, char const *filename)
356 @@ -196,7 +196,11 @@ static int sql_loadfile(TALLOC_CTX *ctx, sqlite3 *db, char const *filename)
360 - (void) sqlite3_prepare_v2(db, s, len, &statement, &z_tail);
361 +#ifdef HAVE_SQLITE3_PREPARE_V2
362 + (void) sqlite3_prepare_v2(db, s, len, &statement, &z_tail);
364 + (void) sqlite3_prepare(db, s, len, &>statement, &z_tail);
366 if (sql_check_error(db)) {
369 @@ -249,7 +253,7 @@ static int mod_instantiate(CONF_SECTION *conf, rlm_sql_config_t *config)
372 if (driver->bootstrap && !exists) {
373 -#ifdef HAVE_SQLITE_V2_API
374 +#ifdef HAVE_SQLITE3_OPEN_V2
378 @@ -280,8 +284,13 @@ static int mod_instantiate(CONF_SECTION *conf, rlm_sql_config_t *config)
380 status = sqlite3_open_v2(driver->filename, &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
382 - ERROR("rlm_sql_sqlite: Failed creating opening/creating SQLite database, error "
383 - "code (%u)", status);
384 +#ifdef HAVE_SQLITE3_ERRSTR
385 + ERROR("rlm_sql_sqlite: Failed creating opening/creating SQLite database: %s",
386 + sqlite3_errstr(status));
388 + ERROR("rlm_sql_sqlite: Failed creating opening/creating SQLite database, got code (%i)",
394 @@ -359,14 +368,18 @@ static sql_rcode_t sql_socket_init(rlm_sql_handle_t *handle, rlm_sql_config_t *c
396 INFO("rlm_sql_sqlite: Opening SQLite database \"%s\"", driver->filename);
398 -#ifdef HAVE_SQLITE_V2_API
399 +#ifdef HAVE_SQLITE3_OPEN_V2
400 status = sqlite3_open_v2(driver->filename, &(conn->db), SQLITE_OPEN_READWRITE | SQLITE_OPEN_NOMUTEX, NULL);
402 status = sqlite3_open(driver->filename, &(conn->db));
405 - ERROR("rlm_sql_sqlite: Failed creating opening/creating SQLite database error code (%u)",
407 +#ifdef HAVE_SQLITE3_ERRSTR
408 + ERROR("rlm_sql_sqlite: Failed creating opening/creating SQLite: %s", sqlite3_errstr(status));
410 + ERROR("rlm_sql_sqlite: Failed creating opening/creating SQLite database error code (%i)",
416 @@ -384,7 +397,7 @@ static sql_rcode_t sql_socket_init(rlm_sql_handle_t *handle, rlm_sql_config_t *c
420 -#ifdef HAVE_SQLITE_V2_API
421 +#ifdef HAVE_SQLITE3_CREATE_FUNCTION_V2
422 status = sqlite3_create_function_v2(conn->db, "GREATEST", -1, SQLITE_ANY, NULL,
423 _sql_greatest, NULL, NULL, NULL);
425 @@ -403,7 +416,7 @@ static sql_rcode_t sql_select_query(rlm_sql_handle_t *handle, UNUSED rlm_sql_con
426 rlm_sql_sqlite_conn_t *conn = handle->conn;
429 -#ifdef HAVE_SQLITE_V2_API
430 +#ifdef HAVE_SQLITE3_PREPARE_V2
431 (void) sqlite3_prepare_v2(conn->db, query, strlen(query), &conn->statement, &z_tail);
433 (void) sqlite3_prepare(conn->db, query, strlen(query), &conn->statement, &z_tail);
434 @@ -421,7 +434,7 @@ static sql_rcode_t sql_query(rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t *
435 rlm_sql_sqlite_conn_t *conn = handle->conn;
438 -#ifdef HAVE_SQLITE_V2_API
439 +#ifdef HAVE_SQLITE3_PREPARE_V2
440 status = sqlite3_prepare_v2(conn->db, query, strlen(query), &conn->statement, &z_tail);
442 status = sqlite3_prepare(conn->db, query, strlen(query), &conn->statement, &z_tail);