]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add the prefix of the root module onto the name of thread instance data
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 9 Apr 2022 05:19:53 +0000 (00:19 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 9 Apr 2022 05:20:18 +0000 (00:20 -0500)
src/bin/radclient.c
src/lib/server/module.c
src/lib/server/module.h

index 7fc7145f97d979e6e4bcc023665530d6fd361e4e..6be1f434241c2cc303ac1ee3e76d534b41c8f41c 100644 (file)
@@ -1108,7 +1108,9 @@ int main(int argc, char **argv)
        int             parallel = 1;
        rc_request_t    *this;
        int             force_af = AF_UNSPEC;
+#ifndef NDEBUG
        TALLOC_CTX      *autofree;
+#endif
        fr_rb_tree_t    *filename_tree = NULL;
 
        /*
@@ -1124,9 +1126,9 @@ int main(int argc, char **argv)
         */
        fr_atexit_global_setup();
 
+#ifndef NDEBUG
        autofree = talloc_autofree_context();
 
-#ifndef NDEBUG
        if (fr_fault_setup(autofree, getenv("PANIC_ACTION"), argv[0]) < 0) {
                fr_perror("radclient");
                fr_exit_now(EXIT_FAILURE);
@@ -1621,6 +1623,10 @@ int main(int argc, char **argv)
 
        fr_dict_autofree(radclient_dict);
 
+#ifndef NDEBUG
+       talloc_free(autofree);
+#endif
+
        if (do_summary) {
                fr_perror("Packet summary:\n"
                      "\tAccepted      : %" PRIu64 "\n"
index 4a5565c099a25a0d3e403b4a8416d63f44aacb63..fe9c8a5a73261345845ea8c49b49bd1603304f40 100644 (file)
@@ -228,8 +228,8 @@ static int cmd_set_module_status(UNUSED FILE *fp, FILE *fp_err, void *ctx, fr_cm
  */
 static int8_t _module_instance_global_cmp(void const *one, void const *two)
 {
-       module_instance_t const *a = talloc_get_type_abort(one, module_instance_t);
-       module_instance_t const *b = talloc_get_type_abort(two, module_instance_t);
+       module_instance_t const *a = talloc_get_type_abort_const(one, module_instance_t);
+       module_instance_t const *b = talloc_get_type_abort_const(two, module_instance_t);
        int8_t ret;
 
        fr_assert(a->ml && b->ml);
@@ -410,6 +410,28 @@ module_instance_t *module_parent(module_instance_t const *child)
        return module_by_data(child->ml, parent->data);
 }
 
+/** Find the module's shallowest parent
+ *
+ * @param[in] child    to locate the root for.
+ * @return
+ *     - The module's shallowest parent.
+ *     - NULL on error.
+ */
+module_instance_t *module_root(module_instance_t const *child)
+{
+       module_instance_t *parent = NULL;
+       module_instance_t *next;
+
+       for (;;) {
+               next = module_parent(child);
+               if (!next) break;
+
+               parent = next;
+       }
+
+       return parent;
+}
+
 /** Find an existing module instance by its private instance data
  *
  * @param[in] ml       to search in.
@@ -594,7 +616,7 @@ int modules_thread_instantiate(TALLOC_CTX *ctx, module_list_t const *ml, fr_even
        for (instance = fr_rb_iter_init_inorder(&iter, ml->name_tree);
             instance;
             instance = fr_rb_iter_next_inorder(&iter)) {
-               module_instance_t               *mi = talloc_get_type_abort(instance, module_instance_t);
+               module_instance_t               *mi = talloc_get_type_abort(instance, module_instance_t), *rmi;
                module_thread_instance_t        *ti;
                TALLOC_CTX                      *our_ctx = ctx;
 
@@ -611,6 +633,8 @@ int modules_thread_instantiate(TALLOC_CTX *ctx, module_list_t const *ml, fr_even
                if (mi->module->thread_inst_size) {
                        MEM(ti->data = talloc_zero_array(ti, uint8_t, mi->module->thread_inst_size));
 
+                       rmi = module_root(mi);
+
                        /*
                         *      Fixup the type name, incase something calls
                         *      talloc_get_type_abort() on it...
@@ -618,7 +642,9 @@ int modules_thread_instantiate(TALLOC_CTX *ctx, module_list_t const *ml, fr_even
                        if (!mi->module->thread_inst_type) {
                                talloc_set_name(ti->data, "%s_%s_thread_t",
                                                fr_table_str_by_value(dl_module_type_prefix,
-                                                                     mi->dl_inst->module->type, "<INVALID>"),
+                                                                     rmi ? rmi->dl_inst->module->type :
+                                                                           mi->dl_inst->module->type,
+                                                                     "<INVALID>"),
                                                mi->module->name);
                        } else {
                                talloc_set_name_const(ti->data, mi->module->thread_inst_type);
@@ -942,7 +968,10 @@ module_instance_t *module_alloc(module_list_t *ml,
         *      Takes the inst_name and adds qualifiers
         *      if this is a submodule.
         */
-       module_instance_name(NULL, &qual_inst_name, ml, parent, inst_name);
+       if (module_instance_name(NULL, &qual_inst_name, ml, parent, inst_name) < 0) {
+               ERROR("Module name too long");
+               return NULL;
+       }
 
        /*
         *      See if the module already exists.
index 41f0efdb68564a751950e1b21f75eb5b94d3f2c6..faff657d85353bc3f29e3f40bf6dfd1f4cebc00c 100644 (file)
@@ -255,6 +255,8 @@ int         module_submodule_parse(UNUSED TALLOC_CTX *ctx, void *out, void *parent,
  */
 module_instance_t      *module_parent(module_instance_t const *child);
 
+module_instance_t      *module_root(module_instance_t const *child);
+
 module_instance_t      *module_by_name(module_list_t const *ml, module_instance_t const *parent, char const *asked_name)
                        CC_HINT(nonnull(1,3));