Make alias_apply() take 3 arguments, the first being a pointer to the
struct sudoers_parse_tree.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
@@ -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) {
|
||||
|
@@ -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)
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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");
|
||||
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user