7cb5a0588490889df32fd7617b6966f4360512e6
[samba.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 BOOL test_lsa_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                 printf("Testing OpenSecret of just-deleted secret\n");
801                 
802                 status = dcerpc_lsa_OpenSecret(p, mem_ctx, &r2);
803                 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
804                         printf("OpenSecret expected OBJECT_NAME_NOT_FOUND - %s\n", nt_errstr(status));
805                         ret = False;
806                 }
807                 
808         }
809
810         return ret;
811 }
812
813
814 static BOOL test_EnumAccountRights(struct dcerpc_pipe *p, 
815                                    TALLOC_CTX *mem_ctx, 
816                                    struct policy_handle *acct_handle,
817                                    struct dom_sid *sid)
818 {
819         NTSTATUS status;
820         struct lsa_EnumAccountRights r;
821         struct lsa_RightSet rights;
822
823         printf("Testing EnumAccountRights\n");
824
825         r.in.handle = acct_handle;
826         r.in.sid = sid;
827         r.out.rights = &rights;
828
829         status = dcerpc_lsa_EnumAccountRights(p, mem_ctx, &r);
830         if (!NT_STATUS_IS_OK(status)) {
831                 printf("EnumAccountRights failed - %s\n", nt_errstr(status));
832                 return False;
833         }
834
835         return True;
836 }
837
838
839 static BOOL test_QuerySecurity(struct dcerpc_pipe *p, 
840                              TALLOC_CTX *mem_ctx, 
841                              struct policy_handle *handle,
842                              struct policy_handle *acct_handle)
843 {
844         NTSTATUS status;
845         struct lsa_QuerySecurity r;
846
847         printf("Testing QuerySecurity\n");
848
849         r.in.handle = acct_handle;
850         r.in.sec_info = 7;
851
852         status = dcerpc_lsa_QuerySecurity(p, mem_ctx, &r);
853         if (!NT_STATUS_IS_OK(status)) {
854                 printf("QuerySecurity failed - %s\n", nt_errstr(status));
855                 return False;
856         }
857
858         return True;
859 }
860
861 static BOOL test_OpenAccount(struct dcerpc_pipe *p, 
862                              TALLOC_CTX *mem_ctx, 
863                              struct policy_handle *handle,
864                              struct dom_sid *sid)
865 {
866         NTSTATUS status;
867         struct lsa_OpenAccount r;
868         struct policy_handle acct_handle;
869
870         printf("Testing OpenAccount\n");
871
872         r.in.handle = handle;
873         r.in.sid = sid;
874         r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
875         r.out.acct_handle = &acct_handle;
876
877         status = dcerpc_lsa_OpenAccount(p, mem_ctx, &r);
878         if (!NT_STATUS_IS_OK(status)) {
879                 printf("OpenAccount failed - %s\n", nt_errstr(status));
880                 return False;
881         }
882
883         if (!test_EnumPrivsAccount(p, mem_ctx, handle, &acct_handle)) {
884                 return False;
885         }
886
887         if (!test_QuerySecurity(p, mem_ctx, handle, &acct_handle)) {
888                 return False;
889         }
890
891         return True;
892 }
893
894 static BOOL test_EnumAccounts(struct dcerpc_pipe *p, 
895                           TALLOC_CTX *mem_ctx, 
896                           struct policy_handle *handle)
897 {
898         NTSTATUS status;
899         struct lsa_EnumAccounts r;
900         struct lsa_SidArray sids1, sids2;
901         uint32_t resume_handle = 0;
902         int i;
903
904         printf("\ntesting EnumAccounts\n");
905
906         r.in.handle = handle;
907         r.in.resume_handle = &resume_handle;
908         r.in.num_entries = 100;
909         r.out.resume_handle = &resume_handle;
910         r.out.sids = &sids1;
911
912         resume_handle = 0;
913         while (True) {
914                 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
915                 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
916                         break;
917                 }
918                 if (!NT_STATUS_IS_OK(status)) {
919                         printf("EnumAccounts failed - %s\n", nt_errstr(status));
920                         return False;
921                 }
922
923                 if (!test_LookupSids(p, mem_ctx, handle, &sids1)) {
924                         return False;
925                 }
926
927                 if (!test_LookupSids2(p, mem_ctx, handle, &sids1)) {
928                         return False;
929                 }
930
931                 if (!test_LookupSids3(p, mem_ctx, handle, &sids1)) {
932                         return False;
933                 }
934
935                 printf("testing all accounts\n");
936                 for (i=0;i<sids1.num_sids;i++) {
937                         test_OpenAccount(p, mem_ctx, handle, sids1.sids[i].sid);
938                         test_EnumAccountRights(p, mem_ctx, handle, sids1.sids[i].sid);
939                 }
940                 printf("\n");
941         }
942
943         if (sids1.num_sids < 3) {
944                 return True;
945         }
946         
947         printf("trying EnumAccounts partial listing (asking for 1 at 2)\n");
948         resume_handle = 2;
949         r.in.num_entries = 1;
950         r.out.sids = &sids2;
951
952         status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
953         if (!NT_STATUS_IS_OK(status)) {
954                 printf("EnumAccounts failed - %s\n", nt_errstr(status));
955                 return False;
956         }
957
958         if (sids2.num_sids != 1) {
959                 printf("Returned wrong number of entries (%d)\n", sids2.num_sids);
960                 return False;
961         }
962
963         return True;
964 }
965
966 static BOOL test_LookupPrivDisplayName(struct dcerpc_pipe *p,
967                                 TALLOC_CTX *mem_ctx,
968                                 struct policy_handle *handle,
969                                 struct lsa_String *priv_name)
970 {
971         struct lsa_LookupPrivDisplayName r;
972         NTSTATUS status;
973         /* produce a reasonable range of language output without screwing up
974            terminals */
975         uint16 language_id = (random() % 4) + 0x409;
976
977         printf("testing LookupPrivDisplayName(%s)\n", priv_name->string);
978         
979         r.in.handle = handle;
980         r.in.name = priv_name;
981         r.in.language_id = &language_id;
982         r.out.language_id = &language_id;
983         r.in.unknown = 0;
984
985         status = dcerpc_lsa_LookupPrivDisplayName(p, mem_ctx, &r);
986         if (!NT_STATUS_IS_OK(status)) {
987                 printf("LookupPrivDisplayName failed - %s\n", nt_errstr(status));
988                 return False;
989         }
990         printf("%s -> \"%s\"  (language 0x%x/0x%x)\n", 
991                priv_name->string, r.out.disp_name->string, 
992                *r.in.language_id, *r.out.language_id);
993
994         return True;
995 }
996
997 static BOOL test_EnumAccountsWithUserRight(struct dcerpc_pipe *p, 
998                                 TALLOC_CTX *mem_ctx,
999                                 struct policy_handle *handle,
1000                                 struct lsa_String *priv_name)
1001 {
1002         struct lsa_EnumAccountsWithUserRight r;
1003         struct lsa_SidArray sids;
1004         NTSTATUS status;
1005
1006         ZERO_STRUCT(sids);
1007         
1008         printf("testing EnumAccountsWithUserRight(%s)\n", priv_name->string);
1009         
1010         r.in.handle = handle;
1011         r.in.name = priv_name;
1012         r.out.sids = &sids;
1013
1014         status = dcerpc_lsa_EnumAccountsWithUserRight(p, mem_ctx, &r);
1015
1016         /* NT_STATUS_NO_MORE_ENTRIES means noone has this privilege */
1017         if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
1018                 return True;
1019         }
1020
1021         if (!NT_STATUS_IS_OK(status)) {
1022                 printf("EnumAccountsWithUserRight failed - %s\n", nt_errstr(status));
1023                 return False;
1024         }
1025         
1026         return True;
1027 }
1028
1029
1030 static BOOL test_EnumPrivs(struct dcerpc_pipe *p, 
1031                            TALLOC_CTX *mem_ctx, 
1032                            struct policy_handle *handle)
1033 {
1034         NTSTATUS status;
1035         struct lsa_EnumPrivs r;
1036         struct lsa_PrivArray privs1;
1037         uint32_t resume_handle = 0;
1038         int i;
1039         BOOL ret = True;
1040
1041         printf("\ntesting EnumPrivs\n");
1042
1043         r.in.handle = handle;
1044         r.in.resume_handle = &resume_handle;
1045         r.in.max_count = 100;
1046         r.out.resume_handle = &resume_handle;
1047         r.out.privs = &privs1;
1048
1049         resume_handle = 0;
1050         status = dcerpc_lsa_EnumPrivs(p, mem_ctx, &r);
1051         if (!NT_STATUS_IS_OK(status)) {
1052                 printf("EnumPrivs failed - %s\n", nt_errstr(status));
1053                 return False;
1054         }
1055
1056         for (i = 0; i< privs1.count; i++) {
1057                 test_LookupPrivDisplayName(p, mem_ctx, handle, &privs1.privs[i].name);
1058                 test_LookupPrivValue(p, mem_ctx, handle, &privs1.privs[i].name);
1059                 if (!test_EnumAccountsWithUserRight(p, mem_ctx, handle, &privs1.privs[i].name)) {
1060                         ret = False;
1061                 }
1062         }
1063
1064         return ret;
1065 }
1066
1067
1068 static BOOL test_EnumTrustDom(struct dcerpc_pipe *p, 
1069                               TALLOC_CTX *mem_ctx, 
1070                               struct policy_handle *handle)
1071 {
1072         struct lsa_EnumTrustDom r;
1073         NTSTATUS status;
1074         uint32_t resume_handle = 0;
1075         struct lsa_DomainList domains;
1076         int i,j;
1077         BOOL ret = True;
1078
1079         printf("\nTesting EnumTrustDom\n");
1080
1081         r.in.handle = handle;
1082         r.in.resume_handle = &resume_handle;
1083         r.in.num_entries = 100;
1084         r.out.domains = &domains;
1085         r.out.resume_handle = &resume_handle;
1086
1087         status = dcerpc_lsa_EnumTrustDom(p, mem_ctx, &r);
1088
1089         /* NO_MORE_ENTRIES is allowed */
1090         if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
1091                 return True;
1092         }
1093
1094         if (!NT_STATUS_IS_OK(status)) {
1095                 printf("EnumTrustDom failed - %s\n", nt_errstr(status));
1096                 return False;
1097         }
1098
1099         printf("\nTesting OpenTrustedDomain, OpenTrustedDomainByName and QueryInfoTrustedDomain\n");
1100
1101         for (i=0; i< domains.count; i++) {
1102                 struct lsa_OpenTrustedDomain trust;
1103                 struct lsa_OpenTrustedDomainByName trust_by_name;
1104                 struct policy_handle trustdom_handle;
1105                 struct policy_handle handle2;
1106                 struct lsa_Close c;
1107                 int levels [] = {1, 3, 6, 8, 12};
1108                 
1109                 trust.in.handle = handle;
1110                 trust.in.sid = domains.domains[i].sid;
1111                 trust.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1112                 trust.out.trustdom_handle = &trustdom_handle;
1113
1114                 status = dcerpc_lsa_OpenTrustedDomain(p, mem_ctx, &trust);
1115
1116                 if (!NT_STATUS_IS_OK(status)) {
1117                         printf("OpenTrustedDomain failed - %s\n", nt_errstr(status));
1118                         return False;
1119                 }
1120
1121                 c.in.handle = &trustdom_handle;
1122                 c.out.handle = &handle2;
1123                 
1124                 for (j=0; j < ARRAY_SIZE(levels); j++) {
1125                         struct lsa_QueryTrustedDomainInfo q;
1126                         union lsa_TrustedDomainInfo info;
1127                         q.in.trustdom_handle = &trustdom_handle;
1128                         q.in.level = levels[j];
1129                         q.out.info = &info;
1130                         status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
1131                         if (!NT_STATUS_IS_OK(status)) {
1132                                 printf("QueryTrustedDomainInfo level %d failed - %s\n", 
1133                                        levels[j], nt_errstr(status));
1134                                 ret = False;
1135                         }
1136                 }
1137                 
1138                 status = dcerpc_lsa_Close(p, mem_ctx, &c);
1139                 if (!NT_STATUS_IS_OK(status)) {
1140                         printf("Close of trusted domain failed - %s\n", nt_errstr(status));
1141                         return False;
1142                 }
1143
1144                 trust_by_name.in.handle = handle;
1145                 trust_by_name.in.name = domains.domains[i].name;
1146                 trust_by_name.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1147                 trust_by_name.out.trustdom_handle = &trustdom_handle;
1148                 
1149                 status = dcerpc_lsa_OpenTrustedDomainByName(p, mem_ctx, &trust_by_name);
1150
1151                 if (!NT_STATUS_IS_OK(status)) {
1152                         printf("OpenTrustedDomainByName failed - %s\n", nt_errstr(status));
1153                         return False;
1154                 }
1155
1156                 for (j=0; j < ARRAY_SIZE(levels); j++) {
1157                         struct lsa_QueryTrustedDomainInfo q;
1158                         union lsa_TrustedDomainInfo info;
1159                         q.in.trustdom_handle = &trustdom_handle;
1160                         q.in.level = levels[j];
1161                         q.out.info = &info;
1162                         status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
1163                         if (!NT_STATUS_IS_OK(status)) {
1164                                 printf("QueryTrustedDomainInfo level %d failed - %s\n", 
1165                                        levels[j], nt_errstr(status));
1166                                 ret = False;
1167                         }
1168                 }
1169                 
1170                 c.in.handle = &trustdom_handle;
1171                 c.out.handle = &handle2;
1172
1173                 status = dcerpc_lsa_Close(p, mem_ctx, &c);
1174                 if (!NT_STATUS_IS_OK(status)) {
1175                         printf("Close of trusted domain failed - %s\n", nt_errstr(status));
1176                         return False;
1177                 }
1178
1179                 for (j=0; j < ARRAY_SIZE(levels); j++) {
1180                         struct lsa_QueryTrustedDomainInfoBySid q;
1181                         union lsa_TrustedDomainInfo info;
1182                         q.in.handle  = handle;
1183                         q.in.dom_sid = domains.domains[i].sid;
1184                         q.in.level   = levels[j];
1185                         q.out.info   = &info;
1186                         status = dcerpc_lsa_QueryTrustedDomainInfoBySid(p, mem_ctx, &q);
1187                         if (!NT_STATUS_IS_OK(status)) {
1188                                 printf("QueryTrustedDomainInfoBySid level %d failed - %s\n", 
1189                                        levels[j], nt_errstr(status));
1190                                 ret = False;
1191                         }
1192                 }
1193                 
1194                 for (j=0; j < ARRAY_SIZE(levels); j++) {
1195                         struct lsa_QueryTrustedDomainInfoByName q;
1196                         union lsa_TrustedDomainInfo info;
1197                         q.in.handle         = handle;
1198                         q.in.trusted_domain = domains.domains[i].name;
1199                         q.in.level          = levels[j];
1200                         q.out.info          = &info;
1201                         status = dcerpc_lsa_QueryTrustedDomainInfoByName(p, mem_ctx, &q);
1202                         if (!NT_STATUS_IS_OK(status)) {
1203                                 printf("QueryTrustedDomainInfoByName level %d failed - %s\n", 
1204                                        levels[j], nt_errstr(status));
1205                                 ret = False;
1206                         }
1207                 }
1208                 
1209                 
1210
1211         }
1212
1213         return ret;
1214 }
1215
1216 static BOOL test_QueryInfoPolicy(struct dcerpc_pipe *p, 
1217                                  TALLOC_CTX *mem_ctx, 
1218                                  struct policy_handle *handle)
1219 {
1220         struct lsa_QueryInfoPolicy r;
1221         NTSTATUS status;
1222         int i;
1223         BOOL ret = True;
1224         printf("\nTesting QueryInfoPolicy\n");
1225
1226         for (i=1;i<13;i++) {
1227                 r.in.handle = handle;
1228                 r.in.level = i;
1229
1230                 printf("\ntrying QueryInfoPolicy level %d\n", i);
1231
1232                 status = dcerpc_lsa_QueryInfoPolicy(p, mem_ctx, &r);
1233
1234                 if ((i == 9 || i == 10 || i == 11) &&
1235                     NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
1236                         printf("server failed level %u (OK)\n", i);
1237                         continue;
1238                 }
1239
1240                 if (!NT_STATUS_IS_OK(status)) {
1241                         printf("QueryInfoPolicy failed - %s\n", nt_errstr(status));
1242                         ret = False;
1243                         continue;
1244                 }
1245         }
1246
1247         return ret;
1248 }
1249
1250 static BOOL test_QueryInfoPolicy2(struct dcerpc_pipe *p, 
1251                                   TALLOC_CTX *mem_ctx, 
1252                                   struct policy_handle *handle)
1253 {
1254         struct lsa_QueryInfoPolicy2 r;
1255         NTSTATUS status;
1256         int i;
1257         BOOL ret = True;
1258         printf("\nTesting QueryInfoPolicy2\n");
1259
1260         for (i=1;i<13;i++) {
1261                 r.in.handle = handle;
1262                 r.in.level = i;
1263
1264                 printf("\ntrying QueryInfoPolicy2 level %d\n", i);
1265
1266                 status = dcerpc_lsa_QueryInfoPolicy2(p, mem_ctx, &r);
1267
1268                 if ((i == 9 || i == 10 || i == 11) &&
1269                     NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
1270                         printf("server failed level %u (OK)\n", i);
1271                         continue;
1272                 }
1273
1274                 if (!NT_STATUS_IS_OK(status)) {
1275                         printf("QueryInfoPolicy2 failed - %s\n", nt_errstr(status));
1276                         ret = False;
1277                         continue;
1278                 }
1279         }
1280
1281         return ret;
1282 }
1283
1284 static BOOL test_GetUserName(struct dcerpc_pipe *p, 
1285                                   TALLOC_CTX *mem_ctx, 
1286                                   struct policy_handle *handle)
1287 {
1288         struct lsa_GetUserName r;
1289         NTSTATUS status;
1290         BOOL ret = True;
1291         struct lsa_StringPointer authority_name_p;
1292
1293         printf("\nTesting GetUserName\n");
1294
1295         r.in.system_name = "\\";        
1296         r.in.account_name = NULL;       
1297         r.in.authority_name = &authority_name_p;
1298         authority_name_p.string = NULL;
1299
1300         status = dcerpc_lsa_GetUserName(p, mem_ctx, &r);
1301
1302         if (!NT_STATUS_IS_OK(status)) {
1303                 printf("GetUserName failed - %s\n", nt_errstr(status));
1304                 ret = False;
1305         }
1306
1307         return ret;
1308 }
1309
1310 BOOL test_lsa_Close(struct dcerpc_pipe *p, 
1311                     TALLOC_CTX *mem_ctx, 
1312                     struct policy_handle *handle)
1313 {
1314         NTSTATUS status;
1315         struct lsa_Close r;
1316         struct policy_handle handle2;
1317
1318         printf("\ntesting Close\n");
1319
1320         r.in.handle = handle;
1321         r.out.handle = &handle2;
1322
1323         status = dcerpc_lsa_Close(p, mem_ctx, &r);
1324         if (!NT_STATUS_IS_OK(status)) {
1325                 printf("Close failed - %s\n", nt_errstr(status));
1326                 return False;
1327         }
1328
1329         status = dcerpc_lsa_Close(p, mem_ctx, &r);
1330         /* its really a fault - we need a status code for rpc fault */
1331         if (!NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
1332                 printf("Close failed - %s\n", nt_errstr(status));
1333                 return False;
1334         }
1335
1336         printf("\n");
1337
1338         return True;
1339 }
1340
1341 BOOL torture_rpc_lsa(void)
1342 {
1343         NTSTATUS status;
1344         struct dcerpc_pipe *p;
1345         TALLOC_CTX *mem_ctx;
1346         BOOL ret = True;
1347         struct policy_handle handle;
1348
1349         mem_ctx = talloc_init("torture_rpc_lsa");
1350
1351         status = torture_rpc_connection(&p, 
1352                                         DCERPC_LSARPC_NAME, 
1353                                         DCERPC_LSARPC_UUID, 
1354                                         DCERPC_LSARPC_VERSION);
1355         if (!NT_STATUS_IS_OK(status)) {
1356                 return False;
1357         }
1358
1359         if (!test_OpenPolicy(p, mem_ctx)) {
1360                 ret = False;
1361         }
1362
1363         if (!test_lsa_OpenPolicy2(p, mem_ctx, &handle)) {
1364                 ret = False;
1365         }
1366
1367         if (!test_many_LookupSids(p, mem_ctx, &handle)) {
1368                 ret = False;
1369         }
1370
1371         if (!test_CreateAccount(p, mem_ctx, &handle)) {
1372                 ret = False;
1373         }
1374
1375         if (!test_CreateSecret(p, mem_ctx, &handle)) {
1376                 ret = False;
1377         }
1378
1379         if (!test_CreateTrustedDomain(p, mem_ctx, &handle)) {
1380                 ret = False;
1381         }
1382
1383         if (!test_EnumAccounts(p, mem_ctx, &handle)) {
1384                 ret = False;
1385         }
1386
1387         if (!test_EnumPrivs(p, mem_ctx, &handle)) {
1388                 ret = False;
1389         }
1390
1391         if (!test_EnumTrustDom(p, mem_ctx, &handle)) {
1392                 ret = False;
1393         }
1394
1395         if (!test_QueryInfoPolicy(p, mem_ctx, &handle)) {
1396                 ret = False;
1397         }
1398
1399         if (!test_QueryInfoPolicy2(p, mem_ctx, &handle)) {
1400                 ret = False;
1401         }
1402
1403         if (!test_GetUserName(p, mem_ctx, &handle)) {
1404                 ret = False;
1405         }
1406
1407 #if 0
1408         if (!test_Delete(p, mem_ctx, &handle)) {
1409                 ret = False;
1410         }
1411 #endif
1412         
1413         if (!test_lsa_Close(p, mem_ctx, &handle)) {
1414                 ret = False;
1415         }
1416
1417         talloc_destroy(mem_ctx);
1418
1419         torture_rpc_close(p);
1420
1421         return ret;
1422 }