2 * Unix SMB/Netbios implementation.
4 * RPC Pipe client / server routines
5 * Copyright (C) Andrew Tridgell 1992-1997,
6 * Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
7 * Copyright (C) Paul Ashton 1997.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 extern int DEBUGLEVEL
;
29 /*******************************************************************
30 Reads or writes a UTIME type.
31 ********************************************************************/
33 static BOOL
smb_io_utime(char *desc
, UTIME
*t
, prs_struct
*ps
, int depth
)
38 prs_debug(ps
, depth
, desc
, "smb_io_utime");
44 if(!prs_uint32 ("time", ps
, depth
, &t
->time
))
50 /*******************************************************************
51 Reads or writes an NTTIME structure.
52 ********************************************************************/
54 BOOL
smb_io_time(char *desc
, NTTIME
*nttime
, prs_struct
*ps
, int depth
)
59 prs_debug(ps
, depth
, desc
, "smb_io_time");
65 if(!prs_uint32("low ", ps
, depth
, &nttime
->low
)) /* low part */
67 if(!prs_uint32("high", ps
, depth
, &nttime
->high
)) /* high part */
73 /*******************************************************************
74 Reads or writes a LOOKUP_LEVEL structure.
75 ********************************************************************/
77 BOOL
smb_io_lookup_level(char *desc
, LOOKUP_LEVEL
*level
, prs_struct
*ps
, int depth
)
82 prs_debug(ps
, depth
, desc
, "smb_io_lookup_level");
87 if(!prs_uint16("value", ps
, depth
, &level
->value
))
95 /*******************************************************************
96 Gets an enumeration handle from an ENUM_HND structure.
97 ********************************************************************/
99 uint32
get_enum_hnd(ENUM_HND
*enh
)
101 return (enh
&& enh
->ptr_hnd
!= 0) ? enh
->handle
: 0;
104 /*******************************************************************
105 Inits an ENUM_HND structure.
106 ********************************************************************/
108 void init_enum_hnd(ENUM_HND
*enh
, uint32 hnd
)
110 DEBUG(5,("smb_io_enum_hnd\n"));
112 enh
->ptr_hnd
= (hnd
!= 0) ? 1 : 0;
116 /*******************************************************************
117 Reads or writes an ENUM_HND structure.
118 ********************************************************************/
120 BOOL
smb_io_enum_hnd(char *desc
, ENUM_HND
*hnd
, prs_struct
*ps
, int depth
)
125 prs_debug(ps
, depth
, desc
, "smb_io_enum_hnd");
131 if(!prs_uint32("ptr_hnd", ps
, depth
, &hnd
->ptr_hnd
)) /* pointer */
134 if (hnd
->ptr_hnd
!= 0) {
135 if(!prs_uint32("handle ", ps
, depth
, &hnd
->handle
)) /* enum handle */
142 /*******************************************************************
143 Reads or writes a DOM_SID structure.
144 ********************************************************************/
146 BOOL
smb_io_dom_sid(char *desc
, DOM_SID
*sid
, prs_struct
*ps
, int depth
)
153 prs_debug(ps
, depth
, desc
, "smb_io_dom_sid");
159 if(!prs_uint8 ("sid_rev_num", ps
, depth
, &sid
->sid_rev_num
))
161 if(!prs_uint8 ("num_auths ", ps
, depth
, &sid
->num_auths
))
164 for (i
= 0; i
< 6; i
++)
167 slprintf(tmp
, sizeof(tmp
) - 1, "id_auth[%d] ", i
);
168 if(!prs_uint8 (tmp
, ps
, depth
, &sid
->id_auth
[i
]))
172 /* oops! XXXX should really issue a warning here... */
173 if (sid
->num_auths
> MAXSUBAUTHS
)
174 sid
->num_auths
= MAXSUBAUTHS
;
176 if(!prs_uint32s(False
, "sub_auths ", ps
, depth
, sid
->sub_auths
, sid
->num_auths
))
182 /*******************************************************************
183 Inits a DOM_SID structure.
185 BIG NOTE: this function only does SIDS where the identauth is not >= 2^32
186 identauth >= 2^32 can be detected because it will be specified in hex
187 ********************************************************************/
189 void init_dom_sid(DOM_SID
*sid
, char *str_sid
)
197 DEBUG(4,("netlogon domain SID: none\n"));
198 sid
->sid_rev_num
= 0;
203 pstrcpy(domsid
, str_sid
);
205 DEBUG(4,("init_dom_sid %d SID: %s\n", __LINE__
, domsid
));
207 /* assume, but should check, that domsid starts "S-" */
208 p
= strtok(domsid
+2,"-");
209 sid
->sid_rev_num
= atoi(p
);
211 /* identauth in decimal should be < 2^32 */
212 /* identauth in hex should be >= 2^32 */
213 identauth
= atoi(strtok(0,"-"));
215 DEBUG(4,("netlogon rev %d\n", sid
->sid_rev_num
));
216 DEBUG(4,("netlogon %s ia %d\n", p
, identauth
));
220 sid
->id_auth
[2] = (identauth
& 0xff000000) >> 24;
221 sid
->id_auth
[3] = (identauth
& 0x00ff0000) >> 16;
222 sid
->id_auth
[4] = (identauth
& 0x0000ff00) >> 8;
223 sid
->id_auth
[5] = (identauth
& 0x000000ff);
227 while ((p
= strtok(0, "-")) != NULL
&& sid
->num_auths
< MAXSUBAUTHS
)
228 sid
->sub_auths
[sid
->num_auths
++] = atoi(p
);
230 DEBUG(4,("init_dom_sid: %d SID: %s\n", __LINE__
, domsid
));
233 /*******************************************************************
234 Inits a DOM_SID2 structure.
235 ********************************************************************/
237 void init_dom_sid2(DOM_SID2
*sid2
, DOM_SID
*sid
)
240 sid2
->num_auths
= sid2
->sid
.num_auths
;
243 /*******************************************************************
244 Reads or writes a DOM_SID2 structure.
245 ********************************************************************/
247 BOOL
smb_io_dom_sid2(char *desc
, DOM_SID2
*sid
, prs_struct
*ps
, int depth
)
252 prs_debug(ps
, depth
, desc
, "smb_io_dom_sid2");
258 if(!prs_uint32("num_auths", ps
, depth
, &sid
->num_auths
))
261 if(!smb_io_dom_sid("sid", &sid
->sid
, ps
, depth
))
267 /*******************************************************************
268 creates a STRHDR structure.
269 ********************************************************************/
271 void init_str_hdr(STRHDR
*hdr
, int max_len
, int len
, uint32 buffer
)
273 hdr
->str_max_len
= max_len
;
274 hdr
->str_str_len
= len
;
275 hdr
->buffer
= buffer
;
278 /*******************************************************************
279 Reads or writes a STRHDR structure.
280 ********************************************************************/
282 BOOL
smb_io_strhdr(char *desc
, STRHDR
*hdr
, prs_struct
*ps
, int depth
)
287 prs_debug(ps
, depth
, desc
, "smb_io_strhdr");
292 if(!prs_uint16("str_str_len", ps
, depth
, &hdr
->str_str_len
))
294 if(!prs_uint16("str_max_len", ps
, depth
, &hdr
->str_max_len
))
296 if(!prs_uint32("buffer ", ps
, depth
, &hdr
->buffer
))
299 /* oops! XXXX maybe issue a warning that this is happening... */
300 if (hdr
->str_max_len
> MAX_STRINGLEN
)
301 hdr
->str_max_len
= MAX_STRINGLEN
;
302 if (hdr
->str_str_len
> MAX_STRINGLEN
)
303 hdr
->str_str_len
= MAX_STRINGLEN
;
308 /*******************************************************************
309 Inits a UNIHDR structure.
310 ********************************************************************/
312 void init_uni_hdr(UNIHDR
*hdr
, int len
)
314 hdr
->uni_str_len
= 2 * len
;
315 hdr
->uni_max_len
= 2 * len
;
316 hdr
->buffer
= len
!= 0 ? 1 : 0;
319 /*******************************************************************
320 Reads or writes a UNIHDR structure.
321 ********************************************************************/
323 BOOL
smb_io_unihdr(char *desc
, UNIHDR
*hdr
, prs_struct
*ps
, int depth
)
328 prs_debug(ps
, depth
, desc
, "smb_io_unihdr");
334 if(!prs_uint16("uni_str_len", ps
, depth
, &hdr
->uni_str_len
))
336 if(!prs_uint16("uni_max_len", ps
, depth
, &hdr
->uni_max_len
))
338 if(!prs_uint32("buffer ", ps
, depth
, &hdr
->buffer
))
341 /* oops! XXXX maybe issue a warning that this is happening... */
342 if (hdr
->uni_max_len
> MAX_UNISTRLEN
)
343 hdr
->uni_max_len
= MAX_UNISTRLEN
;
344 if (hdr
->uni_str_len
> MAX_UNISTRLEN
)
345 hdr
->uni_str_len
= MAX_UNISTRLEN
;
350 /*******************************************************************
351 Inits a BUFHDR structure.
352 ********************************************************************/
354 void init_buf_hdr(BUFHDR
*hdr
, int max_len
, int len
)
356 hdr
->buf_max_len
= max_len
;
360 /*******************************************************************
361 prs_uint16 wrapper. Call this and it sets up a pointer to where the
362 uint16 should be stored, or gets the size if reading.
363 ********************************************************************/
365 BOOL
smb_io_hdrbuf_pre(char *desc
, BUFHDR
*hdr
, prs_struct
*ps
, int depth
, uint32
*offset
)
367 (*offset
) = prs_offset(ps
);
372 if(!smb_io_hdrbuf(desc
, hdr
, ps
, depth
))
379 if(!prs_set_offset(ps
, prs_offset(ps
) + (sizeof(uint32
) * 2)))
386 /*******************************************************************
387 smb_io_hdrbuf wrapper. Call this and it retrospectively stores the size.
388 Does nothing on reading, as that is already handled by ...._pre()
389 ********************************************************************/
391 BOOL
smb_io_hdrbuf_post(char *desc
, BUFHDR
*hdr
, prs_struct
*ps
, int depth
,
392 uint32 ptr_hdrbuf
, uint32 max_len
, uint32 len
)
395 /* writing: go back and do a retrospective job. i hate this */
397 uint32 old_offset
= prs_offset(ps
);
399 init_buf_hdr(hdr
, max_len
, len
);
400 if(!prs_set_offset(ps
, ptr_hdrbuf
))
402 if(!smb_io_hdrbuf(desc
, hdr
, ps
, depth
))
405 if(!prs_set_offset(ps
, old_offset
))
412 /*******************************************************************
413 Reads or writes a BUFHDR structure.
414 ********************************************************************/
416 BOOL
smb_io_hdrbuf(char *desc
, BUFHDR
*hdr
, prs_struct
*ps
, int depth
)
421 prs_debug(ps
, depth
, desc
, "smb_io_hdrbuf");
427 if(!prs_uint32("buf_max_len", ps
, depth
, &hdr
->buf_max_len
))
429 if(!prs_uint32("buf_len ", ps
, depth
, &hdr
->buf_len
))
432 /* oops! XXXX maybe issue a warning that this is happening... */
433 if (hdr
->buf_max_len
> MAX_BUFFERLEN
)
434 hdr
->buf_max_len
= MAX_BUFFERLEN
;
435 if (hdr
->buf_len
> MAX_BUFFERLEN
)
436 hdr
->buf_len
= MAX_BUFFERLEN
;
441 /*******************************************************************
442 creates a UNIHDR2 structure.
443 ********************************************************************/
445 void init_uni_hdr2(UNIHDR2
*hdr
, int len
)
447 init_uni_hdr(&hdr
->unihdr
, len
);
448 hdr
->buffer
= (len
> 0) ? 1 : 0;
451 /*******************************************************************
452 Reads or writes a UNIHDR2 structure.
453 ********************************************************************/
455 BOOL
smb_io_unihdr2(char *desc
, UNIHDR2
*hdr2
, prs_struct
*ps
, int depth
)
460 prs_debug(ps
, depth
, desc
, "smb_io_unihdr2");
466 if(!smb_io_unihdr("hdr", &hdr2
->unihdr
, ps
, depth
))
468 if(!prs_uint32("buffer", ps
, depth
, &hdr2
->buffer
))
474 /*******************************************************************
475 Inits a UNISTR structure.
476 ********************************************************************/
478 void init_unistr(UNISTR
*str
, const char *buf
)
480 /* store the string (null-terminated copy) */
481 dos_struni2((char *)str
->buffer
, buf
, sizeof(str
->buffer
));
484 /*******************************************************************
485 reads or writes a UNISTR structure.
486 XXXX NOTE: UNISTR structures NEED to be null-terminated.
487 ********************************************************************/
489 BOOL
smb_io_unistr(char *desc
, UNISTR
*uni
, prs_struct
*ps
, int depth
)
494 prs_debug(ps
, depth
, desc
, "smb_io_unistr");
499 if(!prs_unistr("unistr", ps
, depth
, uni
))
505 /*******************************************************************
506 Inits a BUFFER3 structure from a uint32
507 ********************************************************************/
509 void init_buffer3_uint32(BUFFER3
*str
, uint32 val
)
513 /* set up string lengths. */
514 str
->buf_max_len
= sizeof(uint32
);
515 str
->buf_len
= sizeof(uint32
);
517 SIVAL(str
->buffer
, 0, val
);
520 /*******************************************************************
521 Inits a BUFFER3 structure.
522 ********************************************************************/
524 void init_buffer3_str(BUFFER3
*str
, char *buf
, int len
)
528 /* set up string lengths. */
529 str
->buf_max_len
= len
* 2;
530 str
->buf_len
= len
* 2;
532 /* store the string (null-terminated 8 bit chars into 16 bit chars) */
533 dos_struni2((char *)str
->buffer
, buf
, sizeof(str
->buffer
));
536 /*******************************************************************
537 Inits a BUFFER3 structure from a hex string.
538 ********************************************************************/
540 void init_buffer3_hex(BUFFER3
*str
, char *buf
)
543 str
->buf_max_len
= str
->buf_len
= strhex_to_str((char *)str
->buffer
, sizeof(str
->buffer
), buf
);
546 /*******************************************************************
547 Inits a BUFFER3 structure.
548 ********************************************************************/
550 void init_buffer3_bytes(BUFFER3
*str
, uint8
*buf
, int len
)
554 /* max buffer size (allocated size) */
555 str
->buf_max_len
= len
;
557 memcpy(str
->buffer
, buf
, MIN(str
->buf_len
, sizeof(str
->buffer
)));
558 str
->buf_len
= buf
!= NULL
? len
: 0;
561 /*******************************************************************
562 Reads or writes a BUFFER3 structure.
563 the uni_max_len member tells you how large the buffer is.
564 the uni_str_len member tells you how much of the buffer is really used.
565 ********************************************************************/
567 BOOL
smb_io_buffer3(char *desc
, BUFFER3
*buf3
, prs_struct
*ps
, int depth
)
572 prs_debug(ps
, depth
, desc
, "smb_io_buffer3");
578 if(!prs_uint32("uni_max_len", ps
, depth
, &buf3
->buf_max_len
))
581 if (buf3
->buf_max_len
> MAX_UNISTRLEN
)
582 buf3
->buf_max_len
= MAX_UNISTRLEN
;
584 if(!prs_uint8s(True
, "buffer ", ps
, depth
, buf3
->buffer
, buf3
->buf_max_len
))
587 if(!prs_uint32("buf_len ", ps
, depth
, &buf3
->buf_len
))
589 if (buf3
->buf_len
> MAX_UNISTRLEN
)
590 buf3
->buf_len
= MAX_UNISTRLEN
;
595 /*******************************************************************
596 reads or writes a BUFFER5 structure.
597 the buf_len member tells you how large the buffer is.
598 ********************************************************************/
599 BOOL
smb_io_buffer5(char *desc
, BUFFER5
*buf5
, prs_struct
*ps
, int depth
)
601 prs_debug(ps
, depth
, desc
, "smb_io_buffer5");
604 if (buf5
== NULL
) return False
;
607 prs_uint32("buf_len", ps
, depth
, &(buf5
->buf_len
));
609 /* reading: alloc the buffer first */
612 buf5
->buffer
=(uint16
*)malloc( sizeof(uint16
)*buf5
->buf_len
);
615 prs_uint16s(True
, "buffer", ps
, depth
, buf5
->buffer
, buf5
->buf_len
);
620 /*******************************************************************
621 Frees a BUFFER5 structure (just the malloced part).
622 ********************************************************************/
624 void free_buffer5(BUFFER5
*buf5
)
626 safe_free(buf5
->buffer
);
629 /*******************************************************************
630 Inits a BUFFER2 structure.
631 ********************************************************************/
633 void init_buffer2(BUFFER2
*str
, uint8
*buf
, int len
)
637 /* max buffer size (allocated size) */
638 str
->buf_max_len
= len
;
640 str
->buf_len
= buf
!= NULL
? len
: 0;
643 memcpy(str
->buffer
, buf
, MIN(str
->buf_len
, sizeof(str
->buffer
)));
646 /*******************************************************************
647 Reads or writes a BUFFER2 structure.
648 the uni_max_len member tells you how large the buffer is.
649 the uni_str_len member tells you how much of the buffer is really used.
650 ********************************************************************/
652 BOOL
smb_io_buffer2(char *desc
, BUFFER2
*buf2
, uint32 buffer
, prs_struct
*ps
, int depth
)
659 prs_debug(ps
, depth
, desc
, "smb_io_buffer2");
665 if(!prs_uint32("uni_max_len", ps
, depth
, &buf2
->buf_max_len
))
667 if(!prs_uint32("undoc ", ps
, depth
, &buf2
->undoc
))
669 if(!prs_uint32("buf_len ", ps
, depth
, &buf2
->buf_len
))
672 /* oops! XXXX maybe issue a warning that this is happening... */
673 if (buf2
->buf_max_len
> MAX_UNISTRLEN
)
674 buf2
->buf_max_len
= MAX_UNISTRLEN
;
675 if (buf2
->buf_len
> MAX_UNISTRLEN
)
676 buf2
->buf_len
= MAX_UNISTRLEN
;
678 /* buffer advanced by indicated length of string
679 NOT by searching for null-termination */
681 if(!prs_buffer2(True
, "buffer ", ps
, depth
, buf2
))
686 prs_debug(ps
, depth
, desc
, "smb_io_buffer2 - NULL");
688 memset((char *)buf2
, '\0', sizeof(*buf2
));
694 /*******************************************************************
695 creates a UNISTR2 structure: sets up the buffer, too
696 ********************************************************************/
698 void init_buf_unistr2(UNISTR2
*str
, uint32
*ptr
, const char *buf
)
703 init_unistr2(str
, buf
, strlen(buf
)+1);
708 init_unistr2(str
, "", 0);
713 /*******************************************************************
714 Copies a UNISTR2 structure.
715 ********************************************************************/
717 void copy_unistr2(UNISTR2
*str
, UNISTR2
*from
)
719 /* set up string lengths. add one if string is not null-terminated */
720 str
->uni_max_len
= from
->uni_max_len
;
721 str
->undoc
= from
->undoc
;
722 str
->uni_str_len
= from
->uni_str_len
;
724 /* copy the string */
725 memcpy(str
->buffer
, from
->buffer
, sizeof(from
->buffer
));
728 /*******************************************************************
729 Creates a STRING2 structure.
730 ********************************************************************/
732 void init_string2(STRING2
*str
, char *buf
, int len
)
734 /* set up string lengths. */
735 str
->str_max_len
= len
;
737 str
->str_str_len
= len
;
739 /* store the string */
741 memcpy(str
->buffer
, buf
, len
);
744 /*******************************************************************
745 Reads or writes a STRING2 structure.
746 XXXX NOTE: STRING2 structures need NOT be null-terminated.
747 the str_str_len member tells you how long the string is;
748 the str_max_len member tells you how large the buffer is.
749 ********************************************************************/
751 BOOL
smb_io_string2(char *desc
, STRING2
*str2
, uint32 buffer
, prs_struct
*ps
, int depth
)
758 prs_debug(ps
, depth
, desc
, "smb_io_string2");
764 if(!prs_uint32("str_max_len", ps
, depth
, &str2
->str_max_len
))
766 if(!prs_uint32("undoc ", ps
, depth
, &str2
->undoc
))
768 if(!prs_uint32("str_str_len", ps
, depth
, &str2
->str_str_len
))
771 /* oops! XXXX maybe issue a warning that this is happening... */
772 if (str2
->str_max_len
> MAX_STRINGLEN
)
773 str2
->str_max_len
= MAX_STRINGLEN
;
774 if (str2
->str_str_len
> MAX_STRINGLEN
)
775 str2
->str_str_len
= MAX_STRINGLEN
;
777 /* buffer advanced by indicated length of string
778 NOT by searching for null-termination */
779 if(!prs_string2(True
, "buffer ", ps
, depth
, str2
))
784 prs_debug(ps
, depth
, desc
, "smb_io_string2 - NULL");
786 memset((char *)str2
, '\0', sizeof(*str2
));
793 /*******************************************************************
794 Inits a UNISTR2 structure.
795 ********************************************************************/
797 void init_unistr2(UNISTR2
*str
, const char *buf
, size_t len
)
801 /* set up string lengths. */
802 str
->uni_max_len
= (uint32
)len
;
804 str
->uni_str_len
= (uint32
)len
;
806 /* store the string (null-terminated 8 bit chars into 16 bit chars) */
807 dos_struni2((char *)str
->buffer
, buf
, sizeof(str
->buffer
));
810 /*******************************************************************
811 Reads or writes a UNISTR2 structure.
812 XXXX NOTE: UNISTR2 structures need NOT be null-terminated.
813 the uni_str_len member tells you how long the string is;
814 the uni_max_len member tells you how large the buffer is.
815 ********************************************************************/
817 BOOL
smb_io_unistr2(char *desc
, UNISTR2
*uni2
, uint32 buffer
, prs_struct
*ps
, int depth
)
824 prs_debug(ps
, depth
, desc
, "smb_io_unistr2");
830 if(!prs_uint32("uni_max_len", ps
, depth
, &uni2
->uni_max_len
))
832 if(!prs_uint32("undoc ", ps
, depth
, &uni2
->undoc
))
834 if(!prs_uint32("uni_str_len", ps
, depth
, &uni2
->uni_str_len
))
837 /* oops! XXXX maybe issue a warning that this is happening... */
838 if (uni2
->uni_max_len
> MAX_UNISTRLEN
)
839 uni2
->uni_max_len
= MAX_UNISTRLEN
;
840 if (uni2
->uni_str_len
> MAX_UNISTRLEN
)
841 uni2
->uni_str_len
= MAX_UNISTRLEN
;
843 /* buffer advanced by indicated length of string
844 NOT by searching for null-termination */
845 if(!prs_unistr2(True
, "buffer ", ps
, depth
, uni2
))
850 prs_debug(ps
, depth
, desc
, "smb_io_unistr2 - NULL");
852 memset((char *)uni2
, '\0', sizeof(*uni2
));
859 /*******************************************************************
860 Inits a DOM_RID2 structure.
861 ********************************************************************/
863 void init_dom_rid2(DOM_RID2
*rid2
, uint32 rid
, uint8 type
, uint32 idx
)
870 /*******************************************************************
871 Reads or writes a DOM_RID2 structure.
872 ********************************************************************/
874 BOOL
smb_io_dom_rid2(char *desc
, DOM_RID2
*rid2
, prs_struct
*ps
, int depth
)
879 prs_debug(ps
, depth
, desc
, "smb_io_dom_rid2");
885 if(!prs_uint8("type ", ps
, depth
, &rid2
->type
))
889 if(!prs_uint32("rid ", ps
, depth
, &rid2
->rid
))
891 if(!prs_uint32("rid_idx", ps
, depth
, &rid2
->rid_idx
))
897 /*******************************************************************
898 creates a DOM_RID3 structure.
899 ********************************************************************/
901 void init_dom_rid3(DOM_RID3
*rid3
, uint32 rid
, uint8 type
)
905 rid3
->ptr_type
= 0x1; /* non-zero, basically. */
910 /*******************************************************************
911 reads or writes a DOM_RID3 structure.
912 ********************************************************************/
914 BOOL
smb_io_dom_rid3(char *desc
, DOM_RID3
*rid3
, prs_struct
*ps
, int depth
)
919 prs_debug(ps
, depth
, desc
, "smb_io_dom_rid3");
925 if(!prs_uint32("rid ", ps
, depth
, &rid3
->rid
))
927 if(!prs_uint32("type1 ", ps
, depth
, &rid3
->type1
))
929 if(!prs_uint32("ptr_type", ps
, depth
, &rid3
->ptr_type
))
931 if(!prs_uint32("type2 ", ps
, depth
, &rid3
->type2
))
933 if(!prs_uint32("unk ", ps
, depth
, &rid3
->unk
))
939 /*******************************************************************
940 Inits a DOM_RID4 structure.
941 ********************************************************************/
943 void init_dom_rid4(DOM_RID4
*rid4
, uint16 unknown
, uint16 attr
, uint32 rid
)
945 rid4
->unknown
= unknown
;
950 /*******************************************************************
951 Inits a DOM_CLNT_SRV structure.
952 ********************************************************************/
954 static void init_clnt_srv(DOM_CLNT_SRV
*log
, char *logon_srv
, char *comp_name
)
956 DEBUG(5,("init_clnt_srv: %d\n", __LINE__
));
958 if (logon_srv
!= NULL
) {
959 log
->undoc_buffer
= 1;
960 init_unistr2(&(log
->uni_logon_srv
), logon_srv
, strlen(logon_srv
)+1);
962 log
->undoc_buffer
= 0;
965 if (comp_name
!= NULL
) {
966 log
->undoc_buffer2
= 1;
967 init_unistr2(&(log
->uni_comp_name
), comp_name
, strlen(comp_name
)+1);
969 log
->undoc_buffer2
= 0;
973 /*******************************************************************
974 Inits or writes a DOM_CLNT_SRV structure.
975 ********************************************************************/
977 static BOOL
smb_io_clnt_srv(char *desc
, DOM_CLNT_SRV
*log
, prs_struct
*ps
, int depth
)
982 prs_debug(ps
, depth
, desc
, "smb_io_clnt_srv");
988 if(!prs_uint32("undoc_buffer ", ps
, depth
, &log
->undoc_buffer
))
991 if (log
->undoc_buffer
!= 0) {
992 if(!smb_io_unistr2("unistr2", &log
->uni_logon_srv
, log
->undoc_buffer
, ps
, depth
))
999 if(!prs_uint32("undoc_buffer2", ps
, depth
, &log
->undoc_buffer2
))
1002 if (log
->undoc_buffer2
!= 0) {
1003 if(!smb_io_unistr2("unistr2", &log
->uni_comp_name
, log
->undoc_buffer2
, ps
, depth
))
1010 /*******************************************************************
1011 Inits a DOM_LOG_INFO structure.
1012 ********************************************************************/
1014 void init_log_info(DOM_LOG_INFO
*log
, char *logon_srv
, char *acct_name
,
1015 uint16 sec_chan
, char *comp_name
)
1017 DEBUG(5,("make_log_info %d\n", __LINE__
));
1019 log
->undoc_buffer
= 1;
1021 init_unistr2(&log
->uni_logon_srv
, logon_srv
, strlen(logon_srv
)+1);
1022 init_unistr2(&log
->uni_acct_name
, acct_name
, strlen(acct_name
)+1);
1024 log
->sec_chan
= sec_chan
;
1026 init_unistr2(&log
->uni_comp_name
, comp_name
, strlen(comp_name
)+1);
1029 /*******************************************************************
1030 Reads or writes a DOM_LOG_INFO structure.
1031 ********************************************************************/
1033 BOOL
smb_io_log_info(char *desc
, DOM_LOG_INFO
*log
, prs_struct
*ps
, int depth
)
1038 prs_debug(ps
, depth
, desc
, "smb_io_log_info");
1044 if(!prs_uint32("undoc_buffer", ps
, depth
, &log
->undoc_buffer
))
1047 if(!smb_io_unistr2("unistr2", &log
->uni_logon_srv
, True
, ps
, depth
))
1049 if(!smb_io_unistr2("unistr2", &log
->uni_acct_name
, True
, ps
, depth
))
1052 if(!prs_uint16("sec_chan", ps
, depth
, &log
->sec_chan
))
1055 if(!smb_io_unistr2("unistr2", &log
->uni_comp_name
, True
, ps
, depth
))
1061 /*******************************************************************
1062 Reads or writes a DOM_CHAL structure.
1063 ********************************************************************/
1065 BOOL
smb_io_chal(char *desc
, DOM_CHAL
*chal
, prs_struct
*ps
, int depth
)
1070 prs_debug(ps
, depth
, desc
, "smb_io_chal");
1076 if(!prs_uint8s (False
, "data", ps
, depth
, chal
->data
, 8))
1082 /*******************************************************************
1083 Reads or writes a DOM_CRED structure.
1084 ********************************************************************/
1086 BOOL
smb_io_cred(char *desc
, DOM_CRED
*cred
, prs_struct
*ps
, int depth
)
1091 prs_debug(ps
, depth
, desc
, "smb_io_cred");
1097 if(!smb_io_chal ("", &cred
->challenge
, ps
, depth
))
1099 if(!smb_io_utime("", &cred
->timestamp
, ps
, depth
))
1105 /*******************************************************************
1106 Inits a DOM_CLNT_INFO2 structure.
1107 ********************************************************************/
1109 void init_clnt_info2(DOM_CLNT_INFO2
*clnt
,
1110 char *logon_srv
, char *comp_name
,
1111 DOM_CRED
*clnt_cred
)
1113 DEBUG(5,("make_clnt_info: %d\n", __LINE__
));
1115 init_clnt_srv(&(clnt
->login
), logon_srv
, comp_name
);
1117 if (clnt_cred
!= NULL
) {
1119 memcpy(&(clnt
->cred
), clnt_cred
, sizeof(clnt
->cred
));
1125 /*******************************************************************
1126 Reads or writes a DOM_CLNT_INFO2 structure.
1127 ********************************************************************/
1129 BOOL
smb_io_clnt_info2(char *desc
, DOM_CLNT_INFO2
*clnt
, prs_struct
*ps
, int depth
)
1134 prs_debug(ps
, depth
, desc
, "smb_io_clnt_info2");
1140 if(!smb_io_clnt_srv("", &clnt
->login
, ps
, depth
))
1146 if(!prs_uint32("ptr_cred", ps
, depth
, &clnt
->ptr_cred
))
1148 if(!smb_io_cred("", &clnt
->cred
, ps
, depth
))
1154 /*******************************************************************
1155 Inits a DOM_CLNT_INFO structure.
1156 ********************************************************************/
1158 void init_clnt_info(DOM_CLNT_INFO
*clnt
,
1159 char *logon_srv
, char *acct_name
,
1160 uint16 sec_chan
, char *comp_name
,
1163 DEBUG(5,("make_clnt_info\n"));
1165 init_log_info(&clnt
->login
, logon_srv
, acct_name
, sec_chan
, comp_name
);
1166 memcpy(&clnt
->cred
, cred
, sizeof(clnt
->cred
));
1169 /*******************************************************************
1170 Reads or writes a DOM_CLNT_INFO structure.
1171 ********************************************************************/
1173 BOOL
smb_io_clnt_info(char *desc
, DOM_CLNT_INFO
*clnt
, prs_struct
*ps
, int depth
)
1178 prs_debug(ps
, depth
, desc
, "smb_io_clnt_info");
1184 if(!smb_io_log_info("", &clnt
->login
, ps
, depth
))
1186 if(!smb_io_cred("", &clnt
->cred
, ps
, depth
))
1192 /*******************************************************************
1193 Inits a DOM_LOGON_ID structure.
1194 ********************************************************************/
1196 void init_logon_id(DOM_LOGON_ID
*log
, uint32 log_id_low
, uint32 log_id_high
)
1198 DEBUG(5,("make_logon_id: %d\n", __LINE__
));
1200 log
->low
= log_id_low
;
1201 log
->high
= log_id_high
;
1204 /*******************************************************************
1205 Reads or writes a DOM_LOGON_ID structure.
1206 ********************************************************************/
1208 BOOL
smb_io_logon_id(char *desc
, DOM_LOGON_ID
*log
, prs_struct
*ps
, int depth
)
1213 prs_debug(ps
, depth
, desc
, "smb_io_logon_id");
1219 if(!prs_uint32("low ", ps
, depth
, &log
->low
))
1221 if(!prs_uint32("high", ps
, depth
, &log
->high
))
1227 /*******************************************************************
1228 Inits an OWF_INFO structure.
1229 ********************************************************************/
1231 void init_owf_info(OWF_INFO
*hash
, uint8 data
[16])
1233 DEBUG(5,("init_owf_info: %d\n", __LINE__
));
1236 memcpy(hash
->data
, data
, sizeof(hash
->data
));
1238 memset((char *)hash
->data
, '\0', sizeof(hash
->data
));
1241 /*******************************************************************
1242 Reads or writes an OWF_INFO structure.
1243 ********************************************************************/
1245 BOOL
smb_io_owf_info(char *desc
, OWF_INFO
*hash
, prs_struct
*ps
, int depth
)
1250 prs_debug(ps
, depth
, desc
, "smb_io_owf_info");
1256 if(!prs_uint8s (False
, "data", ps
, depth
, hash
->data
, 16))
1262 /*******************************************************************
1263 Reads or writes a DOM_GID structure.
1264 ********************************************************************/
1266 BOOL
smb_io_gid(char *desc
, DOM_GID
*gid
, prs_struct
*ps
, int depth
)
1271 prs_debug(ps
, depth
, desc
, "smb_io_gid");
1277 if(!prs_uint32("g_rid", ps
, depth
, &gid
->g_rid
))
1279 if(!prs_uint32("attr ", ps
, depth
, &gid
->attr
))
1285 /*******************************************************************
1286 Reads or writes an POLICY_HND structure.
1287 ********************************************************************/
1289 BOOL
smb_io_pol_hnd(char *desc
, POLICY_HND
*pol
, prs_struct
*ps
, int depth
)
1294 prs_debug(ps
, depth
, desc
, "smb_io_pol_hnd");
1300 if(!prs_uint8s (False
, "data", ps
, depth
, pol
->data
, POL_HND_SIZE
))
1306 /*******************************************************************
1307 Reads or writes a dom query structure.
1308 ********************************************************************/
1310 static BOOL
smb_io_dom_query(char *desc
, DOM_QUERY
*d_q
, prs_struct
*ps
, int depth
)
1315 prs_debug(ps
, depth
, desc
, "smb_io_dom_query");
1321 if(!prs_uint16("uni_dom_max_len", ps
, depth
, &d_q
->uni_dom_max_len
)) /* domain name string length * 2 */
1323 if(!prs_uint16("uni_dom_str_len", ps
, depth
, &d_q
->uni_dom_str_len
)) /* domain name string length * 2 */
1326 if(!prs_uint32("buffer_dom_name", ps
, depth
, &d_q
->buffer_dom_name
)) /* undocumented domain name string buffer pointer */
1328 if(!prs_uint32("buffer_dom_sid ", ps
, depth
, &d_q
->buffer_dom_sid
)) /* undocumented domain SID string buffer pointer */
1331 if(!smb_io_unistr2("unistr2", &d_q
->uni_domain_name
, d_q
->buffer_dom_name
, ps
, depth
)) /* domain name (unicode string) */
1337 if (d_q
->buffer_dom_sid
!= 0) {
1338 if(!smb_io_dom_sid2("", &d_q
->dom_sid
, ps
, depth
)) /* domain SID */
1341 memset((char *)&d_q
->dom_sid
, '\0', sizeof(d_q
->dom_sid
));
1347 /*******************************************************************
1348 Reads or writes a dom query structure.
1349 ********************************************************************/
1351 BOOL
smb_io_dom_query_3(char *desc
, DOM_QUERY_3
*d_q
, prs_struct
*ps
, int depth
)
1353 return smb_io_dom_query("", d_q
, ps
, depth
);
1356 /*******************************************************************
1357 Reads or writes a dom query structure.
1358 ********************************************************************/
1360 BOOL
smb_io_dom_query_5(char *desc
, DOM_QUERY_3
*d_q
, prs_struct
*ps
, int depth
)
1362 return smb_io_dom_query("", d_q
, ps
, depth
);
1366 /*******************************************************************
1367 Reads or writes a UNISTR3 structure.
1368 ********************************************************************/
1370 BOOL
smb_io_unistr3(char *desc
, UNISTR3
*name
, prs_struct
*ps
, int depth
)
1375 prs_debug(ps
, depth
, desc
, "smb_io_unistr3");
1381 if(!prs_uint32("uni_str_len", ps
, depth
, &name
->uni_str_len
))
1384 /* don't know if len is specified by uni_str_len member... */
1385 /* assume unicode string is unicode-null-terminated, instead */
1387 if(!prs_unistr3(True
, "unistr", name
, ps
, depth
))
1394 /*******************************************************************
1395 Stream a uint64_struct
1396 ********************************************************************/
1397 BOOL
prs_uint64(char *name
, prs_struct
*ps
, int depth
, UINT64_S
*data64
)
1399 return prs_uint32(name
, ps
, depth
+1, &data64
->low
) &&
1400 prs_uint32(name
, ps
, depth
+1, &data64
->high
);