Include sources needed by RPM packages
[moonshot.git] / rpm-sources / freeradius-rlm_sql_sqlite-v2api.patch
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
5
6 ---
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(-)
12
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
17 @@ -1,7 +1,16 @@
18  /* config.h.in.  Generated from configure.ac by autoheader.  */
19  
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
24 +
25 +/* Define to 1 if you have the `sqlite3_errstr' function. */
26 +#undef HAVE_SQLITE3_ERRSTR
27 +
28 +/* Define to 1 if you have the `sqlite3_open_v2' function. */
29 +#undef HAVE_SQLITE3_OPEN_V2
30 +
31 +/* Define to 1 if you have the `sqlite3_prepare_v2' function. */
32 +#undef HAVE_SQLITE3_PREPARE_V2
33  
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
42  
43  } # ac_fn_c_try_link
44 +
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 ()
49 +{
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
55 +else
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
61 +
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.  */
66 +
67 +#ifdef __STDC__
68 +# include <limits.h>
69 +#else
70 +# include <assert.h>
71 +#endif
72 +
73 +#undef $2
74 +
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.  */
78 +#ifdef __cplusplus
79 +extern "C"
80 +#endif
81 +char $2 ();
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
86 +choke me
87 +#endif
88 +
89 +int
90 +main ()
91 +{
92 +return $2 ();
93 +  ;
94 +  return 0;
95 +}
96 +_ACEOF
97 +if ac_fn_c_try_link "$LINENO"; then :
98 +  eval "$3=yes"
99 +else
100 +  eval "$3=no"
101 +fi
102 +rm -f core conftest.err conftest.$ac_objext \
103 +    conftest$ac_exeext conftest.$ac_ext
104 +fi
105 +eval ac_res=\$$3
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
109 +
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"
116  fi
117  
118 +        LDFLAGS="$SMART_LIBS"
119      if test "x$ac_cv_lib_sqlite3_sqlite3_open" != "xyes"
120      then
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"
124      else
125 -
126 -
127 -sm_lib_safe=`echo "sqlite3" | sed 'y%./+-%__p_%'`
128 -sm_func_safe=`echo "sqlite3_open_v2" | sed 'y%./+-%__p_%'`
129 -
130 -old_LIBS="$LIBS"
131 -smart_lib=
132 -smart_lib_dir=
133 -
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();
142 -int
143 -main ()
144 -{
145 -sqlite3_open_v2()
146 -  ;
147 -  return 0;
148 -}
149 -_ACEOF
150 -if ac_fn_c_try_link "$LINENO"; then :
151 -
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; }
155 -                break
156 -
157 -else
158 -  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
159 -$as_echo "no" >&6; }
160 -fi
161 -rm -f core conftest.err conftest.$ac_objext \
162 -    conftest$ac_exeext conftest.$ac_ext
163 -  done
164 -  LIBS="$old_LIBS"
165 -fi
166 -
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();
174 -int
175 -main ()
176 -{
177 -sqlite3_open_v2()
178 -  ;
179 -  return 0;
180 -}
181 -_ACEOF
182 -if ac_fn_c_try_link "$LINENO"; then :
183 -
184 -               smart_lib="-lsqlite3"
185 -               { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
186 -$as_echo "yes" >&6; }
187 -
188 -else
189 -  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
190 -$as_echo "no" >&6; }
191 -fi
192 -rm -f core conftest.err conftest.$ac_objext \
193 -    conftest$ac_exeext conftest.$ac_ext
194 -  LIBS="$old_LIBS"
195 -fi
196 -
197 -if test "x$smart_lib" = "x"; then
198 -
199 -
200 -if test "x$LOCATE" != "x"; then
201 -        DIRS=
202 -  file=libsqlite3${libltdl_cv_shlibext}
203 -
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
207 -      continue;
208 -    fi
209 -
210 -    dir=`${DIRNAME} $x 2>/dev/null`
211 -                exclude=`echo ${dir} | ${GREP} /home`
212 -    if test "x$exclude" != "x"; then
213 -      continue
214 -    fi
215 -
216 -                    already=`echo \$smart_lib_dir ${DIRS} | ${GREP} ${dir}`
217 -    if test "x$already" = "x"; then
218 -      DIRS="$DIRS $dir"
219 -    fi
220 -  done
221 -fi
222 -
223 -eval "smart_lib_dir=\"\$smart_lib_dir $DIRS\""
224 -
225 -
226 -
227 -if test "x$LOCATE" != "x"; then
228 -        DIRS=
229 -  file=libsqlite3.a
230 -
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
234 -      continue;
235 -    fi
236 -
237 -    dir=`${DIRNAME} $x 2>/dev/null`
238 -                exclude=`echo ${dir} | ${GREP} /home`
239 -    if test "x$exclude" != "x"; then
240 -      continue
241 -    fi
242 -
243 -                    already=`echo \$smart_lib_dir ${DIRS} | ${GREP} ${dir}`
244 -    if test "x$already" = "x"; then
245 -      DIRS="$DIRS $dir"
246 -    fi
247 -  done
248 -fi
249 -
250 -eval "smart_lib_dir=\"\$smart_lib_dir $DIRS\""
251 -
252 -
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();
260 -int
261 -main ()
262 -{
263 -sqlite3_open_v2()
264 -  ;
265 -  return 0;
266 -}
267 +               for ac_func in \
268 +               sqlite3_prepare_v2 \
269 +               sqlite3_open_v2 \
270 +               sqlite3_create_function_v2 \
271 +               sqlite3_errstr \
272 +
273 +do :
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
279  _ACEOF
280 -if ac_fn_c_try_link "$LINENO"; then :
281  
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; }
285 -                 break
286 -
287 -else
288 -  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
289 -$as_echo "no" >&6; }
290 -fi
291 -rm -f core conftest.err conftest.$ac_objext \
292 -    conftest$ac_exeext conftest.$ac_ext
293 -  done
294 -  LIBS="$old_LIBS"
295  fi
296 +done
297  
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"
302 -fi
303 -
304 -        if test "x$ac_cv_lib_sqlite3_sqlite3_open_v2" == "xyes"
305 -       then
306 -
307 -$as_echo "#define HAVE_SQLITE_V2_API 1" >>confdefs.h
308 -
309 -        fi
310      fi
311  
312  
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"
324      then
325          AC_MSG_WARN([Sqlite libraries not found. Use --with-sqlite-lib-dir=<path>.])
326          fail="$fail libsqlite3"
327      else
328 -        FR_SMART_CHECK_LIB(sqlite3, sqlite3_open_v2)
329 -        if test "x$ac_cv_lib_sqlite3_sqlite3_open_v2" == "xyes"
330 -       then
331 -            AC_DEFINE(HAVE_SQLITE_V2_API, [1], [Define if the SQLite library has v2 API functions])   
332 -        fi
333 +       dnl # Add any v2 variants here
334 +       AC_CHECK_FUNCS(\
335 +               sqlite3_prepare_v2 \
336 +               sqlite3_open_v2 \
337 +               sqlite3_create_function_v2 \
338 +               sqlite3_errstr \
339 +       )
340      fi
341  
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)
348         }
349  }
350  
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)
354  {
355         ssize_t len;
356 @@ -196,7 +196,11 @@ static int sql_loadfile(TALLOC_CTX *ctx, sqlite3 *db, char const *filename)
357  
358                 *q = '\0';
359  
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);
363 +#else
364 +               (void) sqlite3_prepare(db, s, len, &>statement, &z_tail);
365 +#endif
366                 if (sql_check_error(db)) {
367                         talloc_free(buffer);
368                         return -1;
369 @@ -249,7 +253,7 @@ static int mod_instantiate(CONF_SECTION *conf, rlm_sql_config_t *config)
370         }
371  
372         if (driver->bootstrap && !exists) {
373 -#ifdef HAVE_SQLITE_V2_API
374 +#ifdef HAVE_SQLITE3_OPEN_V2
375                 int status;
376                 int ret;
377                 char *p;
378 @@ -280,8 +284,13 @@ static int mod_instantiate(CONF_SECTION *conf, rlm_sql_config_t *config)
379  
380                 status = sqlite3_open_v2(driver->filename, &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
381                 if (!db) {
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));
387 +#else
388 +                       ERROR("rlm_sql_sqlite: Failed creating opening/creating SQLite database, got code (%i)",
389 +                             status);
390 +#endif
391  
392                         goto unlink;
393                 }
394 @@ -359,14 +368,18 @@ static sql_rcode_t sql_socket_init(rlm_sql_handle_t *handle, rlm_sql_config_t *c
395  
396         INFO("rlm_sql_sqlite: Opening SQLite database \"%s\"", driver->filename);
397  
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);
401  #else
402         status = sqlite3_open(driver->filename, &(conn->db));
403  #endif
404         if (!conn->db) {
405 -               ERROR("rlm_sql_sqlite: Failed creating opening/creating SQLite database error code (%u)",
406 -                      status);
407 +#ifdef HAVE_SQLITE3_ERRSTR
408 +               ERROR("rlm_sql_sqlite: Failed creating opening/creating SQLite: %s", sqlite3_errstr(status));
409 +#else
410 +               ERROR("rlm_sql_sqlite: Failed creating opening/creating SQLite database error code (%i)",
411 +                     status);
412 +#endif
413  
414                 return -1;
415         }
416 @@ -384,7 +397,7 @@ static sql_rcode_t sql_socket_init(rlm_sql_handle_t *handle, rlm_sql_config_t *c
417                 return -1;
418         }
419  
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);
424  #else
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;
427         char const *z_tail;
428  
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);
432  #else
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;
436         char const *z_tail;
437  
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);
441  #else
442         status = sqlite3_prepare(conn->db, query, strlen(query), &conn->statement, &z_tail);
443 -- 
444 1.8.5.1
445