2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 2003
7 Copyright (C) Jelmer Vernooij 2005-2008
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
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"
34 #define NDR_BASE_MARSHALL_SIZE 1024
36 /* this guid indicates NDR encoding in a protocol tower */
37 const struct ndr_syntax_id ndr_transfer_syntax_ndr
= {
38 { 0x8a885d04, 0x1ceb, 0x11c9, {0x9f, 0xe8}, {0x08,0x00,0x2b,0x10,0x48,0x60} },
42 const struct ndr_syntax_id ndr_transfer_syntax_ndr64
= {
43 { 0x71710533, 0xbeba, 0x4937, {0x83, 0x19}, {0xb5,0xdb,0xef,0x9c,0xcc,0x36} },
47 const struct ndr_syntax_id ndr_syntax_id_null
= {
48 { 0, 0, 0, { 0, 0 }, { 0, 0, 0, 0, 0, 0 } },
53 work out the number of bytes needed to align on a n byte boundary
55 _PUBLIC_
size_t ndr_align_size(uint32_t offset
, size_t n
)
57 if ((offset
& (n
-1)) == 0) return 0;
58 return n
- (offset
& (n
-1));
62 initialise a ndr parse structure from a data blob
64 _PUBLIC_
struct ndr_pull
*ndr_pull_init_blob(const DATA_BLOB
*blob
, TALLOC_CTX
*mem_ctx
)
68 ndr
= talloc_zero(mem_ctx
, struct ndr_pull
);
69 if (!ndr
) return NULL
;
70 ndr
->current_mem_ctx
= mem_ctx
;
72 ndr
->data
= blob
->data
;
73 ndr
->data_size
= blob
->length
;
79 advance by 'size' bytes
81 _PUBLIC_
enum ndr_err_code
ndr_pull_advance(struct ndr_pull
*ndr
, uint32_t size
)
84 if (ndr
->offset
> ndr
->data_size
) {
85 return ndr_pull_error(ndr
, NDR_ERR_BUFSIZE
,
86 "ndr_pull_advance by %u failed",
89 return NDR_ERR_SUCCESS
;
93 set the parse offset to 'ofs'
95 static enum ndr_err_code
ndr_pull_set_offset(struct ndr_pull
*ndr
, uint32_t ofs
)
98 if (ndr
->offset
> ndr
->data_size
) {
99 return ndr_pull_error(ndr
, NDR_ERR_BUFSIZE
,
100 "ndr_pull_set_offset %u failed",
103 return NDR_ERR_SUCCESS
;
106 /* create a ndr_push structure, ready for some marshalling */
107 _PUBLIC_
struct ndr_push
*ndr_push_init_ctx(TALLOC_CTX
*mem_ctx
)
109 struct ndr_push
*ndr
;
111 ndr
= talloc_zero(mem_ctx
, struct ndr_push
);
117 ndr
->alloc_size
= NDR_BASE_MARSHALL_SIZE
;
118 ndr
->data
= talloc_array(ndr
, uint8_t, ndr
->alloc_size
);
126 /* return a DATA_BLOB structure for the current ndr_push marshalled data */
127 _PUBLIC_ DATA_BLOB
ndr_push_blob(struct ndr_push
*ndr
)
130 blob
= data_blob_const(ndr
->data
, ndr
->offset
);
131 if (ndr
->alloc_size
> ndr
->offset
) {
132 ndr
->data
[ndr
->offset
] = 0;
139 expand the available space in the buffer to ndr->offset + extra_size
141 _PUBLIC_
enum ndr_err_code
ndr_push_expand(struct ndr_push
*ndr
, uint32_t extra_size
)
143 uint32_t size
= extra_size
+ ndr
->offset
;
145 if (size
< ndr
->offset
) {
146 /* extra_size overflowed the offset */
147 return ndr_push_error(ndr
, NDR_ERR_BUFSIZE
, "Overflow in push_expand to %u",
151 if (ndr
->alloc_size
> size
) {
152 return NDR_ERR_SUCCESS
;
155 ndr
->alloc_size
+= NDR_BASE_MARSHALL_SIZE
;
156 if (size
+1 > ndr
->alloc_size
) {
157 ndr
->alloc_size
= size
+1;
159 ndr
->data
= talloc_realloc(ndr
, ndr
->data
, uint8_t, ndr
->alloc_size
);
161 return ndr_push_error(ndr
, NDR_ERR_ALLOC
, "Failed to push_expand to %u",
165 return NDR_ERR_SUCCESS
;
168 _PUBLIC_
void ndr_print_debugc_helper(struct ndr_print
*ndr
, const char *format
, ...)
176 va_start(ap
, format
);
177 ret
= vasprintf(&s
, format
, ap
);
184 dbgc_class
= *(int *)ndr
->private_data
;
186 if (ndr
->no_newline
) {
187 DEBUGADDC(dbgc_class
, 1,("%s", s
));
192 for (i
=0;i
<ndr
->depth
;i
++) {
193 DEBUGADDC(dbgc_class
, 1,(" "));
196 DEBUGADDC(dbgc_class
, 1,("%s\n", s
));
200 _PUBLIC_
void ndr_print_debug_helper(struct ndr_print
*ndr
, const char *format
, ...)
207 va_start(ap
, format
);
208 ret
= vasprintf(&s
, format
, ap
);
215 if (ndr
->no_newline
) {
216 DEBUGADD(1,("%s", s
));
221 for (i
=0;i
<ndr
->depth
;i
++) {
225 DEBUGADD(1,("%s\n", s
));
229 _PUBLIC_
void ndr_print_printf_helper(struct ndr_print
*ndr
, const char *format
, ...)
234 if (!ndr
->no_newline
) {
235 for (i
=0;i
<ndr
->depth
;i
++) {
240 va_start(ap
, format
);
243 if (!ndr
->no_newline
) {
248 _PUBLIC_
void ndr_print_string_helper(struct ndr_print
*ndr
, const char *format
, ...)
253 if (!ndr
->no_newline
) {
254 for (i
=0;i
<ndr
->depth
;i
++) {
255 ndr
->private_data
= talloc_asprintf_append_buffer(
256 (char *)ndr
->private_data
, " ");
260 va_start(ap
, format
);
261 ndr
->private_data
= talloc_vasprintf_append_buffer((char *)ndr
->private_data
,
264 if (!ndr
->no_newline
) {
265 ndr
->private_data
= talloc_asprintf_append_buffer((char *)ndr
->private_data
,
271 a useful helper function for printing idl structures via DEBUGC()
273 _PUBLIC_
void ndr_print_debugc(int dbgc_class
, ndr_print_fn_t fn
, const char *name
, void *ptr
)
275 struct ndr_print
*ndr
;
277 DEBUGC(dbgc_class
, 1,(" "));
279 ndr
= talloc_zero(NULL
, struct ndr_print
);
281 ndr
->private_data
= &dbgc_class
;
282 ndr
->print
= ndr_print_debugc_helper
;
290 a useful helper function for printing idl structures via DEBUG()
292 _PUBLIC_
void ndr_print_debug(ndr_print_fn_t fn
, const char *name
, void *ptr
)
294 struct ndr_print
*ndr
;
298 ndr
= talloc_zero(NULL
, struct ndr_print
);
300 ndr
->print
= ndr_print_debug_helper
;
308 a useful helper function for printing idl unions via DEBUG()
310 _PUBLIC_
void ndr_print_union_debug(ndr_print_fn_t fn
, const char *name
, uint32_t level
, void *ptr
)
312 struct ndr_print
*ndr
;
316 ndr
= talloc_zero(NULL
, struct ndr_print
);
318 ndr
->print
= ndr_print_debug_helper
;
321 ndr_print_set_switch_value(ndr
, ptr
, level
);
327 a useful helper function for printing idl function calls via DEBUG()
329 _PUBLIC_
void ndr_print_function_debug(ndr_print_function_t fn
, const char *name
, int flags
, void *ptr
)
331 struct ndr_print
*ndr
;
335 ndr
= talloc_zero(NULL
, struct ndr_print
);
337 ndr
->print
= ndr_print_debug_helper
;
341 fn(ndr
, name
, flags
, ptr
);
346 a useful helper function for printing idl structures to a string
348 _PUBLIC_
char *ndr_print_struct_string(TALLOC_CTX
*mem_ctx
, ndr_print_fn_t fn
, const char *name
, void *ptr
)
350 struct ndr_print
*ndr
;
353 ndr
= talloc_zero(mem_ctx
, struct ndr_print
);
354 if (!ndr
) return NULL
;
355 ndr
->private_data
= talloc_strdup(ndr
, "");
356 if (!ndr
->private_data
) {
359 ndr
->print
= ndr_print_string_helper
;
364 ret
= talloc_steal(mem_ctx
, (char *)ndr
->private_data
);
371 a useful helper function for printing idl unions to a string
373 _PUBLIC_
char *ndr_print_union_string(TALLOC_CTX
*mem_ctx
, ndr_print_fn_t fn
, const char *name
, uint32_t level
, void *ptr
)
375 struct ndr_print
*ndr
;
378 ndr
= talloc_zero(mem_ctx
, struct ndr_print
);
379 if (!ndr
) return NULL
;
380 ndr
->private_data
= talloc_strdup(ndr
, "");
381 if (!ndr
->private_data
) {
384 ndr
->print
= ndr_print_string_helper
;
387 ndr_print_set_switch_value(ndr
, ptr
, level
);
389 ret
= talloc_steal(mem_ctx
, (char *)ndr
->private_data
);
396 a useful helper function for printing idl function calls to a string
398 _PUBLIC_
char *ndr_print_function_string(TALLOC_CTX
*mem_ctx
,
399 ndr_print_function_t fn
, const char *name
,
400 int flags
, void *ptr
)
402 struct ndr_print
*ndr
;
405 ndr
= talloc_zero(mem_ctx
, struct ndr_print
);
406 if (!ndr
) return NULL
;
407 ndr
->private_data
= talloc_strdup(ndr
, "");
408 if (!ndr
->private_data
) {
411 ndr
->print
= ndr_print_string_helper
;
414 fn(ndr
, name
, flags
, ptr
);
415 ret
= talloc_steal(mem_ctx
, (char *)ndr
->private_data
);
421 _PUBLIC_
void ndr_set_flags(uint32_t *pflags
, uint32_t new_flags
)
423 /* the big/little endian flags are inter-dependent */
424 if (new_flags
& LIBNDR_FLAG_LITTLE_ENDIAN
) {
425 (*pflags
) &= ~LIBNDR_FLAG_BIGENDIAN
;
426 (*pflags
) &= ~LIBNDR_FLAG_NDR64
;
428 if (new_flags
& LIBNDR_FLAG_BIGENDIAN
) {
429 (*pflags
) &= ~LIBNDR_FLAG_LITTLE_ENDIAN
;
430 (*pflags
) &= ~LIBNDR_FLAG_NDR64
;
432 if (new_flags
& LIBNDR_ALIGN_FLAGS
) {
433 /* Ensure we only have the passed-in
434 align flag set in the new_flags,
435 remove any old align flag. */
436 (*pflags
) &= ~LIBNDR_ALIGN_FLAGS
;
438 if (new_flags
& LIBNDR_FLAG_NO_RELATIVE_REVERSE
) {
439 (*pflags
) &= ~LIBNDR_FLAG_RELATIVE_REVERSE
;
441 (*pflags
) |= new_flags
;
445 return and possibly log an NDR error
447 _PUBLIC_
enum ndr_err_code
ndr_pull_error(struct ndr_pull
*ndr
,
448 enum ndr_err_code ndr_err
,
449 const char *format
, ...)
455 va_start(ap
, format
);
456 ret
= vasprintf(&s
, format
, ap
);
460 return NDR_ERR_ALLOC
;
463 DEBUG(1,("ndr_pull_error(%u): %s\n", ndr_err
, s
));
471 return and possibly log an NDR error
473 _PUBLIC_
enum ndr_err_code
ndr_push_error(struct ndr_push
*ndr
,
474 enum ndr_err_code ndr_err
,
475 const char *format
, ...)
481 va_start(ap
, format
);
482 ret
= vasprintf(&s
, format
, ap
);
486 return NDR_ERR_ALLOC
;
489 DEBUG(1,("ndr_push_error(%u): %s\n", ndr_err
, s
));
497 handle subcontext buffers, which in midl land are user-marshalled, but
498 we use magic in pidl to make them easier to cope with
500 _PUBLIC_
enum ndr_err_code
ndr_pull_subcontext_start(struct ndr_pull
*ndr
,
501 struct ndr_pull
**_subndr
,
505 struct ndr_pull
*subndr
;
506 uint32_t r_content_size
;
507 bool force_le
= false;
508 bool force_be
= false;
510 switch (header_size
) {
512 uint32_t content_size
= ndr
->data_size
- ndr
->offset
;
514 content_size
= size_is
;
516 r_content_size
= content_size
;
521 uint16_t content_size
;
522 NDR_CHECK(ndr_pull_uint16(ndr
, NDR_SCALARS
, &content_size
));
523 if (size_is
>= 0 && size_is
!= content_size
) {
524 return ndr_pull_error(ndr
, NDR_ERR_SUBCONTEXT
, "Bad subcontext (PULL) size_is(%d) mismatch content_size %d",
525 (int)size_is
, (int)content_size
);
527 r_content_size
= content_size
;
532 uint32_t content_size
;
533 NDR_CHECK(ndr_pull_uint3264(ndr
, NDR_SCALARS
, &content_size
));
534 if (size_is
>= 0 && size_is
!= content_size
) {
535 return ndr_pull_error(ndr
, NDR_ERR_SUBCONTEXT
, "Bad subcontext (PULL) size_is(%d) mismatch content_size %d",
536 (int)size_is
, (int)content_size
);
538 r_content_size
= content_size
;
543 * Common Type Header for the Serialization Stream
544 * See [MS-RPCE] 2.2.6 Type Serialization Version 1
550 uint32_t content_size
;
554 NDR_CHECK(ndr_pull_uint8(ndr
, NDR_SCALARS
, &version
));
557 return ndr_pull_error(ndr
, NDR_ERR_SUBCONTEXT
,
558 "Bad subcontext (PULL) Common Type Header version %d != 1",
566 NDR_CHECK(ndr_pull_uint8(ndr
, NDR_SCALARS
, &drep
));
569 } else if (drep
== 0x00) {
572 return ndr_pull_error(ndr
, NDR_ERR_SUBCONTEXT
,
573 "Bad subcontext (PULL) Common Type Header invalid drep 0x%02X",
577 /* length of the "Private Header for Constructed Type" */
578 NDR_CHECK(ndr_pull_uint16(ndr
, NDR_SCALARS
, &hdrlen
));
580 return ndr_pull_error(ndr
, NDR_ERR_SUBCONTEXT
,
581 "Bad subcontext (PULL) Common Type Header length %d != 8",
585 /* filler should be ignored */
586 NDR_CHECK(ndr_pull_uint32(ndr
, NDR_SCALARS
, &filler
));
589 * Private Header for Constructed Type
591 /* length - will be updated latter */
592 NDR_CHECK(ndr_pull_uint32(ndr
, NDR_SCALARS
, &content_size
));
593 if (size_is
>= 0 && size_is
!= content_size
) {
594 return ndr_pull_error(ndr
, NDR_ERR_SUBCONTEXT
, "Bad subcontext (PULL) size_is(%d) mismatch content_size %d",
595 (int)size_is
, (int)content_size
);
597 /* the content size must be a multiple of 8 */
598 if ((content_size
% 8) != 0) {
599 return ndr_pull_error(ndr
, NDR_ERR_SUBCONTEXT
,
600 "Bad subcontext (PULL) size_is(%d) not padded to 8 content_size %d",
601 (int)size_is
, (int)content_size
);
603 r_content_size
= content_size
;
606 NDR_CHECK(ndr_pull_uint32(ndr
, NDR_SCALARS
, &reserved
));
610 return ndr_pull_error(ndr
, NDR_ERR_SUBCONTEXT
, "Bad subcontext (PULL) header_size %d",
614 NDR_PULL_NEED_BYTES(ndr
, r_content_size
);
616 subndr
= talloc_zero(ndr
, struct ndr_pull
);
617 NDR_ERR_HAVE_NO_MEMORY(subndr
);
618 subndr
->flags
= ndr
->flags
& ~LIBNDR_FLAG_NDR64
;
619 subndr
->current_mem_ctx
= ndr
->current_mem_ctx
;
621 subndr
->data
= ndr
->data
+ ndr
->offset
;
623 subndr
->data_size
= r_content_size
;
626 ndr_set_flags(&ndr
->flags
, LIBNDR_FLAG_LITTLE_ENDIAN
);
627 } else if (force_be
) {
628 ndr_set_flags(&ndr
->flags
, LIBNDR_FLAG_BIGENDIAN
);
632 return NDR_ERR_SUCCESS
;
635 _PUBLIC_
enum ndr_err_code
ndr_pull_subcontext_end(struct ndr_pull
*ndr
,
636 struct ndr_pull
*subndr
,
643 } else if (header_size
> 0) {
644 advance
= subndr
->data_size
;
646 advance
= subndr
->offset
;
648 NDR_CHECK(ndr_pull_advance(ndr
, advance
));
649 return NDR_ERR_SUCCESS
;
652 _PUBLIC_
enum ndr_err_code
ndr_push_subcontext_start(struct ndr_push
*ndr
,
653 struct ndr_push
**_subndr
,
657 struct ndr_push
*subndr
;
659 subndr
= ndr_push_init_ctx(ndr
);
660 NDR_ERR_HAVE_NO_MEMORY(subndr
);
661 subndr
->flags
= ndr
->flags
& ~LIBNDR_FLAG_NDR64
;
664 NDR_CHECK(ndr_push_zero(subndr
, size_is
));
666 subndr
->relative_end_offset
= size_is
;
670 return NDR_ERR_SUCCESS
;
674 push a subcontext header
676 _PUBLIC_
enum ndr_err_code
ndr_push_subcontext_end(struct ndr_push
*ndr
,
677 struct ndr_push
*subndr
,
684 padding_len
= size_is
- subndr
->offset
;
685 if (padding_len
< 0) {
686 return ndr_push_error(ndr
, NDR_ERR_SUBCONTEXT
, "Bad subcontext (PUSH) content_size %d is larger than size_is(%d)",
687 (int)subndr
->offset
, (int)size_is
);
689 subndr
->offset
= size_is
;
692 switch (header_size
) {
697 NDR_CHECK(ndr_push_uint16(ndr
, NDR_SCALARS
, subndr
->offset
));
701 NDR_CHECK(ndr_push_uint3264(ndr
, NDR_SCALARS
, subndr
->offset
));
706 * Common Type Header for the Serialization Stream
707 * See [MS-RPCE] 2.2.6 Type Serialization Version 1
709 padding_len
= NDR_ROUND(subndr
->offset
, 8) - subndr
->offset
;
710 if (padding_len
> 0) {
711 NDR_CHECK(ndr_push_zero(subndr
, padding_len
));
715 NDR_CHECK(ndr_push_uint8(ndr
, NDR_SCALARS
, 1));
721 NDR_CHECK(ndr_push_uint8(ndr
, NDR_SCALARS
, NDR_BE(ndr
)?0x00:0x10));
723 /* length of the "Private Header for Constructed Type" */
724 NDR_CHECK(ndr_push_uint16(ndr
, NDR_SCALARS
, 8));
727 NDR_CHECK(ndr_push_uint32(ndr
, NDR_SCALARS
, 0xCCCCCCCC));
730 * Private Header for Constructed Type
732 /* length - will be updated latter */
733 NDR_CHECK(ndr_push_uint32(ndr
, NDR_SCALARS
, subndr
->offset
));
736 NDR_CHECK(ndr_push_uint32(ndr
, NDR_SCALARS
, 0));
740 return ndr_push_error(ndr
, NDR_ERR_SUBCONTEXT
, "Bad subcontext header size %d",
744 NDR_CHECK(ndr_push_bytes(ndr
, subndr
->data
, subndr
->offset
));
745 return NDR_ERR_SUCCESS
;
749 store a token in the ndr context, for later retrieval
751 _PUBLIC_
enum ndr_err_code
ndr_token_store(TALLOC_CTX
*mem_ctx
,
752 struct ndr_token_list
**list
,
756 struct ndr_token_list
*tok
;
757 tok
= talloc(mem_ctx
, struct ndr_token_list
);
758 NDR_ERR_HAVE_NO_MEMORY(tok
);
761 DLIST_ADD((*list
), tok
);
762 return NDR_ERR_SUCCESS
;
766 retrieve a token from a ndr context, using cmp_fn to match the tokens
768 _PUBLIC_
enum ndr_err_code
ndr_token_retrieve_cmp_fn(struct ndr_token_list
**list
, const void *key
, uint32_t *v
,
769 comparison_fn_t _cmp_fn
, bool _remove_tok
)
771 struct ndr_token_list
*tok
;
772 for (tok
=*list
;tok
;tok
=tok
->next
) {
773 if (_cmp_fn
&& _cmp_fn(tok
->key
,key
)==0) goto found
;
774 else if (!_cmp_fn
&& tok
->key
== key
) goto found
;
776 return NDR_ERR_TOKEN
;
780 DLIST_REMOVE((*list
), tok
);
783 return NDR_ERR_SUCCESS
;
787 retrieve a token from a ndr context
789 _PUBLIC_
enum ndr_err_code
ndr_token_retrieve(struct ndr_token_list
**list
, const void *key
, uint32_t *v
)
791 return ndr_token_retrieve_cmp_fn(list
, key
, v
, NULL
, true);
795 peek at but don't removed a token from a ndr context
797 _PUBLIC_
uint32_t ndr_token_peek(struct ndr_token_list
**list
, const void *key
)
799 enum ndr_err_code status
;
802 status
= ndr_token_retrieve_cmp_fn(list
, key
, &v
, NULL
, false);
803 if (!NDR_ERR_CODE_IS_SUCCESS(status
)) {
811 pull an array size field and add it to the array_size_list token list
813 _PUBLIC_
enum ndr_err_code
ndr_pull_array_size(struct ndr_pull
*ndr
, const void *p
)
816 NDR_CHECK(ndr_pull_uint3264(ndr
, NDR_SCALARS
, &size
));
817 return ndr_token_store(ndr
, &ndr
->array_size_list
, p
, size
);
821 get the stored array size field
823 _PUBLIC_
uint32_t ndr_get_array_size(struct ndr_pull
*ndr
, const void *p
)
825 return ndr_token_peek(&ndr
->array_size_list
, p
);
829 check the stored array size field
831 _PUBLIC_
enum ndr_err_code
ndr_check_array_size(struct ndr_pull
*ndr
, void *p
, uint32_t size
)
834 stored
= ndr_token_peek(&ndr
->array_size_list
, p
);
835 if (stored
!= size
) {
836 return ndr_pull_error(ndr
, NDR_ERR_ARRAY_SIZE
,
837 "Bad array size - got %u expected %u\n",
840 return NDR_ERR_SUCCESS
;
844 pull an array length field and add it to the array_length_list token list
846 _PUBLIC_
enum ndr_err_code
ndr_pull_array_length(struct ndr_pull
*ndr
, const void *p
)
848 uint32_t length
, offset
;
849 NDR_CHECK(ndr_pull_uint3264(ndr
, NDR_SCALARS
, &offset
));
851 return ndr_pull_error(ndr
, NDR_ERR_ARRAY_SIZE
,
852 "non-zero array offset %u\n", offset
);
854 NDR_CHECK(ndr_pull_uint3264(ndr
, NDR_SCALARS
, &length
));
855 return ndr_token_store(ndr
, &ndr
->array_length_list
, p
, length
);
859 get the stored array length field
861 _PUBLIC_
uint32_t ndr_get_array_length(struct ndr_pull
*ndr
, const void *p
)
863 return ndr_token_peek(&ndr
->array_length_list
, p
);
867 check the stored array length field
869 _PUBLIC_
enum ndr_err_code
ndr_check_array_length(struct ndr_pull
*ndr
, void *p
, uint32_t length
)
872 stored
= ndr_token_peek(&ndr
->array_length_list
, p
);
873 if (stored
!= length
) {
874 return ndr_pull_error(ndr
, NDR_ERR_ARRAY_SIZE
,
875 "Bad array length - got %u expected %u\n",
878 return NDR_ERR_SUCCESS
;
881 _PUBLIC_
enum ndr_err_code
ndr_push_pipe_chunk_trailer(struct ndr_push
*ndr
, int ndr_flags
, uint32_t count
)
883 if (ndr
->flags
& LIBNDR_FLAG_NDR64
) {
884 int64_t tmp
= 0 - (int64_t)count
;
885 uint64_t ncount
= tmp
;
887 NDR_CHECK(ndr_push_hyper(ndr
, ndr_flags
, ncount
));
890 return NDR_ERR_SUCCESS
;
893 _PUBLIC_
enum ndr_err_code
ndr_check_pipe_chunk_trailer(struct ndr_pull
*ndr
, int ndr_flags
, uint32_t count
)
895 if (ndr
->flags
& LIBNDR_FLAG_NDR64
) {
896 int64_t tmp
= 0 - (int64_t)count
;
897 uint64_t ncount1
= tmp
;
900 NDR_CHECK(ndr_pull_hyper(ndr
, ndr_flags
, &ncount2
));
901 if (ncount1
== ncount2
) {
902 return NDR_ERR_SUCCESS
;
905 return ndr_pull_error(ndr
, NDR_ERR_ARRAY_SIZE
,
906 "Bad pipe trailer[%lld should be %lld] size was %lu\"",
907 (unsigned long long)ncount2
,
908 (unsigned long long)ncount1
,
909 (unsigned long)count
);
912 return NDR_ERR_SUCCESS
;
918 _PUBLIC_
enum ndr_err_code
ndr_push_set_switch_value(struct ndr_push
*ndr
, const void *p
, uint32_t val
)
920 return ndr_token_store(ndr
, &ndr
->switch_list
, p
, val
);
923 _PUBLIC_
enum ndr_err_code
ndr_pull_set_switch_value(struct ndr_pull
*ndr
, const void *p
, uint32_t val
)
925 return ndr_token_store(ndr
, &ndr
->switch_list
, p
, val
);
928 _PUBLIC_
enum ndr_err_code
ndr_print_set_switch_value(struct ndr_print
*ndr
, const void *p
, uint32_t val
)
930 return ndr_token_store(ndr
, &ndr
->switch_list
, p
, val
);
934 retrieve a switch value
936 _PUBLIC_
uint32_t ndr_push_get_switch_value(struct ndr_push
*ndr
, const void *p
)
938 return ndr_token_peek(&ndr
->switch_list
, p
);
941 _PUBLIC_
uint32_t ndr_pull_get_switch_value(struct ndr_pull
*ndr
, const void *p
)
943 return ndr_token_peek(&ndr
->switch_list
, p
);
946 _PUBLIC_
uint32_t ndr_print_get_switch_value(struct ndr_print
*ndr
, const void *p
)
948 return ndr_token_peek(&ndr
->switch_list
, p
);
952 pull a struct from a blob using NDR
954 _PUBLIC_
enum ndr_err_code
ndr_pull_struct_blob(const DATA_BLOB
*blob
, TALLOC_CTX
*mem_ctx
, void *p
,
955 ndr_pull_flags_fn_t fn
)
957 struct ndr_pull
*ndr
;
958 ndr
= ndr_pull_init_blob(blob
, mem_ctx
);
959 NDR_ERR_HAVE_NO_MEMORY(ndr
);
960 NDR_CHECK_FREE(fn(ndr
, NDR_SCALARS
|NDR_BUFFERS
, p
));
962 return NDR_ERR_SUCCESS
;
966 pull a struct from a blob using NDR - failing if all bytes are not consumed
968 _PUBLIC_
enum ndr_err_code
ndr_pull_struct_blob_all(const DATA_BLOB
*blob
, TALLOC_CTX
*mem_ctx
,
969 void *p
, ndr_pull_flags_fn_t fn
)
971 struct ndr_pull
*ndr
;
972 uint32_t highest_ofs
;
973 ndr
= ndr_pull_init_blob(blob
, mem_ctx
);
974 NDR_ERR_HAVE_NO_MEMORY(ndr
);
975 NDR_CHECK_FREE(fn(ndr
, NDR_SCALARS
|NDR_BUFFERS
, p
));
976 if (ndr
->offset
> ndr
->relative_highest_offset
) {
977 highest_ofs
= ndr
->offset
;
979 highest_ofs
= ndr
->relative_highest_offset
;
981 if (highest_ofs
< ndr
->data_size
) {
982 enum ndr_err_code ret
;
983 ret
= ndr_pull_error(ndr
, NDR_ERR_UNREAD_BYTES
,
984 "not all bytes consumed ofs[%u] size[%u]",
985 highest_ofs
, ndr
->data_size
);
990 return NDR_ERR_SUCCESS
;
994 pull a union from a blob using NDR, given the union discriminator
996 _PUBLIC_
enum ndr_err_code
ndr_pull_union_blob(const DATA_BLOB
*blob
, TALLOC_CTX
*mem_ctx
,
998 uint32_t level
, ndr_pull_flags_fn_t fn
)
1000 struct ndr_pull
*ndr
;
1001 ndr
= ndr_pull_init_blob(blob
, mem_ctx
);
1002 NDR_ERR_HAVE_NO_MEMORY(ndr
);
1003 NDR_CHECK_FREE(ndr_pull_set_switch_value(ndr
, p
, level
));
1004 NDR_CHECK_FREE(fn(ndr
, NDR_SCALARS
|NDR_BUFFERS
, p
));
1006 return NDR_ERR_SUCCESS
;
1010 pull a union from a blob using NDR, given the union discriminator,
1011 failing if all bytes are not consumed
1013 _PUBLIC_
enum ndr_err_code
ndr_pull_union_blob_all(const DATA_BLOB
*blob
, TALLOC_CTX
*mem_ctx
,
1015 uint32_t level
, ndr_pull_flags_fn_t fn
)
1017 struct ndr_pull
*ndr
;
1018 uint32_t highest_ofs
;
1019 ndr
= ndr_pull_init_blob(blob
, mem_ctx
);
1020 NDR_ERR_HAVE_NO_MEMORY(ndr
);
1021 NDR_CHECK_FREE(ndr_pull_set_switch_value(ndr
, p
, level
));
1022 NDR_CHECK_FREE(fn(ndr
, NDR_SCALARS
|NDR_BUFFERS
, p
));
1023 if (ndr
->offset
> ndr
->relative_highest_offset
) {
1024 highest_ofs
= ndr
->offset
;
1026 highest_ofs
= ndr
->relative_highest_offset
;
1028 if (highest_ofs
< ndr
->data_size
) {
1029 enum ndr_err_code ret
;
1030 ret
= ndr_pull_error(ndr
, NDR_ERR_UNREAD_BYTES
,
1031 "not all bytes consumed ofs[%u] size[%u]",
1032 highest_ofs
, ndr
->data_size
);
1037 return NDR_ERR_SUCCESS
;
1041 push a struct to a blob using NDR
1043 _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
)
1045 struct ndr_push
*ndr
;
1046 ndr
= ndr_push_init_ctx(mem_ctx
);
1047 NDR_ERR_HAVE_NO_MEMORY(ndr
);
1049 NDR_CHECK(fn(ndr
, NDR_SCALARS
|NDR_BUFFERS
, p
));
1051 *blob
= ndr_push_blob(ndr
);
1052 talloc_steal(mem_ctx
, blob
->data
);
1055 return NDR_ERR_SUCCESS
;
1059 push a union to a blob using NDR
1061 _PUBLIC_
enum ndr_err_code
ndr_push_union_blob(DATA_BLOB
*blob
, TALLOC_CTX
*mem_ctx
, void *p
,
1062 uint32_t level
, ndr_push_flags_fn_t fn
)
1064 struct ndr_push
*ndr
;
1065 ndr
= ndr_push_init_ctx(mem_ctx
);
1066 NDR_ERR_HAVE_NO_MEMORY(ndr
);
1068 NDR_CHECK(ndr_push_set_switch_value(ndr
, p
, level
));
1069 NDR_CHECK(fn(ndr
, NDR_SCALARS
|NDR_BUFFERS
, p
));
1071 *blob
= ndr_push_blob(ndr
);
1072 talloc_steal(mem_ctx
, blob
->data
);
1075 return NDR_ERR_SUCCESS
;
1079 generic ndr_size_*() handler for structures
1081 _PUBLIC_
size_t ndr_size_struct(const void *p
, int flags
, ndr_push_flags_fn_t push
)
1083 struct ndr_push
*ndr
;
1084 enum ndr_err_code status
;
1087 /* avoid recursion */
1088 if (flags
& LIBNDR_FLAG_NO_NDR_SIZE
) return 0;
1090 ndr
= ndr_push_init_ctx(NULL
);
1092 ndr
->flags
|= flags
| LIBNDR_FLAG_NO_NDR_SIZE
;
1093 status
= push(ndr
, NDR_SCALARS
|NDR_BUFFERS
, discard_const(p
));
1094 if (!NDR_ERR_CODE_IS_SUCCESS(status
)) {
1104 generic ndr_size_*() handler for unions
1106 _PUBLIC_
size_t ndr_size_union(const void *p
, int flags
, uint32_t level
, ndr_push_flags_fn_t push
)
1108 struct ndr_push
*ndr
;
1109 enum ndr_err_code status
;
1112 /* avoid recursion */
1113 if (flags
& LIBNDR_FLAG_NO_NDR_SIZE
) return 0;
1115 ndr
= ndr_push_init_ctx(NULL
);
1117 ndr
->flags
|= flags
| LIBNDR_FLAG_NO_NDR_SIZE
;
1119 status
= ndr_push_set_switch_value(ndr
, p
, level
);
1120 if (!NDR_ERR_CODE_IS_SUCCESS(status
)) {
1124 status
= push(ndr
, NDR_SCALARS
|NDR_BUFFERS
, p
);
1125 if (!NDR_ERR_CODE_IS_SUCCESS(status
)) {
1135 get the current base for relative pointers for the push
1137 _PUBLIC_
uint32_t ndr_push_get_relative_base_offset(struct ndr_push
*ndr
)
1139 return ndr
->relative_base_offset
;
1143 restore the old base for relative pointers for the push
1145 _PUBLIC_
void ndr_push_restore_relative_base_offset(struct ndr_push
*ndr
, uint32_t offset
)
1147 ndr
->relative_base_offset
= offset
;
1151 setup the current base for relative pointers for the push
1152 called in the NDR_SCALAR stage
1154 _PUBLIC_
enum ndr_err_code
ndr_push_setup_relative_base_offset1(struct ndr_push
*ndr
, const void *p
, uint32_t offset
)
1156 ndr
->relative_base_offset
= offset
;
1157 return ndr_token_store(ndr
, &ndr
->relative_base_list
, p
, offset
);
1161 setup the current base for relative pointers for the push
1162 called in the NDR_BUFFERS stage
1164 _PUBLIC_
enum ndr_err_code
ndr_push_setup_relative_base_offset2(struct ndr_push
*ndr
, const void *p
)
1166 return ndr_token_retrieve(&ndr
->relative_base_list
, p
, &ndr
->relative_base_offset
);
1170 push a relative object - stage1
1171 this is called during SCALARS processing
1173 _PUBLIC_
enum ndr_err_code
ndr_push_relative_ptr1(struct ndr_push
*ndr
, const void *p
)
1176 NDR_CHECK(ndr_push_uint32(ndr
, NDR_SCALARS
, 0));
1177 return NDR_ERR_SUCCESS
;
1179 NDR_CHECK(ndr_push_align(ndr
, 4));
1180 NDR_CHECK(ndr_token_store(ndr
, &ndr
->relative_list
, p
, ndr
->offset
));
1181 return ndr_push_uint32(ndr
, NDR_SCALARS
, 0xFFFFFFFF);
1185 push a short relative object - stage1
1186 this is called during SCALARS processing
1188 _PUBLIC_
enum ndr_err_code
ndr_push_short_relative_ptr1(struct ndr_push
*ndr
, const void *p
)
1191 NDR_CHECK(ndr_push_uint16(ndr
, NDR_SCALARS
, 0));
1192 return NDR_ERR_SUCCESS
;
1194 NDR_CHECK(ndr_push_align(ndr
, 2));
1195 NDR_CHECK(ndr_token_store(ndr
, &ndr
->relative_list
, p
, ndr
->offset
));
1196 return ndr_push_uint16(ndr
, NDR_SCALARS
, 0xFFFF);
1199 push a relative object - stage2
1200 this is called during buffers processing
1202 static enum ndr_err_code
ndr_push_relative_ptr2(struct ndr_push
*ndr
, const void *p
)
1204 uint32_t save_offset
;
1205 uint32_t ptr_offset
= 0xFFFFFFFF;
1207 return NDR_ERR_SUCCESS
;
1209 save_offset
= ndr
->offset
;
1210 NDR_CHECK(ndr_token_retrieve(&ndr
->relative_list
, p
, &ptr_offset
));
1211 if (ptr_offset
> ndr
->offset
) {
1212 return ndr_push_error(ndr
, NDR_ERR_BUFSIZE
,
1213 "ndr_push_relative_ptr2 ptr_offset(%u) > ndr->offset(%u)",
1214 ptr_offset
, ndr
->offset
);
1216 ndr
->offset
= ptr_offset
;
1217 if (save_offset
< ndr
->relative_base_offset
) {
1218 return ndr_push_error(ndr
, NDR_ERR_BUFSIZE
,
1219 "ndr_push_relative_ptr2 save_offset(%u) < ndr->relative_base_offset(%u)",
1220 save_offset
, ndr
->relative_base_offset
);
1222 NDR_CHECK(ndr_push_uint32(ndr
, NDR_SCALARS
, save_offset
- ndr
->relative_base_offset
));
1223 ndr
->offset
= save_offset
;
1224 return NDR_ERR_SUCCESS
;
1227 push a short relative object - stage2
1228 this is called during buffers processing
1230 _PUBLIC_
enum ndr_err_code
ndr_push_short_relative_ptr2(struct ndr_push
*ndr
, const void *p
)
1232 uint32_t save_offset
;
1233 uint32_t ptr_offset
= 0xFFFF;
1235 return NDR_ERR_SUCCESS
;
1237 save_offset
= ndr
->offset
;
1238 NDR_CHECK(ndr_token_retrieve(&ndr
->relative_list
, p
, &ptr_offset
));
1239 if (ptr_offset
> ndr
->offset
) {
1240 return ndr_push_error(ndr
, NDR_ERR_BUFSIZE
,
1241 "ndr_push_short_relative_ptr2 ptr_offset(%u) > ndr->offset(%u)",
1242 ptr_offset
, ndr
->offset
);
1244 ndr
->offset
= ptr_offset
;
1245 if (save_offset
< ndr
->relative_base_offset
) {
1246 return ndr_push_error(ndr
, NDR_ERR_BUFSIZE
,
1247 "ndr_push_relative_ptr2 save_offset(%u) < ndr->relative_base_offset(%u)",
1248 save_offset
, ndr
->relative_base_offset
);
1250 NDR_CHECK(ndr_push_uint16(ndr
, NDR_SCALARS
, save_offset
- ndr
->relative_base_offset
));
1251 ndr
->offset
= save_offset
;
1252 return NDR_ERR_SUCCESS
;
1256 push a relative object - stage2 start
1257 this is called during buffers processing
1259 _PUBLIC_
enum ndr_err_code
ndr_push_relative_ptr2_start(struct ndr_push
*ndr
, const void *p
)
1262 return NDR_ERR_SUCCESS
;
1264 if (!(ndr
->flags
& LIBNDR_FLAG_RELATIVE_REVERSE
)) {
1265 uint32_t relative_offset
;
1269 if (ndr
->offset
< ndr
->relative_base_offset
) {
1270 return ndr_push_error(ndr
, NDR_ERR_BUFSIZE
,
1271 "ndr_push_relative_ptr2_start ndr->offset(%u) < ndr->relative_base_offset(%u)",
1272 ndr
->offset
, ndr
->relative_base_offset
);
1275 relative_offset
= ndr
->offset
- ndr
->relative_base_offset
;
1277 if (ndr
->flags
& LIBNDR_FLAG_NOALIGN
) {
1279 } else if (ndr
->flags
& LIBNDR_FLAG_ALIGN2
) {
1281 } else if (ndr
->flags
& LIBNDR_FLAG_ALIGN4
) {
1283 } else if (ndr
->flags
& LIBNDR_FLAG_ALIGN8
) {
1287 pad
= ndr_align_size(relative_offset
, align
);
1289 NDR_CHECK(ndr_push_zero(ndr
, pad
));
1292 return ndr_push_relative_ptr2(ndr
, p
);
1294 if (ndr
->relative_end_offset
== -1) {
1295 return ndr_push_error(ndr
, NDR_ERR_RELATIVE
,
1296 "ndr_push_relative_ptr2_start RELATIVE_REVERSE flag set and relative_end_offset %d",
1297 ndr
->relative_end_offset
);
1299 NDR_CHECK(ndr_token_store(ndr
, &ndr
->relative_begin_list
, p
, ndr
->offset
));
1300 return NDR_ERR_SUCCESS
;
1304 push a relative object - stage2 end
1305 this is called during buffers processing
1307 _PUBLIC_
enum ndr_err_code
ndr_push_relative_ptr2_end(struct ndr_push
*ndr
, const void *p
)
1309 uint32_t begin_offset
= 0xFFFFFFFF;
1311 uint32_t correct_offset
= 0;
1316 return NDR_ERR_SUCCESS
;
1319 if (!(ndr
->flags
& LIBNDR_FLAG_RELATIVE_REVERSE
)) {
1320 return NDR_ERR_SUCCESS
;
1323 if (ndr
->flags
& LIBNDR_FLAG_NO_NDR_SIZE
) {
1324 /* better say more than calculation a too small buffer */
1325 NDR_PUSH_ALIGN(ndr
, 8);
1326 return NDR_ERR_SUCCESS
;
1329 if (ndr
->relative_end_offset
< ndr
->offset
) {
1330 return ndr_push_error(ndr
, NDR_ERR_RELATIVE
,
1331 "ndr_push_relative_ptr2_end:"
1332 "relative_end_offset %u < offset %u",
1333 ndr
->relative_end_offset
, ndr
->offset
);
1336 NDR_CHECK(ndr_token_retrieve(&ndr
->relative_begin_list
, p
, &begin_offset
));
1338 /* we have marshalled a buffer, see how long it was */
1339 len
= ndr
->offset
- begin_offset
;
1342 return ndr_push_error(ndr
, NDR_ERR_RELATIVE
,
1343 "ndr_push_relative_ptr2_end:"
1344 "offset %u - begin_offset %u < 0",
1345 ndr
->offset
, begin_offset
);
1348 if (ndr
->relative_end_offset
< len
) {
1349 return ndr_push_error(ndr
, NDR_ERR_RELATIVE
,
1350 "ndr_push_relative_ptr2_end:"
1351 "relative_end_offset %u < len %lld",
1352 ndr
->offset
, (long long)len
);
1355 /* the reversed offset is at the end of the main buffer */
1356 correct_offset
= ndr
->relative_end_offset
- len
;
1358 if (ndr
->flags
& LIBNDR_FLAG_NOALIGN
) {
1360 } else if (ndr
->flags
& LIBNDR_FLAG_ALIGN2
) {
1362 } else if (ndr
->flags
& LIBNDR_FLAG_ALIGN4
) {
1364 } else if (ndr
->flags
& LIBNDR_FLAG_ALIGN8
) {
1368 pad
= ndr_align_size(correct_offset
, align
);
1370 correct_offset
+= pad
;
1371 correct_offset
-= align
;
1374 if (correct_offset
< begin_offset
) {
1375 return ndr_push_error(ndr
, NDR_ERR_RELATIVE
,
1376 "ndr_push_relative_ptr2_end: "
1377 "correct_offset %u < begin_offset %u",
1378 correct_offset
, begin_offset
);
1382 uint32_t clear_size
= correct_offset
- begin_offset
;
1384 clear_size
= MIN(clear_size
, len
);
1386 /* now move the marshalled buffer to the end of the main buffer */
1387 memmove(ndr
->data
+ correct_offset
, ndr
->data
+ begin_offset
, len
);
1390 /* and wipe out old buffer within the main buffer */
1391 memset(ndr
->data
+ begin_offset
, '\0', clear_size
);
1395 /* and set the end offset for the next buffer */
1396 ndr
->relative_end_offset
= correct_offset
;
1398 /* finally write the offset to the main buffer */
1399 ndr
->offset
= correct_offset
;
1400 NDR_CHECK(ndr_push_relative_ptr2(ndr
, p
));
1402 /* restore to where we were in the main buffer */
1403 ndr
->offset
= begin_offset
;
1405 return NDR_ERR_SUCCESS
;
1409 get the current base for relative pointers for the pull
1411 _PUBLIC_
uint32_t ndr_pull_get_relative_base_offset(struct ndr_pull
*ndr
)
1413 return ndr
->relative_base_offset
;
1417 restore the old base for relative pointers for the pull
1419 _PUBLIC_
void ndr_pull_restore_relative_base_offset(struct ndr_pull
*ndr
, uint32_t offset
)
1421 ndr
->relative_base_offset
= offset
;
1425 setup the current base for relative pointers for the pull
1426 called in the NDR_SCALAR stage
1428 _PUBLIC_
enum ndr_err_code
ndr_pull_setup_relative_base_offset1(struct ndr_pull
*ndr
, const void *p
, uint32_t offset
)
1430 ndr
->relative_base_offset
= offset
;
1431 return ndr_token_store(ndr
, &ndr
->relative_base_list
, p
, offset
);
1435 setup the current base for relative pointers for the pull
1436 called in the NDR_BUFFERS stage
1438 _PUBLIC_
enum ndr_err_code
ndr_pull_setup_relative_base_offset2(struct ndr_pull
*ndr
, const void *p
)
1440 return ndr_token_retrieve(&ndr
->relative_base_list
, p
, &ndr
->relative_base_offset
);
1444 pull a relative object - stage1
1445 called during SCALARS processing
1447 _PUBLIC_
enum ndr_err_code
ndr_pull_relative_ptr1(struct ndr_pull
*ndr
, const void *p
, uint32_t rel_offset
)
1449 rel_offset
+= ndr
->relative_base_offset
;
1450 if (rel_offset
> ndr
->data_size
) {
1451 return ndr_pull_error(ndr
, NDR_ERR_BUFSIZE
,
1452 "ndr_pull_relative_ptr1 rel_offset(%u) > ndr->data_size(%u)",
1453 rel_offset
, ndr
->data_size
);
1455 return ndr_token_store(ndr
, &ndr
->relative_list
, p
, rel_offset
);
1459 pull a relative object - stage2
1460 called during BUFFERS processing
1462 _PUBLIC_
enum ndr_err_code
ndr_pull_relative_ptr2(struct ndr_pull
*ndr
, const void *p
)
1464 uint32_t rel_offset
;
1465 NDR_CHECK(ndr_token_retrieve(&ndr
->relative_list
, p
, &rel_offset
));
1466 return ndr_pull_set_offset(ndr
, rel_offset
);
1469 const static struct {
1470 enum ndr_err_code err
;
1472 } ndr_err_code_strings
[] = {
1473 { NDR_ERR_SUCCESS
, "Success" },
1474 { NDR_ERR_ARRAY_SIZE
, "Bad Array Size" },
1475 { NDR_ERR_BAD_SWITCH
, "Bad Switch" },
1476 { NDR_ERR_OFFSET
, "Offset Error" },
1477 { NDR_ERR_RELATIVE
, "Relative Pointer Error" },
1478 { NDR_ERR_CHARCNV
, "Character Conversion Error" },
1479 { NDR_ERR_LENGTH
, "Length Error" },
1480 { NDR_ERR_SUBCONTEXT
, "Subcontext Error" },
1481 { NDR_ERR_COMPRESSION
, "Compression Error" },
1482 { NDR_ERR_STRING
, "String Error" },
1483 { NDR_ERR_VALIDATE
, "Validate Error" },
1484 { NDR_ERR_BUFSIZE
, "Buffer Size Error" },
1485 { NDR_ERR_ALLOC
, "Allocation Error" },
1486 { NDR_ERR_RANGE
, "Range Error" },
1487 { NDR_ERR_TOKEN
, "Token Error" },
1488 { NDR_ERR_IPV4ADDRESS
, "IPv4 Address Error" },
1489 { NDR_ERR_INVALID_POINTER
, "Invalid Pointer" },
1490 { NDR_ERR_UNREAD_BYTES
, "Unread Bytes" },
1491 { NDR_ERR_NDR64
, "NDR64 assertion error" },
1495 _PUBLIC_
const char *ndr_map_error2string(enum ndr_err_code ndr_err
)
1498 for (i
= 0; ndr_err_code_strings
[i
].string
!= NULL
; i
++) {
1499 if (ndr_err_code_strings
[i
].err
== ndr_err
)
1500 return ndr_err_code_strings
[i
].string
;
1502 return "Unknown error";