Use ntvfs session close to close downstream session
[Samba/vfs_proxy.git] / source3 / rpc_parse / parse_misc.c
blob169e5cb560b0b97f3428a898fc9c64fde684518e
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.
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.
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/>.
23 #include "includes.h"
25 #undef DBGC_CLASS
26 #define DBGC_CLASS DBGC_RPC_PARSE
28 /*******************************************************************
29 Reads or writes a UTIME type.
30 ********************************************************************/
32 static bool smb_io_utime(const char *desc, UTIME *t, prs_struct *ps, int depth)
34 if (t == NULL)
35 return False;
37 prs_debug(ps, depth, desc, "smb_io_utime");
38 depth++;
40 if(!prs_align(ps))
41 return False;
43 if(!prs_uint32 ("time", ps, depth, &t->time))
44 return False;
46 return True;
49 /*******************************************************************
50 Reads or writes an NTTIME structure.
51 ********************************************************************/
53 bool smb_io_time(const char *desc, NTTIME *nttime, prs_struct *ps, int depth)
55 uint32 low, high;
56 if (nttime == NULL)
57 return False;
59 prs_debug(ps, depth, desc, "smb_io_time");
60 depth++;
62 if(!prs_align(ps))
63 return False;
65 if (MARSHALLING(ps)) {
66 low = *nttime & 0xFFFFFFFF;
67 high = *nttime >> 32;
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;
75 if (UNMARSHALLING(ps)) {
76 *nttime = (((uint64_t)high << 32) + low);
79 return True;
82 /*******************************************************************
83 Reads or writes an NTTIME structure.
84 ********************************************************************/
86 bool smb_io_nttime(const char *desc, prs_struct *ps, int depth, NTTIME *nttime)
88 return smb_io_time( desc, nttime, ps, depth );
91 /*******************************************************************
92 Gets an enumeration handle from an ENUM_HND structure.
93 ********************************************************************/
95 uint32 get_enum_hnd(ENUM_HND *enh)
97 return (enh && enh->ptr_hnd != 0) ? enh->handle : 0;
100 /*******************************************************************
101 Inits an ENUM_HND structure.
102 ********************************************************************/
104 void init_enum_hnd(ENUM_HND *enh, uint32 hnd)
106 DEBUG(5,("smb_io_enum_hnd\n"));
108 enh->ptr_hnd = (hnd != 0) ? 1 : 0;
109 enh->handle = hnd;
112 /*******************************************************************
113 Reads or writes an ENUM_HND structure.
114 ********************************************************************/
116 bool smb_io_enum_hnd(const char *desc, ENUM_HND *hnd, prs_struct *ps, int depth)
118 if (hnd == NULL)
119 return False;
121 prs_debug(ps, depth, desc, "smb_io_enum_hnd");
122 depth++;
124 if(!prs_align(ps))
125 return False;
127 if(!prs_uint32("ptr_hnd", ps, depth, &hnd->ptr_hnd)) /* pointer */
128 return False;
130 if (hnd->ptr_hnd != 0) {
131 if(!prs_uint32("handle ", ps, depth, &hnd->handle )) /* enum handle */
132 return False;
135 return True;
138 /*******************************************************************
139 Reads or writes a DOM_SID structure.
140 ********************************************************************/
142 bool smb_io_dom_sid(const char *desc, DOM_SID *sid, prs_struct *ps, int depth)
144 int i;
146 if (sid == NULL)
147 return False;
149 prs_debug(ps, depth, desc, "smb_io_dom_sid");
150 depth++;
152 if(!prs_uint8 ("sid_rev_num", ps, depth, &sid->sid_rev_num))
153 return False;
155 if(!prs_uint8 ("num_auths ", ps, depth, &sid->num_auths))
156 return False;
158 for (i = 0; i < 6; i++)
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;
166 /* oops! XXXX should really issue a warning here... */
167 if (sid->num_auths > MAXSUBAUTHS)
168 sid->num_auths = MAXSUBAUTHS;
170 if(!prs_uint32s(False, "sub_auths ", ps, depth, sid->sub_auths, sid->num_auths))
171 return False;
173 return True;
176 /*******************************************************************
177 Inits a DOM_SID2 structure.
178 ********************************************************************/
180 void init_dom_sid2(DOM_SID2 *sid2, const DOM_SID *sid)
182 sid2->sid = *sid;
183 sid2->num_auths = sid2->sid.num_auths;
186 /*******************************************************************
187 Reads or writes a DOM_SID2 structure.
188 ********************************************************************/
190 bool smb_io_dom_sid2_p(const char *desc, prs_struct *ps, int depth, DOM_SID2 **sid2)
192 uint32 data_p;
194 /* caputure the pointer value to stream */
196 data_p = *sid2 ? 0xf000baaa : 0;
198 if ( !prs_uint32("dom_sid2_p", ps, depth, &data_p ))
199 return False;
201 /* we're done if there is no data */
203 if ( !data_p )
204 return True;
206 if (UNMARSHALLING(ps)) {
207 if ( !(*sid2 = PRS_ALLOC_MEM(ps, DOM_SID2, 1)) )
208 return False;
211 return True;
213 /*******************************************************************
214 Reads or writes a DOM_SID2 structure.
215 ********************************************************************/
217 bool smb_io_dom_sid2(const char *desc, DOM_SID2 *sid, prs_struct *ps, int depth)
219 if (sid == NULL)
220 return False;
222 prs_debug(ps, depth, desc, "smb_io_dom_sid2");
223 depth++;
225 if(!prs_align(ps))
226 return False;
228 if(!prs_uint32("num_auths", ps, depth, &sid->num_auths))
229 return False;
231 if(!smb_io_dom_sid("sid", &sid->sid, ps, depth))
232 return False;
234 return True;
237 /*******************************************************************
238 Reads or writes a struct GUID
239 ********************************************************************/
241 bool smb_io_uuid(const char *desc, struct GUID *uuid,
242 prs_struct *ps, int depth)
244 if (uuid == NULL)
245 return False;
247 prs_debug(ps, depth, desc, "smb_io_uuid");
248 depth++;
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;
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;
262 return True;
265 /*******************************************************************
266 creates a STRHDR structure.
267 ********************************************************************/
269 void init_str_hdr(STRHDR *hdr, int max_len, int len, uint32 buffer)
271 hdr->str_max_len = max_len;
272 hdr->str_str_len = len;
273 hdr->buffer = buffer;
276 /*******************************************************************
277 Reads or writes a STRHDR structure.
278 ********************************************************************/
280 bool smb_io_strhdr(const char *desc, STRHDR *hdr, prs_struct *ps, int depth)
282 if (hdr == NULL)
283 return False;
285 prs_debug(ps, depth, desc, "smb_io_strhdr");
286 depth++;
288 if(!prs_align(ps))
289 return False;
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;
298 return True;
301 /*******************************************************************
302 Inits a UNIHDR structure.
303 ********************************************************************/
305 void init_uni_hdr(UNIHDR *hdr, UNISTR2 *str2)
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;
312 /*******************************************************************
313 Reads or writes a UNIHDR structure.
314 ********************************************************************/
316 bool smb_io_unihdr(const char *desc, UNIHDR *hdr, prs_struct *ps, int depth)
318 if (hdr == NULL)
319 return False;
321 prs_debug(ps, depth, desc, "smb_io_unihdr");
322 depth++;
324 if(!prs_align(ps))
325 return False;
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;
334 return True;
337 /*******************************************************************
338 Inits a BUFHDR structure.
339 ********************************************************************/
341 void init_buf_hdr(BUFHDR *hdr, int max_len, int len)
343 hdr->buf_max_len = max_len;
344 hdr->buf_len = len;
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 ********************************************************************/
352 bool smb_io_hdrbuf_pre(const char *desc, BUFHDR *hdr, prs_struct *ps, int depth, uint32 *offset)
354 (*offset) = prs_offset(ps);
355 if (ps->io) {
357 /* reading. */
359 if(!smb_io_hdrbuf(desc, hdr, ps, depth))
360 return False;
362 } else {
364 /* writing. */
366 if(!prs_set_offset(ps, prs_offset(ps) + (sizeof(uint32) * 2)))
367 return False;
370 return True;
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 ********************************************************************/
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)
381 if (!ps->io) {
382 /* writing: go back and do a retrospective job. i hate this */
384 uint32 old_offset = prs_offset(ps);
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;
392 if(!prs_set_offset(ps, old_offset))
393 return False;
396 return True;
399 /*******************************************************************
400 Reads or writes a BUFHDR structure.
401 ********************************************************************/
403 bool smb_io_hdrbuf(const char *desc, BUFHDR *hdr, prs_struct *ps, int depth)
405 if (hdr == NULL)
406 return False;
408 prs_debug(ps, depth, desc, "smb_io_hdrbuf");
409 depth++;
411 if(!prs_align(ps))
412 return False;
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;
419 return True;
422 /*******************************************************************
423 Inits a UNISTR structure.
424 ********************************************************************/
426 void init_unistr(UNISTR *str, const char *buf)
428 size_t len;
430 if (buf == NULL) {
431 str->buffer = NULL;
432 return;
435 len = rpcstr_push_talloc(talloc_tos(), &str->buffer, buf);
436 if (len == (size_t)-1) {
437 str->buffer = NULL;
441 /*******************************************************************
442 reads or writes a UNISTR structure.
443 XXXX NOTE: UNISTR structures NEED to be null-terminated.
444 ********************************************************************/
446 bool smb_io_unistr(const char *desc, UNISTR *uni, prs_struct *ps, int depth)
448 if (uni == NULL)
449 return False;
451 prs_debug(ps, depth, desc, "smb_io_unistr");
452 depth++;
454 if(!prs_unistr("unistr", ps, depth, uni))
455 return False;
457 return True;
460 /*******************************************************************
461 Allocate the RPC_DATA_BLOB memory.
462 ********************************************************************/
464 static void create_rpc_blob(RPC_DATA_BLOB *str, size_t len)
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;
477 /*******************************************************************
478 Inits a RPC_DATA_BLOB structure from a uint32
479 ********************************************************************/
481 void init_rpc_blob_uint32(RPC_DATA_BLOB *str, uint32 val)
483 ZERO_STRUCTP(str);
485 /* set up string lengths. */
486 create_rpc_blob(str, sizeof(uint32));
487 SIVAL(str->buffer, 0, val);
490 /*******************************************************************
491 Inits a RPC_DATA_BLOB structure.
492 ********************************************************************/
494 void init_rpc_blob_str(RPC_DATA_BLOB *str, const char *buf, int len)
496 ZERO_STRUCTP(str);
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);
505 /*******************************************************************
506 Inits a RPC_DATA_BLOB structure from a hex string.
507 ********************************************************************/
509 void init_rpc_blob_hex(RPC_DATA_BLOB *str, const char *buf)
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);
520 /*******************************************************************
521 Inits a RPC_DATA_BLOB structure.
522 ********************************************************************/
524 void init_rpc_blob_bytes(RPC_DATA_BLOB *str, uint8 *buf, size_t len)
526 ZERO_STRUCTP(str);
528 /* max buffer size (allocated size) */
529 if (buf != NULL && len) {
530 create_rpc_blob(str, len);
531 memcpy(str->buffer, buf, len);
533 str->buf_len = len;
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)
542 prs_debug(ps, depth, desc, "smb_io_buffer5");
543 depth++;
545 if (buf5 == NULL) return False;
547 if(!prs_align(ps))
548 return False;
549 if(!prs_uint32("buf_len", ps, depth, &buf5->buf_len))
550 return False;
552 if(buf5->buf_len) {
553 if(!prs_buffer5(True, "buffer" , ps, depth, buf5))
554 return False;
557 return True;
560 /*******************************************************************
561 creates a UNISTR2 structure: sets up the buffer, too
562 ********************************************************************/
564 void init_buf_unistr2(UNISTR2 *str, uint32 *ptr, const char *buf)
566 if (buf != NULL) {
567 *ptr = 1;
568 init_unistr2(str, buf, UNI_STR_TERMINATE);
569 } else {
570 *ptr = 0;
571 init_unistr2(str, NULL, UNI_FLAGS_NONE);
576 /*******************************************************************
577 Copies a UNISTR2 structure.
578 ********************************************************************/
580 void copy_unistr2(UNISTR2 *str, const UNISTR2 *from)
582 if (from->buffer == NULL) {
583 ZERO_STRUCTP(str);
584 return;
587 SMB_ASSERT(from->uni_max_len >= from->uni_str_len);
589 str->uni_max_len = from->uni_max_len;
590 str->offset = from->offset;
591 str->uni_str_len = from->uni_str_len;
593 /* the string buffer is allocated to the maximum size
594 (the the length of the source string) to prevent
595 reallocation of memory. */
596 if (str->buffer == NULL) {
597 if (str->uni_max_len) {
598 str->buffer = (uint16 *)TALLOC_ZERO_ARRAY(talloc_tos(), uint16, str->uni_max_len);
599 if ((str->buffer == NULL)) {
600 smb_panic("copy_unistr2: talloc fail");
601 return;
603 /* copy the string */
604 memcpy(str->buffer, from->buffer, str->uni_max_len*sizeof(uint16));
605 } else {
606 str->buffer = NULL;
611 /*******************************************************************
612 Creates a STRING2 structure.
613 ********************************************************************/
615 void init_string2(STRING2 *str, const char *buf, size_t max_len, size_t str_len)
617 /* set up string lengths. */
618 SMB_ASSERT(max_len >= str_len);
620 /* Ensure buf is valid if str_len was set. Coverity check. */
621 if (str_len && !buf) {
622 return;
625 str->str_max_len = max_len;
626 str->offset = 0;
627 str->str_str_len = str_len;
629 /* store the string */
630 if(str_len != 0) {
631 str->buffer = (uint8 *)TALLOC_ZERO(talloc_tos(),
632 str->str_max_len);
633 if (str->buffer == NULL)
634 smb_panic("init_string2: malloc fail");
635 memcpy(str->buffer, buf, str_len);
639 /*******************************************************************
640 Reads or writes a STRING2 structure.
641 XXXX NOTE: STRING2 structures need NOT be null-terminated.
642 the str_str_len member tells you how long the string is;
643 the str_max_len member tells you how large the buffer is.
644 ********************************************************************/
646 bool smb_io_string2(const char *desc, STRING2 *str2, uint32 buffer, prs_struct *ps, int depth)
648 if (str2 == NULL)
649 return False;
651 if (buffer) {
653 prs_debug(ps, depth, desc, "smb_io_string2");
654 depth++;
656 if(!prs_align(ps))
657 return False;
659 if(!prs_uint32("str_max_len", ps, depth, &str2->str_max_len))
660 return False;
661 if(!prs_uint32("offset ", ps, depth, &str2->offset))
662 return False;
663 if(!prs_uint32("str_str_len", ps, depth, &str2->str_str_len))
664 return False;
666 /* buffer advanced by indicated length of string
667 NOT by searching for null-termination */
668 if(!prs_string2(True, "buffer ", ps, depth, str2))
669 return False;
671 } else {
673 prs_debug(ps, depth, desc, "smb_io_string2 - NULL");
674 depth++;
675 memset((char *)str2, '\0', sizeof(*str2));
679 return True;
682 /*******************************************************************
683 Inits a UNISTR2 structure.
684 ********************************************************************/
686 void init_unistr2(UNISTR2 *str, const char *buf, enum unistr2_term_codes flags)
688 size_t len = 0;
689 uint32 num_chars = 0;
691 if (buf) {
692 /* We always null terminate the copy. */
693 len = strlen(buf) + 1;
694 if ( flags == UNI_STR_DBLTERMINATE )
695 len++;
698 if (buf == NULL || len == 0) {
699 /* no buffer -- nothing to do */
700 str->uni_max_len = 0;
701 str->offset = 0;
702 str->uni_str_len = 0;
704 return;
708 str->buffer = TALLOC_ZERO_ARRAY(talloc_tos(), uint16, len);
709 if (str->buffer == NULL) {
710 smb_panic("init_unistr2: malloc fail");
711 return;
714 /* Ensure len is the length in *bytes* */
715 len *= sizeof(uint16);
718 * The UNISTR2 must be initialized !!!
719 * jfm, 7/7/2001.
721 if (buf) {
722 rpcstr_push((char *)str->buffer, buf, len, STR_TERMINATE);
723 num_chars = strlen_w(str->buffer);
724 if (flags == UNI_STR_TERMINATE || flags == UNI_MAXLEN_TERMINATE) {
725 num_chars++;
727 if ( flags == UNI_STR_DBLTERMINATE )
728 num_chars += 2;
731 str->uni_max_len = num_chars;
732 str->offset = 0;
733 str->uni_str_len = num_chars;
734 if ( num_chars && ((flags == UNI_MAXLEN_TERMINATE) || (flags == UNI_BROKEN_NON_NULL)) )
735 str->uni_max_len++;
738 /*******************************************************************
739 Inits a UNISTR4 structure.
740 ********************************************************************/
742 void init_unistr4(UNISTR4 *uni4, const char *buf, enum unistr2_term_codes flags)
744 uni4->string = TALLOC_P( talloc_tos(), UNISTR2 );
745 if (!uni4->string) {
746 smb_panic("init_unistr4: talloc fail");
747 return;
749 init_unistr2( uni4->string, buf, flags );
751 uni4->length = 2 * (uni4->string->uni_str_len);
752 uni4->size = 2 * (uni4->string->uni_max_len);
755 void init_unistr4_w( TALLOC_CTX *ctx, UNISTR4 *uni4, const smb_ucs2_t *buf )
757 uni4->string = TALLOC_P( ctx, UNISTR2 );
758 if (!uni4->string) {
759 smb_panic("init_unistr4_w: talloc fail");
760 return;
762 init_unistr2_w( ctx, uni4->string, buf );
764 uni4->length = 2 * (uni4->string->uni_str_len);
765 uni4->size = 2 * (uni4->string->uni_max_len);
768 /**
769 * Inits a UNISTR2 structure.
770 * @param ctx talloc context to allocate string on
771 * @param str pointer to string to create
772 * @param buf UCS2 null-terminated buffer to init from
775 void init_unistr2_w(TALLOC_CTX *ctx, UNISTR2 *str, const smb_ucs2_t *buf)
777 uint32 len = buf ? strlen_w(buf) : 0;
779 ZERO_STRUCTP(str);
781 /* set up string lengths. */
782 str->uni_max_len = len;
783 str->offset = 0;
784 str->uni_str_len = len;
786 if (len + 1) {
787 str->buffer = TALLOC_ZERO_ARRAY(ctx, uint16, len + 1);
788 if (str->buffer == NULL) {
789 smb_panic("init_unistr2_w: talloc fail");
790 return;
792 } else {
793 str->buffer = NULL;
797 * don't move this test above ! The UNISTR2 must be initialized !!!
798 * jfm, 7/7/2001.
800 if (buf==NULL)
801 return;
803 /* Yes, this is a strncpy( foo, bar, strlen(bar)) - but as
804 long as the buffer above is talloc()ed correctly then this
805 is the correct thing to do */
806 if (len+1) {
807 strncpy_w(str->buffer, buf, len + 1);
811 /*******************************************************************
812 Inits a UNISTR2 structure from a UNISTR
813 ********************************************************************/
815 void init_unistr2_from_unistr(TALLOC_CTX *ctx, UNISTR2 *to, const UNISTR *from)
817 uint32 i;
819 /* the destination UNISTR2 should never be NULL.
820 if it is it is a programming error */
822 /* if the source UNISTR is NULL, then zero out
823 the destination string and return */
824 ZERO_STRUCTP (to);
825 if ((from == NULL) || (from->buffer == NULL))
826 return;
828 /* get the length; UNISTR must be NULL terminated */
829 i = 0;
830 while ((from->buffer)[i]!='\0')
831 i++;
832 i++; /* one more to catch the terminating NULL */
833 /* is this necessary -- jerry? I need to think */
835 /* set up string lengths; uni_max_len is set to i+1
836 because we need to account for the final NULL termination */
837 to->uni_max_len = i;
838 to->offset = 0;
839 to->uni_str_len = i;
841 /* allocate the space and copy the string buffer */
842 if (i) {
843 to->buffer = TALLOC_ZERO_ARRAY(ctx, uint16, i);
844 if (to->buffer == NULL)
845 smb_panic("init_unistr2_from_unistr: talloc fail");
846 memcpy(to->buffer, from->buffer, i*sizeof(uint16));
847 } else {
848 to->buffer = NULL;
850 return;
853 /*******************************************************************
854 Inits a UNISTR2 structure from a DATA_BLOB.
855 The length of the data_blob must count the bytes of the buffer.
856 Copies the blob data.
857 ********************************************************************/
859 void init_unistr2_from_datablob(UNISTR2 *str, DATA_BLOB *blob)
861 /* Allocs the unistring */
862 init_unistr2(str, NULL, UNI_FLAGS_NONE);
864 /* Sets the values */
865 str->uni_str_len = blob->length / sizeof(uint16);
866 str->uni_max_len = str->uni_str_len;
867 str->offset = 0;
868 if (blob->length) {
869 str->buffer = (uint16 *) memdup(blob->data, blob->length);
870 } else {
871 str->buffer = NULL;
873 if ((str->buffer == NULL) && (blob->length > 0)) {
874 smb_panic("init_unistr2_from_datablob: malloc fail");
878 /*******************************************************************
879 UNISTR2* are a little different in that the pointer and the UNISTR2
880 are not necessarily read/written back to back. So we break it up
881 into 2 separate functions.
882 See SPOOL_USER_1 in include/rpc_spoolss.h for an example.
883 ********************************************************************/
885 bool prs_io_unistr2_p(const char *desc, prs_struct *ps, int depth, UNISTR2 **uni2)
887 uint32 data_p;
889 /* caputure the pointer value to stream */
891 data_p = *uni2 ? 0xf000baaa : 0;
893 if ( !prs_uint32("ptr", ps, depth, &data_p ))
894 return False;
896 /* we're done if there is no data */
898 if ( !data_p )
899 return True;
901 if (UNMARSHALLING(ps)) {
902 if ( !(*uni2 = PRS_ALLOC_MEM(ps, UNISTR2, 1)) )
903 return False;
906 return True;
909 /*******************************************************************
910 now read/write the actual UNISTR2. Memory for the UNISTR2 (but
911 not UNISTR2.buffer) has been allocated previously by prs_unistr2_p()
912 ********************************************************************/
914 bool prs_io_unistr2(const char *desc, prs_struct *ps, int depth, UNISTR2 *uni2 )
916 /* just return true if there is no pointer to deal with.
917 the memory must have been previously allocated on unmarshalling
918 by prs_unistr2_p() */
920 if ( !uni2 )
921 return True;
923 /* just pass off to smb_io_unstr2() passing the uni2 address as
924 the pointer (like you would expect) */
926 return smb_io_unistr2( desc, uni2, uni2 ? 1 : 0, ps, depth );
929 /*******************************************************************
930 Reads or writes a UNISTR2 structure.
931 XXXX NOTE: UNISTR2 structures need NOT be null-terminated.
932 the uni_str_len member tells you how long the string is;
933 the uni_max_len member tells you how large the buffer is.
934 ********************************************************************/
936 bool smb_io_unistr2(const char *desc, UNISTR2 *uni2, uint32 buffer, prs_struct *ps, int depth)
938 if (uni2 == NULL)
939 return False;
941 if (buffer) {
943 prs_debug(ps, depth, desc, "smb_io_unistr2");
944 depth++;
946 if(!prs_align(ps))
947 return False;
949 if(!prs_uint32("uni_max_len", ps, depth, &uni2->uni_max_len))
950 return False;
951 if(!prs_uint32("offset ", ps, depth, &uni2->offset))
952 return False;
953 if(!prs_uint32("uni_str_len", ps, depth, &uni2->uni_str_len))
954 return False;
956 /* buffer advanced by indicated length of string
957 NOT by searching for null-termination */
958 if(!prs_unistr2(True, "buffer ", ps, depth, uni2))
959 return False;
961 } else {
963 prs_debug(ps, depth, desc, "smb_io_unistr2 - NULL");
964 depth++;
965 memset((char *)uni2, '\0', sizeof(*uni2));
969 return True;
972 /*******************************************************************
973 now read/write UNISTR4
974 ********************************************************************/
976 bool prs_unistr4(const char *desc, prs_struct *ps, int depth, UNISTR4 *uni4)
978 void *ptr;
979 prs_debug(ps, depth, desc, "prs_unistr4");
980 depth++;
982 if ( !prs_uint16("length", ps, depth, &uni4->length ))
983 return False;
984 if ( !prs_uint16("size", ps, depth, &uni4->size ))
985 return False;
987 ptr = uni4->string;
989 if ( !prs_pointer( desc, ps, depth, &ptr, sizeof(UNISTR2), (PRS_POINTER_CAST)prs_io_unistr2 ) )
990 return False;
992 uni4->string = (UNISTR2 *)ptr;
994 return True;
997 /*******************************************************************
998 now read/write UNISTR4 header
999 ********************************************************************/
1001 bool prs_unistr4_hdr(const char *desc, prs_struct *ps, int depth, UNISTR4 *uni4)
1003 prs_debug(ps, depth, desc, "prs_unistr4_hdr");
1004 depth++;
1006 if ( !prs_uint16("length", ps, depth, &uni4->length) )
1007 return False;
1008 if ( !prs_uint16("size", ps, depth, &uni4->size) )
1009 return False;
1010 if ( !prs_io_unistr2_p(desc, ps, depth, &uni4->string) )
1011 return False;
1013 return True;
1016 /*******************************************************************
1017 now read/write UNISTR4 string
1018 ********************************************************************/
1020 bool prs_unistr4_str(const char *desc, prs_struct *ps, int depth, UNISTR4 *uni4)
1022 prs_debug(ps, depth, desc, "prs_unistr4_str");
1023 depth++;
1025 if ( !prs_io_unistr2(desc, ps, depth, uni4->string) )
1026 return False;
1028 return True;
1031 /*******************************************************************
1032 Reads or writes a UNISTR4_ARRAY structure.
1033 ********************************************************************/
1035 bool prs_unistr4_array(const char *desc, prs_struct *ps, int depth, UNISTR4_ARRAY *array )
1037 unsigned int i;
1039 prs_debug(ps, depth, desc, "prs_unistr4_array");
1040 depth++;
1042 if(!prs_uint32("count", ps, depth, &array->count))
1043 return False;
1045 if (UNMARSHALLING(ps)) {
1046 if (array->count) {
1047 if ( !(array->strings = TALLOC_ZERO_ARRAY( talloc_tos(), UNISTR4, array->count)) )
1048 return False;
1049 } else {
1050 array->strings = NULL;
1054 /* write the headers and then the actual string buffer */
1056 for ( i=0; i<array->count; i++ ) {
1057 if ( !prs_unistr4_hdr( "string", ps, depth, &array->strings[i]) )
1058 return False;
1061 for (i=0;i<array->count;i++) {
1062 if ( !prs_unistr4_str("string", ps, depth, &array->strings[i]) )
1063 return False;
1066 return True;
1069 /********************************************************************
1070 initialise a UNISTR_ARRAY from a char**
1071 ********************************************************************/
1073 bool init_unistr4_array( UNISTR4_ARRAY *array, uint32 count, const char **strings )
1075 unsigned int i;
1077 array->count = count;
1079 /* allocate memory for the array of UNISTR4 objects */
1081 if (array->count) {
1082 if ( !(array->strings = TALLOC_ZERO_ARRAY(talloc_tos(), UNISTR4, count )) )
1083 return False;
1084 } else {
1085 array->strings = NULL;
1088 for ( i=0; i<count; i++ )
1089 init_unistr4( &array->strings[i], strings[i], UNI_STR_TERMINATE );
1091 return True;
1094 /*******************************************************************
1095 Inits a DOM_RID structure.
1096 ********************************************************************/
1098 void init_dom_rid(DOM_RID *prid, uint32 rid, uint16 type, uint32 idx)
1100 prid->type = type;
1101 prid->rid = rid;
1102 prid->rid_idx = idx;
1105 /*******************************************************************
1106 Reads or writes a DOM_RID structure.
1107 ********************************************************************/
1109 bool smb_io_dom_rid(const char *desc, DOM_RID *rid, prs_struct *ps, int depth)
1111 if (rid == NULL)
1112 return False;
1114 prs_debug(ps, depth, desc, "smb_io_dom_rid");
1115 depth++;
1117 if(!prs_align(ps))
1118 return False;
1120 if(!prs_uint16("type ", ps, depth, &rid->type))
1121 return False;
1122 if(!prs_align(ps))
1123 return False;
1124 if(!prs_uint32("rid ", ps, depth, &rid->rid))
1125 return False;
1126 if(!prs_uint32("rid_idx", ps, depth, &rid->rid_idx))
1127 return False;
1129 return True;
1132 /*******************************************************************
1133 Reads or writes a DOM_RID2 structure.
1134 ********************************************************************/
1136 bool smb_io_dom_rid2(const char *desc, DOM_RID2 *rid, prs_struct *ps, int depth)
1138 if (rid == NULL)
1139 return False;
1141 prs_debug(ps, depth, desc, "smb_io_dom_rid2");
1142 depth++;
1144 if(!prs_align(ps))
1145 return False;
1147 if(!prs_uint16("type ", ps, depth, &rid->type))
1148 return False;
1149 if(!prs_align(ps))
1150 return False;
1151 if(!prs_uint32("rid ", ps, depth, &rid->rid))
1152 return False;
1153 if(!prs_uint32("rid_idx", ps, depth, &rid->rid_idx))
1154 return False;
1155 if(!prs_uint32("unknown", ps, depth, &rid->unknown))
1156 return False;
1158 return True;
1162 /*******************************************************************
1163 creates a DOM_RID3 structure.
1164 ********************************************************************/
1166 void init_dom_rid3(DOM_RID3 *rid3, uint32 rid, uint8 type)
1168 rid3->rid = rid;
1169 rid3->type1 = type;
1170 rid3->ptr_type = 0x1; /* non-zero, basically. */
1171 rid3->type2 = 0x1;
1172 rid3->unk = type;
1175 /*******************************************************************
1176 reads or writes a DOM_RID3 structure.
1177 ********************************************************************/
1179 bool smb_io_dom_rid3(const char *desc, DOM_RID3 *rid3, prs_struct *ps, int depth)
1181 if (rid3 == NULL)
1182 return False;
1184 prs_debug(ps, depth, desc, "smb_io_dom_rid3");
1185 depth++;
1187 if(!prs_align(ps))
1188 return False;
1190 if(!prs_uint32("rid ", ps, depth, &rid3->rid))
1191 return False;
1192 if(!prs_uint32("type1 ", ps, depth, &rid3->type1))
1193 return False;
1194 if(!prs_uint32("ptr_type", ps, depth, &rid3->ptr_type))
1195 return False;
1196 if(!prs_uint32("type2 ", ps, depth, &rid3->type2))
1197 return False;
1198 if(!prs_uint32("unk ", ps, depth, &rid3->unk))
1199 return False;
1201 return True;
1204 /*******************************************************************
1205 Inits a DOM_RID4 structure.
1206 ********************************************************************/
1208 void init_dom_rid4(DOM_RID4 *rid4, uint16 unknown, uint16 attr, uint32 rid)
1210 rid4->unknown = unknown;
1211 rid4->attr = attr;
1212 rid4->rid = rid;
1215 /*******************************************************************
1216 Inits a DOM_CLNT_SRV structure.
1217 ********************************************************************/
1219 void init_clnt_srv(DOM_CLNT_SRV *logcln, const char *logon_srv,
1220 const char *comp_name)
1222 DEBUG(5,("init_clnt_srv: %d\n", __LINE__));
1224 if (logon_srv != NULL) {
1225 logcln->undoc_buffer = 1;
1226 init_unistr2(&logcln->uni_logon_srv, logon_srv, UNI_STR_TERMINATE);
1227 } else {
1228 logcln->undoc_buffer = 0;
1231 if (comp_name != NULL) {
1232 logcln->undoc_buffer2 = 1;
1233 init_unistr2(&logcln->uni_comp_name, comp_name, UNI_STR_TERMINATE);
1234 } else {
1235 logcln->undoc_buffer2 = 0;
1239 /*******************************************************************
1240 Inits or writes a DOM_CLNT_SRV structure.
1241 ********************************************************************/
1243 bool smb_io_clnt_srv(const char *desc, DOM_CLNT_SRV *logcln, prs_struct *ps, int depth)
1245 if (logcln == NULL)
1246 return False;
1248 prs_debug(ps, depth, desc, "smb_io_clnt_srv");
1249 depth++;
1251 if(!prs_align(ps))
1252 return False;
1254 if(!prs_uint32("undoc_buffer ", ps, depth, &logcln->undoc_buffer))
1255 return False;
1257 if (logcln->undoc_buffer != 0) {
1258 if(!smb_io_unistr2("unistr2", &logcln->uni_logon_srv, logcln->undoc_buffer, ps, depth))
1259 return False;
1262 if(!prs_align(ps))
1263 return False;
1265 if(!prs_uint32("undoc_buffer2", ps, depth, &logcln->undoc_buffer2))
1266 return False;
1268 if (logcln->undoc_buffer2 != 0) {
1269 if(!smb_io_unistr2("unistr2", &logcln->uni_comp_name, logcln->undoc_buffer2, ps, depth))
1270 return False;
1273 return True;
1276 /*******************************************************************
1277 Inits a DOM_LOG_INFO structure.
1278 ********************************************************************/
1280 void init_log_info(DOM_LOG_INFO *loginfo, const char *logon_srv, const char *acct_name,
1281 uint16 sec_chan, const char *comp_name)
1283 DEBUG(5,("make_log_info %d\n", __LINE__));
1285 loginfo->undoc_buffer = 1;
1287 init_unistr2(&loginfo->uni_logon_srv, logon_srv, UNI_STR_TERMINATE);
1288 init_unistr2(&loginfo->uni_acct_name, acct_name, UNI_STR_TERMINATE);
1290 loginfo->sec_chan = sec_chan;
1292 init_unistr2(&loginfo->uni_comp_name, comp_name, UNI_STR_TERMINATE);
1295 /*******************************************************************
1296 Reads or writes a DOM_LOG_INFO structure.
1297 ********************************************************************/
1299 bool smb_io_log_info(const char *desc, DOM_LOG_INFO *loginfo, prs_struct *ps, int depth)
1301 if (loginfo == NULL)
1302 return False;
1304 prs_debug(ps, depth, desc, "smb_io_log_info");
1305 depth++;
1307 if(!prs_align(ps))
1308 return False;
1310 if(!prs_uint32("undoc_buffer", ps, depth, &loginfo->undoc_buffer))
1311 return False;
1313 if(!smb_io_unistr2("unistr2", &loginfo->uni_logon_srv, True, ps, depth))
1314 return False;
1315 if(!smb_io_unistr2("unistr2", &loginfo->uni_acct_name, True, ps, depth))
1316 return False;
1318 if(!prs_uint16("sec_chan", ps, depth, &loginfo->sec_chan))
1319 return False;
1321 if(!smb_io_unistr2("unistr2", &loginfo->uni_comp_name, True, ps, depth))
1322 return False;
1324 return True;
1327 /*******************************************************************
1328 Reads or writes a DOM_CHAL structure.
1329 ********************************************************************/
1331 bool smb_io_chal(const char *desc, DOM_CHAL *chal, prs_struct *ps, int depth)
1333 if (chal == NULL)
1334 return False;
1336 prs_debug(ps, depth, desc, "smb_io_chal");
1337 depth++;
1339 if(!prs_uint8s (False, "data", ps, depth, chal->data, 8))
1340 return False;
1342 return True;
1345 /*******************************************************************
1346 Reads or writes a DOM_CRED structure.
1347 ********************************************************************/
1349 bool smb_io_cred(const char *desc, DOM_CRED *cred, prs_struct *ps, int depth)
1351 if (cred == NULL)
1352 return False;
1354 prs_debug(ps, depth, desc, "smb_io_cred");
1355 depth++;
1357 if(!prs_align(ps))
1358 return False;
1360 if(!smb_io_chal ("", &cred->challenge, ps, depth))
1361 return False;
1363 if(!smb_io_utime("", &cred->timestamp, ps, depth))
1364 return False;
1366 return True;
1369 /*******************************************************************
1370 Inits a DOM_CLNT_INFO2 structure.
1371 ********************************************************************/
1373 void init_clnt_info2(DOM_CLNT_INFO2 *clnt,
1374 const char *logon_srv, const char *comp_name,
1375 const DOM_CRED *clnt_cred)
1377 DEBUG(5,("make_clnt_info: %d\n", __LINE__));
1379 init_clnt_srv(&clnt->login, logon_srv, comp_name);
1381 if (clnt_cred != NULL) {
1382 clnt->ptr_cred = 1;
1383 memcpy(&clnt->cred, clnt_cred, sizeof(clnt->cred));
1384 } else {
1385 clnt->ptr_cred = 0;
1389 /*******************************************************************
1390 Reads or writes a DOM_CLNT_INFO2 structure.
1391 ********************************************************************/
1393 bool smb_io_clnt_info2(const char *desc, DOM_CLNT_INFO2 *clnt, prs_struct *ps, int depth)
1395 if (clnt == NULL)
1396 return False;
1398 prs_debug(ps, depth, desc, "smb_io_clnt_info2");
1399 depth++;
1401 if(!prs_align(ps))
1402 return False;
1404 if(!smb_io_clnt_srv("", &clnt->login, ps, depth))
1405 return False;
1407 if(!prs_align(ps))
1408 return False;
1410 if(!prs_uint32("ptr_cred", ps, depth, &clnt->ptr_cred))
1411 return False;
1412 if(!smb_io_cred("", &clnt->cred, ps, depth))
1413 return False;
1415 return True;
1418 /*******************************************************************
1419 Inits a DOM_CLNT_INFO structure.
1420 ********************************************************************/
1422 void init_clnt_info(DOM_CLNT_INFO *clnt,
1423 const char *logon_srv, const char *acct_name,
1424 uint16 sec_chan, const char *comp_name,
1425 const DOM_CRED *cred)
1427 DEBUG(5,("make_clnt_info\n"));
1429 init_log_info(&clnt->login, logon_srv, acct_name, sec_chan, comp_name);
1430 memcpy(&clnt->cred, cred, sizeof(clnt->cred));
1433 /*******************************************************************
1434 Reads or writes a DOM_CLNT_INFO structure.
1435 ********************************************************************/
1437 bool smb_io_clnt_info(const char *desc, DOM_CLNT_INFO *clnt, prs_struct *ps, int depth)
1439 if (clnt == NULL)
1440 return False;
1442 prs_debug(ps, depth, desc, "smb_io_clnt_info");
1443 depth++;
1445 if(!prs_align(ps))
1446 return False;
1448 if(!smb_io_log_info("", &clnt->login, ps, depth))
1449 return False;
1450 if(!smb_io_cred("", &clnt->cred, ps, depth))
1451 return False;
1453 return True;
1456 /*******************************************************************
1457 Inits a DOM_LOGON_ID structure.
1458 ********************************************************************/
1460 void init_logon_id(DOM_LOGON_ID *logonid, uint32 log_id_low, uint32 log_id_high)
1462 DEBUG(5,("make_logon_id: %d\n", __LINE__));
1464 logonid->low = log_id_low;
1465 logonid->high = log_id_high;
1468 /*******************************************************************
1469 Reads or writes a DOM_LOGON_ID structure.
1470 ********************************************************************/
1472 bool smb_io_logon_id(const char *desc, DOM_LOGON_ID *logonid, prs_struct *ps, int depth)
1474 if (logonid == NULL)
1475 return False;
1477 prs_debug(ps, depth, desc, "smb_io_logon_id");
1478 depth++;
1480 if(!prs_align(ps))
1481 return False;
1483 if(!prs_uint32("low ", ps, depth, &logonid->low ))
1484 return False;
1485 if(!prs_uint32("high", ps, depth, &logonid->high))
1486 return False;
1488 return True;
1491 /*******************************************************************
1492 Inits an OWF_INFO structure.
1493 ********************************************************************/
1495 void init_owf_info(OWF_INFO *hash, const uint8 data[16])
1497 DEBUG(5,("init_owf_info: %d\n", __LINE__));
1499 if (data != NULL)
1500 memcpy(hash->data, data, sizeof(hash->data));
1501 else
1502 memset((char *)hash->data, '\0', sizeof(hash->data));
1505 /*******************************************************************
1506 Reads or writes an OWF_INFO structure.
1507 ********************************************************************/
1509 bool smb_io_owf_info(const char *desc, OWF_INFO *hash, prs_struct *ps, int depth)
1511 if (hash == NULL)
1512 return False;
1514 prs_debug(ps, depth, desc, "smb_io_owf_info");
1515 depth++;
1517 if(!prs_align(ps))
1518 return False;
1520 if(!prs_uint8s (False, "data", ps, depth, hash->data, 16))
1521 return False;
1523 return True;
1526 /*******************************************************************
1527 Reads or writes a DOM_GID structure.
1528 ********************************************************************/
1530 bool smb_io_gid(const char *desc, DOM_GID *gid, prs_struct *ps, int depth)
1532 if (gid == NULL)
1533 return False;
1535 prs_debug(ps, depth, desc, "smb_io_gid");
1536 depth++;
1538 if(!prs_align(ps))
1539 return False;
1541 if(!prs_uint32("g_rid", ps, depth, &gid->g_rid))
1542 return False;
1543 if(!prs_uint32("attr ", ps, depth, &gid->attr))
1544 return False;
1546 return True;
1549 /*******************************************************************
1550 Reads or writes an POLICY_HND structure.
1551 ********************************************************************/
1553 bool smb_io_pol_hnd(const char *desc, POLICY_HND *pol, prs_struct *ps, int depth)
1555 if (pol == NULL)
1556 return False;
1558 prs_debug(ps, depth, desc, "smb_io_pol_hnd");
1559 depth++;
1561 if(!prs_align(ps))
1562 return False;
1564 if(UNMARSHALLING(ps))
1565 ZERO_STRUCTP(pol);
1567 if (!prs_uint32("handle_type", ps, depth, &pol->handle_type))
1568 return False;
1569 if (!smb_io_uuid("uuid", (struct GUID*)&pol->uuid, ps, depth))
1570 return False;
1572 return True;
1575 /*******************************************************************
1576 Create a UNISTR3.
1577 ********************************************************************/
1579 void init_unistr3(UNISTR3 *str, const char *buf)
1581 if (buf == NULL) {
1582 str->uni_str_len=0;
1583 str->str.buffer = NULL;
1584 return;
1587 str->uni_str_len = strlen(buf) + 1;
1589 if (str->uni_str_len) {
1590 str->str.buffer = TALLOC_ZERO_ARRAY(talloc_tos(), uint16, str->uni_str_len);
1591 if (str->str.buffer == NULL)
1592 smb_panic("init_unistr3: malloc fail");
1594 rpcstr_push((char *)str->str.buffer, buf, str->uni_str_len * sizeof(uint16), STR_TERMINATE);
1595 } else {
1596 str->str.buffer = NULL;
1600 /*******************************************************************
1601 Reads or writes a UNISTR3 structure.
1602 ********************************************************************/
1604 bool smb_io_unistr3(const char *desc, UNISTR3 *name, prs_struct *ps, int depth)
1606 if (name == NULL)
1607 return False;
1609 prs_debug(ps, depth, desc, "smb_io_unistr3");
1610 depth++;
1612 if(!prs_align(ps))
1613 return False;
1615 if(!prs_uint32("uni_str_len", ps, depth, &name->uni_str_len))
1616 return False;
1618 /* we're done if there is no string */
1620 if ( name->uni_str_len == 0 )
1621 return True;
1623 /* don't know if len is specified by uni_str_len member... */
1624 /* assume unicode string is unicode-null-terminated, instead */
1626 if(!prs_unistr3(True, "unistr", name, ps, depth))
1627 return False;
1629 return True;
1632 /*******************************************************************
1633 Stream a uint64_struct
1634 ********************************************************************/
1635 bool prs_uint64(const char *name, prs_struct *ps, int depth, uint64 *data64)
1637 if (UNMARSHALLING(ps)) {
1638 uint32 high, low;
1640 if (!prs_uint32(name, ps, depth+1, &low))
1641 return False;
1643 if (!prs_uint32(name, ps, depth+1, &high))
1644 return False;
1646 *data64 = ((uint64_t)high << 32) + low;
1648 return True;
1649 } else {
1650 uint32 high = (*data64) >> 32, low = (*data64) & 0xFFFFFFFF;
1651 return prs_uint32(name, ps, depth+1, &low) &&
1652 prs_uint32(name, ps, depth+1, &high);
1656 /*******************************************************************
1657 reads or writes a BUFHDR2 structure.
1658 ********************************************************************/
1659 bool smb_io_bufhdr2(const char *desc, BUFHDR2 *hdr, prs_struct *ps, int depth)
1661 prs_debug(ps, depth, desc, "smb_io_bufhdr2");
1662 depth++;
1664 if (!prs_align(ps))
1665 return False;
1666 if (!prs_uint32("info_level", ps, depth, &(hdr->info_level)))
1667 return False;
1668 if (!prs_uint32("length ", ps, depth, &(hdr->length )))
1669 return False;
1670 if (!prs_uint32("buffer ", ps, depth, &(hdr->buffer )))
1671 return False;
1673 return True;
1676 /*******************************************************************
1677 reads or writes a BUFHDR4 structure.
1678 ********************************************************************/
1679 bool smb_io_bufhdr4(const char *desc, BUFHDR4 *hdr, prs_struct *ps, int depth)
1681 prs_debug(ps, depth, desc, "smb_io_bufhdr4");
1682 depth++;
1684 if (!prs_align(ps))
1685 return False;
1686 if (!prs_uint32("size", ps, depth, &hdr->size))
1687 return False;
1688 if (!prs_uint32("buffer", ps, depth, &hdr->buffer))
1689 return False;
1691 return True;
1694 /*******************************************************************
1695 reads or writes a RPC_DATA_BLOB structure.
1696 ********************************************************************/
1698 bool smb_io_rpc_blob(const char *desc, RPC_DATA_BLOB *blob, prs_struct *ps, int depth)
1700 prs_debug(ps, depth, desc, "smb_io_rpc_blob");
1701 depth++;
1703 if (!prs_align(ps))
1704 return False;
1705 if ( !prs_uint32("buf_len", ps, depth, &blob->buf_len) )
1706 return False;
1708 if ( blob->buf_len == 0 )
1709 return True;
1711 if (UNMARSHALLING(ps)) {
1712 blob->buffer = PRS_ALLOC_MEM(ps, uint8, blob->buf_len);
1713 if (!blob->buffer) {
1714 return False;
1718 if ( !prs_uint8s(True, "buffer", ps, depth, blob->buffer, blob->buf_len) )
1719 return False;
1721 return True;
1724 /*******************************************************************
1725 creates a UNIHDR structure.
1726 ********************************************************************/
1728 bool make_uni_hdr(UNIHDR *hdr, int len)
1730 if (hdr == NULL)
1732 return False;
1734 hdr->uni_str_len = 2 * len;
1735 hdr->uni_max_len = 2 * len;
1736 hdr->buffer = len != 0 ? 1 : 0;
1738 return True;
1741 /*******************************************************************
1742 creates a BUFHDR2 structure.
1743 ********************************************************************/
1744 bool make_bufhdr2(BUFHDR2 *hdr, uint32 info_level, uint32 length, uint32 buffer)
1746 hdr->info_level = info_level;
1747 hdr->length = length;
1748 hdr->buffer = buffer;
1750 return True;
1753 /*******************************************************************
1754 return the length of a UNISTR string.
1755 ********************************************************************/
1757 uint32 str_len_uni(UNISTR *source)
1759 uint32 i=0;
1761 if (!source->buffer)
1762 return 0;
1764 while (source->buffer[i])
1765 i++;
1767 return i;
1770 /*******************************************************************
1771 Verifies policy handle
1772 ********************************************************************/
1774 bool policy_handle_is_valid(const POLICY_HND *hnd)
1776 POLICY_HND zero_pol;
1778 ZERO_STRUCT(zero_pol);
1779 return ((memcmp(&zero_pol, hnd, sizeof(POLICY_HND)) == 0) ? false : true );