]> eyrie.org Git - kerberos/krb5-strength.git/commitdiff
Add real Autoconf probing for SQLite
authorRuss Allbery <eagle@eyrie.org>
Tue, 25 Mar 2014 08:07:27 +0000 (01:07 -0700)
committerRuss Allbery <eagle@eyrie.org>
Tue, 25 Mar 2014 08:07:27 +0000 (01:07 -0700)
Change all the defines to look for HAVE_SQLITE instead of
HAVE_SQLITE3, since non-v3 versions are so old that I'm not going
to worry about the naming.  Add an Autoconf probe for SQLite that
tries pkg-config first and falls back on library probing.

Makefile.am
configure.ac
m4/sqlite.m4 [new file with mode: 0644]
plugin/internal.h
plugin/sqlite.c
tests/plugin/heimdal-t.c
tests/plugin/mit-t.c

index c2286f9583e2dda3ab8ef493b28299d73c7fc1fe..3debeb823a3a725caa03e5bf81fc7a287fe49c71 100644 (file)
@@ -22,10 +22,12 @@ EXTRA_DIST = .gitignore LICENSE autogen cracklib/HISTORY cracklib/LICENCE  \
        tests/util/xmalloc-t tools/heimdal-strength.pod
 
 # Do this globally.  Everything needs to find the Kerberos headers and
-# libraries, and if we're using the system CrackLib or libcdb, add its
-# location unconditionally as well.
-AM_CPPFLAGS = $(CRACKLIB_CPPFLAGS) $(KRB5_CPPFLAGS) $(CDB_CPPFLAGS)
-AM_LDFLAGS = $(CRACKLIB_LDFLAGS) $(KRB5_LDFLAGS) $(CDB_LDFLAGS)
+# libraries, and if we're using the system CrackLib, TinyCDB, or SQLite, add
+# its location unconditionally as well.
+AM_CPPFLAGS = $(CRACKLIB_CPPFLAGS) $(KRB5_CPPFLAGS) $(CDB_CPPFLAGS) \
+       $(SQLITE_CPPFLAGS)
+AM_LDFLAGS = $(CRACKLIB_LDFLAGS) $(KRB5_LDFLAGS) $(CDB_LDFLAGS) \
+       $(SQLITE_LDFLAGS)
 
 # Build our portability library.
 noinst_LTLIBRARIES = portable/libportable.la
@@ -66,7 +68,8 @@ if EMBEDDED_CRACKLIB
 else
     plugin_strength_la_LIBADD = $(CRACKLIB_LIBS)
 endif
-plugin_strength_la_LIBADD += portable/libportable.la $(KRB5_LIBS) $(CDB_LIBS)
+plugin_strength_la_LIBADD += portable/libportable.la $(KRB5_LIBS) \
+       $(CDB_LIBS) $(SQLITE_LIBS)
 
 # The Heimdal external check program.
 bin_PROGRAMS = tools/heimdal-strength
@@ -81,7 +84,7 @@ else
     tools_heimdal_strength_LDADD = $(CRACKLIB_LIBS)
 endif
 tools_heimdal_strength_LDADD += util/libutil.a portable/libportable.la \
-       $(KRB5_LIBS) $(CDB_LIBS)
+       $(KRB5_LIBS) $(CDB_LIBS) $(SQLITE_LIBS)
 
 # Other tools.
 dist_bin_SCRIPTS = tools/heimdal-history tools/krb5-strength-wordlist
index 89bcc9e7cd4e7a8bde1a8f54f04655a3c6e27ed0..508e89db82e4d02f5d6596529557eaf87a32db06 100644 (file)
@@ -50,11 +50,7 @@ AC_CHECK_FUNCS([krb5_get_init_creds_opt_free],
 AC_CHECK_DECLS([krb5_kt_free_entry], [], [], [RRA_INCLUDES_KRB5])
 AC_LIBOBJ([krb5-extra])
 RRA_LIB_KRB5_RESTORE
-
-dnl Temporary hack to force building with SQLite.
-AC_CHECK_HEADERS([sqlite3.h])
-AC_DEFINE([HAVE_SQLITE3], 1, [Define if SQLite 3 is available.])
-LIBS="$LIBS -lsqlite3"
+RRA_LIB_SQLITE_OPTIONAL
 
 dnl Probe for libdl, which is used for the test suite.
 save_LIBS="$LIBS"
diff --git a/m4/sqlite.m4 b/m4/sqlite.m4
new file mode 100644 (file)
index 0000000..d17ca9b
--- /dev/null
@@ -0,0 +1,78 @@
+dnl Find the compiler and linker flags for SQLite.
+dnl
+dnl Finds the compiler and linker flags for linking with the SQLite library.
+dnl Provides the --with-sqlite, --with-sqlite-lib, and --with-sqlite-include
+dnl configure options to specify non-standard paths to the SQLite libraries or
+dnl header files.  Currently, only SQLite 3 is considered sufficient.
+dnl
+dnl Provides the macros RRA_LIB_SQLITE and RRA_LIB_SQLITE_OPTIONAL and sets
+dnl the substitution variables SQLITE_CPPFLAGS, SQLITE_LDFLAGS, and
+dnl SQLITE_LIBS.  Also provides RRA_LIB_SQLITE_SWITCH to set CPPFLAGS,
+dnl LDFLAGS, and LIBS to include the SQLite libraries, saving the current
+dnl values first, and RRA_LIB_SQLITE_RESTORE to restore those settings to
+dnl before the last RRA_LIB_SQLITE_SWITCH.  Defines HAVE_SQLITE and sets
+dnl rra_use_SQLITE to true if libevent is found.  If it isn't found, the
+dnl substitution variables will be empty.
+dnl
+dnl Depends on the lib-helper.m4 framework.
+dnl
+dnl The canonical version of this file is maintained in the rra-c-util
+dnl package, available at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
+dnl
+dnl Written by Russ Allbery <eagle@eyrie.org>
+dnl Copyright 2014
+dnl     The Board of Trustees of the Leland Stanford Junior University
+dnl
+dnl This file is free software; the authors give unlimited permission to copy
+dnl and/or distribute it, with or without modifications, as long as this
+dnl notice is preserved.
+
+dnl Save the current CPPFLAGS, LDFLAGS, and LIBS settings and switch to
+dnl versions that include the libevent flags.  Used as a wrapper, with
+dnl RRA_LIB_SQLITE_RESTORE, around tests.
+AC_DEFUN([RRA_LIB_SQLITE_SWITCH], [RRA_LIB_HELPER_SWITCH([SQLITE])])
+
+dnl Restore CPPFLAGS, LDFLAGS, and LIBS to their previous values before
+dnl RRA_LIB_SQLITE_SWITCH was called.
+AC_DEFUN([RRA_LIB_SQLITE_RESTORE], [RRA_LIB_HELPER_RESTORE([SQLITE])])
+
+dnl Checks if SQLite is present.  The single argument, if "true", says to fail
+dnl if the SQLite library could not be found.  Prefer probing with pkg-config
+dnl if available and the --with flags were not given.
+AC_DEFUN([_RRA_LIB_SQLITE_INTERNAL],
+[RRA_LIB_HELPER_PATHS([SQLITE])
+ AS_IF([test x"$SQLITE_CPPFLAGS" = x && test x"$SQLITE_LDFLAGS" = x],
+    [PKG_CHECK_EXISTS([sqlite3],
+        [PKG_CHECK_MODULES([SQLITE], [sqlite3])
+         SQLITE_CPPFLAGS="$SQLITE_CFLAGS"])])
+ AS_IF([test x"$SQLITE_LIBS" = x],
+    [RRA_LIB_SQLITE_SWITCH
+     LIBS=
+     AC_SEARCH_LIBS([sqlite3_open_v2], [sqlite3],
+        [SQLITE_LIBS="$LIBS"],
+        [AS_IF([test x"$1" = xtrue],
+            [AC_MSG_ERROR([cannot find usable SQLite library])])])
+     RRA_LIB_SQLITE_RESTORE])
+ RRA_LIB_SQLITE_SWITCH
+ AC_CHECK_HEADERS([sqlite3.h])
+ RRA_LIB_SQLITE_RESTORE])
+
+dnl The main macro for packages with mandatory SQLite 3 support.
+AC_DEFUN([RRA_LIB_SQLITE],
+[RRA_LIB_HELPER_VAR_INIT([SQLITE])
+ RRA_LIB_HELPER_WITH([sqlite], [SQLite], [SQLITE])
+ _RRA_LIB_SQLITE_INTERNAL([true])
+ rra_use_SQLITE=true
+ AC_DEFINE([HAVE_SQLITE], 1, [Define if SQLite is available.])])
+
+dnl The main macro for packages with optional SQLite support.
+AC_DEFUN([RRA_LIB_SQLITE_OPTIONAL],
+[RRA_LIB_HELPER_VAR_INIT([SQLITE])
+ RRA_LIB_HELPER_WITH_OPTIONAL([sqlite], [SQLite], [SQLITE])
+ AS_IF([test x"$rra_use_SQLITE" != xfalse],
+    [AS_IF([test x"$rra_use_SQLITE" = xtrue],
+        [_RRA_LIB_SQLITE_INTERNAL([true])],
+        [_RRA_LIB_SQLITE_INTERNAL([false])])])
+ AS_IF([test x"$SQLITE_LIBS" != x],
+    [rra_use_SQLITE=true
+     AC_DEFINE([HAVE_SQLITE], 1, [Define if SQLite is available.])])])
index 72b5a12a19565d6d171d0e5dd2161790b9f8959a..a32832192c1eec8908c8111de505b2de40b20c4f 100644 (file)
@@ -145,7 +145,7 @@ krb5_error_code strength_check_cracklib(krb5_context, krb5_pwqual_moddata,
  * requested and not available.
  */
 krb5_error_code strength_init_sqlite(krb5_context, krb5_pwqual_moddata);
-#ifdef HAVE_SQLITE3
+#ifdef HAVE_SQLITE
 krb5_error_code strength_check_sqlite(krb5_context, krb5_pwqual_moddata,
                                       const char *password);
 void strength_close_sqlite(krb5_context, krb5_pwqual_moddata);
index c6fd2d6b40d8f14618764a8045bf73109dd9358d..707223c28aa89498bd37e268d05abd90a251a54b 100644 (file)
@@ -62,7 +62,7 @@
 /*
  * Stub for strength_init_sqlite if not built with SQLite support.
  */
-#ifndef HAVE_SQLITE3
+#ifndef HAVE_SQLITE
 krb5_error_code
 strength_init_sqlite(krb5_context ctx, krb5_pwqual_moddata data UNUSED)
 {
@@ -83,7 +83,7 @@ strength_init_sqlite(krb5_context ctx, krb5_pwqual_moddata data UNUSED)
 
 
 /* Skip the rest of this file if SQLite is not available. */
-#ifdef HAVE_SQLITE3
+#ifdef HAVE_SQLITE
 
 /*
  * Report a SQLite error.  Takes the SQLite error code and the Kerberos
@@ -393,4 +393,4 @@ strength_close_sqlite(krb5_context ctx UNUSED, krb5_pwqual_moddata data)
         sqlite3_close_v2(data->sqlite);
 }
 
-#endif /* HAVE_CDB */
+#endif /* HAVE_SQLITE */
index 6fc561870265e881d23f0c468a86b5b7976b948a..8ea373b7ea22b843f216bc105786523b1d576b4c 100644 (file)
@@ -254,7 +254,7 @@ main(void)
 
 #endif /* !HAVE_CDB */
 
-#ifdef HAVE_SQLITE3
+#ifdef HAVE_SQLITE
 
     /*
      * If built with SQLite, set up krb5.conf to use a SQLite dictionary
@@ -276,13 +276,13 @@ main(void)
     for (i = 0; i < ARRAY_SIZE(principal_tests); i++)
         is_password_test(verifier, &principal_tests[i]);
 
-#else /* !HAVE_SQLITE3 */
+#else /* !HAVE_SQLITE */
 
     /* Otherwise, mark the SQLite tests as skipped. */
     count = ARRAY_SIZE(sqlite_tests) + ARRAY_SIZE(principal_tests);
     skip_block(count * 2 + 1, "not built with SQLite support");
 
-#endif /* !HAVE_SQLITE3 */
+#endif /* !HAVE_SQLITE */
 
     /* Manually clean up after the results of make-krb5-conf. */
     basprintf(&path, "%s/krb5.conf", tmpdir);
index 09401c3101a163109d7477056d97f7b1c7bc44bc..5922ab9a2d8deda95e7845892f9874a064502055 100644 (file)
@@ -354,7 +354,7 @@ main(void)
 
 #endif /* !HAVE_CDB */
 
-#ifdef HAVE_SQLITE3
+#ifdef HAVE_SQLITE
 
     /*
      * If built with SQLite, set up krb5.conf to use a SQLite dictionary
@@ -388,13 +388,13 @@ main(void)
         is_password_test(ctx, vtable, data, &principal_tests[i]);
     vtable->close(ctx, data);
 
-#else /* !HAVE_SQLITE3 */
+#else /* !HAVE_SQLITE */
 
     /* Otherwise, mark the SQLite tests as skipped. */
     count = ARRAY_SIZE(sqlite_tests) + ARRAY_SIZE(principal_tests);
     skip_block(count * 2 + 1, "not built with SQLite support");
 
-#endif /* !HAVE_SQLITE3 */
+#endif /* !HAVE_SQLITE */
 
     /* Manually clean up after the results of make-krb5-conf. */
     basprintf(&path, "%s/krb5.conf", tmpdir);