]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imapc: Make sure storage error has the proper auth failure error string
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 12 Jun 2017 08:40:03 +0000 (11:40 +0300)
committerGitLab <gitlab@git.dovecot.net>
Mon, 12 Jun 2017 13:23:59 +0000 (16:23 +0300)
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.

src/lib-storage/index/imapc/imapc-storage.c

index 9805d8516de3004e18e5fc3ca57efc8cbcf78298..1af89bdc3903b6c4d2e46f393dbcd9d44352a856 100644 (file)
@@ -231,28 +231,36 @@ imapc_storage_client_login_callback(const struct imapc_command_reply *reply,
 
        client->auth_failed_state = reply->state;
        client->auth_failed_reason = i_strdup(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)
+{
+       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 (reply->state == IMAPC_COMMAND_STATE_DISCONNECTED)
+               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, reply->text_full);
+                               MAIL_ERROR_PERM, client->auth_failed_reason);
                }
        }
        if (client->_list != NULL) {
-               if (reply->state == IMAPC_COMMAND_STATE_DISCONNECTED)
+               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, reply->text_full);
+                               MAIL_ERROR_PERM, client->auth_failed_reason);
                }
        }
-}
-
-bool imapc_storage_client_handle_auth_failure(struct imapc_storage_client *client)
-{
-       return client->auth_failed_state != IMAPC_COMMAND_STATE_OK;
+       return TRUE;
 }
 
 static void imapc_storage_client_login(struct imapc_storage_client *client,