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/gen_ndr/srv_netlogon.h"
32 #include "../librpc/gen_ndr/ndr_samr_c.h"
33 #include "../librpc/gen_ndr/ndr_lsa_c.h"
34 #include "rpc_client/cli_lsarpc.h"
35 #include "rpc_client/init_lsa.h"
36 #include "rpc_server/rpc_ncacn_np.h"
37 #include "../libcli/security/security.h"
38 #include "../libcli/security/dom_sid.h"
39 #include "librpc/gen_ndr/ndr_drsblobs.h"
40 #include "lib/crypto/arcfour.h"
41 #include "lib/crypto/md4.h"
42 #include "nsswitch/libwbclient/wbclient.h"
43 #include "../libcli/registry/util_reg.h"
47 #include "../lib/tsocket/tsocket.h"
48 #include "lib/param/param.h"
50 extern userdom_struct current_user_info
;
53 #define DBGC_CLASS DBGC_RPC_SRV
55 struct netlogon_server_pipe_state
{
56 struct netr_Credential client_challenge
;
57 struct netr_Credential server_challenge
;
60 /*************************************************************************
62 *************************************************************************/
64 WERROR
_netr_LogonControl(struct pipes_struct
*p
,
65 struct netr_LogonControl
*r
)
67 struct netr_LogonControl2Ex l
;
69 switch (r
->in
.level
) {
73 return WERR_NOT_SUPPORTED
;
75 return WERR_UNKNOWN_LEVEL
;
78 l
.in
.logon_server
= r
->in
.logon_server
;
79 l
.in
.function_code
= r
->in
.function_code
;
80 l
.in
.level
= r
->in
.level
;
82 l
.out
.query
= r
->out
.query
;
84 return _netr_LogonControl2Ex(p
, &l
);
87 /*************************************************************************
89 *************************************************************************/
91 WERROR
_netr_LogonControl2(struct pipes_struct
*p
,
92 struct netr_LogonControl2
*r
)
94 struct netr_LogonControl2Ex l
;
96 l
.in
.logon_server
= r
->in
.logon_server
;
97 l
.in
.function_code
= r
->in
.function_code
;
98 l
.in
.level
= r
->in
.level
;
99 l
.in
.data
= r
->in
.data
;
100 l
.out
.query
= r
->out
.query
;
102 return _netr_LogonControl2Ex(p
, &l
);
105 /*************************************************************************
106 *************************************************************************/
108 static bool wb_change_trust_creds(const char *domain
, WERROR
*tc_status
)
111 struct wbcAuthErrorInfo
*error
= NULL
;
113 result
= wbcChangeTrustCredentials(domain
, &error
);
115 case WBC_ERR_WINBIND_NOT_AVAILABLE
:
117 case WBC_ERR_DOMAIN_NOT_FOUND
:
118 *tc_status
= WERR_NO_SUCH_DOMAIN
;
120 case WBC_ERR_SUCCESS
:
121 *tc_status
= WERR_OK
;
127 if (error
&& error
->nt_status
!= 0) {
128 *tc_status
= ntstatus_to_werror(NT_STATUS(error
->nt_status
));
130 *tc_status
= WERR_TRUST_FAILURE
;
132 wbcFreeMemory(error
);
136 /*************************************************************************
137 *************************************************************************/
139 static bool wb_check_trust_creds(const char *domain
, WERROR
*tc_status
)
142 struct wbcAuthErrorInfo
*error
= NULL
;
144 result
= wbcCheckTrustCredentials(domain
, &error
);
146 case WBC_ERR_WINBIND_NOT_AVAILABLE
:
148 case WBC_ERR_DOMAIN_NOT_FOUND
:
149 *tc_status
= WERR_NO_SUCH_DOMAIN
;
151 case WBC_ERR_SUCCESS
:
152 *tc_status
= WERR_OK
;
158 if (error
&& error
->nt_status
!= 0) {
159 *tc_status
= ntstatus_to_werror(NT_STATUS(error
->nt_status
));
161 *tc_status
= WERR_TRUST_FAILURE
;
163 wbcFreeMemory(error
);
167 /****************************************************************
168 _netr_LogonControl2Ex
169 ****************************************************************/
171 WERROR
_netr_LogonControl2Ex(struct pipes_struct
*p
,
172 struct netr_LogonControl2Ex
*r
)
174 uint32_t flags
= 0x0;
175 WERROR pdc_connection_status
= WERR_OK
;
176 uint32_t logon_attempts
= 0x0;
179 const char *dc_name
= NULL
;
180 struct sockaddr_storage dc_ss
;
181 const char *domain
= NULL
;
182 struct netr_NETLOGON_INFO_1
*info1
;
183 struct netr_NETLOGON_INFO_2
*info2
;
184 struct netr_NETLOGON_INFO_3
*info3
;
185 struct netr_NETLOGON_INFO_4
*info4
;
189 struct netr_DsRGetDCNameInfo
*dc_info
;
192 case NDR_NETR_LOGONCONTROL
:
193 fn
= "_netr_LogonControl";
195 case NDR_NETR_LOGONCONTROL2
:
196 fn
= "_netr_LogonControl2";
198 case NDR_NETR_LOGONCONTROL2EX
:
199 fn
= "_netr_LogonControl2Ex";
202 return WERR_INVALID_PARAM
;
205 acct_ctrl
= p
->session_info
->info
->acct_flags
;
207 switch (r
->in
.function_code
) {
208 case NETLOGON_CONTROL_TC_VERIFY
:
209 case NETLOGON_CONTROL_CHANGE_PASSWORD
:
210 case NETLOGON_CONTROL_REDISCOVER
:
211 if ((geteuid() != sec_initial_uid()) &&
212 !nt_token_check_domain_rid(p
->session_info
->security_token
, DOMAIN_RID_ADMINS
) &&
213 !nt_token_check_sid(&global_sid_Builtin_Administrators
, p
->session_info
->security_token
) &&
214 !(acct_ctrl
& (ACB_WSTRUST
| ACB_SVRTRUST
))) {
215 return WERR_ACCESS_DENIED
;
222 tc_status
= WERR_NO_SUCH_DOMAIN
;
224 switch (r
->in
.function_code
) {
225 case NETLOGON_CONTROL_QUERY
:
228 case NETLOGON_CONTROL_REPLICATE
:
229 case NETLOGON_CONTROL_SYNCHRONIZE
:
230 case NETLOGON_CONTROL_PDC_REPLICATE
:
231 case NETLOGON_CONTROL_BACKUP_CHANGE_LOG
:
232 case NETLOGON_CONTROL_BREAKPOINT
:
233 if (acct_ctrl
& ACB_NORMAL
) {
234 return WERR_NOT_SUPPORTED
;
235 } else if (acct_ctrl
& (ACB_WSTRUST
| ACB_SVRTRUST
)) {
236 return WERR_ACCESS_DENIED
;
238 return WERR_ACCESS_DENIED
;
240 case NETLOGON_CONTROL_TRUNCATE_LOG
:
241 if (acct_ctrl
& ACB_NORMAL
) {
243 } else if (acct_ctrl
& (ACB_WSTRUST
| ACB_SVRTRUST
)) {
244 return WERR_ACCESS_DENIED
;
246 return WERR_ACCESS_DENIED
;
249 case NETLOGON_CONTROL_TRANSPORT_NOTIFY
:
250 case NETLOGON_CONTROL_FORCE_DNS_REG
:
251 case NETLOGON_CONTROL_QUERY_DNS_REG
:
252 return WERR_NOT_SUPPORTED
;
253 case NETLOGON_CONTROL_FIND_USER
:
254 if (!r
->in
.data
|| !r
->in
.data
->user
) {
255 return WERR_NOT_SUPPORTED
;
258 case NETLOGON_CONTROL_SET_DBFLAG
:
260 return WERR_NOT_SUPPORTED
;
263 case NETLOGON_CONTROL_TC_VERIFY
:
264 if (!r
->in
.data
|| !r
->in
.data
->domain
) {
265 return WERR_NOT_SUPPORTED
;
268 if (!wb_check_trust_creds(r
->in
.data
->domain
, &tc_status
)) {
269 return WERR_NOT_SUPPORTED
;
272 case NETLOGON_CONTROL_TC_QUERY
:
273 if (!r
->in
.data
|| !r
->in
.data
->domain
) {
274 return WERR_NOT_SUPPORTED
;
277 domain
= r
->in
.data
->domain
;
279 if (!is_trusted_domain(domain
)) {
283 if (!get_dc_name(domain
, NULL
, dc_name2
, &dc_ss
)) {
284 tc_status
= WERR_NO_LOGON_SERVERS
;
288 dc_name
= talloc_asprintf(p
->mem_ctx
, "\\\\%s", dc_name2
);
297 case NETLOGON_CONTROL_REDISCOVER
:
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 status
= dsgetdcname(p
->mem_ctx
, p
->msg_ctx
, domain
, NULL
, NULL
,
309 DS_FORCE_REDISCOVERY
| DS_RETURN_FLAT_NAME
,
311 if (!NT_STATUS_IS_OK(status
)) {
312 tc_status
= WERR_NO_LOGON_SERVERS
;
316 dc_name
= talloc_asprintf(p
->mem_ctx
, "\\\\%s", dc_info
->dc_unc
);
325 case NETLOGON_CONTROL_CHANGE_PASSWORD
:
326 if (!r
->in
.data
|| !r
->in
.data
->domain
) {
327 return WERR_NOT_SUPPORTED
;
330 if (!wb_change_trust_creds(r
->in
.data
->domain
, &tc_status
)) {
331 return WERR_NOT_SUPPORTED
;
336 /* no idea what this should be */
337 DEBUG(0,("%s: unimplemented function level [%d]\n",
338 fn
, r
->in
.function_code
));
339 return WERR_UNKNOWN_LEVEL
;
342 /* prepare the response */
344 switch (r
->in
.level
) {
346 info1
= talloc_zero(p
->mem_ctx
, struct netr_NETLOGON_INFO_1
);
347 W_ERROR_HAVE_NO_MEMORY(info1
);
349 info1
->flags
= flags
;
350 info1
->pdc_connection_status
= pdc_connection_status
;
352 r
->out
.query
->info1
= info1
;
355 info2
= talloc_zero(p
->mem_ctx
, struct netr_NETLOGON_INFO_2
);
356 W_ERROR_HAVE_NO_MEMORY(info2
);
358 info2
->flags
= flags
;
359 info2
->pdc_connection_status
= pdc_connection_status
;
360 info2
->trusted_dc_name
= dc_name
;
361 info2
->tc_connection_status
= tc_status
;
363 r
->out
.query
->info2
= info2
;
366 info3
= talloc_zero(p
->mem_ctx
, struct netr_NETLOGON_INFO_3
);
367 W_ERROR_HAVE_NO_MEMORY(info3
);
369 info3
->flags
= flags
;
370 info3
->logon_attempts
= logon_attempts
;
372 r
->out
.query
->info3
= info3
;
375 info4
= talloc_zero(p
->mem_ctx
, struct netr_NETLOGON_INFO_4
);
376 W_ERROR_HAVE_NO_MEMORY(info4
);
378 info4
->trusted_dc_name
= dc_name
;
379 info4
->trusted_domain_name
= r
->in
.data
->domain
;
381 r
->out
.query
->info4
= info4
;
384 return WERR_UNKNOWN_LEVEL
;
390 /*************************************************************************
391 _netr_NetrEnumerateTrustedDomains
392 *************************************************************************/
394 NTSTATUS
_netr_NetrEnumerateTrustedDomains(struct pipes_struct
*p
,
395 struct netr_NetrEnumerateTrustedDomains
*r
)
398 NTSTATUS result
= NT_STATUS_OK
;
401 const char **trusted_domains
= NULL
;
402 struct lsa_DomainList domain_list
;
403 struct dcerpc_binding_handle
*h
= NULL
;
404 struct policy_handle pol
;
405 uint32_t enum_ctx
= 0;
407 uint32_t max_size
= (uint32_t)-1;
409 DEBUG(6,("_netr_NetrEnumerateTrustedDomains: %d\n", __LINE__
));
411 status
= rpcint_binding_handle(p
->mem_ctx
,
417 if (!NT_STATUS_IS_OK(status
)) {
421 status
= dcerpc_lsa_open_policy2(h
,
425 LSA_POLICY_VIEW_LOCAL_INFORMATION
,
428 if (!NT_STATUS_IS_OK(status
)) {
431 if (!NT_STATUS_IS_OK(result
)) {
437 /* Lookup list of trusted domains */
438 status
= dcerpc_lsa_EnumTrustDom(h
,
445 if (!NT_STATUS_IS_OK(status
)) {
448 if (!NT_STATUS_IS_OK(result
) &&
449 !NT_STATUS_EQUAL(result
, NT_STATUS_NO_MORE_ENTRIES
) &&
450 !NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
)) {
455 for (i
= 0; i
< domain_list
.count
; i
++) {
456 if (!add_string_to_array(p
->mem_ctx
, domain_list
.domains
[i
].name
.string
,
457 &trusted_domains
, &num_domains
)) {
458 status
= NT_STATUS_NO_MEMORY
;
462 } while (NT_STATUS_EQUAL(result
, STATUS_MORE_ENTRIES
));
464 if (num_domains
> 0) {
465 /* multi sz terminate */
466 trusted_domains
= talloc_realloc(p
->mem_ctx
, trusted_domains
, const char *, num_domains
+ 1);
467 if (trusted_domains
== NULL
) {
468 status
= NT_STATUS_NO_MEMORY
;
472 trusted_domains
[num_domains
] = NULL
;
475 if (!push_reg_multi_sz(trusted_domains
, &blob
, trusted_domains
)) {
476 TALLOC_FREE(trusted_domains
);
477 status
= NT_STATUS_NO_MEMORY
;
481 r
->out
.trusted_domains_blob
->data
= blob
.data
;
482 r
->out
.trusted_domains_blob
->length
= blob
.length
;
484 DEBUG(6,("_netr_NetrEnumerateTrustedDomains: %d\n", __LINE__
));
486 status
= NT_STATUS_OK
;
489 if (is_valid_policy_hnd(&pol
)) {
490 dcerpc_lsa_Close(h
, p
->mem_ctx
, &pol
, &result
);
496 /*************************************************************************
497 *************************************************************************/
499 static NTSTATUS
samr_find_machine_account(TALLOC_CTX
*mem_ctx
,
500 struct dcerpc_binding_handle
*b
,
501 const char *account_name
,
502 uint32_t access_mask
,
503 struct dom_sid2
**domain_sid_p
,
504 uint32_t *user_rid_p
,
505 struct policy_handle
*user_handle
)
508 NTSTATUS result
= NT_STATUS_OK
;
509 struct policy_handle connect_handle
;
510 struct policy_handle domain_handle
= { 0, };
511 struct lsa_String domain_name
;
512 struct dom_sid2
*domain_sid
;
513 struct lsa_String names
;
514 struct samr_Ids rids
;
515 struct samr_Ids types
;
518 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
520 SAMR_ACCESS_CONNECT_TO_SERVER
|
521 SAMR_ACCESS_ENUM_DOMAINS
|
522 SAMR_ACCESS_LOOKUP_DOMAIN
,
525 if (!NT_STATUS_IS_OK(status
)) {
528 if (!NT_STATUS_IS_OK(result
)) {
533 init_lsa_String(&domain_name
, get_global_sam_name());
535 status
= dcerpc_samr_LookupDomain(b
, mem_ctx
,
540 if (!NT_STATUS_IS_OK(status
)) {
543 if (!NT_STATUS_IS_OK(result
)) {
548 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
550 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
,
554 if (!NT_STATUS_IS_OK(status
)) {
557 if (!NT_STATUS_IS_OK(result
)) {
562 init_lsa_String(&names
, account_name
);
564 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
571 if (!NT_STATUS_IS_OK(status
)) {
574 if (!NT_STATUS_IS_OK(result
)) {
579 if (rids
.count
!= 1) {
580 status
= NT_STATUS_NO_SUCH_USER
;
583 if (types
.count
!= 1) {
584 status
= NT_STATUS_INVALID_PARAMETER
;
587 if (types
.ids
[0] != SID_NAME_USER
) {
588 status
= NT_STATUS_NO_SUCH_USER
;
594 status
= dcerpc_samr_OpenUser(b
, mem_ctx
,
600 if (!NT_STATUS_IS_OK(status
)) {
603 if (!NT_STATUS_IS_OK(result
)) {
613 *domain_sid_p
= domain_sid
;
617 if (is_valid_policy_hnd(&domain_handle
)) {
618 dcerpc_samr_Close(b
, mem_ctx
, &domain_handle
, &result
);
620 if (is_valid_policy_hnd(&connect_handle
)) {
621 dcerpc_samr_Close(b
, mem_ctx
, &connect_handle
, &result
);
627 /******************************************************************
628 gets a machine password entry. checks access rights of the host.
629 ******************************************************************/
631 static NTSTATUS
get_md4pw(struct samr_Password
*md4pw
, const char *mach_acct
,
632 enum netr_SchannelType sec_chan_type
,
634 struct messaging_context
*msg_ctx
)
637 NTSTATUS result
= NT_STATUS_OK
;
639 struct dcerpc_binding_handle
*h
= NULL
;
640 struct tsocket_address
*local
;
641 struct policy_handle user_handle
;
643 struct dom_sid
*domain_sid
;
645 union samr_UserInfo
*info
;
646 struct auth_session_info
*session_info
;
652 * Currently this code is redundent as we already have a filter
653 * by hostname list. What this code really needs to do is to
654 * get a hosts allowed/hosts denied list from the SAM database
655 * on a per user basis, and make the access decision there.
656 * I will leave this code here for now as a reminder to implement
657 * this at a later date. JRA.
660 if (!allow_access(lp_domain_hostsdeny(), lp_domain_hostsallow(),
662 p
->client_id
.addr
)) {
663 DEBUG(0,("get_md4pw: Workstation %s denied access to domain\n", mach_acct
));
668 mem_ctx
= talloc_stackframe();
669 if (mem_ctx
== NULL
) {
670 status
= NT_STATUS_NO_MEMORY
;
674 status
= make_session_info_system(mem_ctx
, &session_info
);
675 if (!NT_STATUS_IS_OK(status
)) {
679 ZERO_STRUCT(user_handle
);
681 rc
= tsocket_address_inet_from_strings(mem_ctx
,
687 status
= NT_STATUS_NO_MEMORY
;
691 status
= rpcint_binding_handle(mem_ctx
,
697 if (!NT_STATUS_IS_OK(status
)) {
702 status
= samr_find_machine_account(mem_ctx
, h
, mach_acct
,
703 SEC_FLAG_MAXIMUM_ALLOWED
,
704 &domain_sid
, &user_rid
,
707 if (!NT_STATUS_IS_OK(status
)) {
711 status
= dcerpc_samr_QueryUserInfo2(h
,
714 UserControlInformation
,
717 if (!NT_STATUS_IS_OK(status
)) {
720 if (!NT_STATUS_IS_OK(result
)) {
725 acct_ctrl
= info
->info16
.acct_flags
;
727 if (acct_ctrl
& ACB_DISABLED
) {
728 DEBUG(0,("get_md4pw: Workstation %s: account is disabled\n", mach_acct
));
729 status
= NT_STATUS_ACCOUNT_DISABLED
;
733 if (!(acct_ctrl
& ACB_SVRTRUST
) &&
734 !(acct_ctrl
& ACB_WSTRUST
) &&
735 !(acct_ctrl
& ACB_DOMTRUST
))
737 DEBUG(0,("get_md4pw: Workstation %s: account is not a trust account\n", mach_acct
));
738 status
= NT_STATUS_NO_TRUST_SAM_ACCOUNT
;
742 switch (sec_chan_type
) {
744 if (!(acct_ctrl
& ACB_SVRTRUST
)) {
745 DEBUG(0,("get_md4pw: Workstation %s: BDC secure channel requested "
746 "but not a server trust account\n", mach_acct
));
747 status
= NT_STATUS_NO_TRUST_SAM_ACCOUNT
;
752 if (!(acct_ctrl
& ACB_WSTRUST
)) {
753 DEBUG(0,("get_md4pw: Workstation %s: WORKSTATION secure channel requested "
754 "but not a workstation trust account\n", mach_acct
));
755 status
= NT_STATUS_NO_TRUST_SAM_ACCOUNT
;
759 case SEC_CHAN_DOMAIN
:
760 if (!(acct_ctrl
& ACB_DOMTRUST
)) {
761 DEBUG(0,("get_md4pw: Workstation %s: DOMAIN secure channel requested "
762 "but not a interdomain trust account\n", mach_acct
));
763 status
= NT_STATUS_NO_TRUST_SAM_ACCOUNT
;
772 status
= dcerpc_samr_QueryUserInfo2(h
,
775 UserInternal1Information
,
779 if (!NT_STATUS_IS_OK(status
)) {
782 if (!NT_STATUS_IS_OK(result
)) {
787 if (info
->info18
.nt_pwd_active
== 0) {
788 DEBUG(0,("get_md4pw: Workstation %s: account does not have a password\n", mach_acct
));
789 status
= NT_STATUS_LOGON_FAILURE
;
793 /* samr gives out nthash unencrypted (!) */
794 memcpy(md4pw
->hash
, info
->info18
.nt_pwd
.hash
, 16);
796 sid_compose(sid
, domain_sid
, user_rid
);
799 if (h
&& is_valid_policy_hnd(&user_handle
)) {
800 dcerpc_samr_Close(h
, mem_ctx
, &user_handle
, &result
);
803 talloc_free(mem_ctx
);
808 /*************************************************************************
809 _netr_ServerReqChallenge
810 *************************************************************************/
812 NTSTATUS
_netr_ServerReqChallenge(struct pipes_struct
*p
,
813 struct netr_ServerReqChallenge
*r
)
815 struct netlogon_server_pipe_state
*pipe_state
=
816 talloc_get_type(p
->private_data
, struct netlogon_server_pipe_state
);
819 DEBUG(10,("_netr_ServerReqChallenge: new challenge requested. Clearing old state.\n"));
820 talloc_free(pipe_state
);
821 p
->private_data
= NULL
;
824 pipe_state
= talloc(p
, struct netlogon_server_pipe_state
);
825 NT_STATUS_HAVE_NO_MEMORY(pipe_state
);
827 pipe_state
->client_challenge
= *r
->in
.credentials
;
829 generate_random_buffer(pipe_state
->server_challenge
.data
,
830 sizeof(pipe_state
->server_challenge
.data
));
832 *r
->out
.return_credentials
= pipe_state
->server_challenge
;
834 p
->private_data
= pipe_state
;
839 /*************************************************************************
840 _netr_ServerAuthenticate
841 Create the initial credentials.
842 *************************************************************************/
844 NTSTATUS
_netr_ServerAuthenticate(struct pipes_struct
*p
,
845 struct netr_ServerAuthenticate
*r
)
847 struct netr_ServerAuthenticate3 a
;
848 uint32_t negotiate_flags
= 0;
851 a
.in
.server_name
= r
->in
.server_name
;
852 a
.in
.account_name
= r
->in
.account_name
;
853 a
.in
.secure_channel_type
= r
->in
.secure_channel_type
;
854 a
.in
.computer_name
= r
->in
.computer_name
;
855 a
.in
.credentials
= r
->in
.credentials
;
856 a
.in
.negotiate_flags
= &negotiate_flags
;
858 a
.out
.return_credentials
= r
->out
.return_credentials
;
860 a
.out
.negotiate_flags
= &negotiate_flags
;
862 return _netr_ServerAuthenticate3(p
, &a
);
866 /*************************************************************************
867 _netr_ServerAuthenticate3
868 *************************************************************************/
870 NTSTATUS
_netr_ServerAuthenticate3(struct pipes_struct
*p
,
871 struct netr_ServerAuthenticate3
*r
)
875 /* r->in.negotiate_flags is an aliased pointer to r->out.negotiate_flags,
876 * so use a copy to avoid destroying the client values. */
877 uint32_t in_neg_flags
= *r
->in
.negotiate_flags
;
879 struct loadparm_context
*lp_ctx
;
881 struct samr_Password mach_pwd
;
882 struct netlogon_creds_CredentialState
*creds
;
883 struct netlogon_server_pipe_state
*pipe_state
=
884 talloc_get_type(p
->private_data
, struct netlogon_server_pipe_state
);
886 /* According to Microsoft (see bugid #6099)
887 * Windows 7 looks at the negotiate_flags
888 * returned in this structure *even if the
889 * call fails with access denied* ! So in order
890 * to allow Win7 to connect to a Samba NT style
891 * PDC we set the flags before we know if it's
896 srv_flgs
= NETLOGON_NEG_ACCOUNT_LOCKOUT
|
897 NETLOGON_NEG_PERSISTENT_SAMREPL
|
898 NETLOGON_NEG_ARCFOUR
|
899 NETLOGON_NEG_PROMOTION_COUNT
|
900 NETLOGON_NEG_CHANGELOG_BDC
|
901 NETLOGON_NEG_FULL_SYNC_REPL
|
902 NETLOGON_NEG_MULTIPLE_SIDS
|
904 NETLOGON_NEG_PASSWORD_CHANGE_REFUSAL
|
905 NETLOGON_NEG_PASSWORD_SET2
;
907 /* Ensure we support strong (128-bit) keys. */
908 if (in_neg_flags
& NETLOGON_NEG_STRONG_KEYS
) {
909 srv_flgs
|= NETLOGON_NEG_STRONG_KEYS
;
912 if (in_neg_flags
& NETLOGON_NEG_SUPPORTS_AES
) {
913 srv_flgs
|= NETLOGON_NEG_SUPPORTS_AES
;
916 if (lp_server_schannel() != false) {
917 srv_flgs
|= NETLOGON_NEG_SCHANNEL
;
921 * Support authenticaten of trusted domains.
923 * These flags are the minimum required set which works with win2k3
926 if (pdb_capabilities() & PDB_CAP_TRUSTED_DOMAINS_EX
) {
927 srv_flgs
|= NETLOGON_NEG_TRANSITIVE_TRUSTS
|
928 NETLOGON_NEG_DNS_DOMAIN_TRUSTS
|
929 NETLOGON_NEG_CROSS_FOREST_TRUSTS
|
930 NETLOGON_NEG_NEUTRALIZE_NT4_EMULATION
;
934 case NDR_NETR_SERVERAUTHENTICATE
:
935 fn
= "_netr_ServerAuthenticate";
937 case NDR_NETR_SERVERAUTHENTICATE2
:
938 fn
= "_netr_ServerAuthenticate2";
940 case NDR_NETR_SERVERAUTHENTICATE3
:
941 fn
= "_netr_ServerAuthenticate3";
944 return NT_STATUS_INTERNAL_ERROR
;
947 /* We use this as the key to store the creds: */
948 /* r->in.computer_name */
951 DEBUG(0,("%s: no challenge sent to client %s\n", fn
,
952 r
->in
.computer_name
));
953 status
= NT_STATUS_ACCESS_DENIED
;
957 if ( (lp_server_schannel() == true) &&
958 ((in_neg_flags
& NETLOGON_NEG_SCHANNEL
) == 0) ) {
960 /* schannel must be used, but client did not offer it. */
961 DEBUG(0,("%s: schannel required but client failed "
962 "to offer it. Client was %s\n",
963 fn
, r
->in
.account_name
));
964 status
= NT_STATUS_ACCESS_DENIED
;
968 status
= get_md4pw(&mach_pwd
,
970 r
->in
.secure_channel_type
,
972 if (!NT_STATUS_IS_OK(status
)) {
973 DEBUG(0,("%s: failed to get machine password for "
975 fn
, r
->in
.account_name
, nt_errstr(status
) ));
976 /* always return NT_STATUS_ACCESS_DENIED */
977 status
= NT_STATUS_ACCESS_DENIED
;
981 /* From the client / server challenges and md4 password, generate sess key */
982 /* Check client credentials are valid. */
983 creds
= netlogon_creds_server_init(p
->mem_ctx
,
986 r
->in
.secure_channel_type
,
987 &pipe_state
->client_challenge
,
988 &pipe_state
->server_challenge
,
991 r
->out
.return_credentials
,
994 DEBUG(0,("%s: netlogon_creds_server_check failed. Rejecting auth "
995 "request from client %s machine account %s\n",
996 fn
, r
->in
.computer_name
,
997 r
->in
.account_name
));
998 status
= NT_STATUS_ACCESS_DENIED
;
1002 creds
->sid
= dom_sid_dup(creds
, &sid
);
1004 status
= NT_STATUS_NO_MEMORY
;
1008 lp_ctx
= loadparm_init_s3(p
->mem_ctx
, loadparm_s3_helpers());
1009 if (lp_ctx
== NULL
) {
1010 DEBUG(10, ("loadparm_init_s3 failed\n"));
1011 status
= NT_STATUS_INTERNAL_ERROR
;
1015 /* Store off the state so we can continue after client disconnect. */
1017 status
= schannel_save_creds_state(p
->mem_ctx
, lp_ctx
, creds
);
1020 talloc_unlink(p
->mem_ctx
, lp_ctx
);
1022 if (!NT_STATUS_IS_OK(status
)) {
1026 sid_peek_rid(&sid
, r
->out
.rid
);
1028 status
= NT_STATUS_OK
;
1032 *r
->out
.negotiate_flags
= srv_flgs
;
1036 /*************************************************************************
1037 _netr_ServerAuthenticate2
1038 *************************************************************************/
1040 NTSTATUS
_netr_ServerAuthenticate2(struct pipes_struct
*p
,
1041 struct netr_ServerAuthenticate2
*r
)
1043 struct netr_ServerAuthenticate3 a
;
1046 a
.in
.server_name
= r
->in
.server_name
;
1047 a
.in
.account_name
= r
->in
.account_name
;
1048 a
.in
.secure_channel_type
= r
->in
.secure_channel_type
;
1049 a
.in
.computer_name
= r
->in
.computer_name
;
1050 a
.in
.credentials
= r
->in
.credentials
;
1051 a
.in
.negotiate_flags
= r
->in
.negotiate_flags
;
1053 a
.out
.return_credentials
= r
->out
.return_credentials
;
1055 a
.out
.negotiate_flags
= r
->out
.negotiate_flags
;
1057 return _netr_ServerAuthenticate3(p
, &a
);
1060 /*************************************************************************
1061 * If schannel is required for this call test that it actually is available.
1062 *************************************************************************/
1063 static NTSTATUS
schannel_check_required(struct pipe_auth_data
*auth_info
,
1064 const char *computer_name
,
1065 bool integrity
, bool privacy
)
1067 if (auth_info
&& auth_info
->auth_type
== DCERPC_AUTH_TYPE_SCHANNEL
) {
1068 if (!privacy
&& !integrity
) {
1069 return NT_STATUS_OK
;
1072 if ((!privacy
&& integrity
) &&
1073 auth_info
->auth_level
== DCERPC_AUTH_LEVEL_INTEGRITY
) {
1074 return NT_STATUS_OK
;
1077 if ((privacy
|| integrity
) &&
1078 auth_info
->auth_level
== DCERPC_AUTH_LEVEL_PRIVACY
) {
1079 return NT_STATUS_OK
;
1083 /* test didn't pass */
1084 DEBUG(0, ("schannel_check_required: [%s] is not using schannel\n",
1087 return NT_STATUS_ACCESS_DENIED
;
1090 /*************************************************************************
1091 *************************************************************************/
1093 static NTSTATUS
netr_creds_server_step_check(struct pipes_struct
*p
,
1094 TALLOC_CTX
*mem_ctx
,
1095 const char *computer_name
,
1096 struct netr_Authenticator
*received_authenticator
,
1097 struct netr_Authenticator
*return_authenticator
,
1098 struct netlogon_creds_CredentialState
**creds_out
)
1101 bool schannel_global_required
= (lp_server_schannel() == true) ? true:false;
1102 struct loadparm_context
*lp_ctx
;
1104 if (creds_out
!= NULL
) {
1108 if (schannel_global_required
) {
1109 status
= schannel_check_required(&p
->auth
,
1112 if (!NT_STATUS_IS_OK(status
)) {
1117 lp_ctx
= loadparm_init_s3(mem_ctx
, loadparm_s3_helpers());
1118 if (lp_ctx
== NULL
) {
1119 DEBUG(0, ("loadparm_init_s3 failed\n"));
1120 return NT_STATUS_INTERNAL_ERROR
;
1123 status
= schannel_check_creds_state(mem_ctx
, lp_ctx
,
1124 computer_name
, received_authenticator
,
1125 return_authenticator
, creds_out
);
1126 talloc_unlink(mem_ctx
, lp_ctx
);
1130 /*************************************************************************
1131 *************************************************************************/
1133 static NTSTATUS
netr_set_machine_account_password(TALLOC_CTX
*mem_ctx
,
1134 struct auth_session_info
*session_info
,
1135 struct messaging_context
*msg_ctx
,
1136 const char *account_name
,
1137 struct samr_Password
*nt_hash
)
1140 NTSTATUS result
= NT_STATUS_OK
;
1141 struct dcerpc_binding_handle
*h
= NULL
;
1142 struct tsocket_address
*local
;
1143 struct policy_handle user_handle
;
1145 union samr_UserInfo
*info
;
1146 struct samr_UserInfo18 info18
;
1149 DATA_BLOB session_key
;
1151 ZERO_STRUCT(user_handle
);
1153 status
= session_extract_session_key(session_info
,
1156 if (!NT_STATUS_IS_OK(status
)) {
1160 rc
= tsocket_address_inet_from_strings(mem_ctx
,
1166 status
= NT_STATUS_NO_MEMORY
;
1170 status
= rpcint_binding_handle(mem_ctx
,
1176 if (!NT_STATUS_IS_OK(status
)) {
1181 status
= samr_find_machine_account(mem_ctx
,
1184 SEC_FLAG_MAXIMUM_ALLOWED
,
1189 if (!NT_STATUS_IS_OK(status
)) {
1193 status
= dcerpc_samr_QueryUserInfo2(h
,
1196 UserControlInformation
,
1199 if (!NT_STATUS_IS_OK(status
)) {
1202 if (!NT_STATUS_IS_OK(result
)) {
1207 acct_ctrl
= info
->info16
.acct_flags
;
1209 if (!(acct_ctrl
& ACB_WSTRUST
||
1210 acct_ctrl
& ACB_SVRTRUST
||
1211 acct_ctrl
& ACB_DOMTRUST
)) {
1212 status
= NT_STATUS_NO_SUCH_USER
;
1216 if (acct_ctrl
& ACB_DISABLED
) {
1217 status
= NT_STATUS_ACCOUNT_DISABLED
;
1221 ZERO_STRUCT(info18
);
1223 in
= data_blob_const(nt_hash
->hash
, 16);
1224 out
= data_blob_talloc_zero(mem_ctx
, 16);
1225 sess_crypt_blob(&out
, &in
, &session_key
, true);
1226 memcpy(info18
.nt_pwd
.hash
, out
.data
, out
.length
);
1228 info18
.nt_pwd_active
= true;
1230 info
->info18
= info18
;
1233 status
= dcerpc_samr_SetUserInfo2(h
,
1236 UserInternal1Information
,
1240 if (!NT_STATUS_IS_OK(status
)) {
1243 if (!NT_STATUS_IS_OK(result
)) {
1249 if (h
&& is_valid_policy_hnd(&user_handle
)) {
1250 dcerpc_samr_Close(h
, mem_ctx
, &user_handle
, &result
);
1256 /*************************************************************************
1257 _netr_ServerPasswordSet
1258 *************************************************************************/
1260 NTSTATUS
_netr_ServerPasswordSet(struct pipes_struct
*p
,
1261 struct netr_ServerPasswordSet
*r
)
1263 NTSTATUS status
= NT_STATUS_OK
;
1265 struct netlogon_creds_CredentialState
*creds
= NULL
;
1267 DEBUG(5,("_netr_ServerPasswordSet: %d\n", __LINE__
));
1270 status
= netr_creds_server_step_check(p
, p
->mem_ctx
,
1271 r
->in
.computer_name
,
1273 r
->out
.return_authenticator
,
1277 if (!NT_STATUS_IS_OK(status
)) {
1278 const char *computer_name
= "<unknown>";
1280 if (creds
!= NULL
&& creds
->computer_name
!= NULL
) {
1281 computer_name
= creds
->computer_name
;
1283 DEBUG(2,("_netr_ServerPasswordSet: netlogon_creds_server_step failed. Rejecting auth "
1284 "request from client %s machine account %s\n",
1285 r
->in
.computer_name
, computer_name
));
1290 DEBUG(3,("_netr_ServerPasswordSet: Server Password Set by remote machine:[%s] on account [%s]\n",
1291 r
->in
.computer_name
, creds
->computer_name
));
1293 netlogon_creds_des_decrypt(creds
, r
->in
.new_password
);
1295 DEBUG(100,("_netr_ServerPasswordSet: new given value was :\n"));
1296 for(i
= 0; i
< sizeof(r
->in
.new_password
->hash
); i
++)
1297 DEBUG(100,("%02X ", r
->in
.new_password
->hash
[i
]));
1300 status
= netr_set_machine_account_password(p
->mem_ctx
,
1303 creds
->account_name
,
1304 r
->in
.new_password
);
1308 /****************************************************************
1309 _netr_ServerPasswordSet2
1310 ****************************************************************/
1312 NTSTATUS
_netr_ServerPasswordSet2(struct pipes_struct
*p
,
1313 struct netr_ServerPasswordSet2
*r
)
1316 struct netlogon_creds_CredentialState
*creds
= NULL
;
1317 DATA_BLOB plaintext
;
1318 struct samr_CryptPassword password_buf
;
1319 struct samr_Password nt_hash
;
1322 status
= netr_creds_server_step_check(p
, p
->mem_ctx
,
1323 r
->in
.computer_name
,
1325 r
->out
.return_authenticator
,
1329 if (!NT_STATUS_IS_OK(status
)) {
1330 const char *computer_name
= "<unknown>";
1332 if (creds
&& creds
->computer_name
) {
1333 computer_name
= creds
->computer_name
;
1335 DEBUG(2,("_netr_ServerPasswordSet2: netlogon_creds_server_step "
1336 "failed. Rejecting auth request from client %s machine account %s\n",
1337 r
->in
.computer_name
, computer_name
));
1342 memcpy(password_buf
.data
, r
->in
.new_password
->data
, 512);
1343 SIVAL(password_buf
.data
, 512, r
->in
.new_password
->length
);
1345 if (creds
->negotiate_flags
& NETLOGON_NEG_SUPPORTS_AES
) {
1346 netlogon_creds_aes_decrypt(creds
, password_buf
.data
, 516);
1348 netlogon_creds_arcfour_crypt(creds
, password_buf
.data
, 516);
1351 if (!extract_pw_from_buffer(p
->mem_ctx
, password_buf
.data
, &plaintext
)) {
1353 return NT_STATUS_WRONG_PASSWORD
;
1356 mdfour(nt_hash
.hash
, plaintext
.data
, plaintext
.length
);
1358 status
= netr_set_machine_account_password(p
->mem_ctx
,
1361 creds
->account_name
,
1367 /*************************************************************************
1368 _netr_LogonSamLogoff
1369 *************************************************************************/
1371 NTSTATUS
_netr_LogonSamLogoff(struct pipes_struct
*p
,
1372 struct netr_LogonSamLogoff
*r
)
1375 struct netlogon_creds_CredentialState
*creds
;
1378 status
= netr_creds_server_step_check(p
, p
->mem_ctx
,
1379 r
->in
.computer_name
,
1381 r
->out
.return_authenticator
,
1388 static NTSTATUS
_netr_LogonSamLogon_check(const struct netr_LogonSamLogonEx
*r
)
1390 switch (r
->in
.logon_level
) {
1391 case NetlogonInteractiveInformation
:
1392 case NetlogonServiceInformation
:
1393 case NetlogonInteractiveTransitiveInformation
:
1394 case NetlogonServiceTransitiveInformation
:
1395 if (r
->in
.logon
->password
== NULL
) {
1396 return NT_STATUS_INVALID_PARAMETER
;
1399 switch (r
->in
.validation_level
) {
1400 case NetlogonValidationSamInfo
: /* 2 */
1401 case NetlogonValidationSamInfo2
: /* 3 */
1403 case NetlogonValidationSamInfo4
: /* 6 */
1404 if ((pdb_capabilities() & PDB_CAP_ADS
) == 0) {
1405 DEBUG(10,("Not adding validation info level 6 "
1406 "without ADS passdb backend\n"));
1407 return NT_STATUS_INVALID_INFO_CLASS
;
1411 return NT_STATUS_INVALID_INFO_CLASS
;
1415 case NetlogonNetworkInformation
:
1416 case NetlogonNetworkTransitiveInformation
:
1417 if (r
->in
.logon
->network
== NULL
) {
1418 return NT_STATUS_INVALID_PARAMETER
;
1421 switch (r
->in
.validation_level
) {
1422 case NetlogonValidationSamInfo
: /* 2 */
1423 case NetlogonValidationSamInfo2
: /* 3 */
1425 case NetlogonValidationSamInfo4
: /* 6 */
1426 if ((pdb_capabilities() & PDB_CAP_ADS
) == 0) {
1427 DEBUG(10,("Not adding validation info level 6 "
1428 "without ADS passdb backend\n"));
1429 return NT_STATUS_INVALID_INFO_CLASS
;
1433 return NT_STATUS_INVALID_INFO_CLASS
;
1438 case NetlogonGenericInformation
:
1439 if (r
->in
.logon
->generic
== NULL
) {
1440 return NT_STATUS_INVALID_PARAMETER
;
1443 /* we don't support this here */
1444 return NT_STATUS_INVALID_PARAMETER
;
1446 switch (r
->in
.validation_level
) {
1447 /* TODO: case NetlogonValidationGenericInfo: 4 */
1448 case NetlogonValidationGenericInfo2
: /* 5 */
1451 return NT_STATUS_INVALID_INFO_CLASS
;
1457 return NT_STATUS_INVALID_PARAMETER
;
1460 return NT_STATUS_OK
;
1463 /*************************************************************************
1464 _netr_LogonSamLogon_base
1465 *************************************************************************/
1467 static NTSTATUS
_netr_LogonSamLogon_base(struct pipes_struct
*p
,
1468 struct netr_LogonSamLogonEx
*r
,
1469 struct netlogon_creds_CredentialState
*creds
)
1471 NTSTATUS status
= NT_STATUS_OK
;
1472 union netr_LogonLevel
*logon
= r
->in
.logon
;
1473 const char *nt_username
, *nt_domain
, *nt_workstation
;
1474 struct auth_usersupplied_info
*user_info
= NULL
;
1475 struct auth_serversupplied_info
*server_info
= NULL
;
1476 struct auth_context
*auth_context
= NULL
;
1478 struct netr_SamBaseInfo
*base
;
1481 case NDR_NETR_LOGONSAMLOGON
:
1482 fn
= "_netr_LogonSamLogon";
1484 case NDR_NETR_LOGONSAMLOGONWITHFLAGS
:
1485 fn
= "_netr_LogonSamLogonWithFlags";
1487 case NDR_NETR_LOGONSAMLOGONEX
:
1488 fn
= "_netr_LogonSamLogonEx";
1491 return NT_STATUS_INTERNAL_ERROR
;
1494 *r
->out
.authoritative
= true; /* authoritative response */
1496 switch (r
->in
.validation_level
) {
1498 r
->out
.validation
->sam2
= talloc_zero(p
->mem_ctx
, struct netr_SamInfo2
);
1499 if (!r
->out
.validation
->sam2
) {
1500 return NT_STATUS_NO_MEMORY
;
1504 r
->out
.validation
->sam3
= talloc_zero(p
->mem_ctx
, struct netr_SamInfo3
);
1505 if (!r
->out
.validation
->sam3
) {
1506 return NT_STATUS_NO_MEMORY
;
1510 r
->out
.validation
->sam6
= talloc_zero(p
->mem_ctx
, struct netr_SamInfo6
);
1511 if (!r
->out
.validation
->sam6
) {
1512 return NT_STATUS_NO_MEMORY
;
1516 DEBUG(0,("%s: bad validation_level value %d.\n",
1517 fn
, (int)r
->in
.validation_level
));
1518 return NT_STATUS_INVALID_INFO_CLASS
;
1521 switch (r
->in
.logon_level
) {
1522 case NetlogonInteractiveInformation
:
1523 case NetlogonServiceInformation
:
1524 case NetlogonInteractiveTransitiveInformation
:
1525 case NetlogonServiceTransitiveInformation
:
1526 nt_username
= logon
->password
->identity_info
.account_name
.string
?
1527 logon
->password
->identity_info
.account_name
.string
: "";
1528 nt_domain
= logon
->password
->identity_info
.domain_name
.string
?
1529 logon
->password
->identity_info
.domain_name
.string
: "";
1530 nt_workstation
= logon
->password
->identity_info
.workstation
.string
?
1531 logon
->password
->identity_info
.workstation
.string
: "";
1533 DEBUG(3,("SAM Logon (Interactive). Domain:[%s]. ", lp_workgroup()));
1535 case NetlogonNetworkInformation
:
1536 case NetlogonNetworkTransitiveInformation
:
1537 nt_username
= logon
->network
->identity_info
.account_name
.string
?
1538 logon
->network
->identity_info
.account_name
.string
: "";
1539 nt_domain
= logon
->network
->identity_info
.domain_name
.string
?
1540 logon
->network
->identity_info
.domain_name
.string
: "";
1541 nt_workstation
= logon
->network
->identity_info
.workstation
.string
?
1542 logon
->network
->identity_info
.workstation
.string
: "";
1544 DEBUG(3,("SAM Logon (Network). Domain:[%s]. ", lp_workgroup()));
1547 DEBUG(2,("SAM Logon: unsupported switch value\n"));
1548 return NT_STATUS_INVALID_INFO_CLASS
;
1551 DEBUG(3,("User:[%s@%s] Requested Domain:[%s]\n", nt_username
, nt_workstation
, nt_domain
));
1552 fstrcpy(current_user_info
.smb_name
, nt_username
);
1553 sub_set_smb_name(nt_username
);
1555 DEBUG(5,("Attempting validation level %d for unmapped username %s.\n",
1556 r
->in
.validation_level
, nt_username
));
1558 status
= NT_STATUS_OK
;
1560 switch (r
->in
.logon_level
) {
1561 case NetlogonNetworkInformation
:
1562 case NetlogonNetworkTransitiveInformation
:
1564 const char *wksname
= nt_workstation
;
1566 status
= make_auth_context_fixed(talloc_tos(), &auth_context
,
1567 logon
->network
->challenge
);
1568 if (!NT_STATUS_IS_OK(status
)) {
1572 /* For a network logon, the workstation name comes in with two
1573 * backslashes in the front. Strip them if they are there. */
1575 if (*wksname
== '\\') wksname
++;
1576 if (*wksname
== '\\') wksname
++;
1578 /* Standard challenge/response authentication */
1579 if (!make_user_info_netlogon_network(&user_info
,
1580 nt_username
, nt_domain
,
1583 logon
->network
->identity_info
.parameter_control
,
1584 logon
->network
->lm
.data
,
1585 logon
->network
->lm
.length
,
1586 logon
->network
->nt
.data
,
1587 logon
->network
->nt
.length
)) {
1588 status
= NT_STATUS_NO_MEMORY
;
1592 case NetlogonInteractiveInformation
:
1593 case NetlogonServiceInformation
:
1594 case NetlogonInteractiveTransitiveInformation
:
1595 case NetlogonServiceTransitiveInformation
:
1597 /* 'Interactive' authentication, supplies the password in its
1598 MD4 form, encrypted with the session key. We will convert
1599 this to challenge/response for the auth subsystem to chew
1604 #ifdef DEBUG_PASSWORD
1605 DEBUG(100,("lm owf password:"));
1606 dump_data(100, logon
->password
->lmpassword
.hash
, 16);
1608 DEBUG(100,("nt owf password:"));
1609 dump_data(100, logon
->password
->ntpassword
.hash
, 16);
1611 if (creds
->negotiate_flags
& NETLOGON_NEG_SUPPORTS_AES
) {
1612 netlogon_creds_aes_decrypt(creds
,
1613 logon
->password
->lmpassword
.hash
,
1615 netlogon_creds_aes_decrypt(creds
,
1616 logon
->password
->ntpassword
.hash
,
1618 } else if (creds
->negotiate_flags
& NETLOGON_NEG_ARCFOUR
) {
1619 netlogon_creds_arcfour_crypt(creds
,
1620 logon
->password
->lmpassword
.hash
,
1622 netlogon_creds_arcfour_crypt(creds
,
1623 logon
->password
->ntpassword
.hash
,
1626 netlogon_creds_des_decrypt(creds
, &logon
->password
->lmpassword
);
1627 netlogon_creds_des_decrypt(creds
, &logon
->password
->ntpassword
);
1630 #ifdef DEBUG_PASSWORD
1631 DEBUG(100,("decrypt of lm owf password:"));
1632 dump_data(100, logon
->password
->lmpassword
.hash
, 16);
1634 DEBUG(100,("decrypt of nt owf password:"));
1635 dump_data(100, logon
->password
->ntpassword
.hash
, 16);
1637 status
= make_auth_context_subsystem(talloc_tos(),
1639 if (!NT_STATUS_IS_OK(status
)) {
1643 auth_get_ntlm_challenge(auth_context
, chal
);
1645 if (!make_user_info_netlogon_interactive(&user_info
,
1646 nt_username
, nt_domain
,
1649 logon
->password
->identity_info
.parameter_control
,
1651 logon
->password
->lmpassword
.hash
,
1652 logon
->password
->ntpassword
.hash
)) {
1653 status
= NT_STATUS_NO_MEMORY
;
1658 DEBUG(2,("SAM Logon: unsupported switch value\n"));
1659 return NT_STATUS_INVALID_INFO_CLASS
;
1662 if ( NT_STATUS_IS_OK(status
) ) {
1663 status
= auth_check_ntlm_password(auth_context
,
1664 user_info
, &server_info
);
1667 TALLOC_FREE(auth_context
);
1668 free_user_info(&user_info
);
1670 DEBUG(5,("%s: check_password returned status %s\n",
1671 fn
, nt_errstr(status
)));
1673 /* Check account and password */
1675 if (!NT_STATUS_IS_OK(status
)) {
1676 /* If we don't know what this domain is, we need to
1677 indicate that we are not authoritative. This
1678 allows the client to decide if it needs to try
1679 a local user. Fix by jpjanosi@us.ibm.com, #2976 */
1680 if ( NT_STATUS_EQUAL(status
, NT_STATUS_NO_SUCH_USER
)
1681 && !strequal(nt_domain
, get_global_sam_name())
1682 && !is_trusted_domain(nt_domain
) )
1683 *r
->out
.authoritative
= false; /* We are not authoritative */
1685 TALLOC_FREE(server_info
);
1689 if (server_info
->guest
) {
1690 /* We don't like guest domain logons... */
1691 DEBUG(5,("%s: Attempted domain logon as GUEST "
1693 TALLOC_FREE(server_info
);
1694 return NT_STATUS_LOGON_FAILURE
;
1697 /* This is the point at which, if the login was successful, that
1698 the SAM Local Security Authority should record that the user is
1699 logged in to the domain. */
1701 switch (r
->in
.validation_level
) {
1703 status
= serverinfo_to_SamInfo2(server_info
,
1704 r
->out
.validation
->sam2
);
1705 base
= &r
->out
.validation
->sam2
->base
;
1708 status
= serverinfo_to_SamInfo3(server_info
,
1709 r
->out
.validation
->sam3
);
1710 base
= &r
->out
.validation
->sam3
->base
;
1713 status
= serverinfo_to_SamInfo6(server_info
,
1714 r
->out
.validation
->sam6
);
1715 base
= &r
->out
.validation
->sam6
->base
;
1719 TALLOC_FREE(server_info
);
1721 if (!NT_STATUS_IS_OK(status
)) {
1725 if (r
->in
.validation_level
== 6) {
1726 /* no further crypto to be applied - gd */
1727 return NT_STATUS_OK
;
1730 if (creds
->negotiate_flags
& NETLOGON_NEG_SUPPORTS_AES
) {
1731 netlogon_creds_aes_encrypt(creds
, base
->key
.key
, 16);
1732 netlogon_creds_aes_encrypt(creds
, base
->LMSessKey
.key
, 8);
1733 } else if (creds
->negotiate_flags
& NETLOGON_NEG_ARCFOUR
) {
1734 netlogon_creds_arcfour_crypt(creds
, base
->key
.key
, 16);
1735 netlogon_creds_arcfour_crypt(creds
, base
->LMSessKey
.key
, 8);
1737 /* key is unencrypted when neither AES nor RC4 bits are set */
1738 netlogon_creds_des_encrypt_LMKey(creds
, &base
->LMSessKey
);
1741 return NT_STATUS_OK
;
1744 /****************************************************************
1745 _netr_LogonSamLogonWithFlags
1746 ****************************************************************/
1748 NTSTATUS
_netr_LogonSamLogonWithFlags(struct pipes_struct
*p
,
1749 struct netr_LogonSamLogonWithFlags
*r
)
1752 struct netlogon_creds_CredentialState
*creds
;
1753 struct netr_LogonSamLogonEx r2
;
1754 struct netr_Authenticator return_authenticator
;
1756 *r
->out
.authoritative
= true;
1758 r2
.in
.server_name
= r
->in
.server_name
;
1759 r2
.in
.computer_name
= r
->in
.computer_name
;
1760 r2
.in
.logon_level
= r
->in
.logon_level
;
1761 r2
.in
.logon
= r
->in
.logon
;
1762 r2
.in
.validation_level
= r
->in
.validation_level
;
1763 r2
.in
.flags
= r
->in
.flags
;
1764 r2
.out
.validation
= r
->out
.validation
;
1765 r2
.out
.authoritative
= r
->out
.authoritative
;
1766 r2
.out
.flags
= r
->out
.flags
;
1768 status
= _netr_LogonSamLogon_check(&r2
);
1769 if (!NT_STATUS_IS_OK(status
)) {
1774 status
= netr_creds_server_step_check(p
, p
->mem_ctx
,
1775 r
->in
.computer_name
,
1777 &return_authenticator
,
1780 if (!NT_STATUS_IS_OK(status
)) {
1784 status
= _netr_LogonSamLogon_base(p
, &r2
, creds
);
1786 *r
->out
.return_authenticator
= return_authenticator
;
1791 /*************************************************************************
1793 *************************************************************************/
1795 NTSTATUS
_netr_LogonSamLogon(struct pipes_struct
*p
,
1796 struct netr_LogonSamLogon
*r
)
1799 struct netr_LogonSamLogonWithFlags r2
;
1802 r2
.in
.server_name
= r
->in
.server_name
;
1803 r2
.in
.computer_name
= r
->in
.computer_name
;
1804 r2
.in
.credential
= r
->in
.credential
;
1805 r2
.in
.logon_level
= r
->in
.logon_level
;
1806 r2
.in
.logon
= r
->in
.logon
;
1807 r2
.in
.validation_level
= r
->in
.validation_level
;
1808 r2
.in
.return_authenticator
= r
->in
.return_authenticator
;
1809 r2
.in
.flags
= &flags
;
1810 r2
.out
.validation
= r
->out
.validation
;
1811 r2
.out
.authoritative
= r
->out
.authoritative
;
1812 r2
.out
.flags
= &flags
;
1813 r2
.out
.return_authenticator
= r
->out
.return_authenticator
;
1815 status
= _netr_LogonSamLogonWithFlags(p
, &r2
);
1820 /*************************************************************************
1821 _netr_LogonSamLogonEx
1822 - no credential chaining. Map into net sam logon.
1823 *************************************************************************/
1825 NTSTATUS
_netr_LogonSamLogonEx(struct pipes_struct
*p
,
1826 struct netr_LogonSamLogonEx
*r
)
1829 struct netlogon_creds_CredentialState
*creds
= NULL
;
1830 struct loadparm_context
*lp_ctx
;
1832 *r
->out
.authoritative
= true;
1834 status
= _netr_LogonSamLogon_check(r
);
1835 if (!NT_STATUS_IS_OK(status
)) {
1839 /* Only allow this if the pipe is protected. */
1840 if (p
->auth
.auth_type
!= DCERPC_AUTH_TYPE_SCHANNEL
) {
1841 DEBUG(0,("_netr_LogonSamLogonEx: client %s not using schannel for netlogon\n",
1842 get_remote_machine_name() ));
1843 return NT_STATUS_INVALID_PARAMETER
;
1846 lp_ctx
= loadparm_init_s3(p
->mem_ctx
, loadparm_s3_helpers());
1847 if (lp_ctx
== NULL
) {
1848 DEBUG(0, ("loadparm_init_s3 failed\n"));
1849 return NT_STATUS_INTERNAL_ERROR
;
1853 status
= schannel_get_creds_state(p
->mem_ctx
, lp_ctx
,
1854 r
->in
.computer_name
, &creds
);
1856 talloc_unlink(p
->mem_ctx
, lp_ctx
);
1858 if (!NT_STATUS_IS_OK(status
)) {
1862 status
= _netr_LogonSamLogon_base(p
, r
, creds
);
1868 /*************************************************************************
1870 *************************************************************************/
1871 #if 0 /* JERRY -- not correct */
1872 NTSTATUS
_ds_enum_dom_trusts(struct pipes_struct
*p
, DS_Q_ENUM_DOM_TRUSTS
*q_u
,
1873 DS_R_ENUM_DOM_TRUSTS
*r_u
)
1875 NTSTATUS status
= NT_STATUS_OK
;
1877 /* TODO: According to MSDN, the can only be executed against a
1878 DC or domain member running Windows 2000 or later. Need
1879 to test against a standalone 2k server and see what it
1880 does. A windows 2000 DC includes its own domain in the
1888 /****************************************************************
1889 ****************************************************************/
1891 WERROR
_netr_LogonUasLogon(struct pipes_struct
*p
,
1892 struct netr_LogonUasLogon
*r
)
1894 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
1895 return WERR_NOT_SUPPORTED
;
1898 /****************************************************************
1899 ****************************************************************/
1901 WERROR
_netr_LogonUasLogoff(struct pipes_struct
*p
,
1902 struct netr_LogonUasLogoff
*r
)
1904 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
1905 return WERR_NOT_SUPPORTED
;
1908 /****************************************************************
1909 ****************************************************************/
1911 NTSTATUS
_netr_DatabaseDeltas(struct pipes_struct
*p
,
1912 struct netr_DatabaseDeltas
*r
)
1914 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
1915 return NT_STATUS_NOT_IMPLEMENTED
;
1918 /****************************************************************
1919 ****************************************************************/
1921 NTSTATUS
_netr_DatabaseSync(struct pipes_struct
*p
,
1922 struct netr_DatabaseSync
*r
)
1924 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
1925 return NT_STATUS_NOT_IMPLEMENTED
;
1928 /****************************************************************
1929 ****************************************************************/
1931 NTSTATUS
_netr_AccountDeltas(struct pipes_struct
*p
,
1932 struct netr_AccountDeltas
*r
)
1934 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
1935 return NT_STATUS_NOT_IMPLEMENTED
;
1938 /****************************************************************
1939 ****************************************************************/
1941 NTSTATUS
_netr_AccountSync(struct pipes_struct
*p
,
1942 struct netr_AccountSync
*r
)
1944 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
1945 return NT_STATUS_NOT_IMPLEMENTED
;
1948 /****************************************************************
1949 ****************************************************************/
1951 static bool wb_getdcname(TALLOC_CTX
*mem_ctx
,
1953 const char **dcname
,
1958 struct wbcDomainControllerInfo
*dc_info
= NULL
;
1960 result
= wbcLookupDomainController(domain
,
1964 case WBC_ERR_SUCCESS
:
1966 case WBC_ERR_WINBIND_NOT_AVAILABLE
:
1968 case WBC_ERR_DOMAIN_NOT_FOUND
:
1969 *werr
= WERR_NO_SUCH_DOMAIN
;
1972 *werr
= WERR_DOMAIN_CONTROLLER_NOT_FOUND
;
1976 *dcname
= talloc_strdup(mem_ctx
, dc_info
->dc_name
);
1977 wbcFreeMemory(dc_info
);
1988 /****************************************************************
1990 ****************************************************************/
1992 WERROR
_netr_GetDcName(struct pipes_struct
*p
,
1993 struct netr_GetDcName
*r
)
1998 struct netr_DsRGetDCNameInfo
*info
;
2001 ret
= wb_getdcname(p
->mem_ctx
,
2004 WBC_LOOKUP_DC_IS_FLAT_NAME
|
2005 WBC_LOOKUP_DC_RETURN_FLAT_NAME
|
2006 WBC_LOOKUP_DC_PDC_REQUIRED
,
2012 flags
= DS_PDC_REQUIRED
| DS_IS_FLAT_NAME
| DS_RETURN_FLAT_NAME
;
2014 status
= dsgetdcname(p
->mem_ctx
,
2021 if (!NT_STATUS_IS_OK(status
)) {
2022 return ntstatus_to_werror(status
);
2025 *r
->out
.dcname
= talloc_strdup(p
->mem_ctx
, info
->dc_unc
);
2027 if (!*r
->out
.dcname
) {
2034 /****************************************************************
2036 ****************************************************************/
2038 WERROR
_netr_GetAnyDCName(struct pipes_struct
*p
,
2039 struct netr_GetAnyDCName
*r
)
2044 struct netr_DsRGetDCNameInfo
*info
;
2047 ret
= wb_getdcname(p
->mem_ctx
,
2050 WBC_LOOKUP_DC_IS_FLAT_NAME
|
2051 WBC_LOOKUP_DC_RETURN_FLAT_NAME
,
2057 flags
= DS_IS_FLAT_NAME
| DS_RETURN_FLAT_NAME
;
2059 status
= dsgetdcname(p
->mem_ctx
,
2066 if (!NT_STATUS_IS_OK(status
)) {
2067 return ntstatus_to_werror(status
);
2070 *r
->out
.dcname
= talloc_strdup(p
->mem_ctx
, info
->dc_unc
);
2072 if (!*r
->out
.dcname
) {
2079 /****************************************************************
2080 ****************************************************************/
2082 NTSTATUS
_netr_DatabaseSync2(struct pipes_struct
*p
,
2083 struct netr_DatabaseSync2
*r
)
2085 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2086 return NT_STATUS_NOT_IMPLEMENTED
;
2089 /****************************************************************
2090 ****************************************************************/
2092 NTSTATUS
_netr_DatabaseRedo(struct pipes_struct
*p
,
2093 struct netr_DatabaseRedo
*r
)
2095 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2096 return NT_STATUS_NOT_IMPLEMENTED
;
2099 /****************************************************************
2100 ****************************************************************/
2102 WERROR
_netr_DsRGetDCName(struct pipes_struct
*p
,
2103 struct netr_DsRGetDCName
*r
)
2105 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2106 return WERR_NOT_SUPPORTED
;
2109 /****************************************************************
2110 ****************************************************************/
2112 NTSTATUS
_netr_LogonGetCapabilities(struct pipes_struct
*p
,
2113 struct netr_LogonGetCapabilities
*r
)
2115 struct netlogon_creds_CredentialState
*creds
;
2119 status
= netr_creds_server_step_check(p
, p
->mem_ctx
,
2120 r
->in
.computer_name
,
2122 r
->out
.return_authenticator
,
2125 if (!NT_STATUS_IS_OK(status
)) {
2129 if (r
->in
.query_level
!= 1) {
2130 return NT_STATUS_NOT_SUPPORTED
;
2133 r
->out
.capabilities
->server_capabilities
= creds
->negotiate_flags
;
2135 return NT_STATUS_OK
;
2138 /****************************************************************
2139 ****************************************************************/
2141 WERROR
_netr_NETRLOGONSETSERVICEBITS(struct pipes_struct
*p
,
2142 struct netr_NETRLOGONSETSERVICEBITS
*r
)
2144 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2145 return WERR_NOT_SUPPORTED
;
2148 /****************************************************************
2149 ****************************************************************/
2151 WERROR
_netr_LogonGetTrustRid(struct pipes_struct
*p
,
2152 struct netr_LogonGetTrustRid
*r
)
2154 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2155 return WERR_NOT_SUPPORTED
;
2158 /****************************************************************
2159 ****************************************************************/
2161 WERROR
_netr_NETRLOGONCOMPUTESERVERDIGEST(struct pipes_struct
*p
,
2162 struct netr_NETRLOGONCOMPUTESERVERDIGEST
*r
)
2164 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2165 return WERR_NOT_SUPPORTED
;
2168 /****************************************************************
2169 ****************************************************************/
2171 WERROR
_netr_NETRLOGONCOMPUTECLIENTDIGEST(struct pipes_struct
*p
,
2172 struct netr_NETRLOGONCOMPUTECLIENTDIGEST
*r
)
2174 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2175 return WERR_NOT_SUPPORTED
;
2178 /****************************************************************
2179 ****************************************************************/
2181 WERROR
_netr_DsRGetDCNameEx(struct pipes_struct
*p
,
2182 struct netr_DsRGetDCNameEx
*r
)
2184 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2185 return WERR_NOT_SUPPORTED
;
2188 /****************************************************************
2189 ****************************************************************/
2191 WERROR
_netr_DsRGetSiteName(struct pipes_struct
*p
,
2192 struct netr_DsRGetSiteName
*r
)
2194 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2195 return WERR_NOT_SUPPORTED
;
2198 /****************************************************************
2199 ****************************************************************/
2201 NTSTATUS
_netr_LogonGetDomainInfo(struct pipes_struct
*p
,
2202 struct netr_LogonGetDomainInfo
*r
)
2204 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2205 return NT_STATUS_NOT_IMPLEMENTED
;
2208 /****************************************************************
2209 ****************************************************************/
2211 WERROR
_netr_ServerPasswordGet(struct pipes_struct
*p
,
2212 struct netr_ServerPasswordGet
*r
)
2214 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2215 return WERR_NOT_SUPPORTED
;
2218 /****************************************************************
2219 ****************************************************************/
2221 WERROR
_netr_NETRLOGONSENDTOSAM(struct pipes_struct
*p
,
2222 struct netr_NETRLOGONSENDTOSAM
*r
)
2224 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2225 return WERR_NOT_SUPPORTED
;
2228 /****************************************************************
2229 ****************************************************************/
2231 WERROR
_netr_DsRAddressToSitenamesW(struct pipes_struct
*p
,
2232 struct netr_DsRAddressToSitenamesW
*r
)
2234 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2235 return WERR_NOT_SUPPORTED
;
2238 /****************************************************************
2239 ****************************************************************/
2241 WERROR
_netr_DsRGetDCNameEx2(struct pipes_struct
*p
,
2242 struct netr_DsRGetDCNameEx2
*r
)
2244 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2245 return WERR_NOT_SUPPORTED
;
2248 /****************************************************************
2249 ****************************************************************/
2251 WERROR
_netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN(struct pipes_struct
*p
,
2252 struct netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN
*r
)
2254 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2255 return WERR_NOT_SUPPORTED
;
2258 /****************************************************************
2259 ****************************************************************/
2261 WERROR
_netr_NetrEnumerateTrustedDomainsEx(struct pipes_struct
*p
,
2262 struct netr_NetrEnumerateTrustedDomainsEx
*r
)
2264 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2265 return WERR_NOT_SUPPORTED
;
2268 /****************************************************************
2269 ****************************************************************/
2271 WERROR
_netr_DsRAddressToSitenamesExW(struct pipes_struct
*p
,
2272 struct netr_DsRAddressToSitenamesExW
*r
)
2274 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2275 return WERR_NOT_SUPPORTED
;
2278 /****************************************************************
2279 ****************************************************************/
2281 WERROR
_netr_DsrGetDcSiteCoverageW(struct pipes_struct
*p
,
2282 struct netr_DsrGetDcSiteCoverageW
*r
)
2284 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2285 return WERR_NOT_SUPPORTED
;
2288 /****************************************************************
2289 ****************************************************************/
2291 WERROR
_netr_DsrEnumerateDomainTrusts(struct pipes_struct
*p
,
2292 struct netr_DsrEnumerateDomainTrusts
*r
)
2294 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2295 return WERR_NOT_SUPPORTED
;
2298 /****************************************************************
2299 ****************************************************************/
2301 WERROR
_netr_DsrDeregisterDNSHostRecords(struct pipes_struct
*p
,
2302 struct netr_DsrDeregisterDNSHostRecords
*r
)
2304 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2305 return WERR_NOT_SUPPORTED
;
2308 /****************************************************************
2309 ****************************************************************/
2311 NTSTATUS
_netr_ServerTrustPasswordsGet(struct pipes_struct
*p
,
2312 struct netr_ServerTrustPasswordsGet
*r
)
2314 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2315 return NT_STATUS_NOT_IMPLEMENTED
;
2318 /****************************************************************
2319 ****************************************************************/
2321 static NTSTATUS
fill_forest_trust_array(TALLOC_CTX
*mem_ctx
,
2322 struct lsa_ForestTrustInformation
*info
)
2324 struct lsa_ForestTrustRecord
*e
;
2325 struct pdb_domain_info
*dom_info
;
2326 struct lsa_ForestTrustDomainInfo
*domain_info
;
2327 char **upn_suffixes
= NULL
;
2328 uint32_t num_suffixes
= 0;
2332 dom_info
= pdb_get_domain_info(mem_ctx
);
2333 if (dom_info
== NULL
) {
2334 return NT_STATUS_NO_MEMORY
;
2340 status
= pdb_enum_upn_suffixes(info
, &num_suffixes
, &upn_suffixes
);
2342 if (NT_STATUS_IS_OK(status
) && (num_suffixes
> 0)) {
2343 info
->count
+= num_suffixes
;
2346 info
->entries
= talloc_array(info
, struct lsa_ForestTrustRecord
*, info
->count
);
2347 if (info
->entries
== NULL
) {
2348 return NT_STATUS_NO_MEMORY
;
2351 e
= talloc(info
, struct lsa_ForestTrustRecord
);
2353 return NT_STATUS_NO_MEMORY
;
2357 e
->type
= LSA_FOREST_TRUST_TOP_LEVEL_NAME
;
2358 e
->time
= 0; /* so far always 0 in trces. */
2359 e
->forest_trust_data
.top_level_name
.string
= talloc_steal(info
,
2360 dom_info
->dns_forest
);
2362 info
->entries
[0] = e
;
2364 if (num_suffixes
> 0) {
2365 for (i
= 0; i
< num_suffixes
; i
++) {
2366 e
= talloc(info
, struct lsa_ForestTrustRecord
);
2368 return NT_STATUS_NO_MEMORY
;
2372 e
->type
= LSA_FOREST_TRUST_TOP_LEVEL_NAME
;
2373 e
->time
= 0; /* so far always 0 in traces. */
2374 e
->forest_trust_data
.top_level_name
.string
= upn_suffixes
[i
];
2375 info
->entries
[1 + i
] = e
;
2379 e
= talloc(info
, struct lsa_ForestTrustRecord
);
2381 return NT_STATUS_NO_MEMORY
;
2384 /* TODO: check if disabled and set flags accordingly */
2386 e
->type
= LSA_FOREST_TRUST_DOMAIN_INFO
;
2387 e
->time
= 0; /* so far always 0 in traces. */
2389 domain_info
= &e
->forest_trust_data
.domain_info
;
2390 domain_info
->domain_sid
= dom_sid_dup(info
, &dom_info
->sid
);
2392 domain_info
->dns_domain_name
.string
= talloc_steal(info
,
2393 dom_info
->dns_domain
);
2394 domain_info
->netbios_domain_name
.string
= talloc_steal(info
,
2397 info
->entries
[info
->count
- 1] = e
;
2399 return NT_STATUS_OK
;
2402 /****************************************************************
2403 ****************************************************************/
2405 WERROR
_netr_DsRGetForestTrustInformation(struct pipes_struct
*p
,
2406 struct netr_DsRGetForestTrustInformation
*r
)
2409 struct lsa_ForestTrustInformation
*info
, **info_ptr
;
2411 if (!(p
->pipe_bound
&& (p
->auth
.auth_type
!= DCERPC_AUTH_TYPE_NONE
)
2412 && (p
->auth
.auth_level
!= DCERPC_AUTH_LEVEL_NONE
))) {
2413 p
->fault_state
= DCERPC_FAULT_ACCESS_DENIED
;
2414 return WERR_ACCESS_DENIED
;
2417 if (r
->in
.flags
& (~DS_GFTI_UPDATE_TDO
)) {
2418 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2419 return WERR_INVALID_FLAGS
;
2422 if ((r
->in
.flags
& DS_GFTI_UPDATE_TDO
) && (lp_server_role() != ROLE_DOMAIN_PDC
)) {
2423 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2424 return WERR_NERR_NOTPRIMARY
;
2427 if ((r
->in
.trusted_domain_name
== NULL
) && (r
->in
.flags
& DS_GFTI_UPDATE_TDO
)) {
2428 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2429 return WERR_INVALID_PARAMETER
;
2432 /* retrieve forest trust information and stop further processing */
2433 if (r
->in
.trusted_domain_name
== NULL
) {
2434 info_ptr
= talloc(p
->mem_ctx
, struct lsa_ForestTrustInformation
*);
2435 if (info_ptr
== NULL
) {
2436 p
->fault_state
= DCERPC_FAULT_CANT_PERFORM
;
2439 info
= talloc_zero(info_ptr
, struct lsa_ForestTrustInformation
);
2441 p
->fault_state
= DCERPC_FAULT_CANT_PERFORM
;
2445 /* Fill forest trust information and expand UPN suffixes list */
2446 status
= fill_forest_trust_array(p
->mem_ctx
, info
);
2447 if (!NT_STATUS_IS_OK(status
)) {
2448 p
->fault_state
= DCERPC_FAULT_CANT_PERFORM
;
2453 r
->out
.forest_trust_info
= info_ptr
;
2459 /* TODO: implement remaining parts of DsrGetForestTrustInformation (opnum 43)
2460 * when trusted_domain_name is not NULL */
2462 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2463 return WERR_NOT_SUPPORTED
;
2466 /****************************************************************
2467 _netr_GetForestTrustInformation
2468 ****************************************************************/
2470 NTSTATUS
_netr_GetForestTrustInformation(struct pipes_struct
*p
,
2471 struct netr_GetForestTrustInformation
*r
)
2474 struct netlogon_creds_CredentialState
*creds
;
2475 struct lsa_ForestTrustInformation
*info
, **info_ptr
;
2476 struct loadparm_context
*lp_ctx
;
2478 /* TODO: check server name */
2480 lp_ctx
= loadparm_init_s3(p
->mem_ctx
, loadparm_s3_helpers());
2481 if (lp_ctx
== NULL
) {
2482 DEBUG(0, ("loadparm_init_s3 failed\n"));
2483 return NT_STATUS_INTERNAL_ERROR
;
2486 status
= schannel_check_creds_state(p
->mem_ctx
, lp_ctx
,
2487 r
->in
.computer_name
,
2489 r
->out
.return_authenticator
,
2491 talloc_unlink(p
->mem_ctx
, lp_ctx
);
2492 if (!NT_STATUS_IS_OK(status
)) {
2496 if ((creds
->secure_channel_type
!= SEC_CHAN_DNS_DOMAIN
) &&
2497 (creds
->secure_channel_type
!= SEC_CHAN_DOMAIN
)) {
2498 return NT_STATUS_NOT_IMPLEMENTED
;
2501 info_ptr
= talloc(p
->mem_ctx
, struct lsa_ForestTrustInformation
*);
2503 return NT_STATUS_NO_MEMORY
;
2505 info
= talloc_zero(info_ptr
, struct lsa_ForestTrustInformation
);
2507 return NT_STATUS_NO_MEMORY
;
2510 /* Fill forest trust information, do expand UPN suffixes list */
2511 status
= fill_forest_trust_array(p
->mem_ctx
, info
);
2512 if (!NT_STATUS_IS_OK(status
)) {
2517 r
->out
.forest_trust_info
= info_ptr
;
2519 return NT_STATUS_OK
;
2522 /****************************************************************
2523 ****************************************************************/
2525 static NTSTATUS
get_password_from_trustAuth(TALLOC_CTX
*mem_ctx
,
2526 const DATA_BLOB
*trustAuth_blob
,
2527 struct netlogon_creds_CredentialState
*creds
,
2528 struct samr_Password
*current_pw_enc
,
2529 struct samr_Password
*previous_pw_enc
)
2531 enum ndr_err_code ndr_err
;
2532 struct trustAuthInOutBlob trustAuth
;
2534 ndr_err
= ndr_pull_struct_blob_all(trustAuth_blob
, mem_ctx
, &trustAuth
,
2535 (ndr_pull_flags_fn_t
)ndr_pull_trustAuthInOutBlob
);
2536 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2537 return NT_STATUS_UNSUCCESSFUL
;
2541 if (trustAuth
.count
!= 0 && trustAuth
.current
.count
!= 0 &&
2542 trustAuth
.current
.array
[0].AuthType
== TRUST_AUTH_TYPE_CLEAR
) {
2543 mdfour(previous_pw_enc
->hash
,
2544 trustAuth
.current
.array
[0].AuthInfo
.clear
.password
,
2545 trustAuth
.current
.array
[0].AuthInfo
.clear
.size
);
2547 return NT_STATUS_UNSUCCESSFUL
;
2550 netlogon_creds_des_encrypt(creds
, current_pw_enc
);
2552 if (trustAuth
.previous
.count
!= 0 &&
2553 trustAuth
.previous
.array
[0].AuthType
== TRUST_AUTH_TYPE_CLEAR
) {
2554 mdfour(previous_pw_enc
->hash
,
2555 trustAuth
.previous
.array
[0].AuthInfo
.clear
.password
,
2556 trustAuth
.previous
.array
[0].AuthInfo
.clear
.size
);
2558 mdfour(previous_pw_enc
->hash
, NULL
, 0);
2561 netlogon_creds_des_encrypt(creds
, previous_pw_enc
);
2563 return NT_STATUS_OK
;
2566 /****************************************************************
2567 _netr_ServerGetTrustInfo
2568 ****************************************************************/
2570 NTSTATUS
_netr_ServerGetTrustInfo(struct pipes_struct
*p
,
2571 struct netr_ServerGetTrustInfo
*r
)
2574 struct netlogon_creds_CredentialState
*creds
;
2576 size_t account_name_last
;
2578 struct netr_TrustInfo
*trust_info
;
2579 struct pdb_trusted_domain
*td
;
2580 DATA_BLOB trustAuth_blob
;
2581 struct samr_Password
*new_owf_enc
;
2582 struct samr_Password
*old_owf_enc
;
2583 struct loadparm_context
*lp_ctx
;
2585 lp_ctx
= loadparm_init_s3(p
->mem_ctx
, loadparm_s3_helpers());
2586 if (lp_ctx
== NULL
) {
2587 DEBUG(0, ("loadparm_init_s3 failed\n"));
2588 return NT_STATUS_INTERNAL_ERROR
;
2591 /* TODO: check server name */
2593 status
= schannel_check_creds_state(p
->mem_ctx
, lp_ctx
,
2594 r
->in
.computer_name
,
2596 r
->out
.return_authenticator
,
2598 talloc_unlink(p
->mem_ctx
, lp_ctx
);
2599 if (!NT_STATUS_IS_OK(status
)) {
2603 account_name
= talloc_strdup(p
->mem_ctx
, r
->in
.account_name
);
2604 if (account_name
== NULL
) {
2605 return NT_STATUS_NO_MEMORY
;
2608 account_name_last
= strlen(account_name
);
2609 if (account_name_last
== 0) {
2610 return NT_STATUS_INVALID_PARAMETER
;
2612 account_name_last
--;
2613 if (account_name
[account_name_last
] == '.') {
2614 account_name
[account_name_last
] = '\0';
2617 if ((creds
->secure_channel_type
!= SEC_CHAN_DNS_DOMAIN
) &&
2618 (creds
->secure_channel_type
!= SEC_CHAN_DOMAIN
)) {
2626 account_name_last
= strlen(account_name
);
2627 if (account_name_last
== 0) {
2628 return NT_STATUS_INVALID_PARAMETER
;
2630 account_name_last
--;
2631 if (account_name
[account_name_last
] == '$') {
2632 account_name
[account_name_last
] = '\0';
2635 status
= pdb_get_trusted_domain(p
->mem_ctx
, account_name
, &td
);
2636 if (!NT_STATUS_IS_OK(status
)) {
2640 if (r
->out
.trust_info
!= NULL
) {
2641 trust_info
= talloc_zero(p
->mem_ctx
, struct netr_TrustInfo
);
2642 if (trust_info
== NULL
) {
2643 return NT_STATUS_NO_MEMORY
;
2645 trust_info
->count
= 1;
2647 trust_info
->data
= talloc_array(trust_info
, uint32_t, 1);
2648 if (trust_info
->data
== NULL
) {
2649 return NT_STATUS_NO_MEMORY
;
2651 trust_info
->data
[0] = td
->trust_attributes
;
2653 *r
->out
.trust_info
= trust_info
;
2656 new_owf_enc
= talloc_zero(p
->mem_ctx
, struct samr_Password
);
2657 old_owf_enc
= talloc_zero(p
->mem_ctx
, struct samr_Password
);
2658 if (new_owf_enc
== NULL
|| old_owf_enc
== NULL
) {
2659 return NT_STATUS_NO_MEMORY
;
2662 /* TODO: which trustAuth shall we use if we have in/out trust or do they have to
2664 if (td
->trust_direction
& NETR_TRUST_FLAG_INBOUND
) {
2665 trustAuth_blob
= td
->trust_auth_incoming
;
2666 } else if (td
->trust_direction
& NETR_TRUST_FLAG_OUTBOUND
) {
2667 trustAuth_blob
= td
->trust_auth_outgoing
;
2670 status
= get_password_from_trustAuth(p
->mem_ctx
, &trustAuth_blob
,
2672 new_owf_enc
, old_owf_enc
);
2674 if (!NT_STATUS_IS_OK(status
)) {
2678 r
->out
.new_owf_password
= new_owf_enc
;
2679 r
->out
.old_owf_password
= old_owf_enc
;
2681 /* TODO: look for machine password */
2682 r
->out
.new_owf_password
= NULL
;
2683 r
->out
.old_owf_password
= NULL
;
2685 return NT_STATUS_NOT_IMPLEMENTED
;
2688 return NT_STATUS_OK
;
2691 /****************************************************************
2692 ****************************************************************/
2694 NTSTATUS
_netr_Unused47(struct pipes_struct
*p
,
2695 struct netr_Unused47
*r
)
2697 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2698 return NT_STATUS_NOT_IMPLEMENTED
;
2701 /****************************************************************
2702 ****************************************************************/
2704 NTSTATUS
_netr_DsrUpdateReadOnlyServerDnsRecords(struct pipes_struct
*p
,
2705 struct netr_DsrUpdateReadOnlyServerDnsRecords
*r
)
2707 p
->fault_state
= DCERPC_FAULT_OP_RNG_ERROR
;
2708 return NT_STATUS_NOT_IMPLEMENTED
;