dovecot-2.0: doveadm user: Added -f parameter to show only the s...

dovecot at dovecot.org dovecot at dovecot.org
Wed May 4 16:04:13 EEST 2011


details:   http://hg.dovecot.org/dovecot-2.0/rev/23b6234ce0ae
changeset: 12770:23b6234ce0ae
user:      Timo Sirainen <tss at iki.fi>
date:      Wed May 04 15:03:14 2011 +0200
description:
doveadm user: Added -f parameter to show only the specified extra field's value.

diffstat:

 src/doveadm/doveadm-auth.c |  27 +++++++++++++++++++++------
 1 files changed, 21 insertions(+), 6 deletions(-)

diffs (74 lines):

diff -r d0f54521bb3b -r 23b6234ce0ae src/doveadm/doveadm-auth.c
--- a/src/doveadm/doveadm-auth.c	Wed May 04 14:58:03 2011 +0200
+++ b/src/doveadm/doveadm-auth.c	Wed May 04 15:03:14 2011 +0200
@@ -24,7 +24,8 @@
 };
 
 static int
-cmd_user_input(const char *auth_socket_path, const struct authtest_input *input)
+cmd_user_input(const char *auth_socket_path, const struct authtest_input *input,
+	       const char *show_field)
 {
 	struct auth_master_connection *conn;
 	pool_t pool;
@@ -49,8 +50,17 @@
 				input->username, fields[0]);
 		}
 	} else if (ret == 0) {
-		printf("userdb lookup: user %s doesn't exist\n",
-		       input->username);
+		fprintf(show_field == NULL ? stdout : stderr,
+			"userdb lookup: user %s doesn't exist\n",
+			input->username);
+	} else if (show_field != NULL) {
+		unsigned int show_field_len = strlen(show_field);
+
+		for (; *fields; fields++) {
+			if (strncmp(*fields, show_field, show_field_len) == 0 &&
+			    (*fields)[show_field_len] == '=')
+				printf("%s\n", *fields + show_field_len + 1);
+		}
 	} else {
 		printf("userdb: %s\n", input->username);
 
@@ -239,6 +249,7 @@
 {
 	const char *auth_socket_path = NULL;
 	struct authtest_input input;
+	const char *show_field = NULL;
 	unsigned int i;
 	bool have_wildcards;
 	int c;
@@ -246,11 +257,14 @@
 	memset(&input, 0, sizeof(input));
 	input.info.service = "doveadm";
 
-	while ((c = getopt(argc, argv, "a:x:")) > 0) {
+	while ((c = getopt(argc, argv, "a:f:x:")) > 0) {
 		switch (c) {
 		case 'a':
 			auth_socket_path = optarg;
 			break;
+		case 'f':
+			show_field = optarg;
+			break;
 		case 'x':
 			auth_user_info_parse(&input.info, optarg);
 			break;
@@ -282,7 +296,8 @@
 				first = FALSE;
 			else
 				putchar('\n');
-			switch (cmd_user_input(auth_socket_path, &input)) {
+			switch (cmd_user_input(auth_socket_path, &input,
+					       show_field)) {
 			case -1:
 				exit(1);
 			case 0:
@@ -302,5 +317,5 @@
 
 struct doveadm_cmd doveadm_cmd_user = {
 	cmd_user, "user",
-	"[-a <userdb socket path>] [-x <auth info>] <user mask> [...]"
+	"[-a <userdb socket path>] [-x <auth info>] [-f field] <user mask> [...]"
 };


More information about the dovecot-cvs mailing list