pop3-proxy.c revision 9f627b360ed38fdc54cb02ec5e67246c3f0d5b0f
5f5870385cff47efd2f58e7892f251cf13761528Timo Sirainen/* Copyright (c) 2004-2012 Dovecot authors, see the included COPYING file */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenstatic void proxy_free_password(struct client *client)
8372fc7efb6d64dff2e5f55fb4a3822c56869cfeTimo Sirainen safe_memset(client->proxy_password, 0, strlen(client->proxy_password));
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenstatic void get_plain_auth(struct client *client, string_t *dest)
ccef83820a01bb37ad48653a05a9c5aa6560826aTimo Sirainen base64_encode(str_data(str), str_len(str), dest);
e95dba8921087afebb8a92c592af3b8ca22ae796Timo Sirainenstatic void proxy_send_login(struct pop3_client *client, struct ostream *output)
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen if (client->common.proxy_master_user == NULL) {
e95dba8921087afebb8a92c592af3b8ca22ae796Timo Sirainen /* send USER command */
e95dba8921087afebb8a92c592af3b8ca22ae796Timo Sirainen /* master user login - use AUTH PLAIN. */
e95dba8921087afebb8a92c592af3b8ca22ae796Timo Sirainen (void)o_stream_send(output, str_data(str), str_len(str));
3612ee5c737954d5fb88fd1775aad80f7bf1dc4eTimo Sirainen client->common.proxy_state = POP3_PROXY_LOGIN1;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainenint pop3_proxy_parse_line(struct client *client, const char *line)
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen struct pop3_client *pop3_client = (struct pop3_client *)client;
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen output = login_proxy_get_ostream(client->login_proxy);
f30577ff7cf29858f1878abe963b4f40a436434fTimo Sirainen /* this is a banner */
45155bb1250cf5a120278f349465aded513a100fTimo Sirainen "proxy: Remote returned invalid banner: %s",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen ssl_flags = login_proxy_get_ssl_flags(client->login_proxy);
e95dba8921087afebb8a92c592af3b8ca22ae796Timo Sirainen if ((ssl_flags & PROXY_SSL_FLAG_STARTTLS) == 0) {
e95dba8921087afebb8a92c592af3b8ca22ae796Timo Sirainen "proxy: Remote STLS failed: %s",
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen if (login_proxy_starttls(client->login_proxy) < 0) {
e95dba8921087afebb8a92c592af3b8ca22ae796Timo Sirainen /* i/ostreams changed. */
e248fe370c4047cee921a91b48edc37944ab0526Timo Sirainen output = login_proxy_get_ostream(client->login_proxy);
ccef83820a01bb37ad48653a05a9c5aa6560826aTimo Sirainen /* USER successful, send PASS */
ccef83820a01bb37ad48653a05a9c5aa6560826aTimo Sirainen /* AUTH successful, send the authentication data */
8372fc7efb6d64dff2e5f55fb4a3822c56869cfeTimo Sirainen (void)o_stream_send(output, str_data(str), str_len(str));
ab1236617440e654d5c5a043b677512714b788ddTimo Sirainen /* Login successful. Send this line to client. */
ab1236617440e654d5c5a043b677512714b788ddTimo Sirainen (void)o_stream_send_str(client->output, line);
e3a838c80f54f024115fade93c6c87a0998f1fabTimo Sirainen /* Login failed. Pass through the error message to client.
e3a838c80f54f024115fade93c6c87a0998f1fabTimo Sirainen If the backend server isn't Dovecot, the error message may
e3a838c80f54f024115fade93c6c87a0998f1fabTimo Sirainen be different from Dovecot's "user doesn't exist" error. This
e3a838c80f54f024115fade93c6c87a0998f1fabTimo Sirainen would allow an attacker to find out what users exist in the
e3a838c80f54f024115fade93c6c87a0998f1fabTimo Sirainen The optimal way to handle this would be to replace the
e3a838c80f54f024115fade93c6c87a0998f1fabTimo Sirainen backend's "password failed" error message with Dovecot's
e3a838c80f54f024115fade93c6c87a0998f1fabTimo Sirainen AUTH_FAILED_MSG, but this would require a new setting and
e3a838c80f54f024115fade93c6c87a0998f1fabTimo Sirainen the sysadmin to actually bother setting it properly.
e3a838c80f54f024115fade93c6c87a0998f1fabTimo Sirainen So for now we'll just forward the error message. This
e3a838c80f54f024115fade93c6c87a0998f1fabTimo Sirainen shouldn't be a real problem since of course everyone will
e3a838c80f54f024115fade93c6c87a0998f1fabTimo Sirainen be using only Dovecot as their backend :) */
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainen client_send_reply(client, POP3_CMD_REPLY_ERROR,
00fa8dcbc66f56daa737487c9dec7166c37de79eTimo Sirainen client_send_raw(client, t_strconcat(line, "\r\n", NULL));
9f627b360ed38fdc54cb02ec5e67246c3f0d5b0fTimo Sirainenvoid pop3_proxy_error(struct client *client, const char *text)