pop3-proxy.c revision 5a580c3a38ced62d4bcc95b8ac7c4f2935b5d294
5f5870385cff47efd2f58e7892f251cf13761528Timo Sirainen/* Copyright (c) 2004-2013 Dovecot authors, see the included COPYING file */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenstatic void proxy_free_password(struct client *client)
70ead6466f9baa8294e71fc2fba0a4f54f488b5eTimo Sirainen safe_memset(client->proxy_password, 0, strlen(client->proxy_password));
67c47dbb3fde79218320fd38a45c33f61bbf3012Timo Sirainenstatic void get_plain_auth(struct client *client, string_t *dest)
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen base64_encode(str_data(str), str_len(str), dest);
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenstatic void proxy_send_login(struct pop3_client *client, struct ostream *output)
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen /* remote supports XCLIENT, send it */
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen "XCLIENT ADDR=%s PORT=%u SESSION=%s TTL=%u\r\n",
4c892b0d94c5b1d6853dbe8e0b38059ea5b08ecaTimo Sirainen client->common.proxy_state = POP3_PROXY_XCLIENT;
2fb9ae42f9e36388ec6db24188b9108434043fd0Timo Sirainen client->common.proxy_state = POP3_PROXY_LOGIN1;
a8d47e2427558d5011dfc75694b704760c1ef8baTimo Sirainen if (client->common.proxy_master_user == NULL) {
a8d47e2427558d5011dfc75694b704760c1ef8baTimo Sirainen /* send USER command */
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen /* master user login - use AUTH PLAIN. */
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen o_stream_nsend(output, str_data(str), str_len(str));
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainenint pop3_proxy_parse_line(struct client *client, const char *line)
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen struct pop3_client *pop3_client = (struct pop3_client *)client;
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen output = login_proxy_get_ostream(client->login_proxy);
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen /* this is a banner */
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen "proxy: Remote returned invalid banner: %s",
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen ssl_flags = login_proxy_get_ssl_flags(client->login_proxy);
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen if ((ssl_flags & PROXY_SSL_FLAG_STARTTLS) == 0) {
39993536eaef0a23954105e41040dcf88afd2e7eTimo Sirainen "proxy: Remote STLS failed: %s",
39993536eaef0a23954105e41040dcf88afd2e7eTimo Sirainen if (login_proxy_starttls(client->login_proxy) < 0) {
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen /* i/ostreams changed. */
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen output = login_proxy_get_ostream(client->login_proxy);
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen "proxy: Remote XCLIENT failed: %s",
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen /* USER successful, send PASS */
67c47dbb3fde79218320fd38a45c33f61bbf3012Timo Sirainen /* AUTH successful, send the authentication data */
d80f37f025593d959bdfa9c378915e4322f4f504Timo Sirainen o_stream_nsend(output, str_data(str), str_len(str));
e51cfb5506de764499cb5b81a098b23cf46f90f1Timo Sirainen /* Login successful. Send this line to client. */
67c47dbb3fde79218320fd38a45c33f61bbf3012Timo Sirainen /* Login failed. Pass through the error message to client.
a443e5aaf632257bfd1e7aa9b3c42c09512bbe43Timo Sirainen If the backend server isn't Dovecot, the error message may
a443e5aaf632257bfd1e7aa9b3c42c09512bbe43Timo Sirainen be different from Dovecot's "user doesn't exist" error. This
a443e5aaf632257bfd1e7aa9b3c42c09512bbe43Timo Sirainen would allow an attacker to find out what users exist in the
a443e5aaf632257bfd1e7aa9b3c42c09512bbe43Timo Sirainen The optimal way to handle this would be to replace the
a443e5aaf632257bfd1e7aa9b3c42c09512bbe43Timo Sirainen backend's "password failed" error message with Dovecot's
a443e5aaf632257bfd1e7aa9b3c42c09512bbe43Timo Sirainen AUTH_FAILED_MSG, but this would require a new setting and
a443e5aaf632257bfd1e7aa9b3c42c09512bbe43Timo Sirainen the sysadmin to actually bother setting it properly.
13b063ba3ea51256fd97d7fa883f14cb08842b0dTimo Sirainen So for now we'll just forward the error message. This
13b063ba3ea51256fd97d7fa883f14cb08842b0dTimo Sirainen shouldn't be a real problem since of course everyone will
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen be using only Dovecot as their backend :) */
013a8a91c83c6ea24bc75322b81235f19e26fa8fTimo Sirainen client_send_reply(client, POP3_CMD_REPLY_ERROR,
d1fff80640050631b06bfab904a34b2ad24601e8Timo Sirainen client_send_raw(client, t_strconcat(line, "\r\n", NULL));
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainenvoid pop3_proxy_error(struct client *client, const char *text)