r15298: Fix the build using a few hacks in the build system.
[bbaumbach/samba-autobuild/.git] / source4 / rpc_server / netlogon / dcerpc_netlogon.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    endpoint server for the netlogon pipe
5
6    Copyright (C) Andrew Bartlett <abartlet@samba.org> 2004
7    Copyright (C) Stefan Metzmacher <metze@samba.org>  2005
8    
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13    
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 #include "includes.h"
25 #include "rpc_server/dcerpc_server.h"
26 #include "rpc_server/common/common.h"
27 #include "lib/ldb/include/ldb.h"
28 #include "auth/auth_sam.h"
29 #include "auth/auth.h"
30 #include "dsdb/samdb/samdb.h"
31 #include "rpc_server/samr/proto.h"
32 #include "db_wrap.h"
33 #include "libcli/auth/libcli_auth.h"
34 #include "auth/gensec/schannel_state.h"
35
36 struct server_pipe_state {
37         struct netr_Credential client_challenge;
38         struct netr_Credential server_challenge;
39 };
40
41
42 static NTSTATUS netr_ServerReqChallenge(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
43                                         struct netr_ServerReqChallenge *r)
44 {
45         struct server_pipe_state *pipe_state = dce_call->context->private;
46
47         ZERO_STRUCTP(r->out.credentials);
48
49         /* destroyed on pipe shutdown */
50
51         if (pipe_state) {
52                 talloc_free(pipe_state);
53                 dce_call->context->private = NULL;
54         }
55         
56         pipe_state = talloc(dce_call->context, struct server_pipe_state);
57         if (!pipe_state) {
58                 return NT_STATUS_NO_MEMORY;
59         }
60
61         pipe_state->client_challenge = *r->in.credentials;
62
63         generate_random_buffer(pipe_state->server_challenge.data, 
64                                sizeof(pipe_state->server_challenge.data));
65
66         *r->out.credentials = pipe_state->server_challenge;
67
68         dce_call->context->private = pipe_state;
69
70         return NT_STATUS_OK;
71 }
72
73 static NTSTATUS netr_ServerAuthenticate3(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
74                                          struct netr_ServerAuthenticate3 *r)
75 {
76         struct server_pipe_state *pipe_state = dce_call->context->private;
77         struct creds_CredentialState *creds;
78         void *sam_ctx;
79         struct samr_Password *mach_pwd;
80         uint16_t acct_flags;
81         int num_records;
82         struct ldb_message **msgs;
83         NTSTATUS nt_status;
84         const char *attrs[] = {"ntPwdHash", "userAccountControl", 
85                                "objectSid", NULL};
86
87         ZERO_STRUCTP(r->out.credentials);
88         *r->out.rid = 0;
89         *r->out.negotiate_flags = *r->in.negotiate_flags;
90
91         if (!pipe_state) {
92                 DEBUG(1, ("No challenge requested by client, cannot authenticate\n"));
93                 return NT_STATUS_ACCESS_DENIED;
94         }
95
96         sam_ctx = samdb_connect(mem_ctx, system_session(mem_ctx));
97         if (sam_ctx == NULL) {
98                 return NT_STATUS_INVALID_SYSTEM_SERVICE;
99         }
100         /* pull the user attributes */
101         num_records = gendb_search(sam_ctx, mem_ctx, NULL, &msgs, attrs,
102                                    "(&(sAMAccountName=%s)(objectclass=user))", 
103                                    r->in.account_name);
104
105         if (num_records == 0) {
106                 DEBUG(3,("Couldn't find user [%s] in samdb.\n", 
107                          r->in.account_name));
108                 return NT_STATUS_ACCESS_DENIED;
109         }
110
111         if (num_records > 1) {
112                 DEBUG(0,("Found %d records matching user [%s]\n", num_records, r->in.account_name));
113                 return NT_STATUS_INTERNAL_DB_CORRUPTION;
114         }
115
116         acct_flags = samdb_result_acct_flags(msgs[0], 
117                                              "userAccountControl");
118
119         if (acct_flags & ACB_DISABLED) {
120                 DEBUG(1, ("Account [%s] is disabled\n", r->in.account_name));
121                 return NT_STATUS_ACCESS_DENIED;
122         }
123
124         if (r->in.secure_channel_type == SEC_CHAN_WKSTA) {
125                 if (!(acct_flags & ACB_WSTRUST)) {
126                         DEBUG(1, ("Client asked for a workstation secure channel, but is not a workstation (member server) acb flags: 0x%x\n", acct_flags));
127                         return NT_STATUS_ACCESS_DENIED;
128                 }
129         } else if (r->in.secure_channel_type == SEC_CHAN_DOMAIN) {
130                 if (!(acct_flags & ACB_DOMTRUST)) {
131                         DEBUG(1, ("Client asked for a trusted domain secure channel, but is not a trusted domain: acb flags: 0x%x\n", acct_flags));
132                         return NT_STATUS_ACCESS_DENIED;
133                 }
134         } else if (r->in.secure_channel_type == SEC_CHAN_BDC) {
135                 if (!(acct_flags & ACB_SVRTRUST)) {
136                         DEBUG(1, ("Client asked for a server secure channel, but is not a server (domain controller): acb flags: 0x%x\n", acct_flags));
137                         return NT_STATUS_ACCESS_DENIED;
138                 }
139         } else {
140                 DEBUG(1, ("Client asked for an invalid secure channel type: %d\n", 
141                           r->in.secure_channel_type));
142                 return NT_STATUS_ACCESS_DENIED;
143         }
144
145         *r->out.rid = samdb_result_rid_from_sid(mem_ctx, msgs[0], 
146                                                 "objectSid", 0);
147
148         mach_pwd = samdb_result_hash(mem_ctx, msgs[0], "ntPwdHash");
149         if (mach_pwd == NULL) {
150                 return NT_STATUS_ACCESS_DENIED;
151         }
152
153         creds = talloc(mem_ctx, struct creds_CredentialState);
154         if (!creds) {
155                 return NT_STATUS_NO_MEMORY;
156         }
157
158         creds_server_init(creds, &pipe_state->client_challenge, 
159                           &pipe_state->server_challenge, mach_pwd,
160                           r->out.credentials,
161                           *r->in.negotiate_flags);
162         
163         if (!creds_server_check(creds, r->in.credentials)) {
164                 talloc_free(creds);
165                 return NT_STATUS_ACCESS_DENIED;
166         }
167
168         creds->account_name = talloc_steal(creds, r->in.account_name);
169         
170         creds->computer_name = talloc_steal(creds, r->in.computer_name);
171         creds->domain = talloc_strdup(creds, lp_workgroup());
172
173         creds->secure_channel_type = r->in.secure_channel_type;
174
175         creds->sid = samdb_result_dom_sid(creds, msgs[0], "objectSid");
176
177
178         /* remember this session key state */
179         nt_status = schannel_store_session_key(mem_ctx, creds);
180
181         return nt_status;
182 }
183                                                  
184 static NTSTATUS netr_ServerAuthenticate(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
185                                         struct netr_ServerAuthenticate *r)
186 {
187         struct netr_ServerAuthenticate3 r3;
188         uint32_t rid = 0;
189         /* TODO: 
190          * negotiate_flags is used as an [in] parameter
191          * so it need to be initialised.
192          *
193          * (I think ... = 0; seems wrong here --metze)
194          */
195         uint32_t negotiate_flags = 0;  
196
197         r3.in.server_name = r->in.server_name;
198         r3.in.account_name = r->in.account_name;
199         r3.in.secure_channel_type = r->in.secure_channel_type;
200         r3.in.computer_name = r->in.computer_name;
201         r3.in.credentials = r->in.credentials;
202         r3.out.credentials = r->out.credentials;
203         r3.in.negotiate_flags = &negotiate_flags;
204         r3.out.negotiate_flags = &negotiate_flags;
205         r3.out.rid = &rid;
206         
207         return netr_ServerAuthenticate3(dce_call, mem_ctx, &r3);
208 }
209
210 static NTSTATUS netr_ServerAuthenticate2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
211                                          struct netr_ServerAuthenticate2 *r)
212 {
213         struct netr_ServerAuthenticate3 r3;
214         uint32_t rid = 0;
215
216         r3.in.server_name = r->in.server_name;
217         r3.in.account_name = r->in.account_name;
218         r3.in.secure_channel_type = r->in.secure_channel_type;
219         r3.in.computer_name = r->in.computer_name;
220         r3.in.credentials = r->in.credentials;
221         r3.out.credentials = r->out.credentials;
222         r3.in.negotiate_flags = r->in.negotiate_flags;
223         r3.out.negotiate_flags = r->out.negotiate_flags;
224         r3.out.rid = &rid;
225         
226         return netr_ServerAuthenticate3(dce_call, mem_ctx, &r3);
227 }
228
229 /*
230   Validate an incoming authenticator against the credentials for the remote machine.
231
232   The credentials are (re)read and from the schannel database, and
233   written back after the caclulations are performed.
234
235   The creds_out parameter (if not NULL) returns the credentials, if
236   the caller needs some of that information.
237
238 */
239 static NTSTATUS netr_creds_server_step_check(const char *computer_name,
240                                              TALLOC_CTX *mem_ctx, 
241                                              struct netr_Authenticator *received_authenticator,
242                                              struct netr_Authenticator *return_authenticator,
243                                              struct creds_CredentialState **creds_out) 
244 {
245         struct creds_CredentialState *creds;
246         NTSTATUS nt_status;
247         struct ldb_context *ldb;
248         int ret;
249
250         ldb = schannel_db_connect(mem_ctx);
251         if (!ldb) {
252                 return NT_STATUS_ACCESS_DENIED;
253         }
254
255         ret = ldb_transaction_start(ldb);
256         if (ret != 0) {
257                 talloc_free(ldb);
258                 return NT_STATUS_INTERNAL_DB_CORRUPTION;
259         }
260
261         /* Because this is a shared structure (even across
262          * disconnects) we must update the database every time we
263          * update the structure */ 
264         
265         nt_status = schannel_fetch_session_key_ldb(ldb, ldb, computer_name, lp_workgroup(),
266                                                    &creds);
267         if (NT_STATUS_IS_OK(nt_status)) {
268                 nt_status = creds_server_step_check(creds, 
269                                                     received_authenticator, 
270                                                     return_authenticator);
271         }
272         if (NT_STATUS_IS_OK(nt_status)) {
273                 nt_status = schannel_store_session_key_ldb(ldb, ldb, creds);
274         }
275
276         if (NT_STATUS_IS_OK(nt_status)) {
277                 ldb_transaction_commit(ldb);
278                 if (creds_out) {
279                         *creds_out = creds;
280                         talloc_steal(mem_ctx, creds);
281                 }
282         } else {
283                 ldb_transaction_cancel(ldb);
284         }
285         talloc_free(ldb);
286         return nt_status;
287 }
288
289 /* 
290   Change the machine account password for the currently connected
291   client.  Supplies only the NT#.
292 */
293
294 static NTSTATUS netr_ServerPasswordSet(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
295                                        struct netr_ServerPasswordSet *r)
296 {
297         struct creds_CredentialState *creds;
298         struct ldb_context *sam_ctx;
299         NTSTATUS nt_status;
300
301         nt_status = netr_creds_server_step_check(r->in.computer_name, mem_ctx, 
302                                                  &r->in.credential, &r->out.return_authenticator,
303                                                  &creds);
304         NT_STATUS_NOT_OK_RETURN(nt_status);
305
306         sam_ctx = samdb_connect(mem_ctx, system_session(mem_ctx));
307         if (sam_ctx == NULL) {
308                 return NT_STATUS_INVALID_SYSTEM_SERVICE;
309         }
310
311         creds_des_decrypt(creds, &r->in.new_password);
312
313         /* Using the sid for the account as the key, set the password */
314         nt_status = samdb_set_password_sid(sam_ctx, mem_ctx, 
315                                            creds->sid,
316                                            NULL, /* Don't have plaintext */
317                                            NULL, &r->in.new_password,
318                                            False, /* This is not considered a password change */
319                                            False, /* don't restrict this password change (match w2k3) */
320                                            NULL, NULL);
321         return nt_status;
322 }
323
324 /* 
325   Change the machine account password for the currently connected
326   client.  Supplies new plaintext.
327 */
328 static NTSTATUS netr_ServerPasswordSet2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
329                                        struct netr_ServerPasswordSet2 *r)
330 {
331         struct creds_CredentialState *creds;
332         struct ldb_context *sam_ctx;
333         NTSTATUS nt_status;
334         char new_pass[512];
335         uint32_t new_pass_len;
336         BOOL ret;
337
338         struct samr_CryptPassword password_buf;
339
340         nt_status = netr_creds_server_step_check(r->in.computer_name, mem_ctx, 
341                                                  &r->in.credential, &r->out.return_authenticator,
342                                                  &creds);
343         NT_STATUS_NOT_OK_RETURN(nt_status);
344
345         sam_ctx = samdb_connect(mem_ctx, system_session(mem_ctx));
346         if (sam_ctx == NULL) {
347                 return NT_STATUS_INVALID_SYSTEM_SERVICE;
348         }
349
350         memcpy(password_buf.data, r->in.new_password.data, 512);
351         SIVAL(password_buf.data,512,r->in.new_password.length);
352         creds_arcfour_crypt(creds, password_buf.data, 516);
353
354         ret = decode_pw_buffer(password_buf.data, new_pass, sizeof(new_pass),
355                                &new_pass_len, STR_UNICODE);
356         if (!ret) {
357                 DEBUG(3,("netr_ServerPasswordSet2: failed to decode password buffer\n"));
358                 return NT_STATUS_ACCESS_DENIED;
359         }
360
361         /* Using the sid for the account as the key, set the password */
362         nt_status = samdb_set_password_sid(sam_ctx, mem_ctx,
363                                            creds->sid,
364                                            new_pass, /* we have plaintext */
365                                            NULL, NULL,
366                                            False, /* This is not considered a password change */
367                                            False, /* don't restrict this password change (match w2k3) */
368                                            NULL, NULL);
369         return nt_status;
370 }
371
372
373 /* 
374   netr_LogonUasLogon 
375 */
376 static WERROR netr_LogonUasLogon(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
377                                  struct netr_LogonUasLogon *r)
378 {
379         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
380 }
381
382
383 /* 
384   netr_LogonUasLogoff 
385 */
386 static WERROR netr_LogonUasLogoff(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
387                        struct netr_LogonUasLogoff *r)
388 {
389         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
390 }
391
392
393 /* 
394   netr_LogonSamLogon_base
395
396   This version of the function allows other wrappers to say 'do not check the credentials'
397
398   We can't do the traditional 'wrapping' format completly, as this function must only run under schannel
399 */
400 static NTSTATUS netr_LogonSamLogon_base(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
401                                         struct netr_LogonSamLogonEx *r, struct creds_CredentialState *creds)
402 {
403         struct auth_context *auth_context;
404         struct auth_usersupplied_info *user_info;
405         struct auth_serversupplied_info *server_info;
406         NTSTATUS nt_status;
407         static const char zeros[16];
408         struct netr_SamBaseInfo *sam;
409         struct netr_SamInfo2 *sam2;
410         struct netr_SamInfo3 *sam3;
411         struct netr_SamInfo6 *sam6;
412         
413         user_info = talloc(mem_ctx, struct auth_usersupplied_info);
414         if (!user_info) {
415                 return NT_STATUS_NO_MEMORY;
416         }
417
418         user_info->flags = 0;
419         user_info->mapped_state = False;
420         user_info->remote_host = NULL;
421
422         switch (r->in.logon_level) {
423         case 1:
424         case 3:
425         case 5:
426                 if (creds->negotiate_flags & NETLOGON_NEG_ARCFOUR) {
427                         creds_arcfour_crypt(creds, 
428                                             r->in.logon.password->lmpassword.hash, 
429                                             sizeof(r->in.logon.password->lmpassword.hash));
430                         creds_arcfour_crypt(creds, 
431                                             r->in.logon.password->ntpassword.hash, 
432                                             sizeof(r->in.logon.password->ntpassword.hash));
433                 } else {
434                         creds_des_decrypt(creds, &r->in.logon.password->lmpassword);
435                         creds_des_decrypt(creds, &r->in.logon.password->ntpassword);
436                 }
437
438                 /* TODO: we need to deny anonymous access here */
439                 nt_status = auth_context_create(mem_ctx, lp_auth_methods(), &auth_context,
440                                                 dce_call->event_ctx);
441                 NT_STATUS_NOT_OK_RETURN(nt_status);
442
443                 user_info->logon_parameters = r->in.logon.password->identity_info.parameter_control;
444                 user_info->client.account_name = r->in.logon.password->identity_info.account_name.string;
445                 user_info->client.domain_name = r->in.logon.password->identity_info.domain_name.string;
446                 user_info->workstation_name = r->in.logon.password->identity_info.workstation.string;
447                 
448                 user_info->password_state = AUTH_PASSWORD_HASH;
449                 user_info->password.hash.lanman = talloc(user_info, struct samr_Password);
450                 if (!user_info->password.hash.lanman) {
451                         return NT_STATUS_NO_MEMORY;
452                 }
453                 *user_info->password.hash.lanman = r->in.logon.password->lmpassword;
454
455                 user_info->password.hash.nt = talloc(user_info, struct samr_Password);
456                 if (!user_info->password.hash.nt) {
457                         return NT_STATUS_NO_MEMORY;
458                 }
459                 *user_info->password.hash.nt = r->in.logon.password->ntpassword;
460
461                 user_info->flags |= USER_INFO_INTERACTIVE_LOGON;
462
463                 break;          
464         case 2:
465         case 6:
466
467                 /* TODO: we need to deny anonymous access here */
468                 nt_status = auth_context_create(mem_ctx, lp_auth_methods(), &auth_context,
469                                                 dce_call->event_ctx);
470                 NT_STATUS_NOT_OK_RETURN(nt_status);
471
472                 nt_status = auth_context_set_challenge(auth_context, r->in.logon.network->challenge, "netr_LogonSamLogonWithFlags");
473                 NT_STATUS_NOT_OK_RETURN(nt_status);
474
475                 user_info->logon_parameters = r->in.logon.network->identity_info.parameter_control;
476                 user_info->client.account_name = r->in.logon.network->identity_info.account_name.string;
477                 user_info->client.domain_name = r->in.logon.network->identity_info.domain_name.string;
478                 user_info->workstation_name = r->in.logon.network->identity_info.workstation.string;
479                 
480                 user_info->password_state = AUTH_PASSWORD_RESPONSE;
481                 user_info->password.response.lanman = data_blob(r->in.logon.network->lm.data, r->in.logon.network->lm.length);
482                 user_info->password.response.nt = data_blob(r->in.logon.network->nt.data, r->in.logon.network->nt.length);
483         
484                 break;
485         default:
486                 return NT_STATUS_INVALID_PARAMETER;
487         }
488         
489         nt_status = auth_check_password(auth_context, mem_ctx, user_info, &server_info);
490         NT_STATUS_NOT_OK_RETURN(nt_status);
491
492         nt_status = auth_convert_server_info_sambaseinfo(mem_ctx, server_info, &sam);
493
494         NT_STATUS_NOT_OK_RETURN(nt_status);
495
496         /* Don't crypt an all-zero key, it would give away the NETLOGON pipe session key */
497         /* It appears that level 6 is not individually encrypted */
498         if ((r->in.validation_level != 6) 
499             && memcmp(sam->key.key, zeros,  
500                       sizeof(sam->key.key)) != 0) {
501
502                 /* This key is sent unencrypted without the ARCFOUR flag set */
503                 if (creds->negotiate_flags & NETLOGON_NEG_ARCFOUR) {
504                         creds_arcfour_crypt(creds, 
505                                             sam->key.key, 
506                                             sizeof(sam->key.key));
507                 }
508         }
509
510         /* Don't crypt an all-zero key, it would give away the NETLOGON pipe session key */
511         /* It appears that level 6 is not individually encrypted */
512         if ((r->in.validation_level != 6) 
513             && memcmp(sam->LMSessKey.key, zeros,  
514                       sizeof(sam->LMSessKey.key)) != 0) {
515                 if (creds->negotiate_flags & NETLOGON_NEG_ARCFOUR) {
516                         creds_arcfour_crypt(creds, 
517                                             sam->LMSessKey.key, 
518                                             sizeof(sam->LMSessKey.key));
519                 } else {
520                         creds_des_encrypt_LMKey(creds, 
521                                                 &sam->LMSessKey);
522                 }
523         }
524
525         switch (r->in.validation_level) {
526         case 2:
527                 sam2 = talloc_zero(mem_ctx, struct netr_SamInfo2);
528                 NT_STATUS_HAVE_NO_MEMORY(sam2);
529                 sam2->base = *sam;
530                 r->out.validation.sam2 = sam2;
531                 break;
532
533         case 3:
534                 sam3 = talloc_zero(mem_ctx, struct netr_SamInfo3);
535                 NT_STATUS_HAVE_NO_MEMORY(sam3);
536                 sam3->base = *sam;
537                 r->out.validation.sam3 = sam3;
538                 break;
539
540         case 6:
541                 sam6 = talloc_zero(mem_ctx, struct netr_SamInfo6);
542                 NT_STATUS_HAVE_NO_MEMORY(sam6);
543                 sam6->base = *sam;
544                 sam6->forest.string = lp_realm();
545                 sam6->principle.string = talloc_asprintf(mem_ctx, "%s@%s", 
546                                                          sam->account_name.string, sam6->forest.string);
547                 NT_STATUS_HAVE_NO_MEMORY(sam6->principle.string);
548                 r->out.validation.sam6 = sam6;
549                 break;
550
551         default:
552                 break;
553         }
554
555         r->out.authoritative = 1;
556
557         /* TODO: Describe and deal with these flags */
558         r->out.flags = 0;
559
560         return NT_STATUS_OK;
561 }
562
563 static NTSTATUS netr_LogonSamLogonEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
564                                      struct netr_LogonSamLogonEx *r) 
565 {
566         NTSTATUS nt_status;
567         struct creds_CredentialState *creds;
568         nt_status = schannel_fetch_session_key(mem_ctx, r->in.computer_name, lp_workgroup(), &creds);
569         if (!NT_STATUS_IS_OK(nt_status)) {
570                 return nt_status;
571         }
572
573         if (!dce_call->conn->auth_state.auth_info
574             || dce_call->conn->auth_state.auth_info->auth_type != DCERPC_AUTH_TYPE_SCHANNEL) {
575                 return NT_STATUS_INTERNAL_ERROR;
576         }
577         return netr_LogonSamLogon_base(dce_call, mem_ctx, r, creds);
578 }
579
580 /* 
581   netr_LogonSamLogonWithFlags
582
583 */
584 static NTSTATUS netr_LogonSamLogonWithFlags(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
585                                             struct netr_LogonSamLogonWithFlags *r)
586 {
587         NTSTATUS nt_status;
588         struct creds_CredentialState *creds;
589         struct netr_LogonSamLogonEx r2;
590
591         struct netr_Authenticator *return_authenticator;
592
593         return_authenticator = talloc(mem_ctx, struct netr_Authenticator);
594         NT_STATUS_HAVE_NO_MEMORY(return_authenticator);
595
596         nt_status = netr_creds_server_step_check(r->in.computer_name, mem_ctx, 
597                                                  r->in.credential, return_authenticator,
598                                                  &creds);
599         NT_STATUS_NOT_OK_RETURN(nt_status);
600
601         ZERO_STRUCT(r2);
602
603         r2.in.server_name       = r->in.server_name;
604         r2.in.computer_name     = r->in.computer_name;
605         r2.in.logon_level       = r->in.logon_level;
606         r2.in.logon             = r->in.logon;
607         r2.in.validation_level  = r->in.validation_level;
608         r2.in.flags             = r->in.flags;
609
610         nt_status = netr_LogonSamLogon_base(dce_call, mem_ctx, &r2, creds);
611
612         r->out.return_authenticator     = return_authenticator;
613         r->out.validation               = r2.out.validation;
614         r->out.authoritative            = r2.out.authoritative;
615         r->out.flags                    = r2.out.flags;
616
617         return nt_status;
618 }
619
620 /* 
621   netr_LogonSamLogon
622 */
623 static NTSTATUS netr_LogonSamLogon(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
624                                    struct netr_LogonSamLogon *r)
625 {
626         struct netr_LogonSamLogonWithFlags r2;
627         NTSTATUS status;
628
629         ZERO_STRUCT(r2);
630
631         r2.in.server_name = r->in.server_name;
632         r2.in.computer_name = r->in.computer_name;
633         r2.in.credential  = r->in.credential;
634         r2.in.return_authenticator = r->in.return_authenticator;
635         r2.in.logon_level = r->in.logon_level;
636         r2.in.logon = r->in.logon;
637         r2.in.validation_level = r->in.validation_level;
638         r2.in.flags = 0;
639
640         status = netr_LogonSamLogonWithFlags(dce_call, mem_ctx, &r2);
641
642         r->out.return_authenticator = r2.out.return_authenticator;
643         r->out.validation = r2.out.validation;
644         r->out.authoritative = r2.out.authoritative;
645
646         return status;
647 }
648
649
650 /* 
651   netr_LogonSamLogoff 
652 */
653 static NTSTATUS netr_LogonSamLogoff(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
654                        struct netr_LogonSamLogoff *r)
655 {
656         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
657 }
658
659
660
661 /* 
662   netr_DatabaseDeltas 
663 */
664 static NTSTATUS netr_DatabaseDeltas(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
665                        struct netr_DatabaseDeltas *r)
666 {
667         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
668 }
669
670
671 /* 
672   netr_DatabaseSync 
673 */
674 static NTSTATUS netr_DatabaseSync(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
675                        struct netr_DatabaseSync *r)
676 {
677         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
678 }
679
680
681 /* 
682   netr_AccountDeltas 
683 */
684 static NTSTATUS netr_AccountDeltas(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
685                        struct netr_AccountDeltas *r)
686 {
687         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
688 }
689
690
691 /* 
692   netr_AccountSync 
693 */
694 static NTSTATUS netr_AccountSync(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
695                        struct netr_AccountSync *r)
696 {
697         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
698 }
699
700
701 /* 
702   netr_GetDcName 
703 */
704 static NTSTATUS netr_GetDcName(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
705                        struct netr_GetDcName *r)
706 {
707         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
708 }
709
710
711 /* 
712   netr_LogonControl 
713 */
714 static WERROR netr_LogonControl(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
715                        struct netr_LogonControl *r)
716 {
717         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
718 }
719
720
721 /* 
722   netr_GetAnyDCName 
723 */
724 static WERROR netr_GetAnyDCName(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
725                        struct netr_GetAnyDCName *r)
726 {
727         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
728 }
729
730
731 /* 
732   netr_LogonControl2 
733 */
734 static WERROR netr_LogonControl2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
735                        struct netr_LogonControl2 *r)
736 {
737         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
738 }
739
740
741 /* 
742   netr_DatabaseSync2 
743 */
744 static NTSTATUS netr_DatabaseSync2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
745                        struct netr_DatabaseSync2 *r)
746 {
747         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
748 }
749
750
751 /* 
752   netr_DatabaseRedo 
753 */
754 static NTSTATUS netr_DatabaseRedo(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
755                        struct netr_DatabaseRedo *r)
756 {
757         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
758 }
759
760
761 /* 
762   netr_LogonControl2Ex 
763 */
764 static WERROR netr_LogonControl2Ex(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
765                        struct netr_LogonControl2Ex *r)
766 {
767         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
768 }
769
770
771 /* 
772   netr_NETRENUMERATETRUSTEDDOMAINS 
773 */
774 static WERROR netr_NETRENUMERATETRUSTEDDOMAINS(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
775                        struct netr_NETRENUMERATETRUSTEDDOMAINS *r)
776 {
777         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
778 }
779
780
781 /* 
782   netr_NETRLOGONDUMMYROUTINE1 
783 */
784 static WERROR netr_NETRLOGONDUMMYROUTINE1(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
785                        struct netr_NETRLOGONDUMMYROUTINE1 *r)
786 {
787         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
788 }
789
790
791 /* 
792   netr_NETRLOGONSETSERVICEBITS 
793 */
794 static WERROR netr_NETRLOGONSETSERVICEBITS(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
795                        struct netr_NETRLOGONSETSERVICEBITS *r)
796 {
797         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
798 }
799
800
801 /* 
802   netr_NETRLOGONGETTRUSTRID 
803 */
804 static WERROR netr_NETRLOGONGETTRUSTRID(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
805                        struct netr_NETRLOGONGETTRUSTRID *r)
806 {
807         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
808 }
809
810
811 /* 
812   netr_NETRLOGONCOMPUTESERVERDIGEST 
813 */
814 static WERROR netr_NETRLOGONCOMPUTESERVERDIGEST(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
815                        struct netr_NETRLOGONCOMPUTESERVERDIGEST *r)
816 {
817         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
818 }
819
820
821 /* 
822   netr_NETRLOGONCOMPUTECLIENTDIGEST 
823 */
824 static WERROR netr_NETRLOGONCOMPUTECLIENTDIGEST(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
825                        struct netr_NETRLOGONCOMPUTECLIENTDIGEST *r)
826 {
827         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
828 }
829
830
831
832 /* 
833   netr_DsRGetSiteName
834 */
835 static WERROR netr_DsRGetSiteName(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
836                                   struct netr_DsRGetSiteName *r)
837 {
838         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
839 }
840
841
842 /*
843   fill in a netr_DomainTrustInfo from a ldb search result
844 */
845 static NTSTATUS fill_domain_primary_info(TALLOC_CTX *mem_ctx, struct ldb_message *res,
846                                          struct netr_DomainTrustInfo *info, 
847                                          const char *local_domain)
848 {
849         ZERO_STRUCTP(info);
850
851         info->domainname.string = local_domain;
852         info->fulldomainname.string = talloc_asprintf(info, "%s.", samdb_result_string(res, "dnsDomain", NULL));
853         /* TODO: we need proper forest support */
854         info->forest.string = info->fulldomainname.string;
855         info->guid = samdb_result_guid(res, "objectGUID");
856         info->sid = samdb_result_dom_sid(mem_ctx, res, "objectSid");
857
858         return NT_STATUS_OK;
859 }
860
861 /*
862   fill in a netr_DomainTrustInfo from a ldb search result
863 */
864 static NTSTATUS fill_domain_trust_info(TALLOC_CTX *mem_ctx, struct ldb_message *res,
865                                        struct netr_DomainTrustInfo *info, 
866                                        const char *local_domain, BOOL is_local)
867 {
868         ZERO_STRUCTP(info);
869
870         if (is_local) {
871                 info->domainname.string = local_domain;
872                 info->fulldomainname.string = samdb_result_string(res, "dnsDomain", NULL);
873                 info->forest.string = NULL;
874                 info->guid = samdb_result_guid(res, "objectGUID");
875                 info->sid = samdb_result_dom_sid(mem_ctx, res, "objectSid");
876         } else {
877                 info->domainname.string = samdb_result_string(res, "flatName", NULL);
878                 info->fulldomainname.string = samdb_result_string(res, "name", NULL);
879                 info->forest.string = NULL;
880                 info->guid = samdb_result_guid(res, "objectGUID");
881                 info->sid = samdb_result_dom_sid(mem_ctx, res, "securityIdentifier");
882         }
883
884         return NT_STATUS_OK;
885 }
886
887 /* 
888   netr_LogonGetDomainInfo
889   this is called as part of the ADS domain logon procedure.
890 */
891 static NTSTATUS netr_LogonGetDomainInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
892                                         struct netr_LogonGetDomainInfo *r)
893 {
894         const char * const attrs[] = { "dnsDomain", "objectSid", 
895                                        "objectGUID", "flatName", "securityIdentifier",
896                                        NULL };
897         const char * const ref_attrs[] = { "nETBIOSName", NULL };
898         struct ldb_context *sam_ctx;
899         struct ldb_message **res1, **res2, **ref_res;
900         struct netr_DomainInfo1 *info1;
901         int ret, ret1, ret2, i;
902         NTSTATUS status;
903
904         const char *local_domain;
905
906         status = netr_creds_server_step_check(r->in.computer_name, mem_ctx, 
907                                               r->in.credential, 
908                                               r->out.return_authenticator,
909                                               NULL);
910         if (!NT_STATUS_IS_OK(status)) {
911                 return status;
912         }
913
914         sam_ctx = samdb_connect(mem_ctx, dce_call->conn->auth_state.session_info);
915         if (sam_ctx == NULL) {
916                 return NT_STATUS_INVALID_SYSTEM_SERVICE;
917         }
918
919         /* we need to do two searches. The first will pull our primary
920            domain and the second will pull any trusted domains. Our
921            primary domain is also a "trusted" domain, so we need to
922            put the primary domain into the lists of returned trusts as
923            well */
924         ret1 = gendb_search(sam_ctx, mem_ctx, NULL, &res1, attrs, "(objectClass=domainDNS)");
925         if (ret1 != 1) {
926                 return NT_STATUS_INTERNAL_DB_CORRUPTION;
927         }
928
929         /* try and find the domain */
930         ret = gendb_search(sam_ctx, mem_ctx, NULL, 
931                            &ref_res, ref_attrs, 
932                            "(&(objectClass=crossRef)(ncName=%s))", 
933                            ldb_dn_linearize(mem_ctx, res1[0]->dn));
934         if (ret != 1) {
935                 return NT_STATUS_INTERNAL_DB_CORRUPTION;
936         }
937
938         local_domain = samdb_result_string(ref_res[0], "nETBIOSName", NULL);
939
940         ret2 = gendb_search(sam_ctx, mem_ctx, NULL, &res2, attrs, "(objectClass=trustedDomain)");
941         if (ret2 == -1) {
942                 return NT_STATUS_INTERNAL_DB_CORRUPTION;
943         }
944
945         info1 = talloc(mem_ctx, struct netr_DomainInfo1);
946         if (info1 == NULL) {
947                 return NT_STATUS_NO_MEMORY;
948         }
949
950         ZERO_STRUCTP(info1);
951
952         info1->num_trusts = ret2 + 1;
953         info1->trusts = talloc_array(mem_ctx, struct netr_DomainTrustInfo, 
954                                        info1->num_trusts);
955         if (info1->trusts == NULL) {
956                 return NT_STATUS_NO_MEMORY;
957         }
958
959         status = fill_domain_primary_info(mem_ctx, res1[0], &info1->domaininfo, local_domain);
960         if (!NT_STATUS_IS_OK(status)) {
961                 return status;
962         }
963
964         for (i=0;i<ret2;i++) {
965                 status = fill_domain_trust_info(mem_ctx, res2[i], &info1->trusts[i], NULL, False);
966                 if (!NT_STATUS_IS_OK(status)) {
967                         return status;
968                 }
969         }
970
971         status = fill_domain_trust_info(mem_ctx, res1[0], &info1->trusts[i], local_domain, True);
972         if (!NT_STATUS_IS_OK(status)) {
973                 return status;
974         }
975
976         r->out.info.info1 = info1;
977
978         return NT_STATUS_OK;
979 }
980
981
982
983 /* 
984   netr_NETRSERVERPASSWORDGET 
985 */
986 static WERROR netr_NETRSERVERPASSWORDGET(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
987                        struct netr_NETRSERVERPASSWORDGET *r)
988 {
989         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
990 }
991
992
993 /* 
994   netr_NETRLOGONSENDTOSAM 
995 */
996 static WERROR netr_NETRLOGONSENDTOSAM(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
997                        struct netr_NETRLOGONSENDTOSAM *r)
998 {
999         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1000 }
1001
1002
1003 /* 
1004   netr_DSRADDRESSTOSITENAMESW 
1005 */
1006 static WERROR netr_DSRADDRESSTOSITENAMESW(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1007                        struct netr_DSRADDRESSTOSITENAMESW *r)
1008 {
1009         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1010 }
1011
1012
1013 /* 
1014   netr_DsRGetDCNameEx2
1015 */
1016 static WERROR netr_DsRGetDCNameEx2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1017                                    struct netr_DsRGetDCNameEx2 *r)
1018 {
1019         const char * const attrs[] = { "dnsDomain", "objectGUID", NULL };
1020         void *sam_ctx;
1021         struct ldb_message **res;
1022         int ret;
1023
1024         ZERO_STRUCT(r->out);
1025
1026         sam_ctx = samdb_connect(mem_ctx, dce_call->conn->auth_state.session_info);
1027         if (sam_ctx == NULL) {
1028                 return WERR_DS_SERVICE_UNAVAILABLE;
1029         }
1030
1031         ret = gendb_search(sam_ctx, mem_ctx, NULL, &res, attrs,
1032                                 "(&(objectClass=domainDNS)(dnsDomain=%s))",
1033                                 r->in.domain_name);
1034         if (ret != 1) {
1035                 return WERR_NO_SUCH_DOMAIN;
1036         }
1037
1038         r->out.info = talloc(mem_ctx, struct netr_DsRGetDCNameInfo);
1039         if (!r->out.info) {
1040                 return WERR_NOMEM;
1041         }
1042
1043         /* TODO: - return real IP address
1044          *       - check all r->in.* parameters (server_unc is ignored by w2k3!)
1045          */
1046         r->out.info->dc_unc             = talloc_asprintf(mem_ctx, "\\\\%s.%s", lp_netbios_name(),lp_realm());
1047         r->out.info->dc_address = talloc_strdup(mem_ctx, "\\\\0.0.0.0");
1048         r->out.info->dc_address_type    = 1;
1049         r->out.info->domain_guid        = samdb_result_guid(res[0], "objectGUID");
1050         r->out.info->domain_name        = samdb_result_string(res[0], "dnsDomain", NULL);
1051         r->out.info->forest_name        = samdb_result_string(res[0], "dnsDomain", NULL);
1052         r->out.info->dc_flags           = 0xE00001FD;
1053         r->out.info->dc_site_name       = talloc_strdup(mem_ctx, "Default-First-Site-Name");
1054         r->out.info->client_site_name   = talloc_strdup(mem_ctx, "Default-First-Site-Name");
1055
1056         return WERR_OK;
1057 }
1058
1059 /* 
1060   netr_DsRGetDCNameEx
1061 */
1062 static WERROR netr_DsRGetDCNameEx(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1063                                   struct netr_DsRGetDCNameEx *r)
1064 {
1065         struct netr_DsRGetDCNameEx2 r2;
1066         WERROR werr;
1067
1068         ZERO_STRUCT(r2);
1069
1070         r2.in.server_unc = r->in.server_unc;
1071         r2.in.client_account = NULL;
1072         r2.in.mask = 0;
1073         r2.in.domain_guid = r->in.domain_guid;
1074         r2.in.domain_name = r->in.domain_name;
1075         r2.in.site_name = r->in.site_name;
1076         r2.in.flags = r->in.flags;
1077         r2.out.info = NULL;
1078
1079         werr = netr_DsRGetDCNameEx2(dce_call, mem_ctx, &r2);
1080         
1081         r->out.info = r2.out.info;
1082         
1083         return werr;
1084 }
1085
1086 /* 
1087   netr_DsRGetDCName
1088 */
1089 static WERROR netr_DsRGetDCName(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1090                                 struct netr_DsRGetDCName *r)
1091 {
1092         struct netr_DsRGetDCNameEx2 r2;
1093         WERROR werr;
1094
1095         ZERO_STRUCT(r2);
1096
1097         r2.in.server_unc = r->in.server_unc;
1098         r2.in.client_account = NULL;
1099         r2.in.mask = 0;
1100         r2.in.domain_name = r->in.domain_name;
1101         r2.in.domain_guid = r->in.domain_guid;
1102         
1103         r2.in.site_name = NULL; /* should fill in from site GUID */
1104         r2.in.flags = r->in.flags;
1105         r2.out.info = NULL;
1106
1107         werr = netr_DsRGetDCNameEx2(dce_call, mem_ctx, &r2);
1108         
1109         r->out.info = r2.out.info;
1110         
1111         return werr;
1112 }
1113
1114 /* 
1115   netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN 
1116 */
1117 static WERROR netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1118                        struct netr_NETRLOGONGETTIMESERVICEPARENTDOMAIN *r)
1119 {
1120         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1121 }
1122
1123
1124 /* 
1125   netr_NETRENUMERATETRUSTEDDOMAINSEX 
1126 */
1127 static WERROR netr_NETRENUMERATETRUSTEDDOMAINSEX(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1128                        struct netr_NETRENUMERATETRUSTEDDOMAINSEX *r)
1129 {
1130         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1131 }
1132
1133
1134 /* 
1135   netr_DSRADDRESSTOSITENAMESEXW 
1136 */
1137 static WERROR netr_DSRADDRESSTOSITENAMESEXW(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1138                        struct netr_DSRADDRESSTOSITENAMESEXW *r)
1139 {
1140         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1141 }
1142
1143
1144 /* 
1145   netr_DSRGETDCSITECOVERAGEW 
1146 */
1147 static WERROR netr_DSRGETDCSITECOVERAGEW(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1148                        struct netr_DSRGETDCSITECOVERAGEW *r)
1149 {
1150         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1151 }
1152
1153
1154 /* 
1155   netr_DsrEnumerateDomainTrusts 
1156 */
1157 static WERROR netr_DsrEnumerateDomainTrusts(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1158                                               struct netr_DsrEnumerateDomainTrusts *r)
1159 {
1160         struct netr_DomainTrust *trusts;
1161         void *sam_ctx;
1162         int ret;
1163         struct ldb_message **dom_res, **ref_res;
1164         const char * const dom_attrs[] = { "dnsDomain", "objectSid", "objectGUID", NULL };
1165         const char * const ref_attrs[] = { "nETBIOSName", NULL };
1166
1167         ZERO_STRUCT(r->out);
1168
1169         sam_ctx = samdb_connect(mem_ctx, dce_call->conn->auth_state.session_info);
1170         if (sam_ctx == NULL) {
1171                 return WERR_GENERAL_FAILURE;
1172         }
1173
1174         ret = gendb_search_dn(sam_ctx, mem_ctx, samdb_base_dn(mem_ctx), &dom_res, dom_attrs);
1175         if (ret == -1) {
1176                 return WERR_GENERAL_FAILURE;            
1177         }
1178
1179         if (ret != 1) {
1180                 return WERR_GENERAL_FAILURE;
1181         }
1182
1183         ret = gendb_search(sam_ctx, mem_ctx, NULL, &ref_res, ref_attrs,
1184                            "(&(objectClass=crossRef)(ncName=%s))",
1185                            ldb_dn_linearize(mem_ctx, dom_res[0]->dn));
1186         if (ret == -1) {
1187                 return WERR_GENERAL_FAILURE;
1188         }
1189
1190         if (ret != 1) {
1191                 return WERR_GENERAL_FAILURE;
1192         }
1193
1194
1195
1196         trusts = talloc_array(mem_ctx, struct netr_DomainTrust, ret);
1197         if (trusts == NULL) {
1198                 return WERR_NOMEM;
1199         }
1200         
1201         r->out.count = 1;
1202         r->out.trusts = trusts;
1203
1204         /* TODO: add filtering by trust_flags, and correct trust_type
1205            and attributes */
1206         trusts[0].netbios_name = samdb_result_string(ref_res[0], "nETBIOSName", NULL);
1207         trusts[0].dns_name     = samdb_result_string(dom_res[0], "dnsDomain", NULL);
1208         trusts[0].trust_flags = 
1209                 NETR_TRUST_FLAG_TREEROOT | 
1210                 NETR_TRUST_FLAG_IN_FOREST | 
1211                 NETR_TRUST_FLAG_PRIMARY;
1212         trusts[0].parent_index = 0;
1213         trusts[0].trust_type = 2;
1214         trusts[0].trust_attributes = 0;
1215         trusts[0].sid  = samdb_result_dom_sid(mem_ctx, dom_res[0], "objectSid");
1216         trusts[0].guid = samdb_result_guid(dom_res[0], "objectGUID");
1217
1218         return WERR_OK;
1219 }
1220
1221
1222 /* 
1223   netr_DSRDEREGISTERDNSHOSTRECORDS 
1224 */
1225 static WERROR netr_DSRDEREGISTERDNSHOSTRECORDS(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1226                        struct netr_DSRDEREGISTERDNSHOSTRECORDS *r)
1227 {
1228         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1229 }
1230
1231
1232 /* 
1233   netr_NETRSERVERTRUSTPASSWORDSGET 
1234 */
1235 static WERROR netr_NETRSERVERTRUSTPASSWORDSGET(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1236                        struct netr_NETRSERVERTRUSTPASSWORDSGET *r)
1237 {
1238         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1239 }
1240
1241
1242 /* 
1243   netr_DSRGETFORESTTRUSTINFORMATION 
1244 */
1245 static WERROR netr_DSRGETFORESTTRUSTINFORMATION(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1246                        struct netr_DSRGETFORESTTRUSTINFORMATION *r)
1247 {
1248         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1249 }
1250
1251
1252 /* 
1253   netr_NETRGETFORESTTRUSTINFORMATION 
1254 */
1255 static WERROR netr_NETRGETFORESTTRUSTINFORMATION(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1256                        struct netr_NETRGETFORESTTRUSTINFORMATION *r)
1257 {
1258         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1259 }
1260
1261
1262 /* 
1263   netr_NETRSERVERGETTRUSTINFO 
1264 */
1265 static WERROR netr_NETRSERVERGETTRUSTINFO(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx,
1266                        struct netr_NETRSERVERGETTRUSTINFO *r)
1267 {
1268         DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR);
1269 }
1270
1271
1272 /* include the generated boilerplate */
1273 #include "librpc/gen_ndr/ndr_netlogon_s.c"