2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-1997,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
6 * Copyright (C) Paul Ashton 1997.
7 * Copyright (C) Jeremy Allison 1998-2001.
8 * Copyright (C) Andrew Bartlett 2001.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 /* This is the implementation of the netlogon pipe. */
29 extern struct dcinfo last_dcinfo;
30 extern BOOL server_auth2_negotiated;
31 extern userdom_struct current_user_info;
34 #define DBGC_CLASS DBGC_RPC_SRV
36 /*************************************************************************
38 *************************************************************************/
40 static void init_net_r_req_chal(NET_R_REQ_CHAL *r_c,
41 DOM_CHAL *srv_chal, NTSTATUS status)
43 DEBUG(6,("init_net_r_req_chal: %d\n", __LINE__));
44 memcpy(r_c->srv_chal.data, srv_chal->data, sizeof(srv_chal->data));
48 /*************************************************************************
49 error messages cropping up when using nltest.exe...
50 *************************************************************************/
52 #define ERROR_NO_SUCH_DOMAIN 0x54b
53 #define ERROR_NO_LOGON_SERVERS 0x51f
56 /*************************************************************************
58 *************************************************************************/
60 NTSTATUS _net_logon_ctrl(pipes_struct *p, NET_Q_LOGON_CTRL *q_u,
61 NET_R_LOGON_CTRL *r_u)
64 uint32 pdc_connection_status = 0x00; /* Maybe a win32 error code? */
66 /* Setup the Logon Control response */
68 init_net_r_logon_ctrl(r_u, q_u->query_level, flags,
69 pdc_connection_status);
74 /****************************************************************************
75 Send a message to smbd to do a sam synchronisation
76 **************************************************************************/
78 static void send_sync_message(void)
82 tdb = tdb_open_log(lock_path("connections.tdb"), 0,
83 TDB_DEFAULT, O_RDONLY, 0);
86 DEBUG(3, ("send_sync_message(): failed to open connections "
91 DEBUG(3, ("sending sam synchronisation message\n"));
93 message_send_all(tdb, MSG_SMB_SAM_SYNC, NULL, 0, False, NULL);
98 /*************************************************************************
99 net_reply_logon_ctrl2:
100 *************************************************************************/
102 NTSTATUS _net_logon_ctrl2(pipes_struct *p, NET_Q_LOGON_CTRL2 *q_u, NET_R_LOGON_CTRL2 *r_u)
105 uint32 pdc_connection_status = 0x0;
106 uint32 logon_attempts = 0x0;
108 fstring servername, domain, dc_name, dc_name2;
109 struct in_addr dc_ip;
111 /* this should be \\global_myname() */
112 unistr2_to_ascii(servername, &q_u->uni_server_name, sizeof(servername));
114 r_u->status = NT_STATUS_OK;
116 tc_status = ERROR_NO_SUCH_DOMAIN;
117 fstrcpy( dc_name, "" );
119 switch ( q_u->function_code ) {
120 case NETLOGON_CONTROL_TC_QUERY:
121 unistr2_to_ascii(domain, &q_u->info.info6.domain, sizeof(domain));
123 if ( !is_trusted_domain( domain ) )
126 if ( !get_dc_name( domain, NULL, dc_name2, &dc_ip ) ) {
127 tc_status = ERROR_NO_LOGON_SERVERS;
131 fstr_sprintf( dc_name, "\\\\%s", dc_name2 );
133 tc_status = NO_ERROR;
137 case NETLOGON_CONTROL_REDISCOVER:
138 unistr2_to_ascii(domain, &q_u->info.info6.domain, sizeof(domain));
140 if ( !is_trusted_domain( domain ) )
143 if ( !get_dc_name( domain, NULL, dc_name2, &dc_ip ) ) {
144 tc_status = ERROR_NO_LOGON_SERVERS;
148 fstr_sprintf( dc_name, "\\\\%s", dc_name2 );
150 tc_status = NO_ERROR;
155 /* no idea what this should be */
156 DEBUG(0,("_net_logon_ctrl2: unimplemented function level [%d]\n",
157 q_u->function_code));
160 /* prepare the response */
162 init_net_r_logon_ctrl2( r_u, q_u->query_level, flags,
163 pdc_connection_status, logon_attempts, tc_status, dc_name );
165 if (lp_server_role() == ROLE_DOMAIN_BDC)
171 /*************************************************************************
172 net_reply_trust_dom_list:
173 *************************************************************************/
175 NTSTATUS _net_trust_dom_list(pipes_struct *p, NET_Q_TRUST_DOM_LIST *q_u, NET_R_TRUST_DOM_LIST *r_u)
177 const char *trusted_domain = "test_domain";
178 uint32 num_trust_domains = 1;
180 DEBUG(6,("_net_trust_dom_list: %d\n", __LINE__));
182 /* set up the Trusted Domain List response */
183 init_r_trust_dom(r_u, num_trust_domains, trusted_domain);
185 DEBUG(6,("_net_trust_dom_list: %d\n", __LINE__));
190 /***********************************************************************************
191 init_net_r_srv_pwset:
192 ***********************************************************************************/
194 static void init_net_r_srv_pwset(NET_R_SRV_PWSET *r_s,
195 DOM_CRED *srv_cred, NTSTATUS status)
197 DEBUG(5,("init_net_r_srv_pwset: %d\n", __LINE__));
199 memcpy(&r_s->srv_cred, srv_cred, sizeof(r_s->srv_cred));
200 r_s->status = status;
202 DEBUG(5,("init_net_r_srv_pwset: %d\n", __LINE__));
205 /******************************************************************
206 gets a machine password entry. checks access rights of the host.
207 ******************************************************************/
209 static BOOL get_md4pw(char *md4pw, char *mach_acct)
211 SAM_ACCOUNT *sampass = NULL;
218 * Currently this code is redundent as we already have a filter
219 * by hostname list. What this code really needs to do is to
220 * get a hosts allowed/hosts denied list from the SAM database
221 * on a per user basis, and make the access decision there.
222 * I will leave this code here for now as a reminder to implement
223 * this at a later date. JRA.
226 if (!allow_access(lp_domain_hostsdeny(), lp_domain_hostsallow(),
227 client_name(), client_addr()))
229 DEBUG(0,("get_md4pw: Workstation %s denied access to domain\n", mach_acct));
234 if(!NT_STATUS_IS_OK(pdb_init_sam(&sampass)))
237 /* JRA. This is ok as it is only used for generating the challenge. */
239 ret=pdb_getsampwnam(sampass, mach_acct);
243 DEBUG(0,("get_md4pw: Workstation %s: no account in domain\n", mach_acct));
244 pdb_free_sam(&sampass);
248 acct_ctrl = pdb_get_acct_ctrl(sampass);
249 if (!(acct_ctrl & ACB_DISABLED) &&
250 ((acct_ctrl & ACB_DOMTRUST) ||
251 (acct_ctrl & ACB_WSTRUST) ||
252 (acct_ctrl & ACB_SVRTRUST)) &&
253 ((pass=pdb_get_nt_passwd(sampass)) != NULL)) {
254 memcpy(md4pw, pass, 16);
255 dump_data(5, md4pw, 16);
256 pdb_free_sam(&sampass);
260 DEBUG(0,("get_md4pw: Workstation %s: no account in domain\n", mach_acct));
261 pdb_free_sam(&sampass);
266 /*************************************************************************
268 *************************************************************************/
270 NTSTATUS _net_req_chal(pipes_struct *p, NET_Q_REQ_CHAL *q_u, NET_R_REQ_CHAL *r_u)
273 p->dc = TALLOC_ZERO_P(p->pipe_state_mem_ctx, struct dcinfo);
275 return NT_STATUS_NO_MEMORY;
278 DEBUG(10,("_net_req_chal: new challenge requested. Clearing old state.\n"));
282 rpcstr_pull(p->dc->remote_machine,
283 q_u->uni_logon_clnt.buffer,
284 sizeof(fstring),q_u->uni_logon_clnt.uni_str_len*2,0);
286 /* Save the client challenge to the server. */
287 memcpy(p->dc->clnt_chal.data, q_u->clnt_chal.data, sizeof(q_u->clnt_chal.data));
289 /* Create a server challenge for the client */
290 /* Set this to a random value. */
291 generate_random_buffer(p->dc->srv_chal.data, 8);
293 /* set up the LSA REQUEST CHALLENGE response */
294 init_net_r_req_chal(r_u, &p->dc->srv_chal, NT_STATUS_OK);
296 p->dc->challenge_sent = True;
301 /*************************************************************************
303 *************************************************************************/
305 static void init_net_r_auth(NET_R_AUTH *r_a, DOM_CHAL *resp_cred, NTSTATUS status)
307 memcpy(r_a->srv_chal.data, resp_cred->data, sizeof(resp_cred->data));
308 r_a->status = status;
311 /*************************************************************************
312 _net_auth. Create the initial credentials.
313 *************************************************************************/
315 NTSTATUS _net_auth(pipes_struct *p, NET_Q_AUTH *q_u, NET_R_AUTH *r_u)
318 fstring remote_machine;
319 DOM_CHAL srv_chal_out;
321 if (!p->dc || !p->dc->challenge_sent) {
322 return NT_STATUS_ACCESS_DENIED;
325 rpcstr_pull(mach_acct, q_u->clnt_id.uni_acct_name.buffer,sizeof(fstring),
326 q_u->clnt_id.uni_acct_name.uni_str_len*2,0);
327 rpcstr_pull(remote_machine, q_u->clnt_id.uni_comp_name.buffer,sizeof(fstring),
328 q_u->clnt_id.uni_comp_name.uni_str_len*2,0);
330 if (!get_md4pw((char *)p->dc->mach_pw, mach_acct)) {
331 DEBUG(0,("_net_auth: creds_server_check failed. Failed to "
332 "get pasword for machine account %s "
334 mach_acct, remote_machine ));
335 return NT_STATUS_ACCESS_DENIED;
338 /* From the client / server challenges and md4 password, generate sess key */
339 creds_server_init(p->dc,
340 &p->dc->clnt_chal, /* Stored client chal. */
341 &p->dc->srv_chal, /* Stored server chal. */
345 /* Check client credentials are valid. */
346 if (!creds_server_check(p->dc, &q_u->clnt_chal)) {
347 DEBUG(0,("_net_auth: creds_server_check failed. Rejecting auth "
348 "request from client %s machine account %s\n",
349 remote_machine, mach_acct ));
350 return NT_STATUS_ACCESS_DENIED;
353 fstrcpy(p->dc->mach_acct, mach_acct);
354 fstrcpy(p->dc->remote_machine, remote_machine);
355 p->dc->authenticated = True;
357 /* set up the LSA AUTH response */
358 /* Return the server credentials. */
359 init_net_r_auth(r_u, &srv_chal_out, NT_STATUS_OK);
364 /*************************************************************************
366 *************************************************************************/
368 static void init_net_r_auth_2(NET_R_AUTH_2 *r_a,
369 DOM_CHAL *resp_cred, NEG_FLAGS *flgs, NTSTATUS status)
371 memcpy(r_a->srv_chal.data, resp_cred->data, sizeof(resp_cred->data));
372 memcpy(&r_a->srv_flgs, flgs, sizeof(r_a->srv_flgs));
373 r_a->status = status;
376 /*************************************************************************
378 *************************************************************************/
380 NTSTATUS _net_auth_2(pipes_struct *p, NET_Q_AUTH_2 *q_u, NET_R_AUTH_2 *r_u)
384 fstring remote_machine;
385 DOM_CHAL srv_chal_out;
387 rpcstr_pull(mach_acct, q_u->clnt_id.uni_acct_name.buffer,sizeof(fstring),
388 q_u->clnt_id.uni_acct_name.uni_str_len*2,0);
389 rpcstr_pull(remote_machine, q_u->clnt_id.uni_comp_name.buffer,sizeof(fstring),
390 q_u->clnt_id.uni_comp_name.uni_str_len*2,0);
392 if (!p->dc || !p->dc->challenge_sent) {
393 DEBUG(0,("_net_auth2: no challenge sent to client %s\n",
395 return NT_STATUS_ACCESS_DENIED;
398 if ( (lp_server_schannel() == True) &&
399 ((q_u->clnt_flgs.neg_flags & NETLOGON_NEG_SCHANNEL) == 0) ) {
401 /* schannel must be used, but client did not offer it. */
402 DEBUG(0,("_net_auth2: schannel required but client failed "
403 "to offer it. Client was %s\n",
405 return NT_STATUS_ACCESS_DENIED;
408 if (!get_md4pw((char *)p->dc->mach_pw, mach_acct)) {
409 DEBUG(0,("_net_auth2: failed to get machine password for "
412 return NT_STATUS_ACCESS_DENIED;
415 /* From the client / server challenges and md4 password, generate sess key */
416 creds_server_init(p->dc,
417 &p->dc->clnt_chal, /* Stored client chal. */
418 &p->dc->srv_chal, /* Stored server chal. */
422 /* Check client credentials are valid. */
423 if (!creds_server_check(p->dc, &q_u->clnt_chal)) {
424 DEBUG(0,("_net_auth2: creds_server_check failed. Rejecting auth "
425 "request from client %s machine account %s\n",
426 remote_machine, mach_acct ));
427 return NT_STATUS_ACCESS_DENIED;
430 srv_flgs.neg_flags = 0x000001ff;
432 if (lp_server_schannel() != False) {
433 srv_flgs.neg_flags |= NETLOGON_NEG_SCHANNEL;
436 /* set up the LSA AUTH 2 response */
437 init_net_r_auth_2(r_u, &srv_chal_out, &srv_flgs, NT_STATUS_OK);
439 fstrcpy(p->dc->mach_acct, mach_acct);
440 fstrcpy(p->dc->remote_machine, remote_machine);
442 server_auth2_negotiated = True;
443 p->dc->authenticated = True;
444 last_dcinfo = *p->dc;
446 //secrets_store_schannel_session_info(p->dc);
450 /*************************************************************************
452 *************************************************************************/
454 NTSTATUS _net_srv_pwset(pipes_struct *p, NET_Q_SRV_PWSET *q_u, NET_R_SRV_PWSET *r_u)
456 NTSTATUS status = NT_STATUS_ACCESS_DENIED;
458 SAM_ACCOUNT *sampass=NULL;
460 unsigned char pwd[16];
466 if (!p->dc || !p->dc->authenticated) {
467 return NT_STATUS_INVALID_HANDLE;
470 /* Step the creds chain forward. */
471 if (!creds_server_step(p->dc, &q_u->clnt_id.cred, &cred_out)) {
472 DEBUG(0,("_net_srv_pwset: creds_server_step failed. Rejecting auth "
473 "request from client %s machine account %s\n",
474 p->dc->remote_machine, p->dc->mach_acct ));
475 return NT_STATUS_ACCESS_DENIED;
478 DEBUG(5,("_net_srv_pwset: %d\n", __LINE__));
480 rpcstr_pull(workstation,q_u->clnt_id.login.uni_comp_name.buffer,
481 sizeof(workstation),q_u->clnt_id.login.uni_comp_name.uni_str_len*2,0);
483 DEBUG(3,("_net_srv_pwset: Server Password Set by Wksta:[%s] on account [%s]\n",
484 workstation, p->dc->mach_acct));
486 pdb_init_sam(&sampass);
489 ret=pdb_getsampwnam(sampass, p->dc->mach_acct);
492 /* Ensure the account exists and is a machine account. */
494 acct_ctrl = pdb_get_acct_ctrl(sampass);
497 && (acct_ctrl & ACB_WSTRUST ||
498 acct_ctrl & ACB_SVRTRUST ||
499 acct_ctrl & ACB_DOMTRUST))) {
500 pdb_free_sam(&sampass);
501 return NT_STATUS_NO_SUCH_USER;
504 if (pdb_get_acct_ctrl(sampass) & ACB_DISABLED) {
505 pdb_free_sam(&sampass);
506 return NT_STATUS_ACCOUNT_DISABLED;
509 /* Woah - what does this to to the credential chain ? JRA */
510 cred_hash3( pwd, q_u->pwd, p->dc->sess_key, 0);
512 DEBUG(100,("Server password set : new given value was :\n"));
513 for(i = 0; i < sizeof(pwd); i++)
514 DEBUG(100,("%02X ", pwd[i]));
517 old_pw = pdb_get_nt_passwd(sampass);
519 if (old_pw && memcmp(pwd, old_pw, 16) == 0) {
520 /* Avoid backend modificiations and other fun if the
521 client changed the password to the *same thing* */
526 /* LM password should be NULL for machines */
527 if (!pdb_set_lanman_passwd(sampass, NULL, PDB_CHANGED)) {
528 pdb_free_sam(&sampass);
529 return NT_STATUS_NO_MEMORY;
532 if (!pdb_set_nt_passwd(sampass, pwd, PDB_CHANGED)) {
533 pdb_free_sam(&sampass);
534 return NT_STATUS_NO_MEMORY;
537 if (!pdb_set_pass_changed_now(sampass)) {
538 pdb_free_sam(&sampass);
539 /* Not quite sure what this one qualifies as, but this will do */
540 return NT_STATUS_UNSUCCESSFUL;
544 ret = pdb_update_sam_account (sampass);
548 status = NT_STATUS_OK;
551 /* set up the LSA Server Password Set response */
552 init_net_r_srv_pwset(r_u, &cred_out, status);
554 pdb_free_sam(&sampass);
558 /*************************************************************************
560 *************************************************************************/
562 NTSTATUS _net_sam_logoff(pipes_struct *p, NET_Q_SAM_LOGOFF *q_u, NET_R_SAM_LOGOFF *r_u)
564 if (!get_valid_user_struct(p->vuid))
565 return NT_STATUS_NO_SUCH_USER;
567 if (!p->dc || !p->dc->authenticated) {
568 return NT_STATUS_INVALID_HANDLE;
571 r_u->buffer_creds = 1; /* yes, we have valid server credentials */
573 /* checks and updates credentials. creates reply credentials */
574 if (!creds_server_step(p->dc, &q_u->sam_id.client.cred, &r_u->srv_creds)) {
575 DEBUG(0,("_net_sam_logoff: creds_server_step failed. Rejecting auth "
576 "request from client %s machine account %s\n",
577 p->dc->remote_machine, p->dc->mach_acct ));
578 return NT_STATUS_ACCESS_DENIED;
581 r_u->status = NT_STATUS_OK;
586 /*************************************************************************
588 *************************************************************************/
590 NTSTATUS _net_sam_logon(pipes_struct *p, NET_Q_SAM_LOGON *q_u, NET_R_SAM_LOGON *r_u)
592 NTSTATUS status = NT_STATUS_OK;
593 NET_USER_INFO_3 *usr_info = NULL;
594 NET_ID_INFO_CTR *ctr = q_u->sam_id.ctr;
595 UNISTR2 *uni_samlogon_user = NULL;
596 UNISTR2 *uni_samlogon_domain = NULL;
597 UNISTR2 *uni_samlogon_workstation = NULL;
598 fstring nt_username, nt_domain, nt_workstation;
599 auth_usersupplied_info *user_info = NULL;
600 auth_serversupplied_info *server_info = NULL;
602 struct auth_context *auth_context = NULL;
604 usr_info = TALLOC_P(p->mem_ctx, NET_USER_INFO_3);
606 return NT_STATUS_NO_MEMORY;
608 ZERO_STRUCTP(usr_info);
610 /* store the user information, if there is any. */
611 r_u->user = usr_info;
612 r_u->switch_value = 0; /* indicates no info */
613 r_u->auth_resp = 1; /* authoritative response */
614 r_u->switch_value = 3; /* indicates type of validation user info */
615 r_u->buffer_creds = 1; /* Ensure we always return server creds. */
617 if (!get_valid_user_struct(p->vuid))
618 return NT_STATUS_NO_SUCH_USER;
620 if (!p->dc || !p->dc->authenticated) {
621 return NT_STATUS_INVALID_HANDLE;
624 if ( (lp_server_schannel() == True) && (p->auth.auth_type != PIPE_AUTH_TYPE_SCHANNEL) ) {
625 /* 'server schannel = yes' should enforce use of
626 schannel, the client did offer it in auth2, but
627 obviously did not use it. */
628 DEBUG(0,("_net_sam_logoff: client %s not using schannel for netlogon\n",
629 p->dc->remote_machine ));
630 return NT_STATUS_ACCESS_DENIED;
633 /* checks and updates credentials. creates reply credentials */
634 if (!creds_server_step(p->dc, &q_u->sam_id.client.cred, &r_u->srv_creds)) {
635 DEBUG(0,("_net_sam_logoff: creds_server_step failed. Rejecting auth "
636 "request from client %s machine account %s\n",
637 p->dc->remote_machine, p->dc->mach_acct ));
638 return NT_STATUS_ACCESS_DENIED;
641 /* find the username */
643 switch (q_u->sam_id.logon_level) {
644 case INTERACTIVE_LOGON_TYPE:
645 uni_samlogon_user = &ctr->auth.id1.uni_user_name;
646 uni_samlogon_domain = &ctr->auth.id1.uni_domain_name;
648 uni_samlogon_workstation = &ctr->auth.id1.uni_wksta_name;
650 DEBUG(3,("SAM Logon (Interactive). Domain:[%s]. ", lp_workgroup()));
653 uni_samlogon_user = &ctr->auth.id2.uni_user_name;
654 uni_samlogon_domain = &ctr->auth.id2.uni_domain_name;
655 uni_samlogon_workstation = &ctr->auth.id2.uni_wksta_name;
657 DEBUG(3,("SAM Logon (Network). Domain:[%s]. ", lp_workgroup()));
660 DEBUG(2,("SAM Logon: unsupported switch value\n"));
661 return NT_STATUS_INVALID_INFO_CLASS;
664 rpcstr_pull(nt_username,uni_samlogon_user->buffer,sizeof(nt_username),uni_samlogon_user->uni_str_len*2,0);
665 rpcstr_pull(nt_domain,uni_samlogon_domain->buffer,sizeof(nt_domain),uni_samlogon_domain->uni_str_len*2,0);
666 rpcstr_pull(nt_workstation,uni_samlogon_workstation->buffer,sizeof(nt_workstation),uni_samlogon_workstation->uni_str_len*2,0);
668 DEBUG(3,("User:[%s@%s] Requested Domain:[%s]\n", nt_username,
669 nt_workstation, nt_domain));
671 fstrcpy(current_user_info.smb_name, nt_username);
672 sub_set_smb_name(nt_username);
674 DEBUG(5,("Attempting validation level %d for unmapped username %s.\n", q_u->sam_id.ctr->switch_value, nt_username));
676 status = NT_STATUS_OK;
678 switch (ctr->switch_value) {
681 const char *wksname = nt_workstation;
683 if (!NT_STATUS_IS_OK(status = make_auth_context_fixed(&auth_context, ctr->auth.id2.lm_chal))) {
687 /* For a network logon, the workstation name comes in with two
688 * backslashes in the front. Strip them if they are there. */
690 if (*wksname == '\\') wksname++;
691 if (*wksname == '\\') wksname++;
693 /* Standard challenge/response authenticaion */
694 if (!make_user_info_netlogon_network(&user_info,
695 nt_username, nt_domain,
697 ctr->auth.id2.lm_chal_resp.buffer,
698 ctr->auth.id2.lm_chal_resp.str_str_len,
699 ctr->auth.id2.nt_chal_resp.buffer,
700 ctr->auth.id2.nt_chal_resp.str_str_len)) {
701 status = NT_STATUS_NO_MEMORY;
705 case INTERACTIVE_LOGON_TYPE:
706 /* 'Interactive' autheticaion, supplies the password in its
707 MD4 form, encrypted with the session key. We will
708 convert this to chellange/responce for the auth
709 subsystem to chew on */
713 if (!NT_STATUS_IS_OK(status = make_auth_context_subsystem(&auth_context))) {
717 chal = auth_context->get_ntlm_challenge(auth_context);
719 if (!make_user_info_netlogon_interactive(&user_info,
720 nt_username, nt_domain,
721 nt_workstation, chal,
722 ctr->auth.id1.lm_owf.data,
723 ctr->auth.id1.nt_owf.data,
725 status = NT_STATUS_NO_MEMORY;
730 DEBUG(2,("SAM Logon: unsupported switch value\n"));
731 return NT_STATUS_INVALID_INFO_CLASS;
734 if ( NT_STATUS_IS_OK(status) ) {
735 status = auth_context->check_ntlm_password(auth_context,
736 user_info, &server_info);
739 (auth_context->free)(&auth_context);
740 free_user_info(&user_info);
742 DEBUG(5, ("_net_sam_logon: check_password returned status %s\n",
745 /* Check account and password */
747 if (!NT_STATUS_IS_OK(status)) {
748 /* If we don't know what this domain is, we need to
749 indicate that we are not authoritative. This
750 allows the client to decide if it needs to try
751 a local user. Fix by jpjanosi@us.ibm.com, #2976 */
752 if ( NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_USER)
753 && !strequal(nt_domain, get_global_sam_name())
754 && !is_trusted_domain(nt_domain) )
755 r_u->auth_resp = 0; /* We are not authoritative */
757 free_server_info(&server_info);
761 if (server_info->guest) {
762 /* We don't like guest domain logons... */
763 DEBUG(5,("_net_sam_logon: Attempted domain logon as GUEST denied.\n"));
764 free_server_info(&server_info);
765 return NT_STATUS_LOGON_FAILURE;
768 /* This is the point at which, if the login was successful, that
769 the SAM Local Security Authority should record that the user is
770 logged in to the domain. */
773 DOM_GID *gids = NULL;
774 const DOM_SID *user_sid = NULL;
775 const DOM_SID *group_sid = NULL;
777 uint32 user_rid, group_rid;
781 fstring user_sid_string;
782 fstring group_sid_string;
783 uchar user_session_key[16];
784 uchar lm_session_key[16];
785 uchar netlogon_sess_key[16];
787 sampw = server_info->sam_account;
789 /* set up pointer indicating user/password failed to be found */
790 usr_info->ptr_user_info = 0;
792 user_sid = pdb_get_user_sid(sampw);
793 group_sid = pdb_get_group_sid(sampw);
795 sid_copy(&domain_sid, user_sid);
796 sid_split_rid(&domain_sid, &user_rid);
798 if (!sid_peek_check_rid(&domain_sid, group_sid, &group_rid)) {
799 DEBUG(1, ("_net_sam_logon: user %s\\%s has user sid %s\n but group sid %s.\nThe conflicting domain portions are not supported for NETLOGON calls\n",
800 pdb_get_domain(sampw), pdb_get_username(sampw),
801 sid_to_string(user_sid_string, user_sid),
802 sid_to_string(group_sid_string, group_sid)));
803 return NT_STATUS_UNSUCCESSFUL;
807 if(server_info->login_server) {
808 pstrcpy(my_name, server_info->login_server);
810 pstrcpy(my_name, global_myname());
813 if (!NT_STATUS_IS_OK(status
814 = nt_token_to_group_list(p->mem_ctx,
822 ZERO_STRUCT(netlogon_sess_key);
823 memcpy(netlogon_sess_key, p->dc->sess_key, 8);
824 if (server_info->user_session_key.length) {
825 memcpy(user_session_key, server_info->user_session_key.data,
826 MIN(sizeof(user_session_key), server_info->user_session_key.length));
827 SamOEMhash(user_session_key, netlogon_sess_key, 16);
829 if (server_info->lm_session_key.length) {
830 memcpy(lm_session_key, server_info->lm_session_key.data,
831 MIN(sizeof(lm_session_key), server_info->lm_session_key.length));
832 SamOEMhash(lm_session_key, netlogon_sess_key, 16);
834 ZERO_STRUCT(netlogon_sess_key);
836 init_net_user_info3(p->mem_ctx, usr_info,
839 pdb_get_username(sampw),
840 pdb_get_fullname(sampw),
841 pdb_get_homedir(sampw),
842 pdb_get_dir_drive(sampw),
843 pdb_get_logon_script(sampw),
844 pdb_get_profile_path(sampw),
845 pdb_get_logon_time(sampw),
848 pdb_get_pass_last_set_time(sampw),
849 pdb_get_pass_can_change_time(sampw),
850 pdb_get_pass_must_change_time(sampw),
853 0, /* bad_pw_count */
854 num_gids, /* uint32 num_groups */
855 gids , /* DOM_GID *gids */
856 0x20 , /* uint32 user_flgs (?) */
857 server_info->user_session_key.length ? user_session_key : NULL,
858 server_info->lm_session_key.length ? lm_session_key : NULL,
859 my_name , /* char *logon_srv */
860 pdb_get_domain(sampw),
861 &domain_sid, /* DOM_SID *dom_sid */
862 /* Should be users domain sid, not servers - for trusted domains */
864 NULL); /* char *other_sids */
865 ZERO_STRUCT(user_session_key);
866 ZERO_STRUCT(lm_session_key);
868 free_server_info(&server_info);
872 /*************************************************************************
874 *************************************************************************/
875 #if 0 /* JERRY -- not correct */
876 NTSTATUS _ds_enum_dom_trusts(pipes_struct *p, DS_Q_ENUM_DOM_TRUSTS *q_u,
877 DS_R_ENUM_DOM_TRUSTS *r_u)
879 NTSTATUS status = NT_STATUS_OK;
881 /* TODO: According to MSDN, the can only be executed against a
882 DC or domain member running Windows 2000 or later. Need
883 to test against a standalone 2k server and see what it
884 does. A windows 2000 DC includes its own domain in the