]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
We need to resume iterating from the previous configuration item
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 15 May 2024 04:58:11 +0000 (22:58 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 15 May 2024 04:58:11 +0000 (22:58 -0600)
src/lib/server/cf_util.c
src/lib/server/cf_util.h
src/lib/server/module_rlm.c

index 1bc692893d312bfe6598b70e5a18dca94ec5319c..fdf7dc6238664fa92c8566a241157e776d5e0d53 100644 (file)
@@ -499,19 +499,34 @@ CONF_ITEM *_cf_item_remove(CONF_ITEM *parent, CONF_ITEM *child)
        return prev;
 }
 
+/** Return the next child of the CONF_ITEM
+ *
+ * @param[in] ci       to return children from.
+ * @param[in] curr     child to start searching from.
+ * @return
+ *     - The next #CONF_ITEM that's a child of cs.
+ *     - NULL if no more #CONF_ITEM.
+ */
+CONF_ITEM *_cf_item_next(CONF_ITEM const *ci, CONF_ITEM const *curr)
+{
+       if (!ci) return NULL;
+
+       return fr_dlist_next(&ci->children, curr);
+}
+
 /** Return the next child of cs
  *
  * @param[in] ci       to return children from.
- * @param[in] prev     child to start searching from.
+ * @param[in] curr     child to start searching from.
  * @return
  *     - The next #CONF_ITEM that's a child of cs.
  *     - NULL if no more #CONF_ITEM.
  */
-CONF_ITEM *_cf_item_next(CONF_ITEM const *ci, CONF_ITEM const *prev)
+CONF_ITEM *_cf_item_prev(CONF_ITEM const *ci, CONF_ITEM const *curr)
 {
        if (!ci) return NULL;
 
-       return fr_dlist_next(&ci->children, prev);
+       return fr_dlist_prev(&ci->children, curr);
 }
 
 /** Initialize a CONF_ITEM, so we don't have repeated code
index a1e3d0560cb160ef8efe39e9e7d0d7f0f7b8bbd3..728fb0be698967c42b789b04bd33b0e7a41d3296 100644 (file)
@@ -89,8 +89,11 @@ void         _cf_item_insert_after(CONF_ITEM *parent, CONF_ITEM *prev, CONF_ITEM *child
 #define                cf_item_remove(_parent, _child) _cf_item_remove(CF_TO_ITEM(_parent), CF_TO_ITEM(_child))
 CONF_ITEM      *_cf_item_remove(CONF_ITEM *parent, CONF_ITEM *child);
 
-#define                cf_item_next(_ci, _prev) _cf_item_next(CF_TO_ITEM(_ci), _prev)
-CONF_ITEM      *_cf_item_next(CONF_ITEM const *ci, CONF_ITEM const *prev);
+#define                cf_item_next(_ci, _curr) _cf_item_next(CF_TO_ITEM(_ci), _curr)
+CONF_ITEM      *_cf_item_next(CONF_ITEM const *ci, CONF_ITEM const *curr);
+
+#define                cf_item_prev(_ci, _curr) _cf_item_prev(CF_TO_ITEM(_ci), _curr)
+CONF_ITEM      *_cf_item_prev(CONF_ITEM const *ci, CONF_ITEM const *prev);
 
 #define                cf_root(_cf) _cf_root(CF_TO_ITEM(_cf))
 CONF_SECTION   *_cf_root(CONF_ITEM const *ci);
index e9541796c6c03b92f7425bb96f31c6b178629ccb..66e5e2e1db12bd84959ad9f144cffc6097739b8a 100644 (file)
@@ -1069,7 +1069,7 @@ int modules_rlm_bootstrap(CONF_SECTION *root)
        if (!static_cs) {
                static_cs = cf_section_alloc(modules, NULL, "static", NULL);
                cf_section_foreach(modules, mod_cs) {
-                       CONF_SECTION *prev;
+                       CONF_ITEM *prev;
 
                        /*
                         *      Skip over the dynamic section
@@ -1082,9 +1082,18 @@ int modules_rlm_bootstrap(CONF_SECTION *root)
                         *      the dynamic section into the static
                         *      section for backwards compatibility.
                         */
-                       prev = cf_item_to_section(cf_item_remove(modules, mod_cs));
+                       prev = cf_item_remove(modules, mod_cs);
                        cf_item_add(static_cs, mod_cs);
-                       mod_cs = prev;
+
+                       /*
+                        *      Find the previous item that's a section
+                        */
+                       while (prev && !cf_item_is_section(prev)) prev = cf_item_prev(modules, prev);
+
+                       /*
+                        *      Resume iterating from that item
+                        */
+                       mod_cs = cf_item_to_section(prev);
                }
                cf_item_add(modules, static_cs);
        }