2 Unix SMB/CIFS implementation.
3 test suite for lsa rpc operations
5 Copyright (C) Andrew Tridgell 2003
6 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2004-2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "torture/torture.h"
24 #include "librpc/gen_ndr/ndr_lsa_c.h"
25 #include "librpc/gen_ndr/netlogon.h"
26 #include "librpc/gen_ndr/ndr_drsblobs.h"
27 #include "lib/events/events.h"
28 #include "libcli/security/security.h"
29 #include "libcli/auth/libcli_auth.h"
30 #include "torture/rpc/torture_rpc.h"
31 #include "param/param.h"
32 #include "../lib/crypto/crypto.h"
33 #define TEST_MACHINENAME "lsatestmach"
35 static void init_lsa_String(struct lsa_String
*name
, const char *s
)
40 static bool test_OpenPolicy(struct dcerpc_binding_handle
*b
,
41 struct torture_context
*tctx
)
43 struct lsa_ObjectAttribute attr
;
44 struct policy_handle handle
;
45 struct lsa_QosInfo qos
;
46 struct lsa_OpenPolicy r
;
47 uint16_t system_name
= '\\';
49 torture_comment(tctx
, "\nTesting OpenPolicy\n");
52 qos
.impersonation_level
= 2;
54 qos
.effective_only
= 0;
58 attr
.object_name
= NULL
;
63 r
.in
.system_name
= &system_name
;
65 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
66 r
.out
.handle
= &handle
;
68 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenPolicy_r(b
, tctx
, &r
),
70 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
71 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_ACCESS_DENIED
) ||
72 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
73 torture_comment(tctx
, "not considering %s to be an error\n",
74 nt_errstr(r
.out
.result
));
77 torture_comment(tctx
, "OpenPolicy failed - %s\n",
78 nt_errstr(r
.out
.result
));
86 bool test_lsa_OpenPolicy2_ex(struct dcerpc_binding_handle
*b
,
87 struct torture_context
*tctx
,
88 struct policy_handle
**handle
,
89 NTSTATUS expected_status
)
91 struct lsa_ObjectAttribute attr
;
92 struct lsa_QosInfo qos
;
93 struct lsa_OpenPolicy2 r
;
96 torture_comment(tctx
, "\nTesting OpenPolicy2\n");
98 *handle
= talloc(tctx
, struct policy_handle
);
104 qos
.impersonation_level
= 2;
105 qos
.context_mode
= 1;
106 qos
.effective_only
= 0;
109 attr
.root_dir
= NULL
;
110 attr
.object_name
= NULL
;
112 attr
.sec_desc
= NULL
;
115 r
.in
.system_name
= "\\";
117 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
118 r
.out
.handle
= *handle
;
120 status
= dcerpc_lsa_OpenPolicy2_r(b
, tctx
, &r
);
121 torture_assert_ntstatus_equal(tctx
, status
, expected_status
,
122 "OpenPolicy2 failed");
123 if (!NT_STATUS_IS_OK(expected_status
)) {
126 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
127 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_ACCESS_DENIED
) ||
128 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
129 torture_comment(tctx
, "not considering %s to be an error\n",
130 nt_errstr(r
.out
.result
));
131 talloc_free(*handle
);
135 torture_comment(tctx
, "OpenPolicy2 failed - %s\n",
136 nt_errstr(r
.out
.result
));
144 bool test_lsa_OpenPolicy2(struct dcerpc_binding_handle
*b
,
145 struct torture_context
*tctx
,
146 struct policy_handle
**handle
)
148 return test_lsa_OpenPolicy2_ex(b
, tctx
, handle
, NT_STATUS_OK
);
151 static bool test_LookupNames(struct dcerpc_binding_handle
*b
,
152 struct torture_context
*tctx
,
153 struct policy_handle
*handle
,
154 struct lsa_TransNameArray
*tnames
)
156 struct lsa_LookupNames r
;
157 struct lsa_TransSidArray sids
;
158 struct lsa_RefDomainList
*domains
= NULL
;
159 struct lsa_String
*names
;
164 torture_comment(tctx
, "\nTesting LookupNames with %d names\n", tnames
->count
);
172 input_idx
= talloc_array(tctx
, uint32_t, tnames
->count
);
173 names
= talloc_array(tctx
, struct lsa_String
, tnames
->count
);
175 for (i
=0;i
<tnames
->count
;i
++) {
176 if (tnames
->names
[i
].sid_type
!= SID_NAME_UNKNOWN
) {
177 init_lsa_String(&names
[r
.in
.num_names
], tnames
->names
[i
].name
.string
);
178 input_idx
[r
.in
.num_names
] = i
;
183 r
.in
.handle
= handle
;
188 r
.out
.count
= &count
;
190 r
.out
.domains
= &domains
;
192 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames_r(b
, tctx
, &r
),
193 "LookupNames failed");
194 if (NT_STATUS_EQUAL(r
.out
.result
, STATUS_SOME_UNMAPPED
) ||
195 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NONE_MAPPED
)) {
196 for (i
=0;i
< r
.in
.num_names
;i
++) {
197 if (i
< count
&& sids
.sids
[i
].sid_type
== SID_NAME_UNKNOWN
) {
198 torture_comment(tctx
, "LookupName of %s was unmapped\n",
199 tnames
->names
[i
].name
.string
);
200 } else if (i
>=count
) {
201 torture_comment(tctx
, "LookupName of %s failed to return a result\n",
202 tnames
->names
[i
].name
.string
);
205 torture_comment(tctx
, "LookupNames failed - %s\n",
206 nt_errstr(r
.out
.result
));
208 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
209 torture_comment(tctx
, "LookupNames failed - %s\n",
210 nt_errstr(r
.out
.result
));
214 for (i
=0;i
< r
.in
.num_names
;i
++) {
216 if (sids
.sids
[i
].sid_type
!= tnames
->names
[input_idx
[i
]].sid_type
) {
217 torture_comment(tctx
, "LookupName of %s got unexpected name type: %s\n",
218 tnames
->names
[input_idx
[i
]].name
.string
,
219 sid_type_lookup(sids
.sids
[i
].sid_type
));
222 if ((sids
.sids
[i
].sid_type
== SID_NAME_DOMAIN
) &&
223 (sids
.sids
[i
].rid
!= (uint32_t)-1)) {
224 torture_comment(tctx
, "LookupName of %s got unexpected rid: %d\n",
225 tnames
->names
[input_idx
[i
]].name
.string
, sids
.sids
[i
].rid
);
228 } else if (i
>=count
) {
229 torture_comment(tctx
, "LookupName of %s failed to return a result\n",
230 tnames
->names
[input_idx
[i
]].name
.string
);
234 torture_comment(tctx
, "\n");
239 static bool test_LookupNames_bogus(struct dcerpc_binding_handle
*b
,
240 struct torture_context
*tctx
,
241 struct policy_handle
*handle
)
243 struct lsa_LookupNames r
;
244 struct lsa_TransSidArray sids
;
245 struct lsa_RefDomainList
*domains
= NULL
;
246 struct lsa_String names
[1];
249 torture_comment(tctx
, "\nTesting LookupNames with bogus name\n");
254 init_lsa_String(&names
[0], "NT AUTHORITY\\BOGUS");
256 r
.in
.handle
= handle
;
262 r
.out
.count
= &count
;
264 r
.out
.domains
= &domains
;
266 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames_r(b
, tctx
, &r
),
267 "LookupNames bogus failed");
268 if (!NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NONE_MAPPED
)) {
269 torture_comment(tctx
, "LookupNames failed - %s\n",
270 nt_errstr(r
.out
.result
));
274 torture_comment(tctx
, "\n");
279 static bool test_LookupNames_NULL(struct dcerpc_binding_handle
*b
,
280 struct torture_context
*tctx
,
281 struct policy_handle
*handle
)
283 struct lsa_LookupNames r
;
284 struct lsa_TransSidArray sids
;
285 struct lsa_RefDomainList
*domains
= NULL
;
286 struct lsa_String names
[1];
289 torture_comment(tctx
, "\nTesting LookupNames with NULL name\n");
294 names
[0].string
= NULL
;
296 r
.in
.handle
= handle
;
302 r
.out
.count
= &count
;
304 r
.out
.domains
= &domains
;
306 /* nt4 returns NT_STATUS_NONE_MAPPED with sid_type
307 * SID_NAME_UNKNOWN, rid 0, and sid_index -1;
309 * w2k3/w2k8 return NT_STATUS_OK with sid_type
310 * SID_NAME_DOMAIN, rid -1 and sid_index 0 and BUILTIN domain
313 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames_r(b
, tctx
, &r
),
314 "LookupNames with NULL name failed");
315 torture_assert_ntstatus_ok(tctx
, r
.out
.result
,
316 "LookupNames with NULL name failed");
318 torture_comment(tctx
, "\n");
323 static bool test_LookupNames_wellknown(struct dcerpc_binding_handle
*b
,
324 struct torture_context
*tctx
,
325 struct policy_handle
*handle
)
327 struct lsa_TranslatedName name
;
328 struct lsa_TransNameArray tnames
;
331 torture_comment(tctx
, "Testing LookupNames with well known names\n");
333 tnames
.names
= &name
;
335 name
.name
.string
= "NT AUTHORITY\\SYSTEM";
336 name
.sid_type
= SID_NAME_WKN_GRP
;
337 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
339 name
.name
.string
= "NT AUTHORITY\\ANONYMOUS LOGON";
340 name
.sid_type
= SID_NAME_WKN_GRP
;
341 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
343 name
.name
.string
= "NT AUTHORITY\\Authenticated Users";
344 name
.sid_type
= SID_NAME_WKN_GRP
;
345 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
348 name
.name
.string
= "NT AUTHORITY";
349 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
351 name
.name
.string
= "NT AUTHORITY\\";
352 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
355 name
.name
.string
= "BUILTIN\\";
356 name
.sid_type
= SID_NAME_DOMAIN
;
357 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
359 name
.name
.string
= "BUILTIN\\Administrators";
360 name
.sid_type
= SID_NAME_ALIAS
;
361 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
363 name
.name
.string
= "SYSTEM";
364 name
.sid_type
= SID_NAME_WKN_GRP
;
365 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
367 name
.name
.string
= "Everyone";
368 name
.sid_type
= SID_NAME_WKN_GRP
;
369 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
373 static bool test_LookupNames2(struct dcerpc_binding_handle
*b
,
374 struct torture_context
*tctx
,
375 struct policy_handle
*handle
,
376 struct lsa_TransNameArray2
*tnames
,
379 struct lsa_LookupNames2 r
;
380 struct lsa_TransSidArray2 sids
;
381 struct lsa_RefDomainList
*domains
= NULL
;
382 struct lsa_String
*names
;
386 torture_comment(tctx
, "\nTesting LookupNames2 with %d names\n", tnames
->count
);
394 input_idx
= talloc_array(tctx
, uint32_t, tnames
->count
);
395 names
= talloc_array(tctx
, struct lsa_String
, tnames
->count
);
397 for (i
=0;i
<tnames
->count
;i
++) {
398 if (tnames
->names
[i
].sid_type
!= SID_NAME_UNKNOWN
) {
399 init_lsa_String(&names
[r
.in
.num_names
], tnames
->names
[i
].name
.string
);
400 input_idx
[r
.in
.num_names
] = i
;
405 r
.in
.handle
= handle
;
410 r
.in
.lookup_options
= 0;
411 r
.in
.client_revision
= 0;
412 r
.out
.count
= &count
;
414 r
.out
.domains
= &domains
;
416 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames2_r(b
, tctx
, &r
),
417 "LookupNames2 failed");
418 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
419 torture_comment(tctx
, "LookupNames2 failed - %s\n",
420 nt_errstr(r
.out
.result
));
425 torture_assert_int_equal(tctx
, count
, sids
.count
,
426 "unexpected number of results returned");
427 if (sids
.count
> 0) {
428 torture_assert(tctx
, sids
.sids
, "invalid sid buffer");
432 torture_comment(tctx
, "\n");
438 static bool test_LookupNames3(struct dcerpc_binding_handle
*b
,
439 struct torture_context
*tctx
,
440 struct policy_handle
*handle
,
441 struct lsa_TransNameArray2
*tnames
,
444 struct lsa_LookupNames3 r
;
445 struct lsa_TransSidArray3 sids
;
446 struct lsa_RefDomainList
*domains
= NULL
;
447 struct lsa_String
*names
;
452 torture_comment(tctx
, "\nTesting LookupNames3 with %d names\n", tnames
->count
);
459 input_idx
= talloc_array(tctx
, uint32_t, tnames
->count
);
460 names
= talloc_array(tctx
, struct lsa_String
, tnames
->count
);
461 for (i
=0;i
<tnames
->count
;i
++) {
462 if (tnames
->names
[i
].sid_type
!= SID_NAME_UNKNOWN
) {
463 init_lsa_String(&names
[r
.in
.num_names
], tnames
->names
[i
].name
.string
);
464 input_idx
[r
.in
.num_names
] = i
;
469 r
.in
.handle
= handle
;
474 r
.in
.lookup_options
= 0;
475 r
.in
.client_revision
= 0;
476 r
.out
.count
= &count
;
478 r
.out
.domains
= &domains
;
480 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames3_r(b
, tctx
, &r
),
481 "LookupNames3 failed");
482 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
483 torture_comment(tctx
, "LookupNames3 failed - %s\n",
484 nt_errstr(r
.out
.result
));
489 torture_assert_int_equal(tctx
, count
, sids
.count
,
490 "unexpected number of results returned");
491 if (sids
.count
> 0) {
492 torture_assert(tctx
, sids
.sids
, "invalid sid buffer");
496 torture_comment(tctx
, "\n");
501 static bool test_LookupNames4(struct dcerpc_binding_handle
*b
,
502 struct torture_context
*tctx
,
503 struct lsa_TransNameArray2
*tnames
,
506 struct lsa_LookupNames4 r
;
507 struct lsa_TransSidArray3 sids
;
508 struct lsa_RefDomainList
*domains
= NULL
;
509 struct lsa_String
*names
;
514 torture_comment(tctx
, "\nTesting LookupNames4 with %d names\n", tnames
->count
);
521 input_idx
= talloc_array(tctx
, uint32_t, tnames
->count
);
522 names
= talloc_array(tctx
, struct lsa_String
, tnames
->count
);
523 for (i
=0;i
<tnames
->count
;i
++) {
524 if (tnames
->names
[i
].sid_type
!= SID_NAME_UNKNOWN
) {
525 init_lsa_String(&names
[r
.in
.num_names
], tnames
->names
[i
].name
.string
);
526 input_idx
[r
.in
.num_names
] = i
;
531 r
.in
.num_names
= tnames
->count
;
536 r
.in
.lookup_options
= 0;
537 r
.in
.client_revision
= 0;
538 r
.out
.count
= &count
;
540 r
.out
.domains
= &domains
;
542 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames4_r(b
, tctx
, &r
),
543 "LookupNames4 failed");
544 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
545 torture_comment(tctx
, "LookupNames4 failed - %s\n",
546 nt_errstr(r
.out
.result
));
551 torture_assert_int_equal(tctx
, count
, sids
.count
,
552 "unexpected number of results returned");
553 if (sids
.count
> 0) {
554 torture_assert(tctx
, sids
.sids
, "invalid sid buffer");
558 torture_comment(tctx
, "\n");
564 static bool test_LookupSids(struct dcerpc_binding_handle
*b
,
565 struct torture_context
*tctx
,
566 struct policy_handle
*handle
,
567 struct lsa_SidArray
*sids
)
569 struct lsa_LookupSids r
;
570 struct lsa_TransNameArray names
;
571 struct lsa_RefDomainList
*domains
= NULL
;
572 uint32_t count
= sids
->num_sids
;
574 torture_comment(tctx
, "\nTesting LookupSids\n");
579 r
.in
.handle
= handle
;
584 r
.out
.count
= &count
;
585 r
.out
.names
= &names
;
586 r
.out
.domains
= &domains
;
588 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupSids_r(b
, tctx
, &r
),
589 "LookupSids failed");
590 if (!NT_STATUS_IS_OK(r
.out
.result
) &&
591 !NT_STATUS_EQUAL(r
.out
.result
, STATUS_SOME_UNMAPPED
)) {
592 torture_comment(tctx
, "LookupSids failed - %s\n",
593 nt_errstr(r
.out
.result
));
597 torture_comment(tctx
, "\n");
599 if (!test_LookupNames(b
, tctx
, handle
, &names
)) {
607 static bool test_LookupSids2(struct dcerpc_binding_handle
*b
,
608 struct torture_context
*tctx
,
609 struct policy_handle
*handle
,
610 struct lsa_SidArray
*sids
)
612 struct lsa_LookupSids2 r
;
613 struct lsa_TransNameArray2 names
;
614 struct lsa_RefDomainList
*domains
= NULL
;
615 uint32_t count
= sids
->num_sids
;
617 torture_comment(tctx
, "\nTesting LookupSids2\n");
622 r
.in
.handle
= handle
;
627 r
.in
.lookup_options
= 0;
628 r
.in
.client_revision
= 0;
629 r
.out
.count
= &count
;
630 r
.out
.names
= &names
;
631 r
.out
.domains
= &domains
;
633 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupSids2_r(b
, tctx
, &r
),
634 "LookupSids2 failed");
635 if (!NT_STATUS_IS_OK(r
.out
.result
) &&
636 !NT_STATUS_EQUAL(r
.out
.result
, STATUS_SOME_UNMAPPED
)) {
637 torture_comment(tctx
, "LookupSids2 failed - %s\n",
638 nt_errstr(r
.out
.result
));
642 torture_comment(tctx
, "\n");
644 if (!test_LookupNames2(b
, tctx
, handle
, &names
, false)) {
648 if (!test_LookupNames3(b
, tctx
, handle
, &names
, false)) {
655 static bool test_LookupSids3(struct dcerpc_binding_handle
*b
,
656 struct torture_context
*tctx
,
657 struct lsa_SidArray
*sids
)
659 struct lsa_LookupSids3 r
;
660 struct lsa_TransNameArray2 names
;
661 struct lsa_RefDomainList
*domains
= NULL
;
662 uint32_t count
= sids
->num_sids
;
664 torture_comment(tctx
, "\nTesting LookupSids3\n");
673 r
.in
.lookup_options
= 0;
674 r
.in
.client_revision
= 0;
675 r
.out
.domains
= &domains
;
676 r
.out
.count
= &count
;
677 r
.out
.names
= &names
;
679 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupSids3_r(b
, tctx
, &r
),
680 "LookupSids3 failed");
681 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
682 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_ACCESS_DENIED
) ||
683 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
684 torture_comment(tctx
, "not considering %s to be an error\n",
685 nt_errstr(r
.out
.result
));
688 torture_comment(tctx
, "LookupSids3 failed - %s - not considered an error\n",
689 nt_errstr(r
.out
.result
));
693 torture_comment(tctx
, "\n");
695 if (!test_LookupNames4(b
, tctx
, &names
, false)) {
702 bool test_many_LookupSids(struct dcerpc_pipe
*p
,
703 struct torture_context
*tctx
,
704 struct policy_handle
*handle
)
707 struct lsa_SidArray sids
;
709 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
711 torture_comment(tctx
, "\nTesting LookupSids with lots of SIDs\n");
715 sids
.sids
= talloc_array(tctx
, struct lsa_SidPtr
, sids
.num_sids
);
717 for (i
=0; i
<sids
.num_sids
; i
++) {
718 const char *sidstr
= "S-1-5-32-545";
719 sids
.sids
[i
].sid
= dom_sid_parse_talloc(tctx
, sidstr
);
722 count
= sids
.num_sids
;
725 struct lsa_LookupSids r
;
726 struct lsa_TransNameArray names
;
727 struct lsa_RefDomainList
*domains
= NULL
;
731 r
.in
.handle
= handle
;
735 r
.in
.count
= &names
.count
;
736 r
.out
.count
= &count
;
737 r
.out
.names
= &names
;
738 r
.out
.domains
= &domains
;
740 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupSids_r(b
, tctx
, &r
),
741 "LookupSids failed");
742 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
743 torture_comment(tctx
, "LookupSids failed - %s\n",
744 nt_errstr(r
.out
.result
));
748 torture_comment(tctx
, "\n");
750 if (!test_LookupNames(b
, tctx
, handle
, &names
)) {
753 } else if (p
->conn
->security_state
.auth_info
->auth_type
== DCERPC_AUTH_TYPE_SCHANNEL
&&
754 p
->conn
->security_state
.auth_info
->auth_level
>= DCERPC_AUTH_LEVEL_INTEGRITY
) {
755 struct lsa_LookupSids3 r
;
756 struct lsa_RefDomainList
*domains
= NULL
;
757 struct lsa_TransNameArray2 names
;
762 torture_comment(tctx
, "\nTesting LookupSids3\n");
768 r
.in
.lookup_options
= 0;
769 r
.in
.client_revision
= 0;
770 r
.out
.count
= &count
;
771 r
.out
.names
= &names
;
772 r
.out
.domains
= &domains
;
774 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupSids3_r(b
, tctx
, &r
),
775 "LookupSids3 failed");
776 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
777 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_ACCESS_DENIED
) ||
778 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
779 torture_comment(tctx
, "not considering %s to be an error\n",
780 nt_errstr(r
.out
.result
));
783 torture_comment(tctx
, "LookupSids3 failed - %s\n",
784 nt_errstr(r
.out
.result
));
787 if (!test_LookupNames4(b
, tctx
, &names
, false)) {
792 torture_comment(tctx
, "\n");
799 static void lookupsids_cb(struct tevent_req
*subreq
)
801 int *replies
= (int *)tevent_req_callback_data_void(subreq
);
804 status
= dcerpc_lsa_LookupSids_r_recv(subreq
, subreq
);
806 if (!NT_STATUS_IS_OK(status
)) {
807 printf("lookupsids returned %s\n", nt_errstr(status
));
816 static bool test_LookupSids_async(struct dcerpc_binding_handle
*b
,
817 struct torture_context
*tctx
,
818 struct policy_handle
*handle
)
820 struct lsa_SidArray sids
;
821 struct lsa_SidPtr sidptr
;
823 struct lsa_TransNameArray
*names
;
824 struct lsa_LookupSids
*r
;
825 struct lsa_RefDomainList
*domains
= NULL
;
826 struct tevent_req
**req
;
829 const int num_async_requests
= 50;
831 count
= talloc_array(tctx
, uint32_t, num_async_requests
);
832 names
= talloc_array(tctx
, struct lsa_TransNameArray
, num_async_requests
);
833 r
= talloc_array(tctx
, struct lsa_LookupSids
, num_async_requests
);
835 torture_comment(tctx
, "\nTesting %d async lookupsids request\n", num_async_requests
);
837 req
= talloc_array(tctx
, struct tevent_req
*, num_async_requests
);
841 sidptr
.sid
= dom_sid_parse_talloc(tctx
, "S-1-5-32-545");
845 for (i
=0; i
<num_async_requests
; i
++) {
848 names
[i
].names
= NULL
;
850 r
[i
].in
.handle
= handle
;
851 r
[i
].in
.sids
= &sids
;
852 r
[i
].in
.names
= &names
[i
];
854 r
[i
].in
.count
= &names
[i
].count
;
855 r
[i
].out
.count
= &count
[i
];
856 r
[i
].out
.names
= &names
[i
];
857 r
[i
].out
.domains
= &domains
;
859 req
[i
] = dcerpc_lsa_LookupSids_r_send(tctx
, tctx
->ev
, b
, &r
[i
]);
860 if (req
[i
] == NULL
) {
865 tevent_req_set_callback(req
[i
], lookupsids_cb
, &replies
);
868 while (replies
>= 0 && replies
< num_async_requests
) {
869 event_loop_once(tctx
->ev
);
881 static bool test_LookupPrivValue(struct dcerpc_binding_handle
*b
,
882 struct torture_context
*tctx
,
883 struct policy_handle
*handle
,
884 struct lsa_String
*name
)
886 struct lsa_LookupPrivValue r
;
887 struct lsa_LUID luid
;
889 r
.in
.handle
= handle
;
893 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupPrivValue_r(b
, tctx
, &r
),
894 "LookupPrivValue failed");
895 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
896 torture_comment(tctx
, "\nLookupPrivValue failed - %s\n",
897 nt_errstr(r
.out
.result
));
904 static bool test_LookupPrivName(struct dcerpc_binding_handle
*b
,
905 struct torture_context
*tctx
,
906 struct policy_handle
*handle
,
907 struct lsa_LUID
*luid
)
909 struct lsa_LookupPrivName r
;
910 struct lsa_StringLarge
*name
= NULL
;
912 r
.in
.handle
= handle
;
916 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupPrivName_r(b
, tctx
, &r
),
917 "LookupPrivName failed");
918 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
919 torture_comment(tctx
, "\nLookupPrivName failed - %s\n",
920 nt_errstr(r
.out
.result
));
927 static bool test_RemovePrivilegesFromAccount(struct dcerpc_binding_handle
*b
,
928 struct torture_context
*tctx
,
929 struct policy_handle
*handle
,
930 struct policy_handle
*acct_handle
,
931 struct lsa_LUID
*luid
)
933 struct lsa_RemovePrivilegesFromAccount r
;
934 struct lsa_PrivilegeSet privs
;
937 torture_comment(tctx
, "\nTesting RemovePrivilegesFromAccount\n");
939 r
.in
.handle
= acct_handle
;
945 privs
.set
= talloc_array(tctx
, struct lsa_LUIDAttribute
, 1);
946 privs
.set
[0].luid
= *luid
;
947 privs
.set
[0].attribute
= 0;
949 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_RemovePrivilegesFromAccount_r(b
, tctx
, &r
),
950 "RemovePrivilegesFromAccount failed");
951 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
953 struct lsa_LookupPrivName r_name
;
954 struct lsa_StringLarge
*name
= NULL
;
956 r_name
.in
.handle
= handle
;
957 r_name
.in
.luid
= luid
;
958 r_name
.out
.name
= &name
;
960 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupPrivName_r(b
, tctx
, &r_name
),
961 "LookupPrivName failed");
962 if (!NT_STATUS_IS_OK(r_name
.out
.result
)) {
963 torture_comment(tctx
, "\nLookupPrivName failed - %s\n",
964 nt_errstr(r_name
.out
.result
));
967 /* Windows 2008 does not allow this to be removed */
968 if (strcmp("SeAuditPrivilege", name
->string
) == 0) {
972 torture_comment(tctx
, "RemovePrivilegesFromAccount failed to remove %s - %s\n",
974 nt_errstr(r
.out
.result
));
981 static bool test_AddPrivilegesToAccount(struct dcerpc_binding_handle
*b
,
982 struct torture_context
*tctx
,
983 struct policy_handle
*acct_handle
,
984 struct lsa_LUID
*luid
)
986 struct lsa_AddPrivilegesToAccount r
;
987 struct lsa_PrivilegeSet privs
;
990 torture_comment(tctx
, "\nTesting AddPrivilegesToAccount\n");
992 r
.in
.handle
= acct_handle
;
997 privs
.set
= talloc_array(tctx
, struct lsa_LUIDAttribute
, 1);
998 privs
.set
[0].luid
= *luid
;
999 privs
.set
[0].attribute
= 0;
1001 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_AddPrivilegesToAccount_r(b
, tctx
, &r
),
1002 "AddPrivilegesToAccount failed");
1003 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1004 torture_comment(tctx
, "AddPrivilegesToAccount failed - %s\n",
1005 nt_errstr(r
.out
.result
));
1012 static bool test_EnumPrivsAccount(struct dcerpc_binding_handle
*b
,
1013 struct torture_context
*tctx
,
1014 struct policy_handle
*handle
,
1015 struct policy_handle
*acct_handle
)
1017 struct lsa_EnumPrivsAccount r
;
1018 struct lsa_PrivilegeSet
*privs
= NULL
;
1021 torture_comment(tctx
, "\nTesting EnumPrivsAccount\n");
1023 r
.in
.handle
= acct_handle
;
1024 r
.out
.privs
= &privs
;
1026 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumPrivsAccount_r(b
, tctx
, &r
),
1027 "EnumPrivsAccount failed");
1028 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1029 torture_comment(tctx
, "EnumPrivsAccount failed - %s\n",
1030 nt_errstr(r
.out
.result
));
1034 if (privs
&& privs
->count
> 0) {
1036 for (i
=0;i
<privs
->count
;i
++) {
1037 test_LookupPrivName(b
, tctx
, handle
,
1038 &privs
->set
[i
].luid
);
1041 ret
&= test_RemovePrivilegesFromAccount(b
, tctx
, handle
, acct_handle
,
1042 &privs
->set
[0].luid
);
1043 ret
&= test_AddPrivilegesToAccount(b
, tctx
, acct_handle
,
1044 &privs
->set
[0].luid
);
1050 static bool test_GetSystemAccessAccount(struct dcerpc_binding_handle
*b
,
1051 struct torture_context
*tctx
,
1052 struct policy_handle
*handle
,
1053 struct policy_handle
*acct_handle
)
1055 uint32_t access_mask
;
1056 struct lsa_GetSystemAccessAccount r
;
1058 torture_comment(tctx
, "\nTesting GetSystemAccessAccount\n");
1060 r
.in
.handle
= acct_handle
;
1061 r
.out
.access_mask
= &access_mask
;
1063 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_GetSystemAccessAccount_r(b
, tctx
, &r
),
1064 "GetSystemAccessAccount failed");
1065 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1066 torture_comment(tctx
, "GetSystemAccessAccount failed - %s\n",
1067 nt_errstr(r
.out
.result
));
1071 if (r
.out
.access_mask
!= NULL
) {
1072 torture_comment(tctx
, "Rights:");
1073 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_INTERACTIVE
)
1074 torture_comment(tctx
, " LSA_POLICY_MODE_INTERACTIVE");
1075 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_NETWORK
)
1076 torture_comment(tctx
, " LSA_POLICY_MODE_NETWORK");
1077 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_BATCH
)
1078 torture_comment(tctx
, " LSA_POLICY_MODE_BATCH");
1079 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_SERVICE
)
1080 torture_comment(tctx
, " LSA_POLICY_MODE_SERVICE");
1081 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_PROXY
)
1082 torture_comment(tctx
, " LSA_POLICY_MODE_PROXY");
1083 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_INTERACTIVE
)
1084 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_INTERACTIVE");
1085 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_NETWORK
)
1086 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_NETWORK");
1087 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_BATCH
)
1088 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_BATCH");
1089 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_SERVICE
)
1090 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_SERVICE");
1091 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_REMOTE_INTERACTIVE
)
1092 torture_comment(tctx
, " LSA_POLICY_MODE_REMOTE_INTERACTIVE");
1093 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_REMOTE_INTERACTIVE
)
1094 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_REMOTE_INTERACTIVE");
1095 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_ALL
)
1096 torture_comment(tctx
, " LSA_POLICY_MODE_ALL");
1097 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_ALL_NT4
)
1098 torture_comment(tctx
, " LSA_POLICY_MODE_ALL_NT4");
1099 torture_comment(tctx
, "\n");
1105 static bool test_Delete(struct dcerpc_binding_handle
*b
,
1106 struct torture_context
*tctx
,
1107 struct policy_handle
*handle
)
1109 struct lsa_Delete r
;
1111 torture_comment(tctx
, "\nTesting Delete\n");
1113 r
.in
.handle
= handle
;
1114 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_Delete_r(b
, tctx
, &r
),
1116 if (!NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NOT_SUPPORTED
)) {
1117 torture_comment(tctx
, "Delete should have failed NT_STATUS_NOT_SUPPORTED - %s\n", nt_errstr(r
.out
.result
));
1124 static bool test_DeleteObject(struct dcerpc_binding_handle
*b
,
1125 struct torture_context
*tctx
,
1126 struct policy_handle
*handle
)
1128 struct lsa_DeleteObject r
;
1130 torture_comment(tctx
, "\nTesting DeleteObject\n");
1132 r
.in
.handle
= handle
;
1133 r
.out
.handle
= handle
;
1134 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_DeleteObject_r(b
, tctx
, &r
),
1135 "DeleteObject failed");
1136 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1137 torture_comment(tctx
, "DeleteObject failed - %s\n",
1138 nt_errstr(r
.out
.result
));
1146 static bool test_CreateAccount(struct dcerpc_binding_handle
*b
,
1147 struct torture_context
*tctx
,
1148 struct policy_handle
*handle
)
1150 struct lsa_CreateAccount r
;
1151 struct dom_sid2
*newsid
;
1152 struct policy_handle acct_handle
;
1154 newsid
= dom_sid_parse_talloc(tctx
, "S-1-5-12349876-4321-2854");
1156 torture_comment(tctx
, "\nTesting CreateAccount\n");
1158 r
.in
.handle
= handle
;
1160 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1161 r
.out
.acct_handle
= &acct_handle
;
1163 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateAccount_r(b
, tctx
, &r
),
1164 "CreateAccount failed");
1165 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
1166 struct lsa_OpenAccount r_o
;
1167 r_o
.in
.handle
= handle
;
1168 r_o
.in
.sid
= newsid
;
1169 r_o
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1170 r_o
.out
.acct_handle
= &acct_handle
;
1172 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenAccount_r(b
, tctx
, &r_o
),
1173 "OpenAccount failed");
1174 if (!NT_STATUS_IS_OK(r_o
.out
.result
)) {
1175 torture_comment(tctx
, "OpenAccount failed - %s\n",
1176 nt_errstr(r_o
.out
.result
));
1179 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1180 torture_comment(tctx
, "CreateAccount failed - %s\n",
1181 nt_errstr(r
.out
.result
));
1185 if (!test_Delete(b
, tctx
, &acct_handle
)) {
1189 if (!test_DeleteObject(b
, tctx
, &acct_handle
)) {
1196 static bool test_DeleteTrustedDomain(struct dcerpc_binding_handle
*b
,
1197 struct torture_context
*tctx
,
1198 struct policy_handle
*handle
,
1199 struct lsa_StringLarge name
)
1201 struct lsa_OpenTrustedDomainByName r
;
1202 struct policy_handle trustdom_handle
;
1204 r
.in
.handle
= handle
;
1205 r
.in
.name
.string
= name
.string
;
1206 r
.in
.access_mask
= SEC_STD_DELETE
;
1207 r
.out
.trustdom_handle
= &trustdom_handle
;
1209 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenTrustedDomainByName_r(b
, tctx
, &r
),
1210 "OpenTrustedDomainByName failed");
1211 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1212 torture_comment(tctx
, "OpenTrustedDomainByName failed - %s\n", nt_errstr(r
.out
.result
));
1216 if (!test_Delete(b
, tctx
, &trustdom_handle
)) {
1220 if (!test_DeleteObject(b
, tctx
, &trustdom_handle
)) {
1227 static bool test_DeleteTrustedDomainBySid(struct dcerpc_binding_handle
*b
,
1228 struct torture_context
*tctx
,
1229 struct policy_handle
*handle
,
1230 struct dom_sid
*sid
)
1232 struct lsa_DeleteTrustedDomain r
;
1234 r
.in
.handle
= handle
;
1237 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_DeleteTrustedDomain_r(b
, tctx
, &r
),
1238 "DeleteTrustedDomain failed");
1239 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1240 torture_comment(tctx
, "DeleteTrustedDomain failed - %s\n", nt_errstr(r
.out
.result
));
1248 static bool test_CreateSecret(struct dcerpc_pipe
*p
,
1249 struct torture_context
*tctx
,
1250 struct policy_handle
*handle
)
1253 struct lsa_CreateSecret r
;
1254 struct lsa_OpenSecret r2
;
1255 struct lsa_SetSecret r3
;
1256 struct lsa_QuerySecret r4
;
1257 struct lsa_SetSecret r5
;
1258 struct lsa_QuerySecret r6
;
1259 struct lsa_SetSecret r7
;
1260 struct lsa_QuerySecret r8
;
1261 struct policy_handle sec_handle
, sec_handle2
, sec_handle3
;
1262 struct lsa_DeleteObject d_o
;
1263 struct lsa_DATA_BUF buf1
;
1264 struct lsa_DATA_BUF_PTR bufp1
;
1265 struct lsa_DATA_BUF_PTR bufp2
;
1268 DATA_BLOB session_key
;
1269 NTTIME old_mtime
, new_mtime
;
1270 DATA_BLOB blob1
, blob2
;
1271 const char *secret1
= "abcdef12345699qwerty";
1273 const char *secret3
= "ABCDEF12345699QWERTY";
1275 const char *secret5
= "NEW-SAMBA4-SECRET";
1279 const int LOCAL
= 0;
1280 const int GLOBAL
= 1;
1281 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
1283 secname
[LOCAL
] = talloc_asprintf(tctx
, "torturesecret-%u", (unsigned int)random());
1284 secname
[GLOBAL
] = talloc_asprintf(tctx
, "G$torturesecret-%u", (unsigned int)random());
1286 for (i
=0; i
< 2; i
++) {
1287 torture_comment(tctx
, "\nTesting CreateSecret of %s\n", secname
[i
]);
1289 init_lsa_String(&r
.in
.name
, secname
[i
]);
1291 r
.in
.handle
= handle
;
1292 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1293 r
.out
.sec_handle
= &sec_handle
;
1295 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateSecret_r(b
, tctx
, &r
),
1296 "CreateSecret failed");
1297 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1298 torture_comment(tctx
, "CreateSecret failed - %s\n", nt_errstr(r
.out
.result
));
1302 r
.in
.handle
= handle
;
1303 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1304 r
.out
.sec_handle
= &sec_handle3
;
1306 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateSecret_r(b
, tctx
, &r
),
1307 "CreateSecret failed");
1308 if (!NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
1309 torture_comment(tctx
, "CreateSecret should have failed OBJECT_NAME_COLLISION - %s\n", nt_errstr(r
.out
.result
));
1313 r2
.in
.handle
= handle
;
1314 r2
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1315 r2
.in
.name
= r
.in
.name
;
1316 r2
.out
.sec_handle
= &sec_handle2
;
1318 torture_comment(tctx
, "Testing OpenSecret\n");
1320 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenSecret_r(b
, tctx
, &r2
),
1321 "OpenSecret failed");
1322 if (!NT_STATUS_IS_OK(r2
.out
.result
)) {
1323 torture_comment(tctx
, "OpenSecret failed - %s\n", nt_errstr(r2
.out
.result
));
1327 status
= dcerpc_fetch_session_key(p
, &session_key
);
1328 if (!NT_STATUS_IS_OK(status
)) {
1329 torture_comment(tctx
, "dcerpc_fetch_session_key failed - %s\n", nt_errstr(status
));
1333 enc_key
= sess_encrypt_string(secret1
, &session_key
);
1335 r3
.in
.sec_handle
= &sec_handle
;
1336 r3
.in
.new_val
= &buf1
;
1337 r3
.in
.old_val
= NULL
;
1338 r3
.in
.new_val
->data
= enc_key
.data
;
1339 r3
.in
.new_val
->length
= enc_key
.length
;
1340 r3
.in
.new_val
->size
= enc_key
.length
;
1342 torture_comment(tctx
, "Testing SetSecret\n");
1344 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_SetSecret_r(b
, tctx
, &r3
),
1345 "SetSecret failed");
1346 if (!NT_STATUS_IS_OK(r3
.out
.result
)) {
1347 torture_comment(tctx
, "SetSecret failed - %s\n", nt_errstr(r3
.out
.result
));
1351 r3
.in
.sec_handle
= &sec_handle
;
1352 r3
.in
.new_val
= &buf1
;
1353 r3
.in
.old_val
= NULL
;
1354 r3
.in
.new_val
->data
= enc_key
.data
;
1355 r3
.in
.new_val
->length
= enc_key
.length
;
1356 r3
.in
.new_val
->size
= enc_key
.length
;
1358 /* break the encrypted data */
1361 torture_comment(tctx
, "Testing SetSecret with broken key\n");
1363 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_SetSecret_r(b
, tctx
, &r3
),
1364 "SetSecret failed");
1365 if (!NT_STATUS_EQUAL(r3
.out
.result
, NT_STATUS_UNKNOWN_REVISION
)) {
1366 torture_comment(tctx
, "SetSecret should have failed UNKNOWN_REVISION - %s\n", nt_errstr(r3
.out
.result
));
1370 data_blob_free(&enc_key
);
1372 ZERO_STRUCT(new_mtime
);
1373 ZERO_STRUCT(old_mtime
);
1375 /* fetch the secret back again */
1376 r4
.in
.sec_handle
= &sec_handle
;
1377 r4
.in
.new_val
= &bufp1
;
1378 r4
.in
.new_mtime
= &new_mtime
;
1379 r4
.in
.old_val
= NULL
;
1380 r4
.in
.old_mtime
= NULL
;
1384 torture_comment(tctx
, "Testing QuerySecret\n");
1385 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QuerySecret_r(b
, tctx
, &r4
),
1386 "QuerySecret failed");
1387 if (!NT_STATUS_IS_OK(r4
.out
.result
)) {
1388 torture_comment(tctx
, "QuerySecret failed - %s\n", nt_errstr(r4
.out
.result
));
1391 if (r4
.out
.new_val
== NULL
|| r4
.out
.new_val
->buf
== NULL
) {
1392 torture_comment(tctx
, "No secret buffer returned\n");
1395 blob1
.data
= r4
.out
.new_val
->buf
->data
;
1396 blob1
.length
= r4
.out
.new_val
->buf
->size
;
1398 blob2
= data_blob_talloc(tctx
, NULL
, blob1
.length
);
1400 secret2
= sess_decrypt_string(tctx
,
1401 &blob1
, &session_key
);
1403 if (strcmp(secret1
, secret2
) != 0) {
1404 torture_comment(tctx
, "Returned secret (r4) '%s' doesn't match '%s'\n",
1411 enc_key
= sess_encrypt_string(secret3
, &session_key
);
1413 r5
.in
.sec_handle
= &sec_handle
;
1414 r5
.in
.new_val
= &buf1
;
1415 r5
.in
.old_val
= NULL
;
1416 r5
.in
.new_val
->data
= enc_key
.data
;
1417 r5
.in
.new_val
->length
= enc_key
.length
;
1418 r5
.in
.new_val
->size
= enc_key
.length
;
1422 torture_comment(tctx
, "Testing SetSecret (existing value should move to old)\n");
1424 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_SetSecret_r(b
, tctx
, &r5
),
1425 "SetSecret failed");
1426 if (!NT_STATUS_IS_OK(r5
.out
.result
)) {
1427 torture_comment(tctx
, "SetSecret failed - %s\n", nt_errstr(r5
.out
.result
));
1431 data_blob_free(&enc_key
);
1433 ZERO_STRUCT(new_mtime
);
1434 ZERO_STRUCT(old_mtime
);
1436 /* fetch the secret back again */
1437 r6
.in
.sec_handle
= &sec_handle
;
1438 r6
.in
.new_val
= &bufp1
;
1439 r6
.in
.new_mtime
= &new_mtime
;
1440 r6
.in
.old_val
= &bufp2
;
1441 r6
.in
.old_mtime
= &old_mtime
;
1446 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QuerySecret_r(b
, tctx
, &r6
),
1447 "QuerySecret failed");
1448 if (!NT_STATUS_IS_OK(r6
.out
.result
)) {
1449 torture_comment(tctx
, "QuerySecret failed - %s\n", nt_errstr(r6
.out
.result
));
1454 if (r6
.out
.new_val
->buf
== NULL
|| r6
.out
.old_val
->buf
== NULL
1455 || r6
.out
.new_mtime
== NULL
|| r6
.out
.old_mtime
== NULL
) {
1456 torture_comment(tctx
, "Both secret buffers and both times not returned\n");
1460 blob1
.data
= r6
.out
.new_val
->buf
->data
;
1461 blob1
.length
= r6
.out
.new_val
->buf
->size
;
1463 blob2
= data_blob_talloc(tctx
, NULL
, blob1
.length
);
1465 secret4
= sess_decrypt_string(tctx
,
1466 &blob1
, &session_key
);
1468 if (strcmp(secret3
, secret4
) != 0) {
1469 torture_comment(tctx
, "Returned NEW secret %s doesn't match %s\n", secret4
, secret3
);
1473 blob1
.data
= r6
.out
.old_val
->buf
->data
;
1474 blob1
.length
= r6
.out
.old_val
->buf
->length
;
1476 blob2
= data_blob_talloc(tctx
, NULL
, blob1
.length
);
1478 secret2
= sess_decrypt_string(tctx
,
1479 &blob1
, &session_key
);
1481 if (strcmp(secret1
, secret2
) != 0) {
1482 torture_comment(tctx
, "Returned OLD secret %s doesn't match %s\n", secret2
, secret1
);
1486 if (*r6
.out
.new_mtime
== *r6
.out
.old_mtime
) {
1487 torture_comment(tctx
, "Returned secret (r6-%d) %s must not have same mtime for both secrets: %s != %s\n",
1490 nt_time_string(tctx
, *r6
.out
.old_mtime
),
1491 nt_time_string(tctx
, *r6
.out
.new_mtime
));
1497 enc_key
= sess_encrypt_string(secret5
, &session_key
);
1499 r7
.in
.sec_handle
= &sec_handle
;
1500 r7
.in
.old_val
= &buf1
;
1501 r7
.in
.old_val
->data
= enc_key
.data
;
1502 r7
.in
.old_val
->length
= enc_key
.length
;
1503 r7
.in
.old_val
->size
= enc_key
.length
;
1504 r7
.in
.new_val
= NULL
;
1506 torture_comment(tctx
, "Testing SetSecret of old Secret only\n");
1508 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_SetSecret_r(b
, tctx
, &r7
),
1509 "SetSecret failed");
1510 if (!NT_STATUS_IS_OK(r7
.out
.result
)) {
1511 torture_comment(tctx
, "SetSecret failed - %s\n", nt_errstr(r7
.out
.result
));
1515 data_blob_free(&enc_key
);
1517 /* fetch the secret back again */
1518 r8
.in
.sec_handle
= &sec_handle
;
1519 r8
.in
.new_val
= &bufp1
;
1520 r8
.in
.new_mtime
= &new_mtime
;
1521 r8
.in
.old_val
= &bufp2
;
1522 r8
.in
.old_mtime
= &old_mtime
;
1527 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QuerySecret_r(b
, tctx
, &r8
),
1528 "QuerySecret failed");
1529 if (!NT_STATUS_IS_OK(r8
.out
.result
)) {
1530 torture_comment(tctx
, "QuerySecret failed - %s\n", nt_errstr(r8
.out
.result
));
1533 if (!r8
.out
.new_val
|| !r8
.out
.old_val
) {
1534 torture_comment(tctx
, "in/out pointers not returned, despite being set on in for QuerySecret\n");
1536 } else if (r8
.out
.new_val
->buf
!= NULL
) {
1537 torture_comment(tctx
, "NEW secret buffer must not be returned after OLD set\n");
1539 } else if (r8
.out
.old_val
->buf
== NULL
) {
1540 torture_comment(tctx
, "OLD secret buffer was not returned after OLD set\n");
1542 } else if (r8
.out
.new_mtime
== NULL
|| r8
.out
.old_mtime
== NULL
) {
1543 torture_comment(tctx
, "Both times not returned after OLD set\n");
1546 blob1
.data
= r8
.out
.old_val
->buf
->data
;
1547 blob1
.length
= r8
.out
.old_val
->buf
->size
;
1549 blob2
= data_blob_talloc(tctx
, NULL
, blob1
.length
);
1551 secret6
= sess_decrypt_string(tctx
,
1552 &blob1
, &session_key
);
1554 if (strcmp(secret5
, secret6
) != 0) {
1555 torture_comment(tctx
, "Returned OLD secret %s doesn't match %s\n", secret5
, secret6
);
1559 if (*r8
.out
.new_mtime
!= *r8
.out
.old_mtime
) {
1560 torture_comment(tctx
, "Returned secret (r8) %s did not had same mtime for both secrets: %s != %s\n",
1562 nt_time_string(tctx
, *r8
.out
.old_mtime
),
1563 nt_time_string(tctx
, *r8
.out
.new_mtime
));
1569 if (!test_Delete(b
, tctx
, &sec_handle
)) {
1573 if (!test_DeleteObject(b
, tctx
, &sec_handle
)) {
1577 d_o
.in
.handle
= &sec_handle2
;
1578 d_o
.out
.handle
= &sec_handle2
;
1579 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_DeleteObject_r(b
, tctx
, &d_o
),
1580 "DeleteObject failed");
1581 if (!NT_STATUS_EQUAL(d_o
.out
.result
, NT_STATUS_INVALID_HANDLE
)) {
1582 torture_comment(tctx
, "Second delete expected INVALID_HANDLE - %s\n", nt_errstr(d_o
.out
.result
));
1586 torture_comment(tctx
, "Testing OpenSecret of just-deleted secret\n");
1588 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenSecret_r(b
, tctx
, &r2
),
1589 "OpenSecret failed");
1590 if (!NT_STATUS_EQUAL(r2
.out
.result
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
1591 torture_comment(tctx
, "OpenSecret expected OBJECT_NAME_NOT_FOUND - %s\n", nt_errstr(r2
.out
.result
));
1602 static bool test_EnumAccountRights(struct dcerpc_binding_handle
*b
,
1603 struct torture_context
*tctx
,
1604 struct policy_handle
*acct_handle
,
1605 struct dom_sid
*sid
)
1607 struct lsa_EnumAccountRights r
;
1608 struct lsa_RightSet rights
;
1610 torture_comment(tctx
, "\nTesting EnumAccountRights\n");
1612 r
.in
.handle
= acct_handle
;
1614 r
.out
.rights
= &rights
;
1616 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumAccountRights_r(b
, tctx
, &r
),
1617 "EnumAccountRights failed");
1618 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1619 torture_comment(tctx
, "EnumAccountRights of %s failed - %s\n",
1620 dom_sid_string(tctx
, sid
), nt_errstr(r
.out
.result
));
1628 static bool test_QuerySecurity(struct dcerpc_binding_handle
*b
,
1629 struct torture_context
*tctx
,
1630 struct policy_handle
*handle
,
1631 struct policy_handle
*acct_handle
)
1633 struct lsa_QuerySecurity r
;
1634 struct sec_desc_buf
*sdbuf
= NULL
;
1636 if (torture_setting_bool(tctx
, "samba4", false)) {
1637 torture_comment(tctx
, "\nskipping QuerySecurity test against Samba4\n");
1641 torture_comment(tctx
, "\nTesting QuerySecurity\n");
1643 r
.in
.handle
= acct_handle
;
1644 r
.in
.sec_info
= SECINFO_OWNER
|
1647 r
.out
.sdbuf
= &sdbuf
;
1649 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QuerySecurity_r(b
, tctx
, &r
),
1650 "QuerySecurity failed");
1651 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1652 torture_comment(tctx
, "QuerySecurity failed - %s\n", nt_errstr(r
.out
.result
));
1659 static bool test_OpenAccount(struct dcerpc_binding_handle
*b
,
1660 struct torture_context
*tctx
,
1661 struct policy_handle
*handle
,
1662 struct dom_sid
*sid
)
1664 struct lsa_OpenAccount r
;
1665 struct policy_handle acct_handle
;
1667 torture_comment(tctx
, "\nTesting OpenAccount\n");
1669 r
.in
.handle
= handle
;
1671 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1672 r
.out
.acct_handle
= &acct_handle
;
1674 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenAccount_r(b
, tctx
, &r
),
1675 "OpenAccount failed");
1676 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1677 torture_comment(tctx
, "OpenAccount failed - %s\n", nt_errstr(r
.out
.result
));
1681 if (!test_EnumPrivsAccount(b
, tctx
, handle
, &acct_handle
)) {
1685 if (!test_GetSystemAccessAccount(b
, tctx
, handle
, &acct_handle
)) {
1689 if (!test_QuerySecurity(b
, tctx
, handle
, &acct_handle
)) {
1696 static bool test_EnumAccounts(struct dcerpc_binding_handle
*b
,
1697 struct torture_context
*tctx
,
1698 struct policy_handle
*handle
)
1700 struct lsa_EnumAccounts r
;
1701 struct lsa_SidArray sids1
, sids2
;
1702 uint32_t resume_handle
= 0;
1706 torture_comment(tctx
, "\nTesting EnumAccounts\n");
1708 r
.in
.handle
= handle
;
1709 r
.in
.resume_handle
= &resume_handle
;
1710 r
.in
.num_entries
= 100;
1711 r
.out
.resume_handle
= &resume_handle
;
1712 r
.out
.sids
= &sids1
;
1716 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumAccounts_r(b
, tctx
, &r
),
1717 "EnumAccounts failed");
1718 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
)) {
1721 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1722 torture_comment(tctx
, "EnumAccounts failed - %s\n", nt_errstr(r
.out
.result
));
1726 if (!test_LookupSids(b
, tctx
, handle
, &sids1
)) {
1730 if (!test_LookupSids2(b
, tctx
, handle
, &sids1
)) {
1734 /* Can't test lookupSids3 here, as clearly we must not
1735 * be on schannel, or we would not be able to do the
1738 torture_comment(tctx
, "Testing all accounts\n");
1739 for (i
=0;i
<sids1
.num_sids
;i
++) {
1740 ret
&= test_OpenAccount(b
, tctx
, handle
, sids1
.sids
[i
].sid
);
1741 ret
&= test_EnumAccountRights(b
, tctx
, handle
, sids1
.sids
[i
].sid
);
1743 torture_comment(tctx
, "\n");
1746 if (sids1
.num_sids
< 3) {
1750 torture_comment(tctx
, "Trying EnumAccounts partial listing (asking for 1 at 2)\n");
1752 r
.in
.num_entries
= 1;
1753 r
.out
.sids
= &sids2
;
1755 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumAccounts_r(b
, tctx
, &r
),
1756 "EnumAccounts failed");
1757 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1758 torture_comment(tctx
, "EnumAccounts failed - %s\n", nt_errstr(r
.out
.result
));
1762 if (sids2
.num_sids
!= 1) {
1763 torture_comment(tctx
, "Returned wrong number of entries (%d)\n", sids2
.num_sids
);
1770 static bool test_LookupPrivDisplayName(struct dcerpc_binding_handle
*b
,
1771 struct torture_context
*tctx
,
1772 struct policy_handle
*handle
,
1773 struct lsa_String
*priv_name
)
1775 struct lsa_LookupPrivDisplayName r
;
1776 /* produce a reasonable range of language output without screwing up
1778 uint16_t language_id
= (random() % 4) + 0x409;
1779 uint16_t returned_language_id
= 0;
1780 struct lsa_StringLarge
*disp_name
= NULL
;
1782 torture_comment(tctx
, "\nTesting LookupPrivDisplayName(%s)\n", priv_name
->string
);
1784 r
.in
.handle
= handle
;
1785 r
.in
.name
= priv_name
;
1786 r
.in
.language_id
= language_id
;
1787 r
.in
.language_id_sys
= 0;
1788 r
.out
.returned_language_id
= &returned_language_id
;
1789 r
.out
.disp_name
= &disp_name
;
1791 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupPrivDisplayName_r(b
, tctx
, &r
),
1792 "LookupPrivDisplayName failed");
1793 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1794 torture_comment(tctx
, "LookupPrivDisplayName failed - %s\n", nt_errstr(r
.out
.result
));
1797 torture_comment(tctx
, "%s -> \"%s\" (language 0x%x/0x%x)\n",
1798 priv_name
->string
, disp_name
->string
,
1799 r
.in
.language_id
, *r
.out
.returned_language_id
);
1804 static bool test_EnumAccountsWithUserRight(struct dcerpc_binding_handle
*b
,
1805 struct torture_context
*tctx
,
1806 struct policy_handle
*handle
,
1807 struct lsa_String
*priv_name
)
1809 struct lsa_EnumAccountsWithUserRight r
;
1810 struct lsa_SidArray sids
;
1814 torture_comment(tctx
, "\nTesting EnumAccountsWithUserRight(%s)\n", priv_name
->string
);
1816 r
.in
.handle
= handle
;
1817 r
.in
.name
= priv_name
;
1820 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumAccountsWithUserRight_r(b
, tctx
, &r
),
1821 "EnumAccountsWithUserRight failed");
1823 /* NT_STATUS_NO_MORE_ENTRIES means noone has this privilege */
1824 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
)) {
1828 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1829 torture_comment(tctx
, "EnumAccountsWithUserRight failed - %s\n", nt_errstr(r
.out
.result
));
1837 static bool test_EnumPrivs(struct dcerpc_binding_handle
*b
,
1838 struct torture_context
*tctx
,
1839 struct policy_handle
*handle
)
1841 struct lsa_EnumPrivs r
;
1842 struct lsa_PrivArray privs1
;
1843 uint32_t resume_handle
= 0;
1847 torture_comment(tctx
, "\nTesting EnumPrivs\n");
1849 r
.in
.handle
= handle
;
1850 r
.in
.resume_handle
= &resume_handle
;
1851 r
.in
.max_count
= 100;
1852 r
.out
.resume_handle
= &resume_handle
;
1853 r
.out
.privs
= &privs1
;
1856 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumPrivs_r(b
, tctx
, &r
),
1857 "EnumPrivs failed");
1858 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1859 torture_comment(tctx
, "EnumPrivs failed - %s\n", nt_errstr(r
.out
.result
));
1863 for (i
= 0; i
< privs1
.count
; i
++) {
1864 test_LookupPrivDisplayName(b
, tctx
, handle
, (struct lsa_String
*)&privs1
.privs
[i
].name
);
1865 test_LookupPrivValue(b
, tctx
, handle
, (struct lsa_String
*)&privs1
.privs
[i
].name
);
1866 if (!test_EnumAccountsWithUserRight(b
, tctx
, handle
, (struct lsa_String
*)&privs1
.privs
[i
].name
)) {
1874 static bool test_QueryForestTrustInformation(struct dcerpc_binding_handle
*b
,
1875 struct torture_context
*tctx
,
1876 struct policy_handle
*handle
,
1877 const char *trusted_domain_name
)
1880 struct lsa_lsaRQueryForestTrustInformation r
;
1881 struct lsa_String string
;
1882 struct lsa_ForestTrustInformation info
, *info_ptr
;
1884 torture_comment(tctx
, "\nTesting lsaRQueryForestTrustInformation\n");
1886 if (torture_setting_bool(tctx
, "samba4", false)) {
1887 torture_comment(tctx
, "skipping QueryForestTrustInformation against Samba4\n");
1891 ZERO_STRUCT(string
);
1893 if (trusted_domain_name
) {
1894 init_lsa_String(&string
, trusted_domain_name
);
1899 r
.in
.handle
= handle
;
1900 r
.in
.trusted_domain_name
= &string
;
1902 r
.out
.forest_trust_info
= &info_ptr
;
1904 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_lsaRQueryForestTrustInformation_r(b
, tctx
, &r
),
1905 "lsaRQueryForestTrustInformation failed");
1907 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
1908 torture_comment(tctx
, "lsaRQueryForestTrustInformation of %s failed - %s\n", trusted_domain_name
, nt_errstr(r
.out
.result
));
1915 static bool test_query_each_TrustDomEx(struct dcerpc_binding_handle
*b
,
1916 struct torture_context
*tctx
,
1917 struct policy_handle
*handle
,
1918 struct lsa_DomainListEx
*domains
)
1923 for (i
=0; i
< domains
->count
; i
++) {
1925 if (domains
->domains
[i
].trust_attributes
& NETR_TRUST_ATTRIBUTE_FOREST_TRANSITIVE
) {
1926 ret
&= test_QueryForestTrustInformation(b
, tctx
, handle
,
1927 domains
->domains
[i
].domain_name
.string
);
1934 static bool test_query_each_TrustDom(struct dcerpc_binding_handle
*b
,
1935 struct torture_context
*tctx
,
1936 struct policy_handle
*handle
,
1937 struct lsa_DomainList
*domains
)
1942 torture_comment(tctx
, "\nTesting OpenTrustedDomain, OpenTrustedDomainByName and QueryInfoTrustedDomain\n");
1943 for (i
=0; i
< domains
->count
; i
++) {
1944 struct lsa_OpenTrustedDomain trust
;
1945 struct lsa_OpenTrustedDomainByName trust_by_name
;
1946 struct policy_handle trustdom_handle
;
1947 struct policy_handle handle2
;
1949 struct lsa_CloseTrustedDomainEx c_trust
;
1950 int levels
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
1951 int ok
[] = {1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1};
1953 if (domains
->domains
[i
].sid
) {
1954 trust
.in
.handle
= handle
;
1955 trust
.in
.sid
= domains
->domains
[i
].sid
;
1956 trust
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1957 trust
.out
.trustdom_handle
= &trustdom_handle
;
1959 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenTrustedDomain_r(b
, tctx
, &trust
),
1960 "OpenTrustedDomain failed");
1962 if (!NT_STATUS_IS_OK(trust
.out
.result
)) {
1963 torture_comment(tctx
, "OpenTrustedDomain failed - %s\n", nt_errstr(trust
.out
.result
));
1967 c
.in
.handle
= &trustdom_handle
;
1968 c
.out
.handle
= &handle2
;
1970 c_trust
.in
.handle
= &trustdom_handle
;
1971 c_trust
.out
.handle
= &handle2
;
1973 for (j
=0; j
< ARRAY_SIZE(levels
); j
++) {
1974 struct lsa_QueryTrustedDomainInfo q
;
1975 union lsa_TrustedDomainInfo
*info
= NULL
;
1976 q
.in
.trustdom_handle
= &trustdom_handle
;
1977 q
.in
.level
= levels
[j
];
1979 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfo_r(b
, tctx
, &q
),
1980 "QueryTrustedDomainInfo failed");
1981 if (!NT_STATUS_IS_OK(q
.out
.result
) && ok
[j
]) {
1982 torture_comment(tctx
, "QueryTrustedDomainInfo level %d failed - %s\n",
1983 levels
[j
], nt_errstr(q
.out
.result
));
1985 } else if (NT_STATUS_IS_OK(q
.out
.result
) && !ok
[j
]) {
1986 torture_comment(tctx
, "QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
1987 levels
[j
], nt_errstr(q
.out
.result
));
1992 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CloseTrustedDomainEx_r(b
, tctx
, &c_trust
),
1993 "CloseTrustedDomainEx failed");
1994 if (!NT_STATUS_EQUAL(c_trust
.out
.result
, NT_STATUS_NOT_IMPLEMENTED
)) {
1995 torture_comment(tctx
, "Expected CloseTrustedDomainEx to return NT_STATUS_NOT_IMPLEMENTED, instead - %s\n", nt_errstr(c_trust
.out
.result
));
1999 c
.in
.handle
= &trustdom_handle
;
2000 c
.out
.handle
= &handle2
;
2002 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_Close_r(b
, tctx
, &c
),
2004 if (!NT_STATUS_IS_OK(c
.out
.result
)) {
2005 torture_comment(tctx
, "Close of trusted domain failed - %s\n", nt_errstr(c
.out
.result
));
2009 for (j
=0; j
< ARRAY_SIZE(levels
); j
++) {
2010 struct lsa_QueryTrustedDomainInfoBySid q
;
2011 union lsa_TrustedDomainInfo
*info
= NULL
;
2013 if (!domains
->domains
[i
].sid
) {
2017 q
.in
.handle
= handle
;
2018 q
.in
.dom_sid
= domains
->domains
[i
].sid
;
2019 q
.in
.level
= levels
[j
];
2022 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfoBySid_r(b
, tctx
, &q
),
2023 "lsa_QueryTrustedDomainInfoBySid failed");
2024 if (!NT_STATUS_IS_OK(q
.out
.result
) && ok
[j
]) {
2025 torture_comment(tctx
, "QueryTrustedDomainInfoBySid level %d failed - %s\n",
2026 levels
[j
], nt_errstr(q
.out
.result
));
2028 } else if (NT_STATUS_IS_OK(q
.out
.result
) && !ok
[j
]) {
2029 torture_comment(tctx
, "QueryTrustedDomainInfoBySid level %d unexpectedly succeeded - %s\n",
2030 levels
[j
], nt_errstr(q
.out
.result
));
2036 trust_by_name
.in
.handle
= handle
;
2037 trust_by_name
.in
.name
.string
= domains
->domains
[i
].name
.string
;
2038 trust_by_name
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2039 trust_by_name
.out
.trustdom_handle
= &trustdom_handle
;
2041 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_OpenTrustedDomainByName_r(b
, tctx
, &trust_by_name
),
2042 "OpenTrustedDomainByName failed");
2044 if (!NT_STATUS_IS_OK(trust_by_name
.out
.result
)) {
2045 torture_comment(tctx
, "OpenTrustedDomainByName failed - %s\n", nt_errstr(trust_by_name
.out
.result
));
2049 for (j
=0; j
< ARRAY_SIZE(levels
); j
++) {
2050 struct lsa_QueryTrustedDomainInfo q
;
2051 union lsa_TrustedDomainInfo
*info
= NULL
;
2052 q
.in
.trustdom_handle
= &trustdom_handle
;
2053 q
.in
.level
= levels
[j
];
2055 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfo_r(b
, tctx
, &q
),
2056 "QueryTrustedDomainInfo failed");
2057 if (!NT_STATUS_IS_OK(q
.out
.result
) && ok
[j
]) {
2058 torture_comment(tctx
, "QueryTrustedDomainInfo level %d failed - %s\n",
2059 levels
[j
], nt_errstr(q
.out
.result
));
2061 } else if (NT_STATUS_IS_OK(q
.out
.result
) && !ok
[j
]) {
2062 torture_comment(tctx
, "QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
2063 levels
[j
], nt_errstr(q
.out
.result
));
2068 c
.in
.handle
= &trustdom_handle
;
2069 c
.out
.handle
= &handle2
;
2071 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_Close_r(b
, tctx
, &c
),
2073 if (!NT_STATUS_IS_OK(c
.out
.result
)) {
2074 torture_comment(tctx
, "Close of trusted domain failed - %s\n", nt_errstr(c
.out
.result
));
2078 for (j
=0; j
< ARRAY_SIZE(levels
); j
++) {
2079 struct lsa_QueryTrustedDomainInfoByName q
;
2080 union lsa_TrustedDomainInfo
*info
= NULL
;
2081 struct lsa_String name
;
2083 name
.string
= domains
->domains
[i
].name
.string
;
2085 q
.in
.handle
= handle
;
2086 q
.in
.trusted_domain
= &name
;
2087 q
.in
.level
= levels
[j
];
2089 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfoByName_r(b
, tctx
, &q
),
2090 "QueryTrustedDomainInfoByName failed");
2091 if (!NT_STATUS_IS_OK(q
.out
.result
) && ok
[j
]) {
2092 torture_comment(tctx
, "QueryTrustedDomainInfoByName level %d failed - %s\n",
2093 levels
[j
], nt_errstr(q
.out
.result
));
2095 } else if (NT_STATUS_IS_OK(q
.out
.result
) && !ok
[j
]) {
2096 torture_comment(tctx
, "QueryTrustedDomainInfoByName level %d unexpectedly succeeded - %s\n",
2097 levels
[j
], nt_errstr(q
.out
.result
));
2105 static bool test_EnumTrustDom(struct dcerpc_binding_handle
*b
,
2106 struct torture_context
*tctx
,
2107 struct policy_handle
*handle
)
2109 struct lsa_EnumTrustDom r
;
2110 uint32_t in_resume_handle
= 0;
2111 uint32_t out_resume_handle
;
2112 struct lsa_DomainList domains
;
2115 torture_comment(tctx
, "\nTesting EnumTrustDom\n");
2117 r
.in
.handle
= handle
;
2118 r
.in
.resume_handle
= &in_resume_handle
;
2120 r
.out
.domains
= &domains
;
2121 r
.out
.resume_handle
= &out_resume_handle
;
2123 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumTrustDom_r(b
, tctx
, &r
),
2124 "lsa_EnumTrustDom failed");
2126 /* according to MS-LSAD 3.1.4.7.8 output resume handle MUST
2127 * always be larger than the previous input resume handle, in
2128 * particular when hitting the last query it is vital to set the
2129 * resume handle correctly to avoid infinite client loops, as
2130 * seen e.g. with Windows XP SP3 when resume handle is 0 and
2131 * status is NT_STATUS_OK - gd */
2133 if (NT_STATUS_IS_OK(r
.out
.result
) ||
2134 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
) ||
2135 NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
))
2137 if (out_resume_handle
<= in_resume_handle
) {
2138 torture_comment(tctx
, "EnumTrustDom failed - should have returned output resume_handle (0x%08x) larger than input resume handle (0x%08x)\n",
2139 out_resume_handle
, in_resume_handle
);
2144 if (NT_STATUS_IS_OK(r
.out
.result
)) {
2145 if (domains
.count
== 0) {
2146 torture_comment(tctx
, "EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2149 } else if (!(NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
) || NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
))) {
2150 torture_comment(tctx
, "EnumTrustDom of zero size failed - %s\n", nt_errstr(r
.out
.result
));
2154 /* Start from the bottom again */
2155 in_resume_handle
= 0;
2158 r
.in
.handle
= handle
;
2159 r
.in
.resume_handle
= &in_resume_handle
;
2160 r
.in
.max_size
= LSA_ENUM_TRUST_DOMAIN_MULTIPLIER
* 3;
2161 r
.out
.domains
= &domains
;
2162 r
.out
.resume_handle
= &out_resume_handle
;
2164 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumTrustDom_r(b
, tctx
, &r
),
2165 "EnumTrustDom failed");
2167 /* according to MS-LSAD 3.1.4.7.8 output resume handle MUST
2168 * always be larger than the previous input resume handle, in
2169 * particular when hitting the last query it is vital to set the
2170 * resume handle correctly to avoid infinite client loops, as
2171 * seen e.g. with Windows XP SP3 when resume handle is 0 and
2172 * status is NT_STATUS_OK - gd */
2174 if (NT_STATUS_IS_OK(r
.out
.result
) ||
2175 NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
) ||
2176 NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
))
2178 if (out_resume_handle
<= in_resume_handle
) {
2179 torture_comment(tctx
, "EnumTrustDom failed - should have returned output resume_handle (0x%08x) larger than input resume handle (0x%08x)\n",
2180 out_resume_handle
, in_resume_handle
);
2185 /* NO_MORE_ENTRIES is allowed */
2186 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
)) {
2187 if (domains
.count
== 0) {
2190 torture_comment(tctx
, "EnumTrustDom failed - should have returned 0 trusted domains with 'NT_STATUS_NO_MORE_ENTRIES'\n");
2192 } else if (NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
)) {
2193 /* Windows 2003 gets this off by one on the first run */
2194 if (r
.out
.domains
->count
< 3 || r
.out
.domains
->count
> 4) {
2195 torture_comment(tctx
, "EnumTrustDom didn't fill the buffer we "
2196 "asked it to (got %d, expected %d / %d == %d entries)\n",
2197 r
.out
.domains
->count
, LSA_ENUM_TRUST_DOMAIN_MULTIPLIER
* 3,
2198 LSA_ENUM_TRUST_DOMAIN_MULTIPLIER
, r
.in
.max_size
);
2201 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2202 torture_comment(tctx
, "EnumTrustDom failed - %s\n", nt_errstr(r
.out
.result
));
2206 if (domains
.count
== 0) {
2207 torture_comment(tctx
, "EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2211 ret
&= test_query_each_TrustDom(b
, tctx
, handle
, &domains
);
2213 in_resume_handle
= out_resume_handle
;
2215 } while ((NT_STATUS_EQUAL(r
.out
.result
, STATUS_MORE_ENTRIES
)));
2220 static bool test_EnumTrustDomEx(struct dcerpc_binding_handle
*b
,
2221 struct torture_context
*tctx
,
2222 struct policy_handle
*handle
)
2224 struct lsa_EnumTrustedDomainsEx r_ex
;
2225 uint32_t resume_handle
= 0;
2226 struct lsa_DomainListEx domains_ex
;
2229 torture_comment(tctx
, "\nTesting EnumTrustedDomainsEx\n");
2231 r_ex
.in
.handle
= handle
;
2232 r_ex
.in
.resume_handle
= &resume_handle
;
2233 r_ex
.in
.max_size
= LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER
* 3;
2234 r_ex
.out
.domains
= &domains_ex
;
2235 r_ex
.out
.resume_handle
= &resume_handle
;
2237 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumTrustedDomainsEx_r(b
, tctx
, &r_ex
),
2238 "EnumTrustedDomainsEx failed");
2240 if (!(NT_STATUS_EQUAL(r_ex
.out
.result
, STATUS_MORE_ENTRIES
) || NT_STATUS_EQUAL(r_ex
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
))) {
2241 torture_comment(tctx
, "EnumTrustedDomainEx of zero size failed - %s\n", nt_errstr(r_ex
.out
.result
));
2247 r_ex
.in
.handle
= handle
;
2248 r_ex
.in
.resume_handle
= &resume_handle
;
2249 r_ex
.in
.max_size
= LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER
* 3;
2250 r_ex
.out
.domains
= &domains_ex
;
2251 r_ex
.out
.resume_handle
= &resume_handle
;
2253 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_EnumTrustedDomainsEx_r(b
, tctx
, &r_ex
),
2254 "EnumTrustedDomainsEx failed");
2256 /* NO_MORE_ENTRIES is allowed */
2257 if (NT_STATUS_EQUAL(r_ex
.out
.result
, NT_STATUS_NO_MORE_ENTRIES
)) {
2258 if (domains_ex
.count
== 0) {
2261 torture_comment(tctx
, "EnumTrustDomainsEx failed - should have returned 0 trusted domains with 'NT_STATUS_NO_MORE_ENTRIES'\n");
2263 } else if (NT_STATUS_EQUAL(r_ex
.out
.result
, STATUS_MORE_ENTRIES
)) {
2264 /* Windows 2003 gets this off by one on the first run */
2265 if (r_ex
.out
.domains
->count
< 3 || r_ex
.out
.domains
->count
> 4) {
2266 torture_comment(tctx
, "EnumTrustDom didn't fill the buffer we "
2267 "asked it to (got %d, expected %d / %d == %d entries)\n",
2268 r_ex
.out
.domains
->count
,
2270 LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER
,
2271 r_ex
.in
.max_size
/ LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER
);
2273 } else if (!NT_STATUS_IS_OK(r_ex
.out
.result
)) {
2274 torture_comment(tctx
, "EnumTrustedDomainEx failed - %s\n", nt_errstr(r_ex
.out
.result
));
2278 if (domains_ex
.count
== 0) {
2279 torture_comment(tctx
, "EnumTrustDomainEx failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2283 ret
&= test_query_each_TrustDomEx(b
, tctx
, handle
, &domains_ex
);
2285 } while ((NT_STATUS_EQUAL(r_ex
.out
.result
, STATUS_MORE_ENTRIES
)));
2291 static bool test_CreateTrustedDomain(struct dcerpc_binding_handle
*b
,
2292 struct torture_context
*tctx
,
2293 struct policy_handle
*handle
,
2294 uint32_t num_trusts
)
2297 struct lsa_CreateTrustedDomain r
;
2298 struct lsa_DomainInfo trustinfo
;
2299 struct dom_sid
**domsid
;
2300 struct policy_handle
*trustdom_handle
;
2301 struct lsa_QueryTrustedDomainInfo q
;
2302 union lsa_TrustedDomainInfo
*info
= NULL
;
2305 torture_comment(tctx
, "\nTesting CreateTrustedDomain for %d domains\n", num_trusts
);
2307 if (!test_EnumTrustDom(b
, tctx
, handle
)) {
2311 if (!test_EnumTrustDomEx(b
, tctx
, handle
)) {
2315 domsid
= talloc_array(tctx
, struct dom_sid
*, num_trusts
);
2316 trustdom_handle
= talloc_array(tctx
, struct policy_handle
, num_trusts
);
2318 for (i
=0; i
< num_trusts
; i
++) {
2319 char *trust_name
= talloc_asprintf(tctx
, "torturedom%02d", i
);
2320 char *trust_sid
= talloc_asprintf(tctx
, "S-1-5-21-97398-379795-100%02d", i
);
2322 domsid
[i
] = dom_sid_parse_talloc(tctx
, trust_sid
);
2324 trustinfo
.sid
= domsid
[i
];
2325 init_lsa_String((struct lsa_String
*)&trustinfo
.name
, trust_name
);
2327 r
.in
.policy_handle
= handle
;
2328 r
.in
.info
= &trustinfo
;
2329 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2330 r
.out
.trustdom_handle
= &trustdom_handle
[i
];
2332 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateTrustedDomain_r(b
, tctx
, &r
),
2333 "CreateTrustedDomain failed");
2334 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
2335 test_DeleteTrustedDomain(b
, tctx
, handle
, trustinfo
.name
);
2336 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateTrustedDomain_r(b
, tctx
, &r
),
2337 "CreateTrustedDomain failed");
2339 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2340 torture_comment(tctx
, "CreateTrustedDomain failed - %s\n", nt_errstr(r
.out
.result
));
2344 q
.in
.trustdom_handle
= &trustdom_handle
[i
];
2345 q
.in
.level
= LSA_TRUSTED_DOMAIN_INFO_INFO_EX
;
2347 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfo_r(b
, tctx
, &q
),
2348 "QueryTrustedDomainInfo failed");
2349 if (!NT_STATUS_IS_OK(q
.out
.result
)) {
2350 torture_comment(tctx
, "QueryTrustedDomainInfo level %d failed - %s\n", q
.in
.level
, nt_errstr(q
.out
.result
));
2352 } else if (!q
.out
.info
) {
2355 if (strcmp(info
->info_ex
.netbios_name
.string
, trustinfo
.name
.string
) != 0) {
2356 torture_comment(tctx
, "QueryTrustedDomainInfo returned inconsistent short name: %s != %s\n",
2357 info
->info_ex
.netbios_name
.string
, trustinfo
.name
.string
);
2360 if (info
->info_ex
.trust_type
!= LSA_TRUST_TYPE_DOWNLEVEL
) {
2361 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
2362 trust_name
, info
->info_ex
.trust_type
, LSA_TRUST_TYPE_DOWNLEVEL
);
2365 if (info
->info_ex
.trust_attributes
!= 0) {
2366 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
2367 trust_name
, info
->info_ex
.trust_attributes
, 0);
2370 if (info
->info_ex
.trust_direction
!= LSA_TRUST_DIRECTION_OUTBOUND
) {
2371 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
2372 trust_name
, info
->info_ex
.trust_direction
, LSA_TRUST_DIRECTION_OUTBOUND
);
2379 /* now that we have some domains to look over, we can test the enum calls */
2380 if (!test_EnumTrustDom(b
, tctx
, handle
)) {
2384 if (!test_EnumTrustDomEx(b
, tctx
, handle
)) {
2388 for (i
=0; i
<num_trusts
; i
++) {
2389 if (!test_DeleteTrustedDomainBySid(b
, tctx
, handle
, domsid
[i
])) {
2397 static bool test_CreateTrustedDomainEx2(struct dcerpc_pipe
*p
,
2398 struct torture_context
*tctx
,
2399 struct policy_handle
*handle
,
2400 uint32_t num_trusts
)
2404 struct lsa_CreateTrustedDomainEx2 r
;
2405 struct lsa_TrustDomainInfoInfoEx trustinfo
;
2406 struct lsa_TrustDomainInfoAuthInfoInternal authinfo
;
2407 struct trustDomainPasswords auth_struct
;
2408 DATA_BLOB auth_blob
;
2409 struct dom_sid
**domsid
;
2410 struct policy_handle
*trustdom_handle
;
2411 struct lsa_QueryTrustedDomainInfo q
;
2412 union lsa_TrustedDomainInfo
*info
= NULL
;
2413 DATA_BLOB session_key
;
2414 enum ndr_err_code ndr_err
;
2416 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
2418 torture_comment(tctx
, "\nTesting CreateTrustedDomainEx2 for %d domains\n", num_trusts
);
2420 domsid
= talloc_array(tctx
, struct dom_sid
*, num_trusts
);
2421 trustdom_handle
= talloc_array(tctx
, struct policy_handle
, num_trusts
);
2423 status
= dcerpc_fetch_session_key(p
, &session_key
);
2424 if (!NT_STATUS_IS_OK(status
)) {
2425 torture_comment(tctx
, "dcerpc_fetch_session_key failed - %s\n", nt_errstr(status
));
2429 for (i
=0; i
< num_trusts
; i
++) {
2430 char *trust_name
= talloc_asprintf(tctx
, "torturedom%02d", i
);
2431 char *trust_name_dns
= talloc_asprintf(tctx
, "torturedom%02d.samba.example.com", i
);
2432 char *trust_sid
= talloc_asprintf(tctx
, "S-1-5-21-97398-379795-100%02d", i
);
2434 domsid
[i
] = dom_sid_parse_talloc(tctx
, trust_sid
);
2436 trustinfo
.sid
= domsid
[i
];
2437 trustinfo
.netbios_name
.string
= trust_name
;
2438 trustinfo
.domain_name
.string
= trust_name_dns
;
2440 /* Create inbound, some outbound, and some
2441 * bi-directional trusts in a repeating pattern based
2444 /* 1 == inbound, 2 == outbound, 3 == both */
2445 trustinfo
.trust_direction
= (i
% 3) + 1;
2447 /* Try different trust types too */
2449 /* 1 == downlevel (NT4), 2 == uplevel (ADS), 3 == MIT (kerberos but not AD) */
2450 trustinfo
.trust_type
= (((i
/ 3) + 1) % 3) + 1;
2452 trustinfo
.trust_attributes
= LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION
;
2454 generate_random_buffer(auth_struct
.confounder
, sizeof(auth_struct
.confounder
));
2456 auth_struct
.outgoing
.count
= 0;
2457 auth_struct
.outgoing
.current
.count
= 0;
2458 auth_struct
.outgoing
.current
.array
= NULL
;
2459 auth_struct
.outgoing
.previous
.count
= 0;
2460 auth_struct
.outgoing
.previous
.array
= NULL
;
2462 auth_struct
.incoming
.count
= 0;
2463 auth_struct
.incoming
.current
.count
= 0;
2464 auth_struct
.incoming
.current
.array
= NULL
;
2465 auth_struct
.incoming
.previous
.count
= 0;
2466 auth_struct
.incoming
.previous
.array
= NULL
;
2469 ndr_err
= ndr_push_struct_blob(&auth_blob
, tctx
, &auth_struct
,
2470 (ndr_push_flags_fn_t
)ndr_push_trustDomainPasswords
);
2471 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2472 torture_comment(tctx
, "ndr_push_struct_blob of trustDomainPasswords structure failed");
2476 arcfour_crypt_blob(auth_blob
.data
, auth_blob
.length
, &session_key
);
2478 authinfo
.auth_blob
.size
= auth_blob
.length
;
2479 authinfo
.auth_blob
.data
= auth_blob
.data
;
2481 r
.in
.policy_handle
= handle
;
2482 r
.in
.info
= &trustinfo
;
2483 r
.in
.auth_info
= &authinfo
;
2484 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2485 r
.out
.trustdom_handle
= &trustdom_handle
[i
];
2487 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateTrustedDomainEx2_r(b
, tctx
, &r
),
2488 "CreateTrustedDomainEx2 failed");
2489 if (NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
2490 test_DeleteTrustedDomain(b
, tctx
, handle
, trustinfo
.netbios_name
);
2491 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_CreateTrustedDomainEx2_r(b
, tctx
, &r
),
2492 "CreateTrustedDomainEx2 failed");
2494 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2495 torture_comment(tctx
, "CreateTrustedDomainEx failed2 - %s\n", nt_errstr(r
.out
.result
));
2499 q
.in
.trustdom_handle
= &trustdom_handle
[i
];
2500 q
.in
.level
= LSA_TRUSTED_DOMAIN_INFO_INFO_EX
;
2502 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryTrustedDomainInfo_r(b
, tctx
, &q
),
2503 "QueryTrustedDomainInfo failed");
2504 if (!NT_STATUS_IS_OK(q
.out
.result
)) {
2505 torture_comment(tctx
, "QueryTrustedDomainInfo level 1 failed - %s\n", nt_errstr(q
.out
.result
));
2507 } else if (!q
.out
.info
) {
2508 torture_comment(tctx
, "QueryTrustedDomainInfo level 1 failed to return an info pointer\n");
2511 if (strcmp(info
->info_ex
.netbios_name
.string
, trustinfo
.netbios_name
.string
) != 0) {
2512 torture_comment(tctx
, "QueryTrustedDomainInfo returned inconsistent short name: %s != %s\n",
2513 info
->info_ex
.netbios_name
.string
, trustinfo
.netbios_name
.string
);
2516 if (info
->info_ex
.trust_type
!= trustinfo
.trust_type
) {
2517 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
2518 trust_name
, info
->info_ex
.trust_type
, trustinfo
.trust_type
);
2521 if (info
->info_ex
.trust_attributes
!= LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION
) {
2522 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
2523 trust_name
, info
->info_ex
.trust_attributes
, LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION
);
2526 if (info
->info_ex
.trust_direction
!= trustinfo
.trust_direction
) {
2527 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
2528 trust_name
, info
->info_ex
.trust_direction
, trustinfo
.trust_direction
);
2535 /* now that we have some domains to look over, we can test the enum calls */
2536 if (!test_EnumTrustDom(b
, tctx
, handle
)) {
2537 torture_comment(tctx
, "test_EnumTrustDom failed\n");
2541 if (!test_EnumTrustDomEx(b
, tctx
, handle
)) {
2542 torture_comment(tctx
, "test_EnumTrustDomEx failed\n");
2546 for (i
=0; i
<num_trusts
; i
++) {
2547 if (!test_DeleteTrustedDomainBySid(b
, tctx
, handle
, domsid
[i
])) {
2548 torture_comment(tctx
, "test_DeleteTrustedDomainBySid failed\n");
2556 static bool test_QueryDomainInfoPolicy(struct dcerpc_binding_handle
*b
,
2557 struct torture_context
*tctx
,
2558 struct policy_handle
*handle
)
2560 struct lsa_QueryDomainInformationPolicy r
;
2561 union lsa_DomainInformationPolicy
*info
= NULL
;
2565 if (torture_setting_bool(tctx
, "samba3", false)) {
2566 torture_skip(tctx
, "skipping QueryDomainInformationPolicy test\n");
2569 torture_comment(tctx
, "\nTesting QueryDomainInformationPolicy\n");
2572 r
.in
.handle
= handle
;
2576 torture_comment(tctx
, "\nTrying QueryDomainInformationPolicy level %d\n", i
);
2578 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryDomainInformationPolicy_r(b
, tctx
, &r
),
2579 "QueryDomainInformationPolicy failed");
2581 /* If the server does not support EFS, then this is the correct return */
2582 if (i
== LSA_DOMAIN_INFO_POLICY_EFS
&& NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
2584 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2585 torture_comment(tctx
, "QueryDomainInformationPolicy failed - %s\n", nt_errstr(r
.out
.result
));
2595 static bool test_QueryInfoPolicyCalls( bool version2
,
2596 struct dcerpc_binding_handle
*b
,
2597 struct torture_context
*tctx
,
2598 struct policy_handle
*handle
)
2600 struct lsa_QueryInfoPolicy r
;
2601 union lsa_PolicyInformation
*info
= NULL
;
2604 const char *call
= talloc_asprintf(tctx
, "QueryInfoPolicy%s", version2
? "2":"");
2606 torture_comment(tctx
, "\nTesting %s\n", call
);
2608 if (version2
&& torture_setting_bool(tctx
, "samba3", false)) {
2609 torture_skip(tctx
, "skipping QueryInfoPolicy2 tests\n");
2612 for (i
=1;i
<=14;i
++) {
2613 r
.in
.handle
= handle
;
2617 torture_comment(tctx
, "\nTrying %s level %d\n", call
, i
);
2620 /* We can perform the cast, because both types are
2621 structurally equal */
2622 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryInfoPolicy2_r(b
, tctx
,
2623 (struct lsa_QueryInfoPolicy2
*) &r
),
2624 "QueryInfoPolicy2 failed");
2626 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_QueryInfoPolicy_r(b
, tctx
, &r
),
2627 "QueryInfoPolicy2 failed");
2630 case LSA_POLICY_INFO_MOD
:
2631 case LSA_POLICY_INFO_AUDIT_FULL_SET
:
2632 case LSA_POLICY_INFO_AUDIT_FULL_QUERY
:
2633 if (!NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_INVALID_PARAMETER
)) {
2634 torture_comment(tctx
, "Server should have failed level %u: %s\n", i
, nt_errstr(r
.out
.result
));
2638 case LSA_POLICY_INFO_DOMAIN
:
2639 case LSA_POLICY_INFO_ACCOUNT_DOMAIN
:
2640 case LSA_POLICY_INFO_REPLICA
:
2641 case LSA_POLICY_INFO_QUOTA
:
2642 case LSA_POLICY_INFO_ROLE
:
2643 case LSA_POLICY_INFO_AUDIT_LOG
:
2644 case LSA_POLICY_INFO_AUDIT_EVENTS
:
2645 case LSA_POLICY_INFO_PD
:
2646 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2647 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(r
.out
.result
));
2651 case LSA_POLICY_INFO_L_ACCOUNT_DOMAIN
:
2652 case LSA_POLICY_INFO_DNS_INT
:
2653 case LSA_POLICY_INFO_DNS
:
2654 if (torture_setting_bool(tctx
, "samba3", false)) {
2655 /* Other levels not implemented yet */
2656 if (!NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_INVALID_INFO_CLASS
)) {
2657 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(r
.out
.result
));
2660 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2661 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(r
.out
.result
));
2666 if (torture_setting_bool(tctx
, "samba4", false)) {
2667 /* Other levels not implemented yet */
2668 if (!NT_STATUS_EQUAL(r
.out
.result
, NT_STATUS_INVALID_INFO_CLASS
)) {
2669 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(r
.out
.result
));
2672 } else if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2673 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(r
.out
.result
));
2679 if (NT_STATUS_IS_OK(r
.out
.result
) && (i
== LSA_POLICY_INFO_DNS
2680 || i
== LSA_POLICY_INFO_DNS_INT
)) {
2681 /* Let's look up some of these names */
2683 struct lsa_TransNameArray tnames
;
2685 tnames
.names
= talloc_zero_array(tctx
, struct lsa_TranslatedName
, tnames
.count
);
2686 tnames
.names
[0].name
.string
= info
->dns
.name
.string
;
2687 tnames
.names
[0].sid_type
= SID_NAME_DOMAIN
;
2688 tnames
.names
[1].name
.string
= info
->dns
.dns_domain
.string
;
2689 tnames
.names
[1].sid_type
= SID_NAME_DOMAIN
;
2690 tnames
.names
[2].name
.string
= talloc_asprintf(tctx
, "%s\\", info
->dns
.name
.string
);
2691 tnames
.names
[2].sid_type
= SID_NAME_DOMAIN
;
2692 tnames
.names
[3].name
.string
= talloc_asprintf(tctx
, "%s\\", info
->dns
.dns_domain
.string
);
2693 tnames
.names
[3].sid_type
= SID_NAME_DOMAIN
;
2694 tnames
.names
[4].name
.string
= talloc_asprintf(tctx
, "%s\\guest", info
->dns
.name
.string
);
2695 tnames
.names
[4].sid_type
= SID_NAME_USER
;
2696 tnames
.names
[5].name
.string
= talloc_asprintf(tctx
, "%s\\krbtgt", info
->dns
.name
.string
);
2697 tnames
.names
[5].sid_type
= SID_NAME_USER
;
2698 tnames
.names
[6].name
.string
= talloc_asprintf(tctx
, "%s\\guest", info
->dns
.dns_domain
.string
);
2699 tnames
.names
[6].sid_type
= SID_NAME_USER
;
2700 tnames
.names
[7].name
.string
= talloc_asprintf(tctx
, "%s\\krbtgt", info
->dns
.dns_domain
.string
);
2701 tnames
.names
[7].sid_type
= SID_NAME_USER
;
2702 tnames
.names
[8].name
.string
= talloc_asprintf(tctx
, "krbtgt@%s", info
->dns
.name
.string
);
2703 tnames
.names
[8].sid_type
= SID_NAME_USER
;
2704 tnames
.names
[9].name
.string
= talloc_asprintf(tctx
, "krbtgt@%s", info
->dns
.dns_domain
.string
);
2705 tnames
.names
[9].sid_type
= SID_NAME_USER
;
2706 tnames
.names
[10].name
.string
= talloc_asprintf(tctx
, "%s\\"TEST_MACHINENAME
"$", info
->dns
.name
.string
);
2707 tnames
.names
[10].sid_type
= SID_NAME_USER
;
2708 tnames
.names
[11].name
.string
= talloc_asprintf(tctx
, "%s\\"TEST_MACHINENAME
"$", info
->dns
.dns_domain
.string
);
2709 tnames
.names
[11].sid_type
= SID_NAME_USER
;
2710 tnames
.names
[12].name
.string
= talloc_asprintf(tctx
, TEST_MACHINENAME
"$@%s", info
->dns
.name
.string
);
2711 tnames
.names
[12].sid_type
= SID_NAME_USER
;
2712 tnames
.names
[13].name
.string
= talloc_asprintf(tctx
, TEST_MACHINENAME
"$@%s", info
->dns
.dns_domain
.string
);
2713 tnames
.names
[13].sid_type
= SID_NAME_USER
;
2714 ret
&= test_LookupNames(b
, tctx
, handle
, &tnames
);
2722 static bool test_QueryInfoPolicy(struct dcerpc_binding_handle
*b
,
2723 struct torture_context
*tctx
,
2724 struct policy_handle
*handle
)
2726 return test_QueryInfoPolicyCalls(false, b
, tctx
, handle
);
2729 static bool test_QueryInfoPolicy2(struct dcerpc_binding_handle
*b
,
2730 struct torture_context
*tctx
,
2731 struct policy_handle
*handle
)
2733 return test_QueryInfoPolicyCalls(true, b
, tctx
, handle
);
2736 static bool test_GetUserName(struct dcerpc_binding_handle
*b
,
2737 struct torture_context
*tctx
)
2739 struct lsa_GetUserName r
;
2741 struct lsa_String
*authority_name_p
= NULL
;
2742 struct lsa_String
*account_name_p
= NULL
;
2744 torture_comment(tctx
, "\nTesting GetUserName\n");
2746 r
.in
.system_name
= "\\";
2747 r
.in
.account_name
= &account_name_p
;
2748 r
.in
.authority_name
= NULL
;
2749 r
.out
.account_name
= &account_name_p
;
2751 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_GetUserName_r(b
, tctx
, &r
),
2752 "GetUserName failed");
2754 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2755 torture_comment(tctx
, "GetUserName failed - %s\n", nt_errstr(r
.out
.result
));
2759 account_name_p
= NULL
;
2760 r
.in
.account_name
= &account_name_p
;
2761 r
.in
.authority_name
= &authority_name_p
;
2762 r
.out
.account_name
= &account_name_p
;
2764 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_GetUserName_r(b
, tctx
, &r
),
2765 "GetUserName failed");
2767 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2768 torture_comment(tctx
, "GetUserName failed - %s\n", nt_errstr(r
.out
.result
));
2775 bool test_lsa_Close(struct dcerpc_binding_handle
*b
,
2776 struct torture_context
*tctx
,
2777 struct policy_handle
*handle
)
2780 struct policy_handle handle2
;
2782 torture_comment(tctx
, "\nTesting Close\n");
2784 r
.in
.handle
= handle
;
2785 r
.out
.handle
= &handle2
;
2787 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_Close_r(b
, tctx
, &r
),
2789 if (!NT_STATUS_IS_OK(r
.out
.result
)) {
2790 torture_comment(tctx
, "Close failed - %s\n",
2791 nt_errstr(r
.out
.result
));
2795 torture_assert_ntstatus_equal(tctx
, dcerpc_lsa_Close_r(b
, tctx
, &r
),
2796 NT_STATUS_RPC_SS_CONTEXT_MISMATCH
, "Close should failed");
2798 torture_comment(tctx
, "\n");
2803 bool torture_rpc_lsa(struct torture_context
*tctx
)
2806 struct dcerpc_pipe
*p
;
2808 struct policy_handle
*handle
;
2809 struct test_join
*join
= NULL
;
2810 struct cli_credentials
*machine_creds
;
2811 struct dcerpc_binding_handle
*b
;
2813 status
= torture_rpc_connection(tctx
, &p
, &ndr_table_lsarpc
);
2814 if (!NT_STATUS_IS_OK(status
)) {
2817 b
= p
->binding_handle
;
2819 if (!test_OpenPolicy(b
, tctx
)) {
2823 if (!test_lsa_OpenPolicy2(b
, tctx
, &handle
)) {
2828 join
= torture_join_domain(tctx
, TEST_MACHINENAME
, ACB_WSTRUST
, &machine_creds
);
2833 if (!test_LookupSids_async(b
, tctx
, handle
)) {
2837 if (!test_QueryDomainInfoPolicy(b
, tctx
, handle
)) {
2841 if (!test_CreateSecret(p
, tctx
, handle
)) {
2845 if (!test_QueryInfoPolicy(b
, tctx
, handle
)) {
2849 if (!test_QueryInfoPolicy2(b
, tctx
, handle
)) {
2853 if (!test_Delete(b
, tctx
, handle
)) {
2857 if (!test_many_LookupSids(p
, tctx
, handle
)) {
2861 if (!test_lsa_Close(b
, tctx
, handle
)) {
2865 torture_leave_domain(tctx
, join
);
2868 if (!test_many_LookupSids(p
, tctx
, handle
)) {
2873 if (!test_GetUserName(b
, tctx
)) {
2880 bool torture_rpc_lsa_get_user(struct torture_context
*tctx
)
2883 struct dcerpc_pipe
*p
;
2885 struct dcerpc_binding_handle
*b
;
2887 status
= torture_rpc_connection(tctx
, &p
, &ndr_table_lsarpc
);
2888 if (!NT_STATUS_IS_OK(status
)) {
2891 b
= p
->binding_handle
;
2893 if (!test_GetUserName(b
, tctx
)) {
2900 static bool testcase_LookupNames(struct torture_context
*tctx
,
2901 struct dcerpc_pipe
*p
)
2904 struct policy_handle
*handle
;
2905 struct lsa_TransNameArray tnames
;
2906 struct lsa_TransNameArray2 tnames2
;
2907 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
2909 if (!test_OpenPolicy(b
, tctx
)) {
2913 if (!test_lsa_OpenPolicy2(b
, tctx
, &handle
)) {
2922 tnames
.names
= talloc_array(tctx
, struct lsa_TranslatedName
, tnames
.count
);
2923 ZERO_STRUCT(tnames
.names
[0]);
2924 tnames
.names
[0].name
.string
= "BUILTIN";
2925 tnames
.names
[0].sid_type
= SID_NAME_DOMAIN
;
2927 if (!test_LookupNames(b
, tctx
, handle
, &tnames
)) {
2932 tnames2
.names
= talloc_array(tctx
, struct lsa_TranslatedName2
, tnames2
.count
);
2933 ZERO_STRUCT(tnames2
.names
[0]);
2934 tnames2
.names
[0].name
.string
= "BUILTIN";
2935 tnames2
.names
[0].sid_type
= SID_NAME_DOMAIN
;
2937 if (!test_LookupNames2(b
, tctx
, handle
, &tnames2
, true)) {
2941 if (!test_LookupNames3(b
, tctx
, handle
, &tnames2
, true)) {
2945 if (!test_LookupNames_wellknown(b
, tctx
, handle
)) {
2949 if (!test_LookupNames_NULL(b
, tctx
, handle
)) {
2953 if (!test_LookupNames_bogus(b
, tctx
, handle
)) {
2957 if (!test_lsa_Close(b
, tctx
, handle
)) {
2964 struct torture_suite
*torture_rpc_lsa_lookup_names(TALLOC_CTX
*mem_ctx
)
2966 struct torture_suite
*suite
;
2967 struct torture_rpc_tcase
*tcase
;
2969 suite
= torture_suite_create(mem_ctx
, "lsa.lookupnames");
2971 tcase
= torture_suite_add_rpc_iface_tcase(suite
, "lsa",
2973 torture_rpc_tcase_add_test(tcase
, "LookupNames",
2974 testcase_LookupNames
);
2979 struct lsa_trustdom_state
{
2980 uint32_t num_trusts
;
2983 static bool testcase_TrustedDomains(struct torture_context
*tctx
,
2984 struct dcerpc_pipe
*p
,
2988 struct policy_handle
*handle
;
2989 struct lsa_trustdom_state
*state
=
2990 talloc_get_type_abort(data
, struct lsa_trustdom_state
);
2991 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
2993 torture_comment(tctx
, "Testing %d domains\n", state
->num_trusts
);
2995 if (!test_OpenPolicy(b
, tctx
)) {
2999 if (!test_lsa_OpenPolicy2(b
, tctx
, &handle
)) {
3007 if (!test_CreateTrustedDomain(b
, tctx
, handle
, state
->num_trusts
)) {
3011 if (!test_CreateTrustedDomainEx2(p
, tctx
, handle
, state
->num_trusts
)) {
3015 if (!test_lsa_Close(b
, tctx
, handle
)) {
3022 struct torture_suite
*torture_rpc_lsa_trusted_domains(TALLOC_CTX
*mem_ctx
)
3024 struct torture_suite
*suite
;
3025 struct torture_rpc_tcase
*tcase
;
3026 struct lsa_trustdom_state
*state
;
3028 state
= talloc(mem_ctx
, struct lsa_trustdom_state
);
3030 state
->num_trusts
= 12;
3032 suite
= torture_suite_create(mem_ctx
, "lsa.trusted.domains");
3034 tcase
= torture_suite_add_rpc_iface_tcase(suite
, "lsa",
3036 torture_rpc_tcase_add_test_ex(tcase
, "TrustedDomains",
3037 testcase_TrustedDomains
,
3043 static bool testcase_Privileges(struct torture_context
*tctx
,
3044 struct dcerpc_pipe
*p
)
3047 struct policy_handle
*handle
;
3048 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
3050 if (!test_OpenPolicy(b
, tctx
)) {
3054 if (!test_lsa_OpenPolicy2(b
, tctx
, &handle
)) {
3062 if (!test_CreateAccount(b
, tctx
, handle
)) {
3066 if (!test_EnumAccounts(b
, tctx
, handle
)) {
3070 if (!test_EnumPrivs(b
, tctx
, handle
)) {
3074 if (!test_lsa_Close(b
, tctx
, handle
)) {
3082 struct torture_suite
*torture_rpc_lsa_privileges(TALLOC_CTX
*mem_ctx
)
3084 struct torture_suite
*suite
;
3085 struct torture_rpc_tcase
*tcase
;
3087 suite
= torture_suite_create(mem_ctx
, "lsa.privileges");
3089 tcase
= torture_suite_add_rpc_iface_tcase(suite
, "lsa",
3091 torture_rpc_tcase_add_test(tcase
, "Privileges",
3092 testcase_Privileges
);