2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-1997,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
6 * Copyright (C) Paul Ashton 1997.
7 * Copyright (C) Jeremy Allison 1998-2001.
8 * Copyright (C) Andrew Bartlett 2001.
9 * Copyright (C) Guenther Deschner 2008-2009.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <http://www.gnu.org/licenses/>.
25 /* This is the implementation of the netlogon pipe. */
28 #include "system/passwd.h" /* uid_wrapper */
30 #include "../libcli/auth/schannel.h"
31 #include "../librpc/gen_ndr/srv_netlogon.h"
32 #include "../librpc/gen_ndr/ndr_samr_c.h"
33 #include "../librpc/gen_ndr/ndr_lsa_c.h"
34 #include "rpc_client/cli_lsarpc.h"
35 #include "rpc_client/init_lsa.h"
36 #include "rpc_server/rpc_ncacn_np.h"
37 #include "../libcli/security/security.h"
38 #include "../libcli/security/dom_sid.h"
39 #include "librpc/gen_ndr/ndr_drsblobs.h"
40 #include "lib/crypto/arcfour.h"
41 #include "lib/crypto/md4.h"
42 #include "nsswitch/libwbclient/wbclient.h"
43 #include "../libcli/registry/util_reg.h"
47 #include "../lib/tsocket/tsocket.h"
48 #include "lib/param/param.h"
50 extern userdom_struct current_user_info;
53 #define DBGC_CLASS DBGC_RPC_SRV
55 struct netlogon_server_pipe_state {
56 struct netr_Credential client_challenge;
57 struct netr_Credential server_challenge;
60 /*************************************************************************
62 *************************************************************************/
64 WERROR _netr_LogonControl(struct pipes_struct *p,
65 struct netr_LogonControl *r)
67 struct netr_LogonControl2Ex l;
69 switch (r->in.level) {
73 return WERR_NOT_SUPPORTED;
75 return WERR_UNKNOWN_LEVEL;
78 l.in.logon_server = r->in.logon_server;
79 l.in.function_code = r->in.function_code;
80 l.in.level = r->in.level;
82 l.out.query = r->out.query;
84 return _netr_LogonControl2Ex(p, &l);
87 /****************************************************************************
88 Send a message to smbd to do a sam synchronisation
89 **************************************************************************/
91 static void send_sync_message(struct messaging_context *msg_ctx)
93 DEBUG(3, ("sending sam synchronisation message\n"));
94 message_send_all(msg_ctx, MSG_SMB_SAM_SYNC, NULL, 0, NULL);
97 /*************************************************************************
99 *************************************************************************/
101 WERROR _netr_LogonControl2(struct pipes_struct *p,
102 struct netr_LogonControl2 *r)
104 struct netr_LogonControl2Ex l;
106 l.in.logon_server = r->in.logon_server;
107 l.in.function_code = r->in.function_code;
108 l.in.level = r->in.level;
109 l.in.data = r->in.data;
110 l.out.query = r->out.query;
112 return _netr_LogonControl2Ex(p, &l);
115 /*************************************************************************
116 *************************************************************************/
118 static bool wb_change_trust_creds(const char *domain, WERROR *tc_status)
121 struct wbcAuthErrorInfo *error = NULL;
123 result = wbcChangeTrustCredentials(domain, &error);
125 case WBC_ERR_WINBIND_NOT_AVAILABLE:
127 case WBC_ERR_DOMAIN_NOT_FOUND:
128 *tc_status = WERR_NO_SUCH_DOMAIN;
130 case WBC_ERR_SUCCESS:
131 *tc_status = WERR_OK;
137 if (error && error->nt_status != 0) {
138 *tc_status = ntstatus_to_werror(NT_STATUS(error->nt_status));
140 *tc_status = WERR_TRUST_FAILURE;
142 wbcFreeMemory(error);
146 /*************************************************************************
147 *************************************************************************/
149 static bool wb_check_trust_creds(const char *domain, WERROR *tc_status)
152 struct wbcAuthErrorInfo *error = NULL;
154 result = wbcCheckTrustCredentials(domain, &error);
156 case WBC_ERR_WINBIND_NOT_AVAILABLE:
158 case WBC_ERR_DOMAIN_NOT_FOUND:
159 *tc_status = WERR_NO_SUCH_DOMAIN;
161 case WBC_ERR_SUCCESS:
162 *tc_status = WERR_OK;
168 if (error && error->nt_status != 0) {
169 *tc_status = ntstatus_to_werror(NT_STATUS(error->nt_status));
171 *tc_status = WERR_TRUST_FAILURE;
173 wbcFreeMemory(error);
177 /****************************************************************
178 _netr_LogonControl2Ex
179 ****************************************************************/
181 WERROR _netr_LogonControl2Ex(struct pipes_struct *p,
182 struct netr_LogonControl2Ex *r)
184 uint32_t flags = 0x0;
185 WERROR pdc_connection_status = WERR_OK;
186 uint32_t logon_attempts = 0x0;
189 const char *dc_name = NULL;
190 struct sockaddr_storage dc_ss;
191 const char *domain = NULL;
192 struct netr_NETLOGON_INFO_1 *info1;
193 struct netr_NETLOGON_INFO_2 *info2;
194 struct netr_NETLOGON_INFO_3 *info3;
195 struct netr_NETLOGON_INFO_4 *info4;
200 case NDR_NETR_LOGONCONTROL:
201 fn = "_netr_LogonControl";
203 case NDR_NETR_LOGONCONTROL2:
204 fn = "_netr_LogonControl2";
206 case NDR_NETR_LOGONCONTROL2EX:
207 fn = "_netr_LogonControl2Ex";
210 return WERR_INVALID_PARAM;
213 acct_ctrl = p->session_info->info->acct_flags;
215 switch (r->in.function_code) {
216 case NETLOGON_CONTROL_TC_VERIFY:
217 case NETLOGON_CONTROL_CHANGE_PASSWORD:
218 case NETLOGON_CONTROL_REDISCOVER:
219 if ((geteuid() != sec_initial_uid()) &&
220 !nt_token_check_domain_rid(p->session_info->security_token, DOMAIN_RID_ADMINS) &&
221 !nt_token_check_sid(&global_sid_Builtin_Administrators, p->session_info->security_token) &&
222 !(acct_ctrl & (ACB_WSTRUST | ACB_SVRTRUST))) {
223 return WERR_ACCESS_DENIED;
230 tc_status = WERR_NO_SUCH_DOMAIN;
232 switch (r->in.function_code) {
233 case NETLOGON_CONTROL_QUERY:
236 case NETLOGON_CONTROL_REPLICATE:
237 case NETLOGON_CONTROL_SYNCHRONIZE:
238 case NETLOGON_CONTROL_PDC_REPLICATE:
239 case NETLOGON_CONTROL_BACKUP_CHANGE_LOG:
240 case NETLOGON_CONTROL_BREAKPOINT:
241 if (acct_ctrl & ACB_NORMAL) {
242 return WERR_NOT_SUPPORTED;
243 } else if (acct_ctrl & (ACB_WSTRUST | ACB_SVRTRUST)) {
244 return WERR_ACCESS_DENIED;
246 return WERR_ACCESS_DENIED;
248 case NETLOGON_CONTROL_TRUNCATE_LOG:
249 if (acct_ctrl & ACB_NORMAL) {
251 } else if (acct_ctrl & (ACB_WSTRUST | ACB_SVRTRUST)) {
252 return WERR_ACCESS_DENIED;
254 return WERR_ACCESS_DENIED;
257 case NETLOGON_CONTROL_TRANSPORT_NOTIFY:
258 case NETLOGON_CONTROL_FORCE_DNS_REG:
259 case NETLOGON_CONTROL_QUERY_DNS_REG:
260 return WERR_NOT_SUPPORTED;
261 case NETLOGON_CONTROL_FIND_USER:
262 if (!r->in.data || !r->in.data->user) {
263 return WERR_NOT_SUPPORTED;
266 case NETLOGON_CONTROL_SET_DBFLAG:
268 return WERR_NOT_SUPPORTED;
271 case NETLOGON_CONTROL_TC_VERIFY:
272 if (!r->in.data || !r->in.data->domain) {
273 return WERR_NOT_SUPPORTED;
276 if (!wb_check_trust_creds(r->in.data->domain, &tc_status)) {
277 return WERR_NOT_SUPPORTED;
280 case NETLOGON_CONTROL_TC_QUERY:
281 if (!r->in.data || !r->in.data->domain) {
282 return WERR_NOT_SUPPORTED;
285 domain = r->in.data->domain;
287 if (!is_trusted_domain(domain)) {
291 if (!get_dc_name(domain, NULL, dc_name2, &dc_ss)) {
292 tc_status = WERR_NO_LOGON_SERVERS;
296 dc_name = talloc_asprintf(p->mem_ctx, "\\\\%s", dc_name2);
305 case NETLOGON_CONTROL_REDISCOVER:
306 if (!r->in.data || !r->in.data->domain) {
307 return WERR_NOT_SUPPORTED;
310 domain = r->in.data->domain;
312 if (!is_trusted_domain(domain)) {
316 if (!get_dc_name(domain, NULL, dc_name2, &dc_ss)) {
317 tc_status = WERR_NO_LOGON_SERVERS;
321 dc_name = talloc_asprintf(p->mem_ctx, "\\\\%s", dc_name2);
330 case NETLOGON_CONTROL_CHANGE_PASSWORD:
331 if (!r->in.data || !r->in.data->domain) {
332 return WERR_NOT_SUPPORTED;
335 if (!wb_change_trust_creds(r->in.data->domain, &tc_status)) {
336 return WERR_NOT_SUPPORTED;
341 /* no idea what this should be */
342 DEBUG(0,("%s: unimplemented function level [%d]\n",
343 fn, r->in.function_code));
344 return WERR_UNKNOWN_LEVEL;
347 /* prepare the response */
349 switch (r->in.level) {
351 info1 = talloc_zero(p->mem_ctx, struct netr_NETLOGON_INFO_1);
352 W_ERROR_HAVE_NO_MEMORY(info1);
354 info1->flags = flags;
355 info1->pdc_connection_status = pdc_connection_status;
357 r->out.query->info1 = info1;
360 info2 = talloc_zero(p->mem_ctx, struct netr_NETLOGON_INFO_2);
361 W_ERROR_HAVE_NO_MEMORY(info2);
363 info2->flags = flags;
364 info2->pdc_connection_status = pdc_connection_status;
365 info2->trusted_dc_name = dc_name;
366 info2->tc_connection_status = tc_status;
368 r->out.query->info2 = info2;
371 info3 = talloc_zero(p->mem_ctx, struct netr_NETLOGON_INFO_3);
372 W_ERROR_HAVE_NO_MEMORY(info3);
374 info3->flags = flags;
375 info3->logon_attempts = logon_attempts;
377 r->out.query->info3 = info3;
380 info4 = talloc_zero(p->mem_ctx, struct netr_NETLOGON_INFO_4);
381 W_ERROR_HAVE_NO_MEMORY(info4);
383 info4->trusted_dc_name = dc_name;
384 info4->trusted_domain_name = r->in.data->domain;
386 r->out.query->info4 = info4;
389 return WERR_UNKNOWN_LEVEL;
392 if (lp_server_role() == ROLE_DOMAIN_BDC) {
393 send_sync_message(p->msg_ctx);
399 /*************************************************************************
400 _netr_NetrEnumerateTrustedDomains
401 *************************************************************************/
403 NTSTATUS _netr_NetrEnumerateTrustedDomains(struct pipes_struct *p,
404 struct netr_NetrEnumerateTrustedDomains *r)
407 NTSTATUS result = NT_STATUS_OK;
410 const char **trusted_domains = NULL;
411 struct lsa_DomainList domain_list;
412 struct dcerpc_binding_handle *h = NULL;
413 struct policy_handle pol;
414 uint32_t enum_ctx = 0;
416 uint32_t max_size = (uint32_t)-1;
418 DEBUG(6,("_netr_NetrEnumerateTrustedDomains: %d\n", __LINE__));
420 status = rpcint_binding_handle(p->mem_ctx,
426 if (!NT_STATUS_IS_OK(status)) {
430 status = dcerpc_lsa_open_policy2(h,
434 LSA_POLICY_VIEW_LOCAL_INFORMATION,
437 if (!NT_STATUS_IS_OK(status)) {
440 if (!NT_STATUS_IS_OK(result)) {
446 /* Lookup list of trusted domains */
447 status = dcerpc_lsa_EnumTrustDom(h,
454 if (!NT_STATUS_IS_OK(status)) {
457 if (!NT_STATUS_IS_OK(result) &&
458 !NT_STATUS_EQUAL(result, NT_STATUS_NO_MORE_ENTRIES) &&
459 !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)) {
464 for (i = 0; i < domain_list.count; i++) {
465 if (!add_string_to_array(p->mem_ctx, domain_list.domains[i].name.string,
466 &trusted_domains, &num_domains)) {
467 status = NT_STATUS_NO_MEMORY;
471 } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
473 if (num_domains > 0) {
474 /* multi sz terminate */
475 trusted_domains = talloc_realloc(p->mem_ctx, trusted_domains, const char *, num_domains + 1);
476 if (trusted_domains == NULL) {
477 status = NT_STATUS_NO_MEMORY;
481 trusted_domains[num_domains] = NULL;
484 if (!push_reg_multi_sz(trusted_domains, &blob, trusted_domains)) {
485 TALLOC_FREE(trusted_domains);
486 status = NT_STATUS_NO_MEMORY;
490 r->out.trusted_domains_blob->data = blob.data;
491 r->out.trusted_domains_blob->length = blob.length;
493 DEBUG(6,("_netr_NetrEnumerateTrustedDomains: %d\n", __LINE__));
495 status = NT_STATUS_OK;
498 if (is_valid_policy_hnd(&pol)) {
499 dcerpc_lsa_Close(h, p->mem_ctx, &pol, &result);
505 /*************************************************************************
506 *************************************************************************/
508 static NTSTATUS samr_find_machine_account(TALLOC_CTX *mem_ctx,
509 struct dcerpc_binding_handle *b,
510 const char *account_name,
511 uint32_t access_mask,
512 struct dom_sid2 **domain_sid_p,
513 uint32_t *user_rid_p,
514 struct policy_handle *user_handle)
517 NTSTATUS result = NT_STATUS_OK;
518 struct policy_handle connect_handle, domain_handle;
519 struct lsa_String domain_name;
520 struct dom_sid2 *domain_sid;
521 struct lsa_String names;
522 struct samr_Ids rids;
523 struct samr_Ids types;
526 status = dcerpc_samr_Connect2(b, mem_ctx,
528 SAMR_ACCESS_CONNECT_TO_SERVER |
529 SAMR_ACCESS_ENUM_DOMAINS |
530 SAMR_ACCESS_LOOKUP_DOMAIN,
533 if (!NT_STATUS_IS_OK(status)) {
536 if (!NT_STATUS_IS_OK(result)) {
541 init_lsa_String(&domain_name, get_global_sam_name());
543 status = dcerpc_samr_LookupDomain(b, mem_ctx,
548 if (!NT_STATUS_IS_OK(status)) {
551 if (!NT_STATUS_IS_OK(result)) {
556 status = dcerpc_samr_OpenDomain(b, mem_ctx,
558 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
562 if (!NT_STATUS_IS_OK(status)) {
565 if (!NT_STATUS_IS_OK(result)) {
570 init_lsa_String(&names, account_name);
572 status = dcerpc_samr_LookupNames(b, mem_ctx,
579 if (!NT_STATUS_IS_OK(status)) {
582 if (!NT_STATUS_IS_OK(result)) {
587 if (rids.count != 1) {
588 status = NT_STATUS_NO_SUCH_USER;
591 if (rids.count != types.count) {
592 status = NT_STATUS_INVALID_PARAMETER;
595 if (types.ids[0] != SID_NAME_USER) {
596 status = NT_STATUS_NO_SUCH_USER;
602 status = dcerpc_samr_OpenUser(b, mem_ctx,
608 if (!NT_STATUS_IS_OK(status)) {
611 if (!NT_STATUS_IS_OK(result)) {
621 *domain_sid_p = domain_sid;
625 if (is_valid_policy_hnd(&domain_handle)) {
626 dcerpc_samr_Close(b, mem_ctx, &domain_handle, &result);
628 if (is_valid_policy_hnd(&connect_handle)) {
629 dcerpc_samr_Close(b, mem_ctx, &connect_handle, &result);
635 /******************************************************************
636 gets a machine password entry. checks access rights of the host.
637 ******************************************************************/
639 static NTSTATUS get_md4pw(struct samr_Password *md4pw, const char *mach_acct,
640 enum netr_SchannelType sec_chan_type,
642 struct messaging_context *msg_ctx)
645 NTSTATUS result = NT_STATUS_OK;
647 struct dcerpc_binding_handle *h = NULL;
648 struct tsocket_address *local;
649 struct policy_handle user_handle;
651 struct dom_sid *domain_sid;
653 union samr_UserInfo *info;
654 struct auth_session_info *session_info;
660 * Currently this code is redundent as we already have a filter
661 * by hostname list. What this code really needs to do is to
662 * get a hosts allowed/hosts denied list from the SAM database
663 * on a per user basis, and make the access decision there.
664 * I will leave this code here for now as a reminder to implement
665 * this at a later date. JRA.
668 if (!allow_access(lp_domain_hostsdeny(), lp_domain_hostsallow(),
670 p->client_id.addr)) {
671 DEBUG(0,("get_md4pw: Workstation %s denied access to domain\n", mach_acct));
676 mem_ctx = talloc_stackframe();
677 if (mem_ctx == NULL) {
678 status = NT_STATUS_NO_MEMORY;
682 status = make_session_info_system(mem_ctx, &session_info);
683 if (!NT_STATUS_IS_OK(status)) {
687 ZERO_STRUCT(user_handle);
689 rc = tsocket_address_inet_from_strings(mem_ctx,
695 status = NT_STATUS_NO_MEMORY;
699 status = rpcint_binding_handle(mem_ctx,
705 if (!NT_STATUS_IS_OK(status)) {
710 status = samr_find_machine_account(mem_ctx, h, mach_acct,
711 SEC_FLAG_MAXIMUM_ALLOWED,
712 &domain_sid, &user_rid,
715 if (!NT_STATUS_IS_OK(status)) {
719 status = dcerpc_samr_QueryUserInfo2(h,
722 UserControlInformation,
725 if (!NT_STATUS_IS_OK(status)) {
728 if (!NT_STATUS_IS_OK(result)) {
733 acct_ctrl = info->info16.acct_flags;
735 if (acct_ctrl & ACB_DISABLED) {
736 DEBUG(0,("get_md4pw: Workstation %s: account is disabled\n", mach_acct));
737 status = NT_STATUS_ACCOUNT_DISABLED;
741 if (!(acct_ctrl & ACB_SVRTRUST) &&
742 !(acct_ctrl & ACB_WSTRUST) &&
743 !(acct_ctrl & ACB_DOMTRUST))
745 DEBUG(0,("get_md4pw: Workstation %s: account is not a trust account\n", mach_acct));
746 status = NT_STATUS_NO_TRUST_SAM_ACCOUNT;
750 switch (sec_chan_type) {
752 if (!(acct_ctrl & ACB_SVRTRUST)) {
753 DEBUG(0,("get_md4pw: Workstation %s: BDC secure channel requested "
754 "but not a server trust account\n", mach_acct));
755 status = NT_STATUS_NO_TRUST_SAM_ACCOUNT;
760 if (!(acct_ctrl & ACB_WSTRUST)) {
761 DEBUG(0,("get_md4pw: Workstation %s: WORKSTATION secure channel requested "
762 "but not a workstation trust account\n", mach_acct));
763 status = NT_STATUS_NO_TRUST_SAM_ACCOUNT;
767 case SEC_CHAN_DOMAIN:
768 if (!(acct_ctrl & ACB_DOMTRUST)) {
769 DEBUG(0,("get_md4pw: Workstation %s: DOMAIN secure channel requested "
770 "but not a interdomain trust account\n", mach_acct));
771 status = NT_STATUS_NO_TRUST_SAM_ACCOUNT;
780 status = dcerpc_samr_QueryUserInfo2(h,
783 UserInternal1Information,
787 if (!NT_STATUS_IS_OK(status)) {
790 if (!NT_STATUS_IS_OK(result)) {
795 if (info->info18.nt_pwd_active == 0) {
796 DEBUG(0,("get_md4pw: Workstation %s: account does not have a password\n", mach_acct));
797 status = NT_STATUS_LOGON_FAILURE;
801 /* samr gives out nthash unencrypted (!) */
802 memcpy(md4pw->hash, info->info18.nt_pwd.hash, 16);
804 sid_compose(sid, domain_sid, user_rid);
807 if (h && is_valid_policy_hnd(&user_handle)) {
808 dcerpc_samr_Close(h, mem_ctx, &user_handle, &result);
811 talloc_free(mem_ctx);
816 /*************************************************************************
817 _netr_ServerReqChallenge
818 *************************************************************************/
820 NTSTATUS _netr_ServerReqChallenge(struct pipes_struct *p,
821 struct netr_ServerReqChallenge *r)
823 struct netlogon_server_pipe_state *pipe_state =
824 talloc_get_type(p->private_data, struct netlogon_server_pipe_state);
827 DEBUG(10,("_netr_ServerReqChallenge: new challenge requested. Clearing old state.\n"));
828 talloc_free(pipe_state);
829 p->private_data = NULL;
832 pipe_state = talloc(p, struct netlogon_server_pipe_state);
833 NT_STATUS_HAVE_NO_MEMORY(pipe_state);
835 pipe_state->client_challenge = *r->in.credentials;
837 generate_random_buffer(pipe_state->server_challenge.data,
838 sizeof(pipe_state->server_challenge.data));
840 *r->out.return_credentials = pipe_state->server_challenge;
842 p->private_data = pipe_state;
847 /*************************************************************************
848 _netr_ServerAuthenticate
849 Create the initial credentials.
850 *************************************************************************/
852 NTSTATUS _netr_ServerAuthenticate(struct pipes_struct *p,
853 struct netr_ServerAuthenticate *r)
855 struct netr_ServerAuthenticate3 a;
856 uint32_t negotiate_flags = 0;
859 a.in.server_name = r->in.server_name;
860 a.in.account_name = r->in.account_name;
861 a.in.secure_channel_type = r->in.secure_channel_type;
862 a.in.computer_name = r->in.computer_name;
863 a.in.credentials = r->in.credentials;
864 a.in.negotiate_flags = &negotiate_flags;
866 a.out.return_credentials = r->out.return_credentials;
868 a.out.negotiate_flags = &negotiate_flags;
870 return _netr_ServerAuthenticate3(p, &a);
874 /*************************************************************************
875 _netr_ServerAuthenticate3
876 *************************************************************************/
878 NTSTATUS _netr_ServerAuthenticate3(struct pipes_struct *p,
879 struct netr_ServerAuthenticate3 *r)
883 /* r->in.negotiate_flags is an aliased pointer to r->out.negotiate_flags,
884 * so use a copy to avoid destroying the client values. */
885 uint32_t in_neg_flags = *r->in.negotiate_flags;
887 struct loadparm_context *lp_ctx;
889 struct samr_Password mach_pwd;
890 struct netlogon_creds_CredentialState *creds;
891 struct netlogon_server_pipe_state *pipe_state =
892 talloc_get_type(p->private_data, struct netlogon_server_pipe_state);
894 /* According to Microsoft (see bugid #6099)
895 * Windows 7 looks at the negotiate_flags
896 * returned in this structure *even if the
897 * call fails with access denied* ! So in order
898 * to allow Win7 to connect to a Samba NT style
899 * PDC we set the flags before we know if it's
904 srv_flgs = NETLOGON_NEG_ACCOUNT_LOCKOUT |
905 NETLOGON_NEG_PERSISTENT_SAMREPL |
906 NETLOGON_NEG_ARCFOUR |
907 NETLOGON_NEG_PROMOTION_COUNT |
908 NETLOGON_NEG_CHANGELOG_BDC |
909 NETLOGON_NEG_FULL_SYNC_REPL |
910 NETLOGON_NEG_MULTIPLE_SIDS |
912 NETLOGON_NEG_PASSWORD_CHANGE_REFUSAL |
913 NETLOGON_NEG_PASSWORD_SET2;
915 /* Ensure we support strong (128-bit) keys. */
916 if (in_neg_flags & NETLOGON_NEG_STRONG_KEYS) {
917 srv_flgs |= NETLOGON_NEG_STRONG_KEYS;
920 if (lp_server_schannel() != false) {
921 srv_flgs |= NETLOGON_NEG_SCHANNEL;
925 case NDR_NETR_SERVERAUTHENTICATE:
926 fn = "_netr_ServerAuthenticate";
928 case NDR_NETR_SERVERAUTHENTICATE2:
929 fn = "_netr_ServerAuthenticate2";
931 case NDR_NETR_SERVERAUTHENTICATE3:
932 fn = "_netr_ServerAuthenticate3";
935 return NT_STATUS_INTERNAL_ERROR;
938 /* We use this as the key to store the creds: */
939 /* r->in.computer_name */
942 DEBUG(0,("%s: no challenge sent to client %s\n", fn,
943 r->in.computer_name));
944 status = NT_STATUS_ACCESS_DENIED;
948 if ( (lp_server_schannel() == true) &&
949 ((in_neg_flags & NETLOGON_NEG_SCHANNEL) == 0) ) {
951 /* schannel must be used, but client did not offer it. */
952 DEBUG(0,("%s: schannel required but client failed "
953 "to offer it. Client was %s\n",
954 fn, r->in.account_name));
955 status = NT_STATUS_ACCESS_DENIED;
959 status = get_md4pw(&mach_pwd,
961 r->in.secure_channel_type,
963 if (!NT_STATUS_IS_OK(status)) {
964 DEBUG(0,("%s: failed to get machine password for "
966 fn, r->in.account_name, nt_errstr(status) ));
967 /* always return NT_STATUS_ACCESS_DENIED */
968 status = NT_STATUS_ACCESS_DENIED;
972 /* From the client / server challenges and md4 password, generate sess key */
973 /* Check client credentials are valid. */
974 creds = netlogon_creds_server_init(p->mem_ctx,
977 r->in.secure_channel_type,
978 &pipe_state->client_challenge,
979 &pipe_state->server_challenge,
982 r->out.return_credentials,
983 *r->in.negotiate_flags);
985 DEBUG(0,("%s: netlogon_creds_server_check failed. Rejecting auth "
986 "request from client %s machine account %s\n",
987 fn, r->in.computer_name,
988 r->in.account_name));
989 status = NT_STATUS_ACCESS_DENIED;
993 creds->sid = dom_sid_dup(creds, &sid);
995 status = NT_STATUS_NO_MEMORY;
999 lp_ctx = loadparm_init_s3(p->mem_ctx, loadparm_s3_context());
1000 if (lp_ctx == NULL) {
1001 DEBUG(10, ("loadparm_init_s3 failed\n"));
1002 status = NT_STATUS_INTERNAL_ERROR;
1006 /* Store off the state so we can continue after client disconnect. */
1008 status = schannel_save_creds_state(p->mem_ctx, lp_ctx, creds);
1011 talloc_unlink(p->mem_ctx, lp_ctx);
1013 if (!NT_STATUS_IS_OK(status)) {
1017 sid_peek_rid(&sid, r->out.rid);
1019 status = NT_STATUS_OK;
1023 *r->out.negotiate_flags = srv_flgs;
1027 /*************************************************************************
1028 _netr_ServerAuthenticate2
1029 *************************************************************************/
1031 NTSTATUS _netr_ServerAuthenticate2(struct pipes_struct *p,
1032 struct netr_ServerAuthenticate2 *r)
1034 struct netr_ServerAuthenticate3 a;
1037 a.in.server_name = r->in.server_name;
1038 a.in.account_name = r->in.account_name;
1039 a.in.secure_channel_type = r->in.secure_channel_type;
1040 a.in.computer_name = r->in.computer_name;
1041 a.in.credentials = r->in.credentials;
1042 a.in.negotiate_flags = r->in.negotiate_flags;
1044 a.out.return_credentials = r->out.return_credentials;
1046 a.out.negotiate_flags = r->out.negotiate_flags;
1048 return _netr_ServerAuthenticate3(p, &a);
1051 /*************************************************************************
1052 * If schannel is required for this call test that it actually is available.
1053 *************************************************************************/
1054 static NTSTATUS schannel_check_required(struct pipe_auth_data *auth_info,
1055 const char *computer_name,
1056 bool integrity, bool privacy)
1058 if (auth_info && auth_info->auth_type == DCERPC_AUTH_TYPE_SCHANNEL) {
1059 if (!privacy && !integrity) {
1060 return NT_STATUS_OK;
1063 if ((!privacy && integrity) &&
1064 auth_info->auth_level == DCERPC_AUTH_LEVEL_INTEGRITY) {
1065 return NT_STATUS_OK;
1068 if ((privacy || integrity) &&
1069 auth_info->auth_level == DCERPC_AUTH_LEVEL_PRIVACY) {
1070 return NT_STATUS_OK;
1074 /* test didn't pass */
1075 DEBUG(0, ("schannel_check_required: [%s] is not using schannel\n",
1078 return NT_STATUS_ACCESS_DENIED;
1081 /*************************************************************************
1082 *************************************************************************/
1084 static NTSTATUS netr_creds_server_step_check(struct pipes_struct *p,
1085 TALLOC_CTX *mem_ctx,
1086 const char *computer_name,
1087 struct netr_Authenticator *received_authenticator,
1088 struct netr_Authenticator *return_authenticator,
1089 struct netlogon_creds_CredentialState **creds_out)
1092 bool schannel_global_required = (lp_server_schannel() == true) ? true:false;
1093 struct loadparm_context *lp_ctx;
1095 if (schannel_global_required) {
1096 status = schannel_check_required(&p->auth,
1099 if (!NT_STATUS_IS_OK(status)) {
1104 lp_ctx = loadparm_init_s3(mem_ctx, loadparm_s3_context());
1105 if (lp_ctx == NULL) {
1106 DEBUG(0, ("loadparm_init_s3 failed\n"));
1107 return NT_STATUS_INTERNAL_ERROR;
1110 status = schannel_check_creds_state(mem_ctx, lp_ctx,
1111 computer_name, received_authenticator,
1112 return_authenticator, creds_out);
1113 talloc_unlink(mem_ctx, lp_ctx);
1117 /*************************************************************************
1118 *************************************************************************/
1120 static NTSTATUS netr_set_machine_account_password(TALLOC_CTX *mem_ctx,
1121 struct auth_session_info *session_info,
1122 struct messaging_context *msg_ctx,
1123 const char *account_name,
1124 struct samr_Password *nt_hash)
1127 NTSTATUS result = NT_STATUS_OK;
1128 struct dcerpc_binding_handle *h = NULL;
1129 struct tsocket_address *local;
1130 struct policy_handle user_handle;
1132 union samr_UserInfo *info;
1133 struct samr_UserInfo18 info18;
1137 ZERO_STRUCT(user_handle);
1139 rc = tsocket_address_inet_from_strings(mem_ctx,
1145 status = NT_STATUS_NO_MEMORY;
1149 status = rpcint_binding_handle(mem_ctx,
1155 if (!NT_STATUS_IS_OK(status)) {
1160 status = samr_find_machine_account(mem_ctx,
1163 SEC_FLAG_MAXIMUM_ALLOWED,
1168 if (!NT_STATUS_IS_OK(status)) {
1172 status = dcerpc_samr_QueryUserInfo2(h,
1175 UserControlInformation,
1178 if (!NT_STATUS_IS_OK(status)) {
1181 if (!NT_STATUS_IS_OK(result)) {
1186 acct_ctrl = info->info16.acct_flags;
1188 if (!(acct_ctrl & ACB_WSTRUST ||
1189 acct_ctrl & ACB_SVRTRUST ||
1190 acct_ctrl & ACB_DOMTRUST)) {
1191 status = NT_STATUS_NO_SUCH_USER;
1195 if (acct_ctrl & ACB_DISABLED) {
1196 status = NT_STATUS_ACCOUNT_DISABLED;
1200 ZERO_STRUCT(info18);
1202 in = data_blob_const(nt_hash->hash, 16);
1203 out = data_blob_talloc_zero(mem_ctx, 16);
1204 sess_crypt_blob(&out, &in, &session_info->session_key, true);
1205 memcpy(info18.nt_pwd.hash, out.data, out.length);
1207 info18.nt_pwd_active = true;
1209 info->info18 = info18;
1212 status = dcerpc_samr_SetUserInfo2(h,
1215 UserInternal1Information,
1219 if (!NT_STATUS_IS_OK(status)) {
1222 if (!NT_STATUS_IS_OK(result)) {
1228 if (h && is_valid_policy_hnd(&user_handle)) {
1229 dcerpc_samr_Close(h, mem_ctx, &user_handle, &result);
1235 /*************************************************************************
1236 _netr_ServerPasswordSet
1237 *************************************************************************/
1239 NTSTATUS _netr_ServerPasswordSet(struct pipes_struct *p,
1240 struct netr_ServerPasswordSet *r)
1242 NTSTATUS status = NT_STATUS_OK;
1244 struct netlogon_creds_CredentialState *creds;
1246 DEBUG(5,("_netr_ServerPasswordSet: %d\n", __LINE__));
1249 status = netr_creds_server_step_check(p, p->mem_ctx,
1250 r->in.computer_name,
1252 r->out.return_authenticator,
1256 if (!NT_STATUS_IS_OK(status)) {
1257 DEBUG(2,("_netr_ServerPasswordSet: netlogon_creds_server_step failed. Rejecting auth "
1258 "request from client %s machine account %s\n",
1259 r->in.computer_name, creds->computer_name));
1264 DEBUG(3,("_netr_ServerPasswordSet: Server Password Set by remote machine:[%s] on account [%s]\n",
1265 r->in.computer_name, creds->computer_name));
1267 netlogon_creds_des_decrypt(creds, r->in.new_password);
1269 DEBUG(100,("_netr_ServerPasswordSet: new given value was :\n"));
1270 for(i = 0; i < sizeof(r->in.new_password->hash); i++)
1271 DEBUG(100,("%02X ", r->in.new_password->hash[i]));
1274 status = netr_set_machine_account_password(p->mem_ctx,
1277 creds->account_name,
1278 r->in.new_password);
1282 /****************************************************************
1283 _netr_ServerPasswordSet2
1284 ****************************************************************/
1286 NTSTATUS _netr_ServerPasswordSet2(struct pipes_struct *p,
1287 struct netr_ServerPasswordSet2 *r)
1290 struct netlogon_creds_CredentialState *creds = NULL;
1291 DATA_BLOB plaintext;
1292 struct samr_CryptPassword password_buf;
1293 struct samr_Password nt_hash;
1296 status = netr_creds_server_step_check(p, p->mem_ctx,
1297 r->in.computer_name,
1299 r->out.return_authenticator,
1303 if (!NT_STATUS_IS_OK(status)) {
1304 const char *computer_name = "<unknown>";
1306 if (creds && creds->computer_name) {
1307 computer_name = creds->computer_name;
1309 DEBUG(2,("_netr_ServerPasswordSet2: netlogon_creds_server_step "
1310 "failed. Rejecting auth request from client %s machine account %s\n",
1311 r->in.computer_name, computer_name));
1316 memcpy(password_buf.data, r->in.new_password->data, 512);
1317 SIVAL(password_buf.data, 512, r->in.new_password->length);
1318 netlogon_creds_arcfour_crypt(creds, password_buf.data, 516);
1320 if (!extract_pw_from_buffer(p->mem_ctx, password_buf.data, &plaintext)) {
1322 return NT_STATUS_WRONG_PASSWORD;
1325 mdfour(nt_hash.hash, plaintext.data, plaintext.length);
1327 status = netr_set_machine_account_password(p->mem_ctx,
1330 creds->account_name,
1336 /*************************************************************************
1337 _netr_LogonSamLogoff
1338 *************************************************************************/
1340 NTSTATUS _netr_LogonSamLogoff(struct pipes_struct *p,
1341 struct netr_LogonSamLogoff *r)
1344 struct netlogon_creds_CredentialState *creds;
1347 status = netr_creds_server_step_check(p, p->mem_ctx,
1348 r->in.computer_name,
1350 r->out.return_authenticator,
1357 static NTSTATUS _netr_LogonSamLogon_check(const struct netr_LogonSamLogonEx *r)
1359 switch (r->in.logon_level) {
1360 case NetlogonInteractiveInformation:
1361 case NetlogonServiceInformation:
1362 case NetlogonInteractiveTransitiveInformation:
1363 case NetlogonServiceTransitiveInformation:
1364 if (r->in.logon->password == NULL) {
1365 return NT_STATUS_INVALID_PARAMETER;
1368 switch (r->in.validation_level) {
1369 case NetlogonValidationSamInfo: /* 2 */
1370 case NetlogonValidationSamInfo2: /* 3 */
1372 case NetlogonValidationSamInfo4: /* 6 */
1373 if ((pdb_capabilities() & PDB_CAP_ADS) == 0) {
1374 DEBUG(10,("Not adding validation info level 6 "
1375 "without ADS passdb backend\n"));
1376 return NT_STATUS_INVALID_INFO_CLASS;
1380 return NT_STATUS_INVALID_INFO_CLASS;
1384 case NetlogonNetworkInformation:
1385 case NetlogonNetworkTransitiveInformation:
1386 if (r->in.logon->network == NULL) {
1387 return NT_STATUS_INVALID_PARAMETER;
1390 switch (r->in.validation_level) {
1391 case NetlogonValidationSamInfo: /* 2 */
1392 case NetlogonValidationSamInfo2: /* 3 */
1394 case NetlogonValidationSamInfo4: /* 6 */
1395 if ((pdb_capabilities() & PDB_CAP_ADS) == 0) {
1396 DEBUG(10,("Not adding validation info level 6 "
1397 "without ADS passdb backend\n"));
1398 return NT_STATUS_INVALID_INFO_CLASS;
1402 return NT_STATUS_INVALID_INFO_CLASS;
1407 case NetlogonGenericInformation:
1408 if (r->in.logon->generic == NULL) {
1409 return NT_STATUS_INVALID_PARAMETER;
1412 /* we don't support this here */
1413 return NT_STATUS_INVALID_PARAMETER;
1415 switch (r->in.validation_level) {
1416 /* TODO: case NetlogonValidationGenericInfo: 4 */
1417 case NetlogonValidationGenericInfo2: /* 5 */
1420 return NT_STATUS_INVALID_INFO_CLASS;
1426 return NT_STATUS_INVALID_PARAMETER;
1429 return NT_STATUS_OK;
1432 /*************************************************************************
1433 _netr_LogonSamLogon_base
1434 *************************************************************************/
1436 static NTSTATUS _netr_LogonSamLogon_base(struct pipes_struct *p,
1437 struct netr_LogonSamLogonEx *r,
1438 struct netlogon_creds_CredentialState *creds)
1440 NTSTATUS status = NT_STATUS_OK;
1441 union netr_LogonLevel *logon = r->in.logon;
1442 const char *nt_username, *nt_domain, *nt_workstation;
1443 struct auth_usersupplied_info *user_info = NULL;
1444 struct auth_serversupplied_info *server_info = NULL;
1445 struct auth_context *auth_context = NULL;
1446 uint8_t pipe_session_key[16];
1447 bool process_creds = true;
1451 case NDR_NETR_LOGONSAMLOGON:
1452 process_creds = true;
1453 fn = "_netr_LogonSamLogon";
1455 case NDR_NETR_LOGONSAMLOGONWITHFLAGS:
1456 process_creds = true;
1457 fn = "_netr_LogonSamLogonWithFlags";
1459 case NDR_NETR_LOGONSAMLOGONEX:
1460 process_creds = false;
1461 fn = "_netr_LogonSamLogonEx";
1464 return NT_STATUS_INTERNAL_ERROR;
1467 *r->out.authoritative = true; /* authoritative response */
1469 switch (r->in.validation_level) {
1471 r->out.validation->sam2 = talloc_zero(p->mem_ctx, struct netr_SamInfo2);
1472 if (!r->out.validation->sam2) {
1473 return NT_STATUS_NO_MEMORY;
1477 r->out.validation->sam3 = talloc_zero(p->mem_ctx, struct netr_SamInfo3);
1478 if (!r->out.validation->sam3) {
1479 return NT_STATUS_NO_MEMORY;
1483 r->out.validation->sam6 = talloc_zero(p->mem_ctx, struct netr_SamInfo6);
1484 if (!r->out.validation->sam6) {
1485 return NT_STATUS_NO_MEMORY;
1489 DEBUG(0,("%s: bad validation_level value %d.\n",
1490 fn, (int)r->in.validation_level));
1491 return NT_STATUS_INVALID_INFO_CLASS;
1494 switch (r->in.logon_level) {
1495 case NetlogonInteractiveInformation:
1496 case NetlogonServiceInformation:
1497 case NetlogonInteractiveTransitiveInformation:
1498 case NetlogonServiceTransitiveInformation:
1499 nt_username = logon->password->identity_info.account_name.string ?
1500 logon->password->identity_info.account_name.string : "";
1501 nt_domain = logon->password->identity_info.domain_name.string ?
1502 logon->password->identity_info.domain_name.string : "";
1503 nt_workstation = logon->password->identity_info.workstation.string ?
1504 logon->password->identity_info.workstation.string : "";
1506 DEBUG(3,("SAM Logon (Interactive). Domain:[%s]. ", lp_workgroup()));
1508 case NetlogonNetworkInformation:
1509 case NetlogonNetworkTransitiveInformation:
1510 nt_username = logon->network->identity_info.account_name.string ?
1511 logon->network->identity_info.account_name.string : "";
1512 nt_domain = logon->network->identity_info.domain_name.string ?
1513 logon->network->identity_info.domain_name.string : "";
1514 nt_workstation = logon->network->identity_info.workstation.string ?
1515 logon->network->identity_info.workstation.string : "";
1517 DEBUG(3,("SAM Logon (Network). Domain:[%s]. ", lp_workgroup()));
1520 DEBUG(2,("SAM Logon: unsupported switch value\n"));
1521 return NT_STATUS_INVALID_INFO_CLASS;
1524 DEBUG(3,("User:[%s@%s] Requested Domain:[%s]\n", nt_username, nt_workstation, nt_domain));
1525 fstrcpy(current_user_info.smb_name, nt_username);
1526 sub_set_smb_name(nt_username);
1528 DEBUG(5,("Attempting validation level %d for unmapped username %s.\n",
1529 r->in.validation_level, nt_username));
1531 status = NT_STATUS_OK;
1533 switch (r->in.logon_level) {
1534 case NetlogonNetworkInformation:
1535 case NetlogonNetworkTransitiveInformation:
1537 const char *wksname = nt_workstation;
1539 status = make_auth_context_fixed(talloc_tos(), &auth_context,
1540 logon->network->challenge);
1541 if (!NT_STATUS_IS_OK(status)) {
1545 /* For a network logon, the workstation name comes in with two
1546 * backslashes in the front. Strip them if they are there. */
1548 if (*wksname == '\\') wksname++;
1549 if (*wksname == '\\') wksname++;
1551 /* Standard challenge/response authentication */
1552 if (!make_user_info_netlogon_network(&user_info,
1553 nt_username, nt_domain,
1556 logon->network->identity_info.parameter_control,
1557 logon->network->lm.data,
1558 logon->network->lm.length,
1559 logon->network->nt.data,
1560 logon->network->nt.length)) {
1561 status = NT_STATUS_NO_MEMORY;
1565 case NetlogonInteractiveInformation:
1566 case NetlogonServiceInformation:
1567 case NetlogonInteractiveTransitiveInformation:
1568 case NetlogonServiceTransitiveInformation:
1570 /* 'Interactive' authentication, supplies the password in its
1571 MD4 form, encrypted with the session key. We will convert
1572 this to challenge/response for the auth subsystem to chew
1577 status = make_auth_context_subsystem(talloc_tos(),
1579 if (!NT_STATUS_IS_OK(status)) {
1583 auth_context->get_ntlm_challenge(auth_context, chal);
1585 if (!make_user_info_netlogon_interactive(&user_info,
1586 nt_username, nt_domain,
1589 logon->password->identity_info.parameter_control,
1591 logon->password->lmpassword.hash,
1592 logon->password->ntpassword.hash,
1593 creds->session_key)) {
1594 status = NT_STATUS_NO_MEMORY;
1599 DEBUG(2,("SAM Logon: unsupported switch value\n"));
1600 return NT_STATUS_INVALID_INFO_CLASS;
1603 if ( NT_STATUS_IS_OK(status) ) {
1604 status = auth_context->check_ntlm_password(auth_context,
1605 user_info, &server_info);
1608 TALLOC_FREE(auth_context);
1609 free_user_info(&user_info);
1611 DEBUG(5,("%s: check_password returned status %s\n",
1612 fn, nt_errstr(status)));
1614 /* Check account and password */
1616 if (!NT_STATUS_IS_OK(status)) {
1617 /* If we don't know what this domain is, we need to
1618 indicate that we are not authoritative. This
1619 allows the client to decide if it needs to try
1620 a local user. Fix by jpjanosi@us.ibm.com, #2976 */
1621 if ( NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_USER)
1622 && !strequal(nt_domain, get_global_sam_name())
1623 && !is_trusted_domain(nt_domain) )
1624 *r->out.authoritative = false; /* We are not authoritative */
1626 TALLOC_FREE(server_info);
1630 if (server_info->guest) {
1631 /* We don't like guest domain logons... */
1632 DEBUG(5,("%s: Attempted domain logon as GUEST "
1634 TALLOC_FREE(server_info);
1635 return NT_STATUS_LOGON_FAILURE;
1638 /* This is the point at which, if the login was successful, that
1639 the SAM Local Security Authority should record that the user is
1640 logged in to the domain. */
1642 if (process_creds) {
1643 /* Get the pipe session key from the creds. */
1644 memcpy(pipe_session_key, creds->session_key, 16);
1646 struct schannel_state *schannel_auth;
1647 /* Get the pipe session key from the schannel. */
1648 if ((p->auth.auth_type != DCERPC_AUTH_TYPE_SCHANNEL)
1649 || (p->auth.auth_ctx == NULL)) {
1650 return NT_STATUS_INVALID_HANDLE;
1653 schannel_auth = talloc_get_type_abort(p->auth.auth_ctx,
1654 struct schannel_state);
1655 memcpy(pipe_session_key, schannel_auth->creds->session_key, 16);
1658 switch (r->in.validation_level) {
1660 status = serverinfo_to_SamInfo2(server_info, pipe_session_key, 16,
1661 r->out.validation->sam2);
1664 status = serverinfo_to_SamInfo3(server_info, pipe_session_key, 16,
1665 r->out.validation->sam3);
1668 status = serverinfo_to_SamInfo6(server_info, pipe_session_key, 16,
1669 r->out.validation->sam6);
1673 TALLOC_FREE(server_info);
1678 /****************************************************************
1679 _netr_LogonSamLogonWithFlags
1680 ****************************************************************/
1682 NTSTATUS _netr_LogonSamLogonWithFlags(struct pipes_struct *p,
1683 struct netr_LogonSamLogonWithFlags *r)
1686 struct netlogon_creds_CredentialState *creds;
1687 struct netr_LogonSamLogonEx r2;
1688 struct netr_Authenticator return_authenticator;
1690 *r->out.authoritative = true;
1692 r2.in.server_name = r->in.server_name;
1693 r2.in.computer_name = r->in.computer_name;
1694 r2.in.logon_level = r->in.logon_level;
1695 r2.in.logon = r->in.logon;
1696 r2.in.validation_level = r->in.validation_level;
1697 r2.in.flags = r->in.flags;
1698 r2.out.validation = r->out.validation;
1699 r2.out.authoritative = r->out.authoritative;
1700 r2.out.flags = r->out.flags;
1702 status = _netr_LogonSamLogon_check(&r2);
1703 if (!NT_STATUS_IS_OK(status)) {
1708 status = netr_creds_server_step_check(p, p->mem_ctx,
1709 r->in.computer_name,
1711 &return_authenticator,
1714 if (!NT_STATUS_IS_OK(status)) {
1718 status = _netr_LogonSamLogon_base(p, &r2, creds);
1720 *r->out.return_authenticator = return_authenticator;
1725 /*************************************************************************
1727 *************************************************************************/
1729 NTSTATUS _netr_LogonSamLogon(struct pipes_struct *p,
1730 struct netr_LogonSamLogon *r)
1733 struct netr_LogonSamLogonWithFlags r2;
1736 r2.in.server_name = r->in.server_name;
1737 r2.in.computer_name = r->in.computer_name;
1738 r2.in.credential = r->in.credential;
1739 r2.in.logon_level = r->in.logon_level;
1740 r2.in.logon = r->in.logon;
1741 r2.in.validation_level = r->in.validation_level;
1742 r2.in.return_authenticator = r->in.return_authenticator;
1743 r2.in.flags = &flags;
1744 r2.out.validation = r->out.validation;
1745 r2.out.authoritative = r->out.authoritative;
1746 r2.out.flags = &flags;
1747 r2.out.return_authenticator = r->out.return_authenticator;
1749 status = _netr_LogonSamLogonWithFlags(p, &r2);
1754 /*************************************************************************
1755 _netr_LogonSamLogonEx
1756 - no credential chaining. Map into net sam logon.
1757 *************************************************************************/
1759 NTSTATUS _netr_LogonSamLogonEx(struct pipes_struct *p,
1760 struct netr_LogonSamLogonEx *r)
1763 struct netlogon_creds_CredentialState *creds = NULL;
1764 struct loadparm_context *lp_ctx;
1766 *r->out.authoritative = true;
1768 status = _netr_LogonSamLogon_check(r);
1769 if (!NT_STATUS_IS_OK(status)) {
1773 /* Only allow this if the pipe is protected. */
1774 if (p->auth.auth_type != DCERPC_AUTH_TYPE_SCHANNEL) {
1775 DEBUG(0,("_netr_LogonSamLogonEx: client %s not using schannel for netlogon\n",
1776 get_remote_machine_name() ));
1777 return NT_STATUS_INVALID_PARAMETER;
1780 lp_ctx = loadparm_init_s3(p->mem_ctx, loadparm_s3_context());
1781 if (lp_ctx == NULL) {
1782 DEBUG(0, ("loadparm_init_s3 failed\n"));
1783 return NT_STATUS_INTERNAL_ERROR;
1787 status = schannel_get_creds_state(p->mem_ctx, lp_ctx,
1788 r->in.computer_name, &creds);
1790 talloc_unlink(p->mem_ctx, lp_ctx);
1792 if (!NT_STATUS_IS_OK(status)) {
1796 status = _netr_LogonSamLogon_base(p, r, creds);
1802 /*************************************************************************
1804 *************************************************************************/
1805 #if 0 /* JERRY -- not correct */
1806 NTSTATUS _ds_enum_dom_trusts(struct pipes_struct *p, DS_Q_ENUM_DOM_TRUSTS *q_u,
1807 DS_R_ENUM_DOM_TRUSTS *r_u)
1809 NTSTATUS status = NT_STATUS_OK;
1811 /* TODO: According to MSDN, the can only be executed against a
1812 DC or domain member running Windows 2000 or later. Need
1813 to test against a standalone 2k server and see what it
1814 does. A windows 2000 DC includes its own domain in the
1822 /****************************************************************
1823 ****************************************************************/
1825 WERROR _netr_LogonUasLogon(struct pipes_struct *p,
1826 struct netr_LogonUasLogon *r)
1828 p->rng_fault_state = true;
1829 return WERR_NOT_SUPPORTED;
1832 /****************************************************************
1833 ****************************************************************/
1835 WERROR _netr_LogonUasLogoff(struct pipes_struct *p,
1836 struct netr_LogonUasLogoff *r)
1838 p->rng_fault_state = true;
1839 return WERR_NOT_SUPPORTED;
1842 /****************************************************************
1843 ****************************************************************/
1845 NTSTATUS _netr_DatabaseDeltas(struct pipes_struct *p,
1846 struct netr_DatabaseDeltas *r)
1848 p->rng_fault_state = true;
1849 return NT_STATUS_NOT_IMPLEMENTED;
1852 /****************************************************************
1853 ****************************************************************/
1855 NTSTATUS _netr_DatabaseSync(struct pipes_struct *p,
1856 struct netr_DatabaseSync *r)
1858 p->rng_fault_state = true;
1859 return NT_STATUS_NOT_IMPLEMENTED;
1862 /****************************************************************
1863 ****************************************************************/
1865 NTSTATUS _netr_AccountDeltas(struct pipes_struct *p,
1866 struct netr_AccountDeltas *r)
1868 p->rng_fault_state = true;
1869 return NT_STATUS_NOT_IMPLEMENTED;
1872 /****************************************************************
1873 ****************************************************************/
1875 NTSTATUS _netr_AccountSync(struct pipes_struct *p,
1876 struct netr_AccountSync *r)
1878 p->rng_fault_state = true;
1879 return NT_STATUS_NOT_IMPLEMENTED;
1882 /****************************************************************
1883 ****************************************************************/
1885 static bool wb_getdcname(TALLOC_CTX *mem_ctx,
1887 const char **dcname,
1892 struct wbcDomainControllerInfo *dc_info = NULL;
1894 result = wbcLookupDomainController(domain,
1898 case WBC_ERR_SUCCESS:
1900 case WBC_ERR_WINBIND_NOT_AVAILABLE:
1902 case WBC_ERR_DOMAIN_NOT_FOUND:
1903 *werr = WERR_NO_SUCH_DOMAIN;
1906 *werr = WERR_DOMAIN_CONTROLLER_NOT_FOUND;
1910 *dcname = talloc_strdup(mem_ctx, dc_info->dc_name);
1911 wbcFreeMemory(dc_info);
1922 /****************************************************************
1924 ****************************************************************/
1926 WERROR _netr_GetDcName(struct pipes_struct *p,
1927 struct netr_GetDcName *r)
1932 struct netr_DsRGetDCNameInfo *info;
1935 ret = wb_getdcname(p->mem_ctx,
1938 WBC_LOOKUP_DC_IS_FLAT_NAME |
1939 WBC_LOOKUP_DC_RETURN_FLAT_NAME |
1940 WBC_LOOKUP_DC_PDC_REQUIRED,
1946 flags = DS_PDC_REQUIRED | DS_IS_FLAT_NAME | DS_RETURN_FLAT_NAME;
1948 status = dsgetdcname(p->mem_ctx,
1955 if (!NT_STATUS_IS_OK(status)) {
1956 return ntstatus_to_werror(status);
1959 *r->out.dcname = talloc_strdup(p->mem_ctx, info->dc_unc);
1961 if (!*r->out.dcname) {
1968 /****************************************************************
1970 ****************************************************************/
1972 WERROR _netr_GetAnyDCName(struct pipes_struct *p,
1973 struct netr_GetAnyDCName *r)
1978 struct netr_DsRGetDCNameInfo *info;
1981 ret = wb_getdcname(p->mem_ctx,
1984 WBC_LOOKUP_DC_IS_FLAT_NAME |
1985 WBC_LOOKUP_DC_RETURN_FLAT_NAME,
1991 flags = DS_IS_FLAT_NAME | DS_RETURN_FLAT_NAME;
1993 status = dsgetdcname(p->mem_ctx,
2000 if (!NT_STATUS_IS_OK(status)) {
2001 return ntstatus_to_werror(status);
2004 *r->out.dcname = talloc_strdup(p->mem_ctx, info->dc_unc);
2006 if (!*r->out.dcname) {
2013 /****************************************************************
2014 ****************************************************************/
2016 NTSTATUS _netr_DatabaseSync2(struct pipes_struct *p,
2017 struct netr_DatabaseSync2 *r)
2019 p->rng_fault_state = true;
2020 return NT_STATUS_NOT_IMPLEMENTED;
2023 /****************************************************************
2024 ****************************************************************/
2026 NTSTATUS _netr_DatabaseRedo(struct pipes_struct *p,
2027 struct netr_DatabaseRedo *r)
2029 p->rng_fault_state = true;
2030 return NT_STATUS_NOT_IMPLEMENTED;
2033 /****************************************************************
2034 ****************************************************************/
2036 WERROR _netr_DsRGetDCName(struct pipes_struct *p,
2037 struct netr_DsRGetDCName *r)
2039 p->rng_fault_state = true;
2040 return WERR_NOT_SUPPORTED;
2043 /****************************************************************
2044 ****************************************************************/
2046 NTSTATUS _netr_LogonGetCapabilities(struct pipes_struct *p,
2047 struct netr_LogonGetCapabilities *r)
2049 return NT_STATUS_NOT_IMPLEMENTED;
2052 /****************************************************************
2053 ****************************************************************/
2055 WERROR _netr_NETRLOGONSETSERVICEBITS(struct pipes_struct *p,
2056 struct netr_NETRLOGONSETSERVICEBITS *r)
2058 p->rng_fault_state = true;
2059 return WERR_NOT_SUPPORTED;
2062 /****************************************************************
2063 ****************************************************************/
2065 WERROR _netr_LogonGetTrustRid(struct pipes_struct *p,
2066 struct netr_LogonGetTrustRid *r)
2068 p->rng_fault_state = true;
2069 return WERR_NOT_SUPPORTED;
2072 /****************************************************************
2073 ****************************************************************/
2075 WERROR _netr_NETRLOGONCOMPUTESERVERDIGEST(struct pipes_struct *p,
2076 struct netr_NETRLOGONCOMPUTESERVERDIGEST *r)
2078 p->rng_fault_state = true;
2079 return WERR_NOT_SUPPORTED;
2082 /****************************************************************
2083 ****************************************************************/
2085 WERROR _netr_NETRLOGONCOMPUTECLIENTDIGEST(struct pipes_struct *p,
2086 struct netr_NETRLOGONCOMPUTECLIENTDIGEST *r)
2088 p->rng_fault_state = true;
2089 return WERR_NOT_SUPPORTED;
2092 /****************************************************************
2093 ****************************************************************/
2095 WERROR _netr_DsRGetDCNameEx(struct pipes_struct *p,
2096 struct netr_DsRGetDCNameEx *r)
2098 p->rng_fault_state = true;
2099 return WERR_NOT_SUPPORTED;
2102 /****************************************************************
2103 ****************************************************************/
2105 WERROR _netr_DsRGetSiteName(struct pipes_struct *p,
2106 struct netr_DsRGetSiteName *r)
2108 p->rng_fault_state = true;
2109 return WERR_NOT_SUPPORTED;
2112 /****************************************************************
2113 ****************************************************************/
2115 NTSTATUS _netr_LogonGetDomainInfo(struct pipes_struct *p,
2116 struct netr_LogonGetDomainInfo *r)
2118 p->rng_fault_state = true;
2119 return NT_STATUS_NOT_IMPLEMENTED;
2122 /****************************************************************
2123 ****************************************************************/
2125 WERROR _netr_ServerPasswordGet(struct pipes_struct *p,
2126 struct netr_ServerPasswordGet *r)
2128 p->rng_fault_state = true;
2129 return WERR_NOT_SUPPORTED;
2132 /****************************************************************
2133 ****************************************************************/
2135 WERROR _netr_NETRLOGONSENDTOSAM(struct pipes_struct *p,
2136 struct netr_NETRLOGONSENDTOSAM *r)
2138 p->rng_fault_state = true;
2139 return WERR_NOT_SUPPORTED;
2142 /****************************************************************
2143 ****************************************************************/
2145 WERROR _netr_DsRAddressToSitenamesW(struct pipes_struct *p,
2146 struct netr_DsRAddressToSitenamesW *r)
2148 p->rng_fault_state = true;
2149 return WERR_NOT_SUPPORTED;
2152 /****************************************************************
2153 ****************************************************************/
2155 WERROR _netr_DsRGetDCNameEx2(struct pipes_struct *p,
2156 struct netr_DsRGetDCNameEx2 *r)
2158 p->rng_fault_state = true;
2159 return WERR_NOT_SUPPORTED;
2162 /****************************************************************
2163 ****************************************************************/
2165 WERROR _netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN(struct pipes_struct *p,
2166 struct netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN *r)
2168 p->rng_fault_state = true;
2169 return WERR_NOT_SUPPORTED;
2172 /****************************************************************
2173 ****************************************************************/
2175 WERROR _netr_NetrEnumerateTrustedDomainsEx(struct pipes_struct *p,
2176 struct netr_NetrEnumerateTrustedDomainsEx *r)
2178 p->rng_fault_state = true;
2179 return WERR_NOT_SUPPORTED;
2182 /****************************************************************
2183 ****************************************************************/
2185 WERROR _netr_DsRAddressToSitenamesExW(struct pipes_struct *p,
2186 struct netr_DsRAddressToSitenamesExW *r)
2188 p->rng_fault_state = true;
2189 return WERR_NOT_SUPPORTED;
2192 /****************************************************************
2193 ****************************************************************/
2195 WERROR _netr_DsrGetDcSiteCoverageW(struct pipes_struct *p,
2196 struct netr_DsrGetDcSiteCoverageW *r)
2198 p->rng_fault_state = true;
2199 return WERR_NOT_SUPPORTED;
2202 /****************************************************************
2203 ****************************************************************/
2205 WERROR _netr_DsrEnumerateDomainTrusts(struct pipes_struct *p,
2206 struct netr_DsrEnumerateDomainTrusts *r)
2208 p->rng_fault_state = true;
2209 return WERR_NOT_SUPPORTED;
2212 /****************************************************************
2213 ****************************************************************/
2215 WERROR _netr_DsrDeregisterDNSHostRecords(struct pipes_struct *p,
2216 struct netr_DsrDeregisterDNSHostRecords *r)
2218 p->rng_fault_state = true;
2219 return WERR_NOT_SUPPORTED;
2222 /****************************************************************
2223 ****************************************************************/
2225 NTSTATUS _netr_ServerTrustPasswordsGet(struct pipes_struct *p,
2226 struct netr_ServerTrustPasswordsGet *r)
2228 p->rng_fault_state = true;
2229 return NT_STATUS_NOT_IMPLEMENTED;
2232 /****************************************************************
2233 ****************************************************************/
2235 WERROR _netr_DsRGetForestTrustInformation(struct pipes_struct *p,
2236 struct netr_DsRGetForestTrustInformation *r)
2238 p->rng_fault_state = true;
2239 return WERR_NOT_SUPPORTED;
2242 /****************************************************************
2243 ****************************************************************/
2245 static NTSTATUS fill_forest_trust_array(TALLOC_CTX *mem_ctx,
2246 struct lsa_ForestTrustInformation *info)
2248 struct lsa_ForestTrustRecord *e;
2249 struct pdb_domain_info *dom_info;
2250 struct lsa_ForestTrustDomainInfo *domain_info;
2252 dom_info = pdb_get_domain_info(mem_ctx);
2253 if (dom_info == NULL) {
2254 return NT_STATUS_NO_MEMORY;
2258 info->entries = talloc_array(info, struct lsa_ForestTrustRecord *, 2);
2259 if (info->entries == NULL) {
2260 return NT_STATUS_NO_MEMORY;
2263 e = talloc(info, struct lsa_ForestTrustRecord);
2265 return NT_STATUS_NO_MEMORY;
2269 e->type = LSA_FOREST_TRUST_TOP_LEVEL_NAME;
2270 e->time = 0; /* so far always 0 in trces. */
2271 e->forest_trust_data.top_level_name.string = talloc_steal(info,
2272 dom_info->dns_forest);
2274 info->entries[0] = e;
2276 e = talloc(info, struct lsa_ForestTrustRecord);
2278 return NT_STATUS_NO_MEMORY;
2281 /* TODO: check if disabled and set flags accordingly */
2283 e->type = LSA_FOREST_TRUST_DOMAIN_INFO;
2284 e->time = 0; /* so far always 0 in traces. */
2286 domain_info = &e->forest_trust_data.domain_info;
2287 domain_info->domain_sid = dom_sid_dup(info, &dom_info->sid);
2289 domain_info->dns_domain_name.string = talloc_steal(info,
2290 dom_info->dns_domain);
2291 domain_info->netbios_domain_name.string = talloc_steal(info,
2294 info->entries[1] = e;
2296 return NT_STATUS_OK;
2299 /****************************************************************
2300 _netr_GetForestTrustInformation
2301 ****************************************************************/
2303 NTSTATUS _netr_GetForestTrustInformation(struct pipes_struct *p,
2304 struct netr_GetForestTrustInformation *r)
2307 struct netlogon_creds_CredentialState *creds;
2308 struct lsa_ForestTrustInformation *info, **info_ptr;
2309 struct loadparm_context *lp_ctx;
2311 /* TODO: check server name */
2313 lp_ctx = loadparm_init_s3(p->mem_ctx, loadparm_s3_context());
2314 if (lp_ctx == NULL) {
2315 DEBUG(0, ("loadparm_init_s3 failed\n"));
2316 return NT_STATUS_INTERNAL_ERROR;
2319 status = schannel_check_creds_state(p->mem_ctx, lp_ctx,
2320 r->in.computer_name,
2322 r->out.return_authenticator,
2324 talloc_unlink(p->mem_ctx, lp_ctx);
2325 if (!NT_STATUS_IS_OK(status)) {
2329 if ((creds->secure_channel_type != SEC_CHAN_DNS_DOMAIN) &&
2330 (creds->secure_channel_type != SEC_CHAN_DOMAIN)) {
2331 return NT_STATUS_NOT_IMPLEMENTED;
2334 info_ptr = talloc(p->mem_ctx, struct lsa_ForestTrustInformation *);
2336 return NT_STATUS_NO_MEMORY;
2338 info = talloc_zero(info_ptr, struct lsa_ForestTrustInformation);
2340 return NT_STATUS_NO_MEMORY;
2343 status = fill_forest_trust_array(p->mem_ctx, info);
2344 if (!NT_STATUS_IS_OK(status)) {
2349 r->out.forest_trust_info = info_ptr;
2351 return NT_STATUS_OK;
2354 /****************************************************************
2355 ****************************************************************/
2357 static NTSTATUS get_password_from_trustAuth(TALLOC_CTX *mem_ctx,
2358 const DATA_BLOB *trustAuth_blob,
2359 const DATA_BLOB *session_key,
2360 struct samr_Password *current_pw_enc,
2361 struct samr_Password *previous_pw_enc)
2363 enum ndr_err_code ndr_err;
2364 struct trustAuthInOutBlob trustAuth;
2366 ndr_err = ndr_pull_struct_blob_all(trustAuth_blob, mem_ctx, &trustAuth,
2367 (ndr_pull_flags_fn_t)ndr_pull_trustAuthInOutBlob);
2368 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2369 return NT_STATUS_UNSUCCESSFUL;
2373 if (trustAuth.count != 0 && trustAuth.current.count != 0 &&
2374 trustAuth.current.array[0].AuthType == TRUST_AUTH_TYPE_CLEAR) {
2375 mdfour(previous_pw_enc->hash,
2376 trustAuth.current.array[0].AuthInfo.clear.password,
2377 trustAuth.current.array[0].AuthInfo.clear.size);
2379 return NT_STATUS_UNSUCCESSFUL;
2382 arcfour_crypt_blob(current_pw_enc->hash, sizeof(current_pw_enc->hash),
2385 if (trustAuth.previous.count != 0 &&
2386 trustAuth.previous.array[0].AuthType == TRUST_AUTH_TYPE_CLEAR) {
2387 mdfour(previous_pw_enc->hash,
2388 trustAuth.previous.array[0].AuthInfo.clear.password,
2389 trustAuth.previous.array[0].AuthInfo.clear.size);
2391 mdfour(previous_pw_enc->hash, NULL, 0);
2393 arcfour_crypt_blob(previous_pw_enc->hash, sizeof(previous_pw_enc->hash),
2396 return NT_STATUS_OK;
2399 /****************************************************************
2400 _netr_ServerGetTrustInfo
2401 ****************************************************************/
2403 NTSTATUS _netr_ServerGetTrustInfo(struct pipes_struct *p,
2404 struct netr_ServerGetTrustInfo *r)
2407 struct netlogon_creds_CredentialState *creds;
2409 size_t account_name_last;
2411 struct netr_TrustInfo *trust_info;
2412 struct pdb_trusted_domain *td;
2413 DATA_BLOB trustAuth_blob;
2414 struct samr_Password *new_owf_enc;
2415 struct samr_Password *old_owf_enc;
2416 DATA_BLOB session_key;
2417 struct loadparm_context *lp_ctx;
2419 lp_ctx = loadparm_init_s3(p->mem_ctx, loadparm_s3_context());
2420 if (lp_ctx == NULL) {
2421 DEBUG(0, ("loadparm_init_s3 failed\n"));
2422 return NT_STATUS_INTERNAL_ERROR;
2425 /* TODO: check server name */
2427 status = schannel_check_creds_state(p->mem_ctx, lp_ctx,
2428 r->in.computer_name,
2430 r->out.return_authenticator,
2432 talloc_unlink(p->mem_ctx, lp_ctx);
2433 if (!NT_STATUS_IS_OK(status)) {
2437 account_name = talloc_strdup(p->mem_ctx, r->in.account_name);
2438 if (account_name == NULL) {
2439 return NT_STATUS_NO_MEMORY;
2442 account_name_last = strlen(account_name);
2443 if (account_name_last == 0) {
2444 return NT_STATUS_INVALID_PARAMETER;
2446 account_name_last--;
2447 if (account_name[account_name_last] == '.') {
2448 account_name[account_name_last] = '\0';
2451 if ((creds->secure_channel_type != SEC_CHAN_DNS_DOMAIN) &&
2452 (creds->secure_channel_type != SEC_CHAN_DOMAIN)) {
2460 account_name_last = strlen(account_name);
2461 if (account_name_last == 0) {
2462 return NT_STATUS_INVALID_PARAMETER;
2464 account_name_last--;
2465 if (account_name[account_name_last] == '$') {
2466 account_name[account_name_last] = '\0';
2469 status = pdb_get_trusted_domain(p->mem_ctx, account_name, &td);
2470 if (!NT_STATUS_IS_OK(status)) {
2474 if (r->out.trust_info != NULL) {
2475 trust_info = talloc_zero(p->mem_ctx, struct netr_TrustInfo);
2476 if (trust_info == NULL) {
2477 return NT_STATUS_NO_MEMORY;
2479 trust_info->count = 1;
2481 trust_info->data = talloc_array(trust_info, uint32_t, 1);
2482 if (trust_info->data == NULL) {
2483 return NT_STATUS_NO_MEMORY;
2485 trust_info->data[0] = td->trust_attributes;
2487 *r->out.trust_info = trust_info;
2490 new_owf_enc = talloc_zero(p->mem_ctx, struct samr_Password);
2491 old_owf_enc = talloc_zero(p->mem_ctx, struct samr_Password);
2492 if (new_owf_enc == NULL || old_owf_enc == NULL) {
2493 return NT_STATUS_NO_MEMORY;
2496 /* TODO: which trustAuth shall we use if we have in/out trust or do they have to
2498 if (td->trust_direction & NETR_TRUST_FLAG_INBOUND) {
2499 trustAuth_blob = td->trust_auth_incoming;
2500 } else if (td->trust_direction & NETR_TRUST_FLAG_OUTBOUND) {
2501 trustAuth_blob = td->trust_auth_outgoing;
2504 session_key.data = creds->session_key;
2505 session_key.length = sizeof(creds->session_key);
2506 status = get_password_from_trustAuth(p->mem_ctx, &trustAuth_blob,
2508 new_owf_enc, old_owf_enc);
2510 if (!NT_STATUS_IS_OK(status)) {
2514 r->out.new_owf_password = new_owf_enc;
2515 r->out.old_owf_password = old_owf_enc;
2517 /* TODO: look for machine password */
2518 r->out.new_owf_password = NULL;
2519 r->out.old_owf_password = NULL;
2521 return NT_STATUS_NOT_IMPLEMENTED;
2524 return NT_STATUS_OK;
2527 /****************************************************************
2528 ****************************************************************/
2530 NTSTATUS _netr_Unused47(struct pipes_struct *p,
2531 struct netr_Unused47 *r)
2533 p->rng_fault_state = true;
2534 return NT_STATUS_NOT_IMPLEMENTED;
2537 /****************************************************************
2538 ****************************************************************/
2540 NTSTATUS _netr_DsrUpdateReadOnlyServerDnsRecords(struct pipes_struct *p,
2541 struct netr_DsrUpdateReadOnlyServerDnsRecords *r)
2543 p->rng_fault_state = true;
2544 return NT_STATUS_NOT_IMPLEMENTED;