diff options
author | Stefan Metzmacher <metze@samba.org> | 2005-08-18 01:24:08 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:33:29 -0500 |
commit | ec96a742f7b6ce4cbb4f649dd8aba92ef80f0ff0 (patch) | |
tree | 79de41fa761ca1854c1054161173bec374d371eb /source4/librpc/ndr | |
parent | a8d31eac00cf13c20343374f11224778e470e849 (diff) | |
download | samba-ec96a742f7b6ce4cbb4f649dd8aba92ef80f0ff0.tar.gz samba-ec96a742f7b6ce4cbb4f649dd8aba92ef80f0ff0.tar.bz2 samba-ec96a742f7b6ce4cbb4f649dd8aba92ef80f0ff0.zip |
r9373: - create a hierachical memory tree with recursiv ndr_pull_* functions
- with this it's also possible to talloc_free() the ndr_pull structure
and talloc_steal(ndr->current_mem_ctx); to fetch the whole data of the hierachical tree
- if the toplevel struct is a valid talloc pointer it's also possible to use
NDR_PULL_SET_MEM_CTX(ndr, mem_ctx); to the the toplevel pointer with the struct pointer
(NOTE: no callers are using this yet, but they shortly will)
metze
(This used to be commit 1a2b8369586642cc9bc15d015c1e4256c3a92732)
Diffstat (limited to 'source4/librpc/ndr')
-rw-r--r-- | source4/librpc/ndr/libndr.h | 44 | ||||
-rw-r--r-- | source4/librpc/ndr/ndr.c | 2 | ||||
-rw-r--r-- | source4/librpc/ndr/ndr_compression.c | 1 | ||||
-rw-r--r-- | source4/librpc/ndr/ndr_krb5pac.c | 6 | ||||
-rw-r--r-- | source4/librpc/ndr/ndr_sec.c | 2 |
5 files changed, 42 insertions, 13 deletions
diff --git a/source4/librpc/ndr/libndr.h b/source4/librpc/ndr/libndr.h index b7e06087a7..a319a44102 100644 --- a/source4/librpc/ndr/libndr.h +++ b/source4/librpc/ndr/libndr.h @@ -54,6 +54,8 @@ struct ndr_pull { struct ndr_token_list *array_length_list; struct ndr_token_list *switch_list; + TALLOC_CTX *current_mem_ctx; + /* this is used to ensure we generate unique reference IDs between request and reply */ uint32_t ptr_count; @@ -224,28 +226,46 @@ enum ndr_compression_alg { return _status; \ } while (0) +#define NDR_PULL_GET_MEM_CTX(ndr) (ndr->current_mem_ctx) -#define NDR_ALLOC_SIZE(ndr, s, size) do { \ - (s) = talloc_size(ndr, size); \ - if ((size) && !(s)) return ndr_pull_error(ndr, NDR_ERR_ALLOC, \ - "Alloc %u failed\n", \ - (unsigned)size); \ - } while (0) +#define NDR_PULL_SET_MEM_CTX(ndr, mem_ctx, flgs) do {\ + if ( !(flgs) || (ndr->flags & flgs) ) {\ + if (!(mem_ctx)) {\ + return ndr_pull_error(ndr, NDR_ERR_ALLOC, "NDR_PULL_SET_MEM_CTX(NULL): %s\n", __location__); \ + }\ + ndr->current_mem_ctx = discard_const(mem_ctx);\ + }\ +} while(0) -#define NDR_ALLOC(ndr, s) NDR_ALLOC_SIZE(ndr, s, sizeof(*(s))) +#define _NDR_PULL_FIX_CURRENT_MEM_CTX(ndr) do {\ + if (!ndr->current_mem_ctx) {\ + ndr->current_mem_ctx = talloc_new(ndr);\ + if (!ndr->current_mem_ctx) {\ + return ndr_pull_error(ndr, NDR_ERR_ALLOC, "_NDR_PULL_FIX_CURRENT_MEM_CTX() failed: %s\n", __location__); \ + }\ + }\ +} while(0) + +#define NDR_PULL_ALLOC_SIZE(ndr, s, size) do { \ + _NDR_PULL_FIX_CURRENT_MEM_CTX(ndr);\ + (s) = talloc_size(ndr->current_mem_ctx, size); \ + if (!(s)) return ndr_pull_error(ndr, NDR_ERR_ALLOC, "Alloc %u failed: %s\n",(unsigned)size, __location__); \ +} while (0) +#define NDR_PULL_ALLOC(ndr, s) NDR_PULL_ALLOC_SIZE(ndr, s, sizeof(*(s))) -#define NDR_ALLOC_N_SIZE(ndr, s, n, elsize) do { \ - (s) = talloc_array_size(ndr, elsize, n); \ - if (!(s)) return ndr_pull_error(ndr, NDR_ERR_ALLOC, "Alloc %u * %u failed\n", (unsigned)n, (unsigned)elsize); \ +#define NDR_PULL_ALLOC_N_SIZE(ndr, s, n, elsize) do { \ + _NDR_PULL_FIX_CURRENT_MEM_CTX(ndr);\ + (s) = talloc_array_size(ndr->current_mem_ctx, elsize, n); \ + if (!(s)) return ndr_pull_error(ndr, NDR_ERR_ALLOC, "Alloc %u * %u failed: %s\n", (unsigned)n, (unsigned)elsize, __location__); \ } while (0) -#define NDR_ALLOC_N(ndr, s, n) NDR_ALLOC_N_SIZE(ndr, s, n, sizeof(*(s))) +#define NDR_PULL_ALLOC_N(ndr, s, n) NDR_PULL_ALLOC_N_SIZE(ndr, s, n, sizeof(*(s))) #define NDR_PUSH_ALLOC_SIZE(ndr, s, size) do { \ (s) = talloc_size(ndr, size); \ - if (!(s)) return ndr_push_error(ndr, NDR_ERR_ALLOC, "push alloc %u failed\n", (unsigned)size); \ + if (!(s)) return ndr_push_error(ndr, NDR_ERR_ALLOC, "push alloc %u failed: %s\n", (unsigned)size, __location__); \ } while (0) #define NDR_PUSH_ALLOC(ndr, s) NDR_PUSH_ALLOC_SIZE(ndr, s, sizeof(*(s))) diff --git a/source4/librpc/ndr/ndr.c b/source4/librpc/ndr/ndr.c index a84049a3b0..6bc4198de1 100644 --- a/source4/librpc/ndr/ndr.c +++ b/source4/librpc/ndr/ndr.c @@ -50,6 +50,7 @@ struct ndr_pull *ndr_pull_init_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx) ndr = talloc_zero(mem_ctx, struct ndr_pull); if (!ndr) return NULL; + ndr->current_mem_ctx = mem_ctx; ndr->data = blob->data; ndr->data_size = blob->length; @@ -359,6 +360,7 @@ NTSTATUS ndr_pull_subcontext_start(struct ndr_pull *ndr, subndr = talloc_zero(ndr, struct ndr_pull); NT_STATUS_HAVE_NO_MEMORY(subndr); subndr->flags = ndr->flags; + subndr->current_mem_ctx = ndr->current_mem_ctx; subndr->data = ndr->data + ndr->offset; subndr->offset = 0; diff --git a/source4/librpc/ndr/ndr_compression.c b/source4/librpc/ndr/ndr_compression.c index 097f76c90a..def194634f 100644 --- a/source4/librpc/ndr/ndr_compression.c +++ b/source4/librpc/ndr/ndr_compression.c @@ -105,6 +105,7 @@ static NTSTATUS ndr_pull_compression_mszip(struct ndr_pull *subndr, comndr = talloc_zero(subndr, struct ndr_pull); NT_STATUS_HAVE_NO_MEMORY(comndr); comndr->flags = subndr->flags; + comndr->current_mem_ctx = subndr->current_mem_ctx; comndr->data = uncompressed.data; comndr->data_size = uncompressed.length; diff --git a/source4/librpc/ndr/ndr_krb5pac.c b/source4/librpc/ndr/ndr_krb5pac.c index 7d7e105e3e..92e3d77707 100644 --- a/source4/librpc/ndr/ndr_krb5pac.c +++ b/source4/librpc/ndr/ndr_krb5pac.c @@ -78,6 +78,7 @@ NTSTATUS ndr_push_PAC_BUFFER(struct ndr_push *ndr, int ndr_flags, const struct P NTSTATUS ndr_pull_PAC_BUFFER(struct ndr_pull *ndr, int ndr_flags, struct PAC_BUFFER *r) { uint32_t _ptr_info; + TALLOC_CTX *_mem_save_info_0; if (ndr_flags & NDR_SCALARS) { NDR_CHECK(ndr_pull_align(ndr, 4)); NDR_CHECK(ndr_pull_PAC_TYPE(ndr, NDR_SCALARS, &r->type)); @@ -87,7 +88,7 @@ NTSTATUS ndr_pull_PAC_BUFFER(struct ndr_pull *ndr, int ndr_flags, struct PAC_BUF ndr_set_flags(&ndr->flags, LIBNDR_FLAG_ALIGN8); NDR_CHECK(ndr_pull_generic_ptr(ndr, &_ptr_info)); if (_ptr_info) { - NDR_ALLOC(ndr, r->info); + NDR_PULL_ALLOC(ndr, r->info); NDR_CHECK(ndr_pull_relative_ptr1(ndr, r->info, _ptr_info)); } else { r->info = NULL; @@ -104,6 +105,8 @@ NTSTATUS ndr_pull_PAC_BUFFER(struct ndr_pull *ndr, int ndr_flags, struct PAC_BUF struct ndr_pull_save _relative_save; ndr_pull_save(ndr, &_relative_save); NDR_CHECK(ndr_pull_relative_ptr2(ndr, r->info)); + _mem_save_info_0 = NDR_PULL_GET_MEM_CTX(ndr); + NDR_PULL_SET_MEM_CTX(ndr, r->info, 0); { struct ndr_pull *_ndr_info; NDR_CHECK(ndr_pull_subcontext_start(ndr, &_ndr_info, 0, r->_ndr_size)); @@ -111,6 +114,7 @@ NTSTATUS ndr_pull_PAC_BUFFER(struct ndr_pull *ndr, int ndr_flags, struct PAC_BUF NDR_CHECK(ndr_pull_PAC_INFO(_ndr_info, NDR_SCALARS|NDR_BUFFERS, r->info)); NDR_CHECK(ndr_pull_subcontext_end(ndr, _ndr_info, 0, r->_ndr_size)); } + NDR_PULL_SET_MEM_CTX(ndr, _mem_save_info_0, 0); ndr_pull_restore(ndr, &_relative_save); } ndr->flags = _flags_save_PAC_INFO; diff --git a/source4/librpc/ndr/ndr_sec.c b/source4/librpc/ndr/ndr_sec.c index c6eb98c58a..fb18d48909 100644 --- a/source4/librpc/ndr/ndr_sec.c +++ b/source4/librpc/ndr/ndr_sec.c @@ -70,6 +70,8 @@ NTSTATUS ndr_pull_dom_sid28(struct ndr_pull *ndr, int ndr_flags, struct dom_sid subndr = talloc_zero(ndr, struct ndr_pull); NT_STATUS_HAVE_NO_MEMORY(subndr); + subndr->flags = ndr->flags; + subndr->current_mem_ctx = ndr->current_mem_ctx; subndr->data = ndr->data + ndr->offset; subndr->data_size = 28; |