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/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_pipe
*p
,
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
;
48 uint16_t system_name
= '\\';
50 torture_comment(tctx
, "\nTesting OpenPolicy\n");
53 qos
.impersonation_level
= 2;
55 qos
.effective_only
= 0;
59 attr
.object_name
= NULL
;
64 r
.in
.system_name
= &system_name
;
66 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
67 r
.out
.handle
= &handle
;
69 status
= dcerpc_lsa_OpenPolicy(p
, tctx
, &r
);
70 if (!NT_STATUS_IS_OK(status
)) {
71 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
) ||
72 NT_STATUS_EQUAL(status
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
73 torture_comment(tctx
, "not considering %s to be an error\n", nt_errstr(status
));
76 torture_comment(tctx
, "OpenPolicy failed - %s\n", nt_errstr(status
));
84 bool test_lsa_OpenPolicy2(struct dcerpc_pipe
*p
,
85 struct torture_context
*tctx
,
86 struct policy_handle
**handle
)
88 struct lsa_ObjectAttribute attr
;
89 struct lsa_QosInfo qos
;
90 struct lsa_OpenPolicy2 r
;
93 torture_comment(tctx
, "\nTesting OpenPolicy2\n");
95 *handle
= talloc(tctx
, struct policy_handle
);
101 qos
.impersonation_level
= 2;
102 qos
.context_mode
= 1;
103 qos
.effective_only
= 0;
106 attr
.root_dir
= NULL
;
107 attr
.object_name
= NULL
;
109 attr
.sec_desc
= NULL
;
112 r
.in
.system_name
= "\\";
114 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
115 r
.out
.handle
= *handle
;
117 status
= dcerpc_lsa_OpenPolicy2(p
, tctx
, &r
);
118 if (!NT_STATUS_IS_OK(status
)) {
119 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
) ||
120 NT_STATUS_EQUAL(status
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
121 torture_comment(tctx
, "not considering %s to be an error\n", nt_errstr(status
));
122 talloc_free(*handle
);
126 torture_comment(tctx
, "OpenPolicy2 failed - %s\n", nt_errstr(status
));
134 static const char *sid_type_lookup(enum lsa_SidType r
)
137 case SID_NAME_USE_NONE
: return "SID_NAME_USE_NONE"; break;
138 case SID_NAME_USER
: return "SID_NAME_USER"; break;
139 case SID_NAME_DOM_GRP
: return "SID_NAME_DOM_GRP"; break;
140 case SID_NAME_DOMAIN
: return "SID_NAME_DOMAIN"; break;
141 case SID_NAME_ALIAS
: return "SID_NAME_ALIAS"; break;
142 case SID_NAME_WKN_GRP
: return "SID_NAME_WKN_GRP"; break;
143 case SID_NAME_DELETED
: return "SID_NAME_DELETED"; break;
144 case SID_NAME_INVALID
: return "SID_NAME_INVALID"; break;
145 case SID_NAME_UNKNOWN
: return "SID_NAME_UNKNOWN"; break;
146 case SID_NAME_COMPUTER
: return "SID_NAME_COMPUTER"; break;
148 return "Invalid sid type\n";
151 static bool test_LookupNames(struct dcerpc_pipe
*p
,
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
);
169 names
= talloc_array(tctx
, struct lsa_String
, tnames
->count
);
170 for (i
=0;i
<tnames
->count
;i
++) {
171 init_lsa_String(&names
[i
], tnames
->names
[i
].name
.string
);
174 r
.in
.handle
= handle
;
175 r
.in
.num_names
= tnames
->count
;
180 r
.out
.count
= &count
;
182 r
.out
.domains
= &domains
;
184 status
= dcerpc_lsa_LookupNames(p
, tctx
, &r
);
186 if (NT_STATUS_EQUAL(status
, STATUS_SOME_UNMAPPED
) ||
187 NT_STATUS_EQUAL(status
, NT_STATUS_NONE_MAPPED
)) {
188 for (i
=0;i
< tnames
->count
;i
++) {
189 if (i
< count
&& sids
.sids
[i
].sid_type
== SID_NAME_UNKNOWN
) {
190 torture_comment(tctx
, "LookupName of %s was unmapped\n",
191 tnames
->names
[i
].name
.string
);
192 } else if (i
>=count
) {
193 torture_comment(tctx
, "LookupName of %s failed to return a result\n",
194 tnames
->names
[i
].name
.string
);
197 torture_comment(tctx
, "LookupNames failed - %s\n", nt_errstr(status
));
199 } else if (!NT_STATUS_IS_OK(status
)) {
200 torture_comment(tctx
, "LookupNames failed - %s\n", nt_errstr(status
));
204 for (i
=0;i
< tnames
->count
;i
++) {
206 if (sids
.sids
[i
].sid_type
!= tnames
->names
[i
].sid_type
) {
207 torture_comment(tctx
, "LookupName of %s got unexpected name type: %s\n",
208 tnames
->names
[i
].name
.string
, sid_type_lookup(sids
.sids
[i
].sid_type
));
211 if ((sids
.sids
[i
].sid_type
== SID_NAME_DOMAIN
) &&
212 (sids
.sids
[i
].rid
!= (uint32_t)-1)) {
213 torture_comment(tctx
, "LookupName of %s got unexpected rid: %d\n",
214 tnames
->names
[i
].name
.string
, sids
.sids
[i
].rid
);
217 } else if (i
>=count
) {
218 torture_comment(tctx
, "LookupName of %s failed to return a result\n",
219 tnames
->names
[i
].name
.string
);
223 torture_comment(tctx
, "\n");
228 static bool test_LookupNames_bogus(struct dcerpc_pipe
*p
,
229 struct torture_context
*tctx
,
230 struct policy_handle
*handle
)
232 struct lsa_LookupNames r
;
233 struct lsa_TransSidArray sids
;
234 struct lsa_RefDomainList
*domains
= NULL
;
235 struct lsa_String names
[1];
239 torture_comment(tctx
, "\nTesting LookupNames with bogus name\n");
244 init_lsa_String(&names
[0], "NT AUTHORITY\\BOGUS");
246 r
.in
.handle
= handle
;
252 r
.out
.count
= &count
;
254 r
.out
.domains
= &domains
;
256 status
= dcerpc_lsa_LookupNames(p
, tctx
, &r
);
257 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NONE_MAPPED
)) {
258 torture_comment(tctx
, "LookupNames failed - %s\n", nt_errstr(status
));
262 torture_comment(tctx
, "\n");
267 static bool test_LookupNames_NULL(struct dcerpc_pipe
*p
,
268 struct torture_context
*tctx
,
269 struct policy_handle
*handle
)
271 struct lsa_LookupNames r
;
272 struct lsa_TransSidArray sids
;
273 struct lsa_RefDomainList
*domains
= NULL
;
274 struct lsa_String names
[1];
277 torture_comment(tctx
, "\nTesting LookupNames with NULL name\n");
282 names
[0].string
= NULL
;
284 r
.in
.handle
= handle
;
290 r
.out
.count
= &count
;
292 r
.out
.domains
= &domains
;
294 /* nt4 returns NT_STATUS_NONE_MAPPED with sid_type
295 * SID_NAME_UNKNOWN, rid 0, and sid_index -1;
297 * w2k3/w2k8 return NT_STATUS_OK with sid_type
298 * SID_NAME_DOMAIN, rid -1 and sid_index 0 and BUILTIN domain
301 torture_assert_ntstatus_ok(tctx
, dcerpc_lsa_LookupNames(p
, tctx
, &r
),
302 "LookupNames with NULL name failed");
304 torture_comment(tctx
, "\n");
309 static bool test_LookupNames_wellknown(struct dcerpc_pipe
*p
,
310 struct torture_context
*tctx
,
311 struct policy_handle
*handle
)
313 struct lsa_TranslatedName name
;
314 struct lsa_TransNameArray tnames
;
317 torture_comment(tctx
, "Testing LookupNames with well known names\n");
319 tnames
.names
= &name
;
321 name
.name
.string
= "NT AUTHORITY\\SYSTEM";
322 name
.sid_type
= SID_NAME_WKN_GRP
;
323 ret
&= test_LookupNames(p
, tctx
, handle
, &tnames
);
325 name
.name
.string
= "NT AUTHORITY\\ANONYMOUS LOGON";
326 name
.sid_type
= SID_NAME_WKN_GRP
;
327 ret
&= test_LookupNames(p
, tctx
, handle
, &tnames
);
329 name
.name
.string
= "NT AUTHORITY\\Authenticated Users";
330 name
.sid_type
= SID_NAME_WKN_GRP
;
331 ret
&= test_LookupNames(p
, tctx
, handle
, &tnames
);
334 name
.name
.string
= "NT AUTHORITY";
335 ret
&= test_LookupNames(p
, tctx
, handle
, &tnames
);
337 name
.name
.string
= "NT AUTHORITY\\";
338 ret
&= test_LookupNames(p
, tctx
, handle
, &tnames
);
341 name
.name
.string
= "BUILTIN\\";
342 name
.sid_type
= SID_NAME_DOMAIN
;
343 ret
&= test_LookupNames(p
, tctx
, handle
, &tnames
);
345 name
.name
.string
= "BUILTIN\\Administrators";
346 name
.sid_type
= SID_NAME_ALIAS
;
347 ret
&= test_LookupNames(p
, tctx
, handle
, &tnames
);
349 name
.name
.string
= "SYSTEM";
350 name
.sid_type
= SID_NAME_WKN_GRP
;
351 ret
&= test_LookupNames(p
, tctx
, handle
, &tnames
);
353 name
.name
.string
= "Everyone";
354 name
.sid_type
= SID_NAME_WKN_GRP
;
355 ret
&= test_LookupNames(p
, tctx
, handle
, &tnames
);
359 static bool test_LookupNames2(struct dcerpc_pipe
*p
,
360 struct torture_context
*tctx
,
361 struct policy_handle
*handle
,
362 struct lsa_TransNameArray2
*tnames
,
365 struct lsa_LookupNames2 r
;
366 struct lsa_TransSidArray2 sids
;
367 struct lsa_RefDomainList
*domains
= NULL
;
368 struct lsa_String
*names
;
373 torture_comment(tctx
, "\nTesting LookupNames2 with %d names\n", tnames
->count
);
378 names
= talloc_array(tctx
, struct lsa_String
, tnames
->count
);
379 for (i
=0;i
<tnames
->count
;i
++) {
380 init_lsa_String(&names
[i
], tnames
->names
[i
].name
.string
);
383 r
.in
.handle
= handle
;
384 r
.in
.num_names
= tnames
->count
;
389 r
.in
.lookup_options
= 0;
390 r
.in
.client_revision
= 0;
391 r
.out
.count
= &count
;
393 r
.out
.domains
= &domains
;
395 status
= dcerpc_lsa_LookupNames2(p
, tctx
, &r
);
396 if (!NT_STATUS_IS_OK(status
)) {
397 torture_comment(tctx
, "LookupNames2 failed - %s\n", nt_errstr(status
));
402 torture_assert_int_equal(tctx
, count
, sids
.count
,
403 "unexpected number of results returned");
404 if (sids
.count
> 0) {
405 torture_assert(tctx
, sids
.sids
, "invalid sid buffer");
409 torture_comment(tctx
, "\n");
415 static bool test_LookupNames3(struct dcerpc_pipe
*p
,
416 struct torture_context
*tctx
,
417 struct policy_handle
*handle
,
418 struct lsa_TransNameArray2
*tnames
,
421 struct lsa_LookupNames3 r
;
422 struct lsa_TransSidArray3 sids
;
423 struct lsa_RefDomainList
*domains
= NULL
;
424 struct lsa_String
*names
;
429 torture_comment(tctx
, "\nTesting LookupNames3 with %d names\n", tnames
->count
);
434 names
= talloc_array(tctx
, struct lsa_String
, tnames
->count
);
435 for (i
=0;i
<tnames
->count
;i
++) {
436 init_lsa_String(&names
[i
], tnames
->names
[i
].name
.string
);
439 r
.in
.handle
= handle
;
440 r
.in
.num_names
= tnames
->count
;
445 r
.in
.lookup_options
= 0;
446 r
.in
.client_revision
= 0;
447 r
.out
.count
= &count
;
449 r
.out
.domains
= &domains
;
451 status
= dcerpc_lsa_LookupNames3(p
, tctx
, &r
);
452 if (!NT_STATUS_IS_OK(status
)) {
453 torture_comment(tctx
, "LookupNames3 failed - %s\n", nt_errstr(status
));
458 torture_assert_int_equal(tctx
, count
, sids
.count
,
459 "unexpected number of results returned");
460 if (sids
.count
> 0) {
461 torture_assert(tctx
, sids
.sids
, "invalid sid buffer");
465 torture_comment(tctx
, "\n");
470 static bool test_LookupNames4(struct dcerpc_pipe
*p
,
471 struct torture_context
*tctx
,
472 struct lsa_TransNameArray2
*tnames
,
475 struct lsa_LookupNames4 r
;
476 struct lsa_TransSidArray3 sids
;
477 struct lsa_RefDomainList
*domains
= NULL
;
478 struct lsa_String
*names
;
483 torture_comment(tctx
, "\nTesting LookupNames4 with %d names\n", tnames
->count
);
488 names
= talloc_array(tctx
, struct lsa_String
, tnames
->count
);
489 for (i
=0;i
<tnames
->count
;i
++) {
490 init_lsa_String(&names
[i
], tnames
->names
[i
].name
.string
);
493 r
.in
.num_names
= tnames
->count
;
498 r
.in
.lookup_options
= 0;
499 r
.in
.client_revision
= 0;
500 r
.out
.count
= &count
;
502 r
.out
.domains
= &domains
;
504 status
= dcerpc_lsa_LookupNames4(p
, tctx
, &r
);
505 if (!NT_STATUS_IS_OK(status
)) {
506 torture_comment(tctx
, "LookupNames4 failed - %s\n", nt_errstr(status
));
511 torture_assert_int_equal(tctx
, count
, sids
.count
,
512 "unexpected number of results returned");
513 if (sids
.count
> 0) {
514 torture_assert(tctx
, sids
.sids
, "invalid sid buffer");
518 torture_comment(tctx
, "\n");
524 static bool test_LookupSids(struct dcerpc_pipe
*p
,
525 struct torture_context
*tctx
,
526 struct policy_handle
*handle
,
527 struct lsa_SidArray
*sids
)
529 struct lsa_LookupSids r
;
530 struct lsa_TransNameArray names
;
531 struct lsa_RefDomainList
*domains
= NULL
;
532 uint32_t count
= sids
->num_sids
;
535 torture_comment(tctx
, "\nTesting LookupSids\n");
540 r
.in
.handle
= handle
;
545 r
.out
.count
= &count
;
546 r
.out
.names
= &names
;
547 r
.out
.domains
= &domains
;
549 status
= dcerpc_lsa_LookupSids(p
, tctx
, &r
);
550 if (!NT_STATUS_IS_OK(status
)) {
551 torture_comment(tctx
, "LookupSids failed - %s\n", nt_errstr(status
));
555 torture_comment(tctx
, "\n");
557 if (!test_LookupNames(p
, tctx
, handle
, &names
)) {
565 static bool test_LookupSids2(struct dcerpc_pipe
*p
,
566 struct torture_context
*tctx
,
567 struct policy_handle
*handle
,
568 struct lsa_SidArray
*sids
)
570 struct lsa_LookupSids2 r
;
571 struct lsa_TransNameArray2 names
;
572 struct lsa_RefDomainList
*domains
= NULL
;
573 uint32_t count
= sids
->num_sids
;
576 torture_comment(tctx
, "\nTesting LookupSids2\n");
581 r
.in
.handle
= handle
;
586 r
.in
.lookup_options
= 0;
587 r
.in
.client_revision
= 0;
588 r
.out
.count
= &count
;
589 r
.out
.names
= &names
;
590 r
.out
.domains
= &domains
;
592 status
= dcerpc_lsa_LookupSids2(p
, tctx
, &r
);
593 if (!NT_STATUS_IS_OK(status
)) {
594 torture_comment(tctx
, "LookupSids2 failed - %s\n", nt_errstr(status
));
598 torture_comment(tctx
, "\n");
600 if (!test_LookupNames2(p
, tctx
, handle
, &names
, false)) {
604 if (!test_LookupNames3(p
, tctx
, handle
, &names
, false)) {
611 static bool test_LookupSids3(struct dcerpc_pipe
*p
,
612 struct torture_context
*tctx
,
613 struct lsa_SidArray
*sids
)
615 struct lsa_LookupSids3 r
;
616 struct lsa_TransNameArray2 names
;
617 struct lsa_RefDomainList
*domains
= NULL
;
618 uint32_t count
= sids
->num_sids
;
621 torture_comment(tctx
, "\nTesting LookupSids3\n");
630 r
.in
.lookup_options
= 0;
631 r
.in
.client_revision
= 0;
632 r
.out
.domains
= &domains
;
633 r
.out
.count
= &count
;
634 r
.out
.names
= &names
;
636 status
= dcerpc_lsa_LookupSids3(p
, tctx
, &r
);
637 if (!NT_STATUS_IS_OK(status
)) {
638 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
) ||
639 NT_STATUS_EQUAL(status
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
640 torture_comment(tctx
, "not considering %s to be an error\n", nt_errstr(status
));
643 torture_comment(tctx
, "LookupSids3 failed - %s - not considered an error\n",
648 torture_comment(tctx
, "\n");
650 if (!test_LookupNames4(p
, tctx
, &names
, false)) {
657 bool test_many_LookupSids(struct dcerpc_pipe
*p
,
658 struct torture_context
*tctx
,
659 struct policy_handle
*handle
)
663 struct lsa_SidArray sids
;
666 torture_comment(tctx
, "\nTesting LookupSids with lots of SIDs\n");
670 sids
.sids
= talloc_array(tctx
, struct lsa_SidPtr
, sids
.num_sids
);
672 for (i
=0; i
<sids
.num_sids
; i
++) {
673 const char *sidstr
= "S-1-5-32-545";
674 sids
.sids
[i
].sid
= dom_sid_parse_talloc(tctx
, sidstr
);
677 count
= sids
.num_sids
;
680 struct lsa_LookupSids r
;
681 struct lsa_TransNameArray names
;
682 struct lsa_RefDomainList
*domains
= NULL
;
686 r
.in
.handle
= handle
;
690 r
.in
.count
= &names
.count
;
691 r
.out
.count
= &count
;
692 r
.out
.names
= &names
;
693 r
.out
.domains
= &domains
;
695 status
= dcerpc_lsa_LookupSids(p
, tctx
, &r
);
696 if (!NT_STATUS_IS_OK(status
)) {
697 torture_comment(tctx
, "LookupSids failed - %s\n", nt_errstr(status
));
701 torture_comment(tctx
, "\n");
703 if (!test_LookupNames(p
, tctx
, handle
, &names
)) {
706 } else if (p
->conn
->security_state
.auth_info
->auth_type
== DCERPC_AUTH_TYPE_SCHANNEL
&&
707 p
->conn
->security_state
.auth_info
->auth_level
>= DCERPC_AUTH_LEVEL_INTEGRITY
) {
708 struct lsa_LookupSids3 r
;
709 struct lsa_RefDomainList
*domains
= NULL
;
710 struct lsa_TransNameArray2 names
;
715 torture_comment(tctx
, "\nTesting LookupSids3\n");
721 r
.in
.lookup_options
= 0;
722 r
.in
.client_revision
= 0;
723 r
.out
.count
= &count
;
724 r
.out
.names
= &names
;
725 r
.out
.domains
= &domains
;
727 status
= dcerpc_lsa_LookupSids3(p
, tctx
, &r
);
728 if (!NT_STATUS_IS_OK(status
)) {
729 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
) ||
730 NT_STATUS_EQUAL(status
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
731 torture_comment(tctx
, "not considering %s to be an error\n", nt_errstr(status
));
734 torture_comment(tctx
, "LookupSids3 failed - %s\n",
738 if (!test_LookupNames4(p
, tctx
, &names
, false)) {
743 torture_comment(tctx
, "\n");
750 static void lookupsids_cb(struct rpc_request
*req
)
752 int *replies
= (int *)req
->async
.private_data
;
755 status
= dcerpc_lsa_LookupSids_recv(req
);
756 if (!NT_STATUS_IS_OK(status
)) {
757 printf("lookupsids returned %s\n", nt_errstr(status
));
766 static bool test_LookupSids_async(struct dcerpc_pipe
*p
,
767 struct torture_context
*tctx
,
768 struct policy_handle
*handle
)
770 struct lsa_SidArray sids
;
771 struct lsa_SidPtr sidptr
;
773 struct lsa_TransNameArray
*names
;
774 struct lsa_LookupSids
*r
;
775 struct lsa_RefDomainList
*domains
= NULL
;
776 struct rpc_request
**req
;
779 const int num_async_requests
= 50;
781 count
= talloc_array(tctx
, uint32_t, num_async_requests
);
782 names
= talloc_array(tctx
, struct lsa_TransNameArray
, num_async_requests
);
783 r
= talloc_array(tctx
, struct lsa_LookupSids
, num_async_requests
);
785 torture_comment(tctx
, "\nTesting %d async lookupsids request\n", num_async_requests
);
787 req
= talloc_array(tctx
, struct rpc_request
*, num_async_requests
);
791 sidptr
.sid
= dom_sid_parse_talloc(tctx
, "S-1-5-32-545");
795 for (i
=0; i
<num_async_requests
; i
++) {
798 names
[i
].names
= NULL
;
800 r
[i
].in
.handle
= handle
;
801 r
[i
].in
.sids
= &sids
;
802 r
[i
].in
.names
= &names
[i
];
804 r
[i
].in
.count
= &names
[i
].count
;
805 r
[i
].out
.count
= &count
[i
];
806 r
[i
].out
.names
= &names
[i
];
807 r
[i
].out
.domains
= &domains
;
809 req
[i
] = dcerpc_lsa_LookupSids_send(p
, req
, &r
[i
]);
810 if (req
[i
] == NULL
) {
815 req
[i
]->async
.callback
= lookupsids_cb
;
816 req
[i
]->async
.private_data
= &replies
;
819 while (replies
>= 0 && replies
< num_async_requests
) {
820 event_loop_once(p
->conn
->event_ctx
);
832 static bool test_LookupPrivValue(struct dcerpc_pipe
*p
,
833 struct torture_context
*tctx
,
834 struct policy_handle
*handle
,
835 struct lsa_String
*name
)
838 struct lsa_LookupPrivValue r
;
839 struct lsa_LUID luid
;
841 r
.in
.handle
= handle
;
845 status
= dcerpc_lsa_LookupPrivValue(p
, tctx
, &r
);
846 if (!NT_STATUS_IS_OK(status
)) {
847 torture_comment(tctx
, "\nLookupPrivValue failed - %s\n", nt_errstr(status
));
854 static bool test_LookupPrivName(struct dcerpc_pipe
*p
,
855 struct torture_context
*tctx
,
856 struct policy_handle
*handle
,
857 struct lsa_LUID
*luid
)
860 struct lsa_LookupPrivName r
;
861 struct lsa_StringLarge
*name
= NULL
;
863 r
.in
.handle
= handle
;
867 status
= dcerpc_lsa_LookupPrivName(p
, tctx
, &r
);
868 if (!NT_STATUS_IS_OK(status
)) {
869 torture_comment(tctx
, "\nLookupPrivName failed - %s\n", nt_errstr(status
));
876 static bool test_RemovePrivilegesFromAccount(struct dcerpc_pipe
*p
,
877 struct torture_context
*tctx
,
878 struct policy_handle
*handle
,
879 struct policy_handle
*acct_handle
,
880 struct lsa_LUID
*luid
)
883 struct lsa_RemovePrivilegesFromAccount r
;
884 struct lsa_PrivilegeSet privs
;
887 torture_comment(tctx
, "\nTesting RemovePrivilegesFromAccount\n");
889 r
.in
.handle
= acct_handle
;
895 privs
.set
= talloc_array(tctx
, struct lsa_LUIDAttribute
, 1);
896 privs
.set
[0].luid
= *luid
;
897 privs
.set
[0].attribute
= 0;
899 status
= dcerpc_lsa_RemovePrivilegesFromAccount(p
, tctx
, &r
);
900 if (!NT_STATUS_IS_OK(status
)) {
902 struct lsa_LookupPrivName r_name
;
903 struct lsa_StringLarge
*name
= NULL
;
905 r_name
.in
.handle
= handle
;
906 r_name
.in
.luid
= luid
;
907 r_name
.out
.name
= &name
;
909 status
= dcerpc_lsa_LookupPrivName(p
, tctx
, &r_name
);
910 if (!NT_STATUS_IS_OK(status
)) {
911 torture_comment(tctx
, "\nLookupPrivName failed - %s\n", nt_errstr(status
));
914 /* Windows 2008 does not allow this to be removed */
915 if (strcmp("SeAuditPrivilege", name
->string
) == 0) {
919 torture_comment(tctx
, "RemovePrivilegesFromAccount failed to remove %s - %s\n",
928 static bool test_AddPrivilegesToAccount(struct dcerpc_pipe
*p
,
929 struct torture_context
*tctx
,
930 struct policy_handle
*acct_handle
,
931 struct lsa_LUID
*luid
)
934 struct lsa_AddPrivilegesToAccount r
;
935 struct lsa_PrivilegeSet privs
;
938 torture_comment(tctx
, "\nTesting AddPrivilegesToAccount\n");
940 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 status
= dcerpc_lsa_AddPrivilegesToAccount(p
, tctx
, &r
);
950 if (!NT_STATUS_IS_OK(status
)) {
951 torture_comment(tctx
, "AddPrivilegesToAccount failed - %s\n", nt_errstr(status
));
958 static bool test_EnumPrivsAccount(struct dcerpc_pipe
*p
,
959 struct torture_context
*tctx
,
960 struct policy_handle
*handle
,
961 struct policy_handle
*acct_handle
)
964 struct lsa_EnumPrivsAccount r
;
965 struct lsa_PrivilegeSet
*privs
= NULL
;
968 torture_comment(tctx
, "\nTesting EnumPrivsAccount\n");
970 r
.in
.handle
= acct_handle
;
971 r
.out
.privs
= &privs
;
973 status
= dcerpc_lsa_EnumPrivsAccount(p
, tctx
, &r
);
974 if (!NT_STATUS_IS_OK(status
)) {
975 torture_comment(tctx
, "EnumPrivsAccount failed - %s\n", nt_errstr(status
));
979 if (privs
&& privs
->count
> 0) {
981 for (i
=0;i
<privs
->count
;i
++) {
982 test_LookupPrivName(p
, tctx
, handle
,
983 &privs
->set
[i
].luid
);
986 ret
&= test_RemovePrivilegesFromAccount(p
, tctx
, handle
, acct_handle
,
987 &privs
->set
[0].luid
);
988 ret
&= test_AddPrivilegesToAccount(p
, tctx
, acct_handle
,
989 &privs
->set
[0].luid
);
995 static bool test_GetSystemAccessAccount(struct dcerpc_pipe
*p
,
996 struct torture_context
*tctx
,
997 struct policy_handle
*handle
,
998 struct policy_handle
*acct_handle
)
1001 uint32_t access_mask
;
1002 struct lsa_GetSystemAccessAccount r
;
1004 torture_comment(tctx
, "\nTesting GetSystemAccessAccount\n");
1006 r
.in
.handle
= acct_handle
;
1007 r
.out
.access_mask
= &access_mask
;
1009 status
= dcerpc_lsa_GetSystemAccessAccount(p
, tctx
, &r
);
1010 if (!NT_STATUS_IS_OK(status
)) {
1011 torture_comment(tctx
, "GetSystemAccessAccount failed - %s\n", nt_errstr(status
));
1015 if (r
.out
.access_mask
!= NULL
) {
1016 torture_comment(tctx
, "Rights:");
1017 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_INTERACTIVE
)
1018 torture_comment(tctx
, " LSA_POLICY_MODE_INTERACTIVE");
1019 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_NETWORK
)
1020 torture_comment(tctx
, " LSA_POLICY_MODE_NETWORK");
1021 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_BATCH
)
1022 torture_comment(tctx
, " LSA_POLICY_MODE_BATCH");
1023 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_SERVICE
)
1024 torture_comment(tctx
, " LSA_POLICY_MODE_SERVICE");
1025 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_PROXY
)
1026 torture_comment(tctx
, " LSA_POLICY_MODE_PROXY");
1027 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_INTERACTIVE
)
1028 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_INTERACTIVE");
1029 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_NETWORK
)
1030 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_NETWORK");
1031 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_BATCH
)
1032 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_BATCH");
1033 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_SERVICE
)
1034 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_SERVICE");
1035 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_REMOTE_INTERACTIVE
)
1036 torture_comment(tctx
, " LSA_POLICY_MODE_REMOTE_INTERACTIVE");
1037 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_REMOTE_INTERACTIVE
)
1038 torture_comment(tctx
, " LSA_POLICY_MODE_DENY_REMOTE_INTERACTIVE");
1039 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_ALL
)
1040 torture_comment(tctx
, " LSA_POLICY_MODE_ALL");
1041 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_ALL_NT4
)
1042 torture_comment(tctx
, " LSA_POLICY_MODE_ALL_NT4");
1043 torture_comment(tctx
, "\n");
1049 static bool test_Delete(struct dcerpc_pipe
*p
,
1050 struct torture_context
*tctx
,
1051 struct policy_handle
*handle
)
1054 struct lsa_Delete r
;
1056 torture_comment(tctx
, "\nTesting Delete\n");
1058 r
.in
.handle
= handle
;
1059 status
= dcerpc_lsa_Delete(p
, tctx
, &r
);
1060 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NOT_SUPPORTED
)) {
1061 torture_comment(tctx
, "Delete should have failed NT_STATUS_NOT_SUPPORTED - %s\n", nt_errstr(status
));
1068 static bool test_DeleteObject(struct dcerpc_pipe
*p
,
1069 struct torture_context
*tctx
,
1070 struct policy_handle
*handle
)
1073 struct lsa_DeleteObject r
;
1075 torture_comment(tctx
, "\nTesting DeleteObject\n");
1077 r
.in
.handle
= handle
;
1078 r
.out
.handle
= handle
;
1079 status
= dcerpc_lsa_DeleteObject(p
, tctx
, &r
);
1080 if (!NT_STATUS_IS_OK(status
)) {
1081 torture_comment(tctx
, "DeleteObject failed - %s\n", nt_errstr(status
));
1089 static bool test_CreateAccount(struct dcerpc_pipe
*p
,
1090 struct torture_context
*tctx
,
1091 struct policy_handle
*handle
)
1094 struct lsa_CreateAccount r
;
1095 struct dom_sid2
*newsid
;
1096 struct policy_handle acct_handle
;
1098 newsid
= dom_sid_parse_talloc(tctx
, "S-1-5-12349876-4321-2854");
1100 torture_comment(tctx
, "\nTesting CreateAccount\n");
1102 r
.in
.handle
= handle
;
1104 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1105 r
.out
.acct_handle
= &acct_handle
;
1107 status
= dcerpc_lsa_CreateAccount(p
, tctx
, &r
);
1108 if (NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
1109 struct lsa_OpenAccount r_o
;
1110 r_o
.in
.handle
= handle
;
1111 r_o
.in
.sid
= newsid
;
1112 r_o
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1113 r_o
.out
.acct_handle
= &acct_handle
;
1115 status
= dcerpc_lsa_OpenAccount(p
, tctx
, &r_o
);
1116 if (!NT_STATUS_IS_OK(status
)) {
1117 torture_comment(tctx
, "OpenAccount failed - %s\n", nt_errstr(status
));
1120 } else if (!NT_STATUS_IS_OK(status
)) {
1121 torture_comment(tctx
, "CreateAccount failed - %s\n", nt_errstr(status
));
1125 if (!test_Delete(p
, tctx
, &acct_handle
)) {
1129 if (!test_DeleteObject(p
, tctx
, &acct_handle
)) {
1136 static bool test_DeleteTrustedDomain(struct dcerpc_pipe
*p
,
1137 struct torture_context
*tctx
,
1138 struct policy_handle
*handle
,
1139 struct lsa_StringLarge name
)
1142 struct lsa_OpenTrustedDomainByName r
;
1143 struct policy_handle trustdom_handle
;
1145 r
.in
.handle
= handle
;
1146 r
.in
.name
.string
= name
.string
;
1147 r
.in
.access_mask
= SEC_STD_DELETE
;
1148 r
.out
.trustdom_handle
= &trustdom_handle
;
1150 status
= dcerpc_lsa_OpenTrustedDomainByName(p
, tctx
, &r
);
1151 if (!NT_STATUS_IS_OK(status
)) {
1152 torture_comment(tctx
, "OpenTrustedDomainByName failed - %s\n", nt_errstr(status
));
1156 if (!test_Delete(p
, tctx
, &trustdom_handle
)) {
1160 if (!test_DeleteObject(p
, tctx
, &trustdom_handle
)) {
1167 static bool test_DeleteTrustedDomainBySid(struct dcerpc_pipe
*p
,
1168 struct torture_context
*tctx
,
1169 struct policy_handle
*handle
,
1170 struct dom_sid
*sid
)
1173 struct lsa_DeleteTrustedDomain r
;
1175 r
.in
.handle
= handle
;
1178 status
= dcerpc_lsa_DeleteTrustedDomain(p
, tctx
, &r
);
1179 if (!NT_STATUS_IS_OK(status
)) {
1180 torture_comment(tctx
, "DeleteTrustedDomain failed - %s\n", nt_errstr(status
));
1188 static bool test_CreateSecret(struct dcerpc_pipe
*p
,
1189 struct torture_context
*tctx
,
1190 struct policy_handle
*handle
)
1193 struct lsa_CreateSecret r
;
1194 struct lsa_OpenSecret r2
;
1195 struct lsa_SetSecret r3
;
1196 struct lsa_QuerySecret r4
;
1197 struct lsa_SetSecret r5
;
1198 struct lsa_QuerySecret r6
;
1199 struct lsa_SetSecret r7
;
1200 struct lsa_QuerySecret r8
;
1201 struct policy_handle sec_handle
, sec_handle2
, sec_handle3
;
1202 struct lsa_DeleteObject d_o
;
1203 struct lsa_DATA_BUF buf1
;
1204 struct lsa_DATA_BUF_PTR bufp1
;
1205 struct lsa_DATA_BUF_PTR bufp2
;
1208 DATA_BLOB session_key
;
1209 NTTIME old_mtime
, new_mtime
;
1210 DATA_BLOB blob1
, blob2
;
1211 const char *secret1
= "abcdef12345699qwerty";
1213 const char *secret3
= "ABCDEF12345699QWERTY";
1215 const char *secret5
= "NEW-SAMBA4-SECRET";
1219 const int LOCAL
= 0;
1220 const int GLOBAL
= 1;
1222 secname
[LOCAL
] = talloc_asprintf(tctx
, "torturesecret-%u", (unsigned int)random());
1223 secname
[GLOBAL
] = talloc_asprintf(tctx
, "G$torturesecret-%u", (unsigned int)random());
1225 for (i
=0; i
< 2; i
++) {
1226 torture_comment(tctx
, "\nTesting CreateSecret of %s\n", secname
[i
]);
1228 init_lsa_String(&r
.in
.name
, secname
[i
]);
1230 r
.in
.handle
= handle
;
1231 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1232 r
.out
.sec_handle
= &sec_handle
;
1234 status
= dcerpc_lsa_CreateSecret(p
, tctx
, &r
);
1235 if (!NT_STATUS_IS_OK(status
)) {
1236 torture_comment(tctx
, "CreateSecret failed - %s\n", nt_errstr(status
));
1240 r
.in
.handle
= handle
;
1241 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1242 r
.out
.sec_handle
= &sec_handle3
;
1244 status
= dcerpc_lsa_CreateSecret(p
, tctx
, &r
);
1245 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
1246 torture_comment(tctx
, "CreateSecret should have failed OBJECT_NAME_COLLISION - %s\n", nt_errstr(status
));
1250 r2
.in
.handle
= handle
;
1251 r2
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1252 r2
.in
.name
= r
.in
.name
;
1253 r2
.out
.sec_handle
= &sec_handle2
;
1255 torture_comment(tctx
, "Testing OpenSecret\n");
1257 status
= dcerpc_lsa_OpenSecret(p
, tctx
, &r2
);
1258 if (!NT_STATUS_IS_OK(status
)) {
1259 torture_comment(tctx
, "OpenSecret failed - %s\n", nt_errstr(status
));
1263 status
= dcerpc_fetch_session_key(p
, &session_key
);
1264 if (!NT_STATUS_IS_OK(status
)) {
1265 torture_comment(tctx
, "dcerpc_fetch_session_key failed - %s\n", nt_errstr(status
));
1269 enc_key
= sess_encrypt_string(secret1
, &session_key
);
1271 r3
.in
.sec_handle
= &sec_handle
;
1272 r3
.in
.new_val
= &buf1
;
1273 r3
.in
.old_val
= NULL
;
1274 r3
.in
.new_val
->data
= enc_key
.data
;
1275 r3
.in
.new_val
->length
= enc_key
.length
;
1276 r3
.in
.new_val
->size
= enc_key
.length
;
1278 torture_comment(tctx
, "Testing SetSecret\n");
1280 status
= dcerpc_lsa_SetSecret(p
, tctx
, &r3
);
1281 if (!NT_STATUS_IS_OK(status
)) {
1282 torture_comment(tctx
, "SetSecret failed - %s\n", nt_errstr(status
));
1286 r3
.in
.sec_handle
= &sec_handle
;
1287 r3
.in
.new_val
= &buf1
;
1288 r3
.in
.old_val
= NULL
;
1289 r3
.in
.new_val
->data
= enc_key
.data
;
1290 r3
.in
.new_val
->length
= enc_key
.length
;
1291 r3
.in
.new_val
->size
= enc_key
.length
;
1293 /* break the encrypted data */
1296 torture_comment(tctx
, "Testing SetSecret with broken key\n");
1298 status
= dcerpc_lsa_SetSecret(p
, tctx
, &r3
);
1299 if (!NT_STATUS_EQUAL(status
, NT_STATUS_UNKNOWN_REVISION
)) {
1300 torture_comment(tctx
, "SetSecret should have failed UNKNOWN_REVISION - %s\n", nt_errstr(status
));
1304 data_blob_free(&enc_key
);
1306 ZERO_STRUCT(new_mtime
);
1307 ZERO_STRUCT(old_mtime
);
1309 /* fetch the secret back again */
1310 r4
.in
.sec_handle
= &sec_handle
;
1311 r4
.in
.new_val
= &bufp1
;
1312 r4
.in
.new_mtime
= &new_mtime
;
1313 r4
.in
.old_val
= NULL
;
1314 r4
.in
.old_mtime
= NULL
;
1318 torture_comment(tctx
, "Testing QuerySecret\n");
1319 status
= dcerpc_lsa_QuerySecret(p
, tctx
, &r4
);
1320 if (!NT_STATUS_IS_OK(status
)) {
1321 torture_comment(tctx
, "QuerySecret failed - %s\n", nt_errstr(status
));
1324 if (r4
.out
.new_val
== NULL
|| r4
.out
.new_val
->buf
== NULL
) {
1325 torture_comment(tctx
, "No secret buffer returned\n");
1328 blob1
.data
= r4
.out
.new_val
->buf
->data
;
1329 blob1
.length
= r4
.out
.new_val
->buf
->size
;
1331 blob2
= data_blob_talloc(tctx
, NULL
, blob1
.length
);
1333 secret2
= sess_decrypt_string(tctx
,
1334 &blob1
, &session_key
);
1336 if (strcmp(secret1
, secret2
) != 0) {
1337 torture_comment(tctx
, "Returned secret (r4) '%s' doesn't match '%s'\n",
1344 enc_key
= sess_encrypt_string(secret3
, &session_key
);
1346 r5
.in
.sec_handle
= &sec_handle
;
1347 r5
.in
.new_val
= &buf1
;
1348 r5
.in
.old_val
= NULL
;
1349 r5
.in
.new_val
->data
= enc_key
.data
;
1350 r5
.in
.new_val
->length
= enc_key
.length
;
1351 r5
.in
.new_val
->size
= enc_key
.length
;
1355 torture_comment(tctx
, "Testing SetSecret (existing value should move to old)\n");
1357 status
= dcerpc_lsa_SetSecret(p
, tctx
, &r5
);
1358 if (!NT_STATUS_IS_OK(status
)) {
1359 torture_comment(tctx
, "SetSecret failed - %s\n", nt_errstr(status
));
1363 data_blob_free(&enc_key
);
1365 ZERO_STRUCT(new_mtime
);
1366 ZERO_STRUCT(old_mtime
);
1368 /* fetch the secret back again */
1369 r6
.in
.sec_handle
= &sec_handle
;
1370 r6
.in
.new_val
= &bufp1
;
1371 r6
.in
.new_mtime
= &new_mtime
;
1372 r6
.in
.old_val
= &bufp2
;
1373 r6
.in
.old_mtime
= &old_mtime
;
1378 status
= dcerpc_lsa_QuerySecret(p
, tctx
, &r6
);
1379 if (!NT_STATUS_IS_OK(status
)) {
1380 torture_comment(tctx
, "QuerySecret failed - %s\n", nt_errstr(status
));
1385 if (r6
.out
.new_val
->buf
== NULL
|| r6
.out
.old_val
->buf
== NULL
1386 || r6
.out
.new_mtime
== NULL
|| r6
.out
.old_mtime
== NULL
) {
1387 torture_comment(tctx
, "Both secret buffers and both times not returned\n");
1391 blob1
.data
= r6
.out
.new_val
->buf
->data
;
1392 blob1
.length
= r6
.out
.new_val
->buf
->size
;
1394 blob2
= data_blob_talloc(tctx
, NULL
, blob1
.length
);
1396 secret4
= sess_decrypt_string(tctx
,
1397 &blob1
, &session_key
);
1399 if (strcmp(secret3
, secret4
) != 0) {
1400 torture_comment(tctx
, "Returned NEW secret %s doesn't match %s\n", secret4
, secret3
);
1404 blob1
.data
= r6
.out
.old_val
->buf
->data
;
1405 blob1
.length
= r6
.out
.old_val
->buf
->length
;
1407 blob2
= data_blob_talloc(tctx
, NULL
, blob1
.length
);
1409 secret2
= sess_decrypt_string(tctx
,
1410 &blob1
, &session_key
);
1412 if (strcmp(secret1
, secret2
) != 0) {
1413 torture_comment(tctx
, "Returned OLD secret %s doesn't match %s\n", secret2
, secret1
);
1417 if (*r6
.out
.new_mtime
== *r6
.out
.old_mtime
) {
1418 torture_comment(tctx
, "Returned secret (r6-%d) %s must not have same mtime for both secrets: %s != %s\n",
1421 nt_time_string(tctx
, *r6
.out
.old_mtime
),
1422 nt_time_string(tctx
, *r6
.out
.new_mtime
));
1428 enc_key
= sess_encrypt_string(secret5
, &session_key
);
1430 r7
.in
.sec_handle
= &sec_handle
;
1431 r7
.in
.old_val
= &buf1
;
1432 r7
.in
.old_val
->data
= enc_key
.data
;
1433 r7
.in
.old_val
->length
= enc_key
.length
;
1434 r7
.in
.old_val
->size
= enc_key
.length
;
1435 r7
.in
.new_val
= NULL
;
1437 torture_comment(tctx
, "Testing SetSecret of old Secret only\n");
1439 status
= dcerpc_lsa_SetSecret(p
, tctx
, &r7
);
1440 if (!NT_STATUS_IS_OK(status
)) {
1441 torture_comment(tctx
, "SetSecret failed - %s\n", nt_errstr(status
));
1445 data_blob_free(&enc_key
);
1447 /* fetch the secret back again */
1448 r8
.in
.sec_handle
= &sec_handle
;
1449 r8
.in
.new_val
= &bufp1
;
1450 r8
.in
.new_mtime
= &new_mtime
;
1451 r8
.in
.old_val
= &bufp2
;
1452 r8
.in
.old_mtime
= &old_mtime
;
1457 status
= dcerpc_lsa_QuerySecret(p
, tctx
, &r8
);
1458 if (!NT_STATUS_IS_OK(status
)) {
1459 torture_comment(tctx
, "QuerySecret failed - %s\n", nt_errstr(status
));
1462 if (!r8
.out
.new_val
|| !r8
.out
.old_val
) {
1463 torture_comment(tctx
, "in/out pointers not returned, despite being set on in for QuerySecret\n");
1465 } else if (r8
.out
.new_val
->buf
!= NULL
) {
1466 torture_comment(tctx
, "NEW secret buffer must not be returned after OLD set\n");
1468 } else if (r8
.out
.old_val
->buf
== NULL
) {
1469 torture_comment(tctx
, "OLD secret buffer was not returned after OLD set\n");
1471 } else if (r8
.out
.new_mtime
== NULL
|| r8
.out
.old_mtime
== NULL
) {
1472 torture_comment(tctx
, "Both times not returned after OLD set\n");
1475 blob1
.data
= r8
.out
.old_val
->buf
->data
;
1476 blob1
.length
= r8
.out
.old_val
->buf
->size
;
1478 blob2
= data_blob_talloc(tctx
, NULL
, blob1
.length
);
1480 secret6
= sess_decrypt_string(tctx
,
1481 &blob1
, &session_key
);
1483 if (strcmp(secret5
, secret6
) != 0) {
1484 torture_comment(tctx
, "Returned OLD secret %s doesn't match %s\n", secret5
, secret6
);
1488 if (*r8
.out
.new_mtime
!= *r8
.out
.old_mtime
) {
1489 torture_comment(tctx
, "Returned secret (r8) %s did not had same mtime for both secrets: %s != %s\n",
1491 nt_time_string(tctx
, *r8
.out
.old_mtime
),
1492 nt_time_string(tctx
, *r8
.out
.new_mtime
));
1498 if (!test_Delete(p
, tctx
, &sec_handle
)) {
1502 if (!test_DeleteObject(p
, tctx
, &sec_handle
)) {
1506 d_o
.in
.handle
= &sec_handle2
;
1507 d_o
.out
.handle
= &sec_handle2
;
1508 status
= dcerpc_lsa_DeleteObject(p
, tctx
, &d_o
);
1509 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1510 torture_comment(tctx
, "Second delete expected INVALID_HANDLE - %s\n", nt_errstr(status
));
1514 torture_comment(tctx
, "Testing OpenSecret of just-deleted secret\n");
1516 status
= dcerpc_lsa_OpenSecret(p
, tctx
, &r2
);
1517 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
1518 torture_comment(tctx
, "OpenSecret expected OBJECT_NAME_NOT_FOUND - %s\n", nt_errstr(status
));
1529 static bool test_EnumAccountRights(struct dcerpc_pipe
*p
,
1530 struct torture_context
*tctx
,
1531 struct policy_handle
*acct_handle
,
1532 struct dom_sid
*sid
)
1535 struct lsa_EnumAccountRights r
;
1536 struct lsa_RightSet rights
;
1538 torture_comment(tctx
, "\nTesting EnumAccountRights\n");
1540 r
.in
.handle
= acct_handle
;
1542 r
.out
.rights
= &rights
;
1544 status
= dcerpc_lsa_EnumAccountRights(p
, tctx
, &r
);
1545 if (!NT_STATUS_IS_OK(status
)) {
1546 torture_comment(tctx
, "EnumAccountRights of %s failed - %s\n",
1547 dom_sid_string(tctx
, sid
), nt_errstr(status
));
1555 static bool test_QuerySecurity(struct dcerpc_pipe
*p
,
1556 struct torture_context
*tctx
,
1557 struct policy_handle
*handle
,
1558 struct policy_handle
*acct_handle
)
1561 struct lsa_QuerySecurity r
;
1562 struct sec_desc_buf
*sdbuf
= NULL
;
1564 if (torture_setting_bool(tctx
, "samba4", false)) {
1565 torture_comment(tctx
, "\nskipping QuerySecurity test against Samba4\n");
1569 torture_comment(tctx
, "\nTesting QuerySecurity\n");
1571 r
.in
.handle
= acct_handle
;
1572 r
.in
.sec_info
= SECINFO_OWNER
|
1575 r
.out
.sdbuf
= &sdbuf
;
1577 status
= dcerpc_lsa_QuerySecurity(p
, tctx
, &r
);
1578 if (!NT_STATUS_IS_OK(status
)) {
1579 torture_comment(tctx
, "QuerySecurity failed - %s\n", nt_errstr(status
));
1586 static bool test_OpenAccount(struct dcerpc_pipe
*p
,
1587 struct torture_context
*tctx
,
1588 struct policy_handle
*handle
,
1589 struct dom_sid
*sid
)
1592 struct lsa_OpenAccount r
;
1593 struct policy_handle acct_handle
;
1595 torture_comment(tctx
, "\nTesting OpenAccount\n");
1597 r
.in
.handle
= handle
;
1599 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1600 r
.out
.acct_handle
= &acct_handle
;
1602 status
= dcerpc_lsa_OpenAccount(p
, tctx
, &r
);
1603 if (!NT_STATUS_IS_OK(status
)) {
1604 torture_comment(tctx
, "OpenAccount failed - %s\n", nt_errstr(status
));
1608 if (!test_EnumPrivsAccount(p
, tctx
, handle
, &acct_handle
)) {
1612 if (!test_GetSystemAccessAccount(p
, tctx
, handle
, &acct_handle
)) {
1616 if (!test_QuerySecurity(p
, tctx
, handle
, &acct_handle
)) {
1623 static bool test_EnumAccounts(struct dcerpc_pipe
*p
,
1624 struct torture_context
*tctx
,
1625 struct policy_handle
*handle
)
1628 struct lsa_EnumAccounts r
;
1629 struct lsa_SidArray sids1
, sids2
;
1630 uint32_t resume_handle
= 0;
1634 torture_comment(tctx
, "\nTesting EnumAccounts\n");
1636 r
.in
.handle
= handle
;
1637 r
.in
.resume_handle
= &resume_handle
;
1638 r
.in
.num_entries
= 100;
1639 r
.out
.resume_handle
= &resume_handle
;
1640 r
.out
.sids
= &sids1
;
1644 status
= dcerpc_lsa_EnumAccounts(p
, tctx
, &r
);
1645 if (NT_STATUS_EQUAL(status
, NT_STATUS_NO_MORE_ENTRIES
)) {
1648 if (!NT_STATUS_IS_OK(status
)) {
1649 torture_comment(tctx
, "EnumAccounts failed - %s\n", nt_errstr(status
));
1653 if (!test_LookupSids(p
, tctx
, handle
, &sids1
)) {
1657 if (!test_LookupSids2(p
, tctx
, handle
, &sids1
)) {
1661 /* Can't test lookupSids3 here, as clearly we must not
1662 * be on schannel, or we would not be able to do the
1665 torture_comment(tctx
, "Testing all accounts\n");
1666 for (i
=0;i
<sids1
.num_sids
;i
++) {
1667 ret
&= test_OpenAccount(p
, tctx
, handle
, sids1
.sids
[i
].sid
);
1668 ret
&= test_EnumAccountRights(p
, tctx
, handle
, sids1
.sids
[i
].sid
);
1670 torture_comment(tctx
, "\n");
1673 if (sids1
.num_sids
< 3) {
1677 torture_comment(tctx
, "Trying EnumAccounts partial listing (asking for 1 at 2)\n");
1679 r
.in
.num_entries
= 1;
1680 r
.out
.sids
= &sids2
;
1682 status
= dcerpc_lsa_EnumAccounts(p
, tctx
, &r
);
1683 if (!NT_STATUS_IS_OK(status
)) {
1684 torture_comment(tctx
, "EnumAccounts failed - %s\n", nt_errstr(status
));
1688 if (sids2
.num_sids
!= 1) {
1689 torture_comment(tctx
, "Returned wrong number of entries (%d)\n", sids2
.num_sids
);
1696 static bool test_LookupPrivDisplayName(struct dcerpc_pipe
*p
,
1697 struct torture_context
*tctx
,
1698 struct policy_handle
*handle
,
1699 struct lsa_String
*priv_name
)
1701 struct lsa_LookupPrivDisplayName r
;
1703 /* produce a reasonable range of language output without screwing up
1705 uint16_t language_id
= (random() % 4) + 0x409;
1706 uint16_t returned_language_id
= 0;
1707 struct lsa_StringLarge
*disp_name
= NULL
;
1709 torture_comment(tctx
, "\nTesting LookupPrivDisplayName(%s)\n", priv_name
->string
);
1711 r
.in
.handle
= handle
;
1712 r
.in
.name
= priv_name
;
1713 r
.in
.language_id
= language_id
;
1714 r
.in
.language_id_sys
= 0;
1715 r
.out
.returned_language_id
= &returned_language_id
;
1716 r
.out
.disp_name
= &disp_name
;
1718 status
= dcerpc_lsa_LookupPrivDisplayName(p
, tctx
, &r
);
1719 if (!NT_STATUS_IS_OK(status
)) {
1720 torture_comment(tctx
, "LookupPrivDisplayName failed - %s\n", nt_errstr(status
));
1723 torture_comment(tctx
, "%s -> \"%s\" (language 0x%x/0x%x)\n",
1724 priv_name
->string
, disp_name
->string
,
1725 r
.in
.language_id
, *r
.out
.returned_language_id
);
1730 static bool test_EnumAccountsWithUserRight(struct dcerpc_pipe
*p
,
1731 struct torture_context
*tctx
,
1732 struct policy_handle
*handle
,
1733 struct lsa_String
*priv_name
)
1735 struct lsa_EnumAccountsWithUserRight r
;
1736 struct lsa_SidArray sids
;
1741 torture_comment(tctx
, "\nTesting EnumAccountsWithUserRight(%s)\n", priv_name
->string
);
1743 r
.in
.handle
= handle
;
1744 r
.in
.name
= priv_name
;
1747 status
= dcerpc_lsa_EnumAccountsWithUserRight(p
, tctx
, &r
);
1749 /* NT_STATUS_NO_MORE_ENTRIES means noone has this privilege */
1750 if (NT_STATUS_EQUAL(status
, NT_STATUS_NO_MORE_ENTRIES
)) {
1754 if (!NT_STATUS_IS_OK(status
)) {
1755 torture_comment(tctx
, "EnumAccountsWithUserRight failed - %s\n", nt_errstr(status
));
1763 static bool test_EnumPrivs(struct dcerpc_pipe
*p
,
1764 struct torture_context
*tctx
,
1765 struct policy_handle
*handle
)
1768 struct lsa_EnumPrivs r
;
1769 struct lsa_PrivArray privs1
;
1770 uint32_t resume_handle
= 0;
1774 torture_comment(tctx
, "\nTesting EnumPrivs\n");
1776 r
.in
.handle
= handle
;
1777 r
.in
.resume_handle
= &resume_handle
;
1778 r
.in
.max_count
= 100;
1779 r
.out
.resume_handle
= &resume_handle
;
1780 r
.out
.privs
= &privs1
;
1783 status
= dcerpc_lsa_EnumPrivs(p
, tctx
, &r
);
1784 if (!NT_STATUS_IS_OK(status
)) {
1785 torture_comment(tctx
, "EnumPrivs failed - %s\n", nt_errstr(status
));
1789 for (i
= 0; i
< privs1
.count
; i
++) {
1790 test_LookupPrivDisplayName(p
, tctx
, handle
, (struct lsa_String
*)&privs1
.privs
[i
].name
);
1791 test_LookupPrivValue(p
, tctx
, handle
, (struct lsa_String
*)&privs1
.privs
[i
].name
);
1792 if (!test_EnumAccountsWithUserRight(p
, tctx
, handle
, (struct lsa_String
*)&privs1
.privs
[i
].name
)) {
1800 static bool test_QueryForestTrustInformation(struct dcerpc_pipe
*p
,
1801 struct torture_context
*tctx
,
1802 struct policy_handle
*handle
,
1803 const char *trusted_domain_name
)
1806 struct lsa_lsaRQueryForestTrustInformation r
;
1808 struct lsa_String string
;
1809 struct lsa_ForestTrustInformation info
, *info_ptr
;
1811 torture_comment(tctx
, "\nTesting lsaRQueryForestTrustInformation\n");
1813 if (torture_setting_bool(tctx
, "samba4", false)) {
1814 torture_comment(tctx
, "skipping QueryForestTrustInformation against Samba4\n");
1818 ZERO_STRUCT(string
);
1820 if (trusted_domain_name
) {
1821 init_lsa_String(&string
, trusted_domain_name
);
1826 r
.in
.handle
= handle
;
1827 r
.in
.trusted_domain_name
= &string
;
1829 r
.out
.forest_trust_info
= &info_ptr
;
1831 status
= dcerpc_lsa_lsaRQueryForestTrustInformation(p
, tctx
, &r
);
1833 if (!NT_STATUS_IS_OK(status
)) {
1834 torture_comment(tctx
, "lsaRQueryForestTrustInformation of %s failed - %s\n", trusted_domain_name
, nt_errstr(status
));
1841 static bool test_query_each_TrustDomEx(struct dcerpc_pipe
*p
,
1842 struct torture_context
*tctx
,
1843 struct policy_handle
*handle
,
1844 struct lsa_DomainListEx
*domains
)
1849 for (i
=0; i
< domains
->count
; i
++) {
1851 if (domains
->domains
[i
].trust_attributes
& NETR_TRUST_ATTRIBUTE_FOREST_TRANSITIVE
) {
1852 ret
&= test_QueryForestTrustInformation(p
, tctx
, handle
,
1853 domains
->domains
[i
].domain_name
.string
);
1860 static bool test_query_each_TrustDom(struct dcerpc_pipe
*p
,
1861 struct torture_context
*tctx
,
1862 struct policy_handle
*handle
,
1863 struct lsa_DomainList
*domains
)
1869 torture_comment(tctx
, "\nTesting OpenTrustedDomain, OpenTrustedDomainByName and QueryInfoTrustedDomain\n");
1870 for (i
=0; i
< domains
->count
; i
++) {
1871 struct lsa_OpenTrustedDomain trust
;
1872 struct lsa_OpenTrustedDomainByName trust_by_name
;
1873 struct policy_handle trustdom_handle
;
1874 struct policy_handle handle2
;
1876 struct lsa_CloseTrustedDomainEx c_trust
;
1877 int levels
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
1878 int ok
[] = {1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1};
1880 if (domains
->domains
[i
].sid
) {
1881 trust
.in
.handle
= handle
;
1882 trust
.in
.sid
= domains
->domains
[i
].sid
;
1883 trust
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1884 trust
.out
.trustdom_handle
= &trustdom_handle
;
1886 status
= dcerpc_lsa_OpenTrustedDomain(p
, tctx
, &trust
);
1888 if (!NT_STATUS_IS_OK(status
)) {
1889 torture_comment(tctx
, "OpenTrustedDomain failed - %s\n", nt_errstr(status
));
1893 c
.in
.handle
= &trustdom_handle
;
1894 c
.out
.handle
= &handle2
;
1896 c_trust
.in
.handle
= &trustdom_handle
;
1897 c_trust
.out
.handle
= &handle2
;
1899 for (j
=0; j
< ARRAY_SIZE(levels
); j
++) {
1900 struct lsa_QueryTrustedDomainInfo q
;
1901 union lsa_TrustedDomainInfo
*info
= NULL
;
1902 q
.in
.trustdom_handle
= &trustdom_handle
;
1903 q
.in
.level
= levels
[j
];
1905 status
= dcerpc_lsa_QueryTrustedDomainInfo(p
, tctx
, &q
);
1906 if (!NT_STATUS_IS_OK(status
) && ok
[j
]) {
1907 torture_comment(tctx
, "QueryTrustedDomainInfo level %d failed - %s\n",
1908 levels
[j
], nt_errstr(status
));
1910 } else if (NT_STATUS_IS_OK(status
) && !ok
[j
]) {
1911 torture_comment(tctx
, "QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
1912 levels
[j
], nt_errstr(status
));
1917 status
= dcerpc_lsa_CloseTrustedDomainEx(p
, tctx
, &c_trust
);
1918 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NOT_IMPLEMENTED
)) {
1919 torture_comment(tctx
, "Expected CloseTrustedDomainEx to return NT_STATUS_NOT_IMPLEMENTED, instead - %s\n", nt_errstr(status
));
1923 c
.in
.handle
= &trustdom_handle
;
1924 c
.out
.handle
= &handle2
;
1926 status
= dcerpc_lsa_Close(p
, tctx
, &c
);
1927 if (!NT_STATUS_IS_OK(status
)) {
1928 torture_comment(tctx
, "Close of trusted domain failed - %s\n", nt_errstr(status
));
1932 for (j
=0; j
< ARRAY_SIZE(levels
); j
++) {
1933 struct lsa_QueryTrustedDomainInfoBySid q
;
1934 union lsa_TrustedDomainInfo
*info
= NULL
;
1936 if (!domains
->domains
[i
].sid
) {
1940 q
.in
.handle
= handle
;
1941 q
.in
.dom_sid
= domains
->domains
[i
].sid
;
1942 q
.in
.level
= levels
[j
];
1945 status
= dcerpc_lsa_QueryTrustedDomainInfoBySid(p
, tctx
, &q
);
1946 if (!NT_STATUS_IS_OK(status
) && ok
[j
]) {
1947 torture_comment(tctx
, "QueryTrustedDomainInfoBySid level %d failed - %s\n",
1948 levels
[j
], nt_errstr(status
));
1950 } else if (NT_STATUS_IS_OK(status
) && !ok
[j
]) {
1951 torture_comment(tctx
, "QueryTrustedDomainInfoBySid level %d unexpectedly succeeded - %s\n",
1952 levels
[j
], nt_errstr(status
));
1958 trust_by_name
.in
.handle
= handle
;
1959 trust_by_name
.in
.name
.string
= domains
->domains
[i
].name
.string
;
1960 trust_by_name
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1961 trust_by_name
.out
.trustdom_handle
= &trustdom_handle
;
1963 status
= dcerpc_lsa_OpenTrustedDomainByName(p
, tctx
, &trust_by_name
);
1965 if (!NT_STATUS_IS_OK(status
)) {
1966 torture_comment(tctx
, "OpenTrustedDomainByName failed - %s\n", nt_errstr(status
));
1970 for (j
=0; j
< ARRAY_SIZE(levels
); j
++) {
1971 struct lsa_QueryTrustedDomainInfo q
;
1972 union lsa_TrustedDomainInfo
*info
= NULL
;
1973 q
.in
.trustdom_handle
= &trustdom_handle
;
1974 q
.in
.level
= levels
[j
];
1976 status
= dcerpc_lsa_QueryTrustedDomainInfo(p
, tctx
, &q
);
1977 if (!NT_STATUS_IS_OK(status
) && ok
[j
]) {
1978 torture_comment(tctx
, "QueryTrustedDomainInfo level %d failed - %s\n",
1979 levels
[j
], nt_errstr(status
));
1981 } else if (NT_STATUS_IS_OK(status
) && !ok
[j
]) {
1982 torture_comment(tctx
, "QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
1983 levels
[j
], nt_errstr(status
));
1988 c
.in
.handle
= &trustdom_handle
;
1989 c
.out
.handle
= &handle2
;
1991 status
= dcerpc_lsa_Close(p
, tctx
, &c
);
1992 if (!NT_STATUS_IS_OK(status
)) {
1993 torture_comment(tctx
, "Close of trusted domain failed - %s\n", nt_errstr(status
));
1997 for (j
=0; j
< ARRAY_SIZE(levels
); j
++) {
1998 struct lsa_QueryTrustedDomainInfoByName q
;
1999 union lsa_TrustedDomainInfo
*info
= NULL
;
2000 struct lsa_String name
;
2002 name
.string
= domains
->domains
[i
].name
.string
;
2004 q
.in
.handle
= handle
;
2005 q
.in
.trusted_domain
= &name
;
2006 q
.in
.level
= levels
[j
];
2008 status
= dcerpc_lsa_QueryTrustedDomainInfoByName(p
, tctx
, &q
);
2009 if (!NT_STATUS_IS_OK(status
) && ok
[j
]) {
2010 torture_comment(tctx
, "QueryTrustedDomainInfoByName level %d failed - %s\n",
2011 levels
[j
], nt_errstr(status
));
2013 } else if (NT_STATUS_IS_OK(status
) && !ok
[j
]) {
2014 torture_comment(tctx
, "QueryTrustedDomainInfoByName level %d unexpectedly succeeded - %s\n",
2015 levels
[j
], nt_errstr(status
));
2023 static bool test_EnumTrustDom(struct dcerpc_pipe
*p
,
2024 struct torture_context
*tctx
,
2025 struct policy_handle
*handle
)
2027 struct lsa_EnumTrustDom r
;
2028 NTSTATUS enum_status
;
2029 uint32_t in_resume_handle
= 0;
2030 uint32_t out_resume_handle
;
2031 struct lsa_DomainList domains
;
2034 torture_comment(tctx
, "\nTesting EnumTrustDom\n");
2036 r
.in
.handle
= handle
;
2037 r
.in
.resume_handle
= &in_resume_handle
;
2039 r
.out
.domains
= &domains
;
2040 r
.out
.resume_handle
= &out_resume_handle
;
2042 enum_status
= dcerpc_lsa_EnumTrustDom(p
, tctx
, &r
);
2044 /* according to MS-LSAD 3.1.4.7.8 output resume handle MUST
2045 * always be larger than the previous input resume handle, in
2046 * particular when hitting the last query it is vital to set the
2047 * resume handle correctly to avoid infinite client loops, as
2048 * seen e.g. with Windows XP SP3 when resume handle is 0 and
2049 * status is NT_STATUS_OK - gd */
2051 if (NT_STATUS_IS_OK(enum_status
) ||
2052 NT_STATUS_EQUAL(enum_status
, NT_STATUS_NO_MORE_ENTRIES
) ||
2053 NT_STATUS_EQUAL(enum_status
, STATUS_MORE_ENTRIES
))
2055 if (out_resume_handle
<= in_resume_handle
) {
2056 torture_comment(tctx
, "EnumTrustDom failed - should have returned output resume_handle (0x%08x) larger than input resume handle (0x%08x)\n",
2057 out_resume_handle
, in_resume_handle
);
2062 if (NT_STATUS_IS_OK(enum_status
)) {
2063 if (domains
.count
== 0) {
2064 torture_comment(tctx
, "EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2067 } else if (!(NT_STATUS_EQUAL(enum_status
, STATUS_MORE_ENTRIES
) || NT_STATUS_EQUAL(enum_status
, NT_STATUS_NO_MORE_ENTRIES
))) {
2068 torture_comment(tctx
, "EnumTrustDom of zero size failed - %s\n", nt_errstr(enum_status
));
2072 /* Start from the bottom again */
2073 in_resume_handle
= 0;
2076 r
.in
.handle
= handle
;
2077 r
.in
.resume_handle
= &in_resume_handle
;
2078 r
.in
.max_size
= LSA_ENUM_TRUST_DOMAIN_MULTIPLIER
* 3;
2079 r
.out
.domains
= &domains
;
2080 r
.out
.resume_handle
= &out_resume_handle
;
2082 enum_status
= dcerpc_lsa_EnumTrustDom(p
, tctx
, &r
);
2084 /* according to MS-LSAD 3.1.4.7.8 output resume handle MUST
2085 * always be larger than the previous input resume handle, in
2086 * particular when hitting the last query it is vital to set the
2087 * resume handle correctly to avoid infinite client loops, as
2088 * seen e.g. with Windows XP SP3 when resume handle is 0 and
2089 * status is NT_STATUS_OK - gd */
2091 if (NT_STATUS_IS_OK(enum_status
) ||
2092 NT_STATUS_EQUAL(enum_status
, NT_STATUS_NO_MORE_ENTRIES
) ||
2093 NT_STATUS_EQUAL(enum_status
, STATUS_MORE_ENTRIES
))
2095 if (out_resume_handle
<= in_resume_handle
) {
2096 torture_comment(tctx
, "EnumTrustDom failed - should have returned output resume_handle (0x%08x) larger than input resume handle (0x%08x)\n",
2097 out_resume_handle
, in_resume_handle
);
2102 /* NO_MORE_ENTRIES is allowed */
2103 if (NT_STATUS_EQUAL(enum_status
, NT_STATUS_NO_MORE_ENTRIES
)) {
2104 if (domains
.count
== 0) {
2107 torture_comment(tctx
, "EnumTrustDom failed - should have returned 0 trusted domains with 'NT_STATUS_NO_MORE_ENTRIES'\n");
2109 } else if (NT_STATUS_EQUAL(enum_status
, STATUS_MORE_ENTRIES
)) {
2110 /* Windows 2003 gets this off by one on the first run */
2111 if (r
.out
.domains
->count
< 3 || r
.out
.domains
->count
> 4) {
2112 torture_comment(tctx
, "EnumTrustDom didn't fill the buffer we "
2113 "asked it to (got %d, expected %d / %d == %d entries)\n",
2114 r
.out
.domains
->count
, LSA_ENUM_TRUST_DOMAIN_MULTIPLIER
* 3,
2115 LSA_ENUM_TRUST_DOMAIN_MULTIPLIER
, r
.in
.max_size
);
2118 } else if (!NT_STATUS_IS_OK(enum_status
)) {
2119 torture_comment(tctx
, "EnumTrustDom failed - %s\n", nt_errstr(enum_status
));
2123 if (domains
.count
== 0) {
2124 torture_comment(tctx
, "EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2128 ret
&= test_query_each_TrustDom(p
, tctx
, handle
, &domains
);
2130 in_resume_handle
= out_resume_handle
;
2132 } while ((NT_STATUS_EQUAL(enum_status
, STATUS_MORE_ENTRIES
)));
2137 static bool test_EnumTrustDomEx(struct dcerpc_pipe
*p
,
2138 struct torture_context
*tctx
,
2139 struct policy_handle
*handle
)
2141 struct lsa_EnumTrustedDomainsEx r_ex
;
2142 NTSTATUS enum_status
;
2143 uint32_t resume_handle
= 0;
2144 struct lsa_DomainListEx domains_ex
;
2147 torture_comment(tctx
, "\nTesting EnumTrustedDomainsEx\n");
2149 r_ex
.in
.handle
= handle
;
2150 r_ex
.in
.resume_handle
= &resume_handle
;
2151 r_ex
.in
.max_size
= LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER
* 3;
2152 r_ex
.out
.domains
= &domains_ex
;
2153 r_ex
.out
.resume_handle
= &resume_handle
;
2155 enum_status
= dcerpc_lsa_EnumTrustedDomainsEx(p
, tctx
, &r_ex
);
2157 if (!(NT_STATUS_EQUAL(enum_status
, STATUS_MORE_ENTRIES
) || NT_STATUS_EQUAL(enum_status
, NT_STATUS_NO_MORE_ENTRIES
))) {
2158 torture_comment(tctx
, "EnumTrustedDomainEx of zero size failed - %s\n", nt_errstr(enum_status
));
2164 r_ex
.in
.handle
= handle
;
2165 r_ex
.in
.resume_handle
= &resume_handle
;
2166 r_ex
.in
.max_size
= LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER
* 3;
2167 r_ex
.out
.domains
= &domains_ex
;
2168 r_ex
.out
.resume_handle
= &resume_handle
;
2170 enum_status
= dcerpc_lsa_EnumTrustedDomainsEx(p
, tctx
, &r_ex
);
2172 /* NO_MORE_ENTRIES is allowed */
2173 if (NT_STATUS_EQUAL(enum_status
, NT_STATUS_NO_MORE_ENTRIES
)) {
2174 if (domains_ex
.count
== 0) {
2177 torture_comment(tctx
, "EnumTrustDomainsEx failed - should have returned 0 trusted domains with 'NT_STATUS_NO_MORE_ENTRIES'\n");
2179 } else if (NT_STATUS_EQUAL(enum_status
, STATUS_MORE_ENTRIES
)) {
2180 /* Windows 2003 gets this off by one on the first run */
2181 if (r_ex
.out
.domains
->count
< 3 || r_ex
.out
.domains
->count
> 4) {
2182 torture_comment(tctx
, "EnumTrustDom didn't fill the buffer we "
2183 "asked it to (got %d, expected %d / %d == %d entries)\n",
2184 r_ex
.out
.domains
->count
,
2186 LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER
,
2187 r_ex
.in
.max_size
/ LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER
);
2189 } else if (!NT_STATUS_IS_OK(enum_status
)) {
2190 torture_comment(tctx
, "EnumTrustedDomainEx failed - %s\n", nt_errstr(enum_status
));
2194 if (domains_ex
.count
== 0) {
2195 torture_comment(tctx
, "EnumTrustDomainEx failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2199 ret
&= test_query_each_TrustDomEx(p
, tctx
, handle
, &domains_ex
);
2201 } while ((NT_STATUS_EQUAL(enum_status
, STATUS_MORE_ENTRIES
)));
2207 static bool test_CreateTrustedDomain(struct dcerpc_pipe
*p
,
2208 struct torture_context
*tctx
,
2209 struct policy_handle
*handle
,
2210 uint32_t num_trusts
)
2214 struct lsa_CreateTrustedDomain r
;
2215 struct lsa_DomainInfo trustinfo
;
2216 struct dom_sid
**domsid
;
2217 struct policy_handle
*trustdom_handle
;
2218 struct lsa_QueryTrustedDomainInfo q
;
2219 union lsa_TrustedDomainInfo
*info
= NULL
;
2222 torture_comment(tctx
, "\nTesting CreateTrustedDomain for %d domains\n", num_trusts
);
2224 if (!test_EnumTrustDom(p
, tctx
, handle
)) {
2228 if (!test_EnumTrustDomEx(p
, tctx
, handle
)) {
2232 domsid
= talloc_array(tctx
, struct dom_sid
*, num_trusts
);
2233 trustdom_handle
= talloc_array(tctx
, struct policy_handle
, num_trusts
);
2235 for (i
=0; i
< num_trusts
; i
++) {
2236 char *trust_name
= talloc_asprintf(tctx
, "torturedom%02d", i
);
2237 char *trust_sid
= talloc_asprintf(tctx
, "S-1-5-21-97398-379795-100%02d", i
);
2239 domsid
[i
] = dom_sid_parse_talloc(tctx
, trust_sid
);
2241 trustinfo
.sid
= domsid
[i
];
2242 init_lsa_String((struct lsa_String
*)&trustinfo
.name
, trust_name
);
2244 r
.in
.policy_handle
= handle
;
2245 r
.in
.info
= &trustinfo
;
2246 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2247 r
.out
.trustdom_handle
= &trustdom_handle
[i
];
2249 status
= dcerpc_lsa_CreateTrustedDomain(p
, tctx
, &r
);
2250 if (NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
2251 test_DeleteTrustedDomain(p
, tctx
, handle
, trustinfo
.name
);
2252 status
= dcerpc_lsa_CreateTrustedDomain(p
, tctx
, &r
);
2254 if (!NT_STATUS_IS_OK(status
)) {
2255 torture_comment(tctx
, "CreateTrustedDomain failed - %s\n", nt_errstr(status
));
2259 q
.in
.trustdom_handle
= &trustdom_handle
[i
];
2260 q
.in
.level
= LSA_TRUSTED_DOMAIN_INFO_INFO_EX
;
2262 status
= dcerpc_lsa_QueryTrustedDomainInfo(p
, tctx
, &q
);
2263 if (!NT_STATUS_IS_OK(status
)) {
2264 torture_comment(tctx
, "QueryTrustedDomainInfo level %d failed - %s\n", q
.in
.level
, nt_errstr(status
));
2266 } else if (!q
.out
.info
) {
2269 if (strcmp(info
->info_ex
.netbios_name
.string
, trustinfo
.name
.string
) != 0) {
2270 torture_comment(tctx
, "QueryTrustedDomainInfo returned inconsistant short name: %s != %s\n",
2271 info
->info_ex
.netbios_name
.string
, trustinfo
.name
.string
);
2274 if (info
->info_ex
.trust_type
!= LSA_TRUST_TYPE_DOWNLEVEL
) {
2275 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
2276 trust_name
, info
->info_ex
.trust_type
, LSA_TRUST_TYPE_DOWNLEVEL
);
2279 if (info
->info_ex
.trust_attributes
!= 0) {
2280 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
2281 trust_name
, info
->info_ex
.trust_attributes
, 0);
2284 if (info
->info_ex
.trust_direction
!= LSA_TRUST_DIRECTION_OUTBOUND
) {
2285 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
2286 trust_name
, info
->info_ex
.trust_direction
, LSA_TRUST_DIRECTION_OUTBOUND
);
2293 /* now that we have some domains to look over, we can test the enum calls */
2294 if (!test_EnumTrustDom(p
, tctx
, handle
)) {
2298 if (!test_EnumTrustDomEx(p
, tctx
, handle
)) {
2302 for (i
=0; i
<num_trusts
; i
++) {
2303 if (!test_DeleteTrustedDomainBySid(p
, tctx
, handle
, domsid
[i
])) {
2311 static bool test_CreateTrustedDomainEx2(struct dcerpc_pipe
*p
,
2312 struct torture_context
*tctx
,
2313 struct policy_handle
*handle
,
2314 uint32_t num_trusts
)
2318 struct lsa_CreateTrustedDomainEx2 r
;
2319 struct lsa_TrustDomainInfoInfoEx trustinfo
;
2320 struct lsa_TrustDomainInfoAuthInfoInternal authinfo
;
2321 struct trustDomainPasswords auth_struct
;
2322 DATA_BLOB auth_blob
;
2323 struct dom_sid
**domsid
;
2324 struct policy_handle
*trustdom_handle
;
2325 struct lsa_QueryTrustedDomainInfo q
;
2326 union lsa_TrustedDomainInfo
*info
= NULL
;
2327 DATA_BLOB session_key
;
2328 enum ndr_err_code ndr_err
;
2331 torture_comment(tctx
, "\nTesting CreateTrustedDomainEx2 for %d domains\n", num_trusts
);
2333 domsid
= talloc_array(tctx
, struct dom_sid
*, num_trusts
);
2334 trustdom_handle
= talloc_array(tctx
, struct policy_handle
, num_trusts
);
2336 status
= dcerpc_fetch_session_key(p
, &session_key
);
2337 if (!NT_STATUS_IS_OK(status
)) {
2338 torture_comment(tctx
, "dcerpc_fetch_session_key failed - %s\n", nt_errstr(status
));
2342 for (i
=0; i
< num_trusts
; i
++) {
2343 char *trust_name
= talloc_asprintf(tctx
, "torturedom%02d", i
);
2344 char *trust_name_dns
= talloc_asprintf(tctx
, "torturedom%02d.samba.example.com", i
);
2345 char *trust_sid
= talloc_asprintf(tctx
, "S-1-5-21-97398-379795-100%02d", i
);
2347 domsid
[i
] = dom_sid_parse_talloc(tctx
, trust_sid
);
2349 trustinfo
.sid
= domsid
[i
];
2350 trustinfo
.netbios_name
.string
= trust_name
;
2351 trustinfo
.domain_name
.string
= trust_name_dns
;
2353 /* Create inbound, some outbound, and some
2354 * bi-directional trusts in a repeating pattern based
2357 /* 1 == inbound, 2 == outbound, 3 == both */
2358 trustinfo
.trust_direction
= (i
% 3) + 1;
2360 /* Try different trust types too */
2362 /* 1 == downlevel (NT4), 2 == uplevel (ADS), 3 == MIT (kerberos but not AD) */
2363 trustinfo
.trust_type
= (((i
/ 3) + 1) % 3) + 1;
2365 trustinfo
.trust_attributes
= LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION
;
2367 generate_random_buffer(auth_struct
.confounder
, sizeof(auth_struct
.confounder
));
2369 auth_struct
.outgoing
.count
= 0;
2370 auth_struct
.incoming
.count
= 0;
2372 ndr_err
= ndr_push_struct_blob(&auth_blob
, tctx
, lp_iconv_convenience(tctx
->lp_ctx
), &auth_struct
,
2373 (ndr_push_flags_fn_t
)ndr_push_trustDomainPasswords
);
2374 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2375 torture_comment(tctx
, "ndr_push_struct_blob of trustDomainPasswords structure failed");
2379 arcfour_crypt_blob(auth_blob
.data
, auth_blob
.length
, &session_key
);
2381 authinfo
.auth_blob
.size
= auth_blob
.length
;
2382 authinfo
.auth_blob
.data
= auth_blob
.data
;
2384 r
.in
.policy_handle
= handle
;
2385 r
.in
.info
= &trustinfo
;
2386 r
.in
.auth_info
= &authinfo
;
2387 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2388 r
.out
.trustdom_handle
= &trustdom_handle
[i
];
2390 status
= dcerpc_lsa_CreateTrustedDomainEx2(p
, tctx
, &r
);
2391 if (NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
2392 test_DeleteTrustedDomain(p
, tctx
, handle
, trustinfo
.netbios_name
);
2393 status
= dcerpc_lsa_CreateTrustedDomainEx2(p
, tctx
, &r
);
2395 if (!NT_STATUS_IS_OK(status
)) {
2396 torture_comment(tctx
, "CreateTrustedDomainEx failed2 - %s\n", nt_errstr(status
));
2400 q
.in
.trustdom_handle
= &trustdom_handle
[i
];
2401 q
.in
.level
= LSA_TRUSTED_DOMAIN_INFO_INFO_EX
;
2403 status
= dcerpc_lsa_QueryTrustedDomainInfo(p
, tctx
, &q
);
2404 if (!NT_STATUS_IS_OK(status
)) {
2405 torture_comment(tctx
, "QueryTrustedDomainInfo level 1 failed - %s\n", nt_errstr(status
));
2407 } else if (!q
.out
.info
) {
2408 torture_comment(tctx
, "QueryTrustedDomainInfo level 1 failed to return an info pointer\n");
2411 if (strcmp(info
->info_ex
.netbios_name
.string
, trustinfo
.netbios_name
.string
) != 0) {
2412 torture_comment(tctx
, "QueryTrustedDomainInfo returned inconsistant short name: %s != %s\n",
2413 info
->info_ex
.netbios_name
.string
, trustinfo
.netbios_name
.string
);
2416 if (info
->info_ex
.trust_type
!= trustinfo
.trust_type
) {
2417 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
2418 trust_name
, info
->info_ex
.trust_type
, trustinfo
.trust_type
);
2421 if (info
->info_ex
.trust_attributes
!= LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION
) {
2422 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
2423 trust_name
, info
->info_ex
.trust_attributes
, LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION
);
2426 if (info
->info_ex
.trust_direction
!= trustinfo
.trust_direction
) {
2427 torture_comment(tctx
, "QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
2428 trust_name
, info
->info_ex
.trust_direction
, trustinfo
.trust_direction
);
2435 /* now that we have some domains to look over, we can test the enum calls */
2436 if (!test_EnumTrustDom(p
, tctx
, handle
)) {
2437 torture_comment(tctx
, "test_EnumTrustDom failed\n");
2441 if (!test_EnumTrustDomEx(p
, tctx
, handle
)) {
2442 torture_comment(tctx
, "test_EnumTrustDomEx failed\n");
2446 for (i
=0; i
<num_trusts
; i
++) {
2447 if (!test_DeleteTrustedDomainBySid(p
, tctx
, handle
, domsid
[i
])) {
2448 torture_comment(tctx
, "test_DeleteTrustedDomainBySid failed\n");
2456 static bool test_QueryDomainInfoPolicy(struct dcerpc_pipe
*p
,
2457 struct torture_context
*tctx
,
2458 struct policy_handle
*handle
)
2460 struct lsa_QueryDomainInformationPolicy r
;
2461 union lsa_DomainInformationPolicy
*info
= NULL
;
2466 if (torture_setting_bool(tctx
, "samba3", false)) {
2467 torture_skip(tctx
, "skipping QueryDomainInformationPolicy test\n");
2470 torture_comment(tctx
, "\nTesting QueryDomainInformationPolicy\n");
2473 r
.in
.handle
= handle
;
2477 torture_comment(tctx
, "\nTrying QueryDomainInformationPolicy level %d\n", i
);
2479 status
= dcerpc_lsa_QueryDomainInformationPolicy(p
, tctx
, &r
);
2481 /* If the server does not support EFS, then this is the correct return */
2482 if (i
== LSA_DOMAIN_INFO_POLICY_EFS
&& NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
2484 } else if (!NT_STATUS_IS_OK(status
)) {
2485 torture_comment(tctx
, "QueryDomainInformationPolicy failed - %s\n", nt_errstr(status
));
2495 static bool test_QueryInfoPolicyCalls( bool version2
,
2496 struct dcerpc_pipe
*p
,
2497 struct torture_context
*tctx
,
2498 struct policy_handle
*handle
)
2500 struct lsa_QueryInfoPolicy r
;
2501 union lsa_PolicyInformation
*info
= NULL
;
2505 const char *call
= talloc_asprintf(tctx
, "QueryInfoPolicy%s", version2
? "2":"");
2507 torture_comment(tctx
, "\nTesting %s\n", call
);
2509 if (version2
&& torture_setting_bool(tctx
, "samba3", false)) {
2510 torture_skip(tctx
, "skipping QueryInfoPolicy2 tests\n");
2513 for (i
=1;i
<=14;i
++) {
2514 r
.in
.handle
= handle
;
2518 torture_comment(tctx
, "\nTrying %s level %d\n", call
, i
);
2521 /* We can perform the cast, because both types are
2522 structurally equal */
2523 status
= dcerpc_lsa_QueryInfoPolicy2(p
, tctx
,
2524 (struct lsa_QueryInfoPolicy2
*) &r
);
2526 status
= dcerpc_lsa_QueryInfoPolicy(p
, tctx
, &r
);
2529 case LSA_POLICY_INFO_MOD
:
2530 case LSA_POLICY_INFO_AUDIT_FULL_SET
:
2531 case LSA_POLICY_INFO_AUDIT_FULL_QUERY
:
2532 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_PARAMETER
)) {
2533 torture_comment(tctx
, "Server should have failed level %u: %s\n", i
, nt_errstr(status
));
2537 case LSA_POLICY_INFO_DOMAIN
:
2538 case LSA_POLICY_INFO_ACCOUNT_DOMAIN
:
2539 case LSA_POLICY_INFO_REPLICA
:
2540 case LSA_POLICY_INFO_QUOTA
:
2541 case LSA_POLICY_INFO_ROLE
:
2542 case LSA_POLICY_INFO_AUDIT_LOG
:
2543 case LSA_POLICY_INFO_AUDIT_EVENTS
:
2544 case LSA_POLICY_INFO_PD
:
2545 if (!NT_STATUS_IS_OK(status
)) {
2546 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(status
));
2550 case LSA_POLICY_INFO_L_ACCOUNT_DOMAIN
:
2551 case LSA_POLICY_INFO_DNS_INT
:
2552 case LSA_POLICY_INFO_DNS
:
2553 if (torture_setting_bool(tctx
, "samba3", false)) {
2554 /* Other levels not implemented yet */
2555 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_INFO_CLASS
)) {
2556 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(status
));
2559 } else if (!NT_STATUS_IS_OK(status
)) {
2560 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(status
));
2565 if (torture_setting_bool(tctx
, "samba4", false)) {
2566 /* Other levels not implemented yet */
2567 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_INFO_CLASS
)) {
2568 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(status
));
2571 } else if (!NT_STATUS_IS_OK(status
)) {
2572 torture_comment(tctx
, "%s failed - %s\n", call
, nt_errstr(status
));
2578 if (NT_STATUS_IS_OK(status
) && (i
== LSA_POLICY_INFO_DNS
2579 || i
== LSA_POLICY_INFO_DNS_INT
)) {
2580 /* Let's look up some of these names */
2582 struct lsa_TransNameArray tnames
;
2584 tnames
.names
= talloc_zero_array(tctx
, struct lsa_TranslatedName
, tnames
.count
);
2585 tnames
.names
[0].name
.string
= info
->dns
.name
.string
;
2586 tnames
.names
[0].sid_type
= SID_NAME_DOMAIN
;
2587 tnames
.names
[1].name
.string
= info
->dns
.dns_domain
.string
;
2588 tnames
.names
[1].sid_type
= SID_NAME_DOMAIN
;
2589 tnames
.names
[2].name
.string
= talloc_asprintf(tctx
, "%s\\", info
->dns
.name
.string
);
2590 tnames
.names
[2].sid_type
= SID_NAME_DOMAIN
;
2591 tnames
.names
[3].name
.string
= talloc_asprintf(tctx
, "%s\\", info
->dns
.dns_domain
.string
);
2592 tnames
.names
[3].sid_type
= SID_NAME_DOMAIN
;
2593 tnames
.names
[4].name
.string
= talloc_asprintf(tctx
, "%s\\guest", info
->dns
.name
.string
);
2594 tnames
.names
[4].sid_type
= SID_NAME_USER
;
2595 tnames
.names
[5].name
.string
= talloc_asprintf(tctx
, "%s\\krbtgt", info
->dns
.name
.string
);
2596 tnames
.names
[5].sid_type
= SID_NAME_USER
;
2597 tnames
.names
[6].name
.string
= talloc_asprintf(tctx
, "%s\\guest", info
->dns
.dns_domain
.string
);
2598 tnames
.names
[6].sid_type
= SID_NAME_USER
;
2599 tnames
.names
[7].name
.string
= talloc_asprintf(tctx
, "%s\\krbtgt", info
->dns
.dns_domain
.string
);
2600 tnames
.names
[7].sid_type
= SID_NAME_USER
;
2601 tnames
.names
[8].name
.string
= talloc_asprintf(tctx
, "krbtgt@%s", info
->dns
.name
.string
);
2602 tnames
.names
[8].sid_type
= SID_NAME_USER
;
2603 tnames
.names
[9].name
.string
= talloc_asprintf(tctx
, "krbtgt@%s", info
->dns
.dns_domain
.string
);
2604 tnames
.names
[9].sid_type
= SID_NAME_USER
;
2605 tnames
.names
[10].name
.string
= talloc_asprintf(tctx
, "%s\\"TEST_MACHINENAME
"$", info
->dns
.name
.string
);
2606 tnames
.names
[10].sid_type
= SID_NAME_USER
;
2607 tnames
.names
[11].name
.string
= talloc_asprintf(tctx
, "%s\\"TEST_MACHINENAME
"$", info
->dns
.dns_domain
.string
);
2608 tnames
.names
[11].sid_type
= SID_NAME_USER
;
2609 tnames
.names
[12].name
.string
= talloc_asprintf(tctx
, TEST_MACHINENAME
"$@%s", info
->dns
.name
.string
);
2610 tnames
.names
[12].sid_type
= SID_NAME_USER
;
2611 tnames
.names
[13].name
.string
= talloc_asprintf(tctx
, TEST_MACHINENAME
"$@%s", info
->dns
.dns_domain
.string
);
2612 tnames
.names
[13].sid_type
= SID_NAME_USER
;
2613 ret
&= test_LookupNames(p
, tctx
, handle
, &tnames
);
2621 static bool test_QueryInfoPolicy(struct dcerpc_pipe
*p
,
2622 struct torture_context
*tctx
,
2623 struct policy_handle
*handle
)
2625 return test_QueryInfoPolicyCalls(false, p
, tctx
, handle
);
2628 static bool test_QueryInfoPolicy2(struct dcerpc_pipe
*p
,
2629 struct torture_context
*tctx
,
2630 struct policy_handle
*handle
)
2632 return test_QueryInfoPolicyCalls(true, p
, tctx
, handle
);
2635 static bool test_GetUserName(struct dcerpc_pipe
*p
,
2636 struct torture_context
*tctx
)
2638 struct lsa_GetUserName r
;
2641 struct lsa_String
*authority_name_p
= NULL
;
2642 struct lsa_String
*account_name_p
= NULL
;
2644 torture_comment(tctx
, "\nTesting GetUserName\n");
2646 r
.in
.system_name
= "\\";
2647 r
.in
.account_name
= &account_name_p
;
2648 r
.in
.authority_name
= NULL
;
2649 r
.out
.account_name
= &account_name_p
;
2651 status
= dcerpc_lsa_GetUserName(p
, tctx
, &r
);
2653 if (!NT_STATUS_IS_OK(status
)) {
2654 torture_comment(tctx
, "GetUserName failed - %s\n", nt_errstr(status
));
2658 account_name_p
= NULL
;
2659 r
.in
.account_name
= &account_name_p
;
2660 r
.in
.authority_name
= &authority_name_p
;
2661 r
.out
.account_name
= &account_name_p
;
2663 status
= dcerpc_lsa_GetUserName(p
, tctx
, &r
);
2665 if (!NT_STATUS_IS_OK(status
)) {
2666 torture_comment(tctx
, "GetUserName failed - %s\n", nt_errstr(status
));
2673 bool test_lsa_Close(struct dcerpc_pipe
*p
,
2674 struct torture_context
*tctx
,
2675 struct policy_handle
*handle
)
2679 struct policy_handle handle2
;
2681 torture_comment(tctx
, "\nTesting Close\n");
2683 r
.in
.handle
= handle
;
2684 r
.out
.handle
= &handle2
;
2686 status
= dcerpc_lsa_Close(p
, tctx
, &r
);
2687 if (!NT_STATUS_IS_OK(status
)) {
2688 torture_comment(tctx
, "Close failed - %s\n", nt_errstr(status
));
2692 status
= dcerpc_lsa_Close(p
, tctx
, &r
);
2693 /* its really a fault - we need a status code for rpc fault */
2694 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NET_WRITE_FAULT
)) {
2695 torture_comment(tctx
, "Close failed - %s\n", nt_errstr(status
));
2699 torture_comment(tctx
, "\n");
2704 bool torture_rpc_lsa(struct torture_context
*tctx
)
2707 struct dcerpc_pipe
*p
;
2709 struct policy_handle
*handle
;
2710 struct test_join
*join
= NULL
;
2711 struct cli_credentials
*machine_creds
;
2713 status
= torture_rpc_connection(tctx
, &p
, &ndr_table_lsarpc
);
2714 if (!NT_STATUS_IS_OK(status
)) {
2718 if (!test_OpenPolicy(p
, tctx
)) {
2722 if (!test_lsa_OpenPolicy2(p
, tctx
, &handle
)) {
2727 join
= torture_join_domain(tctx
, TEST_MACHINENAME
, ACB_WSTRUST
, &machine_creds
);
2732 if (!test_LookupSids_async(p
, tctx
, handle
)) {
2736 if (!test_QueryDomainInfoPolicy(p
, tctx
, handle
)) {
2740 if (!test_CreateSecret(p
, tctx
, handle
)) {
2744 if (!test_QueryInfoPolicy(p
, tctx
, handle
)) {
2748 if (!test_QueryInfoPolicy2(p
, tctx
, handle
)) {
2752 if (!test_Delete(p
, tctx
, handle
)) {
2756 if (!test_many_LookupSids(p
, tctx
, handle
)) {
2760 if (!test_lsa_Close(p
, tctx
, handle
)) {
2764 torture_leave_domain(tctx
, join
);
2767 if (!test_many_LookupSids(p
, tctx
, handle
)) {
2772 if (!test_GetUserName(p
, tctx
)) {
2779 bool torture_rpc_lsa_get_user(struct torture_context
*tctx
)
2782 struct dcerpc_pipe
*p
;
2785 status
= torture_rpc_connection(tctx
, &p
, &ndr_table_lsarpc
);
2786 if (!NT_STATUS_IS_OK(status
)) {
2790 if (!test_GetUserName(p
, tctx
)) {
2797 static bool testcase_LookupNames(struct torture_context
*tctx
,
2798 struct dcerpc_pipe
*p
)
2801 struct policy_handle
*handle
;
2802 struct lsa_TransNameArray tnames
;
2803 struct lsa_TransNameArray2 tnames2
;
2805 if (!test_OpenPolicy(p
, tctx
)) {
2809 if (!test_lsa_OpenPolicy2(p
, tctx
, &handle
)) {
2818 tnames
.names
= talloc_array(tctx
, struct lsa_TranslatedName
, tnames
.count
);
2819 ZERO_STRUCT(tnames
.names
[0]);
2820 tnames
.names
[0].name
.string
= "BUILTIN";
2821 tnames
.names
[0].sid_type
= SID_NAME_DOMAIN
;
2823 if (!test_LookupNames(p
, tctx
, handle
, &tnames
)) {
2828 tnames2
.names
= talloc_array(tctx
, struct lsa_TranslatedName2
, tnames2
.count
);
2829 ZERO_STRUCT(tnames2
.names
[0]);
2830 tnames2
.names
[0].name
.string
= "BUILTIN";
2831 tnames2
.names
[0].sid_type
= SID_NAME_DOMAIN
;
2833 if (!test_LookupNames2(p
, tctx
, handle
, &tnames2
, true)) {
2837 if (!test_LookupNames3(p
, tctx
, handle
, &tnames2
, true)) {
2841 if (!test_LookupNames_wellknown(p
, tctx
, handle
)) {
2845 if (!test_LookupNames_NULL(p
, tctx
, handle
)) {
2849 if (!test_LookupNames_bogus(p
, tctx
, handle
)) {
2853 if (!test_lsa_Close(p
, tctx
, handle
)) {
2860 struct torture_suite
*torture_rpc_lsa_lookup_names(TALLOC_CTX
*mem_ctx
)
2862 struct torture_suite
*suite
;
2863 struct torture_rpc_tcase
*tcase
;
2865 suite
= torture_suite_create(mem_ctx
, "LSA-LOOKUPNAMES");
2867 tcase
= torture_suite_add_rpc_iface_tcase(suite
, "lsa",
2869 torture_rpc_tcase_add_test(tcase
, "LookupNames",
2870 testcase_LookupNames
);
2875 struct lsa_trustdom_state
{
2876 uint32_t num_trusts
;
2879 static bool testcase_TrustedDomains(struct torture_context
*tctx
,
2880 struct dcerpc_pipe
*p
,
2884 struct policy_handle
*handle
;
2885 struct lsa_trustdom_state
*state
=
2886 talloc_get_type_abort(data
, struct lsa_trustdom_state
);
2888 torture_comment(tctx
, "testing %d domains\n", state
->num_trusts
);
2890 if (!test_OpenPolicy(p
, tctx
)) {
2894 if (!test_lsa_OpenPolicy2(p
, tctx
, &handle
)) {
2902 if (!test_CreateTrustedDomain(p
, tctx
, handle
, state
->num_trusts
)) {
2906 if (!test_CreateTrustedDomainEx2(p
, tctx
, handle
, state
->num_trusts
)) {
2910 if (!test_lsa_Close(p
, tctx
, handle
)) {
2917 struct torture_suite
*torture_rpc_lsa_trusted_domains(TALLOC_CTX
*mem_ctx
)
2919 struct torture_suite
*suite
;
2920 struct torture_rpc_tcase
*tcase
;
2921 struct lsa_trustdom_state
*state
;
2923 state
= talloc(mem_ctx
, struct lsa_trustdom_state
);
2925 state
->num_trusts
= 12;
2927 suite
= torture_suite_create(mem_ctx
, "LSA-TRUSTED-DOMAINS");
2929 tcase
= torture_suite_add_rpc_iface_tcase(suite
, "lsa",
2931 torture_rpc_tcase_add_test_ex(tcase
, "TrustedDomains",
2932 testcase_TrustedDomains
,
2938 static bool testcase_Privileges(struct torture_context
*tctx
,
2939 struct dcerpc_pipe
*p
)
2942 struct policy_handle
*handle
;
2944 if (!test_OpenPolicy(p
, tctx
)) {
2948 if (!test_lsa_OpenPolicy2(p
, tctx
, &handle
)) {
2956 if (!test_CreateAccount(p
, tctx
, handle
)) {
2960 if (!test_EnumAccounts(p
, tctx
, handle
)) {
2964 if (!test_EnumPrivs(p
, tctx
, handle
)) {
2968 if (!test_lsa_Close(p
, tctx
, handle
)) {
2976 struct torture_suite
*torture_rpc_lsa_privileges(TALLOC_CTX
*mem_ctx
)
2978 struct torture_suite
*suite
;
2979 struct torture_rpc_tcase
*tcase
;
2981 suite
= torture_suite_create(mem_ctx
, "LSA-PRIVILEGES");
2983 tcase
= torture_suite_add_rpc_iface_tcase(suite
, "lsa",
2985 torture_rpc_tcase_add_test(tcase
, "Privileges",
2986 testcase_Privileges
);