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/>.
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 "librpc/gen_ndr/ndr_netlogon_c.h"
28 #include "lib/events/events.h"
29 #include "libcli/security/security.h"
30 #include "libcli/auth/libcli_auth.h"
31 #include "torture/rpc/torture_rpc.h"
32 #include "param/param.h"
33 #include "../lib/crypto/crypto.h"
34 #define TEST_MACHINENAME "lsatestmach"
35 #define TRUSTPW "12345678"
37 static void init_lsa_String(struct lsa_String *name, const char *s)
42 static bool test_OpenPolicy(struct dcerpc_binding_handle *b,
43 struct torture_context *tctx)
45 struct lsa_ObjectAttribute attr;
46 struct policy_handle handle;
47 struct lsa_QosInfo qos;
48 struct lsa_OpenPolicy r;
49 uint16_t system_name = '\\';
51 torture_comment(tctx, "\nTesting OpenPolicy\n");
54 qos.impersonation_level = 2;
56 qos.effective_only = 0;
60 attr.object_name = NULL;
65 r.in.system_name = &system_name;
67 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
68 r.out.handle = &handle;
70 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenPolicy_r(b, tctx, &r),
73 torture_assert_ntstatus_ok(tctx,
80 static bool test_OpenPolicy_fail(struct dcerpc_binding_handle *b,
81 struct torture_context *tctx)
83 struct lsa_ObjectAttribute attr;
84 struct policy_handle handle;
85 struct lsa_QosInfo qos;
86 struct lsa_OpenPolicy r;
87 uint16_t system_name = '\\';
90 torture_comment(tctx, "\nTesting OpenPolicy_fail\n");
93 qos.impersonation_level = 2;
95 qos.effective_only = 0;
99 attr.object_name = NULL;
101 attr.sec_desc = NULL;
104 r.in.system_name = &system_name;
106 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
107 r.out.handle = &handle;
109 status = dcerpc_lsa_OpenPolicy_r(b, tctx, &r);
110 if (!NT_STATUS_IS_OK(status)) {
111 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
112 torture_comment(tctx,
113 "OpenPolicy correctly returned with "
119 torture_assert_ntstatus_equal(tctx,
121 NT_STATUS_ACCESS_DENIED,
122 "OpenPolicy return value should "
127 if (!NT_STATUS_IS_OK(r.out.result)) {
128 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_ACCESS_DENIED) ||
129 NT_STATUS_EQUAL(r.out.result, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
130 torture_comment(tctx,
131 "OpenPolicy correctly returned with "
133 nt_errstr(r.out.result));
138 torture_assert_ntstatus_equal(tctx,
141 "OpenPolicy return value should be "
148 bool test_lsa_OpenPolicy2_ex(struct dcerpc_binding_handle *b,
149 struct torture_context *tctx,
150 struct policy_handle **handle,
151 NTSTATUS expected_status)
153 struct lsa_ObjectAttribute attr;
154 struct lsa_QosInfo qos;
155 struct lsa_OpenPolicy2 r;
158 torture_comment(tctx, "\nTesting OpenPolicy2\n");
160 *handle = talloc(tctx, struct policy_handle);
166 qos.impersonation_level = 2;
167 qos.context_mode = 1;
168 qos.effective_only = 0;
171 attr.root_dir = NULL;
172 attr.object_name = NULL;
174 attr.sec_desc = NULL;
177 r.in.system_name = "\\";
179 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
180 r.out.handle = *handle;
182 status = dcerpc_lsa_OpenPolicy2_r(b, tctx, &r);
183 torture_assert_ntstatus_equal(tctx, status, expected_status,
184 "OpenPolicy2 failed");
185 if (!NT_STATUS_IS_OK(expected_status)) {
189 torture_assert_ntstatus_ok(tctx,
191 "OpenPolicy2 failed");
197 bool test_lsa_OpenPolicy2(struct dcerpc_binding_handle *b,
198 struct torture_context *tctx,
199 struct policy_handle **handle)
201 return test_lsa_OpenPolicy2_ex(b, tctx, handle, NT_STATUS_OK);
204 static bool test_OpenPolicy2_fail(struct dcerpc_binding_handle *b,
205 struct torture_context *tctx)
207 struct lsa_ObjectAttribute attr;
208 struct policy_handle handle;
209 struct lsa_QosInfo qos;
210 struct lsa_OpenPolicy2 r;
213 torture_comment(tctx, "\nTesting OpenPolicy2_fail\n");
216 qos.impersonation_level = 2;
217 qos.context_mode = 1;
218 qos.effective_only = 0;
221 attr.root_dir = NULL;
222 attr.object_name = NULL;
224 attr.sec_desc = NULL;
227 r.in.system_name = "\\";
229 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
230 r.out.handle = &handle;
232 status = dcerpc_lsa_OpenPolicy2_r(b, tctx, &r);
233 if (!NT_STATUS_IS_OK(status)) {
234 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
235 torture_comment(tctx,
236 "OpenPolicy2 correctly returned with "
242 torture_assert_ntstatus_equal(tctx,
244 NT_STATUS_ACCESS_DENIED,
245 "OpenPolicy2 return value should "
250 if (!NT_STATUS_IS_OK(r.out.result)) {
251 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_ACCESS_DENIED) ||
252 NT_STATUS_EQUAL(r.out.result, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
253 torture_comment(tctx,
254 "OpenPolicy2 correctly returned with "
256 nt_errstr(r.out.result));
261 torture_assert_ntstatus_equal(tctx,
264 "OpenPolicy2 return value should be "
270 static bool test_LookupNames(struct dcerpc_binding_handle *b,
271 struct torture_context *tctx,
272 struct policy_handle *handle,
273 struct lsa_TransNameArray *tnames)
275 struct lsa_LookupNames r;
276 struct lsa_TransSidArray sids;
277 struct lsa_RefDomainList *domains = NULL;
278 struct lsa_String *names;
283 torture_comment(tctx, "\nTesting LookupNames with %d names\n", tnames->count);
291 input_idx = talloc_array(tctx, uint32_t, tnames->count);
292 names = talloc_array(tctx, struct lsa_String, tnames->count);
294 for (i=0;i<tnames->count;i++) {
295 if (tnames->names[i].sid_type != SID_NAME_UNKNOWN) {
296 init_lsa_String(&names[r.in.num_names], tnames->names[i].name.string);
297 input_idx[r.in.num_names] = i;
302 r.in.handle = handle;
307 r.out.count = &count;
309 r.out.domains = &domains;
311 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupNames_r(b, tctx, &r),
312 "LookupNames failed");
313 if (NT_STATUS_EQUAL(r.out.result, STATUS_SOME_UNMAPPED) ||
314 NT_STATUS_EQUAL(r.out.result, NT_STATUS_NONE_MAPPED)) {
315 for (i=0;i< r.in.num_names;i++) {
316 if (i < count && sids.sids[i].sid_type == SID_NAME_UNKNOWN) {
317 torture_comment(tctx, "LookupName of %s was unmapped\n",
318 tnames->names[i].name.string);
319 } else if (i >=count) {
320 torture_comment(tctx, "LookupName of %s failed to return a result\n",
321 tnames->names[i].name.string);
324 torture_comment(tctx, "LookupNames failed - %s\n",
325 nt_errstr(r.out.result));
327 } else if (!NT_STATUS_IS_OK(r.out.result)) {
328 torture_comment(tctx, "LookupNames failed - %s\n",
329 nt_errstr(r.out.result));
333 for (i=0;i< r.in.num_names;i++) {
335 if (sids.sids[i].sid_type != tnames->names[input_idx[i]].sid_type) {
336 torture_comment(tctx, "LookupName of %s got unexpected name type: %s\n",
337 tnames->names[input_idx[i]].name.string,
338 sid_type_lookup(sids.sids[i].sid_type));
341 if ((sids.sids[i].sid_type == SID_NAME_DOMAIN) &&
342 (sids.sids[i].rid != (uint32_t)-1)) {
343 torture_comment(tctx, "LookupName of %s got unexpected rid: %d\n",
344 tnames->names[input_idx[i]].name.string, sids.sids[i].rid);
347 } else if (i >=count) {
348 torture_comment(tctx, "LookupName of %s failed to return a result\n",
349 tnames->names[input_idx[i]].name.string);
353 torture_comment(tctx, "\n");
358 static bool test_LookupNames_bogus(struct dcerpc_binding_handle *b,
359 struct torture_context *tctx,
360 struct policy_handle *handle)
362 struct lsa_LookupNames r;
363 struct lsa_TransSidArray sids;
364 struct lsa_RefDomainList *domains = NULL;
365 struct lsa_String names[1];
368 torture_comment(tctx, "\nTesting LookupNames with bogus name\n");
373 init_lsa_String(&names[0], "NT AUTHORITY\\BOGUS");
375 r.in.handle = handle;
381 r.out.count = &count;
383 r.out.domains = &domains;
385 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupNames_r(b, tctx, &r),
386 "LookupNames bogus failed");
387 if (!NT_STATUS_EQUAL(r.out.result, NT_STATUS_NONE_MAPPED)) {
388 torture_comment(tctx, "LookupNames failed - %s\n",
389 nt_errstr(r.out.result));
393 torture_comment(tctx, "\n");
398 static bool test_LookupNames_NULL(struct dcerpc_binding_handle *b,
399 struct torture_context *tctx,
400 struct policy_handle *handle)
402 struct lsa_LookupNames r;
403 struct lsa_TransSidArray sids;
404 struct lsa_RefDomainList *domains = NULL;
405 struct lsa_String names[1];
408 torture_comment(tctx, "\nTesting LookupNames with NULL name\n");
413 names[0].string = NULL;
415 r.in.handle = handle;
421 r.out.count = &count;
423 r.out.domains = &domains;
425 /* nt4 returns NT_STATUS_NONE_MAPPED with sid_type
426 * SID_NAME_UNKNOWN, rid 0, and sid_index -1;
428 * w2k3/w2k8 return NT_STATUS_OK with sid_type
429 * SID_NAME_DOMAIN, rid -1 and sid_index 0 and BUILTIN domain
432 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupNames_r(b, tctx, &r),
433 "LookupNames with NULL name failed");
434 torture_assert_ntstatus_ok(tctx, r.out.result,
435 "LookupNames with NULL name failed");
437 torture_comment(tctx, "\n");
442 static bool test_LookupNames_wellknown(struct dcerpc_binding_handle *b,
443 struct torture_context *tctx,
444 struct policy_handle *handle)
446 struct lsa_TranslatedName name;
447 struct lsa_TransNameArray tnames;
450 torture_comment(tctx, "Testing LookupNames with well known names\n");
452 tnames.names = &name;
454 name.name.string = "NT AUTHORITY\\SYSTEM";
455 name.sid_type = SID_NAME_WKN_GRP;
456 ret &= test_LookupNames(b, tctx, handle, &tnames);
458 name.name.string = "NT AUTHORITY\\ANONYMOUS LOGON";
459 name.sid_type = SID_NAME_WKN_GRP;
460 ret &= test_LookupNames(b, tctx, handle, &tnames);
462 name.name.string = "NT AUTHORITY\\Authenticated Users";
463 name.sid_type = SID_NAME_WKN_GRP;
464 ret &= test_LookupNames(b, tctx, handle, &tnames);
467 name.name.string = "NT AUTHORITY";
468 ret &= test_LookupNames(b, tctx, handle, &tnames);
470 name.name.string = "NT AUTHORITY\\";
471 ret &= test_LookupNames(b, tctx, handle, &tnames);
474 name.name.string = "BUILTIN\\";
475 name.sid_type = SID_NAME_DOMAIN;
476 ret &= test_LookupNames(b, tctx, handle, &tnames);
478 name.name.string = "BUILTIN\\Administrators";
479 name.sid_type = SID_NAME_ALIAS;
480 ret &= test_LookupNames(b, tctx, handle, &tnames);
482 name.name.string = "SYSTEM";
483 name.sid_type = SID_NAME_WKN_GRP;
484 ret &= test_LookupNames(b, tctx, handle, &tnames);
486 name.name.string = "Everyone";
487 name.sid_type = SID_NAME_WKN_GRP;
488 ret &= test_LookupNames(b, tctx, handle, &tnames);
492 static bool test_LookupNames2(struct dcerpc_binding_handle *b,
493 struct torture_context *tctx,
494 struct policy_handle *handle,
495 struct lsa_TransNameArray2 *tnames,
498 struct lsa_LookupNames2 r;
499 struct lsa_TransSidArray2 sids;
500 struct lsa_RefDomainList *domains = NULL;
501 struct lsa_String *names;
506 torture_comment(tctx, "\nTesting LookupNames2 with %d names\n", tnames->count);
513 input_idx = talloc_array(tctx, uint32_t, tnames->count);
514 names = talloc_array(tctx, struct lsa_String, tnames->count);
516 for (i=0;i<tnames->count;i++) {
517 if (tnames->names[i].sid_type != SID_NAME_UNKNOWN) {
518 init_lsa_String(&names[r.in.num_names], tnames->names[i].name.string);
519 input_idx[r.in.num_names] = i;
524 r.in.handle = handle;
529 r.in.lookup_options = 0;
530 r.in.client_revision = 0;
531 r.out.count = &count;
533 r.out.domains = &domains;
535 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupNames2_r(b, tctx, &r),
536 "LookupNames2 failed");
537 if (!NT_STATUS_IS_OK(r.out.result)) {
538 torture_comment(tctx, "LookupNames2 failed - %s\n",
539 nt_errstr(r.out.result));
544 torture_assert_int_equal(tctx, count, sids.count,
545 "unexpected number of results returned");
546 if (sids.count > 0) {
547 torture_assert(tctx, sids.sids, "invalid sid buffer");
551 torture_comment(tctx, "\n");
557 static bool test_LookupNames3(struct dcerpc_binding_handle *b,
558 struct torture_context *tctx,
559 struct policy_handle *handle,
560 struct lsa_TransNameArray2 *tnames,
563 struct lsa_LookupNames3 r;
564 struct lsa_TransSidArray3 sids;
565 struct lsa_RefDomainList *domains = NULL;
566 struct lsa_String *names;
571 torture_comment(tctx, "\nTesting LookupNames3 with %d names\n", tnames->count);
578 input_idx = talloc_array(tctx, uint32_t, tnames->count);
579 names = talloc_array(tctx, struct lsa_String, tnames->count);
580 for (i=0;i<tnames->count;i++) {
581 if (tnames->names[i].sid_type != SID_NAME_UNKNOWN) {
582 init_lsa_String(&names[r.in.num_names], tnames->names[i].name.string);
583 input_idx[r.in.num_names] = i;
588 r.in.handle = handle;
593 r.in.lookup_options = 0;
594 r.in.client_revision = 0;
595 r.out.count = &count;
597 r.out.domains = &domains;
599 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupNames3_r(b, tctx, &r),
600 "LookupNames3 failed");
601 if (!NT_STATUS_IS_OK(r.out.result)) {
602 torture_comment(tctx, "LookupNames3 failed - %s\n",
603 nt_errstr(r.out.result));
608 torture_assert_int_equal(tctx, count, sids.count,
609 "unexpected number of results returned");
610 if (sids.count > 0) {
611 torture_assert(tctx, sids.sids, "invalid sid buffer");
615 torture_comment(tctx, "\n");
620 static bool test_LookupNames4(struct dcerpc_binding_handle *b,
621 struct torture_context *tctx,
622 struct lsa_TransNameArray2 *tnames,
625 struct lsa_LookupNames4 r;
626 struct lsa_TransSidArray3 sids;
627 struct lsa_RefDomainList *domains = NULL;
628 struct lsa_String *names;
633 torture_comment(tctx, "\nTesting LookupNames4 with %d names\n", tnames->count);
640 input_idx = talloc_array(tctx, uint32_t, tnames->count);
641 names = talloc_array(tctx, struct lsa_String, tnames->count);
642 for (i=0;i<tnames->count;i++) {
643 if (tnames->names[i].sid_type != SID_NAME_UNKNOWN) {
644 init_lsa_String(&names[r.in.num_names], tnames->names[i].name.string);
645 input_idx[r.in.num_names] = i;
650 r.in.num_names = tnames->count;
655 r.in.lookup_options = 0;
656 r.in.client_revision = 0;
657 r.out.count = &count;
659 r.out.domains = &domains;
661 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupNames4_r(b, tctx, &r),
662 "LookupNames4 failed");
664 if (!NT_STATUS_IS_OK(r.out.result)) {
665 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_NONE_MAPPED)) {
666 torture_comment(tctx,
667 "LookupNames4 failed: %s - not considered as an error",
668 nt_errstr(r.out.result));
673 torture_assert_ntstatus_ok(tctx,
675 "LookupNames4 failed");
681 torture_assert_int_equal(tctx, count, sids.count,
682 "unexpected number of results returned");
683 if (sids.count > 0) {
684 torture_assert(tctx, sids.sids, "invalid sid buffer");
688 torture_comment(tctx, "\n");
693 static bool test_LookupNames4_fail(struct dcerpc_binding_handle *b,
694 struct torture_context *tctx)
696 struct lsa_LookupNames4 r;
697 struct lsa_TransSidArray3 sids;
698 struct lsa_RefDomainList *domains = NULL;
699 struct lsa_String *names = NULL;
703 torture_comment(tctx, "\nTesting LookupNames4_fail");
710 r.in.num_names = count;
715 r.in.lookup_options = 0;
716 r.in.client_revision = 0;
717 r.out.count = &count;
719 r.out.domains = &domains;
721 status = dcerpc_lsa_LookupNames4_r(b, tctx, &r);
722 if (!NT_STATUS_IS_OK(status)) {
723 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
724 torture_comment(tctx,
725 "LookupNames4 correctly returned with "
731 torture_assert_ntstatus_equal(tctx,
733 NT_STATUS_ACCESS_DENIED,
734 "LookupNames4 return value should "
739 if (!NT_STATUS_IS_OK(r.out.result)) {
740 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_ACCESS_DENIED) ||
741 NT_STATUS_EQUAL(r.out.result, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
742 torture_comment(tctx,
743 "LookupSids3 correctly returned with "
745 nt_errstr(r.out.result));
750 torture_assert_ntstatus_equal(tctx,
753 "LookupNames4 return value should be "
760 static bool test_LookupSids(struct dcerpc_binding_handle *b,
761 struct torture_context *tctx,
762 struct policy_handle *handle,
763 struct lsa_SidArray *sids)
765 struct lsa_LookupSids r;
766 struct lsa_TransNameArray names;
767 struct lsa_RefDomainList *domains = NULL;
768 uint32_t count = sids->num_sids;
770 torture_comment(tctx, "\nTesting LookupSids\n");
775 r.in.handle = handle;
780 r.out.count = &count;
781 r.out.names = &names;
782 r.out.domains = &domains;
784 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupSids_r(b, tctx, &r),
785 "LookupSids failed");
786 if (!NT_STATUS_IS_OK(r.out.result) &&
787 !NT_STATUS_EQUAL(r.out.result, STATUS_SOME_UNMAPPED)) {
788 torture_comment(tctx, "LookupSids failed - %s\n",
789 nt_errstr(r.out.result));
793 torture_comment(tctx, "\n");
795 if (!test_LookupNames(b, tctx, handle, &names)) {
803 static bool test_LookupSids2(struct dcerpc_binding_handle *b,
804 struct torture_context *tctx,
805 struct policy_handle *handle,
806 struct lsa_SidArray *sids)
808 struct lsa_LookupSids2 r;
809 struct lsa_TransNameArray2 names;
810 struct lsa_RefDomainList *domains = NULL;
811 uint32_t count = sids->num_sids;
813 torture_comment(tctx, "\nTesting LookupSids2\n");
818 r.in.handle = handle;
823 r.in.lookup_options = 0;
824 r.in.client_revision = 0;
825 r.out.count = &count;
826 r.out.names = &names;
827 r.out.domains = &domains;
829 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupSids2_r(b, tctx, &r),
830 "LookupSids2 failed");
831 if (!NT_STATUS_IS_OK(r.out.result) &&
832 !NT_STATUS_EQUAL(r.out.result, STATUS_SOME_UNMAPPED)) {
833 torture_comment(tctx, "LookupSids2 failed - %s\n",
834 nt_errstr(r.out.result));
838 torture_comment(tctx, "\n");
840 if (!test_LookupNames2(b, tctx, handle, &names, false)) {
844 if (!test_LookupNames3(b, tctx, handle, &names, false)) {
851 static bool test_LookupSids3(struct dcerpc_binding_handle *b,
852 struct torture_context *tctx,
853 struct lsa_SidArray *sids)
855 struct lsa_LookupSids3 r;
856 struct lsa_TransNameArray2 names;
857 struct lsa_RefDomainList *domains = NULL;
858 uint32_t count = sids->num_sids;
860 torture_comment(tctx, "\nTesting LookupSids3\n");
869 r.in.lookup_options = 0;
870 r.in.client_revision = 0;
871 r.out.domains = &domains;
872 r.out.count = &count;
873 r.out.names = &names;
875 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupSids3_r(b, tctx, &r),
876 "LookupSids3 failed");
878 torture_assert_ntstatus_ok(tctx,
880 "LookupSids3 failed");
882 torture_comment(tctx, "\n");
887 static bool test_LookupSids3_fail(struct dcerpc_binding_handle *b,
888 struct torture_context *tctx,
889 struct lsa_SidArray *sids)
891 struct lsa_LookupSids3 r;
892 struct lsa_TransNameArray2 names;
893 struct lsa_RefDomainList *domains = NULL;
894 uint32_t count = sids->num_sids;
897 torture_comment(tctx, "\nTesting LookupSids3\n");
906 r.in.lookup_options = 0;
907 r.in.client_revision = 0;
908 r.out.domains = &domains;
909 r.out.count = &count;
910 r.out.names = &names;
912 status = dcerpc_lsa_LookupSids3_r(b, tctx, &r);
913 if (!NT_STATUS_IS_OK(status)) {
914 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
915 torture_comment(tctx,
916 "LookupSids3 correctly returned with "
922 torture_assert_ntstatus_equal(tctx,
924 NT_STATUS_ACCESS_DENIED,
925 "LookupSids3 return value should "
930 if (!NT_STATUS_IS_OK(r.out.result)) {
931 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_ACCESS_DENIED) ||
932 NT_STATUS_EQUAL(r.out.result, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
933 torture_comment(tctx,
934 "LookupNames4 correctly returned with "
936 nt_errstr(r.out.result));
941 torture_assert_ntstatus_equal(tctx,
944 "LookupSids3 return value should be "
950 bool test_many_LookupSids(struct dcerpc_pipe *p,
951 struct torture_context *tctx,
952 struct policy_handle *handle)
955 struct lsa_SidArray sids;
957 struct dcerpc_binding_handle *b = p->binding_handle;
959 torture_comment(tctx, "\nTesting LookupSids with lots of SIDs\n");
963 sids.sids = talloc_array(tctx, struct lsa_SidPtr, sids.num_sids);
965 for (i=0; i<sids.num_sids; i++) {
966 const char *sidstr = "S-1-5-32-545";
967 sids.sids[i].sid = dom_sid_parse_talloc(tctx, sidstr);
970 count = sids.num_sids;
973 struct lsa_LookupSids r;
974 struct lsa_TransNameArray names;
975 struct lsa_RefDomainList *domains = NULL;
979 r.in.handle = handle;
983 r.in.count = &names.count;
984 r.out.count = &count;
985 r.out.names = &names;
986 r.out.domains = &domains;
988 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupSids_r(b, tctx, &r),
989 "LookupSids failed");
990 if (!NT_STATUS_IS_OK(r.out.result)) {
991 torture_comment(tctx, "LookupSids failed - %s\n",
992 nt_errstr(r.out.result));
996 torture_comment(tctx, "\n");
998 if (!test_LookupNames(b, tctx, handle, &names)) {
1003 if (p->binding->transport == NCACN_NP) {
1004 if (!test_LookupSids3_fail(b, tctx, &sids)) {
1007 if (!test_LookupNames4_fail(b, tctx)) {
1010 } else if (p->binding->transport == NCACN_IP_TCP) {
1011 struct lsa_TransNameArray2 names;
1016 if (p->conn->security_state.auth_info->auth_type == DCERPC_AUTH_TYPE_SCHANNEL &&
1017 p->conn->security_state.auth_info->auth_level >= DCERPC_AUTH_LEVEL_INTEGRITY) {
1018 if (!test_LookupSids3(b, tctx, &sids)) {
1021 if (!test_LookupNames4(b, tctx, &names, true)) {
1026 * If we don't have a secure channel these tests must
1027 * fail with ACCESS_DENIED.
1029 if (!test_LookupSids3_fail(b, tctx, &sids)) {
1032 if (!test_LookupNames4_fail(b, tctx)) {
1038 torture_comment(tctx, "\n");
1045 static void lookupsids_cb(struct tevent_req *subreq)
1047 int *replies = (int *)tevent_req_callback_data_void(subreq);
1050 status = dcerpc_lsa_LookupSids_r_recv(subreq, subreq);
1051 TALLOC_FREE(subreq);
1052 if (!NT_STATUS_IS_OK(status)) {
1053 printf("lookupsids returned %s\n", nt_errstr(status));
1057 if (*replies >= 0) {
1062 static bool test_LookupSids_async(struct dcerpc_binding_handle *b,
1063 struct torture_context *tctx,
1064 struct policy_handle *handle)
1066 struct lsa_SidArray sids;
1067 struct lsa_SidPtr sidptr;
1069 struct lsa_TransNameArray *names;
1070 struct lsa_LookupSids *r;
1071 struct lsa_RefDomainList *domains = NULL;
1072 struct tevent_req **req;
1075 const int num_async_requests = 50;
1077 count = talloc_array(tctx, uint32_t, num_async_requests);
1078 names = talloc_array(tctx, struct lsa_TransNameArray, num_async_requests);
1079 r = talloc_array(tctx, struct lsa_LookupSids, num_async_requests);
1081 torture_comment(tctx, "\nTesting %d async lookupsids request\n", num_async_requests);
1083 req = talloc_array(tctx, struct tevent_req *, num_async_requests);
1086 sids.sids = &sidptr;
1087 sidptr.sid = dom_sid_parse_talloc(tctx, "S-1-5-32-545");
1091 for (i=0; i<num_async_requests; i++) {
1094 names[i].names = NULL;
1096 r[i].in.handle = handle;
1097 r[i].in.sids = &sids;
1098 r[i].in.names = &names[i];
1100 r[i].in.count = &names[i].count;
1101 r[i].out.count = &count[i];
1102 r[i].out.names = &names[i];
1103 r[i].out.domains = &domains;
1105 req[i] = dcerpc_lsa_LookupSids_r_send(tctx, tctx->ev, b, &r[i]);
1106 if (req[i] == NULL) {
1111 tevent_req_set_callback(req[i], lookupsids_cb, &replies);
1114 while (replies >= 0 && replies < num_async_requests) {
1115 tevent_loop_once(tctx->ev);
1127 static bool test_LookupPrivValue(struct dcerpc_binding_handle *b,
1128 struct torture_context *tctx,
1129 struct policy_handle *handle,
1130 struct lsa_String *name)
1132 struct lsa_LookupPrivValue r;
1133 struct lsa_LUID luid;
1135 r.in.handle = handle;
1139 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupPrivValue_r(b, tctx, &r),
1140 "LookupPrivValue failed");
1141 if (!NT_STATUS_IS_OK(r.out.result)) {
1142 torture_comment(tctx, "\nLookupPrivValue failed - %s\n",
1143 nt_errstr(r.out.result));
1150 static bool test_LookupPrivName(struct dcerpc_binding_handle *b,
1151 struct torture_context *tctx,
1152 struct policy_handle *handle,
1153 struct lsa_LUID *luid)
1155 struct lsa_LookupPrivName r;
1156 struct lsa_StringLarge *name = NULL;
1158 r.in.handle = handle;
1162 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupPrivName_r(b, tctx, &r),
1163 "LookupPrivName failed");
1164 if (!NT_STATUS_IS_OK(r.out.result)) {
1165 torture_comment(tctx, "\nLookupPrivName failed - %s\n",
1166 nt_errstr(r.out.result));
1173 static bool test_RemovePrivilegesFromAccount(struct dcerpc_binding_handle *b,
1174 struct torture_context *tctx,
1175 struct policy_handle *handle,
1176 struct policy_handle *acct_handle,
1177 struct lsa_LUID *luid)
1179 struct lsa_RemovePrivilegesFromAccount r;
1180 struct lsa_PrivilegeSet privs;
1183 torture_comment(tctx, "\nTesting RemovePrivilegesFromAccount\n");
1185 r.in.handle = acct_handle;
1186 r.in.remove_all = 0;
1187 r.in.privs = &privs;
1191 privs.set = talloc_array(tctx, struct lsa_LUIDAttribute, 1);
1192 privs.set[0].luid = *luid;
1193 privs.set[0].attribute = 0;
1195 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_RemovePrivilegesFromAccount_r(b, tctx, &r),
1196 "RemovePrivilegesFromAccount failed");
1197 if (!NT_STATUS_IS_OK(r.out.result)) {
1199 struct lsa_LookupPrivName r_name;
1200 struct lsa_StringLarge *name = NULL;
1202 r_name.in.handle = handle;
1203 r_name.in.luid = luid;
1204 r_name.out.name = &name;
1206 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupPrivName_r(b, tctx, &r_name),
1207 "LookupPrivName failed");
1208 if (!NT_STATUS_IS_OK(r_name.out.result)) {
1209 torture_comment(tctx, "\nLookupPrivName failed - %s\n",
1210 nt_errstr(r_name.out.result));
1213 /* Windows 2008 does not allow this to be removed */
1214 if (strcmp("SeAuditPrivilege", name->string) == 0) {
1218 torture_comment(tctx, "RemovePrivilegesFromAccount failed to remove %s - %s\n",
1220 nt_errstr(r.out.result));
1227 static bool test_AddPrivilegesToAccount(struct dcerpc_binding_handle *b,
1228 struct torture_context *tctx,
1229 struct policy_handle *acct_handle,
1230 struct lsa_LUID *luid)
1232 struct lsa_AddPrivilegesToAccount r;
1233 struct lsa_PrivilegeSet privs;
1236 torture_comment(tctx, "\nTesting AddPrivilegesToAccount\n");
1238 r.in.handle = acct_handle;
1239 r.in.privs = &privs;
1243 privs.set = talloc_array(tctx, struct lsa_LUIDAttribute, 1);
1244 privs.set[0].luid = *luid;
1245 privs.set[0].attribute = 0;
1247 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_AddPrivilegesToAccount_r(b, tctx, &r),
1248 "AddPrivilegesToAccount failed");
1249 if (!NT_STATUS_IS_OK(r.out.result)) {
1250 torture_comment(tctx, "AddPrivilegesToAccount failed - %s\n",
1251 nt_errstr(r.out.result));
1258 static bool test_EnumPrivsAccount(struct dcerpc_binding_handle *b,
1259 struct torture_context *tctx,
1260 struct policy_handle *handle,
1261 struct policy_handle *acct_handle)
1263 struct lsa_EnumPrivsAccount r;
1264 struct lsa_PrivilegeSet *privs = NULL;
1267 torture_comment(tctx, "\nTesting EnumPrivsAccount\n");
1269 r.in.handle = acct_handle;
1270 r.out.privs = &privs;
1272 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumPrivsAccount_r(b, tctx, &r),
1273 "EnumPrivsAccount failed");
1274 if (!NT_STATUS_IS_OK(r.out.result)) {
1275 torture_comment(tctx, "EnumPrivsAccount failed - %s\n",
1276 nt_errstr(r.out.result));
1280 if (privs && privs->count > 0) {
1282 for (i=0;i<privs->count;i++) {
1283 test_LookupPrivName(b, tctx, handle,
1284 &privs->set[i].luid);
1287 ret &= test_RemovePrivilegesFromAccount(b, tctx, handle, acct_handle,
1288 &privs->set[0].luid);
1289 ret &= test_AddPrivilegesToAccount(b, tctx, acct_handle,
1290 &privs->set[0].luid);
1296 static bool test_GetSystemAccessAccount(struct dcerpc_binding_handle *b,
1297 struct torture_context *tctx,
1298 struct policy_handle *handle,
1299 struct policy_handle *acct_handle)
1301 uint32_t access_mask;
1302 struct lsa_GetSystemAccessAccount r;
1304 torture_comment(tctx, "\nTesting GetSystemAccessAccount\n");
1306 r.in.handle = acct_handle;
1307 r.out.access_mask = &access_mask;
1309 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_GetSystemAccessAccount_r(b, tctx, &r),
1310 "GetSystemAccessAccount failed");
1311 if (!NT_STATUS_IS_OK(r.out.result)) {
1312 torture_comment(tctx, "GetSystemAccessAccount failed - %s\n",
1313 nt_errstr(r.out.result));
1317 if (r.out.access_mask != NULL) {
1318 torture_comment(tctx, "Rights:");
1319 if (*(r.out.access_mask) & LSA_POLICY_MODE_INTERACTIVE)
1320 torture_comment(tctx, " LSA_POLICY_MODE_INTERACTIVE");
1321 if (*(r.out.access_mask) & LSA_POLICY_MODE_NETWORK)
1322 torture_comment(tctx, " LSA_POLICY_MODE_NETWORK");
1323 if (*(r.out.access_mask) & LSA_POLICY_MODE_BATCH)
1324 torture_comment(tctx, " LSA_POLICY_MODE_BATCH");
1325 if (*(r.out.access_mask) & LSA_POLICY_MODE_SERVICE)
1326 torture_comment(tctx, " LSA_POLICY_MODE_SERVICE");
1327 if (*(r.out.access_mask) & LSA_POLICY_MODE_PROXY)
1328 torture_comment(tctx, " LSA_POLICY_MODE_PROXY");
1329 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_INTERACTIVE)
1330 torture_comment(tctx, " LSA_POLICY_MODE_DENY_INTERACTIVE");
1331 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_NETWORK)
1332 torture_comment(tctx, " LSA_POLICY_MODE_DENY_NETWORK");
1333 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_BATCH)
1334 torture_comment(tctx, " LSA_POLICY_MODE_DENY_BATCH");
1335 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_SERVICE)
1336 torture_comment(tctx, " LSA_POLICY_MODE_DENY_SERVICE");
1337 if (*(r.out.access_mask) & LSA_POLICY_MODE_REMOTE_INTERACTIVE)
1338 torture_comment(tctx, " LSA_POLICY_MODE_REMOTE_INTERACTIVE");
1339 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_REMOTE_INTERACTIVE)
1340 torture_comment(tctx, " LSA_POLICY_MODE_DENY_REMOTE_INTERACTIVE");
1341 if (*(r.out.access_mask) & LSA_POLICY_MODE_ALL)
1342 torture_comment(tctx, " LSA_POLICY_MODE_ALL");
1343 if (*(r.out.access_mask) & LSA_POLICY_MODE_ALL_NT4)
1344 torture_comment(tctx, " LSA_POLICY_MODE_ALL_NT4");
1345 torture_comment(tctx, "\n");
1351 static bool test_Delete(struct dcerpc_binding_handle *b,
1352 struct torture_context *tctx,
1353 struct policy_handle *handle)
1355 struct lsa_Delete r;
1357 torture_comment(tctx, "\nTesting Delete\n");
1359 r.in.handle = handle;
1360 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_Delete_r(b, tctx, &r),
1362 if (!NT_STATUS_EQUAL(r.out.result, NT_STATUS_NOT_SUPPORTED)) {
1363 torture_comment(tctx, "Delete should have failed NT_STATUS_NOT_SUPPORTED - %s\n", nt_errstr(r.out.result));
1370 static bool test_DeleteObject(struct dcerpc_binding_handle *b,
1371 struct torture_context *tctx,
1372 struct policy_handle *handle)
1374 struct lsa_DeleteObject r;
1376 torture_comment(tctx, "\nTesting DeleteObject\n");
1378 r.in.handle = handle;
1379 r.out.handle = handle;
1380 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_DeleteObject_r(b, tctx, &r),
1381 "DeleteObject failed");
1382 if (!NT_STATUS_IS_OK(r.out.result)) {
1383 torture_comment(tctx, "DeleteObject failed - %s\n",
1384 nt_errstr(r.out.result));
1392 static bool test_CreateAccount(struct dcerpc_binding_handle *b,
1393 struct torture_context *tctx,
1394 struct policy_handle *handle)
1396 struct lsa_CreateAccount r;
1397 struct dom_sid2 *newsid;
1398 struct policy_handle acct_handle;
1400 newsid = dom_sid_parse_talloc(tctx, "S-1-5-12349876-4321-2854");
1402 torture_comment(tctx, "\nTesting CreateAccount\n");
1404 r.in.handle = handle;
1406 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1407 r.out.acct_handle = &acct_handle;
1409 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_CreateAccount_r(b, tctx, &r),
1410 "CreateAccount failed");
1411 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_OBJECT_NAME_COLLISION)) {
1412 struct lsa_OpenAccount r_o;
1413 r_o.in.handle = handle;
1414 r_o.in.sid = newsid;
1415 r_o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1416 r_o.out.acct_handle = &acct_handle;
1418 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenAccount_r(b, tctx, &r_o),
1419 "OpenAccount failed");
1420 if (!NT_STATUS_IS_OK(r_o.out.result)) {
1421 torture_comment(tctx, "OpenAccount failed - %s\n",
1422 nt_errstr(r_o.out.result));
1425 } else if (!NT_STATUS_IS_OK(r.out.result)) {
1426 torture_comment(tctx, "CreateAccount failed - %s\n",
1427 nt_errstr(r.out.result));
1431 if (!test_Delete(b, tctx, &acct_handle)) {
1435 if (!test_DeleteObject(b, tctx, &acct_handle)) {
1442 static bool test_DeleteTrustedDomain(struct dcerpc_binding_handle *b,
1443 struct torture_context *tctx,
1444 struct policy_handle *handle,
1445 struct lsa_StringLarge name)
1447 struct lsa_OpenTrustedDomainByName r;
1448 struct policy_handle trustdom_handle;
1450 r.in.handle = handle;
1451 r.in.name.string = name.string;
1452 r.in.access_mask = SEC_STD_DELETE;
1453 r.out.trustdom_handle = &trustdom_handle;
1455 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenTrustedDomainByName_r(b, tctx, &r),
1456 "OpenTrustedDomainByName failed");
1457 if (!NT_STATUS_IS_OK(r.out.result)) {
1458 torture_comment(tctx, "OpenTrustedDomainByName failed - %s\n", nt_errstr(r.out.result));
1462 if (!test_Delete(b, tctx, &trustdom_handle)) {
1466 if (!test_DeleteObject(b, tctx, &trustdom_handle)) {
1473 static bool test_DeleteTrustedDomainBySid(struct dcerpc_binding_handle *b,
1474 struct torture_context *tctx,
1475 struct policy_handle *handle,
1476 struct dom_sid *sid)
1478 struct lsa_DeleteTrustedDomain r;
1480 r.in.handle = handle;
1483 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_DeleteTrustedDomain_r(b, tctx, &r),
1484 "DeleteTrustedDomain failed");
1485 if (!NT_STATUS_IS_OK(r.out.result)) {
1486 torture_comment(tctx, "DeleteTrustedDomain failed - %s\n", nt_errstr(r.out.result));
1494 static bool test_CreateSecret(struct dcerpc_pipe *p,
1495 struct torture_context *tctx,
1496 struct policy_handle *handle)
1499 struct lsa_CreateSecret r;
1500 struct lsa_OpenSecret r2;
1501 struct lsa_SetSecret r3;
1502 struct lsa_QuerySecret r4;
1503 struct lsa_SetSecret r5;
1504 struct lsa_QuerySecret r6;
1505 struct lsa_SetSecret r7;
1506 struct lsa_QuerySecret r8;
1507 struct policy_handle sec_handle, sec_handle2, sec_handle3;
1508 struct lsa_DeleteObject d_o;
1509 struct lsa_DATA_BUF buf1;
1510 struct lsa_DATA_BUF_PTR bufp1;
1511 struct lsa_DATA_BUF_PTR bufp2;
1514 DATA_BLOB session_key;
1515 NTTIME old_mtime, new_mtime;
1517 const char *secret1 = "abcdef12345699qwerty";
1519 const char *secret3 = "ABCDEF12345699QWERTY";
1521 const char *secret5 = "NEW-SAMBA4-SECRET";
1525 const int LOCAL = 0;
1526 const int GLOBAL = 1;
1527 struct dcerpc_binding_handle *b = p->binding_handle;
1529 secname[LOCAL] = talloc_asprintf(tctx, "torturesecret-%u", (unsigned int)random());
1530 secname[GLOBAL] = talloc_asprintf(tctx, "G$torturesecret-%u", (unsigned int)random());
1532 for (i=0; i< 2; i++) {
1533 torture_comment(tctx, "\nTesting CreateSecret of %s\n", secname[i]);
1535 init_lsa_String(&r.in.name, secname[i]);
1537 r.in.handle = handle;
1538 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1539 r.out.sec_handle = &sec_handle;
1541 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_CreateSecret_r(b, tctx, &r),
1542 "CreateSecret failed");
1543 if (!NT_STATUS_IS_OK(r.out.result)) {
1544 torture_comment(tctx, "CreateSecret failed - %s\n", nt_errstr(r.out.result));
1548 r.in.handle = handle;
1549 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1550 r.out.sec_handle = &sec_handle3;
1552 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_CreateSecret_r(b, tctx, &r),
1553 "CreateSecret failed");
1554 if (!NT_STATUS_EQUAL(r.out.result, NT_STATUS_OBJECT_NAME_COLLISION)) {
1555 torture_comment(tctx, "CreateSecret should have failed OBJECT_NAME_COLLISION - %s\n", nt_errstr(r.out.result));
1559 r2.in.handle = handle;
1560 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1561 r2.in.name = r.in.name;
1562 r2.out.sec_handle = &sec_handle2;
1564 torture_comment(tctx, "Testing OpenSecret\n");
1566 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenSecret_r(b, tctx, &r2),
1567 "OpenSecret failed");
1568 if (!NT_STATUS_IS_OK(r2.out.result)) {
1569 torture_comment(tctx, "OpenSecret failed - %s\n", nt_errstr(r2.out.result));
1573 status = dcerpc_fetch_session_key(p, &session_key);
1574 if (!NT_STATUS_IS_OK(status)) {
1575 torture_comment(tctx, "dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
1579 enc_key = sess_encrypt_string(secret1, &session_key);
1581 r3.in.sec_handle = &sec_handle;
1582 r3.in.new_val = &buf1;
1583 r3.in.old_val = NULL;
1584 r3.in.new_val->data = enc_key.data;
1585 r3.in.new_val->length = enc_key.length;
1586 r3.in.new_val->size = enc_key.length;
1588 torture_comment(tctx, "Testing SetSecret\n");
1590 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_SetSecret_r(b, tctx, &r3),
1591 "SetSecret failed");
1592 if (!NT_STATUS_IS_OK(r3.out.result)) {
1593 torture_comment(tctx, "SetSecret failed - %s\n", nt_errstr(r3.out.result));
1597 r3.in.sec_handle = &sec_handle;
1598 r3.in.new_val = &buf1;
1599 r3.in.old_val = NULL;
1600 r3.in.new_val->data = enc_key.data;
1601 r3.in.new_val->length = enc_key.length;
1602 r3.in.new_val->size = enc_key.length;
1604 /* break the encrypted data */
1607 torture_comment(tctx, "Testing SetSecret with broken key\n");
1609 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_SetSecret_r(b, tctx, &r3),
1610 "SetSecret failed");
1611 if (!NT_STATUS_EQUAL(r3.out.result, NT_STATUS_UNKNOWN_REVISION)) {
1612 torture_comment(tctx, "SetSecret should have failed UNKNOWN_REVISION - %s\n", nt_errstr(r3.out.result));
1616 data_blob_free(&enc_key);
1618 ZERO_STRUCT(new_mtime);
1619 ZERO_STRUCT(old_mtime);
1621 /* fetch the secret back again */
1622 r4.in.sec_handle = &sec_handle;
1623 r4.in.new_val = &bufp1;
1624 r4.in.new_mtime = &new_mtime;
1625 r4.in.old_val = NULL;
1626 r4.in.old_mtime = NULL;
1630 torture_comment(tctx, "Testing QuerySecret\n");
1631 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QuerySecret_r(b, tctx, &r4),
1632 "QuerySecret failed");
1633 if (!NT_STATUS_IS_OK(r4.out.result)) {
1634 torture_comment(tctx, "QuerySecret failed - %s\n", nt_errstr(r4.out.result));
1637 if (r4.out.new_val == NULL || r4.out.new_val->buf == NULL) {
1638 torture_comment(tctx, "No secret buffer returned\n");
1641 blob1.data = r4.out.new_val->buf->data;
1642 blob1.length = r4.out.new_val->buf->size;
1644 secret2 = sess_decrypt_string(tctx,
1645 &blob1, &session_key);
1647 if (strcmp(secret1, secret2) != 0) {
1648 torture_comment(tctx, "Returned secret (r4) '%s' doesn't match '%s'\n",
1655 enc_key = sess_encrypt_string(secret3, &session_key);
1657 r5.in.sec_handle = &sec_handle;
1658 r5.in.new_val = &buf1;
1659 r5.in.old_val = NULL;
1660 r5.in.new_val->data = enc_key.data;
1661 r5.in.new_val->length = enc_key.length;
1662 r5.in.new_val->size = enc_key.length;
1666 torture_comment(tctx, "Testing SetSecret (existing value should move to old)\n");
1668 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_SetSecret_r(b, tctx, &r5),
1669 "SetSecret failed");
1670 if (!NT_STATUS_IS_OK(r5.out.result)) {
1671 torture_comment(tctx, "SetSecret failed - %s\n", nt_errstr(r5.out.result));
1675 data_blob_free(&enc_key);
1677 ZERO_STRUCT(new_mtime);
1678 ZERO_STRUCT(old_mtime);
1680 /* fetch the secret back again */
1681 r6.in.sec_handle = &sec_handle;
1682 r6.in.new_val = &bufp1;
1683 r6.in.new_mtime = &new_mtime;
1684 r6.in.old_val = &bufp2;
1685 r6.in.old_mtime = &old_mtime;
1690 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QuerySecret_r(b, tctx, &r6),
1691 "QuerySecret failed");
1692 if (!NT_STATUS_IS_OK(r6.out.result)) {
1693 torture_comment(tctx, "QuerySecret failed - %s\n", nt_errstr(r6.out.result));
1698 if (r6.out.new_val->buf == NULL || r6.out.old_val->buf == NULL
1699 || r6.out.new_mtime == NULL || r6.out.old_mtime == NULL) {
1700 torture_comment(tctx, "Both secret buffers and both times not returned\n");
1704 blob1.data = r6.out.new_val->buf->data;
1705 blob1.length = r6.out.new_val->buf->size;
1707 secret4 = sess_decrypt_string(tctx,
1708 &blob1, &session_key);
1710 if (strcmp(secret3, secret4) != 0) {
1711 torture_comment(tctx, "Returned NEW secret %s doesn't match %s\n", secret4, secret3);
1715 blob1.data = r6.out.old_val->buf->data;
1716 blob1.length = r6.out.old_val->buf->length;
1718 secret2 = sess_decrypt_string(tctx,
1719 &blob1, &session_key);
1721 if (strcmp(secret1, secret2) != 0) {
1722 torture_comment(tctx, "Returned OLD secret %s doesn't match %s\n", secret2, secret1);
1726 if (*r6.out.new_mtime == *r6.out.old_mtime) {
1727 torture_comment(tctx, "Returned secret (r6-%d) %s must not have same mtime for both secrets: %s != %s\n",
1730 nt_time_string(tctx, *r6.out.old_mtime),
1731 nt_time_string(tctx, *r6.out.new_mtime));
1737 enc_key = sess_encrypt_string(secret5, &session_key);
1739 r7.in.sec_handle = &sec_handle;
1740 r7.in.old_val = &buf1;
1741 r7.in.old_val->data = enc_key.data;
1742 r7.in.old_val->length = enc_key.length;
1743 r7.in.old_val->size = enc_key.length;
1744 r7.in.new_val = NULL;
1746 torture_comment(tctx, "Testing SetSecret of old Secret only\n");
1748 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_SetSecret_r(b, tctx, &r7),
1749 "SetSecret failed");
1750 if (!NT_STATUS_IS_OK(r7.out.result)) {
1751 torture_comment(tctx, "SetSecret failed - %s\n", nt_errstr(r7.out.result));
1755 data_blob_free(&enc_key);
1757 /* fetch the secret back again */
1758 r8.in.sec_handle = &sec_handle;
1759 r8.in.new_val = &bufp1;
1760 r8.in.new_mtime = &new_mtime;
1761 r8.in.old_val = &bufp2;
1762 r8.in.old_mtime = &old_mtime;
1767 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QuerySecret_r(b, tctx, &r8),
1768 "QuerySecret failed");
1769 if (!NT_STATUS_IS_OK(r8.out.result)) {
1770 torture_comment(tctx, "QuerySecret failed - %s\n", nt_errstr(r8.out.result));
1773 if (!r8.out.new_val || !r8.out.old_val) {
1774 torture_comment(tctx, "in/out pointers not returned, despite being set on in for QuerySecret\n");
1776 } else if (r8.out.new_val->buf != NULL) {
1777 torture_comment(tctx, "NEW secret buffer must not be returned after OLD set\n");
1779 } else if (r8.out.old_val->buf == NULL) {
1780 torture_comment(tctx, "OLD secret buffer was not returned after OLD set\n");
1782 } else if (r8.out.new_mtime == NULL || r8.out.old_mtime == NULL) {
1783 torture_comment(tctx, "Both times not returned after OLD set\n");
1786 blob1.data = r8.out.old_val->buf->data;
1787 blob1.length = r8.out.old_val->buf->size;
1789 secret6 = sess_decrypt_string(tctx,
1790 &blob1, &session_key);
1792 if (strcmp(secret5, secret6) != 0) {
1793 torture_comment(tctx, "Returned OLD secret %s doesn't match %s\n", secret5, secret6);
1797 if (*r8.out.new_mtime != *r8.out.old_mtime) {
1798 torture_comment(tctx, "Returned secret (r8) %s did not had same mtime for both secrets: %s != %s\n",
1800 nt_time_string(tctx, *r8.out.old_mtime),
1801 nt_time_string(tctx, *r8.out.new_mtime));
1807 if (!test_Delete(b, tctx, &sec_handle)) {
1811 if (!test_DeleteObject(b, tctx, &sec_handle)) {
1815 d_o.in.handle = &sec_handle2;
1816 d_o.out.handle = &sec_handle2;
1817 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_DeleteObject_r(b, tctx, &d_o),
1818 "DeleteObject failed");
1819 if (!NT_STATUS_EQUAL(d_o.out.result, NT_STATUS_INVALID_HANDLE)) {
1820 torture_comment(tctx, "Second delete expected INVALID_HANDLE - %s\n", nt_errstr(d_o.out.result));
1824 torture_comment(tctx, "Testing OpenSecret of just-deleted secret\n");
1826 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenSecret_r(b, tctx, &r2),
1827 "OpenSecret failed");
1828 if (!NT_STATUS_EQUAL(r2.out.result, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
1829 torture_comment(tctx, "OpenSecret expected OBJECT_NAME_NOT_FOUND - %s\n", nt_errstr(r2.out.result));
1840 static bool test_EnumAccountRights(struct dcerpc_binding_handle *b,
1841 struct torture_context *tctx,
1842 struct policy_handle *acct_handle,
1843 struct dom_sid *sid)
1845 struct lsa_EnumAccountRights r;
1846 struct lsa_RightSet rights;
1848 torture_comment(tctx, "\nTesting EnumAccountRights\n");
1850 r.in.handle = acct_handle;
1852 r.out.rights = &rights;
1854 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumAccountRights_r(b, tctx, &r),
1855 "EnumAccountRights failed");
1856 if (!NT_STATUS_IS_OK(r.out.result)) {
1857 torture_comment(tctx, "EnumAccountRights of %s failed - %s\n",
1858 dom_sid_string(tctx, sid), nt_errstr(r.out.result));
1866 static bool test_QuerySecurity(struct dcerpc_binding_handle *b,
1867 struct torture_context *tctx,
1868 struct policy_handle *handle,
1869 struct policy_handle *acct_handle)
1871 struct lsa_QuerySecurity r;
1872 struct sec_desc_buf *sdbuf = NULL;
1874 if (torture_setting_bool(tctx, "samba4", false)) {
1875 torture_comment(tctx, "\nskipping QuerySecurity test against Samba4\n");
1879 torture_comment(tctx, "\nTesting QuerySecurity\n");
1881 r.in.handle = acct_handle;
1882 r.in.sec_info = SECINFO_OWNER |
1885 r.out.sdbuf = &sdbuf;
1887 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QuerySecurity_r(b, tctx, &r),
1888 "QuerySecurity failed");
1889 if (!NT_STATUS_IS_OK(r.out.result)) {
1890 torture_comment(tctx, "QuerySecurity failed - %s\n", nt_errstr(r.out.result));
1897 static bool test_OpenAccount(struct dcerpc_binding_handle *b,
1898 struct torture_context *tctx,
1899 struct policy_handle *handle,
1900 struct dom_sid *sid)
1902 struct lsa_OpenAccount r;
1903 struct policy_handle acct_handle;
1905 torture_comment(tctx, "\nTesting OpenAccount\n");
1907 r.in.handle = handle;
1909 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1910 r.out.acct_handle = &acct_handle;
1912 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenAccount_r(b, tctx, &r),
1913 "OpenAccount failed");
1914 if (!NT_STATUS_IS_OK(r.out.result)) {
1915 torture_comment(tctx, "OpenAccount failed - %s\n", nt_errstr(r.out.result));
1919 if (!test_EnumPrivsAccount(b, tctx, handle, &acct_handle)) {
1923 if (!test_GetSystemAccessAccount(b, tctx, handle, &acct_handle)) {
1927 if (!test_QuerySecurity(b, tctx, handle, &acct_handle)) {
1934 static bool test_EnumAccounts(struct dcerpc_binding_handle *b,
1935 struct torture_context *tctx,
1936 struct policy_handle *handle)
1938 struct lsa_EnumAccounts r;
1939 struct lsa_SidArray sids1, sids2;
1940 uint32_t resume_handle = 0;
1944 torture_comment(tctx, "\nTesting EnumAccounts\n");
1946 r.in.handle = handle;
1947 r.in.resume_handle = &resume_handle;
1948 r.in.num_entries = 100;
1949 r.out.resume_handle = &resume_handle;
1950 r.out.sids = &sids1;
1954 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumAccounts_r(b, tctx, &r),
1955 "EnumAccounts failed");
1956 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_NO_MORE_ENTRIES)) {
1959 if (!NT_STATUS_IS_OK(r.out.result)) {
1960 torture_comment(tctx, "EnumAccounts failed - %s\n", nt_errstr(r.out.result));
1964 if (!test_LookupSids(b, tctx, handle, &sids1)) {
1968 if (!test_LookupSids2(b, tctx, handle, &sids1)) {
1972 /* Can't test lookupSids3 here, as clearly we must not
1973 * be on schannel, or we would not be able to do the
1976 torture_comment(tctx, "Testing all accounts\n");
1977 for (i=0;i<sids1.num_sids;i++) {
1978 ret &= test_OpenAccount(b, tctx, handle, sids1.sids[i].sid);
1979 ret &= test_EnumAccountRights(b, tctx, handle, sids1.sids[i].sid);
1981 torture_comment(tctx, "\n");
1984 if (sids1.num_sids < 3) {
1988 torture_comment(tctx, "Trying EnumAccounts partial listing (asking for 1 at 2)\n");
1990 r.in.num_entries = 1;
1991 r.out.sids = &sids2;
1993 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumAccounts_r(b, tctx, &r),
1994 "EnumAccounts failed");
1995 if (!NT_STATUS_IS_OK(r.out.result)) {
1996 torture_comment(tctx, "EnumAccounts failed - %s\n", nt_errstr(r.out.result));
2000 if (sids2.num_sids != 1) {
2001 torture_comment(tctx, "Returned wrong number of entries (%d)\n", sids2.num_sids);
2008 static bool test_LookupPrivDisplayName(struct dcerpc_binding_handle *b,
2009 struct torture_context *tctx,
2010 struct policy_handle *handle,
2011 struct lsa_String *priv_name)
2013 struct lsa_LookupPrivDisplayName r;
2014 /* produce a reasonable range of language output without screwing up
2016 uint16_t language_id = (random() % 4) + 0x409;
2017 uint16_t returned_language_id = 0;
2018 struct lsa_StringLarge *disp_name = NULL;
2020 torture_comment(tctx, "\nTesting LookupPrivDisplayName(%s)\n", priv_name->string);
2022 r.in.handle = handle;
2023 r.in.name = priv_name;
2024 r.in.language_id = language_id;
2025 r.in.language_id_sys = 0;
2026 r.out.returned_language_id = &returned_language_id;
2027 r.out.disp_name = &disp_name;
2029 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupPrivDisplayName_r(b, tctx, &r),
2030 "LookupPrivDisplayName failed");
2031 if (!NT_STATUS_IS_OK(r.out.result)) {
2032 torture_comment(tctx, "LookupPrivDisplayName failed - %s\n", nt_errstr(r.out.result));
2035 torture_comment(tctx, "%s -> \"%s\" (language 0x%x/0x%x)\n",
2036 priv_name->string, disp_name->string,
2037 r.in.language_id, *r.out.returned_language_id);
2042 static bool test_EnumAccountsWithUserRight(struct dcerpc_binding_handle *b,
2043 struct torture_context *tctx,
2044 struct policy_handle *handle,
2045 struct lsa_String *priv_name)
2047 struct lsa_EnumAccountsWithUserRight r;
2048 struct lsa_SidArray sids;
2052 torture_comment(tctx, "\nTesting EnumAccountsWithUserRight(%s)\n", priv_name->string);
2054 r.in.handle = handle;
2055 r.in.name = priv_name;
2058 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumAccountsWithUserRight_r(b, tctx, &r),
2059 "EnumAccountsWithUserRight failed");
2061 /* NT_STATUS_NO_MORE_ENTRIES means noone has this privilege */
2062 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_NO_MORE_ENTRIES)) {
2066 if (!NT_STATUS_IS_OK(r.out.result)) {
2067 torture_comment(tctx, "EnumAccountsWithUserRight failed - %s\n", nt_errstr(r.out.result));
2075 static bool test_EnumPrivs(struct dcerpc_binding_handle *b,
2076 struct torture_context *tctx,
2077 struct policy_handle *handle)
2079 struct lsa_EnumPrivs r;
2080 struct lsa_PrivArray privs1;
2081 uint32_t resume_handle = 0;
2085 torture_comment(tctx, "\nTesting EnumPrivs\n");
2087 r.in.handle = handle;
2088 r.in.resume_handle = &resume_handle;
2089 r.in.max_count = 100;
2090 r.out.resume_handle = &resume_handle;
2091 r.out.privs = &privs1;
2094 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumPrivs_r(b, tctx, &r),
2095 "EnumPrivs failed");
2096 if (!NT_STATUS_IS_OK(r.out.result)) {
2097 torture_comment(tctx, "EnumPrivs failed - %s\n", nt_errstr(r.out.result));
2101 for (i = 0; i< privs1.count; i++) {
2102 test_LookupPrivDisplayName(b, tctx, handle, (struct lsa_String *)&privs1.privs[i].name);
2103 test_LookupPrivValue(b, tctx, handle, (struct lsa_String *)&privs1.privs[i].name);
2104 if (!test_EnumAccountsWithUserRight(b, tctx, handle, (struct lsa_String *)&privs1.privs[i].name)) {
2112 static bool test_QueryForestTrustInformation(struct dcerpc_binding_handle *b,
2113 struct torture_context *tctx,
2114 struct policy_handle *handle,
2115 const char *trusted_domain_name)
2118 struct lsa_lsaRQueryForestTrustInformation r;
2119 struct lsa_String string;
2120 struct lsa_ForestTrustInformation info, *info_ptr;
2122 torture_comment(tctx, "\nTesting lsaRQueryForestTrustInformation\n");
2124 if (torture_setting_bool(tctx, "samba4", false)) {
2125 torture_comment(tctx, "skipping QueryForestTrustInformation against Samba4\n");
2129 ZERO_STRUCT(string);
2131 if (trusted_domain_name) {
2132 init_lsa_String(&string, trusted_domain_name);
2137 r.in.handle = handle;
2138 r.in.trusted_domain_name = &string;
2140 r.out.forest_trust_info = &info_ptr;
2142 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_lsaRQueryForestTrustInformation_r(b, tctx, &r),
2143 "lsaRQueryForestTrustInformation failed");
2145 if (!NT_STATUS_IS_OK(r.out.result)) {
2146 torture_comment(tctx, "lsaRQueryForestTrustInformation of %s failed - %s\n", trusted_domain_name, nt_errstr(r.out.result));
2153 static bool test_query_each_TrustDomEx(struct dcerpc_binding_handle *b,
2154 struct torture_context *tctx,
2155 struct policy_handle *handle,
2156 struct lsa_DomainListEx *domains)
2161 for (i=0; i< domains->count; i++) {
2163 if (domains->domains[i].trust_attributes & NETR_TRUST_ATTRIBUTE_FOREST_TRANSITIVE) {
2164 ret &= test_QueryForestTrustInformation(b, tctx, handle,
2165 domains->domains[i].domain_name.string);
2172 static bool test_query_each_TrustDom(struct dcerpc_binding_handle *b,
2173 struct torture_context *tctx,
2174 struct policy_handle *handle,
2175 struct lsa_DomainList *domains)
2180 torture_comment(tctx, "\nTesting OpenTrustedDomain, OpenTrustedDomainByName and QueryInfoTrustedDomain\n");
2181 for (i=0; i< domains->count; i++) {
2182 struct lsa_OpenTrustedDomain trust;
2183 struct lsa_OpenTrustedDomainByName trust_by_name;
2184 struct policy_handle trustdom_handle;
2185 struct policy_handle handle2;
2187 struct lsa_CloseTrustedDomainEx c_trust;
2188 int levels [] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
2189 int ok[] = {1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1};
2191 if (domains->domains[i].sid) {
2192 trust.in.handle = handle;
2193 trust.in.sid = domains->domains[i].sid;
2194 trust.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2195 trust.out.trustdom_handle = &trustdom_handle;
2197 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenTrustedDomain_r(b, tctx, &trust),
2198 "OpenTrustedDomain failed");
2200 if (!NT_STATUS_IS_OK(trust.out.result)) {
2201 torture_comment(tctx, "OpenTrustedDomain failed - %s\n", nt_errstr(trust.out.result));
2205 c.in.handle = &trustdom_handle;
2206 c.out.handle = &handle2;
2208 c_trust.in.handle = &trustdom_handle;
2209 c_trust.out.handle = &handle2;
2211 for (j=0; j < ARRAY_SIZE(levels); j++) {
2212 struct lsa_QueryTrustedDomainInfo q;
2213 union lsa_TrustedDomainInfo *info = NULL;
2214 q.in.trustdom_handle = &trustdom_handle;
2215 q.in.level = levels[j];
2217 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryTrustedDomainInfo_r(b, tctx, &q),
2218 "QueryTrustedDomainInfo failed");
2219 if (!NT_STATUS_IS_OK(q.out.result) && ok[j]) {
2220 torture_comment(tctx, "QueryTrustedDomainInfo level %d failed - %s\n",
2221 levels[j], nt_errstr(q.out.result));
2223 } else if (NT_STATUS_IS_OK(q.out.result) && !ok[j]) {
2224 torture_comment(tctx, "QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
2225 levels[j], nt_errstr(q.out.result));
2230 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_CloseTrustedDomainEx_r(b, tctx, &c_trust),
2231 "CloseTrustedDomainEx failed");
2232 if (!NT_STATUS_EQUAL(c_trust.out.result, NT_STATUS_NOT_IMPLEMENTED)) {
2233 torture_comment(tctx, "Expected CloseTrustedDomainEx to return NT_STATUS_NOT_IMPLEMENTED, instead - %s\n", nt_errstr(c_trust.out.result));
2237 c.in.handle = &trustdom_handle;
2238 c.out.handle = &handle2;
2240 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_Close_r(b, tctx, &c),
2242 if (!NT_STATUS_IS_OK(c.out.result)) {
2243 torture_comment(tctx, "Close of trusted domain failed - %s\n", nt_errstr(c.out.result));
2247 for (j=0; j < ARRAY_SIZE(levels); j++) {
2248 struct lsa_QueryTrustedDomainInfoBySid q;
2249 union lsa_TrustedDomainInfo *info = NULL;
2251 if (!domains->domains[i].sid) {
2255 q.in.handle = handle;
2256 q.in.dom_sid = domains->domains[i].sid;
2257 q.in.level = levels[j];
2260 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryTrustedDomainInfoBySid_r(b, tctx, &q),
2261 "lsa_QueryTrustedDomainInfoBySid failed");
2262 if (!NT_STATUS_IS_OK(q.out.result) && ok[j]) {
2263 torture_comment(tctx, "QueryTrustedDomainInfoBySid level %d failed - %s\n",
2264 levels[j], nt_errstr(q.out.result));
2266 } else if (NT_STATUS_IS_OK(q.out.result) && !ok[j]) {
2267 torture_comment(tctx, "QueryTrustedDomainInfoBySid level %d unexpectedly succeeded - %s\n",
2268 levels[j], nt_errstr(q.out.result));
2274 trust_by_name.in.handle = handle;
2275 trust_by_name.in.name.string = domains->domains[i].name.string;
2276 trust_by_name.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2277 trust_by_name.out.trustdom_handle = &trustdom_handle;
2279 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenTrustedDomainByName_r(b, tctx, &trust_by_name),
2280 "OpenTrustedDomainByName failed");
2282 if (!NT_STATUS_IS_OK(trust_by_name.out.result)) {
2283 torture_comment(tctx, "OpenTrustedDomainByName failed - %s\n", nt_errstr(trust_by_name.out.result));
2287 for (j=0; j < ARRAY_SIZE(levels); j++) {
2288 struct lsa_QueryTrustedDomainInfo q;
2289 union lsa_TrustedDomainInfo *info = NULL;
2290 q.in.trustdom_handle = &trustdom_handle;
2291 q.in.level = levels[j];
2293 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryTrustedDomainInfo_r(b, tctx, &q),
2294 "QueryTrustedDomainInfo failed");
2295 if (!NT_STATUS_IS_OK(q.out.result) && ok[j]) {
2296 torture_comment(tctx, "QueryTrustedDomainInfo level %d failed - %s\n",
2297 levels[j], nt_errstr(q.out.result));
2299 } else if (NT_STATUS_IS_OK(q.out.result) && !ok[j]) {
2300 torture_comment(tctx, "QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
2301 levels[j], nt_errstr(q.out.result));
2306 c.in.handle = &trustdom_handle;
2307 c.out.handle = &handle2;
2309 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_Close_r(b, tctx, &c),
2311 if (!NT_STATUS_IS_OK(c.out.result)) {
2312 torture_comment(tctx, "Close of trusted domain failed - %s\n", nt_errstr(c.out.result));
2316 for (j=0; j < ARRAY_SIZE(levels); j++) {
2317 struct lsa_QueryTrustedDomainInfoByName q;
2318 union lsa_TrustedDomainInfo *info = NULL;
2319 struct lsa_String name;
2321 name.string = domains->domains[i].name.string;
2323 q.in.handle = handle;
2324 q.in.trusted_domain = &name;
2325 q.in.level = levels[j];
2327 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryTrustedDomainInfoByName_r(b, tctx, &q),
2328 "QueryTrustedDomainInfoByName failed");
2329 if (!NT_STATUS_IS_OK(q.out.result) && ok[j]) {
2330 torture_comment(tctx, "QueryTrustedDomainInfoByName level %d failed - %s\n",
2331 levels[j], nt_errstr(q.out.result));
2333 } else if (NT_STATUS_IS_OK(q.out.result) && !ok[j]) {
2334 torture_comment(tctx, "QueryTrustedDomainInfoByName level %d unexpectedly succeeded - %s\n",
2335 levels[j], nt_errstr(q.out.result));
2343 static bool test_EnumTrustDom(struct dcerpc_binding_handle *b,
2344 struct torture_context *tctx,
2345 struct policy_handle *handle)
2347 struct lsa_EnumTrustDom r;
2348 uint32_t in_resume_handle = 0;
2349 uint32_t out_resume_handle;
2350 struct lsa_DomainList domains;
2353 torture_comment(tctx, "\nTesting EnumTrustDom\n");
2355 r.in.handle = handle;
2356 r.in.resume_handle = &in_resume_handle;
2358 r.out.domains = &domains;
2359 r.out.resume_handle = &out_resume_handle;
2361 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumTrustDom_r(b, tctx, &r),
2362 "lsa_EnumTrustDom failed");
2364 /* according to MS-LSAD 3.1.4.7.8 output resume handle MUST
2365 * always be larger than the previous input resume handle, in
2366 * particular when hitting the last query it is vital to set the
2367 * resume handle correctly to avoid infinite client loops, as
2368 * seen e.g. with Windows XP SP3 when resume handle is 0 and
2369 * status is NT_STATUS_OK - gd */
2371 if (NT_STATUS_IS_OK(r.out.result) ||
2372 NT_STATUS_EQUAL(r.out.result, NT_STATUS_NO_MORE_ENTRIES) ||
2373 NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES))
2375 if (out_resume_handle <= in_resume_handle) {
2376 torture_comment(tctx, "EnumTrustDom failed - should have returned output resume_handle (0x%08x) larger than input resume handle (0x%08x)\n",
2377 out_resume_handle, in_resume_handle);
2382 if (NT_STATUS_IS_OK(r.out.result)) {
2383 if (domains.count == 0) {
2384 torture_comment(tctx, "EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2387 } else if (!(NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES) || NT_STATUS_EQUAL(r.out.result, NT_STATUS_NO_MORE_ENTRIES))) {
2388 torture_comment(tctx, "EnumTrustDom of zero size failed - %s\n", nt_errstr(r.out.result));
2392 /* Start from the bottom again */
2393 in_resume_handle = 0;
2396 r.in.handle = handle;
2397 r.in.resume_handle = &in_resume_handle;
2398 r.in.max_size = LSA_ENUM_TRUST_DOMAIN_MULTIPLIER * 3;
2399 r.out.domains = &domains;
2400 r.out.resume_handle = &out_resume_handle;
2402 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumTrustDom_r(b, tctx, &r),
2403 "EnumTrustDom failed");
2405 /* according to MS-LSAD 3.1.4.7.8 output resume handle MUST
2406 * always be larger than the previous input resume handle, in
2407 * particular when hitting the last query it is vital to set the
2408 * resume handle correctly to avoid infinite client loops, as
2409 * seen e.g. with Windows XP SP3 when resume handle is 0 and
2410 * status is NT_STATUS_OK - gd */
2412 if (NT_STATUS_IS_OK(r.out.result) ||
2413 NT_STATUS_EQUAL(r.out.result, NT_STATUS_NO_MORE_ENTRIES) ||
2414 NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES))
2416 if (out_resume_handle <= in_resume_handle) {
2417 torture_comment(tctx, "EnumTrustDom failed - should have returned output resume_handle (0x%08x) larger than input resume handle (0x%08x)\n",
2418 out_resume_handle, in_resume_handle);
2423 /* NO_MORE_ENTRIES is allowed */
2424 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_NO_MORE_ENTRIES)) {
2425 if (domains.count == 0) {
2428 torture_comment(tctx, "EnumTrustDom failed - should have returned 0 trusted domains with 'NT_STATUS_NO_MORE_ENTRIES'\n");
2430 } else if (NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES)) {
2431 /* Windows 2003 gets this off by one on the first run */
2432 if (r.out.domains->count < 3 || r.out.domains->count > 4) {
2433 torture_comment(tctx, "EnumTrustDom didn't fill the buffer we "
2434 "asked it to (got %d, expected %d / %d == %d entries)\n",
2435 r.out.domains->count, LSA_ENUM_TRUST_DOMAIN_MULTIPLIER * 3,
2436 LSA_ENUM_TRUST_DOMAIN_MULTIPLIER, r.in.max_size);
2439 } else if (!NT_STATUS_IS_OK(r.out.result)) {
2440 torture_comment(tctx, "EnumTrustDom failed - %s\n", nt_errstr(r.out.result));
2444 if (domains.count == 0) {
2445 torture_comment(tctx, "EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2449 ret &= test_query_each_TrustDom(b, tctx, handle, &domains);
2451 in_resume_handle = out_resume_handle;
2453 } while ((NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES)));
2458 static bool test_EnumTrustDomEx(struct dcerpc_binding_handle *b,
2459 struct torture_context *tctx,
2460 struct policy_handle *handle)
2462 struct lsa_EnumTrustedDomainsEx r_ex;
2463 uint32_t resume_handle = 0;
2464 struct lsa_DomainListEx domains_ex;
2467 torture_comment(tctx, "\nTesting EnumTrustedDomainsEx\n");
2469 r_ex.in.handle = handle;
2470 r_ex.in.resume_handle = &resume_handle;
2471 r_ex.in.max_size = LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER * 3;
2472 r_ex.out.domains = &domains_ex;
2473 r_ex.out.resume_handle = &resume_handle;
2475 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumTrustedDomainsEx_r(b, tctx, &r_ex),
2476 "EnumTrustedDomainsEx failed");
2478 if (!(NT_STATUS_EQUAL(r_ex.out.result, STATUS_MORE_ENTRIES) || NT_STATUS_EQUAL(r_ex.out.result, NT_STATUS_NO_MORE_ENTRIES))) {
2479 torture_comment(tctx, "EnumTrustedDomainEx of zero size failed - %s\n", nt_errstr(r_ex.out.result));
2485 r_ex.in.handle = handle;
2486 r_ex.in.resume_handle = &resume_handle;
2487 r_ex.in.max_size = LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER * 3;
2488 r_ex.out.domains = &domains_ex;
2489 r_ex.out.resume_handle = &resume_handle;
2491 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumTrustedDomainsEx_r(b, tctx, &r_ex),
2492 "EnumTrustedDomainsEx failed");
2494 /* NO_MORE_ENTRIES is allowed */
2495 if (NT_STATUS_EQUAL(r_ex.out.result, NT_STATUS_NO_MORE_ENTRIES)) {
2496 if (domains_ex.count == 0) {
2499 torture_comment(tctx, "EnumTrustDomainsEx failed - should have returned 0 trusted domains with 'NT_STATUS_NO_MORE_ENTRIES'\n");
2501 } else if (NT_STATUS_EQUAL(r_ex.out.result, STATUS_MORE_ENTRIES)) {
2502 /* Windows 2003 gets this off by one on the first run */
2503 if (r_ex.out.domains->count < 3 || r_ex.out.domains->count > 4) {
2504 torture_comment(tctx, "EnumTrustDom didn't fill the buffer we "
2505 "asked it to (got %d, expected %d / %d == %d entries)\n",
2506 r_ex.out.domains->count,
2508 LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER,
2509 r_ex.in.max_size / LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER);
2511 } else if (!NT_STATUS_IS_OK(r_ex.out.result)) {
2512 torture_comment(tctx, "EnumTrustedDomainEx failed - %s\n", nt_errstr(r_ex.out.result));
2516 if (domains_ex.count == 0) {
2517 torture_comment(tctx, "EnumTrustDomainEx failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2521 ret &= test_query_each_TrustDomEx(b, tctx, handle, &domains_ex);
2523 } while ((NT_STATUS_EQUAL(r_ex.out.result, STATUS_MORE_ENTRIES)));
2529 static bool test_CreateTrustedDomain(struct dcerpc_binding_handle *b,
2530 struct torture_context *tctx,
2531 struct policy_handle *handle,
2532 uint32_t num_trusts)
2535 struct lsa_CreateTrustedDomain r;
2536 struct lsa_DomainInfo trustinfo;
2537 struct dom_sid **domsid;
2538 struct policy_handle *trustdom_handle;
2539 struct lsa_QueryTrustedDomainInfo q;
2540 union lsa_TrustedDomainInfo *info = NULL;
2543 torture_comment(tctx, "\nTesting CreateTrustedDomain for %d domains\n", num_trusts);
2545 if (!test_EnumTrustDom(b, tctx, handle)) {
2549 if (!test_EnumTrustDomEx(b, tctx, handle)) {
2553 domsid = talloc_array(tctx, struct dom_sid *, num_trusts);
2554 trustdom_handle = talloc_array(tctx, struct policy_handle, num_trusts);
2556 for (i=0; i< num_trusts; i++) {
2557 char *trust_name = talloc_asprintf(tctx, "torturedom%02d", i);
2558 char *trust_sid = talloc_asprintf(tctx, "S-1-5-21-97398-379795-100%02d", i);
2560 domsid[i] = dom_sid_parse_talloc(tctx, trust_sid);
2562 trustinfo.sid = domsid[i];
2563 init_lsa_String((struct lsa_String *)&trustinfo.name, trust_name);
2565 r.in.policy_handle = handle;
2566 r.in.info = &trustinfo;
2567 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2568 r.out.trustdom_handle = &trustdom_handle[i];
2570 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_CreateTrustedDomain_r(b, tctx, &r),
2571 "CreateTrustedDomain failed");
2572 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_OBJECT_NAME_COLLISION)) {
2573 test_DeleteTrustedDomain(b, tctx, handle, trustinfo.name);
2574 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_CreateTrustedDomain_r(b, tctx, &r),
2575 "CreateTrustedDomain failed");
2577 if (!NT_STATUS_IS_OK(r.out.result)) {
2578 torture_comment(tctx, "CreateTrustedDomain failed - %s\n", nt_errstr(r.out.result));
2582 q.in.trustdom_handle = &trustdom_handle[i];
2583 q.in.level = LSA_TRUSTED_DOMAIN_INFO_INFO_EX;
2585 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryTrustedDomainInfo_r(b, tctx, &q),
2586 "QueryTrustedDomainInfo failed");
2587 if (!NT_STATUS_IS_OK(q.out.result)) {
2588 torture_comment(tctx, "QueryTrustedDomainInfo level %d failed - %s\n", q.in.level, nt_errstr(q.out.result));
2590 } else if (!q.out.info) {
2593 if (strcmp(info->info_ex.netbios_name.string, trustinfo.name.string) != 0) {
2594 torture_comment(tctx, "QueryTrustedDomainInfo returned inconsistent short name: %s != %s\n",
2595 info->info_ex.netbios_name.string, trustinfo.name.string);
2598 if (info->info_ex.trust_type != LSA_TRUST_TYPE_DOWNLEVEL) {
2599 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
2600 trust_name, info->info_ex.trust_type, LSA_TRUST_TYPE_DOWNLEVEL);
2603 if (info->info_ex.trust_attributes != 0) {
2604 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
2605 trust_name, info->info_ex.trust_attributes, 0);
2608 if (info->info_ex.trust_direction != LSA_TRUST_DIRECTION_OUTBOUND) {
2609 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
2610 trust_name, info->info_ex.trust_direction, LSA_TRUST_DIRECTION_OUTBOUND);
2617 /* now that we have some domains to look over, we can test the enum calls */
2618 if (!test_EnumTrustDom(b, tctx, handle)) {
2622 if (!test_EnumTrustDomEx(b, tctx, handle)) {
2626 for (i=0; i<num_trusts; i++) {
2627 if (!test_DeleteTrustedDomainBySid(b, tctx, handle, domsid[i])) {
2635 static bool gen_authinfo_internal(TALLOC_CTX *mem_ctx, const char *password,
2636 DATA_BLOB session_key,
2637 struct lsa_TrustDomainInfoAuthInfoInternal **_authinfo_internal)
2639 struct lsa_TrustDomainInfoAuthInfoInternal *authinfo_internal;
2640 struct trustDomainPasswords auth_struct;
2641 struct AuthenticationInformation *auth_info_array;
2642 size_t converted_size;
2643 DATA_BLOB auth_blob;
2644 enum ndr_err_code ndr_err;
2646 authinfo_internal = talloc_zero(mem_ctx, struct lsa_TrustDomainInfoAuthInfoInternal);
2647 if (authinfo_internal == NULL) {
2651 auth_info_array = talloc_array(mem_ctx,
2652 struct AuthenticationInformation, 1);
2653 if (auth_info_array == NULL) {
2657 generate_random_buffer(auth_struct.confounder, sizeof(auth_struct.confounder));
2659 auth_info_array[0].AuthType = TRUST_AUTH_TYPE_CLEAR;
2661 if (!convert_string_talloc(mem_ctx, CH_UNIX, CH_UTF16, password,
2663 &auth_info_array[0].AuthInfo.clear.password,
2668 auth_info_array[0].AuthInfo.clear.size = converted_size;
2670 auth_struct.outgoing.count = 1;
2671 auth_struct.outgoing.current.count = 1;
2672 auth_struct.outgoing.current.array = auth_info_array;
2673 auth_struct.outgoing.previous.count = 0;
2674 auth_struct.outgoing.previous.array = NULL;
2676 auth_struct.incoming.count = 1;
2677 auth_struct.incoming.current.count = 1;
2678 auth_struct.incoming.current.array = auth_info_array;
2679 auth_struct.incoming.previous.count = 0;
2680 auth_struct.incoming.previous.array = NULL;
2683 ndr_err = ndr_push_struct_blob(&auth_blob, mem_ctx, &auth_struct,
2684 (ndr_push_flags_fn_t)ndr_push_trustDomainPasswords);
2685 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2689 arcfour_crypt_blob(auth_blob.data, auth_blob.length, &session_key);
2691 authinfo_internal->auth_blob.size = auth_blob.length;
2692 authinfo_internal->auth_blob.data = auth_blob.data;
2694 *_authinfo_internal = authinfo_internal;
2699 static bool gen_authinfo(TALLOC_CTX *mem_ctx, const char *password,
2700 struct lsa_TrustDomainInfoAuthInfo **_authinfo)
2702 struct lsa_TrustDomainInfoAuthInfo *authinfo;
2703 struct lsa_TrustDomainInfoBuffer *info_buffer;
2704 size_t converted_size;
2706 authinfo = talloc_zero(mem_ctx, struct lsa_TrustDomainInfoAuthInfo);
2707 if (authinfo == NULL) {
2711 info_buffer = talloc_zero(mem_ctx, struct lsa_TrustDomainInfoBuffer);
2712 if (info_buffer == NULL) {
2716 info_buffer->AuthType = TRUST_AUTH_TYPE_CLEAR;
2718 if (!convert_string_talloc(mem_ctx, CH_UNIX, CH_UTF16, password,
2720 &info_buffer->data.data,
2725 info_buffer->data.size = converted_size;
2727 authinfo->incoming_count = 1;
2728 authinfo->incoming_current_auth_info = info_buffer;
2729 authinfo->incoming_previous_auth_info = NULL;
2730 authinfo->outgoing_count = 1;
2731 authinfo->outgoing_current_auth_info = info_buffer;
2732 authinfo->outgoing_previous_auth_info = NULL;
2734 *_authinfo = authinfo;
2739 static bool check_pw_with_ServerAuthenticate3(struct dcerpc_pipe *p,
2740 struct torture_context *tctx,
2741 uint32_t negotiate_flags,
2742 struct cli_credentials *machine_credentials,
2743 struct netlogon_creds_CredentialState **creds_out)
2745 struct netr_ServerReqChallenge r;
2746 struct netr_ServerAuthenticate3 a;
2747 struct netr_Credential credentials1, credentials2, credentials3;
2748 struct netlogon_creds_CredentialState *creds;
2749 struct samr_Password mach_password;
2751 const char *machine_name;
2752 const char *plain_pass;
2753 struct dcerpc_binding_handle *b = p->binding_handle;
2755 machine_name = cli_credentials_get_workstation(machine_credentials);
2756 plain_pass = cli_credentials_get_password(machine_credentials);
2758 r.in.server_name = NULL;
2759 r.in.computer_name = machine_name;
2760 r.in.credentials = &credentials1;
2761 r.out.return_credentials = &credentials2;
2763 generate_random_buffer(credentials1.data, sizeof(credentials1.data));
2765 torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerReqChallenge_r(b, tctx, &r),
2766 "ServerReqChallenge failed");
2767 torture_assert_ntstatus_ok(tctx, r.out.result, "ServerReqChallenge failed");
2769 E_md4hash(plain_pass, mach_password.hash);
2771 a.in.server_name = NULL;
2772 a.in.account_name = talloc_asprintf(tctx, "%s$", machine_name);
2773 a.in.secure_channel_type = cli_credentials_get_secure_channel_type(machine_credentials);
2774 a.in.computer_name = machine_name;
2775 a.in.negotiate_flags = &negotiate_flags;
2776 a.in.credentials = &credentials3;
2777 a.out.return_credentials = &credentials3;
2778 a.out.negotiate_flags = &negotiate_flags;
2781 creds = netlogon_creds_client_init(tctx, a.in.account_name,
2783 &credentials1, &credentials2,
2784 &mach_password, &credentials3,
2787 torture_assert(tctx, creds != NULL, "memory allocation");
2789 torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerAuthenticate3_r(b, tctx, &a),
2790 "ServerAuthenticate3 failed");
2791 if (!NT_STATUS_IS_OK(a.out.result)) {
2792 if (!NT_STATUS_EQUAL(a.out.result, NT_STATUS_ACCESS_DENIED)) {
2793 torture_assert_ntstatus_ok(tctx, a.out.result,
2794 "ServerAuthenticate3 failed");
2798 torture_assert(tctx, netlogon_creds_client_check(creds, &credentials3), "Credential chaining failed");
2800 /* Prove that requesting a challenge again won't break it */
2801 torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerReqChallenge_r(b, tctx, &r),
2802 "ServerReqChallenge failed");
2803 torture_assert_ntstatus_ok(tctx, r.out.result, "ServerReqChallenge failed");
2809 static bool check_dom_trust_pw(struct dcerpc_pipe *p,
2810 struct torture_context *tctx,
2811 const char *trusted_dom_name,
2812 const char *password)
2814 struct cli_credentials *credentials;
2816 struct netlogon_creds_CredentialState *creds;
2817 struct dcerpc_pipe *pipe;
2821 credentials = cli_credentials_init(tctx);
2822 if (credentials == NULL) {
2826 dummy = talloc_asprintf(tctx, "%s$", trusted_dom_name);
2827 if (dummy == NULL) {
2831 cli_credentials_set_username(credentials, dummy, CRED_SPECIFIED);
2832 cli_credentials_set_password(credentials, password, CRED_SPECIFIED);
2833 cli_credentials_set_workstation(credentials,
2834 trusted_dom_name, CRED_SPECIFIED);
2835 cli_credentials_set_secure_channel_type(credentials, SEC_CHAN_DOMAIN);
2837 status = dcerpc_pipe_connect_b(tctx, &pipe, p->binding,
2838 &ndr_table_netlogon,
2839 cli_credentials_init_anon(tctx),
2840 tctx->ev, tctx->lp_ctx);
2841 if (!NT_STATUS_IS_OK(status)) {
2842 torture_comment(tctx, "dcerpc_pipe_connect_b failed.\n");
2846 ok = check_pw_with_ServerAuthenticate3(pipe, tctx,
2847 NETLOGON_NEG_AUTH2_ADS_FLAGS,
2848 credentials, &creds);
2854 static bool test_CreateTrustedDomainEx_common(struct dcerpc_pipe *p,
2855 struct torture_context *tctx,
2856 struct policy_handle *handle,
2857 uint32_t num_trusts,
2862 struct lsa_CreateTrustedDomainEx r;
2863 struct lsa_CreateTrustedDomainEx2 r2;
2864 struct lsa_TrustDomainInfoInfoEx trustinfo;
2865 struct lsa_TrustDomainInfoAuthInfoInternal *authinfo_internal;
2866 struct lsa_TrustDomainInfoAuthInfo *authinfo;
2867 struct dom_sid **domsid;
2868 struct policy_handle *trustdom_handle;
2869 struct lsa_QueryTrustedDomainInfo q;
2870 union lsa_TrustedDomainInfo *info = NULL;
2871 DATA_BLOB session_key;
2873 struct dcerpc_binding_handle *b = p->binding_handle;
2876 torture_comment(tctx, "\nTesting CreateTrustedDomainEx2 for %d domains\n", num_trusts);
2878 torture_comment(tctx, "\nTesting CreateTrustedDomainEx for %d domains\n", num_trusts);
2881 domsid = talloc_array(tctx, struct dom_sid *, num_trusts);
2882 trustdom_handle = talloc_array(tctx, struct policy_handle, num_trusts);
2884 status = dcerpc_fetch_session_key(p, &session_key);
2885 if (!NT_STATUS_IS_OK(status)) {
2886 torture_comment(tctx, "dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
2890 for (i=0; i< num_trusts; i++) {
2891 char *trust_name = talloc_asprintf(tctx, "torturedom%02d", i);
2892 char *trust_name_dns = talloc_asprintf(tctx, "torturedom%02d.samba.example.com", i);
2893 char *trust_sid = talloc_asprintf(tctx, "S-1-5-21-97398-379795-100%02d", i);
2895 domsid[i] = dom_sid_parse_talloc(tctx, trust_sid);
2897 trustinfo.sid = domsid[i];
2898 trustinfo.netbios_name.string = trust_name;
2899 trustinfo.domain_name.string = trust_name_dns;
2901 /* Create inbound, some outbound, and some
2902 * bi-directional trusts in a repeating pattern based
2905 /* 1 == inbound, 2 == outbound, 3 == both */
2906 trustinfo.trust_direction = (i % 3) + 1;
2908 /* Try different trust types too */
2910 /* 1 == downlevel (NT4), 2 == uplevel (ADS), 3 == MIT (kerberos but not AD) */
2911 trustinfo.trust_type = (((i / 3) + 1) % 3) + 1;
2913 trustinfo.trust_attributes = LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION;
2915 if (!gen_authinfo_internal(tctx, TRUSTPW, session_key, &authinfo_internal)) {
2916 torture_comment(tctx, "gen_authinfo_internal failed");
2920 if (!gen_authinfo(tctx, TRUSTPW, &authinfo)) {
2921 torture_comment(tctx, "gen_authinfonfo failed");
2927 r2.in.policy_handle = handle;
2928 r2.in.info = &trustinfo;
2929 r2.in.auth_info_internal = authinfo_internal;
2930 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2931 r2.out.trustdom_handle = &trustdom_handle[i];
2933 torture_assert_ntstatus_ok(tctx,
2934 dcerpc_lsa_CreateTrustedDomainEx2_r(b, tctx, &r2),
2935 "CreateTrustedDomainEx2 failed");
2937 status = r2.out.result;
2940 r.in.policy_handle = handle;
2941 r.in.info = &trustinfo;
2942 r.in.auth_info = authinfo;
2943 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2944 r.out.trustdom_handle = &trustdom_handle[i];
2946 torture_assert_ntstatus_ok(tctx,
2947 dcerpc_lsa_CreateTrustedDomainEx_r(b, tctx, &r),
2948 "CreateTrustedDomainEx failed");
2950 status = r.out.result;
2953 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
2954 test_DeleteTrustedDomain(b, tctx, handle, trustinfo.netbios_name);
2956 torture_assert_ntstatus_ok(tctx,
2957 dcerpc_lsa_CreateTrustedDomainEx2_r(b, tctx, &r2),
2958 "CreateTrustedDomainEx2 failed");
2959 status = r2.out.result;
2961 torture_assert_ntstatus_ok(tctx,
2962 dcerpc_lsa_CreateTrustedDomainEx_r(b, tctx, &r),
2963 "CreateTrustedDomainEx2 failed");
2964 status = r.out.result;
2967 if (!NT_STATUS_IS_OK(status)) {
2968 torture_comment(tctx, "CreateTrustedDomainEx failed2 - %s\n", nt_errstr(status));
2971 /* For outbound and MIT trusts there is no trust account */
2972 if (trustinfo.trust_direction != 2 &&
2973 trustinfo.trust_type != 3) {
2975 if (torture_setting_bool(tctx, "samba3", false) ||
2976 torture_setting_bool(tctx, "samba4", false)) {
2977 torture_comment(tctx, "skipping trusted domain auth tests against samba");
2979 if (check_dom_trust_pw(p, tctx, trust_name,
2981 torture_comment(tctx, "Password check passed unexpectedly\n");
2984 if (!check_dom_trust_pw(p, tctx, trust_name,
2986 torture_comment(tctx, "Password check failed\n");
2992 q.in.trustdom_handle = &trustdom_handle[i];
2993 q.in.level = LSA_TRUSTED_DOMAIN_INFO_INFO_EX;
2995 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryTrustedDomainInfo_r(b, tctx, &q),
2996 "QueryTrustedDomainInfo failed");
2997 if (!NT_STATUS_IS_OK(q.out.result)) {
2998 torture_comment(tctx, "QueryTrustedDomainInfo level 1 failed - %s\n", nt_errstr(q.out.result));
3000 } else if (!q.out.info) {
3001 torture_comment(tctx, "QueryTrustedDomainInfo level 1 failed to return an info pointer\n");
3004 if (strcmp(info->info_ex.netbios_name.string, trustinfo.netbios_name.string) != 0) {
3005 torture_comment(tctx, "QueryTrustedDomainInfo returned inconsistent short name: %s != %s\n",
3006 info->info_ex.netbios_name.string, trustinfo.netbios_name.string);
3009 if (info->info_ex.trust_type != trustinfo.trust_type) {
3010 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
3011 trust_name, info->info_ex.trust_type, trustinfo.trust_type);
3014 if (info->info_ex.trust_attributes != LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION) {
3015 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
3016 trust_name, info->info_ex.trust_attributes, LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION);
3019 if (info->info_ex.trust_direction != trustinfo.trust_direction) {
3020 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
3021 trust_name, info->info_ex.trust_direction, trustinfo.trust_direction);
3028 /* now that we have some domains to look over, we can test the enum calls */
3029 if (!test_EnumTrustDom(b, tctx, handle)) {
3030 torture_comment(tctx, "test_EnumTrustDom failed\n");
3034 if (!test_EnumTrustDomEx(b, tctx, handle)) {
3035 torture_comment(tctx, "test_EnumTrustDomEx failed\n");
3039 for (i=0; i<num_trusts; i++) {
3040 if (!test_DeleteTrustedDomainBySid(b, tctx, handle, domsid[i])) {
3041 torture_comment(tctx, "test_DeleteTrustedDomainBySid failed\n");
3049 static bool test_CreateTrustedDomainEx2(struct dcerpc_pipe *p,
3050 struct torture_context *tctx,
3051 struct policy_handle *handle,
3052 uint32_t num_trusts)
3054 return test_CreateTrustedDomainEx_common(p, tctx, handle, num_trusts, true);
3057 static bool test_CreateTrustedDomainEx(struct dcerpc_pipe *p,
3058 struct torture_context *tctx,
3059 struct policy_handle *handle,
3060 uint32_t num_trusts)
3062 return test_CreateTrustedDomainEx_common(p, tctx, handle, num_trusts, false);
3065 static bool test_QueryDomainInfoPolicy(struct dcerpc_binding_handle *b,
3066 struct torture_context *tctx,
3067 struct policy_handle *handle)
3069 struct lsa_QueryDomainInformationPolicy r;
3070 union lsa_DomainInformationPolicy *info = NULL;
3074 if (torture_setting_bool(tctx, "samba3", false)) {
3075 torture_skip(tctx, "skipping QueryDomainInformationPolicy test\n");
3078 torture_comment(tctx, "\nTesting QueryDomainInformationPolicy\n");
3081 r.in.handle = handle;
3085 torture_comment(tctx, "\nTrying QueryDomainInformationPolicy level %d\n", i);
3087 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryDomainInformationPolicy_r(b, tctx, &r),
3088 "QueryDomainInformationPolicy failed");
3090 /* If the server does not support EFS, then this is the correct return */
3091 if (i == LSA_DOMAIN_INFO_POLICY_EFS && NT_STATUS_EQUAL(r.out.result, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
3093 } else if (!NT_STATUS_IS_OK(r.out.result)) {
3094 torture_comment(tctx, "QueryDomainInformationPolicy failed - %s\n", nt_errstr(r.out.result));
3104 static bool test_QueryInfoPolicyCalls( bool version2,
3105 struct dcerpc_binding_handle *b,
3106 struct torture_context *tctx,
3107 struct policy_handle *handle)
3109 struct lsa_QueryInfoPolicy r;
3110 union lsa_PolicyInformation *info = NULL;
3113 const char *call = talloc_asprintf(tctx, "QueryInfoPolicy%s", version2 ? "2":"");
3115 torture_comment(tctx, "\nTesting %s\n", call);
3117 if (version2 && torture_setting_bool(tctx, "samba3", false)) {
3118 torture_skip(tctx, "skipping QueryInfoPolicy2 tests\n");
3121 for (i=1;i<=14;i++) {
3122 r.in.handle = handle;
3126 torture_comment(tctx, "\nTrying %s level %d\n", call, i);
3129 /* We can perform the cast, because both types are
3130 structurally equal */
3131 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryInfoPolicy2_r(b, tctx,
3132 (struct lsa_QueryInfoPolicy2*) &r),
3133 "QueryInfoPolicy2 failed");
3135 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryInfoPolicy_r(b, tctx, &r),
3136 "QueryInfoPolicy2 failed");
3139 case LSA_POLICY_INFO_MOD:
3140 case LSA_POLICY_INFO_AUDIT_FULL_SET:
3141 case LSA_POLICY_INFO_AUDIT_FULL_QUERY:
3142 if (!NT_STATUS_EQUAL(r.out.result, NT_STATUS_INVALID_PARAMETER)) {
3143 torture_comment(tctx, "Server should have failed level %u: %s\n", i, nt_errstr(r.out.result));
3147 case LSA_POLICY_INFO_DOMAIN:
3148 case LSA_POLICY_INFO_ACCOUNT_DOMAIN:
3149 case LSA_POLICY_INFO_REPLICA:
3150 case LSA_POLICY_INFO_QUOTA:
3151 case LSA_POLICY_INFO_ROLE:
3152 case LSA_POLICY_INFO_AUDIT_LOG:
3153 case LSA_POLICY_INFO_AUDIT_EVENTS:
3154 case LSA_POLICY_INFO_PD:
3155 if (!NT_STATUS_IS_OK(r.out.result)) {
3156 torture_comment(tctx, "%s failed - %s\n", call, nt_errstr(r.out.result));
3160 case LSA_POLICY_INFO_L_ACCOUNT_DOMAIN:
3161 case LSA_POLICY_INFO_DNS_INT:
3162 case LSA_POLICY_INFO_DNS:
3163 if (torture_setting_bool(tctx, "samba3", false)) {
3164 /* Other levels not implemented yet */
3165 if (!NT_STATUS_EQUAL(r.out.result, NT_STATUS_INVALID_INFO_CLASS)) {
3166 torture_comment(tctx, "%s failed - %s\n", call, nt_errstr(r.out.result));
3169 } else if (!NT_STATUS_IS_OK(r.out.result)) {
3170 torture_comment(tctx, "%s failed - %s\n", call, nt_errstr(r.out.result));
3175 if (torture_setting_bool(tctx, "samba4", false)) {
3176 /* Other levels not implemented yet */
3177 if (!NT_STATUS_EQUAL(r.out.result, NT_STATUS_INVALID_INFO_CLASS)) {
3178 torture_comment(tctx, "%s failed - %s\n", call, nt_errstr(r.out.result));
3181 } else if (!NT_STATUS_IS_OK(r.out.result)) {
3182 torture_comment(tctx, "%s failed - %s\n", call, nt_errstr(r.out.result));
3188 if (NT_STATUS_IS_OK(r.out.result) && (i == LSA_POLICY_INFO_DNS
3189 || i == LSA_POLICY_INFO_DNS_INT)) {
3190 /* Let's look up some of these names */
3192 struct lsa_TransNameArray tnames;
3194 tnames.names = talloc_zero_array(tctx, struct lsa_TranslatedName, tnames.count);
3195 tnames.names[0].name.string = info->dns.name.string;
3196 tnames.names[0].sid_type = SID_NAME_DOMAIN;
3197 tnames.names[1].name.string = info->dns.dns_domain.string;
3198 tnames.names[1].sid_type = SID_NAME_DOMAIN;
3199 tnames.names[2].name.string = talloc_asprintf(tctx, "%s\\", info->dns.name.string);
3200 tnames.names[2].sid_type = SID_NAME_DOMAIN;
3201 tnames.names[3].name.string = talloc_asprintf(tctx, "%s\\", info->dns.dns_domain.string);
3202 tnames.names[3].sid_type = SID_NAME_DOMAIN;
3203 tnames.names[4].name.string = talloc_asprintf(tctx, "%s\\guest", info->dns.name.string);
3204 tnames.names[4].sid_type = SID_NAME_USER;
3205 tnames.names[5].name.string = talloc_asprintf(tctx, "%s\\krbtgt", info->dns.name.string);
3206 tnames.names[5].sid_type = SID_NAME_USER;
3207 tnames.names[6].name.string = talloc_asprintf(tctx, "%s\\guest", info->dns.dns_domain.string);
3208 tnames.names[6].sid_type = SID_NAME_USER;
3209 tnames.names[7].name.string = talloc_asprintf(tctx, "%s\\krbtgt", info->dns.dns_domain.string);
3210 tnames.names[7].sid_type = SID_NAME_USER;
3211 tnames.names[8].name.string = talloc_asprintf(tctx, "krbtgt@%s", info->dns.name.string);
3212 tnames.names[8].sid_type = SID_NAME_USER;
3213 tnames.names[9].name.string = talloc_asprintf(tctx, "krbtgt@%s", info->dns.dns_domain.string);
3214 tnames.names[9].sid_type = SID_NAME_USER;
3215 tnames.names[10].name.string = talloc_asprintf(tctx, "%s\\"TEST_MACHINENAME "$", info->dns.name.string);
3216 tnames.names[10].sid_type = SID_NAME_USER;
3217 tnames.names[11].name.string = talloc_asprintf(tctx, "%s\\"TEST_MACHINENAME "$", info->dns.dns_domain.string);
3218 tnames.names[11].sid_type = SID_NAME_USER;
3219 tnames.names[12].name.string = talloc_asprintf(tctx, TEST_MACHINENAME "$@%s", info->dns.name.string);
3220 tnames.names[12].sid_type = SID_NAME_USER;
3221 tnames.names[13].name.string = talloc_asprintf(tctx, TEST_MACHINENAME "$@%s", info->dns.dns_domain.string);
3222 tnames.names[13].sid_type = SID_NAME_USER;
3223 ret &= test_LookupNames(b, tctx, handle, &tnames);
3231 static bool test_QueryInfoPolicy(struct dcerpc_binding_handle *b,
3232 struct torture_context *tctx,
3233 struct policy_handle *handle)
3235 return test_QueryInfoPolicyCalls(false, b, tctx, handle);
3238 static bool test_QueryInfoPolicy2(struct dcerpc_binding_handle *b,
3239 struct torture_context *tctx,
3240 struct policy_handle *handle)
3242 return test_QueryInfoPolicyCalls(true, b, tctx, handle);
3245 static bool test_GetUserName(struct dcerpc_binding_handle *b,
3246 struct torture_context *tctx)
3248 struct lsa_GetUserName r;
3250 struct lsa_String *authority_name_p = NULL;
3251 struct lsa_String *account_name_p = NULL;
3253 torture_comment(tctx, "\nTesting GetUserName\n");
3255 r.in.system_name = "\\";
3256 r.in.account_name = &account_name_p;
3257 r.in.authority_name = NULL;
3258 r.out.account_name = &account_name_p;
3260 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_GetUserName_r(b, tctx, &r),
3261 "GetUserName failed");
3263 if (!NT_STATUS_IS_OK(r.out.result)) {
3264 torture_comment(tctx, "GetUserName failed - %s\n", nt_errstr(r.out.result));
3268 account_name_p = NULL;
3269 r.in.account_name = &account_name_p;
3270 r.in.authority_name = &authority_name_p;
3271 r.out.account_name = &account_name_p;
3273 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_GetUserName_r(b, tctx, &r),
3274 "GetUserName failed");
3276 if (!NT_STATUS_IS_OK(r.out.result)) {
3277 torture_comment(tctx, "GetUserName failed - %s\n", nt_errstr(r.out.result));
3284 static bool test_GetUserName_fail(struct dcerpc_binding_handle *b,
3285 struct torture_context *tctx)
3287 struct lsa_GetUserName r;
3288 struct lsa_String *account_name_p = NULL;
3291 torture_comment(tctx, "\nTesting GetUserName_fail\n");
3293 r.in.system_name = "\\";
3294 r.in.account_name = &account_name_p;
3295 r.in.authority_name = NULL;
3296 r.out.account_name = &account_name_p;
3298 status = dcerpc_lsa_GetUserName_r(b, tctx, &r);
3299 if (!NT_STATUS_IS_OK(status)) {
3300 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
3301 torture_comment(tctx,
3302 "GetUserName correctly returned with "
3308 torture_assert_ntstatus_equal(tctx,
3310 NT_STATUS_ACCESS_DENIED,
3311 "GetUserName return value should "
3312 "be ACCESS_DENIED");
3316 if (!NT_STATUS_IS_OK(r.out.result)) {
3317 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_ACCESS_DENIED) ||
3318 NT_STATUS_EQUAL(r.out.result, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
3319 torture_comment(tctx,
3320 "GetUserName correctly returned with "
3322 nt_errstr(r.out.result));
3327 torture_assert_ntstatus_equal(tctx,
3330 "GetUserName return value should be "
3336 bool test_lsa_Close(struct dcerpc_binding_handle *b,
3337 struct torture_context *tctx,
3338 struct policy_handle *handle)
3341 struct policy_handle handle2;
3343 torture_comment(tctx, "\nTesting Close\n");
3345 r.in.handle = handle;
3346 r.out.handle = &handle2;
3348 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_Close_r(b, tctx, &r),
3350 if (!NT_STATUS_IS_OK(r.out.result)) {
3351 torture_comment(tctx, "Close failed - %s\n",
3352 nt_errstr(r.out.result));
3356 torture_assert_ntstatus_equal(tctx, dcerpc_lsa_Close_r(b, tctx, &r),
3357 NT_STATUS_RPC_SS_CONTEXT_MISMATCH, "Close should failed");
3359 torture_comment(tctx, "\n");
3364 bool torture_rpc_lsa(struct torture_context *tctx)
3367 struct dcerpc_pipe *p;
3369 struct policy_handle *handle = NULL;
3370 struct test_join *join = NULL;
3371 struct cli_credentials *machine_creds;
3372 struct dcerpc_binding_handle *b;
3374 status = torture_rpc_connection(tctx, &p, &ndr_table_lsarpc);
3375 if (!NT_STATUS_IS_OK(status)) {
3378 b = p->binding_handle;
3380 /* Test lsaLookupSids3 and lsaLookupNames4 over tcpip */
3381 if (p->binding->transport == NCACN_IP_TCP) {
3382 if (!test_OpenPolicy_fail(b, tctx)) {
3386 if (!test_OpenPolicy2_fail(b, tctx)) {
3390 if (!test_many_LookupSids(p, tctx, handle)) {
3397 if (!test_OpenPolicy(b, tctx)) {
3401 if (!test_lsa_OpenPolicy2(b, tctx, &handle)) {
3406 join = torture_join_domain(tctx, TEST_MACHINENAME, ACB_WSTRUST, &machine_creds);
3411 if (!test_LookupSids_async(b, tctx, handle)) {
3415 if (!test_QueryDomainInfoPolicy(b, tctx, handle)) {
3419 if (!test_CreateSecret(p, tctx, handle)) {
3423 if (!test_QueryInfoPolicy(b, tctx, handle)) {
3427 if (!test_QueryInfoPolicy2(b, tctx, handle)) {
3431 if (!test_Delete(b, tctx, handle)) {
3435 if (!test_many_LookupSids(p, tctx, handle)) {
3439 if (!test_lsa_Close(b, tctx, handle)) {
3443 torture_leave_domain(tctx, join);
3446 if (!test_many_LookupSids(p, tctx, handle)) {
3451 if (!test_GetUserName(b, tctx)) {
3458 bool torture_rpc_lsa_get_user(struct torture_context *tctx)
3461 struct dcerpc_pipe *p;
3463 struct dcerpc_binding_handle *b;
3465 status = torture_rpc_connection(tctx, &p, &ndr_table_lsarpc);
3466 if (!NT_STATUS_IS_OK(status)) {
3469 b = p->binding_handle;
3471 if (p->binding->transport == NCACN_IP_TCP) {
3472 if (!test_GetUserName_fail(b, tctx)) {
3478 if (!test_GetUserName(b, tctx)) {
3485 static bool testcase_LookupNames(struct torture_context *tctx,
3486 struct dcerpc_pipe *p)
3489 struct policy_handle *handle;
3490 struct lsa_TransNameArray tnames;
3491 struct lsa_TransNameArray2 tnames2;
3492 struct dcerpc_binding_handle *b = p->binding_handle;
3494 if (p->binding->transport != NCACN_NP &&
3495 p->binding->transport != NCALRPC) {
3496 torture_comment(tctx, "testcase_LookupNames is only available "
3497 "over NCACN_NP or NCALRPC");
3501 if (!test_OpenPolicy(b, tctx)) {
3505 if (!test_lsa_OpenPolicy2(b, tctx, &handle)) {
3514 tnames.names = talloc_array(tctx, struct lsa_TranslatedName, tnames.count);
3515 ZERO_STRUCT(tnames.names[0]);
3516 tnames.names[0].name.string = "BUILTIN";
3517 tnames.names[0].sid_type = SID_NAME_DOMAIN;
3519 if (!test_LookupNames(b, tctx, handle, &tnames)) {
3524 tnames2.names = talloc_array(tctx, struct lsa_TranslatedName2, tnames2.count);
3525 ZERO_STRUCT(tnames2.names[0]);
3526 tnames2.names[0].name.string = "BUILTIN";
3527 tnames2.names[0].sid_type = SID_NAME_DOMAIN;
3529 if (!test_LookupNames2(b, tctx, handle, &tnames2, true)) {
3533 if (!test_LookupNames3(b, tctx, handle, &tnames2, true)) {
3537 if (!test_LookupNames_wellknown(b, tctx, handle)) {
3541 if (!test_LookupNames_NULL(b, tctx, handle)) {
3545 if (!test_LookupNames_bogus(b, tctx, handle)) {
3549 if (!test_lsa_Close(b, tctx, handle)) {
3556 struct torture_suite *torture_rpc_lsa_lookup_names(TALLOC_CTX *mem_ctx)
3558 struct torture_suite *suite;
3559 struct torture_rpc_tcase *tcase;
3561 suite = torture_suite_create(mem_ctx, "lsa.lookupnames");
3563 tcase = torture_suite_add_rpc_iface_tcase(suite, "lsa",
3565 torture_rpc_tcase_add_test(tcase, "LookupNames",
3566 testcase_LookupNames);
3571 struct lsa_trustdom_state {
3572 uint32_t num_trusts;
3575 static bool testcase_TrustedDomains(struct torture_context *tctx,
3576 struct dcerpc_pipe *p,
3580 struct policy_handle *handle;
3581 struct lsa_trustdom_state *state =
3582 talloc_get_type_abort(data, struct lsa_trustdom_state);
3583 struct dcerpc_binding_handle *b = p->binding_handle;
3585 if (p->binding->transport != NCACN_NP &&
3586 p->binding->transport != NCALRPC) {
3587 torture_comment(tctx, "testcase_TrustedDomains is only available "
3588 "over NCACN_NP or NCALRPC");
3592 torture_comment(tctx, "Testing %d domains\n", state->num_trusts);
3594 if (!test_OpenPolicy(b, tctx)) {
3598 if (!test_lsa_OpenPolicy2(b, tctx, &handle)) {
3606 if (!test_CreateTrustedDomain(b, tctx, handle, state->num_trusts)) {
3610 if (!test_CreateTrustedDomainEx(p, tctx, handle, state->num_trusts)) {
3614 if (!test_CreateTrustedDomainEx2(p, tctx, handle, state->num_trusts)) {
3618 if (!test_lsa_Close(b, tctx, handle)) {
3625 struct torture_suite *torture_rpc_lsa_trusted_domains(TALLOC_CTX *mem_ctx)
3627 struct torture_suite *suite;
3628 struct torture_rpc_tcase *tcase;
3629 struct lsa_trustdom_state *state;
3631 state = talloc(mem_ctx, struct lsa_trustdom_state);
3633 state->num_trusts = 12;
3635 suite = torture_suite_create(mem_ctx, "lsa.trusted.domains");
3637 tcase = torture_suite_add_rpc_iface_tcase(suite, "lsa",
3639 torture_rpc_tcase_add_test_ex(tcase, "TrustedDomains",
3640 testcase_TrustedDomains,
3646 static bool testcase_Privileges(struct torture_context *tctx,
3647 struct dcerpc_pipe *p)
3650 struct policy_handle *handle;
3651 struct dcerpc_binding_handle *b = p->binding_handle;
3653 if (p->binding->transport != NCACN_NP &&
3654 p->binding->transport != NCALRPC) {
3655 torture_comment(tctx, "testcase_Privileges is only available "
3656 "over NCACN_NP or NCALRPC");
3660 if (!test_OpenPolicy(b, tctx)) {
3664 if (!test_lsa_OpenPolicy2(b, tctx, &handle)) {
3672 if (!test_CreateAccount(b, tctx, handle)) {
3676 if (!test_EnumAccounts(b, tctx, handle)) {
3680 if (!test_EnumPrivs(b, tctx, handle)) {
3684 if (!test_lsa_Close(b, tctx, handle)) {
3692 struct torture_suite *torture_rpc_lsa_privileges(TALLOC_CTX *mem_ctx)
3694 struct torture_suite *suite;
3695 struct torture_rpc_tcase *tcase;
3697 suite = torture_suite_create(mem_ctx, "lsa.privileges");
3699 tcase = torture_suite_add_rpc_iface_tcase(suite, "lsa",
3701 torture_rpc_tcase_add_test(tcase, "Privileges",
3702 testcase_Privileges);