Blame SOURCES/dovecot-2.3.19.1-7bad6a24.patch

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