imap-proxy.c revision 45312f52ff3a3d4c137447be4c7556500c2f8bf2
/* Copyright (c) 2004-2009 Dovecot authors, see the included COPYING file */
#include "common.h"
#include "ioloop.h"
#include "istream.h"
#include "ostream.h"
#include "base64.h"
#include "str.h"
#include "str-sanitize.h"
#include "safe-memset.h"
#include "client.h"
#include "imap-resp-code.h"
#include "imap-quote.h"
#include "imap-proxy.h"
#define PROXY_FAILURE_MSG \
{
return FALSE;
line += 12;
/* skip over the capability */
while (*line != ' ') {
if (*line == '\0')
return FALSE;
line++;
}
line++;
}
return TRUE;
}
{
"\"x-originating-ip\" \"%s\" "
"\"x-originating-port\" \"%u\" "
"\"x-connected-ip\" \"%s\" "
"\"x-connected-port\" \"%u\")\r\n",
}
{
return;
}
{
if (send_tagline)
/* call this last - it may destroy the client */
}
{
}
{
"proxy: Remote returned invalid banner: %s",
return -1;
}
/* logging in normally - use LOGIN command */
/* master user login with SASL initial response support */
} else {
/* master user login without SASL initial response */
}
return 0;
}
{
if (!client->proxy_login_sent) {
/* this is a banner */
return -1;
}
return 0;
} else if (*line == '+') {
/* AUTHENTICATE started. finish it. */
return 0;
/* Login successful. Send this line to client. */
str_truncate(str, 0);
client->proxy_user) != 0) {
/* remote username is different, log it */
}
}
(void)client_skip_line(client);
return -1;
/* If the backend server isn't Dovecot, the error message may
be different from Dovecot's "user doesn't exist" error. This
would allow an attacker to find out what users exist in the
system.
The optimal way to handle this would be to replace the
backend's "password failed" error message with Dovecot's
AUTH_FAILED_MSG, but this would require a new setting and
the sysadmin to actually bother setting it properly.
So for now we'll just forward the error message. This
shouldn't be a real problem since of course everyone will
be using only Dovecot as their backend :) */
if (verbose_auth) {
client->proxy_user) != 0) {
/* remote username is different, log it */
}
}
else
}
return -1;
} else {
/* probably some untagged reply */
return 0;
}
}
struct imap_client *client)
{
const char *line;
/* we're just freeing the proxy */
return;
}
/* we came here from client_destroy() */
return;
}
/* failed for some reason, probably server disconnected */
return;
}
switch (i_stream_read(input)) {
case -2:
"proxy: Remote input buffer full");
return;
case -1:
"proxy: Remote disconnected");
return;
}
break;
}
}
const char *password)
{
return -1;
}
/* connection_queue_add() decided that we were the oldest
connection and killed us. */
return -1;
}
return -1;
}
return -1;
}
/* disable input until authentication is finished */
return 0;
}