Imported Upstream version 1.8.4p4
[debian/sudo] / plugins / sudoers / gram.y
index f3f0aace351b2ab4c4d253ca30c08a58e0cb8a0b..483d0c3a8627c7dc412327dbc87907db24391e86 100644 (file)
@@ -1,6 +1,6 @@
 %{
 /*
- * Copyright (c) 1996, 1998-2005, 2007-2011
+ * Copyright (c) 1996, 1998-2005, 2007-2012
  *     Todd C. Miller <Todd.Miller@courtesan.com>
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -52,6 +52,7 @@
 #include "sudoers.h" /* XXX */
 #include "parse.h"
 #include "toke.h"
+#include "gram.h"
 
 /*
  * We must define SIZE_MAX for yacc's skeleton.c.
  * Globals
  */
 extern int sudolineno;
+extern int last_token;
 extern char *sudoers;
-static int verbose = FALSE;
-int parse_error = FALSE;
-int pedantic = FALSE;
+static bool verbose = false;
+bool parse_error = false;
 int errorlineno = -1;
 char *errorfile = NULL;
 
@@ -92,18 +93,24 @@ static struct member *new_member(char *, int);
 void
 yyerror(const char *s)
 {
+    debug_decl(yyerror, SUDO_DEBUG_PARSER)
+
+    /* If we last saw a newline the error is on the preceding line. */
+    if (last_token == COMMENT)
+       sudolineno--;
+
     /* Save the line the first error occurred on. */
     if (errorlineno == -1) {
-       errorlineno = sudolineno ? sudolineno - 1 : 0;
+       errorlineno = sudolineno;
        errorfile = estrdup(sudoers);
     }
     if (trace_print != NULL) {
        LEXTRACE("<*> ");
     } else if (verbose && s != NULL) {
-       warningx(_(">>> %s: %s near line %d <<<"), sudoers, s,
-           sudolineno ? sudolineno - 1 : 0);
+       warningx(_(">>> %s: %s near line %d <<<"), sudoers, s, sudolineno);
     }
-    parse_error = TRUE;
+    parse_error = true;
+    debug_return;
 }
 %}
 
@@ -236,13 +243,13 @@ defaults_list     :       defaults_entry
                ;
 
 defaults_entry :       DEFVAR {
-                           $$ = new_default($1, NULL, TRUE);
+                           $$ = new_default($1, NULL, true);
                        }
                |       '!' DEFVAR {
-                           $$ = new_default($2, NULL, FALSE);
+                           $$ = new_default($2, NULL, false);
                        }
                |       DEFVAR '=' WORD {
-                           $$ = new_default($1, $3, TRUE);
+                           $$ = new_default($1, $3, true);
                        }
                |       DEFVAR '+' WORD {
                            $$ = new_default($1, $3, '+');
@@ -271,11 +278,11 @@ privilege :       hostlist '=' cmndspeclist {
 
 ophost         :       host {
                            $$ = $1;
-                           $$->negated = FALSE;
+                           $$->negated = false;
                        }
                |       '!' host {
                            $$ = $2;
-                           $$->negated = TRUE;
+                           $$->negated = true;
                        }
                ;
 
@@ -357,11 +364,11 @@ cmndspec  :       runasspec selinux cmndtag opcmnd {
 
 opcmnd         :       cmnd {
                            $$ = $1;
-                           $$->negated = FALSE;
+                           $$->negated = false;
                        }
                |       '!' cmnd {
                            $$ = $2;
-                           $$->negated = TRUE;
+                           $$->negated = true;
                        }
                ;
 
@@ -427,34 +434,34 @@ cmndtag           :       /* empty */ {
                                $$.log_input = $$.log_output = UNSPEC;
                        }
                |       cmndtag NOPASSWD {
-                           $$.nopasswd = TRUE;
+                           $$.nopasswd = true;
                        }
                |       cmndtag PASSWD {
-                           $$.nopasswd = FALSE;
+                           $$.nopasswd = false;
                        }
                |       cmndtag NOEXEC {
-                           $$.noexec = TRUE;
+                           $$.noexec = true;
                        }
                |       cmndtag EXEC {
-                           $$.noexec = FALSE;
+                           $$.noexec = false;
                        }
                |       cmndtag SETENV {
-                           $$.setenv = TRUE;
+                           $$.setenv = true;
                        }
                |       cmndtag NOSETENV {
-                           $$.setenv = FALSE;
+                           $$.setenv = false;
                        }
                |       cmndtag LOG_INPUT {
-                           $$.log_input = TRUE;
+                           $$.log_input = true;
                        }
                |       cmndtag NOLOG_INPUT {
-                           $$.log_input = FALSE;
+                           $$.log_input = false;
                        }
                |       cmndtag LOG_OUTPUT {
-                           $$.log_output = TRUE;
+                           $$.log_output = true;
                        }
                |       cmndtag NOLOG_OUTPUT {
-                           $$.log_output = FALSE;
+                           $$.log_output = false;
                        }
                ;
 
@@ -547,11 +554,11 @@ userlist  :       opuser
 
 opuser         :       user {
                            $$ = $1;
-                           $$->negated = FALSE;
+                           $$->negated = false;
                        }
                |       '!' user {
                            $$ = $2;
-                           $$->negated = TRUE;
+                           $$->negated = true;
                        }
                ;
 
@@ -581,11 +588,11 @@ grouplist :       opgroup
 
 opgroup                :       group {
                            $$ = $1;
-                           $$->negated = FALSE;
+                           $$->negated = false;
                        }
                |       '!' group {
                            $$ = $2;
-                           $$->negated = TRUE;
+                           $$->negated = true;
                        }
                ;
 
@@ -605,6 +612,7 @@ static struct defaults *
 new_default(char *var, char *val, int op)
 {
     struct defaults *d;
+    debug_decl(new_default, SUDO_DEBUG_PARSER)
 
     d = emalloc(sizeof(struct defaults));
     d->var = var;
@@ -615,13 +623,14 @@ new_default(char *var, char *val, int op)
     d->prev = d;
     d->next = NULL;
 
-    return d;
+    debug_return_ptr(d);
 }
 
 static struct member *
 new_member(char *name, int type)
 {
     struct member *m;
+    debug_decl(new_member, SUDO_DEBUG_PARSER)
 
     m = emalloc(sizeof(struct member));
     m->name = name;
@@ -629,7 +638,7 @@ new_member(char *name, int type)
     m->prev = m;
     m->next = NULL;
 
-    return m;
+    debug_return_ptr(m);
 }
 
 /*
@@ -642,6 +651,7 @@ add_defaults(int type, struct member *bmem, struct defaults *defs)
 {
     struct defaults *d;
     struct member_list binding;
+    debug_decl(add_defaults, SUDO_DEBUG_PARSER)
 
     /*
      * We can only call list2tq once on bmem as it will zero
@@ -657,6 +667,8 @@ add_defaults(int type, struct member *bmem, struct defaults *defs)
        d->binding = binding;
     }
     tq_append(&defaults, defs);
+
+    debug_return;
 }
 
 /*
@@ -667,6 +679,7 @@ static void
 add_userspec(struct member *members, struct privilege *privs)
 {
     struct userspec *u;
+    debug_decl(add_userspec, SUDO_DEBUG_PARSER)
 
     u = emalloc(sizeof(*u));
     list2tq(&u->users, members);
@@ -674,6 +687,8 @@ add_userspec(struct member *members, struct privilege *privs)
     u->prev = u;
     u->next = NULL;
     tq_append(&userspecs, u);
+
+    debug_return;
 }
 
 /*
@@ -689,6 +704,7 @@ init_parser(const char *path, int quiet)
     struct privilege *priv;
     struct cmndspec *cs;
     struct sudo_command *c;
+    debug_decl(init_parser, SUDO_DEBUG_PARSER)
 
     while ((us = tq_pop(&userspecs)) != NULL) {
        while ((m = tq_pop(&us->users)) != NULL) {
@@ -773,8 +789,10 @@ init_parser(const char *path, int quiet)
     efree(sudoers);
     sudoers = path ? estrdup(path) : NULL;
 
-    parse_error = FALSE;
+    parse_error = false;
     errorlineno = -1;
-    errorfile = NULL;
+    errorfile = sudoers;
     verbose = !quiet;
+
+    debug_return;
 }