]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imapc: Fail user creation if login to imapc_host fails.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sun, 19 Mar 2017 13:32:53 +0000 (15:32 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 27 Mar 2017 10:07:02 +0000 (13:07 +0300)
This causes imapc to actually wait for the login to succeed or fail.
Such a wait was already done by the imap code, which will be removed by
the next patch.

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

index 58d3531681c52ffc33a869ed86963f0e93467abe..6744761b8e0aac268bf4e06a0fc10b0ca947fb6c 100644 (file)
@@ -216,11 +216,14 @@ imapc_storage_client_untagged_cb(const struct imapc_untagged_reply *reply,
 }
 
 static void
-imapc_storage_client_login(const struct imapc_command_reply *reply,
-                          void *context)
+imapc_storage_client_login_callback(const struct imapc_command_reply *reply,
+                                   void *context)
 {
        struct imapc_storage_client *client = context;
 
+       client->auth_returned = TRUE;
+       imapc_client_stop(client->client);
+
        if (reply->state == IMAPC_COMMAND_STATE_OK)
                return;
        if (client->destroying &&
@@ -231,6 +234,7 @@ imapc_storage_client_login(const struct imapc_command_reply *reply,
        }
 
        client->auth_failed = TRUE;
+       client->auth_error = i_strdup(reply->text_full);
 
        if (client->_storage != NULL) {
                if (reply->state == IMAPC_COMMAND_STATE_DISCONNECTED)
@@ -250,6 +254,24 @@ imapc_storage_client_login(const struct imapc_command_reply *reply,
        }
 }
 
+static void imapc_storage_client_login(struct imapc_storage_client *client,
+                                      struct mail_user *user, const char *host)
+{
+       imapc_client_login(client->client, imapc_storage_client_login_callback, client);
+       if (!user->namespaces_created) {
+               /* we're still initializing the user. wait for the
+                  login to finish, so we can fail the user creation
+                  if it fails. */
+               while (!client->auth_returned)
+                       imapc_client_run(client->client);
+               if (client->auth_failed) {
+                       user->error = p_strdup_printf(user->pool,
+                               "imapc: Login to %s failed: %s",
+                               host, client->auth_error);
+               }
+       }
+}
+
 int imapc_storage_client_create(struct mail_namespace *ns,
                                const struct imapc_settings *imapc_set,
                                const struct mail_storage_settings *mail_set,
@@ -318,7 +340,7 @@ int imapc_storage_client_create(struct mail_namespace *ns,
                                       imapc_storage_client_untagged_cb, client);
        if ((ns->flags & NAMESPACE_FLAG_LIST_PREFIX) != 0) {
                /* start logging in immediately */
-               imapc_client_login(client->client, imapc_storage_client_login, client);
+               imapc_storage_client_login(client, ns->user, set.host);
        }
 
        *client_r = client;
@@ -339,6 +361,7 @@ void imapc_storage_client_unref(struct imapc_storage_client **_client)
        array_foreach_modifiable(&client->untagged_callbacks, cb)
                i_free(cb->name);
        array_free(&client->untagged_callbacks);
+       i_free(client->auth_error);
        i_free(client);
 }
 
index 0eda3eb48422bd8f7cc5156fe508b306f7e43890..e3a3dd8fc31cecc97461c9453b07eac78b276359 100644 (file)
@@ -51,6 +51,10 @@ struct imapc_storage_client {
 
        ARRAY(struct imapc_storage_event_callback) untagged_callbacks;
 
+       char *auth_error;
+       /* Authentication reply was received (success or failure) */
+       bool auth_returned:1;
+       /* Authentication failed */
        unsigned int auth_failed:1;
        unsigned int destroying:1;
 };