/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "istream.h"
#include "smtp-syntax.h"
#include "smtp-command-parser.h"
#include "smtp-server-private.h"
/* AUTH command (RFC 4954) */
static bool
{
/* RFC 4954, Section 4:
After an AUTH command has been successfully completed, no more
AUTH commands may be issued in the same session. After a
successful AUTH command completes, a server MUST reject any
further AUTH commands with a 503 reply. */
if (conn->authenticated) {
503, "5.5.0", "Already authenticated");
return FALSE;
}
/* RFC 4954, Section 4:
The AUTH command is not permitted during a mail transaction.
An AUTH command issued during a mail transaction MUST be
rejected with a 503 reply. */
"Authentication not permitted during a mail transaction");
return FALSE;
}
return TRUE;
}
const char *username, const char *success_msg)
{
}
{
/* only one valid success status for AUTH command */
}
}
{
int ret;
/* parse response */
/* check for disconnect */
case 0:
case EPIPE:
case ECONNRESET:
"Remote closed connection unexpectedly during AUTH");
break;
default:
"Connection lost during AUTH: "
"read(%s) failed: %s",
"Read failure");
}
return;
}
/* handle syntax error */
if (ret < 0) {
"Client sent invalid AUTH response: %s", error);
switch (error_code) {
/* fall through */
"Invalid AUTH response syntax");
break;
"Line too long");
break;
default:
i_unreached();
}
}
return;
}
"Received AUTH response: %s", auth_response);
/* continue authentication */
cmd, auth_response)) <= 0) {
/* command is waiting for external event or it failed */
return;
}
if (!smtp_server_command_is_replied(command)) {
/* set generic AUTH success reply if none is provided */
}
}
const char *challenge)
{
/* start AUTH-specific input handling */
}
{
int ret;
/* all preceeding commands have finished and now the transaction state
is clear. This provides the opportunity to re-check the protocol
state */
if (!cmd_auth_check_state(cmd))
return;
/* advance state */
/* specific implementation of AUTH command */
if (ret == 0)
return;
}
const char *params)
{
const char *const *argv;
502, "5.5.1", "Unsupported command");
return;
}
/* RFC 4954, Section 8:
auth-command = "AUTH" SP sasl-mech [SP initial-response]
*(CRLF [base64]) [CRLF cancel-response]
CRLF
;; <sasl-mech> is defined in [SASL]
initial-response = base64 / "="
*/
501, "5.5.4", "Missing SASL mechanism parameter");
ret = -1;
} else {
501, "5.5.4", "Invalid parameters");
ret = -1;
} else {
}
}
}
if (ret < 0)
return;
/* check protocol state */
if (!cmd_auth_check_state(cmd))
return;
}