From: Todd C. Miller Date: Fri, 24 Aug 2018 15:52:53 +0000 (-0600) Subject: Make alias_apply() take 3 arguments, the first being a pointer to the X-Git-Tag: SUDO_1_8_25^2~29 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b2e3adccf32bc9004149be154101bbbc0b317fb9;p=sudo Make alias_apply() take 3 arguments, the first being a pointer to the struct sudoers_parse_tree. --- diff --git a/plugins/sudoers/alias.c b/plugins/sudoers/alias.c index c66241159..d80dcfc97 100644 --- a/plugins/sudoers/alias.c +++ b/plugins/sudoers/alias.c @@ -149,17 +149,42 @@ alias_add(struct sudoers_parse_tree *parse_tree, char *name, int type, 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. */ 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) { + struct alias_apply_closure closure; debug_decl(alias_apply, SUDOERS_DEBUG_ALIAS) - if (parse_tree->aliases != NULL) - rbapply(parse_tree->aliases, func, cookie, inorder); + if (parse_tree->aliases != NULL) { + closure.parse_tree = parse_tree; + closure.func = func; + closure.cookie = cookie; + rbapply(parse_tree->aliases, alias_apply_func, &closure, inorder); + } debug_return; } diff --git a/plugins/sudoers/cvtsudoers.c b/plugins/sudoers/cvtsudoers.c index e086d7deb..ad0e374f0 100644 --- a/plugins/sudoers/cvtsudoers.c +++ b/plugins/sudoers/cvtsudoers.c @@ -849,10 +849,10 @@ print_defaults_sudoers(struct sudo_lbuf *lbuf, bool expand_aliases) } 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 = v2; + struct sudo_lbuf *lbuf = v; struct member *m; 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) { if (m != TAILQ_FIRST(&a->members)) 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"); @@ -1199,11 +1199,11 @@ alias_remove_unused(void) /* * Prune out non-matching entries from user and host aliases. */ -int -alias_prune_helper(void *v, void *cookie) +static int +alias_prune_helper(struct sudoers_parse_tree *parse_tree, struct alias *a, + void *v) { - struct alias *a = v; - struct cvtsudoers_config *conf = cookie; + struct cvtsudoers_config *conf = v; /* XXX - misue of these functions */ switch (a->type) { diff --git a/plugins/sudoers/cvtsudoers_json.c b/plugins/sudoers/cvtsudoers_json.c index 7ca59850e..15942966e 100644 --- a/plugins/sudoers/cvtsudoers_json.c +++ b/plugins/sudoers/cvtsudoers_json.c @@ -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 * the type specified in the closure. */ -int -print_alias_json(void *v1, void *v2) +static int +print_alias_json(struct sudoers_parse_tree *parse_tree, struct alias *a, void *v) { - struct alias *a = v1; - struct json_alias_closure *closure = v2; + struct json_alias_closure *closure = v; struct member *m; debug_decl(print_alias_json, SUDOERS_DEBUG_UTIL) diff --git a/plugins/sudoers/parse.h b/plugins/sudoers/parse.h index 519677edb..b8b2497ad 100644 --- a/plugins/sudoers/parse.h +++ b/plugins/sudoers/parse.h @@ -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_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); -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_put(struct alias *a); diff --git a/plugins/sudoers/testsudoers.c b/plugins/sudoers/testsudoers.c index 489a4b3d8..8b4f8e513 100644 --- a/plugins/sudoers/testsudoers.c +++ b/plugins/sudoers/testsudoers.c @@ -491,10 +491,9 @@ print_defaults(struct sudo_lbuf *lbuf) } 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 = v2; + struct sudo_lbuf *lbuf = v; struct member *m; debug_decl(print_alias, SUDOERS_DEBUG_UTIL) @@ -503,7 +502,7 @@ print_alias(void *v1, void *v2) TAILQ_FOREACH(m, &a->members, entries) { if (m != TAILQ_FIRST(&a->members)) 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"); diff --git a/plugins/sudoers/visudo.c b/plugins/sudoers/visudo.c index 0366cd40a..304846995 100644 --- a/plugins/sudoers/visudo.c +++ b/plugins/sudoers/visudo.c @@ -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 edit_sudoers(struct sudoersfile *, char *, int, char **, int); 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 int run_command(char *, char **); static void parse_sudoers_options(void); @@ -1131,10 +1131,8 @@ check_aliases(bool strict, bool quiet) } 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\""), a->file, a->lineno, alias_type_to_string(a->type), a->name); fputc('\n', stderr);