dovecot-2.2: doveadm: Added -U <file> parameter for executing th...

dovecot at dovecot.org dovecot at dovecot.org
Wed May 6 12:47:40 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/14eae320322c
changeset: 18530:14eae320322c
user:      Timo Sirainen <tss at iki.fi>
date:      Wed May 06 15:45:43 2015 +0300
description:
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.

diffstat:

 src/doveadm/client-connection.c |   3 ++-
 src/doveadm/doveadm-mail.c      |  23 +++++++++++++++++++++--
 src/doveadm/doveadm-mail.h      |   1 +
 3 files changed, 24 insertions(+), 3 deletions(-)

diffs (81 lines):

diff -r 5fce0eaa75d6 -r 14eae320322c src/doveadm/client-connection.c
--- 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':
diff -r 5fce0eaa75d6 -r 14eae320322c src/doveadm/doveadm-mail.c
--- 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)
diff -r 5fce0eaa75d6 -r 14eae320322c src/doveadm/doveadm-mail.h
--- 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;


More information about the dovecot-cvs mailing list