dovecot-2.0: doveadm: -u parameter now allows wildcards for user...

dovecot at dovecot.org dovecot at dovecot.org
Thu May 27 23:10:12 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/6ac0459a6f0e
changeset: 11402:6ac0459a6f0e
user:      Timo Sirainen <tss at iki.fi>
date:      Thu May 27 21:10:07 2010 +0100
description:
doveadm: -u parameter now allows wildcards for usernames.

diffstat:

 src/doveadm/doveadm-mail.c |  15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)

diffs (70 lines):

diff -r d7b9712d1dfc -r 6ac0459a6f0e src/doveadm/doveadm-mail.c
--- a/src/doveadm/doveadm-mail.c	Thu May 27 21:03:36 2010 +0100
+++ b/src/doveadm/doveadm-mail.c	Thu May 27 21:10:07 2010 +0100
@@ -5,6 +5,7 @@
 #include "lib-signals.h"
 #include "ioloop.h"
 #include "module-dir.h"
+#include "wildcard-match.h"
 #include "master-service.h"
 #include "mail-user.h"
 #include "mail-namespace.h"
@@ -235,6 +236,7 @@
 
 static void
 doveadm_mail_all_users(struct doveadm_mail_cmd_context *ctx,
+		       const char *wildcard_user,
 		       enum mail_storage_service_flags service_flags)
 {
 	struct mail_storage_service_input input;
@@ -262,6 +264,10 @@
 	
 	user_idx = 0;
 	while ((ret = ctx->v.get_next_user(ctx, &user)) > 0) {
+		if (wildcard_user != NULL) {
+			if (!wildcard_match_icase(user, wildcard_user))
+				continue;
+		}
 		input.username = user;
 		T_BEGIN {
 			ret = doveadm_mail_next_user(ctx, &input, &error);
@@ -316,7 +322,7 @@
 	enum mail_storage_service_flags service_flags =
 		MAIL_STORAGE_SERVICE_FLAG_NO_LOG_INIT;
 	struct doveadm_mail_cmd_context *ctx;
-	const char *getopt_args, *username;
+	const char *getopt_args, *username, *wildcard_user;
 	bool all_users = FALSE;
 	int c;
 
@@ -335,6 +341,7 @@
 
 	getopt_args = t_strconcat("Au:", ctx->getopt_args, NULL);
 	username = getenv("USER");
+	wildcard_user = NULL;
 	while ((c = getopt(argc, argv, getopt_args)) > 0) {
 		switch (c) {
 		case 'A':
@@ -344,6 +351,8 @@
 			service_flags |=
 				MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP;
 			username = optarg;
+			if (strchr(username, '*') != NULL)
+				wildcard_user = username;
 			break;
 		default:
 			if (ctx->v.parse_arg == NULL ||
@@ -360,11 +369,11 @@
 
 	ctx->v.init(ctx, (const void *)argv);
 
-	if (!all_users) {
+	if (!all_users && wildcard_user == NULL) {
 		doveadm_mail_single_user(ctx, username, service_flags);
 	} else {
 		service_flags |= MAIL_STORAGE_SERVICE_FLAG_TEMP_PRIV_DROP;
-		doveadm_mail_all_users(ctx, service_flags);
+		doveadm_mail_all_users(ctx, wildcard_user, service_flags);
 	}
 	ctx->v.deinit(ctx);
 }


More information about the dovecot-cvs mailing list