changeset 20613:f29b99e582a8

doveadm: Fixed -A and -u wildcard handling with server connections.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Mon, 08 Aug 2016 19:25:05 +0300
parents e8a85457b96d
children f3b498663de4
files src/doveadm/client-connection.c src/doveadm/doveadm-cmd.h src/doveadm/doveadm-mail.c src/doveadm/doveadm-mail.h
diffstat 4 files changed, 23 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/doveadm/client-connection.c	Mon Aug 08 19:24:08 2016 +0300
+++ b/src/doveadm/client-connection.c	Mon Aug 08 19:25:05 2016 +0300
@@ -292,6 +292,7 @@
 	}
 	memset(&cctx, 0, sizeof(cctx));
 	cctx.cli = FALSE;
+	cctx.tcp_server = TRUE;
 
 	cctx.local_ip = conn->local_ip;
 	cctx.remote_ip = conn->remote_ip;
--- a/src/doveadm/doveadm-cmd.h	Mon Aug 08 19:24:08 2016 +0300
+++ b/src/doveadm/doveadm-cmd.h	Mon Aug 08 19:25:05 2016 +0300
@@ -77,6 +77,7 @@
 
 	const char *username;
 	bool cli;
+	bool tcp_server;
 	struct ip_addr local_ip, remote_ip;
 	in_port_t local_port, remote_port;
 	struct client_connection *conn;
--- a/src/doveadm/doveadm-mail.c	Mon Aug 08 19:24:08 2016 +0300
+++ b/src/doveadm/doveadm-mail.c	Mon Aug 08 19:25:05 2016 +0300
@@ -573,7 +573,8 @@
 
 	ctx->iterate_single_user =
 		!ctx->iterate_all_users && wildcard_user == NULL;
-	if (doveadm_print_is_initialized() && !ctx->iterate_single_user) {
+	if (doveadm_print_is_initialized() &&
+	    (!ctx->iterate_single_user || ctx->add_username_header)) {
 		doveadm_print_header("username", "Username",
 				     DOVEADM_PRINT_HEADER_FLAG_STICKY |
 				     DOVEADM_PRINT_HEADER_FLAG_HIDE_TITLE);
@@ -587,6 +588,8 @@
 			ctx->service_flags |= MAIL_STORAGE_SERVICE_FLAG_TEMP_PRIV_DROP;
 		}
 
+		if (ctx->add_username_header)
+			doveadm_print_sticky("username", cctx->username);
 		ret = doveadm_mail_single_user(ctx, cctx, &error);
 		if (ret < 0) {
 			/* user lookup/init failed somehow */
@@ -953,7 +956,10 @@
 			continue;
 
 		if (strcmp(arg->name, "all-users") == 0) {
-			mctx->iterate_all_users = arg->value.v_bool;
+			if (cctx->tcp_server)
+				mctx->add_username_header = TRUE;
+			else
+				mctx->iterate_all_users = arg->value.v_bool;
 			fieldstr = "-A";
 			array_append(&full_args, &fieldstr, 1);
 		} else if (strcmp(arg->name, "socket-path") == 0) {
@@ -962,16 +968,21 @@
 				doveadm_settings->doveadm_worker_count = 1;
 		} else if (strcmp(arg->name, "user") == 0) {
 			mctx->service_flags |= MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP;
-			mctx->cur_username = arg->value.v_string;
+			if (!cctx->tcp_server)
+				mctx->cur_username = arg->value.v_string;
 
 			fieldstr = "-u";
 			array_append(&full_args, &fieldstr, 1);
 			array_append(&full_args, &arg->value.v_string, 1);
-			if (strchr(mctx->cur_username, '*') != NULL ||
-			    strchr(mctx->cur_username, '?') != NULL) {
-				wildcard_user = mctx->cur_username;
-				mctx->cur_username = NULL;
-			} else {
+			if (strchr(arg->value.v_string, '*') != NULL ||
+			    strchr(arg->value.v_string, '?') != NULL) {
+				if (cctx->tcp_server)
+					mctx->add_username_header = TRUE;
+				else {
+					wildcard_user = arg->value.v_string;
+					mctx->cur_username = NULL;
+				}
+			} else if (!cctx->tcp_server) {
 				cctx->username = mctx->cur_username;
 			}
 		} else if (strcmp(arg->name, "user-file") == 0) {
--- a/src/doveadm/doveadm-mail.h	Mon Aug 08 19:24:08 2016 +0300
+++ b/src/doveadm/doveadm-mail.h	Mon Aug 08 19:25:05 2016 +0300
@@ -97,6 +97,8 @@
 	unsigned int iterate_single_user:1;
 	/* We're going through all users (not set for wildcard usernames) */
 	unsigned int iterate_all_users:1;
+	/* Add username header to all replies */
+	unsigned int add_username_header:1;
 	/* Running from CLI doveadm (not doveadm-server) */
 	unsigned int cli:1;
 };