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,
44 bool test_fail) /* check if the tests fails! */
46 struct lsa_ObjectAttribute attr;
47 struct policy_handle handle;
48 struct lsa_QosInfo qos;
49 struct lsa_OpenPolicy r;
50 uint16_t system_name = '\\';
52 torture_comment(tctx, "\nTesting OpenPolicy\n");
55 qos.impersonation_level = 2;
57 qos.effective_only = 0;
61 attr.object_name = NULL;
66 r.in.system_name = &system_name;
68 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
69 r.out.handle = &handle;
71 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenPolicy_r(b, tctx, &r),
73 if (!NT_STATUS_IS_OK(r.out.result)) {
74 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_ACCESS_DENIED) ||
75 NT_STATUS_EQUAL(r.out.result, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
77 torture_comment(tctx, "not considering %s to be an error\n",
78 nt_errstr(r.out.result));
82 torture_comment(tctx, "OpenPolicy failed - %s\n",
83 nt_errstr(r.out.result));
91 bool test_lsa_OpenPolicy2_ex(struct dcerpc_binding_handle *b,
92 struct torture_context *tctx,
93 struct policy_handle **handle,
94 NTSTATUS expected_status,
97 struct lsa_ObjectAttribute attr;
98 struct lsa_QosInfo qos;
99 struct lsa_OpenPolicy2 r;
102 torture_comment(tctx, "\nTesting OpenPolicy2\n");
104 *handle = talloc(tctx, struct policy_handle);
110 qos.impersonation_level = 2;
111 qos.context_mode = 1;
112 qos.effective_only = 0;
115 attr.root_dir = NULL;
116 attr.object_name = NULL;
118 attr.sec_desc = NULL;
121 r.in.system_name = "\\";
123 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
124 r.out.handle = *handle;
126 status = dcerpc_lsa_OpenPolicy2_r(b, tctx, &r);
127 torture_assert_ntstatus_equal(tctx, status, expected_status,
128 "OpenPolicy2 failed");
129 if (!NT_STATUS_IS_OK(expected_status)) {
132 if (!NT_STATUS_IS_OK(r.out.result)) {
133 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_ACCESS_DENIED) ||
134 NT_STATUS_EQUAL(r.out.result, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
136 torture_comment(tctx, "not considering %s to be an error\n",
137 nt_errstr(r.out.result));
138 talloc_free(*handle);
143 torture_comment(tctx, "OpenPolicy2 failed - %s\n",
144 nt_errstr(r.out.result));
152 bool test_lsa_OpenPolicy2(struct dcerpc_binding_handle *b,
153 struct torture_context *tctx,
154 struct policy_handle **handle)
156 return test_lsa_OpenPolicy2_ex(b, tctx, handle, NT_STATUS_OK, false);
159 static bool test_LookupNames(struct dcerpc_binding_handle *b,
160 struct torture_context *tctx,
161 struct policy_handle *handle,
162 struct lsa_TransNameArray *tnames)
164 struct lsa_LookupNames r;
165 struct lsa_TransSidArray sids;
166 struct lsa_RefDomainList *domains = NULL;
167 struct lsa_String *names;
172 torture_comment(tctx, "\nTesting LookupNames with %d names\n", tnames->count);
180 input_idx = talloc_array(tctx, uint32_t, tnames->count);
181 names = talloc_array(tctx, struct lsa_String, tnames->count);
183 for (i=0;i<tnames->count;i++) {
184 if (tnames->names[i].sid_type != SID_NAME_UNKNOWN) {
185 init_lsa_String(&names[r.in.num_names], tnames->names[i].name.string);
186 input_idx[r.in.num_names] = i;
191 r.in.handle = handle;
196 r.out.count = &count;
198 r.out.domains = &domains;
200 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupNames_r(b, tctx, &r),
201 "LookupNames failed");
202 if (NT_STATUS_EQUAL(r.out.result, STATUS_SOME_UNMAPPED) ||
203 NT_STATUS_EQUAL(r.out.result, NT_STATUS_NONE_MAPPED)) {
204 for (i=0;i< r.in.num_names;i++) {
205 if (i < count && sids.sids[i].sid_type == SID_NAME_UNKNOWN) {
206 torture_comment(tctx, "LookupName of %s was unmapped\n",
207 tnames->names[i].name.string);
208 } else if (i >=count) {
209 torture_comment(tctx, "LookupName of %s failed to return a result\n",
210 tnames->names[i].name.string);
213 torture_comment(tctx, "LookupNames failed - %s\n",
214 nt_errstr(r.out.result));
216 } else if (!NT_STATUS_IS_OK(r.out.result)) {
217 torture_comment(tctx, "LookupNames failed - %s\n",
218 nt_errstr(r.out.result));
222 for (i=0;i< r.in.num_names;i++) {
224 if (sids.sids[i].sid_type != tnames->names[input_idx[i]].sid_type) {
225 torture_comment(tctx, "LookupName of %s got unexpected name type: %s\n",
226 tnames->names[input_idx[i]].name.string,
227 sid_type_lookup(sids.sids[i].sid_type));
230 if ((sids.sids[i].sid_type == SID_NAME_DOMAIN) &&
231 (sids.sids[i].rid != (uint32_t)-1)) {
232 torture_comment(tctx, "LookupName of %s got unexpected rid: %d\n",
233 tnames->names[input_idx[i]].name.string, sids.sids[i].rid);
236 } else if (i >=count) {
237 torture_comment(tctx, "LookupName of %s failed to return a result\n",
238 tnames->names[input_idx[i]].name.string);
242 torture_comment(tctx, "\n");
247 static bool test_LookupNames_bogus(struct dcerpc_binding_handle *b,
248 struct torture_context *tctx,
249 struct policy_handle *handle)
251 struct lsa_LookupNames r;
252 struct lsa_TransSidArray sids;
253 struct lsa_RefDomainList *domains = NULL;
254 struct lsa_String names[1];
257 torture_comment(tctx, "\nTesting LookupNames with bogus name\n");
262 init_lsa_String(&names[0], "NT AUTHORITY\\BOGUS");
264 r.in.handle = handle;
270 r.out.count = &count;
272 r.out.domains = &domains;
274 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupNames_r(b, tctx, &r),
275 "LookupNames bogus failed");
276 if (!NT_STATUS_EQUAL(r.out.result, NT_STATUS_NONE_MAPPED)) {
277 torture_comment(tctx, "LookupNames failed - %s\n",
278 nt_errstr(r.out.result));
282 torture_comment(tctx, "\n");
287 static bool test_LookupNames_NULL(struct dcerpc_binding_handle *b,
288 struct torture_context *tctx,
289 struct policy_handle *handle)
291 struct lsa_LookupNames r;
292 struct lsa_TransSidArray sids;
293 struct lsa_RefDomainList *domains = NULL;
294 struct lsa_String names[1];
297 torture_comment(tctx, "\nTesting LookupNames with NULL name\n");
302 names[0].string = NULL;
304 r.in.handle = handle;
310 r.out.count = &count;
312 r.out.domains = &domains;
314 /* nt4 returns NT_STATUS_NONE_MAPPED with sid_type
315 * SID_NAME_UNKNOWN, rid 0, and sid_index -1;
317 * w2k3/w2k8 return NT_STATUS_OK with sid_type
318 * SID_NAME_DOMAIN, rid -1 and sid_index 0 and BUILTIN domain
321 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupNames_r(b, tctx, &r),
322 "LookupNames with NULL name failed");
323 torture_assert_ntstatus_ok(tctx, r.out.result,
324 "LookupNames with NULL name failed");
326 torture_comment(tctx, "\n");
331 static bool test_LookupNames_wellknown(struct dcerpc_binding_handle *b,
332 struct torture_context *tctx,
333 struct policy_handle *handle)
335 struct lsa_TranslatedName name;
336 struct lsa_TransNameArray tnames;
339 torture_comment(tctx, "Testing LookupNames with well known names\n");
341 tnames.names = &name;
343 name.name.string = "NT AUTHORITY\\SYSTEM";
344 name.sid_type = SID_NAME_WKN_GRP;
345 ret &= test_LookupNames(b, tctx, handle, &tnames);
347 name.name.string = "NT AUTHORITY\\ANONYMOUS LOGON";
348 name.sid_type = SID_NAME_WKN_GRP;
349 ret &= test_LookupNames(b, tctx, handle, &tnames);
351 name.name.string = "NT AUTHORITY\\Authenticated Users";
352 name.sid_type = SID_NAME_WKN_GRP;
353 ret &= test_LookupNames(b, tctx, handle, &tnames);
356 name.name.string = "NT AUTHORITY";
357 ret &= test_LookupNames(b, tctx, handle, &tnames);
359 name.name.string = "NT AUTHORITY\\";
360 ret &= test_LookupNames(b, tctx, handle, &tnames);
363 name.name.string = "BUILTIN\\";
364 name.sid_type = SID_NAME_DOMAIN;
365 ret &= test_LookupNames(b, tctx, handle, &tnames);
367 name.name.string = "BUILTIN\\Administrators";
368 name.sid_type = SID_NAME_ALIAS;
369 ret &= test_LookupNames(b, tctx, handle, &tnames);
371 name.name.string = "SYSTEM";
372 name.sid_type = SID_NAME_WKN_GRP;
373 ret &= test_LookupNames(b, tctx, handle, &tnames);
375 name.name.string = "Everyone";
376 name.sid_type = SID_NAME_WKN_GRP;
377 ret &= test_LookupNames(b, tctx, handle, &tnames);
381 static bool test_LookupNames2(struct dcerpc_binding_handle *b,
382 struct torture_context *tctx,
383 struct policy_handle *handle,
384 struct lsa_TransNameArray2 *tnames,
387 struct lsa_LookupNames2 r;
388 struct lsa_TransSidArray2 sids;
389 struct lsa_RefDomainList *domains = NULL;
390 struct lsa_String *names;
395 torture_comment(tctx, "\nTesting LookupNames2 with %d names\n", tnames->count);
402 input_idx = talloc_array(tctx, uint32_t, tnames->count);
403 names = talloc_array(tctx, struct lsa_String, tnames->count);
405 for (i=0;i<tnames->count;i++) {
406 if (tnames->names[i].sid_type != SID_NAME_UNKNOWN) {
407 init_lsa_String(&names[r.in.num_names], tnames->names[i].name.string);
408 input_idx[r.in.num_names] = i;
413 r.in.handle = handle;
418 r.in.lookup_options = 0;
419 r.in.client_revision = 0;
420 r.out.count = &count;
422 r.out.domains = &domains;
424 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupNames2_r(b, tctx, &r),
425 "LookupNames2 failed");
426 if (!NT_STATUS_IS_OK(r.out.result)) {
427 torture_comment(tctx, "LookupNames2 failed - %s\n",
428 nt_errstr(r.out.result));
433 torture_assert_int_equal(tctx, count, sids.count,
434 "unexpected number of results returned");
435 if (sids.count > 0) {
436 torture_assert(tctx, sids.sids, "invalid sid buffer");
440 torture_comment(tctx, "\n");
446 static bool test_LookupNames3(struct dcerpc_binding_handle *b,
447 struct torture_context *tctx,
448 struct policy_handle *handle,
449 struct lsa_TransNameArray2 *tnames,
452 struct lsa_LookupNames3 r;
453 struct lsa_TransSidArray3 sids;
454 struct lsa_RefDomainList *domains = NULL;
455 struct lsa_String *names;
460 torture_comment(tctx, "\nTesting LookupNames3 with %d names\n", tnames->count);
467 input_idx = talloc_array(tctx, uint32_t, tnames->count);
468 names = talloc_array(tctx, struct lsa_String, tnames->count);
469 for (i=0;i<tnames->count;i++) {
470 if (tnames->names[i].sid_type != SID_NAME_UNKNOWN) {
471 init_lsa_String(&names[r.in.num_names], tnames->names[i].name.string);
472 input_idx[r.in.num_names] = i;
477 r.in.handle = handle;
482 r.in.lookup_options = 0;
483 r.in.client_revision = 0;
484 r.out.count = &count;
486 r.out.domains = &domains;
488 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupNames3_r(b, tctx, &r),
489 "LookupNames3 failed");
490 if (!NT_STATUS_IS_OK(r.out.result)) {
491 torture_comment(tctx, "LookupNames3 failed - %s\n",
492 nt_errstr(r.out.result));
497 torture_assert_int_equal(tctx, count, sids.count,
498 "unexpected number of results returned");
499 if (sids.count > 0) {
500 torture_assert(tctx, sids.sids, "invalid sid buffer");
504 torture_comment(tctx, "\n");
509 static bool test_LookupNames4(struct dcerpc_binding_handle *b,
510 struct torture_context *tctx,
511 struct lsa_TransNameArray2 *tnames,
513 bool test_fail) /* check if the tests fails! */
515 struct lsa_LookupNames4 r;
516 struct lsa_TransSidArray3 sids;
517 struct lsa_RefDomainList *domains = NULL;
518 struct lsa_String *names;
523 torture_comment(tctx, "\nTesting LookupNames4 with %d names\n", tnames->count);
530 input_idx = talloc_array(tctx, uint32_t, tnames->count);
531 names = talloc_array(tctx, struct lsa_String, tnames->count);
532 for (i=0;i<tnames->count;i++) {
533 if (tnames->names[i].sid_type != SID_NAME_UNKNOWN) {
534 init_lsa_String(&names[r.in.num_names], tnames->names[i].name.string);
535 input_idx[r.in.num_names] = i;
540 r.in.num_names = tnames->count;
545 r.in.lookup_options = 0;
546 r.in.client_revision = 0;
547 r.out.count = &count;
549 r.out.domains = &domains;
551 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupNames4_r(b, tctx, &r),
552 "LookupNames4 failed");
553 if (!NT_STATUS_IS_OK(r.out.result)) {
554 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_ACCESS_DENIED) ||
555 NT_STATUS_EQUAL(r.out.result, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
557 torture_comment(tctx, "not considering %s to be an error\n",
558 nt_errstr(r.out.result));
562 torture_comment(tctx, "LookupNames4 failed - %s\n",
563 nt_errstr(r.out.result));
568 torture_assert_int_equal(tctx, count, sids.count,
569 "unexpected number of results returned");
570 if (sids.count > 0) {
571 torture_assert(tctx, sids.sids, "invalid sid buffer");
575 torture_comment(tctx, "\n");
581 static bool test_LookupSids(struct dcerpc_binding_handle *b,
582 struct torture_context *tctx,
583 struct policy_handle *handle,
584 struct lsa_SidArray *sids)
586 struct lsa_LookupSids r;
587 struct lsa_TransNameArray names;
588 struct lsa_RefDomainList *domains = NULL;
589 uint32_t count = sids->num_sids;
591 torture_comment(tctx, "\nTesting LookupSids\n");
596 r.in.handle = handle;
601 r.out.count = &count;
602 r.out.names = &names;
603 r.out.domains = &domains;
605 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupSids_r(b, tctx, &r),
606 "LookupSids failed");
607 if (!NT_STATUS_IS_OK(r.out.result) &&
608 !NT_STATUS_EQUAL(r.out.result, STATUS_SOME_UNMAPPED)) {
609 torture_comment(tctx, "LookupSids failed - %s\n",
610 nt_errstr(r.out.result));
614 torture_comment(tctx, "\n");
616 if (!test_LookupNames(b, tctx, handle, &names)) {
624 static bool test_LookupSids2(struct dcerpc_binding_handle *b,
625 struct torture_context *tctx,
626 struct policy_handle *handle,
627 struct lsa_SidArray *sids)
629 struct lsa_LookupSids2 r;
630 struct lsa_TransNameArray2 names;
631 struct lsa_RefDomainList *domains = NULL;
632 uint32_t count = sids->num_sids;
634 torture_comment(tctx, "\nTesting LookupSids2\n");
639 r.in.handle = handle;
644 r.in.lookup_options = 0;
645 r.in.client_revision = 0;
646 r.out.count = &count;
647 r.out.names = &names;
648 r.out.domains = &domains;
650 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupSids2_r(b, tctx, &r),
651 "LookupSids2 failed");
652 if (!NT_STATUS_IS_OK(r.out.result) &&
653 !NT_STATUS_EQUAL(r.out.result, STATUS_SOME_UNMAPPED)) {
654 torture_comment(tctx, "LookupSids2 failed - %s\n",
655 nt_errstr(r.out.result));
659 torture_comment(tctx, "\n");
661 if (!test_LookupNames2(b, tctx, handle, &names, false)) {
665 if (!test_LookupNames3(b, tctx, handle, &names, false)) {
672 static bool test_LookupSids3(struct dcerpc_binding_handle *b,
673 struct torture_context *tctx,
674 struct lsa_SidArray *sids,
675 bool test_fail) /* check if the tests fails! */
677 struct lsa_LookupSids3 r;
678 struct lsa_TransNameArray2 names;
679 struct lsa_RefDomainList *domains = NULL;
680 uint32_t count = sids->num_sids;
682 torture_comment(tctx, "\nTesting LookupSids3\n");
691 r.in.lookup_options = 0;
692 r.in.client_revision = 0;
693 r.out.domains = &domains;
694 r.out.count = &count;
695 r.out.names = &names;
697 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupSids3_r(b, tctx, &r),
698 "LookupSids3 failed");
699 if (!NT_STATUS_IS_OK(r.out.result)) {
700 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_ACCESS_DENIED) ||
701 NT_STATUS_EQUAL(r.out.result, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
703 torture_comment(tctx, "not considering %s to be an error\n",
704 nt_errstr(r.out.result));
708 torture_comment(tctx, "LookupSids3 failed - %s - not considered an error\n",
709 nt_errstr(r.out.result));
713 torture_comment(tctx, "\n");
718 bool test_many_LookupSids(struct dcerpc_pipe *p,
719 struct torture_context *tctx,
720 struct policy_handle *handle)
723 struct lsa_SidArray sids;
725 struct dcerpc_binding_handle *b = p->binding_handle;
727 torture_comment(tctx, "\nTesting LookupSids with lots of SIDs\n");
731 sids.sids = talloc_array(tctx, struct lsa_SidPtr, sids.num_sids);
733 for (i=0; i<sids.num_sids; i++) {
734 const char *sidstr = "S-1-5-32-545";
735 sids.sids[i].sid = dom_sid_parse_talloc(tctx, sidstr);
738 count = sids.num_sids;
741 struct lsa_LookupSids r;
742 struct lsa_TransNameArray names;
743 struct lsa_RefDomainList *domains = NULL;
747 r.in.handle = handle;
751 r.in.count = &names.count;
752 r.out.count = &count;
753 r.out.names = &names;
754 r.out.domains = &domains;
756 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupSids_r(b, tctx, &r),
757 "LookupSids failed");
758 if (!NT_STATUS_IS_OK(r.out.result)) {
759 torture_comment(tctx, "LookupSids failed - %s\n",
760 nt_errstr(r.out.result));
764 torture_comment(tctx, "\n");
766 if (!test_LookupNames(b, tctx, handle, &names)) {
769 } else if (p->conn->security_state.auth_info->auth_type == DCERPC_AUTH_TYPE_SCHANNEL &&
770 p->conn->security_state.auth_info->auth_level >= DCERPC_AUTH_LEVEL_INTEGRITY) {
772 if (p->binding->transport == NCACN_IP_TCP) {
773 struct lsa_TransNameArray2 names;
775 if (!test_LookupSids3(b, tctx, &sids, false)) {
778 if (!test_LookupNames4(b, tctx, &names, false, false)) {
781 } else if (p->binding->transport == NCACN_NP) {
782 struct lsa_TransNameArray2 names;
784 if (!test_LookupSids3(b, tctx, &sids, true)) {
787 if (!test_LookupNames4(b, tctx, &names, false, true)) {
793 torture_comment(tctx, "\n");
800 static void lookupsids_cb(struct tevent_req *subreq)
802 int *replies = (int *)tevent_req_callback_data_void(subreq);
805 status = dcerpc_lsa_LookupSids_r_recv(subreq, subreq);
807 if (!NT_STATUS_IS_OK(status)) {
808 printf("lookupsids returned %s\n", nt_errstr(status));
817 static bool test_LookupSids_async(struct dcerpc_binding_handle *b,
818 struct torture_context *tctx,
819 struct policy_handle *handle)
821 struct lsa_SidArray sids;
822 struct lsa_SidPtr sidptr;
824 struct lsa_TransNameArray *names;
825 struct lsa_LookupSids *r;
826 struct lsa_RefDomainList *domains = NULL;
827 struct tevent_req **req;
830 const int num_async_requests = 50;
832 count = talloc_array(tctx, uint32_t, num_async_requests);
833 names = talloc_array(tctx, struct lsa_TransNameArray, num_async_requests);
834 r = talloc_array(tctx, struct lsa_LookupSids, num_async_requests);
836 torture_comment(tctx, "\nTesting %d async lookupsids request\n", num_async_requests);
838 req = talloc_array(tctx, struct tevent_req *, num_async_requests);
842 sidptr.sid = dom_sid_parse_talloc(tctx, "S-1-5-32-545");
846 for (i=0; i<num_async_requests; i++) {
849 names[i].names = NULL;
851 r[i].in.handle = handle;
852 r[i].in.sids = &sids;
853 r[i].in.names = &names[i];
855 r[i].in.count = &names[i].count;
856 r[i].out.count = &count[i];
857 r[i].out.names = &names[i];
858 r[i].out.domains = &domains;
860 req[i] = dcerpc_lsa_LookupSids_r_send(tctx, tctx->ev, b, &r[i]);
861 if (req[i] == NULL) {
866 tevent_req_set_callback(req[i], lookupsids_cb, &replies);
869 while (replies >= 0 && replies < num_async_requests) {
870 tevent_loop_once(tctx->ev);
882 static bool test_LookupPrivValue(struct dcerpc_binding_handle *b,
883 struct torture_context *tctx,
884 struct policy_handle *handle,
885 struct lsa_String *name)
887 struct lsa_LookupPrivValue r;
888 struct lsa_LUID luid;
890 r.in.handle = handle;
894 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupPrivValue_r(b, tctx, &r),
895 "LookupPrivValue failed");
896 if (!NT_STATUS_IS_OK(r.out.result)) {
897 torture_comment(tctx, "\nLookupPrivValue failed - %s\n",
898 nt_errstr(r.out.result));
905 static bool test_LookupPrivName(struct dcerpc_binding_handle *b,
906 struct torture_context *tctx,
907 struct policy_handle *handle,
908 struct lsa_LUID *luid)
910 struct lsa_LookupPrivName r;
911 struct lsa_StringLarge *name = NULL;
913 r.in.handle = handle;
917 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupPrivName_r(b, tctx, &r),
918 "LookupPrivName failed");
919 if (!NT_STATUS_IS_OK(r.out.result)) {
920 torture_comment(tctx, "\nLookupPrivName failed - %s\n",
921 nt_errstr(r.out.result));
928 static bool test_RemovePrivilegesFromAccount(struct dcerpc_binding_handle *b,
929 struct torture_context *tctx,
930 struct policy_handle *handle,
931 struct policy_handle *acct_handle,
932 struct lsa_LUID *luid)
934 struct lsa_RemovePrivilegesFromAccount r;
935 struct lsa_PrivilegeSet privs;
938 torture_comment(tctx, "\nTesting RemovePrivilegesFromAccount\n");
940 r.in.handle = acct_handle;
946 privs.set = talloc_array(tctx, struct lsa_LUIDAttribute, 1);
947 privs.set[0].luid = *luid;
948 privs.set[0].attribute = 0;
950 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_RemovePrivilegesFromAccount_r(b, tctx, &r),
951 "RemovePrivilegesFromAccount failed");
952 if (!NT_STATUS_IS_OK(r.out.result)) {
954 struct lsa_LookupPrivName r_name;
955 struct lsa_StringLarge *name = NULL;
957 r_name.in.handle = handle;
958 r_name.in.luid = luid;
959 r_name.out.name = &name;
961 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupPrivName_r(b, tctx, &r_name),
962 "LookupPrivName failed");
963 if (!NT_STATUS_IS_OK(r_name.out.result)) {
964 torture_comment(tctx, "\nLookupPrivName failed - %s\n",
965 nt_errstr(r_name.out.result));
968 /* Windows 2008 does not allow this to be removed */
969 if (strcmp("SeAuditPrivilege", name->string) == 0) {
973 torture_comment(tctx, "RemovePrivilegesFromAccount failed to remove %s - %s\n",
975 nt_errstr(r.out.result));
982 static bool test_AddPrivilegesToAccount(struct dcerpc_binding_handle *b,
983 struct torture_context *tctx,
984 struct policy_handle *acct_handle,
985 struct lsa_LUID *luid)
987 struct lsa_AddPrivilegesToAccount r;
988 struct lsa_PrivilegeSet privs;
991 torture_comment(tctx, "\nTesting AddPrivilegesToAccount\n");
993 r.in.handle = acct_handle;
998 privs.set = talloc_array(tctx, struct lsa_LUIDAttribute, 1);
999 privs.set[0].luid = *luid;
1000 privs.set[0].attribute = 0;
1002 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_AddPrivilegesToAccount_r(b, tctx, &r),
1003 "AddPrivilegesToAccount failed");
1004 if (!NT_STATUS_IS_OK(r.out.result)) {
1005 torture_comment(tctx, "AddPrivilegesToAccount failed - %s\n",
1006 nt_errstr(r.out.result));
1013 static bool test_EnumPrivsAccount(struct dcerpc_binding_handle *b,
1014 struct torture_context *tctx,
1015 struct policy_handle *handle,
1016 struct policy_handle *acct_handle)
1018 struct lsa_EnumPrivsAccount r;
1019 struct lsa_PrivilegeSet *privs = NULL;
1022 torture_comment(tctx, "\nTesting EnumPrivsAccount\n");
1024 r.in.handle = acct_handle;
1025 r.out.privs = &privs;
1027 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumPrivsAccount_r(b, tctx, &r),
1028 "EnumPrivsAccount failed");
1029 if (!NT_STATUS_IS_OK(r.out.result)) {
1030 torture_comment(tctx, "EnumPrivsAccount failed - %s\n",
1031 nt_errstr(r.out.result));
1035 if (privs && privs->count > 0) {
1037 for (i=0;i<privs->count;i++) {
1038 test_LookupPrivName(b, tctx, handle,
1039 &privs->set[i].luid);
1042 ret &= test_RemovePrivilegesFromAccount(b, tctx, handle, acct_handle,
1043 &privs->set[0].luid);
1044 ret &= test_AddPrivilegesToAccount(b, tctx, acct_handle,
1045 &privs->set[0].luid);
1051 static bool test_GetSystemAccessAccount(struct dcerpc_binding_handle *b,
1052 struct torture_context *tctx,
1053 struct policy_handle *handle,
1054 struct policy_handle *acct_handle)
1056 uint32_t access_mask;
1057 struct lsa_GetSystemAccessAccount r;
1059 torture_comment(tctx, "\nTesting GetSystemAccessAccount\n");
1061 r.in.handle = acct_handle;
1062 r.out.access_mask = &access_mask;
1064 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_GetSystemAccessAccount_r(b, tctx, &r),
1065 "GetSystemAccessAccount failed");
1066 if (!NT_STATUS_IS_OK(r.out.result)) {
1067 torture_comment(tctx, "GetSystemAccessAccount failed - %s\n",
1068 nt_errstr(r.out.result));
1072 if (r.out.access_mask != NULL) {
1073 torture_comment(tctx, "Rights:");
1074 if (*(r.out.access_mask) & LSA_POLICY_MODE_INTERACTIVE)
1075 torture_comment(tctx, " LSA_POLICY_MODE_INTERACTIVE");
1076 if (*(r.out.access_mask) & LSA_POLICY_MODE_NETWORK)
1077 torture_comment(tctx, " LSA_POLICY_MODE_NETWORK");
1078 if (*(r.out.access_mask) & LSA_POLICY_MODE_BATCH)
1079 torture_comment(tctx, " LSA_POLICY_MODE_BATCH");
1080 if (*(r.out.access_mask) & LSA_POLICY_MODE_SERVICE)
1081 torture_comment(tctx, " LSA_POLICY_MODE_SERVICE");
1082 if (*(r.out.access_mask) & LSA_POLICY_MODE_PROXY)
1083 torture_comment(tctx, " LSA_POLICY_MODE_PROXY");
1084 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_INTERACTIVE)
1085 torture_comment(tctx, " LSA_POLICY_MODE_DENY_INTERACTIVE");
1086 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_NETWORK)
1087 torture_comment(tctx, " LSA_POLICY_MODE_DENY_NETWORK");
1088 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_BATCH)
1089 torture_comment(tctx, " LSA_POLICY_MODE_DENY_BATCH");
1090 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_SERVICE)
1091 torture_comment(tctx, " LSA_POLICY_MODE_DENY_SERVICE");
1092 if (*(r.out.access_mask) & LSA_POLICY_MODE_REMOTE_INTERACTIVE)
1093 torture_comment(tctx, " LSA_POLICY_MODE_REMOTE_INTERACTIVE");
1094 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_REMOTE_INTERACTIVE)
1095 torture_comment(tctx, " LSA_POLICY_MODE_DENY_REMOTE_INTERACTIVE");
1096 if (*(r.out.access_mask) & LSA_POLICY_MODE_ALL)
1097 torture_comment(tctx, " LSA_POLICY_MODE_ALL");
1098 if (*(r.out.access_mask) & LSA_POLICY_MODE_ALL_NT4)
1099 torture_comment(tctx, " LSA_POLICY_MODE_ALL_NT4");
1100 torture_comment(tctx, "\n");
1106 static bool test_Delete(struct dcerpc_binding_handle *b,
1107 struct torture_context *tctx,
1108 struct policy_handle *handle)
1110 struct lsa_Delete r;
1112 torture_comment(tctx, "\nTesting Delete\n");
1114 r.in.handle = handle;
1115 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_Delete_r(b, tctx, &r),
1117 if (!NT_STATUS_EQUAL(r.out.result, NT_STATUS_NOT_SUPPORTED)) {
1118 torture_comment(tctx, "Delete should have failed NT_STATUS_NOT_SUPPORTED - %s\n", nt_errstr(r.out.result));
1125 static bool test_DeleteObject(struct dcerpc_binding_handle *b,
1126 struct torture_context *tctx,
1127 struct policy_handle *handle)
1129 struct lsa_DeleteObject r;
1131 torture_comment(tctx, "\nTesting DeleteObject\n");
1133 r.in.handle = handle;
1134 r.out.handle = handle;
1135 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_DeleteObject_r(b, tctx, &r),
1136 "DeleteObject failed");
1137 if (!NT_STATUS_IS_OK(r.out.result)) {
1138 torture_comment(tctx, "DeleteObject failed - %s\n",
1139 nt_errstr(r.out.result));
1147 static bool test_CreateAccount(struct dcerpc_binding_handle *b,
1148 struct torture_context *tctx,
1149 struct policy_handle *handle)
1151 struct lsa_CreateAccount r;
1152 struct dom_sid2 *newsid;
1153 struct policy_handle acct_handle;
1155 newsid = dom_sid_parse_talloc(tctx, "S-1-5-12349876-4321-2854");
1157 torture_comment(tctx, "\nTesting CreateAccount\n");
1159 r.in.handle = handle;
1161 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1162 r.out.acct_handle = &acct_handle;
1164 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_CreateAccount_r(b, tctx, &r),
1165 "CreateAccount failed");
1166 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_OBJECT_NAME_COLLISION)) {
1167 struct lsa_OpenAccount r_o;
1168 r_o.in.handle = handle;
1169 r_o.in.sid = newsid;
1170 r_o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1171 r_o.out.acct_handle = &acct_handle;
1173 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenAccount_r(b, tctx, &r_o),
1174 "OpenAccount failed");
1175 if (!NT_STATUS_IS_OK(r_o.out.result)) {
1176 torture_comment(tctx, "OpenAccount failed - %s\n",
1177 nt_errstr(r_o.out.result));
1180 } else if (!NT_STATUS_IS_OK(r.out.result)) {
1181 torture_comment(tctx, "CreateAccount failed - %s\n",
1182 nt_errstr(r.out.result));
1186 if (!test_Delete(b, tctx, &acct_handle)) {
1190 if (!test_DeleteObject(b, tctx, &acct_handle)) {
1197 static bool test_DeleteTrustedDomain(struct dcerpc_binding_handle *b,
1198 struct torture_context *tctx,
1199 struct policy_handle *handle,
1200 struct lsa_StringLarge name)
1202 struct lsa_OpenTrustedDomainByName r;
1203 struct policy_handle trustdom_handle;
1205 r.in.handle = handle;
1206 r.in.name.string = name.string;
1207 r.in.access_mask = SEC_STD_DELETE;
1208 r.out.trustdom_handle = &trustdom_handle;
1210 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenTrustedDomainByName_r(b, tctx, &r),
1211 "OpenTrustedDomainByName failed");
1212 if (!NT_STATUS_IS_OK(r.out.result)) {
1213 torture_comment(tctx, "OpenTrustedDomainByName failed - %s\n", nt_errstr(r.out.result));
1217 if (!test_Delete(b, tctx, &trustdom_handle)) {
1221 if (!test_DeleteObject(b, tctx, &trustdom_handle)) {
1228 static bool test_DeleteTrustedDomainBySid(struct dcerpc_binding_handle *b,
1229 struct torture_context *tctx,
1230 struct policy_handle *handle,
1231 struct dom_sid *sid)
1233 struct lsa_DeleteTrustedDomain r;
1235 r.in.handle = handle;
1238 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_DeleteTrustedDomain_r(b, tctx, &r),
1239 "DeleteTrustedDomain failed");
1240 if (!NT_STATUS_IS_OK(r.out.result)) {
1241 torture_comment(tctx, "DeleteTrustedDomain failed - %s\n", nt_errstr(r.out.result));
1249 static bool test_CreateSecret(struct dcerpc_pipe *p,
1250 struct torture_context *tctx,
1251 struct policy_handle *handle)
1254 struct lsa_CreateSecret r;
1255 struct lsa_OpenSecret r2;
1256 struct lsa_SetSecret r3;
1257 struct lsa_QuerySecret r4;
1258 struct lsa_SetSecret r5;
1259 struct lsa_QuerySecret r6;
1260 struct lsa_SetSecret r7;
1261 struct lsa_QuerySecret r8;
1262 struct policy_handle sec_handle, sec_handle2, sec_handle3;
1263 struct lsa_DeleteObject d_o;
1264 struct lsa_DATA_BUF buf1;
1265 struct lsa_DATA_BUF_PTR bufp1;
1266 struct lsa_DATA_BUF_PTR bufp2;
1269 DATA_BLOB session_key;
1270 NTTIME old_mtime, new_mtime;
1272 const char *secret1 = "abcdef12345699qwerty";
1274 const char *secret3 = "ABCDEF12345699QWERTY";
1276 const char *secret5 = "NEW-SAMBA4-SECRET";
1280 const int LOCAL = 0;
1281 const int GLOBAL = 1;
1282 struct dcerpc_binding_handle *b = p->binding_handle;
1284 secname[LOCAL] = talloc_asprintf(tctx, "torturesecret-%u", (unsigned int)random());
1285 secname[GLOBAL] = talloc_asprintf(tctx, "G$torturesecret-%u", (unsigned int)random());
1287 for (i=0; i< 2; i++) {
1288 torture_comment(tctx, "\nTesting CreateSecret of %s\n", secname[i]);
1290 init_lsa_String(&r.in.name, secname[i]);
1292 r.in.handle = handle;
1293 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1294 r.out.sec_handle = &sec_handle;
1296 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_CreateSecret_r(b, tctx, &r),
1297 "CreateSecret failed");
1298 if (!NT_STATUS_IS_OK(r.out.result)) {
1299 torture_comment(tctx, "CreateSecret failed - %s\n", nt_errstr(r.out.result));
1303 r.in.handle = handle;
1304 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1305 r.out.sec_handle = &sec_handle3;
1307 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_CreateSecret_r(b, tctx, &r),
1308 "CreateSecret failed");
1309 if (!NT_STATUS_EQUAL(r.out.result, NT_STATUS_OBJECT_NAME_COLLISION)) {
1310 torture_comment(tctx, "CreateSecret should have failed OBJECT_NAME_COLLISION - %s\n", nt_errstr(r.out.result));
1314 r2.in.handle = handle;
1315 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1316 r2.in.name = r.in.name;
1317 r2.out.sec_handle = &sec_handle2;
1319 torture_comment(tctx, "Testing OpenSecret\n");
1321 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenSecret_r(b, tctx, &r2),
1322 "OpenSecret failed");
1323 if (!NT_STATUS_IS_OK(r2.out.result)) {
1324 torture_comment(tctx, "OpenSecret failed - %s\n", nt_errstr(r2.out.result));
1328 status = dcerpc_fetch_session_key(p, &session_key);
1329 if (!NT_STATUS_IS_OK(status)) {
1330 torture_comment(tctx, "dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
1334 enc_key = sess_encrypt_string(secret1, &session_key);
1336 r3.in.sec_handle = &sec_handle;
1337 r3.in.new_val = &buf1;
1338 r3.in.old_val = NULL;
1339 r3.in.new_val->data = enc_key.data;
1340 r3.in.new_val->length = enc_key.length;
1341 r3.in.new_val->size = enc_key.length;
1343 torture_comment(tctx, "Testing SetSecret\n");
1345 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_SetSecret_r(b, tctx, &r3),
1346 "SetSecret failed");
1347 if (!NT_STATUS_IS_OK(r3.out.result)) {
1348 torture_comment(tctx, "SetSecret failed - %s\n", nt_errstr(r3.out.result));
1352 r3.in.sec_handle = &sec_handle;
1353 r3.in.new_val = &buf1;
1354 r3.in.old_val = NULL;
1355 r3.in.new_val->data = enc_key.data;
1356 r3.in.new_val->length = enc_key.length;
1357 r3.in.new_val->size = enc_key.length;
1359 /* break the encrypted data */
1362 torture_comment(tctx, "Testing SetSecret with broken key\n");
1364 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_SetSecret_r(b, tctx, &r3),
1365 "SetSecret failed");
1366 if (!NT_STATUS_EQUAL(r3.out.result, NT_STATUS_UNKNOWN_REVISION)) {
1367 torture_comment(tctx, "SetSecret should have failed UNKNOWN_REVISION - %s\n", nt_errstr(r3.out.result));
1371 data_blob_free(&enc_key);
1373 ZERO_STRUCT(new_mtime);
1374 ZERO_STRUCT(old_mtime);
1376 /* fetch the secret back again */
1377 r4.in.sec_handle = &sec_handle;
1378 r4.in.new_val = &bufp1;
1379 r4.in.new_mtime = &new_mtime;
1380 r4.in.old_val = NULL;
1381 r4.in.old_mtime = NULL;
1385 torture_comment(tctx, "Testing QuerySecret\n");
1386 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QuerySecret_r(b, tctx, &r4),
1387 "QuerySecret failed");
1388 if (!NT_STATUS_IS_OK(r4.out.result)) {
1389 torture_comment(tctx, "QuerySecret failed - %s\n", nt_errstr(r4.out.result));
1392 if (r4.out.new_val == NULL || r4.out.new_val->buf == NULL) {
1393 torture_comment(tctx, "No secret buffer returned\n");
1396 blob1.data = r4.out.new_val->buf->data;
1397 blob1.length = r4.out.new_val->buf->size;
1399 secret2 = sess_decrypt_string(tctx,
1400 &blob1, &session_key);
1402 if (strcmp(secret1, secret2) != 0) {
1403 torture_comment(tctx, "Returned secret (r4) '%s' doesn't match '%s'\n",
1410 enc_key = sess_encrypt_string(secret3, &session_key);
1412 r5.in.sec_handle = &sec_handle;
1413 r5.in.new_val = &buf1;
1414 r5.in.old_val = NULL;
1415 r5.in.new_val->data = enc_key.data;
1416 r5.in.new_val->length = enc_key.length;
1417 r5.in.new_val->size = enc_key.length;
1421 torture_comment(tctx, "Testing SetSecret (existing value should move to old)\n");
1423 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_SetSecret_r(b, tctx, &r5),
1424 "SetSecret failed");
1425 if (!NT_STATUS_IS_OK(r5.out.result)) {
1426 torture_comment(tctx, "SetSecret failed - %s\n", nt_errstr(r5.out.result));
1430 data_blob_free(&enc_key);
1432 ZERO_STRUCT(new_mtime);
1433 ZERO_STRUCT(old_mtime);
1435 /* fetch the secret back again */
1436 r6.in.sec_handle = &sec_handle;
1437 r6.in.new_val = &bufp1;
1438 r6.in.new_mtime = &new_mtime;
1439 r6.in.old_val = &bufp2;
1440 r6.in.old_mtime = &old_mtime;
1445 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QuerySecret_r(b, tctx, &r6),
1446 "QuerySecret failed");
1447 if (!NT_STATUS_IS_OK(r6.out.result)) {
1448 torture_comment(tctx, "QuerySecret failed - %s\n", nt_errstr(r6.out.result));
1453 if (r6.out.new_val->buf == NULL || r6.out.old_val->buf == NULL
1454 || r6.out.new_mtime == NULL || r6.out.old_mtime == NULL) {
1455 torture_comment(tctx, "Both secret buffers and both times not returned\n");
1459 blob1.data = r6.out.new_val->buf->data;
1460 blob1.length = r6.out.new_val->buf->size;
1462 secret4 = sess_decrypt_string(tctx,
1463 &blob1, &session_key);
1465 if (strcmp(secret3, secret4) != 0) {
1466 torture_comment(tctx, "Returned NEW secret %s doesn't match %s\n", secret4, secret3);
1470 blob1.data = r6.out.old_val->buf->data;
1471 blob1.length = r6.out.old_val->buf->length;
1473 secret2 = sess_decrypt_string(tctx,
1474 &blob1, &session_key);
1476 if (strcmp(secret1, secret2) != 0) {
1477 torture_comment(tctx, "Returned OLD secret %s doesn't match %s\n", secret2, secret1);
1481 if (*r6.out.new_mtime == *r6.out.old_mtime) {
1482 torture_comment(tctx, "Returned secret (r6-%d) %s must not have same mtime for both secrets: %s != %s\n",
1485 nt_time_string(tctx, *r6.out.old_mtime),
1486 nt_time_string(tctx, *r6.out.new_mtime));
1492 enc_key = sess_encrypt_string(secret5, &session_key);
1494 r7.in.sec_handle = &sec_handle;
1495 r7.in.old_val = &buf1;
1496 r7.in.old_val->data = enc_key.data;
1497 r7.in.old_val->length = enc_key.length;
1498 r7.in.old_val->size = enc_key.length;
1499 r7.in.new_val = NULL;
1501 torture_comment(tctx, "Testing SetSecret of old Secret only\n");
1503 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_SetSecret_r(b, tctx, &r7),
1504 "SetSecret failed");
1505 if (!NT_STATUS_IS_OK(r7.out.result)) {
1506 torture_comment(tctx, "SetSecret failed - %s\n", nt_errstr(r7.out.result));
1510 data_blob_free(&enc_key);
1512 /* fetch the secret back again */
1513 r8.in.sec_handle = &sec_handle;
1514 r8.in.new_val = &bufp1;
1515 r8.in.new_mtime = &new_mtime;
1516 r8.in.old_val = &bufp2;
1517 r8.in.old_mtime = &old_mtime;
1522 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QuerySecret_r(b, tctx, &r8),
1523 "QuerySecret failed");
1524 if (!NT_STATUS_IS_OK(r8.out.result)) {
1525 torture_comment(tctx, "QuerySecret failed - %s\n", nt_errstr(r8.out.result));
1528 if (!r8.out.new_val || !r8.out.old_val) {
1529 torture_comment(tctx, "in/out pointers not returned, despite being set on in for QuerySecret\n");
1531 } else if (r8.out.new_val->buf != NULL) {
1532 torture_comment(tctx, "NEW secret buffer must not be returned after OLD set\n");
1534 } else if (r8.out.old_val->buf == NULL) {
1535 torture_comment(tctx, "OLD secret buffer was not returned after OLD set\n");
1537 } else if (r8.out.new_mtime == NULL || r8.out.old_mtime == NULL) {
1538 torture_comment(tctx, "Both times not returned after OLD set\n");
1541 blob1.data = r8.out.old_val->buf->data;
1542 blob1.length = r8.out.old_val->buf->size;
1544 secret6 = sess_decrypt_string(tctx,
1545 &blob1, &session_key);
1547 if (strcmp(secret5, secret6) != 0) {
1548 torture_comment(tctx, "Returned OLD secret %s doesn't match %s\n", secret5, secret6);
1552 if (*r8.out.new_mtime != *r8.out.old_mtime) {
1553 torture_comment(tctx, "Returned secret (r8) %s did not had same mtime for both secrets: %s != %s\n",
1555 nt_time_string(tctx, *r8.out.old_mtime),
1556 nt_time_string(tctx, *r8.out.new_mtime));
1562 if (!test_Delete(b, tctx, &sec_handle)) {
1566 if (!test_DeleteObject(b, tctx, &sec_handle)) {
1570 d_o.in.handle = &sec_handle2;
1571 d_o.out.handle = &sec_handle2;
1572 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_DeleteObject_r(b, tctx, &d_o),
1573 "DeleteObject failed");
1574 if (!NT_STATUS_EQUAL(d_o.out.result, NT_STATUS_INVALID_HANDLE)) {
1575 torture_comment(tctx, "Second delete expected INVALID_HANDLE - %s\n", nt_errstr(d_o.out.result));
1579 torture_comment(tctx, "Testing OpenSecret of just-deleted secret\n");
1581 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenSecret_r(b, tctx, &r2),
1582 "OpenSecret failed");
1583 if (!NT_STATUS_EQUAL(r2.out.result, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
1584 torture_comment(tctx, "OpenSecret expected OBJECT_NAME_NOT_FOUND - %s\n", nt_errstr(r2.out.result));
1595 static bool test_EnumAccountRights(struct dcerpc_binding_handle *b,
1596 struct torture_context *tctx,
1597 struct policy_handle *acct_handle,
1598 struct dom_sid *sid)
1600 struct lsa_EnumAccountRights r;
1601 struct lsa_RightSet rights;
1603 torture_comment(tctx, "\nTesting EnumAccountRights\n");
1605 r.in.handle = acct_handle;
1607 r.out.rights = &rights;
1609 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumAccountRights_r(b, tctx, &r),
1610 "EnumAccountRights failed");
1611 if (!NT_STATUS_IS_OK(r.out.result)) {
1612 torture_comment(tctx, "EnumAccountRights of %s failed - %s\n",
1613 dom_sid_string(tctx, sid), nt_errstr(r.out.result));
1621 static bool test_QuerySecurity(struct dcerpc_binding_handle *b,
1622 struct torture_context *tctx,
1623 struct policy_handle *handle,
1624 struct policy_handle *acct_handle)
1626 struct lsa_QuerySecurity r;
1627 struct sec_desc_buf *sdbuf = NULL;
1629 if (torture_setting_bool(tctx, "samba4", false)) {
1630 torture_comment(tctx, "\nskipping QuerySecurity test against Samba4\n");
1634 torture_comment(tctx, "\nTesting QuerySecurity\n");
1636 r.in.handle = acct_handle;
1637 r.in.sec_info = SECINFO_OWNER |
1640 r.out.sdbuf = &sdbuf;
1642 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QuerySecurity_r(b, tctx, &r),
1643 "QuerySecurity failed");
1644 if (!NT_STATUS_IS_OK(r.out.result)) {
1645 torture_comment(tctx, "QuerySecurity failed - %s\n", nt_errstr(r.out.result));
1652 static bool test_OpenAccount(struct dcerpc_binding_handle *b,
1653 struct torture_context *tctx,
1654 struct policy_handle *handle,
1655 struct dom_sid *sid)
1657 struct lsa_OpenAccount r;
1658 struct policy_handle acct_handle;
1660 torture_comment(tctx, "\nTesting OpenAccount\n");
1662 r.in.handle = handle;
1664 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1665 r.out.acct_handle = &acct_handle;
1667 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenAccount_r(b, tctx, &r),
1668 "OpenAccount failed");
1669 if (!NT_STATUS_IS_OK(r.out.result)) {
1670 torture_comment(tctx, "OpenAccount failed - %s\n", nt_errstr(r.out.result));
1674 if (!test_EnumPrivsAccount(b, tctx, handle, &acct_handle)) {
1678 if (!test_GetSystemAccessAccount(b, tctx, handle, &acct_handle)) {
1682 if (!test_QuerySecurity(b, tctx, handle, &acct_handle)) {
1689 static bool test_EnumAccounts(struct dcerpc_binding_handle *b,
1690 struct torture_context *tctx,
1691 struct policy_handle *handle)
1693 struct lsa_EnumAccounts r;
1694 struct lsa_SidArray sids1, sids2;
1695 uint32_t resume_handle = 0;
1699 torture_comment(tctx, "\nTesting EnumAccounts\n");
1701 r.in.handle = handle;
1702 r.in.resume_handle = &resume_handle;
1703 r.in.num_entries = 100;
1704 r.out.resume_handle = &resume_handle;
1705 r.out.sids = &sids1;
1709 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumAccounts_r(b, tctx, &r),
1710 "EnumAccounts failed");
1711 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_NO_MORE_ENTRIES)) {
1714 if (!NT_STATUS_IS_OK(r.out.result)) {
1715 torture_comment(tctx, "EnumAccounts failed - %s\n", nt_errstr(r.out.result));
1719 if (!test_LookupSids(b, tctx, handle, &sids1)) {
1723 if (!test_LookupSids2(b, tctx, handle, &sids1)) {
1727 /* Can't test lookupSids3 here, as clearly we must not
1728 * be on schannel, or we would not be able to do the
1731 torture_comment(tctx, "Testing all accounts\n");
1732 for (i=0;i<sids1.num_sids;i++) {
1733 ret &= test_OpenAccount(b, tctx, handle, sids1.sids[i].sid);
1734 ret &= test_EnumAccountRights(b, tctx, handle, sids1.sids[i].sid);
1736 torture_comment(tctx, "\n");
1739 if (sids1.num_sids < 3) {
1743 torture_comment(tctx, "Trying EnumAccounts partial listing (asking for 1 at 2)\n");
1745 r.in.num_entries = 1;
1746 r.out.sids = &sids2;
1748 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumAccounts_r(b, tctx, &r),
1749 "EnumAccounts failed");
1750 if (!NT_STATUS_IS_OK(r.out.result)) {
1751 torture_comment(tctx, "EnumAccounts failed - %s\n", nt_errstr(r.out.result));
1755 if (sids2.num_sids != 1) {
1756 torture_comment(tctx, "Returned wrong number of entries (%d)\n", sids2.num_sids);
1763 static bool test_LookupPrivDisplayName(struct dcerpc_binding_handle *b,
1764 struct torture_context *tctx,
1765 struct policy_handle *handle,
1766 struct lsa_String *priv_name)
1768 struct lsa_LookupPrivDisplayName r;
1769 /* produce a reasonable range of language output without screwing up
1771 uint16_t language_id = (random() % 4) + 0x409;
1772 uint16_t returned_language_id = 0;
1773 struct lsa_StringLarge *disp_name = NULL;
1775 torture_comment(tctx, "\nTesting LookupPrivDisplayName(%s)\n", priv_name->string);
1777 r.in.handle = handle;
1778 r.in.name = priv_name;
1779 r.in.language_id = language_id;
1780 r.in.language_id_sys = 0;
1781 r.out.returned_language_id = &returned_language_id;
1782 r.out.disp_name = &disp_name;
1784 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_LookupPrivDisplayName_r(b, tctx, &r),
1785 "LookupPrivDisplayName failed");
1786 if (!NT_STATUS_IS_OK(r.out.result)) {
1787 torture_comment(tctx, "LookupPrivDisplayName failed - %s\n", nt_errstr(r.out.result));
1790 torture_comment(tctx, "%s -> \"%s\" (language 0x%x/0x%x)\n",
1791 priv_name->string, disp_name->string,
1792 r.in.language_id, *r.out.returned_language_id);
1797 static bool test_EnumAccountsWithUserRight(struct dcerpc_binding_handle *b,
1798 struct torture_context *tctx,
1799 struct policy_handle *handle,
1800 struct lsa_String *priv_name)
1802 struct lsa_EnumAccountsWithUserRight r;
1803 struct lsa_SidArray sids;
1807 torture_comment(tctx, "\nTesting EnumAccountsWithUserRight(%s)\n", priv_name->string);
1809 r.in.handle = handle;
1810 r.in.name = priv_name;
1813 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumAccountsWithUserRight_r(b, tctx, &r),
1814 "EnumAccountsWithUserRight failed");
1816 /* NT_STATUS_NO_MORE_ENTRIES means noone has this privilege */
1817 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_NO_MORE_ENTRIES)) {
1821 if (!NT_STATUS_IS_OK(r.out.result)) {
1822 torture_comment(tctx, "EnumAccountsWithUserRight failed - %s\n", nt_errstr(r.out.result));
1830 static bool test_EnumPrivs(struct dcerpc_binding_handle *b,
1831 struct torture_context *tctx,
1832 struct policy_handle *handle)
1834 struct lsa_EnumPrivs r;
1835 struct lsa_PrivArray privs1;
1836 uint32_t resume_handle = 0;
1840 torture_comment(tctx, "\nTesting EnumPrivs\n");
1842 r.in.handle = handle;
1843 r.in.resume_handle = &resume_handle;
1844 r.in.max_count = 100;
1845 r.out.resume_handle = &resume_handle;
1846 r.out.privs = &privs1;
1849 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumPrivs_r(b, tctx, &r),
1850 "EnumPrivs failed");
1851 if (!NT_STATUS_IS_OK(r.out.result)) {
1852 torture_comment(tctx, "EnumPrivs failed - %s\n", nt_errstr(r.out.result));
1856 for (i = 0; i< privs1.count; i++) {
1857 test_LookupPrivDisplayName(b, tctx, handle, (struct lsa_String *)&privs1.privs[i].name);
1858 test_LookupPrivValue(b, tctx, handle, (struct lsa_String *)&privs1.privs[i].name);
1859 if (!test_EnumAccountsWithUserRight(b, tctx, handle, (struct lsa_String *)&privs1.privs[i].name)) {
1867 static bool test_QueryForestTrustInformation(struct dcerpc_binding_handle *b,
1868 struct torture_context *tctx,
1869 struct policy_handle *handle,
1870 const char *trusted_domain_name)
1873 struct lsa_lsaRQueryForestTrustInformation r;
1874 struct lsa_String string;
1875 struct lsa_ForestTrustInformation info, *info_ptr;
1877 torture_comment(tctx, "\nTesting lsaRQueryForestTrustInformation\n");
1879 if (torture_setting_bool(tctx, "samba4", false)) {
1880 torture_comment(tctx, "skipping QueryForestTrustInformation against Samba4\n");
1884 ZERO_STRUCT(string);
1886 if (trusted_domain_name) {
1887 init_lsa_String(&string, trusted_domain_name);
1892 r.in.handle = handle;
1893 r.in.trusted_domain_name = &string;
1895 r.out.forest_trust_info = &info_ptr;
1897 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_lsaRQueryForestTrustInformation_r(b, tctx, &r),
1898 "lsaRQueryForestTrustInformation failed");
1900 if (!NT_STATUS_IS_OK(r.out.result)) {
1901 torture_comment(tctx, "lsaRQueryForestTrustInformation of %s failed - %s\n", trusted_domain_name, nt_errstr(r.out.result));
1908 static bool test_query_each_TrustDomEx(struct dcerpc_binding_handle *b,
1909 struct torture_context *tctx,
1910 struct policy_handle *handle,
1911 struct lsa_DomainListEx *domains)
1916 for (i=0; i< domains->count; i++) {
1918 if (domains->domains[i].trust_attributes & NETR_TRUST_ATTRIBUTE_FOREST_TRANSITIVE) {
1919 ret &= test_QueryForestTrustInformation(b, tctx, handle,
1920 domains->domains[i].domain_name.string);
1927 static bool test_query_each_TrustDom(struct dcerpc_binding_handle *b,
1928 struct torture_context *tctx,
1929 struct policy_handle *handle,
1930 struct lsa_DomainList *domains)
1935 torture_comment(tctx, "\nTesting OpenTrustedDomain, OpenTrustedDomainByName and QueryInfoTrustedDomain\n");
1936 for (i=0; i< domains->count; i++) {
1937 struct lsa_OpenTrustedDomain trust;
1938 struct lsa_OpenTrustedDomainByName trust_by_name;
1939 struct policy_handle trustdom_handle;
1940 struct policy_handle handle2;
1942 struct lsa_CloseTrustedDomainEx c_trust;
1943 int levels [] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
1944 int ok[] = {1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1};
1946 if (domains->domains[i].sid) {
1947 trust.in.handle = handle;
1948 trust.in.sid = domains->domains[i].sid;
1949 trust.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1950 trust.out.trustdom_handle = &trustdom_handle;
1952 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenTrustedDomain_r(b, tctx, &trust),
1953 "OpenTrustedDomain failed");
1955 if (!NT_STATUS_IS_OK(trust.out.result)) {
1956 torture_comment(tctx, "OpenTrustedDomain failed - %s\n", nt_errstr(trust.out.result));
1960 c.in.handle = &trustdom_handle;
1961 c.out.handle = &handle2;
1963 c_trust.in.handle = &trustdom_handle;
1964 c_trust.out.handle = &handle2;
1966 for (j=0; j < ARRAY_SIZE(levels); j++) {
1967 struct lsa_QueryTrustedDomainInfo q;
1968 union lsa_TrustedDomainInfo *info = NULL;
1969 q.in.trustdom_handle = &trustdom_handle;
1970 q.in.level = levels[j];
1972 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryTrustedDomainInfo_r(b, tctx, &q),
1973 "QueryTrustedDomainInfo failed");
1974 if (!NT_STATUS_IS_OK(q.out.result) && ok[j]) {
1975 torture_comment(tctx, "QueryTrustedDomainInfo level %d failed - %s\n",
1976 levels[j], nt_errstr(q.out.result));
1978 } else if (NT_STATUS_IS_OK(q.out.result) && !ok[j]) {
1979 torture_comment(tctx, "QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
1980 levels[j], nt_errstr(q.out.result));
1985 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_CloseTrustedDomainEx_r(b, tctx, &c_trust),
1986 "CloseTrustedDomainEx failed");
1987 if (!NT_STATUS_EQUAL(c_trust.out.result, NT_STATUS_NOT_IMPLEMENTED)) {
1988 torture_comment(tctx, "Expected CloseTrustedDomainEx to return NT_STATUS_NOT_IMPLEMENTED, instead - %s\n", nt_errstr(c_trust.out.result));
1992 c.in.handle = &trustdom_handle;
1993 c.out.handle = &handle2;
1995 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_Close_r(b, tctx, &c),
1997 if (!NT_STATUS_IS_OK(c.out.result)) {
1998 torture_comment(tctx, "Close of trusted domain failed - %s\n", nt_errstr(c.out.result));
2002 for (j=0; j < ARRAY_SIZE(levels); j++) {
2003 struct lsa_QueryTrustedDomainInfoBySid q;
2004 union lsa_TrustedDomainInfo *info = NULL;
2006 if (!domains->domains[i].sid) {
2010 q.in.handle = handle;
2011 q.in.dom_sid = domains->domains[i].sid;
2012 q.in.level = levels[j];
2015 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryTrustedDomainInfoBySid_r(b, tctx, &q),
2016 "lsa_QueryTrustedDomainInfoBySid failed");
2017 if (!NT_STATUS_IS_OK(q.out.result) && ok[j]) {
2018 torture_comment(tctx, "QueryTrustedDomainInfoBySid level %d failed - %s\n",
2019 levels[j], nt_errstr(q.out.result));
2021 } else if (NT_STATUS_IS_OK(q.out.result) && !ok[j]) {
2022 torture_comment(tctx, "QueryTrustedDomainInfoBySid level %d unexpectedly succeeded - %s\n",
2023 levels[j], nt_errstr(q.out.result));
2029 trust_by_name.in.handle = handle;
2030 trust_by_name.in.name.string = domains->domains[i].name.string;
2031 trust_by_name.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2032 trust_by_name.out.trustdom_handle = &trustdom_handle;
2034 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenTrustedDomainByName_r(b, tctx, &trust_by_name),
2035 "OpenTrustedDomainByName failed");
2037 if (!NT_STATUS_IS_OK(trust_by_name.out.result)) {
2038 torture_comment(tctx, "OpenTrustedDomainByName failed - %s\n", nt_errstr(trust_by_name.out.result));
2042 for (j=0; j < ARRAY_SIZE(levels); j++) {
2043 struct lsa_QueryTrustedDomainInfo q;
2044 union lsa_TrustedDomainInfo *info = NULL;
2045 q.in.trustdom_handle = &trustdom_handle;
2046 q.in.level = levels[j];
2048 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryTrustedDomainInfo_r(b, tctx, &q),
2049 "QueryTrustedDomainInfo failed");
2050 if (!NT_STATUS_IS_OK(q.out.result) && ok[j]) {
2051 torture_comment(tctx, "QueryTrustedDomainInfo level %d failed - %s\n",
2052 levels[j], nt_errstr(q.out.result));
2054 } else if (NT_STATUS_IS_OK(q.out.result) && !ok[j]) {
2055 torture_comment(tctx, "QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
2056 levels[j], nt_errstr(q.out.result));
2061 c.in.handle = &trustdom_handle;
2062 c.out.handle = &handle2;
2064 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_Close_r(b, tctx, &c),
2066 if (!NT_STATUS_IS_OK(c.out.result)) {
2067 torture_comment(tctx, "Close of trusted domain failed - %s\n", nt_errstr(c.out.result));
2071 for (j=0; j < ARRAY_SIZE(levels); j++) {
2072 struct lsa_QueryTrustedDomainInfoByName q;
2073 union lsa_TrustedDomainInfo *info = NULL;
2074 struct lsa_String name;
2076 name.string = domains->domains[i].name.string;
2078 q.in.handle = handle;
2079 q.in.trusted_domain = &name;
2080 q.in.level = levels[j];
2082 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryTrustedDomainInfoByName_r(b, tctx, &q),
2083 "QueryTrustedDomainInfoByName failed");
2084 if (!NT_STATUS_IS_OK(q.out.result) && ok[j]) {
2085 torture_comment(tctx, "QueryTrustedDomainInfoByName level %d failed - %s\n",
2086 levels[j], nt_errstr(q.out.result));
2088 } else if (NT_STATUS_IS_OK(q.out.result) && !ok[j]) {
2089 torture_comment(tctx, "QueryTrustedDomainInfoByName level %d unexpectedly succeeded - %s\n",
2090 levels[j], nt_errstr(q.out.result));
2098 static bool test_EnumTrustDom(struct dcerpc_binding_handle *b,
2099 struct torture_context *tctx,
2100 struct policy_handle *handle)
2102 struct lsa_EnumTrustDom r;
2103 uint32_t in_resume_handle = 0;
2104 uint32_t out_resume_handle;
2105 struct lsa_DomainList domains;
2108 torture_comment(tctx, "\nTesting EnumTrustDom\n");
2110 r.in.handle = handle;
2111 r.in.resume_handle = &in_resume_handle;
2113 r.out.domains = &domains;
2114 r.out.resume_handle = &out_resume_handle;
2116 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumTrustDom_r(b, tctx, &r),
2117 "lsa_EnumTrustDom failed");
2119 /* according to MS-LSAD 3.1.4.7.8 output resume handle MUST
2120 * always be larger than the previous input resume handle, in
2121 * particular when hitting the last query it is vital to set the
2122 * resume handle correctly to avoid infinite client loops, as
2123 * seen e.g. with Windows XP SP3 when resume handle is 0 and
2124 * status is NT_STATUS_OK - gd */
2126 if (NT_STATUS_IS_OK(r.out.result) ||
2127 NT_STATUS_EQUAL(r.out.result, NT_STATUS_NO_MORE_ENTRIES) ||
2128 NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES))
2130 if (out_resume_handle <= in_resume_handle) {
2131 torture_comment(tctx, "EnumTrustDom failed - should have returned output resume_handle (0x%08x) larger than input resume handle (0x%08x)\n",
2132 out_resume_handle, in_resume_handle);
2137 if (NT_STATUS_IS_OK(r.out.result)) {
2138 if (domains.count == 0) {
2139 torture_comment(tctx, "EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2142 } else if (!(NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES) || NT_STATUS_EQUAL(r.out.result, NT_STATUS_NO_MORE_ENTRIES))) {
2143 torture_comment(tctx, "EnumTrustDom of zero size failed - %s\n", nt_errstr(r.out.result));
2147 /* Start from the bottom again */
2148 in_resume_handle = 0;
2151 r.in.handle = handle;
2152 r.in.resume_handle = &in_resume_handle;
2153 r.in.max_size = LSA_ENUM_TRUST_DOMAIN_MULTIPLIER * 3;
2154 r.out.domains = &domains;
2155 r.out.resume_handle = &out_resume_handle;
2157 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumTrustDom_r(b, tctx, &r),
2158 "EnumTrustDom failed");
2160 /* according to MS-LSAD 3.1.4.7.8 output resume handle MUST
2161 * always be larger than the previous input resume handle, in
2162 * particular when hitting the last query it is vital to set the
2163 * resume handle correctly to avoid infinite client loops, as
2164 * seen e.g. with Windows XP SP3 when resume handle is 0 and
2165 * status is NT_STATUS_OK - gd */
2167 if (NT_STATUS_IS_OK(r.out.result) ||
2168 NT_STATUS_EQUAL(r.out.result, NT_STATUS_NO_MORE_ENTRIES) ||
2169 NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES))
2171 if (out_resume_handle <= in_resume_handle) {
2172 torture_comment(tctx, "EnumTrustDom failed - should have returned output resume_handle (0x%08x) larger than input resume handle (0x%08x)\n",
2173 out_resume_handle, in_resume_handle);
2178 /* NO_MORE_ENTRIES is allowed */
2179 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_NO_MORE_ENTRIES)) {
2180 if (domains.count == 0) {
2183 torture_comment(tctx, "EnumTrustDom failed - should have returned 0 trusted domains with 'NT_STATUS_NO_MORE_ENTRIES'\n");
2185 } else if (NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES)) {
2186 /* Windows 2003 gets this off by one on the first run */
2187 if (r.out.domains->count < 3 || r.out.domains->count > 4) {
2188 torture_comment(tctx, "EnumTrustDom didn't fill the buffer we "
2189 "asked it to (got %d, expected %d / %d == %d entries)\n",
2190 r.out.domains->count, LSA_ENUM_TRUST_DOMAIN_MULTIPLIER * 3,
2191 LSA_ENUM_TRUST_DOMAIN_MULTIPLIER, r.in.max_size);
2194 } else if (!NT_STATUS_IS_OK(r.out.result)) {
2195 torture_comment(tctx, "EnumTrustDom failed - %s\n", nt_errstr(r.out.result));
2199 if (domains.count == 0) {
2200 torture_comment(tctx, "EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2204 ret &= test_query_each_TrustDom(b, tctx, handle, &domains);
2206 in_resume_handle = out_resume_handle;
2208 } while ((NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES)));
2213 static bool test_EnumTrustDomEx(struct dcerpc_binding_handle *b,
2214 struct torture_context *tctx,
2215 struct policy_handle *handle)
2217 struct lsa_EnumTrustedDomainsEx r_ex;
2218 uint32_t resume_handle = 0;
2219 struct lsa_DomainListEx domains_ex;
2222 torture_comment(tctx, "\nTesting EnumTrustedDomainsEx\n");
2224 r_ex.in.handle = handle;
2225 r_ex.in.resume_handle = &resume_handle;
2226 r_ex.in.max_size = LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER * 3;
2227 r_ex.out.domains = &domains_ex;
2228 r_ex.out.resume_handle = &resume_handle;
2230 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumTrustedDomainsEx_r(b, tctx, &r_ex),
2231 "EnumTrustedDomainsEx failed");
2233 if (!(NT_STATUS_EQUAL(r_ex.out.result, STATUS_MORE_ENTRIES) || NT_STATUS_EQUAL(r_ex.out.result, NT_STATUS_NO_MORE_ENTRIES))) {
2234 torture_comment(tctx, "EnumTrustedDomainEx of zero size failed - %s\n", nt_errstr(r_ex.out.result));
2240 r_ex.in.handle = handle;
2241 r_ex.in.resume_handle = &resume_handle;
2242 r_ex.in.max_size = LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER * 3;
2243 r_ex.out.domains = &domains_ex;
2244 r_ex.out.resume_handle = &resume_handle;
2246 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumTrustedDomainsEx_r(b, tctx, &r_ex),
2247 "EnumTrustedDomainsEx failed");
2249 /* NO_MORE_ENTRIES is allowed */
2250 if (NT_STATUS_EQUAL(r_ex.out.result, NT_STATUS_NO_MORE_ENTRIES)) {
2251 if (domains_ex.count == 0) {
2254 torture_comment(tctx, "EnumTrustDomainsEx failed - should have returned 0 trusted domains with 'NT_STATUS_NO_MORE_ENTRIES'\n");
2256 } else if (NT_STATUS_EQUAL(r_ex.out.result, STATUS_MORE_ENTRIES)) {
2257 /* Windows 2003 gets this off by one on the first run */
2258 if (r_ex.out.domains->count < 3 || r_ex.out.domains->count > 4) {
2259 torture_comment(tctx, "EnumTrustDom didn't fill the buffer we "
2260 "asked it to (got %d, expected %d / %d == %d entries)\n",
2261 r_ex.out.domains->count,
2263 LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER,
2264 r_ex.in.max_size / LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER);
2266 } else if (!NT_STATUS_IS_OK(r_ex.out.result)) {
2267 torture_comment(tctx, "EnumTrustedDomainEx failed - %s\n", nt_errstr(r_ex.out.result));
2271 if (domains_ex.count == 0) {
2272 torture_comment(tctx, "EnumTrustDomainEx failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2276 ret &= test_query_each_TrustDomEx(b, tctx, handle, &domains_ex);
2278 } while ((NT_STATUS_EQUAL(r_ex.out.result, STATUS_MORE_ENTRIES)));
2284 static bool test_CreateTrustedDomain(struct dcerpc_binding_handle *b,
2285 struct torture_context *tctx,
2286 struct policy_handle *handle,
2287 uint32_t num_trusts)
2290 struct lsa_CreateTrustedDomain r;
2291 struct lsa_DomainInfo trustinfo;
2292 struct dom_sid **domsid;
2293 struct policy_handle *trustdom_handle;
2294 struct lsa_QueryTrustedDomainInfo q;
2295 union lsa_TrustedDomainInfo *info = NULL;
2298 torture_comment(tctx, "\nTesting CreateTrustedDomain for %d domains\n", num_trusts);
2300 if (!test_EnumTrustDom(b, tctx, handle)) {
2304 if (!test_EnumTrustDomEx(b, tctx, handle)) {
2308 domsid = talloc_array(tctx, struct dom_sid *, num_trusts);
2309 trustdom_handle = talloc_array(tctx, struct policy_handle, num_trusts);
2311 for (i=0; i< num_trusts; i++) {
2312 char *trust_name = talloc_asprintf(tctx, "torturedom%02d", i);
2313 char *trust_sid = talloc_asprintf(tctx, "S-1-5-21-97398-379795-100%02d", i);
2315 domsid[i] = dom_sid_parse_talloc(tctx, trust_sid);
2317 trustinfo.sid = domsid[i];
2318 init_lsa_String((struct lsa_String *)&trustinfo.name, trust_name);
2320 r.in.policy_handle = handle;
2321 r.in.info = &trustinfo;
2322 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2323 r.out.trustdom_handle = &trustdom_handle[i];
2325 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_CreateTrustedDomain_r(b, tctx, &r),
2326 "CreateTrustedDomain failed");
2327 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_OBJECT_NAME_COLLISION)) {
2328 test_DeleteTrustedDomain(b, tctx, handle, trustinfo.name);
2329 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_CreateTrustedDomain_r(b, tctx, &r),
2330 "CreateTrustedDomain failed");
2332 if (!NT_STATUS_IS_OK(r.out.result)) {
2333 torture_comment(tctx, "CreateTrustedDomain failed - %s\n", nt_errstr(r.out.result));
2337 q.in.trustdom_handle = &trustdom_handle[i];
2338 q.in.level = LSA_TRUSTED_DOMAIN_INFO_INFO_EX;
2340 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryTrustedDomainInfo_r(b, tctx, &q),
2341 "QueryTrustedDomainInfo failed");
2342 if (!NT_STATUS_IS_OK(q.out.result)) {
2343 torture_comment(tctx, "QueryTrustedDomainInfo level %d failed - %s\n", q.in.level, nt_errstr(q.out.result));
2345 } else if (!q.out.info) {
2348 if (strcmp(info->info_ex.netbios_name.string, trustinfo.name.string) != 0) {
2349 torture_comment(tctx, "QueryTrustedDomainInfo returned inconsistent short name: %s != %s\n",
2350 info->info_ex.netbios_name.string, trustinfo.name.string);
2353 if (info->info_ex.trust_type != LSA_TRUST_TYPE_DOWNLEVEL) {
2354 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
2355 trust_name, info->info_ex.trust_type, LSA_TRUST_TYPE_DOWNLEVEL);
2358 if (info->info_ex.trust_attributes != 0) {
2359 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
2360 trust_name, info->info_ex.trust_attributes, 0);
2363 if (info->info_ex.trust_direction != LSA_TRUST_DIRECTION_OUTBOUND) {
2364 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
2365 trust_name, info->info_ex.trust_direction, LSA_TRUST_DIRECTION_OUTBOUND);
2372 /* now that we have some domains to look over, we can test the enum calls */
2373 if (!test_EnumTrustDom(b, tctx, handle)) {
2377 if (!test_EnumTrustDomEx(b, tctx, handle)) {
2381 for (i=0; i<num_trusts; i++) {
2382 if (!test_DeleteTrustedDomainBySid(b, tctx, handle, domsid[i])) {
2390 static bool gen_authinfo_internal(TALLOC_CTX *mem_ctx, const char *password,
2391 DATA_BLOB session_key,
2392 struct lsa_TrustDomainInfoAuthInfoInternal **_authinfo_internal)
2394 struct lsa_TrustDomainInfoAuthInfoInternal *authinfo_internal;
2395 struct trustDomainPasswords auth_struct;
2396 struct AuthenticationInformation *auth_info_array;
2397 size_t converted_size;
2398 DATA_BLOB auth_blob;
2399 enum ndr_err_code ndr_err;
2401 authinfo_internal = talloc_zero(mem_ctx, struct lsa_TrustDomainInfoAuthInfoInternal);
2402 if (authinfo_internal == NULL) {
2406 auth_info_array = talloc_array(mem_ctx,
2407 struct AuthenticationInformation, 1);
2408 if (auth_info_array == NULL) {
2412 generate_random_buffer(auth_struct.confounder, sizeof(auth_struct.confounder));
2414 auth_info_array[0].AuthType = TRUST_AUTH_TYPE_CLEAR;
2416 if (!convert_string_talloc(mem_ctx, CH_UNIX, CH_UTF16, password,
2418 &auth_info_array[0].AuthInfo.clear.password,
2423 auth_info_array[0].AuthInfo.clear.size = converted_size;
2425 auth_struct.outgoing.count = 1;
2426 auth_struct.outgoing.current.count = 1;
2427 auth_struct.outgoing.current.array = auth_info_array;
2428 auth_struct.outgoing.previous.count = 0;
2429 auth_struct.outgoing.previous.array = NULL;
2431 auth_struct.incoming.count = 1;
2432 auth_struct.incoming.current.count = 1;
2433 auth_struct.incoming.current.array = auth_info_array;
2434 auth_struct.incoming.previous.count = 0;
2435 auth_struct.incoming.previous.array = NULL;
2438 ndr_err = ndr_push_struct_blob(&auth_blob, mem_ctx, &auth_struct,
2439 (ndr_push_flags_fn_t)ndr_push_trustDomainPasswords);
2440 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2444 arcfour_crypt_blob(auth_blob.data, auth_blob.length, &session_key);
2446 authinfo_internal->auth_blob.size = auth_blob.length;
2447 authinfo_internal->auth_blob.data = auth_blob.data;
2449 *_authinfo_internal = authinfo_internal;
2454 static bool gen_authinfo(TALLOC_CTX *mem_ctx, const char *password,
2455 struct lsa_TrustDomainInfoAuthInfo **_authinfo)
2457 struct lsa_TrustDomainInfoAuthInfo *authinfo;
2458 struct lsa_TrustDomainInfoBuffer *info_buffer;
2459 size_t converted_size;
2461 authinfo = talloc_zero(mem_ctx, struct lsa_TrustDomainInfoAuthInfo);
2462 if (authinfo == NULL) {
2466 info_buffer = talloc_zero(mem_ctx, struct lsa_TrustDomainInfoBuffer);
2467 if (info_buffer == NULL) {
2471 info_buffer->AuthType = TRUST_AUTH_TYPE_CLEAR;
2473 if (!convert_string_talloc(mem_ctx, CH_UNIX, CH_UTF16, password,
2475 &info_buffer->data.data,
2480 info_buffer->data.size = converted_size;
2482 authinfo->incoming_count = 1;
2483 authinfo->incoming_current_auth_info = info_buffer;
2484 authinfo->incoming_previous_auth_info = NULL;
2485 authinfo->outgoing_count = 1;
2486 authinfo->outgoing_current_auth_info = info_buffer;
2487 authinfo->outgoing_previous_auth_info = NULL;
2489 *_authinfo = authinfo;
2494 static bool check_pw_with_ServerAuthenticate3(struct dcerpc_pipe *p,
2495 struct torture_context *tctx,
2496 uint32_t negotiate_flags,
2497 struct cli_credentials *machine_credentials,
2498 struct netlogon_creds_CredentialState **creds_out)
2500 struct netr_ServerReqChallenge r;
2501 struct netr_ServerAuthenticate3 a;
2502 struct netr_Credential credentials1, credentials2, credentials3;
2503 struct netlogon_creds_CredentialState *creds;
2504 struct samr_Password mach_password;
2506 const char *machine_name;
2507 const char *plain_pass;
2508 struct dcerpc_binding_handle *b = p->binding_handle;
2510 machine_name = cli_credentials_get_workstation(machine_credentials);
2511 plain_pass = cli_credentials_get_password(machine_credentials);
2513 r.in.server_name = NULL;
2514 r.in.computer_name = machine_name;
2515 r.in.credentials = &credentials1;
2516 r.out.return_credentials = &credentials2;
2518 generate_random_buffer(credentials1.data, sizeof(credentials1.data));
2520 torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerReqChallenge_r(b, tctx, &r),
2521 "ServerReqChallenge failed");
2522 torture_assert_ntstatus_ok(tctx, r.out.result, "ServerReqChallenge failed");
2524 E_md4hash(plain_pass, mach_password.hash);
2526 a.in.server_name = NULL;
2527 a.in.account_name = talloc_asprintf(tctx, "%s$", machine_name);
2528 a.in.secure_channel_type = cli_credentials_get_secure_channel_type(machine_credentials);
2529 a.in.computer_name = machine_name;
2530 a.in.negotiate_flags = &negotiate_flags;
2531 a.in.credentials = &credentials3;
2532 a.out.return_credentials = &credentials3;
2533 a.out.negotiate_flags = &negotiate_flags;
2536 creds = netlogon_creds_client_init(tctx, a.in.account_name,
2538 &credentials1, &credentials2,
2539 &mach_password, &credentials3,
2542 torture_assert(tctx, creds != NULL, "memory allocation");
2544 torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerAuthenticate3_r(b, tctx, &a),
2545 "ServerAuthenticate3 failed");
2546 if (!NT_STATUS_IS_OK(a.out.result)) {
2547 if (!NT_STATUS_EQUAL(a.out.result, NT_STATUS_ACCESS_DENIED)) {
2548 torture_assert_ntstatus_ok(tctx, a.out.result,
2549 "ServerAuthenticate3 failed");
2553 torture_assert(tctx, netlogon_creds_client_check(creds, &credentials3), "Credential chaining failed");
2555 /* Prove that requesting a challenge again won't break it */
2556 torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerReqChallenge_r(b, tctx, &r),
2557 "ServerReqChallenge failed");
2558 torture_assert_ntstatus_ok(tctx, r.out.result, "ServerReqChallenge failed");
2564 static bool check_dom_trust_pw(struct dcerpc_pipe *p,
2565 struct torture_context *tctx,
2566 const char *trusted_dom_name,
2567 const char *password)
2569 struct cli_credentials *credentials;
2571 struct netlogon_creds_CredentialState *creds;
2572 struct dcerpc_pipe *pipe;
2576 credentials = cli_credentials_init(tctx);
2577 if (credentials == NULL) {
2581 dummy = talloc_asprintf(tctx, "%s$", trusted_dom_name);
2582 if (dummy == NULL) {
2586 cli_credentials_set_username(credentials, dummy, CRED_SPECIFIED);
2587 cli_credentials_set_password(credentials, password, CRED_SPECIFIED);
2588 cli_credentials_set_workstation(credentials,
2589 trusted_dom_name, CRED_SPECIFIED);
2590 cli_credentials_set_secure_channel_type(credentials, SEC_CHAN_DOMAIN);
2592 status = dcerpc_pipe_connect_b(tctx, &pipe, p->binding,
2593 &ndr_table_netlogon,
2594 cli_credentials_init_anon(tctx),
2595 tctx->ev, tctx->lp_ctx);
2596 if (!NT_STATUS_IS_OK(status)) {
2597 torture_comment(tctx, "dcerpc_pipe_connect_b failed.\n");
2601 ok = check_pw_with_ServerAuthenticate3(pipe, tctx,
2602 NETLOGON_NEG_AUTH2_ADS_FLAGS,
2603 credentials, &creds);
2609 static bool test_CreateTrustedDomainEx_common(struct dcerpc_pipe *p,
2610 struct torture_context *tctx,
2611 struct policy_handle *handle,
2612 uint32_t num_trusts,
2617 struct lsa_CreateTrustedDomainEx r;
2618 struct lsa_CreateTrustedDomainEx2 r2;
2619 struct lsa_TrustDomainInfoInfoEx trustinfo;
2620 struct lsa_TrustDomainInfoAuthInfoInternal *authinfo_internal;
2621 struct lsa_TrustDomainInfoAuthInfo *authinfo;
2622 struct dom_sid **domsid;
2623 struct policy_handle *trustdom_handle;
2624 struct lsa_QueryTrustedDomainInfo q;
2625 union lsa_TrustedDomainInfo *info = NULL;
2626 DATA_BLOB session_key;
2628 struct dcerpc_binding_handle *b = p->binding_handle;
2631 torture_comment(tctx, "\nTesting CreateTrustedDomainEx2 for %d domains\n", num_trusts);
2633 torture_comment(tctx, "\nTesting CreateTrustedDomainEx for %d domains\n", num_trusts);
2636 domsid = talloc_array(tctx, struct dom_sid *, num_trusts);
2637 trustdom_handle = talloc_array(tctx, struct policy_handle, num_trusts);
2639 status = dcerpc_fetch_session_key(p, &session_key);
2640 if (!NT_STATUS_IS_OK(status)) {
2641 torture_comment(tctx, "dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
2645 for (i=0; i< num_trusts; i++) {
2646 char *trust_name = talloc_asprintf(tctx, "torturedom%02d", i);
2647 char *trust_name_dns = talloc_asprintf(tctx, "torturedom%02d.samba.example.com", i);
2648 char *trust_sid = talloc_asprintf(tctx, "S-1-5-21-97398-379795-100%02d", i);
2650 domsid[i] = dom_sid_parse_talloc(tctx, trust_sid);
2652 trustinfo.sid = domsid[i];
2653 trustinfo.netbios_name.string = trust_name;
2654 trustinfo.domain_name.string = trust_name_dns;
2656 /* Create inbound, some outbound, and some
2657 * bi-directional trusts in a repeating pattern based
2660 /* 1 == inbound, 2 == outbound, 3 == both */
2661 trustinfo.trust_direction = (i % 3) + 1;
2663 /* Try different trust types too */
2665 /* 1 == downlevel (NT4), 2 == uplevel (ADS), 3 == MIT (kerberos but not AD) */
2666 trustinfo.trust_type = (((i / 3) + 1) % 3) + 1;
2668 trustinfo.trust_attributes = LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION;
2670 if (!gen_authinfo_internal(tctx, TRUSTPW, session_key, &authinfo_internal)) {
2671 torture_comment(tctx, "gen_authinfo_internal failed");
2675 if (!gen_authinfo(tctx, TRUSTPW, &authinfo)) {
2676 torture_comment(tctx, "gen_authinfonfo failed");
2682 r2.in.policy_handle = handle;
2683 r2.in.info = &trustinfo;
2684 r2.in.auth_info_internal = authinfo_internal;
2685 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2686 r2.out.trustdom_handle = &trustdom_handle[i];
2688 torture_assert_ntstatus_ok(tctx,
2689 dcerpc_lsa_CreateTrustedDomainEx2_r(b, tctx, &r2),
2690 "CreateTrustedDomainEx2 failed");
2692 status = r2.out.result;
2695 r.in.policy_handle = handle;
2696 r.in.info = &trustinfo;
2697 r.in.auth_info = authinfo;
2698 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2699 r.out.trustdom_handle = &trustdom_handle[i];
2701 torture_assert_ntstatus_ok(tctx,
2702 dcerpc_lsa_CreateTrustedDomainEx_r(b, tctx, &r),
2703 "CreateTrustedDomainEx failed");
2705 status = r.out.result;
2708 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
2709 test_DeleteTrustedDomain(b, tctx, handle, trustinfo.netbios_name);
2711 torture_assert_ntstatus_ok(tctx,
2712 dcerpc_lsa_CreateTrustedDomainEx2_r(b, tctx, &r2),
2713 "CreateTrustedDomainEx2 failed");
2714 status = r2.out.result;
2716 torture_assert_ntstatus_ok(tctx,
2717 dcerpc_lsa_CreateTrustedDomainEx_r(b, tctx, &r),
2718 "CreateTrustedDomainEx2 failed");
2719 status = r.out.result;
2722 if (!NT_STATUS_IS_OK(status)) {
2723 torture_comment(tctx, "CreateTrustedDomainEx failed2 - %s\n", nt_errstr(status));
2726 /* For outbound and MIT trusts there is no trust account */
2727 if (trustinfo.trust_direction != 2 &&
2728 trustinfo.trust_type != 3) {
2730 if (torture_setting_bool(tctx, "samba3", false) ||
2731 torture_setting_bool(tctx, "samba4", false)) {
2732 torture_comment(tctx, "skipping trusted domain auth tests against samba");
2734 if (check_dom_trust_pw(p, tctx, trust_name,
2736 torture_comment(tctx, "Password check passed unexpectedly\n");
2739 if (!check_dom_trust_pw(p, tctx, trust_name,
2741 torture_comment(tctx, "Password check failed\n");
2747 q.in.trustdom_handle = &trustdom_handle[i];
2748 q.in.level = LSA_TRUSTED_DOMAIN_INFO_INFO_EX;
2750 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryTrustedDomainInfo_r(b, tctx, &q),
2751 "QueryTrustedDomainInfo failed");
2752 if (!NT_STATUS_IS_OK(q.out.result)) {
2753 torture_comment(tctx, "QueryTrustedDomainInfo level 1 failed - %s\n", nt_errstr(q.out.result));
2755 } else if (!q.out.info) {
2756 torture_comment(tctx, "QueryTrustedDomainInfo level 1 failed to return an info pointer\n");
2759 if (strcmp(info->info_ex.netbios_name.string, trustinfo.netbios_name.string) != 0) {
2760 torture_comment(tctx, "QueryTrustedDomainInfo returned inconsistent short name: %s != %s\n",
2761 info->info_ex.netbios_name.string, trustinfo.netbios_name.string);
2764 if (info->info_ex.trust_type != trustinfo.trust_type) {
2765 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
2766 trust_name, info->info_ex.trust_type, trustinfo.trust_type);
2769 if (info->info_ex.trust_attributes != LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION) {
2770 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
2771 trust_name, info->info_ex.trust_attributes, LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION);
2774 if (info->info_ex.trust_direction != trustinfo.trust_direction) {
2775 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
2776 trust_name, info->info_ex.trust_direction, trustinfo.trust_direction);
2783 /* now that we have some domains to look over, we can test the enum calls */
2784 if (!test_EnumTrustDom(b, tctx, handle)) {
2785 torture_comment(tctx, "test_EnumTrustDom failed\n");
2789 if (!test_EnumTrustDomEx(b, tctx, handle)) {
2790 torture_comment(tctx, "test_EnumTrustDomEx failed\n");
2794 for (i=0; i<num_trusts; i++) {
2795 if (!test_DeleteTrustedDomainBySid(b, tctx, handle, domsid[i])) {
2796 torture_comment(tctx, "test_DeleteTrustedDomainBySid failed\n");
2804 static bool test_CreateTrustedDomainEx2(struct dcerpc_pipe *p,
2805 struct torture_context *tctx,
2806 struct policy_handle *handle,
2807 uint32_t num_trusts)
2809 return test_CreateTrustedDomainEx_common(p, tctx, handle, num_trusts, true);
2812 static bool test_CreateTrustedDomainEx(struct dcerpc_pipe *p,
2813 struct torture_context *tctx,
2814 struct policy_handle *handle,
2815 uint32_t num_trusts)
2817 return test_CreateTrustedDomainEx_common(p, tctx, handle, num_trusts, false);
2820 static bool test_QueryDomainInfoPolicy(struct dcerpc_binding_handle *b,
2821 struct torture_context *tctx,
2822 struct policy_handle *handle)
2824 struct lsa_QueryDomainInformationPolicy r;
2825 union lsa_DomainInformationPolicy *info = NULL;
2829 if (torture_setting_bool(tctx, "samba3", false)) {
2830 torture_skip(tctx, "skipping QueryDomainInformationPolicy test\n");
2833 torture_comment(tctx, "\nTesting QueryDomainInformationPolicy\n");
2836 r.in.handle = handle;
2840 torture_comment(tctx, "\nTrying QueryDomainInformationPolicy level %d\n", i);
2842 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryDomainInformationPolicy_r(b, tctx, &r),
2843 "QueryDomainInformationPolicy failed");
2845 /* If the server does not support EFS, then this is the correct return */
2846 if (i == LSA_DOMAIN_INFO_POLICY_EFS && NT_STATUS_EQUAL(r.out.result, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
2848 } else if (!NT_STATUS_IS_OK(r.out.result)) {
2849 torture_comment(tctx, "QueryDomainInformationPolicy failed - %s\n", nt_errstr(r.out.result));
2859 static bool test_QueryInfoPolicyCalls( bool version2,
2860 struct dcerpc_binding_handle *b,
2861 struct torture_context *tctx,
2862 struct policy_handle *handle)
2864 struct lsa_QueryInfoPolicy r;
2865 union lsa_PolicyInformation *info = NULL;
2868 const char *call = talloc_asprintf(tctx, "QueryInfoPolicy%s", version2 ? "2":"");
2870 torture_comment(tctx, "\nTesting %s\n", call);
2872 if (version2 && torture_setting_bool(tctx, "samba3", false)) {
2873 torture_skip(tctx, "skipping QueryInfoPolicy2 tests\n");
2876 for (i=1;i<=14;i++) {
2877 r.in.handle = handle;
2881 torture_comment(tctx, "\nTrying %s level %d\n", call, i);
2884 /* We can perform the cast, because both types are
2885 structurally equal */
2886 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryInfoPolicy2_r(b, tctx,
2887 (struct lsa_QueryInfoPolicy2*) &r),
2888 "QueryInfoPolicy2 failed");
2890 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_QueryInfoPolicy_r(b, tctx, &r),
2891 "QueryInfoPolicy2 failed");
2894 case LSA_POLICY_INFO_MOD:
2895 case LSA_POLICY_INFO_AUDIT_FULL_SET:
2896 case LSA_POLICY_INFO_AUDIT_FULL_QUERY:
2897 if (!NT_STATUS_EQUAL(r.out.result, NT_STATUS_INVALID_PARAMETER)) {
2898 torture_comment(tctx, "Server should have failed level %u: %s\n", i, nt_errstr(r.out.result));
2902 case LSA_POLICY_INFO_DOMAIN:
2903 case LSA_POLICY_INFO_ACCOUNT_DOMAIN:
2904 case LSA_POLICY_INFO_REPLICA:
2905 case LSA_POLICY_INFO_QUOTA:
2906 case LSA_POLICY_INFO_ROLE:
2907 case LSA_POLICY_INFO_AUDIT_LOG:
2908 case LSA_POLICY_INFO_AUDIT_EVENTS:
2909 case LSA_POLICY_INFO_PD:
2910 if (!NT_STATUS_IS_OK(r.out.result)) {
2911 torture_comment(tctx, "%s failed - %s\n", call, nt_errstr(r.out.result));
2915 case LSA_POLICY_INFO_L_ACCOUNT_DOMAIN:
2916 case LSA_POLICY_INFO_DNS_INT:
2917 case LSA_POLICY_INFO_DNS:
2918 if (torture_setting_bool(tctx, "samba3", false)) {
2919 /* Other levels not implemented yet */
2920 if (!NT_STATUS_EQUAL(r.out.result, NT_STATUS_INVALID_INFO_CLASS)) {
2921 torture_comment(tctx, "%s failed - %s\n", call, nt_errstr(r.out.result));
2924 } else if (!NT_STATUS_IS_OK(r.out.result)) {
2925 torture_comment(tctx, "%s failed - %s\n", call, nt_errstr(r.out.result));
2930 if (torture_setting_bool(tctx, "samba4", false)) {
2931 /* Other levels not implemented yet */
2932 if (!NT_STATUS_EQUAL(r.out.result, NT_STATUS_INVALID_INFO_CLASS)) {
2933 torture_comment(tctx, "%s failed - %s\n", call, nt_errstr(r.out.result));
2936 } else if (!NT_STATUS_IS_OK(r.out.result)) {
2937 torture_comment(tctx, "%s failed - %s\n", call, nt_errstr(r.out.result));
2943 if (NT_STATUS_IS_OK(r.out.result) && (i == LSA_POLICY_INFO_DNS
2944 || i == LSA_POLICY_INFO_DNS_INT)) {
2945 /* Let's look up some of these names */
2947 struct lsa_TransNameArray tnames;
2949 tnames.names = talloc_zero_array(tctx, struct lsa_TranslatedName, tnames.count);
2950 tnames.names[0].name.string = info->dns.name.string;
2951 tnames.names[0].sid_type = SID_NAME_DOMAIN;
2952 tnames.names[1].name.string = info->dns.dns_domain.string;
2953 tnames.names[1].sid_type = SID_NAME_DOMAIN;
2954 tnames.names[2].name.string = talloc_asprintf(tctx, "%s\\", info->dns.name.string);
2955 tnames.names[2].sid_type = SID_NAME_DOMAIN;
2956 tnames.names[3].name.string = talloc_asprintf(tctx, "%s\\", info->dns.dns_domain.string);
2957 tnames.names[3].sid_type = SID_NAME_DOMAIN;
2958 tnames.names[4].name.string = talloc_asprintf(tctx, "%s\\guest", info->dns.name.string);
2959 tnames.names[4].sid_type = SID_NAME_USER;
2960 tnames.names[5].name.string = talloc_asprintf(tctx, "%s\\krbtgt", info->dns.name.string);
2961 tnames.names[5].sid_type = SID_NAME_USER;
2962 tnames.names[6].name.string = talloc_asprintf(tctx, "%s\\guest", info->dns.dns_domain.string);
2963 tnames.names[6].sid_type = SID_NAME_USER;
2964 tnames.names[7].name.string = talloc_asprintf(tctx, "%s\\krbtgt", info->dns.dns_domain.string);
2965 tnames.names[7].sid_type = SID_NAME_USER;
2966 tnames.names[8].name.string = talloc_asprintf(tctx, "krbtgt@%s", info->dns.name.string);
2967 tnames.names[8].sid_type = SID_NAME_USER;
2968 tnames.names[9].name.string = talloc_asprintf(tctx, "krbtgt@%s", info->dns.dns_domain.string);
2969 tnames.names[9].sid_type = SID_NAME_USER;
2970 tnames.names[10].name.string = talloc_asprintf(tctx, "%s\\"TEST_MACHINENAME "$", info->dns.name.string);
2971 tnames.names[10].sid_type = SID_NAME_USER;
2972 tnames.names[11].name.string = talloc_asprintf(tctx, "%s\\"TEST_MACHINENAME "$", info->dns.dns_domain.string);
2973 tnames.names[11].sid_type = SID_NAME_USER;
2974 tnames.names[12].name.string = talloc_asprintf(tctx, TEST_MACHINENAME "$@%s", info->dns.name.string);
2975 tnames.names[12].sid_type = SID_NAME_USER;
2976 tnames.names[13].name.string = talloc_asprintf(tctx, TEST_MACHINENAME "$@%s", info->dns.dns_domain.string);
2977 tnames.names[13].sid_type = SID_NAME_USER;
2978 ret &= test_LookupNames(b, tctx, handle, &tnames);
2986 static bool test_QueryInfoPolicy(struct dcerpc_binding_handle *b,
2987 struct torture_context *tctx,
2988 struct policy_handle *handle)
2990 return test_QueryInfoPolicyCalls(false, b, tctx, handle);
2993 static bool test_QueryInfoPolicy2(struct dcerpc_binding_handle *b,
2994 struct torture_context *tctx,
2995 struct policy_handle *handle)
2997 return test_QueryInfoPolicyCalls(true, b, tctx, handle);
3000 static bool test_GetUserName(struct dcerpc_binding_handle *b,
3001 struct torture_context *tctx)
3003 struct lsa_GetUserName r;
3005 struct lsa_String *authority_name_p = NULL;
3006 struct lsa_String *account_name_p = NULL;
3008 torture_comment(tctx, "\nTesting GetUserName\n");
3010 r.in.system_name = "\\";
3011 r.in.account_name = &account_name_p;
3012 r.in.authority_name = NULL;
3013 r.out.account_name = &account_name_p;
3015 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_GetUserName_r(b, tctx, &r),
3016 "GetUserName failed");
3018 if (!NT_STATUS_IS_OK(r.out.result)) {
3019 torture_comment(tctx, "GetUserName failed - %s\n", nt_errstr(r.out.result));
3023 account_name_p = NULL;
3024 r.in.account_name = &account_name_p;
3025 r.in.authority_name = &authority_name_p;
3026 r.out.account_name = &account_name_p;
3028 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_GetUserName_r(b, tctx, &r),
3029 "GetUserName failed");
3031 if (!NT_STATUS_IS_OK(r.out.result)) {
3032 torture_comment(tctx, "GetUserName failed - %s\n", nt_errstr(r.out.result));
3039 bool test_lsa_Close(struct dcerpc_binding_handle *b,
3040 struct torture_context *tctx,
3041 struct policy_handle *handle)
3044 struct policy_handle handle2;
3046 torture_comment(tctx, "\nTesting Close\n");
3048 r.in.handle = handle;
3049 r.out.handle = &handle2;
3051 torture_assert_ntstatus_ok(tctx, dcerpc_lsa_Close_r(b, tctx, &r),
3053 if (!NT_STATUS_IS_OK(r.out.result)) {
3054 torture_comment(tctx, "Close failed - %s\n",
3055 nt_errstr(r.out.result));
3059 torture_assert_ntstatus_equal(tctx, dcerpc_lsa_Close_r(b, tctx, &r),
3060 NT_STATUS_RPC_SS_CONTEXT_MISMATCH, "Close should failed");
3062 torture_comment(tctx, "\n");
3067 bool torture_rpc_lsa(struct torture_context *tctx)
3070 struct dcerpc_pipe *p;
3072 struct policy_handle *handle = NULL;
3073 struct test_join *join = NULL;
3074 struct cli_credentials *machine_creds;
3075 struct dcerpc_binding_handle *b;
3077 status = torture_rpc_connection(tctx, &p, &ndr_table_lsarpc);
3078 if (!NT_STATUS_IS_OK(status)) {
3081 b = p->binding_handle;
3083 /* Test lsaLookupSids3 and lsaLookupNames4 over tcpip */
3084 if (p->binding->transport == NCACN_IP_TCP) {
3085 if (!test_OpenPolicy(b, tctx, true)) {
3089 if (!test_lsa_OpenPolicy2_ex(b, tctx, &handle,
3090 NT_STATUS_OK, true)) {
3094 if (!test_many_LookupSids(p, tctx, handle)) {
3101 if (!test_OpenPolicy(b, tctx, false)) {
3105 if (!test_lsa_OpenPolicy2(b, tctx, &handle)) {
3110 join = torture_join_domain(tctx, TEST_MACHINENAME, ACB_WSTRUST, &machine_creds);
3115 if (!test_LookupSids_async(b, tctx, handle)) {
3119 if (!test_QueryDomainInfoPolicy(b, tctx, handle)) {
3123 if (!test_CreateSecret(p, tctx, handle)) {
3127 if (!test_QueryInfoPolicy(b, tctx, handle)) {
3131 if (!test_QueryInfoPolicy2(b, tctx, handle)) {
3135 if (!test_Delete(b, tctx, handle)) {
3139 if (!test_many_LookupSids(p, tctx, handle)) {
3143 if (!test_lsa_Close(b, tctx, handle)) {
3147 torture_leave_domain(tctx, join);
3150 if (!test_many_LookupSids(p, tctx, handle)) {
3155 if (!test_GetUserName(b, tctx)) {
3162 bool torture_rpc_lsa_get_user(struct torture_context *tctx)
3165 struct dcerpc_pipe *p;
3167 struct dcerpc_binding_handle *b;
3169 status = torture_rpc_connection(tctx, &p, &ndr_table_lsarpc);
3170 if (!NT_STATUS_IS_OK(status)) {
3173 b = p->binding_handle;
3175 if (!test_GetUserName(b, tctx)) {
3182 static bool testcase_LookupNames(struct torture_context *tctx,
3183 struct dcerpc_pipe *p)
3186 struct policy_handle *handle;
3187 struct lsa_TransNameArray tnames;
3188 struct lsa_TransNameArray2 tnames2;
3189 struct dcerpc_binding_handle *b = p->binding_handle;
3191 if (p->binding->transport != NCACN_NP &&
3192 p->binding->transport != NCALRPC) {
3193 torture_comment(tctx, "testcase_LookupNames is only available "
3194 "over NCACN_NP or NCALRPC");
3198 if (!test_OpenPolicy(b, tctx, false)) {
3202 if (!test_lsa_OpenPolicy2(b, tctx, &handle)) {
3211 tnames.names = talloc_array(tctx, struct lsa_TranslatedName, tnames.count);
3212 ZERO_STRUCT(tnames.names[0]);
3213 tnames.names[0].name.string = "BUILTIN";
3214 tnames.names[0].sid_type = SID_NAME_DOMAIN;
3216 if (!test_LookupNames(b, tctx, handle, &tnames)) {
3221 tnames2.names = talloc_array(tctx, struct lsa_TranslatedName2, tnames2.count);
3222 ZERO_STRUCT(tnames2.names[0]);
3223 tnames2.names[0].name.string = "BUILTIN";
3224 tnames2.names[0].sid_type = SID_NAME_DOMAIN;
3226 if (!test_LookupNames2(b, tctx, handle, &tnames2, true)) {
3230 if (!test_LookupNames3(b, tctx, handle, &tnames2, true)) {
3234 if (!test_LookupNames_wellknown(b, tctx, handle)) {
3238 if (!test_LookupNames_NULL(b, tctx, handle)) {
3242 if (!test_LookupNames_bogus(b, tctx, handle)) {
3246 if (!test_lsa_Close(b, tctx, handle)) {
3253 struct torture_suite *torture_rpc_lsa_lookup_names(TALLOC_CTX *mem_ctx)
3255 struct torture_suite *suite;
3256 struct torture_rpc_tcase *tcase;
3258 suite = torture_suite_create(mem_ctx, "lsa.lookupnames");
3260 tcase = torture_suite_add_rpc_iface_tcase(suite, "lsa",
3262 torture_rpc_tcase_add_test(tcase, "LookupNames",
3263 testcase_LookupNames);
3268 struct lsa_trustdom_state {
3269 uint32_t num_trusts;
3272 static bool testcase_TrustedDomains(struct torture_context *tctx,
3273 struct dcerpc_pipe *p,
3277 struct policy_handle *handle;
3278 struct lsa_trustdom_state *state =
3279 talloc_get_type_abort(data, struct lsa_trustdom_state);
3280 struct dcerpc_binding_handle *b = p->binding_handle;
3282 if (p->binding->transport != NCACN_NP &&
3283 p->binding->transport != NCALRPC) {
3284 torture_comment(tctx, "testcase_TrustedDomains is only available "
3285 "over NCACN_NP or NCALRPC");
3289 torture_comment(tctx, "Testing %d domains\n", state->num_trusts);
3291 if (!test_OpenPolicy(b, tctx, false)) {
3295 if (!test_lsa_OpenPolicy2(b, tctx, &handle)) {
3303 if (!test_CreateTrustedDomain(b, tctx, handle, state->num_trusts)) {
3307 if (!test_CreateTrustedDomainEx(p, tctx, handle, state->num_trusts)) {
3311 if (!test_CreateTrustedDomainEx2(p, tctx, handle, state->num_trusts)) {
3315 if (!test_lsa_Close(b, tctx, handle)) {
3322 struct torture_suite *torture_rpc_lsa_trusted_domains(TALLOC_CTX *mem_ctx)
3324 struct torture_suite *suite;
3325 struct torture_rpc_tcase *tcase;
3326 struct lsa_trustdom_state *state;
3328 state = talloc(mem_ctx, struct lsa_trustdom_state);
3330 state->num_trusts = 12;
3332 suite = torture_suite_create(mem_ctx, "lsa.trusted.domains");
3334 tcase = torture_suite_add_rpc_iface_tcase(suite, "lsa",
3336 torture_rpc_tcase_add_test_ex(tcase, "TrustedDomains",
3337 testcase_TrustedDomains,
3343 static bool testcase_Privileges(struct torture_context *tctx,
3344 struct dcerpc_pipe *p)
3347 struct policy_handle *handle;
3348 struct dcerpc_binding_handle *b = p->binding_handle;
3350 if (p->binding->transport != NCACN_NP &&
3351 p->binding->transport != NCALRPC) {
3352 torture_comment(tctx, "testcase_Privileges is only available "
3353 "over NCACN_NP or NCALRPC");
3357 if (!test_OpenPolicy(b, tctx, false)) {
3361 if (!test_lsa_OpenPolicy2(b, tctx, &handle)) {
3369 if (!test_CreateAccount(b, tctx, handle)) {
3373 if (!test_EnumAccounts(b, tctx, handle)) {
3377 if (!test_EnumPrivs(b, tctx, handle)) {
3381 if (!test_lsa_Close(b, tctx, handle)) {
3389 struct torture_suite *torture_rpc_lsa_privileges(TALLOC_CTX *mem_ctx)
3391 struct torture_suite *suite;
3392 struct torture_rpc_tcase *tcase;
3394 suite = torture_suite_create(mem_ctx, "lsa.privileges");
3396 tcase = torture_suite_add_rpc_iface_tcase(suite, "lsa",
3398 torture_rpc_tcase_add_test(tcase, "Privileges",
3399 testcase_Privileges);