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
, 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 Inits a BUFFER2 structure.
597 ********************************************************************/
599 void init_buffer2(BUFFER2
*str
, uint8
*buf
, int len
)
603 /* max buffer size (allocated size) */
604 str
->buf_max_len
= len
;
606 str
->buf_len
= buf
!= NULL
? len
: 0;
609 memcpy(str
->buffer
, buf
, MIN(str
->buf_len
, sizeof(str
->buffer
)));
612 /*******************************************************************
613 Reads or writes a BUFFER2 structure.
614 the uni_max_len member tells you how large the buffer is.
615 the uni_str_len member tells you how much of the buffer is really used.
616 ********************************************************************/
618 BOOL
smb_io_buffer2(char *desc
, BUFFER2
*buf2
, uint32 buffer
, prs_struct
*ps
, int depth
)
625 prs_debug(ps
, depth
, desc
, "smb_io_buffer2");
631 if(!prs_uint32("uni_max_len", ps
, depth
, &buf2
->buf_max_len
))
633 if(!prs_uint32("undoc ", ps
, depth
, &buf2
->undoc
))
635 if(!prs_uint32("buf_len ", ps
, depth
, &buf2
->buf_len
))
638 /* oops! XXXX maybe issue a warning that this is happening... */
639 if (buf2
->buf_max_len
> MAX_UNISTRLEN
)
640 buf2
->buf_max_len
= MAX_UNISTRLEN
;
641 if (buf2
->buf_len
> MAX_UNISTRLEN
)
642 buf2
->buf_len
= MAX_UNISTRLEN
;
644 /* buffer advanced by indicated length of string
645 NOT by searching for null-termination */
647 if(!prs_buffer2(True
, "buffer ", ps
, depth
, buf2
))
652 prs_debug(ps
, depth
, desc
, "smb_io_buffer2 - NULL");
654 memset((char *)buf2
, '\0', sizeof(*buf2
));
660 /*******************************************************************
661 creates a UNISTR2 structure: sets up the buffer, too
662 ********************************************************************/
664 void init_buf_unistr2(UNISTR2
*str
, uint32
*ptr
, char *buf
)
669 init_unistr2(str
, buf
, strlen(buf
)+1);
674 init_unistr2(str
, "", 0);
679 /*******************************************************************
680 Copies a UNISTR2 structure.
681 ********************************************************************/
683 void copy_unistr2(UNISTR2
*str
, UNISTR2
*from
)
685 /* set up string lengths. add one if string is not null-terminated */
686 str
->uni_max_len
= from
->uni_max_len
;
687 str
->undoc
= from
->undoc
;
688 str
->uni_str_len
= from
->uni_str_len
;
690 /* copy the string */
691 memcpy(str
->buffer
, from
->buffer
, sizeof(from
->buffer
));
694 /*******************************************************************
695 Creates a STRING2 structure.
696 ********************************************************************/
698 void init_string2(STRING2
*str
, char *buf
, int len
)
700 /* set up string lengths. */
701 str
->str_max_len
= len
;
703 str
->str_str_len
= len
;
705 /* store the string */
707 memcpy(str
->buffer
, buf
, len
);
710 /*******************************************************************
711 Reads or writes a STRING2 structure.
712 XXXX NOTE: STRING2 structures need NOT be null-terminated.
713 the str_str_len member tells you how long the string is;
714 the str_max_len member tells you how large the buffer is.
715 ********************************************************************/
717 BOOL
smb_io_string2(char *desc
, STRING2
*str2
, uint32 buffer
, prs_struct
*ps
, int depth
)
724 prs_debug(ps
, depth
, desc
, "smb_io_string2");
730 if(!prs_uint32("str_max_len", ps
, depth
, &str2
->str_max_len
))
732 if(!prs_uint32("undoc ", ps
, depth
, &str2
->undoc
))
734 if(!prs_uint32("str_str_len", ps
, depth
, &str2
->str_str_len
))
737 /* oops! XXXX maybe issue a warning that this is happening... */
738 if (str2
->str_max_len
> MAX_STRINGLEN
)
739 str2
->str_max_len
= MAX_STRINGLEN
;
740 if (str2
->str_str_len
> MAX_STRINGLEN
)
741 str2
->str_str_len
= MAX_STRINGLEN
;
743 /* buffer advanced by indicated length of string
744 NOT by searching for null-termination */
745 if(!prs_string2(True
, "buffer ", ps
, depth
, str2
))
750 prs_debug(ps
, depth
, desc
, "smb_io_string2 - NULL");
752 memset((char *)str2
, '\0', sizeof(*str2
));
759 /*******************************************************************
760 Inits a UNISTR2 structure.
761 ********************************************************************/
763 void init_unistr2(UNISTR2
*str
, char *buf
, int len
)
767 /* set up string lengths. */
768 str
->uni_max_len
= len
;
770 str
->uni_str_len
= len
;
772 /* store the string (null-terminated 8 bit chars into 16 bit chars) */
773 dos_struni2((char *)str
->buffer
, buf
, sizeof(str
->buffer
));
776 /*******************************************************************
777 Reads or writes a UNISTR2 structure.
778 XXXX NOTE: UNISTR2 structures need NOT be null-terminated.
779 the uni_str_len member tells you how long the string is;
780 the uni_max_len member tells you how large the buffer is.
781 ********************************************************************/
783 BOOL
smb_io_unistr2(char *desc
, UNISTR2
*uni2
, uint32 buffer
, prs_struct
*ps
, int depth
)
790 prs_debug(ps
, depth
, desc
, "smb_io_unistr2");
796 if(!prs_uint32("uni_max_len", ps
, depth
, &uni2
->uni_max_len
))
798 if(!prs_uint32("undoc ", ps
, depth
, &uni2
->undoc
))
800 if(!prs_uint32("uni_str_len", ps
, depth
, &uni2
->uni_str_len
))
803 /* oops! XXXX maybe issue a warning that this is happening... */
804 if (uni2
->uni_max_len
> MAX_UNISTRLEN
)
805 uni2
->uni_max_len
= MAX_UNISTRLEN
;
806 if (uni2
->uni_str_len
> MAX_UNISTRLEN
)
807 uni2
->uni_str_len
= MAX_UNISTRLEN
;
809 /* buffer advanced by indicated length of string
810 NOT by searching for null-termination */
811 if(!prs_unistr2(True
, "buffer ", ps
, depth
, uni2
))
816 prs_debug(ps
, depth
, desc
, "smb_io_unistr2 - NULL");
818 memset((char *)uni2
, '\0', sizeof(*uni2
));
825 /*******************************************************************
826 Inits a DOM_RID2 structure.
827 ********************************************************************/
829 void init_dom_rid2(DOM_RID2
*rid2
, uint32 rid
, uint8 type
, uint32 idx
)
836 /*******************************************************************
837 Reads or writes a DOM_RID2 structure.
838 ********************************************************************/
840 BOOL
smb_io_dom_rid2(char *desc
, DOM_RID2
*rid2
, prs_struct
*ps
, int depth
)
845 prs_debug(ps
, depth
, desc
, "smb_io_dom_rid2");
851 if(!prs_uint8("type ", ps
, depth
, &rid2
->type
))
855 if(!prs_uint32("rid ", ps
, depth
, &rid2
->rid
))
857 if(!prs_uint32("rid_idx", ps
, depth
, &rid2
->rid_idx
))
863 /*******************************************************************
864 creates a DOM_RID3 structure.
865 ********************************************************************/
867 void init_dom_rid3(DOM_RID3
*rid3
, uint32 rid
, uint8 type
)
871 rid3
->ptr_type
= 0x1; /* non-zero, basically. */
876 /*******************************************************************
877 reads or writes a DOM_RID3 structure.
878 ********************************************************************/
880 BOOL
smb_io_dom_rid3(char *desc
, DOM_RID3
*rid3
, prs_struct
*ps
, int depth
)
885 prs_debug(ps
, depth
, desc
, "smb_io_dom_rid3");
891 if(!prs_uint32("rid ", ps
, depth
, &rid3
->rid
))
893 if(!prs_uint32("type1 ", ps
, depth
, &rid3
->type1
))
895 if(!prs_uint32("ptr_type", ps
, depth
, &rid3
->ptr_type
))
897 if(!prs_uint32("type2 ", ps
, depth
, &rid3
->type2
))
899 if(!prs_uint32("unk ", ps
, depth
, &rid3
->unk
))
905 /*******************************************************************
906 Inits a DOM_RID4 structure.
907 ********************************************************************/
909 void init_dom_rid4(DOM_RID4
*rid4
, uint16 unknown
, uint16 attr
, uint32 rid
)
911 rid4
->unknown
= unknown
;
916 /*******************************************************************
917 Inits a DOM_CLNT_SRV structure.
918 ********************************************************************/
920 static void init_clnt_srv(DOM_CLNT_SRV
*log
, char *logon_srv
, char *comp_name
)
922 DEBUG(5,("init_clnt_srv: %d\n", __LINE__
));
924 if (logon_srv
!= NULL
) {
925 log
->undoc_buffer
= 1;
926 init_unistr2(&(log
->uni_logon_srv
), logon_srv
, strlen(logon_srv
)+1);
928 log
->undoc_buffer
= 0;
931 if (comp_name
!= NULL
) {
932 log
->undoc_buffer2
= 1;
933 init_unistr2(&(log
->uni_comp_name
), comp_name
, strlen(comp_name
)+1);
935 log
->undoc_buffer2
= 0;
939 /*******************************************************************
940 Inits or writes a DOM_CLNT_SRV structure.
941 ********************************************************************/
943 static BOOL
smb_io_clnt_srv(char *desc
, DOM_CLNT_SRV
*log
, prs_struct
*ps
, int depth
)
948 prs_debug(ps
, depth
, desc
, "smb_io_clnt_srv");
954 if(!prs_uint32("undoc_buffer ", ps
, depth
, &log
->undoc_buffer
))
957 if (log
->undoc_buffer
!= 0) {
958 if(!smb_io_unistr2("unistr2", &log
->uni_logon_srv
, log
->undoc_buffer
, ps
, depth
))
965 if(!prs_uint32("undoc_buffer2", ps
, depth
, &log
->undoc_buffer2
))
968 if (log
->undoc_buffer2
!= 0) {
969 if(!smb_io_unistr2("unistr2", &log
->uni_comp_name
, log
->undoc_buffer2
, ps
, depth
))
976 /*******************************************************************
977 Inits a DOM_LOG_INFO structure.
978 ********************************************************************/
980 void init_log_info(DOM_LOG_INFO
*log
, char *logon_srv
, char *acct_name
,
981 uint16 sec_chan
, char *comp_name
)
983 DEBUG(5,("make_log_info %d\n", __LINE__
));
985 log
->undoc_buffer
= 1;
987 init_unistr2(&log
->uni_logon_srv
, logon_srv
, strlen(logon_srv
)+1);
988 init_unistr2(&log
->uni_acct_name
, acct_name
, strlen(acct_name
)+1);
990 log
->sec_chan
= sec_chan
;
992 init_unistr2(&log
->uni_comp_name
, comp_name
, strlen(comp_name
)+1);
995 /*******************************************************************
996 Reads or writes a DOM_LOG_INFO structure.
997 ********************************************************************/
999 BOOL
smb_io_log_info(char *desc
, DOM_LOG_INFO
*log
, prs_struct
*ps
, int depth
)
1004 prs_debug(ps
, depth
, desc
, "smb_io_log_info");
1010 if(!prs_uint32("undoc_buffer", ps
, depth
, &log
->undoc_buffer
))
1013 if(!smb_io_unistr2("unistr2", &log
->uni_logon_srv
, True
, ps
, depth
))
1015 if(!smb_io_unistr2("unistr2", &log
->uni_acct_name
, True
, ps
, depth
))
1018 if(!prs_uint16("sec_chan", ps
, depth
, &log
->sec_chan
))
1021 if(!smb_io_unistr2("unistr2", &log
->uni_comp_name
, True
, ps
, depth
))
1027 /*******************************************************************
1028 Reads or writes a DOM_CHAL structure.
1029 ********************************************************************/
1031 BOOL
smb_io_chal(char *desc
, DOM_CHAL
*chal
, prs_struct
*ps
, int depth
)
1036 prs_debug(ps
, depth
, desc
, "smb_io_chal");
1042 if(!prs_uint8s (False
, "data", ps
, depth
, chal
->data
, 8))
1048 /*******************************************************************
1049 Reads or writes a DOM_CRED structure.
1050 ********************************************************************/
1052 BOOL
smb_io_cred(char *desc
, DOM_CRED
*cred
, prs_struct
*ps
, int depth
)
1057 prs_debug(ps
, depth
, desc
, "smb_io_cred");
1063 if(!smb_io_chal ("", &cred
->challenge
, ps
, depth
))
1065 if(!smb_io_utime("", &cred
->timestamp
, ps
, depth
))
1071 /*******************************************************************
1072 Inits a DOM_CLNT_INFO2 structure.
1073 ********************************************************************/
1075 void init_clnt_info2(DOM_CLNT_INFO2
*clnt
,
1076 char *logon_srv
, char *comp_name
,
1077 DOM_CRED
*clnt_cred
)
1079 DEBUG(5,("make_clnt_info: %d\n", __LINE__
));
1081 init_clnt_srv(&(clnt
->login
), logon_srv
, comp_name
);
1083 if (clnt_cred
!= NULL
) {
1085 memcpy(&(clnt
->cred
), clnt_cred
, sizeof(clnt
->cred
));
1091 /*******************************************************************
1092 Reads or writes a DOM_CLNT_INFO2 structure.
1093 ********************************************************************/
1095 BOOL
smb_io_clnt_info2(char *desc
, DOM_CLNT_INFO2
*clnt
, prs_struct
*ps
, int depth
)
1100 prs_debug(ps
, depth
, desc
, "smb_io_clnt_info2");
1106 if(!smb_io_clnt_srv("", &clnt
->login
, ps
, depth
))
1112 if(!prs_uint32("ptr_cred", ps
, depth
, &clnt
->ptr_cred
))
1114 if(!smb_io_cred("", &clnt
->cred
, ps
, depth
))
1120 /*******************************************************************
1121 Inits a DOM_CLNT_INFO structure.
1122 ********************************************************************/
1124 void init_clnt_info(DOM_CLNT_INFO
*clnt
,
1125 char *logon_srv
, char *acct_name
,
1126 uint16 sec_chan
, char *comp_name
,
1129 DEBUG(5,("make_clnt_info\n"));
1131 init_log_info(&clnt
->login
, logon_srv
, acct_name
, sec_chan
, comp_name
);
1132 memcpy(&clnt
->cred
, cred
, sizeof(clnt
->cred
));
1135 /*******************************************************************
1136 Reads or writes a DOM_CLNT_INFO structure.
1137 ********************************************************************/
1139 BOOL
smb_io_clnt_info(char *desc
, DOM_CLNT_INFO
*clnt
, prs_struct
*ps
, int depth
)
1144 prs_debug(ps
, depth
, desc
, "smb_io_clnt_info");
1150 if(!smb_io_log_info("", &clnt
->login
, ps
, depth
))
1152 if(!smb_io_cred("", &clnt
->cred
, ps
, depth
))
1158 /*******************************************************************
1159 Inits a DOM_LOGON_ID structure.
1160 ********************************************************************/
1162 void init_logon_id(DOM_LOGON_ID
*log
, uint32 log_id_low
, uint32 log_id_high
)
1164 DEBUG(5,("make_logon_id: %d\n", __LINE__
));
1166 log
->low
= log_id_low
;
1167 log
->high
= log_id_high
;
1170 /*******************************************************************
1171 Reads or writes a DOM_LOGON_ID structure.
1172 ********************************************************************/
1174 BOOL
smb_io_logon_id(char *desc
, DOM_LOGON_ID
*log
, prs_struct
*ps
, int depth
)
1179 prs_debug(ps
, depth
, desc
, "smb_io_logon_id");
1185 if(!prs_uint32("low ", ps
, depth
, &log
->low
))
1187 if(!prs_uint32("high", ps
, depth
, &log
->high
))
1193 /*******************************************************************
1194 Inits an OWF_INFO structure.
1195 ********************************************************************/
1197 void init_owf_info(OWF_INFO
*hash
, uint8 data
[16])
1199 DEBUG(5,("init_owf_info: %d\n", __LINE__
));
1202 memcpy(hash
->data
, data
, sizeof(hash
->data
));
1204 memset((char *)hash
->data
, '\0', sizeof(hash
->data
));
1207 /*******************************************************************
1208 Reads or writes an OWF_INFO structure.
1209 ********************************************************************/
1211 BOOL
smb_io_owf_info(char *desc
, OWF_INFO
*hash
, prs_struct
*ps
, int depth
)
1216 prs_debug(ps
, depth
, desc
, "smb_io_owf_info");
1222 if(!prs_uint8s (False
, "data", ps
, depth
, hash
->data
, 16))
1228 /*******************************************************************
1229 Reads or writes a DOM_GID structure.
1230 ********************************************************************/
1232 BOOL
smb_io_gid(char *desc
, DOM_GID
*gid
, prs_struct
*ps
, int depth
)
1237 prs_debug(ps
, depth
, desc
, "smb_io_gid");
1243 if(!prs_uint32("g_rid", ps
, depth
, &gid
->g_rid
))
1245 if(!prs_uint32("attr ", ps
, depth
, &gid
->attr
))
1251 /*******************************************************************
1252 Reads or writes an POLICY_HND structure.
1253 ********************************************************************/
1255 BOOL
smb_io_pol_hnd(char *desc
, POLICY_HND
*pol
, prs_struct
*ps
, int depth
)
1260 prs_debug(ps
, depth
, desc
, "smb_io_pol_hnd");
1266 if(!prs_uint8s (False
, "data", ps
, depth
, pol
->data
, POL_HND_SIZE
))
1272 /*******************************************************************
1273 Reads or writes a dom query structure.
1274 ********************************************************************/
1276 static BOOL
smb_io_dom_query(char *desc
, DOM_QUERY
*d_q
, prs_struct
*ps
, int depth
)
1281 prs_debug(ps
, depth
, desc
, "smb_io_dom_query");
1287 if(!prs_uint16("uni_dom_max_len", ps
, depth
, &d_q
->uni_dom_max_len
)) /* domain name string length * 2 */
1289 if(!prs_uint16("uni_dom_str_len", ps
, depth
, &d_q
->uni_dom_str_len
)) /* domain name string length * 2 */
1292 if(!prs_uint32("buffer_dom_name", ps
, depth
, &d_q
->buffer_dom_name
)) /* undocumented domain name string buffer pointer */
1294 if(!prs_uint32("buffer_dom_sid ", ps
, depth
, &d_q
->buffer_dom_sid
)) /* undocumented domain SID string buffer pointer */
1297 if(!smb_io_unistr2("unistr2", &d_q
->uni_domain_name
, d_q
->buffer_dom_name
, ps
, depth
)) /* domain name (unicode string) */
1303 if (d_q
->buffer_dom_sid
!= 0) {
1304 if(!smb_io_dom_sid2("", &d_q
->dom_sid
, ps
, depth
)) /* domain SID */
1307 memset((char *)&d_q
->dom_sid
, '\0', sizeof(d_q
->dom_sid
));
1313 /*******************************************************************
1314 Reads or writes a dom query structure.
1315 ********************************************************************/
1317 BOOL
smb_io_dom_query_3(char *desc
, DOM_QUERY_3
*d_q
, prs_struct
*ps
, int depth
)
1319 return smb_io_dom_query("", d_q
, ps
, depth
);
1322 /*******************************************************************
1323 Reads or writes a dom query structure.
1324 ********************************************************************/
1326 BOOL
smb_io_dom_query_5(char *desc
, DOM_QUERY_3
*d_q
, prs_struct
*ps
, int depth
)
1328 return smb_io_dom_query("", d_q
, ps
, depth
);
1332 /*******************************************************************
1333 Reads or writes a UNISTR3 structure.
1334 ********************************************************************/
1336 BOOL
smb_io_unistr3(char *desc
, UNISTR3
*name
, prs_struct
*ps
, int depth
)
1341 prs_debug(ps
, depth
, desc
, "smb_io_unistr3");
1347 if(!prs_uint32("uni_str_len", ps
, depth
, &name
->uni_str_len
))
1350 /* don't know if len is specified by uni_str_len member... */
1351 /* assume unicode string is unicode-null-terminated, instead */
1353 if(!prs_unistr3(True
, "unistr", name
, ps
, depth
))