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_client/init_samr.h"
37 #include "rpc_server/rpc_ncacn_np.h"
38 #include "../libcli/security/security.h"
39 #include "../libcli/security/dom_sid.h"
40 #include "librpc/gen_ndr/ndr_drsblobs.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"
49 #include "libsmb/dsgetdcname.h"
51 extern userdom_struct current_user_info;
54 #define DBGC_CLASS DBGC_RPC_SRV
56 struct netlogon_server_pipe_state {
57 struct netr_Credential client_challenge;
58 struct netr_Credential server_challenge;
61 /*************************************************************************
63 *************************************************************************/
65 WERROR _netr_LogonControl(struct pipes_struct *p,
66 struct netr_LogonControl *r)
68 struct netr_LogonControl2Ex l;
70 switch (r->in.level) {
74 return WERR_NOT_SUPPORTED;
76 return WERR_INVALID_LEVEL;
79 switch (r->in.function_code) {
80 case NETLOGON_CONTROL_QUERY:
81 case NETLOGON_CONTROL_REPLICATE:
82 case NETLOGON_CONTROL_SYNCHRONIZE:
83 case NETLOGON_CONTROL_PDC_REPLICATE:
84 case NETLOGON_CONTROL_BREAKPOINT:
85 case NETLOGON_CONTROL_BACKUP_CHANGE_LOG:
86 case NETLOGON_CONTROL_TRUNCATE_LOG:
89 return WERR_NOT_SUPPORTED;
92 l.in.logon_server = r->in.logon_server;
93 l.in.function_code = r->in.function_code;
94 l.in.level = r->in.level;
96 l.out.query = r->out.query;
98 return _netr_LogonControl2Ex(p, &l);
101 /*************************************************************************
103 *************************************************************************/
105 WERROR _netr_LogonControl2(struct pipes_struct *p,
106 struct netr_LogonControl2 *r)
108 struct netr_LogonControl2Ex l;
110 l.in.logon_server = r->in.logon_server;
111 l.in.function_code = r->in.function_code;
112 l.in.level = r->in.level;
113 l.in.data = r->in.data;
114 l.out.query = r->out.query;
116 return _netr_LogonControl2Ex(p, &l);
119 /*************************************************************************
120 *************************************************************************/
122 static bool wb_change_trust_creds(const char *domain, WERROR *tc_status)
125 struct wbcAuthErrorInfo *error = NULL;
127 result = wbcChangeTrustCredentials(domain, &error);
129 case WBC_ERR_WINBIND_NOT_AVAILABLE:
131 case WBC_ERR_DOMAIN_NOT_FOUND:
132 *tc_status = WERR_NO_SUCH_DOMAIN;
134 case WBC_ERR_SUCCESS:
135 *tc_status = WERR_OK;
141 if (error && error->nt_status != 0) {
142 *tc_status = ntstatus_to_werror(NT_STATUS(error->nt_status));
144 *tc_status = WERR_TRUST_FAILURE;
146 wbcFreeMemory(error);
150 /*************************************************************************
151 *************************************************************************/
153 static bool wb_check_trust_creds(const char *domain, WERROR *tc_status)
156 struct wbcAuthErrorInfo *error = NULL;
158 result = wbcCheckTrustCredentials(domain, &error);
160 case WBC_ERR_WINBIND_NOT_AVAILABLE:
162 case WBC_ERR_DOMAIN_NOT_FOUND:
163 *tc_status = WERR_NO_SUCH_DOMAIN;
165 case WBC_ERR_SUCCESS:
166 *tc_status = WERR_OK;
172 if (error && error->nt_status != 0) {
173 *tc_status = ntstatus_to_werror(NT_STATUS(error->nt_status));
175 *tc_status = WERR_TRUST_FAILURE;
177 wbcFreeMemory(error);
181 /****************************************************************
182 _netr_LogonControl2Ex
183 ****************************************************************/
185 WERROR _netr_LogonControl2Ex(struct pipes_struct *p,
186 struct netr_LogonControl2Ex *r)
188 uint32_t flags = 0x0;
189 WERROR pdc_connection_status = WERR_OK;
190 uint32_t logon_attempts = 0x0;
193 const char *dc_name = NULL;
194 struct sockaddr_storage dc_ss;
195 const char *domain = NULL;
196 struct netr_NETLOGON_INFO_1 *info1;
197 struct netr_NETLOGON_INFO_2 *info2;
198 struct netr_NETLOGON_INFO_3 *info3;
199 struct netr_NETLOGON_INFO_4 *info4;
202 struct netr_DsRGetDCNameInfo *dc_info;
205 case NDR_NETR_LOGONCONTROL:
206 fn = "_netr_LogonControl";
208 case NDR_NETR_LOGONCONTROL2:
209 fn = "_netr_LogonControl2";
211 case NDR_NETR_LOGONCONTROL2EX:
212 fn = "_netr_LogonControl2Ex";
215 return WERR_INVALID_PARAMETER;
218 switch (r->in.level) {
225 return WERR_INVALID_LEVEL;
228 switch (r->in.function_code) {
229 case NETLOGON_CONTROL_QUERY:
232 if ((geteuid() != sec_initial_uid()) &&
233 !nt_token_check_domain_rid(p->session_info->security_token, DOMAIN_RID_ADMINS) &&
234 !nt_token_check_sid(&global_sid_Builtin_Administrators, p->session_info->security_token))
236 return WERR_ACCESS_DENIED;
241 tc_status = WERR_NO_SUCH_DOMAIN;
243 switch (r->in.function_code) {
244 case NETLOGON_CONTROL_QUERY:
245 switch (r->in.level) {
250 return WERR_INVALID_PARAMETER;
255 case NETLOGON_CONTROL_REPLICATE:
256 case NETLOGON_CONTROL_SYNCHRONIZE:
257 case NETLOGON_CONTROL_PDC_REPLICATE:
258 case NETLOGON_CONTROL_BACKUP_CHANGE_LOG:
259 case NETLOGON_CONTROL_BREAKPOINT:
260 case NETLOGON_CONTROL_TRUNCATE_LOG:
261 case NETLOGON_CONTROL_TRANSPORT_NOTIFY:
262 case NETLOGON_CONTROL_FORCE_DNS_REG:
263 case NETLOGON_CONTROL_QUERY_DNS_REG:
264 return WERR_NOT_SUPPORTED;
266 case NETLOGON_CONTROL_FIND_USER:
267 if (!r->in.data || !r->in.data->user) {
268 return WERR_NOT_SUPPORTED;
271 case NETLOGON_CONTROL_SET_DBFLAG:
273 return WERR_NOT_SUPPORTED;
276 case NETLOGON_CONTROL_TC_VERIFY:
277 if (!r->in.data || !r->in.data->domain) {
278 return WERR_NOT_SUPPORTED;
281 if (!wb_check_trust_creds(r->in.data->domain, &tc_status)) {
282 return WERR_NOT_SUPPORTED;
285 case NETLOGON_CONTROL_TC_QUERY:
286 if (!r->in.data || !r->in.data->domain) {
287 return WERR_NOT_SUPPORTED;
290 domain = r->in.data->domain;
292 if (!is_trusted_domain(domain)) {
296 if (!get_dc_name(domain, NULL, dc_name2, &dc_ss)) {
297 tc_status = WERR_NO_LOGON_SERVERS;
301 dc_name = talloc_asprintf(p->mem_ctx, "\\\\%s", dc_name2);
303 return WERR_NOT_ENOUGH_MEMORY;
310 case NETLOGON_CONTROL_REDISCOVER:
311 if (!r->in.data || !r->in.data->domain) {
312 return WERR_NOT_SUPPORTED;
315 domain = r->in.data->domain;
317 if (!is_trusted_domain(domain)) {
321 status = dsgetdcname(p->mem_ctx, p->msg_ctx, domain, NULL, NULL,
322 DS_FORCE_REDISCOVERY | DS_RETURN_FLAT_NAME,
324 if (!NT_STATUS_IS_OK(status)) {
325 tc_status = WERR_NO_LOGON_SERVERS;
329 dc_name = talloc_asprintf(p->mem_ctx, "\\\\%s", dc_info->dc_unc);
331 return WERR_NOT_ENOUGH_MEMORY;
338 case NETLOGON_CONTROL_CHANGE_PASSWORD:
339 if (!r->in.data || !r->in.data->domain) {
340 return WERR_NOT_SUPPORTED;
343 if (!wb_change_trust_creds(r->in.data->domain, &tc_status)) {
344 return WERR_NOT_SUPPORTED;
349 /* no idea what this should be */
350 DEBUG(0,("%s: unimplemented function level [%d]\n",
351 fn, r->in.function_code));
352 return WERR_NOT_SUPPORTED;
355 /* prepare the response */
357 switch (r->in.level) {
359 info1 = talloc_zero(p->mem_ctx, struct netr_NETLOGON_INFO_1);
360 W_ERROR_HAVE_NO_MEMORY(info1);
362 info1->flags = flags;
363 info1->pdc_connection_status = pdc_connection_status;
365 r->out.query->info1 = info1;
368 info2 = talloc_zero(p->mem_ctx, struct netr_NETLOGON_INFO_2);
369 W_ERROR_HAVE_NO_MEMORY(info2);
371 info2->flags = flags;
372 info2->pdc_connection_status = pdc_connection_status;
373 info2->trusted_dc_name = dc_name;
374 info2->tc_connection_status = tc_status;
376 r->out.query->info2 = info2;
379 info3 = talloc_zero(p->mem_ctx, struct netr_NETLOGON_INFO_3);
380 W_ERROR_HAVE_NO_MEMORY(info3);
382 info3->flags = flags;
383 info3->logon_attempts = logon_attempts;
385 r->out.query->info3 = info3;
388 info4 = talloc_zero(p->mem_ctx, struct netr_NETLOGON_INFO_4);
389 W_ERROR_HAVE_NO_MEMORY(info4);
391 info4->trusted_dc_name = dc_name;
392 info4->trusted_domain_name = r->in.data->domain;
394 r->out.query->info4 = info4;
397 return WERR_INVALID_LEVEL;
403 /*************************************************************************
404 _netr_NetrEnumerateTrustedDomains
405 *************************************************************************/
407 NTSTATUS _netr_NetrEnumerateTrustedDomains(struct pipes_struct *p,
408 struct netr_NetrEnumerateTrustedDomains *r)
411 NTSTATUS result = NT_STATUS_OK;
413 size_t num_domains = 0;
414 const char **trusted_domains = NULL;
415 struct lsa_DomainList domain_list;
416 struct dcerpc_binding_handle *h = NULL;
417 struct policy_handle pol;
418 uint32_t enum_ctx = 0;
420 uint32_t max_size = (uint32_t)-1;
422 DEBUG(6,("_netr_NetrEnumerateTrustedDomains: %d\n", __LINE__));
424 status = rpcint_binding_handle(p->mem_ctx,
431 if (!NT_STATUS_IS_OK(status)) {
435 status = dcerpc_lsa_open_policy2(h,
439 LSA_POLICY_VIEW_LOCAL_INFORMATION,
442 if (!NT_STATUS_IS_OK(status)) {
445 if (!NT_STATUS_IS_OK(result)) {
451 /* Lookup list of trusted domains */
452 status = dcerpc_lsa_EnumTrustDom(h,
459 if (!NT_STATUS_IS_OK(status)) {
462 if (!NT_STATUS_IS_OK(result) &&
463 !NT_STATUS_EQUAL(result, NT_STATUS_NO_MORE_ENTRIES) &&
464 !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)) {
469 for (i = 0; i < domain_list.count; i++) {
470 if (!add_string_to_array(p->mem_ctx, domain_list.domains[i].name.string,
471 &trusted_domains, &num_domains)) {
472 status = NT_STATUS_NO_MEMORY;
476 } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
478 if (num_domains > 0) {
479 /* multi sz terminate */
480 trusted_domains = talloc_realloc(p->mem_ctx, trusted_domains, const char *, num_domains + 1);
481 if (trusted_domains == NULL) {
482 status = NT_STATUS_NO_MEMORY;
486 trusted_domains[num_domains] = NULL;
489 if (!push_reg_multi_sz(trusted_domains, &blob, trusted_domains)) {
490 TALLOC_FREE(trusted_domains);
491 status = NT_STATUS_NO_MEMORY;
495 r->out.trusted_domains_blob->data = blob.data;
496 r->out.trusted_domains_blob->length = blob.length;
498 DEBUG(6,("_netr_NetrEnumerateTrustedDomains: %d\n", __LINE__));
500 status = NT_STATUS_OK;
503 if (is_valid_policy_hnd(&pol)) {
504 dcerpc_lsa_Close(h, p->mem_ctx, &pol, &result);
510 /*************************************************************************
511 *************************************************************************/
513 static NTSTATUS samr_find_machine_account(TALLOC_CTX *mem_ctx,
514 struct dcerpc_binding_handle *b,
515 const char *account_name,
516 uint32_t access_mask,
517 struct dom_sid2 **domain_sid_p,
518 uint32_t *user_rid_p,
519 struct policy_handle *user_handle)
522 NTSTATUS result = NT_STATUS_OK;
523 struct policy_handle connect_handle;
524 struct policy_handle domain_handle = { 0, };
525 struct lsa_String domain_name;
526 struct dom_sid2 *domain_sid;
527 struct lsa_String names;
528 struct samr_Ids rids;
529 struct samr_Ids types;
532 status = dcerpc_samr_Connect2(b, mem_ctx,
534 SAMR_ACCESS_CONNECT_TO_SERVER |
535 SAMR_ACCESS_ENUM_DOMAINS |
536 SAMR_ACCESS_LOOKUP_DOMAIN,
539 if (!NT_STATUS_IS_OK(status)) {
542 if (!NT_STATUS_IS_OK(result)) {
547 init_lsa_String(&domain_name, get_global_sam_name());
549 status = dcerpc_samr_LookupDomain(b, mem_ctx,
554 if (!NT_STATUS_IS_OK(status)) {
557 if (!NT_STATUS_IS_OK(result)) {
562 status = dcerpc_samr_OpenDomain(b, mem_ctx,
564 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
568 if (!NT_STATUS_IS_OK(status)) {
571 if (!NT_STATUS_IS_OK(result)) {
576 init_lsa_String(&names, account_name);
578 status = dcerpc_samr_LookupNames(b, mem_ctx,
585 if (!NT_STATUS_IS_OK(status)) {
588 if (!NT_STATUS_IS_OK(result)) {
593 if (rids.count != 1) {
594 status = NT_STATUS_NO_SUCH_USER;
597 if (types.count != 1) {
598 status = NT_STATUS_INVALID_PARAMETER;
601 if (types.ids[0] != SID_NAME_USER) {
602 status = NT_STATUS_NO_SUCH_USER;
608 status = dcerpc_samr_OpenUser(b, mem_ctx,
614 if (!NT_STATUS_IS_OK(status)) {
617 if (!NT_STATUS_IS_OK(result)) {
627 *domain_sid_p = domain_sid;
631 if (is_valid_policy_hnd(&domain_handle)) {
632 dcerpc_samr_Close(b, mem_ctx, &domain_handle, &result);
634 if (is_valid_policy_hnd(&connect_handle)) {
635 dcerpc_samr_Close(b, mem_ctx, &connect_handle, &result);
641 /******************************************************************
642 gets a machine password entry. checks access rights of the host.
643 ******************************************************************/
645 static NTSTATUS get_md4pw(struct samr_Password *md4pw, const char *mach_acct,
646 enum netr_SchannelType sec_chan_type,
648 struct messaging_context *msg_ctx)
651 NTSTATUS result = NT_STATUS_OK;
653 struct dcerpc_binding_handle *h = NULL;
654 struct tsocket_address *local;
655 struct policy_handle user_handle;
657 struct dom_sid *domain_sid;
659 union samr_UserInfo *info;
660 struct auth_session_info *session_info;
666 * Currently this code is redundant as we already have a filter
667 * by hostname list. What this code really needs to do is to
668 * get a hosts allowed/hosts denied list from the SAM database
669 * on a per user basis, and make the access decision there.
670 * I will leave this code here for now as a reminder to implement
671 * this at a later date. JRA.
674 if (!allow_access(lp_domain_hostsdeny(), lp_domain_hostsallow(),
676 p->client_id.addr)) {
677 DEBUG(0,("get_md4pw: Workstation %s denied access to domain\n", mach_acct));
682 mem_ctx = talloc_stackframe();
683 if (mem_ctx == NULL) {
684 status = NT_STATUS_NO_MEMORY;
688 status = make_session_info_system(mem_ctx, &session_info);
689 if (!NT_STATUS_IS_OK(status)) {
693 ZERO_STRUCT(user_handle);
695 rc = tsocket_address_inet_from_strings(mem_ctx,
701 status = NT_STATUS_NO_MEMORY;
705 status = rpcint_binding_handle(mem_ctx,
712 if (!NT_STATUS_IS_OK(status)) {
716 status = samr_find_machine_account(mem_ctx, h, mach_acct,
717 SEC_FLAG_MAXIMUM_ALLOWED,
718 &domain_sid, &user_rid,
720 if (!NT_STATUS_IS_OK(status)) {
724 status = dcerpc_samr_QueryUserInfo2(h,
727 UserControlInformation,
730 if (!NT_STATUS_IS_OK(status)) {
733 if (!NT_STATUS_IS_OK(result)) {
738 acct_ctrl = info->info16.acct_flags;
740 if (acct_ctrl & ACB_DISABLED) {
741 DEBUG(0,("get_md4pw: Workstation %s: account is disabled\n", mach_acct));
742 status = NT_STATUS_ACCOUNT_DISABLED;
746 if (!(acct_ctrl & ACB_SVRTRUST) &&
747 !(acct_ctrl & ACB_WSTRUST) &&
748 !(acct_ctrl & ACB_DOMTRUST))
750 DEBUG(0,("get_md4pw: Workstation %s: account is not a trust account\n", mach_acct));
751 status = NT_STATUS_NO_TRUST_SAM_ACCOUNT;
755 switch (sec_chan_type) {
757 if (!(acct_ctrl & ACB_SVRTRUST)) {
758 DEBUG(0,("get_md4pw: Workstation %s: BDC secure channel requested "
759 "but not a server trust account\n", mach_acct));
760 status = NT_STATUS_NO_TRUST_SAM_ACCOUNT;
765 if (!(acct_ctrl & ACB_WSTRUST)) {
766 DEBUG(0,("get_md4pw: Workstation %s: WORKSTATION secure channel requested "
767 "but not a workstation trust account\n", mach_acct));
768 status = NT_STATUS_NO_TRUST_SAM_ACCOUNT;
772 case SEC_CHAN_DOMAIN:
773 if (!(acct_ctrl & ACB_DOMTRUST)) {
774 DEBUG(0,("get_md4pw: Workstation %s: DOMAIN secure channel requested "
775 "but not a interdomain trust account\n", mach_acct));
776 status = NT_STATUS_NO_TRUST_SAM_ACCOUNT;
785 status = dcerpc_samr_QueryUserInfo2(h,
788 UserInternal1Information,
792 if (!NT_STATUS_IS_OK(status)) {
795 if (!NT_STATUS_IS_OK(result)) {
800 if (info->info18.nt_pwd_active == 0) {
801 DEBUG(0,("get_md4pw: Workstation %s: account does not have a password\n", mach_acct));
802 status = NT_STATUS_LOGON_FAILURE;
806 /* samr gives out nthash unencrypted (!) */
807 memcpy(md4pw->hash, info->info18.nt_pwd.hash, 16);
809 sid_compose(sid, domain_sid, user_rid);
812 if (h && is_valid_policy_hnd(&user_handle)) {
813 dcerpc_samr_Close(h, mem_ctx, &user_handle, &result);
816 talloc_free(mem_ctx);
821 /*************************************************************************
822 _netr_ServerReqChallenge
823 *************************************************************************/
825 NTSTATUS _netr_ServerReqChallenge(struct pipes_struct *p,
826 struct netr_ServerReqChallenge *r)
828 struct netlogon_server_pipe_state *pipe_state =
829 talloc_get_type(p->private_data, struct netlogon_server_pipe_state);
832 DEBUG(10,("_netr_ServerReqChallenge: new challenge requested. Clearing old state.\n"));
833 talloc_free(pipe_state);
834 p->private_data = NULL;
837 pipe_state = talloc(p, struct netlogon_server_pipe_state);
838 NT_STATUS_HAVE_NO_MEMORY(pipe_state);
840 pipe_state->client_challenge = *r->in.credentials;
842 generate_random_buffer(pipe_state->server_challenge.data,
843 sizeof(pipe_state->server_challenge.data));
845 *r->out.return_credentials = pipe_state->server_challenge;
847 p->private_data = pipe_state;
852 /*************************************************************************
853 _netr_ServerAuthenticate
854 Create the initial credentials.
855 *************************************************************************/
857 NTSTATUS _netr_ServerAuthenticate(struct pipes_struct *p,
858 struct netr_ServerAuthenticate *r)
860 struct netr_ServerAuthenticate3 a;
861 uint32_t negotiate_flags = 0;
864 a.in.server_name = r->in.server_name;
865 a.in.account_name = r->in.account_name;
866 a.in.secure_channel_type = r->in.secure_channel_type;
867 a.in.computer_name = r->in.computer_name;
868 a.in.credentials = r->in.credentials;
869 a.in.negotiate_flags = &negotiate_flags;
871 a.out.return_credentials = r->out.return_credentials;
873 a.out.negotiate_flags = &negotiate_flags;
875 return _netr_ServerAuthenticate3(p, &a);
879 /*************************************************************************
880 _netr_ServerAuthenticate3
881 *************************************************************************/
883 NTSTATUS _netr_ServerAuthenticate3(struct pipes_struct *p,
884 struct netr_ServerAuthenticate3 *r)
888 /* r->in.negotiate_flags is an aliased pointer to r->out.negotiate_flags,
889 * so use a copy to avoid destroying the client values. */
890 uint32_t in_neg_flags = *r->in.negotiate_flags;
892 struct loadparm_context *lp_ctx;
894 struct samr_Password mach_pwd;
895 struct netlogon_creds_CredentialState *creds;
896 struct netlogon_server_pipe_state *pipe_state =
897 talloc_get_type(p->private_data, struct netlogon_server_pipe_state);
899 /* According to Microsoft (see bugid #6099)
900 * Windows 7 looks at the negotiate_flags
901 * returned in this structure *even if the
902 * call fails with access denied* ! So in order
903 * to allow Win7 to connect to a Samba NT style
904 * PDC we set the flags before we know if it's
909 srv_flgs = NETLOGON_NEG_ACCOUNT_LOCKOUT |
910 NETLOGON_NEG_PERSISTENT_SAMREPL |
911 NETLOGON_NEG_ARCFOUR |
912 NETLOGON_NEG_PROMOTION_COUNT |
913 NETLOGON_NEG_CHANGELOG_BDC |
914 NETLOGON_NEG_FULL_SYNC_REPL |
915 NETLOGON_NEG_MULTIPLE_SIDS |
917 NETLOGON_NEG_PASSWORD_CHANGE_REFUSAL |
918 NETLOGON_NEG_PASSWORD_SET2;
920 /* Ensure we support strong (128-bit) keys. */
921 if (in_neg_flags & NETLOGON_NEG_STRONG_KEYS) {
922 srv_flgs |= NETLOGON_NEG_STRONG_KEYS;
925 if (in_neg_flags & NETLOGON_NEG_SUPPORTS_AES) {
926 srv_flgs |= NETLOGON_NEG_SUPPORTS_AES;
929 if (lp_server_schannel() != false) {
930 srv_flgs |= NETLOGON_NEG_SCHANNEL;
934 * Support authenticaten of trusted domains.
936 * These flags are the minimum required set which works with win2k3
939 if (pdb_capabilities() & PDB_CAP_TRUSTED_DOMAINS_EX) {
940 srv_flgs |= NETLOGON_NEG_TRANSITIVE_TRUSTS |
941 NETLOGON_NEG_DNS_DOMAIN_TRUSTS |
942 NETLOGON_NEG_CROSS_FOREST_TRUSTS |
943 NETLOGON_NEG_NEUTRALIZE_NT4_EMULATION;
947 case NDR_NETR_SERVERAUTHENTICATE:
948 fn = "_netr_ServerAuthenticate";
950 case NDR_NETR_SERVERAUTHENTICATE2:
951 fn = "_netr_ServerAuthenticate2";
953 case NDR_NETR_SERVERAUTHENTICATE3:
954 fn = "_netr_ServerAuthenticate3";
957 return NT_STATUS_INTERNAL_ERROR;
960 /* We use this as the key to store the creds: */
961 /* r->in.computer_name */
964 DEBUG(0,("%s: no challenge sent to client %s\n", fn,
965 r->in.computer_name));
966 status = NT_STATUS_ACCESS_DENIED;
970 if ( (lp_server_schannel() == true) &&
971 ((in_neg_flags & NETLOGON_NEG_SCHANNEL) == 0) ) {
973 /* schannel must be used, but client did not offer it. */
974 DEBUG(0,("%s: schannel required but client failed "
975 "to offer it. Client was %s\n",
976 fn, r->in.account_name));
977 status = NT_STATUS_ACCESS_DENIED;
981 status = get_md4pw(&mach_pwd,
983 r->in.secure_channel_type,
985 if (!NT_STATUS_IS_OK(status)) {
986 DEBUG(0,("%s: failed to get machine password for "
988 fn, r->in.account_name, nt_errstr(status) ));
989 /* always return NT_STATUS_ACCESS_DENIED */
990 status = NT_STATUS_ACCESS_DENIED;
994 /* From the client / server challenges and md4 password, generate sess key */
995 /* Check client credentials are valid. */
996 creds = netlogon_creds_server_init(p->mem_ctx,
999 r->in.secure_channel_type,
1000 &pipe_state->client_challenge,
1001 &pipe_state->server_challenge,
1004 r->out.return_credentials,
1007 DEBUG(0,("%s: netlogon_creds_server_check failed. Rejecting auth "
1008 "request from client %s machine account %s\n",
1009 fn, r->in.computer_name,
1010 r->in.account_name));
1011 status = NT_STATUS_ACCESS_DENIED;
1015 creds->sid = dom_sid_dup(creds, &sid);
1017 status = NT_STATUS_NO_MEMORY;
1021 lp_ctx = loadparm_init_s3(p->mem_ctx, loadparm_s3_helpers());
1022 if (lp_ctx == NULL) {
1023 DEBUG(10, ("loadparm_init_s3 failed\n"));
1024 status = NT_STATUS_INTERNAL_ERROR;
1028 /* Store off the state so we can continue after client disconnect. */
1030 status = schannel_save_creds_state(p->mem_ctx, lp_ctx, creds);
1033 talloc_unlink(p->mem_ctx, lp_ctx);
1035 if (!NT_STATUS_IS_OK(status)) {
1036 ZERO_STRUCTP(r->out.return_credentials);
1040 sid_peek_rid(&sid, r->out.rid);
1042 status = NT_STATUS_OK;
1046 *r->out.negotiate_flags = srv_flgs;
1050 /*************************************************************************
1051 _netr_ServerAuthenticate2
1052 *************************************************************************/
1054 NTSTATUS _netr_ServerAuthenticate2(struct pipes_struct *p,
1055 struct netr_ServerAuthenticate2 *r)
1057 struct netr_ServerAuthenticate3 a;
1060 a.in.server_name = r->in.server_name;
1061 a.in.account_name = r->in.account_name;
1062 a.in.secure_channel_type = r->in.secure_channel_type;
1063 a.in.computer_name = r->in.computer_name;
1064 a.in.credentials = r->in.credentials;
1065 a.in.negotiate_flags = r->in.negotiate_flags;
1067 a.out.return_credentials = r->out.return_credentials;
1069 a.out.negotiate_flags = r->out.negotiate_flags;
1071 return _netr_ServerAuthenticate3(p, &a);
1074 /*************************************************************************
1075 * If schannel is required for this call test that it actually is available.
1076 *************************************************************************/
1077 static NTSTATUS schannel_check_required(struct pipe_auth_data *auth_info,
1078 const char *computer_name,
1079 bool integrity, bool privacy)
1081 if (auth_info && auth_info->auth_type == DCERPC_AUTH_TYPE_SCHANNEL) {
1082 if (!privacy && !integrity) {
1083 return NT_STATUS_OK;
1086 if ((!privacy && integrity) &&
1087 auth_info->auth_level == DCERPC_AUTH_LEVEL_INTEGRITY) {
1088 return NT_STATUS_OK;
1091 if ((privacy || integrity) &&
1092 auth_info->auth_level == DCERPC_AUTH_LEVEL_PRIVACY) {
1093 return NT_STATUS_OK;
1097 /* test didn't pass */
1098 DEBUG(0, ("schannel_check_required: [%s] is not using schannel\n",
1101 return NT_STATUS_ACCESS_DENIED;
1104 /*************************************************************************
1105 *************************************************************************/
1107 static NTSTATUS netr_creds_server_step_check(struct pipes_struct *p,
1108 TALLOC_CTX *mem_ctx,
1109 const char *computer_name,
1110 struct netr_Authenticator *received_authenticator,
1111 struct netr_Authenticator *return_authenticator,
1112 struct netlogon_creds_CredentialState **creds_out)
1115 bool schannel_global_required = (lp_server_schannel() == true) ? true:false;
1116 struct loadparm_context *lp_ctx;
1118 if (creds_out != NULL) {
1122 if (schannel_global_required) {
1123 status = schannel_check_required(&p->auth,
1126 if (!NT_STATUS_IS_OK(status)) {
1131 lp_ctx = loadparm_init_s3(mem_ctx, loadparm_s3_helpers());
1132 if (lp_ctx == NULL) {
1133 DEBUG(0, ("loadparm_init_s3 failed\n"));
1134 return NT_STATUS_INTERNAL_ERROR;
1137 status = schannel_check_creds_state(mem_ctx, lp_ctx,
1138 computer_name, received_authenticator,
1139 return_authenticator, creds_out);
1140 talloc_unlink(mem_ctx, lp_ctx);
1145 /*************************************************************************
1146 *************************************************************************/
1148 struct _samr_Credentials_t {
1151 CRED_TYPE_PLAIN_TEXT,
1154 struct samr_Password *nt_hash;
1155 const char *password;
1160 static NTSTATUS netr_set_machine_account_password(TALLOC_CTX *mem_ctx,
1161 struct auth_session_info *session_info,
1162 struct messaging_context *msg_ctx,
1163 const char *account_name,
1164 struct _samr_Credentials_t *cr)
1167 NTSTATUS result = NT_STATUS_OK;
1168 struct dcerpc_binding_handle *h = NULL;
1169 struct tsocket_address *local;
1170 struct policy_handle user_handle;
1172 union samr_UserInfo *info;
1173 struct samr_UserInfo18 info18;
1174 struct samr_UserInfo26 info26;
1177 DATA_BLOB session_key;
1178 enum samr_UserInfoLevel infolevel;
1180 ZERO_STRUCT(user_handle);
1182 status = session_extract_session_key(session_info,
1185 if (!NT_STATUS_IS_OK(status)) {
1189 rc = tsocket_address_inet_from_strings(mem_ctx,
1195 status = NT_STATUS_NO_MEMORY;
1199 status = rpcint_binding_handle(mem_ctx,
1206 if (!NT_STATUS_IS_OK(status)) {
1211 status = samr_find_machine_account(mem_ctx,
1214 SEC_FLAG_MAXIMUM_ALLOWED,
1219 if (!NT_STATUS_IS_OK(status)) {
1223 status = dcerpc_samr_QueryUserInfo2(h,
1226 UserControlInformation,
1229 if (!NT_STATUS_IS_OK(status)) {
1232 if (!NT_STATUS_IS_OK(result)) {
1237 acct_ctrl = info->info16.acct_flags;
1239 if (!(acct_ctrl & ACB_WSTRUST ||
1240 acct_ctrl & ACB_SVRTRUST ||
1241 acct_ctrl & ACB_DOMTRUST)) {
1242 status = NT_STATUS_NO_SUCH_USER;
1246 if (acct_ctrl & ACB_DISABLED) {
1247 status = NT_STATUS_ACCOUNT_DISABLED;
1251 switch(cr->cred_type) {
1252 case CRED_TYPE_NT_HASH:
1253 ZERO_STRUCT(info18);
1255 infolevel = UserInternal1Information;
1257 in = data_blob_const(cr->creds.nt_hash, 16);
1258 out = data_blob_talloc_zero(mem_ctx, 16);
1259 sess_crypt_blob(&out, &in, &session_key, true);
1260 memcpy(info18.nt_pwd.hash, out.data, out.length);
1262 info18.nt_pwd_active = true;
1264 info->info18 = info18;
1266 case CRED_TYPE_PLAIN_TEXT:
1267 ZERO_STRUCT(info26);
1269 infolevel = UserInternal5InformationNew;
1271 init_samr_CryptPasswordEx(cr->creds.password,
1275 info26.password_expired = PASS_DONT_CHANGE_AT_NEXT_LOGON;
1276 info->info26 = info26;
1279 status = NT_STATUS_INTERNAL_ERROR;
1285 status = dcerpc_samr_SetUserInfo2(h,
1292 if (!NT_STATUS_IS_OK(status)) {
1295 if (!NT_STATUS_IS_OK(result)) {
1301 if (h && is_valid_policy_hnd(&user_handle)) {
1302 dcerpc_samr_Close(h, mem_ctx, &user_handle, &result);
1308 /*************************************************************************
1309 _netr_ServerPasswordSet
1310 *************************************************************************/
1312 NTSTATUS _netr_ServerPasswordSet(struct pipes_struct *p,
1313 struct netr_ServerPasswordSet *r)
1315 NTSTATUS status = NT_STATUS_OK;
1317 struct netlogon_creds_CredentialState *creds = NULL;
1318 struct _samr_Credentials_t cr = { CRED_TYPE_NT_HASH, {0}};
1320 DEBUG(5,("_netr_ServerPasswordSet: %d\n", __LINE__));
1323 status = netr_creds_server_step_check(p, p->mem_ctx,
1324 r->in.computer_name,
1326 r->out.return_authenticator,
1330 if (!NT_STATUS_IS_OK(status)) {
1331 const char *computer_name = "<unknown>";
1333 if (creds != NULL && creds->computer_name != NULL) {
1334 computer_name = creds->computer_name;
1336 DEBUG(2,("_netr_ServerPasswordSet: netlogon_creds_server_step failed. Rejecting auth "
1337 "request from client %s machine account %s\n",
1338 r->in.computer_name, computer_name));
1343 DEBUG(3,("_netr_ServerPasswordSet: Server Password Set by remote machine:[%s] on account [%s]\n",
1344 r->in.computer_name, creds->computer_name));
1346 netlogon_creds_des_decrypt(creds, r->in.new_password);
1348 DEBUG(100,("_netr_ServerPasswordSet: new given value was :\n"));
1349 for(i = 0; i < sizeof(r->in.new_password->hash); i++)
1350 DEBUG(100,("%02X ", r->in.new_password->hash[i]));
1353 cr.creds.nt_hash = r->in.new_password;
1354 status = netr_set_machine_account_password(p->mem_ctx,
1357 creds->account_name,
1362 /****************************************************************
1363 _netr_ServerPasswordSet2
1364 ****************************************************************/
1366 NTSTATUS _netr_ServerPasswordSet2(struct pipes_struct *p,
1367 struct netr_ServerPasswordSet2 *r)
1370 struct netlogon_creds_CredentialState *creds = NULL;
1371 DATA_BLOB plaintext;
1372 struct samr_CryptPassword password_buf;
1373 struct _samr_Credentials_t cr = { CRED_TYPE_PLAIN_TEXT, {0}};
1376 status = netr_creds_server_step_check(p, p->mem_ctx,
1377 r->in.computer_name,
1379 r->out.return_authenticator,
1383 if (!NT_STATUS_IS_OK(status)) {
1384 const char *computer_name = "<unknown>";
1386 if (creds && creds->computer_name) {
1387 computer_name = creds->computer_name;
1389 DEBUG(2,("_netr_ServerPasswordSet2: netlogon_creds_server_step "
1390 "failed. Rejecting auth request from client %s machine account %s\n",
1391 r->in.computer_name, computer_name));
1396 DEBUG(3,("_netr_ServerPasswordSet2: Server Password Seti2 by remote "
1397 "machine:[%s] on account [%s]\n",
1398 r->in.computer_name, creds->computer_name));
1400 memcpy(password_buf.data, r->in.new_password->data, 512);
1401 SIVAL(password_buf.data, 512, r->in.new_password->length);
1403 if (creds->negotiate_flags & NETLOGON_NEG_SUPPORTS_AES) {
1404 netlogon_creds_aes_decrypt(creds, password_buf.data, 516);
1406 netlogon_creds_arcfour_crypt(creds, password_buf.data, 516);
1409 if (!decode_pw_buffer(p->mem_ctx,
1411 (char**) &plaintext.data,
1414 DEBUG(2,("_netr_ServerPasswordSet2: unable to extract password "
1415 "from a buffer. Rejecting auth request as a wrong password\n"));
1417 return NT_STATUS_WRONG_PASSWORD;
1420 cr.creds.password = (const char*) plaintext.data;
1421 status = netr_set_machine_account_password(p->mem_ctx,
1424 creds->account_name,
1430 /*************************************************************************
1431 _netr_LogonSamLogoff
1432 *************************************************************************/
1434 NTSTATUS _netr_LogonSamLogoff(struct pipes_struct *p,
1435 struct netr_LogonSamLogoff *r)
1438 struct netlogon_creds_CredentialState *creds;
1441 status = netr_creds_server_step_check(p, p->mem_ctx,
1442 r->in.computer_name,
1444 r->out.return_authenticator,
1451 static NTSTATUS _netr_LogonSamLogon_check(const struct netr_LogonSamLogonEx *r)
1453 switch (r->in.logon_level) {
1454 case NetlogonInteractiveInformation:
1455 case NetlogonServiceInformation:
1456 case NetlogonInteractiveTransitiveInformation:
1457 case NetlogonServiceTransitiveInformation:
1458 if (r->in.logon->password == NULL) {
1459 return NT_STATUS_INVALID_PARAMETER;
1462 switch (r->in.validation_level) {
1463 case NetlogonValidationSamInfo: /* 2 */
1464 case NetlogonValidationSamInfo2: /* 3 */
1466 case NetlogonValidationSamInfo4: /* 6 */
1467 if ((pdb_capabilities() & PDB_CAP_ADS) == 0) {
1468 DEBUG(10,("Not adding validation info level 6 "
1469 "without ADS passdb backend\n"));
1470 return NT_STATUS_INVALID_INFO_CLASS;
1474 return NT_STATUS_INVALID_INFO_CLASS;
1478 case NetlogonNetworkInformation:
1479 case NetlogonNetworkTransitiveInformation:
1480 if (r->in.logon->network == NULL) {
1481 return NT_STATUS_INVALID_PARAMETER;
1484 switch (r->in.validation_level) {
1485 case NetlogonValidationSamInfo: /* 2 */
1486 case NetlogonValidationSamInfo2: /* 3 */
1488 case NetlogonValidationSamInfo4: /* 6 */
1489 if ((pdb_capabilities() & PDB_CAP_ADS) == 0) {
1490 DEBUG(10,("Not adding validation info level 6 "
1491 "without ADS passdb backend\n"));
1492 return NT_STATUS_INVALID_INFO_CLASS;
1496 return NT_STATUS_INVALID_INFO_CLASS;
1501 case NetlogonGenericInformation:
1502 if (r->in.logon->generic == NULL) {
1503 return NT_STATUS_INVALID_PARAMETER;
1506 /* we don't support this here */
1507 return NT_STATUS_INVALID_PARAMETER;
1509 switch (r->in.validation_level) {
1510 /* TODO: case NetlogonValidationGenericInfo: 4 */
1511 case NetlogonValidationGenericInfo2: /* 5 */
1514 return NT_STATUS_INVALID_INFO_CLASS;
1520 return NT_STATUS_INVALID_PARAMETER;
1523 return NT_STATUS_OK;
1526 /*************************************************************************
1527 _netr_LogonSamLogon_base
1528 *************************************************************************/
1530 static NTSTATUS _netr_LogonSamLogon_base(struct pipes_struct *p,
1531 struct netr_LogonSamLogonEx *r,
1532 struct netlogon_creds_CredentialState *creds)
1534 NTSTATUS status = NT_STATUS_OK;
1535 union netr_LogonLevel *logon = r->in.logon;
1536 const char *nt_username, *nt_domain, *nt_workstation;
1537 struct auth_usersupplied_info *user_info = NULL;
1538 struct auth_serversupplied_info *server_info = NULL;
1539 struct auth_context *auth_context = NULL;
1542 #ifdef DEBUG_PASSWORD
1543 logon = netlogon_creds_shallow_copy_logon(p->mem_ctx,
1546 if (logon == NULL) {
1547 logon = r->in.logon;
1552 case NDR_NETR_LOGONSAMLOGON:
1553 fn = "_netr_LogonSamLogon";
1555 case NDR_NETR_LOGONSAMLOGONWITHFLAGS:
1556 fn = "_netr_LogonSamLogonWithFlags";
1558 case NDR_NETR_LOGONSAMLOGONEX:
1559 fn = "_netr_LogonSamLogonEx";
1562 return NT_STATUS_INTERNAL_ERROR;
1565 *r->out.authoritative = 1; /* authoritative response */
1567 switch (r->in.validation_level) {
1569 r->out.validation->sam2 = talloc_zero(p->mem_ctx, struct netr_SamInfo2);
1570 if (!r->out.validation->sam2) {
1571 return NT_STATUS_NO_MEMORY;
1575 r->out.validation->sam3 = talloc_zero(p->mem_ctx, struct netr_SamInfo3);
1576 if (!r->out.validation->sam3) {
1577 return NT_STATUS_NO_MEMORY;
1581 r->out.validation->sam6 = talloc_zero(p->mem_ctx, struct netr_SamInfo6);
1582 if (!r->out.validation->sam6) {
1583 return NT_STATUS_NO_MEMORY;
1587 DEBUG(0,("%s: bad validation_level value %d.\n",
1588 fn, (int)r->in.validation_level));
1589 return NT_STATUS_INVALID_INFO_CLASS;
1592 switch (r->in.logon_level) {
1593 case NetlogonInteractiveInformation:
1594 case NetlogonServiceInformation:
1595 case NetlogonInteractiveTransitiveInformation:
1596 case NetlogonServiceTransitiveInformation:
1597 nt_username = logon->password->identity_info.account_name.string ?
1598 logon->password->identity_info.account_name.string : "";
1599 nt_domain = logon->password->identity_info.domain_name.string ?
1600 logon->password->identity_info.domain_name.string : "";
1601 nt_workstation = logon->password->identity_info.workstation.string ?
1602 logon->password->identity_info.workstation.string : "";
1604 DEBUG(3,("SAM Logon (Interactive). Domain:[%s]. ", lp_workgroup()));
1606 case NetlogonNetworkInformation:
1607 case NetlogonNetworkTransitiveInformation:
1608 nt_username = logon->network->identity_info.account_name.string ?
1609 logon->network->identity_info.account_name.string : "";
1610 nt_domain = logon->network->identity_info.domain_name.string ?
1611 logon->network->identity_info.domain_name.string : "";
1612 nt_workstation = logon->network->identity_info.workstation.string ?
1613 logon->network->identity_info.workstation.string : "";
1615 DEBUG(3,("SAM Logon (Network). Domain:[%s]. ", lp_workgroup()));
1618 DEBUG(2,("SAM Logon: unsupported switch value\n"));
1619 return NT_STATUS_INVALID_INFO_CLASS;
1622 DEBUG(3,("User:[%s@%s] Requested Domain:[%s]\n", nt_username, nt_workstation, nt_domain));
1623 fstrcpy(current_user_info.smb_name, nt_username);
1624 sub_set_smb_name(nt_username);
1626 DEBUG(5,("Attempting validation level %d for unmapped username %s.\n",
1627 r->in.validation_level, nt_username));
1629 status = NT_STATUS_OK;
1631 netlogon_creds_decrypt_samlogon_logon(creds,
1635 status = make_auth3_context_for_netlogon(talloc_tos(), &auth_context);
1636 if (!NT_STATUS_IS_OK(status)) {
1640 switch (r->in.logon_level) {
1641 case NetlogonNetworkInformation:
1642 case NetlogonNetworkTransitiveInformation:
1644 const char *wksname = nt_workstation;
1645 const char *workgroup = lp_workgroup();
1648 ok = auth3_context_set_challenge(
1649 auth_context, logon->network->challenge, "fixed");
1651 return NT_STATUS_NO_MEMORY;
1654 /* For a network logon, the workstation name comes in with two
1655 * backslashes in the front. Strip them if they are there. */
1657 if (*wksname == '\\') wksname++;
1658 if (*wksname == '\\') wksname++;
1660 /* Standard challenge/response authentication */
1661 if (!make_user_info_netlogon_network(talloc_tos(),
1663 nt_username, nt_domain,
1667 logon->network->identity_info.parameter_control,
1668 logon->network->lm.data,
1669 logon->network->lm.length,
1670 logon->network->nt.data,
1671 logon->network->nt.length)) {
1672 status = NT_STATUS_NO_MEMORY;
1675 if (NT_STATUS_IS_OK(status)) {
1676 status = NTLMv2_RESPONSE_verify_netlogon_creds(
1677 user_info->client.account_name,
1678 user_info->client.domain_name,
1679 user_info->password.response.nt,
1684 case NetlogonInteractiveInformation:
1685 case NetlogonServiceInformation:
1686 case NetlogonInteractiveTransitiveInformation:
1687 case NetlogonServiceTransitiveInformation:
1689 /* 'Interactive' authentication, supplies the password in its
1690 MD4 form, encrypted with the session key. We will convert
1691 this to challenge/response for the auth subsystem to chew
1696 #ifdef DEBUG_PASSWORD
1697 if (logon != r->in.logon) {
1698 DEBUG(100,("lm owf password:"));
1700 r->in.logon->password->lmpassword.hash, 16);
1702 DEBUG(100,("nt owf password:"));
1704 r->in.logon->password->ntpassword.hash, 16);
1707 DEBUG(100,("decrypt of lm owf password:"));
1708 dump_data(100, logon->password->lmpassword.hash, 16);
1710 DEBUG(100,("decrypt of nt owf password:"));
1711 dump_data(100, logon->password->ntpassword.hash, 16);
1714 auth_get_ntlm_challenge(auth_context, chal);
1716 if (!make_user_info_netlogon_interactive(talloc_tos(),
1718 nt_username, nt_domain,
1722 logon->password->identity_info.parameter_control,
1724 logon->password->lmpassword.hash,
1725 logon->password->ntpassword.hash)) {
1726 status = NT_STATUS_NO_MEMORY;
1731 DEBUG(2,("SAM Logon: unsupported switch value\n"));
1732 return NT_STATUS_INVALID_INFO_CLASS;
1735 if ( NT_STATUS_IS_OK(status) ) {
1736 status = auth_check_ntlm_password(p->mem_ctx,
1740 r->out.authoritative);
1743 TALLOC_FREE(auth_context);
1744 TALLOC_FREE(user_info);
1746 DEBUG(5,("%s: check_password returned status %s\n",
1747 fn, nt_errstr(status)));
1749 /* Check account and password */
1751 if (!NT_STATUS_IS_OK(status)) {
1752 TALLOC_FREE(server_info);
1756 if (server_info->guest) {
1757 /* We don't like guest domain logons... */
1758 DEBUG(5,("%s: Attempted domain logon as GUEST "
1760 TALLOC_FREE(server_info);
1761 return NT_STATUS_LOGON_FAILURE;
1764 /* This is the point at which, if the login was successful, that
1765 the SAM Local Security Authority should record that the user is
1766 logged in to the domain. */
1768 switch (r->in.validation_level) {
1770 status = serverinfo_to_SamInfo2(server_info,
1771 r->out.validation->sam2);
1774 status = serverinfo_to_SamInfo3(server_info,
1775 r->out.validation->sam3);
1778 /* Only allow this if the pipe is protected. */
1779 if (p->auth.auth_level < DCERPC_AUTH_LEVEL_PRIVACY) {
1780 DEBUG(0,("netr_Validation6: client %s not using privacy for netlogon\n",
1781 get_remote_machine_name()));
1782 status = NT_STATUS_INVALID_PARAMETER;
1786 status = serverinfo_to_SamInfo6(server_info,
1787 r->out.validation->sam6);
1791 TALLOC_FREE(server_info);
1793 if (!NT_STATUS_IS_OK(status)) {
1797 netlogon_creds_encrypt_samlogon_validation(creds,
1798 r->in.validation_level,
1800 return NT_STATUS_OK;
1803 /****************************************************************
1804 _netr_LogonSamLogonWithFlags
1805 ****************************************************************/
1807 NTSTATUS _netr_LogonSamLogonWithFlags(struct pipes_struct *p,
1808 struct netr_LogonSamLogonWithFlags *r)
1811 struct netlogon_creds_CredentialState *creds;
1812 struct netr_LogonSamLogonEx r2;
1813 struct netr_Authenticator return_authenticator;
1815 *r->out.authoritative = true;
1817 r2.in.server_name = r->in.server_name;
1818 r2.in.computer_name = r->in.computer_name;
1819 r2.in.logon_level = r->in.logon_level;
1820 r2.in.logon = r->in.logon;
1821 r2.in.validation_level = r->in.validation_level;
1822 r2.in.flags = r->in.flags;
1823 r2.out.validation = r->out.validation;
1824 r2.out.authoritative = r->out.authoritative;
1825 r2.out.flags = r->out.flags;
1827 status = _netr_LogonSamLogon_check(&r2);
1828 if (!NT_STATUS_IS_OK(status)) {
1833 status = netr_creds_server_step_check(p, p->mem_ctx,
1834 r->in.computer_name,
1836 &return_authenticator,
1839 if (!NT_STATUS_IS_OK(status)) {
1843 status = _netr_LogonSamLogon_base(p, &r2, creds);
1845 *r->out.return_authenticator = return_authenticator;
1850 /*************************************************************************
1852 *************************************************************************/
1854 NTSTATUS _netr_LogonSamLogon(struct pipes_struct *p,
1855 struct netr_LogonSamLogon *r)
1858 struct netr_LogonSamLogonWithFlags r2;
1861 r2.in.server_name = r->in.server_name;
1862 r2.in.computer_name = r->in.computer_name;
1863 r2.in.credential = r->in.credential;
1864 r2.in.logon_level = r->in.logon_level;
1865 r2.in.logon = r->in.logon;
1866 r2.in.validation_level = r->in.validation_level;
1867 r2.in.return_authenticator = r->in.return_authenticator;
1868 r2.in.flags = &flags;
1869 r2.out.validation = r->out.validation;
1870 r2.out.authoritative = r->out.authoritative;
1871 r2.out.flags = &flags;
1872 r2.out.return_authenticator = r->out.return_authenticator;
1874 status = _netr_LogonSamLogonWithFlags(p, &r2);
1879 /*************************************************************************
1880 _netr_LogonSamLogonEx
1881 - no credential chaining. Map into net sam logon.
1882 *************************************************************************/
1884 NTSTATUS _netr_LogonSamLogonEx(struct pipes_struct *p,
1885 struct netr_LogonSamLogonEx *r)
1888 struct netlogon_creds_CredentialState *creds = NULL;
1889 struct loadparm_context *lp_ctx;
1891 *r->out.authoritative = true;
1893 status = _netr_LogonSamLogon_check(r);
1894 if (!NT_STATUS_IS_OK(status)) {
1898 /* Only allow this if the pipe is protected. */
1899 if (p->auth.auth_type != DCERPC_AUTH_TYPE_SCHANNEL) {
1900 DEBUG(0,("_netr_LogonSamLogonEx: client %s not using schannel for netlogon\n",
1901 get_remote_machine_name() ));
1902 return NT_STATUS_INVALID_PARAMETER;
1905 lp_ctx = loadparm_init_s3(p->mem_ctx, loadparm_s3_helpers());
1906 if (lp_ctx == NULL) {
1907 DEBUG(0, ("loadparm_init_s3 failed\n"));
1908 return NT_STATUS_INTERNAL_ERROR;
1912 status = schannel_get_creds_state(p->mem_ctx, lp_ctx,
1913 r->in.computer_name, &creds);
1915 talloc_unlink(p->mem_ctx, lp_ctx);
1917 if (!NT_STATUS_IS_OK(status)) {
1921 status = _netr_LogonSamLogon_base(p, r, creds);
1927 /*************************************************************************
1929 *************************************************************************/
1930 #if 0 /* JERRY -- not correct */
1931 NTSTATUS _ds_enum_dom_trusts(struct pipes_struct *p, DS_Q_ENUM_DOM_TRUSTS *q_u,
1932 DS_R_ENUM_DOM_TRUSTS *r_u)
1934 NTSTATUS status = NT_STATUS_OK;
1936 /* TODO: According to MSDN, the can only be executed against a
1937 DC or domain member running Windows 2000 or later. Need
1938 to test against a standalone 2k server and see what it
1939 does. A windows 2000 DC includes its own domain in the
1947 /****************************************************************
1948 ****************************************************************/
1950 WERROR _netr_LogonUasLogon(struct pipes_struct *p,
1951 struct netr_LogonUasLogon *r)
1953 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
1954 return WERR_NOT_SUPPORTED;
1957 /****************************************************************
1958 ****************************************************************/
1960 WERROR _netr_LogonUasLogoff(struct pipes_struct *p,
1961 struct netr_LogonUasLogoff *r)
1963 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
1964 return WERR_NOT_SUPPORTED;
1967 /****************************************************************
1968 ****************************************************************/
1970 NTSTATUS _netr_DatabaseDeltas(struct pipes_struct *p,
1971 struct netr_DatabaseDeltas *r)
1973 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
1974 return NT_STATUS_NOT_IMPLEMENTED;
1977 /****************************************************************
1978 ****************************************************************/
1980 NTSTATUS _netr_DatabaseSync(struct pipes_struct *p,
1981 struct netr_DatabaseSync *r)
1983 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
1984 return NT_STATUS_NOT_IMPLEMENTED;
1987 /****************************************************************
1988 ****************************************************************/
1990 NTSTATUS _netr_AccountDeltas(struct pipes_struct *p,
1991 struct netr_AccountDeltas *r)
1993 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
1994 return NT_STATUS_NOT_IMPLEMENTED;
1997 /****************************************************************
1998 ****************************************************************/
2000 NTSTATUS _netr_AccountSync(struct pipes_struct *p,
2001 struct netr_AccountSync *r)
2003 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2004 return NT_STATUS_NOT_IMPLEMENTED;
2007 /****************************************************************
2008 ****************************************************************/
2010 static bool wb_getdcname(TALLOC_CTX *mem_ctx,
2012 const char **dcname,
2017 struct wbcDomainControllerInfo *dc_info = NULL;
2019 result = wbcLookupDomainController(domain,
2023 case WBC_ERR_SUCCESS:
2025 case WBC_ERR_WINBIND_NOT_AVAILABLE:
2027 case WBC_ERR_DOMAIN_NOT_FOUND:
2028 *werr = WERR_NO_SUCH_DOMAIN;
2031 *werr = WERR_DOMAIN_CONTROLLER_NOT_FOUND;
2035 *dcname = talloc_strdup(mem_ctx, dc_info->dc_name);
2036 wbcFreeMemory(dc_info);
2038 *werr = WERR_NOT_ENOUGH_MEMORY;
2047 /****************************************************************
2049 ****************************************************************/
2051 WERROR _netr_GetDcName(struct pipes_struct *p,
2052 struct netr_GetDcName *r)
2057 struct netr_DsRGetDCNameInfo *info;
2060 ret = wb_getdcname(p->mem_ctx,
2063 WBC_LOOKUP_DC_IS_FLAT_NAME |
2064 WBC_LOOKUP_DC_RETURN_FLAT_NAME |
2065 WBC_LOOKUP_DC_PDC_REQUIRED,
2071 flags = DS_PDC_REQUIRED | DS_IS_FLAT_NAME | DS_RETURN_FLAT_NAME;
2073 status = dsgetdcname(p->mem_ctx,
2080 if (!NT_STATUS_IS_OK(status)) {
2081 return ntstatus_to_werror(status);
2084 *r->out.dcname = talloc_strdup(p->mem_ctx, info->dc_unc);
2086 if (!*r->out.dcname) {
2087 return WERR_NOT_ENOUGH_MEMORY;
2093 /****************************************************************
2095 ****************************************************************/
2097 WERROR _netr_GetAnyDCName(struct pipes_struct *p,
2098 struct netr_GetAnyDCName *r)
2103 struct netr_DsRGetDCNameInfo *info;
2106 ret = wb_getdcname(p->mem_ctx,
2109 WBC_LOOKUP_DC_IS_FLAT_NAME |
2110 WBC_LOOKUP_DC_RETURN_FLAT_NAME,
2116 flags = DS_IS_FLAT_NAME | DS_RETURN_FLAT_NAME;
2118 status = dsgetdcname(p->mem_ctx,
2125 if (!NT_STATUS_IS_OK(status)) {
2126 return ntstatus_to_werror(status);
2129 *r->out.dcname = talloc_strdup(p->mem_ctx, info->dc_unc);
2131 if (!*r->out.dcname) {
2132 return WERR_NOT_ENOUGH_MEMORY;
2138 /****************************************************************
2139 ****************************************************************/
2141 NTSTATUS _netr_DatabaseSync2(struct pipes_struct *p,
2142 struct netr_DatabaseSync2 *r)
2144 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2145 return NT_STATUS_NOT_IMPLEMENTED;
2148 /****************************************************************
2149 ****************************************************************/
2151 NTSTATUS _netr_DatabaseRedo(struct pipes_struct *p,
2152 struct netr_DatabaseRedo *r)
2154 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2155 return NT_STATUS_NOT_IMPLEMENTED;
2158 /****************************************************************
2159 ****************************************************************/
2161 WERROR _netr_DsRGetDCName(struct pipes_struct *p,
2162 struct netr_DsRGetDCName *r)
2164 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2165 return WERR_NOT_SUPPORTED;
2168 /****************************************************************
2169 ****************************************************************/
2171 NTSTATUS _netr_LogonGetCapabilities(struct pipes_struct *p,
2172 struct netr_LogonGetCapabilities *r)
2174 struct netlogon_creds_CredentialState *creds;
2178 status = netr_creds_server_step_check(p, p->mem_ctx,
2179 r->in.computer_name,
2181 r->out.return_authenticator,
2184 if (!NT_STATUS_IS_OK(status)) {
2188 if (r->in.query_level != 1) {
2189 return NT_STATUS_NOT_SUPPORTED;
2192 r->out.capabilities->server_capabilities = creds->negotiate_flags;
2194 return NT_STATUS_OK;
2197 /****************************************************************
2198 ****************************************************************/
2200 WERROR _netr_NETRLOGONSETSERVICEBITS(struct pipes_struct *p,
2201 struct netr_NETRLOGONSETSERVICEBITS *r)
2203 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2204 return WERR_NOT_SUPPORTED;
2207 /****************************************************************
2208 ****************************************************************/
2210 WERROR _netr_LogonGetTrustRid(struct pipes_struct *p,
2211 struct netr_LogonGetTrustRid *r)
2213 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2214 return WERR_NOT_SUPPORTED;
2217 /****************************************************************
2218 ****************************************************************/
2220 WERROR _netr_NETRLOGONCOMPUTESERVERDIGEST(struct pipes_struct *p,
2221 struct netr_NETRLOGONCOMPUTESERVERDIGEST *r)
2223 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2224 return WERR_NOT_SUPPORTED;
2227 /****************************************************************
2228 ****************************************************************/
2230 WERROR _netr_NETRLOGONCOMPUTECLIENTDIGEST(struct pipes_struct *p,
2231 struct netr_NETRLOGONCOMPUTECLIENTDIGEST *r)
2233 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2234 return WERR_NOT_SUPPORTED;
2237 /****************************************************************
2238 ****************************************************************/
2240 WERROR _netr_DsRGetDCNameEx(struct pipes_struct *p,
2241 struct netr_DsRGetDCNameEx *r)
2243 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2244 return WERR_NOT_SUPPORTED;
2247 /****************************************************************
2248 ****************************************************************/
2250 WERROR _netr_DsRGetSiteName(struct pipes_struct *p,
2251 struct netr_DsRGetSiteName *r)
2253 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2254 return WERR_NOT_SUPPORTED;
2257 /****************************************************************
2258 ****************************************************************/
2260 NTSTATUS _netr_LogonGetDomainInfo(struct pipes_struct *p,
2261 struct netr_LogonGetDomainInfo *r)
2263 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2264 return NT_STATUS_NOT_IMPLEMENTED;
2267 /****************************************************************
2268 ****************************************************************/
2270 NTSTATUS _netr_ServerPasswordGet(struct pipes_struct *p,
2271 struct netr_ServerPasswordGet *r)
2273 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2274 return NT_STATUS_NOT_SUPPORTED;
2277 /****************************************************************
2278 ****************************************************************/
2280 NTSTATUS _netr_NetrLogonSendToSam(struct pipes_struct *p,
2281 struct netr_NetrLogonSendToSam *r)
2283 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2284 return NT_STATUS_NOT_IMPLEMENTED;
2287 /****************************************************************
2288 ****************************************************************/
2290 WERROR _netr_DsRAddressToSitenamesW(struct pipes_struct *p,
2291 struct netr_DsRAddressToSitenamesW *r)
2293 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2294 return WERR_NOT_SUPPORTED;
2297 /****************************************************************
2298 ****************************************************************/
2300 WERROR _netr_DsRGetDCNameEx2(struct pipes_struct *p,
2301 struct netr_DsRGetDCNameEx2 *r)
2303 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2304 return WERR_NOT_SUPPORTED;
2307 /****************************************************************
2308 ****************************************************************/
2310 WERROR _netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN(struct pipes_struct *p,
2311 struct netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN *r)
2313 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2314 return WERR_NOT_SUPPORTED;
2317 /****************************************************************
2318 ****************************************************************/
2320 WERROR _netr_NetrEnumerateTrustedDomainsEx(struct pipes_struct *p,
2321 struct netr_NetrEnumerateTrustedDomainsEx *r)
2323 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2324 return WERR_NOT_SUPPORTED;
2327 /****************************************************************
2328 ****************************************************************/
2330 WERROR _netr_DsRAddressToSitenamesExW(struct pipes_struct *p,
2331 struct netr_DsRAddressToSitenamesExW *r)
2333 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2334 return WERR_NOT_SUPPORTED;
2337 /****************************************************************
2338 ****************************************************************/
2340 WERROR _netr_DsrGetDcSiteCoverageW(struct pipes_struct *p,
2341 struct netr_DsrGetDcSiteCoverageW *r)
2343 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2344 return WERR_NOT_SUPPORTED;
2347 /****************************************************************
2348 ****************************************************************/
2350 WERROR _netr_DsrEnumerateDomainTrusts(struct pipes_struct *p,
2351 struct netr_DsrEnumerateDomainTrusts *r)
2353 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2354 return WERR_NOT_SUPPORTED;
2357 /****************************************************************
2358 ****************************************************************/
2360 WERROR _netr_DsrDeregisterDNSHostRecords(struct pipes_struct *p,
2361 struct netr_DsrDeregisterDNSHostRecords *r)
2363 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2364 return WERR_NOT_SUPPORTED;
2367 /****************************************************************
2368 ****************************************************************/
2370 NTSTATUS _netr_ServerTrustPasswordsGet(struct pipes_struct *p,
2371 struct netr_ServerTrustPasswordsGet *r)
2373 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2374 return NT_STATUS_NOT_IMPLEMENTED;
2377 /****************************************************************
2378 ****************************************************************/
2380 static NTSTATUS fill_forest_trust_array(TALLOC_CTX *mem_ctx,
2381 struct lsa_ForestTrustInformation *info)
2383 struct lsa_ForestTrustRecord *e;
2384 struct pdb_domain_info *dom_info;
2385 struct lsa_ForestTrustDomainInfo *domain_info;
2386 char **upn_suffixes = NULL;
2387 uint32_t num_suffixes = 0;
2391 dom_info = pdb_get_domain_info(mem_ctx);
2392 if (dom_info == NULL) {
2393 return NT_STATUS_NO_MEMORY;
2399 status = pdb_enum_upn_suffixes(info, &num_suffixes, &upn_suffixes);
2401 if (NT_STATUS_IS_OK(status) && (num_suffixes > 0)) {
2402 info->count += num_suffixes;
2405 info->entries = talloc_array(info, struct lsa_ForestTrustRecord *, info->count);
2406 if (info->entries == NULL) {
2407 return NT_STATUS_NO_MEMORY;
2410 e = talloc(info, struct lsa_ForestTrustRecord);
2412 return NT_STATUS_NO_MEMORY;
2416 e->type = LSA_FOREST_TRUST_TOP_LEVEL_NAME;
2417 e->time = 0; /* so far always 0 in trces. */
2418 e->forest_trust_data.top_level_name.string = talloc_steal(info,
2419 dom_info->dns_forest);
2421 info->entries[0] = e;
2423 if (num_suffixes > 0) {
2424 for (i = 0; i < num_suffixes ; i++) {
2425 e = talloc(info, struct lsa_ForestTrustRecord);
2427 return NT_STATUS_NO_MEMORY;
2431 e->type = LSA_FOREST_TRUST_TOP_LEVEL_NAME;
2432 e->time = 0; /* so far always 0 in traces. */
2433 e->forest_trust_data.top_level_name.string = upn_suffixes[i];
2434 info->entries[1 + i] = e;
2438 e = talloc(info, struct lsa_ForestTrustRecord);
2440 return NT_STATUS_NO_MEMORY;
2443 /* TODO: check if disabled and set flags accordingly */
2445 e->type = LSA_FOREST_TRUST_DOMAIN_INFO;
2446 e->time = 0; /* so far always 0 in traces. */
2448 domain_info = &e->forest_trust_data.domain_info;
2449 domain_info->domain_sid = dom_sid_dup(info, &dom_info->sid);
2451 domain_info->dns_domain_name.string = talloc_steal(info,
2452 dom_info->dns_domain);
2453 domain_info->netbios_domain_name.string = talloc_steal(info,
2456 info->entries[info->count - 1] = e;
2458 return NT_STATUS_OK;
2461 /****************************************************************
2462 ****************************************************************/
2464 WERROR _netr_DsRGetForestTrustInformation(struct pipes_struct *p,
2465 struct netr_DsRGetForestTrustInformation *r)
2468 struct lsa_ForestTrustInformation *info, **info_ptr;
2470 if (!(p->pipe_bound && (p->auth.auth_type != DCERPC_AUTH_TYPE_NONE)
2471 && (p->auth.auth_level != DCERPC_AUTH_LEVEL_NONE))) {
2472 p->fault_state = DCERPC_FAULT_ACCESS_DENIED;
2473 return WERR_ACCESS_DENIED;
2476 if (r->in.flags & (~DS_GFTI_UPDATE_TDO)) {
2477 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2478 return WERR_INVALID_FLAGS;
2481 if ((r->in.flags & DS_GFTI_UPDATE_TDO) && (lp_server_role() != ROLE_DOMAIN_PDC)) {
2482 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2483 return WERR_NERR_NOTPRIMARY;
2486 if ((r->in.trusted_domain_name == NULL) && (r->in.flags & DS_GFTI_UPDATE_TDO)) {
2487 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2488 return WERR_INVALID_PARAMETER;
2491 /* retrieve forest trust information and stop further processing */
2492 if (r->in.trusted_domain_name == NULL) {
2493 info_ptr = talloc(p->mem_ctx, struct lsa_ForestTrustInformation *);
2494 if (info_ptr == NULL) {
2495 p->fault_state = DCERPC_FAULT_CANT_PERFORM;
2496 return WERR_NOT_ENOUGH_MEMORY;
2498 info = talloc_zero(info_ptr, struct lsa_ForestTrustInformation);
2500 p->fault_state = DCERPC_FAULT_CANT_PERFORM;
2501 return WERR_NOT_ENOUGH_MEMORY;
2504 /* Fill forest trust information and expand UPN suffixes list */
2505 status = fill_forest_trust_array(p->mem_ctx, info);
2506 if (!NT_STATUS_IS_OK(status)) {
2507 p->fault_state = DCERPC_FAULT_CANT_PERFORM;
2508 return WERR_NOT_ENOUGH_MEMORY;
2512 r->out.forest_trust_info = info_ptr;
2518 /* TODO: implement remaining parts of DsrGetForestTrustInformation (opnum 43)
2519 * when trusted_domain_name is not NULL */
2521 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2522 return WERR_NOT_SUPPORTED;
2525 /****************************************************************
2526 _netr_GetForestTrustInformation
2527 ****************************************************************/
2529 NTSTATUS _netr_GetForestTrustInformation(struct pipes_struct *p,
2530 struct netr_GetForestTrustInformation *r)
2533 struct netlogon_creds_CredentialState *creds;
2534 struct lsa_ForestTrustInformation *info, **info_ptr;
2536 /* TODO: check server name */
2539 status = netr_creds_server_step_check(p, p->mem_ctx,
2540 r->in.computer_name,
2542 r->out.return_authenticator,
2545 if (!NT_STATUS_IS_OK(status)) {
2549 if ((creds->secure_channel_type != SEC_CHAN_DNS_DOMAIN) &&
2550 (creds->secure_channel_type != SEC_CHAN_DOMAIN)) {
2551 return NT_STATUS_NOT_IMPLEMENTED;
2554 info_ptr = talloc(p->mem_ctx, struct lsa_ForestTrustInformation *);
2556 return NT_STATUS_NO_MEMORY;
2558 info = talloc_zero(info_ptr, struct lsa_ForestTrustInformation);
2560 return NT_STATUS_NO_MEMORY;
2563 /* Fill forest trust information, do expand UPN suffixes list */
2564 status = fill_forest_trust_array(p->mem_ctx, info);
2565 if (!NT_STATUS_IS_OK(status)) {
2570 r->out.forest_trust_info = info_ptr;
2572 return NT_STATUS_OK;
2575 /****************************************************************
2576 ****************************************************************/
2578 static NTSTATUS get_password_from_trustAuth(TALLOC_CTX *mem_ctx,
2579 const DATA_BLOB *trustAuth_blob,
2580 struct netlogon_creds_CredentialState *creds,
2581 struct samr_Password *current_pw_enc,
2582 struct samr_Password *previous_pw_enc)
2584 enum ndr_err_code ndr_err;
2585 struct trustAuthInOutBlob trustAuth;
2587 ndr_err = ndr_pull_struct_blob_all(trustAuth_blob, mem_ctx, &trustAuth,
2588 (ndr_pull_flags_fn_t)ndr_pull_trustAuthInOutBlob);
2589 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2590 return NT_STATUS_UNSUCCESSFUL;
2593 if (trustAuth.count != 0 && trustAuth.current.count != 0 &&
2594 trustAuth.current.array[0].AuthType == TRUST_AUTH_TYPE_CLEAR) {
2595 mdfour(current_pw_enc->hash,
2596 trustAuth.current.array[0].AuthInfo.clear.password,
2597 trustAuth.current.array[0].AuthInfo.clear.size);
2598 netlogon_creds_des_encrypt(creds, current_pw_enc);
2600 return NT_STATUS_UNSUCCESSFUL;
2604 if (trustAuth.previous.count != 0 &&
2605 trustAuth.previous.array[0].AuthType == TRUST_AUTH_TYPE_CLEAR) {
2606 mdfour(previous_pw_enc->hash,
2607 trustAuth.previous.array[0].AuthInfo.clear.password,
2608 trustAuth.previous.array[0].AuthInfo.clear.size);
2609 netlogon_creds_des_encrypt(creds, previous_pw_enc);
2611 ZERO_STRUCTP(previous_pw_enc);
2614 return NT_STATUS_OK;
2617 /****************************************************************
2618 _netr_ServerGetTrustInfo
2619 ****************************************************************/
2621 NTSTATUS _netr_ServerGetTrustInfo(struct pipes_struct *p,
2622 struct netr_ServerGetTrustInfo *r)
2625 struct netlogon_creds_CredentialState *creds;
2627 size_t account_name_last;
2629 struct netr_TrustInfo *trust_info;
2630 struct pdb_trusted_domain *td;
2632 /* TODO: check server name */
2635 status = netr_creds_server_step_check(p, p->mem_ctx,
2636 r->in.computer_name,
2638 r->out.return_authenticator,
2641 if (!NT_STATUS_IS_OK(status)) {
2645 account_name = talloc_strdup(p->mem_ctx, r->in.account_name);
2646 if (account_name == NULL) {
2647 return NT_STATUS_NO_MEMORY;
2650 account_name_last = strlen(account_name);
2651 if (account_name_last == 0) {
2652 return NT_STATUS_INVALID_PARAMETER;
2654 account_name_last--;
2655 if (account_name[account_name_last] == '.') {
2656 account_name[account_name_last] = '\0';
2659 if ((creds->secure_channel_type != SEC_CHAN_DNS_DOMAIN) &&
2660 (creds->secure_channel_type != SEC_CHAN_DOMAIN)) {
2668 account_name_last = strlen(account_name);
2669 if (account_name_last == 0) {
2670 return NT_STATUS_INVALID_PARAMETER;
2672 account_name_last--;
2673 if (account_name[account_name_last] == '$') {
2674 account_name[account_name_last] = '\0';
2677 status = pdb_get_trusted_domain(p->mem_ctx, account_name, &td);
2678 if (!NT_STATUS_IS_OK(status)) {
2682 if (r->out.trust_info != NULL) {
2683 trust_info = talloc_zero(p->mem_ctx, struct netr_TrustInfo);
2684 if (trust_info == NULL) {
2685 return NT_STATUS_NO_MEMORY;
2687 trust_info->count = 1;
2689 trust_info->data = talloc_array(trust_info, uint32_t, 1);
2690 if (trust_info->data == NULL) {
2691 return NT_STATUS_NO_MEMORY;
2693 trust_info->data[0] = td->trust_attributes;
2695 *r->out.trust_info = trust_info;
2698 if (td->trust_auth_incoming.data == NULL) {
2699 return NT_STATUS_INVALID_PARAMETER;
2702 status = get_password_from_trustAuth(p->mem_ctx,
2703 &td->trust_auth_incoming,
2705 r->out.new_owf_password,
2706 r->out.old_owf_password);
2708 if (!NT_STATUS_IS_OK(status)) {
2713 /* TODO: look for machine password */
2714 ZERO_STRUCTP(r->out.new_owf_password);
2715 ZERO_STRUCTP(r->out.old_owf_password);
2717 return NT_STATUS_NOT_IMPLEMENTED;
2720 return NT_STATUS_OK;
2723 /****************************************************************
2724 ****************************************************************/
2726 NTSTATUS _netr_Unused47(struct pipes_struct *p,
2727 struct netr_Unused47 *r)
2729 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2730 return NT_STATUS_NOT_IMPLEMENTED;
2733 /****************************************************************
2734 ****************************************************************/
2736 NTSTATUS _netr_DsrUpdateReadOnlyServerDnsRecords(struct pipes_struct *p,
2737 struct netr_DsrUpdateReadOnlyServerDnsRecords *r)
2739 p->fault_state = DCERPC_FAULT_OP_RNG_ERROR;
2740 return NT_STATUS_NOT_IMPLEMENTED;