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 "lib/util/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);
137 /* return a DATA_BLOB structure for the current ndr_push marshalled data */
138 _PUBLIC_ DATA_BLOB ndr_push_blob(struct ndr_push *ndr)
141 blob.data = ndr->data;
142 blob.length = ndr->offset;
143 if (ndr->alloc_size > ndr->offset) {
144 ndr->data[ndr->offset] = 0;
151 expand the available space in the buffer to 'size'
153 _PUBLIC_ NTSTATUS ndr_push_expand(struct ndr_push *ndr, uint32_t size)
155 if (ndr->alloc_size > size) {
159 ndr->alloc_size += NDR_BASE_MARSHALL_SIZE;
160 if (size+1 > ndr->alloc_size) {
161 ndr->alloc_size = size+1;
163 ndr->data = talloc_realloc(ndr, ndr->data, uint8_t, ndr->alloc_size);
165 return ndr_push_error(ndr, NDR_ERR_ALLOC, "Failed to push_expand to %u",
172 _PUBLIC_ void ndr_print_debug_helper(struct ndr_print *ndr, const char *format, ...) _PRINTF_ATTRIBUTE(2,3)
178 va_start(ap, format);
179 vasprintf(&s, format, ap);
182 for (i=0;i<ndr->depth;i++) {
186 DEBUG(0,("%s\n", s));
190 _PUBLIC_ void ndr_print_string_helper(struct ndr_print *ndr, const char *format, ...) _PRINTF_ATTRIBUTE(2,3)
195 for (i=0;i<ndr->depth;i++) {
196 ndr->private_data = talloc_asprintf_append(ndr->private_data, " ");
199 va_start(ap, format);
200 ndr->private_data = talloc_vasprintf_append(ndr->private_data, format, ap);
202 ndr->private_data = talloc_asprintf_append(ndr->private_data, "\n");
206 a useful helper function for printing idl structures via DEBUG()
208 _PUBLIC_ void ndr_print_debug(ndr_print_fn_t fn, const char *name, void *ptr)
210 struct ndr_print *ndr;
212 ndr = talloc_zero(NULL, struct ndr_print);
214 ndr->print = ndr_print_debug_helper;
222 a useful helper function for printing idl unions via DEBUG()
224 _PUBLIC_ void ndr_print_union_debug(ndr_print_fn_t fn, const char *name, uint32_t level, void *ptr)
226 struct ndr_print *ndr;
228 ndr = talloc_zero(NULL, struct ndr_print);
230 ndr->print = ndr_print_debug_helper;
233 ndr_print_set_switch_value(ndr, ptr, level);
239 a useful helper function for printing idl function calls via DEBUG()
241 _PUBLIC_ void ndr_print_function_debug(ndr_print_function_t fn, const char *name, int flags, void *ptr)
243 struct ndr_print *ndr;
245 ndr = talloc_zero(NULL, struct ndr_print);
247 ndr->print = ndr_print_debug_helper;
250 fn(ndr, name, flags, ptr);
255 a useful helper function for printing idl structures to a string
257 _PUBLIC_ char *ndr_print_struct_string(TALLOC_CTX *mem_ctx, ndr_print_fn_t fn, const char *name, void *ptr)
259 struct ndr_print *ndr;
262 ndr = talloc_zero(mem_ctx, struct ndr_print);
263 if (!ndr) return NULL;
264 ndr->private_data = talloc_strdup(ndr, "");
265 if (!ndr->private_data) {
268 ndr->print = ndr_print_string_helper;
272 ret = talloc_steal(mem_ctx, ndr->private_data);
279 a useful helper function for printing idl unions to a string
281 _PUBLIC_ char *ndr_print_union_string(TALLOC_CTX *mem_ctx, ndr_print_fn_t fn, const char *name, uint32_t level, void *ptr)
283 struct ndr_print *ndr;
286 ndr = talloc_zero(mem_ctx, struct ndr_print);
287 if (!ndr) return NULL;
288 ndr->private_data = talloc_strdup(ndr, "");
289 if (!ndr->private_data) {
292 ndr->print = ndr_print_string_helper;
295 ndr_print_set_switch_value(ndr, ptr, level);
297 ret = talloc_steal(mem_ctx, ndr->private_data);
304 a useful helper function for printing idl function calls to a string
306 _PUBLIC_ char *ndr_print_function_string(TALLOC_CTX *mem_ctx,
307 ndr_print_function_t fn, const char *name,
308 int flags, void *ptr)
310 struct ndr_print *ndr;
313 ndr = talloc_zero(mem_ctx, struct ndr_print);
314 if (!ndr) return NULL;
315 ndr->private_data = talloc_strdup(ndr, "");
316 if (!ndr->private_data) {
319 ndr->print = ndr_print_string_helper;
322 fn(ndr, name, flags, ptr);
323 ret = talloc_steal(mem_ctx, ndr->private_data);
329 _PUBLIC_ void ndr_set_flags(uint32_t *pflags, uint32_t new_flags)
331 /* the big/little endian flags are inter-dependent */
332 if (new_flags & LIBNDR_FLAG_LITTLE_ENDIAN) {
333 (*pflags) &= ~LIBNDR_FLAG_BIGENDIAN;
335 if (new_flags & LIBNDR_FLAG_BIGENDIAN) {
336 (*pflags) &= ~LIBNDR_FLAG_LITTLE_ENDIAN;
338 if (new_flags & LIBNDR_FLAG_REMAINING) {
339 (*pflags) &= ~LIBNDR_ALIGN_FLAGS;
341 if (new_flags & LIBNDR_ALIGN_FLAGS) {
342 (*pflags) &= ~LIBNDR_FLAG_REMAINING;
344 (*pflags) |= new_flags;
347 static NTSTATUS ndr_map_error(enum ndr_err_code ndr_err)
350 case NDR_ERR_BUFSIZE:
351 return NT_STATUS_BUFFER_TOO_SMALL;
353 return NT_STATUS_INTERNAL_ERROR;
355 return NT_STATUS_NO_MEMORY;
356 case NDR_ERR_ARRAY_SIZE:
357 return NT_STATUS_ARRAY_BOUNDS_EXCEEDED;
362 /* we should map all error codes to different status codes */
363 return NT_STATUS_INVALID_PARAMETER;
367 return and possibly log an NDR error
369 _PUBLIC_ NTSTATUS ndr_pull_error(struct ndr_pull *ndr,
370 enum ndr_err_code ndr_err,
371 const char *format, ...) _PRINTF_ATTRIBUTE(3,4)
376 va_start(ap, format);
377 vasprintf(&s, format, ap);
380 DEBUG(3,("ndr_pull_error(%u): %s\n", ndr_err, s));
384 return ndr_map_error(ndr_err);
388 return and possibly log an NDR error
390 _PUBLIC_ NTSTATUS ndr_push_error(struct ndr_push *ndr,
391 enum ndr_err_code ndr_err,
392 const char *format, ...) _PRINTF_ATTRIBUTE(3,4)
397 va_start(ap, format);
398 vasprintf(&s, format, ap);
401 DEBUG(3,("ndr_push_error(%u): %s\n", ndr_err, s));
405 return ndr_map_error(ndr_err);
409 handle subcontext buffers, which in midl land are user-marshalled, but
410 we use magic in pidl to make them easier to cope with
412 _PUBLIC_ NTSTATUS ndr_pull_subcontext_start(struct ndr_pull *ndr,
413 struct ndr_pull **_subndr,
417 struct ndr_pull *subndr;
418 uint32_t r_content_size;
420 switch (header_size) {
422 uint32_t content_size = ndr->data_size - ndr->offset;
424 content_size = size_is;
426 r_content_size = content_size;
431 uint16_t content_size;
432 NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &content_size));
433 if (size_is >= 0 && size_is != content_size) {
434 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) size_is(%d) mismatch content_size %d",
435 (int)size_is, (int)content_size);
437 r_content_size = content_size;
442 uint32_t content_size;
443 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &content_size));
444 if (size_is >= 0 && size_is != content_size) {
445 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) size_is(%d) mismatch content_size %d",
446 (int)size_is, (int)content_size);
448 r_content_size = content_size;
452 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) header_size %d",
456 NDR_PULL_NEED_BYTES(ndr, r_content_size);
458 subndr = talloc_zero(ndr, struct ndr_pull);
459 NT_STATUS_HAVE_NO_MEMORY(subndr);
460 subndr->flags = ndr->flags;
461 subndr->current_mem_ctx = ndr->current_mem_ctx;
463 subndr->data = ndr->data + ndr->offset;
465 subndr->data_size = r_content_size;
471 _PUBLIC_ NTSTATUS ndr_pull_subcontext_end(struct ndr_pull *ndr,
472 struct ndr_pull *subndr,
479 } else if (header_size > 0) {
480 advance = subndr->data_size;
482 advance = subndr->offset;
484 NDR_CHECK(ndr_pull_advance(ndr, advance));
488 _PUBLIC_ NTSTATUS ndr_push_subcontext_start(struct ndr_push *ndr,
489 struct ndr_push **_subndr,
493 struct ndr_push *subndr;
495 subndr = ndr_push_init_ctx(ndr);
496 NT_STATUS_HAVE_NO_MEMORY(subndr);
497 subndr->flags = ndr->flags;
504 push a subcontext header
506 _PUBLIC_ NTSTATUS ndr_push_subcontext_end(struct ndr_push *ndr,
507 struct ndr_push *subndr,
512 ssize_t padding_len = size_is - subndr->offset;
513 if (padding_len > 0) {
514 NDR_CHECK(ndr_push_zero(subndr, padding_len));
515 } else if (padding_len < 0) {
516 return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PUSH) content_size %d is larger than size_is(%d)",
517 (int)subndr->offset, (int)size_is);
521 switch (header_size) {
526 NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, subndr->offset));
530 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, subndr->offset));
534 return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext header size %d",
538 NDR_CHECK(ndr_push_bytes(ndr, subndr->data, subndr->offset));
543 store a token in the ndr context, for later retrieval
545 _PUBLIC_ NTSTATUS ndr_token_store(TALLOC_CTX *mem_ctx,
546 struct ndr_token_list **list,
550 struct ndr_token_list *tok;
551 tok = talloc(mem_ctx, struct ndr_token_list);
553 return NT_STATUS_NO_MEMORY;
557 DLIST_ADD((*list), tok);
562 retrieve a token from a ndr context, using cmp_fn to match the tokens
564 _PUBLIC_ NTSTATUS ndr_token_retrieve_cmp_fn(struct ndr_token_list **list, const void *key, uint32_t *v,
565 comparison_fn_t _cmp_fn, BOOL _remove_tok)
567 struct ndr_token_list *tok;
568 for (tok=*list;tok;tok=tok->next) {
569 if (_cmp_fn && _cmp_fn(tok->key,key)==0) goto found;
570 else if (!_cmp_fn && tok->key == key) goto found;
572 return ndr_map_error(NDR_ERR_TOKEN);
576 DLIST_REMOVE((*list), tok);
583 retrieve a token from a ndr context
585 _PUBLIC_ NTSTATUS ndr_token_retrieve(struct ndr_token_list **list, const void *key, uint32_t *v)
587 return ndr_token_retrieve_cmp_fn(list, key, v, NULL, True);
591 peek at but don't removed a token from a ndr context
593 _PUBLIC_ uint32_t ndr_token_peek(struct ndr_token_list **list, const void *key)
597 status = ndr_token_retrieve_cmp_fn(list, key, &v, NULL, False);
598 if (NT_STATUS_IS_OK(status)) return v;
603 pull an array size field and add it to the array_size_list token list
605 _PUBLIC_ NTSTATUS ndr_pull_array_size(struct ndr_pull *ndr, const void *p)
608 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &size));
609 return ndr_token_store(ndr, &ndr->array_size_list, p, size);
613 get the stored array size field
615 _PUBLIC_ uint32_t ndr_get_array_size(struct ndr_pull *ndr, const void *p)
617 return ndr_token_peek(&ndr->array_size_list, p);
621 check the stored array size field
623 _PUBLIC_ NTSTATUS ndr_check_array_size(struct ndr_pull *ndr, void *p, uint32_t size)
626 stored = ndr_token_peek(&ndr->array_size_list, p);
627 if (stored != size) {
628 return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE,
629 "Bad array size - got %u expected %u\n",
636 pull an array length field and add it to the array_length_list token list
638 _PUBLIC_ NTSTATUS ndr_pull_array_length(struct ndr_pull *ndr, const void *p)
640 uint32_t length, offset;
641 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &offset));
643 return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE,
644 "non-zero array offset %u\n", offset);
646 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &length));
647 return ndr_token_store(ndr, &ndr->array_length_list, p, length);
651 get the stored array length field
653 _PUBLIC_ uint32_t ndr_get_array_length(struct ndr_pull *ndr, const void *p)
655 return ndr_token_peek(&ndr->array_length_list, p);
659 check the stored array length field
661 _PUBLIC_ NTSTATUS ndr_check_array_length(struct ndr_pull *ndr, void *p, uint32_t length)
664 stored = ndr_token_peek(&ndr->array_length_list, p);
665 if (stored != length) {
666 return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE,
667 "Bad array length - got %u expected %u\n",
676 _PUBLIC_ NTSTATUS ndr_push_set_switch_value(struct ndr_push *ndr, const void *p, uint32_t val)
678 return ndr_token_store(ndr, &ndr->switch_list, p, val);
681 _PUBLIC_ NTSTATUS ndr_pull_set_switch_value(struct ndr_pull *ndr, const void *p, uint32_t val)
683 return ndr_token_store(ndr, &ndr->switch_list, p, val);
686 _PUBLIC_ NTSTATUS ndr_print_set_switch_value(struct ndr_print *ndr, const void *p, uint32_t val)
688 return ndr_token_store(ndr, &ndr->switch_list, p, val);
692 retrieve a switch value
694 _PUBLIC_ uint32_t ndr_push_get_switch_value(struct ndr_push *ndr, const void *p)
696 return ndr_token_peek(&ndr->switch_list, p);
699 _PUBLIC_ uint32_t ndr_pull_get_switch_value(struct ndr_pull *ndr, const void *p)
701 return ndr_token_peek(&ndr->switch_list, p);
704 _PUBLIC_ uint32_t ndr_print_get_switch_value(struct ndr_print *ndr, const void *p)
706 return ndr_token_peek(&ndr->switch_list, p);
710 pull a struct from a blob using NDR
712 _PUBLIC_ NTSTATUS ndr_pull_struct_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
713 ndr_pull_flags_fn_t fn)
715 struct ndr_pull *ndr;
716 ndr = ndr_pull_init_blob(blob, mem_ctx);
718 return NT_STATUS_NO_MEMORY;
720 return fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
724 pull a struct from a blob using NDR - failing if all bytes are not consumed
726 _PUBLIC_ NTSTATUS ndr_pull_struct_blob_all(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
727 ndr_pull_flags_fn_t fn)
729 struct ndr_pull *ndr;
732 ndr = ndr_pull_init_blob(blob, mem_ctx);
734 return NT_STATUS_NO_MEMORY;
736 status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
737 if (!NT_STATUS_IS_OK(status)) return status;
738 if (ndr->offset < ndr->data_size) {
739 return NT_STATUS_PORT_MESSAGE_TOO_LONG;
745 pull a union from a blob using NDR, given the union discriminator
747 _PUBLIC_ NTSTATUS ndr_pull_union_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
748 uint32_t level, ndr_pull_flags_fn_t fn)
750 struct ndr_pull *ndr;
753 ndr = ndr_pull_init_blob(blob, mem_ctx);
755 return NT_STATUS_NO_MEMORY;
757 ndr_pull_set_switch_value(ndr, p, level);
758 status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
759 if (!NT_STATUS_IS_OK(status)) return status;
760 if (ndr->offset != ndr->data_size) {
761 return NT_STATUS_BUFFER_TOO_SMALL;
767 push a struct to a blob using NDR
769 _PUBLIC_ NTSTATUS ndr_push_struct_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, const void *p,
770 ndr_push_flags_fn_t fn)
773 struct ndr_push *ndr;
774 ndr = ndr_push_init_ctx(mem_ctx);
776 return NT_STATUS_NO_MEMORY;
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 push a union to a blob using NDR
793 _PUBLIC_ NTSTATUS ndr_push_union_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
794 uint32_t level, ndr_push_flags_fn_t fn)
797 struct ndr_push *ndr;
798 ndr = ndr_push_init_ctx(mem_ctx);
800 return NT_STATUS_NO_MEMORY;
802 ndr_push_set_switch_value(ndr, p, level);
803 status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
804 if (!NT_STATUS_IS_OK(status)) {
808 *blob = ndr_push_blob(ndr);
809 talloc_steal(mem_ctx, blob->data);
816 generic ndr_size_*() handler for structures
818 _PUBLIC_ size_t ndr_size_struct(const void *p, int flags, ndr_push_flags_fn_t push)
820 struct ndr_push *ndr;
824 /* avoid recursion */
825 if (flags & LIBNDR_FLAG_NO_NDR_SIZE) return 0;
827 ndr = ndr_push_init_ctx(NULL);
829 ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE;
830 status = push(ndr, NDR_SCALARS|NDR_BUFFERS, discard_const(p));
831 if (!NT_STATUS_IS_OK(status)) {
840 generic ndr_size_*() handler for unions
842 _PUBLIC_ size_t ndr_size_union(const void *p, int flags, uint32_t level, ndr_push_flags_fn_t push)
844 struct ndr_push *ndr;
848 /* avoid recursion */
849 if (flags & LIBNDR_FLAG_NO_NDR_SIZE) return 0;
851 ndr = ndr_push_init_ctx(NULL);
853 ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE;
854 ndr_push_set_switch_value(ndr, p, level);
855 status = push(ndr, NDR_SCALARS|NDR_BUFFERS, p);
856 if (!NT_STATUS_IS_OK(status)) {
865 get the current base for relative pointers for the push
867 _PUBLIC_ uint32_t ndr_push_get_relative_base_offset(struct ndr_push *ndr)
869 return ndr->relative_base_offset;
873 restore the old base for relative pointers for the push
875 _PUBLIC_ void ndr_push_restore_relative_base_offset(struct ndr_push *ndr, uint32_t offset)
877 ndr->relative_base_offset = offset;
881 setup the current base for relative pointers for the push
882 called in the NDR_SCALAR stage
884 _PUBLIC_ NTSTATUS ndr_push_setup_relative_base_offset1(struct ndr_push *ndr, const void *p, uint32_t offset)
886 ndr->relative_base_offset = offset;
887 return ndr_token_store(ndr, &ndr->relative_base_list, p, offset);
891 setup the current base for relative pointers for the push
892 called in the NDR_BUFFERS stage
894 _PUBLIC_ NTSTATUS ndr_push_setup_relative_base_offset2(struct ndr_push *ndr, const void *p)
896 return ndr_token_retrieve(&ndr->relative_base_list, p, &ndr->relative_base_offset);
900 push a relative object - stage1
901 this is called during SCALARS processing
903 _PUBLIC_ NTSTATUS ndr_push_relative_ptr1(struct ndr_push *ndr, const void *p)
906 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0));
909 NDR_CHECK(ndr_push_align(ndr, 4));
910 NDR_CHECK(ndr_token_store(ndr, &ndr->relative_list, p, ndr->offset));
911 return ndr_push_uint32(ndr, NDR_SCALARS, 0xFFFFFFFF);
915 push a relative object - stage2
916 this is called during buffers processing
918 _PUBLIC_ NTSTATUS ndr_push_relative_ptr2(struct ndr_push *ndr, const void *p)
920 struct ndr_push_save save;
921 uint32_t ptr_offset = 0xFFFFFFFF;
925 ndr_push_save(ndr, &save);
926 NDR_CHECK(ndr_token_retrieve(&ndr->relative_list, p, &ptr_offset));
927 if (ptr_offset > ndr->offset) {
928 return ndr_push_error(ndr, NDR_ERR_BUFSIZE,
929 "ndr_push_relative_ptr2 ptr_offset(%u) > ndr->offset(%u)",
930 ptr_offset, ndr->offset);
932 ndr->offset = ptr_offset;
933 if (save.offset < ndr->relative_base_offset) {
934 return ndr_push_error(ndr, NDR_ERR_BUFSIZE,
935 "ndr_push_relative_ptr2 save.offset(%u) < ndr->relative_base_offset(%u)",
936 save.offset, ndr->relative_base_offset);
938 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, save.offset - ndr->relative_base_offset));
939 ndr_push_restore(ndr, &save);
944 get the current base for relative pointers for the pull
946 _PUBLIC_ uint32_t ndr_pull_get_relative_base_offset(struct ndr_pull *ndr)
948 return ndr->relative_base_offset;
952 restore the old base for relative pointers for the pull
954 _PUBLIC_ void ndr_pull_restore_relative_base_offset(struct ndr_pull *ndr, uint32_t offset)
956 ndr->relative_base_offset = offset;
960 setup the current base for relative pointers for the pull
961 called in the NDR_SCALAR stage
963 _PUBLIC_ NTSTATUS ndr_pull_setup_relative_base_offset1(struct ndr_pull *ndr, const void *p, uint32_t offset)
965 ndr->relative_base_offset = offset;
966 return ndr_token_store(ndr, &ndr->relative_base_list, p, offset);
970 setup the current base for relative pointers for the pull
971 called in the NDR_BUFFERS stage
973 _PUBLIC_ NTSTATUS ndr_pull_setup_relative_base_offset2(struct ndr_pull *ndr, const void *p)
975 return ndr_token_retrieve(&ndr->relative_base_list, p, &ndr->relative_base_offset);
979 pull a relative object - stage1
980 called during SCALARS processing
982 _PUBLIC_ NTSTATUS ndr_pull_relative_ptr1(struct ndr_pull *ndr, const void *p, uint32_t rel_offset)
984 rel_offset += ndr->relative_base_offset;
985 if (rel_offset > ndr->data_size) {
986 return ndr_pull_error(ndr, NDR_ERR_BUFSIZE,
987 "ndr_pull_relative_ptr1 rel_offset(%u) > ndr->data_size(%u)",
988 rel_offset, ndr->data_size);
990 return ndr_token_store(ndr, &ndr->relative_list, p, rel_offset);
994 pull a relative object - stage2
995 called during BUFFERS processing
997 _PUBLIC_ NTSTATUS ndr_pull_relative_ptr2(struct ndr_pull *ndr, const void *p)
1000 NDR_CHECK(ndr_token_retrieve(&ndr->relative_list, p, &rel_offset));
1001 return ndr_pull_set_offset(ndr, rel_offset);