1 | /*
|
---|
2 | * Unix SMB/CIFS implementation.
|
---|
3 | * RPC Pipe client / server routines
|
---|
4 | * Copyright (C) Andrew Tridgell 1992-1997,
|
---|
5 | * Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
|
---|
6 | * Copyright (C) Paul Ashton 1997.
|
---|
7 | * Copyright (C) Gerald (Jerry) Carter 2005
|
---|
8 | *
|
---|
9 | * This program is free software; you can redistribute it and/or modify
|
---|
10 | * it under the terms of the GNU General Public License as published by
|
---|
11 | * the Free Software Foundation; either version 3 of the License, or
|
---|
12 | * (at your option) any later version.
|
---|
13 | *
|
---|
14 | * This program is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
17 | * GNU General Public License for more details.
|
---|
18 | *
|
---|
19 | * You should have received a copy of the GNU General Public License
|
---|
20 | * along with this program; if not, see <http://www.gnu.org/licenses/>.
|
---|
21 | */
|
---|
22 |
|
---|
23 | #include "includes.h"
|
---|
24 |
|
---|
25 | #undef DBGC_CLASS
|
---|
26 | #define DBGC_CLASS DBGC_RPC_PARSE
|
---|
27 |
|
---|
28 | /*******************************************************************
|
---|
29 | Reads or writes a UTIME type.
|
---|
30 | ********************************************************************/
|
---|
31 |
|
---|
32 | static bool smb_io_utime(const char *desc, UTIME *t, prs_struct *ps, int depth)
|
---|
33 | {
|
---|
34 | if (t == NULL)
|
---|
35 | return False;
|
---|
36 |
|
---|
37 | prs_debug(ps, depth, desc, "smb_io_utime");
|
---|
38 | depth++;
|
---|
39 |
|
---|
40 | if(!prs_align(ps))
|
---|
41 | return False;
|
---|
42 |
|
---|
43 | if(!prs_uint32 ("time", ps, depth, &t->time))
|
---|
44 | return False;
|
---|
45 |
|
---|
46 | return True;
|
---|
47 | }
|
---|
48 |
|
---|
49 | /*******************************************************************
|
---|
50 | Reads or writes an NTTIME structure.
|
---|
51 | ********************************************************************/
|
---|
52 |
|
---|
53 | bool smb_io_time(const char *desc, NTTIME *nttime, prs_struct *ps, int depth)
|
---|
54 | {
|
---|
55 | uint32 low, high;
|
---|
56 | if (nttime == NULL)
|
---|
57 | return False;
|
---|
58 |
|
---|
59 | prs_debug(ps, depth, desc, "smb_io_time");
|
---|
60 | depth++;
|
---|
61 |
|
---|
62 | if(!prs_align(ps))
|
---|
63 | return False;
|
---|
64 |
|
---|
65 | if (MARSHALLING(ps)) {
|
---|
66 | low = *nttime & 0xFFFFFFFF;
|
---|
67 | high = *nttime >> 32;
|
---|
68 | }
|
---|
69 |
|
---|
70 | if(!prs_uint32("low ", ps, depth, &low)) /* low part */
|
---|
71 | return False;
|
---|
72 | if(!prs_uint32("high", ps, depth, &high)) /* high part */
|
---|
73 | return False;
|
---|
74 |
|
---|
75 | if (UNMARSHALLING(ps)) {
|
---|
76 | *nttime = (((uint64_t)high << 32) + low);
|
---|
77 | }
|
---|
78 |
|
---|
79 | return True;
|
---|
80 | }
|
---|
81 |
|
---|
82 | /*******************************************************************
|
---|
83 | Reads or writes an NTTIME structure.
|
---|
84 | ********************************************************************/
|
---|
85 |
|
---|
86 | bool smb_io_nttime(const char *desc, prs_struct *ps, int depth, NTTIME *nttime)
|
---|
87 | {
|
---|
88 | return smb_io_time( desc, nttime, ps, depth );
|
---|
89 | }
|
---|
90 |
|
---|
91 | /*******************************************************************
|
---|
92 | Gets an enumeration handle from an ENUM_HND structure.
|
---|
93 | ********************************************************************/
|
---|
94 |
|
---|
95 | uint32 get_enum_hnd(ENUM_HND *enh)
|
---|
96 | {
|
---|
97 | return (enh && enh->ptr_hnd != 0) ? enh->handle : 0;
|
---|
98 | }
|
---|
99 |
|
---|
100 | /*******************************************************************
|
---|
101 | Inits an ENUM_HND structure.
|
---|
102 | ********************************************************************/
|
---|
103 |
|
---|
104 | void init_enum_hnd(ENUM_HND *enh, uint32 hnd)
|
---|
105 | {
|
---|
106 | DEBUG(5,("smb_io_enum_hnd\n"));
|
---|
107 |
|
---|
108 | enh->ptr_hnd = (hnd != 0) ? 1 : 0;
|
---|
109 | enh->handle = hnd;
|
---|
110 | }
|
---|
111 |
|
---|
112 | /*******************************************************************
|
---|
113 | Reads or writes an ENUM_HND structure.
|
---|
114 | ********************************************************************/
|
---|
115 |
|
---|
116 | bool smb_io_enum_hnd(const char *desc, ENUM_HND *hnd, prs_struct *ps, int depth)
|
---|
117 | {
|
---|
118 | if (hnd == NULL)
|
---|
119 | return False;
|
---|
120 |
|
---|
121 | prs_debug(ps, depth, desc, "smb_io_enum_hnd");
|
---|
122 | depth++;
|
---|
123 |
|
---|
124 | if(!prs_align(ps))
|
---|
125 | return False;
|
---|
126 |
|
---|
127 | if(!prs_uint32("ptr_hnd", ps, depth, &hnd->ptr_hnd)) /* pointer */
|
---|
128 | return False;
|
---|
129 |
|
---|
130 | if (hnd->ptr_hnd != 0) {
|
---|
131 | if(!prs_uint32("handle ", ps, depth, &hnd->handle )) /* enum handle */
|
---|
132 | return False;
|
---|
133 | }
|
---|
134 |
|
---|
135 | return True;
|
---|
136 | }
|
---|
137 |
|
---|
138 | /*******************************************************************
|
---|
139 | Reads or writes a DOM_SID structure.
|
---|
140 | ********************************************************************/
|
---|
141 |
|
---|
142 | bool smb_io_dom_sid(const char *desc, DOM_SID *sid, prs_struct *ps, int depth)
|
---|
143 | {
|
---|
144 | int i;
|
---|
145 |
|
---|
146 | if (sid == NULL)
|
---|
147 | return False;
|
---|
148 |
|
---|
149 | prs_debug(ps, depth, desc, "smb_io_dom_sid");
|
---|
150 | depth++;
|
---|
151 |
|
---|
152 | if(!prs_uint8 ("sid_rev_num", ps, depth, &sid->sid_rev_num))
|
---|
153 | return False;
|
---|
154 |
|
---|
155 | if(!prs_uint8 ("num_auths ", ps, depth, &sid->num_auths))
|
---|
156 | return False;
|
---|
157 |
|
---|
158 | for (i = 0; i < 6; i++)
|
---|
159 | {
|
---|
160 | fstring tmp;
|
---|
161 | slprintf(tmp, sizeof(tmp) - 1, "id_auth[%d] ", i);
|
---|
162 | if(!prs_uint8 (tmp, ps, depth, &sid->id_auth[i]))
|
---|
163 | return False;
|
---|
164 | }
|
---|
165 |
|
---|
166 | /* oops! XXXX should really issue a warning here... */
|
---|
167 | if (sid->num_auths > MAXSUBAUTHS)
|
---|
168 | sid->num_auths = MAXSUBAUTHS;
|
---|
169 |
|
---|
170 | if(!prs_uint32s(False, "sub_auths ", ps, depth, sid->sub_auths, sid->num_auths))
|
---|
171 | return False;
|
---|
172 |
|
---|
173 | return True;
|
---|
174 | }
|
---|
175 |
|
---|
176 | /*******************************************************************
|
---|
177 | Inits a DOM_SID2 structure.
|
---|
178 | ********************************************************************/
|
---|
179 |
|
---|
180 | void init_dom_sid2(DOM_SID2 *sid2, const DOM_SID *sid)
|
---|
181 | {
|
---|
182 | sid2->sid = *sid;
|
---|
183 | sid2->num_auths = sid2->sid.num_auths;
|
---|
184 | }
|
---|
185 |
|
---|
186 | /*******************************************************************
|
---|
187 | Reads or writes a DOM_SID2 structure.
|
---|
188 | ********************************************************************/
|
---|
189 |
|
---|
190 | bool smb_io_dom_sid2_p(const char *desc, prs_struct *ps, int depth, DOM_SID2 **sid2)
|
---|
191 | {
|
---|
192 | uint32 data_p;
|
---|
193 |
|
---|
194 | /* caputure the pointer value to stream */
|
---|
195 |
|
---|
196 | data_p = *sid2 ? 0xf000baaa : 0;
|
---|
197 |
|
---|
198 | if ( !prs_uint32("dom_sid2_p", ps, depth, &data_p ))
|
---|
199 | return False;
|
---|
200 |
|
---|
201 | /* we're done if there is no data */
|
---|
202 |
|
---|
203 | if ( !data_p )
|
---|
204 | return True;
|
---|
205 |
|
---|
206 | if (UNMARSHALLING(ps)) {
|
---|
207 | if ( !(*sid2 = PRS_ALLOC_MEM(ps, DOM_SID2, 1)) )
|
---|
208 | return False;
|
---|
209 | }
|
---|
210 |
|
---|
211 | return True;
|
---|
212 | }
|
---|
213 | /*******************************************************************
|
---|
214 | Reads or writes a DOM_SID2 structure.
|
---|
215 | ********************************************************************/
|
---|
216 |
|
---|
217 | bool smb_io_dom_sid2(const char *desc, DOM_SID2 *sid, prs_struct *ps, int depth)
|
---|
218 | {
|
---|
219 | if (sid == NULL)
|
---|
220 | return False;
|
---|
221 |
|
---|
222 | prs_debug(ps, depth, desc, "smb_io_dom_sid2");
|
---|
223 | depth++;
|
---|
224 |
|
---|
225 | if(!prs_align(ps))
|
---|
226 | return False;
|
---|
227 |
|
---|
228 | if(!prs_uint32("num_auths", ps, depth, &sid->num_auths))
|
---|
229 | return False;
|
---|
230 |
|
---|
231 | if(!smb_io_dom_sid("sid", &sid->sid, ps, depth))
|
---|
232 | return False;
|
---|
233 |
|
---|
234 | return True;
|
---|
235 | }
|
---|
236 |
|
---|
237 | /*******************************************************************
|
---|
238 | Reads or writes a struct GUID
|
---|
239 | ********************************************************************/
|
---|
240 |
|
---|
241 | bool smb_io_uuid(const char *desc, struct GUID *uuid,
|
---|
242 | prs_struct *ps, int depth)
|
---|
243 | {
|
---|
244 | if (uuid == NULL)
|
---|
245 | return False;
|
---|
246 |
|
---|
247 | prs_debug(ps, depth, desc, "smb_io_uuid");
|
---|
248 | depth++;
|
---|
249 |
|
---|
250 | if(!prs_uint32 ("data ", ps, depth, &uuid->time_low))
|
---|
251 | return False;
|
---|
252 | if(!prs_uint16 ("data ", ps, depth, &uuid->time_mid))
|
---|
253 | return False;
|
---|
254 | if(!prs_uint16 ("data ", ps, depth, &uuid->time_hi_and_version))
|
---|
255 | return False;
|
---|
256 |
|
---|
257 | if(!prs_uint8s (False, "data ", ps, depth, uuid->clock_seq, sizeof(uuid->clock_seq)))
|
---|
258 | return False;
|
---|
259 | if(!prs_uint8s (False, "data ", ps, depth, uuid->node, sizeof(uuid->node)))
|
---|
260 | return False;
|
---|
261 |
|
---|
262 | return True;
|
---|
263 | }
|
---|
264 |
|
---|
265 | /*******************************************************************
|
---|
266 | creates a STRHDR structure.
|
---|
267 | ********************************************************************/
|
---|
268 |
|
---|
269 | void init_str_hdr(STRHDR *hdr, int max_len, int len, uint32 buffer)
|
---|
270 | {
|
---|
271 | hdr->str_max_len = max_len;
|
---|
272 | hdr->str_str_len = len;
|
---|
273 | hdr->buffer = buffer;
|
---|
274 | }
|
---|
275 |
|
---|
276 | /*******************************************************************
|
---|
277 | Reads or writes a STRHDR structure.
|
---|
278 | ********************************************************************/
|
---|
279 |
|
---|
280 | bool smb_io_strhdr(const char *desc, STRHDR *hdr, prs_struct *ps, int depth)
|
---|
281 | {
|
---|
282 | if (hdr == NULL)
|
---|
283 | return False;
|
---|
284 |
|
---|
285 | prs_debug(ps, depth, desc, "smb_io_strhdr");
|
---|
286 | depth++;
|
---|
287 |
|
---|
288 | if(!prs_align(ps))
|
---|
289 | return False;
|
---|
290 |
|
---|
291 | if(!prs_uint16("str_str_len", ps, depth, &hdr->str_str_len))
|
---|
292 | return False;
|
---|
293 | if(!prs_uint16("str_max_len", ps, depth, &hdr->str_max_len))
|
---|
294 | return False;
|
---|
295 | if(!prs_uint32("buffer ", ps, depth, &hdr->buffer))
|
---|
296 | return False;
|
---|
297 |
|
---|
298 | return True;
|
---|
299 | }
|
---|
300 |
|
---|
301 | /*******************************************************************
|
---|
302 | Inits a UNIHDR structure.
|
---|
303 | ********************************************************************/
|
---|
304 |
|
---|
305 | void init_uni_hdr(UNIHDR *hdr, UNISTR2 *str2)
|
---|
306 | {
|
---|
307 | hdr->uni_str_len = 2 * (str2->uni_str_len);
|
---|
308 | hdr->uni_max_len = 2 * (str2->uni_max_len);
|
---|
309 | hdr->buffer = (str2->uni_str_len != 0) ? 1 : 0;
|
---|
310 | }
|
---|
311 |
|
---|
312 | /*******************************************************************
|
---|
313 | Reads or writes a UNIHDR structure.
|
---|
314 | ********************************************************************/
|
---|
315 |
|
---|
316 | bool smb_io_unihdr(const char *desc, UNIHDR *hdr, prs_struct *ps, int depth)
|
---|
317 | {
|
---|
318 | if (hdr == NULL)
|
---|
319 | return False;
|
---|
320 |
|
---|
321 | prs_debug(ps, depth, desc, "smb_io_unihdr");
|
---|
322 | depth++;
|
---|
323 |
|
---|
324 | if(!prs_align(ps))
|
---|
325 | return False;
|
---|
326 |
|
---|
327 | if(!prs_uint16("uni_str_len", ps, depth, &hdr->uni_str_len))
|
---|
328 | return False;
|
---|
329 | if(!prs_uint16("uni_max_len", ps, depth, &hdr->uni_max_len))
|
---|
330 | return False;
|
---|
331 | if(!prs_uint32("buffer ", ps, depth, &hdr->buffer))
|
---|
332 | return False;
|
---|
333 |
|
---|
334 | return True;
|
---|
335 | }
|
---|
336 |
|
---|
337 | /*******************************************************************
|
---|
338 | Inits a BUFHDR structure.
|
---|
339 | ********************************************************************/
|
---|
340 |
|
---|
341 | void init_buf_hdr(BUFHDR *hdr, int max_len, int len)
|
---|
342 | {
|
---|
343 | hdr->buf_max_len = max_len;
|
---|
344 | hdr->buf_len = len;
|
---|
345 | }
|
---|
346 |
|
---|
347 | /*******************************************************************
|
---|
348 | prs_uint16 wrapper. Call this and it sets up a pointer to where the
|
---|
349 | uint16 should be stored, or gets the size if reading.
|
---|
350 | ********************************************************************/
|
---|
351 |
|
---|
352 | bool smb_io_hdrbuf_pre(const char *desc, BUFHDR *hdr, prs_struct *ps, int depth, uint32 *offset)
|
---|
353 | {
|
---|
354 | (*offset) = prs_offset(ps);
|
---|
355 | if (ps->io) {
|
---|
356 |
|
---|
357 | /* reading. */
|
---|
358 |
|
---|
359 | if(!smb_io_hdrbuf(desc, hdr, ps, depth))
|
---|
360 | return False;
|
---|
361 |
|
---|
362 | } else {
|
---|
363 |
|
---|
364 | /* writing. */
|
---|
365 |
|
---|
366 | if(!prs_set_offset(ps, prs_offset(ps) + (sizeof(uint32) * 2)))
|
---|
367 | return False;
|
---|
368 | }
|
---|
369 |
|
---|
370 | return True;
|
---|
371 | }
|
---|
372 |
|
---|
373 | /*******************************************************************
|
---|
374 | smb_io_hdrbuf wrapper. Call this and it retrospectively stores the size.
|
---|
375 | Does nothing on reading, as that is already handled by ...._pre()
|
---|
376 | ********************************************************************/
|
---|
377 |
|
---|
378 | bool smb_io_hdrbuf_post(const char *desc, BUFHDR *hdr, prs_struct *ps, int depth,
|
---|
379 | uint32 ptr_hdrbuf, uint32 max_len, uint32 len)
|
---|
380 | {
|
---|
381 | if (!ps->io) {
|
---|
382 | /* writing: go back and do a retrospective job. i hate this */
|
---|
383 |
|
---|
384 | uint32 old_offset = prs_offset(ps);
|
---|
385 |
|
---|
386 | init_buf_hdr(hdr, max_len, len);
|
---|
387 | if(!prs_set_offset(ps, ptr_hdrbuf))
|
---|
388 | return False;
|
---|
389 | if(!smb_io_hdrbuf(desc, hdr, ps, depth))
|
---|
390 | return False;
|
---|
391 |
|
---|
392 | if(!prs_set_offset(ps, old_offset))
|
---|
393 | return False;
|
---|
394 | }
|
---|
395 |
|
---|
396 | return True;
|
---|
397 | }
|
---|
398 |
|
---|
399 | /*******************************************************************
|
---|
400 | Reads or writes a BUFHDR structure.
|
---|
401 | ********************************************************************/
|
---|
402 |
|
---|
403 | bool smb_io_hdrbuf(const char *desc, BUFHDR *hdr, prs_struct *ps, int depth)
|
---|
404 | {
|
---|
405 | if (hdr == NULL)
|
---|
406 | return False;
|
---|
407 |
|
---|
408 | prs_debug(ps, depth, desc, "smb_io_hdrbuf");
|
---|
409 | depth++;
|
---|
410 |
|
---|
411 | if(!prs_align(ps))
|
---|
412 | return False;
|
---|
413 |
|
---|
414 | if(!prs_uint32("buf_max_len", ps, depth, &hdr->buf_max_len))
|
---|
415 | return False;
|
---|
416 | if(!prs_uint32("buf_len ", ps, depth, &hdr->buf_len))
|
---|
417 | return False;
|
---|
418 |
|
---|
419 | return True;
|
---|
420 | }
|
---|
421 |
|
---|
422 | /*******************************************************************
|
---|
423 | Inits a UNISTR structure.
|
---|
424 | ********************************************************************/
|
---|
425 |
|
---|
426 | void init_unistr(UNISTR *str, const char *buf)
|
---|
427 | {
|
---|
428 | size_t len;
|
---|
429 |
|
---|
430 | if (buf == NULL) {
|
---|
431 | str->buffer = NULL;
|
---|
432 | return;
|
---|
433 | }
|
---|
434 |
|
---|
435 | len = rpcstr_push_talloc(talloc_tos(), &str->buffer, buf);
|
---|
436 | if (len == (size_t)-1) {
|
---|
437 | str->buffer = NULL;
|
---|
438 | }
|
---|
439 | }
|
---|
440 |
|
---|
441 | /*******************************************************************
|
---|
442 | reads or writes a UNISTR structure.
|
---|
443 | XXXX NOTE: UNISTR structures NEED to be null-terminated.
|
---|
444 | ********************************************************************/
|
---|
445 |
|
---|
446 | bool smb_io_unistr(const char *desc, UNISTR *uni, prs_struct *ps, int depth)
|
---|
447 | {
|
---|
448 | if (uni == NULL)
|
---|
449 | return False;
|
---|
450 |
|
---|
451 | prs_debug(ps, depth, desc, "smb_io_unistr");
|
---|
452 | depth++;
|
---|
453 |
|
---|
454 | if(!prs_unistr("unistr", ps, depth, uni))
|
---|
455 | return False;
|
---|
456 |
|
---|
457 | return True;
|
---|
458 | }
|
---|
459 |
|
---|
460 | /*******************************************************************
|
---|
461 | Allocate the RPC_DATA_BLOB memory.
|
---|
462 | ********************************************************************/
|
---|
463 |
|
---|
464 | static void create_rpc_blob(RPC_DATA_BLOB *str, size_t len)
|
---|
465 | {
|
---|
466 | if (len) {
|
---|
467 | str->buffer = (uint8 *)TALLOC_ZERO(talloc_tos(), len);
|
---|
468 | if (str->buffer == NULL)
|
---|
469 | smb_panic("create_rpc_blob: talloc fail");
|
---|
470 | str->buf_len = len;
|
---|
471 | } else {
|
---|
472 | str->buffer = NULL;
|
---|
473 | str->buf_len = 0;
|
---|
474 | }
|
---|
475 | }
|
---|
476 |
|
---|
477 | /*******************************************************************
|
---|
478 | Inits a RPC_DATA_BLOB structure from a uint32
|
---|
479 | ********************************************************************/
|
---|
480 |
|
---|
481 | void init_rpc_blob_uint32(RPC_DATA_BLOB *str, uint32 val)
|
---|
482 | {
|
---|
483 | ZERO_STRUCTP(str);
|
---|
484 |
|
---|
485 | /* set up string lengths. */
|
---|
486 | create_rpc_blob(str, sizeof(uint32));
|
---|
487 | SIVAL(str->buffer, 0, val);
|
---|
488 | }
|
---|
489 |
|
---|
490 | /*******************************************************************
|
---|
491 | Inits a RPC_DATA_BLOB structure.
|
---|
492 | ********************************************************************/
|
---|
493 |
|
---|
494 | void init_rpc_blob_str(RPC_DATA_BLOB *str, const char *buf, int len)
|
---|
495 | {
|
---|
496 | ZERO_STRUCTP(str);
|
---|
497 |
|
---|
498 | /* set up string lengths. */
|
---|
499 | if (len) {
|
---|
500 | create_rpc_blob(str, len*2);
|
---|
501 | rpcstr_push(str->buffer, buf, (size_t)str->buf_len, STR_TERMINATE);
|
---|
502 | }
|
---|
503 | }
|
---|
504 |
|
---|
505 | /*******************************************************************
|
---|
506 | Inits a RPC_DATA_BLOB structure from a hex string.
|
---|
507 | ********************************************************************/
|
---|
508 |
|
---|
509 | void init_rpc_blob_hex(RPC_DATA_BLOB *str, const char *buf)
|
---|
510 | {
|
---|
511 | ZERO_STRUCTP(str);
|
---|
512 | if (buf && *buf) {
|
---|
513 | size_t len = strlen(buf);
|
---|
514 | create_rpc_blob(str, len);
|
---|
515 | str->buf_len = strhex_to_str((char *)str->buffer, str->buf_len,
|
---|
516 | buf, len);
|
---|
517 | }
|
---|
518 | }
|
---|
519 |
|
---|
520 | /*******************************************************************
|
---|
521 | Inits a RPC_DATA_BLOB structure.
|
---|
522 | ********************************************************************/
|
---|
523 |
|
---|
524 | void init_rpc_blob_bytes(RPC_DATA_BLOB *str, uint8 *buf, size_t len)
|
---|
525 | {
|
---|
526 | ZERO_STRUCTP(str);
|
---|
527 |
|
---|
528 | /* max buffer size (allocated size) */
|
---|
529 | if (buf != NULL && len) {
|
---|
530 | create_rpc_blob(str, len);
|
---|
531 | memcpy(str->buffer, buf, len);
|
---|
532 | }
|
---|
533 | str->buf_len = len;
|
---|
534 | }
|
---|
535 |
|
---|
536 | /*******************************************************************
|
---|
537 | reads or writes a BUFFER5 structure.
|
---|
538 | the buf_len member tells you how large the buffer is.
|
---|
539 | ********************************************************************/
|
---|
540 | bool smb_io_buffer5(const char *desc, BUFFER5 *buf5, prs_struct *ps, int depth)
|
---|
541 | {
|
---|
542 | prs_debug(ps, depth, desc, "smb_io_buffer5");
|
---|
543 | depth++;
|
---|
544 |
|
---|
545 | if (buf5 == NULL) return False;
|
---|
546 |
|
---|
547 | if(!prs_align(ps))
|
---|
548 | return False;
|
---|
549 | if(!prs_uint32("buf_len", ps, depth, &buf5->buf_len))
|
---|
550 | return False;
|
---|
551 |
|
---|
552 | if(buf5->buf_len) {
|
---|
553 | if(!prs_buffer5(True, "buffer" , ps, depth, buf5))
|
---|
554 | return False;
|
---|
555 | }
|
---|
556 |
|
---|
557 | return True;
|
---|
558 | }
|
---|
559 |
|
---|
560 | /*******************************************************************
|
---|
561 | Inits a REGVAL_BUFFER structure.
|
---|
562 | ********************************************************************/
|
---|
563 |
|
---|
564 | void init_regval_buffer(REGVAL_BUFFER *str, const uint8 *buf, size_t len)
|
---|
565 | {
|
---|
566 | ZERO_STRUCTP(str);
|
---|
567 |
|
---|
568 | /* max buffer size (allocated size) */
|
---|
569 | str->buf_max_len = len;
|
---|
570 | str->offset = 0;
|
---|
571 | str->buf_len = buf != NULL ? len : 0;
|
---|
572 |
|
---|
573 | if (buf != NULL) {
|
---|
574 | SMB_ASSERT(str->buf_max_len >= str->buf_len);
|
---|
575 | str->buffer = (uint16 *)TALLOC_ZERO(talloc_tos(),
|
---|
576 | str->buf_max_len);
|
---|
577 | if (str->buffer == NULL)
|
---|
578 | smb_panic("init_regval_buffer: talloc fail");
|
---|
579 | memcpy(str->buffer, buf, str->buf_len);
|
---|
580 | }
|
---|
581 | }
|
---|
582 |
|
---|
583 | /*******************************************************************
|
---|
584 | Reads or writes a REGVAL_BUFFER structure.
|
---|
585 | the uni_max_len member tells you how large the buffer is.
|
---|
586 | the uni_str_len member tells you how much of the buffer is really used.
|
---|
587 | ********************************************************************/
|
---|
588 |
|
---|
589 | bool smb_io_regval_buffer(const char *desc, prs_struct *ps, int depth, REGVAL_BUFFER *buf2)
|
---|
590 | {
|
---|
591 |
|
---|
592 | prs_debug(ps, depth, desc, "smb_io_regval_buffer");
|
---|
593 | depth++;
|
---|
594 |
|
---|
595 | if(!prs_align(ps))
|
---|
596 | return False;
|
---|
597 |
|
---|
598 | if(!prs_uint32("buf_max_len", ps, depth, &buf2->buf_max_len))
|
---|
599 | return False;
|
---|
600 | if(!prs_uint32("offset ", ps, depth, &buf2->offset))
|
---|
601 | return False;
|
---|
602 | if(!prs_uint32("buf_len ", ps, depth, &buf2->buf_len))
|
---|
603 | return False;
|
---|
604 |
|
---|
605 | /* buffer advanced by indicated length of string
|
---|
606 | NOT by searching for null-termination */
|
---|
607 |
|
---|
608 | if(!prs_regval_buffer(True, "buffer ", ps, depth, buf2))
|
---|
609 | return False;
|
---|
610 |
|
---|
611 | return True;
|
---|
612 | }
|
---|
613 |
|
---|
614 | /*******************************************************************
|
---|
615 | creates a UNISTR2 structure: sets up the buffer, too
|
---|
616 | ********************************************************************/
|
---|
617 |
|
---|
618 | void init_buf_unistr2(UNISTR2 *str, uint32 *ptr, const char *buf)
|
---|
619 | {
|
---|
620 | if (buf != NULL) {
|
---|
621 | *ptr = 1;
|
---|
622 | init_unistr2(str, buf, UNI_STR_TERMINATE);
|
---|
623 | } else {
|
---|
624 | *ptr = 0;
|
---|
625 | init_unistr2(str, NULL, UNI_FLAGS_NONE);
|
---|
626 |
|
---|
627 | }
|
---|
628 | }
|
---|
629 |
|
---|
630 | /*******************************************************************
|
---|
631 | Copies a UNISTR2 structure.
|
---|
632 | ********************************************************************/
|
---|
633 |
|
---|
634 | void copy_unistr2(UNISTR2 *str, const UNISTR2 *from)
|
---|
635 | {
|
---|
636 | if (from->buffer == NULL) {
|
---|
637 | ZERO_STRUCTP(str);
|
---|
638 | return;
|
---|
639 | }
|
---|
640 |
|
---|
641 | SMB_ASSERT(from->uni_max_len >= from->uni_str_len);
|
---|
642 |
|
---|
643 | str->uni_max_len = from->uni_max_len;
|
---|
644 | str->offset = from->offset;
|
---|
645 | str->uni_str_len = from->uni_str_len;
|
---|
646 |
|
---|
647 | /* the string buffer is allocated to the maximum size
|
---|
648 | (the the length of the source string) to prevent
|
---|
649 | reallocation of memory. */
|
---|
650 | if (str->buffer == NULL) {
|
---|
651 | if (str->uni_max_len) {
|
---|
652 | str->buffer = (uint16 *)TALLOC_ZERO_ARRAY(talloc_tos(), uint16, str->uni_max_len);
|
---|
653 | if ((str->buffer == NULL)) {
|
---|
654 | smb_panic("copy_unistr2: talloc fail");
|
---|
655 | return;
|
---|
656 | }
|
---|
657 | /* copy the string */
|
---|
658 | memcpy(str->buffer, from->buffer, str->uni_max_len*sizeof(uint16));
|
---|
659 | } else {
|
---|
660 | str->buffer = NULL;
|
---|
661 | }
|
---|
662 | }
|
---|
663 | }
|
---|
664 |
|
---|
665 | /*******************************************************************
|
---|
666 | Creates a STRING2 structure.
|
---|
667 | ********************************************************************/
|
---|
668 |
|
---|
669 | void init_string2(STRING2 *str, const char *buf, size_t max_len, size_t str_len)
|
---|
670 | {
|
---|
671 | /* set up string lengths. */
|
---|
672 | SMB_ASSERT(max_len >= str_len);
|
---|
673 |
|
---|
674 | /* Ensure buf is valid if str_len was set. Coverity check. */
|
---|
675 | if (str_len && !buf) {
|
---|
676 | return;
|
---|
677 | }
|
---|
678 |
|
---|
679 | str->str_max_len = max_len;
|
---|
680 | str->offset = 0;
|
---|
681 | str->str_str_len = str_len;
|
---|
682 |
|
---|
683 | /* store the string */
|
---|
684 | if(str_len != 0) {
|
---|
685 | str->buffer = (uint8 *)TALLOC_ZERO(talloc_tos(),
|
---|
686 | str->str_max_len);
|
---|
687 | if (str->buffer == NULL)
|
---|
688 | smb_panic("init_string2: malloc fail");
|
---|
689 | memcpy(str->buffer, buf, str_len);
|
---|
690 | }
|
---|
691 | }
|
---|
692 |
|
---|
693 | /*******************************************************************
|
---|
694 | Reads or writes a STRING2 structure.
|
---|
695 | XXXX NOTE: STRING2 structures need NOT be null-terminated.
|
---|
696 | the str_str_len member tells you how long the string is;
|
---|
697 | the str_max_len member tells you how large the buffer is.
|
---|
698 | ********************************************************************/
|
---|
699 |
|
---|
700 | bool smb_io_string2(const char *desc, STRING2 *str2, uint32 buffer, prs_struct *ps, int depth)
|
---|
701 | {
|
---|
702 | if (str2 == NULL)
|
---|
703 | return False;
|
---|
704 |
|
---|
705 | if (buffer) {
|
---|
706 |
|
---|
707 | prs_debug(ps, depth, desc, "smb_io_string2");
|
---|
708 | depth++;
|
---|
709 |
|
---|
710 | if(!prs_align(ps))
|
---|
711 | return False;
|
---|
712 |
|
---|
713 | if(!prs_uint32("str_max_len", ps, depth, &str2->str_max_len))
|
---|
714 | return False;
|
---|
715 | if(!prs_uint32("offset ", ps, depth, &str2->offset))
|
---|
716 | return False;
|
---|
717 | if(!prs_uint32("str_str_len", ps, depth, &str2->str_str_len))
|
---|
718 | return False;
|
---|
719 |
|
---|
720 | /* buffer advanced by indicated length of string
|
---|
721 | NOT by searching for null-termination */
|
---|
722 | if(!prs_string2(True, "buffer ", ps, depth, str2))
|
---|
723 | return False;
|
---|
724 |
|
---|
725 | } else {
|
---|
726 |
|
---|
727 | prs_debug(ps, depth, desc, "smb_io_string2 - NULL");
|
---|
728 | depth++;
|
---|
729 | memset((char *)str2, '\0', sizeof(*str2));
|
---|
730 |
|
---|
731 | }
|
---|
732 |
|
---|
733 | return True;
|
---|
734 | }
|
---|
735 |
|
---|
736 | /*******************************************************************
|
---|
737 | Inits a UNISTR2 structure.
|
---|
738 | ********************************************************************/
|
---|
739 |
|
---|
740 | void init_unistr2(UNISTR2 *str, const char *buf, enum unistr2_term_codes flags)
|
---|
741 | {
|
---|
742 | size_t len = 0;
|
---|
743 | uint32 num_chars = 0;
|
---|
744 |
|
---|
745 | if (buf) {
|
---|
746 | /* We always null terminate the copy. */
|
---|
747 | len = strlen(buf) + 1;
|
---|
748 | if ( flags == UNI_STR_DBLTERMINATE )
|
---|
749 | len++;
|
---|
750 | }
|
---|
751 |
|
---|
752 | if (buf == NULL || len == 0) {
|
---|
753 | /* no buffer -- nothing to do */
|
---|
754 | str->uni_max_len = 0;
|
---|
755 | str->offset = 0;
|
---|
756 | str->uni_str_len = 0;
|
---|
757 |
|
---|
758 | return;
|
---|
759 | }
|
---|
760 |
|
---|
761 |
|
---|
762 | str->buffer = TALLOC_ZERO_ARRAY(talloc_tos(), uint16, len);
|
---|
763 | if (str->buffer == NULL) {
|
---|
764 | smb_panic("init_unistr2: malloc fail");
|
---|
765 | return;
|
---|
766 | }
|
---|
767 |
|
---|
768 | /* Ensure len is the length in *bytes* */
|
---|
769 | len *= sizeof(uint16);
|
---|
770 |
|
---|
771 | /*
|
---|
772 | * The UNISTR2 must be initialized !!!
|
---|
773 | * jfm, 7/7/2001.
|
---|
774 | */
|
---|
775 | if (buf) {
|
---|
776 | rpcstr_push((char *)str->buffer, buf, len, STR_TERMINATE);
|
---|
777 | num_chars = strlen_w(str->buffer);
|
---|
778 | if (flags == UNI_STR_TERMINATE || flags == UNI_MAXLEN_TERMINATE) {
|
---|
779 | num_chars++;
|
---|
780 | }
|
---|
781 | if ( flags == UNI_STR_DBLTERMINATE )
|
---|
782 | num_chars += 2;
|
---|
783 | }
|
---|
784 |
|
---|
785 | str->uni_max_len = num_chars;
|
---|
786 | str->offset = 0;
|
---|
787 | str->uni_str_len = num_chars;
|
---|
788 | if ( num_chars && ((flags == UNI_MAXLEN_TERMINATE) || (flags == UNI_BROKEN_NON_NULL)) )
|
---|
789 | str->uni_max_len++;
|
---|
790 | }
|
---|
791 |
|
---|
792 | /*******************************************************************
|
---|
793 | Inits a UNISTR4 structure.
|
---|
794 | ********************************************************************/
|
---|
795 |
|
---|
796 | void init_unistr4(UNISTR4 *uni4, const char *buf, enum unistr2_term_codes flags)
|
---|
797 | {
|
---|
798 | uni4->string = TALLOC_P( talloc_tos(), UNISTR2 );
|
---|
799 | if (!uni4->string) {
|
---|
800 | smb_panic("init_unistr4: talloc fail");
|
---|
801 | return;
|
---|
802 | }
|
---|
803 | init_unistr2( uni4->string, buf, flags );
|
---|
804 |
|
---|
805 | uni4->length = 2 * (uni4->string->uni_str_len);
|
---|
806 | uni4->size = 2 * (uni4->string->uni_max_len);
|
---|
807 | }
|
---|
808 |
|
---|
809 | void init_unistr4_w( TALLOC_CTX *ctx, UNISTR4 *uni4, const smb_ucs2_t *buf )
|
---|
810 | {
|
---|
811 | uni4->string = TALLOC_P( ctx, UNISTR2 );
|
---|
812 | if (!uni4->string) {
|
---|
813 | smb_panic("init_unistr4_w: talloc fail");
|
---|
814 | return;
|
---|
815 | }
|
---|
816 | init_unistr2_w( ctx, uni4->string, buf );
|
---|
817 |
|
---|
818 | uni4->length = 2 * (uni4->string->uni_str_len);
|
---|
819 | uni4->size = 2 * (uni4->string->uni_max_len);
|
---|
820 | }
|
---|
821 |
|
---|
822 | /**
|
---|
823 | * Inits a UNISTR2 structure.
|
---|
824 | * @param ctx talloc context to allocate string on
|
---|
825 | * @param str pointer to string to create
|
---|
826 | * @param buf UCS2 null-terminated buffer to init from
|
---|
827 | */
|
---|
828 |
|
---|
829 | void init_unistr2_w(TALLOC_CTX *ctx, UNISTR2 *str, const smb_ucs2_t *buf)
|
---|
830 | {
|
---|
831 | uint32 len = buf ? strlen_w(buf) : 0;
|
---|
832 |
|
---|
833 | ZERO_STRUCTP(str);
|
---|
834 |
|
---|
835 | /* set up string lengths. */
|
---|
836 | str->uni_max_len = len;
|
---|
837 | str->offset = 0;
|
---|
838 | str->uni_str_len = len;
|
---|
839 |
|
---|
840 | if (len + 1) {
|
---|
841 | str->buffer = TALLOC_ZERO_ARRAY(ctx, uint16, len + 1);
|
---|
842 | if (str->buffer == NULL) {
|
---|
843 | smb_panic("init_unistr2_w: talloc fail");
|
---|
844 | return;
|
---|
845 | }
|
---|
846 | } else {
|
---|
847 | str->buffer = NULL;
|
---|
848 | }
|
---|
849 |
|
---|
850 | /*
|
---|
851 | * don't move this test above ! The UNISTR2 must be initialized !!!
|
---|
852 | * jfm, 7/7/2001.
|
---|
853 | */
|
---|
854 | if (buf==NULL)
|
---|
855 | return;
|
---|
856 |
|
---|
857 | /* Yes, this is a strncpy( foo, bar, strlen(bar)) - but as
|
---|
858 | long as the buffer above is talloc()ed correctly then this
|
---|
859 | is the correct thing to do */
|
---|
860 | if (len+1) {
|
---|
861 | strncpy_w(str->buffer, buf, len + 1);
|
---|
862 | }
|
---|
863 | }
|
---|
864 |
|
---|
865 | /*******************************************************************
|
---|
866 | Inits a UNISTR2 structure from a UNISTR
|
---|
867 | ********************************************************************/
|
---|
868 |
|
---|
869 | void init_unistr2_from_unistr(TALLOC_CTX *ctx, UNISTR2 *to, const UNISTR *from)
|
---|
870 | {
|
---|
871 | uint32 i;
|
---|
872 |
|
---|
873 | /* the destination UNISTR2 should never be NULL.
|
---|
874 | if it is it is a programming error */
|
---|
875 |
|
---|
876 | /* if the source UNISTR is NULL, then zero out
|
---|
877 | the destination string and return */
|
---|
878 | ZERO_STRUCTP (to);
|
---|
879 | if ((from == NULL) || (from->buffer == NULL))
|
---|
880 | return;
|
---|
881 |
|
---|
882 | /* get the length; UNISTR must be NULL terminated */
|
---|
883 | i = 0;
|
---|
884 | while ((from->buffer)[i]!='\0')
|
---|
885 | i++;
|
---|
886 | i++; /* one more to catch the terminating NULL */
|
---|
887 | /* is this necessary -- jerry? I need to think */
|
---|
888 |
|
---|
889 | /* set up string lengths; uni_max_len is set to i+1
|
---|
890 | because we need to account for the final NULL termination */
|
---|
891 | to->uni_max_len = i;
|
---|
892 | to->offset = 0;
|
---|
893 | to->uni_str_len = i;
|
---|
894 |
|
---|
895 | /* allocate the space and copy the string buffer */
|
---|
896 | if (i) {
|
---|
897 | to->buffer = TALLOC_ZERO_ARRAY(ctx, uint16, i);
|
---|
898 | if (to->buffer == NULL)
|
---|
899 | smb_panic("init_unistr2_from_unistr: talloc fail");
|
---|
900 | memcpy(to->buffer, from->buffer, i*sizeof(uint16));
|
---|
901 | } else {
|
---|
902 | to->buffer = NULL;
|
---|
903 | }
|
---|
904 | return;
|
---|
905 | }
|
---|
906 |
|
---|
907 | /*******************************************************************
|
---|
908 | Inits a UNISTR2 structure from a DATA_BLOB.
|
---|
909 | The length of the data_blob must count the bytes of the buffer.
|
---|
910 | Copies the blob data.
|
---|
911 | ********************************************************************/
|
---|
912 |
|
---|
913 | void init_unistr2_from_datablob(UNISTR2 *str, DATA_BLOB *blob)
|
---|
914 | {
|
---|
915 | /* Allocs the unistring */
|
---|
916 | init_unistr2(str, NULL, UNI_FLAGS_NONE);
|
---|
917 |
|
---|
918 | /* Sets the values */
|
---|
919 | str->uni_str_len = blob->length / sizeof(uint16);
|
---|
920 | str->uni_max_len = str->uni_str_len;
|
---|
921 | str->offset = 0;
|
---|
922 | if (blob->length) {
|
---|
923 | str->buffer = (uint16 *) memdup(blob->data, blob->length);
|
---|
924 | } else {
|
---|
925 | str->buffer = NULL;
|
---|
926 | }
|
---|
927 | if ((str->buffer == NULL) && (blob->length > 0)) {
|
---|
928 | smb_panic("init_unistr2_from_datablob: malloc fail");
|
---|
929 | }
|
---|
930 | }
|
---|
931 |
|
---|
932 | /*******************************************************************
|
---|
933 | UNISTR2* are a little different in that the pointer and the UNISTR2
|
---|
934 | are not necessarily read/written back to back. So we break it up
|
---|
935 | into 2 separate functions.
|
---|
936 | See SPOOL_USER_1 in include/rpc_spoolss.h for an example.
|
---|
937 | ********************************************************************/
|
---|
938 |
|
---|
939 | bool prs_io_unistr2_p(const char *desc, prs_struct *ps, int depth, UNISTR2 **uni2)
|
---|
940 | {
|
---|
941 | uint32 data_p;
|
---|
942 |
|
---|
943 | /* caputure the pointer value to stream */
|
---|
944 |
|
---|
945 | data_p = *uni2 ? 0xf000baaa : 0;
|
---|
946 |
|
---|
947 | if ( !prs_uint32("ptr", ps, depth, &data_p ))
|
---|
948 | return False;
|
---|
949 |
|
---|
950 | /* we're done if there is no data */
|
---|
951 |
|
---|
952 | if ( !data_p )
|
---|
953 | return True;
|
---|
954 |
|
---|
955 | if (UNMARSHALLING(ps)) {
|
---|
956 | if ( !(*uni2 = PRS_ALLOC_MEM(ps, UNISTR2, 1)) )
|
---|
957 | return False;
|
---|
958 | }
|
---|
959 |
|
---|
960 | return True;
|
---|
961 | }
|
---|
962 |
|
---|
963 | /*******************************************************************
|
---|
964 | now read/write the actual UNISTR2. Memory for the UNISTR2 (but
|
---|
965 | not UNISTR2.buffer) has been allocated previously by prs_unistr2_p()
|
---|
966 | ********************************************************************/
|
---|
967 |
|
---|
968 | bool prs_io_unistr2(const char *desc, prs_struct *ps, int depth, UNISTR2 *uni2 )
|
---|
969 | {
|
---|
970 | /* just return true if there is no pointer to deal with.
|
---|
971 | the memory must have been previously allocated on unmarshalling
|
---|
972 | by prs_unistr2_p() */
|
---|
973 |
|
---|
974 | if ( !uni2 )
|
---|
975 | return True;
|
---|
976 |
|
---|
977 | /* just pass off to smb_io_unstr2() passing the uni2 address as
|
---|
978 | the pointer (like you would expect) */
|
---|
979 |
|
---|
980 | return smb_io_unistr2( desc, uni2, uni2 ? 1 : 0, ps, depth );
|
---|
981 | }
|
---|
982 |
|
---|
983 | /*******************************************************************
|
---|
984 | Reads or writes a UNISTR2 structure.
|
---|
985 | XXXX NOTE: UNISTR2 structures need NOT be null-terminated.
|
---|
986 | the uni_str_len member tells you how long the string is;
|
---|
987 | the uni_max_len member tells you how large the buffer is.
|
---|
988 | ********************************************************************/
|
---|
989 |
|
---|
990 | bool smb_io_unistr2(const char *desc, UNISTR2 *uni2, uint32 buffer, prs_struct *ps, int depth)
|
---|
991 | {
|
---|
992 | if (uni2 == NULL)
|
---|
993 | return False;
|
---|
994 |
|
---|
995 | if (buffer) {
|
---|
996 |
|
---|
997 | prs_debug(ps, depth, desc, "smb_io_unistr2");
|
---|
998 | depth++;
|
---|
999 |
|
---|
1000 | if(!prs_align(ps))
|
---|
1001 | return False;
|
---|
1002 |
|
---|
1003 | if(!prs_uint32("uni_max_len", ps, depth, &uni2->uni_max_len))
|
---|
1004 | return False;
|
---|
1005 | if(!prs_uint32("offset ", ps, depth, &uni2->offset))
|
---|
1006 | return False;
|
---|
1007 | if(!prs_uint32("uni_str_len", ps, depth, &uni2->uni_str_len))
|
---|
1008 | return False;
|
---|
1009 |
|
---|
1010 | /* buffer advanced by indicated length of string
|
---|
1011 | NOT by searching for null-termination */
|
---|
1012 | if(!prs_unistr2(True, "buffer ", ps, depth, uni2))
|
---|
1013 | return False;
|
---|
1014 |
|
---|
1015 | } else {
|
---|
1016 |
|
---|
1017 | prs_debug(ps, depth, desc, "smb_io_unistr2 - NULL");
|
---|
1018 | depth++;
|
---|
1019 | memset((char *)uni2, '\0', sizeof(*uni2));
|
---|
1020 |
|
---|
1021 | }
|
---|
1022 |
|
---|
1023 | return True;
|
---|
1024 | }
|
---|
1025 |
|
---|
1026 | /*******************************************************************
|
---|
1027 | now read/write UNISTR4
|
---|
1028 | ********************************************************************/
|
---|
1029 |
|
---|
1030 | bool prs_unistr4(const char *desc, prs_struct *ps, int depth, UNISTR4 *uni4)
|
---|
1031 | {
|
---|
1032 | void *ptr;
|
---|
1033 | prs_debug(ps, depth, desc, "prs_unistr4");
|
---|
1034 | depth++;
|
---|
1035 |
|
---|
1036 | if ( !prs_uint16("length", ps, depth, &uni4->length ))
|
---|
1037 | return False;
|
---|
1038 | if ( !prs_uint16("size", ps, depth, &uni4->size ))
|
---|
1039 | return False;
|
---|
1040 |
|
---|
1041 | ptr = uni4->string;
|
---|
1042 |
|
---|
1043 | if ( !prs_pointer( desc, ps, depth, &ptr, sizeof(UNISTR2), (PRS_POINTER_CAST)prs_io_unistr2 ) )
|
---|
1044 | return False;
|
---|
1045 |
|
---|
1046 | uni4->string = (UNISTR2 *)ptr;
|
---|
1047 |
|
---|
1048 | return True;
|
---|
1049 | }
|
---|
1050 |
|
---|
1051 | /*******************************************************************
|
---|
1052 | now read/write UNISTR4 header
|
---|
1053 | ********************************************************************/
|
---|
1054 |
|
---|
1055 | bool prs_unistr4_hdr(const char *desc, prs_struct *ps, int depth, UNISTR4 *uni4)
|
---|
1056 | {
|
---|
1057 | prs_debug(ps, depth, desc, "prs_unistr4_hdr");
|
---|
1058 | depth++;
|
---|
1059 |
|
---|
1060 | if ( !prs_uint16("length", ps, depth, &uni4->length) )
|
---|
1061 | return False;
|
---|
1062 | if ( !prs_uint16("size", ps, depth, &uni4->size) )
|
---|
1063 | return False;
|
---|
1064 | if ( !prs_io_unistr2_p(desc, ps, depth, &uni4->string) )
|
---|
1065 | return False;
|
---|
1066 |
|
---|
1067 | return True;
|
---|
1068 | }
|
---|
1069 |
|
---|
1070 | /*******************************************************************
|
---|
1071 | now read/write UNISTR4 string
|
---|
1072 | ********************************************************************/
|
---|
1073 |
|
---|
1074 | bool prs_unistr4_str(const char *desc, prs_struct *ps, int depth, UNISTR4 *uni4)
|
---|
1075 | {
|
---|
1076 | prs_debug(ps, depth, desc, "prs_unistr4_str");
|
---|
1077 | depth++;
|
---|
1078 |
|
---|
1079 | if ( !prs_io_unistr2(desc, ps, depth, uni4->string) )
|
---|
1080 | return False;
|
---|
1081 |
|
---|
1082 | return True;
|
---|
1083 | }
|
---|
1084 |
|
---|
1085 | /*******************************************************************
|
---|
1086 | Reads or writes a UNISTR4_ARRAY structure.
|
---|
1087 | ********************************************************************/
|
---|
1088 |
|
---|
1089 | bool prs_unistr4_array(const char *desc, prs_struct *ps, int depth, UNISTR4_ARRAY *array )
|
---|
1090 | {
|
---|
1091 | unsigned int i;
|
---|
1092 |
|
---|
1093 | prs_debug(ps, depth, desc, "prs_unistr4_array");
|
---|
1094 | depth++;
|
---|
1095 |
|
---|
1096 | if(!prs_uint32("count", ps, depth, &array->count))
|
---|
1097 | return False;
|
---|
1098 |
|
---|
1099 | if (UNMARSHALLING(ps)) {
|
---|
1100 | if (array->count) {
|
---|
1101 | if ( !(array->strings = TALLOC_ZERO_ARRAY( talloc_tos(), UNISTR4, array->count)) )
|
---|
1102 | return False;
|
---|
1103 | } else {
|
---|
1104 | array->strings = NULL;
|
---|
1105 | }
|
---|
1106 | }
|
---|
1107 |
|
---|
1108 | /* write the headers and then the actual string buffer */
|
---|
1109 |
|
---|
1110 | for ( i=0; i<array->count; i++ ) {
|
---|
1111 | if ( !prs_unistr4_hdr( "string", ps, depth, &array->strings[i]) )
|
---|
1112 | return False;
|
---|
1113 | }
|
---|
1114 |
|
---|
1115 | for (i=0;i<array->count;i++) {
|
---|
1116 | if ( !prs_unistr4_str("string", ps, depth, &array->strings[i]) )
|
---|
1117 | return False;
|
---|
1118 | }
|
---|
1119 |
|
---|
1120 | return True;
|
---|
1121 | }
|
---|
1122 |
|
---|
1123 | /********************************************************************
|
---|
1124 | initialise a UNISTR_ARRAY from a char**
|
---|
1125 | ********************************************************************/
|
---|
1126 |
|
---|
1127 | bool init_unistr4_array( UNISTR4_ARRAY *array, uint32 count, const char **strings )
|
---|
1128 | {
|
---|
1129 | unsigned int i;
|
---|
1130 |
|
---|
1131 | array->count = count;
|
---|
1132 |
|
---|
1133 | /* allocate memory for the array of UNISTR4 objects */
|
---|
1134 |
|
---|
1135 | if (array->count) {
|
---|
1136 | if ( !(array->strings = TALLOC_ZERO_ARRAY(talloc_tos(), UNISTR4, count )) )
|
---|
1137 | return False;
|
---|
1138 | } else {
|
---|
1139 | array->strings = NULL;
|
---|
1140 | }
|
---|
1141 |
|
---|
1142 | for ( i=0; i<count; i++ )
|
---|
1143 | init_unistr4( &array->strings[i], strings[i], UNI_STR_TERMINATE );
|
---|
1144 |
|
---|
1145 | return True;
|
---|
1146 | }
|
---|
1147 |
|
---|
1148 | /*******************************************************************
|
---|
1149 | Inits a DOM_RID structure.
|
---|
1150 | ********************************************************************/
|
---|
1151 |
|
---|
1152 | void init_dom_rid(DOM_RID *prid, uint32 rid, uint16 type, uint32 idx)
|
---|
1153 | {
|
---|
1154 | prid->type = type;
|
---|
1155 | prid->rid = rid;
|
---|
1156 | prid->rid_idx = idx;
|
---|
1157 | }
|
---|
1158 |
|
---|
1159 | /*******************************************************************
|
---|
1160 | Reads or writes a DOM_RID structure.
|
---|
1161 | ********************************************************************/
|
---|
1162 |
|
---|
1163 | bool smb_io_dom_rid(const char *desc, DOM_RID *rid, prs_struct *ps, int depth)
|
---|
1164 | {
|
---|
1165 | if (rid == NULL)
|
---|
1166 | return False;
|
---|
1167 |
|
---|
1168 | prs_debug(ps, depth, desc, "smb_io_dom_rid");
|
---|
1169 | depth++;
|
---|
1170 |
|
---|
1171 | if(!prs_align(ps))
|
---|
1172 | return False;
|
---|
1173 |
|
---|
1174 | if(!prs_uint16("type ", ps, depth, &rid->type))
|
---|
1175 | return False;
|
---|
1176 | if(!prs_align(ps))
|
---|
1177 | return False;
|
---|
1178 | if(!prs_uint32("rid ", ps, depth, &rid->rid))
|
---|
1179 | return False;
|
---|
1180 | if(!prs_uint32("rid_idx", ps, depth, &rid->rid_idx))
|
---|
1181 | return False;
|
---|
1182 |
|
---|
1183 | return True;
|
---|
1184 | }
|
---|
1185 |
|
---|
1186 | /*******************************************************************
|
---|
1187 | Reads or writes a DOM_RID2 structure.
|
---|
1188 | ********************************************************************/
|
---|
1189 |
|
---|
1190 | bool smb_io_dom_rid2(const char *desc, DOM_RID2 *rid, prs_struct *ps, int depth)
|
---|
1191 | {
|
---|
1192 | if (rid == NULL)
|
---|
1193 | return False;
|
---|
1194 |
|
---|
1195 | prs_debug(ps, depth, desc, "smb_io_dom_rid2");
|
---|
1196 | depth++;
|
---|
1197 |
|
---|
1198 | if(!prs_align(ps))
|
---|
1199 | return False;
|
---|
1200 |
|
---|
1201 | if(!prs_uint16("type ", ps, depth, &rid->type))
|
---|
1202 | return False;
|
---|
1203 | if(!prs_align(ps))
|
---|
1204 | return False;
|
---|
1205 | if(!prs_uint32("rid ", ps, depth, &rid->rid))
|
---|
1206 | return False;
|
---|
1207 | if(!prs_uint32("rid_idx", ps, depth, &rid->rid_idx))
|
---|
1208 | return False;
|
---|
1209 | if(!prs_uint32("unknown", ps, depth, &rid->unknown))
|
---|
1210 | return False;
|
---|
1211 |
|
---|
1212 | return True;
|
---|
1213 | }
|
---|
1214 |
|
---|
1215 |
|
---|
1216 | /*******************************************************************
|
---|
1217 | creates a DOM_RID3 structure.
|
---|
1218 | ********************************************************************/
|
---|
1219 |
|
---|
1220 | void init_dom_rid3(DOM_RID3 *rid3, uint32 rid, uint8 type)
|
---|
1221 | {
|
---|
1222 | rid3->rid = rid;
|
---|
1223 | rid3->type1 = type;
|
---|
1224 | rid3->ptr_type = 0x1; /* non-zero, basically. */
|
---|
1225 | rid3->type2 = 0x1;
|
---|
1226 | rid3->unk = type;
|
---|
1227 | }
|
---|
1228 |
|
---|
1229 | /*******************************************************************
|
---|
1230 | reads or writes a DOM_RID3 structure.
|
---|
1231 | ********************************************************************/
|
---|
1232 |
|
---|
1233 | bool smb_io_dom_rid3(const char *desc, DOM_RID3 *rid3, prs_struct *ps, int depth)
|
---|
1234 | {
|
---|
1235 | if (rid3 == NULL)
|
---|
1236 | return False;
|
---|
1237 |
|
---|
1238 | prs_debug(ps, depth, desc, "smb_io_dom_rid3");
|
---|
1239 | depth++;
|
---|
1240 |
|
---|
1241 | if(!prs_align(ps))
|
---|
1242 | return False;
|
---|
1243 |
|
---|
1244 | if(!prs_uint32("rid ", ps, depth, &rid3->rid))
|
---|
1245 | return False;
|
---|
1246 | if(!prs_uint32("type1 ", ps, depth, &rid3->type1))
|
---|
1247 | return False;
|
---|
1248 | if(!prs_uint32("ptr_type", ps, depth, &rid3->ptr_type))
|
---|
1249 | return False;
|
---|
1250 | if(!prs_uint32("type2 ", ps, depth, &rid3->type2))
|
---|
1251 | return False;
|
---|
1252 | if(!prs_uint32("unk ", ps, depth, &rid3->unk))
|
---|
1253 | return False;
|
---|
1254 |
|
---|
1255 | return True;
|
---|
1256 | }
|
---|
1257 |
|
---|
1258 | /*******************************************************************
|
---|
1259 | Inits a DOM_RID4 structure.
|
---|
1260 | ********************************************************************/
|
---|
1261 |
|
---|
1262 | void init_dom_rid4(DOM_RID4 *rid4, uint16 unknown, uint16 attr, uint32 rid)
|
---|
1263 | {
|
---|
1264 | rid4->unknown = unknown;
|
---|
1265 | rid4->attr = attr;
|
---|
1266 | rid4->rid = rid;
|
---|
1267 | }
|
---|
1268 |
|
---|
1269 | /*******************************************************************
|
---|
1270 | Inits a DOM_CLNT_SRV structure.
|
---|
1271 | ********************************************************************/
|
---|
1272 |
|
---|
1273 | void init_clnt_srv(DOM_CLNT_SRV *logcln, const char *logon_srv,
|
---|
1274 | const char *comp_name)
|
---|
1275 | {
|
---|
1276 | DEBUG(5,("init_clnt_srv: %d\n", __LINE__));
|
---|
1277 |
|
---|
1278 | if (logon_srv != NULL) {
|
---|
1279 | logcln->undoc_buffer = 1;
|
---|
1280 | init_unistr2(&logcln->uni_logon_srv, logon_srv, UNI_STR_TERMINATE);
|
---|
1281 | } else {
|
---|
1282 | logcln->undoc_buffer = 0;
|
---|
1283 | }
|
---|
1284 |
|
---|
1285 | if (comp_name != NULL) {
|
---|
1286 | logcln->undoc_buffer2 = 1;
|
---|
1287 | init_unistr2(&logcln->uni_comp_name, comp_name, UNI_STR_TERMINATE);
|
---|
1288 | } else {
|
---|
1289 | logcln->undoc_buffer2 = 0;
|
---|
1290 | }
|
---|
1291 | }
|
---|
1292 |
|
---|
1293 | /*******************************************************************
|
---|
1294 | Inits or writes a DOM_CLNT_SRV structure.
|
---|
1295 | ********************************************************************/
|
---|
1296 |
|
---|
1297 | bool smb_io_clnt_srv(const char *desc, DOM_CLNT_SRV *logcln, prs_struct *ps, int depth)
|
---|
1298 | {
|
---|
1299 | if (logcln == NULL)
|
---|
1300 | return False;
|
---|
1301 |
|
---|
1302 | prs_debug(ps, depth, desc, "smb_io_clnt_srv");
|
---|
1303 | depth++;
|
---|
1304 |
|
---|
1305 | if(!prs_align(ps))
|
---|
1306 | return False;
|
---|
1307 |
|
---|
1308 | if(!prs_uint32("undoc_buffer ", ps, depth, &logcln->undoc_buffer))
|
---|
1309 | return False;
|
---|
1310 |
|
---|
1311 | if (logcln->undoc_buffer != 0) {
|
---|
1312 | if(!smb_io_unistr2("unistr2", &logcln->uni_logon_srv, logcln->undoc_buffer, ps, depth))
|
---|
1313 | return False;
|
---|
1314 | }
|
---|
1315 |
|
---|
1316 | if(!prs_align(ps))
|
---|
1317 | return False;
|
---|
1318 |
|
---|
1319 | if(!prs_uint32("undoc_buffer2", ps, depth, &logcln->undoc_buffer2))
|
---|
1320 | return False;
|
---|
1321 |
|
---|
1322 | if (logcln->undoc_buffer2 != 0) {
|
---|
1323 | if(!smb_io_unistr2("unistr2", &logcln->uni_comp_name, logcln->undoc_buffer2, ps, depth))
|
---|
1324 | return False;
|
---|
1325 | }
|
---|
1326 |
|
---|
1327 | return True;
|
---|
1328 | }
|
---|
1329 |
|
---|
1330 | /*******************************************************************
|
---|
1331 | Inits a DOM_LOG_INFO structure.
|
---|
1332 | ********************************************************************/
|
---|
1333 |
|
---|
1334 | void init_log_info(DOM_LOG_INFO *loginfo, const char *logon_srv, const char *acct_name,
|
---|
1335 | uint16 sec_chan, const char *comp_name)
|
---|
1336 | {
|
---|
1337 | DEBUG(5,("make_log_info %d\n", __LINE__));
|
---|
1338 |
|
---|
1339 | loginfo->undoc_buffer = 1;
|
---|
1340 |
|
---|
1341 | init_unistr2(&loginfo->uni_logon_srv, logon_srv, UNI_STR_TERMINATE);
|
---|
1342 | init_unistr2(&loginfo->uni_acct_name, acct_name, UNI_STR_TERMINATE);
|
---|
1343 |
|
---|
1344 | loginfo->sec_chan = sec_chan;
|
---|
1345 |
|
---|
1346 | init_unistr2(&loginfo->uni_comp_name, comp_name, UNI_STR_TERMINATE);
|
---|
1347 | }
|
---|
1348 |
|
---|
1349 | /*******************************************************************
|
---|
1350 | Reads or writes a DOM_LOG_INFO structure.
|
---|
1351 | ********************************************************************/
|
---|
1352 |
|
---|
1353 | bool smb_io_log_info(const char *desc, DOM_LOG_INFO *loginfo, prs_struct *ps, int depth)
|
---|
1354 | {
|
---|
1355 | if (loginfo == NULL)
|
---|
1356 | return False;
|
---|
1357 |
|
---|
1358 | prs_debug(ps, depth, desc, "smb_io_log_info");
|
---|
1359 | depth++;
|
---|
1360 |
|
---|
1361 | if(!prs_align(ps))
|
---|
1362 | return False;
|
---|
1363 |
|
---|
1364 | if(!prs_uint32("undoc_buffer", ps, depth, &loginfo->undoc_buffer))
|
---|
1365 | return False;
|
---|
1366 |
|
---|
1367 | if(!smb_io_unistr2("unistr2", &loginfo->uni_logon_srv, True, ps, depth))
|
---|
1368 | return False;
|
---|
1369 | if(!smb_io_unistr2("unistr2", &loginfo->uni_acct_name, True, ps, depth))
|
---|
1370 | return False;
|
---|
1371 |
|
---|
1372 | if(!prs_uint16("sec_chan", ps, depth, &loginfo->sec_chan))
|
---|
1373 | return False;
|
---|
1374 |
|
---|
1375 | if(!smb_io_unistr2("unistr2", &loginfo->uni_comp_name, True, ps, depth))
|
---|
1376 | return False;
|
---|
1377 |
|
---|
1378 | return True;
|
---|
1379 | }
|
---|
1380 |
|
---|
1381 | /*******************************************************************
|
---|
1382 | Reads or writes a DOM_CHAL structure.
|
---|
1383 | ********************************************************************/
|
---|
1384 |
|
---|
1385 | bool smb_io_chal(const char *desc, DOM_CHAL *chal, prs_struct *ps, int depth)
|
---|
1386 | {
|
---|
1387 | if (chal == NULL)
|
---|
1388 | return False;
|
---|
1389 |
|
---|
1390 | prs_debug(ps, depth, desc, "smb_io_chal");
|
---|
1391 | depth++;
|
---|
1392 |
|
---|
1393 | if(!prs_uint8s (False, "data", ps, depth, chal->data, 8))
|
---|
1394 | return False;
|
---|
1395 |
|
---|
1396 | return True;
|
---|
1397 | }
|
---|
1398 |
|
---|
1399 | /*******************************************************************
|
---|
1400 | Reads or writes a DOM_CRED structure.
|
---|
1401 | ********************************************************************/
|
---|
1402 |
|
---|
1403 | bool smb_io_cred(const char *desc, DOM_CRED *cred, prs_struct *ps, int depth)
|
---|
1404 | {
|
---|
1405 | if (cred == NULL)
|
---|
1406 | return False;
|
---|
1407 |
|
---|
1408 | prs_debug(ps, depth, desc, "smb_io_cred");
|
---|
1409 | depth++;
|
---|
1410 |
|
---|
1411 | if(!prs_align(ps))
|
---|
1412 | return False;
|
---|
1413 |
|
---|
1414 | if(!smb_io_chal ("", &cred->challenge, ps, depth))
|
---|
1415 | return False;
|
---|
1416 |
|
---|
1417 | if(!smb_io_utime("", &cred->timestamp, ps, depth))
|
---|
1418 | return False;
|
---|
1419 |
|
---|
1420 | return True;
|
---|
1421 | }
|
---|
1422 |
|
---|
1423 | /*******************************************************************
|
---|
1424 | Inits a DOM_CLNT_INFO2 structure.
|
---|
1425 | ********************************************************************/
|
---|
1426 |
|
---|
1427 | void init_clnt_info2(DOM_CLNT_INFO2 *clnt,
|
---|
1428 | const char *logon_srv, const char *comp_name,
|
---|
1429 | const DOM_CRED *clnt_cred)
|
---|
1430 | {
|
---|
1431 | DEBUG(5,("make_clnt_info: %d\n", __LINE__));
|
---|
1432 |
|
---|
1433 | init_clnt_srv(&clnt->login, logon_srv, comp_name);
|
---|
1434 |
|
---|
1435 | if (clnt_cred != NULL) {
|
---|
1436 | clnt->ptr_cred = 1;
|
---|
1437 | memcpy(&clnt->cred, clnt_cred, sizeof(clnt->cred));
|
---|
1438 | } else {
|
---|
1439 | clnt->ptr_cred = 0;
|
---|
1440 | }
|
---|
1441 | }
|
---|
1442 |
|
---|
1443 | /*******************************************************************
|
---|
1444 | Reads or writes a DOM_CLNT_INFO2 structure.
|
---|
1445 | ********************************************************************/
|
---|
1446 |
|
---|
1447 | bool smb_io_clnt_info2(const char *desc, DOM_CLNT_INFO2 *clnt, prs_struct *ps, int depth)
|
---|
1448 | {
|
---|
1449 | if (clnt == NULL)
|
---|
1450 | return False;
|
---|
1451 |
|
---|
1452 | prs_debug(ps, depth, desc, "smb_io_clnt_info2");
|
---|
1453 | depth++;
|
---|
1454 |
|
---|
1455 | if(!prs_align(ps))
|
---|
1456 | return False;
|
---|
1457 |
|
---|
1458 | if(!smb_io_clnt_srv("", &clnt->login, ps, depth))
|
---|
1459 | return False;
|
---|
1460 |
|
---|
1461 | if(!prs_align(ps))
|
---|
1462 | return False;
|
---|
1463 |
|
---|
1464 | if(!prs_uint32("ptr_cred", ps, depth, &clnt->ptr_cred))
|
---|
1465 | return False;
|
---|
1466 | if(!smb_io_cred("", &clnt->cred, ps, depth))
|
---|
1467 | return False;
|
---|
1468 |
|
---|
1469 | return True;
|
---|
1470 | }
|
---|
1471 |
|
---|
1472 | /*******************************************************************
|
---|
1473 | Inits a DOM_CLNT_INFO structure.
|
---|
1474 | ********************************************************************/
|
---|
1475 |
|
---|
1476 | void init_clnt_info(DOM_CLNT_INFO *clnt,
|
---|
1477 | const char *logon_srv, const char *acct_name,
|
---|
1478 | uint16 sec_chan, const char *comp_name,
|
---|
1479 | const DOM_CRED *cred)
|
---|
1480 | {
|
---|
1481 | DEBUG(5,("make_clnt_info\n"));
|
---|
1482 |
|
---|
1483 | init_log_info(&clnt->login, logon_srv, acct_name, sec_chan, comp_name);
|
---|
1484 | memcpy(&clnt->cred, cred, sizeof(clnt->cred));
|
---|
1485 | }
|
---|
1486 |
|
---|
1487 | /*******************************************************************
|
---|
1488 | Reads or writes a DOM_CLNT_INFO structure.
|
---|
1489 | ********************************************************************/
|
---|
1490 |
|
---|
1491 | bool smb_io_clnt_info(const char *desc, DOM_CLNT_INFO *clnt, prs_struct *ps, int depth)
|
---|
1492 | {
|
---|
1493 | if (clnt == NULL)
|
---|
1494 | return False;
|
---|
1495 |
|
---|
1496 | prs_debug(ps, depth, desc, "smb_io_clnt_info");
|
---|
1497 | depth++;
|
---|
1498 |
|
---|
1499 | if(!prs_align(ps))
|
---|
1500 | return False;
|
---|
1501 |
|
---|
1502 | if(!smb_io_log_info("", &clnt->login, ps, depth))
|
---|
1503 | return False;
|
---|
1504 | if(!smb_io_cred("", &clnt->cred, ps, depth))
|
---|
1505 | return False;
|
---|
1506 |
|
---|
1507 | return True;
|
---|
1508 | }
|
---|
1509 |
|
---|
1510 | /*******************************************************************
|
---|
1511 | Inits a DOM_LOGON_ID structure.
|
---|
1512 | ********************************************************************/
|
---|
1513 |
|
---|
1514 | void init_logon_id(DOM_LOGON_ID *logonid, uint32 log_id_low, uint32 log_id_high)
|
---|
1515 | {
|
---|
1516 | DEBUG(5,("make_logon_id: %d\n", __LINE__));
|
---|
1517 |
|
---|
1518 | logonid->low = log_id_low;
|
---|
1519 | logonid->high = log_id_high;
|
---|
1520 | }
|
---|
1521 |
|
---|
1522 | /*******************************************************************
|
---|
1523 | Reads or writes a DOM_LOGON_ID structure.
|
---|
1524 | ********************************************************************/
|
---|
1525 |
|
---|
1526 | bool smb_io_logon_id(const char *desc, DOM_LOGON_ID *logonid, prs_struct *ps, int depth)
|
---|
1527 | {
|
---|
1528 | if (logonid == NULL)
|
---|
1529 | return False;
|
---|
1530 |
|
---|
1531 | prs_debug(ps, depth, desc, "smb_io_logon_id");
|
---|
1532 | depth++;
|
---|
1533 |
|
---|
1534 | if(!prs_align(ps))
|
---|
1535 | return False;
|
---|
1536 |
|
---|
1537 | if(!prs_uint32("low ", ps, depth, &logonid->low ))
|
---|
1538 | return False;
|
---|
1539 | if(!prs_uint32("high", ps, depth, &logonid->high))
|
---|
1540 | return False;
|
---|
1541 |
|
---|
1542 | return True;
|
---|
1543 | }
|
---|
1544 |
|
---|
1545 | /*******************************************************************
|
---|
1546 | Inits an OWF_INFO structure.
|
---|
1547 | ********************************************************************/
|
---|
1548 |
|
---|
1549 | void init_owf_info(OWF_INFO *hash, const uint8 data[16])
|
---|
1550 | {
|
---|
1551 | DEBUG(5,("init_owf_info: %d\n", __LINE__));
|
---|
1552 |
|
---|
1553 | if (data != NULL)
|
---|
1554 | memcpy(hash->data, data, sizeof(hash->data));
|
---|
1555 | else
|
---|
1556 | memset((char *)hash->data, '\0', sizeof(hash->data));
|
---|
1557 | }
|
---|
1558 |
|
---|
1559 | /*******************************************************************
|
---|
1560 | Reads or writes an OWF_INFO structure.
|
---|
1561 | ********************************************************************/
|
---|
1562 |
|
---|
1563 | bool smb_io_owf_info(const char *desc, OWF_INFO *hash, prs_struct *ps, int depth)
|
---|
1564 | {
|
---|
1565 | if (hash == NULL)
|
---|
1566 | return False;
|
---|
1567 |
|
---|
1568 | prs_debug(ps, depth, desc, "smb_io_owf_info");
|
---|
1569 | depth++;
|
---|
1570 |
|
---|
1571 | if(!prs_align(ps))
|
---|
1572 | return False;
|
---|
1573 |
|
---|
1574 | if(!prs_uint8s (False, "data", ps, depth, hash->data, 16))
|
---|
1575 | return False;
|
---|
1576 |
|
---|
1577 | return True;
|
---|
1578 | }
|
---|
1579 |
|
---|
1580 | /*******************************************************************
|
---|
1581 | Reads or writes a DOM_GID structure.
|
---|
1582 | ********************************************************************/
|
---|
1583 |
|
---|
1584 | bool smb_io_gid(const char *desc, DOM_GID *gid, prs_struct *ps, int depth)
|
---|
1585 | {
|
---|
1586 | if (gid == NULL)
|
---|
1587 | return False;
|
---|
1588 |
|
---|
1589 | prs_debug(ps, depth, desc, "smb_io_gid");
|
---|
1590 | depth++;
|
---|
1591 |
|
---|
1592 | if(!prs_align(ps))
|
---|
1593 | return False;
|
---|
1594 |
|
---|
1595 | if(!prs_uint32("g_rid", ps, depth, &gid->g_rid))
|
---|
1596 | return False;
|
---|
1597 | if(!prs_uint32("attr ", ps, depth, &gid->attr))
|
---|
1598 | return False;
|
---|
1599 |
|
---|
1600 | return True;
|
---|
1601 | }
|
---|
1602 |
|
---|
1603 | /*******************************************************************
|
---|
1604 | Reads or writes an POLICY_HND structure.
|
---|
1605 | ********************************************************************/
|
---|
1606 |
|
---|
1607 | bool smb_io_pol_hnd(const char *desc, POLICY_HND *pol, prs_struct *ps, int depth)
|
---|
1608 | {
|
---|
1609 | if (pol == NULL)
|
---|
1610 | return False;
|
---|
1611 |
|
---|
1612 | prs_debug(ps, depth, desc, "smb_io_pol_hnd");
|
---|
1613 | depth++;
|
---|
1614 |
|
---|
1615 | if(!prs_align(ps))
|
---|
1616 | return False;
|
---|
1617 |
|
---|
1618 | if(UNMARSHALLING(ps))
|
---|
1619 | ZERO_STRUCTP(pol);
|
---|
1620 |
|
---|
1621 | if (!prs_uint32("handle_type", ps, depth, &pol->handle_type))
|
---|
1622 | return False;
|
---|
1623 | if (!smb_io_uuid("uuid", (struct GUID*)&pol->uuid, ps, depth))
|
---|
1624 | return False;
|
---|
1625 |
|
---|
1626 | return True;
|
---|
1627 | }
|
---|
1628 |
|
---|
1629 | /*******************************************************************
|
---|
1630 | Create a UNISTR3.
|
---|
1631 | ********************************************************************/
|
---|
1632 |
|
---|
1633 | void init_unistr3(UNISTR3 *str, const char *buf)
|
---|
1634 | {
|
---|
1635 | if (buf == NULL) {
|
---|
1636 | str->uni_str_len=0;
|
---|
1637 | str->str.buffer = NULL;
|
---|
1638 | return;
|
---|
1639 | }
|
---|
1640 |
|
---|
1641 | str->uni_str_len = strlen(buf) + 1;
|
---|
1642 |
|
---|
1643 | if (str->uni_str_len) {
|
---|
1644 | str->str.buffer = TALLOC_ZERO_ARRAY(talloc_tos(), uint16, str->uni_str_len);
|
---|
1645 | if (str->str.buffer == NULL)
|
---|
1646 | smb_panic("init_unistr3: malloc fail");
|
---|
1647 |
|
---|
1648 | rpcstr_push((char *)str->str.buffer, buf, str->uni_str_len * sizeof(uint16), STR_TERMINATE);
|
---|
1649 | } else {
|
---|
1650 | str->str.buffer = NULL;
|
---|
1651 | }
|
---|
1652 | }
|
---|
1653 |
|
---|
1654 | /*******************************************************************
|
---|
1655 | Reads or writes a UNISTR3 structure.
|
---|
1656 | ********************************************************************/
|
---|
1657 |
|
---|
1658 | bool smb_io_unistr3(const char *desc, UNISTR3 *name, prs_struct *ps, int depth)
|
---|
1659 | {
|
---|
1660 | if (name == NULL)
|
---|
1661 | return False;
|
---|
1662 |
|
---|
1663 | prs_debug(ps, depth, desc, "smb_io_unistr3");
|
---|
1664 | depth++;
|
---|
1665 |
|
---|
1666 | if(!prs_align(ps))
|
---|
1667 | return False;
|
---|
1668 |
|
---|
1669 | if(!prs_uint32("uni_str_len", ps, depth, &name->uni_str_len))
|
---|
1670 | return False;
|
---|
1671 |
|
---|
1672 | /* we're done if there is no string */
|
---|
1673 |
|
---|
1674 | if ( name->uni_str_len == 0 )
|
---|
1675 | return True;
|
---|
1676 |
|
---|
1677 | /* don't know if len is specified by uni_str_len member... */
|
---|
1678 | /* assume unicode string is unicode-null-terminated, instead */
|
---|
1679 |
|
---|
1680 | if(!prs_unistr3(True, "unistr", name, ps, depth))
|
---|
1681 | return False;
|
---|
1682 |
|
---|
1683 | return True;
|
---|
1684 | }
|
---|
1685 |
|
---|
1686 | /*******************************************************************
|
---|
1687 | Stream a uint64_struct
|
---|
1688 | ********************************************************************/
|
---|
1689 | bool prs_uint64(const char *name, prs_struct *ps, int depth, uint64 *data64)
|
---|
1690 | {
|
---|
1691 | if (UNMARSHALLING(ps)) {
|
---|
1692 | uint32 high, low;
|
---|
1693 |
|
---|
1694 | if (!prs_uint32(name, ps, depth+1, &low))
|
---|
1695 | return False;
|
---|
1696 |
|
---|
1697 | if (!prs_uint32(name, ps, depth+1, &high))
|
---|
1698 | return False;
|
---|
1699 |
|
---|
1700 | *data64 = ((uint64_t)high << 32) + low;
|
---|
1701 |
|
---|
1702 | return True;
|
---|
1703 | } else {
|
---|
1704 | uint32 high = (*data64) >> 32, low = (*data64) & 0xFFFFFFFF;
|
---|
1705 | return prs_uint32(name, ps, depth+1, &low) &&
|
---|
1706 | prs_uint32(name, ps, depth+1, &high);
|
---|
1707 | }
|
---|
1708 | }
|
---|
1709 |
|
---|
1710 | /*******************************************************************
|
---|
1711 | reads or writes a BUFHDR2 structure.
|
---|
1712 | ********************************************************************/
|
---|
1713 | bool smb_io_bufhdr2(const char *desc, BUFHDR2 *hdr, prs_struct *ps, int depth)
|
---|
1714 | {
|
---|
1715 | prs_debug(ps, depth, desc, "smb_io_bufhdr2");
|
---|
1716 | depth++;
|
---|
1717 |
|
---|
1718 | if (!prs_align(ps))
|
---|
1719 | return False;
|
---|
1720 | if (!prs_uint32("info_level", ps, depth, &(hdr->info_level)))
|
---|
1721 | return False;
|
---|
1722 | if (!prs_uint32("length ", ps, depth, &(hdr->length )))
|
---|
1723 | return False;
|
---|
1724 | if (!prs_uint32("buffer ", ps, depth, &(hdr->buffer )))
|
---|
1725 | return False;
|
---|
1726 |
|
---|
1727 | return True;
|
---|
1728 | }
|
---|
1729 |
|
---|
1730 | /*******************************************************************
|
---|
1731 | reads or writes a BUFHDR4 structure.
|
---|
1732 | ********************************************************************/
|
---|
1733 | bool smb_io_bufhdr4(const char *desc, BUFHDR4 *hdr, prs_struct *ps, int depth)
|
---|
1734 | {
|
---|
1735 | prs_debug(ps, depth, desc, "smb_io_bufhdr4");
|
---|
1736 | depth++;
|
---|
1737 |
|
---|
1738 | if (!prs_align(ps))
|
---|
1739 | return False;
|
---|
1740 | if (!prs_uint32("size", ps, depth, &hdr->size))
|
---|
1741 | return False;
|
---|
1742 | if (!prs_uint32("buffer", ps, depth, &hdr->buffer))
|
---|
1743 | return False;
|
---|
1744 |
|
---|
1745 | return True;
|
---|
1746 | }
|
---|
1747 |
|
---|
1748 | /*******************************************************************
|
---|
1749 | reads or writes a RPC_DATA_BLOB structure.
|
---|
1750 | ********************************************************************/
|
---|
1751 |
|
---|
1752 | bool smb_io_rpc_blob(const char *desc, RPC_DATA_BLOB *blob, prs_struct *ps, int depth)
|
---|
1753 | {
|
---|
1754 | prs_debug(ps, depth, desc, "smb_io_rpc_blob");
|
---|
1755 | depth++;
|
---|
1756 |
|
---|
1757 | if (!prs_align(ps))
|
---|
1758 | return False;
|
---|
1759 | if ( !prs_uint32("buf_len", ps, depth, &blob->buf_len) )
|
---|
1760 | return False;
|
---|
1761 |
|
---|
1762 | if ( blob->buf_len == 0 )
|
---|
1763 | return True;
|
---|
1764 |
|
---|
1765 | if (UNMARSHALLING(ps)) {
|
---|
1766 | blob->buffer = PRS_ALLOC_MEM(ps, uint8, blob->buf_len);
|
---|
1767 | if (!blob->buffer) {
|
---|
1768 | return False;
|
---|
1769 | }
|
---|
1770 | }
|
---|
1771 |
|
---|
1772 | if ( !prs_uint8s(True, "buffer", ps, depth, blob->buffer, blob->buf_len) )
|
---|
1773 | return False;
|
---|
1774 |
|
---|
1775 | return True;
|
---|
1776 | }
|
---|
1777 |
|
---|
1778 | /*******************************************************************
|
---|
1779 | creates a UNIHDR structure.
|
---|
1780 | ********************************************************************/
|
---|
1781 |
|
---|
1782 | bool make_uni_hdr(UNIHDR *hdr, int len)
|
---|
1783 | {
|
---|
1784 | if (hdr == NULL)
|
---|
1785 | {
|
---|
1786 | return False;
|
---|
1787 | }
|
---|
1788 | hdr->uni_str_len = 2 * len;
|
---|
1789 | hdr->uni_max_len = 2 * len;
|
---|
1790 | hdr->buffer = len != 0 ? 1 : 0;
|
---|
1791 |
|
---|
1792 | return True;
|
---|
1793 | }
|
---|
1794 |
|
---|
1795 | /*******************************************************************
|
---|
1796 | creates a BUFHDR2 structure.
|
---|
1797 | ********************************************************************/
|
---|
1798 | bool make_bufhdr2(BUFHDR2 *hdr, uint32 info_level, uint32 length, uint32 buffer)
|
---|
1799 | {
|
---|
1800 | hdr->info_level = info_level;
|
---|
1801 | hdr->length = length;
|
---|
1802 | hdr->buffer = buffer;
|
---|
1803 |
|
---|
1804 | return True;
|
---|
1805 | }
|
---|
1806 |
|
---|
1807 | /*******************************************************************
|
---|
1808 | return the length of a UNISTR string.
|
---|
1809 | ********************************************************************/
|
---|
1810 |
|
---|
1811 | uint32 str_len_uni(UNISTR *source)
|
---|
1812 | {
|
---|
1813 | uint32 i=0;
|
---|
1814 |
|
---|
1815 | if (!source->buffer)
|
---|
1816 | return 0;
|
---|
1817 |
|
---|
1818 | while (source->buffer[i])
|
---|
1819 | i++;
|
---|
1820 |
|
---|
1821 | return i;
|
---|
1822 | }
|
---|
1823 |
|
---|
1824 | /*******************************************************************
|
---|
1825 | Verifies policy handle
|
---|
1826 | ********************************************************************/
|
---|
1827 |
|
---|
1828 | bool policy_handle_is_valid(const POLICY_HND *hnd)
|
---|
1829 | {
|
---|
1830 | POLICY_HND zero_pol;
|
---|
1831 |
|
---|
1832 | ZERO_STRUCT(zero_pol);
|
---|
1833 | return ((memcmp(&zero_pol, hnd, sizeof(POLICY_HND)) == 0) ? false : true );
|
---|
1834 | }
|
---|