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