From: Timo Sirainen Date: Thu, 20 May 2010 09:46:21 +0000 (+0200) Subject: doveadm director status username now returns which server the user is assigned to. X-Git-Tag: 2.0.beta6~179 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b2024fa4e6ed39f9b5b6bb6c051f6d535fc0e011;p=thirdparty%2Fdovecot%2Fcore.git doveadm director status username now returns which server the user is assigned to. --HG-- branch : HEAD --- diff --git a/src/director/doveadm-connection.c b/src/director/doveadm-connection.c index b69b193aae..e1de4edec9 100644 --- a/src/director/doveadm-connection.c +++ b/src/director/doveadm-connection.c @@ -115,6 +115,23 @@ doveadm_cmd_host_remove(struct doveadm_connection *conn, const char *line) 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 @@ static void doveadm_connection_input(struct doveadm_connection *conn) 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 --git a/src/doveadm/doveadm-director.c b/src/doveadm/doveadm-director.c index 2fde7a16ec..8d27edadfe 100644 --- a/src/doveadm/doveadm-director.c +++ b/src/doveadm/doveadm-director.c @@ -77,12 +77,36 @@ cmd_director_init(int argc, char *argv[], unsigned int cmd_idx) 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 @@ static void cmd_director_remove(int argc, char *argv[]) struct doveadm_cmd doveadm_cmd_director[] = { { cmd_director_status, "director status", - "[-a ]", NULL }, + "[-a ] []", NULL }, { cmd_director_add, "director add", "[-a ] []", NULL }, { cmd_director_remove, "director remove",