Index | Thread | Search

From:
Kirill A. Korinsky <kirill@korins.ky>
Subject:
Re: smtpd: allow braces for `listen' options
To:
Omar Polo <op@omarpolo.com>
Cc:
tech@openbsd.org
Date:
Mon, 21 Oct 2024 00:34:59 +0200

Download raw body.

Thread
On Sun, 20 Oct 2024 16:51:17 +0200,
Omar Polo <op@omarpolo.com> wrote:
> 
> i was thinking something way more complex, but your approach could work
> as well too.  I'll need a moment to make sure we're not breaking other
> cases, but I like it.
>

Here a bit updated diff where I've adde / into possible string, otherwise it
won't work with path.

> > Anyway, keywords is different story, yeah.
> 
> this is a pain in other contexts as well, so maybe we could just live
> with it.  The manpage would need a note that "reserved keywords must be
> quoted."
> 

If I recall right this sort of issue is called shift-reduce conflict and
%prec is magic which is used to solve it.

Thus, here an updated diff:

Index: parse.y
===================================================================
RCS file: /cvs/src/usr.sbin/smtpd/parse.y,v
diff -u -p -r1.299 parse.y
--- parse.y	19 Feb 2024 21:00:19 -0000	1.299
+++ parse.y	20 Oct 2024 22:34:24 -0000
@@ -191,6 +191,7 @@ typedef struct {
 %token	<v.string>	STRING
 %token  <v.number>	NUMBER
 %type	<v.table>	table
+%type	<v.string>	numberstr cmdline cmdline_l
 %type	<v.number>	size negation
 %type	<v.table>	tables tablenew tableref
 %%
@@ -295,6 +296,29 @@ tableval_list	: string_list			{ }
 		| keyval_list			{ }
 		;
 
+numberstr:
+STRING
+| NUMBER {
+	if (asprintf(&$$, "%lld", (long long)$1) == -1)
+		fatalx("asprintf");
+}
+;
+
+cmdline_l:
+numberstr optnl { $$ = $1; }
+| cmdline_l numberstr optnl {
+	if (asprintf(&$$, "%s %s", $1, $2) == -1)
+		fatalx("asprint");
+	free($1);
+	free($2);
+}
+;
+
+cmdline:
+STRING
+| '{' optnl cmdline_l '}' { $$ = $3; }
+;
+
 bounce:
 BOUNCE WARN_INTERVAL {
 	memset(conf->sc_bounce_warn, 0, sizeof conf->sc_bounce_warn);
@@ -1911,7 +1935,7 @@ FILTER STRING PROC STRING {
 	filter_config = NULL;
 }
 |
-FILTER STRING PROC_EXEC STRING {
+FILTER STRING PROC_EXEC cmdline {
 	if (dict_get(conf->sc_filters_dict, $2)) {
 		yyerror("filter already exists with that name: %s", $2);
 		free($2);
@@ -2889,7 +2913,7 @@ top:
 				yyerror("string too long");
 				return (findeol());
 			}
-			if (isalnum(c) || c == '_') {
+			if (isalnum(c) || c == '/' || c == '-' || c == '_') {
 				*p++ = c;
 				continue;
 			}
@@ -2983,8 +3007,6 @@ nodigits:
 			while (p > buf + 1)
 				lungetc((unsigned char)*--p);
 			c = (unsigned char)*--p;
-			if (c == '-')
-				return (c);
 		}
 	}
 
@@ -3001,7 +3023,7 @@ nodigits:
 	x != '!' && x != '=' && x != '#' && \
 	x != ','))
 
-	if (isalnum(c) || c == ':' || c == '_') {
+	if (isalnum(c) || c == ':' || c == '/' || c == '-' || c == '_') {
 		do {
 			*p++ = c;
 			if ((size_t)(p-buf) >= sizeof(buf)) {


-- 
wbr, Kirill