From a8d31eac00cf13c20343374f11224778e470e849 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 18 Aug 2005 00:45:19 +0000 Subject: r9372: - make the subcontext handling autogenerated code look nicer, - unify the handling of subcontext, compression and obfucation metze (This used to be commit 09de7e0af7f9f7539cf63791baf90ac202536176) --- source4/librpc/ndr/ndr.c | 98 +++++++++++++++++++++++------------- source4/librpc/ndr/ndr_compression.c | 54 +++++++++++++++----- source4/librpc/ndr/ndr_krb5pac.c | 14 ++---- source4/librpc/ndr/ndr_obfuscate.c | 14 +++++- 4 files changed, 121 insertions(+), 59 deletions(-) (limited to 'source4/librpc/ndr') diff --git a/source4/librpc/ndr/ndr.c b/source4/librpc/ndr/ndr.c index 3a291c2cf8..a84049a3b0 100644 --- a/source4/librpc/ndr/ndr.c +++ b/source4/librpc/ndr/ndr.c @@ -57,22 +57,6 @@ struct ndr_pull *ndr_pull_init_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx) return ndr; } -/* - create an ndr sub-context based on an existing context. The new context starts - at the current offset, with the given size limit -*/ -NTSTATUS ndr_pull_subcontext(struct ndr_pull *ndr, struct ndr_pull *ndr2, uint32_t size) -{ - NDR_PULL_NEED_BYTES(ndr, size); - *ndr2 = *ndr; - ndr2->data += ndr2->offset; - ndr2->offset = 0; - ndr2->data_size = size; - ndr2->flags = ndr->flags; - return NT_STATUS_OK; -} - - /* advance by 'size' bytes */ @@ -322,17 +306,17 @@ NTSTATUS ndr_push_error(struct ndr_push *ndr, enum ndr_err_code err, const char return ndr_map_error(err); } - /* handle subcontext buffers, which in midl land are user-marshalled, but we use magic in pidl to make them easier to cope with */ -NTSTATUS ndr_pull_subcontext_header(struct ndr_pull *ndr, - size_t header_size, - ssize_t size_is, - struct ndr_pull *ndr2) +NTSTATUS ndr_pull_subcontext_start(struct ndr_pull *ndr, + struct ndr_pull **_subndr, + size_t header_size, + ssize_t size_is) { - ndr2->flags = ndr->flags; + struct ndr_pull *subndr; + uint32_t r_content_size; switch (header_size) { case 0: { @@ -340,7 +324,7 @@ NTSTATUS ndr_pull_subcontext_header(struct ndr_pull *ndr, if (size_is >= 0) { content_size = size_is; } - NDR_CHECK(ndr_pull_subcontext(ndr, ndr2, content_size)); + r_content_size = content_size; break; } @@ -351,7 +335,7 @@ NTSTATUS ndr_pull_subcontext_header(struct ndr_pull *ndr, return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) size_is(%d) mismatch content_size %d", (int)size_is, (int)content_size); } - NDR_CHECK(ndr_pull_subcontext(ndr, ndr2, content_size)); + r_content_size = content_size; break; } @@ -362,31 +346,75 @@ NTSTATUS ndr_pull_subcontext_header(struct ndr_pull *ndr, return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) size_is(%d) mismatch content_size %d", (int)size_is, (int)content_size); } - NDR_CHECK(ndr_pull_subcontext(ndr, ndr2, content_size)); + r_content_size = content_size; break; } default: return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) header_size %d", (int)header_size); } + + NDR_PULL_NEED_BYTES(ndr, r_content_size); + + subndr = talloc_zero(ndr, struct ndr_pull); + NT_STATUS_HAVE_NO_MEMORY(subndr); + subndr->flags = ndr->flags; + + subndr->data = ndr->data + ndr->offset; + subndr->offset = 0; + subndr->data_size = r_content_size; + + *_subndr = subndr; + return NT_STATUS_OK; +} + +NTSTATUS ndr_pull_subcontext_end(struct ndr_pull *ndr, + struct ndr_pull *subndr, + size_t header_size, + ssize_t size_is) +{ + uint32_t advance; + if (size_is >= 0) { + advance = size_is; + } else if (header_size > 0) { + advance = subndr->data_size; + } else { + advance = subndr->offset; + } + NDR_CHECK(ndr_pull_advance(ndr, advance)); + return NT_STATUS_OK; +} + +NTSTATUS ndr_push_subcontext_start(struct ndr_push *ndr, + struct ndr_push **_subndr, + size_t header_size, + ssize_t size_is) +{ + struct ndr_push *subndr; + + subndr = ndr_push_init_ctx(ndr); + NT_STATUS_HAVE_NO_MEMORY(subndr); + subndr->flags = ndr->flags; + + *_subndr = subndr; return NT_STATUS_OK; } /* push a subcontext header */ -NTSTATUS ndr_push_subcontext_header(struct ndr_push *ndr, - size_t header_size, - ssize_t size_is, - struct ndr_push *ndr2) +NTSTATUS ndr_push_subcontext_end(struct ndr_push *ndr, + struct ndr_push *subndr, + size_t header_size, + ssize_t size_is) { if (size_is >= 0) { - ssize_t padding_len = size_is - ndr2->offset; + ssize_t padding_len = size_is - subndr->offset; if (padding_len > 0) { - NDR_CHECK(ndr_push_zero(ndr2, padding_len)); + NDR_CHECK(ndr_push_zero(subndr, padding_len)); } else if (padding_len < 0) { return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PUSH) content_size %d is larger than size_is(%d)", - (int)ndr2->offset, (int)size_is); + (int)subndr->offset, (int)size_is); } } @@ -395,17 +423,19 @@ NTSTATUS ndr_push_subcontext_header(struct ndr_push *ndr, break; case 2: - NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, ndr2->offset)); + NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, subndr->offset)); break; case 4: - NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, ndr2->offset)); + NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, subndr->offset)); break; default: return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext header size %d", (int)header_size); } + + NDR_CHECK(ndr_push_bytes(ndr, subndr->data, subndr->offset)); return NT_STATUS_OK; } diff --git a/source4/librpc/ndr/ndr_compression.c b/source4/librpc/ndr/ndr_compression.c index cf3c3ae97b..097f76c90a 100644 --- a/source4/librpc/ndr/ndr_compression.c +++ b/source4/librpc/ndr/ndr_compression.c @@ -71,11 +71,12 @@ static NTSTATUS ndr_pull_compression_mszip_chunk(struct ndr_pull *ndrpull, } static NTSTATUS ndr_pull_compression_mszip(struct ndr_pull *subndr, - struct ndr_pull *comndr, + struct ndr_pull **_comndr, ssize_t decompressed_len) { NTSTATUS status = NT_STATUS_MORE_PROCESSING_REQUIRED; struct ndr_push *ndrpush; + struct ndr_pull *comndr; DATA_BLOB uncompressed; uint32_t payload_header[4]; uint32_t payload_size; @@ -101,7 +102,10 @@ static NTSTATUS ndr_pull_compression_mszip(struct ndr_pull *subndr, (int)uncompressed.length, (int)decompressed_len); } - *comndr = *subndr; + comndr = talloc_zero(subndr, struct ndr_pull); + NT_STATUS_HAVE_NO_MEMORY(comndr); + comndr->flags = subndr->flags; + comndr->data = uncompressed.data; comndr->data_size = uncompressed.length; comndr->offset = 0; @@ -127,6 +131,7 @@ static NTSTATUS ndr_pull_compression_mszip(struct ndr_pull *subndr, comndr->data_size = payload_size; comndr->offset = 0; + *_comndr = comndr; return NT_STATUS_OK; } @@ -140,16 +145,14 @@ static NTSTATUS ndr_push_compression_mszip(struct ndr_push *subndr, handle compressed subcontext buffers, which in midl land are user-marshalled, but we use magic in pidl to make them easier to cope with */ -NTSTATUS ndr_pull_compression(struct ndr_pull *subndr, - struct ndr_pull *comndr, - enum ndr_compression_alg compression_alg, - ssize_t decompressed_len) +NTSTATUS ndr_pull_compression_start(struct ndr_pull *subndr, + struct ndr_pull **_comndr, + enum ndr_compression_alg compression_alg, + ssize_t decompressed_len) { - comndr->flags = subndr->flags; - switch (compression_alg) { case NDR_COMPRESSION_MSZIP: - return ndr_pull_compression_mszip(subndr, comndr, decompressed_len); + return ndr_pull_compression_mszip(subndr, _comndr, decompressed_len); default: return ndr_pull_error(subndr, NDR_ERR_COMPRESSION, "Bad compression algorithm %d (PULL)", compression_alg); @@ -157,15 +160,40 @@ NTSTATUS ndr_pull_compression(struct ndr_pull *subndr, return NT_STATUS_OK; } +NTSTATUS ndr_pull_compression_end(struct ndr_pull *subndr, + struct ndr_pull *comndr, + enum ndr_compression_alg compression_alg, + ssize_t decompressed_len) +{ + return NT_STATUS_OK; +} + /* push a compressed subcontext */ -NTSTATUS ndr_push_compression(struct ndr_push *subndr, - struct ndr_push *comndr, - enum ndr_compression_alg compression_alg) +NTSTATUS ndr_push_compression_start(struct ndr_push *subndr, + struct ndr_push **_comndr, + enum ndr_compression_alg compression_alg, + ssize_t decompressed_len) { - comndr->flags = subndr->flags; + struct ndr_push *comndr; + + comndr = ndr_push_init_ctx(subndr); + NT_STATUS_HAVE_NO_MEMORY(comndr); + comndr->flags = subndr->flags; + *_comndr = comndr; + return NT_STATUS_OK; +} + +/* + push a compressed subcontext +*/ +NTSTATUS ndr_push_compression_end(struct ndr_push *subndr, + struct ndr_push *comndr, + enum ndr_compression_alg compression_alg, + ssize_t decompressed_len) +{ switch (compression_alg) { case NDR_COMPRESSION_MSZIP: return ndr_push_compression_mszip(subndr, comndr); diff --git a/source4/librpc/ndr/ndr_krb5pac.c b/source4/librpc/ndr/ndr_krb5pac.c index 3af3a185e5..7d7e105e3e 100644 --- a/source4/librpc/ndr/ndr_krb5pac.c +++ b/source4/librpc/ndr/ndr_krb5pac.c @@ -63,15 +63,10 @@ NTSTATUS ndr_push_PAC_BUFFER(struct ndr_push *ndr, int ndr_flags, const struct P NDR_CHECK(ndr_push_relative_ptr2(ndr, r->info)); { struct ndr_push *_ndr_info; - - _ndr_info = ndr_push_init_ctx(ndr); - if (!_ndr_info) return NT_STATUS_NO_MEMORY; - _ndr_info->flags = ndr->flags; - + NDR_CHECK(ndr_push_subcontext_start(ndr, &_ndr_info, 0, _subcontext_size_PAC_INFO(r->info,r->type,0))); NDR_CHECK(ndr_push_set_switch_value(_ndr_info, r->info, r->type)); NDR_CHECK(ndr_push_PAC_INFO(_ndr_info, NDR_SCALARS|NDR_BUFFERS, r->info)); - NDR_CHECK(ndr_push_subcontext_header(ndr, 0, _subcontext_size_PAC_INFO(r->info,r->type,0), _ndr_info)); - NDR_CHECK(ndr_push_bytes(ndr, _ndr_info->data, _ndr_info->offset)); + NDR_CHECK(ndr_push_subcontext_end(ndr, _ndr_info, 0, _subcontext_size_PAC_INFO(r->info,r->type,0))); } } ndr->flags = _flags_save_PAC_INFO; @@ -111,11 +106,10 @@ NTSTATUS ndr_pull_PAC_BUFFER(struct ndr_pull *ndr, int ndr_flags, struct PAC_BUF NDR_CHECK(ndr_pull_relative_ptr2(ndr, r->info)); { struct ndr_pull *_ndr_info; - NDR_ALLOC(ndr, _ndr_info); - NDR_CHECK(ndr_pull_subcontext_header(ndr, 0, r->_ndr_size, _ndr_info)); + NDR_CHECK(ndr_pull_subcontext_start(ndr, &_ndr_info, 0, r->_ndr_size)); NDR_CHECK(ndr_pull_set_switch_value(_ndr_info, r->info, r->type)); NDR_CHECK(ndr_pull_PAC_INFO(_ndr_info, NDR_SCALARS|NDR_BUFFERS, r->info)); - NDR_CHECK(ndr_pull_advance(ndr, r->_ndr_size)); + NDR_CHECK(ndr_pull_subcontext_end(ndr, _ndr_info, 0, r->_ndr_size)); } ndr_pull_restore(ndr, &_relative_save); } diff --git a/source4/librpc/ndr/ndr_obfuscate.c b/source4/librpc/ndr/ndr_obfuscate.c index 4f875f19a7..3b10e172b7 100644 --- a/source4/librpc/ndr/ndr_obfuscate.c +++ b/source4/librpc/ndr/ndr_obfuscate.c @@ -26,7 +26,7 @@ handle obfuscated subcontext buffers, which in midl land are user-marshalled, but we use magic in pidl to make them easier to cope with */ -NTSTATUS ndr_pull_obfuscation(struct ndr_pull *ndr, uint8_t salt) +NTSTATUS ndr_pull_obfuscation_start(struct ndr_pull *ndr, uint8_t salt) { uint32_t i; @@ -37,10 +37,20 @@ NTSTATUS ndr_pull_obfuscation(struct ndr_pull *ndr, uint8_t salt) return NT_STATUS_OK; } +NTSTATUS ndr_pull_obfuscation_end(struct ndr_pull *ndr, uint8_t salt) +{ + return NT_STATUS_OK; +} + +NTSTATUS ndr_push_obfuscation_start(struct ndr_push *ndr, uint8_t salt) +{ + return NT_STATUS_OK; +} + /* push a obfuscated subcontext */ -NTSTATUS ndr_push_obfuscation(struct ndr_push *ndr, uint8_t salt) +NTSTATUS ndr_push_obfuscation_end(struct ndr_push *ndr, uint8_t salt) { uint32_t i; -- cgit