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