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-2009.
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. */
28 #include "system/passwd.h" /* uid_wrapper */
30 #include "../libcli/auth/schannel.h"
31 #include "librpc/rpc/dcesrv_core.h"
32 #include "librpc/gen_ndr/ndr_netlogon.h"
33 #include "librpc/gen_ndr/ndr_netlogon_scompat.h"
34 #include "librpc/gen_ndr/ndr_samr_c.h"
35 #include "librpc/gen_ndr/ndr_lsa_c.h"
36 #include "rpc_client/cli_lsarpc.h"
37 #include "rpc_client/init_lsa.h"
38 #include "rpc_client/init_samr.h"
39 #include "rpc_server/rpc_ncacn_np.h"
40 #include "../libcli/security/security.h"
41 #include "../libcli/security/dom_sid.h"
42 #include "librpc/gen_ndr/ndr_drsblobs.h"
43 #include "lib/crypto/md4.h"
44 #include "nsswitch/libwbclient/wbclient.h"
45 #include "../libcli/registry/util_reg.h"
49 #include "../lib/tsocket/tsocket.h"
50 #include "lib/param/param.h"
51 #include "libsmb/dsgetdcname.h"
52 #include "lib/util/util_str_escape.h"
53 #include "source3/lib/substitute.h"
54 #include "librpc/rpc/server/netlogon/schannel_util.h"
57 #define DBGC_CLASS DBGC_RPC_SRV
59 /*************************************************************************
61 *************************************************************************/
63 WERROR
_netr_LogonControl(struct pipes_struct
*p
,
64 struct netr_LogonControl
*r
)
66 struct netr_LogonControl2Ex l
;
68 switch (r
->in
.level
) {
72 return WERR_NOT_SUPPORTED
;
74 return WERR_INVALID_LEVEL
;
77 switch (r
->in
.function_code
) {
78 case NETLOGON_CONTROL_QUERY
:
79 case NETLOGON_CONTROL_REPLICATE
:
80 case NETLOGON_CONTROL_SYNCHRONIZE
:
81 case NETLOGON_CONTROL_PDC_REPLICATE
:
82 case NETLOGON_CONTROL_BREAKPOINT
:
83 case NETLOGON_CONTROL_BACKUP_CHANGE_LOG
:
84 case NETLOGON_CONTROL_TRUNCATE_LOG
:
87 return WERR_NOT_SUPPORTED
;
90 l
.in
.logon_server
= r
->in
.logon_server
;
91 l
.in
.function_code
= r
->in
.function_code
;
92 l
.in
.level
= r
->in
.level
;
94 l
.out
.query
= r
->out
.query
;
96 return _netr_LogonControl2Ex(p
, &l
);
99 /*************************************************************************
101 *************************************************************************/
103 WERROR
_netr_LogonControl2(struct pipes_struct
*p
,
104 struct netr_LogonControl2
*r
)
106 struct netr_LogonControl2Ex l
;
108 l
.in
.logon_server
= r
->in
.logon_server
;
109 l
.in
.function_code
= r
->in
.function_code
;
110 l
.in
.level
= r
->in
.level
;
111 l
.in
.data
= r
->in
.data
;
112 l
.out
.query
= r
->out
.query
;
114 return _netr_LogonControl2Ex(p
, &l
);
117 /*************************************************************************
118 *************************************************************************/
120 static bool wb_change_trust_creds(const char *domain
, WERROR
*tc_status
)
123 struct wbcAuthErrorInfo
*error
= NULL
;
125 result
= wbcChangeTrustCredentials(domain
, &error
);
127 case WBC_ERR_WINBIND_NOT_AVAILABLE
:
129 case WBC_ERR_DOMAIN_NOT_FOUND
:
130 *tc_status
= WERR_NO_SUCH_DOMAIN
;
132 case WBC_ERR_SUCCESS
:
133 *tc_status
= WERR_OK
;
139 if (error
&& error
->nt_status
!= 0) {
140 *tc_status
= ntstatus_to_werror(NT_STATUS(error
->nt_status
));
142 *tc_status
= WERR_TRUST_FAILURE
;
144 wbcFreeMemory(error
);
148 /*************************************************************************
149 *************************************************************************/
151 static bool wb_check_trust_creds(const char *domain
, WERROR
*tc_status
)
154 struct wbcAuthErrorInfo
*error
= NULL
;
156 result
= wbcCheckTrustCredentials(domain
, &error
);
158 case WBC_ERR_WINBIND_NOT_AVAILABLE
:
160 case WBC_ERR_DOMAIN_NOT_FOUND
:
161 *tc_status
= WERR_NO_SUCH_DOMAIN
;
163 case WBC_ERR_SUCCESS
:
164 *tc_status
= WERR_OK
;
170 if (error
&& error
->nt_status
!= 0) {
171 *tc_status
= ntstatus_to_werror(NT_STATUS(error
->nt_status
));
173 *tc_status
= WERR_TRUST_FAILURE
;
175 wbcFreeMemory(error
);
179 /****************************************************************
180 _netr_LogonControl2Ex
181 ****************************************************************/
183 WERROR
_netr_LogonControl2Ex(struct pipes_struct
*p
,
184 struct netr_LogonControl2Ex
*r
)
186 struct dcesrv_call_state
*dce_call
= p
->dce_call
;
187 struct auth_session_info
*session_info
=
188 dcesrv_call_session_info(dce_call
);
189 uint32_t flags
= 0x0;
190 WERROR pdc_connection_status
= WERR_OK
;
191 uint32_t logon_attempts
= 0x0;
194 const char *dc_name
= NULL
;
195 struct sockaddr_storage dc_ss
;
196 const char *domain
= NULL
;
197 struct netr_NETLOGON_INFO_1
*info1
;
198 struct netr_NETLOGON_INFO_2
*info2
;
199 struct netr_NETLOGON_INFO_3
*info3
;
202 struct netr_DsRGetDCNameInfo
*dc_info
;
204 switch (dce_call
->pkt
.u
.request
.opnum
) {
205 case NDR_NETR_LOGONCONTROL
:
206 fn
= "_netr_LogonControl";
208 case NDR_NETR_LOGONCONTROL2
:
209 fn
= "_netr_LogonControl2";
211 case NDR_NETR_LOGONCONTROL2EX
:
212 fn
= "_netr_LogonControl2Ex";
215 return WERR_INVALID_PARAMETER
;
218 switch (r
->in
.level
) {
225 return WERR_INVALID_LEVEL
;
228 switch (r
->in
.function_code
) {
229 case NETLOGON_CONTROL_QUERY
:
232 if ((geteuid() != sec_initial_uid()) &&
233 !nt_token_check_domain_rid(
234 session_info
->security_token
, DOMAIN_RID_ADMINS
) &&
236 &global_sid_Builtin_Administrators
,
237 session_info
->security_token
))
239 return WERR_ACCESS_DENIED
;
244 tc_status
= WERR_NO_SUCH_DOMAIN
;
246 switch (r
->in
.function_code
) {
247 case NETLOGON_CONTROL_QUERY
:
248 switch (r
->in
.level
) {
253 return WERR_INVALID_PARAMETER
;
258 case NETLOGON_CONTROL_REPLICATE
:
259 case NETLOGON_CONTROL_SYNCHRONIZE
:
260 case NETLOGON_CONTROL_PDC_REPLICATE
:
261 case NETLOGON_CONTROL_BACKUP_CHANGE_LOG
:
262 case NETLOGON_CONTROL_BREAKPOINT
:
263 case NETLOGON_CONTROL_TRUNCATE_LOG
:
264 case NETLOGON_CONTROL_TRANSPORT_NOTIFY
:
265 case NETLOGON_CONTROL_FORCE_DNS_REG
:
266 return WERR_NOT_SUPPORTED
;
267 case NETLOGON_CONTROL_QUERY_DNS_REG
:
268 if (r
->in
.level
!= 1) {
269 return WERR_INVALID_PARAMETER
;
271 return WERR_NOT_SUPPORTED
;
272 case NETLOGON_CONTROL_FIND_USER
:
273 if (r
->in
.level
!= 4) {
274 return WERR_INVALID_PARAMETER
;
276 if (!r
->in
.data
|| !r
->in
.data
->user
) {
277 return WERR_NOT_SUPPORTED
;
280 case NETLOGON_CONTROL_SET_DBFLAG
:
282 return WERR_NOT_SUPPORTED
;
285 case NETLOGON_CONTROL_TC_VERIFY
:
286 if (r
->in
.level
!= 2) {
287 return WERR_INVALID_PARAMETER
;
289 if (!r
->in
.data
|| !r
->in
.data
->domain
) {
290 return WERR_NOT_SUPPORTED
;
293 if (!wb_check_trust_creds(r
->in
.data
->domain
, &tc_status
)) {
294 return WERR_NOT_SUPPORTED
;
297 case NETLOGON_CONTROL_TC_QUERY
:
298 if (!r
->in
.data
|| !r
->in
.data
->domain
) {
299 return WERR_NOT_SUPPORTED
;
302 domain
= r
->in
.data
->domain
;
304 if (!is_trusted_domain(domain
)) {
308 if (!get_dc_name(domain
, NULL
, dc_name2
, &dc_ss
)) {
309 tc_status
= WERR_NO_LOGON_SERVERS
;
313 dc_name
= talloc_asprintf(p
->mem_ctx
, "\\\\%s", dc_name2
);
315 return WERR_NOT_ENOUGH_MEMORY
;
322 case NETLOGON_CONTROL_REDISCOVER
:
323 if (!r
->in
.data
|| !r
->in
.data
->domain
) {
324 return WERR_NOT_SUPPORTED
;
327 domain
= r
->in
.data
->domain
;
329 if (!is_trusted_domain(domain
)) {
333 status
= dsgetdcname(p
->mem_ctx
, p
->msg_ctx
, domain
, NULL
, NULL
,
334 DS_FORCE_REDISCOVERY
| DS_RETURN_FLAT_NAME
,
336 if (!NT_STATUS_IS_OK(status
)) {
337 tc_status
= WERR_NO_LOGON_SERVERS
;
341 dc_name
= talloc_asprintf(p
->mem_ctx
, "\\\\%s", dc_info
->dc_unc
);
343 return WERR_NOT_ENOUGH_MEMORY
;
350 case NETLOGON_CONTROL_CHANGE_PASSWORD
:
351 if (!r
->in
.data
|| !r
->in
.data
->domain
) {
352 return WERR_NOT_SUPPORTED
;
355 if (!wb_change_trust_creds(r
->in
.data
->domain
, &tc_status
)) {
356 return WERR_NOT_SUPPORTED
;
361 /* no idea what this should be */
362 DEBUG(0,("%s: unimplemented function level [%d]\n",
363 fn
, r
->in
.function_code
));
364 return WERR_NOT_SUPPORTED
;
367 /* prepare the response */
369 switch (r
->in
.level
) {
371 info1
= talloc_zero(p
->mem_ctx
, struct netr_NETLOGON_INFO_1
);
372 W_ERROR_HAVE_NO_MEMORY(info1
);
374 info1
->flags
= flags
;
375 info1
->pdc_connection_status
= pdc_connection_status
;
377 r
->out
.query
->info1
= info1
;
380 if (r
->in
.function_code
!= NETLOGON_CONTROL_REDISCOVER
&&
381 r
->in
.function_code
!= NETLOGON_CONTROL_TC_QUERY
&&
382 r
->in
.function_code
!= NETLOGON_CONTROL_TC_VERIFY
)
384 return WERR_INVALID_PARAMETER
;
386 info2
= talloc_zero(p
->mem_ctx
, struct netr_NETLOGON_INFO_2
);
387 W_ERROR_HAVE_NO_MEMORY(info2
);
389 info2
->flags
= flags
;
390 info2
->pdc_connection_status
= pdc_connection_status
;
391 info2
->trusted_dc_name
= dc_name
;
392 info2
->tc_connection_status
= tc_status
;
394 r
->out
.query
->info2
= info2
;
397 info3
= talloc_zero(p
->mem_ctx
, struct netr_NETLOGON_INFO_3
);
398 W_ERROR_HAVE_NO_MEMORY(info3
);
400 info3
->flags
= flags
;
401 info3
->logon_attempts
= logon_attempts
;
403 r
->out
.query
->info3
= info3
;
406 if (r
->in
.function_code
!= NETLOGON_CONTROL_FIND_USER
) {
407 return WERR_INVALID_PARAMETER
;
409 return WERR_NOT_SUPPORTED
;
411 return WERR_INVALID_LEVEL
;
417 /*************************************************************************
418 _netr_NetrEnumerateTrustedDomains
419 *************************************************************************/
421 NTSTATUS
_netr_NetrEnumerateTrustedDomains(struct pipes_struct
*p
,
422 struct netr_NetrEnumerateTrustedDomains
*r
)
424 struct dcesrv_call_state
*dce_call
= p
->dce_call
;
425 struct dcesrv_connection
*dcesrv_conn
= dce_call
->conn
;
426 const struct tsocket_address
*local_address
=
427 dcesrv_connection_get_local_address(dcesrv_conn
);
428 const struct tsocket_address
*remote_address
=
429 dcesrv_connection_get_remote_address(dcesrv_conn
);
430 struct auth_session_info
*session_info
=
431 dcesrv_call_session_info(dce_call
);
433 NTSTATUS result
= NT_STATUS_OK
;
435 size_t num_domains
= 0;
436 const char **trusted_domains
= NULL
;
437 struct lsa_DomainList domain_list
;
438 struct dcerpc_binding_handle
*h
= NULL
;
439 struct policy_handle pol
;
440 uint32_t enum_ctx
= 0;
441 uint32_t max_size
= (uint32_t)-1;
442 union lsa_revision_info out_revision_info
= {
447 uint32_t out_version
= 0;
450 DEBUG(6,("_netr_NetrEnumerateTrustedDomains: %d\n", __LINE__
));
452 status
= rpcint_binding_handle(p
->mem_ctx
,
459 if (!NT_STATUS_IS_OK(status
)) {
463 status
= dcerpc_lsa_open_policy_fallback(
468 LSA_POLICY_VIEW_LOCAL_INFORMATION
,
473 if (any_nt_status_not_ok(status
, result
, &status
)) {
480 /* Lookup list of trusted domains */
481 status
= dcerpc_lsa_EnumTrustDom(h
,
488 if (!NT_STATUS_IS_OK(status
)) {
491 if (!NT_STATUS_IS_OK(result
) &&
492 !NT_STATUS_EQUAL(result
, NT_STATUS_NO_MORE_ENTRIES
) &&
493 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
)) {
498 for (i
= 0; i
< domain_list
.count
; i
++) {
499 if (!add_string_to_array(p
->mem_ctx
, domain_list
.domains
[i
].name
.string
,
500 &trusted_domains
, &num_domains
)) {
501 status
= NT_STATUS_NO_MEMORY
;
505 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
507 if (num_domains
> 0) {
508 /* multi sz terminate */
509 trusted_domains
= talloc_realloc(p
->mem_ctx
, trusted_domains
, const char *, num_domains
+ 1);
510 if (trusted_domains
== NULL
) {
511 status
= NT_STATUS_NO_MEMORY
;
515 trusted_domains
[num_domains
] = NULL
;
518 if (!push_reg_multi_sz(trusted_domains
, &blob
, trusted_domains
)) {
519 TALLOC_FREE(trusted_domains
);
520 status
= NT_STATUS_NO_MEMORY
;
524 r
->out
.trusted_domains_blob
->data
= blob
.data
;
525 r
->out
.trusted_domains_blob
->length
= blob
.length
;
527 DEBUG(6,("_netr_NetrEnumerateTrustedDomains: %d\n", __LINE__
));
529 status
= NT_STATUS_OK
;
532 if (is_valid_policy_hnd(&pol
)) {
533 dcerpc_lsa_Close(h
, p
->mem_ctx
, &pol
, &result
);
539 /*************************************************************************
540 *************************************************************************/
542 static NTSTATUS
samr_find_machine_account(TALLOC_CTX
*mem_ctx
,
543 struct dcerpc_binding_handle
*b
,
544 const char *account_name
,
545 uint32_t access_mask
,
546 struct dom_sid2
**domain_sid_p
,
547 uint32_t *user_rid_p
,
548 struct policy_handle
*user_handle
)
551 NTSTATUS result
= NT_STATUS_OK
;
552 struct policy_handle connect_handle
;
553 struct policy_handle domain_handle
= { 0, };
554 struct lsa_String domain_name
;
555 struct dom_sid2
*domain_sid
;
556 struct lsa_String names
;
557 struct samr_Ids rids
;
558 struct samr_Ids types
;
561 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
563 SAMR_ACCESS_CONNECT_TO_SERVER
|
564 SAMR_ACCESS_ENUM_DOMAINS
|
565 SAMR_ACCESS_LOOKUP_DOMAIN
,
568 if (any_nt_status_not_ok(status
, result
, &status
)) {
572 init_lsa_String(&domain_name
, get_global_sam_name());
574 status
= dcerpc_samr_LookupDomain(b
, mem_ctx
,
579 if (any_nt_status_not_ok(status
, result
, &status
)) {
583 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
585 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
,
589 if (any_nt_status_not_ok(status
, result
, &status
)) {
593 init_lsa_String(&names
, account_name
);
595 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
602 if (any_nt_status_not_ok(status
, result
, &status
)) {
606 if (rids
.count
!= 1) {
607 status
= NT_STATUS_NO_SUCH_USER
;
610 if (types
.count
!= 1) {
611 status
= NT_STATUS_INVALID_PARAMETER
;
614 if (types
.ids
[0] != SID_NAME_USER
) {
615 status
= NT_STATUS_NO_SUCH_USER
;
621 status
= dcerpc_samr_OpenUser(b
, mem_ctx
,
627 if (any_nt_status_not_ok(status
, result
, &status
)) {
636 *domain_sid_p
= domain_sid
;
640 if (is_valid_policy_hnd(&domain_handle
)) {
641 dcerpc_samr_Close(b
, mem_ctx
, &domain_handle
, &result
);
643 if (is_valid_policy_hnd(&connect_handle
)) {
644 dcerpc_samr_Close(b
, mem_ctx
, &connect_handle
, &result
);
650 /******************************************************************
651 gets a machine password entry. checks access rights of the host.
652 ******************************************************************/
654 static NTSTATUS
get_md4pw(struct samr_Password
*md4pw
, const char *mach_acct
,
655 enum netr_SchannelType sec_chan_type
,
657 struct messaging_context
*msg_ctx
)
660 NTSTATUS result
= NT_STATUS_OK
;
661 TALLOC_CTX
*mem_ctx
= NULL
;
662 struct dcerpc_binding_handle
*h
= NULL
;
663 struct tsocket_address
*local
= NULL
;
664 struct policy_handle user_handle
= { .handle_type
= 0 };
665 uint32_t user_rid
= UINT32_MAX
;
666 struct dom_sid
*domain_sid
= NULL
;
667 uint32_t acct_ctrl
= 0;
668 union samr_UserInfo
*info
= NULL
;
669 struct auth_session_info
*session_info
= NULL
;
675 * Currently this code is redundant as we already have a filter
676 * by hostname list. What this code really needs to do is to
677 * get a hosts allowed/hosts denied list from the SAM database
678 * on a per user basis, and make the access decision there.
679 * I will leave this code here for now as a reminder to implement
680 * this at a later date. JRA.
683 if (!allow_access(lp_domain_hostsdeny(), lp_domain_hostsallow(),
685 p
->client_id
.addr
)) {
686 DEBUG(0,("get_md4pw: Workstation %s denied access to domain\n", mach_acct
));
691 mem_ctx
= talloc_stackframe();
693 status
= make_session_info_system(mem_ctx
, &session_info
);
694 if (!NT_STATUS_IS_OK(status
)) {
698 ZERO_STRUCT(user_handle
);
700 rc
= tsocket_address_inet_from_strings(mem_ctx
,
706 status
= NT_STATUS_NO_MEMORY
;
710 status
= rpcint_binding_handle(mem_ctx
,
717 if (!NT_STATUS_IS_OK(status
)) {
721 status
= samr_find_machine_account(mem_ctx
, h
, mach_acct
,
722 SEC_FLAG_MAXIMUM_ALLOWED
,
723 &domain_sid
, &user_rid
,
725 if (!NT_STATUS_IS_OK(status
)) {
729 status
= dcerpc_samr_QueryUserInfo2(h
,
732 UserControlInformation
,
735 if (any_nt_status_not_ok(status
, result
, &status
)) {
739 acct_ctrl
= info
->info16
.acct_flags
;
741 if (acct_ctrl
& ACB_DISABLED
) {
742 DEBUG(0,("get_md4pw: Workstation %s: account is disabled\n", mach_acct
));
743 status
= NT_STATUS_ACCOUNT_DISABLED
;
747 if (!(acct_ctrl
& ACB_SVRTRUST
) &&
748 !(acct_ctrl
& ACB_WSTRUST
) &&
749 !(acct_ctrl
& ACB_DOMTRUST
))
751 DEBUG(0,("get_md4pw: Workstation %s: account is not a trust account\n", mach_acct
));
752 status
= NT_STATUS_NO_TRUST_SAM_ACCOUNT
;
756 switch (sec_chan_type
) {
758 if (!(acct_ctrl
& ACB_SVRTRUST
)) {
759 DEBUG(0,("get_md4pw: Workstation %s: BDC secure channel requested "
760 "but not a server trust account\n", mach_acct
));
761 status
= NT_STATUS_NO_TRUST_SAM_ACCOUNT
;
766 if (!(acct_ctrl
& ACB_WSTRUST
)) {
767 DEBUG(0,("get_md4pw: Workstation %s: WORKSTATION secure channel requested "
768 "but not a workstation trust account\n", mach_acct
));
769 status
= NT_STATUS_NO_TRUST_SAM_ACCOUNT
;
773 case SEC_CHAN_DOMAIN
:
774 if (!(acct_ctrl
& ACB_DOMTRUST
)) {
775 DEBUG(0,("get_md4pw: Workstation %s: DOMAIN secure channel requested "
776 "but not a interdomain trust account\n", mach_acct
));
777 status
= NT_STATUS_NO_TRUST_SAM_ACCOUNT
;
786 status
= dcerpc_samr_QueryUserInfo2(h
,
789 UserInternal1Information
,
793 if (any_nt_status_not_ok(status
, result
, &status
)) {
797 if (info
->info18
.nt_pwd_active
== 0) {
798 DEBUG(0,("get_md4pw: Workstation %s: account does not have a password\n", mach_acct
));
799 status
= NT_STATUS_LOGON_FAILURE
;
803 /* samr gives out nthash unencrypted (!) */
804 memcpy(md4pw
->hash
, info
->info18
.nt_pwd
.hash
, 16);
806 sid_compose(sid
, domain_sid
, user_rid
);
809 if (h
&& is_valid_policy_hnd(&user_handle
)) {
810 dcerpc_samr_Close(h
, mem_ctx
, &user_handle
, &result
);
813 talloc_free(mem_ctx
);
818 /*************************************************************************
819 _netr_ServerReqChallenge
820 *************************************************************************/
822 NTSTATUS
_netr_ServerReqChallenge(struct pipes_struct
*p
,
823 struct netr_ServerReqChallenge
*r
)
825 struct dcesrv_call_state
*dce_call
= p
->dce_call
;
826 struct netlogon_server_pipe_state
*pipe_state
= NULL
;
829 pipe_state
= dcesrv_iface_state_find_conn(
831 NETLOGON_SERVER_PIPE_STATE_MAGIC
,
832 struct netlogon_server_pipe_state
);
835 DEBUG(10,("_netr_ServerReqChallenge: new challenge requested. Clearing old state.\n"));
836 talloc_free(pipe_state
);
839 pipe_state
= talloc(p
->mem_ctx
, struct netlogon_server_pipe_state
);
840 NT_STATUS_HAVE_NO_MEMORY(pipe_state
);
842 pipe_state
->client_challenge
= *r
->in
.credentials
;
844 netlogon_creds_random_challenge(&pipe_state
->server_challenge
);
846 *r
->out
.return_credentials
= pipe_state
->server_challenge
;
848 status
= dcesrv_iface_state_store_conn(
850 NETLOGON_SERVER_PIPE_STATE_MAGIC
,
852 if (!NT_STATUS_IS_OK(status
)) {
859 /*************************************************************************
860 _netr_ServerAuthenticate
861 Create the initial credentials.
862 *************************************************************************/
864 NTSTATUS
_netr_ServerAuthenticate(struct pipes_struct
*p
,
865 struct netr_ServerAuthenticate
*r
)
867 struct netr_ServerAuthenticate3 a
;
868 uint32_t negotiate_flags
= 0;
871 a
.in
.server_name
= r
->in
.server_name
;
872 a
.in
.account_name
= r
->in
.account_name
;
873 a
.in
.secure_channel_type
= r
->in
.secure_channel_type
;
874 a
.in
.computer_name
= r
->in
.computer_name
;
875 a
.in
.credentials
= r
->in
.credentials
;
876 a
.in
.negotiate_flags
= &negotiate_flags
;
878 a
.out
.return_credentials
= r
->out
.return_credentials
;
880 a
.out
.negotiate_flags
= &negotiate_flags
;
882 return _netr_ServerAuthenticate3(p
, &a
);
886 /*************************************************************************
887 _netr_ServerAuthenticate3
888 *************************************************************************/
890 NTSTATUS
_netr_ServerAuthenticate3(struct pipes_struct
*p
,
891 struct netr_ServerAuthenticate3
*r
)
893 struct dcesrv_call_state
*dce_call
= p
->dce_call
;
896 /* r->in.negotiate_flags is an aliased pointer to r->out.negotiate_flags,
897 * so use a copy to avoid destroying the client values. */
898 uint32_t in_neg_flags
= *r
->in
.negotiate_flags
;
899 uint32_t neg_flags
= 0;
901 struct loadparm_context
*lp_ctx
= p
->dce_call
->conn
->dce_ctx
->lp_ctx
;
903 struct samr_Password mach_pwd
;
904 struct netlogon_creds_CredentialState
*creds
;
905 struct netlogon_server_pipe_state
*pipe_state
= NULL
;
907 /* According to Microsoft (see bugid #6099)
908 * Windows 7 looks at the negotiate_flags
909 * returned in this structure *even if the
910 * call fails with access denied* ! So in order
911 * to allow Win7 to connect to a Samba NT style
912 * PDC we set the flags before we know if it's
916 srv_flgs
= NETLOGON_NEG_ACCOUNT_LOCKOUT
|
917 NETLOGON_NEG_PERSISTENT_SAMREPL
|
918 NETLOGON_NEG_ARCFOUR
|
919 NETLOGON_NEG_PROMOTION_COUNT
|
920 NETLOGON_NEG_CHANGELOG_BDC
|
921 NETLOGON_NEG_FULL_SYNC_REPL
|
922 NETLOGON_NEG_MULTIPLE_SIDS
|
924 NETLOGON_NEG_PASSWORD_CHANGE_REFUSAL
|
925 NETLOGON_NEG_PASSWORD_SET2
|
926 NETLOGON_NEG_STRONG_KEYS
|
927 NETLOGON_NEG_SUPPORTS_AES
|
928 NETLOGON_NEG_SCHANNEL
;
931 * With SAMBA_WEAK_CRYPTO_DISALLOWED we will return DOWNGRADE_DETECTED
932 * with negotiate_flags = 0 below, if NETLOGON_NEG_SUPPORTS_AES was not
935 * And if NETLOGON_NEG_SUPPORTS_AES was negotiated there's no harm in
936 * returning the NETLOGON_NEG_ARCFOUR flag too...
938 * So there's no reason to remove NETLOGON_NEG_ARCFOUR nor
939 * NETLOGON_NEG_STRONG_KEYS from srv_flgs...
943 * Support authentication of trusted domains.
945 * These flags are the minimum required set which works with win2k3
948 if (pdb_capabilities() & PDB_CAP_TRUSTED_DOMAINS_EX
) {
949 srv_flgs
|= NETLOGON_NEG_TRANSITIVE_TRUSTS
|
950 NETLOGON_NEG_DNS_DOMAIN_TRUSTS
|
951 NETLOGON_NEG_CROSS_FOREST_TRUSTS
|
952 NETLOGON_NEG_NEUTRALIZE_NT4_EMULATION
;
955 neg_flags
= in_neg_flags
& srv_flgs
;
957 switch (dce_call
->pkt
.u
.request
.opnum
) {
958 case NDR_NETR_SERVERAUTHENTICATE
:
959 fn
= "_netr_ServerAuthenticate";
961 case NDR_NETR_SERVERAUTHENTICATE2
:
962 fn
= "_netr_ServerAuthenticate2";
964 case NDR_NETR_SERVERAUTHENTICATE3
:
965 fn
= "_netr_ServerAuthenticate3";
968 return NT_STATUS_INTERNAL_ERROR
;
971 if (lp_weak_crypto() == SAMBA_WEAK_CRYPTO_DISALLOWED
) {
972 if (!(neg_flags
& NETLOGON_NEG_SUPPORTS_AES
)) {
973 DBG_NOTICE("%s: no AES support negotiated from client %s\n",
974 fn
, r
->in
.computer_name
);
976 * Here we match Windows 2012 and return no flags.
979 status
= NT_STATUS_DOWNGRADE_DETECTED
;
984 /* We use this as the key to store the creds: */
985 /* r->in.computer_name */
987 pipe_state
= dcesrv_iface_state_find_conn(
989 NETLOGON_SERVER_PIPE_STATE_MAGIC
,
990 struct netlogon_server_pipe_state
);
993 DEBUG(0,("%s: no challenge sent to client %s\n", fn
,
994 r
->in
.computer_name
));
995 status
= NT_STATUS_ACCESS_DENIED
;
999 status
= get_md4pw(&mach_pwd
,
1001 r
->in
.secure_channel_type
,
1003 if (!NT_STATUS_IS_OK(status
)) {
1004 DEBUG(0,("%s: failed to get machine password for "
1006 fn
, r
->in
.account_name
, nt_errstr(status
) ));
1007 /* always return NT_STATUS_ACCESS_DENIED */
1008 status
= NT_STATUS_ACCESS_DENIED
;
1012 /* From the client / server challenges and md4 password, generate sess key */
1013 /* Check client credentials are valid. */
1014 creds
= netlogon_creds_server_init(p
->mem_ctx
,
1016 r
->in
.computer_name
,
1017 r
->in
.secure_channel_type
,
1018 &pipe_state
->client_challenge
,
1019 &pipe_state
->server_challenge
,
1022 r
->out
.return_credentials
,
1027 DEBUG(0,("%s: netlogon_creds_server_check failed. Rejecting auth "
1028 "request from client %s machine account %s\n",
1029 fn
, r
->in
.computer_name
,
1030 r
->in
.account_name
));
1031 status
= NT_STATUS_ACCESS_DENIED
;
1035 /* Store off the state so we can continue after client disconnect. */
1037 status
= schannel_save_creds_state(p
->mem_ctx
, lp_ctx
, creds
);
1040 if (!NT_STATUS_IS_OK(status
)) {
1041 ZERO_STRUCTP(r
->out
.return_credentials
);
1045 sid_peek_rid(&sid
, r
->out
.rid
);
1047 status
= NT_STATUS_OK
;
1051 *r
->out
.negotiate_flags
= neg_flags
;
1055 /*************************************************************************
1056 _netr_ServerAuthenticate2
1057 *************************************************************************/
1059 NTSTATUS
_netr_ServerAuthenticate2(struct pipes_struct
*p
,
1060 struct netr_ServerAuthenticate2
*r
)
1062 struct netr_ServerAuthenticate3 a
;
1065 a
.in
.server_name
= r
->in
.server_name
;
1066 a
.in
.account_name
= r
->in
.account_name
;
1067 a
.in
.secure_channel_type
= r
->in
.secure_channel_type
;
1068 a
.in
.computer_name
= r
->in
.computer_name
;
1069 a
.in
.credentials
= r
->in
.credentials
;
1070 a
.in
.negotiate_flags
= r
->in
.negotiate_flags
;
1072 a
.out
.return_credentials
= r
->out
.return_credentials
;
1074 a
.out
.negotiate_flags
= r
->out
.negotiate_flags
;
1076 return _netr_ServerAuthenticate3(p
, &a
);
1079 /*************************************************************************
1080 *************************************************************************/
1082 static NTSTATUS
samr_open_machine_account(
1083 struct dcerpc_binding_handle
*b
,
1084 const struct dom_sid
*machine_sid
,
1085 uint32_t access_mask
,
1086 struct policy_handle
*machine_handle
)
1088 TALLOC_CTX
*frame
= talloc_stackframe();
1089 struct policy_handle connect_handle
= { .handle_type
= 0 };
1090 struct policy_handle domain_handle
= { .handle_type
= 0 };
1091 struct dom_sid domain_sid
= *machine_sid
;
1092 uint32_t machine_rid
;
1093 NTSTATUS result
= NT_STATUS_OK
;
1094 NTSTATUS status
= NT_STATUS_INVALID_PARAMETER
;
1097 ok
= sid_split_rid(&domain_sid
, &machine_rid
);
1102 status
= dcerpc_samr_Connect2(
1106 SAMR_ACCESS_CONNECT_TO_SERVER
|
1107 SAMR_ACCESS_ENUM_DOMAINS
|
1108 SAMR_ACCESS_LOOKUP_DOMAIN
,
1111 if (any_nt_status_not_ok(status
, result
, &status
)) {
1115 status
= dcerpc_samr_OpenDomain(
1119 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
,
1123 if (any_nt_status_not_ok(status
, result
, &status
)) {
1127 status
= dcerpc_samr_OpenUser(
1131 SEC_FLAG_MAXIMUM_ALLOWED
,
1135 if (any_nt_status_not_ok(status
, result
, &status
)) {
1140 if ((b
!= NULL
) && is_valid_policy_hnd(&domain_handle
)) {
1141 dcerpc_samr_Close(b
, frame
, &domain_handle
, &result
);
1143 if ((b
!= NULL
) && is_valid_policy_hnd(&connect_handle
)) {
1144 dcerpc_samr_Close(b
, frame
, &connect_handle
, &result
);
1150 struct _samr_Credentials_t
{
1153 CRED_TYPE_PLAIN_TEXT
,
1156 struct samr_Password
*nt_hash
;
1157 const char *password
;
1162 static NTSTATUS
netr_set_machine_account_password(
1163 TALLOC_CTX
*mem_ctx
,
1164 struct auth_session_info
*session_info
,
1165 struct messaging_context
*msg_ctx
,
1166 const struct dom_sid
*machine_sid
,
1167 struct _samr_Credentials_t
*cr
)
1170 NTSTATUS result
= NT_STATUS_OK
;
1171 struct dcerpc_binding_handle
*h
= NULL
;
1172 struct tsocket_address
*local
;
1173 struct policy_handle user_handle
= { .handle_type
= 0 };
1175 union samr_UserInfo
*info
;
1176 struct samr_UserInfo18 info18
;
1177 struct samr_UserInfo26 info26
;
1180 DATA_BLOB session_key
;
1181 enum samr_UserInfoLevel infolevel
;
1182 TALLOC_CTX
*frame
= talloc_stackframe();
1184 status
= session_extract_session_key(session_info
,
1187 if (!NT_STATUS_IS_OK(status
)) {
1191 rc
= tsocket_address_inet_from_strings(frame
,
1197 status
= NT_STATUS_NO_MEMORY
;
1201 status
= rpcint_binding_handle(frame
,
1205 get_session_info_system(),
1208 if (!NT_STATUS_IS_OK(status
)) {
1212 status
= samr_open_machine_account(
1213 h
, machine_sid
, SEC_FLAG_MAXIMUM_ALLOWED
, &user_handle
);
1214 if (!NT_STATUS_IS_OK(status
)) {
1218 status
= dcerpc_samr_QueryUserInfo2(h
,
1221 UserControlInformation
,
1224 if (any_nt_status_not_ok(status
, result
, &status
)) {
1228 acct_ctrl
= info
->info16
.acct_flags
;
1230 if (!(acct_ctrl
& ACB_WSTRUST
||
1231 acct_ctrl
& ACB_SVRTRUST
||
1232 acct_ctrl
& ACB_DOMTRUST
)) {
1233 status
= NT_STATUS_NO_SUCH_USER
;
1237 if (acct_ctrl
& ACB_DISABLED
) {
1238 status
= NT_STATUS_ACCOUNT_DISABLED
;
1242 switch(cr
->cred_type
) {
1243 case CRED_TYPE_NT_HASH
:
1244 ZERO_STRUCT(info18
);
1246 infolevel
= UserInternal1Information
;
1248 in
= data_blob_const(cr
->creds
.nt_hash
, 16);
1249 out
= data_blob_talloc_zero(frame
, 16);
1250 if (out
.data
== NULL
) {
1251 status
= NT_STATUS_NO_MEMORY
;
1254 rc
= sess_crypt_blob(&out
, &in
, &session_key
, SAMBA_GNUTLS_ENCRYPT
);
1256 status
= gnutls_error_to_ntstatus(rc
,
1257 NT_STATUS_ACCESS_DISABLED_BY_POLICY_OTHER
);
1260 memcpy(info18
.nt_pwd
.hash
, out
.data
, out
.length
);
1262 info18
.nt_pwd_active
= true;
1264 info
->info18
= info18
;
1266 case CRED_TYPE_PLAIN_TEXT
:
1267 ZERO_STRUCT(info26
);
1269 infolevel
= UserInternal5InformationNew
;
1271 status
= init_samr_CryptPasswordEx(cr
->creds
.password
,
1274 if (!NT_STATUS_IS_OK(status
)) {
1278 info26
.password_expired
= PASS_DONT_CHANGE_AT_NEXT_LOGON
;
1279 info
->info26
= info26
;
1282 status
= NT_STATUS_INTERNAL_ERROR
;
1287 status
= dcerpc_samr_SetUserInfo2(h
,
1293 if (any_nt_status_not_ok(status
, result
, &status
)) {
1298 if (h
&& is_valid_policy_hnd(&user_handle
)) {
1299 dcerpc_samr_Close(h
, frame
, &user_handle
, &result
);
1306 /*************************************************************************
1307 _netr_ServerPasswordSet
1308 *************************************************************************/
1310 NTSTATUS
_netr_ServerPasswordSet(struct pipes_struct
*p
,
1311 struct netr_ServerPasswordSet
*r
)
1313 struct dcesrv_call_state
*dce_call
= p
->dce_call
;
1314 struct auth_session_info
*session_info
=
1315 dcesrv_call_session_info(dce_call
);
1316 NTSTATUS status
= NT_STATUS_OK
;
1318 struct netlogon_creds_CredentialState
*creds
= NULL
;
1319 struct _samr_Credentials_t cr
= { CRED_TYPE_NT_HASH
, {0}};
1320 const struct dom_sid
*client_sid
= NULL
;
1321 enum dcerpc_AuthType auth_type
= DCERPC_AUTH_TYPE_NONE
;
1322 enum dcerpc_AuthLevel auth_level
= DCERPC_AUTH_LEVEL_NONE
;
1324 dcesrv_call_auth_info(dce_call
, &auth_type
, &auth_level
);
1326 DEBUG(5,("_netr_ServerPasswordSet: %d\n", __LINE__
));
1329 status
= dcesrv_netr_creds_server_step_check(p
->dce_call
,
1331 r
->in
.computer_name
,
1333 r
->out
.return_authenticator
,
1337 if (!NT_STATUS_IS_OK(status
)) {
1338 const char *computer_name
= "<unknown>";
1340 if (creds
!= NULL
&& creds
->computer_name
!= NULL
) {
1341 computer_name
= creds
->computer_name
;
1343 DEBUG(2,("_netr_ServerPasswordSet: netlogon_creds_server_step failed. Rejecting auth "
1344 "request from client %s machine account %s\n",
1345 r
->in
.computer_name
, computer_name
));
1349 client_sid
= &creds
->ex
->client_sid
;
1351 DEBUG(3,("_netr_ServerPasswordSet: Server Password Set by remote machine:[%s] on account [%s]\n",
1352 r
->in
.computer_name
, creds
->computer_name
));
1354 status
= netlogon_creds_decrypt_samr_Password(creds
,
1358 if (!NT_STATUS_IS_OK(status
)) {
1362 DEBUG(100,("_netr_ServerPasswordSet: new given value was :\n"));
1363 for(i
= 0; i
< sizeof(r
->in
.new_password
->hash
); i
++)
1364 DEBUG(100,("%02X ", r
->in
.new_password
->hash
[i
]));
1367 cr
.creds
.nt_hash
= r
->in
.new_password
;
1368 status
= netr_set_machine_account_password(p
->mem_ctx
,
1376 /****************************************************************
1377 _netr_ServerPasswordSet2
1378 ****************************************************************/
1380 NTSTATUS
_netr_ServerPasswordSet2(struct pipes_struct
*p
,
1381 struct netr_ServerPasswordSet2
*r
)
1383 struct dcesrv_call_state
*dce_call
= p
->dce_call
;
1384 struct auth_session_info
*session_info
=
1385 dcesrv_call_session_info(dce_call
);
1387 struct netlogon_creds_CredentialState
*creds
= NULL
;
1388 const struct dom_sid
*client_sid
= NULL
;
1389 DATA_BLOB plaintext
= data_blob_null
;
1390 DATA_BLOB new_password
= data_blob_null
;
1391 size_t confounder_len
;
1392 DATA_BLOB dec_blob
= data_blob_null
;
1393 DATA_BLOB enc_blob
= data_blob_null
;
1394 struct samr_CryptPassword password_buf
;
1395 struct _samr_Credentials_t cr
= { CRED_TYPE_PLAIN_TEXT
, {0}};
1397 enum dcerpc_AuthType auth_type
= DCERPC_AUTH_TYPE_NONE
;
1398 enum dcerpc_AuthLevel auth_level
= DCERPC_AUTH_LEVEL_NONE
;
1400 dcesrv_call_auth_info(dce_call
, &auth_type
, &auth_level
);
1403 status
= dcesrv_netr_creds_server_step_check(p
->dce_call
,
1405 r
->in
.computer_name
,
1407 r
->out
.return_authenticator
,
1411 if (!NT_STATUS_IS_OK(status
)) {
1412 DBG_NOTICE("netlogon_creds_server_step failed. "
1413 "Rejecting auth request from client %s\n",
1414 r
->in
.computer_name
);
1418 client_sid
= &creds
->ex
->client_sid
;
1420 DBG_NOTICE("Server Password Set2 by remote "
1421 "machine:[%s] on account [%s]\n",
1422 r
->in
.computer_name
,
1423 creds
->computer_name
!= NULL
?
1424 creds
->computer_name
: "<unknown>");
1426 memcpy(password_buf
.data
, r
->in
.new_password
->data
, 512);
1427 SIVAL(password_buf
.data
, 512, r
->in
.new_password
->length
);
1429 status
= netlogon_creds_decrypt_samr_CryptPassword(creds
,
1433 if (!NT_STATUS_IS_OK(status
)) {
1438 if (!extract_pw_from_buffer(p
->mem_ctx
, password_buf
.data
, &new_password
)) {
1439 DEBUG(2,("_netr_ServerPasswordSet2: unable to extract password "
1440 "from a buffer. Rejecting auth request as a wrong password\n"));
1442 return NT_STATUS_WRONG_PASSWORD
;
1446 * Make sure the length field was encrypted,
1447 * otherwise we are under attack.
1449 if (new_password
.length
== r
->in
.new_password
->length
) {
1450 DBG_WARNING("Length[%zu] field not encrypted\n",
1451 new_password
.length
);
1453 return NT_STATUS_WRONG_PASSWORD
;
1457 * We don't allow empty passwords for machine accounts.
1459 if (new_password
.length
< 2) {
1460 DBG_WARNING("Empty password Length[%zu]\n",
1461 new_password
.length
);
1463 return NT_STATUS_WRONG_PASSWORD
;
1467 * Make sure the confounder part of CryptPassword
1468 * buffer was encrypted, otherwise we are under attack.
1470 confounder_len
= 512 - new_password
.length
;
1471 enc_blob
= data_blob_const(r
->in
.new_password
->data
, confounder_len
);
1472 dec_blob
= data_blob_const(password_buf
.data
, confounder_len
);
1473 if (confounder_len
> 0 && data_blob_equal_const_time(&dec_blob
, &enc_blob
)) {
1474 DBG_WARNING("Confounder buffer not encrypted Length[%zu]\n",
1477 return NT_STATUS_WRONG_PASSWORD
;
1481 * Check that the password part was actually encrypted,
1482 * otherwise we are under attack.
1484 enc_blob
= data_blob_const(r
->in
.new_password
->data
+ confounder_len
,
1485 new_password
.length
);
1486 dec_blob
= data_blob_const(password_buf
.data
+ confounder_len
,
1487 new_password
.length
);
1488 if (data_blob_equal_const_time(&dec_blob
, &enc_blob
)) {
1489 DBG_WARNING("Password buffer not encrypted Length[%zu]\n",
1490 new_password
.length
);
1492 return NT_STATUS_WRONG_PASSWORD
;
1496 * don't allow zero buffers
1498 if (all_zero(new_password
.data
, new_password
.length
)) {
1499 DBG_WARNING("Password zero buffer Length[%zu]\n",
1500 new_password
.length
);
1502 return NT_STATUS_WRONG_PASSWORD
;
1505 /* Convert from UTF16 -> plaintext. */
1506 ok
= convert_string_talloc(p
->mem_ctx
,
1510 new_password
.length
,
1514 DBG_WARNING("unable to extract password from a buffer. "
1515 "Rejecting auth request as a wrong password\n");
1517 return NT_STATUS_WRONG_PASSWORD
;
1521 * We don't allow empty passwords for machine accounts.
1524 cr
.creds
.password
= (const char*) plaintext
.data
;
1525 if (strlen(cr
.creds
.password
) == 0) {
1526 DBG_WARNING("Empty plaintext password\n");
1528 return NT_STATUS_WRONG_PASSWORD
;
1531 status
= netr_set_machine_account_password(p
->mem_ctx
,
1540 /*************************************************************************
1541 _netr_LogonSamLogoff
1542 *************************************************************************/
1544 NTSTATUS
_netr_LogonSamLogoff(struct pipes_struct
*p
,
1545 struct netr_LogonSamLogoff
*r
)
1548 struct netlogon_creds_CredentialState
*creds
;
1551 status
= dcesrv_netr_creds_server_step_check(p
->dce_call
,
1553 r
->in
.computer_name
,
1555 r
->out
.return_authenticator
,
1562 static NTSTATUS
_netr_LogonSamLogon_check(const struct netr_LogonSamLogonEx
*r
)
1564 switch (r
->in
.logon_level
) {
1565 case NetlogonInteractiveInformation
:
1566 case NetlogonServiceInformation
:
1567 case NetlogonInteractiveTransitiveInformation
:
1568 case NetlogonServiceTransitiveInformation
:
1569 if (r
->in
.logon
->password
== NULL
) {
1570 return NT_STATUS_INVALID_PARAMETER
;
1573 switch (r
->in
.validation_level
) {
1574 case NetlogonValidationSamInfo
: /* 2 */
1575 case NetlogonValidationSamInfo2
: /* 3 */
1577 case NetlogonValidationSamInfo4
: /* 6 */
1578 if ((pdb_capabilities() & PDB_CAP_ADS
) == 0) {
1579 DEBUG(10,("Not adding validation info level 6 "
1580 "without ADS passdb backend\n"));
1581 return NT_STATUS_INVALID_INFO_CLASS
;
1585 return NT_STATUS_INVALID_INFO_CLASS
;
1589 case NetlogonNetworkInformation
:
1590 case NetlogonNetworkTransitiveInformation
:
1591 if (r
->in
.logon
->network
== NULL
) {
1592 return NT_STATUS_INVALID_PARAMETER
;
1595 switch (r
->in
.validation_level
) {
1596 case NetlogonValidationSamInfo
: /* 2 */
1597 case NetlogonValidationSamInfo2
: /* 3 */
1599 case NetlogonValidationSamInfo4
: /* 6 */
1600 if ((pdb_capabilities() & PDB_CAP_ADS
) == 0) {
1601 DEBUG(10,("Not adding validation info level 6 "
1602 "without ADS passdb backend\n"));
1603 return NT_STATUS_INVALID_INFO_CLASS
;
1607 return NT_STATUS_INVALID_INFO_CLASS
;
1612 case NetlogonGenericInformation
:
1613 if (r
->in
.logon
->generic
== NULL
) {
1614 return NT_STATUS_INVALID_PARAMETER
;
1617 /* we don't support this here */
1618 return NT_STATUS_INVALID_PARAMETER
;
1620 switch (r
->in
.validation_level
) {
1621 /* TODO: case NetlogonValidationGenericInfo: 4 */
1622 case NetlogonValidationGenericInfo2
: /* 5 */
1625 return NT_STATUS_INVALID_INFO_CLASS
;
1631 return NT_STATUS_INVALID_PARAMETER
;
1634 return NT_STATUS_OK
;
1637 /*************************************************************************
1638 _netr_LogonSamLogon_base
1639 *************************************************************************/
1641 static NTSTATUS
_netr_LogonSamLogon_base(struct pipes_struct
*p
,
1642 struct netr_LogonSamLogonEx
*r
,
1643 struct netlogon_creds_CredentialState
*creds
)
1645 struct dcesrv_call_state
*dce_call
= p
->dce_call
;
1646 struct dcesrv_connection
*dcesrv_conn
= dce_call
->conn
;
1647 const struct tsocket_address
*local_address
=
1648 dcesrv_connection_get_local_address(dcesrv_conn
);
1649 const struct tsocket_address
*remote_address
=
1650 dcesrv_connection_get_remote_address(dcesrv_conn
);
1651 NTSTATUS status
= NT_STATUS_OK
;
1652 union netr_LogonLevel
*logon
= r
->in
.logon
;
1653 const char *nt_username
, *nt_domain
, *nt_workstation
;
1654 char *sanitized_username
= NULL
;
1655 struct auth_usersupplied_info
*user_info
= NULL
;
1656 struct auth_serversupplied_info
*server_info
= NULL
;
1657 struct auth_context
*auth_context
= NULL
;
1659 enum dcerpc_AuthType auth_type
= DCERPC_AUTH_TYPE_NONE
;
1660 enum dcerpc_AuthLevel auth_level
= DCERPC_AUTH_LEVEL_NONE
;
1661 uint16_t opnum
= dce_call
->pkt
.u
.request
.opnum
;
1663 dcesrv_call_auth_info(dce_call
, &auth_type
, &auth_level
);
1665 #ifdef DEBUG_PASSWORD
1666 logon
= netlogon_creds_shallow_copy_logon(p
->mem_ctx
,
1669 if (logon
== NULL
) {
1670 logon
= r
->in
.logon
;
1675 case NDR_NETR_LOGONSAMLOGON
:
1676 fn
= "_netr_LogonSamLogon";
1678 * Already called netr_check_schannel() via
1679 * netr_creds_server_step_check()
1682 case NDR_NETR_LOGONSAMLOGONWITHFLAGS
:
1683 fn
= "_netr_LogonSamLogonWithFlags";
1685 * Already called netr_check_schannel() via
1686 * netr_creds_server_step_check()
1689 case NDR_NETR_LOGONSAMLOGONEX
:
1690 fn
= "_netr_LogonSamLogonEx";
1692 if (auth_type
!= DCERPC_AUTH_TYPE_SCHANNEL
) {
1693 return NT_STATUS_ACCESS_DENIED
;
1696 status
= dcesrv_netr_check_schannel(p
->dce_call
,
1701 if (NT_STATUS_IS_ERR(status
)) {
1707 return NT_STATUS_INTERNAL_ERROR
;
1710 *r
->out
.authoritative
= 1; /* authoritative response */
1712 switch (r
->in
.validation_level
) {
1714 r
->out
.validation
->sam2
= talloc_zero(p
->mem_ctx
, struct netr_SamInfo2
);
1715 if (!r
->out
.validation
->sam2
) {
1716 return NT_STATUS_NO_MEMORY
;
1720 r
->out
.validation
->sam3
= talloc_zero(p
->mem_ctx
, struct netr_SamInfo3
);
1721 if (!r
->out
.validation
->sam3
) {
1722 return NT_STATUS_NO_MEMORY
;
1726 r
->out
.validation
->sam6
= talloc_zero(p
->mem_ctx
, struct netr_SamInfo6
);
1727 if (!r
->out
.validation
->sam6
) {
1728 return NT_STATUS_NO_MEMORY
;
1732 DEBUG(0,("%s: bad validation_level value %d.\n",
1733 fn
, (int)r
->in
.validation_level
));
1734 return NT_STATUS_INVALID_INFO_CLASS
;
1737 switch (r
->in
.logon_level
) {
1738 case NetlogonInteractiveInformation
:
1739 case NetlogonServiceInformation
:
1740 case NetlogonInteractiveTransitiveInformation
:
1741 case NetlogonServiceTransitiveInformation
:
1742 nt_username
= logon
->password
->identity_info
.account_name
.string
?
1743 logon
->password
->identity_info
.account_name
.string
: "";
1744 nt_domain
= logon
->password
->identity_info
.domain_name
.string
?
1745 logon
->password
->identity_info
.domain_name
.string
: "";
1746 nt_workstation
= logon
->password
->identity_info
.workstation
.string
?
1747 logon
->password
->identity_info
.workstation
.string
: "";
1749 DEBUG(3,("SAM Logon (Interactive). Domain:[%s]. ", lp_workgroup()));
1751 case NetlogonNetworkInformation
:
1752 case NetlogonNetworkTransitiveInformation
:
1753 nt_username
= logon
->network
->identity_info
.account_name
.string
?
1754 logon
->network
->identity_info
.account_name
.string
: "";
1755 nt_domain
= logon
->network
->identity_info
.domain_name
.string
?
1756 logon
->network
->identity_info
.domain_name
.string
: "";
1757 nt_workstation
= logon
->network
->identity_info
.workstation
.string
?
1758 logon
->network
->identity_info
.workstation
.string
: "";
1760 DEBUG(3,("SAM Logon (Network). Domain:[%s]. ", lp_workgroup()));
1763 DEBUG(2,("SAM Logon: unsupported switch value\n"));
1764 return NT_STATUS_INVALID_INFO_CLASS
;
1767 DEBUG(3,("User:[%s@%s] Requested Domain:[%s]\n", nt_username
, nt_workstation
, nt_domain
));
1769 DEBUG(5,("Attempting validation level %d for unmapped username %s.\n",
1770 r
->in
.validation_level
, nt_username
));
1772 status
= netlogon_creds_decrypt_samlogon_logon(creds
,
1777 if (!NT_STATUS_IS_OK(status
)) {
1781 status
= make_auth3_context_for_netlogon(talloc_tos(), &auth_context
);
1782 if (!NT_STATUS_IS_OK(status
)) {
1786 switch (r
->in
.logon_level
) {
1787 case NetlogonNetworkInformation
:
1788 case NetlogonNetworkTransitiveInformation
:
1790 const char *wksname
= nt_workstation
;
1791 const char *workgroup
= lp_workgroup();
1794 ok
= auth3_context_set_challenge(
1795 auth_context
, logon
->network
->challenge
, "fixed");
1797 return NT_STATUS_NO_MEMORY
;
1800 /* For a network logon, the workstation name comes in with two
1801 * backslashes in the front. Strip them if they are there. */
1803 if (*wksname
== '\\') wksname
++;
1804 if (*wksname
== '\\') wksname
++;
1806 /* Standard challenge/response authentication */
1807 if (!make_user_info_netlogon_network(talloc_tos(),
1809 nt_username
, nt_domain
,
1813 logon
->network
->identity_info
.parameter_control
,
1814 logon
->network
->lm
.data
,
1815 logon
->network
->lm
.length
,
1816 logon
->network
->nt
.data
,
1817 logon
->network
->nt
.length
)) {
1818 status
= NT_STATUS_NO_MEMORY
;
1821 if (NT_STATUS_IS_OK(status
)) {
1822 status
= NTLMv2_RESPONSE_verify_netlogon_creds(
1823 user_info
->client
.account_name
,
1824 user_info
->client
.domain_name
,
1825 user_info
->password
.response
.nt
,
1830 case NetlogonInteractiveInformation
:
1831 case NetlogonServiceInformation
:
1832 case NetlogonInteractiveTransitiveInformation
:
1833 case NetlogonServiceTransitiveInformation
:
1835 /* 'Interactive' authentication, supplies the password in its
1836 MD4 form, encrypted with the session key. We will convert
1837 this to challenge/response for the auth subsystem to chew
1842 #ifdef DEBUG_PASSWORD
1843 if (logon
!= r
->in
.logon
) {
1844 DEBUG(100,("lm owf password:"));
1846 r
->in
.logon
->password
->lmpassword
.hash
, 16);
1848 DEBUG(100,("nt owf password:"));
1850 r
->in
.logon
->password
->ntpassword
.hash
, 16);
1853 DEBUG(100,("decrypt of lm owf password:"));
1854 dump_data(100, logon
->password
->lmpassword
.hash
, 16);
1856 DEBUG(100,("decrypt of nt owf password:"));
1857 dump_data(100, logon
->password
->ntpassword
.hash
, 16);
1860 auth_get_ntlm_challenge(auth_context
, chal
);
1862 if (!make_user_info_netlogon_interactive(talloc_tos(),
1864 nt_username
, nt_domain
,
1868 logon
->password
->identity_info
.parameter_control
,
1870 logon
->password
->lmpassword
.hash
,
1871 logon
->password
->ntpassword
.hash
)) {
1872 status
= NT_STATUS_NO_MEMORY
;
1877 DEBUG(2,("SAM Logon: unsupported switch value\n"));
1878 return NT_STATUS_INVALID_INFO_CLASS
;
1881 if ( NT_STATUS_IS_OK(status
) ) {
1882 status
= auth_check_ntlm_password(p
->mem_ctx
,
1886 r
->out
.authoritative
);
1889 TALLOC_FREE(auth_context
);
1890 TALLOC_FREE(user_info
);
1892 DEBUG(5,("%s: check_password returned status %s\n",
1893 fn
, nt_errstr(status
)));
1895 /* Check account and password */
1897 if (!NT_STATUS_IS_OK(status
)) {
1898 TALLOC_FREE(server_info
);
1902 if (server_info
->guest
) {
1903 /* We don't like guest domain logons... */
1904 DEBUG(5,("%s: Attempted domain logon as GUEST "
1906 TALLOC_FREE(server_info
);
1907 return NT_STATUS_LOGON_FAILURE
;
1910 sanitized_username
= talloc_alpha_strcpy(talloc_tos(),
1912 SAFE_NETBIOS_CHARS
"$");
1913 if (sanitized_username
== NULL
) {
1914 TALLOC_FREE(server_info
);
1915 return NT_STATUS_NO_MEMORY
;
1918 set_current_user_info(sanitized_username
,
1919 server_info
->unix_name
,
1920 server_info
->info3
->base
.logon_domain
.string
);
1921 TALLOC_FREE(sanitized_username
);
1923 /* This is the point at which, if the login was successful, that
1924 the SAM Local Security Authority should record that the user is
1925 logged in to the domain. */
1927 switch (r
->in
.validation_level
) {
1929 status
= serverinfo_to_SamInfo2(server_info
,
1930 r
->out
.validation
->sam2
);
1933 status
= serverinfo_to_SamInfo3(server_info
,
1934 r
->out
.validation
->sam3
);
1937 /* Only allow this if the pipe is protected. */
1938 if (auth_level
< DCERPC_AUTH_LEVEL_PRIVACY
) {
1939 DEBUG(0,("netr_Validation6: client %s not using privacy for netlogon\n",
1940 get_remote_machine_name()));
1941 status
= NT_STATUS_INVALID_PARAMETER
;
1945 status
= serverinfo_to_SamInfo6(server_info
,
1946 r
->out
.validation
->sam6
);
1951 TALLOC_FREE(server_info
);
1953 if (!NT_STATUS_IS_OK(status
)) {
1957 status
= netlogon_creds_encrypt_samlogon_validation(creds
,
1958 r
->in
.validation_level
,
1966 /****************************************************************
1967 _netr_LogonSamLogonWithFlags
1968 ****************************************************************/
1970 NTSTATUS
_netr_LogonSamLogonWithFlags(struct pipes_struct
*p
,
1971 struct netr_LogonSamLogonWithFlags
*r
)
1974 struct netlogon_creds_CredentialState
*creds
;
1975 struct netr_LogonSamLogonEx r2
;
1976 struct netr_Authenticator return_authenticator
;
1978 *r
->out
.authoritative
= true;
1980 r2
.in
.server_name
= r
->in
.server_name
;
1981 r2
.in
.computer_name
= r
->in
.computer_name
;
1982 r2
.in
.logon_level
= r
->in
.logon_level
;
1983 r2
.in
.logon
= r
->in
.logon
;
1984 r2
.in
.validation_level
= r
->in
.validation_level
;
1985 r2
.in
.flags
= r
->in
.flags
;
1986 r2
.out
.validation
= r
->out
.validation
;
1987 r2
.out
.authoritative
= r
->out
.authoritative
;
1988 r2
.out
.flags
= r
->out
.flags
;
1990 status
= _netr_LogonSamLogon_check(&r2
);
1991 if (!NT_STATUS_IS_OK(status
)) {
1996 status
= dcesrv_netr_creds_server_step_check(p
->dce_call
,
1998 r
->in
.computer_name
,
2000 &return_authenticator
,
2003 if (!NT_STATUS_IS_OK(status
)) {
2007 status
= _netr_LogonSamLogon_base(p
, &r2
, creds
);
2009 *r
->out
.return_authenticator
= return_authenticator
;
2014 /*************************************************************************
2016 *************************************************************************/
2018 NTSTATUS
_netr_LogonSamLogon(struct pipes_struct
*p
,
2019 struct netr_LogonSamLogon
*r
)
2022 struct netr_LogonSamLogonWithFlags r2
;
2025 r2
.in
.server_name
= r
->in
.server_name
;
2026 r2
.in
.computer_name
= r
->in
.computer_name
;
2027 r2
.in
.credential
= r
->in
.credential
;
2028 r2
.in
.logon_level
= r
->in
.logon_level
;
2029 r2
.in
.logon
= r
->in
.logon
;
2030 r2
.in
.validation_level
= r
->in
.validation_level
;
2031 r2
.in
.return_authenticator
= r
->in
.return_authenticator
;
2032 r2
.in
.flags
= &flags
;
2033 r2
.out
.validation
= r
->out
.validation
;
2034 r2
.out
.authoritative
= r
->out
.authoritative
;
2035 r2
.out
.flags
= &flags
;
2036 r2
.out
.return_authenticator
= r
->out
.return_authenticator
;
2038 status
= _netr_LogonSamLogonWithFlags(p
, &r2
);
2043 /*************************************************************************
2044 _netr_LogonSamLogonEx
2045 - no credential chaining. Map into net sam logon.
2046 *************************************************************************/
2048 NTSTATUS
_netr_LogonSamLogonEx(struct pipes_struct
*p
,
2049 struct netr_LogonSamLogonEx
*r
)
2052 struct netlogon_creds_CredentialState
*creds
= NULL
;
2053 struct loadparm_context
*lp_ctx
= p
->dce_call
->conn
->dce_ctx
->lp_ctx
;
2055 *r
->out
.authoritative
= true;
2057 status
= _netr_LogonSamLogon_check(r
);
2058 if (!NT_STATUS_IS_OK(status
)) {
2063 status
= schannel_get_creds_state(p
->mem_ctx
, lp_ctx
,
2064 r
->in
.computer_name
, &creds
);
2066 if (!NT_STATUS_IS_OK(status
)) {
2070 status
= _netr_LogonSamLogon_base(p
, r
, creds
);
2076 /*************************************************************************
2078 *************************************************************************/
2079 #if 0 /* JERRY -- not correct */
2080 NTSTATUS
_ds_enum_dom_trusts(struct pipes_struct
*p
, DS_Q_ENUM_DOM_TRUSTS
*q_u
,
2081 DS_R_ENUM_DOM_TRUSTS
*r_u
)
2083 NTSTATUS status
= NT_STATUS_OK
;
2085 /* TODO: According to MSDN, the can only be executed against a
2086 DC or domain member running Windows 2000 or later. Need
2087 to test against a standalone 2k server and see what it
2088 does. A windows 2000 DC includes its own domain in the
2096 /****************************************************************
2097 ****************************************************************/
2099 WERROR
_netr_LogonUasLogon(struct pipes_struct
*p
,
2100 struct netr_LogonUasLogon
*r
)
2102 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2103 return WERR_NOT_SUPPORTED
;
2106 /****************************************************************
2107 ****************************************************************/
2109 WERROR
_netr_LogonUasLogoff(struct pipes_struct
*p
,
2110 struct netr_LogonUasLogoff
*r
)
2112 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2113 return WERR_NOT_SUPPORTED
;
2116 /****************************************************************
2117 ****************************************************************/
2119 NTSTATUS
_netr_DatabaseDeltas(struct pipes_struct
*p
,
2120 struct netr_DatabaseDeltas
*r
)
2122 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2123 return NT_STATUS_NOT_IMPLEMENTED
;
2126 /****************************************************************
2127 ****************************************************************/
2129 NTSTATUS
_netr_DatabaseSync(struct pipes_struct
*p
,
2130 struct netr_DatabaseSync
*r
)
2132 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2133 return NT_STATUS_NOT_IMPLEMENTED
;
2136 /****************************************************************
2137 ****************************************************************/
2139 NTSTATUS
_netr_AccountDeltas(struct pipes_struct
*p
,
2140 struct netr_AccountDeltas
*r
)
2142 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2143 return NT_STATUS_NOT_IMPLEMENTED
;
2146 /****************************************************************
2147 ****************************************************************/
2149 NTSTATUS
_netr_AccountSync(struct pipes_struct
*p
,
2150 struct netr_AccountSync
*r
)
2152 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2153 return NT_STATUS_NOT_IMPLEMENTED
;
2156 /****************************************************************
2157 ****************************************************************/
2159 static bool wb_getdcname(TALLOC_CTX
*mem_ctx
,
2161 const char **dcname
,
2166 struct wbcDomainControllerInfo
*dc_info
= NULL
;
2168 result
= wbcLookupDomainController(domain
,
2172 case WBC_ERR_SUCCESS
:
2174 case WBC_ERR_WINBIND_NOT_AVAILABLE
:
2176 case WBC_ERR_DOMAIN_NOT_FOUND
:
2177 *werr
= WERR_NO_SUCH_DOMAIN
;
2180 *werr
= WERR_DOMAIN_CONTROLLER_NOT_FOUND
;
2184 *dcname
= talloc_strdup(mem_ctx
, dc_info
->dc_name
);
2185 wbcFreeMemory(dc_info
);
2187 *werr
= WERR_NOT_ENOUGH_MEMORY
;
2196 /****************************************************************
2198 ****************************************************************/
2200 WERROR
_netr_GetDcName(struct pipes_struct
*p
,
2201 struct netr_GetDcName
*r
)
2206 struct netr_DsRGetDCNameInfo
*info
;
2209 ret
= wb_getdcname(p
->mem_ctx
,
2212 WBC_LOOKUP_DC_IS_FLAT_NAME
|
2213 WBC_LOOKUP_DC_RETURN_FLAT_NAME
|
2214 WBC_LOOKUP_DC_PDC_REQUIRED
,
2220 flags
= DS_PDC_REQUIRED
| DS_IS_FLAT_NAME
| DS_RETURN_FLAT_NAME
;
2222 status
= dsgetdcname(p
->mem_ctx
,
2229 if (!NT_STATUS_IS_OK(status
)) {
2230 return ntstatus_to_werror(status
);
2233 *r
->out
.dcname
= talloc_strdup(p
->mem_ctx
, info
->dc_unc
);
2235 if (!*r
->out
.dcname
) {
2236 return WERR_NOT_ENOUGH_MEMORY
;
2242 /****************************************************************
2244 ****************************************************************/
2246 WERROR
_netr_GetAnyDCName(struct pipes_struct
*p
,
2247 struct netr_GetAnyDCName
*r
)
2252 struct netr_DsRGetDCNameInfo
*info
;
2255 ret
= wb_getdcname(p
->mem_ctx
,
2258 WBC_LOOKUP_DC_IS_FLAT_NAME
|
2259 WBC_LOOKUP_DC_RETURN_FLAT_NAME
,
2265 flags
= DS_IS_FLAT_NAME
| DS_RETURN_FLAT_NAME
;
2267 status
= dsgetdcname(p
->mem_ctx
,
2274 if (!NT_STATUS_IS_OK(status
)) {
2275 return ntstatus_to_werror(status
);
2278 *r
->out
.dcname
= talloc_strdup(p
->mem_ctx
, info
->dc_unc
);
2280 if (!*r
->out
.dcname
) {
2281 return WERR_NOT_ENOUGH_MEMORY
;
2287 /****************************************************************
2288 ****************************************************************/
2290 NTSTATUS
_netr_DatabaseSync2(struct pipes_struct
*p
,
2291 struct netr_DatabaseSync2
*r
)
2293 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2294 return NT_STATUS_NOT_IMPLEMENTED
;
2297 /****************************************************************
2298 ****************************************************************/
2300 NTSTATUS
_netr_DatabaseRedo(struct pipes_struct
*p
,
2301 struct netr_DatabaseRedo
*r
)
2303 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2304 return NT_STATUS_NOT_IMPLEMENTED
;
2307 /****************************************************************
2308 ****************************************************************/
2310 WERROR
_netr_DsRGetDCName(struct pipes_struct
*p
,
2311 struct netr_DsRGetDCName
*r
)
2313 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2314 return WERR_NOT_SUPPORTED
;
2317 /****************************************************************
2318 ****************************************************************/
2320 NTSTATUS
_netr_LogonGetCapabilities(struct pipes_struct
*p
,
2321 struct netr_LogonGetCapabilities
*r
)
2323 struct netlogon_creds_CredentialState
*creds
;
2326 switch (r
->in
.query_level
) {
2333 * There would not be a way to marshall the
2334 * the response. Which would mean our final
2335 * ndr_push would fail an we would return
2336 * an RPC-level fault with DCERPC_FAULT_BAD_STUB_DATA.
2338 * But it's important to match a Windows server
2339 * especially before KB5028166, see also our bug #15418
2340 * Otherwise Windows client would stop talking to us.
2342 p
->fault_state
= DCERPC_NCA_S_FAULT_INVALID_TAG
;
2343 return NT_STATUS_NOT_SUPPORTED
;
2347 status
= dcesrv_netr_creds_server_step_check(p
->dce_call
,
2349 r
->in
.computer_name
,
2351 r
->out
.return_authenticator
,
2354 if (!NT_STATUS_IS_OK(status
)) {
2358 switch (r
->in
.query_level
) {
2360 r
->out
.capabilities
->server_capabilities
= creds
->negotiate_flags
;
2363 r
->out
.capabilities
->requested_flags
=
2364 creds
->ex
->client_requested_flags
;
2368 return NT_STATUS_OK
;
2371 /****************************************************************
2372 ****************************************************************/
2374 WERROR
_netr_NETRLOGONSETSERVICEBITS(struct pipes_struct
*p
,
2375 struct netr_NETRLOGONSETSERVICEBITS
*r
)
2377 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2378 return WERR_NOT_SUPPORTED
;
2381 /****************************************************************
2382 ****************************************************************/
2384 WERROR
_netr_LogonGetTrustRid(struct pipes_struct
*p
,
2385 struct netr_LogonGetTrustRid
*r
)
2387 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2388 return WERR_NOT_SUPPORTED
;
2391 /****************************************************************
2392 ****************************************************************/
2394 WERROR
_netr_NETRLOGONCOMPUTESERVERDIGEST(struct pipes_struct
*p
,
2395 struct netr_NETRLOGONCOMPUTESERVERDIGEST
*r
)
2397 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2398 return WERR_NOT_SUPPORTED
;
2401 /****************************************************************
2402 ****************************************************************/
2404 WERROR
_netr_NETRLOGONCOMPUTECLIENTDIGEST(struct pipes_struct
*p
,
2405 struct netr_NETRLOGONCOMPUTECLIENTDIGEST
*r
)
2407 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2408 return WERR_NOT_SUPPORTED
;
2411 /****************************************************************
2412 ****************************************************************/
2414 WERROR
_netr_DsRGetDCNameEx(struct pipes_struct
*p
,
2415 struct netr_DsRGetDCNameEx
*r
)
2417 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2418 return WERR_NOT_SUPPORTED
;
2421 /****************************************************************
2422 ****************************************************************/
2424 WERROR
_netr_DsRGetSiteName(struct pipes_struct
*p
,
2425 struct netr_DsRGetSiteName
*r
)
2427 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2428 return WERR_NOT_SUPPORTED
;
2431 /****************************************************************
2432 ****************************************************************/
2434 NTSTATUS
_netr_LogonGetDomainInfo(struct pipes_struct
*p
,
2435 struct netr_LogonGetDomainInfo
*r
)
2437 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2438 return NT_STATUS_NOT_IMPLEMENTED
;
2441 /****************************************************************
2442 ****************************************************************/
2444 NTSTATUS
_netr_ServerPasswordGet(struct pipes_struct
*p
,
2445 struct netr_ServerPasswordGet
*r
)
2447 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2448 return NT_STATUS_NOT_SUPPORTED
;
2451 /****************************************************************
2452 ****************************************************************/
2454 NTSTATUS
_netr_NetrLogonSendToSam(struct pipes_struct
*p
,
2455 struct netr_NetrLogonSendToSam
*r
)
2457 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2458 return NT_STATUS_NOT_IMPLEMENTED
;
2461 /****************************************************************
2462 ****************************************************************/
2464 WERROR
_netr_DsRAddressToSitenamesW(struct pipes_struct
*p
,
2465 struct netr_DsRAddressToSitenamesW
*r
)
2467 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2468 return WERR_NOT_SUPPORTED
;
2471 /****************************************************************
2472 ****************************************************************/
2474 WERROR
_netr_DsRGetDCNameEx2(struct pipes_struct
*p
,
2475 struct netr_DsRGetDCNameEx2
*r
)
2477 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2478 return WERR_NOT_SUPPORTED
;
2481 /****************************************************************
2482 ****************************************************************/
2484 WERROR
_netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN(struct pipes_struct
*p
,
2485 struct netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN
*r
)
2487 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2488 return WERR_NOT_SUPPORTED
;
2491 /****************************************************************
2492 ****************************************************************/
2494 WERROR
_netr_NetrEnumerateTrustedDomainsEx(struct pipes_struct
*p
,
2495 struct netr_NetrEnumerateTrustedDomainsEx
*r
)
2497 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2498 return WERR_NOT_SUPPORTED
;
2501 /****************************************************************
2502 ****************************************************************/
2504 WERROR
_netr_DsRAddressToSitenamesExW(struct pipes_struct
*p
,
2505 struct netr_DsRAddressToSitenamesExW
*r
)
2507 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2508 return WERR_NOT_SUPPORTED
;
2511 /****************************************************************
2512 ****************************************************************/
2514 WERROR
_netr_DsrGetDcSiteCoverageW(struct pipes_struct
*p
,
2515 struct netr_DsrGetDcSiteCoverageW
*r
)
2517 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2518 return WERR_NOT_SUPPORTED
;
2521 /****************************************************************
2522 ****************************************************************/
2524 WERROR
_netr_DsrEnumerateDomainTrusts(struct pipes_struct
*p
,
2525 struct netr_DsrEnumerateDomainTrusts
*r
)
2527 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2528 return WERR_NOT_SUPPORTED
;
2531 /****************************************************************
2532 ****************************************************************/
2534 WERROR
_netr_DsrDeregisterDNSHostRecords(struct pipes_struct
*p
,
2535 struct netr_DsrDeregisterDNSHostRecords
*r
)
2537 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2538 return WERR_NOT_SUPPORTED
;
2541 /****************************************************************
2542 ****************************************************************/
2544 NTSTATUS
_netr_ServerTrustPasswordsGet(struct pipes_struct
*p
,
2545 struct netr_ServerTrustPasswordsGet
*r
)
2547 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2548 return NT_STATUS_NOT_IMPLEMENTED
;
2551 /****************************************************************
2552 ****************************************************************/
2554 static NTSTATUS
fill_forest_trust_array(TALLOC_CTX
*mem_ctx
,
2555 struct lsa_ForestTrustInformation
*info
)
2557 struct lsa_ForestTrustRecord
*e
;
2558 struct pdb_domain_info
*dom_info
;
2559 struct lsa_ForestTrustDomainInfo
*domain_info
;
2560 char **upn_suffixes
= NULL
;
2561 uint32_t num_suffixes
= 0;
2565 dom_info
= pdb_get_domain_info(mem_ctx
);
2566 if (dom_info
== NULL
) {
2567 return NT_STATUS_NO_MEMORY
;
2573 status
= pdb_enum_upn_suffixes(info
, &num_suffixes
, &upn_suffixes
);
2575 if (NT_STATUS_IS_OK(status
) && (num_suffixes
> 0)) {
2576 info
->count
+= num_suffixes
;
2579 info
->entries
= talloc_array(info
, struct lsa_ForestTrustRecord
*, info
->count
);
2580 if (info
->entries
== NULL
) {
2581 return NT_STATUS_NO_MEMORY
;
2584 e
= talloc(info
, struct lsa_ForestTrustRecord
);
2586 return NT_STATUS_NO_MEMORY
;
2590 e
->type
= LSA_FOREST_TRUST_TOP_LEVEL_NAME
;
2591 e
->time
= 0; /* so far always 0 in trces. */
2592 e
->forest_trust_data
.top_level_name
.string
= talloc_steal(info
,
2593 dom_info
->dns_forest
);
2595 info
->entries
[0] = e
;
2597 if (num_suffixes
> 0) {
2598 for (i
= 0; i
< num_suffixes
; i
++) {
2599 e
= talloc(info
, struct lsa_ForestTrustRecord
);
2601 return NT_STATUS_NO_MEMORY
;
2605 e
->type
= LSA_FOREST_TRUST_TOP_LEVEL_NAME
;
2606 e
->time
= 0; /* so far always 0 in traces. */
2607 e
->forest_trust_data
.top_level_name
.string
= upn_suffixes
[i
];
2608 info
->entries
[1 + i
] = e
;
2612 e
= talloc(info
, struct lsa_ForestTrustRecord
);
2614 return NT_STATUS_NO_MEMORY
;
2617 /* TODO: check if disabled and set flags accordingly */
2619 e
->type
= LSA_FOREST_TRUST_DOMAIN_INFO
;
2620 e
->time
= 0; /* so far always 0 in traces. */
2622 domain_info
= &e
->forest_trust_data
.domain_info
;
2623 domain_info
->domain_sid
= dom_sid_dup(info
, &dom_info
->sid
);
2625 domain_info
->dns_domain_name
.string
= talloc_steal(info
,
2626 dom_info
->dns_domain
);
2627 domain_info
->netbios_domain_name
.string
= talloc_steal(info
,
2630 info
->entries
[info
->count
- 1] = e
;
2632 return NT_STATUS_OK
;
2635 /****************************************************************
2636 ****************************************************************/
2638 WERROR
_netr_DsRGetForestTrustInformation(struct pipes_struct
*p
,
2639 struct netr_DsRGetForestTrustInformation
*r
)
2641 struct dcesrv_call_state
*dce_call
= p
->dce_call
;
2642 struct auth_session_info
*session_info
=
2643 dcesrv_call_session_info(dce_call
);
2645 struct lsa_ForestTrustInformation
*info
, **info_ptr
;
2646 enum security_user_level security_level
;
2648 security_level
= security_session_user_level(session_info
, NULL
);
2649 if (security_level
< SECURITY_USER
) {
2650 return WERR_ACCESS_DENIED
;
2653 if (r
->in
.flags
& (~DS_GFTI_UPDATE_TDO
)) {
2654 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2655 return WERR_INVALID_FLAGS
;
2658 if ((r
->in
.flags
& DS_GFTI_UPDATE_TDO
) && (lp_server_role() != ROLE_DOMAIN_PDC
)) {
2659 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2660 return WERR_NERR_NOTPRIMARY
;
2663 if ((r
->in
.trusted_domain_name
== NULL
) && (r
->in
.flags
& DS_GFTI_UPDATE_TDO
)) {
2664 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2665 return WERR_INVALID_PARAMETER
;
2668 /* retrieve forest trust information and stop further processing */
2669 if (r
->in
.trusted_domain_name
== NULL
) {
2670 info_ptr
= talloc(p
->mem_ctx
, struct lsa_ForestTrustInformation
*);
2671 if (info_ptr
== NULL
) {
2672 p
->fault_state
= DCERPC_FAULT_CANT_PERFORM
;
2673 return WERR_NOT_ENOUGH_MEMORY
;
2675 info
= talloc_zero(info_ptr
, struct lsa_ForestTrustInformation
);
2677 p
->fault_state
= DCERPC_FAULT_CANT_PERFORM
;
2678 return WERR_NOT_ENOUGH_MEMORY
;
2681 /* Fill forest trust information and expand UPN suffixes list */
2682 status
= fill_forest_trust_array(p
->mem_ctx
, info
);
2683 if (!NT_STATUS_IS_OK(status
)) {
2684 p
->fault_state
= DCERPC_FAULT_CANT_PERFORM
;
2685 return WERR_NOT_ENOUGH_MEMORY
;
2689 r
->out
.forest_trust_info
= info_ptr
;
2695 /* TODO: implement remaining parts of DsrGetForestTrustInformation (opnum 43)
2696 * when trusted_domain_name is not NULL */
2698 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2699 return WERR_NOT_SUPPORTED
;
2702 /****************************************************************
2703 _netr_GetForestTrustInformation
2704 ****************************************************************/
2706 NTSTATUS
_netr_GetForestTrustInformation(struct pipes_struct
*p
,
2707 struct netr_GetForestTrustInformation
*r
)
2710 struct netlogon_creds_CredentialState
*creds
;
2711 struct lsa_ForestTrustInformation
*info
, **info_ptr
;
2713 /* TODO: check server name */
2716 status
= dcesrv_netr_creds_server_step_check(p
->dce_call
,
2718 r
->in
.computer_name
,
2720 r
->out
.return_authenticator
,
2723 if (!NT_STATUS_IS_OK(status
)) {
2727 if ((creds
->secure_channel_type
!= SEC_CHAN_DNS_DOMAIN
) &&
2728 (creds
->secure_channel_type
!= SEC_CHAN_DOMAIN
)) {
2729 return NT_STATUS_NOT_IMPLEMENTED
;
2732 info_ptr
= talloc(p
->mem_ctx
, struct lsa_ForestTrustInformation
*);
2734 return NT_STATUS_NO_MEMORY
;
2736 info
= talloc_zero(info_ptr
, struct lsa_ForestTrustInformation
);
2738 return NT_STATUS_NO_MEMORY
;
2741 /* Fill forest trust information, do expand UPN suffixes list */
2742 status
= fill_forest_trust_array(p
->mem_ctx
, info
);
2743 if (!NT_STATUS_IS_OK(status
)) {
2748 r
->out
.forest_trust_info
= info_ptr
;
2750 return NT_STATUS_OK
;
2753 /****************************************************************
2754 ****************************************************************/
2756 static NTSTATUS
get_password_from_trustAuth(TALLOC_CTX
*mem_ctx
,
2757 const DATA_BLOB
*trustAuth_blob
,
2758 struct netlogon_creds_CredentialState
*creds
,
2759 struct samr_Password
*current_pw_enc
,
2760 struct samr_Password
*previous_pw_enc
,
2761 enum dcerpc_AuthType auth_type
,
2762 enum dcerpc_AuthLevel auth_level
)
2764 enum ndr_err_code ndr_err
;
2765 struct trustAuthInOutBlob trustAuth
;
2768 ndr_err
= ndr_pull_struct_blob_all(trustAuth_blob
, mem_ctx
, &trustAuth
,
2769 (ndr_pull_flags_fn_t
)ndr_pull_trustAuthInOutBlob
);
2770 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2771 return NT_STATUS_UNSUCCESSFUL
;
2774 if (trustAuth
.count
!= 0 && trustAuth
.current
.count
!= 0 &&
2775 trustAuth
.current
.array
[0].AuthType
== TRUST_AUTH_TYPE_CLEAR
) {
2776 mdfour(current_pw_enc
->hash
,
2777 trustAuth
.current
.array
[0].AuthInfo
.clear
.password
,
2778 trustAuth
.current
.array
[0].AuthInfo
.clear
.size
);
2779 status
= netlogon_creds_encrypt_samr_Password(creds
,
2783 if (!NT_STATUS_IS_OK(status
)) {
2787 return NT_STATUS_UNSUCCESSFUL
;
2791 if (trustAuth
.previous
.count
!= 0 &&
2792 trustAuth
.previous
.array
[0].AuthType
== TRUST_AUTH_TYPE_CLEAR
) {
2793 mdfour(previous_pw_enc
->hash
,
2794 trustAuth
.previous
.array
[0].AuthInfo
.clear
.password
,
2795 trustAuth
.previous
.array
[0].AuthInfo
.clear
.size
);
2796 status
= netlogon_creds_encrypt_samr_Password(creds
,
2800 if (!NT_STATUS_IS_OK(status
)) {
2804 ZERO_STRUCTP(previous_pw_enc
);
2807 return NT_STATUS_OK
;
2810 /****************************************************************
2811 _netr_ServerGetTrustInfo
2812 ****************************************************************/
2814 NTSTATUS
_netr_ServerGetTrustInfo(struct pipes_struct
*p
,
2815 struct netr_ServerGetTrustInfo
*r
)
2818 struct netlogon_creds_CredentialState
*creds
;
2820 size_t account_name_last
;
2822 struct netr_TrustInfo
*trust_info
;
2823 struct pdb_trusted_domain
*td
;
2824 enum dcerpc_AuthType auth_type
= DCERPC_AUTH_TYPE_NONE
;
2825 enum dcerpc_AuthLevel auth_level
= DCERPC_AUTH_LEVEL_NONE
;
2827 dcesrv_call_auth_info(p
->dce_call
, &auth_type
, &auth_level
);
2829 /* TODO: check server name */
2832 status
= dcesrv_netr_creds_server_step_check(p
->dce_call
,
2834 r
->in
.computer_name
,
2836 r
->out
.return_authenticator
,
2839 if (!NT_STATUS_IS_OK(status
)) {
2843 account_name
= talloc_strdup(p
->mem_ctx
, r
->in
.account_name
);
2844 if (account_name
== NULL
) {
2845 return NT_STATUS_NO_MEMORY
;
2848 account_name_last
= strlen(account_name
);
2849 if (account_name_last
== 0) {
2850 return NT_STATUS_INVALID_PARAMETER
;
2852 account_name_last
--;
2853 if (account_name
[account_name_last
] == '.') {
2854 account_name
[account_name_last
] = '\0';
2857 if ((creds
->secure_channel_type
!= SEC_CHAN_DNS_DOMAIN
) &&
2858 (creds
->secure_channel_type
!= SEC_CHAN_DOMAIN
)) {
2866 account_name_last
= strlen(account_name
);
2867 if (account_name_last
== 0) {
2868 return NT_STATUS_INVALID_PARAMETER
;
2870 account_name_last
--;
2871 if (account_name
[account_name_last
] == '$') {
2872 account_name
[account_name_last
] = '\0';
2875 status
= pdb_get_trusted_domain(p
->mem_ctx
, account_name
, &td
);
2876 if (!NT_STATUS_IS_OK(status
)) {
2880 if (r
->out
.trust_info
!= NULL
) {
2881 trust_info
= talloc_zero(p
->mem_ctx
, struct netr_TrustInfo
);
2882 if (trust_info
== NULL
) {
2883 return NT_STATUS_NO_MEMORY
;
2885 trust_info
->count
= 1;
2887 trust_info
->data
= talloc_array(trust_info
, uint32_t, 1);
2888 if (trust_info
->data
== NULL
) {
2889 return NT_STATUS_NO_MEMORY
;
2891 trust_info
->data
[0] = td
->trust_attributes
;
2893 *r
->out
.trust_info
= trust_info
;
2896 if (td
->trust_auth_incoming
.data
== NULL
) {
2897 return NT_STATUS_INVALID_PARAMETER
;
2900 status
= get_password_from_trustAuth(p
->mem_ctx
,
2901 &td
->trust_auth_incoming
,
2903 r
->out
.new_owf_password
,
2904 r
->out
.old_owf_password
,
2907 if (!NT_STATUS_IS_OK(status
)) {
2912 /* TODO: look for machine password */
2913 ZERO_STRUCTP(r
->out
.new_owf_password
);
2914 ZERO_STRUCTP(r
->out
.old_owf_password
);
2916 return NT_STATUS_NOT_IMPLEMENTED
;
2919 return NT_STATUS_OK
;
2922 /****************************************************************
2923 ****************************************************************/
2925 NTSTATUS
_netr_Unused47(struct pipes_struct
*p
,
2926 struct netr_Unused47
*r
)
2928 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2929 return NT_STATUS_NOT_IMPLEMENTED
;
2932 /****************************************************************
2933 ****************************************************************/
2935 NTSTATUS
_netr_DsrUpdateReadOnlyServerDnsRecords(struct pipes_struct
*p
,
2936 struct netr_DsrUpdateReadOnlyServerDnsRecords
*r
)
2938 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2939 return NT_STATUS_NOT_IMPLEMENTED
;
2942 DCESRV_COMPAT_NOT_USED_ON_WIRE(netr_Opnum49NotUsedOnWire
)
2943 DCESRV_COMPAT_NOT_USED_ON_WIRE(netr_Opnum50NotUsedOnWire
)
2944 DCESRV_COMPAT_NOT_USED_ON_WIRE(netr_Opnum51NotUsedOnWire
)
2945 DCESRV_COMPAT_NOT_USED_ON_WIRE(netr_Opnum52NotUsedOnWire
)
2946 DCESRV_COMPAT_NOT_USED_ON_WIRE(netr_Opnum53NotUsedOnWire
)
2948 NTSTATUS
_netr_ChainSetClientAttributes(struct pipes_struct
*p
,
2949 struct netr_ChainSetClientAttributes
*r
)
2951 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2952 return NT_STATUS_NOT_IMPLEMENTED
;
2955 DCESRV_COMPAT_NOT_USED_ON_WIRE(netr_Opnum55NotUsedOnWire
)
2956 DCESRV_COMPAT_NOT_USED_ON_WIRE(netr_Opnum56NotUsedOnWire
)
2957 DCESRV_COMPAT_NOT_USED_ON_WIRE(netr_Opnum57NotUsedOnWire
)
2958 DCESRV_COMPAT_NOT_USED_ON_WIRE(netr_Opnum58NotUsedOnWire
)
2960 NTSTATUS
_netr_ServerAuthenticateKerberos(struct pipes_struct
*p
,
2961 struct netr_ServerAuthenticateKerberos
*r
)
2963 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2964 return NT_STATUS_NOT_IMPLEMENTED
;
2968 * Define the bind function that will be used by ndr_netlogon_scompat.c,
2969 * included at the bottom of this file.
2971 #define DCESRV_INTERFACE_NETLOGON_BIND(context, iface) \
2972 dcesrv_interface_netlogon_bind(context, iface)
2974 static NTSTATUS
dcesrv_interface_netlogon_bind(struct dcesrv_connection_context
*context
,
2975 const struct dcesrv_interface
*iface
)
2977 struct loadparm_context
*lp_ctx
= context
->conn
->dce_ctx
->lp_ctx
;
2978 int schannel
= lpcfg_server_schannel(lp_ctx
);
2979 bool schannel_global_required
= (schannel
== true);
2980 bool global_require_seal
= lpcfg_server_schannel_require_seal(lp_ctx
);
2981 static bool warned_global_schannel_once
= false;
2982 static bool warned_global_seal_once
= false;
2984 if (!schannel_global_required
&& !warned_global_schannel_once
) {
2986 * We want admins to notice their misconfiguration!
2988 D_ERR("CVE-2020-1472(ZeroLogon): "
2989 "Please configure 'server schannel = yes' (the default), "
2990 "See https://bugzilla.samba.org/show_bug.cgi?id=14497\n");
2991 warned_global_schannel_once
= true;
2994 if (!global_require_seal
&& !warned_global_seal_once
) {
2996 * We want admins to notice their misconfiguration!
2998 D_ERR("CVE-2022-38023 (and others): "
2999 "Please configure 'server schannel require seal = yes' (the default), "
3000 "See https://bugzilla.samba.org/show_bug.cgi?id=15240\n");
3001 warned_global_seal_once
= true;
3004 return NT_STATUS_OK
;
3007 /* include the generated boilerplate */
3008 #include "librpc/gen_ndr/ndr_netlogon_scompat.c"