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 structure.
31 ********************************************************************/
33 static BOOL
net_io_neg_flags(char *desc
, NEG_FLAGS
*neg
, prs_struct
*ps
, int depth
)
38 prs_debug(ps
, depth
, desc
, "net_io_neg_flags");
44 if(!prs_uint32("neg_flags", ps
, depth
, &neg
->neg_flags
))
50 /*******************************************************************
51 Inits a NETLOGON_INFO_3 structure.
52 ********************************************************************/
54 static void init_netinfo_3(NETLOGON_INFO_3
*info
, uint32 flags
, uint32 logon_attempts
)
57 info
->logon_attempts
= logon_attempts
;
58 info
->reserved_1
= 0x0;
59 info
->reserved_2
= 0x0;
60 info
->reserved_3
= 0x0;
61 info
->reserved_4
= 0x0;
62 info
->reserved_5
= 0x0;
65 /*******************************************************************
66 Reads or writes a NETLOGON_INFO_3 structure.
67 ********************************************************************/
69 static BOOL
net_io_netinfo_3(char *desc
, NETLOGON_INFO_3
*info
, prs_struct
*ps
, int depth
)
74 prs_debug(ps
, depth
, desc
, "net_io_netinfo_3");
80 if(!prs_uint32("flags ", ps
, depth
, &info
->flags
))
82 if(!prs_uint32("logon_attempts", ps
, depth
, &info
->logon_attempts
))
84 if(!prs_uint32("reserved_1 ", ps
, depth
, &info
->reserved_1
))
86 if(!prs_uint32("reserved_2 ", ps
, depth
, &info
->reserved_2
))
88 if(!prs_uint32("reserved_3 ", ps
, depth
, &info
->reserved_3
))
90 if(!prs_uint32("reserved_4 ", ps
, depth
, &info
->reserved_4
))
92 if(!prs_uint32("reserved_5 ", ps
, depth
, &info
->reserved_5
))
99 /*******************************************************************
100 Inits a NETLOGON_INFO_1 structure.
101 ********************************************************************/
103 static void init_netinfo_1(NETLOGON_INFO_1
*info
, uint32 flags
, uint32 pdc_status
)
106 info
->pdc_status
= pdc_status
;
109 /*******************************************************************
110 Reads or writes a NETLOGON_INFO_1 structure.
111 ********************************************************************/
113 static BOOL
net_io_netinfo_1(char *desc
, NETLOGON_INFO_1
*info
, prs_struct
*ps
, int depth
)
118 prs_debug(ps
, depth
, desc
, "net_io_netinfo_1");
124 if(!prs_uint32("flags ", ps
, depth
, &info
->flags
))
126 if(!prs_uint32("pdc_status", ps
, depth
, &info
->pdc_status
))
132 /*******************************************************************
133 Inits a NETLOGON_INFO_2 structure.
134 ********************************************************************/
136 static void init_netinfo_2(NETLOGON_INFO_2
*info
, uint32 flags
, uint32 pdc_status
,
137 uint32 tc_status
, char *trusted_dc_name
)
139 int len_dc_name
= strlen(trusted_dc_name
);
141 info
->pdc_status
= pdc_status
;
142 info
->ptr_trusted_dc_name
= 1;
143 info
->tc_status
= tc_status
;
145 if (trusted_dc_name
!= NULL
)
146 init_unistr2(&(info
->uni_trusted_dc_name
), trusted_dc_name
, len_dc_name
+1);
148 init_unistr2(&(info
->uni_trusted_dc_name
), "", 1);
151 /*******************************************************************
152 Reads or writes a NETLOGON_INFO_2 structure.
153 ********************************************************************/
155 static BOOL
net_io_netinfo_2(char *desc
, NETLOGON_INFO_2
*info
, prs_struct
*ps
, int depth
)
160 prs_debug(ps
, depth
, desc
, "net_io_netinfo_2");
166 if(!prs_uint32("flags ", ps
, depth
, &info
->flags
))
168 if(!prs_uint32("pdc_status ", ps
, depth
, &info
->pdc_status
))
170 if(!prs_uint32("ptr_trusted_dc_name", ps
, depth
, &info
->ptr_trusted_dc_name
))
172 if(!prs_uint32("tc_status ", ps
, depth
, &info
->tc_status
))
175 if (info
->ptr_trusted_dc_name
!= 0) {
176 if(!smb_io_unistr2("unistr2", &info
->uni_trusted_dc_name
, info
->ptr_trusted_dc_name
, ps
, depth
))
186 /*******************************************************************
187 Reads or writes an NET_Q_LOGON_CTRL2 structure.
188 ********************************************************************/
190 BOOL
net_io_q_logon_ctrl2(char *desc
, NET_Q_LOGON_CTRL2
*q_l
, prs_struct
*ps
, int depth
)
195 prs_debug(ps
, depth
, desc
, "net_io_q_logon_ctrl2");
201 if(!prs_uint32("ptr ", ps
, depth
, &q_l
->ptr
))
204 if(!smb_io_unistr2 ("", &q_l
->uni_server_name
, q_l
->ptr
, ps
, depth
))
210 if(!prs_uint32("function_code", ps
, depth
, &q_l
->function_code
))
212 if(!prs_uint32("query_level ", ps
, depth
, &q_l
->query_level
))
214 if(!prs_uint32("switch_value ", ps
, depth
, &q_l
->switch_value
))
220 /*******************************************************************
221 Inits an NET_R_LOGON_CTRL2 structure.
222 ********************************************************************/
224 void init_r_logon_ctrl2(NET_R_LOGON_CTRL2
*r_l
, uint32 query_level
,
225 uint32 flags
, uint32 pdc_status
, uint32 logon_attempts
,
226 uint32 tc_status
, char *trusted_domain_name
)
228 DEBUG(5,("make_r_logon_ctrl2\n"));
230 r_l
->switch_value
= query_level
; /* should only be 0x1 */
232 switch (query_level
) {
234 r_l
->ptr
= 1; /* undocumented pointer */
235 init_netinfo_1(&r_l
->logon
.info1
, flags
, pdc_status
);
239 r_l
->ptr
= 1; /* undocumented pointer */
240 init_netinfo_2(&r_l
->logon
.info2
, flags
, pdc_status
,
241 tc_status
, trusted_domain_name
);
245 r_l
->ptr
= 1; /* undocumented pointer */
246 init_netinfo_3(&(r_l
->logon
.info3
), flags
, logon_attempts
);
250 DEBUG(2,("init_r_logon_ctrl2: unsupported switch value %d\n",
252 r_l
->ptr
= 0; /* undocumented pointer */
254 /* take a guess at an error code... */
255 r_l
->status
= NT_STATUS_INVALID_INFO_CLASS
;
260 /*******************************************************************
261 Reads or writes an NET_R_LOGON_CTRL2 structure.
262 ********************************************************************/
264 BOOL
net_io_r_logon_ctrl2(char *desc
, NET_R_LOGON_CTRL2
*r_l
, prs_struct
*ps
, int depth
)
269 prs_debug(ps
, depth
, desc
, "net_io_r_logon_ctrl2");
272 if(!prs_uint32("switch_value ", ps
, depth
, &r_l
->switch_value
))
274 if(!prs_uint32("ptr ", ps
, depth
, &r_l
->ptr
))
278 switch (r_l
->switch_value
) {
280 if(!net_io_netinfo_1("", &r_l
->logon
.info1
, ps
, depth
))
284 if(!net_io_netinfo_2("", &r_l
->logon
.info2
, ps
, depth
))
288 if(!net_io_netinfo_3("", &r_l
->logon
.info3
, ps
, depth
))
292 DEBUG(2,("net_io_r_logon_ctrl2: unsupported switch value %d\n",
298 if(!prs_uint32("status ", ps
, depth
, &r_l
->status
))
304 /*******************************************************************
305 Inits an NET_R_TRUST_DOM_LIST structure.
306 ********************************************************************/
308 void init_r_trust_dom(NET_R_TRUST_DOM_LIST
*r_t
,
309 uint32 num_doms
, char *dom_name
)
313 DEBUG(5,("make_r_trust_dom\n"));
315 for (i
= 0; i
< MAX_TRUST_DOMS
; i
++) {
316 r_t
->uni_trust_dom_name
[i
].uni_str_len
= 0;
317 r_t
->uni_trust_dom_name
[i
].uni_max_len
= 0;
319 if (num_doms
> MAX_TRUST_DOMS
)
320 num_doms
= MAX_TRUST_DOMS
;
322 for (i
= 0; i
< num_doms
; i
++) {
324 fstrcpy(domain_name
, dom_name
);
325 strupper(domain_name
);
326 init_unistr2(&r_t
->uni_trust_dom_name
[i
], domain_name
, strlen(domain_name
)+1);
327 /* the use of UNISTR2 here is non-standard. */
328 r_t
->uni_trust_dom_name
[i
].undoc
= 0x1;
334 /*******************************************************************
335 Reads or writes an NET_R_TRUST_DOM_LIST structure.
336 ********************************************************************/
338 BOOL
net_io_r_trust_dom(char *desc
, NET_R_TRUST_DOM_LIST
*r_t
, prs_struct
*ps
, int depth
)
344 prs_debug(ps
, depth
, desc
, "net_io_r_trust_dom");
347 for (i
= 0; i
< MAX_TRUST_DOMS
; i
++) {
348 if (r_t
->uni_trust_dom_name
[i
].uni_str_len
== 0)
350 if(!smb_io_unistr2("", &r_t
->uni_trust_dom_name
[i
], True
, ps
, depth
))
354 if(!prs_uint32("status", ps
, depth
, &r_t
->status
))
361 /*******************************************************************
362 Reads or writes an NET_Q_TRUST_DOM_LIST structure.
363 ********************************************************************/
365 BOOL
net_io_q_trust_dom(char *desc
, NET_Q_TRUST_DOM_LIST
*q_l
, prs_struct
*ps
, int depth
)
370 prs_debug(ps
, depth
, desc
, "net_io_q_trust_dom");
373 if(!prs_uint32("ptr ", ps
, depth
, &q_l
->ptr
))
375 if(!smb_io_unistr2 ("", &q_l
->uni_server_name
, q_l
->ptr
, ps
, depth
))
381 if(!prs_uint32("function_code", ps
, depth
, &q_l
->function_code
))
387 /*******************************************************************
388 Inits an NET_Q_REQ_CHAL structure.
389 ********************************************************************/
391 void init_q_req_chal(NET_Q_REQ_CHAL
*q_c
,
392 char *logon_srv
, char *logon_clnt
,
395 DEBUG(5,("make_q_req_chal: %d\n", __LINE__
));
397 q_c
->undoc_buffer
= 1; /* don't know what this buffer is */
399 init_unistr2(&q_c
->uni_logon_srv
, logon_srv
, strlen(logon_srv
)+1);
400 init_unistr2(&q_c
->uni_logon_clnt
, logon_clnt
, strlen(logon_clnt
)+1);
402 memcpy(q_c
->clnt_chal
.data
, clnt_chal
->data
, sizeof(clnt_chal
->data
));
404 DEBUG(5,("make_q_req_chal: %d\n", __LINE__
));
407 /*******************************************************************
408 Reads or writes an NET_Q_REQ_CHAL structure.
409 ********************************************************************/
411 BOOL
net_io_q_req_chal(char *desc
, NET_Q_REQ_CHAL
*q_c
, prs_struct
*ps
, int depth
)
418 prs_debug(ps
, depth
, desc
, "net_io_q_req_chal");
424 if(!prs_uint32("undoc_buffer", ps
, depth
, &q_c
->undoc_buffer
))
427 if(!smb_io_unistr2("", &q_c
->uni_logon_srv
, True
, ps
, depth
)) /* logon server unicode string */
429 if(!smb_io_unistr2("", &q_c
->uni_logon_clnt
, True
, ps
, depth
)) /* logon client unicode string */
432 old_align
= ps
->align
;
434 /* client challenge is _not_ aligned after the unicode strings */
435 if(!smb_io_chal("", &q_c
->clnt_chal
, ps
, depth
)) {
436 /* client challenge */
437 ps
->align
= old_align
;
440 ps
->align
= old_align
;
445 /*******************************************************************
446 Reads or writes a structure.
447 ********************************************************************/
449 BOOL
net_io_r_req_chal(char *desc
, NET_R_REQ_CHAL
*r_c
, prs_struct
*ps
, int depth
)
454 prs_debug(ps
, depth
, desc
, "net_io_r_req_chal");
460 if(!smb_io_chal("", &r_c
->srv_chal
, ps
, depth
)) /* server challenge */
463 if(!prs_uint32("status", ps
, depth
, &r_c
->status
))
470 /*******************************************************************
471 Inits a NET_Q_AUTH_2 struct.
472 ********************************************************************/
474 void init_q_auth_2(NET_Q_AUTH_2
*q_a
,
475 char *logon_srv
, char *acct_name
, uint16 sec_chan
, char *comp_name
,
476 DOM_CHAL
*clnt_chal
, uint32 clnt_flgs
)
478 DEBUG(5,("init_q_auth_2: %d\n", __LINE__
));
480 init_log_info(&q_a
->clnt_id
, logon_srv
, acct_name
, sec_chan
, comp_name
);
481 memcpy(q_a
->clnt_chal
.data
, clnt_chal
->data
, sizeof(clnt_chal
->data
));
482 q_a
->clnt_flgs
.neg_flags
= clnt_flgs
;
484 DEBUG(5,("init_q_auth_2: %d\n", __LINE__
));
487 /*******************************************************************
488 Reads or writes a structure.
489 ********************************************************************/
491 BOOL
net_io_q_auth_2(char *desc
, NET_Q_AUTH_2
*q_a
, prs_struct
*ps
, int depth
)
497 prs_debug(ps
, depth
, desc
, "net_io_q_auth_2");
503 if(!smb_io_log_info ("", &q_a
->clnt_id
, ps
, depth
)) /* client identification info */
505 /* client challenge is _not_ aligned */
506 old_align
= ps
->align
;
508 if(!smb_io_chal("", &q_a
->clnt_chal
, ps
, depth
)) {
509 /* client-calculated credentials */
510 ps
->align
= old_align
;
513 ps
->align
= old_align
;
514 if(!net_io_neg_flags("", &q_a
->clnt_flgs
, ps
, depth
))
520 /*******************************************************************
521 Reads or writes a structure.
522 ********************************************************************/
524 BOOL
net_io_r_auth_2(char *desc
, NET_R_AUTH_2
*r_a
, prs_struct
*ps
, int depth
)
529 prs_debug(ps
, depth
, desc
, "net_io_r_auth_2");
535 if(!smb_io_chal("", &r_a
->srv_chal
, ps
, depth
)) /* server challenge */
537 if(!net_io_neg_flags("", &r_a
->srv_flgs
, ps
, depth
))
540 if(!prs_uint32("status", ps
, depth
, &r_a
->status
))
547 /*******************************************************************
548 Inits a NET_Q_SRV_PWSET.
549 ********************************************************************/
551 void init_q_srv_pwset(NET_Q_SRV_PWSET
*q_s
, char *logon_srv
, char *acct_name
,
552 uint16 sec_chan
, char *comp_name
, DOM_CRED
*cred
, char nt_cypher
[16])
554 DEBUG(5,("make_q_srv_pwset\n"));
556 init_clnt_info(&q_s
->clnt_id
, logon_srv
, acct_name
, sec_chan
, comp_name
, cred
);
558 memcpy(q_s
->pwd
, nt_cypher
, sizeof(q_s
->pwd
));
561 /*******************************************************************
562 Reads or writes a structure.
563 ********************************************************************/
565 BOOL
net_io_q_srv_pwset(char *desc
, NET_Q_SRV_PWSET
*q_s
, prs_struct
*ps
, int depth
)
570 prs_debug(ps
, depth
, desc
, "net_io_q_srv_pwset");
576 if(!smb_io_clnt_info("", &q_s
->clnt_id
, ps
, depth
)) /* client identification/authentication info */
578 if(!prs_uint8s (False
, "pwd", ps
, depth
, q_s
->pwd
, 16)) /* new password - undocumented */
584 /*******************************************************************
585 Reads or writes a structure.
586 ********************************************************************/
588 BOOL
net_io_r_srv_pwset(char *desc
, NET_R_SRV_PWSET
*r_s
, prs_struct
*ps
, int depth
)
593 prs_debug(ps
, depth
, desc
, "net_io_r_srv_pwset");
599 if(!smb_io_cred("", &r_s
->srv_cred
, ps
, depth
)) /* server challenge */
602 if(!prs_uint32("status", ps
, depth
, &r_s
->status
))
608 /*************************************************************************
609 Init DOM_SID2 array from a string containing multiple sids
610 *************************************************************************/
612 static int init_dom_sid2s(char *sids_str
, DOM_SID2
*sids
, int max_sids
)
618 DEBUG(4,("init_dom_sid2s: %s\n", sids_str
? sids_str
:""));
621 for (count
= 0, ptr
= sids_str
;
622 next_token(&ptr
, s2
, NULL
, sizeof(s2
)) && count
< max_sids
; count
++) {
624 string_to_sid(&tmpsid
, s2
);
625 init_dom_sid2(&sids
[count
], &tmpsid
);
632 /*******************************************************************
633 Inits a NET_ID_INFO_1 structure.
634 ********************************************************************/
636 void init_id_info1(NET_ID_INFO_1
*id
, char *domain_name
,
637 uint32 param_ctrl
, uint32 log_id_low
, uint32 log_id_high
,
638 char *user_name
, char *wksta_name
,
640 unsigned char lm_cypher
[16], unsigned char nt_cypher
[16])
642 int len_domain_name
= strlen(domain_name
);
643 int len_user_name
= strlen(user_name
);
644 int len_wksta_name
= strlen(wksta_name
);
646 unsigned char lm_owf
[16];
647 unsigned char nt_owf
[16];
649 DEBUG(5,("make_id_info1: %d\n", __LINE__
));
651 id
->ptr_id_info1
= 1;
653 init_uni_hdr(&id
->hdr_domain_name
, len_domain_name
);
655 id
->param_ctrl
= param_ctrl
;
656 init_logon_id(&id
->logon_id
, log_id_low
, log_id_high
);
658 init_uni_hdr(&id
->hdr_user_name
, len_user_name
);
659 init_uni_hdr(&id
->hdr_wksta_name
, len_wksta_name
);
661 if (lm_cypher
&& nt_cypher
) {
662 unsigned char key
[16];
663 #ifdef DEBUG_PASSWORD
664 DEBUG(100,("lm cypher:"));
665 dump_data(100, (char *)lm_cypher
, 16);
667 DEBUG(100,("nt cypher:"));
668 dump_data(100, (char *)nt_cypher
, 16);
672 memcpy(key
, sess_key
, 8);
674 memcpy(lm_owf
, lm_cypher
, 16);
675 SamOEMhash(lm_owf
, key
, False
);
676 memcpy(nt_owf
, nt_cypher
, 16);
677 SamOEMhash(nt_owf
, key
, False
);
679 #ifdef DEBUG_PASSWORD
680 DEBUG(100,("encrypt of lm owf password:"));
681 dump_data(100, (char *)lm_owf
, 16);
683 DEBUG(100,("encrypt of nt owf password:"));
684 dump_data(100, (char *)nt_owf
, 16);
686 /* set up pointers to cypher blocks */
691 init_owf_info(&id
->lm_owf
, lm_cypher
);
692 init_owf_info(&id
->nt_owf
, nt_cypher
);
694 init_unistr2(&id
->uni_domain_name
, domain_name
, len_domain_name
);
695 init_unistr2(&id
->uni_user_name
, user_name
, len_user_name
);
696 init_unistr2(&id
->uni_wksta_name
, wksta_name
, len_wksta_name
);
699 /*******************************************************************
700 Reads or writes an NET_ID_INFO_1 structure.
701 ********************************************************************/
703 static BOOL
net_io_id_info1(char *desc
, NET_ID_INFO_1
*id
, prs_struct
*ps
, int depth
)
708 prs_debug(ps
, depth
, desc
, "net_io_id_info1");
714 if(!prs_uint32("ptr_id_info1", ps
, depth
, &id
->ptr_id_info1
))
717 if (id
->ptr_id_info1
!= 0) {
718 if(!smb_io_unihdr("unihdr", &id
->hdr_domain_name
, ps
, depth
))
721 if(!prs_uint32("param_ctrl", ps
, depth
, &id
->param_ctrl
))
723 if(!smb_io_logon_id("", &id
->logon_id
, ps
, depth
))
726 if(!smb_io_unihdr("unihdr", &id
->hdr_user_name
, ps
, depth
))
728 if(!smb_io_unihdr("unihdr", &id
->hdr_wksta_name
, ps
, depth
))
731 if(!smb_io_owf_info("", &id
->lm_owf
, ps
, depth
))
733 if(!smb_io_owf_info("", &id
->nt_owf
, ps
, depth
))
736 if(!smb_io_unistr2("unistr2", &id
->uni_domain_name
,
737 id
->hdr_domain_name
.buffer
, ps
, depth
))
739 if(!smb_io_unistr2("unistr2", &id
->uni_user_name
,
740 id
->hdr_user_name
.buffer
, ps
, depth
))
742 if(!smb_io_unistr2("unistr2", &id
->uni_wksta_name
,
743 id
->hdr_wksta_name
.buffer
, ps
, depth
))
750 /*******************************************************************
751 Inits a NET_ID_INFO_2 structure.
753 This is a network logon packet. The log_id parameters
754 are what an NT server would generate for LUID once the
755 user is logged on. I don't think we care about them.
757 Note that this has no access to the NT and LM hashed passwords,
758 so it forwards the challenge, and the NT and LM responses (24
759 bytes each) over the secure channel to the Domain controller
760 for it to say yea or nay. This is the preferred method of
761 checking for a logon as it doesn't export the password
762 hashes to anyone who has compromised the secure channel. JRA.
763 ********************************************************************/
765 void init_id_info2(NET_ID_INFO_2
*id
, char *domain_name
,
766 uint32 param_ctrl
, uint32 log_id_low
, uint32 log_id_high
,
767 char *user_name
, char *wksta_name
,
768 unsigned char lm_challenge
[8],
769 unsigned char lm_chal_resp
[24],
770 unsigned char nt_chal_resp
[24])
772 int len_domain_name
= strlen(domain_name
);
773 int len_user_name
= strlen(user_name
);
774 int len_wksta_name
= strlen(wksta_name
);
775 int nt_chal_resp_len
= ((nt_chal_resp
!= NULL
) ? 24 : 0);
776 int lm_chal_resp_len
= ((lm_chal_resp
!= NULL
) ? 24 : 0);
777 unsigned char lm_owf
[24];
778 unsigned char nt_owf
[24];
780 DEBUG(5,("init_id_info2: %d\n", __LINE__
));
782 id
->ptr_id_info2
= 1;
784 init_uni_hdr(&id
->hdr_domain_name
, len_domain_name
);
786 id
->param_ctrl
= param_ctrl
;
787 init_logon_id(&id
->logon_id
, log_id_low
, log_id_high
);
789 init_uni_hdr(&id
->hdr_user_name
, len_user_name
);
790 init_uni_hdr(&id
->hdr_wksta_name
, len_wksta_name
);
793 /* oops. can only send what-ever-it-is direct */
794 memcpy(nt_owf
, nt_chal_resp
, 24);
795 nt_chal_resp
= nt_owf
;
798 /* oops. can only send what-ever-it-is direct */
799 memcpy(lm_owf
, lm_chal_resp
, 24);
800 lm_chal_resp
= lm_owf
;
803 memcpy(id
->lm_chal
, lm_challenge
, sizeof(id
->lm_chal
));
804 init_str_hdr(&id
->hdr_nt_chal_resp
, 24, nt_chal_resp_len
, (nt_chal_resp
!= NULL
) ? 1 : 0);
805 init_str_hdr(&id
->hdr_lm_chal_resp
, 24, lm_chal_resp_len
, (lm_chal_resp
!= NULL
) ? 1 : 0);
807 init_unistr2(&id
->uni_domain_name
, domain_name
, len_domain_name
);
808 init_unistr2(&id
->uni_user_name
, user_name
, len_user_name
);
809 init_unistr2(&id
->uni_wksta_name
, wksta_name
, len_wksta_name
);
811 init_string2(&id
->nt_chal_resp
, (char *)nt_chal_resp
, nt_chal_resp_len
);
812 init_string2(&id
->lm_chal_resp
, (char *)lm_chal_resp
, lm_chal_resp_len
);
815 /*******************************************************************
816 Reads or writes an NET_ID_INFO_2 structure.
817 ********************************************************************/
819 static BOOL
net_io_id_info2(char *desc
, NET_ID_INFO_2
*id
, prs_struct
*ps
, int depth
)
824 prs_debug(ps
, depth
, desc
, "net_io_id_info2");
830 if(!prs_uint32("ptr_id_info2", ps
, depth
, &id
->ptr_id_info2
))
833 if (id
->ptr_id_info2
!= 0) {
834 if(!smb_io_unihdr("unihdr", &id
->hdr_domain_name
, ps
, depth
))
837 if(!prs_uint32("param_ctrl", ps
, depth
, &id
->param_ctrl
))
839 if(!smb_io_logon_id("", &id
->logon_id
, ps
, depth
))
842 if(!smb_io_unihdr("unihdr", &id
->hdr_user_name
, ps
, depth
))
844 if(!smb_io_unihdr("unihdr", &id
->hdr_wksta_name
, ps
, depth
))
847 if(!prs_uint8s (False
, "lm_chal", ps
, depth
, id
->lm_chal
, 8)) /* lm 8 byte challenge */
850 if(!smb_io_strhdr("hdr_nt_chal_resp", &id
->hdr_nt_chal_resp
, ps
, depth
))
852 if(!smb_io_strhdr("hdr_lm_chal_resp", &id
->hdr_lm_chal_resp
, ps
, depth
))
855 if(!smb_io_unistr2("uni_domain_name", &id
->uni_domain_name
,
856 id
->hdr_domain_name
.buffer
, ps
, depth
))
858 if(!smb_io_unistr2("uni_user_name ", &id
->uni_user_name
,
859 id
->hdr_user_name
.buffer
, ps
, depth
))
861 if(!smb_io_unistr2("uni_wksta_name ", &id
->uni_wksta_name
,
862 id
->hdr_wksta_name
.buffer
, ps
, depth
))
864 if(!smb_io_string2("nt_chal_resp", &id
->nt_chal_resp
,
865 id
->hdr_nt_chal_resp
.buffer
, ps
, depth
))
867 if(!smb_io_string2("lm_chal_resp", &id
->lm_chal_resp
,
868 id
->hdr_lm_chal_resp
.buffer
, ps
, depth
))
876 /*******************************************************************
877 Inits a DOM_SAM_INFO structure.
878 ********************************************************************/
880 void init_sam_info(DOM_SAM_INFO
*sam
,
881 char *logon_srv
, char *comp_name
, DOM_CRED
*clnt_cred
,
882 DOM_CRED
*rtn_cred
, uint16 logon_level
,
883 NET_ID_INFO_CTR
*ctr
)
885 DEBUG(5,("init_sam_info: %d\n", __LINE__
));
887 init_clnt_info2(&(sam
->client
), logon_srv
, comp_name
, clnt_cred
);
889 if (rtn_cred
!= NULL
) {
890 sam
->ptr_rtn_cred
= 1;
891 memcpy(&sam
->rtn_cred
, rtn_cred
, sizeof(sam
->rtn_cred
));
893 sam
->ptr_rtn_cred
= 0;
896 sam
->logon_level
= logon_level
;
900 /*******************************************************************
901 Reads or writes a DOM_SAM_INFO structure.
902 ********************************************************************/
904 static BOOL
net_io_id_info_ctr(char *desc
, NET_ID_INFO_CTR
*ctr
, prs_struct
*ps
, int depth
)
909 prs_debug(ps
, depth
, desc
, "smb_io_sam_info");
912 /* don't 4-byte align here! */
914 if(!prs_uint16("switch_value ", ps
, depth
, &ctr
->switch_value
))
917 switch (ctr
->switch_value
) {
919 if(!net_io_id_info1("", &ctr
->auth
.id1
, ps
, depth
))
923 if(!net_io_id_info2("", &ctr
->auth
.id2
, ps
, depth
))
928 DEBUG(4,("smb_io_sam_info: unknown switch_value!\n"));
935 /*******************************************************************
936 Reads or writes a DOM_SAM_INFO structure.
937 ********************************************************************/
939 static BOOL
smb_io_sam_info(char *desc
, DOM_SAM_INFO
*sam
, prs_struct
*ps
, int depth
)
944 prs_debug(ps
, depth
, desc
, "smb_io_sam_info");
950 if(!smb_io_clnt_info2("", &sam
->client
, ps
, depth
))
953 if(!prs_uint32("ptr_rtn_cred ", ps
, depth
, &sam
->ptr_rtn_cred
))
955 if(!smb_io_cred("", &sam
->rtn_cred
, ps
, depth
))
958 if(!prs_uint16("logon_level ", ps
, depth
, &sam
->logon_level
))
961 if (sam
->logon_level
!= 0 && sam
->ctr
!= NULL
) {
962 if(!net_io_id_info_ctr("logon_info", sam
->ctr
, ps
, depth
))
969 /*************************************************************************
971 *************************************************************************/
973 void init_net_user_info3(NET_USER_INFO_3
*usr
,
977 NTTIME
*kickoff_time
,
978 NTTIME
*pass_last_set_time
,
979 NTTIME
*pass_can_change_time
,
980 NTTIME
*pass_must_change_time
,
1006 /* only cope with one "other" sid, right now. */
1007 /* need to count the number of space-delimited sids */
1009 int num_other_sids
= 0;
1011 int len_user_name
= strlen(user_name
);
1012 int len_full_name
= strlen(full_name
);
1013 int len_logon_script
= strlen(logon_script
);
1014 int len_profile_path
= strlen(profile_path
);
1015 int len_home_dir
= strlen(home_dir
);
1016 int len_dir_drive
= strlen(dir_drive
);
1018 int len_logon_srv
= strlen(logon_srv
);
1019 int len_logon_dom
= strlen(logon_dom
);
1021 memset(usr
, '\0', sizeof(*usr
));
1023 usr
->ptr_user_info
= 1; /* yes, we're bothering to put USER_INFO data here */
1025 usr
->logon_time
= *logon_time
;
1026 usr
->logoff_time
= *logoff_time
;
1027 usr
->kickoff_time
= *kickoff_time
;
1028 usr
->pass_last_set_time
= *pass_last_set_time
;
1029 usr
->pass_can_change_time
= *pass_can_change_time
;
1030 usr
->pass_must_change_time
= *pass_must_change_time
;
1032 init_uni_hdr(&usr
->hdr_user_name
, len_user_name
);
1033 init_uni_hdr(&usr
->hdr_full_name
, len_full_name
);
1034 init_uni_hdr(&usr
->hdr_logon_script
, len_logon_script
);
1035 init_uni_hdr(&usr
->hdr_profile_path
, len_profile_path
);
1036 init_uni_hdr(&usr
->hdr_home_dir
, len_home_dir
);
1037 init_uni_hdr(&usr
->hdr_dir_drive
, len_dir_drive
);
1039 usr
->logon_count
= logon_count
;
1040 usr
->bad_pw_count
= bad_pw_count
;
1042 usr
->user_id
= user_id
;
1043 usr
->group_id
= group_id
;
1044 usr
->num_groups
= num_groups
;
1045 usr
->buffer_groups
= 1; /* indicates fill in groups, below, even if there are none */
1046 usr
->user_flgs
= user_flgs
;
1048 if (sess_key
!= NULL
)
1049 memcpy(usr
->user_sess_key
, sess_key
, sizeof(usr
->user_sess_key
));
1051 memset((char *)usr
->user_sess_key
, '\0', sizeof(usr
->user_sess_key
));
1053 init_uni_hdr(&usr
->hdr_logon_srv
, len_logon_srv
);
1054 init_uni_hdr(&usr
->hdr_logon_dom
, len_logon_dom
);
1056 usr
->buffer_dom_id
= dom_sid
? 1 : 0; /* yes, we're bothering to put a domain SID in */
1058 memset((char *)usr
->padding
, '\0', sizeof(usr
->padding
));
1060 num_other_sids
= init_dom_sid2s(other_sids
, usr
->other_sids
, LSA_MAX_SIDS
);
1062 usr
->num_other_sids
= num_other_sids
;
1063 usr
->buffer_other_sids
= (num_other_sids
!= 0) ? 1 : 0;
1065 init_unistr2(&usr
->uni_user_name
, user_name
, len_user_name
);
1066 init_unistr2(&usr
->uni_full_name
, full_name
, len_full_name
);
1067 init_unistr2(&usr
->uni_logon_script
, logon_script
, len_logon_script
);
1068 init_unistr2(&usr
->uni_profile_path
, profile_path
, len_profile_path
);
1069 init_unistr2(&usr
->uni_home_dir
, home_dir
, len_home_dir
);
1070 init_unistr2(&usr
->uni_dir_drive
, dir_drive
, len_dir_drive
);
1072 usr
->num_groups2
= num_groups
;
1074 SMB_ASSERT_ARRAY(usr
->gids
, num_groups
);
1076 for (i
= 0; i
< num_groups
; i
++)
1077 usr
->gids
[i
] = gids
[i
];
1079 init_unistr2(&usr
->uni_logon_srv
, logon_srv
, len_logon_srv
);
1080 init_unistr2(&usr
->uni_logon_dom
, logon_dom
, len_logon_dom
);
1082 init_dom_sid2(&usr
->dom_sid
, dom_sid
);
1083 /* "other" sids are set up above */
1087 /*******************************************************************
1088 Reads or writes a structure.
1089 ********************************************************************/
1091 static BOOL
net_io_user_info3(char *desc
, NET_USER_INFO_3
*usr
, prs_struct
*ps
, int depth
)
1098 prs_debug(ps
, depth
, desc
, "lsa_io_lsa_user_info");
1104 if(!prs_uint32("ptr_user_info ", ps
, depth
, &usr
->ptr_user_info
))
1107 if (usr
->ptr_user_info
== 0)
1110 if(!smb_io_time("time", &usr
->logon_time
, ps
, depth
)) /* logon time */
1112 if(!smb_io_time("time", &usr
->logoff_time
, ps
, depth
)) /* logoff time */
1114 if(!smb_io_time("time", &usr
->kickoff_time
, ps
, depth
)) /* kickoff time */
1116 if(!smb_io_time("time", &usr
->pass_last_set_time
, ps
, depth
)) /* password last set time */
1118 if(!smb_io_time("time", &usr
->pass_can_change_time
, ps
, depth
)) /* password can change time */
1120 if(!smb_io_time("time", &usr
->pass_must_change_time
, ps
, depth
)) /* password must change time */
1123 if(!smb_io_unihdr("unihdr", &usr
->hdr_user_name
, ps
, depth
)) /* username unicode string header */
1125 if(!smb_io_unihdr("unihdr", &usr
->hdr_full_name
, ps
, depth
)) /* user's full name unicode string header */
1127 if(!smb_io_unihdr("unihdr", &usr
->hdr_logon_script
, ps
, depth
)) /* logon script unicode string header */
1129 if(!smb_io_unihdr("unihdr", &usr
->hdr_profile_path
, ps
, depth
)) /* profile path unicode string header */
1131 if(!smb_io_unihdr("unihdr", &usr
->hdr_home_dir
, ps
, depth
)) /* home directory unicode string header */
1133 if(!smb_io_unihdr("unihdr", &usr
->hdr_dir_drive
, ps
, depth
)) /* home directory drive unicode string header */
1136 if(!prs_uint16("logon_count ", ps
, depth
, &usr
->logon_count
)) /* logon count */
1138 if(!prs_uint16("bad_pw_count ", ps
, depth
, &usr
->bad_pw_count
)) /* bad password count */
1141 if(!prs_uint32("user_id ", ps
, depth
, &usr
->user_id
)) /* User ID */
1143 if(!prs_uint32("group_id ", ps
, depth
, &usr
->group_id
)) /* Group ID */
1145 if(!prs_uint32("num_groups ", ps
, depth
, &usr
->num_groups
)) /* num groups */
1147 if(!prs_uint32("buffer_groups ", ps
, depth
, &usr
->buffer_groups
)) /* undocumented buffer pointer to groups. */
1149 if(!prs_uint32("user_flgs ", ps
, depth
, &usr
->user_flgs
)) /* user flags */
1152 if(!prs_uint8s(False
, "user_sess_key", ps
, depth
, usr
->user_sess_key
, 16)) /* unused user session key */
1155 if(!smb_io_unihdr("unihdr", &usr
->hdr_logon_srv
, ps
, depth
)) /* logon server unicode string header */
1157 if(!smb_io_unihdr("unihdr", &usr
->hdr_logon_dom
, ps
, depth
)) /* logon domain unicode string header */
1160 if(!prs_uint32("buffer_dom_id ", ps
, depth
, &usr
->buffer_dom_id
)) /* undocumented logon domain id pointer */
1162 if(!prs_uint8s (False
, "padding ", ps
, depth
, usr
->padding
, 40)) /* unused padding bytes? */
1165 if(!prs_uint32("num_other_sids", ps
, depth
, &usr
->num_other_sids
)) /* 0 - num_sids */
1167 if(!prs_uint32("buffer_other_sids", ps
, depth
, &usr
->buffer_other_sids
)) /* NULL - undocumented pointer to SIDs. */
1170 if(!smb_io_unistr2("unistr2", &usr
->uni_user_name
, usr
->hdr_user_name
.buffer
, ps
, depth
)) /* username unicode string */
1172 if(!smb_io_unistr2("unistr2", &usr
->uni_full_name
, usr
->hdr_full_name
.buffer
, ps
, depth
)) /* user's full name unicode string */
1174 if(!smb_io_unistr2("unistr2", &usr
->uni_logon_script
, usr
->hdr_logon_script
.buffer
, ps
, depth
)) /* logon script unicode string */
1176 if(!smb_io_unistr2("unistr2", &usr
->uni_profile_path
, usr
->hdr_profile_path
.buffer
, ps
, depth
)) /* profile path unicode string */
1178 if(!smb_io_unistr2("unistr2", &usr
->uni_home_dir
, usr
->hdr_home_dir
.buffer
, ps
, depth
)) /* home directory unicode string */
1180 if(!smb_io_unistr2("unistr2", &usr
->uni_dir_drive
, usr
->hdr_dir_drive
.buffer
, ps
, depth
)) /* home directory drive unicode string */
1185 if(!prs_uint32("num_groups2 ", ps
, depth
, &usr
->num_groups2
)) /* num groups */
1187 SMB_ASSERT_ARRAY(usr
->gids
, usr
->num_groups2
);
1188 for (i
= 0; i
< usr
->num_groups2
; i
++) {
1189 if(!smb_io_gid("", &usr
->gids
[i
], ps
, depth
)) /* group info */
1193 if(!smb_io_unistr2("unistr2", &usr
->uni_logon_srv
, usr
->hdr_logon_srv
.buffer
, ps
, depth
)) /* logon server unicode string */
1195 if(!smb_io_unistr2("unistr2", &usr
->uni_logon_dom
, usr
->hdr_logon_srv
.buffer
, ps
, depth
)) /* logon domain unicode string */
1198 if(!smb_io_dom_sid2("", &usr
->dom_sid
, ps
, depth
)) /* domain SID */
1201 SMB_ASSERT_ARRAY(usr
->other_sids
, usr
->num_other_sids
);
1203 for (i
= 0; i
< usr
->num_other_sids
; i
++) {
1204 if(!smb_io_dom_sid2("", &usr
->other_sids
[i
], ps
, depth
)) /* other domain SIDs */
1211 /*******************************************************************
1212 Reads or writes a structure.
1213 ********************************************************************/
1215 BOOL
net_io_q_sam_logon(char *desc
, NET_Q_SAM_LOGON
*q_l
, prs_struct
*ps
, int depth
)
1220 prs_debug(ps
, depth
, desc
, "net_io_q_sam_logon");
1226 if(!smb_io_sam_info("", &q_l
->sam_id
, ps
, depth
)) /* domain SID */
1229 if(!prs_uint16("validation_level", ps
, depth
, &q_l
->validation_level
))
1235 /*******************************************************************
1236 Reads or writes a structure.
1237 ********************************************************************/
1239 BOOL
net_io_r_sam_logon(char *desc
, NET_R_SAM_LOGON
*r_l
, prs_struct
*ps
, int depth
)
1244 prs_debug(ps
, depth
, desc
, "net_io_r_sam_logon");
1247 if(!prs_uint32("buffer_creds", ps
, depth
, &r_l
->buffer_creds
)) /* undocumented buffer pointer */
1249 if(!smb_io_cred("", &r_l
->srv_creds
, ps
, depth
)) /* server credentials. server time stamp appears to be ignored. */
1252 if(!prs_uint16("switch_value", ps
, depth
, &r_l
->switch_value
))
1257 if (r_l
->switch_value
!= 0) {
1258 if(!net_io_user_info3("", r_l
->user
, ps
, depth
))
1262 if(!prs_uint32("auth_resp ", ps
, depth
, &r_l
->auth_resp
)) /* 1 - Authoritative response; 0 - Non-Auth? */
1265 if(!prs_uint32("status ", ps
, depth
, &r_l
->status
))
1274 /*******************************************************************
1275 Reads or writes a structure.
1276 ********************************************************************/
1278 BOOL
net_io_q_sam_logoff(char *desc
, NET_Q_SAM_LOGOFF
*q_l
, prs_struct
*ps
, int depth
)
1283 prs_debug(ps
, depth
, desc
, "net_io_q_sam_logoff");
1289 if(!smb_io_sam_info("", &q_l
->sam_id
, ps
, depth
)) /* domain SID */
1295 /*******************************************************************
1296 Reads or writes a structure.
1297 ********************************************************************/
1299 BOOL
net_io_r_sam_logoff(char *desc
, NET_R_SAM_LOGOFF
*r_l
, prs_struct
*ps
, int depth
)
1304 prs_debug(ps
, depth
, desc
, "net_io_r_sam_logoff");
1310 if(!prs_uint32("buffer_creds", ps
, depth
, &r_l
->buffer_creds
)) /* undocumented buffer pointer */
1312 if(!smb_io_cred("", &r_l
->srv_creds
, ps
, depth
)) /* server credentials. server time stamp appears to be ignored. */
1315 if(!prs_uint32("status ", ps
, depth
, &r_l
->status
))