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"
41 extern userdom_struct current_user_info;
44 #define DBGC_CLASS DBGC_RPC_SRV
46 struct netlogon_server_pipe_state {
47 struct netr_Credential client_challenge;
48 struct netr_Credential server_challenge;
51 /*************************************************************************
53 *************************************************************************/
55 WERROR _netr_LogonControl(struct pipes_struct *p,
56 struct netr_LogonControl *r)
58 struct netr_LogonControl2Ex l;
60 switch (r->in.level) {
64 return WERR_NOT_SUPPORTED;
66 return WERR_UNKNOWN_LEVEL;
69 l.in.logon_server = r->in.logon_server;
70 l.in.function_code = r->in.function_code;
71 l.in.level = r->in.level;
73 l.out.query = r->out.query;
75 return _netr_LogonControl2Ex(p, &l);
78 /****************************************************************************
79 Send a message to smbd to do a sam synchronisation
80 **************************************************************************/
82 static void send_sync_message(struct messaging_context *msg_ctx)
84 DEBUG(3, ("sending sam synchronisation message\n"));
85 message_send_all(msg_ctx, MSG_SMB_SAM_SYNC, NULL, 0, NULL);
88 /*************************************************************************
90 *************************************************************************/
92 WERROR _netr_LogonControl2(struct pipes_struct *p,
93 struct netr_LogonControl2 *r)
95 struct netr_LogonControl2Ex l;
97 l.in.logon_server = r->in.logon_server;
98 l.in.function_code = r->in.function_code;
99 l.in.level = r->in.level;
100 l.in.data = r->in.data;
101 l.out.query = r->out.query;
103 return _netr_LogonControl2Ex(p, &l);
106 /*************************************************************************
107 *************************************************************************/
109 static bool wb_change_trust_creds(const char *domain, WERROR *tc_status)
112 struct wbcAuthErrorInfo *error = NULL;
114 result = wbcChangeTrustCredentials(domain, &error);
116 case WBC_ERR_WINBIND_NOT_AVAILABLE:
118 case WBC_ERR_DOMAIN_NOT_FOUND:
119 *tc_status = WERR_NO_SUCH_DOMAIN;
121 case WBC_ERR_SUCCESS:
122 *tc_status = WERR_OK;
128 if (error && error->nt_status != 0) {
129 *tc_status = ntstatus_to_werror(NT_STATUS(error->nt_status));
131 *tc_status = WERR_TRUST_FAILURE;
133 wbcFreeMemory(error);
137 /*************************************************************************
138 *************************************************************************/
140 static bool wb_check_trust_creds(const char *domain, WERROR *tc_status)
143 struct wbcAuthErrorInfo *error = NULL;
145 result = wbcCheckTrustCredentials(domain, &error);
147 case WBC_ERR_WINBIND_NOT_AVAILABLE:
149 case WBC_ERR_DOMAIN_NOT_FOUND:
150 *tc_status = WERR_NO_SUCH_DOMAIN;
152 case WBC_ERR_SUCCESS:
153 *tc_status = WERR_OK;
159 if (error && error->nt_status != 0) {
160 *tc_status = ntstatus_to_werror(NT_STATUS(error->nt_status));
162 *tc_status = WERR_TRUST_FAILURE;
164 wbcFreeMemory(error);
168 /****************************************************************
169 _netr_LogonControl2Ex
170 ****************************************************************/
172 WERROR _netr_LogonControl2Ex(struct pipes_struct *p,
173 struct netr_LogonControl2Ex *r)
175 uint32_t flags = 0x0;
176 WERROR pdc_connection_status = WERR_OK;
177 uint32_t logon_attempts = 0x0;
180 const char *dc_name = NULL;
181 struct sockaddr_storage dc_ss;
182 const char *domain = NULL;
183 struct netr_NETLOGON_INFO_1 *info1;
184 struct netr_NETLOGON_INFO_2 *info2;
185 struct netr_NETLOGON_INFO_3 *info3;
186 struct netr_NETLOGON_INFO_4 *info4;
191 case NDR_NETR_LOGONCONTROL:
192 fn = "_netr_LogonControl";
194 case NDR_NETR_LOGONCONTROL2:
195 fn = "_netr_LogonControl2";
197 case NDR_NETR_LOGONCONTROL2EX:
198 fn = "_netr_LogonControl2Ex";
201 return WERR_INVALID_PARAM;
204 acct_ctrl = p->server_info->info3->base.acct_flags;
206 switch (r->in.function_code) {
207 case NETLOGON_CONTROL_TC_VERIFY:
208 case NETLOGON_CONTROL_CHANGE_PASSWORD:
209 case NETLOGON_CONTROL_REDISCOVER:
210 if ((geteuid() != sec_initial_uid()) &&
211 !nt_token_check_domain_rid(p->server_info->security_token, DOMAIN_RID_ADMINS) &&
212 !nt_token_check_sid(&global_sid_Builtin_Administrators, p->server_info->security_token) &&
213 !(acct_ctrl & (ACB_WSTRUST | ACB_SVRTRUST))) {
214 return WERR_ACCESS_DENIED;
221 tc_status = WERR_NO_SUCH_DOMAIN;
223 switch (r->in.function_code) {
224 case NETLOGON_CONTROL_QUERY:
227 case NETLOGON_CONTROL_REPLICATE:
228 case NETLOGON_CONTROL_SYNCHRONIZE:
229 case NETLOGON_CONTROL_PDC_REPLICATE:
230 case NETLOGON_CONTROL_BACKUP_CHANGE_LOG:
231 case NETLOGON_CONTROL_BREAKPOINT:
232 if (acct_ctrl & ACB_NORMAL) {
233 return WERR_NOT_SUPPORTED;
234 } else if (acct_ctrl & (ACB_WSTRUST | ACB_SVRTRUST)) {
235 return WERR_ACCESS_DENIED;
237 return WERR_ACCESS_DENIED;
239 case NETLOGON_CONTROL_TRUNCATE_LOG:
240 if (acct_ctrl & ACB_NORMAL) {
242 } else if (acct_ctrl & (ACB_WSTRUST | ACB_SVRTRUST)) {
243 return WERR_ACCESS_DENIED;
245 return WERR_ACCESS_DENIED;
248 case NETLOGON_CONTROL_TRANSPORT_NOTIFY:
249 case NETLOGON_CONTROL_FORCE_DNS_REG:
250 case NETLOGON_CONTROL_QUERY_DNS_REG:
251 return WERR_NOT_SUPPORTED;
252 case NETLOGON_CONTROL_FIND_USER:
253 if (!r->in.data || !r->in.data->user) {
254 return WERR_NOT_SUPPORTED;
257 case NETLOGON_CONTROL_SET_DBFLAG:
259 return WERR_NOT_SUPPORTED;
262 case NETLOGON_CONTROL_TC_VERIFY:
263 if (!r->in.data || !r->in.data->domain) {
264 return WERR_NOT_SUPPORTED;
267 if (!wb_check_trust_creds(r->in.data->domain, &tc_status)) {
268 return WERR_NOT_SUPPORTED;
271 case NETLOGON_CONTROL_TC_QUERY:
272 if (!r->in.data || !r->in.data->domain) {
273 return WERR_NOT_SUPPORTED;
276 domain = r->in.data->domain;
278 if (!is_trusted_domain(domain)) {
282 if (!get_dc_name(domain, NULL, dc_name2, &dc_ss)) {
283 tc_status = WERR_NO_LOGON_SERVERS;
287 dc_name = talloc_asprintf(p->mem_ctx, "\\\\%s", dc_name2);
296 case NETLOGON_CONTROL_REDISCOVER:
297 if (!r->in.data || !r->in.data->domain) {
298 return WERR_NOT_SUPPORTED;
301 domain = r->in.data->domain;
303 if (!is_trusted_domain(domain)) {
307 if (!get_dc_name(domain, NULL, dc_name2, &dc_ss)) {
308 tc_status = WERR_NO_LOGON_SERVERS;
312 dc_name = talloc_asprintf(p->mem_ctx, "\\\\%s", dc_name2);
321 case NETLOGON_CONTROL_CHANGE_PASSWORD:
322 if (!r->in.data || !r->in.data->domain) {
323 return WERR_NOT_SUPPORTED;
326 if (!wb_change_trust_creds(r->in.data->domain, &tc_status)) {
327 return WERR_NOT_SUPPORTED;
332 /* no idea what this should be */
333 DEBUG(0,("%s: unimplemented function level [%d]\n",
334 fn, r->in.function_code));
335 return WERR_UNKNOWN_LEVEL;
338 /* prepare the response */
340 switch (r->in.level) {
342 info1 = TALLOC_ZERO_P(p->mem_ctx, struct netr_NETLOGON_INFO_1);
343 W_ERROR_HAVE_NO_MEMORY(info1);
345 info1->flags = flags;
346 info1->pdc_connection_status = pdc_connection_status;
348 r->out.query->info1 = info1;
351 info2 = TALLOC_ZERO_P(p->mem_ctx, struct netr_NETLOGON_INFO_2);
352 W_ERROR_HAVE_NO_MEMORY(info2);
354 info2->flags = flags;
355 info2->pdc_connection_status = pdc_connection_status;
356 info2->trusted_dc_name = dc_name;
357 info2->tc_connection_status = tc_status;
359 r->out.query->info2 = info2;
362 info3 = TALLOC_ZERO_P(p->mem_ctx, struct netr_NETLOGON_INFO_3);
363 W_ERROR_HAVE_NO_MEMORY(info3);
365 info3->flags = flags;
366 info3->logon_attempts = logon_attempts;
368 r->out.query->info3 = info3;
371 info4 = TALLOC_ZERO_P(p->mem_ctx, struct netr_NETLOGON_INFO_4);
372 W_ERROR_HAVE_NO_MEMORY(info4);
374 info4->trusted_dc_name = dc_name;
375 info4->trusted_domain_name = r->in.data->domain;
377 r->out.query->info4 = info4;
380 return WERR_UNKNOWN_LEVEL;
383 if (lp_server_role() == ROLE_DOMAIN_BDC) {
384 send_sync_message(p->msg_ctx);
390 /*************************************************************************
391 _netr_NetrEnumerateTrustedDomains
392 *************************************************************************/
394 NTSTATUS _netr_NetrEnumerateTrustedDomains(struct pipes_struct *p,
395 struct netr_NetrEnumerateTrustedDomains *r)
398 NTSTATUS result = NT_STATUS_OK;
401 const char **trusted_domains = NULL;
402 struct lsa_DomainList domain_list;
403 struct dcerpc_binding_handle *h = NULL;
404 struct policy_handle pol;
405 uint32_t enum_ctx = 0;
407 uint32_t max_size = (uint32_t)-1;
409 DEBUG(6,("_netr_NetrEnumerateTrustedDomains: %d\n", __LINE__));
411 status = rpcint_binding_handle(p->mem_ctx,
417 if (!NT_STATUS_IS_OK(status)) {
421 status = dcerpc_lsa_open_policy2(h,
425 LSA_POLICY_VIEW_LOCAL_INFORMATION,
428 if (!NT_STATUS_IS_OK(status)) {
431 if (!NT_STATUS_IS_OK(result)) {
437 /* Lookup list of trusted domains */
438 status = dcerpc_lsa_EnumTrustDom(h,
445 if (!NT_STATUS_IS_OK(status)) {
448 if (!NT_STATUS_IS_OK(result) &&
449 !NT_STATUS_EQUAL(result, NT_STATUS_NO_MORE_ENTRIES) &&
450 !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)) {
455 for (i = 0; i < domain_list.count; i++) {
456 if (!add_string_to_array(p->mem_ctx, domain_list.domains[i].name.string,
457 &trusted_domains, &num_domains)) {
458 status = NT_STATUS_NO_MEMORY;
462 } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
464 if (num_domains > 0) {
465 /* multi sz terminate */
466 trusted_domains = talloc_realloc(p->mem_ctx, trusted_domains, const char *, num_domains + 1);
467 if (trusted_domains == NULL) {
468 status = NT_STATUS_NO_MEMORY;
472 trusted_domains[num_domains] = NULL;
475 if (!push_reg_multi_sz(trusted_domains, &blob, trusted_domains)) {
476 TALLOC_FREE(trusted_domains);
477 status = NT_STATUS_NO_MEMORY;
481 r->out.trusted_domains_blob->data = blob.data;
482 r->out.trusted_domains_blob->length = blob.length;
484 DEBUG(6,("_netr_NetrEnumerateTrustedDomains: %d\n", __LINE__));
486 status = NT_STATUS_OK;
489 if (h && is_valid_policy_hnd(&pol)) {
490 dcerpc_lsa_Close(h, p->mem_ctx, &pol, &result);
496 /*************************************************************************
497 *************************************************************************/
499 static NTSTATUS samr_find_machine_account(TALLOC_CTX *mem_ctx,
500 struct dcerpc_binding_handle *b,
501 const char *account_name,
502 uint32_t access_mask,
503 struct dom_sid2 **domain_sid_p,
504 uint32_t *user_rid_p,
505 struct policy_handle *user_handle)
508 NTSTATUS result = NT_STATUS_OK;
509 struct policy_handle connect_handle, domain_handle;
510 struct lsa_String domain_name;
511 struct dom_sid2 *domain_sid;
512 struct lsa_String names;
513 struct samr_Ids rids;
514 struct samr_Ids types;
517 status = dcerpc_samr_Connect2(b, mem_ctx,
519 SAMR_ACCESS_CONNECT_TO_SERVER |
520 SAMR_ACCESS_ENUM_DOMAINS |
521 SAMR_ACCESS_LOOKUP_DOMAIN,
524 if (!NT_STATUS_IS_OK(status)) {
527 if (!NT_STATUS_IS_OK(result)) {
532 init_lsa_String(&domain_name, get_global_sam_name());
534 status = dcerpc_samr_LookupDomain(b, mem_ctx,
539 if (!NT_STATUS_IS_OK(status)) {
542 if (!NT_STATUS_IS_OK(result)) {
547 status = dcerpc_samr_OpenDomain(b, mem_ctx,
549 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
553 if (!NT_STATUS_IS_OK(status)) {
556 if (!NT_STATUS_IS_OK(result)) {
561 init_lsa_String(&names, account_name);
563 status = dcerpc_samr_LookupNames(b, mem_ctx,
570 if (!NT_STATUS_IS_OK(status)) {
573 if (!NT_STATUS_IS_OK(result)) {
578 if (rids.count != 1) {
579 status = NT_STATUS_NO_SUCH_USER;
582 if (rids.count != types.count) {
583 status = NT_STATUS_INVALID_PARAMETER;
586 if (types.ids[0] != SID_NAME_USER) {
587 status = NT_STATUS_NO_SUCH_USER;
593 status = dcerpc_samr_OpenUser(b, mem_ctx,
599 if (!NT_STATUS_IS_OK(status)) {
602 if (!NT_STATUS_IS_OK(result)) {
612 *domain_sid_p = domain_sid;
616 if (b && is_valid_policy_hnd(&domain_handle)) {
617 dcerpc_samr_Close(b, mem_ctx, &domain_handle, &result);
619 if (b && is_valid_policy_hnd(&connect_handle)) {
620 dcerpc_samr_Close(b, mem_ctx, &connect_handle, &result);
626 /******************************************************************
627 gets a machine password entry. checks access rights of the host.
628 ******************************************************************/
630 static NTSTATUS get_md4pw(struct samr_Password *md4pw, const char *mach_acct,
631 enum netr_SchannelType sec_chan_type,
633 struct messaging_context *msg_ctx)
636 NTSTATUS result = NT_STATUS_OK;
638 struct dcerpc_binding_handle *h = NULL;
639 static struct client_address client_id;
640 struct policy_handle user_handle;
642 struct dom_sid *domain_sid;
644 union samr_UserInfo *info;
645 struct auth_serversupplied_info *server_info;
649 * Currently this code is redundent as we already have a filter
650 * by hostname list. What this code really needs to do is to
651 * get a hosts allowed/hosts denied list from the SAM database
652 * on a per user basis, and make the access decision there.
653 * I will leave this code here for now as a reminder to implement
654 * this at a later date. JRA.
657 if (!allow_access(lp_domain_hostsdeny(), lp_domain_hostsallow(),
659 p->client_id.addr)) {
660 DEBUG(0,("get_md4pw: Workstation %s denied access to domain\n", mach_acct));
665 mem_ctx = talloc_stackframe();
666 if (mem_ctx == NULL) {
667 status = NT_STATUS_NO_MEMORY;
671 status = make_server_info_system(mem_ctx, &server_info);
672 if (!NT_STATUS_IS_OK(status)) {
676 ZERO_STRUCT(user_handle);
678 strlcpy(client_id.addr, "127.0.0.1", sizeof(client_id.addr));
679 client_id.name = "127.0.0.1";
681 status = rpcint_binding_handle(mem_ctx,
687 if (!NT_STATUS_IS_OK(status)) {
692 status = samr_find_machine_account(mem_ctx, h, mach_acct,
693 SEC_FLAG_MAXIMUM_ALLOWED,
694 &domain_sid, &user_rid,
697 if (!NT_STATUS_IS_OK(status)) {
701 status = dcerpc_samr_QueryUserInfo2(h,
704 UserControlInformation,
707 if (!NT_STATUS_IS_OK(status)) {
710 if (!NT_STATUS_IS_OK(result)) {
715 acct_ctrl = info->info16.acct_flags;
717 if (acct_ctrl & ACB_DISABLED) {
718 DEBUG(0,("get_md4pw: Workstation %s: account is disabled\n", mach_acct));
719 status = NT_STATUS_ACCOUNT_DISABLED;
723 if (!(acct_ctrl & ACB_SVRTRUST) &&
724 !(acct_ctrl & ACB_WSTRUST) &&
725 !(acct_ctrl & ACB_DOMTRUST))
727 DEBUG(0,("get_md4pw: Workstation %s: account is not a trust account\n", mach_acct));
728 status = NT_STATUS_NO_TRUST_SAM_ACCOUNT;
732 switch (sec_chan_type) {
734 if (!(acct_ctrl & ACB_SVRTRUST)) {
735 DEBUG(0,("get_md4pw: Workstation %s: BDC secure channel requested "
736 "but not a server trust account\n", mach_acct));
737 status = NT_STATUS_NO_TRUST_SAM_ACCOUNT;
742 if (!(acct_ctrl & ACB_WSTRUST)) {
743 DEBUG(0,("get_md4pw: Workstation %s: WORKSTATION secure channel requested "
744 "but not a workstation trust account\n", mach_acct));
745 status = NT_STATUS_NO_TRUST_SAM_ACCOUNT;
749 case SEC_CHAN_DOMAIN:
750 if (!(acct_ctrl & ACB_DOMTRUST)) {
751 DEBUG(0,("get_md4pw: Workstation %s: DOMAIN secure channel requested "
752 "but not a interdomain trust account\n", mach_acct));
753 status = NT_STATUS_NO_TRUST_SAM_ACCOUNT;
762 status = dcerpc_samr_QueryUserInfo2(h,
765 UserInternal1Information,
769 if (!NT_STATUS_IS_OK(status)) {
772 if (!NT_STATUS_IS_OK(result)) {
777 if (info->info18.nt_pwd_active == 0) {
778 DEBUG(0,("get_md4pw: Workstation %s: account does not have a password\n", mach_acct));
779 status = NT_STATUS_LOGON_FAILURE;
783 /* samr gives out nthash unencrypted (!) */
784 memcpy(md4pw->hash, info->info18.nt_pwd.hash, 16);
786 sid_compose(sid, domain_sid, user_rid);
789 if (h && is_valid_policy_hnd(&user_handle)) {
790 dcerpc_samr_Close(h, mem_ctx, &user_handle, &result);
793 talloc_free(mem_ctx);
798 /*************************************************************************
799 _netr_ServerReqChallenge
800 *************************************************************************/
802 NTSTATUS _netr_ServerReqChallenge(struct pipes_struct *p,
803 struct netr_ServerReqChallenge *r)
805 struct netlogon_server_pipe_state *pipe_state =
806 talloc_get_type(p->private_data, struct netlogon_server_pipe_state);
809 DEBUG(10,("_netr_ServerReqChallenge: new challenge requested. Clearing old state.\n"));
810 talloc_free(pipe_state);
811 p->private_data = NULL;
814 pipe_state = talloc(p, struct netlogon_server_pipe_state);
815 NT_STATUS_HAVE_NO_MEMORY(pipe_state);
817 pipe_state->client_challenge = *r->in.credentials;
819 generate_random_buffer(pipe_state->server_challenge.data,
820 sizeof(pipe_state->server_challenge.data));
822 *r->out.return_credentials = pipe_state->server_challenge;
824 p->private_data = pipe_state;
829 /*************************************************************************
830 _netr_ServerAuthenticate
831 Create the initial credentials.
832 *************************************************************************/
834 NTSTATUS _netr_ServerAuthenticate(struct pipes_struct *p,
835 struct netr_ServerAuthenticate *r)
837 struct netr_ServerAuthenticate3 a;
838 uint32_t negotiate_flags = 0;
841 a.in.server_name = r->in.server_name;
842 a.in.account_name = r->in.account_name;
843 a.in.secure_channel_type = r->in.secure_channel_type;
844 a.in.computer_name = r->in.computer_name;
845 a.in.credentials = r->in.credentials;
846 a.in.negotiate_flags = &negotiate_flags;
848 a.out.return_credentials = r->out.return_credentials;
850 a.out.negotiate_flags = &negotiate_flags;
852 return _netr_ServerAuthenticate3(p, &a);
856 /*************************************************************************
857 _netr_ServerAuthenticate3
858 *************************************************************************/
860 NTSTATUS _netr_ServerAuthenticate3(struct pipes_struct *p,
861 struct netr_ServerAuthenticate3 *r)
865 /* r->in.negotiate_flags is an aliased pointer to r->out.negotiate_flags,
866 * so use a copy to avoid destroying the client values. */
867 uint32_t in_neg_flags = *r->in.negotiate_flags;
870 struct samr_Password mach_pwd;
871 struct netlogon_creds_CredentialState *creds;
872 struct netlogon_server_pipe_state *pipe_state =
873 talloc_get_type(p->private_data, struct netlogon_server_pipe_state);
875 /* According to Microsoft (see bugid #6099)
876 * Windows 7 looks at the negotiate_flags
877 * returned in this structure *even if the
878 * call fails with access denied* ! So in order
879 * to allow Win7 to connect to a Samba NT style
880 * PDC we set the flags before we know if it's
885 srv_flgs = NETLOGON_NEG_ACCOUNT_LOCKOUT |
886 NETLOGON_NEG_PERSISTENT_SAMREPL |
887 NETLOGON_NEG_ARCFOUR |
888 NETLOGON_NEG_PROMOTION_COUNT |
889 NETLOGON_NEG_CHANGELOG_BDC |
890 NETLOGON_NEG_FULL_SYNC_REPL |
891 NETLOGON_NEG_MULTIPLE_SIDS |
893 NETLOGON_NEG_PASSWORD_CHANGE_REFUSAL |
894 NETLOGON_NEG_PASSWORD_SET2;
896 /* Ensure we support strong (128-bit) keys. */
897 if (in_neg_flags & NETLOGON_NEG_STRONG_KEYS) {
898 srv_flgs |= NETLOGON_NEG_STRONG_KEYS;
901 if (lp_server_schannel() != false) {
902 srv_flgs |= NETLOGON_NEG_SCHANNEL;
906 case NDR_NETR_SERVERAUTHENTICATE:
907 fn = "_netr_ServerAuthenticate";
909 case NDR_NETR_SERVERAUTHENTICATE2:
910 fn = "_netr_ServerAuthenticate2";
912 case NDR_NETR_SERVERAUTHENTICATE3:
913 fn = "_netr_ServerAuthenticate3";
916 return NT_STATUS_INTERNAL_ERROR;
919 /* We use this as the key to store the creds: */
920 /* r->in.computer_name */
923 DEBUG(0,("%s: no challenge sent to client %s\n", fn,
924 r->in.computer_name));
925 status = NT_STATUS_ACCESS_DENIED;
929 if ( (lp_server_schannel() == true) &&
930 ((in_neg_flags & NETLOGON_NEG_SCHANNEL) == 0) ) {
932 /* schannel must be used, but client did not offer it. */
933 DEBUG(0,("%s: schannel required but client failed "
934 "to offer it. Client was %s\n",
935 fn, r->in.account_name));
936 status = NT_STATUS_ACCESS_DENIED;
940 status = get_md4pw(&mach_pwd,
942 r->in.secure_channel_type,
944 if (!NT_STATUS_IS_OK(status)) {
945 DEBUG(0,("%s: failed to get machine password for "
947 fn, r->in.account_name, nt_errstr(status) ));
948 /* always return NT_STATUS_ACCESS_DENIED */
949 status = NT_STATUS_ACCESS_DENIED;
953 /* From the client / server challenges and md4 password, generate sess key */
954 /* Check client credentials are valid. */
955 creds = netlogon_creds_server_init(p->mem_ctx,
958 r->in.secure_channel_type,
959 &pipe_state->client_challenge,
960 &pipe_state->server_challenge,
963 r->out.return_credentials,
964 *r->in.negotiate_flags);
966 DEBUG(0,("%s: netlogon_creds_server_check failed. Rejecting auth "
967 "request from client %s machine account %s\n",
968 fn, r->in.computer_name,
969 r->in.account_name));
970 status = NT_STATUS_ACCESS_DENIED;
974 creds->sid = dom_sid_dup(creds, &sid);
976 status = NT_STATUS_NO_MEMORY;
980 /* Store off the state so we can continue after client disconnect. */
982 status = schannel_save_creds_state(p->mem_ctx, lp_private_dir(), creds);
985 if (!NT_STATUS_IS_OK(status)) {
989 sid_peek_rid(&sid, r->out.rid);
991 status = NT_STATUS_OK;
995 *r->out.negotiate_flags = srv_flgs;
999 /*************************************************************************
1000 _netr_ServerAuthenticate2
1001 *************************************************************************/
1003 NTSTATUS _netr_ServerAuthenticate2(struct pipes_struct *p,
1004 struct netr_ServerAuthenticate2 *r)
1006 struct netr_ServerAuthenticate3 a;
1009 a.in.server_name = r->in.server_name;
1010 a.in.account_name = r->in.account_name;
1011 a.in.secure_channel_type = r->in.secure_channel_type;
1012 a.in.computer_name = r->in.computer_name;
1013 a.in.credentials = r->in.credentials;
1014 a.in.negotiate_flags = r->in.negotiate_flags;
1016 a.out.return_credentials = r->out.return_credentials;
1018 a.out.negotiate_flags = r->out.negotiate_flags;
1020 return _netr_ServerAuthenticate3(p, &a);
1023 /*************************************************************************
1024 * If schannel is required for this call test that it actually is available.
1025 *************************************************************************/
1026 static NTSTATUS schannel_check_required(struct pipe_auth_data *auth_info,
1027 const char *computer_name,
1028 bool integrity, bool privacy)
1030 if (auth_info && auth_info->auth_type == DCERPC_AUTH_TYPE_SCHANNEL) {
1031 if (!privacy && !integrity) {
1032 return NT_STATUS_OK;
1035 if ((!privacy && integrity) &&
1036 auth_info->auth_level == DCERPC_AUTH_LEVEL_INTEGRITY) {
1037 return NT_STATUS_OK;
1040 if ((privacy || integrity) &&
1041 auth_info->auth_level == DCERPC_AUTH_LEVEL_PRIVACY) {
1042 return NT_STATUS_OK;
1046 /* test didn't pass */
1047 DEBUG(0, ("schannel_check_required: [%s] is not using schannel\n",
1050 return NT_STATUS_ACCESS_DENIED;
1053 /*************************************************************************
1054 *************************************************************************/
1056 static NTSTATUS netr_creds_server_step_check(struct pipes_struct *p,
1057 TALLOC_CTX *mem_ctx,
1058 const char *computer_name,
1059 struct netr_Authenticator *received_authenticator,
1060 struct netr_Authenticator *return_authenticator,
1061 struct netlogon_creds_CredentialState **creds_out)
1064 bool schannel_global_required = (lp_server_schannel() == true) ? true:false;
1066 if (schannel_global_required) {
1067 status = schannel_check_required(&p->auth,
1070 if (!NT_STATUS_IS_OK(status)) {
1075 status = schannel_check_creds_state(mem_ctx, lp_private_dir(),
1076 computer_name, received_authenticator,
1077 return_authenticator, creds_out);
1082 /*************************************************************************
1083 *************************************************************************/
1085 static NTSTATUS netr_set_machine_account_password(TALLOC_CTX *mem_ctx,
1086 struct auth_serversupplied_info *server_info,
1087 struct messaging_context *msg_ctx,
1088 const char *account_name,
1089 struct samr_Password *nt_hash)
1092 NTSTATUS result = NT_STATUS_OK;
1093 struct dcerpc_binding_handle *h = NULL;
1094 static struct client_address client_id;
1095 struct policy_handle user_handle;
1097 union samr_UserInfo *info;
1098 struct samr_UserInfo18 info18;
1101 ZERO_STRUCT(user_handle);
1103 strlcpy(client_id.addr, "127.0.0.1", sizeof(client_id.addr));
1104 client_id.name = "127.0.0.1";
1106 status = rpcint_binding_handle(mem_ctx,
1112 if (!NT_STATUS_IS_OK(status)) {
1116 status = samr_find_machine_account(mem_ctx,
1119 SEC_FLAG_MAXIMUM_ALLOWED,
1123 if (!NT_STATUS_IS_OK(status)) {
1127 status = dcerpc_samr_QueryUserInfo2(h,
1130 UserControlInformation,
1133 if (!NT_STATUS_IS_OK(status)) {
1136 if (!NT_STATUS_IS_OK(result)) {
1141 acct_ctrl = info->info16.acct_flags;
1143 if (!(acct_ctrl & ACB_WSTRUST ||
1144 acct_ctrl & ACB_SVRTRUST ||
1145 acct_ctrl & ACB_DOMTRUST)) {
1146 status = NT_STATUS_NO_SUCH_USER;
1150 if (acct_ctrl & ACB_DISABLED) {
1151 status = NT_STATUS_ACCOUNT_DISABLED;
1155 ZERO_STRUCT(info18);
1157 in = data_blob_const(nt_hash->hash, 16);
1158 out = data_blob_talloc_zero(mem_ctx, 16);
1159 sess_crypt_blob(&out, &in, &server_info->user_session_key, true);
1160 memcpy(info18.nt_pwd.hash, out.data, out.length);
1162 info18.nt_pwd_active = true;
1164 info->info18 = info18;
1166 status = dcerpc_samr_SetUserInfo2(h,
1169 UserInternal1Information,
1172 if (!NT_STATUS_IS_OK(status)) {
1175 if (!NT_STATUS_IS_OK(result)) {
1181 if (h && is_valid_policy_hnd(&user_handle)) {
1182 dcerpc_samr_Close(h, mem_ctx, &user_handle, &result);
1188 /*************************************************************************
1189 _netr_ServerPasswordSet
1190 *************************************************************************/
1192 NTSTATUS _netr_ServerPasswordSet(struct pipes_struct *p,
1193 struct netr_ServerPasswordSet *r)
1195 NTSTATUS status = NT_STATUS_OK;
1197 struct netlogon_creds_CredentialState *creds;
1199 DEBUG(5,("_netr_ServerPasswordSet: %d\n", __LINE__));
1202 status = netr_creds_server_step_check(p, p->mem_ctx,
1203 r->in.computer_name,
1205 r->out.return_authenticator,
1209 if (!NT_STATUS_IS_OK(status)) {
1210 DEBUG(2,("_netr_ServerPasswordSet: netlogon_creds_server_step failed. Rejecting auth "
1211 "request from client %s machine account %s\n",
1212 r->in.computer_name, creds->computer_name));
1217 DEBUG(3,("_netr_ServerPasswordSet: Server Password Set by remote machine:[%s] on account [%s]\n",
1218 r->in.computer_name, creds->computer_name));
1220 netlogon_creds_des_decrypt(creds, r->in.new_password);
1222 DEBUG(100,("_netr_ServerPasswordSet: new given value was :\n"));
1223 for(i = 0; i < sizeof(r->in.new_password->hash); i++)
1224 DEBUG(100,("%02X ", r->in.new_password->hash[i]));
1227 status = netr_set_machine_account_password(p->mem_ctx,
1230 creds->account_name,
1231 r->in.new_password);
1235 /****************************************************************
1236 _netr_ServerPasswordSet2
1237 ****************************************************************/
1239 NTSTATUS _netr_ServerPasswordSet2(struct pipes_struct *p,
1240 struct netr_ServerPasswordSet2 *r)
1243 struct netlogon_creds_CredentialState *creds;
1244 DATA_BLOB plaintext;
1245 struct samr_CryptPassword password_buf;
1246 struct samr_Password nt_hash;
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_ServerPasswordSet2: netlogon_creds_server_step "
1258 "failed. Rejecting auth request from client %s machine account %s\n",
1259 r->in.computer_name, creds->computer_name));
1264 memcpy(password_buf.data, r->in.new_password->data, 512);
1265 SIVAL(password_buf.data, 512, r->in.new_password->length);
1266 netlogon_creds_arcfour_crypt(creds, password_buf.data, 516);
1268 if (!extract_pw_from_buffer(p->mem_ctx, password_buf.data, &plaintext)) {
1269 return NT_STATUS_WRONG_PASSWORD;
1272 mdfour(nt_hash.hash, plaintext.data, plaintext.length);
1274 status = netr_set_machine_account_password(p->mem_ctx,
1277 creds->account_name,
1282 /*************************************************************************
1283 _netr_LogonSamLogoff
1284 *************************************************************************/
1286 NTSTATUS _netr_LogonSamLogoff(struct pipes_struct *p,
1287 struct netr_LogonSamLogoff *r)
1290 struct netlogon_creds_CredentialState *creds;
1293 status = netr_creds_server_step_check(p, p->mem_ctx,
1294 r->in.computer_name,
1296 r->out.return_authenticator,
1303 static NTSTATUS _netr_LogonSamLogon_check(const struct netr_LogonSamLogonEx *r)
1305 switch (r->in.logon_level) {
1306 case NetlogonInteractiveInformation:
1307 case NetlogonServiceInformation:
1308 case NetlogonInteractiveTransitiveInformation:
1309 case NetlogonServiceTransitiveInformation:
1310 if (r->in.logon->password == NULL) {
1311 return NT_STATUS_INVALID_PARAMETER;
1314 switch (r->in.validation_level) {
1315 case NetlogonValidationSamInfo: /* 2 */
1316 case NetlogonValidationSamInfo2: /* 3 */
1318 case NetlogonValidationSamInfo4: /* 6 */
1319 if ((pdb_capabilities() & PDB_CAP_ADS) == 0) {
1320 DEBUG(10,("Not adding validation info level 6 "
1321 "without ADS passdb backend\n"));
1322 return NT_STATUS_INVALID_INFO_CLASS;
1326 return NT_STATUS_INVALID_INFO_CLASS;
1330 case NetlogonNetworkInformation:
1331 case NetlogonNetworkTransitiveInformation:
1332 if (r->in.logon->network == NULL) {
1333 return NT_STATUS_INVALID_PARAMETER;
1336 switch (r->in.validation_level) {
1337 case NetlogonValidationSamInfo: /* 2 */
1338 case NetlogonValidationSamInfo2: /* 3 */
1340 case NetlogonValidationSamInfo4: /* 6 */
1341 if ((pdb_capabilities() & PDB_CAP_ADS) == 0) {
1342 DEBUG(10,("Not adding validation info level 6 "
1343 "without ADS passdb backend\n"));
1344 return NT_STATUS_INVALID_INFO_CLASS;
1348 return NT_STATUS_INVALID_INFO_CLASS;
1353 case NetlogonGenericInformation:
1354 if (r->in.logon->generic == NULL) {
1355 return NT_STATUS_INVALID_PARAMETER;
1358 /* we don't support this here */
1359 return NT_STATUS_INVALID_PARAMETER;
1361 switch (r->in.validation_level) {
1362 /* TODO: case NetlogonValidationGenericInfo: 4 */
1363 case NetlogonValidationGenericInfo2: /* 5 */
1366 return NT_STATUS_INVALID_INFO_CLASS;
1372 return NT_STATUS_INVALID_PARAMETER;
1375 return NT_STATUS_OK;
1378 /*************************************************************************
1379 _netr_LogonSamLogon_base
1380 *************************************************************************/
1382 static NTSTATUS _netr_LogonSamLogon_base(struct pipes_struct *p,
1383 struct netr_LogonSamLogonEx *r,
1384 struct netlogon_creds_CredentialState *creds)
1386 NTSTATUS status = NT_STATUS_OK;
1387 union netr_LogonLevel *logon = r->in.logon;
1388 const char *nt_username, *nt_domain, *nt_workstation;
1389 struct auth_usersupplied_info *user_info = NULL;
1390 struct auth_serversupplied_info *server_info = NULL;
1391 struct auth_context *auth_context = NULL;
1392 uint8_t pipe_session_key[16];
1393 bool process_creds = true;
1397 case NDR_NETR_LOGONSAMLOGON:
1398 process_creds = true;
1399 fn = "_netr_LogonSamLogon";
1401 case NDR_NETR_LOGONSAMLOGONWITHFLAGS:
1402 process_creds = true;
1403 fn = "_netr_LogonSamLogonWithFlags";
1405 case NDR_NETR_LOGONSAMLOGONEX:
1406 process_creds = false;
1407 fn = "_netr_LogonSamLogonEx";
1410 return NT_STATUS_INTERNAL_ERROR;
1413 *r->out.authoritative = true; /* authoritative response */
1415 switch (r->in.validation_level) {
1417 r->out.validation->sam2 = TALLOC_ZERO_P(p->mem_ctx, struct netr_SamInfo2);
1418 if (!r->out.validation->sam2) {
1419 return NT_STATUS_NO_MEMORY;
1423 r->out.validation->sam3 = TALLOC_ZERO_P(p->mem_ctx, struct netr_SamInfo3);
1424 if (!r->out.validation->sam3) {
1425 return NT_STATUS_NO_MEMORY;
1429 r->out.validation->sam6 = TALLOC_ZERO_P(p->mem_ctx, struct netr_SamInfo6);
1430 if (!r->out.validation->sam6) {
1431 return NT_STATUS_NO_MEMORY;
1435 DEBUG(0,("%s: bad validation_level value %d.\n",
1436 fn, (int)r->in.validation_level));
1437 return NT_STATUS_INVALID_INFO_CLASS;
1440 switch (r->in.logon_level) {
1441 case NetlogonInteractiveInformation:
1442 case NetlogonServiceInformation:
1443 case NetlogonInteractiveTransitiveInformation:
1444 case NetlogonServiceTransitiveInformation:
1445 nt_username = logon->password->identity_info.account_name.string ?
1446 logon->password->identity_info.account_name.string : "";
1447 nt_domain = logon->password->identity_info.domain_name.string ?
1448 logon->password->identity_info.domain_name.string : "";
1449 nt_workstation = logon->password->identity_info.workstation.string ?
1450 logon->password->identity_info.workstation.string : "";
1452 DEBUG(3,("SAM Logon (Interactive). Domain:[%s]. ", lp_workgroup()));
1454 case NetlogonNetworkInformation:
1455 case NetlogonNetworkTransitiveInformation:
1456 nt_username = logon->network->identity_info.account_name.string ?
1457 logon->network->identity_info.account_name.string : "";
1458 nt_domain = logon->network->identity_info.domain_name.string ?
1459 logon->network->identity_info.domain_name.string : "";
1460 nt_workstation = logon->network->identity_info.workstation.string ?
1461 logon->network->identity_info.workstation.string : "";
1463 DEBUG(3,("SAM Logon (Network). Domain:[%s]. ", lp_workgroup()));
1466 DEBUG(2,("SAM Logon: unsupported switch value\n"));
1467 return NT_STATUS_INVALID_INFO_CLASS;
1470 DEBUG(3,("User:[%s@%s] Requested Domain:[%s]\n", nt_username, nt_workstation, nt_domain));
1471 fstrcpy(current_user_info.smb_name, nt_username);
1472 sub_set_smb_name(nt_username);
1474 DEBUG(5,("Attempting validation level %d for unmapped username %s.\n",
1475 r->in.validation_level, nt_username));
1477 status = NT_STATUS_OK;
1479 switch (r->in.logon_level) {
1480 case NetlogonNetworkInformation:
1481 case NetlogonNetworkTransitiveInformation:
1483 const char *wksname = nt_workstation;
1485 status = make_auth_context_fixed(talloc_tos(), &auth_context,
1486 logon->network->challenge);
1487 if (!NT_STATUS_IS_OK(status)) {
1491 /* For a network logon, the workstation name comes in with two
1492 * backslashes in the front. Strip them if they are there. */
1494 if (*wksname == '\\') wksname++;
1495 if (*wksname == '\\') wksname++;
1497 /* Standard challenge/response authentication */
1498 if (!make_user_info_netlogon_network(&user_info,
1499 nt_username, nt_domain,
1501 logon->network->identity_info.parameter_control,
1502 logon->network->lm.data,
1503 logon->network->lm.length,
1504 logon->network->nt.data,
1505 logon->network->nt.length)) {
1506 status = NT_STATUS_NO_MEMORY;
1510 case NetlogonInteractiveInformation:
1511 case NetlogonServiceInformation:
1512 case NetlogonInteractiveTransitiveInformation:
1513 case NetlogonServiceTransitiveInformation:
1515 /* 'Interactive' authentication, supplies the password in its
1516 MD4 form, encrypted with the session key. We will convert
1517 this to challenge/response for the auth subsystem to chew
1522 status = make_auth_context_subsystem(talloc_tos(),
1524 if (!NT_STATUS_IS_OK(status)) {
1528 auth_context->get_ntlm_challenge(auth_context, chal);
1530 if (!make_user_info_netlogon_interactive(&user_info,
1531 nt_username, nt_domain,
1533 logon->password->identity_info.parameter_control,
1535 logon->password->lmpassword.hash,
1536 logon->password->ntpassword.hash,
1537 creds->session_key)) {
1538 status = NT_STATUS_NO_MEMORY;
1543 DEBUG(2,("SAM Logon: unsupported switch value\n"));
1544 return NT_STATUS_INVALID_INFO_CLASS;
1547 if ( NT_STATUS_IS_OK(status) ) {
1548 status = auth_context->check_ntlm_password(auth_context,
1549 user_info, &server_info);
1552 TALLOC_FREE(auth_context);
1553 free_user_info(&user_info);
1555 DEBUG(5,("%s: check_password returned status %s\n",
1556 fn, nt_errstr(status)));
1558 /* Check account and password */
1560 if (!NT_STATUS_IS_OK(status)) {
1561 /* If we don't know what this domain is, we need to
1562 indicate that we are not authoritative. This
1563 allows the client to decide if it needs to try
1564 a local user. Fix by jpjanosi@us.ibm.com, #2976 */
1565 if ( NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_USER)
1566 && !strequal(nt_domain, get_global_sam_name())
1567 && !is_trusted_domain(nt_domain) )
1568 *r->out.authoritative = false; /* We are not authoritative */
1570 TALLOC_FREE(server_info);
1574 if (server_info->guest) {
1575 /* We don't like guest domain logons... */
1576 DEBUG(5,("%s: Attempted domain logon as GUEST "
1578 TALLOC_FREE(server_info);
1579 return NT_STATUS_LOGON_FAILURE;
1582 /* This is the point at which, if the login was successful, that
1583 the SAM Local Security Authority should record that the user is
1584 logged in to the domain. */
1586 if (process_creds) {
1587 /* Get the pipe session key from the creds. */
1588 memcpy(pipe_session_key, creds->session_key, 16);
1590 struct schannel_state *schannel_auth;
1591 /* Get the pipe session key from the schannel. */
1592 if ((p->auth.auth_type != DCERPC_AUTH_TYPE_SCHANNEL)
1593 || (p->auth.auth_ctx == NULL)) {
1594 return NT_STATUS_INVALID_HANDLE;
1597 schannel_auth = talloc_get_type_abort(p->auth.auth_ctx,
1598 struct schannel_state);
1599 memcpy(pipe_session_key, schannel_auth->creds->session_key, 16);
1602 switch (r->in.validation_level) {
1604 status = serverinfo_to_SamInfo2(server_info, pipe_session_key, 16,
1605 r->out.validation->sam2);
1608 status = serverinfo_to_SamInfo3(server_info, pipe_session_key, 16,
1609 r->out.validation->sam3);
1612 status = serverinfo_to_SamInfo6(server_info, pipe_session_key, 16,
1613 r->out.validation->sam6);
1617 TALLOC_FREE(server_info);
1622 /****************************************************************
1623 _netr_LogonSamLogonWithFlags
1624 ****************************************************************/
1626 NTSTATUS _netr_LogonSamLogonWithFlags(struct pipes_struct *p,
1627 struct netr_LogonSamLogonWithFlags *r)
1630 struct netlogon_creds_CredentialState *creds;
1631 struct netr_LogonSamLogonEx r2;
1632 struct netr_Authenticator return_authenticator;
1634 *r->out.authoritative = true;
1636 r2.in.server_name = r->in.server_name;
1637 r2.in.computer_name = r->in.computer_name;
1638 r2.in.logon_level = r->in.logon_level;
1639 r2.in.logon = r->in.logon;
1640 r2.in.validation_level = r->in.validation_level;
1641 r2.in.flags = r->in.flags;
1642 r2.out.validation = r->out.validation;
1643 r2.out.authoritative = r->out.authoritative;
1644 r2.out.flags = r->out.flags;
1646 status = _netr_LogonSamLogon_check(&r2);
1647 if (!NT_STATUS_IS_OK(status)) {
1652 status = netr_creds_server_step_check(p, p->mem_ctx,
1653 r->in.computer_name,
1655 &return_authenticator,
1658 if (!NT_STATUS_IS_OK(status)) {
1662 status = _netr_LogonSamLogon_base(p, &r2, creds);
1664 *r->out.return_authenticator = return_authenticator;
1669 /*************************************************************************
1671 *************************************************************************/
1673 NTSTATUS _netr_LogonSamLogon(struct pipes_struct *p,
1674 struct netr_LogonSamLogon *r)
1677 struct netr_LogonSamLogonWithFlags r2;
1680 r2.in.server_name = r->in.server_name;
1681 r2.in.computer_name = r->in.computer_name;
1682 r2.in.credential = r->in.credential;
1683 r2.in.logon_level = r->in.logon_level;
1684 r2.in.logon = r->in.logon;
1685 r2.in.validation_level = r->in.validation_level;
1686 r2.in.return_authenticator = r->in.return_authenticator;
1687 r2.in.flags = &flags;
1688 r2.out.validation = r->out.validation;
1689 r2.out.authoritative = r->out.authoritative;
1690 r2.out.flags = &flags;
1691 r2.out.return_authenticator = r->out.return_authenticator;
1693 status = _netr_LogonSamLogonWithFlags(p, &r2);
1698 /*************************************************************************
1699 _netr_LogonSamLogonEx
1700 - no credential chaining. Map into net sam logon.
1701 *************************************************************************/
1703 NTSTATUS _netr_LogonSamLogonEx(struct pipes_struct *p,
1704 struct netr_LogonSamLogonEx *r)
1707 struct netlogon_creds_CredentialState *creds = NULL;
1709 *r->out.authoritative = true;
1711 status = _netr_LogonSamLogon_check(r);
1712 if (!NT_STATUS_IS_OK(status)) {
1716 /* Only allow this if the pipe is protected. */
1717 if (p->auth.auth_type != DCERPC_AUTH_TYPE_SCHANNEL) {
1718 DEBUG(0,("_netr_LogonSamLogonEx: client %s not using schannel for netlogon\n",
1719 get_remote_machine_name() ));
1720 return NT_STATUS_INVALID_PARAMETER;
1724 status = schannel_get_creds_state(p->mem_ctx, lp_private_dir(),
1725 r->in.computer_name, &creds);
1727 if (!NT_STATUS_IS_OK(status)) {
1731 status = _netr_LogonSamLogon_base(p, r, creds);
1737 /*************************************************************************
1739 *************************************************************************/
1740 #if 0 /* JERRY -- not correct */
1741 NTSTATUS _ds_enum_dom_trusts(struct pipes_struct *p, DS_Q_ENUM_DOM_TRUSTS *q_u,
1742 DS_R_ENUM_DOM_TRUSTS *r_u)
1744 NTSTATUS status = NT_STATUS_OK;
1746 /* TODO: According to MSDN, the can only be executed against a
1747 DC or domain member running Windows 2000 or later. Need
1748 to test against a standalone 2k server and see what it
1749 does. A windows 2000 DC includes its own domain in the
1757 /****************************************************************
1758 ****************************************************************/
1760 WERROR _netr_LogonUasLogon(struct pipes_struct *p,
1761 struct netr_LogonUasLogon *r)
1763 p->rng_fault_state = true;
1764 return WERR_NOT_SUPPORTED;
1767 /****************************************************************
1768 ****************************************************************/
1770 WERROR _netr_LogonUasLogoff(struct pipes_struct *p,
1771 struct netr_LogonUasLogoff *r)
1773 p->rng_fault_state = true;
1774 return WERR_NOT_SUPPORTED;
1777 /****************************************************************
1778 ****************************************************************/
1780 NTSTATUS _netr_DatabaseDeltas(struct pipes_struct *p,
1781 struct netr_DatabaseDeltas *r)
1783 p->rng_fault_state = true;
1784 return NT_STATUS_NOT_IMPLEMENTED;
1787 /****************************************************************
1788 ****************************************************************/
1790 NTSTATUS _netr_DatabaseSync(struct pipes_struct *p,
1791 struct netr_DatabaseSync *r)
1793 p->rng_fault_state = true;
1794 return NT_STATUS_NOT_IMPLEMENTED;
1797 /****************************************************************
1798 ****************************************************************/
1800 NTSTATUS _netr_AccountDeltas(struct pipes_struct *p,
1801 struct netr_AccountDeltas *r)
1803 p->rng_fault_state = true;
1804 return NT_STATUS_NOT_IMPLEMENTED;
1807 /****************************************************************
1808 ****************************************************************/
1810 NTSTATUS _netr_AccountSync(struct pipes_struct *p,
1811 struct netr_AccountSync *r)
1813 p->rng_fault_state = true;
1814 return NT_STATUS_NOT_IMPLEMENTED;
1817 /****************************************************************
1818 ****************************************************************/
1820 static bool wb_getdcname(TALLOC_CTX *mem_ctx,
1822 const char **dcname,
1827 struct wbcDomainControllerInfo *dc_info = NULL;
1829 result = wbcLookupDomainController(domain,
1833 case WBC_ERR_SUCCESS:
1835 case WBC_ERR_WINBIND_NOT_AVAILABLE:
1837 case WBC_ERR_DOMAIN_NOT_FOUND:
1838 *werr = WERR_NO_SUCH_DOMAIN;
1841 *werr = WERR_DOMAIN_CONTROLLER_NOT_FOUND;
1845 *dcname = talloc_strdup(mem_ctx, dc_info->dc_name);
1846 wbcFreeMemory(dc_info);
1857 /****************************************************************
1859 ****************************************************************/
1861 WERROR _netr_GetDcName(struct pipes_struct *p,
1862 struct netr_GetDcName *r)
1867 struct netr_DsRGetDCNameInfo *info;
1870 ret = wb_getdcname(p->mem_ctx,
1873 WBC_LOOKUP_DC_IS_FLAT_NAME |
1874 WBC_LOOKUP_DC_RETURN_FLAT_NAME |
1875 WBC_LOOKUP_DC_PDC_REQUIRED,
1881 flags = DS_PDC_REQUIRED | DS_IS_FLAT_NAME | DS_RETURN_FLAT_NAME;
1883 status = dsgetdcname(p->mem_ctx,
1890 if (!NT_STATUS_IS_OK(status)) {
1891 return ntstatus_to_werror(status);
1894 *r->out.dcname = talloc_strdup(p->mem_ctx, info->dc_unc);
1896 if (!*r->out.dcname) {
1903 /****************************************************************
1905 ****************************************************************/
1907 WERROR _netr_GetAnyDCName(struct pipes_struct *p,
1908 struct netr_GetAnyDCName *r)
1913 struct netr_DsRGetDCNameInfo *info;
1916 ret = wb_getdcname(p->mem_ctx,
1919 WBC_LOOKUP_DC_IS_FLAT_NAME |
1920 WBC_LOOKUP_DC_RETURN_FLAT_NAME,
1926 flags = DS_IS_FLAT_NAME | DS_RETURN_FLAT_NAME;
1928 status = dsgetdcname(p->mem_ctx,
1935 if (!NT_STATUS_IS_OK(status)) {
1936 return ntstatus_to_werror(status);
1939 *r->out.dcname = talloc_strdup(p->mem_ctx, info->dc_unc);
1941 if (!*r->out.dcname) {
1948 /****************************************************************
1949 ****************************************************************/
1951 NTSTATUS _netr_DatabaseSync2(struct pipes_struct *p,
1952 struct netr_DatabaseSync2 *r)
1954 p->rng_fault_state = true;
1955 return NT_STATUS_NOT_IMPLEMENTED;
1958 /****************************************************************
1959 ****************************************************************/
1961 NTSTATUS _netr_DatabaseRedo(struct pipes_struct *p,
1962 struct netr_DatabaseRedo *r)
1964 p->rng_fault_state = true;
1965 return NT_STATUS_NOT_IMPLEMENTED;
1968 /****************************************************************
1969 ****************************************************************/
1971 WERROR _netr_DsRGetDCName(struct pipes_struct *p,
1972 struct netr_DsRGetDCName *r)
1974 p->rng_fault_state = true;
1975 return WERR_NOT_SUPPORTED;
1978 /****************************************************************
1979 ****************************************************************/
1981 NTSTATUS _netr_LogonGetCapabilities(struct pipes_struct *p,
1982 struct netr_LogonGetCapabilities *r)
1984 return NT_STATUS_NOT_IMPLEMENTED;
1987 /****************************************************************
1988 ****************************************************************/
1990 WERROR _netr_NETRLOGONSETSERVICEBITS(struct pipes_struct *p,
1991 struct netr_NETRLOGONSETSERVICEBITS *r)
1993 p->rng_fault_state = true;
1994 return WERR_NOT_SUPPORTED;
1997 /****************************************************************
1998 ****************************************************************/
2000 WERROR _netr_LogonGetTrustRid(struct pipes_struct *p,
2001 struct netr_LogonGetTrustRid *r)
2003 p->rng_fault_state = true;
2004 return WERR_NOT_SUPPORTED;
2007 /****************************************************************
2008 ****************************************************************/
2010 WERROR _netr_NETRLOGONCOMPUTESERVERDIGEST(struct pipes_struct *p,
2011 struct netr_NETRLOGONCOMPUTESERVERDIGEST *r)
2013 p->rng_fault_state = true;
2014 return WERR_NOT_SUPPORTED;
2017 /****************************************************************
2018 ****************************************************************/
2020 WERROR _netr_NETRLOGONCOMPUTECLIENTDIGEST(struct pipes_struct *p,
2021 struct netr_NETRLOGONCOMPUTECLIENTDIGEST *r)
2023 p->rng_fault_state = true;
2024 return WERR_NOT_SUPPORTED;
2027 /****************************************************************
2028 ****************************************************************/
2030 WERROR _netr_DsRGetDCNameEx(struct pipes_struct *p,
2031 struct netr_DsRGetDCNameEx *r)
2033 p->rng_fault_state = true;
2034 return WERR_NOT_SUPPORTED;
2037 /****************************************************************
2038 ****************************************************************/
2040 WERROR _netr_DsRGetSiteName(struct pipes_struct *p,
2041 struct netr_DsRGetSiteName *r)
2043 p->rng_fault_state = true;
2044 return WERR_NOT_SUPPORTED;
2047 /****************************************************************
2048 ****************************************************************/
2050 NTSTATUS _netr_LogonGetDomainInfo(struct pipes_struct *p,
2051 struct netr_LogonGetDomainInfo *r)
2053 p->rng_fault_state = true;
2054 return NT_STATUS_NOT_IMPLEMENTED;
2057 /****************************************************************
2058 ****************************************************************/
2060 WERROR _netr_ServerPasswordGet(struct pipes_struct *p,
2061 struct netr_ServerPasswordGet *r)
2063 p->rng_fault_state = true;
2064 return WERR_NOT_SUPPORTED;
2067 /****************************************************************
2068 ****************************************************************/
2070 WERROR _netr_NETRLOGONSENDTOSAM(struct pipes_struct *p,
2071 struct netr_NETRLOGONSENDTOSAM *r)
2073 p->rng_fault_state = true;
2074 return WERR_NOT_SUPPORTED;
2077 /****************************************************************
2078 ****************************************************************/
2080 WERROR _netr_DsRAddressToSitenamesW(struct pipes_struct *p,
2081 struct netr_DsRAddressToSitenamesW *r)
2083 p->rng_fault_state = true;
2084 return WERR_NOT_SUPPORTED;
2087 /****************************************************************
2088 ****************************************************************/
2090 WERROR _netr_DsRGetDCNameEx2(struct pipes_struct *p,
2091 struct netr_DsRGetDCNameEx2 *r)
2093 p->rng_fault_state = true;
2094 return WERR_NOT_SUPPORTED;
2097 /****************************************************************
2098 ****************************************************************/
2100 WERROR _netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN(struct pipes_struct *p,
2101 struct netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN *r)
2103 p->rng_fault_state = true;
2104 return WERR_NOT_SUPPORTED;
2107 /****************************************************************
2108 ****************************************************************/
2110 WERROR _netr_NetrEnumerateTrustedDomainsEx(struct pipes_struct *p,
2111 struct netr_NetrEnumerateTrustedDomainsEx *r)
2113 p->rng_fault_state = true;
2114 return WERR_NOT_SUPPORTED;
2117 /****************************************************************
2118 ****************************************************************/
2120 WERROR _netr_DsRAddressToSitenamesExW(struct pipes_struct *p,
2121 struct netr_DsRAddressToSitenamesExW *r)
2123 p->rng_fault_state = true;
2124 return WERR_NOT_SUPPORTED;
2127 /****************************************************************
2128 ****************************************************************/
2130 WERROR _netr_DsrGetDcSiteCoverageW(struct pipes_struct *p,
2131 struct netr_DsrGetDcSiteCoverageW *r)
2133 p->rng_fault_state = true;
2134 return WERR_NOT_SUPPORTED;
2137 /****************************************************************
2138 ****************************************************************/
2140 WERROR _netr_DsrEnumerateDomainTrusts(struct pipes_struct *p,
2141 struct netr_DsrEnumerateDomainTrusts *r)
2143 p->rng_fault_state = true;
2144 return WERR_NOT_SUPPORTED;
2147 /****************************************************************
2148 ****************************************************************/
2150 WERROR _netr_DsrDeregisterDNSHostRecords(struct pipes_struct *p,
2151 struct netr_DsrDeregisterDNSHostRecords *r)
2153 p->rng_fault_state = true;
2154 return WERR_NOT_SUPPORTED;
2157 /****************************************************************
2158 ****************************************************************/
2160 NTSTATUS _netr_ServerTrustPasswordsGet(struct pipes_struct *p,
2161 struct netr_ServerTrustPasswordsGet *r)
2163 p->rng_fault_state = true;
2164 return NT_STATUS_NOT_IMPLEMENTED;
2167 /****************************************************************
2168 ****************************************************************/
2170 WERROR _netr_DsRGetForestTrustInformation(struct pipes_struct *p,
2171 struct netr_DsRGetForestTrustInformation *r)
2173 p->rng_fault_state = true;
2174 return WERR_NOT_SUPPORTED;
2177 /****************************************************************
2178 ****************************************************************/
2180 NTSTATUS _netr_GetForestTrustInformation(struct pipes_struct *p,
2181 struct netr_GetForestTrustInformation *r)
2183 p->rng_fault_state = true;
2184 return NT_STATUS_NOT_IMPLEMENTED;
2187 /****************************************************************
2188 ****************************************************************/
2190 NTSTATUS _netr_ServerGetTrustInfo(struct pipes_struct *p,
2191 struct netr_ServerGetTrustInfo *r)
2193 p->rng_fault_state = true;
2194 return NT_STATUS_NOT_IMPLEMENTED;
2197 /****************************************************************
2198 ****************************************************************/
2200 NTSTATUS _netr_Unused47(struct pipes_struct *p,
2201 struct netr_Unused47 *r)
2203 p->rng_fault_state = true;
2204 return NT_STATUS_NOT_IMPLEMENTED;
2207 /****************************************************************
2208 ****************************************************************/
2210 NTSTATUS _netr_DsrUpdateReadOnlyServerDnsRecords(struct pipes_struct *p,
2211 struct netr_DsrUpdateReadOnlyServerDnsRecords *r)
2213 p->rng_fault_state = true;
2214 return NT_STATUS_NOT_IMPLEMENTED;