simplify iterator

This commit is contained in:
Todd C. Miller
2018-02-10 04:29:43 -07:00
parent 6e2a267060
commit 34820c6b15
4 changed files with 10 additions and 15 deletions

View File

@@ -2312,12 +2312,11 @@ sudo_ldap_display_bound_defaults(struct sudo_nss *nss, struct passwd *pw,
} }
static char * static char *
berval_iter(void *base, void **save) berval_iter(void **vp)
{ {
struct berval **bv; struct berval **bv = *vp;
bv = *save ? *save : base; *vp = bv + 1;
*save = bv + 1;
return *bv ? (*bv)->bv_val : NULL; return *bv ? (*bv)->bv_val : NULL;
} }

View File

@@ -121,7 +121,6 @@ array_to_member_list(void *a, sudo_ldap_iter_t iter)
{ {
struct member_list *members; struct member_list *members;
struct member *m; struct member *m;
void *save = NULL;
char *val; char *val;
debug_decl(bv_to_member_list, SUDOERS_DEBUG_LDAP) 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; return NULL;
TAILQ_INIT(members); TAILQ_INIT(members);
while ((val = iter(a, &save)) != NULL) { while ((val = iter(&a)) != NULL) {
if ((m = calloc(1, sizeof(*m))) == NULL) if ((m = calloc(1, sizeof(*m))) == NULL)
goto bad; goto bad;
@@ -180,7 +179,6 @@ sudo_ldap_role_to_priv(const char *cn, void *runasusers, void *runasgroups,
struct sudo_command *c; struct sudo_command *c;
struct privilege *priv; struct privilege *priv;
struct member *m; struct member *m;
void *cmnds_save = NULL;
char *cmnd; char *cmnd;
debug_decl(sudo_ldap_role_to_priv, SUDOERS_DEBUG_LDAP) 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. * Parse sudoCommands and add to cmndlist.
*/ */
while ((cmnd = iter(cmnds, &cmnds_save)) != NULL) { while ((cmnd = iter(&cmnds)) != NULL) {
char *args; char *args;
/* Allocate storage upfront. */ /* Allocate storage upfront. */
@@ -275,10 +273,9 @@ sudo_ldap_role_to_priv(const char *cn, void *runasusers, void *runasgroups,
/* Parse sudoOptions. */ /* Parse sudoOptions. */
if (opts != NULL) { if (opts != NULL) {
void *opts_save = NULL;
char *opt; char *opt;
while ((opt = iter(opts, &opts_save)) != NULL) { while ((opt = iter(&opts)) != NULL) {
char *var, *val; char *var, *val;
int op; int op;

View File

@@ -1409,12 +1409,11 @@ sudo_sss_display_bound_defaults(struct sudo_nss *nss,
} }
static char * 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; *vp = val_array + 1;
*save = val_array + 1;
return *val_array; return *val_array;
} }

View File

@@ -17,7 +17,7 @@
#ifndef SUDOERS_LDAP_H #ifndef SUDOERS_LDAP_H
#define 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); bool sudo_ldap_is_negated(char **valp);
int sudo_ldap_parse_option(char *optstr, char **varp, char **valp); int sudo_ldap_parse_option(char *optstr, char **varp, char **valp);