2 Unix SMB/CIFS implementation.
4 routines for marshalling/unmarshalling basic types
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 #include "system/network.h"
24 #include "librpc/ndr/libndr.h"
25 #include "lib/util/util_net.h"
27 #define NDR_SVAL(ndr, ofs) (NDR_BE(ndr)?RSVAL(ndr->data,ofs):SVAL(ndr->data,ofs))
28 #define NDR_IVAL(ndr, ofs) (NDR_BE(ndr)?RIVAL(ndr->data,ofs):IVAL(ndr->data,ofs))
29 #define NDR_IVALS(ndr, ofs) (NDR_BE(ndr)?RIVALS(ndr->data,ofs):IVALS(ndr->data,ofs))
30 #define NDR_SSVAL(ndr, ofs, v) do { if (NDR_BE(ndr)) { RSSVAL(ndr->data,ofs,v); } else SSVAL(ndr->data,ofs,v); } while (0)
31 #define NDR_SIVAL(ndr, ofs, v) do { if (NDR_BE(ndr)) { RSIVAL(ndr->data,ofs,v); } else SIVAL(ndr->data,ofs,v); } while (0)
32 #define NDR_SIVALS(ndr, ofs, v) do { if (NDR_BE(ndr)) { RSIVALS(ndr->data,ofs,v); } else SIVALS(ndr->data,ofs,v); } while (0)
35 static void ndr_dump_data(struct ndr_print
*ndr
, const uint8_t *buf
, int len
);
38 check for data leaks from the server by looking for non-zero pad bytes
39 these could also indicate that real structure elements have been
40 mistaken for padding in the IDL
42 _PUBLIC_
void ndr_check_padding(struct ndr_pull
*ndr
, size_t n
)
44 size_t ofs2
= (ndr
->offset
+ (n
-1)) & ~(n
-1);
46 for (i
=ndr
->offset
;i
<ofs2
;i
++) {
47 if (ndr
->data
[i
] != 0) {
52 DEBUG(0,("WARNING: Non-zero padding to %d: ", (int)n
));
53 for (i
=ndr
->offset
;i
<ofs2
;i
++) {
54 DEBUG(0,("%02x ", ndr
->data
[i
]));
64 _PUBLIC_
enum ndr_err_code
ndr_pull_int8(struct ndr_pull
*ndr
, int ndr_flags
, int8_t *v
)
66 NDR_PULL_CHECK_FLAGS(ndr
, ndr_flags
);
67 NDR_PULL_NEED_BYTES(ndr
, 1);
68 *v
= (int8_t)CVAL(ndr
->data
, ndr
->offset
);
70 return NDR_ERR_SUCCESS
;
76 _PUBLIC_
enum ndr_err_code
ndr_pull_uint8(struct ndr_pull
*ndr
, int ndr_flags
, uint8_t *v
)
78 NDR_PULL_CHECK_FLAGS(ndr
, ndr_flags
);
79 NDR_PULL_NEED_BYTES(ndr
, 1);
80 *v
= CVAL(ndr
->data
, ndr
->offset
);
82 return NDR_ERR_SUCCESS
;
88 _PUBLIC_
enum ndr_err_code
ndr_pull_int16(struct ndr_pull
*ndr
, int ndr_flags
, int16_t *v
)
90 NDR_PULL_CHECK_FLAGS(ndr
, ndr_flags
);
91 NDR_PULL_ALIGN(ndr
, 2);
92 NDR_PULL_NEED_BYTES(ndr
, 2);
93 *v
= (uint16_t)NDR_SVAL(ndr
, ndr
->offset
);
95 return NDR_ERR_SUCCESS
;
101 _PUBLIC_
enum ndr_err_code
ndr_pull_uint16(struct ndr_pull
*ndr
, int ndr_flags
, uint16_t *v
)
103 NDR_PULL_CHECK_FLAGS(ndr
, ndr_flags
);
104 NDR_PULL_ALIGN(ndr
, 2);
105 NDR_PULL_NEED_BYTES(ndr
, 2);
106 *v
= NDR_SVAL(ndr
, ndr
->offset
);
108 return NDR_ERR_SUCCESS
;
114 _PUBLIC_
enum ndr_err_code
ndr_pull_uint1632(struct ndr_pull
*ndr
, int ndr_flags
, uint16_t *v
)
116 NDR_PULL_CHECK_FLAGS(ndr
, ndr_flags
);
117 if (unlikely(ndr
->flags
& LIBNDR_FLAG_NDR64
)) {
119 enum ndr_err_code err
= ndr_pull_uint32(ndr
, ndr_flags
, &v32
);
121 if (unlikely(v32
!= *v
)) {
122 DEBUG(0,(__location__
": non-zero upper 16 bits 0x%08x\n", (unsigned)v32
));
123 return NDR_ERR_NDR64
;
127 return ndr_pull_uint16(ndr
, ndr_flags
, v
);
133 _PUBLIC_
enum ndr_err_code
ndr_pull_int32(struct ndr_pull
*ndr
, int ndr_flags
, int32_t *v
)
135 NDR_PULL_CHECK_FLAGS(ndr
, ndr_flags
);
136 NDR_PULL_ALIGN(ndr
, 4);
137 NDR_PULL_NEED_BYTES(ndr
, 4);
138 *v
= NDR_IVALS(ndr
, ndr
->offset
);
140 return NDR_ERR_SUCCESS
;
146 _PUBLIC_
enum ndr_err_code
ndr_pull_uint32(struct ndr_pull
*ndr
, int ndr_flags
, uint32_t *v
)
148 NDR_PULL_CHECK_FLAGS(ndr
, ndr_flags
);
149 NDR_PULL_ALIGN(ndr
, 4);
150 NDR_PULL_NEED_BYTES(ndr
, 4);
151 *v
= NDR_IVAL(ndr
, ndr
->offset
);
153 return NDR_ERR_SUCCESS
;
157 parse a arch dependent uint32/uint64
159 _PUBLIC_
enum ndr_err_code
ndr_pull_uint3264(struct ndr_pull
*ndr
, int ndr_flags
, uint32_t *v
)
162 enum ndr_err_code err
;
163 NDR_PULL_CHECK_FLAGS(ndr
, ndr_flags
);
164 if (likely(!(ndr
->flags
& LIBNDR_FLAG_NDR64
))) {
165 return ndr_pull_uint32(ndr
, ndr_flags
, v
);
167 err
= ndr_pull_hyper(ndr
, ndr_flags
, &v64
);
169 if (unlikely(v64
!= *v
)) {
170 DEBUG(0,(__location__
": non-zero upper 32 bits 0x%016llx\n",
171 (unsigned long long)v64
));
172 return ndr_pull_error(ndr
, NDR_ERR_NDR64
, __location__
": non-zero upper 32 bits 0x%016llx\n",
173 (unsigned long long)v64
);
181 _PUBLIC_
enum ndr_err_code
ndr_pull_double(struct ndr_pull
*ndr
, int ndr_flags
, double *v
)
183 NDR_PULL_CHECK_FLAGS(ndr
, ndr_flags
);
184 NDR_PULL_ALIGN(ndr
, 8);
185 NDR_PULL_NEED_BYTES(ndr
, 8);
186 memcpy(v
, ndr
->data
+ndr
->offset
, 8);
188 return NDR_ERR_SUCCESS
;
192 parse a pointer referent identifier stored in 2 bytes
194 _PUBLIC_
enum ndr_err_code
ndr_pull_relative_ptr_short(struct ndr_pull
*ndr
, uint16_t *v
)
196 NDR_CHECK(ndr_pull_uint16(ndr
, NDR_SCALARS
, v
));
200 *(v
) -= ndr
->relative_rap_convert
;
201 return NDR_ERR_SUCCESS
;
205 parse a pointer referent identifier
207 _PUBLIC_
enum ndr_err_code
ndr_pull_generic_ptr(struct ndr_pull
*ndr
, uint32_t *v
)
209 NDR_CHECK(ndr_pull_uint3264(ndr
, NDR_SCALARS
, v
));
213 return NDR_ERR_SUCCESS
;
217 parse a ref pointer referent identifier
219 _PUBLIC_
enum ndr_err_code
ndr_pull_ref_ptr(struct ndr_pull
*ndr
, uint32_t *v
)
221 NDR_CHECK(ndr_pull_uint3264(ndr
, NDR_SCALARS
, v
));
222 /* ref pointers always point to data */
224 return NDR_ERR_SUCCESS
;
230 _PUBLIC_
enum ndr_err_code
ndr_pull_udlong(struct ndr_pull
*ndr
, int ndr_flags
, uint64_t *v
)
232 NDR_PULL_CHECK_FLAGS(ndr
, ndr_flags
);
233 NDR_PULL_ALIGN(ndr
, 4);
234 NDR_PULL_NEED_BYTES(ndr
, 8);
235 *v
= NDR_IVAL(ndr
, ndr
->offset
);
236 *v
|= (uint64_t)(NDR_IVAL(ndr
, ndr
->offset
+4)) << 32;
238 return NDR_ERR_SUCCESS
;
244 _PUBLIC_
enum ndr_err_code
ndr_pull_udlongr(struct ndr_pull
*ndr
, int ndr_flags
, uint64_t *v
)
246 NDR_PULL_CHECK_FLAGS(ndr
, ndr_flags
);
247 NDR_PULL_ALIGN(ndr
, 4);
248 NDR_PULL_NEED_BYTES(ndr
, 8);
249 *v
= ((uint64_t)NDR_IVAL(ndr
, ndr
->offset
)) << 32;
250 *v
|= NDR_IVAL(ndr
, ndr
->offset
+4);
252 return NDR_ERR_SUCCESS
;
258 _PUBLIC_
enum ndr_err_code
ndr_pull_dlong(struct ndr_pull
*ndr
, int ndr_flags
, int64_t *v
)
260 return ndr_pull_udlong(ndr
, ndr_flags
, (uint64_t *)v
);
266 _PUBLIC_
enum ndr_err_code
ndr_pull_hyper(struct ndr_pull
*ndr
, int ndr_flags
, uint64_t *v
)
268 NDR_PULL_ALIGN(ndr
, 8);
270 return ndr_pull_udlongr(ndr
, ndr_flags
, v
);
272 return ndr_pull_udlong(ndr
, ndr_flags
, v
);
278 _PUBLIC_
enum ndr_err_code
ndr_pull_pointer(struct ndr_pull
*ndr
, int ndr_flags
, void* *v
)
281 NDR_PULL_CHECK_FLAGS(ndr
, ndr_flags
);
282 NDR_PULL_ALIGN(ndr
, sizeof(h
));
283 NDR_PULL_NEED_BYTES(ndr
, sizeof(h
));
284 memcpy(&h
, ndr
->data
+ndr
->offset
, sizeof(h
));
285 ndr
->offset
+= sizeof(h
);
287 return NDR_ERR_SUCCESS
;
293 _PUBLIC_
enum ndr_err_code
ndr_pull_NTSTATUS(struct ndr_pull
*ndr
, int ndr_flags
, NTSTATUS
*status
)
296 NDR_PULL_CHECK_FLAGS(ndr
, ndr_flags
);
297 NDR_CHECK(ndr_pull_uint32(ndr
, NDR_SCALARS
, &v
));
298 *status
= NT_STATUS(v
);
299 return NDR_ERR_SUCCESS
;
305 _PUBLIC_
enum ndr_err_code
ndr_push_NTSTATUS(struct ndr_push
*ndr
, int ndr_flags
, NTSTATUS status
)
307 return ndr_push_uint32(ndr
, ndr_flags
, NT_STATUS_V(status
));
310 _PUBLIC_
void ndr_print_NTSTATUS(struct ndr_print
*ndr
, const char *name
, NTSTATUS r
)
312 ndr
->print(ndr
, "%-25s: %s", name
, nt_errstr(r
));
318 _PUBLIC_
enum ndr_err_code
ndr_pull_WERROR(struct ndr_pull
*ndr
, int ndr_flags
, WERROR
*status
)
321 NDR_PULL_CHECK_FLAGS(ndr
, ndr_flags
);
322 NDR_CHECK(ndr_pull_uint32(ndr
, NDR_SCALARS
, &v
));
323 *status
= W_ERROR(v
);
324 return NDR_ERR_SUCCESS
;
330 _PUBLIC_
enum ndr_err_code
ndr_pull_HRESULT(struct ndr_pull
*ndr
, int ndr_flags
, HRESULT
*status
)
333 NDR_PULL_CHECK_FLAGS(ndr
, ndr_flags
);
334 NDR_CHECK(ndr_pull_uint32(ndr
, NDR_SCALARS
, &v
));
335 *status
= HRES_ERROR(v
);
336 return NDR_ERR_SUCCESS
;
342 _PUBLIC_
enum ndr_err_code
ndr_pull_enum_uint8(struct ndr_pull
*ndr
, int ndr_flags
, uint8_t *v
)
344 return ndr_pull_uint8(ndr
, ndr_flags
, v
);
348 parse a uint16_t enum
350 _PUBLIC_
enum ndr_err_code
ndr_pull_enum_uint16(struct ndr_pull
*ndr
, int ndr_flags
, uint16_t *v
)
352 return ndr_pull_uint16(ndr
, ndr_flags
, v
);
356 parse a uint1632_t enum (uint32_t on NDR64)
358 _PUBLIC_
enum ndr_err_code
ndr_pull_enum_uint1632(struct ndr_pull
*ndr
, int ndr_flags
, uint16_t *v
)
360 if (unlikely(ndr
->flags
& LIBNDR_FLAG_NDR64
)) {
362 NDR_CHECK(ndr_pull_uint32(ndr
, ndr_flags
, &v32
));
365 DEBUG(0,(__location__
": non-zero upper 16 bits 0x%08x\n", (unsigned)v32
));
366 return NDR_ERR_NDR64
;
368 return NDR_ERR_SUCCESS
;
370 return ndr_pull_uint16(ndr
, ndr_flags
, v
);
374 parse a uint32_t enum
376 _PUBLIC_
enum ndr_err_code
ndr_pull_enum_uint32(struct ndr_pull
*ndr
, int ndr_flags
, uint32_t *v
)
378 return ndr_pull_uint32(ndr
, ndr_flags
, v
);
384 _PUBLIC_
enum ndr_err_code
ndr_push_enum_uint8(struct ndr_push
*ndr
, int ndr_flags
, uint8_t v
)
386 return ndr_push_uint8(ndr
, ndr_flags
, v
);
392 _PUBLIC_
enum ndr_err_code
ndr_push_enum_uint16(struct ndr_push
*ndr
, int ndr_flags
, uint16_t v
)
394 return ndr_push_uint16(ndr
, ndr_flags
, v
);
400 _PUBLIC_
enum ndr_err_code
ndr_push_enum_uint32(struct ndr_push
*ndr
, int ndr_flags
, uint32_t v
)
402 return ndr_push_uint32(ndr
, ndr_flags
, v
);
406 push a uint1632_t enum
408 _PUBLIC_
enum ndr_err_code
ndr_push_enum_uint1632(struct ndr_push
*ndr
, int ndr_flags
, uint16_t v
)
410 if (unlikely(ndr
->flags
& LIBNDR_FLAG_NDR64
)) {
411 return ndr_push_uint32(ndr
, ndr_flags
, v
);
413 return ndr_push_uint16(ndr
, ndr_flags
, v
);
419 _PUBLIC_
enum ndr_err_code
ndr_push_WERROR(struct ndr_push
*ndr
, int ndr_flags
, WERROR status
)
421 return ndr_push_uint32(ndr
, NDR_SCALARS
, W_ERROR_V(status
));
424 _PUBLIC_
void ndr_print_WERROR(struct ndr_print
*ndr
, const char *name
, WERROR r
)
426 ndr
->print(ndr
, "%-25s: %s", name
, win_errstr(r
));
432 _PUBLIC_
enum ndr_err_code
ndr_push_HRESULT(struct ndr_push
*ndr
, int ndr_flags
, HRESULT status
)
434 return ndr_push_uint32(ndr
, NDR_SCALARS
, HRES_ERROR_V(status
));
437 _PUBLIC_
void ndr_print_HRESULT(struct ndr_print
*ndr
, const char *name
, HRESULT r
)
439 ndr
->print(ndr
, "%-25s: %s", name
, hresult_errstr(r
));
446 _PUBLIC_
enum ndr_err_code
ndr_pull_bytes(struct ndr_pull
*ndr
, uint8_t *data
, uint32_t n
)
448 NDR_PULL_NEED_BYTES(ndr
, n
);
449 memcpy(data
, ndr
->data
+ ndr
->offset
, n
);
451 return NDR_ERR_SUCCESS
;
455 pull an array of uint8
457 _PUBLIC_
enum ndr_err_code
ndr_pull_array_uint8(struct ndr_pull
*ndr
, int ndr_flags
, uint8_t *data
, uint32_t n
)
459 NDR_PULL_CHECK_FLAGS(ndr
, ndr_flags
);
460 if (!(ndr_flags
& NDR_SCALARS
)) {
461 return NDR_ERR_SUCCESS
;
463 return ndr_pull_bytes(ndr
, data
, n
);
469 _PUBLIC_
enum ndr_err_code
ndr_push_int8(struct ndr_push
*ndr
, int ndr_flags
, int8_t v
)
471 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
472 NDR_PUSH_NEED_BYTES(ndr
, 1);
473 SCVAL(ndr
->data
, ndr
->offset
, (uint8_t)v
);
475 return NDR_ERR_SUCCESS
;
481 _PUBLIC_
enum ndr_err_code
ndr_push_uint8(struct ndr_push
*ndr
, int ndr_flags
, uint8_t v
)
483 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
484 NDR_PUSH_NEED_BYTES(ndr
, 1);
485 SCVAL(ndr
->data
, ndr
->offset
, v
);
487 return NDR_ERR_SUCCESS
;
493 _PUBLIC_
enum ndr_err_code
ndr_push_int16(struct ndr_push
*ndr
, int ndr_flags
, int16_t v
)
495 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
496 NDR_PUSH_ALIGN(ndr
, 2);
497 NDR_PUSH_NEED_BYTES(ndr
, 2);
498 NDR_SSVAL(ndr
, ndr
->offset
, (uint16_t)v
);
500 return NDR_ERR_SUCCESS
;
506 _PUBLIC_
enum ndr_err_code
ndr_push_uint16(struct ndr_push
*ndr
, int ndr_flags
, uint16_t v
)
508 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
509 NDR_PUSH_ALIGN(ndr
, 2);
510 NDR_PUSH_NEED_BYTES(ndr
, 2);
511 NDR_SSVAL(ndr
, ndr
->offset
, v
);
513 return NDR_ERR_SUCCESS
;
519 _PUBLIC_
enum ndr_err_code
ndr_push_uint1632(struct ndr_push
*ndr
, int ndr_flags
, uint16_t v
)
521 if (unlikely(ndr
->flags
& LIBNDR_FLAG_NDR64
)) {
522 return ndr_push_uint32(ndr
, ndr_flags
, v
);
524 return ndr_push_uint16(ndr
, ndr_flags
, v
);
530 _PUBLIC_
enum ndr_err_code
ndr_push_int32(struct ndr_push
*ndr
, int ndr_flags
, int32_t v
)
532 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
533 NDR_PUSH_ALIGN(ndr
, 4);
534 NDR_PUSH_NEED_BYTES(ndr
, 4);
535 NDR_SIVALS(ndr
, ndr
->offset
, v
);
537 return NDR_ERR_SUCCESS
;
543 _PUBLIC_
enum ndr_err_code
ndr_push_uint32(struct ndr_push
*ndr
, int ndr_flags
, uint32_t v
)
545 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
546 NDR_PUSH_ALIGN(ndr
, 4);
547 NDR_PUSH_NEED_BYTES(ndr
, 4);
548 NDR_SIVAL(ndr
, ndr
->offset
, v
);
550 return NDR_ERR_SUCCESS
;
556 _PUBLIC_
enum ndr_err_code
ndr_push_uint3264(struct ndr_push
*ndr
, int ndr_flags
, uint32_t v
)
558 if (unlikely(ndr
->flags
& LIBNDR_FLAG_NDR64
)) {
559 return ndr_push_hyper(ndr
, ndr_flags
, v
);
561 return ndr_push_uint32(ndr
, ndr_flags
, v
);
567 _PUBLIC_
enum ndr_err_code
ndr_push_udlong(struct ndr_push
*ndr
, int ndr_flags
, uint64_t v
)
569 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
570 NDR_PUSH_ALIGN(ndr
, 4);
571 NDR_PUSH_NEED_BYTES(ndr
, 8);
572 NDR_SIVAL(ndr
, ndr
->offset
, (v
& 0xFFFFFFFF));
573 NDR_SIVAL(ndr
, ndr
->offset
+4, (v
>>32));
575 return NDR_ERR_SUCCESS
;
581 _PUBLIC_
enum ndr_err_code
ndr_push_udlongr(struct ndr_push
*ndr
, int ndr_flags
, uint64_t v
)
583 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
584 NDR_PUSH_ALIGN(ndr
, 4);
585 NDR_PUSH_NEED_BYTES(ndr
, 8);
586 NDR_SIVAL(ndr
, ndr
->offset
, (v
>>32));
587 NDR_SIVAL(ndr
, ndr
->offset
+4, (v
& 0xFFFFFFFF));
589 return NDR_ERR_SUCCESS
;
595 _PUBLIC_
enum ndr_err_code
ndr_push_dlong(struct ndr_push
*ndr
, int ndr_flags
, int64_t v
)
597 return ndr_push_udlong(ndr
, NDR_SCALARS
, (uint64_t)v
);
603 _PUBLIC_
enum ndr_err_code
ndr_push_hyper(struct ndr_push
*ndr
, int ndr_flags
, uint64_t v
)
605 NDR_PUSH_ALIGN(ndr
, 8);
607 return ndr_push_udlongr(ndr
, NDR_SCALARS
, v
);
609 return ndr_push_udlong(ndr
, NDR_SCALARS
, v
);
615 _PUBLIC_
enum ndr_err_code
ndr_push_double(struct ndr_push
*ndr
, int ndr_flags
, double v
)
617 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
618 NDR_PUSH_ALIGN(ndr
, 8);
619 NDR_PUSH_NEED_BYTES(ndr
, 8);
620 memcpy(ndr
->data
+ndr
->offset
, &v
, 8);
622 return NDR_ERR_SUCCESS
;
628 _PUBLIC_
enum ndr_err_code
ndr_push_pointer(struct ndr_push
*ndr
, int ndr_flags
, void* v
)
630 uintptr_t h
= (intptr_t)v
;
631 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
632 NDR_PUSH_ALIGN(ndr
, sizeof(h
));
633 NDR_PUSH_NEED_BYTES(ndr
, sizeof(h
));
634 memcpy(ndr
->data
+ndr
->offset
, &h
, sizeof(h
));
635 ndr
->offset
+= sizeof(h
);
636 return NDR_ERR_SUCCESS
;
639 _PUBLIC_
enum ndr_err_code
ndr_push_align(struct ndr_push
*ndr
, size_t size
)
641 /* this is a nasty hack to make pidl work with NDR64 */
643 if (ndr
->flags
& LIBNDR_FLAG_NDR64
) {
648 } else if (size
== 3) {
649 if (ndr
->flags
& LIBNDR_FLAG_NDR64
) {
655 NDR_PUSH_ALIGN(ndr
, size
);
656 return NDR_ERR_SUCCESS
;
659 _PUBLIC_
enum ndr_err_code
ndr_pull_align(struct ndr_pull
*ndr
, size_t size
)
661 /* this is a nasty hack to make pidl work with NDR64 */
663 if (ndr
->flags
& LIBNDR_FLAG_NDR64
) {
668 } else if (size
== 3) {
669 if (ndr
->flags
& LIBNDR_FLAG_NDR64
) {
675 NDR_PULL_ALIGN(ndr
, size
);
676 return NDR_ERR_SUCCESS
;
679 _PUBLIC_
enum ndr_err_code
ndr_push_union_align(struct ndr_push
*ndr
, size_t size
)
681 /* MS-RPCE section 2.2.5.3.4.4 */
682 if (ndr
->flags
& LIBNDR_FLAG_NDR64
) {
683 return ndr_push_align(ndr
, size
);
685 return NDR_ERR_SUCCESS
;
688 _PUBLIC_
enum ndr_err_code
ndr_pull_union_align(struct ndr_pull
*ndr
, size_t size
)
690 /* MS-RPCE section 2.2.5.3.4.4 */
691 if (ndr
->flags
& LIBNDR_FLAG_NDR64
) {
692 return ndr_pull_align(ndr
, size
);
694 return NDR_ERR_SUCCESS
;
697 _PUBLIC_
enum ndr_err_code
ndr_push_trailer_align(struct ndr_push
*ndr
, size_t size
)
699 /* MS-RPCE section 2.2.5.3.4.1 */
700 if (ndr
->flags
& LIBNDR_FLAG_NDR64
) {
701 return ndr_push_align(ndr
, size
);
703 return NDR_ERR_SUCCESS
;
706 _PUBLIC_
enum ndr_err_code
ndr_pull_trailer_align(struct ndr_pull
*ndr
, size_t size
)
708 /* MS-RPCE section 2.2.5.3.4.1 */
709 if (ndr
->flags
& LIBNDR_FLAG_NDR64
) {
710 return ndr_pull_align(ndr
, size
);
712 return NDR_ERR_SUCCESS
;
718 _PUBLIC_
enum ndr_err_code
ndr_push_bytes(struct ndr_push
*ndr
, const uint8_t *data
, uint32_t n
)
720 NDR_PUSH_NEED_BYTES(ndr
, n
);
721 memcpy(ndr
->data
+ ndr
->offset
, data
, n
);
723 return NDR_ERR_SUCCESS
;
729 _PUBLIC_
enum ndr_err_code
ndr_push_zero(struct ndr_push
*ndr
, uint32_t n
)
731 NDR_PUSH_NEED_BYTES(ndr
, n
);
732 memset(ndr
->data
+ ndr
->offset
, 0, n
);
734 return NDR_ERR_SUCCESS
;
738 push an array of uint8
740 _PUBLIC_
enum ndr_err_code
ndr_push_array_uint8(struct ndr_push
*ndr
, int ndr_flags
, const uint8_t *data
, uint32_t n
)
742 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
743 if (!(ndr_flags
& NDR_SCALARS
)) {
744 return NDR_ERR_SUCCESS
;
746 return ndr_push_bytes(ndr
, data
, n
);
750 push a unique non-zero value if a pointer is non-NULL, otherwise 0
752 _PUBLIC_
enum ndr_err_code
ndr_push_unique_ptr(struct ndr_push
*ndr
, const void *p
)
756 ptr
= ndr
->ptr_count
* 4;
760 return ndr_push_uint3264(ndr
, NDR_SCALARS
, ptr
);
764 push a 'simple' full non-zero value if a pointer is non-NULL, otherwise 0
766 _PUBLIC_
enum ndr_err_code
ndr_push_full_ptr(struct ndr_push
*ndr
, const void *p
)
770 /* Check if the pointer already exists and has an id */
771 ptr
= ndr_token_peek(&ndr
->full_ptr_list
, p
);
774 ptr
= ndr
->ptr_count
;
775 ndr_token_store(ndr
, &ndr
->full_ptr_list
, p
, ptr
);
778 return ndr_push_uint3264(ndr
, NDR_SCALARS
, ptr
);
782 push always a 0, if a pointer is NULL it's a fatal error
784 _PUBLIC_
enum ndr_err_code
ndr_push_ref_ptr(struct ndr_push
*ndr
)
786 return ndr_push_uint3264(ndr
, NDR_SCALARS
, 0xAEF1AEF1);
793 _PUBLIC_
enum ndr_err_code
ndr_push_NTTIME(struct ndr_push
*ndr
, int ndr_flags
, NTTIME t
)
795 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
796 NDR_CHECK(ndr_push_udlong(ndr
, ndr_flags
, t
));
797 return NDR_ERR_SUCCESS
;
803 _PUBLIC_
enum ndr_err_code
ndr_pull_NTTIME(struct ndr_pull
*ndr
, int ndr_flags
, NTTIME
*t
)
805 NDR_PULL_CHECK_FLAGS(ndr
, ndr_flags
);
806 NDR_CHECK(ndr_pull_udlong(ndr
, ndr_flags
, t
));
807 return NDR_ERR_SUCCESS
;
813 _PUBLIC_
enum ndr_err_code
ndr_push_NTTIME_1sec(struct ndr_push
*ndr
, int ndr_flags
, NTTIME t
)
815 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
817 NDR_CHECK(ndr_push_hyper(ndr
, ndr_flags
, t
));
818 return NDR_ERR_SUCCESS
;
824 _PUBLIC_
enum ndr_err_code
ndr_pull_NTTIME_1sec(struct ndr_pull
*ndr
, int ndr_flags
, NTTIME
*t
)
826 NDR_PULL_CHECK_FLAGS(ndr
, ndr_flags
);
827 NDR_CHECK(ndr_pull_hyper(ndr
, ndr_flags
, t
));
829 return NDR_ERR_SUCCESS
;
835 _PUBLIC_
enum ndr_err_code
ndr_pull_NTTIME_hyper(struct ndr_pull
*ndr
, int ndr_flags
, NTTIME
*t
)
837 NDR_PULL_CHECK_FLAGS(ndr
, ndr_flags
);
838 NDR_CHECK(ndr_pull_hyper(ndr
, ndr_flags
, t
));
839 return NDR_ERR_SUCCESS
;
845 _PUBLIC_
enum ndr_err_code
ndr_push_NTTIME_hyper(struct ndr_push
*ndr
, int ndr_flags
, NTTIME t
)
847 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
848 NDR_CHECK(ndr_push_hyper(ndr
, ndr_flags
, t
));
849 return NDR_ERR_SUCCESS
;
855 _PUBLIC_
enum ndr_err_code
ndr_push_time_t(struct ndr_push
*ndr
, int ndr_flags
, time_t t
)
857 return ndr_push_uint32(ndr
, ndr_flags
, t
);
863 _PUBLIC_
enum ndr_err_code
ndr_pull_time_t(struct ndr_pull
*ndr
, int ndr_flags
, time_t *t
)
866 NDR_CHECK(ndr_pull_uint32(ndr
, ndr_flags
, &tt
));
868 return NDR_ERR_SUCCESS
;
875 _PUBLIC_
enum ndr_err_code
ndr_push_uid_t(struct ndr_push
*ndr
, int ndr_flags
, uid_t u
)
877 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
878 return ndr_push_hyper(ndr
, NDR_SCALARS
, (uint64_t)u
);
884 _PUBLIC_
enum ndr_err_code
ndr_pull_uid_t(struct ndr_pull
*ndr
, int ndr_flags
, uid_t
*u
)
887 NDR_CHECK(ndr_pull_hyper(ndr
, ndr_flags
, &uu
));
889 if (unlikely(uu
!= *u
)) {
890 DEBUG(0,(__location__
": uid_t pull doesn't fit 0x%016llx\n",
891 (unsigned long long)uu
));
892 return NDR_ERR_NDR64
;
894 return NDR_ERR_SUCCESS
;
901 _PUBLIC_
enum ndr_err_code
ndr_push_gid_t(struct ndr_push
*ndr
, int ndr_flags
, gid_t g
)
903 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
904 return ndr_push_hyper(ndr
, NDR_SCALARS
, (uint64_t)g
);
910 _PUBLIC_
enum ndr_err_code
ndr_pull_gid_t(struct ndr_pull
*ndr
, int ndr_flags
, gid_t
*g
)
913 NDR_CHECK(ndr_pull_hyper(ndr
, ndr_flags
, &gg
));
915 if (unlikely(gg
!= *g
)) {
916 DEBUG(0,(__location__
": gid_t pull doesn't fit 0x%016llx\n",
917 (unsigned long long)gg
));
918 return NDR_ERR_NDR64
;
920 return NDR_ERR_SUCCESS
;
927 _PUBLIC_
enum ndr_err_code
ndr_pull_ipv4address(struct ndr_pull
*ndr
, int ndr_flags
, const char **address
)
931 NDR_CHECK(ndr_pull_uint32(ndr
, ndr_flags
, &addr
));
932 in
.s_addr
= htonl(addr
);
933 *address
= talloc_strdup(ndr
->current_mem_ctx
, inet_ntoa(in
));
934 NDR_ERR_HAVE_NO_MEMORY(*address
);
935 return NDR_ERR_SUCCESS
;
941 _PUBLIC_
enum ndr_err_code
ndr_push_ipv4address(struct ndr_push
*ndr
, int ndr_flags
, const char *address
)
944 if (!is_ipaddress(address
)) {
945 return ndr_push_error(ndr
, NDR_ERR_IPV4ADDRESS
,
946 "Invalid IPv4 address: '%s'",
949 addr
= inet_addr(address
);
950 NDR_CHECK(ndr_push_uint32(ndr
, ndr_flags
, htonl(addr
)));
951 return NDR_ERR_SUCCESS
;
957 _PUBLIC_
void ndr_print_ipv4address(struct ndr_print
*ndr
, const char *name
,
960 ndr
->print(ndr
, "%-25s: %s", name
, address
);
966 #define IPV6_BYTES 16
967 #define IPV6_ADDR_STR_LEN 39
968 _PUBLIC_
enum ndr_err_code
ndr_pull_ipv6address(struct ndr_pull
*ndr
, int ndr_flags
, const char **address
)
970 uint8_t addr
[IPV6_BYTES
];
971 char *addr_str
= talloc_strdup(ndr
->current_mem_ctx
, "");
973 NDR_CHECK(ndr_pull_array_uint8(ndr
, ndr_flags
, addr
, IPV6_BYTES
));
974 for (i
= 0; i
< IPV6_BYTES
; ++i
) {
975 addr_str
= talloc_asprintf_append(addr_str
, "%02x", addr
[i
]);
976 /* We need a ':' every second byte but the last one */
977 if (i
%2 == 1 && i
!= (IPV6_BYTES
- 1)) {
978 addr_str
= talloc_strdup_append(addr_str
, ":");
982 NDR_ERR_HAVE_NO_MEMORY(*address
);
983 return NDR_ERR_SUCCESS
;
989 _PUBLIC_
enum ndr_err_code
ndr_push_ipv6address(struct ndr_push
*ndr
, int ndr_flags
, const char *address
)
992 uint8_t addr
[IPV6_BYTES
];
995 if (!is_ipaddress(address
)) {
996 return ndr_push_error(ndr
, NDR_ERR_IPV6ADDRESS
,
997 "Invalid IPv6 address: '%s'",
1000 ret
= inet_pton(AF_INET6
, address
, addr
);
1002 return NDR_ERR_IPV6ADDRESS
;
1005 NDR_CHECK(ndr_push_array_uint8(ndr
, ndr_flags
, addr
, IPV6_BYTES
));
1007 return NDR_ERR_SUCCESS
;
1009 return NDR_ERR_IPV6ADDRESS
;
1016 _PUBLIC_
void ndr_print_ipv6address(struct ndr_print
*ndr
, const char *name
,
1017 const char *address
)
1019 ndr
->print(ndr
, "%-25s: %s", name
, address
);
1023 _PUBLIC_
void ndr_print_struct(struct ndr_print
*ndr
, const char *name
, const char *type
)
1025 ndr
->print(ndr
, "%s: struct %s", name
, type
);
1028 _PUBLIC_
void ndr_print_null(struct ndr_print
*ndr
)
1030 ndr
->print(ndr
, "UNEXPECTED NULL POINTER");
1033 _PUBLIC_
void ndr_print_enum(struct ndr_print
*ndr
, const char *name
, const char *type
,
1034 const char *val
, uint32_t value
)
1036 if (ndr
->flags
& LIBNDR_PRINT_ARRAY_HEX
) {
1037 ndr
->print(ndr
, "%-25s: %s (0x%X)", name
, val
?val
:"UNKNOWN_ENUM_VALUE", value
);
1039 ndr
->print(ndr
, "%-25s: %s (%d)", name
, val
?val
:"UNKNOWN_ENUM_VALUE", value
);
1043 _PUBLIC_
void ndr_print_bitmap_flag(struct ndr_print
*ndr
, size_t size
, const char *flag_name
, uint32_t flag
, uint32_t value
)
1049 /* this is an attempt to support multi-bit bitmap masks */
1052 while (!(flag
& 1)) {
1057 ndr
->print(ndr
, " %d: %-25s", value
, flag_name
);
1059 ndr
->print(ndr
, "0x%02x: %-25s (%d)", value
, flag_name
, value
);
1063 _PUBLIC_
void ndr_print_int8(struct ndr_print
*ndr
, const char *name
, int8_t v
)
1065 ndr
->print(ndr
, "%-25s: %d", name
, v
);
1068 _PUBLIC_
void ndr_print_uint8(struct ndr_print
*ndr
, const char *name
, uint8_t v
)
1070 ndr
->print(ndr
, "%-25s: 0x%02x (%u)", name
, v
, v
);
1073 _PUBLIC_
void ndr_print_int16(struct ndr_print
*ndr
, const char *name
, int16_t v
)
1075 ndr
->print(ndr
, "%-25s: %d", name
, v
);
1078 _PUBLIC_
void ndr_print_uint16(struct ndr_print
*ndr
, const char *name
, uint16_t v
)
1080 ndr
->print(ndr
, "%-25s: 0x%04x (%u)", name
, v
, v
);
1083 _PUBLIC_
void ndr_print_int32(struct ndr_print
*ndr
, const char *name
, int32_t v
)
1085 ndr
->print(ndr
, "%-25s: %d", name
, v
);
1088 _PUBLIC_
void ndr_print_uint32(struct ndr_print
*ndr
, const char *name
, uint32_t v
)
1090 ndr
->print(ndr
, "%-25s: 0x%08x (%u)", name
, v
, v
);
1093 _PUBLIC_
void ndr_print_int3264(struct ndr_print
*ndr
, const char *name
, int32_t v
)
1095 ndr
->print(ndr
, "%-25s: %d", name
, v
);
1098 _PUBLIC_
void ndr_print_uint3264(struct ndr_print
*ndr
, const char *name
, uint32_t v
)
1100 ndr
->print(ndr
, "%-25s: 0x%08x (%u)", name
, v
, v
);
1103 _PUBLIC_
void ndr_print_udlong(struct ndr_print
*ndr
, const char *name
, uint64_t v
)
1105 ndr
->print(ndr
, "%-25s: 0x%016llx (%llu)", name
, (unsigned long long)v
, (unsigned long long)v
);
1108 _PUBLIC_
void ndr_print_udlongr(struct ndr_print
*ndr
, const char *name
, uint64_t v
)
1110 ndr_print_udlong(ndr
, name
, v
);
1113 _PUBLIC_
void ndr_print_dlong(struct ndr_print
*ndr
, const char *name
, int64_t v
)
1115 ndr
->print(ndr
, "%-25s: 0x%016llx (%lld)", name
, (unsigned long long)v
, (long long)v
);
1118 _PUBLIC_
void ndr_print_double(struct ndr_print
*ndr
, const char *name
, double v
)
1120 ndr
->print(ndr
, "%-25s: %f", name
, v
);
1123 _PUBLIC_
void ndr_print_hyper(struct ndr_print
*ndr
, const char *name
, uint64_t v
)
1125 ndr_print_dlong(ndr
, name
, v
);
1128 _PUBLIC_
void ndr_print_pointer(struct ndr_print
*ndr
, const char *name
, void *v
)
1130 ndr
->print(ndr
, "%-25s: %p", name
, v
);
1133 _PUBLIC_
void ndr_print_ptr(struct ndr_print
*ndr
, const char *name
, const void *p
)
1136 ndr
->print(ndr
, "%-25s: *", name
);
1138 ndr
->print(ndr
, "%-25s: NULL", name
);
1142 _PUBLIC_
void ndr_print_NTTIME(struct ndr_print
*ndr
, const char *name
, NTTIME t
)
1144 ndr
->print(ndr
, "%-25s: %s", name
, nt_time_string(ndr
, t
));
1147 _PUBLIC_
void ndr_print_NTTIME_1sec(struct ndr_print
*ndr
, const char *name
, NTTIME t
)
1149 /* this is a standard NTTIME here
1150 * as it's already converted in the pull/push code
1152 ndr_print_NTTIME(ndr
, name
, t
);
1155 _PUBLIC_
void ndr_print_NTTIME_hyper(struct ndr_print
*ndr
, const char *name
, NTTIME t
)
1157 ndr_print_NTTIME(ndr
, name
, t
);
1160 _PUBLIC_
void ndr_print_time_t(struct ndr_print
*ndr
, const char *name
, time_t t
)
1162 if (t
== (time_t)-1 || t
== 0) {
1163 ndr
->print(ndr
, "%-25s: (time_t)%d", name
, (int)t
);
1165 ndr
->print(ndr
, "%-25s: %s", name
, timestring(ndr
, t
));
1169 _PUBLIC_
void ndr_print_uid_t(struct ndr_print
*ndr
, const char *name
, uid_t u
)
1171 ndr_print_dlong(ndr
, name
, u
);
1174 _PUBLIC_
void ndr_print_gid_t(struct ndr_print
*ndr
, const char *name
, gid_t g
)
1176 ndr_print_dlong(ndr
, name
, g
);
1179 _PUBLIC_
void ndr_print_union(struct ndr_print
*ndr
, const char *name
, int level
, const char *type
)
1181 if (ndr
->flags
& LIBNDR_PRINT_ARRAY_HEX
) {
1182 ndr
->print(ndr
, "%-25s: union %s(case 0x%X)", name
, type
, level
);
1184 ndr
->print(ndr
, "%-25s: union %s(case %d)", name
, type
, level
);
1188 _PUBLIC_
void ndr_print_bad_level(struct ndr_print
*ndr
, const char *name
, uint16_t level
)
1190 ndr
->print(ndr
, "UNKNOWN LEVEL %u", level
);
1193 _PUBLIC_
void ndr_print_array_uint8(struct ndr_print
*ndr
, const char *name
,
1194 const uint8_t *data
, uint32_t count
)
1197 #define _ONELINE_LIMIT 32
1200 ndr
->print(ndr
, "%s: ARRAY(%d) : NULL", name
, count
);
1204 if (count
<= _ONELINE_LIMIT
&& (ndr
->flags
& LIBNDR_PRINT_ARRAY_HEX
)) {
1205 char s
[(_ONELINE_LIMIT
+ 1) * 2];
1206 for (i
=0;i
<count
;i
++) {
1207 snprintf(&s
[i
*2], 3, "%02x", data
[i
]);
1210 ndr
->print(ndr
, "%-25s: %s", name
, s
);
1214 ndr
->print(ndr
, "%s: ARRAY(%d)", name
, count
);
1215 if (count
> _ONELINE_LIMIT
&& (ndr
->flags
& LIBNDR_PRINT_ARRAY_HEX
)) {
1216 ndr_dump_data(ndr
, data
, count
);
1221 for (i
=0;i
<count
;i
++) {
1223 if (asprintf(&idx
, "[%d]", i
) != -1) {
1224 ndr_print_uint8(ndr
, idx
, data
[i
]);
1229 #undef _ONELINE_LIMIT
1232 static void ndr_print_dump_data_cb(const char *buf
, void *private_data
)
1234 struct ndr_print
*ndr
= (struct ndr_print
*)private_data
;
1236 ndr
->print(ndr
, "%s", buf
);
1240 ndr_print version of dump_data()
1242 static void ndr_dump_data(struct ndr_print
*ndr
, const uint8_t *buf
, int len
)
1244 ndr
->no_newline
= true;
1245 dump_data_cb(buf
, len
, true, ndr_print_dump_data_cb
, ndr
);
1246 ndr
->no_newline
= false;
1250 _PUBLIC_
void ndr_print_DATA_BLOB(struct ndr_print
*ndr
, const char *name
, DATA_BLOB r
)
1252 ndr
->print(ndr
, "%-25s: DATA_BLOB length=%u", name
, (unsigned)r
.length
);
1254 ndr_dump_data(ndr
, r
.data
, r
.length
);
1260 * Push a DATA_BLOB onto the wire.
1261 * 1) When called with LIBNDR_FLAG_ALIGN* alignment flags set, push padding
1262 * bytes _only_. The length is determined by the alignment required and the
1263 * current ndr offset.
1264 * 2) When called with the LIBNDR_FLAG_REMAINING flag, push the byte array to
1266 * 3) Otherwise, push a uint3264 length _and_ a corresponding byte array to the
1269 _PUBLIC_
enum ndr_err_code
ndr_push_DATA_BLOB(struct ndr_push
*ndr
, int ndr_flags
, DATA_BLOB blob
)
1271 if (ndr
->flags
& LIBNDR_FLAG_REMAINING
) {
1273 } else if (ndr
->flags
& (LIBNDR_ALIGN_FLAGS
& ~LIBNDR_FLAG_NOALIGN
)) {
1274 if (ndr
->flags
& LIBNDR_FLAG_ALIGN2
) {
1275 blob
.length
= NDR_ALIGN(ndr
, 2);
1276 } else if (ndr
->flags
& LIBNDR_FLAG_ALIGN4
) {
1277 blob
.length
= NDR_ALIGN(ndr
, 4);
1278 } else if (ndr
->flags
& LIBNDR_FLAG_ALIGN8
) {
1279 blob
.length
= NDR_ALIGN(ndr
, 8);
1281 NDR_PUSH_ALLOC_SIZE(ndr
, blob
.data
, blob
.length
);
1282 data_blob_clear(&blob
);
1284 NDR_CHECK(ndr_push_uint3264(ndr
, NDR_SCALARS
, blob
.length
));
1286 NDR_CHECK(ndr_push_bytes(ndr
, blob
.data
, blob
.length
));
1287 return NDR_ERR_SUCCESS
;
1291 * Pull a DATA_BLOB from the wire.
1292 * 1) when called with LIBNDR_FLAG_ALIGN* alignment flags set, pull padding
1293 * bytes _only_. The length is determined by the alignment required and the
1294 * current ndr offset.
1295 * 2) When called with the LIBNDR_FLAG_REMAINING flag, pull all remaining bytes
1296 * from the ndr buffer.
1297 * 3) Otherwise, pull a uint3264 length _and_ a corresponding byte array from the
1300 _PUBLIC_
enum ndr_err_code
ndr_pull_DATA_BLOB(struct ndr_pull
*ndr
, int ndr_flags
, DATA_BLOB
*blob
)
1302 uint32_t length
= 0;
1304 if (ndr
->flags
& LIBNDR_FLAG_REMAINING
) {
1305 length
= ndr
->data_size
- ndr
->offset
;
1306 } else if (ndr
->flags
& (LIBNDR_ALIGN_FLAGS
& ~LIBNDR_FLAG_NOALIGN
)) {
1307 if (ndr
->flags
& LIBNDR_FLAG_ALIGN2
) {
1308 length
= NDR_ALIGN(ndr
, 2);
1309 } else if (ndr
->flags
& LIBNDR_FLAG_ALIGN4
) {
1310 length
= NDR_ALIGN(ndr
, 4);
1311 } else if (ndr
->flags
& LIBNDR_FLAG_ALIGN8
) {
1312 length
= NDR_ALIGN(ndr
, 8);
1314 if (ndr
->data_size
- ndr
->offset
< length
) {
1315 length
= ndr
->data_size
- ndr
->offset
;
1318 NDR_CHECK(ndr_pull_uint3264(ndr
, NDR_SCALARS
, &length
));
1320 NDR_PULL_NEED_BYTES(ndr
, length
);
1321 *blob
= data_blob_talloc(ndr
->current_mem_ctx
, ndr
->data
+ndr
->offset
, length
);
1322 ndr
->offset
+= length
;
1323 return NDR_ERR_SUCCESS
;
1326 _PUBLIC_
uint32_t ndr_size_DATA_BLOB(int ret
, const DATA_BLOB
*data
, int flags
)
1328 if (!data
) return ret
;
1329 return ret
+ data
->length
;
1332 _PUBLIC_
void ndr_print_bool(struct ndr_print
*ndr
, const char *name
, const bool b
)
1334 ndr
->print(ndr
, "%-25s: %s", name
, b
?"true":"false");
1337 _PUBLIC_ NTSTATUS
ndr_map_error2ntstatus(enum ndr_err_code ndr_err
)
1340 case NDR_ERR_SUCCESS
:
1341 return NT_STATUS_OK
;
1342 case NDR_ERR_BUFSIZE
:
1343 return NT_STATUS_BUFFER_TOO_SMALL
;
1345 return NT_STATUS_INTERNAL_ERROR
;
1347 return NT_STATUS_NO_MEMORY
;
1348 case NDR_ERR_ARRAY_SIZE
:
1349 return NT_STATUS_ARRAY_BOUNDS_EXCEEDED
;
1350 case NDR_ERR_INVALID_POINTER
:
1351 return NT_STATUS_INVALID_PARAMETER_MIX
;
1352 case NDR_ERR_UNREAD_BYTES
:
1353 return NT_STATUS_PORT_MESSAGE_TOO_LONG
;
1358 /* we should map all error codes to different status codes */
1359 return NT_STATUS_INVALID_PARAMETER
;
1362 _PUBLIC_
int ndr_map_error2errno(enum ndr_err_code ndr_err
)
1365 case NDR_ERR_SUCCESS
:
1367 case NDR_ERR_BUFSIZE
:
1373 case NDR_ERR_ARRAY_SIZE
:
1375 case NDR_ERR_INVALID_POINTER
:
1377 case NDR_ERR_UNREAD_BYTES
:
1383 /* we should map all error codes to different status codes */
1387 _PUBLIC_
enum ndr_err_code
ndr_push_timespec(struct ndr_push
*ndr
,
1389 const struct timespec
*t
)
1391 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
1392 NDR_CHECK(ndr_push_hyper(ndr
, ndr_flags
, t
->tv_sec
));
1393 NDR_CHECK(ndr_push_uint32(ndr
, ndr_flags
, t
->tv_nsec
));
1394 return NDR_ERR_SUCCESS
;
1397 _PUBLIC_
enum ndr_err_code
ndr_pull_timespec(struct ndr_pull
*ndr
,
1403 NDR_PULL_CHECK_FLAGS(ndr
, ndr_flags
);
1404 NDR_CHECK(ndr_pull_hyper(ndr
, ndr_flags
, &secs
));
1405 NDR_CHECK(ndr_pull_uint32(ndr
, ndr_flags
, &nsecs
));
1408 return NDR_ERR_SUCCESS
;
1411 _PUBLIC_
void ndr_print_timespec(struct ndr_print
*ndr
, const char *name
,
1412 const struct timespec
*t
)
1414 ndr
->print(ndr
, "%-25s: %s.%ld", name
, timestring(ndr
, t
->tv_sec
),
1418 _PUBLIC_
enum ndr_err_code
ndr_push_timeval(struct ndr_push
*ndr
,
1420 const struct timeval
*t
)
1422 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
1423 NDR_CHECK(ndr_push_hyper(ndr
, ndr_flags
, t
->tv_sec
));
1424 NDR_CHECK(ndr_push_uint32(ndr
, ndr_flags
, t
->tv_usec
));
1425 return NDR_ERR_SUCCESS
;
1428 _PUBLIC_
enum ndr_err_code
ndr_pull_timeval(struct ndr_pull
*ndr
,
1434 NDR_PULL_CHECK_FLAGS(ndr
, ndr_flags
);
1435 NDR_CHECK(ndr_pull_hyper(ndr
, ndr_flags
, &secs
));
1436 NDR_CHECK(ndr_pull_uint32(ndr
, ndr_flags
, &usecs
));
1439 return NDR_ERR_SUCCESS
;
1442 _PUBLIC_
void ndr_print_timeval(struct ndr_print
*ndr
, const char *name
,
1443 const struct timeval
*t
)
1445 ndr
->print(ndr
, "%-25s: %s.%ld", name
, timestring(ndr
, t
->tv_sec
),