pop3-proxy.c revision 6e8ad595d0603295f57bef576da8a3a00b55c5e2
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen/* Copyright (c) 2004-2008 Dovecot authors, see the included COPYING file */
573f0491a5733fe21fa062a455acb4790b4e0499Timo Sirainenstatic void proxy_input(struct istream *input, struct ostream *output,
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen /* remote authentication failed, we're just
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen freeing the proxy */
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen /* we came here from client_destroy() */
563273bdac80393af63b9520cbf4d24cc0efd028Timo Sirainen /* failed for some reason, probably server disconnected */
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen "-ERR [IN-USE] Temporary login failure.");
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen /* buffer full */
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen "proxy: Remote input buffer full");
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen /* disconnected */
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen client_destroy_success(client, "Proxy: Remote disconnected");
57a8c6a95e4bce3eeaba36985adb81c07dd683ffTimo Sirainen /* this is a banner */
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen client_syslog(&client->common, t_strdup_printf(
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen "proxy: Remote returned invalid banner: %s",
563273bdac80393af63b9520cbf4d24cc0efd028Timo Sirainen /* send USER command */
f1743785713e7632459d623d5df2108f4b93accbTimo Sirainen (void)o_stream_send(output, str_data(str), str_len(str));
c5ab90cfad9cc3e33bcb1baeb30ffc82a7b7053aTimo Sirainen /* USER successful, send PASS */
88187ee880b4829443e0d55ea7d145d9d5880217Timo Sirainen /* Login successful. Send this line to client. */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen (void)o_stream_send_str(client->output, line);
d3442384ca53d4b18a493db7dd0b000f470419cfTimo Sirainen str_printfa(str, "proxy(%s): started proxying to %s:%u",
d3442384ca53d4b18a493db7dd0b000f470419cfTimo Sirainen /* remote username is different, log it */
c979eeda1f46483d9c963e265786b701d7683d77Timo Sirainen login_proxy_detach(client->proxy, client->common.input,
f81f4bc282cd1944cec187bae89c0701a416ed2aTimo Sirainen /* Login failed. Pass through the error message to client
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen (see imap-proxy code for potential problems with this) */
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen client_send_line(client, "-ERR "AUTH_FAILED_MSG);
48270badadd82279bfe50ae3d187aea8b0b2b30eTimo Sirainen str_printfa(str, "proxy(%s): Login failed to %s:%u",
cb05ecbd96ddb5e53c1850d27434541138a3f284Timo Sirainen /* remote username is different, log it */
408e5be344c9131fdebe771718a5bf49f88cc51cTimo Sirainen /* allow client input again */
0c909e3461607eadcd66f4eac69b7f34e37fccf1Timo Sirainen client->io = io_add(client->common.fd, IO_READ,
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainenint pop3_proxy_new(struct pop3_client *client, const char *host,
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen unsigned int port, const char *user, const char *password)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen client_syslog(&client->common, "proxy: password not given");
bd1b2615928a1e8be190cb0405754f0aec8cac2fTimo Sirainen /* connection_queue_add() decided that we were the oldest
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen connection and killed us. */
a423d985ba7261661475811c22b21b80ec765a71Timo Sirainen client->proxy = login_proxy_new(&client->common, host, port,
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen /* disable input until authentication is finished */