From: Timo Sirainen Date: Mon, 5 Aug 2013 19:16:02 +0000 (+0300) Subject: lib-storage: Use a separate auth-userdb connection for iterating through users. X-Git-Tag: 2.2.5~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=49621bf0ef1d55aaaa2dc7d76011cbfeabdcfbe1;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Use a separate auth-userdb connection for iterating through users. This is required because the auth-userdb connection is also wanted in the middle of the iteration to do USER lookups. --- diff --git a/src/lib-storage/mail-storage-service.c b/src/lib-storage/mail-storage-service.c index 61e40af00b..87ac94ccaf 100644 --- a/src/lib-storage/mail-storage-service.c +++ b/src/lib-storage/mail-storage-service.c @@ -52,7 +52,7 @@ struct mail_storage_service_ctx { struct master_service *service; const char *default_log_prefix; - struct auth_master_connection *conn; + struct auth_master_connection *conn, *iter_conn; struct auth_master_user_list_ctx *auth_list; const struct setting_parser_info **set_roots; enum mail_storage_service_flags flags; @@ -1277,13 +1277,33 @@ void mail_storage_service_init_settings(struct mail_storage_service_ctx *ctx, pool_unref(&temp_pool); } +static int +mail_storage_service_all_iter_deinit(struct mail_storage_service_ctx *ctx) +{ + int ret = 0; + + if (ctx->auth_list != NULL) { + ret = auth_master_user_list_deinit(&ctx->auth_list); + auth_master_deinit(&ctx->iter_conn); + } + return ret; +} + void mail_storage_service_all_init(struct mail_storage_service_ctx *ctx) { - if (ctx->auth_list != NULL) - (void)auth_master_user_list_deinit(&ctx->auth_list); + enum auth_master_flags flags = 0; + + (void)mail_storage_service_all_iter_deinit(ctx); mail_storage_service_init_settings(ctx, NULL); - ctx->auth_list = auth_master_user_list_init(ctx->conn, "", NULL); + /* create a new connection, because the iteration might take a while + and we might want to do USER lookups during it, which don't mix + well in the same connection. */ + if (ctx->debug) + flags |= AUTH_MASTER_FLAG_DEBUG; + ctx->iter_conn = auth_master_init(auth_master_get_socket_path(ctx->conn), + flags); + ctx->auth_list = auth_master_user_list_init(ctx->iter_conn, "", NULL); } int mail_storage_service_all_next(struct mail_storage_service_ctx *ctx, @@ -1294,7 +1314,7 @@ int mail_storage_service_all_next(struct mail_storage_service_ctx *ctx, *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); + return mail_storage_service_all_iter_deinit(ctx); } void mail_storage_service_deinit(struct mail_storage_service_ctx **_ctx) @@ -1302,8 +1322,7 @@ void mail_storage_service_deinit(struct mail_storage_service_ctx **_ctx) struct mail_storage_service_ctx *ctx = *_ctx; *_ctx = NULL; - if (ctx->auth_list != NULL) - (void)auth_master_user_list_deinit(&ctx->auth_list); + (void)mail_storage_service_all_iter_deinit(ctx); if (ctx->conn != NULL) { if (mail_user_auth_master_conn == ctx->conn) mail_user_auth_master_conn = NULL;