s3/docs: Raise version number up to 3.5.
[Samba/gebeck_regimport.git] / source4 / torture / rpc / lsa.c
blob454afabc50030cb0480af8a3d5fbf7f848d830d8
1 /*
2 Unix SMB/CIFS implementation.
3 test suite for lsa rpc operations
5 Copyright (C) Andrew Tridgell 2003
6 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2004-2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "torture/torture.h"
24 #include "librpc/gen_ndr/ndr_lsa_c.h"
25 #include "librpc/gen_ndr/netlogon.h"
26 #include "librpc/gen_ndr/ndr_drsblobs.h"
27 #include "lib/events/events.h"
28 #include "libcli/security/security.h"
29 #include "libcli/auth/libcli_auth.h"
30 #include "torture/rpc/rpc.h"
31 #include "param/param.h"
32 #include "../lib/crypto/crypto.h"
33 #define TEST_MACHINENAME "lsatestmach"
35 static void init_lsa_String(struct lsa_String *name, const char *s)
37 name->string = s;
40 static bool test_OpenPolicy(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
42 struct lsa_ObjectAttribute attr;
43 struct policy_handle handle;
44 struct lsa_QosInfo qos;
45 struct lsa_OpenPolicy r;
46 NTSTATUS status;
47 uint16_t system_name = '\\';
49 printf("\nTesting OpenPolicy\n");
51 qos.len = 0;
52 qos.impersonation_level = 2;
53 qos.context_mode = 1;
54 qos.effective_only = 0;
56 attr.len = 0;
57 attr.root_dir = NULL;
58 attr.object_name = NULL;
59 attr.attributes = 0;
60 attr.sec_desc = NULL;
61 attr.sec_qos = &qos;
63 r.in.system_name = &system_name;
64 r.in.attr = &attr;
65 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
66 r.out.handle = &handle;
68 status = dcerpc_lsa_OpenPolicy(p, mem_ctx, &r);
69 if (!NT_STATUS_IS_OK(status)) {
70 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
71 NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
72 printf("not considering %s to be an error\n", nt_errstr(status));
73 return true;
75 printf("OpenPolicy failed - %s\n", nt_errstr(status));
76 return false;
79 return true;
83 bool test_lsa_OpenPolicy2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
84 struct policy_handle **handle)
86 struct lsa_ObjectAttribute attr;
87 struct lsa_QosInfo qos;
88 struct lsa_OpenPolicy2 r;
89 NTSTATUS status;
91 printf("\nTesting OpenPolicy2\n");
93 *handle = talloc(mem_ctx, struct policy_handle);
94 if (!*handle) {
95 return false;
98 qos.len = 0;
99 qos.impersonation_level = 2;
100 qos.context_mode = 1;
101 qos.effective_only = 0;
103 attr.len = 0;
104 attr.root_dir = NULL;
105 attr.object_name = NULL;
106 attr.attributes = 0;
107 attr.sec_desc = NULL;
108 attr.sec_qos = &qos;
110 r.in.system_name = "\\";
111 r.in.attr = &attr;
112 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
113 r.out.handle = *handle;
115 status = dcerpc_lsa_OpenPolicy2(p, mem_ctx, &r);
116 if (!NT_STATUS_IS_OK(status)) {
117 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
118 NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
119 printf("not considering %s to be an error\n", nt_errstr(status));
120 talloc_free(*handle);
121 *handle = NULL;
122 return true;
124 printf("OpenPolicy2 failed - %s\n", nt_errstr(status));
125 return false;
128 return true;
132 static const char *sid_type_lookup(enum lsa_SidType r)
134 switch (r) {
135 case SID_NAME_USE_NONE: return "SID_NAME_USE_NONE"; break;
136 case SID_NAME_USER: return "SID_NAME_USER"; break;
137 case SID_NAME_DOM_GRP: return "SID_NAME_DOM_GRP"; break;
138 case SID_NAME_DOMAIN: return "SID_NAME_DOMAIN"; break;
139 case SID_NAME_ALIAS: return "SID_NAME_ALIAS"; break;
140 case SID_NAME_WKN_GRP: return "SID_NAME_WKN_GRP"; break;
141 case SID_NAME_DELETED: return "SID_NAME_DELETED"; break;
142 case SID_NAME_INVALID: return "SID_NAME_INVALID"; break;
143 case SID_NAME_UNKNOWN: return "SID_NAME_UNKNOWN"; break;
144 case SID_NAME_COMPUTER: return "SID_NAME_COMPUTER"; break;
146 return "Invalid sid type\n";
149 static bool test_LookupNames(struct dcerpc_pipe *p,
150 TALLOC_CTX *mem_ctx,
151 struct policy_handle *handle,
152 struct lsa_TransNameArray *tnames)
154 struct lsa_LookupNames r;
155 struct lsa_TransSidArray sids;
156 struct lsa_RefDomainList *domains = NULL;
157 struct lsa_String *names;
158 uint32_t count = 0;
159 NTSTATUS status;
160 int i;
162 printf("\nTesting LookupNames with %d names\n", tnames->count);
164 sids.count = 0;
165 sids.sids = NULL;
167 names = talloc_array(mem_ctx, struct lsa_String, tnames->count);
168 for (i=0;i<tnames->count;i++) {
169 init_lsa_String(&names[i], tnames->names[i].name.string);
172 r.in.handle = handle;
173 r.in.num_names = tnames->count;
174 r.in.names = names;
175 r.in.sids = &sids;
176 r.in.level = 1;
177 r.in.count = &count;
178 r.out.count = &count;
179 r.out.sids = &sids;
180 r.out.domains = &domains;
182 status = dcerpc_lsa_LookupNames(p, mem_ctx, &r);
184 if (NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED) ||
185 NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED)) {
186 for (i=0;i< tnames->count;i++) {
187 if (i < count && sids.sids[i].sid_type == SID_NAME_UNKNOWN) {
188 printf("LookupName of %s was unmapped\n",
189 tnames->names[i].name.string);
190 } else if (i >=count) {
191 printf("LookupName of %s failed to return a result\n",
192 tnames->names[i].name.string);
195 printf("LookupNames failed - %s\n", nt_errstr(status));
196 return false;
197 } else if (!NT_STATUS_IS_OK(status)) {
198 printf("LookupNames failed - %s\n", nt_errstr(status));
199 return false;
202 for (i=0;i< tnames->count;i++) {
203 if (i < count && sids.sids[i].sid_type != tnames->names[i].sid_type) {
204 printf("LookupName of %s got unexpected name type: %s\n",
205 tnames->names[i].name.string, sid_type_lookup(sids.sids[i].sid_type));
206 } else if (i >=count) {
207 printf("LookupName of %s failed to return a result\n",
208 tnames->names[i].name.string);
211 printf("\n");
213 return true;
216 static bool test_LookupNames_bogus(struct dcerpc_pipe *p,
217 TALLOC_CTX *mem_ctx,
218 struct policy_handle *handle)
220 struct lsa_LookupNames r;
221 struct lsa_TransSidArray sids;
222 struct lsa_RefDomainList *domains = NULL;
223 struct lsa_String *names;
224 uint32_t count = 0;
225 NTSTATUS status;
226 int i;
228 struct lsa_TranslatedName name[2];
229 struct lsa_TransNameArray tnames;
231 tnames.names = name;
232 tnames.count = 2;
233 name[0].name.string = "NT AUTHORITY\\BOGUS";
234 name[1].name.string = NULL;
236 printf("\nTesting LookupNames with bogus names\n");
238 sids.count = 0;
239 sids.sids = NULL;
241 names = talloc_array(mem_ctx, struct lsa_String, tnames.count);
242 for (i=0;i<tnames.count;i++) {
243 init_lsa_String(&names[i], tnames.names[i].name.string);
246 r.in.handle = handle;
247 r.in.num_names = tnames.count;
248 r.in.names = names;
249 r.in.sids = &sids;
250 r.in.level = 1;
251 r.in.count = &count;
252 r.out.count = &count;
253 r.out.sids = &sids;
254 r.out.domains = &domains;
256 status = dcerpc_lsa_LookupNames(p, mem_ctx, &r);
257 if (!NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED)) {
258 printf("LookupNames failed - %s\n", nt_errstr(status));
259 return false;
262 printf("\n");
264 return true;
267 static bool test_LookupNames_wellknown(struct dcerpc_pipe *p,
268 TALLOC_CTX *mem_ctx,
269 struct policy_handle *handle)
271 struct lsa_TranslatedName name;
272 struct lsa_TransNameArray tnames;
273 bool ret = true;
275 printf("Testing LookupNames with well known names\n");
277 tnames.names = &name;
278 tnames.count = 1;
279 name.name.string = "NT AUTHORITY\\SYSTEM";
280 name.sid_type = SID_NAME_WKN_GRP;
281 ret &= test_LookupNames(p, mem_ctx, handle, &tnames);
283 name.name.string = "NT AUTHORITY\\ANONYMOUS LOGON";
284 name.sid_type = SID_NAME_WKN_GRP;
285 ret &= test_LookupNames(p, mem_ctx, handle, &tnames);
287 name.name.string = "NT AUTHORITY\\Authenticated Users";
288 name.sid_type = SID_NAME_WKN_GRP;
289 ret &= test_LookupNames(p, mem_ctx, handle, &tnames);
291 #if 0
292 name.name.string = "NT AUTHORITY";
293 ret &= test_LookupNames(p, mem_ctx, handle, &tnames);
295 name.name.string = "NT AUTHORITY\\";
296 ret &= test_LookupNames(p, mem_ctx, handle, &tnames);
297 #endif
299 name.name.string = "BUILTIN\\";
300 name.sid_type = SID_NAME_DOMAIN;
301 ret &= test_LookupNames(p, mem_ctx, handle, &tnames);
303 name.name.string = "BUILTIN\\Administrators";
304 name.sid_type = SID_NAME_ALIAS;
305 ret &= test_LookupNames(p, mem_ctx, handle, &tnames);
307 name.name.string = "SYSTEM";
308 name.sid_type = SID_NAME_WKN_GRP;
309 ret &= test_LookupNames(p, mem_ctx, handle, &tnames);
311 name.name.string = "Everyone";
312 name.sid_type = SID_NAME_WKN_GRP;
313 ret &= test_LookupNames(p, mem_ctx, handle, &tnames);
314 return ret;
317 static bool test_LookupNames2(struct dcerpc_pipe *p,
318 TALLOC_CTX *mem_ctx,
319 struct policy_handle *handle,
320 struct lsa_TransNameArray2 *tnames)
322 struct lsa_LookupNames2 r;
323 struct lsa_TransSidArray2 sids;
324 struct lsa_RefDomainList *domains = NULL;
325 struct lsa_String *names;
326 uint32_t count = 0;
327 NTSTATUS status;
328 int i;
330 printf("\nTesting LookupNames2 with %d names\n", tnames->count);
332 sids.count = 0;
333 sids.sids = NULL;
335 names = talloc_array(mem_ctx, struct lsa_String, tnames->count);
336 for (i=0;i<tnames->count;i++) {
337 init_lsa_String(&names[i], tnames->names[i].name.string);
340 r.in.handle = handle;
341 r.in.num_names = tnames->count;
342 r.in.names = names;
343 r.in.sids = &sids;
344 r.in.level = 1;
345 r.in.count = &count;
346 r.in.lookup_options = 0;
347 r.in.client_revision = 0;
348 r.out.count = &count;
349 r.out.sids = &sids;
350 r.out.domains = &domains;
352 status = dcerpc_lsa_LookupNames2(p, mem_ctx, &r);
353 if (!NT_STATUS_IS_OK(status)) {
354 printf("LookupNames2 failed - %s\n", nt_errstr(status));
355 return false;
358 printf("\n");
360 return true;
364 static bool test_LookupNames3(struct dcerpc_pipe *p,
365 TALLOC_CTX *mem_ctx,
366 struct policy_handle *handle,
367 struct lsa_TransNameArray2 *tnames)
369 struct lsa_LookupNames3 r;
370 struct lsa_TransSidArray3 sids;
371 struct lsa_RefDomainList *domains = NULL;
372 struct lsa_String *names;
373 uint32_t count = 0;
374 NTSTATUS status;
375 int i;
377 printf("\nTesting LookupNames3 with %d names\n", tnames->count);
379 sids.count = 0;
380 sids.sids = NULL;
382 names = talloc_array(mem_ctx, struct lsa_String, tnames->count);
383 for (i=0;i<tnames->count;i++) {
384 init_lsa_String(&names[i], tnames->names[i].name.string);
387 r.in.handle = handle;
388 r.in.num_names = tnames->count;
389 r.in.names = names;
390 r.in.sids = &sids;
391 r.in.level = 1;
392 r.in.count = &count;
393 r.in.lookup_options = 0;
394 r.in.client_revision = 0;
395 r.out.count = &count;
396 r.out.sids = &sids;
397 r.out.domains = &domains;
399 status = dcerpc_lsa_LookupNames3(p, mem_ctx, &r);
400 if (!NT_STATUS_IS_OK(status)) {
401 printf("LookupNames3 failed - %s\n", nt_errstr(status));
402 return false;
405 printf("\n");
407 return true;
410 static bool test_LookupNames4(struct dcerpc_pipe *p,
411 TALLOC_CTX *mem_ctx,
412 struct lsa_TransNameArray2 *tnames)
414 struct lsa_LookupNames4 r;
415 struct lsa_TransSidArray3 sids;
416 struct lsa_RefDomainList *domains = NULL;
417 struct lsa_String *names;
418 uint32_t count = 0;
419 NTSTATUS status;
420 int i;
422 printf("\nTesting LookupNames4 with %d names\n", tnames->count);
424 sids.count = 0;
425 sids.sids = NULL;
427 names = talloc_array(mem_ctx, struct lsa_String, tnames->count);
428 for (i=0;i<tnames->count;i++) {
429 init_lsa_String(&names[i], tnames->names[i].name.string);
432 r.in.num_names = tnames->count;
433 r.in.names = names;
434 r.in.sids = &sids;
435 r.in.level = 1;
436 r.in.count = &count;
437 r.in.lookup_options = 0;
438 r.in.client_revision = 0;
439 r.out.count = &count;
440 r.out.sids = &sids;
441 r.out.domains = &domains;
443 status = dcerpc_lsa_LookupNames4(p, mem_ctx, &r);
444 if (!NT_STATUS_IS_OK(status)) {
445 printf("LookupNames4 failed - %s\n", nt_errstr(status));
446 return false;
449 printf("\n");
451 return true;
455 static bool test_LookupSids(struct dcerpc_pipe *p,
456 TALLOC_CTX *mem_ctx,
457 struct policy_handle *handle,
458 struct lsa_SidArray *sids)
460 struct lsa_LookupSids r;
461 struct lsa_TransNameArray names;
462 struct lsa_RefDomainList *domains = NULL;
463 uint32_t count = sids->num_sids;
464 NTSTATUS status;
466 printf("\nTesting LookupSids\n");
468 names.count = 0;
469 names.names = NULL;
471 r.in.handle = handle;
472 r.in.sids = sids;
473 r.in.names = &names;
474 r.in.level = 1;
475 r.in.count = &count;
476 r.out.count = &count;
477 r.out.names = &names;
478 r.out.domains = &domains;
480 status = dcerpc_lsa_LookupSids(p, mem_ctx, &r);
481 if (!NT_STATUS_IS_OK(status)) {
482 printf("LookupSids failed - %s\n", nt_errstr(status));
483 return false;
486 printf("\n");
488 if (!test_LookupNames(p, mem_ctx, handle, &names)) {
489 return false;
492 return true;
496 static bool test_LookupSids2(struct dcerpc_pipe *p,
497 TALLOC_CTX *mem_ctx,
498 struct policy_handle *handle,
499 struct lsa_SidArray *sids)
501 struct lsa_LookupSids2 r;
502 struct lsa_TransNameArray2 names;
503 struct lsa_RefDomainList *domains = NULL;
504 uint32_t count = sids->num_sids;
505 NTSTATUS status;
507 printf("\nTesting LookupSids2\n");
509 names.count = 0;
510 names.names = NULL;
512 r.in.handle = handle;
513 r.in.sids = sids;
514 r.in.names = &names;
515 r.in.level = 1;
516 r.in.count = &count;
517 r.in.unknown1 = 0;
518 r.in.unknown2 = 0;
519 r.out.count = &count;
520 r.out.names = &names;
521 r.out.domains = &domains;
523 status = dcerpc_lsa_LookupSids2(p, mem_ctx, &r);
524 if (!NT_STATUS_IS_OK(status)) {
525 printf("LookupSids2 failed - %s\n", nt_errstr(status));
526 return false;
529 printf("\n");
531 if (!test_LookupNames2(p, mem_ctx, handle, &names)) {
532 return false;
535 if (!test_LookupNames3(p, mem_ctx, handle, &names)) {
536 return false;
539 return true;
542 static bool test_LookupSids3(struct dcerpc_pipe *p,
543 TALLOC_CTX *mem_ctx,
544 struct lsa_SidArray *sids)
546 struct lsa_LookupSids3 r;
547 struct lsa_TransNameArray2 names;
548 struct lsa_RefDomainList *domains = NULL;
549 uint32_t count = sids->num_sids;
550 NTSTATUS status;
552 printf("\nTesting LookupSids3\n");
554 names.count = 0;
555 names.names = NULL;
557 r.in.sids = sids;
558 r.in.names = &names;
559 r.in.level = 1;
560 r.in.count = &count;
561 r.in.unknown1 = 0;
562 r.in.unknown2 = 0;
563 r.out.domains = &domains;
564 r.out.count = &count;
565 r.out.names = &names;
567 status = dcerpc_lsa_LookupSids3(p, mem_ctx, &r);
568 if (!NT_STATUS_IS_OK(status)) {
569 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
570 NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
571 printf("not considering %s to be an error\n", nt_errstr(status));
572 return true;
574 printf("LookupSids3 failed - %s - not considered an error\n",
575 nt_errstr(status));
576 return false;
579 printf("\n");
581 if (!test_LookupNames4(p, mem_ctx, &names)) {
582 return false;
585 return true;
588 bool test_many_LookupSids(struct dcerpc_pipe *p,
589 TALLOC_CTX *mem_ctx,
590 struct policy_handle *handle)
592 uint32_t count;
593 NTSTATUS status;
594 struct lsa_SidArray sids;
595 int i;
597 printf("\nTesting LookupSids with lots of SIDs\n");
599 sids.num_sids = 100;
601 sids.sids = talloc_array(mem_ctx, struct lsa_SidPtr, sids.num_sids);
603 for (i=0; i<sids.num_sids; i++) {
604 const char *sidstr = "S-1-5-32-545";
605 sids.sids[i].sid = dom_sid_parse_talloc(mem_ctx, sidstr);
608 count = sids.num_sids;
610 if (handle) {
611 struct lsa_LookupSids r;
612 struct lsa_TransNameArray names;
613 struct lsa_RefDomainList *domains = NULL;
614 names.count = 0;
615 names.names = NULL;
617 r.in.handle = handle;
618 r.in.sids = &sids;
619 r.in.names = &names;
620 r.in.level = 1;
621 r.in.count = &names.count;
622 r.out.count = &count;
623 r.out.names = &names;
624 r.out.domains = &domains;
626 status = dcerpc_lsa_LookupSids(p, mem_ctx, &r);
627 if (!NT_STATUS_IS_OK(status)) {
628 printf("LookupSids failed - %s\n", nt_errstr(status));
629 return false;
632 printf("\n");
634 if (!test_LookupNames(p, mem_ctx, handle, &names)) {
635 return false;
637 } else if (p->conn->security_state.auth_info->auth_type == DCERPC_AUTH_TYPE_SCHANNEL &&
638 p->conn->security_state.auth_info->auth_level >= DCERPC_AUTH_LEVEL_INTEGRITY) {
639 struct lsa_LookupSids3 r;
640 struct lsa_RefDomainList *domains = NULL;
641 struct lsa_TransNameArray2 names;
643 names.count = 0;
644 names.names = NULL;
646 printf("\nTesting LookupSids3\n");
648 r.in.sids = &sids;
649 r.in.names = &names;
650 r.in.level = 1;
651 r.in.count = &count;
652 r.in.unknown1 = 0;
653 r.in.unknown2 = 0;
654 r.out.count = &count;
655 r.out.names = &names;
656 r.out.domains = &domains;
658 status = dcerpc_lsa_LookupSids3(p, mem_ctx, &r);
659 if (!NT_STATUS_IS_OK(status)) {
660 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
661 NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
662 printf("not considering %s to be an error\n", nt_errstr(status));
663 return true;
665 printf("LookupSids3 failed - %s\n",
666 nt_errstr(status));
667 return false;
669 if (!test_LookupNames4(p, mem_ctx, &names)) {
670 return false;
674 printf("\n");
678 return true;
681 static void lookupsids_cb(struct rpc_request *req)
683 int *replies = (int *)req->async.private_data;
684 NTSTATUS status;
686 status = dcerpc_ndr_request_recv(req);
687 if (!NT_STATUS_IS_OK(status)) {
688 printf("lookupsids returned %s\n", nt_errstr(status));
689 *replies = -1;
692 if (*replies >= 0) {
693 *replies += 1;
697 static bool test_LookupSids_async(struct dcerpc_pipe *p,
698 TALLOC_CTX *mem_ctx,
699 struct policy_handle *handle)
701 struct lsa_SidArray sids;
702 struct lsa_SidPtr sidptr;
703 uint32_t *count;
704 struct lsa_TransNameArray *names;
705 struct lsa_LookupSids *r;
706 struct lsa_RefDomainList *domains = NULL;
707 struct rpc_request **req;
708 int i, replies;
709 bool ret = true;
710 const int num_async_requests = 50;
712 count = talloc_array(mem_ctx, uint32_t, num_async_requests);
713 names = talloc_array(mem_ctx, struct lsa_TransNameArray, num_async_requests);
714 r = talloc_array(mem_ctx, struct lsa_LookupSids, num_async_requests);
716 printf("\nTesting %d async lookupsids request\n", num_async_requests);
718 req = talloc_array(mem_ctx, struct rpc_request *, num_async_requests);
720 sids.num_sids = 1;
721 sids.sids = &sidptr;
722 sidptr.sid = dom_sid_parse_talloc(mem_ctx, "S-1-5-32-545");
724 replies = 0;
726 for (i=0; i<num_async_requests; i++) {
727 count[i] = 0;
728 names[i].count = 0;
729 names[i].names = NULL;
731 r[i].in.handle = handle;
732 r[i].in.sids = &sids;
733 r[i].in.names = &names[i];
734 r[i].in.level = 1;
735 r[i].in.count = &names[i].count;
736 r[i].out.count = &count[i];
737 r[i].out.names = &names[i];
738 r[i].out.domains = &domains;
740 req[i] = dcerpc_lsa_LookupSids_send(p, req, &r[i]);
741 if (req[i] == NULL) {
742 ret = false;
743 break;
746 req[i]->async.callback = lookupsids_cb;
747 req[i]->async.private_data = &replies;
750 while (replies >= 0 && replies < num_async_requests) {
751 event_loop_once(p->conn->event_ctx);
754 talloc_free(req);
756 if (replies < 0) {
757 ret = false;
760 return ret;
763 static bool test_LookupPrivValue(struct dcerpc_pipe *p,
764 TALLOC_CTX *mem_ctx,
765 struct policy_handle *handle,
766 struct lsa_String *name)
768 NTSTATUS status;
769 struct lsa_LookupPrivValue r;
770 struct lsa_LUID luid;
772 r.in.handle = handle;
773 r.in.name = name;
774 r.out.luid = &luid;
776 status = dcerpc_lsa_LookupPrivValue(p, mem_ctx, &r);
777 if (!NT_STATUS_IS_OK(status)) {
778 printf("\nLookupPrivValue failed - %s\n", nt_errstr(status));
779 return false;
782 return true;
785 static bool test_LookupPrivName(struct dcerpc_pipe *p,
786 TALLOC_CTX *mem_ctx,
787 struct policy_handle *handle,
788 struct lsa_LUID *luid)
790 NTSTATUS status;
791 struct lsa_LookupPrivName r;
792 struct lsa_StringLarge *name = NULL;
794 r.in.handle = handle;
795 r.in.luid = luid;
796 r.out.name = &name;
798 status = dcerpc_lsa_LookupPrivName(p, mem_ctx, &r);
799 if (!NT_STATUS_IS_OK(status)) {
800 printf("\nLookupPrivName failed - %s\n", nt_errstr(status));
801 return false;
804 return true;
807 static bool test_RemovePrivilegesFromAccount(struct dcerpc_pipe *p,
808 TALLOC_CTX *mem_ctx,
809 struct policy_handle *handle,
810 struct policy_handle *acct_handle,
811 struct lsa_LUID *luid)
813 NTSTATUS status;
814 struct lsa_RemovePrivilegesFromAccount r;
815 struct lsa_PrivilegeSet privs;
816 bool ret = true;
818 printf("\nTesting RemovePrivilegesFromAccount\n");
820 r.in.handle = acct_handle;
821 r.in.remove_all = 0;
822 r.in.privs = &privs;
824 privs.count = 1;
825 privs.unknown = 0;
826 privs.set = talloc_array(mem_ctx, struct lsa_LUIDAttribute, 1);
827 privs.set[0].luid = *luid;
828 privs.set[0].attribute = 0;
830 status = dcerpc_lsa_RemovePrivilegesFromAccount(p, mem_ctx, &r);
831 if (!NT_STATUS_IS_OK(status)) {
833 struct lsa_LookupPrivName r_name;
834 struct lsa_StringLarge *name = NULL;
836 r_name.in.handle = handle;
837 r_name.in.luid = luid;
838 r_name.out.name = &name;
840 status = dcerpc_lsa_LookupPrivName(p, mem_ctx, &r_name);
841 if (!NT_STATUS_IS_OK(status)) {
842 printf("\nLookupPrivName failed - %s\n", nt_errstr(status));
843 return false;
845 /* Windows 2008 does not allow this to be removed */
846 if (strcmp("SeAuditPrivilege", name->string) == 0) {
847 return ret;
850 printf("RemovePrivilegesFromAccount failed to remove %s - %s\n",
851 name->string,
852 nt_errstr(status));
853 return false;
856 return ret;
859 static bool test_AddPrivilegesToAccount(struct dcerpc_pipe *p,
860 TALLOC_CTX *mem_ctx,
861 struct policy_handle *acct_handle,
862 struct lsa_LUID *luid)
864 NTSTATUS status;
865 struct lsa_AddPrivilegesToAccount r;
866 struct lsa_PrivilegeSet privs;
867 bool ret = true;
869 printf("\nTesting AddPrivilegesToAccount\n");
871 r.in.handle = acct_handle;
872 r.in.privs = &privs;
874 privs.count = 1;
875 privs.unknown = 0;
876 privs.set = talloc_array(mem_ctx, struct lsa_LUIDAttribute, 1);
877 privs.set[0].luid = *luid;
878 privs.set[0].attribute = 0;
880 status = dcerpc_lsa_AddPrivilegesToAccount(p, mem_ctx, &r);
881 if (!NT_STATUS_IS_OK(status)) {
882 printf("AddPrivilegesToAccount failed - %s\n", nt_errstr(status));
883 return false;
886 return ret;
889 static bool test_EnumPrivsAccount(struct dcerpc_pipe *p,
890 TALLOC_CTX *mem_ctx,
891 struct policy_handle *handle,
892 struct policy_handle *acct_handle)
894 NTSTATUS status;
895 struct lsa_EnumPrivsAccount r;
896 struct lsa_PrivilegeSet *privs = NULL;
897 bool ret = true;
899 printf("\nTesting EnumPrivsAccount\n");
901 r.in.handle = acct_handle;
902 r.out.privs = &privs;
904 status = dcerpc_lsa_EnumPrivsAccount(p, mem_ctx, &r);
905 if (!NT_STATUS_IS_OK(status)) {
906 printf("EnumPrivsAccount failed - %s\n", nt_errstr(status));
907 return false;
910 if (privs && privs->count > 0) {
911 int i;
912 for (i=0;i<privs->count;i++) {
913 test_LookupPrivName(p, mem_ctx, handle,
914 &privs->set[i].luid);
917 ret &= test_RemovePrivilegesFromAccount(p, mem_ctx, handle, acct_handle,
918 &privs->set[0].luid);
919 ret &= test_AddPrivilegesToAccount(p, mem_ctx, acct_handle,
920 &privs->set[0].luid);
923 return ret;
926 static bool test_GetSystemAccessAccount(struct dcerpc_pipe *p,
927 TALLOC_CTX *mem_ctx,
928 struct policy_handle *handle,
929 struct policy_handle *acct_handle)
931 NTSTATUS status;
932 uint32_t access_mask;
933 struct lsa_GetSystemAccessAccount r;
935 printf("\nTesting GetSystemAccessAccount\n");
937 r.in.handle = acct_handle;
938 r.out.access_mask = &access_mask;
940 status = dcerpc_lsa_GetSystemAccessAccount(p, mem_ctx, &r);
941 if (!NT_STATUS_IS_OK(status)) {
942 printf("GetSystemAccessAccount failed - %s\n", nt_errstr(status));
943 return false;
946 if (r.out.access_mask != NULL) {
947 printf("Rights:");
948 if (*(r.out.access_mask) & LSA_POLICY_MODE_INTERACTIVE)
949 printf(" LSA_POLICY_MODE_INTERACTIVE");
950 if (*(r.out.access_mask) & LSA_POLICY_MODE_NETWORK)
951 printf(" LSA_POLICY_MODE_NETWORK");
952 if (*(r.out.access_mask) & LSA_POLICY_MODE_BATCH)
953 printf(" LSA_POLICY_MODE_BATCH");
954 if (*(r.out.access_mask) & LSA_POLICY_MODE_SERVICE)
955 printf(" LSA_POLICY_MODE_SERVICE");
956 if (*(r.out.access_mask) & LSA_POLICY_MODE_PROXY)
957 printf(" LSA_POLICY_MODE_PROXY");
958 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_INTERACTIVE)
959 printf(" LSA_POLICY_MODE_DENY_INTERACTIVE");
960 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_NETWORK)
961 printf(" LSA_POLICY_MODE_DENY_NETWORK");
962 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_BATCH)
963 printf(" LSA_POLICY_MODE_DENY_BATCH");
964 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_SERVICE)
965 printf(" LSA_POLICY_MODE_DENY_SERVICE");
966 if (*(r.out.access_mask) & LSA_POLICY_MODE_REMOTE_INTERACTIVE)
967 printf(" LSA_POLICY_MODE_REMOTE_INTERACTIVE");
968 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_REMOTE_INTERACTIVE)
969 printf(" LSA_POLICY_MODE_DENY_REMOTE_INTERACTIVE");
970 if (*(r.out.access_mask) & LSA_POLICY_MODE_ALL)
971 printf(" LSA_POLICY_MODE_ALL");
972 if (*(r.out.access_mask) & LSA_POLICY_MODE_ALL_NT4)
973 printf(" LSA_POLICY_MODE_ALL_NT4");
974 printf("\n");
977 return true;
980 static bool test_Delete(struct dcerpc_pipe *p,
981 TALLOC_CTX *mem_ctx,
982 struct policy_handle *handle)
984 NTSTATUS status;
985 struct lsa_Delete r;
987 printf("\nTesting Delete\n");
989 r.in.handle = handle;
990 status = dcerpc_lsa_Delete(p, mem_ctx, &r);
991 if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
992 printf("Delete should have failed NT_STATUS_NOT_SUPPORTED - %s\n", nt_errstr(status));
993 return false;
996 return true;
999 static bool test_DeleteObject(struct dcerpc_pipe *p,
1000 TALLOC_CTX *mem_ctx,
1001 struct policy_handle *handle)
1003 NTSTATUS status;
1004 struct lsa_DeleteObject r;
1006 printf("\nTesting DeleteObject\n");
1008 r.in.handle = handle;
1009 r.out.handle = handle;
1010 status = dcerpc_lsa_DeleteObject(p, mem_ctx, &r);
1011 if (!NT_STATUS_IS_OK(status)) {
1012 printf("DeleteObject failed - %s\n", nt_errstr(status));
1013 return false;
1016 return true;
1020 static bool test_CreateAccount(struct dcerpc_pipe *p,
1021 TALLOC_CTX *mem_ctx,
1022 struct policy_handle *handle)
1024 NTSTATUS status;
1025 struct lsa_CreateAccount r;
1026 struct dom_sid2 *newsid;
1027 struct policy_handle acct_handle;
1029 newsid = dom_sid_parse_talloc(mem_ctx, "S-1-5-12349876-4321-2854");
1031 printf("\nTesting CreateAccount\n");
1033 r.in.handle = handle;
1034 r.in.sid = newsid;
1035 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1036 r.out.acct_handle = &acct_handle;
1038 status = dcerpc_lsa_CreateAccount(p, mem_ctx, &r);
1039 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
1040 struct lsa_OpenAccount r_o;
1041 r_o.in.handle = handle;
1042 r_o.in.sid = newsid;
1043 r_o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1044 r_o.out.acct_handle = &acct_handle;
1046 status = dcerpc_lsa_OpenAccount(p, mem_ctx, &r_o);
1047 if (!NT_STATUS_IS_OK(status)) {
1048 printf("OpenAccount failed - %s\n", nt_errstr(status));
1049 return false;
1051 } else if (!NT_STATUS_IS_OK(status)) {
1052 printf("CreateAccount failed - %s\n", nt_errstr(status));
1053 return false;
1056 if (!test_Delete(p, mem_ctx, &acct_handle)) {
1057 return false;
1060 if (!test_DeleteObject(p, mem_ctx, &acct_handle)) {
1061 return false;
1064 return true;
1067 static bool test_DeleteTrustedDomain(struct dcerpc_pipe *p,
1068 TALLOC_CTX *mem_ctx,
1069 struct policy_handle *handle,
1070 struct lsa_StringLarge name)
1072 NTSTATUS status;
1073 struct lsa_OpenTrustedDomainByName r;
1074 struct policy_handle trustdom_handle;
1076 r.in.handle = handle;
1077 r.in.name.string = name.string;
1078 r.in.access_mask = SEC_STD_DELETE;
1079 r.out.trustdom_handle = &trustdom_handle;
1081 status = dcerpc_lsa_OpenTrustedDomainByName(p, mem_ctx, &r);
1082 if (!NT_STATUS_IS_OK(status)) {
1083 printf("OpenTrustedDomainByName failed - %s\n", nt_errstr(status));
1084 return false;
1087 if (!test_Delete(p, mem_ctx, &trustdom_handle)) {
1088 return false;
1091 if (!test_DeleteObject(p, mem_ctx, &trustdom_handle)) {
1092 return false;
1095 return true;
1098 static bool test_DeleteTrustedDomainBySid(struct dcerpc_pipe *p,
1099 TALLOC_CTX *mem_ctx,
1100 struct policy_handle *handle,
1101 struct dom_sid *sid)
1103 NTSTATUS status;
1104 struct lsa_DeleteTrustedDomain r;
1106 r.in.handle = handle;
1107 r.in.dom_sid = sid;
1109 status = dcerpc_lsa_DeleteTrustedDomain(p, mem_ctx, &r);
1110 if (!NT_STATUS_IS_OK(status)) {
1111 printf("DeleteTrustedDomain failed - %s\n", nt_errstr(status));
1112 return false;
1115 return true;
1119 static bool test_CreateSecret(struct dcerpc_pipe *p,
1120 TALLOC_CTX *mem_ctx,
1121 struct policy_handle *handle)
1123 NTSTATUS status;
1124 struct lsa_CreateSecret r;
1125 struct lsa_OpenSecret r2;
1126 struct lsa_SetSecret r3;
1127 struct lsa_QuerySecret r4;
1128 struct lsa_SetSecret r5;
1129 struct lsa_QuerySecret r6;
1130 struct lsa_SetSecret r7;
1131 struct lsa_QuerySecret r8;
1132 struct policy_handle sec_handle, sec_handle2, sec_handle3;
1133 struct lsa_DeleteObject d_o;
1134 struct lsa_DATA_BUF buf1;
1135 struct lsa_DATA_BUF_PTR bufp1;
1136 struct lsa_DATA_BUF_PTR bufp2;
1137 DATA_BLOB enc_key;
1138 bool ret = true;
1139 DATA_BLOB session_key;
1140 NTTIME old_mtime, new_mtime;
1141 DATA_BLOB blob1, blob2;
1142 const char *secret1 = "abcdef12345699qwerty";
1143 char *secret2;
1144 const char *secret3 = "ABCDEF12345699QWERTY";
1145 char *secret4;
1146 const char *secret5 = "NEW-SAMBA4-SECRET";
1147 char *secret6;
1148 char *secname[2];
1149 int i;
1150 const int LOCAL = 0;
1151 const int GLOBAL = 1;
1153 secname[LOCAL] = talloc_asprintf(mem_ctx, "torturesecret-%u", (uint_t)random());
1154 secname[GLOBAL] = talloc_asprintf(mem_ctx, "G$torturesecret-%u", (uint_t)random());
1156 for (i=0; i< 2; i++) {
1157 printf("\nTesting CreateSecret of %s\n", secname[i]);
1159 init_lsa_String(&r.in.name, secname[i]);
1161 r.in.handle = handle;
1162 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1163 r.out.sec_handle = &sec_handle;
1165 status = dcerpc_lsa_CreateSecret(p, mem_ctx, &r);
1166 if (!NT_STATUS_IS_OK(status)) {
1167 printf("CreateSecret failed - %s\n", nt_errstr(status));
1168 return false;
1171 r.in.handle = handle;
1172 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1173 r.out.sec_handle = &sec_handle3;
1175 status = dcerpc_lsa_CreateSecret(p, mem_ctx, &r);
1176 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
1177 printf("CreateSecret should have failed OBJECT_NAME_COLLISION - %s\n", nt_errstr(status));
1178 return false;
1181 r2.in.handle = handle;
1182 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1183 r2.in.name = r.in.name;
1184 r2.out.sec_handle = &sec_handle2;
1186 printf("Testing OpenSecret\n");
1188 status = dcerpc_lsa_OpenSecret(p, mem_ctx, &r2);
1189 if (!NT_STATUS_IS_OK(status)) {
1190 printf("OpenSecret failed - %s\n", nt_errstr(status));
1191 return false;
1194 status = dcerpc_fetch_session_key(p, &session_key);
1195 if (!NT_STATUS_IS_OK(status)) {
1196 printf("dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
1197 return false;
1200 enc_key = sess_encrypt_string(secret1, &session_key);
1202 r3.in.sec_handle = &sec_handle;
1203 r3.in.new_val = &buf1;
1204 r3.in.old_val = NULL;
1205 r3.in.new_val->data = enc_key.data;
1206 r3.in.new_val->length = enc_key.length;
1207 r3.in.new_val->size = enc_key.length;
1209 printf("Testing SetSecret\n");
1211 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r3);
1212 if (!NT_STATUS_IS_OK(status)) {
1213 printf("SetSecret failed - %s\n", nt_errstr(status));
1214 return false;
1217 r3.in.sec_handle = &sec_handle;
1218 r3.in.new_val = &buf1;
1219 r3.in.old_val = NULL;
1220 r3.in.new_val->data = enc_key.data;
1221 r3.in.new_val->length = enc_key.length;
1222 r3.in.new_val->size = enc_key.length;
1224 /* break the encrypted data */
1225 enc_key.data[0]++;
1227 printf("Testing SetSecret with broken key\n");
1229 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r3);
1230 if (!NT_STATUS_EQUAL(status, NT_STATUS_UNKNOWN_REVISION)) {
1231 printf("SetSecret should have failed UNKNOWN_REVISION - %s\n", nt_errstr(status));
1232 ret = false;
1235 data_blob_free(&enc_key);
1237 ZERO_STRUCT(new_mtime);
1238 ZERO_STRUCT(old_mtime);
1240 /* fetch the secret back again */
1241 r4.in.sec_handle = &sec_handle;
1242 r4.in.new_val = &bufp1;
1243 r4.in.new_mtime = &new_mtime;
1244 r4.in.old_val = NULL;
1245 r4.in.old_mtime = NULL;
1247 bufp1.buf = NULL;
1249 printf("Testing QuerySecret\n");
1250 status = dcerpc_lsa_QuerySecret(p, mem_ctx, &r4);
1251 if (!NT_STATUS_IS_OK(status)) {
1252 printf("QuerySecret failed - %s\n", nt_errstr(status));
1253 ret = false;
1254 } else {
1255 if (r4.out.new_val == NULL || r4.out.new_val->buf == NULL) {
1256 printf("No secret buffer returned\n");
1257 ret = false;
1258 } else {
1259 blob1.data = r4.out.new_val->buf->data;
1260 blob1.length = r4.out.new_val->buf->size;
1262 blob2 = data_blob_talloc(mem_ctx, NULL, blob1.length);
1264 secret2 = sess_decrypt_string(mem_ctx,
1265 &blob1, &session_key);
1267 if (strcmp(secret1, secret2) != 0) {
1268 printf("Returned secret (r4) '%s' doesn't match '%s'\n",
1269 secret2, secret1);
1270 ret = false;
1275 enc_key = sess_encrypt_string(secret3, &session_key);
1277 r5.in.sec_handle = &sec_handle;
1278 r5.in.new_val = &buf1;
1279 r5.in.old_val = NULL;
1280 r5.in.new_val->data = enc_key.data;
1281 r5.in.new_val->length = enc_key.length;
1282 r5.in.new_val->size = enc_key.length;
1285 msleep(200);
1286 printf("Testing SetSecret (existing value should move to old)\n");
1288 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r5);
1289 if (!NT_STATUS_IS_OK(status)) {
1290 printf("SetSecret failed - %s\n", nt_errstr(status));
1291 ret = false;
1294 data_blob_free(&enc_key);
1296 ZERO_STRUCT(new_mtime);
1297 ZERO_STRUCT(old_mtime);
1299 /* fetch the secret back again */
1300 r6.in.sec_handle = &sec_handle;
1301 r6.in.new_val = &bufp1;
1302 r6.in.new_mtime = &new_mtime;
1303 r6.in.old_val = &bufp2;
1304 r6.in.old_mtime = &old_mtime;
1306 bufp1.buf = NULL;
1307 bufp2.buf = NULL;
1309 status = dcerpc_lsa_QuerySecret(p, mem_ctx, &r6);
1310 if (!NT_STATUS_IS_OK(status)) {
1311 printf("QuerySecret failed - %s\n", nt_errstr(status));
1312 ret = false;
1313 secret4 = NULL;
1314 } else {
1316 if (r6.out.new_val->buf == NULL || r6.out.old_val->buf == NULL
1317 || r6.out.new_mtime == NULL || r6.out.old_mtime == NULL) {
1318 printf("Both secret buffers and both times not returned\n");
1319 ret = false;
1320 secret4 = NULL;
1321 } else {
1322 blob1.data = r6.out.new_val->buf->data;
1323 blob1.length = r6.out.new_val->buf->size;
1325 blob2 = data_blob_talloc(mem_ctx, NULL, blob1.length);
1327 secret4 = sess_decrypt_string(mem_ctx,
1328 &blob1, &session_key);
1330 if (strcmp(secret3, secret4) != 0) {
1331 printf("Returned NEW secret %s doesn't match %s\n", secret4, secret3);
1332 ret = false;
1335 blob1.data = r6.out.old_val->buf->data;
1336 blob1.length = r6.out.old_val->buf->length;
1338 blob2 = data_blob_talloc(mem_ctx, NULL, blob1.length);
1340 secret2 = sess_decrypt_string(mem_ctx,
1341 &blob1, &session_key);
1343 if (strcmp(secret1, secret2) != 0) {
1344 printf("Returned OLD secret %s doesn't match %s\n", secret2, secret1);
1345 ret = false;
1348 if (*r6.out.new_mtime == *r6.out.old_mtime) {
1349 printf("Returned secret (r6-%d) %s must not have same mtime for both secrets: %s != %s\n",
1351 secname[i],
1352 nt_time_string(mem_ctx, *r6.out.old_mtime),
1353 nt_time_string(mem_ctx, *r6.out.new_mtime));
1354 ret = false;
1359 enc_key = sess_encrypt_string(secret5, &session_key);
1361 r7.in.sec_handle = &sec_handle;
1362 r7.in.old_val = &buf1;
1363 r7.in.old_val->data = enc_key.data;
1364 r7.in.old_val->length = enc_key.length;
1365 r7.in.old_val->size = enc_key.length;
1366 r7.in.new_val = NULL;
1368 printf("Testing SetSecret of old Secret only\n");
1370 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r7);
1371 if (!NT_STATUS_IS_OK(status)) {
1372 printf("SetSecret failed - %s\n", nt_errstr(status));
1373 ret = false;
1376 data_blob_free(&enc_key);
1378 /* fetch the secret back again */
1379 r8.in.sec_handle = &sec_handle;
1380 r8.in.new_val = &bufp1;
1381 r8.in.new_mtime = &new_mtime;
1382 r8.in.old_val = &bufp2;
1383 r8.in.old_mtime = &old_mtime;
1385 bufp1.buf = NULL;
1386 bufp2.buf = NULL;
1388 status = dcerpc_lsa_QuerySecret(p, mem_ctx, &r8);
1389 if (!NT_STATUS_IS_OK(status)) {
1390 printf("QuerySecret failed - %s\n", nt_errstr(status));
1391 ret = false;
1392 } else {
1393 if (!r8.out.new_val || !r8.out.old_val) {
1394 printf("in/out pointers not returned, despite being set on in for QuerySecret\n");
1395 ret = false;
1396 } else if (r8.out.new_val->buf != NULL) {
1397 printf("NEW secret buffer must not be returned after OLD set\n");
1398 ret = false;
1399 } else if (r8.out.old_val->buf == NULL) {
1400 printf("OLD secret buffer was not returned after OLD set\n");
1401 ret = false;
1402 } else if (r8.out.new_mtime == NULL || r8.out.old_mtime == NULL) {
1403 printf("Both times not returned after OLD set\n");
1404 ret = false;
1405 } else {
1406 blob1.data = r8.out.old_val->buf->data;
1407 blob1.length = r8.out.old_val->buf->size;
1409 blob2 = data_blob_talloc(mem_ctx, NULL, blob1.length);
1411 secret6 = sess_decrypt_string(mem_ctx,
1412 &blob1, &session_key);
1414 if (strcmp(secret5, secret6) != 0) {
1415 printf("Returned OLD secret %s doesn't match %s\n", secret5, secret6);
1416 ret = false;
1419 if (*r8.out.new_mtime != *r8.out.old_mtime) {
1420 printf("Returned secret (r8) %s did not had same mtime for both secrets: %s != %s\n",
1421 secname[i],
1422 nt_time_string(mem_ctx, *r8.out.old_mtime),
1423 nt_time_string(mem_ctx, *r8.out.new_mtime));
1424 ret = false;
1429 if (!test_Delete(p, mem_ctx, &sec_handle)) {
1430 ret = false;
1433 if (!test_DeleteObject(p, mem_ctx, &sec_handle)) {
1434 return false;
1437 d_o.in.handle = &sec_handle2;
1438 d_o.out.handle = &sec_handle2;
1439 status = dcerpc_lsa_DeleteObject(p, mem_ctx, &d_o);
1440 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1441 printf("Second delete expected INVALID_HANDLE - %s\n", nt_errstr(status));
1442 ret = false;
1443 } else {
1445 printf("Testing OpenSecret of just-deleted secret\n");
1447 status = dcerpc_lsa_OpenSecret(p, mem_ctx, &r2);
1448 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
1449 printf("OpenSecret expected OBJECT_NAME_NOT_FOUND - %s\n", nt_errstr(status));
1450 ret = false;
1456 return ret;
1460 static bool test_EnumAccountRights(struct dcerpc_pipe *p,
1461 TALLOC_CTX *mem_ctx,
1462 struct policy_handle *acct_handle,
1463 struct dom_sid *sid)
1465 NTSTATUS status;
1466 struct lsa_EnumAccountRights r;
1467 struct lsa_RightSet rights;
1469 printf("\nTesting EnumAccountRights\n");
1471 r.in.handle = acct_handle;
1472 r.in.sid = sid;
1473 r.out.rights = &rights;
1475 status = dcerpc_lsa_EnumAccountRights(p, mem_ctx, &r);
1476 if (!NT_STATUS_IS_OK(status)) {
1477 printf("EnumAccountRights of %s failed - %s\n",
1478 dom_sid_string(mem_ctx, sid), nt_errstr(status));
1479 return false;
1482 return true;
1486 static bool test_QuerySecurity(struct dcerpc_pipe *p,
1487 struct torture_context *tctx,
1488 struct policy_handle *handle,
1489 struct policy_handle *acct_handle)
1491 NTSTATUS status;
1492 struct lsa_QuerySecurity r;
1493 struct sec_desc_buf *sdbuf = NULL;
1495 if (torture_setting_bool(tctx, "samba4", false)) {
1496 printf("\nskipping QuerySecurity test against Samba4\n");
1497 return true;
1500 printf("\nTesting QuerySecurity\n");
1502 r.in.handle = acct_handle;
1503 r.in.sec_info = 7;
1504 r.out.sdbuf = &sdbuf;
1506 status = dcerpc_lsa_QuerySecurity(p, tctx, &r);
1507 if (!NT_STATUS_IS_OK(status)) {
1508 printf("QuerySecurity failed - %s\n", nt_errstr(status));
1509 return false;
1512 return true;
1515 static bool test_OpenAccount(struct dcerpc_pipe *p,
1516 TALLOC_CTX *mem_ctx,
1517 struct policy_handle *handle,
1518 struct dom_sid *sid)
1520 NTSTATUS status;
1521 struct lsa_OpenAccount r;
1522 struct policy_handle acct_handle;
1524 printf("\nTesting OpenAccount\n");
1526 r.in.handle = handle;
1527 r.in.sid = sid;
1528 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1529 r.out.acct_handle = &acct_handle;
1531 status = dcerpc_lsa_OpenAccount(p, mem_ctx, &r);
1532 if (!NT_STATUS_IS_OK(status)) {
1533 printf("OpenAccount failed - %s\n", nt_errstr(status));
1534 return false;
1537 if (!test_EnumPrivsAccount(p, mem_ctx, handle, &acct_handle)) {
1538 return false;
1541 if (!test_GetSystemAccessAccount(p, mem_ctx, handle, &acct_handle)) {
1542 return false;
1545 if (!test_QuerySecurity(p, mem_ctx, handle, &acct_handle)) {
1546 return false;
1549 return true;
1552 static bool test_EnumAccounts(struct dcerpc_pipe *p,
1553 TALLOC_CTX *mem_ctx,
1554 struct policy_handle *handle)
1556 NTSTATUS status;
1557 struct lsa_EnumAccounts r;
1558 struct lsa_SidArray sids1, sids2;
1559 uint32_t resume_handle = 0;
1560 int i;
1561 bool ret = true;
1563 printf("\nTesting EnumAccounts\n");
1565 r.in.handle = handle;
1566 r.in.resume_handle = &resume_handle;
1567 r.in.num_entries = 100;
1568 r.out.resume_handle = &resume_handle;
1569 r.out.sids = &sids1;
1571 resume_handle = 0;
1572 while (true) {
1573 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
1574 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
1575 break;
1577 if (!NT_STATUS_IS_OK(status)) {
1578 printf("EnumAccounts failed - %s\n", nt_errstr(status));
1579 return false;
1582 if (!test_LookupSids(p, mem_ctx, handle, &sids1)) {
1583 return false;
1586 if (!test_LookupSids2(p, mem_ctx, handle, &sids1)) {
1587 return false;
1590 /* Can't test lookupSids3 here, as clearly we must not
1591 * be on schannel, or we would not be able to do the
1592 * rest */
1594 printf("Testing all accounts\n");
1595 for (i=0;i<sids1.num_sids;i++) {
1596 ret &= test_OpenAccount(p, mem_ctx, handle, sids1.sids[i].sid);
1597 ret &= test_EnumAccountRights(p, mem_ctx, handle, sids1.sids[i].sid);
1599 printf("\n");
1602 if (sids1.num_sids < 3) {
1603 return ret;
1606 printf("Trying EnumAccounts partial listing (asking for 1 at 2)\n");
1607 resume_handle = 2;
1608 r.in.num_entries = 1;
1609 r.out.sids = &sids2;
1611 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
1612 if (!NT_STATUS_IS_OK(status)) {
1613 printf("EnumAccounts failed - %s\n", nt_errstr(status));
1614 return false;
1617 if (sids2.num_sids != 1) {
1618 printf("Returned wrong number of entries (%d)\n", sids2.num_sids);
1619 return false;
1622 return true;
1625 static bool test_LookupPrivDisplayName(struct dcerpc_pipe *p,
1626 TALLOC_CTX *mem_ctx,
1627 struct policy_handle *handle,
1628 struct lsa_String *priv_name)
1630 struct lsa_LookupPrivDisplayName r;
1631 NTSTATUS status;
1632 /* produce a reasonable range of language output without screwing up
1633 terminals */
1634 uint16_t language_id = (random() % 4) + 0x409;
1635 uint16_t returned_language_id = 0;
1636 struct lsa_StringLarge *disp_name = NULL;
1638 printf("\nTesting LookupPrivDisplayName(%s)\n", priv_name->string);
1640 r.in.handle = handle;
1641 r.in.name = priv_name;
1642 r.in.language_id = language_id;
1643 r.in.language_id_sys = 0;
1644 r.out.returned_language_id = &returned_language_id;
1645 r.out.disp_name = &disp_name;
1647 status = dcerpc_lsa_LookupPrivDisplayName(p, mem_ctx, &r);
1648 if (!NT_STATUS_IS_OK(status)) {
1649 printf("LookupPrivDisplayName failed - %s\n", nt_errstr(status));
1650 return false;
1652 printf("%s -> \"%s\" (language 0x%x/0x%x)\n",
1653 priv_name->string, disp_name->string,
1654 r.in.language_id, *r.out.returned_language_id);
1656 return true;
1659 static bool test_EnumAccountsWithUserRight(struct dcerpc_pipe *p,
1660 TALLOC_CTX *mem_ctx,
1661 struct policy_handle *handle,
1662 struct lsa_String *priv_name)
1664 struct lsa_EnumAccountsWithUserRight r;
1665 struct lsa_SidArray sids;
1666 NTSTATUS status;
1668 ZERO_STRUCT(sids);
1670 printf("\nTesting EnumAccountsWithUserRight(%s)\n", priv_name->string);
1672 r.in.handle = handle;
1673 r.in.name = priv_name;
1674 r.out.sids = &sids;
1676 status = dcerpc_lsa_EnumAccountsWithUserRight(p, mem_ctx, &r);
1678 /* NT_STATUS_NO_MORE_ENTRIES means noone has this privilege */
1679 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
1680 return true;
1683 if (!NT_STATUS_IS_OK(status)) {
1684 printf("EnumAccountsWithUserRight failed - %s\n", nt_errstr(status));
1685 return false;
1688 return true;
1692 static bool test_EnumPrivs(struct dcerpc_pipe *p,
1693 TALLOC_CTX *mem_ctx,
1694 struct policy_handle *handle)
1696 NTSTATUS status;
1697 struct lsa_EnumPrivs r;
1698 struct lsa_PrivArray privs1;
1699 uint32_t resume_handle = 0;
1700 int i;
1701 bool ret = true;
1703 printf("\nTesting EnumPrivs\n");
1705 r.in.handle = handle;
1706 r.in.resume_handle = &resume_handle;
1707 r.in.max_count = 100;
1708 r.out.resume_handle = &resume_handle;
1709 r.out.privs = &privs1;
1711 resume_handle = 0;
1712 status = dcerpc_lsa_EnumPrivs(p, mem_ctx, &r);
1713 if (!NT_STATUS_IS_OK(status)) {
1714 printf("EnumPrivs failed - %s\n", nt_errstr(status));
1715 return false;
1718 for (i = 0; i< privs1.count; i++) {
1719 test_LookupPrivDisplayName(p, mem_ctx, handle, (struct lsa_String *)&privs1.privs[i].name);
1720 test_LookupPrivValue(p, mem_ctx, handle, (struct lsa_String *)&privs1.privs[i].name);
1721 if (!test_EnumAccountsWithUserRight(p, mem_ctx, handle, (struct lsa_String *)&privs1.privs[i].name)) {
1722 ret = false;
1726 return ret;
1729 static bool test_QueryForestTrustInformation(struct dcerpc_pipe *p,
1730 struct torture_context *tctx,
1731 struct policy_handle *handle,
1732 const char *trusted_domain_name)
1734 bool ret = true;
1735 struct lsa_lsaRQueryForestTrustInformation r;
1736 NTSTATUS status;
1737 struct lsa_String string;
1738 struct lsa_ForestTrustInformation info, *info_ptr;
1740 printf("\nTesting lsaRQueryForestTrustInformation\n");
1742 if (torture_setting_bool(tctx, "samba4", false)) {
1743 printf("skipping QueryForestTrustInformation against Samba4\n");
1744 return true;
1747 ZERO_STRUCT(string);
1749 if (trusted_domain_name) {
1750 init_lsa_String(&string, trusted_domain_name);
1753 info_ptr = &info;
1755 r.in.handle = handle;
1756 r.in.trusted_domain_name = &string;
1757 r.in.unknown = 0;
1758 r.out.forest_trust_info = &info_ptr;
1760 status = dcerpc_lsa_lsaRQueryForestTrustInformation(p, tctx, &r);
1762 if (!NT_STATUS_IS_OK(status)) {
1763 printf("lsaRQueryForestTrustInformation of %s failed - %s\n", trusted_domain_name, nt_errstr(status));
1764 ret = false;
1767 return ret;
1770 static bool test_query_each_TrustDomEx(struct dcerpc_pipe *p,
1771 TALLOC_CTX *mem_ctx,
1772 struct policy_handle *handle,
1773 struct lsa_DomainListEx *domains)
1775 int i;
1776 bool ret = true;
1778 for (i=0; i< domains->count; i++) {
1780 if (domains->domains[i].trust_attributes & NETR_TRUST_ATTRIBUTE_FOREST_TRANSITIVE) {
1781 ret &= test_QueryForestTrustInformation(p, mem_ctx, handle,
1782 domains->domains[i].domain_name.string);
1786 return ret;
1789 static bool test_query_each_TrustDom(struct dcerpc_pipe *p,
1790 TALLOC_CTX *mem_ctx,
1791 struct policy_handle *handle,
1792 struct lsa_DomainList *domains)
1794 NTSTATUS status;
1795 int i,j;
1796 bool ret = true;
1798 printf("\nTesting OpenTrustedDomain, OpenTrustedDomainByName and QueryInfoTrustedDomain\n");
1799 for (i=0; i< domains->count; i++) {
1800 struct lsa_OpenTrustedDomain trust;
1801 struct lsa_OpenTrustedDomainByName trust_by_name;
1802 struct policy_handle trustdom_handle;
1803 struct policy_handle handle2;
1804 struct lsa_Close c;
1805 struct lsa_CloseTrustedDomainEx c_trust;
1806 int levels [] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
1807 int ok[] = {1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1};
1809 if (domains->domains[i].sid) {
1810 trust.in.handle = handle;
1811 trust.in.sid = domains->domains[i].sid;
1812 trust.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1813 trust.out.trustdom_handle = &trustdom_handle;
1815 status = dcerpc_lsa_OpenTrustedDomain(p, mem_ctx, &trust);
1817 if (!NT_STATUS_IS_OK(status)) {
1818 printf("OpenTrustedDomain failed - %s\n", nt_errstr(status));
1819 return false;
1822 c.in.handle = &trustdom_handle;
1823 c.out.handle = &handle2;
1825 c_trust.in.handle = &trustdom_handle;
1826 c_trust.out.handle = &handle2;
1828 for (j=0; j < ARRAY_SIZE(levels); j++) {
1829 struct lsa_QueryTrustedDomainInfo q;
1830 union lsa_TrustedDomainInfo *info = NULL;
1831 q.in.trustdom_handle = &trustdom_handle;
1832 q.in.level = levels[j];
1833 q.out.info = &info;
1834 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
1835 if (!NT_STATUS_IS_OK(status) && ok[j]) {
1836 printf("QueryTrustedDomainInfo level %d failed - %s\n",
1837 levels[j], nt_errstr(status));
1838 ret = false;
1839 } else if (NT_STATUS_IS_OK(status) && !ok[j]) {
1840 printf("QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
1841 levels[j], nt_errstr(status));
1842 ret = false;
1846 status = dcerpc_lsa_CloseTrustedDomainEx(p, mem_ctx, &c_trust);
1847 if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED)) {
1848 printf("Expected CloseTrustedDomainEx to return NT_STATUS_NOT_IMPLEMENTED, instead - %s\n", nt_errstr(status));
1849 return false;
1852 c.in.handle = &trustdom_handle;
1853 c.out.handle = &handle2;
1855 status = dcerpc_lsa_Close(p, mem_ctx, &c);
1856 if (!NT_STATUS_IS_OK(status)) {
1857 printf("Close of trusted domain failed - %s\n", nt_errstr(status));
1858 return false;
1861 for (j=0; j < ARRAY_SIZE(levels); j++) {
1862 struct lsa_QueryTrustedDomainInfoBySid q;
1863 union lsa_TrustedDomainInfo *info = NULL;
1865 if (!domains->domains[i].sid) {
1866 continue;
1869 q.in.handle = handle;
1870 q.in.dom_sid = domains->domains[i].sid;
1871 q.in.level = levels[j];
1872 q.out.info = &info;
1874 status = dcerpc_lsa_QueryTrustedDomainInfoBySid(p, mem_ctx, &q);
1875 if (!NT_STATUS_IS_OK(status) && ok[j]) {
1876 printf("QueryTrustedDomainInfoBySid level %d failed - %s\n",
1877 levels[j], nt_errstr(status));
1878 ret = false;
1879 } else if (NT_STATUS_IS_OK(status) && !ok[j]) {
1880 printf("QueryTrustedDomainInfoBySid level %d unexpectedly succeeded - %s\n",
1881 levels[j], nt_errstr(status));
1882 ret = false;
1887 trust_by_name.in.handle = handle;
1888 trust_by_name.in.name.string = domains->domains[i].name.string;
1889 trust_by_name.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1890 trust_by_name.out.trustdom_handle = &trustdom_handle;
1892 status = dcerpc_lsa_OpenTrustedDomainByName(p, mem_ctx, &trust_by_name);
1894 if (!NT_STATUS_IS_OK(status)) {
1895 printf("OpenTrustedDomainByName failed - %s\n", nt_errstr(status));
1896 return false;
1899 for (j=0; j < ARRAY_SIZE(levels); j++) {
1900 struct lsa_QueryTrustedDomainInfo q;
1901 union lsa_TrustedDomainInfo *info = NULL;
1902 q.in.trustdom_handle = &trustdom_handle;
1903 q.in.level = levels[j];
1904 q.out.info = &info;
1905 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
1906 if (!NT_STATUS_IS_OK(status) && ok[j]) {
1907 printf("QueryTrustedDomainInfo level %d failed - %s\n",
1908 levels[j], nt_errstr(status));
1909 ret = false;
1910 } else if (NT_STATUS_IS_OK(status) && !ok[j]) {
1911 printf("QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
1912 levels[j], nt_errstr(status));
1913 ret = false;
1917 c.in.handle = &trustdom_handle;
1918 c.out.handle = &handle2;
1920 status = dcerpc_lsa_Close(p, mem_ctx, &c);
1921 if (!NT_STATUS_IS_OK(status)) {
1922 printf("Close of trusted domain failed - %s\n", nt_errstr(status));
1923 return false;
1926 for (j=0; j < ARRAY_SIZE(levels); j++) {
1927 struct lsa_QueryTrustedDomainInfoByName q;
1928 union lsa_TrustedDomainInfo *info = NULL;
1929 struct lsa_String name;
1931 name.string = domains->domains[i].name.string;
1933 q.in.handle = handle;
1934 q.in.trusted_domain = &name;
1935 q.in.level = levels[j];
1936 q.out.info = &info;
1937 status = dcerpc_lsa_QueryTrustedDomainInfoByName(p, mem_ctx, &q);
1938 if (!NT_STATUS_IS_OK(status) && ok[j]) {
1939 printf("QueryTrustedDomainInfoByName level %d failed - %s\n",
1940 levels[j], nt_errstr(status));
1941 ret = false;
1942 } else if (NT_STATUS_IS_OK(status) && !ok[j]) {
1943 printf("QueryTrustedDomainInfoByName level %d unexpectedly succeeded - %s\n",
1944 levels[j], nt_errstr(status));
1945 ret = false;
1949 return ret;
1952 static bool test_EnumTrustDom(struct dcerpc_pipe *p,
1953 TALLOC_CTX *mem_ctx,
1954 struct policy_handle *handle)
1956 struct lsa_EnumTrustDom r;
1957 struct lsa_EnumTrustedDomainsEx r_ex;
1958 NTSTATUS enum_status;
1959 uint32_t resume_handle = 0;
1960 struct lsa_DomainList domains;
1961 struct lsa_DomainListEx domains_ex;
1962 bool ret = true;
1964 printf("\nTesting EnumTrustDom\n");
1966 r.in.handle = handle;
1967 r.in.resume_handle = &resume_handle;
1968 r.in.max_size = 0;
1969 r.out.domains = &domains;
1970 r.out.resume_handle = &resume_handle;
1972 enum_status = dcerpc_lsa_EnumTrustDom(p, mem_ctx, &r);
1974 if (NT_STATUS_IS_OK(enum_status)) {
1975 if (domains.count == 0) {
1976 printf("EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
1977 return false;
1979 } else if (!(NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES) || NT_STATUS_EQUAL(enum_status, NT_STATUS_NO_MORE_ENTRIES))) {
1980 printf("EnumTrustDom of zero size failed - %s\n", nt_errstr(enum_status));
1981 return false;
1984 /* Start from the bottom again */
1985 resume_handle = 0;
1987 do {
1988 r.in.handle = handle;
1989 r.in.resume_handle = &resume_handle;
1990 r.in.max_size = LSA_ENUM_TRUST_DOMAIN_MULTIPLIER * 3;
1991 r.out.domains = &domains;
1992 r.out.resume_handle = &resume_handle;
1994 enum_status = dcerpc_lsa_EnumTrustDom(p, mem_ctx, &r);
1996 /* NO_MORE_ENTRIES is allowed */
1997 if (NT_STATUS_EQUAL(enum_status, NT_STATUS_NO_MORE_ENTRIES)) {
1998 if (domains.count == 0) {
1999 return true;
2001 printf("EnumTrustDom failed - should have returned 0 trusted domains with 'NT_STATUS_NO_MORE_ENTRIES'\n");
2002 return false;
2003 } else if (NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES)) {
2004 /* Windows 2003 gets this off by one on the first run */
2005 if (r.out.domains->count < 3 || r.out.domains->count > 4) {
2006 printf("EnumTrustDom didn't fill the buffer we "
2007 "asked it to (got %d, expected %d / %d == %d entries)\n",
2008 r.out.domains->count, LSA_ENUM_TRUST_DOMAIN_MULTIPLIER * 3,
2009 LSA_ENUM_TRUST_DOMAIN_MULTIPLIER, r.in.max_size);
2010 ret = false;
2012 } else if (!NT_STATUS_IS_OK(enum_status)) {
2013 printf("EnumTrustDom failed - %s\n", nt_errstr(enum_status));
2014 return false;
2017 if (domains.count == 0) {
2018 printf("EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2019 return false;
2022 ret &= test_query_each_TrustDom(p, mem_ctx, handle, &domains);
2024 } while ((NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES)));
2026 printf("\nTesting EnumTrustedDomainsEx\n");
2028 r_ex.in.handle = handle;
2029 r_ex.in.resume_handle = &resume_handle;
2030 r_ex.in.max_size = LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER * 3;
2031 r_ex.out.domains = &domains_ex;
2032 r_ex.out.resume_handle = &resume_handle;
2034 enum_status = dcerpc_lsa_EnumTrustedDomainsEx(p, mem_ctx, &r_ex);
2036 if (!(NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES) || NT_STATUS_EQUAL(enum_status, NT_STATUS_NO_MORE_ENTRIES))) {
2037 printf("EnumTrustedDomainEx of zero size failed - %s\n", nt_errstr(enum_status));
2038 return false;
2041 resume_handle = 0;
2042 do {
2043 r_ex.in.handle = handle;
2044 r_ex.in.resume_handle = &resume_handle;
2045 r_ex.in.max_size = LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER * 3;
2046 r_ex.out.domains = &domains_ex;
2047 r_ex.out.resume_handle = &resume_handle;
2049 enum_status = dcerpc_lsa_EnumTrustedDomainsEx(p, mem_ctx, &r_ex);
2051 /* NO_MORE_ENTRIES is allowed */
2052 if (NT_STATUS_EQUAL(enum_status, NT_STATUS_NO_MORE_ENTRIES)) {
2053 if (domains_ex.count == 0) {
2054 return true;
2056 printf("EnumTrustDomainsEx failed - should have returned 0 trusted domains with 'NT_STATUS_NO_MORE_ENTRIES'\n");
2057 return false;
2058 } else if (NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES)) {
2059 /* Windows 2003 gets this off by one on the first run */
2060 if (r_ex.out.domains->count < 3 || r_ex.out.domains->count > 4) {
2061 printf("EnumTrustDom didn't fill the buffer we "
2062 "asked it to (got %d, expected %d / %d == %d entries)\n",
2063 r_ex.out.domains->count,
2064 r_ex.in.max_size,
2065 LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER,
2066 r_ex.in.max_size / LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER);
2068 } else if (!NT_STATUS_IS_OK(enum_status)) {
2069 printf("EnumTrustedDomainEx failed - %s\n", nt_errstr(enum_status));
2070 return false;
2073 if (domains_ex.count == 0) {
2074 printf("EnumTrustDomainEx failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2075 return false;
2078 ret &= test_query_each_TrustDomEx(p, mem_ctx, handle, &domains_ex);
2080 } while ((NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES)));
2082 return ret;
2085 static bool test_CreateTrustedDomain(struct dcerpc_pipe *p,
2086 TALLOC_CTX *mem_ctx,
2087 struct policy_handle *handle)
2089 NTSTATUS status;
2090 bool ret = true;
2091 struct lsa_CreateTrustedDomain r;
2092 struct lsa_DomainInfo trustinfo;
2093 struct dom_sid *domsid[12];
2094 struct policy_handle trustdom_handle[12];
2095 struct lsa_QueryTrustedDomainInfo q;
2096 union lsa_TrustedDomainInfo *info = NULL;
2097 int i;
2099 printf("\nTesting CreateTrustedDomain for 12 domains\n");
2101 if (!test_EnumTrustDom(p, mem_ctx, handle)) {
2102 ret = false;
2105 for (i=0; i< 12; i++) {
2106 char *trust_name = talloc_asprintf(mem_ctx, "torturedom%02d", i);
2107 char *trust_sid = talloc_asprintf(mem_ctx, "S-1-5-21-97398-379795-100%02d", i);
2109 domsid[i] = dom_sid_parse_talloc(mem_ctx, trust_sid);
2111 trustinfo.sid = domsid[i];
2112 init_lsa_String((struct lsa_String *)&trustinfo.name, trust_name);
2114 r.in.policy_handle = handle;
2115 r.in.info = &trustinfo;
2116 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2117 r.out.trustdom_handle = &trustdom_handle[i];
2119 status = dcerpc_lsa_CreateTrustedDomain(p, mem_ctx, &r);
2120 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
2121 test_DeleteTrustedDomain(p, mem_ctx, handle, trustinfo.name);
2122 status = dcerpc_lsa_CreateTrustedDomain(p, mem_ctx, &r);
2124 if (!NT_STATUS_IS_OK(status)) {
2125 printf("CreateTrustedDomain failed - %s\n", nt_errstr(status));
2126 ret = false;
2127 } else {
2129 q.in.trustdom_handle = &trustdom_handle[i];
2130 q.in.level = LSA_TRUSTED_DOMAIN_INFO_INFO_EX;
2131 q.out.info = &info;
2132 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
2133 if (!NT_STATUS_IS_OK(status)) {
2134 printf("QueryTrustedDomainInfo level 1 failed - %s\n", nt_errstr(status));
2135 ret = false;
2136 } else if (!q.out.info) {
2137 ret = false;
2138 } else {
2139 if (strcmp(info->info_ex.netbios_name.string, trustinfo.name.string) != 0) {
2140 printf("QueryTrustedDomainInfo returned inconsistant short name: %s != %s\n",
2141 info->info_ex.netbios_name.string, trustinfo.name.string);
2142 ret = false;
2144 if (info->info_ex.trust_type != LSA_TRUST_TYPE_DOWNLEVEL) {
2145 printf("QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
2146 trust_name, info->info_ex.trust_type, LSA_TRUST_TYPE_DOWNLEVEL);
2147 ret = false;
2149 if (info->info_ex.trust_attributes != 0) {
2150 printf("QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
2151 trust_name, info->info_ex.trust_attributes, 0);
2152 ret = false;
2154 if (info->info_ex.trust_direction != LSA_TRUST_DIRECTION_OUTBOUND) {
2155 printf("QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
2156 trust_name, info->info_ex.trust_direction, LSA_TRUST_DIRECTION_OUTBOUND);
2157 ret = false;
2163 /* now that we have some domains to look over, we can test the enum calls */
2164 if (!test_EnumTrustDom(p, mem_ctx, handle)) {
2165 ret = false;
2168 for (i=0; i<12; i++) {
2169 if (!test_DeleteTrustedDomainBySid(p, mem_ctx, handle, domsid[i])) {
2170 ret = false;
2174 return ret;
2177 static bool test_CreateTrustedDomainEx2(struct dcerpc_pipe *p,
2178 struct torture_context *tctx,
2179 TALLOC_CTX *mem_ctx,
2180 struct policy_handle *handle)
2182 NTSTATUS status;
2183 bool ret = true;
2184 struct lsa_CreateTrustedDomainEx2 r;
2185 struct lsa_TrustDomainInfoInfoEx trustinfo;
2186 struct lsa_TrustDomainInfoAuthInfoInternal authinfo;
2187 struct trustDomainPasswords auth_struct;
2188 DATA_BLOB auth_blob;
2189 struct dom_sid *domsid[12];
2190 struct policy_handle trustdom_handle[12];
2191 struct lsa_QueryTrustedDomainInfo q;
2192 union lsa_TrustedDomainInfo *info = NULL;
2193 DATA_BLOB session_key;
2194 enum ndr_err_code ndr_err;
2195 int i;
2197 printf("\nTesting CreateTrustedDomainEx2 for 12 domains\n");
2199 status = dcerpc_fetch_session_key(p, &session_key);
2200 if (!NT_STATUS_IS_OK(status)) {
2201 printf("dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
2202 return false;
2205 for (i=0; i< 12; i++) {
2206 char *trust_name = talloc_asprintf(mem_ctx, "torturedom%02d", i);
2207 char *trust_name_dns = talloc_asprintf(mem_ctx, "torturedom%02d.samba.example.com", i);
2208 char *trust_sid = talloc_asprintf(mem_ctx, "S-1-5-21-97398-379795-100%02d", i);
2210 domsid[i] = dom_sid_parse_talloc(mem_ctx, trust_sid);
2212 trustinfo.sid = domsid[i];
2213 trustinfo.netbios_name.string = trust_name;
2214 trustinfo.domain_name.string = trust_name_dns;
2216 /* Create inbound, some outbound, and some
2217 * bi-directional trusts in a repeating pattern based
2218 * on i */
2220 /* 1 == inbound, 2 == outbound, 3 == both */
2221 trustinfo.trust_direction = (i % 3) + 1;
2223 /* Try different trust types too */
2225 /* 1 == downlevel (NT4), 2 == uplevel (ADS), 3 == MIT (kerberos but not AD) */
2226 trustinfo.trust_type = (((i / 3) + 1) % 3) + 1;
2228 trustinfo.trust_attributes = LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION;
2230 generate_random_buffer(auth_struct.confounder, sizeof(auth_struct.confounder));
2232 auth_struct.outgoing.count = 0;
2233 auth_struct.incoming.count = 0;
2235 ndr_err = ndr_push_struct_blob(&auth_blob, mem_ctx, lp_iconv_convenience(tctx->lp_ctx), &auth_struct,
2236 (ndr_push_flags_fn_t)ndr_push_trustDomainPasswords);
2237 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2238 printf("ndr_push_struct_blob of trustDomainPasswords structure failed");
2239 ret = false;
2242 arcfour_crypt_blob(auth_blob.data, auth_blob.length, &session_key);
2244 authinfo.auth_blob.size = auth_blob.length;
2245 authinfo.auth_blob.data = auth_blob.data;
2247 r.in.policy_handle = handle;
2248 r.in.info = &trustinfo;
2249 r.in.auth_info = &authinfo;
2250 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2251 r.out.trustdom_handle = &trustdom_handle[i];
2253 status = dcerpc_lsa_CreateTrustedDomainEx2(p, mem_ctx, &r);
2254 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
2255 test_DeleteTrustedDomain(p, mem_ctx, handle, trustinfo.netbios_name);
2256 status = dcerpc_lsa_CreateTrustedDomainEx2(p, mem_ctx, &r);
2258 if (!NT_STATUS_IS_OK(status)) {
2259 printf("CreateTrustedDomainEx failed2 - %s\n", nt_errstr(status));
2260 ret = false;
2261 } else {
2263 q.in.trustdom_handle = &trustdom_handle[i];
2264 q.in.level = LSA_TRUSTED_DOMAIN_INFO_INFO_EX;
2265 q.out.info = &info;
2266 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
2267 if (!NT_STATUS_IS_OK(status)) {
2268 printf("QueryTrustedDomainInfo level 1 failed - %s\n", nt_errstr(status));
2269 ret = false;
2270 } else if (!q.out.info) {
2271 printf("QueryTrustedDomainInfo level 1 failed to return an info pointer\n");
2272 ret = false;
2273 } else {
2274 if (strcmp(info->info_ex.netbios_name.string, trustinfo.netbios_name.string) != 0) {
2275 printf("QueryTrustedDomainInfo returned inconsistant short name: %s != %s\n",
2276 info->info_ex.netbios_name.string, trustinfo.netbios_name.string);
2277 ret = false;
2279 if (info->info_ex.trust_type != trustinfo.trust_type) {
2280 printf("QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
2281 trust_name, info->info_ex.trust_type, trustinfo.trust_type);
2282 ret = false;
2284 if (info->info_ex.trust_attributes != LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION) {
2285 printf("QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
2286 trust_name, info->info_ex.trust_attributes, LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION);
2287 ret = false;
2289 if (info->info_ex.trust_direction != trustinfo.trust_direction) {
2290 printf("QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
2291 trust_name, info->info_ex.trust_direction, trustinfo.trust_direction);
2292 ret = false;
2298 /* now that we have some domains to look over, we can test the enum calls */
2299 if (!test_EnumTrustDom(p, mem_ctx, handle)) {
2300 printf("test_EnumTrustDom failed\n");
2301 ret = false;
2304 for (i=0; i<12; i++) {
2305 if (!test_DeleteTrustedDomainBySid(p, mem_ctx, handle, domsid[i])) {
2306 printf("test_DeleteTrustedDomainBySid failed\n");
2307 ret = false;
2311 return ret;
2314 static bool test_QueryDomainInfoPolicy(struct dcerpc_pipe *p,
2315 struct torture_context *tctx,
2316 struct policy_handle *handle)
2318 struct lsa_QueryDomainInformationPolicy r;
2319 union lsa_DomainInformationPolicy *info = NULL;
2320 NTSTATUS status;
2321 int i;
2322 bool ret = true;
2324 printf("\nTesting QueryDomainInformationPolicy\n");
2326 for (i=2;i<4;i++) {
2327 r.in.handle = handle;
2328 r.in.level = i;
2329 r.out.info = &info;
2331 printf("\nTrying QueryDomainInformationPolicy level %d\n", i);
2333 status = dcerpc_lsa_QueryDomainInformationPolicy(p, tctx, &r);
2335 /* If the server does not support EFS, then this is the correct return */
2336 if (i == LSA_DOMAIN_INFO_POLICY_EFS && NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
2337 continue;
2338 } else if (!NT_STATUS_IS_OK(status)) {
2339 printf("QueryDomainInformationPolicy failed - %s\n", nt_errstr(status));
2340 ret = false;
2341 continue;
2345 return ret;
2349 static bool test_QueryInfoPolicyCalls( bool version2,
2350 struct dcerpc_pipe *p,
2351 struct torture_context *tctx,
2352 struct policy_handle *handle)
2354 struct lsa_QueryInfoPolicy r;
2355 union lsa_PolicyInformation *info = NULL;
2356 NTSTATUS status;
2357 int i;
2358 bool ret = true;
2360 if (version2)
2361 printf("\nTesting QueryInfoPolicy2\n");
2362 else
2363 printf("\nTesting QueryInfoPolicy\n");
2365 for (i=1;i<=14;i++) {
2366 r.in.handle = handle;
2367 r.in.level = i;
2368 r.out.info = &info;
2370 if (version2)
2371 printf("\nTrying QueryInfoPolicy2 level %d\n", i);
2372 else
2373 printf("\nTrying QueryInfoPolicy level %d\n", i);
2375 if (version2)
2376 /* We can perform the cast, because both types are
2377 structurally equal */
2378 status = dcerpc_lsa_QueryInfoPolicy2(p, tctx,
2379 (struct lsa_QueryInfoPolicy2*) &r);
2380 else
2381 status = dcerpc_lsa_QueryInfoPolicy(p, tctx, &r);
2383 switch (i) {
2384 case LSA_POLICY_INFO_MOD:
2385 case LSA_POLICY_INFO_AUDIT_FULL_SET:
2386 case LSA_POLICY_INFO_AUDIT_FULL_QUERY:
2387 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
2388 printf("Server should have failed level %u: %s\n", i, nt_errstr(status));
2389 ret = false;
2391 break;
2392 case LSA_POLICY_INFO_DOMAIN:
2393 case LSA_POLICY_INFO_ACCOUNT_DOMAIN:
2394 case LSA_POLICY_INFO_L_ACCOUNT_DOMAIN:
2395 case LSA_POLICY_INFO_DNS_INT:
2396 case LSA_POLICY_INFO_DNS:
2397 case LSA_POLICY_INFO_REPLICA:
2398 case LSA_POLICY_INFO_QUOTA:
2399 case LSA_POLICY_INFO_ROLE:
2400 case LSA_POLICY_INFO_AUDIT_LOG:
2401 case LSA_POLICY_INFO_AUDIT_EVENTS:
2402 case LSA_POLICY_INFO_PD:
2403 if (!NT_STATUS_IS_OK(status)) {
2404 if (version2)
2405 printf("QueryInfoPolicy2 failed - %s\n", nt_errstr(status));
2406 else
2407 printf("QueryInfoPolicy failed - %s\n", nt_errstr(status));
2408 ret = false;
2410 break;
2411 default:
2412 if (torture_setting_bool(tctx, "samba4", false)) {
2413 /* Other levels not implemented yet */
2414 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_INFO_CLASS)) {
2415 if (version2)
2416 printf("QueryInfoPolicy2 failed - %s\n", nt_errstr(status));
2417 else
2418 printf("QueryInfoPolicy failed - %s\n", nt_errstr(status));
2419 ret = false;
2421 } else if (!NT_STATUS_IS_OK(status)) {
2422 if (version2)
2423 printf("QueryInfoPolicy2 failed - %s\n", nt_errstr(status));
2424 else
2425 printf("QueryInfoPolicy failed - %s\n", nt_errstr(status));
2426 ret = false;
2428 break;
2431 if (NT_STATUS_IS_OK(status) && (i == LSA_POLICY_INFO_DNS
2432 || i == LSA_POLICY_INFO_DNS_INT)) {
2433 /* Let's look up some of these names */
2435 struct lsa_TransNameArray tnames;
2436 tnames.count = 14;
2437 tnames.names = talloc_zero_array(tctx, struct lsa_TranslatedName, tnames.count);
2438 tnames.names[0].name.string = info->dns.name.string;
2439 tnames.names[0].sid_type = SID_NAME_DOMAIN;
2440 tnames.names[1].name.string = info->dns.dns_domain.string;
2441 tnames.names[1].sid_type = SID_NAME_DOMAIN;
2442 tnames.names[2].name.string = talloc_asprintf(tctx, "%s\\", info->dns.name.string);
2443 tnames.names[2].sid_type = SID_NAME_DOMAIN;
2444 tnames.names[3].name.string = talloc_asprintf(tctx, "%s\\", info->dns.dns_domain.string);
2445 tnames.names[3].sid_type = SID_NAME_DOMAIN;
2446 tnames.names[4].name.string = talloc_asprintf(tctx, "%s\\guest", info->dns.name.string);
2447 tnames.names[4].sid_type = SID_NAME_USER;
2448 tnames.names[5].name.string = talloc_asprintf(tctx, "%s\\krbtgt", info->dns.name.string);
2449 tnames.names[5].sid_type = SID_NAME_USER;
2450 tnames.names[6].name.string = talloc_asprintf(tctx, "%s\\guest", info->dns.dns_domain.string);
2451 tnames.names[6].sid_type = SID_NAME_USER;
2452 tnames.names[7].name.string = talloc_asprintf(tctx, "%s\\krbtgt", info->dns.dns_domain.string);
2453 tnames.names[7].sid_type = SID_NAME_USER;
2454 tnames.names[8].name.string = talloc_asprintf(tctx, "krbtgt@%s", info->dns.name.string);
2455 tnames.names[8].sid_type = SID_NAME_USER;
2456 tnames.names[9].name.string = talloc_asprintf(tctx, "krbtgt@%s", info->dns.dns_domain.string);
2457 tnames.names[9].sid_type = SID_NAME_USER;
2458 tnames.names[10].name.string = talloc_asprintf(tctx, "%s\\"TEST_MACHINENAME "$", info->dns.name.string);
2459 tnames.names[10].sid_type = SID_NAME_USER;
2460 tnames.names[11].name.string = talloc_asprintf(tctx, "%s\\"TEST_MACHINENAME "$", info->dns.dns_domain.string);
2461 tnames.names[11].sid_type = SID_NAME_USER;
2462 tnames.names[12].name.string = talloc_asprintf(tctx, TEST_MACHINENAME "$@%s", info->dns.name.string);
2463 tnames.names[12].sid_type = SID_NAME_USER;
2464 tnames.names[13].name.string = talloc_asprintf(tctx, TEST_MACHINENAME "$@%s", info->dns.dns_domain.string);
2465 tnames.names[13].sid_type = SID_NAME_USER;
2466 ret &= test_LookupNames(p, tctx, handle, &tnames);
2471 return ret;
2474 static bool test_QueryInfoPolicy(struct dcerpc_pipe *p,
2475 struct torture_context *tctx,
2476 struct policy_handle *handle)
2478 return test_QueryInfoPolicyCalls(false, p, tctx, handle);
2481 static bool test_QueryInfoPolicy2(struct dcerpc_pipe *p,
2482 struct torture_context *tctx,
2483 struct policy_handle *handle)
2485 return test_QueryInfoPolicyCalls(true, p, tctx, handle);
2488 static bool test_GetUserName(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
2490 struct lsa_GetUserName r;
2491 NTSTATUS status;
2492 bool ret = true;
2493 struct lsa_String *authority_name_p = NULL;
2494 struct lsa_String *account_name_p = NULL;
2496 printf("\nTesting GetUserName\n");
2498 r.in.system_name = "\\";
2499 r.in.account_name = &account_name_p;
2500 r.in.authority_name = NULL;
2501 r.out.account_name = &account_name_p;
2503 status = dcerpc_lsa_GetUserName(p, mem_ctx, &r);
2505 if (!NT_STATUS_IS_OK(status)) {
2506 printf("GetUserName failed - %s\n", nt_errstr(status));
2507 ret = false;
2510 account_name_p = NULL;
2511 r.in.account_name = &account_name_p;
2512 r.in.authority_name = &authority_name_p;
2513 r.out.account_name = &account_name_p;
2515 status = dcerpc_lsa_GetUserName(p, mem_ctx, &r);
2517 if (!NT_STATUS_IS_OK(status)) {
2518 printf("GetUserName failed - %s\n", nt_errstr(status));
2519 ret = false;
2522 return ret;
2525 bool test_lsa_Close(struct dcerpc_pipe *p,
2526 TALLOC_CTX *mem_ctx,
2527 struct policy_handle *handle)
2529 NTSTATUS status;
2530 struct lsa_Close r;
2531 struct policy_handle handle2;
2533 printf("\nTesting Close\n");
2535 r.in.handle = handle;
2536 r.out.handle = &handle2;
2538 status = dcerpc_lsa_Close(p, mem_ctx, &r);
2539 if (!NT_STATUS_IS_OK(status)) {
2540 printf("Close failed - %s\n", nt_errstr(status));
2541 return false;
2544 status = dcerpc_lsa_Close(p, mem_ctx, &r);
2545 /* its really a fault - we need a status code for rpc fault */
2546 if (!NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
2547 printf("Close failed - %s\n", nt_errstr(status));
2548 return false;
2551 printf("\n");
2553 return true;
2556 bool torture_rpc_lsa(struct torture_context *tctx)
2558 NTSTATUS status;
2559 struct dcerpc_pipe *p;
2560 bool ret = true;
2561 struct policy_handle *handle;
2562 struct test_join *join = NULL;
2563 struct cli_credentials *machine_creds;
2565 status = torture_rpc_connection(tctx, &p, &ndr_table_lsarpc);
2566 if (!NT_STATUS_IS_OK(status)) {
2567 return false;
2570 if (!test_OpenPolicy(p, tctx)) {
2571 ret = false;
2574 if (!test_lsa_OpenPolicy2(p, tctx, &handle)) {
2575 ret = false;
2578 if (handle) {
2579 join = torture_join_domain(tctx, TEST_MACHINENAME, ACB_WSTRUST, &machine_creds);
2580 if (!join) {
2581 ret = false;
2583 if (!test_LookupNames_wellknown(p, tctx, handle)) {
2584 ret = false;
2587 if (!test_LookupNames_bogus(p, tctx, handle)) {
2588 ret = false;
2591 if (!test_LookupSids_async(p, tctx, handle)) {
2592 ret = false;
2595 if (!test_QueryDomainInfoPolicy(p, tctx, handle)) {
2596 ret = false;
2599 if (!test_CreateAccount(p, tctx, handle)) {
2600 ret = false;
2603 if (!test_CreateSecret(p, tctx, handle)) {
2604 ret = false;
2606 if (!test_CreateTrustedDomain(p, tctx, handle)) {
2607 ret = false;
2610 if (!test_CreateTrustedDomainEx2(p, tctx, tctx, handle)) {
2611 ret = false;
2614 if (!test_EnumAccounts(p, tctx, handle)) {
2615 ret = false;
2618 if (!test_EnumPrivs(p, tctx, handle)) {
2619 ret = false;
2622 if (!test_QueryInfoPolicy(p, tctx, handle)) {
2623 ret = false;
2626 if (!test_QueryInfoPolicy2(p, tctx, handle)) {
2627 ret = false;
2630 if (!test_Delete(p, tctx, handle)) {
2631 ret = false;
2634 if (!test_many_LookupSids(p, tctx, handle)) {
2635 ret = false;
2638 if (!test_lsa_Close(p, tctx, handle)) {
2639 ret = false;
2642 torture_leave_domain(tctx, join);
2644 } else {
2645 if (!test_many_LookupSids(p, tctx, handle)) {
2646 ret = false;
2650 if (!test_GetUserName(p, tctx)) {
2651 ret = false;
2654 return ret;
2657 bool torture_rpc_lsa_get_user(struct torture_context *torture)
2659 NTSTATUS status;
2660 struct dcerpc_pipe *p;
2661 TALLOC_CTX *mem_ctx;
2662 bool ret = true;
2664 mem_ctx = talloc_init("torture_rpc_lsa_get_user");
2666 status = torture_rpc_connection(torture, &p, &ndr_table_lsarpc);
2667 if (!NT_STATUS_IS_OK(status)) {
2668 talloc_free(mem_ctx);
2669 return false;
2672 if (!test_GetUserName(p, mem_ctx)) {
2673 ret = false;
2676 talloc_free(mem_ctx);
2678 return ret;