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 "../libcli/auth/schannel.h"
29 #include "../librpc/gen_ndr/srv_netlogon.h"
30 #include "../librpc/gen_ndr/srv_samr.h"
31 #include "../librpc/gen_ndr/srv_lsa.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 "librpc/gen_ndr/messaging.h"
36 #include "../lib/crypto/md4.h"
37 #include "rpc_client/init_lsa.h"
38 #include "rpc_server/rpc_ncacn_np.h"
39 #include "../libcli/security/security.h"
40 #include "../libcli/security/dom_sid.h"
41 #include "librpc/gen_ndr/ndr_drsblobs.h"
42 #include "lib/crypto/arcfour.h"
43 #include "lib/crypto/md4.h"
45 extern userdom_struct current_user_info;
48 #define DBGC_CLASS DBGC_RPC_SRV
50 struct netlogon_server_pipe_state {
51 struct netr_Credential client_challenge;
52 struct netr_Credential server_challenge;
55 /*************************************************************************
57 *************************************************************************/
59 WERROR _netr_LogonControl(struct pipes_struct *p,
60 struct netr_LogonControl *r)
62 struct netr_LogonControl2Ex l;
64 switch (r->in.level) {
68 return WERR_NOT_SUPPORTED;
70 return WERR_UNKNOWN_LEVEL;
73 l.in.logon_server = r->in.logon_server;
74 l.in.function_code = r->in.function_code;
75 l.in.level = r->in.level;
77 l.out.query = r->out.query;
79 return _netr_LogonControl2Ex(p, &l);
82 /****************************************************************************
83 Send a message to smbd to do a sam synchronisation
84 **************************************************************************/
86 static void send_sync_message(struct messaging_context *msg_ctx)
88 DEBUG(3, ("sending sam synchronisation message\n"));
89 message_send_all(msg_ctx, MSG_SMB_SAM_SYNC, NULL, 0, NULL);
92 /*************************************************************************
94 *************************************************************************/
96 WERROR _netr_LogonControl2(struct pipes_struct *p,
97 struct netr_LogonControl2 *r)
99 struct netr_LogonControl2Ex l;
101 l.in.logon_server = r->in.logon_server;
102 l.in.function_code = r->in.function_code;
103 l.in.level = r->in.level;
104 l.in.data = r->in.data;
105 l.out.query = r->out.query;
107 return _netr_LogonControl2Ex(p, &l);
110 /*************************************************************************
111 *************************************************************************/
113 static bool wb_change_trust_creds(const char *domain, WERROR *tc_status)
116 struct wbcAuthErrorInfo *error = NULL;
118 result = wbcChangeTrustCredentials(domain, &error);
120 case WBC_ERR_WINBIND_NOT_AVAILABLE:
122 case WBC_ERR_DOMAIN_NOT_FOUND:
123 *tc_status = WERR_NO_SUCH_DOMAIN;
125 case WBC_ERR_SUCCESS:
126 *tc_status = WERR_OK;
132 if (error && error->nt_status != 0) {
133 *tc_status = ntstatus_to_werror(NT_STATUS(error->nt_status));
135 *tc_status = WERR_TRUST_FAILURE;
137 wbcFreeMemory(error);
141 /*************************************************************************
142 *************************************************************************/
144 static bool wb_check_trust_creds(const char *domain, WERROR *tc_status)
147 struct wbcAuthErrorInfo *error = NULL;
149 result = wbcCheckTrustCredentials(domain, &error);
151 case WBC_ERR_WINBIND_NOT_AVAILABLE:
153 case WBC_ERR_DOMAIN_NOT_FOUND:
154 *tc_status = WERR_NO_SUCH_DOMAIN;
156 case WBC_ERR_SUCCESS:
157 *tc_status = WERR_OK;
163 if (error && error->nt_status != 0) {
164 *tc_status = ntstatus_to_werror(NT_STATUS(error->nt_status));
166 *tc_status = WERR_TRUST_FAILURE;
168 wbcFreeMemory(error);
172 /****************************************************************
173 _netr_LogonControl2Ex
174 ****************************************************************/
176 WERROR _netr_LogonControl2Ex(struct pipes_struct *p,
177 struct netr_LogonControl2Ex *r)
179 uint32_t flags = 0x0;
180 WERROR pdc_connection_status = WERR_OK;
181 uint32_t logon_attempts = 0x0;
184 const char *dc_name = NULL;
185 struct sockaddr_storage dc_ss;
186 const char *domain = NULL;
187 struct netr_NETLOGON_INFO_1 *info1;
188 struct netr_NETLOGON_INFO_2 *info2;
189 struct netr_NETLOGON_INFO_3 *info3;
190 struct netr_NETLOGON_INFO_4 *info4;
195 case NDR_NETR_LOGONCONTROL:
196 fn = "_netr_LogonControl";
198 case NDR_NETR_LOGONCONTROL2:
199 fn = "_netr_LogonControl2";
201 case NDR_NETR_LOGONCONTROL2EX:
202 fn = "_netr_LogonControl2Ex";
205 return WERR_INVALID_PARAM;
208 acct_ctrl = p->session_info->info3->base.acct_flags;
210 switch (r->in.function_code) {
211 case NETLOGON_CONTROL_TC_VERIFY:
212 case NETLOGON_CONTROL_CHANGE_PASSWORD:
213 case NETLOGON_CONTROL_REDISCOVER:
214 if ((geteuid() != sec_initial_uid()) &&
215 !nt_token_check_domain_rid(p->session_info->security_token, DOMAIN_RID_ADMINS) &&
216 !nt_token_check_sid(&global_sid_Builtin_Administrators, p->session_info->security_token) &&
217 !(acct_ctrl & (ACB_WSTRUST | ACB_SVRTRUST))) {
218 return WERR_ACCESS_DENIED;
225 tc_status = WERR_NO_SUCH_DOMAIN;
227 switch (r->in.function_code) {
228 case NETLOGON_CONTROL_QUERY:
231 case NETLOGON_CONTROL_REPLICATE:
232 case NETLOGON_CONTROL_SYNCHRONIZE:
233 case NETLOGON_CONTROL_PDC_REPLICATE:
234 case NETLOGON_CONTROL_BACKUP_CHANGE_LOG:
235 case NETLOGON_CONTROL_BREAKPOINT:
236 if (acct_ctrl & ACB_NORMAL) {
237 return WERR_NOT_SUPPORTED;
238 } else if (acct_ctrl & (ACB_WSTRUST | ACB_SVRTRUST)) {
239 return WERR_ACCESS_DENIED;
241 return WERR_ACCESS_DENIED;
243 case NETLOGON_CONTROL_TRUNCATE_LOG:
244 if (acct_ctrl & ACB_NORMAL) {
246 } else if (acct_ctrl & (ACB_WSTRUST | ACB_SVRTRUST)) {
247 return WERR_ACCESS_DENIED;
249 return WERR_ACCESS_DENIED;
252 case NETLOGON_CONTROL_TRANSPORT_NOTIFY:
253 case NETLOGON_CONTROL_FORCE_DNS_REG:
254 case NETLOGON_CONTROL_QUERY_DNS_REG:
255 return WERR_NOT_SUPPORTED;
256 case NETLOGON_CONTROL_FIND_USER:
257 if (!r->in.data || !r->in.data->user) {
258 return WERR_NOT_SUPPORTED;
261 case NETLOGON_CONTROL_SET_DBFLAG:
263 return WERR_NOT_SUPPORTED;
266 case NETLOGON_CONTROL_TC_VERIFY:
267 if (!r->in.data || !r->in.data->domain) {
268 return WERR_NOT_SUPPORTED;
271 if (!wb_check_trust_creds(r->in.data->domain, &tc_status)) {
272 return WERR_NOT_SUPPORTED;
275 case NETLOGON_CONTROL_TC_QUERY:
276 if (!r->in.data || !r->in.data->domain) {
277 return WERR_NOT_SUPPORTED;
280 domain = r->in.data->domain;
282 if (!is_trusted_domain(domain)) {
286 if (!get_dc_name(domain, NULL, dc_name2, &dc_ss)) {
287 tc_status = WERR_NO_LOGON_SERVERS;
291 dc_name = talloc_asprintf(p->mem_ctx, "\\\\%s", dc_name2);
300 case NETLOGON_CONTROL_REDISCOVER:
301 if (!r->in.data || !r->in.data->domain) {
302 return WERR_NOT_SUPPORTED;
305 domain = r->in.data->domain;
307 if (!is_trusted_domain(domain)) {
311 if (!get_dc_name(domain, NULL, dc_name2, &dc_ss)) {
312 tc_status = WERR_NO_LOGON_SERVERS;
316 dc_name = talloc_asprintf(p->mem_ctx, "\\\\%s", dc_name2);
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(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(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(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(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;
387 if (lp_server_role() == ROLE_DOMAIN_BDC) {
388 send_sync_message(p->msg_ctx);
394 /*************************************************************************
395 _netr_NetrEnumerateTrustedDomains
396 *************************************************************************/
398 NTSTATUS _netr_NetrEnumerateTrustedDomains(struct pipes_struct *p,
399 struct netr_NetrEnumerateTrustedDomains *r)
402 NTSTATUS result = NT_STATUS_OK;
405 const char **trusted_domains = NULL;
406 struct lsa_DomainList domain_list;
407 struct dcerpc_binding_handle *h = NULL;
408 struct policy_handle pol;
409 uint32_t enum_ctx = 0;
411 uint32_t max_size = (uint32_t)-1;
413 DEBUG(6,("_netr_NetrEnumerateTrustedDomains: %d\n", __LINE__));
415 status = rpcint_binding_handle(p->mem_ctx,
421 if (!NT_STATUS_IS_OK(status)) {
425 status = dcerpc_lsa_open_policy2(h,
429 LSA_POLICY_VIEW_LOCAL_INFORMATION,
432 if (!NT_STATUS_IS_OK(status)) {
435 if (!NT_STATUS_IS_OK(result)) {
441 /* Lookup list of trusted domains */
442 status = dcerpc_lsa_EnumTrustDom(h,
449 if (!NT_STATUS_IS_OK(status)) {
452 if (!NT_STATUS_IS_OK(result) &&
453 !NT_STATUS_EQUAL(result, NT_STATUS_NO_MORE_ENTRIES) &&
454 !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)) {
459 for (i = 0; i < domain_list.count; i++) {
460 if (!add_string_to_array(p->mem_ctx, domain_list.domains[i].name.string,
461 &trusted_domains, &num_domains)) {
462 status = NT_STATUS_NO_MEMORY;
466 } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
468 if (num_domains > 0) {
469 /* multi sz terminate */
470 trusted_domains = talloc_realloc(p->mem_ctx, trusted_domains, const char *, num_domains + 1);
471 if (trusted_domains == NULL) {
472 status = NT_STATUS_NO_MEMORY;
476 trusted_domains[num_domains] = NULL;
479 if (!push_reg_multi_sz(trusted_domains, &blob, trusted_domains)) {
480 TALLOC_FREE(trusted_domains);
481 status = NT_STATUS_NO_MEMORY;
485 r->out.trusted_domains_blob->data = blob.data;
486 r->out.trusted_domains_blob->length = blob.length;
488 DEBUG(6,("_netr_NetrEnumerateTrustedDomains: %d\n", __LINE__));
490 status = NT_STATUS_OK;
493 if (h && is_valid_policy_hnd(&pol)) {
494 dcerpc_lsa_Close(h, p->mem_ctx, &pol, &result);
500 /*************************************************************************
501 *************************************************************************/
503 static NTSTATUS samr_find_machine_account(TALLOC_CTX *mem_ctx,
504 struct dcerpc_binding_handle *b,
505 const char *account_name,
506 uint32_t access_mask,
507 struct dom_sid2 **domain_sid_p,
508 uint32_t *user_rid_p,
509 struct policy_handle *user_handle)
512 NTSTATUS result = NT_STATUS_OK;
513 struct policy_handle connect_handle, domain_handle;
514 struct lsa_String domain_name;
515 struct dom_sid2 *domain_sid;
516 struct lsa_String names;
517 struct samr_Ids rids;
518 struct samr_Ids types;
521 status = dcerpc_samr_Connect2(b, mem_ctx,
523 SAMR_ACCESS_CONNECT_TO_SERVER |
524 SAMR_ACCESS_ENUM_DOMAINS |
525 SAMR_ACCESS_LOOKUP_DOMAIN,
528 if (!NT_STATUS_IS_OK(status)) {
531 if (!NT_STATUS_IS_OK(result)) {
536 init_lsa_String(&domain_name, get_global_sam_name());
538 status = dcerpc_samr_LookupDomain(b, mem_ctx,
543 if (!NT_STATUS_IS_OK(status)) {
546 if (!NT_STATUS_IS_OK(result)) {
551 status = dcerpc_samr_OpenDomain(b, mem_ctx,
553 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
557 if (!NT_STATUS_IS_OK(status)) {
560 if (!NT_STATUS_IS_OK(result)) {
565 init_lsa_String(&names, account_name);
567 status = dcerpc_samr_LookupNames(b, mem_ctx,
574 if (!NT_STATUS_IS_OK(status)) {
577 if (!NT_STATUS_IS_OK(result)) {
582 if (rids.count != 1) {
583 status = NT_STATUS_NO_SUCH_USER;
586 if (rids.count != types.count) {
587 status = NT_STATUS_INVALID_PARAMETER;
590 if (types.ids[0] != SID_NAME_USER) {
591 status = NT_STATUS_NO_SUCH_USER;
597 status = dcerpc_samr_OpenUser(b, mem_ctx,
603 if (!NT_STATUS_IS_OK(status)) {
606 if (!NT_STATUS_IS_OK(result)) {
616 *domain_sid_p = domain_sid;
620 if (b && is_valid_policy_hnd(&domain_handle)) {
621 dcerpc_samr_Close(b, mem_ctx, &domain_handle, &result);
623 if (b && is_valid_policy_hnd(&connect_handle)) {
624 dcerpc_samr_Close(b, mem_ctx, &connect_handle, &result);
630 /******************************************************************
631 gets a machine password entry. checks access rights of the host.
632 ******************************************************************/
634 static NTSTATUS get_md4pw(struct samr_Password *md4pw, const char *mach_acct,
635 enum netr_SchannelType sec_chan_type,
637 struct messaging_context *msg_ctx)
640 NTSTATUS result = NT_STATUS_OK;
642 struct dcerpc_binding_handle *h = NULL;
643 static struct client_address client_id;
644 struct policy_handle user_handle;
646 struct dom_sid *domain_sid;
648 union samr_UserInfo *info;
649 struct auth_serversupplied_info *session_info;
653 * Currently this code is redundent as we already have a filter
654 * by hostname list. What this code really needs to do is to
655 * get a hosts allowed/hosts denied list from the SAM database
656 * on a per user basis, and make the access decision there.
657 * I will leave this code here for now as a reminder to implement
658 * this at a later date. JRA.
661 if (!allow_access(lp_domain_hostsdeny(), lp_domain_hostsallow(),
663 p->client_id.addr)) {
664 DEBUG(0,("get_md4pw: Workstation %s denied access to domain\n", mach_acct));
669 mem_ctx = talloc_stackframe();
670 if (mem_ctx == NULL) {
671 status = NT_STATUS_NO_MEMORY;
675 status = make_session_info_system(mem_ctx, &session_info);
676 if (!NT_STATUS_IS_OK(status)) {
680 ZERO_STRUCT(user_handle);
682 strlcpy(client_id.addr, "127.0.0.1", sizeof(client_id.addr));
683 client_id.name = "127.0.0.1";
685 status = rpcint_binding_handle(mem_ctx,
691 if (!NT_STATUS_IS_OK(status)) {
696 status = samr_find_machine_account(mem_ctx, h, mach_acct,
697 SEC_FLAG_MAXIMUM_ALLOWED,
698 &domain_sid, &user_rid,
701 if (!NT_STATUS_IS_OK(status)) {
705 status = dcerpc_samr_QueryUserInfo2(h,
708 UserControlInformation,
711 if (!NT_STATUS_IS_OK(status)) {
714 if (!NT_STATUS_IS_OK(result)) {
719 acct_ctrl = info->info16.acct_flags;
721 if (acct_ctrl & ACB_DISABLED) {
722 DEBUG(0,("get_md4pw: Workstation %s: account is disabled\n", mach_acct));
723 status = NT_STATUS_ACCOUNT_DISABLED;
727 if (!(acct_ctrl & ACB_SVRTRUST) &&
728 !(acct_ctrl & ACB_WSTRUST) &&
729 !(acct_ctrl & ACB_DOMTRUST))
731 DEBUG(0,("get_md4pw: Workstation %s: account is not a trust account\n", mach_acct));
732 status = NT_STATUS_NO_TRUST_SAM_ACCOUNT;
736 switch (sec_chan_type) {
738 if (!(acct_ctrl & ACB_SVRTRUST)) {
739 DEBUG(0,("get_md4pw: Workstation %s: BDC secure channel requested "
740 "but not a server trust account\n", mach_acct));
741 status = NT_STATUS_NO_TRUST_SAM_ACCOUNT;
746 if (!(acct_ctrl & ACB_WSTRUST)) {
747 DEBUG(0,("get_md4pw: Workstation %s: WORKSTATION secure channel requested "
748 "but not a workstation trust account\n", mach_acct));
749 status = NT_STATUS_NO_TRUST_SAM_ACCOUNT;
753 case SEC_CHAN_DOMAIN:
754 if (!(acct_ctrl & ACB_DOMTRUST)) {
755 DEBUG(0,("get_md4pw: Workstation %s: DOMAIN secure channel requested "
756 "but not a interdomain trust account\n", mach_acct));
757 status = NT_STATUS_NO_TRUST_SAM_ACCOUNT;
766 status = dcerpc_samr_QueryUserInfo2(h,
769 UserInternal1Information,
773 if (!NT_STATUS_IS_OK(status)) {
776 if (!NT_STATUS_IS_OK(result)) {
781 if (info->info18.nt_pwd_active == 0) {
782 DEBUG(0,("get_md4pw: Workstation %s: account does not have a password\n", mach_acct));
783 status = NT_STATUS_LOGON_FAILURE;
787 /* samr gives out nthash unencrypted (!) */
788 memcpy(md4pw->hash, info->info18.nt_pwd.hash, 16);
790 sid_compose(sid, domain_sid, user_rid);
793 if (h && is_valid_policy_hnd(&user_handle)) {
794 dcerpc_samr_Close(h, mem_ctx, &user_handle, &result);
797 talloc_free(mem_ctx);
802 /*************************************************************************
803 _netr_ServerReqChallenge
804 *************************************************************************/
806 NTSTATUS _netr_ServerReqChallenge(struct pipes_struct *p,
807 struct netr_ServerReqChallenge *r)
809 struct netlogon_server_pipe_state *pipe_state =
810 talloc_get_type(p->private_data, struct netlogon_server_pipe_state);
813 DEBUG(10,("_netr_ServerReqChallenge: new challenge requested. Clearing old state.\n"));
814 talloc_free(pipe_state);
815 p->private_data = NULL;
818 pipe_state = talloc(p, struct netlogon_server_pipe_state);
819 NT_STATUS_HAVE_NO_MEMORY(pipe_state);
821 pipe_state->client_challenge = *r->in.credentials;
823 generate_random_buffer(pipe_state->server_challenge.data,
824 sizeof(pipe_state->server_challenge.data));
826 *r->out.return_credentials = pipe_state->server_challenge;
828 p->private_data = pipe_state;
833 /*************************************************************************
834 _netr_ServerAuthenticate
835 Create the initial credentials.
836 *************************************************************************/
838 NTSTATUS _netr_ServerAuthenticate(struct pipes_struct *p,
839 struct netr_ServerAuthenticate *r)
841 struct netr_ServerAuthenticate3 a;
842 uint32_t negotiate_flags = 0;
845 a.in.server_name = r->in.server_name;
846 a.in.account_name = r->in.account_name;
847 a.in.secure_channel_type = r->in.secure_channel_type;
848 a.in.computer_name = r->in.computer_name;
849 a.in.credentials = r->in.credentials;
850 a.in.negotiate_flags = &negotiate_flags;
852 a.out.return_credentials = r->out.return_credentials;
854 a.out.negotiate_flags = &negotiate_flags;
856 return _netr_ServerAuthenticate3(p, &a);
860 /*************************************************************************
861 _netr_ServerAuthenticate3
862 *************************************************************************/
864 NTSTATUS _netr_ServerAuthenticate3(struct pipes_struct *p,
865 struct netr_ServerAuthenticate3 *r)
869 /* r->in.negotiate_flags is an aliased pointer to r->out.negotiate_flags,
870 * so use a copy to avoid destroying the client values. */
871 uint32_t in_neg_flags = *r->in.negotiate_flags;
874 struct samr_Password mach_pwd;
875 struct netlogon_creds_CredentialState *creds;
876 struct netlogon_server_pipe_state *pipe_state =
877 talloc_get_type(p->private_data, struct netlogon_server_pipe_state);
879 /* According to Microsoft (see bugid #6099)
880 * Windows 7 looks at the negotiate_flags
881 * returned in this structure *even if the
882 * call fails with access denied* ! So in order
883 * to allow Win7 to connect to a Samba NT style
884 * PDC we set the flags before we know if it's
889 srv_flgs = NETLOGON_NEG_ACCOUNT_LOCKOUT |
890 NETLOGON_NEG_PERSISTENT_SAMREPL |
891 NETLOGON_NEG_ARCFOUR |
892 NETLOGON_NEG_PROMOTION_COUNT |
893 NETLOGON_NEG_CHANGELOG_BDC |
894 NETLOGON_NEG_FULL_SYNC_REPL |
895 NETLOGON_NEG_MULTIPLE_SIDS |
897 NETLOGON_NEG_PASSWORD_CHANGE_REFUSAL |
898 NETLOGON_NEG_PASSWORD_SET2;
900 /* Ensure we support strong (128-bit) keys. */
901 if (in_neg_flags & NETLOGON_NEG_STRONG_KEYS) {
902 srv_flgs |= NETLOGON_NEG_STRONG_KEYS;
905 if (lp_server_schannel() != false) {
906 srv_flgs |= NETLOGON_NEG_SCHANNEL;
910 case NDR_NETR_SERVERAUTHENTICATE:
911 fn = "_netr_ServerAuthenticate";
913 case NDR_NETR_SERVERAUTHENTICATE2:
914 fn = "_netr_ServerAuthenticate2";
916 case NDR_NETR_SERVERAUTHENTICATE3:
917 fn = "_netr_ServerAuthenticate3";
920 return NT_STATUS_INTERNAL_ERROR;
923 /* We use this as the key to store the creds: */
924 /* r->in.computer_name */
927 DEBUG(0,("%s: no challenge sent to client %s\n", fn,
928 r->in.computer_name));
929 status = NT_STATUS_ACCESS_DENIED;
933 if ( (lp_server_schannel() == true) &&
934 ((in_neg_flags & NETLOGON_NEG_SCHANNEL) == 0) ) {
936 /* schannel must be used, but client did not offer it. */
937 DEBUG(0,("%s: schannel required but client failed "
938 "to offer it. Client was %s\n",
939 fn, r->in.account_name));
940 status = NT_STATUS_ACCESS_DENIED;
944 status = get_md4pw(&mach_pwd,
946 r->in.secure_channel_type,
948 if (!NT_STATUS_IS_OK(status)) {
949 DEBUG(0,("%s: failed to get machine password for "
951 fn, r->in.account_name, nt_errstr(status) ));
952 /* always return NT_STATUS_ACCESS_DENIED */
953 status = NT_STATUS_ACCESS_DENIED;
957 /* From the client / server challenges and md4 password, generate sess key */
958 /* Check client credentials are valid. */
959 creds = netlogon_creds_server_init(p->mem_ctx,
962 r->in.secure_channel_type,
963 &pipe_state->client_challenge,
964 &pipe_state->server_challenge,
967 r->out.return_credentials,
968 *r->in.negotiate_flags);
970 DEBUG(0,("%s: netlogon_creds_server_check failed. Rejecting auth "
971 "request from client %s machine account %s\n",
972 fn, r->in.computer_name,
973 r->in.account_name));
974 status = NT_STATUS_ACCESS_DENIED;
978 creds->sid = dom_sid_dup(creds, &sid);
980 status = NT_STATUS_NO_MEMORY;
984 /* Store off the state so we can continue after client disconnect. */
986 status = schannel_save_creds_state(p->mem_ctx, lp_private_dir(), creds);
989 if (!NT_STATUS_IS_OK(status)) {
993 sid_peek_rid(&sid, r->out.rid);
995 status = NT_STATUS_OK;
999 *r->out.negotiate_flags = srv_flgs;
1003 /*************************************************************************
1004 _netr_ServerAuthenticate2
1005 *************************************************************************/
1007 NTSTATUS _netr_ServerAuthenticate2(struct pipes_struct *p,
1008 struct netr_ServerAuthenticate2 *r)
1010 struct netr_ServerAuthenticate3 a;
1013 a.in.server_name = r->in.server_name;
1014 a.in.account_name = r->in.account_name;
1015 a.in.secure_channel_type = r->in.secure_channel_type;
1016 a.in.computer_name = r->in.computer_name;
1017 a.in.credentials = r->in.credentials;
1018 a.in.negotiate_flags = r->in.negotiate_flags;
1020 a.out.return_credentials = r->out.return_credentials;
1022 a.out.negotiate_flags = r->out.negotiate_flags;
1024 return _netr_ServerAuthenticate3(p, &a);
1027 /*************************************************************************
1028 * If schannel is required for this call test that it actually is available.
1029 *************************************************************************/
1030 static NTSTATUS schannel_check_required(struct pipe_auth_data *auth_info,
1031 const char *computer_name,
1032 bool integrity, bool privacy)
1034 if (auth_info && auth_info->auth_type == DCERPC_AUTH_TYPE_SCHANNEL) {
1035 if (!privacy && !integrity) {
1036 return NT_STATUS_OK;
1039 if ((!privacy && integrity) &&
1040 auth_info->auth_level == DCERPC_AUTH_LEVEL_INTEGRITY) {
1041 return NT_STATUS_OK;
1044 if ((privacy || integrity) &&
1045 auth_info->auth_level == DCERPC_AUTH_LEVEL_PRIVACY) {
1046 return NT_STATUS_OK;
1050 /* test didn't pass */
1051 DEBUG(0, ("schannel_check_required: [%s] is not using schannel\n",
1054 return NT_STATUS_ACCESS_DENIED;
1057 /*************************************************************************
1058 *************************************************************************/
1060 static NTSTATUS netr_creds_server_step_check(struct pipes_struct *p,
1061 TALLOC_CTX *mem_ctx,
1062 const char *computer_name,
1063 struct netr_Authenticator *received_authenticator,
1064 struct netr_Authenticator *return_authenticator,
1065 struct netlogon_creds_CredentialState **creds_out)
1068 bool schannel_global_required = (lp_server_schannel() == true) ? true:false;
1070 if (schannel_global_required) {
1071 status = schannel_check_required(&p->auth,
1074 if (!NT_STATUS_IS_OK(status)) {
1079 status = schannel_check_creds_state(mem_ctx, lp_private_dir(),
1080 computer_name, received_authenticator,
1081 return_authenticator, creds_out);
1086 /*************************************************************************
1087 *************************************************************************/
1089 static NTSTATUS netr_set_machine_account_password(TALLOC_CTX *mem_ctx,
1090 struct auth_serversupplied_info *session_info,
1091 struct messaging_context *msg_ctx,
1092 const char *account_name,
1093 struct samr_Password *nt_hash)
1096 NTSTATUS result = NT_STATUS_OK;
1097 struct dcerpc_binding_handle *h = NULL;
1098 static struct client_address client_id;
1099 struct policy_handle user_handle;
1101 union samr_UserInfo *info;
1102 struct samr_UserInfo18 info18;
1105 ZERO_STRUCT(user_handle);
1107 strlcpy(client_id.addr, "127.0.0.1", sizeof(client_id.addr));
1108 client_id.name = "127.0.0.1";
1110 status = rpcint_binding_handle(mem_ctx,
1116 if (!NT_STATUS_IS_OK(status)) {
1120 status = samr_find_machine_account(mem_ctx,
1123 SEC_FLAG_MAXIMUM_ALLOWED,
1127 if (!NT_STATUS_IS_OK(status)) {
1131 status = dcerpc_samr_QueryUserInfo2(h,
1134 UserControlInformation,
1137 if (!NT_STATUS_IS_OK(status)) {
1140 if (!NT_STATUS_IS_OK(result)) {
1145 acct_ctrl = info->info16.acct_flags;
1147 if (!(acct_ctrl & ACB_WSTRUST ||
1148 acct_ctrl & ACB_SVRTRUST ||
1149 acct_ctrl & ACB_DOMTRUST)) {
1150 status = NT_STATUS_NO_SUCH_USER;
1154 if (acct_ctrl & ACB_DISABLED) {
1155 status = NT_STATUS_ACCOUNT_DISABLED;
1159 ZERO_STRUCT(info18);
1161 in = data_blob_const(nt_hash->hash, 16);
1162 out = data_blob_talloc_zero(mem_ctx, 16);
1163 sess_crypt_blob(&out, &in, &session_info->user_session_key, true);
1164 memcpy(info18.nt_pwd.hash, out.data, out.length);
1166 info18.nt_pwd_active = true;
1168 info->info18 = info18;
1170 status = dcerpc_samr_SetUserInfo2(h,
1173 UserInternal1Information,
1176 if (!NT_STATUS_IS_OK(status)) {
1179 if (!NT_STATUS_IS_OK(result)) {
1185 if (h && is_valid_policy_hnd(&user_handle)) {
1186 dcerpc_samr_Close(h, mem_ctx, &user_handle, &result);
1192 /*************************************************************************
1193 _netr_ServerPasswordSet
1194 *************************************************************************/
1196 NTSTATUS _netr_ServerPasswordSet(struct pipes_struct *p,
1197 struct netr_ServerPasswordSet *r)
1199 NTSTATUS status = NT_STATUS_OK;
1201 struct netlogon_creds_CredentialState *creds;
1203 DEBUG(5,("_netr_ServerPasswordSet: %d\n", __LINE__));
1206 status = netr_creds_server_step_check(p, p->mem_ctx,
1207 r->in.computer_name,
1209 r->out.return_authenticator,
1213 if (!NT_STATUS_IS_OK(status)) {
1214 DEBUG(2,("_netr_ServerPasswordSet: netlogon_creds_server_step failed. Rejecting auth "
1215 "request from client %s machine account %s\n",
1216 r->in.computer_name, creds->computer_name));
1221 DEBUG(3,("_netr_ServerPasswordSet: Server Password Set by remote machine:[%s] on account [%s]\n",
1222 r->in.computer_name, creds->computer_name));
1224 netlogon_creds_des_decrypt(creds, r->in.new_password);
1226 DEBUG(100,("_netr_ServerPasswordSet: new given value was :\n"));
1227 for(i = 0; i < sizeof(r->in.new_password->hash); i++)
1228 DEBUG(100,("%02X ", r->in.new_password->hash[i]));
1231 status = netr_set_machine_account_password(p->mem_ctx,
1234 creds->account_name,
1235 r->in.new_password);
1239 /****************************************************************
1240 _netr_ServerPasswordSet2
1241 ****************************************************************/
1243 NTSTATUS _netr_ServerPasswordSet2(struct pipes_struct *p,
1244 struct netr_ServerPasswordSet2 *r)
1247 struct netlogon_creds_CredentialState *creds;
1248 DATA_BLOB plaintext;
1249 struct samr_CryptPassword password_buf;
1250 struct samr_Password nt_hash;
1253 status = netr_creds_server_step_check(p, p->mem_ctx,
1254 r->in.computer_name,
1256 r->out.return_authenticator,
1260 if (!NT_STATUS_IS_OK(status)) {
1261 DEBUG(2,("_netr_ServerPasswordSet2: netlogon_creds_server_step "
1262 "failed. Rejecting auth request from client %s machine account %s\n",
1263 r->in.computer_name, creds->computer_name));
1268 memcpy(password_buf.data, r->in.new_password->data, 512);
1269 SIVAL(password_buf.data, 512, r->in.new_password->length);
1270 netlogon_creds_arcfour_crypt(creds, password_buf.data, 516);
1272 if (!extract_pw_from_buffer(p->mem_ctx, password_buf.data, &plaintext)) {
1273 return NT_STATUS_WRONG_PASSWORD;
1276 mdfour(nt_hash.hash, plaintext.data, plaintext.length);
1278 status = netr_set_machine_account_password(p->mem_ctx,
1281 creds->account_name,
1286 /*************************************************************************
1287 _netr_LogonSamLogoff
1288 *************************************************************************/
1290 NTSTATUS _netr_LogonSamLogoff(struct pipes_struct *p,
1291 struct netr_LogonSamLogoff *r)
1294 struct netlogon_creds_CredentialState *creds;
1297 status = netr_creds_server_step_check(p, p->mem_ctx,
1298 r->in.computer_name,
1300 r->out.return_authenticator,
1307 static NTSTATUS _netr_LogonSamLogon_check(const struct netr_LogonSamLogonEx *r)
1309 switch (r->in.logon_level) {
1310 case NetlogonInteractiveInformation:
1311 case NetlogonServiceInformation:
1312 case NetlogonInteractiveTransitiveInformation:
1313 case NetlogonServiceTransitiveInformation:
1314 if (r->in.logon->password == NULL) {
1315 return NT_STATUS_INVALID_PARAMETER;
1318 switch (r->in.validation_level) {
1319 case NetlogonValidationSamInfo: /* 2 */
1320 case NetlogonValidationSamInfo2: /* 3 */
1322 case NetlogonValidationSamInfo4: /* 6 */
1323 if ((pdb_capabilities() & PDB_CAP_ADS) == 0) {
1324 DEBUG(10,("Not adding validation info level 6 "
1325 "without ADS passdb backend\n"));
1326 return NT_STATUS_INVALID_INFO_CLASS;
1330 return NT_STATUS_INVALID_INFO_CLASS;
1334 case NetlogonNetworkInformation:
1335 case NetlogonNetworkTransitiveInformation:
1336 if (r->in.logon->network == NULL) {
1337 return NT_STATUS_INVALID_PARAMETER;
1340 switch (r->in.validation_level) {
1341 case NetlogonValidationSamInfo: /* 2 */
1342 case NetlogonValidationSamInfo2: /* 3 */
1344 case NetlogonValidationSamInfo4: /* 6 */
1345 if ((pdb_capabilities() & PDB_CAP_ADS) == 0) {
1346 DEBUG(10,("Not adding validation info level 6 "
1347 "without ADS passdb backend\n"));
1348 return NT_STATUS_INVALID_INFO_CLASS;
1352 return NT_STATUS_INVALID_INFO_CLASS;
1357 case NetlogonGenericInformation:
1358 if (r->in.logon->generic == NULL) {
1359 return NT_STATUS_INVALID_PARAMETER;
1362 /* we don't support this here */
1363 return NT_STATUS_INVALID_PARAMETER;
1365 switch (r->in.validation_level) {
1366 /* TODO: case NetlogonValidationGenericInfo: 4 */
1367 case NetlogonValidationGenericInfo2: /* 5 */
1370 return NT_STATUS_INVALID_INFO_CLASS;
1376 return NT_STATUS_INVALID_PARAMETER;
1379 return NT_STATUS_OK;
1382 /*************************************************************************
1383 _netr_LogonSamLogon_base
1384 *************************************************************************/
1386 static NTSTATUS _netr_LogonSamLogon_base(struct pipes_struct *p,
1387 struct netr_LogonSamLogonEx *r,
1388 struct netlogon_creds_CredentialState *creds)
1390 NTSTATUS status = NT_STATUS_OK;
1391 union netr_LogonLevel *logon = r->in.logon;
1392 const char *nt_username, *nt_domain, *nt_workstation;
1393 struct auth_usersupplied_info *user_info = NULL;
1394 struct auth_serversupplied_info *server_info = NULL;
1395 struct auth_context *auth_context = NULL;
1396 uint8_t pipe_session_key[16];
1397 bool process_creds = true;
1401 case NDR_NETR_LOGONSAMLOGON:
1402 process_creds = true;
1403 fn = "_netr_LogonSamLogon";
1405 case NDR_NETR_LOGONSAMLOGONWITHFLAGS:
1406 process_creds = true;
1407 fn = "_netr_LogonSamLogonWithFlags";
1409 case NDR_NETR_LOGONSAMLOGONEX:
1410 process_creds = false;
1411 fn = "_netr_LogonSamLogonEx";
1414 return NT_STATUS_INTERNAL_ERROR;
1417 *r->out.authoritative = true; /* authoritative response */
1419 switch (r->in.validation_level) {
1421 r->out.validation->sam2 = TALLOC_ZERO_P(p->mem_ctx, struct netr_SamInfo2);
1422 if (!r->out.validation->sam2) {
1423 return NT_STATUS_NO_MEMORY;
1427 r->out.validation->sam3 = TALLOC_ZERO_P(p->mem_ctx, struct netr_SamInfo3);
1428 if (!r->out.validation->sam3) {
1429 return NT_STATUS_NO_MEMORY;
1433 r->out.validation->sam6 = TALLOC_ZERO_P(p->mem_ctx, struct netr_SamInfo6);
1434 if (!r->out.validation->sam6) {
1435 return NT_STATUS_NO_MEMORY;
1439 DEBUG(0,("%s: bad validation_level value %d.\n",
1440 fn, (int)r->in.validation_level));
1441 return NT_STATUS_INVALID_INFO_CLASS;
1444 switch (r->in.logon_level) {
1445 case NetlogonInteractiveInformation:
1446 case NetlogonServiceInformation:
1447 case NetlogonInteractiveTransitiveInformation:
1448 case NetlogonServiceTransitiveInformation:
1449 nt_username = logon->password->identity_info.account_name.string ?
1450 logon->password->identity_info.account_name.string : "";
1451 nt_domain = logon->password->identity_info.domain_name.string ?
1452 logon->password->identity_info.domain_name.string : "";
1453 nt_workstation = logon->password->identity_info.workstation.string ?
1454 logon->password->identity_info.workstation.string : "";
1456 DEBUG(3,("SAM Logon (Interactive). Domain:[%s]. ", lp_workgroup()));
1458 case NetlogonNetworkInformation:
1459 case NetlogonNetworkTransitiveInformation:
1460 nt_username = logon->network->identity_info.account_name.string ?
1461 logon->network->identity_info.account_name.string : "";
1462 nt_domain = logon->network->identity_info.domain_name.string ?
1463 logon->network->identity_info.domain_name.string : "";
1464 nt_workstation = logon->network->identity_info.workstation.string ?
1465 logon->network->identity_info.workstation.string : "";
1467 DEBUG(3,("SAM Logon (Network). Domain:[%s]. ", lp_workgroup()));
1470 DEBUG(2,("SAM Logon: unsupported switch value\n"));
1471 return NT_STATUS_INVALID_INFO_CLASS;
1474 DEBUG(3,("User:[%s@%s] Requested Domain:[%s]\n", nt_username, nt_workstation, nt_domain));
1475 fstrcpy(current_user_info.smb_name, nt_username);
1476 sub_set_smb_name(nt_username);
1478 DEBUG(5,("Attempting validation level %d for unmapped username %s.\n",
1479 r->in.validation_level, nt_username));
1481 status = NT_STATUS_OK;
1483 switch (r->in.logon_level) {
1484 case NetlogonNetworkInformation:
1485 case NetlogonNetworkTransitiveInformation:
1487 const char *wksname = nt_workstation;
1489 status = make_auth_context_fixed(talloc_tos(), &auth_context,
1490 logon->network->challenge);
1491 if (!NT_STATUS_IS_OK(status)) {
1495 /* For a network logon, the workstation name comes in with two
1496 * backslashes in the front. Strip them if they are there. */
1498 if (*wksname == '\\') wksname++;
1499 if (*wksname == '\\') wksname++;
1501 /* Standard challenge/response authentication */
1502 if (!make_user_info_netlogon_network(&user_info,
1503 nt_username, nt_domain,
1505 logon->network->identity_info.parameter_control,
1506 logon->network->lm.data,
1507 logon->network->lm.length,
1508 logon->network->nt.data,
1509 logon->network->nt.length)) {
1510 status = NT_STATUS_NO_MEMORY;
1514 case NetlogonInteractiveInformation:
1515 case NetlogonServiceInformation:
1516 case NetlogonInteractiveTransitiveInformation:
1517 case NetlogonServiceTransitiveInformation:
1519 /* 'Interactive' authentication, supplies the password in its
1520 MD4 form, encrypted with the session key. We will convert
1521 this to challenge/response for the auth subsystem to chew
1526 status = make_auth_context_subsystem(talloc_tos(),
1528 if (!NT_STATUS_IS_OK(status)) {
1532 auth_context->get_ntlm_challenge(auth_context, chal);
1534 if (!make_user_info_netlogon_interactive(&user_info,
1535 nt_username, nt_domain,
1537 logon->password->identity_info.parameter_control,
1539 logon->password->lmpassword.hash,
1540 logon->password->ntpassword.hash,
1541 creds->session_key)) {
1542 status = NT_STATUS_NO_MEMORY;
1547 DEBUG(2,("SAM Logon: unsupported switch value\n"));
1548 return NT_STATUS_INVALID_INFO_CLASS;
1551 if ( NT_STATUS_IS_OK(status) ) {
1552 status = auth_context->check_ntlm_password(auth_context,
1553 user_info, &server_info);
1556 TALLOC_FREE(auth_context);
1557 free_user_info(&user_info);
1559 DEBUG(5,("%s: check_password returned status %s\n",
1560 fn, nt_errstr(status)));
1562 /* Check account and password */
1564 if (!NT_STATUS_IS_OK(status)) {
1565 /* If we don't know what this domain is, we need to
1566 indicate that we are not authoritative. This
1567 allows the client to decide if it needs to try
1568 a local user. Fix by jpjanosi@us.ibm.com, #2976 */
1569 if ( NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_USER)
1570 && !strequal(nt_domain, get_global_sam_name())
1571 && !is_trusted_domain(nt_domain) )
1572 *r->out.authoritative = false; /* We are not authoritative */
1574 TALLOC_FREE(server_info);
1578 if (server_info->guest) {
1579 /* We don't like guest domain logons... */
1580 DEBUG(5,("%s: Attempted domain logon as GUEST "
1582 TALLOC_FREE(server_info);
1583 return NT_STATUS_LOGON_FAILURE;
1586 /* This is the point at which, if the login was successful, that
1587 the SAM Local Security Authority should record that the user is
1588 logged in to the domain. */
1590 if (process_creds) {
1591 /* Get the pipe session key from the creds. */
1592 memcpy(pipe_session_key, creds->session_key, 16);
1594 struct schannel_state *schannel_auth;
1595 /* Get the pipe session key from the schannel. */
1596 if ((p->auth.auth_type != DCERPC_AUTH_TYPE_SCHANNEL)
1597 || (p->auth.auth_ctx == NULL)) {
1598 return NT_STATUS_INVALID_HANDLE;
1601 schannel_auth = talloc_get_type_abort(p->auth.auth_ctx,
1602 struct schannel_state);
1603 memcpy(pipe_session_key, schannel_auth->creds->session_key, 16);
1606 switch (r->in.validation_level) {
1608 status = serverinfo_to_SamInfo2(server_info, pipe_session_key, 16,
1609 r->out.validation->sam2);
1612 status = serverinfo_to_SamInfo3(server_info, pipe_session_key, 16,
1613 r->out.validation->sam3);
1616 status = serverinfo_to_SamInfo6(server_info, pipe_session_key, 16,
1617 r->out.validation->sam6);
1621 TALLOC_FREE(server_info);
1626 /****************************************************************
1627 _netr_LogonSamLogonWithFlags
1628 ****************************************************************/
1630 NTSTATUS _netr_LogonSamLogonWithFlags(struct pipes_struct *p,
1631 struct netr_LogonSamLogonWithFlags *r)
1634 struct netlogon_creds_CredentialState *creds;
1635 struct netr_LogonSamLogonEx r2;
1636 struct netr_Authenticator return_authenticator;
1638 *r->out.authoritative = true;
1640 r2.in.server_name = r->in.server_name;
1641 r2.in.computer_name = r->in.computer_name;
1642 r2.in.logon_level = r->in.logon_level;
1643 r2.in.logon = r->in.logon;
1644 r2.in.validation_level = r->in.validation_level;
1645 r2.in.flags = r->in.flags;
1646 r2.out.validation = r->out.validation;
1647 r2.out.authoritative = r->out.authoritative;
1648 r2.out.flags = r->out.flags;
1650 status = _netr_LogonSamLogon_check(&r2);
1651 if (!NT_STATUS_IS_OK(status)) {
1656 status = netr_creds_server_step_check(p, p->mem_ctx,
1657 r->in.computer_name,
1659 &return_authenticator,
1662 if (!NT_STATUS_IS_OK(status)) {
1666 status = _netr_LogonSamLogon_base(p, &r2, creds);
1668 *r->out.return_authenticator = return_authenticator;
1673 /*************************************************************************
1675 *************************************************************************/
1677 NTSTATUS _netr_LogonSamLogon(struct pipes_struct *p,
1678 struct netr_LogonSamLogon *r)
1681 struct netr_LogonSamLogonWithFlags r2;
1684 r2.in.server_name = r->in.server_name;
1685 r2.in.computer_name = r->in.computer_name;
1686 r2.in.credential = r->in.credential;
1687 r2.in.logon_level = r->in.logon_level;
1688 r2.in.logon = r->in.logon;
1689 r2.in.validation_level = r->in.validation_level;
1690 r2.in.return_authenticator = r->in.return_authenticator;
1691 r2.in.flags = &flags;
1692 r2.out.validation = r->out.validation;
1693 r2.out.authoritative = r->out.authoritative;
1694 r2.out.flags = &flags;
1695 r2.out.return_authenticator = r->out.return_authenticator;
1697 status = _netr_LogonSamLogonWithFlags(p, &r2);
1702 /*************************************************************************
1703 _netr_LogonSamLogonEx
1704 - no credential chaining. Map into net sam logon.
1705 *************************************************************************/
1707 NTSTATUS _netr_LogonSamLogonEx(struct pipes_struct *p,
1708 struct netr_LogonSamLogonEx *r)
1711 struct netlogon_creds_CredentialState *creds = NULL;
1713 *r->out.authoritative = true;
1715 status = _netr_LogonSamLogon_check(r);
1716 if (!NT_STATUS_IS_OK(status)) {
1720 /* Only allow this if the pipe is protected. */
1721 if (p->auth.auth_type != DCERPC_AUTH_TYPE_SCHANNEL) {
1722 DEBUG(0,("_netr_LogonSamLogonEx: client %s not using schannel for netlogon\n",
1723 get_remote_machine_name() ));
1724 return NT_STATUS_INVALID_PARAMETER;
1728 status = schannel_get_creds_state(p->mem_ctx, lp_private_dir(),
1729 r->in.computer_name, &creds);
1731 if (!NT_STATUS_IS_OK(status)) {
1735 status = _netr_LogonSamLogon_base(p, r, creds);
1741 /*************************************************************************
1743 *************************************************************************/
1744 #if 0 /* JERRY -- not correct */
1745 NTSTATUS _ds_enum_dom_trusts(struct pipes_struct *p, DS_Q_ENUM_DOM_TRUSTS *q_u,
1746 DS_R_ENUM_DOM_TRUSTS *r_u)
1748 NTSTATUS status = NT_STATUS_OK;
1750 /* TODO: According to MSDN, the can only be executed against a
1751 DC or domain member running Windows 2000 or later. Need
1752 to test against a standalone 2k server and see what it
1753 does. A windows 2000 DC includes its own domain in the
1761 /****************************************************************
1762 ****************************************************************/
1764 WERROR _netr_LogonUasLogon(struct pipes_struct *p,
1765 struct netr_LogonUasLogon *r)
1767 p->rng_fault_state = true;
1768 return WERR_NOT_SUPPORTED;
1771 /****************************************************************
1772 ****************************************************************/
1774 WERROR _netr_LogonUasLogoff(struct pipes_struct *p,
1775 struct netr_LogonUasLogoff *r)
1777 p->rng_fault_state = true;
1778 return WERR_NOT_SUPPORTED;
1781 /****************************************************************
1782 ****************************************************************/
1784 NTSTATUS _netr_DatabaseDeltas(struct pipes_struct *p,
1785 struct netr_DatabaseDeltas *r)
1787 p->rng_fault_state = true;
1788 return NT_STATUS_NOT_IMPLEMENTED;
1791 /****************************************************************
1792 ****************************************************************/
1794 NTSTATUS _netr_DatabaseSync(struct pipes_struct *p,
1795 struct netr_DatabaseSync *r)
1797 p->rng_fault_state = true;
1798 return NT_STATUS_NOT_IMPLEMENTED;
1801 /****************************************************************
1802 ****************************************************************/
1804 NTSTATUS _netr_AccountDeltas(struct pipes_struct *p,
1805 struct netr_AccountDeltas *r)
1807 p->rng_fault_state = true;
1808 return NT_STATUS_NOT_IMPLEMENTED;
1811 /****************************************************************
1812 ****************************************************************/
1814 NTSTATUS _netr_AccountSync(struct pipes_struct *p,
1815 struct netr_AccountSync *r)
1817 p->rng_fault_state = true;
1818 return NT_STATUS_NOT_IMPLEMENTED;
1821 /****************************************************************
1822 ****************************************************************/
1824 static bool wb_getdcname(TALLOC_CTX *mem_ctx,
1826 const char **dcname,
1831 struct wbcDomainControllerInfo *dc_info = NULL;
1833 result = wbcLookupDomainController(domain,
1837 case WBC_ERR_SUCCESS:
1839 case WBC_ERR_WINBIND_NOT_AVAILABLE:
1841 case WBC_ERR_DOMAIN_NOT_FOUND:
1842 *werr = WERR_NO_SUCH_DOMAIN;
1845 *werr = WERR_DOMAIN_CONTROLLER_NOT_FOUND;
1849 *dcname = talloc_strdup(mem_ctx, dc_info->dc_name);
1850 wbcFreeMemory(dc_info);
1861 /****************************************************************
1863 ****************************************************************/
1865 WERROR _netr_GetDcName(struct pipes_struct *p,
1866 struct netr_GetDcName *r)
1871 struct netr_DsRGetDCNameInfo *info;
1874 ret = wb_getdcname(p->mem_ctx,
1877 WBC_LOOKUP_DC_IS_FLAT_NAME |
1878 WBC_LOOKUP_DC_RETURN_FLAT_NAME |
1879 WBC_LOOKUP_DC_PDC_REQUIRED,
1885 flags = DS_PDC_REQUIRED | DS_IS_FLAT_NAME | DS_RETURN_FLAT_NAME;
1887 status = dsgetdcname(p->mem_ctx,
1894 if (!NT_STATUS_IS_OK(status)) {
1895 return ntstatus_to_werror(status);
1898 *r->out.dcname = talloc_strdup(p->mem_ctx, info->dc_unc);
1900 if (!*r->out.dcname) {
1907 /****************************************************************
1909 ****************************************************************/
1911 WERROR _netr_GetAnyDCName(struct pipes_struct *p,
1912 struct netr_GetAnyDCName *r)
1917 struct netr_DsRGetDCNameInfo *info;
1920 ret = wb_getdcname(p->mem_ctx,
1923 WBC_LOOKUP_DC_IS_FLAT_NAME |
1924 WBC_LOOKUP_DC_RETURN_FLAT_NAME,
1930 flags = DS_IS_FLAT_NAME | DS_RETURN_FLAT_NAME;
1932 status = dsgetdcname(p->mem_ctx,
1939 if (!NT_STATUS_IS_OK(status)) {
1940 return ntstatus_to_werror(status);
1943 *r->out.dcname = talloc_strdup(p->mem_ctx, info->dc_unc);
1945 if (!*r->out.dcname) {
1952 /****************************************************************
1953 ****************************************************************/
1955 NTSTATUS _netr_DatabaseSync2(struct pipes_struct *p,
1956 struct netr_DatabaseSync2 *r)
1958 p->rng_fault_state = true;
1959 return NT_STATUS_NOT_IMPLEMENTED;
1962 /****************************************************************
1963 ****************************************************************/
1965 NTSTATUS _netr_DatabaseRedo(struct pipes_struct *p,
1966 struct netr_DatabaseRedo *r)
1968 p->rng_fault_state = true;
1969 return NT_STATUS_NOT_IMPLEMENTED;
1972 /****************************************************************
1973 ****************************************************************/
1975 WERROR _netr_DsRGetDCName(struct pipes_struct *p,
1976 struct netr_DsRGetDCName *r)
1978 p->rng_fault_state = true;
1979 return WERR_NOT_SUPPORTED;
1982 /****************************************************************
1983 ****************************************************************/
1985 NTSTATUS _netr_LogonGetCapabilities(struct pipes_struct *p,
1986 struct netr_LogonGetCapabilities *r)
1988 return NT_STATUS_NOT_IMPLEMENTED;
1991 /****************************************************************
1992 ****************************************************************/
1994 WERROR _netr_NETRLOGONSETSERVICEBITS(struct pipes_struct *p,
1995 struct netr_NETRLOGONSETSERVICEBITS *r)
1997 p->rng_fault_state = true;
1998 return WERR_NOT_SUPPORTED;
2001 /****************************************************************
2002 ****************************************************************/
2004 WERROR _netr_LogonGetTrustRid(struct pipes_struct *p,
2005 struct netr_LogonGetTrustRid *r)
2007 p->rng_fault_state = true;
2008 return WERR_NOT_SUPPORTED;
2011 /****************************************************************
2012 ****************************************************************/
2014 WERROR _netr_NETRLOGONCOMPUTESERVERDIGEST(struct pipes_struct *p,
2015 struct netr_NETRLOGONCOMPUTESERVERDIGEST *r)
2017 p->rng_fault_state = true;
2018 return WERR_NOT_SUPPORTED;
2021 /****************************************************************
2022 ****************************************************************/
2024 WERROR _netr_NETRLOGONCOMPUTECLIENTDIGEST(struct pipes_struct *p,
2025 struct netr_NETRLOGONCOMPUTECLIENTDIGEST *r)
2027 p->rng_fault_state = true;
2028 return WERR_NOT_SUPPORTED;
2031 /****************************************************************
2032 ****************************************************************/
2034 WERROR _netr_DsRGetDCNameEx(struct pipes_struct *p,
2035 struct netr_DsRGetDCNameEx *r)
2037 p->rng_fault_state = true;
2038 return WERR_NOT_SUPPORTED;
2041 /****************************************************************
2042 ****************************************************************/
2044 WERROR _netr_DsRGetSiteName(struct pipes_struct *p,
2045 struct netr_DsRGetSiteName *r)
2047 p->rng_fault_state = true;
2048 return WERR_NOT_SUPPORTED;
2051 /****************************************************************
2052 ****************************************************************/
2054 NTSTATUS _netr_LogonGetDomainInfo(struct pipes_struct *p,
2055 struct netr_LogonGetDomainInfo *r)
2057 p->rng_fault_state = true;
2058 return NT_STATUS_NOT_IMPLEMENTED;
2061 /****************************************************************
2062 ****************************************************************/
2064 WERROR _netr_ServerPasswordGet(struct pipes_struct *p,
2065 struct netr_ServerPasswordGet *r)
2067 p->rng_fault_state = true;
2068 return WERR_NOT_SUPPORTED;
2071 /****************************************************************
2072 ****************************************************************/
2074 WERROR _netr_NETRLOGONSENDTOSAM(struct pipes_struct *p,
2075 struct netr_NETRLOGONSENDTOSAM *r)
2077 p->rng_fault_state = true;
2078 return WERR_NOT_SUPPORTED;
2081 /****************************************************************
2082 ****************************************************************/
2084 WERROR _netr_DsRAddressToSitenamesW(struct pipes_struct *p,
2085 struct netr_DsRAddressToSitenamesW *r)
2087 p->rng_fault_state = true;
2088 return WERR_NOT_SUPPORTED;
2091 /****************************************************************
2092 ****************************************************************/
2094 WERROR _netr_DsRGetDCNameEx2(struct pipes_struct *p,
2095 struct netr_DsRGetDCNameEx2 *r)
2097 p->rng_fault_state = true;
2098 return WERR_NOT_SUPPORTED;
2101 /****************************************************************
2102 ****************************************************************/
2104 WERROR _netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN(struct pipes_struct *p,
2105 struct netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN *r)
2107 p->rng_fault_state = true;
2108 return WERR_NOT_SUPPORTED;
2111 /****************************************************************
2112 ****************************************************************/
2114 WERROR _netr_NetrEnumerateTrustedDomainsEx(struct pipes_struct *p,
2115 struct netr_NetrEnumerateTrustedDomainsEx *r)
2117 p->rng_fault_state = true;
2118 return WERR_NOT_SUPPORTED;
2121 /****************************************************************
2122 ****************************************************************/
2124 WERROR _netr_DsRAddressToSitenamesExW(struct pipes_struct *p,
2125 struct netr_DsRAddressToSitenamesExW *r)
2127 p->rng_fault_state = true;
2128 return WERR_NOT_SUPPORTED;
2131 /****************************************************************
2132 ****************************************************************/
2134 WERROR _netr_DsrGetDcSiteCoverageW(struct pipes_struct *p,
2135 struct netr_DsrGetDcSiteCoverageW *r)
2137 p->rng_fault_state = true;
2138 return WERR_NOT_SUPPORTED;
2141 /****************************************************************
2142 ****************************************************************/
2144 WERROR _netr_DsrEnumerateDomainTrusts(struct pipes_struct *p,
2145 struct netr_DsrEnumerateDomainTrusts *r)
2147 p->rng_fault_state = true;
2148 return WERR_NOT_SUPPORTED;
2151 /****************************************************************
2152 ****************************************************************/
2154 WERROR _netr_DsrDeregisterDNSHostRecords(struct pipes_struct *p,
2155 struct netr_DsrDeregisterDNSHostRecords *r)
2157 p->rng_fault_state = true;
2158 return WERR_NOT_SUPPORTED;
2161 /****************************************************************
2162 ****************************************************************/
2164 NTSTATUS _netr_ServerTrustPasswordsGet(struct pipes_struct *p,
2165 struct netr_ServerTrustPasswordsGet *r)
2167 p->rng_fault_state = true;
2168 return NT_STATUS_NOT_IMPLEMENTED;
2171 /****************************************************************
2172 ****************************************************************/
2174 WERROR _netr_DsRGetForestTrustInformation(struct pipes_struct *p,
2175 struct netr_DsRGetForestTrustInformation *r)
2177 p->rng_fault_state = true;
2178 return WERR_NOT_SUPPORTED;
2181 /****************************************************************
2182 ****************************************************************/
2184 static NTSTATUS fill_forest_trust_array(TALLOC_CTX *mem_ctx,
2185 struct lsa_ForestTrustInformation *info)
2187 struct lsa_ForestTrustRecord *e;
2188 struct pdb_domain_info *dom_info;
2189 struct lsa_ForestTrustDomainInfo *domain_info;
2191 dom_info = pdb_get_domain_info(mem_ctx);
2192 if (dom_info == NULL) {
2193 return NT_STATUS_NO_MEMORY;
2197 info->entries = talloc_array(info, struct lsa_ForestTrustRecord *, 2);
2198 if (info->entries == NULL) {
2199 return NT_STATUS_NO_MEMORY;
2202 e = talloc(info, struct lsa_ForestTrustRecord);
2204 return NT_STATUS_NO_MEMORY;
2208 e->type = LSA_FOREST_TRUST_TOP_LEVEL_NAME;
2209 e->time = 0; /* so far always 0 in trces. */
2210 e->forest_trust_data.top_level_name.string = talloc_steal(info,
2211 dom_info->dns_forest);
2213 info->entries[0] = e;
2215 e = talloc(info, struct lsa_ForestTrustRecord);
2217 return NT_STATUS_NO_MEMORY;
2220 /* TODO: check if disabled and set flags accordingly */
2222 e->type = LSA_FOREST_TRUST_DOMAIN_INFO;
2223 e->time = 0; /* so far always 0 in traces. */
2225 domain_info = &e->forest_trust_data.domain_info;
2226 domain_info->domain_sid = dom_sid_dup(info, &dom_info->sid);
2228 domain_info->dns_domain_name.string = talloc_steal(info,
2229 dom_info->dns_domain);
2230 domain_info->netbios_domain_name.string = talloc_steal(info,
2233 info->entries[1] = e;
2235 return NT_STATUS_OK;
2238 /****************************************************************
2239 _netr_GetForestTrustInformation
2240 ****************************************************************/
2242 NTSTATUS _netr_GetForestTrustInformation(struct pipes_struct *p,
2243 struct netr_GetForestTrustInformation *r)
2246 struct netlogon_creds_CredentialState *creds;
2247 struct lsa_ForestTrustInformation *info, **info_ptr;
2249 /* TODO: check server name */
2251 status = schannel_check_creds_state(p->mem_ctx, lp_private_dir(),
2252 r->in.computer_name,
2254 r->out.return_authenticator,
2256 if (!NT_STATUS_IS_OK(status)) {
2260 if ((creds->secure_channel_type != SEC_CHAN_DNS_DOMAIN) &&
2261 (creds->secure_channel_type != SEC_CHAN_DOMAIN)) {
2262 return NT_STATUS_NOT_IMPLEMENTED;
2265 info_ptr = talloc(p->mem_ctx, struct lsa_ForestTrustInformation *);
2267 return NT_STATUS_NO_MEMORY;
2269 info = talloc_zero(info_ptr, struct lsa_ForestTrustInformation);
2271 return NT_STATUS_NO_MEMORY;
2274 status = fill_forest_trust_array(p->mem_ctx, info);
2275 if (!NT_STATUS_IS_OK(status)) {
2280 r->out.forest_trust_info = info_ptr;
2282 return NT_STATUS_OK;
2285 /****************************************************************
2286 ****************************************************************/
2288 static NTSTATUS get_password_from_trustAuth(TALLOC_CTX *mem_ctx,
2289 const DATA_BLOB *trustAuth_blob,
2290 const DATA_BLOB *session_key,
2291 struct samr_Password *current_pw_enc,
2292 struct samr_Password *previous_pw_enc)
2294 enum ndr_err_code ndr_err;
2295 struct trustAuthInOutBlob trustAuth;
2297 ndr_err = ndr_pull_struct_blob_all(trustAuth_blob, mem_ctx, &trustAuth,
2298 (ndr_pull_flags_fn_t)ndr_pull_trustAuthInOutBlob);
2299 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2300 return NT_STATUS_UNSUCCESSFUL;
2304 if (trustAuth.count != 0 && trustAuth.current.count != 0 &&
2305 trustAuth.current.array[0].AuthType == TRUST_AUTH_TYPE_CLEAR) {
2306 mdfour(previous_pw_enc->hash,
2307 trustAuth.current.array[0].AuthInfo.clear.password,
2308 trustAuth.current.array[0].AuthInfo.clear.size);
2310 return NT_STATUS_UNSUCCESSFUL;
2313 arcfour_crypt_blob(current_pw_enc->hash, sizeof(current_pw_enc->hash),
2316 if (trustAuth.previous.count != 0 &&
2317 trustAuth.previous.array[0].AuthType == TRUST_AUTH_TYPE_CLEAR) {
2318 mdfour(previous_pw_enc->hash,
2319 trustAuth.previous.array[0].AuthInfo.clear.password,
2320 trustAuth.previous.array[0].AuthInfo.clear.size);
2322 mdfour(previous_pw_enc->hash, NULL, 0);
2324 arcfour_crypt_blob(previous_pw_enc->hash, sizeof(previous_pw_enc->hash),
2327 return NT_STATUS_OK;
2330 /****************************************************************
2331 _netr_ServerGetTrustInfo
2332 ****************************************************************/
2334 NTSTATUS _netr_ServerGetTrustInfo(struct pipes_struct *p,
2335 struct netr_ServerGetTrustInfo *r)
2338 struct netlogon_creds_CredentialState *creds;
2340 size_t account_name_last;
2342 struct netr_TrustInfo *trust_info;
2343 struct pdb_trusted_domain *td;
2344 DATA_BLOB trustAuth_blob;
2345 struct samr_Password *new_owf_enc;
2346 struct samr_Password *old_owf_enc;
2347 DATA_BLOB session_key;
2349 /* TODO: check server name */
2351 status = schannel_check_creds_state(p->mem_ctx, lp_private_dir(),
2352 r->in.computer_name,
2354 r->out.return_authenticator,
2356 if (!NT_STATUS_IS_OK(status)) {
2360 account_name = talloc_strdup(p->mem_ctx, r->in.account_name);
2361 if (account_name == NULL) {
2362 return NT_STATUS_NO_MEMORY;
2365 account_name_last = strlen(account_name);
2366 if (account_name_last == 0) {
2367 return NT_STATUS_INVALID_PARAMETER;
2369 account_name_last--;
2370 if (account_name[account_name_last] == '.') {
2371 account_name[account_name_last] = '\0';
2374 if ((creds->secure_channel_type != SEC_CHAN_DNS_DOMAIN) &&
2375 (creds->secure_channel_type != SEC_CHAN_DOMAIN)) {
2383 account_name_last = strlen(account_name);
2384 if (account_name_last == 0) {
2385 return NT_STATUS_INVALID_PARAMETER;
2387 account_name_last--;
2388 if (account_name[account_name_last] == '$') {
2389 account_name[account_name_last] = '\0';
2392 status = pdb_get_trusted_domain(p->mem_ctx, account_name, &td);
2393 if (!NT_STATUS_IS_OK(status)) {
2397 if (r->out.trust_info != NULL) {
2398 trust_info = talloc_zero(p->mem_ctx, struct netr_TrustInfo);
2399 if (trust_info == NULL) {
2400 return NT_STATUS_NO_MEMORY;
2402 trust_info->count = 1;
2404 trust_info->data = talloc_array(trust_info, uint32_t, 1);
2405 if (trust_info->data == NULL) {
2406 return NT_STATUS_NO_MEMORY;
2408 trust_info->data[0] = td->trust_attributes;
2410 *r->out.trust_info = trust_info;
2413 new_owf_enc = talloc_zero(p->mem_ctx, struct samr_Password);
2414 old_owf_enc = talloc_zero(p->mem_ctx, struct samr_Password);
2415 if (new_owf_enc == NULL || old_owf_enc == NULL) {
2416 return NT_STATUS_NO_MEMORY;
2419 /* TODO: which trustAuth shall we use if we have in/out trust or do they have to
2421 if (td->trust_direction & NETR_TRUST_FLAG_INBOUND) {
2422 trustAuth_blob = td->trust_auth_incoming;
2423 } else if (td->trust_direction & NETR_TRUST_FLAG_OUTBOUND) {
2424 trustAuth_blob = td->trust_auth_outgoing;
2427 session_key.data = creds->session_key;
2428 session_key.length = sizeof(creds->session_key);
2429 status = get_password_from_trustAuth(p->mem_ctx, &trustAuth_blob,
2431 new_owf_enc, old_owf_enc);
2433 if (!NT_STATUS_IS_OK(status)) {
2437 r->out.new_owf_password = new_owf_enc;
2438 r->out.old_owf_password = old_owf_enc;
2440 /* TODO: look for machine password */
2441 r->out.new_owf_password = NULL;
2442 r->out.old_owf_password = NULL;
2444 return NT_STATUS_NOT_IMPLEMENTED;
2447 return NT_STATUS_OK;
2450 /****************************************************************
2451 ****************************************************************/
2453 NTSTATUS _netr_Unused47(struct pipes_struct *p,
2454 struct netr_Unused47 *r)
2456 p->rng_fault_state = true;
2457 return NT_STATUS_NOT_IMPLEMENTED;
2460 /****************************************************************
2461 ****************************************************************/
2463 NTSTATUS _netr_DsrUpdateReadOnlyServerDnsRecords(struct pipes_struct *p,
2464 struct netr_DsrUpdateReadOnlyServerDnsRecords *r)
2466 p->rng_fault_state = true;
2467 return NT_STATUS_NOT_IMPLEMENTED;