extern YYSTYPE yylval;
extern int clearaliases;
int sudolineno = 1;
+char *sudoers;
static int sawspace = 0;
static int arg_len = 0;
static int arg_size = 0;
static int fill __P((char *, int));
static int fill_cmnd __P((char *, int));
static int fill_args __P((char *, int, int));
-static int buffer_frob __P((const char *));
+static int buffer_frob __P((char *));
extern void reset_aliases __P((void));
extern void yyerror __P((const char *));
#define INDEFS 5
-#line 1278 "lex.yy.c"
+#line 1279 "lex.yy.c"
/* Macros after this point can all be overridden by user definitions in
* section 1.
register char *yy_cp, *yy_bp;
register int yy_act;
-#line 103 "parse.lex"
+#line 104 "parse.lex"
-#line 1434 "lex.yy.c"
+#line 1435 "lex.yy.c"
if ( yy_init )
{
case 1:
YY_RULE_SETUP
-#line 104 "parse.lex"
+#line 105 "parse.lex"
BEGIN STARTDEFS;
YY_BREAK
case 2:
YY_RULE_SETUP
-#line 106 "parse.lex"
+#line 107 "parse.lex"
{
BEGIN INDEFS;
LEXTRACE("DEFVAR ");
case 3:
YY_RULE_SETUP
-#line 115 "parse.lex"
+#line 116 "parse.lex"
{
BEGIN STARTDEFS;
LEXTRACE(", ");
YY_BREAK
case 4:
YY_RULE_SETUP
-#line 121 "parse.lex"
+#line 122 "parse.lex"
{
LEXTRACE("= ");
return('=');
YY_BREAK
case 5:
YY_RULE_SETUP
-#line 126 "parse.lex"
+#line 127 "parse.lex"
{
LEXTRACE("+= ");
return('+');
YY_BREAK
case 6:
YY_RULE_SETUP
-#line 131 "parse.lex"
+#line 132 "parse.lex"
{
LEXTRACE("-= ");
return('-');
YY_BREAK
case 7:
YY_RULE_SETUP
-#line 136 "parse.lex"
+#line 137 "parse.lex"
{
LEXTRACE("WORD(1) ");
if (!fill(yytext + 1, yyleng - 2))
YY_BREAK
case 8:
YY_RULE_SETUP
-#line 143 "parse.lex"
+#line 144 "parse.lex"
{
LEXTRACE("WORD(2) ");
if (!fill(yytext, yyleng))
case 9:
YY_RULE_SETUP
-#line 152 "parse.lex"
+#line 153 "parse.lex"
{
/* quoted fnmatch glob char, pass verbatim */
LEXTRACE("QUOTEDCHAR ");
YY_BREAK
case 10:
YY_RULE_SETUP
-#line 160 "parse.lex"
+#line 161 "parse.lex"
{
/* quoted sudoers special char, strip backslash */
LEXTRACE("QUOTEDCHAR ");
YY_BREAK
case 11:
YY_RULE_SETUP
-#line 168 "parse.lex"
+#line 169 "parse.lex"
{
BEGIN INITIAL;
unput(*yytext);
YY_BREAK
case 12:
YY_RULE_SETUP
-#line 174 "parse.lex"
+#line 175 "parse.lex"
{
LEXTRACE("ARG ");
if (!fill_args(yytext, yyleng, sawspace))
case 13:
YY_RULE_SETUP
-#line 182 "parse.lex"
+#line 183 "parse.lex"
{
char *cp, *ep;
+ ++sudolineno;
/* pull out path from #include line */
for (cp = yytext + 9; isspace(*cp); cp++)
continue;
YY_BREAK
case 14:
YY_RULE_SETUP
-#line 197 "parse.lex"
+#line 199 "parse.lex"
{
BEGIN GOTDEFS;
switch (yytext[8]) {
YY_BREAK
case 15:
YY_RULE_SETUP
-#line 218 "parse.lex"
+#line 220 "parse.lex"
{
if (!fill(yytext, yyleng))
yyterminate();
YY_BREAK
case 16:
YY_RULE_SETUP
-#line 238 "parse.lex"
+#line 240 "parse.lex"
{
/* cmnd does not require passwd for this user */
LEXTRACE("NOPASSWD ");
YY_BREAK
case 17:
YY_RULE_SETUP
-#line 244 "parse.lex"
+#line 246 "parse.lex"
{
/* cmnd requires passwd for this user */
LEXTRACE("PASSWD ");
YY_BREAK
case 18:
YY_RULE_SETUP
-#line 250 "parse.lex"
+#line 252 "parse.lex"
{
LEXTRACE("NOEXEC ");
return(NOEXEC);
YY_BREAK
case 19:
YY_RULE_SETUP
-#line 255 "parse.lex"
+#line 257 "parse.lex"
{
LEXTRACE("EXEC ");
return(EXEC);
YY_BREAK
case 20:
YY_RULE_SETUP
-#line 260 "parse.lex"
+#line 262 "parse.lex"
{
LEXTRACE("NOTRACE ");
return(NOTRACE);
YY_BREAK
case 21:
YY_RULE_SETUP
-#line 265 "parse.lex"
+#line 267 "parse.lex"
{
LEXTRACE("TRACE ");
return(TRACE);
YY_BREAK
case 22:
YY_RULE_SETUP
-#line 270 "parse.lex"
+#line 272 "parse.lex"
{
/* netgroup */
if (!fill(yytext, yyleng))
YY_BREAK
case 23:
YY_RULE_SETUP
-#line 278 "parse.lex"
+#line 280 "parse.lex"
{
/* UN*X group */
if (!fill(yytext, yyleng))
YY_BREAK
case 24:
YY_RULE_SETUP
-#line 286 "parse.lex"
+#line 288 "parse.lex"
{
if (!fill(yytext, yyleng))
yyterminate();
YY_BREAK
case 25:
YY_RULE_SETUP
-#line 293 "parse.lex"
+#line 295 "parse.lex"
{
if (!fill(yytext, yyleng))
yyterminate();
YY_BREAK
case 26:
YY_RULE_SETUP
-#line 300 "parse.lex"
+#line 302 "parse.lex"
{
BEGIN GOTRUNAS;
LEXTRACE("RUNAS ");
YY_BREAK
case 27:
YY_RULE_SETUP
-#line 306 "parse.lex"
+#line 308 "parse.lex"
{
if (strcmp(yytext, "ALL") == 0) {
LEXTRACE("ALL ");
YY_BREAK
case 28:
YY_RULE_SETUP
-#line 318 "parse.lex"
+#line 320 "parse.lex"
{
/* username/uid that user can run command as */
if (!fill(yytext, yyleng))
YY_BREAK
case 29:
YY_RULE_SETUP
-#line 326 "parse.lex"
+#line 328 "parse.lex"
{
BEGIN INITIAL;
}
YY_BREAK
case 30:
YY_RULE_SETUP
-#line 330 "parse.lex"
+#line 332 "parse.lex"
{
BEGIN GOTCMND;
LEXTRACE("COMMAND ");
YY_BREAK
case 31:
YY_RULE_SETUP
-#line 337 "parse.lex"
+#line 339 "parse.lex"
{
/* directories can't have args... */
if (yytext[yyleng - 1] == '/') {
YY_BREAK
case 32:
YY_RULE_SETUP
-#line 352 "parse.lex"
+#line 354 "parse.lex"
{
/* a word */
if (!fill(yytext, yyleng))
YY_BREAK
case 33:
YY_RULE_SETUP
-#line 360 "parse.lex"
+#line 362 "parse.lex"
{
LEXTRACE(", ");
return(',');
YY_BREAK
case 34:
YY_RULE_SETUP
-#line 365 "parse.lex"
+#line 367 "parse.lex"
{
LEXTRACE("= ");
return('=');
YY_BREAK
case 35:
YY_RULE_SETUP
-#line 370 "parse.lex"
+#line 372 "parse.lex"
{
LEXTRACE(": ");
return(':');
YY_BREAK
case 36:
YY_RULE_SETUP
-#line 375 "parse.lex"
+#line 377 "parse.lex"
{
if (yyleng % 2 == 1)
return('!'); /* return '!' */
YY_BREAK
case 37:
YY_RULE_SETUP
-#line 380 "parse.lex"
+#line 382 "parse.lex"
{
BEGIN INITIAL;
++sudolineno;
YY_BREAK
case 38:
YY_RULE_SETUP
-#line 387 "parse.lex"
+#line 389 "parse.lex"
{ /* throw away space/tabs */
sawspace = TRUE; /* but remember for fill_args */
}
YY_BREAK
case 39:
YY_RULE_SETUP
-#line 391 "parse.lex"
+#line 393 "parse.lex"
{
sawspace = TRUE; /* remember for fill_args */
++sudolineno;
YY_BREAK
case 40:
YY_RULE_SETUP
-#line 397 "parse.lex"
+#line 399 "parse.lex"
{
BEGIN INITIAL;
++sudolineno;
YY_BREAK
case 41:
YY_RULE_SETUP
-#line 404 "parse.lex"
+#line 406 "parse.lex"
{
LEXTRACE("ERROR ");
return(ERROR);
case YY_STATE_EOF(GOTCMND):
case YY_STATE_EOF(STARTDEFS):
case YY_STATE_EOF(INDEFS):
-#line 409 "parse.lex"
+#line 411 "parse.lex"
{
if (YY_START != INITIAL) {
BEGIN INITIAL;
YY_BREAK
case 42:
YY_RULE_SETUP
-#line 419 "parse.lex"
+#line 421 "parse.lex"
ECHO;
YY_BREAK
-#line 1968 "lex.yy.c"
+#line 1970 "lex.yy.c"
case YY_END_OF_BUFFER:
{
return 0;
}
#endif
-#line 419 "parse.lex"
+#line 421 "parse.lex"
static int
fill(s, len)
return(TRUE);
}
-#define MAX_INCLUDE_DEPTH 128
-int
+struct sudoers_state {
+ YY_BUFFER_STATE bs;
+ char *path;
+ int lineno;
+};
+
+#define MAX_SUDOERS_DEPTH 128
+
+static int
buffer_frob(path)
- const char *path;
+ char *path;
{
static size_t stacksize, depth;
- static YY_BUFFER_STATE *bufstack;
+ static struct sudoers_state *state;
FILE *fp;
if (path != NULL) {
- /* push */
+ /* push current state */
+ if ((path = strdup(path)) == NULL) {
+ yyerror("unable to allocate memory");
+ return(FALSE);
+ }
if (depth >= stacksize) {
- if (depth > MAX_INCLUDE_DEPTH) {
+ if (depth > MAX_SUDOERS_DEPTH) {
yyerror("too many levels of includes");
return(FALSE);
}
stacksize += 16;
- if ((bufstack = realloc(bufstack, stacksize)) == NULL) {
+ if ((state = realloc(state, sizeof(state) * stacksize)) == NULL) {
yyerror("unable to allocate memory");
return(FALSE);
}
yyerror(path);
return(FALSE);
}
- bufstack[depth++] = YY_CURRENT_BUFFER;
+ state[depth].bs = YY_CURRENT_BUFFER;
+ state[depth].path = sudoers;
+ state[depth].lineno = sudolineno;
+ depth++;
+ sudolineno = 1;
+ sudoers = path;
yy_switch_to_buffer(yy_create_buffer(fp, YY_BUF_SIZE));
} else {
/* pop */
if (depth == 0)
return(FALSE);
+ depth--;
fclose(YY_CURRENT_BUFFER->yy_input_file);
yy_delete_buffer(YY_CURRENT_BUFFER);
- yy_switch_to_buffer(bufstack[--depth]);
+ yy_switch_to_buffer(state[depth].bs);
+ free(sudoers);
+ sudoers = state[depth].path;
+ sudolineno = state[depth].lineno;
}
return(TRUE);
}
* Globals
*/
extern int sudolineno, parse_error;
+extern char *sudoers;
int errorlineno = -1;
int clearaliases = TRUE;
int printmatches = FALSE;
static void expand_match_list __P((void));
static aliasinfo *find_alias __P((char *, int));
static int more_aliases __P((void));
- void init_parser __P((void));
void yyerror __P((const char *));
void
errorlineno = sudolineno ? sudolineno - 1 : 0;
if (s && !quiet) {
#ifndef TRACELEXER
- (void) fprintf(stderr, ">>> sudoers file: %s, line %d <<<\n", s,
+ (void) fprintf(stderr, ">>> %s: %s, line %d <<<\n", sudoers, s,
sudolineno ? sudolineno - 1 : 0);
#else
(void) fprintf(stderr, "<*> ");
* for various data structures.
*/
void
-init_parser()
+init_parser(char *path)
{
/* Free up old data structures if we run the parser more than once. */
used_runas = FALSE;
errorlineno = -1;
sudolineno = 1;
+ free(sudoers);
}
/* Allocate space for the matching stack. */
/* Allocate space for the match list (for `sudo -l'). */
if (printmatches == TRUE)
expand_match_list();
+
+ sudoers = estrdup(path);
}
-#line 989 "sudo.tab.c"
+#line 992 "sudo.tab.c"
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
#if defined(__cplusplus) || defined(__STDC__)
static int yygrowstack(void)
yyval.BOOLEAN = TRUE;
}
break;
-#line 1948 "sudo.tab.c"
+#line 1951 "sudo.tab.c"
}
yyssp -= yym;
yystate = *yyssp;