2 Unix SMB/CIFS implementation.
3 test suite for lsa rpc operations
5 Copyright (C) Andrew Tridgell 2003
6 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2004-2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "torture/torture.h"
24 #include "librpc/gen_ndr/ndr_lsa_c.h"
25 #include "librpc/gen_ndr/netlogon.h"
26 #include "librpc/gen_ndr/ndr_drsblobs.h"
27 #include "librpc/gen_ndr/ndr_netlogon_c.h"
28 #include "lib/events/events.h"
29 #include "libcli/security/security.h"
30 #include "libcli/auth/libcli_auth.h"
31 #include "torture/rpc/torture_rpc.h"
32 #include "param/param.h"
33 #include "../lib/crypto/crypto.h"
34 #define TEST_MACHINENAME "lsatestmach"
35 #define TRUSTPW "12345678"
37 static void init_lsa_String(struct lsa_String
*name
, const char *s
)
42 static bool test_OpenPolicy(struct dcerpc_binding_handle
*b
,
43 struct torture_context
*tctx
)
45 struct lsa_ObjectAttribute attr
;
46 struct policy_handle handle
;
47 struct lsa_QosInfo qos
;
48 struct lsa_OpenPolicy r
;
49 uint16_t system_name
= '\\';
51 torture_comment(tctx
, "\nTesting OpenPolicy\n");
54 qos
.impersonation_level
= 2;
56 qos
.effective_only
= 0;
60 attr
.object_name
= NULL
;
65 r
.in
.system_name
= &system_name
;
67 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
68 r
.out
.handle
= &handle
;
70 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenPolicy_r(b
, tctx
, &r
),
72 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
73 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_ACCESS_DENIED
) ||
74 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
75 torture_comment(tctx
, "not considering %s to be an error\n",
76 nt_errstr(r
.out
.result
));
79 torture_comment(tctx
, "OpenPolicy failed - %s\n",
80 nt_errstr(r
.out
.result
));
88 bool test_lsa_OpenPolicy2_ex(struct dcerpc_binding_handle
*b
,
89 struct torture_context
*tctx
,
90 struct policy_handle
**handle
,
91 NTSTATUS expected_status
)
93 struct lsa_ObjectAttribute attr
;
94 struct lsa_QosInfo qos
;
95 struct lsa_OpenPolicy2 r
;
98 torture_comment(tctx
, "\nTesting OpenPolicy2\n");
100 *handle
= talloc(tctx
, struct policy_handle
);
106 qos
.impersonation_level
= 2;
107 qos
.context_mode
= 1;
108 qos
.effective_only
= 0;
111 attr
.root_dir
= NULL
;
112 attr
.object_name
= NULL
;
114 attr
.sec_desc
= NULL
;
117 r
.in
.system_name
= "\\";
119 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
120 r
.out
.handle
= *handle
;
122 status
= dcerpc_lsa_OpenPolicy2_r(b
, tctx
, &r
);
123 torture_assert_ntstatus_equal(tctx
, status
, expected_status
,
124 "OpenPolicy2 failed");
125 if (!NT_STATUS_IS_OK(expected_status
)) {
128 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
129 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_ACCESS_DENIED
) ||
130 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
131 torture_comment(tctx
, "not considering %s to be an error\n",
132 nt_errstr(r
.out
.result
));
133 talloc_free(*handle
);
137 torture_comment(tctx
, "OpenPolicy2 failed - %s\n",
138 nt_errstr(r
.out
.result
));
146 bool test_lsa_OpenPolicy2(struct dcerpc_binding_handle
*b
,
147 struct torture_context
*tctx
,
148 struct policy_handle
**handle
)
150 return test_lsa_OpenPolicy2_ex(b
, tctx
, handle
, NT_STATUS_OK
);
153 static bool test_LookupNames(struct dcerpc_binding_handle
*b
,
154 struct torture_context
*tctx
,
155 struct policy_handle
*handle
,
156 struct lsa_TransNameArray
*tnames
)
158 struct lsa_LookupNames r
;
159 struct lsa_TransSidArray sids
;
160 struct lsa_RefDomainList
*domains
= NULL
;
161 struct lsa_String
*names
;
166 torture_comment(tctx
, "\nTesting LookupNames with %d names\n", tnames
->count
);
174 input_idx
= talloc_array(tctx
, uint32_t, tnames
->count
);
175 names
= talloc_array(tctx
, struct lsa_String
, tnames
->count
);
177 for (i
=0;i
<tnames
->count
;i
++) {
178 if (tnames
->names
[i
].sid_type
!= SID_NAME_UNKNOWN
) {
179 init_lsa_String(&names
[r
.in
.num_names
], tnames
->names
[i
].name
.string
);
180 input_idx
[r
.in
.num_names
] = i
;
185 r
.in
.handle
= handle
;
190 r
.out
.count
= &count
;
192 r
.out
.domains
= &domains
;
194 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames_r(b
, tctx
, &r
),
195 "LookupNames failed");
196 if (NT_STATUS_EQUAL(r
.out
.result
, STATUS_SOME_UNMAPPED
) ||
197 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NONE_MAPPED
)) {
198 for (i
=0;i
< r
.in
.num_names
;i
++) {
199 if (i
< count
&& sids
.sids
[i
].sid_type
== SID_NAME_UNKNOWN
) {
200 torture_comment(tctx
, "LookupName of %s was unmapped\n",
201 tnames
->names
[i
].name
.string
);
202 } else if (i
>=count
) {
203 torture_comment(tctx
, "LookupName of %s failed to return a result\n",
204 tnames
->names
[i
].name
.string
);
207 torture_comment(tctx
, "LookupNames failed - %s\n",
208 nt_errstr(r
.out
.result
));
210 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
211 torture_comment(tctx
, "LookupNames failed - %s\n",
212 nt_errstr(r
.out
.result
));
216 for (i
=0;i
< r
.in
.num_names
;i
++) {
218 if (sids
.sids
[i
].sid_type
!= tnames
->names
[input_idx
[i
]].sid_type
) {
219 torture_comment(tctx
, "LookupName of %s got unexpected name type: %s\n",
220 tnames
->names
[input_idx
[i
]].name
.string
,
221 sid_type_lookup(sids
.sids
[i
].sid_type
));
224 if ((sids
.sids
[i
].sid_type
== SID_NAME_DOMAIN
) &&
225 (sids
.sids
[i
].rid
!= (uint32_t)-1)) {
226 torture_comment(tctx
, "LookupName of %s got unexpected rid: %d\n",
227 tnames
->names
[input_idx
[i
]].name
.string
, sids
.sids
[i
].rid
);
230 } else if (i
>=count
) {
231 torture_comment(tctx
, "LookupName of %s failed to return a result\n",
232 tnames
->names
[input_idx
[i
]].name
.string
);
236 torture_comment(tctx
, "\n");
241 static bool test_LookupNames_bogus(struct dcerpc_binding_handle
*b
,
242 struct torture_context
*tctx
,
243 struct policy_handle
*handle
)
245 struct lsa_LookupNames r
;
246 struct lsa_TransSidArray sids
;
247 struct lsa_RefDomainList
*domains
= NULL
;
248 struct lsa_String names
[1];
251 torture_comment(tctx
, "\nTesting LookupNames with bogus name\n");
256 init_lsa_String(&names
[0], "NT AUTHORITY\\BOGUS");
258 r
.in
.handle
= handle
;
264 r
.out
.count
= &count
;
266 r
.out
.domains
= &domains
;
268 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames_r(b
, tctx
, &r
),
269 "LookupNames bogus failed");
270 if (!NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NONE_MAPPED
)) {
271 torture_comment(tctx
, "LookupNames failed - %s\n",
272 nt_errstr(r
.out
.result
));
276 torture_comment(tctx
, "\n");
281 static bool test_LookupNames_NULL(struct dcerpc_binding_handle
*b
,
282 struct torture_context
*tctx
,
283 struct policy_handle
*handle
)
285 struct lsa_LookupNames r
;
286 struct lsa_TransSidArray sids
;
287 struct lsa_RefDomainList
*domains
= NULL
;
288 struct lsa_String names
[1];
291 torture_comment(tctx
, "\nTesting LookupNames with NULL name\n");
296 names
[0].string
= NULL
;
298 r
.in
.handle
= handle
;
304 r
.out
.count
= &count
;
306 r
.out
.domains
= &domains
;
308 /* nt4 returns NT_STATUS_NONE_MAPPED with sid_type
309 * SID_NAME_UNKNOWN, rid 0, and sid_index -1;
311 * w2k3/w2k8 return NT_STATUS_OK with sid_type
312 * SID_NAME_DOMAIN, rid -1 and sid_index 0 and BUILTIN domain
315 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames_r(b
, tctx
, &r
),
316 "LookupNames with NULL name failed");
317 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
318 "LookupNames with NULL name failed");
320 torture_comment(tctx
, "\n");
325 static bool test_LookupNames_wellknown(struct dcerpc_binding_handle
*b
,
326 struct torture_context
*tctx
,
327 struct policy_handle
*handle
)
329 struct lsa_TranslatedName name
;
330 struct lsa_TransNameArray tnames
;
333 torture_comment(tctx
, "Testing LookupNames with well known names\n");
335 tnames
.names
= &name
;
337 name
.name
.string
= "NT AUTHORITY\\SYSTEM";
338 name
.sid_type
= SID_NAME_WKN_GRP
;
339 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
341 name
.name
.string
= "NT AUTHORITY\\ANONYMOUS LOGON";
342 name
.sid_type
= SID_NAME_WKN_GRP
;
343 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
345 name
.name
.string
= "NT AUTHORITY\\Authenticated Users";
346 name
.sid_type
= SID_NAME_WKN_GRP
;
347 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
350 name
.name
.string
= "NT AUTHORITY";
351 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
353 name
.name
.string
= "NT AUTHORITY\\";
354 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
357 name
.name
.string
= "BUILTIN\\";
358 name
.sid_type
= SID_NAME_DOMAIN
;
359 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
361 name
.name
.string
= "BUILTIN\\Administrators";
362 name
.sid_type
= SID_NAME_ALIAS
;
363 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
365 name
.name
.string
= "SYSTEM";
366 name
.sid_type
= SID_NAME_WKN_GRP
;
367 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
369 name
.name
.string
= "Everyone";
370 name
.sid_type
= SID_NAME_WKN_GRP
;
371 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
375 static bool test_LookupNames2(struct dcerpc_binding_handle
*b
,
376 struct torture_context
*tctx
,
377 struct policy_handle
*handle
,
378 struct lsa_TransNameArray2
*tnames
,
381 struct lsa_LookupNames2 r
;
382 struct lsa_TransSidArray2 sids
;
383 struct lsa_RefDomainList
*domains
= NULL
;
384 struct lsa_String
*names
;
388 torture_comment(tctx
, "\nTesting LookupNames2 with %d names\n", tnames
->count
);
396 input_idx
= talloc_array(tctx
, uint32_t, tnames
->count
);
397 names
= talloc_array(tctx
, struct lsa_String
, tnames
->count
);
399 for (i
=0;i
<tnames
->count
;i
++) {
400 if (tnames
->names
[i
].sid_type
!= SID_NAME_UNKNOWN
) {
401 init_lsa_String(&names
[r
.in
.num_names
], tnames
->names
[i
].name
.string
);
402 input_idx
[r
.in
.num_names
] = i
;
407 r
.in
.handle
= handle
;
412 r
.in
.lookup_options
= 0;
413 r
.in
.client_revision
= 0;
414 r
.out
.count
= &count
;
416 r
.out
.domains
= &domains
;
418 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames2_r(b
, tctx
, &r
),
419 "LookupNames2 failed");
420 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
421 torture_comment(tctx
, "LookupNames2 failed - %s\n",
422 nt_errstr(r
.out
.result
));
427 torture_assert_int_equal(tctx
, count
, sids
.count
,
428 "unexpected number of results returned");
429 if (sids
.count
> 0) {
430 torture_assert(tctx
, sids
.sids
, "invalid sid buffer");
434 torture_comment(tctx
, "\n");
440 static bool test_LookupNames3(struct dcerpc_binding_handle
*b
,
441 struct torture_context
*tctx
,
442 struct policy_handle
*handle
,
443 struct lsa_TransNameArray2
*tnames
,
446 struct lsa_LookupNames3 r
;
447 struct lsa_TransSidArray3 sids
;
448 struct lsa_RefDomainList
*domains
= NULL
;
449 struct lsa_String
*names
;
454 torture_comment(tctx
, "\nTesting LookupNames3 with %d names\n", tnames
->count
);
461 input_idx
= talloc_array(tctx
, uint32_t, tnames
->count
);
462 names
= talloc_array(tctx
, struct lsa_String
, tnames
->count
);
463 for (i
=0;i
<tnames
->count
;i
++) {
464 if (tnames
->names
[i
].sid_type
!= SID_NAME_UNKNOWN
) {
465 init_lsa_String(&names
[r
.in
.num_names
], tnames
->names
[i
].name
.string
);
466 input_idx
[r
.in
.num_names
] = i
;
471 r
.in
.handle
= handle
;
476 r
.in
.lookup_options
= 0;
477 r
.in
.client_revision
= 0;
478 r
.out
.count
= &count
;
480 r
.out
.domains
= &domains
;
482 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames3_r(b
, tctx
, &r
),
483 "LookupNames3 failed");
484 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
485 torture_comment(tctx
, "LookupNames3 failed - %s\n",
486 nt_errstr(r
.out
.result
));
491 torture_assert_int_equal(tctx
, count
, sids
.count
,
492 "unexpected number of results returned");
493 if (sids
.count
> 0) {
494 torture_assert(tctx
, sids
.sids
, "invalid sid buffer");
498 torture_comment(tctx
, "\n");
503 static bool test_LookupNames4(struct dcerpc_binding_handle
*b
,
504 struct torture_context
*tctx
,
505 struct lsa_TransNameArray2
*tnames
,
508 struct lsa_LookupNames4 r
;
509 struct lsa_TransSidArray3 sids
;
510 struct lsa_RefDomainList
*domains
= NULL
;
511 struct lsa_String
*names
;
516 torture_comment(tctx
, "\nTesting LookupNames4 with %d names\n", tnames
->count
);
523 input_idx
= talloc_array(tctx
, uint32_t, tnames
->count
);
524 names
= talloc_array(tctx
, struct lsa_String
, tnames
->count
);
525 for (i
=0;i
<tnames
->count
;i
++) {
526 if (tnames
->names
[i
].sid_type
!= SID_NAME_UNKNOWN
) {
527 init_lsa_String(&names
[r
.in
.num_names
], tnames
->names
[i
].name
.string
);
528 input_idx
[r
.in
.num_names
] = i
;
533 r
.in
.num_names
= tnames
->count
;
538 r
.in
.lookup_options
= 0;
539 r
.in
.client_revision
= 0;
540 r
.out
.count
= &count
;
542 r
.out
.domains
= &domains
;
544 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames4_r(b
, tctx
, &r
),
545 "LookupNames4 failed");
546 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
547 torture_comment(tctx
, "LookupNames4 failed - %s\n",
548 nt_errstr(r
.out
.result
));
553 torture_assert_int_equal(tctx
, count
, sids
.count
,
554 "unexpected number of results returned");
555 if (sids
.count
> 0) {
556 torture_assert(tctx
, sids
.sids
, "invalid sid buffer");
560 torture_comment(tctx
, "\n");
566 static bool test_LookupSids(struct dcerpc_binding_handle
*b
,
567 struct torture_context
*tctx
,
568 struct policy_handle
*handle
,
569 struct lsa_SidArray
*sids
)
571 struct lsa_LookupSids r
;
572 struct lsa_TransNameArray names
;
573 struct lsa_RefDomainList
*domains
= NULL
;
574 uint32_t count
= sids
->num_sids
;
576 torture_comment(tctx
, "\nTesting LookupSids\n");
581 r
.in
.handle
= handle
;
586 r
.out
.count
= &count
;
587 r
.out
.names
= &names
;
588 r
.out
.domains
= &domains
;
590 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupSids_r(b
, tctx
, &r
),
591 "LookupSids failed");
592 if (!NT_STATUS_IS_OK(r
.out
.result
) &&
593 !NT_STATUS_EQUAL(r
.out
.result
, STATUS_SOME_UNMAPPED
)) {
594 torture_comment(tctx
, "LookupSids failed - %s\n",
595 nt_errstr(r
.out
.result
));
599 torture_comment(tctx
, "\n");
601 if (!test_LookupNames(b
, tctx
, handle
, &names
)) {
609 static bool test_LookupSids2(struct dcerpc_binding_handle
*b
,
610 struct torture_context
*tctx
,
611 struct policy_handle
*handle
,
612 struct lsa_SidArray
*sids
)
614 struct lsa_LookupSids2 r
;
615 struct lsa_TransNameArray2 names
;
616 struct lsa_RefDomainList
*domains
= NULL
;
617 uint32_t count
= sids
->num_sids
;
619 torture_comment(tctx
, "\nTesting LookupSids2\n");
624 r
.in
.handle
= handle
;
629 r
.in
.lookup_options
= 0;
630 r
.in
.client_revision
= 0;
631 r
.out
.count
= &count
;
632 r
.out
.names
= &names
;
633 r
.out
.domains
= &domains
;
635 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupSids2_r(b
, tctx
, &r
),
636 "LookupSids2 failed");
637 if (!NT_STATUS_IS_OK(r
.out
.result
) &&
638 !NT_STATUS_EQUAL(r
.out
.result
, STATUS_SOME_UNMAPPED
)) {
639 torture_comment(tctx
, "LookupSids2 failed - %s\n",
640 nt_errstr(r
.out
.result
));
644 torture_comment(tctx
, "\n");
646 if (!test_LookupNames2(b
, tctx
, handle
, &names
, false)) {
650 if (!test_LookupNames3(b
, tctx
, handle
, &names
, false)) {
657 static bool test_LookupSids3(struct dcerpc_binding_handle
*b
,
658 struct torture_context
*tctx
,
659 struct lsa_SidArray
*sids
)
661 struct lsa_LookupSids3 r
;
662 struct lsa_TransNameArray2 names
;
663 struct lsa_RefDomainList
*domains
= NULL
;
664 uint32_t count
= sids
->num_sids
;
666 torture_comment(tctx
, "\nTesting LookupSids3\n");
675 r
.in
.lookup_options
= 0;
676 r
.in
.client_revision
= 0;
677 r
.out
.domains
= &domains
;
678 r
.out
.count
= &count
;
679 r
.out
.names
= &names
;
681 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupSids3_r(b
, tctx
, &r
),
682 "LookupSids3 failed");
683 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
684 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_ACCESS_DENIED
) ||
685 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
686 torture_comment(tctx
, "not considering %s to be an error\n",
687 nt_errstr(r
.out
.result
));
690 torture_comment(tctx
, "LookupSids3 failed - %s - not considered an error\n",
691 nt_errstr(r
.out
.result
));
695 torture_comment(tctx
, "\n");
697 if (!test_LookupNames4(b
, tctx
, &names
, false)) {
704 bool test_many_LookupSids(struct dcerpc_pipe
*p
,
705 struct torture_context
*tctx
,
706 struct policy_handle
*handle
)
709 struct lsa_SidArray sids
;
711 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
713 torture_comment(tctx
, "\nTesting LookupSids with lots of SIDs\n");
717 sids
.sids
= talloc_array(tctx
, struct lsa_SidPtr
, sids
.num_sids
);
719 for (i
=0; i
<sids
.num_sids
; i
++) {
720 const char *sidstr
= "S-1-5-32-545";
721 sids
.sids
[i
].sid
= dom_sid_parse_talloc(tctx
, sidstr
);
724 count
= sids
.num_sids
;
727 struct lsa_LookupSids r
;
728 struct lsa_TransNameArray names
;
729 struct lsa_RefDomainList
*domains
= NULL
;
733 r
.in
.handle
= handle
;
737 r
.in
.count
= &names
.count
;
738 r
.out
.count
= &count
;
739 r
.out
.names
= &names
;
740 r
.out
.domains
= &domains
;
742 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupSids_r(b
, tctx
, &r
),
743 "LookupSids failed");
744 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
745 torture_comment(tctx
, "LookupSids failed - %s\n",
746 nt_errstr(r
.out
.result
));
750 torture_comment(tctx
, "\n");
752 if (!test_LookupNames(b
, tctx
, handle
, &names
)) {
755 } else if (p
->conn
->security_state
.auth_info
->auth_type
== DCERPC_AUTH_TYPE_SCHANNEL
&&
756 p
->conn
->security_state
.auth_info
->auth_level
>= DCERPC_AUTH_LEVEL_INTEGRITY
&&
757 (p
->binding
->transport
== NCACN_IP_TCP
|| p
->binding
->transport
== NCALRPC
)) {
758 struct lsa_LookupSids3 r
;
759 struct lsa_RefDomainList
*domains
= NULL
;
760 struct lsa_TransNameArray2 names
;
765 torture_comment(tctx
, "\nTesting LookupSids3\n");
771 r
.in
.lookup_options
= 0;
772 r
.in
.client_revision
= 0;
773 r
.out
.count
= &count
;
774 r
.out
.names
= &names
;
775 r
.out
.domains
= &domains
;
777 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupSids3_r(b
, tctx
, &r
),
778 "LookupSids3 failed");
779 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
780 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_ACCESS_DENIED
) ||
781 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
782 torture_comment(tctx
, "not considering %s to be an error\n",
783 nt_errstr(r
.out
.result
));
786 torture_comment(tctx
, "LookupSids3 failed - %s\n",
787 nt_errstr(r
.out
.result
));
790 if (!test_LookupNames4(b
, tctx
, &names
, false)) {
795 torture_comment(tctx
, "\n");
802 static void lookupsids_cb(struct tevent_req
*subreq
)
804 int *replies
= (int *)tevent_req_callback_data_void(subreq
);
807 status
= dcerpc_lsa_LookupSids_r_recv(subreq
, subreq
);
809 if (!NT_STATUS_IS_OK(status
)) {
810 printf("lookupsids returned %s\n", nt_errstr(status
));
819 static bool test_LookupSids_async(struct dcerpc_binding_handle
*b
,
820 struct torture_context
*tctx
,
821 struct policy_handle
*handle
)
823 struct lsa_SidArray sids
;
824 struct lsa_SidPtr sidptr
;
826 struct lsa_TransNameArray
*names
;
827 struct lsa_LookupSids
*r
;
828 struct lsa_RefDomainList
*domains
= NULL
;
829 struct tevent_req
**req
;
832 const int num_async_requests
= 50;
834 count
= talloc_array(tctx
, uint32_t, num_async_requests
);
835 names
= talloc_array(tctx
, struct lsa_TransNameArray
, num_async_requests
);
836 r
= talloc_array(tctx
, struct lsa_LookupSids
, num_async_requests
);
838 torture_comment(tctx
, "\nTesting %d async lookupsids request\n", num_async_requests
);
840 req
= talloc_array(tctx
, struct tevent_req
*, num_async_requests
);
844 sidptr
.sid
= dom_sid_parse_talloc(tctx
, "S-1-5-32-545");
848 for (i
=0; i
<num_async_requests
; i
++) {
851 names
[i
].names
= NULL
;
853 r
[i
].in
.handle
= handle
;
854 r
[i
].in
.sids
= &sids
;
855 r
[i
].in
.names
= &names
[i
];
857 r
[i
].in
.count
= &names
[i
].count
;
858 r
[i
].out
.count
= &count
[i
];
859 r
[i
].out
.names
= &names
[i
];
860 r
[i
].out
.domains
= &domains
;
862 req
[i
] = dcerpc_lsa_LookupSids_r_send(tctx
, tctx
->ev
, b
, &r
[i
]);
863 if (req
[i
] == NULL
) {
868 tevent_req_set_callback(req
[i
], lookupsids_cb
, &replies
);
871 while (replies
>= 0 && replies
< num_async_requests
) {
872 tevent_loop_once(tctx
->ev
);
884 static bool test_LookupPrivValue(struct dcerpc_binding_handle
*b
,
885 struct torture_context
*tctx
,
886 struct policy_handle
*handle
,
887 struct lsa_String
*name
)
889 struct lsa_LookupPrivValue r
;
890 struct lsa_LUID luid
;
892 r
.in
.handle
= handle
;
896 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupPrivValue_r(b
, tctx
, &r
),
897 "LookupPrivValue failed");
898 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
899 torture_comment(tctx
, "\nLookupPrivValue failed - %s\n",
900 nt_errstr(r
.out
.result
));
907 static bool test_LookupPrivName(struct dcerpc_binding_handle
*b
,
908 struct torture_context
*tctx
,
909 struct policy_handle
*handle
,
910 struct lsa_LUID
*luid
)
912 struct lsa_LookupPrivName r
;
913 struct lsa_StringLarge
*name
= NULL
;
915 r
.in
.handle
= handle
;
919 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupPrivName_r(b
, tctx
, &r
),
920 "LookupPrivName failed");
921 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
922 torture_comment(tctx
, "\nLookupPrivName failed - %s\n",
923 nt_errstr(r
.out
.result
));
930 static bool test_RemovePrivilegesFromAccount(struct dcerpc_binding_handle
*b
,
931 struct torture_context
*tctx
,
932 struct policy_handle
*handle
,
933 struct policy_handle
*acct_handle
,
934 struct lsa_LUID
*luid
)
936 struct lsa_RemovePrivilegesFromAccount r
;
937 struct lsa_PrivilegeSet privs
;
940 torture_comment(tctx
, "\nTesting RemovePrivilegesFromAccount\n");
942 r
.in
.handle
= acct_handle
;
948 privs
.set
= talloc_array(tctx
, struct lsa_LUIDAttribute
, 1);
949 privs
.set
[0].luid
= *luid
;
950 privs
.set
[0].attribute
= 0;
952 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_RemovePrivilegesFromAccount_r(b
, tctx
, &r
),
953 "RemovePrivilegesFromAccount failed");
954 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
956 struct lsa_LookupPrivName r_name
;
957 struct lsa_StringLarge
*name
= NULL
;
959 r_name
.in
.handle
= handle
;
960 r_name
.in
.luid
= luid
;
961 r_name
.out
.name
= &name
;
963 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupPrivName_r(b
, tctx
, &r_name
),
964 "LookupPrivName failed");
965 if (!NT_STATUS_IS_OK(r_name
.out
.result
)) {
966 torture_comment(tctx
, "\nLookupPrivName failed - %s\n",
967 nt_errstr(r_name
.out
.result
));
970 /* Windows 2008 does not allow this to be removed */
971 if (strcmp("SeAuditPrivilege", name
->string
) == 0) {
975 torture_comment(tctx
, "RemovePrivilegesFromAccount failed to remove %s - %s\n",
977 nt_errstr(r
.out
.result
));
984 static bool test_AddPrivilegesToAccount(struct dcerpc_binding_handle
*b
,
985 struct torture_context
*tctx
,
986 struct policy_handle
*acct_handle
,
987 struct lsa_LUID
*luid
)
989 struct lsa_AddPrivilegesToAccount r
;
990 struct lsa_PrivilegeSet privs
;
993 torture_comment(tctx
, "\nTesting AddPrivilegesToAccount\n");
995 r
.in
.handle
= acct_handle
;
1000 privs
.set
= talloc_array(tctx
, struct lsa_LUIDAttribute
, 1);
1001 privs
.set
[0].luid
= *luid
;
1002 privs
.set
[0].attribute
= 0;
1004 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_AddPrivilegesToAccount_r(b
, tctx
, &r
),
1005 "AddPrivilegesToAccount failed");
1006 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1007 torture_comment(tctx
, "AddPrivilegesToAccount failed - %s\n",
1008 nt_errstr(r
.out
.result
));
1015 static bool test_EnumPrivsAccount(struct dcerpc_binding_handle
*b
,
1016 struct torture_context
*tctx
,
1017 struct policy_handle
*handle
,
1018 struct policy_handle
*acct_handle
)
1020 struct lsa_EnumPrivsAccount r
;
1021 struct lsa_PrivilegeSet
*privs
= NULL
;
1024 torture_comment(tctx
, "\nTesting EnumPrivsAccount\n");
1026 r
.in
.handle
= acct_handle
;
1027 r
.out
.privs
= &privs
;
1029 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumPrivsAccount_r(b
, tctx
, &r
),
1030 "EnumPrivsAccount failed");
1031 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1032 torture_comment(tctx
, "EnumPrivsAccount failed - %s\n",
1033 nt_errstr(r
.out
.result
));
1037 if (privs
&& privs
->count
> 0) {
1039 for (i
=0;i
<privs
->count
;i
++) {
1040 test_LookupPrivName(b
, tctx
, handle
,
1041 &privs
->set
[i
].luid
);
1044 ret
&= test_RemovePrivilegesFromAccount(b
, tctx
, handle
, acct_handle
,
1045 &privs
->set
[0].luid
);
1046 ret
&= test_AddPrivilegesToAccount(b
, tctx
, acct_handle
,
1047 &privs
->set
[0].luid
);
1053 static bool test_GetSystemAccessAccount(struct dcerpc_binding_handle
*b
,
1054 struct torture_context
*tctx
,
1055 struct policy_handle
*handle
,
1056 struct policy_handle
*acct_handle
)
1058 uint32_t access_mask
;
1059 struct lsa_GetSystemAccessAccount r
;
1061 torture_comment(tctx
, "\nTesting GetSystemAccessAccount\n");
1063 r
.in
.handle
= acct_handle
;
1064 r
.out
.access_mask
= &access_mask
;
1066 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_GetSystemAccessAccount_r(b
, tctx
, &r
),
1067 "GetSystemAccessAccount failed");
1068 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1069 torture_comment(tctx
, "GetSystemAccessAccount failed - %s\n",
1070 nt_errstr(r
.out
.result
));
1074 if (r
.out
.access_mask
!= NULL
) {
1075 torture_comment(tctx
, "Rights:");
1076 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_INTERACTIVE
)
1077 torture_comment(tctx
, " LSA_POLICY_MODE_INTERACTIVE");
1078 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_NETWORK
)
1079 torture_comment(tctx
, " LSA_POLICY_MODE_NETWORK");
1080 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_BATCH
)
1081 torture_comment(tctx
, " LSA_POLICY_MODE_BATCH");
1082 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_SERVICE
)
1083 torture_comment(tctx
, " LSA_POLICY_MODE_SERVICE");
1084 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_PROXY
)
1085 torture_comment(tctx
, " LSA_POLICY_MODE_PROXY");
1086 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_INTERACTIVE
)
1087 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_INTERACTIVE");
1088 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_NETWORK
)
1089 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_NETWORK");
1090 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_BATCH
)
1091 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_BATCH");
1092 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_SERVICE
)
1093 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_SERVICE");
1094 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_REMOTE_INTERACTIVE
)
1095 torture_comment(tctx
, " LSA_POLICY_MODE_REMOTE_INTERACTIVE");
1096 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_REMOTE_INTERACTIVE
)
1097 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_REMOTE_INTERACTIVE");
1098 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_ALL
)
1099 torture_comment(tctx
, " LSA_POLICY_MODE_ALL");
1100 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_ALL_NT4
)
1101 torture_comment(tctx
, " LSA_POLICY_MODE_ALL_NT4");
1102 torture_comment(tctx
, "\n");
1108 static bool test_Delete(struct dcerpc_binding_handle
*b
,
1109 struct torture_context
*tctx
,
1110 struct policy_handle
*handle
)
1112 struct lsa_Delete r
;
1114 torture_comment(tctx
, "\nTesting Delete\n");
1116 r
.in
.handle
= handle
;
1117 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_Delete_r(b
, tctx
, &r
),
1119 if (!NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NOT_SUPPORTED
)) {
1120 torture_comment(tctx
, "Delete should have failed NT_STATUS_NOT_SUPPORTED - %s\n", nt_errstr(r
.out
.result
));
1127 static bool test_DeleteObject(struct dcerpc_binding_handle
*b
,
1128 struct torture_context
*tctx
,
1129 struct policy_handle
*handle
)
1131 struct lsa_DeleteObject r
;
1133 torture_comment(tctx
, "\nTesting DeleteObject\n");
1135 r
.in
.handle
= handle
;
1136 r
.out
.handle
= handle
;
1137 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_DeleteObject_r(b
, tctx
, &r
),
1138 "DeleteObject failed");
1139 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1140 torture_comment(tctx
, "DeleteObject failed - %s\n",
1141 nt_errstr(r
.out
.result
));
1149 static bool test_CreateAccount(struct dcerpc_binding_handle
*b
,
1150 struct torture_context
*tctx
,
1151 struct policy_handle
*handle
)
1153 struct lsa_CreateAccount r
;
1154 struct dom_sid2
*newsid
;
1155 struct policy_handle acct_handle
;
1157 newsid
= dom_sid_parse_talloc(tctx
, "S-1-5-12349876-4321-2854");
1159 torture_comment(tctx
, "\nTesting CreateAccount\n");
1161 r
.in
.handle
= handle
;
1163 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1164 r
.out
.acct_handle
= &acct_handle
;
1166 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateAccount_r(b
, tctx
, &r
),
1167 "CreateAccount failed");
1168 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
1169 struct lsa_OpenAccount r_o
;
1170 r_o
.in
.handle
= handle
;
1171 r_o
.in
.sid
= newsid
;
1172 r_o
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1173 r_o
.out
.acct_handle
= &acct_handle
;
1175 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenAccount_r(b
, tctx
, &r_o
),
1176 "OpenAccount failed");
1177 if (!NT_STATUS_IS_OK(r_o
.out
.result
)) {
1178 torture_comment(tctx
, "OpenAccount failed - %s\n",
1179 nt_errstr(r_o
.out
.result
));
1182 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1183 torture_comment(tctx
, "CreateAccount failed - %s\n",
1184 nt_errstr(r
.out
.result
));
1188 if (!test_Delete(b
, tctx
, &acct_handle
)) {
1192 if (!test_DeleteObject(b
, tctx
, &acct_handle
)) {
1199 static bool test_DeleteTrustedDomain(struct dcerpc_binding_handle
*b
,
1200 struct torture_context
*tctx
,
1201 struct policy_handle
*handle
,
1202 struct lsa_StringLarge name
)
1204 struct lsa_OpenTrustedDomainByName r
;
1205 struct policy_handle trustdom_handle
;
1207 r
.in
.handle
= handle
;
1208 r
.in
.name
.string
= name
.string
;
1209 r
.in
.access_mask
= SEC_STD_DELETE
;
1210 r
.out
.trustdom_handle
= &trustdom_handle
;
1212 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenTrustedDomainByName_r(b
, tctx
, &r
),
1213 "OpenTrustedDomainByName failed");
1214 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1215 torture_comment(tctx
, "OpenTrustedDomainByName failed - %s\n", nt_errstr(r
.out
.result
));
1219 if (!test_Delete(b
, tctx
, &trustdom_handle
)) {
1223 if (!test_DeleteObject(b
, tctx
, &trustdom_handle
)) {
1230 static bool test_DeleteTrustedDomainBySid(struct dcerpc_binding_handle
*b
,
1231 struct torture_context
*tctx
,
1232 struct policy_handle
*handle
,
1233 struct dom_sid
*sid
)
1235 struct lsa_DeleteTrustedDomain r
;
1237 r
.in
.handle
= handle
;
1240 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_DeleteTrustedDomain_r(b
, tctx
, &r
),
1241 "DeleteTrustedDomain failed");
1242 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1243 torture_comment(tctx
, "DeleteTrustedDomain failed - %s\n", nt_errstr(r
.out
.result
));
1251 static bool test_CreateSecret(struct dcerpc_pipe
*p
,
1252 struct torture_context
*tctx
,
1253 struct policy_handle
*handle
)
1256 struct lsa_CreateSecret r
;
1257 struct lsa_OpenSecret r2
;
1258 struct lsa_SetSecret r3
;
1259 struct lsa_QuerySecret r4
;
1260 struct lsa_SetSecret r5
;
1261 struct lsa_QuerySecret r6
;
1262 struct lsa_SetSecret r7
;
1263 struct lsa_QuerySecret r8
;
1264 struct policy_handle sec_handle
, sec_handle2
, sec_handle3
;
1265 struct lsa_DeleteObject d_o
;
1266 struct lsa_DATA_BUF buf1
;
1267 struct lsa_DATA_BUF_PTR bufp1
;
1268 struct lsa_DATA_BUF_PTR bufp2
;
1271 DATA_BLOB session_key
;
1272 NTTIME old_mtime
, new_mtime
;
1273 DATA_BLOB blob1
, blob2
;
1274 const char *secret1
= "abcdef12345699qwerty";
1276 const char *secret3
= "ABCDEF12345699QWERTY";
1278 const char *secret5
= "NEW-SAMBA4-SECRET";
1282 const int LOCAL
= 0;
1283 const int GLOBAL
= 1;
1284 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
1286 secname
[LOCAL
] = talloc_asprintf(tctx
, "torturesecret-%u", (unsigned int)random());
1287 secname
[GLOBAL
] = talloc_asprintf(tctx
, "G$torturesecret-%u", (unsigned int)random());
1289 for (i
=0; i
< 2; i
++) {
1290 torture_comment(tctx
, "\nTesting CreateSecret of %s\n", secname
[i
]);
1292 init_lsa_String(&r
.in
.name
, secname
[i
]);
1294 r
.in
.handle
= handle
;
1295 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1296 r
.out
.sec_handle
= &sec_handle
;
1298 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateSecret_r(b
, tctx
, &r
),
1299 "CreateSecret failed");
1300 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1301 torture_comment(tctx
, "CreateSecret failed - %s\n", nt_errstr(r
.out
.result
));
1305 r
.in
.handle
= handle
;
1306 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1307 r
.out
.sec_handle
= &sec_handle3
;
1309 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateSecret_r(b
, tctx
, &r
),
1310 "CreateSecret failed");
1311 if (!NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
1312 torture_comment(tctx
, "CreateSecret should have failed OBJECT_NAME_COLLISION - %s\n", nt_errstr(r
.out
.result
));
1316 r2
.in
.handle
= handle
;
1317 r2
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1318 r2
.in
.name
= r
.in
.name
;
1319 r2
.out
.sec_handle
= &sec_handle2
;
1321 torture_comment(tctx
, "Testing OpenSecret\n");
1323 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenSecret_r(b
, tctx
, &r2
),
1324 "OpenSecret failed");
1325 if (!NT_STATUS_IS_OK(r2
.out
.result
)) {
1326 torture_comment(tctx
, "OpenSecret failed - %s\n", nt_errstr(r2
.out
.result
));
1330 status
= dcerpc_fetch_session_key(p
, &session_key
);
1331 if (!NT_STATUS_IS_OK(status
)) {
1332 torture_comment(tctx
, "dcerpc_fetch_session_key failed - %s\n", nt_errstr(status
));
1336 enc_key
= sess_encrypt_string(secret1
, &session_key
);
1338 r3
.in
.sec_handle
= &sec_handle
;
1339 r3
.in
.new_val
= &buf1
;
1340 r3
.in
.old_val
= NULL
;
1341 r3
.in
.new_val
->data
= enc_key
.data
;
1342 r3
.in
.new_val
->length
= enc_key
.length
;
1343 r3
.in
.new_val
->size
= enc_key
.length
;
1345 torture_comment(tctx
, "Testing SetSecret\n");
1347 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_SetSecret_r(b
, tctx
, &r3
),
1348 "SetSecret failed");
1349 if (!NT_STATUS_IS_OK(r3
.out
.result
)) {
1350 torture_comment(tctx
, "SetSecret failed - %s\n", nt_errstr(r3
.out
.result
));
1354 r3
.in
.sec_handle
= &sec_handle
;
1355 r3
.in
.new_val
= &buf1
;
1356 r3
.in
.old_val
= NULL
;
1357 r3
.in
.new_val
->data
= enc_key
.data
;
1358 r3
.in
.new_val
->length
= enc_key
.length
;
1359 r3
.in
.new_val
->size
= enc_key
.length
;
1361 /* break the encrypted data */
1364 torture_comment(tctx
, "Testing SetSecret with broken key\n");
1366 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_SetSecret_r(b
, tctx
, &r3
),
1367 "SetSecret failed");
1368 if (!NT_STATUS_EQUAL(r3
.out
.result
, NT_STATUS_UNKNOWN_REVISION
)) {
1369 torture_comment(tctx
, "SetSecret should have failed UNKNOWN_REVISION - %s\n", nt_errstr(r3
.out
.result
));
1373 data_blob_free(&enc_key
);
1375 ZERO_STRUCT(new_mtime
);
1376 ZERO_STRUCT(old_mtime
);
1378 /* fetch the secret back again */
1379 r4
.in
.sec_handle
= &sec_handle
;
1380 r4
.in
.new_val
= &bufp1
;
1381 r4
.in
.new_mtime
= &new_mtime
;
1382 r4
.in
.old_val
= NULL
;
1383 r4
.in
.old_mtime
= NULL
;
1387 torture_comment(tctx
, "Testing QuerySecret\n");
1388 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QuerySecret_r(b
, tctx
, &r4
),
1389 "QuerySecret failed");
1390 if (!NT_STATUS_IS_OK(r4
.out
.result
)) {
1391 torture_comment(tctx
, "QuerySecret failed - %s\n", nt_errstr(r4
.out
.result
));
1394 if (r4
.out
.new_val
== NULL
|| r4
.out
.new_val
->buf
== NULL
) {
1395 torture_comment(tctx
, "No secret buffer returned\n");
1398 blob1
.data
= r4
.out
.new_val
->buf
->data
;
1399 blob1
.length
= r4
.out
.new_val
->buf
->size
;
1401 blob2
= data_blob_talloc(tctx
, NULL
, blob1
.length
);
1403 secret2
= sess_decrypt_string(tctx
,
1404 &blob1
, &session_key
);
1406 if (strcmp(secret1
, secret2
) != 0) {
1407 torture_comment(tctx
, "Returned secret (r4) '%s' doesn't match '%s'\n",
1414 enc_key
= sess_encrypt_string(secret3
, &session_key
);
1416 r5
.in
.sec_handle
= &sec_handle
;
1417 r5
.in
.new_val
= &buf1
;
1418 r5
.in
.old_val
= NULL
;
1419 r5
.in
.new_val
->data
= enc_key
.data
;
1420 r5
.in
.new_val
->length
= enc_key
.length
;
1421 r5
.in
.new_val
->size
= enc_key
.length
;
1425 torture_comment(tctx
, "Testing SetSecret (existing value should move to old)\n");
1427 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_SetSecret_r(b
, tctx
, &r5
),
1428 "SetSecret failed");
1429 if (!NT_STATUS_IS_OK(r5
.out
.result
)) {
1430 torture_comment(tctx
, "SetSecret failed - %s\n", nt_errstr(r5
.out
.result
));
1434 data_blob_free(&enc_key
);
1436 ZERO_STRUCT(new_mtime
);
1437 ZERO_STRUCT(old_mtime
);
1439 /* fetch the secret back again */
1440 r6
.in
.sec_handle
= &sec_handle
;
1441 r6
.in
.new_val
= &bufp1
;
1442 r6
.in
.new_mtime
= &new_mtime
;
1443 r6
.in
.old_val
= &bufp2
;
1444 r6
.in
.old_mtime
= &old_mtime
;
1449 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QuerySecret_r(b
, tctx
, &r6
),
1450 "QuerySecret failed");
1451 if (!NT_STATUS_IS_OK(r6
.out
.result
)) {
1452 torture_comment(tctx
, "QuerySecret failed - %s\n", nt_errstr(r6
.out
.result
));
1457 if (r6
.out
.new_val
->buf
== NULL
|| r6
.out
.old_val
->buf
== NULL
1458 || r6
.out
.new_mtime
== NULL
|| r6
.out
.old_mtime
== NULL
) {
1459 torture_comment(tctx
, "Both secret buffers and both times not returned\n");
1463 blob1
.data
= r6
.out
.new_val
->buf
->data
;
1464 blob1
.length
= r6
.out
.new_val
->buf
->size
;
1466 blob2
= data_blob_talloc(tctx
, NULL
, blob1
.length
);
1468 secret4
= sess_decrypt_string(tctx
,
1469 &blob1
, &session_key
);
1471 if (strcmp(secret3
, secret4
) != 0) {
1472 torture_comment(tctx
, "Returned NEW secret %s doesn't match %s\n", secret4
, secret3
);
1476 blob1
.data
= r6
.out
.old_val
->buf
->data
;
1477 blob1
.length
= r6
.out
.old_val
->buf
->length
;
1479 blob2
= data_blob_talloc(tctx
, NULL
, blob1
.length
);
1481 secret2
= sess_decrypt_string(tctx
,
1482 &blob1
, &session_key
);
1484 if (strcmp(secret1
, secret2
) != 0) {
1485 torture_comment(tctx
, "Returned OLD secret %s doesn't match %s\n", secret2
, secret1
);
1489 if (*r6
.out
.new_mtime
== *r6
.out
.old_mtime
) {
1490 torture_comment(tctx
, "Returned secret (r6-%d) %s must not have same mtime for both secrets: %s != %s\n",
1493 nt_time_string(tctx
, *r6
.out
.old_mtime
),
1494 nt_time_string(tctx
, *r6
.out
.new_mtime
));
1500 enc_key
= sess_encrypt_string(secret5
, &session_key
);
1502 r7
.in
.sec_handle
= &sec_handle
;
1503 r7
.in
.old_val
= &buf1
;
1504 r7
.in
.old_val
->data
= enc_key
.data
;
1505 r7
.in
.old_val
->length
= enc_key
.length
;
1506 r7
.in
.old_val
->size
= enc_key
.length
;
1507 r7
.in
.new_val
= NULL
;
1509 torture_comment(tctx
, "Testing SetSecret of old Secret only\n");
1511 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_SetSecret_r(b
, tctx
, &r7
),
1512 "SetSecret failed");
1513 if (!NT_STATUS_IS_OK(r7
.out
.result
)) {
1514 torture_comment(tctx
, "SetSecret failed - %s\n", nt_errstr(r7
.out
.result
));
1518 data_blob_free(&enc_key
);
1520 /* fetch the secret back again */
1521 r8
.in
.sec_handle
= &sec_handle
;
1522 r8
.in
.new_val
= &bufp1
;
1523 r8
.in
.new_mtime
= &new_mtime
;
1524 r8
.in
.old_val
= &bufp2
;
1525 r8
.in
.old_mtime
= &old_mtime
;
1530 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QuerySecret_r(b
, tctx
, &r8
),
1531 "QuerySecret failed");
1532 if (!NT_STATUS_IS_OK(r8
.out
.result
)) {
1533 torture_comment(tctx
, "QuerySecret failed - %s\n", nt_errstr(r8
.out
.result
));
1536 if (!r8
.out
.new_val
|| !r8
.out
.old_val
) {
1537 torture_comment(tctx
, "in/out pointers not returned, despite being set on in for QuerySecret\n");
1539 } else if (r8
.out
.new_val
->buf
!= NULL
) {
1540 torture_comment(tctx
, "NEW secret buffer must not be returned after OLD set\n");
1542 } else if (r8
.out
.old_val
->buf
== NULL
) {
1543 torture_comment(tctx
, "OLD secret buffer was not returned after OLD set\n");
1545 } else if (r8
.out
.new_mtime
== NULL
|| r8
.out
.old_mtime
== NULL
) {
1546 torture_comment(tctx
, "Both times not returned after OLD set\n");
1549 blob1
.data
= r8
.out
.old_val
->buf
->data
;
1550 blob1
.length
= r8
.out
.old_val
->buf
->size
;
1552 blob2
= data_blob_talloc(tctx
, NULL
, blob1
.length
);
1554 secret6
= sess_decrypt_string(tctx
,
1555 &blob1
, &session_key
);
1557 if (strcmp(secret5
, secret6
) != 0) {
1558 torture_comment(tctx
, "Returned OLD secret %s doesn't match %s\n", secret5
, secret6
);
1562 if (*r8
.out
.new_mtime
!= *r8
.out
.old_mtime
) {
1563 torture_comment(tctx
, "Returned secret (r8) %s did not had same mtime for both secrets: %s != %s\n",
1565 nt_time_string(tctx
, *r8
.out
.old_mtime
),
1566 nt_time_string(tctx
, *r8
.out
.new_mtime
));
1572 if (!test_Delete(b
, tctx
, &sec_handle
)) {
1576 if (!test_DeleteObject(b
, tctx
, &sec_handle
)) {
1580 d_o
.in
.handle
= &sec_handle2
;
1581 d_o
.out
.handle
= &sec_handle2
;
1582 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_DeleteObject_r(b
, tctx
, &d_o
),
1583 "DeleteObject failed");
1584 if (!NT_STATUS_EQUAL(d_o
.out
.result
, NT_STATUS_INVALID_HANDLE
)) {
1585 torture_comment(tctx
, "Second delete expected INVALID_HANDLE - %s\n", nt_errstr(d_o
.out
.result
));
1589 torture_comment(tctx
, "Testing OpenSecret of just-deleted secret\n");
1591 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenSecret_r(b
, tctx
, &r2
),
1592 "OpenSecret failed");
1593 if (!NT_STATUS_EQUAL(r2
.out
.result
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
1594 torture_comment(tctx
, "OpenSecret expected OBJECT_NAME_NOT_FOUND - %s\n", nt_errstr(r2
.out
.result
));
1605 static bool test_EnumAccountRights(struct dcerpc_binding_handle
*b
,
1606 struct torture_context
*tctx
,
1607 struct policy_handle
*acct_handle
,
1608 struct dom_sid
*sid
)
1610 struct lsa_EnumAccountRights r
;
1611 struct lsa_RightSet rights
;
1613 torture_comment(tctx
, "\nTesting EnumAccountRights\n");
1615 r
.in
.handle
= acct_handle
;
1617 r
.out
.rights
= &rights
;
1619 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumAccountRights_r(b
, tctx
, &r
),
1620 "EnumAccountRights failed");
1621 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1622 torture_comment(tctx
, "EnumAccountRights of %s failed - %s\n",
1623 dom_sid_string(tctx
, sid
), nt_errstr(r
.out
.result
));
1631 static bool test_QuerySecurity(struct dcerpc_binding_handle
*b
,
1632 struct torture_context
*tctx
,
1633 struct policy_handle
*handle
,
1634 struct policy_handle
*acct_handle
)
1636 struct lsa_QuerySecurity r
;
1637 struct sec_desc_buf
*sdbuf
= NULL
;
1639 if (torture_setting_bool(tctx
, "samba4", false)) {
1640 torture_comment(tctx
, "\nskipping QuerySecurity test against Samba4\n");
1644 torture_comment(tctx
, "\nTesting QuerySecurity\n");
1646 r
.in
.handle
= acct_handle
;
1647 r
.in
.sec_info
= SECINFO_OWNER
|
1650 r
.out
.sdbuf
= &sdbuf
;
1652 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QuerySecurity_r(b
, tctx
, &r
),
1653 "QuerySecurity failed");
1654 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1655 torture_comment(tctx
, "QuerySecurity failed - %s\n", nt_errstr(r
.out
.result
));
1662 static bool test_OpenAccount(struct dcerpc_binding_handle
*b
,
1663 struct torture_context
*tctx
,
1664 struct policy_handle
*handle
,
1665 struct dom_sid
*sid
)
1667 struct lsa_OpenAccount r
;
1668 struct policy_handle acct_handle
;
1670 torture_comment(tctx
, "\nTesting OpenAccount\n");
1672 r
.in
.handle
= handle
;
1674 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1675 r
.out
.acct_handle
= &acct_handle
;
1677 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenAccount_r(b
, tctx
, &r
),
1678 "OpenAccount failed");
1679 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1680 torture_comment(tctx
, "OpenAccount failed - %s\n", nt_errstr(r
.out
.result
));
1684 if (!test_EnumPrivsAccount(b
, tctx
, handle
, &acct_handle
)) {
1688 if (!test_GetSystemAccessAccount(b
, tctx
, handle
, &acct_handle
)) {
1692 if (!test_QuerySecurity(b
, tctx
, handle
, &acct_handle
)) {
1699 static bool test_EnumAccounts(struct dcerpc_binding_handle
*b
,
1700 struct torture_context
*tctx
,
1701 struct policy_handle
*handle
)
1703 struct lsa_EnumAccounts r
;
1704 struct lsa_SidArray sids1
, sids2
;
1705 uint32_t resume_handle
= 0;
1709 torture_comment(tctx
, "\nTesting EnumAccounts\n");
1711 r
.in
.handle
= handle
;
1712 r
.in
.resume_handle
= &resume_handle
;
1713 r
.in
.num_entries
= 100;
1714 r
.out
.resume_handle
= &resume_handle
;
1715 r
.out
.sids
= &sids1
;
1719 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumAccounts_r(b
, tctx
, &r
),
1720 "EnumAccounts failed");
1721 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
)) {
1724 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1725 torture_comment(tctx
, "EnumAccounts failed - %s\n", nt_errstr(r
.out
.result
));
1729 if (!test_LookupSids(b
, tctx
, handle
, &sids1
)) {
1733 if (!test_LookupSids2(b
, tctx
, handle
, &sids1
)) {
1737 /* Can't test lookupSids3 here, as clearly we must not
1738 * be on schannel, or we would not be able to do the
1741 torture_comment(tctx
, "Testing all accounts\n");
1742 for (i
=0;i
<sids1
.num_sids
;i
++) {
1743 ret
&= test_OpenAccount(b
, tctx
, handle
, sids1
.sids
[i
].sid
);
1744 ret
&= test_EnumAccountRights(b
, tctx
, handle
, sids1
.sids
[i
].sid
);
1746 torture_comment(tctx
, "\n");
1749 if (sids1
.num_sids
< 3) {
1753 torture_comment(tctx
, "Trying EnumAccounts partial listing (asking for 1 at 2)\n");
1755 r
.in
.num_entries
= 1;
1756 r
.out
.sids
= &sids2
;
1758 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumAccounts_r(b
, tctx
, &r
),
1759 "EnumAccounts failed");
1760 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1761 torture_comment(tctx
, "EnumAccounts failed - %s\n", nt_errstr(r
.out
.result
));
1765 if (sids2
.num_sids
!= 1) {
1766 torture_comment(tctx
, "Returned wrong number of entries (%d)\n", sids2
.num_sids
);
1773 static bool test_LookupPrivDisplayName(struct dcerpc_binding_handle
*b
,
1774 struct torture_context
*tctx
,
1775 struct policy_handle
*handle
,
1776 struct lsa_String
*priv_name
)
1778 struct lsa_LookupPrivDisplayName r
;
1779 /* produce a reasonable range of language output without screwing up
1781 uint16_t language_id
= (random() % 4) + 0x409;
1782 uint16_t returned_language_id
= 0;
1783 struct lsa_StringLarge
*disp_name
= NULL
;
1785 torture_comment(tctx
, "\nTesting LookupPrivDisplayName(%s)\n", priv_name
->string
);
1787 r
.in
.handle
= handle
;
1788 r
.in
.name
= priv_name
;
1789 r
.in
.language_id
= language_id
;
1790 r
.in
.language_id_sys
= 0;
1791 r
.out
.returned_language_id
= &returned_language_id
;
1792 r
.out
.disp_name
= &disp_name
;
1794 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupPrivDisplayName_r(b
, tctx
, &r
),
1795 "LookupPrivDisplayName failed");
1796 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1797 torture_comment(tctx
, "LookupPrivDisplayName failed - %s\n", nt_errstr(r
.out
.result
));
1800 torture_comment(tctx
, "%s -> \"%s\" (language 0x%x/0x%x)\n",
1801 priv_name
->string
, disp_name
->string
,
1802 r
.in
.language_id
, *r
.out
.returned_language_id
);
1807 static bool test_EnumAccountsWithUserRight(struct dcerpc_binding_handle
*b
,
1808 struct torture_context
*tctx
,
1809 struct policy_handle
*handle
,
1810 struct lsa_String
*priv_name
)
1812 struct lsa_EnumAccountsWithUserRight r
;
1813 struct lsa_SidArray sids
;
1817 torture_comment(tctx
, "\nTesting EnumAccountsWithUserRight(%s)\n", priv_name
->string
);
1819 r
.in
.handle
= handle
;
1820 r
.in
.name
= priv_name
;
1823 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumAccountsWithUserRight_r(b
, tctx
, &r
),
1824 "EnumAccountsWithUserRight failed");
1826 /* NT_STATUS_NO_MORE_ENTRIES means noone has this privilege */
1827 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
)) {
1831 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1832 torture_comment(tctx
, "EnumAccountsWithUserRight failed - %s\n", nt_errstr(r
.out
.result
));
1840 static bool test_EnumPrivs(struct dcerpc_binding_handle
*b
,
1841 struct torture_context
*tctx
,
1842 struct policy_handle
*handle
)
1844 struct lsa_EnumPrivs r
;
1845 struct lsa_PrivArray privs1
;
1846 uint32_t resume_handle
= 0;
1850 torture_comment(tctx
, "\nTesting EnumPrivs\n");
1852 r
.in
.handle
= handle
;
1853 r
.in
.resume_handle
= &resume_handle
;
1854 r
.in
.max_count
= 100;
1855 r
.out
.resume_handle
= &resume_handle
;
1856 r
.out
.privs
= &privs1
;
1859 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumPrivs_r(b
, tctx
, &r
),
1860 "EnumPrivs failed");
1861 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1862 torture_comment(tctx
, "EnumPrivs failed - %s\n", nt_errstr(r
.out
.result
));
1866 for (i
= 0; i
< privs1
.count
; i
++) {
1867 test_LookupPrivDisplayName(b
, tctx
, handle
, (struct lsa_String
*)&privs1
.privs
[i
].name
);
1868 test_LookupPrivValue(b
, tctx
, handle
, (struct lsa_String
*)&privs1
.privs
[i
].name
);
1869 if (!test_EnumAccountsWithUserRight(b
, tctx
, handle
, (struct lsa_String
*)&privs1
.privs
[i
].name
)) {
1877 static bool test_QueryForestTrustInformation(struct dcerpc_binding_handle
*b
,
1878 struct torture_context
*tctx
,
1879 struct policy_handle
*handle
,
1880 const char *trusted_domain_name
)
1883 struct lsa_lsaRQueryForestTrustInformation r
;
1884 struct lsa_String string
;
1885 struct lsa_ForestTrustInformation info
, *info_ptr
;
1887 torture_comment(tctx
, "\nTesting lsaRQueryForestTrustInformation\n");
1889 if (torture_setting_bool(tctx
, "samba4", false)) {
1890 torture_comment(tctx
, "skipping QueryForestTrustInformation against Samba4\n");
1894 ZERO_STRUCT(string
);
1896 if (trusted_domain_name
) {
1897 init_lsa_String(&string
, trusted_domain_name
);
1902 r
.in
.handle
= handle
;
1903 r
.in
.trusted_domain_name
= &string
;
1905 r
.out
.forest_trust_info
= &info_ptr
;
1907 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_lsaRQueryForestTrustInformation_r(b
, tctx
, &r
),
1908 "lsaRQueryForestTrustInformation failed");
1910 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1911 torture_comment(tctx
, "lsaRQueryForestTrustInformation of %s failed - %s\n", trusted_domain_name
, nt_errstr(r
.out
.result
));
1918 static bool test_query_each_TrustDomEx(struct dcerpc_binding_handle
*b
,
1919 struct torture_context
*tctx
,
1920 struct policy_handle
*handle
,
1921 struct lsa_DomainListEx
*domains
)
1926 for (i
=0; i
< domains
->count
; i
++) {
1928 if (domains
->domains
[i
].trust_attributes
& NETR_TRUST_ATTRIBUTE_FOREST_TRANSITIVE
) {
1929 ret
&= test_QueryForestTrustInformation(b
, tctx
, handle
,
1930 domains
->domains
[i
].domain_name
.string
);
1937 static bool test_query_each_TrustDom(struct dcerpc_binding_handle
*b
,
1938 struct torture_context
*tctx
,
1939 struct policy_handle
*handle
,
1940 struct lsa_DomainList
*domains
)
1945 torture_comment(tctx
, "\nTesting OpenTrustedDomain, OpenTrustedDomainByName and QueryInfoTrustedDomain\n");
1946 for (i
=0; i
< domains
->count
; i
++) {
1947 struct lsa_OpenTrustedDomain trust
;
1948 struct lsa_OpenTrustedDomainByName trust_by_name
;
1949 struct policy_handle trustdom_handle
;
1950 struct policy_handle handle2
;
1952 struct lsa_CloseTrustedDomainEx c_trust
;
1953 int levels
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
1954 int ok
[] = {1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1};
1956 if (domains
->domains
[i
].sid
) {
1957 trust
.in
.handle
= handle
;
1958 trust
.in
.sid
= domains
->domains
[i
].sid
;
1959 trust
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1960 trust
.out
.trustdom_handle
= &trustdom_handle
;
1962 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenTrustedDomain_r(b
, tctx
, &trust
),
1963 "OpenTrustedDomain failed");
1965 if (!NT_STATUS_IS_OK(trust
.out
.result
)) {
1966 torture_comment(tctx
, "OpenTrustedDomain failed - %s\n", nt_errstr(trust
.out
.result
));
1970 c
.in
.handle
= &trustdom_handle
;
1971 c
.out
.handle
= &handle2
;
1973 c_trust
.in
.handle
= &trustdom_handle
;
1974 c_trust
.out
.handle
= &handle2
;
1976 for (j
=0; j
< ARRAY_SIZE(levels
); j
++) {
1977 struct lsa_QueryTrustedDomainInfo q
;
1978 union lsa_TrustedDomainInfo
*info
= NULL
;
1979 q
.in
.trustdom_handle
= &trustdom_handle
;
1980 q
.in
.level
= levels
[j
];
1982 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfo_r(b
, tctx
, &q
),
1983 "QueryTrustedDomainInfo failed");
1984 if (!NT_STATUS_IS_OK(q
.out
.result
) && ok
[j
]) {
1985 torture_comment(tctx
, "QueryTrustedDomainInfo level %d failed - %s\n",
1986 levels
[j
], nt_errstr(q
.out
.result
));
1988 } else if (NT_STATUS_IS_OK(q
.out
.result
) && !ok
[j
]) {
1989 torture_comment(tctx
, "QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
1990 levels
[j
], nt_errstr(q
.out
.result
));
1995 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CloseTrustedDomainEx_r(b
, tctx
, &c_trust
),
1996 "CloseTrustedDomainEx failed");
1997 if (!NT_STATUS_EQUAL(c_trust
.out
.result
, NT_STATUS_NOT_IMPLEMENTED
)) {
1998 torture_comment(tctx
, "Expected CloseTrustedDomainEx to return NT_STATUS_NOT_IMPLEMENTED, instead - %s\n", nt_errstr(c_trust
.out
.result
));
2002 c
.in
.handle
= &trustdom_handle
;
2003 c
.out
.handle
= &handle2
;
2005 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_Close_r(b
, tctx
, &c
),
2007 if (!NT_STATUS_IS_OK(c
.out
.result
)) {
2008 torture_comment(tctx
, "Close of trusted domain failed - %s\n", nt_errstr(c
.out
.result
));
2012 for (j
=0; j
< ARRAY_SIZE(levels
); j
++) {
2013 struct lsa_QueryTrustedDomainInfoBySid q
;
2014 union lsa_TrustedDomainInfo
*info
= NULL
;
2016 if (!domains
->domains
[i
].sid
) {
2020 q
.in
.handle
= handle
;
2021 q
.in
.dom_sid
= domains
->domains
[i
].sid
;
2022 q
.in
.level
= levels
[j
];
2025 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfoBySid_r(b
, tctx
, &q
),
2026 "lsa_QueryTrustedDomainInfoBySid failed");
2027 if (!NT_STATUS_IS_OK(q
.out
.result
) && ok
[j
]) {
2028 torture_comment(tctx
, "QueryTrustedDomainInfoBySid level %d failed - %s\n",
2029 levels
[j
], nt_errstr(q
.out
.result
));
2031 } else if (NT_STATUS_IS_OK(q
.out
.result
) && !ok
[j
]) {
2032 torture_comment(tctx
, "QueryTrustedDomainInfoBySid level %d unexpectedly succeeded - %s\n",
2033 levels
[j
], nt_errstr(q
.out
.result
));
2039 trust_by_name
.in
.handle
= handle
;
2040 trust_by_name
.in
.name
.string
= domains
->domains
[i
].name
.string
;
2041 trust_by_name
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2042 trust_by_name
.out
.trustdom_handle
= &trustdom_handle
;
2044 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenTrustedDomainByName_r(b
, tctx
, &trust_by_name
),
2045 "OpenTrustedDomainByName failed");
2047 if (!NT_STATUS_IS_OK(trust_by_name
.out
.result
)) {
2048 torture_comment(tctx
, "OpenTrustedDomainByName failed - %s\n", nt_errstr(trust_by_name
.out
.result
));
2052 for (j
=0; j
< ARRAY_SIZE(levels
); j
++) {
2053 struct lsa_QueryTrustedDomainInfo q
;
2054 union lsa_TrustedDomainInfo
*info
= NULL
;
2055 q
.in
.trustdom_handle
= &trustdom_handle
;
2056 q
.in
.level
= levels
[j
];
2058 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfo_r(b
, tctx
, &q
),
2059 "QueryTrustedDomainInfo failed");
2060 if (!NT_STATUS_IS_OK(q
.out
.result
) && ok
[j
]) {
2061 torture_comment(tctx
, "QueryTrustedDomainInfo level %d failed - %s\n",
2062 levels
[j
], nt_errstr(q
.out
.result
));
2064 } else if (NT_STATUS_IS_OK(q
.out
.result
) && !ok
[j
]) {
2065 torture_comment(tctx
, "QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
2066 levels
[j
], nt_errstr(q
.out
.result
));
2071 c
.in
.handle
= &trustdom_handle
;
2072 c
.out
.handle
= &handle2
;
2074 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_Close_r(b
, tctx
, &c
),
2076 if (!NT_STATUS_IS_OK(c
.out
.result
)) {
2077 torture_comment(tctx
, "Close of trusted domain failed - %s\n", nt_errstr(c
.out
.result
));
2081 for (j
=0; j
< ARRAY_SIZE(levels
); j
++) {
2082 struct lsa_QueryTrustedDomainInfoByName q
;
2083 union lsa_TrustedDomainInfo
*info
= NULL
;
2084 struct lsa_String name
;
2086 name
.string
= domains
->domains
[i
].name
.string
;
2088 q
.in
.handle
= handle
;
2089 q
.in
.trusted_domain
= &name
;
2090 q
.in
.level
= levels
[j
];
2092 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfoByName_r(b
, tctx
, &q
),
2093 "QueryTrustedDomainInfoByName failed");
2094 if (!NT_STATUS_IS_OK(q
.out
.result
) && ok
[j
]) {
2095 torture_comment(tctx
, "QueryTrustedDomainInfoByName level %d failed - %s\n",
2096 levels
[j
], nt_errstr(q
.out
.result
));
2098 } else if (NT_STATUS_IS_OK(q
.out
.result
) && !ok
[j
]) {
2099 torture_comment(tctx
, "QueryTrustedDomainInfoByName level %d unexpectedly succeeded - %s\n",
2100 levels
[j
], nt_errstr(q
.out
.result
));
2108 static bool test_EnumTrustDom(struct dcerpc_binding_handle
*b
,
2109 struct torture_context
*tctx
,
2110 struct policy_handle
*handle
)
2112 struct lsa_EnumTrustDom r
;
2113 uint32_t in_resume_handle
= 0;
2114 uint32_t out_resume_handle
;
2115 struct lsa_DomainList domains
;
2118 torture_comment(tctx
, "\nTesting EnumTrustDom\n");
2120 r
.in
.handle
= handle
;
2121 r
.in
.resume_handle
= &in_resume_handle
;
2123 r
.out
.domains
= &domains
;
2124 r
.out
.resume_handle
= &out_resume_handle
;
2126 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumTrustDom_r(b
, tctx
, &r
),
2127 "lsa_EnumTrustDom failed");
2129 /* according to MS-LSAD 3.1.4.7.8 output resume handle MUST
2130 * always be larger than the previous input resume handle, in
2131 * particular when hitting the last query it is vital to set the
2132 * resume handle correctly to avoid infinite client loops, as
2133 * seen e.g. with Windows XP SP3 when resume handle is 0 and
2134 * status is NT_STATUS_OK - gd */
2136 if (NT_STATUS_IS_OK(r
.out
.result
) ||
2137 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
) ||
2138 NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
))
2140 if (out_resume_handle
<= in_resume_handle
) {
2141 torture_comment(tctx
, "EnumTrustDom failed - should have returned output resume_handle (0x%08x) larger than input resume handle (0x%08x)\n",
2142 out_resume_handle
, in_resume_handle
);
2147 if (NT_STATUS_IS_OK(r
.out
.result
)) {
2148 if (domains
.count
== 0) {
2149 torture_comment(tctx
, "EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2152 } else if (!(NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
) || NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
))) {
2153 torture_comment(tctx
, "EnumTrustDom of zero size failed - %s\n", nt_errstr(r
.out
.result
));
2157 /* Start from the bottom again */
2158 in_resume_handle
= 0;
2161 r
.in
.handle
= handle
;
2162 r
.in
.resume_handle
= &in_resume_handle
;
2163 r
.in
.max_size
= LSA_ENUM_TRUST_DOMAIN_MULTIPLIER
* 3;
2164 r
.out
.domains
= &domains
;
2165 r
.out
.resume_handle
= &out_resume_handle
;
2167 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumTrustDom_r(b
, tctx
, &r
),
2168 "EnumTrustDom failed");
2170 /* according to MS-LSAD 3.1.4.7.8 output resume handle MUST
2171 * always be larger than the previous input resume handle, in
2172 * particular when hitting the last query it is vital to set the
2173 * resume handle correctly to avoid infinite client loops, as
2174 * seen e.g. with Windows XP SP3 when resume handle is 0 and
2175 * status is NT_STATUS_OK - gd */
2177 if (NT_STATUS_IS_OK(r
.out
.result
) ||
2178 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
) ||
2179 NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
))
2181 if (out_resume_handle
<= in_resume_handle
) {
2182 torture_comment(tctx
, "EnumTrustDom failed - should have returned output resume_handle (0x%08x) larger than input resume handle (0x%08x)\n",
2183 out_resume_handle
, in_resume_handle
);
2188 /* NO_MORE_ENTRIES is allowed */
2189 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
)) {
2190 if (domains
.count
== 0) {
2193 torture_comment(tctx
, "EnumTrustDom failed - should have returned 0 trusted domains with 'NT_STATUS_NO_MORE_ENTRIES'\n");
2195 } else if (NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
)) {
2196 /* Windows 2003 gets this off by one on the first run */
2197 if (r
.out
.domains
->count
< 3 || r
.out
.domains
->count
> 4) {
2198 torture_comment(tctx
, "EnumTrustDom didn't fill the buffer we "
2199 "asked it to (got %d, expected %d / %d == %d entries)\n",
2200 r
.out
.domains
->count
, LSA_ENUM_TRUST_DOMAIN_MULTIPLIER
* 3,
2201 LSA_ENUM_TRUST_DOMAIN_MULTIPLIER
, r
.in
.max_size
);
2204 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2205 torture_comment(tctx
, "EnumTrustDom failed - %s\n", nt_errstr(r
.out
.result
));
2209 if (domains
.count
== 0) {
2210 torture_comment(tctx
, "EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2214 ret
&= test_query_each_TrustDom(b
, tctx
, handle
, &domains
);
2216 in_resume_handle
= out_resume_handle
;
2218 } while ((NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
)));
2223 static bool test_EnumTrustDomEx(struct dcerpc_binding_handle
*b
,
2224 struct torture_context
*tctx
,
2225 struct policy_handle
*handle
)
2227 struct lsa_EnumTrustedDomainsEx r_ex
;
2228 uint32_t resume_handle
= 0;
2229 struct lsa_DomainListEx domains_ex
;
2232 torture_comment(tctx
, "\nTesting EnumTrustedDomainsEx\n");
2234 r_ex
.in
.handle
= handle
;
2235 r_ex
.in
.resume_handle
= &resume_handle
;
2236 r_ex
.in
.max_size
= LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER
* 3;
2237 r_ex
.out
.domains
= &domains_ex
;
2238 r_ex
.out
.resume_handle
= &resume_handle
;
2240 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumTrustedDomainsEx_r(b
, tctx
, &r_ex
),
2241 "EnumTrustedDomainsEx failed");
2243 if (!(NT_STATUS_EQUAL(r_ex
.out
.result
, STATUS_MORE_ENTRIES
) || NT_STATUS_EQUAL(r_ex
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
))) {
2244 torture_comment(tctx
, "EnumTrustedDomainEx of zero size failed - %s\n", nt_errstr(r_ex
.out
.result
));
2250 r_ex
.in
.handle
= handle
;
2251 r_ex
.in
.resume_handle
= &resume_handle
;
2252 r_ex
.in
.max_size
= LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER
* 3;
2253 r_ex
.out
.domains
= &domains_ex
;
2254 r_ex
.out
.resume_handle
= &resume_handle
;
2256 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumTrustedDomainsEx_r(b
, tctx
, &r_ex
),
2257 "EnumTrustedDomainsEx failed");
2259 /* NO_MORE_ENTRIES is allowed */
2260 if (NT_STATUS_EQUAL(r_ex
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
)) {
2261 if (domains_ex
.count
== 0) {
2264 torture_comment(tctx
, "EnumTrustDomainsEx failed - should have returned 0 trusted domains with 'NT_STATUS_NO_MORE_ENTRIES'\n");
2266 } else if (NT_STATUS_EQUAL(r_ex
.out
.result
, STATUS_MORE_ENTRIES
)) {
2267 /* Windows 2003 gets this off by one on the first run */
2268 if (r_ex
.out
.domains
->count
< 3 || r_ex
.out
.domains
->count
> 4) {
2269 torture_comment(tctx
, "EnumTrustDom didn't fill the buffer we "
2270 "asked it to (got %d, expected %d / %d == %d entries)\n",
2271 r_ex
.out
.domains
->count
,
2273 LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER
,
2274 r_ex
.in
.max_size
/ LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER
);
2276 } else if (!NT_STATUS_IS_OK(r_ex
.out
.result
)) {
2277 torture_comment(tctx
, "EnumTrustedDomainEx failed - %s\n", nt_errstr(r_ex
.out
.result
));
2281 if (domains_ex
.count
== 0) {
2282 torture_comment(tctx
, "EnumTrustDomainEx failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2286 ret
&= test_query_each_TrustDomEx(b
, tctx
, handle
, &domains_ex
);
2288 } while ((NT_STATUS_EQUAL(r_ex
.out
.result
, STATUS_MORE_ENTRIES
)));
2294 static bool test_CreateTrustedDomain(struct dcerpc_binding_handle
*b
,
2295 struct torture_context
*tctx
,
2296 struct policy_handle
*handle
,
2297 uint32_t num_trusts
)
2300 struct lsa_CreateTrustedDomain r
;
2301 struct lsa_DomainInfo trustinfo
;
2302 struct dom_sid
**domsid
;
2303 struct policy_handle
*trustdom_handle
;
2304 struct lsa_QueryTrustedDomainInfo q
;
2305 union lsa_TrustedDomainInfo
*info
= NULL
;
2308 torture_comment(tctx
, "\nTesting CreateTrustedDomain for %d domains\n", num_trusts
);
2310 if (!test_EnumTrustDom(b
, tctx
, handle
)) {
2314 if (!test_EnumTrustDomEx(b
, tctx
, handle
)) {
2318 domsid
= talloc_array(tctx
, struct dom_sid
*, num_trusts
);
2319 trustdom_handle
= talloc_array(tctx
, struct policy_handle
, num_trusts
);
2321 for (i
=0; i
< num_trusts
; i
++) {
2322 char *trust_name
= talloc_asprintf(tctx
, "torturedom%02d", i
);
2323 char *trust_sid
= talloc_asprintf(tctx
, "S-1-5-21-97398-379795-100%02d", i
);
2325 domsid
[i
] = dom_sid_parse_talloc(tctx
, trust_sid
);
2327 trustinfo
.sid
= domsid
[i
];
2328 init_lsa_String((struct lsa_String
*)&trustinfo
.name
, trust_name
);
2330 r
.in
.policy_handle
= handle
;
2331 r
.in
.info
= &trustinfo
;
2332 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2333 r
.out
.trustdom_handle
= &trustdom_handle
[i
];
2335 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateTrustedDomain_r(b
, tctx
, &r
),
2336 "CreateTrustedDomain failed");
2337 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
2338 test_DeleteTrustedDomain(b
, tctx
, handle
, trustinfo
.name
);
2339 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateTrustedDomain_r(b
, tctx
, &r
),
2340 "CreateTrustedDomain failed");
2342 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2343 torture_comment(tctx
, "CreateTrustedDomain failed - %s\n", nt_errstr(r
.out
.result
));
2347 q
.in
.trustdom_handle
= &trustdom_handle
[i
];
2348 q
.in
.level
= LSA_TRUSTED_DOMAIN_INFO_INFO_EX
;
2350 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfo_r(b
, tctx
, &q
),
2351 "QueryTrustedDomainInfo failed");
2352 if (!NT_STATUS_IS_OK(q
.out
.result
)) {
2353 torture_comment(tctx
, "QueryTrustedDomainInfo level %d failed - %s\n", q
.in
.level
, nt_errstr(q
.out
.result
));
2355 } else if (!q
.out
.info
) {
2358 if (strcmp(info
->info_ex
.netbios_name
.string
, trustinfo
.name
.string
) != 0) {
2359 torture_comment(tctx
, "QueryTrustedDomainInfo returned inconsistent short name: %s != %s\n",
2360 info
->info_ex
.netbios_name
.string
, trustinfo
.name
.string
);
2363 if (info
->info_ex
.trust_type
!= LSA_TRUST_TYPE_DOWNLEVEL
) {
2364 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
2365 trust_name
, info
->info_ex
.trust_type
, LSA_TRUST_TYPE_DOWNLEVEL
);
2368 if (info
->info_ex
.trust_attributes
!= 0) {
2369 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
2370 trust_name
, info
->info_ex
.trust_attributes
, 0);
2373 if (info
->info_ex
.trust_direction
!= LSA_TRUST_DIRECTION_OUTBOUND
) {
2374 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
2375 trust_name
, info
->info_ex
.trust_direction
, LSA_TRUST_DIRECTION_OUTBOUND
);
2382 /* now that we have some domains to look over, we can test the enum calls */
2383 if (!test_EnumTrustDom(b
, tctx
, handle
)) {
2387 if (!test_EnumTrustDomEx(b
, tctx
, handle
)) {
2391 for (i
=0; i
<num_trusts
; i
++) {
2392 if (!test_DeleteTrustedDomainBySid(b
, tctx
, handle
, domsid
[i
])) {
2400 static bool gen_authinfo_internal(TALLOC_CTX
*mem_ctx
, const char *password
,
2401 DATA_BLOB session_key
,
2402 struct lsa_TrustDomainInfoAuthInfoInternal
**_authinfo_internal
)
2404 struct lsa_TrustDomainInfoAuthInfoInternal
*authinfo_internal
;
2405 struct trustDomainPasswords auth_struct
;
2406 struct AuthenticationInformation
*auth_info_array
;
2407 size_t converted_size
;
2408 DATA_BLOB auth_blob
;
2409 enum ndr_err_code ndr_err
;
2411 authinfo_internal
= talloc_zero(mem_ctx
, struct lsa_TrustDomainInfoAuthInfoInternal
);
2412 if (authinfo_internal
== NULL
) {
2416 auth_info_array
= talloc_array(mem_ctx
,
2417 struct AuthenticationInformation
, 1);
2418 if (auth_info_array
== NULL
) {
2422 generate_random_buffer(auth_struct
.confounder
, sizeof(auth_struct
.confounder
));
2424 auth_info_array
[0].AuthType
= TRUST_AUTH_TYPE_CLEAR
;
2426 if (!convert_string_talloc(mem_ctx
, CH_UNIX
, CH_UTF16
, password
,
2428 &auth_info_array
[0].AuthInfo
.clear
.password
,
2433 auth_info_array
[0].AuthInfo
.clear
.size
= converted_size
;
2435 auth_struct
.outgoing
.count
= 1;
2436 auth_struct
.outgoing
.current
.count
= 1;
2437 auth_struct
.outgoing
.current
.array
= auth_info_array
;
2438 auth_struct
.outgoing
.previous
.count
= 0;
2439 auth_struct
.outgoing
.previous
.array
= NULL
;
2441 auth_struct
.incoming
.count
= 1;
2442 auth_struct
.incoming
.current
.count
= 1;
2443 auth_struct
.incoming
.current
.array
= auth_info_array
;
2444 auth_struct
.incoming
.previous
.count
= 0;
2445 auth_struct
.incoming
.previous
.array
= NULL
;
2448 ndr_err
= ndr_push_struct_blob(&auth_blob
, mem_ctx
, &auth_struct
,
2449 (ndr_push_flags_fn_t
)ndr_push_trustDomainPasswords
);
2450 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2454 arcfour_crypt_blob(auth_blob
.data
, auth_blob
.length
, &session_key
);
2456 authinfo_internal
->auth_blob
.size
= auth_blob
.length
;
2457 authinfo_internal
->auth_blob
.data
= auth_blob
.data
;
2459 *_authinfo_internal
= authinfo_internal
;
2464 static bool gen_authinfo(TALLOC_CTX
*mem_ctx
, const char *password
,
2465 struct lsa_TrustDomainInfoAuthInfo
**_authinfo
)
2467 struct lsa_TrustDomainInfoAuthInfo
*authinfo
;
2468 struct lsa_TrustDomainInfoBuffer
*info_buffer
;
2469 size_t converted_size
;
2471 authinfo
= talloc_zero(mem_ctx
, struct lsa_TrustDomainInfoAuthInfo
);
2472 if (authinfo
== NULL
) {
2476 info_buffer
= talloc_zero(mem_ctx
, struct lsa_TrustDomainInfoBuffer
);
2477 if (info_buffer
== NULL
) {
2481 info_buffer
->AuthType
= TRUST_AUTH_TYPE_CLEAR
;
2483 if (!convert_string_talloc(mem_ctx
, CH_UNIX
, CH_UTF16
, password
,
2485 &info_buffer
->data
.data
,
2490 info_buffer
->data
.size
= converted_size
;
2492 authinfo
->incoming_count
= 1;
2493 authinfo
->incoming_current_auth_info
= info_buffer
;
2494 authinfo
->incoming_previous_auth_info
= NULL
;
2495 authinfo
->outgoing_count
= 1;
2496 authinfo
->outgoing_current_auth_info
= info_buffer
;
2497 authinfo
->outgoing_previous_auth_info
= NULL
;
2499 *_authinfo
= authinfo
;
2504 static bool check_pw_with_ServerAuthenticate3(struct dcerpc_pipe
*p
,
2505 struct torture_context
*tctx
,
2506 uint32_t negotiate_flags
,
2507 struct cli_credentials
*machine_credentials
,
2508 struct netlogon_creds_CredentialState
**creds_out
)
2510 struct netr_ServerReqChallenge r
;
2511 struct netr_ServerAuthenticate3 a
;
2512 struct netr_Credential credentials1
, credentials2
, credentials3
;
2513 struct netlogon_creds_CredentialState
*creds
;
2514 struct samr_Password mach_password
;
2516 const char *machine_name
;
2517 const char *plain_pass
;
2518 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
2520 machine_name
= cli_credentials_get_workstation(machine_credentials
);
2521 plain_pass
= cli_credentials_get_password(machine_credentials
);
2523 r
.in
.server_name
= NULL
;
2524 r
.in
.computer_name
= machine_name
;
2525 r
.in
.credentials
= &credentials1
;
2526 r
.out
.return_credentials
= &credentials2
;
2528 generate_random_buffer(credentials1
.data
, sizeof(credentials1
.data
));
2530 torture_assert_ntstatus_ok(tctx
, dcerpc_netr_ServerReqChallenge_r(b
, tctx
, &r
),
2531 "ServerReqChallenge failed");
2532 torture_assert_ntstatus_ok(tctx
, r
.out
.result
, "ServerReqChallenge failed");
2534 E_md4hash(plain_pass
, mach_password
.hash
);
2536 a
.in
.server_name
= NULL
;
2537 a
.in
.account_name
= talloc_asprintf(tctx
, "%s$", machine_name
);
2538 a
.in
.secure_channel_type
= cli_credentials_get_secure_channel_type(machine_credentials
);
2539 a
.in
.computer_name
= machine_name
;
2540 a
.in
.negotiate_flags
= &negotiate_flags
;
2541 a
.in
.credentials
= &credentials3
;
2542 a
.out
.return_credentials
= &credentials3
;
2543 a
.out
.negotiate_flags
= &negotiate_flags
;
2546 creds
= netlogon_creds_client_init(tctx
, a
.in
.account_name
,
2548 &credentials1
, &credentials2
,
2549 &mach_password
, &credentials3
,
2552 torture_assert(tctx
, creds
!= NULL
, "memory allocation");
2554 torture_assert_ntstatus_ok(tctx
, dcerpc_netr_ServerAuthenticate3_r(b
, tctx
, &a
),
2555 "ServerAuthenticate3 failed");
2556 if (!NT_STATUS_IS_OK(a
.out
.result
)) {
2557 if (!NT_STATUS_EQUAL(a
.out
.result
, NT_STATUS_ACCESS_DENIED
)) {
2558 torture_assert_ntstatus_ok(tctx
, a
.out
.result
,
2559 "ServerAuthenticate3 failed");
2563 torture_assert(tctx
, netlogon_creds_client_check(creds
, &credentials3
), "Credential chaining failed");
2565 /* Prove that requesting a challenge again won't break it */
2566 torture_assert_ntstatus_ok(tctx
, dcerpc_netr_ServerReqChallenge_r(b
, tctx
, &r
),
2567 "ServerReqChallenge failed");
2568 torture_assert_ntstatus_ok(tctx
, r
.out
.result
, "ServerReqChallenge failed");
2574 static bool check_dom_trust_pw(struct dcerpc_pipe
*p
,
2575 struct torture_context
*tctx
,
2576 const char *trusted_dom_name
,
2577 const char *password
)
2579 struct cli_credentials
*credentials
;
2581 struct netlogon_creds_CredentialState
*creds
;
2582 struct dcerpc_pipe
*pipe
;
2586 credentials
= cli_credentials_init(tctx
);
2587 if (credentials
== NULL
) {
2591 dummy
= talloc_asprintf(tctx
, "%s$", trusted_dom_name
);
2592 if (dummy
== NULL
) {
2596 cli_credentials_set_username(credentials
, dummy
, CRED_SPECIFIED
);
2597 cli_credentials_set_password(credentials
, password
, CRED_SPECIFIED
);
2598 cli_credentials_set_workstation(credentials
,
2599 trusted_dom_name
, CRED_SPECIFIED
);
2600 cli_credentials_set_secure_channel_type(credentials
, SEC_CHAN_DOMAIN
);
2602 status
= dcerpc_pipe_connect_b(tctx
, &pipe
, p
->binding
,
2603 &ndr_table_netlogon
,
2604 cli_credentials_init_anon(tctx
),
2605 tctx
->ev
, tctx
->lp_ctx
);
2606 if (!NT_STATUS_IS_OK(status
)) {
2607 torture_comment(tctx
, "dcerpc_pipe_connect_b failed.\n");
2611 ok
= check_pw_with_ServerAuthenticate3(pipe
, tctx
,
2612 NETLOGON_NEG_AUTH2_ADS_FLAGS
,
2613 credentials
, &creds
);
2619 static bool test_CreateTrustedDomainEx_common(struct dcerpc_pipe
*p
,
2620 struct torture_context
*tctx
,
2621 struct policy_handle
*handle
,
2622 uint32_t num_trusts
,
2627 struct lsa_CreateTrustedDomainEx r
;
2628 struct lsa_CreateTrustedDomainEx2 r2
;
2629 struct lsa_TrustDomainInfoInfoEx trustinfo
;
2630 struct lsa_TrustDomainInfoAuthInfoInternal
*authinfo_internal
;
2631 struct lsa_TrustDomainInfoAuthInfo
*authinfo
;
2632 struct dom_sid
**domsid
;
2633 struct policy_handle
*trustdom_handle
;
2634 struct lsa_QueryTrustedDomainInfo q
;
2635 union lsa_TrustedDomainInfo
*info
= NULL
;
2636 DATA_BLOB session_key
;
2638 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
2641 torture_comment(tctx
, "\nTesting CreateTrustedDomainEx2 for %d domains\n", num_trusts
);
2643 torture_comment(tctx
, "\nTesting CreateTrustedDomainEx for %d domains\n", num_trusts
);
2646 domsid
= talloc_array(tctx
, struct dom_sid
*, num_trusts
);
2647 trustdom_handle
= talloc_array(tctx
, struct policy_handle
, num_trusts
);
2649 status
= dcerpc_fetch_session_key(p
, &session_key
);
2650 if (!NT_STATUS_IS_OK(status
)) {
2651 torture_comment(tctx
, "dcerpc_fetch_session_key failed - %s\n", nt_errstr(status
));
2655 for (i
=0; i
< num_trusts
; i
++) {
2656 char *trust_name
= talloc_asprintf(tctx
, "torturedom%02d", i
);
2657 char *trust_name_dns
= talloc_asprintf(tctx
, "torturedom%02d.samba.example.com", i
);
2658 char *trust_sid
= talloc_asprintf(tctx
, "S-1-5-21-97398-379795-100%02d", i
);
2660 domsid
[i
] = dom_sid_parse_talloc(tctx
, trust_sid
);
2662 trustinfo
.sid
= domsid
[i
];
2663 trustinfo
.netbios_name
.string
= trust_name
;
2664 trustinfo
.domain_name
.string
= trust_name_dns
;
2666 /* Create inbound, some outbound, and some
2667 * bi-directional trusts in a repeating pattern based
2670 /* 1 == inbound, 2 == outbound, 3 == both */
2671 trustinfo
.trust_direction
= (i
% 3) + 1;
2673 /* Try different trust types too */
2675 /* 1 == downlevel (NT4), 2 == uplevel (ADS), 3 == MIT (kerberos but not AD) */
2676 trustinfo
.trust_type
= (((i
/ 3) + 1) % 3) + 1;
2678 trustinfo
.trust_attributes
= LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION
;
2680 if (!gen_authinfo_internal(tctx
, TRUSTPW
, session_key
, &authinfo_internal
)) {
2681 torture_comment(tctx
, "gen_authinfo_internal failed");
2685 if (!gen_authinfo(tctx
, TRUSTPW
, &authinfo
)) {
2686 torture_comment(tctx
, "gen_authinfonfo failed");
2692 r2
.in
.policy_handle
= handle
;
2693 r2
.in
.info
= &trustinfo
;
2694 r2
.in
.auth_info_internal
= authinfo_internal
;
2695 r2
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2696 r2
.out
.trustdom_handle
= &trustdom_handle
[i
];
2698 torture_assert_ntstatus_ok(tctx
,
2699 dcerpc_lsa_CreateTrustedDomainEx2_r(b
, tctx
, &r2
),
2700 "CreateTrustedDomainEx2 failed");
2702 status
= r2
.out
.result
;
2705 r
.in
.policy_handle
= handle
;
2706 r
.in
.info
= &trustinfo
;
2707 r
.in
.auth_info
= authinfo
;
2708 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2709 r
.out
.trustdom_handle
= &trustdom_handle
[i
];
2711 torture_assert_ntstatus_ok(tctx
,
2712 dcerpc_lsa_CreateTrustedDomainEx_r(b
, tctx
, &r
),
2713 "CreateTrustedDomainEx failed");
2715 status
= r
.out
.result
;
2718 if (NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
2719 test_DeleteTrustedDomain(b
, tctx
, handle
, trustinfo
.netbios_name
);
2721 torture_assert_ntstatus_ok(tctx
,
2722 dcerpc_lsa_CreateTrustedDomainEx2_r(b
, tctx
, &r2
),
2723 "CreateTrustedDomainEx2 failed");
2724 status
= r2
.out
.result
;
2726 torture_assert_ntstatus_ok(tctx
,
2727 dcerpc_lsa_CreateTrustedDomainEx_r(b
, tctx
, &r
),
2728 "CreateTrustedDomainEx2 failed");
2729 status
= r
.out
.result
;
2732 if (!NT_STATUS_IS_OK(status
)) {
2733 torture_comment(tctx
, "CreateTrustedDomainEx failed2 - %s\n", nt_errstr(status
));
2736 /* For outbound and MIT trusts there is no trust account */
2737 if (trustinfo
.trust_direction
!= 2 &&
2738 trustinfo
.trust_type
!= 3) {
2740 if (torture_setting_bool(tctx
, "samba3", false) ||
2741 torture_setting_bool(tctx
, "samba4", false)) {
2742 torture_comment(tctx
, "skipping trusted domain auth tests against samba");
2744 if (check_dom_trust_pw(p
, tctx
, trust_name
,
2746 torture_comment(tctx
, "Password check passed unexpectedly\n");
2749 if (!check_dom_trust_pw(p
, tctx
, trust_name
,
2751 torture_comment(tctx
, "Password check failed\n");
2757 q
.in
.trustdom_handle
= &trustdom_handle
[i
];
2758 q
.in
.level
= LSA_TRUSTED_DOMAIN_INFO_INFO_EX
;
2760 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfo_r(b
, tctx
, &q
),
2761 "QueryTrustedDomainInfo failed");
2762 if (!NT_STATUS_IS_OK(q
.out
.result
)) {
2763 torture_comment(tctx
, "QueryTrustedDomainInfo level 1 failed - %s\n", nt_errstr(q
.out
.result
));
2765 } else if (!q
.out
.info
) {
2766 torture_comment(tctx
, "QueryTrustedDomainInfo level 1 failed to return an info pointer\n");
2769 if (strcmp(info
->info_ex
.netbios_name
.string
, trustinfo
.netbios_name
.string
) != 0) {
2770 torture_comment(tctx
, "QueryTrustedDomainInfo returned inconsistent short name: %s != %s\n",
2771 info
->info_ex
.netbios_name
.string
, trustinfo
.netbios_name
.string
);
2774 if (info
->info_ex
.trust_type
!= trustinfo
.trust_type
) {
2775 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
2776 trust_name
, info
->info_ex
.trust_type
, trustinfo
.trust_type
);
2779 if (info
->info_ex
.trust_attributes
!= LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION
) {
2780 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
2781 trust_name
, info
->info_ex
.trust_attributes
, LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION
);
2784 if (info
->info_ex
.trust_direction
!= trustinfo
.trust_direction
) {
2785 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
2786 trust_name
, info
->info_ex
.trust_direction
, trustinfo
.trust_direction
);
2793 /* now that we have some domains to look over, we can test the enum calls */
2794 if (!test_EnumTrustDom(b
, tctx
, handle
)) {
2795 torture_comment(tctx
, "test_EnumTrustDom failed\n");
2799 if (!test_EnumTrustDomEx(b
, tctx
, handle
)) {
2800 torture_comment(tctx
, "test_EnumTrustDomEx failed\n");
2804 for (i
=0; i
<num_trusts
; i
++) {
2805 if (!test_DeleteTrustedDomainBySid(b
, tctx
, handle
, domsid
[i
])) {
2806 torture_comment(tctx
, "test_DeleteTrustedDomainBySid failed\n");
2814 static bool test_CreateTrustedDomainEx2(struct dcerpc_pipe
*p
,
2815 struct torture_context
*tctx
,
2816 struct policy_handle
*handle
,
2817 uint32_t num_trusts
)
2819 return test_CreateTrustedDomainEx_common(p
, tctx
, handle
, num_trusts
, true);
2822 static bool test_CreateTrustedDomainEx(struct dcerpc_pipe
*p
,
2823 struct torture_context
*tctx
,
2824 struct policy_handle
*handle
,
2825 uint32_t num_trusts
)
2827 return test_CreateTrustedDomainEx_common(p
, tctx
, handle
, num_trusts
, false);
2830 static bool test_QueryDomainInfoPolicy(struct dcerpc_binding_handle
*b
,
2831 struct torture_context
*tctx
,
2832 struct policy_handle
*handle
)
2834 struct lsa_QueryDomainInformationPolicy r
;
2835 union lsa_DomainInformationPolicy
*info
= NULL
;
2839 if (torture_setting_bool(tctx
, "samba3", false)) {
2840 torture_skip(tctx
, "skipping QueryDomainInformationPolicy test\n");
2843 torture_comment(tctx
, "\nTesting QueryDomainInformationPolicy\n");
2846 r
.in
.handle
= handle
;
2850 torture_comment(tctx
, "\nTrying QueryDomainInformationPolicy level %d\n", i
);
2852 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryDomainInformationPolicy_r(b
, tctx
, &r
),
2853 "QueryDomainInformationPolicy failed");
2855 /* If the server does not support EFS, then this is the correct return */
2856 if (i
== LSA_DOMAIN_INFO_POLICY_EFS
&& NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
2858 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2859 torture_comment(tctx
, "QueryDomainInformationPolicy failed - %s\n", nt_errstr(r
.out
.result
));
2869 static bool test_QueryInfoPolicyCalls( bool version2
,
2870 struct dcerpc_binding_handle
*b
,
2871 struct torture_context
*tctx
,
2872 struct policy_handle
*handle
)
2874 struct lsa_QueryInfoPolicy r
;
2875 union lsa_PolicyInformation
*info
= NULL
;
2878 const char *call
= talloc_asprintf(tctx
, "QueryInfoPolicy%s", version2
? "2":"");
2880 torture_comment(tctx
, "\nTesting %s\n", call
);
2882 if (version2
&& torture_setting_bool(tctx
, "samba3", false)) {
2883 torture_skip(tctx
, "skipping QueryInfoPolicy2 tests\n");
2886 for (i
=1;i
<=14;i
++) {
2887 r
.in
.handle
= handle
;
2891 torture_comment(tctx
, "\nTrying %s level %d\n", call
, i
);
2894 /* We can perform the cast, because both types are
2895 structurally equal */
2896 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryInfoPolicy2_r(b
, tctx
,
2897 (struct lsa_QueryInfoPolicy2
*) &r
),
2898 "QueryInfoPolicy2 failed");
2900 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryInfoPolicy_r(b
, tctx
, &r
),
2901 "QueryInfoPolicy2 failed");
2904 case LSA_POLICY_INFO_MOD
:
2905 case LSA_POLICY_INFO_AUDIT_FULL_SET
:
2906 case LSA_POLICY_INFO_AUDIT_FULL_QUERY
:
2907 if (!NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_INVALID_PARAMETER
)) {
2908 torture_comment(tctx
, "Server should have failed level %u: %s\n", i
, nt_errstr(r
.out
.result
));
2912 case LSA_POLICY_INFO_DOMAIN
:
2913 case LSA_POLICY_INFO_ACCOUNT_DOMAIN
:
2914 case LSA_POLICY_INFO_REPLICA
:
2915 case LSA_POLICY_INFO_QUOTA
:
2916 case LSA_POLICY_INFO_ROLE
:
2917 case LSA_POLICY_INFO_AUDIT_LOG
:
2918 case LSA_POLICY_INFO_AUDIT_EVENTS
:
2919 case LSA_POLICY_INFO_PD
:
2920 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2921 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(r
.out
.result
));
2925 case LSA_POLICY_INFO_L_ACCOUNT_DOMAIN
:
2926 case LSA_POLICY_INFO_DNS_INT
:
2927 case LSA_POLICY_INFO_DNS
:
2928 if (torture_setting_bool(tctx
, "samba3", false)) {
2929 /* Other levels not implemented yet */
2930 if (!NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_INVALID_INFO_CLASS
)) {
2931 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(r
.out
.result
));
2934 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2935 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(r
.out
.result
));
2940 if (torture_setting_bool(tctx
, "samba4", false)) {
2941 /* Other levels not implemented yet */
2942 if (!NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_INVALID_INFO_CLASS
)) {
2943 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(r
.out
.result
));
2946 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2947 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(r
.out
.result
));
2953 if (NT_STATUS_IS_OK(r
.out
.result
) && (i
== LSA_POLICY_INFO_DNS
2954 || i
== LSA_POLICY_INFO_DNS_INT
)) {
2955 /* Let's look up some of these names */
2957 struct lsa_TransNameArray tnames
;
2959 tnames
.names
= talloc_zero_array(tctx
, struct lsa_TranslatedName
, tnames
.count
);
2960 tnames
.names
[0].name
.string
= info
->dns
.name
.string
;
2961 tnames
.names
[0].sid_type
= SID_NAME_DOMAIN
;
2962 tnames
.names
[1].name
.string
= info
->dns
.dns_domain
.string
;
2963 tnames
.names
[1].sid_type
= SID_NAME_DOMAIN
;
2964 tnames
.names
[2].name
.string
= talloc_asprintf(tctx
, "%s\\", info
->dns
.name
.string
);
2965 tnames
.names
[2].sid_type
= SID_NAME_DOMAIN
;
2966 tnames
.names
[3].name
.string
= talloc_asprintf(tctx
, "%s\\", info
->dns
.dns_domain
.string
);
2967 tnames
.names
[3].sid_type
= SID_NAME_DOMAIN
;
2968 tnames
.names
[4].name
.string
= talloc_asprintf(tctx
, "%s\\guest", info
->dns
.name
.string
);
2969 tnames
.names
[4].sid_type
= SID_NAME_USER
;
2970 tnames
.names
[5].name
.string
= talloc_asprintf(tctx
, "%s\\krbtgt", info
->dns
.name
.string
);
2971 tnames
.names
[5].sid_type
= SID_NAME_USER
;
2972 tnames
.names
[6].name
.string
= talloc_asprintf(tctx
, "%s\\guest", info
->dns
.dns_domain
.string
);
2973 tnames
.names
[6].sid_type
= SID_NAME_USER
;
2974 tnames
.names
[7].name
.string
= talloc_asprintf(tctx
, "%s\\krbtgt", info
->dns
.dns_domain
.string
);
2975 tnames
.names
[7].sid_type
= SID_NAME_USER
;
2976 tnames
.names
[8].name
.string
= talloc_asprintf(tctx
, "krbtgt@%s", info
->dns
.name
.string
);
2977 tnames
.names
[8].sid_type
= SID_NAME_USER
;
2978 tnames
.names
[9].name
.string
= talloc_asprintf(tctx
, "krbtgt@%s", info
->dns
.dns_domain
.string
);
2979 tnames
.names
[9].sid_type
= SID_NAME_USER
;
2980 tnames
.names
[10].name
.string
= talloc_asprintf(tctx
, "%s\\"TEST_MACHINENAME
"$", info
->dns
.name
.string
);
2981 tnames
.names
[10].sid_type
= SID_NAME_USER
;
2982 tnames
.names
[11].name
.string
= talloc_asprintf(tctx
, "%s\\"TEST_MACHINENAME
"$", info
->dns
.dns_domain
.string
);
2983 tnames
.names
[11].sid_type
= SID_NAME_USER
;
2984 tnames
.names
[12].name
.string
= talloc_asprintf(tctx
, TEST_MACHINENAME
"$@%s", info
->dns
.name
.string
);
2985 tnames
.names
[12].sid_type
= SID_NAME_USER
;
2986 tnames
.names
[13].name
.string
= talloc_asprintf(tctx
, TEST_MACHINENAME
"$@%s", info
->dns
.dns_domain
.string
);
2987 tnames
.names
[13].sid_type
= SID_NAME_USER
;
2988 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
2996 static bool test_QueryInfoPolicy(struct dcerpc_binding_handle
*b
,
2997 struct torture_context
*tctx
,
2998 struct policy_handle
*handle
)
3000 return test_QueryInfoPolicyCalls(false, b
, tctx
, handle
);
3003 static bool test_QueryInfoPolicy2(struct dcerpc_binding_handle
*b
,
3004 struct torture_context
*tctx
,
3005 struct policy_handle
*handle
)
3007 return test_QueryInfoPolicyCalls(true, b
, tctx
, handle
);
3010 static bool test_GetUserName(struct dcerpc_binding_handle
*b
,
3011 struct torture_context
*tctx
)
3013 struct lsa_GetUserName r
;
3015 struct lsa_String
*authority_name_p
= NULL
;
3016 struct lsa_String
*account_name_p
= NULL
;
3018 torture_comment(tctx
, "\nTesting GetUserName\n");
3020 r
.in
.system_name
= "\\";
3021 r
.in
.account_name
= &account_name_p
;
3022 r
.in
.authority_name
= NULL
;
3023 r
.out
.account_name
= &account_name_p
;
3025 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_GetUserName_r(b
, tctx
, &r
),
3026 "GetUserName failed");
3028 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
3029 torture_comment(tctx
, "GetUserName failed - %s\n", nt_errstr(r
.out
.result
));
3033 account_name_p
= NULL
;
3034 r
.in
.account_name
= &account_name_p
;
3035 r
.in
.authority_name
= &authority_name_p
;
3036 r
.out
.account_name
= &account_name_p
;
3038 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_GetUserName_r(b
, tctx
, &r
),
3039 "GetUserName failed");
3041 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
3042 torture_comment(tctx
, "GetUserName failed - %s\n", nt_errstr(r
.out
.result
));
3049 bool test_lsa_Close(struct dcerpc_binding_handle
*b
,
3050 struct torture_context
*tctx
,
3051 struct policy_handle
*handle
)
3054 struct policy_handle handle2
;
3056 torture_comment(tctx
, "\nTesting Close\n");
3058 r
.in
.handle
= handle
;
3059 r
.out
.handle
= &handle2
;
3061 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_Close_r(b
, tctx
, &r
),
3063 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
3064 torture_comment(tctx
, "Close failed - %s\n",
3065 nt_errstr(r
.out
.result
));
3069 torture_assert_ntstatus_equal(tctx
, dcerpc_lsa_Close_r(b
, tctx
, &r
),
3070 NT_STATUS_RPC_SS_CONTEXT_MISMATCH
, "Close should failed");
3072 torture_comment(tctx
, "\n");
3077 bool torture_rpc_lsa(struct torture_context
*tctx
)
3080 struct dcerpc_pipe
*p
;
3082 struct policy_handle
*handle
;
3083 struct test_join
*join
= NULL
;
3084 struct cli_credentials
*machine_creds
;
3085 struct dcerpc_binding_handle
*b
;
3087 status
= torture_rpc_connection(tctx
, &p
, &ndr_table_lsarpc
);
3088 if (!NT_STATUS_IS_OK(status
)) {
3091 b
= p
->binding_handle
;
3093 if (!test_OpenPolicy(b
, tctx
)) {
3097 if (!test_lsa_OpenPolicy2(b
, tctx
, &handle
)) {
3102 join
= torture_join_domain(tctx
, TEST_MACHINENAME
, ACB_WSTRUST
, &machine_creds
);
3107 if (!test_LookupSids_async(b
, tctx
, handle
)) {
3111 if (!test_QueryDomainInfoPolicy(b
, tctx
, handle
)) {
3115 if (!test_CreateSecret(p
, tctx
, handle
)) {
3119 if (!test_QueryInfoPolicy(b
, tctx
, handle
)) {
3123 if (!test_QueryInfoPolicy2(b
, tctx
, handle
)) {
3127 if (!test_Delete(b
, tctx
, handle
)) {
3131 if (!test_many_LookupSids(p
, tctx
, handle
)) {
3135 if (!test_lsa_Close(b
, tctx
, handle
)) {
3139 torture_leave_domain(tctx
, join
);
3142 if (!test_many_LookupSids(p
, tctx
, handle
)) {
3147 if (!test_GetUserName(b
, tctx
)) {
3154 bool torture_rpc_lsa_get_user(struct torture_context
*tctx
)
3157 struct dcerpc_pipe
*p
;
3159 struct dcerpc_binding_handle
*b
;
3161 status
= torture_rpc_connection(tctx
, &p
, &ndr_table_lsarpc
);
3162 if (!NT_STATUS_IS_OK(status
)) {
3165 b
= p
->binding_handle
;
3167 if (!test_GetUserName(b
, tctx
)) {
3174 static bool testcase_LookupNames(struct torture_context
*tctx
,
3175 struct dcerpc_pipe
*p
)
3178 struct policy_handle
*handle
;
3179 struct lsa_TransNameArray tnames
;
3180 struct lsa_TransNameArray2 tnames2
;
3181 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
3183 if (!test_OpenPolicy(b
, tctx
)) {
3187 if (!test_lsa_OpenPolicy2(b
, tctx
, &handle
)) {
3196 tnames
.names
= talloc_array(tctx
, struct lsa_TranslatedName
, tnames
.count
);
3197 ZERO_STRUCT(tnames
.names
[0]);
3198 tnames
.names
[0].name
.string
= "BUILTIN";
3199 tnames
.names
[0].sid_type
= SID_NAME_DOMAIN
;
3201 if (!test_LookupNames(b
, tctx
, handle
, &tnames
)) {
3206 tnames2
.names
= talloc_array(tctx
, struct lsa_TranslatedName2
, tnames2
.count
);
3207 ZERO_STRUCT(tnames2
.names
[0]);
3208 tnames2
.names
[0].name
.string
= "BUILTIN";
3209 tnames2
.names
[0].sid_type
= SID_NAME_DOMAIN
;
3211 if (!test_LookupNames2(b
, tctx
, handle
, &tnames2
, true)) {
3215 if (!test_LookupNames3(b
, tctx
, handle
, &tnames2
, true)) {
3219 if (!test_LookupNames_wellknown(b
, tctx
, handle
)) {
3223 if (!test_LookupNames_NULL(b
, tctx
, handle
)) {
3227 if (!test_LookupNames_bogus(b
, tctx
, handle
)) {
3231 if (!test_lsa_Close(b
, tctx
, handle
)) {
3238 struct torture_suite
*torture_rpc_lsa_lookup_names(TALLOC_CTX
*mem_ctx
)
3240 struct torture_suite
*suite
;
3241 struct torture_rpc_tcase
*tcase
;
3243 suite
= torture_suite_create(mem_ctx
, "lsa.lookupnames");
3245 tcase
= torture_suite_add_rpc_iface_tcase(suite
, "lsa",
3247 torture_rpc_tcase_add_test(tcase
, "LookupNames",
3248 testcase_LookupNames
);
3253 struct lsa_trustdom_state
{
3254 uint32_t num_trusts
;
3257 static bool testcase_TrustedDomains(struct torture_context
*tctx
,
3258 struct dcerpc_pipe
*p
,
3262 struct policy_handle
*handle
;
3263 struct lsa_trustdom_state
*state
=
3264 talloc_get_type_abort(data
, struct lsa_trustdom_state
);
3265 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
3267 torture_comment(tctx
, "Testing %d domains\n", state
->num_trusts
);
3269 if (!test_OpenPolicy(b
, tctx
)) {
3273 if (!test_lsa_OpenPolicy2(b
, tctx
, &handle
)) {
3281 if (!test_CreateTrustedDomain(b
, tctx
, handle
, state
->num_trusts
)) {
3285 if (!test_CreateTrustedDomainEx(p
, tctx
, handle
, state
->num_trusts
)) {
3289 if (!test_CreateTrustedDomainEx2(p
, tctx
, handle
, state
->num_trusts
)) {
3293 if (!test_lsa_Close(b
, tctx
, handle
)) {
3300 struct torture_suite
*torture_rpc_lsa_trusted_domains(TALLOC_CTX
*mem_ctx
)
3302 struct torture_suite
*suite
;
3303 struct torture_rpc_tcase
*tcase
;
3304 struct lsa_trustdom_state
*state
;
3306 state
= talloc(mem_ctx
, struct lsa_trustdom_state
);
3308 state
->num_trusts
= 12;
3310 suite
= torture_suite_create(mem_ctx
, "lsa.trusted.domains");
3312 tcase
= torture_suite_add_rpc_iface_tcase(suite
, "lsa",
3314 torture_rpc_tcase_add_test_ex(tcase
, "TrustedDomains",
3315 testcase_TrustedDomains
,
3321 static bool testcase_Privileges(struct torture_context
*tctx
,
3322 struct dcerpc_pipe
*p
)
3325 struct policy_handle
*handle
;
3326 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
3328 if (!test_OpenPolicy(b
, tctx
)) {
3332 if (!test_lsa_OpenPolicy2(b
, tctx
, &handle
)) {
3340 if (!test_CreateAccount(b
, tctx
, handle
)) {
3344 if (!test_EnumAccounts(b
, tctx
, handle
)) {
3348 if (!test_EnumPrivs(b
, tctx
, handle
)) {
3352 if (!test_lsa_Close(b
, tctx
, handle
)) {
3360 struct torture_suite
*torture_rpc_lsa_privileges(TALLOC_CTX
*mem_ctx
)
3362 struct torture_suite
*suite
;
3363 struct torture_rpc_tcase
*tcase
;
3365 suite
= torture_suite_create(mem_ctx
, "lsa.privileges");
3367 tcase
= torture_suite_add_rpc_iface_tcase(suite
, "lsa",
3369 torture_rpc_tcase_add_test(tcase
, "Privileges",
3370 testcase_Privileges
);