]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
move to internal function for things which don't need to be public
authorAlan T. DeKok <aland@freeradius.org>
Mon, 25 Dec 2023 13:07:26 +0000 (08:07 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 25 Dec 2023 13:07:26 +0000 (08:07 -0500)
src/lib/server/users_file.c
src/lib/server/users_file.h
src/modules/rlm_attr_filter/rlm_attr_filter.c
src/modules/rlm_files/rlm_files.c

index df315d70ce18ec61ad812cc1b7ed01e1b576f13e..11e47faaf3f666ac51569ad805c13cd3b800fa19 100644 (file)
@@ -37,6 +37,9 @@ RCSID("$Id$")
 #include <ctype.h>
 #include <fcntl.h>
 
+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.
index caf4b8e3bf22c1f9b645026dbc2ad7bba84b0113..b5e3bd5b144a50be75972aaa737525d42fe5d024 100644 (file)
@@ -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)
index a76f4cf6fcd0a6277dcdca687b9ad0c6792f76cf..ce29cd97f8bc39c1104101d53ff5c3b6280f0efd 100644 (file)
@@ -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;
        }
index 90009e23581a6ee35ae651f6b4e0487eb8632fcc..bbf6d3be99bc95ccba67592e1035995b61f22211 100644 (file)
@@ -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;
        }