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);
695 return NT_STATUS_NO_MEMORY;
697 return fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
701 pull a struct from a blob using NDR - failing if all bytes are not consumed
703 NTSTATUS ndr_pull_struct_blob_all(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
704 ndr_pull_flags_fn_t fn)
706 struct ndr_pull *ndr;
709 ndr = ndr_pull_init_blob(blob, mem_ctx);
711 return NT_STATUS_NO_MEMORY;
713 status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
714 if (!NT_STATUS_IS_OK(status)) return status;
715 if (ndr->offset < ndr->data_size) {
716 return ndr_pull_error(ndr, NDR_ERR_UNREAD_BYTES,
717 "not all bytes consumed ofs[%u] size[%u]",
718 ndr->offset, ndr->data_size);
724 pull a union from a blob using NDR, given the union discriminator
726 NTSTATUS ndr_pull_union_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
727 uint32_t level, ndr_pull_flags_fn_t fn)
729 struct ndr_pull *ndr;
730 ndr = ndr_pull_init_blob(blob, mem_ctx);
732 return NT_STATUS_NO_MEMORY;
734 ndr_pull_set_switch_value(ndr, p, level);
735 return fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
739 pull a union from a blob using NDR, given the union discriminator,
740 failing if all bytes are not consumed
742 _PUBLIC_ NTSTATUS ndr_pull_union_blob_all(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
743 uint32_t level, ndr_pull_flags_fn_t fn)
745 struct ndr_pull *ndr;
748 ndr = ndr_pull_init_blob(blob, mem_ctx);
750 return NT_STATUS_NO_MEMORY;
752 ndr_pull_set_switch_value(ndr, p, level);
753 status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
754 if (!NT_STATUS_IS_OK(status)) return status;
755 if (ndr->offset < ndr->data_size) {
756 return ndr_pull_error(ndr, NDR_ERR_UNREAD_BYTES,
757 "not all bytes consumed ofs[%u] size[%u]",
758 ndr->offset, ndr->data_size);
764 push a struct to a blob using NDR
766 NTSTATUS ndr_push_struct_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, const void *p,
767 ndr_push_flags_fn_t fn)
770 struct ndr_push *ndr;
771 ndr = ndr_push_init_ctx(mem_ctx);
773 return NT_STATUS_NO_MEMORY;
775 status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
776 if (!NT_STATUS_IS_OK(status)) {
780 *blob = ndr_push_blob(ndr);
781 talloc_steal(mem_ctx, blob->data);
788 push a union to a blob using NDR
790 NTSTATUS ndr_push_union_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
791 uint32_t level, ndr_push_flags_fn_t fn)
794 struct ndr_push *ndr;
795 ndr = ndr_push_init_ctx(mem_ctx);
797 return NT_STATUS_NO_MEMORY;
799 ndr_push_set_switch_value(ndr, p, level);
800 status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
801 if (!NT_STATUS_IS_OK(status)) {
805 *blob = ndr_push_blob(ndr);
806 talloc_steal(mem_ctx, blob->data);
813 generic ndr_size_*() handler for structures
815 size_t ndr_size_struct(const void *p, int flags, ndr_push_flags_fn_t push)
817 struct ndr_push *ndr;
821 /* avoid recursion */
822 if (flags & LIBNDR_FLAG_NO_NDR_SIZE) return 0;
824 ndr = ndr_push_init_ctx(NULL);
826 ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE;
827 status = push(ndr, NDR_SCALARS|NDR_BUFFERS, p);
828 if (!NT_STATUS_IS_OK(status)) {
837 generic ndr_size_*() handler for unions
839 size_t ndr_size_union(const void *p, int flags, uint32_t level, ndr_push_flags_fn_t push)
841 struct ndr_push *ndr;
845 /* avoid recursion */
846 if (flags & LIBNDR_FLAG_NO_NDR_SIZE) return 0;
848 ndr = ndr_push_init_ctx(NULL);
850 ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE;
851 ndr_push_set_switch_value(ndr, p, level);
852 status = push(ndr, NDR_SCALARS|NDR_BUFFERS, p);
853 if (!NT_STATUS_IS_OK(status)) {
862 get the current base for relative pointers for the push
864 uint32_t ndr_push_get_relative_base_offset(struct ndr_push *ndr)
866 return ndr->relative_base_offset;
870 restore the old base for relative pointers for the push
872 void ndr_push_restore_relative_base_offset(struct ndr_push *ndr, uint32_t offset)
874 ndr->relative_base_offset = offset;
878 setup the current base for relative pointers for the push
879 called in the NDR_SCALAR stage
881 NTSTATUS ndr_push_setup_relative_base_offset1(struct ndr_push *ndr, const void *p, uint32_t offset)
883 ndr->relative_base_offset = offset;
884 return ndr_token_store(ndr, &ndr->relative_base_list, p, offset);
888 setup the current base for relative pointers for the push
889 called in the NDR_BUFFERS stage
891 NTSTATUS ndr_push_setup_relative_base_offset2(struct ndr_push *ndr, const void *p)
893 return ndr_token_retrieve(&ndr->relative_base_list, p, &ndr->relative_base_offset);
897 push a relative object - stage1
898 this is called during SCALARS processing
900 NTSTATUS ndr_push_relative_ptr1(struct ndr_push *ndr, const void *p)
903 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0));
906 NDR_CHECK(ndr_push_align(ndr, 4));
907 NDR_CHECK(ndr_token_store(ndr, &ndr->relative_list, p, ndr->offset));
908 return ndr_push_uint32(ndr, NDR_SCALARS, 0xFFFFFFFF);
912 push a relative object - stage2
913 this is called during buffers processing
915 NTSTATUS ndr_push_relative_ptr2(struct ndr_push *ndr, const void *p)
917 struct ndr_push_save save;
918 uint32_t ptr_offset = 0xFFFFFFFF;
922 ndr_push_save(ndr, &save);
923 NDR_CHECK(ndr_token_retrieve(&ndr->relative_list, p, &ptr_offset));
924 if (ptr_offset > ndr->offset) {
925 return ndr_push_error(ndr, NDR_ERR_BUFSIZE,
926 "ndr_push_relative_ptr2 ptr_offset(%u) > ndr->offset(%u)",
927 ptr_offset, ndr->offset);
929 ndr->offset = ptr_offset;
930 if (save.offset < ndr->relative_base_offset) {
931 return ndr_push_error(ndr, NDR_ERR_BUFSIZE,
932 "ndr_push_relative_ptr2 save.offset(%u) < ndr->relative_base_offset(%u)",
933 save.offset, ndr->relative_base_offset);
935 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, save.offset - ndr->relative_base_offset));
936 ndr_push_restore(ndr, &save);
941 get the current base for relative pointers for the pull
943 uint32_t ndr_pull_get_relative_base_offset(struct ndr_pull *ndr)
945 return ndr->relative_base_offset;
949 restore the old base for relative pointers for the pull
951 void ndr_pull_restore_relative_base_offset(struct ndr_pull *ndr, uint32_t offset)
953 ndr->relative_base_offset = offset;
957 setup the current base for relative pointers for the pull
958 called in the NDR_SCALAR stage
960 NTSTATUS ndr_pull_setup_relative_base_offset1(struct ndr_pull *ndr, const void *p, uint32_t offset)
962 ndr->relative_base_offset = offset;
963 return ndr_token_store(ndr, &ndr->relative_base_list, p, offset);
967 setup the current base for relative pointers for the pull
968 called in the NDR_BUFFERS stage
970 NTSTATUS ndr_pull_setup_relative_base_offset2(struct ndr_pull *ndr, const void *p)
972 return ndr_token_retrieve(&ndr->relative_base_list, p, &ndr->relative_base_offset);
976 pull a relative object - stage1
977 called during SCALARS processing
979 NTSTATUS ndr_pull_relative_ptr1(struct ndr_pull *ndr, const void *p, uint32_t rel_offset)
981 rel_offset += ndr->relative_base_offset;
982 if (rel_offset > ndr->data_size) {
983 return ndr_pull_error(ndr, NDR_ERR_BUFSIZE,
984 "ndr_pull_relative_ptr1 rel_offset(%u) > ndr->data_size(%u)",
985 rel_offset, ndr->data_size);
987 return ndr_token_store(ndr, &ndr->relative_list, p, rel_offset);
991 pull a relative object - stage2
992 called during BUFFERS processing
994 NTSTATUS ndr_pull_relative_ptr2(struct ndr_pull *ndr, const void *p)
997 NDR_CHECK(ndr_token_retrieve(&ndr->relative_list, p, &rel_offset));
998 return ndr_pull_set_offset(ndr, rel_offset);