From: Timo Sirainen Date: Thu, 9 Apr 2020 20:15:05 +0000 (+0300) Subject: login-proxy: Split off proxy_check_start() X-Git-Tag: 2.3.11.2~214 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=509906c48ef30bb6174d6c916f9977c6ffd3365f;p=thirdparty%2Fdovecot%2Fcore.git login-proxy: Split off proxy_check_start() --- diff --git a/src/login-common/client-common-auth.c b/src/login-common/client-common-auth.c index eb3b6749a6..a3c830fa64 100644 --- a/src/login-common/client-common-auth.c +++ b/src/login-common/client-common-auth.c @@ -382,47 +382,55 @@ static void proxy_input(struct client *client) o_stream_unref(&output); } -static int proxy_start(struct client *client, - const struct client_auth_reply *reply) +static bool +proxy_check_start(struct client *client, const struct client_auth_reply *reply, + const struct dsasl_client_mech **sasl_mech_r) { - struct login_proxy_settings proxy_set; - const struct dsasl_client_mech *sasl_mech = NULL; - - i_assert(reply->destuser != NULL); - i_assert(!client->destroyed); - i_assert(client->proxy_sasl_client == NULL); - - client->proxy_mech = NULL; - client->v.proxy_reset(client); - if (reply->password == NULL) { e_error(client->event, "proxy: password not given"); - client_proxy_error(client, PROXY_FAILURE_MSG); - return -1; + return FALSE; } if (reply->host == NULL || *reply->host == '\0') { e_error(client->event, "proxy: host not given"); - client_proxy_error(client, PROXY_FAILURE_MSG); - return -1; + return FALSE; } if (reply->proxy_mech != NULL) { - sasl_mech = dsasl_client_mech_find(reply->proxy_mech); - if (sasl_mech == NULL) { + *sasl_mech_r = dsasl_client_mech_find(reply->proxy_mech); + if (*sasl_mech_r == NULL) { e_error(client->event, "proxy: Unsupported SASL mechanism %s", reply->proxy_mech); - client_proxy_error(client, PROXY_FAILURE_MSG); - return -1; + return FALSE; } } else if (reply->master_user != NULL) { /* have to use PLAIN authentication with master user logins */ - sasl_mech = &dsasl_client_mech_plain; + *sasl_mech_r = &dsasl_client_mech_plain; } if (login_proxy_is_ourself(client, reply->host, reply->port, reply->destuser)) { e_error(client->event, "Proxying loops to itself"); + return FALSE; + } + return TRUE; +} + +static int proxy_start(struct client *client, + const struct client_auth_reply *reply) +{ + struct login_proxy_settings proxy_set; + const struct dsasl_client_mech *sasl_mech = NULL; + + i_assert(reply->destuser != NULL); + i_assert(client->refcount > 1); + i_assert(!client->destroyed); + i_assert(client->proxy_sasl_client == NULL); + + client->proxy_mech = NULL; + client->v.proxy_reset(client); + + if (!proxy_check_start(client, reply, &sasl_mech)) { client_proxy_error(client, PROXY_FAILURE_MSG); return -1; }