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 static TALLOC_CTX
*parse_misc_talloc
= NULL
;
31 /******************************************************************* a
32 free up temporary memory - called from the main loop
33 ********************************************************************/
35 void parse_talloc_free(void)
37 if (!parse_misc_talloc
)
39 talloc_destroy(parse_misc_talloc
);
40 parse_misc_talloc
= NULL
;
43 /*******************************************************************
44 Reads or writes a UTIME type.
45 ********************************************************************/
47 static BOOL
smb_io_utime(char *desc
, UTIME
*t
, prs_struct
*ps
, int depth
)
52 prs_debug(ps
, depth
, desc
, "smb_io_utime");
58 if(!prs_uint32 ("time", ps
, depth
, &t
->time
))
64 /*******************************************************************
65 Reads or writes an NTTIME structure.
66 ********************************************************************/
68 BOOL
smb_io_time(char *desc
, NTTIME
*nttime
, prs_struct
*ps
, int depth
)
73 prs_debug(ps
, depth
, desc
, "smb_io_time");
79 if(!prs_uint32("low ", ps
, depth
, &nttime
->low
)) /* low part */
81 if(!prs_uint32("high", ps
, depth
, &nttime
->high
)) /* high part */
87 /*******************************************************************
88 Reads or writes a LOOKUP_LEVEL structure.
89 ********************************************************************/
91 BOOL
smb_io_lookup_level(char *desc
, LOOKUP_LEVEL
*level
, prs_struct
*ps
, int depth
)
96 prs_debug(ps
, depth
, desc
, "smb_io_lookup_level");
101 if(!prs_uint16("value", ps
, depth
, &level
->value
))
109 /*******************************************************************
110 Gets an enumeration handle from an ENUM_HND structure.
111 ********************************************************************/
113 uint32
get_enum_hnd(ENUM_HND
*enh
)
115 return (enh
&& enh
->ptr_hnd
!= 0) ? enh
->handle
: 0;
118 /*******************************************************************
119 Inits an ENUM_HND structure.
120 ********************************************************************/
122 void init_enum_hnd(ENUM_HND
*enh
, uint32 hnd
)
124 DEBUG(5,("smb_io_enum_hnd\n"));
126 enh
->ptr_hnd
= (hnd
!= 0) ? 1 : 0;
130 /*******************************************************************
131 Reads or writes an ENUM_HND structure.
132 ********************************************************************/
134 BOOL
smb_io_enum_hnd(char *desc
, ENUM_HND
*hnd
, prs_struct
*ps
, int depth
)
139 prs_debug(ps
, depth
, desc
, "smb_io_enum_hnd");
145 if(!prs_uint32("ptr_hnd", ps
, depth
, &hnd
->ptr_hnd
)) /* pointer */
148 if (hnd
->ptr_hnd
!= 0) {
149 if(!prs_uint32("handle ", ps
, depth
, &hnd
->handle
)) /* enum handle */
156 /*******************************************************************
157 Reads or writes a DOM_SID structure.
158 ********************************************************************/
160 BOOL
smb_io_dom_sid(char *desc
, DOM_SID
*sid
, prs_struct
*ps
, int depth
)
167 prs_debug(ps
, depth
, desc
, "smb_io_dom_sid");
173 if(!prs_uint8 ("sid_rev_num", ps
, depth
, &sid
->sid_rev_num
))
175 if(!prs_uint8 ("num_auths ", ps
, depth
, &sid
->num_auths
))
178 for (i
= 0; i
< 6; i
++)
181 slprintf(tmp
, sizeof(tmp
) - 1, "id_auth[%d] ", i
);
182 if(!prs_uint8 (tmp
, ps
, depth
, &sid
->id_auth
[i
]))
186 /* oops! XXXX should really issue a warning here... */
187 if (sid
->num_auths
> MAXSUBAUTHS
)
188 sid
->num_auths
= MAXSUBAUTHS
;
190 if(!prs_uint32s(False
, "sub_auths ", ps
, depth
, sid
->sub_auths
, sid
->num_auths
))
196 /*******************************************************************
197 Inits a DOM_SID structure.
199 BIG NOTE: this function only does SIDS where the identauth is not >= 2^32
200 identauth >= 2^32 can be detected because it will be specified in hex
201 ********************************************************************/
203 void init_dom_sid(DOM_SID
*sid
, char *str_sid
)
211 DEBUG(4,("netlogon domain SID: none\n"));
212 sid
->sid_rev_num
= 0;
217 pstrcpy(domsid
, str_sid
);
219 DEBUG(4,("init_dom_sid %d SID: %s\n", __LINE__
, domsid
));
221 /* assume, but should check, that domsid starts "S-" */
222 p
= strtok(domsid
+2,"-");
223 sid
->sid_rev_num
= atoi(p
);
225 /* identauth in decimal should be < 2^32 */
226 /* identauth in hex should be >= 2^32 */
227 identauth
= atoi(strtok(0,"-"));
229 DEBUG(4,("netlogon rev %d\n", sid
->sid_rev_num
));
230 DEBUG(4,("netlogon %s ia %d\n", p
, identauth
));
234 sid
->id_auth
[2] = (identauth
& 0xff000000) >> 24;
235 sid
->id_auth
[3] = (identauth
& 0x00ff0000) >> 16;
236 sid
->id_auth
[4] = (identauth
& 0x0000ff00) >> 8;
237 sid
->id_auth
[5] = (identauth
& 0x000000ff);
241 while ((p
= strtok(0, "-")) != NULL
&& sid
->num_auths
< MAXSUBAUTHS
)
242 sid
->sub_auths
[sid
->num_auths
++] = atoi(p
);
244 DEBUG(4,("init_dom_sid: %d SID: %s\n", __LINE__
, domsid
));
247 /*******************************************************************
248 Inits a DOM_SID2 structure.
249 ********************************************************************/
251 void init_dom_sid2(DOM_SID2
*sid2
, DOM_SID
*sid
)
254 sid2
->num_auths
= sid2
->sid
.num_auths
;
257 /*******************************************************************
258 Reads or writes a DOM_SID2 structure.
259 ********************************************************************/
261 BOOL
smb_io_dom_sid2(char *desc
, DOM_SID2
*sid
, prs_struct
*ps
, int depth
)
266 prs_debug(ps
, depth
, desc
, "smb_io_dom_sid2");
272 if(!prs_uint32("num_auths", ps
, depth
, &sid
->num_auths
))
275 if(!smb_io_dom_sid("sid", &sid
->sid
, ps
, depth
))
281 /*******************************************************************
282 creates a STRHDR structure.
283 ********************************************************************/
285 void init_str_hdr(STRHDR
*hdr
, int max_len
, int len
, uint32 buffer
)
287 hdr
->str_max_len
= max_len
;
288 hdr
->str_str_len
= len
;
289 hdr
->buffer
= buffer
;
292 /*******************************************************************
293 Reads or writes a STRHDR structure.
294 ********************************************************************/
296 BOOL
smb_io_strhdr(char *desc
, STRHDR
*hdr
, prs_struct
*ps
, int depth
)
301 prs_debug(ps
, depth
, desc
, "smb_io_strhdr");
306 if(!prs_uint16("str_str_len", ps
, depth
, &hdr
->str_str_len
))
308 if(!prs_uint16("str_max_len", ps
, depth
, &hdr
->str_max_len
))
310 if(!prs_uint32("buffer ", ps
, depth
, &hdr
->buffer
))
316 /*******************************************************************
317 Inits a UNIHDR structure.
318 ********************************************************************/
320 void init_uni_hdr(UNIHDR
*hdr
, int len
)
322 hdr
->uni_str_len
= 2 * len
;
323 hdr
->uni_max_len
= 2 * len
;
324 hdr
->buffer
= len
!= 0 ? 1 : 0;
327 /*******************************************************************
328 Reads or writes a UNIHDR structure.
329 ********************************************************************/
331 BOOL
smb_io_unihdr(char *desc
, UNIHDR
*hdr
, prs_struct
*ps
, int depth
)
336 prs_debug(ps
, depth
, desc
, "smb_io_unihdr");
342 if(!prs_uint16("uni_str_len", ps
, depth
, &hdr
->uni_str_len
))
344 if(!prs_uint16("uni_max_len", ps
, depth
, &hdr
->uni_max_len
))
346 if(!prs_uint32("buffer ", ps
, depth
, &hdr
->buffer
))
352 /*******************************************************************
353 Inits a BUFHDR structure.
354 ********************************************************************/
356 void init_buf_hdr(BUFHDR
*hdr
, int max_len
, int len
)
358 hdr
->buf_max_len
= max_len
;
362 /*******************************************************************
363 prs_uint16 wrapper. Call this and it sets up a pointer to where the
364 uint16 should be stored, or gets the size if reading.
365 ********************************************************************/
367 BOOL
smb_io_hdrbuf_pre(char *desc
, BUFHDR
*hdr
, prs_struct
*ps
, int depth
, uint32
*offset
)
369 (*offset
) = prs_offset(ps
);
374 if(!smb_io_hdrbuf(desc
, hdr
, ps
, depth
))
381 if(!prs_set_offset(ps
, prs_offset(ps
) + (sizeof(uint32
) * 2)))
388 /*******************************************************************
389 smb_io_hdrbuf wrapper. Call this and it retrospectively stores the size.
390 Does nothing on reading, as that is already handled by ...._pre()
391 ********************************************************************/
393 BOOL
smb_io_hdrbuf_post(char *desc
, BUFHDR
*hdr
, prs_struct
*ps
, int depth
,
394 uint32 ptr_hdrbuf
, uint32 max_len
, uint32 len
)
397 /* writing: go back and do a retrospective job. i hate this */
399 uint32 old_offset
= prs_offset(ps
);
401 init_buf_hdr(hdr
, max_len
, len
);
402 if(!prs_set_offset(ps
, ptr_hdrbuf
))
404 if(!smb_io_hdrbuf(desc
, hdr
, ps
, depth
))
407 if(!prs_set_offset(ps
, old_offset
))
414 /*******************************************************************
415 Reads or writes a BUFHDR structure.
416 ********************************************************************/
418 BOOL
smb_io_hdrbuf(char *desc
, BUFHDR
*hdr
, prs_struct
*ps
, int depth
)
423 prs_debug(ps
, depth
, desc
, "smb_io_hdrbuf");
429 if(!prs_uint32("buf_max_len", ps
, depth
, &hdr
->buf_max_len
))
431 if(!prs_uint32("buf_len ", ps
, depth
, &hdr
->buf_len
))
437 /*******************************************************************
438 creates a UNIHDR2 structure.
439 ********************************************************************/
441 void init_uni_hdr2(UNIHDR2
*hdr
, int len
)
443 init_uni_hdr(&hdr
->unihdr
, len
);
444 hdr
->buffer
= (len
> 0) ? 1 : 0;
447 /*******************************************************************
448 Reads or writes a UNIHDR2 structure.
449 ********************************************************************/
451 BOOL
smb_io_unihdr2(char *desc
, UNIHDR2
*hdr2
, prs_struct
*ps
, int depth
)
456 prs_debug(ps
, depth
, desc
, "smb_io_unihdr2");
462 if(!smb_io_unihdr("hdr", &hdr2
->unihdr
, ps
, depth
))
464 if(!prs_uint32("buffer", ps
, depth
, &hdr2
->buffer
))
470 /*******************************************************************
471 Inits a UNISTR structure.
472 ********************************************************************/
474 void init_unistr(UNISTR
*str
, const char *buf
)
485 len
= strlen(buf
) + 1;
487 if (!parse_misc_talloc
)
488 parse_misc_talloc
= talloc_init();
490 if (len
< MAX_UNISTRLEN
)
492 len
*= sizeof(uint16
);
494 str
->buffer
= (uint16
*)talloc(parse_misc_talloc
, len
);
495 if (str
->buffer
== NULL
)
496 smb_panic("init_unistr2: malloc fail\n");
498 /* store the string (null-terminated copy) */
499 dos_struni2((char *)str
->buffer
, buf
, len
);
504 /*******************************************************************
505 reads or writes a UNISTR structure.
506 XXXX NOTE: UNISTR structures NEED to be null-terminated.
507 ********************************************************************/
509 BOOL
smb_io_unistr(char *desc
, UNISTR
*uni
, prs_struct
*ps
, int depth
)
514 prs_debug(ps
, depth
, desc
, "smb_io_unistr");
519 if(!prs_unistr("unistr", ps
, depth
, uni
))
525 /*******************************************************************
526 Allocate the BUFFER3 memory.
527 ********************************************************************/
529 static void create_buffer3(BUFFER3
*str
, size_t len
)
531 if (!parse_misc_talloc
)
532 parse_misc_talloc
= talloc_init();
534 if (len
< MAX_BUFFERLEN
)
537 str
->buffer
= talloc(parse_misc_talloc
, len
);
538 if (str
->buffer
== NULL
)
539 smb_panic("create_buffer3: malloc fail\n");
543 /*******************************************************************
544 Inits a BUFFER3 structure from a uint32
545 ********************************************************************/
547 void init_buffer3_uint32(BUFFER3
*str
, uint32 val
)
551 /* set up string lengths. */
552 str
->buf_max_len
= sizeof(uint32
);
553 str
->buf_len
= sizeof(uint32
);
555 create_buffer3(str
, sizeof(uint32
));
556 SIVAL(str
->buffer
, 0, val
);
559 /*******************************************************************
560 Inits a BUFFER3 structure.
561 ********************************************************************/
563 void init_buffer3_str(BUFFER3
*str
, char *buf
, int len
)
567 /* set up string lengths. */
568 str
->buf_max_len
= len
* 2;
569 str
->buf_len
= len
* 2;
571 create_buffer3(str
, str
->buf_max_len
);
573 /* store the string (null-terminated 8 bit chars into 16 bit chars) */
574 dos_struni2((char *)str
->buffer
, buf
, str
->buf_max_len
);
577 /*******************************************************************
578 Inits a BUFFER3 structure from a hex string.
579 ********************************************************************/
581 void init_buffer3_hex(BUFFER3
*str
, char *buf
)
584 create_buffer3(str
, strlen(buf
));
585 str
->buf_max_len
= str
->buf_len
= strhex_to_str((char *)str
->buffer
, sizeof(str
->buffer
), buf
);
588 /*******************************************************************
589 Inits a BUFFER3 structure.
590 ********************************************************************/
592 void init_buffer3_bytes(BUFFER3
*str
, uint8
*buf
, int len
)
596 /* max buffer size (allocated size) */
597 str
->buf_max_len
= len
;
599 create_buffer3(str
, len
);
600 memcpy(str
->buffer
, buf
, len
);
602 str
->buf_len
= buf
!= NULL
? len
: 0;
605 /*******************************************************************
606 Reads or writes a BUFFER3 structure.
607 the uni_max_len member tells you how large the buffer is.
608 the uni_str_len member tells you how much of the buffer is really used.
609 ********************************************************************/
611 BOOL
smb_io_buffer3(char *desc
, BUFFER3
*buf3
, prs_struct
*ps
, int depth
)
616 prs_debug(ps
, depth
, desc
, "smb_io_buffer3");
622 if(!prs_uint32("uni_max_len", ps
, depth
, &buf3
->buf_max_len
))
625 if (UNMARSHALLING(ps
)) {
626 buf3
->buffer
= prs_alloc_mem(ps
, buf3
->buf_max_len
);
627 if (buf3
->buffer
== NULL
)
631 if(!prs_uint8s(True
, "buffer ", ps
, depth
, buf3
->buffer
, buf3
->buf_max_len
))
634 if(!prs_uint32("buf_len ", ps
, depth
, &buf3
->buf_len
))
640 /*******************************************************************
641 reads or writes a BUFFER5 structure.
642 the buf_len member tells you how large the buffer is.
643 ********************************************************************/
644 BOOL
smb_io_buffer5(char *desc
, BUFFER5
*buf5
, prs_struct
*ps
, int depth
)
646 prs_debug(ps
, depth
, desc
, "smb_io_buffer5");
649 if (buf5
== NULL
) return False
;
652 prs_uint32("buf_len", ps
, depth
, &(buf5
->buf_len
));
654 /* reading: alloc the buffer first */
655 if ( UNMARSHALLING(ps
) ) {
656 buf5
->buffer
=(uint16
*)prs_alloc_mem(ps
, sizeof(uint16
)*buf5
->buf_len
);
657 if (buf5
->buffer
== NULL
)
661 prs_uint16s(True
, "buffer", ps
, depth
, buf5
->buffer
, buf5
->buf_len
);
666 /*******************************************************************
667 Inits a BUFFER2 structure.
668 ********************************************************************/
670 void init_buffer2(BUFFER2
*str
, uint8
*buf
, int len
)
674 /* max buffer size (allocated size) */
675 str
->buf_max_len
= len
;
677 str
->buf_len
= buf
!= NULL
? len
: 0;
680 if (!parse_misc_talloc
)
681 parse_misc_talloc
= talloc_init();
683 if (len
< MAX_BUFFERLEN
)
685 str
->buffer
= talloc(parse_misc_talloc
, len
);
686 if (str
->buffer
== NULL
)
687 smb_panic("init_buffer2: malloc fail\n");
688 memcpy(str
->buffer
, buf
, MIN(str
->buf_len
, len
));
692 /*******************************************************************
693 Reads or writes a BUFFER2 structure.
694 the uni_max_len member tells you how large the buffer is.
695 the uni_str_len member tells you how much of the buffer is really used.
696 ********************************************************************/
698 BOOL
smb_io_buffer2(char *desc
, BUFFER2
*buf2
, uint32 buffer
, prs_struct
*ps
, int depth
)
705 prs_debug(ps
, depth
, desc
, "smb_io_buffer2");
711 if(!prs_uint32("uni_max_len", ps
, depth
, &buf2
->buf_max_len
))
713 if(!prs_uint32("undoc ", ps
, depth
, &buf2
->undoc
))
715 if(!prs_uint32("buf_len ", ps
, depth
, &buf2
->buf_len
))
718 /* buffer advanced by indicated length of string
719 NOT by searching for null-termination */
721 if(!prs_buffer2(True
, "buffer ", ps
, depth
, buf2
))
726 prs_debug(ps
, depth
, desc
, "smb_io_buffer2 - NULL");
728 memset((char *)buf2
, '\0', sizeof(*buf2
));
734 /*******************************************************************
735 creates a UNISTR2 structure: sets up the buffer, too
736 ********************************************************************/
738 void init_buf_unistr2(UNISTR2
*str
, uint32
*ptr
, const char *buf
)
743 init_unistr2(str
, buf
, strlen(buf
)+1);
748 init_unistr2(str
, "", 0);
753 /*******************************************************************
754 Copies a UNISTR2 structure.
755 ********************************************************************/
757 void copy_unistr2(UNISTR2
*str
, UNISTR2
*from
)
759 /* set up string lengths. add one if string is not null-terminated */
760 str
->uni_max_len
= from
->uni_max_len
;
761 str
->undoc
= from
->undoc
;
762 str
->uni_str_len
= from
->uni_str_len
;
764 if (str
->buffer
== NULL
) {
765 size_t len
= from
->uni_max_len
* 2;
767 if (!parse_misc_talloc
)
768 parse_misc_talloc
= talloc_init();
770 if (len
< MAX_UNISTRLEN
)
772 len
*= sizeof(uint16
);
774 str
->buffer
= (uint16
*)talloc(parse_misc_talloc
, len
);
775 if (str
->buffer
== NULL
)
776 smb_panic("copy_unistr2: malloc fail\n");
779 /* copy the string */
780 memcpy(str
->buffer
, from
->buffer
, sizeof(from
->buffer
));
783 /*******************************************************************
784 Creates a STRING2 structure.
785 ********************************************************************/
787 void init_string2(STRING2
*str
, char *buf
, int len
)
791 /* set up string lengths. */
792 str
->str_max_len
= len
;
794 str
->str_str_len
= len
;
796 /* store the string */
798 if (!parse_misc_talloc
)
799 parse_misc_talloc
= talloc_init();
801 if (len
< MAX_STRINGLEN
)
802 alloc_len
= MAX_STRINGLEN
;
803 str
->buffer
= talloc(parse_misc_talloc
, alloc_len
);
804 if (str
->buffer
== NULL
)
805 smb_panic("init_string2: malloc fail\n");
806 memcpy(str
->buffer
, buf
, len
);
810 /*******************************************************************
811 Reads or writes a STRING2 structure.
812 XXXX NOTE: STRING2 structures need NOT be null-terminated.
813 the str_str_len member tells you how long the string is;
814 the str_max_len member tells you how large the buffer is.
815 ********************************************************************/
817 BOOL
smb_io_string2(char *desc
, STRING2
*str2
, uint32 buffer
, prs_struct
*ps
, int depth
)
824 prs_debug(ps
, depth
, desc
, "smb_io_string2");
830 if(!prs_uint32("str_max_len", ps
, depth
, &str2
->str_max_len
))
832 if(!prs_uint32("undoc ", ps
, depth
, &str2
->undoc
))
834 if(!prs_uint32("str_str_len", ps
, depth
, &str2
->str_str_len
))
837 /* buffer advanced by indicated length of string
838 NOT by searching for null-termination */
839 if(!prs_string2(True
, "buffer ", ps
, depth
, str2
))
844 prs_debug(ps
, depth
, desc
, "smb_io_string2 - NULL");
846 memset((char *)str2
, '\0', sizeof(*str2
));
853 /*******************************************************************
854 Inits a UNISTR2 structure.
855 ********************************************************************/
857 void init_unistr2(UNISTR2
*str
, const char *buf
, size_t len
)
861 /* set up string lengths. */
862 str
->uni_max_len
= (uint32
)len
;
864 str
->uni_str_len
= (uint32
)len
;
866 if (!parse_misc_talloc
)
867 parse_misc_talloc
= talloc_init();
869 if (len
< MAX_UNISTRLEN
)
871 len
*= sizeof(uint16
);
873 str
->buffer
= (uint16
*)talloc(parse_misc_talloc
, len
);
874 if (str
->buffer
== NULL
)
875 smb_panic("init_unistr2: malloc fail\n");
877 /* store the string (null-terminated 8 bit chars into 16 bit chars) */
878 dos_struni2((char *)str
->buffer
, buf
, len
);
881 /*******************************************************************
882 Inits a UNISTR2 structure from a UNISTR
883 ********************************************************************/
884 void init_unistr2_from_unistr (UNISTR2
*to
, UNISTR
*from
)
889 /* the destination UNISTR2 should never be NULL.
890 if it is it is a programming error */
892 /* if the source UNISTR is NULL, then zero out
893 the destination string and return */
895 if ((from
== NULL
) || (from
->buffer
== NULL
))
898 /* get the length; UNISTR must be NULL terminated */
900 while ((from
->buffer
)[i
]!='\0')
903 /* set up string lengths; uni_max_len is set to i+1
904 because we need to account for the final NULL termination */
905 to
->uni_max_len
= i
+1;
907 to
->uni_str_len
= i
+1;
909 if (!parse_misc_talloc
)
910 parse_misc_talloc
= talloc_init();
912 /* allocate the space and copy the string buffer */
913 to
->buffer
= (uint16
*)talloc(parse_misc_talloc
, sizeof(uint16
)*(to
->uni_str_len
));
914 if (to
->buffer
== NULL
)
915 smb_panic("init_unistr2_from_unistr: malloc fail\n");
916 memcpy(to
->buffer
, from
->buffer
, to
->uni_max_len
*sizeof(uint16
));
922 /*******************************************************************
923 Reads or writes a UNISTR2 structure.
924 XXXX NOTE: UNISTR2 structures need NOT be null-terminated.
925 the uni_str_len member tells you how long the string is;
926 the uni_max_len member tells you how large the buffer is.
927 ********************************************************************/
929 BOOL
smb_io_unistr2(char *desc
, UNISTR2
*uni2
, uint32 buffer
, prs_struct
*ps
, int depth
)
936 prs_debug(ps
, depth
, desc
, "smb_io_unistr2");
942 if(!prs_uint32("uni_max_len", ps
, depth
, &uni2
->uni_max_len
))
944 if(!prs_uint32("undoc ", ps
, depth
, &uni2
->undoc
))
946 if(!prs_uint32("uni_str_len", ps
, depth
, &uni2
->uni_str_len
))
949 /* buffer advanced by indicated length of string
950 NOT by searching for null-termination */
951 if(!prs_unistr2(True
, "buffer ", ps
, depth
, uni2
))
956 prs_debug(ps
, depth
, desc
, "smb_io_unistr2 - NULL");
958 memset((char *)uni2
, '\0', sizeof(*uni2
));
965 /*******************************************************************
966 Inits a DOM_RID2 structure.
967 ********************************************************************/
969 void init_dom_rid2(DOM_RID2
*rid2
, uint32 rid
, uint8 type
, uint32 idx
)
976 /*******************************************************************
977 Reads or writes a DOM_RID2 structure.
978 ********************************************************************/
980 BOOL
smb_io_dom_rid2(char *desc
, DOM_RID2
*rid2
, prs_struct
*ps
, int depth
)
985 prs_debug(ps
, depth
, desc
, "smb_io_dom_rid2");
991 if(!prs_uint8("type ", ps
, depth
, &rid2
->type
))
995 if(!prs_uint32("rid ", ps
, depth
, &rid2
->rid
))
997 if(!prs_uint32("rid_idx", ps
, depth
, &rid2
->rid_idx
))
1003 /*******************************************************************
1004 creates a DOM_RID3 structure.
1005 ********************************************************************/
1007 void init_dom_rid3(DOM_RID3
*rid3
, uint32 rid
, uint8 type
)
1011 rid3
->ptr_type
= 0x1; /* non-zero, basically. */
1016 /*******************************************************************
1017 reads or writes a DOM_RID3 structure.
1018 ********************************************************************/
1020 BOOL
smb_io_dom_rid3(char *desc
, DOM_RID3
*rid3
, prs_struct
*ps
, int depth
)
1025 prs_debug(ps
, depth
, desc
, "smb_io_dom_rid3");
1031 if(!prs_uint32("rid ", ps
, depth
, &rid3
->rid
))
1033 if(!prs_uint32("type1 ", ps
, depth
, &rid3
->type1
))
1035 if(!prs_uint32("ptr_type", ps
, depth
, &rid3
->ptr_type
))
1037 if(!prs_uint32("type2 ", ps
, depth
, &rid3
->type2
))
1039 if(!prs_uint32("unk ", ps
, depth
, &rid3
->unk
))
1045 /*******************************************************************
1046 Inits a DOM_RID4 structure.
1047 ********************************************************************/
1049 void init_dom_rid4(DOM_RID4
*rid4
, uint16 unknown
, uint16 attr
, uint32 rid
)
1051 rid4
->unknown
= unknown
;
1056 /*******************************************************************
1057 Inits a DOM_CLNT_SRV structure.
1058 ********************************************************************/
1060 static void init_clnt_srv(DOM_CLNT_SRV
*log
, char *logon_srv
, char *comp_name
)
1062 DEBUG(5,("init_clnt_srv: %d\n", __LINE__
));
1064 if (logon_srv
!= NULL
) {
1065 log
->undoc_buffer
= 1;
1066 init_unistr2(&log
->uni_logon_srv
, logon_srv
, strlen(logon_srv
)+1);
1068 log
->undoc_buffer
= 0;
1071 if (comp_name
!= NULL
) {
1072 log
->undoc_buffer2
= 1;
1073 init_unistr2(&log
->uni_comp_name
, comp_name
, strlen(comp_name
)+1);
1075 log
->undoc_buffer2
= 0;
1079 /*******************************************************************
1080 Inits or writes a DOM_CLNT_SRV structure.
1081 ********************************************************************/
1083 static BOOL
smb_io_clnt_srv(char *desc
, DOM_CLNT_SRV
*log
, prs_struct
*ps
, int depth
)
1088 prs_debug(ps
, depth
, desc
, "smb_io_clnt_srv");
1094 if(!prs_uint32("undoc_buffer ", ps
, depth
, &log
->undoc_buffer
))
1097 if (log
->undoc_buffer
!= 0) {
1098 if(!smb_io_unistr2("unistr2", &log
->uni_logon_srv
, log
->undoc_buffer
, ps
, depth
))
1105 if(!prs_uint32("undoc_buffer2", ps
, depth
, &log
->undoc_buffer2
))
1108 if (log
->undoc_buffer2
!= 0) {
1109 if(!smb_io_unistr2("unistr2", &log
->uni_comp_name
, log
->undoc_buffer2
, ps
, depth
))
1116 /*******************************************************************
1117 Inits a DOM_LOG_INFO structure.
1118 ********************************************************************/
1120 void init_log_info(DOM_LOG_INFO
*log
, char *logon_srv
, char *acct_name
,
1121 uint16 sec_chan
, char *comp_name
)
1123 DEBUG(5,("make_log_info %d\n", __LINE__
));
1125 log
->undoc_buffer
= 1;
1127 init_unistr2(&log
->uni_logon_srv
, logon_srv
, strlen(logon_srv
)+1);
1128 init_unistr2(&log
->uni_acct_name
, acct_name
, strlen(acct_name
)+1);
1130 log
->sec_chan
= sec_chan
;
1132 init_unistr2(&log
->uni_comp_name
, comp_name
, strlen(comp_name
)+1);
1135 /*******************************************************************
1136 Reads or writes a DOM_LOG_INFO structure.
1137 ********************************************************************/
1139 BOOL
smb_io_log_info(char *desc
, DOM_LOG_INFO
*log
, prs_struct
*ps
, int depth
)
1144 prs_debug(ps
, depth
, desc
, "smb_io_log_info");
1150 if(!prs_uint32("undoc_buffer", ps
, depth
, &log
->undoc_buffer
))
1153 if(!smb_io_unistr2("unistr2", &log
->uni_logon_srv
, True
, ps
, depth
))
1155 if(!smb_io_unistr2("unistr2", &log
->uni_acct_name
, True
, ps
, depth
))
1158 if(!prs_uint16("sec_chan", ps
, depth
, &log
->sec_chan
))
1161 if(!smb_io_unistr2("unistr2", &log
->uni_comp_name
, True
, ps
, depth
))
1167 /*******************************************************************
1168 Reads or writes a DOM_CHAL structure.
1169 ********************************************************************/
1171 BOOL
smb_io_chal(char *desc
, DOM_CHAL
*chal
, prs_struct
*ps
, int depth
)
1176 prs_debug(ps
, depth
, desc
, "smb_io_chal");
1182 if(!prs_uint8s (False
, "data", ps
, depth
, chal
->data
, 8))
1188 /*******************************************************************
1189 Reads or writes a DOM_CRED structure.
1190 ********************************************************************/
1192 BOOL
smb_io_cred(char *desc
, DOM_CRED
*cred
, prs_struct
*ps
, int depth
)
1197 prs_debug(ps
, depth
, desc
, "smb_io_cred");
1203 if(!smb_io_chal ("", &cred
->challenge
, ps
, depth
))
1205 if(!smb_io_utime("", &cred
->timestamp
, ps
, depth
))
1211 /*******************************************************************
1212 Inits a DOM_CLNT_INFO2 structure.
1213 ********************************************************************/
1215 void init_clnt_info2(DOM_CLNT_INFO2
*clnt
,
1216 char *logon_srv
, char *comp_name
,
1217 DOM_CRED
*clnt_cred
)
1219 DEBUG(5,("make_clnt_info: %d\n", __LINE__
));
1221 init_clnt_srv(&(clnt
->login
), logon_srv
, comp_name
);
1223 if (clnt_cred
!= NULL
) {
1225 memcpy(&(clnt
->cred
), clnt_cred
, sizeof(clnt
->cred
));
1231 /*******************************************************************
1232 Reads or writes a DOM_CLNT_INFO2 structure.
1233 ********************************************************************/
1235 BOOL
smb_io_clnt_info2(char *desc
, DOM_CLNT_INFO2
*clnt
, prs_struct
*ps
, int depth
)
1240 prs_debug(ps
, depth
, desc
, "smb_io_clnt_info2");
1246 if(!smb_io_clnt_srv("", &clnt
->login
, ps
, depth
))
1252 if(!prs_uint32("ptr_cred", ps
, depth
, &clnt
->ptr_cred
))
1254 if(!smb_io_cred("", &clnt
->cred
, ps
, depth
))
1260 /*******************************************************************
1261 Inits a DOM_CLNT_INFO structure.
1262 ********************************************************************/
1264 void init_clnt_info(DOM_CLNT_INFO
*clnt
,
1265 char *logon_srv
, char *acct_name
,
1266 uint16 sec_chan
, char *comp_name
,
1269 DEBUG(5,("make_clnt_info\n"));
1271 init_log_info(&clnt
->login
, logon_srv
, acct_name
, sec_chan
, comp_name
);
1272 memcpy(&clnt
->cred
, cred
, sizeof(clnt
->cred
));
1275 /*******************************************************************
1276 Reads or writes a DOM_CLNT_INFO structure.
1277 ********************************************************************/
1279 BOOL
smb_io_clnt_info(char *desc
, DOM_CLNT_INFO
*clnt
, prs_struct
*ps
, int depth
)
1284 prs_debug(ps
, depth
, desc
, "smb_io_clnt_info");
1290 if(!smb_io_log_info("", &clnt
->login
, ps
, depth
))
1292 if(!smb_io_cred("", &clnt
->cred
, ps
, depth
))
1298 /*******************************************************************
1299 Inits a DOM_LOGON_ID structure.
1300 ********************************************************************/
1302 void init_logon_id(DOM_LOGON_ID
*log
, uint32 log_id_low
, uint32 log_id_high
)
1304 DEBUG(5,("make_logon_id: %d\n", __LINE__
));
1306 log
->low
= log_id_low
;
1307 log
->high
= log_id_high
;
1310 /*******************************************************************
1311 Reads or writes a DOM_LOGON_ID structure.
1312 ********************************************************************/
1314 BOOL
smb_io_logon_id(char *desc
, DOM_LOGON_ID
*log
, prs_struct
*ps
, int depth
)
1319 prs_debug(ps
, depth
, desc
, "smb_io_logon_id");
1325 if(!prs_uint32("low ", ps
, depth
, &log
->low
))
1327 if(!prs_uint32("high", ps
, depth
, &log
->high
))
1333 /*******************************************************************
1334 Inits an OWF_INFO structure.
1335 ********************************************************************/
1337 void init_owf_info(OWF_INFO
*hash
, uint8 data
[16])
1339 DEBUG(5,("init_owf_info: %d\n", __LINE__
));
1342 memcpy(hash
->data
, data
, sizeof(hash
->data
));
1344 memset((char *)hash
->data
, '\0', sizeof(hash
->data
));
1347 /*******************************************************************
1348 Reads or writes an OWF_INFO structure.
1349 ********************************************************************/
1351 BOOL
smb_io_owf_info(char *desc
, OWF_INFO
*hash
, prs_struct
*ps
, int depth
)
1356 prs_debug(ps
, depth
, desc
, "smb_io_owf_info");
1362 if(!prs_uint8s (False
, "data", ps
, depth
, hash
->data
, 16))
1368 /*******************************************************************
1369 Reads or writes a DOM_GID structure.
1370 ********************************************************************/
1372 BOOL
smb_io_gid(char *desc
, DOM_GID
*gid
, prs_struct
*ps
, int depth
)
1377 prs_debug(ps
, depth
, desc
, "smb_io_gid");
1383 if(!prs_uint32("g_rid", ps
, depth
, &gid
->g_rid
))
1385 if(!prs_uint32("attr ", ps
, depth
, &gid
->attr
))
1391 /*******************************************************************
1392 Reads or writes an POLICY_HND structure.
1393 ********************************************************************/
1395 BOOL
smb_io_pol_hnd(char *desc
, POLICY_HND
*pol
, prs_struct
*ps
, int depth
)
1400 prs_debug(ps
, depth
, desc
, "smb_io_pol_hnd");
1406 if(!prs_uint8s (False
, "data", ps
, depth
, pol
->data
, POL_HND_SIZE
))
1412 /*******************************************************************
1413 Reads or writes a dom query structure.
1414 ********************************************************************/
1416 static BOOL
smb_io_dom_query(char *desc
, DOM_QUERY
*d_q
, prs_struct
*ps
, int depth
)
1421 prs_debug(ps
, depth
, desc
, "smb_io_dom_query");
1427 if(!prs_uint16("uni_dom_max_len", ps
, depth
, &d_q
->uni_dom_max_len
)) /* domain name string length * 2 */
1429 if(!prs_uint16("uni_dom_str_len", ps
, depth
, &d_q
->uni_dom_str_len
)) /* domain name string length * 2 */
1432 if(!prs_uint32("buffer_dom_name", ps
, depth
, &d_q
->buffer_dom_name
)) /* undocumented domain name string buffer pointer */
1434 if(!prs_uint32("buffer_dom_sid ", ps
, depth
, &d_q
->buffer_dom_sid
)) /* undocumented domain SID string buffer pointer */
1437 if(!smb_io_unistr2("unistr2", &d_q
->uni_domain_name
, d_q
->buffer_dom_name
, ps
, depth
)) /* domain name (unicode string) */
1443 if (d_q
->buffer_dom_sid
!= 0) {
1444 if(!smb_io_dom_sid2("", &d_q
->dom_sid
, ps
, depth
)) /* domain SID */
1447 memset((char *)&d_q
->dom_sid
, '\0', sizeof(d_q
->dom_sid
));
1453 /*******************************************************************
1454 Reads or writes a dom query structure.
1455 ********************************************************************/
1457 BOOL
smb_io_dom_query_3(char *desc
, DOM_QUERY_3
*d_q
, prs_struct
*ps
, int depth
)
1459 return smb_io_dom_query("", d_q
, ps
, depth
);
1462 /*******************************************************************
1463 Reads or writes a dom query structure.
1464 ********************************************************************/
1466 BOOL
smb_io_dom_query_5(char *desc
, DOM_QUERY_3
*d_q
, prs_struct
*ps
, int depth
)
1468 return smb_io_dom_query("", d_q
, ps
, depth
);
1472 /*******************************************************************
1473 Reads or writes a UNISTR3 structure.
1474 ********************************************************************/
1476 BOOL
smb_io_unistr3(char *desc
, UNISTR3
*name
, prs_struct
*ps
, int depth
)
1481 prs_debug(ps
, depth
, desc
, "smb_io_unistr3");
1487 if(!prs_uint32("uni_str_len", ps
, depth
, &name
->uni_str_len
))
1490 /* don't know if len is specified by uni_str_len member... */
1491 /* assume unicode string is unicode-null-terminated, instead */
1493 if(!prs_unistr3(True
, "unistr", name
, ps
, depth
))
1500 /*******************************************************************
1501 Stream a uint64_struct
1502 ********************************************************************/
1503 BOOL
prs_uint64(char *name
, prs_struct
*ps
, int depth
, UINT64_S
*data64
)
1505 return prs_uint32(name
, ps
, depth
+1, &data64
->low
) &&
1506 prs_uint32(name
, ps
, depth
+1, &data64
->high
);