X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=toke.l;h=ce1fd4c177370c868c3980338931ac8274337ac6;hb=0b416d12e899a02a7cdec722c946400abbe9ad67;hp=9b93563558f3f4e7260a59268e0584b363aa6c00;hpb=967e372b4817accfd07afe09c8934052beed1a2c;p=debian%2Fsudo diff --git a/toke.l b/toke.l index 9b93563..ce1fd4c 100644 --- a/toke.l +++ b/toke.l @@ -1,6 +1,6 @@ %{ /* - * Copyright (c) 1996, 1998-2005, 2007-2009 + * Copyright (c) 1996, 1998-2005, 2007-2010 * Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any @@ -39,11 +39,10 @@ #endif /* STDC_HEADERS */ #ifdef HAVE_STRING_H # include -#else -# ifdef HAVE_STRINGS_H -# include -# endif #endif /* HAVE_STRING_H */ +#ifdef HAVE_STRINGS_H +# include +#endif /* HAVE_STRINGS_H */ #ifdef HAVE_UNISTD_H # include #endif /* HAVE_UNISTD_H */ @@ -71,11 +70,8 @@ #include "parse.h" #include -#ifndef lint -__unused static const char rcsid[] = "$Sudo: toke.l,v 1.37 2009/05/27 00:46:51 millert Exp $"; -#endif /* lint */ - extern YYSTYPE yylval; +extern int parse_error; int sudolineno = 1; char *sudoers; static int sawspace = 0; @@ -224,7 +220,7 @@ DEFVAR [a-z_]+ return(COMMAND); } /* end of command line args */ - [^\\:, \t\n]+ { + [^#\\:, \t\n]+ { LEXTRACE("ARG "); if (!fill_args(yytext, yyleng, sawspace)) yyterminate(); @@ -253,12 +249,15 @@ DEFVAR [a-z_]+ LEXTRACE("INCLUDEDIR\n"); - /* Push current buffer and switch to include file */ - if (!push_includedir(path)) + /* + * Push current buffer and switch to include file. + * We simply ignore empty directories. + */ + if (!push_includedir(path) && parse_error) yyterminate(); } -^[[:blank:]]*Defaults([:@>\!]{WORD})? { +^[[:blank:]]*Defaults([:@>\!]\!?{WORD})? { int n; for (n = 0; isblank((unsigned char)yytext[n]); n++) continue; @@ -748,7 +747,7 @@ switch_dir(stack, dirpath) if (!(dir = opendir(dirpath))) { yyerror(dirpath); - return(FALSE); + return(NULL); } while ((dent = readdir(dir))) { /* Ignore files that end in '~' or have a '.' in them. */ @@ -840,7 +839,7 @@ init_lexer() efree(pl); } efree(istack[idepth].path); - if (!istack[idepth].keepopen) + if (idepth && !istack[idepth].keepopen) fclose(istack[idepth].bs->yy_input_file); yy_delete_buffer(istack[idepth].bs); } @@ -855,6 +854,7 @@ _push_include(path, isdir) char *path; int isdir; { + struct path_list *pl; FILE *fp; /* push current state onto stack */ @@ -865,7 +865,7 @@ _push_include(path, isdir) } istacksize += SUDOERS_STACK_INCREMENT; istack = (struct include_stack *) realloc(istack, - sizeof(istack) * istacksize); + sizeof(*istack) * istacksize); if (istack == NULL) { yyerror("unable to allocate memory"); return(FALSE); @@ -873,12 +873,17 @@ _push_include(path, isdir) } if (isdir) { if (!(path = switch_dir(&istack[idepth], path))) { - yyerror(path); + /* switch_dir() called yyerror() for us */ return(FALSE); } - if ((fp = open_sudoers(path, FALSE, &keepopen)) == NULL) { - yyerror(path); - return(FALSE); /* XXX - just to go next one? */ + 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) + return(FALSE); + path = pl->path; + istack[idepth].more = pl->next; + efree(pl); } } else { if ((fp = open_sudoers(path, TRUE, &keepopen)) == NULL) { @@ -912,25 +917,31 @@ pop_include() if (!keepopen) fclose(YY_CURRENT_BUFFER->yy_input_file); yy_delete_buffer(YY_CURRENT_BUFFER); - keepopen = FALSE; - if ((pl = istack[idepth - 1].more) != NULL) { - /* Move to next file in the dir. */ - istack[idepth - 1].more = pl->next; - if ((fp = open_sudoers(pl->path, FALSE, &keepopen)) == NULL) { - yyerror(pl->path); - return(FALSE); /* XXX - just to go next one? */ + /* If we are in an include dir, move to the next file. */ + while ((pl = istack[idepth - 1].more) != NULL) { + fp = open_sudoers(pl->path, FALSE, &keepopen); + if (fp != NULL) { + istack[idepth - 1].more = pl->next; + efree(sudoers); + sudoers = pl->path; + sudolineno = 1; + yy_switch_to_buffer(yy_create_buffer(fp, YY_BUF_SIZE)); + efree(pl); + break; } - efree(sudoers); - sudoers = pl->path; - sudolineno = 1; - yy_switch_to_buffer(yy_create_buffer(fp, YY_BUF_SIZE)); + /* Unable to open path in include dir, go to next one. */ + istack[idepth - 1].more = pl->next; + efree(pl->path); efree(pl); - } else { + } + /* If no path list, just pop the last dir on the stack. */ + if (pl == NULL) { idepth--; yy_switch_to_buffer(istack[idepth].bs); efree(sudoers); sudoers = istack[idepth].path; sudolineno = istack[idepth].lineno; + keepopen = istack[idepth].keepopen; } return(TRUE); } @@ -971,6 +982,7 @@ parse_include(base) memcpy(pp, user_shost, shost_len); pp += shost_len; cp += 2; + continue; } *pp++ = *cp++; }