s3-netlogon: use WERRORs in NETLOGON_INFO structures.
[ira/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.
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/libcli_auth.h"
29 #include "../libcli/auth/schannel_state.h"
30
31 extern userdom_struct current_user_info;
32
33 #undef DBGC_CLASS
34 #define DBGC_CLASS DBGC_RPC_SRV
35
36 struct netlogon_server_pipe_state {
37         struct netr_Credential client_challenge;
38         struct netr_Credential server_challenge;
39 };
40
41 /*************************************************************************
42  _netr_LogonControl
43  *************************************************************************/
44
45 WERROR _netr_LogonControl(pipes_struct *p,
46                           struct netr_LogonControl *r)
47 {
48         struct netr_LogonControl2Ex l;
49
50         switch (r->in.level) {
51         case 1:
52                 break;
53         case 2:
54                 return WERR_NOT_SUPPORTED;
55         default:
56                 return WERR_UNKNOWN_LEVEL;
57         }
58
59         l.in.logon_server       = r->in.logon_server;
60         l.in.function_code      = r->in.function_code;
61         l.in.level              = r->in.level;
62         l.in.data               = NULL;
63         l.out.query             = r->out.query;
64
65         return _netr_LogonControl2Ex(p, &l);
66 }
67
68 /****************************************************************************
69 Send a message to smbd to do a sam synchronisation
70 **************************************************************************/
71
72 static void send_sync_message(void)
73 {
74         DEBUG(3, ("sending sam synchronisation message\n"));
75         message_send_all(smbd_messaging_context(), MSG_SMB_SAM_SYNC, NULL, 0,
76                          NULL);
77 }
78
79 /*************************************************************************
80  _netr_LogonControl2
81  *************************************************************************/
82
83 WERROR _netr_LogonControl2(pipes_struct *p,
84                            struct netr_LogonControl2 *r)
85 {
86         struct netr_LogonControl2Ex l;
87
88         l.in.logon_server       = r->in.logon_server;
89         l.in.function_code      = r->in.function_code;
90         l.in.level              = r->in.level;
91         l.in.data               = r->in.data;
92         l.out.query             = r->out.query;
93
94         return _netr_LogonControl2Ex(p, &l);
95 }
96
97 /****************************************************************
98  _netr_LogonControl2Ex
99 ****************************************************************/
100
101 WERROR _netr_LogonControl2Ex(pipes_struct *p,
102                              struct netr_LogonControl2Ex *r)
103 {
104         uint32_t flags = 0x0;
105         WERROR pdc_connection_status = WERR_OK;
106         uint32_t logon_attempts = 0x0;
107         WERROR tc_status;
108         fstring dc_name2;
109         const char *dc_name = NULL;
110         struct sockaddr_storage dc_ss;
111         const char *domain = NULL;
112         struct netr_NETLOGON_INFO_1 *info1;
113         struct netr_NETLOGON_INFO_2 *info2;
114         struct netr_NETLOGON_INFO_3 *info3;
115         const char *fn;
116
117         switch (p->hdr_req.opnum) {
118                 case NDR_NETR_LOGONCONTROL:
119                         fn = "_netr_LogonControl";
120                         break;
121                 case NDR_NETR_LOGONCONTROL2:
122                         fn = "_netr_LogonControl2";
123                         break;
124                 case NDR_NETR_LOGONCONTROL2EX:
125                         fn = "_netr_LogonControl2Ex";
126                         break;
127                 default:
128                         return WERR_INVALID_PARAM;
129         }
130
131         tc_status = WERR_NO_SUCH_DOMAIN;
132
133         switch (r->in.function_code) {
134                 case NETLOGON_CONTROL_TC_QUERY:
135                         domain = r->in.data->domain;
136
137                         if ( !is_trusted_domain( domain ) )
138                                 break;
139
140                         if ( !get_dc_name( domain, NULL, dc_name2, &dc_ss ) ) {
141                                 tc_status = WERR_NO_LOGON_SERVERS;
142                                 break;
143                         }
144
145                         dc_name = talloc_asprintf(p->mem_ctx, "\\\\%s", dc_name2);
146                         if (!dc_name) {
147                                 return WERR_NOMEM;
148                         }
149
150                         tc_status = WERR_OK;
151
152                         break;
153
154                 case NETLOGON_CONTROL_REDISCOVER:
155                         domain = r->in.data->domain;
156
157                         if ( !is_trusted_domain( domain ) )
158                                 break;
159
160                         if ( !get_dc_name( domain, NULL, dc_name2, &dc_ss ) ) {
161                                 tc_status = WERR_NO_LOGON_SERVERS;
162                                 break;
163                         }
164
165                         dc_name = talloc_asprintf(p->mem_ctx, "\\\\%s", dc_name2);
166                         if (!dc_name) {
167                                 return WERR_NOMEM;
168                         }
169
170                         tc_status = WERR_OK;
171
172                         break;
173
174                 default:
175                         /* no idea what this should be */
176                         DEBUG(0,("%s: unimplemented function level [%d]\n",
177                                 fn, r->in.function_code));
178                         return WERR_UNKNOWN_LEVEL;
179         }
180
181         /* prepare the response */
182
183         switch (r->in.level) {
184                 case 1:
185                         info1 = TALLOC_ZERO_P(p->mem_ctx, struct netr_NETLOGON_INFO_1);
186                         W_ERROR_HAVE_NO_MEMORY(info1);
187
188                         info1->flags                    = flags;
189                         info1->pdc_connection_status    = pdc_connection_status;
190
191                         r->out.query->info1 = info1;
192                         break;
193                 case 2:
194                         info2 = TALLOC_ZERO_P(p->mem_ctx, struct netr_NETLOGON_INFO_2);
195                         W_ERROR_HAVE_NO_MEMORY(info2);
196
197                         info2->flags                    = flags;
198                         info2->pdc_connection_status    = pdc_connection_status;
199                         info2->trusted_dc_name          = dc_name;
200                         info2->tc_connection_status     = tc_status;
201
202                         r->out.query->info2 = info2;
203                         break;
204                 case 3:
205                         info3 = TALLOC_ZERO_P(p->mem_ctx, struct netr_NETLOGON_INFO_3);
206                         W_ERROR_HAVE_NO_MEMORY(info3);
207
208                         info3->flags                    = flags;
209                         info3->logon_attempts           = logon_attempts;
210
211                         r->out.query->info3 = info3;
212                         break;
213                 default:
214                         return WERR_UNKNOWN_LEVEL;
215         }
216
217         if (lp_server_role() == ROLE_DOMAIN_BDC) {
218                 send_sync_message();
219         }
220
221         return WERR_OK;
222 }
223
224 /*************************************************************************
225  _netr_NetrEnumerateTrustedDomains
226  *************************************************************************/
227
228 WERROR _netr_NetrEnumerateTrustedDomains(pipes_struct *p,
229                                          struct netr_NetrEnumerateTrustedDomains *r)
230 {
231         struct netr_Blob trusted_domains_blob;
232         DATA_BLOB blob;
233
234         DEBUG(6,("_netr_NetrEnumerateTrustedDomains: %d\n", __LINE__));
235
236         /* set up the Trusted Domain List response */
237
238         blob = data_blob_talloc_zero(p->mem_ctx, 2);
239         trusted_domains_blob.data = blob.data;
240         trusted_domains_blob.length = blob.length;
241
242         DEBUG(6,("_netr_NetrEnumerateTrustedDomains: %d\n", __LINE__));
243
244         *r->out.trusted_domains_blob = trusted_domains_blob;
245
246         return WERR_OK;
247 }
248
249 /******************************************************************
250  gets a machine password entry.  checks access rights of the host.
251  ******************************************************************/
252
253 static NTSTATUS get_md4pw(struct samr_Password *md4pw, const char *mach_acct,
254                           uint16_t sec_chan_type, struct dom_sid *sid)
255 {
256         struct samu *sampass = NULL;
257         const uint8 *pass;
258         bool ret;
259         uint32 acct_ctrl;
260
261 #if 0
262         char addr[INET6_ADDRSTRLEN];
263
264     /*
265      * Currently this code is redundent as we already have a filter
266      * by hostname list. What this code really needs to do is to
267      * get a hosts allowed/hosts denied list from the SAM database
268      * on a per user basis, and make the access decision there.
269      * I will leave this code here for now as a reminder to implement
270      * this at a later date. JRA.
271      */
272
273         if (!allow_access(lp_domain_hostsdeny(), lp_domain_hostsallow(),
274                         client_name(get_client_fd()),
275                         client_addr(get_client_fd(),addr,sizeof(addr)))) {
276                 DEBUG(0,("get_md4pw: Workstation %s denied access to domain\n", mach_acct));
277                 return False;
278         }
279 #endif /* 0 */
280
281         if ( !(sampass = samu_new( NULL )) ) {
282                 return NT_STATUS_NO_MEMORY;
283         }
284
285         /* JRA. This is ok as it is only used for generating the challenge. */
286         become_root();
287         ret = pdb_getsampwnam(sampass, mach_acct);
288         unbecome_root();
289
290         if (!ret) {
291                 DEBUG(0,("get_md4pw: Workstation %s: no account in domain\n", mach_acct));
292                 TALLOC_FREE(sampass);
293                 return NT_STATUS_ACCESS_DENIED;
294         }
295
296         acct_ctrl = pdb_get_acct_ctrl(sampass);
297         if (acct_ctrl & ACB_DISABLED) {
298                 DEBUG(0,("get_md4pw: Workstation %s: account is disabled\n", mach_acct));
299                 TALLOC_FREE(sampass);
300                 return NT_STATUS_ACCOUNT_DISABLED;
301         }
302
303         if (!(acct_ctrl & ACB_SVRTRUST) &&
304             !(acct_ctrl & ACB_WSTRUST) &&
305             !(acct_ctrl & ACB_DOMTRUST))
306         {
307                 DEBUG(0,("get_md4pw: Workstation %s: account is not a trust account\n", mach_acct));
308                 TALLOC_FREE(sampass);
309                 return NT_STATUS_NO_TRUST_SAM_ACCOUNT;
310         }
311
312         switch (sec_chan_type) {
313                 case SEC_CHAN_BDC:
314                         if (!(acct_ctrl & ACB_SVRTRUST)) {
315                                 DEBUG(0,("get_md4pw: Workstation %s: BDC secure channel requested "
316                                          "but not a server trust account\n", mach_acct));
317                                 TALLOC_FREE(sampass);
318                                 return NT_STATUS_NO_TRUST_SAM_ACCOUNT;
319                         }
320                         break;
321                 case SEC_CHAN_WKSTA:
322                         if (!(acct_ctrl & ACB_WSTRUST)) {
323                                 DEBUG(0,("get_md4pw: Workstation %s: WORKSTATION secure channel requested "
324                                          "but not a workstation trust account\n", mach_acct));
325                                 TALLOC_FREE(sampass);
326                                 return NT_STATUS_NO_TRUST_SAM_ACCOUNT;
327                         }
328                         break;
329                 case SEC_CHAN_DOMAIN:
330                         if (!(acct_ctrl & ACB_DOMTRUST)) {
331                                 DEBUG(0,("get_md4pw: Workstation %s: DOMAIN secure channel requested "
332                                          "but not a interdomain trust account\n", mach_acct));
333                                 TALLOC_FREE(sampass);
334                                 return NT_STATUS_NO_TRUST_SAM_ACCOUNT;
335                         }
336                         break;
337                 default:
338                         break;
339         }
340
341         if ((pass = pdb_get_nt_passwd(sampass)) == NULL) {
342                 DEBUG(0,("get_md4pw: Workstation %s: account does not have a password\n", mach_acct));
343                 TALLOC_FREE(sampass);
344                 return NT_STATUS_LOGON_FAILURE;
345         }
346
347         memcpy(md4pw->hash, pass, 16);
348         dump_data(5, md4pw->hash, 16);
349
350         sid_copy(sid, pdb_get_user_sid(sampass));
351
352         TALLOC_FREE(sampass);
353
354         return NT_STATUS_OK;
355
356
357 }
358
359 /*************************************************************************
360  _netr_ServerReqChallenge
361  *************************************************************************/
362
363 NTSTATUS _netr_ServerReqChallenge(pipes_struct *p,
364                                   struct netr_ServerReqChallenge *r)
365 {
366         struct netlogon_server_pipe_state *pipe_state =
367                 talloc_get_type(p->private_data, struct netlogon_server_pipe_state);
368
369         if (pipe_state) {
370                 DEBUG(10,("_netr_ServerReqChallenge: new challenge requested. Clearing old state.\n"));
371                 talloc_free(pipe_state);
372                 p->private_data = NULL;
373         }
374
375         pipe_state = talloc(p, struct netlogon_server_pipe_state);
376         NT_STATUS_HAVE_NO_MEMORY(pipe_state);
377
378         pipe_state->client_challenge = *r->in.credentials;
379
380         generate_random_buffer(pipe_state->server_challenge.data,
381                                sizeof(pipe_state->server_challenge.data));
382
383         *r->out.return_credentials = pipe_state->server_challenge;
384
385         p->private_data = pipe_state;
386
387         return NT_STATUS_OK;
388 }
389
390 /*************************************************************************
391  _netr_ServerAuthenticate
392  Create the initial credentials.
393  *************************************************************************/
394
395 NTSTATUS _netr_ServerAuthenticate(pipes_struct *p,
396                                   struct netr_ServerAuthenticate *r)
397 {
398         struct netr_ServerAuthenticate3 a;
399         uint32_t negotiate_flags = 0;
400         uint32_t rid;
401
402         a.in.server_name                = r->in.server_name;
403         a.in.account_name               = r->in.account_name;
404         a.in.secure_channel_type        = r->in.secure_channel_type;
405         a.in.computer_name              = r->in.computer_name;
406         a.in.credentials                = r->in.credentials;
407         a.in.negotiate_flags            = &negotiate_flags;
408
409         a.out.return_credentials        = r->out.return_credentials;
410         a.out.rid                       = &rid;
411         a.out.negotiate_flags           = &negotiate_flags;
412
413         return _netr_ServerAuthenticate3(p, &a);
414
415 }
416
417 /*************************************************************************
418  _netr_ServerAuthenticate3
419  *************************************************************************/
420
421 NTSTATUS _netr_ServerAuthenticate3(pipes_struct *p,
422                                    struct netr_ServerAuthenticate3 *r)
423 {
424         NTSTATUS status;
425         uint32_t srv_flgs;
426         /* r->in.negotiate_flags is an aliased pointer to r->out.negotiate_flags,
427          * so use a copy to avoid destroying the client values. */
428         uint32_t in_neg_flags = *r->in.negotiate_flags;
429         const char *fn;
430         struct dom_sid sid;
431         struct samr_Password mach_pwd;
432         struct netlogon_creds_CredentialState *creds;
433         struct netlogon_server_pipe_state *pipe_state =
434                 talloc_get_type(p->private_data, struct netlogon_server_pipe_state);
435
436         /* According to Microsoft (see bugid #6099)
437          * Windows 7 looks at the negotiate_flags
438          * returned in this structure *even if the
439          * call fails with access denied* ! So in order
440          * to allow Win7 to connect to a Samba NT style
441          * PDC we set the flags before we know if it's
442          * an error or not.
443          */
444
445         /* 0x000001ff */
446         srv_flgs = NETLOGON_NEG_ACCOUNT_LOCKOUT |
447                    NETLOGON_NEG_PERSISTENT_SAMREPL |
448                    NETLOGON_NEG_ARCFOUR |
449                    NETLOGON_NEG_PROMOTION_COUNT |
450                    NETLOGON_NEG_CHANGELOG_BDC |
451                    NETLOGON_NEG_FULL_SYNC_REPL |
452                    NETLOGON_NEG_MULTIPLE_SIDS |
453                    NETLOGON_NEG_REDO |
454                    NETLOGON_NEG_PASSWORD_CHANGE_REFUSAL |
455                    NETLOGON_NEG_PASSWORD_SET2;
456
457         /* Ensure we support strong (128-bit) keys. */
458         if (in_neg_flags & NETLOGON_NEG_STRONG_KEYS) {
459                 srv_flgs |= NETLOGON_NEG_STRONG_KEYS;
460         }
461
462         if (lp_server_schannel() != false) {
463                 srv_flgs |= NETLOGON_NEG_SCHANNEL;
464         }
465
466         switch (p->hdr_req.opnum) {
467                 case NDR_NETR_SERVERAUTHENTICATE:
468                         fn = "_netr_ServerAuthenticate";
469                         break;
470                 case NDR_NETR_SERVERAUTHENTICATE2:
471                         fn = "_netr_ServerAuthenticate2";
472                         break;
473                 case NDR_NETR_SERVERAUTHENTICATE3:
474                         fn = "_netr_ServerAuthenticate3";
475                         break;
476                 default:
477                         return NT_STATUS_INTERNAL_ERROR;
478         }
479
480         /* We use this as the key to store the creds: */
481         /* r->in.computer_name */
482
483         if (!pipe_state) {
484                 DEBUG(0,("%s: no challenge sent to client %s\n", fn,
485                         r->in.computer_name));
486                 status = NT_STATUS_ACCESS_DENIED;
487                 goto out;
488         }
489
490         if ( (lp_server_schannel() == true) &&
491              ((in_neg_flags & NETLOGON_NEG_SCHANNEL) == 0) ) {
492
493                 /* schannel must be used, but client did not offer it. */
494                 DEBUG(0,("%s: schannel required but client failed "
495                         "to offer it. Client was %s\n",
496                         fn, r->in.account_name));
497                 status = NT_STATUS_ACCESS_DENIED;
498                 goto out;
499         }
500
501         status = get_md4pw(&mach_pwd,
502                            r->in.account_name,
503                            r->in.secure_channel_type,
504                            &sid);
505         if (!NT_STATUS_IS_OK(status)) {
506                 DEBUG(0,("%s: failed to get machine password for "
507                         "account %s: %s\n",
508                         fn, r->in.account_name, nt_errstr(status) ));
509                 /* always return NT_STATUS_ACCESS_DENIED */
510                 status = NT_STATUS_ACCESS_DENIED;
511                 goto out;
512         }
513
514         /* From the client / server challenges and md4 password, generate sess key */
515         /* Check client credentials are valid. */
516         creds = netlogon_creds_server_init(p->mem_ctx,
517                                            r->in.account_name,
518                                            r->in.computer_name,
519                                            r->in.secure_channel_type,
520                                            &pipe_state->client_challenge,
521                                            &pipe_state->server_challenge,
522                                            &mach_pwd,
523                                            r->in.credentials,
524                                            r->out.return_credentials,
525                                            *r->in.negotiate_flags);
526         if (!creds) {
527                 DEBUG(0,("%s: netlogon_creds_server_check failed. Rejecting auth "
528                         "request from client %s machine account %s\n",
529                         fn, r->in.computer_name,
530                         r->in.account_name));
531                 status = NT_STATUS_ACCESS_DENIED;
532                 goto out;
533         }
534
535         creds->sid = sid_dup_talloc(creds, &sid);
536         if (!creds->sid) {
537                 status = NT_STATUS_NO_MEMORY;
538                 goto out;
539         }
540
541         /* Store off the state so we can continue after client disconnect. */
542         become_root();
543         status = schannel_store_session_key(p->mem_ctx, creds);
544         unbecome_root();
545
546         if (!NT_STATUS_IS_OK(status)) {
547                 goto out;
548         }
549
550         sid_peek_rid(&sid, r->out.rid);
551
552         status = NT_STATUS_OK;
553
554   out:
555
556         *r->out.negotiate_flags = srv_flgs;
557         return status;
558 }
559
560 /*************************************************************************
561  _netr_ServerAuthenticate2
562  *************************************************************************/
563
564 NTSTATUS _netr_ServerAuthenticate2(pipes_struct *p,
565                                    struct netr_ServerAuthenticate2 *r)
566 {
567         struct netr_ServerAuthenticate3 a;
568         uint32_t rid;
569
570         a.in.server_name                = r->in.server_name;
571         a.in.account_name               = r->in.account_name;
572         a.in.secure_channel_type        = r->in.secure_channel_type;
573         a.in.computer_name              = r->in.computer_name;
574         a.in.credentials                = r->in.credentials;
575         a.in.negotiate_flags            = r->in.negotiate_flags;
576
577         a.out.return_credentials        = r->out.return_credentials;
578         a.out.rid                       = &rid;
579         a.out.negotiate_flags           = r->out.negotiate_flags;
580
581         return _netr_ServerAuthenticate3(p, &a);
582 }
583
584 /*************************************************************************
585  *************************************************************************/
586
587 static NTSTATUS netr_creds_server_step_check(pipes_struct *p,
588                                              TALLOC_CTX *mem_ctx,
589                                              const char *computer_name,
590                                              struct netr_Authenticator *received_authenticator,
591                                              struct netr_Authenticator *return_authenticator,
592                                              struct netlogon_creds_CredentialState **creds_out)
593 {
594         NTSTATUS status;
595         struct tdb_context *tdb;
596         bool schannel_global_required = (lp_server_schannel() == true) ? true:false;
597         bool schannel_in_use = (p->auth.auth_type == PIPE_AUTH_TYPE_SCHANNEL) ? true:false; /* &&
598                 (p->auth.auth_level == PIPE_AUTH_LEVEL_INTEGRITY ||
599                  p->auth.auth_level == PIPE_AUTH_LEVEL_PRIVACY); */
600
601         tdb = open_schannel_session_store(mem_ctx);
602         if (!tdb) {
603                 return NT_STATUS_ACCESS_DENIED;
604         }
605
606         status = schannel_creds_server_step_check_tdb(tdb, mem_ctx,
607                                                       computer_name,
608                                                       schannel_global_required,
609                                                       schannel_in_use,
610                                                       received_authenticator,
611                                                       return_authenticator,
612                                                       creds_out);
613         tdb_close(tdb);
614
615         return status;
616 }
617
618 /*************************************************************************
619  *************************************************************************/
620
621 static NTSTATUS netr_find_machine_account(TALLOC_CTX *mem_ctx,
622                                           const char *account_name,
623                                           struct samu **sampassp)
624 {
625         struct samu *sampass;
626         bool ret = false;
627         uint32_t acct_ctrl;
628
629         sampass = samu_new(mem_ctx);
630         if (!sampass) {
631                 return NT_STATUS_NO_MEMORY;
632         }
633
634         become_root();
635         ret = pdb_getsampwnam(sampass, account_name);
636         unbecome_root();
637
638         if (!ret) {
639                 TALLOC_FREE(sampass);
640                 return NT_STATUS_ACCESS_DENIED;
641         }
642
643         /* Ensure the account exists and is a machine account. */
644
645         acct_ctrl = pdb_get_acct_ctrl(sampass);
646
647         if (!(acct_ctrl & ACB_WSTRUST ||
648               acct_ctrl & ACB_SVRTRUST ||
649               acct_ctrl & ACB_DOMTRUST)) {
650                 TALLOC_FREE(sampass);
651                 return NT_STATUS_NO_SUCH_USER;
652         }
653
654         if (acct_ctrl & ACB_DISABLED) {
655                 TALLOC_FREE(sampass);
656                 return NT_STATUS_ACCOUNT_DISABLED;
657         }
658
659         *sampassp = sampass;
660
661         return NT_STATUS_OK;
662 }
663
664 /*************************************************************************
665  *************************************************************************/
666
667 static NTSTATUS netr_set_machine_account_password(TALLOC_CTX *mem_ctx,
668                                                   struct samu *sampass,
669                                                   DATA_BLOB *plaintext_blob,
670                                                   struct samr_Password *nt_hash,
671                                                   struct samr_Password *lm_hash)
672 {
673         NTSTATUS status;
674         const uchar *old_pw;
675         const char *plaintext = NULL;
676         size_t plaintext_len;
677         struct samr_Password nt_hash_local;
678
679         if (!sampass) {
680                 return NT_STATUS_INVALID_PARAMETER;
681         }
682
683         if (plaintext_blob) {
684                 if (!convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX,
685                                            plaintext_blob->data, plaintext_blob->length,
686                                            &plaintext, &plaintext_len, false))
687                 {
688                         plaintext = NULL;
689                         mdfour(nt_hash_local.hash, plaintext_blob->data, plaintext_blob->length);
690                         nt_hash = &nt_hash_local;
691                 }
692         }
693
694         if (plaintext) {
695                 if (!pdb_set_plaintext_passwd(sampass, plaintext)) {
696                         return NT_STATUS_ACCESS_DENIED;
697                 }
698
699                 goto done;
700         }
701
702         if (nt_hash) {
703                 old_pw = pdb_get_nt_passwd(sampass);
704
705                 if (old_pw && memcmp(nt_hash->hash, old_pw, 16) == 0) {
706                         /* Avoid backend modificiations and other fun if the
707                            client changed the password to the *same thing* */
708                 } else {
709                         /* LM password should be NULL for machines */
710                         if (!pdb_set_lanman_passwd(sampass, NULL, PDB_CHANGED)) {
711                                 return NT_STATUS_NO_MEMORY;
712                         }
713                         if (!pdb_set_nt_passwd(sampass, nt_hash->hash, PDB_CHANGED)) {
714                                 return NT_STATUS_NO_MEMORY;
715                         }
716
717                         if (!pdb_set_pass_last_set_time(sampass, time(NULL), PDB_CHANGED)) {
718                                 /* Not quite sure what this one qualifies as, but this will do */
719                                 return NT_STATUS_UNSUCCESSFUL;
720                         }
721                 }
722         }
723
724  done:
725         become_root();
726         status = pdb_update_sam_account(sampass);
727         unbecome_root();
728
729         return status;
730 }
731
732 /*************************************************************************
733  _netr_ServerPasswordSet
734  *************************************************************************/
735
736 NTSTATUS _netr_ServerPasswordSet(pipes_struct *p,
737                                  struct netr_ServerPasswordSet *r)
738 {
739         NTSTATUS status = NT_STATUS_OK;
740         struct samu *sampass=NULL;
741         int i;
742         struct netlogon_creds_CredentialState *creds;
743
744         DEBUG(5,("_netr_ServerPasswordSet: %d\n", __LINE__));
745
746         become_root();
747         status = netr_creds_server_step_check(p, p->mem_ctx,
748                                               r->in.computer_name,
749                                               r->in.credential,
750                                               r->out.return_authenticator,
751                                               &creds);
752         unbecome_root();
753
754         if (!NT_STATUS_IS_OK(status)) {
755                 DEBUG(2,("_netr_ServerPasswordSet: netlogon_creds_server_step failed. Rejecting auth "
756                         "request from client %s machine account %s\n",
757                         r->in.computer_name, creds->computer_name));
758                 TALLOC_FREE(creds);
759                 return status;
760         }
761
762         DEBUG(3,("_netr_ServerPasswordSet: Server Password Set by remote machine:[%s] on account [%s]\n",
763                         r->in.computer_name, creds->computer_name));
764
765         netlogon_creds_des_decrypt(creds, r->in.new_password);
766
767         DEBUG(100,("_netr_ServerPasswordSet: new given value was :\n"));
768         for(i = 0; i < sizeof(r->in.new_password->hash); i++)
769                 DEBUG(100,("%02X ", r->in.new_password->hash[i]));
770         DEBUG(100,("\n"));
771
772         status = netr_find_machine_account(p->mem_ctx,
773                                            creds->account_name,
774                                            &sampass);
775         if (!NT_STATUS_IS_OK(status)) {
776                 return status;
777         }
778
779         status = netr_set_machine_account_password(sampass,
780                                                    sampass,
781                                                    NULL,
782                                                    r->in.new_password,
783                                                    NULL);
784         TALLOC_FREE(sampass);
785         return status;
786 }
787
788 /****************************************************************
789  _netr_ServerPasswordSet2
790 ****************************************************************/
791
792 NTSTATUS _netr_ServerPasswordSet2(pipes_struct *p,
793                                   struct netr_ServerPasswordSet2 *r)
794 {
795         NTSTATUS status;
796         struct netlogon_creds_CredentialState *creds;
797         struct samu *sampass;
798         DATA_BLOB plaintext;
799         struct samr_CryptPassword password_buf;
800
801         become_root();
802         status = netr_creds_server_step_check(p, p->mem_ctx,
803                                               r->in.computer_name,
804                                               r->in.credential,
805                                               r->out.return_authenticator,
806                                               &creds);
807         unbecome_root();
808
809         if (!NT_STATUS_IS_OK(status)) {
810                 DEBUG(2,("_netr_ServerPasswordSet2: netlogon_creds_server_step "
811                         "failed. Rejecting auth request from client %s machine account %s\n",
812                         r->in.computer_name, creds->computer_name));
813                 TALLOC_FREE(creds);
814                 return status;
815         }
816
817         memcpy(password_buf.data, r->in.new_password->data, 512);
818         SIVAL(password_buf.data, 512, r->in.new_password->length);
819         netlogon_creds_arcfour_crypt(creds, password_buf.data, 516);
820
821         if (!extract_pw_from_buffer(p->mem_ctx, password_buf.data, &plaintext)) {
822                 return NT_STATUS_WRONG_PASSWORD;
823         }
824
825         status = netr_find_machine_account(p->mem_ctx,
826                                            creds->account_name,
827                                            &sampass);
828         if (!NT_STATUS_IS_OK(status)) {
829                 return status;
830         }
831
832         status = netr_set_machine_account_password(sampass,
833                                                    sampass,
834                                                    &plaintext,
835                                                    NULL,
836                                                    NULL);
837         TALLOC_FREE(sampass);
838         return status;
839 }
840
841 /*************************************************************************
842  _netr_LogonSamLogoff
843  *************************************************************************/
844
845 NTSTATUS _netr_LogonSamLogoff(pipes_struct *p,
846                               struct netr_LogonSamLogoff *r)
847 {
848         NTSTATUS status;
849         struct netlogon_creds_CredentialState *creds;
850
851         become_root();
852         status = netr_creds_server_step_check(p, p->mem_ctx,
853                                               r->in.computer_name,
854                                               r->in.credential,
855                                               r->out.return_authenticator,
856                                               &creds);
857         unbecome_root();
858
859         return status;
860 }
861
862 /*************************************************************************
863  _netr_LogonSamLogon_base
864  *************************************************************************/
865
866 static NTSTATUS _netr_LogonSamLogon_base(pipes_struct *p,
867                                          struct netr_LogonSamLogonEx *r,
868                                          struct netlogon_creds_CredentialState *creds)
869 {
870         NTSTATUS status = NT_STATUS_OK;
871         union netr_LogonLevel *logon = r->in.logon;
872         const char *nt_username, *nt_domain, *nt_workstation;
873         auth_usersupplied_info *user_info = NULL;
874         auth_serversupplied_info *server_info = NULL;
875         struct auth_context *auth_context = NULL;
876         uint8_t pipe_session_key[16];
877         bool process_creds = true;
878         const char *fn;
879
880         switch (p->hdr_req.opnum) {
881                 case NDR_NETR_LOGONSAMLOGON:
882                         process_creds = true;
883                         fn = "_netr_LogonSamLogon";
884                         break;
885                 case NDR_NETR_LOGONSAMLOGONWITHFLAGS:
886                         process_creds = true;
887                         fn = "_netr_LogonSamLogonWithFlags";
888                         break;
889                 case NDR_NETR_LOGONSAMLOGONEX:
890                         process_creds = false;
891                         fn = "_netr_LogonSamLogonEx";
892                         break;
893                 default:
894                         return NT_STATUS_INTERNAL_ERROR;
895         }
896
897         *r->out.authoritative = true; /* authoritative response */
898
899         switch (r->in.validation_level) {
900         case 2:
901                 r->out.validation->sam2 = TALLOC_ZERO_P(p->mem_ctx, struct netr_SamInfo2);
902                 if (!r->out.validation->sam2) {
903                         return NT_STATUS_NO_MEMORY;
904                 }
905                 break;
906         case 3:
907                 r->out.validation->sam3 = TALLOC_ZERO_P(p->mem_ctx, struct netr_SamInfo3);
908                 if (!r->out.validation->sam3) {
909                         return NT_STATUS_NO_MEMORY;
910                 }
911                 break;
912         default:
913                 DEBUG(0,("%s: bad validation_level value %d.\n",
914                         fn, (int)r->in.validation_level));
915                 return NT_STATUS_INVALID_INFO_CLASS;
916         }
917
918         switch (r->in.logon_level) {
919         case NetlogonInteractiveInformation:
920                 nt_username     = logon->password->identity_info.account_name.string;
921                 nt_domain       = logon->password->identity_info.domain_name.string;
922                 nt_workstation  = logon->password->identity_info.workstation.string;
923
924                 DEBUG(3,("SAM Logon (Interactive). Domain:[%s].  ", lp_workgroup()));
925                 break;
926         case NetlogonNetworkInformation:
927                 nt_username     = logon->network->identity_info.account_name.string;
928                 nt_domain       = logon->network->identity_info.domain_name.string;
929                 nt_workstation  = logon->network->identity_info.workstation.string;
930
931                 DEBUG(3,("SAM Logon (Network). Domain:[%s].  ", lp_workgroup()));
932                 break;
933         default:
934                 DEBUG(2,("SAM Logon: unsupported switch value\n"));
935                 return NT_STATUS_INVALID_INFO_CLASS;
936         } /* end switch */
937
938         DEBUG(3,("User:[%s@%s] Requested Domain:[%s]\n", nt_username, nt_workstation, nt_domain));
939         fstrcpy(current_user_info.smb_name, nt_username);
940         sub_set_smb_name(nt_username);
941
942         DEBUG(5,("Attempting validation level %d for unmapped username %s.\n",
943                 r->in.validation_level, nt_username));
944
945         status = NT_STATUS_OK;
946
947         switch (r->in.logon_level) {
948         case NetlogonNetworkInformation:
949         {
950                 const char *wksname = nt_workstation;
951
952                 status = make_auth_context_fixed(&auth_context,
953                                                  logon->network->challenge);
954                 if (!NT_STATUS_IS_OK(status)) {
955                         return status;
956                 }
957
958                 /* For a network logon, the workstation name comes in with two
959                  * backslashes in the front. Strip them if they are there. */
960
961                 if (*wksname == '\\') wksname++;
962                 if (*wksname == '\\') wksname++;
963
964                 /* Standard challenge/response authenticaion */
965                 if (!make_user_info_netlogon_network(&user_info,
966                                                      nt_username, nt_domain,
967                                                      wksname,
968                                                      logon->network->identity_info.parameter_control,
969                                                      logon->network->lm.data,
970                                                      logon->network->lm.length,
971                                                      logon->network->nt.data,
972                                                      logon->network->nt.length)) {
973                         status = NT_STATUS_NO_MEMORY;
974                 }
975                 break;
976         }
977         case NetlogonInteractiveInformation:
978                 /* 'Interactive' authentication, supplies the password in its
979                    MD4 form, encrypted with the session key.  We will convert
980                    this to challenge/response for the auth subsystem to chew
981                    on */
982         {
983                 uint8_t chal[8];
984
985                 if (!NT_STATUS_IS_OK(status = make_auth_context_subsystem(&auth_context))) {
986                         return status;
987                 }
988
989                 auth_context->get_ntlm_challenge(auth_context, chal);
990
991                 if (!make_user_info_netlogon_interactive(&user_info,
992                                                          nt_username, nt_domain,
993                                                          nt_workstation,
994                                                          logon->password->identity_info.parameter_control,
995                                                          chal,
996                                                          logon->password->lmpassword.hash,
997                                                          logon->password->ntpassword.hash,
998                                                          creds->session_key)) {
999                         status = NT_STATUS_NO_MEMORY;
1000                 }
1001                 break;
1002         }
1003         default:
1004                 DEBUG(2,("SAM Logon: unsupported switch value\n"));
1005                 return NT_STATUS_INVALID_INFO_CLASS;
1006         } /* end switch */
1007
1008         if ( NT_STATUS_IS_OK(status) ) {
1009                 status = auth_context->check_ntlm_password(auth_context,
1010                         user_info, &server_info);
1011         }
1012
1013         (auth_context->free)(&auth_context);
1014         free_user_info(&user_info);
1015
1016         DEBUG(5,("%s: check_password returned status %s\n",
1017                   fn, nt_errstr(status)));
1018
1019         /* Check account and password */
1020
1021         if (!NT_STATUS_IS_OK(status)) {
1022                 /* If we don't know what this domain is, we need to
1023                    indicate that we are not authoritative.  This
1024                    allows the client to decide if it needs to try
1025                    a local user.  Fix by jpjanosi@us.ibm.com, #2976 */
1026                 if ( NT_STATUS_EQUAL(status, NT_STATUS_NO_SUCH_USER)
1027                      && !strequal(nt_domain, get_global_sam_name())
1028                      && !is_trusted_domain(nt_domain) )
1029                         *r->out.authoritative = false; /* We are not authoritative */
1030
1031                 TALLOC_FREE(server_info);
1032                 return status;
1033         }
1034
1035         if (server_info->guest) {
1036                 /* We don't like guest domain logons... */
1037                 DEBUG(5,("%s: Attempted domain logon as GUEST "
1038                          "denied.\n", fn));
1039                 TALLOC_FREE(server_info);
1040                 return NT_STATUS_LOGON_FAILURE;
1041         }
1042
1043         /* This is the point at which, if the login was successful, that
1044            the SAM Local Security Authority should record that the user is
1045            logged in to the domain.  */
1046
1047         if (process_creds) {
1048                 /* Get the pipe session key from the creds. */
1049                 memcpy(pipe_session_key, creds->session_key, 16);
1050         } else {
1051                 /* Get the pipe session key from the schannel. */
1052                 if ((p->auth.auth_type != PIPE_AUTH_TYPE_SCHANNEL)
1053                     || (p->auth.a_u.schannel_auth == NULL)) {
1054                         return NT_STATUS_INVALID_HANDLE;
1055                 }
1056                 memcpy(pipe_session_key, p->auth.a_u.schannel_auth->sess_key, 16);
1057         }
1058
1059         switch (r->in.validation_level) {
1060         case 2:
1061                 status = serverinfo_to_SamInfo2(server_info, pipe_session_key, 16,
1062                                                 r->out.validation->sam2);
1063                 break;
1064         case 3:
1065                 status = serverinfo_to_SamInfo3(server_info, pipe_session_key, 16,
1066                                                 r->out.validation->sam3);
1067                 break;
1068         }
1069
1070         TALLOC_FREE(server_info);
1071
1072         return status;
1073 }
1074
1075 /****************************************************************
1076  _netr_LogonSamLogonWithFlags
1077 ****************************************************************/
1078
1079 NTSTATUS _netr_LogonSamLogonWithFlags(pipes_struct *p,
1080                                       struct netr_LogonSamLogonWithFlags *r)
1081 {
1082         NTSTATUS status;
1083         struct netlogon_creds_CredentialState *creds;
1084         struct netr_LogonSamLogonEx r2;
1085         struct netr_Authenticator return_authenticator;
1086
1087         become_root();
1088         status = netr_creds_server_step_check(p, p->mem_ctx,
1089                                               r->in.computer_name,
1090                                               r->in.credential,
1091                                               &return_authenticator,
1092                                               &creds);
1093         unbecome_root();
1094         if (!NT_STATUS_IS_OK(status)) {
1095                 return status;
1096         }
1097
1098         r2.in.server_name       = r->in.server_name;
1099         r2.in.computer_name     = r->in.computer_name;
1100         r2.in.logon_level       = r->in.logon_level;
1101         r2.in.logon             = r->in.logon;
1102         r2.in.validation_level  = r->in.validation_level;
1103         r2.in.flags             = r->in.flags;
1104         r2.out.validation       = r->out.validation;
1105         r2.out.authoritative    = r->out.authoritative;
1106         r2.out.flags            = r->out.flags;
1107
1108         status = _netr_LogonSamLogon_base(p, &r2, creds);
1109
1110         *r->out.return_authenticator = return_authenticator;
1111
1112         return status;
1113 }
1114
1115 /*************************************************************************
1116  _netr_LogonSamLogon
1117  *************************************************************************/
1118
1119 NTSTATUS _netr_LogonSamLogon(pipes_struct *p,
1120                              struct netr_LogonSamLogon *r)
1121 {
1122         NTSTATUS status;
1123         struct netr_LogonSamLogonWithFlags r2;
1124         uint32_t flags = 0;
1125
1126         r2.in.server_name               = r->in.server_name;
1127         r2.in.computer_name             = r->in.computer_name;
1128         r2.in.credential                = r->in.credential;
1129         r2.in.logon_level               = r->in.logon_level;
1130         r2.in.logon                     = r->in.logon;
1131         r2.in.validation_level          = r->in.validation_level;
1132         r2.in.return_authenticator      = r->in.return_authenticator;
1133         r2.in.flags                     = &flags;
1134         r2.out.validation               = r->out.validation;
1135         r2.out.authoritative            = r->out.authoritative;
1136         r2.out.flags                    = &flags;
1137         r2.out.return_authenticator     = r->out.return_authenticator;
1138
1139         status = _netr_LogonSamLogonWithFlags(p, &r2);
1140
1141         return status;
1142 }
1143
1144 /*************************************************************************
1145  _netr_LogonSamLogonEx
1146  - no credential chaining. Map into net sam logon.
1147  *************************************************************************/
1148
1149 NTSTATUS _netr_LogonSamLogonEx(pipes_struct *p,
1150                                struct netr_LogonSamLogonEx *r)
1151 {
1152         NTSTATUS status;
1153         struct netlogon_creds_CredentialState *creds;
1154
1155         become_root();
1156         status = schannel_fetch_session_key(p->mem_ctx, r->in.computer_name, &creds);
1157         unbecome_root();
1158         if (!NT_STATUS_IS_OK(status)) {
1159                 return status;
1160         }
1161
1162         /* Only allow this if the pipe is protected. */
1163         if (p->auth.auth_type != PIPE_AUTH_TYPE_SCHANNEL) {
1164                 DEBUG(0,("_netr_LogonSamLogonEx: client %s not using schannel for netlogon\n",
1165                         get_remote_machine_name() ));
1166                 return NT_STATUS_INVALID_PARAMETER;
1167         }
1168
1169         status = _netr_LogonSamLogon_base(p, r, creds);
1170         TALLOC_FREE(creds);
1171
1172         return status;
1173 }
1174
1175 /*************************************************************************
1176  _ds_enum_dom_trusts
1177  *************************************************************************/
1178 #if 0   /* JERRY -- not correct */
1179  NTSTATUS _ds_enum_dom_trusts(pipes_struct *p, DS_Q_ENUM_DOM_TRUSTS *q_u,
1180                              DS_R_ENUM_DOM_TRUSTS *r_u)
1181 {
1182         NTSTATUS status = NT_STATUS_OK;
1183
1184         /* TODO: According to MSDN, the can only be executed against a
1185            DC or domain member running Windows 2000 or later.  Need
1186            to test against a standalone 2k server and see what it
1187            does.  A windows 2000 DC includes its own domain in the
1188            list.  --jerry */
1189
1190         return status;
1191 }
1192 #endif  /* JERRY */
1193
1194
1195 /****************************************************************
1196 ****************************************************************/
1197
1198 WERROR _netr_LogonUasLogon(pipes_struct *p,
1199                            struct netr_LogonUasLogon *r)
1200 {
1201         p->rng_fault_state = true;
1202         return WERR_NOT_SUPPORTED;
1203 }
1204
1205 /****************************************************************
1206 ****************************************************************/
1207
1208 WERROR _netr_LogonUasLogoff(pipes_struct *p,
1209                             struct netr_LogonUasLogoff *r)
1210 {
1211         p->rng_fault_state = true;
1212         return WERR_NOT_SUPPORTED;
1213 }
1214
1215 /****************************************************************
1216 ****************************************************************/
1217
1218 NTSTATUS _netr_DatabaseDeltas(pipes_struct *p,
1219                               struct netr_DatabaseDeltas *r)
1220 {
1221         p->rng_fault_state = true;
1222         return NT_STATUS_NOT_IMPLEMENTED;
1223 }
1224
1225 /****************************************************************
1226 ****************************************************************/
1227
1228 NTSTATUS _netr_DatabaseSync(pipes_struct *p,
1229                             struct netr_DatabaseSync *r)
1230 {
1231         p->rng_fault_state = true;
1232         return NT_STATUS_NOT_IMPLEMENTED;
1233 }
1234
1235 /****************************************************************
1236 ****************************************************************/
1237
1238 NTSTATUS _netr_AccountDeltas(pipes_struct *p,
1239                              struct netr_AccountDeltas *r)
1240 {
1241         p->rng_fault_state = true;
1242         return NT_STATUS_NOT_IMPLEMENTED;
1243 }
1244
1245 /****************************************************************
1246 ****************************************************************/
1247
1248 NTSTATUS _netr_AccountSync(pipes_struct *p,
1249                            struct netr_AccountSync *r)
1250 {
1251         p->rng_fault_state = true;
1252         return NT_STATUS_NOT_IMPLEMENTED;
1253 }
1254
1255 /****************************************************************
1256 ****************************************************************/
1257
1258 WERROR _netr_GetDcName(pipes_struct *p,
1259                        struct netr_GetDcName *r)
1260 {
1261         p->rng_fault_state = true;
1262         return WERR_NOT_SUPPORTED;
1263 }
1264
1265 /****************************************************************
1266 ****************************************************************/
1267
1268 WERROR _netr_GetAnyDCName(pipes_struct *p,
1269                           struct netr_GetAnyDCName *r)
1270 {
1271         p->rng_fault_state = true;
1272         return WERR_NOT_SUPPORTED;
1273 }
1274
1275 /****************************************************************
1276 ****************************************************************/
1277
1278 NTSTATUS _netr_DatabaseSync2(pipes_struct *p,
1279                              struct netr_DatabaseSync2 *r)
1280 {
1281         p->rng_fault_state = true;
1282         return NT_STATUS_NOT_IMPLEMENTED;
1283 }
1284
1285 /****************************************************************
1286 ****************************************************************/
1287
1288 NTSTATUS _netr_DatabaseRedo(pipes_struct *p,
1289                             struct netr_DatabaseRedo *r)
1290 {
1291         p->rng_fault_state = true;
1292         return NT_STATUS_NOT_IMPLEMENTED;
1293 }
1294
1295 /****************************************************************
1296 ****************************************************************/
1297
1298 WERROR _netr_DsRGetDCName(pipes_struct *p,
1299                           struct netr_DsRGetDCName *r)
1300 {
1301         p->rng_fault_state = true;
1302         return WERR_NOT_SUPPORTED;
1303 }
1304
1305 /****************************************************************
1306 ****************************************************************/
1307
1308 NTSTATUS _netr_LogonGetCapabilities(pipes_struct *p,
1309                                     struct netr_LogonGetCapabilities *r)
1310 {
1311         return NT_STATUS_NOT_IMPLEMENTED;
1312 }
1313
1314 /****************************************************************
1315 ****************************************************************/
1316
1317 WERROR _netr_NETRLOGONSETSERVICEBITS(pipes_struct *p,
1318                                      struct netr_NETRLOGONSETSERVICEBITS *r)
1319 {
1320         p->rng_fault_state = true;
1321         return WERR_NOT_SUPPORTED;
1322 }
1323
1324 /****************************************************************
1325 ****************************************************************/
1326
1327 WERROR _netr_LogonGetTrustRid(pipes_struct *p,
1328                               struct netr_LogonGetTrustRid *r)
1329 {
1330         p->rng_fault_state = true;
1331         return WERR_NOT_SUPPORTED;
1332 }
1333
1334 /****************************************************************
1335 ****************************************************************/
1336
1337 WERROR _netr_NETRLOGONCOMPUTESERVERDIGEST(pipes_struct *p,
1338                                           struct netr_NETRLOGONCOMPUTESERVERDIGEST *r)
1339 {
1340         p->rng_fault_state = true;
1341         return WERR_NOT_SUPPORTED;
1342 }
1343
1344 /****************************************************************
1345 ****************************************************************/
1346
1347 WERROR _netr_NETRLOGONCOMPUTECLIENTDIGEST(pipes_struct *p,
1348                                           struct netr_NETRLOGONCOMPUTECLIENTDIGEST *r)
1349 {
1350         p->rng_fault_state = true;
1351         return WERR_NOT_SUPPORTED;
1352 }
1353
1354 /****************************************************************
1355 ****************************************************************/
1356
1357 WERROR _netr_DsRGetDCNameEx(pipes_struct *p,
1358                             struct netr_DsRGetDCNameEx *r)
1359 {
1360         p->rng_fault_state = true;
1361         return WERR_NOT_SUPPORTED;
1362 }
1363
1364 /****************************************************************
1365 ****************************************************************/
1366
1367 WERROR _netr_DsRGetSiteName(pipes_struct *p,
1368                             struct netr_DsRGetSiteName *r)
1369 {
1370         p->rng_fault_state = true;
1371         return WERR_NOT_SUPPORTED;
1372 }
1373
1374 /****************************************************************
1375 ****************************************************************/
1376
1377 NTSTATUS _netr_LogonGetDomainInfo(pipes_struct *p,
1378                                   struct netr_LogonGetDomainInfo *r)
1379 {
1380         p->rng_fault_state = true;
1381         return NT_STATUS_NOT_IMPLEMENTED;
1382 }
1383
1384 /****************************************************************
1385 ****************************************************************/
1386
1387 WERROR _netr_ServerPasswordGet(pipes_struct *p,
1388                                struct netr_ServerPasswordGet *r)
1389 {
1390         p->rng_fault_state = true;
1391         return WERR_NOT_SUPPORTED;
1392 }
1393
1394 /****************************************************************
1395 ****************************************************************/
1396
1397 WERROR _netr_NETRLOGONSENDTOSAM(pipes_struct *p,
1398                                 struct netr_NETRLOGONSENDTOSAM *r)
1399 {
1400         p->rng_fault_state = true;
1401         return WERR_NOT_SUPPORTED;
1402 }
1403
1404 /****************************************************************
1405 ****************************************************************/
1406
1407 WERROR _netr_DsRAddressToSitenamesW(pipes_struct *p,
1408                                     struct netr_DsRAddressToSitenamesW *r)
1409 {
1410         p->rng_fault_state = true;
1411         return WERR_NOT_SUPPORTED;
1412 }
1413
1414 /****************************************************************
1415 ****************************************************************/
1416
1417 WERROR _netr_DsRGetDCNameEx2(pipes_struct *p,
1418                              struct netr_DsRGetDCNameEx2 *r)
1419 {
1420         p->rng_fault_state = true;
1421         return WERR_NOT_SUPPORTED;
1422 }
1423
1424 /****************************************************************
1425 ****************************************************************/
1426
1427 WERROR _netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN(pipes_struct *p,
1428                                                  struct netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN *r)
1429 {
1430         p->rng_fault_state = true;
1431         return WERR_NOT_SUPPORTED;
1432 }
1433
1434 /****************************************************************
1435 ****************************************************************/
1436
1437 WERROR _netr_NetrEnumerateTrustedDomainsEx(pipes_struct *p,
1438                                            struct netr_NetrEnumerateTrustedDomainsEx *r)
1439 {
1440         p->rng_fault_state = true;
1441         return WERR_NOT_SUPPORTED;
1442 }
1443
1444 /****************************************************************
1445 ****************************************************************/
1446
1447 WERROR _netr_DsRAddressToSitenamesExW(pipes_struct *p,
1448                                       struct netr_DsRAddressToSitenamesExW *r)
1449 {
1450         p->rng_fault_state = true;
1451         return WERR_NOT_SUPPORTED;
1452 }
1453
1454 /****************************************************************
1455 ****************************************************************/
1456
1457 WERROR _netr_DsrGetDcSiteCoverageW(pipes_struct *p,
1458                                    struct netr_DsrGetDcSiteCoverageW *r)
1459 {
1460         p->rng_fault_state = true;
1461         return WERR_NOT_SUPPORTED;
1462 }
1463
1464 /****************************************************************
1465 ****************************************************************/
1466
1467 WERROR _netr_DsrEnumerateDomainTrusts(pipes_struct *p,
1468                                       struct netr_DsrEnumerateDomainTrusts *r)
1469 {
1470         p->rng_fault_state = true;
1471         return WERR_NOT_SUPPORTED;
1472 }
1473
1474 /****************************************************************
1475 ****************************************************************/
1476
1477 WERROR _netr_DsrDeregisterDNSHostRecords(pipes_struct *p,
1478                                          struct netr_DsrDeregisterDNSHostRecords *r)
1479 {
1480         p->rng_fault_state = true;
1481         return WERR_NOT_SUPPORTED;
1482 }
1483
1484 /****************************************************************
1485 ****************************************************************/
1486
1487 NTSTATUS _netr_ServerTrustPasswordsGet(pipes_struct *p,
1488                                        struct netr_ServerTrustPasswordsGet *r)
1489 {
1490         p->rng_fault_state = true;
1491         return NT_STATUS_NOT_IMPLEMENTED;
1492 }
1493
1494 /****************************************************************
1495 ****************************************************************/
1496
1497 WERROR _netr_DsRGetForestTrustInformation(pipes_struct *p,
1498                                           struct netr_DsRGetForestTrustInformation *r)
1499 {
1500         p->rng_fault_state = true;
1501         return WERR_NOT_SUPPORTED;
1502 }
1503
1504 /****************************************************************
1505 ****************************************************************/
1506
1507 WERROR _netr_GetForestTrustInformation(pipes_struct *p,
1508                                        struct netr_GetForestTrustInformation *r)
1509 {
1510         p->rng_fault_state = true;
1511         return WERR_NOT_SUPPORTED;
1512 }
1513
1514 /****************************************************************
1515 ****************************************************************/
1516
1517 NTSTATUS _netr_ServerGetTrustInfo(pipes_struct *p,
1518                                   struct netr_ServerGetTrustInfo *r)
1519 {
1520         p->rng_fault_state = true;
1521         return NT_STATUS_NOT_IMPLEMENTED;
1522 }
1523