From: Timo Sirainen Date: Mon, 12 Jun 2017 08:32:23 +0000 (+0300) Subject: imapc: Change auth_failed boolean to more specific auth_failed_state X-Git-Tag: 2.2.31.rc1~75 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b139348506f9acb242999d057d8aed110d602e9c;p=thirdparty%2Fdovecot%2Fcore.git 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. --- diff --git a/src/lib-imap-client/imapc-client.h b/src/lib-imap-client/imapc-client.h index 86709d6661..ad1e32f228 100644 --- a/src/lib-imap-client/imapc-client.h +++ b/src/lib-imap-client/imapc-client.h @@ -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) */ diff --git a/src/lib-storage/index/imapc/imapc-list.c b/src/lib-storage/index/imapc/imapc-list.c index 1091d95ef7..2d3318fb44 100644 --- a/src/lib-storage/index/imapc/imapc-list.c +++ b/src/lib-storage/index/imapc/imapc-list.c @@ -128,7 +128,7 @@ static void imapc_list_simple_callback(const struct imapc_command_reply *reply, 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 @@ static void imapc_storage_sep_callback(const struct imapc_command_reply *reply, 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 @@ static void imapc_list_send_hierarcy_sep_lookup(struct imapc_mailbox_list *list) 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 @@ static int imapc_list_refresh(struct imapc_mailbox_list *list) 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); diff --git a/src/lib-storage/index/imapc/imapc-storage.c b/src/lib-storage/index/imapc/imapc-storage.c index 374828c5c7..f4709b11ef 100644 --- a/src/lib-storage/index/imapc/imapc-storage.c +++ b/src/lib-storage/index/imapc/imapc-storage.c @@ -119,7 +119,7 @@ void imapc_simple_context_init(struct imapc_simple_context *sctx, 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 @@ void imapc_simple_callback(const struct imapc_command_reply *reply, 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 @@ imapc_storage_client_login_callback(const struct imapc_command_reply *reply, 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 @@ imapc_storage_client_login_callback(const struct imapc_command_reply *reply, } } +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 @@ static void imapc_storage_client_login(struct imapc_storage_client *client, 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 @@ imapc_mailbox_exists(struct mailbox *box, bool auto_boxes ATTR_UNUSED, 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_mailbox_open_callback(const struct imapc_command_reply *reply, 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 @@ int imapc_mailbox_select(struct imapc_mailbox *mbox) 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) diff --git a/src/lib-storage/index/imapc/imapc-storage.h b/src/lib-storage/index/imapc/imapc-storage.h index a5c69e99a6..dad7a1ee41 100644 --- a/src/lib-storage/index/imapc/imapc-storage.h +++ b/src/lib-storage/index/imapc/imapc-storage.h @@ -52,7 +52,11 @@ struct imapc_storage_client { 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 @@ int imapc_storage_client_create(struct mail_namespace *ns, 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);