dovecot-2.1: auth: Moved all i_fatal()s to preinit stage.

dovecot at dovecot.org dovecot at dovecot.org
Sat Nov 19 23:42:16 EET 2011


details:   http://hg.dovecot.org/dovecot-2.1/rev/ffb2993c99cf
changeset: 13737:ffb2993c99cf
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Nov 19 23:41:17 2011 +0200
description:
auth: Moved all i_fatal()s to preinit stage.
This avoids a wrongly configured auth process from rapidly respawning.

diffstat:

 src/auth/auth.c          |  123 +++++++++++++++++++++++-----------------------
 src/auth/passdb-passwd.c |   15 +++-
 src/auth/passdb-shadow.c |   15 +++-
 3 files changed, 81 insertions(+), 72 deletions(-)

diffs (225 lines):

diff -r 6b62d786fdc4 -r ffb2993c99cf src/auth/auth.c
--- a/src/auth/auth.c	Sat Nov 19 23:28:18 2011 +0200
+++ b/src/auth/auth.c	Sat Nov 19 23:41:17 2011 +0200
@@ -47,66 +47,6 @@
 	auth_userdb->userdb = userdb_preinit(auth->pool, set);
 }
 
-static struct auth *
-auth_preinit(const struct auth_settings *set, const char *service, pool_t pool,
-	     const struct mechanisms_register *reg)
-{
-	struct auth_passdb_settings *const *passdbs;
-	struct auth_userdb_settings *const *userdbs;
-	struct auth *auth;
-	unsigned int i, count, db_count, passdb_count, last_passdb = 0;
-
-	auth = p_new(pool, struct auth, 1);
-	auth->pool = pool;
-	auth->service = p_strdup(pool, service);
-	auth->set = set;
-	auth->reg = reg;
-
-	if (array_is_created(&set->passdbs))
-		passdbs = array_get(&set->passdbs, &db_count);
-	else {
-		passdbs = NULL;
-		db_count = 0;
-	}
-
-	/* initialize passdbs first and count them */
-	for (passdb_count = 0, i = 0; i < db_count; i++) {
-		if (passdbs[i]->master)
-			continue;
-
-		auth_passdb_preinit(auth, passdbs[i], &auth->passdbs);
-		passdb_count++;
-		last_passdb = i;
-	}
-	if (passdb_count != 0 && passdbs[last_passdb]->pass)
-		i_fatal("Last passdb can't have pass=yes");
-
-	for (i = 0; i < db_count; i++) {
-		if (!passdbs[i]->master)
-			continue;
-
-		if (passdbs[i]->deny)
-			i_fatal("Master passdb can't have deny=yes");
-		if (passdbs[i]->pass && passdb_count == 0) {
-			i_fatal("Master passdb can't have pass=yes "
-				"if there are no passdbs");
-		}
-		auth_passdb_preinit(auth, passdbs[i], &auth->masterdbs);
-	}
-
-	if (array_is_created(&set->userdbs)) {
-		userdbs = array_get(&set->userdbs, &count);
-		for (i = 0; i < count; i++)
-			auth_userdb_preinit(auth, userdbs[i]);
-	}
-
-	if (auth->userdbs == NULL) {
-		/* use a dummy userdb static. */
-		auth_userdb_preinit(auth, &userdb_dummy_set);
-	}
-	return auth;
-}
-
 static bool auth_passdb_list_have_verify_plain(struct auth *auth)
 {
 	struct auth_passdb *passdb;
@@ -185,6 +125,67 @@
 	}
 }
 
+static struct auth *
+auth_preinit(const struct auth_settings *set, const char *service, pool_t pool,
+	     const struct mechanisms_register *reg)
+{
+	struct auth_passdb_settings *const *passdbs;
+	struct auth_userdb_settings *const *userdbs;
+	struct auth *auth;
+	unsigned int i, count, db_count, passdb_count, last_passdb = 0;
+
+	auth = p_new(pool, struct auth, 1);
+	auth->pool = pool;
+	auth->service = p_strdup(pool, service);
+	auth->set = set;
+	auth->reg = reg;
+
+	if (array_is_created(&set->passdbs))
+		passdbs = array_get(&set->passdbs, &db_count);
+	else {
+		passdbs = NULL;
+		db_count = 0;
+	}
+
+	/* initialize passdbs first and count them */
+	for (passdb_count = 0, i = 0; i < db_count; i++) {
+		if (passdbs[i]->master)
+			continue;
+
+		auth_passdb_preinit(auth, passdbs[i], &auth->passdbs);
+		passdb_count++;
+		last_passdb = i;
+	}
+	if (passdb_count != 0 && passdbs[last_passdb]->pass)
+		i_fatal("Last passdb can't have pass=yes");
+
+	for (i = 0; i < db_count; i++) {
+		if (!passdbs[i]->master)
+			continue;
+
+		if (passdbs[i]->deny)
+			i_fatal("Master passdb can't have deny=yes");
+		if (passdbs[i]->pass && passdb_count == 0) {
+			i_fatal("Master passdb can't have pass=yes "
+				"if there are no passdbs");
+		}
+		auth_passdb_preinit(auth, passdbs[i], &auth->masterdbs);
+	}
+
+	if (array_is_created(&set->userdbs)) {
+		userdbs = array_get(&set->userdbs, &count);
+		for (i = 0; i < count; i++)
+			auth_userdb_preinit(auth, userdbs[i]);
+	}
+
+	if (auth->userdbs == NULL) {
+		/* use a dummy userdb static. */
+		auth_userdb_preinit(auth, &userdb_dummy_set);
+	}
+	auth_mech_list_verify_passdb(auth);
+	return auth;
+}
+
 static void auth_init(struct auth *auth)
 {
 	struct auth_passdb *passdb;
@@ -196,8 +197,6 @@
 		passdb_init(passdb->passdb);
 	for (userdb = auth->userdbs; userdb != NULL; userdb = userdb->next)
 		userdb_init(userdb->userdb);
-
-	auth_mech_list_verify_passdb(auth);
 }
 
 static void auth_deinit(struct auth *auth)
diff -r 6b62d786fdc4 -r ffb2993c99cf src/auth/passdb-passwd.c
--- a/src/auth/passdb-passwd.c	Sat Nov 19 23:28:18 2011 +0200
+++ b/src/auth/passdb-passwd.c	Sat Nov 19 23:41:17 2011 +0200
@@ -61,16 +61,21 @@
 	callback(PASSDB_RESULT_OK, request);
 }
 
-static void passwd_init(struct passdb_module *module)
+static struct passdb_module *
+passwd_preinit(pool_t pool, const char *args)
 {
+	struct passdb_module *module;
+
+	module = p_new(pool, struct passdb_module, 1);
 	module->blocking = TRUE;
-	if (strcmp(module->args, "blocking=no") == 0)
+	if (strcmp(args, "blocking=no") == 0)
 		module->blocking = FALSE;
-	else if (*module->args != '\0')
-		i_fatal("passdb passwd: Unknown setting: %s", module->args);
+	else if (*args != '\0')
+		i_fatal("passdb passwd: Unknown setting: %s", args);
 
 	module->cache_key = PASSWD_CACHE_KEY;
 	module->default_pass_scheme = PASSWD_PASS_SCHEME;
+	return module;
 }
 
 static void passwd_deinit(struct passdb_module *module ATTR_UNUSED)
@@ -81,8 +86,8 @@
 struct passdb_module_interface passdb_passwd = {
 	"passwd",
 
+	passwd_preinit,
 	NULL,
-	passwd_init,
 	passwd_deinit,
 
 	passwd_verify_plain,
diff -r 6b62d786fdc4 -r ffb2993c99cf src/auth/passdb-shadow.c
--- a/src/auth/passdb-shadow.c	Sat Nov 19 23:28:18 2011 +0200
+++ b/src/auth/passdb-shadow.c	Sat Nov 19 23:41:17 2011 +0200
@@ -57,16 +57,21 @@
 	callback(PASSDB_RESULT_OK, request);
 }
 
-static void shadow_init(struct passdb_module *module)
+static struct passdb_module *
+shadow_preinit(pool_t pool, const char *args)
 {
+	struct passdb_module *module;
+
+	module = p_new(pool, struct passdb_module, 1);
 	module->blocking = TRUE;
-	if (strcmp(module->args, "blocking=no") == 0)
+	if (strcmp(args, "blocking=no") == 0)
 		module->blocking = FALSE;
-	else if (*module->args != '\0')
-		i_fatal("passdb shadow: Unknown setting: %s", module->args);
+	else if (*args != '\0')
+		i_fatal("passdb shadow: Unknown setting: %s", args);
 
 	module->cache_key = SHADOW_CACHE_KEY;
 	module->default_pass_scheme = SHADOW_PASS_SCHEME;
+	return module;
 }
 
 static void shadow_deinit(struct passdb_module *module ATTR_UNUSED)
@@ -77,8 +82,8 @@
 struct passdb_module_interface passdb_shadow = {
 	"shadow",
 
+	shadow_preinit,
 	NULL,
-	shadow_init,
 	shadow_deinit,
 
 	shadow_verify_plain,


More information about the dovecot-cvs mailing list