]> git.armaanb.net Git - opendoas.git/blobdiff - parse.y
clarify that -L will exit without running a command.
[opendoas.git] / parse.y
diff --git a/parse.y b/parse.y
index ee5f11d04ab8b8c5ae60dc7749b78b106b31bcfb..43732a6291144726e88e82d3925620394ddd9ea1 100644 (file)
--- a/parse.y
+++ b/parse.y
 %{
 #include <sys/types.h>
 #include <ctype.h>
-#include <unistd.h>
-#include <stdint.h>
+#include <err.h>
 #include <stdarg.h>
 #include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
 #include <string.h>
-#include <err.h>
+#include <unistd.h>
+
+#include "openbsd.h"
 
 #include "doas.h"
 
@@ -48,6 +51,7 @@ FILE *yyfp;
 struct rule **rules;
 int nrules, maxrules;
 int parse_errors = 0;
+int obsolete_warned = 0;
 
 void yyerror(const char *, ...);
 int yylex(void);
@@ -56,7 +60,7 @@ int yyparse(void);
 %}
 
 %token TPERMIT TDENY TAS TCMD TARGS
-%token TNOPASS TKEEPENV
+%token TNOPASS TPERSIST TKEEPENV TSETENV
 %token TSTRING
 
 %%
@@ -97,15 +101,19 @@ action:            TPERMIT options {
                        $$.envlist = $2.envlist;
                } | TDENY {
                        $$.action = DENY;
+                       $$.options = 0;
+                       $$.envlist = NULL;
                } ;
 
-options:       /* none */
-               | options option {
+options:       /* none */ {
+                       $$.options = 0;
+                       $$.envlist = NULL;
+               } | options option {
                        $$.options = $1.options | $2.options;
                        $$.envlist = $1.envlist;
                        if ($2.envlist) {
                                if ($$.envlist) {
-                                       yyerror("can't have two keepenv sections");
+                                       yyerror("can't have two setenv sections");
                                        YYERROR;
                                } else
                                        $$.envlist = $2.envlist;
@@ -113,16 +121,27 @@ options:  /* none */
                } ;
 option:                TNOPASS {
                        $$.options = NOPASS;
+                       $$.envlist = NULL;
+               } | TPERSIST {
+                       $$.options = PERSIST;
+                       $$.envlist = NULL;
                } | TKEEPENV {
                        $$.options = KEEPENV;
+                       $$.envlist = NULL;
                } | TKEEPENV '{' envlist '}' {
-                       $$.options = KEEPENV;
+                       $$.options = 0;
+                       if (!obsolete_warned) {
+                               warnx("keepenv with list is obsolete");
+                               obsolete_warned = 1;
+                       }
+                       $$.envlist = $3.envlist;
+               } | TSETENV '{' envlist '}' {
+                       $$.options = 0;
                        $$.envlist = $3.envlist;
                } ;
 
 envlist:       /* empty */ {
-                       if (!($$.envlist = calloc(1, sizeof(char *))))
-                               errx(1, "can't allocate envlist");
+                       $$.envlist = NULL;
                } | envlist TSTRING {
                        int nenv = arraylen($1.envlist);
                        if (!($$.envlist = reallocarray($1.envlist, nenv + 2,
@@ -158,8 +177,7 @@ args:               /* empty */ {
                } ;
 
 argslist:      /* empty */ {
-                       if (!($$.cmdargs = calloc(1, sizeof(char *))))
-                               errx(1, "can't allocate args");
+                       $$.cmdargs = NULL;
                } | argslist TSTRING {
                        int nargs = arraylen($1.cmdargs);
                        if (!($$.cmdargs = reallocarray($1.cmdargs, nargs + 2,
@@ -193,14 +211,16 @@ struct keyword {
        { "cmd", TCMD },
        { "args", TARGS },
        { "nopass", TNOPASS },
+       { "persist", TPERSIST },
        { "keepenv", TKEEPENV },
+       { "setenv", TSETENV },
 };
 
 int
 yylex(void)
 {
        char buf[1024], *ebuf, *p, *str;
-       int i, c, quotes = 0, escape = 0, qpos = -1, nonkw = 0;
+       int c, quotes = 0, escape = 0, qpos = -1, nonkw = 0;
 
        p = buf;
        ebuf = buf + sizeof(buf);
@@ -303,6 +323,7 @@ eow:
                        goto repeat;
        }
        if (!nonkw) {
+               size_t i;
                for (i = 0; i < sizeof(keywords) / sizeof(keywords[0]); i++) {
                        if (strcmp(buf, keywords[i].word) == 0)
                                return keywords[i].token;