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;
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;
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) {
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",