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