diff src/director/doveadm-connection.c @ 13045:79f9dce5d5fd

director: Added support for moving user to another server with "doveadm director move".
author Timo Sirainen <tss@iki.fi>
date Mon, 23 May 2011 14:54:02 +0300
parents c838d40bd38e
children 63680f6e21a2
line wrap: on
line diff
--- a/src/director/doveadm-connection.c	Fri May 20 21:46:32 2011 +0300
+++ b/src/director/doveadm-connection.c	Mon May 23 14:54:02 2011 +0300
@@ -267,6 +267,41 @@
 	return TRUE;
 }
 
+static bool
+doveadm_cmd_user_move(struct doveadm_connection *conn, const char *line)
+{
+	unsigned int username_hash;
+	const char *const *args;
+	struct user *user;
+	struct mail_host *host;
+	struct ip_addr ip;
+
+	args = t_strsplit(line, "\t");
+	if (args[0] == NULL || args[1] == NULL ||
+	    net_addr2ip(args[1], &ip) < 0) {
+		i_error("doveadm sent invalid USER-MOVE parameters: %s", line);
+		return FALSE;
+	}
+	host = mail_host_lookup(conn->dir->mail_hosts, &ip);
+	if (host == NULL) {
+		o_stream_send_str(conn->output, "NOTFOUND\n");
+		return TRUE;
+	}
+
+	if (str_to_uint(args[0], &username_hash) < 0)
+		username_hash = user_directory_get_username_hash(line);
+	user = user_directory_lookup(conn->dir->users, username_hash);
+	if (user != NULL && user->kill_state != USER_KILL_STATE_NONE) {
+		o_stream_send_str(conn->output, "TRYAGAIN\n");
+		return TRUE;
+	}
+
+	director_move_user(conn->dir, conn->dir->self_host, NULL,
+			   username_hash, host);
+	o_stream_send(conn->output, "OK\n", 3);
+	return TRUE;
+}
+
 static void doveadm_connection_input(struct doveadm_connection *conn)
 {
 	const char *line, *cmd, *args;
@@ -315,6 +350,8 @@
 			ret = doveadm_cmd_user_lookup(conn, args);
 		else if (strcmp(cmd, "USER-LIST") == 0)
 			ret = doveadm_cmd_user_list(conn, args);
+		else if (strcmp(cmd, "USER-MOVE") == 0)
+			ret = doveadm_cmd_user_move(conn, args);
 		else {
 			i_error("doveadm sent unknown command: %s", line);
 			ret = FALSE;