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),
72 if (!NT_STATUS_IS_OK(r.out.result)) {
73 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_ACCESS_DENIED) ||
74 NT_STATUS_EQUAL(r.out.result, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
75 torture_comment(tctx, "not considering %s to be an error\n",
76 nt_errstr(r.out.result));
79 torture_comment(tctx, "OpenPolicy failed - %s\n",
80 nt_errstr(r.out.result));
88 bool test_lsa_OpenPolicy2_ex(struct dcerpc_binding_handle *b,
89 struct torture_context *tctx,
90 struct policy_handle **handle,
91 NTSTATUS expected_status)
93 struct lsa_ObjectAttribute attr;
94 struct lsa_QosInfo qos;
95 struct lsa_OpenPolicy2 r;
98 torture_comment(tctx, "\nTesting OpenPolicy2\n");
100 *handle = talloc(tctx, struct policy_handle);
106 qos.impersonation_level = 2;
107 qos.context_mode = 1;
108 qos.effective_only = 0;
111 attr.root_dir = NULL;
112 attr.object_name = NULL;
114 attr.sec_desc = NULL;
117 r.in.system_name = "\\";
119 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
120 r.out.handle = *handle;
122 status = dcerpc_lsa_OpenPolicy2_r(b, tctx, &r);
123 torture_assert_ntstatus_equal(tctx, status, expected_status,
124 "OpenPolicy2 failed");
125 if (!NT_STATUS_IS_OK(expected_status)) {
128 if (!NT_STATUS_IS_OK(r.out.result)) {
129 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_ACCESS_DENIED) ||
130 NT_STATUS_EQUAL(r.out.result, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
131 torture_comment(tctx, "not considering %s to be an error\n",
132 nt_errstr(r.out.result));
133 talloc_free(*handle);
137 torture_comment(tctx, "OpenPolicy2 failed - %s\n",
138 nt_errstr(r.out.result));
146 bool test_lsa_OpenPolicy2(struct dcerpc_binding_handle *b,
147 struct torture_context *tctx,
148 struct policy_handle **handle)
150 return test_lsa_OpenPolicy2_ex(b, tctx, handle, NT_STATUS_OK);
153 static bool test_LookupNames(struct dcerpc_binding_handle *b,
154 struct torture_context *tctx,
155 struct policy_handle *handle,
156 struct lsa_TransNameArray *tnames)
158 struct lsa_LookupNames r;
159 struct lsa_TransSidArray sids;
160 struct lsa_RefDomainList *domains = NULL;
161 struct lsa_String *names;
166 torture_comment(tctx, "\nTesting LookupNames with %d names\n", tnames->count);
174 input_idx = talloc_array(tctx, uint32_t, tnames->count);
175 names = talloc_array(tctx, struct lsa_String, tnames->count);
177 for (i=0;i<tnames->count;i++) {
178 if (tnames->names[i].sid_type != SID_NAME_UNKNOWN) {
179 init_lsa_String(&names[r.in.num_names], tnames->names[i].name.string);
180 input_idx[r.in.num_names] = i;
185 r.in.handle = handle;
190 r.out.count = &count;
192 r.out.domains = &domains;
194 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupNames_r(b, tctx, &r),
195 "LookupNames failed");
196 if (NT_STATUS_EQUAL(r.out.result, STATUS_SOME_UNMAPPED) ||
197 NT_STATUS_EQUAL(r.out.result, NT_STATUS_NONE_MAPPED)) {
198 for (i=0;i< r.in.num_names;i++) {
199 if (i < count && sids.sids[i].sid_type == SID_NAME_UNKNOWN) {
200 torture_comment(tctx, "LookupName of %s was unmapped\n",
201 tnames->names[i].name.string);
202 } else if (i >=count) {
203 torture_comment(tctx, "LookupName of %s failed to return a result\n",
204 tnames->names[i].name.string);
207 torture_comment(tctx, "LookupNames failed - %s\n",
208 nt_errstr(r.out.result));
210 } else if (!NT_STATUS_IS_OK(r.out.result)) {
211 torture_comment(tctx, "LookupNames failed - %s\n",
212 nt_errstr(r.out.result));
216 for (i=0;i< r.in.num_names;i++) {
218 if (sids.sids[i].sid_type != tnames->names[input_idx[i]].sid_type) {
219 torture_comment(tctx, "LookupName of %s got unexpected name type: %s\n",
220 tnames->names[input_idx[i]].name.string,
221 sid_type_lookup(sids.sids[i].sid_type));
224 if ((sids.sids[i].sid_type == SID_NAME_DOMAIN) &&
225 (sids.sids[i].rid != (uint32_t)-1)) {
226 torture_comment(tctx, "LookupName of %s got unexpected rid: %d\n",
227 tnames->names[input_idx[i]].name.string, sids.sids[i].rid);
230 } else if (i >=count) {
231 torture_comment(tctx, "LookupName of %s failed to return a result\n",
232 tnames->names[input_idx[i]].name.string);
236 torture_comment(tctx, "\n");
241 static bool test_LookupNames_bogus(struct dcerpc_binding_handle *b,
242 struct torture_context *tctx,
243 struct policy_handle *handle)
245 struct lsa_LookupNames r;
246 struct lsa_TransSidArray sids;
247 struct lsa_RefDomainList *domains = NULL;
248 struct lsa_String names[1];
251 torture_comment(tctx, "\nTesting LookupNames with bogus name\n");
256 init_lsa_String(&names[0], "NT AUTHORITY\\BOGUS");
258 r.in.handle = handle;
264 r.out.count = &count;
266 r.out.domains = &domains;
268 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupNames_r(b, tctx, &r),
269 "LookupNames bogus failed");
270 if (!NT_STATUS_EQUAL(r.out.result, NT_STATUS_NONE_MAPPED)) {
271 torture_comment(tctx, "LookupNames failed - %s\n",
272 nt_errstr(r.out.result));
276 torture_comment(tctx, "\n");
281 static bool test_LookupNames_NULL(struct dcerpc_binding_handle *b,
282 struct torture_context *tctx,
283 struct policy_handle *handle)
285 struct lsa_LookupNames r;
286 struct lsa_TransSidArray sids;
287 struct lsa_RefDomainList *domains = NULL;
288 struct lsa_String names[1];
291 torture_comment(tctx, "\nTesting LookupNames with NULL name\n");
296 names[0].string = NULL;
298 r.in.handle = handle;
304 r.out.count = &count;
306 r.out.domains = &domains;
308 /* nt4 returns NT_STATUS_NONE_MAPPED with sid_type
309 * SID_NAME_UNKNOWN, rid 0, and sid_index -1;
311 * w2k3/w2k8 return NT_STATUS_OK with sid_type
312 * SID_NAME_DOMAIN, rid -1 and sid_index 0 and BUILTIN domain
315 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupNames_r(b, tctx, &r),
316 "LookupNames with NULL name failed");
317 torture_assert_ntstatus_ok(tctx, r.out.result,
318 "LookupNames with NULL name failed");
320 torture_comment(tctx, "\n");
325 static bool test_LookupNames_wellknown(struct dcerpc_binding_handle *b,
326 struct torture_context *tctx,
327 struct policy_handle *handle)
329 struct lsa_TranslatedName name;
330 struct lsa_TransNameArray tnames;
333 torture_comment(tctx, "Testing LookupNames with well known names\n");
335 tnames.names = &name;
337 name.name.string = "NT AUTHORITY\\SYSTEM";
338 name.sid_type = SID_NAME_WKN_GRP;
339 ret &= test_LookupNames(b, tctx, handle, &tnames);
341 name.name.string = "NT AUTHORITY\\ANONYMOUS LOGON";
342 name.sid_type = SID_NAME_WKN_GRP;
343 ret &= test_LookupNames(b, tctx, handle, &tnames);
345 name.name.string = "NT AUTHORITY\\Authenticated Users";
346 name.sid_type = SID_NAME_WKN_GRP;
347 ret &= test_LookupNames(b, tctx, handle, &tnames);
350 name.name.string = "NT AUTHORITY";
351 ret &= test_LookupNames(b, tctx, handle, &tnames);
353 name.name.string = "NT AUTHORITY\\";
354 ret &= test_LookupNames(b, tctx, handle, &tnames);
357 name.name.string = "BUILTIN\\";
358 name.sid_type = SID_NAME_DOMAIN;
359 ret &= test_LookupNames(b, tctx, handle, &tnames);
361 name.name.string = "BUILTIN\\Administrators";
362 name.sid_type = SID_NAME_ALIAS;
363 ret &= test_LookupNames(b, tctx, handle, &tnames);
365 name.name.string = "SYSTEM";
366 name.sid_type = SID_NAME_WKN_GRP;
367 ret &= test_LookupNames(b, tctx, handle, &tnames);
369 name.name.string = "Everyone";
370 name.sid_type = SID_NAME_WKN_GRP;
371 ret &= test_LookupNames(b, tctx, handle, &tnames);
375 static bool test_LookupNames2(struct dcerpc_binding_handle *b,
376 struct torture_context *tctx,
377 struct policy_handle *handle,
378 struct lsa_TransNameArray2 *tnames,
381 struct lsa_LookupNames2 r;
382 struct lsa_TransSidArray2 sids;
383 struct lsa_RefDomainList *domains = NULL;
384 struct lsa_String *names;
388 torture_comment(tctx, "\nTesting LookupNames2 with %d names\n", tnames->count);
396 input_idx = talloc_array(tctx, uint32_t, tnames->count);
397 names = talloc_array(tctx, struct lsa_String, tnames->count);
399 for (i=0;i<tnames->count;i++) {
400 if (tnames->names[i].sid_type != SID_NAME_UNKNOWN) {
401 init_lsa_String(&names[r.in.num_names], tnames->names[i].name.string);
402 input_idx[r.in.num_names] = i;
407 r.in.handle = handle;
412 r.in.lookup_options = 0;
413 r.in.client_revision = 0;
414 r.out.count = &count;
416 r.out.domains = &domains;
418 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupNames2_r(b, tctx, &r),
419 "LookupNames2 failed");
420 if (!NT_STATUS_IS_OK(r.out.result)) {
421 torture_comment(tctx, "LookupNames2 failed - %s\n",
422 nt_errstr(r.out.result));
427 torture_assert_int_equal(tctx, count, sids.count,
428 "unexpected number of results returned");
429 if (sids.count > 0) {
430 torture_assert(tctx, sids.sids, "invalid sid buffer");
434 torture_comment(tctx, "\n");
440 static bool test_LookupNames3(struct dcerpc_binding_handle *b,
441 struct torture_context *tctx,
442 struct policy_handle *handle,
443 struct lsa_TransNameArray2 *tnames,
446 struct lsa_LookupNames3 r;
447 struct lsa_TransSidArray3 sids;
448 struct lsa_RefDomainList *domains = NULL;
449 struct lsa_String *names;
454 torture_comment(tctx, "\nTesting LookupNames3 with %d names\n", tnames->count);
461 input_idx = talloc_array(tctx, uint32_t, tnames->count);
462 names = talloc_array(tctx, struct lsa_String, tnames->count);
463 for (i=0;i<tnames->count;i++) {
464 if (tnames->names[i].sid_type != SID_NAME_UNKNOWN) {
465 init_lsa_String(&names[r.in.num_names], tnames->names[i].name.string);
466 input_idx[r.in.num_names] = i;
471 r.in.handle = handle;
476 r.in.lookup_options = 0;
477 r.in.client_revision = 0;
478 r.out.count = &count;
480 r.out.domains = &domains;
482 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupNames3_r(b, tctx, &r),
483 "LookupNames3 failed");
484 if (!NT_STATUS_IS_OK(r.out.result)) {
485 torture_comment(tctx, "LookupNames3 failed - %s\n",
486 nt_errstr(r.out.result));
491 torture_assert_int_equal(tctx, count, sids.count,
492 "unexpected number of results returned");
493 if (sids.count > 0) {
494 torture_assert(tctx, sids.sids, "invalid sid buffer");
498 torture_comment(tctx, "\n");
503 static bool test_LookupNames4(struct dcerpc_binding_handle *b,
504 struct torture_context *tctx,
505 struct lsa_TransNameArray2 *tnames,
508 struct lsa_LookupNames4 r;
509 struct lsa_TransSidArray3 sids;
510 struct lsa_RefDomainList *domains = NULL;
511 struct lsa_String *names;
516 torture_comment(tctx, "\nTesting LookupNames4 with %d names\n", tnames->count);
523 input_idx = talloc_array(tctx, uint32_t, tnames->count);
524 names = talloc_array(tctx, struct lsa_String, tnames->count);
525 for (i=0;i<tnames->count;i++) {
526 if (tnames->names[i].sid_type != SID_NAME_UNKNOWN) {
527 init_lsa_String(&names[r.in.num_names], tnames->names[i].name.string);
528 input_idx[r.in.num_names] = i;
533 r.in.num_names = tnames->count;
538 r.in.lookup_options = 0;
539 r.in.client_revision = 0;
540 r.out.count = &count;
542 r.out.domains = &domains;
544 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupNames4_r(b, tctx, &r),
545 "LookupNames4 failed");
546 if (!NT_STATUS_IS_OK(r.out.result)) {
547 torture_comment(tctx, "LookupNames4 failed - %s\n",
548 nt_errstr(r.out.result));
553 torture_assert_int_equal(tctx, count, sids.count,
554 "unexpected number of results returned");
555 if (sids.count > 0) {
556 torture_assert(tctx, sids.sids, "invalid sid buffer");
560 torture_comment(tctx, "\n");
566 static bool test_LookupSids(struct dcerpc_binding_handle *b,
567 struct torture_context *tctx,
568 struct policy_handle *handle,
569 struct lsa_SidArray *sids)
571 struct lsa_LookupSids r;
572 struct lsa_TransNameArray names;
573 struct lsa_RefDomainList *domains = NULL;
574 uint32_t count = sids->num_sids;
576 torture_comment(tctx, "\nTesting LookupSids\n");
581 r.in.handle = handle;
586 r.out.count = &count;
587 r.out.names = &names;
588 r.out.domains = &domains;
590 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupSids_r(b, tctx, &r),
591 "LookupSids failed");
592 if (!NT_STATUS_IS_OK(r.out.result) &&
593 !NT_STATUS_EQUAL(r.out.result, STATUS_SOME_UNMAPPED)) {
594 torture_comment(tctx, "LookupSids failed - %s\n",
595 nt_errstr(r.out.result));
599 torture_comment(tctx, "\n");
601 if (!test_LookupNames(b, tctx, handle, &names)) {
609 static bool test_LookupSids2(struct dcerpc_binding_handle *b,
610 struct torture_context *tctx,
611 struct policy_handle *handle,
612 struct lsa_SidArray *sids)
614 struct lsa_LookupSids2 r;
615 struct lsa_TransNameArray2 names;
616 struct lsa_RefDomainList *domains = NULL;
617 uint32_t count = sids->num_sids;
619 torture_comment(tctx, "\nTesting LookupSids2\n");
624 r.in.handle = handle;
629 r.in.lookup_options = 0;
630 r.in.client_revision = 0;
631 r.out.count = &count;
632 r.out.names = &names;
633 r.out.domains = &domains;
635 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupSids2_r(b, tctx, &r),
636 "LookupSids2 failed");
637 if (!NT_STATUS_IS_OK(r.out.result) &&
638 !NT_STATUS_EQUAL(r.out.result, STATUS_SOME_UNMAPPED)) {
639 torture_comment(tctx, "LookupSids2 failed - %s\n",
640 nt_errstr(r.out.result));
644 torture_comment(tctx, "\n");
646 if (!test_LookupNames2(b, tctx, handle, &names, false)) {
650 if (!test_LookupNames3(b, tctx, handle, &names, false)) {
657 static bool test_LookupSids3(struct dcerpc_binding_handle *b,
658 struct torture_context *tctx,
659 struct lsa_SidArray *sids)
661 struct lsa_LookupSids3 r;
662 struct lsa_TransNameArray2 names;
663 struct lsa_RefDomainList *domains = NULL;
664 uint32_t count = sids->num_sids;
666 torture_comment(tctx, "\nTesting LookupSids3\n");
675 r.in.lookup_options = 0;
676 r.in.client_revision = 0;
677 r.out.domains = &domains;
678 r.out.count = &count;
679 r.out.names = &names;
681 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupSids3_r(b, tctx, &r),
682 "LookupSids3 failed");
683 if (!NT_STATUS_IS_OK(r.out.result)) {
684 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_ACCESS_DENIED) ||
685 NT_STATUS_EQUAL(r.out.result, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
686 torture_comment(tctx, "not considering %s to be an error\n",
687 nt_errstr(r.out.result));
690 torture_comment(tctx, "LookupSids3 failed - %s - not considered an error\n",
691 nt_errstr(r.out.result));
695 torture_comment(tctx, "\n");
697 if (!test_LookupNames4(b, tctx, &names, false)) {
704 bool test_many_LookupSids(struct dcerpc_pipe *p,
705 struct torture_context *tctx,
706 struct policy_handle *handle)
709 struct lsa_SidArray sids;
711 struct dcerpc_binding_handle *b = p->binding_handle;
713 torture_comment(tctx, "\nTesting LookupSids with lots of SIDs\n");
717 sids.sids = talloc_array(tctx, struct lsa_SidPtr, sids.num_sids);
719 for (i=0; i<sids.num_sids; i++) {
720 const char *sidstr = "S-1-5-32-545";
721 sids.sids[i].sid = dom_sid_parse_talloc(tctx, sidstr);
724 count = sids.num_sids;
727 struct lsa_LookupSids r;
728 struct lsa_TransNameArray names;
729 struct lsa_RefDomainList *domains = NULL;
733 r.in.handle = handle;
737 r.in.count = &names.count;
738 r.out.count = &count;
739 r.out.names = &names;
740 r.out.domains = &domains;
742 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupSids_r(b, tctx, &r),
743 "LookupSids failed");
744 if (!NT_STATUS_IS_OK(r.out.result)) {
745 torture_comment(tctx, "LookupSids failed - %s\n",
746 nt_errstr(r.out.result));
750 torture_comment(tctx, "\n");
752 if (!test_LookupNames(b, tctx, handle, &names)) {
755 } else if (p->conn->security_state.auth_info->auth_type == DCERPC_AUTH_TYPE_SCHANNEL &&
756 p->conn->security_state.auth_info->auth_level >= DCERPC_AUTH_LEVEL_INTEGRITY) {
757 struct lsa_LookupSids3 r;
758 struct lsa_RefDomainList *domains = NULL;
759 struct lsa_TransNameArray2 names;
764 torture_comment(tctx, "\nTesting LookupSids3\n");
770 r.in.lookup_options = 0;
771 r.in.client_revision = 0;
772 r.out.count = &count;
773 r.out.names = &names;
774 r.out.domains = &domains;
776 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupSids3_r(b, tctx, &r),
777 "LookupSids3 failed");
778 if (!NT_STATUS_IS_OK(r.out.result)) {
779 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_ACCESS_DENIED) ||
780 NT_STATUS_EQUAL(r.out.result, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
781 torture_comment(tctx, "not considering %s to be an error\n",
782 nt_errstr(r.out.result));
785 torture_comment(tctx, "LookupSids3 failed - %s\n",
786 nt_errstr(r.out.result));
789 if (!test_LookupNames4(b, tctx, &names, false)) {
794 torture_comment(tctx, "\n");
801 static void lookupsids_cb(struct tevent_req *subreq)
803 int *replies = (int *)tevent_req_callback_data_void(subreq);
806 status = dcerpc_lsa_LookupSids_r_recv(subreq, subreq);
808 if (!NT_STATUS_IS_OK(status)) {
809 printf("lookupsids returned %s\n", nt_errstr(status));
818 static bool test_LookupSids_async(struct dcerpc_binding_handle *b,
819 struct torture_context *tctx,
820 struct policy_handle *handle)
822 struct lsa_SidArray sids;
823 struct lsa_SidPtr sidptr;
825 struct lsa_TransNameArray *names;
826 struct lsa_LookupSids *r;
827 struct lsa_RefDomainList *domains = NULL;
828 struct tevent_req **req;
831 const int num_async_requests = 50;
833 count = talloc_array(tctx, uint32_t, num_async_requests);
834 names = talloc_array(tctx, struct lsa_TransNameArray, num_async_requests);
835 r = talloc_array(tctx, struct lsa_LookupSids, num_async_requests);
837 torture_comment(tctx, "\nTesting %d async lookupsids request\n", num_async_requests);
839 req = talloc_array(tctx, struct tevent_req *, num_async_requests);
843 sidptr.sid = dom_sid_parse_talloc(tctx, "S-1-5-32-545");
847 for (i=0; i<num_async_requests; i++) {
850 names[i].names = NULL;
852 r[i].in.handle = handle;
853 r[i].in.sids = &sids;
854 r[i].in.names = &names[i];
856 r[i].in.count = &names[i].count;
857 r[i].out.count = &count[i];
858 r[i].out.names = &names[i];
859 r[i].out.domains = &domains;
861 req[i] = dcerpc_lsa_LookupSids_r_send(tctx, tctx->ev, b, &r[i]);
862 if (req[i] == NULL) {
867 tevent_req_set_callback(req[i], lookupsids_cb, &replies);
870 while (replies >= 0 && replies < num_async_requests) {
871 tevent_loop_once(tctx->ev);
883 static bool test_LookupPrivValue(struct dcerpc_binding_handle *b,
884 struct torture_context *tctx,
885 struct policy_handle *handle,
886 struct lsa_String *name)
888 struct lsa_LookupPrivValue r;
889 struct lsa_LUID luid;
891 r.in.handle = handle;
895 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupPrivValue_r(b, tctx, &r),
896 "LookupPrivValue failed");
897 if (!NT_STATUS_IS_OK(r.out.result)) {
898 torture_comment(tctx, "\nLookupPrivValue failed - %s\n",
899 nt_errstr(r.out.result));
906 static bool test_LookupPrivName(struct dcerpc_binding_handle *b,
907 struct torture_context *tctx,
908 struct policy_handle *handle,
909 struct lsa_LUID *luid)
911 struct lsa_LookupPrivName r;
912 struct lsa_StringLarge *name = NULL;
914 r.in.handle = handle;
918 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupPrivName_r(b, tctx, &r),
919 "LookupPrivName failed");
920 if (!NT_STATUS_IS_OK(r.out.result)) {
921 torture_comment(tctx, "\nLookupPrivName failed - %s\n",
922 nt_errstr(r.out.result));
929 static bool test_RemovePrivilegesFromAccount(struct dcerpc_binding_handle *b,
930 struct torture_context *tctx,
931 struct policy_handle *handle,
932 struct policy_handle *acct_handle,
933 struct lsa_LUID *luid)
935 struct lsa_RemovePrivilegesFromAccount r;
936 struct lsa_PrivilegeSet privs;
939 torture_comment(tctx, "\nTesting RemovePrivilegesFromAccount\n");
941 r.in.handle = acct_handle;
947 privs.set = talloc_array(tctx, struct lsa_LUIDAttribute, 1);
948 privs.set[0].luid = *luid;
949 privs.set[0].attribute = 0;
951 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_RemovePrivilegesFromAccount_r(b, tctx, &r),
952 "RemovePrivilegesFromAccount failed");
953 if (!NT_STATUS_IS_OK(r.out.result)) {
955 struct lsa_LookupPrivName r_name;
956 struct lsa_StringLarge *name = NULL;
958 r_name.in.handle = handle;
959 r_name.in.luid = luid;
960 r_name.out.name = &name;
962 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupPrivName_r(b, tctx, &r_name),
963 "LookupPrivName failed");
964 if (!NT_STATUS_IS_OK(r_name.out.result)) {
965 torture_comment(tctx, "\nLookupPrivName failed - %s\n",
966 nt_errstr(r_name.out.result));
969 /* Windows 2008 does not allow this to be removed */
970 if (strcmp("SeAuditPrivilege", name->string) == 0) {
974 torture_comment(tctx, "RemovePrivilegesFromAccount failed to remove %s - %s\n",
976 nt_errstr(r.out.result));
983 static bool test_AddPrivilegesToAccount(struct dcerpc_binding_handle *b,
984 struct torture_context *tctx,
985 struct policy_handle *acct_handle,
986 struct lsa_LUID *luid)
988 struct lsa_AddPrivilegesToAccount r;
989 struct lsa_PrivilegeSet privs;
992 torture_comment(tctx, "\nTesting AddPrivilegesToAccount\n");
994 r.in.handle = acct_handle;
999 privs.set = talloc_array(tctx, struct lsa_LUIDAttribute, 1);
1000 privs.set[0].luid = *luid;
1001 privs.set[0].attribute = 0;
1003 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_AddPrivilegesToAccount_r(b, tctx, &r),
1004 "AddPrivilegesToAccount failed");
1005 if (!NT_STATUS_IS_OK(r.out.result)) {
1006 torture_comment(tctx, "AddPrivilegesToAccount failed - %s\n",
1007 nt_errstr(r.out.result));
1014 static bool test_EnumPrivsAccount(struct dcerpc_binding_handle *b,
1015 struct torture_context *tctx,
1016 struct policy_handle *handle,
1017 struct policy_handle *acct_handle)
1019 struct lsa_EnumPrivsAccount r;
1020 struct lsa_PrivilegeSet *privs = NULL;
1023 torture_comment(tctx, "\nTesting EnumPrivsAccount\n");
1025 r.in.handle = acct_handle;
1026 r.out.privs = &privs;
1028 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumPrivsAccount_r(b, tctx, &r),
1029 "EnumPrivsAccount failed");
1030 if (!NT_STATUS_IS_OK(r.out.result)) {
1031 torture_comment(tctx, "EnumPrivsAccount failed - %s\n",
1032 nt_errstr(r.out.result));
1036 if (privs && privs->count > 0) {
1038 for (i=0;i<privs->count;i++) {
1039 test_LookupPrivName(b, tctx, handle,
1040 &privs->set[i].luid);
1043 ret &= test_RemovePrivilegesFromAccount(b, tctx, handle, acct_handle,
1044 &privs->set[0].luid);
1045 ret &= test_AddPrivilegesToAccount(b, tctx, acct_handle,
1046 &privs->set[0].luid);
1052 static bool test_GetSystemAccessAccount(struct dcerpc_binding_handle *b,
1053 struct torture_context *tctx,
1054 struct policy_handle *handle,
1055 struct policy_handle *acct_handle)
1057 uint32_t access_mask;
1058 struct lsa_GetSystemAccessAccount r;
1060 torture_comment(tctx, "\nTesting GetSystemAccessAccount\n");
1062 r.in.handle = acct_handle;
1063 r.out.access_mask = &access_mask;
1065 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_GetSystemAccessAccount_r(b, tctx, &r),
1066 "GetSystemAccessAccount failed");
1067 if (!NT_STATUS_IS_OK(r.out.result)) {
1068 torture_comment(tctx, "GetSystemAccessAccount failed - %s\n",
1069 nt_errstr(r.out.result));
1073 if (r.out.access_mask != NULL) {
1074 torture_comment(tctx, "Rights:");
1075 if (*(r.out.access_mask) & LSA_POLICY_MODE_INTERACTIVE)
1076 torture_comment(tctx, " LSA_POLICY_MODE_INTERACTIVE");
1077 if (*(r.out.access_mask) & LSA_POLICY_MODE_NETWORK)
1078 torture_comment(tctx, " LSA_POLICY_MODE_NETWORK");
1079 if (*(r.out.access_mask) & LSA_POLICY_MODE_BATCH)
1080 torture_comment(tctx, " LSA_POLICY_MODE_BATCH");
1081 if (*(r.out.access_mask) & LSA_POLICY_MODE_SERVICE)
1082 torture_comment(tctx, " LSA_POLICY_MODE_SERVICE");
1083 if (*(r.out.access_mask) & LSA_POLICY_MODE_PROXY)
1084 torture_comment(tctx, " LSA_POLICY_MODE_PROXY");
1085 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_INTERACTIVE)
1086 torture_comment(tctx, " LSA_POLICY_MODE_DENY_INTERACTIVE");
1087 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_NETWORK)
1088 torture_comment(tctx, " LSA_POLICY_MODE_DENY_NETWORK");
1089 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_BATCH)
1090 torture_comment(tctx, " LSA_POLICY_MODE_DENY_BATCH");
1091 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_SERVICE)
1092 torture_comment(tctx, " LSA_POLICY_MODE_DENY_SERVICE");
1093 if (*(r.out.access_mask) & LSA_POLICY_MODE_REMOTE_INTERACTIVE)
1094 torture_comment(tctx, " LSA_POLICY_MODE_REMOTE_INTERACTIVE");
1095 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_REMOTE_INTERACTIVE)
1096 torture_comment(tctx, " LSA_POLICY_MODE_DENY_REMOTE_INTERACTIVE");
1097 if (*(r.out.access_mask) & LSA_POLICY_MODE_ALL)
1098 torture_comment(tctx, " LSA_POLICY_MODE_ALL");
1099 if (*(r.out.access_mask) & LSA_POLICY_MODE_ALL_NT4)
1100 torture_comment(tctx, " LSA_POLICY_MODE_ALL_NT4");
1101 torture_comment(tctx, "\n");
1107 static bool test_Delete(struct dcerpc_binding_handle *b,
1108 struct torture_context *tctx,
1109 struct policy_handle *handle)
1111 struct lsa_Delete r;
1113 torture_comment(tctx, "\nTesting Delete\n");
1115 r.in.handle = handle;
1116 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_Delete_r(b, tctx, &r),
1118 if (!NT_STATUS_EQUAL(r.out.result, NT_STATUS_NOT_SUPPORTED)) {
1119 torture_comment(tctx, "Delete should have failed NT_STATUS_NOT_SUPPORTED - %s\n", nt_errstr(r.out.result));
1126 static bool test_DeleteObject(struct dcerpc_binding_handle *b,
1127 struct torture_context *tctx,
1128 struct policy_handle *handle)
1130 struct lsa_DeleteObject r;
1132 torture_comment(tctx, "\nTesting DeleteObject\n");
1134 r.in.handle = handle;
1135 r.out.handle = handle;
1136 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_DeleteObject_r(b, tctx, &r),
1137 "DeleteObject failed");
1138 if (!NT_STATUS_IS_OK(r.out.result)) {
1139 torture_comment(tctx, "DeleteObject failed - %s\n",
1140 nt_errstr(r.out.result));
1148 static bool test_CreateAccount(struct dcerpc_binding_handle *b,
1149 struct torture_context *tctx,
1150 struct policy_handle *handle)
1152 struct lsa_CreateAccount r;
1153 struct dom_sid2 *newsid;
1154 struct policy_handle acct_handle;
1156 newsid = dom_sid_parse_talloc(tctx, "S-1-5-12349876-4321-2854");
1158 torture_comment(tctx, "\nTesting CreateAccount\n");
1160 r.in.handle = handle;
1162 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1163 r.out.acct_handle = &acct_handle;
1165 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_CreateAccount_r(b, tctx, &r),
1166 "CreateAccount failed");
1167 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_OBJECT_NAME_COLLISION)) {
1168 struct lsa_OpenAccount r_o;
1169 r_o.in.handle = handle;
1170 r_o.in.sid = newsid;
1171 r_o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1172 r_o.out.acct_handle = &acct_handle;
1174 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenAccount_r(b, tctx, &r_o),
1175 "OpenAccount failed");
1176 if (!NT_STATUS_IS_OK(r_o.out.result)) {
1177 torture_comment(tctx, "OpenAccount failed - %s\n",
1178 nt_errstr(r_o.out.result));
1181 } else if (!NT_STATUS_IS_OK(r.out.result)) {
1182 torture_comment(tctx, "CreateAccount failed - %s\n",
1183 nt_errstr(r.out.result));
1187 if (!test_Delete(b, tctx, &acct_handle)) {
1191 if (!test_DeleteObject(b, tctx, &acct_handle)) {
1198 static bool test_DeleteTrustedDomain(struct dcerpc_binding_handle *b,
1199 struct torture_context *tctx,
1200 struct policy_handle *handle,
1201 struct lsa_StringLarge name)
1203 struct lsa_OpenTrustedDomainByName r;
1204 struct policy_handle trustdom_handle;
1206 r.in.handle = handle;
1207 r.in.name.string = name.string;
1208 r.in.access_mask = SEC_STD_DELETE;
1209 r.out.trustdom_handle = &trustdom_handle;
1211 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenTrustedDomainByName_r(b, tctx, &r),
1212 "OpenTrustedDomainByName failed");
1213 if (!NT_STATUS_IS_OK(r.out.result)) {
1214 torture_comment(tctx, "OpenTrustedDomainByName failed - %s\n", nt_errstr(r.out.result));
1218 if (!test_Delete(b, tctx, &trustdom_handle)) {
1222 if (!test_DeleteObject(b, tctx, &trustdom_handle)) {
1229 static bool test_DeleteTrustedDomainBySid(struct dcerpc_binding_handle *b,
1230 struct torture_context *tctx,
1231 struct policy_handle *handle,
1232 struct dom_sid *sid)
1234 struct lsa_DeleteTrustedDomain r;
1236 r.in.handle = handle;
1239 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_DeleteTrustedDomain_r(b, tctx, &r),
1240 "DeleteTrustedDomain failed");
1241 if (!NT_STATUS_IS_OK(r.out.result)) {
1242 torture_comment(tctx, "DeleteTrustedDomain failed - %s\n", nt_errstr(r.out.result));
1250 static bool test_CreateSecret(struct dcerpc_pipe *p,
1251 struct torture_context *tctx,
1252 struct policy_handle *handle)
1255 struct lsa_CreateSecret r;
1256 struct lsa_OpenSecret r2;
1257 struct lsa_SetSecret r3;
1258 struct lsa_QuerySecret r4;
1259 struct lsa_SetSecret r5;
1260 struct lsa_QuerySecret r6;
1261 struct lsa_SetSecret r7;
1262 struct lsa_QuerySecret r8;
1263 struct policy_handle sec_handle, sec_handle2, sec_handle3;
1264 struct lsa_DeleteObject d_o;
1265 struct lsa_DATA_BUF buf1;
1266 struct lsa_DATA_BUF_PTR bufp1;
1267 struct lsa_DATA_BUF_PTR bufp2;
1270 DATA_BLOB session_key;
1271 NTTIME old_mtime, new_mtime;
1272 DATA_BLOB blob1, blob2;
1273 const char *secret1 = "abcdef12345699qwerty";
1275 const char *secret3 = "ABCDEF12345699QWERTY";
1277 const char *secret5 = "NEW-SAMBA4-SECRET";
1281 const int LOCAL = 0;
1282 const int GLOBAL = 1;
1283 struct dcerpc_binding_handle *b = p->binding_handle;
1285 secname[LOCAL] = talloc_asprintf(tctx, "torturesecret-%u", (unsigned int)random());
1286 secname[GLOBAL] = talloc_asprintf(tctx, "G$torturesecret-%u", (unsigned int)random());
1288 for (i=0; i< 2; i++) {
1289 torture_comment(tctx, "\nTesting CreateSecret of %s\n", secname[i]);
1291 init_lsa_String(&r.in.name, secname[i]);
1293 r.in.handle = handle;
1294 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1295 r.out.sec_handle = &sec_handle;
1297 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_CreateSecret_r(b, tctx, &r),
1298 "CreateSecret failed");
1299 if (!NT_STATUS_IS_OK(r.out.result)) {
1300 torture_comment(tctx, "CreateSecret failed - %s\n", nt_errstr(r.out.result));
1304 r.in.handle = handle;
1305 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1306 r.out.sec_handle = &sec_handle3;
1308 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_CreateSecret_r(b, tctx, &r),
1309 "CreateSecret failed");
1310 if (!NT_STATUS_EQUAL(r.out.result, NT_STATUS_OBJECT_NAME_COLLISION)) {
1311 torture_comment(tctx, "CreateSecret should have failed OBJECT_NAME_COLLISION - %s\n", nt_errstr(r.out.result));
1315 r2.in.handle = handle;
1316 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1317 r2.in.name = r.in.name;
1318 r2.out.sec_handle = &sec_handle2;
1320 torture_comment(tctx, "Testing OpenSecret\n");
1322 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenSecret_r(b, tctx, &r2),
1323 "OpenSecret failed");
1324 if (!NT_STATUS_IS_OK(r2.out.result)) {
1325 torture_comment(tctx, "OpenSecret failed - %s\n", nt_errstr(r2.out.result));
1329 status = dcerpc_fetch_session_key(p, &session_key);
1330 if (!NT_STATUS_IS_OK(status)) {
1331 torture_comment(tctx, "dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
1335 enc_key = sess_encrypt_string(secret1, &session_key);
1337 r3.in.sec_handle = &sec_handle;
1338 r3.in.new_val = &buf1;
1339 r3.in.old_val = NULL;
1340 r3.in.new_val->data = enc_key.data;
1341 r3.in.new_val->length = enc_key.length;
1342 r3.in.new_val->size = enc_key.length;
1344 torture_comment(tctx, "Testing SetSecret\n");
1346 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_SetSecret_r(b, tctx, &r3),
1347 "SetSecret failed");
1348 if (!NT_STATUS_IS_OK(r3.out.result)) {
1349 torture_comment(tctx, "SetSecret failed - %s\n", nt_errstr(r3.out.result));
1353 r3.in.sec_handle = &sec_handle;
1354 r3.in.new_val = &buf1;
1355 r3.in.old_val = NULL;
1356 r3.in.new_val->data = enc_key.data;
1357 r3.in.new_val->length = enc_key.length;
1358 r3.in.new_val->size = enc_key.length;
1360 /* break the encrypted data */
1363 torture_comment(tctx, "Testing SetSecret with broken key\n");
1365 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_SetSecret_r(b, tctx, &r3),
1366 "SetSecret failed");
1367 if (!NT_STATUS_EQUAL(r3.out.result, NT_STATUS_UNKNOWN_REVISION)) {
1368 torture_comment(tctx, "SetSecret should have failed UNKNOWN_REVISION - %s\n", nt_errstr(r3.out.result));
1372 data_blob_free(&enc_key);
1374 ZERO_STRUCT(new_mtime);
1375 ZERO_STRUCT(old_mtime);
1377 /* fetch the secret back again */
1378 r4.in.sec_handle = &sec_handle;
1379 r4.in.new_val = &bufp1;
1380 r4.in.new_mtime = &new_mtime;
1381 r4.in.old_val = NULL;
1382 r4.in.old_mtime = NULL;
1386 torture_comment(tctx, "Testing QuerySecret\n");
1387 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QuerySecret_r(b, tctx, &r4),
1388 "QuerySecret failed");
1389 if (!NT_STATUS_IS_OK(r4.out.result)) {
1390 torture_comment(tctx, "QuerySecret failed - %s\n", nt_errstr(r4.out.result));
1393 if (r4.out.new_val == NULL || r4.out.new_val->buf == NULL) {
1394 torture_comment(tctx, "No secret buffer returned\n");
1397 blob1.data = r4.out.new_val->buf->data;
1398 blob1.length = r4.out.new_val->buf->size;
1400 blob2 = data_blob_talloc(tctx, NULL, blob1.length);
1402 secret2 = sess_decrypt_string(tctx,
1403 &blob1, &session_key);
1405 if (strcmp(secret1, secret2) != 0) {
1406 torture_comment(tctx, "Returned secret (r4) '%s' doesn't match '%s'\n",
1413 enc_key = sess_encrypt_string(secret3, &session_key);
1415 r5.in.sec_handle = &sec_handle;
1416 r5.in.new_val = &buf1;
1417 r5.in.old_val = NULL;
1418 r5.in.new_val->data = enc_key.data;
1419 r5.in.new_val->length = enc_key.length;
1420 r5.in.new_val->size = enc_key.length;
1424 torture_comment(tctx, "Testing SetSecret (existing value should move to old)\n");
1426 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_SetSecret_r(b, tctx, &r5),
1427 "SetSecret failed");
1428 if (!NT_STATUS_IS_OK(r5.out.result)) {
1429 torture_comment(tctx, "SetSecret failed - %s\n", nt_errstr(r5.out.result));
1433 data_blob_free(&enc_key);
1435 ZERO_STRUCT(new_mtime);
1436 ZERO_STRUCT(old_mtime);
1438 /* fetch the secret back again */
1439 r6.in.sec_handle = &sec_handle;
1440 r6.in.new_val = &bufp1;
1441 r6.in.new_mtime = &new_mtime;
1442 r6.in.old_val = &bufp2;
1443 r6.in.old_mtime = &old_mtime;
1448 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QuerySecret_r(b, tctx, &r6),
1449 "QuerySecret failed");
1450 if (!NT_STATUS_IS_OK(r6.out.result)) {
1451 torture_comment(tctx, "QuerySecret failed - %s\n", nt_errstr(r6.out.result));
1456 if (r6.out.new_val->buf == NULL || r6.out.old_val->buf == NULL
1457 || r6.out.new_mtime == NULL || r6.out.old_mtime == NULL) {
1458 torture_comment(tctx, "Both secret buffers and both times not returned\n");
1462 blob1.data = r6.out.new_val->buf->data;
1463 blob1.length = r6.out.new_val->buf->size;
1465 blob2 = data_blob_talloc(tctx, NULL, blob1.length);
1467 secret4 = sess_decrypt_string(tctx,
1468 &blob1, &session_key);
1470 if (strcmp(secret3, secret4) != 0) {
1471 torture_comment(tctx, "Returned NEW secret %s doesn't match %s\n", secret4, secret3);
1475 blob1.data = r6.out.old_val->buf->data;
1476 blob1.length = r6.out.old_val->buf->length;
1478 blob2 = data_blob_talloc(tctx, NULL, blob1.length);
1480 secret2 = sess_decrypt_string(tctx,
1481 &blob1, &session_key);
1483 if (strcmp(secret1, secret2) != 0) {
1484 torture_comment(tctx, "Returned OLD secret %s doesn't match %s\n", secret2, secret1);
1488 if (*r6.out.new_mtime == *r6.out.old_mtime) {
1489 torture_comment(tctx, "Returned secret (r6-%d) %s must not have same mtime for both secrets: %s != %s\n",
1492 nt_time_string(tctx, *r6.out.old_mtime),
1493 nt_time_string(tctx, *r6.out.new_mtime));
1499 enc_key = sess_encrypt_string(secret5, &session_key);
1501 r7.in.sec_handle = &sec_handle;
1502 r7.in.old_val = &buf1;
1503 r7.in.old_val->data = enc_key.data;
1504 r7.in.old_val->length = enc_key.length;
1505 r7.in.old_val->size = enc_key.length;
1506 r7.in.new_val = NULL;
1508 torture_comment(tctx, "Testing SetSecret of old Secret only\n");
1510 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_SetSecret_r(b, tctx, &r7),
1511 "SetSecret failed");
1512 if (!NT_STATUS_IS_OK(r7.out.result)) {
1513 torture_comment(tctx, "SetSecret failed - %s\n", nt_errstr(r7.out.result));
1517 data_blob_free(&enc_key);
1519 /* fetch the secret back again */
1520 r8.in.sec_handle = &sec_handle;
1521 r8.in.new_val = &bufp1;
1522 r8.in.new_mtime = &new_mtime;
1523 r8.in.old_val = &bufp2;
1524 r8.in.old_mtime = &old_mtime;
1529 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QuerySecret_r(b, tctx, &r8),
1530 "QuerySecret failed");
1531 if (!NT_STATUS_IS_OK(r8.out.result)) {
1532 torture_comment(tctx, "QuerySecret failed - %s\n", nt_errstr(r8.out.result));
1535 if (!r8.out.new_val || !r8.out.old_val) {
1536 torture_comment(tctx, "in/out pointers not returned, despite being set on in for QuerySecret\n");
1538 } else if (r8.out.new_val->buf != NULL) {
1539 torture_comment(tctx, "NEW secret buffer must not be returned after OLD set\n");
1541 } else if (r8.out.old_val->buf == NULL) {
1542 torture_comment(tctx, "OLD secret buffer was not returned after OLD set\n");
1544 } else if (r8.out.new_mtime == NULL || r8.out.old_mtime == NULL) {
1545 torture_comment(tctx, "Both times not returned after OLD set\n");
1548 blob1.data = r8.out.old_val->buf->data;
1549 blob1.length = r8.out.old_val->buf->size;
1551 blob2 = data_blob_talloc(tctx, NULL, blob1.length);
1553 secret6 = sess_decrypt_string(tctx,
1554 &blob1, &session_key);
1556 if (strcmp(secret5, secret6) != 0) {
1557 torture_comment(tctx, "Returned OLD secret %s doesn't match %s\n", secret5, secret6);
1561 if (*r8.out.new_mtime != *r8.out.old_mtime) {
1562 torture_comment(tctx, "Returned secret (r8) %s did not had same mtime for both secrets: %s != %s\n",
1564 nt_time_string(tctx, *r8.out.old_mtime),
1565 nt_time_string(tctx, *r8.out.new_mtime));
1571 if (!test_Delete(b, tctx, &sec_handle)) {
1575 if (!test_DeleteObject(b, tctx, &sec_handle)) {
1579 d_o.in.handle = &sec_handle2;
1580 d_o.out.handle = &sec_handle2;
1581 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_DeleteObject_r(b, tctx, &d_o),
1582 "DeleteObject failed");
1583 if (!NT_STATUS_EQUAL(d_o.out.result, NT_STATUS_INVALID_HANDLE)) {
1584 torture_comment(tctx, "Second delete expected INVALID_HANDLE - %s\n", nt_errstr(d_o.out.result));
1588 torture_comment(tctx, "Testing OpenSecret of just-deleted secret\n");
1590 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenSecret_r(b, tctx, &r2),
1591 "OpenSecret failed");
1592 if (!NT_STATUS_EQUAL(r2.out.result, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
1593 torture_comment(tctx, "OpenSecret expected OBJECT_NAME_NOT_FOUND - %s\n", nt_errstr(r2.out.result));
1604 static bool test_EnumAccountRights(struct dcerpc_binding_handle *b,
1605 struct torture_context *tctx,
1606 struct policy_handle *acct_handle,
1607 struct dom_sid *sid)
1609 struct lsa_EnumAccountRights r;
1610 struct lsa_RightSet rights;
1612 torture_comment(tctx, "\nTesting EnumAccountRights\n");
1614 r.in.handle = acct_handle;
1616 r.out.rights = &rights;
1618 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumAccountRights_r(b, tctx, &r),
1619 "EnumAccountRights failed");
1620 if (!NT_STATUS_IS_OK(r.out.result)) {
1621 torture_comment(tctx, "EnumAccountRights of %s failed - %s\n",
1622 dom_sid_string(tctx, sid), nt_errstr(r.out.result));
1630 static bool test_QuerySecurity(struct dcerpc_binding_handle *b,
1631 struct torture_context *tctx,
1632 struct policy_handle *handle,
1633 struct policy_handle *acct_handle)
1635 struct lsa_QuerySecurity r;
1636 struct sec_desc_buf *sdbuf = NULL;
1638 if (torture_setting_bool(tctx, "samba4", false)) {
1639 torture_comment(tctx, "\nskipping QuerySecurity test against Samba4\n");
1643 torture_comment(tctx, "\nTesting QuerySecurity\n");
1645 r.in.handle = acct_handle;
1646 r.in.sec_info = SECINFO_OWNER |
1649 r.out.sdbuf = &sdbuf;
1651 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QuerySecurity_r(b, tctx, &r),
1652 "QuerySecurity failed");
1653 if (!NT_STATUS_IS_OK(r.out.result)) {
1654 torture_comment(tctx, "QuerySecurity failed - %s\n", nt_errstr(r.out.result));
1661 static bool test_OpenAccount(struct dcerpc_binding_handle *b,
1662 struct torture_context *tctx,
1663 struct policy_handle *handle,
1664 struct dom_sid *sid)
1666 struct lsa_OpenAccount r;
1667 struct policy_handle acct_handle;
1669 torture_comment(tctx, "\nTesting OpenAccount\n");
1671 r.in.handle = handle;
1673 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1674 r.out.acct_handle = &acct_handle;
1676 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenAccount_r(b, tctx, &r),
1677 "OpenAccount failed");
1678 if (!NT_STATUS_IS_OK(r.out.result)) {
1679 torture_comment(tctx, "OpenAccount failed - %s\n", nt_errstr(r.out.result));
1683 if (!test_EnumPrivsAccount(b, tctx, handle, &acct_handle)) {
1687 if (!test_GetSystemAccessAccount(b, tctx, handle, &acct_handle)) {
1691 if (!test_QuerySecurity(b, tctx, handle, &acct_handle)) {
1698 static bool test_EnumAccounts(struct dcerpc_binding_handle *b,
1699 struct torture_context *tctx,
1700 struct policy_handle *handle)
1702 struct lsa_EnumAccounts r;
1703 struct lsa_SidArray sids1, sids2;
1704 uint32_t resume_handle = 0;
1708 torture_comment(tctx, "\nTesting EnumAccounts\n");
1710 r.in.handle = handle;
1711 r.in.resume_handle = &resume_handle;
1712 r.in.num_entries = 100;
1713 r.out.resume_handle = &resume_handle;
1714 r.out.sids = &sids1;
1718 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumAccounts_r(b, tctx, &r),
1719 "EnumAccounts failed");
1720 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_NO_MORE_ENTRIES)) {
1723 if (!NT_STATUS_IS_OK(r.out.result)) {
1724 torture_comment(tctx, "EnumAccounts failed - %s\n", nt_errstr(r.out.result));
1728 if (!test_LookupSids(b, tctx, handle, &sids1)) {
1732 if (!test_LookupSids2(b, tctx, handle, &sids1)) {
1736 /* Can't test lookupSids3 here, as clearly we must not
1737 * be on schannel, or we would not be able to do the
1740 torture_comment(tctx, "Testing all accounts\n");
1741 for (i=0;i<sids1.num_sids;i++) {
1742 ret &= test_OpenAccount(b, tctx, handle, sids1.sids[i].sid);
1743 ret &= test_EnumAccountRights(b, tctx, handle, sids1.sids[i].sid);
1745 torture_comment(tctx, "\n");
1748 if (sids1.num_sids < 3) {
1752 torture_comment(tctx, "Trying EnumAccounts partial listing (asking for 1 at 2)\n");
1754 r.in.num_entries = 1;
1755 r.out.sids = &sids2;
1757 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumAccounts_r(b, tctx, &r),
1758 "EnumAccounts failed");
1759 if (!NT_STATUS_IS_OK(r.out.result)) {
1760 torture_comment(tctx, "EnumAccounts failed - %s\n", nt_errstr(r.out.result));
1764 if (sids2.num_sids != 1) {
1765 torture_comment(tctx, "Returned wrong number of entries (%d)\n", sids2.num_sids);
1772 static bool test_LookupPrivDisplayName(struct dcerpc_binding_handle *b,
1773 struct torture_context *tctx,
1774 struct policy_handle *handle,
1775 struct lsa_String *priv_name)
1777 struct lsa_LookupPrivDisplayName r;
1778 /* produce a reasonable range of language output without screwing up
1780 uint16_t language_id = (random() % 4) + 0x409;
1781 uint16_t returned_language_id = 0;
1782 struct lsa_StringLarge *disp_name = NULL;
1784 torture_comment(tctx, "\nTesting LookupPrivDisplayName(%s)\n", priv_name->string);
1786 r.in.handle = handle;
1787 r.in.name = priv_name;
1788 r.in.language_id = language_id;
1789 r.in.language_id_sys = 0;
1790 r.out.returned_language_id = &returned_language_id;
1791 r.out.disp_name = &disp_name;
1793 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupPrivDisplayName_r(b, tctx, &r),
1794 "LookupPrivDisplayName failed");
1795 if (!NT_STATUS_IS_OK(r.out.result)) {
1796 torture_comment(tctx, "LookupPrivDisplayName failed - %s\n", nt_errstr(r.out.result));
1799 torture_comment(tctx, "%s -> \"%s\" (language 0x%x/0x%x)\n",
1800 priv_name->string, disp_name->string,
1801 r.in.language_id, *r.out.returned_language_id);
1806 static bool test_EnumAccountsWithUserRight(struct dcerpc_binding_handle *b,
1807 struct torture_context *tctx,
1808 struct policy_handle *handle,
1809 struct lsa_String *priv_name)
1811 struct lsa_EnumAccountsWithUserRight r;
1812 struct lsa_SidArray sids;
1816 torture_comment(tctx, "\nTesting EnumAccountsWithUserRight(%s)\n", priv_name->string);
1818 r.in.handle = handle;
1819 r.in.name = priv_name;
1822 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumAccountsWithUserRight_r(b, tctx, &r),
1823 "EnumAccountsWithUserRight failed");
1825 /* NT_STATUS_NO_MORE_ENTRIES means noone has this privilege */
1826 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_NO_MORE_ENTRIES)) {
1830 if (!NT_STATUS_IS_OK(r.out.result)) {
1831 torture_comment(tctx, "EnumAccountsWithUserRight failed - %s\n", nt_errstr(r.out.result));
1839 static bool test_EnumPrivs(struct dcerpc_binding_handle *b,
1840 struct torture_context *tctx,
1841 struct policy_handle *handle)
1843 struct lsa_EnumPrivs r;
1844 struct lsa_PrivArray privs1;
1845 uint32_t resume_handle = 0;
1849 torture_comment(tctx, "\nTesting EnumPrivs\n");
1851 r.in.handle = handle;
1852 r.in.resume_handle = &resume_handle;
1853 r.in.max_count = 100;
1854 r.out.resume_handle = &resume_handle;
1855 r.out.privs = &privs1;
1858 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumPrivs_r(b, tctx, &r),
1859 "EnumPrivs failed");
1860 if (!NT_STATUS_IS_OK(r.out.result)) {
1861 torture_comment(tctx, "EnumPrivs failed - %s\n", nt_errstr(r.out.result));
1865 for (i = 0; i< privs1.count; i++) {
1866 test_LookupPrivDisplayName(b, tctx, handle, (struct lsa_String *)&privs1.privs[i].name);
1867 test_LookupPrivValue(b, tctx, handle, (struct lsa_String *)&privs1.privs[i].name);
1868 if (!test_EnumAccountsWithUserRight(b, tctx, handle, (struct lsa_String *)&privs1.privs[i].name)) {
1876 static bool test_QueryForestTrustInformation(struct dcerpc_binding_handle *b,
1877 struct torture_context *tctx,
1878 struct policy_handle *handle,
1879 const char *trusted_domain_name)
1882 struct lsa_lsaRQueryForestTrustInformation r;
1883 struct lsa_String string;
1884 struct lsa_ForestTrustInformation info, *info_ptr;
1886 torture_comment(tctx, "\nTesting lsaRQueryForestTrustInformation\n");
1888 if (torture_setting_bool(tctx, "samba4", false)) {
1889 torture_comment(tctx, "skipping QueryForestTrustInformation against Samba4\n");
1893 ZERO_STRUCT(string);
1895 if (trusted_domain_name) {
1896 init_lsa_String(&string, trusted_domain_name);
1901 r.in.handle = handle;
1902 r.in.trusted_domain_name = &string;
1904 r.out.forest_trust_info = &info_ptr;
1906 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_lsaRQueryForestTrustInformation_r(b, tctx, &r),
1907 "lsaRQueryForestTrustInformation failed");
1909 if (!NT_STATUS_IS_OK(r.out.result)) {
1910 torture_comment(tctx, "lsaRQueryForestTrustInformation of %s failed - %s\n", trusted_domain_name, nt_errstr(r.out.result));
1917 static bool test_query_each_TrustDomEx(struct dcerpc_binding_handle *b,
1918 struct torture_context *tctx,
1919 struct policy_handle *handle,
1920 struct lsa_DomainListEx *domains)
1925 for (i=0; i< domains->count; i++) {
1927 if (domains->domains[i].trust_attributes & NETR_TRUST_ATTRIBUTE_FOREST_TRANSITIVE) {
1928 ret &= test_QueryForestTrustInformation(b, tctx, handle,
1929 domains->domains[i].domain_name.string);
1936 static bool test_query_each_TrustDom(struct dcerpc_binding_handle *b,
1937 struct torture_context *tctx,
1938 struct policy_handle *handle,
1939 struct lsa_DomainList *domains)
1944 torture_comment(tctx, "\nTesting OpenTrustedDomain, OpenTrustedDomainByName and QueryInfoTrustedDomain\n");
1945 for (i=0; i< domains->count; i++) {
1946 struct lsa_OpenTrustedDomain trust;
1947 struct lsa_OpenTrustedDomainByName trust_by_name;
1948 struct policy_handle trustdom_handle;
1949 struct policy_handle handle2;
1951 struct lsa_CloseTrustedDomainEx c_trust;
1952 int levels [] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
1953 int ok[] = {1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1};
1955 if (domains->domains[i].sid) {
1956 trust.in.handle = handle;
1957 trust.in.sid = domains->domains[i].sid;
1958 trust.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1959 trust.out.trustdom_handle = &trustdom_handle;
1961 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenTrustedDomain_r(b, tctx, &trust),
1962 "OpenTrustedDomain failed");
1964 if (!NT_STATUS_IS_OK(trust.out.result)) {
1965 torture_comment(tctx, "OpenTrustedDomain failed - %s\n", nt_errstr(trust.out.result));
1969 c.in.handle = &trustdom_handle;
1970 c.out.handle = &handle2;
1972 c_trust.in.handle = &trustdom_handle;
1973 c_trust.out.handle = &handle2;
1975 for (j=0; j < ARRAY_SIZE(levels); j++) {
1976 struct lsa_QueryTrustedDomainInfo q;
1977 union lsa_TrustedDomainInfo *info = NULL;
1978 q.in.trustdom_handle = &trustdom_handle;
1979 q.in.level = levels[j];
1981 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryTrustedDomainInfo_r(b, tctx, &q),
1982 "QueryTrustedDomainInfo failed");
1983 if (!NT_STATUS_IS_OK(q.out.result) && ok[j]) {
1984 torture_comment(tctx, "QueryTrustedDomainInfo level %d failed - %s\n",
1985 levels[j], nt_errstr(q.out.result));
1987 } else if (NT_STATUS_IS_OK(q.out.result) && !ok[j]) {
1988 torture_comment(tctx, "QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
1989 levels[j], nt_errstr(q.out.result));
1994 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_CloseTrustedDomainEx_r(b, tctx, &c_trust),
1995 "CloseTrustedDomainEx failed");
1996 if (!NT_STATUS_EQUAL(c_trust.out.result, NT_STATUS_NOT_IMPLEMENTED)) {
1997 torture_comment(tctx, "Expected CloseTrustedDomainEx to return NT_STATUS_NOT_IMPLEMENTED, instead - %s\n", nt_errstr(c_trust.out.result));
2001 c.in.handle = &trustdom_handle;
2002 c.out.handle = &handle2;
2004 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_Close_r(b, tctx, &c),
2006 if (!NT_STATUS_IS_OK(c.out.result)) {
2007 torture_comment(tctx, "Close of trusted domain failed - %s\n", nt_errstr(c.out.result));
2011 for (j=0; j < ARRAY_SIZE(levels); j++) {
2012 struct lsa_QueryTrustedDomainInfoBySid q;
2013 union lsa_TrustedDomainInfo *info = NULL;
2015 if (!domains->domains[i].sid) {
2019 q.in.handle = handle;
2020 q.in.dom_sid = domains->domains[i].sid;
2021 q.in.level = levels[j];
2024 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryTrustedDomainInfoBySid_r(b, tctx, &q),
2025 "lsa_QueryTrustedDomainInfoBySid failed");
2026 if (!NT_STATUS_IS_OK(q.out.result) && ok[j]) {
2027 torture_comment(tctx, "QueryTrustedDomainInfoBySid level %d failed - %s\n",
2028 levels[j], nt_errstr(q.out.result));
2030 } else if (NT_STATUS_IS_OK(q.out.result) && !ok[j]) {
2031 torture_comment(tctx, "QueryTrustedDomainInfoBySid level %d unexpectedly succeeded - %s\n",
2032 levels[j], nt_errstr(q.out.result));
2038 trust_by_name.in.handle = handle;
2039 trust_by_name.in.name.string = domains->domains[i].name.string;
2040 trust_by_name.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2041 trust_by_name.out.trustdom_handle = &trustdom_handle;
2043 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenTrustedDomainByName_r(b, tctx, &trust_by_name),
2044 "OpenTrustedDomainByName failed");
2046 if (!NT_STATUS_IS_OK(trust_by_name.out.result)) {
2047 torture_comment(tctx, "OpenTrustedDomainByName failed - %s\n", nt_errstr(trust_by_name.out.result));
2051 for (j=0; j < ARRAY_SIZE(levels); j++) {
2052 struct lsa_QueryTrustedDomainInfo q;
2053 union lsa_TrustedDomainInfo *info = NULL;
2054 q.in.trustdom_handle = &trustdom_handle;
2055 q.in.level = levels[j];
2057 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryTrustedDomainInfo_r(b, tctx, &q),
2058 "QueryTrustedDomainInfo failed");
2059 if (!NT_STATUS_IS_OK(q.out.result) && ok[j]) {
2060 torture_comment(tctx, "QueryTrustedDomainInfo level %d failed - %s\n",
2061 levels[j], nt_errstr(q.out.result));
2063 } else if (NT_STATUS_IS_OK(q.out.result) && !ok[j]) {
2064 torture_comment(tctx, "QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
2065 levels[j], nt_errstr(q.out.result));
2070 c.in.handle = &trustdom_handle;
2071 c.out.handle = &handle2;
2073 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_Close_r(b, tctx, &c),
2075 if (!NT_STATUS_IS_OK(c.out.result)) {
2076 torture_comment(tctx, "Close of trusted domain failed - %s\n", nt_errstr(c.out.result));
2080 for (j=0; j < ARRAY_SIZE(levels); j++) {
2081 struct lsa_QueryTrustedDomainInfoByName q;
2082 union lsa_TrustedDomainInfo *info = NULL;
2083 struct lsa_String name;
2085 name.string = domains->domains[i].name.string;
2087 q.in.handle = handle;
2088 q.in.trusted_domain = &name;
2089 q.in.level = levels[j];
2091 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryTrustedDomainInfoByName_r(b, tctx, &q),
2092 "QueryTrustedDomainInfoByName failed");
2093 if (!NT_STATUS_IS_OK(q.out.result) && ok[j]) {
2094 torture_comment(tctx, "QueryTrustedDomainInfoByName level %d failed - %s\n",
2095 levels[j], nt_errstr(q.out.result));
2097 } else if (NT_STATUS_IS_OK(q.out.result) && !ok[j]) {
2098 torture_comment(tctx, "QueryTrustedDomainInfoByName level %d unexpectedly succeeded - %s\n",
2099 levels[j], nt_errstr(q.out.result));
2107 static bool test_EnumTrustDom(struct dcerpc_binding_handle *b,
2108 struct torture_context *tctx,
2109 struct policy_handle *handle)
2111 struct lsa_EnumTrustDom r;
2112 uint32_t in_resume_handle = 0;
2113 uint32_t out_resume_handle;
2114 struct lsa_DomainList domains;
2117 torture_comment(tctx, "\nTesting EnumTrustDom\n");
2119 r.in.handle = handle;
2120 r.in.resume_handle = &in_resume_handle;
2122 r.out.domains = &domains;
2123 r.out.resume_handle = &out_resume_handle;
2125 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumTrustDom_r(b, tctx, &r),
2126 "lsa_EnumTrustDom failed");
2128 /* according to MS-LSAD 3.1.4.7.8 output resume handle MUST
2129 * always be larger than the previous input resume handle, in
2130 * particular when hitting the last query it is vital to set the
2131 * resume handle correctly to avoid infinite client loops, as
2132 * seen e.g. with Windows XP SP3 when resume handle is 0 and
2133 * status is NT_STATUS_OK - gd */
2135 if (NT_STATUS_IS_OK(r.out.result) ||
2136 NT_STATUS_EQUAL(r.out.result, NT_STATUS_NO_MORE_ENTRIES) ||
2137 NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES))
2139 if (out_resume_handle <= in_resume_handle) {
2140 torture_comment(tctx, "EnumTrustDom failed - should have returned output resume_handle (0x%08x) larger than input resume handle (0x%08x)\n",
2141 out_resume_handle, in_resume_handle);
2146 if (NT_STATUS_IS_OK(r.out.result)) {
2147 if (domains.count == 0) {
2148 torture_comment(tctx, "EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2151 } else if (!(NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES) || NT_STATUS_EQUAL(r.out.result, NT_STATUS_NO_MORE_ENTRIES))) {
2152 torture_comment(tctx, "EnumTrustDom of zero size failed - %s\n", nt_errstr(r.out.result));
2156 /* Start from the bottom again */
2157 in_resume_handle = 0;
2160 r.in.handle = handle;
2161 r.in.resume_handle = &in_resume_handle;
2162 r.in.max_size = LSA_ENUM_TRUST_DOMAIN_MULTIPLIER * 3;
2163 r.out.domains = &domains;
2164 r.out.resume_handle = &out_resume_handle;
2166 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumTrustDom_r(b, tctx, &r),
2167 "EnumTrustDom failed");
2169 /* according to MS-LSAD 3.1.4.7.8 output resume handle MUST
2170 * always be larger than the previous input resume handle, in
2171 * particular when hitting the last query it is vital to set the
2172 * resume handle correctly to avoid infinite client loops, as
2173 * seen e.g. with Windows XP SP3 when resume handle is 0 and
2174 * status is NT_STATUS_OK - gd */
2176 if (NT_STATUS_IS_OK(r.out.result) ||
2177 NT_STATUS_EQUAL(r.out.result, NT_STATUS_NO_MORE_ENTRIES) ||
2178 NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES))
2180 if (out_resume_handle <= in_resume_handle) {
2181 torture_comment(tctx, "EnumTrustDom failed - should have returned output resume_handle (0x%08x) larger than input resume handle (0x%08x)\n",
2182 out_resume_handle, in_resume_handle);
2187 /* NO_MORE_ENTRIES is allowed */
2188 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_NO_MORE_ENTRIES)) {
2189 if (domains.count == 0) {
2192 torture_comment(tctx, "EnumTrustDom failed - should have returned 0 trusted domains with 'NT_STATUS_NO_MORE_ENTRIES'\n");
2194 } else if (NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES)) {
2195 /* Windows 2003 gets this off by one on the first run */
2196 if (r.out.domains->count < 3 || r.out.domains->count > 4) {
2197 torture_comment(tctx, "EnumTrustDom didn't fill the buffer we "
2198 "asked it to (got %d, expected %d / %d == %d entries)\n",
2199 r.out.domains->count, LSA_ENUM_TRUST_DOMAIN_MULTIPLIER * 3,
2200 LSA_ENUM_TRUST_DOMAIN_MULTIPLIER, r.in.max_size);
2203 } else if (!NT_STATUS_IS_OK(r.out.result)) {
2204 torture_comment(tctx, "EnumTrustDom failed - %s\n", nt_errstr(r.out.result));
2208 if (domains.count == 0) {
2209 torture_comment(tctx, "EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2213 ret &= test_query_each_TrustDom(b, tctx, handle, &domains);
2215 in_resume_handle = out_resume_handle;
2217 } while ((NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES)));
2222 static bool test_EnumTrustDomEx(struct dcerpc_binding_handle *b,
2223 struct torture_context *tctx,
2224 struct policy_handle *handle)
2226 struct lsa_EnumTrustedDomainsEx r_ex;
2227 uint32_t resume_handle = 0;
2228 struct lsa_DomainListEx domains_ex;
2231 torture_comment(tctx, "\nTesting EnumTrustedDomainsEx\n");
2233 r_ex.in.handle = handle;
2234 r_ex.in.resume_handle = &resume_handle;
2235 r_ex.in.max_size = LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER * 3;
2236 r_ex.out.domains = &domains_ex;
2237 r_ex.out.resume_handle = &resume_handle;
2239 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumTrustedDomainsEx_r(b, tctx, &r_ex),
2240 "EnumTrustedDomainsEx failed");
2242 if (!(NT_STATUS_EQUAL(r_ex.out.result, STATUS_MORE_ENTRIES) || NT_STATUS_EQUAL(r_ex.out.result, NT_STATUS_NO_MORE_ENTRIES))) {
2243 torture_comment(tctx, "EnumTrustedDomainEx of zero size failed - %s\n", nt_errstr(r_ex.out.result));
2249 r_ex.in.handle = handle;
2250 r_ex.in.resume_handle = &resume_handle;
2251 r_ex.in.max_size = LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER * 3;
2252 r_ex.out.domains = &domains_ex;
2253 r_ex.out.resume_handle = &resume_handle;
2255 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumTrustedDomainsEx_r(b, tctx, &r_ex),
2256 "EnumTrustedDomainsEx failed");
2258 /* NO_MORE_ENTRIES is allowed */
2259 if (NT_STATUS_EQUAL(r_ex.out.result, NT_STATUS_NO_MORE_ENTRIES)) {
2260 if (domains_ex.count == 0) {
2263 torture_comment(tctx, "EnumTrustDomainsEx failed - should have returned 0 trusted domains with 'NT_STATUS_NO_MORE_ENTRIES'\n");
2265 } else if (NT_STATUS_EQUAL(r_ex.out.result, STATUS_MORE_ENTRIES)) {
2266 /* Windows 2003 gets this off by one on the first run */
2267 if (r_ex.out.domains->count < 3 || r_ex.out.domains->count > 4) {
2268 torture_comment(tctx, "EnumTrustDom didn't fill the buffer we "
2269 "asked it to (got %d, expected %d / %d == %d entries)\n",
2270 r_ex.out.domains->count,
2272 LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER,
2273 r_ex.in.max_size / LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER);
2275 } else if (!NT_STATUS_IS_OK(r_ex.out.result)) {
2276 torture_comment(tctx, "EnumTrustedDomainEx failed - %s\n", nt_errstr(r_ex.out.result));
2280 if (domains_ex.count == 0) {
2281 torture_comment(tctx, "EnumTrustDomainEx failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2285 ret &= test_query_each_TrustDomEx(b, tctx, handle, &domains_ex);
2287 } while ((NT_STATUS_EQUAL(r_ex.out.result, STATUS_MORE_ENTRIES)));
2293 static bool test_CreateTrustedDomain(struct dcerpc_binding_handle *b,
2294 struct torture_context *tctx,
2295 struct policy_handle *handle,
2296 uint32_t num_trusts)
2299 struct lsa_CreateTrustedDomain r;
2300 struct lsa_DomainInfo trustinfo;
2301 struct dom_sid **domsid;
2302 struct policy_handle *trustdom_handle;
2303 struct lsa_QueryTrustedDomainInfo q;
2304 union lsa_TrustedDomainInfo *info = NULL;
2307 torture_comment(tctx, "\nTesting CreateTrustedDomain for %d domains\n", num_trusts);
2309 if (!test_EnumTrustDom(b, tctx, handle)) {
2313 if (!test_EnumTrustDomEx(b, tctx, handle)) {
2317 domsid = talloc_array(tctx, struct dom_sid *, num_trusts);
2318 trustdom_handle = talloc_array(tctx, struct policy_handle, num_trusts);
2320 for (i=0; i< num_trusts; i++) {
2321 char *trust_name = talloc_asprintf(tctx, "torturedom%02d", i);
2322 char *trust_sid = talloc_asprintf(tctx, "S-1-5-21-97398-379795-100%02d", i);
2324 domsid[i] = dom_sid_parse_talloc(tctx, trust_sid);
2326 trustinfo.sid = domsid[i];
2327 init_lsa_String((struct lsa_String *)&trustinfo.name, trust_name);
2329 r.in.policy_handle = handle;
2330 r.in.info = &trustinfo;
2331 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2332 r.out.trustdom_handle = &trustdom_handle[i];
2334 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_CreateTrustedDomain_r(b, tctx, &r),
2335 "CreateTrustedDomain failed");
2336 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_OBJECT_NAME_COLLISION)) {
2337 test_DeleteTrustedDomain(b, tctx, handle, trustinfo.name);
2338 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_CreateTrustedDomain_r(b, tctx, &r),
2339 "CreateTrustedDomain failed");
2341 if (!NT_STATUS_IS_OK(r.out.result)) {
2342 torture_comment(tctx, "CreateTrustedDomain failed - %s\n", nt_errstr(r.out.result));
2346 q.in.trustdom_handle = &trustdom_handle[i];
2347 q.in.level = LSA_TRUSTED_DOMAIN_INFO_INFO_EX;
2349 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryTrustedDomainInfo_r(b, tctx, &q),
2350 "QueryTrustedDomainInfo failed");
2351 if (!NT_STATUS_IS_OK(q.out.result)) {
2352 torture_comment(tctx, "QueryTrustedDomainInfo level %d failed - %s\n", q.in.level, nt_errstr(q.out.result));
2354 } else if (!q.out.info) {
2357 if (strcmp(info->info_ex.netbios_name.string, trustinfo.name.string) != 0) {
2358 torture_comment(tctx, "QueryTrustedDomainInfo returned inconsistent short name: %s != %s\n",
2359 info->info_ex.netbios_name.string, trustinfo.name.string);
2362 if (info->info_ex.trust_type != LSA_TRUST_TYPE_DOWNLEVEL) {
2363 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
2364 trust_name, info->info_ex.trust_type, LSA_TRUST_TYPE_DOWNLEVEL);
2367 if (info->info_ex.trust_attributes != 0) {
2368 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
2369 trust_name, info->info_ex.trust_attributes, 0);
2372 if (info->info_ex.trust_direction != LSA_TRUST_DIRECTION_OUTBOUND) {
2373 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
2374 trust_name, info->info_ex.trust_direction, LSA_TRUST_DIRECTION_OUTBOUND);
2381 /* now that we have some domains to look over, we can test the enum calls */
2382 if (!test_EnumTrustDom(b, tctx, handle)) {
2386 if (!test_EnumTrustDomEx(b, tctx, handle)) {
2390 for (i=0; i<num_trusts; i++) {
2391 if (!test_DeleteTrustedDomainBySid(b, tctx, handle, domsid[i])) {
2399 static bool gen_authinfo_internal(TALLOC_CTX *mem_ctx, const char *password,
2400 DATA_BLOB session_key,
2401 struct lsa_TrustDomainInfoAuthInfoInternal **_authinfo_internal)
2403 struct lsa_TrustDomainInfoAuthInfoInternal *authinfo_internal;
2404 struct trustDomainPasswords auth_struct;
2405 struct AuthenticationInformation *auth_info_array;
2406 size_t converted_size;
2407 DATA_BLOB auth_blob;
2408 enum ndr_err_code ndr_err;
2410 authinfo_internal = talloc_zero(mem_ctx, struct lsa_TrustDomainInfoAuthInfoInternal);
2411 if (authinfo_internal == NULL) {
2415 auth_info_array = talloc_array(mem_ctx,
2416 struct AuthenticationInformation, 1);
2417 if (auth_info_array == NULL) {
2421 generate_random_buffer(auth_struct.confounder, sizeof(auth_struct.confounder));
2423 auth_info_array[0].AuthType = TRUST_AUTH_TYPE_CLEAR;
2425 if (!convert_string_talloc(mem_ctx, CH_UNIX, CH_UTF16, password,
2427 &auth_info_array[0].AuthInfo.clear.password,
2432 auth_info_array[0].AuthInfo.clear.size = converted_size;
2434 auth_struct.outgoing.count = 1;
2435 auth_struct.outgoing.current.count = 1;
2436 auth_struct.outgoing.current.array = auth_info_array;
2437 auth_struct.outgoing.previous.count = 0;
2438 auth_struct.outgoing.previous.array = NULL;
2440 auth_struct.incoming.count = 1;
2441 auth_struct.incoming.current.count = 1;
2442 auth_struct.incoming.current.array = auth_info_array;
2443 auth_struct.incoming.previous.count = 0;
2444 auth_struct.incoming.previous.array = NULL;
2447 ndr_err = ndr_push_struct_blob(&auth_blob, mem_ctx, &auth_struct,
2448 (ndr_push_flags_fn_t)ndr_push_trustDomainPasswords);
2449 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2453 arcfour_crypt_blob(auth_blob.data, auth_blob.length, &session_key);
2455 authinfo_internal->auth_blob.size = auth_blob.length;
2456 authinfo_internal->auth_blob.data = auth_blob.data;
2458 *_authinfo_internal = authinfo_internal;
2463 static bool gen_authinfo(TALLOC_CTX *mem_ctx, const char *password,
2464 struct lsa_TrustDomainInfoAuthInfo **_authinfo)
2466 struct lsa_TrustDomainInfoAuthInfo *authinfo;
2467 struct lsa_TrustDomainInfoBuffer *info_buffer;
2468 size_t converted_size;
2470 authinfo = talloc_zero(mem_ctx, struct lsa_TrustDomainInfoAuthInfo);
2471 if (authinfo == NULL) {
2475 info_buffer = talloc_zero(mem_ctx, struct lsa_TrustDomainInfoBuffer);
2476 if (info_buffer == NULL) {
2480 info_buffer->AuthType = TRUST_AUTH_TYPE_CLEAR;
2482 if (!convert_string_talloc(mem_ctx, CH_UNIX, CH_UTF16, password,
2484 &info_buffer->data.data,
2489 info_buffer->data.size = converted_size;
2491 authinfo->incoming_count = 1;
2492 authinfo->incoming_current_auth_info = info_buffer;
2493 authinfo->incoming_previous_auth_info = NULL;
2494 authinfo->outgoing_count = 1;
2495 authinfo->outgoing_current_auth_info = info_buffer;
2496 authinfo->outgoing_previous_auth_info = NULL;
2498 *_authinfo = authinfo;
2503 static bool check_pw_with_ServerAuthenticate3(struct dcerpc_pipe *p,
2504 struct torture_context *tctx,
2505 uint32_t negotiate_flags,
2506 struct cli_credentials *machine_credentials,
2507 struct netlogon_creds_CredentialState **creds_out)
2509 struct netr_ServerReqChallenge r;
2510 struct netr_ServerAuthenticate3 a;
2511 struct netr_Credential credentials1, credentials2, credentials3;
2512 struct netlogon_creds_CredentialState *creds;
2513 struct samr_Password mach_password;
2515 const char *machine_name;
2516 const char *plain_pass;
2517 struct dcerpc_binding_handle *b = p->binding_handle;
2519 machine_name = cli_credentials_get_workstation(machine_credentials);
2520 plain_pass = cli_credentials_get_password(machine_credentials);
2522 r.in.server_name = NULL;
2523 r.in.computer_name = machine_name;
2524 r.in.credentials = &credentials1;
2525 r.out.return_credentials = &credentials2;
2527 generate_random_buffer(credentials1.data, sizeof(credentials1.data));
2529 torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerReqChallenge_r(b, tctx, &r),
2530 "ServerReqChallenge failed");
2531 torture_assert_ntstatus_ok(tctx, r.out.result, "ServerReqChallenge failed");
2533 E_md4hash(plain_pass, mach_password.hash);
2535 a.in.server_name = NULL;
2536 a.in.account_name = talloc_asprintf(tctx, "%s$", machine_name);
2537 a.in.secure_channel_type = cli_credentials_get_secure_channel_type(machine_credentials);
2538 a.in.computer_name = machine_name;
2539 a.in.negotiate_flags = &negotiate_flags;
2540 a.in.credentials = &credentials3;
2541 a.out.return_credentials = &credentials3;
2542 a.out.negotiate_flags = &negotiate_flags;
2545 creds = netlogon_creds_client_init(tctx, a.in.account_name,
2547 &credentials1, &credentials2,
2548 &mach_password, &credentials3,
2551 torture_assert(tctx, creds != NULL, "memory allocation");
2553 torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerAuthenticate3_r(b, tctx, &a),
2554 "ServerAuthenticate3 failed");
2555 if (!NT_STATUS_IS_OK(a.out.result)) {
2556 if (!NT_STATUS_EQUAL(a.out.result, NT_STATUS_ACCESS_DENIED)) {
2557 torture_assert_ntstatus_ok(tctx, a.out.result,
2558 "ServerAuthenticate3 failed");
2562 torture_assert(tctx, netlogon_creds_client_check(creds, &credentials3), "Credential chaining failed");
2564 /* Prove that requesting a challenge again won't break it */
2565 torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerReqChallenge_r(b, tctx, &r),
2566 "ServerReqChallenge failed");
2567 torture_assert_ntstatus_ok(tctx, r.out.result, "ServerReqChallenge failed");
2573 static bool check_dom_trust_pw(struct dcerpc_pipe *p,
2574 struct torture_context *tctx,
2575 const char *trusted_dom_name,
2576 const char *password)
2578 struct cli_credentials *credentials;
2580 struct netlogon_creds_CredentialState *creds;
2581 struct dcerpc_pipe *pipe;
2585 credentials = cli_credentials_init(tctx);
2586 if (credentials == NULL) {
2590 dummy = talloc_asprintf(tctx, "%s$", trusted_dom_name);
2591 if (dummy == NULL) {
2595 cli_credentials_set_username(credentials, dummy, CRED_SPECIFIED);
2596 cli_credentials_set_password(credentials, password, CRED_SPECIFIED);
2597 cli_credentials_set_workstation(credentials,
2598 trusted_dom_name, CRED_SPECIFIED);
2599 cli_credentials_set_secure_channel_type(credentials, SEC_CHAN_DOMAIN);
2601 status = dcerpc_pipe_connect_b(tctx, &pipe, p->binding,
2602 &ndr_table_netlogon,
2603 cli_credentials_init_anon(tctx),
2604 tctx->ev, tctx->lp_ctx);
2605 if (!NT_STATUS_IS_OK(status)) {
2606 torture_comment(tctx, "dcerpc_pipe_connect_b failed.\n");
2610 ok = check_pw_with_ServerAuthenticate3(pipe, tctx,
2611 NETLOGON_NEG_AUTH2_ADS_FLAGS,
2612 credentials, &creds);
2618 static bool test_CreateTrustedDomainEx_common(struct dcerpc_pipe *p,
2619 struct torture_context *tctx,
2620 struct policy_handle *handle,
2621 uint32_t num_trusts,
2626 struct lsa_CreateTrustedDomainEx r;
2627 struct lsa_CreateTrustedDomainEx2 r2;
2628 struct lsa_TrustDomainInfoInfoEx trustinfo;
2629 struct lsa_TrustDomainInfoAuthInfoInternal *authinfo_internal;
2630 struct lsa_TrustDomainInfoAuthInfo *authinfo;
2631 struct dom_sid **domsid;
2632 struct policy_handle *trustdom_handle;
2633 struct lsa_QueryTrustedDomainInfo q;
2634 union lsa_TrustedDomainInfo *info = NULL;
2635 DATA_BLOB session_key;
2637 struct dcerpc_binding_handle *b = p->binding_handle;
2640 torture_comment(tctx, "\nTesting CreateTrustedDomainEx2 for %d domains\n", num_trusts);
2642 torture_comment(tctx, "\nTesting CreateTrustedDomainEx for %d domains\n", num_trusts);
2645 domsid = talloc_array(tctx, struct dom_sid *, num_trusts);
2646 trustdom_handle = talloc_array(tctx, struct policy_handle, num_trusts);
2648 status = dcerpc_fetch_session_key(p, &session_key);
2649 if (!NT_STATUS_IS_OK(status)) {
2650 torture_comment(tctx, "dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
2654 for (i=0; i< num_trusts; i++) {
2655 char *trust_name = talloc_asprintf(tctx, "torturedom%02d", i);
2656 char *trust_name_dns = talloc_asprintf(tctx, "torturedom%02d.samba.example.com", i);
2657 char *trust_sid = talloc_asprintf(tctx, "S-1-5-21-97398-379795-100%02d", i);
2659 domsid[i] = dom_sid_parse_talloc(tctx, trust_sid);
2661 trustinfo.sid = domsid[i];
2662 trustinfo.netbios_name.string = trust_name;
2663 trustinfo.domain_name.string = trust_name_dns;
2665 /* Create inbound, some outbound, and some
2666 * bi-directional trusts in a repeating pattern based
2669 /* 1 == inbound, 2 == outbound, 3 == both */
2670 trustinfo.trust_direction = (i % 3) + 1;
2672 /* Try different trust types too */
2674 /* 1 == downlevel (NT4), 2 == uplevel (ADS), 3 == MIT (kerberos but not AD) */
2675 trustinfo.trust_type = (((i / 3) + 1) % 3) + 1;
2677 trustinfo.trust_attributes = LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION;
2679 if (!gen_authinfo_internal(tctx, TRUSTPW, session_key, &authinfo_internal)) {
2680 torture_comment(tctx, "gen_authinfo_internal failed");
2684 if (!gen_authinfo(tctx, TRUSTPW, &authinfo)) {
2685 torture_comment(tctx, "gen_authinfonfo failed");
2691 r2.in.policy_handle = handle;
2692 r2.in.info = &trustinfo;
2693 r2.in.auth_info_internal = authinfo_internal;
2694 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2695 r2.out.trustdom_handle = &trustdom_handle[i];
2697 torture_assert_ntstatus_ok(tctx,
2698 dcerpc_lsa_CreateTrustedDomainEx2_r(b, tctx, &r2),
2699 "CreateTrustedDomainEx2 failed");
2701 status = r2.out.result;
2704 r.in.policy_handle = handle;
2705 r.in.info = &trustinfo;
2706 r.in.auth_info = authinfo;
2707 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2708 r.out.trustdom_handle = &trustdom_handle[i];
2710 torture_assert_ntstatus_ok(tctx,
2711 dcerpc_lsa_CreateTrustedDomainEx_r(b, tctx, &r),
2712 "CreateTrustedDomainEx failed");
2714 status = r.out.result;
2717 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
2718 test_DeleteTrustedDomain(b, tctx, handle, trustinfo.netbios_name);
2720 torture_assert_ntstatus_ok(tctx,
2721 dcerpc_lsa_CreateTrustedDomainEx2_r(b, tctx, &r2),
2722 "CreateTrustedDomainEx2 failed");
2723 status = r2.out.result;
2725 torture_assert_ntstatus_ok(tctx,
2726 dcerpc_lsa_CreateTrustedDomainEx_r(b, tctx, &r),
2727 "CreateTrustedDomainEx2 failed");
2728 status = r.out.result;
2731 if (!NT_STATUS_IS_OK(status)) {
2732 torture_comment(tctx, "CreateTrustedDomainEx failed2 - %s\n", nt_errstr(status));
2735 /* For outbound and MIT trusts there is no trust account */
2736 if (trustinfo.trust_direction != 2 &&
2737 trustinfo.trust_type != 3) {
2739 if (torture_setting_bool(tctx, "samba3", false) ||
2740 torture_setting_bool(tctx, "samba4", false)) {
2741 torture_comment(tctx, "skipping trusted domain auth tests against samba");
2743 if (check_dom_trust_pw(p, tctx, trust_name,
2745 torture_comment(tctx, "Password check passed unexpectedly\n");
2748 if (!check_dom_trust_pw(p, tctx, trust_name,
2750 torture_comment(tctx, "Password check failed\n");
2756 q.in.trustdom_handle = &trustdom_handle[i];
2757 q.in.level = LSA_TRUSTED_DOMAIN_INFO_INFO_EX;
2759 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryTrustedDomainInfo_r(b, tctx, &q),
2760 "QueryTrustedDomainInfo failed");
2761 if (!NT_STATUS_IS_OK(q.out.result)) {
2762 torture_comment(tctx, "QueryTrustedDomainInfo level 1 failed - %s\n", nt_errstr(q.out.result));
2764 } else if (!q.out.info) {
2765 torture_comment(tctx, "QueryTrustedDomainInfo level 1 failed to return an info pointer\n");
2768 if (strcmp(info->info_ex.netbios_name.string, trustinfo.netbios_name.string) != 0) {
2769 torture_comment(tctx, "QueryTrustedDomainInfo returned inconsistent short name: %s != %s\n",
2770 info->info_ex.netbios_name.string, trustinfo.netbios_name.string);
2773 if (info->info_ex.trust_type != trustinfo.trust_type) {
2774 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
2775 trust_name, info->info_ex.trust_type, trustinfo.trust_type);
2778 if (info->info_ex.trust_attributes != LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION) {
2779 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
2780 trust_name, info->info_ex.trust_attributes, LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION);
2783 if (info->info_ex.trust_direction != trustinfo.trust_direction) {
2784 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
2785 trust_name, info->info_ex.trust_direction, trustinfo.trust_direction);
2792 /* now that we have some domains to look over, we can test the enum calls */
2793 if (!test_EnumTrustDom(b, tctx, handle)) {
2794 torture_comment(tctx, "test_EnumTrustDom failed\n");
2798 if (!test_EnumTrustDomEx(b, tctx, handle)) {
2799 torture_comment(tctx, "test_EnumTrustDomEx failed\n");
2803 for (i=0; i<num_trusts; i++) {
2804 if (!test_DeleteTrustedDomainBySid(b, tctx, handle, domsid[i])) {
2805 torture_comment(tctx, "test_DeleteTrustedDomainBySid failed\n");
2813 static bool test_CreateTrustedDomainEx2(struct dcerpc_pipe *p,
2814 struct torture_context *tctx,
2815 struct policy_handle *handle,
2816 uint32_t num_trusts)
2818 return test_CreateTrustedDomainEx_common(p, tctx, handle, num_trusts, true);
2821 static bool test_CreateTrustedDomainEx(struct dcerpc_pipe *p,
2822 struct torture_context *tctx,
2823 struct policy_handle *handle,
2824 uint32_t num_trusts)
2826 return test_CreateTrustedDomainEx_common(p, tctx, handle, num_trusts, false);
2829 static bool test_QueryDomainInfoPolicy(struct dcerpc_binding_handle *b,
2830 struct torture_context *tctx,
2831 struct policy_handle *handle)
2833 struct lsa_QueryDomainInformationPolicy r;
2834 union lsa_DomainInformationPolicy *info = NULL;
2838 if (torture_setting_bool(tctx, "samba3", false)) {
2839 torture_skip(tctx, "skipping QueryDomainInformationPolicy test\n");
2842 torture_comment(tctx, "\nTesting QueryDomainInformationPolicy\n");
2845 r.in.handle = handle;
2849 torture_comment(tctx, "\nTrying QueryDomainInformationPolicy level %d\n", i);
2851 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryDomainInformationPolicy_r(b, tctx, &r),
2852 "QueryDomainInformationPolicy failed");
2854 /* If the server does not support EFS, then this is the correct return */
2855 if (i == LSA_DOMAIN_INFO_POLICY_EFS && NT_STATUS_EQUAL(r.out.result, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
2857 } else if (!NT_STATUS_IS_OK(r.out.result)) {
2858 torture_comment(tctx, "QueryDomainInformationPolicy failed - %s\n", nt_errstr(r.out.result));
2868 static bool test_QueryInfoPolicyCalls( bool version2,
2869 struct dcerpc_binding_handle *b,
2870 struct torture_context *tctx,
2871 struct policy_handle *handle)
2873 struct lsa_QueryInfoPolicy r;
2874 union lsa_PolicyInformation *info = NULL;
2877 const char *call = talloc_asprintf(tctx, "QueryInfoPolicy%s", version2 ? "2":"");
2879 torture_comment(tctx, "\nTesting %s\n", call);
2881 if (version2 && torture_setting_bool(tctx, "samba3", false)) {
2882 torture_skip(tctx, "skipping QueryInfoPolicy2 tests\n");
2885 for (i=1;i<=14;i++) {
2886 r.in.handle = handle;
2890 torture_comment(tctx, "\nTrying %s level %d\n", call, i);
2893 /* We can perform the cast, because both types are
2894 structurally equal */
2895 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryInfoPolicy2_r(b, tctx,
2896 (struct lsa_QueryInfoPolicy2*) &r),
2897 "QueryInfoPolicy2 failed");
2899 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryInfoPolicy_r(b, tctx, &r),
2900 "QueryInfoPolicy2 failed");
2903 case LSA_POLICY_INFO_MOD:
2904 case LSA_POLICY_INFO_AUDIT_FULL_SET:
2905 case LSA_POLICY_INFO_AUDIT_FULL_QUERY:
2906 if (!NT_STATUS_EQUAL(r.out.result, NT_STATUS_INVALID_PARAMETER)) {
2907 torture_comment(tctx, "Server should have failed level %u: %s\n", i, nt_errstr(r.out.result));
2911 case LSA_POLICY_INFO_DOMAIN:
2912 case LSA_POLICY_INFO_ACCOUNT_DOMAIN:
2913 case LSA_POLICY_INFO_REPLICA:
2914 case LSA_POLICY_INFO_QUOTA:
2915 case LSA_POLICY_INFO_ROLE:
2916 case LSA_POLICY_INFO_AUDIT_LOG:
2917 case LSA_POLICY_INFO_AUDIT_EVENTS:
2918 case LSA_POLICY_INFO_PD:
2919 if (!NT_STATUS_IS_OK(r.out.result)) {
2920 torture_comment(tctx, "%s failed - %s\n", call, nt_errstr(r.out.result));
2924 case LSA_POLICY_INFO_L_ACCOUNT_DOMAIN:
2925 case LSA_POLICY_INFO_DNS_INT:
2926 case LSA_POLICY_INFO_DNS:
2927 if (torture_setting_bool(tctx, "samba3", false)) {
2928 /* Other levels not implemented yet */
2929 if (!NT_STATUS_EQUAL(r.out.result, NT_STATUS_INVALID_INFO_CLASS)) {
2930 torture_comment(tctx, "%s failed - %s\n", call, nt_errstr(r.out.result));
2933 } else if (!NT_STATUS_IS_OK(r.out.result)) {
2934 torture_comment(tctx, "%s failed - %s\n", call, nt_errstr(r.out.result));
2939 if (torture_setting_bool(tctx, "samba4", false)) {
2940 /* Other levels not implemented yet */
2941 if (!NT_STATUS_EQUAL(r.out.result, NT_STATUS_INVALID_INFO_CLASS)) {
2942 torture_comment(tctx, "%s failed - %s\n", call, nt_errstr(r.out.result));
2945 } else if (!NT_STATUS_IS_OK(r.out.result)) {
2946 torture_comment(tctx, "%s failed - %s\n", call, nt_errstr(r.out.result));
2952 if (NT_STATUS_IS_OK(r.out.result) && (i == LSA_POLICY_INFO_DNS
2953 || i == LSA_POLICY_INFO_DNS_INT)) {
2954 /* Let's look up some of these names */
2956 struct lsa_TransNameArray tnames;
2958 tnames.names = talloc_zero_array(tctx, struct lsa_TranslatedName, tnames.count);
2959 tnames.names[0].name.string = info->dns.name.string;
2960 tnames.names[0].sid_type = SID_NAME_DOMAIN;
2961 tnames.names[1].name.string = info->dns.dns_domain.string;
2962 tnames.names[1].sid_type = SID_NAME_DOMAIN;
2963 tnames.names[2].name.string = talloc_asprintf(tctx, "%s\\", info->dns.name.string);
2964 tnames.names[2].sid_type = SID_NAME_DOMAIN;
2965 tnames.names[3].name.string = talloc_asprintf(tctx, "%s\\", info->dns.dns_domain.string);
2966 tnames.names[3].sid_type = SID_NAME_DOMAIN;
2967 tnames.names[4].name.string = talloc_asprintf(tctx, "%s\\guest", info->dns.name.string);
2968 tnames.names[4].sid_type = SID_NAME_USER;
2969 tnames.names[5].name.string = talloc_asprintf(tctx, "%s\\krbtgt", info->dns.name.string);
2970 tnames.names[5].sid_type = SID_NAME_USER;
2971 tnames.names[6].name.string = talloc_asprintf(tctx, "%s\\guest", info->dns.dns_domain.string);
2972 tnames.names[6].sid_type = SID_NAME_USER;
2973 tnames.names[7].name.string = talloc_asprintf(tctx, "%s\\krbtgt", info->dns.dns_domain.string);
2974 tnames.names[7].sid_type = SID_NAME_USER;
2975 tnames.names[8].name.string = talloc_asprintf(tctx, "krbtgt@%s", info->dns.name.string);
2976 tnames.names[8].sid_type = SID_NAME_USER;
2977 tnames.names[9].name.string = talloc_asprintf(tctx, "krbtgt@%s", info->dns.dns_domain.string);
2978 tnames.names[9].sid_type = SID_NAME_USER;
2979 tnames.names[10].name.string = talloc_asprintf(tctx, "%s\\"TEST_MACHINENAME "$", info->dns.name.string);
2980 tnames.names[10].sid_type = SID_NAME_USER;
2981 tnames.names[11].name.string = talloc_asprintf(tctx, "%s\\"TEST_MACHINENAME "$", info->dns.dns_domain.string);
2982 tnames.names[11].sid_type = SID_NAME_USER;
2983 tnames.names[12].name.string = talloc_asprintf(tctx, TEST_MACHINENAME "$@%s", info->dns.name.string);
2984 tnames.names[12].sid_type = SID_NAME_USER;
2985 tnames.names[13].name.string = talloc_asprintf(tctx, TEST_MACHINENAME "$@%s", info->dns.dns_domain.string);
2986 tnames.names[13].sid_type = SID_NAME_USER;
2987 ret &= test_LookupNames(b, tctx, handle, &tnames);
2995 static bool test_QueryInfoPolicy(struct dcerpc_binding_handle *b,
2996 struct torture_context *tctx,
2997 struct policy_handle *handle)
2999 return test_QueryInfoPolicyCalls(false, b, tctx, handle);
3002 static bool test_QueryInfoPolicy2(struct dcerpc_binding_handle *b,
3003 struct torture_context *tctx,
3004 struct policy_handle *handle)
3006 return test_QueryInfoPolicyCalls(true, b, tctx, handle);
3009 static bool test_GetUserName(struct dcerpc_binding_handle *b,
3010 struct torture_context *tctx)
3012 struct lsa_GetUserName r;
3014 struct lsa_String *authority_name_p = NULL;
3015 struct lsa_String *account_name_p = NULL;
3017 torture_comment(tctx, "\nTesting GetUserName\n");
3019 r.in.system_name = "\\";
3020 r.in.account_name = &account_name_p;
3021 r.in.authority_name = NULL;
3022 r.out.account_name = &account_name_p;
3024 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_GetUserName_r(b, tctx, &r),
3025 "GetUserName failed");
3027 if (!NT_STATUS_IS_OK(r.out.result)) {
3028 torture_comment(tctx, "GetUserName failed - %s\n", nt_errstr(r.out.result));
3032 account_name_p = NULL;
3033 r.in.account_name = &account_name_p;
3034 r.in.authority_name = &authority_name_p;
3035 r.out.account_name = &account_name_p;
3037 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_GetUserName_r(b, tctx, &r),
3038 "GetUserName failed");
3040 if (!NT_STATUS_IS_OK(r.out.result)) {
3041 torture_comment(tctx, "GetUserName failed - %s\n", nt_errstr(r.out.result));
3048 bool test_lsa_Close(struct dcerpc_binding_handle *b,
3049 struct torture_context *tctx,
3050 struct policy_handle *handle)
3053 struct policy_handle handle2;
3055 torture_comment(tctx, "\nTesting Close\n");
3057 r.in.handle = handle;
3058 r.out.handle = &handle2;
3060 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_Close_r(b, tctx, &r),
3062 if (!NT_STATUS_IS_OK(r.out.result)) {
3063 torture_comment(tctx, "Close failed - %s\n",
3064 nt_errstr(r.out.result));
3068 torture_assert_ntstatus_equal(tctx, dcerpc_lsa_Close_r(b, tctx, &r),
3069 NT_STATUS_RPC_SS_CONTEXT_MISMATCH, "Close should failed");
3071 torture_comment(tctx, "\n");
3076 bool torture_rpc_lsa(struct torture_context *tctx)
3079 struct dcerpc_pipe *p;
3081 struct policy_handle *handle;
3082 struct test_join *join = NULL;
3083 struct cli_credentials *machine_creds;
3084 struct dcerpc_binding_handle *b;
3086 status = torture_rpc_connection(tctx, &p, &ndr_table_lsarpc);
3087 if (!NT_STATUS_IS_OK(status)) {
3090 b = p->binding_handle;
3092 if (!test_OpenPolicy(b, tctx)) {
3096 if (!test_lsa_OpenPolicy2(b, tctx, &handle)) {
3101 join = torture_join_domain(tctx, TEST_MACHINENAME, ACB_WSTRUST, &machine_creds);
3106 if (!test_LookupSids_async(b, tctx, handle)) {
3110 if (!test_QueryDomainInfoPolicy(b, tctx, handle)) {
3114 if (!test_CreateSecret(p, tctx, handle)) {
3118 if (!test_QueryInfoPolicy(b, tctx, handle)) {
3122 if (!test_QueryInfoPolicy2(b, tctx, handle)) {
3126 if (!test_Delete(b, tctx, handle)) {
3130 if (!test_many_LookupSids(p, tctx, handle)) {
3134 if (!test_lsa_Close(b, tctx, handle)) {
3138 torture_leave_domain(tctx, join);
3141 if (!test_many_LookupSids(p, tctx, handle)) {
3146 if (!test_GetUserName(b, tctx)) {
3153 bool torture_rpc_lsa_get_user(struct torture_context *tctx)
3156 struct dcerpc_pipe *p;
3158 struct dcerpc_binding_handle *b;
3160 status = torture_rpc_connection(tctx, &p, &ndr_table_lsarpc);
3161 if (!NT_STATUS_IS_OK(status)) {
3164 b = p->binding_handle;
3166 if (!test_GetUserName(b, tctx)) {
3173 static bool testcase_LookupNames(struct torture_context *tctx,
3174 struct dcerpc_pipe *p)
3177 struct policy_handle *handle;
3178 struct lsa_TransNameArray tnames;
3179 struct lsa_TransNameArray2 tnames2;
3180 struct dcerpc_binding_handle *b = p->binding_handle;
3182 if (!test_OpenPolicy(b, tctx)) {
3186 if (!test_lsa_OpenPolicy2(b, tctx, &handle)) {
3195 tnames.names = talloc_array(tctx, struct lsa_TranslatedName, tnames.count);
3196 ZERO_STRUCT(tnames.names[0]);
3197 tnames.names[0].name.string = "BUILTIN";
3198 tnames.names[0].sid_type = SID_NAME_DOMAIN;
3200 if (!test_LookupNames(b, tctx, handle, &tnames)) {
3205 tnames2.names = talloc_array(tctx, struct lsa_TranslatedName2, tnames2.count);
3206 ZERO_STRUCT(tnames2.names[0]);
3207 tnames2.names[0].name.string = "BUILTIN";
3208 tnames2.names[0].sid_type = SID_NAME_DOMAIN;
3210 if (!test_LookupNames2(b, tctx, handle, &tnames2, true)) {
3214 if (!test_LookupNames3(b, tctx, handle, &tnames2, true)) {
3218 if (!test_LookupNames_wellknown(b, tctx, handle)) {
3222 if (!test_LookupNames_NULL(b, tctx, handle)) {
3226 if (!test_LookupNames_bogus(b, tctx, handle)) {
3230 if (!test_lsa_Close(b, tctx, handle)) {
3237 struct torture_suite *torture_rpc_lsa_lookup_names(TALLOC_CTX *mem_ctx)
3239 struct torture_suite *suite;
3240 struct torture_rpc_tcase *tcase;
3242 suite = torture_suite_create(mem_ctx, "lsa.lookupnames");
3244 tcase = torture_suite_add_rpc_iface_tcase(suite, "lsa",
3246 torture_rpc_tcase_add_test(tcase, "LookupNames",
3247 testcase_LookupNames);
3252 struct lsa_trustdom_state {
3253 uint32_t num_trusts;
3256 static bool testcase_TrustedDomains(struct torture_context *tctx,
3257 struct dcerpc_pipe *p,
3261 struct policy_handle *handle;
3262 struct lsa_trustdom_state *state =
3263 talloc_get_type_abort(data, struct lsa_trustdom_state);
3264 struct dcerpc_binding_handle *b = p->binding_handle;
3266 torture_comment(tctx, "Testing %d domains\n", state->num_trusts);
3268 if (!test_OpenPolicy(b, tctx)) {
3272 if (!test_lsa_OpenPolicy2(b, tctx, &handle)) {
3280 if (!test_CreateTrustedDomain(b, tctx, handle, state->num_trusts)) {
3284 if (!test_CreateTrustedDomainEx(p, tctx, handle, state->num_trusts)) {
3288 if (!test_CreateTrustedDomainEx2(p, tctx, handle, state->num_trusts)) {
3292 if (!test_lsa_Close(b, tctx, handle)) {
3299 struct torture_suite *torture_rpc_lsa_trusted_domains(TALLOC_CTX *mem_ctx)
3301 struct torture_suite *suite;
3302 struct torture_rpc_tcase *tcase;
3303 struct lsa_trustdom_state *state;
3305 state = talloc(mem_ctx, struct lsa_trustdom_state);
3307 state->num_trusts = 12;
3309 suite = torture_suite_create(mem_ctx, "lsa.trusted.domains");
3311 tcase = torture_suite_add_rpc_iface_tcase(suite, "lsa",
3313 torture_rpc_tcase_add_test_ex(tcase, "TrustedDomains",
3314 testcase_TrustedDomains,
3320 static bool testcase_Privileges(struct torture_context *tctx,
3321 struct dcerpc_pipe *p)
3324 struct policy_handle *handle;
3325 struct dcerpc_binding_handle *b = p->binding_handle;
3327 if (!test_OpenPolicy(b, tctx)) {
3331 if (!test_lsa_OpenPolicy2(b, tctx, &handle)) {
3339 if (!test_CreateAccount(b, tctx, handle)) {
3343 if (!test_EnumAccounts(b, tctx, handle)) {
3347 if (!test_EnumPrivs(b, tctx, handle)) {
3351 if (!test_lsa_Close(b, tctx, handle)) {
3359 struct torture_suite *torture_rpc_lsa_privileges(TALLOC_CTX *mem_ctx)
3361 struct torture_suite *suite;
3362 struct torture_rpc_tcase *tcase;
3364 suite = torture_suite_create(mem_ctx, "lsa.privileges");
3366 tcase = torture_suite_add_rpc_iface_tcase(suite, "lsa",
3368 torture_rpc_tcase_add_test(tcase, "Privileges",
3369 testcase_Privileges);