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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 this provides the core routines for NDR parsing functions
26 see http://www.opengroup.org/onlinepubs/9629399/chap14.htm for details
31 #include "librpc/ndr/libndr.h"
32 #include "dlinklist.h"
33 #include "librpc/gen_ndr/dcerpc.h"
35 #define NDR_BASE_MARSHALL_SIZE 1024
37 /* this guid indicates NDR encoding in a protocol tower */
38 const struct dcerpc_syntax_id ndr_transfer_syntax = {
39 { 0x8a885d04, 0x1ceb, 0x11c9, {0x9f, 0xe8}, {0x08,0x00,0x2b,0x10,0x48,0x60} },
43 const struct dcerpc_syntax_id ndr64_transfer_syntax = {
44 { 0x71710533, 0xbeba, 0x4937, {0x83, 0x19}, {0xb5,0xdb,0xef,0x9c,0xcc,0x36} },
49 work out the number of bytes needed to align on a n byte boundary
51 _PUBLIC_ size_t ndr_align_size(uint32_t offset, size_t n)
53 if ((offset & (n-1)) == 0) return 0;
54 return n - (offset & (n-1));
58 initialise a ndr parse structure from a data blob
60 _PUBLIC_ struct ndr_pull *ndr_pull_init_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx)
64 ndr = talloc_zero(mem_ctx, struct ndr_pull);
65 if (!ndr) return NULL;
66 ndr->current_mem_ctx = mem_ctx;
68 ndr->data = blob->data;
69 ndr->data_size = blob->length;
75 advance by 'size' bytes
77 _PUBLIC_ NTSTATUS ndr_pull_advance(struct ndr_pull *ndr, uint32_t size)
80 if (ndr->offset > ndr->data_size) {
81 return ndr_pull_error(ndr, NDR_ERR_BUFSIZE,
82 "ndr_pull_advance by %u failed",
89 set the parse offset to 'ofs'
91 static NTSTATUS ndr_pull_set_offset(struct ndr_pull *ndr, uint32_t ofs)
94 if (ndr->offset > ndr->data_size) {
95 return ndr_pull_error(ndr, NDR_ERR_BUFSIZE,
96 "ndr_pull_set_offset %u failed",
102 /* save the offset/size of the current ndr state */
103 _PUBLIC_ void ndr_pull_save(struct ndr_pull *ndr, struct ndr_pull_save *save)
105 save->offset = ndr->offset;
106 save->data_size = ndr->data_size;
109 /* restore the size/offset of a ndr structure */
110 _PUBLIC_ void ndr_pull_restore(struct ndr_pull *ndr, struct ndr_pull_save *save)
112 ndr->offset = save->offset;
113 ndr->data_size = save->data_size;
117 /* create a ndr_push structure, ready for some marshalling */
118 _PUBLIC_ struct ndr_push *ndr_push_init_ctx(TALLOC_CTX *mem_ctx)
120 struct ndr_push *ndr;
122 ndr = talloc_zero(mem_ctx, struct ndr_push);
128 ndr->alloc_size = NDR_BASE_MARSHALL_SIZE;
129 ndr->data = talloc_array(ndr, uint8_t, ndr->alloc_size);
138 /* create a ndr_push structure, ready for some marshalling */
139 _PUBLIC_ struct ndr_push *ndr_push_init(void)
141 return ndr_push_init_ctx(NULL);
144 /* free a ndr_push structure */
145 _PUBLIC_ void ndr_push_free(struct ndr_push *ndr)
151 /* return a DATA_BLOB structure for the current ndr_push marshalled data */
152 _PUBLIC_ DATA_BLOB ndr_push_blob(struct ndr_push *ndr)
155 blob.data = ndr->data;
156 blob.length = ndr->offset;
157 if (ndr->alloc_size > ndr->offset) {
158 ndr->data[ndr->offset] = 0;
165 expand the available space in the buffer to 'size'
167 _PUBLIC_ NTSTATUS ndr_push_expand(struct ndr_push *ndr, uint32_t size)
169 if (ndr->alloc_size > size) {
173 ndr->alloc_size += NDR_BASE_MARSHALL_SIZE;
174 if (size+1 > ndr->alloc_size) {
175 ndr->alloc_size = size+1;
177 ndr->data = talloc_realloc(ndr, ndr->data, uint8_t, ndr->alloc_size);
179 return ndr_push_error(ndr, NDR_ERR_ALLOC, "Failed to push_expand to %u",
186 _PUBLIC_ void ndr_print_debug_helper(struct ndr_print *ndr, const char *format, ...) _PRINTF_ATTRIBUTE(2,3)
192 va_start(ap, format);
193 vasprintf(&s, format, ap);
196 for (i=0;i<ndr->depth;i++) {
200 DEBUG(0,("%s\n", s));
204 static void ndr_print_string_helper(struct ndr_print *ndr, const char *format, ...) _PRINTF_ATTRIBUTE(2,3)
209 for (i=0;i<ndr->depth;i++) {
210 ndr->private = talloc_asprintf_append(ndr->private, " ");
213 va_start(ap, format);
214 ndr->private = talloc_vasprintf_append(ndr->private, format, ap);
216 ndr->private = talloc_asprintf_append(ndr->private, "\n");
220 a useful helper function for printing idl structures via DEBUG()
222 _PUBLIC_ void ndr_print_debug(ndr_print_fn_t fn, const char *name, void *ptr)
224 struct ndr_print *ndr;
226 ndr = talloc_zero(NULL, struct ndr_print);
228 ndr->print = ndr_print_debug_helper;
236 a useful helper function for printing idl unions via DEBUG()
238 _PUBLIC_ void ndr_print_union_debug(ndr_print_fn_t fn, const char *name, uint32_t level, void *ptr)
240 struct ndr_print *ndr;
242 ndr = talloc_zero(NULL, struct ndr_print);
244 ndr->print = ndr_print_debug_helper;
247 ndr_print_set_switch_value(ndr, ptr, level);
253 a useful helper function for printing idl function calls via DEBUG()
255 _PUBLIC_ void ndr_print_function_debug(ndr_print_function_t fn, const char *name, int flags, void *ptr)
257 struct ndr_print *ndr;
259 ndr = talloc_zero(NULL, struct ndr_print);
261 ndr->print = ndr_print_debug_helper;
264 fn(ndr, name, flags, ptr);
270 a useful helper function for printing idl function calls to a string
272 _PUBLIC_ char *ndr_print_function_string(TALLOC_CTX *mem_ctx,
273 ndr_print_function_t fn, const char *name,
274 int flags, void *ptr)
276 struct ndr_print *ndr;
279 ndr = talloc_zero(mem_ctx, struct ndr_print);
280 if (!ndr) return NULL;
281 ndr->private = talloc_strdup(ndr, "");
285 ndr->print = ndr_print_string_helper;
288 fn(ndr, name, flags, ptr);
289 ret = talloc_steal(mem_ctx, ndr->private);
295 _PUBLIC_ void ndr_set_flags(uint32_t *pflags, uint32_t new_flags)
297 /* the big/little endian flags are inter-dependent */
298 if (new_flags & LIBNDR_FLAG_LITTLE_ENDIAN) {
299 (*pflags) &= ~LIBNDR_FLAG_BIGENDIAN;
301 if (new_flags & LIBNDR_FLAG_BIGENDIAN) {
302 (*pflags) &= ~LIBNDR_FLAG_LITTLE_ENDIAN;
304 if (new_flags & LIBNDR_FLAG_REMAINING) {
305 (*pflags) &= ~LIBNDR_ALIGN_FLAGS;
307 if (new_flags & LIBNDR_ALIGN_FLAGS) {
308 (*pflags) &= ~LIBNDR_FLAG_REMAINING;
310 (*pflags) |= new_flags;
313 static NTSTATUS ndr_map_error(enum ndr_err_code err)
316 case NDR_ERR_BUFSIZE:
317 return NT_STATUS_BUFFER_TOO_SMALL;
319 return NT_STATUS_INTERNAL_ERROR;
321 return NT_STATUS_NO_MEMORY;
322 case NDR_ERR_ARRAY_SIZE:
323 return NT_STATUS_ARRAY_BOUNDS_EXCEEDED;
328 /* we should map all error codes to different status codes */
329 return NT_STATUS_INVALID_PARAMETER;
333 return and possibly log an NDR error
335 _PUBLIC_ NTSTATUS ndr_pull_error(struct ndr_pull *ndr,
336 enum ndr_err_code err, const char *format, ...) _PRINTF_ATTRIBUTE(3,4)
341 va_start(ap, format);
342 vasprintf(&s, format, ap);
345 DEBUG(3,("ndr_pull_error(%u): %s\n", err, s));
349 return ndr_map_error(err);
353 return and possibly log an NDR error
355 _PUBLIC_ NTSTATUS ndr_push_error(struct ndr_push *ndr, enum ndr_err_code err, const char *format, ...) _PRINTF_ATTRIBUTE(3,4)
360 va_start(ap, format);
361 vasprintf(&s, format, ap);
364 DEBUG(3,("ndr_push_error(%u): %s\n", err, s));
368 return ndr_map_error(err);
372 handle subcontext buffers, which in midl land are user-marshalled, but
373 we use magic in pidl to make them easier to cope with
375 _PUBLIC_ NTSTATUS ndr_pull_subcontext_start(struct ndr_pull *ndr,
376 struct ndr_pull **_subndr,
380 struct ndr_pull *subndr;
381 uint32_t r_content_size;
383 switch (header_size) {
385 uint32_t content_size = ndr->data_size - ndr->offset;
387 content_size = size_is;
389 r_content_size = content_size;
394 uint16_t content_size;
395 NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &content_size));
396 if (size_is >= 0 && size_is != content_size) {
397 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) size_is(%d) mismatch content_size %d",
398 (int)size_is, (int)content_size);
400 r_content_size = content_size;
405 uint32_t content_size;
406 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &content_size));
407 if (size_is >= 0 && size_is != content_size) {
408 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) size_is(%d) mismatch content_size %d",
409 (int)size_is, (int)content_size);
411 r_content_size = content_size;
415 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) header_size %d",
419 NDR_PULL_NEED_BYTES(ndr, r_content_size);
421 subndr = talloc_zero(ndr, struct ndr_pull);
422 NT_STATUS_HAVE_NO_MEMORY(subndr);
423 subndr->flags = ndr->flags;
424 subndr->current_mem_ctx = ndr->current_mem_ctx;
426 subndr->data = ndr->data + ndr->offset;
428 subndr->data_size = r_content_size;
434 _PUBLIC_ NTSTATUS ndr_pull_subcontext_end(struct ndr_pull *ndr,
435 struct ndr_pull *subndr,
442 } else if (header_size > 0) {
443 advance = subndr->data_size;
445 advance = subndr->offset;
447 NDR_CHECK(ndr_pull_advance(ndr, advance));
451 _PUBLIC_ NTSTATUS ndr_push_subcontext_start(struct ndr_push *ndr,
452 struct ndr_push **_subndr,
456 struct ndr_push *subndr;
458 subndr = ndr_push_init_ctx(ndr);
459 NT_STATUS_HAVE_NO_MEMORY(subndr);
460 subndr->flags = ndr->flags;
467 push a subcontext header
469 _PUBLIC_ NTSTATUS ndr_push_subcontext_end(struct ndr_push *ndr,
470 struct ndr_push *subndr,
475 ssize_t padding_len = size_is - subndr->offset;
476 if (padding_len > 0) {
477 NDR_CHECK(ndr_push_zero(subndr, padding_len));
478 } else if (padding_len < 0) {
479 return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PUSH) content_size %d is larger than size_is(%d)",
480 (int)subndr->offset, (int)size_is);
484 switch (header_size) {
489 NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, subndr->offset));
493 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, subndr->offset));
497 return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext header size %d",
501 NDR_CHECK(ndr_push_bytes(ndr, subndr->data, subndr->offset));
506 store a token in the ndr context, for later retrieval
508 _PUBLIC_ NTSTATUS ndr_token_store(TALLOC_CTX *mem_ctx,
509 struct ndr_token_list **list,
513 struct ndr_token_list *tok;
514 tok = talloc(mem_ctx, struct ndr_token_list);
516 return NT_STATUS_NO_MEMORY;
520 DLIST_ADD((*list), tok);
525 retrieve a token from a ndr context, using cmp_fn to match the tokens
527 _PUBLIC_ NTSTATUS ndr_token_retrieve_cmp_fn(struct ndr_token_list **list, const void *key, uint32_t *v,
528 comparison_fn_t _cmp_fn, BOOL _remove_tok)
530 struct ndr_token_list *tok;
531 for (tok=*list;tok;tok=tok->next) {
532 if (_cmp_fn && _cmp_fn(tok->key,key)==0) goto found;
533 else if (!_cmp_fn && tok->key == key) goto found;
535 return ndr_map_error(NDR_ERR_TOKEN);
539 DLIST_REMOVE((*list), tok);
546 retrieve a token from a ndr context
548 _PUBLIC_ NTSTATUS ndr_token_retrieve(struct ndr_token_list **list, const void *key, uint32_t *v)
550 return ndr_token_retrieve_cmp_fn(list, key, v, NULL, True);
554 peek at but don't removed a token from a ndr context
556 _PUBLIC_ uint32_t ndr_token_peek(struct ndr_token_list **list, const void *key)
560 status = ndr_token_retrieve_cmp_fn(list, key, &v, NULL, False);
561 if (NT_STATUS_IS_OK(status)) return v;
566 pull an array size field and add it to the array_size_list token list
568 _PUBLIC_ NTSTATUS ndr_pull_array_size(struct ndr_pull *ndr, const void *p)
571 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &size));
572 return ndr_token_store(ndr, &ndr->array_size_list, p, size);
576 get the stored array size field
578 _PUBLIC_ uint32_t ndr_get_array_size(struct ndr_pull *ndr, const void *p)
580 return ndr_token_peek(&ndr->array_size_list, p);
584 check the stored array size field
586 _PUBLIC_ NTSTATUS ndr_check_array_size(struct ndr_pull *ndr, void *p, uint32_t size)
589 stored = ndr_token_peek(&ndr->array_size_list, p);
590 if (stored != size) {
591 return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE,
592 "Bad array size - got %u expected %u\n",
599 pull an array length field and add it to the array_length_list token list
601 _PUBLIC_ NTSTATUS ndr_pull_array_length(struct ndr_pull *ndr, const void *p)
603 uint32_t length, offset;
604 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &offset));
606 return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE,
607 "non-zero array offset %u\n", offset);
609 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &length));
610 return ndr_token_store(ndr, &ndr->array_length_list, p, length);
614 get the stored array length field
616 _PUBLIC_ uint32_t ndr_get_array_length(struct ndr_pull *ndr, const void *p)
618 return ndr_token_peek(&ndr->array_length_list, p);
622 check the stored array length field
624 _PUBLIC_ NTSTATUS ndr_check_array_length(struct ndr_pull *ndr, void *p, uint32_t length)
627 stored = ndr_token_peek(&ndr->array_length_list, p);
628 if (stored != length) {
629 return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE,
630 "Bad array length - got %u expected %u\n",
639 _PUBLIC_ NTSTATUS ndr_push_set_switch_value(struct ndr_push *ndr, const void *p, uint32_t val)
641 return ndr_token_store(ndr, &ndr->switch_list, p, val);
644 _PUBLIC_ NTSTATUS ndr_pull_set_switch_value(struct ndr_pull *ndr, const void *p, uint32_t val)
646 return ndr_token_store(ndr, &ndr->switch_list, p, val);
649 _PUBLIC_ NTSTATUS ndr_print_set_switch_value(struct ndr_print *ndr, const void *p, uint32_t val)
651 return ndr_token_store(ndr, &ndr->switch_list, p, val);
655 retrieve a switch value
657 _PUBLIC_ uint32_t ndr_push_get_switch_value(struct ndr_push *ndr, const void *p)
659 return ndr_token_peek(&ndr->switch_list, p);
662 _PUBLIC_ uint32_t ndr_pull_get_switch_value(struct ndr_pull *ndr, const void *p)
664 return ndr_token_peek(&ndr->switch_list, p);
667 _PUBLIC_ uint32_t ndr_print_get_switch_value(struct ndr_print *ndr, const void *p)
669 return ndr_token_peek(&ndr->switch_list, p);
673 pull a struct from a blob using NDR
675 _PUBLIC_ NTSTATUS ndr_pull_struct_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
676 ndr_pull_flags_fn_t fn)
678 struct ndr_pull *ndr;
679 ndr = ndr_pull_init_blob(blob, mem_ctx);
681 return NT_STATUS_NO_MEMORY;
683 return fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
687 pull a struct from a blob using NDR - failing if all bytes are not consumed
689 _PUBLIC_ NTSTATUS ndr_pull_struct_blob_all(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
690 ndr_pull_flags_fn_t fn)
692 struct ndr_pull *ndr;
695 ndr = ndr_pull_init_blob(blob, mem_ctx);
697 return NT_STATUS_NO_MEMORY;
699 status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
700 if (!NT_STATUS_IS_OK(status)) return status;
701 if (ndr->offset != ndr->data_size) {
702 return NT_STATUS_BUFFER_TOO_SMALL;
708 pull a union from a blob using NDR, given the union discriminator
710 _PUBLIC_ NTSTATUS ndr_pull_union_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
711 uint32_t level, ndr_pull_flags_fn_t fn)
713 struct ndr_pull *ndr;
716 ndr = ndr_pull_init_blob(blob, mem_ctx);
718 return NT_STATUS_NO_MEMORY;
720 ndr_pull_set_switch_value(ndr, p, level);
721 status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
722 if (!NT_STATUS_IS_OK(status)) return status;
723 if (ndr->offset != ndr->data_size) {
724 return NT_STATUS_BUFFER_TOO_SMALL;
730 push a struct to a blob using NDR
732 _PUBLIC_ NTSTATUS ndr_push_struct_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, const void *p,
733 ndr_push_flags_fn_t fn)
736 struct ndr_push *ndr;
737 ndr = ndr_push_init_ctx(mem_ctx);
739 return NT_STATUS_NO_MEMORY;
741 status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
742 if (!NT_STATUS_IS_OK(status)) {
746 *blob = ndr_push_blob(ndr);
752 push a union to a blob using NDR
754 _PUBLIC_ NTSTATUS ndr_push_union_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
755 uint32_t level, ndr_push_flags_fn_t fn)
758 struct ndr_push *ndr;
759 ndr = ndr_push_init_ctx(mem_ctx);
761 return NT_STATUS_NO_MEMORY;
763 ndr_push_set_switch_value(ndr, p, level);
764 status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
765 if (!NT_STATUS_IS_OK(status)) {
769 *blob = ndr_push_blob(ndr);
775 generic ndr_size_*() handler for structures
777 _PUBLIC_ size_t ndr_size_struct(const void *p, int flags, ndr_push_flags_fn_t push)
779 struct ndr_push *ndr;
783 /* avoid recursion */
784 if (flags & LIBNDR_FLAG_NO_NDR_SIZE) return 0;
786 ndr = ndr_push_init_ctx(NULL);
788 ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE;
789 status = push(ndr, NDR_SCALARS|NDR_BUFFERS, discard_const(p));
790 if (!NT_STATUS_IS_OK(status)) {
799 generic ndr_size_*() handler for unions
801 _PUBLIC_ size_t ndr_size_union(const void *p, int flags, uint32_t level, ndr_push_flags_fn_t push)
803 struct ndr_push *ndr;
807 /* avoid recursion */
808 if (flags & LIBNDR_FLAG_NO_NDR_SIZE) return 0;
810 ndr = ndr_push_init_ctx(NULL);
812 ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE;
813 ndr_push_set_switch_value(ndr, p, level);
814 status = push(ndr, NDR_SCALARS|NDR_BUFFERS, p);
815 if (!NT_STATUS_IS_OK(status)) {
824 get the current base for relative pointers for the push
826 _PUBLIC_ uint32_t ndr_push_get_relative_base_offset(struct ndr_push *ndr)
828 return ndr->relative_base_offset;
832 restore the old base for relative pointers for the push
834 _PUBLIC_ void ndr_push_restore_relative_base_offset(struct ndr_push *ndr, uint32_t offset)
836 ndr->relative_base_offset = offset;
840 setup the current base for relative pointers for the push
841 called in the NDR_SCALAR stage
843 _PUBLIC_ NTSTATUS ndr_push_setup_relative_base_offset1(struct ndr_push *ndr, const void *p, uint32_t offset)
845 ndr->relative_base_offset = offset;
846 return ndr_token_store(ndr, &ndr->relative_base_list, p, offset);
850 setup the current base for relative pointers for the push
851 called in the NDR_BUFFERS stage
853 _PUBLIC_ NTSTATUS ndr_push_setup_relative_base_offset2(struct ndr_push *ndr, const void *p)
855 return ndr_token_retrieve(&ndr->relative_base_list, p, &ndr->relative_base_offset);
859 push a relative object - stage1
860 this is called during SCALARS processing
862 _PUBLIC_ NTSTATUS ndr_push_relative_ptr1(struct ndr_push *ndr, const void *p)
865 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0));
868 NDR_CHECK(ndr_push_align(ndr, 4));
869 NDR_CHECK(ndr_token_store(ndr, &ndr->relative_list, p, ndr->offset));
870 return ndr_push_uint32(ndr, NDR_SCALARS, 0xFFFFFFFF);
874 push a relative object - stage2
875 this is called during buffers processing
877 _PUBLIC_ NTSTATUS ndr_push_relative_ptr2(struct ndr_push *ndr, const void *p)
879 struct ndr_push_save save;
880 uint32_t ptr_offset = 0xFFFFFFFF;
884 ndr_push_save(ndr, &save);
885 NDR_CHECK(ndr_token_retrieve(&ndr->relative_list, p, &ptr_offset));
886 if (ptr_offset > ndr->offset) {
887 return ndr_push_error(ndr, NDR_ERR_BUFSIZE,
888 "ndr_push_relative_ptr2 ptr_offset(%u) > ndr->offset(%u)",
889 ptr_offset, ndr->offset);
891 ndr->offset = ptr_offset;
892 if (save.offset < ndr->relative_base_offset) {
893 return ndr_push_error(ndr, NDR_ERR_BUFSIZE,
894 "ndr_push_relative_ptr2 save.offset(%u) < ndr->relative_base_offset(%u)",
895 save.offset, ndr->relative_base_offset);
897 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, save.offset - ndr->relative_base_offset));
898 ndr_push_restore(ndr, &save);
903 get the current base for relative pointers for the pull
905 _PUBLIC_ uint32_t ndr_pull_get_relative_base_offset(struct ndr_pull *ndr)
907 return ndr->relative_base_offset;
911 restore the old base for relative pointers for the pull
913 _PUBLIC_ void ndr_pull_restore_relative_base_offset(struct ndr_pull *ndr, uint32_t offset)
915 ndr->relative_base_offset = offset;
919 setup the current base for relative pointers for the pull
920 called in the NDR_SCALAR stage
922 _PUBLIC_ NTSTATUS ndr_pull_setup_relative_base_offset1(struct ndr_pull *ndr, const void *p, uint32_t offset)
924 ndr->relative_base_offset = offset;
925 return ndr_token_store(ndr, &ndr->relative_base_list, p, offset);
929 setup the current base for relative pointers for the pull
930 called in the NDR_BUFFERS stage
932 _PUBLIC_ NTSTATUS ndr_pull_setup_relative_base_offset2(struct ndr_pull *ndr, const void *p)
934 return ndr_token_retrieve(&ndr->relative_base_list, p, &ndr->relative_base_offset);
938 pull a relative object - stage1
939 called during SCALARS processing
941 _PUBLIC_ NTSTATUS ndr_pull_relative_ptr1(struct ndr_pull *ndr, const void *p, uint32_t rel_offset)
943 rel_offset += ndr->relative_base_offset;
944 if (rel_offset > ndr->data_size) {
945 return ndr_pull_error(ndr, NDR_ERR_BUFSIZE,
946 "ndr_pull_relative_ptr1 rel_offset(%u) > ndr->data_size(%u)",
947 rel_offset, ndr->data_size);
949 return ndr_token_store(ndr, &ndr->relative_list, p, rel_offset);
953 pull a relative object - stage2
954 called during BUFFERS processing
956 _PUBLIC_ NTSTATUS ndr_pull_relative_ptr2(struct ndr_pull *ndr, const void *p)
959 NDR_CHECK(ndr_token_retrieve(&ndr->relative_list, p, &rel_offset));
960 return ndr_pull_set_offset(ndr, rel_offset);