This is a) a quick hack to mod_auth_db.c to enable libdb4, and
b) a rewrite of mod_auth_db.module to make it easier to locate
the libdb libraries. The latter is a table driven approach which tries
to take advantage of libdb-{n} libs ({n}={2,3,4}) if found.
The patch tries to fall back to the old individual tests if the table
driven algorithm fails, so should not have a negative impact (except on
running time).
Feedback welcome. Without the patch (at least without the 1st part)
Apache-1.3 fails to compile mod_auth_db on Solaris with libdb4 installed.
Martin
--
<[EMAIL PROTECTED]> | Fujitsu Siemens
Fon: +49-89-636-46021, FAX: +49-89-636-47655 | 81730 Munich, Germany
Index: CHANGES
===================================================================
RCS file: /home/cvs/apache-1.3/src/CHANGES,v
retrieving revision 1.1842
diff -u -r1.1842 CHANGES
--- CHANGES 21 Aug 2002 13:42:41 -0000 1.1842
+++ CHANGES 29 Aug 2002 15:46:52 -0000
@@ -1,4 +1,7 @@
Changes with Apache 1.3.27
+ *) Added support for Berkeley-DB/4.x to mod_auth_db.
+ [Martin Kraemer]
+
*) Win32: Fix one byte buffer overflow in ap_get_win32_interpreter
when a CGI script's #! line does not contain a \r or \n (i.e.
a line feed character) in the first 1023 bytes. The overflow
Index: modules/standard/mod_auth_db.module
===================================================================
RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_auth_db.module,v
retrieving revision 1.9
diff -u -r1.9 mod_auth_db.module
--- modules/standard/mod_auth_db.module 16 Oct 2001 09:12:02 -0000 1.9
+++ modules/standard/mod_auth_db.module 29 Aug 2002 15:46:52 -0000
@@ -2,7 +2,69 @@
ConfigStart
DB_VERSION=''
DB_LIB=''
- if ./helpers/TestCompile func db_create; then
+ # $1 $2 $3 $4
+$5 $6 $7
+ # Checks are: <fullname> <test_op> <function_to_link> <libtotry_or_dash>
+<+cflags_or_dash> <+ldflags_or_dash> <+includefile_or_dash>
+ # Note: The include file <db.h> is included unconditionally (like in
+mod_auth_db.c)
+# "Berkeley-DB/4.x sizeof DB_PREPLIST - - <db.h>" (not sufficient because
+it doesn't find the -ldb* lib)
+ for check in \
+ "Berkeley-DB/{3,4}.x func db_create - - <db.h>" \
+ "Berkeley-DB/4.x lib db_create db-4 - <db.h>" \
+ "Berkeley-DB/4.x lib db_create db4 - <db.h>" \
+ "Berkeley-DB/3.x lib db_create db-3 - <db.h>" \
+ "Berkeley-DB/3.x lib db_create db3 - <db.h>" \
+ "Berkeley-DB/{3,4}.x lib db_create db - <db.h>" \
+ "Berkeley-DB/2.x func db_open - - <db.h>" \
+ "Berkeley-DB/2.x lib db_open db-2 - <db.h>" \
+ "Berkeley-DB/2.x lib db_open db2 - <db.h>" \
+ "Berkeley-DB/2.x lib db_open db - <db.h>" \
+ "Berkeley-DB/1.x func dbopen - - <db.h>" \
+ "Berkeley-DB/1.x lib dbopen db - <db.h>" \
+ "Berkeley-DB/1.x lib dbm_open db1 -I/usr/include/db1 <db.h>"
+ do
+ set -- $check
+ db_version="$1"
+ test_op=$2
+ db_function="$3"
+ case "$4" in
+ -) db_lib="";;
+ *) db_lib=-l"$4";
+ test_op="lib $4";;
+ esac
+ case $5 in
+ -) cflags="";;
+ *) cflags="$5";;
+ esac
+ case $6 in
+ -) tcaddincl="";;
+ *) tcaddincl="${TCADDINCL}
+#include $6";;
+ esac
+ if TCADDINCL="${tcaddincl}" INCLUDES1="$INCLUDES1 ${cflags}" TLIB="${db_lib}" \
+ ./helpers/TestCompile ${test_op} ${db_function}; then
+
+ # Special treatment for db3/db4: if the only lib we found was "-ldb", then
+ # we want to check for the typedef DB_PREPLIST which is present in 4.x only
+ case "${db_version}" in
+ *"{3,4}"*) # check ambiguous lib by looking at the header file:
+ if TCADDINCL="#include <db.h>" INCLUDES1="$INCLUDES1 ${cflags}"
+TLIB="${db_lib}" \
+ ./helpers/TestCompile sizeof DB_PREPLIST; then
+ db_version="Berkeley-DB/4.x"
+ fi;;
+ esac
+# echo >&2 "OK: ${db_version} ${test_op} ${db_function} ${db_lib} ${cflags}
+${6}"
+ DB_LIB="${db_lib}"
+ DB_VERSION="${db_version}"
+ if [ _"" != _"${cflags}" ]; then
+ CFLAGS="${CFLAGS} ${cflags}";
+ fi
+ break # use 1st available BerkeleyDB lib
+# else
+# echo >&2 "no: ${db_version} ${test_op} ${db_function} ${db_lib} ${cflags}
+${6}"
+ fi
+ done
+ if [ ".$DB_VERSION" != . ]; then
+ :
+ elif ./helpers/TestCompile func db_create; then
DB_VERSION='Berkeley-DB/3.x'
elif ./helpers/TestCompile lib db db_create; then
DB_VERSION='Berkeley-DB/3.x'
Index: modules/standard/mod_auth_db.c
===================================================================
RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_auth_db.c,v
retrieving revision 1.47
diff -u -r1.47 mod_auth_db.c
--- modules/standard/mod_auth_db.c 13 Mar 2002 21:05:33 -0000 1.47
+++ modules/standard/mod_auth_db.c 29 Aug 2002 15:46:52 -0000
@@ -105,6 +105,9 @@
#if (DB_VERSION_MAJOR == 3)
#define DB3
#endif
+#if (DB_VERSION_MAJOR == 4)
+#define DB4
+#endif
#endif
typedef struct {
@@ -167,7 +170,7 @@
q.data = user;
q.size = strlen(q.data);
-#if defined(DB3)
+#if defined(DB3) || defined(DB4)
if ( db_create(&f, NULL, 0) != 0
|| f->open(f, auth_dbpwfile, NULL, DB_HASH, DB_RDONLY, 0664) != 0) {
#elif defined(DB2)
@@ -180,7 +183,7 @@
return NULL;
}
-#if defined(DB2) || defined(DB3)
+#if defined(DB2) || defined(DB3) || defined(DB4)
if (!((f->get) (f, NULL, &q, &d, 0))) {
#else
if (!((f->get) (f, &q, &d, 0))) {
@@ -190,7 +193,7 @@
pw[d.size] = '\0'; /* Terminate the string */
}
-#if defined(DB2) || defined(DB3)
+#if defined(DB2) || defined(DB3) || defined(DB4)
(f->close) (f, 0);
#else
(f->close) (f);