From: Todd C. Miller Date: Sat, 10 Feb 2018 11:29:43 +0000 (-0700) Subject: simplify iterator X-Git-Tag: SUDO_1_8_23^2~138 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=34820c6b15e0fc64d1e2fdd49a88cf99f404d487;p=sudo simplify iterator --- diff --git a/plugins/sudoers/ldap.c b/plugins/sudoers/ldap.c index 9498454f2..011de2d4c 100644 --- a/plugins/sudoers/ldap.c +++ b/plugins/sudoers/ldap.c @@ -2312,12 +2312,11 @@ sudo_ldap_display_bound_defaults(struct sudo_nss *nss, struct passwd *pw, } static char * -berval_iter(void *base, void **save) +berval_iter(void **vp) { - struct berval **bv; + struct berval **bv = *vp; - bv = *save ? *save : base; - *save = bv + 1; + *vp = bv + 1; return *bv ? (*bv)->bv_val : NULL; } diff --git a/plugins/sudoers/ldap_common.c b/plugins/sudoers/ldap_common.c index 144d24e91..71793e96c 100644 --- a/plugins/sudoers/ldap_common.c +++ b/plugins/sudoers/ldap_common.c @@ -121,7 +121,6 @@ array_to_member_list(void *a, sudo_ldap_iter_t iter) { struct member_list *members; struct member *m; - void *save = NULL; char *val; debug_decl(bv_to_member_list, SUDOERS_DEBUG_LDAP) @@ -129,7 +128,7 @@ array_to_member_list(void *a, sudo_ldap_iter_t iter) return NULL; TAILQ_INIT(members); - while ((val = iter(a, &save)) != NULL) { + while ((val = iter(&a)) != NULL) { if ((m = calloc(1, sizeof(*m))) == NULL) goto bad; @@ -180,7 +179,6 @@ sudo_ldap_role_to_priv(const char *cn, void *runasusers, void *runasgroups, struct sudo_command *c; struct privilege *priv; struct member *m; - void *cmnds_save = NULL; char *cmnd; debug_decl(sudo_ldap_role_to_priv, SUDOERS_DEBUG_LDAP) @@ -203,7 +201,7 @@ sudo_ldap_role_to_priv(const char *cn, void *runasusers, void *runasgroups, /* * Parse sudoCommands and add to cmndlist. */ - while ((cmnd = iter(cmnds, &cmnds_save)) != NULL) { + while ((cmnd = iter(&cmnds)) != NULL) { char *args; /* Allocate storage upfront. */ @@ -275,10 +273,9 @@ sudo_ldap_role_to_priv(const char *cn, void *runasusers, void *runasgroups, /* Parse sudoOptions. */ if (opts != NULL) { - void *opts_save = NULL; char *opt; - while ((opt = iter(opts, &opts_save)) != NULL) { + while ((opt = iter(&opts)) != NULL) { char *var, *val; int op; diff --git a/plugins/sudoers/sssd.c b/plugins/sudoers/sssd.c index d932858b3..c0718d385 100644 --- a/plugins/sudoers/sssd.c +++ b/plugins/sudoers/sssd.c @@ -1409,12 +1409,11 @@ sudo_sss_display_bound_defaults(struct sudo_nss *nss, } static char * -val_array_iter(void *base, void **save) +val_array_iter(void **vp) { - char **val_array; + char **val_array = *vp; - val_array = *save ? *save : base; - *save = val_array + 1; + *vp = val_array + 1; return *val_array; } diff --git a/plugins/sudoers/sudo_ldap.h b/plugins/sudoers/sudo_ldap.h index 1eb567943..10286b837 100644 --- a/plugins/sudoers/sudo_ldap.h +++ b/plugins/sudoers/sudo_ldap.h @@ -17,7 +17,7 @@ #ifndef SUDOERS_LDAP_H #define SUDOERS_LDAP_H -typedef char * (*sudo_ldap_iter_t)(void *, void **); +typedef char * (*sudo_ldap_iter_t)(void **); bool sudo_ldap_is_negated(char **valp); int sudo_ldap_parse_option(char *optstr, char **varp, char **valp);