added netr_LogonControl2Ex()
[jelmer/samba4-debian.git] / source / torture / rpc / netlogon.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    test suite for netlogon rpc operations
5
6    Copyright (C) Andrew Tridgell 2003
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24
25
26 static BOOL test_LogonUasLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
27 {
28         NTSTATUS status;
29         struct netr_LogonUasLogon r;
30
31         r.in.server_name = NULL;
32         r.in.username = lp_parm_string(-1, "torture", "username");
33         r.in.workstation = lp_netbios_name();
34
35         printf("Testing LogonUasLogon\n");
36
37         status = dcerpc_netr_LogonUasLogon(p, mem_ctx, &r);
38         if (!NT_STATUS_IS_OK(status)) {
39                 printf("LogonUasLogon - %s\n", nt_errstr(status));
40                 return False;
41         }
42
43         return True;
44         
45 }
46
47 static BOOL test_LogonUasLogoff(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
48 {
49         NTSTATUS status;
50         struct netr_LogonUasLogoff r;
51
52         r.in.server_name = NULL;
53         r.in.username = lp_parm_string(-1, "torture", "username");
54         r.in.workstation = lp_netbios_name();
55
56         printf("Testing LogonUasLogoff\n");
57
58         status = dcerpc_netr_LogonUasLogoff(p, mem_ctx, &r);
59         if (!NT_STATUS_IS_OK(status)) {
60                 printf("LogonUasLogoff - %s\n", nt_errstr(status));
61                 return False;
62         }
63
64         return True;
65         
66 }
67
68 static BOOL test_SetupCredentials(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
69                                   struct netr_CredentialState *creds)
70 {
71         NTSTATUS status;
72         struct netr_ServerReqChallenge r;
73         struct netr_ServerAuthenticate a;
74         const char *plain_pass;
75         uint8 mach_pwd[16];
76
77         printf("Testing ServerReqChallenge\n");
78
79         r.in.server_name = NULL;
80         r.in.computer_name = lp_netbios_name();
81         generate_random_buffer(r.in.credentials.data, sizeof(r.in.credentials.data), False);
82
83         status = dcerpc_netr_ServerReqChallenge(p, mem_ctx, &r);
84         if (!NT_STATUS_IS_OK(status)) {
85                 printf("ServerReqChallenge - %s\n", nt_errstr(status));
86                 return False;
87         }
88
89         plain_pass = secrets_fetch_machine_password();
90         if (!plain_pass) {
91                 printf("Unable to fetch machine password!\n");
92                 return False;
93         }
94
95         E_md4hash(plain_pass, mach_pwd);
96
97         creds_client_init(creds, &r.in.credentials, &r.out.credentials, mach_pwd,
98                           &a.in.credentials);
99
100         a.in.server_name = NULL;
101         a.in.username = talloc_asprintf(mem_ctx, "%s$", lp_netbios_name());
102         a.in.secure_channel_type = SEC_CHAN_BDC;
103         a.in.computer_name = lp_netbios_name();
104
105         printf("Testing ServerAuthenticate\n");
106
107         status = dcerpc_netr_ServerAuthenticate(p, mem_ctx, &a);
108         if (!NT_STATUS_IS_OK(status)) {
109                 printf("ServerAuthenticate - %s\n", nt_errstr(status));
110                 return False;
111         }
112
113         if (!creds_client_check(creds, &a.out.credentials)) {
114                 printf("Credential chaining failed\n");
115                 return False;
116         }
117
118         return True;
119 }
120
121 static BOOL test_SetupCredentials2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
122                                    struct netr_CredentialState *creds)
123 {
124         NTSTATUS status;
125         struct netr_ServerReqChallenge r;
126         struct netr_ServerAuthenticate2 a;
127         const char *plain_pass;
128         uint8 mach_pwd[16];
129         uint32 negotiate_flags = 0;
130
131         printf("Testing ServerReqChallenge\n");
132
133         r.in.server_name = NULL;
134         r.in.computer_name = lp_netbios_name();
135         generate_random_buffer(r.in.credentials.data, sizeof(r.in.credentials.data), False);
136
137         status = dcerpc_netr_ServerReqChallenge(p, mem_ctx, &r);
138         if (!NT_STATUS_IS_OK(status)) {
139                 printf("ServerReqChallenge - %s\n", nt_errstr(status));
140                 return False;
141         }
142
143         plain_pass = secrets_fetch_machine_password();
144         if (!plain_pass) {
145                 printf("Unable to fetch machine password!\n");
146                 return False;
147         }
148
149         E_md4hash(plain_pass, mach_pwd);
150
151         creds_client_init(creds, &r.in.credentials, &r.out.credentials, mach_pwd,
152                           &a.in.credentials);
153
154         a.in.server_name = NULL;
155         a.in.username = talloc_asprintf(mem_ctx, "%s$", lp_netbios_name());
156         a.in.secure_channel_type = SEC_CHAN_BDC;
157         a.in.computer_name = lp_netbios_name();
158         a.in.negotiate_flags = &negotiate_flags;
159         a.out.negotiate_flags = &negotiate_flags;
160
161         printf("Testing ServerAuthenticate2\n");
162
163         status = dcerpc_netr_ServerAuthenticate2(p, mem_ctx, &a);
164         if (!NT_STATUS_IS_OK(status)) {
165                 printf("ServerAuthenticate2 - %s\n", nt_errstr(status));
166                 return False;
167         }
168
169         if (!creds_client_check(creds, &a.out.credentials)) {
170                 printf("Credential chaining failed\n");
171                 return False;
172         }
173
174         printf("negotiate_flags=0x%08x\n", negotiate_flags);
175
176         return True;
177 }
178
179 /*
180   try a netlogon SamLogon
181 */
182 static BOOL test_SamLogon(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
183 {
184         NTSTATUS status;
185         struct netr_LogonSamLogon r;
186         struct netr_Authenticator auth, auth2;
187         struct netr_NetworkInfo ninfo;
188         const char *username = lp_parm_string(-1, "torture", "username");
189         const char *password = lp_parm_string(-1, "torture", "password");
190         struct netr_CredentialState creds;
191
192         if (!test_SetupCredentials2(p, mem_ctx, &creds)) {
193                 return False;
194         }
195
196         ninfo.logon_info.domain_name.string = lp_workgroup();
197         ninfo.logon_info.parameter_control = 0;
198         ninfo.logon_info.logon_id_low = 0;
199         ninfo.logon_info.logon_id_high = 0;
200         ninfo.logon_info.username.string = username;
201         ninfo.logon_info.workstation.string = lp_netbios_name();
202         generate_random_buffer(ninfo.challenge, 
203                                sizeof(ninfo.challenge), False);
204         ninfo.nt.length = 24;
205         ninfo.nt.data = talloc(mem_ctx, 24);
206         SMBNTencrypt(password, ninfo.challenge, ninfo.nt.data);
207         ninfo.lm.length = 24;
208         ninfo.lm.data = talloc(mem_ctx, 24);
209         SMBencrypt(password, ninfo.challenge, ninfo.lm.data);
210
211         ZERO_STRUCT(auth2);
212
213         creds_client_authenticator(&creds, &auth);
214
215         r.in.server_name = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
216         r.in.workstation = lp_netbios_name();
217         r.in.credential = &auth;
218         r.in.authenticator = &auth2;
219         r.in.logon_level = 2;
220         r.in.logon.network = &ninfo;
221         r.in.validation_level = 2;
222
223         printf("Testing SamLogon\n");
224
225         status = dcerpc_netr_LogonSamLogon(p, mem_ctx, &r);
226         if (!NT_STATUS_IS_OK(status)) {
227                 printf("LogonSamLogon - %s\n", nt_errstr(status));
228                 return False;
229         }
230
231         if (!creds_client_check(&creds, &r.out.authenticator->cred)) {
232                 printf("Credential chaining failed\n");
233         }
234
235         return True;
236 }
237
238
239 /*
240   try a change password for our machine account
241 */
242 static BOOL test_SetPassword(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
243 {
244         NTSTATUS status;
245         struct netr_ServerPasswordSet r;
246         const char *password;
247         struct netr_CredentialState creds;
248
249         if (!test_SetupCredentials(p, mem_ctx, &creds)) {
250                 return False;
251         }
252
253         r.in.server_name = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
254         r.in.username = talloc_asprintf(mem_ctx, "%s$", lp_netbios_name());
255         r.in.secure_channel_type = SEC_CHAN_BDC;
256         r.in.computer_name = lp_netbios_name();
257
258         password = generate_random_str(8);
259         E_md4hash(password, r.in.new_password.data);
260
261         creds_client_encrypt(&creds, &r.in.new_password);
262
263         printf("Testing ServerPasswordSet on machine account\n");
264
265         creds_client_authenticator(&creds, &r.in.credential);
266
267         status = dcerpc_netr_ServerPasswordSet(p, mem_ctx, &r);
268         if (!NT_STATUS_IS_OK(status)) {
269                 printf("ServerPasswordSet - %s\n", nt_errstr(status));
270                 return False;
271         }
272
273         if (!secrets_store_machine_password(password)) {
274                 printf("Failed to save machine password\n");
275         }
276
277         if (!creds_client_check(&creds, &r.out.return_authenticator.cred)) {
278                 printf("Credential chaining failed\n");
279         }
280
281         /* by changing the machine password twice we test the credentials
282            chaining fully */
283         printf("Testing a second ServerPasswordSet on machine account\n");
284
285         creds_client_authenticator(&creds, &r.in.credential);
286
287         status = dcerpc_netr_ServerPasswordSet(p, mem_ctx, &r);
288         if (!NT_STATUS_IS_OK(status)) {
289                 printf("ServerPasswordSet - %s\n", nt_errstr(status));
290                 return False;
291         }
292
293         if (!creds_client_check(&creds, &r.out.return_authenticator.cred)) {
294                 printf("Credential chaining failed\n");
295         }
296
297         return True;
298 }
299
300
301 /* we remember the sequence numbers so we can easily do a DatabaseDelta */
302 static struct ULONG8 sequence_nums[3];
303
304 /*
305   try a netlogon DatabaseSync
306 */
307 static BOOL test_DatabaseSync(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
308 {
309         NTSTATUS status;
310         struct netr_DatabaseSync r;
311         struct netr_CredentialState creds;
312         const uint32 database_ids[] = {0, 1, 2}; 
313         int i;
314         BOOL ret = True;
315
316         if (!test_SetupCredentials(p, mem_ctx, &creds)) {
317                 return False;
318         }
319
320         r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
321         r.in.computername = lp_netbios_name();
322         r.in.preferredmaximumlength = (uint32)-1;
323         ZERO_STRUCT(r.in.return_authenticator);
324
325         for (i=0;i<ARRAY_SIZE(database_ids);i++) {
326                 r.in.sync_context = 0;
327                 r.in.database_id = database_ids[i];
328
329                 printf("Testing DatabaseSync of id %d\n", r.in.database_id);
330
331                 do {
332                         creds_client_authenticator(&creds, &r.in.credential);
333
334                         status = dcerpc_netr_DatabaseSync(p, mem_ctx, &r);
335                         if (!NT_STATUS_IS_OK(status) &&
336                             !NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) {
337                                 printf("DatabaseSync - %s\n", nt_errstr(status));
338                                 ret = False;
339                                 break;
340                         }
341
342                         if (!creds_client_check(&creds, &r.out.return_authenticator.cred)) {
343                                 printf("Credential chaining failed\n");
344                         }
345
346                         r.in.sync_context = r.out.sync_context;
347
348                         if (r.out.delta_enum_array &&
349                             r.out.delta_enum_array->num_deltas > 0 &&
350                             r.out.delta_enum_array->delta_enum[0].delta_type == 1 &&
351                             r.out.delta_enum_array->delta_enum[0].delta_union.domain) {
352                                 sequence_nums[r.in.database_id] = 
353                                         r.out.delta_enum_array->delta_enum[0].delta_union.domain->sequence_num;
354                                 printf("\tsequence_nums[%d]=0x%08x%08x\n",
355                                        r.in.database_id, 
356                                        sequence_nums[r.in.database_id].high,
357                                        sequence_nums[r.in.database_id].low);
358                         }
359                 } while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES));
360         }
361
362         return ret;
363 }
364
365
366 /*
367   try a netlogon DatabaseDeltas
368 */
369 static BOOL test_DatabaseDeltas(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
370 {
371         NTSTATUS status;
372         struct netr_DatabaseDeltas r;
373         struct netr_CredentialState creds;
374         const uint32 database_ids[] = {0, 1, 2}; 
375         int i;
376         BOOL ret = True;
377
378         if (!test_SetupCredentials(p, mem_ctx, &creds)) {
379                 return False;
380         }
381
382         r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
383         r.in.computername = lp_netbios_name();
384         r.in.preferredmaximumlength = (uint32)-1;
385         ZERO_STRUCT(r.in.return_authenticator);
386
387         for (i=0;i<ARRAY_SIZE(database_ids);i++) {
388                 r.in.database_id = database_ids[i];
389                 r.in.sequence_num = sequence_nums[r.in.database_id];
390                 r.in.sequence_num.low -= 1;
391
392                 printf("Testing DatabaseDeltas of id %d at %d\n", 
393                        r.in.database_id, r.in.sequence_num.low);
394
395                 do {
396                         creds_client_authenticator(&creds, &r.in.credential);
397
398                         status = dcerpc_netr_DatabaseDeltas(p, mem_ctx, &r);
399                         if (!NT_STATUS_IS_OK(status) &&
400                             !NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) {
401                                 printf("DatabaseDeltas - %s\n", nt_errstr(status));
402                                 ret = False;
403                                 break;
404                         }
405
406                         if (!creds_client_check(&creds, &r.out.return_authenticator.cred)) {
407                                 printf("Credential chaining failed\n");
408                         }
409
410                         r.in.sequence_num.low++;
411                         r.in.sequence_num.high = 0;
412                 } while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES));
413         }
414
415         return ret;
416 }
417
418
419 /*
420   try a netlogon AccountDeltas
421 */
422 static BOOL test_AccountDeltas(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
423 {
424         NTSTATUS status;
425         struct netr_AccountDeltas r;
426         struct netr_CredentialState creds;
427         BOOL ret = True;
428
429         if (!test_SetupCredentials(p, mem_ctx, &creds)) {
430                 return False;
431         }
432
433         r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
434         r.in.computername = lp_netbios_name();
435         ZERO_STRUCT(r.in.return_authenticator);
436         creds_client_authenticator(&creds, &r.in.credential);
437         ZERO_STRUCT(r.in.uas);
438         r.in.count=10;
439         r.in.level=0;
440         r.in.buffersize=100;
441
442         printf("Testing AccountDeltas\n");
443
444         /* w2k3 returns "NOT IMPLEMENTED" for this call */
445         status = dcerpc_netr_AccountDeltas(p, mem_ctx, &r);
446         if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED)) {
447                 printf("AccountDeltas - %s\n", nt_errstr(status));
448                 ret = False;
449         }
450
451         return ret;
452 }
453
454 /*
455   try a netlogon AccountSync
456 */
457 static BOOL test_AccountSync(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
458 {
459         NTSTATUS status;
460         struct netr_AccountSync r;
461         struct netr_CredentialState creds;
462         BOOL ret = True;
463
464         if (!test_SetupCredentials(p, mem_ctx, &creds)) {
465                 return False;
466         }
467
468         r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
469         r.in.computername = lp_netbios_name();
470         ZERO_STRUCT(r.in.return_authenticator);
471         creds_client_authenticator(&creds, &r.in.credential);
472         ZERO_STRUCT(r.in.recordid);
473         r.in.reference=0;
474         r.in.level=0;
475         r.in.buffersize=100;
476
477         printf("Testing AccountSync\n");
478
479         /* w2k3 returns "NOT IMPLEMENTED" for this call */
480         status = dcerpc_netr_AccountSync(p, mem_ctx, &r);
481         if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED)) {
482                 printf("AccountSync - %s\n", nt_errstr(status));
483                 ret = False;
484         }
485
486         return ret;
487 }
488
489 /*
490   try a netlogon GetDcName
491 */
492 static BOOL test_GetDcName(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
493 {
494         NTSTATUS status;
495         struct netr_GetDcName r;
496
497         r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
498         r.in.domainname = lp_workgroup();
499
500         printf("Testing GetDcName\n");
501
502         status = dcerpc_netr_GetDcName(p, mem_ctx, &r);
503         if (!NT_STATUS_IS_OK(status)) {
504                 printf("GetDcName - %s\n", nt_errstr(status));
505                 return False;
506         }
507
508         printf("\tDC is at '%s'\n", r.out.dcname);
509
510         return True;
511 }
512
513 /*
514   try a netlogon LogonControl 
515 */
516 static BOOL test_LogonControl(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
517 {
518         NTSTATUS status;
519         struct netr_LogonControl r;
520         BOOL ret = True;
521         int i;
522
523         r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
524         r.in.function_code = 1;
525
526         for (i=1;i<4;i++) {
527                 r.in.level = i;
528
529                 printf("Testing LogonControl level %d\n", i);
530
531                 status = dcerpc_netr_LogonControl(p, mem_ctx, &r);
532                 if (!NT_STATUS_IS_OK(status)) {
533                         printf("LogonControl - %s\n", nt_errstr(status));
534                         ret = False;
535                 }
536         }
537
538         return ret;
539 }
540
541
542 /*
543   try a netlogon GetAnyDCName
544 */
545 static BOOL test_GetAnyDCName(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
546 {
547         NTSTATUS status;
548         struct netr_GetAnyDCName r;
549
550         r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
551         r.in.domainname = lp_workgroup();
552
553         printf("Testing GetAnyDCName\n");
554
555         status = dcerpc_netr_GetAnyDCName(p, mem_ctx, &r);
556         if (!NT_STATUS_IS_OK(status)) {
557                 printf("GetAnyDCName - %s\n", nt_errstr(status));
558                 return False;
559         }
560
561         if (r.out.dcname) {
562                 printf("\tDC is at '%s'\n", r.out.dcname);
563         }
564
565         return True;
566 }
567
568
569 /*
570   try a netlogon LogonControl2
571 */
572 static BOOL test_LogonControl2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
573 {
574         NTSTATUS status;
575         struct netr_LogonControl2 r;
576         BOOL ret = True;
577         int i;
578
579         r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
580
581         r.in.function_code = NETLOGON_CONTROL_REDISCOVER;
582         r.in.data.domain = lp_workgroup();
583
584         for (i=1;i<4;i++) {
585                 r.in.level = i;
586
587                 printf("Testing LogonControl2 level %d function %d\n", 
588                        i, r.in.function_code);
589
590                 status = dcerpc_netr_LogonControl2(p, mem_ctx, &r);
591                 if (!NT_STATUS_IS_OK(status)) {
592                         printf("LogonControl - %s\n", nt_errstr(status));
593                         ret = False;
594                 }
595         }
596
597         r.in.function_code = NETLOGON_CONTROL_TC_QUERY;
598         r.in.data.domain = lp_workgroup();
599
600         for (i=1;i<4;i++) {
601                 r.in.level = i;
602
603                 printf("Testing LogonControl2 level %d function %d\n", 
604                        i, r.in.function_code);
605
606                 status = dcerpc_netr_LogonControl2(p, mem_ctx, &r);
607                 if (!NT_STATUS_IS_OK(status)) {
608                         printf("LogonControl - %s\n", nt_errstr(status));
609                         ret = False;
610                 }
611         }
612
613         r.in.function_code = NETLOGON_CONTROL_TRANSPORT_NOTIFY;
614         r.in.data.domain = lp_workgroup();
615
616         for (i=1;i<4;i++) {
617                 r.in.level = i;
618
619                 printf("Testing LogonControl2 level %d function %d\n", 
620                        i, r.in.function_code);
621
622                 status = dcerpc_netr_LogonControl2(p, mem_ctx, &r);
623                 if (!NT_STATUS_IS_OK(status)) {
624                         printf("LogonControl - %s\n", nt_errstr(status));
625                         ret = False;
626                 }
627         }
628
629         r.in.function_code = NETLOGON_CONTROL_SET_DBFLAG;
630         r.in.data.debug_level = ~0;
631
632         for (i=1;i<4;i++) {
633                 r.in.level = i;
634
635                 printf("Testing LogonControl2 level %d function %d\n", 
636                        i, r.in.function_code);
637
638                 status = dcerpc_netr_LogonControl2(p, mem_ctx, &r);
639                 if (!NT_STATUS_IS_OK(status)) {
640                         printf("LogonControl - %s\n", nt_errstr(status));
641                         ret = False;
642                 }
643         }
644
645         return ret;
646 }
647
648 /*
649   try a netlogon DatabaseSync2
650 */
651 static BOOL test_DatabaseSync2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
652 {
653         NTSTATUS status;
654         struct netr_DatabaseSync2 r;
655         struct netr_CredentialState creds;
656         const uint32 database_ids[] = {0, 1, 2}; 
657         int i;
658         BOOL ret = True;
659
660         if (!test_SetupCredentials2(p, mem_ctx, &creds)) {
661                 return False;
662         }
663
664         r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
665         r.in.computername = lp_netbios_name();
666         r.in.preferredmaximumlength = (uint32)-1;
667         ZERO_STRUCT(r.in.return_authenticator);
668
669         for (i=0;i<ARRAY_SIZE(database_ids);i++) {
670                 r.in.sync_context = 0;
671                 r.in.database_id = database_ids[i];
672                 r.in.restart_state = 0;
673
674                 printf("Testing DatabaseSync2 of id %d\n", r.in.database_id);
675
676                 do {
677                         creds_client_authenticator(&creds, &r.in.credential);
678
679                         status = dcerpc_netr_DatabaseSync2(p, mem_ctx, &r);
680                         if (!NT_STATUS_IS_OK(status) &&
681                             !NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) {
682                                 printf("DatabaseSync2 - %s\n", nt_errstr(status));
683                                 ret = False;
684                                 break;
685                         }
686
687                         if (!creds_client_check(&creds, &r.out.return_authenticator.cred)) {
688                                 printf("Credential chaining failed\n");
689                         }
690
691                         r.in.sync_context = r.out.sync_context;
692                 } while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES));
693         }
694
695         return ret;
696 }
697
698
699 /*
700   try a netlogon LogonControl2Ex
701 */
702 static BOOL test_LogonControl2Ex(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
703 {
704         NTSTATUS status;
705         struct netr_LogonControl2Ex r;
706         BOOL ret = True;
707         int i;
708
709         r.in.logon_server = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
710
711         r.in.function_code = NETLOGON_CONTROL_REDISCOVER;
712         r.in.data.domain = lp_workgroup();
713
714         for (i=1;i<4;i++) {
715                 r.in.level = i;
716
717                 printf("Testing LogonControl2Ex level %d function %d\n", 
718                        i, r.in.function_code);
719
720                 status = dcerpc_netr_LogonControl2Ex(p, mem_ctx, &r);
721                 if (!NT_STATUS_IS_OK(status)) {
722                         printf("LogonControl - %s\n", nt_errstr(status));
723                         ret = False;
724                 }
725         }
726
727         r.in.function_code = NETLOGON_CONTROL_TC_QUERY;
728         r.in.data.domain = lp_workgroup();
729
730         for (i=1;i<4;i++) {
731                 r.in.level = i;
732
733                 printf("Testing LogonControl2Ex level %d function %d\n", 
734                        i, r.in.function_code);
735
736                 status = dcerpc_netr_LogonControl2Ex(p, mem_ctx, &r);
737                 if (!NT_STATUS_IS_OK(status)) {
738                         printf("LogonControl - %s\n", nt_errstr(status));
739                         ret = False;
740                 }
741         }
742
743         r.in.function_code = NETLOGON_CONTROL_TRANSPORT_NOTIFY;
744         r.in.data.domain = lp_workgroup();
745
746         for (i=1;i<4;i++) {
747                 r.in.level = i;
748
749                 printf("Testing LogonControl2Ex level %d function %d\n", 
750                        i, r.in.function_code);
751
752                 status = dcerpc_netr_LogonControl2Ex(p, mem_ctx, &r);
753                 if (!NT_STATUS_IS_OK(status)) {
754                         printf("LogonControl - %s\n", nt_errstr(status));
755                         ret = False;
756                 }
757         }
758
759         r.in.function_code = NETLOGON_CONTROL_SET_DBFLAG;
760         r.in.data.debug_level = ~0;
761
762         for (i=1;i<4;i++) {
763                 r.in.level = i;
764
765                 printf("Testing LogonControl2Ex level %d function %d\n", 
766                        i, r.in.function_code);
767
768                 status = dcerpc_netr_LogonControl2Ex(p, mem_ctx, &r);
769                 if (!NT_STATUS_IS_OK(status)) {
770                         printf("LogonControl - %s\n", nt_errstr(status));
771                         ret = False;
772                 }
773         }
774
775         return ret;
776 }
777
778
779
780 BOOL torture_rpc_netlogon(int dummy)
781 {
782         NTSTATUS status;
783         struct dcerpc_pipe *p;
784         TALLOC_CTX *mem_ctx;
785         BOOL ret = True;
786
787         mem_ctx = talloc_init("torture_rpc_netlogon");
788
789         status = torture_rpc_connection(&p, 
790                                         DCERPC_NETLOGON_NAME,
791                                         DCERPC_NETLOGON_UUID,
792                                         DCERPC_NETLOGON_VERSION);
793         if (!NT_STATUS_IS_OK(status)) {
794                 return False;
795         }
796         
797         p->flags |= DCERPC_DEBUG_PRINT_BOTH;
798
799         if (!test_LogonUasLogon(p, mem_ctx)) {
800                 ret = False;
801         }
802
803         if (!test_LogonUasLogoff(p, mem_ctx)) {
804                 ret = False;
805         }
806
807         if (!test_SetPassword(p, mem_ctx)) {
808                 ret = False;
809         }
810
811         if (!test_SamLogon(p, mem_ctx)) {
812                 ret = False;
813         }
814
815         if (!test_DatabaseSync(p, mem_ctx)) {
816                 ret = False;
817         }
818
819         if (!test_DatabaseDeltas(p, mem_ctx)) {
820                 ret = False;
821         }
822
823         if (!test_AccountDeltas(p, mem_ctx)) {
824                 ret = False;
825         }
826
827         if (!test_AccountSync(p, mem_ctx)) {
828                 ret = False;
829         }
830
831         if (!test_GetDcName(p, mem_ctx)) {
832                 ret = False;
833         }
834
835         if (!test_LogonControl(p, mem_ctx)) {
836                 ret = False;
837         }
838
839         if (!test_GetAnyDCName(p, mem_ctx)) {
840                 ret = False;
841         }
842
843         if (!test_LogonControl2(p, mem_ctx)) {
844                 ret = False;
845         }
846
847         if (!test_DatabaseSync2(p, mem_ctx)) {
848                 ret = False;
849         }
850
851         if (!test_LogonControl2Ex(p, mem_ctx)) {
852                 ret = False;
853         }
854
855         torture_rpc_close(p);
856
857         return ret;
858 }