s3: Replace cli_negprot_sendsync() by cli_negprot_send()
[Samba.git] / librpc / ndr / ndr.c
blob56d1fab05e4b2b778f558eb84d8eff204dfeacc5
1 /*
2 Unix SMB/CIFS implementation.
4 libndr interface
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
26 of NDR encoding rules
29 #include "includes.h"
30 #include "librpc/ndr/libndr.h"
31 #include "../lib/util/dlinklist.h"
32 #if _SAMBA_BUILD_ == 4
33 #include "param/param.h"
34 #endif
36 #define NDR_BASE_MARSHALL_SIZE 1024
38 /* this guid indicates NDR encoding in a protocol tower */
39 const struct ndr_syntax_id ndr_transfer_syntax = {
40 { 0x8a885d04, 0x1ceb, 0x11c9, {0x9f, 0xe8}, {0x08,0x00,0x2b,0x10,0x48,0x60} },
44 const struct ndr_syntax_id ndr64_transfer_syntax = {
45 { 0x71710533, 0xbeba, 0x4937, {0x83, 0x19}, {0xb5,0xdb,0xef,0x9c,0xcc,0x36} },
49 const struct ndr_syntax_id null_ndr_syntax_id = {
50 { 0, 0, 0, { 0, 0 }, { 0, 0, 0, 0, 0, 0 } },
55 work out the number of bytes needed to align on a n byte boundary
57 _PUBLIC_ size_t ndr_align_size(uint32_t offset, size_t n)
59 if ((offset & (n-1)) == 0) return 0;
60 return n - (offset & (n-1));
64 initialise a ndr parse structure from a data blob
66 _PUBLIC_ struct ndr_pull *ndr_pull_init_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx)
68 struct ndr_pull *ndr;
70 ndr = talloc_zero(mem_ctx, struct ndr_pull);
71 if (!ndr) return NULL;
72 ndr->current_mem_ctx = mem_ctx;
74 ndr->data = blob->data;
75 ndr->data_size = blob->length;
77 return ndr;
81 advance by 'size' bytes
83 _PUBLIC_ enum ndr_err_code ndr_pull_advance(struct ndr_pull *ndr, uint32_t size)
85 ndr->offset += size;
86 if (ndr->offset > ndr->data_size) {
87 return ndr_pull_error(ndr, NDR_ERR_BUFSIZE,
88 "ndr_pull_advance by %u failed",
89 size);
91 return NDR_ERR_SUCCESS;
95 set the parse offset to 'ofs'
97 static enum ndr_err_code ndr_pull_set_offset(struct ndr_pull *ndr, uint32_t ofs)
99 ndr->offset = ofs;
100 if (ndr->offset > ndr->data_size) {
101 return ndr_pull_error(ndr, NDR_ERR_BUFSIZE,
102 "ndr_pull_set_offset %u failed",
103 ofs);
105 return NDR_ERR_SUCCESS;
108 /* create a ndr_push structure, ready for some marshalling */
109 _PUBLIC_ struct ndr_push *ndr_push_init_ctx(TALLOC_CTX *mem_ctx)
111 struct ndr_push *ndr;
113 ndr = talloc_zero(mem_ctx, struct ndr_push);
114 if (!ndr) {
115 return NULL;
118 ndr->flags = 0;
119 ndr->alloc_size = NDR_BASE_MARSHALL_SIZE;
120 ndr->data = talloc_array(ndr, uint8_t, ndr->alloc_size);
121 if (!ndr->data) {
122 return NULL;
125 return ndr;
128 /* return a DATA_BLOB structure for the current ndr_push marshalled data */
129 _PUBLIC_ DATA_BLOB ndr_push_blob(struct ndr_push *ndr)
131 DATA_BLOB blob;
132 blob = data_blob_const(ndr->data, ndr->offset);
133 if (ndr->alloc_size > ndr->offset) {
134 ndr->data[ndr->offset] = 0;
136 return blob;
141 expand the available space in the buffer to ndr->offset + extra_size
143 _PUBLIC_ enum ndr_err_code ndr_push_expand(struct ndr_push *ndr, uint32_t extra_size)
145 uint32_t size = extra_size + ndr->offset;
147 if (size < ndr->offset) {
148 /* extra_size overflowed the offset */
149 return ndr_push_error(ndr, NDR_ERR_BUFSIZE, "Overflow in push_expand to %u",
150 size);
153 if (ndr->alloc_size > size) {
154 return NDR_ERR_SUCCESS;
157 ndr->alloc_size += NDR_BASE_MARSHALL_SIZE;
158 if (size+1 > ndr->alloc_size) {
159 ndr->alloc_size = size+1;
161 ndr->data = talloc_realloc(ndr, ndr->data, uint8_t, ndr->alloc_size);
162 if (!ndr->data) {
163 return ndr_push_error(ndr, NDR_ERR_ALLOC, "Failed to push_expand to %u",
164 ndr->alloc_size);
167 return NDR_ERR_SUCCESS;
170 _PUBLIC_ void ndr_print_debug_helper(struct ndr_print *ndr, const char *format, ...)
172 va_list ap;
173 char *s = NULL;
174 uint32_t i;
175 int ret;
177 va_start(ap, format);
178 ret = vasprintf(&s, format, ap);
179 va_end(ap);
181 if (ret == -1) {
182 return;
185 if (ndr->no_newline) {
186 DEBUGADD(1,("%s", s));
187 free(s);
188 return;
191 for (i=0;i<ndr->depth;i++) {
192 DEBUGADD(1,(" "));
195 DEBUGADD(1,("%s\n", s));
196 free(s);
199 _PUBLIC_ void ndr_print_printf_helper(struct ndr_print *ndr, const char *format, ...)
201 va_list ap;
202 uint32_t i;
204 if (!ndr->no_newline) {
205 for (i=0;i<ndr->depth;i++) {
206 printf(" ");
210 va_start(ap, format);
211 vprintf(format, ap);
212 va_end(ap);
213 if (!ndr->no_newline) {
214 printf("\n");
218 _PUBLIC_ void ndr_print_string_helper(struct ndr_print *ndr, const char *format, ...)
220 va_list ap;
221 uint32_t i;
223 if (!ndr->no_newline) {
224 for (i=0;i<ndr->depth;i++) {
225 ndr->private_data = talloc_asprintf_append_buffer(
226 (char *)ndr->private_data, " ");
230 va_start(ap, format);
231 ndr->private_data = talloc_vasprintf_append_buffer((char *)ndr->private_data,
232 format, ap);
233 va_end(ap);
234 if (!ndr->no_newline) {
235 ndr->private_data = talloc_asprintf_append_buffer((char *)ndr->private_data,
236 "\n");
241 a useful helper function for printing idl structures via DEBUG()
243 _PUBLIC_ void ndr_print_debug(ndr_print_fn_t fn, const char *name, void *ptr)
245 struct ndr_print *ndr;
247 DEBUG(1,(" "));
249 ndr = talloc_zero(NULL, struct ndr_print);
250 if (!ndr) return;
251 ndr->print = ndr_print_debug_helper;
252 ndr->depth = 1;
253 ndr->flags = 0;
254 fn(ndr, name, ptr);
255 talloc_free(ndr);
259 a useful helper function for printing idl unions via DEBUG()
261 _PUBLIC_ void ndr_print_union_debug(ndr_print_fn_t fn, const char *name, uint32_t level, void *ptr)
263 struct ndr_print *ndr;
265 DEBUG(1,(" "));
267 ndr = talloc_zero(NULL, struct ndr_print);
268 if (!ndr) return;
269 ndr->print = ndr_print_debug_helper;
270 ndr->depth = 1;
271 ndr->flags = 0;
272 ndr_print_set_switch_value(ndr, ptr, level);
273 fn(ndr, name, ptr);
274 talloc_free(ndr);
278 a useful helper function for printing idl function calls via DEBUG()
280 _PUBLIC_ void ndr_print_function_debug(ndr_print_function_t fn, const char *name, int flags, void *ptr)
282 struct ndr_print *ndr;
284 DEBUG(1,(" "));
286 ndr = talloc_zero(NULL, struct ndr_print);
287 if (!ndr) return;
288 ndr->print = ndr_print_debug_helper;
289 ndr->depth = 1;
290 ndr->flags = 0;
292 fn(ndr, name, flags, ptr);
293 talloc_free(ndr);
297 a useful helper function for printing idl structures to a string
299 _PUBLIC_ char *ndr_print_struct_string(TALLOC_CTX *mem_ctx, ndr_print_fn_t fn, const char *name, void *ptr)
301 struct ndr_print *ndr;
302 char *ret = NULL;
304 ndr = talloc_zero(mem_ctx, struct ndr_print);
305 if (!ndr) return NULL;
306 ndr->private_data = talloc_strdup(ndr, "");
307 if (!ndr->private_data) {
308 goto failed;
310 ndr->print = ndr_print_string_helper;
311 ndr->depth = 1;
312 ndr->flags = 0;
314 fn(ndr, name, ptr);
315 ret = talloc_steal(mem_ctx, (char *)ndr->private_data);
316 failed:
317 talloc_free(ndr);
318 return ret;
322 a useful helper function for printing idl unions to a string
324 _PUBLIC_ char *ndr_print_union_string(TALLOC_CTX *mem_ctx, ndr_print_fn_t fn, const char *name, uint32_t level, void *ptr)
326 struct ndr_print *ndr;
327 char *ret = NULL;
329 ndr = talloc_zero(mem_ctx, struct ndr_print);
330 if (!ndr) return NULL;
331 ndr->private_data = talloc_strdup(ndr, "");
332 if (!ndr->private_data) {
333 goto failed;
335 ndr->print = ndr_print_string_helper;
336 ndr->depth = 1;
337 ndr->flags = 0;
338 ndr_print_set_switch_value(ndr, ptr, level);
339 fn(ndr, name, ptr);
340 ret = talloc_steal(mem_ctx, (char *)ndr->private_data);
341 failed:
342 talloc_free(ndr);
343 return ret;
347 a useful helper function for printing idl function calls to a string
349 _PUBLIC_ char *ndr_print_function_string(TALLOC_CTX *mem_ctx,
350 ndr_print_function_t fn, const char *name,
351 int flags, void *ptr)
353 struct ndr_print *ndr;
354 char *ret = NULL;
356 ndr = talloc_zero(mem_ctx, struct ndr_print);
357 if (!ndr) return NULL;
358 ndr->private_data = talloc_strdup(ndr, "");
359 if (!ndr->private_data) {
360 goto failed;
362 ndr->print = ndr_print_string_helper;
363 ndr->depth = 1;
364 ndr->flags = 0;
365 fn(ndr, name, flags, ptr);
366 ret = talloc_steal(mem_ctx, (char *)ndr->private_data);
367 failed:
368 talloc_free(ndr);
369 return ret;
372 _PUBLIC_ void ndr_set_flags(uint32_t *pflags, uint32_t new_flags)
374 /* the big/little endian flags are inter-dependent */
375 if (new_flags & LIBNDR_FLAG_LITTLE_ENDIAN) {
376 (*pflags) &= ~LIBNDR_FLAG_BIGENDIAN;
377 (*pflags) &= ~LIBNDR_FLAG_NDR64;
379 if (new_flags & LIBNDR_FLAG_BIGENDIAN) {
380 (*pflags) &= ~LIBNDR_FLAG_LITTLE_ENDIAN;
381 (*pflags) &= ~LIBNDR_FLAG_NDR64;
383 if (new_flags & LIBNDR_FLAG_REMAINING) {
384 (*pflags) &= ~LIBNDR_ALIGN_FLAGS;
386 if (new_flags & LIBNDR_ALIGN_FLAGS) {
387 (*pflags) &= ~LIBNDR_FLAG_REMAINING;
389 if (new_flags & LIBNDR_FLAG_NO_RELATIVE_REVERSE) {
390 (*pflags) &= ~LIBNDR_FLAG_RELATIVE_REVERSE;
392 (*pflags) |= new_flags;
396 return and possibly log an NDR error
398 _PUBLIC_ enum ndr_err_code ndr_pull_error(struct ndr_pull *ndr,
399 enum ndr_err_code ndr_err,
400 const char *format, ...)
402 char *s=NULL;
403 va_list ap;
404 int ret;
406 va_start(ap, format);
407 ret = vasprintf(&s, format, ap);
408 va_end(ap);
410 if (ret == -1) {
411 return NDR_ERR_ALLOC;
414 DEBUG(1,("ndr_pull_error(%u): %s\n", ndr_err, s));
416 free(s);
418 return ndr_err;
422 return and possibly log an NDR error
424 _PUBLIC_ enum ndr_err_code ndr_push_error(struct ndr_push *ndr,
425 enum ndr_err_code ndr_err,
426 const char *format, ...)
428 char *s=NULL;
429 va_list ap;
430 int ret;
432 va_start(ap, format);
433 ret = vasprintf(&s, format, ap);
434 va_end(ap);
436 if (ret == -1) {
437 return NDR_ERR_ALLOC;
440 DEBUG(1,("ndr_push_error(%u): %s\n", ndr_err, s));
442 free(s);
444 return ndr_err;
448 handle subcontext buffers, which in midl land are user-marshalled, but
449 we use magic in pidl to make them easier to cope with
451 _PUBLIC_ enum ndr_err_code ndr_pull_subcontext_start(struct ndr_pull *ndr,
452 struct ndr_pull **_subndr,
453 size_t header_size,
454 ssize_t size_is)
456 struct ndr_pull *subndr;
457 uint32_t r_content_size;
458 bool force_le = false;
459 bool force_be = false;
461 switch (header_size) {
462 case 0: {
463 uint32_t content_size = ndr->data_size - ndr->offset;
464 if (size_is >= 0) {
465 content_size = size_is;
467 r_content_size = content_size;
468 break;
471 case 2: {
472 uint16_t content_size;
473 NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &content_size));
474 if (size_is >= 0 && size_is != content_size) {
475 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) size_is(%d) mismatch content_size %d",
476 (int)size_is, (int)content_size);
478 r_content_size = content_size;
479 break;
482 case 4: {
483 uint32_t content_size;
484 NDR_CHECK(ndr_pull_uint3264(ndr, NDR_SCALARS, &content_size));
485 if (size_is >= 0 && size_is != content_size) {
486 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) size_is(%d) mismatch content_size %d",
487 (int)size_is, (int)content_size);
489 r_content_size = content_size;
490 break;
492 case 0xFFFFFC01: {
494 * Common Type Header for the Serialization Stream
495 * See [MS-RPCE] 2.2.6 Type Serialization Version 1
497 uint8_t version;
498 uint8_t drep;
499 uint16_t hdrlen;
500 uint32_t filler;
501 uint32_t content_size;
502 uint32_t reserved;
504 /* version */
505 NDR_CHECK(ndr_pull_uint8(ndr, NDR_SCALARS, &version));
507 if (version != 1) {
508 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT,
509 "Bad subcontext (PULL) Common Type Header version %d != 1",
510 (int)version);
514 * 0x10 little endian
515 * 0x00 big endian
517 NDR_CHECK(ndr_pull_uint8(ndr, NDR_SCALARS, &drep));
518 if (drep == 0x10) {
519 force_le = true;
520 } else if (drep == 0x00) {
521 force_be = true;
522 } else {
523 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT,
524 "Bad subcontext (PULL) Common Type Header invalid drep 0x%02X",
525 (unsigned int)drep);
528 /* length of the "Private Header for Constructed Type" */
529 NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, &hdrlen));
530 if (hdrlen != 8) {
531 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT,
532 "Bad subcontext (PULL) Common Type Header length %d != 8",
533 (int)hdrlen);
536 /* filler should be ignored */
537 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &filler));
540 * Private Header for Constructed Type
542 /* length - will be updated latter */
543 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &content_size));
544 if (size_is >= 0 && size_is != content_size) {
545 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) size_is(%d) mismatch content_size %d",
546 (int)size_is, (int)content_size);
548 /* the content size must be a multiple of 8 */
549 if ((content_size % 8) != 0) {
550 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT,
551 "Bad subcontext (PULL) size_is(%d) not padded to 8 content_size %d",
552 (int)size_is, (int)content_size);
554 r_content_size = content_size;
556 /* reserved */
557 NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &reserved));
558 break;
560 default:
561 return ndr_pull_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PULL) header_size %d",
562 (int)header_size);
565 NDR_PULL_NEED_BYTES(ndr, r_content_size);
567 subndr = talloc_zero(ndr, struct ndr_pull);
568 NDR_ERR_HAVE_NO_MEMORY(subndr);
569 subndr->flags = ndr->flags & ~LIBNDR_FLAG_NDR64;
570 subndr->current_mem_ctx = ndr->current_mem_ctx;
572 subndr->data = ndr->data + ndr->offset;
573 subndr->offset = 0;
574 subndr->data_size = r_content_size;
576 if (force_le) {
577 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_LITTLE_ENDIAN);
578 } else if (force_be) {
579 ndr_set_flags(&ndr->flags, LIBNDR_FLAG_BIGENDIAN);
582 *_subndr = subndr;
583 return NDR_ERR_SUCCESS;
586 _PUBLIC_ enum ndr_err_code ndr_pull_subcontext_end(struct ndr_pull *ndr,
587 struct ndr_pull *subndr,
588 size_t header_size,
589 ssize_t size_is)
591 uint32_t advance;
592 if (size_is >= 0) {
593 advance = size_is;
594 } else if (header_size > 0) {
595 advance = subndr->data_size;
596 } else {
597 advance = subndr->offset;
599 NDR_CHECK(ndr_pull_advance(ndr, advance));
600 return NDR_ERR_SUCCESS;
603 _PUBLIC_ enum ndr_err_code ndr_push_subcontext_start(struct ndr_push *ndr,
604 struct ndr_push **_subndr,
605 size_t header_size,
606 ssize_t size_is)
608 struct ndr_push *subndr;
610 subndr = ndr_push_init_ctx(ndr);
611 NDR_ERR_HAVE_NO_MEMORY(subndr);
612 subndr->flags = ndr->flags & ~LIBNDR_FLAG_NDR64;
614 if (size_is > 0) {
615 NDR_CHECK(ndr_push_zero(subndr, size_is));
616 subndr->offset = 0;
617 subndr->relative_end_offset = size_is;
620 *_subndr = subndr;
621 return NDR_ERR_SUCCESS;
625 push a subcontext header
627 _PUBLIC_ enum ndr_err_code ndr_push_subcontext_end(struct ndr_push *ndr,
628 struct ndr_push *subndr,
629 size_t header_size,
630 ssize_t size_is)
632 ssize_t padding_len;
634 if (size_is >= 0) {
635 padding_len = size_is - subndr->offset;
636 if (padding_len < 0) {
637 return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext (PUSH) content_size %d is larger than size_is(%d)",
638 (int)subndr->offset, (int)size_is);
640 subndr->offset = size_is;
643 switch (header_size) {
644 case 0:
645 break;
647 case 2:
648 NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, subndr->offset));
649 break;
651 case 4:
652 NDR_CHECK(ndr_push_uint3264(ndr, NDR_SCALARS, subndr->offset));
653 break;
655 case 0xFFFFFC01:
657 * Common Type Header for the Serialization Stream
658 * See [MS-RPCE] 2.2.6 Type Serialization Version 1
660 padding_len = NDR_ROUND(subndr->offset, 8) - subndr->offset;
661 if (padding_len > 0) {
662 NDR_CHECK(ndr_push_zero(subndr, padding_len));
665 /* version */
666 NDR_CHECK(ndr_push_uint8(ndr, NDR_SCALARS, 1));
669 * 0x10 little endian
670 * 0x00 big endian
672 NDR_CHECK(ndr_push_uint8(ndr, NDR_SCALARS, NDR_BE(ndr)?0x00:0x10));
674 /* length of the "Private Header for Constructed Type" */
675 NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, 8));
677 /* filler */
678 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0xCCCCCCCC));
681 * Private Header for Constructed Type
683 /* length - will be updated latter */
684 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, subndr->offset));
686 /* reserved */
687 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0));
688 break;
690 default:
691 return ndr_push_error(ndr, NDR_ERR_SUBCONTEXT, "Bad subcontext header size %d",
692 (int)header_size);
695 NDR_CHECK(ndr_push_bytes(ndr, subndr->data, subndr->offset));
696 return NDR_ERR_SUCCESS;
700 store a token in the ndr context, for later retrieval
702 _PUBLIC_ enum ndr_err_code ndr_token_store(TALLOC_CTX *mem_ctx,
703 struct ndr_token_list **list,
704 const void *key,
705 uint32_t value)
707 struct ndr_token_list *tok;
708 tok = talloc(mem_ctx, struct ndr_token_list);
709 NDR_ERR_HAVE_NO_MEMORY(tok);
710 tok->key = key;
711 tok->value = value;
712 DLIST_ADD((*list), tok);
713 return NDR_ERR_SUCCESS;
717 retrieve a token from a ndr context, using cmp_fn to match the tokens
719 _PUBLIC_ enum ndr_err_code ndr_token_retrieve_cmp_fn(struct ndr_token_list **list, const void *key, uint32_t *v,
720 comparison_fn_t _cmp_fn, bool _remove_tok)
722 struct ndr_token_list *tok;
723 for (tok=*list;tok;tok=tok->next) {
724 if (_cmp_fn && _cmp_fn(tok->key,key)==0) goto found;
725 else if (!_cmp_fn && tok->key == key) goto found;
727 return NDR_ERR_TOKEN;
728 found:
729 *v = tok->value;
730 if (_remove_tok) {
731 DLIST_REMOVE((*list), tok);
732 talloc_free(tok);
734 return NDR_ERR_SUCCESS;
738 retrieve a token from a ndr context
740 _PUBLIC_ enum ndr_err_code ndr_token_retrieve(struct ndr_token_list **list, const void *key, uint32_t *v)
742 return ndr_token_retrieve_cmp_fn(list, key, v, NULL, true);
746 peek at but don't removed a token from a ndr context
748 _PUBLIC_ uint32_t ndr_token_peek(struct ndr_token_list **list, const void *key)
750 enum ndr_err_code status;
751 uint32_t v;
753 status = ndr_token_retrieve_cmp_fn(list, key, &v, NULL, false);
754 if (!NDR_ERR_CODE_IS_SUCCESS(status)) {
755 return 0;
758 return v;
762 pull an array size field and add it to the array_size_list token list
764 _PUBLIC_ enum ndr_err_code ndr_pull_array_size(struct ndr_pull *ndr, const void *p)
766 uint32_t size;
767 NDR_CHECK(ndr_pull_uint3264(ndr, NDR_SCALARS, &size));
768 return ndr_token_store(ndr, &ndr->array_size_list, p, size);
772 get the stored array size field
774 _PUBLIC_ uint32_t ndr_get_array_size(struct ndr_pull *ndr, const void *p)
776 return ndr_token_peek(&ndr->array_size_list, p);
780 check the stored array size field
782 _PUBLIC_ enum ndr_err_code ndr_check_array_size(struct ndr_pull *ndr, void *p, uint32_t size)
784 uint32_t stored;
785 stored = ndr_token_peek(&ndr->array_size_list, p);
786 if (stored != size) {
787 return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE,
788 "Bad array size - got %u expected %u\n",
789 stored, size);
791 return NDR_ERR_SUCCESS;
795 pull an array length field and add it to the array_length_list token list
797 _PUBLIC_ enum ndr_err_code ndr_pull_array_length(struct ndr_pull *ndr, const void *p)
799 uint32_t length, offset;
800 NDR_CHECK(ndr_pull_uint3264(ndr, NDR_SCALARS, &offset));
801 if (offset != 0) {
802 return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE,
803 "non-zero array offset %u\n", offset);
805 NDR_CHECK(ndr_pull_uint3264(ndr, NDR_SCALARS, &length));
806 return ndr_token_store(ndr, &ndr->array_length_list, p, length);
810 get the stored array length field
812 _PUBLIC_ uint32_t ndr_get_array_length(struct ndr_pull *ndr, const void *p)
814 return ndr_token_peek(&ndr->array_length_list, p);
818 check the stored array length field
820 _PUBLIC_ enum ndr_err_code ndr_check_array_length(struct ndr_pull *ndr, void *p, uint32_t length)
822 uint32_t stored;
823 stored = ndr_token_peek(&ndr->array_length_list, p);
824 if (stored != length) {
825 return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE,
826 "Bad array length - got %u expected %u\n",
827 stored, length);
829 return NDR_ERR_SUCCESS;
832 _PUBLIC_ enum ndr_err_code ndr_push_pipe_chunk_trailer(struct ndr_push *ndr, int ndr_flags, uint32_t count)
834 if (ndr->flags & LIBNDR_FLAG_NDR64) {
835 int64_t tmp = 0 - (int64_t)count;
836 uint64_t ncount = tmp;
838 NDR_CHECK(ndr_push_hyper(ndr, ndr_flags, ncount));
841 return NDR_ERR_SUCCESS;
844 _PUBLIC_ enum ndr_err_code ndr_check_pipe_chunk_trailer(struct ndr_pull *ndr, int ndr_flags, uint32_t count)
846 if (ndr->flags & LIBNDR_FLAG_NDR64) {
847 int64_t tmp = 0 - (int64_t)count;
848 uint64_t ncount1 = tmp;
849 uint64_t ncount2;
851 NDR_CHECK(ndr_pull_hyper(ndr, ndr_flags, &ncount2));
852 if (ncount1 == ncount2) {
853 return NDR_ERR_SUCCESS;
856 return ndr_pull_error(ndr, NDR_ERR_ARRAY_SIZE,
857 "Bad pipe trailer[%lld should be %lld] size was %lu\"",
858 (unsigned long long)ncount2,
859 (unsigned long long)ncount1,
860 (unsigned long)count);
863 return NDR_ERR_SUCCESS;
867 store a switch value
869 _PUBLIC_ enum ndr_err_code ndr_push_set_switch_value(struct ndr_push *ndr, const void *p, uint32_t val)
871 return ndr_token_store(ndr, &ndr->switch_list, p, val);
874 _PUBLIC_ enum ndr_err_code ndr_pull_set_switch_value(struct ndr_pull *ndr, const void *p, uint32_t val)
876 return ndr_token_store(ndr, &ndr->switch_list, p, val);
879 _PUBLIC_ enum ndr_err_code ndr_print_set_switch_value(struct ndr_print *ndr, const void *p, uint32_t val)
881 return ndr_token_store(ndr, &ndr->switch_list, p, val);
885 retrieve a switch value
887 _PUBLIC_ uint32_t ndr_push_get_switch_value(struct ndr_push *ndr, const void *p)
889 return ndr_token_peek(&ndr->switch_list, p);
892 _PUBLIC_ uint32_t ndr_pull_get_switch_value(struct ndr_pull *ndr, const void *p)
894 return ndr_token_peek(&ndr->switch_list, p);
897 _PUBLIC_ uint32_t ndr_print_get_switch_value(struct ndr_print *ndr, const void *p)
899 return ndr_token_peek(&ndr->switch_list, p);
903 pull a struct from a blob using NDR
905 _PUBLIC_ enum ndr_err_code ndr_pull_struct_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
906 ndr_pull_flags_fn_t fn)
908 struct ndr_pull *ndr;
909 ndr = ndr_pull_init_blob(blob, mem_ctx);
910 NDR_ERR_HAVE_NO_MEMORY(ndr);
911 NDR_CHECK_FREE(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p));
912 talloc_free(ndr);
913 return NDR_ERR_SUCCESS;
917 pull a struct from a blob using NDR - failing if all bytes are not consumed
919 _PUBLIC_ enum ndr_err_code ndr_pull_struct_blob_all(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx,
920 void *p, ndr_pull_flags_fn_t fn)
922 struct ndr_pull *ndr;
923 uint32_t highest_ofs;
924 ndr = ndr_pull_init_blob(blob, mem_ctx);
925 NDR_ERR_HAVE_NO_MEMORY(ndr);
926 NDR_CHECK_FREE(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p));
927 if (ndr->offset > ndr->relative_highest_offset) {
928 highest_ofs = ndr->offset;
929 } else {
930 highest_ofs = ndr->relative_highest_offset;
932 if (highest_ofs < ndr->data_size) {
933 enum ndr_err_code ret;
934 ret = ndr_pull_error(ndr, NDR_ERR_UNREAD_BYTES,
935 "not all bytes consumed ofs[%u] size[%u]",
936 highest_ofs, ndr->data_size);
937 talloc_free(ndr);
938 return ret;
940 talloc_free(ndr);
941 return NDR_ERR_SUCCESS;
945 pull a union from a blob using NDR, given the union discriminator
947 _PUBLIC_ enum ndr_err_code ndr_pull_union_blob(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx,
948 void *p,
949 uint32_t level, ndr_pull_flags_fn_t fn)
951 struct ndr_pull *ndr;
952 ndr = ndr_pull_init_blob(blob, mem_ctx);
953 NDR_ERR_HAVE_NO_MEMORY(ndr);
954 NDR_CHECK_FREE(ndr_pull_set_switch_value(ndr, p, level));
955 NDR_CHECK_FREE(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p));
956 talloc_free(ndr);
957 return NDR_ERR_SUCCESS;
961 pull a union from a blob using NDR, given the union discriminator,
962 failing if all bytes are not consumed
964 _PUBLIC_ enum ndr_err_code ndr_pull_union_blob_all(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx,
965 void *p,
966 uint32_t level, ndr_pull_flags_fn_t fn)
968 struct ndr_pull *ndr;
969 uint32_t highest_ofs;
970 ndr = ndr_pull_init_blob(blob, mem_ctx);
971 NDR_ERR_HAVE_NO_MEMORY(ndr);
972 NDR_CHECK_FREE(ndr_pull_set_switch_value(ndr, p, level));
973 NDR_CHECK_FREE(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p));
974 if (ndr->offset > ndr->relative_highest_offset) {
975 highest_ofs = ndr->offset;
976 } else {
977 highest_ofs = ndr->relative_highest_offset;
979 if (highest_ofs < ndr->data_size) {
980 enum ndr_err_code ret;
981 ret = ndr_pull_error(ndr, NDR_ERR_UNREAD_BYTES,
982 "not all bytes consumed ofs[%u] size[%u]",
983 highest_ofs, ndr->data_size);
984 talloc_free(ndr);
985 return ret;
987 talloc_free(ndr);
988 return NDR_ERR_SUCCESS;
992 push a struct to a blob using NDR
994 _PUBLIC_ enum ndr_err_code ndr_push_struct_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, const void *p, ndr_push_flags_fn_t fn)
996 struct ndr_push *ndr;
997 ndr = ndr_push_init_ctx(mem_ctx);
998 NDR_ERR_HAVE_NO_MEMORY(ndr);
1000 NDR_CHECK(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p));
1002 *blob = ndr_push_blob(ndr);
1003 talloc_steal(mem_ctx, blob->data);
1004 talloc_free(ndr);
1006 return NDR_ERR_SUCCESS;
1010 push a union to a blob using NDR
1012 _PUBLIC_ enum ndr_err_code ndr_push_union_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
1013 uint32_t level, ndr_push_flags_fn_t fn)
1015 struct ndr_push *ndr;
1016 ndr = ndr_push_init_ctx(mem_ctx);
1017 NDR_ERR_HAVE_NO_MEMORY(ndr);
1019 NDR_CHECK(ndr_push_set_switch_value(ndr, p, level));
1020 NDR_CHECK(fn(ndr, NDR_SCALARS|NDR_BUFFERS, p));
1022 *blob = ndr_push_blob(ndr);
1023 talloc_steal(mem_ctx, blob->data);
1024 talloc_free(ndr);
1026 return NDR_ERR_SUCCESS;
1030 generic ndr_size_*() handler for structures
1032 _PUBLIC_ size_t ndr_size_struct(const void *p, int flags, ndr_push_flags_fn_t push)
1034 struct ndr_push *ndr;
1035 enum ndr_err_code status;
1036 size_t ret;
1038 /* avoid recursion */
1039 if (flags & LIBNDR_FLAG_NO_NDR_SIZE) return 0;
1041 ndr = ndr_push_init_ctx(NULL);
1042 if (!ndr) return 0;
1043 ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE;
1044 status = push(ndr, NDR_SCALARS|NDR_BUFFERS, discard_const(p));
1045 if (!NDR_ERR_CODE_IS_SUCCESS(status)) {
1046 talloc_free(ndr);
1047 return 0;
1049 ret = ndr->offset;
1050 talloc_free(ndr);
1051 return ret;
1055 generic ndr_size_*() handler for unions
1057 _PUBLIC_ size_t ndr_size_union(const void *p, int flags, uint32_t level, ndr_push_flags_fn_t push)
1059 struct ndr_push *ndr;
1060 enum ndr_err_code status;
1061 size_t ret;
1063 /* avoid recursion */
1064 if (flags & LIBNDR_FLAG_NO_NDR_SIZE) return 0;
1066 ndr = ndr_push_init_ctx(NULL);
1067 if (!ndr) return 0;
1068 ndr->flags |= flags | LIBNDR_FLAG_NO_NDR_SIZE;
1070 status = ndr_push_set_switch_value(ndr, p, level);
1071 if (!NDR_ERR_CODE_IS_SUCCESS(status)) {
1072 talloc_free(ndr);
1073 return 0;
1075 status = push(ndr, NDR_SCALARS|NDR_BUFFERS, p);
1076 if (!NDR_ERR_CODE_IS_SUCCESS(status)) {
1077 talloc_free(ndr);
1078 return 0;
1080 ret = ndr->offset;
1081 talloc_free(ndr);
1082 return ret;
1086 get the current base for relative pointers for the push
1088 _PUBLIC_ uint32_t ndr_push_get_relative_base_offset(struct ndr_push *ndr)
1090 return ndr->relative_base_offset;
1094 restore the old base for relative pointers for the push
1096 _PUBLIC_ void ndr_push_restore_relative_base_offset(struct ndr_push *ndr, uint32_t offset)
1098 ndr->relative_base_offset = offset;
1102 setup the current base for relative pointers for the push
1103 called in the NDR_SCALAR stage
1105 _PUBLIC_ enum ndr_err_code ndr_push_setup_relative_base_offset1(struct ndr_push *ndr, const void *p, uint32_t offset)
1107 ndr->relative_base_offset = offset;
1108 return ndr_token_store(ndr, &ndr->relative_base_list, p, offset);
1112 setup the current base for relative pointers for the push
1113 called in the NDR_BUFFERS stage
1115 _PUBLIC_ enum ndr_err_code ndr_push_setup_relative_base_offset2(struct ndr_push *ndr, const void *p)
1117 return ndr_token_retrieve(&ndr->relative_base_list, p, &ndr->relative_base_offset);
1121 push a relative object - stage1
1122 this is called during SCALARS processing
1124 _PUBLIC_ enum ndr_err_code ndr_push_relative_ptr1(struct ndr_push *ndr, const void *p)
1126 if (p == NULL) {
1127 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, 0));
1128 return NDR_ERR_SUCCESS;
1130 NDR_CHECK(ndr_push_align(ndr, 4));
1131 NDR_CHECK(ndr_token_store(ndr, &ndr->relative_list, p, ndr->offset));
1132 return ndr_push_uint32(ndr, NDR_SCALARS, 0xFFFFFFFF);
1136 push a short relative object - stage1
1137 this is called during SCALARS processing
1139 _PUBLIC_ enum ndr_err_code ndr_push_short_relative_ptr1(struct ndr_push *ndr, const void *p)
1141 if (p == NULL) {
1142 NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, 0));
1143 return NDR_ERR_SUCCESS;
1145 NDR_CHECK(ndr_push_align(ndr, 2));
1146 NDR_CHECK(ndr_token_store(ndr, &ndr->relative_list, p, ndr->offset));
1147 return ndr_push_uint16(ndr, NDR_SCALARS, 0xFFFF);
1150 push a relative object - stage2
1151 this is called during buffers processing
1153 static enum ndr_err_code ndr_push_relative_ptr2(struct ndr_push *ndr, const void *p)
1155 uint32_t save_offset;
1156 uint32_t ptr_offset = 0xFFFFFFFF;
1157 if (p == NULL) {
1158 return NDR_ERR_SUCCESS;
1160 save_offset = ndr->offset;
1161 NDR_CHECK(ndr_token_retrieve(&ndr->relative_list, p, &ptr_offset));
1162 if (ptr_offset > ndr->offset) {
1163 return ndr_push_error(ndr, NDR_ERR_BUFSIZE,
1164 "ndr_push_relative_ptr2 ptr_offset(%u) > ndr->offset(%u)",
1165 ptr_offset, ndr->offset);
1167 ndr->offset = ptr_offset;
1168 if (save_offset < ndr->relative_base_offset) {
1169 return ndr_push_error(ndr, NDR_ERR_BUFSIZE,
1170 "ndr_push_relative_ptr2 save_offset(%u) < ndr->relative_base_offset(%u)",
1171 save_offset, ndr->relative_base_offset);
1173 NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, save_offset - ndr->relative_base_offset));
1174 ndr->offset = save_offset;
1175 return NDR_ERR_SUCCESS;
1178 push a short relative object - stage2
1179 this is called during buffers processing
1181 _PUBLIC_ enum ndr_err_code ndr_push_short_relative_ptr2(struct ndr_push *ndr, const void *p)
1183 uint32_t save_offset;
1184 uint32_t ptr_offset = 0xFFFF;
1185 if (p == NULL) {
1186 return NDR_ERR_SUCCESS;
1188 save_offset = ndr->offset;
1189 NDR_CHECK(ndr_token_retrieve(&ndr->relative_list, p, &ptr_offset));
1190 if (ptr_offset > ndr->offset) {
1191 return ndr_push_error(ndr, NDR_ERR_BUFSIZE,
1192 "ndr_push_short_relative_ptr2 ptr_offset(%u) > ndr->offset(%u)",
1193 ptr_offset, ndr->offset);
1195 ndr->offset = ptr_offset;
1196 if (save_offset < ndr->relative_base_offset) {
1197 return ndr_push_error(ndr, NDR_ERR_BUFSIZE,
1198 "ndr_push_relative_ptr2 save_offset(%u) < ndr->relative_base_offset(%u)",
1199 save_offset, ndr->relative_base_offset);
1201 NDR_CHECK(ndr_push_uint16(ndr, NDR_SCALARS, save_offset - ndr->relative_base_offset));
1202 ndr->offset = save_offset;
1203 return NDR_ERR_SUCCESS;
1207 push a relative object - stage2 start
1208 this is called during buffers processing
1210 _PUBLIC_ enum ndr_err_code ndr_push_relative_ptr2_start(struct ndr_push *ndr, const void *p)
1212 if (p == NULL) {
1213 return NDR_ERR_SUCCESS;
1215 if (!(ndr->flags & LIBNDR_FLAG_RELATIVE_REVERSE)) {
1216 uint32_t relative_offset;
1217 size_t pad;
1218 size_t align = 1;
1220 if (ndr->offset < ndr->relative_base_offset) {
1221 return ndr_push_error(ndr, NDR_ERR_BUFSIZE,
1222 "ndr_push_relative_ptr2_start ndr->offset(%u) < ndr->relative_base_offset(%u)",
1223 ndr->offset, ndr->relative_base_offset);
1226 relative_offset = ndr->offset - ndr->relative_base_offset;
1228 if (ndr->flags & LIBNDR_FLAG_NOALIGN) {
1229 align = 1;
1230 } else if (ndr->flags & LIBNDR_FLAG_ALIGN2) {
1231 align = 2;
1232 } else if (ndr->flags & LIBNDR_FLAG_ALIGN4) {
1233 align = 4;
1234 } else if (ndr->flags & LIBNDR_FLAG_ALIGN8) {
1235 align = 8;
1238 pad = ndr_align_size(relative_offset, align);
1239 if (pad) {
1240 NDR_CHECK(ndr_push_zero(ndr, pad));
1243 return ndr_push_relative_ptr2(ndr, p);
1245 if (ndr->relative_end_offset == -1) {
1246 return ndr_push_error(ndr, NDR_ERR_RELATIVE,
1247 "ndr_push_relative_ptr2_start RELATIVE_REVERSE flag set and relative_end_offset %d",
1248 ndr->relative_end_offset);
1250 NDR_CHECK(ndr_token_store(ndr, &ndr->relative_begin_list, p, ndr->offset));
1251 return NDR_ERR_SUCCESS;
1255 push a relative object - stage2 end
1256 this is called during buffers processing
1258 _PUBLIC_ enum ndr_err_code ndr_push_relative_ptr2_end(struct ndr_push *ndr, const void *p)
1260 uint32_t begin_offset = 0xFFFFFFFF;
1261 ssize_t len;
1262 uint32_t correct_offset = 0;
1263 uint32_t align = 1;
1264 uint32_t pad = 0;
1266 if (p == NULL) {
1267 return NDR_ERR_SUCCESS;
1270 if (!(ndr->flags & LIBNDR_FLAG_RELATIVE_REVERSE)) {
1271 return NDR_ERR_SUCCESS;
1274 if (ndr->flags & LIBNDR_FLAG_NO_NDR_SIZE) {
1275 /* better say more than calculation a too small buffer */
1276 NDR_PUSH_ALIGN(ndr, 8);
1277 return NDR_ERR_SUCCESS;
1280 if (ndr->relative_end_offset < ndr->offset) {
1281 return ndr_push_error(ndr, NDR_ERR_RELATIVE,
1282 "ndr_push_relative_ptr2_end:"
1283 "relative_end_offset %u < offset %u",
1284 ndr->relative_end_offset, ndr->offset);
1287 NDR_CHECK(ndr_token_retrieve(&ndr->relative_begin_list, p, &begin_offset));
1289 /* we have marshalled a buffer, see how long it was */
1290 len = ndr->offset - begin_offset;
1292 if (len < 0) {
1293 return ndr_push_error(ndr, NDR_ERR_RELATIVE,
1294 "ndr_push_relative_ptr2_end:"
1295 "offset %u - begin_offset %u < 0",
1296 ndr->offset, begin_offset);
1299 if (ndr->relative_end_offset < len) {
1300 return ndr_push_error(ndr, NDR_ERR_RELATIVE,
1301 "ndr_push_relative_ptr2_end:"
1302 "relative_end_offset %u < len %lld",
1303 ndr->offset, (long long)len);
1306 /* the reversed offset is at the end of the main buffer */
1307 correct_offset = ndr->relative_end_offset - len;
1309 if (ndr->flags & LIBNDR_FLAG_NOALIGN) {
1310 align = 1;
1311 } else if (ndr->flags & LIBNDR_FLAG_ALIGN2) {
1312 align = 2;
1313 } else if (ndr->flags & LIBNDR_FLAG_ALIGN4) {
1314 align = 4;
1315 } else if (ndr->flags & LIBNDR_FLAG_ALIGN8) {
1316 align = 8;
1319 pad = ndr_align_size(correct_offset, align);
1320 if (pad) {
1321 correct_offset += pad;
1322 correct_offset -= align;
1325 if (correct_offset < begin_offset) {
1326 return ndr_push_error(ndr, NDR_ERR_RELATIVE,
1327 "ndr_push_relative_ptr2_end: "
1328 "correct_offset %u < begin_offset %u",
1329 correct_offset, begin_offset);
1332 if (len > 0) {
1333 uint32_t clear_size = correct_offset - begin_offset;
1335 clear_size = MIN(clear_size, len);
1337 /* now move the marshalled buffer to the end of the main buffer */
1338 memmove(ndr->data + correct_offset, ndr->data + begin_offset, len);
1340 if (clear_size) {
1341 /* and wipe out old buffer within the main buffer */
1342 memset(ndr->data + begin_offset, '\0', clear_size);
1346 /* and set the end offset for the next buffer */
1347 ndr->relative_end_offset = correct_offset;
1349 /* finally write the offset to the main buffer */
1350 ndr->offset = correct_offset;
1351 NDR_CHECK(ndr_push_relative_ptr2(ndr, p));
1353 /* restore to where we were in the main buffer */
1354 ndr->offset = begin_offset;
1356 return NDR_ERR_SUCCESS;
1360 get the current base for relative pointers for the pull
1362 _PUBLIC_ uint32_t ndr_pull_get_relative_base_offset(struct ndr_pull *ndr)
1364 return ndr->relative_base_offset;
1368 restore the old base for relative pointers for the pull
1370 _PUBLIC_ void ndr_pull_restore_relative_base_offset(struct ndr_pull *ndr, uint32_t offset)
1372 ndr->relative_base_offset = offset;
1376 setup the current base for relative pointers for the pull
1377 called in the NDR_SCALAR stage
1379 _PUBLIC_ enum ndr_err_code ndr_pull_setup_relative_base_offset1(struct ndr_pull *ndr, const void *p, uint32_t offset)
1381 ndr->relative_base_offset = offset;
1382 return ndr_token_store(ndr, &ndr->relative_base_list, p, offset);
1386 setup the current base for relative pointers for the pull
1387 called in the NDR_BUFFERS stage
1389 _PUBLIC_ enum ndr_err_code ndr_pull_setup_relative_base_offset2(struct ndr_pull *ndr, const void *p)
1391 return ndr_token_retrieve(&ndr->relative_base_list, p, &ndr->relative_base_offset);
1395 pull a relative object - stage1
1396 called during SCALARS processing
1398 _PUBLIC_ enum ndr_err_code ndr_pull_relative_ptr1(struct ndr_pull *ndr, const void *p, uint32_t rel_offset)
1400 rel_offset += ndr->relative_base_offset;
1401 if (rel_offset > ndr->data_size) {
1402 return ndr_pull_error(ndr, NDR_ERR_BUFSIZE,
1403 "ndr_pull_relative_ptr1 rel_offset(%u) > ndr->data_size(%u)",
1404 rel_offset, ndr->data_size);
1406 return ndr_token_store(ndr, &ndr->relative_list, p, rel_offset);
1410 pull a relative object - stage2
1411 called during BUFFERS processing
1413 _PUBLIC_ enum ndr_err_code ndr_pull_relative_ptr2(struct ndr_pull *ndr, const void *p)
1415 uint32_t rel_offset;
1416 NDR_CHECK(ndr_token_retrieve(&ndr->relative_list, p, &rel_offset));
1417 return ndr_pull_set_offset(ndr, rel_offset);
1420 const static struct {
1421 enum ndr_err_code err;
1422 const char *string;
1423 } ndr_err_code_strings[] = {
1424 { NDR_ERR_SUCCESS, "Success" },
1425 { NDR_ERR_ARRAY_SIZE, "Bad Array Size" },
1426 { NDR_ERR_BAD_SWITCH, "Bad Switch" },
1427 { NDR_ERR_OFFSET, "Offset Error" },
1428 { NDR_ERR_RELATIVE, "Relative Pointer Error" },
1429 { NDR_ERR_CHARCNV, "Character Conversion Error" },
1430 { NDR_ERR_LENGTH, "Length Error" },
1431 { NDR_ERR_SUBCONTEXT, "Subcontext Error" },
1432 { NDR_ERR_COMPRESSION, "Compression Error" },
1433 { NDR_ERR_STRING, "String Error" },
1434 { NDR_ERR_VALIDATE, "Validate Error" },
1435 { NDR_ERR_BUFSIZE, "Buffer Size Error" },
1436 { NDR_ERR_ALLOC, "Allocation Error" },
1437 { NDR_ERR_RANGE, "Range Error" },
1438 { NDR_ERR_TOKEN, "Token Error" },
1439 { NDR_ERR_IPV4ADDRESS, "IPv4 Address Error" },
1440 { NDR_ERR_INVALID_POINTER, "Invalid Pointer" },
1441 { NDR_ERR_UNREAD_BYTES, "Unread Bytes" },
1442 { NDR_ERR_NDR64, "NDR64 assertion error" },
1443 { 0, NULL }
1446 _PUBLIC_ const char *ndr_map_error2string(enum ndr_err_code ndr_err)
1448 int i;
1449 for (i = 0; ndr_err_code_strings[i].string != NULL; i++) {
1450 if (ndr_err_code_strings[i].err == ndr_err)
1451 return ndr_err_code_strings[i].string;
1453 return "Unknown error";