fix typo in changelog
[debian/sudo] / sudo.tab.c
1 #ifndef lint
2 /*static char yysccsid[] = "from: @(#)yaccpar   1.9 (Berkeley) 02/21/93";*/
3 static char yyrcsid[]
4 #if __GNUC__ >= 2
5   __attribute__ ((unused))
6 #endif /* __GNUC__ >= 2 */
7   = "$OpenBSD: skeleton.c,v 1.28 2007/09/03 21:14:58 deraadt Exp $";
8 #endif
9 #include <stdlib.h>
10 #define YYBYACC 1
11 #define YYMAJOR 1
12 #define YYMINOR 9
13 #define YYLEX yylex()
14 #define YYEMPTY -1
15 #define yyclearin (yychar=(YYEMPTY))
16 #define yyerrok (yyerrflag=0)
17 #define YYRECOVERING() (yyerrflag!=0)
18 #define YYPREFIX "yy"
19 #line 2 "parse.yacc"
20 /*
21  * Copyright (c) 1996, 1998-2004, 2007
22  *      Todd C. Miller <Todd.Miller@courtesan.com>
23  *
24  * Permission to use, copy, modify, and distribute this software for any
25  * purpose with or without fee is hereby granted, provided that the above
26  * copyright notice and this permission notice appear in all copies.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
29  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
30  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
31  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
32  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
33  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
34  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
35  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
36  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  *
38  * Sponsored in part by the Defense Advanced Research Projects
39  * Agency (DARPA) and Air Force Research Laboratory, Air Force
40  * Materiel Command, USAF, under agreement number F39502-99-1-0512.
41  */
42
43 /*
44  * XXX - the whole opFOO naming thing is somewhat bogus.
45  *
46  * XXX - the way things are stored for printmatches is stupid,
47  *       they should be stored as elements in an array and then
48  *       list_matches() can format things the way it wants.
49  */
50
51 #include <config.h>
52
53 #include <sys/types.h>
54 #include <sys/param.h>
55 #include <stdio.h>
56 #ifdef STDC_HEADERS
57 # include <stdlib.h>
58 # include <stddef.h>
59 #else
60 # ifdef HAVE_STDLIB_H
61 #  include <stdlib.h>
62 # endif
63 #endif /* STDC_HEADERS */
64 #ifdef HAVE_STRING_H
65 # include <string.h>
66 #else
67 # ifdef HAVE_STRINGS_H
68 #  include <strings.h>
69 # endif
70 #endif /* HAVE_STRING_H */
71 #ifdef HAVE_UNISTD_H
72 # include <unistd.h>
73 #endif /* HAVE_UNISTD_H */
74 #include <pwd.h>
75 #if defined(YYBISON) && defined(HAVE_ALLOCA_H) && !defined(__GNUC__)
76 # include <alloca.h>
77 #endif /* YYBISON && HAVE_ALLOCA_H && !__GNUC__ */
78 #ifdef HAVE_LSEARCH
79 # include <search.h>
80 #endif /* HAVE_LSEARCH */
81 #include <limits.h>
82
83 #include "sudo.h"
84 #include "parse.h"
85
86 #ifndef HAVE_LSEARCH
87 #include "emul/search.h"
88 #endif /* HAVE_LSEARCH */
89
90 #ifndef lint
91 __unused static const char rcsid[] = "$Sudo: sudo.tab.c,v 1.76.2.14 2008/02/27 20:34:42 millert Exp $";
92 #endif /* lint */
93
94 /*
95  * We must define SIZE_MAX for yacc's skeleton.c.
96  * If there is no SIZE_MAX or SIZE_T_MAX we have to assume that size_t
97  * could be signed (as it is on SunOS 4.x).
98  */
99 #ifndef SIZE_MAX
100 # ifdef SIZE_T_MAX
101 #  define SIZE_MAX      SIZE_T_MAX
102 # else
103 #  define SIZE_MAX      INT_MAX
104 # endif /* SIZE_T_MAX */
105 #endif /* SIZE_MAX */
106
107 /*
108  * Globals
109  */
110 extern int sudolineno, parse_error;
111 int errorlineno = -1;
112 int clearaliases = TRUE;
113 int printmatches = FALSE;
114 int pedantic = FALSE;
115 int keepall = FALSE;
116 int quiet = FALSE;
117 int used_runas = FALSE;
118
119 /*
120  * Alias types
121  */
122 #define HOST_ALIAS               1
123 #define CMND_ALIAS               2
124 #define USER_ALIAS               3
125 #define RUNAS_ALIAS              4
126
127 #define SETMATCH(_var, _val)    do { \
128         if ((_var) == UNSPEC || (_val) != NOMATCH) \
129             (_var) = (_val); \
130 } while (0)
131
132 #define SETNMATCH(_var, _val)   do { \
133         if ((_val) != NOMATCH) \
134             (_var) = ! (_val); \
135         else if ((_var) == UNSPEC) \
136             (_var) = NOMATCH; \
137 } while (0)
138
139 #define SETENV_RESET \
140         if (setenv_ok == IMPLIED) setenv_ok = def_setenv ? TRUE : UNSPEC
141
142 /*
143  * The matching stack, initial space allocated in init_parser().
144  */
145 struct matchstack *match;
146 int top = 0, stacksize = 0;
147
148 #define push \
149     do { \
150         if (top >= stacksize) { \
151             while ((stacksize += STACKINCREMENT) < top); \
152             match = (struct matchstack *) erealloc3(match, stacksize, sizeof(struct matchstack)); \
153         } \
154         match[top].user   = UNSPEC; \
155         match[top].cmnd   = UNSPEC; \
156         match[top].host   = UNSPEC; \
157         match[top].runas  = UNSPEC; \
158         match[top].nopass = def_authenticate ? UNSPEC : TRUE; \
159         match[top].noexec = def_noexec ? TRUE : UNSPEC; \
160         match[top].setenv = def_setenv ? TRUE : UNSPEC; \
161         match[top].role = NULL; \
162         match[top].type = NULL; \
163         top++; \
164     } while (0)
165
166 #define pushcp \
167     do { \
168         if (top >= stacksize) { \
169             while ((stacksize += STACKINCREMENT) < top); \
170             match = (struct matchstack *) erealloc3(match, stacksize, sizeof(struct matchstack)); \
171         } \
172         match[top].user   = match[top-1].user; \
173         match[top].cmnd   = match[top-1].cmnd; \
174         match[top].host   = match[top-1].host; \
175         match[top].runas  = match[top-1].runas; \
176         match[top].nopass = match[top-1].nopass; \
177         match[top].noexec = match[top-1].noexec; \
178         match[top].setenv = match[top-1].setenv; \
179         match[top].role   = estrdup(match[top-1].role); \
180         match[top].type   = estrdup(match[top-1].type); \
181         top++; \
182     } while (0)
183
184 #define pop \
185     do { \
186         if (top == 0) \
187             yyerror("matching stack underflow"); \
188         else { \
189             efree(match[top-1].role); \
190             efree(match[top-1].type); \
191             top--; \
192         } \
193     } while (0)
194
195
196 /*
197  * For testing if foo_matches variable was set to TRUE or FALSE
198  */
199 #define MATCHED(_v)     ((_v) >= 0)
200
201 /*
202  * Shortcuts for append()
203  */
204 #define append_cmnd(s, p) append(s, &cm_list[cm_list_len].cmnd, \
205         &cm_list[cm_list_len].cmnd_len, &cm_list[cm_list_len].cmnd_size, p)
206
207 #define append_runas(s, p) append(s, &cm_list[cm_list_len].runas, \
208         &cm_list[cm_list_len].runas_len, &cm_list[cm_list_len].runas_size, p)
209
210 #define append_role(s, p) append(s, &cm_list[cm_list_len].role, \
211         &cm_list[cm_list_len].role_len, &cm_list[cm_list_len].role_size, p)
212
213 #define append_type(s, p) append(s, &cm_list[cm_list_len].type, \
214         &cm_list[cm_list_len].type_len, &cm_list[cm_list_len].type_size, p)
215
216 #define append_entries(s, p) append(s, &ga_list[ga_list_len-1].entries, \
217         &ga_list[ga_list_len-1].entries_len, \
218         &ga_list[ga_list_len-1].entries_size, p)
219
220 /*
221  * The stack for printmatches.  A list of allowed commands for the user.
222  */
223 static struct command_match *cm_list = NULL;
224 static size_t cm_list_len = 0, cm_list_size = 0;
225
226 /*
227  * List of Cmnd_Aliases and expansions for `sudo -l'
228  */
229 static int in_alias = FALSE;
230 static size_t ga_list_len = 0, ga_list_size = 0;
231 static struct generic_alias *ga_list = NULL;
232
233 /*
234  * Does this Defaults list pertain to this user?
235  */
236 static int defaults_matches = FALSE;
237
238 /*
239  * Local protoypes
240  */
241 static int  add_alias           __P((char *, int, int));
242 static void append              __P((char *, char **, size_t *, size_t *, char *));
243 static void expand_ga_list      __P((void));
244 static void expand_match_list   __P((void));
245 static aliasinfo *find_alias    __P((char *, int));
246 static void more_aliases        __P((void));
247        void init_parser         __P((void));
248        void yyerror             __P((char *));
249
250 void
251 yyerror(s)
252     char *s;
253 {
254     /* Save the line the first error occurred on. */
255     if (errorlineno == -1)
256         errorlineno = sudolineno ? sudolineno - 1 : 0;
257     if (s && !quiet) {
258 #ifndef TRACELEXER
259         (void) fprintf(stderr, ">>> sudoers file: %s, line %d <<<\n", s,
260             sudolineno ? sudolineno - 1 : 0);
261 #else
262         (void) fprintf(stderr, "<*> ");
263 #endif
264     }
265     parse_error = TRUE;
266 }
267 #line 251 "parse.yacc"
268 #ifndef YYSTYPE_DEFINED
269 #define YYSTYPE_DEFINED
270 typedef union {
271     char *string;
272     int BOOLEAN;
273     struct sudo_command command;
274     int tok;
275     struct selinux_info seinfo;
276 } YYSTYPE;
277 #endif /* YYSTYPE_DEFINED */
278 #line 279 "sudo.tab.c"
279 #define COMMAND 257
280 #define ALIAS 258
281 #define DEFVAR 259
282 #define NTWKADDR 260
283 #define NETGROUP 261
284 #define USERGROUP 262
285 #define WORD 263
286 #define DEFAULTS 264
287 #define DEFAULTS_HOST 265
288 #define DEFAULTS_USER 266
289 #define DEFAULTS_RUNAS 267
290 #define RUNAS 268
291 #define NOPASSWD 269
292 #define PASSWD 270
293 #define NOEXEC 271
294 #define EXEC 272
295 #define SETENV 273
296 #define NOSETENV 274
297 #define ALL 275
298 #define COMMENT 276
299 #define HOSTALIAS 277
300 #define CMNDALIAS 278
301 #define USERALIAS 279
302 #define RUNASALIAS 280
303 #define ERROR 281
304 #define TYPE 282
305 #define ROLE 283
306 #define YYERRCODE 256
307 #if defined(__cplusplus) || defined(__STDC__)
308 const short yylhs[] =
309 #else
310 short yylhs[] =
311 #endif
312         {                                        -1,
313     0,    0,   10,   10,   12,   10,   10,   10,   10,   10,
314    10,   18,   19,   21,   19,   22,   19,   24,   19,   20,
315    20,   25,   25,   25,   25,   25,   13,   13,   26,   28,
316    28,    2,    2,    2,    2,    2,   27,   27,   31,   29,
317    33,   34,   33,    8,    9,    7,    7,    7,    7,    7,
318    30,   30,    5,    5,    4,   35,    4,    3,    3,    3,
319     3,    3,   32,   32,   32,   32,   32,   32,   32,    1,
320     1,    1,   15,   15,   37,   36,   23,   23,   16,   16,
321    39,   38,   40,   40,   17,   17,   42,   41,   14,   14,
322    44,   43,   11,   11,   45,   45,    6,    6,    6,    6,
323     6,
324 };
325 #if defined(__cplusplus) || defined(__STDC__)
326 const short yylen[] =
327 #else
328 short yylen[] =
329 #endif
330         {                                         2,
331     1,    2,    1,    2,    0,    3,    2,    2,    2,    2,
332     1,    2,    1,    0,    3,    0,    3,    0,    3,    1,
333     3,    1,    2,    3,    3,    3,    1,    3,    3,    1,
334     2,    1,    1,    1,    1,    1,    1,    3,    0,    5,
335     1,    0,    3,    3,    3,    0,    1,    1,    2,    2,
336     0,    2,    1,    3,    1,    0,    3,    1,    1,    1,
337     1,    1,    0,    2,    2,    2,    2,    2,    2,    1,
338     1,    1,    1,    3,    0,    4,    1,    3,    1,    3,
339     0,    4,    1,    3,    1,    3,    0,    4,    1,    3,
340     0,    4,    1,    3,    1,    2,    1,    1,    1,    1,
341     1,
342 };
343 #if defined(__cplusplus) || defined(__STDC__)
344 const short yydefred[] =
345 #else
346 short yydefred[] =
347 #endif
348         {                                      0,
349     0,   13,   18,   14,   16,    3,    0,    0,    0,    0,
350     0,    1,    0,   11,    0,    4,    0,    0,    0,   75,
351     0,   73,   81,    0,   79,   91,    0,   89,   87,    0,
352    85,    2,  100,   99,   98,   97,  101,    0,   95,    0,
353    93,    0,    0,   12,    0,   36,   33,   34,   35,   32,
354     0,   30,    0,   77,    0,   61,   60,   59,   58,   62,
355    56,   55,   53,    0,    0,    0,    0,    0,    0,    0,
356     0,    0,   96,    0,    0,    0,   27,    0,    0,    0,
357    23,    0,   31,    0,    0,    0,    0,   74,    0,   80,
358     0,   90,    0,   86,   94,    0,   39,   24,   25,   26,
359    21,   78,   57,   54,    0,   72,   71,   70,   42,   41,
360    83,    0,    0,    0,   28,    0,   37,    0,    0,    0,
361    39,    0,    0,   43,   84,   38,    0,    0,    0,   63,
362     0,    0,    0,    0,    0,   49,   50,   45,   44,   64,
363    65,   66,   67,   68,   69,   40,
364 };
365 #if defined(__cplusplus) || defined(__STDC__)
366 const short yydgoto[] =
367 #else
368 short yydgoto[] =
369 #endif
370         {                                      11,
371   110,   52,   62,   63,   64,   39,  130,  131,  132,   12,
372    40,   13,   75,   27,   21,   24,   30,   14,   15,   44,
373    18,   19,   76,   17,   45,   77,  116,   54,  117,  123,
374   118,  135,  111,  119,   85,   22,   65,   25,   67,  112,
375    31,   71,   28,   69,   41,
376 };
377 #if defined(__cplusplus) || defined(__STDC__)
378 const short yysindex[] =
379 #else
380 short yysindex[] =
381 #endif
382         {                                   -247,
383  -248,    0,    0,    0,    0,    0, -211, -210, -205, -201,
384  -247,    0,   62,    0,  -33,    0,   89,   62,  114,    0,
385     2,    0,    0,    3,    0,    0,    4,    0,    0,    6,
386     0,    0,    0,    0,    0,    0,    0, -251,    0,  -28,
387     0,  -18, -194,    0,   14,    0,    0,    0,    0,    0,
388  -219,    0,   22,    0,   23,    0,    0,    0,    0,    0,
389     0,    0,    0,   24,    8, -211,    9, -210,   10, -205,
390    11, -201,    0,   62,   16,  -23,    0, -187, -186, -184,
391     0,  -33,    0,   89, -212,  114,   89,    0,  -20,    0,
392    62,    0,  114,    0,    0,   89,    0,    0,    0,    0,
393     0,    0,    0,    0,   22,    0,    0,    0,    0,    0,
394     0,   36,   23,   24,    0,   37,    0, -185, -221,  -20,
395     0,  114, -268,    0,    0,    0,   24,   21,   25,    0,
396  -195, -193, -175, -174,  274,    0,    0,    0,    0,    0,
397     0,    0,    0,    0,    0,    0,};
398 #if defined(__cplusplus) || defined(__STDC__)
399 const short yyrindex[] =
400 #else
401 short yyrindex[] =
402 #endif
403         {                                    141,
404     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
405   141,    0,    0,    0,    0,    0,    0,    0,    0,    0,
406   156,    0,    0,  181,    0,    0,  206,    0,    0,  236,
407     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
408     0,    1,    0,    0,  261,    0,    0,    0,    0,    0,
409     0,    0,  -25,    0,  -11,    0,    0,    0,    0,    0,
410     0,    0,    0,  -10,    0,    0,    0,    0,    0,    0,
411     0,    0,    0,    0,  300,    0,    0,    0,    0,    0,
412     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
413     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
414     0,    0,    0,    0,   26,    0,    0,    0,    0,    0,
415     0,   52,   78,  104,    0,  130,    0,  -29,    0,    0,
416     0,    0,  340,    0,    0,    0,  313,    0,    0,    0,
417   365,  391,    0,    0,    0,    0,    0,    0,    0,    0,
418     0,    0,    0,    0,    0,    0,};
419 #if defined(__cplusplus) || defined(__STDC__)
420 const short yygindex[] =
421 #else
422 short yygindex[] =
423 #endif
424         {                                      0,
425   -27,   40,   12,    7,  -87,   56,    0,  -36,  -32,   87,
426   -16,    0,    0,    0,    0,    0,    0,    0,    0,   18,
427     0,    0,  -14,    0,    0,    5,    0,   19,  -19,    0,
428     0,    0,  -80,    0,    0,   39,    0,   38,    0,    0,
429    35,    0,   42,    0,   34,
430 };
431 #define YYTABLESIZE 666
432 #if defined(__cplusplus) || defined(__STDC__)
433 const short yytable[] =
434 #else
435 short yytable[] =
436 #endif
437         {                                      43,
438    22,   55,   53,   51,   51,  114,   33,   19,    1,   34,
439    35,   36,  109,  128,  129,   74,    2,    3,    4,    5,
440    84,   15,   17,   37,   79,   76,   80,   16,    6,    7,
441     8,    9,   10,   22,  127,  106,  107,   97,   46,  125,
442    47,   48,   78,   49,   22,   56,   20,   23,   57,   58,
443    59,   82,   26,  108,  146,   50,   29,   82,   76,   66,
444    68,   70,   60,   72,   81,   84,   74,   86,   87,   89,
445    91,   93,  105,   96,  113,   98,   99,   92,  100,  120,
446   121,  133,  122,   76,   82,  134,  128,  138,  139,  129,
447    83,  124,  104,   73,   38,  137,  103,   32,  136,  101,
448   115,  126,  102,   88,   88,   90,   94,   95,    0,   82,
449    92,   92,    0,    0,    0,    0,    0,    0,    0,    0,
450     0,   51,    0,    0,    0,    0,    0,    0,    0,   29,
451     0,    0,    0,    0,    0,   92,   88,    0,    0,    0,
452     0,    0,    0,    0,    0,    0,   61,    0,    0,    0,
453     0,    0,    0,    0,    0,    8,    0,    0,    0,    0,
454     0,   88,   29,    0,    0,    0,    0,    0,    0,    0,
455     0,    0,    0,    5,    0,    0,    0,    0,    0,    0,
456     9,    0,    0,    0,    0,    0,    0,   29,    8,    0,
457     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
458     0,    0,    0,    0,    0,    7,    0,    0,    0,    0,
459     0,    0,    0,    9,    0,    0,    0,    0,    0,    0,
460     0,    0,    0,    0,    0,   42,    0,   51,   51,   46,
461     0,   47,   48,   19,   49,   10,  106,  107,    7,   51,
462    51,   51,   51,   51,   51,   51,   50,   15,   17,    0,
463     0,    0,   51,   51,  108,    0,   22,    0,   22,    0,
464    20,   22,   22,   22,   22,   22,   22,   22,   10,    0,
465     0,    0,    0,    0,    0,   22,   22,   22,   22,   22,
466    22,   76,    0,   76,    0,    0,   76,   76,   76,   76,
467    76,   76,   76,   20,    0,    0,    0,    0,    0,    6,
468    76,   76,   76,   76,   76,   76,  109,   82,    0,   82,
469     0,    0,   82,   82,   82,   82,   82,   82,   82,   33,
470     0,    0,   34,   35,   36,    0,   82,   82,   82,   82,
471    82,   82,    6,   92,    0,   92,   37,    0,   92,   92,
472    92,   92,   92,   92,   92,   52,   46,    0,   47,   48,
473     0,   49,   92,   92,   92,   92,   92,   92,    0,   88,
474     0,   88,    0,   50,   88,   88,   88,   88,   88,   88,
475    88,   56,   46,    0,   57,   58,   59,    0,   88,   88,
476    88,   88,   88,   88,    0,   29,    0,   29,   60,    0,
477    29,   29,   29,   29,   29,   29,   29,   47,    5,    0,
478     0,    5,    5,    5,   29,   29,   29,   29,   29,   29,
479     0,    8,    0,    8,    0,    5,    8,    8,    8,    8,
480     8,    8,    8,   48,    0,    0,    0,    0,    0,    0,
481     8,    8,    8,    8,    8,    8,    9,    0,    9,    0,
482     0,    9,    9,    9,    9,    9,    9,    9,    0,    0,
483     0,    0,    0,    0,    0,    9,    9,    9,    9,    9,
484     9,    7,    0,    7,    0,    0,    7,    7,    7,    7,
485     7,    7,    7,    0,    0,    0,    0,    0,    0,    0,
486     7,    7,    7,    7,    7,    7,    0,    0,    0,    0,
487     0,   10,    0,   10,    0,    0,   10,   10,   10,   10,
488    10,   10,   10,    0,    0,    0,    0,    0,    0,    0,
489    10,   10,   10,   10,   10,   10,   20,    0,   20,    0,
490     0,   20,   20,   20,   20,   20,   20,   20,    0,    0,
491   106,  107,    0,    0,    0,   20,   20,   20,   20,   20,
492    20,    0,  140,  141,  142,  143,  144,  145,  108,    0,
493     0,    0,    0,    0,    0,    6,    0,    6,    0,    0,
494     6,    6,    6,    6,    6,    6,    6,    0,    0,   52,
495    52,    0,    0,    0,    6,    6,    6,    6,    6,    6,
496     0,   52,   52,   52,   52,   52,   52,   52,    0,    0,
497     0,    0,    0,    0,   52,   52,   46,   46,    0,    0,
498     0,    0,    0,    0,    0,    0,    0,    0,   46,   46,
499    46,   46,   46,   46,   46,    0,    0,    0,    0,    0,
500     0,   47,   47,    0,    0,    0,    0,    0,    0,    0,
501     0,    0,    0,   47,   47,   47,   47,   47,   47,   47,
502     0,    0,    0,    0,    0,    0,    0,   48,   48,    0,
503     0,    0,    0,    0,    0,    0,    0,    0,    0,   48,
504    48,   48,   48,   48,   48,   48,
505 };
506 #if defined(__cplusplus) || defined(__STDC__)
507 const short yycheck[] =
508 #else
509 short yycheck[] =
510 #endif
511         {                                      33,
512     0,   18,   17,   33,   33,   93,  258,   33,  256,  261,
513   262,  263,   33,  282,  283,   44,  264,  265,  266,  267,
514    44,   33,   33,  275,   43,    0,   45,  276,  276,  277,
515   278,  279,  280,   33,  122,  257,  258,   61,  258,  120,
516   260,  261,   61,  263,   44,  258,  258,  258,  261,  262,
517   263,    0,  258,  275,  135,  275,  258,   44,   33,   58,
518    58,   58,  275,   58,  259,   44,   44,   44,   61,   61,
519    61,   61,   87,   58,   91,  263,  263,    0,  263,   44,
520    44,   61,  268,   58,   33,   61,  282,  263,  263,  283,
521    51,  119,   86,   38,   33,  132,   85,   11,  131,   82,
522    96,  121,   84,    0,   66,   68,   72,   74,   -1,   58,
523    33,   70,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
524    -1,   33,   -1,   -1,   -1,   -1,   -1,   -1,   -1,    0,
525    -1,   -1,   -1,   -1,   -1,   58,   33,   -1,   -1,   -1,
526    -1,   -1,   -1,   -1,   -1,   -1,   33,   -1,   -1,   -1,
527    -1,   -1,   -1,   -1,   -1,    0,   -1,   -1,   -1,   -1,
528    -1,   58,   33,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
529    -1,   -1,   -1,   33,   -1,   -1,   -1,   -1,   -1,   -1,
530     0,   -1,   -1,   -1,   -1,   -1,   -1,   58,   33,   -1,
531    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
532    -1,   -1,   -1,   -1,   -1,    0,   -1,   -1,   -1,   -1,
533    -1,   -1,   -1,   33,   -1,   -1,   -1,   -1,   -1,   -1,
534    -1,   -1,   -1,   -1,   -1,  259,   -1,  257,  258,  258,
535    -1,  260,  261,  259,  263,    0,  257,  258,   33,  269,
536   270,  271,  272,  273,  274,  275,  275,  259,  259,   -1,
537    -1,   -1,  282,  283,  275,   -1,  256,   -1,  258,   -1,
538     0,  261,  262,  263,  264,  265,  266,  267,   33,   -1,
539    -1,   -1,   -1,   -1,   -1,  275,  276,  277,  278,  279,
540   280,  256,   -1,  258,   -1,   -1,  261,  262,  263,  264,
541   265,  266,  267,   33,   -1,   -1,   -1,   -1,   -1,    0,
542   275,  276,  277,  278,  279,  280,   33,  256,   -1,  258,
543    -1,   -1,  261,  262,  263,  264,  265,  266,  267,  258,
544    -1,   -1,  261,  262,  263,   -1,  275,  276,  277,  278,
545   279,  280,   33,  256,   -1,  258,  275,   -1,  261,  262,
546   263,  264,  265,  266,  267,   33,  258,   -1,  260,  261,
547    -1,  263,  275,  276,  277,  278,  279,  280,   -1,  256,
548    -1,  258,   -1,  275,  261,  262,  263,  264,  265,  266,
549   267,  258,   33,   -1,  261,  262,  263,   -1,  275,  276,
550   277,  278,  279,  280,   -1,  256,   -1,  258,  275,   -1,
551   261,  262,  263,  264,  265,  266,  267,   33,  258,   -1,
552    -1,  261,  262,  263,  275,  276,  277,  278,  279,  280,
553    -1,  256,   -1,  258,   -1,  275,  261,  262,  263,  264,
554   265,  266,  267,   33,   -1,   -1,   -1,   -1,   -1,   -1,
555   275,  276,  277,  278,  279,  280,  256,   -1,  258,   -1,
556    -1,  261,  262,  263,  264,  265,  266,  267,   -1,   -1,
557    -1,   -1,   -1,   -1,   -1,  275,  276,  277,  278,  279,
558   280,  256,   -1,  258,   -1,   -1,  261,  262,  263,  264,
559   265,  266,  267,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
560   275,  276,  277,  278,  279,  280,   -1,   -1,   -1,   -1,
561    -1,  256,   -1,  258,   -1,   -1,  261,  262,  263,  264,
562   265,  266,  267,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
563   275,  276,  277,  278,  279,  280,  256,   -1,  258,   -1,
564    -1,  261,  262,  263,  264,  265,  266,  267,   -1,   -1,
565   257,  258,   -1,   -1,   -1,  275,  276,  277,  278,  279,
566   280,   -1,  269,  270,  271,  272,  273,  274,  275,   -1,
567    -1,   -1,   -1,   -1,   -1,  256,   -1,  258,   -1,   -1,
568   261,  262,  263,  264,  265,  266,  267,   -1,   -1,  257,
569   258,   -1,   -1,   -1,  275,  276,  277,  278,  279,  280,
570    -1,  269,  270,  271,  272,  273,  274,  275,   -1,   -1,
571    -1,   -1,   -1,   -1,  282,  283,  257,  258,   -1,   -1,
572    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  269,  270,
573   271,  272,  273,  274,  275,   -1,   -1,   -1,   -1,   -1,
574    -1,  257,  258,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
575    -1,   -1,   -1,  269,  270,  271,  272,  273,  274,  275,
576    -1,   -1,   -1,   -1,   -1,   -1,   -1,  257,  258,   -1,
577    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  269,
578   270,  271,  272,  273,  274,  275,
579 };
580 #define YYFINAL 11
581 #ifndef YYDEBUG
582 #define YYDEBUG 0
583 #endif
584 #define YYMAXTOKEN 283
585 #if YYDEBUG
586 #if defined(__cplusplus) || defined(__STDC__)
587 const char * const yyname[] =
588 #else
589 char *yyname[] =
590 #endif
591         {
592 "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,
593 "'!'",0,0,0,0,0,0,0,0,0,"'+'","','","'-'",0,0,0,0,0,0,0,0,0,0,0,0,"':'",0,0,
594 "'='",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,
595 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,
596 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,
597 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,
598 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,
599 "COMMAND","ALIAS","DEFVAR","NTWKADDR","NETGROUP","USERGROUP","WORD","DEFAULTS",
600 "DEFAULTS_HOST","DEFAULTS_USER","DEFAULTS_RUNAS","RUNAS","NOPASSWD","PASSWD",
601 "NOEXEC","EXEC","SETENV","NOSETENV","ALL","COMMENT","HOSTALIAS","CMNDALIAS",
602 "USERALIAS","RUNASALIAS","ERROR","TYPE","ROLE",
603 };
604 #if defined(__cplusplus) || defined(__STDC__)
605 const char * const yyrule[] =
606 #else
607 char *yyrule[] =
608 #endif
609         {"$accept : file",
610 "file : entry",
611 "file : file entry",
612 "entry : COMMENT",
613 "entry : error COMMENT",
614 "$$1 :",
615 "entry : $$1 userlist privileges",
616 "entry : USERALIAS useraliases",
617 "entry : HOSTALIAS hostaliases",
618 "entry : CMNDALIAS cmndaliases",
619 "entry : RUNASALIAS runasaliases",
620 "entry : defaults_line",
621 "defaults_line : defaults_type defaults_list",
622 "defaults_type : DEFAULTS",
623 "$$2 :",
624 "defaults_type : DEFAULTS_USER $$2 userlist",
625 "$$3 :",
626 "defaults_type : DEFAULTS_RUNAS $$3 runaslist",
627 "$$4 :",
628 "defaults_type : DEFAULTS_HOST $$4 hostlist",
629 "defaults_list : defaults_entry",
630 "defaults_list : defaults_entry ',' defaults_list",
631 "defaults_entry : DEFVAR",
632 "defaults_entry : '!' DEFVAR",
633 "defaults_entry : DEFVAR '=' WORD",
634 "defaults_entry : DEFVAR '+' WORD",
635 "defaults_entry : DEFVAR '-' WORD",
636 "privileges : privilege",
637 "privileges : privileges ':' privilege",
638 "privilege : hostlist '=' cmndspeclist",
639 "ophost : host",
640 "ophost : '!' host",
641 "host : ALL",
642 "host : NTWKADDR",
643 "host : NETGROUP",
644 "host : WORD",
645 "host : ALIAS",
646 "cmndspeclist : cmndspec",
647 "cmndspeclist : cmndspeclist ',' cmndspec",
648 "$$5 :",
649 "cmndspec : $$5 runasspec selinux cmndtag opcmnd",
650 "opcmnd : cmnd",
651 "$$6 :",
652 "opcmnd : '!' $$6 cmnd",
653 "rolespec : ROLE '=' WORD",
654 "typespec : TYPE '=' WORD",
655 "selinux :",
656 "selinux : rolespec",
657 "selinux : typespec",
658 "selinux : rolespec typespec",
659 "selinux : typespec rolespec",
660 "runasspec :",
661 "runasspec : RUNAS runaslist",
662 "runaslist : oprunasuser",
663 "runaslist : runaslist ',' oprunasuser",
664 "oprunasuser : runasuser",
665 "$$7 :",
666 "oprunasuser : '!' $$7 runasuser",
667 "runasuser : WORD",
668 "runasuser : USERGROUP",
669 "runasuser : NETGROUP",
670 "runasuser : ALIAS",
671 "runasuser : ALL",
672 "cmndtag :",
673 "cmndtag : cmndtag NOPASSWD",
674 "cmndtag : cmndtag PASSWD",
675 "cmndtag : cmndtag NOEXEC",
676 "cmndtag : cmndtag EXEC",
677 "cmndtag : cmndtag SETENV",
678 "cmndtag : cmndtag NOSETENV",
679 "cmnd : ALL",
680 "cmnd : ALIAS",
681 "cmnd : COMMAND",
682 "hostaliases : hostalias",
683 "hostaliases : hostaliases ':' hostalias",
684 "$$8 :",
685 "hostalias : ALIAS $$8 '=' hostlist",
686 "hostlist : ophost",
687 "hostlist : hostlist ',' ophost",
688 "cmndaliases : cmndalias",
689 "cmndaliases : cmndaliases ':' cmndalias",
690 "$$9 :",
691 "cmndalias : ALIAS $$9 '=' cmndlist",
692 "cmndlist : opcmnd",
693 "cmndlist : cmndlist ',' opcmnd",
694 "runasaliases : runasalias",
695 "runasaliases : runasaliases ':' runasalias",
696 "$$10 :",
697 "runasalias : ALIAS $$10 '=' runaslist",
698 "useraliases : useralias",
699 "useraliases : useraliases ':' useralias",
700 "$$11 :",
701 "useralias : ALIAS $$11 '=' userlist",
702 "userlist : opuser",
703 "userlist : userlist ',' opuser",
704 "opuser : user",
705 "opuser : '!' user",
706 "user : WORD",
707 "user : USERGROUP",
708 "user : NETGROUP",
709 "user : ALIAS",
710 "user : ALL",
711 };
712 #endif
713 #ifdef YYSTACKSIZE
714 #undef YYMAXDEPTH
715 #define YYMAXDEPTH YYSTACKSIZE
716 #else
717 #ifdef YYMAXDEPTH
718 #define YYSTACKSIZE YYMAXDEPTH
719 #else
720 #define YYSTACKSIZE 10000
721 #define YYMAXDEPTH 10000
722 #endif
723 #endif
724 #define YYINITSTACKSIZE 200
725 /* LINTUSED */
726 int yydebug;
727 int yynerrs;
728 int yyerrflag;
729 int yychar;
730 short *yyssp;
731 YYSTYPE *yyvsp;
732 YYSTYPE yyval;
733 YYSTYPE yylval;
734 short *yyss;
735 short *yysslim;
736 YYSTYPE *yyvs;
737 int yystacksize;
738 #line 1053 "parse.yacc"
739
740 #define MOREALIASES (32)
741 aliasinfo *aliases = NULL;
742 size_t naliases = 0;
743 size_t nslots = 0;
744
745
746 /*
747  * Compare two aliasinfo structures, strcmp() style.
748  * Note that we do *not* compare their values.
749  */
750 static int
751 aliascmp(a1, a2)
752     const VOID *a1, *a2;
753 {
754     int r;
755     aliasinfo *ai1, *ai2;
756
757     ai1 = (aliasinfo *) a1;
758     ai2 = (aliasinfo *) a2;
759     if ((r = strcmp(ai1->name, ai2->name)) == 0)
760         r = ai1->type - ai2->type;
761
762     return(r);
763 }
764
765 /*
766  * Compare two generic_alias structures, strcmp() style.
767  */
768 static int
769 genaliascmp(entry, key)
770     const VOID *entry, *key;
771 {
772     int r;
773     struct generic_alias *ga1, *ga2;
774
775     ga1 = (struct generic_alias *) key;
776     ga2 = (struct generic_alias *) entry;
777     if ((r = strcmp(ga1->alias, ga2->alias)) == 0)
778         r = ga1->type - ga2->type;
779
780     return(r);
781 }
782
783
784 /*
785  * Adds the named alias of the specified type to the aliases list.
786  */
787 static int
788 add_alias(alias, type, val)
789     char *alias;
790     int type;
791     int val;
792 {
793     aliasinfo ai, *aip;
794     size_t onaliases;
795     char s[512];
796
797     if (naliases >= nslots)
798         more_aliases();
799
800     ai.type = type;
801     ai.val = val;
802     ai.name = estrdup(alias);
803     onaliases = naliases;
804
805     aip = (aliasinfo *) lsearch((VOID *)&ai, (VOID *)aliases, &naliases,
806                                 sizeof(ai), aliascmp);
807     if (aip == NULL) {
808         (void) snprintf(s, sizeof(s), "Aliases corrupted defining alias `%s'",
809                         alias);
810         yyerror(s);
811         return(FALSE);
812     }
813     if (onaliases == naliases) {
814         (void) snprintf(s, sizeof(s), "Alias `%s' already defined", alias);
815         yyerror(s);
816         return(FALSE);
817     }
818
819     return(TRUE);
820 }
821
822 /*
823  * Searches for the named alias of the specified type.
824  */
825 static aliasinfo *
826 find_alias(alias, type)
827     char *alias;
828     int type;
829 {
830     aliasinfo ai;
831
832     ai.name = alias;
833     ai.type = type;
834
835     return((aliasinfo *) lfind((VOID *)&ai, (VOID *)aliases, &naliases,
836                  sizeof(ai), aliascmp));
837 }
838
839 /*
840  * Allocates more space for the aliases list.
841  */
842 static void
843 more_aliases()
844 {
845
846     nslots += MOREALIASES;
847     aliases = (aliasinfo *) erealloc3(aliases, nslots, sizeof(aliasinfo));
848 }
849
850 /*
851  * Lists the contents of the aliases list.
852  */
853 void
854 dumpaliases()
855 {
856     size_t n;
857
858     for (n = 0; n < naliases; n++) {
859         if (aliases[n].val == -1)
860             continue;
861
862         switch (aliases[n].type) {
863         case HOST_ALIAS:
864             (void) puts("HOST_ALIAS");
865             break;
866
867         case CMND_ALIAS:
868             (void) puts("CMND_ALIAS");
869             break;
870
871         case USER_ALIAS:
872             (void) puts("USER_ALIAS");
873             break;
874
875         case RUNAS_ALIAS:
876             (void) puts("RUNAS_ALIAS");
877             break;
878         }
879         (void) printf("\t%s: %d\n", aliases[n].name, aliases[n].val);
880     }
881 }
882
883 /*
884  * Lists the contents of cm_list and ga_list for `sudo -l'.
885  */
886 void
887 list_matches()
888 {
889     size_t count;
890     char *p;
891     struct generic_alias *ga, key;
892
893     (void) printf("User %s may run the following commands on this host:\n",
894         user_name);
895     for (count = 0; count < cm_list_len; count++) {
896
897         /* Print the runas list. */
898         (void) fputs("    ", stdout);
899         if (cm_list[count].runas) {
900             (void) putchar('(');
901             p = strtok(cm_list[count].runas, ", ");
902             do {
903                 if (p != cm_list[count].runas)
904                     (void) fputs(", ", stdout);
905
906                 key.alias = p;
907                 key.type = RUNAS_ALIAS;
908                 if ((ga = (struct generic_alias *) lfind((VOID *) &key,
909                     (VOID *) &ga_list[0], &ga_list_len, sizeof(key), genaliascmp)))
910                     (void) fputs(ga->entries, stdout);
911                 else
912                     (void) fputs(p, stdout);
913             } while ((p = strtok(NULL, ", ")));
914             (void) fputs(") ", stdout);
915         } else {
916             (void) printf("(%s) ", def_runas_default);
917         }
918
919 #ifdef HAVE_SELINUX
920         /* SELinux role and type */
921         if (cm_list[count].role != NULL)
922             (void) printf("ROLE=%s ", cm_list[count].role);
923         if (cm_list[count].type != NULL)
924             (void) printf("TYPE=%s ", cm_list[count].type);
925 #endif
926
927         /* Is execve(2) disabled? */
928         if (cm_list[count].noexecve == TRUE && !def_noexec)
929             (void) fputs("NOEXEC: ", stdout);
930         else if (cm_list[count].noexecve == FALSE && def_noexec)
931             (void) fputs("EXEC: ", stdout);
932
933         /* Is a password required? */
934         if (cm_list[count].nopasswd == TRUE && def_authenticate)
935             (void) fputs("NOPASSWD: ", stdout);
936         else if (cm_list[count].nopasswd == FALSE && !def_authenticate)
937             (void) fputs("PASSWD: ", stdout);
938
939         /* Is setenv enabled? */
940         if (cm_list[count].setenv == TRUE && !def_setenv)
941             (void) fputs("SETENV: ", stdout);
942         else if (cm_list[count].setenv == FALSE && def_setenv)
943             (void) fputs("NOSETENV: ", stdout);
944
945         /* Print the actual command or expanded Cmnd_Alias. */
946         key.alias = cm_list[count].cmnd;
947         key.type = CMND_ALIAS;
948         if ((ga = (struct generic_alias *) lfind((VOID *) &key,
949             (VOID *) &ga_list[0], &ga_list_len, sizeof(key), genaliascmp)))
950             (void) puts(ga->entries);
951         else
952             (void) puts(cm_list[count].cmnd);
953     }
954
955     /* Be nice and free up space now that we are done. */
956     for (count = 0; count < ga_list_len; count++) {
957         efree(ga_list[count].alias);
958         efree(ga_list[count].entries);
959     }
960     efree(ga_list);
961     ga_list = NULL;
962
963     for (count = 0; count < cm_list_len; count++) {
964         efree(cm_list[count].runas);
965         efree(cm_list[count].cmnd);
966         efree(cm_list[count].role);
967         efree(cm_list[count].type);
968     }
969     efree(cm_list);
970     cm_list = NULL;
971     cm_list_len = 0;
972     cm_list_size = 0;
973 }
974
975 /*
976  * Appends a source string to the destination, optionally prefixing a separator.
977  */
978 static void
979 append(src, dstp, dst_len, dst_size, separator)
980     char *src, **dstp;
981     size_t *dst_len, *dst_size;
982     char *separator;
983 {
984     size_t src_len = strlen(src);
985     char *dst = *dstp;
986
987     /*
988      * Only add the separator if there is something to separate from.
989      * If the last char is a '!', don't apply the separator (XXX).
990      */
991     if (separator && dst && dst[*dst_len - 1] != '!')
992         src_len += strlen(separator);
993     else
994         separator = NULL;
995
996     /* Assumes dst will be NULL if not set. */
997     if (dst == NULL) {
998         dst = (char *) emalloc(BUFSIZ);
999         *dst = '\0';
1000         *dst_size = BUFSIZ;
1001         *dst_len = 0;
1002         *dstp = dst;
1003     }
1004
1005     /* Allocate more space if necessary. */
1006     if (*dst_size <= *dst_len + src_len) {
1007         while (*dst_size <= *dst_len + src_len)
1008             *dst_size += BUFSIZ;
1009
1010         dst = (char *) erealloc(dst, *dst_size);
1011         *dstp = dst;
1012     }
1013
1014     /* Copy src -> dst adding a separator if appropriate and adjust len. */
1015     if (separator)
1016         (void) strlcat(dst, separator, *dst_size);
1017     (void) strlcat(dst, src, *dst_size);
1018     *dst_len += src_len;
1019 }
1020
1021 /*
1022  * Frees up space used by the aliases list and resets the associated counters.
1023  */
1024 void
1025 reset_aliases()
1026 {
1027     size_t n;
1028
1029     if (aliases) {
1030         for (n = 0; n < naliases; n++)
1031             efree(aliases[n].name);
1032         efree(aliases);
1033         aliases = NULL;
1034     }
1035     naliases = nslots = 0;
1036 }
1037
1038 /*
1039  * Increments ga_list_len, allocating more space as necessary.
1040  */
1041 static void
1042 expand_ga_list()
1043 {
1044
1045     if (++ga_list_len >= ga_list_size) {
1046         while ((ga_list_size += STACKINCREMENT) < ga_list_len)
1047             ;
1048         ga_list = (struct generic_alias *)
1049             erealloc3(ga_list, ga_list_size, sizeof(struct generic_alias));
1050     }
1051
1052     ga_list[ga_list_len - 1].entries = NULL;
1053 }
1054
1055 /*
1056  * Increments cm_list_len, allocating more space as necessary.
1057  */
1058 static void
1059 expand_match_list()
1060 {
1061
1062     if (++cm_list_len >= cm_list_size) {
1063         while ((cm_list_size += STACKINCREMENT) < cm_list_len)
1064             ;
1065         if (cm_list == NULL)
1066             cm_list_len = 0;            /* start at 0 since it is a subscript */
1067         cm_list = (struct command_match *)
1068             erealloc3(cm_list, cm_list_size, sizeof(struct command_match));
1069     }
1070
1071     cm_list[cm_list_len].runas = cm_list[cm_list_len].cmnd = NULL;
1072     cm_list[cm_list_len].type = cm_list[cm_list_len].role = NULL;
1073     cm_list[cm_list_len].nopasswd = FALSE;
1074     cm_list[cm_list_len].noexecve = FALSE;
1075     cm_list[cm_list_len].setenv = FALSE;
1076 }
1077
1078 /*
1079  * Frees up spaced used by a previous parser run and allocates new space
1080  * for various data structures.
1081  */
1082 void
1083 init_parser()
1084 {
1085
1086     /* Free up old data structures if we run the parser more than once. */
1087     if (match) {
1088         efree(match);
1089         match = NULL;
1090         top = 0;
1091         parse_error = FALSE;
1092         used_runas = FALSE;
1093         errorlineno = -1;
1094         sudolineno = 1;
1095     }
1096
1097     /* Allocate space for the matching stack. */
1098     stacksize = STACKINCREMENT;
1099     match = (struct matchstack *) emalloc2(stacksize, sizeof(struct matchstack));
1100
1101     /* Allocate space for the match list (for `sudo -l'). */
1102     if (printmatches == TRUE)
1103         expand_match_list();
1104 }
1105 #line 1054 "sudo.tab.c"
1106 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
1107 #if defined(__cplusplus) || defined(__STDC__)
1108 static int yygrowstack(void)
1109 #else
1110 static int yygrowstack()
1111 #endif
1112 {
1113     int newsize, i;
1114     short *newss;
1115     YYSTYPE *newvs;
1116
1117     if ((newsize = yystacksize) == 0)
1118         newsize = YYINITSTACKSIZE;
1119     else if (newsize >= YYMAXDEPTH)
1120         return -1;
1121     else if ((newsize *= 2) > YYMAXDEPTH)
1122         newsize = YYMAXDEPTH;
1123     i = yyssp - yyss;
1124 #ifdef SIZE_MAX
1125 #define YY_SIZE_MAX SIZE_MAX
1126 #else
1127 #define YY_SIZE_MAX 0x7fffffff
1128 #endif
1129     if (newsize && YY_SIZE_MAX / newsize < sizeof *newss)
1130         goto bail;
1131     newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :
1132       (short *)malloc(newsize * sizeof *newss); /* overflow check above */
1133     if (newss == NULL)
1134         goto bail;
1135     yyss = newss;
1136     yyssp = newss + i;
1137     if (newsize && YY_SIZE_MAX / newsize < sizeof *newvs)
1138         goto bail;
1139     newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :
1140       (YYSTYPE *)malloc(newsize * sizeof *newvs); /* overflow check above */
1141     if (newvs == NULL)
1142         goto bail;
1143     yyvs = newvs;
1144     yyvsp = newvs + i;
1145     yystacksize = newsize;
1146     yysslim = yyss + newsize - 1;
1147     return 0;
1148 bail:
1149     if (yyss)
1150             free(yyss);
1151     if (yyvs)
1152             free(yyvs);
1153     yyss = yyssp = NULL;
1154     yyvs = yyvsp = NULL;
1155     yystacksize = 0;
1156     return -1;
1157 }
1158
1159 #define YYABORT goto yyabort
1160 #define YYREJECT goto yyabort
1161 #define YYACCEPT goto yyaccept
1162 #define YYERROR goto yyerrlab
1163 int
1164 #if defined(__cplusplus) || defined(__STDC__)
1165 yyparse(void)
1166 #else
1167 yyparse()
1168 #endif
1169 {
1170     int yym, yyn, yystate;
1171 #if YYDEBUG
1172 #if defined(__cplusplus) || defined(__STDC__)
1173     const char *yys;
1174 #else /* !(defined(__cplusplus) || defined(__STDC__)) */
1175     char *yys;
1176 #endif /* !(defined(__cplusplus) || defined(__STDC__)) */
1177
1178     if ((yys = getenv("YYDEBUG")))
1179     {
1180         yyn = *yys;
1181         if (yyn >= '0' && yyn <= '9')
1182             yydebug = yyn - '0';
1183     }
1184 #endif /* YYDEBUG */
1185
1186     yynerrs = 0;
1187     yyerrflag = 0;
1188     yychar = (-1);
1189
1190     if (yyss == NULL && yygrowstack()) goto yyoverflow;
1191     yyssp = yyss;
1192     yyvsp = yyvs;
1193     *yyssp = yystate = 0;
1194
1195 yyloop:
1196     if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
1197     if (yychar < 0)
1198     {
1199         if ((yychar = yylex()) < 0) yychar = 0;
1200 #if YYDEBUG
1201         if (yydebug)
1202         {
1203             yys = 0;
1204             if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1205             if (!yys) yys = "illegal-symbol";
1206             printf("%sdebug: state %d, reading %d (%s)\n",
1207                     YYPREFIX, yystate, yychar, yys);
1208         }
1209 #endif
1210     }
1211     if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
1212             yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
1213     {
1214 #if YYDEBUG
1215         if (yydebug)
1216             printf("%sdebug: state %d, shifting to state %d\n",
1217                     YYPREFIX, yystate, yytable[yyn]);
1218 #endif
1219         if (yyssp >= yysslim && yygrowstack())
1220         {
1221             goto yyoverflow;
1222         }
1223         *++yyssp = yystate = yytable[yyn];
1224         *++yyvsp = yylval;
1225         yychar = (-1);
1226         if (yyerrflag > 0)  --yyerrflag;
1227         goto yyloop;
1228     }
1229     if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
1230             yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
1231     {
1232         yyn = yytable[yyn];
1233         goto yyreduce;
1234     }
1235     if (yyerrflag) goto yyinrecovery;
1236 #if defined(lint) || defined(__GNUC__)
1237     goto yynewerror;
1238 #endif
1239 yynewerror:
1240     yyerror("syntax error");
1241 #if defined(lint) || defined(__GNUC__)
1242     goto yyerrlab;
1243 #endif
1244 yyerrlab:
1245     ++yynerrs;
1246 yyinrecovery:
1247     if (yyerrflag < 3)
1248     {
1249         yyerrflag = 3;
1250         for (;;)
1251         {
1252             if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
1253                     yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
1254             {
1255 #if YYDEBUG
1256                 if (yydebug)
1257                     printf("%sdebug: state %d, error recovery shifting\
1258  to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
1259 #endif
1260                 if (yyssp >= yysslim && yygrowstack())
1261                 {
1262                     goto yyoverflow;
1263                 }
1264                 *++yyssp = yystate = yytable[yyn];
1265                 *++yyvsp = yylval;
1266                 goto yyloop;
1267             }
1268             else
1269             {
1270 #if YYDEBUG
1271                 if (yydebug)
1272                     printf("%sdebug: error recovery discarding state %d\n",
1273                             YYPREFIX, *yyssp);
1274 #endif
1275                 if (yyssp <= yyss) goto yyabort;
1276                 --yyssp;
1277                 --yyvsp;
1278             }
1279         }
1280     }
1281     else
1282     {
1283         if (yychar == 0) goto yyabort;
1284 #if YYDEBUG
1285         if (yydebug)
1286         {
1287             yys = 0;
1288             if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1289             if (!yys) yys = "illegal-symbol";
1290             printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
1291                     YYPREFIX, yystate, yychar, yys);
1292         }
1293 #endif
1294         yychar = (-1);
1295         goto yyloop;
1296     }
1297 yyreduce:
1298 #if YYDEBUG
1299     if (yydebug)
1300         printf("%sdebug: state %d, reducing by rule %d (%s)\n",
1301                 YYPREFIX, yystate, yyn, yyrule[yyn]);
1302 #endif
1303     yym = yylen[yyn];
1304     yyval = yyvsp[1-yym];
1305     switch (yyn)
1306     {
1307 case 3:
1308 #line 313 "parse.yacc"
1309 { ; }
1310 break;
1311 case 4:
1312 #line 315 "parse.yacc"
1313 { yyerrok; }
1314 break;
1315 case 5:
1316 #line 316 "parse.yacc"
1317 { push; }
1318 break;
1319 case 6:
1320 #line 316 "parse.yacc"
1321 {
1322                             while (top && user_matches != TRUE)
1323                                 pop;
1324                         }
1325 break;
1326 case 7:
1327 #line 321 "parse.yacc"
1328 { ; }
1329 break;
1330 case 8:
1331 #line 323 "parse.yacc"
1332 { ; }
1333 break;
1334 case 9:
1335 #line 325 "parse.yacc"
1336 { ; }
1337 break;
1338 case 10:
1339 #line 327 "parse.yacc"
1340 { ; }
1341 break;
1342 case 11:
1343 #line 329 "parse.yacc"
1344 { ; }
1345 break;
1346 case 13:
1347 #line 335 "parse.yacc"
1348 {
1349                             defaults_matches = TRUE;
1350                         }
1351 break;
1352 case 14:
1353 #line 338 "parse.yacc"
1354 { push; }
1355 break;
1356 case 15:
1357 #line 338 "parse.yacc"
1358 {
1359                             defaults_matches = user_matches;
1360                             pop;
1361                         }
1362 break;
1363 case 16:
1364 #line 342 "parse.yacc"
1365 { push; }
1366 break;
1367 case 17:
1368 #line 342 "parse.yacc"
1369 {
1370                             defaults_matches = yyvsp[0].BOOLEAN == TRUE;
1371                             pop;
1372                         }
1373 break;
1374 case 18:
1375 #line 346 "parse.yacc"
1376 { push; }
1377 break;
1378 case 19:
1379 #line 346 "parse.yacc"
1380 {
1381                             defaults_matches = host_matches;
1382                             pop;
1383                         }
1384 break;
1385 case 22:
1386 #line 356 "parse.yacc"
1387 {
1388                             if (defaults_matches == TRUE &&
1389                                 !set_default(yyvsp[0].string, NULL, TRUE)) {
1390                                 yyerror(NULL);
1391                                 YYERROR;
1392                             }
1393                             efree(yyvsp[0].string);
1394                         }
1395 break;
1396 case 23:
1397 #line 364 "parse.yacc"
1398 {
1399                             if (defaults_matches == TRUE &&
1400                                 !set_default(yyvsp[0].string, NULL, FALSE)) {
1401                                 yyerror(NULL);
1402                                 YYERROR;
1403                             }
1404                             efree(yyvsp[0].string);
1405                         }
1406 break;
1407 case 24:
1408 #line 372 "parse.yacc"
1409 {
1410                             if (defaults_matches == TRUE &&
1411                                 !set_default(yyvsp[-2].string, yyvsp[0].string, TRUE)) {
1412                                 yyerror(NULL);
1413                                 YYERROR;
1414                             }
1415                             efree(yyvsp[-2].string);
1416                             efree(yyvsp[0].string);
1417                         }
1418 break;
1419 case 25:
1420 #line 381 "parse.yacc"
1421 {
1422                             if (defaults_matches == TRUE &&
1423                                 !set_default(yyvsp[-2].string, yyvsp[0].string, '+')) {
1424                                 yyerror(NULL);
1425                                 YYERROR;
1426                             }
1427                             efree(yyvsp[-2].string);
1428                             efree(yyvsp[0].string);
1429                         }
1430 break;
1431 case 26:
1432 #line 390 "parse.yacc"
1433 {
1434                             if (defaults_matches == TRUE &&
1435                                 !set_default(yyvsp[-2].string, yyvsp[0].string, '-')) {
1436                                 yyerror(NULL);
1437                                 YYERROR;
1438                             }
1439                             efree(yyvsp[-2].string);
1440                             efree(yyvsp[0].string);
1441                         }
1442 break;
1443 case 29:
1444 #line 405 "parse.yacc"
1445 {
1446                             /*
1447                              * We already did a push if necessary in
1448                              * cmndspec so just reset some values so
1449                              * the next 'privilege' gets a clean slate.
1450                              */
1451                             host_matches = UNSPEC;
1452                             runas_matches = UNSPEC;
1453                             no_passwd = def_authenticate ? UNSPEC : TRUE;
1454                             no_execve = def_noexec ? TRUE : UNSPEC;
1455                             setenv_ok = def_setenv ? TRUE : UNSPEC;
1456 #ifdef HAVE_SELINUX
1457                             efree(match[top-1].role);
1458                             match[top-1].role = NULL;
1459                             efree(match[top-1].type);
1460                             match[top-1].type = NULL;
1461 #endif
1462                         }
1463 break;
1464 case 30:
1465 #line 425 "parse.yacc"
1466 {
1467                             SETMATCH(host_matches, yyvsp[0].BOOLEAN);
1468                         }
1469 break;
1470 case 31:
1471 #line 428 "parse.yacc"
1472 {
1473                             SETNMATCH(host_matches, yyvsp[0].BOOLEAN);
1474                         }
1475 break;
1476 case 32:
1477 #line 433 "parse.yacc"
1478 {
1479                             yyval.BOOLEAN = TRUE;
1480                         }
1481 break;
1482 case 33:
1483 #line 436 "parse.yacc"
1484 {
1485                             if (addr_matches(yyvsp[0].string))
1486                                 yyval.BOOLEAN = TRUE;
1487                             else
1488                                 yyval.BOOLEAN = NOMATCH;
1489                             efree(yyvsp[0].string);
1490                         }
1491 break;
1492 case 34:
1493 #line 443 "parse.yacc"
1494 {
1495                             if (netgr_matches(yyvsp[0].string, user_host, user_shost, NULL))
1496                                 yyval.BOOLEAN = TRUE;
1497                             else
1498                                 yyval.BOOLEAN = NOMATCH;
1499                             efree(yyvsp[0].string);
1500                         }
1501 break;
1502 case 35:
1503 #line 450 "parse.yacc"
1504 {
1505                             if (hostname_matches(user_shost, user_host, yyvsp[0].string) == 0)
1506                                 yyval.BOOLEAN = TRUE;
1507                             else
1508                                 yyval.BOOLEAN = NOMATCH;
1509                             efree(yyvsp[0].string);
1510                         }
1511 break;
1512 case 36:
1513 #line 457 "parse.yacc"
1514 {
1515                             aliasinfo *aip = find_alias(yyvsp[0].string, HOST_ALIAS);
1516
1517                             /* could be an all-caps hostname */
1518                             if (aip)
1519                                 yyval.BOOLEAN = aip->val;
1520                             else if (strcasecmp(user_shost, yyvsp[0].string) == 0)
1521                                 yyval.BOOLEAN = TRUE;
1522                             else {
1523                                 if (pedantic) {
1524                                     (void) fprintf(stderr,
1525                                         "%s: undeclared Host_Alias `%s' referenced near line %d\n",
1526                                         (pedantic == 1) ? "Warning" : "Error", yyvsp[0].string, sudolineno);
1527                                     if (pedantic > 1) {
1528                                         yyerror(NULL);
1529                                         YYERROR;
1530                                     }
1531                                 }
1532                                 yyval.BOOLEAN = NOMATCH;
1533                             }
1534                             efree(yyvsp[0].string);
1535                         }
1536 break;
1537 case 39:
1538 #line 485 "parse.yacc"
1539 { SETENV_RESET; }
1540 break;
1541 case 40:
1542 #line 485 "parse.yacc"
1543 {
1544 #ifdef HAVE_SELINUX
1545                             /* Replace inherited role/type as needed. */
1546                             if (yyvsp[-2].seinfo.role != NULL) {
1547                                 efree(match[top-1].role);
1548                                 match[top-1].role = yyvsp[-2].seinfo.role;
1549                             }
1550                             if (yyvsp[-2].seinfo.type != NULL) {
1551                                 efree(match[top-1].type);
1552                                 match[top-1].type = yyvsp[-2].seinfo.type;
1553                             }
1554 #endif
1555                             /*
1556                              * Push the entry onto the stack if it is worth
1557                              * saving and reset cmnd_matches for next cmnd.
1558                              *
1559                              * We need to save at least one entry on
1560                              * the stack so sudoers_lookup() can tell that
1561                              * the user was listed in sudoers.  Also, we
1562                              * need to be able to tell whether or not a
1563                              * user was listed for this specific host.
1564                              *
1565                              * If keepall is set and the user matches then
1566                              * we need to keep entries around too...
1567                              */
1568                             if (MATCHED(user_matches) &&
1569                                 MATCHED(host_matches) &&
1570                                 MATCHED(cmnd_matches) &&
1571                                 MATCHED(runas_matches))
1572                                 pushcp;
1573                             else if (MATCHED(user_matches) && (top == 1 ||
1574                                 (top == 2 && MATCHED(host_matches) &&
1575                                 !MATCHED(match[0].host))))
1576                                 pushcp;
1577                             else if (user_matches == TRUE && keepall)
1578                                 pushcp;
1579
1580                             cmnd_matches = UNSPEC;
1581                         }
1582 break;
1583 case 41:
1584 #line 526 "parse.yacc"
1585 {
1586                             SETMATCH(cmnd_matches, yyvsp[0].BOOLEAN);
1587                         }
1588 break;
1589 case 42:
1590 #line 529 "parse.yacc"
1591 {
1592                             if (printmatches == TRUE) {
1593                                 if (in_alias == TRUE)
1594                                     append_entries("!", ", ");
1595                                 else if (host_matches == TRUE &&
1596                                     user_matches == TRUE)
1597                                     append_cmnd("!", NULL);
1598                             }
1599                         }
1600 break;
1601 case 43:
1602 #line 537 "parse.yacc"
1603 {
1604                             SETNMATCH(cmnd_matches, yyvsp[0].BOOLEAN);
1605                         }
1606 break;
1607 case 44:
1608 #line 542 "parse.yacc"
1609 {
1610 #ifdef HAVE_SELINUX
1611                             if (printmatches == TRUE && host_matches == TRUE &&
1612                                 user_matches == TRUE && runas_matches == TRUE)
1613                                 append_role(yyvsp[0].string, NULL);
1614                             yyval.string = yyvsp[0].string;
1615 #else
1616                             free(yyvsp[0].string);
1617                             yyval.string = NULL;
1618 #endif /* HAVE_SELINUX */
1619                         }
1620 break;
1621 case 45:
1622 #line 555 "parse.yacc"
1623 {
1624 #ifdef HAVE_SELINUX
1625                             if (printmatches == TRUE && host_matches == TRUE &&
1626                                 user_matches == TRUE && runas_matches == TRUE)
1627                                 append_type(yyvsp[0].string, NULL);
1628                             yyval.string = yyvsp[0].string;
1629 #else
1630                             free(yyvsp[0].string);
1631                             yyval.string = NULL;
1632 #endif /* HAVE_SELINUX */
1633                         }
1634 break;
1635 case 46:
1636 #line 568 "parse.yacc"
1637 {
1638 #ifdef HAVE_SELINUX
1639                             if (printmatches == TRUE && host_matches == TRUE &&
1640                                 user_matches == TRUE && runas_matches == TRUE) {
1641                                 /* Inherit role. */
1642                                 cm_list[cm_list_len].role =
1643                                     estrdup(cm_list[cm_list_len-1].role);
1644                                 cm_list[cm_list_len].role_len =
1645                                     cm_list[cm_list_len-1].role_len;
1646                                 cm_list[cm_list_len].role_size =
1647                                     cm_list[cm_list_len-1].role_len + 1;
1648                                 /* Inherit type. */
1649                                 cm_list[cm_list_len].type =
1650                                     estrdup(cm_list[cm_list_len-1].type);
1651                                 cm_list[cm_list_len].type_len =
1652                                     cm_list[cm_list_len-1].type_len;
1653                                 cm_list[cm_list_len].type_size =
1654                                     cm_list[cm_list_len-1].type_len + 1;
1655                             }
1656 #endif /* HAVE_SELINUX */
1657                             yyval.seinfo.role = NULL;
1658                             yyval.seinfo.type = NULL;
1659                         }
1660 break;
1661 case 47:
1662 #line 591 "parse.yacc"
1663 {
1664 #ifdef HAVE_SELINUX
1665                             if (printmatches == TRUE && host_matches == TRUE &&
1666                                 user_matches == TRUE && runas_matches == TRUE) {
1667                                 /* Inherit type. */
1668                                 cm_list[cm_list_len].type =
1669                                     estrdup(cm_list[cm_list_len-1].type);
1670                                 cm_list[cm_list_len].type_len =
1671                                     cm_list[cm_list_len-1].type_len;
1672                                 cm_list[cm_list_len].type_size =
1673                                     cm_list[cm_list_len-1].type_len + 1;
1674                             }
1675 #endif /* HAVE_SELINUX */
1676                             yyval.seinfo.role = yyvsp[0].string;
1677                             yyval.seinfo.type = NULL;
1678                         }
1679 break;
1680 case 48:
1681 #line 607 "parse.yacc"
1682 {
1683 #ifdef HAVE_SELINUX
1684                             if (printmatches == TRUE && host_matches == TRUE &&
1685                                 user_matches == TRUE && runas_matches == TRUE) {
1686                                 /* Inherit role. */
1687                                 cm_list[cm_list_len].role =
1688                                     estrdup(cm_list[cm_list_len-1].role);
1689                                 cm_list[cm_list_len].role_len =
1690                                     cm_list[cm_list_len-1].role_len;
1691                                 cm_list[cm_list_len].role_size =
1692                                     cm_list[cm_list_len-1].role_len + 1;
1693                             }
1694 #endif /* HAVE_SELINUX */
1695                             yyval.seinfo.type = yyvsp[0].string;
1696                             yyval.seinfo.role = NULL;
1697                         }
1698 break;
1699 case 49:
1700 #line 623 "parse.yacc"
1701 {
1702                             yyval.seinfo.role = yyvsp[-1].string;
1703                             yyval.seinfo.type = yyvsp[0].string;
1704                         }
1705 break;
1706 case 50:
1707 #line 627 "parse.yacc"
1708 {
1709                             yyval.seinfo.type = yyvsp[-1].string;
1710                             yyval.seinfo.role = yyvsp[0].string;
1711                         }
1712 break;
1713 case 51:
1714 #line 633 "parse.yacc"
1715 {
1716                             if (printmatches == TRUE && host_matches == TRUE &&
1717                                 user_matches == TRUE) {
1718                                 if (runas_matches == UNSPEC) {
1719                                     cm_list[cm_list_len].runas_len = 0;
1720                                 } else {
1721                                     /* Inherit runas data. */
1722                                     cm_list[cm_list_len].runas =
1723                                         estrdup(cm_list[cm_list_len-1].runas);
1724                                     cm_list[cm_list_len].runas_len =
1725                                         cm_list[cm_list_len-1].runas_len;
1726                                     cm_list[cm_list_len].runas_size =
1727                                         cm_list[cm_list_len-1].runas_len + 1;
1728                                 }
1729                             }
1730                             /*
1731                              * If this is the first entry in a command list
1732                              * then check against default runas user.
1733                              */
1734                             if (runas_matches == UNSPEC) {
1735                                 runas_matches = userpw_matches(def_runas_default,
1736                                     *user_runas, runas_pw) ? TRUE : NOMATCH;
1737                             }
1738                         }
1739 break;
1740 case 52:
1741 #line 657 "parse.yacc"
1742 {
1743                             runas_matches = yyvsp[0].BOOLEAN;
1744                         }
1745 break;
1746 case 53:
1747 #line 662 "parse.yacc"
1748 { ; }
1749 break;
1750 case 54:
1751 #line 663 "parse.yacc"
1752 {
1753                             /* Later entries override earlier ones. */
1754                             if (yyvsp[0].BOOLEAN != NOMATCH)
1755                                 yyval.BOOLEAN = yyvsp[0].BOOLEAN;
1756                             else
1757                                 yyval.BOOLEAN = yyvsp[-2].BOOLEAN;
1758                         }
1759 break;
1760 case 55:
1761 #line 672 "parse.yacc"
1762 { ; }
1763 break;
1764 case 56:
1765 #line 673 "parse.yacc"
1766 {
1767                             if (printmatches == TRUE) {
1768                                 if (in_alias == TRUE)
1769                                     append_entries("!", ", ");
1770                                 else if (host_matches == TRUE &&
1771                                     user_matches == TRUE)
1772                                     append_runas("!", ", ");
1773                             }
1774                         }
1775 break;
1776 case 57:
1777 #line 681 "parse.yacc"
1778 {
1779                             /* Set $$ to the negation of runasuser */
1780                             yyval.BOOLEAN = (yyvsp[0].BOOLEAN == NOMATCH ? NOMATCH : ! yyvsp[0].BOOLEAN);
1781                         }
1782 break;
1783 case 58:
1784 #line 687 "parse.yacc"
1785 {
1786                             if (printmatches == TRUE) {
1787                                 if (in_alias == TRUE)
1788                                     append_entries(yyvsp[0].string, ", ");
1789                                 else if (host_matches == TRUE &&
1790                                     user_matches == TRUE)
1791                                     append_runas(yyvsp[0].string, ", ");
1792                             }
1793                             if (userpw_matches(yyvsp[0].string, *user_runas, runas_pw))
1794                                 yyval.BOOLEAN = TRUE;
1795                             else
1796                                 yyval.BOOLEAN = NOMATCH;
1797                             efree(yyvsp[0].string);
1798                             used_runas = TRUE;
1799                         }
1800 break;
1801 case 59:
1802 #line 702 "parse.yacc"
1803 {
1804                             if (printmatches == TRUE) {
1805                                 if (in_alias == TRUE)
1806                                     append_entries(yyvsp[0].string, ", ");
1807                                 else if (host_matches == TRUE &&
1808                                     user_matches == TRUE)
1809                                     append_runas(yyvsp[0].string, ", ");
1810                             }
1811                             if (usergr_matches(yyvsp[0].string, *user_runas, runas_pw))
1812                                 yyval.BOOLEAN = TRUE;
1813                             else
1814                                 yyval.BOOLEAN = NOMATCH;
1815                             efree(yyvsp[0].string);
1816                             used_runas = TRUE;
1817                         }
1818 break;
1819 case 60:
1820 #line 717 "parse.yacc"
1821 {
1822                             if (printmatches == TRUE) {
1823                                 if (in_alias == TRUE)
1824                                     append_entries(yyvsp[0].string, ", ");
1825                                 else if (host_matches == TRUE &&
1826                                     user_matches == TRUE)
1827                                     append_runas(yyvsp[0].string, ", ");
1828                             }
1829                             if (netgr_matches(yyvsp[0].string, NULL, NULL, *user_runas))
1830                                 yyval.BOOLEAN = TRUE;
1831                             else
1832                                 yyval.BOOLEAN = NOMATCH;
1833                             efree(yyvsp[0].string);
1834                             used_runas = TRUE;
1835                         }
1836 break;
1837 case 61:
1838 #line 732 "parse.yacc"
1839 {
1840                             aliasinfo *aip = find_alias(yyvsp[0].string, RUNAS_ALIAS);
1841
1842                             if (printmatches == TRUE) {
1843                                 if (in_alias == TRUE)
1844                                     append_entries(yyvsp[0].string, ", ");
1845                                 else if (host_matches == TRUE &&
1846                                     user_matches == TRUE)
1847                                     append_runas(yyvsp[0].string, ", ");
1848                             }
1849                             /* could be an all-caps username */
1850                             if (aip)
1851                                 yyval.BOOLEAN = aip->val;
1852                             else if (strcmp(yyvsp[0].string, *user_runas) == 0)
1853                                 yyval.BOOLEAN = TRUE;
1854                             else {
1855                                 if (pedantic) {
1856                                     (void) fprintf(stderr,
1857                                         "%s: undeclared Runas_Alias `%s' referenced near line %d\n",
1858                                         (pedantic == 1) ? "Warning" : "Error", yyvsp[0].string, sudolineno);
1859                                     if (pedantic > 1) {
1860                                         yyerror(NULL);
1861                                         YYERROR;
1862                                     }
1863                                 }
1864                                 yyval.BOOLEAN = NOMATCH;
1865                             }
1866                             efree(yyvsp[0].string);
1867                             used_runas = TRUE;
1868                         }
1869 break;
1870 case 62:
1871 #line 762 "parse.yacc"
1872 {
1873                             if (printmatches == TRUE) {
1874                                 if (in_alias == TRUE)
1875                                     append_entries("ALL", ", ");
1876                                 else if (host_matches == TRUE &&
1877                                     user_matches == TRUE)
1878                                     append_runas("ALL", ", ");
1879                             }
1880                             yyval.BOOLEAN = TRUE;
1881                         }
1882 break;
1883 case 63:
1884 #line 774 "parse.yacc"
1885 {
1886                             /* Inherit {NO,}{PASSWD,EXEC,SETENV} status. */
1887                             if (printmatches == TRUE && host_matches == TRUE &&
1888                                 user_matches == TRUE) {
1889                                 if (no_passwd == TRUE)
1890                                     cm_list[cm_list_len].nopasswd = TRUE;
1891                                 else
1892                                     cm_list[cm_list_len].nopasswd = FALSE;
1893                                 if (no_execve == TRUE)
1894                                     cm_list[cm_list_len].noexecve = TRUE;
1895                                 else
1896                                     cm_list[cm_list_len].noexecve = FALSE;
1897                                 if (setenv_ok == TRUE)
1898                                     cm_list[cm_list_len].setenv = TRUE;
1899                                 else
1900                                     cm_list[cm_list_len].setenv = FALSE;
1901                             }
1902                         }
1903 break;
1904 case 64:
1905 #line 792 "parse.yacc"
1906 {
1907                             no_passwd = TRUE;
1908                             if (printmatches == TRUE && host_matches == TRUE &&
1909                                 user_matches == TRUE)
1910                                 cm_list[cm_list_len].nopasswd = TRUE;
1911                         }
1912 break;
1913 case 65:
1914 #line 798 "parse.yacc"
1915 {
1916                             no_passwd = FALSE;
1917                             if (printmatches == TRUE && host_matches == TRUE &&
1918                                 user_matches == TRUE)
1919                                 cm_list[cm_list_len].nopasswd = FALSE;
1920                         }
1921 break;
1922 case 66:
1923 #line 804 "parse.yacc"
1924 {
1925                             no_execve = TRUE;
1926                             if (printmatches == TRUE && host_matches == TRUE &&
1927                                 user_matches == TRUE)
1928                                 cm_list[cm_list_len].noexecve = TRUE;
1929                         }
1930 break;
1931 case 67:
1932 #line 810 "parse.yacc"
1933 {
1934                             no_execve = FALSE;
1935                             if (printmatches == TRUE && host_matches == TRUE &&
1936                                 user_matches == TRUE)
1937                                 cm_list[cm_list_len].noexecve = FALSE;
1938                         }
1939 break;
1940 case 68:
1941 #line 816 "parse.yacc"
1942 {
1943                             setenv_ok = TRUE;
1944                             if (printmatches == TRUE && host_matches == TRUE &&
1945                                 user_matches == TRUE)
1946                                 cm_list[cm_list_len].setenv = TRUE;
1947                         }
1948 break;
1949 case 69:
1950 #line 822 "parse.yacc"
1951 {
1952                             setenv_ok = FALSE;
1953                             if (printmatches == TRUE && host_matches == TRUE &&
1954                                 user_matches == TRUE)
1955                                 cm_list[cm_list_len].setenv = FALSE;
1956                         }
1957 break;
1958 case 70:
1959 #line 830 "parse.yacc"
1960 {
1961                             if (printmatches == TRUE) {
1962                                 if (in_alias == TRUE)
1963                                     append_entries("ALL", ", ");
1964                                 else if (host_matches == TRUE &&
1965                                     user_matches == TRUE) {
1966                                     append_cmnd("ALL", NULL);
1967                                     expand_match_list();
1968                                 }
1969                             }
1970                             /* sudo "ALL" implies the SETENV tag */
1971                             if (setenv_ok == UNSPEC)
1972                                 setenv_ok = IMPLIED;
1973
1974                             efree(safe_cmnd);
1975                             safe_cmnd = NULL;
1976                             yyval.BOOLEAN = TRUE;
1977                         }
1978 break;
1979 case 71:
1980 #line 848 "parse.yacc"
1981 {
1982                             aliasinfo *aip;
1983
1984                             if (printmatches == TRUE) {
1985                                 if (in_alias == TRUE)
1986                                     append_entries(yyvsp[0].string, ", ");
1987                                 else if (host_matches == TRUE &&
1988                                     user_matches == TRUE) {
1989                                     append_cmnd(yyvsp[0].string, NULL);
1990                                     expand_match_list();
1991                                 }
1992                             }
1993
1994                             if ((aip = find_alias(yyvsp[0].string, CMND_ALIAS)))
1995                                 yyval.BOOLEAN = aip->val;
1996                             else {
1997                                 if (pedantic) {
1998                                     (void) fprintf(stderr,
1999                                         "%s: undeclared Cmnd_Alias `%s' referenced near line %d\n",
2000                                         (pedantic == 1) ? "Warning" : "Error", yyvsp[0].string, sudolineno);
2001                                     if (pedantic > 1) {
2002                                         yyerror(NULL);
2003                                         YYERROR;
2004                                     }
2005                                 }
2006                                 yyval.BOOLEAN = NOMATCH;
2007                             }
2008                             efree(yyvsp[0].string);
2009                         }
2010 break;
2011 case 72:
2012 #line 877 "parse.yacc"
2013 {
2014                             if (printmatches == TRUE) {
2015                                 if (in_alias == TRUE) {
2016                                     append_entries(yyvsp[0].command.cmnd, ", ");
2017                                     if (yyvsp[0].command.args)
2018                                         append_entries(yyvsp[0].command.args, " ");
2019                                 }
2020                                 if (host_matches == TRUE &&
2021                                     user_matches == TRUE)  {
2022                                     append_cmnd(yyvsp[0].command.cmnd, NULL);
2023                                     if (yyvsp[0].command.args)
2024                                         append_cmnd(yyvsp[0].command.args, " ");
2025                                     expand_match_list();
2026                                 }
2027                             }
2028
2029                             if (command_matches(yyvsp[0].command.cmnd, yyvsp[0].command.args))
2030                                 yyval.BOOLEAN = TRUE;
2031                             else
2032                                 yyval.BOOLEAN = NOMATCH;
2033
2034                             efree(yyvsp[0].command.cmnd);
2035                             efree(yyvsp[0].command.args);
2036                         }
2037 break;
2038 case 75:
2039 #line 907 "parse.yacc"
2040 { push; }
2041 break;
2042 case 76:
2043 #line 907 "parse.yacc"
2044 {
2045                             if ((MATCHED(host_matches) || pedantic) &&
2046                                 !add_alias(yyvsp[-3].string, HOST_ALIAS, host_matches)) {
2047                                 yyerror(NULL);
2048                                 YYERROR;
2049                             }
2050                             pop;
2051                         }
2052 break;
2053 case 81:
2054 #line 925 "parse.yacc"
2055 {
2056                             push;
2057                             if (printmatches == TRUE) {
2058                                 in_alias = TRUE;
2059                                 /* Allocate space for ga_list if necessary. */
2060                                 expand_ga_list();
2061                                 ga_list[ga_list_len-1].type = CMND_ALIAS;
2062                                 ga_list[ga_list_len-1].alias = estrdup(yyvsp[0].string);
2063                              }
2064                         }
2065 break;
2066 case 82:
2067 #line 934 "parse.yacc"
2068 {
2069                             if ((MATCHED(cmnd_matches) || pedantic) &&
2070                                 !add_alias(yyvsp[-3].string, CMND_ALIAS, cmnd_matches)) {
2071                                 yyerror(NULL);
2072                                 YYERROR;
2073                             }
2074                             pop;
2075                             efree(yyvsp[-3].string);
2076
2077                             if (printmatches == TRUE)
2078                                 in_alias = FALSE;
2079                         }
2080 break;
2081 case 83:
2082 #line 948 "parse.yacc"
2083 { ; }
2084 break;
2085 case 87:
2086 #line 956 "parse.yacc"
2087 {
2088                             if (printmatches == TRUE) {
2089                                 in_alias = TRUE;
2090                                 /* Allocate space for ga_list if necessary. */
2091                                 expand_ga_list();
2092                                 ga_list[ga_list_len-1].type = RUNAS_ALIAS;
2093                                 ga_list[ga_list_len-1].alias = estrdup(yyvsp[0].string);
2094                             }
2095                         }
2096 break;
2097 case 88:
2098 #line 964 "parse.yacc"
2099 {
2100                             if ((yyvsp[0].BOOLEAN != NOMATCH || pedantic) &&
2101                                 !add_alias(yyvsp[-3].string, RUNAS_ALIAS, yyvsp[0].BOOLEAN)) {
2102                                 yyerror(NULL);
2103                                 YYERROR;
2104                             }
2105                             efree(yyvsp[-3].string);
2106
2107                             if (printmatches == TRUE)
2108                                 in_alias = FALSE;
2109                         }
2110 break;
2111 case 91:
2112 #line 981 "parse.yacc"
2113 { push; }
2114 break;
2115 case 92:
2116 #line 981 "parse.yacc"
2117 {
2118                             if ((MATCHED(user_matches) || pedantic) &&
2119                                 !add_alias(yyvsp[-3].string, USER_ALIAS, user_matches)) {
2120                                 yyerror(NULL);
2121                                 YYERROR;
2122                             }
2123                             pop;
2124                             efree(yyvsp[-3].string);
2125                         }
2126 break;
2127 case 95:
2128 #line 996 "parse.yacc"
2129 {
2130                             SETMATCH(user_matches, yyvsp[0].BOOLEAN);
2131                         }
2132 break;
2133 case 96:
2134 #line 999 "parse.yacc"
2135 {
2136                             SETNMATCH(user_matches, yyvsp[0].BOOLEAN);
2137                         }
2138 break;
2139 case 97:
2140 #line 1004 "parse.yacc"
2141 {
2142                             if (userpw_matches(yyvsp[0].string, user_name, sudo_user.pw))
2143                                 yyval.BOOLEAN = TRUE;
2144                             else
2145                                 yyval.BOOLEAN = NOMATCH;
2146                             efree(yyvsp[0].string);
2147                         }
2148 break;
2149 case 98:
2150 #line 1011 "parse.yacc"
2151 {
2152                             if (usergr_matches(yyvsp[0].string, user_name, sudo_user.pw))
2153                                 yyval.BOOLEAN = TRUE;
2154                             else
2155                                 yyval.BOOLEAN = NOMATCH;
2156                             efree(yyvsp[0].string);
2157                         }
2158 break;
2159 case 99:
2160 #line 1018 "parse.yacc"
2161 {
2162                             if (netgr_matches(yyvsp[0].string, NULL, NULL, user_name))
2163                                 yyval.BOOLEAN = TRUE;
2164                             else
2165                                 yyval.BOOLEAN = NOMATCH;
2166                             efree(yyvsp[0].string);
2167                         }
2168 break;
2169 case 100:
2170 #line 1025 "parse.yacc"
2171 {
2172                             aliasinfo *aip = find_alias(yyvsp[0].string, USER_ALIAS);
2173
2174                             /* could be an all-caps username */
2175                             if (aip)
2176                                 yyval.BOOLEAN = aip->val;
2177                             else if (strcmp(yyvsp[0].string, user_name) == 0)
2178                                 yyval.BOOLEAN = TRUE;
2179                             else {
2180                                 if (pedantic) {
2181                                     (void) fprintf(stderr,
2182                                         "%s: undeclared User_Alias `%s' referenced near line %d\n",
2183                                         (pedantic == 1) ? "Warning" : "Error", yyvsp[0].string, sudolineno);
2184                                     if (pedantic > 1) {
2185                                         yyerror(NULL);
2186                                         YYERROR;
2187                                     }
2188                                 }
2189                                 yyval.BOOLEAN = NOMATCH;
2190                             }
2191                             efree(yyvsp[0].string);
2192                         }
2193 break;
2194 case 101:
2195 #line 1047 "parse.yacc"
2196 {
2197                             yyval.BOOLEAN = TRUE;
2198                         }
2199 break;
2200 #line 2149 "sudo.tab.c"
2201     }
2202     yyssp -= yym;
2203     yystate = *yyssp;
2204     yyvsp -= yym;
2205     yym = yylhs[yyn];
2206     if (yystate == 0 && yym == 0)
2207     {
2208 #if YYDEBUG
2209         if (yydebug)
2210             printf("%sdebug: after reduction, shifting from state 0 to\
2211  state %d\n", YYPREFIX, YYFINAL);
2212 #endif
2213         yystate = YYFINAL;
2214         *++yyssp = YYFINAL;
2215         *++yyvsp = yyval;
2216         if (yychar < 0)
2217         {
2218             if ((yychar = yylex()) < 0) yychar = 0;
2219 #if YYDEBUG
2220             if (yydebug)
2221             {
2222                 yys = 0;
2223                 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
2224                 if (!yys) yys = "illegal-symbol";
2225                 printf("%sdebug: state %d, reading %d (%s)\n",
2226                         YYPREFIX, YYFINAL, yychar, yys);
2227             }
2228 #endif
2229         }
2230         if (yychar == 0) goto yyaccept;
2231         goto yyloop;
2232     }
2233     if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
2234             yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
2235         yystate = yytable[yyn];
2236     else
2237         yystate = yydgoto[yym];
2238 #if YYDEBUG
2239     if (yydebug)
2240         printf("%sdebug: after reduction, shifting from state %d \
2241 to state %d\n", YYPREFIX, *yyssp, yystate);
2242 #endif
2243     if (yyssp >= yysslim && yygrowstack())
2244     {
2245         goto yyoverflow;
2246     }
2247     *++yyssp = yystate;
2248     *++yyvsp = yyval;
2249     goto yyloop;
2250 yyoverflow:
2251     yyerror("yacc stack overflow");
2252 yyabort:
2253     if (yyss)
2254             free(yyss);
2255     if (yyvs)
2256             free(yyvs);
2257     yyss = yyssp = NULL;
2258     yyvs = yyvsp = NULL;
2259     yystacksize = 0;
2260     return (1);
2261 yyaccept:
2262     if (yyss)
2263             free(yyss);
2264     if (yyvs)
2265             free(yyvs);
2266     yyss = yyssp = NULL;
2267     yyvs = yyvsp = NULL;
2268     yystacksize = 0;
2269     return (0);
2270 }