dovecot-2.1: auth: Log a warning if userdb sql isn't used, but u...

dovecot at dovecot.org dovecot at dovecot.org
Wed Jan 18 23:36:21 EET 2012


details:   http://hg.dovecot.org/dovecot-2.1/rev/8822aeae8d82
changeset: 13950:8822aeae8d82
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Jan 18 23:36:13 2012 +0200
description:
auth: Log a warning if userdb sql isn't used, but user_query or iterate_query isn't default.
This is intended to stop people from wondering why user_query doesn't do
anything.

diffstat:

 src/auth/db-sql.c     |  29 +++++++++++++++++++++++++++--
 src/auth/db-sql.h     |   6 +++++-
 src/auth/passdb-sql.c |   5 +++--
 src/auth/userdb-sql.c |   2 +-
 4 files changed, 36 insertions(+), 6 deletions(-)

diffs (130 lines):

diff -r 99ea6da7dc99 -r 8822aeae8d82 src/auth/db-sql.c
--- a/src/auth/db-sql.c	Wed Jan 18 17:58:53 2012 +0200
+++ b/src/auth/db-sql.c	Wed Jan 18 23:36:13 2012 +0200
@@ -23,6 +23,7 @@
  	DEF_STR(update_query),
  	DEF_STR(iterate_query),
 	DEF_STR(default_pass_scheme),
+	DEF_BOOL(userdb_warning_disable),
 
 	{ 0, NULL, 0 }
 };
@@ -34,7 +35,8 @@
 	.user_query = "SELECT home, uid, gid FROM users WHERE username = '%n' AND domain = '%d'",
 	.update_query = "UPDATE users SET password = '%w' WHERE username = '%n' AND domain = '%d'",
 	.iterate_query = "SELECT username, domain FROM users",
-	.default_pass_scheme = "MD5"
+	.default_pass_scheme = "MD5",
+	.userdb_warning_disable = FALSE
 };
 
 static struct sql_connection *connections = NULL;
@@ -58,13 +60,15 @@
 				       &conn->set, key, value);
 }
 
-struct sql_connection *db_sql_init(const char *config_path)
+struct sql_connection *db_sql_init(const char *config_path, bool userdb)
 {
 	struct sql_connection *conn;
 	pool_t pool;
 
 	conn = sql_conn_find(config_path);
 	if (conn != NULL) {
+		if (userdb)
+			conn->userdb_used = TRUE;
 		conn->refcount++;
 		return conn;
 	}
@@ -75,6 +79,7 @@
 	pool = pool_alloconly_create("sql_connection", 1024);
 	conn = p_new(pool, struct sql_connection, 1);
 	conn->pool = pool;
+	conn->userdb_used = userdb;
 
 	conn->refcount = 1;
 
@@ -124,4 +129,24 @@
 	pool_unref(&conn->pool);
 }
 
+void db_sql_check_userdb_warning(struct sql_connection *conn)
+{
+	if (worker || conn->userdb_used || conn->set.userdb_warning_disable)
+		return;
+
+	if (strcmp(conn->set.user_query,
+		   default_sql_settings.user_query) != 0) {
+		i_warning("sql: Ignoring changed user_query in %s, "
+			  "because userdb sql not used. "
+			  "(If this is intentional, set userdb_warning_disable=yes)",
+			  conn->config_path);
+	} else if (strcmp(conn->set.iterate_query,
+			  default_sql_settings.iterate_query) != 0) {
+		i_warning("sql: Ignoring changed iterate_query in %s, "
+			  "because userdb sql not used. "
+			  "(If this is intentional, set userdb_warning_disable=yes)",
+			  conn->config_path);
+	}
+}
+
 #endif
diff -r 99ea6da7dc99 -r 8822aeae8d82 src/auth/db-sql.h
--- a/src/auth/db-sql.h	Wed Jan 18 17:58:53 2012 +0200
+++ b/src/auth/db-sql.h	Wed Jan 18 23:36:13 2012 +0200
@@ -11,6 +11,7 @@
 	const char *update_query;
 	const char *iterate_query;
 	const char *default_pass_scheme;
+	bool userdb_warning_disable;
 };
 
 struct sql_connection {
@@ -27,9 +28,12 @@
 	unsigned int default_user_query:1;
 	unsigned int default_update_query:1;
 	unsigned int default_iterate_query:1;
+	unsigned int userdb_used:1;
 };
 
-struct sql_connection *db_sql_init(const char *config_path);
+struct sql_connection *db_sql_init(const char *config_path, bool userdb);
 void db_sql_unref(struct sql_connection **conn);
 
+void db_sql_check_userdb_warning(struct sql_connection *conn);
+
 #endif
diff -r 99ea6da7dc99 -r 8822aeae8d82 src/auth/passdb-sql.c
--- a/src/auth/passdb-sql.c	Wed Jan 18 17:58:53 2012 +0200
+++ b/src/auth/passdb-sql.c	Wed Jan 18 23:36:13 2012 +0200
@@ -251,7 +251,7 @@
 	struct sql_connection *conn;
 
 	module = p_new(pool, struct sql_passdb_module, 1);
-	module->conn = conn = db_sql_init(args);
+	module->conn = conn = db_sql_init(args, FALSE);
 
 	module->module.cache_key =
 		auth_cache_parse_key(pool, conn->set.password_query);
@@ -269,7 +269,8 @@
 	module->module.blocking = (flags & SQL_DB_FLAG_BLOCKING) != 0;
 
 	if (!module->module.blocking || worker)
-                sql_connect(module->conn->db);
+		sql_connect(module->conn->db);
+	db_sql_check_userdb_warning(module->conn);
 }
 
 static void passdb_sql_deinit(struct passdb_module *_module)
diff -r 99ea6da7dc99 -r 8822aeae8d82 src/auth/userdb-sql.c
--- a/src/auth/userdb-sql.c	Wed Jan 18 17:58:53 2012 +0200
+++ b/src/auth/userdb-sql.c	Wed Jan 18 23:36:13 2012 +0200
@@ -261,7 +261,7 @@
 	struct sql_userdb_module *module;
 
 	module = p_new(pool, struct sql_userdb_module, 1);
-	module->conn = db_sql_init(args);
+	module->conn = db_sql_init(args, TRUE);
 
 	module->module.cache_key =
 		auth_cache_parse_key(pool, module->conn->set.user_query);


More information about the dovecot-cvs mailing list