pop3-proxy.c revision 4b6ddd3770c8484da7308032b75fc93b91aa1b49
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch/* Copyright (c) 2004-2008 Dovecot authors, see the included COPYING file */
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainenstatic void proxy_input(struct istream *input, struct ostream *output,
4c9294fcb17fb12326ff5db29e2f882cf4bd7fedTimo Sirainen /* remote authentication failed, we're just
4c9294fcb17fb12326ff5db29e2f882cf4bd7fedTimo Sirainen freeing the proxy */
4c9294fcb17fb12326ff5db29e2f882cf4bd7fedTimo Sirainen /* we came here from client_destroy() */
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen /* failed for some reason, probably server disconnected */
18a2214eedb08d043277cf1d3e75c45762014663Timo Sirainen "-ERR [IN-USE] Temporary login failure.");
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen /* buffer full */
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen "proxy: Remote input buffer full");
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen /* disconnected */
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen client_destroy(client, "Proxy: Remote disconnected");
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen /* this is a banner */
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen client_syslog(&client->common, t_strdup_printf(
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen "proxy: Remote returned invalid banner: %s",
58a770f1e0ab553a0dba9cad9d6f3a6cdf2dc855Timo Sirainen /* send USER command */
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen (void)o_stream_send(output, str_data(str), str_len(str));
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen /* USER successful, send PASS */
18a2214eedb08d043277cf1d3e75c45762014663Timo Sirainen /* Login successful. Send this line to client. */
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen (void)o_stream_send_str(client->output, line);
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen (void)o_stream_send(client->output, "\r\n", 2);
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen msg = t_strdup_printf("proxy(%s): started proxying to %s:%u",
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen login_proxy_detach(client->proxy, client->input,
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen /* Login failed. Pass through the error message to client
6b8f4863bb2b0938d40f774122baf6528a833ea0Timo Sirainen (see imap-proxy code for potential problems with this) */
f55b07916c82db8b915b28252e44ce6fb2bd3080Timo Sirainen client_send_line(client, "-ERR "AUTH_FAILED_MSG);
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen /* allow client input again */
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen client->io = io_add(client->common.fd, IO_READ,
18a2214eedb08d043277cf1d3e75c45762014663Timo Sirainenint pop3_proxy_new(struct pop3_client *client, const char *host,
18a2214eedb08d043277cf1d3e75c45762014663Timo Sirainen unsigned int port, const char *user, const char *password)
a8ebb72c0fba1a6a71104e530bf5903d5f149351Timo Sirainen client_syslog(&client->common, "proxy: password not given");
f55b07916c82db8b915b28252e44ce6fb2bd3080Timo Sirainen /* connection_queue_add() decided that we were the oldest
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen connection and killed us. */
39025a2dabfcfaeee3790988b9ea00d19887a3d3Timo Sirainen client->proxy = login_proxy_new(&client->common, host, port,
f55b07916c82db8b915b28252e44ce6fb2bd3080Timo Sirainen /* disable input until authentication is finished */