2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 2003
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 this provides the core routines for NDR parsing functions
25 see http://www.opengroup.org/onlinepubs/9629399/chap14.htm for details
30 #include "librpc/ndr/libndr.h"
31 #include "lib/util/dlinklist.h"
32 #include "librpc/gen_ndr/dcerpc.h"
34 #define NDR_BASE_MARSHALL_SIZE 1024
36 /* this guid indicates NDR encoding in a protocol tower */
37 const struct ndr_syntax_id ndr_transfer_syntax = {
38 { 0x8a885d04, 0x1ceb, 0x11c9, {0x9f, 0xe8}, {0x08,0x00,0x2b,0x10,0x48,0x60} },
42 const struct ndr_syntax_id ndr64_transfer_syntax = {
43 { 0x71710533, 0xbeba, 0x4937, {0x83, 0x19}, {0xb5,0xdb,0xef,0x9c,0xcc,0x36} },
48 work out the number of bytes needed to align on a n byte boundary
50 _PUBLIC_ size_t ndr_align_size(uint32_t offset, size_t n)
52 if ((offset & (n-1)) == 0) return 0;
53 return n - (offset & (n-1));
57 initialise a ndr parse structure from a data blob
59 _PUBLIC_ struct ndr_pull *ndr_pull_init_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx)
63 ndr = talloc_zero(mem_ctx, struct ndr_pull);
64 if (!ndr) return NULL;
65 ndr->current_mem_ctx = mem_ctx;
67 ndr->data = blob->data;
68 ndr->data_size = blob->length;
74 advance by 'size' bytes
76 _PUBLIC_ NTSTATUS ndr_pull_advance(struct ndr_pull *ndr, uint32_t size)
79 if (ndr->offset > ndr->data_size) {
80 return ndr_pull_error(ndr, NDR_ERR_BUFSIZE,
81 "ndr_pull_advance by %u failed",
88 set the parse offset to 'ofs'
90 static NTSTATUS ndr_pull_set_offset(struct ndr_pull *ndr, uint32_t ofs)
93 if (ndr->offset > ndr->data_size) {
94 return ndr_pull_error(ndr, NDR_ERR_BUFSIZE,
95 "ndr_pull_set_offset %u failed",
101 /* save the offset/size of the current ndr state */
102 _PUBLIC_ void ndr_pull_save(struct ndr_pull *ndr, struct ndr_pull_save *save)
104 save->offset = ndr->offset;
105 save->data_size = ndr->data_size;
108 /* restore the size/offset of a ndr structure */
109 _PUBLIC_ void ndr_pull_restore(struct ndr_pull *ndr, struct ndr_pull_save *save)
111 ndr->offset = save->offset;
112 ndr->data_size = save->data_size;
116 /* create a ndr_push structure, ready for some marshalling */
117 _PUBLIC_ struct ndr_push *ndr_push_init_ctx(TALLOC_CTX *mem_ctx)
119 struct ndr_push *ndr;
121 ndr = talloc_zero(mem_ctx, struct ndr_push);
127 ndr->alloc_size = NDR_BASE_MARSHALL_SIZE;
128 ndr->data = talloc_array(ndr, uint8_t, ndr->alloc_size);
136 /* return a DATA_BLOB structure for the current ndr_push marshalled data */
137 _PUBLIC_ DATA_BLOB ndr_push_blob(struct ndr_push *ndr)
140 blob.data = ndr->data;
141 blob.length = ndr->offset;
142 if (ndr->alloc_size > ndr->offset) {
143 ndr->data[ndr->offset] = 0;
150 expand the available space in the buffer to ndr->offset + extra_size
152 _PUBLIC_ NTSTATUS ndr_push_expand(struct ndr_push *ndr, uint32_t extra_size)
154 uint32_t size = extra_size + ndr->offset;
156 if (size < ndr->offset) {
157 /* extra_size overflowed the offset */
158 return ndr_push_error(ndr, NDR_ERR_BUFSIZE, "Overflow in push_expand to %u",
162 if (ndr->alloc_size > size) {
166 ndr->alloc_size += NDR_BASE_MARSHALL_SIZE;
167 if (size+1 > ndr->alloc_size) {
168 ndr->alloc_size = size+1;
170 ndr->data = talloc_realloc(ndr, ndr->data, uint8_t, ndr->alloc_size);
172 return ndr_push_error(ndr, NDR_ERR_ALLOC, "Failed to push_expand to %u",
179 _PUBLIC_ void ndr_print_debug_helper(struct ndr_print *ndr, const char *format, ...) _PRINTF_ATTRIBUTE(2,3)
185 va_start(ap, format);
186 vasprintf(&s, format, ap);
189 for (i=0;i<ndr->depth;i++) {
193 DEBUG(0,("%s\n", s));
197 _PUBLIC_ void ndr_print_string_helper(struct ndr_print *ndr, const char *format, ...) _PRINTF_ATTRIBUTE(2,3)
202 for (i=0;i<ndr->depth;i++) {
203 ndr->private_data = talloc_asprintf_append_buffer(
204 (char *)ndr->private_data, " ");
207 va_start(ap, format);
208 ndr->private_data = talloc_vasprintf_append_buffer((char *)ndr->private_data,
211 ndr->private_data = talloc_asprintf_append_buffer((char *)ndr->private_data,
216 a useful helper function for printing idl structures via DEBUG()
218 _PUBLIC_ void ndr_print_debug(ndr_print_fn_t fn, const char *name, void *ptr)
220 struct ndr_print *ndr;
222 ndr = talloc_zero(NULL, struct ndr_print);
224 ndr->print = ndr_print_debug_helper;
232 a useful helper function for printing idl unions via DEBUG()
234 _PUBLIC_ void ndr_print_union_debug(ndr_print_fn_t fn, const char *name, uint32_t level, void *ptr)
236 struct ndr_print *ndr;
238 ndr = talloc_zero(NULL, struct ndr_print);
240 ndr->print = ndr_print_debug_helper;
243 ndr_print_set_switch_value(ndr, ptr, level);
249 a useful helper function for printing idl function calls via DEBUG()
251 _PUBLIC_ void ndr_print_function_debug(ndr_print_function_t fn, const char *name, int flags, void *ptr)
253 struct ndr_print *ndr;
255 ndr = talloc_zero(NULL, struct ndr_print);
257 ndr->print = ndr_print_debug_helper;
260 fn(ndr, name, flags, ptr);
265 a useful helper function for printing idl structures to a string
267 _PUBLIC_ char *ndr_print_struct_string(TALLOC_CTX *mem_ctx, ndr_print_fn_t fn, const char *name, void *ptr)
269 struct ndr_print *ndr;
272 ndr = talloc_zero(mem_ctx, struct ndr_print);
273 if (!ndr) return NULL;
274 ndr->private_data = talloc_strdup(ndr, "");
275 if (!ndr->private_data) {
278 ndr->print = ndr_print_string_helper;
282 ret = talloc_steal(mem_ctx, (char *)ndr->private_data);
289 a useful helper function for printing idl unions to a string
291 _PUBLIC_ char *ndr_print_union_string(TALLOC_CTX *mem_ctx, ndr_print_fn_t fn, const char *name, uint32_t level, void *ptr)
293 struct ndr_print *ndr;
296 ndr = talloc_zero(mem_ctx, struct ndr_print);
297 if (!ndr) return NULL;
298 ndr->private_data = talloc_strdup(ndr, "");
299 if (!ndr->private_data) {
302 ndr->print = ndr_print_string_helper;
305 ndr_print_set_switch_value(ndr, ptr, level);
307 ret = talloc_steal(mem_ctx, (char *)ndr->private_data);
314 a useful helper function for printing idl function calls to a string
316 _PUBLIC_ char *ndr_print_function_string(TALLOC_CTX *mem_ctx,
317 ndr_print_function_t fn, const char *name,
318 int flags, void *ptr)
320 struct ndr_print *ndr;
323 ndr = talloc_zero(mem_ctx, struct ndr_print);
324 if (!ndr) return NULL;
325 ndr->private_data = talloc_strdup(ndr, "");
326 if (!ndr->private_data) {
329 ndr->print = ndr_print_string_helper;
332 fn(ndr, name, flags, ptr);
333 ret = talloc_steal(mem_ctx, (char *)ndr->private_data);
339 _PUBLIC_ void ndr_set_flags(uint32_t *pflags, uint32_t new_flags)
341 /* the big/little endian flags are inter-dependent */
342 if (new_flags & LIBNDR_FLAG_LITTLE_ENDIAN) {
343 (*pflags) &= ~LIBNDR_FLAG_BIGENDIAN;
345 if (new_flags & LIBNDR_FLAG_BIGENDIAN) {
346 (*pflags) &= ~LIBNDR_FLAG_LITTLE_ENDIAN;
348 if (new_flags & LIBNDR_FLAG_REMAINING) {
349 (*pflags) &= ~LIBNDR_ALIGN_FLAGS;
351 if (new_flags & LIBNDR_ALIGN_FLAGS) {
352 (*pflags) &= ~LIBNDR_FLAG_REMAINING;
354 (*pflags) |= new_flags;
357 static NTSTATUS ndr_map_error(enum ndr_err_code ndr_err)
360 case NDR_ERR_BUFSIZE:
361 return NT_STATUS_BUFFER_TOO_SMALL;
363 return NT_STATUS_INTERNAL_ERROR;
365 return NT_STATUS_NO_MEMORY;
366 case NDR_ERR_ARRAY_SIZE:
367 return NT_STATUS_ARRAY_BOUNDS_EXCEEDED;
372 /* we should map all error codes to different status codes */
373 return NT_STATUS_INVALID_PARAMETER;
377 return and possibly log an NDR error
379 _PUBLIC_ NTSTATUS ndr_pull_error(struct ndr_pull *ndr,
380 enum ndr_err_code ndr_err,
381 const char *format, ...) _PRINTF_ATTRIBUTE(3,4)
386 va_start(ap, format);
387 vasprintf(&s, format, ap);
390 DEBUG(3,("ndr_pull_error(%u): %s\n", ndr_err, s));
394 return ndr_map_error(ndr_err);
398 return and possibly log an NDR error
400 _PUBLIC_ NTSTATUS ndr_push_error(struct ndr_push *ndr,
401 enum ndr_err_code ndr_err,
402 const char *format, ...) _PRINTF_ATTRIBUTE(3,4)
407 va_start(ap, format);
408 vasprintf(&s, format, ap);
411 DEBUG(3,("ndr_push_error(%u): %s\n", ndr_err, s));
415 return ndr_map_error(ndr_err);
419 handle subcontext buffers, which in midl land are user-marshalled, but
420 we use magic in pidl to make them easier to cope with
422 _PUBLIC_ NTSTATUS ndr_pull_subcontext_start(struct ndr_pull *ndr,
423 struct ndr_pull **_subndr,
427 struct ndr_pull *subndr;
428 uint32_t r_content_size;
430 switch (header_size) {
432 uint32_t content_size = ndr->data_size - ndr->offset;
434 content_size = size_is;
436 r_content_size = content_size;
441 uint16_t content_size;
442 NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &content_size));
443 if (size_is >= 0 && size_is != content_size) {
444 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) size_is(%d) mismatch content_size %d",
445 (int)size_is, (int)content_size);
447 r_content_size = content_size;
452 uint32_t content_size;
453 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &content_size));
454 if (size_is >= 0 && size_is != content_size) {
455 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) size_is(%d) mismatch content_size %d",
456 (int)size_is, (int)content_size);
458 r_content_size = content_size;
462 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) header_size %d",
466 NDR_PULL_NEED_BYTES(ndr, r_content_size);
468 subndr = talloc_zero(ndr, struct ndr_pull);
469 NT_STATUS_HAVE_NO_MEMORY(subndr);
470 subndr->flags = ndr->flags;
471 subndr->current_mem_ctx = ndr->current_mem_ctx;
473 subndr->data = ndr->data + ndr->offset;
475 subndr->data_size = r_content_size;
481 _PUBLIC_ NTSTATUS ndr_pull_subcontext_end(struct ndr_pull *ndr,
482 struct ndr_pull *subndr,
489 } else if (header_size > 0) {
490 advance = subndr->data_size;
492 advance = subndr->offset;
494 NDR_CHECK(ndr_pull_advance(ndr, advance));
498 _PUBLIC_ NTSTATUS ndr_push_subcontext_start(struct ndr_push *ndr,
499 struct ndr_push **_subndr,
503 struct ndr_push *subndr;
505 subndr = ndr_push_init_ctx(ndr);
506 NT_STATUS_HAVE_NO_MEMORY(subndr);
507 subndr->flags = ndr->flags;
514 push a subcontext header
516 _PUBLIC_ NTSTATUS ndr_push_subcontext_end(struct ndr_push *ndr,
517 struct ndr_push *subndr,
522 ssize_t padding_len = size_is - subndr->offset;
523 if (padding_len > 0) {
524 NDR_CHECK(ndr_push_zero(subndr, padding_len));
525 } else if (padding_len < 0) {
526 return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PUSH) content_size %d is larger than size_is(%d)",
527 (int)subndr->offset, (int)size_is);
531 switch (header_size) {
536 NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, subndr->offset));
540 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, subndr->offset));
544 return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext header size %d",
548 NDR_CHECK(ndr_push_bytes(ndr, subndr->data, subndr->offset));
553 store a token in the ndr context, for later retrieval
555 _PUBLIC_ NTSTATUS ndr_token_store(TALLOC_CTX *mem_ctx,
556 struct ndr_token_list **list,
560 struct ndr_token_list *tok;
561 tok = talloc(mem_ctx, struct ndr_token_list);
563 return NT_STATUS_NO_MEMORY;
567 DLIST_ADD((*list), tok);
572 retrieve a token from a ndr context, using cmp_fn to match the tokens
574 _PUBLIC_ NTSTATUS ndr_token_retrieve_cmp_fn(struct ndr_token_list **list, const void *key, uint32_t *v,
575 comparison_fn_t _cmp_fn, bool _remove_tok)
577 struct ndr_token_list *tok;
578 for (tok=*list;tok;tok=tok->next) {
579 if (_cmp_fn && _cmp_fn(tok->key,key)==0) goto found;
580 else if (!_cmp_fn && tok->key == key) goto found;
582 return ndr_map_error(NDR_ERR_TOKEN);
586 DLIST_REMOVE((*list), tok);
593 retrieve a token from a ndr context
595 _PUBLIC_ NTSTATUS ndr_token_retrieve(struct ndr_token_list **list, const void *key, uint32_t *v)
597 return ndr_token_retrieve_cmp_fn(list, key, v, NULL, true);
601 peek at but don't removed a token from a ndr context
603 _PUBLIC_ uint32_t ndr_token_peek(struct ndr_token_list **list, const void *key)
607 status = ndr_token_retrieve_cmp_fn(list, key, &v, NULL, false);
608 if (NT_STATUS_IS_OK(status)) return v;
613 pull an array size field and add it to the array_size_list token list
615 _PUBLIC_ NTSTATUS ndr_pull_array_size(struct ndr_pull *ndr, const void *p)
618 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &size));
619 return ndr_token_store(ndr, &ndr->array_size_list, p, size);
623 get the stored array size field
625 _PUBLIC_ uint32_t ndr_get_array_size(struct ndr_pull *ndr, const void *p)
627 return ndr_token_peek(&ndr->array_size_list, p);
631 check the stored array size field
633 _PUBLIC_ NTSTATUS ndr_check_array_size(struct ndr_pull *ndr, void *p, uint32_t size)
636 stored = ndr_token_peek(&ndr->array_size_list, p);
637 if (stored != size) {
638 return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE,
639 "Bad array size - got %u expected %u\n",
646 pull an array length field and add it to the array_length_list token list
648 _PUBLIC_ NTSTATUS ndr_pull_array_length(struct ndr_pull *ndr, const void *p)
650 uint32_t length, offset;
651 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &offset));
653 return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE,
654 "non-zero array offset %u\n", offset);
656 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &length));
657 return ndr_token_store(ndr, &ndr->array_length_list, p, length);
661 get the stored array length field
663 _PUBLIC_ uint32_t ndr_get_array_length(struct ndr_pull *ndr, const void *p)
665 return ndr_token_peek(&ndr->array_length_list, p);
669 check the stored array length field
671 _PUBLIC_ NTSTATUS ndr_check_array_length(struct ndr_pull *ndr, void *p, uint32_t length)
674 stored = ndr_token_peek(&ndr->array_length_list, p);
675 if (stored != length) {
676 return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE,
677 "Bad array length - got %u expected %u\n",
686 _PUBLIC_ NTSTATUS ndr_push_set_switch_value(struct ndr_push *ndr, const void *p, uint32_t val)
688 return ndr_token_store(ndr, &ndr->switch_list, p, val);
691 _PUBLIC_ NTSTATUS ndr_pull_set_switch_value(struct ndr_pull *ndr, const void *p, uint32_t val)
693 return ndr_token_store(ndr, &ndr->switch_list, p, val);
696 _PUBLIC_ NTSTATUS ndr_print_set_switch_value(struct ndr_print *ndr, const void *p, uint32_t val)
698 return ndr_token_store(ndr, &ndr->switch_list, p, val);
702 retrieve a switch value
704 _PUBLIC_ uint32_t ndr_push_get_switch_value(struct ndr_push *ndr, const void *p)
706 return ndr_token_peek(&ndr->switch_list, p);
709 _PUBLIC_ uint32_t ndr_pull_get_switch_value(struct ndr_pull *ndr, const void *p)
711 return ndr_token_peek(&ndr->switch_list, p);
714 _PUBLIC_ uint32_t ndr_print_get_switch_value(struct ndr_print *ndr, const void *p)
716 return ndr_token_peek(&ndr->switch_list, p);
720 pull a struct from a blob using NDR
722 _PUBLIC_ NTSTATUS ndr_pull_struct_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
723 ndr_pull_flags_fn_t fn)
725 struct ndr_pull *ndr;
726 ndr = ndr_pull_init_blob(blob, mem_ctx);
728 return NT_STATUS_NO_MEMORY;
730 return fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
734 pull a struct from a blob using NDR - failing if all bytes are not consumed
736 _PUBLIC_ NTSTATUS ndr_pull_struct_blob_all(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
737 ndr_pull_flags_fn_t fn)
739 struct ndr_pull *ndr;
742 ndr = ndr_pull_init_blob(blob, mem_ctx);
744 return NT_STATUS_NO_MEMORY;
746 status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
747 if (!NT_STATUS_IS_OK(status)) return status;
748 if (ndr->offset < ndr->data_size) {
749 return NT_STATUS_PORT_MESSAGE_TOO_LONG;
755 pull a union from a blob using NDR, given the union discriminator
757 _PUBLIC_ NTSTATUS ndr_pull_union_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
758 uint32_t level, ndr_pull_flags_fn_t fn)
760 struct ndr_pull *ndr;
763 ndr = ndr_pull_init_blob(blob, mem_ctx);
765 return NT_STATUS_NO_MEMORY;
767 ndr_pull_set_switch_value(ndr, p, level);
768 status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
769 if (!NT_STATUS_IS_OK(status)) return status;
770 if (ndr->offset != ndr->data_size) {
771 return NT_STATUS_BUFFER_TOO_SMALL;
777 push a struct to a blob using NDR
779 _PUBLIC_ NTSTATUS ndr_push_struct_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, const void *p,
780 ndr_push_flags_fn_t fn)
783 struct ndr_push *ndr;
784 ndr = ndr_push_init_ctx(mem_ctx);
786 return NT_STATUS_NO_MEMORY;
788 status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
789 if (!NT_STATUS_IS_OK(status)) {
793 *blob = ndr_push_blob(ndr);
794 talloc_steal(mem_ctx, blob->data);
801 push a union to a blob using NDR
803 _PUBLIC_ NTSTATUS ndr_push_union_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
804 uint32_t level, ndr_push_flags_fn_t fn)
807 struct ndr_push *ndr;
808 ndr = ndr_push_init_ctx(mem_ctx);
810 return NT_STATUS_NO_MEMORY;
812 ndr_push_set_switch_value(ndr, p, level);
813 status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
814 if (!NT_STATUS_IS_OK(status)) {
818 *blob = ndr_push_blob(ndr);
819 talloc_steal(mem_ctx, blob->data);
826 generic ndr_size_*() handler for structures
828 _PUBLIC_ size_t ndr_size_struct(const void *p, int flags, ndr_push_flags_fn_t push)
830 struct ndr_push *ndr;
834 /* avoid recursion */
835 if (flags & LIBNDR_FLAG_NO_NDR_SIZE) return 0;
837 ndr = ndr_push_init_ctx(NULL);
839 ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE;
840 status = push(ndr, NDR_SCALARS|NDR_BUFFERS, discard_const(p));
841 if (!NT_STATUS_IS_OK(status)) {
850 generic ndr_size_*() handler for unions
852 _PUBLIC_ size_t ndr_size_union(const void *p, int flags, uint32_t level, ndr_push_flags_fn_t push)
854 struct ndr_push *ndr;
858 /* avoid recursion */
859 if (flags & LIBNDR_FLAG_NO_NDR_SIZE) return 0;
861 ndr = ndr_push_init_ctx(NULL);
863 ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE;
864 ndr_push_set_switch_value(ndr, p, level);
865 status = push(ndr, NDR_SCALARS|NDR_BUFFERS, p);
866 if (!NT_STATUS_IS_OK(status)) {
875 get the current base for relative pointers for the push
877 _PUBLIC_ uint32_t ndr_push_get_relative_base_offset(struct ndr_push *ndr)
879 return ndr->relative_base_offset;
883 restore the old base for relative pointers for the push
885 _PUBLIC_ void ndr_push_restore_relative_base_offset(struct ndr_push *ndr, uint32_t offset)
887 ndr->relative_base_offset = offset;
891 setup the current base for relative pointers for the push
892 called in the NDR_SCALAR stage
894 _PUBLIC_ NTSTATUS ndr_push_setup_relative_base_offset1(struct ndr_push *ndr, const void *p, uint32_t offset)
896 ndr->relative_base_offset = offset;
897 return ndr_token_store(ndr, &ndr->relative_base_list, p, offset);
901 setup the current base for relative pointers for the push
902 called in the NDR_BUFFERS stage
904 _PUBLIC_ NTSTATUS ndr_push_setup_relative_base_offset2(struct ndr_push *ndr, const void *p)
906 return ndr_token_retrieve(&ndr->relative_base_list, p, &ndr->relative_base_offset);
910 push a relative object - stage1
911 this is called during SCALARS processing
913 _PUBLIC_ NTSTATUS ndr_push_relative_ptr1(struct ndr_push *ndr, const void *p)
916 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0));
919 NDR_CHECK(ndr_push_align(ndr, 4));
920 NDR_CHECK(ndr_token_store(ndr, &ndr->relative_list, p, ndr->offset));
921 return ndr_push_uint32(ndr, NDR_SCALARS, 0xFFFFFFFF);
925 push a relative object - stage2
926 this is called during buffers processing
928 _PUBLIC_ NTSTATUS ndr_push_relative_ptr2(struct ndr_push *ndr, const void *p)
930 struct ndr_push_save save;
931 uint32_t ptr_offset = 0xFFFFFFFF;
935 ndr_push_save(ndr, &save);
936 NDR_CHECK(ndr_token_retrieve(&ndr->relative_list, p, &ptr_offset));
937 if (ptr_offset > ndr->offset) {
938 return ndr_push_error(ndr, NDR_ERR_BUFSIZE,
939 "ndr_push_relative_ptr2 ptr_offset(%u) > ndr->offset(%u)",
940 ptr_offset, ndr->offset);
942 ndr->offset = ptr_offset;
943 if (save.offset < ndr->relative_base_offset) {
944 return ndr_push_error(ndr, NDR_ERR_BUFSIZE,
945 "ndr_push_relative_ptr2 save.offset(%u) < ndr->relative_base_offset(%u)",
946 save.offset, ndr->relative_base_offset);
948 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, save.offset - ndr->relative_base_offset));
949 ndr_push_restore(ndr, &save);
954 get the current base for relative pointers for the pull
956 _PUBLIC_ uint32_t ndr_pull_get_relative_base_offset(struct ndr_pull *ndr)
958 return ndr->relative_base_offset;
962 restore the old base for relative pointers for the pull
964 _PUBLIC_ void ndr_pull_restore_relative_base_offset(struct ndr_pull *ndr, uint32_t offset)
966 ndr->relative_base_offset = offset;
970 setup the current base for relative pointers for the pull
971 called in the NDR_SCALAR stage
973 _PUBLIC_ NTSTATUS ndr_pull_setup_relative_base_offset1(struct ndr_pull *ndr, const void *p, uint32_t offset)
975 ndr->relative_base_offset = offset;
976 return ndr_token_store(ndr, &ndr->relative_base_list, p, offset);
980 setup the current base for relative pointers for the pull
981 called in the NDR_BUFFERS stage
983 _PUBLIC_ NTSTATUS ndr_pull_setup_relative_base_offset2(struct ndr_pull *ndr, const void *p)
985 return ndr_token_retrieve(&ndr->relative_base_list, p, &ndr->relative_base_offset);
989 pull a relative object - stage1
990 called during SCALARS processing
992 _PUBLIC_ NTSTATUS ndr_pull_relative_ptr1(struct ndr_pull *ndr, const void *p, uint32_t rel_offset)
994 rel_offset += ndr->relative_base_offset;
995 if (rel_offset > ndr->data_size) {
996 return ndr_pull_error(ndr, NDR_ERR_BUFSIZE,
997 "ndr_pull_relative_ptr1 rel_offset(%u) > ndr->data_size(%u)",
998 rel_offset, ndr->data_size);
1000 return ndr_token_store(ndr, &ndr->relative_list, p, rel_offset);
1004 pull a relative object - stage2
1005 called during BUFFERS processing
1007 _PUBLIC_ NTSTATUS ndr_pull_relative_ptr2(struct ndr_pull *ndr, const void *p)
1009 uint32_t rel_offset;
1010 NDR_CHECK(ndr_token_retrieve(&ndr->relative_list, p, &rel_offset));
1011 return ndr_pull_set_offset(ndr, rel_offset);