s3-netlogon: Move to new dcerpc client funtions.
[metze/samba/wip.git] / source3 / rpc_server / srv_netlog_nt.c
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.
10  *
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.
15  *
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.
20  *
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/>.
23  */
24
25 /* This is the implementation of the netlogon pipe. */
26
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"
37 #include "rpc_client/init_lsa.h"
38 #include "rpc_server/rpc_ncacn_np.h"
39 #include "../libcli/security/security.h"
40
41 extern userdom_struct current_user_info;
42
43 #undef DBGC_CLASS
44 #define DBGC_CLASS DBGC_RPC_SRV
45
46 struct netlogon_server_pipe_state {
47         struct netr_Credential client_challenge;
48         struct netr_Credential server_challenge;
49 };
50
51 /*************************************************************************
52  _netr_LogonControl
53  *************************************************************************/
54
55 WERROR _netr_LogonControl(struct pipes_struct *p,
56                           struct netr_LogonControl *r)
57 {
58         struct netr_LogonControl2Ex l;
59
60         switch (r->in.level) {
61         case 1:
62                 break;
63         case 2:
64                 return WERR_NOT_SUPPORTED;
65         default:
66                 return WERR_UNKNOWN_LEVEL;
67         }
68
69         l.in.logon_server       = r->in.logon_server;
70         l.in.function_code      = r->in.function_code;
71         l.in.level              = r->in.level;
72         l.in.data               = NULL;
73         l.out.query             = r->out.query;
74
75         return _netr_LogonControl2Ex(p, &l);
76 }
77
78 /****************************************************************************
79 Send a message to smbd to do a sam synchronisation
80 **************************************************************************/
81
82 static void send_sync_message(struct messaging_context *msg_ctx)
83 {
84         DEBUG(3, ("sending sam synchronisation message\n"));
85         message_send_all(msg_ctx, MSG_SMB_SAM_SYNC, NULL, 0, NULL);
86 }
87
88 /*************************************************************************
89  _netr_LogonControl2
90  *************************************************************************/
91
92 WERROR _netr_LogonControl2(struct pipes_struct *p,
93                            struct netr_LogonControl2 *r)
94 {
95         struct netr_LogonControl2Ex l;
96
97         l.in.logon_server       = r->in.logon_server;
98         l.in.function_code      = r->in.function_code;
99         l.in.level              = r->in.level;
100         l.in.data               = r->in.data;
101         l.out.query             = r->out.query;
102
103         return _netr_LogonControl2Ex(p, &l);
104 }
105
106 /*************************************************************************
107  *************************************************************************/
108
109 static bool wb_change_trust_creds(const char *domain, WERROR *tc_status)
110 {
111         wbcErr result;
112         struct wbcAuthErrorInfo *error = NULL;
113
114         result = wbcChangeTrustCredentials(domain, &error);
115         switch (result) {
116         case WBC_ERR_WINBIND_NOT_AVAILABLE:
117                 return false;
118         case WBC_ERR_DOMAIN_NOT_FOUND:
119                 *tc_status = WERR_NO_SUCH_DOMAIN;
120                 return true;
121         case WBC_ERR_SUCCESS:
122                 *tc_status = WERR_OK;
123                 return true;
124         default:
125                 break;
126         }
127
128         if (error && error->nt_status != 0) {
129                 *tc_status = ntstatus_to_werror(NT_STATUS(error->nt_status));
130         } else {
131                 *tc_status = WERR_TRUST_FAILURE;
132         }
133         wbcFreeMemory(error);
134         return true;
135 }
136
137 /*************************************************************************
138  *************************************************************************/
139
140 static bool wb_check_trust_creds(const char *domain, WERROR *tc_status)
141 {
142         wbcErr result;
143         struct wbcAuthErrorInfo *error = NULL;
144
145         result = wbcCheckTrustCredentials(domain, &error);
146         switch (result) {
147         case WBC_ERR_WINBIND_NOT_AVAILABLE:
148                 return false;
149         case WBC_ERR_DOMAIN_NOT_FOUND:
150                 *tc_status = WERR_NO_SUCH_DOMAIN;
151                 return true;
152         case WBC_ERR_SUCCESS:
153                 *tc_status = WERR_OK;
154                 return true;
155         default:
156                 break;
157         }
158
159         if (error && error->nt_status != 0) {
160                 *tc_status = ntstatus_to_werror(NT_STATUS(error->nt_status));
161         } else {
162                 *tc_status = WERR_TRUST_FAILURE;
163         }
164         wbcFreeMemory(error);
165         return true;
166 }
167
168 /****************************************************************
169  _netr_LogonControl2Ex
170 ****************************************************************/
171
172 WERROR _netr_LogonControl2Ex(struct pipes_struct *p,
173                              struct netr_LogonControl2Ex *r)
174 {
175         uint32_t flags = 0x0;
176         WERROR pdc_connection_status = WERR_OK;
177         uint32_t logon_attempts = 0x0;
178         WERROR tc_status;
179         fstring dc_name2;
180         const char *dc_name = NULL;
181         struct sockaddr_storage dc_ss;
182         const char *domain = NULL;
183         struct netr_NETLOGON_INFO_1 *info1;
184         struct netr_NETLOGON_INFO_2 *info2;
185         struct netr_NETLOGON_INFO_3 *info3;
186         struct netr_NETLOGON_INFO_4 *info4;
187         const char *fn;
188         uint32_t acct_ctrl;
189
190         switch (p->opnum) {
191         case NDR_NETR_LOGONCONTROL:
192                 fn = "_netr_LogonControl";
193                 break;
194         case NDR_NETR_LOGONCONTROL2:
195                 fn = "_netr_LogonControl2";
196                 break;
197         case NDR_NETR_LOGONCONTROL2EX:
198                 fn = "_netr_LogonControl2Ex";
199                 break;
200         default:
201                 return WERR_INVALID_PARAM;
202         }
203
204         acct_ctrl = p->server_info->info3->base.acct_flags;
205
206         switch (r->in.function_code) {
207         case NETLOGON_CONTROL_TC_VERIFY:
208         case NETLOGON_CONTROL_CHANGE_PASSWORD:
209         case NETLOGON_CONTROL_REDISCOVER:
210                 if ((geteuid() != sec_initial_uid()) &&
211                     !nt_token_check_domain_rid(p->server_info->ptok, DOMAIN_RID_ADMINS) &&
212                     !nt_token_check_sid(&global_sid_Builtin_Administrators, p->server_info->ptok) &&
213                     !(acct_ctrl & (ACB_WSTRUST | ACB_SVRTRUST))) {
214                         return WERR_ACCESS_DENIED;
215                 }
216                 break;
217         default:
218                 break;
219         }
220
221         tc_status = WERR_NO_SUCH_DOMAIN;
222
223         switch (r->in.function_code) {
224         case NETLOGON_CONTROL_QUERY:
225                 tc_status = WERR_OK;
226                 break;
227         case NETLOGON_CONTROL_REPLICATE:
228         case NETLOGON_CONTROL_SYNCHRONIZE:
229         case NETLOGON_CONTROL_PDC_REPLICATE:
230         case NETLOGON_CONTROL_BACKUP_CHANGE_LOG:
231         case NETLOGON_CONTROL_BREAKPOINT:
232                 if (acct_ctrl & ACB_NORMAL) {
233                         return WERR_NOT_SUPPORTED;
234                 } else if (acct_ctrl & (ACB_WSTRUST | ACB_SVRTRUST)) {
235                         return WERR_ACCESS_DENIED;
236                 } else {
237                         return WERR_ACCESS_DENIED;
238                 }
239         case NETLOGON_CONTROL_TRUNCATE_LOG:
240                 if (acct_ctrl & ACB_NORMAL) {
241                         break;
242                 } else if (acct_ctrl & (ACB_WSTRUST | ACB_SVRTRUST)) {
243                         return WERR_ACCESS_DENIED;
244                 } else {
245                         return WERR_ACCESS_DENIED;
246                 }
247
248         case NETLOGON_CONTROL_TRANSPORT_NOTIFY:
249         case NETLOGON_CONTROL_FORCE_DNS_REG:
250         case NETLOGON_CONTROL_QUERY_DNS_REG:
251                 return WERR_NOT_SUPPORTED;
252         case NETLOGON_CONTROL_FIND_USER:
253                 if (!r->in.data || !r->in.data->user) {
254                         return WERR_NOT_SUPPORTED;
255                 }
256                 break;
257         case NETLOGON_CONTROL_SET_DBFLAG:
258                 if (!r->in.data) {
259                         return WERR_NOT_SUPPORTED;
260                 }
261                 break;
262         case NETLOGON_CONTROL_TC_VERIFY:
263                 if (!r->in.data || !r->in.data->domain) {
264                         return WERR_NOT_SUPPORTED;
265                 }
266
267                 if (!wb_check_trust_creds(r->in.data->domain, &tc_status)) {
268                         return WERR_NOT_SUPPORTED;
269                 }
270                 break;
271         case NETLOGON_CONTROL_TC_QUERY:
272                 if (!r->in.data || !r->in.data->domain) {
273                         return WERR_NOT_SUPPORTED;
274                 }
275
276                 domain = r->in.data->domain;
277
278                 if (!is_trusted_domain(domain)) {
279                         break;
280                 }
281
282                 if (!get_dc_name(domain, NULL, dc_name2, &dc_ss)) {
283                         tc_status = WERR_NO_LOGON_SERVERS;
284                         break;
285                 }
286
287                 dc_name = talloc_asprintf(p->mem_ctx, "\\\\%s", dc_name2);
288                 if (!dc_name) {
289                         return WERR_NOMEM;
290                 }
291
292                 tc_status = WERR_OK;
293
294                 break;
295
296         case NETLOGON_CONTROL_REDISCOVER:
297                 if (!r->in.data || !r->in.data->domain) {
298                         return WERR_NOT_SUPPORTED;
299                 }
300
301                 domain = r->in.data->domain;
302
303                 if (!is_trusted_domain(domain)) {
304                         break;
305                 }
306
307                 if (!get_dc_name(domain, NULL, dc_name2, &dc_ss)) {
308                         tc_status = WERR_NO_LOGON_SERVERS;
309                         break;
310                 }
311
312                 dc_name = talloc_asprintf(p->mem_ctx, "\\\\%s", dc_name2);
313                 if (!dc_name) {
314                         return WERR_NOMEM;
315                 }
316
317                 tc_status = WERR_OK;
318
319                 break;
320
321         case NETLOGON_CONTROL_CHANGE_PASSWORD:
322                 if (!r->in.data || !r->in.data->domain) {
323                         return WERR_NOT_SUPPORTED;
324                 }
325
326                 if (!wb_change_trust_creds(r->in.data->domain, &tc_status)) {
327                         return WERR_NOT_SUPPORTED;
328                 }
329                 break;
330
331         default:
332                 /* no idea what this should be */
333                 DEBUG(0,("%s: unimplemented function level [%d]\n",
334                         fn, r->in.function_code));
335                 return WERR_UNKNOWN_LEVEL;
336         }
337
338         /* prepare the response */
339
340         switch (r->in.level) {
341         case 1:
342                 info1 = TALLOC_ZERO_P(p->mem_ctx, struct netr_NETLOGON_INFO_1);
343                 W_ERROR_HAVE_NO_MEMORY(info1);
344
345                 info1->flags                    = flags;
346                 info1->pdc_connection_status    = pdc_connection_status;
347
348                 r->out.query->info1 = info1;
349                 break;
350         case 2:
351                 info2 = TALLOC_ZERO_P(p->mem_ctx, struct netr_NETLOGON_INFO_2);
352                 W_ERROR_HAVE_NO_MEMORY(info2);
353
354                 info2->flags                    = flags;
355                 info2->pdc_connection_status    = pdc_connection_status;
356                 info2->trusted_dc_name          = dc_name;
357                 info2->tc_connection_status     = tc_status;
358
359                 r->out.query->info2 = info2;
360                 break;
361         case 3:
362                 info3 = TALLOC_ZERO_P(p->mem_ctx, struct netr_NETLOGON_INFO_3);
363                 W_ERROR_HAVE_NO_MEMORY(info3);
364
365                 info3->flags                    = flags;
366                 info3->logon_attempts           = logon_attempts;
367
368                 r->out.query->info3 = info3;
369                 break;
370         case 4:
371                 info4 = TALLOC_ZERO_P(p->mem_ctx, struct netr_NETLOGON_INFO_4);
372                 W_ERROR_HAVE_NO_MEMORY(info4);
373
374                 info4->trusted_dc_name          = dc_name;
375                 info4->trusted_domain_name      = r->in.data->domain;
376
377                 r->out.query->info4 = info4;
378                 break;
379         default:
380                 return WERR_UNKNOWN_LEVEL;
381         }
382
383         if (lp_server_role() == ROLE_DOMAIN_BDC) {
384                 send_sync_message(p->msg_ctx);
385         }
386
387         return WERR_OK;
388 }
389
390 /*************************************************************************
391  _netr_NetrEnumerateTrustedDomains
392  *************************************************************************/
393
394 NTSTATUS _netr_NetrEnumerateTrustedDomains(struct pipes_struct *p,
395                                            struct netr_NetrEnumerateTrustedDomains *r)
396 {
397         NTSTATUS status;
398         NTSTATUS result = NT_STATUS_OK;
399         DATA_BLOB blob;
400         int num_domains = 0;
401         const char **trusted_domains = NULL;
402         struct lsa_DomainList domain_list;
403         struct dcerpc_binding_handle *h = NULL;
404         struct policy_handle pol;
405         uint32_t enum_ctx = 0;
406         int i;
407         uint32_t max_size = (uint32_t)-1;
408
409         DEBUG(6,("_netr_NetrEnumerateTrustedDomains: %d\n", __LINE__));
410
411         status = rpcint_binding_handle(p->mem_ctx,
412                                        &ndr_table_lsarpc,
413                                        p->client_id,
414                                        p->server_info,
415                                        p->msg_ctx,
416                                        &h);
417         if (!NT_STATUS_IS_OK(status)) {
418                 return status;
419         }
420
421         status = dcerpc_lsa_open_policy2(h,
422                                          p->mem_ctx,
423                                          NULL,
424                                          true,
425                                          LSA_POLICY_VIEW_LOCAL_INFORMATION,
426                                          &pol,
427                                          &result);
428         if (!NT_STATUS_IS_OK(status)) {
429                 goto out;
430         }
431         if (!NT_STATUS_IS_OK(result)) {
432                 status = result;
433                 goto out;
434         }
435
436         do {
437                 /* Lookup list of trusted domains */
438                 status = dcerpc_lsa_EnumTrustDom(h,
439                                                  p->mem_ctx,
440                                                  &pol,
441                                                  &enum_ctx,
442                                                  &domain_list,
443                                                  max_size,
444                                                  &result);
445                 if (!NT_STATUS_IS_OK(status)) {
446                         goto out;
447                 }
448                 if (!NT_STATUS_IS_OK(result) &&
449                     !NT_STATUS_EQUAL(result, NT_STATUS_NO_MORE_ENTRIES) &&
450                     !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)) {
451                         status = result;
452                         goto out;
453                 }
454
455                 for (i = 0; i < domain_list.count; i++) {
456                         if (!add_string_to_array(p->mem_ctx, domain_list.domains[i].name.string,
457                                                  &trusted_domains, &num_domains)) {
458                                 status = NT_STATUS_NO_MEMORY;
459                                 goto out;
460                         }
461                 }
462         } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
463
464         if (num_domains > 0) {
465                 /* multi sz terminate */
466                 trusted_domains = talloc_realloc(p->mem_ctx, trusted_domains, const char *, num_domains + 1);
467                 if (trusted_domains == NULL) {
468                         status = NT_STATUS_NO_MEMORY;
469                         goto out;
470                 }
471
472                 trusted_domains[num_domains] = NULL;
473         }
474
475         if (!push_reg_multi_sz(trusted_domains, &blob, trusted_domains)) {
476                 TALLOC_FREE(trusted_domains);
477                 status = NT_STATUS_NO_MEMORY;
478                 goto out;
479         }
480
481         r->out.trusted_domains_blob->data = blob.data;
482         r->out.trusted_domains_blob->length = blob.length;
483
484         DEBUG(6,("_netr_NetrEnumerateTrustedDomains: %d\n", __LINE__));
485
486         status = NT_STATUS_OK;
487
488  out:
489         if (h && is_valid_policy_hnd(&pol)) {
490                 dcerpc_lsa_Close(h, p->mem_ctx, &pol, &result);
491         }
492
493         return status;
494 }
495
496 /*************************************************************************
497  *************************************************************************/
498
499 static NTSTATUS samr_find_machine_account(TALLOC_CTX *mem_ctx,
500                                           struct dcerpc_binding_handle *b,
501                                           const char *account_name,
502                                           uint32_t access_mask,
503                                           struct dom_sid2 **domain_sid_p,
504                                           uint32_t *user_rid_p,
505                                           struct policy_handle *user_handle)
506 {
507         NTSTATUS status;
508         NTSTATUS result = NT_STATUS_OK;
509         struct policy_handle connect_handle, domain_handle;
510         struct lsa_String domain_name;
511         struct dom_sid2 *domain_sid;
512         struct lsa_String names;
513         struct samr_Ids rids;
514         struct samr_Ids types;
515         uint32_t rid;
516
517         status = dcerpc_samr_Connect2(b, mem_ctx,
518                                       global_myname(),
519                                       SAMR_ACCESS_CONNECT_TO_SERVER |
520                                       SAMR_ACCESS_ENUM_DOMAINS |
521                                       SAMR_ACCESS_LOOKUP_DOMAIN,
522                                       &connect_handle,
523                                       &result);
524         if (!NT_STATUS_IS_OK(status)) {
525                 goto out;
526         }
527         if (!NT_STATUS_IS_OK(result)) {
528                 status = result;
529                 goto out;
530         }
531
532         init_lsa_String(&domain_name, get_global_sam_name());
533
534         status = dcerpc_samr_LookupDomain(b, mem_ctx,
535                                           &connect_handle,
536                                           &domain_name,
537                                           &domain_sid,
538                                           &result);
539         if (!NT_STATUS_IS_OK(status)) {
540                 goto out;
541         }
542         if (!NT_STATUS_IS_OK(result)) {
543                 status = result;
544                 goto out;
545         }
546
547         status = dcerpc_samr_OpenDomain(b, mem_ctx,
548                                         &connect_handle,
549                                         SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT,
550                                         domain_sid,
551                                         &domain_handle,
552                                         &result);
553         if (!NT_STATUS_IS_OK(status)) {
554                 goto out;
555         }
556         if (!NT_STATUS_IS_OK(result)) {
557                 status = result;
558                 goto out;
559         }
560
561         init_lsa_String(&names, account_name);
562
563         status = dcerpc_samr_LookupNames(b, mem_ctx,
564                                          &domain_handle,
565                                          1,
566                                          &names,
567                                          &rids,
568                                          &types,
569                                          &result);
570         if (!NT_STATUS_IS_OK(status)) {
571                 goto out;
572         }
573         if (!NT_STATUS_IS_OK(result)) {
574                 status = result;
575                 goto out;
576         }
577
578         if (rids.count != 1) {
579                 status = NT_STATUS_NO_SUCH_USER;
580                 goto out;
581         }
582         if (rids.count != types.count) {
583                 status = NT_STATUS_INVALID_PARAMETER;
584                 goto out;
585         }
586         if (types.ids[0] != SID_NAME_USER) {
587                 status = NT_STATUS_NO_SUCH_USER;
588                 goto out;
589         }
590
591         rid = rids.ids[0];
592
593         status = dcerpc_samr_OpenUser(b, mem_ctx,
594                                       &domain_handle,
595                                       access_mask,
596                                       rid,
597                                       user_handle,
598                                       &result);
599         if (!NT_STATUS_IS_OK(status)) {
600                 goto out;
601         }
602         if (!NT_STATUS_IS_OK(result)) {
603                 status = result;
604                 goto out;
605         }
606
607         if (user_rid_p) {
608                 *user_rid_p = rid;
609         }
610
611         if (domain_sid_p) {
612                 *domain_sid_p = domain_sid;
613         }
614
615  out:
616         if (b && is_valid_policy_hnd(&domain_handle)) {
617                 dcerpc_samr_Close(b, mem_ctx, &domain_handle, &result);
618         }
619         if (b && is_valid_policy_hnd(&connect_handle)) {
620                 dcerpc_samr_Close(b, mem_ctx, &connect_handle, &result);
621         }
622
623         return status;
624 }
625
626 /******************************************************************
627  gets a machine password entry.  checks access rights of the host.
628  ******************************************************************/
629
630 static NTSTATUS get_md4pw(struct samr_Password *md4pw, const char *mach_acct,
631                           enum netr_SchannelType sec_chan_type,
632                           struct dom_sid *sid,
633                           struct messaging_context *msg_ctx)
634 {
635         NTSTATUS status;
636         NTSTATUS result = NT_STATUS_OK;
637         TALLOC_CTX *mem_ctx;
638         struct dcerpc_binding_handle *h = NULL;
639         static struct client_address client_id;
640         struct policy_handle user_handle;
641         uint32_t user_rid;
642         struct dom_sid *domain_sid;
643         uint32_t acct_ctrl;
644         union samr_UserInfo *info;
645         struct auth_serversupplied_info *server_info;
646 #if 0
647
648     /*
649      * Currently this code is redundent as we already have a filter
650      * by hostname list. What this code really needs to do is to
651      * get a hosts allowed/hosts denied list from the SAM database
652      * on a per user basis, and make the access decision there.
653      * I will leave this code here for now as a reminder to implement
654      * this at a later date. JRA.
655      */
656
657         if (!allow_access(lp_domain_hostsdeny(), lp_domain_hostsallow(),
658                           p->client_id.name,
659                           p->client_id.addr)) {
660                 DEBUG(0,("get_md4pw: Workstation %s denied access to domain\n", mach_acct));
661                 return False;
662         }
663 #endif /* 0 */
664
665         mem_ctx = talloc_stackframe();
666         if (mem_ctx == NULL) {
667                 status = NT_STATUS_NO_MEMORY;
668                 goto out;
669         }
670
671         status = make_server_info_system(mem_ctx, &server_info);
672         if (!NT_STATUS_IS_OK(status)) {
673                 goto out;
674         }
675
676         ZERO_STRUCT(user_handle);
677
678         strlcpy(client_id.addr, "127.0.0.1", sizeof(client_id.addr));
679         client_id.name = "127.0.0.1";
680
681         status = rpcint_binding_handle(mem_ctx,
682                                        &ndr_table_samr,
683                                        &client_id,
684                                        server_info,
685                                        msg_ctx,
686                                        &h);
687         if (!NT_STATUS_IS_OK(status)) {
688                 goto out;
689         }
690
691         become_root();
692         status = samr_find_machine_account(mem_ctx, h, mach_acct,
693                                            SEC_FLAG_MAXIMUM_ALLOWED,
694                                            &domain_sid, &user_rid,
695                                            &user_handle);
696         unbecome_root();
697         if (!NT_STATUS_IS_OK(status)) {
698                 goto out;
699         }
700
701         status = dcerpc_samr_QueryUserInfo2(h,
702                                             mem_ctx,
703                                             &user_handle,
704                                             UserControlInformation,
705                                             &info,
706                                             &result);
707         if (!NT_STATUS_IS_OK(status)) {
708                 goto out;
709         }
710         if (!NT_STATUS_IS_OK(result)) {
711                 status = result;
712                 goto out;
713         }
714
715         acct_ctrl = info->info16.acct_flags;
716
717         if (acct_ctrl & ACB_DISABLED) {
718                 DEBUG(0,("get_md4pw: Workstation %s: account is disabled\n", mach_acct));
719                 status = NT_STATUS_ACCOUNT_DISABLED;
720                 goto out;
721         }
722
723         if (!(acct_ctrl & ACB_SVRTRUST) &&
724             !(acct_ctrl & ACB_WSTRUST) &&
725             !(acct_ctrl & ACB_DOMTRUST))
726         {
727                 DEBUG(0,("get_md4pw: Workstation %s: account is not a trust account\n", mach_acct));
728                 status = NT_STATUS_NO_TRUST_SAM_ACCOUNT;
729                 goto out;
730         }
731
732         switch (sec_chan_type) {
733                 case SEC_CHAN_BDC:
734                         if (!(acct_ctrl & ACB_SVRTRUST)) {
735                                 DEBUG(0,("get_md4pw: Workstation %s: BDC secure channel requested "
736                                          "but not a server trust account\n", mach_acct));
737                                 status = NT_STATUS_NO_TRUST_SAM_ACCOUNT;
738                                 goto out;
739                         }
740                         break;
741                 case SEC_CHAN_WKSTA:
742                         if (!(acct_ctrl & ACB_WSTRUST)) {
743                                 DEBUG(0,("get_md4pw: Workstation %s: WORKSTATION secure channel requested "
744                                          "but not a workstation trust account\n", mach_acct));
745                                 status = NT_STATUS_NO_TRUST_SAM_ACCOUNT;
746                                 goto out;
747                         }
748                         break;
749                 case SEC_CHAN_DOMAIN:
750                         if (!(acct_ctrl & ACB_DOMTRUST)) {
751                                 DEBUG(0,("get_md4pw: Workstation %s: DOMAIN secure channel requested "
752                                          "but not a interdomain trust account\n", mach_acct));
753                                 status = NT_STATUS_NO_TRUST_SAM_ACCOUNT;
754                                 goto out;
755                         }
756                         break;
757                 default:
758                         break;
759         }
760
761         become_root();
762         status = dcerpc_samr_QueryUserInfo2(h,
763                                             mem_ctx,
764                                             &user_handle,
765                                             UserInternal1Information,
766                                             &info,
767                                             &result);
768         unbecome_root();
769         if (!NT_STATUS_IS_OK(status)) {
770                 goto out;
771         }
772         if (!NT_STATUS_IS_OK(result)) {
773                 status = result;
774                 goto out;
775         }
776
777         if (info->info18.nt_pwd_active == 0) {
778                 DEBUG(0,("get_md4pw: Workstation %s: account does not have a password\n", mach_acct));
779                 status = NT_STATUS_LOGON_FAILURE;
780                 goto out;
781         }
782
783         /* samr gives out nthash unencrypted (!) */
784         memcpy(md4pw->hash, info->info18.nt_pwd.hash, 16);
785
786         sid_compose(sid, domain_sid, user_rid);
787
788  out:
789         if (h && is_valid_policy_hnd(&user_handle)) {
790                 dcerpc_samr_Close(h, mem_ctx, &user_handle, &result);
791         }
792
793         talloc_free(mem_ctx);
794
795         return status;
796 }
797
798 /*************************************************************************
799  _netr_ServerReqChallenge
800  *************************************************************************/
801
802 NTSTATUS _netr_ServerReqChallenge(struct pipes_struct *p,
803                                   struct netr_ServerReqChallenge *r)
804 {
805         struct netlogon_server_pipe_state *pipe_state =
806                 talloc_get_type(p->private_data, struct netlogon_server_pipe_state);
807
808         if (pipe_state) {
809                 DEBUG(10,("_netr_ServerReqChallenge: new challenge requested. Clearing old state.\n"));
810                 talloc_free(pipe_state);
811                 p->private_data = NULL;
812         }
813
814         pipe_state = talloc(p, struct netlogon_server_pipe_state);
815         NT_STATUS_HAVE_NO_MEMORY(pipe_state);
816
817         pipe_state->client_challenge = *r->in.credentials;
818
819         generate_random_buffer(pipe_state->server_challenge.data,
820                                sizeof(pipe_state->server_challenge.data));
821
822         *r->out.return_credentials = pipe_state->server_challenge;
823
824         p->private_data = pipe_state;
825
826         return NT_STATUS_OK;
827 }
828
829 /*************************************************************************
830  _netr_ServerAuthenticate
831  Create the initial credentials.
832  *************************************************************************/
833
834 NTSTATUS _netr_ServerAuthenticate(struct pipes_struct *p,
835                                   struct netr_ServerAuthenticate *r)
836 {
837         struct netr_ServerAuthenticate3 a;
838         uint32_t negotiate_flags = 0;
839         uint32_t rid;
840
841         a.in.server_name                = r->in.server_name;
842         a.in.account_name               = r->in.account_name;
843         a.in.secure_channel_type        = r->in.secure_channel_type;
844         a.in.computer_name              = r->in.computer_name;
845         a.in.credentials                = r->in.credentials;
846         a.in.negotiate_flags            = &negotiate_flags;
847
848         a.out.return_credentials        = r->out.return_credentials;
849         a.out.rid                       = &rid;
850         a.out.negotiate_flags           = &negotiate_flags;
851
852         return _netr_ServerAuthenticate3(p, &a);
853
854 }
855
856 /*************************************************************************
857  _netr_ServerAuthenticate3
858  *************************************************************************/
859
860 NTSTATUS _netr_ServerAuthenticate3(struct pipes_struct *p,
861                                    struct netr_ServerAuthenticate3 *r)
862 {
863         NTSTATUS status;
864         uint32_t srv_flgs;
865         /* r->in.negotiate_flags is an aliased pointer to r->out.negotiate_flags,
866          * so use a copy to avoid destroying the client values. */
867         uint32_t in_neg_flags = *r->in.negotiate_flags;
868         const char *fn;
869         struct dom_sid sid;
870         struct samr_Password mach_pwd;
871         struct netlogon_creds_CredentialState *creds;
872         struct netlogon_server_pipe_state *pipe_state =
873                 talloc_get_type(p->private_data, struct netlogon_server_pipe_state);
874
875         /* According to Microsoft (see bugid #6099)
876          * Windows 7 looks at the negotiate_flags
877          * returned in this structure *even if the
878          * call fails with access denied* ! So in order
879          * to allow Win7 to connect to a Samba NT style
880          * PDC we set the flags before we know if it's
881          * an error or not.
882          */
883
884         /* 0x000001ff */
885         srv_flgs = NETLOGON_NEG_ACCOUNT_LOCKOUT |
886                    NETLOGON_NEG_PERSISTENT_SAMREPL |
887                    NETLOGON_NEG_ARCFOUR |
888                    NETLOGON_NEG_PROMOTION_COUNT |
889                    NETLOGON_NEG_CHANGELOG_BDC |
890                    NETLOGON_NEG_FULL_SYNC_REPL |
891                    NETLOGON_NEG_MULTIPLE_SIDS |
892                    NETLOGON_NEG_REDO |
893                    NETLOGON_NEG_PASSWORD_CHANGE_REFUSAL |
894                    NETLOGON_NEG_PASSWORD_SET2;
895
896         /* Ensure we support strong (128-bit) keys. */
897         if (in_neg_flags & NETLOGON_NEG_STRONG_KEYS) {
898                 srv_flgs |= NETLOGON_NEG_STRONG_KEYS;
899         }
900
901         if (lp_server_schannel() != false) {
902                 srv_flgs |= NETLOGON_NEG_SCHANNEL;
903         }
904
905         switch (p->opnum) {
906                 case NDR_NETR_SERVERAUTHENTICATE:
907                         fn = "_netr_ServerAuthenticate";
908                         break;
909                 case NDR_NETR_SERVERAUTHENTICATE2:
910                         fn = "_netr_ServerAuthenticate2";
911                         break;
912                 case NDR_NETR_SERVERAUTHENTICATE3:
913                         fn = "_netr_ServerAuthenticate3";
914                         break;
915                 default:
916                         return NT_STATUS_INTERNAL_ERROR;
917         }
918
919         /* We use this as the key to store the creds: */
920         /* r->in.computer_name */
921
922         if (!pipe_state) {
923                 DEBUG(0,("%s: no challenge sent to client %s\n", fn,
924                         r->in.computer_name));
925                 status = NT_STATUS_ACCESS_DENIED;
926                 goto out;
927         }
928
929         if ( (lp_server_schannel() == true) &&
930              ((in_neg_flags & NETLOGON_NEG_SCHANNEL) == 0) ) {
931
932                 /* schannel must be used, but client did not offer it. */
933                 DEBUG(0,("%s: schannel required but client failed "
934                         "to offer it. Client was %s\n",
935                         fn, r->in.account_name));
936                 status = NT_STATUS_ACCESS_DENIED;
937                 goto out;
938         }
939
940         status = get_md4pw(&mach_pwd,
941                            r->in.account_name,
942                            r->in.secure_channel_type,
943                            &sid, p->msg_ctx);
944         if (!NT_STATUS_IS_OK(status)) {
945                 DEBUG(0,("%s: failed to get machine password for "
946                         "account %s: %s\n",
947                         fn, r->in.account_name, nt_errstr(status) ));
948                 /* always return NT_STATUS_ACCESS_DENIED */
949                 status = NT_STATUS_ACCESS_DENIED;
950                 goto out;
951         }
952
953         /* From the client / server challenges and md4 password, generate sess key */
954         /* Check client credentials are valid. */
955         creds = netlogon_creds_server_init(p->mem_ctx,
956                                            r->in.account_name,
957                                            r->in.computer_name,
958                                            r->in.secure_channel_type,
959                                            &pipe_state->client_challenge,
960                                            &pipe_state->server_challenge,
961                                            &mach_pwd,
962                                            r->in.credentials,
963                                            r->out.return_credentials,
964                                            *r->in.negotiate_flags);
965         if (!creds) {
966                 DEBUG(0,("%s: netlogon_creds_server_check failed. Rejecting auth "
967                         "request from client %s machine account %s\n",
968                         fn, r->in.computer_name,
969                         r->in.account_name));
970                 status = NT_STATUS_ACCESS_DENIED;
971                 goto out;
972         }
973
974         creds->sid = dom_sid_dup(creds, &sid);
975         if (!creds->sid) {
976                 status = NT_STATUS_NO_MEMORY;
977                 goto out;
978         }
979
980         /* Store off the state so we can continue after client disconnect. */
981         become_root();
982         status = schannel_save_creds_state(p->mem_ctx, lp_private_dir(), creds);
983         unbecome_root();
984
985         if (!NT_STATUS_IS_OK(status)) {
986                 goto out;
987         }
988
989         sid_peek_rid(&sid, r->out.rid);
990
991         status = NT_STATUS_OK;
992
993   out:
994
995         *r->out.negotiate_flags = srv_flgs;
996         return status;
997 }
998
999 /*************************************************************************
1000  _netr_ServerAuthenticate2
1001  *************************************************************************/
1002
1003 NTSTATUS _netr_ServerAuthenticate2(struct pipes_struct *p,
1004                                    struct netr_ServerAuthenticate2 *r)
1005 {
1006         struct netr_ServerAuthenticate3 a;
1007         uint32_t rid;
1008
1009         a.in.server_name                = r->in.server_name;
1010         a.in.account_name               = r->in.account_name;
1011         a.in.secure_channel_type        = r->in.secure_channel_type;
1012         a.in.computer_name              = r->in.computer_name;
1013         a.in.credentials                = r->in.credentials;
1014         a.in.negotiate_flags            = r->in.negotiate_flags;
1015
1016         a.out.return_credentials        = r->out.return_credentials;
1017         a.out.rid                       = &rid;
1018         a.out.negotiate_flags           = r->out.negotiate_flags;
1019
1020         return _netr_ServerAuthenticate3(p, &a);
1021 }
1022
1023 /*************************************************************************
1024  * If schannel is required for this call test that it actually is available.
1025  *************************************************************************/
1026 static NTSTATUS schannel_check_required(struct pipe_auth_data *auth_info,
1027                                         const char *computer_name,
1028                                         bool integrity, bool privacy)
1029 {
1030         if (auth_info && auth_info->auth_type == DCERPC_AUTH_TYPE_SCHANNEL) {
1031                 if (!privacy && !integrity) {
1032                         return NT_STATUS_OK;
1033                 }
1034
1035                 if ((!privacy && integrity) &&
1036                     auth_info->auth_level == DCERPC_AUTH_LEVEL_INTEGRITY) {
1037                         return NT_STATUS_OK;
1038                 }
1039
1040                 if ((privacy || integrity) &&
1041                     auth_info->auth_level == DCERPC_AUTH_LEVEL_PRIVACY) {
1042                         return NT_STATUS_OK;
1043                 }
1044         }
1045
1046         /* test didn't pass */
1047         DEBUG(0, ("schannel_check_required: [%s] is not using schannel\n",
1048                   computer_name));
1049
1050         return NT_STATUS_ACCESS_DENIED;
1051 }
1052
1053 /*************************************************************************
1054  *************************************************************************/
1055
1056 static NTSTATUS netr_creds_server_step_check(struct pipes_struct *p,
1057                                              TALLOC_CTX *mem_ctx,
1058                                              const char *computer_name,
1059                                              struct netr_Authenticator *received_authenticator,
1060                                              struct netr_Authenticator *return_authenticator,
1061                                              struct netlogon_creds_CredentialState **creds_out)
1062 {
1063         NTSTATUS status;
1064         bool schannel_global_required = (lp_server_schannel() == true) ? true:false;
1065
1066         if (schannel_global_required) {
1067                 status = schannel_check_required(&p->auth,
1068                                                  computer_name,
1069                                                  false, false);
1070                 if (!NT_STATUS_IS_OK(status)) {
1071                         return status;
1072                 }
1073         }
1074
1075         status = schannel_check_creds_state(mem_ctx, lp_private_dir(),
1076                                             computer_name, received_authenticator,
1077                                             return_authenticator, creds_out);
1078
1079         return status;
1080 }
1081
1082 /*************************************************************************
1083  *************************************************************************/
1084
1085 static NTSTATUS netr_set_machine_account_password(TALLOC_CTX *mem_ctx,
1086                                                   struct auth_serversupplied_info *server_info,
1087                                                   struct messaging_context *msg_ctx,
1088                                                   const char *account_name,
1089                                                   struct samr_Password *nt_hash)
1090 {
1091         NTSTATUS status;
1092         NTSTATUS result = NT_STATUS_OK;
1093         struct dcerpc_binding_handle *h = NULL;
1094         static struct client_address client_id;
1095         struct policy_handle user_handle;
1096         uint32_t acct_ctrl;
1097         union samr_UserInfo *info;
1098         struct samr_UserInfo18 info18;
1099         DATA_BLOB in,out;
1100
1101         ZERO_STRUCT(user_handle);
1102
1103         strlcpy(client_id.addr, "127.0.0.1", sizeof(client_id.addr));
1104         client_id.name = "127.0.0.1";
1105
1106         status = rpcint_binding_handle(mem_ctx,
1107                                        &ndr_table_samr,
1108                                        &client_id,
1109                                        server_info,
1110                                        msg_ctx,
1111                                        &h);
1112         if (!NT_STATUS_IS_OK(status)) {
1113                 goto out;
1114         }
1115
1116         status = samr_find_machine_account(mem_ctx,
1117                                            h,
1118                                            account_name,
1119                                            SEC_FLAG_MAXIMUM_ALLOWED,
1120                                            NULL,
1121                                            NULL,
1122                                            &user_handle);
1123         if (!NT_STATUS_IS_OK(status)) {
1124                 goto out;
1125         }
1126
1127         status = dcerpc_samr_QueryUserInfo2(h,
1128                                             mem_ctx,
1129                                             &user_handle,
1130                                             UserControlInformation,
1131                                             &info,
1132                                             &result);
1133         if (!NT_STATUS_IS_OK(status)) {
1134                 goto out;
1135         }
1136         if (!NT_STATUS_IS_OK(result)) {
1137                 status = result;
1138                 goto out;
1139         }
1140
1141         acct_ctrl = info->info16.acct_flags;
1142
1143         if (!(acct_ctrl & ACB_WSTRUST ||
1144               acct_ctrl & ACB_SVRTRUST ||
1145               acct_ctrl & ACB_DOMTRUST)) {
1146                 status = NT_STATUS_NO_SUCH_USER;
1147                 goto out;
1148         }
1149
1150         if (acct_ctrl & ACB_DISABLED) {
1151                 status = NT_STATUS_ACCOUNT_DISABLED;
1152                 goto out;
1153         }
1154
1155         ZERO_STRUCT(info18);
1156
1157         in = data_blob_const(nt_hash->hash, 16);
1158         out = data_blob_talloc_zero(mem_ctx, 16);
1159         sess_crypt_blob(&out, &in, &server_info->user_session_key, true);
1160         memcpy(info18.nt_pwd.hash, out.data, out.length);
1161
1162         info18.nt_pwd_active = true;
1163
1164         info->info18 = info18;
1165
1166         status = dcerpc_samr_SetUserInfo2(h,
1167                                           mem_ctx,
1168                                           &user_handle,
1169                                           UserInternal1Information,
1170                                           info,
1171                                           &result);
1172         if (!NT_STATUS_IS_OK(status)) {
1173                 goto out;
1174         }
1175         if (!NT_STATUS_IS_OK(result)) {
1176                 status = result;
1177                 goto out;
1178         }
1179
1180  out:
1181         if (h && is_valid_policy_hnd(&user_handle)) {
1182                 dcerpc_samr_Close(h, mem_ctx, &user_handle, &result);
1183         }
1184
1185         return status;
1186 }
1187
1188 /*************************************************************************
1189  _netr_ServerPasswordSet
1190  *************************************************************************/
1191
1192 NTSTATUS _netr_ServerPasswordSet(struct pipes_struct *p,
1193                                  struct netr_ServerPasswordSet *r)
1194 {
1195         NTSTATUS status = NT_STATUS_OK;
1196         int i;
1197         struct netlogon_creds_CredentialState *creds;
1198
1199         DEBUG(5,("_netr_ServerPasswordSet: %d\n", __LINE__));
1200
1201         become_root();
1202         status = netr_creds_server_step_check(p, p->mem_ctx,
1203                                               r->in.computer_name,
1204                                               r->in.credential,
1205                                               r->out.return_authenticator,
1206                                               &creds);
1207         unbecome_root();
1208
1209         if (!NT_STATUS_IS_OK(status)) {
1210                 DEBUG(2,("_netr_ServerPasswordSet: netlogon_creds_server_step failed. Rejecting auth "
1211                         "request from client %s machine account %s\n",
1212                         r->in.computer_name, creds->computer_name));
1213                 TALLOC_FREE(creds);
1214                 return status;
1215         }
1216
1217         DEBUG(3,("_netr_ServerPasswordSet: Server Password Set by remote machine:[%s] on account [%s]\n",
1218                         r->in.computer_name, creds->computer_name));
1219
1220         netlogon_creds_des_decrypt(creds, r->in.new_password);
1221
1222         DEBUG(100,("_netr_ServerPasswordSet: new given value was :\n"));
1223         for(i = 0; i < sizeof(r->in.new_password->hash); i++)
1224                 DEBUG(100,("%02X ", r->in.new_password->hash[i]));
1225         DEBUG(100,("\n"));
1226
1227         status = netr_set_machine_account_password(p->mem_ctx,
1228                                                    p->server_info,
1229                                                    p->msg_ctx,
1230                                                    creds->account_name,
1231                                                    r->in.new_password);
1232         return status;
1233 }
1234
1235 /****************************************************************
1236  _netr_ServerPasswordSet2
1237 ****************************************************************/
1238
1239 NTSTATUS _netr_ServerPasswordSet2(struct pipes_struct *p,
1240                                   struct netr_ServerPasswordSet2 *r)
1241 {
1242         NTSTATUS status;
1243         struct netlogon_creds_CredentialState *creds;
1244         DATA_BLOB plaintext;
1245         struct samr_CryptPassword password_buf;
1246         struct samr_Password nt_hash;
1247
1248         become_root();
1249         status = netr_creds_server_step_check(p, p->mem_ctx,
1250                                               r->in.computer_name,
1251                                               r->in.credential,
1252                                               r->out.return_authenticator,
1253                                               &creds);
1254         unbecome_root();
1255
1256         if (!NT_STATUS_IS_OK(status)) {
1257                 DEBUG(2,("_netr_ServerPasswordSet2: netlogon_creds_server_step "
1258                         "failed. Rejecting auth request from client %s machine account %s\n",
1259                         r->in.computer_name, creds->computer_name));
1260                 TALLOC_FREE(creds);
1261                 return status;
1262         }
1263
1264         memcpy(password_buf.data, r->in.new_password->data, 512);
1265         SIVAL(password_buf.data, 512, r->in.new_password->length);
1266         netlogon_creds_arcfour_crypt(creds, password_buf.data, 516);
1267
1268         if (!extract_pw_from_buffer(p->mem_ctx, password_buf.data, &plaintext)) {
1269                 return NT_STATUS_WRONG_PASSWORD;
1270         }
1271
1272         mdfour(nt_hash.hash, plaintext.data, plaintext.length);
1273
1274         status = netr_set_machine_account_password(p->mem_ctx,
1275                                                    p->server_info,
1276                                                    p->msg_ctx,
1277                                                    creds->account_name,
1278                                                    &nt_hash);
1279         return status;
1280 }
1281
1282 /*************************************************************************
1283  _netr_LogonSamLogoff
1284  *************************************************************************/
1285
1286 NTSTATUS _netr_LogonSamLogoff(struct pipes_struct *p,
1287                               struct netr_LogonSamLogoff *r)
1288 {
1289         NTSTATUS status;
1290         struct netlogon_creds_CredentialState *creds;
1291
1292         become_root();
1293         status = netr_creds_server_step_check(p, p->mem_ctx,
1294                                               r->in.computer_name,
1295                                               r->in.credential,
1296                                               r->out.return_authenticator,
1297                                               &creds);
1298         unbecome_root();
1299
1300         return status;
1301 }
1302
1303 /*************************************************************************
1304  _netr_LogonSamLogon_base
1305  *************************************************************************/
1306
1307 static NTSTATUS _netr_LogonSamLogon_base(struct pipes_struct *p,
1308                                          struct netr_LogonSamLogonEx *r,
1309                                          struct netlogon_creds_CredentialState *creds)
1310 {
1311         NTSTATUS status = NT_STATUS_OK;
1312         union netr_LogonLevel *logon = r->in.logon;
1313         const char *nt_username, *nt_domain, *nt_workstation;
1314         struct auth_usersupplied_info *user_info = NULL;
1315         struct auth_serversupplied_info *server_info = NULL;
1316         struct auth_context *auth_context = NULL;
1317         uint8_t pipe_session_key[16];
1318         bool process_creds = true;
1319         const char *fn;
1320
1321         switch (p->opnum) {
1322                 case NDR_NETR_LOGONSAMLOGON:
1323                         process_creds = true;
1324                         fn = "_netr_LogonSamLogon";
1325                         break;
1326                 case NDR_NETR_LOGONSAMLOGONWITHFLAGS:
1327                         process_creds = true;
1328                         fn = "_netr_LogonSamLogonWithFlags";
1329                         break;
1330                 case NDR_NETR_LOGONSAMLOGONEX:
1331                         process_creds = false;
1332                         fn = "_netr_LogonSamLogonEx";
1333                         break;
1334                 default:
1335                         return NT_STATUS_INTERNAL_ERROR;
1336         }
1337
1338         *r->out.authoritative = true; /* authoritative response */
1339
1340         switch (r->in.validation_level) {
1341         case 2:
1342                 r->out.validation->sam2 = TALLOC_ZERO_P(p->mem_ctx, struct netr_SamInfo2);
1343                 if (!r->out.validation->sam2) {
1344                         return NT_STATUS_NO_MEMORY;
1345                 }
1346                 break;
1347         case 3:
1348                 r->out.validation->sam3 = TALLOC_ZERO_P(p->mem_ctx, struct netr_SamInfo3);
1349                 if (!r->out.validation->sam3) {
1350                         return NT_STATUS_NO_MEMORY;
1351                 }
1352                 break;
1353         case 6:
1354                 r->out.validation->sam6 = TALLOC_ZERO_P(p->mem_ctx, struct netr_SamInfo6);
1355                 if (!r->out.validation->sam6) {
1356                         return NT_STATUS_NO_MEMORY;
1357                 }
1358                 break;
1359         default:
1360                 DEBUG(0,("%s: bad validation_level value %d.\n",
1361                         fn, (int)r->in.validation_level));
1362                 return NT_STATUS_INVALID_INFO_CLASS;
1363         }
1364
1365         switch (r->in.logon_level) {
1366         case NetlogonInteractiveInformation:
1367         case NetlogonServiceInformation:
1368         case NetlogonInteractiveTransitiveInformation:
1369         case NetlogonServiceTransitiveInformation:
1370                 nt_username     = logon->password->identity_info.account_name.string ?
1371                                   logon->password->identity_info.account_name.string : "";
1372                 nt_domain       = logon->password->identity_info.domain_name.string ?
1373                                   logon->password->identity_info.domain_name.string : "";
1374                 nt_workstation  = logon->password->identity_info.workstation.string ?
1375                                   logon->password->identity_info.workstation.string : "";
1376
1377                 DEBUG(3,("SAM Logon (Interactive). Domain:[%s].  ", lp_workgroup()));
1378                 break;
1379         case NetlogonNetworkInformation:
1380         case NetlogonNetworkTransitiveInformation:
1381                 nt_username     = logon->network->identity_info.account_name.string ?
1382                                   logon->network->identity_info.account_name.string : "";
1383                 nt_domain       = logon->network->identity_info.domain_name.string ?
1384                                   logon->network->identity_info.domain_name.string : "";
1385                 nt_workstation  = logon->network->identity_info.workstation.string ?
1386                                   logon->network->identity_info.workstation.string : "";
1387
1388                 DEBUG(3,("SAM Logon (Network). Domain:[%s].  ", lp_workgroup()));
1389                 break;
1390         default:
1391                 DEBUG(2,("SAM Logon: unsupported switch value\n"));
1392                 return NT_STATUS_INVALID_INFO_CLASS;
1393         } /* end switch */
1394
1395         DEBUG(3,("User:[%s@%s] Requested Domain:[%s]\n", nt_username, nt_workstation, nt_domain));
1396         fstrcpy(current_user_info.smb_name, nt_username);
1397         sub_set_smb_name(nt_username);
1398
1399         DEBUG(5,("Attempting validation level %d for unmapped username %s.\n",
1400                 r->in.validation_level, nt_username));
1401
1402         status = NT_STATUS_OK;
1403
1404         switch (r->in.logon_level) {
1405         case NetlogonNetworkInformation:
1406         case NetlogonNetworkTransitiveInformation:
1407         {
1408                 const char *wksname = nt_workstation;
1409
1410                 status = make_auth_context_fixed(talloc_tos(), &auth_context,
1411                                                  logon->network->challenge);
1412                 if (!NT_STATUS_IS_OK(status)) {
1413                         return status;
1414                 }
1415
1416                 /* For a network logon, the workstation name comes in with two
1417                  * backslashes in the front. Strip them if they are there. */
1418
1419                 if (*wksname == '\\') wksname++;
1420                 if (*wksname == '\\') wksname++;
1421
1422                 /* Standard challenge/response authenticaion */
1423                 if (!make_user_info_netlogon_network(&user_info,
1424                                                      nt_username, nt_domain,
1425                                                      wksname,
1426                                                      logon->network->identity_info.parameter_control,
1427                                                      logon->network->lm.data,
1428                                                      logon->network->lm.length,
1429                                                      logon->network->nt.data,
1430                                                      logon->network->nt.length)) {
1431                         status = NT_STATUS_NO_MEMORY;
1432                 }
1433                 break;
1434         }
1435         case NetlogonInteractiveInformation:
1436         case NetlogonServiceInformation:
1437         case NetlogonInteractiveTransitiveInformation:
1438         case NetlogonServiceTransitiveInformation:
1439
1440                 /* 'Interactive' authentication, supplies the password in its
1441                    MD4 form, encrypted with the session key.  We will convert
1442                    this to challenge/response for the auth subsystem to chew
1443                    on */
1444         {
1445                 uint8_t chal[8];
1446
1447                 status = make_auth_context_subsystem(talloc_tos(),
1448                                                      &auth_context);
1449                 if (!NT_STATUS_IS_OK(status)) {
1450                         return status;
1451                 }
1452
1453                 auth_context->get_ntlm_challenge(auth_context, chal);
1454
1455                 if (!make_user_info_netlogon_interactive(&user_info,
1456                                                          nt_username, nt_domain,
1457                                                          nt_workstation,
1458                                                          logon->password->identity_info.parameter_control,
1459                                                          chal,
1460                                                          logon->password->lmpassword.hash,
1461                                                          logon->password->ntpassword.hash,
1462                                                          creds->session_key)) {
1463                         status = NT_STATUS_NO_MEMORY;
1464                 }
1465                 break;
1466         }
1467         default:
1468                 DEBUG(2,("SAM Logon: unsupported switch value\n"));
1469                 return NT_STATUS_INVALID_INFO_CLASS;
1470         } /* end switch */
1471
1472         if ( NT_STATUS_IS_OK(status) ) {
1473                 status = auth_context->check_ntlm_password(auth_context,
1474                         user_info, &server_info);
1475         }
1476
1477         TALLOC_FREE(auth_context);
1478         free_user_info(&user_info);
1479
1480         DEBUG(5,("%s: check_password returned status %s\n",
1481                   fn, nt_errstr(status)));
1482
1483         /* Check account and password */
1484
1485         if (!NT_STATUS_IS_OK(status)) {
1486                 /* If we don't know what this domain is, we need to
1487                    indicate that we are not authoritative.  This
1488                    allows the client to decide if it needs to try
1489                    a local user.  Fix by jpjanosi@us.ibm.com, #2976 */
1490                 if ( NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_USER)
1491                      && !strequal(nt_domain, get_global_sam_name())
1492                      && !is_trusted_domain(nt_domain) )
1493                         *r->out.authoritative = false; /* We are not authoritative */
1494
1495                 TALLOC_FREE(server_info);
1496                 return status;
1497         }
1498
1499         if (server_info->guest) {
1500                 /* We don't like guest domain logons... */
1501                 DEBUG(5,("%s: Attempted domain logon as GUEST "
1502                          "denied.\n", fn));
1503                 TALLOC_FREE(server_info);
1504                 return NT_STATUS_LOGON_FAILURE;
1505         }
1506
1507         /* This is the point at which, if the login was successful, that
1508            the SAM Local Security Authority should record that the user is
1509            logged in to the domain.  */
1510
1511         if (process_creds) {
1512                 /* Get the pipe session key from the creds. */
1513                 memcpy(pipe_session_key, creds->session_key, 16);
1514         } else {
1515                 struct schannel_state *schannel_auth;
1516                 /* Get the pipe session key from the schannel. */
1517                 if ((p->auth.auth_type != DCERPC_AUTH_TYPE_SCHANNEL)
1518                     || (p->auth.auth_ctx == NULL)) {
1519                         return NT_STATUS_INVALID_HANDLE;
1520                 }
1521
1522                 schannel_auth = talloc_get_type_abort(p->auth.auth_ctx,
1523                                                       struct schannel_state);
1524                 memcpy(pipe_session_key, schannel_auth->creds->session_key, 16);
1525         }
1526
1527         switch (r->in.validation_level) {
1528         case 2:
1529                 status = serverinfo_to_SamInfo2(server_info, pipe_session_key, 16,
1530                                                 r->out.validation->sam2);
1531                 break;
1532         case 3:
1533                 status = serverinfo_to_SamInfo3(server_info, pipe_session_key, 16,
1534                                                 r->out.validation->sam3);
1535                 break;
1536         case 6:
1537                 status = serverinfo_to_SamInfo6(server_info, pipe_session_key, 16,
1538                                                 r->out.validation->sam6);
1539                 break;
1540         }
1541
1542         TALLOC_FREE(server_info);
1543
1544         return status;
1545 }
1546
1547 /****************************************************************
1548  _netr_LogonSamLogonWithFlags
1549 ****************************************************************/
1550
1551 NTSTATUS _netr_LogonSamLogonWithFlags(struct pipes_struct *p,
1552                                       struct netr_LogonSamLogonWithFlags *r)
1553 {
1554         NTSTATUS status;
1555         struct netlogon_creds_CredentialState *creds;
1556         struct netr_LogonSamLogonEx r2;
1557         struct netr_Authenticator return_authenticator;
1558
1559         become_root();
1560         status = netr_creds_server_step_check(p, p->mem_ctx,
1561                                               r->in.computer_name,
1562                                               r->in.credential,
1563                                               &return_authenticator,
1564                                               &creds);
1565         unbecome_root();
1566         if (!NT_STATUS_IS_OK(status)) {
1567                 return status;
1568         }
1569
1570         r2.in.server_name       = r->in.server_name;
1571         r2.in.computer_name     = r->in.computer_name;
1572         r2.in.logon_level       = r->in.logon_level;
1573         r2.in.logon             = r->in.logon;
1574         r2.in.validation_level  = r->in.validation_level;
1575         r2.in.flags             = r->in.flags;
1576         r2.out.validation       = r->out.validation;
1577         r2.out.authoritative    = r->out.authoritative;
1578         r2.out.flags            = r->out.flags;
1579
1580         status = _netr_LogonSamLogon_base(p, &r2, creds);
1581
1582         *r->out.return_authenticator = return_authenticator;
1583
1584         return status;
1585 }
1586
1587 /*************************************************************************
1588  _netr_LogonSamLogon
1589  *************************************************************************/
1590
1591 NTSTATUS _netr_LogonSamLogon(struct pipes_struct *p,
1592                              struct netr_LogonSamLogon *r)
1593 {
1594         NTSTATUS status;
1595         struct netr_LogonSamLogonWithFlags r2;
1596         uint32_t flags = 0;
1597
1598         r2.in.server_name               = r->in.server_name;
1599         r2.in.computer_name             = r->in.computer_name;
1600         r2.in.credential                = r->in.credential;
1601         r2.in.logon_level               = r->in.logon_level;
1602         r2.in.logon                     = r->in.logon;
1603         r2.in.validation_level          = r->in.validation_level;
1604         r2.in.return_authenticator      = r->in.return_authenticator;
1605         r2.in.flags                     = &flags;
1606         r2.out.validation               = r->out.validation;
1607         r2.out.authoritative            = r->out.authoritative;
1608         r2.out.flags                    = &flags;
1609         r2.out.return_authenticator     = r->out.return_authenticator;
1610
1611         status = _netr_LogonSamLogonWithFlags(p, &r2);
1612
1613         return status;
1614 }
1615
1616 /*************************************************************************
1617  _netr_LogonSamLogonEx
1618  - no credential chaining. Map into net sam logon.
1619  *************************************************************************/
1620
1621 NTSTATUS _netr_LogonSamLogonEx(struct pipes_struct *p,
1622                                struct netr_LogonSamLogonEx *r)
1623 {
1624         NTSTATUS status;
1625         struct netlogon_creds_CredentialState *creds = NULL;
1626
1627         become_root();
1628         status = schannel_get_creds_state(p->mem_ctx, lp_private_dir(),
1629                                           r->in.computer_name, &creds);
1630         unbecome_root();
1631         if (!NT_STATUS_IS_OK(status)) {
1632                 return status;
1633         }
1634
1635         /* Only allow this if the pipe is protected. */
1636         if (p->auth.auth_type != DCERPC_AUTH_TYPE_SCHANNEL) {
1637                 DEBUG(0,("_netr_LogonSamLogonEx: client %s not using schannel for netlogon\n",
1638                         get_remote_machine_name() ));
1639                 return NT_STATUS_INVALID_PARAMETER;
1640         }
1641
1642         status = _netr_LogonSamLogon_base(p, r, creds);
1643         TALLOC_FREE(creds);
1644
1645         return status;
1646 }
1647
1648 /*************************************************************************
1649  _ds_enum_dom_trusts
1650  *************************************************************************/
1651 #if 0   /* JERRY -- not correct */
1652  NTSTATUS _ds_enum_dom_trusts(struct pipes_struct *p, DS_Q_ENUM_DOM_TRUSTS *q_u,
1653                              DS_R_ENUM_DOM_TRUSTS *r_u)
1654 {
1655         NTSTATUS status = NT_STATUS_OK;
1656
1657         /* TODO: According to MSDN, the can only be executed against a
1658            DC or domain member running Windows 2000 or later.  Need
1659            to test against a standalone 2k server and see what it
1660            does.  A windows 2000 DC includes its own domain in the
1661            list.  --jerry */
1662
1663         return status;
1664 }
1665 #endif  /* JERRY */
1666
1667
1668 /****************************************************************
1669 ****************************************************************/
1670
1671 WERROR _netr_LogonUasLogon(struct pipes_struct *p,
1672                            struct netr_LogonUasLogon *r)
1673 {
1674         p->rng_fault_state = true;
1675         return WERR_NOT_SUPPORTED;
1676 }
1677
1678 /****************************************************************
1679 ****************************************************************/
1680
1681 WERROR _netr_LogonUasLogoff(struct pipes_struct *p,
1682                             struct netr_LogonUasLogoff *r)
1683 {
1684         p->rng_fault_state = true;
1685         return WERR_NOT_SUPPORTED;
1686 }
1687
1688 /****************************************************************
1689 ****************************************************************/
1690
1691 NTSTATUS _netr_DatabaseDeltas(struct pipes_struct *p,
1692                               struct netr_DatabaseDeltas *r)
1693 {
1694         p->rng_fault_state = true;
1695         return NT_STATUS_NOT_IMPLEMENTED;
1696 }
1697
1698 /****************************************************************
1699 ****************************************************************/
1700
1701 NTSTATUS _netr_DatabaseSync(struct pipes_struct *p,
1702                             struct netr_DatabaseSync *r)
1703 {
1704         p->rng_fault_state = true;
1705         return NT_STATUS_NOT_IMPLEMENTED;
1706 }
1707
1708 /****************************************************************
1709 ****************************************************************/
1710
1711 NTSTATUS _netr_AccountDeltas(struct pipes_struct *p,
1712                              struct netr_AccountDeltas *r)
1713 {
1714         p->rng_fault_state = true;
1715         return NT_STATUS_NOT_IMPLEMENTED;
1716 }
1717
1718 /****************************************************************
1719 ****************************************************************/
1720
1721 NTSTATUS _netr_AccountSync(struct pipes_struct *p,
1722                            struct netr_AccountSync *r)
1723 {
1724         p->rng_fault_state = true;
1725         return NT_STATUS_NOT_IMPLEMENTED;
1726 }
1727
1728 /****************************************************************
1729 ****************************************************************/
1730
1731 static bool wb_getdcname(TALLOC_CTX *mem_ctx,
1732                          const char *domain,
1733                          const char **dcname,
1734                          uint32_t flags,
1735                          WERROR *werr)
1736 {
1737         wbcErr result;
1738         struct wbcDomainControllerInfo *dc_info = NULL;
1739
1740         result = wbcLookupDomainController(domain,
1741                                            flags,
1742                                            &dc_info);
1743         switch (result) {
1744         case WBC_ERR_SUCCESS:
1745                 break;
1746         case WBC_ERR_WINBIND_NOT_AVAILABLE:
1747                 return false;
1748         case WBC_ERR_DOMAIN_NOT_FOUND:
1749                 *werr = WERR_NO_SUCH_DOMAIN;
1750                 return true;
1751         default:
1752                 *werr = WERR_DOMAIN_CONTROLLER_NOT_FOUND;
1753                 return true;
1754         }
1755
1756         *dcname = talloc_strdup(mem_ctx, dc_info->dc_name);
1757         wbcFreeMemory(dc_info);
1758         if (!*dcname) {
1759                 *werr = WERR_NOMEM;
1760                 return false;
1761         }
1762
1763         *werr = WERR_OK;
1764
1765         return true;
1766 }
1767
1768 /****************************************************************
1769  _netr_GetDcName
1770 ****************************************************************/
1771
1772 WERROR _netr_GetDcName(struct pipes_struct *p,
1773                        struct netr_GetDcName *r)
1774 {
1775         NTSTATUS status;
1776         WERROR werr;
1777         uint32_t flags;
1778         struct netr_DsRGetDCNameInfo *info;
1779         bool ret;
1780
1781         ret = wb_getdcname(p->mem_ctx,
1782                            r->in.domainname,
1783                            r->out.dcname,
1784                            WBC_LOOKUP_DC_IS_FLAT_NAME |
1785                            WBC_LOOKUP_DC_RETURN_FLAT_NAME |
1786                            WBC_LOOKUP_DC_PDC_REQUIRED,
1787                            &werr);
1788         if (ret == true) {
1789                 return werr;
1790         }
1791
1792         flags = DS_PDC_REQUIRED | DS_IS_FLAT_NAME | DS_RETURN_FLAT_NAME;
1793
1794         status = dsgetdcname(p->mem_ctx,
1795                              p->msg_ctx,
1796                              r->in.domainname,
1797                              NULL,
1798                              NULL,
1799                              flags,
1800                              &info);
1801         if (!NT_STATUS_IS_OK(status)) {
1802                 return ntstatus_to_werror(status);
1803         }
1804
1805         *r->out.dcname = talloc_strdup(p->mem_ctx, info->dc_unc);
1806         talloc_free(info);
1807         if (!*r->out.dcname) {
1808                 return WERR_NOMEM;
1809         }
1810
1811         return WERR_OK;
1812 }
1813
1814 /****************************************************************
1815  _netr_GetAnyDCName
1816 ****************************************************************/
1817
1818 WERROR _netr_GetAnyDCName(struct pipes_struct *p,
1819                           struct netr_GetAnyDCName *r)
1820 {
1821         NTSTATUS status;
1822         WERROR werr;
1823         uint32_t flags;
1824         struct netr_DsRGetDCNameInfo *info;
1825         bool ret;
1826
1827         ret = wb_getdcname(p->mem_ctx,
1828                            r->in.domainname,
1829                            r->out.dcname,
1830                            WBC_LOOKUP_DC_IS_FLAT_NAME |
1831                            WBC_LOOKUP_DC_RETURN_FLAT_NAME,
1832                            &werr);
1833         if (ret == true) {
1834                 return werr;
1835         }
1836
1837         flags = DS_IS_FLAT_NAME | DS_RETURN_FLAT_NAME;
1838
1839         status = dsgetdcname(p->mem_ctx,
1840                              p->msg_ctx,
1841                              r->in.domainname,
1842                              NULL,
1843                              NULL,
1844                              flags,
1845                              &info);
1846         if (!NT_STATUS_IS_OK(status)) {
1847                 return ntstatus_to_werror(status);
1848         }
1849
1850         *r->out.dcname = talloc_strdup(p->mem_ctx, info->dc_unc);
1851         talloc_free(info);
1852         if (!*r->out.dcname) {
1853                 return WERR_NOMEM;
1854         }
1855
1856         return WERR_OK;
1857 }
1858
1859 /****************************************************************
1860 ****************************************************************/
1861
1862 NTSTATUS _netr_DatabaseSync2(struct pipes_struct *p,
1863                              struct netr_DatabaseSync2 *r)
1864 {
1865         p->rng_fault_state = true;
1866         return NT_STATUS_NOT_IMPLEMENTED;
1867 }
1868
1869 /****************************************************************
1870 ****************************************************************/
1871
1872 NTSTATUS _netr_DatabaseRedo(struct pipes_struct *p,
1873                             struct netr_DatabaseRedo *r)
1874 {
1875         p->rng_fault_state = true;
1876         return NT_STATUS_NOT_IMPLEMENTED;
1877 }
1878
1879 /****************************************************************
1880 ****************************************************************/
1881
1882 WERROR _netr_DsRGetDCName(struct pipes_struct *p,
1883                           struct netr_DsRGetDCName *r)
1884 {
1885         p->rng_fault_state = true;
1886         return WERR_NOT_SUPPORTED;
1887 }
1888
1889 /****************************************************************
1890 ****************************************************************/
1891
1892 NTSTATUS _netr_LogonGetCapabilities(struct pipes_struct *p,
1893                                     struct netr_LogonGetCapabilities *r)
1894 {
1895         return NT_STATUS_NOT_IMPLEMENTED;
1896 }
1897
1898 /****************************************************************
1899 ****************************************************************/
1900
1901 WERROR _netr_NETRLOGONSETSERVICEBITS(struct pipes_struct *p,
1902                                      struct netr_NETRLOGONSETSERVICEBITS *r)
1903 {
1904         p->rng_fault_state = true;
1905         return WERR_NOT_SUPPORTED;
1906 }
1907
1908 /****************************************************************
1909 ****************************************************************/
1910
1911 WERROR _netr_LogonGetTrustRid(struct pipes_struct *p,
1912                               struct netr_LogonGetTrustRid *r)
1913 {
1914         p->rng_fault_state = true;
1915         return WERR_NOT_SUPPORTED;
1916 }
1917
1918 /****************************************************************
1919 ****************************************************************/
1920
1921 WERROR _netr_NETRLOGONCOMPUTESERVERDIGEST(struct pipes_struct *p,
1922                                           struct netr_NETRLOGONCOMPUTESERVERDIGEST *r)
1923 {
1924         p->rng_fault_state = true;
1925         return WERR_NOT_SUPPORTED;
1926 }
1927
1928 /****************************************************************
1929 ****************************************************************/
1930
1931 WERROR _netr_NETRLOGONCOMPUTECLIENTDIGEST(struct pipes_struct *p,
1932                                           struct netr_NETRLOGONCOMPUTECLIENTDIGEST *r)
1933 {
1934         p->rng_fault_state = true;
1935         return WERR_NOT_SUPPORTED;
1936 }
1937
1938 /****************************************************************
1939 ****************************************************************/
1940
1941 WERROR _netr_DsRGetDCNameEx(struct pipes_struct *p,
1942                             struct netr_DsRGetDCNameEx *r)
1943 {
1944         p->rng_fault_state = true;
1945         return WERR_NOT_SUPPORTED;
1946 }
1947
1948 /****************************************************************
1949 ****************************************************************/
1950
1951 WERROR _netr_DsRGetSiteName(struct pipes_struct *p,
1952                             struct netr_DsRGetSiteName *r)
1953 {
1954         p->rng_fault_state = true;
1955         return WERR_NOT_SUPPORTED;
1956 }
1957
1958 /****************************************************************
1959 ****************************************************************/
1960
1961 NTSTATUS _netr_LogonGetDomainInfo(struct pipes_struct *p,
1962                                   struct netr_LogonGetDomainInfo *r)
1963 {
1964         p->rng_fault_state = true;
1965         return NT_STATUS_NOT_IMPLEMENTED;
1966 }
1967
1968 /****************************************************************
1969 ****************************************************************/
1970
1971 WERROR _netr_ServerPasswordGet(struct pipes_struct *p,
1972                                struct netr_ServerPasswordGet *r)
1973 {
1974         p->rng_fault_state = true;
1975         return WERR_NOT_SUPPORTED;
1976 }
1977
1978 /****************************************************************
1979 ****************************************************************/
1980
1981 WERROR _netr_NETRLOGONSENDTOSAM(struct pipes_struct *p,
1982                                 struct netr_NETRLOGONSENDTOSAM *r)
1983 {
1984         p->rng_fault_state = true;
1985         return WERR_NOT_SUPPORTED;
1986 }
1987
1988 /****************************************************************
1989 ****************************************************************/
1990
1991 WERROR _netr_DsRAddressToSitenamesW(struct pipes_struct *p,
1992                                     struct netr_DsRAddressToSitenamesW *r)
1993 {
1994         p->rng_fault_state = true;
1995         return WERR_NOT_SUPPORTED;
1996 }
1997
1998 /****************************************************************
1999 ****************************************************************/
2000
2001 WERROR _netr_DsRGetDCNameEx2(struct pipes_struct *p,
2002                              struct netr_DsRGetDCNameEx2 *r)
2003 {
2004         p->rng_fault_state = true;
2005         return WERR_NOT_SUPPORTED;
2006 }
2007
2008 /****************************************************************
2009 ****************************************************************/
2010
2011 WERROR _netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN(struct pipes_struct *p,
2012                                                  struct netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN *r)
2013 {
2014         p->rng_fault_state = true;
2015         return WERR_NOT_SUPPORTED;
2016 }
2017
2018 /****************************************************************
2019 ****************************************************************/
2020
2021 WERROR _netr_NetrEnumerateTrustedDomainsEx(struct pipes_struct *p,
2022                                            struct netr_NetrEnumerateTrustedDomainsEx *r)
2023 {
2024         p->rng_fault_state = true;
2025         return WERR_NOT_SUPPORTED;
2026 }
2027
2028 /****************************************************************
2029 ****************************************************************/
2030
2031 WERROR _netr_DsRAddressToSitenamesExW(struct pipes_struct *p,
2032                                       struct netr_DsRAddressToSitenamesExW *r)
2033 {
2034         p->rng_fault_state = true;
2035         return WERR_NOT_SUPPORTED;
2036 }
2037
2038 /****************************************************************
2039 ****************************************************************/
2040
2041 WERROR _netr_DsrGetDcSiteCoverageW(struct pipes_struct *p,
2042                                    struct netr_DsrGetDcSiteCoverageW *r)
2043 {
2044         p->rng_fault_state = true;
2045         return WERR_NOT_SUPPORTED;
2046 }
2047
2048 /****************************************************************
2049 ****************************************************************/
2050
2051 WERROR _netr_DsrEnumerateDomainTrusts(struct pipes_struct *p,
2052                                       struct netr_DsrEnumerateDomainTrusts *r)
2053 {
2054         p->rng_fault_state = true;
2055         return WERR_NOT_SUPPORTED;
2056 }
2057
2058 /****************************************************************
2059 ****************************************************************/
2060
2061 WERROR _netr_DsrDeregisterDNSHostRecords(struct pipes_struct *p,
2062                                          struct netr_DsrDeregisterDNSHostRecords *r)
2063 {
2064         p->rng_fault_state = true;
2065         return WERR_NOT_SUPPORTED;
2066 }
2067
2068 /****************************************************************
2069 ****************************************************************/
2070
2071 NTSTATUS _netr_ServerTrustPasswordsGet(struct pipes_struct *p,
2072                                        struct netr_ServerTrustPasswordsGet *r)
2073 {
2074         p->rng_fault_state = true;
2075         return NT_STATUS_NOT_IMPLEMENTED;
2076 }
2077
2078 /****************************************************************
2079 ****************************************************************/
2080
2081 WERROR _netr_DsRGetForestTrustInformation(struct pipes_struct *p,
2082                                           struct netr_DsRGetForestTrustInformation *r)
2083 {
2084         p->rng_fault_state = true;
2085         return WERR_NOT_SUPPORTED;
2086 }
2087
2088 /****************************************************************
2089 ****************************************************************/
2090
2091 NTSTATUS _netr_GetForestTrustInformation(struct pipes_struct *p,
2092                                          struct netr_GetForestTrustInformation *r)
2093 {
2094         p->rng_fault_state = true;
2095         return NT_STATUS_NOT_IMPLEMENTED;
2096 }
2097
2098 /****************************************************************
2099 ****************************************************************/
2100
2101 NTSTATUS _netr_ServerGetTrustInfo(struct pipes_struct *p,
2102                                   struct netr_ServerGetTrustInfo *r)
2103 {
2104         p->rng_fault_state = true;
2105         return NT_STATUS_NOT_IMPLEMENTED;
2106 }
2107
2108 /****************************************************************
2109 ****************************************************************/
2110
2111 NTSTATUS _netr_Unused47(struct pipes_struct *p,
2112                         struct netr_Unused47 *r)
2113 {
2114         p->rng_fault_state = true;
2115         return NT_STATUS_NOT_IMPLEMENTED;
2116 }
2117
2118 /****************************************************************
2119 ****************************************************************/
2120
2121 NTSTATUS _netr_DsrUpdateReadOnlyServerDnsRecords(struct pipes_struct *p,
2122                                                  struct netr_DsrUpdateReadOnlyServerDnsRecords *r)
2123 {
2124         p->rng_fault_state = true;
2125         return NT_STATUS_NOT_IMPLEMENTED;
2126 }