fold in patch to sudo.pam to fix ldap usage, closing 607199
[debian/sudo] / gram.c
1 #include <stdlib.h>
2 #include <string.h>
3 #define YYBYACC 1
4 #define YYMAJOR 1
5 #define YYMINOR 9
6 #define YYLEX yylex()
7 #define YYEMPTY -1
8 #define yyclearin (yychar=(YYEMPTY))
9 #define yyerrok (yyerrflag=0)
10 #define YYRECOVERING() (yyerrflag!=0)
11 #define YYPREFIX "yy"
12 #line 2 "gram.y"
13 /*
14  * Copyright (c) 1996, 1998-2005, 2007-2010
15  *      Todd C. Miller <Todd.Miller@courtesan.com>
16  *
17  * Permission to use, copy, modify, and distribute this software for any
18  * purpose with or without fee is hereby granted, provided that the above
19  * copyright notice and this permission notice appear in all copies.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
22  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
23  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
24  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
25  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
26  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
27  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  * Sponsored in part by the Defense Advanced Research Projects
32  * Agency (DARPA) and Air Force Research Laboratory, Air Force
33  * Materiel Command, USAF, under agreement number F39502-99-1-0512.
34  */
35
36 #include <config.h>
37
38 #include <sys/types.h>
39 #include <sys/param.h>
40 #include <stdio.h>
41 #ifdef STDC_HEADERS
42 # include <stdlib.h>
43 # include <stddef.h>
44 #else
45 # ifdef HAVE_STDLIB_H
46 #  include <stdlib.h>
47 # endif
48 #endif /* STDC_HEADERS */
49 #ifdef HAVE_STRING_H
50 # include <string.h>
51 #endif /* HAVE_STRING_H */
52 #ifdef HAVE_STRINGS_H
53 # include <strings.h>
54 #endif /* HAVE_STRINGS_H */
55 #ifdef HAVE_UNISTD_H
56 # include <unistd.h>
57 #endif /* HAVE_UNISTD_H */
58 #if defined(YYBISON) && defined(HAVE_ALLOCA_H) && !defined(__GNUC__)
59 # include <alloca.h>
60 #endif /* YYBISON && HAVE_ALLOCA_H && !__GNUC__ */
61 #include <limits.h>
62
63 #include "sudo.h"
64 #include "parse.h"
65
66 /*
67  * We must define SIZE_MAX for yacc's skeleton.c.
68  * If there is no SIZE_MAX or SIZE_T_MAX we have to assume that size_t
69  * could be signed (as it is on SunOS 4.x).
70  */
71 #ifndef SIZE_MAX
72 # ifdef SIZE_T_MAX
73 #  define SIZE_MAX      SIZE_T_MAX
74 # else
75 #  define SIZE_MAX      INT_MAX
76 # endif /* SIZE_T_MAX */
77 #endif /* SIZE_MAX */
78
79 /*
80  * Globals
81  */
82 extern int sudolineno;
83 extern char *sudoers;
84 int parse_error;
85 int pedantic = FALSE;
86 int verbose = FALSE;
87 int errorlineno = -1;
88 char *errorfile = NULL;
89
90 struct defaults_list defaults;
91 struct userspec_list userspecs;
92
93 /*
94  * Local protoypes
95  */
96 static void  add_defaults       __P((int, struct member *, struct defaults *));
97 static void  add_userspec       __P((struct member *, struct privilege *));
98 static struct defaults *new_default __P((char *, char *, int));
99 static struct member *new_member __P((char *, int));
100        void  yyerror            __P((const char *));
101
102 void
103 yyerror(s)
104     const char *s;
105 {
106     /* Save the line the first error occurred on. */
107     if (errorlineno == -1) {
108         errorlineno = sudolineno ? sudolineno - 1 : 0;
109         errorfile = estrdup(sudoers);
110     }
111     if (verbose && s != NULL) {
112 #ifndef TRACELEXER
113         (void) fprintf(stderr, ">>> %s: %s near line %d <<<\n", sudoers, s,
114             sudolineno ? sudolineno - 1 : 0);
115 #else
116         (void) fprintf(stderr, "<*> ");
117 #endif
118     }
119     parse_error = TRUE;
120 }
121 #line 112 "gram.y"
122 #ifndef YYSTYPE_DEFINED
123 #define YYSTYPE_DEFINED
124 typedef union {
125     struct cmndspec *cmndspec;
126     struct defaults *defaults;
127     struct member *member;
128     struct runascontainer *runas;
129     struct privilege *privilege;
130     struct sudo_command command;
131     struct cmndtag tag;
132     struct selinux_info seinfo;
133     char *string;
134     int tok;
135 } YYSTYPE;
136 #endif /* YYSTYPE_DEFINED */
137 #line 138 "y.tab.c"
138 #define COMMAND 257
139 #define ALIAS 258
140 #define DEFVAR 259
141 #define NTWKADDR 260
142 #define NETGROUP 261
143 #define USERGROUP 262
144 #define WORD 263
145 #define DEFAULTS 264
146 #define DEFAULTS_HOST 265
147 #define DEFAULTS_USER 266
148 #define DEFAULTS_RUNAS 267
149 #define DEFAULTS_CMND 268
150 #define NOPASSWD 269
151 #define PASSWD 270
152 #define NOEXEC 271
153 #define EXEC 272
154 #define SETENV 273
155 #define NOSETENV 274
156 #define LOG_INPUT 275
157 #define NOLOG_INPUT 276
158 #define LOG_OUTPUT 277
159 #define NOLOG_OUTPUT 278
160 #define ALL 279
161 #define COMMENT 280
162 #define HOSTALIAS 281
163 #define CMNDALIAS 282
164 #define USERALIAS 283
165 #define RUNASALIAS 284
166 #define ERROR 285
167 #define TYPE 286
168 #define ROLE 287
169 #define YYERRCODE 256
170 #if defined(__cplusplus) || defined(__STDC__)
171 const short yylhs[] =
172 #else
173 short yylhs[] =
174 #endif
175         {                                        -1,
176     0,    0,   25,   25,   26,   26,   26,   26,   26,   26,
177    26,   26,   26,   26,   26,   26,    4,    4,    3,    3,
178     3,    3,    3,   20,   20,   19,   10,   10,    8,    8,
179     8,    8,    8,    2,    2,    1,    6,    6,   23,   24,
180    22,   22,   22,   22,   22,   17,   17,   18,   18,   18,
181    21,   21,   21,   21,   21,   21,   21,   21,   21,   21,
182    21,    5,    5,    5,   28,   28,   31,    9,    9,   29,
183    29,   32,    7,    7,   30,   30,   33,   27,   27,   34,
184    13,   13,   11,   11,   12,   12,   12,   12,   12,   16,
185    16,   14,   14,   15,   15,   15,
186 };
187 #if defined(__cplusplus) || defined(__STDC__)
188 const short yylen[] =
189 #else
190 short yylen[] =
191 #endif
192         {                                         2,
193     0,    1,    1,    2,    1,    2,    2,    2,    2,    2,
194     2,    2,    3,    3,    3,    3,    1,    3,    1,    2,
195     3,    3,    3,    1,    3,    3,    1,    2,    1,    1,
196     1,    1,    1,    1,    3,    4,    1,    2,    3,    3,
197     0,    1,    1,    2,    2,    0,    3,    1,    3,    2,
198     0,    2,    2,    2,    2,    2,    2,    2,    2,    2,
199     2,    1,    1,    1,    1,    3,    3,    1,    3,    1,
200     3,    3,    1,    3,    1,    3,    3,    1,    3,    3,
201     1,    3,    1,    2,    1,    1,    1,    1,    1,    1,
202     3,    1,    2,    1,    1,    1,
203 };
204 #if defined(__cplusplus) || defined(__STDC__)
205 const short yydefred[] =
206 #else
207 short yydefred[] =
208 #endif
209         {                                      0,
210     0,   85,   87,   88,   89,    0,    0,    0,    0,    0,
211    86,    5,    0,    0,    0,    0,    0,    0,   81,   83,
212     0,    0,    3,    6,    0,    0,   17,    0,   29,   32,
213    31,   33,   30,    0,   27,    0,   68,    0,    0,   64,
214    63,   62,    0,   37,   73,    0,    0,    0,   65,    0,
215     0,   70,    0,    0,   78,    0,    0,   75,   84,    0,
216     0,   24,    0,    4,    0,    0,    0,   20,    0,   28,
217     0,    0,    0,    0,   38,    0,    0,    0,    0,    0,
218     0,    0,    0,    0,    0,   82,    0,    0,   21,   22,
219    23,   18,   69,   74,    0,   66,    0,   71,    0,   79,
220     0,   76,    0,   34,    0,    0,   25,    0,    0,    0,
221     0,    0,    0,   51,    0,    0,   94,   96,   95,    0,
222    90,   92,    0,    0,   47,   35,    0,    0,    0,   44,
223    45,   93,    0,    0,   40,   39,   52,   53,   54,   55,
224    56,   57,   58,   59,   60,   61,   36,   91,
225 };
226 #if defined(__cplusplus) || defined(__STDC__)
227 const short yydgoto[] =
228 #else
229 short yydgoto[] =
230 #endif
231         {                                      18,
232   104,  105,   27,   28,   44,   45,   46,   35,   61,   37,
233    19,   20,   21,  121,  122,  123,  106,  110,   62,   63,
234   129,  114,  115,  116,   22,   23,   54,   48,   51,   57,
235    49,   52,   58,   55,
236 };
237 #if defined(__cplusplus) || defined(__STDC__)
238 const short yysindex[] =
239 #else
240 short yysindex[] =
241 #endif
242         {                                    475,
243  -270,    0,    0,    0,    0,  -29,  567,  594,  594,   -2,
244     0,    0, -240, -222, -216, -212, -241,    0,    0,    0,
245   -25,  475,    0,    0,  -10, -207,    0,    9,    0,    0,
246     0,    0,    0, -235,    0,  -33,    0,  -31,  -31,    0,
247     0,    0, -242,    0,    0,  -30,   -7,    3,    0,   -6,
248     4,    0,   -5,    6,    0,   -1,    8,    0,    0,  594,
249   -20,    0,   10,    0, -205, -196, -194,    0,  -29,    0,
250   567,    9,    9,    9,    0,   -2,    9,  567, -240,   -2,
251  -222,  594, -216,  594, -212,    0,   31,  567,    0,    0,
252     0,    0,    0,    0,   26,    0,   28,    0,   29,    0,
253    29,    0,  541,    0,   32, -247,    0,   86,  -15,   33,
254    31,   14,   16,    0, -208, -204,    0,    0,    0, -231,
255     0,    0,   38,   86,    0,    0, -179, -178,  491,    0,
256     0,    0,   86,   38,    0,    0,    0,    0,    0,    0,
257     0,    0,    0,    0,    0,    0,    0,    0,};
258 #if defined(__cplusplus) || defined(__STDC__)
259 const short yyrindex[] =
260 #else
261 short yyrindex[] =
262 #endif
263         {                                     87,
264     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
265     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
266     0,   90,    0,    0,    1,    0,    0,  177,    0,    0,
267     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
268     0,    0,    0,    0,    0,    0,    0,  207,    0,    0,
269   237,    0,    0,  271,    0,    0,  300,    0,    0,    0,
270     0,    0,  329,    0,    0,    0,    0,    0,    0,    0,
271     0,  358,  387,  417,    0,    0,  446,    0,    0,    0,
272     0,    0,    0,    0,    0,    0,  -26,    0,    0,    0,
273     0,    0,    0,    0,   30,    0,   59,    0,   89,    0,
274   118,    0,    0,    0,  148,  514,    0,    0,   45,    0,
275   -26,    0,    0,    0,  537,  565,    0,    0,    0,    0,
276     0,    0,   50,    0,    0,    0,    0,    0,    0,    0,
277     0,    0,    0,   52,    0,    0,    0,    0,    0,    0,
278     0,    0,    0,    0,    0,    0,    0,    0,};
279 #if defined(__cplusplus) || defined(__STDC__)
280 const short yygindex[] =
281 #else
282 short yygindex[] =
283 #endif
284         {                                      0,
285   -17,    0,   27,   11,   54,  -64,   15,   64,    2,   34,
286    39,   84,   -3,  -27,  -18,  -21,    0,    0,   19,    0,
287     0,    0,  -12,   -4,    0,   88,    0,    0,    0,    0,
288    35,   40,   23,   37,
289 };
290 #define YYTABLESIZE 873
291 #if defined(__cplusplus) || defined(__STDC__)
292 const short yytable[] =
293 #else
294 short yytable[] =
295 #endif
296         {                                      26,
297    19,   26,   26,   26,   38,   39,   46,   34,   36,   24,
298    71,   94,   60,   76,   40,   41,    2,   47,   60,    3,
299     4,    5,   29,   71,   30,   31,  117,   32,   60,   67,
300    43,  118,   66,   19,   67,   50,   42,   11,  112,  113,
301    87,   53,  124,   33,   19,   56,   72,  119,   73,   74,
302    65,   68,   69,   78,   80,   82,   77,   89,   72,   84,
303    79,   81,   67,   83,  147,   85,   90,   88,   91,   71,
304   103,   76,   60,  125,  127,  111,  128,  112,   99,   95,
305   101,  133,  113,  135,  136,   48,    1,   67,   80,    2,
306    50,   72,   49,  126,   97,   92,   75,   70,   86,  109,
307    59,  132,  134,  131,   93,  148,  107,  102,    0,   64,
308   130,    0,    0,   96,    0,    0,   72,   77,  120,  100,
309    98,   80,    0,    0,    0,    0,    0,    0,    0,    0,
310     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
311     0,    0,    0,    0,    0,    0,   80,   26,    0,    0,
312    77,    0,    0,    0,    0,    0,    0,    0,    0,    0,
313     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
314     0,    0,    0,    0,    0,   77,   12,    0,    0,    0,
315    26,    0,    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,   26,    9,    0,    0,   12,
318     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
319     0,    0,    0,    0,    0,   25,    0,   25,   25,   25,
320    46,   46,   29,    0,   30,   31,   10,   32,    0,    9,
321     0,    0,   46,   46,   46,   46,   46,   46,   46,   46,
322    46,   46,   46,   33,   40,   41,   19,    0,   19,   46,
323    46,   19,   19,   19,   19,   19,   19,   19,   19,   10,
324     8,    0,    0,    0,    0,    0,   42,    0,    0,   19,
325    19,   19,   19,   19,   19,   67,    0,   67,    0,    0,
326    67,   67,   67,   67,   67,   67,   67,   67,    0,   11,
327     0,    0,    0,    8,    0,    0,    0,    0,   67,   67,
328    67,   67,   67,   67,   72,    0,   72,    0,    0,   72,
329    72,   72,   72,   72,   72,   72,   72,    0,    7,    0,
330     0,    0,   11,    0,    0,    0,    0,   72,   72,   72,
331    72,   72,   72,  117,   80,    0,   80,    0,  118,   80,
332    80,   80,   80,   80,   80,   80,   80,   15,    0,    0,
333     0,    7,    0,    0,  119,    0,    0,   80,   80,   80,
334    80,   80,   80,   77,    0,   77,    0,    0,   77,   77,
335    77,   77,   77,   77,   77,   77,   13,    0,    0,    0,
336    15,    0,    0,    0,    0,    0,   77,   77,   77,   77,
337    77,   77,    0,   26,    0,   26,    0,    0,   26,   26,
338    26,   26,   26,   26,   26,   26,   14,    0,    0,   13,
339     0,    0,    0,    0,    0,    0,   26,   26,   26,   26,
340    26,   26,   12,    0,   12,    0,    0,   12,   12,   12,
341    12,   12,   12,   12,   12,   16,    0,    0,    0,   14,
342     0,    0,    0,    0,    0,   12,   12,   12,   12,   12,
343    12,    0,    9,    0,    9,    0,    0,    9,    9,    9,
344     9,    9,    9,    9,    9,    0,    0,    0,   16,    0,
345     0,    0,    0,    0,    0,    9,    9,    9,    9,    9,
346     9,    0,   10,    0,   10,    0,    0,   10,   10,   10,
347    10,   10,   10,   10,   10,    0,    0,   17,    0,    0,
348     0,    0,    0,    0,    0,   10,   10,   10,   10,   10,
349    10,    0,    0,   43,    0,    0,    8,    0,    8,    0,
350     0,    8,    8,    8,    8,    8,    8,    8,    8,    0,
351     0,    0,    0,    0,    0,    0,   41,    0,    0,    8,
352     8,    8,    8,    8,    8,   11,    0,   11,    0,    0,
353    11,   11,   11,   11,   11,   11,   11,   11,    0,   42,
354     0,    0,    0,   17,    0,    0,    0,    0,   11,   11,
355    11,   11,   11,   11,    7,    0,    7,    0,    0,    7,
356     7,    7,    7,    7,    7,    7,    7,   43,  108,   34,
357     0,    0,    0,    0,    0,    0,    0,    7,    7,    7,
358     7,    7,    7,   15,    0,   15,    0,    0,   15,   15,
359    15,   15,   15,   15,   15,   15,   17,    0,    0,    0,
360     0,    0,    0,    0,    0,    0,   15,   15,   15,   15,
361    15,   15,   13,    0,   13,    0,    0,   13,   13,   13,
362    13,   13,   13,   13,   13,    0,    0,    0,    0,    0,
363     0,    0,    0,    0,    0,   13,   13,   13,   13,   13,
364    13,    0,   14,    0,   14,    0,    0,   14,   14,   14,
365    14,   14,   14,   14,   14,    0,    0,    0,    0,    0,
366     0,    0,    0,    0,    0,   14,   14,   14,   14,   14,
367    14,   16,    0,   16,    0,    0,   16,   16,   16,   16,
368    16,   16,   16,   16,    0,    0,    0,    0,    0,    0,
369     0,    0,    0,    0,   16,   16,   16,   16,   16,   16,
370     1,    0,    2,    0,    0,    3,    4,    5,    6,    7,
371     8,    9,   10,    0,    0,    0,    0,   40,   41,    0,
372     0,    0,    0,   11,   12,   13,   14,   15,   16,  137,
373   138,  139,  140,  141,  142,  143,  144,  145,  146,   42,
374    41,   41,    0,    0,    0,    0,    0,    0,    0,    0,
375     0,    0,   41,   41,   41,   41,   41,   41,   41,   41,
376    41,   41,   41,   42,   42,    0,    0,    0,    2,    0,
377     0,    3,    4,    5,    0,   42,   42,   42,   42,   42,
378    42,   42,   42,   42,   42,   42,    0,    0,    0,   11,
379     0,   43,   43,    0,   29,    0,   30,   31,    0,   32,
380     0,    0,    0,   43,   43,   43,   43,   43,   43,   43,
381    43,   43,   43,   43,    0,   33,    0,    0,    0,    0,
382     0,    2,    0,    0,    3,    4,    5,    0,    0,    0,
383     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
384     0,    0,   11,
385 };
386 #if defined(__cplusplus) || defined(__STDC__)
387 const short yycheck[] =
388 #else
389 short yycheck[] =
390 #endif
391         {                                      33,
392     0,   33,   33,   33,    8,    9,   33,   33,    7,  280,
393    44,   76,   44,   44,  257,  258,  258,  258,   44,  261,
394   262,  263,  258,   44,  260,  261,  258,  263,   44,    0,
395    33,  263,   43,   33,   45,  258,  279,  279,  286,  287,
396    61,  258,   58,  279,   44,  258,   36,  279,   38,   39,
397    61,  259,   44,   61,   61,   61,   46,  263,    0,   61,
398    58,   58,   33,   58,  129,   58,  263,   58,  263,   44,
399    40,   44,   44,   41,   61,   44,   61,  286,   82,   78,
400    84,   44,  287,  263,  263,   41,    0,   58,    0,    0,
401    41,   33,   41,  111,   80,   69,   43,   34,   60,  103,
402    17,  120,  124,  116,   71,  133,   88,   85,   -1,   22,
403   115,   -1,   -1,   79,   -1,   -1,   58,    0,   33,   83,
404    81,   33,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
405    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
406    -1,   -1,   -1,   -1,   -1,   -1,   58,    0,   -1,   -1,
407    33,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
408    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
409    -1,   -1,   -1,   -1,   -1,   58,    0,   -1,   -1,   -1,
410    33,   -1,   -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,   58,    0,   -1,   -1,   33,
413    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
414    -1,   -1,   -1,   -1,   -1,  259,   -1,  259,  259,  259,
415   257,  258,  258,   -1,  260,  261,    0,  263,   -1,   33,
416    -1,   -1,  269,  270,  271,  272,  273,  274,  275,  276,
417   277,  278,  279,  279,  257,  258,  256,   -1,  258,  286,
418   287,  261,  262,  263,  264,  265,  266,  267,  268,   33,
419     0,   -1,   -1,   -1,   -1,   -1,  279,   -1,   -1,  279,
420   280,  281,  282,  283,  284,  256,   -1,  258,   -1,   -1,
421   261,  262,  263,  264,  265,  266,  267,  268,   -1,    0,
422    -1,   -1,   -1,   33,   -1,   -1,   -1,   -1,  279,  280,
423   281,  282,  283,  284,  256,   -1,  258,   -1,   -1,  261,
424   262,  263,  264,  265,  266,  267,  268,   -1,    0,   -1,
425    -1,   -1,   33,   -1,   -1,   -1,   -1,  279,  280,  281,
426   282,  283,  284,  258,  256,   -1,  258,   -1,  263,  261,
427   262,  263,  264,  265,  266,  267,  268,    0,   -1,   -1,
428    -1,   33,   -1,   -1,  279,   -1,   -1,  279,  280,  281,
429   282,  283,  284,  256,   -1,  258,   -1,   -1,  261,  262,
430   263,  264,  265,  266,  267,  268,    0,   -1,   -1,   -1,
431    33,   -1,   -1,   -1,   -1,   -1,  279,  280,  281,  282,
432   283,  284,   -1,  256,   -1,  258,   -1,   -1,  261,  262,
433   263,  264,  265,  266,  267,  268,    0,   -1,   -1,   33,
434    -1,   -1,   -1,   -1,   -1,   -1,  279,  280,  281,  282,
435   283,  284,  256,   -1,  258,   -1,   -1,  261,  262,  263,
436   264,  265,  266,  267,  268,    0,   -1,   -1,   -1,   33,
437    -1,   -1,   -1,   -1,   -1,  279,  280,  281,  282,  283,
438   284,   -1,  256,   -1,  258,   -1,   -1,  261,  262,  263,
439   264,  265,  266,  267,  268,   -1,   -1,   -1,   33,   -1,
440    -1,   -1,   -1,   -1,   -1,  279,  280,  281,  282,  283,
441   284,   -1,  256,   -1,  258,   -1,   -1,  261,  262,  263,
442   264,  265,  266,  267,  268,   -1,   -1,   33,   -1,   -1,
443    -1,   -1,   -1,   -1,   -1,  279,  280,  281,  282,  283,
444   284,   -1,   -1,   33,   -1,   -1,  256,   -1,  258,   -1,
445    -1,  261,  262,  263,  264,  265,  266,  267,  268,   -1,
446    -1,   -1,   -1,   -1,   -1,   -1,   33,   -1,   -1,  279,
447   280,  281,  282,  283,  284,  256,   -1,  258,   -1,   -1,
448   261,  262,  263,  264,  265,  266,  267,  268,   -1,   33,
449    -1,   -1,   -1,   33,   -1,   -1,   -1,   -1,  279,  280,
450   281,  282,  283,  284,  256,   -1,  258,   -1,   -1,  261,
451   262,  263,  264,  265,  266,  267,  268,   33,   58,   33,
452    -1,   -1,   -1,   -1,   -1,   -1,   -1,  279,  280,  281,
453   282,  283,  284,  256,   -1,  258,   -1,   -1,  261,  262,
454   263,  264,  265,  266,  267,  268,   33,   -1,   -1,   -1,
455    -1,   -1,   -1,   -1,   -1,   -1,  279,  280,  281,  282,
456   283,  284,  256,   -1,  258,   -1,   -1,  261,  262,  263,
457   264,  265,  266,  267,  268,   -1,   -1,   -1,   -1,   -1,
458    -1,   -1,   -1,   -1,   -1,  279,  280,  281,  282,  283,
459   284,   -1,  256,   -1,  258,   -1,   -1,  261,  262,  263,
460   264,  265,  266,  267,  268,   -1,   -1,   -1,   -1,   -1,
461    -1,   -1,   -1,   -1,   -1,  279,  280,  281,  282,  283,
462   284,  256,   -1,  258,   -1,   -1,  261,  262,  263,  264,
463   265,  266,  267,  268,   -1,   -1,   -1,   -1,   -1,   -1,
464    -1,   -1,   -1,   -1,  279,  280,  281,  282,  283,  284,
465   256,   -1,  258,   -1,   -1,  261,  262,  263,  264,  265,
466   266,  267,  268,   -1,   -1,   -1,   -1,  257,  258,   -1,
467    -1,   -1,   -1,  279,  280,  281,  282,  283,  284,  269,
468   270,  271,  272,  273,  274,  275,  276,  277,  278,  279,
469   257,  258,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
470    -1,   -1,  269,  270,  271,  272,  273,  274,  275,  276,
471   277,  278,  279,  257,  258,   -1,   -1,   -1,  258,   -1,
472    -1,  261,  262,  263,   -1,  269,  270,  271,  272,  273,
473   274,  275,  276,  277,  278,  279,   -1,   -1,   -1,  279,
474    -1,  257,  258,   -1,  258,   -1,  260,  261,   -1,  263,
475    -1,   -1,   -1,  269,  270,  271,  272,  273,  274,  275,
476   276,  277,  278,  279,   -1,  279,   -1,   -1,   -1,   -1,
477    -1,  258,   -1,   -1,  261,  262,  263,   -1,   -1,   -1,
478    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
479    -1,   -1,  279,
480 };
481 #define YYFINAL 18
482 #ifndef YYDEBUG
483 #define YYDEBUG 0
484 #endif
485 #define YYMAXTOKEN 287
486 #if YYDEBUG
487 #if defined(__cplusplus) || defined(__STDC__)
488 const char * const yyname[] =
489 #else
490 char *yyname[] =
491 #endif
492         {
493 "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,
494 "'!'",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,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,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 "COMMAND","ALIAS","DEFVAR","NTWKADDR","NETGROUP","USERGROUP","WORD","DEFAULTS",
501 "DEFAULTS_HOST","DEFAULTS_USER","DEFAULTS_RUNAS","DEFAULTS_CMND","NOPASSWD",
502 "PASSWD","NOEXEC","EXEC","SETENV","NOSETENV","LOG_INPUT","NOLOG_INPUT",
503 "LOG_OUTPUT","NOLOG_OUTPUT","ALL","COMMENT","HOSTALIAS","CMNDALIAS","USERALIAS",
504 "RUNASALIAS","ERROR","TYPE","ROLE",
505 };
506 #if defined(__cplusplus) || defined(__STDC__)
507 const char * const yyrule[] =
508 #else
509 char *yyrule[] =
510 #endif
511         {"$accept : file",
512 "file :",
513 "file : line",
514 "line : entry",
515 "line : line entry",
516 "entry : COMMENT",
517 "entry : error COMMENT",
518 "entry : userlist privileges",
519 "entry : USERALIAS useraliases",
520 "entry : HOSTALIAS hostaliases",
521 "entry : CMNDALIAS cmndaliases",
522 "entry : RUNASALIAS runasaliases",
523 "entry : DEFAULTS defaults_list",
524 "entry : DEFAULTS_USER userlist defaults_list",
525 "entry : DEFAULTS_RUNAS userlist defaults_list",
526 "entry : DEFAULTS_HOST hostlist defaults_list",
527 "entry : DEFAULTS_CMND cmndlist defaults_list",
528 "defaults_list : defaults_entry",
529 "defaults_list : defaults_list ',' defaults_entry",
530 "defaults_entry : DEFVAR",
531 "defaults_entry : '!' DEFVAR",
532 "defaults_entry : DEFVAR '=' WORD",
533 "defaults_entry : DEFVAR '+' WORD",
534 "defaults_entry : DEFVAR '-' WORD",
535 "privileges : privilege",
536 "privileges : privileges ':' privilege",
537 "privilege : hostlist '=' cmndspeclist",
538 "ophost : host",
539 "ophost : '!' host",
540 "host : ALIAS",
541 "host : ALL",
542 "host : NETGROUP",
543 "host : NTWKADDR",
544 "host : WORD",
545 "cmndspeclist : cmndspec",
546 "cmndspeclist : cmndspeclist ',' cmndspec",
547 "cmndspec : runasspec selinux cmndtag opcmnd",
548 "opcmnd : cmnd",
549 "opcmnd : '!' cmnd",
550 "rolespec : ROLE '=' WORD",
551 "typespec : TYPE '=' WORD",
552 "selinux :",
553 "selinux : rolespec",
554 "selinux : typespec",
555 "selinux : rolespec typespec",
556 "selinux : typespec rolespec",
557 "runasspec :",
558 "runasspec : '(' runaslist ')'",
559 "runaslist : userlist",
560 "runaslist : userlist ':' grouplist",
561 "runaslist : ':' grouplist",
562 "cmndtag :",
563 "cmndtag : cmndtag NOPASSWD",
564 "cmndtag : cmndtag PASSWD",
565 "cmndtag : cmndtag NOEXEC",
566 "cmndtag : cmndtag EXEC",
567 "cmndtag : cmndtag SETENV",
568 "cmndtag : cmndtag NOSETENV",
569 "cmndtag : cmndtag LOG_INPUT",
570 "cmndtag : cmndtag NOLOG_INPUT",
571 "cmndtag : cmndtag LOG_OUTPUT",
572 "cmndtag : cmndtag NOLOG_OUTPUT",
573 "cmnd : ALL",
574 "cmnd : ALIAS",
575 "cmnd : COMMAND",
576 "hostaliases : hostalias",
577 "hostaliases : hostaliases ':' hostalias",
578 "hostalias : ALIAS '=' hostlist",
579 "hostlist : ophost",
580 "hostlist : hostlist ',' ophost",
581 "cmndaliases : cmndalias",
582 "cmndaliases : cmndaliases ':' cmndalias",
583 "cmndalias : ALIAS '=' cmndlist",
584 "cmndlist : opcmnd",
585 "cmndlist : cmndlist ',' opcmnd",
586 "runasaliases : runasalias",
587 "runasaliases : runasaliases ':' runasalias",
588 "runasalias : ALIAS '=' userlist",
589 "useraliases : useralias",
590 "useraliases : useraliases ':' useralias",
591 "useralias : ALIAS '=' userlist",
592 "userlist : opuser",
593 "userlist : userlist ',' opuser",
594 "opuser : user",
595 "opuser : '!' user",
596 "user : ALIAS",
597 "user : ALL",
598 "user : NETGROUP",
599 "user : USERGROUP",
600 "user : WORD",
601 "grouplist : opgroup",
602 "grouplist : grouplist ',' opgroup",
603 "opgroup : group",
604 "opgroup : '!' group",
605 "group : ALIAS",
606 "group : ALL",
607 "group : WORD",
608 };
609 #endif
610 #ifdef YYSTACKSIZE
611 #undef YYMAXDEPTH
612 #define YYMAXDEPTH YYSTACKSIZE
613 #else
614 #ifdef YYMAXDEPTH
615 #define YYSTACKSIZE YYMAXDEPTH
616 #else
617 #define YYSTACKSIZE 10000
618 #define YYMAXDEPTH 10000
619 #endif
620 #endif
621 #define YYINITSTACKSIZE 200
622 /* LINTUSED */
623 int yydebug;
624 int yynerrs;
625 int yyerrflag;
626 int yychar;
627 short *yyssp;
628 YYSTYPE *yyvsp;
629 YYSTYPE yyval;
630 YYSTYPE yylval;
631 short *yyss;
632 short *yysslim;
633 YYSTYPE *yyvs;
634 int yystacksize;
635 #line 606 "gram.y"
636 static struct defaults *
637 new_default(var, val, op)
638     char *var;
639     char *val;
640     int op;
641 {
642     struct defaults *d;
643
644     d = emalloc(sizeof(struct defaults));
645     d->var = var;
646     d->val = val;
647     tq_init(&d->binding);
648     d->type = 0;
649     d->op = op;
650     d->prev = d;
651     d->next = NULL;
652
653     return(d);
654 }
655
656 static struct member *
657 new_member(name, type)
658     char *name;
659     int type;
660 {
661     struct member *m;
662
663     m = emalloc(sizeof(struct member));
664     m->name = name;
665     m->type = type;
666     m->prev = m;
667     m->next = NULL;
668
669     return(m);
670 }
671
672 /*
673  * Add a list of defaults structures to the defaults list.
674  * The binding, if non-NULL, specifies a list of hosts, users, or
675  * runas users the entries apply to (specified by the type).
676  */
677 static void
678 add_defaults(type, bmem, defs)
679     int type;
680     struct member *bmem;
681     struct defaults *defs;
682 {
683     struct defaults *d;
684     struct member_list binding;
685
686     /*
687      * We can only call list2tq once on bmem as it will zero
688      * out the prev pointer when it consumes bmem.
689      */
690     list2tq(&binding, bmem);
691
692     /*
693      * Set type and binding (who it applies to) for new entries.
694      */
695     for (d = defs; d != NULL; d = d->next) {
696         d->type = type;
697         d->binding = binding;
698     }
699     tq_append(&defaults, defs);
700 }
701
702 /*
703  * Allocate a new struct userspec, populate it, and insert it at the
704  * and of the userspecs list.
705  */
706 static void
707 add_userspec(members, privs)
708     struct member *members;
709     struct privilege *privs;
710 {
711     struct userspec *u;
712
713     u = emalloc(sizeof(*u));
714     list2tq(&u->users, members);
715     list2tq(&u->privileges, privs);
716     u->prev = u;
717     u->next = NULL;
718     tq_append(&userspecs, u);
719 }
720
721 /*
722  * Free up space used by data structures from a previous parser run and sets
723  * the current sudoers file to path.
724  */
725 void
726 init_parser(path, quiet)
727     char *path;
728     int quiet;
729 {
730     struct defaults *d;
731     struct member *m, *binding;
732     struct userspec *us;
733     struct privilege *priv;
734     struct cmndspec *cs;
735     struct sudo_command *c;
736
737     while ((us = tq_pop(&userspecs)) != NULL) {
738         while ((m = tq_pop(&us->users)) != NULL) {
739             efree(m->name);
740             efree(m);
741         }
742         while ((priv = tq_pop(&us->privileges)) != NULL) {
743             struct member *runasuser = NULL, *runasgroup = NULL;
744 #ifdef HAVE_SELINUX
745             char *role = NULL, *type = NULL;
746 #endif /* HAVE_SELINUX */
747
748             while ((m = tq_pop(&priv->hostlist)) != NULL) {
749                 efree(m->name);
750                 efree(m);
751             }
752             while ((cs = tq_pop(&priv->cmndlist)) != NULL) {
753 #ifdef HAVE_SELINUX
754                 /* Only free the first instance of a role/type. */
755                 if (cs->role != role) {
756                     role = cs->role;
757                     efree(cs->role);
758                 }
759                 if (cs->type != type) {
760                     type = cs->type;
761                     efree(cs->type);
762                 }
763 #endif /* HAVE_SELINUX */
764                 if (tq_last(&cs->runasuserlist) != runasuser) {
765                     runasuser = tq_last(&cs->runasuserlist);
766                     while ((m = tq_pop(&cs->runasuserlist)) != NULL) {
767                         efree(m->name);
768                         efree(m);
769                     }
770                 }
771                 if (tq_last(&cs->runasgrouplist) != runasgroup) {
772                     runasgroup = tq_last(&cs->runasgrouplist);
773                     while ((m = tq_pop(&cs->runasgrouplist)) != NULL) {
774                         efree(m->name);
775                         efree(m);
776                     }
777                 }
778                 if (cs->cmnd->type == COMMAND) {
779                         c = (struct sudo_command *) cs->cmnd->name;
780                         efree(c->cmnd);
781                         efree(c->args);
782                 }
783                 efree(cs->cmnd->name);
784                 efree(cs->cmnd);
785                 efree(cs);
786             }
787             efree(priv);
788         }
789         efree(us);
790     }
791     tq_init(&userspecs);
792
793     binding = NULL;
794     while ((d = tq_pop(&defaults)) != NULL) {
795         if (tq_last(&d->binding) != binding) {
796             binding = tq_last(&d->binding);
797             while ((m = tq_pop(&d->binding)) != NULL) {
798                 if (m->type == COMMAND) {
799                         c = (struct sudo_command *) m->name;
800                         efree(c->cmnd);
801                         efree(c->args);
802                 }
803                 efree(m->name);
804                 efree(m);
805             }
806         }
807         efree(d->var);
808         efree(d->val);
809         efree(d);
810     }
811     tq_init(&defaults);
812
813     init_aliases();
814
815     init_lexer();
816
817     efree(sudoers);
818     sudoers = path ? estrdup(path) : NULL;
819
820     parse_error = FALSE;
821     errorlineno = -1;
822     errorfile = NULL;
823     sudolineno = 1;
824     verbose = !quiet;
825 }
826 #line 775 "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 1544 "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 }