]> granicus.if.org Git - sudo/commitdiff
Make alias_apply() take 3 arguments, the first being a pointer to the
authorTodd C. Miller <Todd.Miller@sudo.ws>
Fri, 24 Aug 2018 15:52:53 +0000 (09:52 -0600)
committerTodd C. Miller <Todd.Miller@sudo.ws>
Fri, 24 Aug 2018 15:52:53 +0000 (09:52 -0600)
struct sudoers_parse_tree.

plugins/sudoers/alias.c
plugins/sudoers/cvtsudoers.c
plugins/sudoers/cvtsudoers_json.c
plugins/sudoers/parse.h
plugins/sudoers/testsudoers.c
plugins/sudoers/visudo.c

index c66241159aa76a30c7dec5b8c52c8d39208613a6..d80dcfc97ee8ac9903f482a03870bf1735828217 100644 (file)
@@ -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;
 }
index e086d7debc01ae937325bf9d1ef81b94498cab84..ad0e374f09e6ef12a8480e9ea4d11991a8ab31d4 100644 (file)
@@ -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) {
index 7ca59850e6cced97a8976a5cde284957ac641b44..15942966e805d4ac076cf7df5ce3eb00a343ee30 100644 (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
  * 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)
 
index 519677edb9bf4712ba1fa6ba1c048b8c2add3153..b8b2497ad300c4651cec3cc4ea457fda28771ae0 100644 (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_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);
 
index 489a4b3d818a8ea89a4e93fa05bc6af92cad18c8..8b4f8e5130b2b36f1724306a10a661e1abe8fd1d 100644 (file)
@@ -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");
 
index 0366cd40aeeca454c12ea8558295d2e93aa401a9..304846995862053fbb24872ce6af30d3f4b56d90 100644 (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 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);