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
31 #define NDR_BASE_MARSHALL_SIZE 1024
33 /* this guid indicates NDR encoding in a protocol tower */
34 const struct ndr_syntax_id ndr_transfer_syntax = {
35 { 0x8a885d04, 0x1ceb, 0x11c9, {0x9f, 0xe8}, {0x08,0x00,0x2b,0x10,0x48,0x60} },
39 const struct ndr_syntax_id ndr64_transfer_syntax = {
40 { 0x71710533, 0xbeba, 0x4937, {0x83, 0x19}, {0xb5,0xdb,0xef,0x9c,0xcc,0x36} },
45 work out the number of bytes needed to align on a n byte boundary
47 size_t ndr_align_size(uint32_t offset, size_t n)
49 if ((offset & (n-1)) == 0) return 0;
50 return n - (offset & (n-1));
54 initialise a ndr parse structure from a data blob
56 struct ndr_pull *ndr_pull_init_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx)
60 ndr = talloc_zero(mem_ctx, struct ndr_pull);
61 if (!ndr) return NULL;
62 ndr->current_mem_ctx = mem_ctx;
64 ndr->data = blob->data;
65 ndr->data_size = blob->length;
71 advance by 'size' bytes
73 NTSTATUS ndr_pull_advance(struct ndr_pull *ndr, uint32_t size)
76 if (ndr->offset > ndr->data_size) {
77 return ndr_pull_error(ndr, NDR_ERR_BUFSIZE,
78 "ndr_pull_advance by %u failed",
85 set the parse offset to 'ofs'
87 static NTSTATUS ndr_pull_set_offset(struct ndr_pull *ndr, uint32_t ofs)
90 if (ndr->offset > ndr->data_size) {
91 return ndr_pull_error(ndr, NDR_ERR_BUFSIZE,
92 "ndr_pull_set_offset %u failed",
98 /* save the offset/size of the current ndr state */
99 void ndr_pull_save(struct ndr_pull *ndr, struct ndr_pull_save *save)
101 save->offset = ndr->offset;
102 save->data_size = ndr->data_size;
105 /* restore the size/offset of a ndr structure */
106 void ndr_pull_restore(struct ndr_pull *ndr, struct ndr_pull_save *save)
108 ndr->offset = save->offset;
109 ndr->data_size = save->data_size;
113 /* create a ndr_push structure, ready for some marshalling */
114 struct ndr_push *ndr_push_init_ctx(TALLOC_CTX *mem_ctx)
116 struct ndr_push *ndr;
118 ndr = talloc_zero(mem_ctx, struct ndr_push);
124 ndr->alloc_size = NDR_BASE_MARSHALL_SIZE;
125 ndr->data = talloc_array(ndr, uint8_t, ndr->alloc_size);
134 /* create a ndr_push structure, ready for some marshalling */
135 struct ndr_push *ndr_push_init(void)
137 return ndr_push_init_ctx(NULL);
140 /* free a ndr_push structure */
141 void ndr_push_free(struct ndr_push *ndr)
147 /* return a DATA_BLOB structure for the current ndr_push marshalled data */
148 DATA_BLOB ndr_push_blob(struct ndr_push *ndr)
151 blob.data = ndr->data;
152 blob.length = ndr->offset;
154 if (ndr->alloc_size > ndr->offset) {
155 ndr->data[ndr->offset] = 0;
162 expand the available space in the buffer to ndr->offset + extra_size
164 NTSTATUS ndr_push_expand(struct ndr_push *ndr, uint32_t extra_size)
166 uint32_t size = extra_size + ndr->offset;
168 if (size < ndr->offset) {
169 /* extra_size overflowed the offset */
170 return ndr_push_error(ndr, NDR_ERR_BUFSIZE, "Overflow in push_expand to %u",
174 if (ndr->alloc_size > size) {
178 ndr->alloc_size += NDR_BASE_MARSHALL_SIZE;
179 if (size+1 > ndr->alloc_size) {
180 ndr->alloc_size = size+1;
182 ndr->data = talloc_realloc(ndr, ndr->data, uint8_t, ndr->alloc_size);
184 return ndr_push_error(ndr, NDR_ERR_ALLOC, "Failed to push_expand to %u",
191 void ndr_print_debug_helper(struct ndr_print *ndr, const char *format, ...) _PRINTF_ATTRIBUTE(2,3)
197 va_start(ap, format);
198 vasprintf(&s, format, ap);
201 for (i=0;i<ndr->depth;i++) {
205 DEBUGADD(0,("%s\n", s));
209 static void ndr_print_string_helper(struct ndr_print *ndr, const char *format, ...) _PRINTF_ATTRIBUTE(2,3)
214 for (i=0;i<ndr->depth;i++) {
215 ndr->private_data = talloc_asprintf_append(
216 (char *)ndr->private_data, " ");
219 va_start(ap, format);
220 ndr->private_data = talloc_vasprintf_append(
221 (char *)ndr->private_data, format, ap);
223 ndr->private_data = talloc_asprintf_append(
224 (char *)ndr->private_data, "\n");
228 a useful helper function for printing idl structures via DEBUG()
230 void ndr_print_debug(ndr_print_fn_t fn, const char *name, void *ptr)
232 struct ndr_print *ndr;
234 ndr = talloc_zero(NULL, struct ndr_print);
236 ndr->print = ndr_print_debug_helper;
244 a useful helper function for printing idl unions via DEBUG()
246 void ndr_print_union_debug(ndr_print_fn_t fn, const char *name, uint32_t level, void *ptr)
248 struct ndr_print *ndr;
250 ndr = talloc_zero(NULL, struct ndr_print);
252 ndr->print = ndr_print_debug_helper;
255 ndr_print_set_switch_value(ndr, ptr, level);
261 a useful helper function for printing idl function calls via DEBUG()
263 void ndr_print_function_debug(ndr_print_function_t fn, const char *name, int flags, void *ptr)
265 struct ndr_print *ndr;
267 ndr = talloc_zero(NULL, struct ndr_print);
269 ndr->print = ndr_print_debug_helper;
272 fn(ndr, name, flags, ptr);
278 a useful helper function for printing idl function calls to a string
280 char *ndr_print_function_string(TALLOC_CTX *mem_ctx,
281 ndr_print_function_t fn, const char *name,
282 int flags, void *ptr)
284 struct ndr_print *ndr;
287 ndr = talloc_zero(mem_ctx, struct ndr_print);
288 if (!ndr) return NULL;
289 if (!(ndr->private_data = talloc_strdup(mem_ctx, ""))) {
293 ndr->print = ndr_print_string_helper;
296 fn(ndr, name, flags, ptr);
297 ret = (char *)ndr->private_data;
302 void ndr_set_flags(uint32_t *pflags, uint32_t new_flags)
304 /* the big/little endian flags are inter-dependent */
305 if (new_flags & LIBNDR_FLAG_LITTLE_ENDIAN) {
306 (*pflags) &= ~LIBNDR_FLAG_BIGENDIAN;
308 if (new_flags & LIBNDR_FLAG_BIGENDIAN) {
309 (*pflags) &= ~LIBNDR_FLAG_LITTLE_ENDIAN;
311 if (new_flags & LIBNDR_FLAG_REMAINING) {
312 (*pflags) &= ~LIBNDR_ALIGN_FLAGS;
314 if (new_flags & LIBNDR_ALIGN_FLAGS) {
315 (*pflags) &= ~LIBNDR_FLAG_REMAINING;
317 (*pflags) |= new_flags;
320 static NTSTATUS ndr_map_error(enum ndr_err_code ndr_err)
323 case NDR_ERR_BUFSIZE:
324 return NT_STATUS_BUFFER_TOO_SMALL;
326 return NT_STATUS_INTERNAL_ERROR;
328 return NT_STATUS_NO_MEMORY;
329 case NDR_ERR_ARRAY_SIZE:
330 return NT_STATUS_ARRAY_BOUNDS_EXCEEDED;
331 case NDR_ERR_INVALID_POINTER:
332 return NT_STATUS_INVALID_PARAMETER_MIX;
337 /* we should map all error codes to different status codes */
338 return NT_STATUS_INVALID_PARAMETER;
342 return and possibly log an NDR error
344 NTSTATUS ndr_pull_error(struct ndr_pull *ndr,
345 enum ndr_err_code ndr_err,
346 const char *format, ...) _PRINTF_ATTRIBUTE(3,4)
351 va_start(ap, format);
352 vasprintf(&s, format, ap);
355 DEBUG(3,("ndr_pull_error(%u): %s\n", ndr_err, s));
359 return ndr_map_error(ndr_err);
363 return and possibly log an NDR error
365 NTSTATUS ndr_push_error(struct ndr_push *ndr,
366 enum ndr_err_code ndr_err,
367 const char *format, ...) _PRINTF_ATTRIBUTE(3,4)
372 va_start(ap, format);
373 vasprintf(&s, format, ap);
376 DEBUG(3,("ndr_push_error(%u): %s\n", ndr_err, s));
380 return ndr_map_error(ndr_err);
384 handle subcontext buffers, which in midl land are user-marshalled, but
385 we use magic in pidl to make them easier to cope with
387 NTSTATUS ndr_pull_subcontext_start(struct ndr_pull *ndr,
388 struct ndr_pull **_subndr,
392 struct ndr_pull *subndr;
393 uint32_t r_content_size;
395 switch (header_size) {
397 uint32_t content_size = ndr->data_size - ndr->offset;
399 content_size = size_is;
401 r_content_size = content_size;
406 uint16_t content_size;
407 NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &content_size));
408 if (size_is >= 0 && size_is != content_size) {
409 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) size_is(%d) mismatch content_size %d",
410 (int)size_is, (int)content_size);
412 r_content_size = content_size;
417 uint32_t content_size;
418 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &content_size));
419 if (size_is >= 0 && size_is != content_size) {
420 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) size_is(%d) mismatch content_size %d",
421 (int)size_is, (int)content_size);
423 r_content_size = content_size;
427 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) header_size %d",
431 NDR_PULL_NEED_BYTES(ndr, r_content_size);
433 subndr = talloc_zero(ndr, struct ndr_pull);
434 NT_STATUS_HAVE_NO_MEMORY(subndr);
435 subndr->flags = ndr->flags;
436 subndr->current_mem_ctx = ndr->current_mem_ctx;
438 subndr->data = ndr->data + ndr->offset;
440 subndr->data_size = r_content_size;
446 NTSTATUS ndr_pull_subcontext_end(struct ndr_pull *ndr,
447 struct ndr_pull *subndr,
454 } else if (header_size > 0) {
455 advance = subndr->data_size;
457 advance = subndr->offset;
459 NDR_CHECK(ndr_pull_advance(ndr, advance));
463 NTSTATUS ndr_push_subcontext_start(struct ndr_push *ndr,
464 struct ndr_push **_subndr,
468 struct ndr_push *subndr;
470 subndr = ndr_push_init_ctx(ndr);
471 NT_STATUS_HAVE_NO_MEMORY(subndr);
472 subndr->flags = ndr->flags;
479 push a subcontext header
481 NTSTATUS ndr_push_subcontext_end(struct ndr_push *ndr,
482 struct ndr_push *subndr,
487 ssize_t padding_len = size_is - subndr->offset;
488 if (padding_len > 0) {
489 NDR_CHECK(ndr_push_zero(subndr, padding_len));
490 } else if (padding_len < 0) {
491 return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PUSH) content_size %d is larger than size_is(%d)",
492 (int)subndr->offset, (int)size_is);
496 switch (header_size) {
501 NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, subndr->offset));
505 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, subndr->offset));
509 return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext header size %d",
513 NDR_CHECK(ndr_push_bytes(ndr, subndr->data, subndr->offset));
518 store a token in the ndr context, for later retrieval
520 NTSTATUS ndr_token_store(TALLOC_CTX *mem_ctx,
521 struct ndr_token_list **list,
525 struct ndr_token_list *tok;
526 tok = talloc(mem_ctx, struct ndr_token_list);
528 return NT_STATUS_NO_MEMORY;
532 DLIST_ADD((*list), tok);
537 retrieve a token from a ndr context, using cmp_fn to match the tokens
539 NTSTATUS ndr_token_retrieve_cmp_fn(struct ndr_token_list **list, const void *key, uint32_t *v,
540 comparison_fn_t _cmp_fn, bool _remove_tok)
542 struct ndr_token_list *tok;
543 for (tok=*list;tok;tok=tok->next) {
544 if (_cmp_fn && _cmp_fn(tok->key,key)==0) goto found;
545 else if (!_cmp_fn && tok->key == key) goto found;
547 return ndr_map_error(NDR_ERR_TOKEN);
551 DLIST_REMOVE((*list), tok);
558 retrieve a token from a ndr context
560 NTSTATUS ndr_token_retrieve(struct ndr_token_list **list, const void *key, uint32_t *v)
562 return ndr_token_retrieve_cmp_fn(list, key, v, NULL, True);
566 peek at but don't removed a token from a ndr context
568 uint32_t ndr_token_peek(struct ndr_token_list **list, const void *key)
572 status = ndr_token_retrieve_cmp_fn(list, key, &v, NULL, False);
573 if (NT_STATUS_IS_OK(status)) return v;
578 pull an array size field and add it to the array_size_list token list
580 NTSTATUS ndr_pull_array_size(struct ndr_pull *ndr, const void *p)
583 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &size));
584 return ndr_token_store(ndr, &ndr->array_size_list, p, size);
588 get the stored array size field
590 uint32_t ndr_get_array_size(struct ndr_pull *ndr, const void *p)
592 return ndr_token_peek(&ndr->array_size_list, p);
596 check the stored array size field
598 NTSTATUS ndr_check_array_size(struct ndr_pull *ndr, void *p, uint32_t size)
601 stored = ndr_token_peek(&ndr->array_size_list, p);
602 if (stored != size) {
603 return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE,
604 "Bad array size - got %u expected %u\n",
611 pull an array length field and add it to the array_length_list token list
613 NTSTATUS ndr_pull_array_length(struct ndr_pull *ndr, const void *p)
615 uint32_t length, offset;
616 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &offset));
618 return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE,
619 "non-zero array offset %u\n", offset);
621 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &length));
622 return ndr_token_store(ndr, &ndr->array_length_list, p, length);
626 get the stored array length field
628 uint32_t ndr_get_array_length(struct ndr_pull *ndr, const void *p)
630 return ndr_token_peek(&ndr->array_length_list, p);
634 check the stored array length field
636 NTSTATUS ndr_check_array_length(struct ndr_pull *ndr, void *p, uint32_t length)
639 stored = ndr_token_peek(&ndr->array_length_list, p);
640 if (stored != length) {
641 return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE,
642 "Bad array length - got %u expected %u\n",
651 NTSTATUS ndr_push_set_switch_value(struct ndr_push *ndr, const void *p, uint32_t val)
653 return ndr_token_store(ndr, &ndr->switch_list, p, val);
656 NTSTATUS ndr_pull_set_switch_value(struct ndr_pull *ndr, const void *p, uint32_t val)
658 return ndr_token_store(ndr, &ndr->switch_list, p, val);
661 NTSTATUS ndr_print_set_switch_value(struct ndr_print *ndr, const void *p, uint32_t val)
663 return ndr_token_store(ndr, &ndr->switch_list, p, val);
667 retrieve a switch value
669 uint32_t ndr_push_get_switch_value(struct ndr_push *ndr, const void *p)
671 return ndr_token_peek(&ndr->switch_list, p);
674 uint32_t ndr_pull_get_switch_value(struct ndr_pull *ndr, const void *p)
676 return ndr_token_peek(&ndr->switch_list, p);
679 uint32_t ndr_print_get_switch_value(struct ndr_print *ndr, const void *p)
681 return ndr_token_peek(&ndr->switch_list, p);
685 pull a struct from a blob using NDR
687 NTSTATUS ndr_pull_struct_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
688 ndr_pull_flags_fn_t fn)
690 struct ndr_pull *ndr;
691 ndr = ndr_pull_init_blob(blob, mem_ctx);
693 return NT_STATUS_NO_MEMORY;
695 return fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
699 pull a struct from a blob using NDR - failing if all bytes are not consumed
701 NTSTATUS ndr_pull_struct_blob_all(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
702 ndr_pull_flags_fn_t fn)
704 struct ndr_pull *ndr;
707 ndr = ndr_pull_init_blob(blob, mem_ctx);
709 return NT_STATUS_NO_MEMORY;
711 status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
712 if (!NT_STATUS_IS_OK(status)) return status;
713 if (ndr->offset < ndr->data_size) {
714 return NT_STATUS_PORT_MESSAGE_TOO_LONG;
720 pull a union from a blob using NDR, given the union discriminator
722 NTSTATUS ndr_pull_union_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
723 uint32_t level, ndr_pull_flags_fn_t fn)
725 struct ndr_pull *ndr;
728 ndr = ndr_pull_init_blob(blob, mem_ctx);
730 return NT_STATUS_NO_MEMORY;
732 ndr_pull_set_switch_value(ndr, p, level);
733 status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
734 if (!NT_STATUS_IS_OK(status)) return status;
735 if (ndr->offset != ndr->data_size) {
736 return NT_STATUS_BUFFER_TOO_SMALL;
742 push a struct to a blob using NDR
744 NTSTATUS ndr_push_struct_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, const void *p,
745 ndr_push_flags_fn_t fn)
748 struct ndr_push *ndr;
749 ndr = ndr_push_init_ctx(mem_ctx);
751 return NT_STATUS_NO_MEMORY;
753 status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
754 if (!NT_STATUS_IS_OK(status)) {
758 *blob = ndr_push_blob(ndr);
759 talloc_steal(mem_ctx, blob->data);
766 push a union to a blob using NDR
768 NTSTATUS ndr_push_union_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
769 uint32_t level, ndr_push_flags_fn_t fn)
772 struct ndr_push *ndr;
773 ndr = ndr_push_init_ctx(mem_ctx);
775 return NT_STATUS_NO_MEMORY;
777 ndr_push_set_switch_value(ndr, p, level);
778 status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
779 if (!NT_STATUS_IS_OK(status)) {
783 *blob = ndr_push_blob(ndr);
784 talloc_steal(mem_ctx, blob->data);
791 generic ndr_size_*() handler for structures
793 size_t ndr_size_struct(const void *p, int flags, ndr_push_flags_fn_t push)
795 struct ndr_push *ndr;
799 /* avoid recursion */
800 if (flags & LIBNDR_FLAG_NO_NDR_SIZE) return 0;
802 ndr = ndr_push_init_ctx(NULL);
804 ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE;
805 status = push(ndr, NDR_SCALARS|NDR_BUFFERS, p);
806 if (!NT_STATUS_IS_OK(status)) {
815 generic ndr_size_*() handler for unions
817 size_t ndr_size_union(const void *p, int flags, uint32_t level, ndr_push_flags_fn_t push)
819 struct ndr_push *ndr;
823 /* avoid recursion */
824 if (flags & LIBNDR_FLAG_NO_NDR_SIZE) return 0;
826 ndr = ndr_push_init_ctx(NULL);
828 ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE;
829 ndr_push_set_switch_value(ndr, p, level);
830 status = push(ndr, NDR_SCALARS|NDR_BUFFERS, p);
831 if (!NT_STATUS_IS_OK(status)) {
840 get the current base for relative pointers for the push
842 uint32_t ndr_push_get_relative_base_offset(struct ndr_push *ndr)
844 return ndr->relative_base_offset;
848 restore the old base for relative pointers for the push
850 void ndr_push_restore_relative_base_offset(struct ndr_push *ndr, uint32_t offset)
852 ndr->relative_base_offset = offset;
856 setup the current base for relative pointers for the push
857 called in the NDR_SCALAR stage
859 NTSTATUS ndr_push_setup_relative_base_offset1(struct ndr_push *ndr, const void *p, uint32_t offset)
861 ndr->relative_base_offset = offset;
862 return ndr_token_store(ndr, &ndr->relative_base_list, p, offset);
866 setup the current base for relative pointers for the push
867 called in the NDR_BUFFERS stage
869 NTSTATUS ndr_push_setup_relative_base_offset2(struct ndr_push *ndr, const void *p)
871 return ndr_token_retrieve(&ndr->relative_base_list, p, &ndr->relative_base_offset);
875 push a relative object - stage1
876 this is called during SCALARS processing
878 NTSTATUS ndr_push_relative_ptr1(struct ndr_push *ndr, const void *p)
881 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0));
884 NDR_CHECK(ndr_push_align(ndr, 4));
885 NDR_CHECK(ndr_token_store(ndr, &ndr->relative_list, p, ndr->offset));
886 return ndr_push_uint32(ndr, NDR_SCALARS, 0xFFFFFFFF);
890 push a relative object - stage2
891 this is called during buffers processing
893 NTSTATUS ndr_push_relative_ptr2(struct ndr_push *ndr, const void *p)
895 struct ndr_push_save save;
896 uint32_t ptr_offset = 0xFFFFFFFF;
900 ndr_push_save(ndr, &save);
901 NDR_CHECK(ndr_token_retrieve(&ndr->relative_list, p, &ptr_offset));
902 if (ptr_offset > ndr->offset) {
903 return ndr_push_error(ndr, NDR_ERR_BUFSIZE,
904 "ndr_push_relative_ptr2 ptr_offset(%u) > ndr->offset(%u)",
905 ptr_offset, ndr->offset);
907 ndr->offset = ptr_offset;
908 if (save.offset < ndr->relative_base_offset) {
909 return ndr_push_error(ndr, NDR_ERR_BUFSIZE,
910 "ndr_push_relative_ptr2 save.offset(%u) < ndr->relative_base_offset(%u)",
911 save.offset, ndr->relative_base_offset);
913 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, save.offset - ndr->relative_base_offset));
914 ndr_push_restore(ndr, &save);
919 get the current base for relative pointers for the pull
921 uint32_t ndr_pull_get_relative_base_offset(struct ndr_pull *ndr)
923 return ndr->relative_base_offset;
927 restore the old base for relative pointers for the pull
929 void ndr_pull_restore_relative_base_offset(struct ndr_pull *ndr, uint32_t offset)
931 ndr->relative_base_offset = offset;
935 setup the current base for relative pointers for the pull
936 called in the NDR_SCALAR stage
938 NTSTATUS ndr_pull_setup_relative_base_offset1(struct ndr_pull *ndr, const void *p, uint32_t offset)
940 ndr->relative_base_offset = offset;
941 return ndr_token_store(ndr, &ndr->relative_base_list, p, offset);
945 setup the current base for relative pointers for the pull
946 called in the NDR_BUFFERS stage
948 NTSTATUS ndr_pull_setup_relative_base_offset2(struct ndr_pull *ndr, const void *p)
950 return ndr_token_retrieve(&ndr->relative_base_list, p, &ndr->relative_base_offset);
954 pull a relative object - stage1
955 called during SCALARS processing
957 NTSTATUS ndr_pull_relative_ptr1(struct ndr_pull *ndr, const void *p, uint32_t rel_offset)
959 rel_offset += ndr->relative_base_offset;
960 if (rel_offset > ndr->data_size) {
961 return ndr_pull_error(ndr, NDR_ERR_BUFSIZE,
962 "ndr_pull_relative_ptr1 rel_offset(%u) > ndr->data_size(%u)",
963 rel_offset, ndr->data_size);
965 return ndr_token_store(ndr, &ndr->relative_list, p, rel_offset);
969 pull a relative object - stage2
970 called during BUFFERS processing
972 NTSTATUS ndr_pull_relative_ptr2(struct ndr_pull *ndr, const void *p)
975 NDR_CHECK(ndr_token_retrieve(&ndr->relative_list, p, &rel_offset));
976 return ndr_pull_set_offset(ndr, rel_offset);