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.
26 /****************************************************************************
27 A temporary TALLOC context for things like unistrs, that is valid for
28 the life of a complete RPC call.
29 ****************************************************************************/
31 static TALLOC_CTX
*current_rpc_talloc
= NULL
;
33 TALLOC_CTX
*get_current_rpc_talloc(void)
35 return current_rpc_talloc
;
38 void set_current_rpc_talloc( TALLOC_CTX
*ctx
)
40 current_rpc_talloc
= ctx
;
43 static TALLOC_CTX
*main_loop_talloc
= NULL
;
45 /*******************************************************************
46 free up temporary memory - called from the main loop
47 ********************************************************************/
49 void main_loop_talloc_free(void)
51 if (!main_loop_talloc
)
53 talloc_destroy(main_loop_talloc
);
54 main_loop_talloc
= NULL
;
57 /*******************************************************************
58 Get a talloc context that is freed in the main loop...
59 ********************************************************************/
61 TALLOC_CTX
*main_loop_talloc_get(void)
63 if (!main_loop_talloc
) {
64 main_loop_talloc
= talloc_init_named("main loop talloc (mainly parse_misc)");
65 if (!main_loop_talloc
)
66 smb_panic("main_loop_talloc: malloc fail\n");
69 return main_loop_talloc
;
72 /*******************************************************************
73 Try and get a talloc context. Get the rpc one if possible, else
74 get the main loop one. The main loop one is more dangerous as it
75 goes away between packets, the rpc one will stay around for as long
76 as a current RPC lasts.
77 ********************************************************************/
79 TALLOC_CTX
*get_talloc_ctx(void)
81 TALLOC_CTX
*tc
= get_current_rpc_talloc();
85 return main_loop_talloc_get();
88 /*******************************************************************
89 Reads or writes a UTIME type.
90 ********************************************************************/
92 static BOOL
smb_io_utime(char *desc
, UTIME
*t
, prs_struct
*ps
, int depth
)
97 prs_debug(ps
, depth
, desc
, "smb_io_utime");
103 if(!prs_uint32 ("time", ps
, depth
, &t
->time
))
109 /*******************************************************************
110 Reads or writes an NTTIME structure.
111 ********************************************************************/
113 BOOL
smb_io_time(char *desc
, NTTIME
*nttime
, prs_struct
*ps
, int depth
)
118 prs_debug(ps
, depth
, desc
, "smb_io_time");
124 if(!prs_uint32("low ", ps
, depth
, &nttime
->low
)) /* low part */
126 if(!prs_uint32("high", ps
, depth
, &nttime
->high
)) /* high part */
132 /*******************************************************************
133 Reads or writes a LOOKUP_LEVEL structure.
134 ********************************************************************/
136 BOOL
smb_io_lookup_level(char *desc
, LOOKUP_LEVEL
*level
, prs_struct
*ps
, int depth
)
141 prs_debug(ps
, depth
, desc
, "smb_io_lookup_level");
146 if(!prs_uint16("value", ps
, depth
, &level
->value
))
154 /*******************************************************************
155 Gets an enumeration handle from an ENUM_HND structure.
156 ********************************************************************/
158 uint32
get_enum_hnd(ENUM_HND
*enh
)
160 return (enh
&& enh
->ptr_hnd
!= 0) ? enh
->handle
: 0;
163 /*******************************************************************
164 Inits an ENUM_HND structure.
165 ********************************************************************/
167 void init_enum_hnd(ENUM_HND
*enh
, uint32 hnd
)
169 DEBUG(5,("smb_io_enum_hnd\n"));
171 enh
->ptr_hnd
= (hnd
!= 0) ? 1 : 0;
175 /*******************************************************************
176 Reads or writes an ENUM_HND structure.
177 ********************************************************************/
179 BOOL
smb_io_enum_hnd(char *desc
, ENUM_HND
*hnd
, prs_struct
*ps
, int depth
)
184 prs_debug(ps
, depth
, desc
, "smb_io_enum_hnd");
190 if(!prs_uint32("ptr_hnd", ps
, depth
, &hnd
->ptr_hnd
)) /* pointer */
193 if (hnd
->ptr_hnd
!= 0) {
194 if(!prs_uint32("handle ", ps
, depth
, &hnd
->handle
)) /* enum handle */
201 /*******************************************************************
202 Reads or writes a DOM_SID structure.
203 ********************************************************************/
205 BOOL
smb_io_dom_sid(char *desc
, DOM_SID
*sid
, prs_struct
*ps
, int depth
)
212 prs_debug(ps
, depth
, desc
, "smb_io_dom_sid");
218 if(!prs_uint8 ("sid_rev_num", ps
, depth
, &sid
->sid_rev_num
))
220 if(!prs_uint8 ("num_auths ", ps
, depth
, &sid
->num_auths
))
223 for (i
= 0; i
< 6; i
++)
226 slprintf(tmp
, sizeof(tmp
) - 1, "id_auth[%d] ", i
);
227 if(!prs_uint8 (tmp
, ps
, depth
, &sid
->id_auth
[i
]))
231 /* oops! XXXX should really issue a warning here... */
232 if (sid
->num_auths
> MAXSUBAUTHS
)
233 sid
->num_auths
= MAXSUBAUTHS
;
235 if(!prs_uint32s(False
, "sub_auths ", ps
, depth
, sid
->sub_auths
, sid
->num_auths
))
241 /*******************************************************************
242 Inits a DOM_SID structure.
244 BIG NOTE: this function only does SIDS where the identauth is not >= 2^32
245 identauth >= 2^32 can be detected because it will be specified in hex
246 ********************************************************************/
248 void init_dom_sid(DOM_SID
*sid
, char *str_sid
)
256 DEBUG(4,("netlogon domain SID: none\n"));
257 sid
->sid_rev_num
= 0;
262 pstrcpy(domsid
, str_sid
);
264 DEBUG(4,("init_dom_sid %d SID: %s\n", __LINE__
, domsid
));
266 /* assume, but should check, that domsid starts "S-" */
267 p
= strtok(domsid
+2,"-");
268 sid
->sid_rev_num
= atoi(p
);
270 /* identauth in decimal should be < 2^32 */
271 /* identauth in hex should be >= 2^32 */
272 identauth
= atoi(strtok(0,"-"));
274 DEBUG(4,("netlogon rev %d\n", sid
->sid_rev_num
));
275 DEBUG(4,("netlogon %s ia %d\n", p
, identauth
));
279 sid
->id_auth
[2] = (identauth
& 0xff000000) >> 24;
280 sid
->id_auth
[3] = (identauth
& 0x00ff0000) >> 16;
281 sid
->id_auth
[4] = (identauth
& 0x0000ff00) >> 8;
282 sid
->id_auth
[5] = (identauth
& 0x000000ff);
286 while ((p
= strtok(0, "-")) != NULL
&& sid
->num_auths
< MAXSUBAUTHS
)
287 sid
->sub_auths
[sid
->num_auths
++] = atoi(p
);
289 DEBUG(4,("init_dom_sid: %d SID: %s\n", __LINE__
, domsid
));
292 /*******************************************************************
293 Inits a DOM_SID2 structure.
294 ********************************************************************/
296 void init_dom_sid2(DOM_SID2
*sid2
, const DOM_SID
*sid
)
299 sid2
->num_auths
= sid2
->sid
.num_auths
;
302 /*******************************************************************
303 Reads or writes a DOM_SID2 structure.
304 ********************************************************************/
306 BOOL
smb_io_dom_sid2(char *desc
, DOM_SID2
*sid
, prs_struct
*ps
, int depth
)
311 prs_debug(ps
, depth
, desc
, "smb_io_dom_sid2");
317 if(!prs_uint32("num_auths", ps
, depth
, &sid
->num_auths
))
320 if(!smb_io_dom_sid("sid", &sid
->sid
, ps
, depth
))
326 /*******************************************************************
327 creates a STRHDR structure.
328 ********************************************************************/
330 void init_str_hdr(STRHDR
*hdr
, int max_len
, int len
, uint32 buffer
)
332 hdr
->str_max_len
= max_len
;
333 hdr
->str_str_len
= len
;
334 hdr
->buffer
= buffer
;
337 /*******************************************************************
338 Reads or writes a STRHDR structure.
339 ********************************************************************/
341 BOOL
smb_io_strhdr(char *desc
, STRHDR
*hdr
, prs_struct
*ps
, int depth
)
346 prs_debug(ps
, depth
, desc
, "smb_io_strhdr");
351 if(!prs_uint16("str_str_len", ps
, depth
, &hdr
->str_str_len
))
353 if(!prs_uint16("str_max_len", ps
, depth
, &hdr
->str_max_len
))
355 if(!prs_uint32("buffer ", ps
, depth
, &hdr
->buffer
))
361 /*******************************************************************
362 Inits a UNIHDR structure.
363 ********************************************************************/
365 void init_uni_hdr(UNIHDR
*hdr
, int len
)
367 hdr
->uni_str_len
= 2 * len
;
368 hdr
->uni_max_len
= 2 * len
;
369 hdr
->buffer
= len
!= 0 ? 1 : 0;
372 /*******************************************************************
373 Reads or writes a UNIHDR structure.
374 ********************************************************************/
376 BOOL
smb_io_unihdr(char *desc
, UNIHDR
*hdr
, prs_struct
*ps
, int depth
)
381 prs_debug(ps
, depth
, desc
, "smb_io_unihdr");
387 if(!prs_uint16("uni_str_len", ps
, depth
, &hdr
->uni_str_len
))
389 if(!prs_uint16("uni_max_len", ps
, depth
, &hdr
->uni_max_len
))
391 if(!prs_uint32("buffer ", ps
, depth
, &hdr
->buffer
))
397 /*******************************************************************
398 Inits a BUFHDR structure.
399 ********************************************************************/
401 void init_buf_hdr(BUFHDR
*hdr
, int max_len
, int len
)
403 hdr
->buf_max_len
= max_len
;
407 /*******************************************************************
408 prs_uint16 wrapper. Call this and it sets up a pointer to where the
409 uint16 should be stored, or gets the size if reading.
410 ********************************************************************/
412 BOOL
smb_io_hdrbuf_pre(char *desc
, BUFHDR
*hdr
, prs_struct
*ps
, int depth
, uint32
*offset
)
414 (*offset
) = prs_offset(ps
);
419 if(!smb_io_hdrbuf(desc
, hdr
, ps
, depth
))
426 if(!prs_set_offset(ps
, prs_offset(ps
) + (sizeof(uint32
) * 2)))
433 /*******************************************************************
434 smb_io_hdrbuf wrapper. Call this and it retrospectively stores the size.
435 Does nothing on reading, as that is already handled by ...._pre()
436 ********************************************************************/
438 BOOL
smb_io_hdrbuf_post(char *desc
, BUFHDR
*hdr
, prs_struct
*ps
, int depth
,
439 uint32 ptr_hdrbuf
, uint32 max_len
, uint32 len
)
442 /* writing: go back and do a retrospective job. i hate this */
444 uint32 old_offset
= prs_offset(ps
);
446 init_buf_hdr(hdr
, max_len
, len
);
447 if(!prs_set_offset(ps
, ptr_hdrbuf
))
449 if(!smb_io_hdrbuf(desc
, hdr
, ps
, depth
))
452 if(!prs_set_offset(ps
, old_offset
))
459 /*******************************************************************
460 Reads or writes a BUFHDR structure.
461 ********************************************************************/
463 BOOL
smb_io_hdrbuf(char *desc
, BUFHDR
*hdr
, prs_struct
*ps
, int depth
)
468 prs_debug(ps
, depth
, desc
, "smb_io_hdrbuf");
474 if(!prs_uint32("buf_max_len", ps
, depth
, &hdr
->buf_max_len
))
476 if(!prs_uint32("buf_len ", ps
, depth
, &hdr
->buf_len
))
482 /*******************************************************************
483 creates a UNIHDR2 structure.
484 ********************************************************************/
486 void init_uni_hdr2(UNIHDR2
*hdr
, int len
)
488 init_uni_hdr(&hdr
->unihdr
, len
);
489 hdr
->buffer
= (len
> 0) ? 1 : 0;
492 /*******************************************************************
493 Reads or writes a UNIHDR2 structure.
494 ********************************************************************/
496 BOOL
smb_io_unihdr2(char *desc
, UNIHDR2
*hdr2
, prs_struct
*ps
, int depth
)
501 prs_debug(ps
, depth
, desc
, "smb_io_unihdr2");
507 if(!smb_io_unihdr("hdr", &hdr2
->unihdr
, ps
, depth
))
509 if(!prs_uint32("buffer", ps
, depth
, &hdr2
->buffer
))
515 /*******************************************************************
516 Inits a UNISTR structure.
517 ********************************************************************/
519 void init_unistr(UNISTR
*str
, const char *buf
)
529 len
= strlen(buf
) + 1;
531 if (len
< MAX_UNISTRLEN
)
533 len
*= sizeof(uint16
);
535 str
->buffer
= (uint16
*)talloc_zero(get_talloc_ctx(), len
);
536 if (str
->buffer
== NULL
)
537 smb_panic("init_unistr: malloc fail\n");
539 rpcstr_push(str
->buffer
, buf
, len
, STR_TERMINATE
);
542 /*******************************************************************
543 reads or writes a UNISTR structure.
544 XXXX NOTE: UNISTR structures NEED to be null-terminated.
545 ********************************************************************/
547 BOOL
smb_io_unistr(char *desc
, UNISTR
*uni
, prs_struct
*ps
, int depth
)
552 prs_debug(ps
, depth
, desc
, "smb_io_unistr");
557 if(!prs_unistr("unistr", ps
, depth
, uni
))
563 /*******************************************************************
564 Allocate the BUFFER3 memory.
565 ********************************************************************/
567 static void create_buffer3(BUFFER3
*str
, size_t len
)
569 if (len
< MAX_BUFFERLEN
)
572 str
->buffer
= talloc_zero(get_talloc_ctx(), len
);
573 if (str
->buffer
== NULL
)
574 smb_panic("create_buffer3: talloc fail\n");
578 /*******************************************************************
579 Inits a BUFFER3 structure from a uint32
580 ********************************************************************/
582 void init_buffer3_uint32(BUFFER3
*str
, uint32 val
)
586 /* set up string lengths. */
587 str
->buf_max_len
= sizeof(uint32
);
588 str
->buf_len
= sizeof(uint32
);
590 create_buffer3(str
, sizeof(uint32
));
591 SIVAL(str
->buffer
, 0, val
);
594 /*******************************************************************
595 Inits a BUFFER3 structure.
596 ********************************************************************/
598 void init_buffer3_str(BUFFER3
*str
, char *buf
, int len
)
602 /* set up string lengths. */
603 str
->buf_max_len
= len
* 2;
604 str
->buf_len
= len
* 2;
606 create_buffer3(str
, str
->buf_max_len
);
608 rpcstr_push(str
->buffer
, buf
, str
->buf_max_len
, STR_TERMINATE
);
612 /*******************************************************************
613 Inits a BUFFER3 structure from a hex string.
614 ********************************************************************/
616 void init_buffer3_hex(BUFFER3
*str
, char *buf
)
619 create_buffer3(str
, strlen(buf
));
620 str
->buf_max_len
= str
->buf_len
= strhex_to_str((char *)str
->buffer
, sizeof(str
->buffer
), buf
);
623 /*******************************************************************
624 Inits a BUFFER3 structure.
625 ********************************************************************/
627 void init_buffer3_bytes(BUFFER3
*str
, uint8
*buf
, int len
)
631 /* max buffer size (allocated size) */
632 str
->buf_max_len
= len
;
634 create_buffer3(str
, len
);
635 memcpy(str
->buffer
, buf
, len
);
637 str
->buf_len
= buf
!= NULL
? len
: 0;
640 /*******************************************************************
641 Reads or writes a BUFFER3 structure.
642 the uni_max_len member tells you how large the buffer is.
643 the uni_str_len member tells you how much of the buffer is really used.
644 ********************************************************************/
646 BOOL
smb_io_buffer3(char *desc
, BUFFER3
*buf3
, prs_struct
*ps
, int depth
)
651 prs_debug(ps
, depth
, desc
, "smb_io_buffer3");
657 if(!prs_uint32("uni_max_len", ps
, depth
, &buf3
->buf_max_len
))
660 if (UNMARSHALLING(ps
)) {
661 buf3
->buffer
= (unsigned char *)prs_alloc_mem(ps
, buf3
->buf_max_len
);
662 if (buf3
->buffer
== NULL
)
666 if(!prs_uint8s(True
, "buffer ", ps
, depth
, buf3
->buffer
, buf3
->buf_max_len
))
669 if(!prs_uint32("buf_len ", ps
, depth
, &buf3
->buf_len
))
675 /*******************************************************************
676 reads or writes a BUFFER5 structure.
677 the buf_len member tells you how large the buffer is.
678 ********************************************************************/
679 BOOL
smb_io_buffer5(char *desc
, BUFFER5
*buf5
, prs_struct
*ps
, int depth
)
681 prs_debug(ps
, depth
, desc
, "smb_io_buffer5");
684 if (buf5
== NULL
) return False
;
688 if(!prs_uint32("buf_len", ps
, depth
, &buf5
->buf_len
))
692 if(!prs_buffer5(True
, "buffer" , ps
, depth
, buf5
))
698 /*******************************************************************
699 Inits a BUFFER2 structure.
700 ********************************************************************/
702 void init_buffer2(BUFFER2
*str
, uint8
*buf
, int len
)
706 /* max buffer size (allocated size) */
707 str
->buf_max_len
= len
;
709 str
->buf_len
= buf
!= NULL
? len
: 0;
712 if (len
< MAX_BUFFERLEN
)
714 str
->buffer
= talloc_zero(get_talloc_ctx(), len
);
715 if (str
->buffer
== NULL
)
716 smb_panic("init_buffer2: talloc fail\n");
717 memcpy(str
->buffer
, buf
, MIN(str
->buf_len
, len
));
721 /*******************************************************************
722 Reads or writes a BUFFER2 structure.
723 the uni_max_len member tells you how large the buffer is.
724 the uni_str_len member tells you how much of the buffer is really used.
725 ********************************************************************/
727 BOOL
smb_io_buffer2(char *desc
, BUFFER2
*buf2
, uint32 buffer
, prs_struct
*ps
, int depth
)
734 prs_debug(ps
, depth
, desc
, "smb_io_buffer2");
740 if(!prs_uint32("uni_max_len", ps
, depth
, &buf2
->buf_max_len
))
742 if(!prs_uint32("undoc ", ps
, depth
, &buf2
->undoc
))
744 if(!prs_uint32("buf_len ", ps
, depth
, &buf2
->buf_len
))
747 /* buffer advanced by indicated length of string
748 NOT by searching for null-termination */
750 if(!prs_buffer2(True
, "buffer ", ps
, depth
, buf2
))
755 prs_debug(ps
, depth
, desc
, "smb_io_buffer2 - NULL");
757 memset((char *)buf2
, '\0', sizeof(*buf2
));
763 /*******************************************************************
764 creates a UNISTR2 structure: sets up the buffer, too
765 ********************************************************************/
767 void init_buf_unistr2(UNISTR2
*str
, uint32
*ptr
, const char *buf
)
772 init_unistr2(str
, buf
, strlen(buf
)+1);
777 init_unistr2(str
, "", 0);
782 /*******************************************************************
783 Copies a UNISTR2 structure.
784 ********************************************************************/
786 void copy_unistr2(UNISTR2
*str
, const UNISTR2
*from
)
789 /* set up string lengths. add one if string is not null-terminated */
790 str
->uni_max_len
= from
->uni_max_len
;
791 str
->undoc
= from
->undoc
;
792 str
->uni_str_len
= from
->uni_str_len
;
794 if (from
->buffer
== NULL
)
797 /* the string buffer is allocated to the maximum size
798 (the the length of the source string) to prevent
799 reallocation of memory. */
800 if (str
->buffer
== NULL
) {
801 size_t len
= from
->uni_max_len
* sizeof(uint16
);
803 if (len
< MAX_UNISTRLEN
)
805 len
*= sizeof(uint16
);
807 str
->buffer
= (uint16
*)talloc_zero(get_talloc_ctx(), len
);
808 if ((str
->buffer
== NULL
) && (len
> 0 ))
810 smb_panic("copy_unistr2: talloc fail\n");
815 /* copy the string */
816 memcpy(str
->buffer
, from
->buffer
, from
->uni_max_len
*sizeof(uint16
));
819 /*******************************************************************
820 Creates a STRING2 structure.
821 ********************************************************************/
823 void init_string2(STRING2
*str
, const char *buf
, int max_len
, int str_len
)
827 /* set up string lengths. */
828 str
->str_max_len
= max_len
;
830 str
->str_str_len
= str_len
;
832 /* store the string */
834 if (str_len
< MAX_STRINGLEN
)
835 alloc_len
= MAX_STRINGLEN
;
836 str
->buffer
= talloc_zero(get_talloc_ctx(), alloc_len
);
837 if (str
->buffer
== NULL
)
838 smb_panic("init_string2: malloc fail\n");
839 memcpy(str
->buffer
, buf
, str_len
);
843 /*******************************************************************
844 Reads or writes a STRING2 structure.
845 XXXX NOTE: STRING2 structures need NOT be null-terminated.
846 the str_str_len member tells you how long the string is;
847 the str_max_len member tells you how large the buffer is.
848 ********************************************************************/
850 BOOL
smb_io_string2(char *desc
, STRING2
*str2
, uint32 buffer
, prs_struct
*ps
, int depth
)
857 prs_debug(ps
, depth
, desc
, "smb_io_string2");
863 if(!prs_uint32("str_max_len", ps
, depth
, &str2
->str_max_len
))
865 if(!prs_uint32("undoc ", ps
, depth
, &str2
->undoc
))
867 if(!prs_uint32("str_str_len", ps
, depth
, &str2
->str_str_len
))
870 /* buffer advanced by indicated length of string
871 NOT by searching for null-termination */
872 if(!prs_string2(True
, "buffer ", ps
, depth
, str2
))
877 prs_debug(ps
, depth
, desc
, "smb_io_string2 - NULL");
879 memset((char *)str2
, '\0', sizeof(*str2
));
886 /*******************************************************************
887 Inits a UNISTR2 structure.
888 ********************************************************************/
890 void init_unistr2(UNISTR2
*str
, const char *buf
, size_t len
)
894 /* set up string lengths. */
895 str
->uni_max_len
= (uint32
)len
;
897 str
->uni_str_len
= (uint32
)len
;
899 if (len
< MAX_UNISTRLEN
)
901 len
*= sizeof(uint16
);
903 str
->buffer
= (uint16
*)talloc_zero(get_talloc_ctx(), len
);
904 if ((str
->buffer
== NULL
) && (len
> 0))
906 smb_panic("init_unistr2: malloc fail\n");
911 * don't move this test above ! The UNISTR2 must be initialized !!!
917 rpcstr_push((char *)str
->buffer
, buf
, len
, STR_TERMINATE
);
920 /*******************************************************************
921 Inits a UNISTR2 structure from a UNISTR
922 ********************************************************************/
923 void init_unistr2_from_unistr (UNISTR2
*to
, UNISTR
*from
)
928 /* the destination UNISTR2 should never be NULL.
929 if it is it is a programming error */
931 /* if the source UNISTR is NULL, then zero out
932 the destination string and return */
934 if ((from
== NULL
) || (from
->buffer
== NULL
))
937 /* get the length; UNISTR must be NULL terminated */
939 while ((from
->buffer
)[i
]!='\0')
941 i
++; /* one more to catch the terminating NULL */
942 /* is this necessary -- jerry? I need to think */
944 /* set up string lengths; uni_max_len is set to i+1
945 because we need to account for the final NULL termination */
950 /* allocate the space and copy the string buffer */
951 to
->buffer
= (uint16
*)talloc_zero(get_talloc_ctx(), sizeof(uint16
)*(to
->uni_str_len
));
952 if (to
->buffer
== NULL
)
953 smb_panic("init_unistr2_from_unistr: malloc fail\n");
954 memcpy(to
->buffer
, from
->buffer
, to
->uni_max_len
*sizeof(uint16
));
960 /*******************************************************************
961 Reads or writes a UNISTR2 structure.
962 XXXX NOTE: UNISTR2 structures need NOT be null-terminated.
963 the uni_str_len member tells you how long the string is;
964 the uni_max_len member tells you how large the buffer is.
965 ********************************************************************/
967 BOOL
smb_io_unistr2(char *desc
, UNISTR2
*uni2
, uint32 buffer
, prs_struct
*ps
, int depth
)
974 prs_debug(ps
, depth
, desc
, "smb_io_unistr2");
980 if(!prs_uint32("uni_max_len", ps
, depth
, &uni2
->uni_max_len
))
982 if(!prs_uint32("undoc ", ps
, depth
, &uni2
->undoc
))
984 if(!prs_uint32("uni_str_len", ps
, depth
, &uni2
->uni_str_len
))
987 /* buffer advanced by indicated length of string
988 NOT by searching for null-termination */
989 if(!prs_unistr2(True
, "buffer ", ps
, depth
, uni2
))
994 prs_debug(ps
, depth
, desc
, "smb_io_unistr2 - NULL");
996 memset((char *)uni2
, '\0', sizeof(*uni2
));
1003 /*******************************************************************
1004 Inits a DOM_RID2 structure.
1005 ********************************************************************/
1007 void init_dom_rid2(DOM_RID2
*rid2
, uint32 rid
, uint8 type
, uint32 idx
)
1011 rid2
->rid_idx
= idx
;
1014 /*******************************************************************
1015 Reads or writes a DOM_RID2 structure.
1016 ********************************************************************/
1018 BOOL
smb_io_dom_rid2(char *desc
, DOM_RID2
*rid2
, prs_struct
*ps
, int depth
)
1023 prs_debug(ps
, depth
, desc
, "smb_io_dom_rid2");
1029 if(!prs_uint8("type ", ps
, depth
, &rid2
->type
))
1033 if(!prs_uint32("rid ", ps
, depth
, &rid2
->rid
))
1035 if(!prs_uint32("rid_idx", ps
, depth
, &rid2
->rid_idx
))
1041 /*******************************************************************
1042 creates a DOM_RID3 structure.
1043 ********************************************************************/
1045 void init_dom_rid3(DOM_RID3
*rid3
, uint32 rid
, uint8 type
)
1049 rid3
->ptr_type
= 0x1; /* non-zero, basically. */
1054 /*******************************************************************
1055 reads or writes a DOM_RID3 structure.
1056 ********************************************************************/
1058 BOOL
smb_io_dom_rid3(char *desc
, DOM_RID3
*rid3
, prs_struct
*ps
, int depth
)
1063 prs_debug(ps
, depth
, desc
, "smb_io_dom_rid3");
1069 if(!prs_uint32("rid ", ps
, depth
, &rid3
->rid
))
1071 if(!prs_uint32("type1 ", ps
, depth
, &rid3
->type1
))
1073 if(!prs_uint32("ptr_type", ps
, depth
, &rid3
->ptr_type
))
1075 if(!prs_uint32("type2 ", ps
, depth
, &rid3
->type2
))
1077 if(!prs_uint32("unk ", ps
, depth
, &rid3
->unk
))
1083 /*******************************************************************
1084 Inits a DOM_RID4 structure.
1085 ********************************************************************/
1087 void init_dom_rid4(DOM_RID4
*rid4
, uint16 unknown
, uint16 attr
, uint32 rid
)
1089 rid4
->unknown
= unknown
;
1094 /*******************************************************************
1095 Inits a DOM_CLNT_SRV structure.
1096 ********************************************************************/
1098 static void init_clnt_srv(DOM_CLNT_SRV
*log
, char *logon_srv
, char *comp_name
)
1100 DEBUG(5,("init_clnt_srv: %d\n", __LINE__
));
1102 if (logon_srv
!= NULL
) {
1103 log
->undoc_buffer
= 1;
1104 init_unistr2(&log
->uni_logon_srv
, logon_srv
, strlen(logon_srv
)+1);
1106 log
->undoc_buffer
= 0;
1109 if (comp_name
!= NULL
) {
1110 log
->undoc_buffer2
= 1;
1111 init_unistr2(&log
->uni_comp_name
, comp_name
, strlen(comp_name
)+1);
1113 log
->undoc_buffer2
= 0;
1117 /*******************************************************************
1118 Inits or writes a DOM_CLNT_SRV structure.
1119 ********************************************************************/
1121 static BOOL
smb_io_clnt_srv(char *desc
, DOM_CLNT_SRV
*log
, prs_struct
*ps
, int depth
)
1126 prs_debug(ps
, depth
, desc
, "smb_io_clnt_srv");
1132 if(!prs_uint32("undoc_buffer ", ps
, depth
, &log
->undoc_buffer
))
1135 if (log
->undoc_buffer
!= 0) {
1136 if(!smb_io_unistr2("unistr2", &log
->uni_logon_srv
, log
->undoc_buffer
, ps
, depth
))
1143 if(!prs_uint32("undoc_buffer2", ps
, depth
, &log
->undoc_buffer2
))
1146 if (log
->undoc_buffer2
!= 0) {
1147 if(!smb_io_unistr2("unistr2", &log
->uni_comp_name
, log
->undoc_buffer2
, ps
, depth
))
1154 /*******************************************************************
1155 Inits a DOM_LOG_INFO structure.
1156 ********************************************************************/
1158 void init_log_info(DOM_LOG_INFO
*log
, char *logon_srv
, char *acct_name
,
1159 uint16 sec_chan
, char *comp_name
)
1161 DEBUG(5,("make_log_info %d\n", __LINE__
));
1163 log
->undoc_buffer
= 1;
1165 init_unistr2(&log
->uni_logon_srv
, logon_srv
, strlen(logon_srv
)+1);
1166 init_unistr2(&log
->uni_acct_name
, acct_name
, strlen(acct_name
)+1);
1168 log
->sec_chan
= sec_chan
;
1170 init_unistr2(&log
->uni_comp_name
, comp_name
, strlen(comp_name
)+1);
1173 /*******************************************************************
1174 Reads or writes a DOM_LOG_INFO structure.
1175 ********************************************************************/
1177 BOOL
smb_io_log_info(char *desc
, DOM_LOG_INFO
*log
, prs_struct
*ps
, int depth
)
1182 prs_debug(ps
, depth
, desc
, "smb_io_log_info");
1188 if(!prs_uint32("undoc_buffer", ps
, depth
, &log
->undoc_buffer
))
1191 if(!smb_io_unistr2("unistr2", &log
->uni_logon_srv
, True
, ps
, depth
))
1193 if(!smb_io_unistr2("unistr2", &log
->uni_acct_name
, True
, ps
, depth
))
1196 if(!prs_uint16("sec_chan", ps
, depth
, &log
->sec_chan
))
1199 if(!smb_io_unistr2("unistr2", &log
->uni_comp_name
, True
, ps
, depth
))
1205 /*******************************************************************
1206 Reads or writes a DOM_CHAL structure.
1207 ********************************************************************/
1209 BOOL
smb_io_chal(char *desc
, DOM_CHAL
*chal
, prs_struct
*ps
, int depth
)
1214 prs_debug(ps
, depth
, desc
, "smb_io_chal");
1220 if(!prs_uint8s (False
, "data", ps
, depth
, chal
->data
, 8))
1226 /*******************************************************************
1227 Reads or writes a DOM_CRED structure.
1228 ********************************************************************/
1230 BOOL
smb_io_cred(char *desc
, DOM_CRED
*cred
, prs_struct
*ps
, int depth
)
1235 prs_debug(ps
, depth
, desc
, "smb_io_cred");
1241 if(!smb_io_chal ("", &cred
->challenge
, ps
, depth
))
1244 if(!smb_io_utime("", &cred
->timestamp
, ps
, depth
))
1250 /*******************************************************************
1251 Inits a DOM_CLNT_INFO2 structure.
1252 ********************************************************************/
1254 void init_clnt_info2(DOM_CLNT_INFO2
*clnt
,
1255 char *logon_srv
, char *comp_name
,
1256 DOM_CRED
*clnt_cred
)
1258 DEBUG(5,("make_clnt_info: %d\n", __LINE__
));
1260 init_clnt_srv(&(clnt
->login
), logon_srv
, comp_name
);
1262 if (clnt_cred
!= NULL
) {
1264 memcpy(&(clnt
->cred
), clnt_cred
, sizeof(clnt
->cred
));
1270 /*******************************************************************
1271 Reads or writes a DOM_CLNT_INFO2 structure.
1272 ********************************************************************/
1274 BOOL
smb_io_clnt_info2(char *desc
, DOM_CLNT_INFO2
*clnt
, prs_struct
*ps
, int depth
)
1279 prs_debug(ps
, depth
, desc
, "smb_io_clnt_info2");
1285 if(!smb_io_clnt_srv("", &clnt
->login
, ps
, depth
))
1291 if(!prs_uint32("ptr_cred", ps
, depth
, &clnt
->ptr_cred
))
1293 if(!smb_io_cred("", &clnt
->cred
, ps
, depth
))
1299 /*******************************************************************
1300 Inits a DOM_CLNT_INFO structure.
1301 ********************************************************************/
1303 void init_clnt_info(DOM_CLNT_INFO
*clnt
,
1304 char *logon_srv
, char *acct_name
,
1305 uint16 sec_chan
, char *comp_name
,
1308 DEBUG(5,("make_clnt_info\n"));
1310 init_log_info(&clnt
->login
, logon_srv
, acct_name
, sec_chan
, comp_name
);
1311 memcpy(&clnt
->cred
, cred
, sizeof(clnt
->cred
));
1314 /*******************************************************************
1315 Reads or writes a DOM_CLNT_INFO structure.
1316 ********************************************************************/
1318 BOOL
smb_io_clnt_info(char *desc
, DOM_CLNT_INFO
*clnt
, prs_struct
*ps
, int depth
)
1323 prs_debug(ps
, depth
, desc
, "smb_io_clnt_info");
1329 if(!smb_io_log_info("", &clnt
->login
, ps
, depth
))
1331 if(!smb_io_cred("", &clnt
->cred
, ps
, depth
))
1337 /*******************************************************************
1338 Inits a DOM_LOGON_ID structure.
1339 ********************************************************************/
1341 void init_logon_id(DOM_LOGON_ID
*log
, uint32 log_id_low
, uint32 log_id_high
)
1343 DEBUG(5,("make_logon_id: %d\n", __LINE__
));
1345 log
->low
= log_id_low
;
1346 log
->high
= log_id_high
;
1349 /*******************************************************************
1350 Reads or writes a DOM_LOGON_ID structure.
1351 ********************************************************************/
1353 BOOL
smb_io_logon_id(char *desc
, DOM_LOGON_ID
*log
, prs_struct
*ps
, int depth
)
1358 prs_debug(ps
, depth
, desc
, "smb_io_logon_id");
1364 if(!prs_uint32("low ", ps
, depth
, &log
->low
))
1366 if(!prs_uint32("high", ps
, depth
, &log
->high
))
1372 /*******************************************************************
1373 Inits an OWF_INFO structure.
1374 ********************************************************************/
1376 void init_owf_info(OWF_INFO
*hash
, uint8 data
[16])
1378 DEBUG(5,("init_owf_info: %d\n", __LINE__
));
1381 memcpy(hash
->data
, data
, sizeof(hash
->data
));
1383 memset((char *)hash
->data
, '\0', sizeof(hash
->data
));
1386 /*******************************************************************
1387 Reads or writes an OWF_INFO structure.
1388 ********************************************************************/
1390 BOOL
smb_io_owf_info(char *desc
, OWF_INFO
*hash
, prs_struct
*ps
, int depth
)
1395 prs_debug(ps
, depth
, desc
, "smb_io_owf_info");
1401 if(!prs_uint8s (False
, "data", ps
, depth
, hash
->data
, 16))
1407 /*******************************************************************
1408 Reads or writes a DOM_GID structure.
1409 ********************************************************************/
1411 BOOL
smb_io_gid(char *desc
, DOM_GID
*gid
, prs_struct
*ps
, int depth
)
1416 prs_debug(ps
, depth
, desc
, "smb_io_gid");
1422 if(!prs_uint32("g_rid", ps
, depth
, &gid
->g_rid
))
1424 if(!prs_uint32("attr ", ps
, depth
, &gid
->attr
))
1430 /*******************************************************************
1431 Reads or writes an POLICY_HND structure.
1432 ********************************************************************/
1434 BOOL
smb_io_pol_hnd(char *desc
, POLICY_HND
*pol
, prs_struct
*ps
, int depth
)
1439 prs_debug(ps
, depth
, desc
, "smb_io_pol_hnd");
1445 if(UNMARSHALLING(ps
))
1448 if (!prs_uint32("data1", ps
, depth
, &pol
->data1
))
1450 if (!prs_uint32("data2", ps
, depth
, &pol
->data2
))
1452 if (!prs_uint16("data3", ps
, depth
, &pol
->data3
))
1454 if (!prs_uint16("data4", ps
, depth
, &pol
->data4
))
1456 if(!prs_uint8s (False
, "data5", ps
, depth
, pol
->data5
, sizeof(pol
->data5
)))
1462 /*******************************************************************
1464 ********************************************************************/
1466 void init_unistr3(UNISTR3
*str
, const char *buf
)
1472 str
->str
.buffer
= NULL
;
1476 len
= strlen(buf
) + 1;
1478 str
->uni_str_len
=len
;
1480 if (len
< MAX_UNISTRLEN
)
1481 len
= MAX_UNISTRLEN
;
1483 len
*= sizeof(uint16
);
1485 str
->str
.buffer
= (uint16
*)talloc_zero(get_talloc_ctx(), len
);
1486 if (str
->str
.buffer
== NULL
)
1487 smb_panic("init_unistr3: malloc fail\n");
1489 rpcstr_push((char *)str
->str
.buffer
, buf
, len
, STR_TERMINATE
);
1492 /*******************************************************************
1493 Reads or writes a UNISTR3 structure.
1494 ********************************************************************/
1496 BOOL
smb_io_unistr3(char *desc
, UNISTR3
*name
, prs_struct
*ps
, int depth
)
1501 prs_debug(ps
, depth
, desc
, "smb_io_unistr3");
1507 if(!prs_uint32("uni_str_len", ps
, depth
, &name
->uni_str_len
))
1510 /* don't know if len is specified by uni_str_len member... */
1511 /* assume unicode string is unicode-null-terminated, instead */
1513 if(!prs_unistr3(True
, "unistr", name
, ps
, depth
))
1520 /*******************************************************************
1521 Stream a uint64_struct
1522 ********************************************************************/
1523 BOOL
prs_uint64(char *name
, prs_struct
*ps
, int depth
, UINT64_S
*data64
)
1525 return prs_uint32(name
, ps
, depth
+1, &data64
->low
) &&
1526 prs_uint32(name
, ps
, depth
+1, &data64
->high
);
1529 /*******************************************************************
1530 reads or writes a BUFHDR2 structure.
1531 ********************************************************************/
1532 BOOL
smb_io_bufhdr2(char *desc
, BUFHDR2
*hdr
, prs_struct
*ps
, int depth
)
1534 prs_debug(ps
, depth
, desc
, "smb_io_bufhdr2");
1538 prs_uint32("info_level", ps
, depth
, &(hdr
->info_level
));
1539 prs_uint32("length ", ps
, depth
, &(hdr
->length
));
1540 prs_uint32("buffer ", ps
, depth
, &(hdr
->buffer
));
1545 /*******************************************************************
1546 reads or writes a BUFFER4 structure.
1547 ********************************************************************/
1548 BOOL
smb_io_buffer4(char *desc
, BUFFER4
*buf4
, uint32 buffer
, prs_struct
*ps
, int depth
)
1550 prs_debug(ps
, depth
, desc
, "smb_io_buffer4");
1554 prs_uint32("buf_len", ps
, depth
, &(buf4
->buf_len
));
1556 if (buf4
->buf_len
> MAX_BUFFERLEN
)
1558 buf4
->buf_len
= MAX_BUFFERLEN
;
1561 prs_uint8s(True
, "buffer", ps
, depth
, buf4
->buffer
, buf4
->buf_len
);
1566 /*******************************************************************
1567 creates a UNIHDR structure.
1568 ********************************************************************/
1570 BOOL
make_uni_hdr(UNIHDR
*hdr
, int len
)
1576 hdr
->uni_str_len
= 2 * len
;
1577 hdr
->uni_max_len
= 2 * len
;
1578 hdr
->buffer
= len
!= 0 ? 1 : 0;
1583 /*******************************************************************
1584 creates a BUFHDR2 structure.
1585 ********************************************************************/
1586 BOOL
make_bufhdr2(BUFHDR2
*hdr
, uint32 info_level
, uint32 length
, uint32 buffer
)
1588 hdr
->info_level
= info_level
;
1589 hdr
->length
= length
;
1590 hdr
->buffer
= buffer
;