]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
librpc/ndr: add ndr_deepcopy_struct() helper
authorStefan Metzmacher <metze@samba.org>
Wed, 19 Jul 2023 18:55:55 +0000 (20:55 +0200)
committerVolker Lendecke <vl@samba.org>
Thu, 28 Nov 2024 12:58:32 +0000 (12:58 +0000)
Keep libndr at 6.0.0, this has not been released yet.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15425

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
librpc/ABI/ndr-6.0.0.sigs
librpc/ndr/libndr.h
librpc/ndr/ndr.c
librpc/wscript_build

index 3244948abcc77e5c7c3e61840e711654668b9a5d..7c672a1bf51dcf2ce97f719a07a2911a48b0ab82 100644 (file)
@@ -12,6 +12,7 @@ GUID_string2: char *(TALLOC_CTX *, const struct GUID *)
 GUID_to_ndr_blob: NTSTATUS (const struct GUID *, TALLOC_CTX *, DATA_BLOB *)
 GUID_to_ndr_buf: void (const struct GUID *, struct GUID_ndr_buf *)
 GUID_zero: struct GUID (void)
+_ndr_deepcopy_struct: enum ndr_err_code (ndr_push_flags_fn_t, const void *, ndr_pull_flags_fn_t, TALLOC_CTX *, void *)
 _ndr_pull_error: enum ndr_err_code (struct ndr_pull *, enum ndr_err_code, const char *, const char *, const char *, ...)
 _ndr_push_error: enum ndr_err_code (struct ndr_push *, enum ndr_err_code, const char *, const char *, const char *, ...)
 ndr_align_size: size_t (uint32_t, size_t)
index 21c71f1a022919496ad6e2f94fcdd9244b1db531..c8cf6ee1d45199067f20ef5caa7a3e0e963be7c4 100644 (file)
@@ -759,6 +759,16 @@ enum ndr_err_code ndr_pull_struct_blob_all_noalloc(const DATA_BLOB *blob,
 enum ndr_err_code ndr_pull_union_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p, uint32_t level, ndr_pull_flags_fn_t fn);
 enum ndr_err_code ndr_pull_union_blob_all(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p, uint32_t level, ndr_pull_flags_fn_t fn);
 
+enum ndr_err_code _ndr_deepcopy_struct(ndr_push_flags_fn_t push_fn,
+                                      const void *src,
+                                      ndr_pull_flags_fn_t pull_fn,
+                                      TALLOC_CTX *dst_mem, void *dst);
+#define ndr_deepcopy_struct(type, src, dst_mem, dst) \
+       _ndr_deepcopy_struct((ndr_push_flags_fn_t)ndr_push_ ## type, \
+                            src, \
+                            (ndr_pull_flags_fn_t)ndr_pull_ ## type, \
+                            dst_mem, dst)
+
 /* from libndr_basic.h */
 #define NDR_SCALAR_PROTO(name, type) \
 enum ndr_err_code ndr_push_ ## name(struct ndr_push *ndr, ndr_flags_type ndr_flags, type v); \
index b48c798cd7524f7ecdc3b50d9702f9e0778fd488..c07bd233a93e469d94a9d9e90ac5ec75ff9a1eab 100644 (file)
@@ -1393,6 +1393,32 @@ _PUBLIC_ enum ndr_err_code ndr_pull_struct_blob_all(const DATA_BLOB *blob, TALLO
        return NDR_ERR_SUCCESS;
 }
 
+_PUBLIC_ enum ndr_err_code
+_ndr_deepcopy_struct(ndr_push_flags_fn_t push_fn,
+                    const void *src,
+                    ndr_pull_flags_fn_t pull_fn,
+                    TALLOC_CTX *dst_mem, void *dst)
+{
+       TALLOC_CTX *frame = talloc_stackframe();
+       DATA_BLOB blob = { .length = 0, };
+       enum ndr_err_code ndr_err;
+
+       ndr_err = ndr_push_struct_blob(&blob, frame, src, push_fn);
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               TALLOC_FREE(frame);
+               return ndr_err;
+       }
+
+       ndr_err = ndr_pull_struct_blob_all(&blob, dst_mem, dst, pull_fn);
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               TALLOC_FREE(frame);
+               return ndr_err;
+       }
+
+       TALLOC_FREE(frame);
+       return NDR_ERR_SUCCESS;
+}
+
 /*
  * pull a struct from a blob using NDR
  *
index 6cb4e1cff2b4f36acb4763dee3732bff90d1657a..a4cdfd9f508c181628ca2b727f70c7f116fb1a35 100644 (file)
@@ -676,7 +676,7 @@ bld.SAMBA_LIBRARY('ndr',
     header_path= [('*gen_ndr*', 'gen_ndr')],
     vnum='6.0.0',
     abi_directory='ABI',
-    abi_match='!ndr_table_* ndr_* GUID_* _ndr_pull_error* _ndr_push_error*',
+    abi_match='!ndr_table_* ndr_* GUID_* _ndr_pull_error* _ndr_push_error* _ndr_deepcopy_*',
     )
 
 bld.SAMBA_LIBRARY('dcerpc-binding',