]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
login-proxy: Split off proxy_check_start()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 9 Apr 2020 20:15:05 +0000 (23:15 +0300)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Fri, 24 Apr 2020 08:02:40 +0000 (08:02 +0000)
src/login-common/client-common-auth.c

index eb3b6749a6f722dc0ec91453283a2fc735613760..a3c830fa64d54db54cde7bf83cb3a7c78c95599e 100644 (file)
@@ -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;
        }