]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Pass in both src and dst chunks to the copy callback
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 5 Dec 2020 05:09:38 +0000 (22:09 -0700)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 5 Dec 2020 05:09:38 +0000 (22:09 -0700)
src/lib/util/dict_ext.c
src/lib/util/ext.c
src/lib/util/ext.h

index 82cd32ad79c3a60d32acfd26ce60f2efec10a637..821a9af6070b9addf6a87fd599c76a1f21c59dc9 100644 (file)
@@ -59,11 +59,13 @@ static int fr_dict_attr_ext_name_fixup(UNUSED int ext,
  *
  */
 static int fr_dict_attr_ext_enumv_copy(UNUSED int ext,
-                                      TALLOC_CTX *chunk,
+                                      TALLOC_CTX *chunk_dst,
                                       void *dst_ext_ptr, UNUSED size_t dst_ext_len,
+                                      TALLOC_CTX const *chunk_src,
                                       void *src_ext_ptr, UNUSED size_t src_ext_len)
 {
-       fr_dict_attr_t                  *da_src = talloc_get_type_abort(chunk, fr_dict_attr_t);
+       fr_dict_attr_t const            *da_src = talloc_get_type_abort_const(chunk_src, fr_dict_attr_t);
+       fr_dict_attr_t                  *da_dst = talloc_get_type_abort(chunk_dst, fr_dict_attr_t);
        fr_dict_attr_ext_enumv_t        *dst_ext = dst_ext_ptr, *src_ext = src_ext_ptr;
        fr_hash_iter_t                  iter;
        fr_dict_enum_t                  *enumv;
@@ -92,7 +94,7 @@ static int fr_dict_attr_ext_enumv_copy(UNUSED int ext,
                /*
                 *      Fixme - Child struct copying is probably wrong
                 */
-               if (dict_attr_enum_add_name(da_src, enumv->name, enumv->value,
+               if (dict_attr_enum_add_name(da_dst, enumv->name, enumv->value,
                                            true, true, child_struct) < 0) return -1;
        }
 
@@ -103,11 +105,12 @@ static int fr_dict_attr_ext_enumv_copy(UNUSED int ext,
  *
  */
 static int fr_dict_attr_ext_vendor_copy(UNUSED int ext,
-                                       TALLOC_CTX *chunk,
+                                       TALLOC_CTX *chunk_dst,
                                        void *dst_ext_ptr, UNUSED size_t dst_ext_len,
+                                       UNUSED TALLOC_CTX const *chunk_src,
                                        void *src_ext_ptr, UNUSED size_t src_ext_len)
 {
-       fr_dict_attr_t                  *da_src = talloc_get_type_abort(chunk, fr_dict_attr_t);
+       fr_dict_attr_t                  *da_dst = talloc_get_type_abort_const(chunk_dst, fr_dict_attr_t);
        fr_dict_attr_ext_vendor_t       *dst_ext = dst_ext_ptr, *src_ext = src_ext_ptr;
        fr_dict_attr_t const            **da_stack;
        fr_dict_attr_t const            *old_vendor = src_ext->vendor;
@@ -123,7 +126,7 @@ static int fr_dict_attr_ext_vendor_copy(UNUSED int ext,
         *      find a vendor at the same depth as
         *      the old depth.
         */
-       da_stack = fr_dict_attr_da_stack(da_src);
+       da_stack = fr_dict_attr_da_stack(da_dst);
        if (da_stack) {
                new_vendor = da_stack[old_vendor->depth];
                if ((new_vendor->type == old_vendor->type) && (new_vendor->attr == old_vendor->attr)) {
@@ -139,7 +142,7 @@ static int fr_dict_attr_ext_vendor_copy(UNUSED int ext,
         *      Theoretically the attribute could
         *      have been moved to a different depth.
         */
-       for (da = da_src->parent; da; da = da->parent) {
+       for (da = da_dst->parent; da; da = da->parent) {
                if ((da->type == old_vendor->type) && (da->attr == old_vendor->attr)) {
                        dst_ext->vendor = da;
                        return 0;
index 436e25a01fff3741e1eb47c8e30391de28eb33bc..df4cef0e5429588d741632eb33a5e81ab3cc48d6 100644 (file)
@@ -194,6 +194,7 @@ void *fr_ext_copy(fr_ext_t const *def, TALLOC_CTX **chunk_dst, TALLOC_CTX const
                info->copy(ext,
                           *chunk_dst,
                           ext_dst_ptr, fr_ext_len(def, *chunk_dst, ext),
+                          chunk_src,
                           ext_src_ptr, fr_ext_len(def, chunk_src, ext));
        /*
         *      If there's no special copy function
@@ -298,6 +299,7 @@ int fr_ext_copy_all(fr_ext_t const *def, TALLOC_CTX **chunk_dst, TALLOC_CTX cons
                                       *chunk_dst,
                                       fr_ext_ptr(*chunk_dst, ext_dst_offsets[i], info->has_hdr),
                                       fr_ext_len(def, *chunk_dst, i),
+                                      chunk_src,
                                       fr_ext_ptr(chunk_src, ext_src_offsets[i], info->has_hdr),
                                       fr_ext_len(def, chunk_src, i)) < 0) return -1;
                /*
index 1b9cc23304fc4d398aaea8e638f21c3ec34a3955..b60753910a876fbc9348059aa5065aef466178b6 100644 (file)
@@ -73,17 +73,20 @@ typedef void *(* fr_ext_alloc_t)(fr_ext_t const *def, TALLOC_CTX **dst_chunk_p,
 /** Function for re-populating extensions after they're copied
  *
  * @param[in] ext              that's being copied.
- * @param[in] chunk            Talloc chunk we're copying to.
+ * @param[in] dst_chunk                Talloc chunk we're copying to.
  * @param[in] dst_ext_ptr      Pointer to the dst extension to populate.
  * @param[in] dst_ext_len      The length of the dst extension.
+ * @param[in] src_chunk                Talloc chunk we're copying from.
  * @param[in] src_ext_ptr      Pointer for the src extension.
  * @param[in] src_ext_len      Length of the src extension.
  * @return
  *     - NULL on error.
  *     - Pointer to the new extension on success.
  */
-typedef int (* fr_ext_copy_t)(int ext, TALLOC_CTX *chunk,
+typedef int (* fr_ext_copy_t)(int ext,
+                             TALLOC_CTX *dst_chunk,
                              void *dst_ext_ptr, size_t dst_ext_len,
+                             TALLOC_CTX const *src_chunk,
                              void *src_ext_ptr, size_t src_ext_len);
 
 /** Function for re-establishing internal consistency on realloc