pop3-proxy.c revision 01cd9d4a8050a1dbf1da2c830f9755a45d6d004a
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen/* Copyright (c) 2004-2012 Dovecot authors, see the included COPYING file */
7e235b3a5f622813121cd18f351e036650aaf8f8Timo Sirainenstatic void proxy_free_password(struct client *client)
fadd878cd6098f5b873c21c121209a922679dae4Timo Sirainen safe_memset(client->proxy_password, 0, strlen(client->proxy_password));
471e447023ab73a73f0f78da2afc0c55905330ddTimo Sirainenstatic void get_plain_auth(struct client *client, string_t *dest)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen base64_encode(str_data(str), str_len(str), dest);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic void proxy_send_login(struct pop3_client *client, struct ostream *output)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* remote supports XCLIENT, send it */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen (void)o_stream_send_str(output, t_strdup_printf(
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen "XCLIENT ADDR=%s PORT=%u\r\n",
52d2b356e3ddb4e59ee09c10d47add9d3280284bAki Tuomi /* send USER command */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* master user login - use AUTH PLAIN. */
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen (void)o_stream_send(output, str_data(str), str_len(str));
44ff75ca53188056ff5a3e50428e3f2078800b3cTimo Sirainen client->common.proxy_state = POP3_PROXY_LOGIN1;
51795bfe9d05d92fe942cb451aec2b9d16d32a11Timo Sirainenint pop3_proxy_parse_line(struct client *client, const char *line)
51795bfe9d05d92fe942cb451aec2b9d16d32a11Timo Sirainen struct pop3_client *pop3_client = (struct pop3_client *)client;
44ff75ca53188056ff5a3e50428e3f2078800b3cTimo Sirainen output = login_proxy_get_ostream(client->login_proxy);
8872e5c991430f96138a46e36b7f3c2c40d8e5c2Timo Sirainen /* this is a banner */
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen "proxy: Remote returned invalid banner: %s",
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen ssl_flags = login_proxy_get_ssl_flags(client->login_proxy);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if ((ssl_flags & PROXY_SSL_FLAG_STARTTLS) == 0) {
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen "proxy: Remote STLS failed: %s",
b780aa272b742a43579cdb523cc79cc8d4521306Timo Sirainen if (login_proxy_starttls(client->login_proxy) < 0) {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* i/ostreams changed. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen output = login_proxy_get_ostream(client->login_proxy);
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainen /* USER successful, send PASS */
c0d1bfc45e224251cb549de8d8804861e8acb517Timo Sirainen /* AUTH successful, send the authentication data */
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen (void)o_stream_send(output, str_data(str), str_len(str));
2e99f3f3bb35715ce5e0a75a2f2a9bac3ab4224bTimo Sirainen /* Login successful. Send this line to client. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen (void)o_stream_send_str(client->output, line);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* Login failed. Pass through the error message to client.
ae8817f05005f57bba32479a610b52d083e2b6ebTimo Sirainen If the backend server isn't Dovecot, the error message may
6ded8819b9002150a95a7615e4f64f091c250464Timo Sirainen be different from Dovecot's "user doesn't exist" error. This
6ded8819b9002150a95a7615e4f64f091c250464Timo Sirainen would allow an attacker to find out what users exist in the
b87a4156eca6dcf6b29c504eb0cb9be2fdb11b63Timo Sirainen The optimal way to handle this would be to replace the
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen backend's "password failed" error message with Dovecot's
92dab926b2f2270057b40a907a00cf8eb2309ed6Timo Sirainen AUTH_FAILED_MSG, but this would require a new setting and
92dab926b2f2270057b40a907a00cf8eb2309ed6Timo Sirainen the sysadmin to actually bother setting it properly.
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen So for now we'll just forward the error message. This
a0c8af555ec481ab12c2a99518cf7b20debd1627Timo Sirainen shouldn't be a real problem since of course everyone will
a0c8af555ec481ab12c2a99518cf7b20debd1627Timo Sirainen be using only Dovecot as their backend :) */
95a1a5195d56f3cf5d1e529aad668f87ad3b979bTimo Sirainen client_send_reply(client, POP3_CMD_REPLY_ERROR,