[2025-01-07 22:55] Philipp <phil...@bureaucracy.de> > [2025-01-07 11:28] OlivaFN88 <felipe.n...@gmail.com> > But the parser for this is currently not working. I have started to > write a patch for this.
My patch is attached. Philipp
From 6b59fdf1543bc9a98facabc152e0eaa7eaeb890a Mon Sep 17 00:00:00 2001 From: Philipp <philipp+open...@bureaucracy.de> Date: Tue, 7 Jan 2025 23:33:02 +0100 Subject: [PATCH] filter allow multible conditions --- usr.sbin/smtpd/parse.y | 135 ++++++++++++++++++++++++++++++++++------- 1 file changed, 114 insertions(+), 21 deletions(-) diff --git a/usr.sbin/smtpd/parse.y b/usr.sbin/smtpd/parse.y index 795e9527..30443372 100644 --- a/usr.sbin/smtpd/parse.y +++ b/usr.sbin/smtpd/parse.y @@ -1582,6 +1582,10 @@ REJECT STRING { filter_phase_check_fcrdns: negation FCRDNS { + if (filter_config->fcrdns) { + yyerror("fcrdns already specified for this filter"); + YYERROR; + } filter_config->not_fcrdns = $1 ? -1 : 1; filter_config->fcrdns = 1; } @@ -1589,6 +1593,10 @@ negation FCRDNS { filter_phase_check_rdns: negation RDNS { + if (filter_config->rdns || filter_config->rdns_table || filter_config->rdns_regex) { + yyerror("rdns already specified for this filter"); + YYERROR; + } filter_config->not_rdns = $1 ? -1 : 1; filter_config->rdns = 1; } @@ -1596,12 +1604,20 @@ negation RDNS { filter_phase_check_rdns_table: negation RDNS tables { + if (filter_config->rdns || filter_config->rdns_table || filter_config->rdns_regex) { + yyerror("rdns already specified for this filter"); + YYERROR; + } filter_config->not_rdns_table = $1 ? -1 : 1; filter_config->rdns_table = $3; } ; filter_phase_check_rdns_regex: negation RDNS REGEX tables { + if (filter_config->rdns || filter_config->rdns_table || filter_config->rdns_regex) { + yyerror("rdns already specified for this filter"); + YYERROR; + } filter_config->not_rdns_regex = $1 ? -1 : 1; filter_config->rdns_regex = $4; } @@ -1609,6 +1625,10 @@ negation RDNS REGEX tables { filter_phase_check_src_table: negation SRC tables { + if (filter_config->src_table || filter_config->src_regex) { + yyerror("src already specified for this filter"); + YYERROR; + } filter_config->not_src_table = $1 ? -1 : 1; filter_config->src_table = $3; } @@ -1622,12 +1642,20 @@ negation SRC REGEX tables { filter_phase_check_helo_table: negation HELO tables { + if (filter_config->helo_table || filter_config->helo_regex) { + yyerror("helo already specified for this filter"); + YYERROR; + } filter_config->not_helo_table = $1 ? -1 : 1; filter_config->helo_table = $3; } ; filter_phase_check_helo_regex: negation HELO REGEX tables { + if (filter_config->helo_table || filter_config->helo_regex) { + yyerror("helo already specified for this filter"); + YYERROR; + } filter_config->not_helo_regex = $1 ? -1 : 1; filter_config->helo_regex = $4; } @@ -1635,18 +1663,30 @@ negation HELO REGEX tables { filter_phase_check_auth: negation AUTH { + if (filter_config->auth || filter_config->auth_table || filter_config->auth_regex) { + yyerror("auth already specified for this filter"); + YYERROR; + } filter_config->not_auth = $1 ? -1 : 1; filter_config->auth = 1; } ; filter_phase_check_auth_table: negation AUTH tables { + if (filter_config->auth || filter_config->auth_table || filter_config->auth_regex) { + yyerror("auth already specified for this filter"); + YYERROR; + } filter_config->not_auth_table = $1 ? -1 : 1; filter_config->auth_table = $3; } ; filter_phase_check_auth_regex: negation AUTH REGEX tables { + if (filter_config->auth || filter_config->auth_table || filter_config->auth_regex) { + yyerror("auth already specified for this filter"); + YYERROR; + } filter_config->not_auth_regex = $1 ? -1 : 1; filter_config->auth_regex = $4; } @@ -1654,12 +1694,20 @@ negation AUTH REGEX tables { filter_phase_check_mail_from_table: negation MAIL_FROM tables { + if (filter_config->mail_from_table || filter_config->mail_from_regex) { + yyerror("mail from already specified for this filter"); + YYERROR; + } filter_config->not_mail_from_table = $1 ? -1 : 1; filter_config->mail_from_table = $3; } ; filter_phase_check_mail_from_regex: negation MAIL_FROM REGEX tables { + if (filter_config->mail_from_table || filter_config->mail_from_regex) { + yyerror("mail from already specified for this filter"); + YYERROR; + } filter_config->not_mail_from_regex = $1 ? -1 : 1; filter_config->mail_from_regex = $4; } @@ -1667,18 +1715,26 @@ negation MAIL_FROM REGEX tables { filter_phase_check_rcpt_to_table: negation RCPT_TO tables { + if (filter_config->rcpt_to_table || filter_config->rcpt_to_regex) { + yyerror("rcpt to already specified for this filter"); + YYERROR; + } filter_config->not_rcpt_to_table = $1 ? -1 : 1; filter_config->rcpt_to_table = $3; } ; filter_phase_check_rcpt_to_regex: negation RCPT_TO REGEX tables { + if (filter_config->rcpt_to_table || filter_config->rcpt_to_regex) { + yyerror("rcpt to already specified for this filter"); + YYERROR; + } filter_config->not_rcpt_to_regex = $1 ? -1 : 1; filter_config->rcpt_to_regex = $4; } ; -filter_phase_global_options: +filter_phase_global_option: filter_phase_check_fcrdns | filter_phase_check_rdns | filter_phase_check_rdns_regex | @@ -1686,23 +1742,36 @@ filter_phase_check_rdns_table | filter_phase_check_src_regex | filter_phase_check_src_table; -filter_phase_connect_options: -filter_phase_global_options; +filter_phase_connect_options : filter_phase_global_option filter_phase_connect_options + | /* empty */ + ; -filter_phase_helo_options: +filter_phase_helo_options : filter_phase_helo_option + | /* empty */ + ; + +filter_phase_helo_option: filter_phase_check_helo_table | filter_phase_check_helo_regex | -filter_phase_global_options; +filter_phase_global_option; + +filter_phase_auth_options : filter_phase_auth_option filter_phase_auth_options + | /* empty */ + ; -filter_phase_auth_options: +filter_phase_auth_option: filter_phase_check_helo_table | filter_phase_check_helo_regex | filter_phase_check_auth | filter_phase_check_auth_table | filter_phase_check_auth_regex | -filter_phase_global_options; +filter_phase_global_option; + +filter_phase_mail_from_options : filter_phase_mail_from_option filter_phase_mail_from_options + | /* empty */ + ; -filter_phase_mail_from_options: +filter_phase_mail_from_option: filter_phase_check_helo_table | filter_phase_check_helo_regex | filter_phase_check_auth | @@ -1710,9 +1779,13 @@ filter_phase_check_auth_table | filter_phase_check_auth_regex | filter_phase_check_mail_from_table | filter_phase_check_mail_from_regex | -filter_phase_global_options; +filter_phase_global_option; -filter_phase_rcpt_to_options: +filter_phase_rcpt_to_options : filter_phase_rcpt_to_option filter_phase_rcpt_to_options + | /* empty */ + ; + +filter_phase_rcpt_to_option: filter_phase_check_helo_table | filter_phase_check_helo_regex | filter_phase_check_auth | @@ -1722,9 +1795,13 @@ filter_phase_check_mail_from_table | filter_phase_check_mail_from_regex | filter_phase_check_rcpt_to_table | filter_phase_check_rcpt_to_regex | -filter_phase_global_options; +filter_phase_global_option; + +filter_phase_data_options : filter_phase_data_option filter_phase_data_options + | /* empty */ + ; -filter_phase_data_options: +filter_phase_data_option: filter_phase_check_helo_table | filter_phase_check_helo_regex | filter_phase_check_auth | @@ -1732,26 +1809,42 @@ filter_phase_check_auth_table | filter_phase_check_auth_regex | filter_phase_check_mail_from_table | filter_phase_check_mail_from_regex | -filter_phase_global_options; +filter_phase_global_option; /* -filter_phase_quit_options: +filter_phase_quit_options : filter_phase_quit_option filter_phase_quit_options + | empty + ; + +filter_phase_quit_option: filter_phase_check_helo_table | filter_phase_check_helo_regex | -filter_phase_global_options; +filter_phase_global_option; + +filter_phase_rset_options : filter_phase_rset_option filter_phase_rset_options + | empty + ; -filter_phase_rset_options: +filter_phase_rset_option: filter_phase_check_helo_table | filter_phase_check_helo_regex | -filter_phase_global_options; +filter_phase_global_option; -filter_phase_noop_options: +filter_phase_noop_options : filter_phase_noop_option filter_phase_noop_options + | empty + ; + +filter_phase_noop_option: filter_phase_check_helo_table | filter_phase_check_helo_regex | -filter_phase_global_options; +filter_phase_global_option; */ -filter_phase_commit_options: +filter_phase_commit_options : filter_phase_commit_option filter_phase_commit_options + | /* empty */ + ; + +filter_phase_commit_option: filter_phase_check_helo_table | filter_phase_check_helo_regex | filter_phase_check_auth | @@ -1759,7 +1852,7 @@ filter_phase_check_auth_table | filter_phase_check_auth_regex | filter_phase_check_mail_from_table | filter_phase_check_mail_from_regex | -filter_phase_global_options; +filter_phase_global_option; filter_phase_connect: -- 2.39.5