* Prototypes
*/
static int has_meta __P((char *));
- void init_parser __P((void));
/*
* Look up the user in the sudoers file and check to see if they are
yyout = stdout;
/* Allocate space for data structures in the parser. */
- init_parser();
+ init_parser(_PATH_SUDOERS);
/* If pwcheck *could* be "all" or "any", keep more state. */
if (pwflag > 0)
int netgr_matches __P((char *, char *, char *, char *));
int userpw_matches __P((char *, char *, struct passwd *));
int usergr_matches __P((char *, char *, struct passwd *));
+void init_parser __P((char *));
#endif /* _SUDO_PARSE_H */
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 *));
<INITIAL>^#include[ \t]+.*\n {
char *cp, *ep;
+ ++sudolineno;
/* pull out path from #include line */
for (cp = yytext + 9; isspace(*cp); cp++)
continue;
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);
}