]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
pop3: Add admin-client with KICK-USER command
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 13 Jan 2022 16:07:02 +0000 (18:07 +0200)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 8 Feb 2022 09:48:24 +0000 (10:48 +0100)
src/pop3/main.c
src/pop3/pop3-client.c
src/pop3/pop3-client.h

index 572a82df7292f2c9fd78120bcb59ef3231ca0054..fd4eb06bb054d798f2e19f7ddfd4359c91ea06f1 100644 (file)
@@ -15,6 +15,7 @@
 #include "master-service.h"
 #include "master-login.h"
 #include "master-interface.h"
+#include "master-admin-client.h"
 #include "var-expand.h"
 #include "mail-error.h"
 #include "mail-user.h"
@@ -314,6 +315,26 @@ static void login_client_failed(const struct master_login_client *client,
        }
 }
 
+static unsigned int
+master_admin_cmd_kick_user(const char *user, const guid_128_t conn_guid)
+{
+       struct client *client, *next;
+       unsigned int count = 0;
+
+       for (client = pop3_clients; client != NULL; client = next) {
+               next = client->next;
+               if (strcmp(client->user->username, user) == 0 &&
+                   (guid_128_is_empty(conn_guid) ||
+                    guid_128_cmp(client->anvil_conn_guid, conn_guid) == 0))
+                       client_kick(client);
+       }
+       return count;
+}
+
+static const struct master_admin_client_callback admin_callbacks = {
+       .cmd_kick_user = master_admin_cmd_kick_user,
+};
+
 static void client_connected(struct master_service_connection *conn)
 {
        /* when running standalone, we shouldn't even get here */
@@ -397,6 +418,7 @@ int main(int argc, char *argv[])
        if (!IS_STANDALONE())
                master_login = master_login_init(master_service, &login_set);
 
+       master_admin_clients_init(&admin_callbacks);
        master_service_set_die_callback(master_service, pop3_die);
 
        storage_service =
index 2d68debe5e8a4c83463071d5aa8a614f1463e75a..36d1ebe98dc3b0e045877a6bf003f1c690b7a557 100644 (file)
@@ -846,16 +846,20 @@ static int client_output(struct client *client)
        }
 }
 
-void clients_destroy_all(void)
+void client_kick(struct client *client)
 {
-       while (pop3_clients != NULL) {
-               mail_storage_service_io_activate_user(pop3_clients->service_user);
-               if (pop3_clients->cmd == NULL) {
-                       client_send_line(pop3_clients,
-                               "-ERR [SYS/TEMP] Server shutting down.");
-               }
-               client_destroy(pop3_clients, "Server shutting down.");
+       mail_storage_service_io_activate_user(client->service_user);
+       if (client->cmd == NULL) {
+               client_send_line(client,
+                                "-ERR [SYS/TEMP] Server shutting down.");
        }
+       client_destroy(client, "Server shutting down.");
+}
+
+void clients_destroy_all(void)
+{
+       while (pop3_clients != NULL)
+               client_kick(pop3_clients);
 }
 
 struct pop3_client_vfuncs pop3_client_vfuncs = {
index 853f65fa5c9e6018745b9fede41904f5d5f05b0c..98e574d93f852a058918ed762196d1cc7b349b79 100644 (file)
@@ -132,6 +132,7 @@ void client_destroy(struct client *client, const char *reason) ATTR_NULL(2);
 
 /* Disconnect client connection */
 void client_disconnect(struct client *client, const char *reason);
+void client_kick(struct client *client);
 
 /* Send a line of data to client */
 void client_send_line(struct client *client, const char *fmt, ...)