--- embedaddon/sudo/plugins/sudoers/toke.c 2013/07/22 10:46:12 1.1.1.4 +++ embedaddon/sudo/plugins/sudoers/toke.c 2014/06/15 16:12:54 1.1.1.5 @@ -16,12 +16,12 @@ #define yyrestart sudoersrestart #define yytext sudoerstext -/* $OpenBSD: flex.skl,v 1.11 2010/08/04 18:24:50 millert Exp $ */ +/* $OpenBSD: flex.skl,v 1.12 2013/11/04 17:03:32 millert Exp $ */ /* A lexical scanner generated by flex */ /* Scanner skeleton version: - * $Header: /usr/local/www/users/anoncvs/cvs/embedaddon/sudo/plugins/sudoers/toke.c,v 1.1.1.4 2013/07/22 10:46:12 misho Exp $ + * $Header: /usr/local/www/users/anoncvs/cvs/embedaddon/sudo/plugins/sudoers/toke.c,v 1.1.1.5 2014/06/15 16:12:54 misho Exp $ */ #define FLEX_SCANNER @@ -148,7 +148,7 @@ extern FILE *yyin, *yyout; /* Undo effects of setting up yytext. */ \ *yy_cp = yy_hold_char; \ YY_RESTORE_YY_MORE_OFFSET \ - yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \ + yy_cp = yy_bp + n - YY_MORE_ADJ; \ YY_DO_BEFORE_ACTION; /* set up yytext again */ \ } \ while ( 0 ) @@ -312,45 +312,45 @@ static yyconst short int yy_accept[814] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 68, 55, 63, 62, 61, 54, - 66, 34, 56, 57, 34, 58, 55, 55, 55, 55, + 65, 34, 56, 57, 34, 58, 55, 55, 55, 55, 60, 59, 66, 46, 46, 46, 46, 46, 46, 46, - 46, 46, 46, 66, 55, 55, 63, 66, 46, 46, + 46, 46, 46, 66, 55, 55, 63, 65, 46, 46, 46, 46, 46, 2, 66, 1, 55, 46, 46, 55, - 17, 16, 17, 16, 16, 66, 66, 66, 3, 9, + 17, 16, 17, 16, 16, 66, 65, 66, 3, 9, 8, 9, 4, 9, 5, 66, 13, 13, 13, 11, 12, 66, 19, 19, 18, 18, 18, 19, 18, 18, 18, 19, 19, 19, 19, 19, 18, 19, 19, 55, - 0, 63, 61, 0, 65, 0, 55, 36, 0, 34, + 0, 63, 61, 65, 65, 0, 55, 36, 0, 34, 0, 35, 0, 53, 53, 0, 55, 55, 0, 55, 55, 55, 55, 0, 39, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 55, 64, 55, - 55, 63, 0, 0, 0, 0, 0, 0, 55, 55, + 55, 63, 0, 0, 0, 0, 0, 65, 55, 55, 55, 55, 55, 2, 1, 0, 1, 47, 47, 0, 55, 17, 17, 15, 14, 15, 0, 0, 3, 9, 0, 6, 7, 9, 9, 13, 0, 13, 13, 0, 10, 36, 0, 0, 35, 19, 19, 0, 19, 0, 0, 18, 18, 18, 18, 18, 18, 19, 19, 46, - 19, 19, 19, 19, 19, 19, 19, 0, 0, 0, + 19, 19, 19, 19, 19, 19, 19, 65, 65, 0, 36, 55, 55, 55, 55, 55, 0, 0, 39, 39, 46, 41, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 55, 55, 0, 0, 0, 0, - 0, 0, 55, 55, 55, 55, 55, 0, 55, 10, + 0, 65, 55, 55, 55, 55, 55, 0, 55, 10, 0, 0, 0, 18, 18, 18, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 0, 55, 55, + 19, 19, 19, 19, 19, 19, 19, 65, 55, 55, 55, 55, 55, 55, 0, 40, 40, 40, 0, 0, 39, 39, 39, 39, 39, 39, 39, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 42, 46, 43, - 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, + 55, 55, 55, 55, 0, 0, 0, 0, 0, 65, 55, 55, 55, 55, 0, 0, 0, 0, 0, 18, 18, 19, 46, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 55, 55, 55, 0, 0, 40, 40, 40, 0, 39, 39, 0, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 0, 27, 46, 46, 46, 46, 46, 46, 46, 46, 44, 46, 55, 55, - 55, 55, 55, 0, 0, 0, 0, 55, 55, 55, + 55, 55, 55, 0, 0, 0, 65, 55, 55, 55, 0, 0, 0, 18, 18, 46, 46, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 55, 55, @@ -358,7 +358,7 @@ static yyconst short int yy_accept[814] = 0, 0, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 46, 46, 46, 46, 46, 46, 46, 46, 46, 48, 49, 50, 51, 55, 0, - 0, 0, 55, 55, 55, 0, 0, 0, 0, 0, + 0, 65, 55, 55, 55, 0, 0, 0, 0, 0, 46, 46, 19, 46, 19, 19, 19, 19, 19, 19, 19, 19, 19, 37, 37, 37, 0, 0, 39, 39, 39, 39, 39, 39, 39, 0, 0, 0, 0, 0, @@ -366,12 +366,12 @@ static yyconst short int yy_accept[814] = 39, 39, 39, 39, 46, 46, 46, 0, 26, 46, 46, 46, 46, 0, 25, 0, 28, 55, 0, 0, - 0, 55, 55, 55, 37, 37, 37, 46, 46, 46, + 65, 55, 55, 55, 37, 37, 37, 46, 46, 46, 46, 19, 19, 19, 55, 37, 37, 37, 37, 0, 39, 0, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 0, 0, 0, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 46, - 46, 46, 46, 46, 46, 46, 52, 0, 0, 0, + 46, 46, 46, 46, 46, 46, 52, 0, 0, 65, 55, 22, 47, 0, 37, 37, 37, 37, 46, 46, 46, 46, 19, 19, 19, 38, 38, 38, 38, 39, 0, 0, 0, 39, 39, 39, 39, 39, 39, 39, @@ -379,23 +379,23 @@ static yyconst short int yy_accept[814] = 39, 39, 39, 39, 39, 39, 0, 0, 0, 0, 0, 39, 39, 39, 39, 39, 39, 39, 39, 46, 46, 46, 46, 46, 0, 24, 0, 29, 0, 22, - 0, 0, 55, 0, 55, 38, 38, 38, 38, 46, + 65, 65, 55, 0, 55, 38, 38, 38, 38, 46, 46, 46, 46, 55, 55, 38, 38, 38, 38, 0, 0, 0, 0, 0, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 45, 0, 32, 46, 46, 46, - 0, 0, 0, 20, 0, 23, 22, 0, 0, 0, + 0, 65, 65, 20, 65, 23, 22, 0, 0, 0, 0, 0, 22, 0, 0, 0, 38, 38, 38, 38, 46, 46, 46, 55, 55, 55, 0, 0, 0, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 0, 30, 46, - 46, 23, 0, 0, 22, 0, 0, 0, 46, 46, + 46, 23, 65, 0, 22, 0, 0, 0, 46, 46, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 39, 39, 39, 39, 39, 39, 39, 39, 0, 33, - 46, 0, 0, 0, 0, 0, 0, 46, 55, 55, - 55, 39, 39, 39, 39, 39, 39, 0, 31, 0, - 0, 21, 0, 0, 0, 55, 55, 55, 55, 55, + 46, 65, 0, 0, 0, 0, 0, 46, 55, 55, + 55, 39, 39, 39, 39, 39, 39, 0, 31, 65, + 65, 21, 0, 0, 0, 55, 55, 55, 55, 55, 39, 39, 39, 39, 39, 0, 0, 0, 0, 0, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, @@ -2007,12 +2007,9 @@ char *yytext; #include "sha2.h" #include "secure_path.h" -extern YYSTYPE sudoerslval; -extern bool parse_error; -extern bool sudoers_warnings; -int sudolineno; -int last_token; -char *sudoers; +int sudolineno; /* current sudoers line number. */ +int last_token; /* last token that was parsed. */ +char *sudoers; /* sudoers file being parsed. */ /* Default sudoers path, mode and owner (may be set via sudo.conf) */ const char *sudoers_file = _PATH_SUDOERS; @@ -2053,7 +2050,7 @@ int (*trace_print)(const char *msg) = sudoers_trace_pr #define WANTDIGEST 6 -#line 2056 "lex.sudoers.c" +#line 2053 "lex.sudoers.c" /* Macros after this point can all be overridden by user definitions in * section 1. @@ -2207,9 +2204,9 @@ YY_DECL register char *yy_cp, *yy_bp; register int yy_act; -#line 140 "toke.l" +#line 137 "toke.l" -#line 2212 "lex.sudoers.c" +#line 2209 "lex.sudoers.c" if ( yy_init ) { @@ -2295,7 +2292,7 @@ do_action: /* This label is used only to access EOF ac case 1: YY_RULE_SETUP -#line 141 "toke.l" +#line 138 "toke.l" { LEXTRACE(", "); LEXRETURN(','); @@ -2303,12 +2300,12 @@ YY_RULE_SETUP YY_BREAK case 2: YY_RULE_SETUP -#line 146 "toke.l" +#line 143 "toke.l" BEGIN STARTDEFS; YY_BREAK case 3: YY_RULE_SETUP -#line 148 "toke.l" +#line 145 "toke.l" { BEGIN INDEFS; LEXTRACE("DEFVAR "); @@ -2320,7 +2317,7 @@ YY_RULE_SETUP case 4: YY_RULE_SETUP -#line 157 "toke.l" +#line 154 "toke.l" { BEGIN STARTDEFS; LEXTRACE(", "); @@ -2329,7 +2326,7 @@ YY_RULE_SETUP YY_BREAK case 5: YY_RULE_SETUP -#line 163 "toke.l" +#line 160 "toke.l" { LEXTRACE("= "); LEXRETURN('='); @@ -2337,7 +2334,7 @@ YY_RULE_SETUP YY_BREAK case 6: YY_RULE_SETUP -#line 168 "toke.l" +#line 165 "toke.l" { LEXTRACE("+= "); LEXRETURN('+'); @@ -2345,7 +2342,7 @@ YY_RULE_SETUP YY_BREAK case 7: YY_RULE_SETUP -#line 173 "toke.l" +#line 170 "toke.l" { LEXTRACE("-= "); LEXRETURN('-'); @@ -2353,7 +2350,7 @@ YY_RULE_SETUP YY_BREAK case 8: YY_RULE_SETUP -#line 178 "toke.l" +#line 175 "toke.l" { LEXTRACE("BEGINSTR "); sudoerslval.string = NULL; @@ -2363,7 +2360,7 @@ YY_RULE_SETUP YY_BREAK case 9: YY_RULE_SETUP -#line 185 "toke.l" +#line 182 "toke.l" { LEXTRACE("WORD(2) "); if (!fill(sudoerstext, sudoersleng)) @@ -2375,7 +2372,7 @@ YY_RULE_SETUP case 10: YY_RULE_SETUP -#line 194 "toke.l" +#line 191 "toke.l" { /* Line continuation char followed by newline. */ sudolineno++; @@ -2384,7 +2381,7 @@ YY_RULE_SETUP YY_BREAK case 11: YY_RULE_SETUP -#line 200 "toke.l" +#line 197 "toke.l" { LEXTRACE("ENDSTR "); BEGIN prev_state; @@ -2419,7 +2416,7 @@ YY_RULE_SETUP YY_BREAK case 12: YY_RULE_SETUP -#line 232 "toke.l" +#line 229 "toke.l" { LEXTRACE("BACKSLASH "); if (!append(sudoerstext, sudoersleng)) @@ -2428,7 +2425,7 @@ YY_RULE_SETUP YY_BREAK case 13: YY_RULE_SETUP -#line 238 "toke.l" +#line 235 "toke.l" { LEXTRACE("STRBODY "); if (!append(sudoerstext, sudoersleng)) @@ -2439,7 +2436,7 @@ YY_RULE_SETUP case 14: YY_RULE_SETUP -#line 246 "toke.l" +#line 243 "toke.l" { /* quoted fnmatch glob char, pass verbatim */ LEXTRACE("QUOTEDCHAR "); @@ -2450,7 +2447,7 @@ YY_RULE_SETUP YY_BREAK case 15: YY_RULE_SETUP -#line 254 "toke.l" +#line 251 "toke.l" { /* quoted sudoers special char, strip backslash */ LEXTRACE("QUOTEDCHAR "); @@ -2461,7 +2458,7 @@ YY_RULE_SETUP YY_BREAK case 16: YY_RULE_SETUP -#line 262 "toke.l" +#line 259 "toke.l" { BEGIN INITIAL; yyless(0); @@ -2470,7 +2467,7 @@ YY_RULE_SETUP YY_BREAK case 17: YY_RULE_SETUP -#line 268 "toke.l" +#line 265 "toke.l" { LEXTRACE("ARG "); if (!fill_args(sudoerstext, sudoersleng, sawspace)) @@ -2481,7 +2478,7 @@ YY_RULE_SETUP case 18: YY_RULE_SETUP -#line 276 "toke.l" +#line 273 "toke.l" { /* Only return DIGEST if the length is correct. */ if (sudoersleng == digest_len * 2) { @@ -2497,10 +2494,10 @@ YY_RULE_SETUP YY_BREAK case 19: YY_RULE_SETUP -#line 289 "toke.l" +#line 286 "toke.l" { /* Only return DIGEST if the length is correct. */ - size_t len; + int len; if (sudoerstext[sudoersleng - 1] == '=') { /* use padding */ len = 4 * ((digest_len + 2) / 3); @@ -2521,7 +2518,7 @@ YY_RULE_SETUP YY_BREAK case 20: YY_RULE_SETUP -#line 310 "toke.l" +#line 307 "toke.l" { char *path; @@ -2542,7 +2539,7 @@ YY_RULE_SETUP YY_BREAK case 21: YY_RULE_SETUP -#line 328 "toke.l" +#line 325 "toke.l" { char *path; @@ -2566,7 +2563,7 @@ YY_RULE_SETUP YY_BREAK case 22: YY_RULE_SETUP -#line 349 "toke.l" +#line 346 "toke.l" { char deftype; int n; @@ -2609,7 +2606,7 @@ YY_RULE_SETUP YY_BREAK case 23: YY_RULE_SETUP -#line 389 "toke.l" +#line 386 "toke.l" { int n; @@ -2638,7 +2635,7 @@ YY_RULE_SETUP YY_BREAK case 24: YY_RULE_SETUP -#line 415 "toke.l" +#line 412 "toke.l" { /* cmnd does not require passwd for this user */ LEXTRACE("NOPASSWD "); @@ -2647,7 +2644,7 @@ YY_RULE_SETUP YY_BREAK case 25: YY_RULE_SETUP -#line 421 "toke.l" +#line 418 "toke.l" { /* cmnd requires passwd for this user */ LEXTRACE("PASSWD "); @@ -2656,7 +2653,7 @@ YY_RULE_SETUP YY_BREAK case 26: YY_RULE_SETUP -#line 427 "toke.l" +#line 424 "toke.l" { LEXTRACE("NOEXEC "); LEXRETURN(NOEXEC); @@ -2664,7 +2661,7 @@ YY_RULE_SETUP YY_BREAK case 27: YY_RULE_SETUP -#line 432 "toke.l" +#line 429 "toke.l" { LEXTRACE("EXEC "); LEXRETURN(EXEC); @@ -2672,7 +2669,7 @@ YY_RULE_SETUP YY_BREAK case 28: YY_RULE_SETUP -#line 437 "toke.l" +#line 434 "toke.l" { LEXTRACE("SETENV "); LEXRETURN(SETENV); @@ -2680,7 +2677,7 @@ YY_RULE_SETUP YY_BREAK case 29: YY_RULE_SETUP -#line 442 "toke.l" +#line 439 "toke.l" { LEXTRACE("NOSETENV "); LEXRETURN(NOSETENV); @@ -2688,7 +2685,7 @@ YY_RULE_SETUP YY_BREAK case 30: YY_RULE_SETUP -#line 447 "toke.l" +#line 444 "toke.l" { LEXTRACE("LOG_OUTPUT "); LEXRETURN(LOG_OUTPUT); @@ -2696,7 +2693,7 @@ YY_RULE_SETUP YY_BREAK case 31: YY_RULE_SETUP -#line 452 "toke.l" +#line 449 "toke.l" { LEXTRACE("NOLOG_OUTPUT "); LEXRETURN(NOLOG_OUTPUT); @@ -2704,7 +2701,7 @@ YY_RULE_SETUP YY_BREAK case 32: YY_RULE_SETUP -#line 457 "toke.l" +#line 454 "toke.l" { LEXTRACE("LOG_INPUT "); LEXRETURN(LOG_INPUT); @@ -2712,7 +2709,7 @@ YY_RULE_SETUP YY_BREAK case 33: YY_RULE_SETUP -#line 462 "toke.l" +#line 459 "toke.l" { LEXTRACE("NOLOG_INPUT "); LEXRETURN(NOLOG_INPUT); @@ -2720,7 +2717,7 @@ YY_RULE_SETUP YY_BREAK case 34: YY_RULE_SETUP -#line 467 "toke.l" +#line 464 "toke.l" { /* empty group or netgroup */ LEXTRACE("ERROR "); @@ -2729,7 +2726,7 @@ YY_RULE_SETUP YY_BREAK case 35: YY_RULE_SETUP -#line 473 "toke.l" +#line 470 "toke.l" { /* netgroup */ if (!fill(sudoerstext, sudoersleng)) @@ -2740,7 +2737,7 @@ YY_RULE_SETUP YY_BREAK case 36: YY_RULE_SETUP -#line 481 "toke.l" +#line 478 "toke.l" { /* group */ if (!fill(sudoerstext, sudoersleng)) @@ -2751,7 +2748,7 @@ YY_RULE_SETUP YY_BREAK case 37: YY_RULE_SETUP -#line 489 "toke.l" +#line 486 "toke.l" { if (!fill(sudoerstext, sudoersleng)) yyterminate(); @@ -2761,7 +2758,7 @@ YY_RULE_SETUP YY_BREAK case 38: YY_RULE_SETUP -#line 496 "toke.l" +#line 493 "toke.l" { if (!fill(sudoerstext, sudoersleng)) yyterminate(); @@ -2771,7 +2768,7 @@ YY_RULE_SETUP YY_BREAK case 39: YY_RULE_SETUP -#line 503 "toke.l" +#line 500 "toke.l" { if (!ipv6_valid(sudoerstext)) { LEXTRACE("ERROR "); @@ -2785,7 +2782,7 @@ YY_RULE_SETUP YY_BREAK case 40: YY_RULE_SETUP -#line 514 "toke.l" +#line 511 "toke.l" { if (!ipv6_valid(sudoerstext)) { LEXTRACE("ERROR "); @@ -2799,7 +2796,7 @@ YY_RULE_SETUP YY_BREAK case 41: YY_RULE_SETUP -#line 525 "toke.l" +#line 522 "toke.l" { LEXTRACE("ALL "); LEXRETURN(ALL); @@ -2808,7 +2805,7 @@ YY_RULE_SETUP YY_BREAK case 42: YY_RULE_SETUP -#line 531 "toke.l" +#line 528 "toke.l" { #ifdef HAVE_SELINUX LEXTRACE("ROLE "); @@ -2820,7 +2817,7 @@ YY_RULE_SETUP YY_BREAK case 43: YY_RULE_SETUP -#line 540 "toke.l" +#line 537 "toke.l" { #ifdef HAVE_SELINUX LEXTRACE("TYPE "); @@ -2832,7 +2829,7 @@ YY_RULE_SETUP YY_BREAK case 44: YY_RULE_SETUP -#line 548 "toke.l" +#line 545 "toke.l" { #ifdef HAVE_PRIV_SET LEXTRACE("PRIVS "); @@ -2844,7 +2841,7 @@ YY_RULE_SETUP YY_BREAK case 45: YY_RULE_SETUP -#line 557 "toke.l" +#line 554 "toke.l" { #ifdef HAVE_PRIV_SET LEXTRACE("LIMITPRIVS "); @@ -2856,7 +2853,7 @@ YY_RULE_SETUP YY_BREAK case 46: YY_RULE_SETUP -#line 566 "toke.l" +#line 563 "toke.l" { got_alias: if (!fill(sudoerstext, sudoersleng)) @@ -2867,7 +2864,7 @@ YY_RULE_SETUP YY_BREAK case 47: YY_RULE_SETUP -#line 574 "toke.l" +#line 571 "toke.l" { /* XXX - no way to specify digest for command */ /* no command args allowed for Defaults!/path */ @@ -2879,7 +2876,7 @@ YY_RULE_SETUP YY_BREAK case 48: YY_RULE_SETUP -#line 583 "toke.l" +#line 580 "toke.l" { digest_len = SHA224_DIGEST_LENGTH; BEGIN WANTDIGEST; @@ -2889,7 +2886,7 @@ YY_RULE_SETUP YY_BREAK case 49: YY_RULE_SETUP -#line 590 "toke.l" +#line 587 "toke.l" { digest_len = SHA256_DIGEST_LENGTH; BEGIN WANTDIGEST; @@ -2899,7 +2896,7 @@ YY_RULE_SETUP YY_BREAK case 50: YY_RULE_SETUP -#line 597 "toke.l" +#line 594 "toke.l" { digest_len = SHA384_DIGEST_LENGTH; BEGIN WANTDIGEST; @@ -2909,7 +2906,7 @@ YY_RULE_SETUP YY_BREAK case 51: YY_RULE_SETUP -#line 604 "toke.l" +#line 601 "toke.l" { digest_len = SHA512_DIGEST_LENGTH; BEGIN WANTDIGEST; @@ -2919,7 +2916,7 @@ YY_RULE_SETUP YY_BREAK case 52: YY_RULE_SETUP -#line 611 "toke.l" +#line 608 "toke.l" { BEGIN GOTCMND; LEXTRACE("COMMAND "); @@ -2929,7 +2926,7 @@ YY_RULE_SETUP YY_BREAK case 53: YY_RULE_SETUP -#line 618 "toke.l" +#line 615 "toke.l" { /* directories can't have args... */ if (sudoerstext[sudoersleng - 1] == '/') { @@ -2947,7 +2944,7 @@ YY_RULE_SETUP YY_BREAK case 54: YY_RULE_SETUP -#line 633 "toke.l" +#line 630 "toke.l" { LEXTRACE("BEGINSTR "); sudoerslval.string = NULL; @@ -2957,7 +2954,7 @@ YY_RULE_SETUP YY_BREAK case 55: YY_RULE_SETUP -#line 640 "toke.l" +#line 637 "toke.l" { /* a word */ if (!fill(sudoerstext, sudoersleng)) @@ -2968,7 +2965,7 @@ YY_RULE_SETUP YY_BREAK case 56: YY_RULE_SETUP -#line 648 "toke.l" +#line 645 "toke.l" { LEXTRACE("( "); LEXRETURN('('); @@ -2976,7 +2973,7 @@ YY_RULE_SETUP YY_BREAK case 57: YY_RULE_SETUP -#line 653 "toke.l" +#line 650 "toke.l" { LEXTRACE(") "); LEXRETURN(')'); @@ -2984,7 +2981,7 @@ YY_RULE_SETUP YY_BREAK case 58: YY_RULE_SETUP -#line 658 "toke.l" +#line 655 "toke.l" { LEXTRACE(", "); LEXRETURN(','); @@ -2992,7 +2989,7 @@ YY_RULE_SETUP YY_BREAK case 59: YY_RULE_SETUP -#line 663 "toke.l" +#line 660 "toke.l" { LEXTRACE("= "); LEXRETURN('='); @@ -3000,7 +2997,7 @@ YY_RULE_SETUP YY_BREAK case 60: YY_RULE_SETUP -#line 668 "toke.l" +#line 665 "toke.l" { LEXTRACE(": "); LEXRETURN(':'); @@ -3008,7 +3005,7 @@ YY_RULE_SETUP YY_BREAK case 61: YY_RULE_SETUP -#line 673 "toke.l" +#line 670 "toke.l" { if (sudoersleng & 1) { LEXTRACE("!"); @@ -3018,7 +3015,7 @@ YY_RULE_SETUP YY_BREAK case 62: YY_RULE_SETUP -#line 680 "toke.l" +#line 677 "toke.l" { if (YY_START == INSTR) { LEXTRACE("ERROR "); @@ -3033,14 +3030,14 @@ YY_RULE_SETUP YY_BREAK case 63: YY_RULE_SETUP -#line 692 "toke.l" +#line 689 "toke.l" { /* throw away space/tabs */ sawspace = true; /* but remember for fill_args */ } YY_BREAK case 64: YY_RULE_SETUP -#line 696 "toke.l" +#line 693 "toke.l" { sawspace = true; /* remember for fill_args */ sudolineno++; @@ -3049,18 +3046,24 @@ YY_RULE_SETUP YY_BREAK case 65: YY_RULE_SETUP -#line 702 "toke.l" +#line 699 "toke.l" { - BEGIN INITIAL; - sudolineno++; - continued = false; + if (sudoerstext[sudoersleng - 1] == '\n') { + /* comment ending in a newline */ + BEGIN INITIAL; + sudolineno++; + continued = false; + } else if (!feof(yyin)) { + LEXTRACE("ERROR "); + LEXRETURN(ERROR); + } LEXTRACE("#\n"); LEXRETURN(COMMENT); } /* comment, not uid/gid */ YY_BREAK case 66: YY_RULE_SETUP -#line 710 "toke.l" +#line 713 "toke.l" { LEXTRACE("ERROR "); LEXRETURN(ERROR); @@ -3073,7 +3076,7 @@ case YY_STATE_EOF(STARTDEFS): case YY_STATE_EOF(INDEFS): case YY_STATE_EOF(INSTR): case YY_STATE_EOF(WANTDIGEST): -#line 715 "toke.l" +#line 718 "toke.l" { if (YY_START != INITIAL) { BEGIN INITIAL; @@ -3086,10 +3089,10 @@ case YY_STATE_EOF(WANTDIGEST): YY_BREAK case 67: YY_RULE_SETUP -#line 725 "toke.l" +#line 728 "toke.l" ECHO; YY_BREAK -#line 3092 "lex.sudoers.c" +#line 3095 "lex.sudoers.c" case YY_END_OF_BUFFER: { @@ -3229,7 +3232,7 @@ ECHO; * EOB_ACT_END_OF_FILE - end of file */ -static int yy_get_next_buffer() +static int yy_get_next_buffer YY_PROTO(( void )) { register char *dest = yy_current_buffer->yy_ch_buf; register char *source = yytext_ptr; @@ -3361,7 +3364,7 @@ static int yy_get_next_buffer() /* yy_get_previous_state - get the state just before the EOB char was reached */ -static yy_state_type yy_get_previous_state() +static yy_state_type yy_get_previous_state YY_PROTO(( void )) { register yy_state_type yy_current_state; register char *yy_cp; @@ -3472,9 +3475,9 @@ register char *yy_bp; #ifndef YY_NO_INPUT #ifdef __cplusplus -static int yyinput() +static int yyinput YY_PROTO(( void )) #else -static int input() +static int input YY_PROTO(( void )) #endif { int c; @@ -3850,7 +3853,7 @@ int new_state; #ifndef YY_NO_POP_STATE -static void yy_pop_state() +static void yy_pop_state YY_PROTO(( void )) { if ( --yy_start_stack_ptr < 0 ) YY_FATAL_ERROR( "start-condition stack underflow" ); @@ -3861,7 +3864,7 @@ static void yy_pop_state() #ifndef YY_NO_TOP_STATE -static int yy_top_state() +static int yy_top_state YY_PROTO(( void )) { return yy_start_stack[yy_start_stack_ptr - 1]; } @@ -3980,40 +3983,45 @@ int main() return 0; } #endif -#line 725 "toke.l" +#line 728 "toke.l" struct path_list { + SLIST_ENTRY(path_list) entries; char *path; - struct path_list *next; }; +SLIST_HEAD(path_list_head, path_list); + struct include_stack { YY_BUFFER_STATE bs; char *path; - struct path_list *more; /* more files in case of includedir */ + struct path_list_head more; /* more files in case of includedir */ int lineno; bool keepopen; }; +/* + * Compare two struct path_list structs in reverse order. + */ static int pl_compare(const void *v1, const void *v2) { const struct path_list * const *p1 = v1; const struct path_list * const *p2 = v2; - return strcmp((*p1)->path, (*p2)->path); + return strcmp((*p2)->path, (*p1)->path); } static char * switch_dir(struct include_stack *stack, char *dirpath) { DIR *dir; - int i, count = 0; + unsigned int i, count = 0; + unsigned int max_paths = 32; char *path = NULL; struct dirent *dent; struct stat sb; - struct path_list *pl, *first = NULL; - struct path_list **sorted = NULL; + struct path_list *pl, **paths = NULL; debug_decl(switch_dir, SUDO_DEBUG_PARSER) if (!(dir = opendir(dirpath))) { @@ -4023,6 +4031,11 @@ switch_dir(struct include_stack *stack, char *dirpath) } goto done; } + paths = malloc(sizeof(*paths) * max_paths); + if (paths == NULL) { + closedir(dir); + goto bad; + } while ((dent = readdir(dir))) { /* Ignore files that end in '~' or have a '.' in them. */ if (dent->d_name[0] == '\0' || dent->d_name[NAMLEN(dent) - 1] == '~' @@ -4042,54 +4055,47 @@ switch_dir(struct include_stack *stack, char *dirpath) if (pl == NULL) goto bad; pl->path = path; - pl->next = first; - first = pl; + if (count >= max_paths) { + struct path_list **tmp; + max_paths <<= 1; + tmp = realloc(paths, sizeof(*paths) * max_paths); + if (tmp == NULL) { + closedir(dir); + goto bad; + } + paths = tmp; + } + paths[count++] = pl; path = NULL; - count++; } closedir(dir); if (count == 0) goto done; - /* Sort the list as an array. */ - sorted = malloc(sizeof(*sorted) * count); - if (sorted == NULL) - goto bad; - pl = first; + /* Sort the list as an array in reverse order. */ + qsort(paths, count, sizeof(*paths), pl_compare); + + /* Build up the list in sorted order. */ for (i = 0; i < count; i++) { - sorted[i] = pl; - pl = pl->next; + SLIST_INSERT_HEAD(&stack->more, paths[i], entries); } - qsort(sorted, count, sizeof(*sorted), pl_compare); - /* Apply sorting to the list. */ - first = sorted[0]; - sorted[count - 1]->next = NULL; - for (i = 1; i < count; i++) - sorted[i - 1]->next = sorted[i]; - efree(sorted); - /* Pull out the first element for parsing, leave the rest for later. */ - if (count) { - path = first->path; - pl = first->next; - efree(first); - stack->more = pl; - } else { - path = NULL; - } + pl = SLIST_FIRST(&stack->more); + SLIST_REMOVE_HEAD(&stack->more, entries); + path = pl->path; + efree(pl); done: + efree(paths); efree(dirpath); debug_return_str(path); bad: - while (first != NULL) { - pl = first; - first = pl->next; - efree(pl->path); - efree(pl); + for (i = 0; i < count; i++) { + efree(paths[i]->path); + efree(paths[i]); } - efree(sorted); + efree(paths); efree(dirpath); efree(path); debug_return_str(NULL); @@ -4110,8 +4116,8 @@ init_lexer(void) while (idepth) { idepth--; - while ((pl = istack[idepth].more) != NULL) { - istack[idepth].more = pl->next; + while ((pl = SLIST_FIRST(&istack[idepth].more)) != NULL) { + SLIST_REMOVE_HEAD(&istack[idepth].more, entries); efree(pl->path); efree(pl); } @@ -4141,19 +4147,23 @@ _push_include(char *path, bool isdir) /* push current state onto stack */ if (idepth >= istacksize) { + struct include_stack *new_istack; + if (idepth > MAX_SUDOERS_DEPTH) { sudoerserror(N_("too many levels of includes")); debug_return_bool(false); } istacksize += SUDOERS_STACK_INCREMENT; - istack = (struct include_stack *) realloc(istack, + new_istack = (struct include_stack *) realloc(istack, sizeof(*istack) * istacksize); - if (istack == NULL) { + if (new_istack == NULL) { warning(NULL); sudoerserror(NULL); debug_return_bool(false); } + istack = new_istack; } + SLIST_INIT(&istack[idepth].more); if (isdir) { struct stat sb; switch (sudo_secure_dir(path, sudoers_uid, sudoers_gid, &sb)) { @@ -4169,19 +4179,19 @@ _push_include(char *path, bool isdir) debug_return_bool(false); case SUDO_PATH_WRONG_OWNER: if (sudoers_warnings) { - warningx(_("%s is owned by uid %u, should be %u"), + warningx(U_("%s is owned by uid %u, should be %u"), path, (unsigned int) sb.st_uid, (unsigned int) sudoers_uid); } debug_return_bool(false); case SUDO_PATH_WORLD_WRITABLE: if (sudoers_warnings) { - warningx(_("%s is world writable"), path); + warningx(U_("%s is world writable"), path); } debug_return_bool(false); case SUDO_PATH_GROUP_WRITABLE: if (sudoers_warnings) { - warningx(_("%s is owned by gid %u, should be %u"), + warningx(U_("%s is owned by gid %u, should be %u"), path, (unsigned int) sb.st_gid, (unsigned int) sudoers_gid); } @@ -4197,10 +4207,10 @@ _push_include(char *path, bool isdir) while ((fp = open_sudoers(path, false, &keepopen)) == NULL) { /* Unable to open path in includedir, go to next one, if any. */ efree(path); - if ((pl = istack[idepth].more) == NULL) + if ((pl = SLIST_FIRST(&istack[idepth].more)) == NULL) debug_return_bool(false); + SLIST_REMOVE_HEAD(&istack[idepth].more, entries); path = pl->path; - istack[idepth].more = pl->next; efree(pl); } } else { @@ -4209,7 +4219,6 @@ _push_include(char *path, bool isdir) sudoerserror(NULL); debug_return_bool(false); } - istack[idepth].more = NULL; } /* Push the old (current) file and open the new one. */ istack[idepth].path = sudoers; /* push old path */ @@ -4238,10 +4247,10 @@ pop_include(void) fclose(YY_CURRENT_BUFFER->yy_input_file); sudoers_delete_buffer(YY_CURRENT_BUFFER); /* If we are in an include dir, move to the next file. */ - while ((pl = istack[idepth - 1].more) != NULL) { + while ((pl = SLIST_FIRST(&istack[idepth - 1].more)) != NULL) { + SLIST_REMOVE_HEAD(&istack[idepth - 1].more, entries); fp = open_sudoers(pl->path, false, &keepopen); if (fp != NULL) { - istack[idepth - 1].more = pl->next; efree(sudoers); sudoers = pl->path; sudolineno = 1; @@ -4250,7 +4259,6 @@ pop_include(void) break; } /* Unable to open path in include dir, go to next one. */ - istack[idepth - 1].more = pl->next; efree(pl->path); efree(pl); }