2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-22 09:57:41 +00:00

Restore ability to define TRACELEXER and have trace output go to stderr.

This commit is contained in:
Todd C. Miller 2011-03-21 17:57:38 -04:00
parent a2297743aa
commit 06bf685b33
2 changed files with 91 additions and 63 deletions

View File

@ -1474,7 +1474,6 @@ extern YYSTYPE yylval;
extern int parse_error; extern int parse_error;
int sudolineno = 1; int sudolineno = 1;
char *sudoers; char *sudoers;
int (*trace_print)(const char *msg);
static int sawspace = FALSE; static int sawspace = FALSE;
static int continued = FALSE; static int continued = FALSE;
@ -1484,6 +1483,13 @@ static int _push_include(char *, int);
static int pop_include(void); static int pop_include(void);
static char *parse_include(char *); static char *parse_include(char *);
#ifdef TRACELEXER
static int sudoers_trace_print(const char *msg);
#else
# define sudoers_trace_print NULL
#endif
int (*trace_print)(const char *msg) = sudoers_trace_print;
#define push_include(_p) (_push_include((_p), FALSE)) #define push_include(_p) (_push_include((_p), FALSE))
#define push_includedir(_p) (_push_include((_p), TRUE)) #define push_includedir(_p) (_push_include((_p), TRUE))
#define YY_NO_INPUT 1 #define YY_NO_INPUT 1
@ -1498,7 +1504,7 @@ static char *parse_include(char *);
#define INSTR 5 #define INSTR 5
#line 1501 "lex.yy.c" #line 1507 "lex.yy.c"
/* Macros after this point can all be overridden by user definitions in /* Macros after this point can all be overridden by user definitions in
* section 1. * section 1.
@ -1652,9 +1658,9 @@ YY_DECL
register char *yy_cp, *yy_bp; register char *yy_cp, *yy_bp;
register int yy_act; register int yy_act;
#line 114 "toke.l" #line 120 "toke.l"
#line 1657 "lex.yy.c" #line 1663 "lex.yy.c"
if ( yy_init ) if ( yy_init )
{ {
@ -1740,7 +1746,7 @@ do_action: /* This label is used only to access EOF actions. */
case 1: case 1:
YY_RULE_SETUP YY_RULE_SETUP
#line 115 "toke.l" #line 121 "toke.l"
{ {
LEXTRACE(", "); LEXTRACE(", ");
return ','; return ',';
@ -1748,12 +1754,12 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 2: case 2:
YY_RULE_SETUP YY_RULE_SETUP
#line 120 "toke.l" #line 126 "toke.l"
BEGIN STARTDEFS; BEGIN STARTDEFS;
YY_BREAK YY_BREAK
case 3: case 3:
YY_RULE_SETUP YY_RULE_SETUP
#line 122 "toke.l" #line 128 "toke.l"
{ {
BEGIN INDEFS; BEGIN INDEFS;
LEXTRACE("DEFVAR "); LEXTRACE("DEFVAR ");
@ -1765,7 +1771,7 @@ YY_RULE_SETUP
case 4: case 4:
YY_RULE_SETUP YY_RULE_SETUP
#line 131 "toke.l" #line 137 "toke.l"
{ {
BEGIN STARTDEFS; BEGIN STARTDEFS;
LEXTRACE(", "); LEXTRACE(", ");
@ -1774,7 +1780,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 5: case 5:
YY_RULE_SETUP YY_RULE_SETUP
#line 137 "toke.l" #line 143 "toke.l"
{ {
LEXTRACE("= "); LEXTRACE("= ");
return '='; return '=';
@ -1782,7 +1788,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 6: case 6:
YY_RULE_SETUP YY_RULE_SETUP
#line 142 "toke.l" #line 148 "toke.l"
{ {
LEXTRACE("+= "); LEXTRACE("+= ");
return '+'; return '+';
@ -1790,7 +1796,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 7: case 7:
YY_RULE_SETUP YY_RULE_SETUP
#line 147 "toke.l" #line 153 "toke.l"
{ {
LEXTRACE("-= "); LEXTRACE("-= ");
return '-'; return '-';
@ -1798,7 +1804,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 8: case 8:
YY_RULE_SETUP YY_RULE_SETUP
#line 152 "toke.l" #line 158 "toke.l"
{ {
LEXTRACE("BEGINSTR "); LEXTRACE("BEGINSTR ");
yylval.string = NULL; yylval.string = NULL;
@ -1808,7 +1814,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 9: case 9:
YY_RULE_SETUP YY_RULE_SETUP
#line 159 "toke.l" #line 165 "toke.l"
{ {
LEXTRACE("WORD(2) "); LEXTRACE("WORD(2) ");
if (!fill(yytext, yyleng)) if (!fill(yytext, yyleng))
@ -1820,7 +1826,7 @@ YY_RULE_SETUP
case 10: case 10:
YY_RULE_SETUP YY_RULE_SETUP
#line 168 "toke.l" #line 174 "toke.l"
{ {
/* Line continuation char followed by newline. */ /* Line continuation char followed by newline. */
++sudolineno; ++sudolineno;
@ -1829,7 +1835,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 11: case 11:
YY_RULE_SETUP YY_RULE_SETUP
#line 174 "toke.l" #line 180 "toke.l"
{ {
LEXTRACE("ENDSTR "); LEXTRACE("ENDSTR ");
BEGIN prev_state; BEGIN prev_state;
@ -1849,7 +1855,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 12: case 12:
YY_RULE_SETUP YY_RULE_SETUP
#line 191 "toke.l" #line 197 "toke.l"
{ {
LEXTRACE("BACKSLASH "); LEXTRACE("BACKSLASH ");
if (!append(yytext, yyleng)) if (!append(yytext, yyleng))
@ -1858,7 +1864,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 13: case 13:
YY_RULE_SETUP YY_RULE_SETUP
#line 197 "toke.l" #line 203 "toke.l"
{ {
LEXTRACE("STRBODY "); LEXTRACE("STRBODY ");
if (!append(yytext, yyleng)) if (!append(yytext, yyleng))
@ -1869,7 +1875,7 @@ YY_RULE_SETUP
case 14: case 14:
YY_RULE_SETUP YY_RULE_SETUP
#line 205 "toke.l" #line 211 "toke.l"
{ {
/* quoted fnmatch glob char, pass verbatim */ /* quoted fnmatch glob char, pass verbatim */
LEXTRACE("QUOTEDCHAR "); LEXTRACE("QUOTEDCHAR ");
@ -1880,7 +1886,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 15: case 15:
YY_RULE_SETUP YY_RULE_SETUP
#line 213 "toke.l" #line 219 "toke.l"
{ {
/* quoted sudoers special char, strip backslash */ /* quoted sudoers special char, strip backslash */
LEXTRACE("QUOTEDCHAR "); LEXTRACE("QUOTEDCHAR ");
@ -1891,7 +1897,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 16: case 16:
YY_RULE_SETUP YY_RULE_SETUP
#line 221 "toke.l" #line 227 "toke.l"
{ {
BEGIN INITIAL; BEGIN INITIAL;
yyless(0); yyless(0);
@ -1900,7 +1906,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 17: case 17:
YY_RULE_SETUP YY_RULE_SETUP
#line 227 "toke.l" #line 233 "toke.l"
{ {
LEXTRACE("ARG "); LEXTRACE("ARG ");
if (!fill_args(yytext, yyleng, sawspace)) if (!fill_args(yytext, yyleng, sawspace))
@ -1911,7 +1917,7 @@ YY_RULE_SETUP
case 18: case 18:
YY_RULE_SETUP YY_RULE_SETUP
#line 235 "toke.l" #line 241 "toke.l"
{ {
char *path; char *path;
@ -1932,7 +1938,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 19: case 19:
YY_RULE_SETUP YY_RULE_SETUP
#line 253 "toke.l" #line 259 "toke.l"
{ {
char *path; char *path;
@ -1956,7 +1962,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 20: case 20:
YY_RULE_SETUP YY_RULE_SETUP
#line 274 "toke.l" #line 280 "toke.l"
{ {
char deftype; char deftype;
int n; int n;
@ -1999,7 +2005,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 21: case 21:
YY_RULE_SETUP YY_RULE_SETUP
#line 314 "toke.l" #line 320 "toke.l"
{ {
int n; int n;
@ -2028,7 +2034,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 22: case 22:
YY_RULE_SETUP YY_RULE_SETUP
#line 340 "toke.l" #line 346 "toke.l"
{ {
/* cmnd does not require passwd for this user */ /* cmnd does not require passwd for this user */
LEXTRACE("NOPASSWD "); LEXTRACE("NOPASSWD ");
@ -2037,7 +2043,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 23: case 23:
YY_RULE_SETUP YY_RULE_SETUP
#line 346 "toke.l" #line 352 "toke.l"
{ {
/* cmnd requires passwd for this user */ /* cmnd requires passwd for this user */
LEXTRACE("PASSWD "); LEXTRACE("PASSWD ");
@ -2046,7 +2052,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 24: case 24:
YY_RULE_SETUP YY_RULE_SETUP
#line 352 "toke.l" #line 358 "toke.l"
{ {
LEXTRACE("NOEXEC "); LEXTRACE("NOEXEC ");
return NOEXEC; return NOEXEC;
@ -2054,7 +2060,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 25: case 25:
YY_RULE_SETUP YY_RULE_SETUP
#line 357 "toke.l" #line 363 "toke.l"
{ {
LEXTRACE("EXEC "); LEXTRACE("EXEC ");
return EXEC; return EXEC;
@ -2062,7 +2068,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 26: case 26:
YY_RULE_SETUP YY_RULE_SETUP
#line 362 "toke.l" #line 368 "toke.l"
{ {
LEXTRACE("SETENV "); LEXTRACE("SETENV ");
return SETENV; return SETENV;
@ -2070,7 +2076,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 27: case 27:
YY_RULE_SETUP YY_RULE_SETUP
#line 367 "toke.l" #line 373 "toke.l"
{ {
LEXTRACE("NOSETENV "); LEXTRACE("NOSETENV ");
return NOSETENV; return NOSETENV;
@ -2078,7 +2084,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 28: case 28:
YY_RULE_SETUP YY_RULE_SETUP
#line 372 "toke.l" #line 378 "toke.l"
{ {
LEXTRACE("LOG_OUTPUT "); LEXTRACE("LOG_OUTPUT ");
return LOG_OUTPUT; return LOG_OUTPUT;
@ -2086,7 +2092,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 29: case 29:
YY_RULE_SETUP YY_RULE_SETUP
#line 377 "toke.l" #line 383 "toke.l"
{ {
LEXTRACE("NOLOG_OUTPUT "); LEXTRACE("NOLOG_OUTPUT ");
return NOLOG_OUTPUT; return NOLOG_OUTPUT;
@ -2094,7 +2100,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 30: case 30:
YY_RULE_SETUP YY_RULE_SETUP
#line 382 "toke.l" #line 388 "toke.l"
{ {
LEXTRACE("LOG_INPUT "); LEXTRACE("LOG_INPUT ");
return LOG_INPUT; return LOG_INPUT;
@ -2102,7 +2108,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 31: case 31:
YY_RULE_SETUP YY_RULE_SETUP
#line 387 "toke.l" #line 393 "toke.l"
{ {
LEXTRACE("NOLOG_INPUT "); LEXTRACE("NOLOG_INPUT ");
return NOLOG_INPUT; return NOLOG_INPUT;
@ -2110,7 +2116,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 32: case 32:
YY_RULE_SETUP YY_RULE_SETUP
#line 392 "toke.l" #line 398 "toke.l"
{ {
/* netgroup */ /* netgroup */
if (!fill(yytext, yyleng)) if (!fill(yytext, yyleng))
@ -2121,7 +2127,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 33: case 33:
YY_RULE_SETUP YY_RULE_SETUP
#line 400 "toke.l" #line 406 "toke.l"
{ {
/* UN*X group */ /* UN*X group */
if (!fill(yytext, yyleng)) if (!fill(yytext, yyleng))
@ -2132,7 +2138,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 34: case 34:
YY_RULE_SETUP YY_RULE_SETUP
#line 408 "toke.l" #line 414 "toke.l"
{ {
if (!fill(yytext, yyleng)) if (!fill(yytext, yyleng))
yyterminate(); yyterminate();
@ -2142,7 +2148,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 35: case 35:
YY_RULE_SETUP YY_RULE_SETUP
#line 415 "toke.l" #line 421 "toke.l"
{ {
if (!fill(yytext, yyleng)) if (!fill(yytext, yyleng))
yyterminate(); yyterminate();
@ -2152,7 +2158,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 36: case 36:
YY_RULE_SETUP YY_RULE_SETUP
#line 422 "toke.l" #line 428 "toke.l"
{ {
if (!ipv6_valid(yytext)) { if (!ipv6_valid(yytext)) {
LEXTRACE("ERROR "); LEXTRACE("ERROR ");
@ -2166,7 +2172,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 37: case 37:
YY_RULE_SETUP YY_RULE_SETUP
#line 433 "toke.l" #line 439 "toke.l"
{ {
if (!ipv6_valid(yytext)) { if (!ipv6_valid(yytext)) {
LEXTRACE("ERROR "); LEXTRACE("ERROR ");
@ -2180,7 +2186,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 38: case 38:
YY_RULE_SETUP YY_RULE_SETUP
#line 444 "toke.l" #line 450 "toke.l"
{ {
if (strcmp(yytext, "ALL") == 0) { if (strcmp(yytext, "ALL") == 0) {
LEXTRACE("ALL "); LEXTRACE("ALL ");
@ -2205,7 +2211,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 39: case 39:
YY_RULE_SETUP YY_RULE_SETUP
#line 466 "toke.l" #line 472 "toke.l"
{ {
/* no command args allowed for Defaults!/path */ /* no command args allowed for Defaults!/path */
if (!fill_cmnd(yytext, yyleng)) if (!fill_cmnd(yytext, yyleng))
@ -2216,7 +2222,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 40: case 40:
YY_RULE_SETUP YY_RULE_SETUP
#line 474 "toke.l" #line 480 "toke.l"
{ {
BEGIN GOTCMND; BEGIN GOTCMND;
LEXTRACE("COMMAND "); LEXTRACE("COMMAND ");
@ -2226,7 +2232,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 41: case 41:
YY_RULE_SETUP YY_RULE_SETUP
#line 481 "toke.l" #line 487 "toke.l"
{ {
/* directories can't have args... */ /* directories can't have args... */
if (yytext[yyleng - 1] == '/') { if (yytext[yyleng - 1] == '/') {
@ -2244,7 +2250,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 42: case 42:
YY_RULE_SETUP YY_RULE_SETUP
#line 496 "toke.l" #line 502 "toke.l"
{ {
LEXTRACE("BEGINSTR "); LEXTRACE("BEGINSTR ");
yylval.string = NULL; yylval.string = NULL;
@ -2254,7 +2260,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 43: case 43:
YY_RULE_SETUP YY_RULE_SETUP
#line 503 "toke.l" #line 509 "toke.l"
{ {
/* a word */ /* a word */
if (!fill(yytext, yyleng)) if (!fill(yytext, yyleng))
@ -2265,7 +2271,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 44: case 44:
YY_RULE_SETUP YY_RULE_SETUP
#line 511 "toke.l" #line 517 "toke.l"
{ {
LEXTRACE("( "); LEXTRACE("( ");
return '('; return '(';
@ -2273,7 +2279,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 45: case 45:
YY_RULE_SETUP YY_RULE_SETUP
#line 516 "toke.l" #line 522 "toke.l"
{ {
LEXTRACE(") "); LEXTRACE(") ");
return ')'; return ')';
@ -2281,7 +2287,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 46: case 46:
YY_RULE_SETUP YY_RULE_SETUP
#line 521 "toke.l" #line 527 "toke.l"
{ {
LEXTRACE(", "); LEXTRACE(", ");
return ','; return ',';
@ -2289,7 +2295,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 47: case 47:
YY_RULE_SETUP YY_RULE_SETUP
#line 526 "toke.l" #line 532 "toke.l"
{ {
LEXTRACE("= "); LEXTRACE("= ");
return '='; return '=';
@ -2297,7 +2303,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 48: case 48:
YY_RULE_SETUP YY_RULE_SETUP
#line 531 "toke.l" #line 537 "toke.l"
{ {
LEXTRACE(": "); LEXTRACE(": ");
return ':'; return ':';
@ -2305,7 +2311,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 49: case 49:
YY_RULE_SETUP YY_RULE_SETUP
#line 536 "toke.l" #line 542 "toke.l"
{ {
if (yyleng % 2 == 1) if (yyleng % 2 == 1)
return '!'; /* return '!' */ return '!'; /* return '!' */
@ -2313,7 +2319,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 50: case 50:
YY_RULE_SETUP YY_RULE_SETUP
#line 541 "toke.l" #line 547 "toke.l"
{ {
BEGIN INITIAL; BEGIN INITIAL;
++sudolineno; ++sudolineno;
@ -2324,14 +2330,14 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 51: case 51:
YY_RULE_SETUP YY_RULE_SETUP
#line 549 "toke.l" #line 555 "toke.l"
{ /* throw away space/tabs */ { /* throw away space/tabs */
sawspace = TRUE; /* but remember for fill_args */ sawspace = TRUE; /* but remember for fill_args */
} }
YY_BREAK YY_BREAK
case 52: case 52:
YY_RULE_SETUP YY_RULE_SETUP
#line 553 "toke.l" #line 559 "toke.l"
{ {
sawspace = TRUE; /* remember for fill_args */ sawspace = TRUE; /* remember for fill_args */
++sudolineno; ++sudolineno;
@ -2340,7 +2346,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 53: case 53:
YY_RULE_SETUP YY_RULE_SETUP
#line 559 "toke.l" #line 565 "toke.l"
{ {
BEGIN INITIAL; BEGIN INITIAL;
++sudolineno; ++sudolineno;
@ -2351,7 +2357,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 54: case 54:
YY_RULE_SETUP YY_RULE_SETUP
#line 567 "toke.l" #line 573 "toke.l"
{ {
LEXTRACE("ERROR "); LEXTRACE("ERROR ");
return ERROR; return ERROR;
@ -2363,7 +2369,7 @@ case YY_STATE_EOF(GOTCMND):
case YY_STATE_EOF(STARTDEFS): case YY_STATE_EOF(STARTDEFS):
case YY_STATE_EOF(INDEFS): case YY_STATE_EOF(INDEFS):
case YY_STATE_EOF(INSTR): case YY_STATE_EOF(INSTR):
#line 572 "toke.l" #line 578 "toke.l"
{ {
if (YY_START != INITIAL) { if (YY_START != INITIAL) {
BEGIN INITIAL; BEGIN INITIAL;
@ -2376,10 +2382,10 @@ case YY_STATE_EOF(INSTR):
YY_BREAK YY_BREAK
case 55: case 55:
YY_RULE_SETUP YY_RULE_SETUP
#line 582 "toke.l" #line 588 "toke.l"
ECHO; ECHO;
YY_BREAK YY_BREAK
#line 2382 "lex.yy.c" #line 2388 "lex.yy.c"
case YY_END_OF_BUFFER: case YY_END_OF_BUFFER:
{ {
@ -3270,7 +3276,7 @@ int main()
return 0; return 0;
} }
#endif #endif
#line 582 "toke.l" #line 588 "toke.l"
struct path_list { struct path_list {
char *path; char *path;
@ -3555,3 +3561,11 @@ parse_include(char *base)
return path; return path;
} }
#ifdef TRACELEXER
static int
sudoers_trace_print(const char *msg)
{
return fputs(msg, stderr);
}
#endif /* TRACELEXER */

View File

@ -75,7 +75,6 @@ extern YYSTYPE yylval;
extern int parse_error; extern int parse_error;
int sudolineno = 1; int sudolineno = 1;
char *sudoers; char *sudoers;
int (*trace_print)(const char *msg);
static int sawspace = FALSE; static int sawspace = FALSE;
static int continued = FALSE; static int continued = FALSE;
@ -85,6 +84,13 @@ static int _push_include(char *, int);
static int pop_include(void); static int pop_include(void);
static char *parse_include(char *); static char *parse_include(char *);
#ifdef TRACELEXER
static int sudoers_trace_print(const char *msg);
#else
# define sudoers_trace_print NULL
#endif
int (*trace_print)(const char *msg) = sudoers_trace_print;
#define push_include(_p) (_push_include((_p), FALSE)) #define push_include(_p) (_push_include((_p), FALSE))
#define push_includedir(_p) (_push_include((_p), TRUE)) #define push_includedir(_p) (_push_include((_p), TRUE))
%} %}
@ -863,3 +869,11 @@ parse_include(char *base)
return path; return path;
} }
#ifdef TRACELEXER
static int
sudoers_trace_print(const char *msg)
{
return fputs(msg, stderr);
}
#endif /* TRACELEXER */