summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJeremy Harris <jgh146exb@wizmail.org>2021-03-19 20:42:25 +0000
committerJeremy Harris <jgh146exb@wizmail.org>2021-04-03 21:27:25 +0100
commit1cf47989a0376c3f7156c214c1d509d372e4262b (patch)
tree059e0eb2f099822c38fd0f3eec0b36c3dc59c43c /src
parentbf3e317e5a01916a351278597c6c0664ed198ddc (diff)
Make smtp_accept_max_per_connection expanded
Diffstat (limited to 'src')
-rw-r--r--src/src/globals.c2
-rw-r--r--src/src/globals.h2
-rw-r--r--src/src/readconf.c2
-rw-r--r--src/src/smtp_in.c31
4 files changed, 25 insertions, 12 deletions
diff --git a/src/src/globals.c b/src/src/globals.c
index b7e117868..04e47050e 100644
--- a/src/src/globals.c
+++ b/src/src/globals.c
@@ -1450,7 +1450,7 @@ int smtp_accept_count = 0;
int smtp_accept_max = 20;
int smtp_accept_max_nonmail= 10;
uschar *smtp_accept_max_nonmail_hosts = US"*";
-int smtp_accept_max_per_connection = 1000;
+uschar *smtp_accept_max_per_connection = US"1000";
uschar *smtp_accept_max_per_host = NULL;
int smtp_accept_queue = 0;
int smtp_accept_queue_per_connection = 10;
diff --git a/src/src/globals.h b/src/src/globals.h
index 41705fb4b..652518ade 100644
--- a/src/src/globals.h
+++ b/src/src/globals.h
@@ -926,7 +926,7 @@ extern BOOL smtp_accept_keepalive; /* Set keepalive on incoming */
extern int smtp_accept_max; /* Max SMTP connections */
extern int smtp_accept_max_nonmail;/* Max non-mail commands in one con */
extern uschar *smtp_accept_max_nonmail_hosts; /* Limit non-mail cmds from these hosts */
-extern int smtp_accept_max_per_connection; /* Max msgs per connection */
+extern uschar *smtp_accept_max_per_connection; /* Max msgs per connection */
extern uschar *smtp_accept_max_per_host; /* Max SMTP cons from one IP addr */
extern int smtp_accept_queue; /* Queue after so many connections */
extern int smtp_accept_queue_per_connection; /* Queue after so many msgs */
diff --git a/src/src/readconf.c b/src/src/readconf.c
index fb9164c9d..0ae3166c3 100644
--- a/src/src/readconf.c
+++ b/src/src/readconf.c
@@ -300,7 +300,7 @@ static optionlist optionlist_config[] = {
{ "smtp_accept_max", opt_int, {&smtp_accept_max} },
{ "smtp_accept_max_nonmail", opt_int, {&smtp_accept_max_nonmail} },
{ "smtp_accept_max_nonmail_hosts", opt_stringptr, {&smtp_accept_max_nonmail_hosts} },
- { "smtp_accept_max_per_connection", opt_int, {&smtp_accept_max_per_connection} },
+ { "smtp_accept_max_per_connection", opt_stringptr, {&smtp_accept_max_per_connection} },
{ "smtp_accept_max_per_host", opt_stringptr, {&smtp_accept_max_per_host} },
{ "smtp_accept_queue", opt_int, {&smtp_accept_queue} },
{ "smtp_accept_queue_per_connection", opt_int, {&smtp_accept_queue_per_connection} },
diff --git a/src/src/smtp_in.c b/src/src/smtp_in.c
index 6d6370ffd..5888b8037 100644
--- a/src/src/smtp_in.c
+++ b/src/src/smtp_in.c
@@ -3879,6 +3879,13 @@ cmd_list[CMD_LIST_RSET].is_mail_cmd = FALSE;
}
+static int
+expand_mailmax(const uschar * s)
+{
+if (!(s = expand_cstring(s)))
+ log_write(0, LOG_MAIN|LOG_PANIC, "failed to expand smtp_accept_max_per_connection");
+return *s ? Uatoi(s) : 0;
+}
/*************************************************
* Initialize for SMTP incoming message *
@@ -3909,6 +3916,7 @@ int
smtp_setup_msg(void)
{
int done = 0;
+int mailmax = -1;
BOOL toomany = FALSE;
BOOL discarded = FALSE;
BOOL last_was_rej_mail = FALSE;
@@ -4266,6 +4274,9 @@ while (done <= 0)
fl.smtputf8_advertised = FALSE;
#endif
+ /* Expand the per-connection message count limit option */
+ mailmax = expand_mailmax(smtp_accept_max_per_connection);
+
smtp_code = US"250 "; /* Default response code plus space*/
if (!user_msg)
{
@@ -4541,13 +4552,16 @@ while (done <= 0)
was_rej_mail = TRUE; /* Reset if accepted */
env_mail_type_t * mail_args; /* Sanity check & validate args */
- if (fl.helo_required && !fl.helo_seen)
- {
- smtp_printf("503 HELO or EHLO required\r\n", FALSE);
- log_write(0, LOG_MAIN|LOG_REJECT, "rejected MAIL from %s: no "
- "HELO/EHLO given", host_and_ident(FALSE));
- break;
- }
+ if (!fl.helo_seen)
+ if (fl.helo_required)
+ {
+ smtp_printf("503 HELO or EHLO required\r\n", FALSE);
+ log_write(0, LOG_MAIN|LOG_REJECT, "rejected MAIL from %s: no "
+ "HELO/EHLO given", host_and_ident(FALSE));
+ break;
+ }
+ else if (mailmax < 0)
+ mailmax = expand_mailmax(smtp_accept_max_per_connection);
if (sender_address)
{
@@ -4566,8 +4580,7 @@ while (done <= 0)
/* Check to see if the limit for messages per connection would be
exceeded by accepting further messages. */
- if (smtp_accept_max_per_connection > 0 &&
- smtp_mailcmd_count > smtp_accept_max_per_connection)
+ if (mailmax > 0 && smtp_mailcmd_count > mailmax)
{
smtp_printf("421 too many messages in this connection\r\n", FALSE);
log_write(0, LOG_MAIN|LOG_REJECT, "rejected MAIL command %s: too many "