changeset 22184:4f4219ee5933

imapc: Change auth_failed boolean to more specific auth_failed_state Since we now rely on auth_failed_state being initialized to zero, explicitly set IMAPC_COMMAND_STATE_OK to be defined as 0.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Mon, 12 Jun 2017 11:32:23 +0300
parents 8b503d60ab43
children 5a799d773a6b
files src/lib-imap-client/imapc-client.h src/lib-storage/index/imapc/imapc-list.c src/lib-storage/index/imapc/imapc-storage.c src/lib-storage/index/imapc/imapc-storage.h
diffstat 4 files changed, 22 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-imap-client/imapc-client.h	Mon Jun 12 11:05:31 2017 +0300
+++ b/src/lib-imap-client/imapc-client.h	Mon Jun 12 11:32:23 2017 +0300
@@ -7,7 +7,7 @@
 #define IMAPC_DEFAULT_MAX_IDLE_TIME (60*29)
 
 enum imapc_command_state {
-	IMAPC_COMMAND_STATE_OK,
+	IMAPC_COMMAND_STATE_OK = 0,
 	IMAPC_COMMAND_STATE_NO,
 	IMAPC_COMMAND_STATE_BAD,
 	/* Authentication to IMAP server failed (NO or BAD) */
--- a/src/lib-storage/index/imapc/imapc-list.c	Mon Jun 12 11:05:31 2017 +0300
+++ b/src/lib-storage/index/imapc/imapc-list.c	Mon Jun 12 11:32:23 2017 +0300
@@ -128,7 +128,7 @@
 		imapc_list_copy_error_from_reply(ctx->client->_list,
 						 MAIL_ERROR_PARAMS, reply);
 		ctx->ret = -1;
-	} else if (ctx->client->auth_failed) {
+	} else if (imapc_storage_client_handle_auth_failure(ctx->client)) {
 		ctx->ret = -1;
 	} else if (reply->state == IMAPC_COMMAND_STATE_DISCONNECTED) {
 		mailbox_list_set_internal_error(&ctx->client->_list->list);
@@ -284,7 +284,7 @@
 		imapc_list_sep_verify(list);
 	else if (reply->state == IMAPC_COMMAND_STATE_NO)
 		imapc_list_copy_error_from_reply(list, MAIL_ERROR_PARAMS, reply);
-	else if (list->client->auth_failed)
+	else if (imapc_storage_client_handle_auth_failure(list->client))
 		;
 	else if (reply->state == IMAPC_COMMAND_STATE_DISCONNECTED)
 		mailbox_list_set_internal_error(&list->list);
@@ -312,7 +312,7 @@
 int imapc_list_try_get_root_sep(struct imapc_mailbox_list *list, char *sep_r)
 {
 	if (list->root_sep == '\0') {
-		if (list->client->auth_failed)
+		if (imapc_storage_client_handle_auth_failure(list->client))
 			return -1;
 		imapc_list_send_hierarcy_sep_lookup(list);
 		while (list->root_sep_pending)
@@ -552,7 +552,7 @@
 	struct mailbox_node *node;
 	const char *pattern;
 
-	if (list->client->auth_failed)
+	if (imapc_storage_client_handle_auth_failure(list->client))
 		return -1;
 	if (list->root_sep_lookup_failed) {
 		mailbox_list_set_internal_error(&list->list);
--- a/src/lib-storage/index/imapc/imapc-storage.c	Mon Jun 12 11:05:31 2017 +0300
+++ b/src/lib-storage/index/imapc/imapc-storage.c	Mon Jun 12 11:32:23 2017 +0300
@@ -119,7 +119,7 @@
 
 void imapc_simple_run(struct imapc_simple_context *sctx)
 {
-	if (sctx->client->auth_failed) {
+	if (imapc_storage_client_handle_auth_failure(sctx->client)) {
 		imapc_client_logout(sctx->client->client);
 		sctx->ret = -1;
 	}
@@ -151,7 +151,7 @@
 		imapc_copy_error_from_reply(ctx->client->_storage,
 					    MAIL_ERROR_PARAMS, reply);
 		ctx->ret = -1;
-	} else if (ctx->client->auth_failed) {
+	} else if (imapc_storage_client_handle_auth_failure(ctx->client)) {
 		ctx->ret = -1;
 	} else if (reply->state == IMAPC_COMMAND_STATE_DISCONNECTED) {
 		mail_storage_set_internal_error(&ctx->client->_storage->storage);
@@ -229,7 +229,7 @@
 		return;
 	}
 
-	client->auth_failed = TRUE;
+	client->auth_failed_state = reply->state;
 	client->auth_error = i_strdup(reply->text_full);
 
 	if (client->_storage != NULL) {
@@ -250,6 +250,11 @@
 	}
 }
 
+bool imapc_storage_client_handle_auth_failure(struct imapc_storage_client *client)
+{
+	return client->auth_failed_state != IMAPC_COMMAND_STATE_OK;
+}
+
 static void imapc_storage_client_login(struct imapc_storage_client *client,
 				       struct mail_user *user, const char *host)
 {
@@ -260,7 +265,7 @@
 		   if it fails. */
 		while (!client->auth_returned)
 			imapc_client_run(client->client);
-		if (client->auth_failed) {
+		if (imapc_storage_client_handle_auth_failure(client)) {
 			user->error = p_strdup_printf(user->pool,
 				"imapc: Login to %s failed: %s",
 				host, client->auth_error);
@@ -510,7 +515,7 @@
 
 	struct imapc_mailbox_list *list = (struct imapc_mailbox_list *)box->list;
 
-	if (list->client->auth_failed) {
+	if (imapc_storage_client_handle_auth_failure(list->client)) {
 		mail_storage_copy_list_error(box->storage, box->list);
 		return -1;
 	}
@@ -636,7 +641,7 @@
 		imapc_copy_error_from_reply(ctx->mbox->storage,
 					    MAIL_ERROR_NOTFOUND, reply);
 		ctx->ret = -1;
-	} else if (ctx->mbox->storage->client->auth_failed) {
+	} else if (imapc_storage_client_handle_auth_failure(ctx->mbox->storage->client)) {
 		ctx->ret = -1;
 	} else if (reply->state == IMAPC_COMMAND_STATE_DISCONNECTED) {
 		ctx->ret = -1;
@@ -676,7 +681,7 @@
 	i_assert(mbox->client_box == NULL);
 
 	/* If authentication failed, don't check again. */
-	if (mbox->storage->client->auth_failed) {
+	if (imapc_storage_client_handle_auth_failure(mbox->storage->client)) {
 		return -1;
 	}
 	if (imapc_mailbox_get_capabilities(mbox) < 0)
--- a/src/lib-storage/index/imapc/imapc-storage.h	Mon Jun 12 11:05:31 2017 +0300
+++ b/src/lib-storage/index/imapc/imapc-storage.h	Mon Jun 12 11:32:23 2017 +0300
@@ -52,7 +52,11 @@
 
 	ARRAY(struct imapc_storage_event_callback) untagged_callbacks;
 
+	/* IMAPC_COMMAND_STATE_OK if no auth failure (yet), otherwise result to
+	   the LOGIN/AUTHENTICATE command. */
+	enum imapc_command_state auth_failed_state;
 	char *auth_error;
+
 	/* Authentication reply was received (success or failure) */
 	bool auth_returned:1;
 	/* Authentication failed */
@@ -154,6 +158,7 @@
 				struct imapc_storage_client **client_r,
 				const char **error_r);
 void imapc_storage_client_unref(struct imapc_storage_client **client);
+bool imapc_storage_client_handle_auth_failure(struct imapc_storage_client *client);
 
 struct mail_save_context *
 imapc_save_alloc(struct mailbox_transaction_context *_t);