]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
login proxy: Show proxy state in "disconnected" error message.
authorTimo Sirainen <tss@iki.fi>
Thu, 12 Aug 2010 14:30:08 +0000 (15:30 +0100)
committerTimo Sirainen <tss@iki.fi>
Thu, 12 Aug 2010 14:30:08 +0000 (15:30 +0100)
src/imap-login/imap-proxy.c
src/login-common/client-common-auth.c
src/login-common/client-common.h
src/pop3-login/client.h
src/pop3-login/pop3-proxy.c

index 11a47c17bfe3752b2dba7257906f1d95b4808dd7..1bbce623e03e014a11c1ed9b0e777fa6f457c535 100644 (file)
 
 #include <stdlib.h>
 
+enum imap_proxy_state {
+       IMAP_PROXY_STATE_NONE,
+       IMAP_PROXY_STATE_BANNER,
+       IMAP_PROXY_STATE_ID,
+       IMAP_PROXY_STATE_STARTTLS,
+       IMAP_PROXY_STATE_CAPABILITY,
+       IMAP_PROXY_STATE_AUTH_CONTINUE,
+       IMAP_PROXY_STATE_LOGIN
+};
+
 static void proxy_write_id(struct imap_client *client, string_t *str)
 {
        str_printfa(str, "I ID ("
@@ -164,6 +174,7 @@ int imap_proxy_parse_line(struct client *client, const char *line)
        output = login_proxy_get_ostream(client->login_proxy);
        if (!imap_client->proxy_seen_banner) {
                /* this is a banner */
+               client->proxy_state = IMAP_PROXY_STATE_BANNER;
                imap_client->proxy_seen_banner = TRUE;
                if (proxy_input_banner(imap_client, output, line) < 0) {
                        client_proxy_failed(client, TRUE);
@@ -176,6 +187,7 @@ int imap_proxy_parse_line(struct client *client, const char *line)
                        /* used literals with LOGIN command, just ignore. */
                        return 0;
                }
+               client->proxy_state = IMAP_PROXY_STATE_AUTH_CONTINUE;
                imap_client->proxy_wait_auth_continue = FALSE;
 
                str = t_str_new(128);
@@ -195,6 +207,7 @@ int imap_proxy_parse_line(struct client *client, const char *line)
                        return -1;
                }
                /* STARTTLS successful, begin TLS negotiation. */
+               client->proxy_state = IMAP_PROXY_STATE_STARTTLS;
                if (login_proxy_starttls(client->login_proxy) < 0) {
                        client_proxy_failed(client, TRUE);
                        return -1;
@@ -207,6 +220,7 @@ int imap_proxy_parse_line(struct client *client, const char *line)
                return 1;
        } else if (strncmp(line, "L OK ", 5) == 0) {
                /* Login successful. Send this line to client. */
+               client->proxy_state = IMAP_PROXY_STATE_LOGIN;
                str = t_str_new(128);
                client_send_login_reply(imap_client, str, line + 5);
                (void)o_stream_send(client->output,
@@ -258,10 +272,12 @@ int imap_proxy_parse_line(struct client *client, const char *line)
                return 0;
        } else if (strncmp(line, "C ", 2) == 0) {
                /* Reply to CAPABILITY command we sent, ignore it */
+               client->proxy_state = IMAP_PROXY_STATE_CAPABILITY;
                return 0;
        } else if (strncasecmp(line, "I ", 2) == 0 ||
                   strncasecmp(line, "* ID ", 5) == 0) {
                /* Reply to ID command we sent, ignore it */
+               client->proxy_state = IMAP_PROXY_STATE_ID;
                return 0;
        } else if (strncmp(line, "* ", 2) == 0) {
                /* untagged reply. just foward it. */
@@ -283,4 +299,5 @@ void imap_proxy_reset(struct client *client)
        imap_client->proxy_sasl_ir = FALSE;
        imap_client->proxy_seen_banner = FALSE;
        imap_client->proxy_wait_auth_continue = FALSE;
+       client->proxy_state = IMAP_PROXY_STATE_NONE;
 }
index 5bcc87db02f676426d70fd9e1bf2b88ca3a35bcc..258ac782ba6e0515cd8e942d78b7e2ef5aab133c 100644 (file)
@@ -217,10 +217,10 @@ static void proxy_input(struct client *client)
                return;
        case -1:
                client_log_err(client, t_strdup_printf(
-                       "proxy: Remote %s:%u disconnected: %s",
+                       "proxy: Remote %s:%u disconnected: %s (state=%u)",
                        login_proxy_get_host(client->login_proxy),
                        login_proxy_get_port(client->login_proxy),
-                       get_disconnect_reason(input)));
+                       get_disconnect_reason(input), client->proxy_state));
                client_proxy_failed(client, TRUE);
                return;
        }
index 6d12cae746f2a68e164e32d62feef1a008452562..63100c634ad33af99abb7d3797968fa96ea643ab 100644 (file)
@@ -95,6 +95,7 @@ struct client {
 
        struct login_proxy *login_proxy;
        char *proxy_user, *proxy_master_user, *proxy_password;
+       unsigned int proxy_state;
 
        char *auth_mech_name;
        struct auth_client_request *auth_request;
index 6cc2184ec311ab221fd14a32579b4adeb59e933b..d4b2b3c410529bf2114acd4a1cf89daec50fad09 100644 (file)
@@ -15,8 +15,6 @@ enum pop3_proxy_state {
 struct pop3_client {
        struct client common;
 
-       enum pop3_proxy_state proxy_state;
-
        char *last_user;
        char *apop_challenge;
        unsigned int apop_server_pid, apop_connect_uid;
index 178b882f80afd5c49a6832d259902d15857dd4e5..91b5f740c6ff3880b4e7845a3e0e9f3d7fc28e74 100644 (file)
@@ -48,7 +48,7 @@ static void proxy_send_login(struct pop3_client *client, struct ostream *output)
                str_append(str, "AUTH PLAIN\r\n");
        }
        (void)o_stream_send(output, str_data(str), str_len(str));
-       client->proxy_state = POP3_PROXY_LOGIN1;
+       client->common.proxy_state = POP3_PROXY_LOGIN1;
 }
 
 int pop3_proxy_parse_line(struct client *client, const char *line)
@@ -61,7 +61,7 @@ int pop3_proxy_parse_line(struct client *client, const char *line)
        i_assert(!client->destroyed);
 
        output = login_proxy_get_ostream(client->login_proxy);
-       switch (pop3_client->proxy_state) {
+       switch (client->proxy_state) {
        case POP3_PROXY_BANNER:
                /* this is a banner */
                if (strncmp(line, "+OK", 3) != 0) {
@@ -77,7 +77,7 @@ int pop3_proxy_parse_line(struct client *client, const char *line)
                        proxy_send_login(pop3_client, output);
                } else {
                        (void)o_stream_send_str(output, "STLS\r\n");
-                       pop3_client->proxy_state = POP3_PROXY_STARTTLS;
+                       client->proxy_state = POP3_PROXY_STARTTLS;
                }
                return 0;
        case POP3_PROXY_STARTTLS:
@@ -115,7 +115,7 @@ int pop3_proxy_parse_line(struct client *client, const char *line)
                }
                (void)o_stream_send(output, str_data(str), str_len(str));
                proxy_free_password(client);
-               pop3_client->proxy_state = POP3_PROXY_LOGIN2;
+               client->proxy_state = POP3_PROXY_LOGIN2;
                return 0;
        case POP3_PROXY_LOGIN2:
                if (strncmp(line, "+OK", 3) != 0)
@@ -162,7 +162,5 @@ int pop3_proxy_parse_line(struct client *client, const char *line)
 
 void pop3_proxy_reset(struct client *client)
 {
-       struct pop3_client *pop3_client = (struct pop3_client *)client;
-
-       pop3_client->proxy_state = POP3_PROXY_BANNER;
+       client->proxy_state = POP3_PROXY_BANNER;
 }