]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap-login: Split off client_invalid_command()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 17 Aug 2020 15:15:35 +0000 (18:15 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 4 Jan 2021 22:59:38 +0000 (00:59 +0200)
src/imap-login/imap-login-client.c

index e2af176309cc07861bcd622bd846d09d76124bbc..ce5049d567a56ceff95604de70512c1c0ee21846 100644 (file)
@@ -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;