dovecot-2.0: doveadm director status username now returns which ...

dovecot at dovecot.org dovecot at dovecot.org
Thu May 20 12:46:24 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/c57c1ff9c5f1
changeset: 11351:c57c1ff9c5f1
user:      Timo Sirainen <tss at iki.fi>
date:      Thu May 20 11:46:21 2010 +0200
description:
doveadm director status username now returns which server the user is assigned to.

diffstat:

 src/director/doveadm-connection.c |  19 +++++++++++++++++++
 src/doveadm/doveadm-director.c    |  26 +++++++++++++++++++++++++-
 2 files changed, 44 insertions(+), 1 deletions(-)

diffs (85 lines):

diff -r 5f77c91f3df0 -r c57c1ff9c5f1 src/director/doveadm-connection.c
--- a/src/director/doveadm-connection.c	Thu May 20 10:43:47 2010 +0200
+++ b/src/director/doveadm-connection.c	Thu May 20 11:46:21 2010 +0200
@@ -115,6 +115,23 @@
 	return TRUE;
 }
 
+static bool
+doveadm_cmd_user_lookup(struct doveadm_connection *conn, const char *line)
+{
+	struct user *user;
+	unsigned int hash;
+
+	hash = user_directory_get_username_hash(line);
+	user = user_directory_lookup(conn->dir->users, hash);
+	if (user == NULL)
+		o_stream_send_str(conn->output, "NOTFOUND\n");
+	else {
+		o_stream_send_str(conn->output, t_strconcat(
+			net_ip2addr(&user->host->ip), "\n", NULL));
+	}
+	return TRUE;
+}
+
 static void doveadm_connection_input(struct doveadm_connection *conn)
 {
 	const char *line;
@@ -143,6 +160,8 @@
 			ret = doveadm_cmd_host_set(conn, line + 9);
 		else if (strncmp(line, "HOST-REMOVE\t", 12) == 0)
 			ret = doveadm_cmd_host_remove(conn, line + 12);
+		else if (strncmp(line, "USER-LOOKUP\t", 12) == 0)
+			ret = doveadm_cmd_user_lookup(conn, line + 12);
 		else {
 			i_error("doveadm sent unknown command: %s", line);
 			ret = FALSE;
diff -r 5f77c91f3df0 -r c57c1ff9c5f1 src/doveadm/doveadm-director.c
--- a/src/doveadm/doveadm-director.c	Thu May 20 10:43:47 2010 +0200
+++ b/src/doveadm/doveadm-director.c	Thu May 20 11:46:21 2010 +0200
@@ -77,12 +77,36 @@
 	return ctx;
 }
 
+static void
+cmd_director_status_user(struct director_context *ctx, const char *user)
+{
+	const char *line;
+
+	director_send(ctx, t_strdup_printf("USER-LOOKUP\t%s\n", user));
+	line = i_stream_read_next_line(ctx->input);
+	if (line == NULL) {
+		printf("Lookup failed\n");
+		return;
+	}
+
+	if (strcmp(line, "NOTFOUND") == 0)
+		printf("User not assigned to any server\n");
+	else
+		printf("%s\n", line);
+	director_disconnect(ctx);
+}
+
 static void cmd_director_status(int argc, char *argv[])
 {
 	struct director_context *ctx;
 	const char *line, *const *args;
 
 	ctx = cmd_director_init(argc, argv, 0);
+	if (argv[optind] != NULL) {
+		cmd_director_status_user(ctx, argv[optind]);
+		return;
+	}
+
 	fprintf(stderr, "%-20s vhosts  users\n", "mail server ip");
 	director_send(ctx, "HOST-LIST\n");
 	while ((line = i_stream_read_next_line(ctx->input)) != NULL) {
@@ -191,7 +215,7 @@
 
 struct doveadm_cmd doveadm_cmd_director[] = {
 	{ cmd_director_status, "director status",
-	  "[-a <director socket path>]", NULL },
+	  "[-a <director socket path>] [<username>]", NULL },
 	{ cmd_director_add, "director add",
 	  "[-a <director socket path>] <host> [<vhost count>]", NULL },
 	{ cmd_director_remove, "director remove",


More information about the dovecot-cvs mailing list