2 * Unix SMB/Netbios implementation.
4 * RPC Pipe client / server routines
5 * Copyright (C) Andrew Tridgell 1992-1997,
6 * Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
7 * Copyright (C) Paul Ashton 1997.
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.
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, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 extern int DEBUGLEVEL
;
29 /****************************************************************************
30 A temporary TALLOC context for things like unistrs, that is valid for
31 the life of a complete RPC call.
32 ****************************************************************************/
34 static TALLOC_CTX
*current_rpc_talloc
= NULL
;
36 TALLOC_CTX
*get_current_rpc_talloc(void)
38 return current_rpc_talloc
;
41 void set_current_rpc_talloc( TALLOC_CTX
*ctx
)
43 current_rpc_talloc
= ctx
;
46 static TALLOC_CTX
*main_loop_talloc
= NULL
;
48 /*******************************************************************
49 free up temporary memory - called from the main loop
50 ********************************************************************/
52 void main_loop_talloc_free(void)
54 if (!main_loop_talloc
)
56 talloc_destroy(main_loop_talloc
);
57 main_loop_talloc
= NULL
;
60 /*******************************************************************
61 Get a talloc context that is freed in the main loop...
62 ********************************************************************/
64 TALLOC_CTX
*main_loop_talloc_get(void)
66 if (!main_loop_talloc
) {
67 main_loop_talloc
= talloc_init();
68 if (!main_loop_talloc
)
69 smb_panic("main_loop_talloc: malloc fail\n");
72 return main_loop_talloc
;
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 ********************************************************************/
82 TALLOC_CTX
*get_talloc_ctx(void)
84 TALLOC_CTX
*tc
= get_current_rpc_talloc();
88 return main_loop_talloc_get();
91 /*******************************************************************
92 Reads or writes a UTIME type.
93 ********************************************************************/
95 static BOOL
smb_io_utime(char *desc
, UTIME
*t
, prs_struct
*ps
, int depth
)
100 prs_debug(ps
, depth
, desc
, "smb_io_utime");
106 if(!prs_uint32 ("time", ps
, depth
, &t
->time
))
112 /*******************************************************************
113 Reads or writes an NTTIME structure.
114 ********************************************************************/
116 BOOL
smb_io_time(char *desc
, NTTIME
*nttime
, prs_struct
*ps
, int depth
)
121 prs_debug(ps
, depth
, desc
, "smb_io_time");
127 if(!prs_uint32("low ", ps
, depth
, &nttime
->low
)) /* low part */
129 if(!prs_uint32("high", ps
, depth
, &nttime
->high
)) /* high part */
135 /*******************************************************************
136 Reads or writes a LOOKUP_LEVEL structure.
137 ********************************************************************/
139 BOOL
smb_io_lookup_level(char *desc
, LOOKUP_LEVEL
*level
, prs_struct
*ps
, int depth
)
144 prs_debug(ps
, depth
, desc
, "smb_io_lookup_level");
149 if(!prs_uint16("value", ps
, depth
, &level
->value
))
157 /*******************************************************************
158 Gets an enumeration handle from an ENUM_HND structure.
159 ********************************************************************/
161 uint32
get_enum_hnd(ENUM_HND
*enh
)
163 return (enh
&& enh
->ptr_hnd
!= 0) ? enh
->handle
: 0;
166 /*******************************************************************
167 Inits an ENUM_HND structure.
168 ********************************************************************/
170 void init_enum_hnd(ENUM_HND
*enh
, uint32 hnd
)
172 DEBUG(5,("smb_io_enum_hnd\n"));
174 enh
->ptr_hnd
= (hnd
!= 0) ? 1 : 0;
178 /*******************************************************************
179 Reads or writes an ENUM_HND structure.
180 ********************************************************************/
182 BOOL
smb_io_enum_hnd(char *desc
, ENUM_HND
*hnd
, prs_struct
*ps
, int depth
)
187 prs_debug(ps
, depth
, desc
, "smb_io_enum_hnd");
193 if(!prs_uint32("ptr_hnd", ps
, depth
, &hnd
->ptr_hnd
)) /* pointer */
196 if (hnd
->ptr_hnd
!= 0) {
197 if(!prs_uint32("handle ", ps
, depth
, &hnd
->handle
)) /* enum handle */
204 /*******************************************************************
205 Reads or writes a DOM_SID structure.
206 ********************************************************************/
208 BOOL
smb_io_dom_sid(char *desc
, DOM_SID
*sid
, prs_struct
*ps
, int depth
)
215 prs_debug(ps
, depth
, desc
, "smb_io_dom_sid");
221 if(!prs_uint8 ("sid_rev_num", ps
, depth
, &sid
->sid_rev_num
))
223 if(!prs_uint8 ("num_auths ", ps
, depth
, &sid
->num_auths
))
226 for (i
= 0; i
< 6; i
++)
229 slprintf(tmp
, sizeof(tmp
) - 1, "id_auth[%d] ", i
);
230 if(!prs_uint8 (tmp
, ps
, depth
, &sid
->id_auth
[i
]))
234 /* oops! XXXX should really issue a warning here... */
235 if (sid
->num_auths
> MAXSUBAUTHS
)
236 sid
->num_auths
= MAXSUBAUTHS
;
238 if(!prs_uint32s(False
, "sub_auths ", ps
, depth
, sid
->sub_auths
, sid
->num_auths
))
244 /*******************************************************************
245 Inits a DOM_SID structure.
247 BIG NOTE: this function only does SIDS where the identauth is not >= 2^32
248 identauth >= 2^32 can be detected because it will be specified in hex
249 ********************************************************************/
251 void init_dom_sid(DOM_SID
*sid
, char *str_sid
)
259 DEBUG(4,("netlogon domain SID: none\n"));
260 sid
->sid_rev_num
= 0;
265 pstrcpy(domsid
, str_sid
);
267 DEBUG(4,("init_dom_sid %d SID: %s\n", __LINE__
, domsid
));
269 /* assume, but should check, that domsid starts "S-" */
270 p
= strtok(domsid
+2,"-");
271 sid
->sid_rev_num
= atoi(p
);
273 /* identauth in decimal should be < 2^32 */
274 /* identauth in hex should be >= 2^32 */
275 identauth
= atoi(strtok(0,"-"));
277 DEBUG(4,("netlogon rev %d\n", sid
->sid_rev_num
));
278 DEBUG(4,("netlogon %s ia %d\n", p
, identauth
));
282 sid
->id_auth
[2] = (identauth
& 0xff000000) >> 24;
283 sid
->id_auth
[3] = (identauth
& 0x00ff0000) >> 16;
284 sid
->id_auth
[4] = (identauth
& 0x0000ff00) >> 8;
285 sid
->id_auth
[5] = (identauth
& 0x000000ff);
289 while ((p
= strtok(0, "-")) != NULL
&& sid
->num_auths
< MAXSUBAUTHS
)
290 sid
->sub_auths
[sid
->num_auths
++] = atoi(p
);
292 DEBUG(4,("init_dom_sid: %d SID: %s\n", __LINE__
, domsid
));
295 /*******************************************************************
296 Inits a DOM_SID2 structure.
297 ********************************************************************/
299 void init_dom_sid2(DOM_SID2
*sid2
, DOM_SID
*sid
)
302 sid2
->num_auths
= sid2
->sid
.num_auths
;
305 /*******************************************************************
306 Reads or writes a DOM_SID2 structure.
307 ********************************************************************/
309 BOOL
smb_io_dom_sid2(char *desc
, DOM_SID2
*sid
, prs_struct
*ps
, int depth
)
314 prs_debug(ps
, depth
, desc
, "smb_io_dom_sid2");
320 if(!prs_uint32("num_auths", ps
, depth
, &sid
->num_auths
))
323 if(!smb_io_dom_sid("sid", &sid
->sid
, ps
, depth
))
329 /*******************************************************************
330 creates a STRHDR structure.
331 ********************************************************************/
333 void init_str_hdr(STRHDR
*hdr
, int max_len
, int len
, uint32 buffer
)
335 hdr
->str_max_len
= max_len
;
336 hdr
->str_str_len
= len
;
337 hdr
->buffer
= buffer
;
340 /*******************************************************************
341 Reads or writes a STRHDR structure.
342 ********************************************************************/
344 BOOL
smb_io_strhdr(char *desc
, STRHDR
*hdr
, prs_struct
*ps
, int depth
)
349 prs_debug(ps
, depth
, desc
, "smb_io_strhdr");
354 if(!prs_uint16("str_str_len", ps
, depth
, &hdr
->str_str_len
))
356 if(!prs_uint16("str_max_len", ps
, depth
, &hdr
->str_max_len
))
358 if(!prs_uint32("buffer ", ps
, depth
, &hdr
->buffer
))
364 /*******************************************************************
365 Inits a UNIHDR structure.
366 ********************************************************************/
368 void init_uni_hdr(UNIHDR
*hdr
, int len
)
370 hdr
->uni_str_len
= 2 * len
;
371 hdr
->uni_max_len
= 2 * len
;
372 hdr
->buffer
= len
!= 0 ? 1 : 0;
375 /*******************************************************************
376 Reads or writes a UNIHDR structure.
377 ********************************************************************/
379 BOOL
smb_io_unihdr(char *desc
, UNIHDR
*hdr
, prs_struct
*ps
, int depth
)
384 prs_debug(ps
, depth
, desc
, "smb_io_unihdr");
390 if(!prs_uint16("uni_str_len", ps
, depth
, &hdr
->uni_str_len
))
392 if(!prs_uint16("uni_max_len", ps
, depth
, &hdr
->uni_max_len
))
394 if(!prs_uint32("buffer ", ps
, depth
, &hdr
->buffer
))
400 /*******************************************************************
401 Inits a BUFHDR structure.
402 ********************************************************************/
404 void init_buf_hdr(BUFHDR
*hdr
, int max_len
, int len
)
406 hdr
->buf_max_len
= max_len
;
410 /*******************************************************************
411 prs_uint16 wrapper. Call this and it sets up a pointer to where the
412 uint16 should be stored, or gets the size if reading.
413 ********************************************************************/
415 BOOL
smb_io_hdrbuf_pre(char *desc
, BUFHDR
*hdr
, prs_struct
*ps
, int depth
, uint32
*offset
)
417 (*offset
) = prs_offset(ps
);
422 if(!smb_io_hdrbuf(desc
, hdr
, ps
, depth
))
429 if(!prs_set_offset(ps
, prs_offset(ps
) + (sizeof(uint32
) * 2)))
436 /*******************************************************************
437 smb_io_hdrbuf wrapper. Call this and it retrospectively stores the size.
438 Does nothing on reading, as that is already handled by ...._pre()
439 ********************************************************************/
441 BOOL
smb_io_hdrbuf_post(char *desc
, BUFHDR
*hdr
, prs_struct
*ps
, int depth
,
442 uint32 ptr_hdrbuf
, uint32 max_len
, uint32 len
)
445 /* writing: go back and do a retrospective job. i hate this */
447 uint32 old_offset
= prs_offset(ps
);
449 init_buf_hdr(hdr
, max_len
, len
);
450 if(!prs_set_offset(ps
, ptr_hdrbuf
))
452 if(!smb_io_hdrbuf(desc
, hdr
, ps
, depth
))
455 if(!prs_set_offset(ps
, old_offset
))
462 /*******************************************************************
463 Reads or writes a BUFHDR structure.
464 ********************************************************************/
466 BOOL
smb_io_hdrbuf(char *desc
, BUFHDR
*hdr
, prs_struct
*ps
, int depth
)
471 prs_debug(ps
, depth
, desc
, "smb_io_hdrbuf");
477 if(!prs_uint32("buf_max_len", ps
, depth
, &hdr
->buf_max_len
))
479 if(!prs_uint32("buf_len ", ps
, depth
, &hdr
->buf_len
))
485 /*******************************************************************
486 creates a UNIHDR2 structure.
487 ********************************************************************/
489 void init_uni_hdr2(UNIHDR2
*hdr
, int len
)
491 init_uni_hdr(&hdr
->unihdr
, len
);
492 hdr
->buffer
= (len
> 0) ? 1 : 0;
495 /*******************************************************************
496 Reads or writes a UNIHDR2 structure.
497 ********************************************************************/
499 BOOL
smb_io_unihdr2(char *desc
, UNIHDR2
*hdr2
, prs_struct
*ps
, int depth
)
504 prs_debug(ps
, depth
, desc
, "smb_io_unihdr2");
510 if(!smb_io_unihdr("hdr", &hdr2
->unihdr
, ps
, depth
))
512 if(!prs_uint32("buffer", ps
, depth
, &hdr2
->buffer
))
518 /*******************************************************************
519 Inits a UNISTR structure.
520 ********************************************************************/
522 void init_unistr(UNISTR
*str
, const char *buf
)
532 len
= strlen(buf
) + 1;
534 if (len
< MAX_UNISTRLEN
)
536 len
*= sizeof(uint16
);
538 str
->buffer
= (uint16
*)talloc_zero(get_talloc_ctx(), len
);
539 if (str
->buffer
== NULL
)
540 smb_panic("init_unistr: malloc fail\n");
542 /* store the string (null-terminated copy) */
543 dos_struni2((char *)str
->buffer
, buf
, len
);
546 /*******************************************************************
547 reads or writes a UNISTR structure.
548 XXXX NOTE: UNISTR structures NEED to be null-terminated.
549 ********************************************************************/
551 BOOL
smb_io_unistr(char *desc
, UNISTR
*uni
, prs_struct
*ps
, int depth
)
556 prs_debug(ps
, depth
, desc
, "smb_io_unistr");
561 if(!prs_unistr("unistr", ps
, depth
, uni
))
567 /*******************************************************************
568 Allocate the BUFFER3 memory.
569 ********************************************************************/
571 static void create_buffer3(BUFFER3
*str
, size_t len
)
573 if (len
< MAX_BUFFERLEN
)
576 str
->buffer
= talloc_zero(get_talloc_ctx(), len
);
577 if (str
->buffer
== NULL
)
578 smb_panic("create_buffer3: talloc fail\n");
582 /*******************************************************************
583 Inits a BUFFER3 structure from a uint32
584 ********************************************************************/
586 void init_buffer3_uint32(BUFFER3
*str
, uint32 val
)
590 /* set up string lengths. */
591 str
->buf_max_len
= sizeof(uint32
);
592 str
->buf_len
= sizeof(uint32
);
594 create_buffer3(str
, sizeof(uint32
));
595 SIVAL(str
->buffer
, 0, val
);
598 /*******************************************************************
599 Inits a BUFFER3 structure.
600 ********************************************************************/
602 void init_buffer3_str(BUFFER3
*str
, char *buf
, int len
)
606 /* set up string lengths. */
607 str
->buf_max_len
= len
* 2;
608 str
->buf_len
= len
* 2;
610 create_buffer3(str
, str
->buf_max_len
);
612 /* store the string (null-terminated 8 bit chars into 16 bit chars) */
613 dos_struni2((char *)str
->buffer
, buf
, str
->buf_max_len
);
616 /*******************************************************************
617 Inits a BUFFER3 structure from a hex string.
618 ********************************************************************/
620 void init_buffer3_hex(BUFFER3
*str
, char *buf
)
623 create_buffer3(str
, strlen(buf
));
624 str
->buf_max_len
= str
->buf_len
= strhex_to_str((char *)str
->buffer
, sizeof(str
->buffer
), buf
);
627 /*******************************************************************
628 Inits a BUFFER3 structure.
629 ********************************************************************/
631 void init_buffer3_bytes(BUFFER3
*str
, uint8
*buf
, int len
)
635 /* max buffer size (allocated size) */
636 str
->buf_max_len
= len
;
638 create_buffer3(str
, len
);
639 memcpy(str
->buffer
, buf
, len
);
641 str
->buf_len
= buf
!= NULL
? len
: 0;
644 /*******************************************************************
645 Reads or writes a BUFFER3 structure.
646 the uni_max_len member tells you how large the buffer is.
647 the uni_str_len member tells you how much of the buffer is really used.
648 ********************************************************************/
650 BOOL
smb_io_buffer3(char *desc
, BUFFER3
*buf3
, prs_struct
*ps
, int depth
)
655 prs_debug(ps
, depth
, desc
, "smb_io_buffer3");
661 if(!prs_uint32("uni_max_len", ps
, depth
, &buf3
->buf_max_len
))
664 if (UNMARSHALLING(ps
)) {
665 buf3
->buffer
= (unsigned char *)prs_alloc_mem(ps
, buf3
->buf_max_len
);
666 if (buf3
->buffer
== NULL
)
670 if(!prs_uint8s(True
, "buffer ", ps
, depth
, buf3
->buffer
, buf3
->buf_max_len
))
673 if(!prs_uint32("buf_len ", ps
, depth
, &buf3
->buf_len
))
679 /*******************************************************************
680 reads or writes a BUFFER5 structure.
681 the buf_len member tells you how large the buffer is.
682 ********************************************************************/
683 BOOL
smb_io_buffer5(char *desc
, BUFFER5
*buf5
, prs_struct
*ps
, int depth
)
685 prs_debug(ps
, depth
, desc
, "smb_io_buffer5");
688 if (buf5
== NULL
) return False
;
692 if(!prs_uint32("buf_len", ps
, depth
, &buf5
->buf_len
))
696 if(!prs_buffer5(True
, "buffer" , ps
, depth
, buf5
))
702 /*******************************************************************
703 Inits a BUFFER2 structure.
704 ********************************************************************/
706 void init_buffer2(BUFFER2
*str
, uint8
*buf
, int len
)
710 /* max buffer size (allocated size) */
711 str
->buf_max_len
= len
;
713 str
->buf_len
= buf
!= NULL
? len
: 0;
716 if (len
< MAX_BUFFERLEN
)
718 str
->buffer
= talloc_zero(get_talloc_ctx(), len
);
719 if (str
->buffer
== NULL
)
720 smb_panic("init_buffer2: talloc fail\n");
721 memcpy(str
->buffer
, buf
, MIN(str
->buf_len
, len
));
725 /*******************************************************************
726 Reads or writes a BUFFER2 structure.
727 the uni_max_len member tells you how large the buffer is.
728 the uni_str_len member tells you how much of the buffer is really used.
729 ********************************************************************/
731 BOOL
smb_io_buffer2(char *desc
, BUFFER2
*buf2
, uint32 buffer
, prs_struct
*ps
, int depth
)
738 prs_debug(ps
, depth
, desc
, "smb_io_buffer2");
744 if(!prs_uint32("uni_max_len", ps
, depth
, &buf2
->buf_max_len
))
746 if(!prs_uint32("undoc ", ps
, depth
, &buf2
->undoc
))
748 if(!prs_uint32("buf_len ", ps
, depth
, &buf2
->buf_len
))
751 /* buffer advanced by indicated length of string
752 NOT by searching for null-termination */
754 if(!prs_buffer2(True
, "buffer ", ps
, depth
, buf2
))
759 prs_debug(ps
, depth
, desc
, "smb_io_buffer2 - NULL");
761 memset((char *)buf2
, '\0', sizeof(*buf2
));
767 /*******************************************************************
768 creates a UNISTR2 structure: sets up the buffer, too
769 ********************************************************************/
771 void init_buf_unistr2(UNISTR2
*str
, uint32
*ptr
, const char *buf
)
776 init_unistr2(str
, buf
, strlen(buf
)+1);
781 init_unistr2(str
, "", 0);
786 /*******************************************************************
787 Copies a UNISTR2 structure.
788 ********************************************************************/
790 void copy_unistr2(UNISTR2
*str
, UNISTR2
*from
)
793 /* set up string lengths. add one if string is not null-terminated */
794 str
->uni_max_len
= from
->uni_max_len
;
795 str
->undoc
= from
->undoc
;
796 str
->uni_str_len
= from
->uni_str_len
;
798 if (from
->buffer
== NULL
)
801 /* the string buffer is allocated to the maximum size
802 (the the length of the source string) to prevent
803 reallocation of memory. */
804 if (str
->buffer
== NULL
) {
805 size_t len
= from
->uni_max_len
* sizeof(uint16
);
807 if (len
< MAX_UNISTRLEN
)
809 len
*= sizeof(uint16
);
811 str
->buffer
= (uint16
*)talloc_zero(get_talloc_ctx(), len
);
812 if ((str
->buffer
== NULL
) && (len
> 0 ))
814 smb_panic("copy_unistr2: talloc fail\n");
819 /* copy the string */
820 memcpy(str
->buffer
, from
->buffer
, from
->uni_max_len
*sizeof(uint16
));
823 /*******************************************************************
824 Creates a STRING2 structure.
825 ********************************************************************/
827 void init_string2(STRING2
*str
, char *buf
, int len
)
831 /* set up string lengths. */
832 str
->str_max_len
= len
;
834 str
->str_str_len
= len
;
836 /* store the string */
838 if (len
< MAX_STRINGLEN
)
839 alloc_len
= MAX_STRINGLEN
;
840 str
->buffer
= talloc_zero(get_talloc_ctx(), alloc_len
);
841 if (str
->buffer
== NULL
)
842 smb_panic("init_string2: malloc fail\n");
843 memcpy(str
->buffer
, buf
, len
);
847 /*******************************************************************
848 Reads or writes a STRING2 structure.
849 XXXX NOTE: STRING2 structures need NOT be null-terminated.
850 the str_str_len member tells you how long the string is;
851 the str_max_len member tells you how large the buffer is.
852 ********************************************************************/
854 BOOL
smb_io_string2(char *desc
, STRING2
*str2
, uint32 buffer
, prs_struct
*ps
, int depth
)
861 prs_debug(ps
, depth
, desc
, "smb_io_string2");
867 if(!prs_uint32("str_max_len", ps
, depth
, &str2
->str_max_len
))
869 if(!prs_uint32("undoc ", ps
, depth
, &str2
->undoc
))
871 if(!prs_uint32("str_str_len", ps
, depth
, &str2
->str_str_len
))
874 /* buffer advanced by indicated length of string
875 NOT by searching for null-termination */
876 if(!prs_string2(True
, "buffer ", ps
, depth
, str2
))
881 prs_debug(ps
, depth
, desc
, "smb_io_string2 - NULL");
883 memset((char *)str2
, '\0', sizeof(*str2
));
890 /*******************************************************************
891 Inits a UNISTR2 structure.
892 ********************************************************************/
894 void init_unistr2(UNISTR2
*str
, const char *buf
, size_t len
)
898 /* set up string lengths. */
899 str
->uni_max_len
= (uint32
)len
;
901 str
->uni_str_len
= (uint32
)len
;
903 if (len
< MAX_UNISTRLEN
)
905 len
*= sizeof(uint16
);
907 str
->buffer
= (uint16
*)talloc_zero(get_talloc_ctx(), len
);
908 if ((str
->buffer
== NULL
) && (len
> 0))
910 smb_panic("init_unistr2: malloc fail\n");
914 /* store the string (null-terminated 8 bit chars into 16 bit chars) */
915 dos_struni2((char *)str
->buffer
, buf
, len
);
918 /*******************************************************************
919 Inits a UNISTR2 structure from a UNISTR
920 ********************************************************************/
921 void init_unistr2_from_unistr (UNISTR2
*to
, UNISTR
*from
)
926 /* the destination UNISTR2 should never be NULL.
927 if it is it is a programming error */
929 /* if the source UNISTR is NULL, then zero out
930 the destination string and return */
932 if ((from
== NULL
) || (from
->buffer
== NULL
))
935 /* get the length; UNISTR must be NULL terminated */
937 while ((from
->buffer
)[i
]!='\0')
939 i
++; /* one more to catch the terminating NULL */
940 /* is this necessary -- jerry? I need to think */
942 /* set up string lengths; uni_max_len is set to i+1
943 because we need to account for the final NULL termination */
948 /* allocate the space and copy the string buffer */
949 to
->buffer
= (uint16
*)talloc_zero(get_talloc_ctx(), sizeof(uint16
)*(to
->uni_str_len
));
950 if (to
->buffer
== NULL
)
951 smb_panic("init_unistr2_from_unistr: malloc fail\n");
952 memcpy(to
->buffer
, from
->buffer
, to
->uni_max_len
*sizeof(uint16
));
958 /*******************************************************************
959 Reads or writes a UNISTR2 structure.
960 XXXX NOTE: UNISTR2 structures need NOT be null-terminated.
961 the uni_str_len member tells you how long the string is;
962 the uni_max_len member tells you how large the buffer is.
963 ********************************************************************/
965 BOOL
smb_io_unistr2(char *desc
, UNISTR2
*uni2
, uint32 buffer
, prs_struct
*ps
, int depth
)
972 prs_debug(ps
, depth
, desc
, "smb_io_unistr2");
978 if(!prs_uint32("uni_max_len", ps
, depth
, &uni2
->uni_max_len
))
980 if(!prs_uint32("undoc ", ps
, depth
, &uni2
->undoc
))
982 if(!prs_uint32("uni_str_len", ps
, depth
, &uni2
->uni_str_len
))
985 /* buffer advanced by indicated length of string
986 NOT by searching for null-termination */
987 if(!prs_unistr2(True
, "buffer ", ps
, depth
, uni2
))
992 prs_debug(ps
, depth
, desc
, "smb_io_unistr2 - NULL");
994 memset((char *)uni2
, '\0', sizeof(*uni2
));
1001 /*******************************************************************
1002 Inits a DOM_RID2 structure.
1003 ********************************************************************/
1005 void init_dom_rid2(DOM_RID2
*rid2
, uint32 rid
, uint8 type
, uint32 idx
)
1009 rid2
->rid_idx
= idx
;
1012 /*******************************************************************
1013 Reads or writes a DOM_RID2 structure.
1014 ********************************************************************/
1016 BOOL
smb_io_dom_rid2(char *desc
, DOM_RID2
*rid2
, prs_struct
*ps
, int depth
)
1021 prs_debug(ps
, depth
, desc
, "smb_io_dom_rid2");
1027 if(!prs_uint8("type ", ps
, depth
, &rid2
->type
))
1031 if(!prs_uint32("rid ", ps
, depth
, &rid2
->rid
))
1033 if(!prs_uint32("rid_idx", ps
, depth
, &rid2
->rid_idx
))
1039 /*******************************************************************
1040 creates a DOM_RID3 structure.
1041 ********************************************************************/
1043 void init_dom_rid3(DOM_RID3
*rid3
, uint32 rid
, uint8 type
)
1047 rid3
->ptr_type
= 0x1; /* non-zero, basically. */
1052 /*******************************************************************
1053 reads or writes a DOM_RID3 structure.
1054 ********************************************************************/
1056 BOOL
smb_io_dom_rid3(char *desc
, DOM_RID3
*rid3
, prs_struct
*ps
, int depth
)
1061 prs_debug(ps
, depth
, desc
, "smb_io_dom_rid3");
1067 if(!prs_uint32("rid ", ps
, depth
, &rid3
->rid
))
1069 if(!prs_uint32("type1 ", ps
, depth
, &rid3
->type1
))
1071 if(!prs_uint32("ptr_type", ps
, depth
, &rid3
->ptr_type
))
1073 if(!prs_uint32("type2 ", ps
, depth
, &rid3
->type2
))
1075 if(!prs_uint32("unk ", ps
, depth
, &rid3
->unk
))
1081 /*******************************************************************
1082 Inits a DOM_RID4 structure.
1083 ********************************************************************/
1085 void init_dom_rid4(DOM_RID4
*rid4
, uint16 unknown
, uint16 attr
, uint32 rid
)
1087 rid4
->unknown
= unknown
;
1092 /*******************************************************************
1093 Inits a DOM_CLNT_SRV structure.
1094 ********************************************************************/
1096 static void init_clnt_srv(DOM_CLNT_SRV
*log
, char *logon_srv
, char *comp_name
)
1098 DEBUG(5,("init_clnt_srv: %d\n", __LINE__
));
1100 if (logon_srv
!= NULL
) {
1101 log
->undoc_buffer
= 1;
1102 init_unistr2(&log
->uni_logon_srv
, logon_srv
, strlen(logon_srv
)+1);
1104 log
->undoc_buffer
= 0;
1107 if (comp_name
!= NULL
) {
1108 log
->undoc_buffer2
= 1;
1109 init_unistr2(&log
->uni_comp_name
, comp_name
, strlen(comp_name
)+1);
1111 log
->undoc_buffer2
= 0;
1115 /*******************************************************************
1116 Inits or writes a DOM_CLNT_SRV structure.
1117 ********************************************************************/
1119 static BOOL
smb_io_clnt_srv(char *desc
, DOM_CLNT_SRV
*log
, prs_struct
*ps
, int depth
)
1124 prs_debug(ps
, depth
, desc
, "smb_io_clnt_srv");
1130 if(!prs_uint32("undoc_buffer ", ps
, depth
, &log
->undoc_buffer
))
1133 if (log
->undoc_buffer
!= 0) {
1134 if(!smb_io_unistr2("unistr2", &log
->uni_logon_srv
, log
->undoc_buffer
, ps
, depth
))
1141 if(!prs_uint32("undoc_buffer2", ps
, depth
, &log
->undoc_buffer2
))
1144 if (log
->undoc_buffer2
!= 0) {
1145 if(!smb_io_unistr2("unistr2", &log
->uni_comp_name
, log
->undoc_buffer2
, ps
, depth
))
1152 /*******************************************************************
1153 Inits a DOM_LOG_INFO structure.
1154 ********************************************************************/
1156 void init_log_info(DOM_LOG_INFO
*log
, char *logon_srv
, char *acct_name
,
1157 uint16 sec_chan
, char *comp_name
)
1159 DEBUG(5,("make_log_info %d\n", __LINE__
));
1161 log
->undoc_buffer
= 1;
1163 init_unistr2(&log
->uni_logon_srv
, logon_srv
, strlen(logon_srv
)+1);
1164 init_unistr2(&log
->uni_acct_name
, acct_name
, strlen(acct_name
)+1);
1166 log
->sec_chan
= sec_chan
;
1168 init_unistr2(&log
->uni_comp_name
, comp_name
, strlen(comp_name
)+1);
1171 /*******************************************************************
1172 Reads or writes a DOM_LOG_INFO structure.
1173 ********************************************************************/
1175 BOOL
smb_io_log_info(char *desc
, DOM_LOG_INFO
*log
, prs_struct
*ps
, int depth
)
1180 prs_debug(ps
, depth
, desc
, "smb_io_log_info");
1186 if(!prs_uint32("undoc_buffer", ps
, depth
, &log
->undoc_buffer
))
1189 if(!smb_io_unistr2("unistr2", &log
->uni_logon_srv
, True
, ps
, depth
))
1191 if(!smb_io_unistr2("unistr2", &log
->uni_acct_name
, True
, ps
, depth
))
1194 if(!prs_uint16("sec_chan", ps
, depth
, &log
->sec_chan
))
1197 if(!smb_io_unistr2("unistr2", &log
->uni_comp_name
, True
, ps
, depth
))
1203 /*******************************************************************
1204 Reads or writes a DOM_CHAL structure.
1205 ********************************************************************/
1207 BOOL
smb_io_chal(char *desc
, DOM_CHAL
*chal
, prs_struct
*ps
, int depth
)
1212 prs_debug(ps
, depth
, desc
, "smb_io_chal");
1218 if(!prs_uint8s (False
, "data", ps
, depth
, chal
->data
, 8))
1224 /*******************************************************************
1225 Reads or writes a DOM_CRED structure.
1226 ********************************************************************/
1228 BOOL
smb_io_cred(char *desc
, DOM_CRED
*cred
, prs_struct
*ps
, int depth
)
1233 prs_debug(ps
, depth
, desc
, "smb_io_cred");
1239 if(!smb_io_chal ("", &cred
->challenge
, ps
, depth
))
1241 if(!smb_io_utime("", &cred
->timestamp
, ps
, depth
))
1247 /*******************************************************************
1248 Inits a DOM_CLNT_INFO2 structure.
1249 ********************************************************************/
1251 void init_clnt_info2(DOM_CLNT_INFO2
*clnt
,
1252 char *logon_srv
, char *comp_name
,
1253 DOM_CRED
*clnt_cred
)
1255 DEBUG(5,("make_clnt_info: %d\n", __LINE__
));
1257 init_clnt_srv(&(clnt
->login
), logon_srv
, comp_name
);
1259 if (clnt_cred
!= NULL
) {
1261 memcpy(&(clnt
->cred
), clnt_cred
, sizeof(clnt
->cred
));
1267 /*******************************************************************
1268 Reads or writes a DOM_CLNT_INFO2 structure.
1269 ********************************************************************/
1271 BOOL
smb_io_clnt_info2(char *desc
, DOM_CLNT_INFO2
*clnt
, prs_struct
*ps
, int depth
)
1276 prs_debug(ps
, depth
, desc
, "smb_io_clnt_info2");
1282 if(!smb_io_clnt_srv("", &clnt
->login
, ps
, depth
))
1288 if(!prs_uint32("ptr_cred", ps
, depth
, &clnt
->ptr_cred
))
1290 if(!smb_io_cred("", &clnt
->cred
, ps
, depth
))
1296 /*******************************************************************
1297 Inits a DOM_CLNT_INFO structure.
1298 ********************************************************************/
1300 void init_clnt_info(DOM_CLNT_INFO
*clnt
,
1301 char *logon_srv
, char *acct_name
,
1302 uint16 sec_chan
, char *comp_name
,
1305 DEBUG(5,("make_clnt_info\n"));
1307 init_log_info(&clnt
->login
, logon_srv
, acct_name
, sec_chan
, comp_name
);
1308 memcpy(&clnt
->cred
, cred
, sizeof(clnt
->cred
));
1311 /*******************************************************************
1312 Reads or writes a DOM_CLNT_INFO structure.
1313 ********************************************************************/
1315 BOOL
smb_io_clnt_info(char *desc
, DOM_CLNT_INFO
*clnt
, prs_struct
*ps
, int depth
)
1320 prs_debug(ps
, depth
, desc
, "smb_io_clnt_info");
1326 if(!smb_io_log_info("", &clnt
->login
, ps
, depth
))
1328 if(!smb_io_cred("", &clnt
->cred
, ps
, depth
))
1334 /*******************************************************************
1335 Inits a DOM_LOGON_ID structure.
1336 ********************************************************************/
1338 void init_logon_id(DOM_LOGON_ID
*log
, uint32 log_id_low
, uint32 log_id_high
)
1340 DEBUG(5,("make_logon_id: %d\n", __LINE__
));
1342 log
->low
= log_id_low
;
1343 log
->high
= log_id_high
;
1346 /*******************************************************************
1347 Reads or writes a DOM_LOGON_ID structure.
1348 ********************************************************************/
1350 BOOL
smb_io_logon_id(char *desc
, DOM_LOGON_ID
*log
, prs_struct
*ps
, int depth
)
1355 prs_debug(ps
, depth
, desc
, "smb_io_logon_id");
1361 if(!prs_uint32("low ", ps
, depth
, &log
->low
))
1363 if(!prs_uint32("high", ps
, depth
, &log
->high
))
1369 /*******************************************************************
1370 Inits an OWF_INFO structure.
1371 ********************************************************************/
1373 void init_owf_info(OWF_INFO
*hash
, uint8 data
[16])
1375 DEBUG(5,("init_owf_info: %d\n", __LINE__
));
1378 memcpy(hash
->data
, data
, sizeof(hash
->data
));
1380 memset((char *)hash
->data
, '\0', sizeof(hash
->data
));
1383 /*******************************************************************
1384 Reads or writes an OWF_INFO structure.
1385 ********************************************************************/
1387 BOOL
smb_io_owf_info(char *desc
, OWF_INFO
*hash
, prs_struct
*ps
, int depth
)
1392 prs_debug(ps
, depth
, desc
, "smb_io_owf_info");
1398 if(!prs_uint8s (False
, "data", ps
, depth
, hash
->data
, 16))
1404 /*******************************************************************
1405 Reads or writes a DOM_GID structure.
1406 ********************************************************************/
1408 BOOL
smb_io_gid(char *desc
, DOM_GID
*gid
, prs_struct
*ps
, int depth
)
1413 prs_debug(ps
, depth
, desc
, "smb_io_gid");
1419 if(!prs_uint32("g_rid", ps
, depth
, &gid
->g_rid
))
1421 if(!prs_uint32("attr ", ps
, depth
, &gid
->attr
))
1427 /*******************************************************************
1428 Reads or writes an POLICY_HND structure.
1429 ********************************************************************/
1431 BOOL
smb_io_pol_hnd(char *desc
, POLICY_HND
*pol
, prs_struct
*ps
, int depth
)
1436 prs_debug(ps
, depth
, desc
, "smb_io_pol_hnd");
1442 if(UNMARSHALLING(ps
))
1445 if (!prs_uint32("data1", ps
, depth
, &pol
->data1
))
1447 if (!prs_uint32("data2", ps
, depth
, &pol
->data2
))
1449 if (!prs_uint16("data3", ps
, depth
, &pol
->data3
))
1451 if (!prs_uint16("data4", ps
, depth
, &pol
->data4
))
1453 if(!prs_uint8s (False
, "data5", ps
, depth
, pol
->data5
, sizeof(pol
->data5
)))
1459 /*******************************************************************
1461 ********************************************************************/
1463 void init_unistr3(UNISTR3
*str
, const char *buf
)
1469 str
->str
.buffer
= NULL
;
1473 len
= strlen(buf
) + 1;
1475 str
->uni_str_len
=len
;
1477 if (len
< MAX_UNISTRLEN
)
1478 len
= MAX_UNISTRLEN
;
1480 len
*= sizeof(uint16
);
1482 str
->str
.buffer
= (uint16
*)talloc_zero(get_talloc_ctx(), len
);
1483 if (str
->str
.buffer
== NULL
)
1484 smb_panic("init_unistr3: malloc fail\n");
1486 /* store the string (null-terminated copy) */
1487 dos_struni2((char *)str
->str
.buffer
, buf
, len
);
1490 /*******************************************************************
1491 Reads or writes a UNISTR3 structure.
1492 ********************************************************************/
1494 BOOL
smb_io_unistr3(char *desc
, UNISTR3
*name
, prs_struct
*ps
, int depth
)
1499 prs_debug(ps
, depth
, desc
, "smb_io_unistr3");
1505 if(!prs_uint32("uni_str_len", ps
, depth
, &name
->uni_str_len
))
1508 /* don't know if len is specified by uni_str_len member... */
1509 /* assume unicode string is unicode-null-terminated, instead */
1511 if(!prs_unistr3(True
, "unistr", name
, ps
, depth
))
1518 /*******************************************************************
1519 Stream a uint64_struct
1520 ********************************************************************/
1521 BOOL
prs_uint64(char *name
, prs_struct
*ps
, int depth
, UINT64_S
*data64
)
1523 return prs_uint32(name
, ps
, depth
+1, &data64
->low
) &&
1524 prs_uint32(name
, ps
, depth
+1, &data64
->high
);