dovecot-2.0: auth: Completely removed struct auth_*db from *db.c

dovecot at dovecot.org dovecot at dovecot.org
Sat Mar 13 23:33:43 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/7909611180a8
changeset: 10900:7909611180a8
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Mar 13 21:05:31 2010 +0200
description:
auth: Completely removed struct auth_*db from *db.c

diffstat:

 src/auth/auth.c   |  45 ++++++++++++++++++++++++++++++++++++++-------
 src/auth/passdb.c |  51 ++++++++++++++++++++++-----------------------------
 src/auth/passdb.h |  10 ++++++----
 src/auth/userdb.c |  50 +++++++++++++++++++++-----------------------------
 src/auth/userdb.h |  10 ++++++----
 5 files changed, 93 insertions(+), 73 deletions(-)

diffs (truncated from 313 to 300 lines):

diff -r cff28ea08c4a -r 7909611180a8 src/auth/auth.c
--- a/src/auth/auth.c	Sat Mar 13 20:19:53 2010 +0200
+++ b/src/auth/auth.c	Sat Mar 13 21:05:31 2010 +0200
@@ -20,6 +20,36 @@
 	.args = ""
 };
 
+static void
+auth_passdb_preinit(struct auth *auth, const struct auth_passdb_settings *set)
+{
+	struct auth_passdb *auth_passdb, **dest;
+
+	auth_passdb = p_new(auth->pool, struct auth_passdb, 1);
+	auth_passdb->set = set;
+
+	for (dest = &auth->passdbs; *dest != NULL; dest = &(*dest)->next) ;
+	*dest = auth_passdb;
+
+	auth_passdb->passdb =
+		passdb_preinit(auth->pool, set->driver, set->args);
+}
+
+static void
+auth_userdb_preinit(struct auth *auth, const struct auth_userdb_settings *set)
+{
+        struct auth_userdb *auth_userdb, **dest;
+
+	auth_userdb = p_new(auth->pool, struct auth_userdb, 1);
+	auth_userdb->set = set;
+
+	for (dest = &auth->userdbs; *dest != NULL; dest = &(*dest)->next) ;
+	*dest = auth_userdb;
+
+	auth_userdb->userdb =
+		userdb_preinit(auth->pool, set->driver, set->args);
+}
+
 struct auth *auth_preinit(struct auth_settings *set)
 {
 	struct auth_passdb_settings *const *passdbs;
@@ -45,7 +75,7 @@
 		if (passdbs[i]->master)
 			continue;
 
-		passdb_preinit(auth, passdbs[i]);
+		auth_passdb_preinit(auth, passdbs[i]);
 		passdb_count++;
 		last_passdb = i;
 	}
@@ -62,18 +92,18 @@
 			i_fatal("Master passdb can't have pass=yes "
 				"if there are no passdbs");
 		}
-		passdb_preinit(auth, passdbs[i]);
+		auth_passdb_preinit(auth, passdbs[i]);
 	}
 
 	if (array_is_created(&set->userdbs)) {
 		userdbs = array_get(&set->userdbs, &count);
 		for (i = 0; i < count; i++)
-			userdb_preinit(auth, userdbs[i]);
+			auth_userdb_preinit(auth, userdbs[i]);
 	}
 
 	if (auth->userdbs == NULL) {
 		/* use a dummy userdb static. */
-		userdb_preinit(auth, &userdb_dummy_set);
+		auth_userdb_preinit(auth, &userdb_dummy_set);
 	}
 	return auth;
 }
@@ -204,11 +234,12 @@
 	const char *const *mechanisms;
 
 	for (passdb = auth->masterdbs; passdb != NULL; passdb = passdb->next)
-		passdb_init(passdb->passdb, passdb->set);
+		passdb_init(passdb->passdb, passdb->set->args);
 	for (passdb = auth->passdbs; passdb != NULL; passdb = passdb->next)
-		passdb_init(passdb->passdb, passdb->set);
+		passdb_init(passdb->passdb, passdb->set->args);
 	for (userdb = auth->userdbs; userdb != NULL; userdb = userdb->next)
-		userdb_init(userdb->userdb, userdb->set);
+		userdb_init(userdb->userdb, userdb->set->args);
+
 	/* caching is handled only by the main auth process */
 	if (!worker)
 		passdb_cache_init(auth->set);
diff -r cff28ea08c4a -r 7909611180a8 src/auth/passdb.c
--- a/src/auth/passdb.c	Sat Mar 13 20:19:53 2010 +0200
+++ b/src/auth/passdb.c	Sat Mar 13 21:05:31 2010 +0200
@@ -154,48 +154,39 @@
 	callback(result, credentials, size, auth_request);
 }
 
-void passdb_preinit(struct auth *auth, const struct auth_passdb_settings *set)
+struct passdb_module *
+passdb_preinit(pool_t pool, const char *driver, const char *args)
 {
 	static unsigned int auth_passdb_id = 0;
 	struct passdb_module_interface *iface;
-	struct auth_passdb *auth_passdb, **dest;
+	struct passdb_module *passdb;
 
-	auth_passdb = p_new(auth->pool, struct auth_passdb, 1);
-	auth_passdb->set = set;
-
-	for (dest = &auth->passdbs; *dest != NULL; dest = &(*dest)->next) ;
-	*dest = auth_passdb;
-
-	iface = passdb_interface_find(set->driver);
+	iface = passdb_interface_find(driver);
 	if (iface == NULL)
-		i_fatal("Unknown passdb driver '%s'", set->driver);
+		i_fatal("Unknown passdb driver '%s'", driver);
 	if (iface->verify_plain == NULL) {
 		i_fatal("Support not compiled in for passdb driver '%s'",
-			set->driver);
+			driver);
 	}
 
-	if (iface->preinit == NULL && iface->init == NULL &&
-	    *set->args != '\0') {
-		i_fatal("passdb %s: No args are supported: %s",
-			set->driver, set->args);
-	}
+	if (iface->preinit == NULL && iface->init == NULL && *args != '\0')
+		i_fatal("passdb %s: No args are supported: %s", driver, args);
 
-	if (iface->preinit == NULL) {
-		auth_passdb->passdb =
-			p_new(auth->pool, struct passdb_module, 1);
-	} else {
-		auth_passdb->passdb =
-			iface->preinit(auth->pool, set->args);
-	}
-	auth_passdb->passdb->id = ++auth_passdb_id;
-	auth_passdb->passdb->iface = *iface;
+	if (iface->preinit == NULL)
+		passdb = p_new(pool, struct passdb_module, 1);
+	else
+		passdb = iface->preinit(pool, args);
+	passdb->id = ++auth_passdb_id;
+	passdb->iface = *iface;
+	return passdb;
 }
 
-void passdb_init(struct passdb_module *passdb,
-		 const struct auth_passdb_settings *set)
+void passdb_init(struct passdb_module *passdb, const char *args)
 {
-	if (passdb->iface.init != NULL)
-		passdb->iface.init(passdb, set->args);
+	if (passdb->iface.init != NULL && !passdb->initialized) {
+		passdb->initialized = TRUE;
+		passdb->iface.init(passdb, args);
+	}
 
 	i_assert(passdb->default_pass_scheme != NULL ||
 		 passdb->cache_key == NULL);
@@ -203,6 +194,8 @@
 
 void passdb_deinit(struct passdb_module *passdb)
 {
+	i_assert(passdb->initialized);
+
 	if (passdb->iface.deinit != NULL)
 		passdb->iface.deinit(passdb);
 }
diff -r cff28ea08c4a -r 7909611180a8 src/auth/passdb.h
--- a/src/auth/passdb.h	Sat Mar 13 20:19:53 2010 +0200
+++ b/src/auth/passdb.h	Sat Mar 13 21:05:31 2010 +0200
@@ -5,7 +5,6 @@
 	((pass)[0] != '\0' && (pass)[0] != '*' && (pass)[0] != '!')
 
 struct auth_request;
-struct auth_passdb_settings;
 
 enum passdb_result {
 	PASSDB_RESULT_INTERNAL_FAILURE = -1,
@@ -63,6 +62,9 @@
 	unsigned int id;
 
 	struct passdb_module_interface iface;
+
+	/* init() has been called */
+	unsigned int initialized:1;
 };
 
 /* Try to get credentials in wanted scheme (request->credentials_scheme) from
@@ -82,9 +84,9 @@
 			       lookup_credentials_callback_t *callback,
                                struct auth_request *auth_request);
 
-void passdb_preinit(struct auth *auth, const struct auth_passdb_settings *set);
-void passdb_init(struct passdb_module *passdb,
-		 const struct auth_passdb_settings *set);
+struct passdb_module *
+passdb_preinit(pool_t pool, const char *driver, const char *args);
+void passdb_init(struct passdb_module *passdb, const char *args);
 void passdb_deinit(struct passdb_module *passdb);
 
 void passdb_register_module(struct passdb_module_interface *iface);
diff -r cff28ea08c4a -r 7909611180a8 src/auth/userdb.c
--- a/src/auth/userdb.c	Sat Mar 13 20:19:53 2010 +0200
+++ b/src/auth/userdb.c	Sat Mar 13 21:05:31 2010 +0200
@@ -106,52 +106,44 @@
 	return gr->gr_gid;
 }
 
-void userdb_preinit(struct auth *auth, const struct auth_userdb_settings *set)
+struct userdb_module *
+userdb_preinit(pool_t pool, const char *driver, const char *args)
 {
 	static unsigned int auth_userdb_id = 0;
 	struct userdb_module_interface *iface;
-        struct auth_userdb *auth_userdb, **dest;
+	struct userdb_module *userdb;
 
-	auth_userdb = p_new(auth->pool, struct auth_userdb, 1);
-	auth_userdb->set = set;
-
-	for (dest = &auth->userdbs; *dest != NULL; dest = &(*dest)->next) ;
-	*dest = auth_userdb;
-
-	iface = userdb_interface_find(set->driver);
+	iface = userdb_interface_find(driver);
 	if (iface == NULL)
-		i_fatal("Unknown userdb driver '%s'", set->driver);
+		i_fatal("Unknown userdb driver '%s'", driver);
 	if (iface->lookup == NULL) {
 		i_fatal("Support not compiled in for userdb driver '%s'",
-			set->driver);
+			driver);
 	}
 
-	if (iface->preinit == NULL && iface->init == NULL &&
-	    *auth_userdb->set->args != '\0') {
-		i_fatal("userdb %s: No args are supported: %s",
-			set->driver, auth_userdb->set->args);
-	}
+	if (iface->preinit == NULL && iface->init == NULL && *args != '\0')
+		i_fatal("userdb %s: No args are supported: %s", driver, args);
 
-	if (iface->preinit == NULL) {
-		auth_userdb->userdb =
-			p_new(auth->pool, struct userdb_module, 1);
-	} else {
-		auth_userdb->userdb =
-			iface->preinit(auth->pool, auth_userdb->set->args);
-	}
-	auth_userdb->userdb->id = ++auth_userdb_id;
-	auth_userdb->userdb->iface = iface;
+	if (iface->preinit == NULL)
+		userdb = p_new(pool, struct userdb_module, 1);
+	else
+		userdb = iface->preinit(pool, args);
+	userdb->id = ++auth_userdb_id;
+	userdb->iface = iface;
+	return userdb;
 }
 
-void userdb_init(struct userdb_module *userdb,
-		 const struct auth_userdb_settings *set)
+void userdb_init(struct userdb_module *userdb, const char *args)
 {
-	if (userdb->iface->init != NULL)
-		userdb->iface->init(userdb, set->args);
+	if (userdb->iface->init != NULL && !userdb->initialized) {
+		userdb->initialized = TRUE;
+		userdb->iface->init(userdb, args);
+	}
 }
 
 void userdb_deinit(struct userdb_module *userdb)
 {
+	i_assert(userdb->initialized);
 	if (userdb->iface->deinit != NULL)
 		userdb->iface->deinit(userdb);
 }
diff -r cff28ea08c4a -r 7909611180a8 src/auth/userdb.h
--- a/src/auth/userdb.h	Sat Mar 13 20:19:53 2010 +0200
+++ b/src/auth/userdb.h	Sat Mar 13 21:05:31 2010 +0200
@@ -5,7 +5,6 @@
 
 struct auth;
 struct auth_request;
-struct auth_userdb_settings;
 
 enum userdb_result {
 	USERDB_RESULT_INTERNAL_FAILURE = -1,
@@ -30,6 +29,9 @@
 	unsigned int id;
 
 	const struct userdb_module_interface *iface;
+
+	/* init() has been called */
+	unsigned int initialized:1;
 };
 
 struct userdb_iterate_context {


More information about the dovecot-cvs mailing list