dovecot-2.0: doveadm user: If no user parameters are given, list...

dovecot at dovecot.org dovecot at dovecot.org
Thu May 27 22:31:45 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/85e22167529f
changeset: 11394:85e22167529f
user:      Timo Sirainen <tss at iki.fi>
date:      Thu May 27 19:27:18 2010 +0100
description:
doveadm user: If no user parameters are given, list all usernames.

diffstat:

 src/doveadm/doveadm-auth.c |  34 +++++++++++++++++++++++++++++++---
 1 files changed, 31 insertions(+), 3 deletions(-)

diffs (68 lines):

diff -r f2ece87f9fea -r 85e22167529f src/doveadm/doveadm-auth.c
--- a/src/doveadm/doveadm-auth.c	Thu May 27 19:14:37 2010 +0100
+++ b/src/doveadm/doveadm-auth.c	Thu May 27 19:27:18 2010 +0100
@@ -168,6 +168,28 @@
 	}
 }
 
+static void cmd_user_list(const char *auth_socket_path)
+{
+	struct auth_master_user_list_ctx *ctx;
+	struct auth_master_connection *conn;
+	const char *username;
+
+	if (auth_socket_path == NULL) {
+		auth_socket_path = t_strconcat(doveadm_settings->base_dir,
+					       "/auth-userdb", NULL);
+	}
+
+	conn = auth_master_init(auth_socket_path, 0);
+	ctx = auth_master_user_list_init(conn);
+	while ((username = auth_master_user_list_next(ctx)) != NULL)
+		printf("%s\n", username);
+	if (auth_master_user_list_deinit(&ctx) < 0) {
+		i_error("user listing failed");
+		exit(1);
+	}
+	auth_master_deinit(&conn);
+}
+
 static void
 auth_cmd_common(const struct doveadm_cmd *cmd, int argc, char *argv[])
 {
@@ -190,10 +212,11 @@
 			help(cmd);
 		}
 	}
-	if (optind == argc)
-		help(cmd);
 
 	if (cmd == &doveadm_cmd_auth) {
+		if (optind == argc)
+			help(cmd);
+
 		input.username = argv[optind++];
 		input.password = argv[optind] != NULL ? argv[optind++] :
 			t_askpass("Password: ");
@@ -203,9 +226,14 @@
 			exit(FATAL_DEFAULT);
 		if (!input.success)
 			exit(1);
+	} else if (optind == argc) {
+		cmd_user_list(auth_socket_path);
 	} else {
 		bool first = TRUE;
 
+		if (optind == argc)
+			help(cmd);
+
 		while ((input.username = argv[optind++]) != NULL) {
 			if (first)
 				first = FALSE;
@@ -234,5 +262,5 @@
 
 struct doveadm_cmd doveadm_cmd_user = {
 	cmd_user, "user",
-	"[-a <userdb socket path>] [-x <auth info>] <user> [<user> ...]", NULL
+	"[-a <userdb socket path>] [-x <auth info>] [<user> ...]", NULL
 };


More information about the dovecot-cvs mailing list