b55c74adfc42d6518db37a248f71af264a5200db
[samba.git] / source3 / rpc_server / netlogon / 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/ndr_samr_c.h"
33 #include "../librpc/gen_ndr/ndr_lsa_c.h"
34 #include "rpc_client/cli_lsarpc.h"
35 #include "librpc/gen_ndr/messaging.h"
36 #include "../lib/crypto/md4.h"
37 #include "rpc_client/init_lsa.h"
38 #include "rpc_server/rpc_ncacn_np.h"
39 #include "../libcli/security/security.h"
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->security_token, DOMAIN_RID_ADMINS) &&
212                     !nt_token_check_sid(&global_sid_Builtin_Administrators, p->server_info->security_token) &&
213                     !(acct_ctrl & (ACB_WSTRUST | ACB_SVRTRUST))) {
214                         return WERR_ACCESS_DENIED;
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 static NTSTATUS _netr_LogonSamLogon_check(const struct netr_LogonSamLogonEx *r)
1304 {
1305         switch (r->in.logon_level) {
1306         case NetlogonInteractiveInformation:
1307         case NetlogonServiceInformation:
1308         case NetlogonInteractiveTransitiveInformation:
1309         case NetlogonServiceTransitiveInformation:
1310                 if (r->in.logon->password == NULL) {
1311                         return NT_STATUS_INVALID_PARAMETER;
1312                 }
1313
1314                 switch (r->in.validation_level) {
1315                 case NetlogonValidationSamInfo:  /* 2 */
1316                 case NetlogonValidationSamInfo2: /* 3 */
1317                         break;
1318                 case NetlogonValidationSamInfo4: /* 6 */
1319                         if ((pdb_capabilities() & PDB_CAP_ADS) == 0) {
1320                                 DEBUG(10,("Not adding validation info level 6 "
1321                                    "without ADS passdb backend\n"));
1322                                 return NT_STATUS_INVALID_INFO_CLASS;
1323                         }
1324                         break;
1325                 default:
1326                         return NT_STATUS_INVALID_INFO_CLASS;
1327                 }
1328
1329                 break;
1330         case NetlogonNetworkInformation:
1331         case NetlogonNetworkTransitiveInformation:
1332                 if (r->in.logon->network == NULL) {
1333                         return NT_STATUS_INVALID_PARAMETER;
1334                 }
1335
1336                 switch (r->in.validation_level) {
1337                 case NetlogonValidationSamInfo:  /* 2 */
1338                 case NetlogonValidationSamInfo2: /* 3 */
1339                         break;
1340                 case NetlogonValidationSamInfo4: /* 6 */
1341                         if ((pdb_capabilities() & PDB_CAP_ADS) == 0) {
1342                                 DEBUG(10,("Not adding validation info level 6 "
1343                                    "without ADS passdb backend\n"));
1344                                 return NT_STATUS_INVALID_INFO_CLASS;
1345                         }
1346                         break;
1347                 default:
1348                         return NT_STATUS_INVALID_INFO_CLASS;
1349                 }
1350
1351                 break;
1352
1353         case NetlogonGenericInformation:
1354                 if (r->in.logon->generic == NULL) {
1355                         return NT_STATUS_INVALID_PARAMETER;
1356                 }
1357
1358                 /* we don't support this here */
1359                 return NT_STATUS_INVALID_PARAMETER;
1360 #if 0
1361                 switch (r->in.validation_level) {
1362                 /* TODO: case NetlogonValidationGenericInfo: 4 */
1363                 case NetlogonValidationGenericInfo2: /* 5 */
1364                         break;
1365                 default:
1366                         return NT_STATUS_INVALID_INFO_CLASS;
1367                 }
1368
1369                 break;
1370 #endif
1371         default:
1372                 return NT_STATUS_INVALID_PARAMETER;
1373         }
1374
1375         return NT_STATUS_OK;
1376 }
1377
1378 /*************************************************************************
1379  _netr_LogonSamLogon_base
1380  *************************************************************************/
1381
1382 static NTSTATUS _netr_LogonSamLogon_base(struct pipes_struct *p,
1383                                          struct netr_LogonSamLogonEx *r,
1384                                          struct netlogon_creds_CredentialState *creds)
1385 {
1386         NTSTATUS status = NT_STATUS_OK;
1387         union netr_LogonLevel *logon = r->in.logon;
1388         const char *nt_username, *nt_domain, *nt_workstation;
1389         struct auth_usersupplied_info *user_info = NULL;
1390         struct auth_serversupplied_info *server_info = NULL;
1391         struct auth_context *auth_context = NULL;
1392         uint8_t pipe_session_key[16];
1393         bool process_creds = true;
1394         const char *fn;
1395
1396         switch (p->opnum) {
1397                 case NDR_NETR_LOGONSAMLOGON:
1398                         process_creds = true;
1399                         fn = "_netr_LogonSamLogon";
1400                         break;
1401                 case NDR_NETR_LOGONSAMLOGONWITHFLAGS:
1402                         process_creds = true;
1403                         fn = "_netr_LogonSamLogonWithFlags";
1404                         break;
1405                 case NDR_NETR_LOGONSAMLOGONEX:
1406                         process_creds = false;
1407                         fn = "_netr_LogonSamLogonEx";
1408                         break;
1409                 default:
1410                         return NT_STATUS_INTERNAL_ERROR;
1411         }
1412
1413         *r->out.authoritative = true; /* authoritative response */
1414
1415         switch (r->in.validation_level) {
1416         case 2:
1417                 r->out.validation->sam2 = TALLOC_ZERO_P(p->mem_ctx, struct netr_SamInfo2);
1418                 if (!r->out.validation->sam2) {
1419                         return NT_STATUS_NO_MEMORY;
1420                 }
1421                 break;
1422         case 3:
1423                 r->out.validation->sam3 = TALLOC_ZERO_P(p->mem_ctx, struct netr_SamInfo3);
1424                 if (!r->out.validation->sam3) {
1425                         return NT_STATUS_NO_MEMORY;
1426                 }
1427                 break;
1428         case 6:
1429                 r->out.validation->sam6 = TALLOC_ZERO_P(p->mem_ctx, struct netr_SamInfo6);
1430                 if (!r->out.validation->sam6) {
1431                         return NT_STATUS_NO_MEMORY;
1432                 }
1433                 break;
1434         default:
1435                 DEBUG(0,("%s: bad validation_level value %d.\n",
1436                         fn, (int)r->in.validation_level));
1437                 return NT_STATUS_INVALID_INFO_CLASS;
1438         }
1439
1440         switch (r->in.logon_level) {
1441         case NetlogonInteractiveInformation:
1442         case NetlogonServiceInformation:
1443         case NetlogonInteractiveTransitiveInformation:
1444         case NetlogonServiceTransitiveInformation:
1445                 nt_username     = logon->password->identity_info.account_name.string ?
1446                                   logon->password->identity_info.account_name.string : "";
1447                 nt_domain       = logon->password->identity_info.domain_name.string ?
1448                                   logon->password->identity_info.domain_name.string : "";
1449                 nt_workstation  = logon->password->identity_info.workstation.string ?
1450                                   logon->password->identity_info.workstation.string : "";
1451
1452                 DEBUG(3,("SAM Logon (Interactive). Domain:[%s].  ", lp_workgroup()));
1453                 break;
1454         case NetlogonNetworkInformation:
1455         case NetlogonNetworkTransitiveInformation:
1456                 nt_username     = logon->network->identity_info.account_name.string ?
1457                                   logon->network->identity_info.account_name.string : "";
1458                 nt_domain       = logon->network->identity_info.domain_name.string ?
1459                                   logon->network->identity_info.domain_name.string : "";
1460                 nt_workstation  = logon->network->identity_info.workstation.string ?
1461                                   logon->network->identity_info.workstation.string : "";
1462
1463                 DEBUG(3,("SAM Logon (Network). Domain:[%s].  ", lp_workgroup()));
1464                 break;
1465         default:
1466                 DEBUG(2,("SAM Logon: unsupported switch value\n"));
1467                 return NT_STATUS_INVALID_INFO_CLASS;
1468         } /* end switch */
1469
1470         DEBUG(3,("User:[%s@%s] Requested Domain:[%s]\n", nt_username, nt_workstation, nt_domain));
1471         fstrcpy(current_user_info.smb_name, nt_username);
1472         sub_set_smb_name(nt_username);
1473
1474         DEBUG(5,("Attempting validation level %d for unmapped username %s.\n",
1475                 r->in.validation_level, nt_username));
1476
1477         status = NT_STATUS_OK;
1478
1479         switch (r->in.logon_level) {
1480         case NetlogonNetworkInformation:
1481         case NetlogonNetworkTransitiveInformation:
1482         {
1483                 const char *wksname = nt_workstation;
1484
1485                 status = make_auth_context_fixed(talloc_tos(), &auth_context,
1486                                                  logon->network->challenge);
1487                 if (!NT_STATUS_IS_OK(status)) {
1488                         return status;
1489                 }
1490
1491                 /* For a network logon, the workstation name comes in with two
1492                  * backslashes in the front. Strip them if they are there. */
1493
1494                 if (*wksname == '\\') wksname++;
1495                 if (*wksname == '\\') wksname++;
1496
1497                 /* Standard challenge/response authentication */
1498                 if (!make_user_info_netlogon_network(&user_info,
1499                                                      nt_username, nt_domain,
1500                                                      wksname,
1501                                                      logon->network->identity_info.parameter_control,
1502                                                      logon->network->lm.data,
1503                                                      logon->network->lm.length,
1504                                                      logon->network->nt.data,
1505                                                      logon->network->nt.length)) {
1506                         status = NT_STATUS_NO_MEMORY;
1507                 }
1508                 break;
1509         }
1510         case NetlogonInteractiveInformation:
1511         case NetlogonServiceInformation:
1512         case NetlogonInteractiveTransitiveInformation:
1513         case NetlogonServiceTransitiveInformation:
1514
1515                 /* 'Interactive' authentication, supplies the password in its
1516                    MD4 form, encrypted with the session key.  We will convert
1517                    this to challenge/response for the auth subsystem to chew
1518                    on */
1519         {
1520                 uint8_t chal[8];
1521
1522                 status = make_auth_context_subsystem(talloc_tos(),
1523                                                      &auth_context);
1524                 if (!NT_STATUS_IS_OK(status)) {
1525                         return status;
1526                 }
1527
1528                 auth_context->get_ntlm_challenge(auth_context, chal);
1529
1530                 if (!make_user_info_netlogon_interactive(&user_info,
1531                                                          nt_username, nt_domain,
1532                                                          nt_workstation,
1533                                                          logon->password->identity_info.parameter_control,
1534                                                          chal,
1535                                                          logon->password->lmpassword.hash,
1536                                                          logon->password->ntpassword.hash,
1537                                                          creds->session_key)) {
1538                         status = NT_STATUS_NO_MEMORY;
1539                 }
1540                 break;
1541         }
1542         default:
1543                 DEBUG(2,("SAM Logon: unsupported switch value\n"));
1544                 return NT_STATUS_INVALID_INFO_CLASS;
1545         } /* end switch */
1546
1547         if ( NT_STATUS_IS_OK(status) ) {
1548                 status = auth_context->check_ntlm_password(auth_context,
1549                         user_info, &server_info);
1550         }
1551
1552         TALLOC_FREE(auth_context);
1553         free_user_info(&user_info);
1554
1555         DEBUG(5,("%s: check_password returned status %s\n",
1556                   fn, nt_errstr(status)));
1557
1558         /* Check account and password */
1559
1560         if (!NT_STATUS_IS_OK(status)) {
1561                 /* If we don't know what this domain is, we need to
1562                    indicate that we are not authoritative.  This
1563                    allows the client to decide if it needs to try
1564                    a local user.  Fix by jpjanosi@us.ibm.com, #2976 */
1565                 if ( NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_USER)
1566                      && !strequal(nt_domain, get_global_sam_name())
1567                      && !is_trusted_domain(nt_domain) )
1568                         *r->out.authoritative = false; /* We are not authoritative */
1569
1570                 TALLOC_FREE(server_info);
1571                 return status;
1572         }
1573
1574         if (server_info->guest) {
1575                 /* We don't like guest domain logons... */
1576                 DEBUG(5,("%s: Attempted domain logon as GUEST "
1577                          "denied.\n", fn));
1578                 TALLOC_FREE(server_info);
1579                 return NT_STATUS_LOGON_FAILURE;
1580         }
1581
1582         /* This is the point at which, if the login was successful, that
1583            the SAM Local Security Authority should record that the user is
1584            logged in to the domain.  */
1585
1586         if (process_creds) {
1587                 /* Get the pipe session key from the creds. */
1588                 memcpy(pipe_session_key, creds->session_key, 16);
1589         } else {
1590                 struct schannel_state *schannel_auth;
1591                 /* Get the pipe session key from the schannel. */
1592                 if ((p->auth.auth_type != DCERPC_AUTH_TYPE_SCHANNEL)
1593                     || (p->auth.auth_ctx == NULL)) {
1594                         return NT_STATUS_INVALID_HANDLE;
1595                 }
1596
1597                 schannel_auth = talloc_get_type_abort(p->auth.auth_ctx,
1598                                                       struct schannel_state);
1599                 memcpy(pipe_session_key, schannel_auth->creds->session_key, 16);
1600         }
1601
1602         switch (r->in.validation_level) {
1603         case 2:
1604                 status = serverinfo_to_SamInfo2(server_info, pipe_session_key, 16,
1605                                                 r->out.validation->sam2);
1606                 break;
1607         case 3:
1608                 status = serverinfo_to_SamInfo3(server_info, pipe_session_key, 16,
1609                                                 r->out.validation->sam3);
1610                 break;
1611         case 6:
1612                 status = serverinfo_to_SamInfo6(server_info, pipe_session_key, 16,
1613                                                 r->out.validation->sam6);
1614                 break;
1615         }
1616
1617         TALLOC_FREE(server_info);
1618
1619         return status;
1620 }
1621
1622 /****************************************************************
1623  _netr_LogonSamLogonWithFlags
1624 ****************************************************************/
1625
1626 NTSTATUS _netr_LogonSamLogonWithFlags(struct pipes_struct *p,
1627                                       struct netr_LogonSamLogonWithFlags *r)
1628 {
1629         NTSTATUS status;
1630         struct netlogon_creds_CredentialState *creds;
1631         struct netr_LogonSamLogonEx r2;
1632         struct netr_Authenticator return_authenticator;
1633
1634         *r->out.authoritative = true;
1635
1636         r2.in.server_name       = r->in.server_name;
1637         r2.in.computer_name     = r->in.computer_name;
1638         r2.in.logon_level       = r->in.logon_level;
1639         r2.in.logon             = r->in.logon;
1640         r2.in.validation_level  = r->in.validation_level;
1641         r2.in.flags             = r->in.flags;
1642         r2.out.validation       = r->out.validation;
1643         r2.out.authoritative    = r->out.authoritative;
1644         r2.out.flags            = r->out.flags;
1645
1646         status = _netr_LogonSamLogon_check(&r2);
1647         if (!NT_STATUS_IS_OK(status)) {
1648                 return status;
1649         }
1650
1651         become_root();
1652         status = netr_creds_server_step_check(p, p->mem_ctx,
1653                                               r->in.computer_name,
1654                                               r->in.credential,
1655                                               &return_authenticator,
1656                                               &creds);
1657         unbecome_root();
1658         if (!NT_STATUS_IS_OK(status)) {
1659                 return status;
1660         }
1661
1662         status = _netr_LogonSamLogon_base(p, &r2, creds);
1663
1664         *r->out.return_authenticator = return_authenticator;
1665
1666         return status;
1667 }
1668
1669 /*************************************************************************
1670  _netr_LogonSamLogon
1671  *************************************************************************/
1672
1673 NTSTATUS _netr_LogonSamLogon(struct pipes_struct *p,
1674                              struct netr_LogonSamLogon *r)
1675 {
1676         NTSTATUS status;
1677         struct netr_LogonSamLogonWithFlags r2;
1678         uint32_t flags = 0;
1679
1680         r2.in.server_name               = r->in.server_name;
1681         r2.in.computer_name             = r->in.computer_name;
1682         r2.in.credential                = r->in.credential;
1683         r2.in.logon_level               = r->in.logon_level;
1684         r2.in.logon                     = r->in.logon;
1685         r2.in.validation_level          = r->in.validation_level;
1686         r2.in.return_authenticator      = r->in.return_authenticator;
1687         r2.in.flags                     = &flags;
1688         r2.out.validation               = r->out.validation;
1689         r2.out.authoritative            = r->out.authoritative;
1690         r2.out.flags                    = &flags;
1691         r2.out.return_authenticator     = r->out.return_authenticator;
1692
1693         status = _netr_LogonSamLogonWithFlags(p, &r2);
1694
1695         return status;
1696 }
1697
1698 /*************************************************************************
1699  _netr_LogonSamLogonEx
1700  - no credential chaining. Map into net sam logon.
1701  *************************************************************************/
1702
1703 NTSTATUS _netr_LogonSamLogonEx(struct pipes_struct *p,
1704                                struct netr_LogonSamLogonEx *r)
1705 {
1706         NTSTATUS status;
1707         struct netlogon_creds_CredentialState *creds = NULL;
1708
1709         *r->out.authoritative = true;
1710
1711         status = _netr_LogonSamLogon_check(r);
1712         if (!NT_STATUS_IS_OK(status)) {
1713                 return status;
1714         }
1715
1716         /* Only allow this if the pipe is protected. */
1717         if (p->auth.auth_type != DCERPC_AUTH_TYPE_SCHANNEL) {
1718                 DEBUG(0,("_netr_LogonSamLogonEx: client %s not using schannel for netlogon\n",
1719                         get_remote_machine_name() ));
1720                 return NT_STATUS_INVALID_PARAMETER;
1721         }
1722
1723         become_root();
1724         status = schannel_get_creds_state(p->mem_ctx, lp_private_dir(),
1725                                           r->in.computer_name, &creds);
1726         unbecome_root();
1727         if (!NT_STATUS_IS_OK(status)) {
1728                 return status;
1729         }
1730
1731         status = _netr_LogonSamLogon_base(p, r, creds);
1732         TALLOC_FREE(creds);
1733
1734         return status;
1735 }
1736
1737 /*************************************************************************
1738  _ds_enum_dom_trusts
1739  *************************************************************************/
1740 #if 0   /* JERRY -- not correct */
1741  NTSTATUS _ds_enum_dom_trusts(struct pipes_struct *p, DS_Q_ENUM_DOM_TRUSTS *q_u,
1742                              DS_R_ENUM_DOM_TRUSTS *r_u)
1743 {
1744         NTSTATUS status = NT_STATUS_OK;
1745
1746         /* TODO: According to MSDN, the can only be executed against a
1747            DC or domain member running Windows 2000 or later.  Need
1748            to test against a standalone 2k server and see what it
1749            does.  A windows 2000 DC includes its own domain in the
1750            list.  --jerry */
1751
1752         return status;
1753 }
1754 #endif  /* JERRY */
1755
1756
1757 /****************************************************************
1758 ****************************************************************/
1759
1760 WERROR _netr_LogonUasLogon(struct pipes_struct *p,
1761                            struct netr_LogonUasLogon *r)
1762 {
1763         p->rng_fault_state = true;
1764         return WERR_NOT_SUPPORTED;
1765 }
1766
1767 /****************************************************************
1768 ****************************************************************/
1769
1770 WERROR _netr_LogonUasLogoff(struct pipes_struct *p,
1771                             struct netr_LogonUasLogoff *r)
1772 {
1773         p->rng_fault_state = true;
1774         return WERR_NOT_SUPPORTED;
1775 }
1776
1777 /****************************************************************
1778 ****************************************************************/
1779
1780 NTSTATUS _netr_DatabaseDeltas(struct pipes_struct *p,
1781                               struct netr_DatabaseDeltas *r)
1782 {
1783         p->rng_fault_state = true;
1784         return NT_STATUS_NOT_IMPLEMENTED;
1785 }
1786
1787 /****************************************************************
1788 ****************************************************************/
1789
1790 NTSTATUS _netr_DatabaseSync(struct pipes_struct *p,
1791                             struct netr_DatabaseSync *r)
1792 {
1793         p->rng_fault_state = true;
1794         return NT_STATUS_NOT_IMPLEMENTED;
1795 }
1796
1797 /****************************************************************
1798 ****************************************************************/
1799
1800 NTSTATUS _netr_AccountDeltas(struct pipes_struct *p,
1801                              struct netr_AccountDeltas *r)
1802 {
1803         p->rng_fault_state = true;
1804         return NT_STATUS_NOT_IMPLEMENTED;
1805 }
1806
1807 /****************************************************************
1808 ****************************************************************/
1809
1810 NTSTATUS _netr_AccountSync(struct pipes_struct *p,
1811                            struct netr_AccountSync *r)
1812 {
1813         p->rng_fault_state = true;
1814         return NT_STATUS_NOT_IMPLEMENTED;
1815 }
1816
1817 /****************************************************************
1818 ****************************************************************/
1819
1820 static bool wb_getdcname(TALLOC_CTX *mem_ctx,
1821                          const char *domain,
1822                          const char **dcname,
1823                          uint32_t flags,
1824                          WERROR *werr)
1825 {
1826         wbcErr result;
1827         struct wbcDomainControllerInfo *dc_info = NULL;
1828
1829         result = wbcLookupDomainController(domain,
1830                                            flags,
1831                                            &dc_info);
1832         switch (result) {
1833         case WBC_ERR_SUCCESS:
1834                 break;
1835         case WBC_ERR_WINBIND_NOT_AVAILABLE:
1836                 return false;
1837         case WBC_ERR_DOMAIN_NOT_FOUND:
1838                 *werr = WERR_NO_SUCH_DOMAIN;
1839                 return true;
1840         default:
1841                 *werr = WERR_DOMAIN_CONTROLLER_NOT_FOUND;
1842                 return true;
1843         }
1844
1845         *dcname = talloc_strdup(mem_ctx, dc_info->dc_name);
1846         wbcFreeMemory(dc_info);
1847         if (!*dcname) {
1848                 *werr = WERR_NOMEM;
1849                 return false;
1850         }
1851
1852         *werr = WERR_OK;
1853
1854         return true;
1855 }
1856
1857 /****************************************************************
1858  _netr_GetDcName
1859 ****************************************************************/
1860
1861 WERROR _netr_GetDcName(struct pipes_struct *p,
1862                        struct netr_GetDcName *r)
1863 {
1864         NTSTATUS status;
1865         WERROR werr;
1866         uint32_t flags;
1867         struct netr_DsRGetDCNameInfo *info;
1868         bool ret;
1869
1870         ret = wb_getdcname(p->mem_ctx,
1871                            r->in.domainname,
1872                            r->out.dcname,
1873                            WBC_LOOKUP_DC_IS_FLAT_NAME |
1874                            WBC_LOOKUP_DC_RETURN_FLAT_NAME |
1875                            WBC_LOOKUP_DC_PDC_REQUIRED,
1876                            &werr);
1877         if (ret == true) {
1878                 return werr;
1879         }
1880
1881         flags = DS_PDC_REQUIRED | DS_IS_FLAT_NAME | DS_RETURN_FLAT_NAME;
1882
1883         status = dsgetdcname(p->mem_ctx,
1884                              p->msg_ctx,
1885                              r->in.domainname,
1886                              NULL,
1887                              NULL,
1888                              flags,
1889                              &info);
1890         if (!NT_STATUS_IS_OK(status)) {
1891                 return ntstatus_to_werror(status);
1892         }
1893
1894         *r->out.dcname = talloc_strdup(p->mem_ctx, info->dc_unc);
1895         talloc_free(info);
1896         if (!*r->out.dcname) {
1897                 return WERR_NOMEM;
1898         }
1899
1900         return WERR_OK;
1901 }
1902
1903 /****************************************************************
1904  _netr_GetAnyDCName
1905 ****************************************************************/
1906
1907 WERROR _netr_GetAnyDCName(struct pipes_struct *p,
1908                           struct netr_GetAnyDCName *r)
1909 {
1910         NTSTATUS status;
1911         WERROR werr;
1912         uint32_t flags;
1913         struct netr_DsRGetDCNameInfo *info;
1914         bool ret;
1915
1916         ret = wb_getdcname(p->mem_ctx,
1917                            r->in.domainname,
1918                            r->out.dcname,
1919                            WBC_LOOKUP_DC_IS_FLAT_NAME |
1920                            WBC_LOOKUP_DC_RETURN_FLAT_NAME,
1921                            &werr);
1922         if (ret == true) {
1923                 return werr;
1924         }
1925
1926         flags = DS_IS_FLAT_NAME | DS_RETURN_FLAT_NAME;
1927
1928         status = dsgetdcname(p->mem_ctx,
1929                              p->msg_ctx,
1930                              r->in.domainname,
1931                              NULL,
1932                              NULL,
1933                              flags,
1934                              &info);
1935         if (!NT_STATUS_IS_OK(status)) {
1936                 return ntstatus_to_werror(status);
1937         }
1938
1939         *r->out.dcname = talloc_strdup(p->mem_ctx, info->dc_unc);
1940         talloc_free(info);
1941         if (!*r->out.dcname) {
1942                 return WERR_NOMEM;
1943         }
1944
1945         return WERR_OK;
1946 }
1947
1948 /****************************************************************
1949 ****************************************************************/
1950
1951 NTSTATUS _netr_DatabaseSync2(struct pipes_struct *p,
1952                              struct netr_DatabaseSync2 *r)
1953 {
1954         p->rng_fault_state = true;
1955         return NT_STATUS_NOT_IMPLEMENTED;
1956 }
1957
1958 /****************************************************************
1959 ****************************************************************/
1960
1961 NTSTATUS _netr_DatabaseRedo(struct pipes_struct *p,
1962                             struct netr_DatabaseRedo *r)
1963 {
1964         p->rng_fault_state = true;
1965         return NT_STATUS_NOT_IMPLEMENTED;
1966 }
1967
1968 /****************************************************************
1969 ****************************************************************/
1970
1971 WERROR _netr_DsRGetDCName(struct pipes_struct *p,
1972                           struct netr_DsRGetDCName *r)
1973 {
1974         p->rng_fault_state = true;
1975         return WERR_NOT_SUPPORTED;
1976 }
1977
1978 /****************************************************************
1979 ****************************************************************/
1980
1981 NTSTATUS _netr_LogonGetCapabilities(struct pipes_struct *p,
1982                                     struct netr_LogonGetCapabilities *r)
1983 {
1984         return NT_STATUS_NOT_IMPLEMENTED;
1985 }
1986
1987 /****************************************************************
1988 ****************************************************************/
1989
1990 WERROR _netr_NETRLOGONSETSERVICEBITS(struct pipes_struct *p,
1991                                      struct netr_NETRLOGONSETSERVICEBITS *r)
1992 {
1993         p->rng_fault_state = true;
1994         return WERR_NOT_SUPPORTED;
1995 }
1996
1997 /****************************************************************
1998 ****************************************************************/
1999
2000 WERROR _netr_LogonGetTrustRid(struct pipes_struct *p,
2001                               struct netr_LogonGetTrustRid *r)
2002 {
2003         p->rng_fault_state = true;
2004         return WERR_NOT_SUPPORTED;
2005 }
2006
2007 /****************************************************************
2008 ****************************************************************/
2009
2010 WERROR _netr_NETRLOGONCOMPUTESERVERDIGEST(struct pipes_struct *p,
2011                                           struct netr_NETRLOGONCOMPUTESERVERDIGEST *r)
2012 {
2013         p->rng_fault_state = true;
2014         return WERR_NOT_SUPPORTED;
2015 }
2016
2017 /****************************************************************
2018 ****************************************************************/
2019
2020 WERROR _netr_NETRLOGONCOMPUTECLIENTDIGEST(struct pipes_struct *p,
2021                                           struct netr_NETRLOGONCOMPUTECLIENTDIGEST *r)
2022 {
2023         p->rng_fault_state = true;
2024         return WERR_NOT_SUPPORTED;
2025 }
2026
2027 /****************************************************************
2028 ****************************************************************/
2029
2030 WERROR _netr_DsRGetDCNameEx(struct pipes_struct *p,
2031                             struct netr_DsRGetDCNameEx *r)
2032 {
2033         p->rng_fault_state = true;
2034         return WERR_NOT_SUPPORTED;
2035 }
2036
2037 /****************************************************************
2038 ****************************************************************/
2039
2040 WERROR _netr_DsRGetSiteName(struct pipes_struct *p,
2041                             struct netr_DsRGetSiteName *r)
2042 {
2043         p->rng_fault_state = true;
2044         return WERR_NOT_SUPPORTED;
2045 }
2046
2047 /****************************************************************
2048 ****************************************************************/
2049
2050 NTSTATUS _netr_LogonGetDomainInfo(struct pipes_struct *p,
2051                                   struct netr_LogonGetDomainInfo *r)
2052 {
2053         p->rng_fault_state = true;
2054         return NT_STATUS_NOT_IMPLEMENTED;
2055 }
2056
2057 /****************************************************************
2058 ****************************************************************/
2059
2060 WERROR _netr_ServerPasswordGet(struct pipes_struct *p,
2061                                struct netr_ServerPasswordGet *r)
2062 {
2063         p->rng_fault_state = true;
2064         return WERR_NOT_SUPPORTED;
2065 }
2066
2067 /****************************************************************
2068 ****************************************************************/
2069
2070 WERROR _netr_NETRLOGONSENDTOSAM(struct pipes_struct *p,
2071                                 struct netr_NETRLOGONSENDTOSAM *r)
2072 {
2073         p->rng_fault_state = true;
2074         return WERR_NOT_SUPPORTED;
2075 }
2076
2077 /****************************************************************
2078 ****************************************************************/
2079
2080 WERROR _netr_DsRAddressToSitenamesW(struct pipes_struct *p,
2081                                     struct netr_DsRAddressToSitenamesW *r)
2082 {
2083         p->rng_fault_state = true;
2084         return WERR_NOT_SUPPORTED;
2085 }
2086
2087 /****************************************************************
2088 ****************************************************************/
2089
2090 WERROR _netr_DsRGetDCNameEx2(struct pipes_struct *p,
2091                              struct netr_DsRGetDCNameEx2 *r)
2092 {
2093         p->rng_fault_state = true;
2094         return WERR_NOT_SUPPORTED;
2095 }
2096
2097 /****************************************************************
2098 ****************************************************************/
2099
2100 WERROR _netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN(struct pipes_struct *p,
2101                                                  struct netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN *r)
2102 {
2103         p->rng_fault_state = true;
2104         return WERR_NOT_SUPPORTED;
2105 }
2106
2107 /****************************************************************
2108 ****************************************************************/
2109
2110 WERROR _netr_NetrEnumerateTrustedDomainsEx(struct pipes_struct *p,
2111                                            struct netr_NetrEnumerateTrustedDomainsEx *r)
2112 {
2113         p->rng_fault_state = true;
2114         return WERR_NOT_SUPPORTED;
2115 }
2116
2117 /****************************************************************
2118 ****************************************************************/
2119
2120 WERROR _netr_DsRAddressToSitenamesExW(struct pipes_struct *p,
2121                                       struct netr_DsRAddressToSitenamesExW *r)
2122 {
2123         p->rng_fault_state = true;
2124         return WERR_NOT_SUPPORTED;
2125 }
2126
2127 /****************************************************************
2128 ****************************************************************/
2129
2130 WERROR _netr_DsrGetDcSiteCoverageW(struct pipes_struct *p,
2131                                    struct netr_DsrGetDcSiteCoverageW *r)
2132 {
2133         p->rng_fault_state = true;
2134         return WERR_NOT_SUPPORTED;
2135 }
2136
2137 /****************************************************************
2138 ****************************************************************/
2139
2140 WERROR _netr_DsrEnumerateDomainTrusts(struct pipes_struct *p,
2141                                       struct netr_DsrEnumerateDomainTrusts *r)
2142 {
2143         p->rng_fault_state = true;
2144         return WERR_NOT_SUPPORTED;
2145 }
2146
2147 /****************************************************************
2148 ****************************************************************/
2149
2150 WERROR _netr_DsrDeregisterDNSHostRecords(struct pipes_struct *p,
2151                                          struct netr_DsrDeregisterDNSHostRecords *r)
2152 {
2153         p->rng_fault_state = true;
2154         return WERR_NOT_SUPPORTED;
2155 }
2156
2157 /****************************************************************
2158 ****************************************************************/
2159
2160 NTSTATUS _netr_ServerTrustPasswordsGet(struct pipes_struct *p,
2161                                        struct netr_ServerTrustPasswordsGet *r)
2162 {
2163         p->rng_fault_state = true;
2164         return NT_STATUS_NOT_IMPLEMENTED;
2165 }
2166
2167 /****************************************************************
2168 ****************************************************************/
2169
2170 WERROR _netr_DsRGetForestTrustInformation(struct pipes_struct *p,
2171                                           struct netr_DsRGetForestTrustInformation *r)
2172 {
2173         p->rng_fault_state = true;
2174         return WERR_NOT_SUPPORTED;
2175 }
2176
2177 /****************************************************************
2178 ****************************************************************/
2179
2180 NTSTATUS _netr_GetForestTrustInformation(struct pipes_struct *p,
2181                                          struct netr_GetForestTrustInformation *r)
2182 {
2183         p->rng_fault_state = true;
2184         return NT_STATUS_NOT_IMPLEMENTED;
2185 }
2186
2187 /****************************************************************
2188 ****************************************************************/
2189
2190 NTSTATUS _netr_ServerGetTrustInfo(struct pipes_struct *p,
2191                                   struct netr_ServerGetTrustInfo *r)
2192 {
2193         p->rng_fault_state = true;
2194         return NT_STATUS_NOT_IMPLEMENTED;
2195 }
2196
2197 /****************************************************************
2198 ****************************************************************/
2199
2200 NTSTATUS _netr_Unused47(struct pipes_struct *p,
2201                         struct netr_Unused47 *r)
2202 {
2203         p->rng_fault_state = true;
2204         return NT_STATUS_NOT_IMPLEMENTED;
2205 }
2206
2207 /****************************************************************
2208 ****************************************************************/
2209
2210 NTSTATUS _netr_DsrUpdateReadOnlyServerDnsRecords(struct pipes_struct *p,
2211                                                  struct netr_DsrUpdateReadOnlyServerDnsRecords *r)
2212 {
2213         p->rng_fault_state = true;
2214         return NT_STATUS_NOT_IMPLEMENTED;
2215 }