2 Unix SMB/CIFS implementation.
3 test suite for lsa rpc operations
5 Copyright (C) Andrew Tridgell 2003
6 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2004-2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "torture/torture.h"
24 #include "librpc/gen_ndr/ndr_lsa_c.h"
25 #include "librpc/gen_ndr/netlogon.h"
26 #include "librpc/gen_ndr/ndr_drsblobs.h"
27 #include "librpc/gen_ndr/ndr_netlogon_c.h"
28 #include "lib/events/events.h"
29 #include "libcli/security/security.h"
30 #include "libcli/auth/libcli_auth.h"
31 #include "torture/rpc/torture_rpc.h"
32 #include "param/param.h"
33 #include "../lib/crypto/crypto.h"
34 #define TEST_MACHINENAME "lsatestmach"
35 #define TRUSTPW "12345678"
37 static void init_lsa_String(struct lsa_String
*name
, const char *s
)
42 static bool test_OpenPolicy(struct dcerpc_binding_handle
*b
,
43 struct torture_context
*tctx
)
45 struct lsa_ObjectAttribute attr
;
46 struct policy_handle handle
;
47 struct lsa_QosInfo qos
;
48 struct lsa_OpenPolicy r
;
49 uint16_t system_name
= '\\';
51 torture_comment(tctx
, "\nTesting OpenPolicy\n");
54 qos
.impersonation_level
= 2;
56 qos
.effective_only
= 0;
60 attr
.object_name
= NULL
;
65 r
.in
.system_name
= &system_name
;
67 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
68 r
.out
.handle
= &handle
;
70 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenPolicy_r(b
, tctx
, &r
),
73 torture_assert_ntstatus_ok(tctx
,
80 static bool test_OpenPolicy_fail(struct dcerpc_binding_handle
*b
,
81 struct torture_context
*tctx
)
83 struct lsa_ObjectAttribute attr
;
84 struct policy_handle handle
;
85 struct lsa_QosInfo qos
;
86 struct lsa_OpenPolicy r
;
87 uint16_t system_name
= '\\';
90 torture_comment(tctx
, "\nTesting OpenPolicy_fail\n");
93 qos
.impersonation_level
= 2;
95 qos
.effective_only
= 0;
99 attr
.object_name
= NULL
;
101 attr
.sec_desc
= NULL
;
104 r
.in
.system_name
= &system_name
;
106 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
107 r
.out
.handle
= &handle
;
109 status
= dcerpc_lsa_OpenPolicy_r(b
, tctx
, &r
);
110 if (!NT_STATUS_IS_OK(status
)) {
111 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
112 torture_comment(tctx
,
113 "OpenPolicy correctly returned with "
119 torture_assert_ntstatus_equal(tctx
,
121 NT_STATUS_ACCESS_DENIED
,
122 "OpenPolicy return value should "
127 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
128 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_ACCESS_DENIED
) ||
129 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
130 torture_comment(tctx
,
131 "OpenPolicy correctly returned with "
133 nt_errstr(r
.out
.result
));
138 torture_assert_ntstatus_equal(tctx
,
141 "OpenPolicy return value should be "
148 bool test_lsa_OpenPolicy2_ex(struct dcerpc_binding_handle
*b
,
149 struct torture_context
*tctx
,
150 struct policy_handle
**handle
,
151 NTSTATUS expected_status
)
153 struct lsa_ObjectAttribute attr
;
154 struct lsa_QosInfo qos
;
155 struct lsa_OpenPolicy2 r
;
158 torture_comment(tctx
, "\nTesting OpenPolicy2\n");
160 *handle
= talloc(tctx
, struct policy_handle
);
166 qos
.impersonation_level
= 2;
167 qos
.context_mode
= 1;
168 qos
.effective_only
= 0;
171 attr
.root_dir
= NULL
;
172 attr
.object_name
= NULL
;
174 attr
.sec_desc
= NULL
;
177 r
.in
.system_name
= "\\";
179 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
180 r
.out
.handle
= *handle
;
182 status
= dcerpc_lsa_OpenPolicy2_r(b
, tctx
, &r
);
183 torture_assert_ntstatus_equal(tctx
, status
, expected_status
,
184 "OpenPolicy2 failed");
185 if (!NT_STATUS_IS_OK(expected_status
)) {
189 torture_assert_ntstatus_ok(tctx
,
191 "OpenPolicy2 failed");
197 bool test_lsa_OpenPolicy2(struct dcerpc_binding_handle
*b
,
198 struct torture_context
*tctx
,
199 struct policy_handle
**handle
)
201 return test_lsa_OpenPolicy2_ex(b
, tctx
, handle
, NT_STATUS_OK
);
204 static bool test_OpenPolicy2_fail(struct dcerpc_binding_handle
*b
,
205 struct torture_context
*tctx
)
207 struct lsa_ObjectAttribute attr
;
208 struct policy_handle handle
;
209 struct lsa_QosInfo qos
;
210 struct lsa_OpenPolicy2 r
;
213 torture_comment(tctx
, "\nTesting OpenPolicy2_fail\n");
216 qos
.impersonation_level
= 2;
217 qos
.context_mode
= 1;
218 qos
.effective_only
= 0;
221 attr
.root_dir
= NULL
;
222 attr
.object_name
= NULL
;
224 attr
.sec_desc
= NULL
;
227 r
.in
.system_name
= "\\";
229 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
230 r
.out
.handle
= &handle
;
232 status
= dcerpc_lsa_OpenPolicy2_r(b
, tctx
, &r
);
233 if (!NT_STATUS_IS_OK(status
)) {
234 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
235 torture_comment(tctx
,
236 "OpenPolicy2 correctly returned with "
242 torture_assert_ntstatus_equal(tctx
,
244 NT_STATUS_ACCESS_DENIED
,
245 "OpenPolicy2 return value should "
250 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
251 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_ACCESS_DENIED
) ||
252 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
253 torture_comment(tctx
,
254 "OpenPolicy2 correctly returned with "
256 nt_errstr(r
.out
.result
));
261 torture_assert_ntstatus_equal(tctx
,
264 "OpenPolicy2 return value should be "
270 static bool test_LookupNames(struct dcerpc_binding_handle
*b
,
271 struct torture_context
*tctx
,
272 struct policy_handle
*handle
,
273 struct lsa_TransNameArray
*tnames
)
275 struct lsa_LookupNames r
;
276 struct lsa_TransSidArray sids
;
277 struct lsa_RefDomainList
*domains
= NULL
;
278 struct lsa_String
*names
;
283 torture_comment(tctx
, "\nTesting LookupNames with %d names\n", tnames
->count
);
291 input_idx
= talloc_array(tctx
, uint32_t, tnames
->count
);
292 names
= talloc_array(tctx
, struct lsa_String
, tnames
->count
);
294 for (i
=0;i
<tnames
->count
;i
++) {
295 if (tnames
->names
[i
].sid_type
!= SID_NAME_UNKNOWN
) {
296 init_lsa_String(&names
[r
.in
.num_names
], tnames
->names
[i
].name
.string
);
297 input_idx
[r
.in
.num_names
] = i
;
302 r
.in
.handle
= handle
;
307 r
.out
.count
= &count
;
309 r
.out
.domains
= &domains
;
311 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames_r(b
, tctx
, &r
),
312 "LookupNames failed");
313 if (NT_STATUS_EQUAL(r
.out
.result
, STATUS_SOME_UNMAPPED
) ||
314 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NONE_MAPPED
)) {
315 for (i
=0;i
< r
.in
.num_names
;i
++) {
316 if (i
< count
&& sids
.sids
[i
].sid_type
== SID_NAME_UNKNOWN
) {
317 torture_comment(tctx
, "LookupName of %s was unmapped\n",
318 tnames
->names
[i
].name
.string
);
319 } else if (i
>=count
) {
320 torture_comment(tctx
, "LookupName of %s failed to return a result\n",
321 tnames
->names
[i
].name
.string
);
324 torture_comment(tctx
, "LookupNames failed - %s\n",
325 nt_errstr(r
.out
.result
));
327 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
328 torture_comment(tctx
, "LookupNames failed - %s\n",
329 nt_errstr(r
.out
.result
));
333 for (i
=0;i
< r
.in
.num_names
;i
++) {
335 if (sids
.sids
[i
].sid_type
!= tnames
->names
[input_idx
[i
]].sid_type
) {
336 torture_comment(tctx
, "LookupName of %s got unexpected name type: %s\n",
337 tnames
->names
[input_idx
[i
]].name
.string
,
338 sid_type_lookup(sids
.sids
[i
].sid_type
));
341 if ((sids
.sids
[i
].sid_type
== SID_NAME_DOMAIN
) &&
342 (sids
.sids
[i
].rid
!= (uint32_t)-1)) {
343 torture_comment(tctx
, "LookupName of %s got unexpected rid: %d\n",
344 tnames
->names
[input_idx
[i
]].name
.string
, sids
.sids
[i
].rid
);
347 } else if (i
>=count
) {
348 torture_comment(tctx
, "LookupName of %s failed to return a result\n",
349 tnames
->names
[input_idx
[i
]].name
.string
);
353 torture_comment(tctx
, "\n");
358 static bool test_LookupNames_bogus(struct dcerpc_binding_handle
*b
,
359 struct torture_context
*tctx
,
360 struct policy_handle
*handle
)
362 struct lsa_LookupNames r
;
363 struct lsa_TransSidArray sids
;
364 struct lsa_RefDomainList
*domains
= NULL
;
365 struct lsa_String names
[1];
368 torture_comment(tctx
, "\nTesting LookupNames with bogus name\n");
373 init_lsa_String(&names
[0], "NT AUTHORITY\\BOGUS");
375 r
.in
.handle
= handle
;
381 r
.out
.count
= &count
;
383 r
.out
.domains
= &domains
;
385 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames_r(b
, tctx
, &r
),
386 "LookupNames bogus failed");
387 if (!NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NONE_MAPPED
)) {
388 torture_comment(tctx
, "LookupNames failed - %s\n",
389 nt_errstr(r
.out
.result
));
393 torture_comment(tctx
, "\n");
398 static bool test_LookupNames_NULL(struct dcerpc_binding_handle
*b
,
399 struct torture_context
*tctx
,
400 struct policy_handle
*handle
)
402 struct lsa_LookupNames r
;
403 struct lsa_TransSidArray sids
;
404 struct lsa_RefDomainList
*domains
= NULL
;
405 struct lsa_String names
[1];
408 torture_comment(tctx
, "\nTesting LookupNames with NULL name\n");
413 names
[0].string
= NULL
;
415 r
.in
.handle
= handle
;
421 r
.out
.count
= &count
;
423 r
.out
.domains
= &domains
;
425 /* nt4 returns NT_STATUS_NONE_MAPPED with sid_type
426 * SID_NAME_UNKNOWN, rid 0, and sid_index -1;
428 * w2k3/w2k8 return NT_STATUS_OK with sid_type
429 * SID_NAME_DOMAIN, rid -1 and sid_index 0 and BUILTIN domain
432 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames_r(b
, tctx
, &r
),
433 "LookupNames with NULL name failed");
434 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
435 "LookupNames with NULL name failed");
437 torture_comment(tctx
, "\n");
442 static bool test_LookupNames_wellknown(struct dcerpc_binding_handle
*b
,
443 struct torture_context
*tctx
,
444 struct policy_handle
*handle
)
446 struct lsa_TranslatedName name
;
447 struct lsa_TransNameArray tnames
;
450 torture_comment(tctx
, "Testing LookupNames with well known names\n");
452 tnames
.names
= &name
;
454 name
.name
.string
= "NT AUTHORITY\\SYSTEM";
455 name
.sid_type
= SID_NAME_WKN_GRP
;
456 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
458 name
.name
.string
= "NT AUTHORITY\\ANONYMOUS LOGON";
459 name
.sid_type
= SID_NAME_WKN_GRP
;
460 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
462 name
.name
.string
= "NT AUTHORITY\\Authenticated Users";
463 name
.sid_type
= SID_NAME_WKN_GRP
;
464 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
467 name
.name
.string
= "NT AUTHORITY";
468 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
470 name
.name
.string
= "NT AUTHORITY\\";
471 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
474 name
.name
.string
= "BUILTIN\\";
475 name
.sid_type
= SID_NAME_DOMAIN
;
476 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
478 name
.name
.string
= "BUILTIN\\Administrators";
479 name
.sid_type
= SID_NAME_ALIAS
;
480 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
482 name
.name
.string
= "SYSTEM";
483 name
.sid_type
= SID_NAME_WKN_GRP
;
484 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
486 name
.name
.string
= "Everyone";
487 name
.sid_type
= SID_NAME_WKN_GRP
;
488 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
492 static bool test_LookupNames2(struct dcerpc_binding_handle
*b
,
493 struct torture_context
*tctx
,
494 struct policy_handle
*handle
,
495 struct lsa_TransNameArray2
*tnames
,
498 struct lsa_LookupNames2 r
;
499 struct lsa_TransSidArray2 sids
;
500 struct lsa_RefDomainList
*domains
= NULL
;
501 struct lsa_String
*names
;
506 torture_comment(tctx
, "\nTesting LookupNames2 with %d names\n", tnames
->count
);
513 input_idx
= talloc_array(tctx
, uint32_t, tnames
->count
);
514 names
= talloc_array(tctx
, struct lsa_String
, tnames
->count
);
516 for (i
=0;i
<tnames
->count
;i
++) {
517 if (tnames
->names
[i
].sid_type
!= SID_NAME_UNKNOWN
) {
518 init_lsa_String(&names
[r
.in
.num_names
], tnames
->names
[i
].name
.string
);
519 input_idx
[r
.in
.num_names
] = i
;
524 r
.in
.handle
= handle
;
529 r
.in
.lookup_options
= 0;
530 r
.in
.client_revision
= 0;
531 r
.out
.count
= &count
;
533 r
.out
.domains
= &domains
;
535 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames2_r(b
, tctx
, &r
),
536 "LookupNames2 failed");
537 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
538 torture_comment(tctx
, "LookupNames2 failed - %s\n",
539 nt_errstr(r
.out
.result
));
544 torture_assert_int_equal(tctx
, count
, sids
.count
,
545 "unexpected number of results returned");
546 if (sids
.count
> 0) {
547 torture_assert(tctx
, sids
.sids
, "invalid sid buffer");
551 torture_comment(tctx
, "\n");
557 static bool test_LookupNames3(struct dcerpc_binding_handle
*b
,
558 struct torture_context
*tctx
,
559 struct policy_handle
*handle
,
560 struct lsa_TransNameArray2
*tnames
,
563 struct lsa_LookupNames3 r
;
564 struct lsa_TransSidArray3 sids
;
565 struct lsa_RefDomainList
*domains
= NULL
;
566 struct lsa_String
*names
;
571 torture_comment(tctx
, "\nTesting LookupNames3 with %d names\n", tnames
->count
);
578 input_idx
= talloc_array(tctx
, uint32_t, tnames
->count
);
579 names
= talloc_array(tctx
, struct lsa_String
, tnames
->count
);
580 for (i
=0;i
<tnames
->count
;i
++) {
581 if (tnames
->names
[i
].sid_type
!= SID_NAME_UNKNOWN
) {
582 init_lsa_String(&names
[r
.in
.num_names
], tnames
->names
[i
].name
.string
);
583 input_idx
[r
.in
.num_names
] = i
;
588 r
.in
.handle
= handle
;
593 r
.in
.lookup_options
= 0;
594 r
.in
.client_revision
= 0;
595 r
.out
.count
= &count
;
597 r
.out
.domains
= &domains
;
599 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames3_r(b
, tctx
, &r
),
600 "LookupNames3 failed");
601 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
602 torture_comment(tctx
, "LookupNames3 failed - %s\n",
603 nt_errstr(r
.out
.result
));
608 torture_assert_int_equal(tctx
, count
, sids
.count
,
609 "unexpected number of results returned");
610 if (sids
.count
> 0) {
611 torture_assert(tctx
, sids
.sids
, "invalid sid buffer");
615 torture_comment(tctx
, "\n");
620 static bool test_LookupNames4(struct dcerpc_binding_handle
*b
,
621 struct torture_context
*tctx
,
622 struct lsa_TransNameArray2
*tnames
,
625 struct lsa_LookupNames4 r
;
626 struct lsa_TransSidArray3 sids
;
627 struct lsa_RefDomainList
*domains
= NULL
;
628 struct lsa_String
*names
;
633 torture_comment(tctx
, "\nTesting LookupNames4 with %d names\n", tnames
->count
);
640 input_idx
= talloc_array(tctx
, uint32_t, tnames
->count
);
641 names
= talloc_array(tctx
, struct lsa_String
, tnames
->count
);
642 for (i
=0;i
<tnames
->count
;i
++) {
643 if (tnames
->names
[i
].sid_type
!= SID_NAME_UNKNOWN
) {
644 init_lsa_String(&names
[r
.in
.num_names
], tnames
->names
[i
].name
.string
);
645 input_idx
[r
.in
.num_names
] = i
;
650 r
.in
.num_names
= tnames
->count
;
655 r
.in
.lookup_options
= 0;
656 r
.in
.client_revision
= 0;
657 r
.out
.count
= &count
;
659 r
.out
.domains
= &domains
;
661 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames4_r(b
, tctx
, &r
),
662 "LookupNames4 failed");
664 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
665 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NONE_MAPPED
)) {
666 torture_comment(tctx
,
667 "LookupNames4 failed: %s - not considered as an error",
668 nt_errstr(r
.out
.result
));
673 torture_assert_ntstatus_ok(tctx
,
675 "LookupNames4 failed");
681 torture_assert_int_equal(tctx
, count
, sids
.count
,
682 "unexpected number of results returned");
683 if (sids
.count
> 0) {
684 torture_assert(tctx
, sids
.sids
, "invalid sid buffer");
688 torture_comment(tctx
, "\n");
693 static bool test_LookupNames4_fail(struct dcerpc_binding_handle
*b
,
694 struct torture_context
*tctx
)
696 struct lsa_LookupNames4 r
;
697 struct lsa_TransSidArray3 sids
;
698 struct lsa_RefDomainList
*domains
= NULL
;
699 struct lsa_String
*names
= NULL
;
703 torture_comment(tctx
, "\nTesting LookupNames4_fail");
710 r
.in
.num_names
= count
;
715 r
.in
.lookup_options
= 0;
716 r
.in
.client_revision
= 0;
717 r
.out
.count
= &count
;
719 r
.out
.domains
= &domains
;
721 status
= dcerpc_lsa_LookupNames4_r(b
, tctx
, &r
);
722 if (!NT_STATUS_IS_OK(status
)) {
723 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
724 torture_comment(tctx
,
725 "LookupNames4 correctly returned with "
731 torture_assert_ntstatus_equal(tctx
,
733 NT_STATUS_ACCESS_DENIED
,
734 "LookupNames4 return value should "
739 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
740 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_ACCESS_DENIED
) ||
741 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
742 torture_comment(tctx
,
743 "LookupSids3 correctly returned with "
745 nt_errstr(r
.out
.result
));
750 torture_assert_ntstatus_equal(tctx
,
753 "LookupNames4 return value should be "
760 static bool test_LookupSids(struct dcerpc_binding_handle
*b
,
761 struct torture_context
*tctx
,
762 struct policy_handle
*handle
,
763 struct lsa_SidArray
*sids
)
765 struct lsa_LookupSids r
;
766 struct lsa_TransNameArray names
;
767 struct lsa_RefDomainList
*domains
= NULL
;
768 uint32_t count
= sids
->num_sids
;
770 torture_comment(tctx
, "\nTesting LookupSids\n");
775 r
.in
.handle
= handle
;
780 r
.out
.count
= &count
;
781 r
.out
.names
= &names
;
782 r
.out
.domains
= &domains
;
784 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupSids_r(b
, tctx
, &r
),
785 "LookupSids failed");
786 if (!NT_STATUS_IS_OK(r
.out
.result
) &&
787 !NT_STATUS_EQUAL(r
.out
.result
, STATUS_SOME_UNMAPPED
)) {
788 torture_comment(tctx
, "LookupSids failed - %s\n",
789 nt_errstr(r
.out
.result
));
793 torture_comment(tctx
, "\n");
795 if (!test_LookupNames(b
, tctx
, handle
, &names
)) {
803 static bool test_LookupSids2(struct dcerpc_binding_handle
*b
,
804 struct torture_context
*tctx
,
805 struct policy_handle
*handle
,
806 struct lsa_SidArray
*sids
)
808 struct lsa_LookupSids2 r
;
809 struct lsa_TransNameArray2 names
;
810 struct lsa_RefDomainList
*domains
= NULL
;
811 uint32_t count
= sids
->num_sids
;
813 torture_comment(tctx
, "\nTesting LookupSids2\n");
818 r
.in
.handle
= handle
;
823 r
.in
.lookup_options
= 0;
824 r
.in
.client_revision
= 0;
825 r
.out
.count
= &count
;
826 r
.out
.names
= &names
;
827 r
.out
.domains
= &domains
;
829 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupSids2_r(b
, tctx
, &r
),
830 "LookupSids2 failed");
831 if (!NT_STATUS_IS_OK(r
.out
.result
) &&
832 !NT_STATUS_EQUAL(r
.out
.result
, STATUS_SOME_UNMAPPED
)) {
833 torture_comment(tctx
, "LookupSids2 failed - %s\n",
834 nt_errstr(r
.out
.result
));
838 torture_comment(tctx
, "\n");
840 if (!test_LookupNames2(b
, tctx
, handle
, &names
, false)) {
844 if (!test_LookupNames3(b
, tctx
, handle
, &names
, false)) {
851 static bool test_LookupSids3(struct dcerpc_binding_handle
*b
,
852 struct torture_context
*tctx
,
853 struct lsa_SidArray
*sids
)
855 struct lsa_LookupSids3 r
;
856 struct lsa_TransNameArray2 names
;
857 struct lsa_RefDomainList
*domains
= NULL
;
858 uint32_t count
= sids
->num_sids
;
860 torture_comment(tctx
, "\nTesting LookupSids3\n");
869 r
.in
.lookup_options
= 0;
870 r
.in
.client_revision
= 0;
871 r
.out
.domains
= &domains
;
872 r
.out
.count
= &count
;
873 r
.out
.names
= &names
;
875 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupSids3_r(b
, tctx
, &r
),
876 "LookupSids3 failed");
878 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
879 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NONE_MAPPED
)) {
880 torture_comment(tctx
,
881 "LookupSids3 failed: %s - not considered as an error",
882 nt_errstr(r
.out
.result
));
887 torture_assert_ntstatus_ok(tctx
,
889 "LookupSids3 failed");
894 torture_comment(tctx
, "\n");
896 if (!test_LookupNames4(b
, tctx
, &names
, true)) {
903 static bool test_LookupSids3_fail(struct dcerpc_binding_handle
*b
,
904 struct torture_context
*tctx
,
905 struct lsa_SidArray
*sids
)
907 struct lsa_LookupSids3 r
;
908 struct lsa_TransNameArray2 names
;
909 struct lsa_RefDomainList
*domains
= NULL
;
910 uint32_t count
= sids
->num_sids
;
913 torture_comment(tctx
, "\nTesting LookupSids3\n");
922 r
.in
.lookup_options
= 0;
923 r
.in
.client_revision
= 0;
924 r
.out
.domains
= &domains
;
925 r
.out
.count
= &count
;
926 r
.out
.names
= &names
;
928 status
= dcerpc_lsa_LookupSids3_r(b
, tctx
, &r
);
929 if (!NT_STATUS_IS_OK(status
)) {
930 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
931 torture_comment(tctx
,
932 "LookupSids3 correctly returned with "
938 torture_assert_ntstatus_equal(tctx
,
940 NT_STATUS_ACCESS_DENIED
,
941 "LookupSids3 return value should "
946 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
947 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_ACCESS_DENIED
) ||
948 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
949 torture_comment(tctx
,
950 "LookupNames4 correctly returned with "
952 nt_errstr(r
.out
.result
));
957 torture_assert_ntstatus_equal(tctx
,
960 "LookupSids3 return value should be "
966 bool test_many_LookupSids(struct dcerpc_pipe
*p
,
967 struct torture_context
*tctx
,
968 struct policy_handle
*handle
)
971 struct lsa_SidArray sids
;
973 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
975 torture_comment(tctx
, "\nTesting LookupSids with lots of SIDs\n");
979 sids
.sids
= talloc_array(tctx
, struct lsa_SidPtr
, sids
.num_sids
);
981 for (i
=0; i
<sids
.num_sids
; i
++) {
982 const char *sidstr
= "S-1-5-32-545";
983 sids
.sids
[i
].sid
= dom_sid_parse_talloc(tctx
, sidstr
);
986 count
= sids
.num_sids
;
989 struct lsa_LookupSids r
;
990 struct lsa_TransNameArray names
;
991 struct lsa_RefDomainList
*domains
= NULL
;
995 r
.in
.handle
= handle
;
999 r
.in
.count
= &names
.count
;
1000 r
.out
.count
= &count
;
1001 r
.out
.names
= &names
;
1002 r
.out
.domains
= &domains
;
1004 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupSids_r(b
, tctx
, &r
),
1005 "LookupSids failed");
1006 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1007 torture_comment(tctx
, "LookupSids failed - %s\n",
1008 nt_errstr(r
.out
.result
));
1012 torture_comment(tctx
, "\n");
1014 if (!test_LookupNames(b
, tctx
, handle
, &names
)) {
1019 if (p
->binding
->transport
== NCACN_NP
) {
1020 if (!test_LookupSids3_fail(b
, tctx
, &sids
)) {
1023 if (!test_LookupNames4_fail(b
, tctx
)) {
1026 } else if (p
->binding
->transport
== NCACN_IP_TCP
) {
1027 struct lsa_TransNameArray2 names
;
1032 if (p
->conn
->security_state
.auth_info
->auth_type
== DCERPC_AUTH_TYPE_SCHANNEL
&&
1033 p
->conn
->security_state
.auth_info
->auth_level
>= DCERPC_AUTH_LEVEL_INTEGRITY
) {
1034 if (!test_LookupSids3(b
, tctx
, &sids
)) {
1037 if (!test_LookupNames4(b
, tctx
, &names
, true)) {
1042 * If we don't have a secure channel these tests must
1043 * fail with ACCESS_DENIED.
1045 if (!test_LookupSids3_fail(b
, tctx
, &sids
)) {
1048 if (!test_LookupNames4_fail(b
, tctx
)) {
1054 torture_comment(tctx
, "\n");
1061 static void lookupsids_cb(struct tevent_req
*subreq
)
1063 int *replies
= (int *)tevent_req_callback_data_void(subreq
);
1066 status
= dcerpc_lsa_LookupSids_r_recv(subreq
, subreq
);
1067 TALLOC_FREE(subreq
);
1068 if (!NT_STATUS_IS_OK(status
)) {
1069 printf("lookupsids returned %s\n", nt_errstr(status
));
1073 if (*replies
>= 0) {
1078 static bool test_LookupSids_async(struct dcerpc_binding_handle
*b
,
1079 struct torture_context
*tctx
,
1080 struct policy_handle
*handle
)
1082 struct lsa_SidArray sids
;
1083 struct lsa_SidPtr sidptr
;
1085 struct lsa_TransNameArray
*names
;
1086 struct lsa_LookupSids
*r
;
1087 struct lsa_RefDomainList
*domains
= NULL
;
1088 struct tevent_req
**req
;
1091 const int num_async_requests
= 50;
1093 count
= talloc_array(tctx
, uint32_t, num_async_requests
);
1094 names
= talloc_array(tctx
, struct lsa_TransNameArray
, num_async_requests
);
1095 r
= talloc_array(tctx
, struct lsa_LookupSids
, num_async_requests
);
1097 torture_comment(tctx
, "\nTesting %d async lookupsids request\n", num_async_requests
);
1099 req
= talloc_array(tctx
, struct tevent_req
*, num_async_requests
);
1102 sids
.sids
= &sidptr
;
1103 sidptr
.sid
= dom_sid_parse_talloc(tctx
, "S-1-5-32-545");
1107 for (i
=0; i
<num_async_requests
; i
++) {
1110 names
[i
].names
= NULL
;
1112 r
[i
].in
.handle
= handle
;
1113 r
[i
].in
.sids
= &sids
;
1114 r
[i
].in
.names
= &names
[i
];
1116 r
[i
].in
.count
= &names
[i
].count
;
1117 r
[i
].out
.count
= &count
[i
];
1118 r
[i
].out
.names
= &names
[i
];
1119 r
[i
].out
.domains
= &domains
;
1121 req
[i
] = dcerpc_lsa_LookupSids_r_send(tctx
, tctx
->ev
, b
, &r
[i
]);
1122 if (req
[i
] == NULL
) {
1127 tevent_req_set_callback(req
[i
], lookupsids_cb
, &replies
);
1130 while (replies
>= 0 && replies
< num_async_requests
) {
1131 tevent_loop_once(tctx
->ev
);
1143 static bool test_LookupPrivValue(struct dcerpc_binding_handle
*b
,
1144 struct torture_context
*tctx
,
1145 struct policy_handle
*handle
,
1146 struct lsa_String
*name
)
1148 struct lsa_LookupPrivValue r
;
1149 struct lsa_LUID luid
;
1151 r
.in
.handle
= handle
;
1155 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupPrivValue_r(b
, tctx
, &r
),
1156 "LookupPrivValue failed");
1157 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1158 torture_comment(tctx
, "\nLookupPrivValue failed - %s\n",
1159 nt_errstr(r
.out
.result
));
1166 static bool test_LookupPrivName(struct dcerpc_binding_handle
*b
,
1167 struct torture_context
*tctx
,
1168 struct policy_handle
*handle
,
1169 struct lsa_LUID
*luid
)
1171 struct lsa_LookupPrivName r
;
1172 struct lsa_StringLarge
*name
= NULL
;
1174 r
.in
.handle
= handle
;
1178 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupPrivName_r(b
, tctx
, &r
),
1179 "LookupPrivName failed");
1180 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1181 torture_comment(tctx
, "\nLookupPrivName failed - %s\n",
1182 nt_errstr(r
.out
.result
));
1189 static bool test_RemovePrivilegesFromAccount(struct dcerpc_binding_handle
*b
,
1190 struct torture_context
*tctx
,
1191 struct policy_handle
*handle
,
1192 struct policy_handle
*acct_handle
,
1193 struct lsa_LUID
*luid
)
1195 struct lsa_RemovePrivilegesFromAccount r
;
1196 struct lsa_PrivilegeSet privs
;
1199 torture_comment(tctx
, "\nTesting RemovePrivilegesFromAccount\n");
1201 r
.in
.handle
= acct_handle
;
1202 r
.in
.remove_all
= 0;
1203 r
.in
.privs
= &privs
;
1207 privs
.set
= talloc_array(tctx
, struct lsa_LUIDAttribute
, 1);
1208 privs
.set
[0].luid
= *luid
;
1209 privs
.set
[0].attribute
= 0;
1211 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_RemovePrivilegesFromAccount_r(b
, tctx
, &r
),
1212 "RemovePrivilegesFromAccount failed");
1213 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1215 struct lsa_LookupPrivName r_name
;
1216 struct lsa_StringLarge
*name
= NULL
;
1218 r_name
.in
.handle
= handle
;
1219 r_name
.in
.luid
= luid
;
1220 r_name
.out
.name
= &name
;
1222 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupPrivName_r(b
, tctx
, &r_name
),
1223 "LookupPrivName failed");
1224 if (!NT_STATUS_IS_OK(r_name
.out
.result
)) {
1225 torture_comment(tctx
, "\nLookupPrivName failed - %s\n",
1226 nt_errstr(r_name
.out
.result
));
1229 /* Windows 2008 does not allow this to be removed */
1230 if (strcmp("SeAuditPrivilege", name
->string
) == 0) {
1234 torture_comment(tctx
, "RemovePrivilegesFromAccount failed to remove %s - %s\n",
1236 nt_errstr(r
.out
.result
));
1243 static bool test_AddPrivilegesToAccount(struct dcerpc_binding_handle
*b
,
1244 struct torture_context
*tctx
,
1245 struct policy_handle
*acct_handle
,
1246 struct lsa_LUID
*luid
)
1248 struct lsa_AddPrivilegesToAccount r
;
1249 struct lsa_PrivilegeSet privs
;
1252 torture_comment(tctx
, "\nTesting AddPrivilegesToAccount\n");
1254 r
.in
.handle
= acct_handle
;
1255 r
.in
.privs
= &privs
;
1259 privs
.set
= talloc_array(tctx
, struct lsa_LUIDAttribute
, 1);
1260 privs
.set
[0].luid
= *luid
;
1261 privs
.set
[0].attribute
= 0;
1263 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_AddPrivilegesToAccount_r(b
, tctx
, &r
),
1264 "AddPrivilegesToAccount failed");
1265 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1266 torture_comment(tctx
, "AddPrivilegesToAccount failed - %s\n",
1267 nt_errstr(r
.out
.result
));
1274 static bool test_EnumPrivsAccount(struct dcerpc_binding_handle
*b
,
1275 struct torture_context
*tctx
,
1276 struct policy_handle
*handle
,
1277 struct policy_handle
*acct_handle
)
1279 struct lsa_EnumPrivsAccount r
;
1280 struct lsa_PrivilegeSet
*privs
= NULL
;
1283 torture_comment(tctx
, "\nTesting EnumPrivsAccount\n");
1285 r
.in
.handle
= acct_handle
;
1286 r
.out
.privs
= &privs
;
1288 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumPrivsAccount_r(b
, tctx
, &r
),
1289 "EnumPrivsAccount failed");
1290 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1291 torture_comment(tctx
, "EnumPrivsAccount failed - %s\n",
1292 nt_errstr(r
.out
.result
));
1296 if (privs
&& privs
->count
> 0) {
1298 for (i
=0;i
<privs
->count
;i
++) {
1299 test_LookupPrivName(b
, tctx
, handle
,
1300 &privs
->set
[i
].luid
);
1303 ret
&= test_RemovePrivilegesFromAccount(b
, tctx
, handle
, acct_handle
,
1304 &privs
->set
[0].luid
);
1305 ret
&= test_AddPrivilegesToAccount(b
, tctx
, acct_handle
,
1306 &privs
->set
[0].luid
);
1312 static bool test_GetSystemAccessAccount(struct dcerpc_binding_handle
*b
,
1313 struct torture_context
*tctx
,
1314 struct policy_handle
*handle
,
1315 struct policy_handle
*acct_handle
)
1317 uint32_t access_mask
;
1318 struct lsa_GetSystemAccessAccount r
;
1320 torture_comment(tctx
, "\nTesting GetSystemAccessAccount\n");
1322 r
.in
.handle
= acct_handle
;
1323 r
.out
.access_mask
= &access_mask
;
1325 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_GetSystemAccessAccount_r(b
, tctx
, &r
),
1326 "GetSystemAccessAccount failed");
1327 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1328 torture_comment(tctx
, "GetSystemAccessAccount failed - %s\n",
1329 nt_errstr(r
.out
.result
));
1333 if (r
.out
.access_mask
!= NULL
) {
1334 torture_comment(tctx
, "Rights:");
1335 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_INTERACTIVE
)
1336 torture_comment(tctx
, " LSA_POLICY_MODE_INTERACTIVE");
1337 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_NETWORK
)
1338 torture_comment(tctx
, " LSA_POLICY_MODE_NETWORK");
1339 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_BATCH
)
1340 torture_comment(tctx
, " LSA_POLICY_MODE_BATCH");
1341 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_SERVICE
)
1342 torture_comment(tctx
, " LSA_POLICY_MODE_SERVICE");
1343 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_PROXY
)
1344 torture_comment(tctx
, " LSA_POLICY_MODE_PROXY");
1345 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_INTERACTIVE
)
1346 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_INTERACTIVE");
1347 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_NETWORK
)
1348 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_NETWORK");
1349 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_BATCH
)
1350 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_BATCH");
1351 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_SERVICE
)
1352 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_SERVICE");
1353 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_REMOTE_INTERACTIVE
)
1354 torture_comment(tctx
, " LSA_POLICY_MODE_REMOTE_INTERACTIVE");
1355 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_REMOTE_INTERACTIVE
)
1356 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_REMOTE_INTERACTIVE");
1357 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_ALL
)
1358 torture_comment(tctx
, " LSA_POLICY_MODE_ALL");
1359 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_ALL_NT4
)
1360 torture_comment(tctx
, " LSA_POLICY_MODE_ALL_NT4");
1361 torture_comment(tctx
, "\n");
1367 static bool test_Delete(struct dcerpc_binding_handle
*b
,
1368 struct torture_context
*tctx
,
1369 struct policy_handle
*handle
)
1371 struct lsa_Delete r
;
1373 torture_comment(tctx
, "\nTesting Delete\n");
1375 r
.in
.handle
= handle
;
1376 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_Delete_r(b
, tctx
, &r
),
1378 if (!NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NOT_SUPPORTED
)) {
1379 torture_comment(tctx
, "Delete should have failed NT_STATUS_NOT_SUPPORTED - %s\n", nt_errstr(r
.out
.result
));
1386 static bool test_DeleteObject(struct dcerpc_binding_handle
*b
,
1387 struct torture_context
*tctx
,
1388 struct policy_handle
*handle
)
1390 struct lsa_DeleteObject r
;
1392 torture_comment(tctx
, "\nTesting DeleteObject\n");
1394 r
.in
.handle
= handle
;
1395 r
.out
.handle
= handle
;
1396 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_DeleteObject_r(b
, tctx
, &r
),
1397 "DeleteObject failed");
1398 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1399 torture_comment(tctx
, "DeleteObject failed - %s\n",
1400 nt_errstr(r
.out
.result
));
1408 static bool test_CreateAccount(struct dcerpc_binding_handle
*b
,
1409 struct torture_context
*tctx
,
1410 struct policy_handle
*handle
)
1412 struct lsa_CreateAccount r
;
1413 struct dom_sid2
*newsid
;
1414 struct policy_handle acct_handle
;
1416 newsid
= dom_sid_parse_talloc(tctx
, "S-1-5-12349876-4321-2854");
1418 torture_comment(tctx
, "\nTesting CreateAccount\n");
1420 r
.in
.handle
= handle
;
1422 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1423 r
.out
.acct_handle
= &acct_handle
;
1425 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateAccount_r(b
, tctx
, &r
),
1426 "CreateAccount failed");
1427 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
1428 struct lsa_OpenAccount r_o
;
1429 r_o
.in
.handle
= handle
;
1430 r_o
.in
.sid
= newsid
;
1431 r_o
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1432 r_o
.out
.acct_handle
= &acct_handle
;
1434 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenAccount_r(b
, tctx
, &r_o
),
1435 "OpenAccount failed");
1436 if (!NT_STATUS_IS_OK(r_o
.out
.result
)) {
1437 torture_comment(tctx
, "OpenAccount failed - %s\n",
1438 nt_errstr(r_o
.out
.result
));
1441 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1442 torture_comment(tctx
, "CreateAccount failed - %s\n",
1443 nt_errstr(r
.out
.result
));
1447 if (!test_Delete(b
, tctx
, &acct_handle
)) {
1451 if (!test_DeleteObject(b
, tctx
, &acct_handle
)) {
1458 static bool test_DeleteTrustedDomain(struct dcerpc_binding_handle
*b
,
1459 struct torture_context
*tctx
,
1460 struct policy_handle
*handle
,
1461 struct lsa_StringLarge name
)
1463 struct lsa_OpenTrustedDomainByName r
;
1464 struct policy_handle trustdom_handle
;
1466 r
.in
.handle
= handle
;
1467 r
.in
.name
.string
= name
.string
;
1468 r
.in
.access_mask
= SEC_STD_DELETE
;
1469 r
.out
.trustdom_handle
= &trustdom_handle
;
1471 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenTrustedDomainByName_r(b
, tctx
, &r
),
1472 "OpenTrustedDomainByName failed");
1473 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1474 torture_comment(tctx
, "OpenTrustedDomainByName failed - %s\n", nt_errstr(r
.out
.result
));
1478 if (!test_Delete(b
, tctx
, &trustdom_handle
)) {
1482 if (!test_DeleteObject(b
, tctx
, &trustdom_handle
)) {
1489 static bool test_DeleteTrustedDomainBySid(struct dcerpc_binding_handle
*b
,
1490 struct torture_context
*tctx
,
1491 struct policy_handle
*handle
,
1492 struct dom_sid
*sid
)
1494 struct lsa_DeleteTrustedDomain r
;
1496 r
.in
.handle
= handle
;
1499 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_DeleteTrustedDomain_r(b
, tctx
, &r
),
1500 "DeleteTrustedDomain failed");
1501 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1502 torture_comment(tctx
, "DeleteTrustedDomain failed - %s\n", nt_errstr(r
.out
.result
));
1510 static bool test_CreateSecret(struct dcerpc_pipe
*p
,
1511 struct torture_context
*tctx
,
1512 struct policy_handle
*handle
)
1515 struct lsa_CreateSecret r
;
1516 struct lsa_OpenSecret r2
;
1517 struct lsa_SetSecret r3
;
1518 struct lsa_QuerySecret r4
;
1519 struct lsa_SetSecret r5
;
1520 struct lsa_QuerySecret r6
;
1521 struct lsa_SetSecret r7
;
1522 struct lsa_QuerySecret r8
;
1523 struct policy_handle sec_handle
, sec_handle2
, sec_handle3
;
1524 struct lsa_DeleteObject d_o
;
1525 struct lsa_DATA_BUF buf1
;
1526 struct lsa_DATA_BUF_PTR bufp1
;
1527 struct lsa_DATA_BUF_PTR bufp2
;
1530 DATA_BLOB session_key
;
1531 NTTIME old_mtime
, new_mtime
;
1533 const char *secret1
= "abcdef12345699qwerty";
1535 const char *secret3
= "ABCDEF12345699QWERTY";
1537 const char *secret5
= "NEW-SAMBA4-SECRET";
1541 const int LOCAL
= 0;
1542 const int GLOBAL
= 1;
1543 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
1545 secname
[LOCAL
] = talloc_asprintf(tctx
, "torturesecret-%u", (unsigned int)random());
1546 secname
[GLOBAL
] = talloc_asprintf(tctx
, "G$torturesecret-%u", (unsigned int)random());
1548 for (i
=0; i
< 2; i
++) {
1549 torture_comment(tctx
, "\nTesting CreateSecret of %s\n", secname
[i
]);
1551 init_lsa_String(&r
.in
.name
, secname
[i
]);
1553 r
.in
.handle
= handle
;
1554 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1555 r
.out
.sec_handle
= &sec_handle
;
1557 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateSecret_r(b
, tctx
, &r
),
1558 "CreateSecret failed");
1559 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1560 torture_comment(tctx
, "CreateSecret failed - %s\n", nt_errstr(r
.out
.result
));
1564 r
.in
.handle
= handle
;
1565 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1566 r
.out
.sec_handle
= &sec_handle3
;
1568 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateSecret_r(b
, tctx
, &r
),
1569 "CreateSecret failed");
1570 if (!NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
1571 torture_comment(tctx
, "CreateSecret should have failed OBJECT_NAME_COLLISION - %s\n", nt_errstr(r
.out
.result
));
1575 r2
.in
.handle
= handle
;
1576 r2
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1577 r2
.in
.name
= r
.in
.name
;
1578 r2
.out
.sec_handle
= &sec_handle2
;
1580 torture_comment(tctx
, "Testing OpenSecret\n");
1582 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenSecret_r(b
, tctx
, &r2
),
1583 "OpenSecret failed");
1584 if (!NT_STATUS_IS_OK(r2
.out
.result
)) {
1585 torture_comment(tctx
, "OpenSecret failed - %s\n", nt_errstr(r2
.out
.result
));
1589 status
= dcerpc_fetch_session_key(p
, &session_key
);
1590 if (!NT_STATUS_IS_OK(status
)) {
1591 torture_comment(tctx
, "dcerpc_fetch_session_key failed - %s\n", nt_errstr(status
));
1595 enc_key
= sess_encrypt_string(secret1
, &session_key
);
1597 r3
.in
.sec_handle
= &sec_handle
;
1598 r3
.in
.new_val
= &buf1
;
1599 r3
.in
.old_val
= NULL
;
1600 r3
.in
.new_val
->data
= enc_key
.data
;
1601 r3
.in
.new_val
->length
= enc_key
.length
;
1602 r3
.in
.new_val
->size
= enc_key
.length
;
1604 torture_comment(tctx
, "Testing SetSecret\n");
1606 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_SetSecret_r(b
, tctx
, &r3
),
1607 "SetSecret failed");
1608 if (!NT_STATUS_IS_OK(r3
.out
.result
)) {
1609 torture_comment(tctx
, "SetSecret failed - %s\n", nt_errstr(r3
.out
.result
));
1613 r3
.in
.sec_handle
= &sec_handle
;
1614 r3
.in
.new_val
= &buf1
;
1615 r3
.in
.old_val
= NULL
;
1616 r3
.in
.new_val
->data
= enc_key
.data
;
1617 r3
.in
.new_val
->length
= enc_key
.length
;
1618 r3
.in
.new_val
->size
= enc_key
.length
;
1620 /* break the encrypted data */
1623 torture_comment(tctx
, "Testing SetSecret with broken key\n");
1625 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_SetSecret_r(b
, tctx
, &r3
),
1626 "SetSecret failed");
1627 if (!NT_STATUS_EQUAL(r3
.out
.result
, NT_STATUS_UNKNOWN_REVISION
)) {
1628 torture_comment(tctx
, "SetSecret should have failed UNKNOWN_REVISION - %s\n", nt_errstr(r3
.out
.result
));
1632 data_blob_free(&enc_key
);
1634 ZERO_STRUCT(new_mtime
);
1635 ZERO_STRUCT(old_mtime
);
1637 /* fetch the secret back again */
1638 r4
.in
.sec_handle
= &sec_handle
;
1639 r4
.in
.new_val
= &bufp1
;
1640 r4
.in
.new_mtime
= &new_mtime
;
1641 r4
.in
.old_val
= NULL
;
1642 r4
.in
.old_mtime
= NULL
;
1646 torture_comment(tctx
, "Testing QuerySecret\n");
1647 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QuerySecret_r(b
, tctx
, &r4
),
1648 "QuerySecret failed");
1649 if (!NT_STATUS_IS_OK(r4
.out
.result
)) {
1650 torture_comment(tctx
, "QuerySecret failed - %s\n", nt_errstr(r4
.out
.result
));
1653 if (r4
.out
.new_val
== NULL
|| r4
.out
.new_val
->buf
== NULL
) {
1654 torture_comment(tctx
, "No secret buffer returned\n");
1657 blob1
.data
= r4
.out
.new_val
->buf
->data
;
1658 blob1
.length
= r4
.out
.new_val
->buf
->size
;
1660 secret2
= sess_decrypt_string(tctx
,
1661 &blob1
, &session_key
);
1663 if (strcmp(secret1
, secret2
) != 0) {
1664 torture_comment(tctx
, "Returned secret (r4) '%s' doesn't match '%s'\n",
1671 enc_key
= sess_encrypt_string(secret3
, &session_key
);
1673 r5
.in
.sec_handle
= &sec_handle
;
1674 r5
.in
.new_val
= &buf1
;
1675 r5
.in
.old_val
= NULL
;
1676 r5
.in
.new_val
->data
= enc_key
.data
;
1677 r5
.in
.new_val
->length
= enc_key
.length
;
1678 r5
.in
.new_val
->size
= enc_key
.length
;
1682 torture_comment(tctx
, "Testing SetSecret (existing value should move to old)\n");
1684 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_SetSecret_r(b
, tctx
, &r5
),
1685 "SetSecret failed");
1686 if (!NT_STATUS_IS_OK(r5
.out
.result
)) {
1687 torture_comment(tctx
, "SetSecret failed - %s\n", nt_errstr(r5
.out
.result
));
1691 data_blob_free(&enc_key
);
1693 ZERO_STRUCT(new_mtime
);
1694 ZERO_STRUCT(old_mtime
);
1696 /* fetch the secret back again */
1697 r6
.in
.sec_handle
= &sec_handle
;
1698 r6
.in
.new_val
= &bufp1
;
1699 r6
.in
.new_mtime
= &new_mtime
;
1700 r6
.in
.old_val
= &bufp2
;
1701 r6
.in
.old_mtime
= &old_mtime
;
1706 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QuerySecret_r(b
, tctx
, &r6
),
1707 "QuerySecret failed");
1708 if (!NT_STATUS_IS_OK(r6
.out
.result
)) {
1709 torture_comment(tctx
, "QuerySecret failed - %s\n", nt_errstr(r6
.out
.result
));
1714 if (r6
.out
.new_val
->buf
== NULL
|| r6
.out
.old_val
->buf
== NULL
1715 || r6
.out
.new_mtime
== NULL
|| r6
.out
.old_mtime
== NULL
) {
1716 torture_comment(tctx
, "Both secret buffers and both times not returned\n");
1720 blob1
.data
= r6
.out
.new_val
->buf
->data
;
1721 blob1
.length
= r6
.out
.new_val
->buf
->size
;
1723 secret4
= sess_decrypt_string(tctx
,
1724 &blob1
, &session_key
);
1726 if (strcmp(secret3
, secret4
) != 0) {
1727 torture_comment(tctx
, "Returned NEW secret %s doesn't match %s\n", secret4
, secret3
);
1731 blob1
.data
= r6
.out
.old_val
->buf
->data
;
1732 blob1
.length
= r6
.out
.old_val
->buf
->length
;
1734 secret2
= sess_decrypt_string(tctx
,
1735 &blob1
, &session_key
);
1737 if (strcmp(secret1
, secret2
) != 0) {
1738 torture_comment(tctx
, "Returned OLD secret %s doesn't match %s\n", secret2
, secret1
);
1742 if (*r6
.out
.new_mtime
== *r6
.out
.old_mtime
) {
1743 torture_comment(tctx
, "Returned secret (r6-%d) %s must not have same mtime for both secrets: %s != %s\n",
1746 nt_time_string(tctx
, *r6
.out
.old_mtime
),
1747 nt_time_string(tctx
, *r6
.out
.new_mtime
));
1753 enc_key
= sess_encrypt_string(secret5
, &session_key
);
1755 r7
.in
.sec_handle
= &sec_handle
;
1756 r7
.in
.old_val
= &buf1
;
1757 r7
.in
.old_val
->data
= enc_key
.data
;
1758 r7
.in
.old_val
->length
= enc_key
.length
;
1759 r7
.in
.old_val
->size
= enc_key
.length
;
1760 r7
.in
.new_val
= NULL
;
1762 torture_comment(tctx
, "Testing SetSecret of old Secret only\n");
1764 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_SetSecret_r(b
, tctx
, &r7
),
1765 "SetSecret failed");
1766 if (!NT_STATUS_IS_OK(r7
.out
.result
)) {
1767 torture_comment(tctx
, "SetSecret failed - %s\n", nt_errstr(r7
.out
.result
));
1771 data_blob_free(&enc_key
);
1773 /* fetch the secret back again */
1774 r8
.in
.sec_handle
= &sec_handle
;
1775 r8
.in
.new_val
= &bufp1
;
1776 r8
.in
.new_mtime
= &new_mtime
;
1777 r8
.in
.old_val
= &bufp2
;
1778 r8
.in
.old_mtime
= &old_mtime
;
1783 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QuerySecret_r(b
, tctx
, &r8
),
1784 "QuerySecret failed");
1785 if (!NT_STATUS_IS_OK(r8
.out
.result
)) {
1786 torture_comment(tctx
, "QuerySecret failed - %s\n", nt_errstr(r8
.out
.result
));
1789 if (!r8
.out
.new_val
|| !r8
.out
.old_val
) {
1790 torture_comment(tctx
, "in/out pointers not returned, despite being set on in for QuerySecret\n");
1792 } else if (r8
.out
.new_val
->buf
!= NULL
) {
1793 torture_comment(tctx
, "NEW secret buffer must not be returned after OLD set\n");
1795 } else if (r8
.out
.old_val
->buf
== NULL
) {
1796 torture_comment(tctx
, "OLD secret buffer was not returned after OLD set\n");
1798 } else if (r8
.out
.new_mtime
== NULL
|| r8
.out
.old_mtime
== NULL
) {
1799 torture_comment(tctx
, "Both times not returned after OLD set\n");
1802 blob1
.data
= r8
.out
.old_val
->buf
->data
;
1803 blob1
.length
= r8
.out
.old_val
->buf
->size
;
1805 secret6
= sess_decrypt_string(tctx
,
1806 &blob1
, &session_key
);
1808 if (strcmp(secret5
, secret6
) != 0) {
1809 torture_comment(tctx
, "Returned OLD secret %s doesn't match %s\n", secret5
, secret6
);
1813 if (*r8
.out
.new_mtime
!= *r8
.out
.old_mtime
) {
1814 torture_comment(tctx
, "Returned secret (r8) %s did not had same mtime for both secrets: %s != %s\n",
1816 nt_time_string(tctx
, *r8
.out
.old_mtime
),
1817 nt_time_string(tctx
, *r8
.out
.new_mtime
));
1823 if (!test_Delete(b
, tctx
, &sec_handle
)) {
1827 if (!test_DeleteObject(b
, tctx
, &sec_handle
)) {
1831 d_o
.in
.handle
= &sec_handle2
;
1832 d_o
.out
.handle
= &sec_handle2
;
1833 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_DeleteObject_r(b
, tctx
, &d_o
),
1834 "DeleteObject failed");
1835 if (!NT_STATUS_EQUAL(d_o
.out
.result
, NT_STATUS_INVALID_HANDLE
)) {
1836 torture_comment(tctx
, "Second delete expected INVALID_HANDLE - %s\n", nt_errstr(d_o
.out
.result
));
1840 torture_comment(tctx
, "Testing OpenSecret of just-deleted secret\n");
1842 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenSecret_r(b
, tctx
, &r2
),
1843 "OpenSecret failed");
1844 if (!NT_STATUS_EQUAL(r2
.out
.result
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
1845 torture_comment(tctx
, "OpenSecret expected OBJECT_NAME_NOT_FOUND - %s\n", nt_errstr(r2
.out
.result
));
1856 static bool test_EnumAccountRights(struct dcerpc_binding_handle
*b
,
1857 struct torture_context
*tctx
,
1858 struct policy_handle
*acct_handle
,
1859 struct dom_sid
*sid
)
1861 struct lsa_EnumAccountRights r
;
1862 struct lsa_RightSet rights
;
1864 torture_comment(tctx
, "\nTesting EnumAccountRights\n");
1866 r
.in
.handle
= acct_handle
;
1868 r
.out
.rights
= &rights
;
1870 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumAccountRights_r(b
, tctx
, &r
),
1871 "EnumAccountRights failed");
1872 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1873 torture_comment(tctx
, "EnumAccountRights of %s failed - %s\n",
1874 dom_sid_string(tctx
, sid
), nt_errstr(r
.out
.result
));
1882 static bool test_QuerySecurity(struct dcerpc_binding_handle
*b
,
1883 struct torture_context
*tctx
,
1884 struct policy_handle
*handle
,
1885 struct policy_handle
*acct_handle
)
1887 struct lsa_QuerySecurity r
;
1888 struct sec_desc_buf
*sdbuf
= NULL
;
1890 if (torture_setting_bool(tctx
, "samba4", false)) {
1891 torture_comment(tctx
, "\nskipping QuerySecurity test against Samba4\n");
1895 torture_comment(tctx
, "\nTesting QuerySecurity\n");
1897 r
.in
.handle
= acct_handle
;
1898 r
.in
.sec_info
= SECINFO_OWNER
|
1901 r
.out
.sdbuf
= &sdbuf
;
1903 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QuerySecurity_r(b
, tctx
, &r
),
1904 "QuerySecurity failed");
1905 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1906 torture_comment(tctx
, "QuerySecurity failed - %s\n", nt_errstr(r
.out
.result
));
1913 static bool test_OpenAccount(struct dcerpc_binding_handle
*b
,
1914 struct torture_context
*tctx
,
1915 struct policy_handle
*handle
,
1916 struct dom_sid
*sid
)
1918 struct lsa_OpenAccount r
;
1919 struct policy_handle acct_handle
;
1921 torture_comment(tctx
, "\nTesting OpenAccount\n");
1923 r
.in
.handle
= handle
;
1925 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1926 r
.out
.acct_handle
= &acct_handle
;
1928 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenAccount_r(b
, tctx
, &r
),
1929 "OpenAccount failed");
1930 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1931 torture_comment(tctx
, "OpenAccount failed - %s\n", nt_errstr(r
.out
.result
));
1935 if (!test_EnumPrivsAccount(b
, tctx
, handle
, &acct_handle
)) {
1939 if (!test_GetSystemAccessAccount(b
, tctx
, handle
, &acct_handle
)) {
1943 if (!test_QuerySecurity(b
, tctx
, handle
, &acct_handle
)) {
1950 static bool test_EnumAccounts(struct dcerpc_binding_handle
*b
,
1951 struct torture_context
*tctx
,
1952 struct policy_handle
*handle
)
1954 struct lsa_EnumAccounts r
;
1955 struct lsa_SidArray sids1
, sids2
;
1956 uint32_t resume_handle
= 0;
1960 torture_comment(tctx
, "\nTesting EnumAccounts\n");
1962 r
.in
.handle
= handle
;
1963 r
.in
.resume_handle
= &resume_handle
;
1964 r
.in
.num_entries
= 100;
1965 r
.out
.resume_handle
= &resume_handle
;
1966 r
.out
.sids
= &sids1
;
1970 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumAccounts_r(b
, tctx
, &r
),
1971 "EnumAccounts failed");
1972 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
)) {
1975 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1976 torture_comment(tctx
, "EnumAccounts failed - %s\n", nt_errstr(r
.out
.result
));
1980 if (!test_LookupSids(b
, tctx
, handle
, &sids1
)) {
1984 if (!test_LookupSids2(b
, tctx
, handle
, &sids1
)) {
1988 /* Can't test lookupSids3 here, as clearly we must not
1989 * be on schannel, or we would not be able to do the
1992 torture_comment(tctx
, "Testing all accounts\n");
1993 for (i
=0;i
<sids1
.num_sids
;i
++) {
1994 ret
&= test_OpenAccount(b
, tctx
, handle
, sids1
.sids
[i
].sid
);
1995 ret
&= test_EnumAccountRights(b
, tctx
, handle
, sids1
.sids
[i
].sid
);
1997 torture_comment(tctx
, "\n");
2000 if (sids1
.num_sids
< 3) {
2004 torture_comment(tctx
, "Trying EnumAccounts partial listing (asking for 1 at 2)\n");
2006 r
.in
.num_entries
= 1;
2007 r
.out
.sids
= &sids2
;
2009 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumAccounts_r(b
, tctx
, &r
),
2010 "EnumAccounts failed");
2011 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2012 torture_comment(tctx
, "EnumAccounts failed - %s\n", nt_errstr(r
.out
.result
));
2016 if (sids2
.num_sids
!= 1) {
2017 torture_comment(tctx
, "Returned wrong number of entries (%d)\n", sids2
.num_sids
);
2024 static bool test_LookupPrivDisplayName(struct dcerpc_binding_handle
*b
,
2025 struct torture_context
*tctx
,
2026 struct policy_handle
*handle
,
2027 struct lsa_String
*priv_name
)
2029 struct lsa_LookupPrivDisplayName r
;
2030 /* produce a reasonable range of language output without screwing up
2032 uint16_t language_id
= (random() % 4) + 0x409;
2033 uint16_t returned_language_id
= 0;
2034 struct lsa_StringLarge
*disp_name
= NULL
;
2036 torture_comment(tctx
, "\nTesting LookupPrivDisplayName(%s)\n", priv_name
->string
);
2038 r
.in
.handle
= handle
;
2039 r
.in
.name
= priv_name
;
2040 r
.in
.language_id
= language_id
;
2041 r
.in
.language_id_sys
= 0;
2042 r
.out
.returned_language_id
= &returned_language_id
;
2043 r
.out
.disp_name
= &disp_name
;
2045 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupPrivDisplayName_r(b
, tctx
, &r
),
2046 "LookupPrivDisplayName failed");
2047 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2048 torture_comment(tctx
, "LookupPrivDisplayName failed - %s\n", nt_errstr(r
.out
.result
));
2051 torture_comment(tctx
, "%s -> \"%s\" (language 0x%x/0x%x)\n",
2052 priv_name
->string
, disp_name
->string
,
2053 r
.in
.language_id
, *r
.out
.returned_language_id
);
2058 static bool test_EnumAccountsWithUserRight(struct dcerpc_binding_handle
*b
,
2059 struct torture_context
*tctx
,
2060 struct policy_handle
*handle
,
2061 struct lsa_String
*priv_name
)
2063 struct lsa_EnumAccountsWithUserRight r
;
2064 struct lsa_SidArray sids
;
2068 torture_comment(tctx
, "\nTesting EnumAccountsWithUserRight(%s)\n", priv_name
->string
);
2070 r
.in
.handle
= handle
;
2071 r
.in
.name
= priv_name
;
2074 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumAccountsWithUserRight_r(b
, tctx
, &r
),
2075 "EnumAccountsWithUserRight failed");
2077 /* NT_STATUS_NO_MORE_ENTRIES means noone has this privilege */
2078 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
)) {
2082 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2083 torture_comment(tctx
, "EnumAccountsWithUserRight failed - %s\n", nt_errstr(r
.out
.result
));
2091 static bool test_EnumPrivs(struct dcerpc_binding_handle
*b
,
2092 struct torture_context
*tctx
,
2093 struct policy_handle
*handle
)
2095 struct lsa_EnumPrivs r
;
2096 struct lsa_PrivArray privs1
;
2097 uint32_t resume_handle
= 0;
2101 torture_comment(tctx
, "\nTesting EnumPrivs\n");
2103 r
.in
.handle
= handle
;
2104 r
.in
.resume_handle
= &resume_handle
;
2105 r
.in
.max_count
= 100;
2106 r
.out
.resume_handle
= &resume_handle
;
2107 r
.out
.privs
= &privs1
;
2110 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumPrivs_r(b
, tctx
, &r
),
2111 "EnumPrivs failed");
2112 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2113 torture_comment(tctx
, "EnumPrivs failed - %s\n", nt_errstr(r
.out
.result
));
2117 for (i
= 0; i
< privs1
.count
; i
++) {
2118 test_LookupPrivDisplayName(b
, tctx
, handle
, (struct lsa_String
*)&privs1
.privs
[i
].name
);
2119 test_LookupPrivValue(b
, tctx
, handle
, (struct lsa_String
*)&privs1
.privs
[i
].name
);
2120 if (!test_EnumAccountsWithUserRight(b
, tctx
, handle
, (struct lsa_String
*)&privs1
.privs
[i
].name
)) {
2128 static bool test_QueryForestTrustInformation(struct dcerpc_binding_handle
*b
,
2129 struct torture_context
*tctx
,
2130 struct policy_handle
*handle
,
2131 const char *trusted_domain_name
)
2134 struct lsa_lsaRQueryForestTrustInformation r
;
2135 struct lsa_String string
;
2136 struct lsa_ForestTrustInformation info
, *info_ptr
;
2138 torture_comment(tctx
, "\nTesting lsaRQueryForestTrustInformation\n");
2140 if (torture_setting_bool(tctx
, "samba4", false)) {
2141 torture_comment(tctx
, "skipping QueryForestTrustInformation against Samba4\n");
2145 ZERO_STRUCT(string
);
2147 if (trusted_domain_name
) {
2148 init_lsa_String(&string
, trusted_domain_name
);
2153 r
.in
.handle
= handle
;
2154 r
.in
.trusted_domain_name
= &string
;
2156 r
.out
.forest_trust_info
= &info_ptr
;
2158 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_lsaRQueryForestTrustInformation_r(b
, tctx
, &r
),
2159 "lsaRQueryForestTrustInformation failed");
2161 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2162 torture_comment(tctx
, "lsaRQueryForestTrustInformation of %s failed - %s\n", trusted_domain_name
, nt_errstr(r
.out
.result
));
2169 static bool test_query_each_TrustDomEx(struct dcerpc_binding_handle
*b
,
2170 struct torture_context
*tctx
,
2171 struct policy_handle
*handle
,
2172 struct lsa_DomainListEx
*domains
)
2177 for (i
=0; i
< domains
->count
; i
++) {
2179 if (domains
->domains
[i
].trust_attributes
& NETR_TRUST_ATTRIBUTE_FOREST_TRANSITIVE
) {
2180 ret
&= test_QueryForestTrustInformation(b
, tctx
, handle
,
2181 domains
->domains
[i
].domain_name
.string
);
2188 static bool test_query_each_TrustDom(struct dcerpc_binding_handle
*b
,
2189 struct torture_context
*tctx
,
2190 struct policy_handle
*handle
,
2191 struct lsa_DomainList
*domains
)
2196 torture_comment(tctx
, "\nTesting OpenTrustedDomain, OpenTrustedDomainByName and QueryInfoTrustedDomain\n");
2197 for (i
=0; i
< domains
->count
; i
++) {
2198 struct lsa_OpenTrustedDomain trust
;
2199 struct lsa_OpenTrustedDomainByName trust_by_name
;
2200 struct policy_handle trustdom_handle
;
2201 struct policy_handle handle2
;
2203 struct lsa_CloseTrustedDomainEx c_trust
;
2204 int levels
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
2205 int ok
[] = {1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1};
2207 if (domains
->domains
[i
].sid
) {
2208 trust
.in
.handle
= handle
;
2209 trust
.in
.sid
= domains
->domains
[i
].sid
;
2210 trust
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2211 trust
.out
.trustdom_handle
= &trustdom_handle
;
2213 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenTrustedDomain_r(b
, tctx
, &trust
),
2214 "OpenTrustedDomain failed");
2216 if (!NT_STATUS_IS_OK(trust
.out
.result
)) {
2217 torture_comment(tctx
, "OpenTrustedDomain failed - %s\n", nt_errstr(trust
.out
.result
));
2221 c
.in
.handle
= &trustdom_handle
;
2222 c
.out
.handle
= &handle2
;
2224 c_trust
.in
.handle
= &trustdom_handle
;
2225 c_trust
.out
.handle
= &handle2
;
2227 for (j
=0; j
< ARRAY_SIZE(levels
); j
++) {
2228 struct lsa_QueryTrustedDomainInfo q
;
2229 union lsa_TrustedDomainInfo
*info
= NULL
;
2230 q
.in
.trustdom_handle
= &trustdom_handle
;
2231 q
.in
.level
= levels
[j
];
2233 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfo_r(b
, tctx
, &q
),
2234 "QueryTrustedDomainInfo failed");
2235 if (!NT_STATUS_IS_OK(q
.out
.result
) && ok
[j
]) {
2236 torture_comment(tctx
, "QueryTrustedDomainInfo level %d failed - %s\n",
2237 levels
[j
], nt_errstr(q
.out
.result
));
2239 } else if (NT_STATUS_IS_OK(q
.out
.result
) && !ok
[j
]) {
2240 torture_comment(tctx
, "QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
2241 levels
[j
], nt_errstr(q
.out
.result
));
2246 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CloseTrustedDomainEx_r(b
, tctx
, &c_trust
),
2247 "CloseTrustedDomainEx failed");
2248 if (!NT_STATUS_EQUAL(c_trust
.out
.result
, NT_STATUS_NOT_IMPLEMENTED
)) {
2249 torture_comment(tctx
, "Expected CloseTrustedDomainEx to return NT_STATUS_NOT_IMPLEMENTED, instead - %s\n", nt_errstr(c_trust
.out
.result
));
2253 c
.in
.handle
= &trustdom_handle
;
2254 c
.out
.handle
= &handle2
;
2256 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_Close_r(b
, tctx
, &c
),
2258 if (!NT_STATUS_IS_OK(c
.out
.result
)) {
2259 torture_comment(tctx
, "Close of trusted domain failed - %s\n", nt_errstr(c
.out
.result
));
2263 for (j
=0; j
< ARRAY_SIZE(levels
); j
++) {
2264 struct lsa_QueryTrustedDomainInfoBySid q
;
2265 union lsa_TrustedDomainInfo
*info
= NULL
;
2267 if (!domains
->domains
[i
].sid
) {
2271 q
.in
.handle
= handle
;
2272 q
.in
.dom_sid
= domains
->domains
[i
].sid
;
2273 q
.in
.level
= levels
[j
];
2276 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfoBySid_r(b
, tctx
, &q
),
2277 "lsa_QueryTrustedDomainInfoBySid failed");
2278 if (!NT_STATUS_IS_OK(q
.out
.result
) && ok
[j
]) {
2279 torture_comment(tctx
, "QueryTrustedDomainInfoBySid level %d failed - %s\n",
2280 levels
[j
], nt_errstr(q
.out
.result
));
2282 } else if (NT_STATUS_IS_OK(q
.out
.result
) && !ok
[j
]) {
2283 torture_comment(tctx
, "QueryTrustedDomainInfoBySid level %d unexpectedly succeeded - %s\n",
2284 levels
[j
], nt_errstr(q
.out
.result
));
2290 trust_by_name
.in
.handle
= handle
;
2291 trust_by_name
.in
.name
.string
= domains
->domains
[i
].name
.string
;
2292 trust_by_name
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2293 trust_by_name
.out
.trustdom_handle
= &trustdom_handle
;
2295 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenTrustedDomainByName_r(b
, tctx
, &trust_by_name
),
2296 "OpenTrustedDomainByName failed");
2298 if (!NT_STATUS_IS_OK(trust_by_name
.out
.result
)) {
2299 torture_comment(tctx
, "OpenTrustedDomainByName failed - %s\n", nt_errstr(trust_by_name
.out
.result
));
2303 for (j
=0; j
< ARRAY_SIZE(levels
); j
++) {
2304 struct lsa_QueryTrustedDomainInfo q
;
2305 union lsa_TrustedDomainInfo
*info
= NULL
;
2306 q
.in
.trustdom_handle
= &trustdom_handle
;
2307 q
.in
.level
= levels
[j
];
2309 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfo_r(b
, tctx
, &q
),
2310 "QueryTrustedDomainInfo failed");
2311 if (!NT_STATUS_IS_OK(q
.out
.result
) && ok
[j
]) {
2312 torture_comment(tctx
, "QueryTrustedDomainInfo level %d failed - %s\n",
2313 levels
[j
], nt_errstr(q
.out
.result
));
2315 } else if (NT_STATUS_IS_OK(q
.out
.result
) && !ok
[j
]) {
2316 torture_comment(tctx
, "QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
2317 levels
[j
], nt_errstr(q
.out
.result
));
2322 c
.in
.handle
= &trustdom_handle
;
2323 c
.out
.handle
= &handle2
;
2325 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_Close_r(b
, tctx
, &c
),
2327 if (!NT_STATUS_IS_OK(c
.out
.result
)) {
2328 torture_comment(tctx
, "Close of trusted domain failed - %s\n", nt_errstr(c
.out
.result
));
2332 for (j
=0; j
< ARRAY_SIZE(levels
); j
++) {
2333 struct lsa_QueryTrustedDomainInfoByName q
;
2334 union lsa_TrustedDomainInfo
*info
= NULL
;
2335 struct lsa_String name
;
2337 name
.string
= domains
->domains
[i
].name
.string
;
2339 q
.in
.handle
= handle
;
2340 q
.in
.trusted_domain
= &name
;
2341 q
.in
.level
= levels
[j
];
2343 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfoByName_r(b
, tctx
, &q
),
2344 "QueryTrustedDomainInfoByName failed");
2345 if (!NT_STATUS_IS_OK(q
.out
.result
) && ok
[j
]) {
2346 torture_comment(tctx
, "QueryTrustedDomainInfoByName level %d failed - %s\n",
2347 levels
[j
], nt_errstr(q
.out
.result
));
2349 } else if (NT_STATUS_IS_OK(q
.out
.result
) && !ok
[j
]) {
2350 torture_comment(tctx
, "QueryTrustedDomainInfoByName level %d unexpectedly succeeded - %s\n",
2351 levels
[j
], nt_errstr(q
.out
.result
));
2359 static bool test_EnumTrustDom(struct dcerpc_binding_handle
*b
,
2360 struct torture_context
*tctx
,
2361 struct policy_handle
*handle
)
2363 struct lsa_EnumTrustDom r
;
2364 uint32_t in_resume_handle
= 0;
2365 uint32_t out_resume_handle
;
2366 struct lsa_DomainList domains
;
2369 torture_comment(tctx
, "\nTesting EnumTrustDom\n");
2371 r
.in
.handle
= handle
;
2372 r
.in
.resume_handle
= &in_resume_handle
;
2374 r
.out
.domains
= &domains
;
2375 r
.out
.resume_handle
= &out_resume_handle
;
2377 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumTrustDom_r(b
, tctx
, &r
),
2378 "lsa_EnumTrustDom failed");
2380 /* according to MS-LSAD 3.1.4.7.8 output resume handle MUST
2381 * always be larger than the previous input resume handle, in
2382 * particular when hitting the last query it is vital to set the
2383 * resume handle correctly to avoid infinite client loops, as
2384 * seen e.g. with Windows XP SP3 when resume handle is 0 and
2385 * status is NT_STATUS_OK - gd */
2387 if (NT_STATUS_IS_OK(r
.out
.result
) ||
2388 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
) ||
2389 NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
))
2391 if (out_resume_handle
<= in_resume_handle
) {
2392 torture_comment(tctx
, "EnumTrustDom failed - should have returned output resume_handle (0x%08x) larger than input resume handle (0x%08x)\n",
2393 out_resume_handle
, in_resume_handle
);
2398 if (NT_STATUS_IS_OK(r
.out
.result
)) {
2399 if (domains
.count
== 0) {
2400 torture_comment(tctx
, "EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2403 } else if (!(NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
) || NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
))) {
2404 torture_comment(tctx
, "EnumTrustDom of zero size failed - %s\n", nt_errstr(r
.out
.result
));
2408 /* Start from the bottom again */
2409 in_resume_handle
= 0;
2412 r
.in
.handle
= handle
;
2413 r
.in
.resume_handle
= &in_resume_handle
;
2414 r
.in
.max_size
= LSA_ENUM_TRUST_DOMAIN_MULTIPLIER
* 3;
2415 r
.out
.domains
= &domains
;
2416 r
.out
.resume_handle
= &out_resume_handle
;
2418 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumTrustDom_r(b
, tctx
, &r
),
2419 "EnumTrustDom failed");
2421 /* according to MS-LSAD 3.1.4.7.8 output resume handle MUST
2422 * always be larger than the previous input resume handle, in
2423 * particular when hitting the last query it is vital to set the
2424 * resume handle correctly to avoid infinite client loops, as
2425 * seen e.g. with Windows XP SP3 when resume handle is 0 and
2426 * status is NT_STATUS_OK - gd */
2428 if (NT_STATUS_IS_OK(r
.out
.result
) ||
2429 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
) ||
2430 NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
))
2432 if (out_resume_handle
<= in_resume_handle
) {
2433 torture_comment(tctx
, "EnumTrustDom failed - should have returned output resume_handle (0x%08x) larger than input resume handle (0x%08x)\n",
2434 out_resume_handle
, in_resume_handle
);
2439 /* NO_MORE_ENTRIES is allowed */
2440 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
)) {
2441 if (domains
.count
== 0) {
2444 torture_comment(tctx
, "EnumTrustDom failed - should have returned 0 trusted domains with 'NT_STATUS_NO_MORE_ENTRIES'\n");
2446 } else if (NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
)) {
2447 /* Windows 2003 gets this off by one on the first run */
2448 if (r
.out
.domains
->count
< 3 || r
.out
.domains
->count
> 4) {
2449 torture_comment(tctx
, "EnumTrustDom didn't fill the buffer we "
2450 "asked it to (got %d, expected %d / %d == %d entries)\n",
2451 r
.out
.domains
->count
, LSA_ENUM_TRUST_DOMAIN_MULTIPLIER
* 3,
2452 LSA_ENUM_TRUST_DOMAIN_MULTIPLIER
, r
.in
.max_size
);
2455 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2456 torture_comment(tctx
, "EnumTrustDom failed - %s\n", nt_errstr(r
.out
.result
));
2460 if (domains
.count
== 0) {
2461 torture_comment(tctx
, "EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2465 ret
&= test_query_each_TrustDom(b
, tctx
, handle
, &domains
);
2467 in_resume_handle
= out_resume_handle
;
2469 } while ((NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
)));
2474 static bool test_EnumTrustDomEx(struct dcerpc_binding_handle
*b
,
2475 struct torture_context
*tctx
,
2476 struct policy_handle
*handle
)
2478 struct lsa_EnumTrustedDomainsEx r_ex
;
2479 uint32_t resume_handle
= 0;
2480 struct lsa_DomainListEx domains_ex
;
2483 torture_comment(tctx
, "\nTesting EnumTrustedDomainsEx\n");
2485 r_ex
.in
.handle
= handle
;
2486 r_ex
.in
.resume_handle
= &resume_handle
;
2487 r_ex
.in
.max_size
= LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER
* 3;
2488 r_ex
.out
.domains
= &domains_ex
;
2489 r_ex
.out
.resume_handle
= &resume_handle
;
2491 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumTrustedDomainsEx_r(b
, tctx
, &r_ex
),
2492 "EnumTrustedDomainsEx failed");
2494 if (!(NT_STATUS_EQUAL(r_ex
.out
.result
, STATUS_MORE_ENTRIES
) || NT_STATUS_EQUAL(r_ex
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
))) {
2495 torture_comment(tctx
, "EnumTrustedDomainEx of zero size failed - %s\n", nt_errstr(r_ex
.out
.result
));
2501 r_ex
.in
.handle
= handle
;
2502 r_ex
.in
.resume_handle
= &resume_handle
;
2503 r_ex
.in
.max_size
= LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER
* 3;
2504 r_ex
.out
.domains
= &domains_ex
;
2505 r_ex
.out
.resume_handle
= &resume_handle
;
2507 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumTrustedDomainsEx_r(b
, tctx
, &r_ex
),
2508 "EnumTrustedDomainsEx failed");
2510 /* NO_MORE_ENTRIES is allowed */
2511 if (NT_STATUS_EQUAL(r_ex
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
)) {
2512 if (domains_ex
.count
== 0) {
2515 torture_comment(tctx
, "EnumTrustDomainsEx failed - should have returned 0 trusted domains with 'NT_STATUS_NO_MORE_ENTRIES'\n");
2517 } else if (NT_STATUS_EQUAL(r_ex
.out
.result
, STATUS_MORE_ENTRIES
)) {
2518 /* Windows 2003 gets this off by one on the first run */
2519 if (r_ex
.out
.domains
->count
< 3 || r_ex
.out
.domains
->count
> 4) {
2520 torture_comment(tctx
, "EnumTrustDom didn't fill the buffer we "
2521 "asked it to (got %d, expected %d / %d == %d entries)\n",
2522 r_ex
.out
.domains
->count
,
2524 LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER
,
2525 r_ex
.in
.max_size
/ LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER
);
2527 } else if (!NT_STATUS_IS_OK(r_ex
.out
.result
)) {
2528 torture_comment(tctx
, "EnumTrustedDomainEx failed - %s\n", nt_errstr(r_ex
.out
.result
));
2532 if (domains_ex
.count
== 0) {
2533 torture_comment(tctx
, "EnumTrustDomainEx failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2537 ret
&= test_query_each_TrustDomEx(b
, tctx
, handle
, &domains_ex
);
2539 } while ((NT_STATUS_EQUAL(r_ex
.out
.result
, STATUS_MORE_ENTRIES
)));
2545 static bool test_CreateTrustedDomain(struct dcerpc_binding_handle
*b
,
2546 struct torture_context
*tctx
,
2547 struct policy_handle
*handle
,
2548 uint32_t num_trusts
)
2551 struct lsa_CreateTrustedDomain r
;
2552 struct lsa_DomainInfo trustinfo
;
2553 struct dom_sid
**domsid
;
2554 struct policy_handle
*trustdom_handle
;
2555 struct lsa_QueryTrustedDomainInfo q
;
2556 union lsa_TrustedDomainInfo
*info
= NULL
;
2559 torture_comment(tctx
, "\nTesting CreateTrustedDomain for %d domains\n", num_trusts
);
2561 if (!test_EnumTrustDom(b
, tctx
, handle
)) {
2565 if (!test_EnumTrustDomEx(b
, tctx
, handle
)) {
2569 domsid
= talloc_array(tctx
, struct dom_sid
*, num_trusts
);
2570 trustdom_handle
= talloc_array(tctx
, struct policy_handle
, num_trusts
);
2572 for (i
=0; i
< num_trusts
; i
++) {
2573 char *trust_name
= talloc_asprintf(tctx
, "torturedom%02d", i
);
2574 char *trust_sid
= talloc_asprintf(tctx
, "S-1-5-21-97398-379795-100%02d", i
);
2576 domsid
[i
] = dom_sid_parse_talloc(tctx
, trust_sid
);
2578 trustinfo
.sid
= domsid
[i
];
2579 init_lsa_String((struct lsa_String
*)&trustinfo
.name
, trust_name
);
2581 r
.in
.policy_handle
= handle
;
2582 r
.in
.info
= &trustinfo
;
2583 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2584 r
.out
.trustdom_handle
= &trustdom_handle
[i
];
2586 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateTrustedDomain_r(b
, tctx
, &r
),
2587 "CreateTrustedDomain failed");
2588 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
2589 test_DeleteTrustedDomain(b
, tctx
, handle
, trustinfo
.name
);
2590 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateTrustedDomain_r(b
, tctx
, &r
),
2591 "CreateTrustedDomain failed");
2593 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2594 torture_comment(tctx
, "CreateTrustedDomain failed - %s\n", nt_errstr(r
.out
.result
));
2598 q
.in
.trustdom_handle
= &trustdom_handle
[i
];
2599 q
.in
.level
= LSA_TRUSTED_DOMAIN_INFO_INFO_EX
;
2601 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfo_r(b
, tctx
, &q
),
2602 "QueryTrustedDomainInfo failed");
2603 if (!NT_STATUS_IS_OK(q
.out
.result
)) {
2604 torture_comment(tctx
, "QueryTrustedDomainInfo level %d failed - %s\n", q
.in
.level
, nt_errstr(q
.out
.result
));
2606 } else if (!q
.out
.info
) {
2609 if (strcmp(info
->info_ex
.netbios_name
.string
, trustinfo
.name
.string
) != 0) {
2610 torture_comment(tctx
, "QueryTrustedDomainInfo returned inconsistent short name: %s != %s\n",
2611 info
->info_ex
.netbios_name
.string
, trustinfo
.name
.string
);
2614 if (info
->info_ex
.trust_type
!= LSA_TRUST_TYPE_DOWNLEVEL
) {
2615 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
2616 trust_name
, info
->info_ex
.trust_type
, LSA_TRUST_TYPE_DOWNLEVEL
);
2619 if (info
->info_ex
.trust_attributes
!= 0) {
2620 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
2621 trust_name
, info
->info_ex
.trust_attributes
, 0);
2624 if (info
->info_ex
.trust_direction
!= LSA_TRUST_DIRECTION_OUTBOUND
) {
2625 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
2626 trust_name
, info
->info_ex
.trust_direction
, LSA_TRUST_DIRECTION_OUTBOUND
);
2633 /* now that we have some domains to look over, we can test the enum calls */
2634 if (!test_EnumTrustDom(b
, tctx
, handle
)) {
2638 if (!test_EnumTrustDomEx(b
, tctx
, handle
)) {
2642 for (i
=0; i
<num_trusts
; i
++) {
2643 if (!test_DeleteTrustedDomainBySid(b
, tctx
, handle
, domsid
[i
])) {
2651 static bool gen_authinfo_internal(TALLOC_CTX
*mem_ctx
, const char *password
,
2652 DATA_BLOB session_key
,
2653 struct lsa_TrustDomainInfoAuthInfoInternal
**_authinfo_internal
)
2655 struct lsa_TrustDomainInfoAuthInfoInternal
*authinfo_internal
;
2656 struct trustDomainPasswords auth_struct
;
2657 struct AuthenticationInformation
*auth_info_array
;
2658 size_t converted_size
;
2659 DATA_BLOB auth_blob
;
2660 enum ndr_err_code ndr_err
;
2662 authinfo_internal
= talloc_zero(mem_ctx
, struct lsa_TrustDomainInfoAuthInfoInternal
);
2663 if (authinfo_internal
== NULL
) {
2667 auth_info_array
= talloc_array(mem_ctx
,
2668 struct AuthenticationInformation
, 1);
2669 if (auth_info_array
== NULL
) {
2673 generate_random_buffer(auth_struct
.confounder
, sizeof(auth_struct
.confounder
));
2675 auth_info_array
[0].AuthType
= TRUST_AUTH_TYPE_CLEAR
;
2677 if (!convert_string_talloc(mem_ctx
, CH_UNIX
, CH_UTF16
, password
,
2679 &auth_info_array
[0].AuthInfo
.clear
.password
,
2684 auth_info_array
[0].AuthInfo
.clear
.size
= converted_size
;
2686 auth_struct
.outgoing
.count
= 1;
2687 auth_struct
.outgoing
.current
.count
= 1;
2688 auth_struct
.outgoing
.current
.array
= auth_info_array
;
2689 auth_struct
.outgoing
.previous
.count
= 0;
2690 auth_struct
.outgoing
.previous
.array
= NULL
;
2692 auth_struct
.incoming
.count
= 1;
2693 auth_struct
.incoming
.current
.count
= 1;
2694 auth_struct
.incoming
.current
.array
= auth_info_array
;
2695 auth_struct
.incoming
.previous
.count
= 0;
2696 auth_struct
.incoming
.previous
.array
= NULL
;
2699 ndr_err
= ndr_push_struct_blob(&auth_blob
, mem_ctx
, &auth_struct
,
2700 (ndr_push_flags_fn_t
)ndr_push_trustDomainPasswords
);
2701 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2705 arcfour_crypt_blob(auth_blob
.data
, auth_blob
.length
, &session_key
);
2707 authinfo_internal
->auth_blob
.size
= auth_blob
.length
;
2708 authinfo_internal
->auth_blob
.data
= auth_blob
.data
;
2710 *_authinfo_internal
= authinfo_internal
;
2715 static bool gen_authinfo(TALLOC_CTX
*mem_ctx
, const char *password
,
2716 struct lsa_TrustDomainInfoAuthInfo
**_authinfo
)
2718 struct lsa_TrustDomainInfoAuthInfo
*authinfo
;
2719 struct lsa_TrustDomainInfoBuffer
*info_buffer
;
2720 size_t converted_size
;
2722 authinfo
= talloc_zero(mem_ctx
, struct lsa_TrustDomainInfoAuthInfo
);
2723 if (authinfo
== NULL
) {
2727 info_buffer
= talloc_zero(mem_ctx
, struct lsa_TrustDomainInfoBuffer
);
2728 if (info_buffer
== NULL
) {
2732 info_buffer
->AuthType
= TRUST_AUTH_TYPE_CLEAR
;
2734 if (!convert_string_talloc(mem_ctx
, CH_UNIX
, CH_UTF16
, password
,
2736 &info_buffer
->data
.data
,
2741 info_buffer
->data
.size
= converted_size
;
2743 authinfo
->incoming_count
= 1;
2744 authinfo
->incoming_current_auth_info
= info_buffer
;
2745 authinfo
->incoming_previous_auth_info
= NULL
;
2746 authinfo
->outgoing_count
= 1;
2747 authinfo
->outgoing_current_auth_info
= info_buffer
;
2748 authinfo
->outgoing_previous_auth_info
= NULL
;
2750 *_authinfo
= authinfo
;
2755 static bool check_pw_with_ServerAuthenticate3(struct dcerpc_pipe
*p
,
2756 struct torture_context
*tctx
,
2757 uint32_t negotiate_flags
,
2758 struct cli_credentials
*machine_credentials
,
2759 struct netlogon_creds_CredentialState
**creds_out
)
2761 struct netr_ServerReqChallenge r
;
2762 struct netr_ServerAuthenticate3 a
;
2763 struct netr_Credential credentials1
, credentials2
, credentials3
;
2764 struct netlogon_creds_CredentialState
*creds
;
2765 struct samr_Password mach_password
;
2767 const char *machine_name
;
2768 const char *plain_pass
;
2769 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
2771 machine_name
= cli_credentials_get_workstation(machine_credentials
);
2772 plain_pass
= cli_credentials_get_password(machine_credentials
);
2774 r
.in
.server_name
= NULL
;
2775 r
.in
.computer_name
= machine_name
;
2776 r
.in
.credentials
= &credentials1
;
2777 r
.out
.return_credentials
= &credentials2
;
2779 generate_random_buffer(credentials1
.data
, sizeof(credentials1
.data
));
2781 torture_assert_ntstatus_ok(tctx
, dcerpc_netr_ServerReqChallenge_r(b
, tctx
, &r
),
2782 "ServerReqChallenge failed");
2783 torture_assert_ntstatus_ok(tctx
, r
.out
.result
, "ServerReqChallenge failed");
2785 E_md4hash(plain_pass
, mach_password
.hash
);
2787 a
.in
.server_name
= NULL
;
2788 a
.in
.account_name
= talloc_asprintf(tctx
, "%s$", machine_name
);
2789 a
.in
.secure_channel_type
= cli_credentials_get_secure_channel_type(machine_credentials
);
2790 a
.in
.computer_name
= machine_name
;
2791 a
.in
.negotiate_flags
= &negotiate_flags
;
2792 a
.in
.credentials
= &credentials3
;
2793 a
.out
.return_credentials
= &credentials3
;
2794 a
.out
.negotiate_flags
= &negotiate_flags
;
2797 creds
= netlogon_creds_client_init(tctx
, a
.in
.account_name
,
2799 &credentials1
, &credentials2
,
2800 &mach_password
, &credentials3
,
2803 torture_assert(tctx
, creds
!= NULL
, "memory allocation");
2805 torture_assert_ntstatus_ok(tctx
, dcerpc_netr_ServerAuthenticate3_r(b
, tctx
, &a
),
2806 "ServerAuthenticate3 failed");
2807 if (!NT_STATUS_IS_OK(a
.out
.result
)) {
2808 if (!NT_STATUS_EQUAL(a
.out
.result
, NT_STATUS_ACCESS_DENIED
)) {
2809 torture_assert_ntstatus_ok(tctx
, a
.out
.result
,
2810 "ServerAuthenticate3 failed");
2814 torture_assert(tctx
, netlogon_creds_client_check(creds
, &credentials3
), "Credential chaining failed");
2816 /* Prove that requesting a challenge again won't break it */
2817 torture_assert_ntstatus_ok(tctx
, dcerpc_netr_ServerReqChallenge_r(b
, tctx
, &r
),
2818 "ServerReqChallenge failed");
2819 torture_assert_ntstatus_ok(tctx
, r
.out
.result
, "ServerReqChallenge failed");
2825 static bool check_dom_trust_pw(struct dcerpc_pipe
*p
,
2826 struct torture_context
*tctx
,
2827 const char *trusted_dom_name
,
2828 const char *password
)
2830 struct cli_credentials
*credentials
;
2832 struct netlogon_creds_CredentialState
*creds
;
2833 struct dcerpc_pipe
*pipe
;
2837 credentials
= cli_credentials_init(tctx
);
2838 if (credentials
== NULL
) {
2842 dummy
= talloc_asprintf(tctx
, "%s$", trusted_dom_name
);
2843 if (dummy
== NULL
) {
2847 cli_credentials_set_username(credentials
, dummy
, CRED_SPECIFIED
);
2848 cli_credentials_set_password(credentials
, password
, CRED_SPECIFIED
);
2849 cli_credentials_set_workstation(credentials
,
2850 trusted_dom_name
, CRED_SPECIFIED
);
2851 cli_credentials_set_secure_channel_type(credentials
, SEC_CHAN_DOMAIN
);
2853 status
= dcerpc_pipe_connect_b(tctx
, &pipe
, p
->binding
,
2854 &ndr_table_netlogon
,
2855 cli_credentials_init_anon(tctx
),
2856 tctx
->ev
, tctx
->lp_ctx
);
2857 if (!NT_STATUS_IS_OK(status
)) {
2858 torture_comment(tctx
, "dcerpc_pipe_connect_b failed.\n");
2862 ok
= check_pw_with_ServerAuthenticate3(pipe
, tctx
,
2863 NETLOGON_NEG_AUTH2_ADS_FLAGS
,
2864 credentials
, &creds
);
2870 static bool test_CreateTrustedDomainEx_common(struct dcerpc_pipe
*p
,
2871 struct torture_context
*tctx
,
2872 struct policy_handle
*handle
,
2873 uint32_t num_trusts
,
2878 struct lsa_CreateTrustedDomainEx r
;
2879 struct lsa_CreateTrustedDomainEx2 r2
;
2880 struct lsa_TrustDomainInfoInfoEx trustinfo
;
2881 struct lsa_TrustDomainInfoAuthInfoInternal
*authinfo_internal
;
2882 struct lsa_TrustDomainInfoAuthInfo
*authinfo
;
2883 struct dom_sid
**domsid
;
2884 struct policy_handle
*trustdom_handle
;
2885 struct lsa_QueryTrustedDomainInfo q
;
2886 union lsa_TrustedDomainInfo
*info
= NULL
;
2887 DATA_BLOB session_key
;
2889 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
2892 torture_comment(tctx
, "\nTesting CreateTrustedDomainEx2 for %d domains\n", num_trusts
);
2894 torture_comment(tctx
, "\nTesting CreateTrustedDomainEx for %d domains\n", num_trusts
);
2897 domsid
= talloc_array(tctx
, struct dom_sid
*, num_trusts
);
2898 trustdom_handle
= talloc_array(tctx
, struct policy_handle
, num_trusts
);
2900 status
= dcerpc_fetch_session_key(p
, &session_key
);
2901 if (!NT_STATUS_IS_OK(status
)) {
2902 torture_comment(tctx
, "dcerpc_fetch_session_key failed - %s\n", nt_errstr(status
));
2906 for (i
=0; i
< num_trusts
; i
++) {
2907 char *trust_name
= talloc_asprintf(tctx
, "torturedom%02d", i
);
2908 char *trust_name_dns
= talloc_asprintf(tctx
, "torturedom%02d.samba.example.com", i
);
2909 char *trust_sid
= talloc_asprintf(tctx
, "S-1-5-21-97398-379795-100%02d", i
);
2911 domsid
[i
] = dom_sid_parse_talloc(tctx
, trust_sid
);
2913 trustinfo
.sid
= domsid
[i
];
2914 trustinfo
.netbios_name
.string
= trust_name
;
2915 trustinfo
.domain_name
.string
= trust_name_dns
;
2917 /* Create inbound, some outbound, and some
2918 * bi-directional trusts in a repeating pattern based
2921 /* 1 == inbound, 2 == outbound, 3 == both */
2922 trustinfo
.trust_direction
= (i
% 3) + 1;
2924 /* Try different trust types too */
2926 /* 1 == downlevel (NT4), 2 == uplevel (ADS), 3 == MIT (kerberos but not AD) */
2927 trustinfo
.trust_type
= (((i
/ 3) + 1) % 3) + 1;
2929 trustinfo
.trust_attributes
= LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION
;
2931 if (!gen_authinfo_internal(tctx
, TRUSTPW
, session_key
, &authinfo_internal
)) {
2932 torture_comment(tctx
, "gen_authinfo_internal failed");
2936 if (!gen_authinfo(tctx
, TRUSTPW
, &authinfo
)) {
2937 torture_comment(tctx
, "gen_authinfonfo failed");
2943 r2
.in
.policy_handle
= handle
;
2944 r2
.in
.info
= &trustinfo
;
2945 r2
.in
.auth_info_internal
= authinfo_internal
;
2946 r2
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2947 r2
.out
.trustdom_handle
= &trustdom_handle
[i
];
2949 torture_assert_ntstatus_ok(tctx
,
2950 dcerpc_lsa_CreateTrustedDomainEx2_r(b
, tctx
, &r2
),
2951 "CreateTrustedDomainEx2 failed");
2953 status
= r2
.out
.result
;
2956 r
.in
.policy_handle
= handle
;
2957 r
.in
.info
= &trustinfo
;
2958 r
.in
.auth_info
= authinfo
;
2959 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2960 r
.out
.trustdom_handle
= &trustdom_handle
[i
];
2962 torture_assert_ntstatus_ok(tctx
,
2963 dcerpc_lsa_CreateTrustedDomainEx_r(b
, tctx
, &r
),
2964 "CreateTrustedDomainEx failed");
2966 status
= r
.out
.result
;
2969 if (NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
2970 test_DeleteTrustedDomain(b
, tctx
, handle
, trustinfo
.netbios_name
);
2972 torture_assert_ntstatus_ok(tctx
,
2973 dcerpc_lsa_CreateTrustedDomainEx2_r(b
, tctx
, &r2
),
2974 "CreateTrustedDomainEx2 failed");
2975 status
= r2
.out
.result
;
2977 torture_assert_ntstatus_ok(tctx
,
2978 dcerpc_lsa_CreateTrustedDomainEx_r(b
, tctx
, &r
),
2979 "CreateTrustedDomainEx2 failed");
2980 status
= r
.out
.result
;
2983 if (!NT_STATUS_IS_OK(status
)) {
2984 torture_comment(tctx
, "CreateTrustedDomainEx failed2 - %s\n", nt_errstr(status
));
2987 /* For outbound and MIT trusts there is no trust account */
2988 if (trustinfo
.trust_direction
!= 2 &&
2989 trustinfo
.trust_type
!= 3) {
2991 if (torture_setting_bool(tctx
, "samba3", false) ||
2992 torture_setting_bool(tctx
, "samba4", false)) {
2993 torture_comment(tctx
, "skipping trusted domain auth tests against samba");
2995 if (check_dom_trust_pw(p
, tctx
, trust_name
,
2997 torture_comment(tctx
, "Password check passed unexpectedly\n");
3000 if (!check_dom_trust_pw(p
, tctx
, trust_name
,
3002 torture_comment(tctx
, "Password check failed\n");
3008 q
.in
.trustdom_handle
= &trustdom_handle
[i
];
3009 q
.in
.level
= LSA_TRUSTED_DOMAIN_INFO_INFO_EX
;
3011 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfo_r(b
, tctx
, &q
),
3012 "QueryTrustedDomainInfo failed");
3013 if (!NT_STATUS_IS_OK(q
.out
.result
)) {
3014 torture_comment(tctx
, "QueryTrustedDomainInfo level 1 failed - %s\n", nt_errstr(q
.out
.result
));
3016 } else if (!q
.out
.info
) {
3017 torture_comment(tctx
, "QueryTrustedDomainInfo level 1 failed to return an info pointer\n");
3020 if (strcmp(info
->info_ex
.netbios_name
.string
, trustinfo
.netbios_name
.string
) != 0) {
3021 torture_comment(tctx
, "QueryTrustedDomainInfo returned inconsistent short name: %s != %s\n",
3022 info
->info_ex
.netbios_name
.string
, trustinfo
.netbios_name
.string
);
3025 if (info
->info_ex
.trust_type
!= trustinfo
.trust_type
) {
3026 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
3027 trust_name
, info
->info_ex
.trust_type
, trustinfo
.trust_type
);
3030 if (info
->info_ex
.trust_attributes
!= LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION
) {
3031 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
3032 trust_name
, info
->info_ex
.trust_attributes
, LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION
);
3035 if (info
->info_ex
.trust_direction
!= trustinfo
.trust_direction
) {
3036 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
3037 trust_name
, info
->info_ex
.trust_direction
, trustinfo
.trust_direction
);
3044 /* now that we have some domains to look over, we can test the enum calls */
3045 if (!test_EnumTrustDom(b
, tctx
, handle
)) {
3046 torture_comment(tctx
, "test_EnumTrustDom failed\n");
3050 if (!test_EnumTrustDomEx(b
, tctx
, handle
)) {
3051 torture_comment(tctx
, "test_EnumTrustDomEx failed\n");
3055 for (i
=0; i
<num_trusts
; i
++) {
3056 if (!test_DeleteTrustedDomainBySid(b
, tctx
, handle
, domsid
[i
])) {
3057 torture_comment(tctx
, "test_DeleteTrustedDomainBySid failed\n");
3065 static bool test_CreateTrustedDomainEx2(struct dcerpc_pipe
*p
,
3066 struct torture_context
*tctx
,
3067 struct policy_handle
*handle
,
3068 uint32_t num_trusts
)
3070 return test_CreateTrustedDomainEx_common(p
, tctx
, handle
, num_trusts
, true);
3073 static bool test_CreateTrustedDomainEx(struct dcerpc_pipe
*p
,
3074 struct torture_context
*tctx
,
3075 struct policy_handle
*handle
,
3076 uint32_t num_trusts
)
3078 return test_CreateTrustedDomainEx_common(p
, tctx
, handle
, num_trusts
, false);
3081 static bool test_QueryDomainInfoPolicy(struct dcerpc_binding_handle
*b
,
3082 struct torture_context
*tctx
,
3083 struct policy_handle
*handle
)
3085 struct lsa_QueryDomainInformationPolicy r
;
3086 union lsa_DomainInformationPolicy
*info
= NULL
;
3090 if (torture_setting_bool(tctx
, "samba3", false)) {
3091 torture_skip(tctx
, "skipping QueryDomainInformationPolicy test\n");
3094 torture_comment(tctx
, "\nTesting QueryDomainInformationPolicy\n");
3097 r
.in
.handle
= handle
;
3101 torture_comment(tctx
, "\nTrying QueryDomainInformationPolicy level %d\n", i
);
3103 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryDomainInformationPolicy_r(b
, tctx
, &r
),
3104 "QueryDomainInformationPolicy failed");
3106 /* If the server does not support EFS, then this is the correct return */
3107 if (i
== LSA_DOMAIN_INFO_POLICY_EFS
&& NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
3109 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
3110 torture_comment(tctx
, "QueryDomainInformationPolicy failed - %s\n", nt_errstr(r
.out
.result
));
3120 static bool test_QueryInfoPolicyCalls( bool version2
,
3121 struct dcerpc_binding_handle
*b
,
3122 struct torture_context
*tctx
,
3123 struct policy_handle
*handle
)
3125 struct lsa_QueryInfoPolicy r
;
3126 union lsa_PolicyInformation
*info
= NULL
;
3129 const char *call
= talloc_asprintf(tctx
, "QueryInfoPolicy%s", version2
? "2":"");
3131 torture_comment(tctx
, "\nTesting %s\n", call
);
3133 if (version2
&& torture_setting_bool(tctx
, "samba3", false)) {
3134 torture_skip(tctx
, "skipping QueryInfoPolicy2 tests\n");
3137 for (i
=1;i
<=14;i
++) {
3138 r
.in
.handle
= handle
;
3142 torture_comment(tctx
, "\nTrying %s level %d\n", call
, i
);
3145 /* We can perform the cast, because both types are
3146 structurally equal */
3147 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryInfoPolicy2_r(b
, tctx
,
3148 (struct lsa_QueryInfoPolicy2
*) &r
),
3149 "QueryInfoPolicy2 failed");
3151 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryInfoPolicy_r(b
, tctx
, &r
),
3152 "QueryInfoPolicy2 failed");
3155 case LSA_POLICY_INFO_MOD
:
3156 case LSA_POLICY_INFO_AUDIT_FULL_SET
:
3157 case LSA_POLICY_INFO_AUDIT_FULL_QUERY
:
3158 if (!NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_INVALID_PARAMETER
)) {
3159 torture_comment(tctx
, "Server should have failed level %u: %s\n", i
, nt_errstr(r
.out
.result
));
3163 case LSA_POLICY_INFO_DOMAIN
:
3164 case LSA_POLICY_INFO_ACCOUNT_DOMAIN
:
3165 case LSA_POLICY_INFO_REPLICA
:
3166 case LSA_POLICY_INFO_QUOTA
:
3167 case LSA_POLICY_INFO_ROLE
:
3168 case LSA_POLICY_INFO_AUDIT_LOG
:
3169 case LSA_POLICY_INFO_AUDIT_EVENTS
:
3170 case LSA_POLICY_INFO_PD
:
3171 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
3172 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(r
.out
.result
));
3176 case LSA_POLICY_INFO_L_ACCOUNT_DOMAIN
:
3177 case LSA_POLICY_INFO_DNS_INT
:
3178 case LSA_POLICY_INFO_DNS
:
3179 if (torture_setting_bool(tctx
, "samba3", false)) {
3180 /* Other levels not implemented yet */
3181 if (!NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_INVALID_INFO_CLASS
)) {
3182 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(r
.out
.result
));
3185 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
3186 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(r
.out
.result
));
3191 if (torture_setting_bool(tctx
, "samba4", false)) {
3192 /* Other levels not implemented yet */
3193 if (!NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_INVALID_INFO_CLASS
)) {
3194 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(r
.out
.result
));
3197 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
3198 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(r
.out
.result
));
3204 if (NT_STATUS_IS_OK(r
.out
.result
) && (i
== LSA_POLICY_INFO_DNS
3205 || i
== LSA_POLICY_INFO_DNS_INT
)) {
3206 /* Let's look up some of these names */
3208 struct lsa_TransNameArray tnames
;
3210 tnames
.names
= talloc_zero_array(tctx
, struct lsa_TranslatedName
, tnames
.count
);
3211 tnames
.names
[0].name
.string
= info
->dns
.name
.string
;
3212 tnames
.names
[0].sid_type
= SID_NAME_DOMAIN
;
3213 tnames
.names
[1].name
.string
= info
->dns
.dns_domain
.string
;
3214 tnames
.names
[1].sid_type
= SID_NAME_DOMAIN
;
3215 tnames
.names
[2].name
.string
= talloc_asprintf(tctx
, "%s\\", info
->dns
.name
.string
);
3216 tnames
.names
[2].sid_type
= SID_NAME_DOMAIN
;
3217 tnames
.names
[3].name
.string
= talloc_asprintf(tctx
, "%s\\", info
->dns
.dns_domain
.string
);
3218 tnames
.names
[3].sid_type
= SID_NAME_DOMAIN
;
3219 tnames
.names
[4].name
.string
= talloc_asprintf(tctx
, "%s\\guest", info
->dns
.name
.string
);
3220 tnames
.names
[4].sid_type
= SID_NAME_USER
;
3221 tnames
.names
[5].name
.string
= talloc_asprintf(tctx
, "%s\\krbtgt", info
->dns
.name
.string
);
3222 tnames
.names
[5].sid_type
= SID_NAME_USER
;
3223 tnames
.names
[6].name
.string
= talloc_asprintf(tctx
, "%s\\guest", info
->dns
.dns_domain
.string
);
3224 tnames
.names
[6].sid_type
= SID_NAME_USER
;
3225 tnames
.names
[7].name
.string
= talloc_asprintf(tctx
, "%s\\krbtgt", info
->dns
.dns_domain
.string
);
3226 tnames
.names
[7].sid_type
= SID_NAME_USER
;
3227 tnames
.names
[8].name
.string
= talloc_asprintf(tctx
, "krbtgt@%s", info
->dns
.name
.string
);
3228 tnames
.names
[8].sid_type
= SID_NAME_USER
;
3229 tnames
.names
[9].name
.string
= talloc_asprintf(tctx
, "krbtgt@%s", info
->dns
.dns_domain
.string
);
3230 tnames
.names
[9].sid_type
= SID_NAME_USER
;
3231 tnames
.names
[10].name
.string
= talloc_asprintf(tctx
, "%s\\"TEST_MACHINENAME
"$", info
->dns
.name
.string
);
3232 tnames
.names
[10].sid_type
= SID_NAME_USER
;
3233 tnames
.names
[11].name
.string
= talloc_asprintf(tctx
, "%s\\"TEST_MACHINENAME
"$", info
->dns
.dns_domain
.string
);
3234 tnames
.names
[11].sid_type
= SID_NAME_USER
;
3235 tnames
.names
[12].name
.string
= talloc_asprintf(tctx
, TEST_MACHINENAME
"$@%s", info
->dns
.name
.string
);
3236 tnames
.names
[12].sid_type
= SID_NAME_USER
;
3237 tnames
.names
[13].name
.string
= talloc_asprintf(tctx
, TEST_MACHINENAME
"$@%s", info
->dns
.dns_domain
.string
);
3238 tnames
.names
[13].sid_type
= SID_NAME_USER
;
3239 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
3247 static bool test_QueryInfoPolicy(struct dcerpc_binding_handle
*b
,
3248 struct torture_context
*tctx
,
3249 struct policy_handle
*handle
)
3251 return test_QueryInfoPolicyCalls(false, b
, tctx
, handle
);
3254 static bool test_QueryInfoPolicy2(struct dcerpc_binding_handle
*b
,
3255 struct torture_context
*tctx
,
3256 struct policy_handle
*handle
)
3258 return test_QueryInfoPolicyCalls(true, b
, tctx
, handle
);
3261 static bool test_GetUserName(struct dcerpc_binding_handle
*b
,
3262 struct torture_context
*tctx
)
3264 struct lsa_GetUserName r
;
3266 struct lsa_String
*authority_name_p
= NULL
;
3267 struct lsa_String
*account_name_p
= NULL
;
3269 torture_comment(tctx
, "\nTesting GetUserName\n");
3271 r
.in
.system_name
= "\\";
3272 r
.in
.account_name
= &account_name_p
;
3273 r
.in
.authority_name
= NULL
;
3274 r
.out
.account_name
= &account_name_p
;
3276 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_GetUserName_r(b
, tctx
, &r
),
3277 "GetUserName failed");
3279 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
3280 torture_comment(tctx
, "GetUserName failed - %s\n", nt_errstr(r
.out
.result
));
3284 account_name_p
= NULL
;
3285 r
.in
.account_name
= &account_name_p
;
3286 r
.in
.authority_name
= &authority_name_p
;
3287 r
.out
.account_name
= &account_name_p
;
3289 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_GetUserName_r(b
, tctx
, &r
),
3290 "GetUserName failed");
3292 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
3293 torture_comment(tctx
, "GetUserName failed - %s\n", nt_errstr(r
.out
.result
));
3300 static bool test_GetUserName_fail(struct dcerpc_binding_handle
*b
,
3301 struct torture_context
*tctx
)
3303 struct lsa_GetUserName r
;
3304 struct lsa_String
*account_name_p
= NULL
;
3307 torture_comment(tctx
, "\nTesting GetUserName_fail\n");
3309 r
.in
.system_name
= "\\";
3310 r
.in
.account_name
= &account_name_p
;
3311 r
.in
.authority_name
= NULL
;
3312 r
.out
.account_name
= &account_name_p
;
3314 status
= dcerpc_lsa_GetUserName_r(b
, tctx
, &r
);
3315 if (!NT_STATUS_IS_OK(status
)) {
3316 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
3317 torture_comment(tctx
,
3318 "GetUserName correctly returned with "
3324 torture_assert_ntstatus_equal(tctx
,
3326 NT_STATUS_ACCESS_DENIED
,
3327 "GetUserName return value should "
3328 "be ACCESS_DENIED");
3332 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
3333 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_ACCESS_DENIED
) ||
3334 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
3335 torture_comment(tctx
,
3336 "GetUserName correctly returned with "
3338 nt_errstr(r
.out
.result
));
3343 torture_assert_ntstatus_equal(tctx
,
3346 "GetUserName return value should be "
3352 bool test_lsa_Close(struct dcerpc_binding_handle
*b
,
3353 struct torture_context
*tctx
,
3354 struct policy_handle
*handle
)
3357 struct policy_handle handle2
;
3359 torture_comment(tctx
, "\nTesting Close\n");
3361 r
.in
.handle
= handle
;
3362 r
.out
.handle
= &handle2
;
3364 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_Close_r(b
, tctx
, &r
),
3366 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
3367 torture_comment(tctx
, "Close failed - %s\n",
3368 nt_errstr(r
.out
.result
));
3372 torture_assert_ntstatus_equal(tctx
, dcerpc_lsa_Close_r(b
, tctx
, &r
),
3373 NT_STATUS_RPC_SS_CONTEXT_MISMATCH
, "Close should failed");
3375 torture_comment(tctx
, "\n");
3380 bool torture_rpc_lsa(struct torture_context
*tctx
)
3383 struct dcerpc_pipe
*p
;
3385 struct policy_handle
*handle
= NULL
;
3386 struct test_join
*join
= NULL
;
3387 struct cli_credentials
*machine_creds
;
3388 struct dcerpc_binding_handle
*b
;
3390 status
= torture_rpc_connection(tctx
, &p
, &ndr_table_lsarpc
);
3391 if (!NT_STATUS_IS_OK(status
)) {
3394 b
= p
->binding_handle
;
3396 /* Test lsaLookupSids3 and lsaLookupNames4 over tcpip */
3397 if (p
->binding
->transport
== NCACN_IP_TCP
) {
3398 if (!test_OpenPolicy_fail(b
, tctx
)) {
3402 if (!test_OpenPolicy2_fail(b
, tctx
)) {
3406 if (!test_many_LookupSids(p
, tctx
, handle
)) {
3413 if (!test_OpenPolicy(b
, tctx
)) {
3417 if (!test_lsa_OpenPolicy2(b
, tctx
, &handle
)) {
3422 join
= torture_join_domain(tctx
, TEST_MACHINENAME
, ACB_WSTRUST
, &machine_creds
);
3427 if (!test_LookupSids_async(b
, tctx
, handle
)) {
3431 if (!test_QueryDomainInfoPolicy(b
, tctx
, handle
)) {
3435 if (!test_CreateSecret(p
, tctx
, handle
)) {
3439 if (!test_QueryInfoPolicy(b
, tctx
, handle
)) {
3443 if (!test_QueryInfoPolicy2(b
, tctx
, handle
)) {
3447 if (!test_Delete(b
, tctx
, handle
)) {
3451 if (!test_many_LookupSids(p
, tctx
, handle
)) {
3455 if (!test_lsa_Close(b
, tctx
, handle
)) {
3459 torture_leave_domain(tctx
, join
);
3462 if (!test_many_LookupSids(p
, tctx
, handle
)) {
3467 if (!test_GetUserName(b
, tctx
)) {
3474 bool torture_rpc_lsa_get_user(struct torture_context
*tctx
)
3477 struct dcerpc_pipe
*p
;
3479 struct dcerpc_binding_handle
*b
;
3481 status
= torture_rpc_connection(tctx
, &p
, &ndr_table_lsarpc
);
3482 if (!NT_STATUS_IS_OK(status
)) {
3485 b
= p
->binding_handle
;
3487 if (p
->binding
->transport
== NCACN_IP_TCP
) {
3488 if (!test_GetUserName_fail(b
, tctx
)) {
3494 if (!test_GetUserName(b
, tctx
)) {
3501 static bool testcase_LookupNames(struct torture_context
*tctx
,
3502 struct dcerpc_pipe
*p
)
3505 struct policy_handle
*handle
;
3506 struct lsa_TransNameArray tnames
;
3507 struct lsa_TransNameArray2 tnames2
;
3508 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
3510 if (p
->binding
->transport
!= NCACN_NP
&&
3511 p
->binding
->transport
!= NCALRPC
) {
3512 torture_comment(tctx
, "testcase_LookupNames is only available "
3513 "over NCACN_NP or NCALRPC");
3517 if (!test_OpenPolicy(b
, tctx
)) {
3521 if (!test_lsa_OpenPolicy2(b
, tctx
, &handle
)) {
3530 tnames
.names
= talloc_array(tctx
, struct lsa_TranslatedName
, tnames
.count
);
3531 ZERO_STRUCT(tnames
.names
[0]);
3532 tnames
.names
[0].name
.string
= "BUILTIN";
3533 tnames
.names
[0].sid_type
= SID_NAME_DOMAIN
;
3535 if (!test_LookupNames(b
, tctx
, handle
, &tnames
)) {
3540 tnames2
.names
= talloc_array(tctx
, struct lsa_TranslatedName2
, tnames2
.count
);
3541 ZERO_STRUCT(tnames2
.names
[0]);
3542 tnames2
.names
[0].name
.string
= "BUILTIN";
3543 tnames2
.names
[0].sid_type
= SID_NAME_DOMAIN
;
3545 if (!test_LookupNames2(b
, tctx
, handle
, &tnames2
, true)) {
3549 if (!test_LookupNames3(b
, tctx
, handle
, &tnames2
, true)) {
3553 if (!test_LookupNames_wellknown(b
, tctx
, handle
)) {
3557 if (!test_LookupNames_NULL(b
, tctx
, handle
)) {
3561 if (!test_LookupNames_bogus(b
, tctx
, handle
)) {
3565 if (!test_lsa_Close(b
, tctx
, handle
)) {
3572 struct torture_suite
*torture_rpc_lsa_lookup_names(TALLOC_CTX
*mem_ctx
)
3574 struct torture_suite
*suite
;
3575 struct torture_rpc_tcase
*tcase
;
3577 suite
= torture_suite_create(mem_ctx
, "lsa.lookupnames");
3579 tcase
= torture_suite_add_rpc_iface_tcase(suite
, "lsa",
3581 torture_rpc_tcase_add_test(tcase
, "LookupNames",
3582 testcase_LookupNames
);
3587 struct lsa_trustdom_state
{
3588 uint32_t num_trusts
;
3591 static bool testcase_TrustedDomains(struct torture_context
*tctx
,
3592 struct dcerpc_pipe
*p
,
3596 struct policy_handle
*handle
;
3597 struct lsa_trustdom_state
*state
=
3598 talloc_get_type_abort(data
, struct lsa_trustdom_state
);
3599 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
3601 if (p
->binding
->transport
!= NCACN_NP
&&
3602 p
->binding
->transport
!= NCALRPC
) {
3603 torture_comment(tctx
, "testcase_TrustedDomains is only available "
3604 "over NCACN_NP or NCALRPC");
3608 torture_comment(tctx
, "Testing %d domains\n", state
->num_trusts
);
3610 if (!test_OpenPolicy(b
, tctx
)) {
3614 if (!test_lsa_OpenPolicy2(b
, tctx
, &handle
)) {
3622 if (!test_CreateTrustedDomain(b
, tctx
, handle
, state
->num_trusts
)) {
3626 if (!test_CreateTrustedDomainEx(p
, tctx
, handle
, state
->num_trusts
)) {
3630 if (!test_CreateTrustedDomainEx2(p
, tctx
, handle
, state
->num_trusts
)) {
3634 if (!test_lsa_Close(b
, tctx
, handle
)) {
3641 struct torture_suite
*torture_rpc_lsa_trusted_domains(TALLOC_CTX
*mem_ctx
)
3643 struct torture_suite
*suite
;
3644 struct torture_rpc_tcase
*tcase
;
3645 struct lsa_trustdom_state
*state
;
3647 state
= talloc(mem_ctx
, struct lsa_trustdom_state
);
3649 state
->num_trusts
= 12;
3651 suite
= torture_suite_create(mem_ctx
, "lsa.trusted.domains");
3653 tcase
= torture_suite_add_rpc_iface_tcase(suite
, "lsa",
3655 torture_rpc_tcase_add_test_ex(tcase
, "TrustedDomains",
3656 testcase_TrustedDomains
,
3662 static bool testcase_Privileges(struct torture_context
*tctx
,
3663 struct dcerpc_pipe
*p
)
3666 struct policy_handle
*handle
;
3667 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
3669 if (p
->binding
->transport
!= NCACN_NP
&&
3670 p
->binding
->transport
!= NCALRPC
) {
3671 torture_comment(tctx
, "testcase_Privileges is only available "
3672 "over NCACN_NP or NCALRPC");
3676 if (!test_OpenPolicy(b
, tctx
)) {
3680 if (!test_lsa_OpenPolicy2(b
, tctx
, &handle
)) {
3688 if (!test_CreateAccount(b
, tctx
, handle
)) {
3692 if (!test_EnumAccounts(b
, tctx
, handle
)) {
3696 if (!test_EnumPrivs(b
, tctx
, handle
)) {
3700 if (!test_lsa_Close(b
, tctx
, handle
)) {
3708 struct torture_suite
*torture_rpc_lsa_privileges(TALLOC_CTX
*mem_ctx
)
3710 struct torture_suite
*suite
;
3711 struct torture_rpc_tcase
*tcase
;
3713 suite
= torture_suite_create(mem_ctx
, "lsa.privileges");
3715 tcase
= torture_suite_add_rpc_iface_tcase(suite
, "lsa",
3717 torture_rpc_tcase_add_test(tcase
, "Privileges",
3718 testcase_Privileges
);