|
|
b62b43 |
From 62061e8cf68f506c0ccaaba21fd4174764ca875f Mon Sep 17 00:00:00 2001
|
|
|
b62b43 |
From: Timo Sirainen <timo.sirainen@open-xchange.com>
|
|
|
b62b43 |
Date: Mon, 17 Aug 2020 18:15:35 +0300
|
|
|
b62b43 |
Subject: [PATCH] imap-login: Split off client_invalid_command()
|
|
|
b62b43 |
|
|
|
b62b43 |
---
|
|
|
b62b43 |
src/imap-login/imap-login-client.c | 27 +++++++++++++++++----------
|
|
|
b62b43 |
1 file changed, 17 insertions(+), 10 deletions(-)
|
|
|
b62b43 |
|
|
|
b62b43 |
diff --git a/src/imap-login/imap-login-client.c b/src/imap-login/imap-login-client.c
|
|
|
b62b43 |
index e2af176309..ce5049d567 100644
|
|
|
b62b43 |
--- a/src/imap-login/imap-login-client.c
|
|
|
b62b43 |
+++ b/src/imap-login/imap-login-client.c
|
|
|
b62b43 |
@@ -194,6 +194,22 @@ static int client_command_execute(struct imap_client *client, const char *cmd,
|
|
|
b62b43 |
return login_cmd->func(client, args);
|
|
|
b62b43 |
}
|
|
|
b62b43 |
|
|
|
b62b43 |
+static bool client_invalid_command(struct imap_client *client)
|
|
|
b62b43 |
+{
|
|
|
b62b43 |
+ if (*client->cmd_tag == '\0')
|
|
|
b62b43 |
+ client->cmd_tag = "*";
|
|
|
b62b43 |
+ if (++client->common.bad_counter >= CLIENT_MAX_BAD_COMMANDS) {
|
|
|
b62b43 |
+ client_send_reply(&client->common, IMAP_CMD_REPLY_BYE,
|
|
|
b62b43 |
+ "Too many invalid IMAP commands.");
|
|
|
b62b43 |
+ client_destroy(&client->common,
|
|
|
b62b43 |
+ "Disconnected: Too many invalid commands");
|
|
|
b62b43 |
+ return FALSE;
|
|
|
b62b43 |
+ }
|
|
|
b62b43 |
+ client_send_reply(&client->common, IMAP_CMD_REPLY_BAD,
|
|
|
b62b43 |
+ "Error in IMAP command received by server.");
|
|
|
b62b43 |
+ return TRUE;
|
|
|
b62b43 |
+}
|
|
|
b62b43 |
+
|
|
|
b62b43 |
static bool imap_is_valid_tag(const char *tag)
|
|
|
b62b43 |
{
|
|
|
b62b43 |
for (; *tag != '\0'; tag++) {
|
|
|
b62b43 |
@@ -326,17 +342,8 @@ static bool imap_client_input_next_cmd(struct client *_client)
|
|
|
b62b43 |
"not the command name. Add that before the command, "
|
|
|
b62b43 |
"like: a login user pass");
|
|
|
b62b43 |
} else if (ret < 0) {
|
|
|
b62b43 |
- if (*client->cmd_tag == '\0')
|
|
|
b62b43 |
- client->cmd_tag = "*";
|
|
|
b62b43 |
- if (++client->common.bad_counter >= CLIENT_MAX_BAD_COMMANDS) {
|
|
|
b62b43 |
- client_send_reply(&client->common, IMAP_CMD_REPLY_BYE,
|
|
|
b62b43 |
- "Too many invalid IMAP commands.");
|
|
|
b62b43 |
- client_destroy(&client->common,
|
|
|
b62b43 |
- "Disconnected: Too many invalid commands");
|
|
|
b62b43 |
+ if (!client_invalid_command(client))
|
|
|
b62b43 |
return FALSE;
|
|
|
b62b43 |
- }
|
|
|
b62b43 |
- client_send_reply(&client->common, IMAP_CMD_REPLY_BAD,
|
|
|
b62b43 |
- "Error in IMAP command received by server.");
|
|
|
b62b43 |
}
|
|
|
b62b43 |
|
|
|
b62b43 |
return ret != 0 && !client->common.destroyed;
|