pop3-proxy.c revision d77f679dac93f2416d6b04299b1a8154941036dd
/* Copyright (c) 2004-2017 Dovecot authors, see the included COPYING file */
#include "login-common.h"
#include "ioloop.h"
#include "istream.h"
#include "ostream.h"
#include "base64.h"
#include "safe-memset.h"
#include "str.h"
#include "str-sanitize.h"
#include "dsasl-client.h"
#include "client.h"
#include "pop3-proxy.h"
static const char *pop3_proxy_state_names[POP3_PROXY_STATE_COUNT] = {
"banner", "starttls", "xclient", "login1", "login2"
};
{
return;
}
{
struct dsasl_client_settings sasl_set;
const unsigned char *sasl_output;
if (client->proxy_xclient &&
/* remote supports XCLIENT, send it */
"XCLIENT ADDR=%s PORT=%u SESSION=%s TTL=%u\r\n",
} else {
}
/* send USER command */
return 0;
}
"proxy: SASL mechanism %s init failed: %s",
return -1;
}
if (len == 0)
else
return 0;
}
static int
const char *line)
{
const unsigned char *data;
const char *error;
int ret;
return -1;
}
if (ret == 0) {
}
if (ret < 0) {
"proxy: Server sent invalid authentication data: %s",
error));
return -1;
}
str_truncate(str, 0);
return 0;
}
{
switch (client->proxy_state) {
case POP3_PROXY_BANNER:
/* this is a banner */
"proxy: Remote returned invalid banner: %s",
return -1;
}
if ((ssl_flags & PROXY_SSL_FLAG_STARTTLS) == 0) {
return -1;
}
} else {
}
return 0;
case POP3_PROXY_STARTTLS:
"proxy: Remote STLS failed: %s",
return -1;
}
return -1;
}
return -1;
}
return 1;
case POP3_PROXY_XCLIENT:
"proxy: Remote XCLIENT failed: %s",
return -1;
}
return 0;
case POP3_PROXY_LOGIN1:
break;
/* USER successful, send PASS */
return 0;
case POP3_PROXY_LOGIN2:
/* continue SASL authentication */
line+2) < 0) {
return -1;
}
return 0;
}
break;
/* Login successful. Send this line to client. */
return 1;
case POP3_PROXY_STATE_COUNT:
i_unreached();
}
/* Login failed. Pass through the error message to client.
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 :) */
} else {
}
line += 5;
}
return -1;
}
{
}
{
}
{
}