From: Todd C. Miller Date: Wed, 21 Mar 2018 19:29:47 +0000 (-0600) Subject: Move cvtsudoers string functions into cvtsudoers.c X-Git-Tag: SUDO_1_8_23^2~71 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bbd3e558b14002583d9cc4d27145fe08ef96bcde;p=sudo Move cvtsudoers string functions into cvtsudoers.c --- diff --git a/plugins/sudoers/cvtsudoers.c b/plugins/sudoers/cvtsudoers.c index cbbc0803e..dfa220e3e 100644 --- a/plugins/sudoers/cvtsudoers.c +++ b/plugins/sudoers/cvtsudoers.c @@ -77,7 +77,7 @@ static void help(void) __attribute__((__noreturn__)); static void usage(int); static bool convert_sudoers_sudoers(const char *output_file, struct cvtsudoers_config *conf); static bool parse_sudoers(const char *input_file, struct cvtsudoers_config *conf); -static bool parse_filter(char *expression); +static bool cvtsudoers_parse_filter(char *expression); static bool alias_remove_unused(void); static struct cvtsudoers_config *cvtsudoers_conf_read(const char *conf_file); static void cvtsudoers_conf_free(struct cvtsudoers_config *conf); @@ -236,7 +236,7 @@ main(int argc, char *argv[]) } if (conf->filter != NULL) { /* We always expand aliases when filtering (may change in future). */ - if (!parse_filter(conf->filter)) + if (!cvtsudoers_parse_filter(conf->filter)) usage(1); } @@ -437,10 +437,10 @@ cvtsudoers_conf_free(struct cvtsudoers_config *conf) } static bool -parse_filter(char *expression) +cvtsudoers_parse_filter(char *expression) { char *last = NULL, *cp = expression; - debug_decl(parse_filter, SUDOERS_DEBUG_UTIL) + debug_decl(cvtsudoers_parse_filter, SUDOERS_DEBUG_UTIL) if (filters == NULL) { if ((filters = malloc(sizeof(*filters))) == NULL) { @@ -490,6 +490,59 @@ parse_filter(char *expression) debug_return_bool(true); } +struct cvtsudoers_string * +cvtsudoers_string_alloc(const char *s) +{ + struct cvtsudoers_string *ls; + debug_decl(cvtsudoers_string_alloc, SUDOERS_DEBUG_UTIL) + + if ((ls = malloc(sizeof(*ls))) != NULL) { + if ((ls->str = strdup(s)) == NULL) { + free(ls); + ls = NULL; + } + } + + debug_return_ptr(ls); +} + +void +cvtsudoers_string_free(struct cvtsudoers_string *ls) +{ + free(ls->str); + free(ls); +} + +struct cvtsudoers_str_list * +str_list_alloc(void) +{ + struct cvtsudoers_str_list *strlist; + debug_decl(str_list_alloc, SUDOERS_DEBUG_UTIL) + + strlist = malloc(sizeof(*strlist)); + STAILQ_INIT(strlist); + strlist->refcnt = 1; + + debug_return_ptr(strlist); +} + +void +str_list_free(void *v) +{ + struct cvtsudoers_str_list *strlist = v; + struct cvtsudoers_string *first; + debug_decl(str_list_free, SUDOERS_DEBUG_UTIL) + + if (--strlist->refcnt == 0) { + while ((first = STAILQ_FIRST(strlist)) != NULL) { + STAILQ_REMOVE_HEAD(strlist, entries); + cvtsudoers_string_free(first); + } + free(strlist); + } + debug_return; +} + static bool parse_sudoers(const char *input_file, struct cvtsudoers_config *conf) { diff --git a/plugins/sudoers/cvtsudoers.h b/plugins/sudoers/cvtsudoers.h index efce454fd..acc356576 100644 --- a/plugins/sudoers/cvtsudoers.h +++ b/plugins/sudoers/cvtsudoers.h @@ -26,7 +26,6 @@ enum sudoers_formats { /* * Simple string list with optional reference count. - * XXX - move this so fmtsudoers can use it */ struct cvtsudoers_string { STAILQ_ENTRY(cvtsudoers_string) entries; diff --git a/plugins/sudoers/cvtsudoers_ldif.c b/plugins/sudoers/cvtsudoers_ldif.c index c9ef0731f..6bc8685c3 100644 --- a/plugins/sudoers/cvtsudoers_ldif.c +++ b/plugins/sudoers/cvtsudoers_ldif.c @@ -528,60 +528,6 @@ struct sudo_role { }; STAILQ_HEAD(sudo_role_list, sudo_role); -/* XXX - move to cvtsudoers.c */ -struct cvtsudoers_string * -cvtsudoers_string_alloc(const char *s) -{ - struct cvtsudoers_string *ls; - debug_decl(cvtsudoers_string_alloc, SUDOERS_DEBUG_UTIL) - - if ((ls = malloc(sizeof(*ls))) != NULL) { - if ((ls->str = strdup(s)) == NULL) { - free(ls); - ls = NULL; - } - } - - debug_return_ptr(ls); -} - -void -cvtsudoers_string_free(struct cvtsudoers_string *ls) -{ - free(ls->str); - free(ls); -} - -struct cvtsudoers_str_list * -str_list_alloc(void) -{ - struct cvtsudoers_str_list *strlist; - debug_decl(str_list_alloc, SUDOERS_DEBUG_UTIL) - - strlist = malloc(sizeof(*strlist)); - STAILQ_INIT(strlist); - strlist->refcnt = 1; - - debug_return_ptr(strlist); -} - -void -str_list_free(void *v) -{ - struct cvtsudoers_str_list *strlist = v; - struct cvtsudoers_string *first; - debug_decl(str_list_free, SUDOERS_DEBUG_UTIL) - - if (--strlist->refcnt == 0) { - while ((first = STAILQ_FIRST(strlist)) != NULL) { - STAILQ_REMOVE_HEAD(strlist, entries); - cvtsudoers_string_free(first); - } - free(strlist); - } - debug_return; -} - static struct sudo_role * sudo_role_alloc(void) { @@ -677,7 +623,7 @@ ldif_store_string(const char *str, struct cvtsudoers_str_list *strlist, bool sor * Takes a pointer to a struct cvtsudoers_string *. * Returns the string or NULL if we've reached the end. */ -char * +static char * cvtsudoers_string_iter(void **vp) { struct cvtsudoers_string *ls = *vp;