dovecot-2.0: doveadm user: User listing is done now by using wil...
dovecot at dovecot.org
dovecot at dovecot.org
Thu May 27 22:49:04 EEST 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/ca0503623ff2
changeset: 11399:ca0503623ff2
user: Timo Sirainen <tss at iki.fi>
date: Thu May 27 20:49:00 2010 +0100
description:
doveadm user: User listing is done now by using wildcards in usernames.
diffstat:
src/doveadm/doveadm-auth.c | 40 ++++++++++++++++++++++++++++------------
1 files changed, 28 insertions(+), 12 deletions(-)
diffs (98 lines):
diff -r da750dc62c14 -r ca0503623ff2 src/doveadm/doveadm-auth.c
--- a/src/doveadm/doveadm-auth.c Thu May 27 20:30:04 2010 +0100
+++ b/src/doveadm/doveadm-auth.c Thu May 27 20:49:00 2010 +0100
@@ -6,6 +6,7 @@
#include "askpass.h"
#include "base64.h"
#include "str.h"
+#include "wildcard-match.h"
#include "auth-client.h"
#include "auth-master.h"
#include "auth-server-connection.h"
@@ -168,11 +169,13 @@
}
}
-static void cmd_user_list(const char *auth_socket_path)
+static void
+cmd_user_list(const char *auth_socket_path, char *const *users)
{
struct auth_master_user_list_ctx *ctx;
struct auth_master_connection *conn;
const char *username;
+ unsigned int i;
if (auth_socket_path == NULL) {
auth_socket_path = t_strconcat(doveadm_settings->base_dir,
@@ -181,8 +184,14 @@
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);
+ while ((username = auth_master_user_list_next(ctx)) != NULL) {
+ for (i = 0; users[i] != NULL; i++) {
+ if (wildcard_match_icase(username, users[i]))
+ break;
+ }
+ if (users[i] != NULL)
+ printf("%s\n", username);
+ }
if (auth_master_user_list_deinit(&ctx) < 0) {
i_error("user listing failed");
exit(1);
@@ -195,6 +204,8 @@
{
const char *auth_socket_path = NULL;
struct authtest_input input;
+ unsigned int i;
+ bool have_wildcards;
int c;
memset(&input, 0, sizeof(input));
@@ -213,10 +224,18 @@
}
}
+ if (optind == argc)
+ help(cmd);
+
+ have_wildcards = FALSE;
+ for (i = optind; argv[i] != NULL; i++) {
+ if (strchr(argv[i], '*') != NULL) {
+ have_wildcards = TRUE;
+ break;
+ }
+ }
+
if (cmd == &doveadm_cmd_auth) {
- if (optind == argc)
- help(cmd);
-
input.username = argv[optind++];
input.password = argv[optind] != NULL ? argv[optind++] :
t_askpass("Password: ");
@@ -226,14 +245,11 @@
exit(FATAL_DEFAULT);
if (!input.success)
exit(1);
- } else if (optind == argc) {
- cmd_user_list(auth_socket_path);
+ } else if (have_wildcards) {
+ cmd_user_list(auth_socket_path, argv + optind);
} else {
bool first = TRUE;
- if (optind == argc)
- help(cmd);
-
while ((input.username = argv[optind++]) != NULL) {
if (first)
first = FALSE;
@@ -262,5 +278,5 @@
struct doveadm_cmd doveadm_cmd_user = {
cmd_user, "user",
- "[-a <userdb socket path>] [-x <auth info>] [<user> ...]", NULL
+ "[-a <userdb socket path>] [-x <auth info>] <user mask> [...]", NULL
};
More information about the dovecot-cvs
mailing list