Blame SOURCES/dovecot-2.3.19.1-7bad6a24.patch

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