dovecot-2.1: imap-login: Fixed handling second AUTHENTICATE comm...

dovecot at dovecot.org dovecot at dovecot.org
Sat Jan 21 18:31:37 EET 2012


details:   http://hg.dovecot.org/dovecot-2.1/rev/32cf5ed72e2d
changeset: 13979:32cf5ed72e2d
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Jan 21 18:31:25 2012 +0200
description:
imap-login: Fixed handling second AUTHENTICATE command when the first one failed.

diffstat:

 src/imap-login/client-authenticate.c  |  12 +++++++++---
 src/imap-login/client-authenticate.h  |   2 +-
 src/imap-login/client.c               |   5 +++--
 src/imap-login/client.h               |   1 +
 src/login-common/client-common-auth.c |   2 ++
 5 files changed, 16 insertions(+), 6 deletions(-)

diffs (103 lines):

diff -r e9f68fdf6967 -r 32cf5ed72e2d src/imap-login/client-authenticate.c
--- a/src/imap-login/client-authenticate.c	Sat Jan 21 00:43:13 2012 +0200
+++ b/src/imap-login/client-authenticate.c	Sat Jan 21 18:31:25 2012 +0200
@@ -118,7 +118,7 @@
 	return client_auth_begin(&imap_client->common, mech_name, init_resp);
 }
 
-int cmd_authenticate(struct imap_client *imap_client)
+int cmd_authenticate(struct imap_client *imap_client, bool *parsed_r)
 {
 	/* NOTE: This command's input is handled specially because the
 	   SASL-IR can be large. */
@@ -127,8 +127,10 @@
 	size_t i, size;
 	int ret;
 
+	*parsed_r = FALSE;
+
 	/* <auth mechanism name> [<initial SASL response>] */
-	if (client->auth_mech_name == NULL) {
+	if (!imap_client->auth_mech_name_parsed) {
 		data = i_stream_get_data(client->input, &size);
 		for (i = 0; i < size; i++) {
 			if (data[i] == ' ' ||
@@ -142,7 +144,9 @@
 			imap_client->skip_line = TRUE;
 			return -1;
 		}
+		i_free(client->auth_mech_name);
 		client->auth_mech_name = i_strndup(data, i);
+		imap_client->auth_mech_name_parsed = TRUE;
 		if (data[i] == ' ')
 			i++;
 		i_stream_skip(client->input, i);
@@ -152,9 +156,11 @@
 	if ((ret = client_auth_read_line(client)) <= 0)
 		return ret;
 
+	*parsed_r = TRUE;
+	imap_client->auth_mech_name_parsed = FALSE;
 	return imap_client_auth_begin(imap_client,
 				      t_strdup(client->auth_mech_name),
-				      str_c(client->auth_response));
+				      t_strdup(str_c(client->auth_response)));
 }
 
 int cmd_login(struct imap_client *imap_client, const struct imap_arg *args)
diff -r e9f68fdf6967 -r 32cf5ed72e2d src/imap-login/client-authenticate.h
--- a/src/imap-login/client-authenticate.h	Sat Jan 21 00:43:13 2012 +0200
+++ b/src/imap-login/client-authenticate.h	Sat Jan 21 18:31:25 2012 +0200
@@ -9,6 +9,6 @@
 				   const struct client_auth_reply *reply);
 
 int cmd_login(struct imap_client *client, const struct imap_arg *args);
-int cmd_authenticate(struct imap_client *client);
+int cmd_authenticate(struct imap_client *imap_client, bool *parsed_r);
 
 #endif
diff -r e9f68fdf6967 -r 32cf5ed72e2d src/imap-login/client.c
--- a/src/imap-login/client.c	Sat Jan 21 00:43:13 2012 +0200
+++ b/src/imap-login/client.c	Sat Jan 21 18:31:25 2012 +0200
@@ -248,6 +248,7 @@
 static bool client_handle_input(struct imap_client *client)
 {
 	const struct imap_arg *args;
+	bool parsed;
 	int ret;
 
 	i_assert(!client->common.authenticating);
@@ -293,8 +294,8 @@
 	if (strcasecmp(client->cmd_name, "AUTHENTICATE") == 0) {
 		/* SASL-IR may need more space than input buffer's size,
 		   so we'll handle it as a special case. */
-		ret = cmd_authenticate(client);
-		if (ret == 0)
+		ret = cmd_authenticate(client, &parsed);
+		if (ret == 0 && !parsed)
 			return FALSE;
 	} else {
 		ret = client_parse_command(client, &args);
diff -r e9f68fdf6967 -r 32cf5ed72e2d src/imap-login/client.h
--- a/src/imap-login/client.h	Sat Jan 21 00:43:13 2012 +0200
+++ b/src/imap-login/client.h	Sat Jan 21 18:31:25 2012 +0200
@@ -23,6 +23,7 @@
 	unsigned int skip_line:1;
 	unsigned int id_logged:1;
 	unsigned int client_ignores_capability_resp_code:1;
+	unsigned int auth_mech_name_parsed:1;
 };
 
 bool client_skip_line(struct imap_client *client);
diff -r e9f68fdf6967 -r 32cf5ed72e2d src/login-common/client-common-auth.c
--- a/src/login-common/client-common-auth.c	Sat Jan 21 00:43:13 2012 +0200
+++ b/src/login-common/client-common-auth.c	Sat Jan 21 18:31:25 2012 +0200
@@ -24,6 +24,8 @@
 void client_auth_failed(struct client *client)
 {
 	i_free_and_null(client->master_data_prefix);
+	if (client->auth_response != NULL)
+		str_truncate(client->auth_response, 0);
 
 	if (client->auth_initializing || client->destroyed)
 		return;


More information about the dovecot-cvs mailing list