]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add init/free to fr_dict_protocol_t
authorAlan T. DeKok <aland@freeradius.org>
Fri, 26 Jan 2024 21:14:53 +0000 (16:14 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 26 Jan 2024 21:14:53 +0000 (16:14 -0500)
and call them for autoref dictionaries

src/lib/util/dict.h
src/lib/util/dict_fixup.c
src/lib/util/dict_util.c
src/protocols/dhcpv4/base.c
src/protocols/dhcpv4/encode.c
src/protocols/radius/base.c

index d7c2aa635c39d15345b582a4aa2709dd7a690946..0ad1bda348c50556e9d12359321a6485794c017c 100644 (file)
@@ -327,6 +327,14 @@ typedef ssize_t (*fr_dict_attr_decode_func_t)(TALLOC_CTX *ctx, fr_pair_list_t *v
  */
 typedef ssize_t(*fr_dict_attr_encode_func_t)(fr_dbuff_t *dbuff, fr_pair_list_t const *vps);
 
+/** Init / free callbacks
+ *
+ *  Only for "autoref" usage.
+ */
+typedef int (*fr_dict_protocol_init_t)(void);
+typedef void (*fr_dict_protocol_free_t)(void);
+
+
 /** Protocol-specific callbacks in libfreeradius-PROTOCOL
  *
  */
@@ -337,6 +345,10 @@ typedef struct {
        fr_table_num_ordered_t  const *subtype_table;           //!< for "encrypt=1", etc.
        size_t                  subtype_table_len;              //!< length of subtype_table
        fr_dict_attr_valid_func_t attr_valid;                   //!< validation function for new attributes
+
+       fr_dict_protocol_init_t init;                           //!< initialize the library
+       fr_dict_protocol_free_t free;                           //!< free the library
+
        fr_dict_attr_decode_func_t decode;                      //!< for decoding attributes
        fr_dict_attr_encode_func_t encode;                      //!< for encoding attributes
 } fr_dict_protocol_t;
index 408d78f0b338647ddba995a61b0301ab1594842a..d836255926e85c74d88b0502d9383d6ecd8d02b4 100644 (file)
@@ -270,6 +270,8 @@ static fr_dict_attr_t const *dict_find_or_load_reference(fr_dict_t **dict_def, c
                        return NULL;
                }
 
+               if (dict->proto->init && (dict->proto->init() < 0)) return -1;
+
                /*
                 *      The reference is to the root of the foreign protocol, we're done.
                 */
@@ -285,6 +287,14 @@ static fr_dict_attr_t const *dict_find_or_load_reference(fr_dict_t **dict_def, c
                 *      else, try to resolve the attribute.
                 */
                name += slen + 1;
+
+               if (!*name) {
+                       /*
+                        *      The reference is to the root of the foreign protocol, we're done.
+                        */
+                       *dict_def = dict;
+                       return dict->root;
+               }
        }
 
        /*
index 76321326a99875d18cb358d8ed674c1398ecbc21..ca7f3657777cc1f2a63ba90d636db532bd6bdbde 100644 (file)
@@ -3309,6 +3309,8 @@ static int dict_autoref_free(fr_dict_t *dict)
        }
 
        for (i = 0; i < talloc_array_length(refd_list); i++) {
+               if (refd_list[i]->proto->free) refd_list[i]->proto->free();
+
                if (fr_dict_free(&refd_list[i], dict->root->name) < 0) {
                        fr_strerror_printf("failed freeing autoloaded protocol %s", refd_list[i]->root->name);
                        return -1;
index 589def994b5a14341449a1b0123ab4dc6d2998a6..90c8773fc03206ec501e378076afee3334b40529 100644 (file)
@@ -733,6 +733,10 @@ fr_dict_protocol_t libfreeradius_dhcpv4_dict_protocol = {
        .subtype_table = subtype_table,
        .subtype_table_len = NUM_ELEMENTS(subtype_table),
        .attr_valid = attr_valid,
+
+       .init = fr_dhcpv4_global_init,
+       .free = fr_dhcpv4_global_free,
+
        .encode         = fr_dhcpv4_encode_foreign,
        .decode         = fr_dhcpv4_decode_foreign,
 };
index 279841346b026c339c44eef82b5b396bcc665e48..faca5d70808a51f599ff6c480c98a05613688b22 100644 (file)
@@ -763,8 +763,6 @@ ssize_t     fr_dhcpv4_encode_foreign(fr_dbuff_t *dbuff, fr_pair_list_t const *list)
        fr_dcursor_t    cursor;
        fr_dbuff_t      work_dbuff = FR_DBUFF(dbuff);
 
-       (void) fr_dhcpv4_global_init();
-
        fr_assert(dict_dhcpv4 != NULL);
 
        fr_pair_dcursor_iter_init(&cursor, list, fr_dhcpv4_next_encodable, dict_dhcpv4);
index 7238489e215bd16abd96a01ca490dce962b29a21..0811da1f545bc35a86792f128e09193331b43263 100644 (file)
@@ -1319,6 +1319,10 @@ fr_dict_protocol_t libfreeradius_radius_dict_protocol = {
        .subtype_table = subtype_table,
        .subtype_table_len = NUM_ELEMENTS(subtype_table),
        .attr_valid = attr_valid,
+
+       .init = fr_radius_init,
+       .free = fr_radius_free,
+
        .decode = fr_radius_decode_foreign,
        .encode = fr_radius_encode_foreign,
 };