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