struct sudoers_parse_tree.
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;
}
}
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)
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");
/*
* 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) {
* 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)
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);
}
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)
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");
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);
}
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);