version 1.1.1.2, 2012/05/29 12:26:49
|
version 1.1.1.4, 2013/07/22 10:46:12
|
Line 1
|
Line 1
|
%{ |
%{ |
/* |
/* |
* Copyright (c) 1996, 1998-2005, 2007-2012 | * Copyright (c) 1996, 1998-2005, 2007-2013 |
* Todd C. Miller <Todd.Miller@courtesan.com> |
* Todd C. Miller <Todd.Miller@courtesan.com> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
Line 26
|
Line 26
|
#include <config.h> |
#include <config.h> |
|
|
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/param.h> |
|
#include <sys/stat.h> |
#include <sys/stat.h> |
#include <stdio.h> |
#include <stdio.h> |
#ifdef STDC_HEADERS |
#ifdef STDC_HEADERS |
Line 43
|
Line 42
|
#ifdef HAVE_STRINGS_H |
#ifdef HAVE_STRINGS_H |
# include <strings.h> |
# include <strings.h> |
#endif /* HAVE_STRINGS_H */ |
#endif /* HAVE_STRINGS_H */ |
|
#if defined(HAVE_STDINT_H) |
|
# include <stdint.h> |
|
#elif defined(HAVE_INTTYPES_H) |
|
# include <inttypes.h> |
|
#endif |
#ifdef HAVE_UNISTD_H |
#ifdef HAVE_UNISTD_H |
# include <unistd.h> |
# include <unistd.h> |
#endif /* HAVE_UNISTD_H */ |
#endif /* HAVE_UNISTD_H */ |
Line 72
|
Line 76
|
#include "toke.h" |
#include "toke.h" |
#include <gram.h> |
#include <gram.h> |
#include "lbuf.h" |
#include "lbuf.h" |
|
#include "sha2.h" |
#include "secure_path.h" |
#include "secure_path.h" |
|
|
extern YYSTYPE yylval; | extern YYSTYPE sudoerslval; |
extern bool parse_error; |
extern bool parse_error; |
extern bool sudoers_warnings; |
extern bool sudoers_warnings; |
int sudolineno; |
int sudolineno; |
Line 89 gid_t sudoers_gid = SUDOERS_GID;
|
Line 94 gid_t sudoers_gid = SUDOERS_GID;
|
|
|
static bool continued, sawspace; |
static bool continued, sawspace; |
static int prev_state; |
static int prev_state; |
|
static int digest_len; |
|
|
static bool _push_include(char *, bool); |
static bool _push_include(char *, bool); |
static bool pop_include(void); |
static bool pop_include(void); |
static char *parse_include(char *); |
static char *parse_include(char *); |
|
|
static int sudoers_trace_print(const char *msg); |
|
int (*trace_print)(const char *msg) = sudoers_trace_print; |
int (*trace_print)(const char *msg) = sudoers_trace_print; |
|
|
#define LEXRETURN(n) do { \ |
#define LEXRETURN(n) do { \ |
Line 102 int (*trace_print)(const char *msg) = sudoers_trace_pr
|
Line 107 int (*trace_print)(const char *msg) = sudoers_trace_pr
|
return (n); \ |
return (n); \ |
} while (0) |
} 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_include(_p) (_push_include((_p), false)) |
#define push_includedir(_p) (_push_include((_p), true)) |
#define push_includedir(_p) (_push_include((_p), true)) |
Line 123 DEFVAR [a-z_]+
|
Line 128 DEFVAR [a-z_]+
|
%option noinput |
%option noinput |
%option nounput |
%option nounput |
%option noyywrap |
%option noyywrap |
|
%option prefix="sudoers" |
|
|
%s GOTDEFS |
%s GOTDEFS |
%x GOTCMND |
%x GOTCMND |
%x STARTDEFS |
%x STARTDEFS |
%x INDEFS |
%x INDEFS |
%x INSTR |
%x INSTR |
|
%s WANTDIGEST |
|
|
%% |
%% |
<GOTDEFS>[[:blank:]]*,[[:blank:]]* { |
<GOTDEFS>[[:blank:]]*,[[:blank:]]* { |
Line 141 DEFVAR [a-z_]+
|
Line 148 DEFVAR [a-z_]+
|
<STARTDEFS>{DEFVAR} { |
<STARTDEFS>{DEFVAR} { |
BEGIN INDEFS; |
BEGIN INDEFS; |
LEXTRACE("DEFVAR "); |
LEXTRACE("DEFVAR "); |
if (!fill(yytext, yyleng)) | if (!fill(sudoerstext, sudoersleng)) |
yyterminate(); |
yyterminate(); |
LEXRETURN(DEFVAR); |
LEXRETURN(DEFVAR); |
} |
} |
Line 170 DEFVAR [a-z_]+
|
Line 177 DEFVAR [a-z_]+
|
|
|
\" { |
\" { |
LEXTRACE("BEGINSTR "); |
LEXTRACE("BEGINSTR "); |
yylval.string = NULL; | sudoerslval.string = NULL; |
prev_state = YY_START; |
prev_state = YY_START; |
BEGIN INSTR; |
BEGIN INSTR; |
} |
} |
|
|
{ENVAR} { |
{ENVAR} { |
LEXTRACE("WORD(2) "); |
LEXTRACE("WORD(2) "); |
if (!fill(yytext, yyleng)) | if (!fill(sudoerstext, sudoersleng)) |
yyterminate(); |
yyterminate(); |
LEXRETURN(WORD); |
LEXRETURN(WORD); |
} |
} |
Line 194 DEFVAR [a-z_]+
|
Line 201 DEFVAR [a-z_]+
|
LEXTRACE("ENDSTR "); |
LEXTRACE("ENDSTR "); |
BEGIN prev_state; |
BEGIN prev_state; |
|
|
if (yylval.string == NULL) { | if (sudoerslval.string == NULL) { |
LEXTRACE("ERROR "); /* empty string */ |
LEXTRACE("ERROR "); /* empty string */ |
LEXRETURN(ERROR); |
LEXRETURN(ERROR); |
} |
} |
if (prev_state == INITIAL) { |
if (prev_state == INITIAL) { |
switch (yylval.string[0]) { | switch (sudoerslval.string[0]) { |
case '%': |
case '%': |
if (yylval.string[1] == '\0' || | if (sudoerslval.string[1] == '\0' || |
(yylval.string[1] == ':' && | (sudoerslval.string[1] == ':' && |
yylval.string[2] == '\0')) { | sudoerslval.string[2] == '\0')) { |
LEXTRACE("ERROR "); /* empty group */ |
LEXTRACE("ERROR "); /* empty group */ |
LEXRETURN(ERROR); |
LEXRETURN(ERROR); |
} |
} |
LEXTRACE("USERGROUP "); |
LEXTRACE("USERGROUP "); |
LEXRETURN(USERGROUP); |
LEXRETURN(USERGROUP); |
case '+': |
case '+': |
if (yylval.string[1] == '\0') { | if (sudoerslval.string[1] == '\0') { |
LEXTRACE("ERROR "); /* empty netgroup */ |
LEXTRACE("ERROR "); /* empty netgroup */ |
LEXRETURN(ERROR); |
LEXRETURN(ERROR); |
} |
} |
Line 224 DEFVAR [a-z_]+
|
Line 231 DEFVAR [a-z_]+
|
|
|
\\ { |
\\ { |
LEXTRACE("BACKSLASH "); |
LEXTRACE("BACKSLASH "); |
if (!append(yytext, yyleng)) | if (!append(sudoerstext, sudoersleng)) |
yyterminate(); |
yyterminate(); |
} |
} |
|
|
([^\"\n\\]|\\\")+ { |
([^\"\n\\]|\\\")+ { |
LEXTRACE("STRBODY "); |
LEXTRACE("STRBODY "); |
if (!append(yytext, yyleng)) | if (!append(sudoerstext, sudoersleng)) |
yyterminate(); |
yyterminate(); |
} |
} |
} |
} |
Line 239 DEFVAR [a-z_]+
|
Line 246 DEFVAR [a-z_]+
|
\\[\*\?\[\]\!] { |
\\[\*\?\[\]\!] { |
/* quoted fnmatch glob char, pass verbatim */ |
/* quoted fnmatch glob char, pass verbatim */ |
LEXTRACE("QUOTEDCHAR "); |
LEXTRACE("QUOTEDCHAR "); |
if (!fill_args(yytext, 2, sawspace)) | if (!fill_args(sudoerstext, 2, sawspace)) |
yyterminate(); |
yyterminate(); |
sawspace = false; |
sawspace = false; |
} |
} |
Line 247 DEFVAR [a-z_]+
|
Line 254 DEFVAR [a-z_]+
|
\\[:\\,= \t#] { |
\\[:\\,= \t#] { |
/* quoted sudoers special char, strip backslash */ |
/* quoted sudoers special char, strip backslash */ |
LEXTRACE("QUOTEDCHAR "); |
LEXTRACE("QUOTEDCHAR "); |
if (!fill_args(yytext + 1, 1, sawspace)) | if (!fill_args(sudoerstext + 1, 1, sawspace)) |
yyterminate(); |
yyterminate(); |
sawspace = false; |
sawspace = false; |
} |
} |
Line 260 DEFVAR [a-z_]+
|
Line 267 DEFVAR [a-z_]+
|
|
|
[^#\\:, \t\n]+ { |
[^#\\:, \t\n]+ { |
LEXTRACE("ARG "); |
LEXTRACE("ARG "); |
if (!fill_args(yytext, yyleng, sawspace)) | if (!fill_args(sudoerstext, sudoersleng, sawspace)) |
yyterminate(); |
yyterminate(); |
sawspace = false; |
sawspace = false; |
} /* a command line arg */ |
} /* a command line arg */ |
} |
} |
|
|
|
<WANTDIGEST>[[:xdigit:]]+ { |
|
/* Only return DIGEST if the length is correct. */ |
|
if (sudoersleng == digest_len * 2) { |
|
if (!fill(sudoerstext, sudoersleng)) |
|
yyterminate(); |
|
BEGIN INITIAL; |
|
LEXTRACE("DIGEST "); |
|
LEXRETURN(DIGEST); |
|
} |
|
BEGIN INITIAL; |
|
yyless(sudoersleng); |
|
} /* hex digest */ |
|
|
|
<WANTDIGEST>[A-Za-z0-9\+/=]+ { |
|
/* Only return DIGEST if the length is correct. */ |
|
size_t len; |
|
if (sudoerstext[sudoersleng - 1] == '=') { |
|
/* use padding */ |
|
len = 4 * ((digest_len + 2) / 3); |
|
} else { |
|
/* no padding */ |
|
len = (4 * digest_len + 2) / 3; |
|
} |
|
if (sudoersleng == len) { |
|
if (!fill(sudoerstext, sudoersleng)) |
|
yyterminate(); |
|
BEGIN INITIAL; |
|
LEXTRACE("DIGEST "); |
|
LEXRETURN(DIGEST); |
|
} |
|
BEGIN INITIAL; |
|
yyless(sudoersleng); |
|
} /* base64 digest */ |
|
|
<INITIAL>^#include[[:blank:]]+.*\n { |
<INITIAL>^#include[[:blank:]]+.*\n { |
char *path; |
char *path; |
|
|
Line 274 DEFVAR [a-z_]+
|
Line 315 DEFVAR [a-z_]+
|
LEXRETURN(ERROR); |
LEXRETURN(ERROR); |
} |
} |
|
|
if ((path = parse_include(yytext)) == NULL) | if ((path = parse_include(sudoerstext)) == NULL) |
yyterminate(); |
yyterminate(); |
|
|
LEXTRACE("INCLUDE\n"); |
LEXTRACE("INCLUDE\n"); |
Line 292 DEFVAR [a-z_]+
|
Line 333 DEFVAR [a-z_]+
|
LEXRETURN(ERROR); |
LEXRETURN(ERROR); |
} |
} |
|
|
if ((path = parse_include(yytext)) == NULL) | if ((path = parse_include(sudoerstext)) == NULL) |
yyterminate(); |
yyterminate(); |
|
|
LEXTRACE("INCLUDEDIR\n"); |
LEXTRACE("INCLUDEDIR\n"); |
Line 314 DEFVAR [a-z_]+
|
Line 355 DEFVAR [a-z_]+
|
LEXRETURN(ERROR); |
LEXRETURN(ERROR); |
} |
} |
|
|
for (n = 0; isblank((unsigned char)yytext[n]); n++) | for (n = 0; isblank((unsigned char)sudoerstext[n]); n++) |
continue; |
continue; |
n += sizeof("Defaults") - 1; |
n += sizeof("Defaults") - 1; |
if ((deftype = yytext[n++]) != '\0') { | if ((deftype = sudoerstext[n++]) != '\0') { |
while (isblank((unsigned char)yytext[n])) | while (isblank((unsigned char)sudoerstext[n])) |
n++; |
n++; |
} |
} |
BEGIN GOTDEFS; |
BEGIN GOTDEFS; |
Line 353 DEFVAR [a-z_]+
|
Line 394 DEFVAR [a-z_]+
|
LEXRETURN(ERROR); |
LEXRETURN(ERROR); |
} |
} |
|
|
for (n = 0; isblank((unsigned char)yytext[n]); n++) | for (n = 0; isblank((unsigned char)sudoerstext[n]); n++) |
continue; |
continue; |
switch (yytext[n]) { | switch (sudoerstext[n]) { |
case 'H': |
case 'H': |
LEXTRACE("HOSTALIAS "); |
LEXTRACE("HOSTALIAS "); |
LEXRETURN(HOSTALIAS); |
LEXRETURN(HOSTALIAS); |
Line 431 NOLOG_INPUT[[:blank:]]*: {
|
Line 472 NOLOG_INPUT[[:blank:]]*: {
|
|
|
\+{WORD} { |
\+{WORD} { |
/* netgroup */ |
/* netgroup */ |
if (!fill(yytext, yyleng)) | if (!fill(sudoerstext, sudoersleng)) |
yyterminate(); |
yyterminate(); |
LEXTRACE("NETGROUP "); |
LEXTRACE("NETGROUP "); |
LEXRETURN(NETGROUP); |
LEXRETURN(NETGROUP); |
Line 439 NOLOG_INPUT[[:blank:]]*: {
|
Line 480 NOLOG_INPUT[[:blank:]]*: {
|
|
|
\%:?({WORD}|{ID}) { |
\%:?({WORD}|{ID}) { |
/* group */ |
/* group */ |
if (!fill(yytext, yyleng)) | if (!fill(sudoerstext, sudoersleng)) |
yyterminate(); |
yyterminate(); |
LEXTRACE("USERGROUP "); |
LEXTRACE("USERGROUP "); |
LEXRETURN(USERGROUP); |
LEXRETURN(USERGROUP); |
} |
} |
|
|
{IPV4ADDR}(\/{IPV4ADDR})? { |
{IPV4ADDR}(\/{IPV4ADDR})? { |
if (!fill(yytext, yyleng)) | if (!fill(sudoerstext, sudoersleng)) |
yyterminate(); |
yyterminate(); |
LEXTRACE("NTWKADDR "); |
LEXTRACE("NTWKADDR "); |
LEXRETURN(NTWKADDR); |
LEXRETURN(NTWKADDR); |
} |
} |
|
|
{IPV4ADDR}\/([12]?[0-9]|3[0-2]) { |
{IPV4ADDR}\/([12]?[0-9]|3[0-2]) { |
if (!fill(yytext, yyleng)) | if (!fill(sudoerstext, sudoersleng)) |
yyterminate(); |
yyterminate(); |
LEXTRACE("NTWKADDR "); |
LEXTRACE("NTWKADDR "); |
LEXRETURN(NTWKADDR); |
LEXRETURN(NTWKADDR); |
} |
} |
|
|
{IPV6ADDR}(\/{IPV6ADDR})? { |
{IPV6ADDR}(\/{IPV6ADDR})? { |
if (!ipv6_valid(yytext)) { | if (!ipv6_valid(sudoerstext)) { |
LEXTRACE("ERROR "); |
LEXTRACE("ERROR "); |
LEXRETURN(ERROR); |
LEXRETURN(ERROR); |
} |
} |
if (!fill(yytext, yyleng)) | if (!fill(sudoerstext, sudoersleng)) |
yyterminate(); |
yyterminate(); |
LEXTRACE("NTWKADDR "); |
LEXTRACE("NTWKADDR "); |
LEXRETURN(NTWKADDR); |
LEXRETURN(NTWKADDR); |
} |
} |
|
|
{IPV6ADDR}\/([0-9]|[1-9][0-9]|1[01][0-9]|12[0-8]) { |
{IPV6ADDR}\/([0-9]|[1-9][0-9]|1[01][0-9]|12[0-8]) { |
if (!ipv6_valid(yytext)) { | if (!ipv6_valid(sudoerstext)) { |
LEXTRACE("ERROR "); |
LEXTRACE("ERROR "); |
LEXRETURN(ERROR); |
LEXRETURN(ERROR); |
} |
} |
if (!fill(yytext, yyleng)) | if (!fill(sudoerstext, sudoersleng)) |
yyterminate(); |
yyterminate(); |
LEXTRACE("NTWKADDR "); |
LEXTRACE("NTWKADDR "); |
LEXRETURN(NTWKADDR); |
LEXRETURN(NTWKADDR); |
Line 504 ALL {
|
Line 545 ALL {
|
goto got_alias; |
goto got_alias; |
#endif |
#endif |
} |
} |
|
<INITIAL>PRIVS { |
|
#ifdef HAVE_PRIV_SET |
|
LEXTRACE("PRIVS "); |
|
LEXRETURN(PRIVS); |
|
#else |
|
goto got_alias; |
|
#endif |
|
} |
|
|
|
<INITIAL>LIMITPRIVS { |
|
#ifdef HAVE_PRIV_SET |
|
LEXTRACE("LIMITPRIVS "); |
|
LEXRETURN(LIMITPRIVS); |
|
#else |
|
goto got_alias; |
|
#endif |
|
} |
|
|
[[:upper:]][[:upper:][:digit:]_]* { |
[[:upper:]][[:upper:][:digit:]_]* { |
#ifndef HAVE_SELINUX |
|
got_alias: |
got_alias: |
#endif | if (!fill(sudoerstext, sudoersleng)) |
if (!fill(yytext, yyleng)) | |
yyterminate(); |
yyterminate(); |
LEXTRACE("ALIAS "); |
LEXTRACE("ALIAS "); |
LEXRETURN(ALIAS); |
LEXRETURN(ALIAS); |
} |
} |
|
|
<GOTDEFS>({PATH}|sudoedit) { |
<GOTDEFS>({PATH}|sudoedit) { |
|
/* XXX - no way to specify digest for command */ |
/* no command args allowed for Defaults!/path */ |
/* no command args allowed for Defaults!/path */ |
if (!fill_cmnd(yytext, yyleng)) | if (!fill_cmnd(sudoerstext, sudoersleng)) |
yyterminate(); |
yyterminate(); |
LEXTRACE("COMMAND "); |
LEXTRACE("COMMAND "); |
LEXRETURN(COMMAND); |
LEXRETURN(COMMAND); |
} |
} |
|
|
|
sha224 { |
|
digest_len = SHA224_DIGEST_LENGTH; |
|
BEGIN WANTDIGEST; |
|
LEXTRACE("SHA224 "); |
|
LEXRETURN(SHA224); |
|
} |
|
|
|
sha256 { |
|
digest_len = SHA256_DIGEST_LENGTH; |
|
BEGIN WANTDIGEST; |
|
LEXTRACE("SHA256 "); |
|
LEXRETURN(SHA256); |
|
} |
|
|
|
sha384 { |
|
digest_len = SHA384_DIGEST_LENGTH; |
|
BEGIN WANTDIGEST; |
|
LEXTRACE("SHA384 "); |
|
LEXRETURN(SHA384); |
|
} |
|
|
|
sha512 { |
|
digest_len = SHA512_DIGEST_LENGTH; |
|
BEGIN WANTDIGEST; |
|
LEXTRACE("SHA512 "); |
|
LEXRETURN(SHA512); |
|
} |
|
|
sudoedit { |
sudoedit { |
BEGIN GOTCMND; |
BEGIN GOTCMND; |
LEXTRACE("COMMAND "); |
LEXTRACE("COMMAND "); |
if (!fill_cmnd(yytext, yyleng)) | if (!fill_cmnd(sudoerstext, sudoersleng)) |
yyterminate(); |
yyterminate(); |
} /* sudo -e */ |
} /* sudo -e */ |
|
|
{PATH} { |
{PATH} { |
/* directories can't have args... */ |
/* directories can't have args... */ |
if (yytext[yyleng - 1] == '/') { | if (sudoerstext[sudoersleng - 1] == '/') { |
LEXTRACE("COMMAND "); |
LEXTRACE("COMMAND "); |
if (!fill_cmnd(yytext, yyleng)) | if (!fill_cmnd(sudoerstext, sudoersleng)) |
yyterminate(); |
yyterminate(); |
LEXRETURN(COMMAND); |
LEXRETURN(COMMAND); |
} else { |
} else { |
BEGIN GOTCMND; |
BEGIN GOTCMND; |
LEXTRACE("COMMAND "); |
LEXTRACE("COMMAND "); |
if (!fill_cmnd(yytext, yyleng)) | if (!fill_cmnd(sudoerstext, sudoersleng)) |
yyterminate(); |
yyterminate(); |
} |
} |
} /* a pathname */ |
} /* a pathname */ |
|
|
<INITIAL,GOTDEFS>\" { |
<INITIAL,GOTDEFS>\" { |
LEXTRACE("BEGINSTR "); |
LEXTRACE("BEGINSTR "); |
yylval.string = NULL; | sudoerslval.string = NULL; |
prev_state = YY_START; |
prev_state = YY_START; |
BEGIN INSTR; |
BEGIN INSTR; |
} |
} |
|
|
<INITIAL,GOTDEFS>({ID}|{WORD}) { |
<INITIAL,GOTDEFS>({ID}|{WORD}) { |
/* a word */ |
/* a word */ |
if (!fill(yytext, yyleng)) | if (!fill(sudoerstext, sudoersleng)) |
yyterminate(); |
yyterminate(); |
LEXTRACE("WORD(5) "); |
LEXTRACE("WORD(5) "); |
LEXRETURN(WORD); |
LEXRETURN(WORD); |
Line 586 sudoedit {
|
Line 671 sudoedit {
|
} /* return ':' */ |
} /* return ':' */ |
|
|
<*>!+ { |
<*>!+ { |
if (yyleng & 1) { | if (sudoersleng & 1) { |
LEXTRACE("!"); |
LEXTRACE("!"); |
LEXRETURN('!'); /* return '!' */ |
LEXRETURN('!'); /* return '!' */ |
} |
} |
Line 674 switch_dir(struct include_stack *stack, char *dirpath)
|
Line 759 switch_dir(struct include_stack *stack, char *dirpath)
|
|
|
if (!(dir = opendir(dirpath))) { |
if (!(dir = opendir(dirpath))) { |
if (errno != ENOENT) { |
if (errno != ENOENT) { |
char *errbuf; | warning("%s", dirpath); |
if (asprintf(&errbuf, _("%s: %s"), dirpath, strerror(errno)) != -1) { | sudoerserror(NULL); |
yyerror(errbuf); | |
free(errbuf); | |
} else { | |
yyerror(_("unable to allocate memory")); | |
} | |
} |
} |
goto done; |
goto done; |
} |
} |
Line 705 switch_dir(struct include_stack *stack, char *dirpath)
|
Line 785 switch_dir(struct include_stack *stack, char *dirpath)
|
pl->path = path; |
pl->path = path; |
pl->next = first; |
pl->next = first; |
first = pl; |
first = pl; |
|
path = NULL; |
count++; |
count++; |
} |
} |
closedir(dir); |
closedir(dir); |
Line 746 bad:
|
Line 827 bad:
|
while (first != NULL) { |
while (first != NULL) { |
pl = first; |
pl = first; |
first = pl->next; |
first = pl->next; |
free(pl->path); | efree(pl->path); |
free(pl); | efree(pl); |
} |
} |
efree(sorted); |
efree(sorted); |
efree(dirpath); |
efree(dirpath); |
Line 778 init_lexer(void)
|
Line 859 init_lexer(void)
|
efree(istack[idepth].path); |
efree(istack[idepth].path); |
if (idepth && !istack[idepth].keepopen) |
if (idepth && !istack[idepth].keepopen) |
fclose(istack[idepth].bs->yy_input_file); |
fclose(istack[idepth].bs->yy_input_file); |
yy_delete_buffer(istack[idepth].bs); | sudoers_delete_buffer(istack[idepth].bs); |
} |
} |
efree(istack); |
efree(istack); |
istack = NULL; |
istack = NULL; |
Line 802 _push_include(char *path, bool isdir)
|
Line 883 _push_include(char *path, bool isdir)
|
/* push current state onto stack */ |
/* push current state onto stack */ |
if (idepth >= istacksize) { |
if (idepth >= istacksize) { |
if (idepth > MAX_SUDOERS_DEPTH) { |
if (idepth > MAX_SUDOERS_DEPTH) { |
yyerror(_("too many levels of includes")); | sudoerserror(N_("too many levels of includes")); |
debug_return_bool(false); |
debug_return_bool(false); |
} |
} |
istacksize += SUDOERS_STACK_INCREMENT; |
istacksize += SUDOERS_STACK_INCREMENT; |
istack = (struct include_stack *) realloc(istack, |
istack = (struct include_stack *) realloc(istack, |
sizeof(*istack) * istacksize); |
sizeof(*istack) * istacksize); |
if (istack == NULL) { |
if (istack == NULL) { |
yyerror(_("unable to allocate memory")); | warning(NULL); |
| sudoerserror(NULL); |
debug_return_bool(false); |
debug_return_bool(false); |
} |
} |
} |
} |
Line 850 _push_include(char *path, bool isdir)
|
Line 932 _push_include(char *path, bool isdir)
|
debug_return_bool(false); |
debug_return_bool(false); |
} |
} |
if (!(path = switch_dir(&istack[idepth], path))) { |
if (!(path = switch_dir(&istack[idepth], path))) { |
/* switch_dir() called yyerror() for us */ | /* switch_dir() called sudoerserror() for us */ |
debug_return_bool(false); |
debug_return_bool(false); |
} |
} |
while ((fp = open_sudoers(path, false, &keepopen)) == NULL) { |
while ((fp = open_sudoers(path, false, &keepopen)) == NULL) { |
Line 864 _push_include(char *path, bool isdir)
|
Line 946 _push_include(char *path, bool isdir)
|
} |
} |
} else { |
} else { |
if ((fp = open_sudoers(path, true, &keepopen)) == NULL) { |
if ((fp = open_sudoers(path, true, &keepopen)) == NULL) { |
char *errbuf; | /* The error was already printed by open_sudoers() */ |
if (asprintf(&errbuf, _("%s: %s"), path, strerror(errno)) != -1) { | sudoerserror(NULL); |
yyerror(errbuf); | |
free(errbuf); | |
} else { | |
yyerror(_("unable to allocate memory")); | |
} | |
debug_return_bool(false); |
debug_return_bool(false); |
} |
} |
istack[idepth].more = NULL; |
istack[idepth].more = NULL; |
Line 883 _push_include(char *path, bool isdir)
|
Line 960 _push_include(char *path, bool isdir)
|
idepth++; |
idepth++; |
sudolineno = 1; |
sudolineno = 1; |
sudoers = path; |
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); |
debug_return_bool(true); |
} |
} |
Line 900 pop_include(void)
|
Line 977 pop_include(void)
|
|
|
if (!keepopen) |
if (!keepopen) |
fclose(YY_CURRENT_BUFFER->yy_input_file); |
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. */ |
/* If we are in an include dir, move to the next file. */ |
while ((pl = istack[idepth - 1].more) != NULL) { |
while ((pl = istack[idepth - 1].more) != NULL) { |
fp = open_sudoers(pl->path, false, &keepopen); |
fp = open_sudoers(pl->path, false, &keepopen); |
Line 909 pop_include(void)
|
Line 986 pop_include(void)
|
efree(sudoers); |
efree(sudoers); |
sudoers = pl->path; |
sudoers = pl->path; |
sudolineno = 1; |
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); |
efree(pl); |
break; |
break; |
} |
} |
Line 921 pop_include(void)
|
Line 998 pop_include(void)
|
/* If no path list, just pop the last dir on the stack. */ |
/* If no path list, just pop the last dir on the stack. */ |
if (pl == NULL) { |
if (pl == NULL) { |
idepth--; |
idepth--; |
yy_switch_to_buffer(istack[idepth].bs); | sudoers_switch_to_buffer(istack[idepth].bs); |
efree(sudoers); |
efree(sudoers); |
sudoers = istack[idepth].path; |
sudoers = istack[idepth].path; |
sudolineno = istack[idepth].lineno; |
sudolineno = istack[idepth].lineno; |
Line 965 parse_include(char *base)
|
Line 1042 parse_include(char *base)
|
len += (int)(ep - cp); |
len += (int)(ep - cp); |
path = pp = malloc(len + dirlen + 1); |
path = pp = malloc(len + dirlen + 1); |
if (path == NULL) { |
if (path == NULL) { |
yyerror(_("unable to allocate memory")); | warning(NULL); |
| sudoerserror(NULL); |
debug_return_str(NULL); |
debug_return_str(NULL); |
} |
} |
if (dirlen) { |
if (dirlen) { |
Line 997 parse_include(char *base)
|
Line 1075 parse_include(char *base)
|
} |
} |
|
|
#ifdef TRACELEXER |
#ifdef TRACELEXER |
static int | int |
sudoers_trace_print(const char *msg) |
sudoers_trace_print(const char *msg) |
{ |
{ |
return fputs(msg, stderr); |
return fputs(msg, stderr); |
} |
} |
#else |
#else |
static int | int |
sudoers_trace_print(const char *msg) |
sudoers_trace_print(const char *msg) |
{ |
{ |
static bool initialized; |
static bool initialized; |