Set yacc prefix to "sudoers" to avoid conflicts other yacc parsers.

This commit is contained in:
Todd C. Miller
2012-09-14 16:19:25 -04:00
parent 0c9083b141
commit 5276ab3a5f
12 changed files with 291 additions and 247 deletions

View File

@@ -218,7 +218,7 @@ $(devdir)/gram.c $(devdir)/gram.h: $(srcdir)/gram.y
else \
gram_y="$(srcdir)/gram.y"; \
fi; \
cmd='$(YACC) -d '"$$gram_y"'; echo "#include <config.h>" > $(devdir)/gram.c; sed "s/^\\(#line .*\\) \"y\\.tab\\.c\"/\1 \"gram.c\"/" y.tab.c >> $(devdir)/gram.c; rm -f y.tab.c; mv -f y.tab.h $(devdir)/gram.h'; \
cmd='$(YACC) -d -p sudoers '"$$gram_y"'; echo "#include <config.h>" > $(devdir)/gram.c; sed "s/^\\(#line .*\\) \"y\\.tab\\.c\"/\1 \"gram.c\"/" y.tab.c >> $(devdir)/gram.c; rm -f y.tab.c; mv -f y.tab.h $(devdir)/gram.h'; \
echo "$$cmd"; eval $$cmd; \
fi
@@ -229,7 +229,7 @@ $(devdir)/toke.c: $(srcdir)/toke.l
else \
toke_l="$(srcdir)/toke.l"; \
fi; \
cmd='$(FLEX) '"$$toke_l"'; echo "#include <config.h>" > $(devdir)/toke.c; cat lex.yy.c >> $(devdir)/toke.c; rm -f lex.yy.c'; \
cmd='$(FLEX) '"$$toke_l"'; echo "#include <config.h>" > $(devdir)/toke.c; cat lex.sudoers.c >> $(devdir)/toke.c; rm -f lex.sudoers.c'; \
echo "$$cmd"; eval $$cmd; \
fi

View File

@@ -9,7 +9,33 @@
#define yyclearin (yychar=(YYEMPTY))
#define yyerrok (yyerrflag=0)
#define YYRECOVERING() (yyerrflag!=0)
#define YYPREFIX "yy"
#define yyparse sudoersparse
#define yylex sudoerslex
#define yyerror sudoerserror
#define yychar sudoerschar
#define yyval sudoersval
#define yylval sudoerslval
#define yydebug sudoersdebug
#define yynerrs sudoersnerrs
#define yyerrflag sudoerserrflag
#define yyss sudoersss
#define yysslim sudoerssslim
#define yyssp sudoersssp
#define yyvs sudoersvs
#define yyvsp sudoersvsp
#define yystacksize sudoersstacksize
#define yylhs sudoerslhs
#define yylen sudoerslen
#define yydefred sudoersdefred
#define yydgoto sudoersdgoto
#define yysindex sudoerssindex
#define yyrindex sudoersrindex
#define yygindex sudoersgindex
#define yytable sudoerstable
#define yycheck sudoerscheck
#define yyname sudoersname
#define yyrule sudoersrule
#define YYPREFIX "sudoers"
#line 2 "gram.y"
/*
* Copyright (c) 1996, 1998-2005, 2007-2012
@@ -146,7 +172,7 @@ typedef union {
int tok;
} YYSTYPE;
#endif /* YYSTYPE_DEFINED */
#line 149 "gram.c"
#line 175 "gram.c"
#define COMMAND 257
#define ALIAS 258
#define DEFVAR 259
@@ -183,9 +209,9 @@ typedef union {
#define MYSELF 290
#define YYERRCODE 256
#if defined(__cplusplus) || defined(__STDC__)
const short yylhs[] =
const short sudoerslhs[] =
#else
short yylhs[] =
short sudoerslhs[] =
#endif
{ -1,
0, 0, 28, 28, 29, 29, 29, 29, 29, 29,
@@ -201,9 +227,9 @@ short yylhs[] =
14, 14, 15, 15, 15,
};
#if defined(__cplusplus) || defined(__STDC__)
const short yylen[] =
const short sudoerslen[] =
#else
short yylen[] =
short sudoerslen[] =
#endif
{ 2,
0, 1, 1, 2, 1, 2, 2, 2, 2, 2,
@@ -219,9 +245,9 @@ short yylen[] =
1, 2, 1, 1, 1,
};
#if defined(__cplusplus) || defined(__STDC__)
const short yydefred[] =
const short sudoersdefred[] =
#else
short yydefred[] =
short sudoersdefred[] =
#endif
{ 0,
0, 94, 96, 97, 98, 0, 0, 0, 0, 0,
@@ -242,9 +268,9 @@ short yydefred[] =
63, 64, 65, 66, 67, 68, 69, 70, 36,
};
#if defined(__cplusplus) || defined(__STDC__)
const short yydgoto[] =
const short sudoersdgoto[] =
#else
short yydgoto[] =
short sudoersdgoto[] =
#endif
{ 18,
104, 105, 27, 28, 44, 45, 46, 35, 61, 37,
@@ -253,9 +279,9 @@ short yydgoto[] =
48, 51, 57, 49, 52, 58, 55,
};
#if defined(__cplusplus) || defined(__STDC__)
const short yysindex[] =
const short sudoerssindex[] =
#else
short yysindex[] =
short sudoerssindex[] =
#endif
{ 541,
-270, 0, 0, 0, 0, -21, -5, 553, 553, 20,
@@ -275,9 +301,9 @@ short yysindex[] =
-169, -168, 569, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,};
#if defined(__cplusplus) || defined(__STDC__)
const short yyrindex[] =
const short sudoersrindex[] =
#else
short yyrindex[] =
short sudoersrindex[] =
#endif
{ 96,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -297,9 +323,9 @@ short yyrindex[] =
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,};
#if defined(__cplusplus) || defined(__STDC__)
const short yygindex[] =
const short sudoersgindex[] =
#else
short yygindex[] =
short sudoersgindex[] =
#endif
{ 0,
-11, 0, 39, 12, 66, -72, 27, 76, -4, 40,
@@ -309,9 +335,9 @@ short yygindex[] =
};
#define YYTABLESIZE 932
#if defined(__cplusplus) || defined(__STDC__)
const short yytable[] =
const short sudoerstable[] =
#else
short yytable[] =
short sudoerstable[] =
#endif
{ 26,
19, 26, 36, 94, 41, 34, 38, 39, 26, 24,
@@ -410,9 +436,9 @@ short yytable[] =
50, 50,
};
#if defined(__cplusplus) || defined(__STDC__)
const short yycheck[] =
const short sudoerscheck[] =
#else
short yycheck[] =
short sudoerscheck[] =
#endif
{ 33,
0, 33, 7, 76, 33, 33, 8, 9, 33, 280,
@@ -517,9 +543,9 @@ short yycheck[] =
#define YYMAXTOKEN 290
#if YYDEBUG
#if defined(__cplusplus) || defined(__STDC__)
const char * const yyname[] =
const char * const sudoersname[] =
#else
char *yyname[] =
char *sudoersname[] =
#endif
{
"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
@@ -536,9 +562,9 @@ char *yyname[] =
"RUNASALIAS","ERROR","TYPE","ROLE","PRIVS","LIMITPRIVS","MYSELF",
};
#if defined(__cplusplus) || defined(__STDC__)
const char * const yyrule[] =
const char * const sudoersrule[] =
#else
char *yyrule[] =
char *sudoersrule[] =
#endif
{"$accept : file",
"file :",
@@ -876,7 +902,7 @@ init_parser(const char *path, bool quiet)
debug_return;
}
#line 827 "gram.c"
#line 853 "gram.c"
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
#if defined(__cplusplus) || defined(__STDC__)
static int yygrowstack(void)
@@ -1716,7 +1742,7 @@ case 105:
yyval.member = new_member(yyvsp[0].string, WORD);
}
break;
#line 1667 "gram.c"
#line 1693 "gram.c"
}
yyssp -= yym;
yystate = *yyssp;

View File

@@ -48,4 +48,4 @@ typedef union {
int tok;
} YYSTYPE;
#endif /* YYSTYPE_DEFINED */
extern YYSTYPE yylval;
extern YYSTYPE sudoerslval;

View File

@@ -68,7 +68,7 @@ struct sudo_nss sudo_nss_file = {
/*
* Parser externs.
*/
extern FILE *yyin;
extern FILE *sudoersin;
extern char *errorfile;
extern int errorlineno;
extern bool parse_error;
@@ -100,7 +100,7 @@ sudo_file_close(struct sudo_nss *nss)
if (nss->handle != NULL) {
fclose(nss->handle);
nss->handle = NULL;
yyin = NULL;
sudoersin = NULL;
}
debug_return_int(0);
}
@@ -117,8 +117,8 @@ sudo_file_parse(struct sudo_nss *nss)
debug_return_int(-1);
init_parser(sudoers_file, false);
yyin = nss->handle;
if (yyparse() != 0 || parse_error) {
sudoersin = nss->handle;
if (sudoersparse() != 0 || parse_error) {
if (errorlineno != -1) {
log_error(0, _("parse error in %s near line %d"),
errorfile, errorlineno);

View File

@@ -54,7 +54,7 @@
sudo_conv_t sudo_conv; /* NULL in non-plugin */
YYSTYPE yylval;
YYSTYPE sudoerslval;
struct fill_test {
const char *input;
@@ -106,8 +106,8 @@ check_fill(const char *input, int len, int addspace, const char *expect, char **
{
if (!fill(input, len))
return -1;
*resultp = yylval.string;
return !strcmp(yylval.string, expect);
*resultp = sudoerslval.string;
return !strcmp(sudoerslval.string, expect);
}
static int
@@ -115,8 +115,8 @@ check_fill_cmnd(const char *input, int len, int addspace, const char *expect, ch
{
if (!fill_cmnd(input, len))
return -1;
*resultp = yylval.command.cmnd;
return !strcmp(yylval.command.cmnd, expect);
*resultp = sudoerslval.command.cmnd;
return !strcmp(sudoerslval.command.cmnd, expect);
}
static int
@@ -124,8 +124,8 @@ check_fill_args(const char *input, int len, int addspace, const char *expect, ch
{
if (!fill_args(input, len, addspace))
return -1;
*resultp = yylval.command.args;
return !strcmp(yylval.command.args, expect);
*resultp = sudoerslval.command.args;
return !strcmp(sudoerslval.command.args, expect);
}
static int
@@ -191,7 +191,7 @@ cleanup(int gotsig)
/* STUB */
void
yyerror(const char *s)
sudoerserror(const char *s)
{
return;
}

View File

@@ -221,7 +221,7 @@ struct timeval;
/*
* Function prototypes
*/
#define YY_DECL int yylex(void)
#define YY_DECL int sudoerslex(void)
/* goodpath.c */
bool sudo_goodpath(const char *, struct stat *);
@@ -259,7 +259,7 @@ void restore_perms(void);
int pam_prep_user(struct passwd *);
/* gram.y */
int yyparse(void);
int sudoersparse(void);
/* toke.l */
YY_DECL;

View File

@@ -124,7 +124,7 @@ extern int optind;
extern char *malloc_options;
#endif
#ifdef YYDEBUG
extern int yydebug;
extern int sudoersdebug;
#endif
int
@@ -143,7 +143,7 @@ main(int argc, char *argv[])
malloc_options = "AFGJPR";
#endif
#ifdef YYDEBUG
yydebug = 1;
sudoersdebug = 1;
#endif
#if !defined(HAVE_GETPROGNAME) && !defined(HAVE___PROGNAME)
@@ -270,7 +270,7 @@ main(int argc, char *argv[])
/* Allocate space for data structures in the parser. */
init_parser("sudoers", false);
if (yyparse() != 0 || parse_error) {
if (sudoersparse() != 0 || parse_error) {
parse_error = true;
if (errorlineno != -1)
(void) printf("Parse error in %s near line %d",

View File

@@ -1,4 +1,21 @@
#include <config.h>
#define yy_create_buffer sudoers_create_buffer
#define yy_delete_buffer sudoers_delete_buffer
#define yy_scan_buffer sudoers_scan_buffer
#define yy_scan_string sudoers_scan_string
#define yy_scan_bytes sudoers_scan_bytes
#define yy_flex_debug sudoers_flex_debug
#define yy_init_buffer sudoers_init_buffer
#define yy_flush_buffer sudoers_flush_buffer
#define yy_load_buffer_state sudoers_load_buffer_state
#define yy_switch_to_buffer sudoers_switch_to_buffer
#define yyin sudoersin
#define yyleng sudoersleng
#define yylex sudoerslex
#define yyout sudoersout
#define yyrestart sudoersrestart
#define yytext sudoerstext
/* $OpenBSD: flex.skl,v 1.11 2010/08/04 18:24:50 millert Exp $ */
/* A lexical scanner generated by flex */
@@ -1468,7 +1485,7 @@ char *yytext;
#include "lbuf.h"
#include "secure_path.h"
extern YYSTYPE yylval;
extern YYSTYPE sudoerslval;
extern bool parse_error;
extern bool sudoers_warnings;
int sudolineno;
@@ -1495,7 +1512,7 @@ int (*trace_print)(const char *msg) = sudoers_trace_print;
return (n); \
} while (0)
#define ECHO ignore_result(fwrite(yytext, yyleng, 1, yyout))
#define ECHO ignore_result(fwrite(sudoerstext, sudoersleng, 1, sudoersout))
#define push_include(_p) (_push_include((_p), false))
#define push_includedir(_p) (_push_include((_p), true))
@@ -1511,7 +1528,7 @@ int (*trace_print)(const char *msg) = sudoers_trace_print;
#define INSTR 5
#line 1514 "lex.yy.c"
#line 1531 "lex.sudoers.c"
/* Macros after this point can all be overridden by user definitions in
* section 1.
@@ -1665,9 +1682,9 @@ YY_DECL
register char *yy_cp, *yy_bp;
register int yy_act;
#line 132 "toke.l"
#line 133 "toke.l"
#line 1670 "lex.yy.c"
#line 1687 "lex.sudoers.c"
if ( yy_init )
{
@@ -1753,7 +1770,7 @@ do_action: /* This label is used only to access EOF actions. */
case 1:
YY_RULE_SETUP
#line 133 "toke.l"
#line 134 "toke.l"
{
LEXTRACE(", ");
LEXRETURN(',');
@@ -1761,16 +1778,16 @@ YY_RULE_SETUP
YY_BREAK
case 2:
YY_RULE_SETUP
#line 138 "toke.l"
#line 139 "toke.l"
BEGIN STARTDEFS;
YY_BREAK
case 3:
YY_RULE_SETUP
#line 140 "toke.l"
#line 141 "toke.l"
{
BEGIN INDEFS;
LEXTRACE("DEFVAR ");
if (!fill(yytext, yyleng))
if (!fill(sudoerstext, sudoersleng))
yyterminate();
LEXRETURN(DEFVAR);
}
@@ -1778,7 +1795,7 @@ YY_RULE_SETUP
case 4:
YY_RULE_SETUP
#line 149 "toke.l"
#line 150 "toke.l"
{
BEGIN STARTDEFS;
LEXTRACE(", ");
@@ -1787,7 +1804,7 @@ YY_RULE_SETUP
YY_BREAK
case 5:
YY_RULE_SETUP
#line 155 "toke.l"
#line 156 "toke.l"
{
LEXTRACE("= ");
LEXRETURN('=');
@@ -1795,7 +1812,7 @@ YY_RULE_SETUP
YY_BREAK
case 6:
YY_RULE_SETUP
#line 160 "toke.l"
#line 161 "toke.l"
{
LEXTRACE("+= ");
LEXRETURN('+');
@@ -1803,7 +1820,7 @@ YY_RULE_SETUP
YY_BREAK
case 7:
YY_RULE_SETUP
#line 165 "toke.l"
#line 166 "toke.l"
{
LEXTRACE("-= ");
LEXRETURN('-');
@@ -1811,20 +1828,20 @@ YY_RULE_SETUP
YY_BREAK
case 8:
YY_RULE_SETUP
#line 170 "toke.l"
#line 171 "toke.l"
{
LEXTRACE("BEGINSTR ");
yylval.string = NULL;
sudoerslval.string = NULL;
prev_state = YY_START;
BEGIN INSTR;
}
YY_BREAK
case 9:
YY_RULE_SETUP
#line 177 "toke.l"
#line 178 "toke.l"
{
LEXTRACE("WORD(2) ");
if (!fill(yytext, yyleng))
if (!fill(sudoerstext, sudoersleng))
yyterminate();
LEXRETURN(WORD);
}
@@ -1833,7 +1850,7 @@ YY_RULE_SETUP
case 10:
YY_RULE_SETUP
#line 186 "toke.l"
#line 187 "toke.l"
{
/* Line continuation char followed by newline. */
sudolineno++;
@@ -1842,28 +1859,28 @@ YY_RULE_SETUP
YY_BREAK
case 11:
YY_RULE_SETUP
#line 192 "toke.l"
#line 193 "toke.l"
{
LEXTRACE("ENDSTR ");
BEGIN prev_state;
if (yylval.string == NULL) {
if (sudoerslval.string == NULL) {
LEXTRACE("ERROR "); /* empty string */
LEXRETURN(ERROR);
}
if (prev_state == INITIAL) {
switch (yylval.string[0]) {
switch (sudoerslval.string[0]) {
case '%':
if (yylval.string[1] == '\0' ||
(yylval.string[1] == ':' &&
yylval.string[2] == '\0')) {
if (sudoerslval.string[1] == '\0' ||
(sudoerslval.string[1] == ':' &&
sudoerslval.string[2] == '\0')) {
LEXTRACE("ERROR "); /* empty group */
LEXRETURN(ERROR);
}
LEXTRACE("USERGROUP ");
LEXRETURN(USERGROUP);
case '+':
if (yylval.string[1] == '\0') {
if (sudoerslval.string[1] == '\0') {
LEXTRACE("ERROR "); /* empty netgroup */
LEXRETURN(ERROR);
}
@@ -1877,19 +1894,19 @@ YY_RULE_SETUP
YY_BREAK
case 12:
YY_RULE_SETUP
#line 224 "toke.l"
#line 225 "toke.l"
{
LEXTRACE("BACKSLASH ");
if (!append(yytext, yyleng))
if (!append(sudoerstext, sudoersleng))
yyterminate();
}
YY_BREAK
case 13:
YY_RULE_SETUP
#line 230 "toke.l"
#line 231 "toke.l"
{
LEXTRACE("STRBODY ");
if (!append(yytext, yyleng))
if (!append(sudoerstext, sudoersleng))
yyterminate();
}
YY_BREAK
@@ -1897,29 +1914,29 @@ YY_RULE_SETUP
case 14:
YY_RULE_SETUP
#line 238 "toke.l"
#line 239 "toke.l"
{
/* quoted fnmatch glob char, pass verbatim */
LEXTRACE("QUOTEDCHAR ");
if (!fill_args(yytext, 2, sawspace))
if (!fill_args(sudoerstext, 2, sawspace))
yyterminate();
sawspace = false;
}
YY_BREAK
case 15:
YY_RULE_SETUP
#line 246 "toke.l"
#line 247 "toke.l"
{
/* quoted sudoers special char, strip backslash */
LEXTRACE("QUOTEDCHAR ");
if (!fill_args(yytext + 1, 1, sawspace))
if (!fill_args(sudoerstext + 1, 1, sawspace))
yyterminate();
sawspace = false;
}
YY_BREAK
case 16:
YY_RULE_SETUP
#line 254 "toke.l"
#line 255 "toke.l"
{
BEGIN INITIAL;
yyless(0);
@@ -1928,10 +1945,10 @@ YY_RULE_SETUP
YY_BREAK
case 17:
YY_RULE_SETUP
#line 260 "toke.l"
#line 261 "toke.l"
{
LEXTRACE("ARG ");
if (!fill_args(yytext, yyleng, sawspace))
if (!fill_args(sudoerstext, sudoersleng, sawspace))
yyterminate();
sawspace = false;
} /* a command line arg */
@@ -1939,7 +1956,7 @@ YY_RULE_SETUP
case 18:
YY_RULE_SETUP
#line 268 "toke.l"
#line 269 "toke.l"
{
char *path;
@@ -1948,7 +1965,7 @@ YY_RULE_SETUP
LEXRETURN(ERROR);
}
if ((path = parse_include(yytext)) == NULL)
if ((path = parse_include(sudoerstext)) == NULL)
yyterminate();
LEXTRACE("INCLUDE\n");
@@ -1960,7 +1977,7 @@ YY_RULE_SETUP
YY_BREAK
case 19:
YY_RULE_SETUP
#line 286 "toke.l"
#line 287 "toke.l"
{
char *path;
@@ -1969,7 +1986,7 @@ YY_RULE_SETUP
LEXRETURN(ERROR);
}
if ((path = parse_include(yytext)) == NULL)
if ((path = parse_include(sudoerstext)) == NULL)
yyterminate();
LEXTRACE("INCLUDEDIR\n");
@@ -1984,7 +2001,7 @@ YY_RULE_SETUP
YY_BREAK
case 20:
YY_RULE_SETUP
#line 307 "toke.l"
#line 308 "toke.l"
{
char deftype;
int n;
@@ -1994,11 +2011,11 @@ YY_RULE_SETUP
LEXRETURN(ERROR);
}
for (n = 0; isblank((unsigned char)yytext[n]); n++)
for (n = 0; isblank((unsigned char)sudoerstext[n]); n++)
continue;
n += sizeof("Defaults") - 1;
if ((deftype = yytext[n++]) != '\0') {
while (isblank((unsigned char)yytext[n]))
if ((deftype = sudoerstext[n++]) != '\0') {
while (isblank((unsigned char)sudoerstext[n]))
n++;
}
BEGIN GOTDEFS;
@@ -2027,7 +2044,7 @@ YY_RULE_SETUP
YY_BREAK
case 21:
YY_RULE_SETUP
#line 347 "toke.l"
#line 348 "toke.l"
{
int n;
@@ -2036,9 +2053,9 @@ YY_RULE_SETUP
LEXRETURN(ERROR);
}
for (n = 0; isblank((unsigned char)yytext[n]); n++)
for (n = 0; isblank((unsigned char)sudoerstext[n]); n++)
continue;
switch (yytext[n]) {
switch (sudoerstext[n]) {
case 'H':
LEXTRACE("HOSTALIAS ");
LEXRETURN(HOSTALIAS);
@@ -2056,7 +2073,7 @@ YY_RULE_SETUP
YY_BREAK
case 22:
YY_RULE_SETUP
#line 373 "toke.l"
#line 374 "toke.l"
{
/* cmnd does not require passwd for this user */
LEXTRACE("NOPASSWD ");
@@ -2065,7 +2082,7 @@ YY_RULE_SETUP
YY_BREAK
case 23:
YY_RULE_SETUP
#line 379 "toke.l"
#line 380 "toke.l"
{
/* cmnd requires passwd for this user */
LEXTRACE("PASSWD ");
@@ -2074,7 +2091,7 @@ YY_RULE_SETUP
YY_BREAK
case 24:
YY_RULE_SETUP
#line 385 "toke.l"
#line 386 "toke.l"
{
LEXTRACE("NOEXEC ");
LEXRETURN(NOEXEC);
@@ -2082,7 +2099,7 @@ YY_RULE_SETUP
YY_BREAK
case 25:
YY_RULE_SETUP
#line 390 "toke.l"
#line 391 "toke.l"
{
LEXTRACE("EXEC ");
LEXRETURN(EXEC);
@@ -2090,7 +2107,7 @@ YY_RULE_SETUP
YY_BREAK
case 26:
YY_RULE_SETUP
#line 395 "toke.l"
#line 396 "toke.l"
{
LEXTRACE("SETENV ");
LEXRETURN(SETENV);
@@ -2098,7 +2115,7 @@ YY_RULE_SETUP
YY_BREAK
case 27:
YY_RULE_SETUP
#line 400 "toke.l"
#line 401 "toke.l"
{
LEXTRACE("NOSETENV ");
LEXRETURN(NOSETENV);
@@ -2106,7 +2123,7 @@ YY_RULE_SETUP
YY_BREAK
case 28:
YY_RULE_SETUP
#line 405 "toke.l"
#line 406 "toke.l"
{
LEXTRACE("LOG_OUTPUT ");
LEXRETURN(LOG_OUTPUT);
@@ -2114,7 +2131,7 @@ YY_RULE_SETUP
YY_BREAK
case 29:
YY_RULE_SETUP
#line 410 "toke.l"
#line 411 "toke.l"
{
LEXTRACE("NOLOG_OUTPUT ");
LEXRETURN(NOLOG_OUTPUT);
@@ -2122,7 +2139,7 @@ YY_RULE_SETUP
YY_BREAK
case 30:
YY_RULE_SETUP
#line 415 "toke.l"
#line 416 "toke.l"
{
LEXTRACE("LOG_INPUT ");
LEXRETURN(LOG_INPUT);
@@ -2130,7 +2147,7 @@ YY_RULE_SETUP
YY_BREAK
case 31:
YY_RULE_SETUP
#line 420 "toke.l"
#line 421 "toke.l"
{
LEXTRACE("NOLOG_INPUT ");
LEXRETURN(NOLOG_INPUT);
@@ -2138,7 +2155,7 @@ YY_RULE_SETUP
YY_BREAK
case 32:
YY_RULE_SETUP
#line 425 "toke.l"
#line 426 "toke.l"
{
/* empty group or netgroup */
LEXTRACE("ERROR ");
@@ -2147,10 +2164,10 @@ YY_RULE_SETUP
YY_BREAK
case 33:
YY_RULE_SETUP
#line 431 "toke.l"
#line 432 "toke.l"
{
/* netgroup */
if (!fill(yytext, yyleng))
if (!fill(sudoerstext, sudoersleng))
yyterminate();
LEXTRACE("NETGROUP ");
LEXRETURN(NETGROUP);
@@ -2158,10 +2175,10 @@ YY_RULE_SETUP
YY_BREAK
case 34:
YY_RULE_SETUP
#line 439 "toke.l"
#line 440 "toke.l"
{
/* group */
if (!fill(yytext, yyleng))
if (!fill(sudoerstext, sudoersleng))
yyterminate();
LEXTRACE("USERGROUP ");
LEXRETURN(USERGROUP);
@@ -2169,9 +2186,9 @@ YY_RULE_SETUP
YY_BREAK
case 35:
YY_RULE_SETUP
#line 447 "toke.l"
#line 448 "toke.l"
{
if (!fill(yytext, yyleng))
if (!fill(sudoerstext, sudoersleng))
yyterminate();
LEXTRACE("NTWKADDR ");
LEXRETURN(NTWKADDR);
@@ -2179,9 +2196,9 @@ YY_RULE_SETUP
YY_BREAK
case 36:
YY_RULE_SETUP
#line 454 "toke.l"
#line 455 "toke.l"
{
if (!fill(yytext, yyleng))
if (!fill(sudoerstext, sudoersleng))
yyterminate();
LEXTRACE("NTWKADDR ");
LEXRETURN(NTWKADDR);
@@ -2189,13 +2206,13 @@ YY_RULE_SETUP
YY_BREAK
case 37:
YY_RULE_SETUP
#line 461 "toke.l"
#line 462 "toke.l"
{
if (!ipv6_valid(yytext)) {
if (!ipv6_valid(sudoerstext)) {
LEXTRACE("ERROR ");
LEXRETURN(ERROR);
}
if (!fill(yytext, yyleng))
if (!fill(sudoerstext, sudoersleng))
yyterminate();
LEXTRACE("NTWKADDR ");
LEXRETURN(NTWKADDR);
@@ -2203,13 +2220,13 @@ YY_RULE_SETUP
YY_BREAK
case 38:
YY_RULE_SETUP
#line 472 "toke.l"
#line 473 "toke.l"
{
if (!ipv6_valid(yytext)) {
if (!ipv6_valid(sudoerstext)) {
LEXTRACE("ERROR ");
LEXRETURN(ERROR);
}
if (!fill(yytext, yyleng))
if (!fill(sudoerstext, sudoersleng))
yyterminate();
LEXTRACE("NTWKADDR ");
LEXRETURN(NTWKADDR);
@@ -2217,7 +2234,7 @@ YY_RULE_SETUP
YY_BREAK
case 39:
YY_RULE_SETUP
#line 483 "toke.l"
#line 484 "toke.l"
{
LEXTRACE("ALL ");
LEXRETURN(ALL);
@@ -2226,7 +2243,7 @@ YY_RULE_SETUP
YY_BREAK
case 40:
YY_RULE_SETUP
#line 489 "toke.l"
#line 490 "toke.l"
{
#ifdef HAVE_SELINUX
LEXTRACE("ROLE ");
@@ -2238,7 +2255,7 @@ YY_RULE_SETUP
YY_BREAK
case 41:
YY_RULE_SETUP
#line 498 "toke.l"
#line 499 "toke.l"
{
#ifdef HAVE_SELINUX
LEXTRACE("TYPE ");
@@ -2250,7 +2267,7 @@ YY_RULE_SETUP
YY_BREAK
case 42:
YY_RULE_SETUP
#line 506 "toke.l"
#line 507 "toke.l"
{
#ifdef HAVE_PRIV_SET
LEXTRACE("PRIVS ");
@@ -2262,7 +2279,7 @@ YY_RULE_SETUP
YY_BREAK
case 43:
YY_RULE_SETUP
#line 515 "toke.l"
#line 516 "toke.l"
{
#ifdef HAVE_PRIV_SET
LEXTRACE("LIMITPRIVS ");
@@ -2274,10 +2291,10 @@ YY_RULE_SETUP
YY_BREAK
case 44:
YY_RULE_SETUP
#line 524 "toke.l"
#line 525 "toke.l"
{
got_alias:
if (!fill(yytext, yyleng))
if (!fill(sudoerstext, sudoersleng))
yyterminate();
LEXTRACE("ALIAS ");
LEXRETURN(ALIAS);
@@ -2285,10 +2302,10 @@ YY_RULE_SETUP
YY_BREAK
case 45:
YY_RULE_SETUP
#line 532 "toke.l"
#line 533 "toke.l"
{
/* no command args allowed for Defaults!/path */
if (!fill_cmnd(yytext, yyleng))
if (!fill_cmnd(sudoerstext, sudoersleng))
yyterminate();
LEXTRACE("COMMAND ");
LEXRETURN(COMMAND);
@@ -2296,48 +2313,48 @@ YY_RULE_SETUP
YY_BREAK
case 46:
YY_RULE_SETUP
#line 540 "toke.l"
#line 541 "toke.l"
{
BEGIN GOTCMND;
LEXTRACE("COMMAND ");
if (!fill_cmnd(yytext, yyleng))
if (!fill_cmnd(sudoerstext, sudoersleng))
yyterminate();
} /* sudo -e */
YY_BREAK
case 47:
YY_RULE_SETUP
#line 547 "toke.l"
#line 548 "toke.l"
{
/* directories can't have args... */
if (yytext[yyleng - 1] == '/') {
if (sudoerstext[sudoersleng - 1] == '/') {
LEXTRACE("COMMAND ");
if (!fill_cmnd(yytext, yyleng))
if (!fill_cmnd(sudoerstext, sudoersleng))
yyterminate();
LEXRETURN(COMMAND);
} else {
BEGIN GOTCMND;
LEXTRACE("COMMAND ");
if (!fill_cmnd(yytext, yyleng))
if (!fill_cmnd(sudoerstext, sudoersleng))
yyterminate();
}
} /* a pathname */
YY_BREAK
case 48:
YY_RULE_SETUP
#line 562 "toke.l"
#line 563 "toke.l"
{
LEXTRACE("BEGINSTR ");
yylval.string = NULL;
sudoerslval.string = NULL;
prev_state = YY_START;
BEGIN INSTR;
}
YY_BREAK
case 49:
YY_RULE_SETUP
#line 569 "toke.l"
#line 570 "toke.l"
{
/* a word */
if (!fill(yytext, yyleng))
if (!fill(sudoerstext, sudoersleng))
yyterminate();
LEXTRACE("WORD(5) ");
LEXRETURN(WORD);
@@ -2345,7 +2362,7 @@ YY_RULE_SETUP
YY_BREAK
case 50:
YY_RULE_SETUP
#line 577 "toke.l"
#line 578 "toke.l"
{
LEXTRACE("( ");
LEXRETURN('(');
@@ -2353,7 +2370,7 @@ YY_RULE_SETUP
YY_BREAK
case 51:
YY_RULE_SETUP
#line 582 "toke.l"
#line 583 "toke.l"
{
LEXTRACE(") ");
LEXRETURN(')');
@@ -2361,7 +2378,7 @@ YY_RULE_SETUP
YY_BREAK
case 52:
YY_RULE_SETUP
#line 587 "toke.l"
#line 588 "toke.l"
{
LEXTRACE(", ");
LEXRETURN(',');
@@ -2369,7 +2386,7 @@ YY_RULE_SETUP
YY_BREAK
case 53:
YY_RULE_SETUP
#line 592 "toke.l"
#line 593 "toke.l"
{
LEXTRACE("= ");
LEXRETURN('=');
@@ -2377,7 +2394,7 @@ YY_RULE_SETUP
YY_BREAK
case 54:
YY_RULE_SETUP
#line 597 "toke.l"
#line 598 "toke.l"
{
LEXTRACE(": ");
LEXRETURN(':');
@@ -2385,9 +2402,9 @@ YY_RULE_SETUP
YY_BREAK
case 55:
YY_RULE_SETUP
#line 602 "toke.l"
#line 603 "toke.l"
{
if (yyleng & 1) {
if (sudoersleng & 1) {
LEXTRACE("!");
LEXRETURN('!'); /* return '!' */
}
@@ -2395,7 +2412,7 @@ YY_RULE_SETUP
YY_BREAK
case 56:
YY_RULE_SETUP
#line 609 "toke.l"
#line 610 "toke.l"
{
if (YY_START == INSTR) {
LEXTRACE("ERROR ");
@@ -2410,14 +2427,14 @@ YY_RULE_SETUP
YY_BREAK
case 57:
YY_RULE_SETUP
#line 621 "toke.l"
#line 622 "toke.l"
{ /* throw away space/tabs */
sawspace = true; /* but remember for fill_args */
}
YY_BREAK
case 58:
YY_RULE_SETUP
#line 625 "toke.l"
#line 626 "toke.l"
{
sawspace = true; /* remember for fill_args */
sudolineno++;
@@ -2426,7 +2443,7 @@ YY_RULE_SETUP
YY_BREAK
case 59:
YY_RULE_SETUP
#line 631 "toke.l"
#line 632 "toke.l"
{
BEGIN INITIAL;
sudolineno++;
@@ -2437,7 +2454,7 @@ YY_RULE_SETUP
YY_BREAK
case 60:
YY_RULE_SETUP
#line 639 "toke.l"
#line 640 "toke.l"
{
LEXTRACE("ERROR ");
LEXRETURN(ERROR);
@@ -2449,7 +2466,7 @@ case YY_STATE_EOF(GOTCMND):
case YY_STATE_EOF(STARTDEFS):
case YY_STATE_EOF(INDEFS):
case YY_STATE_EOF(INSTR):
#line 644 "toke.l"
#line 645 "toke.l"
{
if (YY_START != INITIAL) {
BEGIN INITIAL;
@@ -2462,10 +2479,10 @@ case YY_STATE_EOF(INSTR):
YY_BREAK
case 61:
YY_RULE_SETUP
#line 654 "toke.l"
#line 655 "toke.l"
ECHO;
YY_BREAK
#line 2468 "lex.yy.c"
#line 2485 "lex.sudoers.c"
case YY_END_OF_BUFFER:
{
@@ -3356,7 +3373,7 @@ int main()
return 0;
}
#endif
#line 654 "toke.l"
#line 655 "toke.l"
struct path_list {
char *path;
@@ -3396,10 +3413,10 @@ switch_dir(struct include_stack *stack, char *dirpath)
if (errno != ENOENT) {
char *errbuf;
if (asprintf(&errbuf, _("%s: %s"), dirpath, strerror(errno)) != -1) {
yyerror(errbuf);
sudoerserror(errbuf);
free(errbuf);
} else {
yyerror(_("unable to allocate memory"));
sudoerserror(_("unable to allocate memory"));
}
}
goto done;
@@ -3498,7 +3515,7 @@ init_lexer(void)
efree(istack[idepth].path);
if (idepth && !istack[idepth].keepopen)
fclose(istack[idepth].bs->yy_input_file);
yy_delete_buffer(istack[idepth].bs);
sudoers_delete_buffer(istack[idepth].bs);
}
efree(istack);
istack = NULL;
@@ -3522,14 +3539,14 @@ _push_include(char *path, bool isdir)
/* push current state onto stack */
if (idepth >= istacksize) {
if (idepth > MAX_SUDOERS_DEPTH) {
yyerror(_("too many levels of includes"));
sudoerserror(_("too many levels of includes"));
debug_return_bool(false);
}
istacksize += SUDOERS_STACK_INCREMENT;
istack = (struct include_stack *) realloc(istack,
sizeof(*istack) * istacksize);
if (istack == NULL) {
yyerror(_("unable to allocate memory"));
sudoerserror(_("unable to allocate memory"));
debug_return_bool(false);
}
}
@@ -3570,7 +3587,7 @@ _push_include(char *path, bool isdir)
debug_return_bool(false);
}
if (!(path = switch_dir(&istack[idepth], path))) {
/* switch_dir() called yyerror() for us */
/* switch_dir() called sudoerserror() for us */
debug_return_bool(false);
}
while ((fp = open_sudoers(path, false, &keepopen)) == NULL) {
@@ -3585,7 +3602,7 @@ _push_include(char *path, bool isdir)
} else {
if ((fp = open_sudoers(path, true, &keepopen)) == NULL) {
/* The error was already printed by open_sudoers() */
yyerror(NULL);
sudoerserror(NULL);
debug_return_bool(false);
}
istack[idepth].more = NULL;
@@ -3598,7 +3615,7 @@ _push_include(char *path, bool isdir)
idepth++;
sudolineno = 1;
sudoers = path;
yy_switch_to_buffer(yy_create_buffer(fp, YY_BUF_SIZE));
sudoers_switch_to_buffer(sudoers_create_buffer(fp, YY_BUF_SIZE));
debug_return_bool(true);
}
@@ -3615,7 +3632,7 @@ pop_include(void)
if (!keepopen)
fclose(YY_CURRENT_BUFFER->yy_input_file);
yy_delete_buffer(YY_CURRENT_BUFFER);
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) {
fp = open_sudoers(pl->path, false, &keepopen);
@@ -3624,7 +3641,7 @@ pop_include(void)
efree(sudoers);
sudoers = pl->path;
sudolineno = 1;
yy_switch_to_buffer(yy_create_buffer(fp, YY_BUF_SIZE));
sudoers_switch_to_buffer(sudoers_create_buffer(fp, YY_BUF_SIZE));
efree(pl);
break;
}
@@ -3636,7 +3653,7 @@ pop_include(void)
/* If no path list, just pop the last dir on the stack. */
if (pl == NULL) {
idepth--;
yy_switch_to_buffer(istack[idepth].bs);
sudoers_switch_to_buffer(istack[idepth].bs);
efree(sudoers);
sudoers = istack[idepth].path;
sudolineno = istack[idepth].lineno;
@@ -3680,7 +3697,7 @@ parse_include(char *base)
len += (int)(ep - cp);
path = pp = malloc(len + dirlen + 1);
if (path == NULL) {
yyerror(_("unable to allocate memory"));
sudoerserror(_("unable to allocate memory"));
debug_return_str(NULL);
}
if (dirlen) {

View File

@@ -23,7 +23,7 @@ bool fill_cmnd(const char *, int);
bool fill_txt(const char *, int, int);
bool ipv6_valid(const char *s);
int sudoers_trace_print(const char *msg);
void yyerror(const char *);
void sudoerserror(const char *);
#ifndef FLEX_SCANNER
extern int (*trace_print)(const char *msg);

View File

@@ -74,7 +74,7 @@
#include "lbuf.h"
#include "secure_path.h"
extern YYSTYPE yylval;
extern YYSTYPE sudoerslval;
extern bool parse_error;
extern bool sudoers_warnings;
int sudolineno;
@@ -101,7 +101,7 @@ int (*trace_print)(const char *msg) = sudoers_trace_print;
return (n); \
} while (0)
#define ECHO ignore_result(fwrite(yytext, yyleng, 1, yyout))
#define ECHO ignore_result(fwrite(sudoerstext, sudoersleng, 1, sudoersout))
#define push_include(_p) (_push_include((_p), false))
#define push_includedir(_p) (_push_include((_p), true))
@@ -122,6 +122,7 @@ DEFVAR [a-z_]+
%option noinput
%option nounput
%option noyywrap
%option prefix="sudoers"
%s GOTDEFS
%x GOTCMND
@@ -140,7 +141,7 @@ DEFVAR [a-z_]+
<STARTDEFS>{DEFVAR} {
BEGIN INDEFS;
LEXTRACE("DEFVAR ");
if (!fill(yytext, yyleng))
if (!fill(sudoerstext, sudoersleng))
yyterminate();
LEXRETURN(DEFVAR);
}
@@ -169,14 +170,14 @@ DEFVAR [a-z_]+
\" {
LEXTRACE("BEGINSTR ");
yylval.string = NULL;
sudoerslval.string = NULL;
prev_state = YY_START;
BEGIN INSTR;
}
{ENVAR} {
LEXTRACE("WORD(2) ");
if (!fill(yytext, yyleng))
if (!fill(sudoerstext, sudoersleng))
yyterminate();
LEXRETURN(WORD);
}
@@ -193,23 +194,23 @@ DEFVAR [a-z_]+
LEXTRACE("ENDSTR ");
BEGIN prev_state;
if (yylval.string == NULL) {
if (sudoerslval.string == NULL) {
LEXTRACE("ERROR "); /* empty string */
LEXRETURN(ERROR);
}
if (prev_state == INITIAL) {
switch (yylval.string[0]) {
switch (sudoerslval.string[0]) {
case '%':
if (yylval.string[1] == '\0' ||
(yylval.string[1] == ':' &&
yylval.string[2] == '\0')) {
if (sudoerslval.string[1] == '\0' ||
(sudoerslval.string[1] == ':' &&
sudoerslval.string[2] == '\0')) {
LEXTRACE("ERROR "); /* empty group */
LEXRETURN(ERROR);
}
LEXTRACE("USERGROUP ");
LEXRETURN(USERGROUP);
case '+':
if (yylval.string[1] == '\0') {
if (sudoerslval.string[1] == '\0') {
LEXTRACE("ERROR "); /* empty netgroup */
LEXRETURN(ERROR);
}
@@ -223,13 +224,13 @@ DEFVAR [a-z_]+
\\ {
LEXTRACE("BACKSLASH ");
if (!append(yytext, yyleng))
if (!append(sudoerstext, sudoersleng))
yyterminate();
}
([^\"\n\\]|\\\")+ {
LEXTRACE("STRBODY ");
if (!append(yytext, yyleng))
if (!append(sudoerstext, sudoersleng))
yyterminate();
}
}
@@ -238,7 +239,7 @@ DEFVAR [a-z_]+
\\[\*\?\[\]\!] {
/* quoted fnmatch glob char, pass verbatim */
LEXTRACE("QUOTEDCHAR ");
if (!fill_args(yytext, 2, sawspace))
if (!fill_args(sudoerstext, 2, sawspace))
yyterminate();
sawspace = false;
}
@@ -246,7 +247,7 @@ DEFVAR [a-z_]+
\\[:\\,= \t#] {
/* quoted sudoers special char, strip backslash */
LEXTRACE("QUOTEDCHAR ");
if (!fill_args(yytext + 1, 1, sawspace))
if (!fill_args(sudoerstext + 1, 1, sawspace))
yyterminate();
sawspace = false;
}
@@ -259,7 +260,7 @@ DEFVAR [a-z_]+
[^#\\:, \t\n]+ {
LEXTRACE("ARG ");
if (!fill_args(yytext, yyleng, sawspace))
if (!fill_args(sudoerstext, sudoersleng, sawspace))
yyterminate();
sawspace = false;
} /* a command line arg */
@@ -273,7 +274,7 @@ DEFVAR [a-z_]+
LEXRETURN(ERROR);
}
if ((path = parse_include(yytext)) == NULL)
if ((path = parse_include(sudoerstext)) == NULL)
yyterminate();
LEXTRACE("INCLUDE\n");
@@ -291,7 +292,7 @@ DEFVAR [a-z_]+
LEXRETURN(ERROR);
}
if ((path = parse_include(yytext)) == NULL)
if ((path = parse_include(sudoerstext)) == NULL)
yyterminate();
LEXTRACE("INCLUDEDIR\n");
@@ -313,11 +314,11 @@ DEFVAR [a-z_]+
LEXRETURN(ERROR);
}
for (n = 0; isblank((unsigned char)yytext[n]); n++)
for (n = 0; isblank((unsigned char)sudoerstext[n]); n++)
continue;
n += sizeof("Defaults") - 1;
if ((deftype = yytext[n++]) != '\0') {
while (isblank((unsigned char)yytext[n]))
if ((deftype = sudoerstext[n++]) != '\0') {
while (isblank((unsigned char)sudoerstext[n]))
n++;
}
BEGIN GOTDEFS;
@@ -352,9 +353,9 @@ DEFVAR [a-z_]+
LEXRETURN(ERROR);
}
for (n = 0; isblank((unsigned char)yytext[n]); n++)
for (n = 0; isblank((unsigned char)sudoerstext[n]); n++)
continue;
switch (yytext[n]) {
switch (sudoerstext[n]) {
case 'H':
LEXTRACE("HOSTALIAS ");
LEXRETURN(HOSTALIAS);
@@ -430,7 +431,7 @@ NOLOG_INPUT[[:blank:]]*: {
\+{WORD} {
/* netgroup */
if (!fill(yytext, yyleng))
if (!fill(sudoerstext, sudoersleng))
yyterminate();
LEXTRACE("NETGROUP ");
LEXRETURN(NETGROUP);
@@ -438,43 +439,43 @@ NOLOG_INPUT[[:blank:]]*: {
\%:?({WORD}|{ID}) {
/* group */
if (!fill(yytext, yyleng))
if (!fill(sudoerstext, sudoersleng))
yyterminate();
LEXTRACE("USERGROUP ");
LEXRETURN(USERGROUP);
}
{IPV4ADDR}(\/{IPV4ADDR})? {
if (!fill(yytext, yyleng))
if (!fill(sudoerstext, sudoersleng))
yyterminate();
LEXTRACE("NTWKADDR ");
LEXRETURN(NTWKADDR);
}
{IPV4ADDR}\/([12]?[0-9]|3[0-2]) {
if (!fill(yytext, yyleng))
if (!fill(sudoerstext, sudoersleng))
yyterminate();
LEXTRACE("NTWKADDR ");
LEXRETURN(NTWKADDR);
}
{IPV6ADDR}(\/{IPV6ADDR})? {
if (!ipv6_valid(yytext)) {
if (!ipv6_valid(sudoerstext)) {
LEXTRACE("ERROR ");
LEXRETURN(ERROR);
}
if (!fill(yytext, yyleng))
if (!fill(sudoerstext, sudoersleng))
yyterminate();
LEXTRACE("NTWKADDR ");
LEXRETURN(NTWKADDR);
}
{IPV6ADDR}\/([0-9]|[1-9][0-9]|1[01][0-9]|12[0-8]) {
if (!ipv6_valid(yytext)) {
if (!ipv6_valid(sudoerstext)) {
LEXTRACE("ERROR ");
LEXRETURN(ERROR);
}
if (!fill(yytext, yyleng))
if (!fill(sudoerstext, sudoersleng))
yyterminate();
LEXTRACE("NTWKADDR ");
LEXRETURN(NTWKADDR);
@@ -523,7 +524,7 @@ ALL {
[[:upper:]][[:upper:][:digit:]_]* {
got_alias:
if (!fill(yytext, yyleng))
if (!fill(sudoerstext, sudoersleng))
yyterminate();
LEXTRACE("ALIAS ");
LEXRETURN(ALIAS);
@@ -531,7 +532,7 @@ ALL {
<GOTDEFS>({PATH}|sudoedit) {
/* no command args allowed for Defaults!/path */
if (!fill_cmnd(yytext, yyleng))
if (!fill_cmnd(sudoerstext, sudoersleng))
yyterminate();
LEXTRACE("COMMAND ");
LEXRETURN(COMMAND);
@@ -540,35 +541,35 @@ ALL {
sudoedit {
BEGIN GOTCMND;
LEXTRACE("COMMAND ");
if (!fill_cmnd(yytext, yyleng))
if (!fill_cmnd(sudoerstext, sudoersleng))
yyterminate();
} /* sudo -e */
{PATH} {
/* directories can't have args... */
if (yytext[yyleng - 1] == '/') {
if (sudoerstext[sudoersleng - 1] == '/') {
LEXTRACE("COMMAND ");
if (!fill_cmnd(yytext, yyleng))
if (!fill_cmnd(sudoerstext, sudoersleng))
yyterminate();
LEXRETURN(COMMAND);
} else {
BEGIN GOTCMND;
LEXTRACE("COMMAND ");
if (!fill_cmnd(yytext, yyleng))
if (!fill_cmnd(sudoerstext, sudoersleng))
yyterminate();
}
} /* a pathname */
<INITIAL,GOTDEFS>\" {
LEXTRACE("BEGINSTR ");
yylval.string = NULL;
sudoerslval.string = NULL;
prev_state = YY_START;
BEGIN INSTR;
}
<INITIAL,GOTDEFS>({ID}|{WORD}) {
/* a word */
if (!fill(yytext, yyleng))
if (!fill(sudoerstext, sudoersleng))
yyterminate();
LEXTRACE("WORD(5) ");
LEXRETURN(WORD);
@@ -600,7 +601,7 @@ sudoedit {
} /* return ':' */
<*>!+ {
if (yyleng & 1) {
if (sudoersleng & 1) {
LEXTRACE("!");
LEXRETURN('!'); /* return '!' */
}
@@ -690,10 +691,10 @@ switch_dir(struct include_stack *stack, char *dirpath)
if (errno != ENOENT) {
char *errbuf;
if (asprintf(&errbuf, _("%s: %s"), dirpath, strerror(errno)) != -1) {
yyerror(errbuf);
sudoerserror(errbuf);
free(errbuf);
} else {
yyerror(_("unable to allocate memory"));
sudoerserror(_("unable to allocate memory"));
}
}
goto done;
@@ -792,7 +793,7 @@ init_lexer(void)
efree(istack[idepth].path);
if (idepth && !istack[idepth].keepopen)
fclose(istack[idepth].bs->yy_input_file);
yy_delete_buffer(istack[idepth].bs);
sudoers_delete_buffer(istack[idepth].bs);
}
efree(istack);
istack = NULL;
@@ -816,14 +817,14 @@ _push_include(char *path, bool isdir)
/* push current state onto stack */
if (idepth >= istacksize) {
if (idepth > MAX_SUDOERS_DEPTH) {
yyerror(_("too many levels of includes"));
sudoerserror(_("too many levels of includes"));
debug_return_bool(false);
}
istacksize += SUDOERS_STACK_INCREMENT;
istack = (struct include_stack *) realloc(istack,
sizeof(*istack) * istacksize);
if (istack == NULL) {
yyerror(_("unable to allocate memory"));
sudoerserror(_("unable to allocate memory"));
debug_return_bool(false);
}
}
@@ -864,7 +865,7 @@ _push_include(char *path, bool isdir)
debug_return_bool(false);
}
if (!(path = switch_dir(&istack[idepth], path))) {
/* switch_dir() called yyerror() for us */
/* switch_dir() called sudoerserror() for us */
debug_return_bool(false);
}
while ((fp = open_sudoers(path, false, &keepopen)) == NULL) {
@@ -879,7 +880,7 @@ _push_include(char *path, bool isdir)
} else {
if ((fp = open_sudoers(path, true, &keepopen)) == NULL) {
/* The error was already printed by open_sudoers() */
yyerror(NULL);
sudoerserror(NULL);
debug_return_bool(false);
}
istack[idepth].more = NULL;
@@ -892,7 +893,7 @@ _push_include(char *path, bool isdir)
idepth++;
sudolineno = 1;
sudoers = path;
yy_switch_to_buffer(yy_create_buffer(fp, YY_BUF_SIZE));
sudoers_switch_to_buffer(sudoers_create_buffer(fp, YY_BUF_SIZE));
debug_return_bool(true);
}
@@ -909,7 +910,7 @@ pop_include(void)
if (!keepopen)
fclose(YY_CURRENT_BUFFER->yy_input_file);
yy_delete_buffer(YY_CURRENT_BUFFER);
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) {
fp = open_sudoers(pl->path, false, &keepopen);
@@ -918,7 +919,7 @@ pop_include(void)
efree(sudoers);
sudoers = pl->path;
sudolineno = 1;
yy_switch_to_buffer(yy_create_buffer(fp, YY_BUF_SIZE));
sudoers_switch_to_buffer(sudoers_create_buffer(fp, YY_BUF_SIZE));
efree(pl);
break;
}
@@ -930,7 +931,7 @@ pop_include(void)
/* If no path list, just pop the last dir on the stack. */
if (pl == NULL) {
idepth--;
yy_switch_to_buffer(istack[idepth].bs);
sudoers_switch_to_buffer(istack[idepth].bs);
efree(sudoers);
sudoers = istack[idepth].path;
sudolineno = istack[idepth].lineno;
@@ -974,7 +975,7 @@ parse_include(char *base)
len += (int)(ep - cp);
path = pp = malloc(len + dirlen + 1);
if (path == NULL) {
yyerror(_("unable to allocate memory"));
sudoerserror(_("unable to allocate memory"));
debug_return_str(NULL);
}
if (dirlen) {

View File

@@ -108,12 +108,12 @@ fill_txt(const char *src, int len, int olen)
char *dst;
debug_decl(fill_txt, SUDO_DEBUG_PARSER)
dst = olen ? realloc(yylval.string, olen + len + 1) : malloc(len + 1);
dst = olen ? realloc(sudoerslval.string, olen + len + 1) : malloc(len + 1);
if (dst == NULL) {
yyerror(_("unable to allocate memory"));
sudoerserror(_("unable to allocate memory"));
debug_return_bool(false);
}
yylval.string = dst;
sudoerslval.string = dst;
/* Copy the string and collapse any escaped characters. */
dst += olen;
@@ -144,8 +144,8 @@ append(const char *src, int len)
int olen = 0;
debug_decl(append, SUDO_DEBUG_PARSER)
if (yylval.string != NULL)
olen = strlen(yylval.string);
if (sudoerslval.string != NULL)
olen = strlen(sudoerslval.string);
debug_return_bool(fill_txt(src, len, olen));
}
@@ -162,9 +162,9 @@ fill_cmnd(const char *src, int len)
arg_len = arg_size = 0;
dst = yylval.command.cmnd = (char *) malloc(len + 1);
if (yylval.command.cmnd == NULL) {
yyerror(_("unable to allocate memory"));
dst = sudoerslval.command.cmnd = (char *) malloc(len + 1);
if (sudoerslval.command.cmnd == NULL) {
sudoerserror(_("unable to allocate memory"));
debug_return_bool(false);
}
@@ -177,7 +177,7 @@ fill_cmnd(const char *src, int len)
}
*dst = '\0';
yylval.command.args = NULL;
sudoerslval.command.args = NULL;
debug_return_bool(true);
}
@@ -188,7 +188,7 @@ fill_args(const char *s, int len, int addspace)
char *p;
debug_decl(fill_args, SUDO_DEBUG_PARSER)
if (yylval.command.args == NULL) {
if (sudoerslval.command.args == NULL) {
addspace = 0;
new_len = len;
} else
@@ -199,23 +199,23 @@ fill_args(const char *s, int len, int addspace)
while (new_len >= (arg_size += COMMANDARGINC))
;
p = yylval.command.args ?
(char *) realloc(yylval.command.args, arg_size) :
p = sudoerslval.command.args ?
(char *) realloc(sudoerslval.command.args, arg_size) :
(char *) malloc(arg_size);
if (p == NULL) {
efree(yylval.command.args);
yyerror(_("unable to allocate memory"));
efree(sudoerslval.command.args);
sudoerserror(_("unable to allocate memory"));
debug_return_bool(false);
} else
yylval.command.args = p;
sudoerslval.command.args = p;
}
/* Efficiently append the arg (with a leading space if needed). */
p = yylval.command.args + arg_len;
p = sudoerslval.command.args + arg_len;
if (addspace)
*p++ = ' ';
if (strlcpy(p, s, arg_size - (p - yylval.command.args)) != len) {
yyerror(_("fill_args: buffer overflow")); /* paranoia */
if (strlcpy(p, s, arg_size - (p - sudoerslval.command.args)) != len) {
sudoerserror(_("fill_args: buffer overflow")); /* paranoia */
debug_return_bool(false);
}
arg_len = new_len;

View File

@@ -118,14 +118,14 @@ static void usage(int);
void cleanup(int);
extern void yyerror(const char *);
extern void yyrestart(FILE *);
extern void sudoerserror(const char *);
extern void sudoersrestart(FILE *);
/*
* External globals exported by the parser
*/
extern struct rbtree *aliases;
extern FILE *yyin;
extern FILE *sudoersin;
extern char *sudoers, *errorfile;
extern int errorlineno;
extern bool parse_error;
@@ -232,11 +232,11 @@ main(int argc, char *argv[])
* Parse the existing sudoers file(s) in quiet mode to highlight any
* existing errors and to pull in editor and env_editor conf values.
*/
if ((yyin = open_sudoers(sudoers_path, true, NULL)) == NULL) {
if ((sudoersin = open_sudoers(sudoers_path, true, NULL)) == NULL) {
error(1, "%s", sudoers_path);
}
init_parser(sudoers_path, false);
yyparse();
sudoersparse();
(void) update_defaults(SETDEF_GENERIC|SETDEF_HOST|SETDEF_USER);
editor = get_editor(&args);
@@ -491,14 +491,14 @@ reparse_sudoers(char *editor, char *args, bool strict, bool quiet)
init_parser(sp->path, quiet);
/* Parse the sudoers temp file */
yyrestart(fp);
if (yyparse() && !parse_error) {
sudoersrestart(fp);
if (sudoersparse() && !parse_error) {
warningx(_("unabled to parse temporary file (%s), unknown error"),
sp->tpath);
parse_error = true;
errorfile = sp->path;
}
fclose(yyin);
fclose(sudoersin);
if (!parse_error) {
if (!check_defaults(SETDEF_ALL, quiet) ||
check_aliases(strict, quiet) != 0) {
@@ -812,15 +812,15 @@ check_syntax(char *sudoers_path, bool quiet, bool strict, bool oldperms)
debug_decl(check_syntax, SUDO_DEBUG_UTIL)
if (strcmp(sudoers_path, "-") == 0) {
yyin = stdin;
sudoersin = stdin;
sudoers_path = "stdin";
} else if ((yyin = fopen(sudoers_path, "r")) == NULL) {
} else if ((sudoersin = fopen(sudoers_path, "r")) == NULL) {
if (!quiet)
warning(_("unable to open %s"), sudoers_path);
goto done;
}
init_parser(sudoers_path, quiet);
if (yyparse() && !parse_error) {
if (sudoersparse() && !parse_error) {
if (!quiet)
warningx(_("failed to parse %s file, unknown error"), sudoers_path);
parse_error = true;