From: Timo Sirainen Date: Thu, 13 Jan 2022 16:07:02 +0000 (+0200) Subject: pop3: Add admin-client with KICK-USER command X-Git-Tag: 2.4.0~4531 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=762045d2d4ea1a9a82db6a12b2c6b8333d42e439;p=thirdparty%2Fdovecot%2Fcore.git pop3: Add admin-client with KICK-USER command --- diff --git a/src/pop3/main.c b/src/pop3/main.c index 572a82df72..fd4eb06bb0 100644 --- a/src/pop3/main.c +++ b/src/pop3/main.c @@ -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 = diff --git a/src/pop3/pop3-client.c b/src/pop3/pop3-client.c index 2d68debe5e..36d1ebe98d 100644 --- a/src/pop3/pop3-client.c +++ b/src/pop3/pop3-client.c @@ -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 = { diff --git a/src/pop3/pop3-client.h b/src/pop3/pop3-client.h index 853f65fa5c..98e574d93f 100644 --- a/src/pop3/pop3-client.h +++ b/src/pop3/pop3-client.h @@ -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, ...)