2 /*static char yysccsid[] = "from: @(#)yaccpar 1.9 (Berkeley) 02/21/93";*/
5 __attribute__ ((unused))
6 #endif /* __GNUC__ >= 2 */
7 = "$OpenBSD: skeleton.c,v 1.28 2007/09/03 21:14:58 deraadt Exp $";
15 #define yyclearin (yychar=(YYEMPTY))
16 #define yyerrok (yyerrflag=0)
17 #define YYRECOVERING() (yyerrflag!=0)
21 * Copyright (c) 1996, 1998-2004, 2007
22 * Todd C. Miller <Todd.Miller@courtesan.com>
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.
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.
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.
44 * XXX - the whole opFOO naming thing is somewhat bogus.
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.
53 #include <sys/types.h>
54 #include <sys/param.h>
63 #endif /* STDC_HEADERS */
67 # ifdef HAVE_STRINGS_H
70 #endif /* HAVE_STRING_H */
73 #endif /* HAVE_UNISTD_H */
75 #if defined(YYBISON) && defined(HAVE_ALLOCA_H) && !defined(__GNUC__)
77 #endif /* YYBISON && HAVE_ALLOCA_H && !__GNUC__ */
80 #endif /* HAVE_LSEARCH */
87 #include "emul/search.h"
88 #endif /* HAVE_LSEARCH */
91 __unused static const char rcsid[] = "$Sudo: sudo.tab.c,v 1.76.2.11 2008/01/16 23:20:54 millert Exp $";
95 * We must define SIZE_MAX for yacc's skeleton.c.
96 * If there is no SIZE_MAX or SIZE_T_MAX we have to assume that size_t
97 * could be signed (as it is on SunOS 4.x).
101 # define SIZE_MAX SIZE_T_MAX
103 # define SIZE_MAX INT_MAX
104 # endif /* SIZE_T_MAX */
105 #endif /* SIZE_MAX */
110 extern int sudolineno, parse_error;
111 int errorlineno = -1;
112 int clearaliases = TRUE;
113 int printmatches = FALSE;
114 int pedantic = FALSE;
117 int used_runas = FALSE;
125 #define RUNAS_ALIAS 4
127 #define SETMATCH(_var, _val) do { \
128 if ((_var) == UNSPEC || (_val) != NOMATCH) \
132 #define SETNMATCH(_var, _val) do { \
133 if ((_val) != NOMATCH) \
135 else if ((_var) == UNSPEC) \
139 #define SETENV_RESET \
140 if (setenv_ok == IMPLIED) setenv_ok = def_setenv ? TRUE : UNSPEC
143 * The matching stack, initial space allocated in init_parser().
145 struct matchstack *match;
146 int top = 0, stacksize = 0;
150 if (top >= stacksize) { \
151 while ((stacksize += STACKINCREMENT) < top); \
152 match = (struct matchstack *) erealloc3(match, stacksize, sizeof(struct matchstack)); \
154 match[top].user = UNSPEC; \
155 match[top].cmnd = UNSPEC; \
156 match[top].host = UNSPEC; \
157 match[top].runas = UNSPEC; \
158 match[top].nopass = def_authenticate ? UNSPEC : TRUE; \
159 match[top].noexec = def_noexec ? TRUE : UNSPEC; \
160 match[top].setenv = def_setenv ? TRUE : UNSPEC; \
166 if (top >= stacksize) { \
167 while ((stacksize += STACKINCREMENT) < top); \
168 match = (struct matchstack *) erealloc3(match, stacksize, sizeof(struct matchstack)); \
170 match[top].user = match[top-1].user; \
171 match[top].cmnd = match[top-1].cmnd; \
172 match[top].host = match[top-1].host; \
173 match[top].runas = match[top-1].runas; \
174 match[top].nopass = match[top-1].nopass; \
175 match[top].noexec = match[top-1].noexec; \
176 match[top].setenv = match[top-1].setenv; \
183 yyerror("matching stack underflow"); \
190 * For testing if foo_matches variable was set to TRUE or FALSE
192 #define MATCHED(_v) ((_v) >= 0)
195 * Shortcuts for append()
197 #define append_cmnd(s, p) append(s, &cm_list[cm_list_len].cmnd, \
198 &cm_list[cm_list_len].cmnd_len, &cm_list[cm_list_len].cmnd_size, p)
200 #define append_runas(s, p) append(s, &cm_list[cm_list_len].runas, \
201 &cm_list[cm_list_len].runas_len, &cm_list[cm_list_len].runas_size, p)
203 #define append_entries(s, p) append(s, &ga_list[ga_list_len-1].entries, \
204 &ga_list[ga_list_len-1].entries_len, \
205 &ga_list[ga_list_len-1].entries_size, p)
208 * The stack for printmatches. A list of allowed commands for the user.
210 static struct command_match *cm_list = NULL;
211 static size_t cm_list_len = 0, cm_list_size = 0;
214 * List of Cmnd_Aliases and expansions for `sudo -l'
216 static int in_alias = FALSE;
217 static size_t ga_list_len = 0, ga_list_size = 0;
218 static struct generic_alias *ga_list = NULL;
221 * Does this Defaults list pertain to this user?
223 static int defaults_matches = FALSE;
228 static int add_alias __P((char *, int, int));
229 static void append __P((char *, char **, size_t *, size_t *, char *));
230 static void expand_ga_list __P((void));
231 static void expand_match_list __P((void));
232 static aliasinfo *find_alias __P((char *, int));
233 static void more_aliases __P((void));
234 void init_parser __P((void));
235 void yyerror __P((char *));
241 /* Save the line the first error occurred on. */
242 if (errorlineno == -1)
243 errorlineno = sudolineno ? sudolineno - 1 : 0;
246 (void) fprintf(stderr, ">>> sudoers file: %s, line %d <<<\n", s,
247 sudolineno ? sudolineno - 1 : 0);
249 (void) fprintf(stderr, "<*> ");
254 #line 238 "parse.yacc"
255 #ifndef YYSTYPE_DEFINED
256 #define YYSTYPE_DEFINED
260 struct sudo_command command;
263 #endif /* YYSTYPE_DEFINED */
264 #line 265 "sudo.tab.c"
270 #define USERGROUP 262
273 #define DEFAULTS_HOST 265
274 #define DEFAULTS_USER 266
275 #define DEFAULTS_RUNAS 267
285 #define HOSTALIAS 277
286 #define CMNDALIAS 278
287 #define USERALIAS 279
288 #define RUNASALIAS 280
290 #define YYERRCODE 256
291 #if defined(__cplusplus) || defined(__STDC__)
292 const short yylhs[] =
297 0, 0, 7, 7, 9, 7, 7, 7, 7, 7,
298 7, 15, 16, 18, 16, 19, 16, 21, 16, 17,
299 17, 22, 22, 22, 22, 22, 10, 10, 23, 25,
300 25, 2, 2, 2, 2, 2, 24, 24, 28, 26,
301 30, 31, 30, 27, 27, 5, 5, 4, 32, 4,
302 3, 3, 3, 3, 3, 29, 29, 29, 29, 29,
303 29, 29, 1, 1, 1, 12, 12, 34, 33, 20,
304 20, 13, 13, 36, 35, 37, 37, 14, 14, 39,
305 38, 11, 11, 41, 40, 8, 8, 42, 42, 6,
308 #if defined(__cplusplus) || defined(__STDC__)
309 const short yylen[] =
314 1, 2, 1, 2, 0, 3, 2, 2, 2, 2,
315 1, 2, 1, 0, 3, 0, 3, 0, 3, 1,
316 3, 1, 2, 3, 3, 3, 1, 3, 3, 1,
317 2, 1, 1, 1, 1, 1, 1, 3, 0, 4,
318 1, 0, 3, 0, 2, 1, 3, 1, 0, 3,
319 1, 1, 1, 1, 1, 0, 2, 2, 2, 2,
320 2, 2, 1, 1, 1, 1, 3, 0, 4, 1,
321 3, 1, 3, 0, 4, 1, 3, 1, 3, 0,
322 4, 1, 3, 0, 4, 1, 3, 1, 2, 1,
325 #if defined(__cplusplus) || defined(__STDC__)
326 const short yydefred[] =
331 0, 13, 18, 14, 16, 3, 0, 0, 0, 0,
332 0, 1, 0, 11, 0, 4, 0, 0, 0, 68,
333 0, 66, 74, 0, 72, 84, 0, 82, 80, 0,
334 78, 2, 93, 92, 91, 90, 94, 0, 88, 0,
335 86, 0, 0, 12, 0, 36, 33, 34, 35, 32,
336 0, 30, 0, 70, 0, 54, 53, 52, 51, 55,
337 49, 48, 46, 0, 0, 0, 0, 0, 0, 0,
338 0, 0, 89, 0, 0, 0, 27, 0, 0, 0,
339 23, 0, 31, 0, 0, 0, 0, 67, 0, 73,
340 0, 83, 0, 79, 87, 0, 39, 24, 25, 26,
341 21, 71, 50, 47, 0, 65, 64, 63, 42, 41,
342 76, 0, 0, 0, 28, 0, 37, 0, 0, 0,
343 39, 0, 56, 43, 77, 38, 0, 0, 57, 58,
346 #if defined(__cplusplus) || defined(__STDC__)
347 const short yydgoto[] =
352 110, 52, 62, 63, 64, 39, 12, 40, 13, 75,
353 27, 21, 24, 30, 14, 15, 44, 18, 19, 76,
354 17, 45, 77, 116, 54, 117, 123, 118, 128, 111,
355 119, 85, 22, 65, 25, 67, 112, 31, 71, 28,
358 #if defined(__cplusplus) || defined(__STDC__)
359 const short yysindex[] =
364 -256, 0, 0, 0, 0, 0, -237, -234, -231, -226,
365 -223, 0, 62, 0, -33, 0, 88, 62, 114, 0,
366 -22, 0, 0, -21, 0, 0, -19, 0, 0, -18,
367 0, 0, 0, 0, 0, 0, 0, -244, 0, -28,
368 0, -36, -221, 0, 3, 0, 0, 0, 0, 0,
369 -212, 0, 6, 0, 14, 0, 0, 0, 0, 0,
370 0, 0, 0, 16, 7, -237, 8, -234, 9, -231,
371 10, -226, 0, 62, 18, -32, 0, -202, -199, -191,
372 0, -33, 0, 88, -196, 114, 88, 0, 276, 0,
373 62, 0, 114, 0, 0, 88, 0, 0, 0, 0,
374 0, 0, 0, 0, 6, 0, 0, 0, 0, 0,
375 0, 30, 14, 16, 0, 33, 0, -188, -247, 276,
376 0, 114, 0, 0, 0, 0, 16, -29, 0, 0,
378 #if defined(__cplusplus) || defined(__STDC__)
379 const short yyrindex[] =
384 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
385 140, 0, 0, 0, 0, 0, 0, 0, 0, 0,
386 156, 0, 0, 181, 0, 0, 206, 0, 0, 236,
387 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
388 0, 1, 0, 0, 261, 0, 0, 0, 0, 0,
389 0, 0, -25, 0, -11, 0, 0, 0, 0, 0,
390 0, 0, 0, -3, 0, 0, 0, 0, 0, 0,
391 0, 0, 0, 0, 300, 0, 0, 0, 0, 0,
392 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
393 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
394 0, 0, 0, 0, 26, 0, 0, 0, 0, 0,
395 0, 52, 78, 104, 0, 130, 0, -20, 0, 0,
396 0, 0, 0, 0, 0, 0, 274, 0, 0, 0,
398 #if defined(__cplusplus) || defined(__STDC__)
399 const short yygindex[] =
404 -38, 31, -2, 2, -87, 48, 76, -16, 0, 0,
405 0, 0, 0, 0, 0, 0, 11, 0, 0, -14,
406 0, 0, -7, 0, 12, -31, 0, 0, 0, -105,
407 0, 0, 25, 0, 24, 0, 0, 22, 0, 27,
410 #define YYTABLESIZE 580
411 #if defined(__cplusplus) || defined(__STDC__)
412 const short yytable[] =
417 22, 55, 53, 109, 51, 114, 79, 19, 80, 106,
418 107, 84, 44, 33, 125, 74, 34, 35, 36, 16,
419 20, 15, 135, 23, 78, 69, 26, 108, 97, 17,
420 37, 29, 1, 22, 127, 66, 68, 81, 70, 72,
421 2, 3, 4, 5, 22, 46, 82, 47, 48, 84,
422 49, 75, 6, 7, 8, 9, 10, 74, 69, 86,
423 98, 56, 50, 99, 57, 58, 59, 87, 89, 91,
424 93, 100, 105, 120, 113, 96, 121, 85, 60, 122,
425 124, 83, 103, 69, 75, 73, 32, 104, 115, 126,
426 88, 90, 101, 94, 38, 102, 92, 0, 0, 0,
427 0, 95, 0, 81, 0, 0, 0, 0, 0, 75,
428 85, 0, 0, 0, 0, 0, 0, 0, 0, 0,
429 51, 0, 0, 0, 0, 0, 0, 0, 0, 29,
430 0, 0, 0, 0, 0, 85, 81, 0, 0, 0,
431 0, 0, 0, 0, 0, 0, 61, 0, 0, 0,
432 0, 0, 0, 0, 0, 8, 0, 0, 0, 0,
433 0, 81, 29, 0, 0, 0, 0, 0, 0, 0,
434 0, 0, 5, 0, 0, 0, 0, 0, 0, 0,
435 9, 0, 0, 0, 0, 0, 0, 29, 8, 0,
436 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
437 0, 0, 0, 0, 0, 7, 0, 0, 0, 0,
438 0, 0, 0, 9, 0, 0, 0, 0, 0, 0,
439 0, 0, 0, 0, 0, 42, 0, 106, 107, 46,
440 0, 47, 48, 19, 49, 10, 44, 44, 7, 129,
441 130, 131, 132, 133, 134, 108, 50, 15, 44, 44,
442 44, 44, 44, 44, 44, 17, 22, 0, 22, 0,
443 20, 22, 22, 22, 22, 22, 22, 22, 10, 0,
444 0, 0, 0, 0, 0, 22, 22, 22, 22, 22,
445 22, 69, 0, 69, 0, 0, 69, 69, 69, 69,
446 69, 69, 69, 20, 0, 0, 0, 0, 0, 6,
447 69, 69, 69, 69, 69, 69, 45, 75, 109, 75,
448 0, 0, 75, 75, 75, 75, 75, 75, 75, 33,
449 0, 0, 34, 35, 36, 0, 75, 75, 75, 75,
450 75, 75, 6, 85, 0, 85, 37, 0, 85, 85,
451 85, 85, 85, 85, 85, 46, 0, 47, 48, 0,
452 49, 0, 85, 85, 85, 85, 85, 85, 0, 81,
453 0, 81, 50, 0, 81, 81, 81, 81, 81, 81,
454 81, 56, 0, 0, 57, 58, 59, 0, 81, 81,
455 81, 81, 81, 81, 0, 29, 0, 29, 60, 0,
456 29, 29, 29, 29, 29, 29, 29, 5, 0, 0,
457 5, 5, 5, 0, 29, 29, 29, 29, 29, 29,
458 0, 8, 0, 8, 5, 0, 8, 8, 8, 8,
459 8, 8, 8, 0, 0, 0, 0, 0, 0, 0,
460 8, 8, 8, 8, 8, 8, 9, 0, 9, 0,
461 0, 9, 9, 9, 9, 9, 9, 9, 0, 0,
462 0, 0, 0, 0, 0, 9, 9, 9, 9, 9,
463 9, 7, 0, 7, 0, 0, 7, 7, 7, 7,
464 7, 7, 7, 0, 0, 0, 0, 0, 0, 0,
465 7, 7, 7, 7, 7, 7, 0, 0, 0, 0,
466 0, 10, 0, 10, 0, 0, 10, 10, 10, 10,
467 10, 10, 10, 0, 0, 0, 0, 0, 0, 0,
468 10, 10, 10, 10, 10, 10, 20, 0, 20, 0,
469 0, 20, 20, 20, 20, 20, 20, 20, 0, 0,
470 45, 45, 106, 107, 0, 20, 20, 20, 20, 20,
471 20, 0, 45, 45, 45, 45, 45, 45, 45, 0,
472 108, 0, 0, 0, 0, 6, 0, 6, 0, 0,
473 6, 6, 6, 6, 6, 6, 6, 0, 0, 0,
474 0, 0, 0, 0, 6, 6, 6, 6, 6, 6,
476 #if defined(__cplusplus) || defined(__STDC__)
477 const short yycheck[] =
482 0, 18, 17, 33, 33, 93, 43, 33, 45, 257,
483 258, 44, 33, 258, 120, 44, 261, 262, 263, 276,
484 258, 33, 128, 258, 61, 0, 258, 275, 61, 33,
485 275, 258, 256, 33, 122, 58, 58, 259, 58, 58,
486 264, 265, 266, 267, 44, 258, 44, 260, 261, 44,
487 263, 0, 276, 277, 278, 279, 280, 44, 33, 44,
488 263, 258, 275, 263, 261, 262, 263, 61, 61, 61,
489 61, 263, 87, 44, 91, 58, 44, 0, 275, 268,
490 119, 51, 85, 58, 33, 38, 11, 86, 96, 121,
491 66, 68, 82, 72, 33, 84, 70, -1, -1, -1,
492 -1, 74, -1, 0, -1, -1, -1, -1, -1, 58,
493 33, -1, -1, -1, -1, -1, -1, -1, -1, -1,
494 33, -1, -1, -1, -1, -1, -1, -1, -1, 0,
495 -1, -1, -1, -1, -1, 58, 33, -1, -1, -1,
496 -1, -1, -1, -1, -1, -1, 33, -1, -1, -1,
497 -1, -1, -1, -1, -1, 0, -1, -1, -1, -1,
498 -1, 58, 33, -1, -1, -1, -1, -1, -1, -1,
499 -1, -1, 33, -1, -1, -1, -1, -1, -1, -1,
500 0, -1, -1, -1, -1, -1, -1, 58, 33, -1,
501 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
502 -1, -1, -1, -1, -1, 0, -1, -1, -1, -1,
503 -1, -1, -1, 33, -1, -1, -1, -1, -1, -1,
504 -1, -1, -1, -1, -1, 259, -1, 257, 258, 258,
505 -1, 260, 261, 259, 263, 0, 257, 258, 33, 269,
506 270, 271, 272, 273, 274, 275, 275, 259, 269, 270,
507 271, 272, 273, 274, 275, 259, 256, -1, 258, -1,
508 0, 261, 262, 263, 264, 265, 266, 267, 33, -1,
509 -1, -1, -1, -1, -1, 275, 276, 277, 278, 279,
510 280, 256, -1, 258, -1, -1, 261, 262, 263, 264,
511 265, 266, 267, 33, -1, -1, -1, -1, -1, 0,
512 275, 276, 277, 278, 279, 280, 33, 256, 33, 258,
513 -1, -1, 261, 262, 263, 264, 265, 266, 267, 258,
514 -1, -1, 261, 262, 263, -1, 275, 276, 277, 278,
515 279, 280, 33, 256, -1, 258, 275, -1, 261, 262,
516 263, 264, 265, 266, 267, 258, -1, 260, 261, -1,
517 263, -1, 275, 276, 277, 278, 279, 280, -1, 256,
518 -1, 258, 275, -1, 261, 262, 263, 264, 265, 266,
519 267, 258, -1, -1, 261, 262, 263, -1, 275, 276,
520 277, 278, 279, 280, -1, 256, -1, 258, 275, -1,
521 261, 262, 263, 264, 265, 266, 267, 258, -1, -1,
522 261, 262, 263, -1, 275, 276, 277, 278, 279, 280,
523 -1, 256, -1, 258, 275, -1, 261, 262, 263, 264,
524 265, 266, 267, -1, -1, -1, -1, -1, -1, -1,
525 275, 276, 277, 278, 279, 280, 256, -1, 258, -1,
526 -1, 261, 262, 263, 264, 265, 266, 267, -1, -1,
527 -1, -1, -1, -1, -1, 275, 276, 277, 278, 279,
528 280, 256, -1, 258, -1, -1, 261, 262, 263, 264,
529 265, 266, 267, -1, -1, -1, -1, -1, -1, -1,
530 275, 276, 277, 278, 279, 280, -1, -1, -1, -1,
531 -1, 256, -1, 258, -1, -1, 261, 262, 263, 264,
532 265, 266, 267, -1, -1, -1, -1, -1, -1, -1,
533 275, 276, 277, 278, 279, 280, 256, -1, 258, -1,
534 -1, 261, 262, 263, 264, 265, 266, 267, -1, -1,
535 257, 258, 257, 258, -1, 275, 276, 277, 278, 279,
536 280, -1, 269, 270, 271, 272, 273, 274, 275, -1,
537 275, -1, -1, -1, -1, 256, -1, 258, -1, -1,
538 261, 262, 263, 264, 265, 266, 267, -1, -1, -1,
539 -1, -1, -1, -1, 275, 276, 277, 278, 279, 280,
545 #define YYMAXTOKEN 281
547 #if defined(__cplusplus) || defined(__STDC__)
548 const char * const yyname[] =
553 "end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
554 "'!'",0,0,0,0,0,0,0,0,0,"'+'","','","'-'",0,0,0,0,0,0,0,0,0,0,0,0,"':'",0,0,
555 "'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
556 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
557 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
558 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
559 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
560 "COMMAND","ALIAS","DEFVAR","NTWKADDR","NETGROUP","USERGROUP","WORD","DEFAULTS",
561 "DEFAULTS_HOST","DEFAULTS_USER","DEFAULTS_RUNAS","RUNAS","NOPASSWD","PASSWD",
562 "NOEXEC","EXEC","SETENV","NOSETENV","ALL","COMMENT","HOSTALIAS","CMNDALIAS",
563 "USERALIAS","RUNASALIAS","ERROR",
565 #if defined(__cplusplus) || defined(__STDC__)
566 const char * const yyrule[] =
574 "entry : error COMMENT",
576 "entry : $$1 userlist privileges",
577 "entry : USERALIAS useraliases",
578 "entry : HOSTALIAS hostaliases",
579 "entry : CMNDALIAS cmndaliases",
580 "entry : RUNASALIAS runasaliases",
581 "entry : defaults_line",
582 "defaults_line : defaults_type defaults_list",
583 "defaults_type : DEFAULTS",
585 "defaults_type : DEFAULTS_USER $$2 userlist",
587 "defaults_type : DEFAULTS_RUNAS $$3 runaslist",
589 "defaults_type : DEFAULTS_HOST $$4 hostlist",
590 "defaults_list : defaults_entry",
591 "defaults_list : defaults_entry ',' defaults_list",
592 "defaults_entry : DEFVAR",
593 "defaults_entry : '!' DEFVAR",
594 "defaults_entry : DEFVAR '=' WORD",
595 "defaults_entry : DEFVAR '+' WORD",
596 "defaults_entry : DEFVAR '-' WORD",
597 "privileges : privilege",
598 "privileges : privileges ':' privilege",
599 "privilege : hostlist '=' cmndspeclist",
607 "cmndspeclist : cmndspec",
608 "cmndspeclist : cmndspeclist ',' cmndspec",
610 "cmndspec : $$5 runasspec cmndtag opcmnd",
613 "opcmnd : '!' $$6 cmnd",
615 "runasspec : RUNAS runaslist",
616 "runaslist : oprunasuser",
617 "runaslist : runaslist ',' oprunasuser",
618 "oprunasuser : runasuser",
620 "oprunasuser : '!' $$7 runasuser",
622 "runasuser : USERGROUP",
623 "runasuser : NETGROUP",
627 "cmndtag : cmndtag NOPASSWD",
628 "cmndtag : cmndtag PASSWD",
629 "cmndtag : cmndtag NOEXEC",
630 "cmndtag : cmndtag EXEC",
631 "cmndtag : cmndtag SETENV",
632 "cmndtag : cmndtag NOSETENV",
636 "hostaliases : hostalias",
637 "hostaliases : hostaliases ':' hostalias",
639 "hostalias : ALIAS $$8 '=' hostlist",
641 "hostlist : hostlist ',' ophost",
642 "cmndaliases : cmndalias",
643 "cmndaliases : cmndaliases ':' cmndalias",
645 "cmndalias : ALIAS $$9 '=' cmndlist",
647 "cmndlist : cmndlist ',' opcmnd",
648 "runasaliases : runasalias",
649 "runasaliases : runasaliases ':' runasalias",
651 "runasalias : ALIAS $$10 '=' runaslist",
652 "useraliases : useralias",
653 "useraliases : useraliases ':' useralias",
655 "useralias : ALIAS $$11 '=' userlist",
657 "userlist : userlist ',' opuser",
669 #define YYMAXDEPTH YYSTACKSIZE
672 #define YYSTACKSIZE YYMAXDEPTH
674 #define YYSTACKSIZE 10000
675 #define YYMAXDEPTH 10000
678 #define YYINITSTACKSIZE 200
692 #line 925 "parse.yacc"
694 #define MOREALIASES (32)
695 aliasinfo *aliases = NULL;
701 * Compare two aliasinfo structures, strcmp() style.
702 * Note that we do *not* compare their values.
709 aliasinfo *ai1, *ai2;
711 ai1 = (aliasinfo *) a1;
712 ai2 = (aliasinfo *) a2;
713 if ((r = strcmp(ai1->name, ai2->name)) == 0)
714 r = ai1->type - ai2->type;
720 * Compare two generic_alias structures, strcmp() style.
723 genaliascmp(entry, key)
724 const VOID *entry, *key;
727 struct generic_alias *ga1, *ga2;
729 ga1 = (struct generic_alias *) key;
730 ga2 = (struct generic_alias *) entry;
731 if ((r = strcmp(ga1->alias, ga2->alias)) == 0)
732 r = ga1->type - ga2->type;
739 * Adds the named alias of the specified type to the aliases list.
742 add_alias(alias, type, val)
751 if (naliases >= nslots)
756 ai.name = estrdup(alias);
757 onaliases = naliases;
759 aip = (aliasinfo *) lsearch((VOID *)&ai, (VOID *)aliases, &naliases,
760 sizeof(ai), aliascmp);
762 (void) snprintf(s, sizeof(s), "Aliases corrupted defining alias `%s'",
767 if (onaliases == naliases) {
768 (void) snprintf(s, sizeof(s), "Alias `%s' already defined", alias);
777 * Searches for the named alias of the specified type.
780 find_alias(alias, type)
789 return((aliasinfo *) lfind((VOID *)&ai, (VOID *)aliases, &naliases,
790 sizeof(ai), aliascmp));
794 * Allocates more space for the aliases list.
800 nslots += MOREALIASES;
801 aliases = (aliasinfo *) erealloc3(aliases, nslots, sizeof(aliasinfo));
805 * Lists the contents of the aliases list.
812 for (n = 0; n < naliases; n++) {
813 if (aliases[n].val == -1)
816 switch (aliases[n].type) {
818 (void) puts("HOST_ALIAS");
822 (void) puts("CMND_ALIAS");
826 (void) puts("USER_ALIAS");
830 (void) puts("RUNAS_ALIAS");
833 (void) printf("\t%s: %d\n", aliases[n].name, aliases[n].val);
838 * Lists the contents of cm_list and ga_list for `sudo -l'.
845 struct generic_alias *ga, key;
847 (void) printf("User %s may run the following commands on this host:\n",
849 for (count = 0; count < cm_list_len; count++) {
851 /* Print the runas list. */
852 (void) fputs(" ", stdout);
853 if (cm_list[count].runas) {
855 p = strtok(cm_list[count].runas, ", ");
857 if (p != cm_list[count].runas)
858 (void) fputs(", ", stdout);
861 key.type = RUNAS_ALIAS;
862 if ((ga = (struct generic_alias *) lfind((VOID *) &key,
863 (VOID *) &ga_list[0], &ga_list_len, sizeof(key), genaliascmp)))
864 (void) fputs(ga->entries, stdout);
866 (void) fputs(p, stdout);
867 } while ((p = strtok(NULL, ", ")));
868 (void) fputs(") ", stdout);
870 (void) printf("(%s) ", def_runas_default);
873 /* Is execve(2) disabled? */
874 if (cm_list[count].noexecve == TRUE && !def_noexec)
875 (void) fputs("NOEXEC: ", stdout);
876 else if (cm_list[count].noexecve == FALSE && def_noexec)
877 (void) fputs("EXEC: ", stdout);
879 /* Is a password required? */
880 if (cm_list[count].nopasswd == TRUE && def_authenticate)
881 (void) fputs("NOPASSWD: ", stdout);
882 else if (cm_list[count].nopasswd == FALSE && !def_authenticate)
883 (void) fputs("PASSWD: ", stdout);
885 /* Is setenv enabled? */
886 if (cm_list[count].setenv == TRUE && !def_setenv)
887 (void) fputs("SETENV: ", stdout);
888 else if (cm_list[count].setenv == FALSE && def_setenv)
889 (void) fputs("NOSETENV: ", stdout);
891 /* Print the actual command or expanded Cmnd_Alias. */
892 key.alias = cm_list[count].cmnd;
893 key.type = CMND_ALIAS;
894 if ((ga = (struct generic_alias *) lfind((VOID *) &key,
895 (VOID *) &ga_list[0], &ga_list_len, sizeof(key), genaliascmp)))
896 (void) puts(ga->entries);
898 (void) puts(cm_list[count].cmnd);
901 /* Be nice and free up space now that we are done. */
902 for (count = 0; count < ga_list_len; count++) {
903 efree(ga_list[count].alias);
904 efree(ga_list[count].entries);
909 for (count = 0; count < cm_list_len; count++) {
910 efree(cm_list[count].runas);
911 efree(cm_list[count].cmnd);
920 * Appends a source string to the destination, optionally prefixing a separator.
923 append(src, dstp, dst_len, dst_size, separator)
925 size_t *dst_len, *dst_size;
928 size_t src_len = strlen(src);
932 * Only add the separator if there is something to separate from.
933 * If the last char is a '!', don't apply the separator (XXX).
935 if (separator && dst && dst[*dst_len - 1] != '!')
936 src_len += strlen(separator);
940 /* Assumes dst will be NULL if not set. */
942 dst = (char *) emalloc(BUFSIZ);
949 /* Allocate more space if necessary. */
950 if (*dst_size <= *dst_len + src_len) {
951 while (*dst_size <= *dst_len + src_len)
954 dst = (char *) erealloc(dst, *dst_size);
958 /* Copy src -> dst adding a separator if appropriate and adjust len. */
960 (void) strlcat(dst, separator, *dst_size);
961 (void) strlcat(dst, src, *dst_size);
966 * Frees up space used by the aliases list and resets the associated counters.
974 for (n = 0; n < naliases; n++)
975 efree(aliases[n].name);
979 naliases = nslots = 0;
983 * Increments ga_list_len, allocating more space as necessary.
989 if (++ga_list_len >= ga_list_size) {
990 while ((ga_list_size += STACKINCREMENT) < ga_list_len)
992 ga_list = (struct generic_alias *)
993 erealloc3(ga_list, ga_list_size, sizeof(struct generic_alias));
996 ga_list[ga_list_len - 1].entries = NULL;
1000 * Increments cm_list_len, allocating more space as necessary.
1006 if (++cm_list_len >= cm_list_size) {
1007 while ((cm_list_size += STACKINCREMENT) < cm_list_len)
1009 if (cm_list == NULL)
1010 cm_list_len = 0; /* start at 0 since it is a subscript */
1011 cm_list = (struct command_match *)
1012 erealloc3(cm_list, cm_list_size, sizeof(struct command_match));
1015 cm_list[cm_list_len].runas = cm_list[cm_list_len].cmnd = NULL;
1016 cm_list[cm_list_len].nopasswd = FALSE;
1017 cm_list[cm_list_len].noexecve = FALSE;
1018 cm_list[cm_list_len].setenv = FALSE;
1022 * Frees up spaced used by a previous parser run and allocates new space
1023 * for various data structures.
1029 /* Free up old data structures if we run the parser more than once. */
1034 parse_error = FALSE;
1040 /* Allocate space for the matching stack. */
1041 stacksize = STACKINCREMENT;
1042 match = (struct matchstack *) emalloc2(stacksize, sizeof(struct matchstack));
1044 /* Allocate space for the match list (for `sudo -l'). */
1045 if (printmatches == TRUE)
1046 expand_match_list();
1048 #line 997 "sudo.tab.c"
1049 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
1050 #if defined(__cplusplus) || defined(__STDC__)
1051 static int yygrowstack(void)
1053 static int yygrowstack()
1060 if ((newsize = yystacksize) == 0)
1061 newsize = YYINITSTACKSIZE;
1062 else if (newsize >= YYMAXDEPTH)
1064 else if ((newsize *= 2) > YYMAXDEPTH)
1065 newsize = YYMAXDEPTH;
1068 #define YY_SIZE_MAX SIZE_MAX
1070 #define YY_SIZE_MAX 0x7fffffff
1072 if (newsize && YY_SIZE_MAX / newsize < sizeof *newss)
1074 newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :
1075 (short *)malloc(newsize * sizeof *newss); /* overflow check above */
1080 if (newsize && YY_SIZE_MAX / newsize < sizeof *newvs)
1082 newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :
1083 (YYSTYPE *)malloc(newsize * sizeof *newvs); /* overflow check above */
1088 yystacksize = newsize;
1089 yysslim = yyss + newsize - 1;
1096 yyss = yyssp = NULL;
1097 yyvs = yyvsp = NULL;
1102 #define YYABORT goto yyabort
1103 #define YYREJECT goto yyabort
1104 #define YYACCEPT goto yyaccept
1105 #define YYERROR goto yyerrlab
1107 #if defined(__cplusplus) || defined(__STDC__)
1113 int yym, yyn, yystate;
1115 #if defined(__cplusplus) || defined(__STDC__)
1117 #else /* !(defined(__cplusplus) || defined(__STDC__)) */
1119 #endif /* !(defined(__cplusplus) || defined(__STDC__)) */
1121 if ((yys = getenv("YYDEBUG")))
1124 if (yyn >= '0' && yyn <= '9')
1125 yydebug = yyn - '0';
1127 #endif /* YYDEBUG */
1133 if (yyss == NULL && yygrowstack()) goto yyoverflow;
1136 *yyssp = yystate = 0;
1139 if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
1142 if ((yychar = yylex()) < 0) yychar = 0;
1147 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1148 if (!yys) yys = "illegal-symbol";
1149 printf("%sdebug: state %d, reading %d (%s)\n",
1150 YYPREFIX, yystate, yychar, yys);
1154 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
1155 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
1159 printf("%sdebug: state %d, shifting to state %d\n",
1160 YYPREFIX, yystate, yytable[yyn]);
1162 if (yyssp >= yysslim && yygrowstack())
1166 *++yyssp = yystate = yytable[yyn];
1169 if (yyerrflag > 0) --yyerrflag;
1172 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
1173 yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
1178 if (yyerrflag) goto yyinrecovery;
1179 #if defined(lint) || defined(__GNUC__)
1183 yyerror("syntax error");
1184 #if defined(lint) || defined(__GNUC__)
1195 if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
1196 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
1200 printf("%sdebug: state %d, error recovery shifting\
1201 to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
1203 if (yyssp >= yysslim && yygrowstack())
1207 *++yyssp = yystate = yytable[yyn];
1215 printf("%sdebug: error recovery discarding state %d\n",
1218 if (yyssp <= yyss) goto yyabort;
1226 if (yychar == 0) goto yyabort;
1231 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1232 if (!yys) yys = "illegal-symbol";
1233 printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
1234 YYPREFIX, yystate, yychar, yys);
1243 printf("%sdebug: state %d, reducing by rule %d (%s)\n",
1244 YYPREFIX, yystate, yyn, yyrule[yyn]);
1247 yyval = yyvsp[1-yym];
1251 #line 294 "parse.yacc"
1255 #line 296 "parse.yacc"
1259 #line 297 "parse.yacc"
1263 #line 297 "parse.yacc"
1265 while (top && user_matches != TRUE)
1270 #line 302 "parse.yacc"
1274 #line 304 "parse.yacc"
1278 #line 306 "parse.yacc"
1282 #line 308 "parse.yacc"
1286 #line 310 "parse.yacc"
1290 #line 316 "parse.yacc"
1292 defaults_matches = TRUE;
1296 #line 319 "parse.yacc"
1300 #line 319 "parse.yacc"
1302 defaults_matches = user_matches;
1307 #line 323 "parse.yacc"
1311 #line 323 "parse.yacc"
1313 defaults_matches = yyvsp[0].BOOLEAN == TRUE;
1318 #line 327 "parse.yacc"
1322 #line 327 "parse.yacc"
1324 defaults_matches = host_matches;
1329 #line 337 "parse.yacc"
1331 if (defaults_matches == TRUE &&
1332 !set_default(yyvsp[0].string, NULL, TRUE)) {
1336 efree(yyvsp[0].string);
1340 #line 345 "parse.yacc"
1342 if (defaults_matches == TRUE &&
1343 !set_default(yyvsp[0].string, NULL, FALSE)) {
1347 efree(yyvsp[0].string);
1351 #line 353 "parse.yacc"
1353 if (defaults_matches == TRUE &&
1354 !set_default(yyvsp[-2].string, yyvsp[0].string, TRUE)) {
1358 efree(yyvsp[-2].string);
1359 efree(yyvsp[0].string);
1363 #line 362 "parse.yacc"
1365 if (defaults_matches == TRUE &&
1366 !set_default(yyvsp[-2].string, yyvsp[0].string, '+')) {
1370 efree(yyvsp[-2].string);
1371 efree(yyvsp[0].string);
1375 #line 371 "parse.yacc"
1377 if (defaults_matches == TRUE &&
1378 !set_default(yyvsp[-2].string, yyvsp[0].string, '-')) {
1382 efree(yyvsp[-2].string);
1383 efree(yyvsp[0].string);
1387 #line 386 "parse.yacc"
1390 * We already did a push if necessary in
1391 * cmndspec so just reset some values so
1392 * the next 'privilege' gets a clean slate.
1394 host_matches = UNSPEC;
1395 runas_matches = UNSPEC;
1396 no_passwd = def_authenticate ? UNSPEC : TRUE;
1397 no_execve = def_noexec ? TRUE : UNSPEC;
1398 setenv_ok = def_setenv ? TRUE : UNSPEC;
1402 #line 400 "parse.yacc"
1404 SETMATCH(host_matches, yyvsp[0].BOOLEAN);
1408 #line 403 "parse.yacc"
1410 SETNMATCH(host_matches, yyvsp[0].BOOLEAN);
1414 #line 408 "parse.yacc"
1416 yyval.BOOLEAN = TRUE;
1420 #line 411 "parse.yacc"
1422 if (addr_matches(yyvsp[0].string))
1423 yyval.BOOLEAN = TRUE;
1425 yyval.BOOLEAN = NOMATCH;
1426 efree(yyvsp[0].string);
1430 #line 418 "parse.yacc"
1432 if (netgr_matches(yyvsp[0].string, user_host, user_shost, NULL))
1433 yyval.BOOLEAN = TRUE;
1435 yyval.BOOLEAN = NOMATCH;
1436 efree(yyvsp[0].string);
1440 #line 425 "parse.yacc"
1442 if (hostname_matches(user_shost, user_host, yyvsp[0].string) == 0)
1443 yyval.BOOLEAN = TRUE;
1445 yyval.BOOLEAN = NOMATCH;
1446 efree(yyvsp[0].string);
1450 #line 432 "parse.yacc"
1452 aliasinfo *aip = find_alias(yyvsp[0].string, HOST_ALIAS);
1454 /* could be an all-caps hostname */
1456 yyval.BOOLEAN = aip->val;
1457 else if (strcasecmp(user_shost, yyvsp[0].string) == 0)
1458 yyval.BOOLEAN = TRUE;
1461 (void) fprintf(stderr,
1462 "%s: undeclared Host_Alias `%s' referenced near line %d\n",
1463 (pedantic == 1) ? "Warning" : "Error", yyvsp[0].string, sudolineno);
1469 yyval.BOOLEAN = NOMATCH;
1471 efree(yyvsp[0].string);
1475 #line 460 "parse.yacc"
1479 #line 460 "parse.yacc"
1482 * Push the entry onto the stack if it is worth
1483 * saving and reset cmnd_matches for next cmnd.
1485 * We need to save at least one entry on
1486 * the stack so sudoers_lookup() can tell that
1487 * the user was listed in sudoers. Also, we
1488 * need to be able to tell whether or not a
1489 * user was listed for this specific host.
1491 * If keepall is set and the user matches then
1492 * we need to keep entries around too...
1494 if (MATCHED(user_matches) &&
1495 MATCHED(host_matches) &&
1496 MATCHED(cmnd_matches) &&
1497 MATCHED(runas_matches))
1499 else if (MATCHED(user_matches) && (top == 1 ||
1500 (top == 2 && MATCHED(host_matches) &&
1501 !MATCHED(match[0].host))))
1503 else if (user_matches == TRUE && keepall)
1505 cmnd_matches = UNSPEC;
1509 #line 489 "parse.yacc"
1511 SETMATCH(cmnd_matches, yyvsp[0].BOOLEAN);
1515 #line 492 "parse.yacc"
1517 if (printmatches == TRUE) {
1518 if (in_alias == TRUE)
1519 append_entries("!", ", ");
1520 else if (host_matches == TRUE &&
1521 user_matches == TRUE)
1522 append_cmnd("!", NULL);
1527 #line 500 "parse.yacc"
1529 SETNMATCH(cmnd_matches, yyvsp[0].BOOLEAN);
1533 #line 505 "parse.yacc"
1535 if (printmatches == TRUE && host_matches == TRUE &&
1536 user_matches == TRUE) {
1537 if (runas_matches == UNSPEC) {
1538 cm_list[cm_list_len].runas_len = 0;
1540 /* Inherit runas data. */
1541 cm_list[cm_list_len].runas =
1542 estrdup(cm_list[cm_list_len-1].runas);
1543 cm_list[cm_list_len].runas_len =
1544 cm_list[cm_list_len-1].runas_len;
1545 cm_list[cm_list_len].runas_size =
1546 cm_list[cm_list_len-1].runas_size;
1550 * If this is the first entry in a command list
1551 * then check against default runas user.
1553 if (runas_matches == UNSPEC) {
1554 runas_matches = userpw_matches(def_runas_default,
1555 *user_runas, runas_pw) ? TRUE : NOMATCH;
1560 #line 529 "parse.yacc"
1562 runas_matches = yyvsp[0].BOOLEAN;
1566 #line 534 "parse.yacc"
1570 #line 535 "parse.yacc"
1572 /* Later entries override earlier ones. */
1573 if (yyvsp[0].BOOLEAN != NOMATCH)
1574 yyval.BOOLEAN = yyvsp[0].BOOLEAN;
1576 yyval.BOOLEAN = yyvsp[-2].BOOLEAN;
1580 #line 544 "parse.yacc"
1584 #line 545 "parse.yacc"
1586 if (printmatches == TRUE) {
1587 if (in_alias == TRUE)
1588 append_entries("!", ", ");
1589 else if (host_matches == TRUE &&
1590 user_matches == TRUE)
1591 append_runas("!", ", ");
1596 #line 553 "parse.yacc"
1598 /* Set $$ to the negation of runasuser */
1599 yyval.BOOLEAN = (yyvsp[0].BOOLEAN == NOMATCH ? NOMATCH : ! yyvsp[0].BOOLEAN);
1603 #line 559 "parse.yacc"
1605 if (printmatches == TRUE) {
1606 if (in_alias == TRUE)
1607 append_entries(yyvsp[0].string, ", ");
1608 else if (host_matches == TRUE &&
1609 user_matches == TRUE)
1610 append_runas(yyvsp[0].string, ", ");
1612 if (userpw_matches(yyvsp[0].string, *user_runas, runas_pw))
1613 yyval.BOOLEAN = TRUE;
1615 yyval.BOOLEAN = NOMATCH;
1616 efree(yyvsp[0].string);
1621 #line 574 "parse.yacc"
1623 if (printmatches == TRUE) {
1624 if (in_alias == TRUE)
1625 append_entries(yyvsp[0].string, ", ");
1626 else if (host_matches == TRUE &&
1627 user_matches == TRUE)
1628 append_runas(yyvsp[0].string, ", ");
1630 if (usergr_matches(yyvsp[0].string, *user_runas, runas_pw))
1631 yyval.BOOLEAN = TRUE;
1633 yyval.BOOLEAN = NOMATCH;
1634 efree(yyvsp[0].string);
1639 #line 589 "parse.yacc"
1641 if (printmatches == TRUE) {
1642 if (in_alias == TRUE)
1643 append_entries(yyvsp[0].string, ", ");
1644 else if (host_matches == TRUE &&
1645 user_matches == TRUE)
1646 append_runas(yyvsp[0].string, ", ");
1648 if (netgr_matches(yyvsp[0].string, NULL, NULL, *user_runas))
1649 yyval.BOOLEAN = TRUE;
1651 yyval.BOOLEAN = NOMATCH;
1652 efree(yyvsp[0].string);
1657 #line 604 "parse.yacc"
1659 aliasinfo *aip = find_alias(yyvsp[0].string, RUNAS_ALIAS);
1661 if (printmatches == TRUE) {
1662 if (in_alias == TRUE)
1663 append_entries(yyvsp[0].string, ", ");
1664 else if (host_matches == TRUE &&
1665 user_matches == TRUE)
1666 append_runas(yyvsp[0].string, ", ");
1668 /* could be an all-caps username */
1670 yyval.BOOLEAN = aip->val;
1671 else if (strcmp(yyvsp[0].string, *user_runas) == 0)
1672 yyval.BOOLEAN = TRUE;
1675 (void) fprintf(stderr,
1676 "%s: undeclared Runas_Alias `%s' referenced near line %d\n",
1677 (pedantic == 1) ? "Warning" : "Error", yyvsp[0].string, sudolineno);
1683 yyval.BOOLEAN = NOMATCH;
1685 efree(yyvsp[0].string);
1690 #line 634 "parse.yacc"
1692 if (printmatches == TRUE) {
1693 if (in_alias == TRUE)
1694 append_entries("ALL", ", ");
1695 else if (host_matches == TRUE &&
1696 user_matches == TRUE)
1697 append_runas("ALL", ", ");
1699 yyval.BOOLEAN = TRUE;
1703 #line 646 "parse.yacc"
1705 /* Inherit {NO,}{PASSWD,EXEC,SETENV} status. */
1706 if (printmatches == TRUE && host_matches == TRUE &&
1707 user_matches == TRUE) {
1708 if (no_passwd == TRUE)
1709 cm_list[cm_list_len].nopasswd = TRUE;
1711 cm_list[cm_list_len].nopasswd = FALSE;
1712 if (no_execve == TRUE)
1713 cm_list[cm_list_len].noexecve = TRUE;
1715 cm_list[cm_list_len].noexecve = FALSE;
1716 if (setenv_ok == TRUE)
1717 cm_list[cm_list_len].setenv = TRUE;
1719 cm_list[cm_list_len].setenv = FALSE;
1724 #line 664 "parse.yacc"
1727 if (printmatches == TRUE && host_matches == TRUE &&
1728 user_matches == TRUE)
1729 cm_list[cm_list_len].nopasswd = TRUE;
1733 #line 670 "parse.yacc"
1736 if (printmatches == TRUE && host_matches == TRUE &&
1737 user_matches == TRUE)
1738 cm_list[cm_list_len].nopasswd = FALSE;
1742 #line 676 "parse.yacc"
1745 if (printmatches == TRUE && host_matches == TRUE &&
1746 user_matches == TRUE)
1747 cm_list[cm_list_len].noexecve = TRUE;
1751 #line 682 "parse.yacc"
1754 if (printmatches == TRUE && host_matches == TRUE &&
1755 user_matches == TRUE)
1756 cm_list[cm_list_len].noexecve = FALSE;
1760 #line 688 "parse.yacc"
1763 if (printmatches == TRUE && host_matches == TRUE &&
1764 user_matches == TRUE)
1765 cm_list[cm_list_len].setenv = TRUE;
1769 #line 694 "parse.yacc"
1772 if (printmatches == TRUE && host_matches == TRUE &&
1773 user_matches == TRUE)
1774 cm_list[cm_list_len].setenv = FALSE;
1778 #line 702 "parse.yacc"
1780 if (printmatches == TRUE) {
1781 if (in_alias == TRUE)
1782 append_entries("ALL", ", ");
1783 else if (host_matches == TRUE &&
1784 user_matches == TRUE) {
1785 append_cmnd("ALL", NULL);
1786 expand_match_list();
1789 /* sudo "ALL" implies the SETENV tag */
1790 if (setenv_ok == UNSPEC)
1791 setenv_ok = IMPLIED;
1795 yyval.BOOLEAN = TRUE;
1799 #line 720 "parse.yacc"
1803 if (printmatches == TRUE) {
1804 if (in_alias == TRUE)
1805 append_entries(yyvsp[0].string, ", ");
1806 else if (host_matches == TRUE &&
1807 user_matches == TRUE) {
1808 append_cmnd(yyvsp[0].string, NULL);
1809 expand_match_list();
1813 if ((aip = find_alias(yyvsp[0].string, CMND_ALIAS)))
1814 yyval.BOOLEAN = aip->val;
1817 (void) fprintf(stderr,
1818 "%s: undeclared Cmnd_Alias `%s' referenced near line %d\n",
1819 (pedantic == 1) ? "Warning" : "Error", yyvsp[0].string, sudolineno);
1825 yyval.BOOLEAN = NOMATCH;
1827 efree(yyvsp[0].string);
1831 #line 749 "parse.yacc"
1833 if (printmatches == TRUE) {
1834 if (in_alias == TRUE) {
1835 append_entries(yyvsp[0].command.cmnd, ", ");
1836 if (yyvsp[0].command.args)
1837 append_entries(yyvsp[0].command.args, " ");
1839 if (host_matches == TRUE &&
1840 user_matches == TRUE) {
1841 append_cmnd(yyvsp[0].command.cmnd, NULL);
1842 if (yyvsp[0].command.args)
1843 append_cmnd(yyvsp[0].command.args, " ");
1844 expand_match_list();
1848 if (command_matches(yyvsp[0].command.cmnd, yyvsp[0].command.args))
1849 yyval.BOOLEAN = TRUE;
1851 yyval.BOOLEAN = NOMATCH;
1853 efree(yyvsp[0].command.cmnd);
1854 efree(yyvsp[0].command.args);
1858 #line 779 "parse.yacc"
1862 #line 779 "parse.yacc"
1864 if ((MATCHED(host_matches) || pedantic) &&
1865 !add_alias(yyvsp[-3].string, HOST_ALIAS, host_matches)) {
1873 #line 797 "parse.yacc"
1876 if (printmatches == TRUE) {
1878 /* Allocate space for ga_list if necessary. */
1880 ga_list[ga_list_len-1].type = CMND_ALIAS;
1881 ga_list[ga_list_len-1].alias = estrdup(yyvsp[0].string);
1886 #line 806 "parse.yacc"
1888 if ((MATCHED(cmnd_matches) || pedantic) &&
1889 !add_alias(yyvsp[-3].string, CMND_ALIAS, cmnd_matches)) {
1894 efree(yyvsp[-3].string);
1896 if (printmatches == TRUE)
1901 #line 820 "parse.yacc"
1905 #line 828 "parse.yacc"
1907 if (printmatches == TRUE) {
1909 /* Allocate space for ga_list if necessary. */
1911 ga_list[ga_list_len-1].type = RUNAS_ALIAS;
1912 ga_list[ga_list_len-1].alias = estrdup(yyvsp[0].string);
1917 #line 836 "parse.yacc"
1919 if ((yyvsp[0].BOOLEAN != NOMATCH || pedantic) &&
1920 !add_alias(yyvsp[-3].string, RUNAS_ALIAS, yyvsp[0].BOOLEAN)) {
1924 efree(yyvsp[-3].string);
1926 if (printmatches == TRUE)
1931 #line 853 "parse.yacc"
1935 #line 853 "parse.yacc"
1937 if ((MATCHED(user_matches) || pedantic) &&
1938 !add_alias(yyvsp[-3].string, USER_ALIAS, user_matches)) {
1943 efree(yyvsp[-3].string);
1947 #line 868 "parse.yacc"
1949 SETMATCH(user_matches, yyvsp[0].BOOLEAN);
1953 #line 871 "parse.yacc"
1955 SETNMATCH(user_matches, yyvsp[0].BOOLEAN);
1959 #line 876 "parse.yacc"
1961 if (userpw_matches(yyvsp[0].string, user_name, sudo_user.pw))
1962 yyval.BOOLEAN = TRUE;
1964 yyval.BOOLEAN = NOMATCH;
1965 efree(yyvsp[0].string);
1969 #line 883 "parse.yacc"
1971 if (usergr_matches(yyvsp[0].string, user_name, sudo_user.pw))
1972 yyval.BOOLEAN = TRUE;
1974 yyval.BOOLEAN = NOMATCH;
1975 efree(yyvsp[0].string);
1979 #line 890 "parse.yacc"
1981 if (netgr_matches(yyvsp[0].string, NULL, NULL, user_name))
1982 yyval.BOOLEAN = TRUE;
1984 yyval.BOOLEAN = NOMATCH;
1985 efree(yyvsp[0].string);
1989 #line 897 "parse.yacc"
1991 aliasinfo *aip = find_alias(yyvsp[0].string, USER_ALIAS);
1993 /* could be an all-caps username */
1995 yyval.BOOLEAN = aip->val;
1996 else if (strcmp(yyvsp[0].string, user_name) == 0)
1997 yyval.BOOLEAN = TRUE;
2000 (void) fprintf(stderr,
2001 "%s: undeclared User_Alias `%s' referenced near line %d\n",
2002 (pedantic == 1) ? "Warning" : "Error", yyvsp[0].string, sudolineno);
2008 yyval.BOOLEAN = NOMATCH;
2010 efree(yyvsp[0].string);
2014 #line 919 "parse.yacc"
2016 yyval.BOOLEAN = TRUE;
2019 #line 1968 "sudo.tab.c"
2025 if (yystate == 0 && yym == 0)
2029 printf("%sdebug: after reduction, shifting from state 0 to\
2030 state %d\n", YYPREFIX, YYFINAL);
2037 if ((yychar = yylex()) < 0) yychar = 0;
2042 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
2043 if (!yys) yys = "illegal-symbol";
2044 printf("%sdebug: state %d, reading %d (%s)\n",
2045 YYPREFIX, YYFINAL, yychar, yys);
2049 if (yychar == 0) goto yyaccept;
2052 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
2053 yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
2054 yystate = yytable[yyn];
2056 yystate = yydgoto[yym];
2059 printf("%sdebug: after reduction, shifting from state %d \
2060 to state %d\n", YYPREFIX, *yyssp, yystate);
2062 if (yyssp >= yysslim && yygrowstack())
2070 yyerror("yacc stack overflow");
2076 yyss = yyssp = NULL;
2077 yyvs = yyvsp = NULL;
2085 yyss = yyssp = NULL;
2086 yyvs = yyvsp = NULL;