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;
240 struct lsa_TranslatedName name[2];
241 struct lsa_TransNameArray tnames;
245 name[0].name.string = "NT AUTHORITY\\BOGUS";
246 name[1].name.string = NULL;
248 torture_comment(tctx, "\nTesting LookupNames with bogus names\n");
253 names = talloc_array(tctx, struct lsa_String, tnames.count);
254 for (i=0;i<tnames.count;i++) {
255 init_lsa_String(&names[i], tnames.names[i].name.string);
258 r.in.handle = handle;
259 r.in.num_names = tnames.count;
264 r.out.count = &count;
266 r.out.domains = &domains;
268 status = dcerpc_lsa_LookupNames(p, tctx, &r);
269 if (!NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED)) {
270 torture_comment(tctx, "LookupNames failed - %s\n", nt_errstr(status));
274 torture_comment(tctx, "\n");
279 static bool test_LookupNames_wellknown(struct dcerpc_pipe *p,
280 struct torture_context *tctx,
281 struct policy_handle *handle)
283 struct lsa_TranslatedName name;
284 struct lsa_TransNameArray tnames;
287 torture_comment(tctx, "Testing LookupNames with well known names\n");
289 tnames.names = &name;
291 name.name.string = "NT AUTHORITY\\SYSTEM";
292 name.sid_type = SID_NAME_WKN_GRP;
293 ret &= test_LookupNames(p, tctx, handle, &tnames);
295 name.name.string = "NT AUTHORITY\\ANONYMOUS LOGON";
296 name.sid_type = SID_NAME_WKN_GRP;
297 ret &= test_LookupNames(p, tctx, handle, &tnames);
299 name.name.string = "NT AUTHORITY\\Authenticated Users";
300 name.sid_type = SID_NAME_WKN_GRP;
301 ret &= test_LookupNames(p, tctx, handle, &tnames);
304 name.name.string = "NT AUTHORITY";
305 ret &= test_LookupNames(p, tctx, handle, &tnames);
307 name.name.string = "NT AUTHORITY\\";
308 ret &= test_LookupNames(p, tctx, handle, &tnames);
311 name.name.string = "BUILTIN\\";
312 name.sid_type = SID_NAME_DOMAIN;
313 ret &= test_LookupNames(p, tctx, handle, &tnames);
315 name.name.string = "BUILTIN\\Administrators";
316 name.sid_type = SID_NAME_ALIAS;
317 ret &= test_LookupNames(p, tctx, handle, &tnames);
319 name.name.string = "SYSTEM";
320 name.sid_type = SID_NAME_WKN_GRP;
321 ret &= test_LookupNames(p, tctx, handle, &tnames);
323 name.name.string = "Everyone";
324 name.sid_type = SID_NAME_WKN_GRP;
325 ret &= test_LookupNames(p, tctx, handle, &tnames);
329 static bool test_LookupNames2(struct dcerpc_pipe *p,
330 struct torture_context *tctx,
331 struct policy_handle *handle,
332 struct lsa_TransNameArray2 *tnames,
335 struct lsa_LookupNames2 r;
336 struct lsa_TransSidArray2 sids;
337 struct lsa_RefDomainList *domains = NULL;
338 struct lsa_String *names;
343 torture_comment(tctx, "\nTesting LookupNames2 with %d names\n", tnames->count);
348 names = talloc_array(tctx, struct lsa_String, tnames->count);
349 for (i=0;i<tnames->count;i++) {
350 init_lsa_String(&names[i], tnames->names[i].name.string);
353 r.in.handle = handle;
354 r.in.num_names = tnames->count;
359 r.in.lookup_options = 0;
360 r.in.client_revision = 0;
361 r.out.count = &count;
363 r.out.domains = &domains;
365 status = dcerpc_lsa_LookupNames2(p, tctx, &r);
366 if (!NT_STATUS_IS_OK(status)) {
367 torture_comment(tctx, "LookupNames2 failed - %s\n", nt_errstr(status));
372 torture_assert_int_equal(tctx, count, sids.count,
373 "unexpected number of results returned");
374 if (sids.count > 0) {
375 torture_assert(tctx, sids.sids, "invalid sid buffer");
379 torture_comment(tctx, "\n");
385 static bool test_LookupNames3(struct dcerpc_pipe *p,
386 struct torture_context *tctx,
387 struct policy_handle *handle,
388 struct lsa_TransNameArray2 *tnames,
391 struct lsa_LookupNames3 r;
392 struct lsa_TransSidArray3 sids;
393 struct lsa_RefDomainList *domains = NULL;
394 struct lsa_String *names;
399 torture_comment(tctx, "\nTesting LookupNames3 with %d names\n", tnames->count);
404 names = talloc_array(tctx, struct lsa_String, tnames->count);
405 for (i=0;i<tnames->count;i++) {
406 init_lsa_String(&names[i], tnames->names[i].name.string);
409 r.in.handle = handle;
410 r.in.num_names = tnames->count;
415 r.in.lookup_options = 0;
416 r.in.client_revision = 0;
417 r.out.count = &count;
419 r.out.domains = &domains;
421 status = dcerpc_lsa_LookupNames3(p, tctx, &r);
422 if (!NT_STATUS_IS_OK(status)) {
423 torture_comment(tctx, "LookupNames3 failed - %s\n", nt_errstr(status));
428 torture_assert_int_equal(tctx, count, sids.count,
429 "unexpected number of results returned");
430 if (sids.count > 0) {
431 torture_assert(tctx, sids.sids, "invalid sid buffer");
435 torture_comment(tctx, "\n");
440 static bool test_LookupNames4(struct dcerpc_pipe *p,
441 struct torture_context *tctx,
442 struct lsa_TransNameArray2 *tnames,
445 struct lsa_LookupNames4 r;
446 struct lsa_TransSidArray3 sids;
447 struct lsa_RefDomainList *domains = NULL;
448 struct lsa_String *names;
453 torture_comment(tctx, "\nTesting LookupNames4 with %d names\n", tnames->count);
458 names = talloc_array(tctx, struct lsa_String, tnames->count);
459 for (i=0;i<tnames->count;i++) {
460 init_lsa_String(&names[i], tnames->names[i].name.string);
463 r.in.num_names = tnames->count;
468 r.in.lookup_options = 0;
469 r.in.client_revision = 0;
470 r.out.count = &count;
472 r.out.domains = &domains;
474 status = dcerpc_lsa_LookupNames4(p, tctx, &r);
475 if (!NT_STATUS_IS_OK(status)) {
476 torture_comment(tctx, "LookupNames4 failed - %s\n", nt_errstr(status));
481 torture_assert_int_equal(tctx, count, sids.count,
482 "unexpected number of results returned");
483 if (sids.count > 0) {
484 torture_assert(tctx, sids.sids, "invalid sid buffer");
488 torture_comment(tctx, "\n");
494 static bool test_LookupSids(struct dcerpc_pipe *p,
495 struct torture_context *tctx,
496 struct policy_handle *handle,
497 struct lsa_SidArray *sids)
499 struct lsa_LookupSids r;
500 struct lsa_TransNameArray names;
501 struct lsa_RefDomainList *domains = NULL;
502 uint32_t count = sids->num_sids;
505 torture_comment(tctx, "\nTesting LookupSids\n");
510 r.in.handle = handle;
515 r.out.count = &count;
516 r.out.names = &names;
517 r.out.domains = &domains;
519 status = dcerpc_lsa_LookupSids(p, tctx, &r);
520 if (!NT_STATUS_IS_OK(status)) {
521 torture_comment(tctx, "LookupSids failed - %s\n", nt_errstr(status));
525 torture_comment(tctx, "\n");
527 if (!test_LookupNames(p, tctx, handle, &names)) {
535 static bool test_LookupSids2(struct dcerpc_pipe *p,
536 struct torture_context *tctx,
537 struct policy_handle *handle,
538 struct lsa_SidArray *sids)
540 struct lsa_LookupSids2 r;
541 struct lsa_TransNameArray2 names;
542 struct lsa_RefDomainList *domains = NULL;
543 uint32_t count = sids->num_sids;
546 torture_comment(tctx, "\nTesting LookupSids2\n");
551 r.in.handle = handle;
556 r.in.lookup_options = 0;
557 r.in.client_revision = 0;
558 r.out.count = &count;
559 r.out.names = &names;
560 r.out.domains = &domains;
562 status = dcerpc_lsa_LookupSids2(p, tctx, &r);
563 if (!NT_STATUS_IS_OK(status)) {
564 torture_comment(tctx, "LookupSids2 failed - %s\n", nt_errstr(status));
568 torture_comment(tctx, "\n");
570 if (!test_LookupNames2(p, tctx, handle, &names, false)) {
574 if (!test_LookupNames3(p, tctx, handle, &names, false)) {
581 static bool test_LookupSids3(struct dcerpc_pipe *p,
582 struct torture_context *tctx,
583 struct lsa_SidArray *sids)
585 struct lsa_LookupSids3 r;
586 struct lsa_TransNameArray2 names;
587 struct lsa_RefDomainList *domains = NULL;
588 uint32_t count = sids->num_sids;
591 torture_comment(tctx, "\nTesting LookupSids3\n");
600 r.in.lookup_options = 0;
601 r.in.client_revision = 0;
602 r.out.domains = &domains;
603 r.out.count = &count;
604 r.out.names = &names;
606 status = dcerpc_lsa_LookupSids3(p, tctx, &r);
607 if (!NT_STATUS_IS_OK(status)) {
608 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
609 NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
610 torture_comment(tctx, "not considering %s to be an error\n", nt_errstr(status));
613 torture_comment(tctx, "LookupSids3 failed - %s - not considered an error\n",
618 torture_comment(tctx, "\n");
620 if (!test_LookupNames4(p, tctx, &names, false)) {
627 bool test_many_LookupSids(struct dcerpc_pipe *p,
628 struct torture_context *tctx,
629 struct policy_handle *handle)
633 struct lsa_SidArray sids;
636 torture_comment(tctx, "\nTesting LookupSids with lots of SIDs\n");
640 sids.sids = talloc_array(tctx, struct lsa_SidPtr, sids.num_sids);
642 for (i=0; i<sids.num_sids; i++) {
643 const char *sidstr = "S-1-5-32-545";
644 sids.sids[i].sid = dom_sid_parse_talloc(tctx, sidstr);
647 count = sids.num_sids;
650 struct lsa_LookupSids r;
651 struct lsa_TransNameArray names;
652 struct lsa_RefDomainList *domains = NULL;
656 r.in.handle = handle;
660 r.in.count = &names.count;
661 r.out.count = &count;
662 r.out.names = &names;
663 r.out.domains = &domains;
665 status = dcerpc_lsa_LookupSids(p, tctx, &r);
666 if (!NT_STATUS_IS_OK(status)) {
667 torture_comment(tctx, "LookupSids failed - %s\n", nt_errstr(status));
671 torture_comment(tctx, "\n");
673 if (!test_LookupNames(p, tctx, handle, &names)) {
676 } else if (p->conn->security_state.auth_info->auth_type == DCERPC_AUTH_TYPE_SCHANNEL &&
677 p->conn->security_state.auth_info->auth_level >= DCERPC_AUTH_LEVEL_INTEGRITY) {
678 struct lsa_LookupSids3 r;
679 struct lsa_RefDomainList *domains = NULL;
680 struct lsa_TransNameArray2 names;
685 torture_comment(tctx, "\nTesting LookupSids3\n");
691 r.in.lookup_options = 0;
692 r.in.client_revision = 0;
693 r.out.count = &count;
694 r.out.names = &names;
695 r.out.domains = &domains;
697 status = dcerpc_lsa_LookupSids3(p, tctx, &r);
698 if (!NT_STATUS_IS_OK(status)) {
699 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
700 NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
701 torture_comment(tctx, "not considering %s to be an error\n", nt_errstr(status));
704 torture_comment(tctx, "LookupSids3 failed - %s\n",
708 if (!test_LookupNames4(p, tctx, &names, false)) {
713 torture_comment(tctx, "\n");
720 static void lookupsids_cb(struct rpc_request *req)
722 int *replies = (int *)req->async.private_data;
725 status = dcerpc_ndr_request_recv(req);
726 if (!NT_STATUS_IS_OK(status)) {
727 printf("lookupsids returned %s\n", nt_errstr(status));
736 static bool test_LookupSids_async(struct dcerpc_pipe *p,
737 struct torture_context *tctx,
738 struct policy_handle *handle)
740 struct lsa_SidArray sids;
741 struct lsa_SidPtr sidptr;
743 struct lsa_TransNameArray *names;
744 struct lsa_LookupSids *r;
745 struct lsa_RefDomainList *domains = NULL;
746 struct rpc_request **req;
749 const int num_async_requests = 50;
751 count = talloc_array(tctx, uint32_t, num_async_requests);
752 names = talloc_array(tctx, struct lsa_TransNameArray, num_async_requests);
753 r = talloc_array(tctx, struct lsa_LookupSids, num_async_requests);
755 torture_comment(tctx, "\nTesting %d async lookupsids request\n", num_async_requests);
757 req = talloc_array(tctx, struct rpc_request *, num_async_requests);
761 sidptr.sid = dom_sid_parse_talloc(tctx, "S-1-5-32-545");
765 for (i=0; i<num_async_requests; i++) {
768 names[i].names = NULL;
770 r[i].in.handle = handle;
771 r[i].in.sids = &sids;
772 r[i].in.names = &names[i];
774 r[i].in.count = &names[i].count;
775 r[i].out.count = &count[i];
776 r[i].out.names = &names[i];
777 r[i].out.domains = &domains;
779 req[i] = dcerpc_lsa_LookupSids_send(p, req, &r[i]);
780 if (req[i] == NULL) {
785 req[i]->async.callback = lookupsids_cb;
786 req[i]->async.private_data = &replies;
789 while (replies >= 0 && replies < num_async_requests) {
790 event_loop_once(p->conn->event_ctx);
802 static bool test_LookupPrivValue(struct dcerpc_pipe *p,
803 struct torture_context *tctx,
804 struct policy_handle *handle,
805 struct lsa_String *name)
808 struct lsa_LookupPrivValue r;
809 struct lsa_LUID luid;
811 r.in.handle = handle;
815 status = dcerpc_lsa_LookupPrivValue(p, tctx, &r);
816 if (!NT_STATUS_IS_OK(status)) {
817 torture_comment(tctx, "\nLookupPrivValue failed - %s\n", nt_errstr(status));
824 static bool test_LookupPrivName(struct dcerpc_pipe *p,
825 struct torture_context *tctx,
826 struct policy_handle *handle,
827 struct lsa_LUID *luid)
830 struct lsa_LookupPrivName r;
831 struct lsa_StringLarge *name = NULL;
833 r.in.handle = handle;
837 status = dcerpc_lsa_LookupPrivName(p, tctx, &r);
838 if (!NT_STATUS_IS_OK(status)) {
839 torture_comment(tctx, "\nLookupPrivName failed - %s\n", nt_errstr(status));
846 static bool test_RemovePrivilegesFromAccount(struct dcerpc_pipe *p,
847 struct torture_context *tctx,
848 struct policy_handle *handle,
849 struct policy_handle *acct_handle,
850 struct lsa_LUID *luid)
853 struct lsa_RemovePrivilegesFromAccount r;
854 struct lsa_PrivilegeSet privs;
857 torture_comment(tctx, "\nTesting RemovePrivilegesFromAccount\n");
859 r.in.handle = acct_handle;
865 privs.set = talloc_array(tctx, struct lsa_LUIDAttribute, 1);
866 privs.set[0].luid = *luid;
867 privs.set[0].attribute = 0;
869 status = dcerpc_lsa_RemovePrivilegesFromAccount(p, tctx, &r);
870 if (!NT_STATUS_IS_OK(status)) {
872 struct lsa_LookupPrivName r_name;
873 struct lsa_StringLarge *name = NULL;
875 r_name.in.handle = handle;
876 r_name.in.luid = luid;
877 r_name.out.name = &name;
879 status = dcerpc_lsa_LookupPrivName(p, tctx, &r_name);
880 if (!NT_STATUS_IS_OK(status)) {
881 torture_comment(tctx, "\nLookupPrivName failed - %s\n", nt_errstr(status));
884 /* Windows 2008 does not allow this to be removed */
885 if (strcmp("SeAuditPrivilege", name->string) == 0) {
889 torture_comment(tctx, "RemovePrivilegesFromAccount failed to remove %s - %s\n",
898 static bool test_AddPrivilegesToAccount(struct dcerpc_pipe *p,
899 struct torture_context *tctx,
900 struct policy_handle *acct_handle,
901 struct lsa_LUID *luid)
904 struct lsa_AddPrivilegesToAccount r;
905 struct lsa_PrivilegeSet privs;
908 torture_comment(tctx, "\nTesting AddPrivilegesToAccount\n");
910 r.in.handle = acct_handle;
915 privs.set = talloc_array(tctx, struct lsa_LUIDAttribute, 1);
916 privs.set[0].luid = *luid;
917 privs.set[0].attribute = 0;
919 status = dcerpc_lsa_AddPrivilegesToAccount(p, tctx, &r);
920 if (!NT_STATUS_IS_OK(status)) {
921 torture_comment(tctx, "AddPrivilegesToAccount failed - %s\n", nt_errstr(status));
928 static bool test_EnumPrivsAccount(struct dcerpc_pipe *p,
929 struct torture_context *tctx,
930 struct policy_handle *handle,
931 struct policy_handle *acct_handle)
934 struct lsa_EnumPrivsAccount r;
935 struct lsa_PrivilegeSet *privs = NULL;
938 torture_comment(tctx, "\nTesting EnumPrivsAccount\n");
940 r.in.handle = acct_handle;
941 r.out.privs = &privs;
943 status = dcerpc_lsa_EnumPrivsAccount(p, tctx, &r);
944 if (!NT_STATUS_IS_OK(status)) {
945 torture_comment(tctx, "EnumPrivsAccount failed - %s\n", nt_errstr(status));
949 if (privs && privs->count > 0) {
951 for (i=0;i<privs->count;i++) {
952 test_LookupPrivName(p, tctx, handle,
953 &privs->set[i].luid);
956 ret &= test_RemovePrivilegesFromAccount(p, tctx, handle, acct_handle,
957 &privs->set[0].luid);
958 ret &= test_AddPrivilegesToAccount(p, tctx, acct_handle,
959 &privs->set[0].luid);
965 static bool test_GetSystemAccessAccount(struct dcerpc_pipe *p,
966 struct torture_context *tctx,
967 struct policy_handle *handle,
968 struct policy_handle *acct_handle)
971 uint32_t access_mask;
972 struct lsa_GetSystemAccessAccount r;
974 torture_comment(tctx, "\nTesting GetSystemAccessAccount\n");
976 r.in.handle = acct_handle;
977 r.out.access_mask = &access_mask;
979 status = dcerpc_lsa_GetSystemAccessAccount(p, tctx, &r);
980 if (!NT_STATUS_IS_OK(status)) {
981 torture_comment(tctx, "GetSystemAccessAccount failed - %s\n", nt_errstr(status));
985 if (r.out.access_mask != NULL) {
986 torture_comment(tctx, "Rights:");
987 if (*(r.out.access_mask) & LSA_POLICY_MODE_INTERACTIVE)
988 torture_comment(tctx, " LSA_POLICY_MODE_INTERACTIVE");
989 if (*(r.out.access_mask) & LSA_POLICY_MODE_NETWORK)
990 torture_comment(tctx, " LSA_POLICY_MODE_NETWORK");
991 if (*(r.out.access_mask) & LSA_POLICY_MODE_BATCH)
992 torture_comment(tctx, " LSA_POLICY_MODE_BATCH");
993 if (*(r.out.access_mask) & LSA_POLICY_MODE_SERVICE)
994 torture_comment(tctx, " LSA_POLICY_MODE_SERVICE");
995 if (*(r.out.access_mask) & LSA_POLICY_MODE_PROXY)
996 torture_comment(tctx, " LSA_POLICY_MODE_PROXY");
997 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_INTERACTIVE)
998 torture_comment(tctx, " LSA_POLICY_MODE_DENY_INTERACTIVE");
999 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_NETWORK)
1000 torture_comment(tctx, " LSA_POLICY_MODE_DENY_NETWORK");
1001 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_BATCH)
1002 torture_comment(tctx, " LSA_POLICY_MODE_DENY_BATCH");
1003 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_SERVICE)
1004 torture_comment(tctx, " LSA_POLICY_MODE_DENY_SERVICE");
1005 if (*(r.out.access_mask) & LSA_POLICY_MODE_REMOTE_INTERACTIVE)
1006 torture_comment(tctx, " LSA_POLICY_MODE_REMOTE_INTERACTIVE");
1007 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_REMOTE_INTERACTIVE)
1008 torture_comment(tctx, " LSA_POLICY_MODE_DENY_REMOTE_INTERACTIVE");
1009 if (*(r.out.access_mask) & LSA_POLICY_MODE_ALL)
1010 torture_comment(tctx, " LSA_POLICY_MODE_ALL");
1011 if (*(r.out.access_mask) & LSA_POLICY_MODE_ALL_NT4)
1012 torture_comment(tctx, " LSA_POLICY_MODE_ALL_NT4");
1013 torture_comment(tctx, "\n");
1019 static bool test_Delete(struct dcerpc_pipe *p,
1020 struct torture_context *tctx,
1021 struct policy_handle *handle)
1024 struct lsa_Delete r;
1026 torture_comment(tctx, "\nTesting Delete\n");
1028 r.in.handle = handle;
1029 status = dcerpc_lsa_Delete(p, tctx, &r);
1030 if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
1031 torture_comment(tctx, "Delete should have failed NT_STATUS_NOT_SUPPORTED - %s\n", nt_errstr(status));
1038 static bool test_DeleteObject(struct dcerpc_pipe *p,
1039 struct torture_context *tctx,
1040 struct policy_handle *handle)
1043 struct lsa_DeleteObject r;
1045 torture_comment(tctx, "\nTesting DeleteObject\n");
1047 r.in.handle = handle;
1048 r.out.handle = handle;
1049 status = dcerpc_lsa_DeleteObject(p, tctx, &r);
1050 if (!NT_STATUS_IS_OK(status)) {
1051 torture_comment(tctx, "DeleteObject failed - %s\n", nt_errstr(status));
1059 static bool test_CreateAccount(struct dcerpc_pipe *p,
1060 struct torture_context *tctx,
1061 struct policy_handle *handle)
1064 struct lsa_CreateAccount r;
1065 struct dom_sid2 *newsid;
1066 struct policy_handle acct_handle;
1068 newsid = dom_sid_parse_talloc(tctx, "S-1-5-12349876-4321-2854");
1070 torture_comment(tctx, "\nTesting CreateAccount\n");
1072 r.in.handle = handle;
1074 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1075 r.out.acct_handle = &acct_handle;
1077 status = dcerpc_lsa_CreateAccount(p, tctx, &r);
1078 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
1079 struct lsa_OpenAccount r_o;
1080 r_o.in.handle = handle;
1081 r_o.in.sid = newsid;
1082 r_o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1083 r_o.out.acct_handle = &acct_handle;
1085 status = dcerpc_lsa_OpenAccount(p, tctx, &r_o);
1086 if (!NT_STATUS_IS_OK(status)) {
1087 torture_comment(tctx, "OpenAccount failed - %s\n", nt_errstr(status));
1090 } else if (!NT_STATUS_IS_OK(status)) {
1091 torture_comment(tctx, "CreateAccount failed - %s\n", nt_errstr(status));
1095 if (!test_Delete(p, tctx, &acct_handle)) {
1099 if (!test_DeleteObject(p, tctx, &acct_handle)) {
1106 static bool test_DeleteTrustedDomain(struct dcerpc_pipe *p,
1107 struct torture_context *tctx,
1108 struct policy_handle *handle,
1109 struct lsa_StringLarge name)
1112 struct lsa_OpenTrustedDomainByName r;
1113 struct policy_handle trustdom_handle;
1115 r.in.handle = handle;
1116 r.in.name.string = name.string;
1117 r.in.access_mask = SEC_STD_DELETE;
1118 r.out.trustdom_handle = &trustdom_handle;
1120 status = dcerpc_lsa_OpenTrustedDomainByName(p, tctx, &r);
1121 if (!NT_STATUS_IS_OK(status)) {
1122 torture_comment(tctx, "OpenTrustedDomainByName failed - %s\n", nt_errstr(status));
1126 if (!test_Delete(p, tctx, &trustdom_handle)) {
1130 if (!test_DeleteObject(p, tctx, &trustdom_handle)) {
1137 static bool test_DeleteTrustedDomainBySid(struct dcerpc_pipe *p,
1138 struct torture_context *tctx,
1139 struct policy_handle *handle,
1140 struct dom_sid *sid)
1143 struct lsa_DeleteTrustedDomain r;
1145 r.in.handle = handle;
1148 status = dcerpc_lsa_DeleteTrustedDomain(p, tctx, &r);
1149 if (!NT_STATUS_IS_OK(status)) {
1150 torture_comment(tctx, "DeleteTrustedDomain failed - %s\n", nt_errstr(status));
1158 static bool test_CreateSecret(struct dcerpc_pipe *p,
1159 struct torture_context *tctx,
1160 struct policy_handle *handle)
1163 struct lsa_CreateSecret r;
1164 struct lsa_OpenSecret r2;
1165 struct lsa_SetSecret r3;
1166 struct lsa_QuerySecret r4;
1167 struct lsa_SetSecret r5;
1168 struct lsa_QuerySecret r6;
1169 struct lsa_SetSecret r7;
1170 struct lsa_QuerySecret r8;
1171 struct policy_handle sec_handle, sec_handle2, sec_handle3;
1172 struct lsa_DeleteObject d_o;
1173 struct lsa_DATA_BUF buf1;
1174 struct lsa_DATA_BUF_PTR bufp1;
1175 struct lsa_DATA_BUF_PTR bufp2;
1178 DATA_BLOB session_key;
1179 NTTIME old_mtime, new_mtime;
1180 DATA_BLOB blob1, blob2;
1181 const char *secret1 = "abcdef12345699qwerty";
1183 const char *secret3 = "ABCDEF12345699QWERTY";
1185 const char *secret5 = "NEW-SAMBA4-SECRET";
1189 const int LOCAL = 0;
1190 const int GLOBAL = 1;
1192 secname[LOCAL] = talloc_asprintf(tctx, "torturesecret-%u", (uint_t)random());
1193 secname[GLOBAL] = talloc_asprintf(tctx, "G$torturesecret-%u", (uint_t)random());
1195 for (i=0; i< 2; i++) {
1196 torture_comment(tctx, "\nTesting CreateSecret of %s\n", secname[i]);
1198 init_lsa_String(&r.in.name, secname[i]);
1200 r.in.handle = handle;
1201 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1202 r.out.sec_handle = &sec_handle;
1204 status = dcerpc_lsa_CreateSecret(p, tctx, &r);
1205 if (!NT_STATUS_IS_OK(status)) {
1206 torture_comment(tctx, "CreateSecret failed - %s\n", nt_errstr(status));
1210 r.in.handle = handle;
1211 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1212 r.out.sec_handle = &sec_handle3;
1214 status = dcerpc_lsa_CreateSecret(p, tctx, &r);
1215 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
1216 torture_comment(tctx, "CreateSecret should have failed OBJECT_NAME_COLLISION - %s\n", nt_errstr(status));
1220 r2.in.handle = handle;
1221 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1222 r2.in.name = r.in.name;
1223 r2.out.sec_handle = &sec_handle2;
1225 torture_comment(tctx, "Testing OpenSecret\n");
1227 status = dcerpc_lsa_OpenSecret(p, tctx, &r2);
1228 if (!NT_STATUS_IS_OK(status)) {
1229 torture_comment(tctx, "OpenSecret failed - %s\n", nt_errstr(status));
1233 status = dcerpc_fetch_session_key(p, &session_key);
1234 if (!NT_STATUS_IS_OK(status)) {
1235 torture_comment(tctx, "dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
1239 enc_key = sess_encrypt_string(secret1, &session_key);
1241 r3.in.sec_handle = &sec_handle;
1242 r3.in.new_val = &buf1;
1243 r3.in.old_val = NULL;
1244 r3.in.new_val->data = enc_key.data;
1245 r3.in.new_val->length = enc_key.length;
1246 r3.in.new_val->size = enc_key.length;
1248 torture_comment(tctx, "Testing SetSecret\n");
1250 status = dcerpc_lsa_SetSecret(p, tctx, &r3);
1251 if (!NT_STATUS_IS_OK(status)) {
1252 torture_comment(tctx, "SetSecret failed - %s\n", nt_errstr(status));
1256 r3.in.sec_handle = &sec_handle;
1257 r3.in.new_val = &buf1;
1258 r3.in.old_val = NULL;
1259 r3.in.new_val->data = enc_key.data;
1260 r3.in.new_val->length = enc_key.length;
1261 r3.in.new_val->size = enc_key.length;
1263 /* break the encrypted data */
1266 torture_comment(tctx, "Testing SetSecret with broken key\n");
1268 status = dcerpc_lsa_SetSecret(p, tctx, &r3);
1269 if (!NT_STATUS_EQUAL(status, NT_STATUS_UNKNOWN_REVISION)) {
1270 torture_comment(tctx, "SetSecret should have failed UNKNOWN_REVISION - %s\n", nt_errstr(status));
1274 data_blob_free(&enc_key);
1276 ZERO_STRUCT(new_mtime);
1277 ZERO_STRUCT(old_mtime);
1279 /* fetch the secret back again */
1280 r4.in.sec_handle = &sec_handle;
1281 r4.in.new_val = &bufp1;
1282 r4.in.new_mtime = &new_mtime;
1283 r4.in.old_val = NULL;
1284 r4.in.old_mtime = NULL;
1288 torture_comment(tctx, "Testing QuerySecret\n");
1289 status = dcerpc_lsa_QuerySecret(p, tctx, &r4);
1290 if (!NT_STATUS_IS_OK(status)) {
1291 torture_comment(tctx, "QuerySecret failed - %s\n", nt_errstr(status));
1294 if (r4.out.new_val == NULL || r4.out.new_val->buf == NULL) {
1295 torture_comment(tctx, "No secret buffer returned\n");
1298 blob1.data = r4.out.new_val->buf->data;
1299 blob1.length = r4.out.new_val->buf->size;
1301 blob2 = data_blob_talloc(tctx, NULL, blob1.length);
1303 secret2 = sess_decrypt_string(tctx,
1304 &blob1, &session_key);
1306 if (strcmp(secret1, secret2) != 0) {
1307 torture_comment(tctx, "Returned secret (r4) '%s' doesn't match '%s'\n",
1314 enc_key = sess_encrypt_string(secret3, &session_key);
1316 r5.in.sec_handle = &sec_handle;
1317 r5.in.new_val = &buf1;
1318 r5.in.old_val = NULL;
1319 r5.in.new_val->data = enc_key.data;
1320 r5.in.new_val->length = enc_key.length;
1321 r5.in.new_val->size = enc_key.length;
1325 torture_comment(tctx, "Testing SetSecret (existing value should move to old)\n");
1327 status = dcerpc_lsa_SetSecret(p, tctx, &r5);
1328 if (!NT_STATUS_IS_OK(status)) {
1329 torture_comment(tctx, "SetSecret failed - %s\n", nt_errstr(status));
1333 data_blob_free(&enc_key);
1335 ZERO_STRUCT(new_mtime);
1336 ZERO_STRUCT(old_mtime);
1338 /* fetch the secret back again */
1339 r6.in.sec_handle = &sec_handle;
1340 r6.in.new_val = &bufp1;
1341 r6.in.new_mtime = &new_mtime;
1342 r6.in.old_val = &bufp2;
1343 r6.in.old_mtime = &old_mtime;
1348 status = dcerpc_lsa_QuerySecret(p, tctx, &r6);
1349 if (!NT_STATUS_IS_OK(status)) {
1350 torture_comment(tctx, "QuerySecret failed - %s\n", nt_errstr(status));
1355 if (r6.out.new_val->buf == NULL || r6.out.old_val->buf == NULL
1356 || r6.out.new_mtime == NULL || r6.out.old_mtime == NULL) {
1357 torture_comment(tctx, "Both secret buffers and both times not returned\n");
1361 blob1.data = r6.out.new_val->buf->data;
1362 blob1.length = r6.out.new_val->buf->size;
1364 blob2 = data_blob_talloc(tctx, NULL, blob1.length);
1366 secret4 = sess_decrypt_string(tctx,
1367 &blob1, &session_key);
1369 if (strcmp(secret3, secret4) != 0) {
1370 torture_comment(tctx, "Returned NEW secret %s doesn't match %s\n", secret4, secret3);
1374 blob1.data = r6.out.old_val->buf->data;
1375 blob1.length = r6.out.old_val->buf->length;
1377 blob2 = data_blob_talloc(tctx, NULL, blob1.length);
1379 secret2 = sess_decrypt_string(tctx,
1380 &blob1, &session_key);
1382 if (strcmp(secret1, secret2) != 0) {
1383 torture_comment(tctx, "Returned OLD secret %s doesn't match %s\n", secret2, secret1);
1387 if (*r6.out.new_mtime == *r6.out.old_mtime) {
1388 torture_comment(tctx, "Returned secret (r6-%d) %s must not have same mtime for both secrets: %s != %s\n",
1391 nt_time_string(tctx, *r6.out.old_mtime),
1392 nt_time_string(tctx, *r6.out.new_mtime));
1398 enc_key = sess_encrypt_string(secret5, &session_key);
1400 r7.in.sec_handle = &sec_handle;
1401 r7.in.old_val = &buf1;
1402 r7.in.old_val->data = enc_key.data;
1403 r7.in.old_val->length = enc_key.length;
1404 r7.in.old_val->size = enc_key.length;
1405 r7.in.new_val = NULL;
1407 torture_comment(tctx, "Testing SetSecret of old Secret only\n");
1409 status = dcerpc_lsa_SetSecret(p, tctx, &r7);
1410 if (!NT_STATUS_IS_OK(status)) {
1411 torture_comment(tctx, "SetSecret failed - %s\n", nt_errstr(status));
1415 data_blob_free(&enc_key);
1417 /* fetch the secret back again */
1418 r8.in.sec_handle = &sec_handle;
1419 r8.in.new_val = &bufp1;
1420 r8.in.new_mtime = &new_mtime;
1421 r8.in.old_val = &bufp2;
1422 r8.in.old_mtime = &old_mtime;
1427 status = dcerpc_lsa_QuerySecret(p, tctx, &r8);
1428 if (!NT_STATUS_IS_OK(status)) {
1429 torture_comment(tctx, "QuerySecret failed - %s\n", nt_errstr(status));
1432 if (!r8.out.new_val || !r8.out.old_val) {
1433 torture_comment(tctx, "in/out pointers not returned, despite being set on in for QuerySecret\n");
1435 } else if (r8.out.new_val->buf != NULL) {
1436 torture_comment(tctx, "NEW secret buffer must not be returned after OLD set\n");
1438 } else if (r8.out.old_val->buf == NULL) {
1439 torture_comment(tctx, "OLD secret buffer was not returned after OLD set\n");
1441 } else if (r8.out.new_mtime == NULL || r8.out.old_mtime == NULL) {
1442 torture_comment(tctx, "Both times not returned after OLD set\n");
1445 blob1.data = r8.out.old_val->buf->data;
1446 blob1.length = r8.out.old_val->buf->size;
1448 blob2 = data_blob_talloc(tctx, NULL, blob1.length);
1450 secret6 = sess_decrypt_string(tctx,
1451 &blob1, &session_key);
1453 if (strcmp(secret5, secret6) != 0) {
1454 torture_comment(tctx, "Returned OLD secret %s doesn't match %s\n", secret5, secret6);
1458 if (*r8.out.new_mtime != *r8.out.old_mtime) {
1459 torture_comment(tctx, "Returned secret (r8) %s did not had same mtime for both secrets: %s != %s\n",
1461 nt_time_string(tctx, *r8.out.old_mtime),
1462 nt_time_string(tctx, *r8.out.new_mtime));
1468 if (!test_Delete(p, tctx, &sec_handle)) {
1472 if (!test_DeleteObject(p, tctx, &sec_handle)) {
1476 d_o.in.handle = &sec_handle2;
1477 d_o.out.handle = &sec_handle2;
1478 status = dcerpc_lsa_DeleteObject(p, tctx, &d_o);
1479 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1480 torture_comment(tctx, "Second delete expected INVALID_HANDLE - %s\n", nt_errstr(status));
1484 torture_comment(tctx, "Testing OpenSecret of just-deleted secret\n");
1486 status = dcerpc_lsa_OpenSecret(p, tctx, &r2);
1487 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
1488 torture_comment(tctx, "OpenSecret expected OBJECT_NAME_NOT_FOUND - %s\n", nt_errstr(status));
1499 static bool test_EnumAccountRights(struct dcerpc_pipe *p,
1500 struct torture_context *tctx,
1501 struct policy_handle *acct_handle,
1502 struct dom_sid *sid)
1505 struct lsa_EnumAccountRights r;
1506 struct lsa_RightSet rights;
1508 torture_comment(tctx, "\nTesting EnumAccountRights\n");
1510 r.in.handle = acct_handle;
1512 r.out.rights = &rights;
1514 status = dcerpc_lsa_EnumAccountRights(p, tctx, &r);
1515 if (!NT_STATUS_IS_OK(status)) {
1516 torture_comment(tctx, "EnumAccountRights of %s failed - %s\n",
1517 dom_sid_string(tctx, sid), nt_errstr(status));
1525 static bool test_QuerySecurity(struct dcerpc_pipe *p,
1526 struct torture_context *tctx,
1527 struct policy_handle *handle,
1528 struct policy_handle *acct_handle)
1531 struct lsa_QuerySecurity r;
1532 struct sec_desc_buf *sdbuf = NULL;
1534 if (torture_setting_bool(tctx, "samba4", false)) {
1535 torture_comment(tctx, "\nskipping QuerySecurity test against Samba4\n");
1539 torture_comment(tctx, "\nTesting QuerySecurity\n");
1541 r.in.handle = acct_handle;
1542 r.in.sec_info = SECINFO_OWNER |
1545 r.out.sdbuf = &sdbuf;
1547 status = dcerpc_lsa_QuerySecurity(p, tctx, &r);
1548 if (!NT_STATUS_IS_OK(status)) {
1549 torture_comment(tctx, "QuerySecurity failed - %s\n", nt_errstr(status));
1556 static bool test_OpenAccount(struct dcerpc_pipe *p,
1557 struct torture_context *tctx,
1558 struct policy_handle *handle,
1559 struct dom_sid *sid)
1562 struct lsa_OpenAccount r;
1563 struct policy_handle acct_handle;
1565 torture_comment(tctx, "\nTesting OpenAccount\n");
1567 r.in.handle = handle;
1569 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1570 r.out.acct_handle = &acct_handle;
1572 status = dcerpc_lsa_OpenAccount(p, tctx, &r);
1573 if (!NT_STATUS_IS_OK(status)) {
1574 torture_comment(tctx, "OpenAccount failed - %s\n", nt_errstr(status));
1578 if (!test_EnumPrivsAccount(p, tctx, handle, &acct_handle)) {
1582 if (!test_GetSystemAccessAccount(p, tctx, handle, &acct_handle)) {
1586 if (!test_QuerySecurity(p, tctx, handle, &acct_handle)) {
1593 static bool test_EnumAccounts(struct dcerpc_pipe *p,
1594 struct torture_context *tctx,
1595 struct policy_handle *handle)
1598 struct lsa_EnumAccounts r;
1599 struct lsa_SidArray sids1, sids2;
1600 uint32_t resume_handle = 0;
1604 torture_comment(tctx, "\nTesting EnumAccounts\n");
1606 r.in.handle = handle;
1607 r.in.resume_handle = &resume_handle;
1608 r.in.num_entries = 100;
1609 r.out.resume_handle = &resume_handle;
1610 r.out.sids = &sids1;
1614 status = dcerpc_lsa_EnumAccounts(p, tctx, &r);
1615 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
1618 if (!NT_STATUS_IS_OK(status)) {
1619 torture_comment(tctx, "EnumAccounts failed - %s\n", nt_errstr(status));
1623 if (!test_LookupSids(p, tctx, handle, &sids1)) {
1627 if (!test_LookupSids2(p, tctx, handle, &sids1)) {
1631 /* Can't test lookupSids3 here, as clearly we must not
1632 * be on schannel, or we would not be able to do the
1635 torture_comment(tctx, "Testing all accounts\n");
1636 for (i=0;i<sids1.num_sids;i++) {
1637 ret &= test_OpenAccount(p, tctx, handle, sids1.sids[i].sid);
1638 ret &= test_EnumAccountRights(p, tctx, handle, sids1.sids[i].sid);
1640 torture_comment(tctx, "\n");
1643 if (sids1.num_sids < 3) {
1647 torture_comment(tctx, "Trying EnumAccounts partial listing (asking for 1 at 2)\n");
1649 r.in.num_entries = 1;
1650 r.out.sids = &sids2;
1652 status = dcerpc_lsa_EnumAccounts(p, tctx, &r);
1653 if (!NT_STATUS_IS_OK(status)) {
1654 torture_comment(tctx, "EnumAccounts failed - %s\n", nt_errstr(status));
1658 if (sids2.num_sids != 1) {
1659 torture_comment(tctx, "Returned wrong number of entries (%d)\n", sids2.num_sids);
1666 static bool test_LookupPrivDisplayName(struct dcerpc_pipe *p,
1667 struct torture_context *tctx,
1668 struct policy_handle *handle,
1669 struct lsa_String *priv_name)
1671 struct lsa_LookupPrivDisplayName r;
1673 /* produce a reasonable range of language output without screwing up
1675 uint16_t language_id = (random() % 4) + 0x409;
1676 uint16_t returned_language_id = 0;
1677 struct lsa_StringLarge *disp_name = NULL;
1679 torture_comment(tctx, "\nTesting LookupPrivDisplayName(%s)\n", priv_name->string);
1681 r.in.handle = handle;
1682 r.in.name = priv_name;
1683 r.in.language_id = language_id;
1684 r.in.language_id_sys = 0;
1685 r.out.returned_language_id = &returned_language_id;
1686 r.out.disp_name = &disp_name;
1688 status = dcerpc_lsa_LookupPrivDisplayName(p, tctx, &r);
1689 if (!NT_STATUS_IS_OK(status)) {
1690 torture_comment(tctx, "LookupPrivDisplayName failed - %s\n", nt_errstr(status));
1693 torture_comment(tctx, "%s -> \"%s\" (language 0x%x/0x%x)\n",
1694 priv_name->string, disp_name->string,
1695 r.in.language_id, *r.out.returned_language_id);
1700 static bool test_EnumAccountsWithUserRight(struct dcerpc_pipe *p,
1701 struct torture_context *tctx,
1702 struct policy_handle *handle,
1703 struct lsa_String *priv_name)
1705 struct lsa_EnumAccountsWithUserRight r;
1706 struct lsa_SidArray sids;
1711 torture_comment(tctx, "\nTesting EnumAccountsWithUserRight(%s)\n", priv_name->string);
1713 r.in.handle = handle;
1714 r.in.name = priv_name;
1717 status = dcerpc_lsa_EnumAccountsWithUserRight(p, tctx, &r);
1719 /* NT_STATUS_NO_MORE_ENTRIES means noone has this privilege */
1720 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
1724 if (!NT_STATUS_IS_OK(status)) {
1725 torture_comment(tctx, "EnumAccountsWithUserRight failed - %s\n", nt_errstr(status));
1733 static bool test_EnumPrivs(struct dcerpc_pipe *p,
1734 struct torture_context *tctx,
1735 struct policy_handle *handle)
1738 struct lsa_EnumPrivs r;
1739 struct lsa_PrivArray privs1;
1740 uint32_t resume_handle = 0;
1744 torture_comment(tctx, "\nTesting EnumPrivs\n");
1746 r.in.handle = handle;
1747 r.in.resume_handle = &resume_handle;
1748 r.in.max_count = 100;
1749 r.out.resume_handle = &resume_handle;
1750 r.out.privs = &privs1;
1753 status = dcerpc_lsa_EnumPrivs(p, tctx, &r);
1754 if (!NT_STATUS_IS_OK(status)) {
1755 torture_comment(tctx, "EnumPrivs failed - %s\n", nt_errstr(status));
1759 for (i = 0; i< privs1.count; i++) {
1760 test_LookupPrivDisplayName(p, tctx, handle, (struct lsa_String *)&privs1.privs[i].name);
1761 test_LookupPrivValue(p, tctx, handle, (struct lsa_String *)&privs1.privs[i].name);
1762 if (!test_EnumAccountsWithUserRight(p, tctx, handle, (struct lsa_String *)&privs1.privs[i].name)) {
1770 static bool test_QueryForestTrustInformation(struct dcerpc_pipe *p,
1771 struct torture_context *tctx,
1772 struct policy_handle *handle,
1773 const char *trusted_domain_name)
1776 struct lsa_lsaRQueryForestTrustInformation r;
1778 struct lsa_String string;
1779 struct lsa_ForestTrustInformation info, *info_ptr;
1781 torture_comment(tctx, "\nTesting lsaRQueryForestTrustInformation\n");
1783 if (torture_setting_bool(tctx, "samba4", false)) {
1784 torture_comment(tctx, "skipping QueryForestTrustInformation against Samba4\n");
1788 ZERO_STRUCT(string);
1790 if (trusted_domain_name) {
1791 init_lsa_String(&string, trusted_domain_name);
1796 r.in.handle = handle;
1797 r.in.trusted_domain_name = &string;
1799 r.out.forest_trust_info = &info_ptr;
1801 status = dcerpc_lsa_lsaRQueryForestTrustInformation(p, tctx, &r);
1803 if (!NT_STATUS_IS_OK(status)) {
1804 torture_comment(tctx, "lsaRQueryForestTrustInformation of %s failed - %s\n", trusted_domain_name, nt_errstr(status));
1811 static bool test_query_each_TrustDomEx(struct dcerpc_pipe *p,
1812 struct torture_context *tctx,
1813 struct policy_handle *handle,
1814 struct lsa_DomainListEx *domains)
1819 for (i=0; i< domains->count; i++) {
1821 if (domains->domains[i].trust_attributes & NETR_TRUST_ATTRIBUTE_FOREST_TRANSITIVE) {
1822 ret &= test_QueryForestTrustInformation(p, tctx, handle,
1823 domains->domains[i].domain_name.string);
1830 static bool test_query_each_TrustDom(struct dcerpc_pipe *p,
1831 struct torture_context *tctx,
1832 struct policy_handle *handle,
1833 struct lsa_DomainList *domains)
1839 torture_comment(tctx, "\nTesting OpenTrustedDomain, OpenTrustedDomainByName and QueryInfoTrustedDomain\n");
1840 for (i=0; i< domains->count; i++) {
1841 struct lsa_OpenTrustedDomain trust;
1842 struct lsa_OpenTrustedDomainByName trust_by_name;
1843 struct policy_handle trustdom_handle;
1844 struct policy_handle handle2;
1846 struct lsa_CloseTrustedDomainEx c_trust;
1847 int levels [] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
1848 int ok[] = {1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1};
1850 if (domains->domains[i].sid) {
1851 trust.in.handle = handle;
1852 trust.in.sid = domains->domains[i].sid;
1853 trust.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1854 trust.out.trustdom_handle = &trustdom_handle;
1856 status = dcerpc_lsa_OpenTrustedDomain(p, tctx, &trust);
1858 if (!NT_STATUS_IS_OK(status)) {
1859 torture_comment(tctx, "OpenTrustedDomain failed - %s\n", nt_errstr(status));
1863 c.in.handle = &trustdom_handle;
1864 c.out.handle = &handle2;
1866 c_trust.in.handle = &trustdom_handle;
1867 c_trust.out.handle = &handle2;
1869 for (j=0; j < ARRAY_SIZE(levels); j++) {
1870 struct lsa_QueryTrustedDomainInfo q;
1871 union lsa_TrustedDomainInfo *info = NULL;
1872 q.in.trustdom_handle = &trustdom_handle;
1873 q.in.level = levels[j];
1875 status = dcerpc_lsa_QueryTrustedDomainInfo(p, tctx, &q);
1876 if (!NT_STATUS_IS_OK(status) && ok[j]) {
1877 torture_comment(tctx, "QueryTrustedDomainInfo level %d failed - %s\n",
1878 levels[j], nt_errstr(status));
1880 } else if (NT_STATUS_IS_OK(status) && !ok[j]) {
1881 torture_comment(tctx, "QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
1882 levels[j], nt_errstr(status));
1887 status = dcerpc_lsa_CloseTrustedDomainEx(p, tctx, &c_trust);
1888 if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED)) {
1889 torture_comment(tctx, "Expected CloseTrustedDomainEx to return NT_STATUS_NOT_IMPLEMENTED, instead - %s\n", nt_errstr(status));
1893 c.in.handle = &trustdom_handle;
1894 c.out.handle = &handle2;
1896 status = dcerpc_lsa_Close(p, tctx, &c);
1897 if (!NT_STATUS_IS_OK(status)) {
1898 torture_comment(tctx, "Close of trusted domain failed - %s\n", nt_errstr(status));
1902 for (j=0; j < ARRAY_SIZE(levels); j++) {
1903 struct lsa_QueryTrustedDomainInfoBySid q;
1904 union lsa_TrustedDomainInfo *info = NULL;
1906 if (!domains->domains[i].sid) {
1910 q.in.handle = handle;
1911 q.in.dom_sid = domains->domains[i].sid;
1912 q.in.level = levels[j];
1915 status = dcerpc_lsa_QueryTrustedDomainInfoBySid(p, tctx, &q);
1916 if (!NT_STATUS_IS_OK(status) && ok[j]) {
1917 torture_comment(tctx, "QueryTrustedDomainInfoBySid level %d failed - %s\n",
1918 levels[j], nt_errstr(status));
1920 } else if (NT_STATUS_IS_OK(status) && !ok[j]) {
1921 torture_comment(tctx, "QueryTrustedDomainInfoBySid level %d unexpectedly succeeded - %s\n",
1922 levels[j], nt_errstr(status));
1928 trust_by_name.in.handle = handle;
1929 trust_by_name.in.name.string = domains->domains[i].name.string;
1930 trust_by_name.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1931 trust_by_name.out.trustdom_handle = &trustdom_handle;
1933 status = dcerpc_lsa_OpenTrustedDomainByName(p, tctx, &trust_by_name);
1935 if (!NT_STATUS_IS_OK(status)) {
1936 torture_comment(tctx, "OpenTrustedDomainByName failed - %s\n", nt_errstr(status));
1940 for (j=0; j < ARRAY_SIZE(levels); j++) {
1941 struct lsa_QueryTrustedDomainInfo q;
1942 union lsa_TrustedDomainInfo *info = NULL;
1943 q.in.trustdom_handle = &trustdom_handle;
1944 q.in.level = levels[j];
1946 status = dcerpc_lsa_QueryTrustedDomainInfo(p, tctx, &q);
1947 if (!NT_STATUS_IS_OK(status) && ok[j]) {
1948 torture_comment(tctx, "QueryTrustedDomainInfo level %d failed - %s\n",
1949 levels[j], nt_errstr(status));
1951 } else if (NT_STATUS_IS_OK(status) && !ok[j]) {
1952 torture_comment(tctx, "QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
1953 levels[j], nt_errstr(status));
1958 c.in.handle = &trustdom_handle;
1959 c.out.handle = &handle2;
1961 status = dcerpc_lsa_Close(p, tctx, &c);
1962 if (!NT_STATUS_IS_OK(status)) {
1963 torture_comment(tctx, "Close of trusted domain failed - %s\n", nt_errstr(status));
1967 for (j=0; j < ARRAY_SIZE(levels); j++) {
1968 struct lsa_QueryTrustedDomainInfoByName q;
1969 union lsa_TrustedDomainInfo *info = NULL;
1970 struct lsa_String name;
1972 name.string = domains->domains[i].name.string;
1974 q.in.handle = handle;
1975 q.in.trusted_domain = &name;
1976 q.in.level = levels[j];
1978 status = dcerpc_lsa_QueryTrustedDomainInfoByName(p, tctx, &q);
1979 if (!NT_STATUS_IS_OK(status) && ok[j]) {
1980 torture_comment(tctx, "QueryTrustedDomainInfoByName level %d failed - %s\n",
1981 levels[j], nt_errstr(status));
1983 } else if (NT_STATUS_IS_OK(status) && !ok[j]) {
1984 torture_comment(tctx, "QueryTrustedDomainInfoByName level %d unexpectedly succeeded - %s\n",
1985 levels[j], nt_errstr(status));
1993 static bool test_EnumTrustDom(struct dcerpc_pipe *p,
1994 struct torture_context *tctx,
1995 struct policy_handle *handle)
1997 struct lsa_EnumTrustDom r;
1998 NTSTATUS enum_status;
1999 uint32_t resume_handle = 0;
2000 struct lsa_DomainList domains;
2003 torture_comment(tctx, "\nTesting EnumTrustDom\n");
2005 r.in.handle = handle;
2006 r.in.resume_handle = &resume_handle;
2008 r.out.domains = &domains;
2009 r.out.resume_handle = &resume_handle;
2011 enum_status = dcerpc_lsa_EnumTrustDom(p, tctx, &r);
2013 if (NT_STATUS_IS_OK(enum_status)) {
2014 if (domains.count == 0) {
2015 torture_comment(tctx, "EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2018 } else if (!(NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES) || NT_STATUS_EQUAL(enum_status, NT_STATUS_NO_MORE_ENTRIES))) {
2019 torture_comment(tctx, "EnumTrustDom of zero size failed - %s\n", nt_errstr(enum_status));
2023 /* Start from the bottom again */
2027 r.in.handle = handle;
2028 r.in.resume_handle = &resume_handle;
2029 r.in.max_size = LSA_ENUM_TRUST_DOMAIN_MULTIPLIER * 3;
2030 r.out.domains = &domains;
2031 r.out.resume_handle = &resume_handle;
2033 enum_status = dcerpc_lsa_EnumTrustDom(p, tctx, &r);
2035 /* NO_MORE_ENTRIES is allowed */
2036 if (NT_STATUS_EQUAL(enum_status, NT_STATUS_NO_MORE_ENTRIES)) {
2037 if (domains.count == 0) {
2040 torture_comment(tctx, "EnumTrustDom failed - should have returned 0 trusted domains with 'NT_STATUS_NO_MORE_ENTRIES'\n");
2042 } else if (NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES)) {
2043 /* Windows 2003 gets this off by one on the first run */
2044 if (r.out.domains->count < 3 || r.out.domains->count > 4) {
2045 torture_comment(tctx, "EnumTrustDom didn't fill the buffer we "
2046 "asked it to (got %d, expected %d / %d == %d entries)\n",
2047 r.out.domains->count, LSA_ENUM_TRUST_DOMAIN_MULTIPLIER * 3,
2048 LSA_ENUM_TRUST_DOMAIN_MULTIPLIER, r.in.max_size);
2051 } else if (!NT_STATUS_IS_OK(enum_status)) {
2052 torture_comment(tctx, "EnumTrustDom failed - %s\n", nt_errstr(enum_status));
2056 if (domains.count == 0) {
2057 torture_comment(tctx, "EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2061 ret &= test_query_each_TrustDom(p, tctx, handle, &domains);
2063 } while ((NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES)));
2068 static bool test_EnumTrustDomEx(struct dcerpc_pipe *p,
2069 struct torture_context *tctx,
2070 struct policy_handle *handle)
2072 struct lsa_EnumTrustedDomainsEx r_ex;
2073 NTSTATUS enum_status;
2074 uint32_t resume_handle = 0;
2075 struct lsa_DomainListEx domains_ex;
2078 torture_comment(tctx, "\nTesting EnumTrustedDomainsEx\n");
2080 r_ex.in.handle = handle;
2081 r_ex.in.resume_handle = &resume_handle;
2082 r_ex.in.max_size = LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER * 3;
2083 r_ex.out.domains = &domains_ex;
2084 r_ex.out.resume_handle = &resume_handle;
2086 enum_status = dcerpc_lsa_EnumTrustedDomainsEx(p, tctx, &r_ex);
2088 if (!(NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES) || NT_STATUS_EQUAL(enum_status, NT_STATUS_NO_MORE_ENTRIES))) {
2089 torture_comment(tctx, "EnumTrustedDomainEx of zero size failed - %s\n", nt_errstr(enum_status));
2095 r_ex.in.handle = handle;
2096 r_ex.in.resume_handle = &resume_handle;
2097 r_ex.in.max_size = LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER * 3;
2098 r_ex.out.domains = &domains_ex;
2099 r_ex.out.resume_handle = &resume_handle;
2101 enum_status = dcerpc_lsa_EnumTrustedDomainsEx(p, tctx, &r_ex);
2103 /* NO_MORE_ENTRIES is allowed */
2104 if (NT_STATUS_EQUAL(enum_status, NT_STATUS_NO_MORE_ENTRIES)) {
2105 if (domains_ex.count == 0) {
2108 torture_comment(tctx, "EnumTrustDomainsEx failed - should have returned 0 trusted domains with 'NT_STATUS_NO_MORE_ENTRIES'\n");
2110 } else if (NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES)) {
2111 /* Windows 2003 gets this off by one on the first run */
2112 if (r_ex.out.domains->count < 3 || r_ex.out.domains->count > 4) {
2113 torture_comment(tctx, "EnumTrustDom didn't fill the buffer we "
2114 "asked it to (got %d, expected %d / %d == %d entries)\n",
2115 r_ex.out.domains->count,
2117 LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER,
2118 r_ex.in.max_size / LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER);
2120 } else if (!NT_STATUS_IS_OK(enum_status)) {
2121 torture_comment(tctx, "EnumTrustedDomainEx failed - %s\n", nt_errstr(enum_status));
2125 if (domains_ex.count == 0) {
2126 torture_comment(tctx, "EnumTrustDomainEx failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2130 ret &= test_query_each_TrustDomEx(p, tctx, handle, &domains_ex);
2132 } while ((NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES)));
2138 static bool test_CreateTrustedDomain(struct dcerpc_pipe *p,
2139 struct torture_context *tctx,
2140 struct policy_handle *handle)
2144 struct lsa_CreateTrustedDomain r;
2145 struct lsa_DomainInfo trustinfo;
2146 struct dom_sid *domsid[12];
2147 struct policy_handle trustdom_handle[12];
2148 struct lsa_QueryTrustedDomainInfo q;
2149 union lsa_TrustedDomainInfo *info = NULL;
2152 torture_comment(tctx, "\nTesting CreateTrustedDomain for 12 domains\n");
2154 if (!test_EnumTrustDom(p, tctx, handle)) {
2158 if (!test_EnumTrustDomEx(p, tctx, handle)) {
2162 for (i=0; i< 12; i++) {
2163 char *trust_name = talloc_asprintf(tctx, "torturedom%02d", i);
2164 char *trust_sid = talloc_asprintf(tctx, "S-1-5-21-97398-379795-100%02d", i);
2166 domsid[i] = dom_sid_parse_talloc(tctx, trust_sid);
2168 trustinfo.sid = domsid[i];
2169 init_lsa_String((struct lsa_String *)&trustinfo.name, trust_name);
2171 r.in.policy_handle = handle;
2172 r.in.info = &trustinfo;
2173 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2174 r.out.trustdom_handle = &trustdom_handle[i];
2176 status = dcerpc_lsa_CreateTrustedDomain(p, tctx, &r);
2177 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
2178 test_DeleteTrustedDomain(p, tctx, handle, trustinfo.name);
2179 status = dcerpc_lsa_CreateTrustedDomain(p, tctx, &r);
2181 if (!NT_STATUS_IS_OK(status)) {
2182 torture_comment(tctx, "CreateTrustedDomain failed - %s\n", nt_errstr(status));
2186 q.in.trustdom_handle = &trustdom_handle[i];
2187 q.in.level = LSA_TRUSTED_DOMAIN_INFO_INFO_EX;
2189 status = dcerpc_lsa_QueryTrustedDomainInfo(p, tctx, &q);
2190 if (!NT_STATUS_IS_OK(status)) {
2191 torture_comment(tctx, "QueryTrustedDomainInfo level %d failed - %s\n", q.in.level, nt_errstr(status));
2193 } else if (!q.out.info) {
2196 if (strcmp(info->info_ex.netbios_name.string, trustinfo.name.string) != 0) {
2197 torture_comment(tctx, "QueryTrustedDomainInfo returned inconsistant short name: %s != %s\n",
2198 info->info_ex.netbios_name.string, trustinfo.name.string);
2201 if (info->info_ex.trust_type != LSA_TRUST_TYPE_DOWNLEVEL) {
2202 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
2203 trust_name, info->info_ex.trust_type, LSA_TRUST_TYPE_DOWNLEVEL);
2206 if (info->info_ex.trust_attributes != 0) {
2207 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
2208 trust_name, info->info_ex.trust_attributes, 0);
2211 if (info->info_ex.trust_direction != LSA_TRUST_DIRECTION_OUTBOUND) {
2212 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
2213 trust_name, info->info_ex.trust_direction, LSA_TRUST_DIRECTION_OUTBOUND);
2220 /* now that we have some domains to look over, we can test the enum calls */
2221 if (!test_EnumTrustDom(p, tctx, handle)) {
2225 if (!test_EnumTrustDomEx(p, tctx, handle)) {
2229 for (i=0; i<12; i++) {
2230 if (!test_DeleteTrustedDomainBySid(p, tctx, handle, domsid[i])) {
2238 static bool test_CreateTrustedDomainEx2(struct dcerpc_pipe *p,
2239 struct torture_context *tctx,
2240 struct policy_handle *handle)
2244 struct lsa_CreateTrustedDomainEx2 r;
2245 struct lsa_TrustDomainInfoInfoEx trustinfo;
2246 struct lsa_TrustDomainInfoAuthInfoInternal authinfo;
2247 struct trustDomainPasswords auth_struct;
2248 DATA_BLOB auth_blob;
2249 struct dom_sid *domsid[12];
2250 struct policy_handle trustdom_handle[12];
2251 struct lsa_QueryTrustedDomainInfo q;
2252 union lsa_TrustedDomainInfo *info = NULL;
2253 DATA_BLOB session_key;
2254 enum ndr_err_code ndr_err;
2257 torture_comment(tctx, "\nTesting CreateTrustedDomainEx2 for 12 domains\n");
2259 status = dcerpc_fetch_session_key(p, &session_key);
2260 if (!NT_STATUS_IS_OK(status)) {
2261 torture_comment(tctx, "dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
2265 for (i=0; i< 12; i++) {
2266 char *trust_name = talloc_asprintf(tctx, "torturedom%02d", i);
2267 char *trust_name_dns = talloc_asprintf(tctx, "torturedom%02d.samba.example.com", i);
2268 char *trust_sid = talloc_asprintf(tctx, "S-1-5-21-97398-379795-100%02d", i);
2270 domsid[i] = dom_sid_parse_talloc(tctx, trust_sid);
2272 trustinfo.sid = domsid[i];
2273 trustinfo.netbios_name.string = trust_name;
2274 trustinfo.domain_name.string = trust_name_dns;
2276 /* Create inbound, some outbound, and some
2277 * bi-directional trusts in a repeating pattern based
2280 /* 1 == inbound, 2 == outbound, 3 == both */
2281 trustinfo.trust_direction = (i % 3) + 1;
2283 /* Try different trust types too */
2285 /* 1 == downlevel (NT4), 2 == uplevel (ADS), 3 == MIT (kerberos but not AD) */
2286 trustinfo.trust_type = (((i / 3) + 1) % 3) + 1;
2288 trustinfo.trust_attributes = LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION;
2290 generate_random_buffer(auth_struct.confounder, sizeof(auth_struct.confounder));
2292 auth_struct.outgoing.count = 0;
2293 auth_struct.incoming.count = 0;
2295 ndr_err = ndr_push_struct_blob(&auth_blob, tctx, lp_iconv_convenience(tctx->lp_ctx), &auth_struct,
2296 (ndr_push_flags_fn_t)ndr_push_trustDomainPasswords);
2297 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2298 torture_comment(tctx, "ndr_push_struct_blob of trustDomainPasswords structure failed");
2302 arcfour_crypt_blob(auth_blob.data, auth_blob.length, &session_key);
2304 authinfo.auth_blob.size = auth_blob.length;
2305 authinfo.auth_blob.data = auth_blob.data;
2307 r.in.policy_handle = handle;
2308 r.in.info = &trustinfo;
2309 r.in.auth_info = &authinfo;
2310 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2311 r.out.trustdom_handle = &trustdom_handle[i];
2313 status = dcerpc_lsa_CreateTrustedDomainEx2(p, tctx, &r);
2314 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
2315 test_DeleteTrustedDomain(p, tctx, handle, trustinfo.netbios_name);
2316 status = dcerpc_lsa_CreateTrustedDomainEx2(p, tctx, &r);
2318 if (!NT_STATUS_IS_OK(status)) {
2319 torture_comment(tctx, "CreateTrustedDomainEx failed2 - %s\n", nt_errstr(status));
2323 q.in.trustdom_handle = &trustdom_handle[i];
2324 q.in.level = LSA_TRUSTED_DOMAIN_INFO_INFO_EX;
2326 status = dcerpc_lsa_QueryTrustedDomainInfo(p, tctx, &q);
2327 if (!NT_STATUS_IS_OK(status)) {
2328 torture_comment(tctx, "QueryTrustedDomainInfo level 1 failed - %s\n", nt_errstr(status));
2330 } else if (!q.out.info) {
2331 torture_comment(tctx, "QueryTrustedDomainInfo level 1 failed to return an info pointer\n");
2334 if (strcmp(info->info_ex.netbios_name.string, trustinfo.netbios_name.string) != 0) {
2335 torture_comment(tctx, "QueryTrustedDomainInfo returned inconsistant short name: %s != %s\n",
2336 info->info_ex.netbios_name.string, trustinfo.netbios_name.string);
2339 if (info->info_ex.trust_type != trustinfo.trust_type) {
2340 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
2341 trust_name, info->info_ex.trust_type, trustinfo.trust_type);
2344 if (info->info_ex.trust_attributes != LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION) {
2345 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
2346 trust_name, info->info_ex.trust_attributes, LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION);
2349 if (info->info_ex.trust_direction != trustinfo.trust_direction) {
2350 torture_comment(tctx, "QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
2351 trust_name, info->info_ex.trust_direction, trustinfo.trust_direction);
2358 /* now that we have some domains to look over, we can test the enum calls */
2359 if (!test_EnumTrustDom(p, tctx, handle)) {
2360 torture_comment(tctx, "test_EnumTrustDom failed\n");
2364 if (!test_EnumTrustDomEx(p, tctx, handle)) {
2365 torture_comment(tctx, "test_EnumTrustDomEx failed\n");
2369 for (i=0; i<12; i++) {
2370 if (!test_DeleteTrustedDomainBySid(p, tctx, handle, domsid[i])) {
2371 torture_comment(tctx, "test_DeleteTrustedDomainBySid failed\n");
2379 static bool test_QueryDomainInfoPolicy(struct dcerpc_pipe *p,
2380 struct torture_context *tctx,
2381 struct policy_handle *handle)
2383 struct lsa_QueryDomainInformationPolicy r;
2384 union lsa_DomainInformationPolicy *info = NULL;
2389 torture_comment(tctx, "\nTesting QueryDomainInformationPolicy\n");
2392 r.in.handle = handle;
2396 torture_comment(tctx, "\nTrying QueryDomainInformationPolicy level %d\n", i);
2398 status = dcerpc_lsa_QueryDomainInformationPolicy(p, tctx, &r);
2400 /* If the server does not support EFS, then this is the correct return */
2401 if (i == LSA_DOMAIN_INFO_POLICY_EFS && NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
2403 } else if (!NT_STATUS_IS_OK(status)) {
2404 torture_comment(tctx, "QueryDomainInformationPolicy failed - %s\n", nt_errstr(status));
2414 static bool test_QueryInfoPolicyCalls( bool version2,
2415 struct dcerpc_pipe *p,
2416 struct torture_context *tctx,
2417 struct policy_handle *handle)
2419 struct lsa_QueryInfoPolicy r;
2420 union lsa_PolicyInformation *info = NULL;
2426 torture_comment(tctx, "\nTesting QueryInfoPolicy2\n");
2428 torture_comment(tctx, "\nTesting QueryInfoPolicy\n");
2430 for (i=1;i<=14;i++) {
2431 r.in.handle = handle;
2436 torture_comment(tctx, "\nTrying QueryInfoPolicy2 level %d\n", i);
2438 torture_comment(tctx, "\nTrying QueryInfoPolicy level %d\n", i);
2441 /* We can perform the cast, because both types are
2442 structurally equal */
2443 status = dcerpc_lsa_QueryInfoPolicy2(p, tctx,
2444 (struct lsa_QueryInfoPolicy2*) &r);
2446 status = dcerpc_lsa_QueryInfoPolicy(p, tctx, &r);
2449 case LSA_POLICY_INFO_MOD:
2450 case LSA_POLICY_INFO_AUDIT_FULL_SET:
2451 case LSA_POLICY_INFO_AUDIT_FULL_QUERY:
2452 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
2453 torture_comment(tctx, "Server should have failed level %u: %s\n", i, nt_errstr(status));
2457 case LSA_POLICY_INFO_DOMAIN:
2458 case LSA_POLICY_INFO_ACCOUNT_DOMAIN:
2459 case LSA_POLICY_INFO_L_ACCOUNT_DOMAIN:
2460 case LSA_POLICY_INFO_DNS_INT:
2461 case LSA_POLICY_INFO_DNS:
2462 case LSA_POLICY_INFO_REPLICA:
2463 case LSA_POLICY_INFO_QUOTA:
2464 case LSA_POLICY_INFO_ROLE:
2465 case LSA_POLICY_INFO_AUDIT_LOG:
2466 case LSA_POLICY_INFO_AUDIT_EVENTS:
2467 case LSA_POLICY_INFO_PD:
2468 if (!NT_STATUS_IS_OK(status)) {
2470 torture_comment(tctx, "QueryInfoPolicy2 failed - %s\n", nt_errstr(status));
2472 torture_comment(tctx, "QueryInfoPolicy failed - %s\n", nt_errstr(status));
2477 if (torture_setting_bool(tctx, "samba4", false)) {
2478 /* Other levels not implemented yet */
2479 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_INFO_CLASS)) {
2481 torture_comment(tctx, "QueryInfoPolicy2 failed - %s\n", nt_errstr(status));
2483 torture_comment(tctx, "QueryInfoPolicy failed - %s\n", nt_errstr(status));
2486 } else if (!NT_STATUS_IS_OK(status)) {
2488 torture_comment(tctx, "QueryInfoPolicy2 failed - %s\n", nt_errstr(status));
2490 torture_comment(tctx, "QueryInfoPolicy failed - %s\n", nt_errstr(status));
2496 if (NT_STATUS_IS_OK(status) && (i == LSA_POLICY_INFO_DNS
2497 || i == LSA_POLICY_INFO_DNS_INT)) {
2498 /* Let's look up some of these names */
2500 struct lsa_TransNameArray tnames;
2502 tnames.names = talloc_zero_array(tctx, struct lsa_TranslatedName, tnames.count);
2503 tnames.names[0].name.string = info->dns.name.string;
2504 tnames.names[0].sid_type = SID_NAME_DOMAIN;
2505 tnames.names[1].name.string = info->dns.dns_domain.string;
2506 tnames.names[1].sid_type = SID_NAME_DOMAIN;
2507 tnames.names[2].name.string = talloc_asprintf(tctx, "%s\\", info->dns.name.string);
2508 tnames.names[2].sid_type = SID_NAME_DOMAIN;
2509 tnames.names[3].name.string = talloc_asprintf(tctx, "%s\\", info->dns.dns_domain.string);
2510 tnames.names[3].sid_type = SID_NAME_DOMAIN;
2511 tnames.names[4].name.string = talloc_asprintf(tctx, "%s\\guest", info->dns.name.string);
2512 tnames.names[4].sid_type = SID_NAME_USER;
2513 tnames.names[5].name.string = talloc_asprintf(tctx, "%s\\krbtgt", info->dns.name.string);
2514 tnames.names[5].sid_type = SID_NAME_USER;
2515 tnames.names[6].name.string = talloc_asprintf(tctx, "%s\\guest", info->dns.dns_domain.string);
2516 tnames.names[6].sid_type = SID_NAME_USER;
2517 tnames.names[7].name.string = talloc_asprintf(tctx, "%s\\krbtgt", info->dns.dns_domain.string);
2518 tnames.names[7].sid_type = SID_NAME_USER;
2519 tnames.names[8].name.string = talloc_asprintf(tctx, "krbtgt@%s", info->dns.name.string);
2520 tnames.names[8].sid_type = SID_NAME_USER;
2521 tnames.names[9].name.string = talloc_asprintf(tctx, "krbtgt@%s", info->dns.dns_domain.string);
2522 tnames.names[9].sid_type = SID_NAME_USER;
2523 tnames.names[10].name.string = talloc_asprintf(tctx, "%s\\"TEST_MACHINENAME "$", info->dns.name.string);
2524 tnames.names[10].sid_type = SID_NAME_USER;
2525 tnames.names[11].name.string = talloc_asprintf(tctx, "%s\\"TEST_MACHINENAME "$", info->dns.dns_domain.string);
2526 tnames.names[11].sid_type = SID_NAME_USER;
2527 tnames.names[12].name.string = talloc_asprintf(tctx, TEST_MACHINENAME "$@%s", info->dns.name.string);
2528 tnames.names[12].sid_type = SID_NAME_USER;
2529 tnames.names[13].name.string = talloc_asprintf(tctx, TEST_MACHINENAME "$@%s", info->dns.dns_domain.string);
2530 tnames.names[13].sid_type = SID_NAME_USER;
2531 ret &= test_LookupNames(p, tctx, handle, &tnames);
2539 static bool test_QueryInfoPolicy(struct dcerpc_pipe *p,
2540 struct torture_context *tctx,
2541 struct policy_handle *handle)
2543 return test_QueryInfoPolicyCalls(false, p, tctx, handle);
2546 static bool test_QueryInfoPolicy2(struct dcerpc_pipe *p,
2547 struct torture_context *tctx,
2548 struct policy_handle *handle)
2550 return test_QueryInfoPolicyCalls(true, p, tctx, handle);
2553 static bool test_GetUserName(struct dcerpc_pipe *p,
2554 struct torture_context *tctx)
2556 struct lsa_GetUserName r;
2559 struct lsa_String *authority_name_p = NULL;
2560 struct lsa_String *account_name_p = NULL;
2562 torture_comment(tctx, "\nTesting GetUserName\n");
2564 r.in.system_name = "\\";
2565 r.in.account_name = &account_name_p;
2566 r.in.authority_name = NULL;
2567 r.out.account_name = &account_name_p;
2569 status = dcerpc_lsa_GetUserName(p, tctx, &r);
2571 if (!NT_STATUS_IS_OK(status)) {
2572 torture_comment(tctx, "GetUserName failed - %s\n", nt_errstr(status));
2576 account_name_p = NULL;
2577 r.in.account_name = &account_name_p;
2578 r.in.authority_name = &authority_name_p;
2579 r.out.account_name = &account_name_p;
2581 status = dcerpc_lsa_GetUserName(p, tctx, &r);
2583 if (!NT_STATUS_IS_OK(status)) {
2584 torture_comment(tctx, "GetUserName failed - %s\n", nt_errstr(status));
2591 bool test_lsa_Close(struct dcerpc_pipe *p,
2592 struct torture_context *tctx,
2593 struct policy_handle *handle)
2597 struct policy_handle handle2;
2599 torture_comment(tctx, "\nTesting Close\n");
2601 r.in.handle = handle;
2602 r.out.handle = &handle2;
2604 status = dcerpc_lsa_Close(p, tctx, &r);
2605 if (!NT_STATUS_IS_OK(status)) {
2606 torture_comment(tctx, "Close failed - %s\n", nt_errstr(status));
2610 status = dcerpc_lsa_Close(p, tctx, &r);
2611 /* its really a fault - we need a status code for rpc fault */
2612 if (!NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
2613 torture_comment(tctx, "Close failed - %s\n", nt_errstr(status));
2617 torture_comment(tctx, "\n");
2622 bool torture_rpc_lsa(struct torture_context *tctx)
2625 struct dcerpc_pipe *p;
2627 struct policy_handle *handle;
2628 struct test_join *join = NULL;
2629 struct cli_credentials *machine_creds;
2631 status = torture_rpc_connection(tctx, &p, &ndr_table_lsarpc);
2632 if (!NT_STATUS_IS_OK(status)) {
2636 if (!test_OpenPolicy(p, tctx)) {
2640 if (!test_lsa_OpenPolicy2(p, tctx, &handle)) {
2645 join = torture_join_domain(tctx, TEST_MACHINENAME, ACB_WSTRUST, &machine_creds);
2650 if (!test_LookupSids_async(p, tctx, handle)) {
2654 if (!test_QueryDomainInfoPolicy(p, tctx, handle)) {
2658 if (!test_CreateSecret(p, tctx, handle)) {
2662 if (!test_QueryInfoPolicy(p, tctx, handle)) {
2666 if (!test_QueryInfoPolicy2(p, tctx, handle)) {
2670 if (!test_Delete(p, tctx, handle)) {
2674 if (!test_many_LookupSids(p, tctx, handle)) {
2678 if (!test_lsa_Close(p, tctx, handle)) {
2682 torture_leave_domain(tctx, join);
2685 if (!test_many_LookupSids(p, tctx, handle)) {
2690 if (!test_GetUserName(p, tctx)) {
2697 bool torture_rpc_lsa_get_user(struct torture_context *tctx)
2700 struct dcerpc_pipe *p;
2703 status = torture_rpc_connection(tctx, &p, &ndr_table_lsarpc);
2704 if (!NT_STATUS_IS_OK(status)) {
2708 if (!test_GetUserName(p, tctx)) {
2715 static bool testcase_LookupNames(struct torture_context *tctx,
2716 struct dcerpc_pipe *p)
2719 struct policy_handle *handle;
2720 struct lsa_TransNameArray tnames;
2721 struct lsa_TransNameArray2 tnames2;
2723 if (!test_OpenPolicy(p, tctx)) {
2727 if (!test_lsa_OpenPolicy2(p, tctx, &handle)) {
2736 tnames.names = talloc_array(tctx, struct lsa_TranslatedName, tnames.count);
2737 ZERO_STRUCT(tnames.names[0]);
2738 tnames.names[0].name.string = "BUILTIN";
2739 tnames.names[0].sid_type = SID_NAME_DOMAIN;
2741 if (!test_LookupNames(p, tctx, handle, &tnames)) {
2746 tnames2.names = talloc_array(tctx, struct lsa_TranslatedName2, tnames2.count);
2747 ZERO_STRUCT(tnames2.names[0]);
2748 tnames2.names[0].name.string = "BUILTIN";
2749 tnames2.names[0].sid_type = SID_NAME_DOMAIN;
2751 if (!test_LookupNames2(p, tctx, handle, &tnames2, true)) {
2755 if (!test_LookupNames3(p, tctx, handle, &tnames2, true)) {
2759 if (!test_LookupNames_wellknown(p, tctx, handle)) {
2763 if (!test_LookupNames_bogus(p, tctx, handle)) {
2767 if (!test_lsa_Close(p, tctx, handle)) {
2774 struct torture_suite *torture_rpc_lsa_lookup_names(TALLOC_CTX *mem_ctx)
2776 struct torture_suite *suite;
2777 struct torture_rpc_tcase *tcase;
2779 suite = torture_suite_create(mem_ctx, "LSA-LOOKUPNAMES");
2781 tcase = torture_suite_add_rpc_iface_tcase(suite, "lsa",
2783 torture_rpc_tcase_add_test(tcase, "LookupNames",
2784 testcase_LookupNames);
2789 static bool testcase_TrustedDomains(struct torture_context *tctx,
2790 struct dcerpc_pipe *p)
2793 struct policy_handle *handle;
2795 if (!test_OpenPolicy(p, tctx)) {
2799 if (!test_lsa_OpenPolicy2(p, tctx, &handle)) {
2807 if (!test_CreateTrustedDomain(p, tctx, handle)) {
2811 if (!test_CreateTrustedDomainEx2(p, tctx, handle)) {
2815 if (!test_lsa_Close(p, tctx, handle)) {
2822 struct torture_suite *torture_rpc_lsa_trusted_domains(TALLOC_CTX *mem_ctx)
2824 struct torture_suite *suite;
2825 struct torture_rpc_tcase *tcase;
2827 suite = torture_suite_create(mem_ctx, "LSA-TRUSTED-DOMAINS");
2829 tcase = torture_suite_add_rpc_iface_tcase(suite, "lsa",
2831 torture_rpc_tcase_add_test(tcase, "TrustedDomains",
2832 testcase_TrustedDomains);
2837 static bool testcase_Privileges(struct torture_context *tctx,
2838 struct dcerpc_pipe *p)
2841 struct policy_handle *handle;
2843 if (!test_OpenPolicy(p, tctx)) {
2847 if (!test_lsa_OpenPolicy2(p, tctx, &handle)) {
2855 if (!test_CreateAccount(p, tctx, handle)) {
2859 if (!test_EnumAccounts(p, tctx, handle)) {
2863 if (!test_EnumPrivs(p, tctx, handle)) {
2867 if (!test_lsa_Close(p, tctx, handle)) {
2875 struct torture_suite *torture_rpc_lsa_privileges(TALLOC_CTX *mem_ctx)
2877 struct torture_suite *suite;
2878 struct torture_rpc_tcase *tcase;
2880 suite = torture_suite_create(mem_ctx, "LSA-PRIVILEGES");
2882 tcase = torture_suite_add_rpc_iface_tcase(suite, "lsa",
2884 torture_rpc_tcase_add_test(tcase, "Privileges",
2885 testcase_Privileges);