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 /* r->in.negotiate_flags is an aliased pointer to r->out.negotiate_flags,
476 * so use a copy to avoid destroying the client values. */
477 uint32_t in_neg_flags
= *r
->in
.negotiate_flags
;
478 struct netr_Credential srv_chal_out
;
480 /* According to Microsoft (see bugid #6099)
481 * Windows 7 looks at the negotiate_flags
482 * returned in this structure *even if the
483 * call fails with access denied* ! So in order
484 * to allow Win7 to connect to a Samba NT style
485 * PDC we set the flags before we know if it's
490 srv_flgs
= NETLOGON_NEG_ACCOUNT_LOCKOUT
|
491 NETLOGON_NEG_PERSISTENT_SAMREPL
|
492 NETLOGON_NEG_ARCFOUR
|
493 NETLOGON_NEG_PROMOTION_COUNT
|
494 NETLOGON_NEG_CHANGELOG_BDC
|
495 NETLOGON_NEG_FULL_SYNC_REPL
|
496 NETLOGON_NEG_MULTIPLE_SIDS
|
498 NETLOGON_NEG_PASSWORD_CHANGE_REFUSAL
;
500 /* Ensure we support strong (128-bit) keys. */
501 if (in_neg_flags
& NETLOGON_NEG_128BIT
) {
502 srv_flgs
|= NETLOGON_NEG_128BIT
;
505 if (lp_server_schannel() != false) {
506 srv_flgs
|= NETLOGON_NEG_SCHANNEL
;
509 /* We use this as the key to store the creds: */
510 /* r->in.computer_name */
512 if (!p
->dc
|| !p
->dc
->challenge_sent
) {
513 DEBUG(0,("_netr_ServerAuthenticate2: no challenge sent to client %s\n",
514 r
->in
.computer_name
));
515 status
= NT_STATUS_ACCESS_DENIED
;
519 if ( (lp_server_schannel() == true) &&
520 ((in_neg_flags
& NETLOGON_NEG_SCHANNEL
) == 0) ) {
522 /* schannel must be used, but client did not offer it. */
523 DEBUG(0,("_netr_ServerAuthenticate2: schannel required but client failed "
524 "to offer it. Client was %s\n",
525 r
->in
.account_name
));
526 status
= NT_STATUS_ACCESS_DENIED
;
530 status
= get_md4pw((char *)p
->dc
->mach_pw
,
532 r
->in
.secure_channel_type
);
533 if (!NT_STATUS_IS_OK(status
)) {
534 DEBUG(0,("_netr_ServerAuthenticate2: failed to get machine password for "
536 r
->in
.account_name
, nt_errstr(status
) ));
537 /* always return NT_STATUS_ACCESS_DENIED */
538 status
= NT_STATUS_ACCESS_DENIED
;
542 /* From the client / server challenges and md4 password, generate sess key */
543 creds_server_init(in_neg_flags
,
545 &p
->dc
->clnt_chal
, /* Stored client chal. */
546 &p
->dc
->srv_chal
, /* Stored server chal. */
550 /* Check client credentials are valid. */
551 if (!netlogon_creds_server_check(p
->dc
, r
->in
.credentials
)) {
552 DEBUG(0,("_netr_ServerAuthenticate2: netlogon_creds_server_check failed. Rejecting auth "
553 "request from client %s machine account %s\n",
555 r
->in
.account_name
));
556 status
= NT_STATUS_ACCESS_DENIED
;
559 /* set up the LSA AUTH 2 response */
560 memcpy(r
->out
.return_credentials
->data
, &srv_chal_out
.data
,
561 sizeof(r
->out
.return_credentials
->data
));
563 fstrcpy(p
->dc
->mach_acct
, r
->in
.account_name
);
564 fstrcpy(p
->dc
->remote_machine
, r
->in
.computer_name
);
565 fstrcpy(p
->dc
->domain
, lp_workgroup() );
567 p
->dc
->authenticated
= True
;
569 /* Store off the state so we can continue after client disconnect. */
571 secrets_store_schannel_session_info(p
->mem_ctx
,
575 status
= NT_STATUS_OK
;
579 *r
->out
.negotiate_flags
= srv_flgs
;
583 /*************************************************************************
584 _netr_ServerPasswordSet
585 *************************************************************************/
587 NTSTATUS
_netr_ServerPasswordSet(pipes_struct
*p
,
588 struct netr_ServerPasswordSet
*r
)
590 NTSTATUS status
= NT_STATUS_OK
;
591 fstring remote_machine
;
592 struct samu
*sampass
=NULL
;
594 unsigned char pwd
[16];
597 struct netr_Authenticator cred_out
;
600 DEBUG(5,("_netr_ServerPasswordSet: %d\n", __LINE__
));
602 /* We need the remote machine name for the creds lookup. */
603 fstrcpy(remote_machine
, r
->in
.computer_name
);
605 if ( (lp_server_schannel() == True
) && (p
->auth
.auth_type
!= PIPE_AUTH_TYPE_SCHANNEL
) ) {
606 /* 'server schannel = yes' should enforce use of
607 schannel, the client did offer it in auth2, but
608 obviously did not use it. */
609 DEBUG(0,("_netr_ServerPasswordSet: client %s not using schannel for netlogon\n",
611 return NT_STATUS_ACCESS_DENIED
;
615 /* Restore the saved state of the netlogon creds. */
617 ret
= secrets_restore_schannel_session_info(p
, remote_machine
,
621 return NT_STATUS_INVALID_HANDLE
;
625 if (!p
->dc
|| !p
->dc
->authenticated
) {
626 return NT_STATUS_INVALID_HANDLE
;
629 DEBUG(3,("_netr_ServerPasswordSet: Server Password Set by remote machine:[%s] on account [%s]\n",
630 remote_machine
, p
->dc
->mach_acct
));
632 /* Step the creds chain forward. */
633 if (!netlogon_creds_server_step(p
->dc
, r
->in
.credential
, &cred_out
)) {
634 DEBUG(2,("_netr_ServerPasswordSet: netlogon_creds_server_step failed. Rejecting auth "
635 "request from client %s machine account %s\n",
636 remote_machine
, p
->dc
->mach_acct
));
637 return NT_STATUS_INVALID_PARAMETER
;
640 /* We must store the creds state after an update. */
641 sampass
= samu_new( NULL
);
643 return NT_STATUS_NO_MEMORY
;
647 secrets_store_schannel_session_info(p
, remote_machine
, p
->dc
);
648 ret
= pdb_getsampwnam(sampass
, p
->dc
->mach_acct
);
652 TALLOC_FREE(sampass
);
653 return NT_STATUS_ACCESS_DENIED
;
656 /* Ensure the account exists and is a machine account. */
658 acct_ctrl
= pdb_get_acct_ctrl(sampass
);
660 if (!(acct_ctrl
& ACB_WSTRUST
||
661 acct_ctrl
& ACB_SVRTRUST
||
662 acct_ctrl
& ACB_DOMTRUST
)) {
663 TALLOC_FREE(sampass
);
664 return NT_STATUS_NO_SUCH_USER
;
667 if (pdb_get_acct_ctrl(sampass
) & ACB_DISABLED
) {
668 TALLOC_FREE(sampass
);
669 return NT_STATUS_ACCOUNT_DISABLED
;
672 des_crypt112_16(pwd
, r
->in
.new_password
->hash
, p
->dc
->sess_key
, 0);
674 DEBUG(100,("_netr_ServerPasswordSet: new given value was :\n"));
675 for(i
= 0; i
< sizeof(pwd
); i
++)
676 DEBUG(100,("%02X ", pwd
[i
]));
679 old_pw
= pdb_get_nt_passwd(sampass
);
681 if (old_pw
&& memcmp(pwd
, old_pw
, 16) == 0) {
682 /* Avoid backend modificiations and other fun if the
683 client changed the password to the *same thing* */
688 /* LM password should be NULL for machines */
689 if (!pdb_set_lanman_passwd(sampass
, NULL
, PDB_CHANGED
)) {
690 TALLOC_FREE(sampass
);
691 return NT_STATUS_NO_MEMORY
;
694 if (!pdb_set_nt_passwd(sampass
, pwd
, PDB_CHANGED
)) {
695 TALLOC_FREE(sampass
);
696 return NT_STATUS_NO_MEMORY
;
699 if (!pdb_set_pass_last_set_time(sampass
, time(NULL
), PDB_CHANGED
)) {
700 TALLOC_FREE(sampass
);
701 /* Not quite sure what this one qualifies as, but this will do */
702 return NT_STATUS_UNSUCCESSFUL
;
706 status
= pdb_update_sam_account(sampass
);
710 /* set up the LSA Server Password Set response */
712 memcpy(r
->out
.return_authenticator
, &cred_out
,
713 sizeof(*(r
->out
.return_authenticator
)));
715 TALLOC_FREE(sampass
);
719 /*************************************************************************
721 *************************************************************************/
723 NTSTATUS
_netr_LogonSamLogoff(pipes_struct
*p
,
724 struct netr_LogonSamLogoff
*r
)
726 if ( (lp_server_schannel() == True
) && (p
->auth
.auth_type
!= PIPE_AUTH_TYPE_SCHANNEL
) ) {
727 /* 'server schannel = yes' should enforce use of
728 schannel, the client did offer it in auth2, but
729 obviously did not use it. */
730 DEBUG(0,("_netr_LogonSamLogoff: client %s not using schannel for netlogon\n",
731 get_remote_machine_name() ));
732 return NT_STATUS_ACCESS_DENIED
;
736 /* Using the remote machine name for the creds store: */
737 /* r->in.computer_name */
740 /* Restore the saved state of the netlogon creds. */
744 ret
= secrets_restore_schannel_session_info(
745 p
, r
->in
.computer_name
, &p
->dc
);
748 return NT_STATUS_INVALID_HANDLE
;
752 if (!p
->dc
|| !p
->dc
->authenticated
) {
753 return NT_STATUS_INVALID_HANDLE
;
756 /* checks and updates credentials. creates reply credentials */
757 if (!netlogon_creds_server_step(p
->dc
, r
->in
.credential
, r
->out
.return_authenticator
)) {
758 DEBUG(2,("_netr_LogonSamLogoff: netlogon_creds_server_step failed. Rejecting auth "
759 "request from client %s machine account %s\n",
760 r
->in
.computer_name
, p
->dc
->mach_acct
));
761 return NT_STATUS_INVALID_PARAMETER
;
764 /* We must store the creds state after an update. */
766 secrets_store_schannel_session_info(p
, r
->in
.computer_name
, p
->dc
);
772 /*************************************************************************
774 *************************************************************************/
776 NTSTATUS
_netr_LogonSamLogon(pipes_struct
*p
,
777 struct netr_LogonSamLogon
*r
)
779 NTSTATUS status
= NT_STATUS_OK
;
780 struct netr_SamInfo3
*sam3
= NULL
;
781 union netr_LogonInfo
*logon
= r
->in
.logon
;
782 fstring nt_username
, nt_domain
, nt_workstation
;
783 auth_usersupplied_info
*user_info
= NULL
;
784 auth_serversupplied_info
*server_info
= NULL
;
785 struct auth_context
*auth_context
= NULL
;
786 uint8_t pipe_session_key
[16];
787 bool process_creds
= true;
789 switch (p
->hdr_req
.opnum
) {
790 case NDR_NETR_LOGONSAMLOGON
:
791 process_creds
= true;
793 case NDR_NETR_LOGONSAMLOGONEX
:
795 process_creds
= false;
798 if ( (lp_server_schannel() == True
) && (p
->auth
.auth_type
!= PIPE_AUTH_TYPE_SCHANNEL
) ) {
799 /* 'server schannel = yes' should enforce use of
800 schannel, the client did offer it in auth2, but
801 obviously did not use it. */
802 DEBUG(0,("_netr_LogonSamLogon: client %s not using schannel for netlogon\n",
803 get_remote_machine_name() ));
804 return NT_STATUS_ACCESS_DENIED
;
807 sam3
= TALLOC_ZERO_P(p
->mem_ctx
, struct netr_SamInfo3
);
809 return NT_STATUS_NO_MEMORY
;
812 /* store the user information, if there is any. */
813 r
->out
.validation
->sam3
= sam3
;
814 *r
->out
.authoritative
= true; /* authoritative response */
815 if (r
->in
.validation_level
!= 2 && r
->in
.validation_level
!= 3) {
816 DEBUG(0,("_netr_LogonSamLogon: bad validation_level value %d.\n",
817 (int)r
->in
.validation_level
));
818 return NT_STATUS_ACCESS_DENIED
;
823 /* Get the remote machine name for the creds store. */
824 /* Note this is the remote machine this request is coming from (member server),
825 not neccessarily the workstation name the user is logging onto.
829 /* Restore the saved state of the netlogon creds. */
833 ret
= secrets_restore_schannel_session_info(
834 p
, r
->in
.computer_name
, &p
->dc
);
837 return NT_STATUS_INVALID_HANDLE
;
841 if (!p
->dc
|| !p
->dc
->authenticated
) {
842 return NT_STATUS_INVALID_HANDLE
;
845 /* checks and updates credentials. creates reply credentials */
846 if (!netlogon_creds_server_step(p
->dc
, r
->in
.credential
, r
->out
.return_authenticator
)) {
847 DEBUG(2,("_netr_LogonSamLogon: creds_server_step failed. Rejecting auth "
848 "request from client %s machine account %s\n",
849 r
->in
.computer_name
, p
->dc
->mach_acct
));
850 return NT_STATUS_INVALID_PARAMETER
;
853 /* We must store the creds state after an update. */
855 secrets_store_schannel_session_info(p
, r
->in
.computer_name
, p
->dc
);
859 switch (r
->in
.logon_level
) {
860 case INTERACTIVE_LOGON_TYPE
:
862 logon
->password
->identity_info
.account_name
.string
);
864 logon
->password
->identity_info
.domain_name
.string
);
865 fstrcpy(nt_workstation
,
866 logon
->password
->identity_info
.workstation
.string
);
868 DEBUG(3,("SAM Logon (Interactive). Domain:[%s]. ", lp_workgroup()));
872 logon
->network
->identity_info
.account_name
.string
);
874 logon
->network
->identity_info
.domain_name
.string
);
875 fstrcpy(nt_workstation
,
876 logon
->network
->identity_info
.workstation
.string
);
878 DEBUG(3,("SAM Logon (Network). Domain:[%s]. ", lp_workgroup()));
881 DEBUG(2,("SAM Logon: unsupported switch value\n"));
882 return NT_STATUS_INVALID_INFO_CLASS
;
885 DEBUG(3,("User:[%s@%s] Requested Domain:[%s]\n", nt_username
, nt_workstation
, nt_domain
));
886 fstrcpy(current_user_info
.smb_name
, nt_username
);
887 sub_set_smb_name(nt_username
);
889 DEBUG(5,("Attempting validation level %d for unmapped username %s.\n",
890 r
->in
.validation_level
, nt_username
));
892 status
= NT_STATUS_OK
;
894 switch (r
->in
.logon_level
) {
897 const char *wksname
= nt_workstation
;
899 status
= make_auth_context_fixed(&auth_context
,
900 logon
->network
->challenge
);
901 if (!NT_STATUS_IS_OK(status
)) {
905 /* For a network logon, the workstation name comes in with two
906 * backslashes in the front. Strip them if they are there. */
908 if (*wksname
== '\\') wksname
++;
909 if (*wksname
== '\\') wksname
++;
911 /* Standard challenge/response authenticaion */
912 if (!make_user_info_netlogon_network(&user_info
,
913 nt_username
, nt_domain
,
915 logon
->network
->identity_info
.parameter_control
,
916 logon
->network
->lm
.data
,
917 logon
->network
->lm
.length
,
918 logon
->network
->nt
.data
,
919 logon
->network
->nt
.length
)) {
920 status
= NT_STATUS_NO_MEMORY
;
924 case INTERACTIVE_LOGON_TYPE
:
925 /* 'Interactive' authentication, supplies the password in its
926 MD4 form, encrypted with the session key. We will convert
927 this to challenge/response for the auth subsystem to chew
932 if (!NT_STATUS_IS_OK(status
= make_auth_context_subsystem(&auth_context
))) {
936 chal
= auth_context
->get_ntlm_challenge(auth_context
);
938 if (!make_user_info_netlogon_interactive(&user_info
,
939 nt_username
, nt_domain
,
941 logon
->password
->identity_info
.parameter_control
,
943 logon
->password
->lmpassword
.hash
,
944 logon
->password
->ntpassword
.hash
,
946 status
= NT_STATUS_NO_MEMORY
;
951 DEBUG(2,("SAM Logon: unsupported switch value\n"));
952 return NT_STATUS_INVALID_INFO_CLASS
;
955 if ( NT_STATUS_IS_OK(status
) ) {
956 status
= auth_context
->check_ntlm_password(auth_context
,
957 user_info
, &server_info
);
960 (auth_context
->free
)(&auth_context
);
961 free_user_info(&user_info
);
963 DEBUG(5,("_netr_LogonSamLogon: check_password returned status %s\n",
966 /* Check account and password */
968 if (!NT_STATUS_IS_OK(status
)) {
969 /* If we don't know what this domain is, we need to
970 indicate that we are not authoritative. This
971 allows the client to decide if it needs to try
972 a local user. Fix by jpjanosi@us.ibm.com, #2976 */
973 if ( NT_STATUS_EQUAL(status
, NT_STATUS_NO_SUCH_USER
)
974 && !strequal(nt_domain
, get_global_sam_name())
975 && !is_trusted_domain(nt_domain
) )
976 *r
->out
.authoritative
= false; /* We are not authoritative */
978 TALLOC_FREE(server_info
);
982 if (server_info
->guest
) {
983 /* We don't like guest domain logons... */
984 DEBUG(5,("_netr_LogonSamLogon: Attempted domain logon as GUEST "
986 TALLOC_FREE(server_info
);
987 return NT_STATUS_LOGON_FAILURE
;
990 /* This is the point at which, if the login was successful, that
991 the SAM Local Security Authority should record that the user is
992 logged in to the domain. */
995 /* Get the pipe session key from the creds. */
996 memcpy(pipe_session_key
, p
->dc
->sess_key
, 16);
998 /* Get the pipe session key from the schannel. */
999 if ((p
->auth
.auth_type
!= PIPE_AUTH_TYPE_SCHANNEL
)
1000 || (p
->auth
.a_u
.schannel_auth
== NULL
)) {
1001 return NT_STATUS_INVALID_HANDLE
;
1003 memcpy(pipe_session_key
, p
->auth
.a_u
.schannel_auth
->sess_key
, 16);
1006 status
= serverinfo_to_SamInfo3(server_info
, pipe_session_key
, sam3
);
1007 TALLOC_FREE(server_info
);
1011 /*************************************************************************
1012 _netr_LogonSamLogonEx
1013 - no credential chaining. Map into net sam logon.
1014 *************************************************************************/
1016 NTSTATUS
_netr_LogonSamLogonEx(pipes_struct
*p
,
1017 struct netr_LogonSamLogonEx
*r
)
1019 struct netr_LogonSamLogon q
;
1021 /* Only allow this if the pipe is protected. */
1022 if (p
->auth
.auth_type
!= PIPE_AUTH_TYPE_SCHANNEL
) {
1023 DEBUG(0,("_net_sam_logon_ex: client %s not using schannel for netlogon\n",
1024 get_remote_machine_name() ));
1025 return NT_STATUS_INVALID_PARAMETER
;
1028 q
.in
.server_name
= r
->in
.server_name
;
1029 q
.in
.computer_name
= r
->in
.computer_name
;
1030 q
.in
.logon_level
= r
->in
.logon_level
;
1031 q
.in
.logon
= r
->in
.logon
;
1032 q
.in
.validation_level
= r
->in
.validation_level
;
1033 /* we do not handle the flags */
1034 /* = r->in.flags; */
1036 q
.out
.validation
= r
->out
.validation
;
1037 q
.out
.authoritative
= r
->out
.authoritative
;
1038 /* we do not handle the flags */
1039 /* = r->out.flags; */
1041 return _netr_LogonSamLogon(p
, &q
);
1044 /*************************************************************************
1046 *************************************************************************/
1047 #if 0 /* JERRY -- not correct */
1048 NTSTATUS
_ds_enum_dom_trusts(pipes_struct
*p
, DS_Q_ENUM_DOM_TRUSTS
*q_u
,
1049 DS_R_ENUM_DOM_TRUSTS
*r_u
)
1051 NTSTATUS status
= NT_STATUS_OK
;
1053 /* TODO: According to MSDN, the can only be executed against a
1054 DC or domain member running Windows 2000 or later. Need
1055 to test against a standalone 2k server and see what it
1056 does. A windows 2000 DC includes its own domain in the
1064 /****************************************************************
1065 ****************************************************************/
1067 WERROR
_netr_LogonUasLogon(pipes_struct
*p
,
1068 struct netr_LogonUasLogon
*r
)
1070 p
->rng_fault_state
= true;
1071 return WERR_NOT_SUPPORTED
;
1074 /****************************************************************
1075 ****************************************************************/
1077 WERROR
_netr_LogonUasLogoff(pipes_struct
*p
,
1078 struct netr_LogonUasLogoff
*r
)
1080 p
->rng_fault_state
= true;
1081 return WERR_NOT_SUPPORTED
;
1084 /****************************************************************
1085 ****************************************************************/
1087 NTSTATUS
_netr_DatabaseDeltas(pipes_struct
*p
,
1088 struct netr_DatabaseDeltas
*r
)
1090 p
->rng_fault_state
= true;
1091 return NT_STATUS_NOT_IMPLEMENTED
;
1094 /****************************************************************
1095 ****************************************************************/
1097 NTSTATUS
_netr_DatabaseSync(pipes_struct
*p
,
1098 struct netr_DatabaseSync
*r
)
1100 p
->rng_fault_state
= true;
1101 return NT_STATUS_NOT_IMPLEMENTED
;
1104 /****************************************************************
1105 ****************************************************************/
1107 NTSTATUS
_netr_AccountDeltas(pipes_struct
*p
,
1108 struct netr_AccountDeltas
*r
)
1110 p
->rng_fault_state
= true;
1111 return NT_STATUS_NOT_IMPLEMENTED
;
1114 /****************************************************************
1115 ****************************************************************/
1117 NTSTATUS
_netr_AccountSync(pipes_struct
*p
,
1118 struct netr_AccountSync
*r
)
1120 p
->rng_fault_state
= true;
1121 return NT_STATUS_NOT_IMPLEMENTED
;
1124 /****************************************************************
1125 ****************************************************************/
1127 WERROR
_netr_GetDcName(pipes_struct
*p
,
1128 struct netr_GetDcName
*r
)
1130 p
->rng_fault_state
= true;
1131 return WERR_NOT_SUPPORTED
;
1134 /****************************************************************
1135 ****************************************************************/
1137 WERROR
_netr_GetAnyDCName(pipes_struct
*p
,
1138 struct netr_GetAnyDCName
*r
)
1140 p
->rng_fault_state
= true;
1141 return WERR_NOT_SUPPORTED
;
1144 /****************************************************************
1145 ****************************************************************/
1147 NTSTATUS
_netr_DatabaseSync2(pipes_struct
*p
,
1148 struct netr_DatabaseSync2
*r
)
1150 p
->rng_fault_state
= true;
1151 return NT_STATUS_NOT_IMPLEMENTED
;
1154 /****************************************************************
1155 ****************************************************************/
1157 NTSTATUS
_netr_DatabaseRedo(pipes_struct
*p
,
1158 struct netr_DatabaseRedo
*r
)
1160 p
->rng_fault_state
= true;
1161 return NT_STATUS_NOT_IMPLEMENTED
;
1164 /****************************************************************
1165 ****************************************************************/
1167 WERROR
_netr_LogonControl2Ex(pipes_struct
*p
,
1168 struct netr_LogonControl2Ex
*r
)
1170 p
->rng_fault_state
= true;
1171 return WERR_NOT_SUPPORTED
;
1174 /****************************************************************
1175 ****************************************************************/
1177 WERROR
_netr_DsRGetDCName(pipes_struct
*p
,
1178 struct netr_DsRGetDCName
*r
)
1180 p
->rng_fault_state
= true;
1181 return WERR_NOT_SUPPORTED
;
1184 /****************************************************************
1185 ****************************************************************/
1187 NTSTATUS
_netr_LogonGetCapabilities(pipes_struct
*p
,
1188 struct netr_LogonGetCapabilities
*r
)
1190 return NT_STATUS_NOT_IMPLEMENTED
;
1193 /****************************************************************
1194 ****************************************************************/
1196 WERROR
_netr_NETRLOGONSETSERVICEBITS(pipes_struct
*p
,
1197 struct netr_NETRLOGONSETSERVICEBITS
*r
)
1199 p
->rng_fault_state
= true;
1200 return WERR_NOT_SUPPORTED
;
1203 /****************************************************************
1204 ****************************************************************/
1206 WERROR
_netr_LogonGetTrustRid(pipes_struct
*p
,
1207 struct netr_LogonGetTrustRid
*r
)
1209 p
->rng_fault_state
= true;
1210 return WERR_NOT_SUPPORTED
;
1213 /****************************************************************
1214 ****************************************************************/
1216 WERROR
_netr_NETRLOGONCOMPUTESERVERDIGEST(pipes_struct
*p
,
1217 struct netr_NETRLOGONCOMPUTESERVERDIGEST
*r
)
1219 p
->rng_fault_state
= true;
1220 return WERR_NOT_SUPPORTED
;
1223 /****************************************************************
1224 ****************************************************************/
1226 WERROR
_netr_NETRLOGONCOMPUTECLIENTDIGEST(pipes_struct
*p
,
1227 struct netr_NETRLOGONCOMPUTECLIENTDIGEST
*r
)
1229 p
->rng_fault_state
= true;
1230 return WERR_NOT_SUPPORTED
;
1233 /****************************************************************
1234 ****************************************************************/
1236 NTSTATUS
_netr_ServerAuthenticate3(pipes_struct
*p
,
1237 struct netr_ServerAuthenticate3
*r
)
1239 p
->rng_fault_state
= true;
1240 return NT_STATUS_NOT_IMPLEMENTED
;
1243 /****************************************************************
1244 ****************************************************************/
1246 WERROR
_netr_DsRGetDCNameEx(pipes_struct
*p
,
1247 struct netr_DsRGetDCNameEx
*r
)
1249 p
->rng_fault_state
= true;
1250 return WERR_NOT_SUPPORTED
;
1253 /****************************************************************
1254 ****************************************************************/
1256 WERROR
_netr_DsRGetSiteName(pipes_struct
*p
,
1257 struct netr_DsRGetSiteName
*r
)
1259 p
->rng_fault_state
= true;
1260 return WERR_NOT_SUPPORTED
;
1263 /****************************************************************
1264 ****************************************************************/
1266 NTSTATUS
_netr_LogonGetDomainInfo(pipes_struct
*p
,
1267 struct netr_LogonGetDomainInfo
*r
)
1269 p
->rng_fault_state
= true;
1270 return NT_STATUS_NOT_IMPLEMENTED
;
1273 /****************************************************************
1274 ****************************************************************/
1276 NTSTATUS
_netr_ServerPasswordSet2(pipes_struct
*p
,
1277 struct netr_ServerPasswordSet2
*r
)
1279 p
->rng_fault_state
= true;
1280 return NT_STATUS_NOT_IMPLEMENTED
;
1283 /****************************************************************
1284 ****************************************************************/
1286 WERROR
_netr_ServerPasswordGet(pipes_struct
*p
,
1287 struct netr_ServerPasswordGet
*r
)
1289 p
->rng_fault_state
= true;
1290 return WERR_NOT_SUPPORTED
;
1293 /****************************************************************
1294 ****************************************************************/
1296 WERROR
_netr_NETRLOGONSENDTOSAM(pipes_struct
*p
,
1297 struct netr_NETRLOGONSENDTOSAM
*r
)
1299 p
->rng_fault_state
= true;
1300 return WERR_NOT_SUPPORTED
;
1303 /****************************************************************
1304 ****************************************************************/
1306 WERROR
_netr_DsRAddressToSitenamesW(pipes_struct
*p
,
1307 struct netr_DsRAddressToSitenamesW
*r
)
1309 p
->rng_fault_state
= true;
1310 return WERR_NOT_SUPPORTED
;
1313 /****************************************************************
1314 ****************************************************************/
1316 WERROR
_netr_DsRGetDCNameEx2(pipes_struct
*p
,
1317 struct netr_DsRGetDCNameEx2
*r
)
1319 p
->rng_fault_state
= true;
1320 return WERR_NOT_SUPPORTED
;
1323 /****************************************************************
1324 ****************************************************************/
1326 WERROR
_netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN(pipes_struct
*p
,
1327 struct netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN
*r
)
1329 p
->rng_fault_state
= true;
1330 return WERR_NOT_SUPPORTED
;
1333 /****************************************************************
1334 ****************************************************************/
1336 WERROR
_netr_NetrEnumerateTrustedDomainsEx(pipes_struct
*p
,
1337 struct netr_NetrEnumerateTrustedDomainsEx
*r
)
1339 p
->rng_fault_state
= true;
1340 return WERR_NOT_SUPPORTED
;
1343 /****************************************************************
1344 ****************************************************************/
1346 WERROR
_netr_DsRAddressToSitenamesExW(pipes_struct
*p
,
1347 struct netr_DsRAddressToSitenamesExW
*r
)
1349 p
->rng_fault_state
= true;
1350 return WERR_NOT_SUPPORTED
;
1353 /****************************************************************
1354 ****************************************************************/
1356 WERROR
_netr_DsrGetDcSiteCoverageW(pipes_struct
*p
,
1357 struct netr_DsrGetDcSiteCoverageW
*r
)
1359 p
->rng_fault_state
= true;
1360 return WERR_NOT_SUPPORTED
;
1363 /****************************************************************
1364 ****************************************************************/
1366 WERROR
_netr_DsrEnumerateDomainTrusts(pipes_struct
*p
,
1367 struct netr_DsrEnumerateDomainTrusts
*r
)
1369 p
->rng_fault_state
= true;
1370 return WERR_NOT_SUPPORTED
;
1373 /****************************************************************
1374 ****************************************************************/
1376 WERROR
_netr_DsrDeregisterDNSHostRecords(pipes_struct
*p
,
1377 struct netr_DsrDeregisterDNSHostRecords
*r
)
1379 p
->rng_fault_state
= true;
1380 return WERR_NOT_SUPPORTED
;
1383 /****************************************************************
1384 ****************************************************************/
1386 NTSTATUS
_netr_ServerTrustPasswordsGet(pipes_struct
*p
,
1387 struct netr_ServerTrustPasswordsGet
*r
)
1389 p
->rng_fault_state
= true;
1390 return NT_STATUS_NOT_IMPLEMENTED
;
1393 /****************************************************************
1394 ****************************************************************/
1396 WERROR
_netr_DsRGetForestTrustInformation(pipes_struct
*p
,
1397 struct netr_DsRGetForestTrustInformation
*r
)
1399 p
->rng_fault_state
= true;
1400 return WERR_NOT_SUPPORTED
;
1403 /****************************************************************
1404 ****************************************************************/
1406 WERROR
_netr_GetForestTrustInformation(pipes_struct
*p
,
1407 struct netr_GetForestTrustInformation
*r
)
1409 p
->rng_fault_state
= true;
1410 return WERR_NOT_SUPPORTED
;
1413 /****************************************************************
1414 ****************************************************************/
1416 NTSTATUS
_netr_LogonSamLogonWithFlags(pipes_struct
*p
,
1417 struct netr_LogonSamLogonWithFlags
*r
)
1419 p
->rng_fault_state
= true;
1420 return NT_STATUS_NOT_IMPLEMENTED
;
1423 /****************************************************************
1424 ****************************************************************/
1426 WERROR
_netr_NETRSERVERGETTRUSTINFO(pipes_struct
*p
,
1427 struct netr_NETRSERVERGETTRUSTINFO
*r
)
1429 p
->rng_fault_state
= true;
1430 return WERR_NOT_SUPPORTED
;