]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm director kick: Added -f <passdb field> parameter.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 6 Oct 2016 12:22:13 +0000 (15:22 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 13 Oct 2016 08:27:13 +0000 (10:27 +0200)
This works for all the user_* passdb fields.

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

index 89c423b7111d1d3bbea70ceb7463b13df4a2d35b..0bab7c4731edfccf7ff2fc03768a1b9f7569f137 100644 (file)
@@ -1089,6 +1089,25 @@ director_cmd_user_kick(struct director_connection *conn,
        return TRUE;
 }
 
+static bool
+director_cmd_user_kick_alt(struct director_connection *conn,
+                          const char *const *args)
+{
+       struct director_host *dir_host;
+       int ret;
+
+       if ((ret = director_cmd_is_seen(conn, &args, &dir_host)) != 0)
+               return ret > 0;
+
+       if (str_array_length(args) != 2) {
+               director_cmd_error(conn, "Invalid parameters");
+               return FALSE;
+       }
+
+       director_kick_user_alt(conn->dir, conn->host, dir_host, args[0], args[1]);
+       return TRUE;
+}
+
 static bool
 director_cmd_user_kick_hash(struct director_connection *conn,
                            const char *const *args)
@@ -1579,6 +1598,8 @@ director_connection_handle_cmd(struct director_connection *conn,
                return director_cmd_user_move(conn, args);
        if (strcmp(cmd, "USER-KICK") == 0)
                return director_cmd_user_kick(conn, args);
+       if (strcmp(cmd, "USER-KICK-ALT") == 0)
+               return director_cmd_user_kick_alt(conn, args);
        if (strcmp(cmd, "USER-KICK-HASH") == 0)
                return director_cmd_user_kick_hash(conn, args);
        if (strcmp(cmd, "USER-KILLED") == 0)
index 5796d3945cf611a2e9c78c736a60216d121d9423..b0e6c952fca988b611d50996970cbc357eb2e5b3 100644 (file)
@@ -907,6 +907,32 @@ void director_kick_user(struct director *dir, struct director_host *src,
        director_update_send_version(dir, src, DIRECTOR_VERSION_USER_KICK, str_c(cmd));
 }
 
+void director_kick_user_alt(struct director *dir, struct director_host *src,
+                           struct director_host *orig_src,
+                           const char *field, const char *value)
+{
+       string_t *cmd = t_str_new(64);
+
+       str_append(cmd, "proxy\t*\tKICK-ALT\t");
+       str_append_tabescaped(cmd, field);
+       str_append_c(cmd, '\t');
+       str_append_tabescaped(cmd, value);
+       ipc_client_cmd(dir->ipc_proxy, str_c(cmd),
+                      director_kick_user_callback, (void *)NULL);
+
+       if (orig_src == NULL) {
+               orig_src = dir->self_host;
+               orig_src->last_seq++;
+       }
+       str_printfa(cmd, "USER-KICK-ALT\t%s\t%u\t%u\t",
+               net_ip2addr(&orig_src->ip), orig_src->port, orig_src->last_seq);
+       str_append_tabescaped(cmd, field);
+       str_append_c(cmd, '\t');
+       str_append_tabescaped(cmd, value);
+       str_append_c(cmd, '\n');
+       director_update_send_version(dir, src, DIRECTOR_VERSION_USER_KICK_ALT, str_c(cmd));
+}
+
 void director_kick_user_hash(struct director *dir, struct director_host *src,
                             struct director_host *orig_src,
                             unsigned int username_hash,
index 42e225bdbc30084bd153f3144a100e8877afc68f..5e4b1327ac1e36438c9b33f29e456468b54107e7 100644 (file)
@@ -6,7 +6,7 @@
 
 #define DIRECTOR_VERSION_NAME "director"
 #define DIRECTOR_VERSION_MAJOR 1
-#define DIRECTOR_VERSION_MINOR 7
+#define DIRECTOR_VERSION_MINOR 8
 
 /* weak users supported in protocol */
 #define DIRECTOR_VERSION_WEAK_USERS 1
@@ -24,6 +24,8 @@
 #define DIRECTOR_VERSION_UPDOWN 6
 /* user tag version 2 supported */
 #define DIRECTOR_VERSION_TAGS_V2 7
+/* user-kick-alt supported */
+#define DIRECTOR_VERSION_USER_KICK_ALT 8
 
 /* Minimum time between even attempting to communicate with a director that
    failed due to a protocol error. */
@@ -150,6 +152,10 @@ void director_move_user(struct director *dir, struct director_host *src,
 void director_kick_user(struct director *dir, struct director_host *src,
                        struct director_host *orig_src, const char *username)
        ATTR_NULL(3);
+void director_kick_user_alt(struct director *dir, struct director_host *src,
+                           struct director_host *orig_src,
+                           const char *field, const char *value)
+       ATTR_NULL(3);
 void director_kick_user_hash(struct director *dir, struct director_host *src,
                             struct director_host *orig_src,
                             unsigned int username_hash,
index c85d48a3c8e365b518659122e96bc4d9d4f5f85a..772575608271c53ec78c554b1adcfffaef8a288d 100644 (file)
@@ -27,6 +27,7 @@ struct director_context {
        const char *ip;
        const char *port;
        const char *vhost_count;
+       const char *passdb_field;
 
        struct istream *users_input;
        struct istream *input;
@@ -125,6 +126,8 @@ cmd_director_init(struct doveadm_cmd_context *cctx)
                ctx->port = NULL;
        if (!doveadm_cmd_param_str(cctx, "vhost-count", &(ctx->vhost_count)))
                ctx->vhost_count = NULL;
+       if (!doveadm_cmd_param_str(cctx, "passdb-field", &(ctx->passdb_field)))
+               ctx->passdb_field = NULL;
        if (!ctx->user_map)
                director_connect(ctx);
        return ctx;
@@ -595,11 +598,19 @@ static void cmd_director_kick(struct doveadm_cmd_context *cctx)
                return;
        }
 
-       str_append(cmd, "USER-KICK\t");
-       str_append_tabescaped(cmd, ctx->user);
-       str_append_c(cmd, '\n');
-
+       if (ctx->passdb_field == NULL) {
+               str_append(cmd, "USER-KICK\t");
+               str_append_tabescaped(cmd, ctx->user);
+               str_append_c(cmd, '\n');
+       } else {
+               str_append(cmd, "USER-KICK-ALT\t");
+               str_append_tabescaped(cmd, ctx->passdb_field);
+               str_append_c(cmd, '\t');
+               str_append_tabescaped(cmd, ctx->user);
+               str_append_c(cmd, '\n');
+       }
        director_send(ctx, str_c(cmd));
+
        line = i_stream_read_next_line(ctx->input);
        if (line == NULL) {
                i_error("failed");
@@ -921,9 +932,10 @@ DOVEADM_CMD_PARAMS_END
 {
        .name = "director kick",
        .cmd = cmd_director_kick,
-       .usage = "[-a <director socket path>] <user>",
+       .usage = "[-a <director socket path>] [-f <passdb field>] <user>",
 DOVEADM_CMD_PARAMS_START
 DOVEADM_CMD_PARAM('a', "socket-path", CMD_PARAM_STR, 0)
+DOVEADM_CMD_PARAM('\0', "passdb-field", CMD_PARAM_STR, 0)
 DOVEADM_CMD_PARAM('\0', "user", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL)
 DOVEADM_CMD_PARAMS_END
 },