submission-proxy.c revision 4a1af46c8ed806fbc51bedfaf79c019b0afa3aa6
/* Copyright (c) 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 "strescape.h"
#include "dsasl-client.h"
#include "client.h"
#include "submission-login-settings.h"
#include "submission-proxy.h"
#include <ctype.h>
static const char *submission_proxy_state_names[SUBMISSION_PROXY_STATE_COUNT] = {
"banner", "ehlo", "starttls", "tls-ehlo", "xclient", "authenticate"
};
{
return;
}
static void
{
const char *const *arg;
return;
/* remote supports XCLIENT, send it */
}
}
}
}
}
}
static int
{
struct dsasl_client_settings sasl_set;
const unsigned char *sasl_output;
/* Prevent sending credentials to a server that has login disabled;
i.e., due to the lack of TLS */
"Server has disabled authentication (TLS required?)");
return -1;
}
"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;
"proxy: Server sent invalid base64 data in AUTH response");
return -1;
}
if (ret == 0) {
}
if (ret < 0) {
"proxy: Server sent invalid authentication data: %s",
error));
return -1;
}
str_truncate(str, 0);
return 0;
}
static const char *
{
const char *p = text;
unsigned int digits;
*enh_code_r = NULL;
if (*p != '2' && *p != '4' && *p != '5')
return text;
p++;
if (*p != '.')
return text;
p++;
digits = 0;
p++;
digits++;
}
if (*p != '.')
return text;
p++;
digits = 0;
p++;
digits++;
}
if (*p != ' ')
return text;
p++;
return p;
}
static void
{
struct submission_client *subm_client =
}
{
struct submission_client *subm_client =
(struct submission_client *)client;
unsigned int status = 0;
invalid_line = TRUE;
} else {
text++;
}
if (subm_client->proxy_reply_status != 0 &&
"proxy: Remote returned inconsistent SMTP reply: %s "
return -1;
}
} else {
}
if ((subm_client->proxy_capability &
switch (subm_client->proxy_state) {
case SUBMISSION_PROXY_BANNER:
/* this is a banner */
"proxy: Remote returned invalid banner: %s",
return -1;
}
if (!last_line)
return 0;
return 0;
case SUBMISSION_PROXY_EHLO:
"proxy: Remote returned invalid EHLO line: %s",
return -1;
}
}
if (!last_line)
return 0;
return -1;
}
return 0;
}
if ((ssl_flags & PROXY_SSL_FLAG_STARTTLS) == 0) {
return -1;
}
} else {
if ((subm_client->proxy_capability &
SMTP_CAPABILITY_STARTTLS) == 0) {
"proxy: Remote doesn't support STARTTLS");
return -1;
}
}
return 0;
"proxy: Remote STARTTLS failed: %s",
return -1;
}
if (!last_line)
return 0;
return -1;
}
subm_client->proxy_capability = 0;
return 0;
case SUBMISSION_PROXY_XCLIENT:
"proxy: Remote XCLIENT failed: %s",
return -1;
}
if (!last_line)
return 0;
return 0;
if (invalid_line)
break;
/* continue SASL authentication */
text) < 0) {
return -1;
}
return 0;
}
}
if (!last_line)
return 0;
break;
/* Login successful. Send this reply to client. */
return 1;
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 {
}
}
return -1;
}
{
struct submission_client *subm_client =
(struct submission_client *)client;
subm_client->proxy_capability = 0;
}
{
struct submission_client *subm_client =
(struct submission_client *)client;
}
}
{
struct submission_client *subm_client =
(struct submission_client *)client;
}