pop3-proxy.c revision e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4
5f5870385cff47efd2f58e7892f251cf13761528Timo Sirainen/* Copyright (c) 2004-2012 Dovecot authors, see the included COPYING file */
06ff2a72c39cb34cc6425f17fc82c5e93fef2018Timo Sirainenstatic void proxy_free_password(struct client *client)
de76b960297406115cf6bae473f004c08174b16aTimo Sirainen safe_memset(client->proxy_password, 0, strlen(client->proxy_password));
61530b48694398df42744204e35535dbe3f745c4Timo Sirainenstatic void get_plain_auth(struct client *client, string_t *dest)
6789ed17e7ca4021713507baf0dcf6979bb42e0cTimo Sirainen base64_encode(str_data(str), str_len(str), dest);
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainenstatic void proxy_send_login(struct pop3_client *client, struct ostream *output)
fde0b1793a2842da00eaa105d5e13fec465f0443Timo Sirainen /* remote supports XCLIENT, send it */
d244c6cadd5f077f5d0f1e00c3652d0108a2d908Timo Sirainen "XCLIENT ADDR=%s PORT=%u SESSION=%s TTL=%u\r\n",
fde0b1793a2842da00eaa105d5e13fec465f0443Timo Sirainen client->common.proxy_state = POP3_PROXY_XCLIENT;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen client->common.proxy_state = POP3_PROXY_LOGIN1;
fde0b1793a2842da00eaa105d5e13fec465f0443Timo Sirainen if (client->common.proxy_master_user == NULL) {
fde0b1793a2842da00eaa105d5e13fec465f0443Timo Sirainen /* send USER command */
baf1148108b7d9739626b47cc57298c36929586aTimo Sirainen /* master user login - use AUTH PLAIN. */
e82e363e7a6917f470412d629db6c5b1f5891a35Timo Sirainen o_stream_nsend(output, str_data(str), str_len(str));
d6c5ceea8521b92d10e51a59da00c792f6140b1dTimo Sirainenint pop3_proxy_parse_line(struct client *client, const char *line)
d6c5ceea8521b92d10e51a59da00c792f6140b1dTimo Sirainen struct pop3_client *pop3_client = (struct pop3_client *)client;
e82e363e7a6917f470412d629db6c5b1f5891a35Timo Sirainen output = login_proxy_get_ostream(client->login_proxy);
d6c5ceea8521b92d10e51a59da00c792f6140b1dTimo Sirainen /* this is a banner */
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen "proxy: Remote returned invalid banner: %s",
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen ssl_flags = login_proxy_get_ssl_flags(client->login_proxy);
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen if ((ssl_flags & PROXY_SSL_FLAG_STARTTLS) == 0) {
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen "proxy: Remote STLS failed: %s",
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen if (login_proxy_starttls(client->login_proxy) < 0) {
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen /* i/ostreams changed. */
51cbc45fc1ac5dde29bc2adbb175945df1b4f7d4Timo Sirainen output = login_proxy_get_ostream(client->login_proxy);
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen "proxy: Remote XCLIENT failed: %s",
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen /* USER successful, send PASS */
88ea893b45d3ed8d68000921db9156c03cbe1b00Timo Sirainen /* AUTH successful, send the authentication data */
d10a370b2614712d9cb6a1dd8625f62a071b6377Timo Sirainen o_stream_nsend(output, str_data(str), str_len(str));
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen /* Login successful. Send this line to client. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Login failed. Pass through the error message to client.
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen If the backend server isn't Dovecot, the error message may
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen be different from Dovecot's "user doesn't exist" error. This
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen would allow an attacker to find out what users exist in the
e82e363e7a6917f470412d629db6c5b1f5891a35Timo Sirainen The optimal way to handle this would be to replace the
e82e363e7a6917f470412d629db6c5b1f5891a35Timo Sirainen backend's "password failed" error message with Dovecot's
2767104d81e97a109f0aa9758792bfa1da325a97Timo Sirainen AUTH_FAILED_MSG, but this would require a new setting and
d6c5ceea8521b92d10e51a59da00c792f6140b1dTimo Sirainen the sysadmin to actually bother setting it properly.
88ea893b45d3ed8d68000921db9156c03cbe1b00Timo Sirainen So for now we'll just forward the error message. This
d6c5ceea8521b92d10e51a59da00c792f6140b1dTimo Sirainen shouldn't be a real problem since of course everyone will
d6c5ceea8521b92d10e51a59da00c792f6140b1dTimo Sirainen be using only Dovecot as their backend :) */
88ea893b45d3ed8d68000921db9156c03cbe1b00Timo Sirainen client_send_reply(client, POP3_CMD_REPLY_ERROR,
923eb3dde28e4d8841c14fd6b4a69635b7070c3eTimo Sirainen client_send_raw(client, t_strconcat(line, "\r\n", NULL));
905951e448e0d0f0778f43ce7673d0cac60b9b61Timo Sirainenvoid pop3_proxy_error(struct client *client, const char *text)