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