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);
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 _PUBLIC_ 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_data = talloc_asprintf_append(ndr->private_data, " ");
213 va_start(ap, format);
214 ndr->private_data = talloc_vasprintf_append(ndr->private_data, format, ap);
216 ndr->private_data = talloc_asprintf_append(ndr->private_data, "\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);
269 a useful helper function for printing idl structures to a string
271 _PUBLIC_ char *ndr_print_struct_string(TALLOC_CTX *mem_ctx, ndr_print_fn_t fn, const char *name, void *ptr)
273 struct ndr_print *ndr;
276 ndr = talloc_zero(mem_ctx, struct ndr_print);
277 if (!ndr) return NULL;
278 ndr->private_data = talloc_strdup(ndr, "");
279 if (!ndr->private_data) {
282 ndr->print = ndr_print_string_helper;
286 ret = talloc_steal(mem_ctx, ndr->private_data);
293 a useful helper function for printing idl unions to a string
295 _PUBLIC_ char *ndr_print_union_string(TALLOC_CTX *mem_ctx, ndr_print_fn_t fn, const char *name, uint32_t level, void *ptr)
297 struct ndr_print *ndr;
300 ndr = talloc_zero(mem_ctx, struct ndr_print);
301 if (!ndr) return NULL;
302 ndr->private_data = talloc_strdup(ndr, "");
303 if (!ndr->private_data) {
306 ndr->print = ndr_print_string_helper;
309 ndr_print_set_switch_value(ndr, ptr, level);
311 ret = talloc_steal(mem_ctx, ndr->private_data);
318 a useful helper function for printing idl function calls to a string
320 _PUBLIC_ char *ndr_print_function_string(TALLOC_CTX *mem_ctx,
321 ndr_print_function_t fn, const char *name,
322 int flags, void *ptr)
324 struct ndr_print *ndr;
327 ndr = talloc_zero(mem_ctx, struct ndr_print);
328 if (!ndr) return NULL;
329 ndr->private_data = talloc_strdup(ndr, "");
330 if (!ndr->private_data) {
333 ndr->print = ndr_print_string_helper;
336 fn(ndr, name, flags, ptr);
337 ret = talloc_steal(mem_ctx, ndr->private_data);
343 _PUBLIC_ void ndr_set_flags(uint32_t *pflags, uint32_t new_flags)
345 /* the big/little endian flags are inter-dependent */
346 if (new_flags & LIBNDR_FLAG_LITTLE_ENDIAN) {
347 (*pflags) &= ~LIBNDR_FLAG_BIGENDIAN;
349 if (new_flags & LIBNDR_FLAG_BIGENDIAN) {
350 (*pflags) &= ~LIBNDR_FLAG_LITTLE_ENDIAN;
352 if (new_flags & LIBNDR_FLAG_REMAINING) {
353 (*pflags) &= ~LIBNDR_ALIGN_FLAGS;
355 if (new_flags & LIBNDR_ALIGN_FLAGS) {
356 (*pflags) &= ~LIBNDR_FLAG_REMAINING;
358 (*pflags) |= new_flags;
361 static NTSTATUS ndr_map_error(enum ndr_err_code ndr_err)
364 case NDR_ERR_BUFSIZE:
365 return NT_STATUS_BUFFER_TOO_SMALL;
367 return NT_STATUS_INTERNAL_ERROR;
369 return NT_STATUS_NO_MEMORY;
370 case NDR_ERR_ARRAY_SIZE:
371 return NT_STATUS_ARRAY_BOUNDS_EXCEEDED;
376 /* we should map all error codes to different status codes */
377 return NT_STATUS_INVALID_PARAMETER;
381 return and possibly log an NDR error
383 _PUBLIC_ NTSTATUS ndr_pull_error(struct ndr_pull *ndr,
384 enum ndr_err_code ndr_err,
385 const char *format, ...) _PRINTF_ATTRIBUTE(3,4)
390 va_start(ap, format);
391 vasprintf(&s, format, ap);
394 DEBUG(3,("ndr_pull_error(%u): %s\n", ndr_err, s));
398 return ndr_map_error(ndr_err);
402 return and possibly log an NDR error
404 _PUBLIC_ NTSTATUS ndr_push_error(struct ndr_push *ndr,
405 enum ndr_err_code ndr_err,
406 const char *format, ...) _PRINTF_ATTRIBUTE(3,4)
411 va_start(ap, format);
412 vasprintf(&s, format, ap);
415 DEBUG(3,("ndr_push_error(%u): %s\n", ndr_err, s));
419 return ndr_map_error(ndr_err);
423 handle subcontext buffers, which in midl land are user-marshalled, but
424 we use magic in pidl to make them easier to cope with
426 _PUBLIC_ NTSTATUS ndr_pull_subcontext_start(struct ndr_pull *ndr,
427 struct ndr_pull **_subndr,
431 struct ndr_pull *subndr;
432 uint32_t r_content_size;
434 switch (header_size) {
436 uint32_t content_size = ndr->data_size - ndr->offset;
438 content_size = size_is;
440 r_content_size = content_size;
445 uint16_t content_size;
446 NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &content_size));
447 if (size_is >= 0 && size_is != content_size) {
448 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) size_is(%d) mismatch content_size %d",
449 (int)size_is, (int)content_size);
451 r_content_size = content_size;
456 uint32_t content_size;
457 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &content_size));
458 if (size_is >= 0 && size_is != content_size) {
459 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) size_is(%d) mismatch content_size %d",
460 (int)size_is, (int)content_size);
462 r_content_size = content_size;
466 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) header_size %d",
470 NDR_PULL_NEED_BYTES(ndr, r_content_size);
472 subndr = talloc_zero(ndr, struct ndr_pull);
473 NT_STATUS_HAVE_NO_MEMORY(subndr);
474 subndr->flags = ndr->flags;
475 subndr->current_mem_ctx = ndr->current_mem_ctx;
477 subndr->data = ndr->data + ndr->offset;
479 subndr->data_size = r_content_size;
485 _PUBLIC_ NTSTATUS ndr_pull_subcontext_end(struct ndr_pull *ndr,
486 struct ndr_pull *subndr,
493 } else if (header_size > 0) {
494 advance = subndr->data_size;
496 advance = subndr->offset;
498 NDR_CHECK(ndr_pull_advance(ndr, advance));
502 _PUBLIC_ NTSTATUS ndr_push_subcontext_start(struct ndr_push *ndr,
503 struct ndr_push **_subndr,
507 struct ndr_push *subndr;
509 subndr = ndr_push_init_ctx(ndr);
510 NT_STATUS_HAVE_NO_MEMORY(subndr);
511 subndr->flags = ndr->flags;
518 push a subcontext header
520 _PUBLIC_ NTSTATUS ndr_push_subcontext_end(struct ndr_push *ndr,
521 struct ndr_push *subndr,
526 ssize_t padding_len = size_is - subndr->offset;
527 if (padding_len > 0) {
528 NDR_CHECK(ndr_push_zero(subndr, padding_len));
529 } else if (padding_len < 0) {
530 return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PUSH) content_size %d is larger than size_is(%d)",
531 (int)subndr->offset, (int)size_is);
535 switch (header_size) {
540 NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, subndr->offset));
544 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, subndr->offset));
548 return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext header size %d",
552 NDR_CHECK(ndr_push_bytes(ndr, subndr->data, subndr->offset));
557 store a token in the ndr context, for later retrieval
559 _PUBLIC_ NTSTATUS ndr_token_store(TALLOC_CTX *mem_ctx,
560 struct ndr_token_list **list,
564 struct ndr_token_list *tok;
565 tok = talloc(mem_ctx, struct ndr_token_list);
567 return NT_STATUS_NO_MEMORY;
571 DLIST_ADD((*list), tok);
576 retrieve a token from a ndr context, using cmp_fn to match the tokens
578 _PUBLIC_ NTSTATUS ndr_token_retrieve_cmp_fn(struct ndr_token_list **list, const void *key, uint32_t *v,
579 comparison_fn_t _cmp_fn, BOOL _remove_tok)
581 struct ndr_token_list *tok;
582 for (tok=*list;tok;tok=tok->next) {
583 if (_cmp_fn && _cmp_fn(tok->key,key)==0) goto found;
584 else if (!_cmp_fn && tok->key == key) goto found;
586 return ndr_map_error(NDR_ERR_TOKEN);
590 DLIST_REMOVE((*list), tok);
597 retrieve a token from a ndr context
599 _PUBLIC_ NTSTATUS ndr_token_retrieve(struct ndr_token_list **list, const void *key, uint32_t *v)
601 return ndr_token_retrieve_cmp_fn(list, key, v, NULL, True);
605 peek at but don't removed a token from a ndr context
607 _PUBLIC_ uint32_t ndr_token_peek(struct ndr_token_list **list, const void *key)
611 status = ndr_token_retrieve_cmp_fn(list, key, &v, NULL, False);
612 if (NT_STATUS_IS_OK(status)) return v;
617 pull an array size field and add it to the array_size_list token list
619 _PUBLIC_ NTSTATUS ndr_pull_array_size(struct ndr_pull *ndr, const void *p)
622 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &size));
623 return ndr_token_store(ndr, &ndr->array_size_list, p, size);
627 get the stored array size field
629 _PUBLIC_ uint32_t ndr_get_array_size(struct ndr_pull *ndr, const void *p)
631 return ndr_token_peek(&ndr->array_size_list, p);
635 check the stored array size field
637 _PUBLIC_ NTSTATUS ndr_check_array_size(struct ndr_pull *ndr, void *p, uint32_t size)
640 stored = ndr_token_peek(&ndr->array_size_list, p);
641 if (stored != size) {
642 return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE,
643 "Bad array size - got %u expected %u\n",
650 pull an array length field and add it to the array_length_list token list
652 _PUBLIC_ NTSTATUS ndr_pull_array_length(struct ndr_pull *ndr, const void *p)
654 uint32_t length, offset;
655 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &offset));
657 return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE,
658 "non-zero array offset %u\n", offset);
660 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &length));
661 return ndr_token_store(ndr, &ndr->array_length_list, p, length);
665 get the stored array length field
667 _PUBLIC_ uint32_t ndr_get_array_length(struct ndr_pull *ndr, const void *p)
669 return ndr_token_peek(&ndr->array_length_list, p);
673 check the stored array length field
675 _PUBLIC_ NTSTATUS ndr_check_array_length(struct ndr_pull *ndr, void *p, uint32_t length)
678 stored = ndr_token_peek(&ndr->array_length_list, p);
679 if (stored != length) {
680 return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE,
681 "Bad array length - got %u expected %u\n",
690 _PUBLIC_ NTSTATUS ndr_push_set_switch_value(struct ndr_push *ndr, const void *p, uint32_t val)
692 return ndr_token_store(ndr, &ndr->switch_list, p, val);
695 _PUBLIC_ NTSTATUS ndr_pull_set_switch_value(struct ndr_pull *ndr, const void *p, uint32_t val)
697 return ndr_token_store(ndr, &ndr->switch_list, p, val);
700 _PUBLIC_ NTSTATUS ndr_print_set_switch_value(struct ndr_print *ndr, const void *p, uint32_t val)
702 return ndr_token_store(ndr, &ndr->switch_list, p, val);
706 retrieve a switch value
708 _PUBLIC_ uint32_t ndr_push_get_switch_value(struct ndr_push *ndr, const void *p)
710 return ndr_token_peek(&ndr->switch_list, p);
713 _PUBLIC_ uint32_t ndr_pull_get_switch_value(struct ndr_pull *ndr, const void *p)
715 return ndr_token_peek(&ndr->switch_list, p);
718 _PUBLIC_ uint32_t ndr_print_get_switch_value(struct ndr_print *ndr, const void *p)
720 return ndr_token_peek(&ndr->switch_list, p);
724 pull a struct from a blob using NDR
726 _PUBLIC_ NTSTATUS ndr_pull_struct_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
727 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 return fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
738 pull a struct from a blob using NDR - failing if all bytes are not consumed
740 _PUBLIC_ NTSTATUS ndr_pull_struct_blob_all(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
741 ndr_pull_flags_fn_t fn)
743 struct ndr_pull *ndr;
746 ndr = ndr_pull_init_blob(blob, mem_ctx);
748 return NT_STATUS_NO_MEMORY;
750 status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
751 if (!NT_STATUS_IS_OK(status)) return status;
752 if (ndr->offset != ndr->data_size) {
753 return NT_STATUS_BUFFER_TOO_SMALL;
759 pull a union from a blob using NDR, given the union discriminator
761 _PUBLIC_ NTSTATUS ndr_pull_union_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
762 uint32_t level, ndr_pull_flags_fn_t fn)
764 struct ndr_pull *ndr;
767 ndr = ndr_pull_init_blob(blob, mem_ctx);
769 return NT_STATUS_NO_MEMORY;
771 ndr_pull_set_switch_value(ndr, p, level);
772 status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
773 if (!NT_STATUS_IS_OK(status)) return status;
774 if (ndr->offset != ndr->data_size) {
775 return NT_STATUS_BUFFER_TOO_SMALL;
781 push a struct to a blob using NDR
783 _PUBLIC_ NTSTATUS ndr_push_struct_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, const void *p,
784 ndr_push_flags_fn_t fn)
787 struct ndr_push *ndr;
788 ndr = ndr_push_init_ctx(mem_ctx);
790 return NT_STATUS_NO_MEMORY;
792 status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
793 if (!NT_STATUS_IS_OK(status)) {
797 *blob = ndr_push_blob(ndr);
803 push a union to a blob using NDR
805 _PUBLIC_ NTSTATUS ndr_push_union_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
806 uint32_t level, ndr_push_flags_fn_t fn)
809 struct ndr_push *ndr;
810 ndr = ndr_push_init_ctx(mem_ctx);
812 return NT_STATUS_NO_MEMORY;
814 ndr_push_set_switch_value(ndr, p, level);
815 status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
816 if (!NT_STATUS_IS_OK(status)) {
820 *blob = ndr_push_blob(ndr);
826 generic ndr_size_*() handler for structures
828 _PUBLIC_ size_t ndr_size_struct(const void *p, int flags, ndr_push_flags_fn_t push)
830 struct ndr_push *ndr;
834 /* avoid recursion */
835 if (flags & LIBNDR_FLAG_NO_NDR_SIZE) return 0;
837 ndr = ndr_push_init_ctx(NULL);
839 ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE;
840 status = push(ndr, NDR_SCALARS|NDR_BUFFERS, discard_const(p));
841 if (!NT_STATUS_IS_OK(status)) {
850 generic ndr_size_*() handler for unions
852 _PUBLIC_ size_t ndr_size_union(const void *p, int flags, uint32_t level, ndr_push_flags_fn_t push)
854 struct ndr_push *ndr;
858 /* avoid recursion */
859 if (flags & LIBNDR_FLAG_NO_NDR_SIZE) return 0;
861 ndr = ndr_push_init_ctx(NULL);
863 ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE;
864 ndr_push_set_switch_value(ndr, p, level);
865 status = push(ndr, NDR_SCALARS|NDR_BUFFERS, p);
866 if (!NT_STATUS_IS_OK(status)) {
875 get the current base for relative pointers for the push
877 _PUBLIC_ uint32_t ndr_push_get_relative_base_offset(struct ndr_push *ndr)
879 return ndr->relative_base_offset;
883 restore the old base for relative pointers for the push
885 _PUBLIC_ void ndr_push_restore_relative_base_offset(struct ndr_push *ndr, uint32_t offset)
887 ndr->relative_base_offset = offset;
891 setup the current base for relative pointers for the push
892 called in the NDR_SCALAR stage
894 _PUBLIC_ NTSTATUS ndr_push_setup_relative_base_offset1(struct ndr_push *ndr, const void *p, uint32_t offset)
896 ndr->relative_base_offset = offset;
897 return ndr_token_store(ndr, &ndr->relative_base_list, p, offset);
901 setup the current base for relative pointers for the push
902 called in the NDR_BUFFERS stage
904 _PUBLIC_ NTSTATUS ndr_push_setup_relative_base_offset2(struct ndr_push *ndr, const void *p)
906 return ndr_token_retrieve(&ndr->relative_base_list, p, &ndr->relative_base_offset);
910 push a relative object - stage1
911 this is called during SCALARS processing
913 _PUBLIC_ NTSTATUS ndr_push_relative_ptr1(struct ndr_push *ndr, const void *p)
916 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0));
919 NDR_CHECK(ndr_push_align(ndr, 4));
920 NDR_CHECK(ndr_token_store(ndr, &ndr->relative_list, p, ndr->offset));
921 return ndr_push_uint32(ndr, NDR_SCALARS, 0xFFFFFFFF);
925 push a relative object - stage2
926 this is called during buffers processing
928 _PUBLIC_ NTSTATUS ndr_push_relative_ptr2(struct ndr_push *ndr, const void *p)
930 struct ndr_push_save save;
931 uint32_t ptr_offset = 0xFFFFFFFF;
935 ndr_push_save(ndr, &save);
936 NDR_CHECK(ndr_token_retrieve(&ndr->relative_list, p, &ptr_offset));
937 if (ptr_offset > ndr->offset) {
938 return ndr_push_error(ndr, NDR_ERR_BUFSIZE,
939 "ndr_push_relative_ptr2 ptr_offset(%u) > ndr->offset(%u)",
940 ptr_offset, ndr->offset);
942 ndr->offset = ptr_offset;
943 if (save.offset < ndr->relative_base_offset) {
944 return ndr_push_error(ndr, NDR_ERR_BUFSIZE,
945 "ndr_push_relative_ptr2 save.offset(%u) < ndr->relative_base_offset(%u)",
946 save.offset, ndr->relative_base_offset);
948 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, save.offset - ndr->relative_base_offset));
949 ndr_push_restore(ndr, &save);
954 get the current base for relative pointers for the pull
956 _PUBLIC_ uint32_t ndr_pull_get_relative_base_offset(struct ndr_pull *ndr)
958 return ndr->relative_base_offset;
962 restore the old base for relative pointers for the pull
964 _PUBLIC_ void ndr_pull_restore_relative_base_offset(struct ndr_pull *ndr, uint32_t offset)
966 ndr->relative_base_offset = offset;
970 setup the current base for relative pointers for the pull
971 called in the NDR_SCALAR stage
973 _PUBLIC_ NTSTATUS ndr_pull_setup_relative_base_offset1(struct ndr_pull *ndr, const void *p, uint32_t offset)
975 ndr->relative_base_offset = offset;
976 return ndr_token_store(ndr, &ndr->relative_base_list, p, offset);
980 setup the current base for relative pointers for the pull
981 called in the NDR_BUFFERS stage
983 _PUBLIC_ NTSTATUS ndr_pull_setup_relative_base_offset2(struct ndr_pull *ndr, const void *p)
985 return ndr_token_retrieve(&ndr->relative_base_list, p, &ndr->relative_base_offset);
989 pull a relative object - stage1
990 called during SCALARS processing
992 _PUBLIC_ NTSTATUS ndr_pull_relative_ptr1(struct ndr_pull *ndr, const void *p, uint32_t rel_offset)
994 rel_offset += ndr->relative_base_offset;
995 if (rel_offset > ndr->data_size) {
996 return ndr_pull_error(ndr, NDR_ERR_BUFSIZE,
997 "ndr_pull_relative_ptr1 rel_offset(%u) > ndr->data_size(%u)",
998 rel_offset, ndr->data_size);
1000 return ndr_token_store(ndr, &ndr->relative_list, p, rel_offset);
1004 pull a relative object - stage2
1005 called during BUFFERS processing
1007 _PUBLIC_ NTSTATUS ndr_pull_relative_ptr2(struct ndr_pull *ndr, const void *p)
1009 uint32_t rel_offset;
1010 NDR_CHECK(ndr_token_retrieve(&ndr->relative_list, p, &rel_offset));
1011 return ndr_pull_set_offset(ndr, rel_offset);