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.
9 * Copyright (C) Guenther Deschner 2008.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <http://www.gnu.org/licenses/>.
25 /* This is the implementation of the netlogon pipe. */
29 extern userdom_struct current_user_info
;
32 #define DBGC_CLASS DBGC_RPC_SRV
34 /*************************************************************************
36 *************************************************************************/
38 static void init_net_r_req_chal(struct netr_Credential
*r
,
39 struct netr_Credential
*srv_chal
)
41 DEBUG(6,("init_net_r_req_chal: %d\n", __LINE__
));
43 memcpy(r
->data
, srv_chal
->data
, sizeof(r
->data
));
46 /*******************************************************************
47 Inits a netr_NETLOGON_INFO_1 structure.
48 ********************************************************************/
50 static void init_netlogon_info1(struct netr_NETLOGON_INFO_1
*r
,
52 uint32_t pdc_connection_status
)
55 r
->pdc_connection_status
= pdc_connection_status
;
58 /*******************************************************************
59 Inits a netr_NETLOGON_INFO_2 structure.
60 ********************************************************************/
62 static void init_netlogon_info2(struct netr_NETLOGON_INFO_2
*r
,
64 uint32_t pdc_connection_status
,
65 const char *trusted_dc_name
,
66 uint32_t tc_connection_status
)
69 r
->pdc_connection_status
= pdc_connection_status
;
70 r
->trusted_dc_name
= trusted_dc_name
;
71 r
->tc_connection_status
= tc_connection_status
;
74 /*******************************************************************
75 Inits a netr_NETLOGON_INFO_3 structure.
76 ********************************************************************/
78 static void init_netlogon_info3(struct netr_NETLOGON_INFO_3
*r
,
80 uint32_t logon_attempts
)
83 r
->logon_attempts
= logon_attempts
;
86 /*************************************************************************
88 *************************************************************************/
90 WERROR
_netr_LogonControl(pipes_struct
*p
,
91 struct netr_LogonControl
*r
)
93 struct netr_NETLOGON_INFO_1
*info1
;
95 uint32_t pdc_connection_status
= W_ERROR_V(WERR_OK
);
97 /* Setup the Logon Control response */
99 switch (r
->in
.level
) {
101 info1
= TALLOC_ZERO_P(p
->mem_ctx
, struct netr_NETLOGON_INFO_1
);
105 init_netlogon_info1(info1
,
107 pdc_connection_status
);
108 r
->out
.info
->info1
= info1
;
111 return WERR_UNKNOWN_LEVEL
;
117 /****************************************************************************
118 Send a message to smbd to do a sam synchronisation
119 **************************************************************************/
121 static void send_sync_message(void)
123 DEBUG(3, ("sending sam synchronisation message\n"));
124 message_send_all(smbd_messaging_context(), MSG_SMB_SAM_SYNC
, NULL
, 0,
128 /*************************************************************************
130 *************************************************************************/
132 WERROR
_netr_LogonControl2(pipes_struct
*p
,
133 struct netr_LogonControl2
*r
)
136 uint32 pdc_connection_status
= 0x0;
137 uint32 logon_attempts
= 0x0;
140 const char *dc_name
= NULL
;
141 struct sockaddr_storage dc_ss
;
142 const char *domain
= NULL
;
143 struct netr_NETLOGON_INFO_1
*info1
;
144 struct netr_NETLOGON_INFO_2
*info2
;
145 struct netr_NETLOGON_INFO_3
*info3
;
147 tc_status
= W_ERROR_V(WERR_NO_SUCH_DOMAIN
);
149 switch (r
->in
.function_code
) {
150 case NETLOGON_CONTROL_TC_QUERY
:
151 domain
= r
->in
.data
->domain
;
153 if ( !is_trusted_domain( domain
) )
156 if ( !get_dc_name( domain
, NULL
, dc_name2
, &dc_ss
) ) {
157 tc_status
= W_ERROR_V(WERR_NO_LOGON_SERVERS
);
161 dc_name
= talloc_asprintf(p
->mem_ctx
, "\\\\%s", dc_name2
);
166 tc_status
= W_ERROR_V(WERR_OK
);
170 case NETLOGON_CONTROL_REDISCOVER
:
171 domain
= r
->in
.data
->domain
;
173 if ( !is_trusted_domain( domain
) )
176 if ( !get_dc_name( domain
, NULL
, dc_name2
, &dc_ss
) ) {
177 tc_status
= W_ERROR_V(WERR_NO_LOGON_SERVERS
);
181 dc_name
= talloc_asprintf(p
->mem_ctx
, "\\\\%s", dc_name2
);
186 tc_status
= W_ERROR_V(WERR_OK
);
191 /* no idea what this should be */
192 DEBUG(0,("_netr_LogonControl2: unimplemented function level [%d]\n",
193 r
->in
.function_code
));
194 return WERR_UNKNOWN_LEVEL
;
197 /* prepare the response */
199 switch (r
->in
.level
) {
201 info1
= TALLOC_ZERO_P(p
->mem_ctx
, struct netr_NETLOGON_INFO_1
);
202 W_ERROR_HAVE_NO_MEMORY(info1
);
204 init_netlogon_info1(info1
,
206 pdc_connection_status
);
207 r
->out
.query
->info1
= info1
;
210 info2
= TALLOC_ZERO_P(p
->mem_ctx
, struct netr_NETLOGON_INFO_2
);
211 W_ERROR_HAVE_NO_MEMORY(info2
);
213 init_netlogon_info2(info2
,
215 pdc_connection_status
,
218 r
->out
.query
->info2
= info2
;
221 info3
= TALLOC_ZERO_P(p
->mem_ctx
, struct netr_NETLOGON_INFO_3
);
222 W_ERROR_HAVE_NO_MEMORY(info3
);
224 init_netlogon_info3(info3
,
227 r
->out
.query
->info3
= info3
;
230 return WERR_UNKNOWN_LEVEL
;
233 if (lp_server_role() == ROLE_DOMAIN_BDC
) {
240 /*************************************************************************
241 _netr_NetrEnumerateTrustedDomains
242 *************************************************************************/
244 WERROR
_netr_NetrEnumerateTrustedDomains(pipes_struct
*p
,
245 struct netr_NetrEnumerateTrustedDomains
*r
)
247 struct netr_Blob trusted_domains_blob
;
250 DEBUG(6,("_netr_NetrEnumerateTrustedDomains: %d\n", __LINE__
));
252 /* set up the Trusted Domain List response */
254 blob
= data_blob_talloc_zero(p
->mem_ctx
, 2);
255 trusted_domains_blob
.data
= blob
.data
;
256 trusted_domains_blob
.length
= blob
.length
;
258 DEBUG(6,("_netr_NetrEnumerateTrustedDomains: %d\n", __LINE__
));
260 *r
->out
.trusted_domains_blob
= trusted_domains_blob
;
265 /******************************************************************
266 gets a machine password entry. checks access rights of the host.
267 ******************************************************************/
269 static NTSTATUS
get_md4pw(char *md4pw
, const char *mach_acct
, uint16 sec_chan_type
)
271 struct samu
*sampass
= NULL
;
277 char addr
[INET6_ADDRSTRLEN
];
280 * Currently this code is redundent as we already have a filter
281 * by hostname list. What this code really needs to do is to
282 * get a hosts allowed/hosts denied list from the SAM database
283 * on a per user basis, and make the access decision there.
284 * I will leave this code here for now as a reminder to implement
285 * this at a later date. JRA.
288 if (!allow_access(lp_domain_hostsdeny(), lp_domain_hostsallow(),
289 client_name(get_client_fd()),
290 client_addr(get_client_fd(),addr
,sizeof(addr
)))) {
291 DEBUG(0,("get_md4pw: Workstation %s denied access to domain\n", mach_acct
));
296 if ( !(sampass
= samu_new( NULL
)) ) {
297 return NT_STATUS_NO_MEMORY
;
300 /* JRA. This is ok as it is only used for generating the challenge. */
302 ret
= pdb_getsampwnam(sampass
, mach_acct
);
306 DEBUG(0,("get_md4pw: Workstation %s: no account in domain\n", mach_acct
));
307 TALLOC_FREE(sampass
);
308 return NT_STATUS_ACCESS_DENIED
;
311 acct_ctrl
= pdb_get_acct_ctrl(sampass
);
312 if (acct_ctrl
& ACB_DISABLED
) {
313 DEBUG(0,("get_md4pw: Workstation %s: account is disabled\n", mach_acct
));
314 TALLOC_FREE(sampass
);
315 return NT_STATUS_ACCOUNT_DISABLED
;
318 if (!(acct_ctrl
& ACB_SVRTRUST
) &&
319 !(acct_ctrl
& ACB_WSTRUST
) &&
320 !(acct_ctrl
& ACB_DOMTRUST
))
322 DEBUG(0,("get_md4pw: Workstation %s: account is not a trust account\n", mach_acct
));
323 TALLOC_FREE(sampass
);
324 return NT_STATUS_NO_TRUST_SAM_ACCOUNT
;
327 switch (sec_chan_type
) {
329 if (!(acct_ctrl
& ACB_SVRTRUST
)) {
330 DEBUG(0,("get_md4pw: Workstation %s: BDC secure channel requested "
331 "but not a server trust account\n", mach_acct
));
332 TALLOC_FREE(sampass
);
333 return NT_STATUS_NO_TRUST_SAM_ACCOUNT
;
337 if (!(acct_ctrl
& ACB_WSTRUST
)) {
338 DEBUG(0,("get_md4pw: Workstation %s: WORKSTATION secure channel requested "
339 "but not a workstation trust account\n", mach_acct
));
340 TALLOC_FREE(sampass
);
341 return NT_STATUS_NO_TRUST_SAM_ACCOUNT
;
344 case SEC_CHAN_DOMAIN
:
345 if (!(acct_ctrl
& ACB_DOMTRUST
)) {
346 DEBUG(0,("get_md4pw: Workstation %s: DOMAIN secure channel requested "
347 "but not a interdomain trust account\n", mach_acct
));
348 TALLOC_FREE(sampass
);
349 return NT_STATUS_NO_TRUST_SAM_ACCOUNT
;
356 if ((pass
= pdb_get_nt_passwd(sampass
)) == NULL
) {
357 DEBUG(0,("get_md4pw: Workstation %s: account does not have a password\n", mach_acct
));
358 TALLOC_FREE(sampass
);
359 return NT_STATUS_LOGON_FAILURE
;
362 memcpy(md4pw
, pass
, 16);
363 dump_data(5, (uint8
*)md4pw
, 16);
365 TALLOC_FREE(sampass
);
372 /*************************************************************************
373 _netr_ServerReqChallenge
374 *************************************************************************/
376 NTSTATUS
_netr_ServerReqChallenge(pipes_struct
*p
,
377 struct netr_ServerReqChallenge
*r
)
380 p
->dc
= TALLOC_ZERO_P(p
, struct dcinfo
);
382 return NT_STATUS_NO_MEMORY
;
385 DEBUG(10,("_netr_ServerReqChallenge: new challenge requested. Clearing old state.\n"));
389 fstrcpy(p
->dc
->remote_machine
, r
->in
.computer_name
);
391 /* Save the client challenge to the server. */
392 memcpy(p
->dc
->clnt_chal
.data
, r
->in
.credentials
->data
,
393 sizeof(r
->in
.credentials
->data
));
395 /* Create a server challenge for the client */
396 /* Set this to a random value. */
397 generate_random_buffer(p
->dc
->srv_chal
.data
, 8);
399 /* set up the LSA REQUEST CHALLENGE response */
400 init_net_r_req_chal(r
->out
.return_credentials
, &p
->dc
->srv_chal
);
402 p
->dc
->challenge_sent
= True
;
407 /*************************************************************************
408 _netr_ServerAuthenticate
409 Create the initial credentials.
410 *************************************************************************/
412 NTSTATUS
_netr_ServerAuthenticate(pipes_struct
*p
,
413 struct netr_ServerAuthenticate
*r
)
416 struct netr_Credential srv_chal_out
;
418 if (!p
->dc
|| !p
->dc
->challenge_sent
) {
419 return NT_STATUS_ACCESS_DENIED
;
422 status
= get_md4pw((char *)p
->dc
->mach_pw
,
424 r
->in
.secure_channel_type
);
425 if (!NT_STATUS_IS_OK(status
)) {
426 DEBUG(0,("_netr_ServerAuthenticate: get_md4pw failed. Failed to "
427 "get password for machine account %s "
428 "from client %s: %s\n",
431 nt_errstr(status
) ));
432 /* always return NT_STATUS_ACCESS_DENIED */
433 return NT_STATUS_ACCESS_DENIED
;
436 /* From the client / server challenges and md4 password, generate sess key */
437 creds_server_init(0, /* No neg flags. */
439 &p
->dc
->clnt_chal
, /* Stored client chal. */
440 &p
->dc
->srv_chal
, /* Stored server chal. */
444 /* Check client credentials are valid. */
445 if (!netlogon_creds_server_check(p
->dc
, r
->in
.credentials
)) {
446 DEBUG(0,("_netr_ServerAuthenticate: netlogon_creds_server_check failed. Rejecting auth "
447 "request from client %s machine account %s\n",
449 r
->in
.account_name
));
450 return NT_STATUS_ACCESS_DENIED
;
453 fstrcpy(p
->dc
->mach_acct
, r
->in
.account_name
);
454 fstrcpy(p
->dc
->remote_machine
, r
->in
.computer_name
);
455 p
->dc
->authenticated
= True
;
457 /* set up the LSA AUTH response */
458 /* Return the server credentials. */
460 memcpy(r
->out
.return_credentials
->data
, &srv_chal_out
.data
,
461 sizeof(r
->out
.return_credentials
->data
));
466 /*************************************************************************
467 _netr_ServerAuthenticate2
468 *************************************************************************/
470 NTSTATUS
_netr_ServerAuthenticate2(pipes_struct
*p
,
471 struct netr_ServerAuthenticate2
*r
)
475 struct netr_Credential srv_chal_out
;
477 /* We use this as the key to store the creds: */
478 /* r->in.computer_name */
480 if (!p
->dc
|| !p
->dc
->challenge_sent
) {
481 DEBUG(0,("_netr_ServerAuthenticate2: no challenge sent to client %s\n",
482 r
->in
.computer_name
));
483 return NT_STATUS_ACCESS_DENIED
;
486 if ( (lp_server_schannel() == true) &&
487 ((*r
->in
.negotiate_flags
& NETLOGON_NEG_SCHANNEL
) == 0) ) {
489 /* schannel must be used, but client did not offer it. */
490 DEBUG(0,("_netr_ServerAuthenticate2: schannel required but client failed "
491 "to offer it. Client was %s\n",
492 r
->in
.account_name
));
493 return NT_STATUS_ACCESS_DENIED
;
496 status
= get_md4pw((char *)p
->dc
->mach_pw
,
498 r
->in
.secure_channel_type
);
499 if (!NT_STATUS_IS_OK(status
)) {
500 DEBUG(0,("_netr_ServerAuthenticate2: failed to get machine password for "
502 r
->in
.account_name
, nt_errstr(status
) ));
503 /* always return NT_STATUS_ACCESS_DENIED */
504 return NT_STATUS_ACCESS_DENIED
;
507 /* From the client / server challenges and md4 password, generate sess key */
508 creds_server_init(*r
->in
.negotiate_flags
,
510 &p
->dc
->clnt_chal
, /* Stored client chal. */
511 &p
->dc
->srv_chal
, /* Stored server chal. */
515 /* Check client credentials are valid. */
516 if (!netlogon_creds_server_check(p
->dc
, r
->in
.credentials
)) {
517 DEBUG(0,("_netr_ServerAuthenticate2: netlogon_creds_server_check failed. Rejecting auth "
518 "request from client %s machine account %s\n",
520 r
->in
.account_name
));
521 return NT_STATUS_ACCESS_DENIED
;
524 srv_flgs
= 0x000001ff;
526 if (lp_server_schannel() != false) {
527 srv_flgs
|= NETLOGON_NEG_SCHANNEL
;
530 /* set up the LSA AUTH 2 response */
531 memcpy(r
->out
.return_credentials
->data
, &srv_chal_out
.data
,
532 sizeof(r
->out
.return_credentials
->data
));
533 *r
->out
.negotiate_flags
= srv_flgs
;
535 fstrcpy(p
->dc
->mach_acct
, r
->in
.account_name
);
536 fstrcpy(p
->dc
->remote_machine
, r
->in
.computer_name
);
537 fstrcpy(p
->dc
->domain
, lp_workgroup() );
539 p
->dc
->authenticated
= True
;
541 /* Store off the state so we can continue after client disconnect. */
543 secrets_store_schannel_session_info(p
->mem_ctx
,
551 /*************************************************************************
552 _netr_ServerPasswordSet
553 *************************************************************************/
555 NTSTATUS
_netr_ServerPasswordSet(pipes_struct
*p
,
556 struct netr_ServerPasswordSet
*r
)
558 NTSTATUS status
= NT_STATUS_OK
;
559 fstring remote_machine
;
560 struct samu
*sampass
=NULL
;
562 unsigned char pwd
[16];
565 struct netr_Authenticator cred_out
;
568 DEBUG(5,("_netr_ServerPasswordSet: %d\n", __LINE__
));
570 /* We need the remote machine name for the creds lookup. */
571 fstrcpy(remote_machine
, r
->in
.computer_name
);
573 if ( (lp_server_schannel() == True
) && (p
->auth
.auth_type
!= PIPE_AUTH_TYPE_SCHANNEL
) ) {
574 /* 'server schannel = yes' should enforce use of
575 schannel, the client did offer it in auth2, but
576 obviously did not use it. */
577 DEBUG(0,("_netr_ServerPasswordSet: client %s not using schannel for netlogon\n",
579 return NT_STATUS_ACCESS_DENIED
;
583 /* Restore the saved state of the netlogon creds. */
585 ret
= secrets_restore_schannel_session_info(p
, remote_machine
,
589 return NT_STATUS_INVALID_HANDLE
;
593 if (!p
->dc
|| !p
->dc
->authenticated
) {
594 return NT_STATUS_INVALID_HANDLE
;
597 DEBUG(3,("_netr_ServerPasswordSet: Server Password Set by remote machine:[%s] on account [%s]\n",
598 remote_machine
, p
->dc
->mach_acct
));
600 /* Step the creds chain forward. */
601 if (!netlogon_creds_server_step(p
->dc
, r
->in
.credential
, &cred_out
)) {
602 DEBUG(2,("_netr_ServerPasswordSet: netlogon_creds_server_step failed. Rejecting auth "
603 "request from client %s machine account %s\n",
604 remote_machine
, p
->dc
->mach_acct
));
605 return NT_STATUS_INVALID_PARAMETER
;
608 /* We must store the creds state after an update. */
609 sampass
= samu_new( NULL
);
611 return NT_STATUS_NO_MEMORY
;
615 secrets_store_schannel_session_info(p
, remote_machine
, p
->dc
);
616 ret
= pdb_getsampwnam(sampass
, p
->dc
->mach_acct
);
620 TALLOC_FREE(sampass
);
621 return NT_STATUS_ACCESS_DENIED
;
624 /* Ensure the account exists and is a machine account. */
626 acct_ctrl
= pdb_get_acct_ctrl(sampass
);
628 if (!(acct_ctrl
& ACB_WSTRUST
||
629 acct_ctrl
& ACB_SVRTRUST
||
630 acct_ctrl
& ACB_DOMTRUST
)) {
631 TALLOC_FREE(sampass
);
632 return NT_STATUS_NO_SUCH_USER
;
635 if (pdb_get_acct_ctrl(sampass
) & ACB_DISABLED
) {
636 TALLOC_FREE(sampass
);
637 return NT_STATUS_ACCOUNT_DISABLED
;
640 /* Woah - what does this to to the credential chain ? JRA */
641 cred_hash3(pwd
, r
->in
.new_password
->hash
, p
->dc
->sess_key
, 0);
643 DEBUG(100,("_netr_ServerPasswordSet: new given value was :\n"));
644 for(i
= 0; i
< sizeof(pwd
); i
++)
645 DEBUG(100,("%02X ", pwd
[i
]));
648 old_pw
= pdb_get_nt_passwd(sampass
);
650 if (old_pw
&& memcmp(pwd
, old_pw
, 16) == 0) {
651 /* Avoid backend modificiations and other fun if the
652 client changed the password to the *same thing* */
657 /* LM password should be NULL for machines */
658 if (!pdb_set_lanman_passwd(sampass
, NULL
, PDB_CHANGED
)) {
659 TALLOC_FREE(sampass
);
660 return NT_STATUS_NO_MEMORY
;
663 if (!pdb_set_nt_passwd(sampass
, pwd
, PDB_CHANGED
)) {
664 TALLOC_FREE(sampass
);
665 return NT_STATUS_NO_MEMORY
;
668 if (!pdb_set_pass_last_set_time(sampass
, time(NULL
), PDB_CHANGED
)) {
669 TALLOC_FREE(sampass
);
670 /* Not quite sure what this one qualifies as, but this will do */
671 return NT_STATUS_UNSUCCESSFUL
;
675 status
= pdb_update_sam_account(sampass
);
679 /* set up the LSA Server Password Set response */
681 memcpy(r
->out
.return_authenticator
, &cred_out
,
682 sizeof(r
->out
.return_authenticator
));
684 TALLOC_FREE(sampass
);
688 /*************************************************************************
690 *************************************************************************/
692 NTSTATUS
_netr_LogonSamLogoff(pipes_struct
*p
,
693 struct netr_LogonSamLogoff
*r
)
695 if ( (lp_server_schannel() == True
) && (p
->auth
.auth_type
!= PIPE_AUTH_TYPE_SCHANNEL
) ) {
696 /* 'server schannel = yes' should enforce use of
697 schannel, the client did offer it in auth2, but
698 obviously did not use it. */
699 DEBUG(0,("_netr_LogonSamLogoff: client %s not using schannel for netlogon\n",
700 get_remote_machine_name() ));
701 return NT_STATUS_ACCESS_DENIED
;
705 /* Using the remote machine name for the creds store: */
706 /* r->in.computer_name */
709 /* Restore the saved state of the netlogon creds. */
713 ret
= secrets_restore_schannel_session_info(
714 p
, r
->in
.computer_name
, &p
->dc
);
717 return NT_STATUS_INVALID_HANDLE
;
721 if (!p
->dc
|| !p
->dc
->authenticated
) {
722 return NT_STATUS_INVALID_HANDLE
;
725 /* checks and updates credentials. creates reply credentials */
726 if (!netlogon_creds_server_step(p
->dc
, r
->in
.credential
, r
->out
.return_authenticator
)) {
727 DEBUG(2,("_netr_LogonSamLogoff: netlogon_creds_server_step failed. Rejecting auth "
728 "request from client %s machine account %s\n",
729 r
->in
.computer_name
, p
->dc
->mach_acct
));
730 return NT_STATUS_INVALID_PARAMETER
;
733 /* We must store the creds state after an update. */
735 secrets_store_schannel_session_info(p
, r
->in
.computer_name
, p
->dc
);
741 /*************************************************************************
743 *************************************************************************/
745 NTSTATUS
_netr_LogonSamLogon(pipes_struct
*p
,
746 struct netr_LogonSamLogon
*r
)
748 NTSTATUS status
= NT_STATUS_OK
;
749 struct netr_SamInfo3
*sam3
= NULL
;
750 union netr_LogonInfo
*logon
= r
->in
.logon
;
751 fstring nt_username
, nt_domain
, nt_workstation
;
752 auth_usersupplied_info
*user_info
= NULL
;
753 auth_serversupplied_info
*server_info
= NULL
;
754 struct auth_context
*auth_context
= NULL
;
755 uint8_t pipe_session_key
[16];
756 bool process_creds
= true;
758 switch (p
->hdr_req
.opnum
) {
759 case NDR_NETR_LOGONSAMLOGON
:
760 process_creds
= true;
762 case NDR_NETR_LOGONSAMLOGONEX
:
764 process_creds
= false;
767 if ( (lp_server_schannel() == True
) && (p
->auth
.auth_type
!= PIPE_AUTH_TYPE_SCHANNEL
) ) {
768 /* 'server schannel = yes' should enforce use of
769 schannel, the client did offer it in auth2, but
770 obviously did not use it. */
771 DEBUG(0,("_netr_LogonSamLogon: client %s not using schannel for netlogon\n",
772 get_remote_machine_name() ));
773 return NT_STATUS_ACCESS_DENIED
;
776 sam3
= TALLOC_ZERO_P(p
->mem_ctx
, struct netr_SamInfo3
);
778 return NT_STATUS_NO_MEMORY
;
781 /* store the user information, if there is any. */
782 r
->out
.validation
->sam3
= sam3
;
783 *r
->out
.authoritative
= true; /* authoritative response */
784 if (r
->in
.validation_level
!= 2 && r
->in
.validation_level
!= 3) {
785 DEBUG(0,("_netr_LogonSamLogon: bad validation_level value %d.\n",
786 (int)r
->in
.validation_level
));
787 return NT_STATUS_ACCESS_DENIED
;
791 fstring remote_machine
;
793 /* Get the remote machine name for the creds store. */
794 /* Note this is the remote machine this request is coming from (member server),
795 not neccessarily the workstation name the user is logging onto.
798 fstrcpy(remote_machine
, r
->in
.computer_name
);
801 /* Restore the saved state of the netlogon creds. */
805 ret
= secrets_restore_schannel_session_info(
806 p
, remote_machine
, &p
->dc
);
809 return NT_STATUS_INVALID_HANDLE
;
813 if (!p
->dc
|| !p
->dc
->authenticated
) {
814 return NT_STATUS_INVALID_HANDLE
;
817 /* checks and updates credentials. creates reply credentials */
818 if (!netlogon_creds_server_step(p
->dc
, r
->in
.credential
, r
->out
.return_authenticator
)) {
819 DEBUG(2,("_netr_LogonSamLogon: creds_server_step failed. Rejecting auth "
820 "request from client %s machine account %s\n",
821 remote_machine
, p
->dc
->mach_acct
));
822 return NT_STATUS_INVALID_PARAMETER
;
825 /* We must store the creds state after an update. */
827 secrets_store_schannel_session_info(p
, remote_machine
, p
->dc
);
831 switch (r
->in
.logon_level
) {
832 case INTERACTIVE_LOGON_TYPE
:
834 logon
->password
->identity_info
.account_name
.string
);
836 logon
->password
->identity_info
.domain_name
.string
);
837 fstrcpy(nt_workstation
,
838 logon
->password
->identity_info
.workstation
.string
);
840 DEBUG(3,("SAM Logon (Interactive). Domain:[%s]. ", lp_workgroup()));
844 logon
->network
->identity_info
.account_name
.string
);
846 logon
->network
->identity_info
.domain_name
.string
);
847 fstrcpy(nt_workstation
,
848 logon
->network
->identity_info
.workstation
.string
);
850 DEBUG(3,("SAM Logon (Network). Domain:[%s]. ", lp_workgroup()));
853 DEBUG(2,("SAM Logon: unsupported switch value\n"));
854 return NT_STATUS_INVALID_INFO_CLASS
;
857 DEBUG(3,("User:[%s@%s] Requested Domain:[%s]\n", nt_username
, nt_workstation
, nt_domain
));
858 fstrcpy(current_user_info
.smb_name
, nt_username
);
859 sub_set_smb_name(nt_username
);
861 DEBUG(5,("Attempting validation level %d for unmapped username %s.\n",
862 r
->in
.validation_level
, nt_username
));
864 status
= NT_STATUS_OK
;
866 switch (r
->in
.logon_level
) {
869 const char *wksname
= nt_workstation
;
871 status
= make_auth_context_fixed(&auth_context
,
872 logon
->network
->challenge
);
873 if (!NT_STATUS_IS_OK(status
)) {
877 /* For a network logon, the workstation name comes in with two
878 * backslashes in the front. Strip them if they are there. */
880 if (*wksname
== '\\') wksname
++;
881 if (*wksname
== '\\') wksname
++;
883 /* Standard challenge/response authenticaion */
884 if (!make_user_info_netlogon_network(&user_info
,
885 nt_username
, nt_domain
,
887 logon
->network
->identity_info
.parameter_control
,
888 logon
->network
->lm
.data
,
889 logon
->network
->lm
.length
,
890 logon
->network
->nt
.data
,
891 logon
->network
->nt
.length
)) {
892 status
= NT_STATUS_NO_MEMORY
;
896 case INTERACTIVE_LOGON_TYPE
:
897 /* 'Interactive' authentication, supplies the password in its
898 MD4 form, encrypted with the session key. We will convert
899 this to challenge/response for the auth subsystem to chew
904 if (!NT_STATUS_IS_OK(status
= make_auth_context_subsystem(&auth_context
))) {
908 chal
= auth_context
->get_ntlm_challenge(auth_context
);
910 if (!make_user_info_netlogon_interactive(&user_info
,
911 nt_username
, nt_domain
,
913 logon
->password
->identity_info
.parameter_control
,
915 logon
->password
->lmpassword
.hash
,
916 logon
->password
->ntpassword
.hash
,
918 status
= NT_STATUS_NO_MEMORY
;
923 DEBUG(2,("SAM Logon: unsupported switch value\n"));
924 return NT_STATUS_INVALID_INFO_CLASS
;
927 if ( NT_STATUS_IS_OK(status
) ) {
928 status
= auth_context
->check_ntlm_password(auth_context
,
929 user_info
, &server_info
);
932 (auth_context
->free
)(&auth_context
);
933 free_user_info(&user_info
);
935 DEBUG(5,("_netr_LogonSamLogon: check_password returned status %s\n",
938 /* Check account and password */
940 if (!NT_STATUS_IS_OK(status
)) {
941 /* If we don't know what this domain is, we need to
942 indicate that we are not authoritative. This
943 allows the client to decide if it needs to try
944 a local user. Fix by jpjanosi@us.ibm.com, #2976 */
945 if ( NT_STATUS_EQUAL(status
, NT_STATUS_NO_SUCH_USER
)
946 && !strequal(nt_domain
, get_global_sam_name())
947 && !is_trusted_domain(nt_domain
) )
948 *r
->out
.authoritative
= false; /* We are not authoritative */
950 TALLOC_FREE(server_info
);
954 if (server_info
->guest
) {
955 /* We don't like guest domain logons... */
956 DEBUG(5,("_netr_LogonSamLogon: Attempted domain logon as GUEST "
958 TALLOC_FREE(server_info
);
959 return NT_STATUS_LOGON_FAILURE
;
962 /* This is the point at which, if the login was successful, that
963 the SAM Local Security Authority should record that the user is
964 logged in to the domain. */
967 /* Get the pipe session key from the creds. */
968 memcpy(pipe_session_key
, p
->dc
->sess_key
, 16);
970 /* Get the pipe session key from the schannel. */
971 if ((p
->auth
.auth_type
!= PIPE_AUTH_TYPE_SCHANNEL
)
972 || (p
->auth
.a_u
.schannel_auth
== NULL
)) {
973 return NT_STATUS_INVALID_HANDLE
;
975 memcpy(pipe_session_key
, p
->auth
.a_u
.schannel_auth
->sess_key
, 16);
978 status
= serverinfo_to_SamInfo3(server_info
, pipe_session_key
, sam3
);
979 TALLOC_FREE(server_info
);
983 /*************************************************************************
984 _netr_LogonSamLogonEx
985 - no credential chaining. Map into net sam logon.
986 *************************************************************************/
988 NTSTATUS
_netr_LogonSamLogonEx(pipes_struct
*p
,
989 struct netr_LogonSamLogonEx
*r
)
991 struct netr_LogonSamLogon q
;
993 /* Only allow this if the pipe is protected. */
994 if (p
->auth
.auth_type
!= PIPE_AUTH_TYPE_SCHANNEL
) {
995 DEBUG(0,("_net_sam_logon_ex: client %s not using schannel for netlogon\n",
996 get_remote_machine_name() ));
997 return NT_STATUS_INVALID_PARAMETER
;
1000 q
.in
.server_name
= r
->in
.server_name
;
1001 q
.in
.computer_name
= r
->in
.computer_name
;
1002 q
.in
.logon_level
= r
->in
.logon_level
;
1003 q
.in
.logon
= r
->in
.logon
;
1004 q
.in
.validation_level
= r
->in
.validation_level
;
1005 /* we do not handle the flags */
1006 /* = r->in.flags; */
1008 q
.out
.validation
= r
->out
.validation
;
1009 q
.out
.authoritative
= r
->out
.authoritative
;
1010 /* we do not handle the flags */
1011 /* = r->out.flags; */
1013 return _netr_LogonSamLogon(p
, &q
);
1016 /*************************************************************************
1018 *************************************************************************/
1019 #if 0 /* JERRY -- not correct */
1020 NTSTATUS
_ds_enum_dom_trusts(pipes_struct
*p
, DS_Q_ENUM_DOM_TRUSTS
*q_u
,
1021 DS_R_ENUM_DOM_TRUSTS
*r_u
)
1023 NTSTATUS status
= NT_STATUS_OK
;
1025 /* TODO: According to MSDN, the can only be executed against a
1026 DC or domain member running Windows 2000 or later. Need
1027 to test against a standalone 2k server and see what it
1028 does. A windows 2000 DC includes its own domain in the
1036 /****************************************************************
1037 ****************************************************************/
1039 WERROR
_netr_LogonUasLogon(pipes_struct
*p
,
1040 struct netr_LogonUasLogon
*r
)
1042 p
->rng_fault_state
= true;
1043 return WERR_NOT_SUPPORTED
;
1046 /****************************************************************
1047 ****************************************************************/
1049 WERROR
_netr_LogonUasLogoff(pipes_struct
*p
,
1050 struct netr_LogonUasLogoff
*r
)
1052 p
->rng_fault_state
= true;
1053 return WERR_NOT_SUPPORTED
;
1056 /****************************************************************
1057 ****************************************************************/
1059 NTSTATUS
_netr_DatabaseDeltas(pipes_struct
*p
,
1060 struct netr_DatabaseDeltas
*r
)
1062 p
->rng_fault_state
= true;
1063 return NT_STATUS_NOT_IMPLEMENTED
;
1066 /****************************************************************
1067 ****************************************************************/
1069 NTSTATUS
_netr_DatabaseSync(pipes_struct
*p
,
1070 struct netr_DatabaseSync
*r
)
1072 p
->rng_fault_state
= true;
1073 return NT_STATUS_NOT_IMPLEMENTED
;
1076 /****************************************************************
1077 ****************************************************************/
1079 NTSTATUS
_netr_AccountDeltas(pipes_struct
*p
,
1080 struct netr_AccountDeltas
*r
)
1082 p
->rng_fault_state
= true;
1083 return NT_STATUS_NOT_IMPLEMENTED
;
1086 /****************************************************************
1087 ****************************************************************/
1089 NTSTATUS
_netr_AccountSync(pipes_struct
*p
,
1090 struct netr_AccountSync
*r
)
1092 p
->rng_fault_state
= true;
1093 return NT_STATUS_NOT_IMPLEMENTED
;
1096 /****************************************************************
1097 ****************************************************************/
1099 WERROR
_netr_GetDcName(pipes_struct
*p
,
1100 struct netr_GetDcName
*r
)
1102 p
->rng_fault_state
= true;
1103 return WERR_NOT_SUPPORTED
;
1106 /****************************************************************
1107 ****************************************************************/
1109 WERROR
_netr_GetAnyDCName(pipes_struct
*p
,
1110 struct netr_GetAnyDCName
*r
)
1112 p
->rng_fault_state
= true;
1113 return WERR_NOT_SUPPORTED
;
1116 /****************************************************************
1117 ****************************************************************/
1119 NTSTATUS
_netr_DatabaseSync2(pipes_struct
*p
,
1120 struct netr_DatabaseSync2
*r
)
1122 p
->rng_fault_state
= true;
1123 return NT_STATUS_NOT_IMPLEMENTED
;
1126 /****************************************************************
1127 ****************************************************************/
1129 NTSTATUS
_netr_DatabaseRedo(pipes_struct
*p
,
1130 struct netr_DatabaseRedo
*r
)
1132 p
->rng_fault_state
= true;
1133 return NT_STATUS_NOT_IMPLEMENTED
;
1136 /****************************************************************
1137 ****************************************************************/
1139 WERROR
_netr_LogonControl2Ex(pipes_struct
*p
,
1140 struct netr_LogonControl2Ex
*r
)
1142 p
->rng_fault_state
= true;
1143 return WERR_NOT_SUPPORTED
;
1146 /****************************************************************
1147 ****************************************************************/
1149 WERROR
_netr_DsRGetDCName(pipes_struct
*p
,
1150 struct netr_DsRGetDCName
*r
)
1152 p
->rng_fault_state
= true;
1153 return WERR_NOT_SUPPORTED
;
1156 /****************************************************************
1157 ****************************************************************/
1159 WERROR
_netr_NETRLOGONDUMMYROUTINE1(pipes_struct
*p
,
1160 struct netr_NETRLOGONDUMMYROUTINE1
*r
)
1162 p
->rng_fault_state
= true;
1163 return WERR_NOT_SUPPORTED
;
1166 /****************************************************************
1167 ****************************************************************/
1169 WERROR
_netr_NETRLOGONSETSERVICEBITS(pipes_struct
*p
,
1170 struct netr_NETRLOGONSETSERVICEBITS
*r
)
1172 p
->rng_fault_state
= true;
1173 return WERR_NOT_SUPPORTED
;
1176 /****************************************************************
1177 ****************************************************************/
1179 WERROR
_netr_LogonGetTrustRid(pipes_struct
*p
,
1180 struct netr_LogonGetTrustRid
*r
)
1182 p
->rng_fault_state
= true;
1183 return WERR_NOT_SUPPORTED
;
1186 /****************************************************************
1187 ****************************************************************/
1189 WERROR
_netr_NETRLOGONCOMPUTESERVERDIGEST(pipes_struct
*p
,
1190 struct netr_NETRLOGONCOMPUTESERVERDIGEST
*r
)
1192 p
->rng_fault_state
= true;
1193 return WERR_NOT_SUPPORTED
;
1196 /****************************************************************
1197 ****************************************************************/
1199 WERROR
_netr_NETRLOGONCOMPUTECLIENTDIGEST(pipes_struct
*p
,
1200 struct netr_NETRLOGONCOMPUTECLIENTDIGEST
*r
)
1202 p
->rng_fault_state
= true;
1203 return WERR_NOT_SUPPORTED
;
1206 /****************************************************************
1207 ****************************************************************/
1209 NTSTATUS
_netr_ServerAuthenticate3(pipes_struct
*p
,
1210 struct netr_ServerAuthenticate3
*r
)
1212 p
->rng_fault_state
= true;
1213 return NT_STATUS_NOT_IMPLEMENTED
;
1216 /****************************************************************
1217 ****************************************************************/
1219 WERROR
_netr_DsRGetDCNameEx(pipes_struct
*p
,
1220 struct netr_DsRGetDCNameEx
*r
)
1222 p
->rng_fault_state
= true;
1223 return WERR_NOT_SUPPORTED
;
1226 /****************************************************************
1227 ****************************************************************/
1229 WERROR
_netr_DsRGetSiteName(pipes_struct
*p
,
1230 struct netr_DsRGetSiteName
*r
)
1232 p
->rng_fault_state
= true;
1233 return WERR_NOT_SUPPORTED
;
1236 /****************************************************************
1237 ****************************************************************/
1239 NTSTATUS
_netr_LogonGetDomainInfo(pipes_struct
*p
,
1240 struct netr_LogonGetDomainInfo
*r
)
1242 p
->rng_fault_state
= true;
1243 return NT_STATUS_NOT_IMPLEMENTED
;
1246 /****************************************************************
1247 ****************************************************************/
1249 NTSTATUS
_netr_ServerPasswordSet2(pipes_struct
*p
,
1250 struct netr_ServerPasswordSet2
*r
)
1252 p
->rng_fault_state
= true;
1253 return NT_STATUS_NOT_IMPLEMENTED
;
1256 /****************************************************************
1257 ****************************************************************/
1259 WERROR
_netr_ServerPasswordGet(pipes_struct
*p
,
1260 struct netr_ServerPasswordGet
*r
)
1262 p
->rng_fault_state
= true;
1263 return WERR_NOT_SUPPORTED
;
1266 /****************************************************************
1267 ****************************************************************/
1269 WERROR
_netr_NETRLOGONSENDTOSAM(pipes_struct
*p
,
1270 struct netr_NETRLOGONSENDTOSAM
*r
)
1272 p
->rng_fault_state
= true;
1273 return WERR_NOT_SUPPORTED
;
1276 /****************************************************************
1277 ****************************************************************/
1279 WERROR
_netr_DsRAddressToSitenamesW(pipes_struct
*p
,
1280 struct netr_DsRAddressToSitenamesW
*r
)
1282 p
->rng_fault_state
= true;
1283 return WERR_NOT_SUPPORTED
;
1286 /****************************************************************
1287 ****************************************************************/
1289 WERROR
_netr_DsRGetDCNameEx2(pipes_struct
*p
,
1290 struct netr_DsRGetDCNameEx2
*r
)
1292 p
->rng_fault_state
= true;
1293 return WERR_NOT_SUPPORTED
;
1296 /****************************************************************
1297 ****************************************************************/
1299 WERROR
_netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN(pipes_struct
*p
,
1300 struct netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN
*r
)
1302 p
->rng_fault_state
= true;
1303 return WERR_NOT_SUPPORTED
;
1306 /****************************************************************
1307 ****************************************************************/
1309 WERROR
_netr_NetrEnumerateTrustedDomainsEx(pipes_struct
*p
,
1310 struct netr_NetrEnumerateTrustedDomainsEx
*r
)
1312 p
->rng_fault_state
= true;
1313 return WERR_NOT_SUPPORTED
;
1316 /****************************************************************
1317 ****************************************************************/
1319 WERROR
_netr_DsRAddressToSitenamesExW(pipes_struct
*p
,
1320 struct netr_DsRAddressToSitenamesExW
*r
)
1322 p
->rng_fault_state
= true;
1323 return WERR_NOT_SUPPORTED
;
1326 /****************************************************************
1327 ****************************************************************/
1329 WERROR
_netr_DsrGetDcSiteCoverageW(pipes_struct
*p
,
1330 struct netr_DsrGetDcSiteCoverageW
*r
)
1332 p
->rng_fault_state
= true;
1333 return WERR_NOT_SUPPORTED
;
1336 /****************************************************************
1337 ****************************************************************/
1339 WERROR
_netr_DsrEnumerateDomainTrusts(pipes_struct
*p
,
1340 struct netr_DsrEnumerateDomainTrusts
*r
)
1342 p
->rng_fault_state
= true;
1343 return WERR_NOT_SUPPORTED
;
1346 /****************************************************************
1347 ****************************************************************/
1349 WERROR
_netr_DsrDeregisterDNSHostRecords(pipes_struct
*p
,
1350 struct netr_DsrDeregisterDNSHostRecords
*r
)
1352 p
->rng_fault_state
= true;
1353 return WERR_NOT_SUPPORTED
;
1356 /****************************************************************
1357 ****************************************************************/
1359 NTSTATUS
_netr_ServerTrustPasswordsGet(pipes_struct
*p
,
1360 struct netr_ServerTrustPasswordsGet
*r
)
1362 p
->rng_fault_state
= true;
1363 return NT_STATUS_NOT_IMPLEMENTED
;
1366 /****************************************************************
1367 ****************************************************************/
1369 WERROR
_netr_DsRGetForestTrustInformation(pipes_struct
*p
,
1370 struct netr_DsRGetForestTrustInformation
*r
)
1372 p
->rng_fault_state
= true;
1373 return WERR_NOT_SUPPORTED
;
1376 /****************************************************************
1377 ****************************************************************/
1379 WERROR
_netr_GetForestTrustInformation(pipes_struct
*p
,
1380 struct netr_GetForestTrustInformation
*r
)
1382 p
->rng_fault_state
= true;
1383 return WERR_NOT_SUPPORTED
;
1386 /****************************************************************
1387 ****************************************************************/
1389 NTSTATUS
_netr_LogonSamLogonWithFlags(pipes_struct
*p
,
1390 struct netr_LogonSamLogonWithFlags
*r
)
1392 p
->rng_fault_state
= true;
1393 return NT_STATUS_NOT_IMPLEMENTED
;
1396 /****************************************************************
1397 ****************************************************************/
1399 WERROR
_netr_NETRSERVERGETTRUSTINFO(pipes_struct
*p
,
1400 struct netr_NETRSERVERGETTRUSTINFO
*r
)
1402 p
->rng_fault_state
= true;
1403 return WERR_NOT_SUPPORTED
;