]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm director status username now returns which server the user is assigned to.
authorTimo Sirainen <tss@iki.fi>
Thu, 20 May 2010 09:46:21 +0000 (11:46 +0200)
committerTimo Sirainen <tss@iki.fi>
Thu, 20 May 2010 09:46:21 +0000 (11:46 +0200)
--HG--
branch : HEAD

src/director/doveadm-connection.c
src/doveadm/doveadm-director.c

index b69b193aaea419d12d1351126fa1fe93298c51e1..e1de4edec93475902b71589d9c8806f7207bb935 100644 (file)
@@ -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;
index 2fde7a16ecc26c4ca48e15e99c4a664e1147a218..8d27edadfe4dd7216da9ad864c8f2bdf69fc53f6 100644 (file)
@@ -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 <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",