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;
333 case NDR_ERR_UNREAD_BYTES:
334 return NT_STATUS_PORT_MESSAGE_TOO_LONG;
339 /* we should map all error codes to different status codes */
340 return NT_STATUS_INVALID_PARAMETER;
344 return and possibly log an NDR error
346 NTSTATUS ndr_pull_error(struct ndr_pull *ndr,
347 enum ndr_err_code ndr_err,
348 const char *format, ...) _PRINTF_ATTRIBUTE(3,4)
353 va_start(ap, format);
354 vasprintf(&s, format, ap);
357 DEBUG(3,("ndr_pull_error(%u): %s\n", ndr_err, s));
361 return ndr_map_error(ndr_err);
365 return and possibly log an NDR error
367 NTSTATUS ndr_push_error(struct ndr_push *ndr,
368 enum ndr_err_code ndr_err,
369 const char *format, ...) _PRINTF_ATTRIBUTE(3,4)
374 va_start(ap, format);
375 vasprintf(&s, format, ap);
378 DEBUG(3,("ndr_push_error(%u): %s\n", ndr_err, s));
382 return ndr_map_error(ndr_err);
386 handle subcontext buffers, which in midl land are user-marshalled, but
387 we use magic in pidl to make them easier to cope with
389 NTSTATUS ndr_pull_subcontext_start(struct ndr_pull *ndr,
390 struct ndr_pull **_subndr,
394 struct ndr_pull *subndr;
395 uint32_t r_content_size;
397 switch (header_size) {
399 uint32_t content_size = ndr->data_size - ndr->offset;
401 content_size = size_is;
403 r_content_size = content_size;
408 uint16_t content_size;
409 NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &content_size));
410 if (size_is >= 0 && size_is != content_size) {
411 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) size_is(%d) mismatch content_size %d",
412 (int)size_is, (int)content_size);
414 r_content_size = content_size;
419 uint32_t content_size;
420 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &content_size));
421 if (size_is >= 0 && size_is != content_size) {
422 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) size_is(%d) mismatch content_size %d",
423 (int)size_is, (int)content_size);
425 r_content_size = content_size;
429 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) header_size %d",
433 NDR_PULL_NEED_BYTES(ndr, r_content_size);
435 subndr = talloc_zero(ndr, struct ndr_pull);
436 NT_STATUS_HAVE_NO_MEMORY(subndr);
437 subndr->flags = ndr->flags;
438 subndr->current_mem_ctx = ndr->current_mem_ctx;
440 subndr->data = ndr->data + ndr->offset;
442 subndr->data_size = r_content_size;
448 NTSTATUS ndr_pull_subcontext_end(struct ndr_pull *ndr,
449 struct ndr_pull *subndr,
456 } else if (header_size > 0) {
457 advance = subndr->data_size;
459 advance = subndr->offset;
461 NDR_CHECK(ndr_pull_advance(ndr, advance));
465 NTSTATUS ndr_push_subcontext_start(struct ndr_push *ndr,
466 struct ndr_push **_subndr,
470 struct ndr_push *subndr;
472 subndr = ndr_push_init_ctx(ndr);
473 NT_STATUS_HAVE_NO_MEMORY(subndr);
474 subndr->flags = ndr->flags;
481 push a subcontext header
483 NTSTATUS ndr_push_subcontext_end(struct ndr_push *ndr,
484 struct ndr_push *subndr,
489 ssize_t padding_len = size_is - subndr->offset;
490 if (padding_len > 0) {
491 NDR_CHECK(ndr_push_zero(subndr, padding_len));
492 } else if (padding_len < 0) {
493 return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PUSH) content_size %d is larger than size_is(%d)",
494 (int)subndr->offset, (int)size_is);
498 switch (header_size) {
503 NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, subndr->offset));
507 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, subndr->offset));
511 return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext header size %d",
515 NDR_CHECK(ndr_push_bytes(ndr, subndr->data, subndr->offset));
520 store a token in the ndr context, for later retrieval
522 NTSTATUS ndr_token_store(TALLOC_CTX *mem_ctx,
523 struct ndr_token_list **list,
527 struct ndr_token_list *tok;
528 tok = talloc(mem_ctx, struct ndr_token_list);
530 return NT_STATUS_NO_MEMORY;
534 DLIST_ADD((*list), tok);
539 retrieve a token from a ndr context, using cmp_fn to match the tokens
541 NTSTATUS ndr_token_retrieve_cmp_fn(struct ndr_token_list **list, const void *key, uint32_t *v,
542 comparison_fn_t _cmp_fn, bool _remove_tok)
544 struct ndr_token_list *tok;
545 for (tok=*list;tok;tok=tok->next) {
546 if (_cmp_fn && _cmp_fn(tok->key,key)==0) goto found;
547 else if (!_cmp_fn && tok->key == key) goto found;
549 return ndr_map_error(NDR_ERR_TOKEN);
553 DLIST_REMOVE((*list), tok);
560 retrieve a token from a ndr context
562 NTSTATUS ndr_token_retrieve(struct ndr_token_list **list, const void *key, uint32_t *v)
564 return ndr_token_retrieve_cmp_fn(list, key, v, NULL, True);
568 peek at but don't removed a token from a ndr context
570 uint32_t ndr_token_peek(struct ndr_token_list **list, const void *key)
574 status = ndr_token_retrieve_cmp_fn(list, key, &v, NULL, False);
575 if (NT_STATUS_IS_OK(status)) return v;
580 pull an array size field and add it to the array_size_list token list
582 NTSTATUS ndr_pull_array_size(struct ndr_pull *ndr, const void *p)
585 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &size));
586 return ndr_token_store(ndr, &ndr->array_size_list, p, size);
590 get the stored array size field
592 uint32_t ndr_get_array_size(struct ndr_pull *ndr, const void *p)
594 return ndr_token_peek(&ndr->array_size_list, p);
598 check the stored array size field
600 NTSTATUS ndr_check_array_size(struct ndr_pull *ndr, void *p, uint32_t size)
603 stored = ndr_token_peek(&ndr->array_size_list, p);
604 if (stored != size) {
605 return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE,
606 "Bad array size - got %u expected %u\n",
613 pull an array length field and add it to the array_length_list token list
615 NTSTATUS ndr_pull_array_length(struct ndr_pull *ndr, const void *p)
617 uint32_t length, offset;
618 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &offset));
620 return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE,
621 "non-zero array offset %u\n", offset);
623 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &length));
624 return ndr_token_store(ndr, &ndr->array_length_list, p, length);
628 get the stored array length field
630 uint32_t ndr_get_array_length(struct ndr_pull *ndr, const void *p)
632 return ndr_token_peek(&ndr->array_length_list, p);
636 check the stored array length field
638 NTSTATUS ndr_check_array_length(struct ndr_pull *ndr, void *p, uint32_t length)
641 stored = ndr_token_peek(&ndr->array_length_list, p);
642 if (stored != length) {
643 return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE,
644 "Bad array length - got %u expected %u\n",
653 NTSTATUS ndr_push_set_switch_value(struct ndr_push *ndr, const void *p, uint32_t val)
655 return ndr_token_store(ndr, &ndr->switch_list, p, val);
658 NTSTATUS ndr_pull_set_switch_value(struct ndr_pull *ndr, const void *p, uint32_t val)
660 return ndr_token_store(ndr, &ndr->switch_list, p, val);
663 NTSTATUS ndr_print_set_switch_value(struct ndr_print *ndr, const void *p, uint32_t val)
665 return ndr_token_store(ndr, &ndr->switch_list, p, val);
669 retrieve a switch value
671 uint32_t ndr_push_get_switch_value(struct ndr_push *ndr, const void *p)
673 return ndr_token_peek(&ndr->switch_list, p);
676 uint32_t ndr_pull_get_switch_value(struct ndr_pull *ndr, const void *p)
678 return ndr_token_peek(&ndr->switch_list, p);
681 uint32_t ndr_print_get_switch_value(struct ndr_print *ndr, const void *p)
683 return ndr_token_peek(&ndr->switch_list, p);
687 pull a struct from a blob using NDR
689 NTSTATUS ndr_pull_struct_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
690 ndr_pull_flags_fn_t fn)
692 struct ndr_pull *ndr;
693 ndr = ndr_pull_init_blob(blob, mem_ctx);
694 NT_STATUS_HAVE_NO_MEMORY(ndr);
695 NDR_CHECK(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p));
700 pull a struct from a blob using NDR - failing if all bytes are not consumed
702 NTSTATUS ndr_pull_struct_blob_all(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
703 ndr_pull_flags_fn_t fn)
705 struct ndr_pull *ndr;
706 ndr = ndr_pull_init_blob(blob, mem_ctx);
707 NT_STATUS_HAVE_NO_MEMORY(ndr);
708 NDR_CHECK(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p));
709 if (ndr->offset < ndr->data_size) {
710 return ndr_pull_error(ndr, NDR_ERR_UNREAD_BYTES,
711 "not all bytes consumed ofs[%u] size[%u]",
712 ndr->offset, ndr->data_size);
718 pull a union from a blob using NDR, given the union discriminator
720 NTSTATUS ndr_pull_union_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
721 uint32_t level, ndr_pull_flags_fn_t fn)
723 struct ndr_pull *ndr;
724 ndr = ndr_pull_init_blob(blob, mem_ctx);
725 NT_STATUS_HAVE_NO_MEMORY(ndr);
726 ndr_pull_set_switch_value(ndr, p, level);
727 NDR_CHECK(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p));
732 pull a union from a blob using NDR, given the union discriminator,
733 failing if all bytes are not consumed
735 _PUBLIC_ NTSTATUS ndr_pull_union_blob_all(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
736 uint32_t level, ndr_pull_flags_fn_t fn)
738 struct ndr_pull *ndr;
739 ndr = ndr_pull_init_blob(blob, mem_ctx);
740 NT_STATUS_HAVE_NO_MEMORY(ndr);
741 ndr_pull_set_switch_value(ndr, p, level);
742 NDR_CHECK(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p));
743 if (ndr->offset < ndr->data_size) {
744 return ndr_pull_error(ndr, NDR_ERR_UNREAD_BYTES,
745 "not all bytes consumed ofs[%u] size[%u]",
746 ndr->offset, ndr->data_size);
752 push a struct to a blob using NDR
754 NTSTATUS ndr_push_struct_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, const void *p,
755 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 status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
764 if (!NT_STATUS_IS_OK(status)) {
768 *blob = ndr_push_blob(ndr);
769 talloc_steal(mem_ctx, blob->data);
776 push a union to a blob using NDR
778 NTSTATUS ndr_push_union_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
779 uint32_t level, ndr_push_flags_fn_t fn)
782 struct ndr_push *ndr;
783 ndr = ndr_push_init_ctx(mem_ctx);
785 return NT_STATUS_NO_MEMORY;
787 ndr_push_set_switch_value(ndr, p, level);
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 generic ndr_size_*() handler for structures
803 size_t ndr_size_struct(const void *p, int flags, ndr_push_flags_fn_t push)
805 struct ndr_push *ndr;
809 /* avoid recursion */
810 if (flags & LIBNDR_FLAG_NO_NDR_SIZE) return 0;
812 ndr = ndr_push_init_ctx(NULL);
814 ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE;
815 status = push(ndr, NDR_SCALARS|NDR_BUFFERS, p);
816 if (!NT_STATUS_IS_OK(status)) {
825 generic ndr_size_*() handler for unions
827 size_t ndr_size_union(const void *p, int flags, uint32_t level, ndr_push_flags_fn_t push)
829 struct ndr_push *ndr;
833 /* avoid recursion */
834 if (flags & LIBNDR_FLAG_NO_NDR_SIZE) return 0;
836 ndr = ndr_push_init_ctx(NULL);
838 ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE;
839 ndr_push_set_switch_value(ndr, p, level);
840 status = push(ndr, NDR_SCALARS|NDR_BUFFERS, p);
841 if (!NT_STATUS_IS_OK(status)) {
850 get the current base for relative pointers for the push
852 uint32_t ndr_push_get_relative_base_offset(struct ndr_push *ndr)
854 return ndr->relative_base_offset;
858 restore the old base for relative pointers for the push
860 void ndr_push_restore_relative_base_offset(struct ndr_push *ndr, uint32_t offset)
862 ndr->relative_base_offset = offset;
866 setup the current base for relative pointers for the push
867 called in the NDR_SCALAR stage
869 NTSTATUS ndr_push_setup_relative_base_offset1(struct ndr_push *ndr, const void *p, uint32_t offset)
871 ndr->relative_base_offset = offset;
872 return ndr_token_store(ndr, &ndr->relative_base_list, p, offset);
876 setup the current base for relative pointers for the push
877 called in the NDR_BUFFERS stage
879 NTSTATUS ndr_push_setup_relative_base_offset2(struct ndr_push *ndr, const void *p)
881 return ndr_token_retrieve(&ndr->relative_base_list, p, &ndr->relative_base_offset);
885 push a relative object - stage1
886 this is called during SCALARS processing
888 NTSTATUS ndr_push_relative_ptr1(struct ndr_push *ndr, const void *p)
891 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0));
894 NDR_CHECK(ndr_push_align(ndr, 4));
895 NDR_CHECK(ndr_token_store(ndr, &ndr->relative_list, p, ndr->offset));
896 return ndr_push_uint32(ndr, NDR_SCALARS, 0xFFFFFFFF);
900 push a relative object - stage2
901 this is called during buffers processing
903 NTSTATUS ndr_push_relative_ptr2(struct ndr_push *ndr, const void *p)
905 struct ndr_push_save save;
906 uint32_t ptr_offset = 0xFFFFFFFF;
910 ndr_push_save(ndr, &save);
911 NDR_CHECK(ndr_token_retrieve(&ndr->relative_list, p, &ptr_offset));
912 if (ptr_offset > ndr->offset) {
913 return ndr_push_error(ndr, NDR_ERR_BUFSIZE,
914 "ndr_push_relative_ptr2 ptr_offset(%u) > ndr->offset(%u)",
915 ptr_offset, ndr->offset);
917 ndr->offset = ptr_offset;
918 if (save.offset < ndr->relative_base_offset) {
919 return ndr_push_error(ndr, NDR_ERR_BUFSIZE,
920 "ndr_push_relative_ptr2 save.offset(%u) < ndr->relative_base_offset(%u)",
921 save.offset, ndr->relative_base_offset);
923 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, save.offset - ndr->relative_base_offset));
924 ndr_push_restore(ndr, &save);
929 get the current base for relative pointers for the pull
931 uint32_t ndr_pull_get_relative_base_offset(struct ndr_pull *ndr)
933 return ndr->relative_base_offset;
937 restore the old base for relative pointers for the pull
939 void ndr_pull_restore_relative_base_offset(struct ndr_pull *ndr, uint32_t offset)
941 ndr->relative_base_offset = offset;
945 setup the current base for relative pointers for the pull
946 called in the NDR_SCALAR stage
948 NTSTATUS ndr_pull_setup_relative_base_offset1(struct ndr_pull *ndr, const void *p, uint32_t offset)
950 ndr->relative_base_offset = offset;
951 return ndr_token_store(ndr, &ndr->relative_base_list, p, offset);
955 setup the current base for relative pointers for the pull
956 called in the NDR_BUFFERS stage
958 NTSTATUS ndr_pull_setup_relative_base_offset2(struct ndr_pull *ndr, const void *p)
960 return ndr_token_retrieve(&ndr->relative_base_list, p, &ndr->relative_base_offset);
964 pull a relative object - stage1
965 called during SCALARS processing
967 NTSTATUS ndr_pull_relative_ptr1(struct ndr_pull *ndr, const void *p, uint32_t rel_offset)
969 rel_offset += ndr->relative_base_offset;
970 if (rel_offset > ndr->data_size) {
971 return ndr_pull_error(ndr, NDR_ERR_BUFSIZE,
972 "ndr_pull_relative_ptr1 rel_offset(%u) > ndr->data_size(%u)",
973 rel_offset, ndr->data_size);
975 return ndr_token_store(ndr, &ndr->relative_list, p, rel_offset);
979 pull a relative object - stage2
980 called during BUFFERS processing
982 NTSTATUS ndr_pull_relative_ptr2(struct ndr_pull *ndr, const void *p)
985 NDR_CHECK(ndr_token_retrieve(&ndr->relative_list, p, &rel_offset));
986 return ndr_pull_set_offset(ndr, rel_offset);