/src/samba/librpc/ndr/ndr_basic.c
Line | Count | Source |
1 | | /* |
2 | | Unix SMB/CIFS implementation. |
3 | | |
4 | | routines for marshalling/unmarshalling basic types |
5 | | |
6 | | Copyright (C) Andrew Tridgell 2003 |
7 | | |
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. |
12 | | |
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. |
17 | | |
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/>. |
20 | | */ |
21 | | |
22 | | #include "replace.h" |
23 | | #include "system/network.h" |
24 | | #include "librpc/ndr/libndr.h" |
25 | | #include "lib/util/util_net.h" |
26 | | #include "lib/util/debug.h" |
27 | | #include "lib/util/util.h" |
28 | | #include "lib/util/bytearray.h" |
29 | | |
30 | | #define NDR_PULL_U16(ndr, ofs) \ |
31 | 79.2M | (NDR_BE(ndr) ? PULL_BE_U16(ndr->data,ofs) : PULL_LE_U16(ndr->data,ofs)) |
32 | | |
33 | | #define NDR_PULL_U32(ndr, ofs) \ |
34 | 251M | (NDR_BE(ndr) ? PULL_BE_U32(ndr->data,ofs) : PULL_LE_U32(ndr->data,ofs)) |
35 | | |
36 | | #define NDR_PULL_I32(ndr, ofs) \ |
37 | 172k | (int32_t)(NDR_BE(ndr) ? PULL_BE_U32(ndr->data,ofs) : PULL_LE_U32(ndr->data,ofs)) |
38 | | |
39 | | #define NDR_PULL_I64(ndr, ofs) \ |
40 | 1.10M | (NDR_BE(ndr) ? PULL_BE_I64((ndr)->data, ofs) : PULL_LE_I64((ndr)->data, ofs)) |
41 | | |
42 | | #define NDR_PUSH_U16(ndr, ofs, v) \ |
43 | 20.7M | do { \ |
44 | 20.7M | if (NDR_BE(ndr)) { \ |
45 | 7.60M | PUSH_BE_U16(ndr->data, ofs, v); \ |
46 | 13.1M | } else { \ |
47 | 13.1M | PUSH_LE_U16(ndr->data, ofs, v); \ |
48 | 13.1M | } \ |
49 | 20.7M | } while (0) |
50 | | |
51 | | #define NDR_PUSH_U32(ndr, ofs, v) \ |
52 | 113M | do { \ |
53 | 113M | if (NDR_BE(ndr)) { \ |
54 | 6.21M | PUSH_BE_U32(ndr->data, ofs, v); \ |
55 | 107M | } else { \ |
56 | 107M | PUSH_LE_U32(ndr->data, ofs, v); \ |
57 | 107M | } \ |
58 | 113M | } while (0) |
59 | | |
60 | | #define NDR_PUSH_I32(ndr, ofs, v) \ |
61 | 3.34k | do { \ |
62 | 3.34k | if (NDR_BE(ndr)) { \ |
63 | 266 | PUSH_BE_U32(ndr->data, ofs, v); \ |
64 | 3.07k | } else { \ |
65 | 3.07k | PUSH_LE_U32(ndr->data, ofs, v); \ |
66 | 3.07k | } \ |
67 | 3.34k | } while (0) |
68 | | |
69 | | #define NDR_PUSH_I64(ndr, ofs, v) \ |
70 | 660k | do { \ |
71 | 660k | if (NDR_BE(ndr)) { \ |
72 | 1.10k | PUSH_BE_I64((ndr)->data, ofs, v); \ |
73 | 659k | } else { \ |
74 | 659k | PUSH_LE_I64((ndr)->data, ofs, v); \ |
75 | 659k | } \ |
76 | 660k | } while (0) |
77 | | |
78 | | static void ndr_dump_data(struct ndr_print *ndr, const uint8_t *buf, int len); |
79 | | |
80 | | /* |
81 | | check for data leaks from the server by looking for non-zero pad bytes |
82 | | these could also indicate that real structure elements have been |
83 | | mistaken for padding in the IDL |
84 | | */ |
85 | | _PUBLIC_ void ndr_check_padding(struct ndr_pull *ndr, size_t n) |
86 | 0 | { |
87 | 0 | size_t ofs2 = (ndr->offset + (n-1)) & ~(n-1); |
88 | 0 | size_t i; |
89 | 0 | for (i=ndr->offset;i<ofs2;i++) { |
90 | 0 | if (ndr->data[i] != 0) { |
91 | 0 | break; |
92 | 0 | } |
93 | 0 | } |
94 | 0 | if (i<ofs2) { |
95 | 0 | DEBUG(0,("WARNING: Non-zero padding to %zu: ", n)); |
96 | 0 | for (i=ndr->offset;i<ofs2;i++) { |
97 | 0 | DEBUG(0,("%02x ", ndr->data[i])); |
98 | 0 | } |
99 | 0 | DEBUG(0,("\n")); |
100 | 0 | } |
101 | |
|
102 | 0 | } |
103 | | |
104 | | /* |
105 | | parse a int8_t |
106 | | */ |
107 | | _PUBLIC_ enum ndr_err_code ndr_pull_int8(struct ndr_pull *ndr, ndr_flags_type ndr_flags, int8_t *v) |
108 | 3.51M | { |
109 | 3.51M | NDR_PULL_CHECK_FLAGS(ndr, ndr_flags); |
110 | 3.51M | NDR_PULL_NEED_BYTES(ndr, 1); |
111 | 3.51M | *v = (int8_t)PULL_BE_U8(ndr->data, ndr->offset); |
112 | 3.51M | ndr->offset += 1; |
113 | 3.51M | return NDR_ERR_SUCCESS; |
114 | 3.51M | } |
115 | | |
116 | | /* |
117 | | parse a uint8_t |
118 | | */ |
119 | | _PUBLIC_ enum ndr_err_code ndr_pull_uint8(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint8_t *v) |
120 | 15.6M | { |
121 | 15.6M | NDR_PULL_CHECK_FLAGS(ndr, ndr_flags); |
122 | 15.6M | NDR_PULL_NEED_BYTES(ndr, 1); |
123 | 15.6M | *v = PULL_BE_U8(ndr->data, ndr->offset); |
124 | 15.6M | ndr->offset += 1; |
125 | 15.6M | return NDR_ERR_SUCCESS; |
126 | 15.6M | } |
127 | | |
128 | | /* |
129 | | parse a int16_t |
130 | | */ |
131 | | _PUBLIC_ enum ndr_err_code ndr_pull_int16(struct ndr_pull *ndr, ndr_flags_type ndr_flags, int16_t *v) |
132 | 3.23k | { |
133 | 3.23k | NDR_PULL_CHECK_FLAGS(ndr, ndr_flags); |
134 | 3.23k | NDR_PULL_ALIGN(ndr, 2); |
135 | 3.23k | NDR_PULL_NEED_BYTES(ndr, 2); |
136 | 3.17k | *v = (uint16_t)NDR_PULL_U16(ndr, ndr->offset); |
137 | 3.17k | ndr->offset += 2; |
138 | 3.17k | return NDR_ERR_SUCCESS; |
139 | 3.23k | } |
140 | | |
141 | | /* |
142 | | parse a uint16_t |
143 | | */ |
144 | | _PUBLIC_ enum ndr_err_code ndr_pull_uint16(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint16_t *v) |
145 | 79.3M | { |
146 | 79.3M | NDR_PULL_CHECK_FLAGS(ndr, ndr_flags); |
147 | 79.3M | NDR_PULL_ALIGN(ndr, 2); |
148 | 79.3M | NDR_PULL_NEED_BYTES(ndr, 2); |
149 | 79.2M | *v = NDR_PULL_U16(ndr, ndr->offset); |
150 | 79.2M | ndr->offset += 2; |
151 | 79.2M | return NDR_ERR_SUCCESS; |
152 | 79.3M | } |
153 | | |
154 | | /* |
155 | | parse a uint1632_t |
156 | | */ |
157 | | _PUBLIC_ enum ndr_err_code ndr_pull_uint1632(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint16_t *v) |
158 | 3.29M | { |
159 | 3.29M | NDR_PULL_CHECK_FLAGS(ndr, ndr_flags); |
160 | 3.29M | if (unlikely(ndr->flags & LIBNDR_FLAG_NDR64)) { |
161 | 0 | uint32_t v32 = 0; |
162 | 0 | enum ndr_err_code err = ndr_pull_uint32(ndr, ndr_flags, &v32); |
163 | 0 | *v = v32; |
164 | 0 | if (unlikely(v32 != *v)) { |
165 | 0 | DEBUG(0,(__location__ ": non-zero upper 16 bits 0x%08"PRIx32"\n", v32)); |
166 | 0 | return NDR_ERR_NDR64; |
167 | 0 | } |
168 | 0 | return err; |
169 | 0 | } |
170 | 3.29M | return ndr_pull_uint16(ndr, ndr_flags, v); |
171 | 3.29M | } |
172 | | |
173 | | /* |
174 | | parse a int32_t |
175 | | */ |
176 | | _PUBLIC_ enum ndr_err_code ndr_pull_int32(struct ndr_pull *ndr, ndr_flags_type ndr_flags, int32_t *v) |
177 | 173k | { |
178 | 173k | NDR_PULL_CHECK_FLAGS(ndr, ndr_flags); |
179 | 173k | NDR_PULL_ALIGN(ndr, 4); |
180 | 173k | NDR_PULL_NEED_BYTES(ndr, 4); |
181 | 172k | *v = NDR_PULL_I32(ndr, ndr->offset); |
182 | 172k | ndr->offset += 4; |
183 | 172k | return NDR_ERR_SUCCESS; |
184 | 173k | } |
185 | | |
186 | | /* |
187 | | parse a uint32_t |
188 | | */ |
189 | | _PUBLIC_ enum ndr_err_code ndr_pull_uint32(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint32_t *v) |
190 | 218M | { |
191 | 218M | NDR_PULL_CHECK_FLAGS(ndr, ndr_flags); |
192 | 218M | NDR_PULL_ALIGN(ndr, 4); |
193 | 218M | NDR_PULL_NEED_BYTES(ndr, 4); |
194 | 218M | *v = NDR_PULL_U32(ndr, ndr->offset); |
195 | 218M | ndr->offset += 4; |
196 | 218M | return NDR_ERR_SUCCESS; |
197 | 218M | } |
198 | | |
199 | | /* |
200 | | parse a arch dependent uint32/uint64 |
201 | | */ |
202 | | _PUBLIC_ enum ndr_err_code ndr_pull_uint3264(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint32_t *v) |
203 | 69.7M | { |
204 | 69.7M | uint64_t v64 = 0; |
205 | 69.7M | enum ndr_err_code err; |
206 | 69.7M | NDR_PULL_CHECK_FLAGS(ndr, ndr_flags); |
207 | 69.7M | if (likely(!(ndr->flags & LIBNDR_FLAG_NDR64))) { |
208 | 69.7M | return ndr_pull_uint32(ndr, ndr_flags, v); |
209 | 69.7M | } |
210 | 0 | err = ndr_pull_hyper(ndr, ndr_flags, &v64); |
211 | 0 | if (!NDR_ERR_CODE_IS_SUCCESS(err)) { |
212 | 0 | return err; |
213 | 0 | } |
214 | 0 | *v = (uint32_t)v64; |
215 | 0 | if (unlikely(v64 != *v)) { |
216 | 0 | DEBUG(0,(__location__ ": non-zero upper 32 bits 0x%016"PRIx64"\n", |
217 | 0 | v64)); |
218 | 0 | return ndr_pull_error(ndr, NDR_ERR_NDR64, __location__ ": non-zero upper 32 bits 0x%016"PRIx64"\n", |
219 | 0 | v64); |
220 | 0 | } |
221 | 0 | return err; |
222 | 0 | } |
223 | | |
224 | | /* |
225 | | parse a double |
226 | | */ |
227 | | _PUBLIC_ enum ndr_err_code ndr_pull_double(struct ndr_pull *ndr, ndr_flags_type ndr_flags, double *v) |
228 | 0 | { |
229 | 0 | NDR_PULL_CHECK_FLAGS(ndr, ndr_flags); |
230 | 0 | NDR_PULL_ALIGN(ndr, 8); |
231 | 0 | NDR_PULL_NEED_BYTES(ndr, 8); |
232 | 0 | memcpy(v, ndr->data+ndr->offset, 8); |
233 | 0 | ndr->offset += 8; |
234 | 0 | return NDR_ERR_SUCCESS; |
235 | 0 | } |
236 | | |
237 | | /* |
238 | | parse a pointer referent identifier stored in 2 bytes |
239 | | */ |
240 | | _PUBLIC_ enum ndr_err_code ndr_pull_relative_ptr_short(struct ndr_pull *ndr, uint16_t *v) |
241 | 1.02M | { |
242 | 1.02M | NDR_CHECK(ndr_pull_uint16(ndr, NDR_SCALARS, v)); |
243 | 1.02M | if (*v != 0) { |
244 | 673k | ndr->ptr_count++; |
245 | 673k | } |
246 | 1.02M | *(v) -= ndr->relative_rap_convert; |
247 | 1.02M | return NDR_ERR_SUCCESS; |
248 | 1.02M | } |
249 | | |
250 | | /* |
251 | | parse a pointer referent identifier |
252 | | */ |
253 | | _PUBLIC_ enum ndr_err_code ndr_pull_generic_ptr(struct ndr_pull *ndr, uint32_t *v) |
254 | 63.7M | { |
255 | 63.7M | NDR_CHECK(ndr_pull_uint3264(ndr, NDR_SCALARS, v)); |
256 | 63.7M | if (*v != 0) { |
257 | 21.6M | ndr->ptr_count++; |
258 | 21.6M | } |
259 | 63.7M | return NDR_ERR_SUCCESS; |
260 | 63.7M | } |
261 | | |
262 | | /* |
263 | | parse a ref pointer referent identifier |
264 | | */ |
265 | | _PUBLIC_ enum ndr_err_code ndr_pull_ref_ptr(struct ndr_pull *ndr, uint32_t *v) |
266 | 839k | { |
267 | 839k | NDR_CHECK(ndr_pull_uint3264(ndr, NDR_SCALARS, v)); |
268 | | /* ref pointers always point to data */ |
269 | 839k | *v = 1; |
270 | 839k | return NDR_ERR_SUCCESS; |
271 | 839k | } |
272 | | |
273 | | /* |
274 | | parse a udlong |
275 | | */ |
276 | | _PUBLIC_ enum ndr_err_code ndr_pull_udlong(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint64_t *v) |
277 | 15.5M | { |
278 | 15.5M | NDR_PULL_CHECK_FLAGS(ndr, ndr_flags); |
279 | 15.5M | NDR_PULL_ALIGN(ndr, 4); |
280 | 15.5M | NDR_PULL_NEED_BYTES(ndr, 8); |
281 | 15.5M | *v = NDR_PULL_U32(ndr, ndr->offset); |
282 | 15.5M | *v |= (uint64_t)(NDR_PULL_U32(ndr, ndr->offset+4)) << 32; |
283 | 15.5M | ndr->offset += 8; |
284 | 15.5M | return NDR_ERR_SUCCESS; |
285 | 15.5M | } |
286 | | |
287 | | /* |
288 | | parse a udlongr |
289 | | */ |
290 | | _PUBLIC_ enum ndr_err_code ndr_pull_udlongr(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint64_t *v) |
291 | 962k | { |
292 | 962k | NDR_PULL_CHECK_FLAGS(ndr, ndr_flags); |
293 | 962k | NDR_PULL_ALIGN(ndr, 4); |
294 | 962k | NDR_PULL_NEED_BYTES(ndr, 8); |
295 | 962k | *v = ((uint64_t)NDR_PULL_U32(ndr, ndr->offset)) << 32; |
296 | 962k | *v |= NDR_PULL_U32(ndr, ndr->offset+4); |
297 | 962k | ndr->offset += 8; |
298 | 962k | return NDR_ERR_SUCCESS; |
299 | 962k | } |
300 | | |
301 | | /* |
302 | | parse a dlong |
303 | | */ |
304 | | _PUBLIC_ enum ndr_err_code ndr_pull_dlong(struct ndr_pull *ndr, ndr_flags_type ndr_flags, int64_t *v) |
305 | 14.3k | { |
306 | 14.3k | return ndr_pull_udlong(ndr, ndr_flags, (uint64_t *)v); |
307 | 14.3k | } |
308 | | |
309 | | /* |
310 | | parse a hyper |
311 | | */ |
312 | | _PUBLIC_ enum ndr_err_code ndr_pull_hyper(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint64_t *v) |
313 | 11.9M | { |
314 | 11.9M | NDR_PULL_ALIGN(ndr, 8); |
315 | 11.9M | if (NDR_BE(ndr)) { |
316 | 105k | return ndr_pull_udlongr(ndr, ndr_flags, v); |
317 | 105k | } |
318 | 11.8M | return ndr_pull_udlong(ndr, ndr_flags, v); |
319 | 11.9M | } |
320 | | |
321 | | /* |
322 | | parse an int64 |
323 | | */ |
324 | | _PUBLIC_ enum ndr_err_code ndr_pull_int64(struct ndr_pull *ndr, ndr_flags_type ndr_flags, int64_t *v) |
325 | 1.10M | { |
326 | 1.10M | NDR_PULL_CHECK_FLAGS(ndr, ndr_flags); |
327 | 1.10M | NDR_PULL_ALIGN(ndr, 8); |
328 | 1.10M | NDR_PULL_NEED_BYTES(ndr, 8); |
329 | 1.10M | *v = NDR_PULL_I64(ndr, ndr->offset); |
330 | 1.10M | ndr->offset += 8; |
331 | 1.10M | return NDR_ERR_SUCCESS; |
332 | 1.10M | } |
333 | | |
334 | | /* |
335 | | parse a pointer |
336 | | */ |
337 | | _PUBLIC_ enum ndr_err_code ndr_pull_pointer(struct ndr_pull *ndr, ndr_flags_type ndr_flags, void* *v) |
338 | 682k | { |
339 | 682k | uintptr_t h; |
340 | 682k | NDR_PULL_CHECK_FLAGS(ndr, ndr_flags); |
341 | 682k | NDR_PULL_ALIGN(ndr, sizeof(h)); |
342 | 682k | NDR_PULL_NEED_BYTES(ndr, sizeof(h)); |
343 | 682k | memcpy(&h, ndr->data+ndr->offset, sizeof(h)); |
344 | 682k | ndr->offset += sizeof(h); |
345 | 682k | *v = (void *)h; |
346 | 682k | return NDR_ERR_SUCCESS; |
347 | 682k | } |
348 | | |
349 | | /* |
350 | | pull a NTSTATUS |
351 | | */ |
352 | | _PUBLIC_ enum ndr_err_code ndr_pull_NTSTATUS(struct ndr_pull *ndr, ndr_flags_type ndr_flags, NTSTATUS *status) |
353 | 439k | { |
354 | 439k | uint32_t v; |
355 | 439k | NDR_PULL_CHECK_FLAGS(ndr, ndr_flags); |
356 | 439k | NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &v)); |
357 | 438k | *status = NT_STATUS(v); |
358 | 438k | return NDR_ERR_SUCCESS; |
359 | 439k | } |
360 | | |
361 | | /* |
362 | | push a NTSTATUS |
363 | | */ |
364 | | _PUBLIC_ enum ndr_err_code ndr_push_NTSTATUS(struct ndr_push *ndr, ndr_flags_type ndr_flags, NTSTATUS status) |
365 | 378k | { |
366 | 378k | return ndr_push_uint32(ndr, ndr_flags, NT_STATUS_V(status)); |
367 | 378k | } |
368 | | |
369 | | _PUBLIC_ void ndr_print_NTSTATUS(struct ndr_print *ndr, const char *name, NTSTATUS r) |
370 | 289k | { |
371 | 289k | ndr->print(ndr, "%-25s: %s", name, nt_errstr(r)); |
372 | 289k | } |
373 | | |
374 | | /* |
375 | | pull a WERROR |
376 | | */ |
377 | | _PUBLIC_ enum ndr_err_code ndr_pull_WERROR(struct ndr_pull *ndr, ndr_flags_type ndr_flags, WERROR *status) |
378 | 28.5M | { |
379 | 28.5M | uint32_t v; |
380 | 28.5M | NDR_PULL_CHECK_FLAGS(ndr, ndr_flags); |
381 | 28.5M | NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &v)); |
382 | 28.5M | *status = W_ERROR(v); |
383 | 28.5M | return NDR_ERR_SUCCESS; |
384 | 28.5M | } |
385 | | |
386 | | /* |
387 | | pull a HRESULT |
388 | | */ |
389 | | _PUBLIC_ enum ndr_err_code ndr_pull_HRESULT(struct ndr_pull *ndr, ndr_flags_type ndr_flags, HRESULT *status) |
390 | 13.9k | { |
391 | 13.9k | uint32_t v; |
392 | 13.9k | NDR_PULL_CHECK_FLAGS(ndr, ndr_flags); |
393 | 13.9k | NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &v)); |
394 | 13.8k | *status = HRES_ERROR(v); |
395 | 13.8k | return NDR_ERR_SUCCESS; |
396 | 13.9k | } |
397 | | |
398 | | /* |
399 | | parse a uint8_t enum |
400 | | */ |
401 | | _PUBLIC_ enum ndr_err_code ndr_pull_enum_uint8(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint8_t *v) |
402 | 1.44M | { |
403 | 1.44M | return ndr_pull_uint8(ndr, ndr_flags, v); |
404 | 1.44M | } |
405 | | |
406 | | /* |
407 | | parse a uint16_t enum |
408 | | */ |
409 | | _PUBLIC_ enum ndr_err_code ndr_pull_enum_uint16(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint16_t *v) |
410 | 9.34M | { |
411 | 9.34M | return ndr_pull_uint16(ndr, ndr_flags, v); |
412 | 9.34M | } |
413 | | |
414 | | /* |
415 | | parse a uint1632_t enum (uint32_t on NDR64) |
416 | | */ |
417 | | _PUBLIC_ enum ndr_err_code ndr_pull_enum_uint1632(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint16_t *v) |
418 | 10.1M | { |
419 | 10.1M | if (unlikely(ndr->flags & LIBNDR_FLAG_NDR64)) { |
420 | 0 | uint32_t v32; |
421 | 0 | NDR_CHECK(ndr_pull_uint32(ndr, ndr_flags, &v32)); |
422 | 0 | *v = v32; |
423 | 0 | if (v32 != *v) { |
424 | 0 | DEBUG(0,(__location__ ": non-zero upper 16 bits 0x%08"PRIx32"\n", v32)); |
425 | 0 | return NDR_ERR_NDR64; |
426 | 0 | } |
427 | 0 | return NDR_ERR_SUCCESS; |
428 | 0 | } |
429 | 10.1M | return ndr_pull_uint16(ndr, ndr_flags, v); |
430 | 10.1M | } |
431 | | |
432 | | /* |
433 | | parse a uint32_t enum |
434 | | */ |
435 | | _PUBLIC_ enum ndr_err_code ndr_pull_enum_uint32(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint32_t *v) |
436 | 11.5M | { |
437 | 11.5M | return ndr_pull_uint32(ndr, ndr_flags, v); |
438 | 11.5M | } |
439 | | |
440 | | /* |
441 | | push a uint8_t enum |
442 | | */ |
443 | | _PUBLIC_ enum ndr_err_code ndr_push_enum_uint8(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint8_t v) |
444 | 677k | { |
445 | 677k | return ndr_push_uint8(ndr, ndr_flags, v); |
446 | 677k | } |
447 | | |
448 | | /* |
449 | | push a uint16_t enum |
450 | | */ |
451 | | _PUBLIC_ enum ndr_err_code ndr_push_enum_uint16(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint16_t v) |
452 | 3.61M | { |
453 | 3.61M | return ndr_push_uint16(ndr, ndr_flags, v); |
454 | 3.61M | } |
455 | | |
456 | | /* |
457 | | push a uint32_t enum |
458 | | */ |
459 | | _PUBLIC_ enum ndr_err_code ndr_push_enum_uint32(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint32_t v) |
460 | 6.27M | { |
461 | 6.27M | return ndr_push_uint32(ndr, ndr_flags, v); |
462 | 6.27M | } |
463 | | |
464 | | /* |
465 | | push a uint1632_t enum |
466 | | */ |
467 | | _PUBLIC_ enum ndr_err_code ndr_push_enum_uint1632(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint16_t v) |
468 | 5.26M | { |
469 | 5.26M | if (unlikely(ndr->flags & LIBNDR_FLAG_NDR64)) { |
470 | 3.64M | return ndr_push_uint32(ndr, ndr_flags, v); |
471 | 3.64M | } |
472 | 1.62M | return ndr_push_uint16(ndr, ndr_flags, v); |
473 | 5.26M | } |
474 | | |
475 | | /* |
476 | | push a WERROR |
477 | | */ |
478 | | _PUBLIC_ enum ndr_err_code ndr_push_WERROR(struct ndr_push *ndr, ndr_flags_type ndr_flags, WERROR status) |
479 | 28.5M | { |
480 | 28.5M | return ndr_push_uint32(ndr, NDR_SCALARS, W_ERROR_V(status)); |
481 | 28.5M | } |
482 | | |
483 | | _PUBLIC_ void ndr_print_WERROR(struct ndr_print *ndr, const char *name, WERROR r) |
484 | 28.5M | { |
485 | 28.5M | ndr->print(ndr, "%-25s: %s", name, win_errstr(r)); |
486 | 28.5M | } |
487 | | |
488 | | /* |
489 | | push a HRESULT |
490 | | */ |
491 | | _PUBLIC_ enum ndr_err_code ndr_push_HRESULT(struct ndr_push *ndr, ndr_flags_type ndr_flags, HRESULT status) |
492 | 5.81k | { |
493 | 5.81k | return ndr_push_uint32(ndr, NDR_SCALARS, HRES_ERROR_V(status)); |
494 | 5.81k | } |
495 | | |
496 | | _PUBLIC_ void ndr_print_HRESULT(struct ndr_print *ndr, const char *name, HRESULT r) |
497 | 5.81k | { |
498 | 5.81k | ndr->print(ndr, "%-25s: %s", name, hresult_errstr(r)); |
499 | 5.81k | } |
500 | | |
501 | | |
502 | | /* |
503 | | parse a set of bytes |
504 | | */ |
505 | | _PUBLIC_ enum ndr_err_code ndr_pull_bytes(struct ndr_pull *ndr, uint8_t *data, uint32_t n) |
506 | 21.4M | { |
507 | 21.4M | NDR_PULL_NEED_BYTES(ndr, n); |
508 | 21.4M | memcpy(data, ndr->data + ndr->offset, n); |
509 | 21.4M | ndr->offset += n; |
510 | 21.4M | return NDR_ERR_SUCCESS; |
511 | 21.4M | } |
512 | | |
513 | | /* |
514 | | pull an array of uint8 |
515 | | */ |
516 | | _PUBLIC_ enum ndr_err_code ndr_pull_array_uint8(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uint8_t *data, uint32_t n) |
517 | 16.3M | { |
518 | 16.3M | NDR_PULL_CHECK_FLAGS(ndr, ndr_flags); |
519 | 16.3M | if (!(ndr_flags & NDR_SCALARS)) { |
520 | 0 | return NDR_ERR_SUCCESS; |
521 | 0 | } |
522 | 16.3M | return ndr_pull_bytes(ndr, data, n); |
523 | 16.3M | } |
524 | | |
525 | | /* |
526 | | push a int8_t |
527 | | */ |
528 | | _PUBLIC_ enum ndr_err_code ndr_push_int8(struct ndr_push *ndr, ndr_flags_type ndr_flags, int8_t v) |
529 | 516k | { |
530 | 516k | NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags); |
531 | 516k | NDR_PUSH_NEED_BYTES(ndr, 1); |
532 | 516k | PUSH_BE_U8(ndr->data, ndr->offset, (uint8_t)v); |
533 | 516k | ndr->offset += 1; |
534 | 516k | return NDR_ERR_SUCCESS; |
535 | 516k | } |
536 | | |
537 | | /* |
538 | | push a uint8_t |
539 | | */ |
540 | | _PUBLIC_ enum ndr_err_code ndr_push_uint8(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint8_t v) |
541 | 25.0M | { |
542 | 25.0M | NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags); |
543 | 25.0M | NDR_PUSH_NEED_BYTES(ndr, 1); |
544 | 25.0M | PUSH_BE_U8(ndr->data, ndr->offset, v); |
545 | 25.0M | ndr->offset += 1; |
546 | 25.0M | return NDR_ERR_SUCCESS; |
547 | 25.0M | } |
548 | | |
549 | | /* |
550 | | push a int16_t |
551 | | */ |
552 | | _PUBLIC_ enum ndr_err_code ndr_push_int16(struct ndr_push *ndr, ndr_flags_type ndr_flags, int16_t v) |
553 | 580 | { |
554 | 580 | NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags); |
555 | 580 | NDR_PUSH_ALIGN(ndr, 2); |
556 | 580 | NDR_PUSH_NEED_BYTES(ndr, 2); |
557 | 580 | NDR_PUSH_U16(ndr, ndr->offset, (uint16_t)v); |
558 | 580 | ndr->offset += 2; |
559 | 580 | return NDR_ERR_SUCCESS; |
560 | 580 | } |
561 | | |
562 | | /* |
563 | | push a uint16_t |
564 | | */ |
565 | | _PUBLIC_ enum ndr_err_code ndr_push_uint16(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint16_t v) |
566 | 20.7M | { |
567 | 20.7M | NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags); |
568 | 20.7M | NDR_PUSH_ALIGN(ndr, 2); |
569 | 20.7M | NDR_PUSH_NEED_BYTES(ndr, 2); |
570 | 20.7M | NDR_PUSH_U16(ndr, ndr->offset, v); |
571 | 20.7M | ndr->offset += 2; |
572 | 20.7M | return NDR_ERR_SUCCESS; |
573 | 20.7M | } |
574 | | |
575 | | /* |
576 | | push a uint1632 |
577 | | */ |
578 | | _PUBLIC_ enum ndr_err_code ndr_push_uint1632(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint16_t v) |
579 | 0 | { |
580 | 0 | if (unlikely(ndr->flags & LIBNDR_FLAG_NDR64)) { |
581 | 0 | return ndr_push_uint32(ndr, ndr_flags, v); |
582 | 0 | } |
583 | 0 | return ndr_push_uint16(ndr, ndr_flags, v); |
584 | 0 | } |
585 | | |
586 | | /* |
587 | | push a int32_t |
588 | | */ |
589 | | _PUBLIC_ enum ndr_err_code ndr_push_int32(struct ndr_push *ndr, ndr_flags_type ndr_flags, int32_t v) |
590 | 3.34k | { |
591 | 3.34k | NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags); |
592 | 3.34k | NDR_PUSH_ALIGN(ndr, 4); |
593 | 3.34k | NDR_PUSH_NEED_BYTES(ndr, 4); |
594 | 3.34k | NDR_PUSH_I32(ndr, ndr->offset, v); |
595 | 3.34k | ndr->offset += 4; |
596 | 3.34k | return NDR_ERR_SUCCESS; |
597 | 3.34k | } |
598 | | |
599 | | /* |
600 | | push a uint32_t |
601 | | */ |
602 | | _PUBLIC_ enum ndr_err_code ndr_push_uint32(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint32_t v) |
603 | 96.8M | { |
604 | 96.8M | NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags); |
605 | 96.8M | NDR_PUSH_ALIGN(ndr, 4); |
606 | 96.8M | NDR_PUSH_NEED_BYTES(ndr, 4); |
607 | 96.8M | NDR_PUSH_U32(ndr, ndr->offset, v); |
608 | 96.8M | ndr->offset += 4; |
609 | 96.8M | return NDR_ERR_SUCCESS; |
610 | 96.8M | } |
611 | | |
612 | | /* |
613 | | push a uint3264 |
614 | | */ |
615 | | _PUBLIC_ enum ndr_err_code ndr_push_uint3264(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint32_t v) |
616 | 7.58M | { |
617 | 7.58M | if (unlikely(ndr->flags & LIBNDR_FLAG_NDR64)) { |
618 | 4.17M | return ndr_push_hyper(ndr, ndr_flags, v); |
619 | 4.17M | } |
620 | 3.40M | return ndr_push_uint32(ndr, ndr_flags, v); |
621 | 7.58M | } |
622 | | |
623 | | /* |
624 | | push a udlong |
625 | | */ |
626 | | _PUBLIC_ enum ndr_err_code ndr_push_udlong(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint64_t v) |
627 | 7.80M | { |
628 | 7.80M | NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags); |
629 | 7.80M | NDR_PUSH_ALIGN(ndr, 4); |
630 | 7.80M | NDR_PUSH_NEED_BYTES(ndr, 8); |
631 | 7.80M | NDR_PUSH_U32(ndr, ndr->offset, (v & 0xFFFFFFFF)); |
632 | 7.80M | NDR_PUSH_U32(ndr, ndr->offset+4, (v>>32)); |
633 | 7.80M | ndr->offset += 8; |
634 | 7.80M | return NDR_ERR_SUCCESS; |
635 | 7.80M | } |
636 | | |
637 | | /* |
638 | | push a udlongr |
639 | | */ |
640 | | _PUBLIC_ enum ndr_err_code ndr_push_udlongr(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint64_t v) |
641 | 383k | { |
642 | 383k | NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags); |
643 | 383k | NDR_PUSH_ALIGN(ndr, 4); |
644 | 383k | NDR_PUSH_NEED_BYTES(ndr, 8); |
645 | 383k | NDR_PUSH_U32(ndr, ndr->offset, (v>>32)); |
646 | 383k | NDR_PUSH_U32(ndr, ndr->offset+4, (v & 0xFFFFFFFF)); |
647 | 383k | ndr->offset += 8; |
648 | 383k | return NDR_ERR_SUCCESS; |
649 | 383k | } |
650 | | |
651 | | /* |
652 | | push a dlong |
653 | | */ |
654 | | _PUBLIC_ enum ndr_err_code ndr_push_dlong(struct ndr_push *ndr, ndr_flags_type ndr_flags, int64_t v) |
655 | 6.42k | { |
656 | 6.42k | return ndr_push_udlong(ndr, NDR_SCALARS, (uint64_t)v); |
657 | 6.42k | } |
658 | | |
659 | | /* |
660 | | push a hyper |
661 | | */ |
662 | | _PUBLIC_ enum ndr_err_code ndr_push_hyper(struct ndr_push *ndr, ndr_flags_type ndr_flags, uint64_t v) |
663 | 7.09M | { |
664 | 7.09M | NDR_PUSH_ALIGN(ndr, 8); |
665 | 7.09M | if (NDR_BE(ndr)) { |
666 | 7.80k | return ndr_push_udlongr(ndr, NDR_SCALARS, v); |
667 | 7.80k | } |
668 | 7.08M | return ndr_push_udlong(ndr, NDR_SCALARS, v); |
669 | 7.09M | } |
670 | | |
671 | | /* |
672 | | push an int64 |
673 | | */ |
674 | | _PUBLIC_ enum ndr_err_code ndr_push_int64(struct ndr_push *ndr, ndr_flags_type ndr_flags, int64_t v) |
675 | 660k | { |
676 | 660k | NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags); |
677 | 660k | NDR_PUSH_ALIGN(ndr, 8); |
678 | 660k | NDR_PUSH_NEED_BYTES(ndr, 8); |
679 | 660k | NDR_PUSH_I64(ndr, ndr->offset, v); |
680 | 660k | ndr->offset += 8; |
681 | 660k | return NDR_ERR_SUCCESS; |
682 | 660k | } |
683 | | |
684 | | /* |
685 | | push a double |
686 | | */ |
687 | | _PUBLIC_ enum ndr_err_code ndr_push_double(struct ndr_push *ndr, ndr_flags_type ndr_flags, double v) |
688 | 0 | { |
689 | 0 | NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags); |
690 | 0 | NDR_PUSH_ALIGN(ndr, 8); |
691 | 0 | NDR_PUSH_NEED_BYTES(ndr, 8); |
692 | 0 | memcpy(ndr->data+ndr->offset, &v, 8); |
693 | 0 | ndr->offset += 8; |
694 | 0 | return NDR_ERR_SUCCESS; |
695 | 0 | } |
696 | | |
697 | | /* |
698 | | push a pointer |
699 | | */ |
700 | | _PUBLIC_ enum ndr_err_code ndr_push_pointer(struct ndr_push *ndr, ndr_flags_type ndr_flags, void* v) |
701 | 136k | { |
702 | 136k | uintptr_t h = (intptr_t)v; |
703 | 136k | NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags); |
704 | 136k | NDR_PUSH_ALIGN(ndr, sizeof(h)); |
705 | 136k | NDR_PUSH_NEED_BYTES(ndr, sizeof(h)); |
706 | 136k | memcpy(ndr->data+ndr->offset, &h, sizeof(h)); |
707 | 136k | ndr->offset += sizeof(h); |
708 | 136k | return NDR_ERR_SUCCESS; |
709 | 136k | } |
710 | | |
711 | | _PUBLIC_ enum ndr_err_code ndr_push_align(struct ndr_push *ndr, size_t size) |
712 | 93.5M | { |
713 | | /* this is a nasty hack to make pidl work with NDR64 */ |
714 | 93.5M | if (size == 5) { |
715 | 14.8M | if (ndr->flags & LIBNDR_FLAG_NDR64) { |
716 | 11.6M | size = 8; |
717 | 11.6M | } else { |
718 | 3.17M | size = 4; |
719 | 3.17M | } |
720 | 78.7M | } else if (size == 3) { |
721 | 275 | if (ndr->flags & LIBNDR_FLAG_NDR64) { |
722 | 112 | size = 4; |
723 | 163 | } else { |
724 | 163 | size = 2; |
725 | 163 | } |
726 | 275 | } |
727 | 93.5M | NDR_PUSH_ALIGN(ndr, size); |
728 | 93.5M | return NDR_ERR_SUCCESS; |
729 | 93.5M | } |
730 | | |
731 | | _PUBLIC_ enum ndr_err_code ndr_pull_align(struct ndr_pull *ndr, size_t size) |
732 | 113M | { |
733 | | /* this is a nasty hack to make pidl work with NDR64 */ |
734 | 113M | if (size == 5) { |
735 | 43.6M | if (ndr->flags & LIBNDR_FLAG_NDR64) { |
736 | 0 | size = 8; |
737 | 43.6M | } else { |
738 | 43.6M | size = 4; |
739 | 43.6M | } |
740 | 70.2M | } else if (size == 3) { |
741 | 233 | if (ndr->flags & LIBNDR_FLAG_NDR64) { |
742 | 0 | size = 4; |
743 | 233 | } else { |
744 | 233 | size = 2; |
745 | 233 | } |
746 | 233 | } |
747 | 113M | NDR_PULL_ALIGN(ndr, size); |
748 | 113M | return NDR_ERR_SUCCESS; |
749 | 113M | } |
750 | | |
751 | | _PUBLIC_ enum ndr_err_code ndr_push_union_align(struct ndr_push *ndr, size_t size) |
752 | 577M | { |
753 | | /* MS-RPCE section 2.2.5.3.4.4 */ |
754 | 577M | if (ndr->flags & LIBNDR_FLAG_NDR64) { |
755 | 3.02M | return ndr_push_align(ndr, size); |
756 | 3.02M | } |
757 | 574M | return NDR_ERR_SUCCESS; |
758 | 577M | } |
759 | | |
760 | | _PUBLIC_ enum ndr_err_code ndr_pull_union_align(struct ndr_pull *ndr, size_t size) |
761 | 270M | { |
762 | | /* MS-RPCE section 2.2.5.3.4.4 */ |
763 | 270M | if (ndr->flags & LIBNDR_FLAG_NDR64) { |
764 | 0 | return ndr_pull_align(ndr, size); |
765 | 0 | } |
766 | 270M | return NDR_ERR_SUCCESS; |
767 | 270M | } |
768 | | |
769 | | _PUBLIC_ enum ndr_err_code ndr_push_trailer_align(struct ndr_push *ndr, size_t size) |
770 | 51.8M | { |
771 | | /* MS-RPCE section 2.2.5.3.4.1 */ |
772 | 51.8M | if (ndr->flags & LIBNDR_FLAG_NDR64) { |
773 | 34.9M | return ndr_push_align(ndr, size); |
774 | 34.9M | } |
775 | 16.9M | return NDR_ERR_SUCCESS; |
776 | 51.8M | } |
777 | | |
778 | | _PUBLIC_ enum ndr_err_code ndr_pull_trailer_align(struct ndr_pull *ndr, size_t size) |
779 | 106M | { |
780 | | /* MS-RPCE section 2.2.5.3.4.1 */ |
781 | 106M | if (ndr->flags & LIBNDR_FLAG_NDR64) { |
782 | 0 | return ndr_pull_align(ndr, size); |
783 | 0 | } |
784 | 106M | return NDR_ERR_SUCCESS; |
785 | 106M | } |
786 | | |
787 | | /* |
788 | | push some bytes |
789 | | */ |
790 | | _PUBLIC_ enum ndr_err_code ndr_push_bytes(struct ndr_push *ndr, const uint8_t *data, uint32_t n) |
791 | 588M | { |
792 | 588M | if (unlikely(n == 0)) { |
793 | 575M | return NDR_ERR_SUCCESS; |
794 | 575M | } |
795 | 12.9M | if (unlikely(data == NULL)) { |
796 | 0 | return NDR_ERR_INVALID_POINTER; |
797 | 0 | } |
798 | 12.9M | NDR_PUSH_NEED_BYTES(ndr, n); |
799 | 12.9M | memcpy(ndr->data + ndr->offset, data, n); |
800 | 12.9M | ndr->offset += n; |
801 | 12.9M | return NDR_ERR_SUCCESS; |
802 | 12.9M | } |
803 | | |
804 | | /* |
805 | | push some zero bytes |
806 | | */ |
807 | | _PUBLIC_ enum ndr_err_code ndr_push_zero(struct ndr_push *ndr, uint32_t n) |
808 | 248k | { |
809 | 248k | NDR_PUSH_NEED_BYTES(ndr, n); |
810 | 248k | memset(ndr->data + ndr->offset, 0, n); |
811 | 248k | ndr->offset += n; |
812 | 248k | return NDR_ERR_SUCCESS; |
813 | 248k | } |
814 | | |
815 | | /* |
816 | | push an array of uint8 |
817 | | */ |
818 | | _PUBLIC_ enum ndr_err_code ndr_push_array_uint8(struct ndr_push *ndr, ndr_flags_type ndr_flags, const uint8_t *data, uint32_t n) |
819 | 4.41M | { |
820 | 4.41M | NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags); |
821 | 4.41M | if (!(ndr_flags & NDR_SCALARS)) { |
822 | 0 | return NDR_ERR_SUCCESS; |
823 | 0 | } |
824 | 4.41M | return ndr_push_bytes(ndr, data, n); |
825 | 4.41M | } |
826 | | |
827 | | /* |
828 | | push a unique non-zero value if a pointer is non-NULL, otherwise 0 |
829 | | */ |
830 | | _PUBLIC_ enum ndr_err_code ndr_push_unique_ptr(struct ndr_push *ndr, const void *p) |
831 | 5.28M | { |
832 | 5.28M | uint32_t ptr = 0; |
833 | 5.28M | if (p) { |
834 | 613k | ptr = ndr->ptr_count * 4; |
835 | 613k | ptr |= 0x00020000; |
836 | 613k | ndr->ptr_count++; |
837 | 613k | } |
838 | 5.28M | return ndr_push_uint3264(ndr, NDR_SCALARS, ptr); |
839 | 5.28M | } |
840 | | |
841 | | /* |
842 | | push a 'simple' full non-zero value if a pointer is non-NULL, otherwise 0 |
843 | | */ |
844 | | _PUBLIC_ enum ndr_err_code ndr_push_full_ptr(struct ndr_push *ndr, const void *p) |
845 | 8.31k | { |
846 | 8.31k | enum ndr_err_code ret = NDR_ERR_SUCCESS; |
847 | 8.31k | uint32_t ptr = 0; |
848 | 8.31k | if (p) { |
849 | | /* Check if the pointer already exists and has an id */ |
850 | 984 | ret = ndr_token_peek(&ndr->full_ptr_list, p, &ptr); |
851 | 984 | if (ret == NDR_ERR_TOKEN) { |
852 | 984 | ndr->ptr_count++; |
853 | 984 | ptr = ndr->ptr_count; |
854 | 984 | ret = ndr_token_store(ndr, &ndr->full_ptr_list, p, ptr); |
855 | 984 | if (ret != NDR_ERR_SUCCESS) { |
856 | 0 | return ret; |
857 | 0 | } |
858 | 984 | } else if (ret != NDR_ERR_SUCCESS) { |
859 | 0 | return ret; |
860 | 0 | } |
861 | 984 | } |
862 | 8.31k | return ndr_push_uint3264(ndr, NDR_SCALARS, ptr); |
863 | 8.31k | } |
864 | | |
865 | | /* |
866 | | push always a 0, if a pointer is NULL it's a fatal error |
867 | | */ |
868 | | _PUBLIC_ enum ndr_err_code ndr_push_ref_ptr(struct ndr_push *ndr) |
869 | 17.9k | { |
870 | 17.9k | return ndr_push_uint3264(ndr, NDR_SCALARS, 0xAEF1AEF1); |
871 | 17.9k | } |
872 | | |
873 | | |
874 | | /* |
875 | | push a NTTIME |
876 | | */ |
877 | | _PUBLIC_ enum ndr_err_code ndr_push_NTTIME(struct ndr_push *ndr, ndr_flags_type ndr_flags, NTTIME t) |
878 | 474k | { |
879 | 474k | NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags); |
880 | 474k | NDR_CHECK(ndr_push_udlong(ndr, ndr_flags, t)); |
881 | 474k | return NDR_ERR_SUCCESS; |
882 | 474k | } |
883 | | |
884 | | /* |
885 | | pull a NTTIME |
886 | | */ |
887 | | _PUBLIC_ enum ndr_err_code ndr_pull_NTTIME(struct ndr_pull *ndr, ndr_flags_type ndr_flags, NTTIME *t) |
888 | 1.53M | { |
889 | 1.53M | NDR_PULL_CHECK_FLAGS(ndr, ndr_flags); |
890 | 1.53M | NDR_CHECK(ndr_pull_udlong(ndr, ndr_flags, t)); |
891 | 1.53M | return NDR_ERR_SUCCESS; |
892 | 1.53M | } |
893 | | |
894 | | /* |
895 | | push a NTTIME_1sec |
896 | | */ |
897 | | _PUBLIC_ enum ndr_err_code ndr_push_NTTIME_1sec(struct ndr_push *ndr, ndr_flags_type ndr_flags, NTTIME t) |
898 | 8.60k | { |
899 | 8.60k | NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags); |
900 | 8.60k | t /= 10000000; |
901 | 8.60k | NDR_CHECK(ndr_push_hyper(ndr, ndr_flags, t)); |
902 | 8.60k | return NDR_ERR_SUCCESS; |
903 | 8.60k | } |
904 | | |
905 | | /* |
906 | | pull a NTTIME_1sec |
907 | | */ |
908 | | _PUBLIC_ enum ndr_err_code ndr_pull_NTTIME_1sec(struct ndr_pull *ndr, ndr_flags_type ndr_flags, NTTIME *t) |
909 | 122k | { |
910 | 122k | NDR_PULL_CHECK_FLAGS(ndr, ndr_flags); |
911 | 122k | NDR_CHECK(ndr_pull_hyper(ndr, ndr_flags, t)); |
912 | 122k | (*t) *= 10000000; |
913 | 122k | return NDR_ERR_SUCCESS; |
914 | 122k | } |
915 | | |
916 | | /* |
917 | | pull a NTTIME_hyper |
918 | | */ |
919 | | _PUBLIC_ enum ndr_err_code ndr_pull_NTTIME_hyper(struct ndr_pull *ndr, ndr_flags_type ndr_flags, NTTIME *t) |
920 | 123k | { |
921 | 123k | NDR_PULL_CHECK_FLAGS(ndr, ndr_flags); |
922 | 123k | NDR_CHECK(ndr_pull_hyper(ndr, ndr_flags, t)); |
923 | 123k | return NDR_ERR_SUCCESS; |
924 | 123k | } |
925 | | |
926 | | /* |
927 | | push a NTTIME_hyper |
928 | | */ |
929 | | _PUBLIC_ enum ndr_err_code ndr_push_NTTIME_hyper(struct ndr_push *ndr, ndr_flags_type ndr_flags, NTTIME t) |
930 | 6.16k | { |
931 | 6.16k | NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags); |
932 | 6.16k | NDR_CHECK(ndr_push_hyper(ndr, ndr_flags, t)); |
933 | 6.16k | return NDR_ERR_SUCCESS; |
934 | 6.16k | } |
935 | | |
936 | | /* |
937 | | push a time_t |
938 | | */ |
939 | | _PUBLIC_ enum ndr_err_code ndr_push_time_t(struct ndr_push *ndr, ndr_flags_type ndr_flags, time_t t) |
940 | 84.6k | { |
941 | 84.6k | return ndr_push_uint32(ndr, ndr_flags, t); |
942 | 84.6k | } |
943 | | |
944 | | /* |
945 | | pull a time_t |
946 | | */ |
947 | | _PUBLIC_ enum ndr_err_code ndr_pull_time_t(struct ndr_pull *ndr, ndr_flags_type ndr_flags, time_t *t) |
948 | 189k | { |
949 | 189k | uint32_t tt; |
950 | 189k | NDR_CHECK(ndr_pull_uint32(ndr, ndr_flags, &tt)); |
951 | 189k | *t = tt; |
952 | 189k | return NDR_ERR_SUCCESS; |
953 | 189k | } |
954 | | |
955 | | |
956 | | /* |
957 | | push a uid_t |
958 | | */ |
959 | | _PUBLIC_ enum ndr_err_code ndr_push_uid_t(struct ndr_push *ndr, ndr_flags_type ndr_flags, uid_t u) |
960 | 3.18k | { |
961 | 3.18k | NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags); |
962 | 3.18k | return ndr_push_hyper(ndr, NDR_SCALARS, (uint64_t)u); |
963 | 3.18k | } |
964 | | |
965 | | /* |
966 | | pull a uid_t |
967 | | */ |
968 | | _PUBLIC_ enum ndr_err_code ndr_pull_uid_t(struct ndr_pull *ndr, ndr_flags_type ndr_flags, uid_t *u) |
969 | 29.2k | { |
970 | 29.2k | uint64_t uu = 0; |
971 | 29.2k | NDR_CHECK(ndr_pull_hyper(ndr, ndr_flags, &uu)); |
972 | 29.1k | *u = (uid_t)uu; |
973 | 29.1k | if (unlikely(uu != *u)) { |
974 | 461 | DEBUG(0,(__location__ ": uid_t pull doesn't fit 0x%016"PRIx64"\n", |
975 | 461 | uu)); |
976 | 461 | return NDR_ERR_NDR64; |
977 | 461 | } |
978 | 28.6k | return NDR_ERR_SUCCESS; |
979 | 29.1k | } |
980 | | |
981 | | |
982 | | /* |
983 | | push a gid_t |
984 | | */ |
985 | | _PUBLIC_ enum ndr_err_code ndr_push_gid_t(struct ndr_push *ndr, ndr_flags_type ndr_flags, gid_t g) |
986 | 11.4k | { |
987 | 11.4k | NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags); |
988 | 11.4k | return ndr_push_hyper(ndr, NDR_SCALARS, (uint64_t)g); |
989 | 11.4k | } |
990 | | |
991 | | /* |
992 | | pull a gid_t |
993 | | */ |
994 | | _PUBLIC_ enum ndr_err_code ndr_pull_gid_t(struct ndr_pull *ndr, ndr_flags_type ndr_flags, gid_t *g) |
995 | 633k | { |
996 | 633k | uint64_t gg = 0; |
997 | 633k | NDR_CHECK(ndr_pull_hyper(ndr, ndr_flags, &gg)); |
998 | 633k | *g = (gid_t)gg; |
999 | 633k | if (unlikely(gg != *g)) { |
1000 | 378 | DEBUG(0,(__location__ ": gid_t pull doesn't fit 0x%016"PRIx64"\n", |
1001 | 378 | gg)); |
1002 | 378 | return NDR_ERR_NDR64; |
1003 | 378 | } |
1004 | 633k | return NDR_ERR_SUCCESS; |
1005 | 633k | } |
1006 | | |
1007 | | |
1008 | | /* |
1009 | | pull a ipv4address |
1010 | | */ |
1011 | | _PUBLIC_ enum ndr_err_code ndr_pull_ipv4address(struct ndr_pull *ndr, ndr_flags_type ndr_flags, const char **address) |
1012 | 4.69M | { |
1013 | 4.69M | uint32_t addr; |
1014 | 4.69M | struct in_addr in; |
1015 | 4.69M | NDR_CHECK(ndr_pull_uint32(ndr, ndr_flags, &addr)); |
1016 | 4.69M | in.s_addr = htonl(addr); |
1017 | 4.69M | *address = talloc_strdup(ndr->current_mem_ctx, inet_ntoa(in)); |
1018 | 4.69M | NDR_ERR_HAVE_NO_MEMORY(*address); |
1019 | 4.69M | return NDR_ERR_SUCCESS; |
1020 | 4.69M | } |
1021 | | |
1022 | | /* |
1023 | | push a ipv4address |
1024 | | */ |
1025 | | _PUBLIC_ enum ndr_err_code ndr_push_ipv4address(struct ndr_push *ndr, ndr_flags_type ndr_flags, const char *address) |
1026 | 2.90M | { |
1027 | 2.90M | uint32_t addr; |
1028 | 2.90M | if (!is_ipaddress_v4(address)) { |
1029 | 0 | return ndr_push_error(ndr, NDR_ERR_IPV4ADDRESS, |
1030 | 0 | "Invalid IPv4 address: '%s'", |
1031 | 0 | address); |
1032 | 0 | } |
1033 | 2.90M | addr = inet_addr(address); |
1034 | 2.90M | NDR_CHECK(ndr_push_uint32(ndr, ndr_flags, htonl(addr))); |
1035 | 2.90M | return NDR_ERR_SUCCESS; |
1036 | 2.90M | } |
1037 | | |
1038 | | /* |
1039 | | print a ipv4address |
1040 | | */ |
1041 | | _PUBLIC_ void ndr_print_ipv4address(struct ndr_print *ndr, const char *name, |
1042 | | const char *address) |
1043 | 2.51M | { |
1044 | 2.51M | ndr->print(ndr, "%-25s: %s", name, address); |
1045 | 2.51M | } |
1046 | | |
1047 | | /* |
1048 | | pull a ipv6address |
1049 | | */ |
1050 | 19.8M | #define IPV6_BYTES 16 |
1051 | | #define IPV6_ADDR_STR_LEN 39 |
1052 | | _PUBLIC_ enum ndr_err_code ndr_pull_ipv6address(struct ndr_pull *ndr, ndr_flags_type ndr_flags, const char **address) |
1053 | 795k | { |
1054 | 795k | uint8_t addr[IPV6_BYTES]; |
1055 | 795k | char *addr_str = talloc_strdup(ndr->current_mem_ctx, ""); |
1056 | 795k | int i; |
1057 | 795k | NDR_ERR_HAVE_NO_MEMORY(addr_str); |
1058 | 795k | NDR_CHECK(ndr_pull_array_uint8(ndr, ndr_flags, addr, IPV6_BYTES)); |
1059 | 13.5M | for (i = 0; i < IPV6_BYTES; ++i) { |
1060 | 12.7M | addr_str = talloc_asprintf_append(addr_str, "%02x", addr[i]); |
1061 | 12.7M | NDR_ERR_HAVE_NO_MEMORY(addr_str); |
1062 | | /* We need a ':' every second byte but the last one */ |
1063 | 12.7M | if (i%2 == 1 && i != (IPV6_BYTES - 1)) { |
1064 | 5.56M | addr_str = talloc_strdup_append(addr_str, ":"); |
1065 | 5.56M | NDR_ERR_HAVE_NO_MEMORY(addr_str); |
1066 | 5.56M | } |
1067 | 12.7M | } |
1068 | 795k | *address = addr_str; |
1069 | 795k | NDR_ERR_HAVE_NO_MEMORY(*address); |
1070 | 795k | return NDR_ERR_SUCCESS; |
1071 | 795k | } |
1072 | | |
1073 | | /* |
1074 | | push a ipv6address |
1075 | | */ |
1076 | | _PUBLIC_ enum ndr_err_code ndr_push_ipv6address(struct ndr_push *ndr, ndr_flags_type ndr_flags, const char *address) |
1077 | 324k | { |
1078 | 324k | #ifdef AF_INET6 |
1079 | 324k | uint8_t addr[IPV6_BYTES]; |
1080 | 324k | int ret; |
1081 | | |
1082 | 324k | if (!is_ipaddress(address)) { |
1083 | 0 | return ndr_push_error(ndr, NDR_ERR_IPV6ADDRESS, |
1084 | 0 | "Invalid IPv6 address: '%s'", |
1085 | 0 | address); |
1086 | 0 | } |
1087 | 324k | ret = inet_pton(AF_INET6, address, addr); |
1088 | 324k | if (ret <= 0) { |
1089 | 0 | return NDR_ERR_IPV6ADDRESS; |
1090 | 0 | } |
1091 | | |
1092 | 324k | NDR_CHECK(ndr_push_array_uint8(ndr, ndr_flags, addr, IPV6_BYTES)); |
1093 | | |
1094 | 324k | return NDR_ERR_SUCCESS; |
1095 | | #else |
1096 | | return NDR_ERR_IPV6ADDRESS; |
1097 | | #endif |
1098 | 324k | } |
1099 | | |
1100 | | /* |
1101 | | print a ipv6address |
1102 | | */ |
1103 | | _PUBLIC_ void ndr_print_ipv6address(struct ndr_print *ndr, const char *name, |
1104 | | const char *address) |
1105 | 112k | { |
1106 | 112k | ndr->print(ndr, "%-25s: %s", name, address); |
1107 | 112k | } |
1108 | | #undef IPV6_BYTES |
1109 | | |
1110 | | _PUBLIC_ void ndr_print_struct(struct ndr_print *ndr, const char *name, const char *type) |
1111 | 48.6M | { |
1112 | 48.6M | ndr->print(ndr, "%s: struct %s", name, type); |
1113 | 48.6M | } |
1114 | | |
1115 | | _PUBLIC_ void ndr_print_null(struct ndr_print *ndr) |
1116 | 0 | { |
1117 | 0 | ndr->print(ndr, "UNEXPECTED NULL POINTER"); |
1118 | 0 | } |
1119 | | |
1120 | | _PUBLIC_ void ndr_print_enum(struct ndr_print *ndr, const char *name, const char *type, |
1121 | | const char *val, uint32_t value) |
1122 | 14.4M | { |
1123 | 14.4M | if (ndr->flags & LIBNDR_PRINT_ARRAY_HEX) { |
1124 | 9.56M | ndr->print(ndr, "%-25s: %s (0x%"PRIX32")", name, val?val:"UNKNOWN_ENUM_VALUE", value); |
1125 | 9.56M | } else { |
1126 | 4.89M | ndr->print(ndr, "%-25s: %s (%"PRIu32")", name, val?val:"UNKNOWN_ENUM_VALUE", value); |
1127 | 4.89M | } |
1128 | 14.4M | } |
1129 | | |
1130 | | _PUBLIC_ void ndr_print_bitmap_flag(struct ndr_print *ndr, size_t size, const char *flag_name, uint64_t flag, uint64_t value) |
1131 | 16.0M | { |
1132 | 16.0M | if (flag == 0) { |
1133 | 4.62k | return; |
1134 | 4.62k | } |
1135 | | |
1136 | | /* this is an attempt to support multi-bit bitmap masks */ |
1137 | 16.0M | value &= flag; |
1138 | | |
1139 | 149M | while (!(flag & 1)) { |
1140 | 133M | flag >>= 1; |
1141 | 133M | value >>= 1; |
1142 | 133M | } |
1143 | 16.0M | if (flag == 1) { |
1144 | 14.3M | ndr->print(ndr, " %"PRIu64": %-25s", value, flag_name); |
1145 | 14.3M | } else { |
1146 | 1.69M | ndr->print(ndr, "0x%02"PRIx64": %-25s (%"PRIu64")", value, flag_name, value); |
1147 | 1.69M | } |
1148 | 16.0M | } |
1149 | | |
1150 | | _PUBLIC_ void ndr_print_int8(struct ndr_print *ndr, const char *name, int8_t v) |
1151 | 0 | { |
1152 | 0 | if (NDR_HIDE_SECRET(ndr)) { |
1153 | 0 | ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name); |
1154 | 0 | return; |
1155 | 0 | } |
1156 | 0 | ndr->print(ndr, "%-25s: %"PRId8, name, v); |
1157 | 0 | } |
1158 | | |
1159 | | _PUBLIC_ void ndr_print_uint8(struct ndr_print *ndr, const char *name, uint8_t v) |
1160 | 70.2M | { |
1161 | 70.2M | if (NDR_HIDE_SECRET(ndr)) { |
1162 | 0 | ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name); |
1163 | 0 | return; |
1164 | 0 | } |
1165 | 70.2M | ndr->print(ndr, "%-25s: 0x%02"PRIx8" (%"PRIu8")", name, v, v); |
1166 | 70.2M | } |
1167 | | |
1168 | | _PUBLIC_ void ndr_print_int16(struct ndr_print *ndr, const char *name, int16_t v) |
1169 | 580 | { |
1170 | 580 | if (NDR_HIDE_SECRET(ndr)) { |
1171 | 0 | ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name); |
1172 | 0 | return; |
1173 | 0 | } |
1174 | 580 | ndr->print(ndr, "%-25s: %"PRId16, name, v); |
1175 | 580 | } |
1176 | | |
1177 | | _PUBLIC_ void ndr_print_uint16(struct ndr_print *ndr, const char *name, uint16_t v) |
1178 | 9.85M | { |
1179 | 9.85M | if (NDR_HIDE_SECRET(ndr)) { |
1180 | 0 | ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name); |
1181 | 0 | return; |
1182 | 0 | } |
1183 | 9.85M | ndr->print(ndr, "%-25s: 0x%04"PRIx16" (%"PRIu16")", name, v, v); |
1184 | 9.85M | } |
1185 | | |
1186 | | _PUBLIC_ void ndr_print_int32(struct ndr_print *ndr, const char *name, int32_t v) |
1187 | 3.17k | { |
1188 | 3.17k | if (NDR_HIDE_SECRET(ndr)) { |
1189 | 0 | ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name); |
1190 | 0 | return; |
1191 | 0 | } |
1192 | 3.17k | ndr->print(ndr, "%-25s: %"PRId32, name, v); |
1193 | 3.17k | } |
1194 | | |
1195 | | _PUBLIC_ void ndr_print_uint32(struct ndr_print *ndr, const char *name, uint32_t v) |
1196 | 42.5M | { |
1197 | 42.5M | if (NDR_HIDE_SECRET(ndr)) { |
1198 | 0 | ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name); |
1199 | 0 | return; |
1200 | 0 | } |
1201 | 42.5M | ndr->print(ndr, "%-25s: 0x%08"PRIx32" (%"PRIu32")", name, v, v); |
1202 | 42.5M | } |
1203 | | |
1204 | | _PUBLIC_ void ndr_print_int3264(struct ndr_print *ndr, const char *name, int32_t v) |
1205 | 0 | { |
1206 | 0 | if (NDR_HIDE_SECRET(ndr)) { |
1207 | 0 | ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name); |
1208 | 0 | return; |
1209 | 0 | } |
1210 | 0 | ndr->print(ndr, "%-25s: %"PRId32, name, v); |
1211 | 0 | } |
1212 | | |
1213 | | _PUBLIC_ void ndr_print_uint3264(struct ndr_print *ndr, const char *name, uint32_t v) |
1214 | 2.92k | { |
1215 | 2.92k | if (NDR_HIDE_SECRET(ndr)) { |
1216 | 0 | ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name); |
1217 | 0 | return; |
1218 | 0 | } |
1219 | 2.92k | ndr->print(ndr, "%-25s: 0x%08"PRIx32" (%"PRIu32")", name, v, v); |
1220 | 2.92k | } |
1221 | | |
1222 | | _PUBLIC_ void ndr_print_udlong(struct ndr_print *ndr, const char *name, uint64_t v) |
1223 | 539k | { |
1224 | 539k | ndr->print(ndr, "%-25s: 0x%016"PRIx64" (%"PRIu64")", name, v, v); |
1225 | 539k | } |
1226 | | |
1227 | | _PUBLIC_ void ndr_print_udlongr(struct ndr_print *ndr, const char *name, uint64_t v) |
1228 | 304k | { |
1229 | 304k | ndr_print_udlong(ndr, name, v); |
1230 | 304k | } |
1231 | | |
1232 | | _PUBLIC_ void ndr_print_dlong(struct ndr_print *ndr, const char *name, int64_t v) |
1233 | 2.86M | { |
1234 | 2.86M | if (NDR_HIDE_SECRET(ndr)) { |
1235 | 0 | ndr->print(ndr, "%-25s: <REDACTED SECRET VALUE>", name); |
1236 | 0 | return; |
1237 | 0 | } |
1238 | 2.86M | ndr->print(ndr, "%-25s: 0x%016"PRIx64" (%"PRId64")", name, v, v); |
1239 | 2.86M | } |
1240 | | |
1241 | | _PUBLIC_ void ndr_print_double(struct ndr_print *ndr, const char *name, double v) |
1242 | 0 | { |
1243 | 0 | ndr->print(ndr, "%-25s: %f", name, v); |
1244 | 0 | } |
1245 | | |
1246 | | _PUBLIC_ void ndr_print_hyper(struct ndr_print *ndr, const char *name, uint64_t v) |
1247 | 2.69M | { |
1248 | 2.69M | ndr_print_dlong(ndr, name, v); |
1249 | 2.69M | } |
1250 | | |
1251 | | _PUBLIC_ void ndr_print_int64(struct ndr_print *ndr, const char *name, int64_t v) |
1252 | 144k | { |
1253 | 144k | ndr_print_dlong(ndr, name, v); |
1254 | 144k | } |
1255 | | |
1256 | | _PUBLIC_ void ndr_print_pointer(struct ndr_print *ndr, const char *name, void *v) |
1257 | 136k | { |
1258 | 136k | ndr->print(ndr, "%-25s: %p", name, v); |
1259 | 136k | } |
1260 | | |
1261 | | _PUBLIC_ void ndr_print_ptr(struct ndr_print *ndr, const char *name, const void *p) |
1262 | 6.94M | { |
1263 | 6.94M | if (p) { |
1264 | 1.55M | ndr->print(ndr, "%-25s: *", name); |
1265 | 5.38M | } else { |
1266 | 5.38M | ndr->print(ndr, "%-25s: NULL", name); |
1267 | 5.38M | } |
1268 | 6.94M | } |
1269 | | |
1270 | | _PUBLIC_ void ndr_print_NTTIME(struct ndr_print *ndr, const char *name, NTTIME t) |
1271 | 407k | { |
1272 | 407k | ndr->print(ndr, "%-25s: %s", name, nt_time_string(ndr, t)); |
1273 | 407k | } |
1274 | | |
1275 | | _PUBLIC_ void ndr_print_NTTIME_1sec(struct ndr_print *ndr, const char *name, NTTIME t) |
1276 | 5.50k | { |
1277 | | /* this is a standard NTTIME here |
1278 | | * as it's already converted in the pull/push code |
1279 | | */ |
1280 | 5.50k | ndr_print_NTTIME(ndr, name, t); |
1281 | 5.50k | } |
1282 | | |
1283 | | _PUBLIC_ void ndr_print_NTTIME_hyper(struct ndr_print *ndr, const char *name, NTTIME t) |
1284 | 8.03k | { |
1285 | 8.03k | ndr_print_NTTIME(ndr, name, t); |
1286 | 8.03k | } |
1287 | | |
1288 | | _PUBLIC_ void ndr_print_time_t(struct ndr_print *ndr, const char *name, time_t t) |
1289 | 84.6k | { |
1290 | 84.6k | if (t == (time_t)-1 || t == 0) { |
1291 | 77.2k | ndr->print(ndr, "%-25s: (time_t)%" PRIi64, name, (int64_t)t); |
1292 | 77.2k | } else { |
1293 | 7.48k | ndr->print(ndr, "%-25s: %s", name, timestring(ndr, t)); |
1294 | 7.48k | } |
1295 | 84.6k | } |
1296 | | |
1297 | | _PUBLIC_ void ndr_print_uid_t(struct ndr_print *ndr, const char *name, uid_t u) |
1298 | 3.13k | { |
1299 | 3.13k | ndr_print_dlong(ndr, name, u); |
1300 | 3.13k | } |
1301 | | |
1302 | | _PUBLIC_ void ndr_print_gid_t(struct ndr_print *ndr, const char *name, gid_t g) |
1303 | 9.82k | { |
1304 | 9.82k | ndr_print_dlong(ndr, name, g); |
1305 | 9.82k | } |
1306 | | |
1307 | | _PUBLIC_ void ndr_print_union(struct ndr_print *ndr, const char *name, int level, const char *type) |
1308 | 220M | { |
1309 | 220M | if (ndr->flags & LIBNDR_PRINT_ARRAY_HEX) { |
1310 | 143M | ndr->print(ndr, "%-25s: union %s(case 0x%X)", name, type, level); |
1311 | 143M | } else { |
1312 | 77.8M | ndr->print(ndr, "%-25s: union %s(case %d)", name, type, level); |
1313 | 77.8M | } |
1314 | 220M | } |
1315 | | |
1316 | | _PUBLIC_ void ndr_print_bad_level(struct ndr_print *ndr, const char *name, uint16_t level) |
1317 | 0 | { |
1318 | 0 | ndr->print(ndr, "UNKNOWN LEVEL %"PRIu16, level); |
1319 | 0 | } |
1320 | | |
1321 | | _PUBLIC_ void ndr_print_array_uint8(struct ndr_print *ndr, const char *name, |
1322 | | const uint8_t *data, uint32_t count) |
1323 | 1.30M | { |
1324 | 1.30M | uint32_t i; |
1325 | 3.52M | #define _ONELINE_LIMIT 32 |
1326 | | |
1327 | 1.30M | if (data == NULL) { |
1328 | 2.28k | ndr->print(ndr, "%s: ARRAY(%"PRIu32") : NULL", name, count); |
1329 | 2.28k | return; |
1330 | 2.28k | } |
1331 | | |
1332 | 1.30M | if (NDR_HIDE_SECRET(ndr)) { |
1333 | 12.5k | ndr->print(ndr, "%s: ARRAY(%"PRIu32"): <REDACTED SECRET VALUES>", name, count); |
1334 | 12.5k | return; |
1335 | 12.5k | } |
1336 | | |
1337 | 1.29M | if (count <= _ONELINE_LIMIT && (ndr->flags & LIBNDR_PRINT_ARRAY_HEX)) { |
1338 | 822k | char s[(_ONELINE_LIMIT + 1) * 2]; |
1339 | 963k | for (i=0;i<count;i++) { |
1340 | 141k | snprintf(&s[i*2], 3, "%02"PRIx8, data[i]); |
1341 | 141k | } |
1342 | 822k | s[i*2] = 0; |
1343 | 822k | ndr->print(ndr, "%-25s: %s", name, s); |
1344 | 822k | return; |
1345 | 822k | } |
1346 | | |
1347 | 470k | ndr->print(ndr, "%s: ARRAY(%"PRIu32")", name, count); |
1348 | 470k | if (count > _ONELINE_LIMIT && (ndr->flags & LIBNDR_PRINT_ARRAY_HEX)) { |
1349 | 3.29k | ndr_dump_data(ndr, data, count); |
1350 | 3.29k | return; |
1351 | 3.29k | } |
1352 | | |
1353 | 466k | ndr->depth++; |
1354 | 69.7M | for (i=0;i<count;i++) { |
1355 | 69.2M | char *idx=NULL; |
1356 | 69.2M | if (asprintf(&idx, "[%"PRIu32"]", i) != -1) { |
1357 | 69.2M | ndr_print_uint8(ndr, idx, data[i]); |
1358 | 69.2M | free(idx); |
1359 | 69.2M | } |
1360 | 69.2M | } |
1361 | 466k | ndr->depth--; |
1362 | 466k | #undef _ONELINE_LIMIT |
1363 | 466k | } |
1364 | | |
1365 | | static void ndr_print_dump_data_cb(const char *buf, void *private_data) |
1366 | 1.21G | { |
1367 | 1.21G | struct ndr_print *ndr = (struct ndr_print *)private_data; |
1368 | | |
1369 | 1.21G | ndr->print(ndr, "%s", buf); |
1370 | 1.21G | } |
1371 | | |
1372 | | /* |
1373 | | ndr_print version of dump_data() |
1374 | | */ |
1375 | | static void ndr_dump_data(struct ndr_print *ndr, const uint8_t *buf, int len) |
1376 | 794k | { |
1377 | 794k | if (NDR_HIDE_SECRET(ndr)) { |
1378 | 477 | return; |
1379 | 477 | } |
1380 | 793k | ndr->no_newline = true; |
1381 | 793k | dump_data_cb(buf, len, true, ndr_print_dump_data_cb, ndr); |
1382 | 793k | ndr->no_newline = false; |
1383 | 793k | } |
1384 | | |
1385 | | |
1386 | | _PUBLIC_ void ndr_print_DATA_BLOB(struct ndr_print *ndr, const char *name, DATA_BLOB r) |
1387 | 143M | { |
1388 | 143M | ndr->print(ndr, "%-25s: DATA_BLOB length=%zu", name, r.length); |
1389 | 143M | if (r.length) { |
1390 | 791k | ndr_dump_data(ndr, r.data, r.length); |
1391 | 791k | } |
1392 | 143M | } |
1393 | | |
1394 | | |
1395 | | /* |
1396 | | * Push a DATA_BLOB onto the wire. |
1397 | | * 1) When called with LIBNDR_FLAG_ALIGN* alignment flags set, push padding |
1398 | | * bytes _only_. The length is determined by the alignment required and the |
1399 | | * current ndr offset. |
1400 | | * 2) When called with the LIBNDR_FLAG_REMAINING flag, push the byte array to |
1401 | | * the ndr buffer. |
1402 | | * 3) Otherwise, push a uint3264 length _and_ a corresponding byte array to the |
1403 | | * ndr buffer. |
1404 | | */ |
1405 | | _PUBLIC_ enum ndr_err_code ndr_push_DATA_BLOB(struct ndr_push *ndr, ndr_flags_type ndr_flags, DATA_BLOB blob) |
1406 | 564M | { |
1407 | 564M | static const uint8_t padding[8] = { 0, }; |
1408 | | |
1409 | 564M | if (ndr->flags & LIBNDR_FLAG_REMAINING) { |
1410 | | /* nothing to do */ |
1411 | 563M | } else if (ndr->flags & (LIBNDR_ALIGN_FLAGS & ~LIBNDR_FLAG_NOALIGN)) { |
1412 | 716k | blob.data = discard_const_p(uint8_t, padding); |
1413 | 716k | if (ndr->flags & LIBNDR_FLAG_ALIGN2) { |
1414 | 73.6k | blob.length = NDR_ALIGN(ndr, 2); |
1415 | 642k | } else if (ndr->flags & LIBNDR_FLAG_ALIGN4) { |
1416 | 636k | blob.length = NDR_ALIGN(ndr, 4); |
1417 | 636k | } else if (ndr->flags & LIBNDR_FLAG_ALIGN8) { |
1418 | 5.68k | blob.length = NDR_ALIGN(ndr, 8); |
1419 | 5.68k | } else { |
1420 | 0 | return ndr_push_error(ndr, |
1421 | 0 | NDR_ERR_LENGTH, |
1422 | 0 | "Invalid align flags"); |
1423 | 0 | } |
1424 | 838k | } else { |
1425 | 838k | NDR_CHECK(ndr_push_uint3264(ndr, NDR_SCALARS, blob.length)); |
1426 | 838k | } |
1427 | 564M | NDR_CHECK(ndr_push_bytes(ndr, blob.data, blob.length)); |
1428 | 564M | return NDR_ERR_SUCCESS; |
1429 | 564M | } |
1430 | | |
1431 | | /* |
1432 | | * Pull a DATA_BLOB from the wire. |
1433 | | * 1) when called with LIBNDR_FLAG_ALIGN* alignment flags set, pull padding |
1434 | | * bytes _only_. The length is determined by the alignment required and the |
1435 | | * current ndr offset. |
1436 | | * 2) When called with the LIBNDR_FLAG_REMAINING flag, pull all remaining bytes |
1437 | | * from the ndr buffer. |
1438 | | * 3) Otherwise, pull a uint3264 length _and_ a corresponding byte array from the |
1439 | | * ndr buffer. |
1440 | | */ |
1441 | | _PUBLIC_ enum ndr_err_code ndr_pull_DATA_BLOB(struct ndr_pull *ndr, ndr_flags_type ndr_flags, DATA_BLOB *blob) |
1442 | 211M | { |
1443 | 211M | uint32_t length = 0; |
1444 | | |
1445 | 211M | if (ndr->flags & LIBNDR_FLAG_REMAINING) { |
1446 | 208M | length = ndr->data_size - ndr->offset; |
1447 | 208M | } else if (ndr->flags & (LIBNDR_ALIGN_FLAGS & ~LIBNDR_FLAG_NOALIGN)) { |
1448 | 2.17M | if (ndr->flags & LIBNDR_FLAG_ALIGN2) { |
1449 | 327k | length = NDR_ALIGN(ndr, 2); |
1450 | 1.84M | } else if (ndr->flags & LIBNDR_FLAG_ALIGN4) { |
1451 | 1.84M | length = NDR_ALIGN(ndr, 4); |
1452 | 1.84M | } else if (ndr->flags & LIBNDR_FLAG_ALIGN8) { |
1453 | 5.68k | length = NDR_ALIGN(ndr, 8); |
1454 | 5.68k | } |
1455 | 2.17M | if (ndr->data_size - ndr->offset < length) { |
1456 | 5.98k | length = ndr->data_size - ndr->offset; |
1457 | 5.98k | } |
1458 | 2.17M | } else { |
1459 | 1.58M | NDR_CHECK(ndr_pull_uint3264(ndr, NDR_SCALARS, &length)); |
1460 | 1.58M | } |
1461 | 211M | if (length == 0) { |
1462 | | /* skip the talloc for an empty blob */ |
1463 | 210M | blob->data = NULL; |
1464 | 210M | blob->length = 0; |
1465 | 210M | return NDR_ERR_SUCCESS; |
1466 | 210M | } |
1467 | 1.91M | NDR_PULL_NEED_BYTES(ndr, length); |
1468 | 1.91M | *blob = data_blob_talloc(ndr->current_mem_ctx, ndr->data+ndr->offset, length); |
1469 | 1.91M | ndr->offset += length; |
1470 | 1.91M | return NDR_ERR_SUCCESS; |
1471 | 1.91M | } |
1472 | | |
1473 | | _PUBLIC_ uint32_t ndr_size_DATA_BLOB(int ret, const DATA_BLOB *data, ndr_flags_type flags) |
1474 | 119k | { |
1475 | 119k | if (!data) return ret; |
1476 | 9.39k | return ret + data->length; |
1477 | 119k | } |
1478 | | |
1479 | | _PUBLIC_ void ndr_print_bool(struct ndr_print *ndr, const char *name, const bool b) |
1480 | 0 | { |
1481 | 0 | ndr->print(ndr, "%-25s: %s", name, b?"true":"false"); |
1482 | 0 | } |
1483 | | |
1484 | | _PUBLIC_ NTSTATUS ndr_map_error2ntstatus(enum ndr_err_code ndr_err) |
1485 | 658 | { |
1486 | 658 | switch (ndr_err) { |
1487 | 0 | case NDR_ERR_SUCCESS: |
1488 | 0 | return NT_STATUS_OK; |
1489 | 340 | case NDR_ERR_BUFSIZE: |
1490 | 340 | return NT_STATUS_BUFFER_TOO_SMALL; |
1491 | 0 | case NDR_ERR_TOKEN: |
1492 | 0 | return NT_STATUS_INTERNAL_ERROR; |
1493 | 0 | case NDR_ERR_ALLOC: |
1494 | 0 | return NT_STATUS_NO_MEMORY; |
1495 | 0 | case NDR_ERR_ARRAY_SIZE: |
1496 | 0 | return NT_STATUS_ARRAY_BOUNDS_EXCEEDED; |
1497 | 0 | case NDR_ERR_INVALID_POINTER: |
1498 | 0 | return NT_STATUS_INVALID_PARAMETER_MIX; |
1499 | 0 | case NDR_ERR_UNREAD_BYTES: |
1500 | 0 | return NT_STATUS_PORT_MESSAGE_TOO_LONG; |
1501 | 318 | default: |
1502 | 318 | break; |
1503 | 658 | } |
1504 | | |
1505 | | /* we should map all error codes to different status codes */ |
1506 | 318 | return NT_STATUS_INVALID_PARAMETER; |
1507 | 658 | } |
1508 | | |
1509 | | _PUBLIC_ int ndr_map_error2errno(enum ndr_err_code ndr_err) |
1510 | 0 | { |
1511 | 0 | switch (ndr_err) { |
1512 | 0 | case NDR_ERR_SUCCESS: |
1513 | 0 | return 0; |
1514 | 0 | case NDR_ERR_BUFSIZE: |
1515 | 0 | return ENOSPC; |
1516 | 0 | case NDR_ERR_TOKEN: |
1517 | 0 | return EINVAL; |
1518 | 0 | case NDR_ERR_ALLOC: |
1519 | 0 | return ENOMEM; |
1520 | 0 | case NDR_ERR_ARRAY_SIZE: |
1521 | 0 | return EMSGSIZE; |
1522 | 0 | case NDR_ERR_INVALID_POINTER: |
1523 | 0 | return EINVAL; |
1524 | 0 | case NDR_ERR_UNREAD_BYTES: |
1525 | 0 | return EOVERFLOW; |
1526 | 0 | default: |
1527 | 0 | break; |
1528 | 0 | } |
1529 | | |
1530 | | /* we should map all error codes to different status codes */ |
1531 | 0 | return EINVAL; |
1532 | 0 | } |
1533 | | |
1534 | | _PUBLIC_ enum ndr_err_code ndr_push_timespec(struct ndr_push *ndr, |
1535 | | ndr_flags_type ndr_flags, |
1536 | | const struct timespec *t) |
1537 | 64 | { |
1538 | 64 | NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags); |
1539 | 64 | NDR_CHECK(ndr_push_hyper(ndr, ndr_flags, t->tv_sec)); |
1540 | 64 | NDR_CHECK(ndr_push_uint32(ndr, ndr_flags, t->tv_nsec)); |
1541 | 64 | return NDR_ERR_SUCCESS; |
1542 | 64 | } |
1543 | | |
1544 | | _PUBLIC_ enum ndr_err_code ndr_pull_timespec(struct ndr_pull *ndr, |
1545 | | ndr_flags_type ndr_flags, |
1546 | | struct timespec *t) |
1547 | 574 | { |
1548 | 574 | uint64_t secs = 0; |
1549 | 574 | uint32_t nsecs = 0; |
1550 | 574 | NDR_PULL_CHECK_FLAGS(ndr, ndr_flags); |
1551 | 574 | NDR_CHECK(ndr_pull_hyper(ndr, ndr_flags, &secs)); |
1552 | 565 | NDR_CHECK(ndr_pull_uint32(ndr, ndr_flags, &nsecs)); |
1553 | 564 | t->tv_sec = secs; |
1554 | 564 | t->tv_nsec = nsecs; |
1555 | 564 | return NDR_ERR_SUCCESS; |
1556 | 565 | } |
1557 | | |
1558 | | _PUBLIC_ void ndr_print_timespec(struct ndr_print *ndr, const char *name, |
1559 | | const struct timespec *t) |
1560 | 32 | { |
1561 | 32 | char *str = timestring(ndr, t->tv_sec); |
1562 | 32 | ndr->print(ndr, "%-25s: %s.%ld", name, str, t->tv_nsec); |
1563 | 32 | TALLOC_FREE(str); |
1564 | 32 | } |
1565 | | |
1566 | | _PUBLIC_ enum ndr_err_code ndr_push_timeval(struct ndr_push *ndr, |
1567 | | ndr_flags_type ndr_flags, |
1568 | | const struct timeval *t) |
1569 | 78 | { |
1570 | 78 | NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags); |
1571 | 78 | NDR_CHECK(ndr_push_hyper(ndr, ndr_flags, t->tv_sec)); |
1572 | 78 | NDR_CHECK(ndr_push_uint32(ndr, ndr_flags, t->tv_usec)); |
1573 | 78 | return NDR_ERR_SUCCESS; |
1574 | 78 | } |
1575 | | |
1576 | | _PUBLIC_ enum ndr_err_code ndr_pull_timeval(struct ndr_pull *ndr, |
1577 | | ndr_flags_type ndr_flags, |
1578 | | struct timeval *t) |
1579 | 89 | { |
1580 | 89 | uint64_t secs = 0; |
1581 | 89 | uint32_t usecs = 0; |
1582 | 89 | NDR_PULL_CHECK_FLAGS(ndr, ndr_flags); |
1583 | 89 | NDR_CHECK(ndr_pull_hyper(ndr, ndr_flags, &secs)); |
1584 | 86 | NDR_CHECK(ndr_pull_uint32(ndr, ndr_flags, &usecs)); |
1585 | 84 | t->tv_sec = secs; |
1586 | 84 | t->tv_usec = usecs; |
1587 | 84 | return NDR_ERR_SUCCESS; |
1588 | 86 | } |
1589 | | |
1590 | | _PUBLIC_ void ndr_print_timeval(struct ndr_print *ndr, const char *name, |
1591 | | const struct timeval *t) |
1592 | 39 | { |
1593 | 39 | ndr->print(ndr, "%-25s: %s.%ld", name, timestring(ndr, t->tv_sec), |
1594 | 39 | (long)t->tv_usec); |
1595 | 39 | } |
1596 | | |
1597 | | _PUBLIC_ void ndr_print_libndr_flags(struct ndr_print *ndr, const char *name, |
1598 | | libndr_flags flags) |
1599 | 156k | { |
1600 | 156k | ndr->print(ndr, "%-25s: 0x%016"PRI_LIBNDR_FLAGS" (%"PRI_LIBNDR_FLAGS_DECIMAL")", name, flags, flags); |
1601 | 156k | } |