Move sudoers search path to struct sudoers_parser_config.
That way we can avoid passing it to init_parser() directly. We still need sudoers_search_path to be shared between the lexer and the parser.
This commit is contained in:
@@ -770,7 +770,7 @@ parse_sudoers(const char *input_file, struct cvtsudoers_config *conf)
|
||||
input_file = "stdin";
|
||||
} else if ((sudoersin = fopen(input_file, "r")) == NULL)
|
||||
sudo_fatal(U_("unable to open %s"), input_file);
|
||||
init_parser(input_file, NULL, NULL);
|
||||
init_parser(input_file, NULL);
|
||||
if (sudoersparse() && !parse_error) {
|
||||
sudo_warnx(U_("failed to parse %s file, unknown error"), input_file);
|
||||
parse_error = true;
|
||||
|
@@ -73,10 +73,10 @@ sudo_file_open(struct sudo_nss *nss)
|
||||
|
||||
handle = malloc(sizeof(*handle));
|
||||
if (handle != NULL) {
|
||||
const char *path_sudoers = policy_path_sudoers();
|
||||
handle->fp = open_sudoers(path_sudoers, &outfile, false, NULL);
|
||||
const struct sudoers_parser_config *conf = policy_sudoers_conf();
|
||||
handle->fp = open_sudoers(conf->sudoers_path, &outfile, false, NULL);
|
||||
if (handle->fp != NULL) {
|
||||
init_parser(NULL, path_sudoers, policy_sudoers_conf());
|
||||
init_parser(NULL, policy_sudoers_conf());
|
||||
init_parse_tree(&handle->parse_tree, NULL, NULL, nss);
|
||||
if (outfile != NULL) {
|
||||
/* Update path to open sudoers file. */
|
||||
|
@@ -3967,8 +3967,7 @@ free_parse_tree(struct sudoers_parse_tree *parse_tree)
|
||||
* the current sudoers file to path.
|
||||
*/
|
||||
bool
|
||||
init_parser(const char *file, const char *path,
|
||||
const struct sudoers_parser_config *conf)
|
||||
init_parser(const char *file, const struct sudoers_parser_config *conf)
|
||||
{
|
||||
bool ret = true;
|
||||
debug_decl(init_parser, SUDOERS_DEBUG_PARSER);
|
||||
@@ -3976,6 +3975,15 @@ init_parser(const char *file, const char *path,
|
||||
free_parse_tree(&parsed_policy);
|
||||
parser_leak_init();
|
||||
init_lexer();
|
||||
parse_error = false;
|
||||
|
||||
if (conf != NULL) {
|
||||
parser_conf = *conf;
|
||||
} else {
|
||||
const struct sudoers_parser_config def_conf =
|
||||
SUDOERS_PARSER_CONFIG_INITIALIZER;
|
||||
parser_conf = def_conf;
|
||||
}
|
||||
|
||||
sudo_rcstr_delref(sudoers);
|
||||
if (file != NULL) {
|
||||
@@ -3988,8 +3996,9 @@ init_parser(const char *file, const char *path,
|
||||
}
|
||||
|
||||
sudo_rcstr_delref(sudoers_search_path);
|
||||
if (path != NULL) {
|
||||
if ((sudoers_search_path = sudo_rcstr_dup(path)) == NULL) {
|
||||
if (parser_conf.sudoers_path != NULL) {
|
||||
sudoers_search_path = sudo_rcstr_dup(parser_conf.sudoers_path);
|
||||
if (sudoers_search_path == NULL) {
|
||||
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
|
||||
ret = false;
|
||||
}
|
||||
@@ -3997,22 +4006,13 @@ init_parser(const char *file, const char *path,
|
||||
sudoers_search_path = NULL;
|
||||
}
|
||||
|
||||
if (conf != NULL) {
|
||||
parser_conf = *conf;
|
||||
} else {
|
||||
const struct sudoers_parser_config def_conf =
|
||||
SUDOERS_PARSER_CONFIG_INITIALIZER;
|
||||
parser_conf = def_conf;
|
||||
}
|
||||
parse_error = false;
|
||||
|
||||
debug_return_bool(ret);
|
||||
}
|
||||
|
||||
bool
|
||||
reset_parser(void)
|
||||
{
|
||||
return init_parser(NULL, NULL, NULL);
|
||||
return init_parser(NULL, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -1784,8 +1784,7 @@ free_parse_tree(struct sudoers_parse_tree *parse_tree)
|
||||
* the current sudoers file to path.
|
||||
*/
|
||||
bool
|
||||
init_parser(const char *file, const char *path,
|
||||
const struct sudoers_parser_config *conf)
|
||||
init_parser(const char *file, const struct sudoers_parser_config *conf)
|
||||
{
|
||||
bool ret = true;
|
||||
debug_decl(init_parser, SUDOERS_DEBUG_PARSER);
|
||||
@@ -1793,6 +1792,15 @@ init_parser(const char *file, const char *path,
|
||||
free_parse_tree(&parsed_policy);
|
||||
parser_leak_init();
|
||||
init_lexer();
|
||||
parse_error = false;
|
||||
|
||||
if (conf != NULL) {
|
||||
parser_conf = *conf;
|
||||
} else {
|
||||
const struct sudoers_parser_config def_conf =
|
||||
SUDOERS_PARSER_CONFIG_INITIALIZER;
|
||||
parser_conf = def_conf;
|
||||
}
|
||||
|
||||
sudo_rcstr_delref(sudoers);
|
||||
if (file != NULL) {
|
||||
@@ -1805,8 +1813,9 @@ init_parser(const char *file, const char *path,
|
||||
}
|
||||
|
||||
sudo_rcstr_delref(sudoers_search_path);
|
||||
if (path != NULL) {
|
||||
if ((sudoers_search_path = sudo_rcstr_dup(path)) == NULL) {
|
||||
if (parser_conf.sudoers_path != NULL) {
|
||||
sudoers_search_path = sudo_rcstr_dup(parser_conf.sudoers_path);
|
||||
if (sudoers_search_path == NULL) {
|
||||
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
|
||||
ret = false;
|
||||
}
|
||||
@@ -1814,22 +1823,13 @@ init_parser(const char *file, const char *path,
|
||||
sudoers_search_path = NULL;
|
||||
}
|
||||
|
||||
if (conf != NULL) {
|
||||
parser_conf = *conf;
|
||||
} else {
|
||||
const struct sudoers_parser_config def_conf =
|
||||
SUDOERS_PARSER_CONFIG_INITIALIZER;
|
||||
parser_conf = def_conf;
|
||||
}
|
||||
parse_error = false;
|
||||
|
||||
debug_return_bool(ret);
|
||||
}
|
||||
|
||||
bool
|
||||
reset_parser(void)
|
||||
{
|
||||
return init_parser(NULL, NULL, NULL);
|
||||
return init_parser(NULL, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -326,6 +326,7 @@ struct cmnd_info {
|
||||
* Parse configuration settings, passed to init_parser().
|
||||
*/
|
||||
struct sudoers_parser_config {
|
||||
const char *sudoers_path;
|
||||
bool strict;
|
||||
bool recovery;
|
||||
int verbose;
|
||||
@@ -334,6 +335,7 @@ struct sudoers_parser_config {
|
||||
gid_t sudoers_gid;
|
||||
};
|
||||
#define SUDOERS_PARSER_CONFIG_INITIALIZER { \
|
||||
NULL, /* sudoers_path */ \
|
||||
false, /* strict */ \
|
||||
true, /* recovery */ \
|
||||
1, /* verbose level 1 */ \
|
||||
@@ -392,7 +394,7 @@ int check_aliases(struct sudoers_parse_tree *parse_tree, bool strict, bool quiet
|
||||
/* gram.y */
|
||||
extern struct sudoers_parse_tree parsed_policy;
|
||||
extern bool (*sudoers_error_hook)(const char *file, int line, int column, const char *fmt, va_list args);
|
||||
bool init_parser(const char *file, const char *path, const struct sudoers_parser_config *conf);
|
||||
bool init_parser(const char *file, const struct sudoers_parser_config *conf);
|
||||
bool reset_parser(void);
|
||||
void free_member(struct member *m);
|
||||
void free_members(struct member_list *members);
|
||||
|
@@ -180,6 +180,7 @@ sudoers_policy_deserialize_info(void *v, struct defaults_list *defaults)
|
||||
}
|
||||
}
|
||||
}
|
||||
parser_conf.sudoers_path = path_sudoers;
|
||||
|
||||
/* Parse command line settings. */
|
||||
sudo_user.flags = 0;
|
||||
@@ -630,13 +631,6 @@ policy_sudoers_conf(void)
|
||||
return &parser_conf;
|
||||
}
|
||||
|
||||
/* Return the path to the sudoers file, which may be set in the plugin args. */
|
||||
const char *
|
||||
policy_path_sudoers(void)
|
||||
{
|
||||
return path_sudoers;
|
||||
}
|
||||
|
||||
/* Return the path to ldap.conf file, which may be set in the plugin args. */
|
||||
const char *
|
||||
policy_path_ldap_conf(void)
|
||||
|
@@ -312,7 +312,7 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
|
||||
/* Initialize defaults and parse sudoers. */
|
||||
init_defaults();
|
||||
init_parser("sudoers", NULL, NULL);
|
||||
init_parser("sudoers", NULL);
|
||||
sudoersrestart(fp);
|
||||
sudoersparse();
|
||||
reparent_parse_tree(&parse_tree);
|
||||
|
@@ -448,7 +448,6 @@ void sudoers_debug_deregister(void);
|
||||
int sudoers_policy_deserialize_info(void *v, struct defaults_list *defaults);
|
||||
bool sudoers_policy_store_result(bool accepted, char *argv[], char *envp[], mode_t cmnd_umask, char *iolog_path, void *v);
|
||||
const struct sudoers_parser_config *policy_sudoers_conf(void);
|
||||
const char *policy_path_sudoers(void);
|
||||
const char *policy_path_ldap_conf(void);
|
||||
const char *policy_path_ldap_secret(void);
|
||||
|
||||
|
@@ -280,7 +280,7 @@ main(int argc, char *argv[])
|
||||
/* Initialize the parser and set sudoers filename to "sudoers". */
|
||||
parser_conf.strict = true;
|
||||
parser_conf.verbose = 2;
|
||||
init_parser("sudoers", NULL, &parser_conf);
|
||||
init_parser("sudoers", &parser_conf);
|
||||
|
||||
/*
|
||||
* Set runas passwd/group entries based on command line or sudoers.
|
||||
|
@@ -291,7 +291,8 @@ main(int argc, char *argv[])
|
||||
*/
|
||||
parser_conf.strict = true;
|
||||
parser_conf.verbose = quiet ? 0 : 2;
|
||||
init_parser(NULL, path_sudoers, &parser_conf);
|
||||
parser_conf.sudoers_path = path_sudoers;
|
||||
init_parser(NULL, &parser_conf);
|
||||
if ((sudoersin = open_sudoers(path_sudoers, &sudoers, true, NULL)) == NULL)
|
||||
exit(EXIT_FAILURE);
|
||||
sudoers_setlocale(SUDOERS_LOCALE_SUDOERS, &oldlocale);
|
||||
@@ -654,7 +655,7 @@ reparse_sudoers(char *editor, int editor_argc, char **editor_argv,
|
||||
/* Clean slate for each parse */
|
||||
if (!init_defaults())
|
||||
sudo_fatalx("%s", U_("unable to initialize sudoers default values"));
|
||||
init_parser(sp->opath, path_sudoers, &parser_conf);
|
||||
init_parser(sp->opath, &parser_conf);
|
||||
sp->errorline = -1;
|
||||
|
||||
/* Parse the sudoers temp file(s) */
|
||||
@@ -1071,7 +1072,7 @@ check_syntax(const char *path, bool quiet, bool strict, bool check_owner,
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
init_parser(fname, path, &parser_conf);
|
||||
init_parser(fname, &parser_conf);
|
||||
sudoers_setlocale(SUDOERS_LOCALE_SUDOERS, &oldlocale);
|
||||
if (sudoersparse() && !parse_error) {
|
||||
if (!quiet)
|
||||
|
Reference in New Issue
Block a user