dovecot-2.0: auth: Cleaned up struct auth_passdb/auth_userdb.

dovecot at dovecot.org dovecot at dovecot.org
Sat Mar 13 20:27:13 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/52eb8317514f
changeset: 10897:52eb8317514f
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Mar 13 20:00:32 2010 +0200
description:
auth: Cleaned up struct auth_passdb/auth_userdb.

diffstat:

 src/auth/auth-request.c       |  13 +++++++------
 src/auth/auth-settings.c      |  15 +++++++++++++++
 src/auth/auth-worker-client.c |   8 ++++----
 src/auth/auth.h               |  12 ++----------
 src/auth/passdb-blocking.c    |   6 +++---
 src/auth/passdb.c             |  19 +++++++++----------
 src/auth/passdb.h             |   2 ++
 src/auth/userdb-blocking.c    |   4 ++--
 src/auth/userdb.c             |  16 ++++++++--------
 src/auth/userdb.h             |   2 ++
 10 files changed, 54 insertions(+), 43 deletions(-)

diffs (truncated from 341 to 300 lines):

diff -r f93195ae4bed -r 52eb8317514f src/auth/auth-request.c
--- a/src/auth/auth-request.c	Sat Mar 13 19:36:30 2010 +0200
+++ b/src/auth/auth-request.c	Sat Mar 13 20:00:32 2010 +0200
@@ -340,7 +340,7 @@
 	request->skip_password_check = TRUE;
 	request->passdb_password = NULL;
 
-	if (!request->passdb->pass) {
+	if (!request->passdb->set->pass) {
 		/* skip the passdb lookup, we're authenticated now. */
 		return TRUE;
 	}
@@ -360,7 +360,8 @@
 			    strlen(request->passdb_password));
 	}
 
-	if (request->passdb->deny && *result != PASSDB_RESULT_USER_UNKNOWN) {
+	if (request->passdb->set->deny &&
+	    *result != PASSDB_RESULT_USER_UNKNOWN) {
 		/* deny passdb. we can get through this step only if the
 		   lookup returned that user doesn't exist in it. internal
 		   errors are fatal here. */
@@ -376,7 +377,7 @@
 			if (!auth_request_master_lookup_finish(request))
 				return FALSE;
 		} else {
-			if (request->passdb->pass) {
+			if (request->passdb->set->pass) {
 				/* this wasn't the final passdb lookup,
 				   continue to next passdb */
 				request->passdb = request->passdb->next;
@@ -1368,7 +1369,7 @@
 		return 1;
 	}
 
-	if (request->passdb->deny) {
+	if (request->passdb->set->deny) {
 		/* this is a deny database, we don't care about the password */
 		return 0;
 	}
@@ -1473,10 +1474,10 @@
 	}
 	if (auth_request->userdb_lookup) {
 		tab[9].value = auth_request->userdb == NULL ? "" :
-			dec2str(auth_request->userdb->num);
+			dec2str(auth_request->userdb->userdb->id);
 	} else {
 		tab[9].value = auth_request->passdb == NULL ? "" :
-			dec2str(auth_request->passdb->id);
+			dec2str(auth_request->passdb->passdb->id);
 	}
 	tab[10].value = auth_request->mech_name == NULL ? "" :
 		auth_request->mech_name;
diff -r f93195ae4bed -r 52eb8317514f src/auth/auth-settings.c
--- a/src/auth/auth-settings.c	Sat Mar 13 19:36:30 2010 +0200
+++ b/src/auth/auth-settings.c	Sat Mar 13 20:00:32 2010 +0200
@@ -110,8 +110,17 @@
 	SETTING_DEFINE_LIST_END
 };
 
+static const struct auth_passdb_settings auth_passdb_settings = {
+	.driver = "",
+	.args = "",
+	.deny = FALSE,
+	.pass = FALSE,
+	.master = FALSE
+};
+
 const struct setting_parser_info auth_passdb_setting_parser_info = {
 	.defines = auth_passdb_setting_defines,
+	.defaults = &auth_passdb_settings,
 
 	.type_offset = (size_t)-1,
 	.struct_size = sizeof(struct auth_passdb_settings),
@@ -133,8 +142,14 @@
 	SETTING_DEFINE_LIST_END
 };
 
+static const struct auth_userdb_settings auth_userdb_settings = {
+	.driver = "",
+	.args = ""
+};
+
 const struct setting_parser_info auth_userdb_setting_parser_info = {
 	.defines = auth_userdb_setting_defines,
+	.defaults = &auth_userdb_settings,
 
 	.type_offset = (size_t)-1,
 	.struct_size = sizeof(struct auth_userdb_settings),
diff -r f93195ae4bed -r 52eb8317514f src/auth/auth-worker-client.c
--- a/src/auth/auth-worker-client.c	Sat Mar 13 19:36:30 2010 +0200
+++ b/src/auth/auth-worker-client.c	Sat Mar 13 20:00:32 2010 +0200
@@ -165,13 +165,13 @@
 	}
 
 	passdb = auth_request->passdb;
-	while (passdb != NULL && passdb->id != passdb_id)
+	while (passdb != NULL && passdb->passdb->id != passdb_id)
 		passdb = passdb->next;
 
 	if (passdb == NULL) {
 		/* could be a masterdb */
 		passdb = auth_request->auth->masterdbs;
-		while (passdb != NULL && passdb->id != passdb_id)
+		while (passdb != NULL && passdb->passdb->id != passdb_id)
 			passdb = passdb->next;
 
 		if (passdb == NULL) {
@@ -264,7 +264,7 @@
 		return;
 	}
 
-	while (auth_request->passdb->id != passdb_id) {
+	while (auth_request->passdb->passdb->id != passdb_id) {
 		auth_request->passdb = auth_request->passdb->next;
 		if (auth_request->passdb == NULL) {
 			i_error("BUG: PASSL had invalid passdb ID");
@@ -328,7 +328,7 @@
 		return;
 	}
 
-	while (auth_request->passdb->id != passdb_id) {
+	while (auth_request->passdb->passdb->id != passdb_id) {
 		auth_request->passdb = auth_request->passdb->next;
 		if (auth_request->passdb == NULL) {
 			i_error("BUG: SETCRED had invalid passdb ID");
diff -r f93195ae4bed -r 52eb8317514f src/auth/auth.h
--- a/src/auth/auth.h	Sat Mar 13 19:36:30 2010 +0200
+++ b/src/auth/auth.h	Sat Mar 13 20:00:32 2010 +0200
@@ -9,23 +9,15 @@
 	pool_t pool;
 	struct auth_passdb *next;
 
-        /* id is used by blocking passdb to identify the passdb */
-	unsigned int id;
-	const char *args;
+	const struct auth_passdb_settings *set;
 	struct passdb_module *passdb;
-
-        /* if user is found from this passdb, deny authentication immediately */
-	unsigned int deny:1;
-	/* after a successful lookup, continue to next passdb */
-	unsigned int pass:1;
 };
 
 struct auth_userdb {
 	pool_t pool;
 	struct auth_userdb *next;
 
-	unsigned int num;
-	const char *args;
+	const struct auth_userdb_settings *set;
 	struct userdb_module *userdb;
 };
 
diff -r f93195ae4bed -r 52eb8317514f src/auth/passdb-blocking.c
--- a/src/auth/passdb-blocking.c	Sat Mar 13 19:36:30 2010 +0200
+++ b/src/auth/passdb-blocking.c	Sat Mar 13 20:00:32 2010 +0200
@@ -80,7 +80,7 @@
 
 	reply = auth_stream_reply_init(pool_datastack_create());
 	auth_stream_reply_add(reply, "PASSV", NULL);
-	auth_stream_reply_add(reply, NULL, dec2str(request->passdb->id));
+	auth_stream_reply_add(reply, NULL, dec2str(request->passdb->passdb->id));
 	auth_stream_reply_add(reply, NULL, request->mech_password);
 	auth_request_export(request, reply);
 
@@ -122,7 +122,7 @@
 
 	reply = auth_stream_reply_init(pool_datastack_create());
 	auth_stream_reply_add(reply, "PASSL", NULL);
-	auth_stream_reply_add(reply, NULL, dec2str(request->passdb->id));
+	auth_stream_reply_add(reply, NULL, dec2str(request->passdb->passdb->id));
 	auth_stream_reply_add(reply, NULL, request->credentials_scheme);
 	auth_request_export(request, reply);
 
@@ -150,7 +150,7 @@
 
 	reply = auth_stream_reply_init(pool_datastack_create());
 	auth_stream_reply_add(reply, "SETCRED", NULL);
-	auth_stream_reply_add(reply, NULL, dec2str(request->passdb->id));
+	auth_stream_reply_add(reply, NULL, dec2str(request->passdb->passdb->id));
 	auth_stream_reply_add(reply, NULL, new_credentials);
 	auth_request_export(request, reply);
 
diff -r f93195ae4bed -r 52eb8317514f src/auth/passdb.c
--- a/src/auth/passdb.c	Sat Mar 13 19:36:30 2010 +0200
+++ b/src/auth/passdb.c	Sat Mar 13 20:00:32 2010 +0200
@@ -157,17 +157,15 @@
 struct auth_passdb *
 passdb_preinit(struct auth *auth, struct auth_passdb_settings *set)
 {
+	static unsigned int auth_passdb_id = 0;
 	struct passdb_module_interface *iface;
-        struct auth_passdb *auth_passdb, **dest;
+	struct auth_passdb *auth_passdb, **dest;
 
 	auth_passdb = p_new(auth->pool, struct auth_passdb, 1);
 	auth_passdb->pool = auth->pool;
-	auth_passdb->args = set->args == NULL ? "" :
-		p_strdup(auth->pool, set->args);
-	auth_passdb->deny = set->deny;
+	auth_passdb->set = set;
 
-	for (dest = &auth->passdbs; *dest != NULL; dest = &(*dest)->next)
-		auth_passdb->id++;
+	for (dest = &auth->passdbs; *dest != NULL; dest = &(*dest)->next) ;
 	*dest = auth_passdb;
 
 	iface = passdb_interface_find(set->driver);
@@ -179,9 +177,9 @@
 	}
 
 	if (iface->preinit == NULL && iface->init == NULL &&
-	    *auth_passdb->args != '\0') {
+	    *set->args != '\0') {
 		i_fatal("passdb %s: No args are supported: %s",
-			set->driver, auth_passdb->args);
+			set->driver, set->args);
 	}
 
 	if (iface->preinit == NULL) {
@@ -189,8 +187,9 @@
 			p_new(auth->pool, struct passdb_module, 1);
 	} else {
 		auth_passdb->passdb =
-			iface->preinit(auth_passdb, auth_passdb->args);
+			iface->preinit(auth_passdb, set->args);
 	}
+	auth_passdb->passdb->id = ++auth_passdb_id;
 	auth_passdb->passdb->iface = *iface;
 	return auth_passdb;
 }
@@ -198,7 +197,7 @@
 void passdb_init(struct auth_passdb *passdb)
 {
 	if (passdb->passdb->iface.init != NULL)
-		passdb->passdb->iface.init(passdb->passdb, passdb->args);
+		passdb->passdb->iface.init(passdb->passdb, passdb->set->args);
 
 	i_assert(passdb->passdb->default_pass_scheme != NULL ||
 		 passdb->passdb->cache_key == NULL);
diff -r f93195ae4bed -r 52eb8317514f src/auth/passdb.h
--- a/src/auth/passdb.h	Sat Mar 13 19:36:30 2010 +0200
+++ b/src/auth/passdb.h	Sat Mar 13 20:00:32 2010 +0200
@@ -61,6 +61,8 @@
 	/* If blocking is set to TRUE, use child processes to access
 	   this passdb. */
 	bool blocking;
+        /* id is used by blocking passdb to identify the passdb */
+	unsigned int id;
 
 	struct passdb_module_interface iface;
 };
diff -r f93195ae4bed -r 52eb8317514f src/auth/userdb-blocking.c
--- a/src/auth/userdb-blocking.c	Sat Mar 13 19:36:30 2010 +0200
+++ b/src/auth/userdb-blocking.c	Sat Mar 13 20:00:32 2010 +0200
@@ -44,7 +44,7 @@
 
 	reply = auth_stream_reply_init(pool_datastack_create());
 	auth_stream_reply_add(reply, "USER", NULL);
-	auth_stream_reply_add(reply, NULL, dec2str(request->userdb->num));
+	auth_stream_reply_add(reply, NULL, dec2str(request->userdb->userdb->id));
 	auth_request_export(request, reply);
 
 	auth_request_ref(request);
@@ -79,7 +79,7 @@
 
 	reply = auth_stream_reply_init(pool_datastack_create());
 	auth_stream_reply_add(reply, "LIST", NULL);
-	auth_stream_reply_add(reply, NULL, dec2str(userdb->num));
+	auth_stream_reply_add(reply, NULL, dec2str(userdb->userdb->id));
 
 	pool = pool_alloconly_create("userdb iter", 512);
 	ctx = p_new(pool, struct blocking_userdb_iterate_context, 1);
diff -r f93195ae4bed -r 52eb8317514f src/auth/userdb.c
--- a/src/auth/userdb.c	Sat Mar 13 19:36:30 2010 +0200
+++ b/src/auth/userdb.c	Sat Mar 13 20:00:32 2010 +0200
@@ -108,16 +108,15 @@
 
 void userdb_preinit(struct auth *auth, struct auth_userdb_settings *set)
 {
+	static unsigned int auth_userdb_id = 0;
 	struct userdb_module_interface *iface;
         struct auth_userdb *auth_userdb, **dest;
 
 	auth_userdb = p_new(auth->pool, struct auth_userdb, 1);
 	auth_userdb->pool = auth->pool;
-	auth_userdb->args = set->args == NULL ? "" :
-		p_strdup(auth->pool, set->args);
+	auth_userdb->set = set;
 
-	for (dest = &auth->userdbs; *dest != NULL; dest = &(*dest)->next)
-		auth_userdb->num++;
+	for (dest = &auth->userdbs; *dest != NULL; dest = &(*dest)->next) ;
 	*dest = auth_userdb;
 
 	iface = userdb_interface_find(set->driver);
@@ -129,9 +128,9 @@
 	}


More information about the dovecot-cvs mailing list