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
;
331 _PUBLIC_
enum ndr_err_code
ndr_pull_enum_uint8(struct ndr_pull
*ndr
, int ndr_flags
, uint8_t *v
)
333 return ndr_pull_uint8(ndr
, ndr_flags
, v
);
337 parse a uint16_t enum
339 _PUBLIC_
enum ndr_err_code
ndr_pull_enum_uint16(struct ndr_pull
*ndr
, int ndr_flags
, uint16_t *v
)
341 return ndr_pull_uint16(ndr
, ndr_flags
, v
);
345 parse a uint1632_t enum (uint32_t on NDR64)
347 _PUBLIC_
enum ndr_err_code
ndr_pull_enum_uint1632(struct ndr_pull
*ndr
, int ndr_flags
, uint16_t *v
)
349 if (unlikely(ndr
->flags
& LIBNDR_FLAG_NDR64
)) {
351 NDR_CHECK(ndr_pull_uint32(ndr
, ndr_flags
, &v32
));
354 DEBUG(0,(__location__
": non-zero upper 16 bits 0x%08x\n", (unsigned)v32
));
355 return NDR_ERR_NDR64
;
357 return NDR_ERR_SUCCESS
;
359 return ndr_pull_uint16(ndr
, ndr_flags
, v
);
363 parse a uint32_t enum
365 _PUBLIC_
enum ndr_err_code
ndr_pull_enum_uint32(struct ndr_pull
*ndr
, int ndr_flags
, uint32_t *v
)
367 return ndr_pull_uint32(ndr
, ndr_flags
, v
);
373 _PUBLIC_
enum ndr_err_code
ndr_push_enum_uint8(struct ndr_push
*ndr
, int ndr_flags
, uint8_t v
)
375 return ndr_push_uint8(ndr
, ndr_flags
, v
);
381 _PUBLIC_
enum ndr_err_code
ndr_push_enum_uint16(struct ndr_push
*ndr
, int ndr_flags
, uint16_t v
)
383 return ndr_push_uint16(ndr
, ndr_flags
, v
);
389 _PUBLIC_
enum ndr_err_code
ndr_push_enum_uint32(struct ndr_push
*ndr
, int ndr_flags
, uint32_t v
)
391 return ndr_push_uint32(ndr
, ndr_flags
, v
);
395 push a uint1632_t enum
397 _PUBLIC_
enum ndr_err_code
ndr_push_enum_uint1632(struct ndr_push
*ndr
, int ndr_flags
, uint16_t v
)
399 if (unlikely(ndr
->flags
& LIBNDR_FLAG_NDR64
)) {
400 return ndr_push_uint32(ndr
, ndr_flags
, v
);
402 return ndr_push_uint16(ndr
, ndr_flags
, v
);
408 _PUBLIC_
enum ndr_err_code
ndr_push_WERROR(struct ndr_push
*ndr
, int ndr_flags
, WERROR status
)
410 return ndr_push_uint32(ndr
, NDR_SCALARS
, W_ERROR_V(status
));
413 _PUBLIC_
void ndr_print_WERROR(struct ndr_print
*ndr
, const char *name
, WERROR r
)
415 ndr
->print(ndr
, "%-25s: %s", name
, win_errstr(r
));
421 _PUBLIC_
enum ndr_err_code
ndr_pull_bytes(struct ndr_pull
*ndr
, uint8_t *data
, uint32_t n
)
423 NDR_PULL_NEED_BYTES(ndr
, n
);
424 memcpy(data
, ndr
->data
+ ndr
->offset
, n
);
426 return NDR_ERR_SUCCESS
;
430 pull an array of uint8
432 _PUBLIC_
enum ndr_err_code
ndr_pull_array_uint8(struct ndr_pull
*ndr
, int ndr_flags
, uint8_t *data
, uint32_t n
)
434 NDR_PULL_CHECK_FLAGS(ndr
, ndr_flags
);
435 if (!(ndr_flags
& NDR_SCALARS
)) {
436 return NDR_ERR_SUCCESS
;
438 return ndr_pull_bytes(ndr
, data
, n
);
444 _PUBLIC_
enum ndr_err_code
ndr_push_int8(struct ndr_push
*ndr
, int ndr_flags
, int8_t v
)
446 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
447 NDR_PUSH_NEED_BYTES(ndr
, 1);
448 SCVAL(ndr
->data
, ndr
->offset
, (uint8_t)v
);
450 return NDR_ERR_SUCCESS
;
456 _PUBLIC_
enum ndr_err_code
ndr_push_uint8(struct ndr_push
*ndr
, int ndr_flags
, uint8_t v
)
458 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
459 NDR_PUSH_NEED_BYTES(ndr
, 1);
460 SCVAL(ndr
->data
, ndr
->offset
, v
);
462 return NDR_ERR_SUCCESS
;
468 _PUBLIC_
enum ndr_err_code
ndr_push_int16(struct ndr_push
*ndr
, int ndr_flags
, int16_t v
)
470 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
471 NDR_PUSH_ALIGN(ndr
, 2);
472 NDR_PUSH_NEED_BYTES(ndr
, 2);
473 NDR_SSVAL(ndr
, ndr
->offset
, (uint16_t)v
);
475 return NDR_ERR_SUCCESS
;
481 _PUBLIC_
enum ndr_err_code
ndr_push_uint16(struct ndr_push
*ndr
, int ndr_flags
, uint16_t v
)
483 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
484 NDR_PUSH_ALIGN(ndr
, 2);
485 NDR_PUSH_NEED_BYTES(ndr
, 2);
486 NDR_SSVAL(ndr
, ndr
->offset
, v
);
488 return NDR_ERR_SUCCESS
;
494 _PUBLIC_
enum ndr_err_code
ndr_push_uint1632(struct ndr_push
*ndr
, int ndr_flags
, uint16_t v
)
496 if (unlikely(ndr
->flags
& LIBNDR_FLAG_NDR64
)) {
497 return ndr_push_uint32(ndr
, ndr_flags
, v
);
499 return ndr_push_uint16(ndr
, ndr_flags
, v
);
505 _PUBLIC_
enum ndr_err_code
ndr_push_int32(struct ndr_push
*ndr
, int ndr_flags
, int32_t v
)
507 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
508 NDR_PUSH_ALIGN(ndr
, 4);
509 NDR_PUSH_NEED_BYTES(ndr
, 4);
510 NDR_SIVALS(ndr
, ndr
->offset
, v
);
512 return NDR_ERR_SUCCESS
;
518 _PUBLIC_
enum ndr_err_code
ndr_push_uint32(struct ndr_push
*ndr
, int ndr_flags
, uint32_t v
)
520 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
521 NDR_PUSH_ALIGN(ndr
, 4);
522 NDR_PUSH_NEED_BYTES(ndr
, 4);
523 NDR_SIVAL(ndr
, ndr
->offset
, v
);
525 return NDR_ERR_SUCCESS
;
531 _PUBLIC_
enum ndr_err_code
ndr_push_uint3264(struct ndr_push
*ndr
, int ndr_flags
, uint32_t v
)
533 if (unlikely(ndr
->flags
& LIBNDR_FLAG_NDR64
)) {
534 return ndr_push_hyper(ndr
, ndr_flags
, v
);
536 return ndr_push_uint32(ndr
, ndr_flags
, v
);
542 _PUBLIC_
enum ndr_err_code
ndr_push_udlong(struct ndr_push
*ndr
, int ndr_flags
, uint64_t v
)
544 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
545 NDR_PUSH_ALIGN(ndr
, 4);
546 NDR_PUSH_NEED_BYTES(ndr
, 8);
547 NDR_SIVAL(ndr
, ndr
->offset
, (v
& 0xFFFFFFFF));
548 NDR_SIVAL(ndr
, ndr
->offset
+4, (v
>>32));
550 return NDR_ERR_SUCCESS
;
556 _PUBLIC_
enum ndr_err_code
ndr_push_udlongr(struct ndr_push
*ndr
, int ndr_flags
, uint64_t v
)
558 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
559 NDR_PUSH_ALIGN(ndr
, 4);
560 NDR_PUSH_NEED_BYTES(ndr
, 8);
561 NDR_SIVAL(ndr
, ndr
->offset
, (v
>>32));
562 NDR_SIVAL(ndr
, ndr
->offset
+4, (v
& 0xFFFFFFFF));
564 return NDR_ERR_SUCCESS
;
570 _PUBLIC_
enum ndr_err_code
ndr_push_dlong(struct ndr_push
*ndr
, int ndr_flags
, int64_t v
)
572 return ndr_push_udlong(ndr
, NDR_SCALARS
, (uint64_t)v
);
578 _PUBLIC_
enum ndr_err_code
ndr_push_hyper(struct ndr_push
*ndr
, int ndr_flags
, uint64_t v
)
580 NDR_PUSH_ALIGN(ndr
, 8);
582 return ndr_push_udlongr(ndr
, NDR_SCALARS
, v
);
584 return ndr_push_udlong(ndr
, NDR_SCALARS
, v
);
590 _PUBLIC_
enum ndr_err_code
ndr_push_double(struct ndr_push
*ndr
, int ndr_flags
, double v
)
592 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
593 NDR_PUSH_ALIGN(ndr
, 8);
594 NDR_PUSH_NEED_BYTES(ndr
, 8);
595 memcpy(ndr
->data
+ndr
->offset
, &v
, 8);
597 return NDR_ERR_SUCCESS
;
603 _PUBLIC_
enum ndr_err_code
ndr_push_pointer(struct ndr_push
*ndr
, int ndr_flags
, void* v
)
605 uintptr_t h
= (intptr_t)v
;
606 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
607 NDR_PUSH_ALIGN(ndr
, sizeof(h
));
608 NDR_PUSH_NEED_BYTES(ndr
, sizeof(h
));
609 memcpy(ndr
->data
+ndr
->offset
, &h
, sizeof(h
));
610 ndr
->offset
+= sizeof(h
);
611 return NDR_ERR_SUCCESS
;
614 _PUBLIC_
enum ndr_err_code
ndr_push_align(struct ndr_push
*ndr
, size_t size
)
616 /* this is a nasty hack to make pidl work with NDR64 */
618 if (ndr
->flags
& LIBNDR_FLAG_NDR64
) {
623 } else if (size
== 3) {
624 if (ndr
->flags
& LIBNDR_FLAG_NDR64
) {
630 NDR_PUSH_ALIGN(ndr
, size
);
631 return NDR_ERR_SUCCESS
;
634 _PUBLIC_
enum ndr_err_code
ndr_pull_align(struct ndr_pull
*ndr
, size_t size
)
636 /* this is a nasty hack to make pidl work with NDR64 */
638 if (ndr
->flags
& LIBNDR_FLAG_NDR64
) {
643 } else if (size
== 3) {
644 if (ndr
->flags
& LIBNDR_FLAG_NDR64
) {
650 NDR_PULL_ALIGN(ndr
, size
);
651 return NDR_ERR_SUCCESS
;
654 _PUBLIC_
enum ndr_err_code
ndr_push_union_align(struct ndr_push
*ndr
, size_t size
)
656 /* MS-RPCE section 2.2.5.3.4.4 */
657 if (ndr
->flags
& LIBNDR_FLAG_NDR64
) {
658 return ndr_push_align(ndr
, size
);
660 return NDR_ERR_SUCCESS
;
663 _PUBLIC_
enum ndr_err_code
ndr_pull_union_align(struct ndr_pull
*ndr
, size_t size
)
665 /* MS-RPCE section 2.2.5.3.4.4 */
666 if (ndr
->flags
& LIBNDR_FLAG_NDR64
) {
667 return ndr_pull_align(ndr
, size
);
669 return NDR_ERR_SUCCESS
;
672 _PUBLIC_
enum ndr_err_code
ndr_push_trailer_align(struct ndr_push
*ndr
, size_t size
)
674 /* MS-RPCE section 2.2.5.3.4.1 */
675 if (ndr
->flags
& LIBNDR_FLAG_NDR64
) {
676 return ndr_push_align(ndr
, size
);
678 return NDR_ERR_SUCCESS
;
681 _PUBLIC_
enum ndr_err_code
ndr_pull_trailer_align(struct ndr_pull
*ndr
, size_t size
)
683 /* MS-RPCE section 2.2.5.3.4.1 */
684 if (ndr
->flags
& LIBNDR_FLAG_NDR64
) {
685 return ndr_pull_align(ndr
, size
);
687 return NDR_ERR_SUCCESS
;
693 _PUBLIC_
enum ndr_err_code
ndr_push_bytes(struct ndr_push
*ndr
, const uint8_t *data
, uint32_t n
)
695 NDR_PUSH_NEED_BYTES(ndr
, n
);
696 memcpy(ndr
->data
+ ndr
->offset
, data
, n
);
698 return NDR_ERR_SUCCESS
;
704 _PUBLIC_
enum ndr_err_code
ndr_push_zero(struct ndr_push
*ndr
, uint32_t n
)
706 NDR_PUSH_NEED_BYTES(ndr
, n
);
707 memset(ndr
->data
+ ndr
->offset
, 0, n
);
709 return NDR_ERR_SUCCESS
;
713 push an array of uint8
715 _PUBLIC_
enum ndr_err_code
ndr_push_array_uint8(struct ndr_push
*ndr
, int ndr_flags
, const uint8_t *data
, uint32_t n
)
717 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
718 if (!(ndr_flags
& NDR_SCALARS
)) {
719 return NDR_ERR_SUCCESS
;
721 return ndr_push_bytes(ndr
, data
, n
);
725 push a unique non-zero value if a pointer is non-NULL, otherwise 0
727 _PUBLIC_
enum ndr_err_code
ndr_push_unique_ptr(struct ndr_push
*ndr
, const void *p
)
731 ptr
= ndr
->ptr_count
* 4;
735 return ndr_push_uint3264(ndr
, NDR_SCALARS
, ptr
);
739 push a 'simple' full non-zero value if a pointer is non-NULL, otherwise 0
741 _PUBLIC_
enum ndr_err_code
ndr_push_full_ptr(struct ndr_push
*ndr
, const void *p
)
745 /* Check if the pointer already exists and has an id */
746 ptr
= ndr_token_peek(&ndr
->full_ptr_list
, p
);
749 ptr
= ndr
->ptr_count
;
750 ndr_token_store(ndr
, &ndr
->full_ptr_list
, p
, ptr
);
753 return ndr_push_uint3264(ndr
, NDR_SCALARS
, ptr
);
757 push always a 0, if a pointer is NULL it's a fatal error
759 _PUBLIC_
enum ndr_err_code
ndr_push_ref_ptr(struct ndr_push
*ndr
)
761 return ndr_push_uint3264(ndr
, NDR_SCALARS
, 0xAEF1AEF1);
768 _PUBLIC_
enum ndr_err_code
ndr_push_NTTIME(struct ndr_push
*ndr
, int ndr_flags
, NTTIME t
)
770 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
771 NDR_CHECK(ndr_push_udlong(ndr
, ndr_flags
, t
));
772 return NDR_ERR_SUCCESS
;
778 _PUBLIC_
enum ndr_err_code
ndr_pull_NTTIME(struct ndr_pull
*ndr
, int ndr_flags
, NTTIME
*t
)
780 NDR_PULL_CHECK_FLAGS(ndr
, ndr_flags
);
781 NDR_CHECK(ndr_pull_udlong(ndr
, ndr_flags
, t
));
782 return NDR_ERR_SUCCESS
;
788 _PUBLIC_
enum ndr_err_code
ndr_push_NTTIME_1sec(struct ndr_push
*ndr
, int ndr_flags
, NTTIME t
)
790 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
792 NDR_CHECK(ndr_push_hyper(ndr
, ndr_flags
, t
));
793 return NDR_ERR_SUCCESS
;
799 _PUBLIC_
enum ndr_err_code
ndr_pull_NTTIME_1sec(struct ndr_pull
*ndr
, int ndr_flags
, NTTIME
*t
)
801 NDR_PULL_CHECK_FLAGS(ndr
, ndr_flags
);
802 NDR_CHECK(ndr_pull_hyper(ndr
, ndr_flags
, t
));
804 return NDR_ERR_SUCCESS
;
810 _PUBLIC_
enum ndr_err_code
ndr_pull_NTTIME_hyper(struct ndr_pull
*ndr
, int ndr_flags
, NTTIME
*t
)
812 NDR_PULL_CHECK_FLAGS(ndr
, ndr_flags
);
813 NDR_CHECK(ndr_pull_hyper(ndr
, ndr_flags
, t
));
814 return NDR_ERR_SUCCESS
;
820 _PUBLIC_
enum ndr_err_code
ndr_push_NTTIME_hyper(struct ndr_push
*ndr
, int ndr_flags
, NTTIME t
)
822 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
823 NDR_CHECK(ndr_push_hyper(ndr
, ndr_flags
, t
));
824 return NDR_ERR_SUCCESS
;
830 _PUBLIC_
enum ndr_err_code
ndr_push_time_t(struct ndr_push
*ndr
, int ndr_flags
, time_t t
)
832 return ndr_push_uint32(ndr
, ndr_flags
, t
);
838 _PUBLIC_
enum ndr_err_code
ndr_pull_time_t(struct ndr_pull
*ndr
, int ndr_flags
, time_t *t
)
841 NDR_CHECK(ndr_pull_uint32(ndr
, ndr_flags
, &tt
));
843 return NDR_ERR_SUCCESS
;
850 _PUBLIC_
enum ndr_err_code
ndr_push_uid_t(struct ndr_push
*ndr
, int ndr_flags
, uid_t u
)
852 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
853 return ndr_push_hyper(ndr
, NDR_SCALARS
, (uint64_t)u
);
859 _PUBLIC_
enum ndr_err_code
ndr_pull_uid_t(struct ndr_pull
*ndr
, int ndr_flags
, uid_t
*u
)
862 NDR_CHECK(ndr_pull_hyper(ndr
, ndr_flags
, &uu
));
864 if (unlikely(uu
!= *u
)) {
865 DEBUG(0,(__location__
": uid_t pull doesn't fit 0x%016llx\n",
866 (unsigned long long)uu
));
867 return NDR_ERR_NDR64
;
869 return NDR_ERR_SUCCESS
;
876 _PUBLIC_
enum ndr_err_code
ndr_push_gid_t(struct ndr_push
*ndr
, int ndr_flags
, gid_t g
)
878 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
879 return ndr_push_hyper(ndr
, NDR_SCALARS
, (uint64_t)g
);
885 _PUBLIC_
enum ndr_err_code
ndr_pull_gid_t(struct ndr_pull
*ndr
, int ndr_flags
, gid_t
*g
)
888 NDR_CHECK(ndr_pull_hyper(ndr
, ndr_flags
, &gg
));
890 if (unlikely(gg
!= *g
)) {
891 DEBUG(0,(__location__
": gid_t pull doesn't fit 0x%016llx\n",
892 (unsigned long long)gg
));
893 return NDR_ERR_NDR64
;
895 return NDR_ERR_SUCCESS
;
902 _PUBLIC_
enum ndr_err_code
ndr_pull_ipv4address(struct ndr_pull
*ndr
, int ndr_flags
, const char **address
)
906 NDR_CHECK(ndr_pull_uint32(ndr
, ndr_flags
, &addr
));
907 in
.s_addr
= htonl(addr
);
908 *address
= talloc_strdup(ndr
->current_mem_ctx
, inet_ntoa(in
));
909 NDR_ERR_HAVE_NO_MEMORY(*address
);
910 return NDR_ERR_SUCCESS
;
916 _PUBLIC_
enum ndr_err_code
ndr_push_ipv4address(struct ndr_push
*ndr
, int ndr_flags
, const char *address
)
919 if (!is_ipaddress(address
)) {
920 return ndr_push_error(ndr
, NDR_ERR_IPV4ADDRESS
,
921 "Invalid IPv4 address: '%s'",
924 addr
= inet_addr(address
);
925 NDR_CHECK(ndr_push_uint32(ndr
, ndr_flags
, htonl(addr
)));
926 return NDR_ERR_SUCCESS
;
932 _PUBLIC_
void ndr_print_ipv4address(struct ndr_print
*ndr
, const char *name
,
935 ndr
->print(ndr
, "%-25s: %s", name
, address
);
941 #define IPV6_BYTES 16
942 #define IPV6_ADDR_STR_LEN 39
943 _PUBLIC_
enum ndr_err_code
ndr_pull_ipv6address(struct ndr_pull
*ndr
, int ndr_flags
, const char **address
)
945 uint8_t addr
[IPV6_BYTES
];
946 char *addr_str
= talloc_strdup(ndr
->current_mem_ctx
, "");
948 NDR_CHECK(ndr_pull_array_uint8(ndr
, ndr_flags
, addr
, IPV6_BYTES
));
949 for (i
= 0; i
< IPV6_BYTES
; ++i
) {
950 addr_str
= talloc_asprintf_append(addr_str
, "%02x", addr
[i
]);
951 /* We need a ':' every second byte but the last one */
952 if (i
%2 == 1 && i
!= (IPV6_BYTES
- 1)) {
953 addr_str
= talloc_strdup_append(addr_str
, ":");
957 NDR_ERR_HAVE_NO_MEMORY(*address
);
958 return NDR_ERR_SUCCESS
;
964 _PUBLIC_
enum ndr_err_code
ndr_push_ipv6address(struct ndr_push
*ndr
, int ndr_flags
, const char *address
)
967 uint8_t addr
[IPV6_BYTES
];
970 if (!is_ipaddress(address
)) {
971 return ndr_push_error(ndr
, NDR_ERR_IPV6ADDRESS
,
972 "Invalid IPv6 address: '%s'",
975 ret
= inet_pton(AF_INET6
, address
, addr
);
977 return NDR_ERR_IPV6ADDRESS
;
980 NDR_CHECK(ndr_push_array_uint8(ndr
, ndr_flags
, addr
, IPV6_BYTES
));
982 return NDR_ERR_SUCCESS
;
984 return NDR_ERR_IPV6ADDRESS
;
991 _PUBLIC_
void ndr_print_ipv6address(struct ndr_print
*ndr
, const char *name
,
994 ndr
->print(ndr
, "%-25s: %s", name
, address
);
998 _PUBLIC_
void ndr_print_struct(struct ndr_print
*ndr
, const char *name
, const char *type
)
1000 ndr
->print(ndr
, "%s: struct %s", name
, type
);
1003 _PUBLIC_
void ndr_print_null(struct ndr_print
*ndr
)
1005 ndr
->print(ndr
, "UNEXPECTED NULL POINTER");
1008 _PUBLIC_
void ndr_print_enum(struct ndr_print
*ndr
, const char *name
, const char *type
,
1009 const char *val
, uint32_t value
)
1011 if (ndr
->flags
& LIBNDR_PRINT_ARRAY_HEX
) {
1012 ndr
->print(ndr
, "%-25s: %s (0x%X)", name
, val
?val
:"UNKNOWN_ENUM_VALUE", value
);
1014 ndr
->print(ndr
, "%-25s: %s (%d)", name
, val
?val
:"UNKNOWN_ENUM_VALUE", value
);
1018 _PUBLIC_
void ndr_print_bitmap_flag(struct ndr_print
*ndr
, size_t size
, const char *flag_name
, uint32_t flag
, uint32_t value
)
1024 /* this is an attempt to support multi-bit bitmap masks */
1027 while (!(flag
& 1)) {
1032 ndr
->print(ndr
, " %d: %-25s", value
, flag_name
);
1034 ndr
->print(ndr
, "0x%02x: %-25s (%d)", value
, flag_name
, value
);
1038 _PUBLIC_
void ndr_print_int8(struct ndr_print
*ndr
, const char *name
, int8_t v
)
1040 ndr
->print(ndr
, "%-25s: %d", name
, v
);
1043 _PUBLIC_
void ndr_print_uint8(struct ndr_print
*ndr
, const char *name
, uint8_t v
)
1045 ndr
->print(ndr
, "%-25s: 0x%02x (%u)", name
, v
, v
);
1048 _PUBLIC_
void ndr_print_int16(struct ndr_print
*ndr
, const char *name
, int16_t v
)
1050 ndr
->print(ndr
, "%-25s: %d", name
, v
);
1053 _PUBLIC_
void ndr_print_uint16(struct ndr_print
*ndr
, const char *name
, uint16_t v
)
1055 ndr
->print(ndr
, "%-25s: 0x%04x (%u)", name
, v
, v
);
1058 _PUBLIC_
void ndr_print_int32(struct ndr_print
*ndr
, const char *name
, int32_t v
)
1060 ndr
->print(ndr
, "%-25s: %d", name
, v
);
1063 _PUBLIC_
void ndr_print_uint32(struct ndr_print
*ndr
, const char *name
, uint32_t v
)
1065 ndr
->print(ndr
, "%-25s: 0x%08x (%u)", name
, v
, v
);
1068 _PUBLIC_
void ndr_print_int3264(struct ndr_print
*ndr
, const char *name
, int32_t v
)
1070 ndr
->print(ndr
, "%-25s: %d", name
, v
);
1073 _PUBLIC_
void ndr_print_uint3264(struct ndr_print
*ndr
, const char *name
, uint32_t v
)
1075 ndr
->print(ndr
, "%-25s: 0x%08x (%u)", name
, v
, v
);
1078 _PUBLIC_
void ndr_print_udlong(struct ndr_print
*ndr
, const char *name
, uint64_t v
)
1080 ndr
->print(ndr
, "%-25s: 0x%016llx (%llu)", name
, (unsigned long long)v
, (unsigned long long)v
);
1083 _PUBLIC_
void ndr_print_udlongr(struct ndr_print
*ndr
, const char *name
, uint64_t v
)
1085 ndr_print_udlong(ndr
, name
, v
);
1088 _PUBLIC_
void ndr_print_dlong(struct ndr_print
*ndr
, const char *name
, int64_t v
)
1090 ndr
->print(ndr
, "%-25s: 0x%016llx (%lld)", name
, (unsigned long long)v
, (long long)v
);
1093 _PUBLIC_
void ndr_print_double(struct ndr_print
*ndr
, const char *name
, double v
)
1095 ndr
->print(ndr
, "%-25s: %f", name
, v
);
1098 _PUBLIC_
void ndr_print_hyper(struct ndr_print
*ndr
, const char *name
, uint64_t v
)
1100 ndr_print_dlong(ndr
, name
, v
);
1103 _PUBLIC_
void ndr_print_pointer(struct ndr_print
*ndr
, const char *name
, void *v
)
1105 ndr
->print(ndr
, "%-25s: %p", name
, v
);
1108 _PUBLIC_
void ndr_print_ptr(struct ndr_print
*ndr
, const char *name
, const void *p
)
1111 ndr
->print(ndr
, "%-25s: *", name
);
1113 ndr
->print(ndr
, "%-25s: NULL", name
);
1117 _PUBLIC_
void ndr_print_NTTIME(struct ndr_print
*ndr
, const char *name
, NTTIME t
)
1119 ndr
->print(ndr
, "%-25s: %s", name
, nt_time_string(ndr
, t
));
1122 _PUBLIC_
void ndr_print_NTTIME_1sec(struct ndr_print
*ndr
, const char *name
, NTTIME t
)
1124 /* this is a standard NTTIME here
1125 * as it's already converted in the pull/push code
1127 ndr_print_NTTIME(ndr
, name
, t
);
1130 _PUBLIC_
void ndr_print_NTTIME_hyper(struct ndr_print
*ndr
, const char *name
, NTTIME t
)
1132 ndr_print_NTTIME(ndr
, name
, t
);
1135 _PUBLIC_
void ndr_print_time_t(struct ndr_print
*ndr
, const char *name
, time_t t
)
1137 if (t
== (time_t)-1 || t
== 0) {
1138 ndr
->print(ndr
, "%-25s: (time_t)%d", name
, (int)t
);
1140 ndr
->print(ndr
, "%-25s: %s", name
, timestring(ndr
, t
));
1144 _PUBLIC_
void ndr_print_uid_t(struct ndr_print
*ndr
, const char *name
, uid_t u
)
1146 ndr_print_dlong(ndr
, name
, u
);
1149 _PUBLIC_
void ndr_print_gid_t(struct ndr_print
*ndr
, const char *name
, gid_t g
)
1151 ndr_print_dlong(ndr
, name
, g
);
1154 _PUBLIC_
void ndr_print_union(struct ndr_print
*ndr
, const char *name
, int level
, const char *type
)
1156 if (ndr
->flags
& LIBNDR_PRINT_ARRAY_HEX
) {
1157 ndr
->print(ndr
, "%-25s: union %s(case 0x%X)", name
, type
, level
);
1159 ndr
->print(ndr
, "%-25s: union %s(case %d)", name
, type
, level
);
1163 _PUBLIC_
void ndr_print_bad_level(struct ndr_print
*ndr
, const char *name
, uint16_t level
)
1165 ndr
->print(ndr
, "UNKNOWN LEVEL %u", level
);
1168 _PUBLIC_
void ndr_print_array_uint8(struct ndr_print
*ndr
, const char *name
,
1169 const uint8_t *data
, uint32_t count
)
1172 #define _ONELINE_LIMIT 32
1175 ndr
->print(ndr
, "%s: ARRAY(%d) : NULL", name
, count
);
1179 if (count
<= _ONELINE_LIMIT
&& (ndr
->flags
& LIBNDR_PRINT_ARRAY_HEX
)) {
1180 char s
[(_ONELINE_LIMIT
+ 1) * 2];
1181 for (i
=0;i
<count
;i
++) {
1182 snprintf(&s
[i
*2], 3, "%02x", data
[i
]);
1185 ndr
->print(ndr
, "%-25s: %s", name
, s
);
1189 ndr
->print(ndr
, "%s: ARRAY(%d)", name
, count
);
1190 if (count
> _ONELINE_LIMIT
&& (ndr
->flags
& LIBNDR_PRINT_ARRAY_HEX
)) {
1191 ndr_dump_data(ndr
, data
, count
);
1196 for (i
=0;i
<count
;i
++) {
1198 if (asprintf(&idx
, "[%d]", i
) != -1) {
1199 ndr_print_uint8(ndr
, idx
, data
[i
]);
1204 #undef _ONELINE_LIMIT
1207 static void ndr_print_asc(struct ndr_print
*ndr
, const uint8_t *buf
, int len
)
1211 ndr
->print(ndr
, "%c", isprint(buf
[i
])?buf
[i
]:'.');
1215 ndr_print version of dump_data()
1217 static void ndr_dump_data(struct ndr_print
*ndr
, const uint8_t *buf
, int len
)
1221 ndr
->no_newline
= true;
1224 if (i
%16 == 0 && i
<len
) {
1225 ndr
->print(ndr
, "[%04X] ",i
);
1228 ndr
->print(ndr
, "%02X ",(int)buf
[i
]);
1230 if (i
%8 == 0) ndr
->print(ndr
," ");
1232 ndr_print_asc(ndr
,&buf
[i
-16],8); ndr
->print(ndr
," ");
1233 ndr_print_asc(ndr
,&buf
[i
-8],8); ndr
->print(ndr
, "\n");
1240 ndr
->print(ndr
, " ");
1241 if (n
>8) ndr
->print(ndr
," ");
1242 while (n
--) ndr
->print(ndr
," ");
1244 ndr_print_asc(ndr
,&buf
[i
-(i
%16)],n
); ndr
->print(ndr
, " ");
1246 if (n
>0) ndr_print_asc(ndr
,&buf
[i
-n
],n
);
1247 ndr
->print(ndr
,"\n");
1250 ndr
->no_newline
= false;
1254 _PUBLIC_
void ndr_print_DATA_BLOB(struct ndr_print
*ndr
, const char *name
, DATA_BLOB r
)
1256 ndr
->print(ndr
, "%-25s: DATA_BLOB length=%u", name
, (unsigned)r
.length
);
1258 ndr_dump_data(ndr
, r
.data
, r
.length
);
1264 * Push a DATA_BLOB onto the wire.
1265 * 1) When called with LIBNDR_FLAG_ALIGN* alignment flags set, push padding
1266 * bytes _only_. The length is determined by the alignment required and the
1267 * current ndr offset.
1268 * 2) When called with the LIBNDR_FLAG_REMAINING flag, push the byte array to
1270 * 3) Otherwise, push a uint3264 length _and_ a corresponding byte array to the
1273 _PUBLIC_
enum ndr_err_code
ndr_push_DATA_BLOB(struct ndr_push
*ndr
, int ndr_flags
, DATA_BLOB blob
)
1275 if (ndr
->flags
& LIBNDR_FLAG_REMAINING
) {
1277 } else if (ndr
->flags
& (LIBNDR_ALIGN_FLAGS
& ~LIBNDR_FLAG_NOALIGN
)) {
1278 if (ndr
->flags
& LIBNDR_FLAG_ALIGN2
) {
1279 blob
.length
= NDR_ALIGN(ndr
, 2);
1280 } else if (ndr
->flags
& LIBNDR_FLAG_ALIGN4
) {
1281 blob
.length
= NDR_ALIGN(ndr
, 4);
1282 } else if (ndr
->flags
& LIBNDR_FLAG_ALIGN8
) {
1283 blob
.length
= NDR_ALIGN(ndr
, 8);
1285 NDR_PUSH_ALLOC_SIZE(ndr
, blob
.data
, blob
.length
);
1286 data_blob_clear(&blob
);
1288 NDR_CHECK(ndr_push_uint3264(ndr
, NDR_SCALARS
, blob
.length
));
1290 NDR_CHECK(ndr_push_bytes(ndr
, blob
.data
, blob
.length
));
1291 return NDR_ERR_SUCCESS
;
1295 * Pull a DATA_BLOB from the wire.
1296 * 1) when called with LIBNDR_FLAG_ALIGN* alignment flags set, pull padding
1297 * bytes _only_. The length is determined by the alignment required and the
1298 * current ndr offset.
1299 * 2) When called with the LIBNDR_FLAG_REMAINING flag, pull all remaining bytes
1300 * from the ndr buffer.
1301 * 3) Otherwise, pull a uint3264 length _and_ a corresponding byte array from the
1304 _PUBLIC_
enum ndr_err_code
ndr_pull_DATA_BLOB(struct ndr_pull
*ndr
, int ndr_flags
, DATA_BLOB
*blob
)
1306 uint32_t length
= 0;
1308 if (ndr
->flags
& LIBNDR_FLAG_REMAINING
) {
1309 length
= ndr
->data_size
- ndr
->offset
;
1310 } else if (ndr
->flags
& (LIBNDR_ALIGN_FLAGS
& ~LIBNDR_FLAG_NOALIGN
)) {
1311 if (ndr
->flags
& LIBNDR_FLAG_ALIGN2
) {
1312 length
= NDR_ALIGN(ndr
, 2);
1313 } else if (ndr
->flags
& LIBNDR_FLAG_ALIGN4
) {
1314 length
= NDR_ALIGN(ndr
, 4);
1315 } else if (ndr
->flags
& LIBNDR_FLAG_ALIGN8
) {
1316 length
= NDR_ALIGN(ndr
, 8);
1318 if (ndr
->data_size
- ndr
->offset
< length
) {
1319 length
= ndr
->data_size
- ndr
->offset
;
1322 NDR_CHECK(ndr_pull_uint3264(ndr
, NDR_SCALARS
, &length
));
1324 NDR_PULL_NEED_BYTES(ndr
, length
);
1325 *blob
= data_blob_talloc(ndr
->current_mem_ctx
, ndr
->data
+ndr
->offset
, length
);
1326 ndr
->offset
+= length
;
1327 return NDR_ERR_SUCCESS
;
1330 _PUBLIC_
uint32_t ndr_size_DATA_BLOB(int ret
, const DATA_BLOB
*data
, int flags
)
1332 if (!data
) return ret
;
1333 return ret
+ data
->length
;
1336 _PUBLIC_
void ndr_print_bool(struct ndr_print
*ndr
, const char *name
, const bool b
)
1338 ndr
->print(ndr
, "%-25s: %s", name
, b
?"true":"false");
1341 _PUBLIC_ NTSTATUS
ndr_map_error2ntstatus(enum ndr_err_code ndr_err
)
1344 case NDR_ERR_SUCCESS
:
1345 return NT_STATUS_OK
;
1346 case NDR_ERR_BUFSIZE
:
1347 return NT_STATUS_BUFFER_TOO_SMALL
;
1349 return NT_STATUS_INTERNAL_ERROR
;
1351 return NT_STATUS_NO_MEMORY
;
1352 case NDR_ERR_ARRAY_SIZE
:
1353 return NT_STATUS_ARRAY_BOUNDS_EXCEEDED
;
1354 case NDR_ERR_INVALID_POINTER
:
1355 return NT_STATUS_INVALID_PARAMETER_MIX
;
1356 case NDR_ERR_UNREAD_BYTES
:
1357 return NT_STATUS_PORT_MESSAGE_TOO_LONG
;
1362 /* we should map all error codes to different status codes */
1363 return NT_STATUS_INVALID_PARAMETER
;
1366 _PUBLIC_
int ndr_map_error2errno(enum ndr_err_code ndr_err
)
1369 case NDR_ERR_SUCCESS
:
1371 case NDR_ERR_BUFSIZE
:
1377 case NDR_ERR_ARRAY_SIZE
:
1379 case NDR_ERR_INVALID_POINTER
:
1381 case NDR_ERR_UNREAD_BYTES
:
1387 /* we should map all error codes to different status codes */
1391 _PUBLIC_
enum ndr_err_code
ndr_push_timespec(struct ndr_push
*ndr
,
1393 const struct timespec
*t
)
1395 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
1396 NDR_CHECK(ndr_push_hyper(ndr
, ndr_flags
, t
->tv_sec
));
1397 NDR_CHECK(ndr_push_uint32(ndr
, ndr_flags
, t
->tv_nsec
));
1398 return NDR_ERR_SUCCESS
;
1401 _PUBLIC_
enum ndr_err_code
ndr_pull_timespec(struct ndr_pull
*ndr
,
1407 NDR_PULL_CHECK_FLAGS(ndr
, ndr_flags
);
1408 NDR_CHECK(ndr_pull_hyper(ndr
, ndr_flags
, &secs
));
1409 NDR_CHECK(ndr_pull_uint32(ndr
, ndr_flags
, &nsecs
));
1412 return NDR_ERR_SUCCESS
;
1415 _PUBLIC_
void ndr_print_timespec(struct ndr_print
*ndr
, const char *name
,
1416 const struct timespec
*t
)
1418 ndr
->print(ndr
, "%-25s: %s.%ld", name
, timestring(ndr
, t
->tv_sec
),
1422 _PUBLIC_
enum ndr_err_code
ndr_push_timeval(struct ndr_push
*ndr
,
1424 const struct timeval
*t
)
1426 NDR_PUSH_CHECK_FLAGS(ndr
, ndr_flags
);
1427 NDR_CHECK(ndr_push_hyper(ndr
, ndr_flags
, t
->tv_sec
));
1428 NDR_CHECK(ndr_push_uint32(ndr
, ndr_flags
, t
->tv_usec
));
1429 return NDR_ERR_SUCCESS
;
1432 _PUBLIC_
enum ndr_err_code
ndr_pull_timeval(struct ndr_pull
*ndr
,
1438 NDR_PULL_CHECK_FLAGS(ndr
, ndr_flags
);
1439 NDR_CHECK(ndr_pull_hyper(ndr
, ndr_flags
, &secs
));
1440 NDR_CHECK(ndr_pull_uint32(ndr
, ndr_flags
, &usecs
));
1443 return NDR_ERR_SUCCESS
;
1446 _PUBLIC_
void ndr_print_timeval(struct ndr_print
*ndr
, const char *name
,
1447 const struct timeval
*t
)
1449 ndr
->print(ndr
, "%-25s: %s.%ld", name
, timestring(ndr
, t
->tv_sec
),