From: Timo Sirainen Date: Thu, 12 Aug 2010 14:30:08 +0000 (+0100) Subject: login proxy: Show proxy state in "disconnected" error message. X-Git-Tag: 2.0.rc6~14 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3612ee5c737954d5fb88fd1775aad80f7bf1dc4e;p=thirdparty%2Fdovecot%2Fcore.git login proxy: Show proxy state in "disconnected" error message. --- diff --git a/src/imap-login/imap-proxy.c b/src/imap-login/imap-proxy.c index 11a47c17bf..1bbce623e0 100644 --- a/src/imap-login/imap-proxy.c +++ b/src/imap-login/imap-proxy.c @@ -17,6 +17,16 @@ #include +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; } diff --git a/src/login-common/client-common-auth.c b/src/login-common/client-common-auth.c index 5bcc87db02..258ac782ba 100644 --- a/src/login-common/client-common-auth.c +++ b/src/login-common/client-common-auth.c @@ -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; } diff --git a/src/login-common/client-common.h b/src/login-common/client-common.h index 6d12cae746..63100c634a 100644 --- a/src/login-common/client-common.h +++ b/src/login-common/client-common.h @@ -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; diff --git a/src/pop3-login/client.h b/src/pop3-login/client.h index 6cc2184ec3..d4b2b3c410 100644 --- a/src/pop3-login/client.h +++ b/src/pop3-login/client.h @@ -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; diff --git a/src/pop3-login/pop3-proxy.c b/src/pop3-login/pop3-proxy.c index 178b882f80..91b5f740c6 100644 --- a/src/pop3-login/pop3-proxy.c +++ b/src/pop3-login/pop3-proxy.c @@ -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; }