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;
389 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,
507 bool test_fail) /* check if the tests fails! */
509 struct lsa_LookupNames4 r;
510 struct lsa_TransSidArray3 sids;
511 struct lsa_RefDomainList *domains = NULL;
512 struct lsa_String *names;
517 torture_comment(tctx, "\nTesting LookupNames4 with %d names\n", tnames->count);
524 input_idx = talloc_array(tctx, uint32_t, tnames->count);
525 names = talloc_array(tctx, struct lsa_String, tnames->count);
526 for (i=0;i<tnames->count;i++) {
527 if (tnames->names[i].sid_type != SID_NAME_UNKNOWN) {
528 init_lsa_String(&names[r.in.num_names], tnames->names[i].name.string);
529 input_idx[r.in.num_names] = i;
534 r.in.num_names = tnames->count;
539 r.in.lookup_options = 0;
540 r.in.client_revision = 0;
541 r.out.count = &count;
543 r.out.domains = &domains;
545 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupNames4_r(b, tctx, &r),
546 "LookupNames4 failed");
547 if (!NT_STATUS_IS_OK(r.out.result)) {
548 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_ACCESS_DENIED) ||
549 NT_STATUS_EQUAL(r.out.result, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
551 torture_comment(tctx, "not considering %s to be an error\n",
552 nt_errstr(r.out.result));
556 torture_comment(tctx, "LookupNames4 failed - %s\n",
557 nt_errstr(r.out.result));
562 torture_assert_int_equal(tctx, count, sids.count,
563 "unexpected number of results returned");
564 if (sids.count > 0) {
565 torture_assert(tctx, sids.sids, "invalid sid buffer");
569 torture_comment(tctx, "\n");
575 static bool test_LookupSids(struct dcerpc_binding_handle *b,
576 struct torture_context *tctx,
577 struct policy_handle *handle,
578 struct lsa_SidArray *sids)
580 struct lsa_LookupSids r;
581 struct lsa_TransNameArray names;
582 struct lsa_RefDomainList *domains = NULL;
583 uint32_t count = sids->num_sids;
585 torture_comment(tctx, "\nTesting LookupSids\n");
590 r.in.handle = handle;
595 r.out.count = &count;
596 r.out.names = &names;
597 r.out.domains = &domains;
599 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupSids_r(b, tctx, &r),
600 "LookupSids failed");
601 if (!NT_STATUS_IS_OK(r.out.result) &&
602 !NT_STATUS_EQUAL(r.out.result, STATUS_SOME_UNMAPPED)) {
603 torture_comment(tctx, "LookupSids failed - %s\n",
604 nt_errstr(r.out.result));
608 torture_comment(tctx, "\n");
610 if (!test_LookupNames(b, tctx, handle, &names)) {
618 static bool test_LookupSids2(struct dcerpc_binding_handle *b,
619 struct torture_context *tctx,
620 struct policy_handle *handle,
621 struct lsa_SidArray *sids)
623 struct lsa_LookupSids2 r;
624 struct lsa_TransNameArray2 names;
625 struct lsa_RefDomainList *domains = NULL;
626 uint32_t count = sids->num_sids;
628 torture_comment(tctx, "\nTesting LookupSids2\n");
633 r.in.handle = handle;
638 r.in.lookup_options = 0;
639 r.in.client_revision = 0;
640 r.out.count = &count;
641 r.out.names = &names;
642 r.out.domains = &domains;
644 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupSids2_r(b, tctx, &r),
645 "LookupSids2 failed");
646 if (!NT_STATUS_IS_OK(r.out.result) &&
647 !NT_STATUS_EQUAL(r.out.result, STATUS_SOME_UNMAPPED)) {
648 torture_comment(tctx, "LookupSids2 failed - %s\n",
649 nt_errstr(r.out.result));
653 torture_comment(tctx, "\n");
655 if (!test_LookupNames2(b, tctx, handle, &names, false)) {
659 if (!test_LookupNames3(b, tctx, handle, &names, false)) {
666 static bool test_LookupSids3(struct dcerpc_binding_handle *b,
667 struct torture_context *tctx,
668 struct lsa_SidArray *sids,
669 bool test_fail) /* check if the tests fails! */
671 struct lsa_LookupSids3 r;
672 struct lsa_TransNameArray2 names;
673 struct lsa_RefDomainList *domains = NULL;
674 uint32_t count = sids->num_sids;
676 torture_comment(tctx, "\nTesting LookupSids3\n");
685 r.in.lookup_options = 0;
686 r.in.client_revision = 0;
687 r.out.domains = &domains;
688 r.out.count = &count;
689 r.out.names = &names;
691 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupSids3_r(b, tctx, &r),
692 "LookupSids3 failed");
693 if (!NT_STATUS_IS_OK(r.out.result)) {
694 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_ACCESS_DENIED) ||
695 NT_STATUS_EQUAL(r.out.result, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
697 torture_comment(tctx, "not considering %s to be an error\n",
698 nt_errstr(r.out.result));
702 torture_comment(tctx, "LookupSids3 failed - %s - not considered an error\n",
703 nt_errstr(r.out.result));
707 torture_comment(tctx, "\n");
712 bool test_many_LookupSids(struct dcerpc_pipe *p,
713 struct torture_context *tctx,
714 struct policy_handle *handle)
717 struct lsa_SidArray sids;
719 struct dcerpc_binding_handle *b = p->binding_handle;
721 torture_comment(tctx, "\nTesting LookupSids with lots of SIDs\n");
725 sids.sids = talloc_array(tctx, struct lsa_SidPtr, sids.num_sids);
727 for (i=0; i<sids.num_sids; i++) {
728 const char *sidstr = "S-1-5-32-545";
729 sids.sids[i].sid = dom_sid_parse_talloc(tctx, sidstr);
732 count = sids.num_sids;
735 struct lsa_LookupSids r;
736 struct lsa_TransNameArray names;
737 struct lsa_RefDomainList *domains = NULL;
741 r.in.handle = handle;
745 r.in.count = &names.count;
746 r.out.count = &count;
747 r.out.names = &names;
748 r.out.domains = &domains;
750 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupSids_r(b, tctx, &r),
751 "LookupSids failed");
752 if (!NT_STATUS_IS_OK(r.out.result)) {
753 torture_comment(tctx, "LookupSids failed - %s\n",
754 nt_errstr(r.out.result));
758 torture_comment(tctx, "\n");
760 if (!test_LookupNames(b, tctx, handle, &names)) {
763 } else if (p->conn->security_state.auth_info->auth_type == DCERPC_AUTH_TYPE_SCHANNEL &&
764 p->conn->security_state.auth_info->auth_level >= DCERPC_AUTH_LEVEL_INTEGRITY) {
766 if (p->binding->transport == NCACN_IP_TCP) {
767 struct lsa_TransNameArray2 names;
769 if (!test_LookupSids3(b, tctx, &sids, false)) {
772 if (!test_LookupNames4(b, tctx, &names, false, false)) {
775 } else if (p->binding->transport == NCACN_NP) {
776 struct lsa_TransNameArray2 names;
778 if (!test_LookupSids3(b, tctx, &sids, true)) {
781 if (!test_LookupNames4(b, tctx, &names, false, true)) {
787 torture_comment(tctx, "\n");
794 static void lookupsids_cb(struct tevent_req *subreq)
796 int *replies = (int *)tevent_req_callback_data_void(subreq);
799 status = dcerpc_lsa_LookupSids_r_recv(subreq, subreq);
801 if (!NT_STATUS_IS_OK(status)) {
802 printf("lookupsids returned %s\n", nt_errstr(status));
811 static bool test_LookupSids_async(struct dcerpc_binding_handle *b,
812 struct torture_context *tctx,
813 struct policy_handle *handle)
815 struct lsa_SidArray sids;
816 struct lsa_SidPtr sidptr;
818 struct lsa_TransNameArray *names;
819 struct lsa_LookupSids *r;
820 struct lsa_RefDomainList *domains = NULL;
821 struct tevent_req **req;
824 const int num_async_requests = 50;
826 count = talloc_array(tctx, uint32_t, num_async_requests);
827 names = talloc_array(tctx, struct lsa_TransNameArray, num_async_requests);
828 r = talloc_array(tctx, struct lsa_LookupSids, num_async_requests);
830 torture_comment(tctx, "\nTesting %d async lookupsids request\n", num_async_requests);
832 req = talloc_array(tctx, struct tevent_req *, num_async_requests);
836 sidptr.sid = dom_sid_parse_talloc(tctx, "S-1-5-32-545");
840 for (i=0; i<num_async_requests; i++) {
843 names[i].names = NULL;
845 r[i].in.handle = handle;
846 r[i].in.sids = &sids;
847 r[i].in.names = &names[i];
849 r[i].in.count = &names[i].count;
850 r[i].out.count = &count[i];
851 r[i].out.names = &names[i];
852 r[i].out.domains = &domains;
854 req[i] = dcerpc_lsa_LookupSids_r_send(tctx, tctx->ev, b, &r[i]);
855 if (req[i] == NULL) {
860 tevent_req_set_callback(req[i], lookupsids_cb, &replies);
863 while (replies >= 0 && replies < num_async_requests) {
864 tevent_loop_once(tctx->ev);
876 static bool test_LookupPrivValue(struct dcerpc_binding_handle *b,
877 struct torture_context *tctx,
878 struct policy_handle *handle,
879 struct lsa_String *name)
881 struct lsa_LookupPrivValue r;
882 struct lsa_LUID luid;
884 r.in.handle = handle;
888 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupPrivValue_r(b, tctx, &r),
889 "LookupPrivValue failed");
890 if (!NT_STATUS_IS_OK(r.out.result)) {
891 torture_comment(tctx, "\nLookupPrivValue failed - %s\n",
892 nt_errstr(r.out.result));
899 static bool test_LookupPrivName(struct dcerpc_binding_handle *b,
900 struct torture_context *tctx,
901 struct policy_handle *handle,
902 struct lsa_LUID *luid)
904 struct lsa_LookupPrivName r;
905 struct lsa_StringLarge *name = NULL;
907 r.in.handle = handle;
911 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupPrivName_r(b, tctx, &r),
912 "LookupPrivName failed");
913 if (!NT_STATUS_IS_OK(r.out.result)) {
914 torture_comment(tctx, "\nLookupPrivName failed - %s\n",
915 nt_errstr(r.out.result));
922 static bool test_RemovePrivilegesFromAccount(struct dcerpc_binding_handle *b,
923 struct torture_context *tctx,
924 struct policy_handle *handle,
925 struct policy_handle *acct_handle,
926 struct lsa_LUID *luid)
928 struct lsa_RemovePrivilegesFromAccount r;
929 struct lsa_PrivilegeSet privs;
932 torture_comment(tctx, "\nTesting RemovePrivilegesFromAccount\n");
934 r.in.handle = acct_handle;
940 privs.set = talloc_array(tctx, struct lsa_LUIDAttribute, 1);
941 privs.set[0].luid = *luid;
942 privs.set[0].attribute = 0;
944 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_RemovePrivilegesFromAccount_r(b, tctx, &r),
945 "RemovePrivilegesFromAccount failed");
946 if (!NT_STATUS_IS_OK(r.out.result)) {
948 struct lsa_LookupPrivName r_name;
949 struct lsa_StringLarge *name = NULL;
951 r_name.in.handle = handle;
952 r_name.in.luid = luid;
953 r_name.out.name = &name;
955 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupPrivName_r(b, tctx, &r_name),
956 "LookupPrivName failed");
957 if (!NT_STATUS_IS_OK(r_name.out.result)) {
958 torture_comment(tctx, "\nLookupPrivName failed - %s\n",
959 nt_errstr(r_name.out.result));
962 /* Windows 2008 does not allow this to be removed */
963 if (strcmp("SeAuditPrivilege", name->string) == 0) {
967 torture_comment(tctx, "RemovePrivilegesFromAccount failed to remove %s - %s\n",
969 nt_errstr(r.out.result));
976 static bool test_AddPrivilegesToAccount(struct dcerpc_binding_handle *b,
977 struct torture_context *tctx,
978 struct policy_handle *acct_handle,
979 struct lsa_LUID *luid)
981 struct lsa_AddPrivilegesToAccount r;
982 struct lsa_PrivilegeSet privs;
985 torture_comment(tctx, "\nTesting AddPrivilegesToAccount\n");
987 r.in.handle = acct_handle;
992 privs.set = talloc_array(tctx, struct lsa_LUIDAttribute, 1);
993 privs.set[0].luid = *luid;
994 privs.set[0].attribute = 0;
996 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_AddPrivilegesToAccount_r(b, tctx, &r),
997 "AddPrivilegesToAccount failed");
998 if (!NT_STATUS_IS_OK(r.out.result)) {
999 torture_comment(tctx, "AddPrivilegesToAccount failed - %s\n",
1000 nt_errstr(r.out.result));
1007 static bool test_EnumPrivsAccount(struct dcerpc_binding_handle *b,
1008 struct torture_context *tctx,
1009 struct policy_handle *handle,
1010 struct policy_handle *acct_handle)
1012 struct lsa_EnumPrivsAccount r;
1013 struct lsa_PrivilegeSet *privs = NULL;
1016 torture_comment(tctx, "\nTesting EnumPrivsAccount\n");
1018 r.in.handle = acct_handle;
1019 r.out.privs = &privs;
1021 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumPrivsAccount_r(b, tctx, &r),
1022 "EnumPrivsAccount failed");
1023 if (!NT_STATUS_IS_OK(r.out.result)) {
1024 torture_comment(tctx, "EnumPrivsAccount failed - %s\n",
1025 nt_errstr(r.out.result));
1029 if (privs && privs->count > 0) {
1031 for (i=0;i<privs->count;i++) {
1032 test_LookupPrivName(b, tctx, handle,
1033 &privs->set[i].luid);
1036 ret &= test_RemovePrivilegesFromAccount(b, tctx, handle, acct_handle,
1037 &privs->set[0].luid);
1038 ret &= test_AddPrivilegesToAccount(b, tctx, acct_handle,
1039 &privs->set[0].luid);
1045 static bool test_GetSystemAccessAccount(struct dcerpc_binding_handle *b,
1046 struct torture_context *tctx,
1047 struct policy_handle *handle,
1048 struct policy_handle *acct_handle)
1050 uint32_t access_mask;
1051 struct lsa_GetSystemAccessAccount r;
1053 torture_comment(tctx, "\nTesting GetSystemAccessAccount\n");
1055 r.in.handle = acct_handle;
1056 r.out.access_mask = &access_mask;
1058 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_GetSystemAccessAccount_r(b, tctx, &r),
1059 "GetSystemAccessAccount failed");
1060 if (!NT_STATUS_IS_OK(r.out.result)) {
1061 torture_comment(tctx, "GetSystemAccessAccount failed - %s\n",
1062 nt_errstr(r.out.result));
1066 if (r.out.access_mask != NULL) {
1067 torture_comment(tctx, "Rights:");
1068 if (*(r.out.access_mask) & LSA_POLICY_MODE_INTERACTIVE)
1069 torture_comment(tctx, " LSA_POLICY_MODE_INTERACTIVE");
1070 if (*(r.out.access_mask) & LSA_POLICY_MODE_NETWORK)
1071 torture_comment(tctx, " LSA_POLICY_MODE_NETWORK");
1072 if (*(r.out.access_mask) & LSA_POLICY_MODE_BATCH)
1073 torture_comment(tctx, " LSA_POLICY_MODE_BATCH");
1074 if (*(r.out.access_mask) & LSA_POLICY_MODE_SERVICE)
1075 torture_comment(tctx, " LSA_POLICY_MODE_SERVICE");
1076 if (*(r.out.access_mask) & LSA_POLICY_MODE_PROXY)
1077 torture_comment(tctx, " LSA_POLICY_MODE_PROXY");
1078 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_INTERACTIVE)
1079 torture_comment(tctx, " LSA_POLICY_MODE_DENY_INTERACTIVE");
1080 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_NETWORK)
1081 torture_comment(tctx, " LSA_POLICY_MODE_DENY_NETWORK");
1082 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_BATCH)
1083 torture_comment(tctx, " LSA_POLICY_MODE_DENY_BATCH");
1084 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_SERVICE)
1085 torture_comment(tctx, " LSA_POLICY_MODE_DENY_SERVICE");
1086 if (*(r.out.access_mask) & LSA_POLICY_MODE_REMOTE_INTERACTIVE)
1087 torture_comment(tctx, " LSA_POLICY_MODE_REMOTE_INTERACTIVE");
1088 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_REMOTE_INTERACTIVE)
1089 torture_comment(tctx, " LSA_POLICY_MODE_DENY_REMOTE_INTERACTIVE");
1090 if (*(r.out.access_mask) & LSA_POLICY_MODE_ALL)
1091 torture_comment(tctx, " LSA_POLICY_MODE_ALL");
1092 if (*(r.out.access_mask) & LSA_POLICY_MODE_ALL_NT4)
1093 torture_comment(tctx, " LSA_POLICY_MODE_ALL_NT4");
1094 torture_comment(tctx, "\n");
1100 static bool test_Delete(struct dcerpc_binding_handle *b,
1101 struct torture_context *tctx,
1102 struct policy_handle *handle)
1104 struct lsa_Delete r;
1106 torture_comment(tctx, "\nTesting Delete\n");
1108 r.in.handle = handle;
1109 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_Delete_r(b, tctx, &r),
1111 if (!NT_STATUS_EQUAL(r.out.result, NT_STATUS_NOT_SUPPORTED)) {
1112 torture_comment(tctx, "Delete should have failed NT_STATUS_NOT_SUPPORTED - %s\n", nt_errstr(r.out.result));
1119 static bool test_DeleteObject(struct dcerpc_binding_handle *b,
1120 struct torture_context *tctx,
1121 struct policy_handle *handle)
1123 struct lsa_DeleteObject r;
1125 torture_comment(tctx, "\nTesting DeleteObject\n");
1127 r.in.handle = handle;
1128 r.out.handle = handle;
1129 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_DeleteObject_r(b, tctx, &r),
1130 "DeleteObject failed");
1131 if (!NT_STATUS_IS_OK(r.out.result)) {
1132 torture_comment(tctx, "DeleteObject failed - %s\n",
1133 nt_errstr(r.out.result));
1141 static bool test_CreateAccount(struct dcerpc_binding_handle *b,
1142 struct torture_context *tctx,
1143 struct policy_handle *handle)
1145 struct lsa_CreateAccount r;
1146 struct dom_sid2 *newsid;
1147 struct policy_handle acct_handle;
1149 newsid = dom_sid_parse_talloc(tctx, "S-1-5-12349876-4321-2854");
1151 torture_comment(tctx, "\nTesting CreateAccount\n");
1153 r.in.handle = handle;
1155 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1156 r.out.acct_handle = &acct_handle;
1158 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_CreateAccount_r(b, tctx, &r),
1159 "CreateAccount failed");
1160 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_OBJECT_NAME_COLLISION)) {
1161 struct lsa_OpenAccount r_o;
1162 r_o.in.handle = handle;
1163 r_o.in.sid = newsid;
1164 r_o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1165 r_o.out.acct_handle = &acct_handle;
1167 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenAccount_r(b, tctx, &r_o),
1168 "OpenAccount failed");
1169 if (!NT_STATUS_IS_OK(r_o.out.result)) {
1170 torture_comment(tctx, "OpenAccount failed - %s\n",
1171 nt_errstr(r_o.out.result));
1174 } else if (!NT_STATUS_IS_OK(r.out.result)) {
1175 torture_comment(tctx, "CreateAccount failed - %s\n",
1176 nt_errstr(r.out.result));
1180 if (!test_Delete(b, tctx, &acct_handle)) {
1184 if (!test_DeleteObject(b, tctx, &acct_handle)) {
1191 static bool test_DeleteTrustedDomain(struct dcerpc_binding_handle *b,
1192 struct torture_context *tctx,
1193 struct policy_handle *handle,
1194 struct lsa_StringLarge name)
1196 struct lsa_OpenTrustedDomainByName r;
1197 struct policy_handle trustdom_handle;
1199 r.in.handle = handle;
1200 r.in.name.string = name.string;
1201 r.in.access_mask = SEC_STD_DELETE;
1202 r.out.trustdom_handle = &trustdom_handle;
1204 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenTrustedDomainByName_r(b, tctx, &r),
1205 "OpenTrustedDomainByName failed");
1206 if (!NT_STATUS_IS_OK(r.out.result)) {
1207 torture_comment(tctx, "OpenTrustedDomainByName failed - %s\n", nt_errstr(r.out.result));
1211 if (!test_Delete(b, tctx, &trustdom_handle)) {
1215 if (!test_DeleteObject(b, tctx, &trustdom_handle)) {
1222 static bool test_DeleteTrustedDomainBySid(struct dcerpc_binding_handle *b,
1223 struct torture_context *tctx,
1224 struct policy_handle *handle,
1225 struct dom_sid *sid)
1227 struct lsa_DeleteTrustedDomain r;
1229 r.in.handle = handle;
1232 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_DeleteTrustedDomain_r(b, tctx, &r),
1233 "DeleteTrustedDomain failed");
1234 if (!NT_STATUS_IS_OK(r.out.result)) {
1235 torture_comment(tctx, "DeleteTrustedDomain failed - %s\n", nt_errstr(r.out.result));
1243 static bool test_CreateSecret(struct dcerpc_pipe *p,
1244 struct torture_context *tctx,
1245 struct policy_handle *handle)
1248 struct lsa_CreateSecret r;
1249 struct lsa_OpenSecret r2;
1250 struct lsa_SetSecret r3;
1251 struct lsa_QuerySecret r4;
1252 struct lsa_SetSecret r5;
1253 struct lsa_QuerySecret r6;
1254 struct lsa_SetSecret r7;
1255 struct lsa_QuerySecret r8;
1256 struct policy_handle sec_handle, sec_handle2, sec_handle3;
1257 struct lsa_DeleteObject d_o;
1258 struct lsa_DATA_BUF buf1;
1259 struct lsa_DATA_BUF_PTR bufp1;
1260 struct lsa_DATA_BUF_PTR bufp2;
1263 DATA_BLOB session_key;
1264 NTTIME old_mtime, new_mtime;
1266 const char *secret1 = "abcdef12345699qwerty";
1268 const char *secret3 = "ABCDEF12345699QWERTY";
1270 const char *secret5 = "NEW-SAMBA4-SECRET";
1274 const int LOCAL = 0;
1275 const int GLOBAL = 1;
1276 struct dcerpc_binding_handle *b = p->binding_handle;
1278 secname[LOCAL] = talloc_asprintf(tctx, "torturesecret-%u", (unsigned int)random());
1279 secname[GLOBAL] = talloc_asprintf(tctx, "G$torturesecret-%u", (unsigned int)random());
1281 for (i=0; i< 2; i++) {
1282 torture_comment(tctx, "\nTesting CreateSecret of %s\n", secname[i]);
1284 init_lsa_String(&r.in.name, secname[i]);
1286 r.in.handle = handle;
1287 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1288 r.out.sec_handle = &sec_handle;
1290 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_CreateSecret_r(b, tctx, &r),
1291 "CreateSecret failed");
1292 if (!NT_STATUS_IS_OK(r.out.result)) {
1293 torture_comment(tctx, "CreateSecret failed - %s\n", nt_errstr(r.out.result));
1297 r.in.handle = handle;
1298 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1299 r.out.sec_handle = &sec_handle3;
1301 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_CreateSecret_r(b, tctx, &r),
1302 "CreateSecret failed");
1303 if (!NT_STATUS_EQUAL(r.out.result, NT_STATUS_OBJECT_NAME_COLLISION)) {
1304 torture_comment(tctx, "CreateSecret should have failed OBJECT_NAME_COLLISION - %s\n", nt_errstr(r.out.result));
1308 r2.in.handle = handle;
1309 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1310 r2.in.name = r.in.name;
1311 r2.out.sec_handle = &sec_handle2;
1313 torture_comment(tctx, "Testing OpenSecret\n");
1315 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenSecret_r(b, tctx, &r2),
1316 "OpenSecret failed");
1317 if (!NT_STATUS_IS_OK(r2.out.result)) {
1318 torture_comment(tctx, "OpenSecret failed - %s\n", nt_errstr(r2.out.result));
1322 status = dcerpc_fetch_session_key(p, &session_key);
1323 if (!NT_STATUS_IS_OK(status)) {
1324 torture_comment(tctx, "dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
1328 enc_key = sess_encrypt_string(secret1, &session_key);
1330 r3.in.sec_handle = &sec_handle;
1331 r3.in.new_val = &buf1;
1332 r3.in.old_val = NULL;
1333 r3.in.new_val->data = enc_key.data;
1334 r3.in.new_val->length = enc_key.length;
1335 r3.in.new_val->size = enc_key.length;
1337 torture_comment(tctx, "Testing SetSecret\n");
1339 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_SetSecret_r(b, tctx, &r3),
1340 "SetSecret failed");
1341 if (!NT_STATUS_IS_OK(r3.out.result)) {
1342 torture_comment(tctx, "SetSecret failed - %s\n", nt_errstr(r3.out.result));
1346 r3.in.sec_handle = &sec_handle;
1347 r3.in.new_val = &buf1;
1348 r3.in.old_val = NULL;
1349 r3.in.new_val->data = enc_key.data;
1350 r3.in.new_val->length = enc_key.length;
1351 r3.in.new_val->size = enc_key.length;
1353 /* break the encrypted data */
1356 torture_comment(tctx, "Testing SetSecret with broken key\n");
1358 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_SetSecret_r(b, tctx, &r3),
1359 "SetSecret failed");
1360 if (!NT_STATUS_EQUAL(r3.out.result, NT_STATUS_UNKNOWN_REVISION)) {
1361 torture_comment(tctx, "SetSecret should have failed UNKNOWN_REVISION - %s\n", nt_errstr(r3.out.result));
1365 data_blob_free(&enc_key);
1367 ZERO_STRUCT(new_mtime);
1368 ZERO_STRUCT(old_mtime);
1370 /* fetch the secret back again */
1371 r4.in.sec_handle = &sec_handle;
1372 r4.in.new_val = &bufp1;
1373 r4.in.new_mtime = &new_mtime;
1374 r4.in.old_val = NULL;
1375 r4.in.old_mtime = NULL;
1379 torture_comment(tctx, "Testing QuerySecret\n");
1380 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QuerySecret_r(b, tctx, &r4),
1381 "QuerySecret failed");
1382 if (!NT_STATUS_IS_OK(r4.out.result)) {
1383 torture_comment(tctx, "QuerySecret failed - %s\n", nt_errstr(r4.out.result));
1386 if (r4.out.new_val == NULL || r4.out.new_val->buf == NULL) {
1387 torture_comment(tctx, "No secret buffer returned\n");
1390 blob1.data = r4.out.new_val->buf->data;
1391 blob1.length = r4.out.new_val->buf->size;
1393 secret2 = sess_decrypt_string(tctx,
1394 &blob1, &session_key);
1396 if (strcmp(secret1, secret2) != 0) {
1397 torture_comment(tctx, "Returned secret (r4) '%s' doesn't match '%s'\n",
1404 enc_key = sess_encrypt_string(secret3, &session_key);
1406 r5.in.sec_handle = &sec_handle;
1407 r5.in.new_val = &buf1;
1408 r5.in.old_val = NULL;
1409 r5.in.new_val->data = enc_key.data;
1410 r5.in.new_val->length = enc_key.length;
1411 r5.in.new_val->size = enc_key.length;
1415 torture_comment(tctx, "Testing SetSecret (existing value should move to old)\n");
1417 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_SetSecret_r(b, tctx, &r5),
1418 "SetSecret failed");
1419 if (!NT_STATUS_IS_OK(r5.out.result)) {
1420 torture_comment(tctx, "SetSecret failed - %s\n", nt_errstr(r5.out.result));
1424 data_blob_free(&enc_key);
1426 ZERO_STRUCT(new_mtime);
1427 ZERO_STRUCT(old_mtime);
1429 /* fetch the secret back again */
1430 r6.in.sec_handle = &sec_handle;
1431 r6.in.new_val = &bufp1;
1432 r6.in.new_mtime = &new_mtime;
1433 r6.in.old_val = &bufp2;
1434 r6.in.old_mtime = &old_mtime;
1439 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QuerySecret_r(b, tctx, &r6),
1440 "QuerySecret failed");
1441 if (!NT_STATUS_IS_OK(r6.out.result)) {
1442 torture_comment(tctx, "QuerySecret failed - %s\n", nt_errstr(r6.out.result));
1447 if (r6.out.new_val->buf == NULL || r6.out.old_val->buf == NULL
1448 || r6.out.new_mtime == NULL || r6.out.old_mtime == NULL) {
1449 torture_comment(tctx, "Both secret buffers and both times not returned\n");
1453 blob1.data = r6.out.new_val->buf->data;
1454 blob1.length = r6.out.new_val->buf->size;
1456 secret4 = sess_decrypt_string(tctx,
1457 &blob1, &session_key);
1459 if (strcmp(secret3, secret4) != 0) {
1460 torture_comment(tctx, "Returned NEW secret %s doesn't match %s\n", secret4, secret3);
1464 blob1.data = r6.out.old_val->buf->data;
1465 blob1.length = r6.out.old_val->buf->length;
1467 secret2 = sess_decrypt_string(tctx,
1468 &blob1, &session_key);
1470 if (strcmp(secret1, secret2) != 0) {
1471 torture_comment(tctx, "Returned OLD secret %s doesn't match %s\n", secret2, secret1);
1475 if (*r6.out.new_mtime == *r6.out.old_mtime) {
1476 torture_comment(tctx, "Returned secret (r6-%d) %s must not have same mtime for both secrets: %s != %s\n",
1479 nt_time_string(tctx, *r6.out.old_mtime),
1480 nt_time_string(tctx, *r6.out.new_mtime));
1486 enc_key = sess_encrypt_string(secret5, &session_key);
1488 r7.in.sec_handle = &sec_handle;
1489 r7.in.old_val = &buf1;
1490 r7.in.old_val->data = enc_key.data;
1491 r7.in.old_val->length = enc_key.length;
1492 r7.in.old_val->size = enc_key.length;
1493 r7.in.new_val = NULL;
1495 torture_comment(tctx, "Testing SetSecret of old Secret only\n");
1497 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_SetSecret_r(b, tctx, &r7),
1498 "SetSecret failed");
1499 if (!NT_STATUS_IS_OK(r7.out.result)) {
1500 torture_comment(tctx, "SetSecret failed - %s\n", nt_errstr(r7.out.result));
1504 data_blob_free(&enc_key);
1506 /* fetch the secret back again */
1507 r8.in.sec_handle = &sec_handle;
1508 r8.in.new_val = &bufp1;
1509 r8.in.new_mtime = &new_mtime;
1510 r8.in.old_val = &bufp2;
1511 r8.in.old_mtime = &old_mtime;
1516 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QuerySecret_r(b, tctx, &r8),
1517 "QuerySecret failed");
1518 if (!NT_STATUS_IS_OK(r8.out.result)) {
1519 torture_comment(tctx, "QuerySecret failed - %s\n", nt_errstr(r8.out.result));
1522 if (!r8.out.new_val || !r8.out.old_val) {
1523 torture_comment(tctx, "in/out pointers not returned, despite being set on in for QuerySecret\n");
1525 } else if (r8.out.new_val->buf != NULL) {
1526 torture_comment(tctx, "NEW secret buffer must not be returned after OLD set\n");
1528 } else if (r8.out.old_val->buf == NULL) {
1529 torture_comment(tctx, "OLD secret buffer was not returned after OLD set\n");
1531 } else if (r8.out.new_mtime == NULL || r8.out.old_mtime == NULL) {
1532 torture_comment(tctx, "Both times not returned after OLD set\n");
1535 blob1.data = r8.out.old_val->buf->data;
1536 blob1.length = r8.out.old_val->buf->size;
1538 secret6 = sess_decrypt_string(tctx,
1539 &blob1, &session_key);
1541 if (strcmp(secret5, secret6) != 0) {
1542 torture_comment(tctx, "Returned OLD secret %s doesn't match %s\n", secret5, secret6);
1546 if (*r8.out.new_mtime != *r8.out.old_mtime) {
1547 torture_comment(tctx, "Returned secret (r8) %s did not had same mtime for both secrets: %s != %s\n",
1549 nt_time_string(tctx, *r8.out.old_mtime),
1550 nt_time_string(tctx, *r8.out.new_mtime));
1556 if (!test_Delete(b, tctx, &sec_handle)) {
1560 if (!test_DeleteObject(b, tctx, &sec_handle)) {
1564 d_o.in.handle = &sec_handle2;
1565 d_o.out.handle = &sec_handle2;
1566 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_DeleteObject_r(b, tctx, &d_o),
1567 "DeleteObject failed");
1568 if (!NT_STATUS_EQUAL(d_o.out.result, NT_STATUS_INVALID_HANDLE)) {
1569 torture_comment(tctx, "Second delete expected INVALID_HANDLE - %s\n", nt_errstr(d_o.out.result));
1573 torture_comment(tctx, "Testing OpenSecret of just-deleted secret\n");
1575 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenSecret_r(b, tctx, &r2),
1576 "OpenSecret failed");
1577 if (!NT_STATUS_EQUAL(r2.out.result, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
1578 torture_comment(tctx, "OpenSecret expected OBJECT_NAME_NOT_FOUND - %s\n", nt_errstr(r2.out.result));
1589 static bool test_EnumAccountRights(struct dcerpc_binding_handle *b,
1590 struct torture_context *tctx,
1591 struct policy_handle *acct_handle,
1592 struct dom_sid *sid)
1594 struct lsa_EnumAccountRights r;
1595 struct lsa_RightSet rights;
1597 torture_comment(tctx, "\nTesting EnumAccountRights\n");
1599 r.in.handle = acct_handle;
1601 r.out.rights = &rights;
1603 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumAccountRights_r(b, tctx, &r),
1604 "EnumAccountRights failed");
1605 if (!NT_STATUS_IS_OK(r.out.result)) {
1606 torture_comment(tctx, "EnumAccountRights of %s failed - %s\n",
1607 dom_sid_string(tctx, sid), nt_errstr(r.out.result));
1615 static bool test_QuerySecurity(struct dcerpc_binding_handle *b,
1616 struct torture_context *tctx,
1617 struct policy_handle *handle,
1618 struct policy_handle *acct_handle)
1620 struct lsa_QuerySecurity r;
1621 struct sec_desc_buf *sdbuf = NULL;
1623 if (torture_setting_bool(tctx, "samba4", false)) {
1624 torture_comment(tctx, "\nskipping QuerySecurity test against Samba4\n");
1628 torture_comment(tctx, "\nTesting QuerySecurity\n");
1630 r.in.handle = acct_handle;
1631 r.in.sec_info = SECINFO_OWNER |
1634 r.out.sdbuf = &sdbuf;
1636 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QuerySecurity_r(b, tctx, &r),
1637 "QuerySecurity failed");
1638 if (!NT_STATUS_IS_OK(r.out.result)) {
1639 torture_comment(tctx, "QuerySecurity failed - %s\n", nt_errstr(r.out.result));
1646 static bool test_OpenAccount(struct dcerpc_binding_handle *b,
1647 struct torture_context *tctx,
1648 struct policy_handle *handle,
1649 struct dom_sid *sid)
1651 struct lsa_OpenAccount r;
1652 struct policy_handle acct_handle;
1654 torture_comment(tctx, "\nTesting OpenAccount\n");
1656 r.in.handle = handle;
1658 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1659 r.out.acct_handle = &acct_handle;
1661 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenAccount_r(b, tctx, &r),
1662 "OpenAccount failed");
1663 if (!NT_STATUS_IS_OK(r.out.result)) {
1664 torture_comment(tctx, "OpenAccount failed - %s\n", nt_errstr(r.out.result));
1668 if (!test_EnumPrivsAccount(b, tctx, handle, &acct_handle)) {
1672 if (!test_GetSystemAccessAccount(b, tctx, handle, &acct_handle)) {
1676 if (!test_QuerySecurity(b, tctx, handle, &acct_handle)) {
1683 static bool test_EnumAccounts(struct dcerpc_binding_handle *b,
1684 struct torture_context *tctx,
1685 struct policy_handle *handle)
1687 struct lsa_EnumAccounts r;
1688 struct lsa_SidArray sids1, sids2;
1689 uint32_t resume_handle = 0;
1693 torture_comment(tctx, "\nTesting EnumAccounts\n");
1695 r.in.handle = handle;
1696 r.in.resume_handle = &resume_handle;
1697 r.in.num_entries = 100;
1698 r.out.resume_handle = &resume_handle;
1699 r.out.sids = &sids1;
1703 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumAccounts_r(b, tctx, &r),
1704 "EnumAccounts failed");
1705 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_NO_MORE_ENTRIES)) {
1708 if (!NT_STATUS_IS_OK(r.out.result)) {
1709 torture_comment(tctx, "EnumAccounts failed - %s\n", nt_errstr(r.out.result));
1713 if (!test_LookupSids(b, tctx, handle, &sids1)) {
1717 if (!test_LookupSids2(b, tctx, handle, &sids1)) {
1721 /* Can't test lookupSids3 here, as clearly we must not
1722 * be on schannel, or we would not be able to do the
1725 torture_comment(tctx, "Testing all accounts\n");
1726 for (i=0;i<sids1.num_sids;i++) {
1727 ret &= test_OpenAccount(b, tctx, handle, sids1.sids[i].sid);
1728 ret &= test_EnumAccountRights(b, tctx, handle, sids1.sids[i].sid);
1730 torture_comment(tctx, "\n");
1733 if (sids1.num_sids < 3) {
1737 torture_comment(tctx, "Trying EnumAccounts partial listing (asking for 1 at 2)\n");
1739 r.in.num_entries = 1;
1740 r.out.sids = &sids2;
1742 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumAccounts_r(b, tctx, &r),
1743 "EnumAccounts failed");
1744 if (!NT_STATUS_IS_OK(r.out.result)) {
1745 torture_comment(tctx, "EnumAccounts failed - %s\n", nt_errstr(r.out.result));
1749 if (sids2.num_sids != 1) {
1750 torture_comment(tctx, "Returned wrong number of entries (%d)\n", sids2.num_sids);
1757 static bool test_LookupPrivDisplayName(struct dcerpc_binding_handle *b,
1758 struct torture_context *tctx,
1759 struct policy_handle *handle,
1760 struct lsa_String *priv_name)
1762 struct lsa_LookupPrivDisplayName r;
1763 /* produce a reasonable range of language output without screwing up
1765 uint16_t language_id = (random() % 4) + 0x409;
1766 uint16_t returned_language_id = 0;
1767 struct lsa_StringLarge *disp_name = NULL;
1769 torture_comment(tctx, "\nTesting LookupPrivDisplayName(%s)\n", priv_name->string);
1771 r.in.handle = handle;
1772 r.in.name = priv_name;
1773 r.in.language_id = language_id;
1774 r.in.language_id_sys = 0;
1775 r.out.returned_language_id = &returned_language_id;
1776 r.out.disp_name = &disp_name;
1778 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupPrivDisplayName_r(b, tctx, &r),
1779 "LookupPrivDisplayName failed");
1780 if (!NT_STATUS_IS_OK(r.out.result)) {
1781 torture_comment(tctx, "LookupPrivDisplayName failed - %s\n", nt_errstr(r.out.result));
1784 torture_comment(tctx, "%s -> \"%s\" (language 0x%x/0x%x)\n",
1785 priv_name->string, disp_name->string,
1786 r.in.language_id, *r.out.returned_language_id);
1791 static bool test_EnumAccountsWithUserRight(struct dcerpc_binding_handle *b,
1792 struct torture_context *tctx,
1793 struct policy_handle *handle,
1794 struct lsa_String *priv_name)
1796 struct lsa_EnumAccountsWithUserRight r;
1797 struct lsa_SidArray sids;
1801 torture_comment(tctx, "\nTesting EnumAccountsWithUserRight(%s)\n", priv_name->string);
1803 r.in.handle = handle;
1804 r.in.name = priv_name;
1807 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumAccountsWithUserRight_r(b, tctx, &r),
1808 "EnumAccountsWithUserRight failed");
1810 /* NT_STATUS_NO_MORE_ENTRIES means noone has this privilege */
1811 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_NO_MORE_ENTRIES)) {
1815 if (!NT_STATUS_IS_OK(r.out.result)) {
1816 torture_comment(tctx, "EnumAccountsWithUserRight failed - %s\n", nt_errstr(r.out.result));
1824 static bool test_EnumPrivs(struct dcerpc_binding_handle *b,
1825 struct torture_context *tctx,
1826 struct policy_handle *handle)
1828 struct lsa_EnumPrivs r;
1829 struct lsa_PrivArray privs1;
1830 uint32_t resume_handle = 0;
1834 torture_comment(tctx, "\nTesting EnumPrivs\n");
1836 r.in.handle = handle;
1837 r.in.resume_handle = &resume_handle;
1838 r.in.max_count = 100;
1839 r.out.resume_handle = &resume_handle;
1840 r.out.privs = &privs1;
1843 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumPrivs_r(b, tctx, &r),
1844 "EnumPrivs failed");
1845 if (!NT_STATUS_IS_OK(r.out.result)) {
1846 torture_comment(tctx, "EnumPrivs failed - %s\n", nt_errstr(r.out.result));
1850 for (i = 0; i< privs1.count; i++) {
1851 test_LookupPrivDisplayName(b, tctx, handle, (struct lsa_String *)&privs1.privs[i].name);
1852 test_LookupPrivValue(b, tctx, handle, (struct lsa_String *)&privs1.privs[i].name);
1853 if (!test_EnumAccountsWithUserRight(b, tctx, handle, (struct lsa_String *)&privs1.privs[i].name)) {
1861 static bool test_QueryForestTrustInformation(struct dcerpc_binding_handle *b,
1862 struct torture_context *tctx,
1863 struct policy_handle *handle,
1864 const char *trusted_domain_name)
1867 struct lsa_lsaRQueryForestTrustInformation r;
1868 struct lsa_String string;
1869 struct lsa_ForestTrustInformation info, *info_ptr;
1871 torture_comment(tctx, "\nTesting lsaRQueryForestTrustInformation\n");
1873 if (torture_setting_bool(tctx, "samba4", false)) {
1874 torture_comment(tctx, "skipping QueryForestTrustInformation against Samba4\n");
1878 ZERO_STRUCT(string);
1880 if (trusted_domain_name) {
1881 init_lsa_String(&string, trusted_domain_name);
1886 r.in.handle = handle;
1887 r.in.trusted_domain_name = &string;
1889 r.out.forest_trust_info = &info_ptr;
1891 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_lsaRQueryForestTrustInformation_r(b, tctx, &r),
1892 "lsaRQueryForestTrustInformation failed");
1894 if (!NT_STATUS_IS_OK(r.out.result)) {
1895 torture_comment(tctx, "lsaRQueryForestTrustInformation of %s failed - %s\n", trusted_domain_name, nt_errstr(r.out.result));
1902 static bool test_query_each_TrustDomEx(struct dcerpc_binding_handle *b,
1903 struct torture_context *tctx,
1904 struct policy_handle *handle,
1905 struct lsa_DomainListEx *domains)
1910 for (i=0; i< domains->count; i++) {
1912 if (domains->domains[i].trust_attributes & NETR_TRUST_ATTRIBUTE_FOREST_TRANSITIVE) {
1913 ret &= test_QueryForestTrustInformation(b, tctx, handle,
1914 domains->domains[i].domain_name.string);
1921 static bool test_query_each_TrustDom(struct dcerpc_binding_handle *b,
1922 struct torture_context *tctx,
1923 struct policy_handle *handle,
1924 struct lsa_DomainList *domains)
1929 torture_comment(tctx, "\nTesting OpenTrustedDomain, OpenTrustedDomainByName and QueryInfoTrustedDomain\n");
1930 for (i=0; i< domains->count; i++) {
1931 struct lsa_OpenTrustedDomain trust;
1932 struct lsa_OpenTrustedDomainByName trust_by_name;
1933 struct policy_handle trustdom_handle;
1934 struct policy_handle handle2;
1936 struct lsa_CloseTrustedDomainEx c_trust;
1937 int levels [] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
1938 int ok[] = {1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1};
1940 if (domains->domains[i].sid) {
1941 trust.in.handle = handle;
1942 trust.in.sid = domains->domains[i].sid;
1943 trust.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1944 trust.out.trustdom_handle = &trustdom_handle;
1946 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenTrustedDomain_r(b, tctx, &trust),
1947 "OpenTrustedDomain failed");
1949 if (!NT_STATUS_IS_OK(trust.out.result)) {
1950 torture_comment(tctx, "OpenTrustedDomain failed - %s\n", nt_errstr(trust.out.result));
1954 c.in.handle = &trustdom_handle;
1955 c.out.handle = &handle2;
1957 c_trust.in.handle = &trustdom_handle;
1958 c_trust.out.handle = &handle2;
1960 for (j=0; j < ARRAY_SIZE(levels); j++) {
1961 struct lsa_QueryTrustedDomainInfo q;
1962 union lsa_TrustedDomainInfo *info = NULL;
1963 q.in.trustdom_handle = &trustdom_handle;
1964 q.in.level = levels[j];
1966 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryTrustedDomainInfo_r(b, tctx, &q),
1967 "QueryTrustedDomainInfo failed");
1968 if (!NT_STATUS_IS_OK(q.out.result) && ok[j]) {
1969 torture_comment(tctx, "QueryTrustedDomainInfo level %d failed - %s\n",
1970 levels[j], nt_errstr(q.out.result));
1972 } else if (NT_STATUS_IS_OK(q.out.result) && !ok[j]) {
1973 torture_comment(tctx, "QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
1974 levels[j], nt_errstr(q.out.result));
1979 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_CloseTrustedDomainEx_r(b, tctx, &c_trust),
1980 "CloseTrustedDomainEx failed");
1981 if (!NT_STATUS_EQUAL(c_trust.out.result, NT_STATUS_NOT_IMPLEMENTED)) {
1982 torture_comment(tctx, "Expected CloseTrustedDomainEx to return NT_STATUS_NOT_IMPLEMENTED, instead - %s\n", nt_errstr(c_trust.out.result));
1986 c.in.handle = &trustdom_handle;
1987 c.out.handle = &handle2;
1989 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_Close_r(b, tctx, &c),
1991 if (!NT_STATUS_IS_OK(c.out.result)) {
1992 torture_comment(tctx, "Close of trusted domain failed - %s\n", nt_errstr(c.out.result));
1996 for (j=0; j < ARRAY_SIZE(levels); j++) {
1997 struct lsa_QueryTrustedDomainInfoBySid q;
1998 union lsa_TrustedDomainInfo *info = NULL;
2000 if (!domains->domains[i].sid) {
2004 q.in.handle = handle;
2005 q.in.dom_sid = domains->domains[i].sid;
2006 q.in.level = levels[j];
2009 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryTrustedDomainInfoBySid_r(b, tctx, &q),
2010 "lsa_QueryTrustedDomainInfoBySid failed");
2011 if (!NT_STATUS_IS_OK(q.out.result) && ok[j]) {
2012 torture_comment(tctx, "QueryTrustedDomainInfoBySid level %d failed - %s\n",
2013 levels[j], nt_errstr(q.out.result));
2015 } else if (NT_STATUS_IS_OK(q.out.result) && !ok[j]) {
2016 torture_comment(tctx, "QueryTrustedDomainInfoBySid level %d unexpectedly succeeded - %s\n",
2017 levels[j], nt_errstr(q.out.result));
2023 trust_by_name.in.handle = handle;
2024 trust_by_name.in.name.string = domains->domains[i].name.string;
2025 trust_by_name.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2026 trust_by_name.out.trustdom_handle = &trustdom_handle;
2028 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenTrustedDomainByName_r(b, tctx, &trust_by_name),
2029 "OpenTrustedDomainByName failed");
2031 if (!NT_STATUS_IS_OK(trust_by_name.out.result)) {
2032 torture_comment(tctx, "OpenTrustedDomainByName failed - %s\n", nt_errstr(trust_by_name.out.result));
2036 for (j=0; j < ARRAY_SIZE(levels); j++) {
2037 struct lsa_QueryTrustedDomainInfo q;
2038 union lsa_TrustedDomainInfo *info = NULL;
2039 q.in.trustdom_handle = &trustdom_handle;
2040 q.in.level = levels[j];
2042 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryTrustedDomainInfo_r(b, tctx, &q),
2043 "QueryTrustedDomainInfo failed");
2044 if (!NT_STATUS_IS_OK(q.out.result) && ok[j]) {
2045 torture_comment(tctx, "QueryTrustedDomainInfo level %d failed - %s\n",
2046 levels[j], nt_errstr(q.out.result));
2048 } else if (NT_STATUS_IS_OK(q.out.result) && !ok[j]) {
2049 torture_comment(tctx, "QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
2050 levels[j], nt_errstr(q.out.result));
2055 c.in.handle = &trustdom_handle;
2056 c.out.handle = &handle2;
2058 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_Close_r(b, tctx, &c),
2060 if (!NT_STATUS_IS_OK(c.out.result)) {
2061 torture_comment(tctx, "Close of trusted domain failed - %s\n", nt_errstr(c.out.result));
2065 for (j=0; j < ARRAY_SIZE(levels); j++) {
2066 struct lsa_QueryTrustedDomainInfoByName q;
2067 union lsa_TrustedDomainInfo *info = NULL;
2068 struct lsa_String name;
2070 name.string = domains->domains[i].name.string;
2072 q.in.handle = handle;
2073 q.in.trusted_domain = &name;
2074 q.in.level = levels[j];
2076 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryTrustedDomainInfoByName_r(b, tctx, &q),
2077 "QueryTrustedDomainInfoByName failed");
2078 if (!NT_STATUS_IS_OK(q.out.result) && ok[j]) {
2079 torture_comment(tctx, "QueryTrustedDomainInfoByName level %d failed - %s\n",
2080 levels[j], nt_errstr(q.out.result));
2082 } else if (NT_STATUS_IS_OK(q.out.result) && !ok[j]) {
2083 torture_comment(tctx, "QueryTrustedDomainInfoByName level %d unexpectedly succeeded - %s\n",
2084 levels[j], nt_errstr(q.out.result));
2092 static bool test_EnumTrustDom(struct dcerpc_binding_handle *b,
2093 struct torture_context *tctx,
2094 struct policy_handle *handle)
2096 struct lsa_EnumTrustDom r;
2097 uint32_t in_resume_handle = 0;
2098 uint32_t out_resume_handle;
2099 struct lsa_DomainList domains;
2102 torture_comment(tctx, "\nTesting EnumTrustDom\n");
2104 r.in.handle = handle;
2105 r.in.resume_handle = &in_resume_handle;
2107 r.out.domains = &domains;
2108 r.out.resume_handle = &out_resume_handle;
2110 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumTrustDom_r(b, tctx, &r),
2111 "lsa_EnumTrustDom failed");
2113 /* according to MS-LSAD 3.1.4.7.8 output resume handle MUST
2114 * always be larger than the previous input resume handle, in
2115 * particular when hitting the last query it is vital to set the
2116 * resume handle correctly to avoid infinite client loops, as
2117 * seen e.g. with Windows XP SP3 when resume handle is 0 and
2118 * status is NT_STATUS_OK - gd */
2120 if (NT_STATUS_IS_OK(r.out.result) ||
2121 NT_STATUS_EQUAL(r.out.result, NT_STATUS_NO_MORE_ENTRIES) ||
2122 NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES))
2124 if (out_resume_handle <= in_resume_handle) {
2125 torture_comment(tctx, "EnumTrustDom failed - should have returned output resume_handle (0x%08x) larger than input resume handle (0x%08x)\n",
2126 out_resume_handle, in_resume_handle);
2131 if (NT_STATUS_IS_OK(r.out.result)) {
2132 if (domains.count == 0) {
2133 torture_comment(tctx, "EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2136 } else if (!(NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES) || NT_STATUS_EQUAL(r.out.result, NT_STATUS_NO_MORE_ENTRIES))) {
2137 torture_comment(tctx, "EnumTrustDom of zero size failed - %s\n", nt_errstr(r.out.result));
2141 /* Start from the bottom again */
2142 in_resume_handle = 0;
2145 r.in.handle = handle;
2146 r.in.resume_handle = &in_resume_handle;
2147 r.in.max_size = LSA_ENUM_TRUST_DOMAIN_MULTIPLIER * 3;
2148 r.out.domains = &domains;
2149 r.out.resume_handle = &out_resume_handle;
2151 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumTrustDom_r(b, tctx, &r),
2152 "EnumTrustDom failed");
2154 /* according to MS-LSAD 3.1.4.7.8 output resume handle MUST
2155 * always be larger than the previous input resume handle, in
2156 * particular when hitting the last query it is vital to set the
2157 * resume handle correctly to avoid infinite client loops, as
2158 * seen e.g. with Windows XP SP3 when resume handle is 0 and
2159 * status is NT_STATUS_OK - gd */
2161 if (NT_STATUS_IS_OK(r.out.result) ||
2162 NT_STATUS_EQUAL(r.out.result, NT_STATUS_NO_MORE_ENTRIES) ||
2163 NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES))
2165 if (out_resume_handle <= in_resume_handle) {
2166 torture_comment(tctx, "EnumTrustDom failed - should have returned output resume_handle (0x%08x) larger than input resume handle (0x%08x)\n",
2167 out_resume_handle, in_resume_handle);
2172 /* NO_MORE_ENTRIES is allowed */
2173 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_NO_MORE_ENTRIES)) {
2174 if (domains.count == 0) {
2177 torture_comment(tctx, "EnumTrustDom failed - should have returned 0 trusted domains with 'NT_STATUS_NO_MORE_ENTRIES'\n");
2179 } else if (NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES)) {
2180 /* Windows 2003 gets this off by one on the first run */
2181 if (r.out.domains->count < 3 || r.out.domains->count > 4) {
2182 torture_comment(tctx, "EnumTrustDom didn't fill the buffer we "
2183 "asked it to (got %d, expected %d / %d == %d entries)\n",
2184 r.out.domains->count, LSA_ENUM_TRUST_DOMAIN_MULTIPLIER * 3,
2185 LSA_ENUM_TRUST_DOMAIN_MULTIPLIER, r.in.max_size);
2188 } else if (!NT_STATUS_IS_OK(r.out.result)) {
2189 torture_comment(tctx, "EnumTrustDom failed - %s\n", nt_errstr(r.out.result));
2193 if (domains.count == 0) {
2194 torture_comment(tctx, "EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2198 ret &= test_query_each_TrustDom(b, tctx, handle, &domains);
2200 in_resume_handle = out_resume_handle;
2202 } while ((NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES)));
2207 static bool test_EnumTrustDomEx(struct dcerpc_binding_handle *b,
2208 struct torture_context *tctx,
2209 struct policy_handle *handle)
2211 struct lsa_EnumTrustedDomainsEx r_ex;
2212 uint32_t resume_handle = 0;
2213 struct lsa_DomainListEx domains_ex;
2216 torture_comment(tctx, "\nTesting EnumTrustedDomainsEx\n");
2218 r_ex.in.handle = handle;
2219 r_ex.in.resume_handle = &resume_handle;
2220 r_ex.in.max_size = LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER * 3;
2221 r_ex.out.domains = &domains_ex;
2222 r_ex.out.resume_handle = &resume_handle;
2224 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumTrustedDomainsEx_r(b, tctx, &r_ex),
2225 "EnumTrustedDomainsEx failed");
2227 if (!(NT_STATUS_EQUAL(r_ex.out.result, STATUS_MORE_ENTRIES) || NT_STATUS_EQUAL(r_ex.out.result, NT_STATUS_NO_MORE_ENTRIES))) {
2228 torture_comment(tctx, "EnumTrustedDomainEx of zero size failed - %s\n", nt_errstr(r_ex.out.result));
2234 r_ex.in.handle = handle;
2235 r_ex.in.resume_handle = &resume_handle;
2236 r_ex.in.max_size = LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER * 3;
2237 r_ex.out.domains = &domains_ex;
2238 r_ex.out.resume_handle = &resume_handle;
2240 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumTrustedDomainsEx_r(b, tctx, &r_ex),
2241 "EnumTrustedDomainsEx failed");
2243 /* NO_MORE_ENTRIES is allowed */
2244 if (NT_STATUS_EQUAL(r_ex.out.result, NT_STATUS_NO_MORE_ENTRIES)) {
2245 if (domains_ex.count == 0) {
2248 torture_comment(tctx, "EnumTrustDomainsEx failed - should have returned 0 trusted domains with 'NT_STATUS_NO_MORE_ENTRIES'\n");
2250 } else if (NT_STATUS_EQUAL(r_ex.out.result, STATUS_MORE_ENTRIES)) {
2251 /* Windows 2003 gets this off by one on the first run */
2252 if (r_ex.out.domains->count < 3 || r_ex.out.domains->count > 4) {
2253 torture_comment(tctx, "EnumTrustDom didn't fill the buffer we "
2254 "asked it to (got %d, expected %d / %d == %d entries)\n",
2255 r_ex.out.domains->count,
2257 LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER,
2258 r_ex.in.max_size / LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER);
2260 } else if (!NT_STATUS_IS_OK(r_ex.out.result)) {
2261 torture_comment(tctx, "EnumTrustedDomainEx failed - %s\n", nt_errstr(r_ex.out.result));
2265 if (domains_ex.count == 0) {
2266 torture_comment(tctx, "EnumTrustDomainEx failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2270 ret &= test_query_each_TrustDomEx(b, tctx, handle, &domains_ex);
2272 } while ((NT_STATUS_EQUAL(r_ex.out.result, STATUS_MORE_ENTRIES)));
2278 static bool test_CreateTrustedDomain(struct dcerpc_binding_handle *b,
2279 struct torture_context *tctx,
2280 struct policy_handle *handle,
2281 uint32_t num_trusts)
2284 struct lsa_CreateTrustedDomain r;
2285 struct lsa_DomainInfo trustinfo;
2286 struct dom_sid **domsid;
2287 struct policy_handle *trustdom_handle;
2288 struct lsa_QueryTrustedDomainInfo q;
2289 union lsa_TrustedDomainInfo *info = NULL;
2292 torture_comment(tctx, "\nTesting CreateTrustedDomain for %d domains\n", num_trusts);
2294 if (!test_EnumTrustDom(b, tctx, handle)) {
2298 if (!test_EnumTrustDomEx(b, tctx, handle)) {
2302 domsid = talloc_array(tctx, struct dom_sid *, num_trusts);
2303 trustdom_handle = talloc_array(tctx, struct policy_handle, num_trusts);
2305 for (i=0; i< num_trusts; i++) {
2306 char *trust_name = talloc_asprintf(tctx, "torturedom%02d", i);
2307 char *trust_sid = talloc_asprintf(tctx, "S-1-5-21-97398-379795-100%02d", i);
2309 domsid[i] = dom_sid_parse_talloc(tctx, trust_sid);
2311 trustinfo.sid = domsid[i];
2312 init_lsa_String((struct lsa_String *)&trustinfo.name, trust_name);
2314 r.in.policy_handle = handle;
2315 r.in.info = &trustinfo;
2316 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2317 r.out.trustdom_handle = &trustdom_handle[i];
2319 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_CreateTrustedDomain_r(b, tctx, &r),
2320 "CreateTrustedDomain failed");
2321 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_OBJECT_NAME_COLLISION)) {
2322 test_DeleteTrustedDomain(b, tctx, handle, trustinfo.name);
2323 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_CreateTrustedDomain_r(b, tctx, &r),
2324 "CreateTrustedDomain failed");
2326 if (!NT_STATUS_IS_OK(r.out.result)) {
2327 torture_comment(tctx, "CreateTrustedDomain failed - %s\n", nt_errstr(r.out.result));
2331 q.in.trustdom_handle = &trustdom_handle[i];
2332 q.in.level = LSA_TRUSTED_DOMAIN_INFO_INFO_EX;
2334 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryTrustedDomainInfo_r(b, tctx, &q),
2335 "QueryTrustedDomainInfo failed");
2336 if (!NT_STATUS_IS_OK(q.out.result)) {
2337 torture_comment(tctx, "QueryTrustedDomainInfo level %d failed - %s\n", q.in.level, nt_errstr(q.out.result));
2339 } else if (!q.out.info) {
2342 if (strcmp(info->info_ex.netbios_name.string, trustinfo.name.string) != 0) {
2343 torture_comment(tctx, "QueryTrustedDomainInfo returned inconsistent short name: %s != %s\n",
2344 info->info_ex.netbios_name.string, trustinfo.name.string);
2347 if (info->info_ex.trust_type != LSA_TRUST_TYPE_DOWNLEVEL) {
2348 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
2349 trust_name, info->info_ex.trust_type, LSA_TRUST_TYPE_DOWNLEVEL);
2352 if (info->info_ex.trust_attributes != 0) {
2353 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
2354 trust_name, info->info_ex.trust_attributes, 0);
2357 if (info->info_ex.trust_direction != LSA_TRUST_DIRECTION_OUTBOUND) {
2358 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
2359 trust_name, info->info_ex.trust_direction, LSA_TRUST_DIRECTION_OUTBOUND);
2366 /* now that we have some domains to look over, we can test the enum calls */
2367 if (!test_EnumTrustDom(b, tctx, handle)) {
2371 if (!test_EnumTrustDomEx(b, tctx, handle)) {
2375 for (i=0; i<num_trusts; i++) {
2376 if (!test_DeleteTrustedDomainBySid(b, tctx, handle, domsid[i])) {
2384 static bool gen_authinfo_internal(TALLOC_CTX *mem_ctx, const char *password,
2385 DATA_BLOB session_key,
2386 struct lsa_TrustDomainInfoAuthInfoInternal **_authinfo_internal)
2388 struct lsa_TrustDomainInfoAuthInfoInternal *authinfo_internal;
2389 struct trustDomainPasswords auth_struct;
2390 struct AuthenticationInformation *auth_info_array;
2391 size_t converted_size;
2392 DATA_BLOB auth_blob;
2393 enum ndr_err_code ndr_err;
2395 authinfo_internal = talloc_zero(mem_ctx, struct lsa_TrustDomainInfoAuthInfoInternal);
2396 if (authinfo_internal == NULL) {
2400 auth_info_array = talloc_array(mem_ctx,
2401 struct AuthenticationInformation, 1);
2402 if (auth_info_array == NULL) {
2406 generate_random_buffer(auth_struct.confounder, sizeof(auth_struct.confounder));
2408 auth_info_array[0].AuthType = TRUST_AUTH_TYPE_CLEAR;
2410 if (!convert_string_talloc(mem_ctx, CH_UNIX, CH_UTF16, password,
2412 &auth_info_array[0].AuthInfo.clear.password,
2417 auth_info_array[0].AuthInfo.clear.size = converted_size;
2419 auth_struct.outgoing.count = 1;
2420 auth_struct.outgoing.current.count = 1;
2421 auth_struct.outgoing.current.array = auth_info_array;
2422 auth_struct.outgoing.previous.count = 0;
2423 auth_struct.outgoing.previous.array = NULL;
2425 auth_struct.incoming.count = 1;
2426 auth_struct.incoming.current.count = 1;
2427 auth_struct.incoming.current.array = auth_info_array;
2428 auth_struct.incoming.previous.count = 0;
2429 auth_struct.incoming.previous.array = NULL;
2432 ndr_err = ndr_push_struct_blob(&auth_blob, mem_ctx, &auth_struct,
2433 (ndr_push_flags_fn_t)ndr_push_trustDomainPasswords);
2434 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2438 arcfour_crypt_blob(auth_blob.data, auth_blob.length, &session_key);
2440 authinfo_internal->auth_blob.size = auth_blob.length;
2441 authinfo_internal->auth_blob.data = auth_blob.data;
2443 *_authinfo_internal = authinfo_internal;
2448 static bool gen_authinfo(TALLOC_CTX *mem_ctx, const char *password,
2449 struct lsa_TrustDomainInfoAuthInfo **_authinfo)
2451 struct lsa_TrustDomainInfoAuthInfo *authinfo;
2452 struct lsa_TrustDomainInfoBuffer *info_buffer;
2453 size_t converted_size;
2455 authinfo = talloc_zero(mem_ctx, struct lsa_TrustDomainInfoAuthInfo);
2456 if (authinfo == NULL) {
2460 info_buffer = talloc_zero(mem_ctx, struct lsa_TrustDomainInfoBuffer);
2461 if (info_buffer == NULL) {
2465 info_buffer->AuthType = TRUST_AUTH_TYPE_CLEAR;
2467 if (!convert_string_talloc(mem_ctx, CH_UNIX, CH_UTF16, password,
2469 &info_buffer->data.data,
2474 info_buffer->data.size = converted_size;
2476 authinfo->incoming_count = 1;
2477 authinfo->incoming_current_auth_info = info_buffer;
2478 authinfo->incoming_previous_auth_info = NULL;
2479 authinfo->outgoing_count = 1;
2480 authinfo->outgoing_current_auth_info = info_buffer;
2481 authinfo->outgoing_previous_auth_info = NULL;
2483 *_authinfo = authinfo;
2488 static bool check_pw_with_ServerAuthenticate3(struct dcerpc_pipe *p,
2489 struct torture_context *tctx,
2490 uint32_t negotiate_flags,
2491 struct cli_credentials *machine_credentials,
2492 struct netlogon_creds_CredentialState **creds_out)
2494 struct netr_ServerReqChallenge r;
2495 struct netr_ServerAuthenticate3 a;
2496 struct netr_Credential credentials1, credentials2, credentials3;
2497 struct netlogon_creds_CredentialState *creds;
2498 struct samr_Password mach_password;
2500 const char *machine_name;
2501 const char *plain_pass;
2502 struct dcerpc_binding_handle *b = p->binding_handle;
2504 machine_name = cli_credentials_get_workstation(machine_credentials);
2505 plain_pass = cli_credentials_get_password(machine_credentials);
2507 r.in.server_name = NULL;
2508 r.in.computer_name = machine_name;
2509 r.in.credentials = &credentials1;
2510 r.out.return_credentials = &credentials2;
2512 generate_random_buffer(credentials1.data, sizeof(credentials1.data));
2514 torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerReqChallenge_r(b, tctx, &r),
2515 "ServerReqChallenge failed");
2516 torture_assert_ntstatus_ok(tctx, r.out.result, "ServerReqChallenge failed");
2518 E_md4hash(plain_pass, mach_password.hash);
2520 a.in.server_name = NULL;
2521 a.in.account_name = talloc_asprintf(tctx, "%s$", machine_name);
2522 a.in.secure_channel_type = cli_credentials_get_secure_channel_type(machine_credentials);
2523 a.in.computer_name = machine_name;
2524 a.in.negotiate_flags = &negotiate_flags;
2525 a.in.credentials = &credentials3;
2526 a.out.return_credentials = &credentials3;
2527 a.out.negotiate_flags = &negotiate_flags;
2530 creds = netlogon_creds_client_init(tctx, a.in.account_name,
2532 &credentials1, &credentials2,
2533 &mach_password, &credentials3,
2536 torture_assert(tctx, creds != NULL, "memory allocation");
2538 torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerAuthenticate3_r(b, tctx, &a),
2539 "ServerAuthenticate3 failed");
2540 if (!NT_STATUS_IS_OK(a.out.result)) {
2541 if (!NT_STATUS_EQUAL(a.out.result, NT_STATUS_ACCESS_DENIED)) {
2542 torture_assert_ntstatus_ok(tctx, a.out.result,
2543 "ServerAuthenticate3 failed");
2547 torture_assert(tctx, netlogon_creds_client_check(creds, &credentials3), "Credential chaining failed");
2549 /* Prove that requesting a challenge again won't break it */
2550 torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerReqChallenge_r(b, tctx, &r),
2551 "ServerReqChallenge failed");
2552 torture_assert_ntstatus_ok(tctx, r.out.result, "ServerReqChallenge failed");
2558 static bool check_dom_trust_pw(struct dcerpc_pipe *p,
2559 struct torture_context *tctx,
2560 const char *trusted_dom_name,
2561 const char *password)
2563 struct cli_credentials *credentials;
2565 struct netlogon_creds_CredentialState *creds;
2566 struct dcerpc_pipe *pipe;
2570 credentials = cli_credentials_init(tctx);
2571 if (credentials == NULL) {
2575 dummy = talloc_asprintf(tctx, "%s$", trusted_dom_name);
2576 if (dummy == NULL) {
2580 cli_credentials_set_username(credentials, dummy, CRED_SPECIFIED);
2581 cli_credentials_set_password(credentials, password, CRED_SPECIFIED);
2582 cli_credentials_set_workstation(credentials,
2583 trusted_dom_name, CRED_SPECIFIED);
2584 cli_credentials_set_secure_channel_type(credentials, SEC_CHAN_DOMAIN);
2586 status = dcerpc_pipe_connect_b(tctx, &pipe, p->binding,
2587 &ndr_table_netlogon,
2588 cli_credentials_init_anon(tctx),
2589 tctx->ev, tctx->lp_ctx);
2590 if (!NT_STATUS_IS_OK(status)) {
2591 torture_comment(tctx, "dcerpc_pipe_connect_b failed.\n");
2595 ok = check_pw_with_ServerAuthenticate3(pipe, tctx,
2596 NETLOGON_NEG_AUTH2_ADS_FLAGS,
2597 credentials, &creds);
2603 static bool test_CreateTrustedDomainEx_common(struct dcerpc_pipe *p,
2604 struct torture_context *tctx,
2605 struct policy_handle *handle,
2606 uint32_t num_trusts,
2611 struct lsa_CreateTrustedDomainEx r;
2612 struct lsa_CreateTrustedDomainEx2 r2;
2613 struct lsa_TrustDomainInfoInfoEx trustinfo;
2614 struct lsa_TrustDomainInfoAuthInfoInternal *authinfo_internal;
2615 struct lsa_TrustDomainInfoAuthInfo *authinfo;
2616 struct dom_sid **domsid;
2617 struct policy_handle *trustdom_handle;
2618 struct lsa_QueryTrustedDomainInfo q;
2619 union lsa_TrustedDomainInfo *info = NULL;
2620 DATA_BLOB session_key;
2622 struct dcerpc_binding_handle *b = p->binding_handle;
2625 torture_comment(tctx, "\nTesting CreateTrustedDomainEx2 for %d domains\n", num_trusts);
2627 torture_comment(tctx, "\nTesting CreateTrustedDomainEx for %d domains\n", num_trusts);
2630 domsid = talloc_array(tctx, struct dom_sid *, num_trusts);
2631 trustdom_handle = talloc_array(tctx, struct policy_handle, num_trusts);
2633 status = dcerpc_fetch_session_key(p, &session_key);
2634 if (!NT_STATUS_IS_OK(status)) {
2635 torture_comment(tctx, "dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
2639 for (i=0; i< num_trusts; i++) {
2640 char *trust_name = talloc_asprintf(tctx, "torturedom%02d", i);
2641 char *trust_name_dns = talloc_asprintf(tctx, "torturedom%02d.samba.example.com", i);
2642 char *trust_sid = talloc_asprintf(tctx, "S-1-5-21-97398-379795-100%02d", i);
2644 domsid[i] = dom_sid_parse_talloc(tctx, trust_sid);
2646 trustinfo.sid = domsid[i];
2647 trustinfo.netbios_name.string = trust_name;
2648 trustinfo.domain_name.string = trust_name_dns;
2650 /* Create inbound, some outbound, and some
2651 * bi-directional trusts in a repeating pattern based
2654 /* 1 == inbound, 2 == outbound, 3 == both */
2655 trustinfo.trust_direction = (i % 3) + 1;
2657 /* Try different trust types too */
2659 /* 1 == downlevel (NT4), 2 == uplevel (ADS), 3 == MIT (kerberos but not AD) */
2660 trustinfo.trust_type = (((i / 3) + 1) % 3) + 1;
2662 trustinfo.trust_attributes = LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION;
2664 if (!gen_authinfo_internal(tctx, TRUSTPW, session_key, &authinfo_internal)) {
2665 torture_comment(tctx, "gen_authinfo_internal failed");
2669 if (!gen_authinfo(tctx, TRUSTPW, &authinfo)) {
2670 torture_comment(tctx, "gen_authinfonfo failed");
2676 r2.in.policy_handle = handle;
2677 r2.in.info = &trustinfo;
2678 r2.in.auth_info_internal = authinfo_internal;
2679 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2680 r2.out.trustdom_handle = &trustdom_handle[i];
2682 torture_assert_ntstatus_ok(tctx,
2683 dcerpc_lsa_CreateTrustedDomainEx2_r(b, tctx, &r2),
2684 "CreateTrustedDomainEx2 failed");
2686 status = r2.out.result;
2689 r.in.policy_handle = handle;
2690 r.in.info = &trustinfo;
2691 r.in.auth_info = authinfo;
2692 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2693 r.out.trustdom_handle = &trustdom_handle[i];
2695 torture_assert_ntstatus_ok(tctx,
2696 dcerpc_lsa_CreateTrustedDomainEx_r(b, tctx, &r),
2697 "CreateTrustedDomainEx failed");
2699 status = r.out.result;
2702 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
2703 test_DeleteTrustedDomain(b, tctx, handle, trustinfo.netbios_name);
2705 torture_assert_ntstatus_ok(tctx,
2706 dcerpc_lsa_CreateTrustedDomainEx2_r(b, tctx, &r2),
2707 "CreateTrustedDomainEx2 failed");
2708 status = r2.out.result;
2710 torture_assert_ntstatus_ok(tctx,
2711 dcerpc_lsa_CreateTrustedDomainEx_r(b, tctx, &r),
2712 "CreateTrustedDomainEx2 failed");
2713 status = r.out.result;
2716 if (!NT_STATUS_IS_OK(status)) {
2717 torture_comment(tctx, "CreateTrustedDomainEx failed2 - %s\n", nt_errstr(status));
2720 /* For outbound and MIT trusts there is no trust account */
2721 if (trustinfo.trust_direction != 2 &&
2722 trustinfo.trust_type != 3) {
2724 if (torture_setting_bool(tctx, "samba3", false) ||
2725 torture_setting_bool(tctx, "samba4", false)) {
2726 torture_comment(tctx, "skipping trusted domain auth tests against samba");
2728 if (check_dom_trust_pw(p, tctx, trust_name,
2730 torture_comment(tctx, "Password check passed unexpectedly\n");
2733 if (!check_dom_trust_pw(p, tctx, trust_name,
2735 torture_comment(tctx, "Password check failed\n");
2741 q.in.trustdom_handle = &trustdom_handle[i];
2742 q.in.level = LSA_TRUSTED_DOMAIN_INFO_INFO_EX;
2744 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryTrustedDomainInfo_r(b, tctx, &q),
2745 "QueryTrustedDomainInfo failed");
2746 if (!NT_STATUS_IS_OK(q.out.result)) {
2747 torture_comment(tctx, "QueryTrustedDomainInfo level 1 failed - %s\n", nt_errstr(q.out.result));
2749 } else if (!q.out.info) {
2750 torture_comment(tctx, "QueryTrustedDomainInfo level 1 failed to return an info pointer\n");
2753 if (strcmp(info->info_ex.netbios_name.string, trustinfo.netbios_name.string) != 0) {
2754 torture_comment(tctx, "QueryTrustedDomainInfo returned inconsistent short name: %s != %s\n",
2755 info->info_ex.netbios_name.string, trustinfo.netbios_name.string);
2758 if (info->info_ex.trust_type != trustinfo.trust_type) {
2759 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
2760 trust_name, info->info_ex.trust_type, trustinfo.trust_type);
2763 if (info->info_ex.trust_attributes != LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION) {
2764 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
2765 trust_name, info->info_ex.trust_attributes, LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION);
2768 if (info->info_ex.trust_direction != trustinfo.trust_direction) {
2769 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
2770 trust_name, info->info_ex.trust_direction, trustinfo.trust_direction);
2777 /* now that we have some domains to look over, we can test the enum calls */
2778 if (!test_EnumTrustDom(b, tctx, handle)) {
2779 torture_comment(tctx, "test_EnumTrustDom failed\n");
2783 if (!test_EnumTrustDomEx(b, tctx, handle)) {
2784 torture_comment(tctx, "test_EnumTrustDomEx failed\n");
2788 for (i=0; i<num_trusts; i++) {
2789 if (!test_DeleteTrustedDomainBySid(b, tctx, handle, domsid[i])) {
2790 torture_comment(tctx, "test_DeleteTrustedDomainBySid failed\n");
2798 static bool test_CreateTrustedDomainEx2(struct dcerpc_pipe *p,
2799 struct torture_context *tctx,
2800 struct policy_handle *handle,
2801 uint32_t num_trusts)
2803 return test_CreateTrustedDomainEx_common(p, tctx, handle, num_trusts, true);
2806 static bool test_CreateTrustedDomainEx(struct dcerpc_pipe *p,
2807 struct torture_context *tctx,
2808 struct policy_handle *handle,
2809 uint32_t num_trusts)
2811 return test_CreateTrustedDomainEx_common(p, tctx, handle, num_trusts, false);
2814 static bool test_QueryDomainInfoPolicy(struct dcerpc_binding_handle *b,
2815 struct torture_context *tctx,
2816 struct policy_handle *handle)
2818 struct lsa_QueryDomainInformationPolicy r;
2819 union lsa_DomainInformationPolicy *info = NULL;
2823 if (torture_setting_bool(tctx, "samba3", false)) {
2824 torture_skip(tctx, "skipping QueryDomainInformationPolicy test\n");
2827 torture_comment(tctx, "\nTesting QueryDomainInformationPolicy\n");
2830 r.in.handle = handle;
2834 torture_comment(tctx, "\nTrying QueryDomainInformationPolicy level %d\n", i);
2836 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryDomainInformationPolicy_r(b, tctx, &r),
2837 "QueryDomainInformationPolicy failed");
2839 /* If the server does not support EFS, then this is the correct return */
2840 if (i == LSA_DOMAIN_INFO_POLICY_EFS && NT_STATUS_EQUAL(r.out.result, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
2842 } else if (!NT_STATUS_IS_OK(r.out.result)) {
2843 torture_comment(tctx, "QueryDomainInformationPolicy failed - %s\n", nt_errstr(r.out.result));
2853 static bool test_QueryInfoPolicyCalls( bool version2,
2854 struct dcerpc_binding_handle *b,
2855 struct torture_context *tctx,
2856 struct policy_handle *handle)
2858 struct lsa_QueryInfoPolicy r;
2859 union lsa_PolicyInformation *info = NULL;
2862 const char *call = talloc_asprintf(tctx, "QueryInfoPolicy%s", version2 ? "2":"");
2864 torture_comment(tctx, "\nTesting %s\n", call);
2866 if (version2 && torture_setting_bool(tctx, "samba3", false)) {
2867 torture_skip(tctx, "skipping QueryInfoPolicy2 tests\n");
2870 for (i=1;i<=14;i++) {
2871 r.in.handle = handle;
2875 torture_comment(tctx, "\nTrying %s level %d\n", call, i);
2878 /* We can perform the cast, because both types are
2879 structurally equal */
2880 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryInfoPolicy2_r(b, tctx,
2881 (struct lsa_QueryInfoPolicy2*) &r),
2882 "QueryInfoPolicy2 failed");
2884 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryInfoPolicy_r(b, tctx, &r),
2885 "QueryInfoPolicy2 failed");
2888 case LSA_POLICY_INFO_MOD:
2889 case LSA_POLICY_INFO_AUDIT_FULL_SET:
2890 case LSA_POLICY_INFO_AUDIT_FULL_QUERY:
2891 if (!NT_STATUS_EQUAL(r.out.result, NT_STATUS_INVALID_PARAMETER)) {
2892 torture_comment(tctx, "Server should have failed level %u: %s\n", i, nt_errstr(r.out.result));
2896 case LSA_POLICY_INFO_DOMAIN:
2897 case LSA_POLICY_INFO_ACCOUNT_DOMAIN:
2898 case LSA_POLICY_INFO_REPLICA:
2899 case LSA_POLICY_INFO_QUOTA:
2900 case LSA_POLICY_INFO_ROLE:
2901 case LSA_POLICY_INFO_AUDIT_LOG:
2902 case LSA_POLICY_INFO_AUDIT_EVENTS:
2903 case LSA_POLICY_INFO_PD:
2904 if (!NT_STATUS_IS_OK(r.out.result)) {
2905 torture_comment(tctx, "%s failed - %s\n", call, nt_errstr(r.out.result));
2909 case LSA_POLICY_INFO_L_ACCOUNT_DOMAIN:
2910 case LSA_POLICY_INFO_DNS_INT:
2911 case LSA_POLICY_INFO_DNS:
2912 if (torture_setting_bool(tctx, "samba3", false)) {
2913 /* Other levels not implemented yet */
2914 if (!NT_STATUS_EQUAL(r.out.result, NT_STATUS_INVALID_INFO_CLASS)) {
2915 torture_comment(tctx, "%s failed - %s\n", call, nt_errstr(r.out.result));
2918 } else if (!NT_STATUS_IS_OK(r.out.result)) {
2919 torture_comment(tctx, "%s failed - %s\n", call, nt_errstr(r.out.result));
2924 if (torture_setting_bool(tctx, "samba4", false)) {
2925 /* Other levels not implemented yet */
2926 if (!NT_STATUS_EQUAL(r.out.result, NT_STATUS_INVALID_INFO_CLASS)) {
2927 torture_comment(tctx, "%s failed - %s\n", call, nt_errstr(r.out.result));
2930 } else if (!NT_STATUS_IS_OK(r.out.result)) {
2931 torture_comment(tctx, "%s failed - %s\n", call, nt_errstr(r.out.result));
2937 if (NT_STATUS_IS_OK(r.out.result) && (i == LSA_POLICY_INFO_DNS
2938 || i == LSA_POLICY_INFO_DNS_INT)) {
2939 /* Let's look up some of these names */
2941 struct lsa_TransNameArray tnames;
2943 tnames.names = talloc_zero_array(tctx, struct lsa_TranslatedName, tnames.count);
2944 tnames.names[0].name.string = info->dns.name.string;
2945 tnames.names[0].sid_type = SID_NAME_DOMAIN;
2946 tnames.names[1].name.string = info->dns.dns_domain.string;
2947 tnames.names[1].sid_type = SID_NAME_DOMAIN;
2948 tnames.names[2].name.string = talloc_asprintf(tctx, "%s\\", info->dns.name.string);
2949 tnames.names[2].sid_type = SID_NAME_DOMAIN;
2950 tnames.names[3].name.string = talloc_asprintf(tctx, "%s\\", info->dns.dns_domain.string);
2951 tnames.names[3].sid_type = SID_NAME_DOMAIN;
2952 tnames.names[4].name.string = talloc_asprintf(tctx, "%s\\guest", info->dns.name.string);
2953 tnames.names[4].sid_type = SID_NAME_USER;
2954 tnames.names[5].name.string = talloc_asprintf(tctx, "%s\\krbtgt", info->dns.name.string);
2955 tnames.names[5].sid_type = SID_NAME_USER;
2956 tnames.names[6].name.string = talloc_asprintf(tctx, "%s\\guest", info->dns.dns_domain.string);
2957 tnames.names[6].sid_type = SID_NAME_USER;
2958 tnames.names[7].name.string = talloc_asprintf(tctx, "%s\\krbtgt", info->dns.dns_domain.string);
2959 tnames.names[7].sid_type = SID_NAME_USER;
2960 tnames.names[8].name.string = talloc_asprintf(tctx, "krbtgt@%s", info->dns.name.string);
2961 tnames.names[8].sid_type = SID_NAME_USER;
2962 tnames.names[9].name.string = talloc_asprintf(tctx, "krbtgt@%s", info->dns.dns_domain.string);
2963 tnames.names[9].sid_type = SID_NAME_USER;
2964 tnames.names[10].name.string = talloc_asprintf(tctx, "%s\\"TEST_MACHINENAME "$", info->dns.name.string);
2965 tnames.names[10].sid_type = SID_NAME_USER;
2966 tnames.names[11].name.string = talloc_asprintf(tctx, "%s\\"TEST_MACHINENAME "$", info->dns.dns_domain.string);
2967 tnames.names[11].sid_type = SID_NAME_USER;
2968 tnames.names[12].name.string = talloc_asprintf(tctx, TEST_MACHINENAME "$@%s", info->dns.name.string);
2969 tnames.names[12].sid_type = SID_NAME_USER;
2970 tnames.names[13].name.string = talloc_asprintf(tctx, TEST_MACHINENAME "$@%s", info->dns.dns_domain.string);
2971 tnames.names[13].sid_type = SID_NAME_USER;
2972 ret &= test_LookupNames(b, tctx, handle, &tnames);
2980 static bool test_QueryInfoPolicy(struct dcerpc_binding_handle *b,
2981 struct torture_context *tctx,
2982 struct policy_handle *handle)
2984 return test_QueryInfoPolicyCalls(false, b, tctx, handle);
2987 static bool test_QueryInfoPolicy2(struct dcerpc_binding_handle *b,
2988 struct torture_context *tctx,
2989 struct policy_handle *handle)
2991 return test_QueryInfoPolicyCalls(true, b, tctx, handle);
2994 static bool test_GetUserName(struct dcerpc_binding_handle *b,
2995 struct torture_context *tctx)
2997 struct lsa_GetUserName r;
2999 struct lsa_String *authority_name_p = NULL;
3000 struct lsa_String *account_name_p = NULL;
3002 torture_comment(tctx, "\nTesting GetUserName\n");
3004 r.in.system_name = "\\";
3005 r.in.account_name = &account_name_p;
3006 r.in.authority_name = NULL;
3007 r.out.account_name = &account_name_p;
3009 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_GetUserName_r(b, tctx, &r),
3010 "GetUserName failed");
3012 if (!NT_STATUS_IS_OK(r.out.result)) {
3013 torture_comment(tctx, "GetUserName failed - %s\n", nt_errstr(r.out.result));
3017 account_name_p = NULL;
3018 r.in.account_name = &account_name_p;
3019 r.in.authority_name = &authority_name_p;
3020 r.out.account_name = &account_name_p;
3022 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_GetUserName_r(b, tctx, &r),
3023 "GetUserName failed");
3025 if (!NT_STATUS_IS_OK(r.out.result)) {
3026 torture_comment(tctx, "GetUserName failed - %s\n", nt_errstr(r.out.result));
3033 bool test_lsa_Close(struct dcerpc_binding_handle *b,
3034 struct torture_context *tctx,
3035 struct policy_handle *handle)
3038 struct policy_handle handle2;
3040 torture_comment(tctx, "\nTesting Close\n");
3042 r.in.handle = handle;
3043 r.out.handle = &handle2;
3045 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_Close_r(b, tctx, &r),
3047 if (!NT_STATUS_IS_OK(r.out.result)) {
3048 torture_comment(tctx, "Close failed - %s\n",
3049 nt_errstr(r.out.result));
3053 torture_assert_ntstatus_equal(tctx, dcerpc_lsa_Close_r(b, tctx, &r),
3054 NT_STATUS_RPC_SS_CONTEXT_MISMATCH, "Close should failed");
3056 torture_comment(tctx, "\n");
3061 bool torture_rpc_lsa(struct torture_context *tctx)
3064 struct dcerpc_pipe *p;
3066 struct policy_handle *handle;
3067 struct test_join *join = NULL;
3068 struct cli_credentials *machine_creds;
3069 struct dcerpc_binding_handle *b;
3071 status = torture_rpc_connection(tctx, &p, &ndr_table_lsarpc);
3072 if (!NT_STATUS_IS_OK(status)) {
3075 b = p->binding_handle;
3077 if (!test_OpenPolicy(b, tctx)) {
3081 if (!test_lsa_OpenPolicy2(b, tctx, &handle)) {
3086 join = torture_join_domain(tctx, TEST_MACHINENAME, ACB_WSTRUST, &machine_creds);
3091 if (!test_LookupSids_async(b, tctx, handle)) {
3095 if (!test_QueryDomainInfoPolicy(b, tctx, handle)) {
3099 if (!test_CreateSecret(p, tctx, handle)) {
3103 if (!test_QueryInfoPolicy(b, tctx, handle)) {
3107 if (!test_QueryInfoPolicy2(b, tctx, handle)) {
3111 if (!test_Delete(b, tctx, handle)) {
3115 if (!test_many_LookupSids(p, tctx, handle)) {
3119 if (!test_lsa_Close(b, tctx, handle)) {
3123 torture_leave_domain(tctx, join);
3126 if (!test_many_LookupSids(p, tctx, handle)) {
3131 if (!test_GetUserName(b, tctx)) {
3138 bool torture_rpc_lsa_get_user(struct torture_context *tctx)
3141 struct dcerpc_pipe *p;
3143 struct dcerpc_binding_handle *b;
3145 status = torture_rpc_connection(tctx, &p, &ndr_table_lsarpc);
3146 if (!NT_STATUS_IS_OK(status)) {
3149 b = p->binding_handle;
3151 if (!test_GetUserName(b, tctx)) {
3158 static bool testcase_LookupNames(struct torture_context *tctx,
3159 struct dcerpc_pipe *p)
3162 struct policy_handle *handle;
3163 struct lsa_TransNameArray tnames;
3164 struct lsa_TransNameArray2 tnames2;
3165 struct dcerpc_binding_handle *b = p->binding_handle;
3167 if (!test_OpenPolicy(b, tctx)) {
3171 if (!test_lsa_OpenPolicy2(b, tctx, &handle)) {
3180 tnames.names = talloc_array(tctx, struct lsa_TranslatedName, tnames.count);
3181 ZERO_STRUCT(tnames.names[0]);
3182 tnames.names[0].name.string = "BUILTIN";
3183 tnames.names[0].sid_type = SID_NAME_DOMAIN;
3185 if (!test_LookupNames(b, tctx, handle, &tnames)) {
3190 tnames2.names = talloc_array(tctx, struct lsa_TranslatedName2, tnames2.count);
3191 ZERO_STRUCT(tnames2.names[0]);
3192 tnames2.names[0].name.string = "BUILTIN";
3193 tnames2.names[0].sid_type = SID_NAME_DOMAIN;
3195 if (!test_LookupNames2(b, tctx, handle, &tnames2, true)) {
3199 if (!test_LookupNames3(b, tctx, handle, &tnames2, true)) {
3203 if (!test_LookupNames_wellknown(b, tctx, handle)) {
3207 if (!test_LookupNames_NULL(b, tctx, handle)) {
3211 if (!test_LookupNames_bogus(b, tctx, handle)) {
3215 if (!test_lsa_Close(b, tctx, handle)) {
3222 struct torture_suite *torture_rpc_lsa_lookup_names(TALLOC_CTX *mem_ctx)
3224 struct torture_suite *suite;
3225 struct torture_rpc_tcase *tcase;
3227 suite = torture_suite_create(mem_ctx, "lsa.lookupnames");
3229 tcase = torture_suite_add_rpc_iface_tcase(suite, "lsa",
3231 torture_rpc_tcase_add_test(tcase, "LookupNames",
3232 testcase_LookupNames);
3237 struct lsa_trustdom_state {
3238 uint32_t num_trusts;
3241 static bool testcase_TrustedDomains(struct torture_context *tctx,
3242 struct dcerpc_pipe *p,
3246 struct policy_handle *handle;
3247 struct lsa_trustdom_state *state =
3248 talloc_get_type_abort(data, struct lsa_trustdom_state);
3249 struct dcerpc_binding_handle *b = p->binding_handle;
3251 torture_comment(tctx, "Testing %d domains\n", state->num_trusts);
3253 if (!test_OpenPolicy(b, tctx)) {
3257 if (!test_lsa_OpenPolicy2(b, tctx, &handle)) {
3265 if (!test_CreateTrustedDomain(b, tctx, handle, state->num_trusts)) {
3269 if (!test_CreateTrustedDomainEx(p, tctx, handle, state->num_trusts)) {
3273 if (!test_CreateTrustedDomainEx2(p, tctx, handle, state->num_trusts)) {
3277 if (!test_lsa_Close(b, tctx, handle)) {
3284 struct torture_suite *torture_rpc_lsa_trusted_domains(TALLOC_CTX *mem_ctx)
3286 struct torture_suite *suite;
3287 struct torture_rpc_tcase *tcase;
3288 struct lsa_trustdom_state *state;
3290 state = talloc(mem_ctx, struct lsa_trustdom_state);
3292 state->num_trusts = 12;
3294 suite = torture_suite_create(mem_ctx, "lsa.trusted.domains");
3296 tcase = torture_suite_add_rpc_iface_tcase(suite, "lsa",
3298 torture_rpc_tcase_add_test_ex(tcase, "TrustedDomains",
3299 testcase_TrustedDomains,
3305 static bool testcase_Privileges(struct torture_context *tctx,
3306 struct dcerpc_pipe *p)
3309 struct policy_handle *handle;
3310 struct dcerpc_binding_handle *b = p->binding_handle;
3312 if (!test_OpenPolicy(b, tctx)) {
3316 if (!test_lsa_OpenPolicy2(b, tctx, &handle)) {
3324 if (!test_CreateAccount(b, tctx, handle)) {
3328 if (!test_EnumAccounts(b, tctx, handle)) {
3332 if (!test_EnumPrivs(b, tctx, handle)) {
3336 if (!test_lsa_Close(b, tctx, handle)) {
3344 struct torture_suite *torture_rpc_lsa_privileges(TALLOC_CTX *mem_ctx)
3346 struct torture_suite *suite;
3347 struct torture_rpc_tcase *tcase;
3349 suite = torture_suite_create(mem_ctx, "lsa.privileges");
3351 tcase = torture_suite_add_rpc_iface_tcase(suite, "lsa",
3353 torture_rpc_tcase_add_test(tcase, "Privileges",
3354 testcase_Privileges);