Index: configure
--- configure.orig	2006-05-18 21:30:13 +0200
+++ configure	2008-12-25 18:48:51 +0100
@@ -5015,9 +5015,6 @@
 
 fi
 
-if test "$ac_cv_c_compiler_gnu" = yes; then
-  CFLAGS="-Wall -W ${CFLAGS}"
-fi
 
 
 # Check whether --with-purecov was given.
@@ -6422,7 +6419,7 @@
 	fi
 
 	saved_LIBS=$LIBS
-        for dbname in ${with_bdb} db-4.7 db4.7 db47 db-4.6 db4.6 db46 db-4.5 db4.5 db45 db-4.4 db4.4 db44 db-4.3 db4.3 db43 db-4.2 db4.2 db42 db-4.1 db4.1 db41 db-4.0 db4.0 db-4 db40 db4 db-3.3 db3.3 db33 db-3.2 db3.2 db32 db-3.1 db3.1 db31 db-3 db30 db3 db
+        for dbname in db
           do
 	    LIBS="$saved_LIBS -l$dbname"
 	    cat >conftest.$ac_ext <<_ACEOF
@@ -6526,6 +6523,54 @@
 rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
       conftest$ac_exeext conftest.$ac_ext
         fi
+        if test "$dblib" = "no"; then
+	    cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <db.h>
+int
+main ()
+{
+dbm_open(NULL, 0, 0, 0, NULL, NULL, NULL);
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  BDB_LIBADD="$BDB_LIBADD -ldb"; dblib="berkeley"; dbname=db
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+dblib="no"
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+        fi
 	LIBS=$saved_LIBS
 
 	LDFLAGS=$BDB_SAVE_LDFLAGS
@@ -7232,7 +7277,7 @@
 	fi
 
 	saved_LIBS=$LIBS
-        for dbname in ${with_bdb} db-4.7 db4.7 db47 db-4.6 db4.6 db46 db-4.5 db4.5 db45 db-4.4 db4.4 db44 db-4.3 db4.3 db43 db-4.2 db4.2 db42 db-4.1 db4.1 db41 db-4.0 db4.0 db-4 db40 db4 db-3.3 db3.3 db33 db-3.2 db3.2 db32 db-3.1 db3.1 db31 db-3 db30 db3 db
+        for dbname in db
           do
 	    LIBS="$saved_LIBS -l$dbname"
 	    cat >conftest.$ac_ext <<_ACEOF
@@ -7336,6 +7381,54 @@
 rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
       conftest$ac_exeext conftest.$ac_ext
         fi
+        if test "$dblib" = "no"; then
+	    cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <db.h>
+int
+main ()
+{
+dbm_open(NULL, 0, 0, 0, NULL, NULL, NULL);
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"
+			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  BDB_LIBADD="$BDB_LIBADD -ldb"; dblib="berkeley"; dbname=db
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+dblib="no"
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+        fi
 	LIBS=$saved_LIBS
 
 	LDFLAGS=$BDB_SAVE_LDFLAGS
@@ -14476,20 +14569,20 @@
      fi
 
      LIB_SQLITE_DIR=$LIB_SQLITE
-     LIB_SQLITE="$LIB_SQLITE -lsqlite"
+     LIB_SQLITE="$LIB_SQLITE -lsqlite3"
 
      if test -d ${with_sqlite}/include; then
          CPPFLAGS="${CPPFLAGS} -I${with_sqlite}/include"
      else
          CPPFLAGS="${CPPFLAGS} -I${with_sqlite}"
      fi
-       { $as_echo "$as_me:$LINENO: checking for sqlite_open in -lsqlite" >&5
-$as_echo_n "checking for sqlite_open in -lsqlite... " >&6; }
+       echo "$as_me:$LINENO: checking for sqlite3_open in -lsqlite3" >&5
+echo $ECHO_N "checking for sqlite3_open in -lsqlite3... $ECHO_C" >&6
 if test "${ac_cv_lib_sqlite_sqlite_open+set}" = set; then
   $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
-LIBS="-lsqlite $LIB_SQLITE_DIR $LIBS"
+LIBS="-lsqlite3 $LIB_SQLITE_DIR $LIBS"
 cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
@@ -14503,11 +14596,11 @@
 #ifdef __cplusplus
 extern "C"
 #endif
-char sqlite_open ();
+char sqlite3_open ();
 int
 main ()
 {
-return sqlite_open ();
+return sqlite3_open ();
   ;
   return 0;
 }
Index: lib/saslint.h
--- lib/saslint.h.orig	2006-04-18 22:25:45 +0200
+++ lib/saslint.h	2008-12-25 18:48:51 +0100
@@ -118,8 +118,6 @@
   const char *appname;
 } sasl_global_callbacks_t;
 
-extern sasl_global_callbacks_t global_callbacks;
-
 typedef struct _sasl_external_properties 
 {
     sasl_ssf_t ssf;
Index: lib/server.c
--- lib/server.c.orig	2006-05-17 18:46:13 +0200
+++ lib/server.c	2008-12-25 18:48:51 +0100
@@ -90,7 +90,7 @@
 
 static mech_list_t *mechlist = NULL; /* global var which holds the list */
 
-sasl_global_callbacks_t global_callbacks;
+static sasl_global_callbacks_t global_callbacks;
 
 /* set the password for a user
  *  conn        -- SASL connection
@@ -606,16 +606,8 @@
         return SASL_CONTINUE;
     }
 
-    /* get the path to the config file */
-    getconfpath_cb = _sasl_find_getconfpath_callback( global_callbacks.callbacks );
-    if (getconfpath_cb == NULL) return SASL_BADPARAM;
-
-    /* getconfpath_cb->proc MUST be a sasl_getconfpath_t; if only C had a type
-       system */
-    result = ((sasl_getconfpath_t *)(getconfpath_cb->proc))(getconfpath_cb->context,
-							    (char **) &path_to_config);
-    if (result != SASL_OK) goto done;
-    if (path_to_config == NULL) path_to_config = "";
+    result = SASL_OK;
+    path_to_config = "@l_sysconfdir@";
 
     next = path_to_config;
 
Index: plugins/sql.c
--- plugins/sql.c.orig	2006-04-07 15:42:16 +0200
+++ plugins/sql.c	2008-12-25 21:57:47 +0100
@@ -150,9 +150,15 @@
 	return -1;
     }
     if (value) {
-	strncpy(value, row[0], size-2);
-	value[size-1] = '\0';
-	if (value_len) *value_len = strlen(value);
+        unsigned long *col_lens;
+        size_t col_len;
+        col_lens = mysql_fetch_lengths(result);
+        col_len = (size_t)col_lens[0];
+        if (col_len > size - 1);
+            col_len = size - 1;
+	memcpy(value, row[0], col_len);
+	value[col_len] = '\0';
+	if (value_len) *value_len = col_len;
     }
     
     /* free result */
@@ -277,7 +283,7 @@
     ExecStatusType status;
     
     /* run the query */
-    result = PQexec(conn, cmd);
+    result = PQexecParams(conn, cmd, 0, NULL, NULL, NULL, NULL, 1);
     
     /* check the status */
     status = PQresultStatus(result);
@@ -298,6 +304,7 @@
     row_count = PQntuples(result);
     if (!row_count) {
 	/* umm nothing found */
+	utils->log(NULL, SASL_LOG_DEBUG, "sql plugin: no result found for query %s", cmd);
 	utils->log(NULL, SASL_LOG_NOTE, "sql plugin: no result found");
 	PQclear(result);
 	return -1;
@@ -310,9 +317,26 @@
     /* now get the result set value and value_len */
     /* we only fetch one because we don't care about the rest */
     if (value) {
-	strncpy(value, PQgetvalue(result,0,0), size-2);
-	value[size-1] = '\0';
-	if (value_len) *value_len = strlen(value);
+        if (PQgetisnull(result, 0, 0)) {
+            size_t col_len;
+            col_len = strlen(SQL_NULL_VALUE);
+            if (col_len > size - 1)
+                col_len = size - 1;
+            memcpy(value, SQL_NULL_VALUE, col_len);
+            value[col_len] = '\0';
+            if (value_len)
+                *value_len = col_len;
+        }
+        else {
+            size_t col_len;
+            col_len = (size_t)PQgetlength(result, 0, 0);
+            if (col_len > size - 1);
+                col_len = size - 1;
+            memcpy(value, PQgetvalue(result, 0, 0), col_len);
+            value[col_len] = '\0';
+            if (value_len)
+                *value_len = col_len;
+        }
     }
     
     /* free result */
@@ -342,7 +366,7 @@
 #endif /* HAVE_PGSQL */
 
 #ifdef HAVE_SQLITE
-#include <sqlite.h>
+#include <sqlite3.h>
 
 static void *_sqlite_open(char *host __attribute__((unused)),
 			  char *port __attribute__((unused)),
@@ -352,21 +376,23 @@
 			  const char *database, const sasl_utils_t *utils)
 {
     int rc;
-    sqlite *db;
+    sqlite3 *db;
     char *zErrMsg = NULL;
 
-    db = sqlite_open(database, 0, &zErrMsg);
-    if (db == NULL) {
+    rc = sqlite3_open(database, &db);
+    if (rc != SQLITE_OK) {
+	zErrMsg = (char *)sqlite3_errmsg(db);
 	utils->log(NULL, SASL_LOG_ERR, "sql plugin: %s", zErrMsg);
-	sqlite_freemem (zErrMsg);
+	sqlite3_free (zErrMsg);
+	sqlite3_close (db);
 	return NULL;
     }
 
-    rc = sqlite_exec(db, "PRAGMA empty_result_callbacks = ON", NULL, NULL, &zErrMsg);
+    rc = sqlite3_exec(db, "PRAGMA empty_result_callbacks = ON", NULL, NULL, &zErrMsg);
     if (rc != SQLITE_OK) {
 	utils->log(NULL, SASL_LOG_ERR, "sql plugin: %s", zErrMsg);
-	sqlite_freemem (zErrMsg);
-	sqlite_close(db);
+	sqlite3_free (zErrMsg);
+	sqlite3_close(db);
 	return NULL;
     }
 
@@ -388,62 +414,67 @@
     return 0;
 }
 
-static int sqlite_my_callback(void *pArg, int argc __attribute__((unused)),
-			      char **argv,
-			      char **columnNames __attribute__((unused)))
-{
-    char **result = (char**)pArg;
-
-    if (argv == NULL) {
-	*result = NULL;				/* no record */
-    } else if (argv[0] == NULL) {
-	*result = strdup(SQL_NULL_VALUE);	/* NULL IS SQL_NULL_VALUE */
-    } else {
-	*result = strdup(argv[0]);
-    }
-
-    return /*ABORT*/1;
-}
-
 static int _sqlite_exec(void *db, const char *cmd, char *value, size_t size,
 		        size_t *value_len, const sasl_utils_t *utils)
 {
     int rc;
-    char *result = NULL;
-    char *zErrMsg = NULL;
+    sqlite3_stmt *stmt;
+    const char *todo;
+    size_t len;
 
-    rc = sqlite_exec((sqlite*)db, cmd, sqlite_my_callback, (void*)&result, &zErrMsg);
-    if (rc != SQLITE_OK && rc != SQLITE_ABORT) {
-	utils->log(NULL, SASL_LOG_DEBUG, "sql plugin: %s ", zErrMsg);
-	sqlite_freemem (zErrMsg);
+    rc = sqlite3_prepare((sqlite3*)db, cmd, (int)strlen(cmd), &stmt, &todo);
+    if (rc != SQLITE_OK) {
+	utils->log(NULL, SASL_LOG_DEBUG, "sql plugin error: %s", sqlite3_errmsg((sqlite3*)db));
 	return -1;
     }
-
-    if (rc == SQLITE_OK) {
+    rc = sqlite3_step(stmt);
+    if (rc != SQLITE_ROW && rc != SQLITE_DONE) {
+	utils->log(NULL, SASL_LOG_DEBUG, "sql plugin error: %s", sqlite3_errmsg((sqlite3*)db));
+	sqlite3_finalize(stmt);
+	return -1;
+    }
+    if (sqlite3_column_count(stmt) == 0) {
 	/* no results (BEGIN, COMMIT, DELETE, INSERT, UPDATE) */
+	sqlite3_finalize(stmt);
 	return 0;
     }
-
-    if (result == NULL) {
+    if (rc == SQLITE_DONE) {
 	/* umm nothing found */
+	utils->log(NULL, SASL_LOG_DEBUG, "sql plugin: no result found for query %s", cmd);
 	utils->log(NULL, SASL_LOG_NOTE, "sql plugin: no result found");
+	sqlite3_finalize(stmt);
 	return -1;
     }
-
-    /* XXX: Duplication cannot be found by this method. */
-
-    /* now get the result set value and value_len */
-    /* we only fetch one because we don't care about the rest */
-    if (value) {
-	strncpy(value, result, size - 2);
-	value[size - 1] = '\0';
-	if (value_len) {
-	    *value_len = strlen(value);
-	}
+    rc = sqlite3_column_type(stmt, 0);
+    switch (rc) {
+        case SQLITE_NULL: {
+            len = strlen(SQL_NULL_VALUE);
+            if (len > size - 1)
+                len = size - 1;
+	    memcpy(value, SQL_NULL_VALUE, len);
+            value[len] = '\0';
+	    if (value_len)
+	        *value_len = len;
+            break;
+        }
+        default: {
+            const void *blob = sqlite3_column_blob(stmt, 0);
+            len = (size_t)sqlite3_column_bytes(stmt, 0);
+            if (len > size - 1)
+                len = size - 1;
+	    memcpy(value, blob, len);
+            value[len] = '\0';
+	    if (value_len)
+	        *value_len = len;
+            break;
+        }
     }
-
-    /* free result */
-    free(result);
+    rc = sqlite3_step(stmt);
+    if (rc != SQLITE_DONE) {
+	utils->log(NULL, SASL_LOG_WARN,
+		   "sql plugin: found duplicate row for query %s", cmd);
+    }
+    sqlite3_finalize(stmt);
     return 0;
 }
 
@@ -464,7 +495,7 @@
 
 static void _sqlite_close(void *db)
 {
-    sqlite_close((sqlite*)db);
+    sqlite3_close((sqlite3 *)db);
 }
 #endif /* HAVE_SQLITE */
 
@@ -918,7 +949,7 @@
     settings = (sql_settings_t *) glob_context;
     
     sparams->utils->log(NULL, SASL_LOG_DEBUG,
-			"sql plugin Parse the username %s\n", user);
+			"sql plugin parse the username %s\n", user);
     
     user_buf = sparams->utils->malloc(ulen + 1);
     if (!user_buf) {
@@ -1022,7 +1053,7 @@
 	}
     
 	sparams->utils->log(NULL, SASL_LOG_DEBUG,
-			    "sql plugin create statement from %s %s %s\n",
+			    "sql plugin create statement from name=%s user=%s realm=%s\n",
 			    realname, escap_userid, escap_realm);
 	
 	/* create a statement that we will use */
@@ -1043,12 +1074,18 @@
 	/* run the query */
 	if (!settings->sql_engine->sql_exec(conn, query, value, sizeof(value),
 					    &value_len, sparams->utils)) {
+            sparams->utils->log(NULL, SASL_LOG_DEBUG,
+                                "sql plugin query successful\n");
 	    sparams->utils->prop_set(sparams->propctx,
 				     cur->name,
 				     value,
 				     (int)value_len);
 	    ret = SASL_OK;
 	}
+        else {
+            sparams->utils->log(NULL, SASL_LOG_DEBUG,
+                                "sql plugin query failed\n");
+        }
 	
 	sparams->utils->free(query);
     }
Index: sample/client.c
--- sample/client.c.orig	2004-03-09 18:35:32 +0100
+++ sample/client.c	2008-12-25 18:48:51 +0100
@@ -137,13 +137,11 @@
     return SASL_OK;
 }
 
-#ifndef HAVE_GETPASSPHRASE
 static char *
-getpassphrase(const char *prompt)
+my_getpassphrase(const char *prompt)
 {
   return getpass(prompt);
 }
-#endif /* ! HAVE_GETPASSPHRASE */
 
 static int
 getsecret(sasl_conn_t *conn,
@@ -159,7 +157,7 @@
     if (! conn || ! psecret || id != SASL_CB_PASS)
 	return SASL_BADPARAM;
 
-    password = getpassphrase("Password: ");
+    password = my_getpassphrase("Password: ");
     if (! password)
 	return SASL_FAIL;
 
Index: sample/sample-client.c
--- sample/sample-client.c.orig	2004-10-26 13:14:33 +0200
+++ sample/sample-client.c	2008-12-25 18:48:51 +0100
@@ -245,13 +245,11 @@
   return SASL_OK;
 }
 
-#ifndef HAVE_GETPASSPHRASE
 static char *
-getpassphrase(const char *prompt)
+my_getpassphrase(const char *prompt)
 {
   return getpass(prompt);
 }
-#endif /* ! HAVE_GETPASSPHRASE */
 
 static int
 getsecret(sasl_conn_t *conn,
@@ -265,7 +263,7 @@
   if (! conn || ! psecret || id != SASL_CB_PASS)
     return SASL_BADPARAM;
 
-  password = getpassphrase("Password: ");
+  password = my_getpassphrase("Password: ");
   if (! password)
     return SASL_FAIL;
 
@@ -308,7 +306,7 @@
   fflush(stdout);
   
   if (id == SASL_CB_ECHOPROMPT) {
-    char *original = getpassphrase("");
+    char *original = my_getpassphrase("");
     if (! original)
       return SASL_FAIL;
     if (*original)
Index: saslauthd/Makefile.am
--- saslauthd/Makefile.am.orig	2006-05-17 18:46:17 +0200
+++ saslauthd/Makefile.am	2008-12-25 18:48:51 +0100
@@ -36,4 +36,4 @@
 
 install-data-local: saslauthd.8
 	$(mkinstalldirs) $(DESTDIR)$(mandir)/man8
-	$(INSTALL_DATA) $(srcdir)/saslauthd.8 $(DESTDIR)$(mandir)/man8/saslauthd.8
+	$(INSTALL_DATA) $(srcdir)/saslauthd.mdoc $(DESTDIR)$(mandir)/man8/saslauthd.8
Index: saslauthd/Makefile.in
--- saslauthd/Makefile.in.orig	2008-12-25 18:48:51 +0100
+++ saslauthd/Makefile.in	2008-12-25 18:48:51 +0100
@@ -722,7 +722,7 @@
 
 install-data-local: saslauthd.8
 	$(mkinstalldirs) $(DESTDIR)$(mandir)/man8
-	$(INSTALL_DATA) $(srcdir)/saslauthd.8 $(DESTDIR)$(mandir)/man8/saslauthd.8
+	$(INSTALL_DATA) $(srcdir)/saslauthd.mdoc $(DESTDIR)$(mandir)/man8/saslauthd.8
 
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
Index: saslauthd/lak.c
--- saslauthd/lak.c.orig	2005-05-15 07:49:51 +0200
+++ saslauthd/lak.c	2008-12-25 18:48:51 +0100
@@ -47,6 +47,7 @@
 #include <crypt.h>
 #endif
 
+#include "saslauthd.h" /* get strlcpy macro for non-BSD; get HAVE_OPENSSL from config.h */
 #ifdef HAVE_OPENSSL
 #ifndef OPENSSL_DISABLE_OLD_DES_SUPPORT
 #define OPENSSL_DISABLE_OLD_DES_SUPPORT
@@ -58,7 +59,7 @@
 #define LDAP_DEPRECATED 1
 #include <ldap.h>
 #include <lber.h>
-#include <sasl.h>
+#include "sasl.h"
 #include "lak.h"
 
 typedef struct lak_auth_method {
