1 /* A Bison parser, made from parse.yacc
4 #define YYBISON 1 /* Identify Bison output. */
11 # define USERGROUP 262
14 # define DEFAULTS_HOST 265
15 # define DEFAULTS_USER 266
21 # define HOSTALIAS 272
22 # define CMNDALIAS 273
23 # define USERALIAS 274
24 # define RUNASALIAS 275
30 * Copyright (c) 1996, 1998-2001 Todd C. Miller <Todd.Miller@courtesan.com>
31 * All rights reserved.
33 * This code is derived from software contributed by Chris Jepeway.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
46 * 3. The name of the author may not be used to endorse or promote products
47 * derived from this software without specific prior written permission.
49 * 4. Products derived from this software may not be called "Sudo" nor
50 * may "Sudo" appear in their names without specific prior written
51 * permission from the author.
53 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
54 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
55 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
56 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
57 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
58 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
59 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
60 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
61 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
62 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
66 * XXX - the whole opFOO naming thing is somewhat bogus.
68 * XXX - the way things are stored for printmatches is stupid,
69 * they should be stored as elements in an array and then
70 * list_matches() can format things the way it wants.
75 #include <sys/types.h>
76 #include <sys/param.h>
85 #endif /* STDC_HEADERS */
89 # ifdef HAVE_STRINGS_H
92 #endif /* HAVE_STRING_H */
95 #endif /* HAVE_UNISTD_H */
97 #if defined(HAVE_MALLOC_H) && !defined(STDC_HEADERS)
99 #endif /* HAVE_MALLOC_H && !STDC_HEADERS */
100 #if defined(YYBISON) && defined(HAVE_ALLOCA_H) && !defined(__GNUC__)
102 #endif /* YYBISON && HAVE_ALLOCA_H && !__GNUC__ */
105 #endif /* HAVE_LSEARCH */
111 #include "emul/search.h"
112 #endif /* HAVE_LSEARCH */
115 static const char rcsid[] = "$Sudo: parse.yacc,v 1.180 2002/03/16 00:44:47 millert Exp $";
121 extern int sudolineno, parse_error;
122 int errorlineno = -1;
123 int clearaliases = TRUE;
124 int printmatches = FALSE;
125 int pedantic = FALSE;
135 #define RUNAS_ALIAS 4
138 * The matching stack, initial space allocated in init_parser().
140 struct matchstack *match;
141 int top = 0, stacksize = 0;
145 if (top >= stacksize) { \
146 while ((stacksize += STACKINCREMENT) < top); \
147 match = (struct matchstack *) erealloc(match, sizeof(struct matchstack) * stacksize); \
149 match[top].user = -1; \
150 match[top].cmnd = -1; \
151 match[top].host = -1; \
152 match[top].runas = -1; \
153 match[top].nopass = def_flag(I_AUTHENTICATE) ? -1 : TRUE; \
159 if (top >= stacksize) { \
160 while ((stacksize += STACKINCREMENT) < top); \
161 match = (struct matchstack *) erealloc(match, sizeof(struct matchstack) * stacksize); \
163 match[top].user = match[top-1].user; \
164 match[top].cmnd = match[top-1].cmnd; \
165 match[top].host = match[top-1].host; \
166 match[top].runas = match[top-1].runas; \
167 match[top].nopass = match[top-1].nopass; \
174 yyerror("matching stack underflow"); \
180 * Shortcuts for append()
182 #define append_cmnd(s, p) append(s, &cm_list[cm_list_len].cmnd, \
183 &cm_list[cm_list_len].cmnd_len, &cm_list[cm_list_len].cmnd_size, p)
185 #define append_runas(s, p) append(s, &cm_list[cm_list_len].runas, \
186 &cm_list[cm_list_len].runas_len, &cm_list[cm_list_len].runas_size, p)
188 #define append_entries(s, p) append(s, &ga_list[ga_list_len-1].entries, \
189 &ga_list[ga_list_len-1].entries_len, \
190 &ga_list[ga_list_len-1].entries_size, p)
193 * The stack for printmatches. A list of allowed commands for the user.
195 static struct command_match *cm_list = NULL;
196 static size_t cm_list_len = 0, cm_list_size = 0;
199 * List of Cmnd_Aliases and expansions for `sudo -l'
201 static int in_alias = FALSE;
202 static size_t ga_list_len = 0, ga_list_size = 0;
203 static struct generic_alias *ga_list = NULL;
206 * Does this Defaults list pertain to this user?
208 static int defaults_matches = 0;
213 static int add_alias __P((char *, int, int));
214 static void append __P((char *, char **, size_t *, size_t *, char *));
215 static void expand_ga_list __P((void));
216 static void expand_match_list __P((void));
217 static aliasinfo *find_alias __P((char *, int));
218 static int more_aliases __P((void));
219 void init_parser __P((void));
220 void yyerror __P((char *));
226 /* Save the line the first error occurred on. */
227 if (errorlineno == -1)
228 errorlineno = sudolineno ? sudolineno - 1 : 0;
231 (void) fprintf(stderr, ">>> sudoers file: %s, line %d <<<\n", s,
232 sudolineno ? sudolineno - 1 : 0);
234 (void) fprintf(stderr, "<*> ");
240 #line 214 "parse.yacc"
245 struct sudo_command command;
248 # define YYSTYPE yystype
249 # define YYSTYPE_IS_TRIVIAL 1
258 #define YYFLAG -32768
261 /* YYTRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */
262 #define YYTRANSLATE(x) ((unsigned)(x) <= 276 ? yytranslate[x] : 70)
264 /* YYTRANSLATE[YYLEX] -- Bison token number corresponding to YYLEX. */
265 static const char yytranslate[] =
267 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
268 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
269 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
270 2, 2, 2, 25, 2, 2, 2, 2, 2, 2,
271 2, 2, 2, 26, 24, 27, 2, 2, 2, 2,
272 2, 2, 2, 2, 2, 2, 2, 2, 22, 2,
273 2, 23, 2, 2, 2, 2, 2, 2, 2, 2,
274 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
275 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
276 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
277 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
278 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
279 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
280 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
281 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
282 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
283 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
284 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
285 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
286 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
287 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
288 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
289 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
290 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
291 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
292 2, 2, 2, 2, 2, 2, 1, 3, 4, 5,
293 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
294 16, 17, 18, 19, 20, 21, 28
298 static const short yyprhs[] =
300 0, 0, 2, 5, 7, 10, 11, 15, 18, 21,
301 24, 27, 29, 32, 34, 35, 39, 40, 44, 46,
302 50, 52, 55, 59, 63, 67, 69, 73, 77, 79,
303 82, 84, 86, 88, 90, 92, 94, 98, 102, 104,
304 105, 109, 110, 113, 115, 119, 121, 122, 126, 128,
305 130, 132, 134, 136, 137, 139, 141, 143, 145, 147,
306 149, 153, 154, 159, 161, 165, 167, 171, 172, 177,
307 179, 183, 185, 189, 190, 195, 197, 201, 202, 207,
308 209, 213, 215, 218, 220, 222, 224, 226
310 static const short yyrhs[] =
312 30, 0, 29, 30, 0, 17, 0, 1, 17, 0,
313 0, 31, 67, 38, 0, 20, 64, 0, 18, 53,
314 0, 19, 57, 0, 21, 61, 0, 32, 0, 33,
315 36, 0, 10, 0, 0, 12, 34, 67, 0, 0,
316 11, 35, 56, 0, 37, 0, 37, 24, 36, 0,
317 5, 0, 25, 5, 0, 5, 23, 9, 0, 5,
318 26, 9, 0, 5, 27, 9, 0, 39, 0, 38,
319 22, 39, 0, 56, 23, 42, 0, 41, 0, 25,
320 41, 0, 16, 0, 6, 0, 7, 0, 9, 0,
321 4, 0, 43, 0, 42, 24, 43, 0, 46, 51,
322 44, 0, 52, 0, 0, 25, 45, 52, 0, 0,
323 13, 47, 0, 48, 0, 47, 24, 48, 0, 50,
324 0, 0, 25, 49, 50, 0, 9, 0, 8, 0,
325 7, 0, 4, 0, 16, 0, 0, 14, 0, 15,
326 0, 16, 0, 4, 0, 3, 0, 54, 0, 53,
327 22, 54, 0, 0, 4, 55, 23, 56, 0, 40,
328 0, 56, 24, 40, 0, 58, 0, 57, 22, 58,
329 0, 0, 4, 59, 23, 60, 0, 44, 0, 60,
330 24, 44, 0, 62, 0, 61, 22, 62, 0, 0,
331 4, 63, 23, 47, 0, 65, 0, 64, 22, 65,
332 0, 0, 4, 66, 23, 67, 0, 68, 0, 67,
333 24, 68, 0, 69, 0, 25, 69, 0, 9, 0,
334 8, 0, 7, 0, 4, 0, 16, 0
340 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
341 static const short yyrline[] =
343 0, 259, 260, 263, 265, 267, 267, 271, 273, 275,
344 277, 279, 283, 285, 288, 288, 292, 292, 298, 299,
345 301, 309, 317, 326, 335, 345, 346, 349, 364, 368,
346 373, 376, 383, 390, 397, 421, 422, 425, 452, 456,
347 456, 470, 493, 498, 499, 508, 509, 509, 522, 536,
348 550, 564, 593, 605, 615, 621, 629, 642, 671, 699,
349 700, 703, 703, 711, 712, 715, 716, 719, 719, 740,
350 741, 744, 745, 748, 748, 767, 768, 771, 771, 780,
351 781, 784, 788, 793, 800, 807, 814, 834
356 #if (YYDEBUG) || defined YYERROR_VERBOSE
358 /* YYTNAME[TOKEN_NUM] -- String name of the token TOKEN_NUM. */
359 static const char *const yytname[] =
361 "$", "error", "$undefined.", "COMMAND", "ALIAS", "DEFVAR", "NTWKADDR",
362 "NETGROUP", "USERGROUP", "WORD", "DEFAULTS", "DEFAULTS_HOST",
363 "DEFAULTS_USER", "RUNAS", "NOPASSWD", "PASSWD", "ALL", "COMMENT",
364 "HOSTALIAS", "CMNDALIAS", "USERALIAS", "RUNASALIAS", "':'", "'='",
365 "','", "'!'", "'+'", "'-'", "ERROR", "file", "entry", "@1",
366 "defaults_line", "defaults_type", "@2", "@3", "defaults_list",
367 "defaults_entry", "privileges", "privilege", "ophost", "host",
368 "cmndspeclist", "cmndspec", "opcmnd", "@4", "runasspec", "runaslist",
369 "oprunasuser", "@5", "runasuser", "nopasswd", "cmnd", "hostaliases",
370 "hostalias", "@6", "hostlist", "cmndaliases", "cmndalias", "@7",
371 "cmndlist", "runasaliases", "runasalias", "@8", "useraliases",
372 "useralias", "@9", "userlist", "opuser", "user", 0
376 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
377 static const short yyr1[] =
379 0, 29, 29, 30, 30, 31, 30, 30, 30, 30,
380 30, 30, 32, 33, 34, 33, 35, 33, 36, 36,
381 37, 37, 37, 37, 37, 38, 38, 39, 40, 40,
382 41, 41, 41, 41, 41, 42, 42, 43, 44, 45,
383 44, 46, 46, 47, 47, 48, 49, 48, 50, 50,
384 50, 50, 50, 51, 51, 51, 52, 52, 52, 53,
385 53, 55, 54, 56, 56, 57, 57, 59, 58, 60,
386 60, 61, 61, 63, 62, 64, 64, 66, 65, 67,
387 67, 68, 68, 69, 69, 69, 69, 69
390 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
391 static const short yyr2[] =
393 0, 1, 2, 1, 2, 0, 3, 2, 2, 2,
394 2, 1, 2, 1, 0, 3, 0, 3, 1, 3,
395 1, 2, 3, 3, 3, 1, 3, 3, 1, 2,
396 1, 1, 1, 1, 1, 1, 3, 3, 1, 0,
397 3, 0, 2, 1, 3, 1, 0, 3, 1, 1,
398 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
399 3, 0, 4, 1, 3, 1, 3, 0, 4, 1,
400 3, 1, 3, 0, 4, 1, 3, 0, 4, 1,
401 3, 1, 2, 1, 1, 1, 1, 1
404 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
405 doesn't specify something else to do. Zero means the default is an
407 static const short yydefact[] =
409 0, 0, 13, 16, 14, 3, 0, 0, 0, 0,
410 0, 1, 0, 11, 0, 4, 0, 0, 61, 8,
411 59, 67, 9, 65, 77, 7, 75, 73, 10, 71,
412 2, 86, 85, 84, 83, 87, 0, 0, 79, 81,
413 20, 0, 12, 18, 34, 31, 32, 33, 30, 0,
414 63, 28, 17, 15, 0, 0, 0, 0, 0, 0,
415 0, 0, 82, 0, 6, 25, 0, 0, 0, 0,
416 21, 0, 29, 0, 0, 60, 0, 66, 0, 76,
417 0, 72, 80, 0, 41, 22, 23, 24, 19, 64,
418 62, 58, 57, 56, 39, 69, 38, 68, 78, 51,
419 50, 49, 48, 52, 46, 74, 43, 45, 26, 0,
420 27, 35, 53, 0, 0, 0, 0, 42, 41, 54,
421 55, 0, 40, 70, 47, 44, 36, 37, 0, 0
424 static const short yydefgoto[] =
426 10, 11, 12, 13, 14, 17, 16, 42, 43, 64,
427 65, 50, 51, 110, 111, 95, 113, 112, 105, 106,
428 115, 107, 121, 96, 19, 20, 54, 66, 22, 23,
429 56, 97, 28, 29, 60, 25, 26, 58, 37, 38,
433 static const short yypact[] =
435 24, -10,-32768,-32768,-32768,-32768, 12, 20, 35, 50,
436 2,-32768, 48,-32768, 33,-32768, 68, 48,-32768, 15,
437 -32768,-32768, 40,-32768,-32768, 41,-32768,-32768, 45,-32768,
438 -32768,-32768,-32768,-32768,-32768,-32768, 78, 44,-32768,-32768,
439 83, 65,-32768, 47,-32768,-32768,-32768,-32768,-32768, 92,
440 -32768,-32768, 59, 66, 69, 12, 79, 20, 84, 35,
441 88, 50,-32768, 48, 67,-32768, 6, 82, 86, 104,
442 -32768, 33,-32768, 68, 68,-32768, 1,-32768, 48,-32768,
443 72,-32768,-32768, 68, 101,-32768,-32768,-32768,-32768,-32768,
444 59,-32768,-32768,-32768,-32768,-32768,-32768, 91, 66,-32768,
445 -32768,-32768,-32768,-32768,-32768, 93,-32768,-32768,-32768, 72,
446 94,-32768, 32, 62, 1, 96, 72, 93, 101,-32768,
447 -32768, 1,-32768,-32768,-32768,-32768,-32768,-32768, 116,-32768
450 static const short yypgoto[] =
452 -32768, 109,-32768,-32768,-32768,-32768,-32768, 49,-32768,-32768,
453 38, 51, 73,-32768, 5, -106,-32768,-32768, 16, 10,
454 -32768, 13,-32768, 14,-32768, 74,-32768, -15,-32768, 75,
455 -32768,-32768,-32768, 70,-32768,-32768, 71,-32768, -17, 76,
463 static const short yytable[] =
465 53, 52, 128, 1, 91, 92, -5, 15, 123, -5,
466 -5, -5, 2, 3, 4, 127, 18, 93, -5, 5,
467 6, 7, 8, 9, 21, 1, 94, -5, -5, 84,
468 73, -5, -5, -5, 2, 3, 4, 55, 40, 24,
469 -5, 5, 6, 7, 8, 9, 119, 120, 44, -5,
470 45, 46, 31, 47, 27, 32, 33, 34, 41, 90,
471 48, 98, 57, 59, 35, 91, 92, 61, 63, 49,
472 70, 71, 44, 36, 45, 46, 99, 47, 93, 100,
473 101, 102, 31, 73, 48, 32, 33, 34, 103, 83,
474 63, 85, 74, 49, 35, 86, 44, 104, 45, 46,
475 99, 47, 76, 100, 101, 102, 67, 78, 48, 68,
476 69, 80, 103, 87, 109, 114, 129, 116, 118, 30,
477 88, 108, 72, 126, 89, 117, 125, 122, 124, 75,
478 79, 81, 77, 62, 0, 0, 0, 0, 0, 82
481 static const short yycheck[] =
483 17, 16, 0, 1, 3, 4, 4, 17, 114, 7,
484 8, 9, 10, 11, 12, 121, 4, 16, 16, 17,
485 18, 19, 20, 21, 4, 1, 25, 25, 4, 23,
486 24, 7, 8, 9, 10, 11, 12, 22, 5, 4,
487 16, 17, 18, 19, 20, 21, 14, 15, 4, 25,
488 6, 7, 4, 9, 4, 7, 8, 9, 25, 74,
489 16, 78, 22, 22, 16, 3, 4, 22, 24, 25,
490 5, 24, 4, 25, 6, 7, 4, 9, 16, 7,
491 8, 9, 4, 24, 16, 7, 8, 9, 16, 22,
492 24, 9, 23, 25, 16, 9, 4, 25, 6, 7,
493 4, 9, 23, 7, 8, 9, 23, 23, 16, 26,
494 27, 23, 16, 9, 13, 24, 0, 24, 24, 10,
495 71, 83, 49, 118, 73, 109, 116, 113, 115, 55,
496 59, 61, 57, 36, -1, -1, -1, -1, -1, 63
498 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
499 #line 3 "/usr/share/bison/bison.simple"
501 /* Skeleton output parser for bison,
503 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software
506 This program is free software; you can redistribute it and/or modify
507 it under the terms of the GNU General Public License as published by
508 the Free Software Foundation; either version 2, or (at your option)
511 This program is distributed in the hope that it will be useful,
512 but WITHOUT ANY WARRANTY; without even the implied warranty of
513 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
514 GNU General Public License for more details.
516 You should have received a copy of the GNU General Public License
517 along with this program; if not, write to the Free Software
518 Foundation, Inc., 59 Temple Place - Suite 330,
519 Boston, MA 02111-1307, USA. */
521 /* As a special exception, when this file is copied by Bison into a
522 Bison output file, you may use that output file without restriction.
523 This special exception was added by the Free Software Foundation
524 in version 1.24 of Bison. */
526 /* This is the parser code that is written into each bison parser when
527 the %semantic_parser declaration is not specified in the grammar.
528 It was written by Richard Stallman by simplifying the hairy parser
529 used when %semantic_parser is specified. */
531 /* All symbols defined below should begin with yy or YY, to avoid
532 infringing on user name space. This should be done even for local
533 variables, as they might otherwise be expanded by user macros.
534 There are some unavoidable exceptions within include files to
535 define necessary library symbols; they are noted "INFRINGES ON
536 USER NAME SPACE" below. */
538 #if ! defined (yyoverflow) || defined (YYERROR_VERBOSE)
540 /* The parser invokes alloca or malloc; define the necessary symbols. */
542 # if YYSTACK_USE_ALLOCA
543 # define YYSTACK_ALLOC alloca
545 # ifndef YYSTACK_USE_ALLOCA
546 # if defined (alloca) || defined (_ALLOCA_H)
547 # define YYSTACK_ALLOC alloca
550 # define YYSTACK_ALLOC __builtin_alloca
556 # ifdef YYSTACK_ALLOC
557 /* Pacify GCC's `empty if-body' warning. */
558 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
560 # if defined (__STDC__) || defined (__cplusplus)
561 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
562 # define YYSIZE_T size_t
564 # define YYSTACK_ALLOC malloc
565 # define YYSTACK_FREE free
567 #endif /* ! defined (yyoverflow) || defined (YYERROR_VERBOSE) */
570 #if (! defined (yyoverflow) \
571 && (! defined (__cplusplus) \
572 || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
574 /* A type that is properly aligned for any stack member. */
584 /* The size of the maximum gap between one aligned stack and the next. */
585 # define YYSTACK_GAP_MAX (sizeof (union yyalloc) - 1)
587 /* The size of an array large to enough to hold all stacks, each with
590 # define YYSTACK_BYTES(N) \
591 ((N) * (sizeof (short) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
592 + 2 * YYSTACK_GAP_MAX)
594 # define YYSTACK_BYTES(N) \
595 ((N) * (sizeof (short) + sizeof (YYSTYPE)) \
599 /* Copy COUNT objects from FROM to TO. The source and destination do
603 # define YYCOPY(To, From, Count) \
604 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
606 # define YYCOPY(To, From, Count) \
609 register YYSIZE_T yyi; \
610 for (yyi = 0; yyi < (Count); yyi++) \
611 (To)[yyi] = (From)[yyi]; \
617 /* Relocate STACK from its old location to the new one. The
618 local variables YYSIZE and YYSTACKSIZE give the old and new number of
619 elements in the stack, and YYPTR gives the new location of the
620 stack. Advance YYPTR to a properly aligned location for the next
622 # define YYSTACK_RELOCATE(Stack) \
625 YYSIZE_T yynewbytes; \
626 YYCOPY (&yyptr->Stack, Stack, yysize); \
627 Stack = &yyptr->Stack; \
628 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAX; \
629 yyptr += yynewbytes / sizeof (*yyptr); \
636 #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
637 # define YYSIZE_T __SIZE_TYPE__
639 #if ! defined (YYSIZE_T) && defined (size_t)
640 # define YYSIZE_T size_t
642 #if ! defined (YYSIZE_T)
643 # if defined (__STDC__) || defined (__cplusplus)
644 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
645 # define YYSIZE_T size_t
648 #if ! defined (YYSIZE_T)
649 # define YYSIZE_T unsigned int
652 #define yyerrok (yyerrstatus = 0)
653 #define yyclearin (yychar = YYEMPTY)
656 #define YYACCEPT goto yyacceptlab
657 #define YYABORT goto yyabortlab
658 #define YYERROR goto yyerrlab1
659 /* Like YYERROR except do call yyerror. This remains here temporarily
660 to ease the transition to the new meaning of YYERROR, for GCC.
661 Once GCC version 2 has supplanted version 1, this can go. */
662 #define YYFAIL goto yyerrlab
663 #define YYRECOVERING() (!!yyerrstatus)
664 #define YYBACKUP(Token, Value) \
666 if (yychar == YYEMPTY && yylen == 1) \
670 yychar1 = YYTRANSLATE (yychar); \
676 yyerror ("syntax error: cannot back up"); \
682 #define YYERRCODE 256
685 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
688 When YYLLOC_DEFAULT is run, CURRENT is set the location of the
689 first token. By default, to implement support for ranges, extend
690 its range to the last symbol. */
692 #ifndef YYLLOC_DEFAULT
693 # define YYLLOC_DEFAULT(Current, Rhs, N) \
694 Current.last_line = Rhs[N].last_line; \
695 Current.last_column = Rhs[N].last_column;
699 /* YYLEX -- calling `yylex' with the right arguments. */
704 # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
706 # define YYLEX yylex (&yylval, &yylloc)
708 # else /* !YYLSP_NEEDED */
710 # define YYLEX yylex (&yylval, YYLEX_PARAM)
712 # define YYLEX yylex (&yylval)
714 # endif /* !YYLSP_NEEDED */
716 # define YYLEX yylex ()
720 /* Enable debugging if requested. */
724 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
725 # define YYFPRINTF fprintf
728 # define YYDPRINTF(Args) \
733 /* Nonzero means print parse trace. It is left uninitialized so that
734 multiple parsers can coexist. */
737 # define YYDPRINTF(Args)
738 #endif /* !YYDEBUG */
740 /* YYINITDEPTH -- initial size of the parser's stacks. */
742 # define YYINITDEPTH 200
745 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
746 if the built-in stack extension method is used).
748 Do not make this value too large; the results are undefined if
749 SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
750 evaluated with infinite-precision integer arithmetic. */
757 # define YYMAXDEPTH 10000
760 #ifdef YYERROR_VERBOSE
763 # if defined (__GLIBC__) && defined (_STRING_H)
764 # define yystrlen strlen
766 /* Return the length of YYSTR. */
768 # if defined (__STDC__) || defined (__cplusplus)
769 yystrlen (const char *yystr)
775 register const char *yys = yystr;
777 while (*yys++ != '\0')
780 return yys - yystr - 1;
786 # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
787 # define yystpcpy stpcpy
789 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
792 # if defined (__STDC__) || defined (__cplusplus)
793 yystpcpy (char *yydest, const char *yysrc)
795 yystpcpy (yydest, yysrc)
800 register char *yyd = yydest;
801 register const char *yys = yysrc;
803 while ((*yyd++ = *yys++) != '\0')
812 #line 315 "/usr/share/bison/bison.simple"
815 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
816 into yyparse. The argument should have type void *.
817 It should actually point to an object.
818 Grammar actions can access the variable by casting it
819 to the proper pointer type. */
822 # if defined (__STDC__) || defined (__cplusplus)
823 # define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
824 # define YYPARSE_PARAM_DECL
826 # define YYPARSE_PARAM_ARG YYPARSE_PARAM
827 # define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
829 #else /* !YYPARSE_PARAM */
830 # define YYPARSE_PARAM_ARG
831 # define YYPARSE_PARAM_DECL
832 #endif /* !YYPARSE_PARAM */
834 /* Prevent warning if -Wstrict-prototypes. */
836 # ifdef YYPARSE_PARAM
837 int yyparse (void *);
843 /* YY_DECL_VARIABLES -- depending whether we use a pure parser,
844 variables are global, or local to YYPARSE. */
846 #define YY_DECL_NON_LSP_VARIABLES \
847 /* The lookahead symbol. */ \
850 /* The semantic value of the lookahead symbol. */ \
853 /* Number of parse errors so far. */ \
857 # define YY_DECL_VARIABLES \
858 YY_DECL_NON_LSP_VARIABLES \
860 /* Location data for the lookahead symbol. */ \
863 # define YY_DECL_VARIABLES \
864 YY_DECL_NON_LSP_VARIABLES
868 /* If nonreentrant, generate the variables here. */
875 yyparse (YYPARSE_PARAM_ARG)
878 /* If reentrant, generate the variables here. */
883 register int yystate;
886 /* Number of tokens to shift before error messages enabled. */
888 /* Lookahead token as an internal (translated) token number. */
891 /* Three stacks and their tools:
892 `yyss': related to states,
893 `yyvs': related to semantic values,
894 `yyls': related to locations.
896 Refer to the stacks thru separate pointers, to allow yyoverflow
897 to reallocate them elsewhere. */
899 /* The state stack. */
900 short yyssa[YYINITDEPTH];
902 register short *yyssp;
904 /* The semantic value stack. */
905 YYSTYPE yyvsa[YYINITDEPTH];
906 YYSTYPE *yyvs = yyvsa;
907 register YYSTYPE *yyvsp;
910 /* The location stack. */
911 YYLTYPE yylsa[YYINITDEPTH];
912 YYLTYPE *yyls = yylsa;
917 # define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
919 # define YYPOPSTACK (yyvsp--, yyssp--)
922 YYSIZE_T yystacksize = YYINITDEPTH;
925 /* The variables used to return semantic value and location from the
932 /* When reducing, the number of symbols on the RHS of the reduced
936 YYDPRINTF ((stderr, "Starting parse\n"));
941 yychar = YYEMPTY; /* Cause a token to be read. */
943 /* Initialize stack pointers.
944 Waste one element of value and location stack
945 so that they stay on the same level as the state stack.
946 The wasted elements are never initialized. */
955 /*------------------------------------------------------------.
956 | yynewstate -- Push a new state, which is found in yystate. |
957 `------------------------------------------------------------*/
959 /* In all cases, when you get here, the value and location stacks
960 have just been pushed. so pushing a state here evens the stacks.
967 if (yyssp >= yyss + yystacksize - 1)
969 /* Get the current used size of the three stacks, in elements. */
970 YYSIZE_T yysize = yyssp - yyss + 1;
974 /* Give user a chance to reallocate the stack. Use copies of
975 these so that the &'s don't force the real ones into
977 YYSTYPE *yyvs1 = yyvs;
980 /* Each stack pointer address is followed by the size of the
981 data in use in that stack, in bytes. */
983 YYLTYPE *yyls1 = yyls;
984 /* This used to be a conditional around just the two extra args,
985 but that might be undefined if yyoverflow is a macro. */
986 yyoverflow ("parser stack overflow",
987 &yyss1, yysize * sizeof (*yyssp),
988 &yyvs1, yysize * sizeof (*yyvsp),
989 &yyls1, yysize * sizeof (*yylsp),
993 yyoverflow ("parser stack overflow",
994 &yyss1, yysize * sizeof (*yyssp),
995 &yyvs1, yysize * sizeof (*yyvsp),
1001 #else /* no yyoverflow */
1002 # ifndef YYSTACK_RELOCATE
1005 /* Extend the stack our own way. */
1006 if (yystacksize >= YYMAXDEPTH)
1009 if (yystacksize > YYMAXDEPTH)
1010 yystacksize = YYMAXDEPTH;
1013 short *yyss1 = yyss;
1014 union yyalloc *yyptr =
1015 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1018 YYSTACK_RELOCATE (yyss);
1019 YYSTACK_RELOCATE (yyvs);
1021 YYSTACK_RELOCATE (yyls);
1023 # undef YYSTACK_RELOCATE
1025 YYSTACK_FREE (yyss1);
1028 #endif /* no yyoverflow */
1030 yyssp = yyss + yysize - 1;
1031 yyvsp = yyvs + yysize - 1;
1033 yylsp = yyls + yysize - 1;
1036 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1037 (unsigned long int) yystacksize));
1039 if (yyssp >= yyss + yystacksize - 1)
1043 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1053 /* Do appropriate processing given the current state. */
1054 /* Read a lookahead token if we need one and don't already have one. */
1057 /* First try to decide what to do without reference to lookahead token. */
1059 yyn = yypact[yystate];
1063 /* Not known => get a lookahead token if don't already have one. */
1065 /* yychar is either YYEMPTY or YYEOF
1066 or a valid token in external form. */
1068 if (yychar == YYEMPTY)
1070 YYDPRINTF ((stderr, "Reading a token: "));
1074 /* Convert token to internal form (in yychar1) for indexing tables with */
1076 if (yychar <= 0) /* This means end of input. */
1079 yychar = YYEOF; /* Don't call YYLEX any more */
1081 YYDPRINTF ((stderr, "Now at end of input.\n"));
1085 yychar1 = YYTRANSLATE (yychar);
1088 /* We have to keep this `#if YYDEBUG', since we use variables
1089 which are defined only if `YYDEBUG' is set. */
1092 YYFPRINTF (stderr, "Next token is %d (%s",
1093 yychar, yytname[yychar1]);
1094 /* Give the individual parser a way to print the precise
1095 meaning of a token, for further debugging info. */
1097 YYPRINT (stderr, yychar, yylval);
1099 YYFPRINTF (stderr, ")\n");
1105 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
1110 /* yyn is what to do for this token type in this state.
1111 Negative => reduce, -yyn is rule number.
1112 Positive => shift, yyn is new state.
1113 New state is final state => don't bother to shift,
1114 just return success.
1115 0, or most negative number => error. */
1130 /* Shift the lookahead token. */
1131 YYDPRINTF ((stderr, "Shifting token %d (%s), ",
1132 yychar, yytname[yychar1]));
1134 /* Discard the token being shifted unless it is eof. */
1135 if (yychar != YYEOF)
1143 /* Count tokens shifted since error; after three, turn off error
1152 /*-----------------------------------------------------------.
1153 | yydefault -- do the default action for the current state. |
1154 `-----------------------------------------------------------*/
1156 yyn = yydefact[yystate];
1162 /*-----------------------------.
1163 | yyreduce -- Do a reduction. |
1164 `-----------------------------*/
1166 /* yyn is the number of a rule to reduce with. */
1169 /* If YYLEN is nonzero, implement the default value of the action:
1172 Otherwise, the following line sets YYVAL to the semantic value of
1173 the lookahead token. This behavior is undocumented and Bison
1174 users should not rely upon it. Assigning to YYVAL
1175 unconditionally makes the parser a bit smaller, and it avoids a
1176 GCC warning that YYVAL may be used uninitialized. */
1177 yyval = yyvsp[1-yylen];
1180 /* Similarly for the default location. Let the user run additional
1181 commands if for instance locations are ranges. */
1182 yyloc = yylsp[1-yylen];
1183 YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
1187 /* We have to keep this `#if YYDEBUG', since we use variables which
1188 are defined only if `YYDEBUG' is set. */
1193 YYFPRINTF (stderr, "Reducing via rule %d (line %d), ",
1196 /* Print the symbols being reduced, and their result. */
1197 for (yyi = yyprhs[yyn]; yyrhs[yyi] > 0; yyi++)
1198 YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]);
1199 YYFPRINTF (stderr, " -> %s\n", yytname[yyr1[yyn]]);
1206 #line 264 "parse.yacc"
1210 #line 266 "parse.yacc"
1214 #line 267 "parse.yacc"
1218 #line 267 "parse.yacc"
1220 while (top && user_matches != TRUE)
1225 #line 272 "parse.yacc"
1229 #line 274 "parse.yacc"
1233 #line 276 "parse.yacc"
1237 #line 278 "parse.yacc"
1241 #line 280 "parse.yacc"
1245 #line 285 "parse.yacc"
1247 defaults_matches = TRUE;
1251 #line 288 "parse.yacc"
1255 #line 288 "parse.yacc"
1257 defaults_matches = user_matches;
1262 #line 292 "parse.yacc"
1266 #line 292 "parse.yacc"
1268 defaults_matches = host_matches;
1273 #line 301 "parse.yacc"
1275 if (defaults_matches == TRUE &&
1276 !set_default(yyvsp[0].string, NULL, TRUE)) {
1280 free(yyvsp[0].string);
1284 #line 309 "parse.yacc"
1286 if (defaults_matches == TRUE &&
1287 !set_default(yyvsp[0].string, NULL, FALSE)) {
1291 free(yyvsp[0].string);
1295 #line 317 "parse.yacc"
1297 if (defaults_matches == TRUE &&
1298 !set_default(yyvsp[-2].string, yyvsp[0].string, TRUE)) {
1302 free(yyvsp[-2].string);
1303 free(yyvsp[0].string);
1307 #line 326 "parse.yacc"
1309 if (defaults_matches == TRUE &&
1310 !set_default(yyvsp[-2].string, yyvsp[0].string, '+')) {
1314 free(yyvsp[-2].string);
1315 free(yyvsp[0].string);
1319 #line 335 "parse.yacc"
1321 if (defaults_matches == TRUE &&
1322 !set_default(yyvsp[-2].string, yyvsp[0].string, '-')) {
1326 free(yyvsp[-2].string);
1327 free(yyvsp[0].string);
1331 #line 349 "parse.yacc"
1334 * We already did a push if necessary in
1335 * cmndspec so just reset some values so
1336 * the next 'privilege' gets a clean slate.
1340 if (def_flag(I_AUTHENTICATE))
1347 #line 364 "parse.yacc"
1349 if (yyvsp[0].BOOLEAN != -1)
1350 host_matches = yyvsp[0].BOOLEAN;
1354 #line 368 "parse.yacc"
1356 if (yyvsp[0].BOOLEAN != -1)
1357 host_matches = ! yyvsp[0].BOOLEAN;
1361 #line 373 "parse.yacc"
1363 yyval.BOOLEAN = TRUE;
1367 #line 376 "parse.yacc"
1369 if (addr_matches(yyvsp[0].string))
1370 yyval.BOOLEAN = TRUE;
1373 free(yyvsp[0].string);
1377 #line 383 "parse.yacc"
1379 if (netgr_matches(yyvsp[0].string, user_host, user_shost, NULL))
1380 yyval.BOOLEAN = TRUE;
1383 free(yyvsp[0].string);
1387 #line 390 "parse.yacc"
1389 if (hostname_matches(user_shost, user_host, yyvsp[0].string) == 0)
1390 yyval.BOOLEAN = TRUE;
1393 free(yyvsp[0].string);
1397 #line 397 "parse.yacc"
1399 aliasinfo *aip = find_alias(yyvsp[0].string, HOST_ALIAS);
1401 /* could be an all-caps hostname */
1403 yyval.BOOLEAN = aip->val;
1404 else if (strcasecmp(user_shost, yyvsp[0].string) == 0)
1405 yyval.BOOLEAN = TRUE;
1408 (void) fprintf(stderr,
1409 "%s: undeclared Host_Alias `%s' referenced near line %d\n",
1410 (pedantic == 1) ? "Warning" : "Error", yyvsp[0].string, sudolineno);
1418 free(yyvsp[0].string);
1422 #line 425 "parse.yacc"
1425 * Push the entry onto the stack if it is worth
1426 * saving and clear cmnd_matches for next cmnd.
1428 * We need to save at least one entry on
1429 * the stack so sudoers_lookup() can tell that
1430 * the user was listed in sudoers. Also, we
1431 * need to be able to tell whether or not a
1432 * user was listed for this specific host.
1434 * If keepall is set and the user matches then
1435 * we need to keep entries around too...
1437 if (user_matches != -1 && host_matches != -1 &&
1438 cmnd_matches != -1 && runas_matches != -1)
1440 else if (user_matches != -1 && (top == 1 ||
1441 (top == 2 && host_matches != -1 &&
1442 match[0].host == -1)))
1444 else if (user_matches == TRUE && keepall)
1450 #line 452 "parse.yacc"
1452 if (yyvsp[0].BOOLEAN != -1)
1453 cmnd_matches = yyvsp[0].BOOLEAN;
1457 #line 456 "parse.yacc"
1459 if (printmatches == TRUE) {
1460 if (in_alias == TRUE)
1461 append_entries("!", ", ");
1462 else if (host_matches == TRUE &&
1463 user_matches == TRUE)
1464 append_cmnd("!", NULL);
1469 #line 464 "parse.yacc"
1471 if (yyvsp[0].BOOLEAN != -1)
1472 cmnd_matches = ! yyvsp[0].BOOLEAN;
1476 #line 470 "parse.yacc"
1478 if (printmatches == TRUE && host_matches == TRUE &&
1479 user_matches == TRUE) {
1480 if (runas_matches == -1) {
1481 cm_list[cm_list_len].runas_len = 0;
1483 /* Inherit runas data. */
1484 cm_list[cm_list_len].runas =
1485 estrdup(cm_list[cm_list_len-1].runas);
1486 cm_list[cm_list_len].runas_len =
1487 cm_list[cm_list_len-1].runas_len;
1488 cm_list[cm_list_len].runas_size =
1489 cm_list[cm_list_len-1].runas_size;
1493 * If this is the first entry in a command list
1494 * then check against default runas user.
1496 if (runas_matches == -1)
1497 runas_matches = (strcmp(*user_runas,
1498 def_str(I_RUNAS_DEFAULT)) == 0);
1502 #line 493 "parse.yacc"
1504 runas_matches = (yyvsp[0].BOOLEAN == TRUE ? TRUE : FALSE);
1508 #line 498 "parse.yacc"
1512 #line 499 "parse.yacc"
1514 /* Later entries override earlier ones. */
1515 if (yyvsp[0].BOOLEAN != -1)
1516 yyval.BOOLEAN = yyvsp[0].BOOLEAN;
1518 yyval.BOOLEAN = yyvsp[-2].BOOLEAN;
1522 #line 508 "parse.yacc"
1526 #line 509 "parse.yacc"
1528 if (printmatches == TRUE) {
1529 if (in_alias == TRUE)
1530 append_entries("!", ", ");
1531 else if (host_matches == TRUE &&
1532 user_matches == TRUE)
1533 append_runas("!", ", ");
1538 #line 517 "parse.yacc"
1540 /* Set $$ to the negation of runasuser */
1541 yyval.BOOLEAN = (yyvsp[0].BOOLEAN == -1 ? -1 : ! yyvsp[0].BOOLEAN);
1545 #line 522 "parse.yacc"
1547 if (printmatches == TRUE) {
1548 if (in_alias == TRUE)
1549 append_entries(yyvsp[0].string, ", ");
1550 else if (host_matches == TRUE &&
1551 user_matches == TRUE)
1552 append_runas(yyvsp[0].string, ", ");
1554 if (strcmp(yyvsp[0].string, *user_runas) == 0)
1555 yyval.BOOLEAN = TRUE;
1558 free(yyvsp[0].string);
1562 #line 536 "parse.yacc"
1564 if (printmatches == TRUE) {
1565 if (in_alias == TRUE)
1566 append_entries(yyvsp[0].string, ", ");
1567 else if (host_matches == TRUE &&
1568 user_matches == TRUE)
1569 append_runas(yyvsp[0].string, ", ");
1571 if (usergr_matches(yyvsp[0].string, *user_runas))
1572 yyval.BOOLEAN = TRUE;
1575 free(yyvsp[0].string);
1579 #line 550 "parse.yacc"
1581 if (printmatches == TRUE) {
1582 if (in_alias == TRUE)
1583 append_entries(yyvsp[0].string, ", ");
1584 else if (host_matches == TRUE &&
1585 user_matches == TRUE)
1586 append_runas(yyvsp[0].string, ", ");
1588 if (netgr_matches(yyvsp[0].string, NULL, NULL, *user_runas))
1589 yyval.BOOLEAN = TRUE;
1592 free(yyvsp[0].string);
1596 #line 564 "parse.yacc"
1598 aliasinfo *aip = find_alias(yyvsp[0].string, RUNAS_ALIAS);
1600 if (printmatches == TRUE) {
1601 if (in_alias == TRUE)
1602 append_entries(yyvsp[0].string, ", ");
1603 else if (host_matches == TRUE &&
1604 user_matches == TRUE)
1605 append_runas(yyvsp[0].string, ", ");
1607 /* could be an all-caps username */
1609 yyval.BOOLEAN = aip->val;
1610 else if (strcmp(yyvsp[0].string, *user_runas) == 0)
1611 yyval.BOOLEAN = TRUE;
1614 (void) fprintf(stderr,
1615 "%s: undeclared Runas_Alias `%s' referenced near line %d\n",
1616 (pedantic == 1) ? "Warning" : "Error", yyvsp[0].string, sudolineno);
1624 free(yyvsp[0].string);
1628 #line 593 "parse.yacc"
1630 if (printmatches == TRUE) {
1631 if (in_alias == TRUE)
1632 append_entries("ALL", ", ");
1633 else if (host_matches == TRUE &&
1634 user_matches == TRUE)
1635 append_runas("ALL", ", ");
1637 yyval.BOOLEAN = TRUE;
1641 #line 605 "parse.yacc"
1643 /* Inherit NOPASSWD/PASSWD status. */
1644 if (printmatches == TRUE && host_matches == TRUE &&
1645 user_matches == TRUE) {
1646 if (no_passwd == TRUE)
1647 cm_list[cm_list_len].nopasswd = TRUE;
1649 cm_list[cm_list_len].nopasswd = FALSE;
1654 #line 615 "parse.yacc"
1657 if (printmatches == TRUE && host_matches == TRUE &&
1658 user_matches == TRUE)
1659 cm_list[cm_list_len].nopasswd = TRUE;
1663 #line 621 "parse.yacc"
1666 if (printmatches == TRUE && host_matches == TRUE &&
1667 user_matches == TRUE)
1668 cm_list[cm_list_len].nopasswd = FALSE;
1672 #line 629 "parse.yacc"
1674 if (printmatches == TRUE) {
1675 if (in_alias == TRUE)
1676 append_entries("ALL", ", ");
1677 else if (host_matches == TRUE &&
1678 user_matches == TRUE) {
1679 append_cmnd("ALL", NULL);
1680 expand_match_list();
1684 yyval.BOOLEAN = TRUE;
1688 #line 642 "parse.yacc"
1692 if (printmatches == TRUE) {
1693 if (in_alias == TRUE)
1694 append_entries(yyvsp[0].string, ", ");
1695 else if (host_matches == TRUE &&
1696 user_matches == TRUE) {
1697 append_cmnd(yyvsp[0].string, NULL);
1698 expand_match_list();
1702 if ((aip = find_alias(yyvsp[0].string, CMND_ALIAS)))
1703 yyval.BOOLEAN = aip->val;
1706 (void) fprintf(stderr,
1707 "%s: undeclared Cmnd_Alias `%s' referenced near line %d\n",
1708 (pedantic == 1) ? "Warning" : "Error", yyvsp[0].string, sudolineno);
1716 free(yyvsp[0].string);
1720 #line 671 "parse.yacc"
1722 if (printmatches == TRUE) {
1723 if (in_alias == TRUE) {
1724 append_entries(yyvsp[0].command.cmnd, ", ");
1725 if (yyvsp[0].command.args)
1726 append_entries(yyvsp[0].command.args, " ");
1728 if (host_matches == TRUE &&
1729 user_matches == TRUE) {
1730 append_cmnd(yyvsp[0].command.cmnd, NULL);
1731 if (yyvsp[0].command.args)
1732 append_cmnd(yyvsp[0].command.args, " ");
1733 expand_match_list();
1737 if (command_matches(user_cmnd, user_args,
1738 yyvsp[0].command.cmnd, yyvsp[0].command.args))
1739 yyval.BOOLEAN = TRUE;
1743 free(yyvsp[0].command.cmnd);
1744 if (yyvsp[0].command.args)
1745 free(yyvsp[0].command.args);
1749 #line 703 "parse.yacc"
1753 #line 703 "parse.yacc"
1755 if ((host_matches != -1 || pedantic) &&
1756 !add_alias(yyvsp[-3].string, HOST_ALIAS, host_matches))
1762 #line 719 "parse.yacc"
1765 if (printmatches == TRUE) {
1767 /* Allocate space for ga_list if necessary. */
1769 ga_list[ga_list_len-1].type = CMND_ALIAS;
1770 ga_list[ga_list_len-1].alias = estrdup(yyvsp[0].string);
1775 #line 728 "parse.yacc"
1777 if ((cmnd_matches != -1 || pedantic) &&
1778 !add_alias(yyvsp[-3].string, CMND_ALIAS, cmnd_matches))
1781 free(yyvsp[-3].string);
1783 if (printmatches == TRUE)
1788 #line 740 "parse.yacc"
1792 #line 748 "parse.yacc"
1794 if (printmatches == TRUE) {
1796 /* Allocate space for ga_list if necessary. */
1798 ga_list[ga_list_len-1].type = RUNAS_ALIAS;
1799 ga_list[ga_list_len-1].alias = estrdup(yyvsp[0].string);
1804 #line 756 "parse.yacc"
1806 if ((yyvsp[0].BOOLEAN != -1 || pedantic) &&
1807 !add_alias(yyvsp[-3].string, RUNAS_ALIAS, yyvsp[0].BOOLEAN))
1809 free(yyvsp[-3].string);
1811 if (printmatches == TRUE)
1816 #line 771 "parse.yacc"
1820 #line 771 "parse.yacc"
1822 if ((user_matches != -1 || pedantic) &&
1823 !add_alias(yyvsp[-3].string, USER_ALIAS, user_matches))
1826 free(yyvsp[-3].string);
1830 #line 784 "parse.yacc"
1832 if (yyvsp[0].BOOLEAN != -1)
1833 user_matches = yyvsp[0].BOOLEAN;
1837 #line 788 "parse.yacc"
1839 if (yyvsp[0].BOOLEAN != -1)
1840 user_matches = ! yyvsp[0].BOOLEAN;
1844 #line 793 "parse.yacc"
1846 if (strcmp(yyvsp[0].string, user_name) == 0)
1847 yyval.BOOLEAN = TRUE;
1850 free(yyvsp[0].string);
1854 #line 800 "parse.yacc"
1856 if (usergr_matches(yyvsp[0].string, user_name))
1857 yyval.BOOLEAN = TRUE;
1860 free(yyvsp[0].string);
1864 #line 807 "parse.yacc"
1866 if (netgr_matches(yyvsp[0].string, NULL, NULL, user_name))
1867 yyval.BOOLEAN = TRUE;
1870 free(yyvsp[0].string);
1874 #line 814 "parse.yacc"
1876 aliasinfo *aip = find_alias(yyvsp[0].string, USER_ALIAS);
1878 /* could be an all-caps username */
1880 yyval.BOOLEAN = aip->val;
1881 else if (strcmp(yyvsp[0].string, user_name) == 0)
1882 yyval.BOOLEAN = TRUE;
1885 (void) fprintf(stderr,
1886 "%s: undeclared User_Alias `%s' referenced near line %d\n",
1887 (pedantic == 1) ? "Warning" : "Error", yyvsp[0].string, sudolineno);
1893 free(yyvsp[0].string);
1897 #line 834 "parse.yacc"
1899 yyval.BOOLEAN = TRUE;
1904 #line 705 "/usr/share/bison/bison.simple"
1916 short *yyssp1 = yyss - 1;
1917 YYFPRINTF (stderr, "state stack now");
1918 while (yyssp1 != yyssp)
1919 YYFPRINTF (stderr, " %d", *++yyssp1);
1920 YYFPRINTF (stderr, "\n");
1929 /* Now `shift' the result of the reduction. Determine what state
1930 that goes to, based on the state we popped back to and the rule
1931 number reduced by. */
1935 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
1936 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1937 yystate = yytable[yystate];
1939 yystate = yydefgoto[yyn - YYNTBASE];
1944 /*------------------------------------.
1945 | yyerrlab -- here on detecting error |
1946 `------------------------------------*/
1948 /* If not already recovering from an error, report this error. */
1953 #ifdef YYERROR_VERBOSE
1954 yyn = yypact[yystate];
1956 if (yyn > YYFLAG && yyn < YYLAST)
1958 YYSIZE_T yysize = 0;
1963 /* Start YYX at -YYN if negative to avoid negative indexes in
1965 for (yyx = yyn < 0 ? -yyn : 0;
1966 yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)
1967 if (yycheck[yyx + yyn] == yyx)
1968 yysize += yystrlen (yytname[yyx]) + 15, yycount++;
1969 yysize += yystrlen ("parse error, unexpected ") + 1;
1970 yysize += yystrlen (yytname[YYTRANSLATE (yychar)]);
1971 yymsg = (char *) YYSTACK_ALLOC (yysize);
1974 char *yyp = yystpcpy (yymsg, "parse error, unexpected ");
1975 yyp = yystpcpy (yyp, yytname[YYTRANSLATE (yychar)]);
1980 for (yyx = yyn < 0 ? -yyn : 0;
1981 yyx < (int) (sizeof (yytname) / sizeof (char *));
1983 if (yycheck[yyx + yyn] == yyx)
1985 const char *yyq = ! yycount ? ", expecting " : " or ";
1986 yyp = yystpcpy (yyp, yyq);
1987 yyp = yystpcpy (yyp, yytname[yyx]);
1992 YYSTACK_FREE (yymsg);
1995 yyerror ("parse error; also virtual memory exhausted");
1998 #endif /* defined (YYERROR_VERBOSE) */
1999 yyerror ("parse error");
2004 /*--------------------------------------------------.
2005 | yyerrlab1 -- error raised explicitly by an action |
2006 `--------------------------------------------------*/
2008 if (yyerrstatus == 3)
2010 /* If just tried and failed to reuse lookahead token after an
2011 error, discard it. */
2013 /* return failure if at end of input */
2014 if (yychar == YYEOF)
2016 YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
2017 yychar, yytname[yychar1]));
2021 /* Else will try to reuse lookahead token after shifting the error
2024 yyerrstatus = 3; /* Each real token shifted decrements this */
2029 /*-------------------------------------------------------------------.
2030 | yyerrdefault -- current state does not do anything special for the |
2032 `-------------------------------------------------------------------*/
2035 /* This is wrong; only states that explicitly want error tokens
2036 should shift them. */
2038 /* If its default is to accept any token, ok. Otherwise pop it. */
2039 yyn = yydefact[yystate];
2045 /*---------------------------------------------------------------.
2046 | yyerrpop -- pop the current state because it cannot handle the |
2048 `---------------------------------------------------------------*/
2061 short *yyssp1 = yyss - 1;
2062 YYFPRINTF (stderr, "Error: state stack now");
2063 while (yyssp1 != yyssp)
2064 YYFPRINTF (stderr, " %d", *++yyssp1);
2065 YYFPRINTF (stderr, "\n");
2073 yyn = yypact[yystate];
2078 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
2095 YYDPRINTF ((stderr, "Shifting error token, "));
2106 /*-------------------------------------.
2107 | yyacceptlab -- YYACCEPT comes here. |
2108 `-------------------------------------*/
2113 /*-----------------------------------.
2114 | yyabortlab -- YYABORT comes here. |
2115 `-----------------------------------*/
2120 /*---------------------------------------------.
2121 | yyoverflowab -- parser overflow comes here. |
2122 `---------------------------------------------*/
2124 yyerror ("parser stack overflow");
2131 YYSTACK_FREE (yyss);
2135 #line 839 "parse.yacc"
2138 #define MOREALIASES (32)
2139 aliasinfo *aliases = NULL;
2140 size_t naliases = 0;
2145 * Compare two aliasinfo structures, strcmp() style.
2146 * Note that we do *not* compare their values.
2150 const VOID *a1, *a2;
2153 aliasinfo *ai1, *ai2;
2155 ai1 = (aliasinfo *) a1;
2156 ai2 = (aliasinfo *) a2;
2157 if ((r = strcmp(ai1->name, ai2->name)) == 0)
2158 r = ai1->type - ai2->type;
2164 * Compare two generic_alias structures, strcmp() style.
2167 genaliascmp(entry, key)
2168 const VOID *entry, *key;
2171 struct generic_alias *ga1, *ga2;
2173 ga1 = (struct generic_alias *) key;
2174 ga2 = (struct generic_alias *) entry;
2175 if ((r = strcmp(ga1->alias, ga2->alias)) == 0)
2176 r = ga1->type - ga2->type;
2183 * Adds the named alias of the specified type to the aliases list.
2186 add_alias(alias, type, val)
2195 if (naliases >= nslots && !more_aliases()) {
2196 (void) snprintf(s, sizeof(s), "Out of memory defining alias `%s'",
2204 ai.name = estrdup(alias);
2205 onaliases = naliases;
2207 aip = (aliasinfo *) lsearch((VOID *)&ai, (VOID *)aliases, &naliases,
2208 sizeof(ai), aliascmp);
2210 (void) snprintf(s, sizeof(s), "Aliases corrupted defining alias `%s'",
2215 if (onaliases == naliases) {
2216 (void) snprintf(s, sizeof(s), "Alias `%s' already defined", alias);
2225 * Searches for the named alias of the specified type.
2228 find_alias(alias, type)
2237 return((aliasinfo *) lfind((VOID *)&ai, (VOID *)aliases, &naliases,
2238 sizeof(ai), aliascmp));
2242 * Allocates more space for the aliases list.
2248 nslots += MOREALIASES;
2249 if (nslots == MOREALIASES)
2250 aliases = (aliasinfo *) malloc(nslots * sizeof(aliasinfo));
2252 aliases = (aliasinfo *) realloc(aliases, nslots * sizeof(aliasinfo));
2254 return(aliases != NULL);
2258 * Lists the contents of the aliases list.
2265 for (n = 0; n < naliases; n++) {
2266 if (aliases[n].val == -1)
2269 switch (aliases[n].type) {
2271 (void) puts("HOST_ALIAS");
2275 (void) puts("CMND_ALIAS");
2279 (void) puts("USER_ALIAS");
2283 (void) puts("RUNAS_ALIAS");
2286 (void) printf("\t%s: %d\n", aliases[n].name, aliases[n].val);
2291 * Lists the contents of cm_list and ga_list for `sudo -l'.
2298 struct generic_alias *ga, key;
2300 (void) printf("User %s may run the following commands on this host:\n",
2302 for (i = 0; i < cm_list_len; i++) {
2304 /* Print the runas list. */
2305 (void) fputs(" ", stdout);
2306 if (cm_list[i].runas) {
2307 (void) putchar('(');
2308 p = strtok(cm_list[i].runas, ", ");
2310 if (p != cm_list[i].runas)
2311 (void) fputs(", ", stdout);
2314 key.type = RUNAS_ALIAS;
2315 if ((ga = (struct generic_alias *) lfind((VOID *) &key,
2316 (VOID *) &ga_list[0], &ga_list_len, sizeof(key), genaliascmp)))
2317 (void) fputs(ga->entries, stdout);
2319 (void) fputs(p, stdout);
2320 } while ((p = strtok(NULL, ", ")));
2321 (void) fputs(") ", stdout);
2323 (void) printf("(%s) ", def_str(I_RUNAS_DEFAULT));
2326 /* Is a password required? */
2327 if (cm_list[i].nopasswd == TRUE && def_flag(I_AUTHENTICATE))
2328 (void) fputs("NOPASSWD: ", stdout);
2329 else if (cm_list[i].nopasswd == FALSE && !def_flag(I_AUTHENTICATE))
2330 (void) fputs("PASSWD: ", stdout);
2332 /* Print the actual command or expanded Cmnd_Alias. */
2333 key.alias = cm_list[i].cmnd;
2334 key.type = CMND_ALIAS;
2335 if ((ga = (struct generic_alias *) lfind((VOID *) &key,
2336 (VOID *) &ga_list[0], &ga_list_len, sizeof(key), genaliascmp)))
2337 (void) puts(ga->entries);
2339 (void) puts(cm_list[i].cmnd);
2342 /* Be nice and free up space now that we are done. */
2343 for (i = 0; i < ga_list_len; i++) {
2344 free(ga_list[i].alias);
2345 free(ga_list[i].entries);
2350 for (i = 0; i < cm_list_len; i++) {
2351 free(cm_list[i].runas);
2352 free(cm_list[i].cmnd);
2361 * Appends a source string to the destination, optionally prefixing a separator.
2364 append(src, dstp, dst_len, dst_size, separator)
2366 size_t *dst_len, *dst_size;
2369 size_t src_len = strlen(src);
2373 * Only add the separator if there is something to separate from.
2374 * If the last char is a '!', don't apply the separator (XXX).
2376 if (separator && dst && dst[*dst_len - 1] != '!')
2377 src_len += strlen(separator);
2381 /* Assumes dst will be NULL if not set. */
2383 dst = (char *) emalloc(BUFSIZ);
2389 /* Allocate more space if necessary. */
2390 if (*dst_size <= *dst_len + src_len) {
2391 while (*dst_size <= *dst_len + src_len)
2392 *dst_size += BUFSIZ;
2394 dst = (char *) erealloc(dst, *dst_size);
2398 /* Copy src -> dst adding a separator if appropriate and adjust len. */
2400 *dst_len += src_len;
2403 (void) strcat(dst, separator);
2404 (void) strcat(dst, src);
2408 * Frees up space used by the aliases list and resets the associated counters.
2416 for (n = 0; n < naliases; n++)
2417 free(aliases[n].name);
2421 naliases = nslots = 0;
2425 * Increments ga_list_len, allocating more space as necessary.
2431 if (++ga_list_len >= ga_list_size) {
2432 while ((ga_list_size += STACKINCREMENT) < ga_list_len)
2434 ga_list = (struct generic_alias *)
2435 erealloc(ga_list, sizeof(struct generic_alias) * ga_list_size);
2438 ga_list[ga_list_len - 1].entries = NULL;
2442 * Increments cm_list_len, allocating more space as necessary.
2448 if (++cm_list_len >= cm_list_size) {
2449 while ((cm_list_size += STACKINCREMENT) < cm_list_len)
2451 if (cm_list == NULL)
2452 cm_list_len = 0; /* start at 0 since it is a subscript */
2453 cm_list = (struct command_match *)
2454 erealloc(cm_list, sizeof(struct command_match) * cm_list_size);
2457 cm_list[cm_list_len].runas = cm_list[cm_list_len].cmnd = NULL;
2458 cm_list[cm_list_len].nopasswd = FALSE;
2462 * Frees up spaced used by a previous parser run and allocates new space
2463 * for various data structures.
2469 /* Free up old data structures if we run the parser more than once. */
2474 parse_error = FALSE;
2479 /* Allocate space for the matching stack. */
2480 stacksize = STACKINCREMENT;
2481 match = (struct matchstack *) emalloc(sizeof(struct matchstack) * stacksize);
2483 /* Allocate space for the match list (for `sudo -l'). */
2484 if (printmatches == TRUE)
2485 expand_match_list();