From: Alan T. DeKok Date: Mon, 25 Dec 2023 13:07:26 +0000 (-0500) Subject: move to internal function for things which don't need to be public X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b0e8febb00be00667da72f3dafe695310c11c7ab;p=thirdparty%2Ffreeradius-server.git move to internal function for things which don't need to be public --- diff --git a/src/lib/server/users_file.c b/src/lib/server/users_file.c index df315d70ce1..11e47faaf3f 100644 --- a/src/lib/server/users_file.c +++ b/src/lib/server/users_file.c @@ -37,6 +37,9 @@ RCSID("$Id$") #include #include +static int pairlist_read_internal(TALLOC_CTX *ctx, fr_dict_t const *dict, char const *file, PAIR_LIST_LIST *list, + bool complain, int *order); + static inline void line_error_marker(char const *src_file, int src_line, char const *user_file, int user_line, fr_sbuff_t *sbuff, char const *error) @@ -146,7 +149,7 @@ static fr_sbuff_parse_rules_t const rhs_term = { * Caller saw a $INCLUDE at the start of a line. */ static int users_include(TALLOC_CTX *ctx, fr_dict_t const *dict, fr_sbuff_t *sbuff, PAIR_LIST_LIST *list, - char const *file, int lineno) + char const *file, int lineno, int *order) { size_t len; char *newfile, *p, c; @@ -226,7 +229,7 @@ static int users_include(TALLOC_CTX *ctx, fr_dict_t const *dict, fr_sbuff_t *sbu /* * Read the $INCLUDEd file recursively. */ - if (pairlist_read(ctx, dict, newfile, list, 0) != 0) { + if (pairlist_read_internal(ctx, dict, newfile, list, false, order) != 0) { ERROR("%s[%d]: Could not read included file %s: %s", file, lineno, newfile, fr_syserror(errno)); talloc_free(newfile); @@ -237,14 +240,19 @@ static int users_include(TALLOC_CTX *ctx, fr_dict_t const *dict, fr_sbuff_t *sbu return 0; } +int pairlist_read(TALLOC_CTX *ctx, fr_dict_t const *dict, char const *file, PAIR_LIST_LIST *list) +{ + int order = 0; + + return pairlist_read_internal(ctx, dict, file, list, true, &order); +} /* * Read the users file. Return a PAIR_LIST. */ -int pairlist_read(TALLOC_CTX *ctx, fr_dict_t const *dict, char const *file, PAIR_LIST_LIST *list, int complain) +static int pairlist_read_internal(TALLOC_CTX *ctx, fr_dict_t const *dict, char const *file, PAIR_LIST_LIST *list, bool complain, int *order) { char *q; - int order = 0; int lineno = 1; map_t *new_map, *relative_map; FILE *fp; @@ -261,9 +269,7 @@ int pairlist_read(TALLOC_CTX *ctx, fr_dict_t const *dict, char const *file, PAIR * more useful... */ if ((fp = fopen(file, "r")) == NULL) { - if (!complain) return -1; - - ERROR("Couldn't open %s for reading: %s", file, fr_syserror(errno)); + if (complain) ERROR("Couldn't open %s for reading: %s", file, fr_syserror(errno)); return -1; } @@ -338,19 +344,14 @@ int pairlist_read(TALLOC_CTX *ctx, fr_dict_t const *dict, char const *file, PAIR PAIR_LIST_LIST tmp_list; pairlist_list_init(&tmp_list); - if (users_include(ctx, dict, &sbuff, &tmp_list, file, lineno) < 0) goto fail; + if (users_include(ctx, dict, &sbuff, &tmp_list, file, lineno, order) < 0) goto fail; /* * The file may have read no entries, one * entry, or it may be a linked list of - * entries. Set the order of the entries - * then move them to the end of the main list. + * entries. Move the to the end of the + * main list. */ - t = NULL; - while ((t = fr_dlist_next(&tmp_list.head, t))) { - t->order = order++; - } - fr_dlist_move(&list->head, &tmp_list.head); if (fr_sbuff_next_if_char(&sbuff, '\n')) { @@ -375,7 +376,7 @@ int pairlist_read(TALLOC_CTX *ctx, fr_dict_t const *dict, char const *file, PAIR map_list_init(&t->reply); t->filename = filename; t->lineno = lineno; - t->order = order++; + t->order = (*order)++; /* * Copy the name from the entry. diff --git a/src/lib/server/users_file.h b/src/lib/server/users_file.h index caf4b8e3bf2..b5e3bd5b144 100644 --- a/src/lib/server/users_file.h +++ b/src/lib/server/users_file.h @@ -54,7 +54,7 @@ typedef struct pair_list_list { } PAIR_LIST_LIST; /* users_file.c */ -int pairlist_read(TALLOC_CTX *ctx, fr_dict_t const *dict, char const *file, PAIR_LIST_LIST *list, int complain); +int pairlist_read(TALLOC_CTX *ctx, fr_dict_t const *dict, char const *file, PAIR_LIST_LIST *list); void pairlist_free(PAIR_LIST_LIST *); static inline void pairlist_list_init(PAIR_LIST_LIST *list) diff --git a/src/modules/rlm_attr_filter/rlm_attr_filter.c b/src/modules/rlm_attr_filter/rlm_attr_filter.c index a76f4cf6fcd..ce29cd97f8b 100644 --- a/src/modules/rlm_attr_filter/rlm_attr_filter.c +++ b/src/modules/rlm_attr_filter/rlm_attr_filter.c @@ -106,7 +106,7 @@ static int attr_filter_getfile(TALLOC_CTX *ctx, module_inst_ctx_t const *mctx, c PAIR_LIST *entry = NULL; map_t *map; - rcode = pairlist_read(ctx, dict_radius, filename, pair_list, 1); + rcode = pairlist_read(ctx, dict_radius, filename, pair_list); if (rcode < 0) { return -1; } diff --git a/src/modules/rlm_files/rlm_files.c b/src/modules/rlm_files/rlm_files.c index 90009e23581..bbf6d3be99b 100644 --- a/src/modules/rlm_files/rlm_files.c +++ b/src/modules/rlm_files/rlm_files.c @@ -133,7 +133,7 @@ static int getrecv_filename(TALLOC_CTX *ctx, char const *filename, fr_htrie_t ** } pairlist_list_init(&users); - rcode = pairlist_read(ctx, dict_radius, filename, &users, 1); + rcode = pairlist_read(ctx, dict_radius, filename, &users); if (rcode < 0) { return -1; }