Make alias_apply() take 3 arguments, the first being a pointer to the

struct sudoers_parse_tree.
This commit is contained in:
Todd C. Miller
2018-08-24 09:52:53 -06:00
parent 4b3c8a73a0
commit b2e3adccf3
6 changed files with 45 additions and 24 deletions

View File

@@ -149,17 +149,42 @@ alias_add(struct sudoers_parse_tree *parse_tree, char *name, int type,
debug_return_str(NULL); debug_return_str(NULL);
} }
/*
* Closure to adapt 2-arg rbapply() to 3-arg alias_apply().
*/
struct alias_apply_closure {
struct sudoers_parse_tree *parse_tree;
int (*func)(struct sudoers_parse_tree *, struct alias *, void *);
void *cookie;
};
/* Adapt rbapply() to alias_apply() calling convention. */
static int
alias_apply_func(void *v1, void *v2)
{
struct alias *a = v1;
struct alias_apply_closure *closure = v2;
return closure->func(closure->parse_tree, a, closure->cookie);
}
/* /*
* Apply a function to each alias entry and pass in a cookie. * Apply a function to each alias entry and pass in a cookie.
*/ */
void void
alias_apply(struct sudoers_parse_tree *parse_tree, int (*func)(void *, void *), alias_apply(struct sudoers_parse_tree *parse_tree,
int (*func)(struct sudoers_parse_tree *, struct alias *, void *),
void *cookie) void *cookie)
{ {
struct alias_apply_closure closure;
debug_decl(alias_apply, SUDOERS_DEBUG_ALIAS) debug_decl(alias_apply, SUDOERS_DEBUG_ALIAS)
if (parse_tree->aliases != NULL) if (parse_tree->aliases != NULL) {
rbapply(parse_tree->aliases, func, cookie, inorder); closure.parse_tree = parse_tree;
closure.func = func;
closure.cookie = cookie;
rbapply(parse_tree->aliases, alias_apply_func, &closure, inorder);
}
debug_return; debug_return;
} }

View File

@@ -849,10 +849,10 @@ print_defaults_sudoers(struct sudo_lbuf *lbuf, bool expand_aliases)
} }
static int static int
print_alias_sudoers(void *v1, void *v2) print_alias_sudoers(struct sudoers_parse_tree *parse_tree, struct alias *a,
void *v)
{ {
struct alias *a = v1; struct sudo_lbuf *lbuf = v;
struct sudo_lbuf *lbuf = v2;
struct member *m; struct member *m;
debug_decl(print_alias_sudoers, SUDOERS_DEBUG_UTIL) debug_decl(print_alias_sudoers, SUDOERS_DEBUG_UTIL)
@@ -861,7 +861,7 @@ print_alias_sudoers(void *v1, void *v2)
TAILQ_FOREACH(m, &a->members, entries) { TAILQ_FOREACH(m, &a->members, entries) {
if (m != TAILQ_FIRST(&a->members)) if (m != TAILQ_FIRST(&a->members))
sudo_lbuf_append(lbuf, ", "); sudo_lbuf_append(lbuf, ", ");
sudoers_format_member(lbuf, &parsed_policy, m, NULL, UNSPEC); sudoers_format_member(lbuf, parse_tree, m, NULL, UNSPEC);
} }
sudo_lbuf_append(lbuf, "\n"); sudo_lbuf_append(lbuf, "\n");
@@ -1199,11 +1199,11 @@ alias_remove_unused(void)
/* /*
* Prune out non-matching entries from user and host aliases. * Prune out non-matching entries from user and host aliases.
*/ */
int static int
alias_prune_helper(void *v, void *cookie) alias_prune_helper(struct sudoers_parse_tree *parse_tree, struct alias *a,
void *v)
{ {
struct alias *a = v; struct cvtsudoers_config *conf = v;
struct cvtsudoers_config *conf = cookie;
/* XXX - misue of these functions */ /* XXX - misue of these functions */
switch (a->type) { switch (a->type) {

View File

@@ -519,11 +519,10 @@ print_member_json(FILE *fp, struct member *m, enum word_type word_type,
* Callback for alias_apply() to print an alias entry if it matches * Callback for alias_apply() to print an alias entry if it matches
* the type specified in the closure. * the type specified in the closure.
*/ */
int static int
print_alias_json(void *v1, void *v2) print_alias_json(struct sudoers_parse_tree *parse_tree, struct alias *a, void *v)
{ {
struct alias *a = v1; struct json_alias_closure *closure = v;
struct json_alias_closure *closure = v2;
struct member *m; struct member *m;
debug_decl(print_alias_json, SUDOERS_DEBUG_UTIL) debug_decl(print_alias_json, SUDOERS_DEBUG_UTIL)

View File

@@ -276,7 +276,7 @@ const char *alias_type_to_string(int alias_type);
struct alias *alias_get(struct sudoers_parse_tree *parse_tree, const char *name, int type); struct alias *alias_get(struct sudoers_parse_tree *parse_tree, const char *name, int type);
struct alias *alias_remove(struct sudoers_parse_tree *parse_tree, char *name, int type); struct alias *alias_remove(struct sudoers_parse_tree *parse_tree, char *name, int type);
bool alias_find_used(struct sudoers_parse_tree *parse_tree, struct rbtree *used_aliases); bool alias_find_used(struct sudoers_parse_tree *parse_tree, struct rbtree *used_aliases);
void alias_apply(struct sudoers_parse_tree *parse_tree, int (*func)(void *, void *), void *cookie); void alias_apply(struct sudoers_parse_tree *parse_tree, int (*func)(struct sudoers_parse_tree *, struct alias *, void *), void *cookie);
void alias_free(void *a); void alias_free(void *a);
void alias_put(struct alias *a); void alias_put(struct alias *a);

View File

@@ -491,10 +491,9 @@ print_defaults(struct sudo_lbuf *lbuf)
} }
static int static int
print_alias(void *v1, void *v2) print_alias(struct sudoers_parse_tree *parse_tree, struct alias *a, void *v)
{ {
struct alias *a = v1; struct sudo_lbuf *lbuf = v;
struct sudo_lbuf *lbuf = v2;
struct member *m; struct member *m;
debug_decl(print_alias, SUDOERS_DEBUG_UTIL) debug_decl(print_alias, SUDOERS_DEBUG_UTIL)
@@ -503,7 +502,7 @@ print_alias(void *v1, void *v2)
TAILQ_FOREACH(m, &a->members, entries) { TAILQ_FOREACH(m, &a->members, entries) {
if (m != TAILQ_FIRST(&a->members)) if (m != TAILQ_FIRST(&a->members))
sudo_lbuf_append(lbuf, ", "); sudo_lbuf_append(lbuf, ", ");
sudoers_format_member(lbuf, &parsed_policy, m, NULL, UNSPEC); sudoers_format_member(lbuf, parse_tree, m, NULL, UNSPEC);
} }
sudo_lbuf_append(lbuf, "\n"); sudo_lbuf_append(lbuf, "\n");

View File

@@ -90,7 +90,7 @@ static char *get_editor(int *editor_argc, char ***editor_argv);
static bool check_syntax(const char *, bool, bool, bool); static bool check_syntax(const char *, bool, bool, bool);
static bool edit_sudoers(struct sudoersfile *, char *, int, char **, int); static bool edit_sudoers(struct sudoersfile *, char *, int, char **, int);
static bool install_sudoers(struct sudoersfile *, bool); static bool install_sudoers(struct sudoersfile *, bool);
static int print_unused(void *, void *); static int print_unused(struct sudoers_parse_tree *, struct alias *, void *);
static bool reparse_sudoers(char *, int, char **, bool, bool); static bool reparse_sudoers(char *, int, char **, bool, bool);
static int run_command(char *, char **); static int run_command(char *, char **);
static void parse_sudoers_options(void); static void parse_sudoers_options(void);
@@ -1131,10 +1131,8 @@ check_aliases(bool strict, bool quiet)
} }
static int static int
print_unused(void *v1, void *v2) print_unused(struct sudoers_parse_tree *parse_tree, struct alias *a, void *v)
{ {
struct alias *a = (struct alias *)v1;
fprintf(stderr, U_("Warning: %s:%d unused %s \"%s\""), fprintf(stderr, U_("Warning: %s:%d unused %s \"%s\""),
a->file, a->lineno, alias_type_to_string(a->type), a->name); a->file, a->lineno, alias_type_to_string(a->type), a->name);
fputc('\n', stderr); fputc('\n', stderr);