r4603: Test creating local and global secrets over LSA.
[ira/wip.git] / source4 / torture / rpc / lsa.c
1 /* 
2    Unix SMB/CIFS implementation.
3    test suite for lsa rpc operations
4
5    Copyright (C) Andrew Tridgell 2003
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23 #include "librpc/gen_ndr/ndr_lsa.h"
24
25 static void init_lsa_String(struct lsa_String *name, const char *s)
26 {
27         name->string = s;
28 }
29
30 static BOOL test_OpenPolicy(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
31 {
32         struct lsa_ObjectAttribute attr;
33         struct policy_handle handle;
34         struct lsa_QosInfo qos;
35         struct lsa_OpenPolicy r;
36         NTSTATUS status;
37         uint16_t system_name = '\\';
38
39         printf("\ntesting OpenPolicy\n");
40
41         qos.len = 0;
42         qos.impersonation_level = 2;
43         qos.context_mode = 1;
44         qos.effective_only = 0;
45
46         attr.len = 0;
47         attr.root_dir = NULL;
48         attr.object_name = NULL;
49         attr.attributes = 0;
50         attr.sec_desc = NULL;
51         attr.sec_qos = &qos;
52
53         r.in.system_name = &system_name;
54         r.in.attr = &attr;
55         r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
56         r.out.handle = &handle;
57
58         status = dcerpc_lsa_OpenPolicy(p, mem_ctx, &r);
59         if (!NT_STATUS_IS_OK(status)) {
60                 printf("OpenPolicy failed - %s\n", nt_errstr(status));
61                 return False;
62         }
63
64         return True;
65 }
66
67
68 static BOOL test_OpenPolicy2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
69                              struct policy_handle *handle)
70 {
71         struct lsa_ObjectAttribute attr;
72         struct lsa_QosInfo qos;
73         struct lsa_OpenPolicy2 r;
74         NTSTATUS status;
75
76         printf("\ntesting OpenPolicy2\n");
77
78         qos.len = 0;
79         qos.impersonation_level = 2;
80         qos.context_mode = 1;
81         qos.effective_only = 0;
82
83         attr.len = 0;
84         attr.root_dir = NULL;
85         attr.object_name = NULL;
86         attr.attributes = 0;
87         attr.sec_desc = NULL;
88         attr.sec_qos = &qos;
89
90         r.in.system_name = "\\";
91         r.in.attr = &attr;
92         r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
93         r.out.handle = handle;
94
95         status = dcerpc_lsa_OpenPolicy2(p, mem_ctx, &r);
96         if (!NT_STATUS_IS_OK(status)) {
97                 printf("OpenPolicy2 failed - %s\n", nt_errstr(status));
98                 return False;
99         }
100
101         return True;
102 }
103
104 static BOOL test_LookupNames(struct dcerpc_pipe *p, 
105                             TALLOC_CTX *mem_ctx, 
106                             struct policy_handle *handle,
107                             struct lsa_TransNameArray *tnames)
108 {
109         struct lsa_LookupNames r;
110         struct lsa_TransSidArray sids;
111         struct lsa_String *names;
112         uint32_t count = 0;
113         NTSTATUS status;
114         int i;
115
116         printf("\nTesting LookupNames with %d names\n", tnames->count);
117
118         sids.count = 0;
119         sids.sids = NULL;
120
121         names = talloc_array_p(mem_ctx, struct lsa_String, tnames->count);
122         for (i=0;i<tnames->count;i++) {
123                 init_lsa_String(&names[i], tnames->names[i].name.string);
124         }
125
126         r.in.handle = handle;
127         r.in.num_names = tnames->count;
128         r.in.names = names;
129         r.in.sids = &sids;
130         r.in.level = 1;
131         r.in.count = &count;
132         r.out.count = &count;
133         r.out.sids = &sids;
134
135         status = dcerpc_lsa_LookupNames(p, mem_ctx, &r);
136         if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
137                 printf("LookupNames failed - %s\n", nt_errstr(status));
138                 return False;
139         }
140
141         printf("\n");
142
143         return True;
144 }
145
146 static BOOL test_LookupNames2(struct dcerpc_pipe *p, 
147                               TALLOC_CTX *mem_ctx, 
148                               struct policy_handle *handle,
149                               struct lsa_TransNameArray2 *tnames)
150 {
151         struct lsa_LookupNames2 r;
152         struct lsa_TransSidArray2 sids;
153         struct lsa_String *names;
154         uint32_t count = 0;
155         NTSTATUS status;
156         int i;
157
158         printf("\nTesting LookupNames2 with %d names\n", tnames->count);
159
160         sids.count = 0;
161         sids.sids = NULL;
162
163         names = talloc_array_p(mem_ctx, struct lsa_String, tnames->count);
164         for (i=0;i<tnames->count;i++) {
165                 init_lsa_String(&names[i], tnames->names[i].name.string);
166         }
167
168         r.in.handle = handle;
169         r.in.num_names = tnames->count;
170         r.in.names = names;
171         r.in.sids = &sids;
172         r.in.level = 1;
173         r.in.count = &count;
174         r.in.unknown1 = 0;
175         r.in.unknown2 = 0;
176         r.out.count = &count;
177         r.out.sids = &sids;
178
179         status = dcerpc_lsa_LookupNames2(p, mem_ctx, &r);
180         if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
181                 printf("LookupNames2 failed - %s\n", nt_errstr(status));
182                 return False;
183         }
184
185         printf("\n");
186
187         return True;
188 }
189
190
191 static BOOL test_LookupNames3(struct dcerpc_pipe *p, 
192                               TALLOC_CTX *mem_ctx, 
193                               struct policy_handle *handle,
194                               struct lsa_TransNameArray2 *tnames)
195 {
196         struct lsa_LookupNames3 r;
197         struct lsa_TransSidArray3 sids;
198         struct lsa_String *names;
199         uint32_t count = 0;
200         NTSTATUS status;
201         int i;
202
203         printf("\nTesting LookupNames3 with %d names\n", tnames->count);
204
205         sids.count = 0;
206         sids.sids = NULL;
207
208         names = talloc_array_p(mem_ctx, struct lsa_String, tnames->count);
209         for (i=0;i<tnames->count;i++) {
210                 init_lsa_String(&names[i], tnames->names[i].name.string);
211         }
212
213         r.in.handle = handle;
214         r.in.num_names = tnames->count;
215         r.in.names = names;
216         r.in.sids = &sids;
217         r.in.level = 1;
218         r.in.count = &count;
219         r.in.unknown1 = 0;
220         r.in.unknown2 = 0;
221         r.out.count = &count;
222         r.out.sids = &sids;
223
224         status = dcerpc_lsa_LookupNames3(p, mem_ctx, &r);
225         if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
226                 printf("LookupNames3 failed - %s\n", nt_errstr(status));
227                 return False;
228         }
229
230         printf("\n");
231
232         return True;
233 }
234
235
236 static BOOL test_LookupSids(struct dcerpc_pipe *p, 
237                             TALLOC_CTX *mem_ctx, 
238                             struct policy_handle *handle,
239                             struct lsa_SidArray *sids)
240 {
241         struct lsa_LookupSids r;
242         struct lsa_TransNameArray names;
243         uint32_t count = sids->num_sids;
244         NTSTATUS status;
245
246         printf("\nTesting LookupSids\n");
247
248         names.count = 0;
249         names.names = NULL;
250
251         r.in.handle = handle;
252         r.in.sids = sids;
253         r.in.names = &names;
254         r.in.level = 1;
255         r.in.count = &count;
256         r.out.count = &count;
257         r.out.names = &names;
258
259         status = dcerpc_lsa_LookupSids(p, mem_ctx, &r);
260         if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
261                 printf("LookupSids failed - %s\n", nt_errstr(status));
262                 return False;
263         }
264
265         printf("\n");
266
267         if (!test_LookupNames(p, mem_ctx, handle, &names)) {
268                 return False;
269         }
270
271         return True;
272 }
273
274
275 static BOOL test_LookupSids2(struct dcerpc_pipe *p, 
276                             TALLOC_CTX *mem_ctx, 
277                             struct policy_handle *handle,
278                             struct lsa_SidArray *sids)
279 {
280         struct lsa_LookupSids2 r;
281         struct lsa_TransNameArray2 names;
282         uint32_t count = sids->num_sids;
283         NTSTATUS status;
284
285         printf("\nTesting LookupSids2\n");
286
287         names.count = 0;
288         names.names = NULL;
289
290         r.in.handle = handle;
291         r.in.sids = sids;
292         r.in.names = &names;
293         r.in.level = 1;
294         r.in.count = &count;
295         r.in.unknown1 = 0;
296         r.in.unknown2 = 0;
297         r.out.count = &count;
298         r.out.names = &names;
299
300         status = dcerpc_lsa_LookupSids2(p, mem_ctx, &r);
301         if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
302                 printf("LookupSids2 failed - %s\n", nt_errstr(status));
303                 return False;
304         }
305
306         printf("\n");
307
308         if (!test_LookupNames2(p, mem_ctx, handle, &names)) {
309                 return False;
310         }
311
312         if (!test_LookupNames3(p, mem_ctx, handle, &names)) {
313                 return False;
314         }
315
316         return True;
317 }
318
319 static BOOL test_LookupSids3(struct dcerpc_pipe *p, 
320                             TALLOC_CTX *mem_ctx, 
321                             struct policy_handle *handle,
322                             struct lsa_SidArray *sids)
323 {
324         struct lsa_LookupSids3 r;
325         struct lsa_TransNameArray2 names;
326         uint32_t count = sids->num_sids;
327         NTSTATUS status;
328
329         printf("\nTesting LookupSids3\n");
330
331         names.count = 0;
332         names.names = NULL;
333
334         r.in.sids = sids;
335         r.in.names = &names;
336         r.in.level = 1;
337         r.in.count = &count;
338         r.in.unknown1 = 0;
339         r.in.unknown2 = 0;
340         r.out.count = &count;
341         r.out.names = &names;
342
343         status = dcerpc_lsa_LookupSids3(p, mem_ctx, &r);
344         if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
345                 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
346                     NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
347                         printf("not considering %s to be an error\n", nt_errstr(status));
348                         return True;
349                 }
350                 printf("LookupSids3 failed - %s - not considered an error\n", 
351                        nt_errstr(status));
352                 return False;
353         }
354
355         printf("\n");
356
357         if (!test_LookupNames3(p, mem_ctx, handle, &names)) {
358                 return False;
359         }
360
361         return True;
362 }
363
364 static BOOL test_many_LookupSids(struct dcerpc_pipe *p, 
365                                  TALLOC_CTX *mem_ctx, 
366                                  struct policy_handle *handle)
367 {
368         struct lsa_LookupSids r;
369         struct lsa_TransNameArray names;
370         uint32_t count;
371         NTSTATUS status;
372         struct lsa_SidArray sids;
373         int i;
374
375         printf("\nTesting LookupSids with lots of SIDs\n");
376
377         names.count = 0;
378         names.names = NULL;
379
380         sids.num_sids = 100;
381
382         sids.sids = talloc_array_p(mem_ctx, struct lsa_SidPtr, sids.num_sids);
383
384         for (i=0; i<sids.num_sids; i++) {
385                 const char *sidstr = "S-1-5-32-545";
386                 sids.sids[i].sid = dom_sid_parse_talloc(mem_ctx, sidstr);
387         }
388
389         count = sids.num_sids;
390
391         r.in.handle = handle;
392         r.in.sids = &sids;
393         r.in.names = &names;
394         r.in.level = 1;
395         r.in.count = &names.count;
396         r.out.count = &count;
397         r.out.names = &names;
398
399         status = dcerpc_lsa_LookupSids(p, mem_ctx, &r);
400         if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
401                 printf("LookupSids failed - %s\n", nt_errstr(status));
402                 return False;
403         }
404
405         printf("\n");
406
407         if (!test_LookupNames(p, mem_ctx, handle, &names)) {
408                 return False;
409         }
410
411         return True;
412 }
413
414 static BOOL test_LookupPrivValue(struct dcerpc_pipe *p, 
415                                  TALLOC_CTX *mem_ctx, 
416                                  struct policy_handle *handle,
417                                  struct lsa_String *name)
418 {
419         NTSTATUS status;
420         struct lsa_LookupPrivValue r;
421         struct lsa_LUID luid;
422
423         r.in.handle = handle;
424         r.in.name = name;
425         r.out.luid = &luid;
426
427         status = dcerpc_lsa_LookupPrivValue(p, mem_ctx, &r);
428         if (!NT_STATUS_IS_OK(status)) {
429                 printf("\nLookupPrivValue failed - %s\n", nt_errstr(status));
430                 return False;
431         }
432
433         return True;
434 }
435
436 static BOOL test_LookupPrivName(struct dcerpc_pipe *p, 
437                                 TALLOC_CTX *mem_ctx, 
438                                 struct policy_handle *handle,
439                                 struct lsa_LUID *luid)
440 {
441         NTSTATUS status;
442         struct lsa_LookupPrivName r;
443
444         r.in.handle = handle;
445         r.in.luid = luid;
446
447         status = dcerpc_lsa_LookupPrivName(p, mem_ctx, &r);
448         if (!NT_STATUS_IS_OK(status)) {
449                 printf("\nLookupPrivName failed - %s\n", nt_errstr(status));
450                 return False;
451         }
452
453         return True;
454 }
455
456 static BOOL test_RemovePrivilegesFromAccount(struct dcerpc_pipe *p, 
457                                              TALLOC_CTX *mem_ctx,                                 
458                                              struct policy_handle *acct_handle,
459                                              struct lsa_LUID *luid)
460 {
461         NTSTATUS status;
462         struct lsa_RemovePrivilegesFromAccount r;
463         struct lsa_PrivilegeSet privs;
464         BOOL ret = True;
465
466         printf("Testing RemovePrivilegesFromAccount\n");
467
468         r.in.handle = acct_handle;
469         r.in.remove_all = 0;
470         r.in.privs = &privs;
471
472         privs.count = 1;
473         privs.unknown = 0;
474         privs.set = talloc_array_p(mem_ctx, struct lsa_LUIDAttribute, 1);
475         privs.set[0].luid = *luid;
476         privs.set[0].attribute = 0;
477
478         status = dcerpc_lsa_RemovePrivilegesFromAccount(p, mem_ctx, &r);
479         if (!NT_STATUS_IS_OK(status)) {
480                 printf("RemovePrivilegesFromAccount failed - %s\n", nt_errstr(status));
481                 return False;
482         }
483
484         return ret;
485 }
486
487 static BOOL test_AddPrivilegesToAccount(struct dcerpc_pipe *p, 
488                                         TALLOC_CTX *mem_ctx,                              
489                                         struct policy_handle *acct_handle,
490                                         struct lsa_LUID *luid)
491 {
492         NTSTATUS status;
493         struct lsa_AddPrivilegesToAccount r;
494         struct lsa_PrivilegeSet privs;
495         BOOL ret = True;
496
497         printf("Testing AddPrivilegesToAccount\n");
498
499         r.in.handle = acct_handle;
500         r.in.privs = &privs;
501
502         privs.count = 1;
503         privs.unknown = 0;
504         privs.set = talloc_array_p(mem_ctx, struct lsa_LUIDAttribute, 1);
505         privs.set[0].luid = *luid;
506         privs.set[0].attribute = 0;
507
508         status = dcerpc_lsa_AddPrivilegesToAccount(p, mem_ctx, &r);
509         if (!NT_STATUS_IS_OK(status)) {
510                 printf("AddPrivilegesToAccount failed - %s\n", nt_errstr(status));
511                 return False;
512         }
513
514         return ret;
515 }
516
517 static BOOL test_EnumPrivsAccount(struct dcerpc_pipe *p, 
518                                   TALLOC_CTX *mem_ctx,                            
519                                   struct policy_handle *handle,
520                                   struct policy_handle *acct_handle)
521 {
522         NTSTATUS status;
523         struct lsa_EnumPrivsAccount r;
524         BOOL ret = True;
525
526         printf("Testing EnumPrivsAccount\n");
527
528         r.in.handle = acct_handle;
529
530         status = dcerpc_lsa_EnumPrivsAccount(p, mem_ctx, &r);
531         if (!NT_STATUS_IS_OK(status)) {
532                 printf("EnumPrivsAccount failed - %s\n", nt_errstr(status));
533                 return False;
534         }
535
536         if (r.out.privs && r.out.privs->count > 0) {
537                 int i;
538                 for (i=0;i<r.out.privs->count;i++) {
539                         test_LookupPrivName(p, mem_ctx, handle, 
540                                             &r.out.privs->set[i].luid);
541                 }
542
543                 ret &= test_RemovePrivilegesFromAccount(p, mem_ctx, acct_handle, 
544                                                         &r.out.privs->set[0].luid);
545                 ret &= test_AddPrivilegesToAccount(p, mem_ctx, acct_handle, 
546                                                    &r.out.privs->set[0].luid);
547         }
548
549         return ret;
550 }
551
552 static BOOL test_Delete(struct dcerpc_pipe *p, 
553                        TALLOC_CTX *mem_ctx, 
554                        struct policy_handle *handle)
555 {
556         NTSTATUS status;
557         struct lsa_Delete r;
558
559         printf("\ntesting Delete\n");
560
561         r.in.handle = handle;
562         status = dcerpc_lsa_Delete(p, mem_ctx, &r);
563         if (!NT_STATUS_IS_OK(status)) {
564                 printf("Delete failed - %s\n", nt_errstr(status));
565                 return False;
566         }
567
568         printf("\n");
569
570         return True;
571 }
572
573
574 static BOOL test_CreateAccount(struct dcerpc_pipe *p, 
575                                TALLOC_CTX *mem_ctx, 
576                                struct policy_handle *handle)
577 {
578         NTSTATUS status;
579         struct lsa_CreateAccount r;
580         struct dom_sid2 *newsid;
581         struct policy_handle acct_handle;
582
583         newsid = dom_sid_parse_talloc(mem_ctx, "S-1-5-12349876-4321-2854");
584
585         printf("Testing CreateAccount\n");
586
587         r.in.handle = handle;
588         r.in.sid = newsid;
589         r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
590         r.out.acct_handle = &acct_handle;
591
592         status = dcerpc_lsa_CreateAccount(p, mem_ctx, &r);
593         if (!NT_STATUS_IS_OK(status)) {
594                 printf("CreateAccount failed - %s\n", nt_errstr(status));
595                 return False;
596         }
597
598         if (!test_Delete(p, mem_ctx, &acct_handle)) {
599                 return False;
600         }
601
602         return True;
603 }
604
605 static BOOL test_DeleteTrustedDomain(struct dcerpc_pipe *p, 
606                                      TALLOC_CTX *mem_ctx, 
607                                      struct policy_handle *handle,
608                                      struct lsa_String name)
609 {
610         NTSTATUS status;
611         struct lsa_OpenTrustedDomainByName r;
612         struct policy_handle trustdom_handle;
613
614         r.in.handle = handle;
615         r.in.name = name;
616         r.in.access_mask = SEC_STD_DELETE;
617         r.out.trustdom_handle = &trustdom_handle;
618
619         status = dcerpc_lsa_OpenTrustedDomainByName(p, mem_ctx, &r);
620         if (!NT_STATUS_IS_OK(status)) {
621                 printf("lsa_OpenTrustedDomainByName failed - %s\n", nt_errstr(status));
622                 return False;
623         }
624
625         if (!test_Delete(p, mem_ctx, &trustdom_handle)) {
626                 return False;
627         }
628
629         return True;
630 }
631
632
633 static BOOL test_CreateTrustedDomain(struct dcerpc_pipe *p, 
634                                      TALLOC_CTX *mem_ctx, 
635                                      struct policy_handle *handle)
636 {
637         NTSTATUS status;
638         struct lsa_CreateTrustedDomain r;
639         struct lsa_TrustInformation trustinfo;
640         struct dom_sid *domsid;
641         struct policy_handle dom_handle;
642
643         printf("Testing CreateTrustedDomain\n");
644
645         domsid = dom_sid_parse_talloc(mem_ctx, "S-1-5-21-97398-379795-12345");
646
647         trustinfo.sid = domsid;
648         init_lsa_String(&trustinfo.name, "torturedomain");
649
650         r.in.handle = handle;
651         r.in.info = &trustinfo;
652         r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
653         r.out.dom_handle = &dom_handle;
654
655         status = dcerpc_lsa_CreateTrustedDomain(p, mem_ctx, &r);
656         if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
657                 test_DeleteTrustedDomain(p, mem_ctx, handle, trustinfo.name);
658                 status = dcerpc_lsa_CreateTrustedDomain(p, mem_ctx, &r);
659         }
660         if (!NT_STATUS_IS_OK(status)) {
661                 printf("CreateTrustedDomain failed - %s\n", nt_errstr(status));
662                 return False;
663         }
664
665         if (!test_Delete(p, mem_ctx, &dom_handle)) {
666                 return False;
667         }
668
669         return True;
670 }
671
672 static BOOL test_CreateSecret(struct dcerpc_pipe *p, 
673                               TALLOC_CTX *mem_ctx, 
674                               struct policy_handle *handle)
675 {
676         NTSTATUS status;
677         struct lsa_CreateSecret r;
678         struct lsa_OpenSecret r2;
679         struct lsa_SetSecret r3;
680         struct lsa_QuerySecret r4;
681         struct policy_handle sec_handle, sec_handle2;
682         struct lsa_Delete d;
683         struct lsa_DATA_BUF buf1;
684         struct lsa_DATA_BUF_PTR bufp1;
685         DATA_BLOB enc_key;
686         BOOL ret = True;
687         DATA_BLOB session_key;
688         NTTIME old_mtime, new_mtime;
689         DATA_BLOB blob1, blob2;
690         const char *secret1 = "abcdef12345699qwerty";
691         char *secret2;
692         char *secname[2];
693         int i;
694
695
696         secname[0] = talloc_asprintf(mem_ctx, "torturesecret-%u", (uint_t)random());
697         secname[1] = talloc_asprintf(mem_ctx, "G$torturesecret-%u", (uint_t)random());
698
699         for (i=0; i< 2; i++) {
700                 printf("Testing CreateSecret of %s\n", secname[i]);
701                 
702                 init_lsa_String(&r.in.name, secname[i]);
703                 
704                 r.in.handle = handle;
705                 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
706                 r.out.sec_handle = &sec_handle;
707                 
708                 status = dcerpc_lsa_CreateSecret(p, mem_ctx, &r);
709                 if (!NT_STATUS_IS_OK(status)) {
710                         printf("CreateSecret failed - %s\n", nt_errstr(status));
711                         return False;
712                 }
713                 
714                 r2.in.handle = handle;
715                 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
716                 r2.in.name = r.in.name;
717                 r2.out.sec_handle = &sec_handle2;
718                 
719                 printf("Testing OpenSecret\n");
720                 
721                 status = dcerpc_lsa_OpenSecret(p, mem_ctx, &r2);
722                 if (!NT_STATUS_IS_OK(status)) {
723                         printf("OpenSecret failed - %s\n", nt_errstr(status));
724                         ret = False;
725                 }
726                 
727                 status = dcerpc_fetch_session_key(p, &session_key);
728                 if (!NT_STATUS_IS_OK(status)) {
729                         printf("dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
730                         ret = False;
731                 }
732                 
733                 enc_key = sess_encrypt_string(secret1, &session_key);
734                 
735                 r3.in.handle = &sec_handle;
736                 r3.in.new_val = &buf1;
737                 r3.in.old_val = NULL;
738                 r3.in.new_val->data = enc_key.data;
739                 r3.in.new_val->length = enc_key.length;
740                 r3.in.new_val->size = enc_key.length;
741                 
742                 printf("Testing SetSecret\n");
743                 
744                 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r3);
745                 if (!NT_STATUS_IS_OK(status)) {
746                         printf("SetSecret failed - %s\n", nt_errstr(status));
747                         ret = False;
748                 }
749                 
750                 data_blob_free(&enc_key);
751                 
752                 ZERO_STRUCT(new_mtime);
753                 ZERO_STRUCT(old_mtime);
754                 
755                 /* fetch the secret back again */
756                 r4.in.handle = &sec_handle;
757                 r4.in.new_val = &bufp1;
758                 r4.in.new_mtime = &new_mtime;
759                 r4.in.old_val = NULL;
760                 r4.in.old_mtime = NULL;
761                 
762                 bufp1.buf = NULL;
763                 
764                 status = dcerpc_lsa_QuerySecret(p, mem_ctx, &r4);
765                 if (!NT_STATUS_IS_OK(status)) {
766                         printf("QuerySecret failed - %s\n", nt_errstr(status));
767                         ret = False;
768                 }
769                 
770                 if (r4.out.new_val->buf == NULL) {
771                         printf("No secret buffer returned\n");
772                         ret = False;
773                 } else {
774                         blob1.data = r4.out.new_val->buf->data;
775                         blob1.length = r4.out.new_val->buf->length;
776                         
777                         blob2 = data_blob(NULL, blob1.length);
778                         
779                         secret2 = sess_decrypt_string(&blob1, &session_key);
780                         
781                         printf("returned secret '%s'\n", secret2);
782                         
783                         if (strcmp(secret1, secret2) != 0) {
784                                 printf("Returned secret doesn't match\n");
785                                 ret = False;
786                         }
787                 }
788                 
789                 if (!test_Delete(p, mem_ctx, &sec_handle)) {
790                         ret = False;
791                 }
792                 
793                 d.in.handle = &sec_handle2;
794                 status = dcerpc_lsa_Delete(p, mem_ctx, &d);
795                 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
796                         printf("Second delete expected INVALID_HANDLE - %s\n", nt_errstr(status));
797                         ret = False;
798                 }
799         }
800
801         return ret;
802 }
803
804
805 static BOOL test_EnumAccountRights(struct dcerpc_pipe *p, 
806                                    TALLOC_CTX *mem_ctx, 
807                                    struct policy_handle *acct_handle,
808                                    struct dom_sid *sid)
809 {
810         NTSTATUS status;
811         struct lsa_EnumAccountRights r;
812         struct lsa_RightSet rights;
813
814         printf("Testing EnumAccountRights\n");
815
816         r.in.handle = acct_handle;
817         r.in.sid = sid;
818         r.out.rights = &rights;
819
820         status = dcerpc_lsa_EnumAccountRights(p, mem_ctx, &r);
821         if (!NT_STATUS_IS_OK(status)) {
822                 printf("EnumAccountRights failed - %s\n", nt_errstr(status));
823                 return False;
824         }
825
826         return True;
827 }
828
829
830 static BOOL test_QuerySecurity(struct dcerpc_pipe *p, 
831                              TALLOC_CTX *mem_ctx, 
832                              struct policy_handle *handle,
833                              struct policy_handle *acct_handle)
834 {
835         NTSTATUS status;
836         struct lsa_QuerySecurity r;
837
838         printf("Testing QuerySecurity\n");
839
840         r.in.handle = acct_handle;
841         r.in.sec_info = 7;
842
843         status = dcerpc_lsa_QuerySecurity(p, mem_ctx, &r);
844         if (!NT_STATUS_IS_OK(status)) {
845                 printf("QuerySecurity failed - %s\n", nt_errstr(status));
846                 return False;
847         }
848
849         return True;
850 }
851
852 static BOOL test_OpenAccount(struct dcerpc_pipe *p, 
853                              TALLOC_CTX *mem_ctx, 
854                              struct policy_handle *handle,
855                              struct dom_sid *sid)
856 {
857         NTSTATUS status;
858         struct lsa_OpenAccount r;
859         struct policy_handle acct_handle;
860
861         printf("Testing OpenAccount\n");
862
863         r.in.handle = handle;
864         r.in.sid = sid;
865         r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
866         r.out.acct_handle = &acct_handle;
867
868         status = dcerpc_lsa_OpenAccount(p, mem_ctx, &r);
869         if (!NT_STATUS_IS_OK(status)) {
870                 printf("OpenAccount failed - %s\n", nt_errstr(status));
871                 return False;
872         }
873
874         if (!test_EnumPrivsAccount(p, mem_ctx, handle, &acct_handle)) {
875                 return False;
876         }
877
878         if (!test_QuerySecurity(p, mem_ctx, handle, &acct_handle)) {
879                 return False;
880         }
881
882         return True;
883 }
884
885 static BOOL test_EnumAccounts(struct dcerpc_pipe *p, 
886                           TALLOC_CTX *mem_ctx, 
887                           struct policy_handle *handle)
888 {
889         NTSTATUS status;
890         struct lsa_EnumAccounts r;
891         struct lsa_SidArray sids1, sids2;
892         uint32_t resume_handle = 0;
893         int i;
894
895         printf("\ntesting EnumAccounts\n");
896
897         r.in.handle = handle;
898         r.in.resume_handle = &resume_handle;
899         r.in.num_entries = 100;
900         r.out.resume_handle = &resume_handle;
901         r.out.sids = &sids1;
902
903         resume_handle = 0;
904         while (True) {
905                 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
906                 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
907                         break;
908                 }
909                 if (!NT_STATUS_IS_OK(status)) {
910                         printf("EnumAccounts failed - %s\n", nt_errstr(status));
911                         return False;
912                 }
913
914                 if (!test_LookupSids(p, mem_ctx, handle, &sids1)) {
915                         return False;
916                 }
917
918                 if (!test_LookupSids2(p, mem_ctx, handle, &sids1)) {
919                         return False;
920                 }
921
922                 if (!test_LookupSids3(p, mem_ctx, handle, &sids1)) {
923                         return False;
924                 }
925
926                 printf("testing all accounts\n");
927                 for (i=0;i<sids1.num_sids;i++) {
928                         test_OpenAccount(p, mem_ctx, handle, sids1.sids[i].sid);
929                         test_EnumAccountRights(p, mem_ctx, handle, sids1.sids[i].sid);
930                 }
931                 printf("\n");
932         }
933
934         if (sids1.num_sids < 3) {
935                 return True;
936         }
937         
938         printf("trying EnumAccounts partial listing (asking for 1 at 2)\n");
939         resume_handle = 2;
940         r.in.num_entries = 1;
941         r.out.sids = &sids2;
942
943         status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
944         if (!NT_STATUS_IS_OK(status)) {
945                 printf("EnumAccounts failed - %s\n", nt_errstr(status));
946                 return False;
947         }
948
949         if (sids2.num_sids != 1) {
950                 printf("Returned wrong number of entries (%d)\n", sids2.num_sids);
951                 return False;
952         }
953
954         return True;
955 }
956
957 static BOOL test_LookupPrivDisplayName(struct dcerpc_pipe *p,
958                                 TALLOC_CTX *mem_ctx,
959                                 struct policy_handle *handle,
960                                 struct lsa_String *priv_name)
961 {
962         struct lsa_LookupPrivDisplayName r;
963         NTSTATUS status;
964         /* produce a reasonable range of language output without screwing up
965            terminals */
966         uint16 language_id = (random() % 4) + 0x409;
967
968         printf("testing LookupPrivDisplayName(%s)\n", priv_name->string);
969         
970         r.in.handle = handle;
971         r.in.name = priv_name;
972         r.in.language_id = &language_id;
973         r.out.language_id = &language_id;
974         r.in.unknown = 0;
975
976         status = dcerpc_lsa_LookupPrivDisplayName(p, mem_ctx, &r);
977         if (!NT_STATUS_IS_OK(status)) {
978                 printf("LookupPrivDisplayName failed - %s\n", nt_errstr(status));
979                 return False;
980         }
981         printf("%s -> \"%s\"  (language 0x%x/0x%x)\n", 
982                priv_name->string, r.out.disp_name->string, 
983                *r.in.language_id, *r.out.language_id);
984
985         return True;
986 }
987
988 static BOOL test_EnumAccountsWithUserRight(struct dcerpc_pipe *p, 
989                                 TALLOC_CTX *mem_ctx,
990                                 struct policy_handle *handle,
991                                 struct lsa_String *priv_name)
992 {
993         struct lsa_EnumAccountsWithUserRight r;
994         struct lsa_SidArray sids;
995         NTSTATUS status;
996
997         ZERO_STRUCT(sids);
998         
999         printf("testing EnumAccountsWithUserRight(%s)\n", priv_name->string);
1000         
1001         r.in.handle = handle;
1002         r.in.name = priv_name;
1003         r.out.sids = &sids;
1004
1005         status = dcerpc_lsa_EnumAccountsWithUserRight(p, mem_ctx, &r);
1006
1007         /* NT_STATUS_NO_MORE_ENTRIES means noone has this privilege */
1008         if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
1009                 return True;
1010         }
1011
1012         if (!NT_STATUS_IS_OK(status)) {
1013                 printf("EnumAccountsWithUserRight failed - %s\n", nt_errstr(status));
1014                 return False;
1015         }
1016         
1017         return True;
1018 }
1019
1020
1021 static BOOL test_EnumPrivs(struct dcerpc_pipe *p, 
1022                            TALLOC_CTX *mem_ctx, 
1023                            struct policy_handle *handle)
1024 {
1025         NTSTATUS status;
1026         struct lsa_EnumPrivs r;
1027         struct lsa_PrivArray privs1;
1028         uint32_t resume_handle = 0;
1029         int i;
1030         BOOL ret = True;
1031
1032         printf("\ntesting EnumPrivs\n");
1033
1034         r.in.handle = handle;
1035         r.in.resume_handle = &resume_handle;
1036         r.in.max_count = 100;
1037         r.out.resume_handle = &resume_handle;
1038         r.out.privs = &privs1;
1039
1040         resume_handle = 0;
1041         status = dcerpc_lsa_EnumPrivs(p, mem_ctx, &r);
1042         if (!NT_STATUS_IS_OK(status)) {
1043                 printf("EnumPrivs failed - %s\n", nt_errstr(status));
1044                 return False;
1045         }
1046
1047         for (i = 0; i< privs1.count; i++) {
1048                 test_LookupPrivDisplayName(p, mem_ctx, handle, &privs1.privs[i].name);
1049                 test_LookupPrivValue(p, mem_ctx, handle, &privs1.privs[i].name);
1050                 if (!test_EnumAccountsWithUserRight(p, mem_ctx, handle, &privs1.privs[i].name)) {
1051                         ret = False;
1052                 }
1053         }
1054
1055         return ret;
1056 }
1057
1058
1059 static BOOL test_EnumTrustDom(struct dcerpc_pipe *p, 
1060                               TALLOC_CTX *mem_ctx, 
1061                               struct policy_handle *handle)
1062 {
1063         struct lsa_EnumTrustDom r;
1064         NTSTATUS status;
1065         uint32_t resume_handle = 0;
1066         struct lsa_DomainList domains;
1067         int i,j;
1068         BOOL ret = True;
1069
1070         printf("\nTesting EnumTrustDom\n");
1071
1072         r.in.handle = handle;
1073         r.in.resume_handle = &resume_handle;
1074         r.in.num_entries = 100;
1075         r.out.domains = &domains;
1076         r.out.resume_handle = &resume_handle;
1077
1078         status = dcerpc_lsa_EnumTrustDom(p, mem_ctx, &r);
1079
1080         /* NO_MORE_ENTRIES is allowed */
1081         if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
1082                 return True;
1083         }
1084
1085         if (!NT_STATUS_IS_OK(status)) {
1086                 printf("EnumTrustDom failed - %s\n", nt_errstr(status));
1087                 return False;
1088         }
1089
1090         printf("\nTesting OpenTrustedDomain, OpenTrustedDomainByName and QueryInfoTrustedDomain\n");
1091
1092         for (i=0; i< domains.count; i++) {
1093                 struct lsa_OpenTrustedDomain trust;
1094                 struct lsa_OpenTrustedDomainByName trust_by_name;
1095                 struct policy_handle trustdom_handle;
1096                 struct policy_handle handle2;
1097                 struct lsa_Close c;
1098                 int levels [] = {1, 3, 6, 8, 12};
1099                 
1100                 trust.in.handle = handle;
1101                 trust.in.sid = domains.domains[i].sid;
1102                 trust.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1103                 trust.out.trustdom_handle = &trustdom_handle;
1104
1105                 status = dcerpc_lsa_OpenTrustedDomain(p, mem_ctx, &trust);
1106
1107                 if (!NT_STATUS_IS_OK(status)) {
1108                         printf("OpenTrustedDomain failed - %s\n", nt_errstr(status));
1109                         return False;
1110                 }
1111
1112                 c.in.handle = &trustdom_handle;
1113                 c.out.handle = &handle2;
1114                 
1115                 for (j=0; j < ARRAY_SIZE(levels); j++) {
1116                         struct lsa_QueryTrustedDomainInfo q;
1117                         union lsa_TrustedDomainInfo info;
1118                         q.in.trustdom_handle = &trustdom_handle;
1119                         q.in.level = levels[j];
1120                         q.out.info = &info;
1121                         status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
1122                         if (!NT_STATUS_IS_OK(status)) {
1123                                 printf("QueryTrustedDomainInfo level %d failed - %s\n", 
1124                                        levels[j], nt_errstr(status));
1125                                 ret = False;
1126                         }
1127                 }
1128                 
1129                 status = dcerpc_lsa_Close(p, mem_ctx, &c);
1130                 if (!NT_STATUS_IS_OK(status)) {
1131                         printf("Close of trusted domain failed - %s\n", nt_errstr(status));
1132                         return False;
1133                 }
1134
1135                 trust_by_name.in.handle = handle;
1136                 trust_by_name.in.name = domains.domains[i].name;
1137                 trust_by_name.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1138                 trust_by_name.out.trustdom_handle = &trustdom_handle;
1139                 
1140                 status = dcerpc_lsa_OpenTrustedDomainByName(p, mem_ctx, &trust_by_name);
1141
1142                 if (!NT_STATUS_IS_OK(status)) {
1143                         printf("OpenTrustedDomainByName failed - %s\n", nt_errstr(status));
1144                         return False;
1145                 }
1146
1147                 for (j=0; j < ARRAY_SIZE(levels); j++) {
1148                         struct lsa_QueryTrustedDomainInfo q;
1149                         union lsa_TrustedDomainInfo info;
1150                         q.in.trustdom_handle = &trustdom_handle;
1151                         q.in.level = levels[j];
1152                         q.out.info = &info;
1153                         status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
1154                         if (!NT_STATUS_IS_OK(status)) {
1155                                 printf("QueryTrustedDomainInfo level %d failed - %s\n", 
1156                                        levels[j], nt_errstr(status));
1157                                 ret = False;
1158                         }
1159                 }
1160                 
1161                 c.in.handle = &trustdom_handle;
1162                 c.out.handle = &handle2;
1163
1164                 status = dcerpc_lsa_Close(p, mem_ctx, &c);
1165                 if (!NT_STATUS_IS_OK(status)) {
1166                         printf("Close of trusted domain failed - %s\n", nt_errstr(status));
1167                         return False;
1168                 }
1169
1170                 for (j=0; j < ARRAY_SIZE(levels); j++) {
1171                         struct lsa_QueryTrustedDomainInfoBySid q;
1172                         union lsa_TrustedDomainInfo info;
1173                         q.in.handle  = handle;
1174                         q.in.dom_sid = domains.domains[i].sid;
1175                         q.in.level   = levels[j];
1176                         q.out.info   = &info;
1177                         status = dcerpc_lsa_QueryTrustedDomainInfoBySid(p, mem_ctx, &q);
1178                         if (!NT_STATUS_IS_OK(status)) {
1179                                 printf("QueryTrustedDomainInfoBySid level %d failed - %s\n", 
1180                                        levels[j], nt_errstr(status));
1181                                 ret = False;
1182                         }
1183                 }
1184                 
1185                 for (j=0; j < ARRAY_SIZE(levels); j++) {
1186                         struct lsa_QueryTrustedDomainInfoByName q;
1187                         union lsa_TrustedDomainInfo info;
1188                         q.in.handle         = handle;
1189                         q.in.trusted_domain = domains.domains[i].name;
1190                         q.in.level          = levels[j];
1191                         q.out.info          = &info;
1192                         status = dcerpc_lsa_QueryTrustedDomainInfoByName(p, mem_ctx, &q);
1193                         if (!NT_STATUS_IS_OK(status)) {
1194                                 printf("QueryTrustedDomainInfoByName level %d failed - %s\n", 
1195                                        levels[j], nt_errstr(status));
1196                                 ret = False;
1197                         }
1198                 }
1199                 
1200                 
1201
1202         }
1203
1204         return ret;
1205 }
1206
1207 static BOOL test_QueryInfoPolicy(struct dcerpc_pipe *p, 
1208                                  TALLOC_CTX *mem_ctx, 
1209                                  struct policy_handle *handle)
1210 {
1211         struct lsa_QueryInfoPolicy r;
1212         NTSTATUS status;
1213         int i;
1214         BOOL ret = True;
1215         printf("\nTesting QueryInfoPolicy\n");
1216
1217         for (i=1;i<13;i++) {
1218                 r.in.handle = handle;
1219                 r.in.level = i;
1220
1221                 printf("\ntrying QueryInfoPolicy level %d\n", i);
1222
1223                 status = dcerpc_lsa_QueryInfoPolicy(p, mem_ctx, &r);
1224
1225                 if ((i == 9 || i == 10 || i == 11) &&
1226                     NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
1227                         printf("server failed level %u (OK)\n", i);
1228                         continue;
1229                 }
1230
1231                 if (!NT_STATUS_IS_OK(status)) {
1232                         printf("QueryInfoPolicy failed - %s\n", nt_errstr(status));
1233                         ret = False;
1234                         continue;
1235                 }
1236         }
1237
1238         return ret;
1239 }
1240
1241 static BOOL test_QueryInfoPolicy2(struct dcerpc_pipe *p, 
1242                                   TALLOC_CTX *mem_ctx, 
1243                                   struct policy_handle *handle)
1244 {
1245         struct lsa_QueryInfoPolicy2 r;
1246         NTSTATUS status;
1247         int i;
1248         BOOL ret = True;
1249         printf("\nTesting QueryInfoPolicy2\n");
1250
1251         for (i=1;i<13;i++) {
1252                 r.in.handle = handle;
1253                 r.in.level = i;
1254
1255                 printf("\ntrying QueryInfoPolicy2 level %d\n", i);
1256
1257                 status = dcerpc_lsa_QueryInfoPolicy2(p, mem_ctx, &r);
1258
1259                 if ((i == 9 || i == 10 || i == 11) &&
1260                     NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
1261                         printf("server failed level %u (OK)\n", i);
1262                         continue;
1263                 }
1264
1265                 if (!NT_STATUS_IS_OK(status)) {
1266                         printf("QueryInfoPolicy2 failed - %s\n", nt_errstr(status));
1267                         ret = False;
1268                         continue;
1269                 }
1270         }
1271
1272         return ret;
1273 }
1274
1275 static BOOL test_GetUserName(struct dcerpc_pipe *p, 
1276                                   TALLOC_CTX *mem_ctx, 
1277                                   struct policy_handle *handle)
1278 {
1279         struct lsa_GetUserName r;
1280         NTSTATUS status;
1281         BOOL ret = True;
1282         struct lsa_StringPointer authority_name_p;
1283
1284         printf("\nTesting GetUserName\n");
1285
1286         r.in.system_name = "\\";        
1287         r.in.account_name = NULL;       
1288         r.in.authority_name = &authority_name_p;
1289         authority_name_p.string = NULL;
1290
1291         status = dcerpc_lsa_GetUserName(p, mem_ctx, &r);
1292
1293         if (!NT_STATUS_IS_OK(status)) {
1294                 printf("GetUserName failed - %s\n", nt_errstr(status));
1295                 ret = False;
1296         }
1297
1298         return ret;
1299 }
1300
1301 static BOOL test_Close(struct dcerpc_pipe *p, 
1302                        TALLOC_CTX *mem_ctx, 
1303                        struct policy_handle *handle)
1304 {
1305         NTSTATUS status;
1306         struct lsa_Close r;
1307         struct policy_handle handle2;
1308
1309         printf("\ntesting Close\n");
1310
1311         r.in.handle = handle;
1312         r.out.handle = &handle2;
1313
1314         status = dcerpc_lsa_Close(p, mem_ctx, &r);
1315         if (!NT_STATUS_IS_OK(status)) {
1316                 printf("Close failed - %s\n", nt_errstr(status));
1317                 return False;
1318         }
1319
1320         status = dcerpc_lsa_Close(p, mem_ctx, &r);
1321         /* its really a fault - we need a status code for rpc fault */
1322         if (!NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
1323                 printf("Close failed - %s\n", nt_errstr(status));
1324                 return False;
1325         }
1326
1327         printf("\n");
1328
1329         return True;
1330 }
1331
1332 BOOL torture_rpc_lsa(void)
1333 {
1334         NTSTATUS status;
1335         struct dcerpc_pipe *p;
1336         TALLOC_CTX *mem_ctx;
1337         BOOL ret = True;
1338         struct policy_handle handle;
1339
1340         mem_ctx = talloc_init("torture_rpc_lsa");
1341
1342         status = torture_rpc_connection(&p, 
1343                                         DCERPC_LSARPC_NAME, 
1344                                         DCERPC_LSARPC_UUID, 
1345                                         DCERPC_LSARPC_VERSION);
1346         if (!NT_STATUS_IS_OK(status)) {
1347                 return False;
1348         }
1349
1350         if (!test_OpenPolicy(p, mem_ctx)) {
1351                 ret = False;
1352         }
1353
1354         if (!test_OpenPolicy2(p, mem_ctx, &handle)) {
1355                 ret = False;
1356         }
1357
1358         if (!test_many_LookupSids(p, mem_ctx, &handle)) {
1359                 ret = False;
1360         }
1361
1362         if (!test_CreateAccount(p, mem_ctx, &handle)) {
1363                 ret = False;
1364         }
1365
1366         if (!test_CreateSecret(p, mem_ctx, &handle)) {
1367                 ret = False;
1368         }
1369
1370         if (!test_CreateTrustedDomain(p, mem_ctx, &handle)) {
1371                 ret = False;
1372         }
1373
1374         if (!test_EnumAccounts(p, mem_ctx, &handle)) {
1375                 ret = False;
1376         }
1377
1378         if (!test_EnumPrivs(p, mem_ctx, &handle)) {
1379                 ret = False;
1380         }
1381
1382         if (!test_EnumTrustDom(p, mem_ctx, &handle)) {
1383                 ret = False;
1384         }
1385
1386         if (!test_QueryInfoPolicy(p, mem_ctx, &handle)) {
1387                 ret = False;
1388         }
1389
1390         if (!test_QueryInfoPolicy2(p, mem_ctx, &handle)) {
1391                 ret = False;
1392         }
1393
1394         if (!test_GetUserName(p, mem_ctx, &handle)) {
1395                 ret = False;
1396         }
1397
1398 #if 0
1399         if (!test_Delete(p, mem_ctx, &handle)) {
1400                 ret = False;
1401         }
1402 #endif
1403         
1404         if (!test_Close(p, mem_ctx, &handle)) {
1405                 ret = False;
1406         }
1407
1408         talloc_destroy(mem_ctx);
1409
1410         torture_rpc_close(p);
1411
1412         return ret;
1413 }