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 /****************************************************************************
28 A temporary TALLOC context for things like unistrs, that is valid for
29 the life of a complete RPC call.
30 ****************************************************************************/
32 static TALLOC_CTX
*current_rpc_talloc
= NULL
;
34 TALLOC_CTX
*get_current_rpc_talloc(void)
36 return current_rpc_talloc
;
39 void set_current_rpc_talloc( TALLOC_CTX
*ctx
)
41 current_rpc_talloc
= ctx
;
44 static TALLOC_CTX
*main_loop_talloc
= NULL
;
46 /*******************************************************************
47 free up temporary memory - called from the main loop
48 ********************************************************************/
50 void main_loop_talloc_free(void)
52 if (!main_loop_talloc
)
54 talloc_destroy(main_loop_talloc
);
55 main_loop_talloc
= NULL
;
58 /*******************************************************************
59 Get a talloc context that is freed in the main loop...
60 ********************************************************************/
62 TALLOC_CTX
*main_loop_talloc_get(void)
64 if (!main_loop_talloc
) {
65 main_loop_talloc
= talloc_init();
66 if (!main_loop_talloc
)
67 smb_panic("main_loop_talloc: malloc fail\n");
70 return main_loop_talloc
;
73 /*******************************************************************
74 Try and get a talloc context. Get the rpc one if possible, else
75 get the main loop one. The main loop one is more dangerous as it
76 goes away between packets, the rpc one will stay around for as long
77 as a current RPC lasts.
78 ********************************************************************/
80 TALLOC_CTX
*get_talloc_ctx(void)
82 TALLOC_CTX
*tc
= get_current_rpc_talloc();
86 return main_loop_talloc_get();
89 /*******************************************************************
90 Reads or writes a UTIME type.
91 ********************************************************************/
93 static BOOL
smb_io_utime(char *desc
, UTIME
*t
, prs_struct
*ps
, int depth
)
98 prs_debug(ps
, depth
, desc
, "smb_io_utime");
104 if(!prs_uint32 ("time", ps
, depth
, &t
->time
))
110 /*******************************************************************
111 Reads or writes an NTTIME structure.
112 ********************************************************************/
114 BOOL
smb_io_time(char *desc
, NTTIME
*nttime
, prs_struct
*ps
, int depth
)
119 prs_debug(ps
, depth
, desc
, "smb_io_time");
125 if(!prs_uint32("low ", ps
, depth
, &nttime
->low
)) /* low part */
127 if(!prs_uint32("high", ps
, depth
, &nttime
->high
)) /* high part */
133 /*******************************************************************
134 Reads or writes a LOOKUP_LEVEL structure.
135 ********************************************************************/
137 BOOL
smb_io_lookup_level(char *desc
, LOOKUP_LEVEL
*level
, prs_struct
*ps
, int depth
)
142 prs_debug(ps
, depth
, desc
, "smb_io_lookup_level");
147 if(!prs_uint16("value", ps
, depth
, &level
->value
))
155 /*******************************************************************
156 Gets an enumeration handle from an ENUM_HND structure.
157 ********************************************************************/
159 uint32
get_enum_hnd(ENUM_HND
*enh
)
161 return (enh
&& enh
->ptr_hnd
!= 0) ? enh
->handle
: 0;
164 /*******************************************************************
165 Inits an ENUM_HND structure.
166 ********************************************************************/
168 void init_enum_hnd(ENUM_HND
*enh
, uint32 hnd
)
170 DEBUG(5,("smb_io_enum_hnd\n"));
172 enh
->ptr_hnd
= (hnd
!= 0) ? 1 : 0;
176 /*******************************************************************
177 Reads or writes an ENUM_HND structure.
178 ********************************************************************/
180 BOOL
smb_io_enum_hnd(char *desc
, ENUM_HND
*hnd
, prs_struct
*ps
, int depth
)
185 prs_debug(ps
, depth
, desc
, "smb_io_enum_hnd");
191 if(!prs_uint32("ptr_hnd", ps
, depth
, &hnd
->ptr_hnd
)) /* pointer */
194 if (hnd
->ptr_hnd
!= 0) {
195 if(!prs_uint32("handle ", ps
, depth
, &hnd
->handle
)) /* enum handle */
202 /*******************************************************************
203 Reads or writes a DOM_SID structure.
204 ********************************************************************/
206 BOOL
smb_io_dom_sid(char *desc
, DOM_SID
*sid
, prs_struct
*ps
, int depth
)
213 prs_debug(ps
, depth
, desc
, "smb_io_dom_sid");
219 if(!prs_uint8 ("sid_rev_num", ps
, depth
, &sid
->sid_rev_num
))
221 if(!prs_uint8 ("num_auths ", ps
, depth
, &sid
->num_auths
))
224 for (i
= 0; i
< 6; i
++)
227 slprintf(tmp
, sizeof(tmp
) - 1, "id_auth[%d] ", i
);
228 if(!prs_uint8 (tmp
, ps
, depth
, &sid
->id_auth
[i
]))
232 /* oops! XXXX should really issue a warning here... */
233 if (sid
->num_auths
> MAXSUBAUTHS
)
234 sid
->num_auths
= MAXSUBAUTHS
;
236 if(!prs_uint32s(False
, "sub_auths ", ps
, depth
, sid
->sub_auths
, sid
->num_auths
))
242 /*******************************************************************
243 Inits a DOM_SID structure.
245 BIG NOTE: this function only does SIDS where the identauth is not >= 2^32
246 identauth >= 2^32 can be detected because it will be specified in hex
247 ********************************************************************/
249 void init_dom_sid(DOM_SID
*sid
, char *str_sid
)
257 DEBUG(4,("netlogon domain SID: none\n"));
258 sid
->sid_rev_num
= 0;
263 pstrcpy(domsid
, str_sid
);
265 DEBUG(4,("init_dom_sid %d SID: %s\n", __LINE__
, domsid
));
267 /* assume, but should check, that domsid starts "S-" */
268 p
= strtok(domsid
+2,"-");
269 sid
->sid_rev_num
= atoi(p
);
271 /* identauth in decimal should be < 2^32 */
272 /* identauth in hex should be >= 2^32 */
273 identauth
= atoi(strtok(0,"-"));
275 DEBUG(4,("netlogon rev %d\n", sid
->sid_rev_num
));
276 DEBUG(4,("netlogon %s ia %d\n", p
, identauth
));
280 sid
->id_auth
[2] = (identauth
& 0xff000000) >> 24;
281 sid
->id_auth
[3] = (identauth
& 0x00ff0000) >> 16;
282 sid
->id_auth
[4] = (identauth
& 0x0000ff00) >> 8;
283 sid
->id_auth
[5] = (identauth
& 0x000000ff);
287 while ((p
= strtok(0, "-")) != NULL
&& sid
->num_auths
< MAXSUBAUTHS
)
288 sid
->sub_auths
[sid
->num_auths
++] = atoi(p
);
290 DEBUG(4,("init_dom_sid: %d SID: %s\n", __LINE__
, domsid
));
293 /*******************************************************************
294 Inits a DOM_SID2 structure.
295 ********************************************************************/
297 void init_dom_sid2(DOM_SID2
*sid2
, const DOM_SID
*sid
)
300 sid2
->num_auths
= sid2
->sid
.num_auths
;
303 /*******************************************************************
304 Reads or writes a DOM_SID2 structure.
305 ********************************************************************/
307 BOOL
smb_io_dom_sid2(char *desc
, DOM_SID2
*sid
, prs_struct
*ps
, int depth
)
312 prs_debug(ps
, depth
, desc
, "smb_io_dom_sid2");
318 if(!prs_uint32("num_auths", ps
, depth
, &sid
->num_auths
))
321 if(!smb_io_dom_sid("sid", &sid
->sid
, ps
, depth
))
327 /*******************************************************************
328 creates a STRHDR structure.
329 ********************************************************************/
331 void init_str_hdr(STRHDR
*hdr
, int max_len
, int len
, uint32 buffer
)
333 hdr
->str_max_len
= max_len
;
334 hdr
->str_str_len
= len
;
335 hdr
->buffer
= buffer
;
338 /*******************************************************************
339 Reads or writes a STRHDR structure.
340 ********************************************************************/
342 BOOL
smb_io_strhdr(char *desc
, STRHDR
*hdr
, prs_struct
*ps
, int depth
)
347 prs_debug(ps
, depth
, desc
, "smb_io_strhdr");
352 if(!prs_uint16("str_str_len", ps
, depth
, &hdr
->str_str_len
))
354 if(!prs_uint16("str_max_len", ps
, depth
, &hdr
->str_max_len
))
356 if(!prs_uint32("buffer ", ps
, depth
, &hdr
->buffer
))
362 /*******************************************************************
363 Inits a UNIHDR structure.
364 ********************************************************************/
366 void init_uni_hdr(UNIHDR
*hdr
, int len
)
368 hdr
->uni_str_len
= 2 * len
;
369 hdr
->uni_max_len
= 2 * len
;
370 hdr
->buffer
= len
!= 0 ? 1 : 0;
373 /*******************************************************************
374 Reads or writes a UNIHDR structure.
375 ********************************************************************/
377 BOOL
smb_io_unihdr(char *desc
, UNIHDR
*hdr
, prs_struct
*ps
, int depth
)
382 prs_debug(ps
, depth
, desc
, "smb_io_unihdr");
388 if(!prs_uint16("uni_str_len", ps
, depth
, &hdr
->uni_str_len
))
390 if(!prs_uint16("uni_max_len", ps
, depth
, &hdr
->uni_max_len
))
392 if(!prs_uint32("buffer ", ps
, depth
, &hdr
->buffer
))
398 /*******************************************************************
399 Inits a BUFHDR structure.
400 ********************************************************************/
402 void init_buf_hdr(BUFHDR
*hdr
, int max_len
, int len
)
404 hdr
->buf_max_len
= max_len
;
408 /*******************************************************************
409 prs_uint16 wrapper. Call this and it sets up a pointer to where the
410 uint16 should be stored, or gets the size if reading.
411 ********************************************************************/
413 BOOL
smb_io_hdrbuf_pre(char *desc
, BUFHDR
*hdr
, prs_struct
*ps
, int depth
, uint32
*offset
)
415 (*offset
) = prs_offset(ps
);
420 if(!smb_io_hdrbuf(desc
, hdr
, ps
, depth
))
427 if(!prs_set_offset(ps
, prs_offset(ps
) + (sizeof(uint32
) * 2)))
434 /*******************************************************************
435 smb_io_hdrbuf wrapper. Call this and it retrospectively stores the size.
436 Does nothing on reading, as that is already handled by ...._pre()
437 ********************************************************************/
439 BOOL
smb_io_hdrbuf_post(char *desc
, BUFHDR
*hdr
, prs_struct
*ps
, int depth
,
440 uint32 ptr_hdrbuf
, uint32 max_len
, uint32 len
)
443 /* writing: go back and do a retrospective job. i hate this */
445 uint32 old_offset
= prs_offset(ps
);
447 init_buf_hdr(hdr
, max_len
, len
);
448 if(!prs_set_offset(ps
, ptr_hdrbuf
))
450 if(!smb_io_hdrbuf(desc
, hdr
, ps
, depth
))
453 if(!prs_set_offset(ps
, old_offset
))
460 /*******************************************************************
461 Reads or writes a BUFHDR structure.
462 ********************************************************************/
464 BOOL
smb_io_hdrbuf(char *desc
, BUFHDR
*hdr
, prs_struct
*ps
, int depth
)
469 prs_debug(ps
, depth
, desc
, "smb_io_hdrbuf");
475 if(!prs_uint32("buf_max_len", ps
, depth
, &hdr
->buf_max_len
))
477 if(!prs_uint32("buf_len ", ps
, depth
, &hdr
->buf_len
))
483 /*******************************************************************
484 creates a UNIHDR2 structure.
485 ********************************************************************/
487 void init_uni_hdr2(UNIHDR2
*hdr
, int len
)
489 init_uni_hdr(&hdr
->unihdr
, len
);
490 hdr
->buffer
= (len
> 0) ? 1 : 0;
493 /*******************************************************************
494 Reads or writes a UNIHDR2 structure.
495 ********************************************************************/
497 BOOL
smb_io_unihdr2(char *desc
, UNIHDR2
*hdr2
, prs_struct
*ps
, int depth
)
502 prs_debug(ps
, depth
, desc
, "smb_io_unihdr2");
508 if(!smb_io_unihdr("hdr", &hdr2
->unihdr
, ps
, depth
))
510 if(!prs_uint32("buffer", ps
, depth
, &hdr2
->buffer
))
516 /*******************************************************************
517 Inits a UNISTR structure.
518 ********************************************************************/
520 void init_unistr(UNISTR
*str
, const char *buf
)
530 len
= strlen(buf
) + 1;
532 if (len
< MAX_UNISTRLEN
)
534 len
*= sizeof(uint16
);
536 str
->buffer
= (uint16
*)talloc_zero(get_talloc_ctx(), len
);
537 if (str
->buffer
== NULL
)
538 smb_panic("init_unistr: malloc fail\n");
540 /* store the string (null-terminated copy) */
541 dos_struni2((char *)str
->buffer
, buf
, len
);
544 /*******************************************************************
545 reads or writes a UNISTR structure.
546 XXXX NOTE: UNISTR structures NEED to be null-terminated.
547 ********************************************************************/
549 BOOL
smb_io_unistr(char *desc
, UNISTR
*uni
, prs_struct
*ps
, int depth
)
554 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 /* store the string (null-terminated 8 bit chars into 16 bit chars) */
609 dos_struni2((char *)str
->buffer
, buf
, str
->buf_max_len
);
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 /* store the string (null-terminated 8 bit chars into 16 bit chars) */
918 dos_struni2((char *)str
->buffer
, buf
, len
);
921 /*******************************************************************
922 Inits a UNISTR2 structure from a UNISTR
923 ********************************************************************/
924 void init_unistr2_from_unistr (UNISTR2
*to
, UNISTR
*from
)
929 /* the destination UNISTR2 should never be NULL.
930 if it is it is a programming error */
932 /* if the source UNISTR is NULL, then zero out
933 the destination string and return */
935 if ((from
== NULL
) || (from
->buffer
== NULL
))
938 /* get the length; UNISTR must be NULL terminated */
940 while ((from
->buffer
)[i
]!='\0')
942 i
++; /* one more to catch the terminating NULL */
943 /* is this necessary -- jerry? I need to think */
945 /* set up string lengths; uni_max_len is set to i+1
946 because we need to account for the final NULL termination */
951 /* allocate the space and copy the string buffer */
952 to
->buffer
= (uint16
*)talloc_zero(get_talloc_ctx(), sizeof(uint16
)*(to
->uni_str_len
));
953 if (to
->buffer
== NULL
)
954 smb_panic("init_unistr2_from_unistr: malloc fail\n");
955 memcpy(to
->buffer
, from
->buffer
, to
->uni_max_len
*sizeof(uint16
));
961 /*******************************************************************
962 Reads or writes a UNISTR2 structure.
963 XXXX NOTE: UNISTR2 structures need NOT be null-terminated.
964 the uni_str_len member tells you how long the string is;
965 the uni_max_len member tells you how large the buffer is.
966 ********************************************************************/
968 BOOL
smb_io_unistr2(char *desc
, UNISTR2
*uni2
, uint32 buffer
, prs_struct
*ps
, int depth
)
975 prs_debug(ps
, depth
, desc
, "smb_io_unistr2");
981 if(!prs_uint32("uni_max_len", ps
, depth
, &uni2
->uni_max_len
))
983 if(!prs_uint32("undoc ", ps
, depth
, &uni2
->undoc
))
985 if(!prs_uint32("uni_str_len", ps
, depth
, &uni2
->uni_str_len
))
988 /* buffer advanced by indicated length of string
989 NOT by searching for null-termination */
990 if(!prs_unistr2(True
, "buffer ", ps
, depth
, uni2
))
995 prs_debug(ps
, depth
, desc
, "smb_io_unistr2 - NULL");
997 memset((char *)uni2
, '\0', sizeof(*uni2
));
1004 /*******************************************************************
1005 Inits a DOM_RID2 structure.
1006 ********************************************************************/
1008 void init_dom_rid2(DOM_RID2
*rid2
, uint32 rid
, uint8 type
, uint32 idx
)
1012 rid2
->rid_idx
= idx
;
1015 /*******************************************************************
1016 Reads or writes a DOM_RID2 structure.
1017 ********************************************************************/
1019 BOOL
smb_io_dom_rid2(char *desc
, DOM_RID2
*rid2
, prs_struct
*ps
, int depth
)
1024 prs_debug(ps
, depth
, desc
, "smb_io_dom_rid2");
1030 if(!prs_uint8("type ", ps
, depth
, &rid2
->type
))
1034 if(!prs_uint32("rid ", ps
, depth
, &rid2
->rid
))
1036 if(!prs_uint32("rid_idx", ps
, depth
, &rid2
->rid_idx
))
1042 /*******************************************************************
1043 creates a DOM_RID3 structure.
1044 ********************************************************************/
1046 void init_dom_rid3(DOM_RID3
*rid3
, uint32 rid
, uint8 type
)
1050 rid3
->ptr_type
= 0x1; /* non-zero, basically. */
1055 /*******************************************************************
1056 reads or writes a DOM_RID3 structure.
1057 ********************************************************************/
1059 BOOL
smb_io_dom_rid3(char *desc
, DOM_RID3
*rid3
, prs_struct
*ps
, int depth
)
1064 prs_debug(ps
, depth
, desc
, "smb_io_dom_rid3");
1070 if(!prs_uint32("rid ", ps
, depth
, &rid3
->rid
))
1072 if(!prs_uint32("type1 ", ps
, depth
, &rid3
->type1
))
1074 if(!prs_uint32("ptr_type", ps
, depth
, &rid3
->ptr_type
))
1076 if(!prs_uint32("type2 ", ps
, depth
, &rid3
->type2
))
1078 if(!prs_uint32("unk ", ps
, depth
, &rid3
->unk
))
1084 /*******************************************************************
1085 Inits a DOM_RID4 structure.
1086 ********************************************************************/
1088 void init_dom_rid4(DOM_RID4
*rid4
, uint16 unknown
, uint16 attr
, uint32 rid
)
1090 rid4
->unknown
= unknown
;
1095 /*******************************************************************
1096 Inits a DOM_CLNT_SRV structure.
1097 ********************************************************************/
1099 static void init_clnt_srv(DOM_CLNT_SRV
*log
, char *logon_srv
, char *comp_name
)
1101 DEBUG(5,("init_clnt_srv: %d\n", __LINE__
));
1103 if (logon_srv
!= NULL
) {
1104 log
->undoc_buffer
= 1;
1105 init_unistr2(&log
->uni_logon_srv
, logon_srv
, strlen(logon_srv
)+1);
1107 log
->undoc_buffer
= 0;
1110 if (comp_name
!= NULL
) {
1111 log
->undoc_buffer2
= 1;
1112 init_unistr2(&log
->uni_comp_name
, comp_name
, strlen(comp_name
)+1);
1114 log
->undoc_buffer2
= 0;
1118 /*******************************************************************
1119 Inits or writes a DOM_CLNT_SRV structure.
1120 ********************************************************************/
1122 static BOOL
smb_io_clnt_srv(char *desc
, DOM_CLNT_SRV
*log
, prs_struct
*ps
, int depth
)
1127 prs_debug(ps
, depth
, desc
, "smb_io_clnt_srv");
1133 if(!prs_uint32("undoc_buffer ", ps
, depth
, &log
->undoc_buffer
))
1136 if (log
->undoc_buffer
!= 0) {
1137 if(!smb_io_unistr2("unistr2", &log
->uni_logon_srv
, log
->undoc_buffer
, ps
, depth
))
1144 if(!prs_uint32("undoc_buffer2", ps
, depth
, &log
->undoc_buffer2
))
1147 if (log
->undoc_buffer2
!= 0) {
1148 if(!smb_io_unistr2("unistr2", &log
->uni_comp_name
, log
->undoc_buffer2
, ps
, depth
))
1155 /*******************************************************************
1156 Inits a DOM_LOG_INFO structure.
1157 ********************************************************************/
1159 void init_log_info(DOM_LOG_INFO
*log
, char *logon_srv
, char *acct_name
,
1160 uint16 sec_chan
, char *comp_name
)
1162 DEBUG(5,("make_log_info %d\n", __LINE__
));
1164 log
->undoc_buffer
= 1;
1166 init_unistr2(&log
->uni_logon_srv
, logon_srv
, strlen(logon_srv
)+1);
1167 init_unistr2(&log
->uni_acct_name
, acct_name
, strlen(acct_name
)+1);
1169 log
->sec_chan
= sec_chan
;
1171 init_unistr2(&log
->uni_comp_name
, comp_name
, strlen(comp_name
)+1);
1174 /*******************************************************************
1175 Reads or writes a DOM_LOG_INFO structure.
1176 ********************************************************************/
1178 BOOL
smb_io_log_info(char *desc
, DOM_LOG_INFO
*log
, prs_struct
*ps
, int depth
)
1183 prs_debug(ps
, depth
, desc
, "smb_io_log_info");
1189 if(!prs_uint32("undoc_buffer", ps
, depth
, &log
->undoc_buffer
))
1192 if(!smb_io_unistr2("unistr2", &log
->uni_logon_srv
, True
, ps
, depth
))
1194 if(!smb_io_unistr2("unistr2", &log
->uni_acct_name
, True
, ps
, depth
))
1197 if(!prs_uint16("sec_chan", ps
, depth
, &log
->sec_chan
))
1200 if(!smb_io_unistr2("unistr2", &log
->uni_comp_name
, True
, ps
, depth
))
1206 /*******************************************************************
1207 Reads or writes a DOM_CHAL structure.
1208 ********************************************************************/
1210 BOOL
smb_io_chal(char *desc
, DOM_CHAL
*chal
, prs_struct
*ps
, int depth
)
1215 prs_debug(ps
, depth
, desc
, "smb_io_chal");
1221 if(!prs_uint8s (False
, "data", ps
, depth
, chal
->data
, 8))
1227 /*******************************************************************
1228 Reads or writes a DOM_CRED structure.
1229 ********************************************************************/
1231 BOOL
smb_io_cred(char *desc
, DOM_CRED
*cred
, prs_struct
*ps
, int depth
)
1236 prs_debug(ps
, depth
, desc
, "smb_io_cred");
1242 if(!smb_io_chal ("", &cred
->challenge
, ps
, depth
))
1245 if(!smb_io_utime("", &cred
->timestamp
, ps
, depth
))
1251 /*******************************************************************
1252 Inits a DOM_CLNT_INFO2 structure.
1253 ********************************************************************/
1255 void init_clnt_info2(DOM_CLNT_INFO2
*clnt
,
1256 char *logon_srv
, char *comp_name
,
1257 DOM_CRED
*clnt_cred
)
1259 DEBUG(5,("make_clnt_info: %d\n", __LINE__
));
1261 init_clnt_srv(&(clnt
->login
), logon_srv
, comp_name
);
1263 if (clnt_cred
!= NULL
) {
1265 memcpy(&(clnt
->cred
), clnt_cred
, sizeof(clnt
->cred
));
1271 /*******************************************************************
1272 Reads or writes a DOM_CLNT_INFO2 structure.
1273 ********************************************************************/
1275 BOOL
smb_io_clnt_info2(char *desc
, DOM_CLNT_INFO2
*clnt
, prs_struct
*ps
, int depth
)
1280 prs_debug(ps
, depth
, desc
, "smb_io_clnt_info2");
1286 if(!smb_io_clnt_srv("", &clnt
->login
, ps
, depth
))
1292 if(!prs_uint32("ptr_cred", ps
, depth
, &clnt
->ptr_cred
))
1294 if(!smb_io_cred("", &clnt
->cred
, ps
, depth
))
1300 /*******************************************************************
1301 Inits a DOM_CLNT_INFO structure.
1302 ********************************************************************/
1304 void init_clnt_info(DOM_CLNT_INFO
*clnt
,
1305 char *logon_srv
, char *acct_name
,
1306 uint16 sec_chan
, char *comp_name
,
1309 DEBUG(5,("make_clnt_info\n"));
1311 init_log_info(&clnt
->login
, logon_srv
, acct_name
, sec_chan
, comp_name
);
1312 memcpy(&clnt
->cred
, cred
, sizeof(clnt
->cred
));
1315 /*******************************************************************
1316 Reads or writes a DOM_CLNT_INFO structure.
1317 ********************************************************************/
1319 BOOL
smb_io_clnt_info(char *desc
, DOM_CLNT_INFO
*clnt
, prs_struct
*ps
, int depth
)
1324 prs_debug(ps
, depth
, desc
, "smb_io_clnt_info");
1330 if(!smb_io_log_info("", &clnt
->login
, ps
, depth
))
1332 if(!smb_io_cred("", &clnt
->cred
, ps
, depth
))
1338 /*******************************************************************
1339 Inits a DOM_LOGON_ID structure.
1340 ********************************************************************/
1342 void init_logon_id(DOM_LOGON_ID
*log
, uint32 log_id_low
, uint32 log_id_high
)
1344 DEBUG(5,("make_logon_id: %d\n", __LINE__
));
1346 log
->low
= log_id_low
;
1347 log
->high
= log_id_high
;
1350 /*******************************************************************
1351 Reads or writes a DOM_LOGON_ID structure.
1352 ********************************************************************/
1354 BOOL
smb_io_logon_id(char *desc
, DOM_LOGON_ID
*log
, prs_struct
*ps
, int depth
)
1359 prs_debug(ps
, depth
, desc
, "smb_io_logon_id");
1365 if(!prs_uint32("low ", ps
, depth
, &log
->low
))
1367 if(!prs_uint32("high", ps
, depth
, &log
->high
))
1373 /*******************************************************************
1374 Inits an OWF_INFO structure.
1375 ********************************************************************/
1377 void init_owf_info(OWF_INFO
*hash
, uint8 data
[16])
1379 DEBUG(5,("init_owf_info: %d\n", __LINE__
));
1382 memcpy(hash
->data
, data
, sizeof(hash
->data
));
1384 memset((char *)hash
->data
, '\0', sizeof(hash
->data
));
1387 /*******************************************************************
1388 Reads or writes an OWF_INFO structure.
1389 ********************************************************************/
1391 BOOL
smb_io_owf_info(char *desc
, OWF_INFO
*hash
, prs_struct
*ps
, int depth
)
1396 prs_debug(ps
, depth
, desc
, "smb_io_owf_info");
1402 if(!prs_uint8s (False
, "data", ps
, depth
, hash
->data
, 16))
1408 /*******************************************************************
1409 Reads or writes a DOM_GID structure.
1410 ********************************************************************/
1412 BOOL
smb_io_gid(char *desc
, DOM_GID
*gid
, prs_struct
*ps
, int depth
)
1417 prs_debug(ps
, depth
, desc
, "smb_io_gid");
1423 if(!prs_uint32("g_rid", ps
, depth
, &gid
->g_rid
))
1425 if(!prs_uint32("attr ", ps
, depth
, &gid
->attr
))
1431 /*******************************************************************
1432 Reads or writes an POLICY_HND structure.
1433 ********************************************************************/
1435 BOOL
smb_io_pol_hnd(char *desc
, POLICY_HND
*pol
, prs_struct
*ps
, int depth
)
1440 prs_debug(ps
, depth
, desc
, "smb_io_pol_hnd");
1446 if(UNMARSHALLING(ps
))
1449 if (!prs_uint32("data1", ps
, depth
, &pol
->data1
))
1451 if (!prs_uint32("data2", ps
, depth
, &pol
->data2
))
1453 if (!prs_uint16("data3", ps
, depth
, &pol
->data3
))
1455 if (!prs_uint16("data4", ps
, depth
, &pol
->data4
))
1457 if(!prs_uint8s (False
, "data5", ps
, depth
, pol
->data5
, sizeof(pol
->data5
)))
1463 /*******************************************************************
1465 ********************************************************************/
1467 void init_unistr3(UNISTR3
*str
, const char *buf
)
1473 str
->str
.buffer
= NULL
;
1477 len
= strlen(buf
) + 1;
1479 str
->uni_str_len
=len
;
1481 if (len
< MAX_UNISTRLEN
)
1482 len
= MAX_UNISTRLEN
;
1484 len
*= sizeof(uint16
);
1486 str
->str
.buffer
= (uint16
*)talloc_zero(get_talloc_ctx(), len
);
1487 if (str
->str
.buffer
== NULL
)
1488 smb_panic("init_unistr3: malloc fail\n");
1490 /* store the string (null-terminated copy) */
1491 dos_struni2((char *)str
->str
.buffer
, buf
, len
);
1494 /*******************************************************************
1495 Reads or writes a UNISTR3 structure.
1496 ********************************************************************/
1498 BOOL
smb_io_unistr3(char *desc
, UNISTR3
*name
, prs_struct
*ps
, int depth
)
1503 prs_debug(ps
, depth
, desc
, "smb_io_unistr3");
1509 if(!prs_uint32("uni_str_len", ps
, depth
, &name
->uni_str_len
))
1512 /* don't know if len is specified by uni_str_len member... */
1513 /* assume unicode string is unicode-null-terminated, instead */
1515 if(!prs_unistr3(True
, "unistr", name
, ps
, depth
))
1522 /*******************************************************************
1523 Stream a uint64_struct
1524 ********************************************************************/
1525 BOOL
prs_uint64(char *name
, prs_struct
*ps
, int depth
, UINT64_S
*data64
)
1527 return prs_uint32(name
, ps
, depth
+1, &data64
->low
) &&
1528 prs_uint32(name
, ps
, depth
+1, &data64
->high
);
1531 /*******************************************************************
1532 reads or writes a BUFHDR2 structure.
1533 ********************************************************************/
1534 BOOL
smb_io_bufhdr2(char *desc
, BUFHDR2
*hdr
, prs_struct
*ps
, int depth
)
1536 prs_debug(ps
, depth
, desc
, "smb_io_bufhdr2");
1540 prs_uint32("info_level", ps
, depth
, &(hdr
->info_level
));
1541 prs_uint32("length ", ps
, depth
, &(hdr
->length
));
1542 prs_uint32("buffer ", ps
, depth
, &(hdr
->buffer
));
1547 /*******************************************************************
1548 reads or writes a BUFFER4 structure.
1549 ********************************************************************/
1550 BOOL
smb_io_buffer4(char *desc
, BUFFER4
*buf4
, uint32 buffer
, prs_struct
*ps
, int depth
)
1552 prs_debug(ps
, depth
, desc
, "smb_io_buffer4");
1556 prs_uint32("buf_len", ps
, depth
, &(buf4
->buf_len
));
1558 if (buf4
->buf_len
> MAX_BUFFERLEN
)
1560 buf4
->buf_len
= MAX_BUFFERLEN
;
1563 prs_uint8s(True
, "buffer", ps
, depth
, buf4
->buffer
, buf4
->buf_len
);
1568 /*******************************************************************
1569 creates a UNIHDR structure.
1570 ********************************************************************/
1572 BOOL
make_uni_hdr(UNIHDR
*hdr
, int len
)
1578 hdr
->uni_str_len
= 2 * len
;
1579 hdr
->uni_max_len
= 2 * len
;
1580 hdr
->buffer
= len
!= 0 ? 1 : 0;
1585 /*******************************************************************
1586 creates a BUFHDR2 structure.
1587 ********************************************************************/
1588 BOOL
make_bufhdr2(BUFHDR2
*hdr
, uint32 info_level
, uint32 length
, uint32 buffer
)
1590 hdr
->info_level
= info_level
;
1591 hdr
->length
= length
;
1592 hdr
->buffer
= buffer
;