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