Mercurial > dovecot > core-2.2
changeset 13761:59e25ebc976f
lib-auth: auth_master_user_list_init() now takes user_mask and info parameters.
These are passed to auth process, which may use them to limit what usernames
are returned.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 23 Nov 2011 22:08:09 +0200 |
parents | acfe332f9aeb |
children | 4d56549a5505 |
files | src/doveadm/doveadm-auth.c src/doveadm/doveadm-director.c src/lib-auth/auth-master.c src/lib-auth/auth-master.h src/lib-storage/mail-storage-service.c |
diffstat | 5 files changed, 36 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/src/doveadm/doveadm-auth.c Wed Nov 23 22:07:08 2011 +0200 +++ b/src/doveadm/doveadm-auth.c Wed Nov 23 22:08:09 2011 +0200 @@ -180,11 +180,12 @@ } static void -cmd_user_list(const char *auth_socket_path, char *const *users) +cmd_user_list(const char *auth_socket_path, const struct authtest_input *input, + char *const *users) { struct auth_master_user_list_ctx *ctx; struct auth_master_connection *conn; - const char *username; + const char *username, *user_mask = NULL; unsigned int i; if (auth_socket_path == NULL) { @@ -192,8 +193,11 @@ "/auth-userdb", NULL); } + if (users[0] != NULL && users[1] == NULL) + user_mask = users[0]; + conn = auth_master_init(auth_socket_path, 0); - ctx = auth_master_user_list_init(conn); + ctx = auth_master_user_list_init(conn, user_mask, &input->info); while ((username = auth_master_user_list_next(ctx)) != NULL) { for (i = 0; users[i] != NULL; i++) { if (wildcard_match_icase(username, users[i])) @@ -286,7 +290,7 @@ } if (have_wildcards) - cmd_user_list(auth_socket_path, argv + optind); + cmd_user_list(auth_socket_path, &input, argv + optind); else { bool first = TRUE; bool notfound = FALSE;
--- a/src/doveadm/doveadm-director.c Wed Nov 23 22:07:08 2011 +0200 +++ b/src/doveadm/doveadm-director.c Wed Nov 23 22:08:09 2011 +0200 @@ -211,7 +211,7 @@ } conn = auth_master_init(auth_socket_path, 0); - ctx = auth_master_user_list_init(conn); + ctx = auth_master_user_list_init(conn, NULL, NULL); while ((username = auth_master_user_list_next(ctx)) != NULL) user_list_add(username, pool, users); if (auth_master_user_list_deinit(&ctx) < 0) {
--- a/src/lib-auth/auth-master.c Wed Nov 23 22:07:08 2011 +0200 +++ b/src/lib-auth/auth-master.c Wed Nov 23 22:08:09 2011 +0200 @@ -434,8 +434,10 @@ static void auth_user_info_export(string_t *str, const struct auth_user_info *info) { - str_append(str, "service="); - str_append(str, info->service); + if (info->service != NULL) { + str_append(str, "\tservice="); + str_append(str, info->service); + } if (info->local_ip.family != 0) str_printfa(str, "\tlip=%s", net_ip2addr(&info->local_ip)); @@ -473,7 +475,7 @@ conn->reply_context = &ctx; str = t_str_new(128); - str_printfa(str, "USER\t%u\t%s\t", + str_printfa(str, "USER\t%u\t%s", auth_master_next_request_id(conn), user); auth_user_info_export(str, info); str_append_c(str, '\n'); @@ -547,7 +549,7 @@ conn->reply_context = &ctx; str = t_str_new(128); - str_printfa(str, "PASS\t%u\t%s\t", + str_printfa(str, "PASS\t%u\t%s", auth_master_next_request_id(conn), user); auth_user_info_export(str, info); str_append_c(str, '\n'); @@ -591,10 +593,12 @@ } struct auth_master_user_list_ctx * -auth_master_user_list_init(struct auth_master_connection *conn) +auth_master_user_list_init(struct auth_master_connection *conn, + const char *user_mask, + const struct auth_user_info *info) { struct auth_master_user_list_ctx *ctx; - const char *str; + string_t *str; pool_t pool; pool = pool_alloconly_create("auth master user list", 10240); @@ -606,9 +610,17 @@ conn->reply_callback = auth_user_list_reply_callback; conn->reply_context = ctx; - str = t_strdup_printf("LIST\t%u\n", auth_master_next_request_id(conn)); + str = t_str_new(128); + str_printfa(str, "LIST\t%u", + auth_master_next_request_id(conn)); + if (user_mask != NULL && *user_mask != '\0') + str_printfa(str, "\tuser=%s", user_mask); + if (info != NULL) + auth_user_info_export(str, info); + str_append_c(str, '\n'); + conn->prefix = "userdb list"; - if (auth_master_run_cmd(conn, str) < 0) + if (auth_master_run_cmd(conn, str_c(str)) < 0) ctx->failed = TRUE; ctx->user_strings = array_get(&ctx->users, &ctx->user_count); conn->prefix = DEFAULT_USERDB_LOOKUP_PREFIX;
--- a/src/lib-auth/auth-master.h Wed Nov 23 22:07:08 2011 +0200 +++ b/src/lib-auth/auth-master.h Wed Nov 23 22:08:09 2011 +0200 @@ -43,9 +43,13 @@ void auth_user_fields_parse(const char *const *fields, pool_t pool, struct auth_user_reply *reply_r); -/* Iterate through all users. */ +/* Iterate through all users. If user_mask is non-NULL, it contains a string + with wildcards ('*', '?') that the auth server MAY use to limit what users + are returned (but it may as well return all users anyway). */ struct auth_master_user_list_ctx * -auth_master_user_list_init(struct auth_master_connection *conn); +auth_master_user_list_init(struct auth_master_connection *conn, + const char *user_mask, + const struct auth_user_info *info); const char *auth_master_user_list_next(struct auth_master_user_list_ctx *ctx); unsigned int auth_master_user_list_count(struct auth_master_user_list_ctx *ctx); /* Returns -1 if anything failed, 0 if ok */
--- a/src/lib-storage/mail-storage-service.c Wed Nov 23 22:07:08 2011 +0200 +++ b/src/lib-storage/mail-storage-service.c Wed Nov 23 22:08:09 2011 +0200 @@ -1119,7 +1119,7 @@ (void)auth_master_user_list_deinit(&ctx->auth_list); mail_storage_service_init_settings(ctx, NULL); - ctx->auth_list = auth_master_user_list_init(ctx->conn); + ctx->auth_list = auth_master_user_list_init(ctx->conn, NULL, NULL); return auth_master_user_list_count(ctx->auth_list); }