]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Allow event filters to use '/' and '%' in values without quoting
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 20 Jan 2023 16:20:15 +0000 (18:20 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 27 Jan 2023 13:01:47 +0000 (13:01 +0000)
This allows using "ip = 127.0.0.0/8%lo" without quotes.

src/lib/event-filter-lexer.l
src/lib/test-event-filter.c

index 8df4ddc510da7fa130c999aeadf196bf60521cdf..8ff73e1acb3c4fe5d21f8c52add23a8ba72415f4 100644 (file)
@@ -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 */ }
 .                              {
                                        /*
index 025472fb047e0ec9ab62e39177cc956384257c4e..6fdfd238b838c3c343c365b2ba71b51acd365e18 100644 (file)
@@ -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();