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 "lib/events/events.h"
28 #include "libcli/security/security.h"
29 #include "libcli/auth/libcli_auth.h"
30 #include "torture/rpc/torture_rpc.h"
31 #include "param/param.h"
32 #include "../lib/crypto/crypto.h"
33 #define TEST_MACHINENAME "lsatestmach"
35 static void init_lsa_String(struct lsa_String
*name
, const char *s
)
40 static bool test_OpenPolicy(struct dcerpc_binding_handle
*b
,
41 struct torture_context
*tctx
)
43 struct lsa_ObjectAttribute attr
;
44 struct policy_handle handle
;
45 struct lsa_QosInfo qos
;
46 struct lsa_OpenPolicy r
;
47 uint16_t system_name
= '\\';
49 torture_comment(tctx
, "\nTesting OpenPolicy\n");
52 qos
.impersonation_level
= 2;
54 qos
.effective_only
= 0;
58 attr
.object_name
= NULL
;
63 r
.in
.system_name
= &system_name
;
65 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
66 r
.out
.handle
= &handle
;
68 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenPolicy_r(b
, tctx
, &r
),
70 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
71 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_ACCESS_DENIED
) ||
72 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
73 torture_comment(tctx
, "not considering %s to be an error\n",
74 nt_errstr(r
.out
.result
));
77 torture_comment(tctx
, "OpenPolicy failed - %s\n",
78 nt_errstr(r
.out
.result
));
86 bool test_lsa_OpenPolicy2_ex(struct dcerpc_binding_handle
*b
,
87 struct torture_context
*tctx
,
88 struct policy_handle
**handle
,
89 NTSTATUS expected_status
)
91 struct lsa_ObjectAttribute attr
;
92 struct lsa_QosInfo qos
;
93 struct lsa_OpenPolicy2 r
;
96 torture_comment(tctx
, "\nTesting OpenPolicy2\n");
98 *handle
= talloc(tctx
, struct policy_handle
);
104 qos
.impersonation_level
= 2;
105 qos
.context_mode
= 1;
106 qos
.effective_only
= 0;
109 attr
.root_dir
= NULL
;
110 attr
.object_name
= NULL
;
112 attr
.sec_desc
= NULL
;
115 r
.in
.system_name
= "\\";
117 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
118 r
.out
.handle
= *handle
;
120 status
= dcerpc_lsa_OpenPolicy2_r(b
, tctx
, &r
);
121 torture_assert_ntstatus_equal(tctx
, status
, expected_status
,
122 "OpenPolicy2 failed");
123 if (!NT_STATUS_IS_OK(expected_status
)) {
126 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
127 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_ACCESS_DENIED
) ||
128 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
129 torture_comment(tctx
, "not considering %s to be an error\n",
130 nt_errstr(r
.out
.result
));
131 talloc_free(*handle
);
135 torture_comment(tctx
, "OpenPolicy2 failed - %s\n",
136 nt_errstr(r
.out
.result
));
144 bool test_lsa_OpenPolicy2(struct dcerpc_binding_handle
*b
,
145 struct torture_context
*tctx
,
146 struct policy_handle
**handle
)
148 return test_lsa_OpenPolicy2_ex(b
, tctx
, handle
, NT_STATUS_OK
);
151 static const char *sid_type_lookup(enum lsa_SidType r
)
154 case SID_NAME_USE_NONE
: return "SID_NAME_USE_NONE"; break;
155 case SID_NAME_USER
: return "SID_NAME_USER"; break;
156 case SID_NAME_DOM_GRP
: return "SID_NAME_DOM_GRP"; break;
157 case SID_NAME_DOMAIN
: return "SID_NAME_DOMAIN"; break;
158 case SID_NAME_ALIAS
: return "SID_NAME_ALIAS"; break;
159 case SID_NAME_WKN_GRP
: return "SID_NAME_WKN_GRP"; break;
160 case SID_NAME_DELETED
: return "SID_NAME_DELETED"; break;
161 case SID_NAME_INVALID
: return "SID_NAME_INVALID"; break;
162 case SID_NAME_UNKNOWN
: return "SID_NAME_UNKNOWN"; break;
163 case SID_NAME_COMPUTER
: return "SID_NAME_COMPUTER"; break;
165 return "Invalid sid type\n";
168 static bool test_LookupNames(struct dcerpc_binding_handle
*b
,
169 struct torture_context
*tctx
,
170 struct policy_handle
*handle
,
171 struct lsa_TransNameArray
*tnames
)
173 struct lsa_LookupNames r
;
174 struct lsa_TransSidArray sids
;
175 struct lsa_RefDomainList
*domains
= NULL
;
176 struct lsa_String
*names
;
181 torture_comment(tctx
, "\nTesting LookupNames with %d names\n", tnames
->count
);
189 input_idx
= talloc_array(tctx
, uint32_t, tnames
->count
);
190 names
= talloc_array(tctx
, struct lsa_String
, tnames
->count
);
192 for (i
=0;i
<tnames
->count
;i
++) {
193 if (tnames
->names
[i
].sid_type
!= SID_NAME_UNKNOWN
) {
194 init_lsa_String(&names
[r
.in
.num_names
], tnames
->names
[i
].name
.string
);
195 input_idx
[r
.in
.num_names
] = i
;
200 r
.in
.handle
= handle
;
205 r
.out
.count
= &count
;
207 r
.out
.domains
= &domains
;
209 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames_r(b
, tctx
, &r
),
210 "LookupNames failed");
211 if (NT_STATUS_EQUAL(r
.out
.result
, STATUS_SOME_UNMAPPED
) ||
212 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NONE_MAPPED
)) {
213 for (i
=0;i
< r
.in
.num_names
;i
++) {
214 if (i
< count
&& sids
.sids
[i
].sid_type
== SID_NAME_UNKNOWN
) {
215 torture_comment(tctx
, "LookupName of %s was unmapped\n",
216 tnames
->names
[i
].name
.string
);
217 } else if (i
>=count
) {
218 torture_comment(tctx
, "LookupName of %s failed to return a result\n",
219 tnames
->names
[i
].name
.string
);
222 torture_comment(tctx
, "LookupNames failed - %s\n",
223 nt_errstr(r
.out
.result
));
225 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
226 torture_comment(tctx
, "LookupNames failed - %s\n",
227 nt_errstr(r
.out
.result
));
231 for (i
=0;i
< r
.in
.num_names
;i
++) {
233 if (sids
.sids
[i
].sid_type
!= tnames
->names
[input_idx
[i
]].sid_type
) {
234 torture_comment(tctx
, "LookupName of %s got unexpected name type: %s\n",
235 tnames
->names
[input_idx
[i
]].name
.string
,
236 sid_type_lookup(sids
.sids
[i
].sid_type
));
239 if ((sids
.sids
[i
].sid_type
== SID_NAME_DOMAIN
) &&
240 (sids
.sids
[i
].rid
!= (uint32_t)-1)) {
241 torture_comment(tctx
, "LookupName of %s got unexpected rid: %d\n",
242 tnames
->names
[input_idx
[i
]].name
.string
, sids
.sids
[i
].rid
);
245 } else if (i
>=count
) {
246 torture_comment(tctx
, "LookupName of %s failed to return a result\n",
247 tnames
->names
[input_idx
[i
]].name
.string
);
251 torture_comment(tctx
, "\n");
256 static bool test_LookupNames_bogus(struct dcerpc_binding_handle
*b
,
257 struct torture_context
*tctx
,
258 struct policy_handle
*handle
)
260 struct lsa_LookupNames r
;
261 struct lsa_TransSidArray sids
;
262 struct lsa_RefDomainList
*domains
= NULL
;
263 struct lsa_String names
[1];
266 torture_comment(tctx
, "\nTesting LookupNames with bogus name\n");
271 init_lsa_String(&names
[0], "NT AUTHORITY\\BOGUS");
273 r
.in
.handle
= handle
;
279 r
.out
.count
= &count
;
281 r
.out
.domains
= &domains
;
283 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames_r(b
, tctx
, &r
),
284 "LookupNames bogus failed");
285 if (!NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NONE_MAPPED
)) {
286 torture_comment(tctx
, "LookupNames failed - %s\n",
287 nt_errstr(r
.out
.result
));
291 torture_comment(tctx
, "\n");
296 static bool test_LookupNames_NULL(struct dcerpc_binding_handle
*b
,
297 struct torture_context
*tctx
,
298 struct policy_handle
*handle
)
300 struct lsa_LookupNames r
;
301 struct lsa_TransSidArray sids
;
302 struct lsa_RefDomainList
*domains
= NULL
;
303 struct lsa_String names
[1];
306 torture_comment(tctx
, "\nTesting LookupNames with NULL name\n");
311 names
[0].string
= NULL
;
313 r
.in
.handle
= handle
;
319 r
.out
.count
= &count
;
321 r
.out
.domains
= &domains
;
323 /* nt4 returns NT_STATUS_NONE_MAPPED with sid_type
324 * SID_NAME_UNKNOWN, rid 0, and sid_index -1;
326 * w2k3/w2k8 return NT_STATUS_OK with sid_type
327 * SID_NAME_DOMAIN, rid -1 and sid_index 0 and BUILTIN domain
330 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames_r(b
, tctx
, &r
),
331 "LookupNames with NULL name failed");
332 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
333 "LookupNames with NULL name failed");
335 torture_comment(tctx
, "\n");
340 static bool test_LookupNames_wellknown(struct dcerpc_binding_handle
*b
,
341 struct torture_context
*tctx
,
342 struct policy_handle
*handle
)
344 struct lsa_TranslatedName name
;
345 struct lsa_TransNameArray tnames
;
348 torture_comment(tctx
, "Testing LookupNames with well known names\n");
350 tnames
.names
= &name
;
352 name
.name
.string
= "NT AUTHORITY\\SYSTEM";
353 name
.sid_type
= SID_NAME_WKN_GRP
;
354 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
356 name
.name
.string
= "NT AUTHORITY\\ANONYMOUS LOGON";
357 name
.sid_type
= SID_NAME_WKN_GRP
;
358 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
360 name
.name
.string
= "NT AUTHORITY\\Authenticated Users";
361 name
.sid_type
= SID_NAME_WKN_GRP
;
362 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
365 name
.name
.string
= "NT AUTHORITY";
366 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
368 name
.name
.string
= "NT AUTHORITY\\";
369 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
372 name
.name
.string
= "BUILTIN\\";
373 name
.sid_type
= SID_NAME_DOMAIN
;
374 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
376 name
.name
.string
= "BUILTIN\\Administrators";
377 name
.sid_type
= SID_NAME_ALIAS
;
378 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
380 name
.name
.string
= "SYSTEM";
381 name
.sid_type
= SID_NAME_WKN_GRP
;
382 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
384 name
.name
.string
= "Everyone";
385 name
.sid_type
= SID_NAME_WKN_GRP
;
386 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
390 static bool test_LookupNames2(struct dcerpc_binding_handle
*b
,
391 struct torture_context
*tctx
,
392 struct policy_handle
*handle
,
393 struct lsa_TransNameArray2
*tnames
,
396 struct lsa_LookupNames2 r
;
397 struct lsa_TransSidArray2 sids
;
398 struct lsa_RefDomainList
*domains
= NULL
;
399 struct lsa_String
*names
;
403 torture_comment(tctx
, "\nTesting LookupNames2 with %d names\n", tnames
->count
);
411 input_idx
= talloc_array(tctx
, uint32_t, tnames
->count
);
412 names
= talloc_array(tctx
, struct lsa_String
, tnames
->count
);
414 for (i
=0;i
<tnames
->count
;i
++) {
415 if (tnames
->names
[i
].sid_type
!= SID_NAME_UNKNOWN
) {
416 init_lsa_String(&names
[r
.in
.num_names
], tnames
->names
[i
].name
.string
);
417 input_idx
[r
.in
.num_names
] = i
;
422 r
.in
.handle
= handle
;
427 r
.in
.lookup_options
= 0;
428 r
.in
.client_revision
= 0;
429 r
.out
.count
= &count
;
431 r
.out
.domains
= &domains
;
433 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames2_r(b
, tctx
, &r
),
434 "LookupNames2 failed");
435 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
436 torture_comment(tctx
, "LookupNames2 failed - %s\n",
437 nt_errstr(r
.out
.result
));
442 torture_assert_int_equal(tctx
, count
, sids
.count
,
443 "unexpected number of results returned");
444 if (sids
.count
> 0) {
445 torture_assert(tctx
, sids
.sids
, "invalid sid buffer");
449 torture_comment(tctx
, "\n");
455 static bool test_LookupNames3(struct dcerpc_binding_handle
*b
,
456 struct torture_context
*tctx
,
457 struct policy_handle
*handle
,
458 struct lsa_TransNameArray2
*tnames
,
461 struct lsa_LookupNames3 r
;
462 struct lsa_TransSidArray3 sids
;
463 struct lsa_RefDomainList
*domains
= NULL
;
464 struct lsa_String
*names
;
469 torture_comment(tctx
, "\nTesting LookupNames3 with %d names\n", tnames
->count
);
476 input_idx
= talloc_array(tctx
, uint32_t, tnames
->count
);
477 names
= talloc_array(tctx
, struct lsa_String
, tnames
->count
);
478 for (i
=0;i
<tnames
->count
;i
++) {
479 if (tnames
->names
[i
].sid_type
!= SID_NAME_UNKNOWN
) {
480 init_lsa_String(&names
[r
.in
.num_names
], tnames
->names
[i
].name
.string
);
481 input_idx
[r
.in
.num_names
] = i
;
486 r
.in
.handle
= handle
;
491 r
.in
.lookup_options
= 0;
492 r
.in
.client_revision
= 0;
493 r
.out
.count
= &count
;
495 r
.out
.domains
= &domains
;
497 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames3_r(b
, tctx
, &r
),
498 "LookupNames3 failed");
499 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
500 torture_comment(tctx
, "LookupNames3 failed - %s\n",
501 nt_errstr(r
.out
.result
));
506 torture_assert_int_equal(tctx
, count
, sids
.count
,
507 "unexpected number of results returned");
508 if (sids
.count
> 0) {
509 torture_assert(tctx
, sids
.sids
, "invalid sid buffer");
513 torture_comment(tctx
, "\n");
518 static bool test_LookupNames4(struct dcerpc_binding_handle
*b
,
519 struct torture_context
*tctx
,
520 struct lsa_TransNameArray2
*tnames
,
523 struct lsa_LookupNames4 r
;
524 struct lsa_TransSidArray3 sids
;
525 struct lsa_RefDomainList
*domains
= NULL
;
526 struct lsa_String
*names
;
531 torture_comment(tctx
, "\nTesting LookupNames4 with %d names\n", tnames
->count
);
538 input_idx
= talloc_array(tctx
, uint32_t, tnames
->count
);
539 names
= talloc_array(tctx
, struct lsa_String
, tnames
->count
);
540 for (i
=0;i
<tnames
->count
;i
++) {
541 if (tnames
->names
[i
].sid_type
!= SID_NAME_UNKNOWN
) {
542 init_lsa_String(&names
[r
.in
.num_names
], tnames
->names
[i
].name
.string
);
543 input_idx
[r
.in
.num_names
] = i
;
548 r
.in
.num_names
= tnames
->count
;
553 r
.in
.lookup_options
= 0;
554 r
.in
.client_revision
= 0;
555 r
.out
.count
= &count
;
557 r
.out
.domains
= &domains
;
559 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames4_r(b
, tctx
, &r
),
560 "LookupNames4 failed");
561 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
562 torture_comment(tctx
, "LookupNames4 failed - %s\n",
563 nt_errstr(r
.out
.result
));
568 torture_assert_int_equal(tctx
, count
, sids
.count
,
569 "unexpected number of results returned");
570 if (sids
.count
> 0) {
571 torture_assert(tctx
, sids
.sids
, "invalid sid buffer");
575 torture_comment(tctx
, "\n");
581 static bool test_LookupSids(struct dcerpc_binding_handle
*b
,
582 struct torture_context
*tctx
,
583 struct policy_handle
*handle
,
584 struct lsa_SidArray
*sids
)
586 struct lsa_LookupSids r
;
587 struct lsa_TransNameArray names
;
588 struct lsa_RefDomainList
*domains
= NULL
;
589 uint32_t count
= sids
->num_sids
;
591 torture_comment(tctx
, "\nTesting LookupSids\n");
596 r
.in
.handle
= handle
;
601 r
.out
.count
= &count
;
602 r
.out
.names
= &names
;
603 r
.out
.domains
= &domains
;
605 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupSids_r(b
, tctx
, &r
),
606 "LookupSids failed");
607 if (!NT_STATUS_IS_OK(r
.out
.result
) &&
608 !NT_STATUS_EQUAL(r
.out
.result
, STATUS_SOME_UNMAPPED
)) {
609 torture_comment(tctx
, "LookupSids failed - %s\n",
610 nt_errstr(r
.out
.result
));
614 torture_comment(tctx
, "\n");
616 if (!test_LookupNames(b
, tctx
, handle
, &names
)) {
624 static bool test_LookupSids2(struct dcerpc_binding_handle
*b
,
625 struct torture_context
*tctx
,
626 struct policy_handle
*handle
,
627 struct lsa_SidArray
*sids
)
629 struct lsa_LookupSids2 r
;
630 struct lsa_TransNameArray2 names
;
631 struct lsa_RefDomainList
*domains
= NULL
;
632 uint32_t count
= sids
->num_sids
;
634 torture_comment(tctx
, "\nTesting LookupSids2\n");
639 r
.in
.handle
= handle
;
644 r
.in
.lookup_options
= 0;
645 r
.in
.client_revision
= 0;
646 r
.out
.count
= &count
;
647 r
.out
.names
= &names
;
648 r
.out
.domains
= &domains
;
650 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupSids2_r(b
, tctx
, &r
),
651 "LookupSids2 failed");
652 if (!NT_STATUS_IS_OK(r
.out
.result
) &&
653 !NT_STATUS_EQUAL(r
.out
.result
, STATUS_SOME_UNMAPPED
)) {
654 torture_comment(tctx
, "LookupSids2 failed - %s\n",
655 nt_errstr(r
.out
.result
));
659 torture_comment(tctx
, "\n");
661 if (!test_LookupNames2(b
, tctx
, handle
, &names
, false)) {
665 if (!test_LookupNames3(b
, tctx
, handle
, &names
, false)) {
672 static bool test_LookupSids3(struct dcerpc_binding_handle
*b
,
673 struct torture_context
*tctx
,
674 struct lsa_SidArray
*sids
)
676 struct lsa_LookupSids3 r
;
677 struct lsa_TransNameArray2 names
;
678 struct lsa_RefDomainList
*domains
= NULL
;
679 uint32_t count
= sids
->num_sids
;
681 torture_comment(tctx
, "\nTesting LookupSids3\n");
690 r
.in
.lookup_options
= 0;
691 r
.in
.client_revision
= 0;
692 r
.out
.domains
= &domains
;
693 r
.out
.count
= &count
;
694 r
.out
.names
= &names
;
696 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupSids3_r(b
, tctx
, &r
),
697 "LookupSids3 failed");
698 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
699 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_ACCESS_DENIED
) ||
700 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
701 torture_comment(tctx
, "not considering %s to be an error\n",
702 nt_errstr(r
.out
.result
));
705 torture_comment(tctx
, "LookupSids3 failed - %s - not considered an error\n",
706 nt_errstr(r
.out
.result
));
710 torture_comment(tctx
, "\n");
712 if (!test_LookupNames4(b
, tctx
, &names
, false)) {
719 bool test_many_LookupSids(struct dcerpc_pipe
*p
,
720 struct torture_context
*tctx
,
721 struct policy_handle
*handle
)
724 struct lsa_SidArray sids
;
726 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
728 torture_comment(tctx
, "\nTesting LookupSids with lots of SIDs\n");
732 sids
.sids
= talloc_array(tctx
, struct lsa_SidPtr
, sids
.num_sids
);
734 for (i
=0; i
<sids
.num_sids
; i
++) {
735 const char *sidstr
= "S-1-5-32-545";
736 sids
.sids
[i
].sid
= dom_sid_parse_talloc(tctx
, sidstr
);
739 count
= sids
.num_sids
;
742 struct lsa_LookupSids r
;
743 struct lsa_TransNameArray names
;
744 struct lsa_RefDomainList
*domains
= NULL
;
748 r
.in
.handle
= handle
;
752 r
.in
.count
= &names
.count
;
753 r
.out
.count
= &count
;
754 r
.out
.names
= &names
;
755 r
.out
.domains
= &domains
;
757 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupSids_r(b
, tctx
, &r
),
758 "LookupSids failed");
759 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
760 torture_comment(tctx
, "LookupSids failed - %s\n",
761 nt_errstr(r
.out
.result
));
765 torture_comment(tctx
, "\n");
767 if (!test_LookupNames(b
, tctx
, handle
, &names
)) {
770 } else if (p
->conn
->security_state
.auth_info
->auth_type
== DCERPC_AUTH_TYPE_SCHANNEL
&&
771 p
->conn
->security_state
.auth_info
->auth_level
>= DCERPC_AUTH_LEVEL_INTEGRITY
) {
772 struct lsa_LookupSids3 r
;
773 struct lsa_RefDomainList
*domains
= NULL
;
774 struct lsa_TransNameArray2 names
;
779 torture_comment(tctx
, "\nTesting LookupSids3\n");
785 r
.in
.lookup_options
= 0;
786 r
.in
.client_revision
= 0;
787 r
.out
.count
= &count
;
788 r
.out
.names
= &names
;
789 r
.out
.domains
= &domains
;
791 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupSids3_r(b
, tctx
, &r
),
792 "LookupSids3 failed");
793 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
794 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_ACCESS_DENIED
) ||
795 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
796 torture_comment(tctx
, "not considering %s to be an error\n",
797 nt_errstr(r
.out
.result
));
800 torture_comment(tctx
, "LookupSids3 failed - %s\n",
801 nt_errstr(r
.out
.result
));
804 if (!test_LookupNames4(b
, tctx
, &names
, false)) {
809 torture_comment(tctx
, "\n");
816 static void lookupsids_cb(struct tevent_req
*subreq
)
818 int *replies
= (int *)tevent_req_callback_data_void(subreq
);
821 status
= dcerpc_lsa_LookupSids_r_recv(subreq
, subreq
);
823 if (!NT_STATUS_IS_OK(status
)) {
824 printf("lookupsids returned %s\n", nt_errstr(status
));
833 static bool test_LookupSids_async(struct dcerpc_binding_handle
*b
,
834 struct torture_context
*tctx
,
835 struct policy_handle
*handle
)
837 struct lsa_SidArray sids
;
838 struct lsa_SidPtr sidptr
;
840 struct lsa_TransNameArray
*names
;
841 struct lsa_LookupSids
*r
;
842 struct lsa_RefDomainList
*domains
= NULL
;
843 struct tevent_req
**req
;
846 const int num_async_requests
= 50;
848 count
= talloc_array(tctx
, uint32_t, num_async_requests
);
849 names
= talloc_array(tctx
, struct lsa_TransNameArray
, num_async_requests
);
850 r
= talloc_array(tctx
, struct lsa_LookupSids
, num_async_requests
);
852 torture_comment(tctx
, "\nTesting %d async lookupsids request\n", num_async_requests
);
854 req
= talloc_array(tctx
, struct tevent_req
*, num_async_requests
);
858 sidptr
.sid
= dom_sid_parse_talloc(tctx
, "S-1-5-32-545");
862 for (i
=0; i
<num_async_requests
; i
++) {
865 names
[i
].names
= NULL
;
867 r
[i
].in
.handle
= handle
;
868 r
[i
].in
.sids
= &sids
;
869 r
[i
].in
.names
= &names
[i
];
871 r
[i
].in
.count
= &names
[i
].count
;
872 r
[i
].out
.count
= &count
[i
];
873 r
[i
].out
.names
= &names
[i
];
874 r
[i
].out
.domains
= &domains
;
876 req
[i
] = dcerpc_lsa_LookupSids_r_send(tctx
, tctx
->ev
, b
, &r
[i
]);
877 if (req
[i
] == NULL
) {
882 tevent_req_set_callback(req
[i
], lookupsids_cb
, &replies
);
885 while (replies
>= 0 && replies
< num_async_requests
) {
886 event_loop_once(tctx
->ev
);
898 static bool test_LookupPrivValue(struct dcerpc_binding_handle
*b
,
899 struct torture_context
*tctx
,
900 struct policy_handle
*handle
,
901 struct lsa_String
*name
)
903 struct lsa_LookupPrivValue r
;
904 struct lsa_LUID luid
;
906 r
.in
.handle
= handle
;
910 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupPrivValue_r(b
, tctx
, &r
),
911 "LookupPrivValue failed");
912 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
913 torture_comment(tctx
, "\nLookupPrivValue failed - %s\n",
914 nt_errstr(r
.out
.result
));
921 static bool test_LookupPrivName(struct dcerpc_binding_handle
*b
,
922 struct torture_context
*tctx
,
923 struct policy_handle
*handle
,
924 struct lsa_LUID
*luid
)
926 struct lsa_LookupPrivName r
;
927 struct lsa_StringLarge
*name
= NULL
;
929 r
.in
.handle
= handle
;
933 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupPrivName_r(b
, tctx
, &r
),
934 "LookupPrivName failed");
935 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
936 torture_comment(tctx
, "\nLookupPrivName failed - %s\n",
937 nt_errstr(r
.out
.result
));
944 static bool test_RemovePrivilegesFromAccount(struct dcerpc_binding_handle
*b
,
945 struct torture_context
*tctx
,
946 struct policy_handle
*handle
,
947 struct policy_handle
*acct_handle
,
948 struct lsa_LUID
*luid
)
950 struct lsa_RemovePrivilegesFromAccount r
;
951 struct lsa_PrivilegeSet privs
;
954 torture_comment(tctx
, "\nTesting RemovePrivilegesFromAccount\n");
956 r
.in
.handle
= acct_handle
;
962 privs
.set
= talloc_array(tctx
, struct lsa_LUIDAttribute
, 1);
963 privs
.set
[0].luid
= *luid
;
964 privs
.set
[0].attribute
= 0;
966 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_RemovePrivilegesFromAccount_r(b
, tctx
, &r
),
967 "RemovePrivilegesFromAccount failed");
968 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
970 struct lsa_LookupPrivName r_name
;
971 struct lsa_StringLarge
*name
= NULL
;
973 r_name
.in
.handle
= handle
;
974 r_name
.in
.luid
= luid
;
975 r_name
.out
.name
= &name
;
977 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupPrivName_r(b
, tctx
, &r_name
),
978 "LookupPrivName failed");
979 if (!NT_STATUS_IS_OK(r_name
.out
.result
)) {
980 torture_comment(tctx
, "\nLookupPrivName failed - %s\n",
981 nt_errstr(r_name
.out
.result
));
984 /* Windows 2008 does not allow this to be removed */
985 if (strcmp("SeAuditPrivilege", name
->string
) == 0) {
989 torture_comment(tctx
, "RemovePrivilegesFromAccount failed to remove %s - %s\n",
991 nt_errstr(r
.out
.result
));
998 static bool test_AddPrivilegesToAccount(struct dcerpc_binding_handle
*b
,
999 struct torture_context
*tctx
,
1000 struct policy_handle
*acct_handle
,
1001 struct lsa_LUID
*luid
)
1003 struct lsa_AddPrivilegesToAccount r
;
1004 struct lsa_PrivilegeSet privs
;
1007 torture_comment(tctx
, "\nTesting AddPrivilegesToAccount\n");
1009 r
.in
.handle
= acct_handle
;
1010 r
.in
.privs
= &privs
;
1014 privs
.set
= talloc_array(tctx
, struct lsa_LUIDAttribute
, 1);
1015 privs
.set
[0].luid
= *luid
;
1016 privs
.set
[0].attribute
= 0;
1018 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_AddPrivilegesToAccount_r(b
, tctx
, &r
),
1019 "AddPrivilegesToAccount failed");
1020 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1021 torture_comment(tctx
, "AddPrivilegesToAccount failed - %s\n",
1022 nt_errstr(r
.out
.result
));
1029 static bool test_EnumPrivsAccount(struct dcerpc_binding_handle
*b
,
1030 struct torture_context
*tctx
,
1031 struct policy_handle
*handle
,
1032 struct policy_handle
*acct_handle
)
1034 struct lsa_EnumPrivsAccount r
;
1035 struct lsa_PrivilegeSet
*privs
= NULL
;
1038 torture_comment(tctx
, "\nTesting EnumPrivsAccount\n");
1040 r
.in
.handle
= acct_handle
;
1041 r
.out
.privs
= &privs
;
1043 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumPrivsAccount_r(b
, tctx
, &r
),
1044 "EnumPrivsAccount failed");
1045 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1046 torture_comment(tctx
, "EnumPrivsAccount failed - %s\n",
1047 nt_errstr(r
.out
.result
));
1051 if (privs
&& privs
->count
> 0) {
1053 for (i
=0;i
<privs
->count
;i
++) {
1054 test_LookupPrivName(b
, tctx
, handle
,
1055 &privs
->set
[i
].luid
);
1058 ret
&= test_RemovePrivilegesFromAccount(b
, tctx
, handle
, acct_handle
,
1059 &privs
->set
[0].luid
);
1060 ret
&= test_AddPrivilegesToAccount(b
, tctx
, acct_handle
,
1061 &privs
->set
[0].luid
);
1067 static bool test_GetSystemAccessAccount(struct dcerpc_binding_handle
*b
,
1068 struct torture_context
*tctx
,
1069 struct policy_handle
*handle
,
1070 struct policy_handle
*acct_handle
)
1072 uint32_t access_mask
;
1073 struct lsa_GetSystemAccessAccount r
;
1075 torture_comment(tctx
, "\nTesting GetSystemAccessAccount\n");
1077 r
.in
.handle
= acct_handle
;
1078 r
.out
.access_mask
= &access_mask
;
1080 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_GetSystemAccessAccount_r(b
, tctx
, &r
),
1081 "GetSystemAccessAccount failed");
1082 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1083 torture_comment(tctx
, "GetSystemAccessAccount failed - %s\n",
1084 nt_errstr(r
.out
.result
));
1088 if (r
.out
.access_mask
!= NULL
) {
1089 torture_comment(tctx
, "Rights:");
1090 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_INTERACTIVE
)
1091 torture_comment(tctx
, " LSA_POLICY_MODE_INTERACTIVE");
1092 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_NETWORK
)
1093 torture_comment(tctx
, " LSA_POLICY_MODE_NETWORK");
1094 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_BATCH
)
1095 torture_comment(tctx
, " LSA_POLICY_MODE_BATCH");
1096 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_SERVICE
)
1097 torture_comment(tctx
, " LSA_POLICY_MODE_SERVICE");
1098 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_PROXY
)
1099 torture_comment(tctx
, " LSA_POLICY_MODE_PROXY");
1100 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_INTERACTIVE
)
1101 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_INTERACTIVE");
1102 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_NETWORK
)
1103 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_NETWORK");
1104 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_BATCH
)
1105 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_BATCH");
1106 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_SERVICE
)
1107 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_SERVICE");
1108 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_REMOTE_INTERACTIVE
)
1109 torture_comment(tctx
, " LSA_POLICY_MODE_REMOTE_INTERACTIVE");
1110 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_REMOTE_INTERACTIVE
)
1111 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_REMOTE_INTERACTIVE");
1112 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_ALL
)
1113 torture_comment(tctx
, " LSA_POLICY_MODE_ALL");
1114 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_ALL_NT4
)
1115 torture_comment(tctx
, " LSA_POLICY_MODE_ALL_NT4");
1116 torture_comment(tctx
, "\n");
1122 static bool test_Delete(struct dcerpc_binding_handle
*b
,
1123 struct torture_context
*tctx
,
1124 struct policy_handle
*handle
)
1126 struct lsa_Delete r
;
1128 torture_comment(tctx
, "\nTesting Delete\n");
1130 r
.in
.handle
= handle
;
1131 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_Delete_r(b
, tctx
, &r
),
1133 if (!NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NOT_SUPPORTED
)) {
1134 torture_comment(tctx
, "Delete should have failed NT_STATUS_NOT_SUPPORTED - %s\n", nt_errstr(r
.out
.result
));
1141 static bool test_DeleteObject(struct dcerpc_binding_handle
*b
,
1142 struct torture_context
*tctx
,
1143 struct policy_handle
*handle
)
1145 struct lsa_DeleteObject r
;
1147 torture_comment(tctx
, "\nTesting DeleteObject\n");
1149 r
.in
.handle
= handle
;
1150 r
.out
.handle
= handle
;
1151 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_DeleteObject_r(b
, tctx
, &r
),
1152 "DeleteObject failed");
1153 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1154 torture_comment(tctx
, "DeleteObject failed - %s\n",
1155 nt_errstr(r
.out
.result
));
1163 static bool test_CreateAccount(struct dcerpc_binding_handle
*b
,
1164 struct torture_context
*tctx
,
1165 struct policy_handle
*handle
)
1167 struct lsa_CreateAccount r
;
1168 struct dom_sid2
*newsid
;
1169 struct policy_handle acct_handle
;
1171 newsid
= dom_sid_parse_talloc(tctx
, "S-1-5-12349876-4321-2854");
1173 torture_comment(tctx
, "\nTesting CreateAccount\n");
1175 r
.in
.handle
= handle
;
1177 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1178 r
.out
.acct_handle
= &acct_handle
;
1180 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateAccount_r(b
, tctx
, &r
),
1181 "CreateAccount failed");
1182 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
1183 struct lsa_OpenAccount r_o
;
1184 r_o
.in
.handle
= handle
;
1185 r_o
.in
.sid
= newsid
;
1186 r_o
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1187 r_o
.out
.acct_handle
= &acct_handle
;
1189 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenAccount_r(b
, tctx
, &r_o
),
1190 "OpenAccount failed");
1191 if (!NT_STATUS_IS_OK(r_o
.out
.result
)) {
1192 torture_comment(tctx
, "OpenAccount failed - %s\n",
1193 nt_errstr(r_o
.out
.result
));
1196 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1197 torture_comment(tctx
, "CreateAccount failed - %s\n",
1198 nt_errstr(r
.out
.result
));
1202 if (!test_Delete(b
, tctx
, &acct_handle
)) {
1206 if (!test_DeleteObject(b
, tctx
, &acct_handle
)) {
1213 static bool test_DeleteTrustedDomain(struct dcerpc_binding_handle
*b
,
1214 struct torture_context
*tctx
,
1215 struct policy_handle
*handle
,
1216 struct lsa_StringLarge name
)
1218 struct lsa_OpenTrustedDomainByName r
;
1219 struct policy_handle trustdom_handle
;
1221 r
.in
.handle
= handle
;
1222 r
.in
.name
.string
= name
.string
;
1223 r
.in
.access_mask
= SEC_STD_DELETE
;
1224 r
.out
.trustdom_handle
= &trustdom_handle
;
1226 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenTrustedDomainByName_r(b
, tctx
, &r
),
1227 "OpenTrustedDomainByName failed");
1228 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1229 torture_comment(tctx
, "OpenTrustedDomainByName failed - %s\n", nt_errstr(r
.out
.result
));
1233 if (!test_Delete(b
, tctx
, &trustdom_handle
)) {
1237 if (!test_DeleteObject(b
, tctx
, &trustdom_handle
)) {
1244 static bool test_DeleteTrustedDomainBySid(struct dcerpc_binding_handle
*b
,
1245 struct torture_context
*tctx
,
1246 struct policy_handle
*handle
,
1247 struct dom_sid
*sid
)
1249 struct lsa_DeleteTrustedDomain r
;
1251 r
.in
.handle
= handle
;
1254 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_DeleteTrustedDomain_r(b
, tctx
, &r
),
1255 "DeleteTrustedDomain failed");
1256 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1257 torture_comment(tctx
, "DeleteTrustedDomain failed - %s\n", nt_errstr(r
.out
.result
));
1265 static bool test_CreateSecret(struct dcerpc_pipe
*p
,
1266 struct torture_context
*tctx
,
1267 struct policy_handle
*handle
)
1270 struct lsa_CreateSecret r
;
1271 struct lsa_OpenSecret r2
;
1272 struct lsa_SetSecret r3
;
1273 struct lsa_QuerySecret r4
;
1274 struct lsa_SetSecret r5
;
1275 struct lsa_QuerySecret r6
;
1276 struct lsa_SetSecret r7
;
1277 struct lsa_QuerySecret r8
;
1278 struct policy_handle sec_handle
, sec_handle2
, sec_handle3
;
1279 struct lsa_DeleteObject d_o
;
1280 struct lsa_DATA_BUF buf1
;
1281 struct lsa_DATA_BUF_PTR bufp1
;
1282 struct lsa_DATA_BUF_PTR bufp2
;
1285 DATA_BLOB session_key
;
1286 NTTIME old_mtime
, new_mtime
;
1287 DATA_BLOB blob1
, blob2
;
1288 const char *secret1
= "abcdef12345699qwerty";
1290 const char *secret3
= "ABCDEF12345699QWERTY";
1292 const char *secret5
= "NEW-SAMBA4-SECRET";
1296 const int LOCAL
= 0;
1297 const int GLOBAL
= 1;
1298 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
1300 secname
[LOCAL
] = talloc_asprintf(tctx
, "torturesecret-%u", (unsigned int)random());
1301 secname
[GLOBAL
] = talloc_asprintf(tctx
, "G$torturesecret-%u", (unsigned int)random());
1303 for (i
=0; i
< 2; i
++) {
1304 torture_comment(tctx
, "\nTesting CreateSecret of %s\n", secname
[i
]);
1306 init_lsa_String(&r
.in
.name
, secname
[i
]);
1308 r
.in
.handle
= handle
;
1309 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1310 r
.out
.sec_handle
= &sec_handle
;
1312 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateSecret_r(b
, tctx
, &r
),
1313 "CreateSecret failed");
1314 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1315 torture_comment(tctx
, "CreateSecret failed - %s\n", nt_errstr(r
.out
.result
));
1319 r
.in
.handle
= handle
;
1320 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1321 r
.out
.sec_handle
= &sec_handle3
;
1323 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateSecret_r(b
, tctx
, &r
),
1324 "CreateSecret failed");
1325 if (!NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
1326 torture_comment(tctx
, "CreateSecret should have failed OBJECT_NAME_COLLISION - %s\n", nt_errstr(r
.out
.result
));
1330 r2
.in
.handle
= handle
;
1331 r2
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1332 r2
.in
.name
= r
.in
.name
;
1333 r2
.out
.sec_handle
= &sec_handle2
;
1335 torture_comment(tctx
, "Testing OpenSecret\n");
1337 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenSecret_r(b
, tctx
, &r2
),
1338 "OpenSecret failed");
1339 if (!NT_STATUS_IS_OK(r2
.out
.result
)) {
1340 torture_comment(tctx
, "OpenSecret failed - %s\n", nt_errstr(r2
.out
.result
));
1344 status
= dcerpc_fetch_session_key(p
, &session_key
);
1345 if (!NT_STATUS_IS_OK(status
)) {
1346 torture_comment(tctx
, "dcerpc_fetch_session_key failed - %s\n", nt_errstr(status
));
1350 enc_key
= sess_encrypt_string(secret1
, &session_key
);
1352 r3
.in
.sec_handle
= &sec_handle
;
1353 r3
.in
.new_val
= &buf1
;
1354 r3
.in
.old_val
= NULL
;
1355 r3
.in
.new_val
->data
= enc_key
.data
;
1356 r3
.in
.new_val
->length
= enc_key
.length
;
1357 r3
.in
.new_val
->size
= enc_key
.length
;
1359 torture_comment(tctx
, "Testing SetSecret\n");
1361 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_SetSecret_r(b
, tctx
, &r3
),
1362 "SetSecret failed");
1363 if (!NT_STATUS_IS_OK(r3
.out
.result
)) {
1364 torture_comment(tctx
, "SetSecret failed - %s\n", nt_errstr(r3
.out
.result
));
1368 r3
.in
.sec_handle
= &sec_handle
;
1369 r3
.in
.new_val
= &buf1
;
1370 r3
.in
.old_val
= NULL
;
1371 r3
.in
.new_val
->data
= enc_key
.data
;
1372 r3
.in
.new_val
->length
= enc_key
.length
;
1373 r3
.in
.new_val
->size
= enc_key
.length
;
1375 /* break the encrypted data */
1378 torture_comment(tctx
, "Testing SetSecret with broken key\n");
1380 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_SetSecret_r(b
, tctx
, &r3
),
1381 "SetSecret failed");
1382 if (!NT_STATUS_EQUAL(r3
.out
.result
, NT_STATUS_UNKNOWN_REVISION
)) {
1383 torture_comment(tctx
, "SetSecret should have failed UNKNOWN_REVISION - %s\n", nt_errstr(r3
.out
.result
));
1387 data_blob_free(&enc_key
);
1389 ZERO_STRUCT(new_mtime
);
1390 ZERO_STRUCT(old_mtime
);
1392 /* fetch the secret back again */
1393 r4
.in
.sec_handle
= &sec_handle
;
1394 r4
.in
.new_val
= &bufp1
;
1395 r4
.in
.new_mtime
= &new_mtime
;
1396 r4
.in
.old_val
= NULL
;
1397 r4
.in
.old_mtime
= NULL
;
1401 torture_comment(tctx
, "Testing QuerySecret\n");
1402 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QuerySecret_r(b
, tctx
, &r4
),
1403 "QuerySecret failed");
1404 if (!NT_STATUS_IS_OK(r4
.out
.result
)) {
1405 torture_comment(tctx
, "QuerySecret failed - %s\n", nt_errstr(r4
.out
.result
));
1408 if (r4
.out
.new_val
== NULL
|| r4
.out
.new_val
->buf
== NULL
) {
1409 torture_comment(tctx
, "No secret buffer returned\n");
1412 blob1
.data
= r4
.out
.new_val
->buf
->data
;
1413 blob1
.length
= r4
.out
.new_val
->buf
->size
;
1415 blob2
= data_blob_talloc(tctx
, NULL
, blob1
.length
);
1417 secret2
= sess_decrypt_string(tctx
,
1418 &blob1
, &session_key
);
1420 if (strcmp(secret1
, secret2
) != 0) {
1421 torture_comment(tctx
, "Returned secret (r4) '%s' doesn't match '%s'\n",
1428 enc_key
= sess_encrypt_string(secret3
, &session_key
);
1430 r5
.in
.sec_handle
= &sec_handle
;
1431 r5
.in
.new_val
= &buf1
;
1432 r5
.in
.old_val
= NULL
;
1433 r5
.in
.new_val
->data
= enc_key
.data
;
1434 r5
.in
.new_val
->length
= enc_key
.length
;
1435 r5
.in
.new_val
->size
= enc_key
.length
;
1439 torture_comment(tctx
, "Testing SetSecret (existing value should move to old)\n");
1441 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_SetSecret_r(b
, tctx
, &r5
),
1442 "SetSecret failed");
1443 if (!NT_STATUS_IS_OK(r5
.out
.result
)) {
1444 torture_comment(tctx
, "SetSecret failed - %s\n", nt_errstr(r5
.out
.result
));
1448 data_blob_free(&enc_key
);
1450 ZERO_STRUCT(new_mtime
);
1451 ZERO_STRUCT(old_mtime
);
1453 /* fetch the secret back again */
1454 r6
.in
.sec_handle
= &sec_handle
;
1455 r6
.in
.new_val
= &bufp1
;
1456 r6
.in
.new_mtime
= &new_mtime
;
1457 r6
.in
.old_val
= &bufp2
;
1458 r6
.in
.old_mtime
= &old_mtime
;
1463 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QuerySecret_r(b
, tctx
, &r6
),
1464 "QuerySecret failed");
1465 if (!NT_STATUS_IS_OK(r6
.out
.result
)) {
1466 torture_comment(tctx
, "QuerySecret failed - %s\n", nt_errstr(r6
.out
.result
));
1471 if (r6
.out
.new_val
->buf
== NULL
|| r6
.out
.old_val
->buf
== NULL
1472 || r6
.out
.new_mtime
== NULL
|| r6
.out
.old_mtime
== NULL
) {
1473 torture_comment(tctx
, "Both secret buffers and both times not returned\n");
1477 blob1
.data
= r6
.out
.new_val
->buf
->data
;
1478 blob1
.length
= r6
.out
.new_val
->buf
->size
;
1480 blob2
= data_blob_talloc(tctx
, NULL
, blob1
.length
);
1482 secret4
= sess_decrypt_string(tctx
,
1483 &blob1
, &session_key
);
1485 if (strcmp(secret3
, secret4
) != 0) {
1486 torture_comment(tctx
, "Returned NEW secret %s doesn't match %s\n", secret4
, secret3
);
1490 blob1
.data
= r6
.out
.old_val
->buf
->data
;
1491 blob1
.length
= r6
.out
.old_val
->buf
->length
;
1493 blob2
= data_blob_talloc(tctx
, NULL
, blob1
.length
);
1495 secret2
= sess_decrypt_string(tctx
,
1496 &blob1
, &session_key
);
1498 if (strcmp(secret1
, secret2
) != 0) {
1499 torture_comment(tctx
, "Returned OLD secret %s doesn't match %s\n", secret2
, secret1
);
1503 if (*r6
.out
.new_mtime
== *r6
.out
.old_mtime
) {
1504 torture_comment(tctx
, "Returned secret (r6-%d) %s must not have same mtime for both secrets: %s != %s\n",
1507 nt_time_string(tctx
, *r6
.out
.old_mtime
),
1508 nt_time_string(tctx
, *r6
.out
.new_mtime
));
1514 enc_key
= sess_encrypt_string(secret5
, &session_key
);
1516 r7
.in
.sec_handle
= &sec_handle
;
1517 r7
.in
.old_val
= &buf1
;
1518 r7
.in
.old_val
->data
= enc_key
.data
;
1519 r7
.in
.old_val
->length
= enc_key
.length
;
1520 r7
.in
.old_val
->size
= enc_key
.length
;
1521 r7
.in
.new_val
= NULL
;
1523 torture_comment(tctx
, "Testing SetSecret of old Secret only\n");
1525 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_SetSecret_r(b
, tctx
, &r7
),
1526 "SetSecret failed");
1527 if (!NT_STATUS_IS_OK(r7
.out
.result
)) {
1528 torture_comment(tctx
, "SetSecret failed - %s\n", nt_errstr(r7
.out
.result
));
1532 data_blob_free(&enc_key
);
1534 /* fetch the secret back again */
1535 r8
.in
.sec_handle
= &sec_handle
;
1536 r8
.in
.new_val
= &bufp1
;
1537 r8
.in
.new_mtime
= &new_mtime
;
1538 r8
.in
.old_val
= &bufp2
;
1539 r8
.in
.old_mtime
= &old_mtime
;
1544 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QuerySecret_r(b
, tctx
, &r8
),
1545 "QuerySecret failed");
1546 if (!NT_STATUS_IS_OK(r8
.out
.result
)) {
1547 torture_comment(tctx
, "QuerySecret failed - %s\n", nt_errstr(r8
.out
.result
));
1550 if (!r8
.out
.new_val
|| !r8
.out
.old_val
) {
1551 torture_comment(tctx
, "in/out pointers not returned, despite being set on in for QuerySecret\n");
1553 } else if (r8
.out
.new_val
->buf
!= NULL
) {
1554 torture_comment(tctx
, "NEW secret buffer must not be returned after OLD set\n");
1556 } else if (r8
.out
.old_val
->buf
== NULL
) {
1557 torture_comment(tctx
, "OLD secret buffer was not returned after OLD set\n");
1559 } else if (r8
.out
.new_mtime
== NULL
|| r8
.out
.old_mtime
== NULL
) {
1560 torture_comment(tctx
, "Both times not returned after OLD set\n");
1563 blob1
.data
= r8
.out
.old_val
->buf
->data
;
1564 blob1
.length
= r8
.out
.old_val
->buf
->size
;
1566 blob2
= data_blob_talloc(tctx
, NULL
, blob1
.length
);
1568 secret6
= sess_decrypt_string(tctx
,
1569 &blob1
, &session_key
);
1571 if (strcmp(secret5
, secret6
) != 0) {
1572 torture_comment(tctx
, "Returned OLD secret %s doesn't match %s\n", secret5
, secret6
);
1576 if (*r8
.out
.new_mtime
!= *r8
.out
.old_mtime
) {
1577 torture_comment(tctx
, "Returned secret (r8) %s did not had same mtime for both secrets: %s != %s\n",
1579 nt_time_string(tctx
, *r8
.out
.old_mtime
),
1580 nt_time_string(tctx
, *r8
.out
.new_mtime
));
1586 if (!test_Delete(b
, tctx
, &sec_handle
)) {
1590 if (!test_DeleteObject(b
, tctx
, &sec_handle
)) {
1594 d_o
.in
.handle
= &sec_handle2
;
1595 d_o
.out
.handle
= &sec_handle2
;
1596 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_DeleteObject_r(b
, tctx
, &d_o
),
1597 "DeleteObject failed");
1598 if (!NT_STATUS_EQUAL(d_o
.out
.result
, NT_STATUS_INVALID_HANDLE
)) {
1599 torture_comment(tctx
, "Second delete expected INVALID_HANDLE - %s\n", nt_errstr(d_o
.out
.result
));
1603 torture_comment(tctx
, "Testing OpenSecret of just-deleted secret\n");
1605 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenSecret_r(b
, tctx
, &r2
),
1606 "OpenSecret failed");
1607 if (!NT_STATUS_EQUAL(r2
.out
.result
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
1608 torture_comment(tctx
, "OpenSecret expected OBJECT_NAME_NOT_FOUND - %s\n", nt_errstr(r2
.out
.result
));
1619 static bool test_EnumAccountRights(struct dcerpc_binding_handle
*b
,
1620 struct torture_context
*tctx
,
1621 struct policy_handle
*acct_handle
,
1622 struct dom_sid
*sid
)
1624 struct lsa_EnumAccountRights r
;
1625 struct lsa_RightSet rights
;
1627 torture_comment(tctx
, "\nTesting EnumAccountRights\n");
1629 r
.in
.handle
= acct_handle
;
1631 r
.out
.rights
= &rights
;
1633 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumAccountRights_r(b
, tctx
, &r
),
1634 "EnumAccountRights failed");
1635 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1636 torture_comment(tctx
, "EnumAccountRights of %s failed - %s\n",
1637 dom_sid_string(tctx
, sid
), nt_errstr(r
.out
.result
));
1645 static bool test_QuerySecurity(struct dcerpc_binding_handle
*b
,
1646 struct torture_context
*tctx
,
1647 struct policy_handle
*handle
,
1648 struct policy_handle
*acct_handle
)
1650 struct lsa_QuerySecurity r
;
1651 struct sec_desc_buf
*sdbuf
= NULL
;
1653 if (torture_setting_bool(tctx
, "samba4", false)) {
1654 torture_comment(tctx
, "\nskipping QuerySecurity test against Samba4\n");
1658 torture_comment(tctx
, "\nTesting QuerySecurity\n");
1660 r
.in
.handle
= acct_handle
;
1661 r
.in
.sec_info
= SECINFO_OWNER
|
1664 r
.out
.sdbuf
= &sdbuf
;
1666 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QuerySecurity_r(b
, tctx
, &r
),
1667 "QuerySecurity failed");
1668 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1669 torture_comment(tctx
, "QuerySecurity failed - %s\n", nt_errstr(r
.out
.result
));
1676 static bool test_OpenAccount(struct dcerpc_binding_handle
*b
,
1677 struct torture_context
*tctx
,
1678 struct policy_handle
*handle
,
1679 struct dom_sid
*sid
)
1681 struct lsa_OpenAccount r
;
1682 struct policy_handle acct_handle
;
1684 torture_comment(tctx
, "\nTesting OpenAccount\n");
1686 r
.in
.handle
= handle
;
1688 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1689 r
.out
.acct_handle
= &acct_handle
;
1691 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenAccount_r(b
, tctx
, &r
),
1692 "OpenAccount failed");
1693 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1694 torture_comment(tctx
, "OpenAccount failed - %s\n", nt_errstr(r
.out
.result
));
1698 if (!test_EnumPrivsAccount(b
, tctx
, handle
, &acct_handle
)) {
1702 if (!test_GetSystemAccessAccount(b
, tctx
, handle
, &acct_handle
)) {
1706 if (!test_QuerySecurity(b
, tctx
, handle
, &acct_handle
)) {
1713 static bool test_EnumAccounts(struct dcerpc_binding_handle
*b
,
1714 struct torture_context
*tctx
,
1715 struct policy_handle
*handle
)
1717 struct lsa_EnumAccounts r
;
1718 struct lsa_SidArray sids1
, sids2
;
1719 uint32_t resume_handle
= 0;
1723 torture_comment(tctx
, "\nTesting EnumAccounts\n");
1725 r
.in
.handle
= handle
;
1726 r
.in
.resume_handle
= &resume_handle
;
1727 r
.in
.num_entries
= 100;
1728 r
.out
.resume_handle
= &resume_handle
;
1729 r
.out
.sids
= &sids1
;
1733 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumAccounts_r(b
, tctx
, &r
),
1734 "EnumAccounts failed");
1735 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
)) {
1738 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1739 torture_comment(tctx
, "EnumAccounts failed - %s\n", nt_errstr(r
.out
.result
));
1743 if (!test_LookupSids(b
, tctx
, handle
, &sids1
)) {
1747 if (!test_LookupSids2(b
, tctx
, handle
, &sids1
)) {
1751 /* Can't test lookupSids3 here, as clearly we must not
1752 * be on schannel, or we would not be able to do the
1755 torture_comment(tctx
, "Testing all accounts\n");
1756 for (i
=0;i
<sids1
.num_sids
;i
++) {
1757 ret
&= test_OpenAccount(b
, tctx
, handle
, sids1
.sids
[i
].sid
);
1758 ret
&= test_EnumAccountRights(b
, tctx
, handle
, sids1
.sids
[i
].sid
);
1760 torture_comment(tctx
, "\n");
1763 if (sids1
.num_sids
< 3) {
1767 torture_comment(tctx
, "Trying EnumAccounts partial listing (asking for 1 at 2)\n");
1769 r
.in
.num_entries
= 1;
1770 r
.out
.sids
= &sids2
;
1772 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumAccounts_r(b
, tctx
, &r
),
1773 "EnumAccounts failed");
1774 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1775 torture_comment(tctx
, "EnumAccounts failed - %s\n", nt_errstr(r
.out
.result
));
1779 if (sids2
.num_sids
!= 1) {
1780 torture_comment(tctx
, "Returned wrong number of entries (%d)\n", sids2
.num_sids
);
1787 static bool test_LookupPrivDisplayName(struct dcerpc_binding_handle
*b
,
1788 struct torture_context
*tctx
,
1789 struct policy_handle
*handle
,
1790 struct lsa_String
*priv_name
)
1792 struct lsa_LookupPrivDisplayName r
;
1793 /* produce a reasonable range of language output without screwing up
1795 uint16_t language_id
= (random() % 4) + 0x409;
1796 uint16_t returned_language_id
= 0;
1797 struct lsa_StringLarge
*disp_name
= NULL
;
1799 torture_comment(tctx
, "\nTesting LookupPrivDisplayName(%s)\n", priv_name
->string
);
1801 r
.in
.handle
= handle
;
1802 r
.in
.name
= priv_name
;
1803 r
.in
.language_id
= language_id
;
1804 r
.in
.language_id_sys
= 0;
1805 r
.out
.returned_language_id
= &returned_language_id
;
1806 r
.out
.disp_name
= &disp_name
;
1808 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupPrivDisplayName_r(b
, tctx
, &r
),
1809 "LookupPrivDisplayName failed");
1810 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1811 torture_comment(tctx
, "LookupPrivDisplayName failed - %s\n", nt_errstr(r
.out
.result
));
1814 torture_comment(tctx
, "%s -> \"%s\" (language 0x%x/0x%x)\n",
1815 priv_name
->string
, disp_name
->string
,
1816 r
.in
.language_id
, *r
.out
.returned_language_id
);
1821 static bool test_EnumAccountsWithUserRight(struct dcerpc_binding_handle
*b
,
1822 struct torture_context
*tctx
,
1823 struct policy_handle
*handle
,
1824 struct lsa_String
*priv_name
)
1826 struct lsa_EnumAccountsWithUserRight r
;
1827 struct lsa_SidArray sids
;
1831 torture_comment(tctx
, "\nTesting EnumAccountsWithUserRight(%s)\n", priv_name
->string
);
1833 r
.in
.handle
= handle
;
1834 r
.in
.name
= priv_name
;
1837 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumAccountsWithUserRight_r(b
, tctx
, &r
),
1838 "EnumAccountsWithUserRight failed");
1840 /* NT_STATUS_NO_MORE_ENTRIES means noone has this privilege */
1841 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
)) {
1845 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1846 torture_comment(tctx
, "EnumAccountsWithUserRight failed - %s\n", nt_errstr(r
.out
.result
));
1854 static bool test_EnumPrivs(struct dcerpc_binding_handle
*b
,
1855 struct torture_context
*tctx
,
1856 struct policy_handle
*handle
)
1858 struct lsa_EnumPrivs r
;
1859 struct lsa_PrivArray privs1
;
1860 uint32_t resume_handle
= 0;
1864 torture_comment(tctx
, "\nTesting EnumPrivs\n");
1866 r
.in
.handle
= handle
;
1867 r
.in
.resume_handle
= &resume_handle
;
1868 r
.in
.max_count
= 100;
1869 r
.out
.resume_handle
= &resume_handle
;
1870 r
.out
.privs
= &privs1
;
1873 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumPrivs_r(b
, tctx
, &r
),
1874 "EnumPrivs failed");
1875 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1876 torture_comment(tctx
, "EnumPrivs failed - %s\n", nt_errstr(r
.out
.result
));
1880 for (i
= 0; i
< privs1
.count
; i
++) {
1881 test_LookupPrivDisplayName(b
, tctx
, handle
, (struct lsa_String
*)&privs1
.privs
[i
].name
);
1882 test_LookupPrivValue(b
, tctx
, handle
, (struct lsa_String
*)&privs1
.privs
[i
].name
);
1883 if (!test_EnumAccountsWithUserRight(b
, tctx
, handle
, (struct lsa_String
*)&privs1
.privs
[i
].name
)) {
1891 static bool test_QueryForestTrustInformation(struct dcerpc_binding_handle
*b
,
1892 struct torture_context
*tctx
,
1893 struct policy_handle
*handle
,
1894 const char *trusted_domain_name
)
1897 struct lsa_lsaRQueryForestTrustInformation r
;
1898 struct lsa_String string
;
1899 struct lsa_ForestTrustInformation info
, *info_ptr
;
1901 torture_comment(tctx
, "\nTesting lsaRQueryForestTrustInformation\n");
1903 if (torture_setting_bool(tctx
, "samba4", false)) {
1904 torture_comment(tctx
, "skipping QueryForestTrustInformation against Samba4\n");
1908 ZERO_STRUCT(string
);
1910 if (trusted_domain_name
) {
1911 init_lsa_String(&string
, trusted_domain_name
);
1916 r
.in
.handle
= handle
;
1917 r
.in
.trusted_domain_name
= &string
;
1919 r
.out
.forest_trust_info
= &info_ptr
;
1921 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_lsaRQueryForestTrustInformation_r(b
, tctx
, &r
),
1922 "lsaRQueryForestTrustInformation failed");
1924 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1925 torture_comment(tctx
, "lsaRQueryForestTrustInformation of %s failed - %s\n", trusted_domain_name
, nt_errstr(r
.out
.result
));
1932 static bool test_query_each_TrustDomEx(struct dcerpc_binding_handle
*b
,
1933 struct torture_context
*tctx
,
1934 struct policy_handle
*handle
,
1935 struct lsa_DomainListEx
*domains
)
1940 for (i
=0; i
< domains
->count
; i
++) {
1942 if (domains
->domains
[i
].trust_attributes
& NETR_TRUST_ATTRIBUTE_FOREST_TRANSITIVE
) {
1943 ret
&= test_QueryForestTrustInformation(b
, tctx
, handle
,
1944 domains
->domains
[i
].domain_name
.string
);
1951 static bool test_query_each_TrustDom(struct dcerpc_binding_handle
*b
,
1952 struct torture_context
*tctx
,
1953 struct policy_handle
*handle
,
1954 struct lsa_DomainList
*domains
)
1959 torture_comment(tctx
, "\nTesting OpenTrustedDomain, OpenTrustedDomainByName and QueryInfoTrustedDomain\n");
1960 for (i
=0; i
< domains
->count
; i
++) {
1961 struct lsa_OpenTrustedDomain trust
;
1962 struct lsa_OpenTrustedDomainByName trust_by_name
;
1963 struct policy_handle trustdom_handle
;
1964 struct policy_handle handle2
;
1966 struct lsa_CloseTrustedDomainEx c_trust
;
1967 int levels
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
1968 int ok
[] = {1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1};
1970 if (domains
->domains
[i
].sid
) {
1971 trust
.in
.handle
= handle
;
1972 trust
.in
.sid
= domains
->domains
[i
].sid
;
1973 trust
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1974 trust
.out
.trustdom_handle
= &trustdom_handle
;
1976 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenTrustedDomain_r(b
, tctx
, &trust
),
1977 "OpenTrustedDomain failed");
1979 if (!NT_STATUS_IS_OK(trust
.out
.result
)) {
1980 torture_comment(tctx
, "OpenTrustedDomain failed - %s\n", nt_errstr(trust
.out
.result
));
1984 c
.in
.handle
= &trustdom_handle
;
1985 c
.out
.handle
= &handle2
;
1987 c_trust
.in
.handle
= &trustdom_handle
;
1988 c_trust
.out
.handle
= &handle2
;
1990 for (j
=0; j
< ARRAY_SIZE(levels
); j
++) {
1991 struct lsa_QueryTrustedDomainInfo q
;
1992 union lsa_TrustedDomainInfo
*info
= NULL
;
1993 q
.in
.trustdom_handle
= &trustdom_handle
;
1994 q
.in
.level
= levels
[j
];
1996 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfo_r(b
, tctx
, &q
),
1997 "QueryTrustedDomainInfo failed");
1998 if (!NT_STATUS_IS_OK(q
.out
.result
) && ok
[j
]) {
1999 torture_comment(tctx
, "QueryTrustedDomainInfo level %d failed - %s\n",
2000 levels
[j
], nt_errstr(q
.out
.result
));
2002 } else if (NT_STATUS_IS_OK(q
.out
.result
) && !ok
[j
]) {
2003 torture_comment(tctx
, "QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
2004 levels
[j
], nt_errstr(q
.out
.result
));
2009 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CloseTrustedDomainEx_r(b
, tctx
, &c_trust
),
2010 "CloseTrustedDomainEx failed");
2011 if (!NT_STATUS_EQUAL(c_trust
.out
.result
, NT_STATUS_NOT_IMPLEMENTED
)) {
2012 torture_comment(tctx
, "Expected CloseTrustedDomainEx to return NT_STATUS_NOT_IMPLEMENTED, instead - %s\n", nt_errstr(c_trust
.out
.result
));
2016 c
.in
.handle
= &trustdom_handle
;
2017 c
.out
.handle
= &handle2
;
2019 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_Close_r(b
, tctx
, &c
),
2021 if (!NT_STATUS_IS_OK(c
.out
.result
)) {
2022 torture_comment(tctx
, "Close of trusted domain failed - %s\n", nt_errstr(c
.out
.result
));
2026 for (j
=0; j
< ARRAY_SIZE(levels
); j
++) {
2027 struct lsa_QueryTrustedDomainInfoBySid q
;
2028 union lsa_TrustedDomainInfo
*info
= NULL
;
2030 if (!domains
->domains
[i
].sid
) {
2034 q
.in
.handle
= handle
;
2035 q
.in
.dom_sid
= domains
->domains
[i
].sid
;
2036 q
.in
.level
= levels
[j
];
2039 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfoBySid_r(b
, tctx
, &q
),
2040 "lsa_QueryTrustedDomainInfoBySid failed");
2041 if (!NT_STATUS_IS_OK(q
.out
.result
) && ok
[j
]) {
2042 torture_comment(tctx
, "QueryTrustedDomainInfoBySid level %d failed - %s\n",
2043 levels
[j
], nt_errstr(q
.out
.result
));
2045 } else if (NT_STATUS_IS_OK(q
.out
.result
) && !ok
[j
]) {
2046 torture_comment(tctx
, "QueryTrustedDomainInfoBySid level %d unexpectedly succeeded - %s\n",
2047 levels
[j
], nt_errstr(q
.out
.result
));
2053 trust_by_name
.in
.handle
= handle
;
2054 trust_by_name
.in
.name
.string
= domains
->domains
[i
].name
.string
;
2055 trust_by_name
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2056 trust_by_name
.out
.trustdom_handle
= &trustdom_handle
;
2058 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenTrustedDomainByName_r(b
, tctx
, &trust_by_name
),
2059 "OpenTrustedDomainByName failed");
2061 if (!NT_STATUS_IS_OK(trust_by_name
.out
.result
)) {
2062 torture_comment(tctx
, "OpenTrustedDomainByName failed - %s\n", nt_errstr(trust_by_name
.out
.result
));
2066 for (j
=0; j
< ARRAY_SIZE(levels
); j
++) {
2067 struct lsa_QueryTrustedDomainInfo q
;
2068 union lsa_TrustedDomainInfo
*info
= NULL
;
2069 q
.in
.trustdom_handle
= &trustdom_handle
;
2070 q
.in
.level
= levels
[j
];
2072 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfo_r(b
, tctx
, &q
),
2073 "QueryTrustedDomainInfo failed");
2074 if (!NT_STATUS_IS_OK(q
.out
.result
) && ok
[j
]) {
2075 torture_comment(tctx
, "QueryTrustedDomainInfo level %d failed - %s\n",
2076 levels
[j
], nt_errstr(q
.out
.result
));
2078 } else if (NT_STATUS_IS_OK(q
.out
.result
) && !ok
[j
]) {
2079 torture_comment(tctx
, "QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
2080 levels
[j
], nt_errstr(q
.out
.result
));
2085 c
.in
.handle
= &trustdom_handle
;
2086 c
.out
.handle
= &handle2
;
2088 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_Close_r(b
, tctx
, &c
),
2090 if (!NT_STATUS_IS_OK(c
.out
.result
)) {
2091 torture_comment(tctx
, "Close of trusted domain failed - %s\n", nt_errstr(c
.out
.result
));
2095 for (j
=0; j
< ARRAY_SIZE(levels
); j
++) {
2096 struct lsa_QueryTrustedDomainInfoByName q
;
2097 union lsa_TrustedDomainInfo
*info
= NULL
;
2098 struct lsa_String name
;
2100 name
.string
= domains
->domains
[i
].name
.string
;
2102 q
.in
.handle
= handle
;
2103 q
.in
.trusted_domain
= &name
;
2104 q
.in
.level
= levels
[j
];
2106 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfoByName_r(b
, tctx
, &q
),
2107 "QueryTrustedDomainInfoByName failed");
2108 if (!NT_STATUS_IS_OK(q
.out
.result
) && ok
[j
]) {
2109 torture_comment(tctx
, "QueryTrustedDomainInfoByName level %d failed - %s\n",
2110 levels
[j
], nt_errstr(q
.out
.result
));
2112 } else if (NT_STATUS_IS_OK(q
.out
.result
) && !ok
[j
]) {
2113 torture_comment(tctx
, "QueryTrustedDomainInfoByName level %d unexpectedly succeeded - %s\n",
2114 levels
[j
], nt_errstr(q
.out
.result
));
2122 static bool test_EnumTrustDom(struct dcerpc_binding_handle
*b
,
2123 struct torture_context
*tctx
,
2124 struct policy_handle
*handle
)
2126 struct lsa_EnumTrustDom r
;
2127 uint32_t in_resume_handle
= 0;
2128 uint32_t out_resume_handle
;
2129 struct lsa_DomainList domains
;
2132 torture_comment(tctx
, "\nTesting EnumTrustDom\n");
2134 r
.in
.handle
= handle
;
2135 r
.in
.resume_handle
= &in_resume_handle
;
2137 r
.out
.domains
= &domains
;
2138 r
.out
.resume_handle
= &out_resume_handle
;
2140 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumTrustDom_r(b
, tctx
, &r
),
2141 "lsa_EnumTrustDom failed");
2143 /* according to MS-LSAD 3.1.4.7.8 output resume handle MUST
2144 * always be larger than the previous input resume handle, in
2145 * particular when hitting the last query it is vital to set the
2146 * resume handle correctly to avoid infinite client loops, as
2147 * seen e.g. with Windows XP SP3 when resume handle is 0 and
2148 * status is NT_STATUS_OK - gd */
2150 if (NT_STATUS_IS_OK(r
.out
.result
) ||
2151 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
) ||
2152 NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
))
2154 if (out_resume_handle
<= in_resume_handle
) {
2155 torture_comment(tctx
, "EnumTrustDom failed - should have returned output resume_handle (0x%08x) larger than input resume handle (0x%08x)\n",
2156 out_resume_handle
, in_resume_handle
);
2161 if (NT_STATUS_IS_OK(r
.out
.result
)) {
2162 if (domains
.count
== 0) {
2163 torture_comment(tctx
, "EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2166 } else if (!(NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
) || NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
))) {
2167 torture_comment(tctx
, "EnumTrustDom of zero size failed - %s\n", nt_errstr(r
.out
.result
));
2171 /* Start from the bottom again */
2172 in_resume_handle
= 0;
2175 r
.in
.handle
= handle
;
2176 r
.in
.resume_handle
= &in_resume_handle
;
2177 r
.in
.max_size
= LSA_ENUM_TRUST_DOMAIN_MULTIPLIER
* 3;
2178 r
.out
.domains
= &domains
;
2179 r
.out
.resume_handle
= &out_resume_handle
;
2181 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumTrustDom_r(b
, tctx
, &r
),
2182 "EnumTrustDom failed");
2184 /* according to MS-LSAD 3.1.4.7.8 output resume handle MUST
2185 * always be larger than the previous input resume handle, in
2186 * particular when hitting the last query it is vital to set the
2187 * resume handle correctly to avoid infinite client loops, as
2188 * seen e.g. with Windows XP SP3 when resume handle is 0 and
2189 * status is NT_STATUS_OK - gd */
2191 if (NT_STATUS_IS_OK(r
.out
.result
) ||
2192 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
) ||
2193 NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
))
2195 if (out_resume_handle
<= in_resume_handle
) {
2196 torture_comment(tctx
, "EnumTrustDom failed - should have returned output resume_handle (0x%08x) larger than input resume handle (0x%08x)\n",
2197 out_resume_handle
, in_resume_handle
);
2202 /* NO_MORE_ENTRIES is allowed */
2203 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
)) {
2204 if (domains
.count
== 0) {
2207 torture_comment(tctx
, "EnumTrustDom failed - should have returned 0 trusted domains with 'NT_STATUS_NO_MORE_ENTRIES'\n");
2209 } else if (NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
)) {
2210 /* Windows 2003 gets this off by one on the first run */
2211 if (r
.out
.domains
->count
< 3 || r
.out
.domains
->count
> 4) {
2212 torture_comment(tctx
, "EnumTrustDom didn't fill the buffer we "
2213 "asked it to (got %d, expected %d / %d == %d entries)\n",
2214 r
.out
.domains
->count
, LSA_ENUM_TRUST_DOMAIN_MULTIPLIER
* 3,
2215 LSA_ENUM_TRUST_DOMAIN_MULTIPLIER
, r
.in
.max_size
);
2218 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2219 torture_comment(tctx
, "EnumTrustDom failed - %s\n", nt_errstr(r
.out
.result
));
2223 if (domains
.count
== 0) {
2224 torture_comment(tctx
, "EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2228 ret
&= test_query_each_TrustDom(b
, tctx
, handle
, &domains
);
2230 in_resume_handle
= out_resume_handle
;
2232 } while ((NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
)));
2237 static bool test_EnumTrustDomEx(struct dcerpc_binding_handle
*b
,
2238 struct torture_context
*tctx
,
2239 struct policy_handle
*handle
)
2241 struct lsa_EnumTrustedDomainsEx r_ex
;
2242 uint32_t resume_handle
= 0;
2243 struct lsa_DomainListEx domains_ex
;
2246 torture_comment(tctx
, "\nTesting EnumTrustedDomainsEx\n");
2248 r_ex
.in
.handle
= handle
;
2249 r_ex
.in
.resume_handle
= &resume_handle
;
2250 r_ex
.in
.max_size
= LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER
* 3;
2251 r_ex
.out
.domains
= &domains_ex
;
2252 r_ex
.out
.resume_handle
= &resume_handle
;
2254 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumTrustedDomainsEx_r(b
, tctx
, &r_ex
),
2255 "EnumTrustedDomainsEx failed");
2257 if (!(NT_STATUS_EQUAL(r_ex
.out
.result
, STATUS_MORE_ENTRIES
) || NT_STATUS_EQUAL(r_ex
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
))) {
2258 torture_comment(tctx
, "EnumTrustedDomainEx of zero size failed - %s\n", nt_errstr(r_ex
.out
.result
));
2264 r_ex
.in
.handle
= handle
;
2265 r_ex
.in
.resume_handle
= &resume_handle
;
2266 r_ex
.in
.max_size
= LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER
* 3;
2267 r_ex
.out
.domains
= &domains_ex
;
2268 r_ex
.out
.resume_handle
= &resume_handle
;
2270 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumTrustedDomainsEx_r(b
, tctx
, &r_ex
),
2271 "EnumTrustedDomainsEx failed");
2273 /* NO_MORE_ENTRIES is allowed */
2274 if (NT_STATUS_EQUAL(r_ex
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
)) {
2275 if (domains_ex
.count
== 0) {
2278 torture_comment(tctx
, "EnumTrustDomainsEx failed - should have returned 0 trusted domains with 'NT_STATUS_NO_MORE_ENTRIES'\n");
2280 } else if (NT_STATUS_EQUAL(r_ex
.out
.result
, STATUS_MORE_ENTRIES
)) {
2281 /* Windows 2003 gets this off by one on the first run */
2282 if (r_ex
.out
.domains
->count
< 3 || r_ex
.out
.domains
->count
> 4) {
2283 torture_comment(tctx
, "EnumTrustDom didn't fill the buffer we "
2284 "asked it to (got %d, expected %d / %d == %d entries)\n",
2285 r_ex
.out
.domains
->count
,
2287 LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER
,
2288 r_ex
.in
.max_size
/ LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER
);
2290 } else if (!NT_STATUS_IS_OK(r_ex
.out
.result
)) {
2291 torture_comment(tctx
, "EnumTrustedDomainEx failed - %s\n", nt_errstr(r_ex
.out
.result
));
2295 if (domains_ex
.count
== 0) {
2296 torture_comment(tctx
, "EnumTrustDomainEx failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2300 ret
&= test_query_each_TrustDomEx(b
, tctx
, handle
, &domains_ex
);
2302 } while ((NT_STATUS_EQUAL(r_ex
.out
.result
, STATUS_MORE_ENTRIES
)));
2308 static bool test_CreateTrustedDomain(struct dcerpc_binding_handle
*b
,
2309 struct torture_context
*tctx
,
2310 struct policy_handle
*handle
,
2311 uint32_t num_trusts
)
2314 struct lsa_CreateTrustedDomain r
;
2315 struct lsa_DomainInfo trustinfo
;
2316 struct dom_sid
**domsid
;
2317 struct policy_handle
*trustdom_handle
;
2318 struct lsa_QueryTrustedDomainInfo q
;
2319 union lsa_TrustedDomainInfo
*info
= NULL
;
2322 torture_comment(tctx
, "\nTesting CreateTrustedDomain for %d domains\n", num_trusts
);
2324 if (!test_EnumTrustDom(b
, tctx
, handle
)) {
2328 if (!test_EnumTrustDomEx(b
, tctx
, handle
)) {
2332 domsid
= talloc_array(tctx
, struct dom_sid
*, num_trusts
);
2333 trustdom_handle
= talloc_array(tctx
, struct policy_handle
, num_trusts
);
2335 for (i
=0; i
< num_trusts
; i
++) {
2336 char *trust_name
= talloc_asprintf(tctx
, "torturedom%02d", i
);
2337 char *trust_sid
= talloc_asprintf(tctx
, "S-1-5-21-97398-379795-100%02d", i
);
2339 domsid
[i
] = dom_sid_parse_talloc(tctx
, trust_sid
);
2341 trustinfo
.sid
= domsid
[i
];
2342 init_lsa_String((struct lsa_String
*)&trustinfo
.name
, trust_name
);
2344 r
.in
.policy_handle
= handle
;
2345 r
.in
.info
= &trustinfo
;
2346 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2347 r
.out
.trustdom_handle
= &trustdom_handle
[i
];
2349 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateTrustedDomain_r(b
, tctx
, &r
),
2350 "CreateTrustedDomain failed");
2351 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
2352 test_DeleteTrustedDomain(b
, tctx
, handle
, trustinfo
.name
);
2353 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateTrustedDomain_r(b
, tctx
, &r
),
2354 "CreateTrustedDomain failed");
2356 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2357 torture_comment(tctx
, "CreateTrustedDomain failed - %s\n", nt_errstr(r
.out
.result
));
2361 q
.in
.trustdom_handle
= &trustdom_handle
[i
];
2362 q
.in
.level
= LSA_TRUSTED_DOMAIN_INFO_INFO_EX
;
2364 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfo_r(b
, tctx
, &q
),
2365 "QueryTrustedDomainInfo failed");
2366 if (!NT_STATUS_IS_OK(q
.out
.result
)) {
2367 torture_comment(tctx
, "QueryTrustedDomainInfo level %d failed - %s\n", q
.in
.level
, nt_errstr(q
.out
.result
));
2369 } else if (!q
.out
.info
) {
2372 if (strcmp(info
->info_ex
.netbios_name
.string
, trustinfo
.name
.string
) != 0) {
2373 torture_comment(tctx
, "QueryTrustedDomainInfo returned inconsistant short name: %s != %s\n",
2374 info
->info_ex
.netbios_name
.string
, trustinfo
.name
.string
);
2377 if (info
->info_ex
.trust_type
!= LSA_TRUST_TYPE_DOWNLEVEL
) {
2378 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
2379 trust_name
, info
->info_ex
.trust_type
, LSA_TRUST_TYPE_DOWNLEVEL
);
2382 if (info
->info_ex
.trust_attributes
!= 0) {
2383 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
2384 trust_name
, info
->info_ex
.trust_attributes
, 0);
2387 if (info
->info_ex
.trust_direction
!= LSA_TRUST_DIRECTION_OUTBOUND
) {
2388 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
2389 trust_name
, info
->info_ex
.trust_direction
, LSA_TRUST_DIRECTION_OUTBOUND
);
2396 /* now that we have some domains to look over, we can test the enum calls */
2397 if (!test_EnumTrustDom(b
, tctx
, handle
)) {
2401 if (!test_EnumTrustDomEx(b
, tctx
, handle
)) {
2405 for (i
=0; i
<num_trusts
; i
++) {
2406 if (!test_DeleteTrustedDomainBySid(b
, tctx
, handle
, domsid
[i
])) {
2414 static bool test_CreateTrustedDomainEx2(struct dcerpc_pipe
*p
,
2415 struct torture_context
*tctx
,
2416 struct policy_handle
*handle
,
2417 uint32_t num_trusts
)
2421 struct lsa_CreateTrustedDomainEx2 r
;
2422 struct lsa_TrustDomainInfoInfoEx trustinfo
;
2423 struct lsa_TrustDomainInfoAuthInfoInternal authinfo
;
2424 struct trustDomainPasswords auth_struct
;
2425 DATA_BLOB auth_blob
;
2426 struct dom_sid
**domsid
;
2427 struct policy_handle
*trustdom_handle
;
2428 struct lsa_QueryTrustedDomainInfo q
;
2429 union lsa_TrustedDomainInfo
*info
= NULL
;
2430 DATA_BLOB session_key
;
2431 enum ndr_err_code ndr_err
;
2433 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
2435 torture_comment(tctx
, "\nTesting CreateTrustedDomainEx2 for %d domains\n", num_trusts
);
2437 domsid
= talloc_array(tctx
, struct dom_sid
*, num_trusts
);
2438 trustdom_handle
= talloc_array(tctx
, struct policy_handle
, num_trusts
);
2440 status
= dcerpc_fetch_session_key(p
, &session_key
);
2441 if (!NT_STATUS_IS_OK(status
)) {
2442 torture_comment(tctx
, "dcerpc_fetch_session_key failed - %s\n", nt_errstr(status
));
2446 for (i
=0; i
< num_trusts
; i
++) {
2447 char *trust_name
= talloc_asprintf(tctx
, "torturedom%02d", i
);
2448 char *trust_name_dns
= talloc_asprintf(tctx
, "torturedom%02d.samba.example.com", i
);
2449 char *trust_sid
= talloc_asprintf(tctx
, "S-1-5-21-97398-379795-100%02d", i
);
2451 domsid
[i
] = dom_sid_parse_talloc(tctx
, trust_sid
);
2453 trustinfo
.sid
= domsid
[i
];
2454 trustinfo
.netbios_name
.string
= trust_name
;
2455 trustinfo
.domain_name
.string
= trust_name_dns
;
2457 /* Create inbound, some outbound, and some
2458 * bi-directional trusts in a repeating pattern based
2461 /* 1 == inbound, 2 == outbound, 3 == both */
2462 trustinfo
.trust_direction
= (i
% 3) + 1;
2464 /* Try different trust types too */
2466 /* 1 == downlevel (NT4), 2 == uplevel (ADS), 3 == MIT (kerberos but not AD) */
2467 trustinfo
.trust_type
= (((i
/ 3) + 1) % 3) + 1;
2469 trustinfo
.trust_attributes
= LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION
;
2471 generate_random_buffer(auth_struct
.confounder
, sizeof(auth_struct
.confounder
));
2473 auth_struct
.outgoing
.count
= 0;
2474 auth_struct
.outgoing
.current
.count
= 0;
2475 auth_struct
.outgoing
.current
.array
= NULL
;
2476 auth_struct
.outgoing
.previous
.count
= 0;
2477 auth_struct
.outgoing
.previous
.array
= NULL
;
2479 auth_struct
.incoming
.count
= 0;
2480 auth_struct
.incoming
.current
.count
= 0;
2481 auth_struct
.incoming
.current
.array
= NULL
;
2482 auth_struct
.incoming
.previous
.count
= 0;
2483 auth_struct
.incoming
.previous
.array
= NULL
;
2486 ndr_err
= ndr_push_struct_blob(&auth_blob
, tctx
, &auth_struct
,
2487 (ndr_push_flags_fn_t
)ndr_push_trustDomainPasswords
);
2488 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2489 torture_comment(tctx
, "ndr_push_struct_blob of trustDomainPasswords structure failed");
2493 arcfour_crypt_blob(auth_blob
.data
, auth_blob
.length
, &session_key
);
2495 authinfo
.auth_blob
.size
= auth_blob
.length
;
2496 authinfo
.auth_blob
.data
= auth_blob
.data
;
2498 r
.in
.policy_handle
= handle
;
2499 r
.in
.info
= &trustinfo
;
2500 r
.in
.auth_info
= &authinfo
;
2501 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2502 r
.out
.trustdom_handle
= &trustdom_handle
[i
];
2504 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateTrustedDomainEx2_r(b
, tctx
, &r
),
2505 "CreateTrustedDomainEx2 failed");
2506 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
2507 test_DeleteTrustedDomain(b
, tctx
, handle
, trustinfo
.netbios_name
);
2508 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateTrustedDomainEx2_r(b
, tctx
, &r
),
2509 "CreateTrustedDomainEx2 failed");
2511 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2512 torture_comment(tctx
, "CreateTrustedDomainEx failed2 - %s\n", nt_errstr(r
.out
.result
));
2516 q
.in
.trustdom_handle
= &trustdom_handle
[i
];
2517 q
.in
.level
= LSA_TRUSTED_DOMAIN_INFO_INFO_EX
;
2519 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfo_r(b
, tctx
, &q
),
2520 "QueryTrustedDomainInfo failed");
2521 if (!NT_STATUS_IS_OK(q
.out
.result
)) {
2522 torture_comment(tctx
, "QueryTrustedDomainInfo level 1 failed - %s\n", nt_errstr(q
.out
.result
));
2524 } else if (!q
.out
.info
) {
2525 torture_comment(tctx
, "QueryTrustedDomainInfo level 1 failed to return an info pointer\n");
2528 if (strcmp(info
->info_ex
.netbios_name
.string
, trustinfo
.netbios_name
.string
) != 0) {
2529 torture_comment(tctx
, "QueryTrustedDomainInfo returned inconsistant short name: %s != %s\n",
2530 info
->info_ex
.netbios_name
.string
, trustinfo
.netbios_name
.string
);
2533 if (info
->info_ex
.trust_type
!= trustinfo
.trust_type
) {
2534 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
2535 trust_name
, info
->info_ex
.trust_type
, trustinfo
.trust_type
);
2538 if (info
->info_ex
.trust_attributes
!= LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION
) {
2539 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
2540 trust_name
, info
->info_ex
.trust_attributes
, LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION
);
2543 if (info
->info_ex
.trust_direction
!= trustinfo
.trust_direction
) {
2544 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
2545 trust_name
, info
->info_ex
.trust_direction
, trustinfo
.trust_direction
);
2552 /* now that we have some domains to look over, we can test the enum calls */
2553 if (!test_EnumTrustDom(b
, tctx
, handle
)) {
2554 torture_comment(tctx
, "test_EnumTrustDom failed\n");
2558 if (!test_EnumTrustDomEx(b
, tctx
, handle
)) {
2559 torture_comment(tctx
, "test_EnumTrustDomEx failed\n");
2563 for (i
=0; i
<num_trusts
; i
++) {
2564 if (!test_DeleteTrustedDomainBySid(b
, tctx
, handle
, domsid
[i
])) {
2565 torture_comment(tctx
, "test_DeleteTrustedDomainBySid failed\n");
2573 static bool test_QueryDomainInfoPolicy(struct dcerpc_binding_handle
*b
,
2574 struct torture_context
*tctx
,
2575 struct policy_handle
*handle
)
2577 struct lsa_QueryDomainInformationPolicy r
;
2578 union lsa_DomainInformationPolicy
*info
= NULL
;
2582 if (torture_setting_bool(tctx
, "samba3", false)) {
2583 torture_skip(tctx
, "skipping QueryDomainInformationPolicy test\n");
2586 torture_comment(tctx
, "\nTesting QueryDomainInformationPolicy\n");
2589 r
.in
.handle
= handle
;
2593 torture_comment(tctx
, "\nTrying QueryDomainInformationPolicy level %d\n", i
);
2595 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryDomainInformationPolicy_r(b
, tctx
, &r
),
2596 "QueryDomainInformationPolicy failed");
2598 /* If the server does not support EFS, then this is the correct return */
2599 if (i
== LSA_DOMAIN_INFO_POLICY_EFS
&& NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
2601 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2602 torture_comment(tctx
, "QueryDomainInformationPolicy failed - %s\n", nt_errstr(r
.out
.result
));
2612 static bool test_QueryInfoPolicyCalls( bool version2
,
2613 struct dcerpc_binding_handle
*b
,
2614 struct torture_context
*tctx
,
2615 struct policy_handle
*handle
)
2617 struct lsa_QueryInfoPolicy r
;
2618 union lsa_PolicyInformation
*info
= NULL
;
2621 const char *call
= talloc_asprintf(tctx
, "QueryInfoPolicy%s", version2
? "2":"");
2623 torture_comment(tctx
, "\nTesting %s\n", call
);
2625 if (version2
&& torture_setting_bool(tctx
, "samba3", false)) {
2626 torture_skip(tctx
, "skipping QueryInfoPolicy2 tests\n");
2629 for (i
=1;i
<=14;i
++) {
2630 r
.in
.handle
= handle
;
2634 torture_comment(tctx
, "\nTrying %s level %d\n", call
, i
);
2637 /* We can perform the cast, because both types are
2638 structurally equal */
2639 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryInfoPolicy2_r(b
, tctx
,
2640 (struct lsa_QueryInfoPolicy2
*) &r
),
2641 "QueryInfoPolicy2 failed");
2643 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryInfoPolicy_r(b
, tctx
, &r
),
2644 "QueryInfoPolicy2 failed");
2647 case LSA_POLICY_INFO_MOD
:
2648 case LSA_POLICY_INFO_AUDIT_FULL_SET
:
2649 case LSA_POLICY_INFO_AUDIT_FULL_QUERY
:
2650 if (!NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_INVALID_PARAMETER
)) {
2651 torture_comment(tctx
, "Server should have failed level %u: %s\n", i
, nt_errstr(r
.out
.result
));
2655 case LSA_POLICY_INFO_DOMAIN
:
2656 case LSA_POLICY_INFO_ACCOUNT_DOMAIN
:
2657 case LSA_POLICY_INFO_REPLICA
:
2658 case LSA_POLICY_INFO_QUOTA
:
2659 case LSA_POLICY_INFO_ROLE
:
2660 case LSA_POLICY_INFO_AUDIT_LOG
:
2661 case LSA_POLICY_INFO_AUDIT_EVENTS
:
2662 case LSA_POLICY_INFO_PD
:
2663 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2664 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(r
.out
.result
));
2668 case LSA_POLICY_INFO_L_ACCOUNT_DOMAIN
:
2669 case LSA_POLICY_INFO_DNS_INT
:
2670 case LSA_POLICY_INFO_DNS
:
2671 if (torture_setting_bool(tctx
, "samba3", false)) {
2672 /* Other levels not implemented yet */
2673 if (!NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_INVALID_INFO_CLASS
)) {
2674 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(r
.out
.result
));
2677 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2678 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(r
.out
.result
));
2683 if (torture_setting_bool(tctx
, "samba4", false)) {
2684 /* Other levels not implemented yet */
2685 if (!NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_INVALID_INFO_CLASS
)) {
2686 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(r
.out
.result
));
2689 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2690 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(r
.out
.result
));
2696 if (NT_STATUS_IS_OK(r
.out
.result
) && (i
== LSA_POLICY_INFO_DNS
2697 || i
== LSA_POLICY_INFO_DNS_INT
)) {
2698 /* Let's look up some of these names */
2700 struct lsa_TransNameArray tnames
;
2702 tnames
.names
= talloc_zero_array(tctx
, struct lsa_TranslatedName
, tnames
.count
);
2703 tnames
.names
[0].name
.string
= info
->dns
.name
.string
;
2704 tnames
.names
[0].sid_type
= SID_NAME_DOMAIN
;
2705 tnames
.names
[1].name
.string
= info
->dns
.dns_domain
.string
;
2706 tnames
.names
[1].sid_type
= SID_NAME_DOMAIN
;
2707 tnames
.names
[2].name
.string
= talloc_asprintf(tctx
, "%s\\", info
->dns
.name
.string
);
2708 tnames
.names
[2].sid_type
= SID_NAME_DOMAIN
;
2709 tnames
.names
[3].name
.string
= talloc_asprintf(tctx
, "%s\\", info
->dns
.dns_domain
.string
);
2710 tnames
.names
[3].sid_type
= SID_NAME_DOMAIN
;
2711 tnames
.names
[4].name
.string
= talloc_asprintf(tctx
, "%s\\guest", info
->dns
.name
.string
);
2712 tnames
.names
[4].sid_type
= SID_NAME_USER
;
2713 tnames
.names
[5].name
.string
= talloc_asprintf(tctx
, "%s\\krbtgt", info
->dns
.name
.string
);
2714 tnames
.names
[5].sid_type
= SID_NAME_USER
;
2715 tnames
.names
[6].name
.string
= talloc_asprintf(tctx
, "%s\\guest", info
->dns
.dns_domain
.string
);
2716 tnames
.names
[6].sid_type
= SID_NAME_USER
;
2717 tnames
.names
[7].name
.string
= talloc_asprintf(tctx
, "%s\\krbtgt", info
->dns
.dns_domain
.string
);
2718 tnames
.names
[7].sid_type
= SID_NAME_USER
;
2719 tnames
.names
[8].name
.string
= talloc_asprintf(tctx
, "krbtgt@%s", info
->dns
.name
.string
);
2720 tnames
.names
[8].sid_type
= SID_NAME_USER
;
2721 tnames
.names
[9].name
.string
= talloc_asprintf(tctx
, "krbtgt@%s", info
->dns
.dns_domain
.string
);
2722 tnames
.names
[9].sid_type
= SID_NAME_USER
;
2723 tnames
.names
[10].name
.string
= talloc_asprintf(tctx
, "%s\\"TEST_MACHINENAME
"$", info
->dns
.name
.string
);
2724 tnames
.names
[10].sid_type
= SID_NAME_USER
;
2725 tnames
.names
[11].name
.string
= talloc_asprintf(tctx
, "%s\\"TEST_MACHINENAME
"$", info
->dns
.dns_domain
.string
);
2726 tnames
.names
[11].sid_type
= SID_NAME_USER
;
2727 tnames
.names
[12].name
.string
= talloc_asprintf(tctx
, TEST_MACHINENAME
"$@%s", info
->dns
.name
.string
);
2728 tnames
.names
[12].sid_type
= SID_NAME_USER
;
2729 tnames
.names
[13].name
.string
= talloc_asprintf(tctx
, TEST_MACHINENAME
"$@%s", info
->dns
.dns_domain
.string
);
2730 tnames
.names
[13].sid_type
= SID_NAME_USER
;
2731 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
2739 static bool test_QueryInfoPolicy(struct dcerpc_binding_handle
*b
,
2740 struct torture_context
*tctx
,
2741 struct policy_handle
*handle
)
2743 return test_QueryInfoPolicyCalls(false, b
, tctx
, handle
);
2746 static bool test_QueryInfoPolicy2(struct dcerpc_binding_handle
*b
,
2747 struct torture_context
*tctx
,
2748 struct policy_handle
*handle
)
2750 return test_QueryInfoPolicyCalls(true, b
, tctx
, handle
);
2753 static bool test_GetUserName(struct dcerpc_binding_handle
*b
,
2754 struct torture_context
*tctx
)
2756 struct lsa_GetUserName r
;
2758 struct lsa_String
*authority_name_p
= NULL
;
2759 struct lsa_String
*account_name_p
= NULL
;
2761 torture_comment(tctx
, "\nTesting GetUserName\n");
2763 r
.in
.system_name
= "\\";
2764 r
.in
.account_name
= &account_name_p
;
2765 r
.in
.authority_name
= NULL
;
2766 r
.out
.account_name
= &account_name_p
;
2768 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_GetUserName_r(b
, tctx
, &r
),
2769 "GetUserName failed");
2771 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2772 torture_comment(tctx
, "GetUserName failed - %s\n", nt_errstr(r
.out
.result
));
2776 account_name_p
= NULL
;
2777 r
.in
.account_name
= &account_name_p
;
2778 r
.in
.authority_name
= &authority_name_p
;
2779 r
.out
.account_name
= &account_name_p
;
2781 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_GetUserName_r(b
, tctx
, &r
),
2782 "GetUserName failed");
2784 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2785 torture_comment(tctx
, "GetUserName failed - %s\n", nt_errstr(r
.out
.result
));
2792 bool test_lsa_Close(struct dcerpc_binding_handle
*b
,
2793 struct torture_context
*tctx
,
2794 struct policy_handle
*handle
)
2797 struct policy_handle handle2
;
2799 torture_comment(tctx
, "\nTesting Close\n");
2801 r
.in
.handle
= handle
;
2802 r
.out
.handle
= &handle2
;
2804 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_Close_r(b
, tctx
, &r
),
2806 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2807 torture_comment(tctx
, "Close failed - %s\n",
2808 nt_errstr(r
.out
.result
));
2812 torture_assert_ntstatus_equal(tctx
, dcerpc_lsa_Close_r(b
, tctx
, &r
),
2813 NT_STATUS_RPC_SS_CONTEXT_MISMATCH
, "Close should failed");
2815 torture_comment(tctx
, "\n");
2820 bool torture_rpc_lsa(struct torture_context
*tctx
)
2823 struct dcerpc_pipe
*p
;
2825 struct policy_handle
*handle
;
2826 struct test_join
*join
= NULL
;
2827 struct cli_credentials
*machine_creds
;
2828 struct dcerpc_binding_handle
*b
;
2830 status
= torture_rpc_connection(tctx
, &p
, &ndr_table_lsarpc
);
2831 if (!NT_STATUS_IS_OK(status
)) {
2834 b
= p
->binding_handle
;
2836 if (!test_OpenPolicy(b
, tctx
)) {
2840 if (!test_lsa_OpenPolicy2(b
, tctx
, &handle
)) {
2845 join
= torture_join_domain(tctx
, TEST_MACHINENAME
, ACB_WSTRUST
, &machine_creds
);
2850 if (!test_LookupSids_async(b
, tctx
, handle
)) {
2854 if (!test_QueryDomainInfoPolicy(b
, tctx
, handle
)) {
2858 if (!test_CreateSecret(p
, tctx
, handle
)) {
2862 if (!test_QueryInfoPolicy(b
, tctx
, handle
)) {
2866 if (!test_QueryInfoPolicy2(b
, tctx
, handle
)) {
2870 if (!test_Delete(b
, tctx
, handle
)) {
2874 if (!test_many_LookupSids(p
, tctx
, handle
)) {
2878 if (!test_lsa_Close(b
, tctx
, handle
)) {
2882 torture_leave_domain(tctx
, join
);
2885 if (!test_many_LookupSids(p
, tctx
, handle
)) {
2890 if (!test_GetUserName(b
, tctx
)) {
2897 bool torture_rpc_lsa_get_user(struct torture_context
*tctx
)
2900 struct dcerpc_pipe
*p
;
2902 struct dcerpc_binding_handle
*b
;
2904 status
= torture_rpc_connection(tctx
, &p
, &ndr_table_lsarpc
);
2905 if (!NT_STATUS_IS_OK(status
)) {
2908 b
= p
->binding_handle
;
2910 if (!test_GetUserName(b
, tctx
)) {
2917 static bool testcase_LookupNames(struct torture_context
*tctx
,
2918 struct dcerpc_pipe
*p
)
2921 struct policy_handle
*handle
;
2922 struct lsa_TransNameArray tnames
;
2923 struct lsa_TransNameArray2 tnames2
;
2924 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
2926 if (!test_OpenPolicy(b
, tctx
)) {
2930 if (!test_lsa_OpenPolicy2(b
, tctx
, &handle
)) {
2939 tnames
.names
= talloc_array(tctx
, struct lsa_TranslatedName
, tnames
.count
);
2940 ZERO_STRUCT(tnames
.names
[0]);
2941 tnames
.names
[0].name
.string
= "BUILTIN";
2942 tnames
.names
[0].sid_type
= SID_NAME_DOMAIN
;
2944 if (!test_LookupNames(b
, tctx
, handle
, &tnames
)) {
2949 tnames2
.names
= talloc_array(tctx
, struct lsa_TranslatedName2
, tnames2
.count
);
2950 ZERO_STRUCT(tnames2
.names
[0]);
2951 tnames2
.names
[0].name
.string
= "BUILTIN";
2952 tnames2
.names
[0].sid_type
= SID_NAME_DOMAIN
;
2954 if (!test_LookupNames2(b
, tctx
, handle
, &tnames2
, true)) {
2958 if (!test_LookupNames3(b
, tctx
, handle
, &tnames2
, true)) {
2962 if (!test_LookupNames_wellknown(b
, tctx
, handle
)) {
2966 if (!test_LookupNames_NULL(b
, tctx
, handle
)) {
2970 if (!test_LookupNames_bogus(b
, tctx
, handle
)) {
2974 if (!test_lsa_Close(b
, tctx
, handle
)) {
2981 struct torture_suite
*torture_rpc_lsa_lookup_names(TALLOC_CTX
*mem_ctx
)
2983 struct torture_suite
*suite
;
2984 struct torture_rpc_tcase
*tcase
;
2986 suite
= torture_suite_create(mem_ctx
, "LSA-LOOKUPNAMES");
2988 tcase
= torture_suite_add_rpc_iface_tcase(suite
, "lsa",
2990 torture_rpc_tcase_add_test(tcase
, "LookupNames",
2991 testcase_LookupNames
);
2996 struct lsa_trustdom_state
{
2997 uint32_t num_trusts
;
3000 static bool testcase_TrustedDomains(struct torture_context
*tctx
,
3001 struct dcerpc_pipe
*p
,
3005 struct policy_handle
*handle
;
3006 struct lsa_trustdom_state
*state
=
3007 talloc_get_type_abort(data
, struct lsa_trustdom_state
);
3008 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
3010 torture_comment(tctx
, "Testing %d domains\n", state
->num_trusts
);
3012 if (!test_OpenPolicy(b
, tctx
)) {
3016 if (!test_lsa_OpenPolicy2(b
, tctx
, &handle
)) {
3024 if (!test_CreateTrustedDomain(b
, tctx
, handle
, state
->num_trusts
)) {
3028 if (!test_CreateTrustedDomainEx2(p
, tctx
, handle
, state
->num_trusts
)) {
3032 if (!test_lsa_Close(b
, tctx
, handle
)) {
3039 struct torture_suite
*torture_rpc_lsa_trusted_domains(TALLOC_CTX
*mem_ctx
)
3041 struct torture_suite
*suite
;
3042 struct torture_rpc_tcase
*tcase
;
3043 struct lsa_trustdom_state
*state
;
3045 state
= talloc(mem_ctx
, struct lsa_trustdom_state
);
3047 state
->num_trusts
= 12;
3049 suite
= torture_suite_create(mem_ctx
, "LSA-TRUSTED-DOMAINS");
3051 tcase
= torture_suite_add_rpc_iface_tcase(suite
, "lsa",
3053 torture_rpc_tcase_add_test_ex(tcase
, "TrustedDomains",
3054 testcase_TrustedDomains
,
3060 static bool testcase_Privileges(struct torture_context
*tctx
,
3061 struct dcerpc_pipe
*p
)
3064 struct policy_handle
*handle
;
3065 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
3067 if (!test_OpenPolicy(b
, tctx
)) {
3071 if (!test_lsa_OpenPolicy2(b
, tctx
, &handle
)) {
3079 if (!test_CreateAccount(b
, tctx
, handle
)) {
3083 if (!test_EnumAccounts(b
, tctx
, handle
)) {
3087 if (!test_EnumPrivs(b
, tctx
, handle
)) {
3091 if (!test_lsa_Close(b
, tctx
, handle
)) {
3099 struct torture_suite
*torture_rpc_lsa_privileges(TALLOC_CTX
*mem_ctx
)
3101 struct torture_suite
*suite
;
3102 struct torture_rpc_tcase
*tcase
;
3104 suite
= torture_suite_create(mem_ctx
, "LSA-PRIVILEGES");
3106 tcase
= torture_suite_add_rpc_iface_tcase(suite
, "lsa",
3108 torture_rpc_tcase_add_test(tcase
, "Privileges",
3109 testcase_Privileges
);