dovecot-2.0: mail storage multi service: Added support for itera...

dovecot at dovecot.org dovecot at dovecot.org
Fri May 15 22:10:36 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/0e02c867b15a
changeset: 9289:0e02c867b15a
user:      Timo Sirainen <tss at iki.fi>
date:      Fri May 15 15:09:35 2009 -0400
description:
mail storage multi service: Added support for iterating through all users.

diffstat:

2 files changed, 35 insertions(+), 10 deletions(-)
src/lib-storage/mail-storage-service.c |   41 ++++++++++++++++++++++++--------
src/lib-storage/mail-storage-service.h |    4 +++

diffs (135 lines):

diff -r 77d6b5eb0963 -r 0e02c867b15a src/lib-storage/mail-storage-service.c
--- a/src/lib-storage/mail-storage-service.c	Fri May 15 15:09:13 2009 -0400
+++ b/src/lib-storage/mail-storage-service.c	Fri May 15 15:09:35 2009 -0400
@@ -24,6 +24,8 @@
 
 struct mail_storage_service_multi_ctx {
 	struct master_service *service;
+	struct auth_master_connection *conn;
+	struct auth_master_user_list_ctx *auth_list;
 	enum mail_storage_service_flags flags;
 
 	unsigned int modules_initialized:1;
@@ -140,25 +142,20 @@ user_reply_handle(struct setting_parser_
 }
 
 static int
-service_auth_userdb_lookup(struct setting_parser_context *set_parser,
+service_auth_userdb_lookup(struct auth_master_connection *conn,
+			   struct setting_parser_context *set_parser,
 			   const char *name,
 			   const struct mail_user_settings *user_set,
 			   const char **user, const char **system_groups_user_r,
 			   const char **error_r)
 {
-	const struct mail_storage_settings *mail_set;
-        struct auth_master_connection *conn;
 	struct auth_user_reply reply;
 	const char *system_groups_user, *orig_user = *user;
 	unsigned int len;
 	pool_t pool;
 	int ret;
 
-	mail_set = mail_user_set_get_storage_set(user_set);
-
 	pool = pool_alloconly_create("userdb lookup", 1024);
-	conn = auth_master_init(user_set->auth_socket_path,
-				mail_set->mail_debug);
 	ret = auth_master_user_lookup(conn, *user, name, pool, &reply);
 	if (ret > 0) {
 		len = reply.chroot == NULL ? 0 : strlen(reply.chroot);
@@ -181,7 +178,6 @@ service_auth_userdb_lookup(struct settin
 			i_info("changed username to %s", *user);
 	}
 
-	auth_master_deinit(&conn);
 	pool_unref(&pool);
 	return ret;
 }
@@ -474,6 +470,7 @@ mail_storage_service_init_user(struct ma
 	const struct mail_user_settings *user_set;
 	const struct mail_storage_settings *mail_set;
 	struct mail_user *mail_user;
+	struct auth_master_connection *conn;
 	void **sets;
 	const char *user, *orig_user, *home, *system_groups_user, *error;
 	unsigned int len;
@@ -498,11 +495,14 @@ mail_storage_service_init_user(struct ma
 		/* userdb lookup may change settings, do it as soon as
 		   possible. */
 		orig_user = user = input.username;
-		if (service_auth_userdb_lookup(service->set_parser,
+		conn = auth_master_init(user_set->auth_socket_path,
+					mail_set->mail_debug);
+		if (service_auth_userdb_lookup(conn, service->set_parser,
 					       service->name, user_set, &user,
 					       &system_groups_user,
 					       &error) <= 0)
 			i_fatal("%s", error);
+		auth_master_deinit(&conn);
 		input.username = user;
 
 		/* set up logging again in case username changed */
@@ -592,6 +592,11 @@ mail_storage_service_multi_init(struct m
 				user_set->mail_plugins, TRUE,
 				master_service_get_version_string(service));
 
+	if ((ctx->flags & MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP) != 0) {
+		ctx->conn = auth_master_init(user_set->auth_socket_path,
+					     mail_set->mail_debug);
+	}
+
 	dict_drivers_register_builtin();
 	mail_users_init(user_set->auth_socket_path, mail_set->mail_debug);
 	return ctx;
@@ -620,7 +625,7 @@ int mail_storage_service_multi_lookup(st
 
 	if ((ctx->flags & MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP) != 0) {
 		orig_user = username = user->input.username;
-		ret = service_auth_userdb_lookup(user->set_parser,
+		ret = service_auth_userdb_lookup(ctx->conn, user->set_parser,
 						 ctx->service->name,
 						 user->user_set, &username,
 						 &user->system_groups_user,
@@ -678,11 +683,27 @@ int mail_storage_service_multi_next(stru
 	return 0;
 }
 
+int mail_storage_service_multi_all_next(struct mail_storage_service_multi_ctx *ctx,
+					const char **username_r)
+{
+	i_assert((ctx->flags & MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP) != 0);
+
+	if (ctx->auth_list == NULL)
+		ctx->auth_list = auth_master_user_list_init(ctx->conn);
+
+	*username_r = auth_master_user_list_next(ctx->auth_list);
+	if (*username_r != NULL)
+		return 1;
+	return auth_master_user_list_deinit(&ctx->auth_list);
+}
+
 void mail_storage_service_multi_deinit(struct mail_storage_service_multi_ctx **_ctx)
 {
 	struct mail_storage_service_multi_ctx *ctx = *_ctx;
 
 	*_ctx = NULL;
+	if (ctx->conn != NULL)
+		auth_master_deinit(&ctx->conn);
 	i_free(ctx);
 	mail_storage_service_deinit_user();
 }
diff -r 77d6b5eb0963 -r 0e02c867b15a src/lib-storage/mail-storage-service.h
--- a/src/lib-storage/mail-storage-service.h	Fri May 15 15:09:13 2009 -0400
+++ b/src/lib-storage/mail-storage-service.h	Fri May 15 15:09:35 2009 -0400
@@ -47,6 +47,10 @@ int mail_storage_service_multi_next(stru
 				    struct mail_storage_service_multi_user *user,
 				    struct mail_user **mail_user_r,
 				    const char **error_r);
+/* Iterate through all usernames. Returns 1 if username was returned, 0 if
+   there are no more users, -1 if error. */
+int mail_storage_service_multi_all_next(struct mail_storage_service_multi_ctx *ctx,
+					const char **username_r);
 void mail_storage_service_multi_deinit(struct mail_storage_service_multi_ctx **ctx);
 
 /* Return the settings pointed to by set_root parameter in _init().


More information about the dovecot-cvs mailing list