From: Timo Sirainen Date: Sun, 19 Mar 2017 13:32:53 +0000 (+0200) Subject: imapc: Fail user creation if login to imapc_host fails. X-Git-Tag: 2.2.29.rc1~84 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a7b684786e67a00a44cf3e4950a437ae4c374de2;p=thirdparty%2Fdovecot%2Fcore.git imapc: Fail user creation if login to imapc_host fails. 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. --- diff --git a/src/lib-storage/index/imapc/imapc-storage.c b/src/lib-storage/index/imapc/imapc-storage.c index 58d3531681..6744761b8e 100644 --- a/src/lib-storage/index/imapc/imapc-storage.c +++ b/src/lib-storage/index/imapc/imapc-storage.c @@ -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); } diff --git a/src/lib-storage/index/imapc/imapc-storage.h b/src/lib-storage/index/imapc/imapc-storage.h index 0eda3eb484..e3a3dd8fc3 100644 --- a/src/lib-storage/index/imapc/imapc-storage.h +++ b/src/lib-storage/index/imapc/imapc-storage.h @@ -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; };