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
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/>.
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)
37 prs_debug(ps, depth, desc, "smb_io_utime");
43 if(!prs_uint32 ("time", ps, depth, &t->time))
49 /*******************************************************************
50 Reads or writes an NTTIME structure.
51 ********************************************************************/
53 BOOL smb_io_time(const char *desc, NTTIME *nttime, prs_struct *ps, int depth)
59 prs_debug(ps, depth, desc, "smb_io_time");
65 if (MARSHALLING(ps)) {
66 low = *nttime & 0xFFFFFFFF;
70 if(!prs_uint32("low ", ps, depth, &low)) /* low part */
72 if(!prs_uint32("high", ps, depth, &high)) /* high part */
75 if (UNMARSHALLING(ps)) {
76 *nttime = (((uint64_t)high << 32) + low);
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 Reads or writes a DOM_SID structure.
93 ********************************************************************/
95 BOOL smb_io_dom_sid(const char *desc, DOM_SID *sid, prs_struct *ps, int depth)
102 prs_debug(ps, depth, desc, "smb_io_dom_sid");
105 if(!prs_uint8 ("sid_rev_num", ps, depth, &sid->sid_rev_num))
108 if(!prs_uint8 ("num_auths ", ps, depth, &sid->num_auths))
111 for (i = 0; i < 6; i++)
114 slprintf(tmp, sizeof(tmp) - 1, "id_auth[%d] ", i);
115 if(!prs_uint8 (tmp, ps, depth, &sid->id_auth[i]))
119 /* oops! XXXX should really issue a warning here... */
120 if (sid->num_auths > MAXSUBAUTHS)
121 sid->num_auths = MAXSUBAUTHS;
123 if(!prs_uint32s(False, "sub_auths ", ps, depth, sid->sub_auths, sid->num_auths))
129 /*******************************************************************
130 Inits a DOM_SID2 structure.
131 ********************************************************************/
133 void init_dom_sid2(DOM_SID2 *sid2, const DOM_SID *sid)
136 sid2->num_auths = sid2->sid.num_auths;
139 /*******************************************************************
140 Reads or writes a DOM_SID2 structure.
141 ********************************************************************/
143 BOOL smb_io_dom_sid2_p(const char *desc, prs_struct *ps, int depth, DOM_SID2 **sid2)
147 /* caputure the pointer value to stream */
149 data_p = *sid2 ? 0xf000baaa : 0;
151 if ( !prs_uint32("dom_sid2_p", ps, depth, &data_p ))
154 /* we're done if there is no data */
159 if (UNMARSHALLING(ps)) {
160 if ( !(*sid2 = PRS_ALLOC_MEM(ps, DOM_SID2, 1)) )
166 /*******************************************************************
167 Reads or writes a DOM_SID2 structure.
168 ********************************************************************/
170 BOOL smb_io_dom_sid2(const char *desc, DOM_SID2 *sid, prs_struct *ps, int depth)
175 prs_debug(ps, depth, desc, "smb_io_dom_sid2");
181 if(!prs_uint32("num_auths", ps, depth, &sid->num_auths))
184 if(!smb_io_dom_sid("sid", &sid->sid, ps, depth))
190 /*******************************************************************
191 Reads or writes a struct GUID
192 ********************************************************************/
194 BOOL smb_io_uuid(const char *desc, struct GUID *uuid,
195 prs_struct *ps, int depth)
200 prs_debug(ps, depth, desc, "smb_io_uuid");
203 if(!prs_uint32 ("data ", ps, depth, &uuid->time_low))
205 if(!prs_uint16 ("data ", ps, depth, &uuid->time_mid))
207 if(!prs_uint16 ("data ", ps, depth, &uuid->time_hi_and_version))
210 if(!prs_uint8s (False, "data ", ps, depth, uuid->clock_seq, sizeof(uuid->clock_seq)))
212 if(!prs_uint8s (False, "data ", ps, depth, uuid->node, sizeof(uuid->node)))
218 /*******************************************************************
219 creates a STRHDR structure.
220 ********************************************************************/
222 void init_str_hdr(STRHDR *hdr, int max_len, int len, uint32 buffer)
224 hdr->str_max_len = max_len;
225 hdr->str_str_len = len;
226 hdr->buffer = buffer;
229 /*******************************************************************
230 Reads or writes a STRHDR structure.
231 ********************************************************************/
233 BOOL smb_io_strhdr(const char *desc, STRHDR *hdr, prs_struct *ps, int depth)
238 prs_debug(ps, depth, desc, "smb_io_strhdr");
243 if(!prs_uint16("str_str_len", ps, depth, &hdr->str_str_len))
245 if(!prs_uint16("str_max_len", ps, depth, &hdr->str_max_len))
247 if(!prs_uint32("buffer ", ps, depth, &hdr->buffer))
253 /*******************************************************************
254 Inits a UNIHDR structure.
255 ********************************************************************/
257 void init_uni_hdr(UNIHDR *hdr, UNISTR2 *str2)
259 hdr->uni_str_len = 2 * (str2->uni_str_len);
260 hdr->uni_max_len = 2 * (str2->uni_max_len);
261 hdr->buffer = (str2->uni_str_len != 0) ? 1 : 0;
264 /*******************************************************************
265 Reads or writes a UNIHDR structure.
266 ********************************************************************/
268 BOOL smb_io_unihdr(const char *desc, UNIHDR *hdr, prs_struct *ps, int depth)
273 prs_debug(ps, depth, desc, "smb_io_unihdr");
279 if(!prs_uint16("uni_str_len", ps, depth, &hdr->uni_str_len))
281 if(!prs_uint16("uni_max_len", ps, depth, &hdr->uni_max_len))
283 if(!prs_uint32("buffer ", ps, depth, &hdr->buffer))
289 /*******************************************************************
290 Inits a BUFHDR structure.
291 ********************************************************************/
293 void init_buf_hdr(BUFHDR *hdr, int max_len, int len)
295 hdr->buf_max_len = max_len;
299 /*******************************************************************
300 prs_uint16 wrapper. Call this and it sets up a pointer to where the
301 uint16 should be stored, or gets the size if reading.
302 ********************************************************************/
304 BOOL smb_io_hdrbuf_pre(const char *desc, BUFHDR *hdr, prs_struct *ps, int depth, uint32 *offset)
306 (*offset) = prs_offset(ps);
311 if(!smb_io_hdrbuf(desc, hdr, ps, depth))
318 if(!prs_set_offset(ps, prs_offset(ps) + (sizeof(uint32) * 2)))
325 /*******************************************************************
326 smb_io_hdrbuf wrapper. Call this and it retrospectively stores the size.
327 Does nothing on reading, as that is already handled by ...._pre()
328 ********************************************************************/
330 BOOL smb_io_hdrbuf_post(const char *desc, BUFHDR *hdr, prs_struct *ps, int depth,
331 uint32 ptr_hdrbuf, uint32 max_len, uint32 len)
334 /* writing: go back and do a retrospective job. i hate this */
336 uint32 old_offset = prs_offset(ps);
338 init_buf_hdr(hdr, max_len, len);
339 if(!prs_set_offset(ps, ptr_hdrbuf))
341 if(!smb_io_hdrbuf(desc, hdr, ps, depth))
344 if(!prs_set_offset(ps, old_offset))
351 /*******************************************************************
352 Reads or writes a BUFHDR structure.
353 ********************************************************************/
355 BOOL smb_io_hdrbuf(const char *desc, BUFHDR *hdr, prs_struct *ps, int depth)
360 prs_debug(ps, depth, desc, "smb_io_hdrbuf");
366 if(!prs_uint32("buf_max_len", ps, depth, &hdr->buf_max_len))
368 if(!prs_uint32("buf_len ", ps, depth, &hdr->buf_len))
374 /*******************************************************************
375 Inits a UNISTR structure.
376 ********************************************************************/
378 void init_unistr(UNISTR *str, const char *buf)
387 len = strlen(buf) + 1;
390 str->buffer = TALLOC_ZERO_ARRAY(talloc_tos(), uint16, len);
391 if (str->buffer == NULL)
392 smb_panic("init_unistr: malloc fail");
394 rpcstr_push(str->buffer, buf, len*sizeof(uint16), STR_TERMINATE);
400 /*******************************************************************
401 reads or writes a UNISTR structure.
402 XXXX NOTE: UNISTR structures NEED to be null-terminated.
403 ********************************************************************/
405 BOOL smb_io_unistr(const char *desc, UNISTR *uni, prs_struct *ps, int depth)
410 prs_debug(ps, depth, desc, "smb_io_unistr");
413 if(!prs_unistr("unistr", ps, depth, uni))
419 /*******************************************************************
420 Allocate the RPC_DATA_BLOB memory.
421 ********************************************************************/
423 static void create_rpc_blob(RPC_DATA_BLOB *str, size_t len)
426 str->buffer = (uint8 *)TALLOC_ZERO(talloc_tos(), len);
427 if (str->buffer == NULL)
428 smb_panic("create_rpc_blob: talloc fail");
436 /*******************************************************************
437 Inits a RPC_DATA_BLOB structure from a uint32
438 ********************************************************************/
440 void init_rpc_blob_uint32(RPC_DATA_BLOB *str, uint32 val)
444 /* set up string lengths. */
445 create_rpc_blob(str, sizeof(uint32));
446 SIVAL(str->buffer, 0, val);
449 /*******************************************************************
450 Inits a RPC_DATA_BLOB structure.
451 ********************************************************************/
453 void init_rpc_blob_str(RPC_DATA_BLOB *str, const char *buf, int len)
457 /* set up string lengths. */
459 create_rpc_blob(str, len*2);
460 rpcstr_push(str->buffer, buf, (size_t)str->buf_len, STR_TERMINATE);
464 /*******************************************************************
465 Inits a RPC_DATA_BLOB structure from a hex string.
466 ********************************************************************/
468 void init_rpc_blob_hex(RPC_DATA_BLOB *str, const char *buf)
472 create_rpc_blob(str, strlen(buf));
473 str->buf_len = strhex_to_str((char *)str->buffer, str->buf_len, buf);
477 /*******************************************************************
478 Inits a RPC_DATA_BLOB structure.
479 ********************************************************************/
481 void init_rpc_blob_bytes(RPC_DATA_BLOB *str, uint8 *buf, size_t len)
485 /* max buffer size (allocated size) */
486 if (buf != NULL && len) {
487 create_rpc_blob(str, len);
488 memcpy(str->buffer, buf, len);
493 /*******************************************************************
494 reads or writes a BUFFER5 structure.
495 the buf_len member tells you how large the buffer is.
496 ********************************************************************/
497 BOOL smb_io_buffer5(const char *desc, BUFFER5 *buf5, prs_struct *ps, int depth)
499 prs_debug(ps, depth, desc, "smb_io_buffer5");
502 if (buf5 == NULL) return False;
506 if(!prs_uint32("buf_len", ps, depth, &buf5->buf_len))
510 if(!prs_buffer5(True, "buffer" , ps, depth, buf5))
517 /*******************************************************************
518 Inits a REGVAL_BUFFER structure.
519 ********************************************************************/
521 void init_regval_buffer(REGVAL_BUFFER *str, const uint8 *buf, size_t len)
525 /* max buffer size (allocated size) */
526 str->buf_max_len = len;
528 str->buf_len = buf != NULL ? len : 0;
531 SMB_ASSERT(str->buf_max_len >= str->buf_len);
532 str->buffer = (uint16 *)TALLOC_ZERO(talloc_tos(),
534 if (str->buffer == NULL)
535 smb_panic("init_regval_buffer: talloc fail");
536 memcpy(str->buffer, buf, str->buf_len);
540 /*******************************************************************
541 Reads or writes a REGVAL_BUFFER structure.
542 the uni_max_len member tells you how large the buffer is.
543 the uni_str_len member tells you how much of the buffer is really used.
544 ********************************************************************/
546 BOOL smb_io_regval_buffer(const char *desc, prs_struct *ps, int depth, REGVAL_BUFFER *buf2)
549 prs_debug(ps, depth, desc, "smb_io_regval_buffer");
555 if(!prs_uint32("buf_max_len", ps, depth, &buf2->buf_max_len))
557 if(!prs_uint32("offset ", ps, depth, &buf2->offset))
559 if(!prs_uint32("buf_len ", ps, depth, &buf2->buf_len))
562 /* buffer advanced by indicated length of string
563 NOT by searching for null-termination */
565 if(!prs_regval_buffer(True, "buffer ", ps, depth, buf2))
571 /*******************************************************************
572 creates a UNISTR2 structure: sets up the buffer, too
573 ********************************************************************/
575 void init_buf_unistr2(UNISTR2 *str, uint32 *ptr, const char *buf)
579 init_unistr2(str, buf, UNI_STR_TERMINATE);
582 init_unistr2(str, NULL, UNI_FLAGS_NONE);
587 /*******************************************************************
588 Copies a UNISTR2 structure.
589 ********************************************************************/
591 void copy_unistr2(UNISTR2 *str, const UNISTR2 *from)
593 if (from->buffer == NULL) {
598 SMB_ASSERT(from->uni_max_len >= from->uni_str_len);
600 str->uni_max_len = from->uni_max_len;
601 str->offset = from->offset;
602 str->uni_str_len = from->uni_str_len;
604 /* the string buffer is allocated to the maximum size
605 (the the length of the source string) to prevent
606 reallocation of memory. */
607 if (str->buffer == NULL) {
608 if (str->uni_max_len) {
609 str->buffer = (uint16 *)TALLOC_ZERO_ARRAY(talloc_tos(), uint16, str->uni_max_len);
610 if ((str->buffer == NULL)) {
611 smb_panic("copy_unistr2: talloc fail");
614 /* copy the string */
615 memcpy(str->buffer, from->buffer, str->uni_max_len*sizeof(uint16));
622 /*******************************************************************
623 Creates a STRING2 structure.
624 ********************************************************************/
626 void init_string2(STRING2 *str, const char *buf, size_t max_len, size_t str_len)
628 /* set up string lengths. */
629 SMB_ASSERT(max_len >= str_len);
631 /* Ensure buf is valid if str_len was set. Coverity check. */
632 if (str_len && !buf) {
636 str->str_max_len = max_len;
638 str->str_str_len = str_len;
640 /* store the string */
642 str->buffer = (uint8 *)TALLOC_ZERO(talloc_tos(),
644 if (str->buffer == NULL)
645 smb_panic("init_string2: malloc fail");
646 memcpy(str->buffer, buf, str_len);
650 /*******************************************************************
651 Reads or writes a STRING2 structure.
652 XXXX NOTE: STRING2 structures need NOT be null-terminated.
653 the str_str_len member tells you how long the string is;
654 the str_max_len member tells you how large the buffer is.
655 ********************************************************************/
657 BOOL smb_io_string2(const char *desc, STRING2 *str2, uint32 buffer, prs_struct *ps, int depth)
664 prs_debug(ps, depth, desc, "smb_io_string2");
670 if(!prs_uint32("str_max_len", ps, depth, &str2->str_max_len))
672 if(!prs_uint32("offset ", ps, depth, &str2->offset))
674 if(!prs_uint32("str_str_len", ps, depth, &str2->str_str_len))
677 /* buffer advanced by indicated length of string
678 NOT by searching for null-termination */
679 if(!prs_string2(True, "buffer ", ps, depth, str2))
684 prs_debug(ps, depth, desc, "smb_io_string2 - NULL");
686 memset((char *)str2, '\0', sizeof(*str2));
693 /*******************************************************************
694 Inits a UNISTR2 structure.
695 ********************************************************************/
697 void init_unistr2(UNISTR2 *str, const char *buf, enum unistr2_term_codes flags)
700 uint32 num_chars = 0;
703 /* We always null terminate the copy. */
704 len = strlen(buf) + 1;
705 if ( flags == UNI_STR_DBLTERMINATE )
709 if (buf == NULL || len == 0) {
710 /* no buffer -- nothing to do */
711 str->uni_max_len = 0;
713 str->uni_str_len = 0;
719 str->buffer = TALLOC_ZERO_ARRAY(talloc_tos(), uint16, len);
720 if (str->buffer == NULL) {
721 smb_panic("init_unistr2: malloc fail");
725 /* Ensure len is the length in *bytes* */
726 len *= sizeof(uint16);
729 * The UNISTR2 must be initialized !!!
733 rpcstr_push((char *)str->buffer, buf, len, STR_TERMINATE);
734 num_chars = strlen_w(str->buffer);
735 if (flags == UNI_STR_TERMINATE || flags == UNI_MAXLEN_TERMINATE) {
738 if ( flags == UNI_STR_DBLTERMINATE )
742 str->uni_max_len = num_chars;
744 str->uni_str_len = num_chars;
745 if ( num_chars && ((flags == UNI_MAXLEN_TERMINATE) || (flags == UNI_BROKEN_NON_NULL)) )
749 /*******************************************************************
750 Inits a UNISTR4 structure.
751 ********************************************************************/
753 void init_unistr4(UNISTR4 *uni4, const char *buf, enum unistr2_term_codes flags)
755 uni4->string = TALLOC_P( talloc_tos(), UNISTR2 );
757 smb_panic("init_unistr4: talloc fail");
760 init_unistr2( uni4->string, buf, flags );
762 uni4->length = 2 * (uni4->string->uni_str_len);
763 uni4->size = 2 * (uni4->string->uni_max_len);
766 void init_unistr4_w( TALLOC_CTX *ctx, UNISTR4 *uni4, const smb_ucs2_t *buf )
768 uni4->string = TALLOC_P( ctx, UNISTR2 );
770 smb_panic("init_unistr4_w: talloc fail");
773 init_unistr2_w( ctx, uni4->string, buf );
775 uni4->length = 2 * (uni4->string->uni_str_len);
776 uni4->size = 2 * (uni4->string->uni_max_len);
780 * Inits a UNISTR2 structure.
781 * @param ctx talloc context to allocate string on
782 * @param str pointer to string to create
783 * @param buf UCS2 null-terminated buffer to init from
786 void init_unistr2_w(TALLOC_CTX *ctx, UNISTR2 *str, const smb_ucs2_t *buf)
788 uint32 len = buf ? strlen_w(buf) : 0;
792 /* set up string lengths. */
793 str->uni_max_len = len;
795 str->uni_str_len = len;
798 str->buffer = TALLOC_ZERO_ARRAY(ctx, uint16, len + 1);
799 if (str->buffer == NULL) {
800 smb_panic("init_unistr2_w: talloc fail");
808 * don't move this test above ! The UNISTR2 must be initialized !!!
814 /* Yes, this is a strncpy( foo, bar, strlen(bar)) - but as
815 long as the buffer above is talloc()ed correctly then this
816 is the correct thing to do */
818 strncpy_w(str->buffer, buf, len + 1);
822 /*******************************************************************
823 Inits a UNISTR2 structure from a UNISTR
824 ********************************************************************/
826 void init_unistr2_from_unistr(UNISTR2 *to, const UNISTR *from)
830 /* the destination UNISTR2 should never be NULL.
831 if it is it is a programming error */
833 /* if the source UNISTR is NULL, then zero out
834 the destination string and return */
836 if ((from == NULL) || (from->buffer == NULL))
839 /* get the length; UNISTR must be NULL terminated */
841 while ((from->buffer)[i]!='\0')
843 i++; /* one more to catch the terminating NULL */
844 /* is this necessary -- jerry? I need to think */
846 /* set up string lengths; uni_max_len is set to i+1
847 because we need to account for the final NULL termination */
852 /* allocate the space and copy the string buffer */
854 to->buffer = TALLOC_ZERO_ARRAY(talloc_tos(), uint16, i);
855 if (to->buffer == NULL)
856 smb_panic("init_unistr2_from_unistr: malloc fail");
857 memcpy(to->buffer, from->buffer, i*sizeof(uint16));
864 /*******************************************************************
865 Inits a UNISTR2 structure from a DATA_BLOB.
866 The length of the data_blob must count the bytes of the buffer.
867 Copies the blob data.
868 ********************************************************************/
870 void init_unistr2_from_datablob(UNISTR2 *str, DATA_BLOB *blob)
872 /* Allocs the unistring */
873 init_unistr2(str, NULL, UNI_FLAGS_NONE);
875 /* Sets the values */
876 str->uni_str_len = blob->length / sizeof(uint16);
877 str->uni_max_len = str->uni_str_len;
880 str->buffer = (uint16 *) memdup(blob->data, blob->length);
884 if ((str->buffer == NULL) && (blob->length > 0)) {
885 smb_panic("init_unistr2_from_datablob: malloc fail");
889 /*******************************************************************
890 UNISTR2* are a little different in that the pointer and the UNISTR2
891 are not necessarily read/written back to back. So we break it up
892 into 2 separate functions.
893 See SPOOL_USER_1 in include/rpc_spoolss.h for an example.
894 ********************************************************************/
896 BOOL prs_io_unistr2_p(const char *desc, prs_struct *ps, int depth, UNISTR2 **uni2)
900 /* caputure the pointer value to stream */
902 data_p = *uni2 ? 0xf000baaa : 0;
904 if ( !prs_uint32("ptr", ps, depth, &data_p ))
907 /* we're done if there is no data */
912 if (UNMARSHALLING(ps)) {
913 if ( !(*uni2 = PRS_ALLOC_MEM(ps, UNISTR2, 1)) )
920 /*******************************************************************
921 now read/write the actual UNISTR2. Memory for the UNISTR2 (but
922 not UNISTR2.buffer) has been allocated previously by prs_unistr2_p()
923 ********************************************************************/
925 BOOL prs_io_unistr2(const char *desc, prs_struct *ps, int depth, UNISTR2 *uni2 )
927 /* just return true if there is no pointer to deal with.
928 the memory must have been previously allocated on unmarshalling
929 by prs_unistr2_p() */
934 /* just pass off to smb_io_unstr2() passing the uni2 address as
935 the pointer (like you would expect) */
937 return smb_io_unistr2( desc, uni2, uni2 ? 1 : 0, ps, depth );
940 /*******************************************************************
941 Reads or writes a UNISTR2 structure.
942 XXXX NOTE: UNISTR2 structures need NOT be null-terminated.
943 the uni_str_len member tells you how long the string is;
944 the uni_max_len member tells you how large the buffer is.
945 ********************************************************************/
947 BOOL smb_io_unistr2(const char *desc, UNISTR2 *uni2, uint32 buffer, prs_struct *ps, int depth)
954 prs_debug(ps, depth, desc, "smb_io_unistr2");
960 if(!prs_uint32("uni_max_len", ps, depth, &uni2->uni_max_len))
962 if(!prs_uint32("offset ", ps, depth, &uni2->offset))
964 if(!prs_uint32("uni_str_len", ps, depth, &uni2->uni_str_len))
967 /* buffer advanced by indicated length of string
968 NOT by searching for null-termination */
969 if(!prs_unistr2(True, "buffer ", ps, depth, uni2))
974 prs_debug(ps, depth, desc, "smb_io_unistr2 - NULL");
976 memset((char *)uni2, '\0', sizeof(*uni2));
983 /*******************************************************************
984 now read/write UNISTR4
985 ********************************************************************/
987 BOOL prs_unistr4(const char *desc, prs_struct *ps, int depth, UNISTR4 *uni4)
990 prs_debug(ps, depth, desc, "prs_unistr4");
993 if ( !prs_uint16("length", ps, depth, &uni4->length ))
995 if ( !prs_uint16("size", ps, depth, &uni4->size ))
1000 if ( !prs_pointer( desc, ps, depth, &ptr, sizeof(UNISTR2), (PRS_POINTER_CAST)prs_io_unistr2 ) )
1003 uni4->string = (UNISTR2 *)ptr;
1008 /*******************************************************************
1009 now read/write UNISTR4 header
1010 ********************************************************************/
1012 BOOL prs_unistr4_hdr(const char *desc, prs_struct *ps, int depth, UNISTR4 *uni4)
1014 prs_debug(ps, depth, desc, "prs_unistr4_hdr");
1017 if ( !prs_uint16("length", ps, depth, &uni4->length) )
1019 if ( !prs_uint16("size", ps, depth, &uni4->size) )
1021 if ( !prs_io_unistr2_p(desc, ps, depth, &uni4->string) )
1027 /*******************************************************************
1028 now read/write UNISTR4 string
1029 ********************************************************************/
1031 BOOL prs_unistr4_str(const char *desc, prs_struct *ps, int depth, UNISTR4 *uni4)
1033 prs_debug(ps, depth, desc, "prs_unistr4_str");
1036 if ( !prs_io_unistr2(desc, ps, depth, uni4->string) )
1042 /*******************************************************************
1043 Reads or writes a UNISTR4_ARRAY structure.
1044 ********************************************************************/
1046 BOOL prs_unistr4_array(const char *desc, prs_struct *ps, int depth, UNISTR4_ARRAY *array )
1050 prs_debug(ps, depth, desc, "prs_unistr4_array");
1053 if(!prs_uint32("count", ps, depth, &array->count))
1056 if (UNMARSHALLING(ps)) {
1058 if ( !(array->strings = TALLOC_ZERO_ARRAY( talloc_tos(), UNISTR4, array->count)) )
1061 array->strings = NULL;
1065 /* write the headers and then the actual string buffer */
1067 for ( i=0; i<array->count; i++ ) {
1068 if ( !prs_unistr4_hdr( "string", ps, depth, &array->strings[i]) )
1072 for (i=0;i<array->count;i++) {
1073 if ( !prs_unistr4_str("string", ps, depth, &array->strings[i]) )
1080 /********************************************************************
1081 initialise a UNISTR_ARRAY from a char**
1082 ********************************************************************/
1084 BOOL init_unistr4_array( UNISTR4_ARRAY *array, uint32 count, const char **strings )
1088 array->count = count;
1090 /* allocate memory for the array of UNISTR4 objects */
1093 if ( !(array->strings = TALLOC_ZERO_ARRAY(talloc_tos(), UNISTR4, count )) )
1096 array->strings = NULL;
1099 for ( i=0; i<count; i++ )
1100 init_unistr4( &array->strings[i], strings[i], UNI_STR_TERMINATE );
1105 BOOL smb_io_lockout_string_hdr(const char *desc, HDR_LOCKOUT_STRING *hdr_account_lockout, prs_struct *ps, int depth)
1107 prs_debug(ps, depth, desc, "smb_io_lockout_string_hdr");
1113 if(!prs_uint16("size", ps, depth, &hdr_account_lockout->size))
1115 if(!prs_uint16("length", ps, depth, &hdr_account_lockout->length))
1117 if(!prs_uint32("buffer", ps, depth, &hdr_account_lockout->buffer))
1123 BOOL smb_io_account_lockout_str(const char *desc, LOCKOUT_STRING *account_lockout, uint32 buffer, prs_struct *ps, int depth)
1125 prs_debug(ps, depth, desc, "smb_io_account_lockout_string");
1128 if(!prs_uint32("array_size", ps, depth, &account_lockout->array_size))
1131 if(!prs_uint32("offset", ps, depth, &account_lockout->offset))
1133 if(!prs_uint32("length", ps, depth, &account_lockout->length))
1136 if (!prs_uint64("lockout_duration", ps, depth, &account_lockout->lockout_duration))
1138 if (!prs_uint64("reset_count", ps, depth, &account_lockout->reset_count))
1140 if (!prs_uint32("bad_attempt_lockout", ps, depth, &account_lockout->bad_attempt_lockout))
1142 if (!prs_uint32("dummy", ps, depth, &account_lockout->dummy))
1145 if(!prs_uint16s (False, "bindata", ps, depth, &account_lockout->bindata, length))
1152 /*******************************************************************
1153 Inits a DOM_RID structure.
1154 ********************************************************************/
1156 void init_dom_rid(DOM_RID *prid, uint32 rid, uint16 type, uint32 idx)
1160 prid->rid_idx = idx;
1163 /*******************************************************************
1164 Reads or writes a DOM_RID structure.
1165 ********************************************************************/
1167 BOOL smb_io_dom_rid(const char *desc, DOM_RID *rid, prs_struct *ps, int depth)
1172 prs_debug(ps, depth, desc, "smb_io_dom_rid");
1178 if(!prs_uint16("type ", ps, depth, &rid->type))
1182 if(!prs_uint32("rid ", ps, depth, &rid->rid))
1184 if(!prs_uint32("rid_idx", ps, depth, &rid->rid_idx))
1190 /*******************************************************************
1191 Reads or writes a DOM_RID2 structure.
1192 ********************************************************************/
1194 BOOL smb_io_dom_rid2(const char *desc, DOM_RID2 *rid, prs_struct *ps, int depth)
1199 prs_debug(ps, depth, desc, "smb_io_dom_rid2");
1205 if(!prs_uint16("type ", ps, depth, &rid->type))
1209 if(!prs_uint32("rid ", ps, depth, &rid->rid))
1211 if(!prs_uint32("rid_idx", ps, depth, &rid->rid_idx))
1213 if(!prs_uint32("unknown", ps, depth, &rid->unknown))
1220 /*******************************************************************
1221 creates a DOM_RID3 structure.
1222 ********************************************************************/
1224 void init_dom_rid3(DOM_RID3 *rid3, uint32 rid, uint8 type)
1228 rid3->ptr_type = 0x1; /* non-zero, basically. */
1233 /*******************************************************************
1234 reads or writes a DOM_RID3 structure.
1235 ********************************************************************/
1237 BOOL smb_io_dom_rid3(const char *desc, DOM_RID3 *rid3, prs_struct *ps, int depth)
1242 prs_debug(ps, depth, desc, "smb_io_dom_rid3");
1248 if(!prs_uint32("rid ", ps, depth, &rid3->rid))
1250 if(!prs_uint32("type1 ", ps, depth, &rid3->type1))
1252 if(!prs_uint32("ptr_type", ps, depth, &rid3->ptr_type))
1254 if(!prs_uint32("type2 ", ps, depth, &rid3->type2))
1256 if(!prs_uint32("unk ", ps, depth, &rid3->unk))
1262 /*******************************************************************
1263 Inits a DOM_RID4 structure.
1264 ********************************************************************/
1266 void init_dom_rid4(DOM_RID4 *rid4, uint16 unknown, uint16 attr, uint32 rid)
1268 rid4->unknown = unknown;
1273 /*******************************************************************
1274 Inits a DOM_CLNT_SRV structure.
1275 ********************************************************************/
1277 void init_clnt_srv(DOM_CLNT_SRV *logcln, const char *logon_srv,
1278 const char *comp_name)
1280 DEBUG(5,("init_clnt_srv: %d\n", __LINE__));
1282 if (logon_srv != NULL) {
1283 logcln->undoc_buffer = 1;
1284 init_unistr2(&logcln->uni_logon_srv, logon_srv, UNI_STR_TERMINATE);
1286 logcln->undoc_buffer = 0;
1289 if (comp_name != NULL) {
1290 logcln->undoc_buffer2 = 1;
1291 init_unistr2(&logcln->uni_comp_name, comp_name, UNI_STR_TERMINATE);
1293 logcln->undoc_buffer2 = 0;
1297 /*******************************************************************
1298 Inits or writes a DOM_CLNT_SRV structure.
1299 ********************************************************************/
1301 BOOL smb_io_clnt_srv(const char *desc, DOM_CLNT_SRV *logcln, prs_struct *ps, int depth)
1306 prs_debug(ps, depth, desc, "smb_io_clnt_srv");
1312 if(!prs_uint32("undoc_buffer ", ps, depth, &logcln->undoc_buffer))
1315 if (logcln->undoc_buffer != 0) {
1316 if(!smb_io_unistr2("unistr2", &logcln->uni_logon_srv, logcln->undoc_buffer, ps, depth))
1323 if(!prs_uint32("undoc_buffer2", ps, depth, &logcln->undoc_buffer2))
1326 if (logcln->undoc_buffer2 != 0) {
1327 if(!smb_io_unistr2("unistr2", &logcln->uni_comp_name, logcln->undoc_buffer2, ps, depth))
1334 /*******************************************************************
1335 Inits a DOM_LOG_INFO structure.
1336 ********************************************************************/
1338 void init_log_info(DOM_LOG_INFO *loginfo, const char *logon_srv, const char *acct_name,
1339 uint16 sec_chan, const char *comp_name)
1341 DEBUG(5,("make_log_info %d\n", __LINE__));
1343 loginfo->undoc_buffer = 1;
1345 init_unistr2(&loginfo->uni_logon_srv, logon_srv, UNI_STR_TERMINATE);
1346 init_unistr2(&loginfo->uni_acct_name, acct_name, UNI_STR_TERMINATE);
1348 loginfo->sec_chan = sec_chan;
1350 init_unistr2(&loginfo->uni_comp_name, comp_name, UNI_STR_TERMINATE);
1353 /*******************************************************************
1354 Reads or writes a DOM_LOG_INFO structure.
1355 ********************************************************************/
1357 BOOL smb_io_log_info(const char *desc, DOM_LOG_INFO *loginfo, prs_struct *ps, int depth)
1359 if (loginfo == NULL)
1362 prs_debug(ps, depth, desc, "smb_io_log_info");
1368 if(!prs_uint32("undoc_buffer", ps, depth, &loginfo->undoc_buffer))
1371 if(!smb_io_unistr2("unistr2", &loginfo->uni_logon_srv, True, ps, depth))
1373 if(!smb_io_unistr2("unistr2", &loginfo->uni_acct_name, True, ps, depth))
1376 if(!prs_uint16("sec_chan", ps, depth, &loginfo->sec_chan))
1379 if(!smb_io_unistr2("unistr2", &loginfo->uni_comp_name, True, ps, depth))
1385 /*******************************************************************
1386 Reads or writes a DOM_CHAL structure.
1387 ********************************************************************/
1389 BOOL smb_io_chal(const char *desc, DOM_CHAL *chal, prs_struct *ps, int depth)
1394 prs_debug(ps, depth, desc, "smb_io_chal");
1397 if(!prs_uint8s (False, "data", ps, depth, chal->data, 8))
1403 /*******************************************************************
1404 Reads or writes a DOM_CRED structure.
1405 ********************************************************************/
1407 BOOL smb_io_cred(const char *desc, DOM_CRED *cred, prs_struct *ps, int depth)
1412 prs_debug(ps, depth, desc, "smb_io_cred");
1418 if(!smb_io_chal ("", &cred->challenge, ps, depth))
1421 if(!smb_io_utime("", &cred->timestamp, ps, depth))
1427 /*******************************************************************
1428 Inits a DOM_CLNT_INFO2 structure.
1429 ********************************************************************/
1431 void init_clnt_info2(DOM_CLNT_INFO2 *clnt,
1432 const char *logon_srv, const char *comp_name,
1433 const DOM_CRED *clnt_cred)
1435 DEBUG(5,("make_clnt_info: %d\n", __LINE__));
1437 init_clnt_srv(&clnt->login, logon_srv, comp_name);
1439 if (clnt_cred != NULL) {
1441 memcpy(&clnt->cred, clnt_cred, sizeof(clnt->cred));
1447 /*******************************************************************
1448 Reads or writes a DOM_CLNT_INFO2 structure.
1449 ********************************************************************/
1451 BOOL smb_io_clnt_info2(const char *desc, DOM_CLNT_INFO2 *clnt, prs_struct *ps, int depth)
1456 prs_debug(ps, depth, desc, "smb_io_clnt_info2");
1462 if(!smb_io_clnt_srv("", &clnt->login, ps, depth))
1468 if(!prs_uint32("ptr_cred", ps, depth, &clnt->ptr_cred))
1470 if(!smb_io_cred("", &clnt->cred, ps, depth))
1476 /*******************************************************************
1477 Inits a DOM_CLNT_INFO structure.
1478 ********************************************************************/
1480 void init_clnt_info(DOM_CLNT_INFO *clnt,
1481 const char *logon_srv, const char *acct_name,
1482 uint16 sec_chan, const char *comp_name,
1483 const DOM_CRED *cred)
1485 DEBUG(5,("make_clnt_info\n"));
1487 init_log_info(&clnt->login, logon_srv, acct_name, sec_chan, comp_name);
1488 memcpy(&clnt->cred, cred, sizeof(clnt->cred));
1491 /*******************************************************************
1492 Reads or writes a DOM_CLNT_INFO structure.
1493 ********************************************************************/
1495 BOOL smb_io_clnt_info(const char *desc, DOM_CLNT_INFO *clnt, prs_struct *ps, int depth)
1500 prs_debug(ps, depth, desc, "smb_io_clnt_info");
1506 if(!smb_io_log_info("", &clnt->login, ps, depth))
1508 if(!smb_io_cred("", &clnt->cred, ps, depth))
1514 /*******************************************************************
1515 Inits a DOM_LOGON_ID structure.
1516 ********************************************************************/
1518 void init_logon_id(DOM_LOGON_ID *logonid, uint32 log_id_low, uint32 log_id_high)
1520 DEBUG(5,("make_logon_id: %d\n", __LINE__));
1522 logonid->low = log_id_low;
1523 logonid->high = log_id_high;
1526 /*******************************************************************
1527 Reads or writes a DOM_LOGON_ID structure.
1528 ********************************************************************/
1530 BOOL smb_io_logon_id(const char *desc, DOM_LOGON_ID *logonid, prs_struct *ps, int depth)
1532 if (logonid == NULL)
1535 prs_debug(ps, depth, desc, "smb_io_logon_id");
1541 if(!prs_uint32("low ", ps, depth, &logonid->low ))
1543 if(!prs_uint32("high", ps, depth, &logonid->high))
1549 /*******************************************************************
1550 Inits an OWF_INFO structure.
1551 ********************************************************************/
1553 void init_owf_info(OWF_INFO *hash, const uint8 data[16])
1555 DEBUG(5,("init_owf_info: %d\n", __LINE__));
1558 memcpy(hash->data, data, sizeof(hash->data));
1560 memset((char *)hash->data, '\0', sizeof(hash->data));
1563 /*******************************************************************
1564 Reads or writes an OWF_INFO structure.
1565 ********************************************************************/
1567 BOOL smb_io_owf_info(const char *desc, OWF_INFO *hash, prs_struct *ps, int depth)
1572 prs_debug(ps, depth, desc, "smb_io_owf_info");
1578 if(!prs_uint8s (False, "data", ps, depth, hash->data, 16))
1584 /*******************************************************************
1585 Reads or writes a DOM_GID structure.
1586 ********************************************************************/
1588 BOOL smb_io_gid(const char *desc, DOM_GID *gid, prs_struct *ps, int depth)
1593 prs_debug(ps, depth, desc, "smb_io_gid");
1599 if(!prs_uint32("g_rid", ps, depth, &gid->g_rid))
1601 if(!prs_uint32("attr ", ps, depth, &gid->attr))
1607 /*******************************************************************
1608 Reads or writes an POLICY_HND structure.
1609 ********************************************************************/
1611 BOOL smb_io_pol_hnd(const char *desc, POLICY_HND *pol, prs_struct *ps, int depth)
1616 prs_debug(ps, depth, desc, "smb_io_pol_hnd");
1622 if(UNMARSHALLING(ps))
1625 if (!prs_uint32("handle_type", ps, depth, &pol->handle_type))
1627 if (!smb_io_uuid("uuid", (struct GUID*)&pol->uuid, ps, depth))
1633 /*******************************************************************
1635 ********************************************************************/
1637 void init_unistr3(UNISTR3 *str, const char *buf)
1641 str->str.buffer = NULL;
1645 str->uni_str_len = strlen(buf) + 1;
1647 if (str->uni_str_len) {
1648 str->str.buffer = TALLOC_ZERO_ARRAY(talloc_tos(), uint16, str->uni_str_len);
1649 if (str->str.buffer == NULL)
1650 smb_panic("init_unistr3: malloc fail");
1652 rpcstr_push((char *)str->str.buffer, buf, str->uni_str_len * sizeof(uint16), STR_TERMINATE);
1654 str->str.buffer = NULL;
1658 /*******************************************************************
1659 Reads or writes a UNISTR3 structure.
1660 ********************************************************************/
1662 BOOL smb_io_unistr3(const char *desc, UNISTR3 *name, prs_struct *ps, int depth)
1667 prs_debug(ps, depth, desc, "smb_io_unistr3");
1673 if(!prs_uint32("uni_str_len", ps, depth, &name->uni_str_len))
1676 /* we're done if there is no string */
1678 if ( name->uni_str_len == 0 )
1681 /* don't know if len is specified by uni_str_len member... */
1682 /* assume unicode string is unicode-null-terminated, instead */
1684 if(!prs_unistr3(True, "unistr", name, ps, depth))
1690 /*******************************************************************
1691 Stream a uint64_struct
1692 ********************************************************************/
1693 BOOL prs_uint64(const char *name, prs_struct *ps, int depth, uint64 *data64)
1695 if (UNMARSHALLING(ps)) {
1698 if (!prs_uint32(name, ps, depth+1, &low))
1701 if (!prs_uint32(name, ps, depth+1, &high))
1704 *data64 = ((uint64_t)high << 32) + low;
1708 uint32 high = (*data64) >> 32, low = (*data64) & 0xFFFFFFFF;
1709 return prs_uint32(name, ps, depth+1, &low) &&
1710 prs_uint32(name, ps, depth+1, &high);
1714 /*******************************************************************
1715 reads or writes a BUFHDR2 structure.
1716 ********************************************************************/
1717 BOOL smb_io_bufhdr2(const char *desc, BUFHDR2 *hdr, prs_struct *ps, int depth)
1719 prs_debug(ps, depth, desc, "smb_io_bufhdr2");
1723 prs_uint32("info_level", ps, depth, &(hdr->info_level));
1724 prs_uint32("length ", ps, depth, &(hdr->length ));
1725 prs_uint32("buffer ", ps, depth, &(hdr->buffer ));
1730 /*******************************************************************
1731 reads or writes a BUFHDR4 structure.
1732 ********************************************************************/
1733 BOOL smb_io_bufhdr4(const char *desc, BUFHDR4 *hdr, prs_struct *ps, int depth)
1735 prs_debug(ps, depth, desc, "smb_io_bufhdr4");
1739 prs_uint32("size", ps, depth, &hdr->size);
1740 prs_uint32("buffer", ps, depth, &hdr->buffer);
1745 /*******************************************************************
1746 reads or writes a RPC_DATA_BLOB structure.
1747 ********************************************************************/
1749 BOOL smb_io_rpc_blob(const char *desc, RPC_DATA_BLOB *blob, prs_struct *ps, int depth)
1751 prs_debug(ps, depth, desc, "smb_io_rpc_blob");
1755 if ( !prs_uint32("buf_len", ps, depth, &blob->buf_len) )
1758 if ( blob->buf_len == 0 )
1761 if (UNMARSHALLING(ps)) {
1762 blob->buffer = PRS_ALLOC_MEM(ps, uint8, blob->buf_len);
1763 if (!blob->buffer) {
1768 if ( !prs_uint8s(True, "buffer", ps, depth, blob->buffer, blob->buf_len) )
1774 /*******************************************************************
1775 creates a UNIHDR structure.
1776 ********************************************************************/
1778 BOOL make_uni_hdr(UNIHDR *hdr, int len)
1784 hdr->uni_str_len = 2 * len;
1785 hdr->uni_max_len = 2 * len;
1786 hdr->buffer = len != 0 ? 1 : 0;
1791 /*******************************************************************
1792 creates a BUFHDR2 structure.
1793 ********************************************************************/
1794 BOOL make_bufhdr2(BUFHDR2 *hdr, uint32 info_level, uint32 length, uint32 buffer)
1796 hdr->info_level = info_level;
1797 hdr->length = length;
1798 hdr->buffer = buffer;
1803 /*******************************************************************
1804 return the length of a UNISTR string.
1805 ********************************************************************/
1807 uint32 str_len_uni(UNISTR *source)
1811 if (!source->buffer)
1814 while (source->buffer[i])