From: Timo Sirainen Date: Mon, 17 Aug 2020 15:15:35 +0000 (+0300) Subject: imap-login: Split off client_invalid_command() X-Git-Tag: 2.3.13~40 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a7103e0c1d18fc88a0f811fbfee1b39c438aaf83;p=thirdparty%2Fdovecot%2Fcore.git imap-login: Split off client_invalid_command() --- diff --git a/src/imap-login/imap-login-client.c b/src/imap-login/imap-login-client.c index e2af176309..ce5049d567 100644 --- a/src/imap-login/imap-login-client.c +++ b/src/imap-login/imap-login-client.c @@ -194,6 +194,22 @@ static int client_command_execute(struct imap_client *client, const char *cmd, return login_cmd->func(client, args); } +static bool client_invalid_command(struct imap_client *client) +{ + if (*client->cmd_tag == '\0') + client->cmd_tag = "*"; + if (++client->common.bad_counter >= CLIENT_MAX_BAD_COMMANDS) { + client_send_reply(&client->common, IMAP_CMD_REPLY_BYE, + "Too many invalid IMAP commands."); + client_destroy(&client->common, + "Disconnected: Too many invalid commands"); + return FALSE; + } + client_send_reply(&client->common, IMAP_CMD_REPLY_BAD, + "Error in IMAP command received by server."); + return TRUE; +} + static bool imap_is_valid_tag(const char *tag) { for (; *tag != '\0'; tag++) { @@ -326,17 +342,8 @@ static bool imap_client_input_next_cmd(struct client *_client) "not the command name. Add that before the command, " "like: a login user pass"); } else if (ret < 0) { - if (*client->cmd_tag == '\0') - client->cmd_tag = "*"; - if (++client->common.bad_counter >= CLIENT_MAX_BAD_COMMANDS) { - client_send_reply(&client->common, IMAP_CMD_REPLY_BYE, - "Too many invalid IMAP commands."); - client_destroy(&client->common, - "Disconnected: Too many invalid commands"); + if (!client_invalid_command(client)) return FALSE; - } - client_send_reply(&client->common, IMAP_CMD_REPLY_BAD, - "Error in IMAP command received by server."); } return ret != 0 && !client->common.destroyed;