Blame SOURCES/dovecot-2.3.19.1-7bad6a24.patch

0b789d
From 7bad6a24160e34bce8f10e73dbbf9e5fbbcd1904 Mon Sep 17 00:00:00 2001
0b789d
From: Timo Sirainen <timo.sirainen@open-xchange.com>
0b789d
Date: Mon, 9 May 2022 15:23:33 +0300
0b789d
Subject: [PATCH] auth: Fix handling passdbs with identical driver/args but
0b789d
 different mechanisms/username_filter
0b789d
0b789d
The passdb was wrongly deduplicated in this situation, causing wrong
0b789d
mechanisms or username_filter setting to be used. This would be a rather
0b789d
unlikely configuration though.
0b789d
0b789d
Fixed by moving mechanisms and username_filter from struct passdb_module
0b789d
to struct auth_passdb, which is where they should have been in the first
0b789d
place.
0b789d
---
0b789d
 src/auth/auth-request.c |  6 +++---
0b789d
 src/auth/auth.c         | 18 ++++++++++++++++++
0b789d
 src/auth/auth.h         |  5 +++++
0b789d
 src/auth/passdb.c       | 15 ++-------------
0b789d
 src/auth/passdb.h       |  4 ----
0b789d
 5 files changed, 28 insertions(+), 20 deletions(-)
0b789d
0b789d
diff --git a/src/auth/auth-request.c b/src/auth/auth-request.c
0b789d
index cd08b1fa02..0ca29f3674 100644
0b789d
--- a/src/auth/auth-request.c
0b789d
+++ b/src/auth/auth-request.c
0b789d
@@ -534,8 +534,8 @@ auth_request_want_skip_passdb(struct auth_request *request,
0b789d
 			      struct auth_passdb *passdb)
0b789d
 {
0b789d
 	/* if mechanism is not supported, skip */
0b789d
-	const char *const *mechs = passdb->passdb->mechanisms;
0b789d
-	const char *const *username_filter = passdb->passdb->username_filter;
0b789d
+	const char *const *mechs = passdb->mechanisms;
0b789d
+	const char *const *username_filter = passdb->username_filter;
0b789d
 	const char *username;
0b789d
 
0b789d
 	username = request->fields.user;
0b789d
@@ -548,7 +548,7 @@ auth_request_want_skip_passdb(struct auth_request *request,
0b789d
 		return TRUE;
0b789d
 	}
0b789d
 
0b789d
-	if (passdb->passdb->username_filter != NULL &&
0b789d
+	if (passdb->username_filter != NULL &&
0b789d
 	    !auth_request_username_accepted(username_filter, username)) {
0b789d
 		auth_request_log_debug(request,
0b789d
 				       request->mech != NULL ? AUTH_SUBSYS_MECH
0b789d
diff --git a/src/auth/auth.c b/src/auth/auth.c
0b789d
index f2f3fda20c..9f6c4ba60c 100644
0b789d
--- a/src/auth/auth.c
0b789d
+++ b/src/auth/auth.c
0b789d
@@ -99,6 +99,24 @@ auth_passdb_preinit(struct auth *auth, const struct auth_passdb_settings *set,
0b789d
 	auth_passdb->override_fields_tmpl =
0b789d
 		passdb_template_build(auth->pool, set->override_fields);
0b789d
 
0b789d
+	if (*set->mechanisms == '\0') {
0b789d
+		auth_passdb->mechanisms = NULL;
0b789d
+	} else if (strcasecmp(set->mechanisms, "none") == 0) {
0b789d
+		auth_passdb->mechanisms = (const char *const[]){ NULL };
0b789d
+	} else {
0b789d
+		auth_passdb->mechanisms =
0b789d
+			(const char *const *)p_strsplit_spaces(auth->pool,
0b789d
+				set->mechanisms, " ,");
0b789d
+	}
0b789d
+
0b789d
+	if (*set->username_filter == '\0') {
0b789d
+		auth_passdb->username_filter = NULL;
0b789d
+	} else {
0b789d
+		auth_passdb->username_filter =
0b789d
+			(const char *const *)p_strsplit_spaces(auth->pool,
0b789d
+				set->username_filter, " ,");
0b789d
+	}
0b789d
+
0b789d
 	/* for backwards compatibility: */
0b789d
 	if (set->pass)
0b789d
 		auth_passdb->result_success = AUTH_DB_RULE_CONTINUE;
0b789d
diff --git a/src/auth/auth.h b/src/auth/auth.h
0b789d
index f700e29d5c..460a179765 100644
0b789d
--- a/src/auth/auth.h
0b789d
+++ b/src/auth/auth.h
0b789d
@@ -41,6 +41,11 @@ struct auth_passdb {
0b789d
 	struct passdb_template *default_fields_tmpl;
0b789d
 	struct passdb_template *override_fields_tmpl;
0b789d
 
0b789d
+	/* Supported authentication mechanisms, NULL is all, {NULL} is none */
0b789d
+	const char *const *mechanisms;
0b789d
+	/* Username filter, NULL is no filter */
0b789d
+	const char *const *username_filter;
0b789d
+
0b789d
 	enum auth_passdb_skip skip;
0b789d
 	enum auth_db_rule result_success;
0b789d
 	enum auth_db_rule result_failure;
0b789d
diff --git a/src/auth/passdb.c b/src/auth/passdb.c
0b789d
index eb4ac8ae82..f5eed1af4f 100644
0b789d
--- a/src/auth/passdb.c
0b789d
+++ b/src/auth/passdb.c
0b789d
@@ -224,19 +224,8 @@ passdb_preinit(pool_t pool, const struct auth_passdb_settings *set)
0b789d
 	passdb->id = ++auth_passdb_id;
0b789d
 	passdb->iface = *iface;
0b789d
 	passdb->args = p_strdup(pool, set->args);
0b789d
-	if (*set->mechanisms == '\0') {
0b789d
-		passdb->mechanisms = NULL;
0b789d
-	} else if (strcasecmp(set->mechanisms, "none") == 0) {
0b789d
-		passdb->mechanisms = (const char *const[]){NULL};
0b789d
-	} else {
0b789d
-		passdb->mechanisms = (const char* const*)p_strsplit_spaces(pool, set->mechanisms, " ,");
0b789d
-	}
0b789d
-
0b789d
-	if (*set->username_filter == '\0') {
0b789d
-		passdb->username_filter = NULL;
0b789d
-	} else {
0b789d
-		passdb->username_filter = (const char* const*)p_strsplit_spaces(pool, set->username_filter, " ,");
0b789d
-	}
0b789d
+	/* NOTE: if anything else than driver & args are added here,
0b789d
+	   passdb_find() also needs to be updated. */
0b789d
 	array_push_back(&passdb_modules, &passdb);
0b789d
 	return passdb;
0b789d
 }
0b789d
diff --git a/src/auth/passdb.h b/src/auth/passdb.h
0b789d
index 2e95328e5c..e466a9fdb6 100644
0b789d
--- a/src/auth/passdb.h
0b789d
+++ b/src/auth/passdb.h
0b789d
@@ -63,10 +63,6 @@ struct passdb_module {
0b789d
 	/* Default password scheme for this module.
0b789d
 	   If default_cache_key is set, must not be NULL. */
0b789d
 	const char *default_pass_scheme;
0b789d
-	/* Supported authentication mechanisms, NULL is all, [NULL] is none*/
0b789d
-	const char *const *mechanisms;
0b789d
-	/* Username filter, NULL is no filter */
0b789d
-	const char *const *username_filter;
0b789d
 
0b789d
 	/* If blocking is set to TRUE, use child processes to access
0b789d
 	   this passdb. */