pop3-proxy.c revision ad9da7356677de3b1176bbed0ec8a04e7a33ea03
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik/* Copyright (c) 2004-2012 Dovecot authors, see the included COPYING file */
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnikstatic void proxy_free_password(struct client *client)
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik safe_memset(client->proxy_password, 0, strlen(client->proxy_password));
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnikstatic void get_plain_auth(struct client *client, string_t *dest)
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik base64_encode(str_data(str), str_len(str), dest);
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnikstatic void proxy_send_login(struct pop3_client *client, struct ostream *output)
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik /* remote supports XCLIENT, send it */
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik (void)o_stream_send_str(output, t_strdup_printf(
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik "XCLIENT ADDR=%s PORT=%u\r\n",
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik if (client->common.proxy_master_user == NULL) {
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik /* send USER command */
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik /* master user login - use AUTH PLAIN. */
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik (void)o_stream_send(output, str_data(str), str_len(str));
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik client->common.proxy_state = POP3_PROXY_LOGIN1;
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnikint pop3_proxy_parse_line(struct client *client, const char *line)
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik struct pop3_client *pop3_client = (struct pop3_client *)client;
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik output = login_proxy_get_ostream(client->login_proxy);
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik /* this is a banner */
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik "proxy: Remote returned invalid banner: %s",
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik ssl_flags = login_proxy_get_ssl_flags(client->login_proxy);
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik if ((ssl_flags & PROXY_SSL_FLAG_STARTTLS) == 0) {
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik (void)o_stream_send_str(output, "STLS\r\n");
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik "proxy: Remote STLS failed: %s",
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik if (login_proxy_starttls(client->login_proxy) < 0) {
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik /* i/ostreams changed. */
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik output = login_proxy_get_ostream(client->login_proxy);
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik /* USER successful, send PASS */
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik /* AUTH successful, send the authentication data */
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik (void)o_stream_send(output, str_data(str), str_len(str));
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik /* Login successful. Send this line to client. */
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik (void)o_stream_send_str(client->output, line);
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik /* Login failed. Pass through the error message to client.
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik If the backend server isn't Dovecot, the error message may
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik be different from Dovecot's "user doesn't exist" error. This
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik would allow an attacker to find out what users exist in the
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik The optimal way to handle this would be to replace the
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik backend's "password failed" error message with Dovecot's
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik AUTH_FAILED_MSG, but this would require a new setting and
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik the sysadmin to actually bother setting it properly.
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik So for now we'll just forward the error message. This
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik shouldn't be a real problem since of course everyone will
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik be using only Dovecot as their backend :) */
49a5412cbc98e630de17359c29cb8d6ce0e16168Lukas Slebodnik client_send_line(client, CLIENT_CMD_REPLY_AUTH_FAILED,