Revert "s3: Use cups-config --libs"
[Samba/gebeck_regimport.git] / source3 / rpc_server / srv_netlog_nt.c
blobb3e54050d47cd57476c6b9529a5768a64c2471e8
1 /*
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. */
27 #include "includes.h"
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/cli_samr.h"
33 #include "../librpc/gen_ndr/cli_lsa.h"
34 #include "rpc_client/cli_lsarpc.h"
35 #include "librpc/gen_ndr/messaging.h"
36 #include "../lib/crypto/md4.h"
38 extern userdom_struct current_user_info;
40 #undef DBGC_CLASS
41 #define DBGC_CLASS DBGC_RPC_SRV
43 struct netlogon_server_pipe_state {
44 struct netr_Credential client_challenge;
45 struct netr_Credential server_challenge;
48 /*************************************************************************
49 _netr_LogonControl
50 *************************************************************************/
52 WERROR _netr_LogonControl(struct pipes_struct *p,
53 struct netr_LogonControl *r)
55 struct netr_LogonControl2Ex l;
57 switch (r->in.level) {
58 case 1:
59 break;
60 case 2:
61 return WERR_NOT_SUPPORTED;
62 default:
63 return WERR_UNKNOWN_LEVEL;
66 l.in.logon_server = r->in.logon_server;
67 l.in.function_code = r->in.function_code;
68 l.in.level = r->in.level;
69 l.in.data = NULL;
70 l.out.query = r->out.query;
72 return _netr_LogonControl2Ex(p, &l);
75 /****************************************************************************
76 Send a message to smbd to do a sam synchronisation
77 **************************************************************************/
79 static void send_sync_message(struct messaging_context *msg_ctx)
81 DEBUG(3, ("sending sam synchronisation message\n"));
82 message_send_all(msg_ctx, MSG_SMB_SAM_SYNC, NULL, 0, NULL);
85 /*************************************************************************
86 _netr_LogonControl2
87 *************************************************************************/
89 WERROR _netr_LogonControl2(struct pipes_struct *p,
90 struct netr_LogonControl2 *r)
92 struct netr_LogonControl2Ex l;
94 l.in.logon_server = r->in.logon_server;
95 l.in.function_code = r->in.function_code;
96 l.in.level = r->in.level;
97 l.in.data = r->in.data;
98 l.out.query = r->out.query;
100 return _netr_LogonControl2Ex(p, &l);
103 /*************************************************************************
104 *************************************************************************/
106 static bool wb_change_trust_creds(const char *domain, WERROR *tc_status)
108 wbcErr result;
109 struct wbcAuthErrorInfo *error = NULL;
111 result = wbcChangeTrustCredentials(domain, &error);
112 switch (result) {
113 case WBC_ERR_WINBIND_NOT_AVAILABLE:
114 return false;
115 case WBC_ERR_DOMAIN_NOT_FOUND:
116 *tc_status = WERR_NO_SUCH_DOMAIN;
117 return true;
118 case WBC_ERR_SUCCESS:
119 *tc_status = WERR_OK;
120 return true;
121 default:
122 break;
125 if (error && error->nt_status != 0) {
126 *tc_status = ntstatus_to_werror(NT_STATUS(error->nt_status));
127 } else {
128 *tc_status = WERR_TRUST_FAILURE;
130 wbcFreeMemory(error);
131 return true;
134 /*************************************************************************
135 *************************************************************************/
137 static bool wb_check_trust_creds(const char *domain, WERROR *tc_status)
139 wbcErr result;
140 struct wbcAuthErrorInfo *error = NULL;
142 result = wbcCheckTrustCredentials(domain, &error);
143 switch (result) {
144 case WBC_ERR_WINBIND_NOT_AVAILABLE:
145 return false;
146 case WBC_ERR_DOMAIN_NOT_FOUND:
147 *tc_status = WERR_NO_SUCH_DOMAIN;
148 return true;
149 case WBC_ERR_SUCCESS:
150 *tc_status = WERR_OK;
151 return true;
152 default:
153 break;
156 if (error && error->nt_status != 0) {
157 *tc_status = ntstatus_to_werror(NT_STATUS(error->nt_status));
158 } else {
159 *tc_status = WERR_TRUST_FAILURE;
161 wbcFreeMemory(error);
162 return true;
165 /****************************************************************
166 _netr_LogonControl2Ex
167 ****************************************************************/
169 WERROR _netr_LogonControl2Ex(struct pipes_struct *p,
170 struct netr_LogonControl2Ex *r)
172 uint32_t flags = 0x0;
173 WERROR pdc_connection_status = WERR_OK;
174 uint32_t logon_attempts = 0x0;
175 WERROR tc_status;
176 fstring dc_name2;
177 const char *dc_name = NULL;
178 struct sockaddr_storage dc_ss;
179 const char *domain = NULL;
180 struct netr_NETLOGON_INFO_1 *info1;
181 struct netr_NETLOGON_INFO_2 *info2;
182 struct netr_NETLOGON_INFO_3 *info3;
183 struct netr_NETLOGON_INFO_4 *info4;
184 const char *fn;
185 uint32_t acct_ctrl;
187 switch (p->opnum) {
188 case NDR_NETR_LOGONCONTROL:
189 fn = "_netr_LogonControl";
190 break;
191 case NDR_NETR_LOGONCONTROL2:
192 fn = "_netr_LogonControl2";
193 break;
194 case NDR_NETR_LOGONCONTROL2EX:
195 fn = "_netr_LogonControl2Ex";
196 break;
197 default:
198 return WERR_INVALID_PARAM;
201 acct_ctrl = p->server_info->info3->base.acct_flags;
203 switch (r->in.function_code) {
204 case NETLOGON_CONTROL_TC_VERIFY:
205 case NETLOGON_CONTROL_CHANGE_PASSWORD:
206 case NETLOGON_CONTROL_REDISCOVER:
207 if ((geteuid() != sec_initial_uid()) &&
208 !nt_token_check_domain_rid(p->server_info->ptok, DOMAIN_RID_ADMINS) &&
209 !nt_token_check_sid(&global_sid_Builtin_Administrators, p->server_info->ptok) &&
210 !(acct_ctrl & (ACB_WSTRUST | ACB_SVRTRUST))) {
211 return WERR_ACCESS_DENIED;
213 break;
214 default:
215 break;
218 tc_status = WERR_NO_SUCH_DOMAIN;
220 switch (r->in.function_code) {
221 case NETLOGON_CONTROL_QUERY:
222 tc_status = WERR_OK;
223 break;
224 case NETLOGON_CONTROL_REPLICATE:
225 case NETLOGON_CONTROL_SYNCHRONIZE:
226 case NETLOGON_CONTROL_PDC_REPLICATE:
227 case NETLOGON_CONTROL_BACKUP_CHANGE_LOG:
228 case NETLOGON_CONTROL_BREAKPOINT:
229 if (acct_ctrl & ACB_NORMAL) {
230 return WERR_NOT_SUPPORTED;
231 } else if (acct_ctrl & (ACB_WSTRUST | ACB_SVRTRUST)) {
232 return WERR_ACCESS_DENIED;
233 } else {
234 return WERR_ACCESS_DENIED;
236 case NETLOGON_CONTROL_TRUNCATE_LOG:
237 if (acct_ctrl & ACB_NORMAL) {
238 break;
239 } else if (acct_ctrl & (ACB_WSTRUST | ACB_SVRTRUST)) {
240 return WERR_ACCESS_DENIED;
241 } else {
242 return WERR_ACCESS_DENIED;
245 case NETLOGON_CONTROL_TRANSPORT_NOTIFY:
246 case NETLOGON_CONTROL_FORCE_DNS_REG:
247 case NETLOGON_CONTROL_QUERY_DNS_REG:
248 return WERR_NOT_SUPPORTED;
249 case NETLOGON_CONTROL_FIND_USER:
250 if (!r->in.data || !r->in.data->user) {
251 return WERR_NOT_SUPPORTED;
253 break;
254 case NETLOGON_CONTROL_SET_DBFLAG:
255 if (!r->in.data) {
256 return WERR_NOT_SUPPORTED;
258 break;
259 case NETLOGON_CONTROL_TC_VERIFY:
260 if (!r->in.data || !r->in.data->domain) {
261 return WERR_NOT_SUPPORTED;
264 if (!wb_check_trust_creds(r->in.data->domain, &tc_status)) {
265 return WERR_NOT_SUPPORTED;
267 break;
268 case NETLOGON_CONTROL_TC_QUERY:
269 if (!r->in.data || !r->in.data->domain) {
270 return WERR_NOT_SUPPORTED;
273 domain = r->in.data->domain;
275 if (!is_trusted_domain(domain)) {
276 break;
279 if (!get_dc_name(domain, NULL, dc_name2, &dc_ss)) {
280 tc_status = WERR_NO_LOGON_SERVERS;
281 break;
284 dc_name = talloc_asprintf(p->mem_ctx, "\\\\%s", dc_name2);
285 if (!dc_name) {
286 return WERR_NOMEM;
289 tc_status = WERR_OK;
291 break;
293 case NETLOGON_CONTROL_REDISCOVER:
294 if (!r->in.data || !r->in.data->domain) {
295 return WERR_NOT_SUPPORTED;
298 domain = r->in.data->domain;
300 if (!is_trusted_domain(domain)) {
301 break;
304 if (!get_dc_name(domain, NULL, dc_name2, &dc_ss)) {
305 tc_status = WERR_NO_LOGON_SERVERS;
306 break;
309 dc_name = talloc_asprintf(p->mem_ctx, "\\\\%s", dc_name2);
310 if (!dc_name) {
311 return WERR_NOMEM;
314 tc_status = WERR_OK;
316 break;
318 case NETLOGON_CONTROL_CHANGE_PASSWORD:
319 if (!r->in.data || !r->in.data->domain) {
320 return WERR_NOT_SUPPORTED;
323 if (!wb_change_trust_creds(r->in.data->domain, &tc_status)) {
324 return WERR_NOT_SUPPORTED;
326 break;
328 default:
329 /* no idea what this should be */
330 DEBUG(0,("%s: unimplemented function level [%d]\n",
331 fn, r->in.function_code));
332 return WERR_UNKNOWN_LEVEL;
335 /* prepare the response */
337 switch (r->in.level) {
338 case 1:
339 info1 = TALLOC_ZERO_P(p->mem_ctx, struct netr_NETLOGON_INFO_1);
340 W_ERROR_HAVE_NO_MEMORY(info1);
342 info1->flags = flags;
343 info1->pdc_connection_status = pdc_connection_status;
345 r->out.query->info1 = info1;
346 break;
347 case 2:
348 info2 = TALLOC_ZERO_P(p->mem_ctx, struct netr_NETLOGON_INFO_2);
349 W_ERROR_HAVE_NO_MEMORY(info2);
351 info2->flags = flags;
352 info2->pdc_connection_status = pdc_connection_status;
353 info2->trusted_dc_name = dc_name;
354 info2->tc_connection_status = tc_status;
356 r->out.query->info2 = info2;
357 break;
358 case 3:
359 info3 = TALLOC_ZERO_P(p->mem_ctx, struct netr_NETLOGON_INFO_3);
360 W_ERROR_HAVE_NO_MEMORY(info3);
362 info3->flags = flags;
363 info3->logon_attempts = logon_attempts;
365 r->out.query->info3 = info3;
366 break;
367 case 4:
368 info4 = TALLOC_ZERO_P(p->mem_ctx, struct netr_NETLOGON_INFO_4);
369 W_ERROR_HAVE_NO_MEMORY(info4);
371 info4->trusted_dc_name = dc_name;
372 info4->trusted_domain_name = r->in.data->domain;
374 r->out.query->info4 = info4;
375 break;
376 default:
377 return WERR_UNKNOWN_LEVEL;
380 if (lp_server_role() == ROLE_DOMAIN_BDC) {
381 send_sync_message(p->msg_ctx);
384 return WERR_OK;
387 /*************************************************************************
388 _netr_NetrEnumerateTrustedDomains
389 *************************************************************************/
391 NTSTATUS _netr_NetrEnumerateTrustedDomains(struct pipes_struct *p,
392 struct netr_NetrEnumerateTrustedDomains *r)
394 NTSTATUS status;
395 DATA_BLOB blob;
396 int num_domains = 0;
397 const char **trusted_domains = NULL;
398 struct lsa_DomainList domain_list;
399 struct rpc_pipe_client *cli = NULL;
400 struct policy_handle pol;
401 uint32_t enum_ctx = 0;
402 int i;
403 uint32_t max_size = (uint32_t)-1;
405 DEBUG(6,("_netr_NetrEnumerateTrustedDomains: %d\n", __LINE__));
407 status = rpc_pipe_open_internal(p->mem_ctx, &ndr_table_lsarpc.syntax_id,
408 p->server_info,
409 p->msg_ctx,
410 &cli);
411 if (!NT_STATUS_IS_OK(status)) {
412 return status;
415 status = rpccli_lsa_open_policy2(cli, p->mem_ctx,
416 true,
417 LSA_POLICY_VIEW_LOCAL_INFORMATION,
418 &pol);
419 if (!NT_STATUS_IS_OK(status)) {
420 goto out;
423 do {
424 /* Lookup list of trusted domains */
426 status = rpccli_lsa_EnumTrustDom(cli, p->mem_ctx,
427 &pol,
428 &enum_ctx,
429 &domain_list,
430 max_size);
431 if (!NT_STATUS_IS_OK(status) &&
432 !NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES) &&
433 !NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) {
434 goto out;
437 for (i = 0; i < domain_list.count; i++) {
438 if (!add_string_to_array(p->mem_ctx, domain_list.domains[i].name.string,
439 &trusted_domains, &num_domains)) {
440 status = NT_STATUS_NO_MEMORY;
441 goto out;
444 } while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES));
446 if (num_domains > 0) {
447 /* multi sz terminate */
448 trusted_domains = talloc_realloc(p->mem_ctx, trusted_domains, const char *, num_domains + 1);
449 if (trusted_domains == NULL) {
450 status = NT_STATUS_NO_MEMORY;
451 goto out;
454 trusted_domains[num_domains] = NULL;
457 if (!push_reg_multi_sz(trusted_domains, &blob, trusted_domains)) {
458 TALLOC_FREE(trusted_domains);
459 status = NT_STATUS_NO_MEMORY;
460 goto out;
463 r->out.trusted_domains_blob->data = blob.data;
464 r->out.trusted_domains_blob->length = blob.length;
466 DEBUG(6,("_netr_NetrEnumerateTrustedDomains: %d\n", __LINE__));
468 status = NT_STATUS_OK;
470 out:
471 if (cli && is_valid_policy_hnd(&pol)) {
472 rpccli_lsa_Close(cli, p->mem_ctx, &pol);
475 return status;
478 /*************************************************************************
479 *************************************************************************/
481 static NTSTATUS samr_find_machine_account(TALLOC_CTX *mem_ctx,
482 struct rpc_pipe_client *cli,
483 const char *account_name,
484 uint32_t access_mask,
485 struct dom_sid2 **domain_sid_p,
486 uint32_t *user_rid_p,
487 struct policy_handle *user_handle)
489 NTSTATUS status;
490 struct policy_handle connect_handle, domain_handle;
491 struct lsa_String domain_name;
492 struct dom_sid2 *domain_sid;
493 struct lsa_String names;
494 struct samr_Ids rids;
495 struct samr_Ids types;
496 uint32_t rid;
498 status = rpccli_samr_Connect2(cli, mem_ctx,
499 global_myname(),
500 SAMR_ACCESS_CONNECT_TO_SERVER |
501 SAMR_ACCESS_ENUM_DOMAINS |
502 SAMR_ACCESS_LOOKUP_DOMAIN,
503 &connect_handle);
504 if (!NT_STATUS_IS_OK(status)) {
505 goto out;
508 init_lsa_String(&domain_name, get_global_sam_name());
510 status = rpccli_samr_LookupDomain(cli, mem_ctx,
511 &connect_handle,
512 &domain_name,
513 &domain_sid);
514 if (!NT_STATUS_IS_OK(status)) {
515 goto out;
518 status = rpccli_samr_OpenDomain(cli, mem_ctx,
519 &connect_handle,
520 SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
521 domain_sid,
522 &domain_handle);
523 if (!NT_STATUS_IS_OK(status)) {
524 goto out;
527 init_lsa_String(&names, account_name);
529 status = rpccli_samr_LookupNames(cli, mem_ctx,
530 &domain_handle,
532 &names,
533 &rids,
534 &types);
535 if (!NT_STATUS_IS_OK(status)) {
536 goto out;
539 if (rids.count != 1) {
540 status = NT_STATUS_NO_SUCH_USER;
541 goto out;
543 if (rids.count != types.count) {
544 status = NT_STATUS_INVALID_PARAMETER;
545 goto out;
547 if (types.ids[0] != SID_NAME_USER) {
548 status = NT_STATUS_NO_SUCH_USER;
549 goto out;
552 rid = rids.ids[0];
554 status = rpccli_samr_OpenUser(cli, mem_ctx,
555 &domain_handle,
556 access_mask,
557 rid,
558 user_handle);
559 if (!NT_STATUS_IS_OK(status)) {
560 goto out;
563 if (user_rid_p) {
564 *user_rid_p = rid;
567 if (domain_sid_p) {
568 *domain_sid_p = domain_sid;
571 out:
572 if (cli && is_valid_policy_hnd(&domain_handle)) {
573 rpccli_samr_Close(cli, mem_ctx, &domain_handle);
575 if (cli && is_valid_policy_hnd(&connect_handle)) {
576 rpccli_samr_Close(cli, mem_ctx, &connect_handle);
579 return status;
582 /******************************************************************
583 gets a machine password entry. checks access rights of the host.
584 ******************************************************************/
586 static NTSTATUS get_md4pw(struct samr_Password *md4pw, const char *mach_acct,
587 enum netr_SchannelType sec_chan_type,
588 struct dom_sid *sid,
589 struct messaging_context *msg_ctx)
591 NTSTATUS status;
592 TALLOC_CTX *mem_ctx;
593 struct rpc_pipe_client *cli = NULL;
594 struct policy_handle user_handle;
595 uint32_t user_rid;
596 struct dom_sid *domain_sid;
597 uint32_t acct_ctrl;
598 union samr_UserInfo *info;
599 struct auth_serversupplied_info *server_info;
600 #if 0
601 char addr[INET6_ADDRSTRLEN];
604 * Currently this code is redundent as we already have a filter
605 * by hostname list. What this code really needs to do is to
606 * get a hosts allowed/hosts denied list from the SAM database
607 * on a per user basis, and make the access decision there.
608 * I will leave this code here for now as a reminder to implement
609 * this at a later date. JRA.
612 if (!allow_access(lp_domain_hostsdeny(), lp_domain_hostsallow(),
613 client_name(get_client_fd()),
614 client_addr(get_client_fd(),addr,sizeof(addr)))) {
615 DEBUG(0,("get_md4pw: Workstation %s denied access to domain\n", mach_acct));
616 return False;
618 #endif /* 0 */
620 mem_ctx = talloc_new(talloc_tos());
621 if (mem_ctx == NULL) {
622 status = NT_STATUS_NO_MEMORY;
623 goto out;
626 status = make_server_info_system(mem_ctx, &server_info);
627 if (!NT_STATUS_IS_OK(status)) {
628 goto out;
631 ZERO_STRUCT(user_handle);
633 status = rpc_pipe_open_internal(mem_ctx, &ndr_table_samr.syntax_id,
634 server_info, msg_ctx,
635 &cli);
636 if (!NT_STATUS_IS_OK(status)) {
637 goto out;
640 become_root();
641 status = samr_find_machine_account(mem_ctx, cli, mach_acct,
642 SEC_FLAG_MAXIMUM_ALLOWED,
643 &domain_sid, &user_rid,
644 &user_handle);
645 unbecome_root();
646 if (!NT_STATUS_IS_OK(status)) {
647 goto out;
650 status = rpccli_samr_QueryUserInfo2(cli, mem_ctx,
651 &user_handle,
652 UserControlInformation,
653 &info);
654 if (!NT_STATUS_IS_OK(status)) {
655 goto out;
658 acct_ctrl = info->info16.acct_flags;
660 if (acct_ctrl & ACB_DISABLED) {
661 DEBUG(0,("get_md4pw: Workstation %s: account is disabled\n", mach_acct));
662 status = NT_STATUS_ACCOUNT_DISABLED;
663 goto out;
666 if (!(acct_ctrl & ACB_SVRTRUST) &&
667 !(acct_ctrl & ACB_WSTRUST) &&
668 !(acct_ctrl & ACB_DOMTRUST))
670 DEBUG(0,("get_md4pw: Workstation %s: account is not a trust account\n", mach_acct));
671 status = NT_STATUS_NO_TRUST_SAM_ACCOUNT;
672 goto out;
675 switch (sec_chan_type) {
676 case SEC_CHAN_BDC:
677 if (!(acct_ctrl & ACB_SVRTRUST)) {
678 DEBUG(0,("get_md4pw: Workstation %s: BDC secure channel requested "
679 "but not a server trust account\n", mach_acct));
680 status = NT_STATUS_NO_TRUST_SAM_ACCOUNT;
681 goto out;
683 break;
684 case SEC_CHAN_WKSTA:
685 if (!(acct_ctrl & ACB_WSTRUST)) {
686 DEBUG(0,("get_md4pw: Workstation %s: WORKSTATION secure channel requested "
687 "but not a workstation trust account\n", mach_acct));
688 status = NT_STATUS_NO_TRUST_SAM_ACCOUNT;
689 goto out;
691 break;
692 case SEC_CHAN_DOMAIN:
693 if (!(acct_ctrl & ACB_DOMTRUST)) {
694 DEBUG(0,("get_md4pw: Workstation %s: DOMAIN secure channel requested "
695 "but not a interdomain trust account\n", mach_acct));
696 status = NT_STATUS_NO_TRUST_SAM_ACCOUNT;
697 goto out;
699 break;
700 default:
701 break;
704 become_root();
705 status = rpccli_samr_QueryUserInfo2(cli, mem_ctx,
706 &user_handle,
707 UserInternal1Information,
708 &info);
709 unbecome_root();
710 if (!NT_STATUS_IS_OK(status)) {
711 goto out;
713 if (info->info18.nt_pwd_active == 0) {
714 DEBUG(0,("get_md4pw: Workstation %s: account does not have a password\n", mach_acct));
715 status = NT_STATUS_LOGON_FAILURE;
716 goto out;
719 /* samr gives out nthash unencrypted (!) */
720 memcpy(md4pw->hash, info->info18.nt_pwd.hash, 16);
722 sid_compose(sid, domain_sid, user_rid);
724 out:
725 if (cli && is_valid_policy_hnd(&user_handle)) {
726 rpccli_samr_Close(cli, mem_ctx, &user_handle);
729 talloc_free(mem_ctx);
731 return status;
734 /*************************************************************************
735 _netr_ServerReqChallenge
736 *************************************************************************/
738 NTSTATUS _netr_ServerReqChallenge(struct pipes_struct *p,
739 struct netr_ServerReqChallenge *r)
741 struct netlogon_server_pipe_state *pipe_state =
742 talloc_get_type(p->private_data, struct netlogon_server_pipe_state);
744 if (pipe_state) {
745 DEBUG(10,("_netr_ServerReqChallenge: new challenge requested. Clearing old state.\n"));
746 talloc_free(pipe_state);
747 p->private_data = NULL;
750 pipe_state = talloc(p, struct netlogon_server_pipe_state);
751 NT_STATUS_HAVE_NO_MEMORY(pipe_state);
753 pipe_state->client_challenge = *r->in.credentials;
755 generate_random_buffer(pipe_state->server_challenge.data,
756 sizeof(pipe_state->server_challenge.data));
758 *r->out.return_credentials = pipe_state->server_challenge;
760 p->private_data = pipe_state;
762 return NT_STATUS_OK;
765 /*************************************************************************
766 _netr_ServerAuthenticate
767 Create the initial credentials.
768 *************************************************************************/
770 NTSTATUS _netr_ServerAuthenticate(struct pipes_struct *p,
771 struct netr_ServerAuthenticate *r)
773 struct netr_ServerAuthenticate3 a;
774 uint32_t negotiate_flags = 0;
775 uint32_t rid;
777 a.in.server_name = r->in.server_name;
778 a.in.account_name = r->in.account_name;
779 a.in.secure_channel_type = r->in.secure_channel_type;
780 a.in.computer_name = r->in.computer_name;
781 a.in.credentials = r->in.credentials;
782 a.in.negotiate_flags = &negotiate_flags;
784 a.out.return_credentials = r->out.return_credentials;
785 a.out.rid = &rid;
786 a.out.negotiate_flags = &negotiate_flags;
788 return _netr_ServerAuthenticate3(p, &a);
792 /*************************************************************************
793 _netr_ServerAuthenticate3
794 *************************************************************************/
796 NTSTATUS _netr_ServerAuthenticate3(struct pipes_struct *p,
797 struct netr_ServerAuthenticate3 *r)
799 NTSTATUS status;
800 uint32_t srv_flgs;
801 /* r->in.negotiate_flags is an aliased pointer to r->out.negotiate_flags,
802 * so use a copy to avoid destroying the client values. */
803 uint32_t in_neg_flags = *r->in.negotiate_flags;
804 const char *fn;
805 struct dom_sid sid;
806 struct samr_Password mach_pwd;
807 struct netlogon_creds_CredentialState *creds;
808 struct netlogon_server_pipe_state *pipe_state =
809 talloc_get_type(p->private_data, struct netlogon_server_pipe_state);
811 /* According to Microsoft (see bugid #6099)
812 * Windows 7 looks at the negotiate_flags
813 * returned in this structure *even if the
814 * call fails with access denied* ! So in order
815 * to allow Win7 to connect to a Samba NT style
816 * PDC we set the flags before we know if it's
817 * an error or not.
820 /* 0x000001ff */
821 srv_flgs = NETLOGON_NEG_ACCOUNT_LOCKOUT |
822 NETLOGON_NEG_PERSISTENT_SAMREPL |
823 NETLOGON_NEG_ARCFOUR |
824 NETLOGON_NEG_PROMOTION_COUNT |
825 NETLOGON_NEG_CHANGELOG_BDC |
826 NETLOGON_NEG_FULL_SYNC_REPL |
827 NETLOGON_NEG_MULTIPLE_SIDS |
828 NETLOGON_NEG_REDO |
829 NETLOGON_NEG_PASSWORD_CHANGE_REFUSAL |
830 NETLOGON_NEG_PASSWORD_SET2;
832 /* Ensure we support strong (128-bit) keys. */
833 if (in_neg_flags & NETLOGON_NEG_STRONG_KEYS) {
834 srv_flgs |= NETLOGON_NEG_STRONG_KEYS;
837 if (lp_server_schannel() != false) {
838 srv_flgs |= NETLOGON_NEG_SCHANNEL;
841 switch (p->opnum) {
842 case NDR_NETR_SERVERAUTHENTICATE:
843 fn = "_netr_ServerAuthenticate";
844 break;
845 case NDR_NETR_SERVERAUTHENTICATE2:
846 fn = "_netr_ServerAuthenticate2";
847 break;
848 case NDR_NETR_SERVERAUTHENTICATE3:
849 fn = "_netr_ServerAuthenticate3";
850 break;
851 default:
852 return NT_STATUS_INTERNAL_ERROR;
855 /* We use this as the key to store the creds: */
856 /* r->in.computer_name */
858 if (!pipe_state) {
859 DEBUG(0,("%s: no challenge sent to client %s\n", fn,
860 r->in.computer_name));
861 status = NT_STATUS_ACCESS_DENIED;
862 goto out;
865 if ( (lp_server_schannel() == true) &&
866 ((in_neg_flags & NETLOGON_NEG_SCHANNEL) == 0) ) {
868 /* schannel must be used, but client did not offer it. */
869 DEBUG(0,("%s: schannel required but client failed "
870 "to offer it. Client was %s\n",
871 fn, r->in.account_name));
872 status = NT_STATUS_ACCESS_DENIED;
873 goto out;
876 status = get_md4pw(&mach_pwd,
877 r->in.account_name,
878 r->in.secure_channel_type,
879 &sid, p->msg_ctx);
880 if (!NT_STATUS_IS_OK(status)) {
881 DEBUG(0,("%s: failed to get machine password for "
882 "account %s: %s\n",
883 fn, r->in.account_name, nt_errstr(status) ));
884 /* always return NT_STATUS_ACCESS_DENIED */
885 status = NT_STATUS_ACCESS_DENIED;
886 goto out;
889 /* From the client / server challenges and md4 password, generate sess key */
890 /* Check client credentials are valid. */
891 creds = netlogon_creds_server_init(p->mem_ctx,
892 r->in.account_name,
893 r->in.computer_name,
894 r->in.secure_channel_type,
895 &pipe_state->client_challenge,
896 &pipe_state->server_challenge,
897 &mach_pwd,
898 r->in.credentials,
899 r->out.return_credentials,
900 *r->in.negotiate_flags);
901 if (!creds) {
902 DEBUG(0,("%s: netlogon_creds_server_check failed. Rejecting auth "
903 "request from client %s machine account %s\n",
904 fn, r->in.computer_name,
905 r->in.account_name));
906 status = NT_STATUS_ACCESS_DENIED;
907 goto out;
910 creds->sid = sid_dup_talloc(creds, &sid);
911 if (!creds->sid) {
912 status = NT_STATUS_NO_MEMORY;
913 goto out;
916 /* Store off the state so we can continue after client disconnect. */
917 become_root();
918 status = schannel_save_creds_state(p->mem_ctx, lp_private_dir(), creds);
919 unbecome_root();
921 if (!NT_STATUS_IS_OK(status)) {
922 goto out;
925 sid_peek_rid(&sid, r->out.rid);
927 status = NT_STATUS_OK;
929 out:
931 *r->out.negotiate_flags = srv_flgs;
932 return status;
935 /*************************************************************************
936 _netr_ServerAuthenticate2
937 *************************************************************************/
939 NTSTATUS _netr_ServerAuthenticate2(struct pipes_struct *p,
940 struct netr_ServerAuthenticate2 *r)
942 struct netr_ServerAuthenticate3 a;
943 uint32_t rid;
945 a.in.server_name = r->in.server_name;
946 a.in.account_name = r->in.account_name;
947 a.in.secure_channel_type = r->in.secure_channel_type;
948 a.in.computer_name = r->in.computer_name;
949 a.in.credentials = r->in.credentials;
950 a.in.negotiate_flags = r->in.negotiate_flags;
952 a.out.return_credentials = r->out.return_credentials;
953 a.out.rid = &rid;
954 a.out.negotiate_flags = r->out.negotiate_flags;
956 return _netr_ServerAuthenticate3(p, &a);
959 /*************************************************************************
960 * If schannel is required for this call test that it actually is available.
961 *************************************************************************/
962 static NTSTATUS schannel_check_required(struct pipe_auth_data *auth_info,
963 const char *computer_name,
964 bool integrity, bool privacy)
966 if (auth_info && auth_info->auth_type == DCERPC_AUTH_TYPE_SCHANNEL) {
967 if (!privacy && !integrity) {
968 return NT_STATUS_OK;
971 if ((!privacy && integrity) &&
972 auth_info->auth_level == DCERPC_AUTH_LEVEL_INTEGRITY) {
973 return NT_STATUS_OK;
976 if ((privacy || integrity) &&
977 auth_info->auth_level == DCERPC_AUTH_LEVEL_PRIVACY) {
978 return NT_STATUS_OK;
982 /* test didn't pass */
983 DEBUG(0, ("schannel_check_required: [%s] is not using schannel\n",
984 computer_name));
986 return NT_STATUS_ACCESS_DENIED;
989 /*************************************************************************
990 *************************************************************************/
992 static NTSTATUS netr_creds_server_step_check(struct pipes_struct *p,
993 TALLOC_CTX *mem_ctx,
994 const char *computer_name,
995 struct netr_Authenticator *received_authenticator,
996 struct netr_Authenticator *return_authenticator,
997 struct netlogon_creds_CredentialState **creds_out)
999 NTSTATUS status;
1000 bool schannel_global_required = (lp_server_schannel() == true) ? true:false;
1002 if (schannel_global_required) {
1003 status = schannel_check_required(&p->auth,
1004 computer_name,
1005 false, false);
1006 if (!NT_STATUS_IS_OK(status)) {
1007 return status;
1011 status = schannel_check_creds_state(mem_ctx, lp_private_dir(),
1012 computer_name, received_authenticator,
1013 return_authenticator, creds_out);
1015 return status;
1018 /*************************************************************************
1019 *************************************************************************/
1021 static NTSTATUS netr_set_machine_account_password(TALLOC_CTX *mem_ctx,
1022 struct auth_serversupplied_info *server_info,
1023 struct messaging_context *msg_ctx,
1024 const char *account_name,
1025 struct samr_Password *nt_hash)
1027 NTSTATUS status;
1028 struct rpc_pipe_client *cli = NULL;
1029 struct policy_handle user_handle;
1030 uint32_t acct_ctrl;
1031 union samr_UserInfo *info;
1032 struct samr_UserInfo18 info18;
1033 DATA_BLOB in,out;
1035 ZERO_STRUCT(user_handle);
1037 status = rpc_pipe_open_internal(mem_ctx, &ndr_table_samr.syntax_id,
1038 server_info, msg_ctx,
1039 &cli);
1040 if (!NT_STATUS_IS_OK(status)) {
1041 goto out;
1044 status = samr_find_machine_account(mem_ctx, cli, account_name,
1045 SEC_FLAG_MAXIMUM_ALLOWED,
1046 NULL, NULL,
1047 &user_handle);
1048 if (!NT_STATUS_IS_OK(status)) {
1049 goto out;
1052 status = rpccli_samr_QueryUserInfo2(cli, mem_ctx,
1053 &user_handle,
1054 UserControlInformation,
1055 &info);
1056 if (!NT_STATUS_IS_OK(status)) {
1057 goto out;
1060 acct_ctrl = info->info16.acct_flags;
1062 if (!(acct_ctrl & ACB_WSTRUST ||
1063 acct_ctrl & ACB_SVRTRUST ||
1064 acct_ctrl & ACB_DOMTRUST)) {
1065 status = NT_STATUS_NO_SUCH_USER;
1066 goto out;
1069 if (acct_ctrl & ACB_DISABLED) {
1070 status = NT_STATUS_ACCOUNT_DISABLED;
1071 goto out;
1074 ZERO_STRUCT(info18);
1076 in = data_blob_const(nt_hash->hash, 16);
1077 out = data_blob_talloc_zero(mem_ctx, 16);
1078 sess_crypt_blob(&out, &in, &server_info->user_session_key, true);
1079 memcpy(info18.nt_pwd.hash, out.data, out.length);
1081 info18.nt_pwd_active = true;
1083 info->info18 = info18;
1085 status = rpccli_samr_SetUserInfo2(cli, mem_ctx,
1086 &user_handle,
1087 UserInternal1Information,
1088 info);
1089 if (!NT_STATUS_IS_OK(status)) {
1090 goto out;
1093 out:
1094 if (cli && is_valid_policy_hnd(&user_handle)) {
1095 rpccli_samr_Close(cli, mem_ctx, &user_handle);
1098 return status;
1101 /*************************************************************************
1102 _netr_ServerPasswordSet
1103 *************************************************************************/
1105 NTSTATUS _netr_ServerPasswordSet(struct pipes_struct *p,
1106 struct netr_ServerPasswordSet *r)
1108 NTSTATUS status = NT_STATUS_OK;
1109 int i;
1110 struct netlogon_creds_CredentialState *creds;
1112 DEBUG(5,("_netr_ServerPasswordSet: %d\n", __LINE__));
1114 become_root();
1115 status = netr_creds_server_step_check(p, p->mem_ctx,
1116 r->in.computer_name,
1117 r->in.credential,
1118 r->out.return_authenticator,
1119 &creds);
1120 unbecome_root();
1122 if (!NT_STATUS_IS_OK(status)) {
1123 DEBUG(2,("_netr_ServerPasswordSet: netlogon_creds_server_step failed. Rejecting auth "
1124 "request from client %s machine account %s\n",
1125 r->in.computer_name, creds->computer_name));
1126 TALLOC_FREE(creds);
1127 return status;
1130 DEBUG(3,("_netr_ServerPasswordSet: Server Password Set by remote machine:[%s] on account [%s]\n",
1131 r->in.computer_name, creds->computer_name));
1133 netlogon_creds_des_decrypt(creds, r->in.new_password);
1135 DEBUG(100,("_netr_ServerPasswordSet: new given value was :\n"));
1136 for(i = 0; i < sizeof(r->in.new_password->hash); i++)
1137 DEBUG(100,("%02X ", r->in.new_password->hash[i]));
1138 DEBUG(100,("\n"));
1140 status = netr_set_machine_account_password(p->mem_ctx,
1141 p->server_info,
1142 p->msg_ctx,
1143 creds->account_name,
1144 r->in.new_password);
1145 return status;
1148 /****************************************************************
1149 _netr_ServerPasswordSet2
1150 ****************************************************************/
1152 NTSTATUS _netr_ServerPasswordSet2(struct pipes_struct *p,
1153 struct netr_ServerPasswordSet2 *r)
1155 NTSTATUS status;
1156 struct netlogon_creds_CredentialState *creds;
1157 DATA_BLOB plaintext;
1158 struct samr_CryptPassword password_buf;
1159 struct samr_Password nt_hash;
1161 become_root();
1162 status = netr_creds_server_step_check(p, p->mem_ctx,
1163 r->in.computer_name,
1164 r->in.credential,
1165 r->out.return_authenticator,
1166 &creds);
1167 unbecome_root();
1169 if (!NT_STATUS_IS_OK(status)) {
1170 DEBUG(2,("_netr_ServerPasswordSet2: netlogon_creds_server_step "
1171 "failed. Rejecting auth request from client %s machine account %s\n",
1172 r->in.computer_name, creds->computer_name));
1173 TALLOC_FREE(creds);
1174 return status;
1177 memcpy(password_buf.data, r->in.new_password->data, 512);
1178 SIVAL(password_buf.data, 512, r->in.new_password->length);
1179 netlogon_creds_arcfour_crypt(creds, password_buf.data, 516);
1181 if (!extract_pw_from_buffer(p->mem_ctx, password_buf.data, &plaintext)) {
1182 return NT_STATUS_WRONG_PASSWORD;
1185 mdfour(nt_hash.hash, plaintext.data, plaintext.length);
1187 status = netr_set_machine_account_password(p->mem_ctx,
1188 p->server_info,
1189 p->msg_ctx,
1190 creds->account_name,
1191 &nt_hash);
1192 return status;
1195 /*************************************************************************
1196 _netr_LogonSamLogoff
1197 *************************************************************************/
1199 NTSTATUS _netr_LogonSamLogoff(struct pipes_struct *p,
1200 struct netr_LogonSamLogoff *r)
1202 NTSTATUS status;
1203 struct netlogon_creds_CredentialState *creds;
1205 become_root();
1206 status = netr_creds_server_step_check(p, p->mem_ctx,
1207 r->in.computer_name,
1208 r->in.credential,
1209 r->out.return_authenticator,
1210 &creds);
1211 unbecome_root();
1213 return status;
1216 /*************************************************************************
1217 _netr_LogonSamLogon_base
1218 *************************************************************************/
1220 static NTSTATUS _netr_LogonSamLogon_base(struct pipes_struct *p,
1221 struct netr_LogonSamLogonEx *r,
1222 struct netlogon_creds_CredentialState *creds)
1224 NTSTATUS status = NT_STATUS_OK;
1225 union netr_LogonLevel *logon = r->in.logon;
1226 const char *nt_username, *nt_domain, *nt_workstation;
1227 struct auth_usersupplied_info *user_info = NULL;
1228 struct auth_serversupplied_info *server_info = NULL;
1229 struct auth_context *auth_context = NULL;
1230 uint8_t pipe_session_key[16];
1231 bool process_creds = true;
1232 const char *fn;
1234 switch (p->opnum) {
1235 case NDR_NETR_LOGONSAMLOGON:
1236 process_creds = true;
1237 fn = "_netr_LogonSamLogon";
1238 break;
1239 case NDR_NETR_LOGONSAMLOGONWITHFLAGS:
1240 process_creds = true;
1241 fn = "_netr_LogonSamLogonWithFlags";
1242 break;
1243 case NDR_NETR_LOGONSAMLOGONEX:
1244 process_creds = false;
1245 fn = "_netr_LogonSamLogonEx";
1246 break;
1247 default:
1248 return NT_STATUS_INTERNAL_ERROR;
1251 *r->out.authoritative = true; /* authoritative response */
1253 switch (r->in.validation_level) {
1254 case 2:
1255 r->out.validation->sam2 = TALLOC_ZERO_P(p->mem_ctx, struct netr_SamInfo2);
1256 if (!r->out.validation->sam2) {
1257 return NT_STATUS_NO_MEMORY;
1259 break;
1260 case 3:
1261 r->out.validation->sam3 = TALLOC_ZERO_P(p->mem_ctx, struct netr_SamInfo3);
1262 if (!r->out.validation->sam3) {
1263 return NT_STATUS_NO_MEMORY;
1265 break;
1266 case 6:
1267 r->out.validation->sam6 = TALLOC_ZERO_P(p->mem_ctx, struct netr_SamInfo6);
1268 if (!r->out.validation->sam6) {
1269 return NT_STATUS_NO_MEMORY;
1271 break;
1272 default:
1273 DEBUG(0,("%s: bad validation_level value %d.\n",
1274 fn, (int)r->in.validation_level));
1275 return NT_STATUS_INVALID_INFO_CLASS;
1278 switch (r->in.logon_level) {
1279 case NetlogonInteractiveInformation:
1280 case NetlogonServiceInformation:
1281 case NetlogonInteractiveTransitiveInformation:
1282 case NetlogonServiceTransitiveInformation:
1283 nt_username = logon->password->identity_info.account_name.string ?
1284 logon->password->identity_info.account_name.string : "";
1285 nt_domain = logon->password->identity_info.domain_name.string ?
1286 logon->password->identity_info.domain_name.string : "";
1287 nt_workstation = logon->password->identity_info.workstation.string ?
1288 logon->password->identity_info.workstation.string : "";
1290 DEBUG(3,("SAM Logon (Interactive). Domain:[%s]. ", lp_workgroup()));
1291 break;
1292 case NetlogonNetworkInformation:
1293 case NetlogonNetworkTransitiveInformation:
1294 nt_username = logon->network->identity_info.account_name.string ?
1295 logon->network->identity_info.account_name.string : "";
1296 nt_domain = logon->network->identity_info.domain_name.string ?
1297 logon->network->identity_info.domain_name.string : "";
1298 nt_workstation = logon->network->identity_info.workstation.string ?
1299 logon->network->identity_info.workstation.string : "";
1301 DEBUG(3,("SAM Logon (Network). Domain:[%s]. ", lp_workgroup()));
1302 break;
1303 default:
1304 DEBUG(2,("SAM Logon: unsupported switch value\n"));
1305 return NT_STATUS_INVALID_INFO_CLASS;
1306 } /* end switch */
1308 DEBUG(3,("User:[%s@%s] Requested Domain:[%s]\n", nt_username, nt_workstation, nt_domain));
1309 fstrcpy(current_user_info.smb_name, nt_username);
1310 sub_set_smb_name(nt_username);
1312 DEBUG(5,("Attempting validation level %d for unmapped username %s.\n",
1313 r->in.validation_level, nt_username));
1315 status = NT_STATUS_OK;
1317 switch (r->in.logon_level) {
1318 case NetlogonNetworkInformation:
1319 case NetlogonNetworkTransitiveInformation:
1321 const char *wksname = nt_workstation;
1323 status = make_auth_context_fixed(&auth_context,
1324 logon->network->challenge);
1325 if (!NT_STATUS_IS_OK(status)) {
1326 return status;
1329 /* For a network logon, the workstation name comes in with two
1330 * backslashes in the front. Strip them if they are there. */
1332 if (*wksname == '\\') wksname++;
1333 if (*wksname == '\\') wksname++;
1335 /* Standard challenge/response authenticaion */
1336 if (!make_user_info_netlogon_network(&user_info,
1337 nt_username, nt_domain,
1338 wksname,
1339 logon->network->identity_info.parameter_control,
1340 logon->network->lm.data,
1341 logon->network->lm.length,
1342 logon->network->nt.data,
1343 logon->network->nt.length)) {
1344 status = NT_STATUS_NO_MEMORY;
1346 break;
1348 case NetlogonInteractiveInformation:
1349 case NetlogonServiceInformation:
1350 case NetlogonInteractiveTransitiveInformation:
1351 case NetlogonServiceTransitiveInformation:
1353 /* 'Interactive' authentication, supplies the password in its
1354 MD4 form, encrypted with the session key. We will convert
1355 this to challenge/response for the auth subsystem to chew
1356 on */
1358 uint8_t chal[8];
1360 if (!NT_STATUS_IS_OK(status = make_auth_context_subsystem(&auth_context))) {
1361 return status;
1364 auth_context->get_ntlm_challenge(auth_context, chal);
1366 if (!make_user_info_netlogon_interactive(&user_info,
1367 nt_username, nt_domain,
1368 nt_workstation,
1369 logon->password->identity_info.parameter_control,
1370 chal,
1371 logon->password->lmpassword.hash,
1372 logon->password->ntpassword.hash,
1373 creds->session_key)) {
1374 status = NT_STATUS_NO_MEMORY;
1376 break;
1378 default:
1379 DEBUG(2,("SAM Logon: unsupported switch value\n"));
1380 return NT_STATUS_INVALID_INFO_CLASS;
1381 } /* end switch */
1383 if ( NT_STATUS_IS_OK(status) ) {
1384 status = auth_context->check_ntlm_password(auth_context,
1385 user_info, &server_info);
1388 TALLOC_FREE(auth_context);
1389 free_user_info(&user_info);
1391 DEBUG(5,("%s: check_password returned status %s\n",
1392 fn, nt_errstr(status)));
1394 /* Check account and password */
1396 if (!NT_STATUS_IS_OK(status)) {
1397 /* If we don't know what this domain is, we need to
1398 indicate that we are not authoritative. This
1399 allows the client to decide if it needs to try
1400 a local user. Fix by jpjanosi@us.ibm.com, #2976 */
1401 if ( NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_USER)
1402 && !strequal(nt_domain, get_global_sam_name())
1403 && !is_trusted_domain(nt_domain) )
1404 *r->out.authoritative = false; /* We are not authoritative */
1406 TALLOC_FREE(server_info);
1407 return status;
1410 if (server_info->guest) {
1411 /* We don't like guest domain logons... */
1412 DEBUG(5,("%s: Attempted domain logon as GUEST "
1413 "denied.\n", fn));
1414 TALLOC_FREE(server_info);
1415 return NT_STATUS_LOGON_FAILURE;
1418 /* This is the point at which, if the login was successful, that
1419 the SAM Local Security Authority should record that the user is
1420 logged in to the domain. */
1422 if (process_creds) {
1423 /* Get the pipe session key from the creds. */
1424 memcpy(pipe_session_key, creds->session_key, 16);
1425 } else {
1426 /* Get the pipe session key from the schannel. */
1427 if ((p->auth.auth_type != DCERPC_AUTH_TYPE_SCHANNEL)
1428 || (p->auth.a_u.schannel_auth == NULL)) {
1429 return NT_STATUS_INVALID_HANDLE;
1431 memcpy(pipe_session_key, p->auth.a_u.schannel_auth->creds->session_key, 16);
1434 switch (r->in.validation_level) {
1435 case 2:
1436 status = serverinfo_to_SamInfo2(server_info, pipe_session_key, 16,
1437 r->out.validation->sam2);
1438 break;
1439 case 3:
1440 status = serverinfo_to_SamInfo3(server_info, pipe_session_key, 16,
1441 r->out.validation->sam3);
1442 break;
1443 case 6:
1444 status = serverinfo_to_SamInfo6(server_info, pipe_session_key, 16,
1445 r->out.validation->sam6);
1446 break;
1449 TALLOC_FREE(server_info);
1451 return status;
1454 /****************************************************************
1455 _netr_LogonSamLogonWithFlags
1456 ****************************************************************/
1458 NTSTATUS _netr_LogonSamLogonWithFlags(struct pipes_struct *p,
1459 struct netr_LogonSamLogonWithFlags *r)
1461 NTSTATUS status;
1462 struct netlogon_creds_CredentialState *creds;
1463 struct netr_LogonSamLogonEx r2;
1464 struct netr_Authenticator return_authenticator;
1466 become_root();
1467 status = netr_creds_server_step_check(p, p->mem_ctx,
1468 r->in.computer_name,
1469 r->in.credential,
1470 &return_authenticator,
1471 &creds);
1472 unbecome_root();
1473 if (!NT_STATUS_IS_OK(status)) {
1474 return status;
1477 r2.in.server_name = r->in.server_name;
1478 r2.in.computer_name = r->in.computer_name;
1479 r2.in.logon_level = r->in.logon_level;
1480 r2.in.logon = r->in.logon;
1481 r2.in.validation_level = r->in.validation_level;
1482 r2.in.flags = r->in.flags;
1483 r2.out.validation = r->out.validation;
1484 r2.out.authoritative = r->out.authoritative;
1485 r2.out.flags = r->out.flags;
1487 status = _netr_LogonSamLogon_base(p, &r2, creds);
1489 *r->out.return_authenticator = return_authenticator;
1491 return status;
1494 /*************************************************************************
1495 _netr_LogonSamLogon
1496 *************************************************************************/
1498 NTSTATUS _netr_LogonSamLogon(struct pipes_struct *p,
1499 struct netr_LogonSamLogon *r)
1501 NTSTATUS status;
1502 struct netr_LogonSamLogonWithFlags r2;
1503 uint32_t flags = 0;
1505 r2.in.server_name = r->in.server_name;
1506 r2.in.computer_name = r->in.computer_name;
1507 r2.in.credential = r->in.credential;
1508 r2.in.logon_level = r->in.logon_level;
1509 r2.in.logon = r->in.logon;
1510 r2.in.validation_level = r->in.validation_level;
1511 r2.in.return_authenticator = r->in.return_authenticator;
1512 r2.in.flags = &flags;
1513 r2.out.validation = r->out.validation;
1514 r2.out.authoritative = r->out.authoritative;
1515 r2.out.flags = &flags;
1516 r2.out.return_authenticator = r->out.return_authenticator;
1518 status = _netr_LogonSamLogonWithFlags(p, &r2);
1520 return status;
1523 /*************************************************************************
1524 _netr_LogonSamLogonEx
1525 - no credential chaining. Map into net sam logon.
1526 *************************************************************************/
1528 NTSTATUS _netr_LogonSamLogonEx(struct pipes_struct *p,
1529 struct netr_LogonSamLogonEx *r)
1531 NTSTATUS status;
1532 struct netlogon_creds_CredentialState *creds = NULL;
1534 become_root();
1535 status = schannel_get_creds_state(p->mem_ctx, lp_private_dir(),
1536 r->in.computer_name, &creds);
1537 unbecome_root();
1538 if (!NT_STATUS_IS_OK(status)) {
1539 return status;
1542 /* Only allow this if the pipe is protected. */
1543 if (p->auth.auth_type != DCERPC_AUTH_TYPE_SCHANNEL) {
1544 DEBUG(0,("_netr_LogonSamLogonEx: client %s not using schannel for netlogon\n",
1545 get_remote_machine_name() ));
1546 return NT_STATUS_INVALID_PARAMETER;
1549 status = _netr_LogonSamLogon_base(p, r, creds);
1550 TALLOC_FREE(creds);
1552 return status;
1555 /*************************************************************************
1556 _ds_enum_dom_trusts
1557 *************************************************************************/
1558 #if 0 /* JERRY -- not correct */
1559 NTSTATUS _ds_enum_dom_trusts(struct pipes_struct *p, DS_Q_ENUM_DOM_TRUSTS *q_u,
1560 DS_R_ENUM_DOM_TRUSTS *r_u)
1562 NTSTATUS status = NT_STATUS_OK;
1564 /* TODO: According to MSDN, the can only be executed against a
1565 DC or domain member running Windows 2000 or later. Need
1566 to test against a standalone 2k server and see what it
1567 does. A windows 2000 DC includes its own domain in the
1568 list. --jerry */
1570 return status;
1572 #endif /* JERRY */
1575 /****************************************************************
1576 ****************************************************************/
1578 WERROR _netr_LogonUasLogon(struct pipes_struct *p,
1579 struct netr_LogonUasLogon *r)
1581 p->rng_fault_state = true;
1582 return WERR_NOT_SUPPORTED;
1585 /****************************************************************
1586 ****************************************************************/
1588 WERROR _netr_LogonUasLogoff(struct pipes_struct *p,
1589 struct netr_LogonUasLogoff *r)
1591 p->rng_fault_state = true;
1592 return WERR_NOT_SUPPORTED;
1595 /****************************************************************
1596 ****************************************************************/
1598 NTSTATUS _netr_DatabaseDeltas(struct pipes_struct *p,
1599 struct netr_DatabaseDeltas *r)
1601 p->rng_fault_state = true;
1602 return NT_STATUS_NOT_IMPLEMENTED;
1605 /****************************************************************
1606 ****************************************************************/
1608 NTSTATUS _netr_DatabaseSync(struct pipes_struct *p,
1609 struct netr_DatabaseSync *r)
1611 p->rng_fault_state = true;
1612 return NT_STATUS_NOT_IMPLEMENTED;
1615 /****************************************************************
1616 ****************************************************************/
1618 NTSTATUS _netr_AccountDeltas(struct pipes_struct *p,
1619 struct netr_AccountDeltas *r)
1621 p->rng_fault_state = true;
1622 return NT_STATUS_NOT_IMPLEMENTED;
1625 /****************************************************************
1626 ****************************************************************/
1628 NTSTATUS _netr_AccountSync(struct pipes_struct *p,
1629 struct netr_AccountSync *r)
1631 p->rng_fault_state = true;
1632 return NT_STATUS_NOT_IMPLEMENTED;
1635 /****************************************************************
1636 ****************************************************************/
1638 static bool wb_getdcname(TALLOC_CTX *mem_ctx,
1639 const char *domain,
1640 const char **dcname,
1641 uint32_t flags,
1642 WERROR *werr)
1644 wbcErr result;
1645 struct wbcDomainControllerInfo *dc_info = NULL;
1647 result = wbcLookupDomainController(domain,
1648 flags,
1649 &dc_info);
1650 switch (result) {
1651 case WBC_ERR_SUCCESS:
1652 break;
1653 case WBC_ERR_WINBIND_NOT_AVAILABLE:
1654 return false;
1655 case WBC_ERR_DOMAIN_NOT_FOUND:
1656 *werr = WERR_NO_SUCH_DOMAIN;
1657 return true;
1658 default:
1659 *werr = WERR_DOMAIN_CONTROLLER_NOT_FOUND;
1660 return true;
1663 *dcname = talloc_strdup(mem_ctx, dc_info->dc_name);
1664 wbcFreeMemory(dc_info);
1665 if (!*dcname) {
1666 *werr = WERR_NOMEM;
1667 return false;
1670 *werr = WERR_OK;
1672 return true;
1675 /****************************************************************
1676 _netr_GetDcName
1677 ****************************************************************/
1679 WERROR _netr_GetDcName(struct pipes_struct *p,
1680 struct netr_GetDcName *r)
1682 NTSTATUS status;
1683 WERROR werr;
1684 uint32_t flags;
1685 struct netr_DsRGetDCNameInfo *info;
1686 bool ret;
1688 ret = wb_getdcname(p->mem_ctx,
1689 r->in.domainname,
1690 r->out.dcname,
1691 WBC_LOOKUP_DC_IS_FLAT_NAME |
1692 WBC_LOOKUP_DC_RETURN_FLAT_NAME |
1693 WBC_LOOKUP_DC_PDC_REQUIRED,
1694 &werr);
1695 if (ret == true) {
1696 return werr;
1699 flags = DS_PDC_REQUIRED | DS_IS_FLAT_NAME | DS_RETURN_FLAT_NAME;
1701 status = dsgetdcname(p->mem_ctx,
1702 p->msg_ctx,
1703 r->in.domainname,
1704 NULL,
1705 NULL,
1706 flags,
1707 &info);
1708 if (!NT_STATUS_IS_OK(status)) {
1709 return ntstatus_to_werror(status);
1712 *r->out.dcname = talloc_strdup(p->mem_ctx, info->dc_unc);
1713 talloc_free(info);
1714 if (!*r->out.dcname) {
1715 return WERR_NOMEM;
1718 return WERR_OK;
1721 /****************************************************************
1722 _netr_GetAnyDCName
1723 ****************************************************************/
1725 WERROR _netr_GetAnyDCName(struct pipes_struct *p,
1726 struct netr_GetAnyDCName *r)
1728 NTSTATUS status;
1729 WERROR werr;
1730 uint32_t flags;
1731 struct netr_DsRGetDCNameInfo *info;
1732 bool ret;
1734 ret = wb_getdcname(p->mem_ctx,
1735 r->in.domainname,
1736 r->out.dcname,
1737 WBC_LOOKUP_DC_IS_FLAT_NAME |
1738 WBC_LOOKUP_DC_RETURN_FLAT_NAME,
1739 &werr);
1740 if (ret == true) {
1741 return werr;
1744 flags = DS_IS_FLAT_NAME | DS_RETURN_FLAT_NAME;
1746 status = dsgetdcname(p->mem_ctx,
1747 p->msg_ctx,
1748 r->in.domainname,
1749 NULL,
1750 NULL,
1751 flags,
1752 &info);
1753 if (!NT_STATUS_IS_OK(status)) {
1754 return ntstatus_to_werror(status);
1757 *r->out.dcname = talloc_strdup(p->mem_ctx, info->dc_unc);
1758 talloc_free(info);
1759 if (!*r->out.dcname) {
1760 return WERR_NOMEM;
1763 return WERR_OK;
1766 /****************************************************************
1767 ****************************************************************/
1769 NTSTATUS _netr_DatabaseSync2(struct pipes_struct *p,
1770 struct netr_DatabaseSync2 *r)
1772 p->rng_fault_state = true;
1773 return NT_STATUS_NOT_IMPLEMENTED;
1776 /****************************************************************
1777 ****************************************************************/
1779 NTSTATUS _netr_DatabaseRedo(struct pipes_struct *p,
1780 struct netr_DatabaseRedo *r)
1782 p->rng_fault_state = true;
1783 return NT_STATUS_NOT_IMPLEMENTED;
1786 /****************************************************************
1787 ****************************************************************/
1789 WERROR _netr_DsRGetDCName(struct pipes_struct *p,
1790 struct netr_DsRGetDCName *r)
1792 p->rng_fault_state = true;
1793 return WERR_NOT_SUPPORTED;
1796 /****************************************************************
1797 ****************************************************************/
1799 NTSTATUS _netr_LogonGetCapabilities(struct pipes_struct *p,
1800 struct netr_LogonGetCapabilities *r)
1802 return NT_STATUS_NOT_IMPLEMENTED;
1805 /****************************************************************
1806 ****************************************************************/
1808 WERROR _netr_NETRLOGONSETSERVICEBITS(struct pipes_struct *p,
1809 struct netr_NETRLOGONSETSERVICEBITS *r)
1811 p->rng_fault_state = true;
1812 return WERR_NOT_SUPPORTED;
1815 /****************************************************************
1816 ****************************************************************/
1818 WERROR _netr_LogonGetTrustRid(struct pipes_struct *p,
1819 struct netr_LogonGetTrustRid *r)
1821 p->rng_fault_state = true;
1822 return WERR_NOT_SUPPORTED;
1825 /****************************************************************
1826 ****************************************************************/
1828 WERROR _netr_NETRLOGONCOMPUTESERVERDIGEST(struct pipes_struct *p,
1829 struct netr_NETRLOGONCOMPUTESERVERDIGEST *r)
1831 p->rng_fault_state = true;
1832 return WERR_NOT_SUPPORTED;
1835 /****************************************************************
1836 ****************************************************************/
1838 WERROR _netr_NETRLOGONCOMPUTECLIENTDIGEST(struct pipes_struct *p,
1839 struct netr_NETRLOGONCOMPUTECLIENTDIGEST *r)
1841 p->rng_fault_state = true;
1842 return WERR_NOT_SUPPORTED;
1845 /****************************************************************
1846 ****************************************************************/
1848 WERROR _netr_DsRGetDCNameEx(struct pipes_struct *p,
1849 struct netr_DsRGetDCNameEx *r)
1851 p->rng_fault_state = true;
1852 return WERR_NOT_SUPPORTED;
1855 /****************************************************************
1856 ****************************************************************/
1858 WERROR _netr_DsRGetSiteName(struct pipes_struct *p,
1859 struct netr_DsRGetSiteName *r)
1861 p->rng_fault_state = true;
1862 return WERR_NOT_SUPPORTED;
1865 /****************************************************************
1866 ****************************************************************/
1868 NTSTATUS _netr_LogonGetDomainInfo(struct pipes_struct *p,
1869 struct netr_LogonGetDomainInfo *r)
1871 p->rng_fault_state = true;
1872 return NT_STATUS_NOT_IMPLEMENTED;
1875 /****************************************************************
1876 ****************************************************************/
1878 WERROR _netr_ServerPasswordGet(struct pipes_struct *p,
1879 struct netr_ServerPasswordGet *r)
1881 p->rng_fault_state = true;
1882 return WERR_NOT_SUPPORTED;
1885 /****************************************************************
1886 ****************************************************************/
1888 WERROR _netr_NETRLOGONSENDTOSAM(struct pipes_struct *p,
1889 struct netr_NETRLOGONSENDTOSAM *r)
1891 p->rng_fault_state = true;
1892 return WERR_NOT_SUPPORTED;
1895 /****************************************************************
1896 ****************************************************************/
1898 WERROR _netr_DsRAddressToSitenamesW(struct pipes_struct *p,
1899 struct netr_DsRAddressToSitenamesW *r)
1901 p->rng_fault_state = true;
1902 return WERR_NOT_SUPPORTED;
1905 /****************************************************************
1906 ****************************************************************/
1908 WERROR _netr_DsRGetDCNameEx2(struct pipes_struct *p,
1909 struct netr_DsRGetDCNameEx2 *r)
1911 p->rng_fault_state = true;
1912 return WERR_NOT_SUPPORTED;
1915 /****************************************************************
1916 ****************************************************************/
1918 WERROR _netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN(struct pipes_struct *p,
1919 struct netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN *r)
1921 p->rng_fault_state = true;
1922 return WERR_NOT_SUPPORTED;
1925 /****************************************************************
1926 ****************************************************************/
1928 WERROR _netr_NetrEnumerateTrustedDomainsEx(struct pipes_struct *p,
1929 struct netr_NetrEnumerateTrustedDomainsEx *r)
1931 p->rng_fault_state = true;
1932 return WERR_NOT_SUPPORTED;
1935 /****************************************************************
1936 ****************************************************************/
1938 WERROR _netr_DsRAddressToSitenamesExW(struct pipes_struct *p,
1939 struct netr_DsRAddressToSitenamesExW *r)
1941 p->rng_fault_state = true;
1942 return WERR_NOT_SUPPORTED;
1945 /****************************************************************
1946 ****************************************************************/
1948 WERROR _netr_DsrGetDcSiteCoverageW(struct pipes_struct *p,
1949 struct netr_DsrGetDcSiteCoverageW *r)
1951 p->rng_fault_state = true;
1952 return WERR_NOT_SUPPORTED;
1955 /****************************************************************
1956 ****************************************************************/
1958 WERROR _netr_DsrEnumerateDomainTrusts(struct pipes_struct *p,
1959 struct netr_DsrEnumerateDomainTrusts *r)
1961 p->rng_fault_state = true;
1962 return WERR_NOT_SUPPORTED;
1965 /****************************************************************
1966 ****************************************************************/
1968 WERROR _netr_DsrDeregisterDNSHostRecords(struct pipes_struct *p,
1969 struct netr_DsrDeregisterDNSHostRecords *r)
1971 p->rng_fault_state = true;
1972 return WERR_NOT_SUPPORTED;
1975 /****************************************************************
1976 ****************************************************************/
1978 NTSTATUS _netr_ServerTrustPasswordsGet(struct pipes_struct *p,
1979 struct netr_ServerTrustPasswordsGet *r)
1981 p->rng_fault_state = true;
1982 return NT_STATUS_NOT_IMPLEMENTED;
1985 /****************************************************************
1986 ****************************************************************/
1988 WERROR _netr_DsRGetForestTrustInformation(struct pipes_struct *p,
1989 struct netr_DsRGetForestTrustInformation *r)
1991 p->rng_fault_state = true;
1992 return WERR_NOT_SUPPORTED;
1995 /****************************************************************
1996 ****************************************************************/
1998 NTSTATUS _netr_GetForestTrustInformation(struct pipes_struct *p,
1999 struct netr_GetForestTrustInformation *r)
2001 p->rng_fault_state = true;
2002 return NT_STATUS_NOT_IMPLEMENTED;
2005 /****************************************************************
2006 ****************************************************************/
2008 NTSTATUS _netr_ServerGetTrustInfo(struct pipes_struct *p,
2009 struct netr_ServerGetTrustInfo *r)
2011 p->rng_fault_state = true;
2012 return NT_STATUS_NOT_IMPLEMENTED;