Mercurial > dovecot > core-2.2
changeset 18530:14eae320322c
doveadm: Added -U <file> parameter for executing the command for all the users in the file.
This is similar to -A parameter, but instead of getting the list of users
from userdb they are read from the file. The file contains one username per
line.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 06 May 2015 15:45:43 +0300 |
parents | 5fce0eaa75d6 |
children | 13c933ed6371 |
files | src/doveadm/client-connection.c src/doveadm/doveadm-mail.c src/doveadm/doveadm-mail.h |
diffstat | 3 files changed, 24 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/doveadm/client-connection.c Wed May 06 15:42:31 2015 +0300 +++ b/src/doveadm/client-connection.c Wed May 06 15:45:43 2015 +0300 @@ -93,10 +93,11 @@ ctx->service_flags |= MAIL_STORAGE_SERVICE_FLAG_DEBUG; optind = 1; - getopt_args = t_strconcat("AS:u:", ctx->getopt_args, NULL); + getopt_args = t_strconcat("AS:u:U:", ctx->getopt_args, NULL); while ((c = getopt(argc, argv, getopt_args)) > 0) { switch (c) { case 'A': + case 'U': add_username_header = TRUE; break; case 'S':
--- a/src/doveadm/doveadm-mail.c Wed May 06 15:42:31 2015 +0300 +++ b/src/doveadm/doveadm-mail.c Wed May 06 15:45:43 2015 +0300 @@ -515,7 +515,17 @@ doveadm_mail_cmd_get_next_user(struct doveadm_mail_cmd_context *ctx, const char **username_r) { - return mail_storage_service_all_next(ctx->storage_service, username_r); + if (ctx->users_list_input == NULL) + return mail_storage_service_all_next(ctx->storage_service, username_r); + + *username_r = i_stream_read_next_line(ctx->users_list_input); + if (ctx->users_list_input->stream_errno != 0) { + i_error("read(%s) failed: %s", + i_stream_get_name(ctx->users_list_input), + i_stream_get_error(ctx->users_list_input)); + return -1; + } + return *username_r != NULL ? 1 : 0; } static void @@ -557,7 +567,7 @@ if (doveadm_debug) ctx->service_flags |= MAIL_STORAGE_SERVICE_FLAG_DEBUG; - getopt_args = "AS:u:"; + getopt_args = "AS:u:U:"; /* keep context's getopt_args first in case it contains '+' */ if (ctx->getopt_args != NULL) getopt_args = t_strconcat(ctx->getopt_args, getopt_args, NULL); @@ -583,6 +593,13 @@ ctx->cur_username = NULL; } break; + case 'U': + ctx->service_flags |= + MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP; + wildcard_user = "*"; + ctx->users_list_input = + i_stream_create_file(optarg, 1024); + break; default: if (ctx->v.parse_arg == NULL || !ctx->v.parse_arg(ctx, c)) @@ -633,6 +650,8 @@ /* service deinit unloads mail plugins, so do it late */ mail_storage_service_deinit(&ctx->storage_service); + if (ctx->users_list_input != NULL) + i_stream_unref(&ctx->users_list_input); if (ctx->cmd_input != NULL) i_stream_unref(&ctx->cmd_input); if (ctx->exit_code != 0)
--- a/src/doveadm/doveadm-mail.h Wed May 06 15:42:31 2015 +0300 +++ b/src/doveadm/doveadm-mail.h Wed May 06 15:45:43 2015 +0300 @@ -75,6 +75,7 @@ struct mail_storage_service_input storage_service_input; /* search args aren't set for all mail commands */ struct mail_search_args *search_args; + struct istream *users_list_input; struct ip_addr cur_client_ip; const char *cur_username;