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
, TALLOC_CTX
*mem_ctx
)
42 struct lsa_ObjectAttribute attr
;
43 struct policy_handle handle
;
44 struct lsa_QosInfo qos
;
45 struct lsa_OpenPolicy r
;
47 uint16_t system_name
= '\\';
49 printf("\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 status
= dcerpc_lsa_OpenPolicy(p
, mem_ctx
, &r
);
69 if (!NT_STATUS_IS_OK(status
)) {
70 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
) ||
71 NT_STATUS_EQUAL(status
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
72 printf("not considering %s to be an error\n", nt_errstr(status
));
75 printf("OpenPolicy failed - %s\n", nt_errstr(status
));
83 bool test_lsa_OpenPolicy2(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
84 struct policy_handle
**handle
)
86 struct lsa_ObjectAttribute attr
;
87 struct lsa_QosInfo qos
;
88 struct lsa_OpenPolicy2 r
;
91 printf("\nTesting OpenPolicy2\n");
93 *handle
= talloc(mem_ctx
, struct policy_handle
);
99 qos
.impersonation_level
= 2;
100 qos
.context_mode
= 1;
101 qos
.effective_only
= 0;
104 attr
.root_dir
= NULL
;
105 attr
.object_name
= NULL
;
107 attr
.sec_desc
= NULL
;
110 r
.in
.system_name
= "\\";
112 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
113 r
.out
.handle
= *handle
;
115 status
= dcerpc_lsa_OpenPolicy2(p
, mem_ctx
, &r
);
116 if (!NT_STATUS_IS_OK(status
)) {
117 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
) ||
118 NT_STATUS_EQUAL(status
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
119 printf("not considering %s to be an error\n", nt_errstr(status
));
120 talloc_free(*handle
);
124 printf("OpenPolicy2 failed - %s\n", nt_errstr(status
));
132 static const char *sid_type_lookup(enum lsa_SidType r
)
135 case SID_NAME_USE_NONE
: return "SID_NAME_USE_NONE"; break;
136 case SID_NAME_USER
: return "SID_NAME_USER"; break;
137 case SID_NAME_DOM_GRP
: return "SID_NAME_DOM_GRP"; break;
138 case SID_NAME_DOMAIN
: return "SID_NAME_DOMAIN"; break;
139 case SID_NAME_ALIAS
: return "SID_NAME_ALIAS"; break;
140 case SID_NAME_WKN_GRP
: return "SID_NAME_WKN_GRP"; break;
141 case SID_NAME_DELETED
: return "SID_NAME_DELETED"; break;
142 case SID_NAME_INVALID
: return "SID_NAME_INVALID"; break;
143 case SID_NAME_UNKNOWN
: return "SID_NAME_UNKNOWN"; break;
144 case SID_NAME_COMPUTER
: return "SID_NAME_COMPUTER"; break;
146 return "Invalid sid type\n";
149 static bool test_LookupNames(struct dcerpc_pipe
*p
,
151 struct policy_handle
*handle
,
152 struct lsa_TransNameArray
*tnames
)
154 struct lsa_LookupNames r
;
155 struct lsa_TransSidArray sids
;
156 struct lsa_RefDomainList
*domains
= NULL
;
157 struct lsa_String
*names
;
162 printf("\nTesting LookupNames with %d names\n", tnames
->count
);
167 names
= talloc_array(mem_ctx
, struct lsa_String
, tnames
->count
);
168 for (i
=0;i
<tnames
->count
;i
++) {
169 init_lsa_String(&names
[i
], tnames
->names
[i
].name
.string
);
172 r
.in
.handle
= handle
;
173 r
.in
.num_names
= tnames
->count
;
178 r
.out
.count
= &count
;
180 r
.out
.domains
= &domains
;
182 status
= dcerpc_lsa_LookupNames(p
, mem_ctx
, &r
);
184 if (NT_STATUS_EQUAL(status
, STATUS_SOME_UNMAPPED
) ||
185 NT_STATUS_EQUAL(status
, NT_STATUS_NONE_MAPPED
)) {
186 for (i
=0;i
< tnames
->count
;i
++) {
187 if (i
< count
&& sids
.sids
[i
].sid_type
== SID_NAME_UNKNOWN
) {
188 printf("LookupName of %s was unmapped\n",
189 tnames
->names
[i
].name
.string
);
190 } else if (i
>=count
) {
191 printf("LookupName of %s failed to return a result\n",
192 tnames
->names
[i
].name
.string
);
195 printf("LookupNames failed - %s\n", nt_errstr(status
));
197 } else if (!NT_STATUS_IS_OK(status
)) {
198 printf("LookupNames failed - %s\n", nt_errstr(status
));
202 for (i
=0;i
< tnames
->count
;i
++) {
203 if (i
< count
&& sids
.sids
[i
].sid_type
!= tnames
->names
[i
].sid_type
) {
204 printf("LookupName of %s got unexpected name type: %s\n",
205 tnames
->names
[i
].name
.string
, sid_type_lookup(sids
.sids
[i
].sid_type
));
206 } else if (i
>=count
) {
207 printf("LookupName of %s failed to return a result\n",
208 tnames
->names
[i
].name
.string
);
216 static bool test_LookupNames_bogus(struct dcerpc_pipe
*p
,
218 struct policy_handle
*handle
)
220 struct lsa_LookupNames r
;
221 struct lsa_TransSidArray sids
;
222 struct lsa_RefDomainList
*domains
= NULL
;
223 struct lsa_String
*names
;
228 struct lsa_TranslatedName name
[2];
229 struct lsa_TransNameArray tnames
;
233 name
[0].name
.string
= "NT AUTHORITY\\BOGUS";
234 name
[1].name
.string
= NULL
;
236 printf("\nTesting LookupNames with bogus names\n");
241 names
= talloc_array(mem_ctx
, struct lsa_String
, tnames
.count
);
242 for (i
=0;i
<tnames
.count
;i
++) {
243 init_lsa_String(&names
[i
], tnames
.names
[i
].name
.string
);
246 r
.in
.handle
= handle
;
247 r
.in
.num_names
= tnames
.count
;
252 r
.out
.count
= &count
;
254 r
.out
.domains
= &domains
;
256 status
= dcerpc_lsa_LookupNames(p
, mem_ctx
, &r
);
257 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NONE_MAPPED
)) {
258 printf("LookupNames failed - %s\n", nt_errstr(status
));
267 static bool test_LookupNames_wellknown(struct dcerpc_pipe
*p
,
269 struct policy_handle
*handle
)
271 struct lsa_TranslatedName name
;
272 struct lsa_TransNameArray tnames
;
275 printf("Testing LookupNames with well known names\n");
277 tnames
.names
= &name
;
279 name
.name
.string
= "NT AUTHORITY\\SYSTEM";
280 name
.sid_type
= SID_NAME_WKN_GRP
;
281 ret
&= test_LookupNames(p
, mem_ctx
, handle
, &tnames
);
283 name
.name
.string
= "NT AUTHORITY\\ANONYMOUS LOGON";
284 name
.sid_type
= SID_NAME_WKN_GRP
;
285 ret
&= test_LookupNames(p
, mem_ctx
, handle
, &tnames
);
287 name
.name
.string
= "NT AUTHORITY\\Authenticated Users";
288 name
.sid_type
= SID_NAME_WKN_GRP
;
289 ret
&= test_LookupNames(p
, mem_ctx
, handle
, &tnames
);
292 name
.name
.string
= "NT AUTHORITY";
293 ret
&= test_LookupNames(p
, mem_ctx
, handle
, &tnames
);
295 name
.name
.string
= "NT AUTHORITY\\";
296 ret
&= test_LookupNames(p
, mem_ctx
, handle
, &tnames
);
299 name
.name
.string
= "BUILTIN\\";
300 name
.sid_type
= SID_NAME_DOMAIN
;
301 ret
&= test_LookupNames(p
, mem_ctx
, handle
, &tnames
);
303 name
.name
.string
= "BUILTIN\\Administrators";
304 name
.sid_type
= SID_NAME_ALIAS
;
305 ret
&= test_LookupNames(p
, mem_ctx
, handle
, &tnames
);
307 name
.name
.string
= "SYSTEM";
308 name
.sid_type
= SID_NAME_WKN_GRP
;
309 ret
&= test_LookupNames(p
, mem_ctx
, handle
, &tnames
);
311 name
.name
.string
= "Everyone";
312 name
.sid_type
= SID_NAME_WKN_GRP
;
313 ret
&= test_LookupNames(p
, mem_ctx
, handle
, &tnames
);
317 static bool test_LookupNames2(struct dcerpc_pipe
*p
,
319 struct policy_handle
*handle
,
320 struct lsa_TransNameArray2
*tnames
)
322 struct lsa_LookupNames2 r
;
323 struct lsa_TransSidArray2 sids
;
324 struct lsa_RefDomainList
*domains
= NULL
;
325 struct lsa_String
*names
;
330 printf("\nTesting LookupNames2 with %d names\n", tnames
->count
);
335 names
= talloc_array(mem_ctx
, struct lsa_String
, tnames
->count
);
336 for (i
=0;i
<tnames
->count
;i
++) {
337 init_lsa_String(&names
[i
], tnames
->names
[i
].name
.string
);
340 r
.in
.handle
= handle
;
341 r
.in
.num_names
= tnames
->count
;
346 r
.in
.lookup_options
= 0;
347 r
.in
.client_revision
= 0;
348 r
.out
.count
= &count
;
350 r
.out
.domains
= &domains
;
352 status
= dcerpc_lsa_LookupNames2(p
, mem_ctx
, &r
);
353 if (!NT_STATUS_IS_OK(status
)) {
354 printf("LookupNames2 failed - %s\n", nt_errstr(status
));
364 static bool test_LookupNames3(struct dcerpc_pipe
*p
,
366 struct policy_handle
*handle
,
367 struct lsa_TransNameArray2
*tnames
)
369 struct lsa_LookupNames3 r
;
370 struct lsa_TransSidArray3 sids
;
371 struct lsa_RefDomainList
*domains
= NULL
;
372 struct lsa_String
*names
;
377 printf("\nTesting LookupNames3 with %d names\n", tnames
->count
);
382 names
= talloc_array(mem_ctx
, struct lsa_String
, tnames
->count
);
383 for (i
=0;i
<tnames
->count
;i
++) {
384 init_lsa_String(&names
[i
], tnames
->names
[i
].name
.string
);
387 r
.in
.handle
= handle
;
388 r
.in
.num_names
= tnames
->count
;
393 r
.in
.lookup_options
= 0;
394 r
.in
.client_revision
= 0;
395 r
.out
.count
= &count
;
397 r
.out
.domains
= &domains
;
399 status
= dcerpc_lsa_LookupNames3(p
, mem_ctx
, &r
);
400 if (!NT_STATUS_IS_OK(status
)) {
401 printf("LookupNames3 failed - %s\n", nt_errstr(status
));
410 static bool test_LookupNames4(struct dcerpc_pipe
*p
,
412 struct lsa_TransNameArray2
*tnames
)
414 struct lsa_LookupNames4 r
;
415 struct lsa_TransSidArray3 sids
;
416 struct lsa_RefDomainList
*domains
= NULL
;
417 struct lsa_String
*names
;
422 printf("\nTesting LookupNames4 with %d names\n", tnames
->count
);
427 names
= talloc_array(mem_ctx
, struct lsa_String
, tnames
->count
);
428 for (i
=0;i
<tnames
->count
;i
++) {
429 init_lsa_String(&names
[i
], tnames
->names
[i
].name
.string
);
432 r
.in
.num_names
= tnames
->count
;
437 r
.in
.lookup_options
= 0;
438 r
.in
.client_revision
= 0;
439 r
.out
.count
= &count
;
441 r
.out
.domains
= &domains
;
443 status
= dcerpc_lsa_LookupNames4(p
, mem_ctx
, &r
);
444 if (!NT_STATUS_IS_OK(status
)) {
445 printf("LookupNames4 failed - %s\n", nt_errstr(status
));
455 static bool test_LookupSids(struct dcerpc_pipe
*p
,
457 struct policy_handle
*handle
,
458 struct lsa_SidArray
*sids
)
460 struct lsa_LookupSids r
;
461 struct lsa_TransNameArray names
;
462 struct lsa_RefDomainList
*domains
= NULL
;
463 uint32_t count
= sids
->num_sids
;
466 printf("\nTesting LookupSids\n");
471 r
.in
.handle
= handle
;
476 r
.out
.count
= &count
;
477 r
.out
.names
= &names
;
478 r
.out
.domains
= &domains
;
480 status
= dcerpc_lsa_LookupSids(p
, mem_ctx
, &r
);
481 if (!NT_STATUS_IS_OK(status
)) {
482 printf("LookupSids failed - %s\n", nt_errstr(status
));
488 if (!test_LookupNames(p
, mem_ctx
, handle
, &names
)) {
496 static bool test_LookupSids2(struct dcerpc_pipe
*p
,
498 struct policy_handle
*handle
,
499 struct lsa_SidArray
*sids
)
501 struct lsa_LookupSids2 r
;
502 struct lsa_TransNameArray2 names
;
503 struct lsa_RefDomainList
*domains
= NULL
;
504 uint32_t count
= sids
->num_sids
;
507 printf("\nTesting LookupSids2\n");
512 r
.in
.handle
= handle
;
519 r
.out
.count
= &count
;
520 r
.out
.names
= &names
;
521 r
.out
.domains
= &domains
;
523 status
= dcerpc_lsa_LookupSids2(p
, mem_ctx
, &r
);
524 if (!NT_STATUS_IS_OK(status
)) {
525 printf("LookupSids2 failed - %s\n", nt_errstr(status
));
531 if (!test_LookupNames2(p
, mem_ctx
, handle
, &names
)) {
535 if (!test_LookupNames3(p
, mem_ctx
, handle
, &names
)) {
542 static bool test_LookupSids3(struct dcerpc_pipe
*p
,
544 struct lsa_SidArray
*sids
)
546 struct lsa_LookupSids3 r
;
547 struct lsa_TransNameArray2 names
;
548 struct lsa_RefDomainList
*domains
= NULL
;
549 uint32_t count
= sids
->num_sids
;
552 printf("\nTesting LookupSids3\n");
563 r
.out
.domains
= &domains
;
564 r
.out
.count
= &count
;
565 r
.out
.names
= &names
;
567 status
= dcerpc_lsa_LookupSids3(p
, mem_ctx
, &r
);
568 if (!NT_STATUS_IS_OK(status
)) {
569 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
) ||
570 NT_STATUS_EQUAL(status
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
571 printf("not considering %s to be an error\n", nt_errstr(status
));
574 printf("LookupSids3 failed - %s - not considered an error\n",
581 if (!test_LookupNames4(p
, mem_ctx
, &names
)) {
588 bool test_many_LookupSids(struct dcerpc_pipe
*p
,
590 struct policy_handle
*handle
)
594 struct lsa_SidArray sids
;
597 printf("\nTesting LookupSids with lots of SIDs\n");
601 sids
.sids
= talloc_array(mem_ctx
, struct lsa_SidPtr
, sids
.num_sids
);
603 for (i
=0; i
<sids
.num_sids
; i
++) {
604 const char *sidstr
= "S-1-5-32-545";
605 sids
.sids
[i
].sid
= dom_sid_parse_talloc(mem_ctx
, sidstr
);
608 count
= sids
.num_sids
;
611 struct lsa_LookupSids r
;
612 struct lsa_TransNameArray names
;
613 struct lsa_RefDomainList
*domains
= NULL
;
617 r
.in
.handle
= handle
;
621 r
.in
.count
= &names
.count
;
622 r
.out
.count
= &count
;
623 r
.out
.names
= &names
;
624 r
.out
.domains
= &domains
;
626 status
= dcerpc_lsa_LookupSids(p
, mem_ctx
, &r
);
627 if (!NT_STATUS_IS_OK(status
)) {
628 printf("LookupSids failed - %s\n", nt_errstr(status
));
634 if (!test_LookupNames(p
, mem_ctx
, handle
, &names
)) {
637 } else if (p
->conn
->security_state
.auth_info
->auth_type
== DCERPC_AUTH_TYPE_SCHANNEL
&&
638 p
->conn
->security_state
.auth_info
->auth_level
>= DCERPC_AUTH_LEVEL_INTEGRITY
) {
639 struct lsa_LookupSids3 r
;
640 struct lsa_RefDomainList
*domains
= NULL
;
641 struct lsa_TransNameArray2 names
;
646 printf("\nTesting LookupSids3\n");
654 r
.out
.count
= &count
;
655 r
.out
.names
= &names
;
656 r
.out
.domains
= &domains
;
658 status
= dcerpc_lsa_LookupSids3(p
, mem_ctx
, &r
);
659 if (!NT_STATUS_IS_OK(status
)) {
660 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
) ||
661 NT_STATUS_EQUAL(status
, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED
)) {
662 printf("not considering %s to be an error\n", nt_errstr(status
));
665 printf("LookupSids3 failed - %s\n",
669 if (!test_LookupNames4(p
, mem_ctx
, &names
)) {
681 static void lookupsids_cb(struct rpc_request
*req
)
683 int *replies
= (int *)req
->async
.private_data
;
686 status
= dcerpc_ndr_request_recv(req
);
687 if (!NT_STATUS_IS_OK(status
)) {
688 printf("lookupsids returned %s\n", nt_errstr(status
));
697 static bool test_LookupSids_async(struct dcerpc_pipe
*p
,
699 struct policy_handle
*handle
)
701 struct lsa_SidArray sids
;
702 struct lsa_SidPtr sidptr
;
704 struct lsa_TransNameArray
*names
;
705 struct lsa_LookupSids
*r
;
706 struct lsa_RefDomainList
*domains
= NULL
;
707 struct rpc_request
**req
;
710 const int num_async_requests
= 50;
712 count
= talloc_array(mem_ctx
, uint32_t, num_async_requests
);
713 names
= talloc_array(mem_ctx
, struct lsa_TransNameArray
, num_async_requests
);
714 r
= talloc_array(mem_ctx
, struct lsa_LookupSids
, num_async_requests
);
716 printf("\nTesting %d async lookupsids request\n", num_async_requests
);
718 req
= talloc_array(mem_ctx
, struct rpc_request
*, num_async_requests
);
722 sidptr
.sid
= dom_sid_parse_talloc(mem_ctx
, "S-1-5-32-545");
726 for (i
=0; i
<num_async_requests
; i
++) {
729 names
[i
].names
= NULL
;
731 r
[i
].in
.handle
= handle
;
732 r
[i
].in
.sids
= &sids
;
733 r
[i
].in
.names
= &names
[i
];
735 r
[i
].in
.count
= &names
[i
].count
;
736 r
[i
].out
.count
= &count
[i
];
737 r
[i
].out
.names
= &names
[i
];
738 r
[i
].out
.domains
= &domains
;
740 req
[i
] = dcerpc_lsa_LookupSids_send(p
, req
, &r
[i
]);
741 if (req
[i
] == NULL
) {
746 req
[i
]->async
.callback
= lookupsids_cb
;
747 req
[i
]->async
.private_data
= &replies
;
750 while (replies
>= 0 && replies
< num_async_requests
) {
751 event_loop_once(p
->conn
->event_ctx
);
763 static bool test_LookupPrivValue(struct dcerpc_pipe
*p
,
765 struct policy_handle
*handle
,
766 struct lsa_String
*name
)
769 struct lsa_LookupPrivValue r
;
770 struct lsa_LUID luid
;
772 r
.in
.handle
= handle
;
776 status
= dcerpc_lsa_LookupPrivValue(p
, mem_ctx
, &r
);
777 if (!NT_STATUS_IS_OK(status
)) {
778 printf("\nLookupPrivValue failed - %s\n", nt_errstr(status
));
785 static bool test_LookupPrivName(struct dcerpc_pipe
*p
,
787 struct policy_handle
*handle
,
788 struct lsa_LUID
*luid
)
791 struct lsa_LookupPrivName r
;
792 struct lsa_StringLarge
*name
= NULL
;
794 r
.in
.handle
= handle
;
798 status
= dcerpc_lsa_LookupPrivName(p
, mem_ctx
, &r
);
799 if (!NT_STATUS_IS_OK(status
)) {
800 printf("\nLookupPrivName failed - %s\n", nt_errstr(status
));
807 static bool test_RemovePrivilegesFromAccount(struct dcerpc_pipe
*p
,
809 struct policy_handle
*handle
,
810 struct policy_handle
*acct_handle
,
811 struct lsa_LUID
*luid
)
814 struct lsa_RemovePrivilegesFromAccount r
;
815 struct lsa_PrivilegeSet privs
;
818 printf("\nTesting RemovePrivilegesFromAccount\n");
820 r
.in
.handle
= acct_handle
;
826 privs
.set
= talloc_array(mem_ctx
, struct lsa_LUIDAttribute
, 1);
827 privs
.set
[0].luid
= *luid
;
828 privs
.set
[0].attribute
= 0;
830 status
= dcerpc_lsa_RemovePrivilegesFromAccount(p
, mem_ctx
, &r
);
831 if (!NT_STATUS_IS_OK(status
)) {
833 struct lsa_LookupPrivName r_name
;
834 struct lsa_StringLarge
*name
= NULL
;
836 r_name
.in
.handle
= handle
;
837 r_name
.in
.luid
= luid
;
838 r_name
.out
.name
= &name
;
840 status
= dcerpc_lsa_LookupPrivName(p
, mem_ctx
, &r_name
);
841 if (!NT_STATUS_IS_OK(status
)) {
842 printf("\nLookupPrivName failed - %s\n", nt_errstr(status
));
845 /* Windows 2008 does not allow this to be removed */
846 if (strcmp("SeAuditPrivilege", name
->string
) == 0) {
850 printf("RemovePrivilegesFromAccount failed to remove %s - %s\n",
859 static bool test_AddPrivilegesToAccount(struct dcerpc_pipe
*p
,
861 struct policy_handle
*acct_handle
,
862 struct lsa_LUID
*luid
)
865 struct lsa_AddPrivilegesToAccount r
;
866 struct lsa_PrivilegeSet privs
;
869 printf("\nTesting AddPrivilegesToAccount\n");
871 r
.in
.handle
= acct_handle
;
876 privs
.set
= talloc_array(mem_ctx
, struct lsa_LUIDAttribute
, 1);
877 privs
.set
[0].luid
= *luid
;
878 privs
.set
[0].attribute
= 0;
880 status
= dcerpc_lsa_AddPrivilegesToAccount(p
, mem_ctx
, &r
);
881 if (!NT_STATUS_IS_OK(status
)) {
882 printf("AddPrivilegesToAccount failed - %s\n", nt_errstr(status
));
889 static bool test_EnumPrivsAccount(struct dcerpc_pipe
*p
,
891 struct policy_handle
*handle
,
892 struct policy_handle
*acct_handle
)
895 struct lsa_EnumPrivsAccount r
;
896 struct lsa_PrivilegeSet
*privs
= NULL
;
899 printf("\nTesting EnumPrivsAccount\n");
901 r
.in
.handle
= acct_handle
;
902 r
.out
.privs
= &privs
;
904 status
= dcerpc_lsa_EnumPrivsAccount(p
, mem_ctx
, &r
);
905 if (!NT_STATUS_IS_OK(status
)) {
906 printf("EnumPrivsAccount failed - %s\n", nt_errstr(status
));
910 if (privs
&& privs
->count
> 0) {
912 for (i
=0;i
<privs
->count
;i
++) {
913 test_LookupPrivName(p
, mem_ctx
, handle
,
914 &privs
->set
[i
].luid
);
917 ret
&= test_RemovePrivilegesFromAccount(p
, mem_ctx
, handle
, acct_handle
,
918 &privs
->set
[0].luid
);
919 ret
&= test_AddPrivilegesToAccount(p
, mem_ctx
, acct_handle
,
920 &privs
->set
[0].luid
);
926 static bool test_GetSystemAccessAccount(struct dcerpc_pipe
*p
,
928 struct policy_handle
*handle
,
929 struct policy_handle
*acct_handle
)
932 uint32_t access_mask
;
933 struct lsa_GetSystemAccessAccount r
;
935 printf("\nTesting GetSystemAccessAccount\n");
937 r
.in
.handle
= acct_handle
;
938 r
.out
.access_mask
= &access_mask
;
940 status
= dcerpc_lsa_GetSystemAccessAccount(p
, mem_ctx
, &r
);
941 if (!NT_STATUS_IS_OK(status
)) {
942 printf("GetSystemAccessAccount failed - %s\n", nt_errstr(status
));
946 if (r
.out
.access_mask
!= NULL
) {
948 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_INTERACTIVE
)
949 printf(" LSA_POLICY_MODE_INTERACTIVE");
950 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_NETWORK
)
951 printf(" LSA_POLICY_MODE_NETWORK");
952 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_BATCH
)
953 printf(" LSA_POLICY_MODE_BATCH");
954 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_SERVICE
)
955 printf(" LSA_POLICY_MODE_SERVICE");
956 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_PROXY
)
957 printf(" LSA_POLICY_MODE_PROXY");
958 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_INTERACTIVE
)
959 printf(" LSA_POLICY_MODE_DENY_INTERACTIVE");
960 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_NETWORK
)
961 printf(" LSA_POLICY_MODE_DENY_NETWORK");
962 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_BATCH
)
963 printf(" LSA_POLICY_MODE_DENY_BATCH");
964 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_SERVICE
)
965 printf(" LSA_POLICY_MODE_DENY_SERVICE");
966 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_REMOTE_INTERACTIVE
)
967 printf(" LSA_POLICY_MODE_REMOTE_INTERACTIVE");
968 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_DENY_REMOTE_INTERACTIVE
)
969 printf(" LSA_POLICY_MODE_DENY_REMOTE_INTERACTIVE");
970 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_ALL
)
971 printf(" LSA_POLICY_MODE_ALL");
972 if (*(r
.out
.access_mask
) & LSA_POLICY_MODE_ALL_NT4
)
973 printf(" LSA_POLICY_MODE_ALL_NT4");
980 static bool test_Delete(struct dcerpc_pipe
*p
,
982 struct policy_handle
*handle
)
987 printf("\nTesting Delete\n");
989 r
.in
.handle
= handle
;
990 status
= dcerpc_lsa_Delete(p
, mem_ctx
, &r
);
991 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NOT_SUPPORTED
)) {
992 printf("Delete should have failed NT_STATUS_NOT_SUPPORTED - %s\n", nt_errstr(status
));
999 static bool test_DeleteObject(struct dcerpc_pipe
*p
,
1000 TALLOC_CTX
*mem_ctx
,
1001 struct policy_handle
*handle
)
1004 struct lsa_DeleteObject r
;
1006 printf("\nTesting DeleteObject\n");
1008 r
.in
.handle
= handle
;
1009 r
.out
.handle
= handle
;
1010 status
= dcerpc_lsa_DeleteObject(p
, mem_ctx
, &r
);
1011 if (!NT_STATUS_IS_OK(status
)) {
1012 printf("DeleteObject failed - %s\n", nt_errstr(status
));
1020 static bool test_CreateAccount(struct dcerpc_pipe
*p
,
1021 TALLOC_CTX
*mem_ctx
,
1022 struct policy_handle
*handle
)
1025 struct lsa_CreateAccount r
;
1026 struct dom_sid2
*newsid
;
1027 struct policy_handle acct_handle
;
1029 newsid
= dom_sid_parse_talloc(mem_ctx
, "S-1-5-12349876-4321-2854");
1031 printf("\nTesting CreateAccount\n");
1033 r
.in
.handle
= handle
;
1035 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1036 r
.out
.acct_handle
= &acct_handle
;
1038 status
= dcerpc_lsa_CreateAccount(p
, mem_ctx
, &r
);
1039 if (NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
1040 struct lsa_OpenAccount r_o
;
1041 r_o
.in
.handle
= handle
;
1042 r_o
.in
.sid
= newsid
;
1043 r_o
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1044 r_o
.out
.acct_handle
= &acct_handle
;
1046 status
= dcerpc_lsa_OpenAccount(p
, mem_ctx
, &r_o
);
1047 if (!NT_STATUS_IS_OK(status
)) {
1048 printf("OpenAccount failed - %s\n", nt_errstr(status
));
1051 } else if (!NT_STATUS_IS_OK(status
)) {
1052 printf("CreateAccount failed - %s\n", nt_errstr(status
));
1056 if (!test_Delete(p
, mem_ctx
, &acct_handle
)) {
1060 if (!test_DeleteObject(p
, mem_ctx
, &acct_handle
)) {
1067 static bool test_DeleteTrustedDomain(struct dcerpc_pipe
*p
,
1068 TALLOC_CTX
*mem_ctx
,
1069 struct policy_handle
*handle
,
1070 struct lsa_StringLarge name
)
1073 struct lsa_OpenTrustedDomainByName r
;
1074 struct policy_handle trustdom_handle
;
1076 r
.in
.handle
= handle
;
1077 r
.in
.name
.string
= name
.string
;
1078 r
.in
.access_mask
= SEC_STD_DELETE
;
1079 r
.out
.trustdom_handle
= &trustdom_handle
;
1081 status
= dcerpc_lsa_OpenTrustedDomainByName(p
, mem_ctx
, &r
);
1082 if (!NT_STATUS_IS_OK(status
)) {
1083 printf("OpenTrustedDomainByName failed - %s\n", nt_errstr(status
));
1087 if (!test_Delete(p
, mem_ctx
, &trustdom_handle
)) {
1091 if (!test_DeleteObject(p
, mem_ctx
, &trustdom_handle
)) {
1098 static bool test_DeleteTrustedDomainBySid(struct dcerpc_pipe
*p
,
1099 TALLOC_CTX
*mem_ctx
,
1100 struct policy_handle
*handle
,
1101 struct dom_sid
*sid
)
1104 struct lsa_DeleteTrustedDomain r
;
1106 r
.in
.handle
= handle
;
1109 status
= dcerpc_lsa_DeleteTrustedDomain(p
, mem_ctx
, &r
);
1110 if (!NT_STATUS_IS_OK(status
)) {
1111 printf("DeleteTrustedDomain failed - %s\n", nt_errstr(status
));
1119 static bool test_CreateSecret(struct dcerpc_pipe
*p
,
1120 TALLOC_CTX
*mem_ctx
,
1121 struct policy_handle
*handle
)
1124 struct lsa_CreateSecret r
;
1125 struct lsa_OpenSecret r2
;
1126 struct lsa_SetSecret r3
;
1127 struct lsa_QuerySecret r4
;
1128 struct lsa_SetSecret r5
;
1129 struct lsa_QuerySecret r6
;
1130 struct lsa_SetSecret r7
;
1131 struct lsa_QuerySecret r8
;
1132 struct policy_handle sec_handle
, sec_handle2
, sec_handle3
;
1133 struct lsa_DeleteObject d_o
;
1134 struct lsa_DATA_BUF buf1
;
1135 struct lsa_DATA_BUF_PTR bufp1
;
1136 struct lsa_DATA_BUF_PTR bufp2
;
1139 DATA_BLOB session_key
;
1140 NTTIME old_mtime
, new_mtime
;
1141 DATA_BLOB blob1
, blob2
;
1142 const char *secret1
= "abcdef12345699qwerty";
1144 const char *secret3
= "ABCDEF12345699QWERTY";
1146 const char *secret5
= "NEW-SAMBA4-SECRET";
1150 const int LOCAL
= 0;
1151 const int GLOBAL
= 1;
1153 secname
[LOCAL
] = talloc_asprintf(mem_ctx
, "torturesecret-%u", (uint_t
)random());
1154 secname
[GLOBAL
] = talloc_asprintf(mem_ctx
, "G$torturesecret-%u", (uint_t
)random());
1156 for (i
=0; i
< 2; i
++) {
1157 printf("\nTesting CreateSecret of %s\n", secname
[i
]);
1159 init_lsa_String(&r
.in
.name
, secname
[i
]);
1161 r
.in
.handle
= handle
;
1162 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1163 r
.out
.sec_handle
= &sec_handle
;
1165 status
= dcerpc_lsa_CreateSecret(p
, mem_ctx
, &r
);
1166 if (!NT_STATUS_IS_OK(status
)) {
1167 printf("CreateSecret failed - %s\n", nt_errstr(status
));
1171 r
.in
.handle
= handle
;
1172 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1173 r
.out
.sec_handle
= &sec_handle3
;
1175 status
= dcerpc_lsa_CreateSecret(p
, mem_ctx
, &r
);
1176 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
1177 printf("CreateSecret should have failed OBJECT_NAME_COLLISION - %s\n", nt_errstr(status
));
1181 r2
.in
.handle
= handle
;
1182 r2
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1183 r2
.in
.name
= r
.in
.name
;
1184 r2
.out
.sec_handle
= &sec_handle2
;
1186 printf("Testing OpenSecret\n");
1188 status
= dcerpc_lsa_OpenSecret(p
, mem_ctx
, &r2
);
1189 if (!NT_STATUS_IS_OK(status
)) {
1190 printf("OpenSecret failed - %s\n", nt_errstr(status
));
1194 status
= dcerpc_fetch_session_key(p
, &session_key
);
1195 if (!NT_STATUS_IS_OK(status
)) {
1196 printf("dcerpc_fetch_session_key failed - %s\n", nt_errstr(status
));
1200 enc_key
= sess_encrypt_string(secret1
, &session_key
);
1202 r3
.in
.sec_handle
= &sec_handle
;
1203 r3
.in
.new_val
= &buf1
;
1204 r3
.in
.old_val
= NULL
;
1205 r3
.in
.new_val
->data
= enc_key
.data
;
1206 r3
.in
.new_val
->length
= enc_key
.length
;
1207 r3
.in
.new_val
->size
= enc_key
.length
;
1209 printf("Testing SetSecret\n");
1211 status
= dcerpc_lsa_SetSecret(p
, mem_ctx
, &r3
);
1212 if (!NT_STATUS_IS_OK(status
)) {
1213 printf("SetSecret failed - %s\n", nt_errstr(status
));
1217 r3
.in
.sec_handle
= &sec_handle
;
1218 r3
.in
.new_val
= &buf1
;
1219 r3
.in
.old_val
= NULL
;
1220 r3
.in
.new_val
->data
= enc_key
.data
;
1221 r3
.in
.new_val
->length
= enc_key
.length
;
1222 r3
.in
.new_val
->size
= enc_key
.length
;
1224 /* break the encrypted data */
1227 printf("Testing SetSecret with broken key\n");
1229 status
= dcerpc_lsa_SetSecret(p
, mem_ctx
, &r3
);
1230 if (!NT_STATUS_EQUAL(status
, NT_STATUS_UNKNOWN_REVISION
)) {
1231 printf("SetSecret should have failed UNKNOWN_REVISION - %s\n", nt_errstr(status
));
1235 data_blob_free(&enc_key
);
1237 ZERO_STRUCT(new_mtime
);
1238 ZERO_STRUCT(old_mtime
);
1240 /* fetch the secret back again */
1241 r4
.in
.sec_handle
= &sec_handle
;
1242 r4
.in
.new_val
= &bufp1
;
1243 r4
.in
.new_mtime
= &new_mtime
;
1244 r4
.in
.old_val
= NULL
;
1245 r4
.in
.old_mtime
= NULL
;
1249 printf("Testing QuerySecret\n");
1250 status
= dcerpc_lsa_QuerySecret(p
, mem_ctx
, &r4
);
1251 if (!NT_STATUS_IS_OK(status
)) {
1252 printf("QuerySecret failed - %s\n", nt_errstr(status
));
1255 if (r4
.out
.new_val
== NULL
|| r4
.out
.new_val
->buf
== NULL
) {
1256 printf("No secret buffer returned\n");
1259 blob1
.data
= r4
.out
.new_val
->buf
->data
;
1260 blob1
.length
= r4
.out
.new_val
->buf
->size
;
1262 blob2
= data_blob_talloc(mem_ctx
, NULL
, blob1
.length
);
1264 secret2
= sess_decrypt_string(mem_ctx
,
1265 &blob1
, &session_key
);
1267 if (strcmp(secret1
, secret2
) != 0) {
1268 printf("Returned secret (r4) '%s' doesn't match '%s'\n",
1275 enc_key
= sess_encrypt_string(secret3
, &session_key
);
1277 r5
.in
.sec_handle
= &sec_handle
;
1278 r5
.in
.new_val
= &buf1
;
1279 r5
.in
.old_val
= NULL
;
1280 r5
.in
.new_val
->data
= enc_key
.data
;
1281 r5
.in
.new_val
->length
= enc_key
.length
;
1282 r5
.in
.new_val
->size
= enc_key
.length
;
1286 printf("Testing SetSecret (existing value should move to old)\n");
1288 status
= dcerpc_lsa_SetSecret(p
, mem_ctx
, &r5
);
1289 if (!NT_STATUS_IS_OK(status
)) {
1290 printf("SetSecret failed - %s\n", nt_errstr(status
));
1294 data_blob_free(&enc_key
);
1296 ZERO_STRUCT(new_mtime
);
1297 ZERO_STRUCT(old_mtime
);
1299 /* fetch the secret back again */
1300 r6
.in
.sec_handle
= &sec_handle
;
1301 r6
.in
.new_val
= &bufp1
;
1302 r6
.in
.new_mtime
= &new_mtime
;
1303 r6
.in
.old_val
= &bufp2
;
1304 r6
.in
.old_mtime
= &old_mtime
;
1309 status
= dcerpc_lsa_QuerySecret(p
, mem_ctx
, &r6
);
1310 if (!NT_STATUS_IS_OK(status
)) {
1311 printf("QuerySecret failed - %s\n", nt_errstr(status
));
1316 if (r6
.out
.new_val
->buf
== NULL
|| r6
.out
.old_val
->buf
== NULL
1317 || r6
.out
.new_mtime
== NULL
|| r6
.out
.old_mtime
== NULL
) {
1318 printf("Both secret buffers and both times not returned\n");
1322 blob1
.data
= r6
.out
.new_val
->buf
->data
;
1323 blob1
.length
= r6
.out
.new_val
->buf
->size
;
1325 blob2
= data_blob_talloc(mem_ctx
, NULL
, blob1
.length
);
1327 secret4
= sess_decrypt_string(mem_ctx
,
1328 &blob1
, &session_key
);
1330 if (strcmp(secret3
, secret4
) != 0) {
1331 printf("Returned NEW secret %s doesn't match %s\n", secret4
, secret3
);
1335 blob1
.data
= r6
.out
.old_val
->buf
->data
;
1336 blob1
.length
= r6
.out
.old_val
->buf
->length
;
1338 blob2
= data_blob_talloc(mem_ctx
, NULL
, blob1
.length
);
1340 secret2
= sess_decrypt_string(mem_ctx
,
1341 &blob1
, &session_key
);
1343 if (strcmp(secret1
, secret2
) != 0) {
1344 printf("Returned OLD secret %s doesn't match %s\n", secret2
, secret1
);
1348 if (*r6
.out
.new_mtime
== *r6
.out
.old_mtime
) {
1349 printf("Returned secret (r6-%d) %s must not have same mtime for both secrets: %s != %s\n",
1352 nt_time_string(mem_ctx
, *r6
.out
.old_mtime
),
1353 nt_time_string(mem_ctx
, *r6
.out
.new_mtime
));
1359 enc_key
= sess_encrypt_string(secret5
, &session_key
);
1361 r7
.in
.sec_handle
= &sec_handle
;
1362 r7
.in
.old_val
= &buf1
;
1363 r7
.in
.old_val
->data
= enc_key
.data
;
1364 r7
.in
.old_val
->length
= enc_key
.length
;
1365 r7
.in
.old_val
->size
= enc_key
.length
;
1366 r7
.in
.new_val
= NULL
;
1368 printf("Testing SetSecret of old Secret only\n");
1370 status
= dcerpc_lsa_SetSecret(p
, mem_ctx
, &r7
);
1371 if (!NT_STATUS_IS_OK(status
)) {
1372 printf("SetSecret failed - %s\n", nt_errstr(status
));
1376 data_blob_free(&enc_key
);
1378 /* fetch the secret back again */
1379 r8
.in
.sec_handle
= &sec_handle
;
1380 r8
.in
.new_val
= &bufp1
;
1381 r8
.in
.new_mtime
= &new_mtime
;
1382 r8
.in
.old_val
= &bufp2
;
1383 r8
.in
.old_mtime
= &old_mtime
;
1388 status
= dcerpc_lsa_QuerySecret(p
, mem_ctx
, &r8
);
1389 if (!NT_STATUS_IS_OK(status
)) {
1390 printf("QuerySecret failed - %s\n", nt_errstr(status
));
1393 if (!r8
.out
.new_val
|| !r8
.out
.old_val
) {
1394 printf("in/out pointers not returned, despite being set on in for QuerySecret\n");
1396 } else if (r8
.out
.new_val
->buf
!= NULL
) {
1397 printf("NEW secret buffer must not be returned after OLD set\n");
1399 } else if (r8
.out
.old_val
->buf
== NULL
) {
1400 printf("OLD secret buffer was not returned after OLD set\n");
1402 } else if (r8
.out
.new_mtime
== NULL
|| r8
.out
.old_mtime
== NULL
) {
1403 printf("Both times not returned after OLD set\n");
1406 blob1
.data
= r8
.out
.old_val
->buf
->data
;
1407 blob1
.length
= r8
.out
.old_val
->buf
->size
;
1409 blob2
= data_blob_talloc(mem_ctx
, NULL
, blob1
.length
);
1411 secret6
= sess_decrypt_string(mem_ctx
,
1412 &blob1
, &session_key
);
1414 if (strcmp(secret5
, secret6
) != 0) {
1415 printf("Returned OLD secret %s doesn't match %s\n", secret5
, secret6
);
1419 if (*r8
.out
.new_mtime
!= *r8
.out
.old_mtime
) {
1420 printf("Returned secret (r8) %s did not had same mtime for both secrets: %s != %s\n",
1422 nt_time_string(mem_ctx
, *r8
.out
.old_mtime
),
1423 nt_time_string(mem_ctx
, *r8
.out
.new_mtime
));
1429 if (!test_Delete(p
, mem_ctx
, &sec_handle
)) {
1433 if (!test_DeleteObject(p
, mem_ctx
, &sec_handle
)) {
1437 d_o
.in
.handle
= &sec_handle2
;
1438 d_o
.out
.handle
= &sec_handle2
;
1439 status
= dcerpc_lsa_DeleteObject(p
, mem_ctx
, &d_o
);
1440 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_HANDLE
)) {
1441 printf("Second delete expected INVALID_HANDLE - %s\n", nt_errstr(status
));
1445 printf("Testing OpenSecret of just-deleted secret\n");
1447 status
= dcerpc_lsa_OpenSecret(p
, mem_ctx
, &r2
);
1448 if (!NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
1449 printf("OpenSecret expected OBJECT_NAME_NOT_FOUND - %s\n", nt_errstr(status
));
1460 static bool test_EnumAccountRights(struct dcerpc_pipe
*p
,
1461 TALLOC_CTX
*mem_ctx
,
1462 struct policy_handle
*acct_handle
,
1463 struct dom_sid
*sid
)
1466 struct lsa_EnumAccountRights r
;
1467 struct lsa_RightSet rights
;
1469 printf("\nTesting EnumAccountRights\n");
1471 r
.in
.handle
= acct_handle
;
1473 r
.out
.rights
= &rights
;
1475 status
= dcerpc_lsa_EnumAccountRights(p
, mem_ctx
, &r
);
1476 if (!NT_STATUS_IS_OK(status
)) {
1477 printf("EnumAccountRights of %s failed - %s\n",
1478 dom_sid_string(mem_ctx
, sid
), nt_errstr(status
));
1486 static bool test_QuerySecurity(struct dcerpc_pipe
*p
,
1487 struct torture_context
*tctx
,
1488 struct policy_handle
*handle
,
1489 struct policy_handle
*acct_handle
)
1492 struct lsa_QuerySecurity r
;
1493 struct sec_desc_buf
*sdbuf
= NULL
;
1495 if (torture_setting_bool(tctx
, "samba4", false)) {
1496 printf("\nskipping QuerySecurity test against Samba4\n");
1500 printf("\nTesting QuerySecurity\n");
1502 r
.in
.handle
= acct_handle
;
1504 r
.out
.sdbuf
= &sdbuf
;
1506 status
= dcerpc_lsa_QuerySecurity(p
, tctx
, &r
);
1507 if (!NT_STATUS_IS_OK(status
)) {
1508 printf("QuerySecurity failed - %s\n", nt_errstr(status
));
1515 static bool test_OpenAccount(struct dcerpc_pipe
*p
,
1516 TALLOC_CTX
*mem_ctx
,
1517 struct policy_handle
*handle
,
1518 struct dom_sid
*sid
)
1521 struct lsa_OpenAccount r
;
1522 struct policy_handle acct_handle
;
1524 printf("\nTesting OpenAccount\n");
1526 r
.in
.handle
= handle
;
1528 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1529 r
.out
.acct_handle
= &acct_handle
;
1531 status
= dcerpc_lsa_OpenAccount(p
, mem_ctx
, &r
);
1532 if (!NT_STATUS_IS_OK(status
)) {
1533 printf("OpenAccount failed - %s\n", nt_errstr(status
));
1537 if (!test_EnumPrivsAccount(p
, mem_ctx
, handle
, &acct_handle
)) {
1541 if (!test_GetSystemAccessAccount(p
, mem_ctx
, handle
, &acct_handle
)) {
1545 if (!test_QuerySecurity(p
, mem_ctx
, handle
, &acct_handle
)) {
1552 static bool test_EnumAccounts(struct dcerpc_pipe
*p
,
1553 TALLOC_CTX
*mem_ctx
,
1554 struct policy_handle
*handle
)
1557 struct lsa_EnumAccounts r
;
1558 struct lsa_SidArray sids1
, sids2
;
1559 uint32_t resume_handle
= 0;
1563 printf("\nTesting EnumAccounts\n");
1565 r
.in
.handle
= handle
;
1566 r
.in
.resume_handle
= &resume_handle
;
1567 r
.in
.num_entries
= 100;
1568 r
.out
.resume_handle
= &resume_handle
;
1569 r
.out
.sids
= &sids1
;
1573 status
= dcerpc_lsa_EnumAccounts(p
, mem_ctx
, &r
);
1574 if (NT_STATUS_EQUAL(status
, NT_STATUS_NO_MORE_ENTRIES
)) {
1577 if (!NT_STATUS_IS_OK(status
)) {
1578 printf("EnumAccounts failed - %s\n", nt_errstr(status
));
1582 if (!test_LookupSids(p
, mem_ctx
, handle
, &sids1
)) {
1586 if (!test_LookupSids2(p
, mem_ctx
, handle
, &sids1
)) {
1590 /* Can't test lookupSids3 here, as clearly we must not
1591 * be on schannel, or we would not be able to do the
1594 printf("Testing all accounts\n");
1595 for (i
=0;i
<sids1
.num_sids
;i
++) {
1596 ret
&= test_OpenAccount(p
, mem_ctx
, handle
, sids1
.sids
[i
].sid
);
1597 ret
&= test_EnumAccountRights(p
, mem_ctx
, handle
, sids1
.sids
[i
].sid
);
1602 if (sids1
.num_sids
< 3) {
1606 printf("Trying EnumAccounts partial listing (asking for 1 at 2)\n");
1608 r
.in
.num_entries
= 1;
1609 r
.out
.sids
= &sids2
;
1611 status
= dcerpc_lsa_EnumAccounts(p
, mem_ctx
, &r
);
1612 if (!NT_STATUS_IS_OK(status
)) {
1613 printf("EnumAccounts failed - %s\n", nt_errstr(status
));
1617 if (sids2
.num_sids
!= 1) {
1618 printf("Returned wrong number of entries (%d)\n", sids2
.num_sids
);
1625 static bool test_LookupPrivDisplayName(struct dcerpc_pipe
*p
,
1626 TALLOC_CTX
*mem_ctx
,
1627 struct policy_handle
*handle
,
1628 struct lsa_String
*priv_name
)
1630 struct lsa_LookupPrivDisplayName r
;
1632 /* produce a reasonable range of language output without screwing up
1634 uint16_t language_id
= (random() % 4) + 0x409;
1635 uint16_t returned_language_id
= 0;
1636 struct lsa_StringLarge
*disp_name
= NULL
;
1638 printf("\nTesting LookupPrivDisplayName(%s)\n", priv_name
->string
);
1640 r
.in
.handle
= handle
;
1641 r
.in
.name
= priv_name
;
1642 r
.in
.language_id
= language_id
;
1643 r
.in
.language_id_sys
= 0;
1644 r
.out
.returned_language_id
= &returned_language_id
;
1645 r
.out
.disp_name
= &disp_name
;
1647 status
= dcerpc_lsa_LookupPrivDisplayName(p
, mem_ctx
, &r
);
1648 if (!NT_STATUS_IS_OK(status
)) {
1649 printf("LookupPrivDisplayName failed - %s\n", nt_errstr(status
));
1652 printf("%s -> \"%s\" (language 0x%x/0x%x)\n",
1653 priv_name
->string
, disp_name
->string
,
1654 r
.in
.language_id
, *r
.out
.returned_language_id
);
1659 static bool test_EnumAccountsWithUserRight(struct dcerpc_pipe
*p
,
1660 TALLOC_CTX
*mem_ctx
,
1661 struct policy_handle
*handle
,
1662 struct lsa_String
*priv_name
)
1664 struct lsa_EnumAccountsWithUserRight r
;
1665 struct lsa_SidArray sids
;
1670 printf("\nTesting EnumAccountsWithUserRight(%s)\n", priv_name
->string
);
1672 r
.in
.handle
= handle
;
1673 r
.in
.name
= priv_name
;
1676 status
= dcerpc_lsa_EnumAccountsWithUserRight(p
, mem_ctx
, &r
);
1678 /* NT_STATUS_NO_MORE_ENTRIES means noone has this privilege */
1679 if (NT_STATUS_EQUAL(status
, NT_STATUS_NO_MORE_ENTRIES
)) {
1683 if (!NT_STATUS_IS_OK(status
)) {
1684 printf("EnumAccountsWithUserRight failed - %s\n", nt_errstr(status
));
1692 static bool test_EnumPrivs(struct dcerpc_pipe
*p
,
1693 TALLOC_CTX
*mem_ctx
,
1694 struct policy_handle
*handle
)
1697 struct lsa_EnumPrivs r
;
1698 struct lsa_PrivArray privs1
;
1699 uint32_t resume_handle
= 0;
1703 printf("\nTesting EnumPrivs\n");
1705 r
.in
.handle
= handle
;
1706 r
.in
.resume_handle
= &resume_handle
;
1707 r
.in
.max_count
= 100;
1708 r
.out
.resume_handle
= &resume_handle
;
1709 r
.out
.privs
= &privs1
;
1712 status
= dcerpc_lsa_EnumPrivs(p
, mem_ctx
, &r
);
1713 if (!NT_STATUS_IS_OK(status
)) {
1714 printf("EnumPrivs failed - %s\n", nt_errstr(status
));
1718 for (i
= 0; i
< privs1
.count
; i
++) {
1719 test_LookupPrivDisplayName(p
, mem_ctx
, handle
, (struct lsa_String
*)&privs1
.privs
[i
].name
);
1720 test_LookupPrivValue(p
, mem_ctx
, handle
, (struct lsa_String
*)&privs1
.privs
[i
].name
);
1721 if (!test_EnumAccountsWithUserRight(p
, mem_ctx
, handle
, (struct lsa_String
*)&privs1
.privs
[i
].name
)) {
1729 static bool test_QueryForestTrustInformation(struct dcerpc_pipe
*p
,
1730 struct torture_context
*tctx
,
1731 struct policy_handle
*handle
,
1732 const char *trusted_domain_name
)
1735 struct lsa_lsaRQueryForestTrustInformation r
;
1737 struct lsa_String string
;
1738 struct lsa_ForestTrustInformation info
, *info_ptr
;
1740 printf("\nTesting lsaRQueryForestTrustInformation\n");
1742 if (torture_setting_bool(tctx
, "samba4", false)) {
1743 printf("skipping QueryForestTrustInformation against Samba4\n");
1747 ZERO_STRUCT(string
);
1749 if (trusted_domain_name
) {
1750 init_lsa_String(&string
, trusted_domain_name
);
1755 r
.in
.handle
= handle
;
1756 r
.in
.trusted_domain_name
= &string
;
1758 r
.out
.forest_trust_info
= &info_ptr
;
1760 status
= dcerpc_lsa_lsaRQueryForestTrustInformation(p
, tctx
, &r
);
1762 if (!NT_STATUS_IS_OK(status
)) {
1763 printf("lsaRQueryForestTrustInformation of %s failed - %s\n", trusted_domain_name
, nt_errstr(status
));
1770 static bool test_query_each_TrustDomEx(struct dcerpc_pipe
*p
,
1771 TALLOC_CTX
*mem_ctx
,
1772 struct policy_handle
*handle
,
1773 struct lsa_DomainListEx
*domains
)
1778 for (i
=0; i
< domains
->count
; i
++) {
1780 if (domains
->domains
[i
].trust_attributes
& NETR_TRUST_ATTRIBUTE_FOREST_TRANSITIVE
) {
1781 ret
&= test_QueryForestTrustInformation(p
, mem_ctx
, handle
,
1782 domains
->domains
[i
].domain_name
.string
);
1789 static bool test_query_each_TrustDom(struct dcerpc_pipe
*p
,
1790 TALLOC_CTX
*mem_ctx
,
1791 struct policy_handle
*handle
,
1792 struct lsa_DomainList
*domains
)
1798 printf("\nTesting OpenTrustedDomain, OpenTrustedDomainByName and QueryInfoTrustedDomain\n");
1799 for (i
=0; i
< domains
->count
; i
++) {
1800 struct lsa_OpenTrustedDomain trust
;
1801 struct lsa_OpenTrustedDomainByName trust_by_name
;
1802 struct policy_handle trustdom_handle
;
1803 struct policy_handle handle2
;
1805 struct lsa_CloseTrustedDomainEx c_trust
;
1806 int levels
[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
1807 int ok
[] = {1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1};
1809 if (domains
->domains
[i
].sid
) {
1810 trust
.in
.handle
= handle
;
1811 trust
.in
.sid
= domains
->domains
[i
].sid
;
1812 trust
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1813 trust
.out
.trustdom_handle
= &trustdom_handle
;
1815 status
= dcerpc_lsa_OpenTrustedDomain(p
, mem_ctx
, &trust
);
1817 if (!NT_STATUS_IS_OK(status
)) {
1818 printf("OpenTrustedDomain failed - %s\n", nt_errstr(status
));
1822 c
.in
.handle
= &trustdom_handle
;
1823 c
.out
.handle
= &handle2
;
1825 c_trust
.in
.handle
= &trustdom_handle
;
1826 c_trust
.out
.handle
= &handle2
;
1828 for (j
=0; j
< ARRAY_SIZE(levels
); j
++) {
1829 struct lsa_QueryTrustedDomainInfo q
;
1830 union lsa_TrustedDomainInfo
*info
= NULL
;
1831 q
.in
.trustdom_handle
= &trustdom_handle
;
1832 q
.in
.level
= levels
[j
];
1834 status
= dcerpc_lsa_QueryTrustedDomainInfo(p
, mem_ctx
, &q
);
1835 if (!NT_STATUS_IS_OK(status
) && ok
[j
]) {
1836 printf("QueryTrustedDomainInfo level %d failed - %s\n",
1837 levels
[j
], nt_errstr(status
));
1839 } else if (NT_STATUS_IS_OK(status
) && !ok
[j
]) {
1840 printf("QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
1841 levels
[j
], nt_errstr(status
));
1846 status
= dcerpc_lsa_CloseTrustedDomainEx(p
, mem_ctx
, &c_trust
);
1847 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NOT_IMPLEMENTED
)) {
1848 printf("Expected CloseTrustedDomainEx to return NT_STATUS_NOT_IMPLEMENTED, instead - %s\n", nt_errstr(status
));
1852 c
.in
.handle
= &trustdom_handle
;
1853 c
.out
.handle
= &handle2
;
1855 status
= dcerpc_lsa_Close(p
, mem_ctx
, &c
);
1856 if (!NT_STATUS_IS_OK(status
)) {
1857 printf("Close of trusted domain failed - %s\n", nt_errstr(status
));
1861 for (j
=0; j
< ARRAY_SIZE(levels
); j
++) {
1862 struct lsa_QueryTrustedDomainInfoBySid q
;
1863 union lsa_TrustedDomainInfo
*info
= NULL
;
1865 if (!domains
->domains
[i
].sid
) {
1869 q
.in
.handle
= handle
;
1870 q
.in
.dom_sid
= domains
->domains
[i
].sid
;
1871 q
.in
.level
= levels
[j
];
1874 status
= dcerpc_lsa_QueryTrustedDomainInfoBySid(p
, mem_ctx
, &q
);
1875 if (!NT_STATUS_IS_OK(status
) && ok
[j
]) {
1876 printf("QueryTrustedDomainInfoBySid level %d failed - %s\n",
1877 levels
[j
], nt_errstr(status
));
1879 } else if (NT_STATUS_IS_OK(status
) && !ok
[j
]) {
1880 printf("QueryTrustedDomainInfoBySid level %d unexpectedly succeeded - %s\n",
1881 levels
[j
], nt_errstr(status
));
1887 trust_by_name
.in
.handle
= handle
;
1888 trust_by_name
.in
.name
.string
= domains
->domains
[i
].name
.string
;
1889 trust_by_name
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
1890 trust_by_name
.out
.trustdom_handle
= &trustdom_handle
;
1892 status
= dcerpc_lsa_OpenTrustedDomainByName(p
, mem_ctx
, &trust_by_name
);
1894 if (!NT_STATUS_IS_OK(status
)) {
1895 printf("OpenTrustedDomainByName failed - %s\n", nt_errstr(status
));
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
, mem_ctx
, &q
);
1906 if (!NT_STATUS_IS_OK(status
) && ok
[j
]) {
1907 printf("QueryTrustedDomainInfo level %d failed - %s\n",
1908 levels
[j
], nt_errstr(status
));
1910 } else if (NT_STATUS_IS_OK(status
) && !ok
[j
]) {
1911 printf("QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
1912 levels
[j
], nt_errstr(status
));
1917 c
.in
.handle
= &trustdom_handle
;
1918 c
.out
.handle
= &handle2
;
1920 status
= dcerpc_lsa_Close(p
, mem_ctx
, &c
);
1921 if (!NT_STATUS_IS_OK(status
)) {
1922 printf("Close of trusted domain failed - %s\n", nt_errstr(status
));
1926 for (j
=0; j
< ARRAY_SIZE(levels
); j
++) {
1927 struct lsa_QueryTrustedDomainInfoByName q
;
1928 union lsa_TrustedDomainInfo
*info
= NULL
;
1929 struct lsa_String name
;
1931 name
.string
= domains
->domains
[i
].name
.string
;
1933 q
.in
.handle
= handle
;
1934 q
.in
.trusted_domain
= &name
;
1935 q
.in
.level
= levels
[j
];
1937 status
= dcerpc_lsa_QueryTrustedDomainInfoByName(p
, mem_ctx
, &q
);
1938 if (!NT_STATUS_IS_OK(status
) && ok
[j
]) {
1939 printf("QueryTrustedDomainInfoByName level %d failed - %s\n",
1940 levels
[j
], nt_errstr(status
));
1942 } else if (NT_STATUS_IS_OK(status
) && !ok
[j
]) {
1943 printf("QueryTrustedDomainInfoByName level %d unexpectedly succeeded - %s\n",
1944 levels
[j
], nt_errstr(status
));
1952 static bool test_EnumTrustDom(struct dcerpc_pipe
*p
,
1953 TALLOC_CTX
*mem_ctx
,
1954 struct policy_handle
*handle
)
1956 struct lsa_EnumTrustDom r
;
1957 struct lsa_EnumTrustedDomainsEx r_ex
;
1958 NTSTATUS enum_status
;
1959 uint32_t resume_handle
= 0;
1960 struct lsa_DomainList domains
;
1961 struct lsa_DomainListEx domains_ex
;
1964 printf("\nTesting EnumTrustDom\n");
1966 r
.in
.handle
= handle
;
1967 r
.in
.resume_handle
= &resume_handle
;
1969 r
.out
.domains
= &domains
;
1970 r
.out
.resume_handle
= &resume_handle
;
1972 enum_status
= dcerpc_lsa_EnumTrustDom(p
, mem_ctx
, &r
);
1974 if (NT_STATUS_IS_OK(enum_status
)) {
1975 if (domains
.count
== 0) {
1976 printf("EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
1979 } else if (!(NT_STATUS_EQUAL(enum_status
, STATUS_MORE_ENTRIES
) || NT_STATUS_EQUAL(enum_status
, NT_STATUS_NO_MORE_ENTRIES
))) {
1980 printf("EnumTrustDom of zero size failed - %s\n", nt_errstr(enum_status
));
1984 /* Start from the bottom again */
1988 r
.in
.handle
= handle
;
1989 r
.in
.resume_handle
= &resume_handle
;
1990 r
.in
.max_size
= LSA_ENUM_TRUST_DOMAIN_MULTIPLIER
* 3;
1991 r
.out
.domains
= &domains
;
1992 r
.out
.resume_handle
= &resume_handle
;
1994 enum_status
= dcerpc_lsa_EnumTrustDom(p
, mem_ctx
, &r
);
1996 /* NO_MORE_ENTRIES is allowed */
1997 if (NT_STATUS_EQUAL(enum_status
, NT_STATUS_NO_MORE_ENTRIES
)) {
1998 if (domains
.count
== 0) {
2001 printf("EnumTrustDom failed - should have returned 0 trusted domains with 'NT_STATUS_NO_MORE_ENTRIES'\n");
2003 } else if (NT_STATUS_EQUAL(enum_status
, STATUS_MORE_ENTRIES
)) {
2004 /* Windows 2003 gets this off by one on the first run */
2005 if (r
.out
.domains
->count
< 3 || r
.out
.domains
->count
> 4) {
2006 printf("EnumTrustDom didn't fill the buffer we "
2007 "asked it to (got %d, expected %d / %d == %d entries)\n",
2008 r
.out
.domains
->count
, LSA_ENUM_TRUST_DOMAIN_MULTIPLIER
* 3,
2009 LSA_ENUM_TRUST_DOMAIN_MULTIPLIER
, r
.in
.max_size
);
2012 } else if (!NT_STATUS_IS_OK(enum_status
)) {
2013 printf("EnumTrustDom failed - %s\n", nt_errstr(enum_status
));
2017 if (domains
.count
== 0) {
2018 printf("EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2022 ret
&= test_query_each_TrustDom(p
, mem_ctx
, handle
, &domains
);
2024 } while ((NT_STATUS_EQUAL(enum_status
, STATUS_MORE_ENTRIES
)));
2026 printf("\nTesting EnumTrustedDomainsEx\n");
2028 r_ex
.in
.handle
= handle
;
2029 r_ex
.in
.resume_handle
= &resume_handle
;
2030 r_ex
.in
.max_size
= LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER
* 3;
2031 r_ex
.out
.domains
= &domains_ex
;
2032 r_ex
.out
.resume_handle
= &resume_handle
;
2034 enum_status
= dcerpc_lsa_EnumTrustedDomainsEx(p
, mem_ctx
, &r_ex
);
2036 if (!(NT_STATUS_EQUAL(enum_status
, STATUS_MORE_ENTRIES
) || NT_STATUS_EQUAL(enum_status
, NT_STATUS_NO_MORE_ENTRIES
))) {
2037 printf("EnumTrustedDomainEx of zero size failed - %s\n", nt_errstr(enum_status
));
2043 r_ex
.in
.handle
= handle
;
2044 r_ex
.in
.resume_handle
= &resume_handle
;
2045 r_ex
.in
.max_size
= LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER
* 3;
2046 r_ex
.out
.domains
= &domains_ex
;
2047 r_ex
.out
.resume_handle
= &resume_handle
;
2049 enum_status
= dcerpc_lsa_EnumTrustedDomainsEx(p
, mem_ctx
, &r_ex
);
2051 /* NO_MORE_ENTRIES is allowed */
2052 if (NT_STATUS_EQUAL(enum_status
, NT_STATUS_NO_MORE_ENTRIES
)) {
2053 if (domains_ex
.count
== 0) {
2056 printf("EnumTrustDomainsEx failed - should have returned 0 trusted domains with 'NT_STATUS_NO_MORE_ENTRIES'\n");
2058 } else if (NT_STATUS_EQUAL(enum_status
, STATUS_MORE_ENTRIES
)) {
2059 /* Windows 2003 gets this off by one on the first run */
2060 if (r_ex
.out
.domains
->count
< 3 || r_ex
.out
.domains
->count
> 4) {
2061 printf("EnumTrustDom didn't fill the buffer we "
2062 "asked it to (got %d, expected %d / %d == %d entries)\n",
2063 r_ex
.out
.domains
->count
,
2065 LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER
,
2066 r_ex
.in
.max_size
/ LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER
);
2068 } else if (!NT_STATUS_IS_OK(enum_status
)) {
2069 printf("EnumTrustedDomainEx failed - %s\n", nt_errstr(enum_status
));
2073 if (domains_ex
.count
== 0) {
2074 printf("EnumTrustDomainEx failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2078 ret
&= test_query_each_TrustDomEx(p
, mem_ctx
, handle
, &domains_ex
);
2080 } while ((NT_STATUS_EQUAL(enum_status
, STATUS_MORE_ENTRIES
)));
2085 static bool test_CreateTrustedDomain(struct dcerpc_pipe
*p
,
2086 TALLOC_CTX
*mem_ctx
,
2087 struct policy_handle
*handle
)
2091 struct lsa_CreateTrustedDomain r
;
2092 struct lsa_DomainInfo trustinfo
;
2093 struct dom_sid
*domsid
[12];
2094 struct policy_handle trustdom_handle
[12];
2095 struct lsa_QueryTrustedDomainInfo q
;
2096 union lsa_TrustedDomainInfo
*info
= NULL
;
2099 printf("\nTesting CreateTrustedDomain for 12 domains\n");
2101 if (!test_EnumTrustDom(p
, mem_ctx
, handle
)) {
2105 for (i
=0; i
< 12; i
++) {
2106 char *trust_name
= talloc_asprintf(mem_ctx
, "torturedom%02d", i
);
2107 char *trust_sid
= talloc_asprintf(mem_ctx
, "S-1-5-21-97398-379795-100%02d", i
);
2109 domsid
[i
] = dom_sid_parse_talloc(mem_ctx
, trust_sid
);
2111 trustinfo
.sid
= domsid
[i
];
2112 init_lsa_String((struct lsa_String
*)&trustinfo
.name
, trust_name
);
2114 r
.in
.policy_handle
= handle
;
2115 r
.in
.info
= &trustinfo
;
2116 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2117 r
.out
.trustdom_handle
= &trustdom_handle
[i
];
2119 status
= dcerpc_lsa_CreateTrustedDomain(p
, mem_ctx
, &r
);
2120 if (NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
2121 test_DeleteTrustedDomain(p
, mem_ctx
, handle
, trustinfo
.name
);
2122 status
= dcerpc_lsa_CreateTrustedDomain(p
, mem_ctx
, &r
);
2124 if (!NT_STATUS_IS_OK(status
)) {
2125 printf("CreateTrustedDomain failed - %s\n", nt_errstr(status
));
2129 q
.in
.trustdom_handle
= &trustdom_handle
[i
];
2130 q
.in
.level
= LSA_TRUSTED_DOMAIN_INFO_INFO_EX
;
2132 status
= dcerpc_lsa_QueryTrustedDomainInfo(p
, mem_ctx
, &q
);
2133 if (!NT_STATUS_IS_OK(status
)) {
2134 printf("QueryTrustedDomainInfo level 1 failed - %s\n", nt_errstr(status
));
2136 } else if (!q
.out
.info
) {
2139 if (strcmp(info
->info_ex
.netbios_name
.string
, trustinfo
.name
.string
) != 0) {
2140 printf("QueryTrustedDomainInfo returned inconsistant short name: %s != %s\n",
2141 info
->info_ex
.netbios_name
.string
, trustinfo
.name
.string
);
2144 if (info
->info_ex
.trust_type
!= LSA_TRUST_TYPE_DOWNLEVEL
) {
2145 printf("QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
2146 trust_name
, info
->info_ex
.trust_type
, LSA_TRUST_TYPE_DOWNLEVEL
);
2149 if (info
->info_ex
.trust_attributes
!= 0) {
2150 printf("QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
2151 trust_name
, info
->info_ex
.trust_attributes
, 0);
2154 if (info
->info_ex
.trust_direction
!= LSA_TRUST_DIRECTION_OUTBOUND
) {
2155 printf("QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
2156 trust_name
, info
->info_ex
.trust_direction
, LSA_TRUST_DIRECTION_OUTBOUND
);
2163 /* now that we have some domains to look over, we can test the enum calls */
2164 if (!test_EnumTrustDom(p
, mem_ctx
, handle
)) {
2168 for (i
=0; i
<12; i
++) {
2169 if (!test_DeleteTrustedDomainBySid(p
, mem_ctx
, handle
, domsid
[i
])) {
2177 static bool test_CreateTrustedDomainEx2(struct dcerpc_pipe
*p
,
2178 struct torture_context
*tctx
,
2179 TALLOC_CTX
*mem_ctx
,
2180 struct policy_handle
*handle
)
2184 struct lsa_CreateTrustedDomainEx2 r
;
2185 struct lsa_TrustDomainInfoInfoEx trustinfo
;
2186 struct lsa_TrustDomainInfoAuthInfoInternal authinfo
;
2187 struct trustDomainPasswords auth_struct
;
2188 DATA_BLOB auth_blob
;
2189 struct dom_sid
*domsid
[12];
2190 struct policy_handle trustdom_handle
[12];
2191 struct lsa_QueryTrustedDomainInfo q
;
2192 union lsa_TrustedDomainInfo
*info
= NULL
;
2193 DATA_BLOB session_key
;
2194 enum ndr_err_code ndr_err
;
2197 printf("\nTesting CreateTrustedDomainEx2 for 12 domains\n");
2199 status
= dcerpc_fetch_session_key(p
, &session_key
);
2200 if (!NT_STATUS_IS_OK(status
)) {
2201 printf("dcerpc_fetch_session_key failed - %s\n", nt_errstr(status
));
2205 for (i
=0; i
< 12; i
++) {
2206 char *trust_name
= talloc_asprintf(mem_ctx
, "torturedom%02d", i
);
2207 char *trust_name_dns
= talloc_asprintf(mem_ctx
, "torturedom%02d.samba.example.com", i
);
2208 char *trust_sid
= talloc_asprintf(mem_ctx
, "S-1-5-21-97398-379795-100%02d", i
);
2210 domsid
[i
] = dom_sid_parse_talloc(mem_ctx
, trust_sid
);
2212 trustinfo
.sid
= domsid
[i
];
2213 trustinfo
.netbios_name
.string
= trust_name
;
2214 trustinfo
.domain_name
.string
= trust_name_dns
;
2216 /* Create inbound, some outbound, and some
2217 * bi-directional trusts in a repeating pattern based
2220 /* 1 == inbound, 2 == outbound, 3 == both */
2221 trustinfo
.trust_direction
= (i
% 3) + 1;
2223 /* Try different trust types too */
2225 /* 1 == downlevel (NT4), 2 == uplevel (ADS), 3 == MIT (kerberos but not AD) */
2226 trustinfo
.trust_type
= (((i
/ 3) + 1) % 3) + 1;
2228 trustinfo
.trust_attributes
= LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION
;
2230 generate_random_buffer(auth_struct
.confounder
, sizeof(auth_struct
.confounder
));
2232 auth_struct
.outgoing
.count
= 0;
2233 auth_struct
.incoming
.count
= 0;
2235 ndr_err
= ndr_push_struct_blob(&auth_blob
, mem_ctx
, lp_iconv_convenience(tctx
->lp_ctx
), &auth_struct
,
2236 (ndr_push_flags_fn_t
)ndr_push_trustDomainPasswords
);
2237 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2238 printf("ndr_push_struct_blob of trustDomainPasswords structure failed");
2242 arcfour_crypt_blob(auth_blob
.data
, auth_blob
.length
, &session_key
);
2244 authinfo
.auth_blob
.size
= auth_blob
.length
;
2245 authinfo
.auth_blob
.data
= auth_blob
.data
;
2247 r
.in
.policy_handle
= handle
;
2248 r
.in
.info
= &trustinfo
;
2249 r
.in
.auth_info
= &authinfo
;
2250 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
2251 r
.out
.trustdom_handle
= &trustdom_handle
[i
];
2253 status
= dcerpc_lsa_CreateTrustedDomainEx2(p
, mem_ctx
, &r
);
2254 if (NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
2255 test_DeleteTrustedDomain(p
, mem_ctx
, handle
, trustinfo
.netbios_name
);
2256 status
= dcerpc_lsa_CreateTrustedDomainEx2(p
, mem_ctx
, &r
);
2258 if (!NT_STATUS_IS_OK(status
)) {
2259 printf("CreateTrustedDomainEx failed2 - %s\n", nt_errstr(status
));
2263 q
.in
.trustdom_handle
= &trustdom_handle
[i
];
2264 q
.in
.level
= LSA_TRUSTED_DOMAIN_INFO_INFO_EX
;
2266 status
= dcerpc_lsa_QueryTrustedDomainInfo(p
, mem_ctx
, &q
);
2267 if (!NT_STATUS_IS_OK(status
)) {
2268 printf("QueryTrustedDomainInfo level 1 failed - %s\n", nt_errstr(status
));
2270 } else if (!q
.out
.info
) {
2271 printf("QueryTrustedDomainInfo level 1 failed to return an info pointer\n");
2274 if (strcmp(info
->info_ex
.netbios_name
.string
, trustinfo
.netbios_name
.string
) != 0) {
2275 printf("QueryTrustedDomainInfo returned inconsistant short name: %s != %s\n",
2276 info
->info_ex
.netbios_name
.string
, trustinfo
.netbios_name
.string
);
2279 if (info
->info_ex
.trust_type
!= trustinfo
.trust_type
) {
2280 printf("QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
2281 trust_name
, info
->info_ex
.trust_type
, trustinfo
.trust_type
);
2284 if (info
->info_ex
.trust_attributes
!= LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION
) {
2285 printf("QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
2286 trust_name
, info
->info_ex
.trust_attributes
, LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION
);
2289 if (info
->info_ex
.trust_direction
!= trustinfo
.trust_direction
) {
2290 printf("QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
2291 trust_name
, info
->info_ex
.trust_direction
, trustinfo
.trust_direction
);
2298 /* now that we have some domains to look over, we can test the enum calls */
2299 if (!test_EnumTrustDom(p
, mem_ctx
, handle
)) {
2300 printf("test_EnumTrustDom failed\n");
2304 for (i
=0; i
<12; i
++) {
2305 if (!test_DeleteTrustedDomainBySid(p
, mem_ctx
, handle
, domsid
[i
])) {
2306 printf("test_DeleteTrustedDomainBySid failed\n");
2314 static bool test_QueryDomainInfoPolicy(struct dcerpc_pipe
*p
,
2315 struct torture_context
*tctx
,
2316 struct policy_handle
*handle
)
2318 struct lsa_QueryDomainInformationPolicy r
;
2319 union lsa_DomainInformationPolicy
*info
= NULL
;
2324 printf("\nTesting QueryDomainInformationPolicy\n");
2327 r
.in
.handle
= handle
;
2331 printf("\nTrying QueryDomainInformationPolicy level %d\n", i
);
2333 status
= dcerpc_lsa_QueryDomainInformationPolicy(p
, tctx
, &r
);
2335 /* If the server does not support EFS, then this is the correct return */
2336 if (i
== LSA_DOMAIN_INFO_POLICY_EFS
&& NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
2338 } else if (!NT_STATUS_IS_OK(status
)) {
2339 printf("QueryDomainInformationPolicy failed - %s\n", nt_errstr(status
));
2349 static bool test_QueryInfoPolicyCalls( bool version2
,
2350 struct dcerpc_pipe
*p
,
2351 struct torture_context
*tctx
,
2352 struct policy_handle
*handle
)
2354 struct lsa_QueryInfoPolicy r
;
2355 union lsa_PolicyInformation
*info
= NULL
;
2361 printf("\nTesting QueryInfoPolicy2\n");
2363 printf("\nTesting QueryInfoPolicy\n");
2365 for (i
=1;i
<=14;i
++) {
2366 r
.in
.handle
= handle
;
2371 printf("\nTrying QueryInfoPolicy2 level %d\n", i
);
2373 printf("\nTrying QueryInfoPolicy level %d\n", i
);
2376 /* We can perform the cast, because both types are
2377 structurally equal */
2378 status
= dcerpc_lsa_QueryInfoPolicy2(p
, tctx
,
2379 (struct lsa_QueryInfoPolicy2
*) &r
);
2381 status
= dcerpc_lsa_QueryInfoPolicy(p
, tctx
, &r
);
2384 case LSA_POLICY_INFO_MOD
:
2385 case LSA_POLICY_INFO_AUDIT_FULL_SET
:
2386 case LSA_POLICY_INFO_AUDIT_FULL_QUERY
:
2387 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_PARAMETER
)) {
2388 printf("Server should have failed level %u: %s\n", i
, nt_errstr(status
));
2392 case LSA_POLICY_INFO_DOMAIN
:
2393 case LSA_POLICY_INFO_ACCOUNT_DOMAIN
:
2394 case LSA_POLICY_INFO_L_ACCOUNT_DOMAIN
:
2395 case LSA_POLICY_INFO_DNS_INT
:
2396 case LSA_POLICY_INFO_DNS
:
2397 case LSA_POLICY_INFO_REPLICA
:
2398 case LSA_POLICY_INFO_QUOTA
:
2399 case LSA_POLICY_INFO_ROLE
:
2400 case LSA_POLICY_INFO_AUDIT_LOG
:
2401 case LSA_POLICY_INFO_AUDIT_EVENTS
:
2402 case LSA_POLICY_INFO_PD
:
2403 if (!NT_STATUS_IS_OK(status
)) {
2405 printf("QueryInfoPolicy2 failed - %s\n", nt_errstr(status
));
2407 printf("QueryInfoPolicy failed - %s\n", nt_errstr(status
));
2412 if (torture_setting_bool(tctx
, "samba4", false)) {
2413 /* Other levels not implemented yet */
2414 if (!NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_INFO_CLASS
)) {
2416 printf("QueryInfoPolicy2 failed - %s\n", nt_errstr(status
));
2418 printf("QueryInfoPolicy failed - %s\n", nt_errstr(status
));
2421 } else if (!NT_STATUS_IS_OK(status
)) {
2423 printf("QueryInfoPolicy2 failed - %s\n", nt_errstr(status
));
2425 printf("QueryInfoPolicy failed - %s\n", nt_errstr(status
));
2431 if (NT_STATUS_IS_OK(status
) && (i
== LSA_POLICY_INFO_DNS
2432 || i
== LSA_POLICY_INFO_DNS_INT
)) {
2433 /* Let's look up some of these names */
2435 struct lsa_TransNameArray tnames
;
2437 tnames
.names
= talloc_zero_array(tctx
, struct lsa_TranslatedName
, tnames
.count
);
2438 tnames
.names
[0].name
.string
= info
->dns
.name
.string
;
2439 tnames
.names
[0].sid_type
= SID_NAME_DOMAIN
;
2440 tnames
.names
[1].name
.string
= info
->dns
.dns_domain
.string
;
2441 tnames
.names
[1].sid_type
= SID_NAME_DOMAIN
;
2442 tnames
.names
[2].name
.string
= talloc_asprintf(tctx
, "%s\\", info
->dns
.name
.string
);
2443 tnames
.names
[2].sid_type
= SID_NAME_DOMAIN
;
2444 tnames
.names
[3].name
.string
= talloc_asprintf(tctx
, "%s\\", info
->dns
.dns_domain
.string
);
2445 tnames
.names
[3].sid_type
= SID_NAME_DOMAIN
;
2446 tnames
.names
[4].name
.string
= talloc_asprintf(tctx
, "%s\\guest", info
->dns
.name
.string
);
2447 tnames
.names
[4].sid_type
= SID_NAME_USER
;
2448 tnames
.names
[5].name
.string
= talloc_asprintf(tctx
, "%s\\krbtgt", info
->dns
.name
.string
);
2449 tnames
.names
[5].sid_type
= SID_NAME_USER
;
2450 tnames
.names
[6].name
.string
= talloc_asprintf(tctx
, "%s\\guest", info
->dns
.dns_domain
.string
);
2451 tnames
.names
[6].sid_type
= SID_NAME_USER
;
2452 tnames
.names
[7].name
.string
= talloc_asprintf(tctx
, "%s\\krbtgt", info
->dns
.dns_domain
.string
);
2453 tnames
.names
[7].sid_type
= SID_NAME_USER
;
2454 tnames
.names
[8].name
.string
= talloc_asprintf(tctx
, "krbtgt@%s", info
->dns
.name
.string
);
2455 tnames
.names
[8].sid_type
= SID_NAME_USER
;
2456 tnames
.names
[9].name
.string
= talloc_asprintf(tctx
, "krbtgt@%s", info
->dns
.dns_domain
.string
);
2457 tnames
.names
[9].sid_type
= SID_NAME_USER
;
2458 tnames
.names
[10].name
.string
= talloc_asprintf(tctx
, "%s\\"TEST_MACHINENAME
"$", info
->dns
.name
.string
);
2459 tnames
.names
[10].sid_type
= SID_NAME_USER
;
2460 tnames
.names
[11].name
.string
= talloc_asprintf(tctx
, "%s\\"TEST_MACHINENAME
"$", info
->dns
.dns_domain
.string
);
2461 tnames
.names
[11].sid_type
= SID_NAME_USER
;
2462 tnames
.names
[12].name
.string
= talloc_asprintf(tctx
, TEST_MACHINENAME
"$@%s", info
->dns
.name
.string
);
2463 tnames
.names
[12].sid_type
= SID_NAME_USER
;
2464 tnames
.names
[13].name
.string
= talloc_asprintf(tctx
, TEST_MACHINENAME
"$@%s", info
->dns
.dns_domain
.string
);
2465 tnames
.names
[13].sid_type
= SID_NAME_USER
;
2466 ret
&= test_LookupNames(p
, tctx
, handle
, &tnames
);
2474 static bool test_QueryInfoPolicy(struct dcerpc_pipe
*p
,
2475 struct torture_context
*tctx
,
2476 struct policy_handle
*handle
)
2478 return test_QueryInfoPolicyCalls(false, p
, tctx
, handle
);
2481 static bool test_QueryInfoPolicy2(struct dcerpc_pipe
*p
,
2482 struct torture_context
*tctx
,
2483 struct policy_handle
*handle
)
2485 return test_QueryInfoPolicyCalls(true, p
, tctx
, handle
);
2488 static bool test_GetUserName(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
)
2490 struct lsa_GetUserName r
;
2493 struct lsa_String
*authority_name_p
= NULL
;
2494 struct lsa_String
*account_name_p
= NULL
;
2496 printf("\nTesting GetUserName\n");
2498 r
.in
.system_name
= "\\";
2499 r
.in
.account_name
= &account_name_p
;
2500 r
.in
.authority_name
= NULL
;
2501 r
.out
.account_name
= &account_name_p
;
2503 status
= dcerpc_lsa_GetUserName(p
, mem_ctx
, &r
);
2505 if (!NT_STATUS_IS_OK(status
)) {
2506 printf("GetUserName failed - %s\n", nt_errstr(status
));
2510 account_name_p
= NULL
;
2511 r
.in
.account_name
= &account_name_p
;
2512 r
.in
.authority_name
= &authority_name_p
;
2513 r
.out
.account_name
= &account_name_p
;
2515 status
= dcerpc_lsa_GetUserName(p
, mem_ctx
, &r
);
2517 if (!NT_STATUS_IS_OK(status
)) {
2518 printf("GetUserName failed - %s\n", nt_errstr(status
));
2525 bool test_lsa_Close(struct dcerpc_pipe
*p
,
2526 TALLOC_CTX
*mem_ctx
,
2527 struct policy_handle
*handle
)
2531 struct policy_handle handle2
;
2533 printf("\nTesting Close\n");
2535 r
.in
.handle
= handle
;
2536 r
.out
.handle
= &handle2
;
2538 status
= dcerpc_lsa_Close(p
, mem_ctx
, &r
);
2539 if (!NT_STATUS_IS_OK(status
)) {
2540 printf("Close failed - %s\n", nt_errstr(status
));
2544 status
= dcerpc_lsa_Close(p
, mem_ctx
, &r
);
2545 /* its really a fault - we need a status code for rpc fault */
2546 if (!NT_STATUS_EQUAL(status
, NT_STATUS_NET_WRITE_FAULT
)) {
2547 printf("Close failed - %s\n", nt_errstr(status
));
2556 bool torture_rpc_lsa(struct torture_context
*tctx
)
2559 struct dcerpc_pipe
*p
;
2561 struct policy_handle
*handle
;
2562 struct test_join
*join
= NULL
;
2563 struct cli_credentials
*machine_creds
;
2565 status
= torture_rpc_connection(tctx
, &p
, &ndr_table_lsarpc
);
2566 if (!NT_STATUS_IS_OK(status
)) {
2570 if (!test_OpenPolicy(p
, tctx
)) {
2574 if (!test_lsa_OpenPolicy2(p
, tctx
, &handle
)) {
2579 join
= torture_join_domain(tctx
, TEST_MACHINENAME
, ACB_WSTRUST
, &machine_creds
);
2583 if (!test_LookupNames_wellknown(p
, tctx
, handle
)) {
2587 if (!test_LookupNames_bogus(p
, tctx
, handle
)) {
2591 if (!test_LookupSids_async(p
, tctx
, handle
)) {
2595 if (!test_QueryDomainInfoPolicy(p
, tctx
, handle
)) {
2599 if (!test_CreateAccount(p
, tctx
, handle
)) {
2603 if (!test_CreateSecret(p
, tctx
, handle
)) {
2606 if (!test_CreateTrustedDomain(p
, tctx
, handle
)) {
2610 if (!test_CreateTrustedDomainEx2(p
, tctx
, tctx
, handle
)) {
2614 if (!test_EnumAccounts(p
, tctx
, handle
)) {
2618 if (!test_EnumPrivs(p
, tctx
, handle
)) {
2622 if (!test_QueryInfoPolicy(p
, tctx
, handle
)) {
2626 if (!test_QueryInfoPolicy2(p
, tctx
, handle
)) {
2630 if (!test_Delete(p
, tctx
, handle
)) {
2634 if (!test_many_LookupSids(p
, tctx
, handle
)) {
2638 if (!test_lsa_Close(p
, tctx
, handle
)) {
2642 torture_leave_domain(tctx
, join
);
2645 if (!test_many_LookupSids(p
, tctx
, handle
)) {
2650 if (!test_GetUserName(p
, tctx
)) {
2657 bool torture_rpc_lsa_get_user(struct torture_context
*torture
)
2660 struct dcerpc_pipe
*p
;
2661 TALLOC_CTX
*mem_ctx
;
2664 mem_ctx
= talloc_init("torture_rpc_lsa_get_user");
2666 status
= torture_rpc_connection(torture
, &p
, &ndr_table_lsarpc
);
2667 if (!NT_STATUS_IS_OK(status
)) {
2668 talloc_free(mem_ctx
);
2672 if (!test_GetUserName(p
, mem_ctx
)) {
2676 talloc_free(mem_ctx
);