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 switch (r->in.function_code) {
79 case NETLOGON_CONTROL_QUERY:
80 case NETLOGON_CONTROL_REPLICATE:
81 case NETLOGON_CONTROL_SYNCHRONIZE:
82 case NETLOGON_CONTROL_PDC_REPLICATE:
83 case NETLOGON_CONTROL_BREAKPOINT:
84 case NETLOGON_CONTROL_BACKUP_CHANGE_LOG:
85 case NETLOGON_CONTROL_TRUNCATE_LOG:
88 return WERR_NOT_SUPPORTED;
91 l.in.logon_server = r->in.logon_server;
92 l.in.function_code = r->in.function_code;
93 l.in.level = r->in.level;
95 l.out.query = r->out.query;
97 return _netr_LogonControl2Ex(p, &l);
100 /*************************************************************************
102 *************************************************************************/
104 WERROR _netr_LogonControl2(struct pipes_struct *p,
105 struct netr_LogonControl2 *r)
107 struct netr_LogonControl2Ex l;
109 l.in.logon_server = r->in.logon_server;
110 l.in.function_code = r->in.function_code;
111 l.in.level = r->in.level;
112 l.in.data = r->in.data;
113 l.out.query = r->out.query;
115 return _netr_LogonControl2Ex(p, &l);
118 /*************************************************************************
119 *************************************************************************/
121 static bool wb_change_trust_creds(const char *domain, WERROR *tc_status)
124 struct wbcAuthErrorInfo *error = NULL;
126 result = wbcChangeTrustCredentials(domain, &error);
128 case WBC_ERR_WINBIND_NOT_AVAILABLE:
130 case WBC_ERR_DOMAIN_NOT_FOUND:
131 *tc_status = WERR_NO_SUCH_DOMAIN;
133 case WBC_ERR_SUCCESS:
134 *tc_status = WERR_OK;
140 if (error && error->nt_status != 0) {
141 *tc_status = ntstatus_to_werror(NT_STATUS(error->nt_status));
143 *tc_status = WERR_TRUST_FAILURE;
145 wbcFreeMemory(error);
149 /*************************************************************************
150 *************************************************************************/
152 static bool wb_check_trust_creds(const char *domain, WERROR *tc_status)
155 struct wbcAuthErrorInfo *error = NULL;
157 result = wbcCheckTrustCredentials(domain, &error);
159 case WBC_ERR_WINBIND_NOT_AVAILABLE:
161 case WBC_ERR_DOMAIN_NOT_FOUND:
162 *tc_status = WERR_NO_SUCH_DOMAIN;
164 case WBC_ERR_SUCCESS:
165 *tc_status = WERR_OK;
171 if (error && error->nt_status != 0) {
172 *tc_status = ntstatus_to_werror(NT_STATUS(error->nt_status));
174 *tc_status = WERR_TRUST_FAILURE;
176 wbcFreeMemory(error);
180 /****************************************************************
181 _netr_LogonControl2Ex
182 ****************************************************************/
184 WERROR _netr_LogonControl2Ex(struct pipes_struct *p,
185 struct netr_LogonControl2Ex *r)
187 uint32_t flags = 0x0;
188 WERROR pdc_connection_status = WERR_OK;
189 uint32_t logon_attempts = 0x0;
192 const char *dc_name = NULL;
193 struct sockaddr_storage dc_ss;
194 const char *domain = NULL;
195 struct netr_NETLOGON_INFO_1 *info1;
196 struct netr_NETLOGON_INFO_2 *info2;
197 struct netr_NETLOGON_INFO_3 *info3;
198 struct netr_NETLOGON_INFO_4 *info4;
201 struct netr_DsRGetDCNameInfo *dc_info;
204 case NDR_NETR_LOGONCONTROL:
205 fn = "_netr_LogonControl";
207 case NDR_NETR_LOGONCONTROL2:
208 fn = "_netr_LogonControl2";
210 case NDR_NETR_LOGONCONTROL2EX:
211 fn = "_netr_LogonControl2Ex";
214 return WERR_INVALID_PARAM;
217 switch (r->in.level) {
224 return WERR_INVALID_LEVEL;
227 switch (r->in.function_code) {
228 case NETLOGON_CONTROL_QUERY:
231 if ((geteuid() != sec_initial_uid()) &&
232 !nt_token_check_domain_rid(p->session_info->security_token, DOMAIN_RID_ADMINS) &&
233 !nt_token_check_sid(&global_sid_Builtin_Administrators, p->session_info->security_token))
235 return WERR_ACCESS_DENIED;
240 tc_status = WERR_NO_SUCH_DOMAIN;
242 switch (r->in.function_code) {
243 case NETLOGON_CONTROL_QUERY:
244 switch (r->in.level) {
249 return WERR_INVALID_PARAMETER;
254 case NETLOGON_CONTROL_REPLICATE:
255 case NETLOGON_CONTROL_SYNCHRONIZE:
256 case NETLOGON_CONTROL_PDC_REPLICATE:
257 case NETLOGON_CONTROL_BACKUP_CHANGE_LOG:
258 case NETLOGON_CONTROL_BREAKPOINT:
259 case NETLOGON_CONTROL_TRUNCATE_LOG:
260 case NETLOGON_CONTROL_TRANSPORT_NOTIFY:
261 case NETLOGON_CONTROL_FORCE_DNS_REG:
262 case NETLOGON_CONTROL_QUERY_DNS_REG:
263 return WERR_NOT_SUPPORTED;
265 case NETLOGON_CONTROL_FIND_USER:
266 if (!r->in.data || !r->in.data->user) {
267 return WERR_NOT_SUPPORTED;
270 case NETLOGON_CONTROL_SET_DBFLAG:
272 return WERR_NOT_SUPPORTED;
275 case NETLOGON_CONTROL_TC_VERIFY:
276 if (!r->in.data || !r->in.data->domain) {
277 return WERR_NOT_SUPPORTED;
280 if (!wb_check_trust_creds(r->in.data->domain, &tc_status)) {
281 return WERR_NOT_SUPPORTED;
284 case NETLOGON_CONTROL_TC_QUERY:
285 if (!r->in.data || !r->in.data->domain) {
286 return WERR_NOT_SUPPORTED;
289 domain = r->in.data->domain;
291 if (!is_trusted_domain(domain)) {
295 if (!get_dc_name(domain, NULL, dc_name2, &dc_ss)) {
296 tc_status = WERR_NO_LOGON_SERVERS;
300 dc_name = talloc_asprintf(p->mem_ctx, "\\\\%s", dc_name2);
309 case NETLOGON_CONTROL_REDISCOVER:
310 if (!r->in.data || !r->in.data->domain) {
311 return WERR_NOT_SUPPORTED;
314 domain = r->in.data->domain;
316 if (!is_trusted_domain(domain)) {
320 status = dsgetdcname(p->mem_ctx, p->msg_ctx, domain, NULL, NULL,
321 DS_FORCE_REDISCOVERY | DS_RETURN_FLAT_NAME,
323 if (!NT_STATUS_IS_OK(status)) {
324 tc_status = WERR_NO_LOGON_SERVERS;
328 dc_name = talloc_asprintf(p->mem_ctx, "\\\\%s", dc_info->dc_unc);
337 case NETLOGON_CONTROL_CHANGE_PASSWORD:
338 if (!r->in.data || !r->in.data->domain) {
339 return WERR_NOT_SUPPORTED;
342 if (!wb_change_trust_creds(r->in.data->domain, &tc_status)) {
343 return WERR_NOT_SUPPORTED;
348 /* no idea what this should be */
349 DEBUG(0,("%s: unimplemented function level [%d]\n",
350 fn, r->in.function_code));
351 return WERR_NOT_SUPPORTED;
354 /* prepare the response */
356 switch (r->in.level) {
358 info1 = talloc_zero(p->mem_ctx, struct netr_NETLOGON_INFO_1);
359 W_ERROR_HAVE_NO_MEMORY(info1);
361 info1->flags = flags;
362 info1->pdc_connection_status = pdc_connection_status;
364 r->out.query->info1 = info1;
367 info2 = talloc_zero(p->mem_ctx, struct netr_NETLOGON_INFO_2);
368 W_ERROR_HAVE_NO_MEMORY(info2);
370 info2->flags = flags;
371 info2->pdc_connection_status = pdc_connection_status;
372 info2->trusted_dc_name = dc_name;
373 info2->tc_connection_status = tc_status;
375 r->out.query->info2 = info2;
378 info3 = talloc_zero(p->mem_ctx, struct netr_NETLOGON_INFO_3);
379 W_ERROR_HAVE_NO_MEMORY(info3);
381 info3->flags = flags;
382 info3->logon_attempts = logon_attempts;
384 r->out.query->info3 = info3;
387 info4 = talloc_zero(p->mem_ctx, struct netr_NETLOGON_INFO_4);
388 W_ERROR_HAVE_NO_MEMORY(info4);
390 info4->trusted_dc_name = dc_name;
391 info4->trusted_domain_name = r->in.data->domain;
393 r->out.query->info4 = info4;
396 return WERR_UNKNOWN_LEVEL;
402 /*************************************************************************
403 _netr_NetrEnumerateTrustedDomains
404 *************************************************************************/
406 NTSTATUS _netr_NetrEnumerateTrustedDomains(struct pipes_struct *p,
407 struct netr_NetrEnumerateTrustedDomains *r)
410 NTSTATUS result = NT_STATUS_OK;
412 size_t num_domains = 0;
413 const char **trusted_domains = NULL;
414 struct lsa_DomainList domain_list;
415 struct dcerpc_binding_handle *h = NULL;
416 struct policy_handle pol;
417 uint32_t enum_ctx = 0;
419 uint32_t max_size = (uint32_t)-1;
421 DEBUG(6,("_netr_NetrEnumerateTrustedDomains: %d\n", __LINE__));
423 status = rpcint_binding_handle(p->mem_ctx,
429 if (!NT_STATUS_IS_OK(status)) {
433 status = dcerpc_lsa_open_policy2(h,
437 LSA_POLICY_VIEW_LOCAL_INFORMATION,
440 if (!NT_STATUS_IS_OK(status)) {
443 if (!NT_STATUS_IS_OK(result)) {
449 /* Lookup list of trusted domains */
450 status = dcerpc_lsa_EnumTrustDom(h,
457 if (!NT_STATUS_IS_OK(status)) {
460 if (!NT_STATUS_IS_OK(result) &&
461 !NT_STATUS_EQUAL(result, NT_STATUS_NO_MORE_ENTRIES) &&
462 !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)) {
467 for (i = 0; i < domain_list.count; i++) {
468 if (!add_string_to_array(p->mem_ctx, domain_list.domains[i].name.string,
469 &trusted_domains, &num_domains)) {
470 status = NT_STATUS_NO_MEMORY;
474 } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
476 if (num_domains > 0) {
477 /* multi sz terminate */
478 trusted_domains = talloc_realloc(p->mem_ctx, trusted_domains, const char *, num_domains + 1);
479 if (trusted_domains == NULL) {
480 status = NT_STATUS_NO_MEMORY;
484 trusted_domains[num_domains] = NULL;
487 if (!push_reg_multi_sz(trusted_domains, &blob, trusted_domains)) {
488 TALLOC_FREE(trusted_domains);
489 status = NT_STATUS_NO_MEMORY;
493 r->out.trusted_domains_blob->data = blob.data;
494 r->out.trusted_domains_blob->length = blob.length;
496 DEBUG(6,("_netr_NetrEnumerateTrustedDomains: %d\n", __LINE__));
498 status = NT_STATUS_OK;
501 if (is_valid_policy_hnd(&pol)) {
502 dcerpc_lsa_Close(h, p->mem_ctx, &pol, &result);
508 /*************************************************************************
509 *************************************************************************/
511 static NTSTATUS samr_find_machine_account(TALLOC_CTX *mem_ctx,
512 struct dcerpc_binding_handle *b,
513 const char *account_name,
514 uint32_t access_mask,
515 struct dom_sid2 **domain_sid_p,
516 uint32_t *user_rid_p,
517 struct policy_handle *user_handle)
520 NTSTATUS result = NT_STATUS_OK;
521 struct policy_handle connect_handle;
522 struct policy_handle domain_handle = { 0, };
523 struct lsa_String domain_name;
524 struct dom_sid2 *domain_sid;
525 struct lsa_String names;
526 struct samr_Ids rids;
527 struct samr_Ids types;
530 status = dcerpc_samr_Connect2(b, mem_ctx,
532 SAMR_ACCESS_CONNECT_TO_SERVER |
533 SAMR_ACCESS_ENUM_DOMAINS |
534 SAMR_ACCESS_LOOKUP_DOMAIN,
537 if (!NT_STATUS_IS_OK(status)) {
540 if (!NT_STATUS_IS_OK(result)) {
545 init_lsa_String(&domain_name, get_global_sam_name());
547 status = dcerpc_samr_LookupDomain(b, mem_ctx,
552 if (!NT_STATUS_IS_OK(status)) {
555 if (!NT_STATUS_IS_OK(result)) {
560 status = dcerpc_samr_OpenDomain(b, mem_ctx,
562 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
566 if (!NT_STATUS_IS_OK(status)) {
569 if (!NT_STATUS_IS_OK(result)) {
574 init_lsa_String(&names, account_name);
576 status = dcerpc_samr_LookupNames(b, mem_ctx,
583 if (!NT_STATUS_IS_OK(status)) {
586 if (!NT_STATUS_IS_OK(result)) {
591 if (rids.count != 1) {
592 status = NT_STATUS_NO_SUCH_USER;
595 if (types.count != 1) {
596 status = NT_STATUS_INVALID_PARAMETER;
599 if (types.ids[0] != SID_NAME_USER) {
600 status = NT_STATUS_NO_SUCH_USER;
606 status = dcerpc_samr_OpenUser(b, mem_ctx,
612 if (!NT_STATUS_IS_OK(status)) {
615 if (!NT_STATUS_IS_OK(result)) {
625 *domain_sid_p = domain_sid;
629 if (is_valid_policy_hnd(&domain_handle)) {
630 dcerpc_samr_Close(b, mem_ctx, &domain_handle, &result);
632 if (is_valid_policy_hnd(&connect_handle)) {
633 dcerpc_samr_Close(b, mem_ctx, &connect_handle, &result);
639 /******************************************************************
640 gets a machine password entry. checks access rights of the host.
641 ******************************************************************/
643 static NTSTATUS get_md4pw(struct samr_Password *md4pw, const char *mach_acct,
644 enum netr_SchannelType sec_chan_type,
646 struct messaging_context *msg_ctx)
649 NTSTATUS result = NT_STATUS_OK;
651 struct dcerpc_binding_handle *h = NULL;
652 struct tsocket_address *local;
653 struct policy_handle user_handle;
655 struct dom_sid *domain_sid;
657 union samr_UserInfo *info;
658 struct auth_session_info *session_info;
664 * Currently this code is redundant as we already have a filter
665 * by hostname list. What this code really needs to do is to
666 * get a hosts allowed/hosts denied list from the SAM database
667 * on a per user basis, and make the access decision there.
668 * I will leave this code here for now as a reminder to implement
669 * this at a later date. JRA.
672 if (!allow_access(lp_domain_hostsdeny(), lp_domain_hostsallow(),
674 p->client_id.addr)) {
675 DEBUG(0,("get_md4pw: Workstation %s denied access to domain\n", mach_acct));
680 mem_ctx = talloc_stackframe();
681 if (mem_ctx == NULL) {
682 status = NT_STATUS_NO_MEMORY;
686 status = make_session_info_system(mem_ctx, &session_info);
687 if (!NT_STATUS_IS_OK(status)) {
691 ZERO_STRUCT(user_handle);
693 rc = tsocket_address_inet_from_strings(mem_ctx,
699 status = NT_STATUS_NO_MEMORY;
703 status = rpcint_binding_handle(mem_ctx,
709 if (!NT_STATUS_IS_OK(status)) {
713 status = samr_find_machine_account(mem_ctx, h, mach_acct,
714 SEC_FLAG_MAXIMUM_ALLOWED,
715 &domain_sid, &user_rid,
717 if (!NT_STATUS_IS_OK(status)) {
721 status = dcerpc_samr_QueryUserInfo2(h,
724 UserControlInformation,
727 if (!NT_STATUS_IS_OK(status)) {
730 if (!NT_STATUS_IS_OK(result)) {
735 acct_ctrl = info->info16.acct_flags;
737 if (acct_ctrl & ACB_DISABLED) {
738 DEBUG(0,("get_md4pw: Workstation %s: account is disabled\n", mach_acct));
739 status = NT_STATUS_ACCOUNT_DISABLED;
743 if (!(acct_ctrl & ACB_SVRTRUST) &&
744 !(acct_ctrl & ACB_WSTRUST) &&
745 !(acct_ctrl & ACB_DOMTRUST))
747 DEBUG(0,("get_md4pw: Workstation %s: account is not a trust account\n", mach_acct));
748 status = NT_STATUS_NO_TRUST_SAM_ACCOUNT;
752 switch (sec_chan_type) {
754 if (!(acct_ctrl & ACB_SVRTRUST)) {
755 DEBUG(0,("get_md4pw: Workstation %s: BDC secure channel requested "
756 "but not a server trust account\n", mach_acct));
757 status = NT_STATUS_NO_TRUST_SAM_ACCOUNT;
762 if (!(acct_ctrl & ACB_WSTRUST)) {
763 DEBUG(0,("get_md4pw: Workstation %s: WORKSTATION secure channel requested "
764 "but not a workstation trust account\n", mach_acct));
765 status = NT_STATUS_NO_TRUST_SAM_ACCOUNT;
769 case SEC_CHAN_DOMAIN:
770 if (!(acct_ctrl & ACB_DOMTRUST)) {
771 DEBUG(0,("get_md4pw: Workstation %s: DOMAIN secure channel requested "
772 "but not a interdomain trust account\n", mach_acct));
773 status = NT_STATUS_NO_TRUST_SAM_ACCOUNT;
782 status = dcerpc_samr_QueryUserInfo2(h,
785 UserInternal1Information,
789 if (!NT_STATUS_IS_OK(status)) {
792 if (!NT_STATUS_IS_OK(result)) {
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 netlogon_server_pipe_state *pipe_state =
826 talloc_get_type(p->private_data, struct netlogon_server_pipe_state);
829 DEBUG(10,("_netr_ServerReqChallenge: new challenge requested. Clearing old state.\n"));
830 talloc_free(pipe_state);
831 p->private_data = NULL;
834 pipe_state = talloc(p, struct netlogon_server_pipe_state);
835 NT_STATUS_HAVE_NO_MEMORY(pipe_state);
837 pipe_state->client_challenge = *r->in.credentials;
839 generate_random_buffer(pipe_state->server_challenge.data,
840 sizeof(pipe_state->server_challenge.data));
842 *r->out.return_credentials = pipe_state->server_challenge;
844 p->private_data = pipe_state;
849 /*************************************************************************
850 _netr_ServerAuthenticate
851 Create the initial credentials.
852 *************************************************************************/
854 NTSTATUS _netr_ServerAuthenticate(struct pipes_struct *p,
855 struct netr_ServerAuthenticate *r)
857 struct netr_ServerAuthenticate3 a;
858 uint32_t negotiate_flags = 0;
861 a.in.server_name = r->in.server_name;
862 a.in.account_name = r->in.account_name;
863 a.in.secure_channel_type = r->in.secure_channel_type;
864 a.in.computer_name = r->in.computer_name;
865 a.in.credentials = r->in.credentials;
866 a.in.negotiate_flags = &negotiate_flags;
868 a.out.return_credentials = r->out.return_credentials;
870 a.out.negotiate_flags = &negotiate_flags;
872 return _netr_ServerAuthenticate3(p, &a);
876 /*************************************************************************
877 _netr_ServerAuthenticate3
878 *************************************************************************/
880 NTSTATUS _netr_ServerAuthenticate3(struct pipes_struct *p,
881 struct netr_ServerAuthenticate3 *r)
885 /* r->in.negotiate_flags is an aliased pointer to r->out.negotiate_flags,
886 * so use a copy to avoid destroying the client values. */
887 uint32_t in_neg_flags = *r->in.negotiate_flags;
889 struct loadparm_context *lp_ctx;
891 struct samr_Password mach_pwd;
892 struct netlogon_creds_CredentialState *creds;
893 struct netlogon_server_pipe_state *pipe_state =
894 talloc_get_type(p->private_data, struct netlogon_server_pipe_state);
896 /* According to Microsoft (see bugid #6099)
897 * Windows 7 looks at the negotiate_flags
898 * returned in this structure *even if the
899 * call fails with access denied* ! So in order
900 * to allow Win7 to connect to a Samba NT style
901 * PDC we set the flags before we know if it's
906 srv_flgs = NETLOGON_NEG_ACCOUNT_LOCKOUT |
907 NETLOGON_NEG_PERSISTENT_SAMREPL |
908 NETLOGON_NEG_ARCFOUR |
909 NETLOGON_NEG_PROMOTION_COUNT |
910 NETLOGON_NEG_CHANGELOG_BDC |
911 NETLOGON_NEG_FULL_SYNC_REPL |
912 NETLOGON_NEG_MULTIPLE_SIDS |
914 NETLOGON_NEG_PASSWORD_CHANGE_REFUSAL |
915 NETLOGON_NEG_PASSWORD_SET2;
917 /* Ensure we support strong (128-bit) keys. */
918 if (in_neg_flags & NETLOGON_NEG_STRONG_KEYS) {
919 srv_flgs |= NETLOGON_NEG_STRONG_KEYS;
922 if (in_neg_flags & NETLOGON_NEG_SUPPORTS_AES) {
923 srv_flgs |= NETLOGON_NEG_SUPPORTS_AES;
926 if (lp_server_schannel() != false) {
927 srv_flgs |= NETLOGON_NEG_SCHANNEL;
931 * Support authenticaten of trusted domains.
933 * These flags are the minimum required set which works with win2k3
936 if (pdb_capabilities() & PDB_CAP_TRUSTED_DOMAINS_EX) {
937 srv_flgs |= NETLOGON_NEG_TRANSITIVE_TRUSTS |
938 NETLOGON_NEG_DNS_DOMAIN_TRUSTS |
939 NETLOGON_NEG_CROSS_FOREST_TRUSTS |
940 NETLOGON_NEG_NEUTRALIZE_NT4_EMULATION;
944 case NDR_NETR_SERVERAUTHENTICATE:
945 fn = "_netr_ServerAuthenticate";
947 case NDR_NETR_SERVERAUTHENTICATE2:
948 fn = "_netr_ServerAuthenticate2";
950 case NDR_NETR_SERVERAUTHENTICATE3:
951 fn = "_netr_ServerAuthenticate3";
954 return NT_STATUS_INTERNAL_ERROR;
957 /* We use this as the key to store the creds: */
958 /* r->in.computer_name */
961 DEBUG(0,("%s: no challenge sent to client %s\n", fn,
962 r->in.computer_name));
963 status = NT_STATUS_ACCESS_DENIED;
967 if ( (lp_server_schannel() == true) &&
968 ((in_neg_flags & NETLOGON_NEG_SCHANNEL) == 0) ) {
970 /* schannel must be used, but client did not offer it. */
971 DEBUG(0,("%s: schannel required but client failed "
972 "to offer it. Client was %s\n",
973 fn, r->in.account_name));
974 status = NT_STATUS_ACCESS_DENIED;
978 status = get_md4pw(&mach_pwd,
980 r->in.secure_channel_type,
982 if (!NT_STATUS_IS_OK(status)) {
983 DEBUG(0,("%s: failed to get machine password for "
985 fn, r->in.account_name, nt_errstr(status) ));
986 /* always return NT_STATUS_ACCESS_DENIED */
987 status = NT_STATUS_ACCESS_DENIED;
991 /* From the client / server challenges and md4 password, generate sess key */
992 /* Check client credentials are valid. */
993 creds = netlogon_creds_server_init(p->mem_ctx,
996 r->in.secure_channel_type,
997 &pipe_state->client_challenge,
998 &pipe_state->server_challenge,
1001 r->out.return_credentials,
1004 DEBUG(0,("%s: netlogon_creds_server_check failed. Rejecting auth "
1005 "request from client %s machine account %s\n",
1006 fn, r->in.computer_name,
1007 r->in.account_name));
1008 status = NT_STATUS_ACCESS_DENIED;
1012 creds->sid = dom_sid_dup(creds, &sid);
1014 status = NT_STATUS_NO_MEMORY;
1018 lp_ctx = loadparm_init_s3(p->mem_ctx, loadparm_s3_helpers());
1019 if (lp_ctx == NULL) {
1020 DEBUG(10, ("loadparm_init_s3 failed\n"));
1021 status = NT_STATUS_INTERNAL_ERROR;
1025 /* Store off the state so we can continue after client disconnect. */
1027 status = schannel_save_creds_state(p->mem_ctx, lp_ctx, creds);
1030 talloc_unlink(p->mem_ctx, lp_ctx);
1032 if (!NT_STATUS_IS_OK(status)) {
1033 ZERO_STRUCTP(r->out.return_credentials);
1037 sid_peek_rid(&sid, r->out.rid);
1039 status = NT_STATUS_OK;
1043 *r->out.negotiate_flags = srv_flgs;
1047 /*************************************************************************
1048 _netr_ServerAuthenticate2
1049 *************************************************************************/
1051 NTSTATUS _netr_ServerAuthenticate2(struct pipes_struct *p,
1052 struct netr_ServerAuthenticate2 *r)
1054 struct netr_ServerAuthenticate3 a;
1057 a.in.server_name = r->in.server_name;
1058 a.in.account_name = r->in.account_name;
1059 a.in.secure_channel_type = r->in.secure_channel_type;
1060 a.in.computer_name = r->in.computer_name;
1061 a.in.credentials = r->in.credentials;
1062 a.in.negotiate_flags = r->in.negotiate_flags;
1064 a.out.return_credentials = r->out.return_credentials;
1066 a.out.negotiate_flags = r->out.negotiate_flags;
1068 return _netr_ServerAuthenticate3(p, &a);
1071 /*************************************************************************
1072 * If schannel is required for this call test that it actually is available.
1073 *************************************************************************/
1074 static NTSTATUS schannel_check_required(struct pipe_auth_data *auth_info,
1075 const char *computer_name,
1076 bool integrity, bool privacy)
1078 if (auth_info && auth_info->auth_type == DCERPC_AUTH_TYPE_SCHANNEL) {
1079 if (!privacy && !integrity) {
1080 return NT_STATUS_OK;
1083 if ((!privacy && integrity) &&
1084 auth_info->auth_level == DCERPC_AUTH_LEVEL_INTEGRITY) {
1085 return NT_STATUS_OK;
1088 if ((privacy || integrity) &&
1089 auth_info->auth_level == DCERPC_AUTH_LEVEL_PRIVACY) {
1090 return NT_STATUS_OK;
1094 /* test didn't pass */
1095 DEBUG(0, ("schannel_check_required: [%s] is not using schannel\n",
1098 return NT_STATUS_ACCESS_DENIED;
1101 /*************************************************************************
1102 *************************************************************************/
1104 static NTSTATUS netr_creds_server_step_check(struct pipes_struct *p,
1105 TALLOC_CTX *mem_ctx,
1106 const char *computer_name,
1107 struct netr_Authenticator *received_authenticator,
1108 struct netr_Authenticator *return_authenticator,
1109 struct netlogon_creds_CredentialState **creds_out)
1112 bool schannel_global_required = (lp_server_schannel() == true) ? true:false;
1113 struct loadparm_context *lp_ctx;
1115 if (creds_out != NULL) {
1119 if (schannel_global_required) {
1120 status = schannel_check_required(&p->auth,
1123 if (!NT_STATUS_IS_OK(status)) {
1128 lp_ctx = loadparm_init_s3(mem_ctx, loadparm_s3_helpers());
1129 if (lp_ctx == NULL) {
1130 DEBUG(0, ("loadparm_init_s3 failed\n"));
1131 return NT_STATUS_INTERNAL_ERROR;
1134 status = schannel_check_creds_state(mem_ctx, lp_ctx,
1135 computer_name, received_authenticator,
1136 return_authenticator, creds_out);
1137 talloc_unlink(mem_ctx, lp_ctx);
1141 /*************************************************************************
1142 *************************************************************************/
1144 static NTSTATUS netr_set_machine_account_password(TALLOC_CTX *mem_ctx,
1145 struct auth_session_info *session_info,
1146 struct messaging_context *msg_ctx,
1147 const char *account_name,
1148 struct samr_Password *nt_hash)
1151 NTSTATUS result = NT_STATUS_OK;
1152 struct dcerpc_binding_handle *h = NULL;
1153 struct tsocket_address *local;
1154 struct policy_handle user_handle;
1156 union samr_UserInfo *info;
1157 struct samr_UserInfo18 info18;
1160 DATA_BLOB session_key;
1162 ZERO_STRUCT(user_handle);
1164 status = session_extract_session_key(session_info,
1167 if (!NT_STATUS_IS_OK(status)) {
1171 rc = tsocket_address_inet_from_strings(mem_ctx,
1177 status = NT_STATUS_NO_MEMORY;
1181 status = rpcint_binding_handle(mem_ctx,
1187 if (!NT_STATUS_IS_OK(status)) {
1192 status = samr_find_machine_account(mem_ctx,
1195 SEC_FLAG_MAXIMUM_ALLOWED,
1200 if (!NT_STATUS_IS_OK(status)) {
1204 status = dcerpc_samr_QueryUserInfo2(h,
1207 UserControlInformation,
1210 if (!NT_STATUS_IS_OK(status)) {
1213 if (!NT_STATUS_IS_OK(result)) {
1218 acct_ctrl = info->info16.acct_flags;
1220 if (!(acct_ctrl & ACB_WSTRUST ||
1221 acct_ctrl & ACB_SVRTRUST ||
1222 acct_ctrl & ACB_DOMTRUST)) {
1223 status = NT_STATUS_NO_SUCH_USER;
1227 if (acct_ctrl & ACB_DISABLED) {
1228 status = NT_STATUS_ACCOUNT_DISABLED;
1232 ZERO_STRUCT(info18);
1234 in = data_blob_const(nt_hash->hash, 16);
1235 out = data_blob_talloc_zero(mem_ctx, 16);
1236 sess_crypt_blob(&out, &in, &session_key, true);
1237 memcpy(info18.nt_pwd.hash, out.data, out.length);
1239 info18.nt_pwd_active = true;
1241 info->info18 = info18;
1244 status = dcerpc_samr_SetUserInfo2(h,
1247 UserInternal1Information,
1251 if (!NT_STATUS_IS_OK(status)) {
1254 if (!NT_STATUS_IS_OK(result)) {
1260 if (h && is_valid_policy_hnd(&user_handle)) {
1261 dcerpc_samr_Close(h, mem_ctx, &user_handle, &result);
1267 /*************************************************************************
1268 _netr_ServerPasswordSet
1269 *************************************************************************/
1271 NTSTATUS _netr_ServerPasswordSet(struct pipes_struct *p,
1272 struct netr_ServerPasswordSet *r)
1274 NTSTATUS status = NT_STATUS_OK;
1276 struct netlogon_creds_CredentialState *creds = NULL;
1278 DEBUG(5,("_netr_ServerPasswordSet: %d\n", __LINE__));
1281 status = netr_creds_server_step_check(p, p->mem_ctx,
1282 r->in.computer_name,
1284 r->out.return_authenticator,
1288 if (!NT_STATUS_IS_OK(status)) {
1289 const char *computer_name = "<unknown>";
1291 if (creds != NULL && creds->computer_name != NULL) {
1292 computer_name = creds->computer_name;
1294 DEBUG(2,("_netr_ServerPasswordSet: netlogon_creds_server_step failed. Rejecting auth "
1295 "request from client %s machine account %s\n",
1296 r->in.computer_name, computer_name));
1301 DEBUG(3,("_netr_ServerPasswordSet: Server Password Set by remote machine:[%s] on account [%s]\n",
1302 r->in.computer_name, creds->computer_name));
1304 netlogon_creds_des_decrypt(creds, r->in.new_password);
1306 DEBUG(100,("_netr_ServerPasswordSet: new given value was :\n"));
1307 for(i = 0; i < sizeof(r->in.new_password->hash); i++)
1308 DEBUG(100,("%02X ", r->in.new_password->hash[i]));
1311 status = netr_set_machine_account_password(p->mem_ctx,
1314 creds->account_name,
1315 r->in.new_password);
1319 /****************************************************************
1320 _netr_ServerPasswordSet2
1321 ****************************************************************/
1323 NTSTATUS _netr_ServerPasswordSet2(struct pipes_struct *p,
1324 struct netr_ServerPasswordSet2 *r)
1327 struct netlogon_creds_CredentialState *creds = NULL;
1328 DATA_BLOB plaintext;
1329 struct samr_CryptPassword password_buf;
1330 struct samr_Password nt_hash;
1333 status = netr_creds_server_step_check(p, p->mem_ctx,
1334 r->in.computer_name,
1336 r->out.return_authenticator,
1340 if (!NT_STATUS_IS_OK(status)) {
1341 const char *computer_name = "<unknown>";
1343 if (creds && creds->computer_name) {
1344 computer_name = creds->computer_name;
1346 DEBUG(2,("_netr_ServerPasswordSet2: netlogon_creds_server_step "
1347 "failed. Rejecting auth request from client %s machine account %s\n",
1348 r->in.computer_name, computer_name));
1353 memcpy(password_buf.data, r->in.new_password->data, 512);
1354 SIVAL(password_buf.data, 512, r->in.new_password->length);
1356 if (creds->negotiate_flags & NETLOGON_NEG_SUPPORTS_AES) {
1357 netlogon_creds_aes_decrypt(creds, password_buf.data, 516);
1359 netlogon_creds_arcfour_crypt(creds, password_buf.data, 516);
1362 if (!extract_pw_from_buffer(p->mem_ctx, password_buf.data, &plaintext)) {
1364 return NT_STATUS_WRONG_PASSWORD;
1367 mdfour(nt_hash.hash, plaintext.data, plaintext.length);
1369 status = netr_set_machine_account_password(p->mem_ctx,
1372 creds->account_name,
1378 /*************************************************************************
1379 _netr_LogonSamLogoff
1380 *************************************************************************/
1382 NTSTATUS _netr_LogonSamLogoff(struct pipes_struct *p,
1383 struct netr_LogonSamLogoff *r)
1386 struct netlogon_creds_CredentialState *creds;
1389 status = netr_creds_server_step_check(p, p->mem_ctx,
1390 r->in.computer_name,
1392 r->out.return_authenticator,
1399 static NTSTATUS _netr_LogonSamLogon_check(const struct netr_LogonSamLogonEx *r)
1401 switch (r->in.logon_level) {
1402 case NetlogonInteractiveInformation:
1403 case NetlogonServiceInformation:
1404 case NetlogonInteractiveTransitiveInformation:
1405 case NetlogonServiceTransitiveInformation:
1406 if (r->in.logon->password == NULL) {
1407 return NT_STATUS_INVALID_PARAMETER;
1410 switch (r->in.validation_level) {
1411 case NetlogonValidationSamInfo: /* 2 */
1412 case NetlogonValidationSamInfo2: /* 3 */
1414 case NetlogonValidationSamInfo4: /* 6 */
1415 if ((pdb_capabilities() & PDB_CAP_ADS) == 0) {
1416 DEBUG(10,("Not adding validation info level 6 "
1417 "without ADS passdb backend\n"));
1418 return NT_STATUS_INVALID_INFO_CLASS;
1422 return NT_STATUS_INVALID_INFO_CLASS;
1426 case NetlogonNetworkInformation:
1427 case NetlogonNetworkTransitiveInformation:
1428 if (r->in.logon->network == NULL) {
1429 return NT_STATUS_INVALID_PARAMETER;
1432 switch (r->in.validation_level) {
1433 case NetlogonValidationSamInfo: /* 2 */
1434 case NetlogonValidationSamInfo2: /* 3 */
1436 case NetlogonValidationSamInfo4: /* 6 */
1437 if ((pdb_capabilities() & PDB_CAP_ADS) == 0) {
1438 DEBUG(10,("Not adding validation info level 6 "
1439 "without ADS passdb backend\n"));
1440 return NT_STATUS_INVALID_INFO_CLASS;
1444 return NT_STATUS_INVALID_INFO_CLASS;
1449 case NetlogonGenericInformation:
1450 if (r->in.logon->generic == NULL) {
1451 return NT_STATUS_INVALID_PARAMETER;
1454 /* we don't support this here */
1455 return NT_STATUS_INVALID_PARAMETER;
1457 switch (r->in.validation_level) {
1458 /* TODO: case NetlogonValidationGenericInfo: 4 */
1459 case NetlogonValidationGenericInfo2: /* 5 */
1462 return NT_STATUS_INVALID_INFO_CLASS;
1468 return NT_STATUS_INVALID_PARAMETER;
1471 return NT_STATUS_OK;
1474 /*************************************************************************
1475 _netr_LogonSamLogon_base
1476 *************************************************************************/
1478 static NTSTATUS _netr_LogonSamLogon_base(struct pipes_struct *p,
1479 struct netr_LogonSamLogonEx *r,
1480 struct netlogon_creds_CredentialState *creds)
1482 NTSTATUS status = NT_STATUS_OK;
1483 union netr_LogonLevel *logon = r->in.logon;
1484 const char *nt_username, *nt_domain, *nt_workstation;
1485 struct auth_usersupplied_info *user_info = NULL;
1486 struct auth_serversupplied_info *server_info = NULL;
1487 struct auth_context *auth_context = NULL;
1490 #ifdef DEBUG_PASSWORD
1491 logon = netlogon_creds_shallow_copy_logon(p->mem_ctx,
1494 if (logon == NULL) {
1495 logon = r->in.logon;
1500 case NDR_NETR_LOGONSAMLOGON:
1501 fn = "_netr_LogonSamLogon";
1503 case NDR_NETR_LOGONSAMLOGONWITHFLAGS:
1504 fn = "_netr_LogonSamLogonWithFlags";
1506 case NDR_NETR_LOGONSAMLOGONEX:
1507 fn = "_netr_LogonSamLogonEx";
1510 return NT_STATUS_INTERNAL_ERROR;
1513 *r->out.authoritative = true; /* authoritative response */
1515 switch (r->in.validation_level) {
1517 r->out.validation->sam2 = talloc_zero(p->mem_ctx, struct netr_SamInfo2);
1518 if (!r->out.validation->sam2) {
1519 return NT_STATUS_NO_MEMORY;
1523 r->out.validation->sam3 = talloc_zero(p->mem_ctx, struct netr_SamInfo3);
1524 if (!r->out.validation->sam3) {
1525 return NT_STATUS_NO_MEMORY;
1529 r->out.validation->sam6 = talloc_zero(p->mem_ctx, struct netr_SamInfo6);
1530 if (!r->out.validation->sam6) {
1531 return NT_STATUS_NO_MEMORY;
1535 DEBUG(0,("%s: bad validation_level value %d.\n",
1536 fn, (int)r->in.validation_level));
1537 return NT_STATUS_INVALID_INFO_CLASS;
1540 switch (r->in.logon_level) {
1541 case NetlogonInteractiveInformation:
1542 case NetlogonServiceInformation:
1543 case NetlogonInteractiveTransitiveInformation:
1544 case NetlogonServiceTransitiveInformation:
1545 nt_username = logon->password->identity_info.account_name.string ?
1546 logon->password->identity_info.account_name.string : "";
1547 nt_domain = logon->password->identity_info.domain_name.string ?
1548 logon->password->identity_info.domain_name.string : "";
1549 nt_workstation = logon->password->identity_info.workstation.string ?
1550 logon->password->identity_info.workstation.string : "";
1552 DEBUG(3,("SAM Logon (Interactive). Domain:[%s]. ", lp_workgroup()));
1554 case NetlogonNetworkInformation:
1555 case NetlogonNetworkTransitiveInformation:
1556 nt_username = logon->network->identity_info.account_name.string ?
1557 logon->network->identity_info.account_name.string : "";
1558 nt_domain = logon->network->identity_info.domain_name.string ?
1559 logon->network->identity_info.domain_name.string : "";
1560 nt_workstation = logon->network->identity_info.workstation.string ?
1561 logon->network->identity_info.workstation.string : "";
1563 DEBUG(3,("SAM Logon (Network). Domain:[%s]. ", lp_workgroup()));
1566 DEBUG(2,("SAM Logon: unsupported switch value\n"));
1567 return NT_STATUS_INVALID_INFO_CLASS;
1570 DEBUG(3,("User:[%s@%s] Requested Domain:[%s]\n", nt_username, nt_workstation, nt_domain));
1571 fstrcpy(current_user_info.smb_name, nt_username);
1572 sub_set_smb_name(nt_username);
1574 DEBUG(5,("Attempting validation level %d for unmapped username %s.\n",
1575 r->in.validation_level, nt_username));
1577 status = NT_STATUS_OK;
1579 netlogon_creds_decrypt_samlogon_logon(creds,
1583 switch (r->in.logon_level) {
1584 case NetlogonNetworkInformation:
1585 case NetlogonNetworkTransitiveInformation:
1587 const char *wksname = nt_workstation;
1588 const char *workgroup = lp_workgroup();
1590 status = make_auth_context_fixed(talloc_tos(), &auth_context,
1591 logon->network->challenge);
1592 if (!NT_STATUS_IS_OK(status)) {
1596 /* For a network logon, the workstation name comes in with two
1597 * backslashes in the front. Strip them if they are there. */
1599 if (*wksname == '\\') wksname++;
1600 if (*wksname == '\\') wksname++;
1602 /* Standard challenge/response authentication */
1603 if (!make_user_info_netlogon_network(talloc_tos(),
1605 nt_username, nt_domain,
1608 logon->network->identity_info.parameter_control,
1609 logon->network->lm.data,
1610 logon->network->lm.length,
1611 logon->network->nt.data,
1612 logon->network->nt.length)) {
1613 status = NT_STATUS_NO_MEMORY;
1616 if (NT_STATUS_IS_OK(status)) {
1617 status = NTLMv2_RESPONSE_verify_netlogon_creds(
1618 user_info->client.account_name,
1619 user_info->client.domain_name,
1620 user_info->password.response.nt,
1625 case NetlogonInteractiveInformation:
1626 case NetlogonServiceInformation:
1627 case NetlogonInteractiveTransitiveInformation:
1628 case NetlogonServiceTransitiveInformation:
1630 /* 'Interactive' authentication, supplies the password in its
1631 MD4 form, encrypted with the session key. We will convert
1632 this to challenge/response for the auth subsystem to chew
1637 #ifdef DEBUG_PASSWORD
1638 if (logon != r->in.logon) {
1639 DEBUG(100,("lm owf password:"));
1641 r->in.logon->password->lmpassword.hash, 16);
1643 DEBUG(100,("nt owf password:"));
1645 r->in.logon->password->ntpassword.hash, 16);
1648 DEBUG(100,("decrypt of lm owf password:"));
1649 dump_data(100, logon->password->lmpassword.hash, 16);
1651 DEBUG(100,("decrypt of nt owf password:"));
1652 dump_data(100, logon->password->ntpassword.hash, 16);
1654 status = make_auth_context_subsystem(talloc_tos(),
1656 if (!NT_STATUS_IS_OK(status)) {
1660 auth_get_ntlm_challenge(auth_context, chal);
1662 if (!make_user_info_netlogon_interactive(talloc_tos(),
1664 nt_username, nt_domain,
1667 logon->password->identity_info.parameter_control,
1669 logon->password->lmpassword.hash,
1670 logon->password->ntpassword.hash)) {
1671 status = NT_STATUS_NO_MEMORY;
1676 DEBUG(2,("SAM Logon: unsupported switch value\n"));
1677 return NT_STATUS_INVALID_INFO_CLASS;
1680 if ( NT_STATUS_IS_OK(status) ) {
1681 status = auth_check_ntlm_password(p->mem_ctx,
1687 TALLOC_FREE(auth_context);
1688 TALLOC_FREE(user_info);
1690 DEBUG(5,("%s: check_password returned status %s\n",
1691 fn, nt_errstr(status)));
1693 /* Check account and password */
1695 if (!NT_STATUS_IS_OK(status)) {
1696 /* If we don't know what this domain is, we need to
1697 indicate that we are not authoritative. This
1698 allows the client to decide if it needs to try
1699 a local user. Fix by jpjanosi@us.ibm.com, #2976 */
1700 if ( NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_USER)
1701 && !strequal(nt_domain, get_global_sam_name())
1702 && !is_trusted_domain(nt_domain) )
1703 *r->out.authoritative = false; /* We are not authoritative */
1705 TALLOC_FREE(server_info);
1709 if (server_info->guest) {
1710 /* We don't like guest domain logons... */
1711 DEBUG(5,("%s: Attempted domain logon as GUEST "
1713 TALLOC_FREE(server_info);
1714 return NT_STATUS_LOGON_FAILURE;
1717 /* This is the point at which, if the login was successful, that
1718 the SAM Local Security Authority should record that the user is
1719 logged in to the domain. */
1721 switch (r->in.validation_level) {
1723 status = serverinfo_to_SamInfo2(server_info,
1724 r->out.validation->sam2);
1727 status = serverinfo_to_SamInfo3(server_info,
1728 r->out.validation->sam3);
1731 /* Only allow this if the pipe is protected. */
1732 if (p->auth.auth_level < DCERPC_AUTH_LEVEL_PRIVACY) {
1733 DEBUG(0,("netr_Validation6: client %s not using privacy for netlogon\n",
1734 get_remote_machine_name()));
1735 status = NT_STATUS_INVALID_PARAMETER;
1739 status = serverinfo_to_SamInfo6(server_info,
1740 r->out.validation->sam6);
1744 TALLOC_FREE(server_info);
1746 if (!NT_STATUS_IS_OK(status)) {
1750 netlogon_creds_encrypt_samlogon_validation(creds,
1751 r->in.validation_level,
1753 return NT_STATUS_OK;
1756 /****************************************************************
1757 _netr_LogonSamLogonWithFlags
1758 ****************************************************************/
1760 NTSTATUS _netr_LogonSamLogonWithFlags(struct pipes_struct *p,
1761 struct netr_LogonSamLogonWithFlags *r)
1764 struct netlogon_creds_CredentialState *creds;
1765 struct netr_LogonSamLogonEx r2;
1766 struct netr_Authenticator return_authenticator;
1768 *r->out.authoritative = true;
1770 r2.in.server_name = r->in.server_name;
1771 r2.in.computer_name = r->in.computer_name;
1772 r2.in.logon_level = r->in.logon_level;
1773 r2.in.logon = r->in.logon;
1774 r2.in.validation_level = r->in.validation_level;
1775 r2.in.flags = r->in.flags;
1776 r2.out.validation = r->out.validation;
1777 r2.out.authoritative = r->out.authoritative;
1778 r2.out.flags = r->out.flags;
1780 status = _netr_LogonSamLogon_check(&r2);
1781 if (!NT_STATUS_IS_OK(status)) {
1786 status = netr_creds_server_step_check(p, p->mem_ctx,
1787 r->in.computer_name,
1789 &return_authenticator,
1792 if (!NT_STATUS_IS_OK(status)) {
1796 status = _netr_LogonSamLogon_base(p, &r2, creds);
1798 *r->out.return_authenticator = return_authenticator;
1803 /*************************************************************************
1805 *************************************************************************/
1807 NTSTATUS _netr_LogonSamLogon(struct pipes_struct *p,
1808 struct netr_LogonSamLogon *r)
1811 struct netr_LogonSamLogonWithFlags r2;
1814 r2.in.server_name = r->in.server_name;
1815 r2.in.computer_name = r->in.computer_name;
1816 r2.in.credential = r->in.credential;
1817 r2.in.logon_level = r->in.logon_level;
1818 r2.in.logon = r->in.logon;
1819 r2.in.validation_level = r->in.validation_level;
1820 r2.in.return_authenticator = r->in.return_authenticator;
1821 r2.in.flags = &flags;
1822 r2.out.validation = r->out.validation;
1823 r2.out.authoritative = r->out.authoritative;
1824 r2.out.flags = &flags;
1825 r2.out.return_authenticator = r->out.return_authenticator;
1827 status = _netr_LogonSamLogonWithFlags(p, &r2);
1832 /*************************************************************************
1833 _netr_LogonSamLogonEx
1834 - no credential chaining. Map into net sam logon.
1835 *************************************************************************/
1837 NTSTATUS _netr_LogonSamLogonEx(struct pipes_struct *p,
1838 struct netr_LogonSamLogonEx *r)
1841 struct netlogon_creds_CredentialState *creds = NULL;
1842 struct loadparm_context *lp_ctx;
1844 *r->out.authoritative = true;
1846 status = _netr_LogonSamLogon_check(r);
1847 if (!NT_STATUS_IS_OK(status)) {
1851 /* Only allow this if the pipe is protected. */
1852 if (p->auth.auth_type != DCERPC_AUTH_TYPE_SCHANNEL) {
1853 DEBUG(0,("_netr_LogonSamLogonEx: client %s not using schannel for netlogon\n",
1854 get_remote_machine_name() ));
1855 return NT_STATUS_INVALID_PARAMETER;
1858 lp_ctx = loadparm_init_s3(p->mem_ctx, loadparm_s3_helpers());
1859 if (lp_ctx == NULL) {
1860 DEBUG(0, ("loadparm_init_s3 failed\n"));
1861 return NT_STATUS_INTERNAL_ERROR;
1865 status = schannel_get_creds_state(p->mem_ctx, lp_ctx,
1866 r->in.computer_name, &creds);
1868 talloc_unlink(p->mem_ctx, lp_ctx);
1870 if (!NT_STATUS_IS_OK(status)) {
1874 status = _netr_LogonSamLogon_base(p, r, creds);
1880 /*************************************************************************
1882 *************************************************************************/
1883 #if 0 /* JERRY -- not correct */
1884 NTSTATUS _ds_enum_dom_trusts(struct pipes_struct *p, DS_Q_ENUM_DOM_TRUSTS *q_u,
1885 DS_R_ENUM_DOM_TRUSTS *r_u)
1887 NTSTATUS status = NT_STATUS_OK;
1889 /* TODO: According to MSDN, the can only be executed against a
1890 DC or domain member running Windows 2000 or later. Need
1891 to test against a standalone 2k server and see what it
1892 does. A windows 2000 DC includes its own domain in the
1900 /****************************************************************
1901 ****************************************************************/
1903 WERROR _netr_LogonUasLogon(struct pipes_struct *p,
1904 struct netr_LogonUasLogon *r)
1906 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
1907 return WERR_NOT_SUPPORTED;
1910 /****************************************************************
1911 ****************************************************************/
1913 WERROR _netr_LogonUasLogoff(struct pipes_struct *p,
1914 struct netr_LogonUasLogoff *r)
1916 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
1917 return WERR_NOT_SUPPORTED;
1920 /****************************************************************
1921 ****************************************************************/
1923 NTSTATUS _netr_DatabaseDeltas(struct pipes_struct *p,
1924 struct netr_DatabaseDeltas *r)
1926 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
1927 return NT_STATUS_NOT_IMPLEMENTED;
1930 /****************************************************************
1931 ****************************************************************/
1933 NTSTATUS _netr_DatabaseSync(struct pipes_struct *p,
1934 struct netr_DatabaseSync *r)
1936 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
1937 return NT_STATUS_NOT_IMPLEMENTED;
1940 /****************************************************************
1941 ****************************************************************/
1943 NTSTATUS _netr_AccountDeltas(struct pipes_struct *p,
1944 struct netr_AccountDeltas *r)
1946 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
1947 return NT_STATUS_NOT_IMPLEMENTED;
1950 /****************************************************************
1951 ****************************************************************/
1953 NTSTATUS _netr_AccountSync(struct pipes_struct *p,
1954 struct netr_AccountSync *r)
1956 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
1957 return NT_STATUS_NOT_IMPLEMENTED;
1960 /****************************************************************
1961 ****************************************************************/
1963 static bool wb_getdcname(TALLOC_CTX *mem_ctx,
1965 const char **dcname,
1970 struct wbcDomainControllerInfo *dc_info = NULL;
1972 result = wbcLookupDomainController(domain,
1976 case WBC_ERR_SUCCESS:
1978 case WBC_ERR_WINBIND_NOT_AVAILABLE:
1980 case WBC_ERR_DOMAIN_NOT_FOUND:
1981 *werr = WERR_NO_SUCH_DOMAIN;
1984 *werr = WERR_DOMAIN_CONTROLLER_NOT_FOUND;
1988 *dcname = talloc_strdup(mem_ctx, dc_info->dc_name);
1989 wbcFreeMemory(dc_info);
2000 /****************************************************************
2002 ****************************************************************/
2004 WERROR _netr_GetDcName(struct pipes_struct *p,
2005 struct netr_GetDcName *r)
2010 struct netr_DsRGetDCNameInfo *info;
2013 ret = wb_getdcname(p->mem_ctx,
2016 WBC_LOOKUP_DC_IS_FLAT_NAME |
2017 WBC_LOOKUP_DC_RETURN_FLAT_NAME |
2018 WBC_LOOKUP_DC_PDC_REQUIRED,
2024 flags = DS_PDC_REQUIRED | DS_IS_FLAT_NAME | DS_RETURN_FLAT_NAME;
2026 status = dsgetdcname(p->mem_ctx,
2033 if (!NT_STATUS_IS_OK(status)) {
2034 return ntstatus_to_werror(status);
2037 *r->out.dcname = talloc_strdup(p->mem_ctx, info->dc_unc);
2039 if (!*r->out.dcname) {
2046 /****************************************************************
2048 ****************************************************************/
2050 WERROR _netr_GetAnyDCName(struct pipes_struct *p,
2051 struct netr_GetAnyDCName *r)
2056 struct netr_DsRGetDCNameInfo *info;
2059 ret = wb_getdcname(p->mem_ctx,
2062 WBC_LOOKUP_DC_IS_FLAT_NAME |
2063 WBC_LOOKUP_DC_RETURN_FLAT_NAME,
2069 flags = DS_IS_FLAT_NAME | DS_RETURN_FLAT_NAME;
2071 status = dsgetdcname(p->mem_ctx,
2078 if (!NT_STATUS_IS_OK(status)) {
2079 return ntstatus_to_werror(status);
2082 *r->out.dcname = talloc_strdup(p->mem_ctx, info->dc_unc);
2084 if (!*r->out.dcname) {
2091 /****************************************************************
2092 ****************************************************************/
2094 NTSTATUS _netr_DatabaseSync2(struct pipes_struct *p,
2095 struct netr_DatabaseSync2 *r)
2097 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2098 return NT_STATUS_NOT_IMPLEMENTED;
2101 /****************************************************************
2102 ****************************************************************/
2104 NTSTATUS _netr_DatabaseRedo(struct pipes_struct *p,
2105 struct netr_DatabaseRedo *r)
2107 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2108 return NT_STATUS_NOT_IMPLEMENTED;
2111 /****************************************************************
2112 ****************************************************************/
2114 WERROR _netr_DsRGetDCName(struct pipes_struct *p,
2115 struct netr_DsRGetDCName *r)
2117 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2118 return WERR_NOT_SUPPORTED;
2121 /****************************************************************
2122 ****************************************************************/
2124 NTSTATUS _netr_LogonGetCapabilities(struct pipes_struct *p,
2125 struct netr_LogonGetCapabilities *r)
2127 struct netlogon_creds_CredentialState *creds;
2131 status = netr_creds_server_step_check(p, p->mem_ctx,
2132 r->in.computer_name,
2134 r->out.return_authenticator,
2137 if (!NT_STATUS_IS_OK(status)) {
2141 if (r->in.query_level != 1) {
2142 return NT_STATUS_NOT_SUPPORTED;
2145 r->out.capabilities->server_capabilities = creds->negotiate_flags;
2147 return NT_STATUS_OK;
2150 /****************************************************************
2151 ****************************************************************/
2153 WERROR _netr_NETRLOGONSETSERVICEBITS(struct pipes_struct *p,
2154 struct netr_NETRLOGONSETSERVICEBITS *r)
2156 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2157 return WERR_NOT_SUPPORTED;
2160 /****************************************************************
2161 ****************************************************************/
2163 WERROR _netr_LogonGetTrustRid(struct pipes_struct *p,
2164 struct netr_LogonGetTrustRid *r)
2166 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2167 return WERR_NOT_SUPPORTED;
2170 /****************************************************************
2171 ****************************************************************/
2173 WERROR _netr_NETRLOGONCOMPUTESERVERDIGEST(struct pipes_struct *p,
2174 struct netr_NETRLOGONCOMPUTESERVERDIGEST *r)
2176 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2177 return WERR_NOT_SUPPORTED;
2180 /****************************************************************
2181 ****************************************************************/
2183 WERROR _netr_NETRLOGONCOMPUTECLIENTDIGEST(struct pipes_struct *p,
2184 struct netr_NETRLOGONCOMPUTECLIENTDIGEST *r)
2186 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2187 return WERR_NOT_SUPPORTED;
2190 /****************************************************************
2191 ****************************************************************/
2193 WERROR _netr_DsRGetDCNameEx(struct pipes_struct *p,
2194 struct netr_DsRGetDCNameEx *r)
2196 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2197 return WERR_NOT_SUPPORTED;
2200 /****************************************************************
2201 ****************************************************************/
2203 WERROR _netr_DsRGetSiteName(struct pipes_struct *p,
2204 struct netr_DsRGetSiteName *r)
2206 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2207 return WERR_NOT_SUPPORTED;
2210 /****************************************************************
2211 ****************************************************************/
2213 NTSTATUS _netr_LogonGetDomainInfo(struct pipes_struct *p,
2214 struct netr_LogonGetDomainInfo *r)
2216 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2217 return NT_STATUS_NOT_IMPLEMENTED;
2220 /****************************************************************
2221 ****************************************************************/
2223 NTSTATUS _netr_ServerPasswordGet(struct pipes_struct *p,
2224 struct netr_ServerPasswordGet *r)
2226 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2227 return NT_STATUS_NOT_SUPPORTED;
2230 /****************************************************************
2231 ****************************************************************/
2233 WERROR _netr_NETRLOGONSENDTOSAM(struct pipes_struct *p,
2234 struct netr_NETRLOGONSENDTOSAM *r)
2236 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2237 return WERR_NOT_SUPPORTED;
2240 /****************************************************************
2241 ****************************************************************/
2243 WERROR _netr_DsRAddressToSitenamesW(struct pipes_struct *p,
2244 struct netr_DsRAddressToSitenamesW *r)
2246 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2247 return WERR_NOT_SUPPORTED;
2250 /****************************************************************
2251 ****************************************************************/
2253 WERROR _netr_DsRGetDCNameEx2(struct pipes_struct *p,
2254 struct netr_DsRGetDCNameEx2 *r)
2256 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2257 return WERR_NOT_SUPPORTED;
2260 /****************************************************************
2261 ****************************************************************/
2263 WERROR _netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN(struct pipes_struct *p,
2264 struct netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN *r)
2266 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2267 return WERR_NOT_SUPPORTED;
2270 /****************************************************************
2271 ****************************************************************/
2273 WERROR _netr_NetrEnumerateTrustedDomainsEx(struct pipes_struct *p,
2274 struct netr_NetrEnumerateTrustedDomainsEx *r)
2276 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2277 return WERR_NOT_SUPPORTED;
2280 /****************************************************************
2281 ****************************************************************/
2283 WERROR _netr_DsRAddressToSitenamesExW(struct pipes_struct *p,
2284 struct netr_DsRAddressToSitenamesExW *r)
2286 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2287 return WERR_NOT_SUPPORTED;
2290 /****************************************************************
2291 ****************************************************************/
2293 WERROR _netr_DsrGetDcSiteCoverageW(struct pipes_struct *p,
2294 struct netr_DsrGetDcSiteCoverageW *r)
2296 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2297 return WERR_NOT_SUPPORTED;
2300 /****************************************************************
2301 ****************************************************************/
2303 WERROR _netr_DsrEnumerateDomainTrusts(struct pipes_struct *p,
2304 struct netr_DsrEnumerateDomainTrusts *r)
2306 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2307 return WERR_NOT_SUPPORTED;
2310 /****************************************************************
2311 ****************************************************************/
2313 WERROR _netr_DsrDeregisterDNSHostRecords(struct pipes_struct *p,
2314 struct netr_DsrDeregisterDNSHostRecords *r)
2316 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2317 return WERR_NOT_SUPPORTED;
2320 /****************************************************************
2321 ****************************************************************/
2323 NTSTATUS _netr_ServerTrustPasswordsGet(struct pipes_struct *p,
2324 struct netr_ServerTrustPasswordsGet *r)
2326 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2327 return NT_STATUS_NOT_IMPLEMENTED;
2330 /****************************************************************
2331 ****************************************************************/
2333 static NTSTATUS fill_forest_trust_array(TALLOC_CTX *mem_ctx,
2334 struct lsa_ForestTrustInformation *info)
2336 struct lsa_ForestTrustRecord *e;
2337 struct pdb_domain_info *dom_info;
2338 struct lsa_ForestTrustDomainInfo *domain_info;
2339 char **upn_suffixes = NULL;
2340 uint32_t num_suffixes = 0;
2344 dom_info = pdb_get_domain_info(mem_ctx);
2345 if (dom_info == NULL) {
2346 return NT_STATUS_NO_MEMORY;
2352 status = pdb_enum_upn_suffixes(info, &num_suffixes, &upn_suffixes);
2354 if (NT_STATUS_IS_OK(status) && (num_suffixes > 0)) {
2355 info->count += num_suffixes;
2358 info->entries = talloc_array(info, struct lsa_ForestTrustRecord *, info->count);
2359 if (info->entries == NULL) {
2360 return NT_STATUS_NO_MEMORY;
2363 e = talloc(info, struct lsa_ForestTrustRecord);
2365 return NT_STATUS_NO_MEMORY;
2369 e->type = LSA_FOREST_TRUST_TOP_LEVEL_NAME;
2370 e->time = 0; /* so far always 0 in trces. */
2371 e->forest_trust_data.top_level_name.string = talloc_steal(info,
2372 dom_info->dns_forest);
2374 info->entries[0] = e;
2376 if (num_suffixes > 0) {
2377 for (i = 0; i < num_suffixes ; i++) {
2378 e = talloc(info, struct lsa_ForestTrustRecord);
2380 return NT_STATUS_NO_MEMORY;
2384 e->type = LSA_FOREST_TRUST_TOP_LEVEL_NAME;
2385 e->time = 0; /* so far always 0 in traces. */
2386 e->forest_trust_data.top_level_name.string = upn_suffixes[i];
2387 info->entries[1 + i] = e;
2391 e = talloc(info, struct lsa_ForestTrustRecord);
2393 return NT_STATUS_NO_MEMORY;
2396 /* TODO: check if disabled and set flags accordingly */
2398 e->type = LSA_FOREST_TRUST_DOMAIN_INFO;
2399 e->time = 0; /* so far always 0 in traces. */
2401 domain_info = &e->forest_trust_data.domain_info;
2402 domain_info->domain_sid = dom_sid_dup(info, &dom_info->sid);
2404 domain_info->dns_domain_name.string = talloc_steal(info,
2405 dom_info->dns_domain);
2406 domain_info->netbios_domain_name.string = talloc_steal(info,
2409 info->entries[info->count - 1] = e;
2411 return NT_STATUS_OK;
2414 /****************************************************************
2415 ****************************************************************/
2417 WERROR _netr_DsRGetForestTrustInformation(struct pipes_struct *p,
2418 struct netr_DsRGetForestTrustInformation *r)
2421 struct lsa_ForestTrustInformation *info, **info_ptr;
2423 if (!(p->pipe_bound && (p->auth.auth_type != DCERPC_AUTH_TYPE_NONE)
2424 && (p->auth.auth_level != DCERPC_AUTH_LEVEL_NONE))) {
2425 p->fault_state = DCERPC_FAULT_ACCESS_DENIED;
2426 return WERR_ACCESS_DENIED;
2429 if (r->in.flags & (~DS_GFTI_UPDATE_TDO)) {
2430 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2431 return WERR_INVALID_FLAGS;
2434 if ((r->in.flags & DS_GFTI_UPDATE_TDO) && (lp_server_role() != ROLE_DOMAIN_PDC)) {
2435 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2436 return WERR_NERR_NOTPRIMARY;
2439 if ((r->in.trusted_domain_name == NULL) && (r->in.flags & DS_GFTI_UPDATE_TDO)) {
2440 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2441 return WERR_INVALID_PARAMETER;
2444 /* retrieve forest trust information and stop further processing */
2445 if (r->in.trusted_domain_name == NULL) {
2446 info_ptr = talloc(p->mem_ctx, struct lsa_ForestTrustInformation *);
2447 if (info_ptr == NULL) {
2448 p->fault_state = DCERPC_FAULT_CANT_PERFORM;
2451 info = talloc_zero(info_ptr, struct lsa_ForestTrustInformation);
2453 p->fault_state = DCERPC_FAULT_CANT_PERFORM;
2457 /* Fill forest trust information and expand UPN suffixes list */
2458 status = fill_forest_trust_array(p->mem_ctx, info);
2459 if (!NT_STATUS_IS_OK(status)) {
2460 p->fault_state = DCERPC_FAULT_CANT_PERFORM;
2465 r->out.forest_trust_info = info_ptr;
2471 /* TODO: implement remaining parts of DsrGetForestTrustInformation (opnum 43)
2472 * when trusted_domain_name is not NULL */
2474 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2475 return WERR_NOT_SUPPORTED;
2478 /****************************************************************
2479 _netr_GetForestTrustInformation
2480 ****************************************************************/
2482 NTSTATUS _netr_GetForestTrustInformation(struct pipes_struct *p,
2483 struct netr_GetForestTrustInformation *r)
2486 struct netlogon_creds_CredentialState *creds;
2487 struct lsa_ForestTrustInformation *info, **info_ptr;
2489 /* TODO: check server name */
2492 status = netr_creds_server_step_check(p, p->mem_ctx,
2493 r->in.computer_name,
2495 r->out.return_authenticator,
2498 if (!NT_STATUS_IS_OK(status)) {
2502 if ((creds->secure_channel_type != SEC_CHAN_DNS_DOMAIN) &&
2503 (creds->secure_channel_type != SEC_CHAN_DOMAIN)) {
2504 return NT_STATUS_NOT_IMPLEMENTED;
2507 info_ptr = talloc(p->mem_ctx, struct lsa_ForestTrustInformation *);
2509 return NT_STATUS_NO_MEMORY;
2511 info = talloc_zero(info_ptr, struct lsa_ForestTrustInformation);
2513 return NT_STATUS_NO_MEMORY;
2516 /* Fill forest trust information, do expand UPN suffixes list */
2517 status = fill_forest_trust_array(p->mem_ctx, info);
2518 if (!NT_STATUS_IS_OK(status)) {
2523 r->out.forest_trust_info = info_ptr;
2525 return NT_STATUS_OK;
2528 /****************************************************************
2529 ****************************************************************/
2531 static NTSTATUS get_password_from_trustAuth(TALLOC_CTX *mem_ctx,
2532 const DATA_BLOB *trustAuth_blob,
2533 struct netlogon_creds_CredentialState *creds,
2534 struct samr_Password *current_pw_enc,
2535 struct samr_Password *previous_pw_enc)
2537 enum ndr_err_code ndr_err;
2538 struct trustAuthInOutBlob trustAuth;
2540 ndr_err = ndr_pull_struct_blob_all(trustAuth_blob, mem_ctx, &trustAuth,
2541 (ndr_pull_flags_fn_t)ndr_pull_trustAuthInOutBlob);
2542 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2543 return NT_STATUS_UNSUCCESSFUL;
2546 if (trustAuth.count != 0 && trustAuth.current.count != 0 &&
2547 trustAuth.current.array[0].AuthType == TRUST_AUTH_TYPE_CLEAR) {
2548 mdfour(current_pw_enc->hash,
2549 trustAuth.current.array[0].AuthInfo.clear.password,
2550 trustAuth.current.array[0].AuthInfo.clear.size);
2551 netlogon_creds_des_encrypt(creds, current_pw_enc);
2553 return NT_STATUS_UNSUCCESSFUL;
2557 if (trustAuth.previous.count != 0 &&
2558 trustAuth.previous.array[0].AuthType == TRUST_AUTH_TYPE_CLEAR) {
2559 mdfour(previous_pw_enc->hash,
2560 trustAuth.previous.array[0].AuthInfo.clear.password,
2561 trustAuth.previous.array[0].AuthInfo.clear.size);
2562 netlogon_creds_des_encrypt(creds, previous_pw_enc);
2564 ZERO_STRUCTP(previous_pw_enc);
2567 return NT_STATUS_OK;
2570 /****************************************************************
2571 _netr_ServerGetTrustInfo
2572 ****************************************************************/
2574 NTSTATUS _netr_ServerGetTrustInfo(struct pipes_struct *p,
2575 struct netr_ServerGetTrustInfo *r)
2578 struct netlogon_creds_CredentialState *creds;
2580 size_t account_name_last;
2582 struct netr_TrustInfo *trust_info;
2583 struct pdb_trusted_domain *td;
2585 /* TODO: check server name */
2588 status = netr_creds_server_step_check(p, p->mem_ctx,
2589 r->in.computer_name,
2591 r->out.return_authenticator,
2594 if (!NT_STATUS_IS_OK(status)) {
2598 account_name = talloc_strdup(p->mem_ctx, r->in.account_name);
2599 if (account_name == NULL) {
2600 return NT_STATUS_NO_MEMORY;
2603 account_name_last = strlen(account_name);
2604 if (account_name_last == 0) {
2605 return NT_STATUS_INVALID_PARAMETER;
2607 account_name_last--;
2608 if (account_name[account_name_last] == '.') {
2609 account_name[account_name_last] = '\0';
2612 if ((creds->secure_channel_type != SEC_CHAN_DNS_DOMAIN) &&
2613 (creds->secure_channel_type != SEC_CHAN_DOMAIN)) {
2621 account_name_last = strlen(account_name);
2622 if (account_name_last == 0) {
2623 return NT_STATUS_INVALID_PARAMETER;
2625 account_name_last--;
2626 if (account_name[account_name_last] == '$') {
2627 account_name[account_name_last] = '\0';
2630 status = pdb_get_trusted_domain(p->mem_ctx, account_name, &td);
2631 if (!NT_STATUS_IS_OK(status)) {
2635 if (r->out.trust_info != NULL) {
2636 trust_info = talloc_zero(p->mem_ctx, struct netr_TrustInfo);
2637 if (trust_info == NULL) {
2638 return NT_STATUS_NO_MEMORY;
2640 trust_info->count = 1;
2642 trust_info->data = talloc_array(trust_info, uint32_t, 1);
2643 if (trust_info->data == NULL) {
2644 return NT_STATUS_NO_MEMORY;
2646 trust_info->data[0] = td->trust_attributes;
2648 *r->out.trust_info = trust_info;
2651 if (td->trust_auth_incoming.data == NULL) {
2652 return NT_STATUS_INVALID_PARAMETER;
2655 status = get_password_from_trustAuth(p->mem_ctx,
2656 &td->trust_auth_incoming,
2658 r->out.new_owf_password,
2659 r->out.old_owf_password);
2661 if (!NT_STATUS_IS_OK(status)) {
2666 /* TODO: look for machine password */
2667 ZERO_STRUCTP(r->out.new_owf_password);
2668 ZERO_STRUCTP(r->out.old_owf_password);
2670 return NT_STATUS_NOT_IMPLEMENTED;
2673 return NT_STATUS_OK;
2676 /****************************************************************
2677 ****************************************************************/
2679 NTSTATUS _netr_Unused47(struct pipes_struct *p,
2680 struct netr_Unused47 *r)
2682 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2683 return NT_STATUS_NOT_IMPLEMENTED;
2686 /****************************************************************
2687 ****************************************************************/
2689 NTSTATUS _netr_DsrUpdateReadOnlyServerDnsRecords(struct pipes_struct *p,
2690 struct netr_DsrUpdateReadOnlyServerDnsRecords *r)
2692 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2693 return NT_STATUS_NOT_IMPLEMENTED;