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
30 #include "librpc/ndr/libndr.h"
31 #include "lib/util/dlinklist.h"
32 #include "librpc/gen_ndr/dcerpc.h"
34 #define NDR_BASE_MARSHALL_SIZE 1024
36 /* this guid indicates NDR encoding in a protocol tower */
37 const struct dcerpc_syntax_id ndr_transfer_syntax = {
38 { 0x8a885d04, 0x1ceb, 0x11c9, {0x9f, 0xe8}, {0x08,0x00,0x2b,0x10,0x48,0x60} },
42 const struct dcerpc_syntax_id ndr64_transfer_syntax = {
43 { 0x71710533, 0xbeba, 0x4937, {0x83, 0x19}, {0xb5,0xdb,0xef,0x9c,0xcc,0x36} },
48 work out the number of bytes needed to align on a n byte boundary
50 _PUBLIC_ size_t ndr_align_size(uint32_t offset, size_t n)
52 if ((offset & (n-1)) == 0) return 0;
53 return n - (offset & (n-1));
57 initialise a ndr parse structure from a data blob
59 _PUBLIC_ struct ndr_pull *ndr_pull_init_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx)
63 ndr = talloc_zero(mem_ctx, struct ndr_pull);
64 if (!ndr) return NULL;
65 ndr->current_mem_ctx = mem_ctx;
67 ndr->data = blob->data;
68 ndr->data_size = blob->length;
74 advance by 'size' bytes
76 _PUBLIC_ NTSTATUS ndr_pull_advance(struct ndr_pull *ndr, uint32_t size)
79 if (ndr->offset > ndr->data_size) {
80 return ndr_pull_error(ndr, NDR_ERR_BUFSIZE,
81 "ndr_pull_advance by %u failed",
88 set the parse offset to 'ofs'
90 static NTSTATUS ndr_pull_set_offset(struct ndr_pull *ndr, uint32_t ofs)
93 if (ndr->offset > ndr->data_size) {
94 return ndr_pull_error(ndr, NDR_ERR_BUFSIZE,
95 "ndr_pull_set_offset %u failed",
101 /* save the offset/size of the current ndr state */
102 _PUBLIC_ void ndr_pull_save(struct ndr_pull *ndr, struct ndr_pull_save *save)
104 save->offset = ndr->offset;
105 save->data_size = ndr->data_size;
108 /* restore the size/offset of a ndr structure */
109 _PUBLIC_ void ndr_pull_restore(struct ndr_pull *ndr, struct ndr_pull_save *save)
111 ndr->offset = save->offset;
112 ndr->data_size = save->data_size;
116 /* create a ndr_push structure, ready for some marshalling */
117 _PUBLIC_ struct ndr_push *ndr_push_init_ctx(TALLOC_CTX *mem_ctx)
119 struct ndr_push *ndr;
121 ndr = talloc_zero(mem_ctx, struct ndr_push);
127 ndr->alloc_size = NDR_BASE_MARSHALL_SIZE;
128 ndr->data = talloc_array(ndr, uint8_t, ndr->alloc_size);
136 /* return a DATA_BLOB structure for the current ndr_push marshalled data */
137 _PUBLIC_ DATA_BLOB ndr_push_blob(struct ndr_push *ndr)
140 blob.data = ndr->data;
141 blob.length = ndr->offset;
142 if (ndr->alloc_size > ndr->offset) {
143 ndr->data[ndr->offset] = 0;
150 expand the available space in the buffer to ndr->offset + extra_size
152 _PUBLIC_ NTSTATUS ndr_push_expand(struct ndr_push *ndr, uint32_t extra_size)
154 uint32_t size = extra_size + ndr->offset;
156 if (size < ndr->offset) {
157 /* extra_size overflowed the offset */
158 return ndr_push_error(ndr, NDR_ERR_BUFSIZE, "Overflow in push_expand to %u",
162 if (ndr->alloc_size > size) {
166 ndr->alloc_size += NDR_BASE_MARSHALL_SIZE;
167 if (size+1 > ndr->alloc_size) {
168 ndr->alloc_size = size+1;
170 ndr->data = talloc_realloc(ndr, ndr->data, uint8_t, ndr->alloc_size);
172 return ndr_push_error(ndr, NDR_ERR_ALLOC, "Failed to push_expand to %u",
179 _PUBLIC_ void ndr_print_debug_helper(struct ndr_print *ndr, const char *format, ...) _PRINTF_ATTRIBUTE(2,3)
185 va_start(ap, format);
186 vasprintf(&s, format, ap);
189 for (i=0;i<ndr->depth;i++) {
193 DEBUG(0,("%s\n", s));
197 _PUBLIC_ void ndr_print_string_helper(struct ndr_print *ndr, const char *format, ...) _PRINTF_ATTRIBUTE(2,3)
202 for (i=0;i<ndr->depth;i++) {
203 ndr->private_data = talloc_asprintf_append(ndr->private_data, " ");
206 va_start(ap, format);
207 ndr->private_data = talloc_vasprintf_append(ndr->private_data, format, ap);
209 ndr->private_data = talloc_asprintf_append(ndr->private_data, "\n");
213 a useful helper function for printing idl structures via DEBUG()
215 _PUBLIC_ void ndr_print_debug(ndr_print_fn_t fn, const char *name, void *ptr)
217 struct ndr_print *ndr;
219 ndr = talloc_zero(NULL, struct ndr_print);
221 ndr->print = ndr_print_debug_helper;
229 a useful helper function for printing idl unions via DEBUG()
231 _PUBLIC_ void ndr_print_union_debug(ndr_print_fn_t fn, const char *name, uint32_t level, void *ptr)
233 struct ndr_print *ndr;
235 ndr = talloc_zero(NULL, struct ndr_print);
237 ndr->print = ndr_print_debug_helper;
240 ndr_print_set_switch_value(ndr, ptr, level);
246 a useful helper function for printing idl function calls via DEBUG()
248 _PUBLIC_ void ndr_print_function_debug(ndr_print_function_t fn, const char *name, int flags, void *ptr)
250 struct ndr_print *ndr;
252 ndr = talloc_zero(NULL, struct ndr_print);
254 ndr->print = ndr_print_debug_helper;
257 fn(ndr, name, flags, ptr);
262 a useful helper function for printing idl structures to a string
264 _PUBLIC_ char *ndr_print_struct_string(TALLOC_CTX *mem_ctx, ndr_print_fn_t fn, const char *name, void *ptr)
266 struct ndr_print *ndr;
269 ndr = talloc_zero(mem_ctx, struct ndr_print);
270 if (!ndr) return NULL;
271 ndr->private_data = talloc_strdup(ndr, "");
272 if (!ndr->private_data) {
275 ndr->print = ndr_print_string_helper;
279 ret = talloc_steal(mem_ctx, ndr->private_data);
286 a useful helper function for printing idl unions to a string
288 _PUBLIC_ char *ndr_print_union_string(TALLOC_CTX *mem_ctx, ndr_print_fn_t fn, const char *name, uint32_t level, void *ptr)
290 struct ndr_print *ndr;
293 ndr = talloc_zero(mem_ctx, struct ndr_print);
294 if (!ndr) return NULL;
295 ndr->private_data = talloc_strdup(ndr, "");
296 if (!ndr->private_data) {
299 ndr->print = ndr_print_string_helper;
302 ndr_print_set_switch_value(ndr, ptr, level);
304 ret = talloc_steal(mem_ctx, ndr->private_data);
311 a useful helper function for printing idl function calls to a string
313 _PUBLIC_ char *ndr_print_function_string(TALLOC_CTX *mem_ctx,
314 ndr_print_function_t fn, const char *name,
315 int flags, void *ptr)
317 struct ndr_print *ndr;
320 ndr = talloc_zero(mem_ctx, struct ndr_print);
321 if (!ndr) return NULL;
322 ndr->private_data = talloc_strdup(ndr, "");
323 if (!ndr->private_data) {
326 ndr->print = ndr_print_string_helper;
329 fn(ndr, name, flags, ptr);
330 ret = talloc_steal(mem_ctx, ndr->private_data);
336 _PUBLIC_ void ndr_set_flags(uint32_t *pflags, uint32_t new_flags)
338 /* the big/little endian flags are inter-dependent */
339 if (new_flags & LIBNDR_FLAG_LITTLE_ENDIAN) {
340 (*pflags) &= ~LIBNDR_FLAG_BIGENDIAN;
342 if (new_flags & LIBNDR_FLAG_BIGENDIAN) {
343 (*pflags) &= ~LIBNDR_FLAG_LITTLE_ENDIAN;
345 if (new_flags & LIBNDR_FLAG_REMAINING) {
346 (*pflags) &= ~LIBNDR_ALIGN_FLAGS;
348 if (new_flags & LIBNDR_ALIGN_FLAGS) {
349 (*pflags) &= ~LIBNDR_FLAG_REMAINING;
351 (*pflags) |= new_flags;
354 static NTSTATUS ndr_map_error(enum ndr_err_code ndr_err)
357 case NDR_ERR_BUFSIZE:
358 return NT_STATUS_BUFFER_TOO_SMALL;
360 return NT_STATUS_INTERNAL_ERROR;
362 return NT_STATUS_NO_MEMORY;
363 case NDR_ERR_ARRAY_SIZE:
364 return NT_STATUS_ARRAY_BOUNDS_EXCEEDED;
369 /* we should map all error codes to different status codes */
370 return NT_STATUS_INVALID_PARAMETER;
374 return and possibly log an NDR error
376 _PUBLIC_ NTSTATUS ndr_pull_error(struct ndr_pull *ndr,
377 enum ndr_err_code ndr_err,
378 const char *format, ...) _PRINTF_ATTRIBUTE(3,4)
383 va_start(ap, format);
384 vasprintf(&s, format, ap);
387 DEBUG(3,("ndr_pull_error(%u): %s\n", ndr_err, s));
391 return ndr_map_error(ndr_err);
395 return and possibly log an NDR error
397 _PUBLIC_ NTSTATUS ndr_push_error(struct ndr_push *ndr,
398 enum ndr_err_code ndr_err,
399 const char *format, ...) _PRINTF_ATTRIBUTE(3,4)
404 va_start(ap, format);
405 vasprintf(&s, format, ap);
408 DEBUG(3,("ndr_push_error(%u): %s\n", ndr_err, s));
412 return ndr_map_error(ndr_err);
416 handle subcontext buffers, which in midl land are user-marshalled, but
417 we use magic in pidl to make them easier to cope with
419 _PUBLIC_ NTSTATUS ndr_pull_subcontext_start(struct ndr_pull *ndr,
420 struct ndr_pull **_subndr,
424 struct ndr_pull *subndr;
425 uint32_t r_content_size;
427 switch (header_size) {
429 uint32_t content_size = ndr->data_size - ndr->offset;
431 content_size = size_is;
433 r_content_size = content_size;
438 uint16_t content_size;
439 NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &content_size));
440 if (size_is >= 0 && size_is != content_size) {
441 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) size_is(%d) mismatch content_size %d",
442 (int)size_is, (int)content_size);
444 r_content_size = content_size;
449 uint32_t content_size;
450 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &content_size));
451 if (size_is >= 0 && size_is != content_size) {
452 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) size_is(%d) mismatch content_size %d",
453 (int)size_is, (int)content_size);
455 r_content_size = content_size;
459 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) header_size %d",
463 NDR_PULL_NEED_BYTES(ndr, r_content_size);
465 subndr = talloc_zero(ndr, struct ndr_pull);
466 NT_STATUS_HAVE_NO_MEMORY(subndr);
467 subndr->flags = ndr->flags;
468 subndr->current_mem_ctx = ndr->current_mem_ctx;
470 subndr->data = ndr->data + ndr->offset;
472 subndr->data_size = r_content_size;
478 _PUBLIC_ NTSTATUS ndr_pull_subcontext_end(struct ndr_pull *ndr,
479 struct ndr_pull *subndr,
486 } else if (header_size > 0) {
487 advance = subndr->data_size;
489 advance = subndr->offset;
491 NDR_CHECK(ndr_pull_advance(ndr, advance));
495 _PUBLIC_ NTSTATUS ndr_push_subcontext_start(struct ndr_push *ndr,
496 struct ndr_push **_subndr,
500 struct ndr_push *subndr;
502 subndr = ndr_push_init_ctx(ndr);
503 NT_STATUS_HAVE_NO_MEMORY(subndr);
504 subndr->flags = ndr->flags;
511 push a subcontext header
513 _PUBLIC_ NTSTATUS ndr_push_subcontext_end(struct ndr_push *ndr,
514 struct ndr_push *subndr,
519 ssize_t padding_len = size_is - subndr->offset;
520 if (padding_len > 0) {
521 NDR_CHECK(ndr_push_zero(subndr, padding_len));
522 } else if (padding_len < 0) {
523 return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PUSH) content_size %d is larger than size_is(%d)",
524 (int)subndr->offset, (int)size_is);
528 switch (header_size) {
533 NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, subndr->offset));
537 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, subndr->offset));
541 return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext header size %d",
545 NDR_CHECK(ndr_push_bytes(ndr, subndr->data, subndr->offset));
550 store a token in the ndr context, for later retrieval
552 _PUBLIC_ NTSTATUS ndr_token_store(TALLOC_CTX *mem_ctx,
553 struct ndr_token_list **list,
557 struct ndr_token_list *tok;
558 tok = talloc(mem_ctx, struct ndr_token_list);
560 return NT_STATUS_NO_MEMORY;
564 DLIST_ADD((*list), tok);
569 retrieve a token from a ndr context, using cmp_fn to match the tokens
571 _PUBLIC_ NTSTATUS ndr_token_retrieve_cmp_fn(struct ndr_token_list **list, const void *key, uint32_t *v,
572 comparison_fn_t _cmp_fn, BOOL _remove_tok)
574 struct ndr_token_list *tok;
575 for (tok=*list;tok;tok=tok->next) {
576 if (_cmp_fn && _cmp_fn(tok->key,key)==0) goto found;
577 else if (!_cmp_fn && tok->key == key) goto found;
579 return ndr_map_error(NDR_ERR_TOKEN);
583 DLIST_REMOVE((*list), tok);
590 retrieve a token from a ndr context
592 _PUBLIC_ NTSTATUS ndr_token_retrieve(struct ndr_token_list **list, const void *key, uint32_t *v)
594 return ndr_token_retrieve_cmp_fn(list, key, v, NULL, True);
598 peek at but don't removed a token from a ndr context
600 _PUBLIC_ uint32_t ndr_token_peek(struct ndr_token_list **list, const void *key)
604 status = ndr_token_retrieve_cmp_fn(list, key, &v, NULL, False);
605 if (NT_STATUS_IS_OK(status)) return v;
610 pull an array size field and add it to the array_size_list token list
612 _PUBLIC_ NTSTATUS ndr_pull_array_size(struct ndr_pull *ndr, const void *p)
615 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &size));
616 return ndr_token_store(ndr, &ndr->array_size_list, p, size);
620 get the stored array size field
622 _PUBLIC_ uint32_t ndr_get_array_size(struct ndr_pull *ndr, const void *p)
624 return ndr_token_peek(&ndr->array_size_list, p);
628 check the stored array size field
630 _PUBLIC_ NTSTATUS ndr_check_array_size(struct ndr_pull *ndr, void *p, uint32_t size)
633 stored = ndr_token_peek(&ndr->array_size_list, p);
634 if (stored != size) {
635 return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE,
636 "Bad array size - got %u expected %u\n",
643 pull an array length field and add it to the array_length_list token list
645 _PUBLIC_ NTSTATUS ndr_pull_array_length(struct ndr_pull *ndr, const void *p)
647 uint32_t length, offset;
648 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &offset));
650 return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE,
651 "non-zero array offset %u\n", offset);
653 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &length));
654 return ndr_token_store(ndr, &ndr->array_length_list, p, length);
658 get the stored array length field
660 _PUBLIC_ uint32_t ndr_get_array_length(struct ndr_pull *ndr, const void *p)
662 return ndr_token_peek(&ndr->array_length_list, p);
666 check the stored array length field
668 _PUBLIC_ NTSTATUS ndr_check_array_length(struct ndr_pull *ndr, void *p, uint32_t length)
671 stored = ndr_token_peek(&ndr->array_length_list, p);
672 if (stored != length) {
673 return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE,
674 "Bad array length - got %u expected %u\n",
683 _PUBLIC_ NTSTATUS ndr_push_set_switch_value(struct ndr_push *ndr, const void *p, uint32_t val)
685 return ndr_token_store(ndr, &ndr->switch_list, p, val);
688 _PUBLIC_ NTSTATUS ndr_pull_set_switch_value(struct ndr_pull *ndr, const void *p, uint32_t val)
690 return ndr_token_store(ndr, &ndr->switch_list, p, val);
693 _PUBLIC_ NTSTATUS ndr_print_set_switch_value(struct ndr_print *ndr, const void *p, uint32_t val)
695 return ndr_token_store(ndr, &ndr->switch_list, p, val);
699 retrieve a switch value
701 _PUBLIC_ uint32_t ndr_push_get_switch_value(struct ndr_push *ndr, const void *p)
703 return ndr_token_peek(&ndr->switch_list, p);
706 _PUBLIC_ uint32_t ndr_pull_get_switch_value(struct ndr_pull *ndr, const void *p)
708 return ndr_token_peek(&ndr->switch_list, p);
711 _PUBLIC_ uint32_t ndr_print_get_switch_value(struct ndr_print *ndr, const void *p)
713 return ndr_token_peek(&ndr->switch_list, p);
717 pull a struct from a blob using NDR
719 _PUBLIC_ NTSTATUS ndr_pull_struct_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
720 ndr_pull_flags_fn_t fn)
722 struct ndr_pull *ndr;
723 ndr = ndr_pull_init_blob(blob, mem_ctx);
725 return NT_STATUS_NO_MEMORY;
727 return fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
731 pull a struct from a blob using NDR - failing if all bytes are not consumed
733 _PUBLIC_ NTSTATUS ndr_pull_struct_blob_all(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
734 ndr_pull_flags_fn_t fn)
736 struct ndr_pull *ndr;
739 ndr = ndr_pull_init_blob(blob, mem_ctx);
741 return NT_STATUS_NO_MEMORY;
743 status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
744 if (!NT_STATUS_IS_OK(status)) return status;
745 if (ndr->offset < ndr->data_size) {
746 return NT_STATUS_PORT_MESSAGE_TOO_LONG;
752 pull a union from a blob using NDR, given the union discriminator
754 _PUBLIC_ NTSTATUS ndr_pull_union_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
755 uint32_t level, ndr_pull_flags_fn_t fn)
757 struct ndr_pull *ndr;
760 ndr = ndr_pull_init_blob(blob, mem_ctx);
762 return NT_STATUS_NO_MEMORY;
764 ndr_pull_set_switch_value(ndr, p, level);
765 status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
766 if (!NT_STATUS_IS_OK(status)) return status;
767 if (ndr->offset != ndr->data_size) {
768 return NT_STATUS_BUFFER_TOO_SMALL;
774 push a struct to a blob using NDR
776 _PUBLIC_ NTSTATUS ndr_push_struct_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, const void *p,
777 ndr_push_flags_fn_t fn)
780 struct ndr_push *ndr;
781 ndr = ndr_push_init_ctx(mem_ctx);
783 return NT_STATUS_NO_MEMORY;
785 status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
786 if (!NT_STATUS_IS_OK(status)) {
790 *blob = ndr_push_blob(ndr);
791 talloc_steal(mem_ctx, blob->data);
798 push a union to a blob using NDR
800 _PUBLIC_ NTSTATUS ndr_push_union_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
801 uint32_t level, ndr_push_flags_fn_t fn)
804 struct ndr_push *ndr;
805 ndr = ndr_push_init_ctx(mem_ctx);
807 return NT_STATUS_NO_MEMORY;
809 ndr_push_set_switch_value(ndr, p, level);
810 status = fn(ndr, NDR_SCALARS|NDR_BUFFERS, p);
811 if (!NT_STATUS_IS_OK(status)) {
815 *blob = ndr_push_blob(ndr);
816 talloc_steal(mem_ctx, blob->data);
823 generic ndr_size_*() handler for structures
825 _PUBLIC_ size_t ndr_size_struct(const void *p, int flags, ndr_push_flags_fn_t push)
827 struct ndr_push *ndr;
831 /* avoid recursion */
832 if (flags & LIBNDR_FLAG_NO_NDR_SIZE) return 0;
834 ndr = ndr_push_init_ctx(NULL);
836 ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE;
837 status = push(ndr, NDR_SCALARS|NDR_BUFFERS, discard_const(p));
838 if (!NT_STATUS_IS_OK(status)) {
847 generic ndr_size_*() handler for unions
849 _PUBLIC_ size_t ndr_size_union(const void *p, int flags, uint32_t level, ndr_push_flags_fn_t push)
851 struct ndr_push *ndr;
855 /* avoid recursion */
856 if (flags & LIBNDR_FLAG_NO_NDR_SIZE) return 0;
858 ndr = ndr_push_init_ctx(NULL);
860 ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE;
861 ndr_push_set_switch_value(ndr, p, level);
862 status = push(ndr, NDR_SCALARS|NDR_BUFFERS, p);
863 if (!NT_STATUS_IS_OK(status)) {
872 get the current base for relative pointers for the push
874 _PUBLIC_ uint32_t ndr_push_get_relative_base_offset(struct ndr_push *ndr)
876 return ndr->relative_base_offset;
880 restore the old base for relative pointers for the push
882 _PUBLIC_ void ndr_push_restore_relative_base_offset(struct ndr_push *ndr, uint32_t offset)
884 ndr->relative_base_offset = offset;
888 setup the current base for relative pointers for the push
889 called in the NDR_SCALAR stage
891 _PUBLIC_ NTSTATUS ndr_push_setup_relative_base_offset1(struct ndr_push *ndr, const void *p, uint32_t offset)
893 ndr->relative_base_offset = offset;
894 return ndr_token_store(ndr, &ndr->relative_base_list, p, offset);
898 setup the current base for relative pointers for the push
899 called in the NDR_BUFFERS stage
901 _PUBLIC_ NTSTATUS ndr_push_setup_relative_base_offset2(struct ndr_push *ndr, const void *p)
903 return ndr_token_retrieve(&ndr->relative_base_list, p, &ndr->relative_base_offset);
907 push a relative object - stage1
908 this is called during SCALARS processing
910 _PUBLIC_ NTSTATUS ndr_push_relative_ptr1(struct ndr_push *ndr, const void *p)
913 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0));
916 NDR_CHECK(ndr_push_align(ndr, 4));
917 NDR_CHECK(ndr_token_store(ndr, &ndr->relative_list, p, ndr->offset));
918 return ndr_push_uint32(ndr, NDR_SCALARS, 0xFFFFFFFF);
922 push a relative object - stage2
923 this is called during buffers processing
925 _PUBLIC_ NTSTATUS ndr_push_relative_ptr2(struct ndr_push *ndr, const void *p)
927 struct ndr_push_save save;
928 uint32_t ptr_offset = 0xFFFFFFFF;
932 ndr_push_save(ndr, &save);
933 NDR_CHECK(ndr_token_retrieve(&ndr->relative_list, p, &ptr_offset));
934 if (ptr_offset > ndr->offset) {
935 return ndr_push_error(ndr, NDR_ERR_BUFSIZE,
936 "ndr_push_relative_ptr2 ptr_offset(%u) > ndr->offset(%u)",
937 ptr_offset, ndr->offset);
939 ndr->offset = ptr_offset;
940 if (save.offset < ndr->relative_base_offset) {
941 return ndr_push_error(ndr, NDR_ERR_BUFSIZE,
942 "ndr_push_relative_ptr2 save.offset(%u) < ndr->relative_base_offset(%u)",
943 save.offset, ndr->relative_base_offset);
945 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, save.offset - ndr->relative_base_offset));
946 ndr_push_restore(ndr, &save);
951 get the current base for relative pointers for the pull
953 _PUBLIC_ uint32_t ndr_pull_get_relative_base_offset(struct ndr_pull *ndr)
955 return ndr->relative_base_offset;
959 restore the old base for relative pointers for the pull
961 _PUBLIC_ void ndr_pull_restore_relative_base_offset(struct ndr_pull *ndr, uint32_t offset)
963 ndr->relative_base_offset = offset;
967 setup the current base for relative pointers for the pull
968 called in the NDR_SCALAR stage
970 _PUBLIC_ NTSTATUS ndr_pull_setup_relative_base_offset1(struct ndr_pull *ndr, const void *p, uint32_t offset)
972 ndr->relative_base_offset = offset;
973 return ndr_token_store(ndr, &ndr->relative_base_list, p, offset);
977 setup the current base for relative pointers for the pull
978 called in the NDR_BUFFERS stage
980 _PUBLIC_ NTSTATUS ndr_pull_setup_relative_base_offset2(struct ndr_pull *ndr, const void *p)
982 return ndr_token_retrieve(&ndr->relative_base_list, p, &ndr->relative_base_offset);
986 pull a relative object - stage1
987 called during SCALARS processing
989 _PUBLIC_ NTSTATUS ndr_pull_relative_ptr1(struct ndr_pull *ndr, const void *p, uint32_t rel_offset)
991 rel_offset += ndr->relative_base_offset;
992 if (rel_offset > ndr->data_size) {
993 return ndr_pull_error(ndr, NDR_ERR_BUFSIZE,
994 "ndr_pull_relative_ptr1 rel_offset(%u) > ndr->data_size(%u)",
995 rel_offset, ndr->data_size);
997 return ndr_token_store(ndr, &ndr->relative_list, p, rel_offset);
1001 pull a relative object - stage2
1002 called during BUFFERS processing
1004 _PUBLIC_ NTSTATUS ndr_pull_relative_ptr2(struct ndr_pull *ndr, const void *p)
1006 uint32_t rel_offset;
1007 NDR_CHECK(ndr_token_retrieve(&ndr->relative_list, p, &rel_offset));
1008 return ndr_pull_set_offset(ndr, rel_offset);