changeset 22186:4dc0ba97d01f

imapc: Make sure storage error has the proper auth failure error string The first failed command always had the correct error string, but the following failed commands just returned -1 without updating storage error. The storage error could have been something completely different by then.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Mon, 12 Jun 2017 11:40:03 +0300
parents 5a799d773a6b
children 226c1f5c34c2
files src/lib-storage/index/imapc/imapc-storage.c
diffstat 1 files changed, 26 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/imapc/imapc-storage.c	Mon Jun 12 11:33:38 2017 +0300
+++ b/src/lib-storage/index/imapc/imapc-storage.c	Mon Jun 12 11:40:03 2017 +0300
@@ -231,28 +231,36 @@
 
 	client->auth_failed_state = reply->state;
 	client->auth_failed_reason = i_strdup(reply->text_full);
-
-	if (client->_storage != NULL) {
-		if (reply->state == IMAPC_COMMAND_STATE_DISCONNECTED)
-			mail_storage_set_internal_error(&client->_storage->storage);
-		else {
-			mail_storage_set_error(&client->_storage->storage,
-					       MAIL_ERROR_PERM, reply->text_full);
-		}
-	}
-	if (client->_list != NULL) {
-		if (reply->state == IMAPC_COMMAND_STATE_DISCONNECTED)
-			mailbox_list_set_internal_error(&client->_list->list);
-		else {
-			mailbox_list_set_error(&client->_list->list,
-					       MAIL_ERROR_PERM, reply->text_full);
-		}
-	}
+	if (!imapc_storage_client_handle_auth_failure(client))
+		i_unreached();
 }
 
 bool imapc_storage_client_handle_auth_failure(struct imapc_storage_client *client)
 {
-	return client->auth_failed_state != IMAPC_COMMAND_STATE_OK;
+	if (client->auth_failed_state == IMAPC_COMMAND_STATE_OK)
+		return FALSE;
+
+	/* We need to set the error to either storage or to list, depending on
+	   whether the caller is from mail-storage.h API or mailbox-list.h API.
+	   We don't know here what the caller is though, so just set the error
+	   to both of them. */
+	if (client->_storage != NULL) {
+		if (client->auth_failed_state == IMAPC_COMMAND_STATE_DISCONNECTED)
+			mail_storage_set_internal_error(&client->_storage->storage);
+		else {
+			mail_storage_set_error(&client->_storage->storage,
+				MAIL_ERROR_PERM, client->auth_failed_reason);
+		}
+	}
+	if (client->_list != NULL) {
+		if (client->auth_failed_state == IMAPC_COMMAND_STATE_DISCONNECTED)
+			mailbox_list_set_internal_error(&client->_list->list);
+		else {
+			mailbox_list_set_error(&client->_list->list,
+				MAIL_ERROR_PERM, client->auth_failed_reason);
+		}
+	}
+	return TRUE;
 }
 
 static void imapc_storage_client_login(struct imapc_storage_client *client,