]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imapc: Change auth_failed boolean to more specific auth_failed_state
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 12 Jun 2017 08:32:23 +0000 (11:32 +0300)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Tue, 13 Jun 2017 09:06:41 +0000 (12:06 +0300)
Since we now rely on auth_failed_state being initialized to zero,
explicitly set IMAPC_COMMAND_STATE_OK to be defined as 0.

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

index 86709d6661ab124468329e7ac292257d303334f0..ad1e32f228d8d110657c3d37dcb2232fc0928621 100644 (file)
@@ -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) */
index 1091d95ef7e81cb889529e97a320d531dc42f524..2d3318fb4426a4e2c6f6c01b36f31ebda09ec4b0 100644 (file)
@@ -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);
index 374828c5c7819c1847c537f4727746d91a336fa5..f4709b11ef934f740c7cd5891e79533ccb49d0b9 100644 (file)
@@ -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)
index a5c69e99a661c7c56e54e767ae30d1fbcd35c752..dad7a1ee4197c8c71157b938fd18bd87b3742fff 100644 (file)
@@ -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);