pop3-proxy.c revision 80980955bb1bbcc1bd73623fe0912f334194ddd2
5f5870385cff47efd2f58e7892f251cf13761528Timo Sirainen/* Copyright (c) 2004-2011 Dovecot authors, see the included COPYING file */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenstatic void proxy_free_password(struct client *client)
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen safe_memset(client->proxy_password, 0, strlen(client->proxy_password));
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainenstatic void get_plain_auth(struct client *client, string_t *dest)
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen base64_encode(str_data(str), str_len(str), dest);
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainenstatic void proxy_send_login(struct pop3_client *client, struct ostream *output)
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen if (client->common.proxy_master_user == NULL) {
4462bd7b4c7ef3de006f060e155a90e5de7cae21Timo Sirainen /* send USER command */
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen /* master user login - use AUTH PLAIN. */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen (void)o_stream_send(output, str_data(str), str_len(str));
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen client->common.proxy_state = POP3_PROXY_LOGIN1;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainenint pop3_proxy_parse_line(struct client *client, const char *line)
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen struct pop3_client *pop3_client = (struct pop3_client *)client;
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen output = login_proxy_get_ostream(client->login_proxy);
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen /* this is a banner */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen "proxy: Remote returned invalid banner: %s",
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen ssl_flags = login_proxy_get_ssl_flags(client->login_proxy);
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen if ((ssl_flags & PROXY_SSL_FLAG_STARTTLS) == 0) {
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen "proxy: Remote STLS failed: %s",
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen if (login_proxy_starttls(client->login_proxy) < 0) {
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainen /* i/ostreams changed. */
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainen output = login_proxy_get_ostream(client->login_proxy);
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainen /* USER successful, send PASS */
bbd4c4cf902539c25c471157eb9849459734759cTimo Sirainen /* AUTH successful, send the authentication data */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen (void)o_stream_send(output, str_data(str), str_len(str));
e376e08040b5f21ff79a15ae728d2532a34207f6Timo Sirainen /* Login successful. Send this line to client. */
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen (void)o_stream_send_str(client->output, line);
fd35227c47190afc832579ca5c76524792701bf7Timo Sirainen /* Login failed. Pass through the error message to client.
fd35227c47190afc832579ca5c76524792701bf7Timo Sirainen If the backend server isn't Dovecot, the error message may
fd35227c47190afc832579ca5c76524792701bf7Timo Sirainen be different from Dovecot's "user doesn't exist" error. This
2e263a9d901483a902720a30c474761bd3324fe8Timo Sirainen would allow an attacker to find out what users exist in the
2e263a9d901483a902720a30c474761bd3324fe8Timo Sirainen The optimal way to handle this would be to replace the
2e263a9d901483a902720a30c474761bd3324fe8Timo Sirainen backend's "password failed" error message with Dovecot's
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainen AUTH_FAILED_MSG, but this would require a new setting and
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen the sysadmin to actually bother setting it properly.
96308127e006bb3b1108093bcf4cc1fd9481cb7aTimo Sirainen So for now we'll just forward the error message. This
eddd9bf1a1369aea4a2715f6be1137da6d17d293Timo Sirainen shouldn't be a real problem since of course everyone will
cf7164ece50797a67fc4bfb5889022ac93a36a8aTimo Sirainen be using only Dovecot as their backend :) */
d66be2bebfa96e7d3d20e2153f60e6e25dcc9a18Timo Sirainen client_send_line(client, CLIENT_CMD_REPLY_AUTH_FAILED,