From: Timo Sirainen Date: Fri, 20 Jan 2023 16:20:15 +0000 (+0200) Subject: lib: Allow event filters to use '/' and '%' in values without quoting X-Git-Tag: 2.4.0~3095 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=896c29ce9f3a63f6bf0f4a3d8eb85f86e73725b3;p=thirdparty%2Fdovecot%2Fcore.git lib: Allow event filters to use '/' and '%' in values without quoting This allows using "ip = 127.0.0.0/8%lo" without quotes. --- diff --git a/src/lib/event-filter-lexer.l b/src/lib/event-filter-lexer.l index 8df4ddc510..8ff73e1acb 100644 --- a/src/lib/event-filter-lexer.l +++ b/src/lib/event-filter-lexer.l @@ -64,7 +64,7 @@ static size_t event_filter_parser_input_proc(char *buf, size_t size, yyscan_t sc [Oo][Rr] { return OR; } [Nn][Oo][Tt] { return NOT; } [<>=()] { return *yytext; } -[A-Za-z0-9:.*?_-]+ { yylval->str = t_strdup(yytext); return TOKEN; } +[A-Za-z0-9:.*?/%_-]+ { yylval->str = t_strdup(yytext); return TOKEN; } [ \t\n\r] { /* ignore */ } . { /* diff --git a/src/lib/test-event-filter.c b/src/lib/test-event-filter.c index 025472fb04..6fdfd238b8 100644 --- a/src/lib/test-event-filter.c +++ b/src/lib/test-event-filter.c @@ -751,7 +751,7 @@ static void test_event_filter_ips(void) event_filter_unref(&filter); filter = event_filter_create(); - test_assert(event_filter_parse("ip = \"127.0.0.0/16\"", filter, &error) == 0); + test_assert(event_filter_parse("ip = 127.0.0.0/16", filter, &error) == 0); /* network mask match */ test_assert(net_addr2ip("127.0.255.255", &ip) == 0); event_add_ip(e, "ip", &ip); @@ -785,14 +785,14 @@ static void test_event_filter_ips(void) { "ip = ::1", test_addr2ip("::1"), TRUE }, { "ip = ::2", test_addr2ip("::1"), FALSE }, - { "ip = \"::1/128\"", test_addr2ip("::1"), TRUE }, - { "ip = \"::1/126\"", test_addr2ip("::2"), TRUE }, + { "ip = ::1/128", test_addr2ip("::1"), TRUE }, + { "ip = ::1/126", test_addr2ip("::2"), TRUE }, { "ip = \"::1/126\"", test_addr2ip("::3"), TRUE }, - { "ip = \"::1/126\"", test_addr2ip("::4"), FALSE }, + { "ip = ::1/126", test_addr2ip("::4"), FALSE }, - { "ip = \"2001::/8\"", test_addr2ip("2001::1"), TRUE }, - { "ip = \"2001::/8\"", test_addr2ip("20ff:ffff::1"), TRUE }, - { "ip = \"2001::/8\"", test_addr2ip("2100::1"), FALSE }, + { "ip = 2001::/8", test_addr2ip("2001::1"), TRUE }, + { "ip = 2001::/8", test_addr2ip("20ff:ffff::1"), TRUE }, + { "ip = 2001::/8", test_addr2ip("2100::1"), FALSE }, { "ip = 2001::1", test_addr2ip("2001::1"), TRUE }, { "ip = \"2001::1\"", test_addr2ip("2001::1"), TRUE }, @@ -804,7 +804,7 @@ static void test_event_filter_ips(void) { "ip = 2001:1190:c02a:130:a87a:ad7:5b76:3310", test_addr2ip("2000:1190:c02a:130:a87a:ad7:5b76:3310"), FALSE }, - { "ip = \"fe80::1%lo\"", test_addr2ip("fe80::1%lo"), TRUE }, + { "ip = fe80::1%lo", test_addr2ip("fe80::1%lo"), TRUE }, }; for (unsigned int i = 0; i < N_ELEMENTS(tests); i++) { filter = event_filter_create();