source: branches/samba-3.0/source/rpc_parse/parse_misc.c

Last change on this file was 39, checked in by Paul Smedley, 18 years ago

Upgrade source to 3.0.25a

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