Imported Upstream version 1.8.4p4
[debian/sudo] / plugins / sudoers / gram.c
1 #include <config.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #define YYBYACC 1
5 #define YYMAJOR 1
6 #define YYMINOR 9
7 #define YYLEX yylex()
8 #define YYEMPTY -1
9 #define yyclearin (yychar=(YYEMPTY))
10 #define yyerrok (yyerrflag=0)
11 #define YYRECOVERING() (yyerrflag!=0)
12 #define YYPREFIX "yy"
13 #line 2 "gram.y"
14 /*
15  * Copyright (c) 1996, 1998-2005, 2007-2011
16  *      Todd C. Miller <Todd.Miller@courtesan.com>
17  *
18  * Permission to use, copy, modify, and distribute this software for any
19  * purpose with or without fee is hereby granted, provided that the above
20  * copyright notice and this permission notice appear in all copies.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
23  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
24  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
25  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
26  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
27  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
28  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * Sponsored in part by the Defense Advanced Research Projects
33  * Agency (DARPA) and Air Force Research Laboratory, Air Force
34  * Materiel Command, USAF, under agreement number F39502-99-1-0512.
35  */
36
37 #include <config.h>
38
39 #include <sys/types.h>
40 #include <sys/param.h>
41 #include <stdio.h>
42 #ifdef STDC_HEADERS
43 # include <stdlib.h>
44 # include <stddef.h>
45 #else
46 # ifdef HAVE_STDLIB_H
47 #  include <stdlib.h>
48 # endif
49 #endif /* STDC_HEADERS */
50 #ifdef HAVE_STRING_H
51 # include <string.h>
52 #endif /* HAVE_STRING_H */
53 #ifdef HAVE_STRINGS_H
54 # include <strings.h>
55 #endif /* HAVE_STRINGS_H */
56 #ifdef HAVE_UNISTD_H
57 # include <unistd.h>
58 #endif /* HAVE_UNISTD_H */
59 #if defined(YYBISON) && defined(HAVE_ALLOCA_H) && !defined(__GNUC__)
60 # include <alloca.h>
61 #endif /* YYBISON && HAVE_ALLOCA_H && !__GNUC__ */
62 #include <limits.h>
63
64 #include "sudoers.h" /* XXX */
65 #include "parse.h"
66 #include "toke.h"
67 #include "gram.h"
68
69 /*
70  * We must define SIZE_MAX for yacc's skeleton.c.
71  * If there is no SIZE_MAX or SIZE_T_MAX we have to assume that size_t
72  * could be signed (as it is on SunOS 4.x).
73  */
74 #ifndef SIZE_MAX
75 # ifdef SIZE_T_MAX
76 #  define SIZE_MAX      SIZE_T_MAX
77 # else
78 #  define SIZE_MAX      INT_MAX
79 # endif /* SIZE_T_MAX */
80 #endif /* SIZE_MAX */
81
82 /*
83  * Globals
84  */
85 extern int sudolineno;
86 extern int last_token;
87 extern char *sudoers;
88 static bool verbose = false;
89 bool parse_error = false;
90 int errorlineno = -1;
91 char *errorfile = NULL;
92
93 struct defaults_list defaults;
94 struct userspec_list userspecs;
95
96 /*
97  * Local protoypes
98  */
99 static void  add_defaults(int, struct member *, struct defaults *);
100 static void  add_userspec(struct member *, struct privilege *);
101 static struct defaults *new_default(char *, char *, int);
102 static struct member *new_member(char *, int);
103        void  yyerror(const char *);
104
105 void
106 yyerror(const char *s)
107 {
108     debug_decl(yyerror, SUDO_DEBUG_PARSER)
109
110     /* If we last saw a newline the error is on the preceding line. */
111     if (last_token == COMMENT)
112         sudolineno--;
113
114     /* Save the line the first error occurred on. */
115     if (errorlineno == -1) {
116         errorlineno = sudolineno;
117         errorfile = estrdup(sudoers);
118     }
119     if (trace_print != NULL) {
120         LEXTRACE("<*> ");
121     } else if (verbose && s != NULL) {
122         warningx(_(">>> %s: %s near line %d <<<"), sudoers, s, sudolineno);
123     }
124     parse_error = true;
125     debug_return;
126 }
127 #line 117 "gram.y"
128 #ifndef YYSTYPE_DEFINED
129 #define YYSTYPE_DEFINED
130 typedef union {
131     struct cmndspec *cmndspec;
132     struct defaults *defaults;
133     struct member *member;
134     struct runascontainer *runas;
135     struct privilege *privilege;
136     struct sudo_command command;
137     struct cmndtag tag;
138     struct selinux_info seinfo;
139     char *string;
140     int tok;
141 } YYSTYPE;
142 #endif /* YYSTYPE_DEFINED */
143 #line 143 "gram.c"
144 #define COMMAND 257
145 #define ALIAS 258
146 #define DEFVAR 259
147 #define NTWKADDR 260
148 #define NETGROUP 261
149 #define USERGROUP 262
150 #define WORD 263
151 #define DEFAULTS 264
152 #define DEFAULTS_HOST 265
153 #define DEFAULTS_USER 266
154 #define DEFAULTS_RUNAS 267
155 #define DEFAULTS_CMND 268
156 #define NOPASSWD 269
157 #define PASSWD 270
158 #define NOEXEC 271
159 #define EXEC 272
160 #define SETENV 273
161 #define NOSETENV 274
162 #define LOG_INPUT 275
163 #define NOLOG_INPUT 276
164 #define LOG_OUTPUT 277
165 #define NOLOG_OUTPUT 278
166 #define ALL 279
167 #define COMMENT 280
168 #define HOSTALIAS 281
169 #define CMNDALIAS 282
170 #define USERALIAS 283
171 #define RUNASALIAS 284
172 #define ERROR 285
173 #define TYPE 286
174 #define ROLE 287
175 #define YYERRCODE 256
176 #if defined(__cplusplus) || defined(__STDC__)
177 const short yylhs[] =
178 #else
179 short yylhs[] =
180 #endif
181         {                                        -1,
182     0,    0,   25,   25,   26,   26,   26,   26,   26,   26,
183    26,   26,   26,   26,   26,   26,    4,    4,    3,    3,
184     3,    3,    3,   20,   20,   19,   10,   10,    8,    8,
185     8,    8,    8,    2,    2,    1,    6,    6,   23,   24,
186    22,   22,   22,   22,   22,   17,   17,   18,   18,   18,
187    21,   21,   21,   21,   21,   21,   21,   21,   21,   21,
188    21,    5,    5,    5,   28,   28,   31,    9,    9,   29,
189    29,   32,    7,    7,   30,   30,   33,   27,   27,   34,
190    13,   13,   11,   11,   12,   12,   12,   12,   12,   16,
191    16,   14,   14,   15,   15,   15,
192 };
193 #if defined(__cplusplus) || defined(__STDC__)
194 const short yylen[] =
195 #else
196 short yylen[] =
197 #endif
198         {                                         2,
199     0,    1,    1,    2,    1,    2,    2,    2,    2,    2,
200     2,    2,    3,    3,    3,    3,    1,    3,    1,    2,
201     3,    3,    3,    1,    3,    3,    1,    2,    1,    1,
202     1,    1,    1,    1,    3,    4,    1,    2,    3,    3,
203     0,    1,    1,    2,    2,    0,    3,    1,    3,    2,
204     0,    2,    2,    2,    2,    2,    2,    2,    2,    2,
205     2,    1,    1,    1,    1,    3,    3,    1,    3,    1,
206     3,    3,    1,    3,    1,    3,    3,    1,    3,    3,
207     1,    3,    1,    2,    1,    1,    1,    1,    1,    1,
208     3,    1,    2,    1,    1,    1,
209 };
210 #if defined(__cplusplus) || defined(__STDC__)
211 const short yydefred[] =
212 #else
213 short yydefred[] =
214 #endif
215         {                                      0,
216     0,   85,   87,   88,   89,    0,    0,    0,    0,    0,
217    86,    5,    0,    0,    0,    0,    0,    0,   81,   83,
218     0,    0,    3,    6,    0,    0,   17,    0,   29,   32,
219    31,   33,   30,    0,   27,    0,   68,    0,    0,   64,
220    63,   62,    0,   37,   73,    0,    0,    0,   65,    0,
221     0,   70,    0,    0,   78,    0,    0,   75,   84,    0,
222     0,   24,    0,    4,    0,    0,    0,   20,    0,   28,
223     0,    0,    0,    0,   38,    0,    0,    0,    0,    0,
224     0,    0,    0,    0,    0,   82,    0,    0,   21,   22,
225    23,   18,   69,   74,    0,   66,    0,   71,    0,   79,
226     0,   76,    0,   34,    0,    0,   25,    0,    0,    0,
227     0,    0,    0,   51,    0,    0,   94,   96,   95,    0,
228    90,   92,    0,    0,   47,   35,    0,    0,    0,   44,
229    45,   93,    0,    0,   40,   39,   52,   53,   54,   55,
230    56,   57,   58,   59,   60,   61,   36,   91,
231 };
232 #if defined(__cplusplus) || defined(__STDC__)
233 const short yydgoto[] =
234 #else
235 short yydgoto[] =
236 #endif
237         {                                      18,
238   104,  105,   27,   28,   44,   45,   46,   35,   61,   37,
239    19,   20,   21,  121,  122,  123,  106,  110,   62,   63,
240   129,  114,  115,  116,   22,   23,   54,   48,   51,   57,
241    49,   52,   58,   55,
242 };
243 #if defined(__cplusplus) || defined(__STDC__)
244 const short yysindex[] =
245 #else
246 short yysindex[] =
247 #endif
248         {                                    475,
249  -270,    0,    0,    0,    0,  -29,  567,  594,  594,   -2,
250     0,    0, -240, -222, -216, -212, -241,    0,    0,    0,
251   -25,  475,    0,    0,  -10, -207,    0,    9,    0,    0,
252     0,    0,    0, -235,    0,  -33,    0,  -31,  -31,    0,
253     0,    0, -242,    0,    0,  -30,   -7,    3,    0,   -6,
254     4,    0,   -5,    6,    0,   -1,    8,    0,    0,  594,
255   -20,    0,   10,    0, -205, -196, -194,    0,  -29,    0,
256   567,    9,    9,    9,    0,   -2,    9,  567, -240,   -2,
257  -222,  594, -216,  594, -212,    0,   31,  567,    0,    0,
258     0,    0,    0,    0,   26,    0,   28,    0,   29,    0,
259    29,    0,  541,    0,   32, -247,    0,   86,  -15,   33,
260    31,   14,   16,    0, -208, -204,    0,    0,    0, -231,
261     0,    0,   38,   86,    0,    0, -179, -178,  491,    0,
262     0,    0,   86,   38,    0,    0,    0,    0,    0,    0,
263     0,    0,    0,    0,    0,    0,    0,    0,};
264 #if defined(__cplusplus) || defined(__STDC__)
265 const short yyrindex[] =
266 #else
267 short yyrindex[] =
268 #endif
269         {                                     87,
270     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
271     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
272     0,   90,    0,    0,    1,    0,    0,  177,    0,    0,
273     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
274     0,    0,    0,    0,    0,    0,    0,  207,    0,    0,
275   237,    0,    0,  271,    0,    0,  300,    0,    0,    0,
276     0,    0,  329,    0,    0,    0,    0,    0,    0,    0,
277     0,  358,  387,  417,    0,    0,  446,    0,    0,    0,
278     0,    0,    0,    0,    0,    0,  -26,    0,    0,    0,
279     0,    0,    0,    0,   30,    0,   59,    0,   89,    0,
280   118,    0,    0,    0,  148,  514,    0,    0,   45,    0,
281   -26,    0,    0,    0,  537,  565,    0,    0,    0,    0,
282     0,    0,   50,    0,    0,    0,    0,    0,    0,    0,
283     0,    0,    0,   52,    0,    0,    0,    0,    0,    0,
284     0,    0,    0,    0,    0,    0,    0,    0,};
285 #if defined(__cplusplus) || defined(__STDC__)
286 const short yygindex[] =
287 #else
288 short yygindex[] =
289 #endif
290         {                                      0,
291   -17,    0,   27,   11,   54,  -64,   15,   64,    2,   34,
292    39,   84,   -3,  -27,  -18,  -21,    0,    0,   19,    0,
293     0,    0,  -12,   -4,    0,   88,    0,    0,    0,    0,
294    35,   40,   23,   37,
295 };
296 #define YYTABLESIZE 873
297 #if defined(__cplusplus) || defined(__STDC__)
298 const short yytable[] =
299 #else
300 short yytable[] =
301 #endif
302         {                                      26,
303    19,   26,   26,   26,   38,   39,   46,   34,   36,   24,
304    71,   94,   60,   76,   40,   41,    2,   47,   60,    3,
305     4,    5,   29,   71,   30,   31,  117,   32,   60,   67,
306    43,  118,   66,   19,   67,   50,   42,   11,  112,  113,
307    87,   53,  124,   33,   19,   56,   72,  119,   73,   74,
308    65,   68,   69,   78,   80,   82,   77,   89,   72,   84,
309    79,   81,   67,   83,  147,   85,   90,   88,   91,   71,
310   103,   76,   60,  125,  127,  111,  128,  112,   99,   95,
311   101,  133,  113,  135,  136,   48,    1,   67,   80,    2,
312    50,   72,   49,  126,   97,   92,   75,   70,   86,  109,
313    59,  132,  134,  131,   93,  148,  107,  102,    0,   64,
314   130,    0,    0,   96,    0,    0,   72,   77,  120,  100,
315    98,   80,    0,    0,    0,    0,    0,    0,    0,    0,
316     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
317     0,    0,    0,    0,    0,    0,   80,   26,    0,    0,
318    77,    0,    0,    0,    0,    0,    0,    0,    0,    0,
319     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
320     0,    0,    0,    0,    0,   77,   12,    0,    0,    0,
321    26,    0,    0,    0,    0,    0,    0,    0,    0,    0,
322     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
323     0,    0,    0,    0,    0,   26,    9,    0,    0,   12,
324     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
325     0,    0,    0,    0,    0,   25,    0,   25,   25,   25,
326    46,   46,   29,    0,   30,   31,   10,   32,    0,    9,
327     0,    0,   46,   46,   46,   46,   46,   46,   46,   46,
328    46,   46,   46,   33,   40,   41,   19,    0,   19,   46,
329    46,   19,   19,   19,   19,   19,   19,   19,   19,   10,
330     8,    0,    0,    0,    0,    0,   42,    0,    0,   19,
331    19,   19,   19,   19,   19,   67,    0,   67,    0,    0,
332    67,   67,   67,   67,   67,   67,   67,   67,    0,   11,
333     0,    0,    0,    8,    0,    0,    0,    0,   67,   67,
334    67,   67,   67,   67,   72,    0,   72,    0,    0,   72,
335    72,   72,   72,   72,   72,   72,   72,    0,    7,    0,
336     0,    0,   11,    0,    0,    0,    0,   72,   72,   72,
337    72,   72,   72,  117,   80,    0,   80,    0,  118,   80,
338    80,   80,   80,   80,   80,   80,   80,   15,    0,    0,
339     0,    7,    0,    0,  119,    0,    0,   80,   80,   80,
340    80,   80,   80,   77,    0,   77,    0,    0,   77,   77,
341    77,   77,   77,   77,   77,   77,   13,    0,    0,    0,
342    15,    0,    0,    0,    0,    0,   77,   77,   77,   77,
343    77,   77,    0,   26,    0,   26,    0,    0,   26,   26,
344    26,   26,   26,   26,   26,   26,   14,    0,    0,   13,
345     0,    0,    0,    0,    0,    0,   26,   26,   26,   26,
346    26,   26,   12,    0,   12,    0,    0,   12,   12,   12,
347    12,   12,   12,   12,   12,   16,    0,    0,    0,   14,
348     0,    0,    0,    0,    0,   12,   12,   12,   12,   12,
349    12,    0,    9,    0,    9,    0,    0,    9,    9,    9,
350     9,    9,    9,    9,    9,    0,    0,    0,   16,    0,
351     0,    0,    0,    0,    0,    9,    9,    9,    9,    9,
352     9,    0,   10,    0,   10,    0,    0,   10,   10,   10,
353    10,   10,   10,   10,   10,    0,    0,   17,    0,    0,
354     0,    0,    0,    0,    0,   10,   10,   10,   10,   10,
355    10,    0,    0,   43,    0,    0,    8,    0,    8,    0,
356     0,    8,    8,    8,    8,    8,    8,    8,    8,    0,
357     0,    0,    0,    0,    0,    0,   41,    0,    0,    8,
358     8,    8,    8,    8,    8,   11,    0,   11,    0,    0,
359    11,   11,   11,   11,   11,   11,   11,   11,    0,   42,
360     0,    0,    0,   17,    0,    0,    0,    0,   11,   11,
361    11,   11,   11,   11,    7,    0,    7,    0,    0,    7,
362     7,    7,    7,    7,    7,    7,    7,   43,  108,   34,
363     0,    0,    0,    0,    0,    0,    0,    7,    7,    7,
364     7,    7,    7,   15,    0,   15,    0,    0,   15,   15,
365    15,   15,   15,   15,   15,   15,   17,    0,    0,    0,
366     0,    0,    0,    0,    0,    0,   15,   15,   15,   15,
367    15,   15,   13,    0,   13,    0,    0,   13,   13,   13,
368    13,   13,   13,   13,   13,    0,    0,    0,    0,    0,
369     0,    0,    0,    0,    0,   13,   13,   13,   13,   13,
370    13,    0,   14,    0,   14,    0,    0,   14,   14,   14,
371    14,   14,   14,   14,   14,    0,    0,    0,    0,    0,
372     0,    0,    0,    0,    0,   14,   14,   14,   14,   14,
373    14,   16,    0,   16,    0,    0,   16,   16,   16,   16,
374    16,   16,   16,   16,    0,    0,    0,    0,    0,    0,
375     0,    0,    0,    0,   16,   16,   16,   16,   16,   16,
376     1,    0,    2,    0,    0,    3,    4,    5,    6,    7,
377     8,    9,   10,    0,    0,    0,    0,   40,   41,    0,
378     0,    0,    0,   11,   12,   13,   14,   15,   16,  137,
379   138,  139,  140,  141,  142,  143,  144,  145,  146,   42,
380    41,   41,    0,    0,    0,    0,    0,    0,    0,    0,
381     0,    0,   41,   41,   41,   41,   41,   41,   41,   41,
382    41,   41,   41,   42,   42,    0,    0,    0,    2,    0,
383     0,    3,    4,    5,    0,   42,   42,   42,   42,   42,
384    42,   42,   42,   42,   42,   42,    0,    0,    0,   11,
385     0,   43,   43,    0,   29,    0,   30,   31,    0,   32,
386     0,    0,    0,   43,   43,   43,   43,   43,   43,   43,
387    43,   43,   43,   43,    0,   33,    0,    0,    0,    0,
388     0,    2,    0,    0,    3,    4,    5,    0,    0,    0,
389     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
390     0,    0,   11,
391 };
392 #if defined(__cplusplus) || defined(__STDC__)
393 const short yycheck[] =
394 #else
395 short yycheck[] =
396 #endif
397         {                                      33,
398     0,   33,   33,   33,    8,    9,   33,   33,    7,  280,
399    44,   76,   44,   44,  257,  258,  258,  258,   44,  261,
400   262,  263,  258,   44,  260,  261,  258,  263,   44,    0,
401    33,  263,   43,   33,   45,  258,  279,  279,  286,  287,
402    61,  258,   58,  279,   44,  258,   36,  279,   38,   39,
403    61,  259,   44,   61,   61,   61,   46,  263,    0,   61,
404    58,   58,   33,   58,  129,   58,  263,   58,  263,   44,
405    40,   44,   44,   41,   61,   44,   61,  286,   82,   78,
406    84,   44,  287,  263,  263,   41,    0,   58,    0,    0,
407    41,   33,   41,  111,   80,   69,   43,   34,   60,  103,
408    17,  120,  124,  116,   71,  133,   88,   85,   -1,   22,
409   115,   -1,   -1,   79,   -1,   -1,   58,    0,   33,   83,
410    81,   33,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
411    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
412    -1,   -1,   -1,   -1,   -1,   -1,   58,    0,   -1,   -1,
413    33,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
414    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
415    -1,   -1,   -1,   -1,   -1,   58,    0,   -1,   -1,   -1,
416    33,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
417    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
418    -1,   -1,   -1,   -1,   -1,   58,    0,   -1,   -1,   33,
419    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
420    -1,   -1,   -1,   -1,   -1,  259,   -1,  259,  259,  259,
421   257,  258,  258,   -1,  260,  261,    0,  263,   -1,   33,
422    -1,   -1,  269,  270,  271,  272,  273,  274,  275,  276,
423   277,  278,  279,  279,  257,  258,  256,   -1,  258,  286,
424   287,  261,  262,  263,  264,  265,  266,  267,  268,   33,
425     0,   -1,   -1,   -1,   -1,   -1,  279,   -1,   -1,  279,
426   280,  281,  282,  283,  284,  256,   -1,  258,   -1,   -1,
427   261,  262,  263,  264,  265,  266,  267,  268,   -1,    0,
428    -1,   -1,   -1,   33,   -1,   -1,   -1,   -1,  279,  280,
429   281,  282,  283,  284,  256,   -1,  258,   -1,   -1,  261,
430   262,  263,  264,  265,  266,  267,  268,   -1,    0,   -1,
431    -1,   -1,   33,   -1,   -1,   -1,   -1,  279,  280,  281,
432   282,  283,  284,  258,  256,   -1,  258,   -1,  263,  261,
433   262,  263,  264,  265,  266,  267,  268,    0,   -1,   -1,
434    -1,   33,   -1,   -1,  279,   -1,   -1,  279,  280,  281,
435   282,  283,  284,  256,   -1,  258,   -1,   -1,  261,  262,
436   263,  264,  265,  266,  267,  268,    0,   -1,   -1,   -1,
437    33,   -1,   -1,   -1,   -1,   -1,  279,  280,  281,  282,
438   283,  284,   -1,  256,   -1,  258,   -1,   -1,  261,  262,
439   263,  264,  265,  266,  267,  268,    0,   -1,   -1,   33,
440    -1,   -1,   -1,   -1,   -1,   -1,  279,  280,  281,  282,
441   283,  284,  256,   -1,  258,   -1,   -1,  261,  262,  263,
442   264,  265,  266,  267,  268,    0,   -1,   -1,   -1,   33,
443    -1,   -1,   -1,   -1,   -1,  279,  280,  281,  282,  283,
444   284,   -1,  256,   -1,  258,   -1,   -1,  261,  262,  263,
445   264,  265,  266,  267,  268,   -1,   -1,   -1,   33,   -1,
446    -1,   -1,   -1,   -1,   -1,  279,  280,  281,  282,  283,
447   284,   -1,  256,   -1,  258,   -1,   -1,  261,  262,  263,
448   264,  265,  266,  267,  268,   -1,   -1,   33,   -1,   -1,
449    -1,   -1,   -1,   -1,   -1,  279,  280,  281,  282,  283,
450   284,   -1,   -1,   33,   -1,   -1,  256,   -1,  258,   -1,
451    -1,  261,  262,  263,  264,  265,  266,  267,  268,   -1,
452    -1,   -1,   -1,   -1,   -1,   -1,   33,   -1,   -1,  279,
453   280,  281,  282,  283,  284,  256,   -1,  258,   -1,   -1,
454   261,  262,  263,  264,  265,  266,  267,  268,   -1,   33,
455    -1,   -1,   -1,   33,   -1,   -1,   -1,   -1,  279,  280,
456   281,  282,  283,  284,  256,   -1,  258,   -1,   -1,  261,
457   262,  263,  264,  265,  266,  267,  268,   33,   58,   33,
458    -1,   -1,   -1,   -1,   -1,   -1,   -1,  279,  280,  281,
459   282,  283,  284,  256,   -1,  258,   -1,   -1,  261,  262,
460   263,  264,  265,  266,  267,  268,   33,   -1,   -1,   -1,
461    -1,   -1,   -1,   -1,   -1,   -1,  279,  280,  281,  282,
462   283,  284,  256,   -1,  258,   -1,   -1,  261,  262,  263,
463   264,  265,  266,  267,  268,   -1,   -1,   -1,   -1,   -1,
464    -1,   -1,   -1,   -1,   -1,  279,  280,  281,  282,  283,
465   284,   -1,  256,   -1,  258,   -1,   -1,  261,  262,  263,
466   264,  265,  266,  267,  268,   -1,   -1,   -1,   -1,   -1,
467    -1,   -1,   -1,   -1,   -1,  279,  280,  281,  282,  283,
468   284,  256,   -1,  258,   -1,   -1,  261,  262,  263,  264,
469   265,  266,  267,  268,   -1,   -1,   -1,   -1,   -1,   -1,
470    -1,   -1,   -1,   -1,  279,  280,  281,  282,  283,  284,
471   256,   -1,  258,   -1,   -1,  261,  262,  263,  264,  265,
472   266,  267,  268,   -1,   -1,   -1,   -1,  257,  258,   -1,
473    -1,   -1,   -1,  279,  280,  281,  282,  283,  284,  269,
474   270,  271,  272,  273,  274,  275,  276,  277,  278,  279,
475   257,  258,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
476    -1,   -1,  269,  270,  271,  272,  273,  274,  275,  276,
477   277,  278,  279,  257,  258,   -1,   -1,   -1,  258,   -1,
478    -1,  261,  262,  263,   -1,  269,  270,  271,  272,  273,
479   274,  275,  276,  277,  278,  279,   -1,   -1,   -1,  279,
480    -1,  257,  258,   -1,  258,   -1,  260,  261,   -1,  263,
481    -1,   -1,   -1,  269,  270,  271,  272,  273,  274,  275,
482   276,  277,  278,  279,   -1,  279,   -1,   -1,   -1,   -1,
483    -1,  258,   -1,   -1,  261,  262,  263,   -1,   -1,   -1,
484    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
485    -1,   -1,  279,
486 };
487 #define YYFINAL 18
488 #ifndef YYDEBUG
489 #define YYDEBUG 0
490 #endif
491 #define YYMAXTOKEN 287
492 #if YYDEBUG
493 #if defined(__cplusplus) || defined(__STDC__)
494 const char * const yyname[] =
495 #else
496 char *yyname[] =
497 #endif
498         {
499 "end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
500 "'!'",0,0,0,0,0,0,"'('","')'",0,"'+'","','","'-'",0,0,0,0,0,0,0,0,0,0,0,0,"':'",
501 0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
502 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
503 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
504 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
505 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
506 "COMMAND","ALIAS","DEFVAR","NTWKADDR","NETGROUP","USERGROUP","WORD","DEFAULTS",
507 "DEFAULTS_HOST","DEFAULTS_USER","DEFAULTS_RUNAS","DEFAULTS_CMND","NOPASSWD",
508 "PASSWD","NOEXEC","EXEC","SETENV","NOSETENV","LOG_INPUT","NOLOG_INPUT",
509 "LOG_OUTPUT","NOLOG_OUTPUT","ALL","COMMENT","HOSTALIAS","CMNDALIAS","USERALIAS",
510 "RUNASALIAS","ERROR","TYPE","ROLE",
511 };
512 #if defined(__cplusplus) || defined(__STDC__)
513 const char * const yyrule[] =
514 #else
515 char *yyrule[] =
516 #endif
517         {"$accept : file",
518 "file :",
519 "file : line",
520 "line : entry",
521 "line : line entry",
522 "entry : COMMENT",
523 "entry : error COMMENT",
524 "entry : userlist privileges",
525 "entry : USERALIAS useraliases",
526 "entry : HOSTALIAS hostaliases",
527 "entry : CMNDALIAS cmndaliases",
528 "entry : RUNASALIAS runasaliases",
529 "entry : DEFAULTS defaults_list",
530 "entry : DEFAULTS_USER userlist defaults_list",
531 "entry : DEFAULTS_RUNAS userlist defaults_list",
532 "entry : DEFAULTS_HOST hostlist defaults_list",
533 "entry : DEFAULTS_CMND cmndlist defaults_list",
534 "defaults_list : defaults_entry",
535 "defaults_list : defaults_list ',' defaults_entry",
536 "defaults_entry : DEFVAR",
537 "defaults_entry : '!' DEFVAR",
538 "defaults_entry : DEFVAR '=' WORD",
539 "defaults_entry : DEFVAR '+' WORD",
540 "defaults_entry : DEFVAR '-' WORD",
541 "privileges : privilege",
542 "privileges : privileges ':' privilege",
543 "privilege : hostlist '=' cmndspeclist",
544 "ophost : host",
545 "ophost : '!' host",
546 "host : ALIAS",
547 "host : ALL",
548 "host : NETGROUP",
549 "host : NTWKADDR",
550 "host : WORD",
551 "cmndspeclist : cmndspec",
552 "cmndspeclist : cmndspeclist ',' cmndspec",
553 "cmndspec : runasspec selinux cmndtag opcmnd",
554 "opcmnd : cmnd",
555 "opcmnd : '!' cmnd",
556 "rolespec : ROLE '=' WORD",
557 "typespec : TYPE '=' WORD",
558 "selinux :",
559 "selinux : rolespec",
560 "selinux : typespec",
561 "selinux : rolespec typespec",
562 "selinux : typespec rolespec",
563 "runasspec :",
564 "runasspec : '(' runaslist ')'",
565 "runaslist : userlist",
566 "runaslist : userlist ':' grouplist",
567 "runaslist : ':' grouplist",
568 "cmndtag :",
569 "cmndtag : cmndtag NOPASSWD",
570 "cmndtag : cmndtag PASSWD",
571 "cmndtag : cmndtag NOEXEC",
572 "cmndtag : cmndtag EXEC",
573 "cmndtag : cmndtag SETENV",
574 "cmndtag : cmndtag NOSETENV",
575 "cmndtag : cmndtag LOG_INPUT",
576 "cmndtag : cmndtag NOLOG_INPUT",
577 "cmndtag : cmndtag LOG_OUTPUT",
578 "cmndtag : cmndtag NOLOG_OUTPUT",
579 "cmnd : ALL",
580 "cmnd : ALIAS",
581 "cmnd : COMMAND",
582 "hostaliases : hostalias",
583 "hostaliases : hostaliases ':' hostalias",
584 "hostalias : ALIAS '=' hostlist",
585 "hostlist : ophost",
586 "hostlist : hostlist ',' ophost",
587 "cmndaliases : cmndalias",
588 "cmndaliases : cmndaliases ':' cmndalias",
589 "cmndalias : ALIAS '=' cmndlist",
590 "cmndlist : opcmnd",
591 "cmndlist : cmndlist ',' opcmnd",
592 "runasaliases : runasalias",
593 "runasaliases : runasaliases ':' runasalias",
594 "runasalias : ALIAS '=' userlist",
595 "useraliases : useralias",
596 "useraliases : useraliases ':' useralias",
597 "useralias : ALIAS '=' userlist",
598 "userlist : opuser",
599 "userlist : userlist ',' opuser",
600 "opuser : user",
601 "opuser : '!' user",
602 "user : ALIAS",
603 "user : ALL",
604 "user : NETGROUP",
605 "user : USERGROUP",
606 "user : WORD",
607 "grouplist : opgroup",
608 "grouplist : grouplist ',' opgroup",
609 "opgroup : group",
610 "opgroup : '!' group",
611 "group : ALIAS",
612 "group : ALL",
613 "group : WORD",
614 };
615 #endif
616 #ifdef YYSTACKSIZE
617 #undef YYMAXDEPTH
618 #define YYMAXDEPTH YYSTACKSIZE
619 #else
620 #ifdef YYMAXDEPTH
621 #define YYSTACKSIZE YYMAXDEPTH
622 #else
623 #define YYSTACKSIZE 10000
624 #define YYMAXDEPTH 10000
625 #endif
626 #endif
627 #define YYINITSTACKSIZE 200
628 /* LINTUSED */
629 int yydebug;
630 int yynerrs;
631 int yyerrflag;
632 int yychar;
633 short *yyssp;
634 YYSTYPE *yyvsp;
635 YYSTYPE yyval;
636 YYSTYPE yylval;
637 short *yyss;
638 short *yysslim;
639 YYSTYPE *yyvs;
640 int yystacksize;
641 #line 611 "gram.y"
642 static struct defaults *
643 new_default(char *var, char *val, int op)
644 {
645     struct defaults *d;
646     debug_decl(new_default, SUDO_DEBUG_PARSER)
647
648     d = emalloc(sizeof(struct defaults));
649     d->var = var;
650     d->val = val;
651     tq_init(&d->binding);
652     d->type = 0;
653     d->op = op;
654     d->prev = d;
655     d->next = NULL;
656
657     debug_return_ptr(d);
658 }
659
660 static struct member *
661 new_member(char *name, int type)
662 {
663     struct member *m;
664     debug_decl(new_member, SUDO_DEBUG_PARSER)
665
666     m = emalloc(sizeof(struct member));
667     m->name = name;
668     m->type = type;
669     m->prev = m;
670     m->next = NULL;
671
672     debug_return_ptr(m);
673 }
674
675 /*
676  * Add a list of defaults structures to the defaults list.
677  * The binding, if non-NULL, specifies a list of hosts, users, or
678  * runas users the entries apply to (specified by the type).
679  */
680 static void
681 add_defaults(int type, struct member *bmem, struct defaults *defs)
682 {
683     struct defaults *d;
684     struct member_list binding;
685     debug_decl(add_defaults, SUDO_DEBUG_PARSER)
686
687     /*
688      * We can only call list2tq once on bmem as it will zero
689      * out the prev pointer when it consumes bmem.
690      */
691     list2tq(&binding, bmem);
692
693     /*
694      * Set type and binding (who it applies to) for new entries.
695      */
696     for (d = defs; d != NULL; d = d->next) {
697         d->type = type;
698         d->binding = binding;
699     }
700     tq_append(&defaults, defs);
701
702     debug_return;
703 }
704
705 /*
706  * Allocate a new struct userspec, populate it, and insert it at the
707  * and of the userspecs list.
708  */
709 static void
710 add_userspec(struct member *members, struct privilege *privs)
711 {
712     struct userspec *u;
713     debug_decl(add_userspec, SUDO_DEBUG_PARSER)
714
715     u = emalloc(sizeof(*u));
716     list2tq(&u->users, members);
717     list2tq(&u->privileges, privs);
718     u->prev = u;
719     u->next = NULL;
720     tq_append(&userspecs, u);
721
722     debug_return;
723 }
724
725 /*
726  * Free up space used by data structures from a previous parser run and sets
727  * the current sudoers file to path.
728  */
729 void
730 init_parser(const char *path, int quiet)
731 {
732     struct defaults *d;
733     struct member *m, *binding;
734     struct userspec *us;
735     struct privilege *priv;
736     struct cmndspec *cs;
737     struct sudo_command *c;
738     debug_decl(init_parser, SUDO_DEBUG_PARSER)
739
740     while ((us = tq_pop(&userspecs)) != NULL) {
741         while ((m = tq_pop(&us->users)) != NULL) {
742             efree(m->name);
743             efree(m);
744         }
745         while ((priv = tq_pop(&us->privileges)) != NULL) {
746             struct member *runasuser = NULL, *runasgroup = NULL;
747 #ifdef HAVE_SELINUX
748             char *role = NULL, *type = NULL;
749 #endif /* HAVE_SELINUX */
750
751             while ((m = tq_pop(&priv->hostlist)) != NULL) {
752                 efree(m->name);
753                 efree(m);
754             }
755             while ((cs = tq_pop(&priv->cmndlist)) != NULL) {
756 #ifdef HAVE_SELINUX
757                 /* Only free the first instance of a role/type. */
758                 if (cs->role != role) {
759                     role = cs->role;
760                     efree(cs->role);
761                 }
762                 if (cs->type != type) {
763                     type = cs->type;
764                     efree(cs->type);
765                 }
766 #endif /* HAVE_SELINUX */
767                 if (tq_last(&cs->runasuserlist) != runasuser) {
768                     runasuser = tq_last(&cs->runasuserlist);
769                     while ((m = tq_pop(&cs->runasuserlist)) != NULL) {
770                         efree(m->name);
771                         efree(m);
772                     }
773                 }
774                 if (tq_last(&cs->runasgrouplist) != runasgroup) {
775                     runasgroup = tq_last(&cs->runasgrouplist);
776                     while ((m = tq_pop(&cs->runasgrouplist)) != NULL) {
777                         efree(m->name);
778                         efree(m);
779                     }
780                 }
781                 if (cs->cmnd->type == COMMAND) {
782                         c = (struct sudo_command *) cs->cmnd->name;
783                         efree(c->cmnd);
784                         efree(c->args);
785                 }
786                 efree(cs->cmnd->name);
787                 efree(cs->cmnd);
788                 efree(cs);
789             }
790             efree(priv);
791         }
792         efree(us);
793     }
794     tq_init(&userspecs);
795
796     binding = NULL;
797     while ((d = tq_pop(&defaults)) != NULL) {
798         if (tq_last(&d->binding) != binding) {
799             binding = tq_last(&d->binding);
800             while ((m = tq_pop(&d->binding)) != NULL) {
801                 if (m->type == COMMAND) {
802                         c = (struct sudo_command *) m->name;
803                         efree(c->cmnd);
804                         efree(c->args);
805                 }
806                 efree(m->name);
807                 efree(m);
808             }
809         }
810         efree(d->var);
811         efree(d->val);
812         efree(d);
813     }
814     tq_init(&defaults);
815
816     init_aliases();
817
818     init_lexer();
819
820     efree(sudoers);
821     sudoers = path ? estrdup(path) : NULL;
822
823     parse_error = false;
824     errorlineno = -1;
825     errorfile = sudoers;
826     verbose = !quiet;
827
828     debug_return;
829 }
830 #line 778 "gram.c"
831 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
832 #if defined(__cplusplus) || defined(__STDC__)
833 static int yygrowstack(void)
834 #else
835 static int yygrowstack()
836 #endif
837 {
838     int newsize, i;
839     short *newss;
840     YYSTYPE *newvs;
841
842     if ((newsize = yystacksize) == 0)
843         newsize = YYINITSTACKSIZE;
844     else if (newsize >= YYMAXDEPTH)
845         return -1;
846     else if ((newsize *= 2) > YYMAXDEPTH)
847         newsize = YYMAXDEPTH;
848     i = yyssp - yyss;
849 #ifdef SIZE_MAX
850 #define YY_SIZE_MAX SIZE_MAX
851 #else
852 #define YY_SIZE_MAX 0x7fffffff
853 #endif
854     if (newsize && YY_SIZE_MAX / newsize < sizeof *newss)
855         goto bail;
856     newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :
857       (short *)malloc(newsize * sizeof *newss); /* overflow check above */
858     if (newss == NULL)
859         goto bail;
860     yyss = newss;
861     yyssp = newss + i;
862     if (newsize && YY_SIZE_MAX / newsize < sizeof *newvs)
863         goto bail;
864     newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :
865       (YYSTYPE *)malloc(newsize * sizeof *newvs); /* overflow check above */
866     if (newvs == NULL)
867         goto bail;
868     yyvs = newvs;
869     yyvsp = newvs + i;
870     yystacksize = newsize;
871     yysslim = yyss + newsize - 1;
872     return 0;
873 bail:
874     if (yyss)
875             free(yyss);
876     if (yyvs)
877             free(yyvs);
878     yyss = yyssp = NULL;
879     yyvs = yyvsp = NULL;
880     yystacksize = 0;
881     return -1;
882 }
883
884 #define YYABORT goto yyabort
885 #define YYREJECT goto yyabort
886 #define YYACCEPT goto yyaccept
887 #define YYERROR goto yyerrlab
888 int
889 #if defined(__cplusplus) || defined(__STDC__)
890 yyparse(void)
891 #else
892 yyparse()
893 #endif
894 {
895     int yym, yyn, yystate;
896 #if YYDEBUG
897 #if defined(__cplusplus) || defined(__STDC__)
898     const char *yys;
899 #else /* !(defined(__cplusplus) || defined(__STDC__)) */
900     char *yys;
901 #endif /* !(defined(__cplusplus) || defined(__STDC__)) */
902
903     if ((yys = getenv("YYDEBUG")))
904     {
905         yyn = *yys;
906         if (yyn >= '0' && yyn <= '9')
907             yydebug = yyn - '0';
908     }
909 #endif /* YYDEBUG */
910
911     yynerrs = 0;
912     yyerrflag = 0;
913     yychar = (-1);
914
915     if (yyss == NULL && yygrowstack()) goto yyoverflow;
916     yyssp = yyss;
917     yyvsp = yyvs;
918     *yyssp = yystate = 0;
919
920 yyloop:
921     if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
922     if (yychar < 0)
923     {
924         if ((yychar = yylex()) < 0) yychar = 0;
925 #if YYDEBUG
926         if (yydebug)
927         {
928             yys = 0;
929             if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
930             if (!yys) yys = "illegal-symbol";
931             printf("%sdebug: state %d, reading %d (%s)\n",
932                     YYPREFIX, yystate, yychar, yys);
933         }
934 #endif
935     }
936     if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
937             yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
938     {
939 #if YYDEBUG
940         if (yydebug)
941             printf("%sdebug: state %d, shifting to state %d\n",
942                     YYPREFIX, yystate, yytable[yyn]);
943 #endif
944         if (yyssp >= yysslim && yygrowstack())
945         {
946             goto yyoverflow;
947         }
948         *++yyssp = yystate = yytable[yyn];
949         *++yyvsp = yylval;
950         yychar = (-1);
951         if (yyerrflag > 0)  --yyerrflag;
952         goto yyloop;
953     }
954     if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
955             yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
956     {
957         yyn = yytable[yyn];
958         goto yyreduce;
959     }
960     if (yyerrflag) goto yyinrecovery;
961 #if defined(lint) || defined(__GNUC__)
962     goto yynewerror;
963 #endif
964 yynewerror:
965     yyerror("syntax error");
966 #if defined(lint) || defined(__GNUC__)
967     goto yyerrlab;
968 #endif
969 yyerrlab:
970     ++yynerrs;
971 yyinrecovery:
972     if (yyerrflag < 3)
973     {
974         yyerrflag = 3;
975         for (;;)
976         {
977             if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
978                     yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
979             {
980 #if YYDEBUG
981                 if (yydebug)
982                     printf("%sdebug: state %d, error recovery shifting\
983  to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
984 #endif
985                 if (yyssp >= yysslim && yygrowstack())
986                 {
987                     goto yyoverflow;
988                 }
989                 *++yyssp = yystate = yytable[yyn];
990                 *++yyvsp = yylval;
991                 goto yyloop;
992             }
993             else
994             {
995 #if YYDEBUG
996                 if (yydebug)
997                     printf("%sdebug: error recovery discarding state %d\n",
998                             YYPREFIX, *yyssp);
999 #endif
1000                 if (yyssp <= yyss) goto yyabort;
1001                 --yyssp;
1002                 --yyvsp;
1003             }
1004         }
1005     }
1006     else
1007     {
1008         if (yychar == 0) goto yyabort;
1009 #if YYDEBUG
1010         if (yydebug)
1011         {
1012             yys = 0;
1013             if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1014             if (!yys) yys = "illegal-symbol";
1015             printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
1016                     YYPREFIX, yystate, yychar, yys);
1017         }
1018 #endif
1019         yychar = (-1);
1020         goto yyloop;
1021     }
1022 yyreduce:
1023 #if YYDEBUG
1024     if (yydebug)
1025         printf("%sdebug: state %d, reducing by rule %d (%s)\n",
1026                 YYPREFIX, yystate, yyn, yyrule[yyn]);
1027 #endif
1028     yym = yylen[yyn];
1029     if (yym)
1030         yyval = yyvsp[1-yym];
1031     else
1032         memset(&yyval, 0, sizeof yyval);
1033     switch (yyn)
1034     {
1035 case 1:
1036 #line 192 "gram.y"
1037 { ; }
1038 break;
1039 case 5:
1040 #line 200 "gram.y"
1041 {
1042                             ;
1043                         }
1044 break;
1045 case 6:
1046 #line 203 "gram.y"
1047 {
1048                             yyerrok;
1049                         }
1050 break;
1051 case 7:
1052 #line 206 "gram.y"
1053 {
1054                             add_userspec(yyvsp[-1].member, yyvsp[0].privilege);
1055                         }
1056 break;
1057 case 8:
1058 #line 209 "gram.y"
1059 {
1060                             ;
1061                         }
1062 break;
1063 case 9:
1064 #line 212 "gram.y"
1065 {
1066                             ;
1067                         }
1068 break;
1069 case 10:
1070 #line 215 "gram.y"
1071 {
1072                             ;
1073                         }
1074 break;
1075 case 11:
1076 #line 218 "gram.y"
1077 {
1078                             ;
1079                         }
1080 break;
1081 case 12:
1082 #line 221 "gram.y"
1083 {
1084                             add_defaults(DEFAULTS, NULL, yyvsp[0].defaults);
1085                         }
1086 break;
1087 case 13:
1088 #line 224 "gram.y"
1089 {
1090                             add_defaults(DEFAULTS_USER, yyvsp[-1].member, yyvsp[0].defaults);
1091                         }
1092 break;
1093 case 14:
1094 #line 227 "gram.y"
1095 {
1096                             add_defaults(DEFAULTS_RUNAS, yyvsp[-1].member, yyvsp[0].defaults);
1097                         }
1098 break;
1099 case 15:
1100 #line 230 "gram.y"
1101 {
1102                             add_defaults(DEFAULTS_HOST, yyvsp[-1].member, yyvsp[0].defaults);
1103                         }
1104 break;
1105 case 16:
1106 #line 233 "gram.y"
1107 {
1108                             add_defaults(DEFAULTS_CMND, yyvsp[-1].member, yyvsp[0].defaults);
1109                         }
1110 break;
1111 case 18:
1112 #line 239 "gram.y"
1113 {
1114                             list_append(yyvsp[-2].defaults, yyvsp[0].defaults);
1115                             yyval.defaults = yyvsp[-2].defaults;
1116                         }
1117 break;
1118 case 19:
1119 #line 245 "gram.y"
1120 {
1121                             yyval.defaults = new_default(yyvsp[0].string, NULL, true);
1122                         }
1123 break;
1124 case 20:
1125 #line 248 "gram.y"
1126 {
1127                             yyval.defaults = new_default(yyvsp[0].string, NULL, false);
1128                         }
1129 break;
1130 case 21:
1131 #line 251 "gram.y"
1132 {
1133                             yyval.defaults = new_default(yyvsp[-2].string, yyvsp[0].string, true);
1134                         }
1135 break;
1136 case 22:
1137 #line 254 "gram.y"
1138 {
1139                             yyval.defaults = new_default(yyvsp[-2].string, yyvsp[0].string, '+');
1140                         }
1141 break;
1142 case 23:
1143 #line 257 "gram.y"
1144 {
1145                             yyval.defaults = new_default(yyvsp[-2].string, yyvsp[0].string, '-');
1146                         }
1147 break;
1148 case 25:
1149 #line 263 "gram.y"
1150 {
1151                             list_append(yyvsp[-2].privilege, yyvsp[0].privilege);
1152                             yyval.privilege = yyvsp[-2].privilege;
1153                         }
1154 break;
1155 case 26:
1156 #line 269 "gram.y"
1157 {
1158                             struct privilege *p = emalloc(sizeof(*p));
1159                             list2tq(&p->hostlist, yyvsp[-2].member);
1160                             list2tq(&p->cmndlist, yyvsp[0].cmndspec);
1161                             p->prev = p;
1162                             p->next = NULL;
1163                             yyval.privilege = p;
1164                         }
1165 break;
1166 case 27:
1167 #line 279 "gram.y"
1168 {
1169                             yyval.member = yyvsp[0].member;
1170                             yyval.member->negated = false;
1171                         }
1172 break;
1173 case 28:
1174 #line 283 "gram.y"
1175 {
1176                             yyval.member = yyvsp[0].member;
1177                             yyval.member->negated = true;
1178                         }
1179 break;
1180 case 29:
1181 #line 289 "gram.y"
1182 {
1183                             yyval.member = new_member(yyvsp[0].string, ALIAS);
1184                         }
1185 break;
1186 case 30:
1187 #line 292 "gram.y"
1188 {
1189                             yyval.member = new_member(NULL, ALL);
1190                         }
1191 break;
1192 case 31:
1193 #line 295 "gram.y"
1194 {
1195                             yyval.member = new_member(yyvsp[0].string, NETGROUP);
1196                         }
1197 break;
1198 case 32:
1199 #line 298 "gram.y"
1200 {
1201                             yyval.member = new_member(yyvsp[0].string, NTWKADDR);
1202                         }
1203 break;
1204 case 33:
1205 #line 301 "gram.y"
1206 {
1207                             yyval.member = new_member(yyvsp[0].string, WORD);
1208                         }
1209 break;
1210 case 35:
1211 #line 307 "gram.y"
1212 {
1213                             list_append(yyvsp[-2].cmndspec, yyvsp[0].cmndspec);
1214 #ifdef HAVE_SELINUX
1215                             /* propagate role and type */
1216                             if (yyvsp[0].cmndspec->role == NULL)
1217                                 yyvsp[0].cmndspec->role = yyvsp[0].cmndspec->prev->role;
1218                             if (yyvsp[0].cmndspec->type == NULL)
1219                                 yyvsp[0].cmndspec->type = yyvsp[0].cmndspec->prev->type;
1220 #endif /* HAVE_SELINUX */
1221                             /* propagate tags and runas list */
1222                             if (yyvsp[0].cmndspec->tags.nopasswd == UNSPEC)
1223                                 yyvsp[0].cmndspec->tags.nopasswd = yyvsp[0].cmndspec->prev->tags.nopasswd;
1224                             if (yyvsp[0].cmndspec->tags.noexec == UNSPEC)
1225                                 yyvsp[0].cmndspec->tags.noexec = yyvsp[0].cmndspec->prev->tags.noexec;
1226                             if (yyvsp[0].cmndspec->tags.setenv == UNSPEC &&
1227                                 yyvsp[0].cmndspec->prev->tags.setenv != IMPLIED)
1228                                 yyvsp[0].cmndspec->tags.setenv = yyvsp[0].cmndspec->prev->tags.setenv;
1229                             if (yyvsp[0].cmndspec->tags.log_input == UNSPEC)
1230                                 yyvsp[0].cmndspec->tags.log_input = yyvsp[0].cmndspec->prev->tags.log_input;
1231                             if (yyvsp[0].cmndspec->tags.log_output == UNSPEC)
1232                                 yyvsp[0].cmndspec->tags.log_output = yyvsp[0].cmndspec->prev->tags.log_output;
1233                             if ((tq_empty(&yyvsp[0].cmndspec->runasuserlist) &&
1234                                  tq_empty(&yyvsp[0].cmndspec->runasgrouplist)) &&
1235                                 (!tq_empty(&yyvsp[0].cmndspec->prev->runasuserlist) ||
1236                                  !tq_empty(&yyvsp[0].cmndspec->prev->runasgrouplist))) {
1237                                 yyvsp[0].cmndspec->runasuserlist = yyvsp[0].cmndspec->prev->runasuserlist;
1238                                 yyvsp[0].cmndspec->runasgrouplist = yyvsp[0].cmndspec->prev->runasgrouplist;
1239                             }
1240                             yyval.cmndspec = yyvsp[-2].cmndspec;
1241                         }
1242 break;
1243 case 36:
1244 #line 339 "gram.y"
1245 {
1246                             struct cmndspec *cs = emalloc(sizeof(*cs));
1247                             if (yyvsp[-3].runas != NULL) {
1248                                 list2tq(&cs->runasuserlist, yyvsp[-3].runas->runasusers);
1249                                 list2tq(&cs->runasgrouplist, yyvsp[-3].runas->runasgroups);
1250                                 efree(yyvsp[-3].runas);
1251                             } else {
1252                                 tq_init(&cs->runasuserlist);
1253                                 tq_init(&cs->runasgrouplist);
1254                             }
1255 #ifdef HAVE_SELINUX
1256                             cs->role = yyvsp[-2].seinfo.role;
1257                             cs->type = yyvsp[-2].seinfo.type;
1258 #endif
1259                             cs->tags = yyvsp[-1].tag;
1260                             cs->cmnd = yyvsp[0].member;
1261                             cs->prev = cs;
1262                             cs->next = NULL;
1263                             /* sudo "ALL" implies the SETENV tag */
1264                             if (cs->cmnd->type == ALL && !cs->cmnd->negated &&
1265                                 cs->tags.setenv == UNSPEC)
1266                                 cs->tags.setenv = IMPLIED;
1267                             yyval.cmndspec = cs;
1268                         }
1269 break;
1270 case 37:
1271 #line 365 "gram.y"
1272 {
1273                             yyval.member = yyvsp[0].member;
1274                             yyval.member->negated = false;
1275                         }
1276 break;
1277 case 38:
1278 #line 369 "gram.y"
1279 {
1280                             yyval.member = yyvsp[0].member;
1281                             yyval.member->negated = true;
1282                         }
1283 break;
1284 case 39:
1285 #line 375 "gram.y"
1286 {
1287                             yyval.string = yyvsp[0].string;
1288                         }
1289 break;
1290 case 40:
1291 #line 380 "gram.y"
1292 {
1293                             yyval.string = yyvsp[0].string;
1294                         }
1295 break;
1296 case 41:
1297 #line 385 "gram.y"
1298 {
1299                             yyval.seinfo.role = NULL;
1300                             yyval.seinfo.type = NULL;
1301                         }
1302 break;
1303 case 42:
1304 #line 389 "gram.y"
1305 {
1306                             yyval.seinfo.role = yyvsp[0].string;
1307                             yyval.seinfo.type = NULL;
1308                         }
1309 break;
1310 case 43:
1311 #line 393 "gram.y"
1312 {
1313                             yyval.seinfo.type = yyvsp[0].string;
1314                             yyval.seinfo.role = NULL;
1315                         }
1316 break;
1317 case 44:
1318 #line 397 "gram.y"
1319 {
1320                             yyval.seinfo.role = yyvsp[-1].string;
1321                             yyval.seinfo.type = yyvsp[0].string;
1322                         }
1323 break;
1324 case 45:
1325 #line 401 "gram.y"
1326 {
1327                             yyval.seinfo.type = yyvsp[-1].string;
1328                             yyval.seinfo.role = yyvsp[0].string;
1329                         }
1330 break;
1331 case 46:
1332 #line 407 "gram.y"
1333 {
1334                             yyval.runas = NULL;
1335                         }
1336 break;
1337 case 47:
1338 #line 410 "gram.y"
1339 {
1340                             yyval.runas = yyvsp[-1].runas;
1341                         }
1342 break;
1343 case 48:
1344 #line 415 "gram.y"
1345 {
1346                             yyval.runas = emalloc(sizeof(struct runascontainer));
1347                             yyval.runas->runasusers = yyvsp[0].member;
1348                             yyval.runas->runasgroups = NULL;
1349                         }
1350 break;
1351 case 49:
1352 #line 420 "gram.y"
1353 {
1354                             yyval.runas = emalloc(sizeof(struct runascontainer));
1355                             yyval.runas->runasusers = yyvsp[-2].member;
1356                             yyval.runas->runasgroups = yyvsp[0].member;
1357                         }
1358 break;
1359 case 50:
1360 #line 425 "gram.y"
1361 {
1362                             yyval.runas = emalloc(sizeof(struct runascontainer));
1363                             yyval.runas->runasusers = NULL;
1364                             yyval.runas->runasgroups = yyvsp[0].member;
1365                         }
1366 break;
1367 case 51:
1368 #line 432 "gram.y"
1369 {
1370                             yyval.tag.nopasswd = yyval.tag.noexec = yyval.tag.setenv =
1371                                 yyval.tag.log_input = yyval.tag.log_output = UNSPEC;
1372                         }
1373 break;
1374 case 52:
1375 #line 436 "gram.y"
1376 {
1377                             yyval.tag.nopasswd = true;
1378                         }
1379 break;
1380 case 53:
1381 #line 439 "gram.y"
1382 {
1383                             yyval.tag.nopasswd = false;
1384                         }
1385 break;
1386 case 54:
1387 #line 442 "gram.y"
1388 {
1389                             yyval.tag.noexec = true;
1390                         }
1391 break;
1392 case 55:
1393 #line 445 "gram.y"
1394 {
1395                             yyval.tag.noexec = false;
1396                         }
1397 break;
1398 case 56:
1399 #line 448 "gram.y"
1400 {
1401                             yyval.tag.setenv = true;
1402                         }
1403 break;
1404 case 57:
1405 #line 451 "gram.y"
1406 {
1407                             yyval.tag.setenv = false;
1408                         }
1409 break;
1410 case 58:
1411 #line 454 "gram.y"
1412 {
1413                             yyval.tag.log_input = true;
1414                         }
1415 break;
1416 case 59:
1417 #line 457 "gram.y"
1418 {
1419                             yyval.tag.log_input = false;
1420                         }
1421 break;
1422 case 60:
1423 #line 460 "gram.y"
1424 {
1425                             yyval.tag.log_output = true;
1426                         }
1427 break;
1428 case 61:
1429 #line 463 "gram.y"
1430 {
1431                             yyval.tag.log_output = false;
1432                         }
1433 break;
1434 case 62:
1435 #line 468 "gram.y"
1436 {
1437                             yyval.member = new_member(NULL, ALL);
1438                         }
1439 break;
1440 case 63:
1441 #line 471 "gram.y"
1442 {
1443                             yyval.member = new_member(yyvsp[0].string, ALIAS);
1444                         }
1445 break;
1446 case 64:
1447 #line 474 "gram.y"
1448 {
1449                             struct sudo_command *c = emalloc(sizeof(*c));
1450                             c->cmnd = yyvsp[0].command.cmnd;
1451                             c->args = yyvsp[0].command.args;
1452                             yyval.member = new_member((char *)c, COMMAND);
1453                         }
1454 break;
1455 case 67:
1456 #line 486 "gram.y"
1457 {
1458                             char *s;
1459                             if ((s = alias_add(yyvsp[-2].string, HOSTALIAS, yyvsp[0].member)) != NULL) {
1460                                 yyerror(s);
1461                                 YYERROR;
1462                             }
1463                         }
1464 break;
1465 case 69:
1466 #line 496 "gram.y"
1467 {
1468                             list_append(yyvsp[-2].member, yyvsp[0].member);
1469                             yyval.member = yyvsp[-2].member;
1470                         }
1471 break;
1472 case 72:
1473 #line 506 "gram.y"
1474 {
1475                             char *s;
1476                             if ((s = alias_add(yyvsp[-2].string, CMNDALIAS, yyvsp[0].member)) != NULL) {
1477                                 yyerror(s);
1478                                 YYERROR;
1479                             }
1480                         }
1481 break;
1482 case 74:
1483 #line 516 "gram.y"
1484 {
1485                             list_append(yyvsp[-2].member, yyvsp[0].member);
1486                             yyval.member = yyvsp[-2].member;
1487                         }
1488 break;
1489 case 77:
1490 #line 526 "gram.y"
1491 {
1492                             char *s;
1493                             if ((s = alias_add(yyvsp[-2].string, RUNASALIAS, yyvsp[0].member)) != NULL) {
1494                                 yyerror(s);
1495                                 YYERROR;
1496                             }
1497                         }
1498 break;
1499 case 80:
1500 #line 539 "gram.y"
1501 {
1502                             char *s;
1503                             if ((s = alias_add(yyvsp[-2].string, USERALIAS, yyvsp[0].member)) != NULL) {
1504                                 yyerror(s);
1505                                 YYERROR;
1506                             }
1507                         }
1508 break;
1509 case 82:
1510 #line 549 "gram.y"
1511 {
1512                             list_append(yyvsp[-2].member, yyvsp[0].member);
1513                             yyval.member = yyvsp[-2].member;
1514                         }
1515 break;
1516 case 83:
1517 #line 555 "gram.y"
1518 {
1519                             yyval.member = yyvsp[0].member;
1520                             yyval.member->negated = false;
1521                         }
1522 break;
1523 case 84:
1524 #line 559 "gram.y"
1525 {
1526                             yyval.member = yyvsp[0].member;
1527                             yyval.member->negated = true;
1528                         }
1529 break;
1530 case 85:
1531 #line 565 "gram.y"
1532 {
1533                             yyval.member = new_member(yyvsp[0].string, ALIAS);
1534                         }
1535 break;
1536 case 86:
1537 #line 568 "gram.y"
1538 {
1539                             yyval.member = new_member(NULL, ALL);
1540                         }
1541 break;
1542 case 87:
1543 #line 571 "gram.y"
1544 {
1545                             yyval.member = new_member(yyvsp[0].string, NETGROUP);
1546                         }
1547 break;
1548 case 88:
1549 #line 574 "gram.y"
1550 {
1551                             yyval.member = new_member(yyvsp[0].string, USERGROUP);
1552                         }
1553 break;
1554 case 89:
1555 #line 577 "gram.y"
1556 {
1557                             yyval.member = new_member(yyvsp[0].string, WORD);
1558                         }
1559 break;
1560 case 91:
1561 #line 583 "gram.y"
1562 {
1563                             list_append(yyvsp[-2].member, yyvsp[0].member);
1564                             yyval.member = yyvsp[-2].member;
1565                         }
1566 break;
1567 case 92:
1568 #line 589 "gram.y"
1569 {
1570                             yyval.member = yyvsp[0].member;
1571                             yyval.member->negated = false;
1572                         }
1573 break;
1574 case 93:
1575 #line 593 "gram.y"
1576 {
1577                             yyval.member = yyvsp[0].member;
1578                             yyval.member->negated = true;
1579                         }
1580 break;
1581 case 94:
1582 #line 599 "gram.y"
1583 {
1584                             yyval.member = new_member(yyvsp[0].string, ALIAS);
1585                         }
1586 break;
1587 case 95:
1588 #line 602 "gram.y"
1589 {
1590                             yyval.member = new_member(NULL, ALL);
1591                         }
1592 break;
1593 case 96:
1594 #line 605 "gram.y"
1595 {
1596                             yyval.member = new_member(yyvsp[0].string, WORD);
1597                         }
1598 break;
1599 #line 1547 "gram.c"
1600     }
1601     yyssp -= yym;
1602     yystate = *yyssp;
1603     yyvsp -= yym;
1604     yym = yylhs[yyn];
1605     if (yystate == 0 && yym == 0)
1606     {
1607 #if YYDEBUG
1608         if (yydebug)
1609             printf("%sdebug: after reduction, shifting from state 0 to\
1610  state %d\n", YYPREFIX, YYFINAL);
1611 #endif
1612         yystate = YYFINAL;
1613         *++yyssp = YYFINAL;
1614         *++yyvsp = yyval;
1615         if (yychar < 0)
1616         {
1617             if ((yychar = yylex()) < 0) yychar = 0;
1618 #if YYDEBUG
1619             if (yydebug)
1620             {
1621                 yys = 0;
1622                 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1623                 if (!yys) yys = "illegal-symbol";
1624                 printf("%sdebug: state %d, reading %d (%s)\n",
1625                         YYPREFIX, YYFINAL, yychar, yys);
1626             }
1627 #endif
1628         }
1629         if (yychar == 0) goto yyaccept;
1630         goto yyloop;
1631     }
1632     if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
1633             yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
1634         yystate = yytable[yyn];
1635     else
1636         yystate = yydgoto[yym];
1637 #if YYDEBUG
1638     if (yydebug)
1639         printf("%sdebug: after reduction, shifting from state %d \
1640 to state %d\n", YYPREFIX, *yyssp, yystate);
1641 #endif
1642     if (yyssp >= yysslim && yygrowstack())
1643     {
1644         goto yyoverflow;
1645     }
1646     *++yyssp = yystate;
1647     *++yyvsp = yyval;
1648     goto yyloop;
1649 yyoverflow:
1650     yyerror("yacc stack overflow");
1651 yyabort:
1652     if (yyss)
1653             free(yyss);
1654     if (yyvs)
1655             free(yyvs);
1656     yyss = yyssp = NULL;
1657     yyvs = yyvsp = NULL;
1658     yystacksize = 0;
1659     return (1);
1660 yyaccept:
1661     if (yyss)
1662             free(yyss);
1663     if (yyvs)
1664             free(yyvs);
1665     yyss = yyssp = NULL;
1666     yyvs = yyvsp = NULL;
1667     yystacksize = 0;
1668     return (0);
1669 }