2 Unix SMB/CIFS implementation.
3 test suite for lsa rpc operations
5 Copyright (C) Andrew Tridgell 2003
6 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2004-2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "torture/torture.h"
24 #include "librpc/gen_ndr/ndr_lsa_c.h"
25 #include "librpc/gen_ndr/netlogon.h"
26 #include "librpc/gen_ndr/ndr_drsblobs.h"
27 #include "librpc/gen_ndr/ndr_netlogon_c.h"
28 #include "lib/events/events.h"
29 #include "libcli/security/security.h"
30 #include "libcli/auth/libcli_auth.h"
31 #include "torture/rpc/torture_rpc.h"
32 #include "param/param.h"
33 #include "../lib/crypto/crypto.h"
34 #define TEST_MACHINENAME "lsatestmach"
35 #define TRUSTPW "12345678"
37 static void init_lsa_String(struct lsa_String
*name
, const char *s
)
42 static bool test_OpenPolicy(struct dcerpc_binding_handle
*b
,
43 struct torture_context
*tctx
)
45 struct lsa_ObjectAttribute attr
;
46 struct policy_handle handle
;
47 struct lsa_QosInfo qos
;
48 struct lsa_OpenPolicy r
;
49 uint16_t system_name
= '\\';
51 torture_comment(tctx
, "\nTesting OpenPolicy\n");
54 qos
.impersonation_level
= 2;
56 qos
.effective_only
= 0;
60 attr
.object_name
= NULL
;
65 r
.in
.system_name
= &system_name
;
67 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
68 r
.out
.handle
= &handle
;
70 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenPolicy_r(b
, tctx
, &r
),
73 torture_assert_ntstatus_ok(tctx
,
80 static bool test_OpenPolicy_fail(struct dcerpc_binding_handle
*b
,
81 struct torture_context
*tctx
)
83 struct lsa_ObjectAttribute attr
;
84 struct policy_handle handle
;
85 struct lsa_QosInfo qos
;
86 struct lsa_OpenPolicy r
;
87 uint16_t system_name
= '\\';
90 torture_comment(tctx
, "\nTesting OpenPolicy_fail\n");
93 qos
.impersonation_level
= 2;
95 qos
.effective_only
= 0;
99 attr
.object_name
= NULL
;
101 attr
.sec_desc
= NULL
;
104 r
.in
.system_name
= &system_name
;
106 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
107 r
.out
.handle
= &handle
;
109 status
= dcerpc_lsa_OpenPolicy_r(b
, tctx
, &r
);
110 if (!NT_STATUS_IS_OK(status
)) {
111 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
112 torture_comment(tctx
,
113 "OpenPolicy correctly returned with "
119 torture_assert_ntstatus_equal(tctx
,
121 NT_STATUS_ACCESS_DENIED
,
122 "OpenPolicy return value should "
127 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
128 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_ACCESS_DENIED
) ||
129 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
130 torture_comment(tctx
,
131 "OpenPolicy correctly returned with "
133 nt_errstr(r
.out
.result
));
138 torture_assert_ntstatus_equal(tctx
,
141 "OpenPolicy return value should be "
148 bool test_lsa_OpenPolicy2_ex(struct dcerpc_binding_handle
*b
,
149 struct torture_context
*tctx
,
150 struct policy_handle
**handle
,
151 NTSTATUS expected_status
)
153 struct lsa_ObjectAttribute attr
;
154 struct lsa_QosInfo qos
;
155 struct lsa_OpenPolicy2 r
;
158 torture_comment(tctx
, "\nTesting OpenPolicy2\n");
160 *handle
= talloc(tctx
, struct policy_handle
);
161 torture_assert(tctx
, *handle
!= NULL
, "talloc(tctx, struct policy_handle)");
164 qos
.impersonation_level
= 2;
165 qos
.context_mode
= 1;
166 qos
.effective_only
= 0;
169 attr
.root_dir
= NULL
;
170 attr
.object_name
= NULL
;
172 attr
.sec_desc
= NULL
;
175 r
.in
.system_name
= "\\";
177 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
178 r
.out
.handle
= *handle
;
180 status
= dcerpc_lsa_OpenPolicy2_r(b
, tctx
, &r
);
181 torture_assert_ntstatus_equal(tctx
, status
, expected_status
,
182 "OpenPolicy2 failed");
183 if (!NT_STATUS_IS_OK(expected_status
)) {
187 torture_assert_ntstatus_ok(tctx
,
189 "OpenPolicy2 failed");
195 bool test_lsa_OpenPolicy2(struct dcerpc_binding_handle
*b
,
196 struct torture_context
*tctx
,
197 struct policy_handle
**handle
)
199 return test_lsa_OpenPolicy2_ex(b
, tctx
, handle
, NT_STATUS_OK
);
202 static bool test_OpenPolicy2_fail(struct dcerpc_binding_handle
*b
,
203 struct torture_context
*tctx
)
205 struct lsa_ObjectAttribute attr
;
206 struct policy_handle handle
;
207 struct lsa_QosInfo qos
;
208 struct lsa_OpenPolicy2 r
;
211 torture_comment(tctx
, "\nTesting OpenPolicy2_fail\n");
214 qos
.impersonation_level
= 2;
215 qos
.context_mode
= 1;
216 qos
.effective_only
= 0;
219 attr
.root_dir
= NULL
;
220 attr
.object_name
= NULL
;
222 attr
.sec_desc
= NULL
;
225 r
.in
.system_name
= "\\";
227 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
228 r
.out
.handle
= &handle
;
230 status
= dcerpc_lsa_OpenPolicy2_r(b
, tctx
, &r
);
231 if (!NT_STATUS_IS_OK(status
)) {
232 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
233 torture_comment(tctx
,
234 "OpenPolicy2 correctly returned with "
240 torture_assert_ntstatus_equal(tctx
,
242 NT_STATUS_ACCESS_DENIED
,
243 "OpenPolicy2 return value should "
248 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_ACCESS_DENIED
) ||
249 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
250 torture_comment(tctx
,
251 "OpenPolicy2 correctly returned with "
253 nt_errstr(r
.out
.result
));
258 "OpenPolicy2 return value should be "
259 "ACCESS_DENIED or RPC_PROTSEQ_NOT_SUPPORTED");
264 static bool test_LookupNames(struct dcerpc_binding_handle
*b
,
265 struct torture_context
*tctx
,
266 struct policy_handle
*handle
,
267 struct lsa_TransNameArray
*tnames
)
269 struct lsa_LookupNames r
;
270 struct lsa_TransSidArray sids
;
271 struct lsa_RefDomainList
*domains
= NULL
;
272 struct lsa_String
*names
;
277 torture_comment(tctx
, "\nTesting LookupNames with %d names\n", tnames
->count
);
285 input_idx
= talloc_array(tctx
, uint32_t, tnames
->count
);
286 names
= talloc_array(tctx
, struct lsa_String
, tnames
->count
);
288 for (i
=0;i
<tnames
->count
;i
++) {
289 if (tnames
->names
[i
].sid_type
!= SID_NAME_UNKNOWN
) {
290 init_lsa_String(&names
[r
.in
.num_names
], tnames
->names
[i
].name
.string
);
291 input_idx
[r
.in
.num_names
] = i
;
296 r
.in
.handle
= handle
;
301 r
.out
.count
= &count
;
303 r
.out
.domains
= &domains
;
305 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames_r(b
, tctx
, &r
),
306 "LookupNames failed");
307 if (NT_STATUS_EQUAL(r
.out
.result
, STATUS_SOME_UNMAPPED
) ||
308 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NONE_MAPPED
)) {
309 for (i
=0;i
< r
.in
.num_names
;i
++) {
310 if (i
< count
&& sids
.sids
[i
].sid_type
== SID_NAME_UNKNOWN
) {
311 torture_comment(tctx
, "LookupName of %s was unmapped\n",
312 tnames
->names
[i
].name
.string
);
313 } else if (i
>=count
) {
314 torture_comment(tctx
, "LookupName of %s failed to return a result\n",
315 tnames
->names
[i
].name
.string
);
318 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
319 "LookupNames failed");
320 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
321 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
322 "LookupNames failed");
325 for (i
=0;i
< r
.in
.num_names
;i
++) {
326 torture_assert(tctx
, (i
< count
),
327 talloc_asprintf(tctx
,
328 "LookupName of %s failed to return a result\n",
329 tnames
->names
[input_idx
[i
]].name
.string
));
331 torture_assert_int_equal(tctx
,
332 sids
.sids
[i
].sid_type
,
333 tnames
->names
[input_idx
[i
]].sid_type
,
334 talloc_asprintf(tctx
,
335 "LookupName of %s got unexpected name type: %s\n",
336 tnames
->names
[input_idx
[i
]].name
.string
,
337 sid_type_lookup(sids
.sids
[i
].sid_type
)));
338 if (sids
.sids
[i
].sid_type
!= SID_NAME_DOMAIN
) {
341 torture_assert_int_equal(tctx
,
344 talloc_asprintf(tctx
,
345 "LookupName of %s got unexpected rid: %d\n",
346 tnames
->names
[input_idx
[i
]].name
.string
,
353 static bool test_LookupNames_bogus(struct dcerpc_binding_handle
*b
,
354 struct torture_context
*tctx
,
355 struct policy_handle
*handle
)
357 struct lsa_LookupNames r
;
358 struct lsa_TransSidArray sids
;
359 struct lsa_RefDomainList
*domains
= NULL
;
360 struct lsa_String names
[1];
363 torture_comment(tctx
, "\nTesting LookupNames with bogus name\n");
368 init_lsa_String(&names
[0], "NT AUTHORITY\\BOGUS");
370 r
.in
.handle
= handle
;
376 r
.out
.count
= &count
;
378 r
.out
.domains
= &domains
;
380 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames_r(b
, tctx
, &r
),
381 "LookupNames bogus failed");
382 if (!NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NONE_MAPPED
)) {
383 torture_comment(tctx
, "LookupNames failed - %s\n",
384 nt_errstr(r
.out
.result
));
388 torture_comment(tctx
, "\n");
393 static bool test_LookupNames_NULL(struct dcerpc_binding_handle
*b
,
394 struct torture_context
*tctx
,
395 struct policy_handle
*handle
)
397 struct lsa_LookupNames r
;
398 struct lsa_TransSidArray sids
;
399 struct lsa_RefDomainList
*domains
= NULL
;
400 struct lsa_String names
[1];
403 torture_comment(tctx
, "\nTesting LookupNames with NULL name\n");
408 names
[0].string
= NULL
;
410 r
.in
.handle
= handle
;
416 r
.out
.count
= &count
;
418 r
.out
.domains
= &domains
;
420 /* nt4 returns NT_STATUS_NONE_MAPPED with sid_type
421 * SID_NAME_UNKNOWN, rid 0, and sid_index -1;
423 * w2k3/w2k8 return NT_STATUS_OK with sid_type
424 * SID_NAME_DOMAIN, rid -1 and sid_index 0 and BUILTIN domain
427 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames_r(b
, tctx
, &r
),
428 "LookupNames with NULL name failed");
429 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
430 "LookupNames with NULL name failed");
432 torture_comment(tctx
, "\n");
437 static bool test_LookupNames_wellknown(struct dcerpc_binding_handle
*b
,
438 struct torture_context
*tctx
,
439 struct policy_handle
*handle
)
441 struct lsa_TranslatedName name
;
442 struct lsa_TransNameArray tnames
;
445 torture_comment(tctx
, "Testing LookupNames with well known names\n");
447 tnames
.names
= &name
;
449 name
.name
.string
= "NT AUTHORITY\\SYSTEM";
450 name
.sid_type
= SID_NAME_WKN_GRP
;
451 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
453 name
.name
.string
= "NT AUTHORITY\\ANONYMOUS LOGON";
454 name
.sid_type
= SID_NAME_WKN_GRP
;
455 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
457 name
.name
.string
= "NT AUTHORITY\\Authenticated Users";
458 name
.sid_type
= SID_NAME_WKN_GRP
;
459 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
462 name
.name
.string
= "NT AUTHORITY";
463 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
465 name
.name
.string
= "NT AUTHORITY\\";
466 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
469 name
.name
.string
= "BUILTIN\\";
470 name
.sid_type
= SID_NAME_DOMAIN
;
471 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
473 name
.name
.string
= "BUILTIN\\Administrators";
474 name
.sid_type
= SID_NAME_ALIAS
;
475 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
477 name
.name
.string
= "SYSTEM";
478 name
.sid_type
= SID_NAME_WKN_GRP
;
479 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
481 name
.name
.string
= "Everyone";
482 name
.sid_type
= SID_NAME_WKN_GRP
;
483 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
487 static bool test_LookupNames2(struct dcerpc_binding_handle
*b
,
488 struct torture_context
*tctx
,
489 struct policy_handle
*handle
,
490 struct lsa_TransNameArray2
*tnames
,
493 struct lsa_LookupNames2 r
;
494 struct lsa_TransSidArray2 sids
;
495 struct lsa_RefDomainList
*domains
= NULL
;
496 struct lsa_String
*names
;
501 torture_comment(tctx
, "\nTesting LookupNames2 with %d names\n", tnames
->count
);
508 input_idx
= talloc_array(tctx
, uint32_t, tnames
->count
);
509 names
= talloc_array(tctx
, struct lsa_String
, tnames
->count
);
511 for (i
=0;i
<tnames
->count
;i
++) {
512 if (tnames
->names
[i
].sid_type
!= SID_NAME_UNKNOWN
) {
513 init_lsa_String(&names
[r
.in
.num_names
], tnames
->names
[i
].name
.string
);
514 input_idx
[r
.in
.num_names
] = i
;
519 r
.in
.handle
= handle
;
524 r
.in
.lookup_options
= 0;
525 r
.in
.client_revision
= 0;
526 r
.out
.count
= &count
;
528 r
.out
.domains
= &domains
;
530 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames2_r(b
, tctx
, &r
),
531 "LookupNames2 failed");
532 torture_assert_ntstatus_ok(tctx
, r
.out
.result
, "LookupNames2 failed");
535 torture_assert_int_equal(tctx
, count
, sids
.count
,
536 "unexpected number of results returned");
537 if (sids
.count
> 0) {
538 torture_assert(tctx
, sids
.sids
, "invalid sid buffer");
542 torture_comment(tctx
, "\n");
548 static bool test_LookupNames3(struct dcerpc_binding_handle
*b
,
549 struct torture_context
*tctx
,
550 struct policy_handle
*handle
,
551 struct lsa_TransNameArray2
*tnames
,
554 struct lsa_LookupNames3 r
;
555 struct lsa_TransSidArray3 sids
;
556 struct lsa_RefDomainList
*domains
= NULL
;
557 struct lsa_String
*names
;
562 torture_comment(tctx
, "\nTesting LookupNames3 with %d names\n", tnames
->count
);
569 input_idx
= talloc_array(tctx
, uint32_t, tnames
->count
);
570 names
= talloc_array(tctx
, struct lsa_String
, tnames
->count
);
571 for (i
=0;i
<tnames
->count
;i
++) {
572 if (tnames
->names
[i
].sid_type
!= SID_NAME_UNKNOWN
) {
573 init_lsa_String(&names
[r
.in
.num_names
], tnames
->names
[i
].name
.string
);
574 input_idx
[r
.in
.num_names
] = i
;
579 r
.in
.handle
= handle
;
584 r
.in
.lookup_options
= 0;
585 r
.in
.client_revision
= 0;
586 r
.out
.count
= &count
;
588 r
.out
.domains
= &domains
;
590 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames3_r(b
, tctx
, &r
),
591 "LookupNames3 failed");
592 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
593 "LookupNames3 failed");
596 torture_assert_int_equal(tctx
, count
, sids
.count
,
597 "unexpected number of results returned");
598 if (sids
.count
> 0) {
599 torture_assert(tctx
, sids
.sids
, "invalid sid buffer");
603 torture_comment(tctx
, "\n");
608 static bool test_LookupNames4(struct dcerpc_binding_handle
*b
,
609 struct torture_context
*tctx
,
610 struct lsa_TransNameArray2
*tnames
,
613 struct lsa_LookupNames4 r
;
614 struct lsa_TransSidArray3 sids
;
615 struct lsa_RefDomainList
*domains
= NULL
;
616 struct lsa_String
*names
;
621 torture_comment(tctx
, "\nTesting LookupNames4 with %d names\n", tnames
->count
);
628 input_idx
= talloc_array(tctx
, uint32_t, tnames
->count
);
629 names
= talloc_array(tctx
, struct lsa_String
, tnames
->count
);
630 for (i
=0;i
<tnames
->count
;i
++) {
631 if (tnames
->names
[i
].sid_type
!= SID_NAME_UNKNOWN
) {
632 init_lsa_String(&names
[r
.in
.num_names
], tnames
->names
[i
].name
.string
);
633 input_idx
[r
.in
.num_names
] = i
;
638 r
.in
.num_names
= tnames
->count
;
643 r
.in
.lookup_options
= 0;
644 r
.in
.client_revision
= 0;
645 r
.out
.count
= &count
;
647 r
.out
.domains
= &domains
;
649 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames4_r(b
, tctx
, &r
),
650 "LookupNames4 failed");
652 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
653 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NONE_MAPPED
)) {
654 torture_comment(tctx
,
655 "LookupNames4 failed: %s - not considered as an error",
656 nt_errstr(r
.out
.result
));
661 torture_assert_ntstatus_ok(tctx
,
663 "LookupNames4 failed");
666 torture_assert_int_equal(tctx
, count
, sids
.count
,
667 "unexpected number of results returned");
668 if (sids
.count
> 0) {
669 torture_assert(tctx
, sids
.sids
, "invalid sid buffer");
673 torture_comment(tctx
, "\n");
678 static bool test_LookupNames4_fail(struct dcerpc_binding_handle
*b
,
679 struct torture_context
*tctx
)
681 struct lsa_LookupNames4 r
;
682 struct lsa_TransSidArray3 sids
;
683 struct lsa_RefDomainList
*domains
= NULL
;
684 struct lsa_String
*names
= NULL
;
688 torture_comment(tctx
, "\nTesting LookupNames4_fail");
695 r
.in
.num_names
= count
;
700 r
.in
.lookup_options
= 0;
701 r
.in
.client_revision
= 0;
702 r
.out
.count
= &count
;
704 r
.out
.domains
= &domains
;
706 status
= dcerpc_lsa_LookupNames4_r(b
, tctx
, &r
);
707 if (!NT_STATUS_IS_OK(status
)) {
708 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
709 torture_comment(tctx
,
710 "LookupNames4 correctly returned with "
716 torture_assert_ntstatus_equal(tctx
,
718 NT_STATUS_ACCESS_DENIED
,
719 "LookupNames4 return value should "
724 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
725 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_ACCESS_DENIED
) ||
726 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
727 torture_comment(tctx
,
728 "LookupSids3 correctly returned with "
730 nt_errstr(r
.out
.result
));
736 "LookupNames4 return value should be "
737 "ACCESS_DENIED or RPC_PROTSEQ_NOT_SUPPORTED");
743 static bool test_LookupSids(struct dcerpc_binding_handle
*b
,
744 struct torture_context
*tctx
,
745 struct policy_handle
*handle
,
746 struct lsa_SidArray
*sids
)
748 struct lsa_LookupSids r
;
749 struct lsa_TransNameArray names
;
750 struct lsa_RefDomainList
*domains
= NULL
;
751 uint32_t count
= sids
->num_sids
;
753 torture_comment(tctx
, "\nTesting LookupSids\n");
758 r
.in
.handle
= handle
;
763 r
.out
.count
= &count
;
764 r
.out
.names
= &names
;
765 r
.out
.domains
= &domains
;
767 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupSids_r(b
, tctx
, &r
),
768 "LookupSids failed");
769 if (!NT_STATUS_EQUAL(r
.out
.result
, STATUS_SOME_UNMAPPED
)) {
770 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
771 "LookupSids failed");
774 torture_comment(tctx
, "\n");
776 if (!test_LookupNames(b
, tctx
, handle
, &names
)) {
784 static bool test_LookupSids2(struct dcerpc_binding_handle
*b
,
785 struct torture_context
*tctx
,
786 struct policy_handle
*handle
,
787 struct lsa_SidArray
*sids
)
789 struct lsa_LookupSids2 r
;
790 struct lsa_TransNameArray2 names
;
791 struct lsa_RefDomainList
*domains
= NULL
;
792 uint32_t count
= sids
->num_sids
;
794 torture_comment(tctx
, "\nTesting LookupSids2\n");
799 r
.in
.handle
= handle
;
804 r
.in
.lookup_options
= 0;
805 r
.in
.client_revision
= 0;
806 r
.out
.count
= &count
;
807 r
.out
.names
= &names
;
808 r
.out
.domains
= &domains
;
810 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupSids2_r(b
, tctx
, &r
),
811 "LookupSids2 failed");
812 if (!NT_STATUS_IS_OK(r
.out
.result
) &&
813 !NT_STATUS_EQUAL(r
.out
.result
, STATUS_SOME_UNMAPPED
)) {
814 torture_comment(tctx
, "LookupSids2 failed - %s\n",
815 nt_errstr(r
.out
.result
));
819 torture_comment(tctx
, "\n");
821 if (!test_LookupNames2(b
, tctx
, handle
, &names
, false)) {
825 if (!test_LookupNames3(b
, tctx
, handle
, &names
, false)) {
832 static bool test_LookupSids3(struct dcerpc_binding_handle
*b
,
833 struct torture_context
*tctx
,
834 struct lsa_SidArray
*sids
)
836 struct lsa_LookupSids3 r
;
837 struct lsa_TransNameArray2 names
;
838 struct lsa_RefDomainList
*domains
= NULL
;
839 uint32_t count
= sids
->num_sids
;
841 torture_comment(tctx
, "\nTesting LookupSids3\n");
850 r
.in
.lookup_options
= 0;
851 r
.in
.client_revision
= 0;
852 r
.out
.domains
= &domains
;
853 r
.out
.count
= &count
;
854 r
.out
.names
= &names
;
856 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupSids3_r(b
, tctx
, &r
),
857 "LookupSids3 failed");
859 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
860 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NONE_MAPPED
)) {
861 torture_comment(tctx
,
862 "LookupSids3 failed: %s - not considered as an error",
863 nt_errstr(r
.out
.result
));
868 torture_assert_ntstatus_ok(tctx
,
870 "LookupSids3 failed");
875 torture_comment(tctx
, "\n");
877 if (!test_LookupNames4(b
, tctx
, &names
, true)) {
884 static bool test_LookupSids3_fail(struct dcerpc_binding_handle
*b
,
885 struct torture_context
*tctx
,
886 struct lsa_SidArray
*sids
)
888 struct lsa_LookupSids3 r
;
889 struct lsa_TransNameArray2 names
;
890 struct lsa_RefDomainList
*domains
= NULL
;
891 uint32_t count
= sids
->num_sids
;
894 torture_comment(tctx
, "\nTesting LookupSids3\n");
903 r
.in
.lookup_options
= 0;
904 r
.in
.client_revision
= 0;
905 r
.out
.domains
= &domains
;
906 r
.out
.count
= &count
;
907 r
.out
.names
= &names
;
909 status
= dcerpc_lsa_LookupSids3_r(b
, tctx
, &r
);
910 if (!NT_STATUS_IS_OK(status
)) {
911 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
912 torture_comment(tctx
,
913 "LookupSids3 correctly returned with "
919 torture_assert_ntstatus_equal(tctx
,
921 NT_STATUS_ACCESS_DENIED
,
922 "LookupSids3 return value should "
927 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_ACCESS_DENIED
) ||
928 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
929 torture_comment(tctx
,
930 "LookupNames4 correctly returned with "
932 nt_errstr(r
.out
.result
));
937 "LookupSids3 return value should be "
938 "ACCESS_DENIED or RPC_PROTSEQ_NOT_SUPPORTED");
943 bool test_many_LookupSids(struct dcerpc_pipe
*p
,
944 struct torture_context
*tctx
,
945 struct policy_handle
*handle
)
948 struct lsa_SidArray sids
;
950 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
951 enum dcerpc_transport_t transport
= dcerpc_binding_get_transport(p
->binding
);
953 torture_comment(tctx
, "\nTesting LookupSids with lots of SIDs\n");
957 sids
.sids
= talloc_array(tctx
, struct lsa_SidPtr
, sids
.num_sids
);
959 for (i
=0; i
<sids
.num_sids
; i
++) {
960 const char *sidstr
= "S-1-5-32-545";
961 sids
.sids
[i
].sid
= dom_sid_parse_talloc(tctx
, sidstr
);
964 count
= sids
.num_sids
;
967 struct lsa_LookupSids r
;
968 struct lsa_TransNameArray names
;
969 struct lsa_RefDomainList
*domains
= NULL
;
973 r
.in
.handle
= handle
;
977 r
.in
.count
= &names
.count
;
978 r
.out
.count
= &count
;
979 r
.out
.names
= &names
;
980 r
.out
.domains
= &domains
;
982 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupSids_r(b
, tctx
, &r
),
983 "LookupSids failed");
984 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
985 torture_comment(tctx
, "LookupSids failed - %s\n",
986 nt_errstr(r
.out
.result
));
990 torture_comment(tctx
, "\n");
992 if (!test_LookupNames(b
, tctx
, handle
, &names
)) {
997 if (transport
== NCACN_NP
) {
998 if (!test_LookupSids3_fail(b
, tctx
, &sids
)) {
1001 if (!test_LookupNames4_fail(b
, tctx
)) {
1004 } else if (transport
== NCACN_IP_TCP
) {
1005 struct lsa_TransNameArray2 names
;
1010 if (p
->conn
->security_state
.auth_info
->auth_type
== DCERPC_AUTH_TYPE_SCHANNEL
&&
1011 p
->conn
->security_state
.auth_info
->auth_level
>= DCERPC_AUTH_LEVEL_INTEGRITY
) {
1012 if (!test_LookupSids3(b
, tctx
, &sids
)) {
1015 if (!test_LookupNames4(b
, tctx
, &names
, true)) {
1020 * If we don't have a secure channel these tests must
1021 * fail with ACCESS_DENIED.
1023 if (!test_LookupSids3_fail(b
, tctx
, &sids
)) {
1026 if (!test_LookupNames4_fail(b
, tctx
)) {
1032 torture_comment(tctx
, "\n");
1039 static void lookupsids_cb(struct tevent_req
*subreq
)
1041 int *replies
= (int *)tevent_req_callback_data_void(subreq
);
1044 status
= dcerpc_lsa_LookupSids_r_recv(subreq
, subreq
);
1045 TALLOC_FREE(subreq
);
1046 if (!NT_STATUS_IS_OK(status
)) {
1047 printf("lookupsids returned %s\n", nt_errstr(status
));
1051 if (*replies
>= 0) {
1056 static bool test_LookupSids_async(struct dcerpc_binding_handle
*b
,
1057 struct torture_context
*tctx
,
1058 struct policy_handle
*handle
)
1060 struct lsa_SidArray sids
;
1061 struct lsa_SidPtr sidptr
;
1063 struct lsa_TransNameArray
*names
;
1064 struct lsa_LookupSids
*r
;
1065 struct lsa_RefDomainList
*domains
= NULL
;
1066 struct tevent_req
**req
;
1069 const int num_async_requests
= 50;
1071 count
= talloc_array(tctx
, uint32_t, num_async_requests
);
1072 names
= talloc_array(tctx
, struct lsa_TransNameArray
, num_async_requests
);
1073 r
= talloc_array(tctx
, struct lsa_LookupSids
, num_async_requests
);
1075 torture_comment(tctx
, "\nTesting %d async lookupsids request\n", num_async_requests
);
1077 req
= talloc_array(tctx
, struct tevent_req
*, num_async_requests
);
1080 sids
.sids
= &sidptr
;
1081 sidptr
.sid
= dom_sid_parse_talloc(tctx
, "S-1-5-32-545");
1085 for (i
=0; i
<num_async_requests
; i
++) {
1088 names
[i
].names
= NULL
;
1090 r
[i
].in
.handle
= handle
;
1091 r
[i
].in
.sids
= &sids
;
1092 r
[i
].in
.names
= &names
[i
];
1094 r
[i
].in
.count
= &names
[i
].count
;
1095 r
[i
].out
.count
= &count
[i
];
1096 r
[i
].out
.names
= &names
[i
];
1097 r
[i
].out
.domains
= &domains
;
1099 req
[i
] = dcerpc_lsa_LookupSids_r_send(tctx
, tctx
->ev
, b
, &r
[i
]);
1100 if (req
[i
] == NULL
) {
1105 tevent_req_set_callback(req
[i
], lookupsids_cb
, &replies
);
1108 while (replies
>= 0 && replies
< num_async_requests
) {
1109 tevent_loop_once(tctx
->ev
);
1121 static bool test_LookupPrivValue(struct dcerpc_binding_handle
*b
,
1122 struct torture_context
*tctx
,
1123 struct policy_handle
*handle
,
1124 struct lsa_String
*name
)
1126 struct lsa_LookupPrivValue r
;
1127 struct lsa_LUID luid
;
1129 r
.in
.handle
= handle
;
1133 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupPrivValue_r(b
, tctx
, &r
),
1134 "LookupPrivValue failed");
1135 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
1136 "LookupPrivValue failed");
1141 static bool test_LookupPrivName(struct dcerpc_binding_handle
*b
,
1142 struct torture_context
*tctx
,
1143 struct policy_handle
*handle
,
1144 struct lsa_LUID
*luid
)
1146 struct lsa_LookupPrivName r
;
1147 struct lsa_StringLarge
*name
= NULL
;
1149 r
.in
.handle
= handle
;
1153 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupPrivName_r(b
, tctx
, &r
),
1154 "LookupPrivName failed");
1155 torture_assert_ntstatus_ok(tctx
, r
.out
.result
, "LookupPrivName failed");
1160 static bool test_RemovePrivilegesFromAccount(struct dcerpc_binding_handle
*b
,
1161 struct torture_context
*tctx
,
1162 struct policy_handle
*handle
,
1163 struct policy_handle
*acct_handle
,
1164 struct lsa_LUID
*luid
)
1166 struct lsa_RemovePrivilegesFromAccount r
;
1167 struct lsa_PrivilegeSet privs
;
1170 torture_comment(tctx
, "\nTesting RemovePrivilegesFromAccount\n");
1172 r
.in
.handle
= acct_handle
;
1173 r
.in
.remove_all
= 0;
1174 r
.in
.privs
= &privs
;
1178 privs
.set
= talloc_array(tctx
, struct lsa_LUIDAttribute
, 1);
1179 privs
.set
[0].luid
= *luid
;
1180 privs
.set
[0].attribute
= 0;
1182 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_RemovePrivilegesFromAccount_r(b
, tctx
, &r
),
1183 "RemovePrivilegesFromAccount failed");
1184 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1186 struct lsa_LookupPrivName r_name
;
1187 struct lsa_StringLarge
*name
= NULL
;
1189 r_name
.in
.handle
= handle
;
1190 r_name
.in
.luid
= luid
;
1191 r_name
.out
.name
= &name
;
1193 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupPrivName_r(b
, tctx
, &r_name
),
1194 "LookupPrivName failed");
1195 if (!NT_STATUS_IS_OK(r_name
.out
.result
)) {
1196 torture_comment(tctx
, "\nLookupPrivName failed - %s\n",
1197 nt_errstr(r_name
.out
.result
));
1200 /* Windows 2008 does not allow this to be removed */
1201 if (strcmp("SeAuditPrivilege", name
->string
) == 0) {
1205 torture_comment(tctx
, "RemovePrivilegesFromAccount failed to remove %s - %s\n",
1207 nt_errstr(r
.out
.result
));
1214 static bool test_AddPrivilegesToAccount(struct dcerpc_binding_handle
*b
,
1215 struct torture_context
*tctx
,
1216 struct policy_handle
*acct_handle
,
1217 struct lsa_LUID
*luid
)
1219 struct lsa_AddPrivilegesToAccount r
;
1220 struct lsa_PrivilegeSet privs
;
1223 torture_comment(tctx
, "\nTesting AddPrivilegesToAccount\n");
1225 r
.in
.handle
= acct_handle
;
1226 r
.in
.privs
= &privs
;
1230 privs
.set
= talloc_array(tctx
, struct lsa_LUIDAttribute
, 1);
1231 privs
.set
[0].luid
= *luid
;
1232 privs
.set
[0].attribute
= 0;
1234 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_AddPrivilegesToAccount_r(b
, tctx
, &r
),
1235 "AddPrivilegesToAccount failed");
1236 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
1237 "AddPrivilegesToAccount failed");
1241 static bool test_EnumPrivsAccount(struct dcerpc_binding_handle
*b
,
1242 struct torture_context
*tctx
,
1243 struct policy_handle
*handle
,
1244 struct policy_handle
*acct_handle
)
1246 struct lsa_EnumPrivsAccount r
;
1247 struct lsa_PrivilegeSet
*privs
= NULL
;
1250 torture_comment(tctx
, "\nTesting EnumPrivsAccount\n");
1252 r
.in
.handle
= acct_handle
;
1253 r
.out
.privs
= &privs
;
1255 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumPrivsAccount_r(b
, tctx
, &r
),
1256 "EnumPrivsAccount failed");
1257 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
1258 "EnumPrivsAccount failed");
1260 if (privs
&& privs
->count
> 0) {
1262 for (i
=0;i
<privs
->count
;i
++) {
1263 test_LookupPrivName(b
, tctx
, handle
,
1264 &privs
->set
[i
].luid
);
1267 ret
&= test_RemovePrivilegesFromAccount(b
, tctx
, handle
, acct_handle
,
1268 &privs
->set
[0].luid
);
1269 ret
&= test_AddPrivilegesToAccount(b
, tctx
, acct_handle
,
1270 &privs
->set
[0].luid
);
1276 static bool test_GetSystemAccessAccount(struct dcerpc_binding_handle
*b
,
1277 struct torture_context
*tctx
,
1278 struct policy_handle
*handle
,
1279 struct policy_handle
*acct_handle
)
1281 uint32_t access_mask
;
1282 struct lsa_GetSystemAccessAccount r
;
1284 torture_comment(tctx
, "\nTesting GetSystemAccessAccount\n");
1286 r
.in
.handle
= acct_handle
;
1287 r
.out
.access_mask
= &access_mask
;
1289 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_GetSystemAccessAccount_r(b
, tctx
, &r
),
1290 "GetSystemAccessAccount failed");
1291 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
1292 "GetSystemAccessAccount failed");
1294 if (r
.out
.access_mask
!= NULL
) {
1295 torture_comment(tctx
, "Rights:");
1296 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_INTERACTIVE
)
1297 torture_comment(tctx
, " LSA_POLICY_MODE_INTERACTIVE");
1298 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_NETWORK
)
1299 torture_comment(tctx
, " LSA_POLICY_MODE_NETWORK");
1300 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_BATCH
)
1301 torture_comment(tctx
, " LSA_POLICY_MODE_BATCH");
1302 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_SERVICE
)
1303 torture_comment(tctx
, " LSA_POLICY_MODE_SERVICE");
1304 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_PROXY
)
1305 torture_comment(tctx
, " LSA_POLICY_MODE_PROXY");
1306 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_INTERACTIVE
)
1307 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_INTERACTIVE");
1308 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_NETWORK
)
1309 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_NETWORK");
1310 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_BATCH
)
1311 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_BATCH");
1312 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_SERVICE
)
1313 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_SERVICE");
1314 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_REMOTE_INTERACTIVE
)
1315 torture_comment(tctx
, " LSA_POLICY_MODE_REMOTE_INTERACTIVE");
1316 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_REMOTE_INTERACTIVE
)
1317 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_REMOTE_INTERACTIVE");
1318 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_ALL
)
1319 torture_comment(tctx
, " LSA_POLICY_MODE_ALL");
1320 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_ALL_NT4
)
1321 torture_comment(tctx
, " LSA_POLICY_MODE_ALL_NT4");
1322 torture_comment(tctx
, "\n");
1328 static bool test_Delete(struct dcerpc_binding_handle
*b
,
1329 struct torture_context
*tctx
,
1330 struct policy_handle
*handle
)
1332 struct lsa_Delete r
;
1334 torture_comment(tctx
, "\nTesting Delete\n");
1336 r
.in
.handle
= handle
;
1337 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_Delete_r(b
, tctx
, &r
),
1339 torture_assert_ntstatus_equal(tctx
, r
.out
.result
, NT_STATUS_NOT_SUPPORTED
,
1340 "Delete should have failed NT_STATUS_NOT_SUPPORTED");
1345 static bool test_DeleteObject(struct dcerpc_binding_handle
*b
,
1346 struct torture_context
*tctx
,
1347 struct policy_handle
*handle
)
1349 struct lsa_DeleteObject r
;
1351 torture_comment(tctx
, "\nTesting DeleteObject\n");
1353 r
.in
.handle
= handle
;
1354 r
.out
.handle
= handle
;
1355 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_DeleteObject_r(b
, tctx
, &r
),
1356 "DeleteObject failed");
1357 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
1358 "DeleteObject failed");
1364 static bool test_CreateAccount(struct dcerpc_binding_handle
*b
,
1365 struct torture_context
*tctx
,
1366 struct policy_handle
*handle
)
1368 struct lsa_CreateAccount r
;
1369 struct dom_sid2
*newsid
;
1370 struct policy_handle acct_handle
;
1372 newsid
= dom_sid_parse_talloc(tctx
, "S-1-5-12349876-4321-2854");
1374 torture_comment(tctx
, "\nTesting CreateAccount\n");
1376 r
.in
.handle
= handle
;
1378 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1379 r
.out
.acct_handle
= &acct_handle
;
1381 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateAccount_r(b
, tctx
, &r
),
1382 "CreateAccount failed");
1383 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
1384 struct lsa_OpenAccount r_o
;
1385 r_o
.in
.handle
= handle
;
1386 r_o
.in
.sid
= newsid
;
1387 r_o
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1388 r_o
.out
.acct_handle
= &acct_handle
;
1390 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenAccount_r(b
, tctx
, &r_o
),
1391 "OpenAccount failed");
1392 torture_assert_ntstatus_ok(tctx
, r_o
.out
.result
,
1393 "OpenAccount failed");
1395 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
1396 "CreateAccount failed");
1399 if (!test_Delete(b
, tctx
, &acct_handle
)) {
1403 if (!test_DeleteObject(b
, tctx
, &acct_handle
)) {
1410 static bool test_DeleteTrustedDomain(struct dcerpc_binding_handle
*b
,
1411 struct torture_context
*tctx
,
1412 struct policy_handle
*handle
,
1413 struct lsa_StringLarge name
)
1415 struct lsa_OpenTrustedDomainByName r
;
1416 struct policy_handle trustdom_handle
;
1418 r
.in
.handle
= handle
;
1419 r
.in
.name
.string
= name
.string
;
1420 r
.in
.access_mask
= SEC_STD_DELETE
;
1421 r
.out
.trustdom_handle
= &trustdom_handle
;
1423 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenTrustedDomainByName_r(b
, tctx
, &r
),
1424 "OpenTrustedDomainByName failed");
1425 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
1426 "OpenTrustedDomainByName failed");
1428 if (!test_Delete(b
, tctx
, &trustdom_handle
)) {
1432 if (!test_DeleteObject(b
, tctx
, &trustdom_handle
)) {
1439 static bool test_DeleteTrustedDomainBySid(struct dcerpc_binding_handle
*b
,
1440 struct torture_context
*tctx
,
1441 struct policy_handle
*handle
,
1442 struct dom_sid
*sid
)
1444 struct lsa_DeleteTrustedDomain r
;
1446 r
.in
.handle
= handle
;
1449 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_DeleteTrustedDomain_r(b
, tctx
, &r
),
1450 "DeleteTrustedDomain failed");
1451 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
1452 "DeleteTrustedDomain failed");
1458 static bool test_CreateSecret(struct dcerpc_pipe
*p
,
1459 struct torture_context
*tctx
,
1460 struct policy_handle
*handle
)
1462 struct lsa_CreateSecret r
;
1463 struct lsa_OpenSecret r2
;
1464 struct lsa_SetSecret r3
;
1465 struct lsa_QuerySecret r4
;
1466 struct lsa_SetSecret r5
;
1467 struct lsa_QuerySecret r6
;
1468 struct lsa_SetSecret r7
;
1469 struct lsa_QuerySecret r8
;
1470 struct policy_handle sec_handle
, sec_handle2
, sec_handle3
;
1471 struct lsa_DeleteObject d_o
;
1472 struct lsa_DATA_BUF buf1
;
1473 struct lsa_DATA_BUF_PTR bufp1
;
1474 struct lsa_DATA_BUF_PTR bufp2
;
1477 DATA_BLOB session_key
;
1478 NTTIME old_mtime
, new_mtime
;
1480 const char *secret1
= "abcdef12345699qwerty";
1482 const char *secret3
= "ABCDEF12345699QWERTY";
1484 const char *secret5
= "NEW-SAMBA4-SECRET";
1488 const int LOCAL
= 0;
1489 const int GLOBAL
= 1;
1490 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
1492 secname
[LOCAL
] = talloc_asprintf(tctx
, "torturesecret-%u", (unsigned int)random());
1493 secname
[GLOBAL
] = talloc_asprintf(tctx
, "G$torturesecret-%u", (unsigned int)random());
1495 for (i
=0; i
< 2; i
++) {
1496 torture_comment(tctx
, "\nTesting CreateSecret of %s\n", secname
[i
]);
1498 init_lsa_String(&r
.in
.name
, secname
[i
]);
1500 r
.in
.handle
= handle
;
1501 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1502 r
.out
.sec_handle
= &sec_handle
;
1504 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateSecret_r(b
, tctx
, &r
),
1505 "CreateSecret failed");
1506 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
1507 "CreateSecret failed");
1509 r
.in
.handle
= handle
;
1510 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1511 r
.out
.sec_handle
= &sec_handle3
;
1513 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateSecret_r(b
, tctx
, &r
),
1514 "CreateSecret failed");
1515 torture_assert_ntstatus_equal(tctx
, r
.out
.result
, NT_STATUS_OBJECT_NAME_COLLISION
,
1516 "CreateSecret should have failed OBJECT_NAME_COLLISION");
1518 r2
.in
.handle
= handle
;
1519 r2
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1520 r2
.in
.name
= r
.in
.name
;
1521 r2
.out
.sec_handle
= &sec_handle2
;
1523 torture_comment(tctx
, "Testing OpenSecret\n");
1525 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenSecret_r(b
, tctx
, &r2
),
1526 "OpenSecret failed");
1527 torture_assert_ntstatus_ok(tctx
, r2
.out
.result
,
1528 "OpenSecret failed");
1530 torture_assert_ntstatus_ok(tctx
, dcerpc_fetch_session_key(p
, &session_key
),
1531 "dcerpc_fetch_session_key failed");
1533 enc_key
= sess_encrypt_string(secret1
, &session_key
);
1535 r3
.in
.sec_handle
= &sec_handle
;
1536 r3
.in
.new_val
= &buf1
;
1537 r3
.in
.old_val
= NULL
;
1538 r3
.in
.new_val
->data
= enc_key
.data
;
1539 r3
.in
.new_val
->length
= enc_key
.length
;
1540 r3
.in
.new_val
->size
= enc_key
.length
;
1542 torture_comment(tctx
, "Testing SetSecret\n");
1544 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_SetSecret_r(b
, tctx
, &r3
),
1545 "SetSecret failed");
1546 torture_assert_ntstatus_ok(tctx
, r3
.out
.result
,
1547 "SetSecret failed");
1549 r3
.in
.sec_handle
= &sec_handle
;
1550 r3
.in
.new_val
= &buf1
;
1551 r3
.in
.old_val
= NULL
;
1552 r3
.in
.new_val
->data
= enc_key
.data
;
1553 r3
.in
.new_val
->length
= enc_key
.length
;
1554 r3
.in
.new_val
->size
= enc_key
.length
;
1556 /* break the encrypted data */
1559 torture_comment(tctx
, "Testing SetSecret with broken key\n");
1561 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_SetSecret_r(b
, tctx
, &r3
),
1562 "SetSecret failed");
1563 torture_assert_ntstatus_equal(tctx
, r3
.out
.result
, NT_STATUS_UNKNOWN_REVISION
,
1564 "SetSecret should have failed UNKNOWN_REVISION");
1566 data_blob_free(&enc_key
);
1568 ZERO_STRUCT(new_mtime
);
1569 ZERO_STRUCT(old_mtime
);
1571 /* fetch the secret back again */
1572 r4
.in
.sec_handle
= &sec_handle
;
1573 r4
.in
.new_val
= &bufp1
;
1574 r4
.in
.new_mtime
= &new_mtime
;
1575 r4
.in
.old_val
= NULL
;
1576 r4
.in
.old_mtime
= NULL
;
1580 torture_comment(tctx
, "Testing QuerySecret\n");
1581 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QuerySecret_r(b
, tctx
, &r4
),
1582 "QuerySecret failed");
1583 if (!NT_STATUS_IS_OK(r4
.out
.result
)) {
1584 torture_comment(tctx
, "QuerySecret failed - %s\n", nt_errstr(r4
.out
.result
));
1587 if (r4
.out
.new_val
== NULL
|| r4
.out
.new_val
->buf
== NULL
) {
1588 torture_comment(tctx
, "No secret buffer returned\n");
1591 blob1
.data
= r4
.out
.new_val
->buf
->data
;
1592 blob1
.length
= r4
.out
.new_val
->buf
->size
;
1594 secret2
= sess_decrypt_string(tctx
,
1595 &blob1
, &session_key
);
1597 if (strcmp(secret1
, secret2
) != 0) {
1598 torture_comment(tctx
, "Returned secret (r4) '%s' doesn't match '%s'\n",
1605 enc_key
= sess_encrypt_string(secret3
, &session_key
);
1607 r5
.in
.sec_handle
= &sec_handle
;
1608 r5
.in
.new_val
= &buf1
;
1609 r5
.in
.old_val
= NULL
;
1610 r5
.in
.new_val
->data
= enc_key
.data
;
1611 r5
.in
.new_val
->length
= enc_key
.length
;
1612 r5
.in
.new_val
->size
= enc_key
.length
;
1616 torture_comment(tctx
, "Testing SetSecret (existing value should move to old)\n");
1618 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_SetSecret_r(b
, tctx
, &r5
),
1619 "SetSecret failed");
1620 if (!NT_STATUS_IS_OK(r5
.out
.result
)) {
1621 torture_comment(tctx
, "SetSecret failed - %s\n", nt_errstr(r5
.out
.result
));
1625 data_blob_free(&enc_key
);
1627 ZERO_STRUCT(new_mtime
);
1628 ZERO_STRUCT(old_mtime
);
1630 /* fetch the secret back again */
1631 r6
.in
.sec_handle
= &sec_handle
;
1632 r6
.in
.new_val
= &bufp1
;
1633 r6
.in
.new_mtime
= &new_mtime
;
1634 r6
.in
.old_val
= &bufp2
;
1635 r6
.in
.old_mtime
= &old_mtime
;
1640 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QuerySecret_r(b
, tctx
, &r6
),
1641 "QuerySecret failed");
1642 if (!NT_STATUS_IS_OK(r6
.out
.result
)) {
1643 torture_comment(tctx
, "QuerySecret failed - %s\n", nt_errstr(r6
.out
.result
));
1648 if (r6
.out
.new_val
->buf
== NULL
|| r6
.out
.old_val
->buf
== NULL
1649 || r6
.out
.new_mtime
== NULL
|| r6
.out
.old_mtime
== NULL
) {
1650 torture_comment(tctx
, "Both secret buffers and both times not returned\n");
1654 blob1
.data
= r6
.out
.new_val
->buf
->data
;
1655 blob1
.length
= r6
.out
.new_val
->buf
->size
;
1657 secret4
= sess_decrypt_string(tctx
,
1658 &blob1
, &session_key
);
1660 if (strcmp(secret3
, secret4
) != 0) {
1661 torture_comment(tctx
, "Returned NEW secret %s doesn't match %s\n", secret4
, secret3
);
1665 blob1
.data
= r6
.out
.old_val
->buf
->data
;
1666 blob1
.length
= r6
.out
.old_val
->buf
->length
;
1668 secret2
= sess_decrypt_string(tctx
,
1669 &blob1
, &session_key
);
1671 if (strcmp(secret1
, secret2
) != 0) {
1672 torture_comment(tctx
, "Returned OLD secret %s doesn't match %s\n", secret2
, secret1
);
1676 if (*r6
.out
.new_mtime
== *r6
.out
.old_mtime
) {
1677 torture_comment(tctx
, "Returned secret (r6-%d) %s must not have same mtime for both secrets: %s != %s\n",
1680 nt_time_string(tctx
, *r6
.out
.old_mtime
),
1681 nt_time_string(tctx
, *r6
.out
.new_mtime
));
1687 enc_key
= sess_encrypt_string(secret5
, &session_key
);
1689 r7
.in
.sec_handle
= &sec_handle
;
1690 r7
.in
.old_val
= &buf1
;
1691 r7
.in
.old_val
->data
= enc_key
.data
;
1692 r7
.in
.old_val
->length
= enc_key
.length
;
1693 r7
.in
.old_val
->size
= enc_key
.length
;
1694 r7
.in
.new_val
= NULL
;
1696 torture_comment(tctx
, "Testing SetSecret of old Secret only\n");
1698 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_SetSecret_r(b
, tctx
, &r7
),
1699 "SetSecret failed");
1700 if (!NT_STATUS_IS_OK(r7
.out
.result
)) {
1701 torture_comment(tctx
, "SetSecret failed - %s\n", nt_errstr(r7
.out
.result
));
1705 data_blob_free(&enc_key
);
1707 /* fetch the secret back again */
1708 r8
.in
.sec_handle
= &sec_handle
;
1709 r8
.in
.new_val
= &bufp1
;
1710 r8
.in
.new_mtime
= &new_mtime
;
1711 r8
.in
.old_val
= &bufp2
;
1712 r8
.in
.old_mtime
= &old_mtime
;
1717 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QuerySecret_r(b
, tctx
, &r8
),
1718 "QuerySecret failed");
1719 if (!NT_STATUS_IS_OK(r8
.out
.result
)) {
1720 torture_comment(tctx
, "QuerySecret failed - %s\n", nt_errstr(r8
.out
.result
));
1723 if (!r8
.out
.new_val
|| !r8
.out
.old_val
) {
1724 torture_comment(tctx
, "in/out pointers not returned, despite being set on in for QuerySecret\n");
1726 } else if (r8
.out
.new_val
->buf
!= NULL
) {
1727 torture_comment(tctx
, "NEW secret buffer must not be returned after OLD set\n");
1729 } else if (r8
.out
.old_val
->buf
== NULL
) {
1730 torture_comment(tctx
, "OLD secret buffer was not returned after OLD set\n");
1732 } else if (r8
.out
.new_mtime
== NULL
|| r8
.out
.old_mtime
== NULL
) {
1733 torture_comment(tctx
, "Both times not returned after OLD set\n");
1736 blob1
.data
= r8
.out
.old_val
->buf
->data
;
1737 blob1
.length
= r8
.out
.old_val
->buf
->size
;
1739 secret6
= sess_decrypt_string(tctx
,
1740 &blob1
, &session_key
);
1742 if (strcmp(secret5
, secret6
) != 0) {
1743 torture_comment(tctx
, "Returned OLD secret %s doesn't match %s\n", secret5
, secret6
);
1747 if (*r8
.out
.new_mtime
!= *r8
.out
.old_mtime
) {
1748 torture_comment(tctx
, "Returned secret (r8) %s did not had same mtime for both secrets: %s != %s\n",
1750 nt_time_string(tctx
, *r8
.out
.old_mtime
),
1751 nt_time_string(tctx
, *r8
.out
.new_mtime
));
1757 if (!test_Delete(b
, tctx
, &sec_handle
)) {
1761 if (!test_DeleteObject(b
, tctx
, &sec_handle
)) {
1765 d_o
.in
.handle
= &sec_handle2
;
1766 d_o
.out
.handle
= &sec_handle2
;
1767 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_DeleteObject_r(b
, tctx
, &d_o
),
1768 "DeleteObject failed");
1769 torture_assert_ntstatus_equal(tctx
, d_o
.out
.result
, NT_STATUS_INVALID_HANDLE
,
1770 "OpenSecret expected INVALID_HANDLE");
1772 torture_comment(tctx
, "Testing OpenSecret of just-deleted secret\n");
1774 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenSecret_r(b
, tctx
, &r2
),
1775 "OpenSecret failed");
1776 torture_assert_ntstatus_equal(tctx
, r2
.out
.result
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
1777 "OpenSecret expected OBJECT_NAME_NOT_FOUND");
1783 static bool test_EnumAccountRights(struct dcerpc_binding_handle
*b
,
1784 struct torture_context
*tctx
,
1785 struct policy_handle
*acct_handle
,
1786 struct dom_sid
*sid
)
1788 struct lsa_EnumAccountRights r
;
1789 struct lsa_RightSet rights
;
1791 torture_comment(tctx
, "\nTesting EnumAccountRights\n");
1793 r
.in
.handle
= acct_handle
;
1795 r
.out
.rights
= &rights
;
1797 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumAccountRights_r(b
, tctx
, &r
),
1798 "EnumAccountRights failed");
1799 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1800 torture_comment(tctx
, "EnumAccountRights of %s failed - %s\n",
1801 dom_sid_string(tctx
, sid
), nt_errstr(r
.out
.result
));
1803 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
1804 "EnumAccountRights failed");
1810 static bool test_QuerySecurity(struct dcerpc_binding_handle
*b
,
1811 struct torture_context
*tctx
,
1812 struct policy_handle
*handle
,
1813 struct policy_handle
*acct_handle
)
1815 struct lsa_QuerySecurity r
;
1816 struct sec_desc_buf
*sdbuf
= NULL
;
1818 if (torture_setting_bool(tctx
, "samba4", false)) {
1819 torture_comment(tctx
, "\nskipping QuerySecurity test against Samba4\n");
1823 torture_comment(tctx
, "\nTesting QuerySecurity\n");
1825 r
.in
.handle
= acct_handle
;
1826 r
.in
.sec_info
= SECINFO_OWNER
|
1829 r
.out
.sdbuf
= &sdbuf
;
1831 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QuerySecurity_r(b
, tctx
, &r
),
1832 "QuerySecurity failed");
1833 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1834 torture_comment(tctx
, "QuerySecurity failed - %s\n", nt_errstr(r
.out
.result
));
1841 static bool test_OpenAccount(struct dcerpc_binding_handle
*b
,
1842 struct torture_context
*tctx
,
1843 struct policy_handle
*handle
,
1844 struct dom_sid
*sid
)
1846 struct lsa_OpenAccount r
;
1847 struct policy_handle acct_handle
;
1849 torture_comment(tctx
, "\nTesting OpenAccount\n");
1851 r
.in
.handle
= handle
;
1853 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1854 r
.out
.acct_handle
= &acct_handle
;
1856 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenAccount_r(b
, tctx
, &r
),
1857 "OpenAccount failed");
1858 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
1859 "OpenAccount failed");
1861 if (!test_EnumPrivsAccount(b
, tctx
, handle
, &acct_handle
)) {
1865 if (!test_GetSystemAccessAccount(b
, tctx
, handle
, &acct_handle
)) {
1869 if (!test_QuerySecurity(b
, tctx
, handle
, &acct_handle
)) {
1876 static bool test_EnumAccounts(struct dcerpc_binding_handle
*b
,
1877 struct torture_context
*tctx
,
1878 struct policy_handle
*handle
)
1880 struct lsa_EnumAccounts r
;
1881 struct lsa_SidArray sids1
, sids2
;
1882 uint32_t resume_handle
= 0;
1886 torture_comment(tctx
, "\nTesting EnumAccounts\n");
1888 r
.in
.handle
= handle
;
1889 r
.in
.resume_handle
= &resume_handle
;
1890 r
.in
.num_entries
= 100;
1891 r
.out
.resume_handle
= &resume_handle
;
1892 r
.out
.sids
= &sids1
;
1896 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumAccounts_r(b
, tctx
, &r
),
1897 "EnumAccounts failed");
1898 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
)) {
1901 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
1902 "EnumAccounts failed");
1904 if (!test_LookupSids(b
, tctx
, handle
, &sids1
)) {
1908 if (!test_LookupSids2(b
, tctx
, handle
, &sids1
)) {
1912 /* Can't test lookupSids3 here, as clearly we must not
1913 * be on schannel, or we would not be able to do the
1916 torture_comment(tctx
, "Testing all accounts\n");
1917 for (i
=0;i
<sids1
.num_sids
;i
++) {
1918 ret
&= test_OpenAccount(b
, tctx
, handle
, sids1
.sids
[i
].sid
);
1919 ret
&= test_EnumAccountRights(b
, tctx
, handle
, sids1
.sids
[i
].sid
);
1921 torture_comment(tctx
, "\n");
1924 if (sids1
.num_sids
< 3) {
1928 torture_comment(tctx
, "Trying EnumAccounts partial listing (asking for 1 at 2)\n");
1930 r
.in
.num_entries
= 1;
1931 r
.out
.sids
= &sids2
;
1933 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumAccounts_r(b
, tctx
, &r
),
1934 "EnumAccounts failed");
1935 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
1936 "EnumAccounts failed");
1938 if (sids2
.num_sids
!= 1) {
1939 torture_comment(tctx
, "Returned wrong number of entries (%d)\n", sids2
.num_sids
);
1946 static bool test_LookupPrivDisplayName(struct dcerpc_binding_handle
*b
,
1947 struct torture_context
*tctx
,
1948 struct policy_handle
*handle
,
1949 struct lsa_String
*priv_name
)
1951 struct lsa_LookupPrivDisplayName r
;
1952 /* produce a reasonable range of language output without screwing up
1954 uint16_t language_id
= (random() % 4) + 0x409;
1955 uint16_t returned_language_id
= 0;
1956 struct lsa_StringLarge
*disp_name
= NULL
;
1958 torture_comment(tctx
, "\nTesting LookupPrivDisplayName(%s)\n", priv_name
->string
);
1960 r
.in
.handle
= handle
;
1961 r
.in
.name
= priv_name
;
1962 r
.in
.language_id
= language_id
;
1963 r
.in
.language_id_sys
= 0;
1964 r
.out
.returned_language_id
= &returned_language_id
;
1965 r
.out
.disp_name
= &disp_name
;
1967 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupPrivDisplayName_r(b
, tctx
, &r
),
1968 "LookupPrivDisplayName failed");
1969 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1970 torture_comment(tctx
, "LookupPrivDisplayName failed - %s\n", nt_errstr(r
.out
.result
));
1973 torture_comment(tctx
, "%s -> \"%s\" (language 0x%x/0x%x)\n",
1974 priv_name
->string
, disp_name
->string
,
1975 r
.in
.language_id
, *r
.out
.returned_language_id
);
1980 static bool test_EnumAccountsWithUserRight(struct dcerpc_binding_handle
*b
,
1981 struct torture_context
*tctx
,
1982 struct policy_handle
*handle
,
1983 struct lsa_String
*priv_name
)
1985 struct lsa_EnumAccountsWithUserRight r
;
1986 struct lsa_SidArray sids
;
1990 torture_comment(tctx
, "\nTesting EnumAccountsWithUserRight(%s)\n", priv_name
->string
);
1992 r
.in
.handle
= handle
;
1993 r
.in
.name
= priv_name
;
1996 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumAccountsWithUserRight_r(b
, tctx
, &r
),
1997 "EnumAccountsWithUserRight failed");
1999 /* NT_STATUS_NO_MORE_ENTRIES means noone has this privilege */
2000 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
)) {
2004 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2005 torture_comment(tctx
, "EnumAccountsWithUserRight failed - %s\n", nt_errstr(r
.out
.result
));
2013 static bool test_EnumPrivs(struct dcerpc_binding_handle
*b
,
2014 struct torture_context
*tctx
,
2015 struct policy_handle
*handle
)
2017 struct lsa_EnumPrivs r
;
2018 struct lsa_PrivArray privs1
;
2019 uint32_t resume_handle
= 0;
2023 torture_comment(tctx
, "\nTesting EnumPrivs\n");
2025 r
.in
.handle
= handle
;
2026 r
.in
.resume_handle
= &resume_handle
;
2027 r
.in
.max_count
= 100;
2028 r
.out
.resume_handle
= &resume_handle
;
2029 r
.out
.privs
= &privs1
;
2032 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumPrivs_r(b
, tctx
, &r
),
2033 "EnumPrivs failed");
2034 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
2035 "EnumPrivs failed");
2037 for (i
= 0; i
< privs1
.count
; i
++) {
2038 test_LookupPrivDisplayName(b
, tctx
, handle
, (struct lsa_String
*)&privs1
.privs
[i
].name
);
2039 test_LookupPrivValue(b
, tctx
, handle
, (struct lsa_String
*)&privs1
.privs
[i
].name
);
2040 if (!test_EnumAccountsWithUserRight(b
, tctx
, handle
, (struct lsa_String
*)&privs1
.privs
[i
].name
)) {
2048 static bool test_QueryForestTrustInformation(struct dcerpc_binding_handle
*b
,
2049 struct torture_context
*tctx
,
2050 struct policy_handle
*handle
,
2051 const char *trusted_domain_name
)
2054 struct lsa_lsaRQueryForestTrustInformation r
;
2055 struct lsa_String string
;
2056 struct lsa_ForestTrustInformation info
, *info_ptr
;
2058 torture_comment(tctx
, "\nTesting lsaRQueryForestTrustInformation\n");
2060 if (torture_setting_bool(tctx
, "samba4", false)) {
2061 torture_comment(tctx
, "skipping QueryForestTrustInformation against Samba4\n");
2065 ZERO_STRUCT(string
);
2067 if (trusted_domain_name
) {
2068 init_lsa_String(&string
, trusted_domain_name
);
2073 r
.in
.handle
= handle
;
2074 r
.in
.trusted_domain_name
= &string
;
2076 r
.out
.forest_trust_info
= &info_ptr
;
2078 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_lsaRQueryForestTrustInformation_r(b
, tctx
, &r
),
2079 "lsaRQueryForestTrustInformation failed");
2081 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2082 torture_comment(tctx
, "lsaRQueryForestTrustInformation of %s failed - %s\n", trusted_domain_name
, nt_errstr(r
.out
.result
));
2089 static bool test_query_each_TrustDomEx(struct dcerpc_binding_handle
*b
,
2090 struct torture_context
*tctx
,
2091 struct policy_handle
*handle
,
2092 struct lsa_DomainListEx
*domains
)
2097 for (i
=0; i
< domains
->count
; i
++) {
2099 if (domains
->domains
[i
].trust_attributes
& NETR_TRUST_ATTRIBUTE_FOREST_TRANSITIVE
) {
2100 ret
&= test_QueryForestTrustInformation(b
, tctx
, handle
,
2101 domains
->domains
[i
].domain_name
.string
);
2108 static bool test_query_each_TrustDom(struct dcerpc_binding_handle
*b
,
2109 struct torture_context
*tctx
,
2110 struct policy_handle
*handle
,
2111 struct lsa_DomainList
*domains
)
2116 torture_comment(tctx
, "\nTesting OpenTrustedDomain, OpenTrustedDomainByName and QueryInfoTrustedDomain\n");
2117 for (i
=0; i
< domains
->count
; i
++) {
2118 struct lsa_OpenTrustedDomain trust
;
2119 struct lsa_OpenTrustedDomainByName trust_by_name
;
2120 struct policy_handle trustdom_handle
;
2121 struct policy_handle handle2
;
2123 struct lsa_CloseTrustedDomainEx c_trust
;
2124 int levels
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
2125 int ok
[] = {1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1};
2127 if (domains
->domains
[i
].sid
) {
2128 trust
.in
.handle
= handle
;
2129 trust
.in
.sid
= domains
->domains
[i
].sid
;
2130 trust
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2131 trust
.out
.trustdom_handle
= &trustdom_handle
;
2133 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenTrustedDomain_r(b
, tctx
, &trust
),
2134 "OpenTrustedDomain failed");
2136 if (!NT_STATUS_IS_OK(trust
.out
.result
)) {
2137 torture_comment(tctx
, "OpenTrustedDomain failed - %s\n", nt_errstr(trust
.out
.result
));
2141 c
.in
.handle
= &trustdom_handle
;
2142 c
.out
.handle
= &handle2
;
2144 c_trust
.in
.handle
= &trustdom_handle
;
2145 c_trust
.out
.handle
= &handle2
;
2147 for (j
=0; j
< ARRAY_SIZE(levels
); j
++) {
2148 struct lsa_QueryTrustedDomainInfo q
;
2149 union lsa_TrustedDomainInfo
*info
= NULL
;
2150 q
.in
.trustdom_handle
= &trustdom_handle
;
2151 q
.in
.level
= levels
[j
];
2153 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfo_r(b
, tctx
, &q
),
2154 "QueryTrustedDomainInfo failed");
2155 if (!NT_STATUS_IS_OK(q
.out
.result
) && ok
[j
]) {
2156 torture_comment(tctx
, "QueryTrustedDomainInfo level %d failed - %s\n",
2157 levels
[j
], nt_errstr(q
.out
.result
));
2159 } else if (NT_STATUS_IS_OK(q
.out
.result
) && !ok
[j
]) {
2160 torture_comment(tctx
, "QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
2161 levels
[j
], nt_errstr(q
.out
.result
));
2166 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CloseTrustedDomainEx_r(b
, tctx
, &c_trust
),
2167 "CloseTrustedDomainEx failed");
2168 if (!NT_STATUS_EQUAL(c_trust
.out
.result
, NT_STATUS_NOT_IMPLEMENTED
)) {
2169 torture_comment(tctx
, "Expected CloseTrustedDomainEx to return NT_STATUS_NOT_IMPLEMENTED, instead - %s\n", nt_errstr(c_trust
.out
.result
));
2173 c
.in
.handle
= &trustdom_handle
;
2174 c
.out
.handle
= &handle2
;
2176 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_Close_r(b
, tctx
, &c
),
2178 if (!NT_STATUS_IS_OK(c
.out
.result
)) {
2179 torture_comment(tctx
, "Close of trusted domain failed - %s\n", nt_errstr(c
.out
.result
));
2183 for (j
=0; j
< ARRAY_SIZE(levels
); j
++) {
2184 struct lsa_QueryTrustedDomainInfoBySid q
;
2185 union lsa_TrustedDomainInfo
*info
= NULL
;
2187 if (!domains
->domains
[i
].sid
) {
2191 q
.in
.handle
= handle
;
2192 q
.in
.dom_sid
= domains
->domains
[i
].sid
;
2193 q
.in
.level
= levels
[j
];
2196 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfoBySid_r(b
, tctx
, &q
),
2197 "lsa_QueryTrustedDomainInfoBySid failed");
2198 if (!NT_STATUS_IS_OK(q
.out
.result
) && ok
[j
]) {
2199 torture_comment(tctx
, "QueryTrustedDomainInfoBySid level %d failed - %s\n",
2200 levels
[j
], nt_errstr(q
.out
.result
));
2202 } else if (NT_STATUS_IS_OK(q
.out
.result
) && !ok
[j
]) {
2203 torture_comment(tctx
, "QueryTrustedDomainInfoBySid level %d unexpectedly succeeded - %s\n",
2204 levels
[j
], nt_errstr(q
.out
.result
));
2210 trust_by_name
.in
.handle
= handle
;
2211 trust_by_name
.in
.name
.string
= domains
->domains
[i
].name
.string
;
2212 trust_by_name
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2213 trust_by_name
.out
.trustdom_handle
= &trustdom_handle
;
2215 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenTrustedDomainByName_r(b
, tctx
, &trust_by_name
),
2216 "OpenTrustedDomainByName failed");
2218 if (!NT_STATUS_IS_OK(trust_by_name
.out
.result
)) {
2219 torture_comment(tctx
, "OpenTrustedDomainByName failed - %s\n", nt_errstr(trust_by_name
.out
.result
));
2223 for (j
=0; j
< ARRAY_SIZE(levels
); j
++) {
2224 struct lsa_QueryTrustedDomainInfo q
;
2225 union lsa_TrustedDomainInfo
*info
= NULL
;
2226 q
.in
.trustdom_handle
= &trustdom_handle
;
2227 q
.in
.level
= levels
[j
];
2229 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfo_r(b
, tctx
, &q
),
2230 "QueryTrustedDomainInfo failed");
2231 if (!NT_STATUS_IS_OK(q
.out
.result
) && ok
[j
]) {
2232 torture_comment(tctx
, "QueryTrustedDomainInfo level %d failed - %s\n",
2233 levels
[j
], nt_errstr(q
.out
.result
));
2235 } else if (NT_STATUS_IS_OK(q
.out
.result
) && !ok
[j
]) {
2236 torture_comment(tctx
, "QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
2237 levels
[j
], nt_errstr(q
.out
.result
));
2242 c
.in
.handle
= &trustdom_handle
;
2243 c
.out
.handle
= &handle2
;
2245 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_Close_r(b
, tctx
, &c
),
2247 if (!NT_STATUS_IS_OK(c
.out
.result
)) {
2248 torture_comment(tctx
, "Close of trusted domain failed - %s\n", nt_errstr(c
.out
.result
));
2252 for (j
=0; j
< ARRAY_SIZE(levels
); j
++) {
2253 struct lsa_QueryTrustedDomainInfoByName q
;
2254 union lsa_TrustedDomainInfo
*info
= NULL
;
2255 struct lsa_String name
;
2257 name
.string
= domains
->domains
[i
].name
.string
;
2259 q
.in
.handle
= handle
;
2260 q
.in
.trusted_domain
= &name
;
2261 q
.in
.level
= levels
[j
];
2263 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfoByName_r(b
, tctx
, &q
),
2264 "QueryTrustedDomainInfoByName failed");
2265 if (!NT_STATUS_IS_OK(q
.out
.result
) && ok
[j
]) {
2266 torture_comment(tctx
, "QueryTrustedDomainInfoByName level %d failed - %s\n",
2267 levels
[j
], nt_errstr(q
.out
.result
));
2269 } else if (NT_STATUS_IS_OK(q
.out
.result
) && !ok
[j
]) {
2270 torture_comment(tctx
, "QueryTrustedDomainInfoByName level %d unexpectedly succeeded - %s\n",
2271 levels
[j
], nt_errstr(q
.out
.result
));
2279 static bool test_EnumTrustDom(struct dcerpc_binding_handle
*b
,
2280 struct torture_context
*tctx
,
2281 struct policy_handle
*handle
)
2283 struct lsa_EnumTrustDom r
;
2284 uint32_t in_resume_handle
= 0;
2285 uint32_t out_resume_handle
;
2286 struct lsa_DomainList domains
;
2289 torture_comment(tctx
, "\nTesting EnumTrustDom\n");
2291 r
.in
.handle
= handle
;
2292 r
.in
.resume_handle
= &in_resume_handle
;
2294 r
.out
.domains
= &domains
;
2295 r
.out
.resume_handle
= &out_resume_handle
;
2297 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumTrustDom_r(b
, tctx
, &r
),
2298 "lsa_EnumTrustDom failed");
2300 /* according to MS-LSAD 3.1.4.7.8 output resume handle MUST
2301 * always be larger than the previous input resume handle, in
2302 * particular when hitting the last query it is vital to set the
2303 * resume handle correctly to avoid infinite client loops, as
2304 * seen e.g. with Windows XP SP3 when resume handle is 0 and
2305 * status is NT_STATUS_OK - gd */
2307 if (NT_STATUS_IS_OK(r
.out
.result
) ||
2308 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
) ||
2309 NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
))
2311 if (out_resume_handle
<= in_resume_handle
) {
2312 torture_comment(tctx
, "EnumTrustDom failed - should have returned output resume_handle (0x%08x) larger than input resume handle (0x%08x)\n",
2313 out_resume_handle
, in_resume_handle
);
2318 if (NT_STATUS_IS_OK(r
.out
.result
)) {
2319 if (domains
.count
== 0) {
2320 torture_comment(tctx
, "EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2323 } else if (!(NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
) || NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
))) {
2324 torture_comment(tctx
, "EnumTrustDom of zero size failed - %s\n", nt_errstr(r
.out
.result
));
2328 /* Start from the bottom again */
2329 in_resume_handle
= 0;
2332 r
.in
.handle
= handle
;
2333 r
.in
.resume_handle
= &in_resume_handle
;
2334 r
.in
.max_size
= LSA_ENUM_TRUST_DOMAIN_MULTIPLIER
* 3;
2335 r
.out
.domains
= &domains
;
2336 r
.out
.resume_handle
= &out_resume_handle
;
2338 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumTrustDom_r(b
, tctx
, &r
),
2339 "EnumTrustDom failed");
2341 /* according to MS-LSAD 3.1.4.7.8 output resume handle MUST
2342 * always be larger than the previous input resume handle, in
2343 * particular when hitting the last query it is vital to set the
2344 * resume handle correctly to avoid infinite client loops, as
2345 * seen e.g. with Windows XP SP3 when resume handle is 0 and
2346 * status is NT_STATUS_OK - gd */
2348 if (NT_STATUS_IS_OK(r
.out
.result
) ||
2349 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
) ||
2350 NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
))
2352 if (out_resume_handle
<= in_resume_handle
) {
2353 torture_comment(tctx
, "EnumTrustDom failed - should have returned output resume_handle (0x%08x) larger than input resume handle (0x%08x)\n",
2354 out_resume_handle
, in_resume_handle
);
2359 /* NO_MORE_ENTRIES is allowed */
2360 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
)) {
2361 if (domains
.count
== 0) {
2364 torture_comment(tctx
, "EnumTrustDom failed - should have returned 0 trusted domains with 'NT_STATUS_NO_MORE_ENTRIES'\n");
2366 } else if (NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
)) {
2367 /* Windows 2003 gets this off by one on the first run */
2368 if (r
.out
.domains
->count
< 3 || r
.out
.domains
->count
> 4) {
2369 torture_comment(tctx
, "EnumTrustDom didn't fill the buffer we "
2370 "asked it to (got %d, expected %d / %d == %d entries)\n",
2371 r
.out
.domains
->count
, LSA_ENUM_TRUST_DOMAIN_MULTIPLIER
* 3,
2372 LSA_ENUM_TRUST_DOMAIN_MULTIPLIER
, r
.in
.max_size
);
2375 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2376 torture_comment(tctx
, "EnumTrustDom failed - %s\n", nt_errstr(r
.out
.result
));
2380 if (domains
.count
== 0) {
2381 torture_comment(tctx
, "EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2385 ret
&= test_query_each_TrustDom(b
, tctx
, handle
, &domains
);
2387 in_resume_handle
= out_resume_handle
;
2389 } while ((NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
)));
2394 static bool test_EnumTrustDomEx(struct dcerpc_binding_handle
*b
,
2395 struct torture_context
*tctx
,
2396 struct policy_handle
*handle
)
2398 struct lsa_EnumTrustedDomainsEx r_ex
;
2399 uint32_t resume_handle
= 0;
2400 struct lsa_DomainListEx domains_ex
;
2403 torture_comment(tctx
, "\nTesting EnumTrustedDomainsEx\n");
2405 r_ex
.in
.handle
= handle
;
2406 r_ex
.in
.resume_handle
= &resume_handle
;
2407 r_ex
.in
.max_size
= LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER
* 3;
2408 r_ex
.out
.domains
= &domains_ex
;
2409 r_ex
.out
.resume_handle
= &resume_handle
;
2411 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumTrustedDomainsEx_r(b
, tctx
, &r_ex
),
2412 "EnumTrustedDomainsEx failed");
2414 if (!(NT_STATUS_EQUAL(r_ex
.out
.result
, STATUS_MORE_ENTRIES
) || NT_STATUS_EQUAL(r_ex
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
))) {
2415 torture_comment(tctx
, "EnumTrustedDomainEx of zero size failed - %s\n", nt_errstr(r_ex
.out
.result
));
2421 r_ex
.in
.handle
= handle
;
2422 r_ex
.in
.resume_handle
= &resume_handle
;
2423 r_ex
.in
.max_size
= LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER
* 3;
2424 r_ex
.out
.domains
= &domains_ex
;
2425 r_ex
.out
.resume_handle
= &resume_handle
;
2427 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumTrustedDomainsEx_r(b
, tctx
, &r_ex
),
2428 "EnumTrustedDomainsEx failed");
2430 /* NO_MORE_ENTRIES is allowed */
2431 if (NT_STATUS_EQUAL(r_ex
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
)) {
2432 if (domains_ex
.count
== 0) {
2435 torture_comment(tctx
, "EnumTrustDomainsEx failed - should have returned 0 trusted domains with 'NT_STATUS_NO_MORE_ENTRIES'\n");
2437 } else if (NT_STATUS_EQUAL(r_ex
.out
.result
, STATUS_MORE_ENTRIES
)) {
2438 /* Windows 2003 gets this off by one on the first run */
2439 if (r_ex
.out
.domains
->count
< 3 || r_ex
.out
.domains
->count
> 4) {
2440 torture_comment(tctx
, "EnumTrustDom didn't fill the buffer we "
2441 "asked it to (got %d, expected %d / %d == %d entries)\n",
2442 r_ex
.out
.domains
->count
,
2444 LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER
,
2445 r_ex
.in
.max_size
/ LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER
);
2447 } else if (!NT_STATUS_IS_OK(r_ex
.out
.result
)) {
2448 torture_comment(tctx
, "EnumTrustedDomainEx failed - %s\n", nt_errstr(r_ex
.out
.result
));
2452 if (domains_ex
.count
== 0) {
2453 torture_comment(tctx
, "EnumTrustDomainEx failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2457 ret
&= test_query_each_TrustDomEx(b
, tctx
, handle
, &domains_ex
);
2459 } while ((NT_STATUS_EQUAL(r_ex
.out
.result
, STATUS_MORE_ENTRIES
)));
2465 static bool test_CreateTrustedDomain(struct dcerpc_binding_handle
*b
,
2466 struct torture_context
*tctx
,
2467 struct policy_handle
*handle
,
2468 uint32_t num_trusts
)
2471 struct lsa_CreateTrustedDomain r
;
2472 struct lsa_DomainInfo trustinfo
;
2473 struct dom_sid
**domsid
;
2474 struct policy_handle
*trustdom_handle
;
2475 struct lsa_QueryTrustedDomainInfo q
;
2476 union lsa_TrustedDomainInfo
*info
= NULL
;
2479 torture_comment(tctx
, "\nTesting CreateTrustedDomain for %d domains\n", num_trusts
);
2481 if (!test_EnumTrustDom(b
, tctx
, handle
)) {
2485 if (!test_EnumTrustDomEx(b
, tctx
, handle
)) {
2489 domsid
= talloc_array(tctx
, struct dom_sid
*, num_trusts
);
2490 trustdom_handle
= talloc_array(tctx
, struct policy_handle
, num_trusts
);
2492 for (i
=0; i
< num_trusts
; i
++) {
2493 char *trust_name
= talloc_asprintf(tctx
, "torturedom%02d", i
);
2494 char *trust_sid
= talloc_asprintf(tctx
, "S-1-5-21-97398-379795-100%02d", i
);
2496 domsid
[i
] = dom_sid_parse_talloc(tctx
, trust_sid
);
2498 trustinfo
.sid
= domsid
[i
];
2499 init_lsa_String((struct lsa_String
*)&trustinfo
.name
, trust_name
);
2501 r
.in
.policy_handle
= handle
;
2502 r
.in
.info
= &trustinfo
;
2503 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2504 r
.out
.trustdom_handle
= &trustdom_handle
[i
];
2506 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateTrustedDomain_r(b
, tctx
, &r
),
2507 "CreateTrustedDomain failed");
2508 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
2509 test_DeleteTrustedDomain(b
, tctx
, handle
, trustinfo
.name
);
2510 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateTrustedDomain_r(b
, tctx
, &r
),
2511 "CreateTrustedDomain failed");
2513 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2514 torture_comment(tctx
, "CreateTrustedDomain failed - %s\n", nt_errstr(r
.out
.result
));
2518 q
.in
.trustdom_handle
= &trustdom_handle
[i
];
2519 q
.in
.level
= LSA_TRUSTED_DOMAIN_INFO_INFO_EX
;
2521 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfo_r(b
, tctx
, &q
),
2522 "QueryTrustedDomainInfo failed");
2523 if (!NT_STATUS_IS_OK(q
.out
.result
)) {
2524 torture_comment(tctx
, "QueryTrustedDomainInfo level %d failed - %s\n", q
.in
.level
, nt_errstr(q
.out
.result
));
2526 } else if (!q
.out
.info
) {
2529 if (strcmp(info
->info_ex
.netbios_name
.string
, trustinfo
.name
.string
) != 0) {
2530 torture_comment(tctx
, "QueryTrustedDomainInfo returned inconsistent short name: %s != %s\n",
2531 info
->info_ex
.netbios_name
.string
, trustinfo
.name
.string
);
2534 if (info
->info_ex
.trust_type
!= LSA_TRUST_TYPE_DOWNLEVEL
) {
2535 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
2536 trust_name
, info
->info_ex
.trust_type
, LSA_TRUST_TYPE_DOWNLEVEL
);
2539 if (info
->info_ex
.trust_attributes
!= 0) {
2540 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
2541 trust_name
, info
->info_ex
.trust_attributes
, 0);
2544 if (info
->info_ex
.trust_direction
!= LSA_TRUST_DIRECTION_OUTBOUND
) {
2545 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
2546 trust_name
, info
->info_ex
.trust_direction
, LSA_TRUST_DIRECTION_OUTBOUND
);
2553 /* now that we have some domains to look over, we can test the enum calls */
2554 if (!test_EnumTrustDom(b
, tctx
, handle
)) {
2558 if (!test_EnumTrustDomEx(b
, tctx
, handle
)) {
2562 for (i
=0; i
<num_trusts
; i
++) {
2563 if (!test_DeleteTrustedDomainBySid(b
, tctx
, handle
, domsid
[i
])) {
2571 static bool gen_authinfo_internal(TALLOC_CTX
*mem_ctx
, const char *password
,
2572 DATA_BLOB session_key
,
2573 struct lsa_TrustDomainInfoAuthInfoInternal
**_authinfo_internal
)
2575 struct lsa_TrustDomainInfoAuthInfoInternal
*authinfo_internal
;
2576 struct trustDomainPasswords auth_struct
;
2577 struct AuthenticationInformation
*auth_info_array
;
2578 size_t converted_size
;
2579 DATA_BLOB auth_blob
;
2580 enum ndr_err_code ndr_err
;
2582 authinfo_internal
= talloc_zero(mem_ctx
, struct lsa_TrustDomainInfoAuthInfoInternal
);
2583 if (authinfo_internal
== NULL
) {
2587 auth_info_array
= talloc_array(mem_ctx
,
2588 struct AuthenticationInformation
, 1);
2589 if (auth_info_array
== NULL
) {
2593 generate_random_buffer(auth_struct
.confounder
, sizeof(auth_struct
.confounder
));
2595 auth_info_array
[0].AuthType
= TRUST_AUTH_TYPE_CLEAR
;
2597 if (!convert_string_talloc(mem_ctx
, CH_UNIX
, CH_UTF16
, password
,
2599 &auth_info_array
[0].AuthInfo
.clear
.password
,
2604 auth_info_array
[0].AuthInfo
.clear
.size
= converted_size
;
2606 auth_struct
.outgoing
.count
= 1;
2607 auth_struct
.outgoing
.current
.count
= 1;
2608 auth_struct
.outgoing
.current
.array
= auth_info_array
;
2609 auth_struct
.outgoing
.previous
.count
= 0;
2610 auth_struct
.outgoing
.previous
.array
= NULL
;
2612 auth_struct
.incoming
.count
= 1;
2613 auth_struct
.incoming
.current
.count
= 1;
2614 auth_struct
.incoming
.current
.array
= auth_info_array
;
2615 auth_struct
.incoming
.previous
.count
= 0;
2616 auth_struct
.incoming
.previous
.array
= NULL
;
2619 ndr_err
= ndr_push_struct_blob(&auth_blob
, mem_ctx
, &auth_struct
,
2620 (ndr_push_flags_fn_t
)ndr_push_trustDomainPasswords
);
2621 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2625 arcfour_crypt_blob(auth_blob
.data
, auth_blob
.length
, &session_key
);
2627 authinfo_internal
->auth_blob
.size
= auth_blob
.length
;
2628 authinfo_internal
->auth_blob
.data
= auth_blob
.data
;
2630 *_authinfo_internal
= authinfo_internal
;
2635 static bool gen_authinfo(TALLOC_CTX
*mem_ctx
, const char *password
,
2636 struct lsa_TrustDomainInfoAuthInfo
**_authinfo
)
2638 struct lsa_TrustDomainInfoAuthInfo
*authinfo
;
2639 struct lsa_TrustDomainInfoBuffer
*info_buffer
;
2640 size_t converted_size
;
2642 authinfo
= talloc_zero(mem_ctx
, struct lsa_TrustDomainInfoAuthInfo
);
2643 if (authinfo
== NULL
) {
2647 info_buffer
= talloc_zero(mem_ctx
, struct lsa_TrustDomainInfoBuffer
);
2648 if (info_buffer
== NULL
) {
2652 info_buffer
->AuthType
= TRUST_AUTH_TYPE_CLEAR
;
2654 if (!convert_string_talloc(mem_ctx
, CH_UNIX
, CH_UTF16
, password
,
2656 &info_buffer
->data
.data
,
2661 info_buffer
->data
.size
= converted_size
;
2663 authinfo
->incoming_count
= 1;
2664 authinfo
->incoming_current_auth_info
= info_buffer
;
2665 authinfo
->incoming_previous_auth_info
= NULL
;
2666 authinfo
->outgoing_count
= 1;
2667 authinfo
->outgoing_current_auth_info
= info_buffer
;
2668 authinfo
->outgoing_previous_auth_info
= NULL
;
2670 *_authinfo
= authinfo
;
2675 static bool check_pw_with_ServerAuthenticate3(struct dcerpc_pipe
*p
,
2676 struct torture_context
*tctx
,
2677 uint32_t negotiate_flags
,
2678 struct cli_credentials
*machine_credentials
,
2679 struct netlogon_creds_CredentialState
**creds_out
)
2681 struct netr_ServerReqChallenge r
;
2682 struct netr_ServerAuthenticate3 a
;
2683 struct netr_Credential credentials1
, credentials2
, credentials3
;
2684 struct netlogon_creds_CredentialState
*creds
;
2685 struct samr_Password mach_password
;
2687 const char *machine_name
;
2688 const char *plain_pass
;
2689 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
2691 machine_name
= cli_credentials_get_workstation(machine_credentials
);
2692 plain_pass
= cli_credentials_get_password(machine_credentials
);
2694 r
.in
.server_name
= NULL
;
2695 r
.in
.computer_name
= machine_name
;
2696 r
.in
.credentials
= &credentials1
;
2697 r
.out
.return_credentials
= &credentials2
;
2699 generate_random_buffer(credentials1
.data
, sizeof(credentials1
.data
));
2701 torture_assert_ntstatus_ok(tctx
, dcerpc_netr_ServerReqChallenge_r(b
, tctx
, &r
),
2702 "ServerReqChallenge failed");
2703 torture_assert_ntstatus_ok(tctx
, r
.out
.result
, "ServerReqChallenge failed");
2705 E_md4hash(plain_pass
, mach_password
.hash
);
2707 a
.in
.server_name
= NULL
;
2708 a
.in
.account_name
= talloc_asprintf(tctx
, "%s$", machine_name
);
2709 a
.in
.secure_channel_type
= cli_credentials_get_secure_channel_type(machine_credentials
);
2710 a
.in
.computer_name
= machine_name
;
2711 a
.in
.negotiate_flags
= &negotiate_flags
;
2712 a
.in
.credentials
= &credentials3
;
2713 a
.out
.return_credentials
= &credentials3
;
2714 a
.out
.negotiate_flags
= &negotiate_flags
;
2717 creds
= netlogon_creds_client_init(tctx
, a
.in
.account_name
,
2719 a
.in
.secure_channel_type
,
2720 &credentials1
, &credentials2
,
2721 &mach_password
, &credentials3
,
2724 torture_assert(tctx
, creds
!= NULL
, "memory allocation");
2726 torture_assert_ntstatus_ok(tctx
, dcerpc_netr_ServerAuthenticate3_r(b
, tctx
, &a
),
2727 "ServerAuthenticate3 failed");
2728 if (!NT_STATUS_IS_OK(a
.out
.result
)) {
2729 if (!NT_STATUS_EQUAL(a
.out
.result
, NT_STATUS_ACCESS_DENIED
)) {
2730 torture_assert_ntstatus_ok(tctx
, a
.out
.result
,
2731 "ServerAuthenticate3 failed");
2735 torture_assert(tctx
, netlogon_creds_client_check(creds
, &credentials3
), "Credential chaining failed");
2737 /* Prove that requesting a challenge again won't break it */
2738 torture_assert_ntstatus_ok(tctx
, dcerpc_netr_ServerReqChallenge_r(b
, tctx
, &r
),
2739 "ServerReqChallenge failed");
2740 torture_assert_ntstatus_ok(tctx
, r
.out
.result
, "ServerReqChallenge failed");
2746 static bool check_dom_trust_pw(struct dcerpc_pipe
*p
,
2747 struct torture_context
*tctx
,
2748 const char *trusted_dom_name
,
2749 const char *password
)
2751 struct cli_credentials
*credentials
;
2753 struct netlogon_creds_CredentialState
*creds
;
2754 struct dcerpc_pipe
*pipe
;
2758 credentials
= cli_credentials_init(tctx
);
2759 if (credentials
== NULL
) {
2763 dummy
= talloc_asprintf(tctx
, "%s$", trusted_dom_name
);
2764 if (dummy
== NULL
) {
2768 cli_credentials_set_username(credentials
, dummy
, CRED_SPECIFIED
);
2769 cli_credentials_set_password(credentials
, password
, CRED_SPECIFIED
);
2770 cli_credentials_set_workstation(credentials
,
2771 trusted_dom_name
, CRED_SPECIFIED
);
2772 cli_credentials_set_secure_channel_type(credentials
, SEC_CHAN_DOMAIN
);
2774 status
= dcerpc_pipe_connect_b(tctx
, &pipe
, p
->binding
,
2775 &ndr_table_netlogon
,
2776 cli_credentials_init_anon(tctx
),
2777 tctx
->ev
, tctx
->lp_ctx
);
2778 if (!NT_STATUS_IS_OK(status
)) {
2779 torture_comment(tctx
, "dcerpc_pipe_connect_b failed.\n");
2783 ok
= check_pw_with_ServerAuthenticate3(pipe
, tctx
,
2784 NETLOGON_NEG_AUTH2_ADS_FLAGS
,
2785 credentials
, &creds
);
2791 static bool test_CreateTrustedDomainEx_common(struct dcerpc_pipe
*p
,
2792 struct torture_context
*tctx
,
2793 struct policy_handle
*handle
,
2794 uint32_t num_trusts
,
2799 struct lsa_CreateTrustedDomainEx r
;
2800 struct lsa_CreateTrustedDomainEx2 r2
;
2801 struct lsa_TrustDomainInfoInfoEx trustinfo
;
2802 struct lsa_TrustDomainInfoAuthInfoInternal
*authinfo_internal
;
2803 struct lsa_TrustDomainInfoAuthInfo
*authinfo
;
2804 struct dom_sid
**domsid
;
2805 struct policy_handle
*trustdom_handle
;
2806 struct lsa_QueryTrustedDomainInfo q
;
2807 union lsa_TrustedDomainInfo
*info
= NULL
;
2808 DATA_BLOB session_key
;
2810 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
2813 torture_comment(tctx
, "\nTesting CreateTrustedDomainEx2 for %d domains\n", num_trusts
);
2815 torture_comment(tctx
, "\nTesting CreateTrustedDomainEx for %d domains\n", num_trusts
);
2818 domsid
= talloc_array(tctx
, struct dom_sid
*, num_trusts
);
2819 trustdom_handle
= talloc_array(tctx
, struct policy_handle
, num_trusts
);
2821 status
= dcerpc_fetch_session_key(p
, &session_key
);
2822 if (!NT_STATUS_IS_OK(status
)) {
2823 torture_comment(tctx
, "dcerpc_fetch_session_key failed - %s\n", nt_errstr(status
));
2827 for (i
=0; i
< num_trusts
; i
++) {
2828 char *trust_name
= talloc_asprintf(tctx
, "torturedom%02d", i
);
2829 char *trust_name_dns
= talloc_asprintf(tctx
, "torturedom%02d.samba.example.com", i
);
2830 char *trust_sid
= talloc_asprintf(tctx
, "S-1-5-21-97398-379795-100%02d", i
);
2832 domsid
[i
] = dom_sid_parse_talloc(tctx
, trust_sid
);
2834 trustinfo
.sid
= domsid
[i
];
2835 trustinfo
.netbios_name
.string
= trust_name
;
2836 trustinfo
.domain_name
.string
= trust_name_dns
;
2838 /* Create inbound, some outbound, and some
2839 * bi-directional trusts in a repeating pattern based
2842 /* 1 == inbound, 2 == outbound, 3 == both */
2843 trustinfo
.trust_direction
= (i
% 3) + 1;
2845 /* Try different trust types too */
2847 /* 1 == downlevel (NT4), 2 == uplevel (ADS), 3 == MIT (kerberos but not AD) */
2848 trustinfo
.trust_type
= (((i
/ 3) + 1) % 3) + 1;
2850 trustinfo
.trust_attributes
= LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION
;
2852 if (!gen_authinfo_internal(tctx
, TRUSTPW
, session_key
, &authinfo_internal
)) {
2853 torture_comment(tctx
, "gen_authinfo_internal failed");
2857 if (!gen_authinfo(tctx
, TRUSTPW
, &authinfo
)) {
2858 torture_comment(tctx
, "gen_authinfonfo failed");
2864 r2
.in
.policy_handle
= handle
;
2865 r2
.in
.info
= &trustinfo
;
2866 r2
.in
.auth_info_internal
= authinfo_internal
;
2867 r2
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2868 r2
.out
.trustdom_handle
= &trustdom_handle
[i
];
2870 torture_assert_ntstatus_ok(tctx
,
2871 dcerpc_lsa_CreateTrustedDomainEx2_r(b
, tctx
, &r2
),
2872 "CreateTrustedDomainEx2 failed");
2874 status
= r2
.out
.result
;
2877 r
.in
.policy_handle
= handle
;
2878 r
.in
.info
= &trustinfo
;
2879 r
.in
.auth_info
= authinfo
;
2880 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2881 r
.out
.trustdom_handle
= &trustdom_handle
[i
];
2883 torture_assert_ntstatus_ok(tctx
,
2884 dcerpc_lsa_CreateTrustedDomainEx_r(b
, tctx
, &r
),
2885 "CreateTrustedDomainEx failed");
2887 status
= r
.out
.result
;
2890 if (NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
2891 test_DeleteTrustedDomain(b
, tctx
, handle
, trustinfo
.netbios_name
);
2893 torture_assert_ntstatus_ok(tctx
,
2894 dcerpc_lsa_CreateTrustedDomainEx2_r(b
, tctx
, &r2
),
2895 "CreateTrustedDomainEx2 failed");
2896 status
= r2
.out
.result
;
2898 torture_assert_ntstatus_ok(tctx
,
2899 dcerpc_lsa_CreateTrustedDomainEx_r(b
, tctx
, &r
),
2900 "CreateTrustedDomainEx2 failed");
2901 status
= r
.out
.result
;
2904 if (!NT_STATUS_IS_OK(status
)) {
2905 torture_comment(tctx
, "CreateTrustedDomainEx failed2 - %s\n", nt_errstr(status
));
2908 /* For outbound and MIT trusts there is no trust account */
2909 if (trustinfo
.trust_direction
!= 2 &&
2910 trustinfo
.trust_type
!= 3) {
2912 if (torture_setting_bool(tctx
, "samba3", false) ||
2913 torture_setting_bool(tctx
, "samba4", false)) {
2914 torture_comment(tctx
, "skipping trusted domain auth tests against samba");
2916 if (check_dom_trust_pw(p
, tctx
, trust_name
,
2918 torture_comment(tctx
, "Password check passed unexpectedly\n");
2921 if (!check_dom_trust_pw(p
, tctx
, trust_name
,
2923 torture_comment(tctx
, "Password check failed\n");
2929 q
.in
.trustdom_handle
= &trustdom_handle
[i
];
2930 q
.in
.level
= LSA_TRUSTED_DOMAIN_INFO_INFO_EX
;
2932 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfo_r(b
, tctx
, &q
),
2933 "QueryTrustedDomainInfo failed");
2934 if (!NT_STATUS_IS_OK(q
.out
.result
)) {
2935 torture_comment(tctx
, "QueryTrustedDomainInfo level 1 failed - %s\n", nt_errstr(q
.out
.result
));
2937 } else if (!q
.out
.info
) {
2938 torture_comment(tctx
, "QueryTrustedDomainInfo level 1 failed to return an info pointer\n");
2941 if (strcmp(info
->info_ex
.netbios_name
.string
, trustinfo
.netbios_name
.string
) != 0) {
2942 torture_comment(tctx
, "QueryTrustedDomainInfo returned inconsistent short name: %s != %s\n",
2943 info
->info_ex
.netbios_name
.string
, trustinfo
.netbios_name
.string
);
2946 if (info
->info_ex
.trust_type
!= trustinfo
.trust_type
) {
2947 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
2948 trust_name
, info
->info_ex
.trust_type
, trustinfo
.trust_type
);
2951 if (info
->info_ex
.trust_attributes
!= LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION
) {
2952 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
2953 trust_name
, info
->info_ex
.trust_attributes
, LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION
);
2956 if (info
->info_ex
.trust_direction
!= trustinfo
.trust_direction
) {
2957 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
2958 trust_name
, info
->info_ex
.trust_direction
, trustinfo
.trust_direction
);
2965 /* now that we have some domains to look over, we can test the enum calls */
2966 if (!test_EnumTrustDom(b
, tctx
, handle
)) {
2967 torture_comment(tctx
, "test_EnumTrustDom failed\n");
2971 if (!test_EnumTrustDomEx(b
, tctx
, handle
)) {
2972 torture_comment(tctx
, "test_EnumTrustDomEx failed\n");
2976 for (i
=0; i
<num_trusts
; i
++) {
2977 if (!test_DeleteTrustedDomainBySid(b
, tctx
, handle
, domsid
[i
])) {
2978 torture_comment(tctx
, "test_DeleteTrustedDomainBySid failed\n");
2986 static bool test_CreateTrustedDomainEx2(struct dcerpc_pipe
*p
,
2987 struct torture_context
*tctx
,
2988 struct policy_handle
*handle
,
2989 uint32_t num_trusts
)
2991 return test_CreateTrustedDomainEx_common(p
, tctx
, handle
, num_trusts
, true);
2994 static bool test_CreateTrustedDomainEx(struct dcerpc_pipe
*p
,
2995 struct torture_context
*tctx
,
2996 struct policy_handle
*handle
,
2997 uint32_t num_trusts
)
2999 return test_CreateTrustedDomainEx_common(p
, tctx
, handle
, num_trusts
, false);
3002 static bool test_QueryDomainInfoPolicy(struct dcerpc_binding_handle
*b
,
3003 struct torture_context
*tctx
,
3004 struct policy_handle
*handle
)
3006 struct lsa_QueryDomainInformationPolicy r
;
3007 union lsa_DomainInformationPolicy
*info
= NULL
;
3011 if (torture_setting_bool(tctx
, "samba3", false)) {
3012 torture_skip(tctx
, "skipping QueryDomainInformationPolicy test\n");
3015 torture_comment(tctx
, "\nTesting QueryDomainInformationPolicy\n");
3018 r
.in
.handle
= handle
;
3022 torture_comment(tctx
, "\nTrying QueryDomainInformationPolicy level %d\n", i
);
3024 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryDomainInformationPolicy_r(b
, tctx
, &r
),
3025 "QueryDomainInformationPolicy failed");
3027 /* If the server does not support EFS, then this is the correct return */
3028 if (i
== LSA_DOMAIN_INFO_POLICY_EFS
&& NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
3030 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
3031 torture_comment(tctx
, "QueryDomainInformationPolicy failed - %s\n", nt_errstr(r
.out
.result
));
3041 static bool test_QueryInfoPolicyCalls( bool version2
,
3042 struct dcerpc_binding_handle
*b
,
3043 struct torture_context
*tctx
,
3044 struct policy_handle
*handle
)
3046 struct lsa_QueryInfoPolicy r
;
3047 union lsa_PolicyInformation
*info
= NULL
;
3050 const char *call
= talloc_asprintf(tctx
, "QueryInfoPolicy%s", version2
? "2":"");
3052 torture_comment(tctx
, "\nTesting %s\n", call
);
3054 if (version2
&& torture_setting_bool(tctx
, "samba3", false)) {
3055 torture_skip(tctx
, "skipping QueryInfoPolicy2 tests\n");
3058 for (i
=1;i
<=14;i
++) {
3059 r
.in
.handle
= handle
;
3063 torture_comment(tctx
, "\nTrying %s level %d\n", call
, i
);
3066 /* We can perform the cast, because both types are
3067 structurally equal */
3068 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryInfoPolicy2_r(b
, tctx
,
3069 (struct lsa_QueryInfoPolicy2
*) &r
),
3070 "QueryInfoPolicy2 failed");
3072 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryInfoPolicy_r(b
, tctx
, &r
),
3073 "QueryInfoPolicy2 failed");
3076 case LSA_POLICY_INFO_MOD
:
3077 case LSA_POLICY_INFO_AUDIT_FULL_SET
:
3078 case LSA_POLICY_INFO_AUDIT_FULL_QUERY
:
3079 if (!NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_INVALID_PARAMETER
)) {
3080 torture_comment(tctx
, "Server should have failed level %u: %s\n", i
, nt_errstr(r
.out
.result
));
3084 case LSA_POLICY_INFO_DOMAIN
:
3085 case LSA_POLICY_INFO_ACCOUNT_DOMAIN
:
3086 case LSA_POLICY_INFO_REPLICA
:
3087 case LSA_POLICY_INFO_QUOTA
:
3088 case LSA_POLICY_INFO_ROLE
:
3089 case LSA_POLICY_INFO_AUDIT_LOG
:
3090 case LSA_POLICY_INFO_AUDIT_EVENTS
:
3091 case LSA_POLICY_INFO_PD
:
3092 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
3093 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(r
.out
.result
));
3097 case LSA_POLICY_INFO_L_ACCOUNT_DOMAIN
:
3098 case LSA_POLICY_INFO_DNS_INT
:
3099 case LSA_POLICY_INFO_DNS
:
3100 if (torture_setting_bool(tctx
, "samba3", false)) {
3101 /* Other levels not implemented yet */
3102 if (!NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_INVALID_INFO_CLASS
)) {
3103 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(r
.out
.result
));
3106 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
3107 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(r
.out
.result
));
3112 if (torture_setting_bool(tctx
, "samba4", false)) {
3113 /* Other levels not implemented yet */
3114 if (!NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_INVALID_INFO_CLASS
)) {
3115 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(r
.out
.result
));
3118 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
3119 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(r
.out
.result
));
3125 if (NT_STATUS_IS_OK(r
.out
.result
) && (i
== LSA_POLICY_INFO_DNS
3126 || i
== LSA_POLICY_INFO_DNS_INT
)) {
3127 /* Let's look up some of these names */
3129 struct lsa_TransNameArray tnames
;
3131 tnames
.names
= talloc_zero_array(tctx
, struct lsa_TranslatedName
, tnames
.count
);
3132 tnames
.names
[0].name
.string
= info
->dns
.name
.string
;
3133 tnames
.names
[0].sid_type
= SID_NAME_DOMAIN
;
3134 tnames
.names
[1].name
.string
= info
->dns
.dns_domain
.string
;
3135 tnames
.names
[1].sid_type
= SID_NAME_DOMAIN
;
3136 tnames
.names
[2].name
.string
= talloc_asprintf(tctx
, "%s\\", info
->dns
.name
.string
);
3137 tnames
.names
[2].sid_type
= SID_NAME_DOMAIN
;
3138 tnames
.names
[3].name
.string
= talloc_asprintf(tctx
, "%s\\", info
->dns
.dns_domain
.string
);
3139 tnames
.names
[3].sid_type
= SID_NAME_DOMAIN
;
3140 tnames
.names
[4].name
.string
= talloc_asprintf(tctx
, "%s\\guest", info
->dns
.name
.string
);
3141 tnames
.names
[4].sid_type
= SID_NAME_USER
;
3142 tnames
.names
[5].name
.string
= talloc_asprintf(tctx
, "%s\\krbtgt", info
->dns
.name
.string
);
3143 tnames
.names
[5].sid_type
= SID_NAME_USER
;
3144 tnames
.names
[6].name
.string
= talloc_asprintf(tctx
, "%s\\guest", info
->dns
.dns_domain
.string
);
3145 tnames
.names
[6].sid_type
= SID_NAME_USER
;
3146 tnames
.names
[7].name
.string
= talloc_asprintf(tctx
, "%s\\krbtgt", info
->dns
.dns_domain
.string
);
3147 tnames
.names
[7].sid_type
= SID_NAME_USER
;
3148 tnames
.names
[8].name
.string
= talloc_asprintf(tctx
, "krbtgt@%s", info
->dns
.name
.string
);
3149 tnames
.names
[8].sid_type
= SID_NAME_USER
;
3150 tnames
.names
[9].name
.string
= talloc_asprintf(tctx
, "krbtgt@%s", info
->dns
.dns_domain
.string
);
3151 tnames
.names
[9].sid_type
= SID_NAME_USER
;
3152 tnames
.names
[10].name
.string
= talloc_asprintf(tctx
, "%s\\"TEST_MACHINENAME
"$", info
->dns
.name
.string
);
3153 tnames
.names
[10].sid_type
= SID_NAME_USER
;
3154 tnames
.names
[11].name
.string
= talloc_asprintf(tctx
, "%s\\"TEST_MACHINENAME
"$", info
->dns
.dns_domain
.string
);
3155 tnames
.names
[11].sid_type
= SID_NAME_USER
;
3156 tnames
.names
[12].name
.string
= talloc_asprintf(tctx
, TEST_MACHINENAME
"$@%s", info
->dns
.name
.string
);
3157 tnames
.names
[12].sid_type
= SID_NAME_USER
;
3158 tnames
.names
[13].name
.string
= talloc_asprintf(tctx
, TEST_MACHINENAME
"$@%s", info
->dns
.dns_domain
.string
);
3159 tnames
.names
[13].sid_type
= SID_NAME_USER
;
3160 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
3168 static bool test_QueryInfoPolicy(struct dcerpc_binding_handle
*b
,
3169 struct torture_context
*tctx
,
3170 struct policy_handle
*handle
)
3172 return test_QueryInfoPolicyCalls(false, b
, tctx
, handle
);
3175 static bool test_QueryInfoPolicy2(struct dcerpc_binding_handle
*b
,
3176 struct torture_context
*tctx
,
3177 struct policy_handle
*handle
)
3179 return test_QueryInfoPolicyCalls(true, b
, tctx
, handle
);
3182 static bool test_GetUserName(struct dcerpc_binding_handle
*b
,
3183 struct torture_context
*tctx
)
3185 struct lsa_GetUserName r
;
3187 struct lsa_String
*authority_name_p
= NULL
;
3188 struct lsa_String
*account_name_p
= NULL
;
3190 torture_comment(tctx
, "\nTesting GetUserName\n");
3192 r
.in
.system_name
= "\\";
3193 r
.in
.account_name
= &account_name_p
;
3194 r
.in
.authority_name
= NULL
;
3195 r
.out
.account_name
= &account_name_p
;
3197 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_GetUserName_r(b
, tctx
, &r
),
3198 "GetUserName failed");
3200 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
3201 torture_comment(tctx
, "GetUserName failed - %s\n", nt_errstr(r
.out
.result
));
3205 account_name_p
= NULL
;
3206 r
.in
.account_name
= &account_name_p
;
3207 r
.in
.authority_name
= &authority_name_p
;
3208 r
.out
.account_name
= &account_name_p
;
3210 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_GetUserName_r(b
, tctx
, &r
),
3211 "GetUserName failed");
3213 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
3214 torture_comment(tctx
, "GetUserName failed - %s\n", nt_errstr(r
.out
.result
));
3221 static bool test_GetUserName_fail(struct dcerpc_binding_handle
*b
,
3222 struct torture_context
*tctx
)
3224 struct lsa_GetUserName r
;
3225 struct lsa_String
*account_name_p
= NULL
;
3228 torture_comment(tctx
, "\nTesting GetUserName_fail\n");
3230 r
.in
.system_name
= "\\";
3231 r
.in
.account_name
= &account_name_p
;
3232 r
.in
.authority_name
= NULL
;
3233 r
.out
.account_name
= &account_name_p
;
3235 status
= dcerpc_lsa_GetUserName_r(b
, tctx
, &r
);
3236 if (!NT_STATUS_IS_OK(status
)) {
3237 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
3238 torture_comment(tctx
,
3239 "GetUserName correctly returned with "
3245 torture_assert_ntstatus_equal(tctx
,
3247 NT_STATUS_ACCESS_DENIED
,
3248 "GetUserName return value should "
3249 "be ACCESS_DENIED");
3253 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
3254 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_ACCESS_DENIED
) ||
3255 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
3256 torture_comment(tctx
,
3257 "GetUserName correctly returned with "
3259 nt_errstr(r
.out
.result
));
3264 torture_assert_ntstatus_equal(tctx
,
3267 "GetUserName return value should be "
3273 bool test_lsa_Close(struct dcerpc_binding_handle
*b
,
3274 struct torture_context
*tctx
,
3275 struct policy_handle
*handle
)
3278 struct policy_handle handle2
;
3280 torture_comment(tctx
, "\nTesting Close\n");
3282 r
.in
.handle
= handle
;
3283 r
.out
.handle
= &handle2
;
3285 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_Close_r(b
, tctx
, &r
),
3287 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
3290 torture_assert_ntstatus_equal(tctx
, dcerpc_lsa_Close_r(b
, tctx
, &r
),
3291 NT_STATUS_RPC_SS_CONTEXT_MISMATCH
, "Close should failed");
3293 torture_comment(tctx
, "\n");
3298 bool torture_rpc_lsa(struct torture_context
*tctx
)
3301 struct dcerpc_pipe
*p
;
3303 struct policy_handle
*handle
= NULL
;
3304 struct test_join
*join
= NULL
;
3305 struct cli_credentials
*machine_creds
;
3306 struct dcerpc_binding_handle
*b
;
3307 enum dcerpc_transport_t transport
;
3309 status
= torture_rpc_connection(tctx
, &p
, &ndr_table_lsarpc
);
3310 if (!NT_STATUS_IS_OK(status
)) {
3313 b
= p
->binding_handle
;
3314 transport
= dcerpc_binding_get_transport(p
->binding
);
3316 /* Test lsaLookupSids3 and lsaLookupNames4 over tcpip */
3317 if (transport
== NCACN_IP_TCP
) {
3318 if (!test_OpenPolicy_fail(b
, tctx
)) {
3322 if (!test_OpenPolicy2_fail(b
, tctx
)) {
3326 if (!test_many_LookupSids(p
, tctx
, handle
)) {
3333 if (!test_OpenPolicy(b
, tctx
)) {
3337 if (!test_lsa_OpenPolicy2(b
, tctx
, &handle
)) {
3342 join
= torture_join_domain(tctx
, TEST_MACHINENAME
, ACB_WSTRUST
, &machine_creds
);
3347 if (!test_LookupSids_async(b
, tctx
, handle
)) {
3351 if (!test_QueryDomainInfoPolicy(b
, tctx
, handle
)) {
3355 if (!test_CreateSecret(p
, tctx
, handle
)) {
3359 if (!test_QueryInfoPolicy(b
, tctx
, handle
)) {
3363 if (!test_QueryInfoPolicy2(b
, tctx
, handle
)) {
3367 if (!test_Delete(b
, tctx
, handle
)) {
3371 if (!test_many_LookupSids(p
, tctx
, handle
)) {
3375 if (!test_lsa_Close(b
, tctx
, handle
)) {
3379 torture_leave_domain(tctx
, join
);
3382 if (!test_many_LookupSids(p
, tctx
, handle
)) {
3387 if (!test_GetUserName(b
, tctx
)) {
3394 bool torture_rpc_lsa_get_user(struct torture_context
*tctx
)
3397 struct dcerpc_pipe
*p
;
3399 struct dcerpc_binding_handle
*b
;
3400 enum dcerpc_transport_t transport
;
3402 status
= torture_rpc_connection(tctx
, &p
, &ndr_table_lsarpc
);
3403 if (!NT_STATUS_IS_OK(status
)) {
3406 b
= p
->binding_handle
;
3407 transport
= dcerpc_binding_get_transport(p
->binding
);
3409 if (transport
== NCACN_IP_TCP
) {
3410 if (!test_GetUserName_fail(b
, tctx
)) {
3416 if (!test_GetUserName(b
, tctx
)) {
3423 static bool testcase_LookupNames(struct torture_context
*tctx
,
3424 struct dcerpc_pipe
*p
)
3427 struct policy_handle
*handle
;
3428 struct lsa_TransNameArray tnames
;
3429 struct lsa_TransNameArray2 tnames2
;
3430 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
3431 enum dcerpc_transport_t transport
= dcerpc_binding_get_transport(p
->binding
);
3433 if (transport
!= NCACN_NP
&& transport
!= NCALRPC
) {
3434 torture_comment(tctx
, "testcase_LookupNames is only available "
3435 "over NCACN_NP or NCALRPC");
3439 if (!test_OpenPolicy(b
, tctx
)) {
3443 if (!test_lsa_OpenPolicy2(b
, tctx
, &handle
)) {
3452 tnames
.names
= talloc_array(tctx
, struct lsa_TranslatedName
, tnames
.count
);
3453 ZERO_STRUCT(tnames
.names
[0]);
3454 tnames
.names
[0].name
.string
= "BUILTIN";
3455 tnames
.names
[0].sid_type
= SID_NAME_DOMAIN
;
3457 if (!test_LookupNames(b
, tctx
, handle
, &tnames
)) {
3462 tnames2
.names
= talloc_array(tctx
, struct lsa_TranslatedName2
, tnames2
.count
);
3463 ZERO_STRUCT(tnames2
.names
[0]);
3464 tnames2
.names
[0].name
.string
= "BUILTIN";
3465 tnames2
.names
[0].sid_type
= SID_NAME_DOMAIN
;
3467 if (!test_LookupNames2(b
, tctx
, handle
, &tnames2
, true)) {
3471 if (!test_LookupNames3(b
, tctx
, handle
, &tnames2
, true)) {
3475 if (!test_LookupNames_wellknown(b
, tctx
, handle
)) {
3479 if (!test_LookupNames_NULL(b
, tctx
, handle
)) {
3483 if (!test_LookupNames_bogus(b
, tctx
, handle
)) {
3487 if (!test_lsa_Close(b
, tctx
, handle
)) {
3494 struct torture_suite
*torture_rpc_lsa_lookup_names(TALLOC_CTX
*mem_ctx
)
3496 struct torture_suite
*suite
;
3497 struct torture_rpc_tcase
*tcase
;
3499 suite
= torture_suite_create(mem_ctx
, "lsa.lookupnames");
3501 tcase
= torture_suite_add_rpc_iface_tcase(suite
, "lsa",
3503 torture_rpc_tcase_add_test(tcase
, "LookupNames",
3504 testcase_LookupNames
);
3509 struct lsa_trustdom_state
{
3510 uint32_t num_trusts
;
3513 static bool testcase_TrustedDomains(struct torture_context
*tctx
,
3514 struct dcerpc_pipe
*p
,
3518 struct policy_handle
*handle
;
3519 struct lsa_trustdom_state
*state
=
3520 talloc_get_type_abort(data
, struct lsa_trustdom_state
);
3521 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
3522 enum dcerpc_transport_t transport
= dcerpc_binding_get_transport(p
->binding
);
3524 if (transport
!= NCACN_NP
&& transport
!= NCALRPC
) {
3525 torture_comment(tctx
, "testcase_TrustedDomains is only available "
3526 "over NCACN_NP or NCALRPC");
3530 torture_comment(tctx
, "Testing %d domains\n", state
->num_trusts
);
3532 if (!test_OpenPolicy(b
, tctx
)) {
3536 if (!test_lsa_OpenPolicy2(b
, tctx
, &handle
)) {
3544 if (!test_CreateTrustedDomain(b
, tctx
, handle
, state
->num_trusts
)) {
3548 if (!test_CreateTrustedDomainEx(p
, tctx
, handle
, state
->num_trusts
)) {
3552 if (!test_CreateTrustedDomainEx2(p
, tctx
, handle
, state
->num_trusts
)) {
3556 if (!test_lsa_Close(b
, tctx
, handle
)) {
3563 struct torture_suite
*torture_rpc_lsa_trusted_domains(TALLOC_CTX
*mem_ctx
)
3565 struct torture_suite
*suite
;
3566 struct torture_rpc_tcase
*tcase
;
3567 struct lsa_trustdom_state
*state
;
3569 state
= talloc(mem_ctx
, struct lsa_trustdom_state
);
3571 state
->num_trusts
= 12;
3573 suite
= torture_suite_create(mem_ctx
, "lsa.trusted.domains");
3575 tcase
= torture_suite_add_rpc_iface_tcase(suite
, "lsa",
3577 torture_rpc_tcase_add_test_ex(tcase
, "TrustedDomains",
3578 testcase_TrustedDomains
,
3584 static bool testcase_Privileges(struct torture_context
*tctx
,
3585 struct dcerpc_pipe
*p
)
3587 struct policy_handle
*handle
;
3588 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
3589 enum dcerpc_transport_t transport
= dcerpc_binding_get_transport(p
->binding
);
3591 if (transport
!= NCACN_NP
&& transport
!= NCALRPC
) {
3592 torture_skip(tctx
, "testcase_Privileges is only available "
3593 "over NCACN_NP or NCALRPC");
3596 if (!test_OpenPolicy(b
, tctx
)) {
3600 if (!test_lsa_OpenPolicy2(b
, tctx
, &handle
)) {
3608 if (!test_CreateAccount(b
, tctx
, handle
)) {
3612 if (!test_EnumAccounts(b
, tctx
, handle
)) {
3616 if (!test_EnumPrivs(b
, tctx
, handle
)) {
3620 if (!test_lsa_Close(b
, tctx
, handle
)) {
3628 struct torture_suite
*torture_rpc_lsa_privileges(TALLOC_CTX
*mem_ctx
)
3630 struct torture_suite
*suite
;
3631 struct torture_rpc_tcase
*tcase
;
3633 suite
= torture_suite_create(mem_ctx
, "lsa.privileges");
3635 tcase
= torture_suite_add_rpc_iface_tcase(suite
, "lsa",
3637 torture_rpc_tcase_add_test(tcase
, "Privileges",
3638 testcase_Privileges
);