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 printf("\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 printf("not considering %s to be an error\n", nt_errstr(status));
76 printf("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 printf("\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 printf("not considering %s to be an error\n", nt_errstr(status));
122 talloc_free(*handle);
126 printf("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 printf("\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 printf("LookupName of %s was unmapped\n",
191 tnames->names[i].name.string);
192 } else if (i >=count) {
193 printf("LookupName of %s failed to return a result\n",
194 tnames->names[i].name.string);
197 printf("LookupNames failed - %s\n", nt_errstr(status));
199 } else if (!NT_STATUS_IS_OK(status)) {
200 printf("LookupNames failed - %s\n", nt_errstr(status));
204 for (i=0;i< tnames->count;i++) {
205 if (i < count && sids.sids[i].sid_type != tnames->names[i].sid_type) {
206 printf("LookupName of %s got unexpected name type: %s\n",
207 tnames->names[i].name.string, sid_type_lookup(sids.sids[i].sid_type));
208 } else if (i >=count) {
209 printf("LookupName of %s failed to return a result\n",
210 tnames->names[i].name.string);
218 static bool test_LookupNames_bogus(struct dcerpc_pipe *p,
219 struct torture_context *tctx,
220 struct policy_handle *handle)
222 struct lsa_LookupNames r;
223 struct lsa_TransSidArray sids;
224 struct lsa_RefDomainList *domains = NULL;
225 struct lsa_String *names;
230 struct lsa_TranslatedName name[2];
231 struct lsa_TransNameArray tnames;
235 name[0].name.string = "NT AUTHORITY\\BOGUS";
236 name[1].name.string = NULL;
238 printf("\nTesting LookupNames with bogus names\n");
243 names = talloc_array(tctx, struct lsa_String, tnames.count);
244 for (i=0;i<tnames.count;i++) {
245 init_lsa_String(&names[i], tnames.names[i].name.string);
248 r.in.handle = handle;
249 r.in.num_names = tnames.count;
254 r.out.count = &count;
256 r.out.domains = &domains;
258 status = dcerpc_lsa_LookupNames(p, tctx, &r);
259 if (!NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED)) {
260 printf("LookupNames failed - %s\n", nt_errstr(status));
269 static bool test_LookupNames_wellknown(struct dcerpc_pipe *p,
270 struct torture_context *tctx,
271 struct policy_handle *handle)
273 struct lsa_TranslatedName name;
274 struct lsa_TransNameArray tnames;
277 printf("Testing LookupNames with well known names\n");
279 tnames.names = &name;
281 name.name.string = "NT AUTHORITY\\SYSTEM";
282 name.sid_type = SID_NAME_WKN_GRP;
283 ret &= test_LookupNames(p, tctx, handle, &tnames);
285 name.name.string = "NT AUTHORITY\\ANONYMOUS LOGON";
286 name.sid_type = SID_NAME_WKN_GRP;
287 ret &= test_LookupNames(p, tctx, handle, &tnames);
289 name.name.string = "NT AUTHORITY\\Authenticated Users";
290 name.sid_type = SID_NAME_WKN_GRP;
291 ret &= test_LookupNames(p, tctx, handle, &tnames);
294 name.name.string = "NT AUTHORITY";
295 ret &= test_LookupNames(p, tctx, handle, &tnames);
297 name.name.string = "NT AUTHORITY\\";
298 ret &= test_LookupNames(p, tctx, handle, &tnames);
301 name.name.string = "BUILTIN\\";
302 name.sid_type = SID_NAME_DOMAIN;
303 ret &= test_LookupNames(p, tctx, handle, &tnames);
305 name.name.string = "BUILTIN\\Administrators";
306 name.sid_type = SID_NAME_ALIAS;
307 ret &= test_LookupNames(p, tctx, handle, &tnames);
309 name.name.string = "SYSTEM";
310 name.sid_type = SID_NAME_WKN_GRP;
311 ret &= test_LookupNames(p, tctx, handle, &tnames);
313 name.name.string = "Everyone";
314 name.sid_type = SID_NAME_WKN_GRP;
315 ret &= test_LookupNames(p, tctx, handle, &tnames);
319 static bool test_LookupNames2(struct dcerpc_pipe *p,
320 struct torture_context *tctx,
321 struct policy_handle *handle,
322 struct lsa_TransNameArray2 *tnames)
324 struct lsa_LookupNames2 r;
325 struct lsa_TransSidArray2 sids;
326 struct lsa_RefDomainList *domains = NULL;
327 struct lsa_String *names;
332 printf("\nTesting LookupNames2 with %d names\n", tnames->count);
337 names = talloc_array(tctx, struct lsa_String, tnames->count);
338 for (i=0;i<tnames->count;i++) {
339 init_lsa_String(&names[i], tnames->names[i].name.string);
342 r.in.handle = handle;
343 r.in.num_names = tnames->count;
348 r.in.lookup_options = 0;
349 r.in.client_revision = 0;
350 r.out.count = &count;
352 r.out.domains = &domains;
354 status = dcerpc_lsa_LookupNames2(p, tctx, &r);
355 if (!NT_STATUS_IS_OK(status)) {
356 printf("LookupNames2 failed - %s\n", nt_errstr(status));
366 static bool test_LookupNames3(struct dcerpc_pipe *p,
367 struct torture_context *tctx,
368 struct policy_handle *handle,
369 struct lsa_TransNameArray2 *tnames)
371 struct lsa_LookupNames3 r;
372 struct lsa_TransSidArray3 sids;
373 struct lsa_RefDomainList *domains = NULL;
374 struct lsa_String *names;
379 printf("\nTesting LookupNames3 with %d names\n", tnames->count);
384 names = talloc_array(tctx, struct lsa_String, tnames->count);
385 for (i=0;i<tnames->count;i++) {
386 init_lsa_String(&names[i], tnames->names[i].name.string);
389 r.in.handle = handle;
390 r.in.num_names = tnames->count;
395 r.in.lookup_options = 0;
396 r.in.client_revision = 0;
397 r.out.count = &count;
399 r.out.domains = &domains;
401 status = dcerpc_lsa_LookupNames3(p, tctx, &r);
402 if (!NT_STATUS_IS_OK(status)) {
403 printf("LookupNames3 failed - %s\n", nt_errstr(status));
412 static bool test_LookupNames4(struct dcerpc_pipe *p,
413 struct torture_context *tctx,
414 struct lsa_TransNameArray2 *tnames)
416 struct lsa_LookupNames4 r;
417 struct lsa_TransSidArray3 sids;
418 struct lsa_RefDomainList *domains = NULL;
419 struct lsa_String *names;
424 printf("\nTesting LookupNames4 with %d names\n", tnames->count);
429 names = talloc_array(tctx, struct lsa_String, tnames->count);
430 for (i=0;i<tnames->count;i++) {
431 init_lsa_String(&names[i], tnames->names[i].name.string);
434 r.in.num_names = tnames->count;
439 r.in.lookup_options = 0;
440 r.in.client_revision = 0;
441 r.out.count = &count;
443 r.out.domains = &domains;
445 status = dcerpc_lsa_LookupNames4(p, tctx, &r);
446 if (!NT_STATUS_IS_OK(status)) {
447 printf("LookupNames4 failed - %s\n", nt_errstr(status));
457 static bool test_LookupSids(struct dcerpc_pipe *p,
458 struct torture_context *tctx,
459 struct policy_handle *handle,
460 struct lsa_SidArray *sids)
462 struct lsa_LookupSids r;
463 struct lsa_TransNameArray names;
464 struct lsa_RefDomainList *domains = NULL;
465 uint32_t count = sids->num_sids;
468 printf("\nTesting LookupSids\n");
473 r.in.handle = handle;
478 r.out.count = &count;
479 r.out.names = &names;
480 r.out.domains = &domains;
482 status = dcerpc_lsa_LookupSids(p, tctx, &r);
483 if (!NT_STATUS_IS_OK(status)) {
484 printf("LookupSids failed - %s\n", nt_errstr(status));
490 if (!test_LookupNames(p, tctx, handle, &names)) {
498 static bool test_LookupSids2(struct dcerpc_pipe *p,
499 struct torture_context *tctx,
500 struct policy_handle *handle,
501 struct lsa_SidArray *sids)
503 struct lsa_LookupSids2 r;
504 struct lsa_TransNameArray2 names;
505 struct lsa_RefDomainList *domains = NULL;
506 uint32_t count = sids->num_sids;
509 printf("\nTesting LookupSids2\n");
514 r.in.handle = handle;
521 r.out.count = &count;
522 r.out.names = &names;
523 r.out.domains = &domains;
525 status = dcerpc_lsa_LookupSids2(p, tctx, &r);
526 if (!NT_STATUS_IS_OK(status)) {
527 printf("LookupSids2 failed - %s\n", nt_errstr(status));
533 if (!test_LookupNames2(p, tctx, handle, &names)) {
537 if (!test_LookupNames3(p, tctx, handle, &names)) {
544 static bool test_LookupSids3(struct dcerpc_pipe *p,
545 struct torture_context *tctx,
546 struct lsa_SidArray *sids)
548 struct lsa_LookupSids3 r;
549 struct lsa_TransNameArray2 names;
550 struct lsa_RefDomainList *domains = NULL;
551 uint32_t count = sids->num_sids;
554 printf("\nTesting LookupSids3\n");
565 r.out.domains = &domains;
566 r.out.count = &count;
567 r.out.names = &names;
569 status = dcerpc_lsa_LookupSids3(p, tctx, &r);
570 if (!NT_STATUS_IS_OK(status)) {
571 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
572 NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
573 printf("not considering %s to be an error\n", nt_errstr(status));
576 printf("LookupSids3 failed - %s - not considered an error\n",
583 if (!test_LookupNames4(p, tctx, &names)) {
590 bool test_many_LookupSids(struct dcerpc_pipe *p,
591 struct torture_context *tctx,
592 struct policy_handle *handle)
596 struct lsa_SidArray sids;
599 printf("\nTesting LookupSids with lots of SIDs\n");
603 sids.sids = talloc_array(tctx, struct lsa_SidPtr, sids.num_sids);
605 for (i=0; i<sids.num_sids; i++) {
606 const char *sidstr = "S-1-5-32-545";
607 sids.sids[i].sid = dom_sid_parse_talloc(tctx, sidstr);
610 count = sids.num_sids;
613 struct lsa_LookupSids r;
614 struct lsa_TransNameArray names;
615 struct lsa_RefDomainList *domains = NULL;
619 r.in.handle = handle;
623 r.in.count = &names.count;
624 r.out.count = &count;
625 r.out.names = &names;
626 r.out.domains = &domains;
628 status = dcerpc_lsa_LookupSids(p, tctx, &r);
629 if (!NT_STATUS_IS_OK(status)) {
630 printf("LookupSids failed - %s\n", nt_errstr(status));
636 if (!test_LookupNames(p, tctx, handle, &names)) {
639 } else if (p->conn->security_state.auth_info->auth_type == DCERPC_AUTH_TYPE_SCHANNEL &&
640 p->conn->security_state.auth_info->auth_level >= DCERPC_AUTH_LEVEL_INTEGRITY) {
641 struct lsa_LookupSids3 r;
642 struct lsa_RefDomainList *domains = NULL;
643 struct lsa_TransNameArray2 names;
648 printf("\nTesting LookupSids3\n");
656 r.out.count = &count;
657 r.out.names = &names;
658 r.out.domains = &domains;
660 status = dcerpc_lsa_LookupSids3(p, tctx, &r);
661 if (!NT_STATUS_IS_OK(status)) {
662 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
663 NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
664 printf("not considering %s to be an error\n", nt_errstr(status));
667 printf("LookupSids3 failed - %s\n",
671 if (!test_LookupNames4(p, tctx, &names)) {
683 static void lookupsids_cb(struct rpc_request *req)
685 int *replies = (int *)req->async.private_data;
688 status = dcerpc_ndr_request_recv(req);
689 if (!NT_STATUS_IS_OK(status)) {
690 printf("lookupsids returned %s\n", nt_errstr(status));
699 static bool test_LookupSids_async(struct dcerpc_pipe *p,
700 struct torture_context *tctx,
701 struct policy_handle *handle)
703 struct lsa_SidArray sids;
704 struct lsa_SidPtr sidptr;
706 struct lsa_TransNameArray *names;
707 struct lsa_LookupSids *r;
708 struct lsa_RefDomainList *domains = NULL;
709 struct rpc_request **req;
712 const int num_async_requests = 50;
714 count = talloc_array(tctx, uint32_t, num_async_requests);
715 names = talloc_array(tctx, struct lsa_TransNameArray, num_async_requests);
716 r = talloc_array(tctx, struct lsa_LookupSids, num_async_requests);
718 printf("\nTesting %d async lookupsids request\n", num_async_requests);
720 req = talloc_array(tctx, struct rpc_request *, num_async_requests);
724 sidptr.sid = dom_sid_parse_talloc(tctx, "S-1-5-32-545");
728 for (i=0; i<num_async_requests; i++) {
731 names[i].names = NULL;
733 r[i].in.handle = handle;
734 r[i].in.sids = &sids;
735 r[i].in.names = &names[i];
737 r[i].in.count = &names[i].count;
738 r[i].out.count = &count[i];
739 r[i].out.names = &names[i];
740 r[i].out.domains = &domains;
742 req[i] = dcerpc_lsa_LookupSids_send(p, req, &r[i]);
743 if (req[i] == NULL) {
748 req[i]->async.callback = lookupsids_cb;
749 req[i]->async.private_data = &replies;
752 while (replies >= 0 && replies < num_async_requests) {
753 event_loop_once(p->conn->event_ctx);
765 static bool test_LookupPrivValue(struct dcerpc_pipe *p,
766 struct torture_context *tctx,
767 struct policy_handle *handle,
768 struct lsa_String *name)
771 struct lsa_LookupPrivValue r;
772 struct lsa_LUID luid;
774 r.in.handle = handle;
778 status = dcerpc_lsa_LookupPrivValue(p, tctx, &r);
779 if (!NT_STATUS_IS_OK(status)) {
780 printf("\nLookupPrivValue failed - %s\n", nt_errstr(status));
787 static bool test_LookupPrivName(struct dcerpc_pipe *p,
788 struct torture_context *tctx,
789 struct policy_handle *handle,
790 struct lsa_LUID *luid)
793 struct lsa_LookupPrivName r;
794 struct lsa_StringLarge *name = NULL;
796 r.in.handle = handle;
800 status = dcerpc_lsa_LookupPrivName(p, tctx, &r);
801 if (!NT_STATUS_IS_OK(status)) {
802 printf("\nLookupPrivName failed - %s\n", nt_errstr(status));
809 static bool test_RemovePrivilegesFromAccount(struct dcerpc_pipe *p,
810 struct torture_context *tctx,
811 struct policy_handle *handle,
812 struct policy_handle *acct_handle,
813 struct lsa_LUID *luid)
816 struct lsa_RemovePrivilegesFromAccount r;
817 struct lsa_PrivilegeSet privs;
820 printf("\nTesting RemovePrivilegesFromAccount\n");
822 r.in.handle = acct_handle;
828 privs.set = talloc_array(tctx, struct lsa_LUIDAttribute, 1);
829 privs.set[0].luid = *luid;
830 privs.set[0].attribute = 0;
832 status = dcerpc_lsa_RemovePrivilegesFromAccount(p, tctx, &r);
833 if (!NT_STATUS_IS_OK(status)) {
835 struct lsa_LookupPrivName r_name;
836 struct lsa_StringLarge *name = NULL;
838 r_name.in.handle = handle;
839 r_name.in.luid = luid;
840 r_name.out.name = &name;
842 status = dcerpc_lsa_LookupPrivName(p, tctx, &r_name);
843 if (!NT_STATUS_IS_OK(status)) {
844 printf("\nLookupPrivName failed - %s\n", nt_errstr(status));
847 /* Windows 2008 does not allow this to be removed */
848 if (strcmp("SeAuditPrivilege", name->string) == 0) {
852 printf("RemovePrivilegesFromAccount failed to remove %s - %s\n",
861 static bool test_AddPrivilegesToAccount(struct dcerpc_pipe *p,
862 struct torture_context *tctx,
863 struct policy_handle *acct_handle,
864 struct lsa_LUID *luid)
867 struct lsa_AddPrivilegesToAccount r;
868 struct lsa_PrivilegeSet privs;
871 printf("\nTesting AddPrivilegesToAccount\n");
873 r.in.handle = acct_handle;
878 privs.set = talloc_array(tctx, struct lsa_LUIDAttribute, 1);
879 privs.set[0].luid = *luid;
880 privs.set[0].attribute = 0;
882 status = dcerpc_lsa_AddPrivilegesToAccount(p, tctx, &r);
883 if (!NT_STATUS_IS_OK(status)) {
884 printf("AddPrivilegesToAccount failed - %s\n", nt_errstr(status));
891 static bool test_EnumPrivsAccount(struct dcerpc_pipe *p,
892 struct torture_context *tctx,
893 struct policy_handle *handle,
894 struct policy_handle *acct_handle)
897 struct lsa_EnumPrivsAccount r;
898 struct lsa_PrivilegeSet *privs = NULL;
901 printf("\nTesting EnumPrivsAccount\n");
903 r.in.handle = acct_handle;
904 r.out.privs = &privs;
906 status = dcerpc_lsa_EnumPrivsAccount(p, tctx, &r);
907 if (!NT_STATUS_IS_OK(status)) {
908 printf("EnumPrivsAccount failed - %s\n", nt_errstr(status));
912 if (privs && privs->count > 0) {
914 for (i=0;i<privs->count;i++) {
915 test_LookupPrivName(p, tctx, handle,
916 &privs->set[i].luid);
919 ret &= test_RemovePrivilegesFromAccount(p, tctx, handle, acct_handle,
920 &privs->set[0].luid);
921 ret &= test_AddPrivilegesToAccount(p, tctx, acct_handle,
922 &privs->set[0].luid);
928 static bool test_GetSystemAccessAccount(struct dcerpc_pipe *p,
929 struct torture_context *tctx,
930 struct policy_handle *handle,
931 struct policy_handle *acct_handle)
934 uint32_t access_mask;
935 struct lsa_GetSystemAccessAccount r;
937 printf("\nTesting GetSystemAccessAccount\n");
939 r.in.handle = acct_handle;
940 r.out.access_mask = &access_mask;
942 status = dcerpc_lsa_GetSystemAccessAccount(p, tctx, &r);
943 if (!NT_STATUS_IS_OK(status)) {
944 printf("GetSystemAccessAccount failed - %s\n", nt_errstr(status));
948 if (r.out.access_mask != NULL) {
950 if (*(r.out.access_mask) & LSA_POLICY_MODE_INTERACTIVE)
951 printf(" LSA_POLICY_MODE_INTERACTIVE");
952 if (*(r.out.access_mask) & LSA_POLICY_MODE_NETWORK)
953 printf(" LSA_POLICY_MODE_NETWORK");
954 if (*(r.out.access_mask) & LSA_POLICY_MODE_BATCH)
955 printf(" LSA_POLICY_MODE_BATCH");
956 if (*(r.out.access_mask) & LSA_POLICY_MODE_SERVICE)
957 printf(" LSA_POLICY_MODE_SERVICE");
958 if (*(r.out.access_mask) & LSA_POLICY_MODE_PROXY)
959 printf(" LSA_POLICY_MODE_PROXY");
960 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_INTERACTIVE)
961 printf(" LSA_POLICY_MODE_DENY_INTERACTIVE");
962 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_NETWORK)
963 printf(" LSA_POLICY_MODE_DENY_NETWORK");
964 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_BATCH)
965 printf(" LSA_POLICY_MODE_DENY_BATCH");
966 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_SERVICE)
967 printf(" LSA_POLICY_MODE_DENY_SERVICE");
968 if (*(r.out.access_mask) & LSA_POLICY_MODE_REMOTE_INTERACTIVE)
969 printf(" LSA_POLICY_MODE_REMOTE_INTERACTIVE");
970 if (*(r.out.access_mask) & LSA_POLICY_MODE_DENY_REMOTE_INTERACTIVE)
971 printf(" LSA_POLICY_MODE_DENY_REMOTE_INTERACTIVE");
972 if (*(r.out.access_mask) & LSA_POLICY_MODE_ALL)
973 printf(" LSA_POLICY_MODE_ALL");
974 if (*(r.out.access_mask) & LSA_POLICY_MODE_ALL_NT4)
975 printf(" LSA_POLICY_MODE_ALL_NT4");
982 static bool test_Delete(struct dcerpc_pipe *p,
983 struct torture_context *tctx,
984 struct policy_handle *handle)
989 printf("\nTesting Delete\n");
991 r.in.handle = handle;
992 status = dcerpc_lsa_Delete(p, tctx, &r);
993 if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
994 printf("Delete should have failed NT_STATUS_NOT_SUPPORTED - %s\n", nt_errstr(status));
1001 static bool test_DeleteObject(struct dcerpc_pipe *p,
1002 struct torture_context *tctx,
1003 struct policy_handle *handle)
1006 struct lsa_DeleteObject r;
1008 printf("\nTesting DeleteObject\n");
1010 r.in.handle = handle;
1011 r.out.handle = handle;
1012 status = dcerpc_lsa_DeleteObject(p, tctx, &r);
1013 if (!NT_STATUS_IS_OK(status)) {
1014 printf("DeleteObject failed - %s\n", nt_errstr(status));
1022 static bool test_CreateAccount(struct dcerpc_pipe *p,
1023 struct torture_context *tctx,
1024 struct policy_handle *handle)
1027 struct lsa_CreateAccount r;
1028 struct dom_sid2 *newsid;
1029 struct policy_handle acct_handle;
1031 newsid = dom_sid_parse_talloc(tctx, "S-1-5-12349876-4321-2854");
1033 printf("\nTesting CreateAccount\n");
1035 r.in.handle = handle;
1037 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1038 r.out.acct_handle = &acct_handle;
1040 status = dcerpc_lsa_CreateAccount(p, tctx, &r);
1041 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
1042 struct lsa_OpenAccount r_o;
1043 r_o.in.handle = handle;
1044 r_o.in.sid = newsid;
1045 r_o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1046 r_o.out.acct_handle = &acct_handle;
1048 status = dcerpc_lsa_OpenAccount(p, tctx, &r_o);
1049 if (!NT_STATUS_IS_OK(status)) {
1050 printf("OpenAccount failed - %s\n", nt_errstr(status));
1053 } else if (!NT_STATUS_IS_OK(status)) {
1054 printf("CreateAccount failed - %s\n", nt_errstr(status));
1058 if (!test_Delete(p, tctx, &acct_handle)) {
1062 if (!test_DeleteObject(p, tctx, &acct_handle)) {
1069 static bool test_DeleteTrustedDomain(struct dcerpc_pipe *p,
1070 struct torture_context *tctx,
1071 struct policy_handle *handle,
1072 struct lsa_StringLarge name)
1075 struct lsa_OpenTrustedDomainByName r;
1076 struct policy_handle trustdom_handle;
1078 r.in.handle = handle;
1079 r.in.name.string = name.string;
1080 r.in.access_mask = SEC_STD_DELETE;
1081 r.out.trustdom_handle = &trustdom_handle;
1083 status = dcerpc_lsa_OpenTrustedDomainByName(p, tctx, &r);
1084 if (!NT_STATUS_IS_OK(status)) {
1085 printf("OpenTrustedDomainByName failed - %s\n", nt_errstr(status));
1089 if (!test_Delete(p, tctx, &trustdom_handle)) {
1093 if (!test_DeleteObject(p, tctx, &trustdom_handle)) {
1100 static bool test_DeleteTrustedDomainBySid(struct dcerpc_pipe *p,
1101 struct torture_context *tctx,
1102 struct policy_handle *handle,
1103 struct dom_sid *sid)
1106 struct lsa_DeleteTrustedDomain r;
1108 r.in.handle = handle;
1111 status = dcerpc_lsa_DeleteTrustedDomain(p, tctx, &r);
1112 if (!NT_STATUS_IS_OK(status)) {
1113 printf("DeleteTrustedDomain failed - %s\n", nt_errstr(status));
1121 static bool test_CreateSecret(struct dcerpc_pipe *p,
1122 struct torture_context *tctx,
1123 struct policy_handle *handle)
1126 struct lsa_CreateSecret r;
1127 struct lsa_OpenSecret r2;
1128 struct lsa_SetSecret r3;
1129 struct lsa_QuerySecret r4;
1130 struct lsa_SetSecret r5;
1131 struct lsa_QuerySecret r6;
1132 struct lsa_SetSecret r7;
1133 struct lsa_QuerySecret r8;
1134 struct policy_handle sec_handle, sec_handle2, sec_handle3;
1135 struct lsa_DeleteObject d_o;
1136 struct lsa_DATA_BUF buf1;
1137 struct lsa_DATA_BUF_PTR bufp1;
1138 struct lsa_DATA_BUF_PTR bufp2;
1141 DATA_BLOB session_key;
1142 NTTIME old_mtime, new_mtime;
1143 DATA_BLOB blob1, blob2;
1144 const char *secret1 = "abcdef12345699qwerty";
1146 const char *secret3 = "ABCDEF12345699QWERTY";
1148 const char *secret5 = "NEW-SAMBA4-SECRET";
1152 const int LOCAL = 0;
1153 const int GLOBAL = 1;
1155 secname[LOCAL] = talloc_asprintf(tctx, "torturesecret-%u", (uint_t)random());
1156 secname[GLOBAL] = talloc_asprintf(tctx, "G$torturesecret-%u", (uint_t)random());
1158 for (i=0; i< 2; i++) {
1159 printf("\nTesting CreateSecret of %s\n", secname[i]);
1161 init_lsa_String(&r.in.name, secname[i]);
1163 r.in.handle = handle;
1164 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1165 r.out.sec_handle = &sec_handle;
1167 status = dcerpc_lsa_CreateSecret(p, tctx, &r);
1168 if (!NT_STATUS_IS_OK(status)) {
1169 printf("CreateSecret failed - %s\n", nt_errstr(status));
1173 r.in.handle = handle;
1174 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1175 r.out.sec_handle = &sec_handle3;
1177 status = dcerpc_lsa_CreateSecret(p, tctx, &r);
1178 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
1179 printf("CreateSecret should have failed OBJECT_NAME_COLLISION - %s\n", nt_errstr(status));
1183 r2.in.handle = handle;
1184 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1185 r2.in.name = r.in.name;
1186 r2.out.sec_handle = &sec_handle2;
1188 printf("Testing OpenSecret\n");
1190 status = dcerpc_lsa_OpenSecret(p, tctx, &r2);
1191 if (!NT_STATUS_IS_OK(status)) {
1192 printf("OpenSecret failed - %s\n", nt_errstr(status));
1196 status = dcerpc_fetch_session_key(p, &session_key);
1197 if (!NT_STATUS_IS_OK(status)) {
1198 printf("dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
1202 enc_key = sess_encrypt_string(secret1, &session_key);
1204 r3.in.sec_handle = &sec_handle;
1205 r3.in.new_val = &buf1;
1206 r3.in.old_val = NULL;
1207 r3.in.new_val->data = enc_key.data;
1208 r3.in.new_val->length = enc_key.length;
1209 r3.in.new_val->size = enc_key.length;
1211 printf("Testing SetSecret\n");
1213 status = dcerpc_lsa_SetSecret(p, tctx, &r3);
1214 if (!NT_STATUS_IS_OK(status)) {
1215 printf("SetSecret failed - %s\n", nt_errstr(status));
1219 r3.in.sec_handle = &sec_handle;
1220 r3.in.new_val = &buf1;
1221 r3.in.old_val = NULL;
1222 r3.in.new_val->data = enc_key.data;
1223 r3.in.new_val->length = enc_key.length;
1224 r3.in.new_val->size = enc_key.length;
1226 /* break the encrypted data */
1229 printf("Testing SetSecret with broken key\n");
1231 status = dcerpc_lsa_SetSecret(p, tctx, &r3);
1232 if (!NT_STATUS_EQUAL(status, NT_STATUS_UNKNOWN_REVISION)) {
1233 printf("SetSecret should have failed UNKNOWN_REVISION - %s\n", nt_errstr(status));
1237 data_blob_free(&enc_key);
1239 ZERO_STRUCT(new_mtime);
1240 ZERO_STRUCT(old_mtime);
1242 /* fetch the secret back again */
1243 r4.in.sec_handle = &sec_handle;
1244 r4.in.new_val = &bufp1;
1245 r4.in.new_mtime = &new_mtime;
1246 r4.in.old_val = NULL;
1247 r4.in.old_mtime = NULL;
1251 printf("Testing QuerySecret\n");
1252 status = dcerpc_lsa_QuerySecret(p, tctx, &r4);
1253 if (!NT_STATUS_IS_OK(status)) {
1254 printf("QuerySecret failed - %s\n", nt_errstr(status));
1257 if (r4.out.new_val == NULL || r4.out.new_val->buf == NULL) {
1258 printf("No secret buffer returned\n");
1261 blob1.data = r4.out.new_val->buf->data;
1262 blob1.length = r4.out.new_val->buf->size;
1264 blob2 = data_blob_talloc(tctx, NULL, blob1.length);
1266 secret2 = sess_decrypt_string(tctx,
1267 &blob1, &session_key);
1269 if (strcmp(secret1, secret2) != 0) {
1270 printf("Returned secret (r4) '%s' doesn't match '%s'\n",
1277 enc_key = sess_encrypt_string(secret3, &session_key);
1279 r5.in.sec_handle = &sec_handle;
1280 r5.in.new_val = &buf1;
1281 r5.in.old_val = NULL;
1282 r5.in.new_val->data = enc_key.data;
1283 r5.in.new_val->length = enc_key.length;
1284 r5.in.new_val->size = enc_key.length;
1288 printf("Testing SetSecret (existing value should move to old)\n");
1290 status = dcerpc_lsa_SetSecret(p, tctx, &r5);
1291 if (!NT_STATUS_IS_OK(status)) {
1292 printf("SetSecret failed - %s\n", nt_errstr(status));
1296 data_blob_free(&enc_key);
1298 ZERO_STRUCT(new_mtime);
1299 ZERO_STRUCT(old_mtime);
1301 /* fetch the secret back again */
1302 r6.in.sec_handle = &sec_handle;
1303 r6.in.new_val = &bufp1;
1304 r6.in.new_mtime = &new_mtime;
1305 r6.in.old_val = &bufp2;
1306 r6.in.old_mtime = &old_mtime;
1311 status = dcerpc_lsa_QuerySecret(p, tctx, &r6);
1312 if (!NT_STATUS_IS_OK(status)) {
1313 printf("QuerySecret failed - %s\n", nt_errstr(status));
1318 if (r6.out.new_val->buf == NULL || r6.out.old_val->buf == NULL
1319 || r6.out.new_mtime == NULL || r6.out.old_mtime == NULL) {
1320 printf("Both secret buffers and both times not returned\n");
1324 blob1.data = r6.out.new_val->buf->data;
1325 blob1.length = r6.out.new_val->buf->size;
1327 blob2 = data_blob_talloc(tctx, NULL, blob1.length);
1329 secret4 = sess_decrypt_string(tctx,
1330 &blob1, &session_key);
1332 if (strcmp(secret3, secret4) != 0) {
1333 printf("Returned NEW secret %s doesn't match %s\n", secret4, secret3);
1337 blob1.data = r6.out.old_val->buf->data;
1338 blob1.length = r6.out.old_val->buf->length;
1340 blob2 = data_blob_talloc(tctx, NULL, blob1.length);
1342 secret2 = sess_decrypt_string(tctx,
1343 &blob1, &session_key);
1345 if (strcmp(secret1, secret2) != 0) {
1346 printf("Returned OLD secret %s doesn't match %s\n", secret2, secret1);
1350 if (*r6.out.new_mtime == *r6.out.old_mtime) {
1351 printf("Returned secret (r6-%d) %s must not have same mtime for both secrets: %s != %s\n",
1354 nt_time_string(tctx, *r6.out.old_mtime),
1355 nt_time_string(tctx, *r6.out.new_mtime));
1361 enc_key = sess_encrypt_string(secret5, &session_key);
1363 r7.in.sec_handle = &sec_handle;
1364 r7.in.old_val = &buf1;
1365 r7.in.old_val->data = enc_key.data;
1366 r7.in.old_val->length = enc_key.length;
1367 r7.in.old_val->size = enc_key.length;
1368 r7.in.new_val = NULL;
1370 printf("Testing SetSecret of old Secret only\n");
1372 status = dcerpc_lsa_SetSecret(p, tctx, &r7);
1373 if (!NT_STATUS_IS_OK(status)) {
1374 printf("SetSecret failed - %s\n", nt_errstr(status));
1378 data_blob_free(&enc_key);
1380 /* fetch the secret back again */
1381 r8.in.sec_handle = &sec_handle;
1382 r8.in.new_val = &bufp1;
1383 r8.in.new_mtime = &new_mtime;
1384 r8.in.old_val = &bufp2;
1385 r8.in.old_mtime = &old_mtime;
1390 status = dcerpc_lsa_QuerySecret(p, tctx, &r8);
1391 if (!NT_STATUS_IS_OK(status)) {
1392 printf("QuerySecret failed - %s\n", nt_errstr(status));
1395 if (!r8.out.new_val || !r8.out.old_val) {
1396 printf("in/out pointers not returned, despite being set on in for QuerySecret\n");
1398 } else if (r8.out.new_val->buf != NULL) {
1399 printf("NEW secret buffer must not be returned after OLD set\n");
1401 } else if (r8.out.old_val->buf == NULL) {
1402 printf("OLD secret buffer was not returned after OLD set\n");
1404 } else if (r8.out.new_mtime == NULL || r8.out.old_mtime == NULL) {
1405 printf("Both times not returned after OLD set\n");
1408 blob1.data = r8.out.old_val->buf->data;
1409 blob1.length = r8.out.old_val->buf->size;
1411 blob2 = data_blob_talloc(tctx, NULL, blob1.length);
1413 secret6 = sess_decrypt_string(tctx,
1414 &blob1, &session_key);
1416 if (strcmp(secret5, secret6) != 0) {
1417 printf("Returned OLD secret %s doesn't match %s\n", secret5, secret6);
1421 if (*r8.out.new_mtime != *r8.out.old_mtime) {
1422 printf("Returned secret (r8) %s did not had same mtime for both secrets: %s != %s\n",
1424 nt_time_string(tctx, *r8.out.old_mtime),
1425 nt_time_string(tctx, *r8.out.new_mtime));
1431 if (!test_Delete(p, tctx, &sec_handle)) {
1435 if (!test_DeleteObject(p, tctx, &sec_handle)) {
1439 d_o.in.handle = &sec_handle2;
1440 d_o.out.handle = &sec_handle2;
1441 status = dcerpc_lsa_DeleteObject(p, tctx, &d_o);
1442 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1443 printf("Second delete expected INVALID_HANDLE - %s\n", nt_errstr(status));
1447 printf("Testing OpenSecret of just-deleted secret\n");
1449 status = dcerpc_lsa_OpenSecret(p, tctx, &r2);
1450 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
1451 printf("OpenSecret expected OBJECT_NAME_NOT_FOUND - %s\n", nt_errstr(status));
1462 static bool test_EnumAccountRights(struct dcerpc_pipe *p,
1463 struct torture_context *tctx,
1464 struct policy_handle *acct_handle,
1465 struct dom_sid *sid)
1468 struct lsa_EnumAccountRights r;
1469 struct lsa_RightSet rights;
1471 printf("\nTesting EnumAccountRights\n");
1473 r.in.handle = acct_handle;
1475 r.out.rights = &rights;
1477 status = dcerpc_lsa_EnumAccountRights(p, tctx, &r);
1478 if (!NT_STATUS_IS_OK(status)) {
1479 printf("EnumAccountRights of %s failed - %s\n",
1480 dom_sid_string(tctx, sid), nt_errstr(status));
1488 static bool test_QuerySecurity(struct dcerpc_pipe *p,
1489 struct torture_context *tctx,
1490 struct policy_handle *handle,
1491 struct policy_handle *acct_handle)
1494 struct lsa_QuerySecurity r;
1495 struct sec_desc_buf *sdbuf = NULL;
1497 if (torture_setting_bool(tctx, "samba4", false)) {
1498 printf("\nskipping QuerySecurity test against Samba4\n");
1502 printf("\nTesting QuerySecurity\n");
1504 r.in.handle = acct_handle;
1506 r.out.sdbuf = &sdbuf;
1508 status = dcerpc_lsa_QuerySecurity(p, tctx, &r);
1509 if (!NT_STATUS_IS_OK(status)) {
1510 printf("QuerySecurity failed - %s\n", nt_errstr(status));
1517 static bool test_OpenAccount(struct dcerpc_pipe *p,
1518 struct torture_context *tctx,
1519 struct policy_handle *handle,
1520 struct dom_sid *sid)
1523 struct lsa_OpenAccount r;
1524 struct policy_handle acct_handle;
1526 printf("\nTesting OpenAccount\n");
1528 r.in.handle = handle;
1530 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1531 r.out.acct_handle = &acct_handle;
1533 status = dcerpc_lsa_OpenAccount(p, tctx, &r);
1534 if (!NT_STATUS_IS_OK(status)) {
1535 printf("OpenAccount failed - %s\n", nt_errstr(status));
1539 if (!test_EnumPrivsAccount(p, tctx, handle, &acct_handle)) {
1543 if (!test_GetSystemAccessAccount(p, tctx, handle, &acct_handle)) {
1547 if (!test_QuerySecurity(p, tctx, handle, &acct_handle)) {
1554 static bool test_EnumAccounts(struct dcerpc_pipe *p,
1555 struct torture_context *tctx,
1556 struct policy_handle *handle)
1559 struct lsa_EnumAccounts r;
1560 struct lsa_SidArray sids1, sids2;
1561 uint32_t resume_handle = 0;
1565 printf("\nTesting EnumAccounts\n");
1567 r.in.handle = handle;
1568 r.in.resume_handle = &resume_handle;
1569 r.in.num_entries = 100;
1570 r.out.resume_handle = &resume_handle;
1571 r.out.sids = &sids1;
1575 status = dcerpc_lsa_EnumAccounts(p, tctx, &r);
1576 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
1579 if (!NT_STATUS_IS_OK(status)) {
1580 printf("EnumAccounts failed - %s\n", nt_errstr(status));
1584 if (!test_LookupSids(p, tctx, handle, &sids1)) {
1588 if (!test_LookupSids2(p, tctx, handle, &sids1)) {
1592 /* Can't test lookupSids3 here, as clearly we must not
1593 * be on schannel, or we would not be able to do the
1596 printf("Testing all accounts\n");
1597 for (i=0;i<sids1.num_sids;i++) {
1598 ret &= test_OpenAccount(p, tctx, handle, sids1.sids[i].sid);
1599 ret &= test_EnumAccountRights(p, tctx, handle, sids1.sids[i].sid);
1604 if (sids1.num_sids < 3) {
1608 printf("Trying EnumAccounts partial listing (asking for 1 at 2)\n");
1610 r.in.num_entries = 1;
1611 r.out.sids = &sids2;
1613 status = dcerpc_lsa_EnumAccounts(p, tctx, &r);
1614 if (!NT_STATUS_IS_OK(status)) {
1615 printf("EnumAccounts failed - %s\n", nt_errstr(status));
1619 if (sids2.num_sids != 1) {
1620 printf("Returned wrong number of entries (%d)\n", sids2.num_sids);
1627 static bool test_LookupPrivDisplayName(struct dcerpc_pipe *p,
1628 struct torture_context *tctx,
1629 struct policy_handle *handle,
1630 struct lsa_String *priv_name)
1632 struct lsa_LookupPrivDisplayName r;
1634 /* produce a reasonable range of language output without screwing up
1636 uint16_t language_id = (random() % 4) + 0x409;
1637 uint16_t returned_language_id = 0;
1638 struct lsa_StringLarge *disp_name = NULL;
1640 printf("\nTesting LookupPrivDisplayName(%s)\n", priv_name->string);
1642 r.in.handle = handle;
1643 r.in.name = priv_name;
1644 r.in.language_id = language_id;
1645 r.in.language_id_sys = 0;
1646 r.out.returned_language_id = &returned_language_id;
1647 r.out.disp_name = &disp_name;
1649 status = dcerpc_lsa_LookupPrivDisplayName(p, tctx, &r);
1650 if (!NT_STATUS_IS_OK(status)) {
1651 printf("LookupPrivDisplayName failed - %s\n", nt_errstr(status));
1654 printf("%s -> \"%s\" (language 0x%x/0x%x)\n",
1655 priv_name->string, disp_name->string,
1656 r.in.language_id, *r.out.returned_language_id);
1661 static bool test_EnumAccountsWithUserRight(struct dcerpc_pipe *p,
1662 struct torture_context *tctx,
1663 struct policy_handle *handle,
1664 struct lsa_String *priv_name)
1666 struct lsa_EnumAccountsWithUserRight r;
1667 struct lsa_SidArray sids;
1672 printf("\nTesting EnumAccountsWithUserRight(%s)\n", priv_name->string);
1674 r.in.handle = handle;
1675 r.in.name = priv_name;
1678 status = dcerpc_lsa_EnumAccountsWithUserRight(p, tctx, &r);
1680 /* NT_STATUS_NO_MORE_ENTRIES means noone has this privilege */
1681 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
1685 if (!NT_STATUS_IS_OK(status)) {
1686 printf("EnumAccountsWithUserRight failed - %s\n", nt_errstr(status));
1694 static bool test_EnumPrivs(struct dcerpc_pipe *p,
1695 struct torture_context *tctx,
1696 struct policy_handle *handle)
1699 struct lsa_EnumPrivs r;
1700 struct lsa_PrivArray privs1;
1701 uint32_t resume_handle = 0;
1705 printf("\nTesting EnumPrivs\n");
1707 r.in.handle = handle;
1708 r.in.resume_handle = &resume_handle;
1709 r.in.max_count = 100;
1710 r.out.resume_handle = &resume_handle;
1711 r.out.privs = &privs1;
1714 status = dcerpc_lsa_EnumPrivs(p, tctx, &r);
1715 if (!NT_STATUS_IS_OK(status)) {
1716 printf("EnumPrivs failed - %s\n", nt_errstr(status));
1720 for (i = 0; i< privs1.count; i++) {
1721 test_LookupPrivDisplayName(p, tctx, handle, (struct lsa_String *)&privs1.privs[i].name);
1722 test_LookupPrivValue(p, tctx, handle, (struct lsa_String *)&privs1.privs[i].name);
1723 if (!test_EnumAccountsWithUserRight(p, tctx, handle, (struct lsa_String *)&privs1.privs[i].name)) {
1731 static bool test_QueryForestTrustInformation(struct dcerpc_pipe *p,
1732 struct torture_context *tctx,
1733 struct policy_handle *handle,
1734 const char *trusted_domain_name)
1737 struct lsa_lsaRQueryForestTrustInformation r;
1739 struct lsa_String string;
1740 struct lsa_ForestTrustInformation info, *info_ptr;
1742 printf("\nTesting lsaRQueryForestTrustInformation\n");
1744 if (torture_setting_bool(tctx, "samba4", false)) {
1745 printf("skipping QueryForestTrustInformation against Samba4\n");
1749 ZERO_STRUCT(string);
1751 if (trusted_domain_name) {
1752 init_lsa_String(&string, trusted_domain_name);
1757 r.in.handle = handle;
1758 r.in.trusted_domain_name = &string;
1760 r.out.forest_trust_info = &info_ptr;
1762 status = dcerpc_lsa_lsaRQueryForestTrustInformation(p, tctx, &r);
1764 if (!NT_STATUS_IS_OK(status)) {
1765 printf("lsaRQueryForestTrustInformation of %s failed - %s\n", trusted_domain_name, nt_errstr(status));
1772 static bool test_query_each_TrustDomEx(struct dcerpc_pipe *p,
1773 struct torture_context *tctx,
1774 struct policy_handle *handle,
1775 struct lsa_DomainListEx *domains)
1780 for (i=0; i< domains->count; i++) {
1782 if (domains->domains[i].trust_attributes & NETR_TRUST_ATTRIBUTE_FOREST_TRANSITIVE) {
1783 ret &= test_QueryForestTrustInformation(p, tctx, handle,
1784 domains->domains[i].domain_name.string);
1791 static bool test_query_each_TrustDom(struct dcerpc_pipe *p,
1792 struct torture_context *tctx,
1793 struct policy_handle *handle,
1794 struct lsa_DomainList *domains)
1800 printf("\nTesting OpenTrustedDomain, OpenTrustedDomainByName and QueryInfoTrustedDomain\n");
1801 for (i=0; i< domains->count; i++) {
1802 struct lsa_OpenTrustedDomain trust;
1803 struct lsa_OpenTrustedDomainByName trust_by_name;
1804 struct policy_handle trustdom_handle;
1805 struct policy_handle handle2;
1807 struct lsa_CloseTrustedDomainEx c_trust;
1808 int levels [] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
1809 int ok[] = {1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1};
1811 if (domains->domains[i].sid) {
1812 trust.in.handle = handle;
1813 trust.in.sid = domains->domains[i].sid;
1814 trust.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1815 trust.out.trustdom_handle = &trustdom_handle;
1817 status = dcerpc_lsa_OpenTrustedDomain(p, tctx, &trust);
1819 if (!NT_STATUS_IS_OK(status)) {
1820 printf("OpenTrustedDomain failed - %s\n", nt_errstr(status));
1824 c.in.handle = &trustdom_handle;
1825 c.out.handle = &handle2;
1827 c_trust.in.handle = &trustdom_handle;
1828 c_trust.out.handle = &handle2;
1830 for (j=0; j < ARRAY_SIZE(levels); j++) {
1831 struct lsa_QueryTrustedDomainInfo q;
1832 union lsa_TrustedDomainInfo *info = NULL;
1833 q.in.trustdom_handle = &trustdom_handle;
1834 q.in.level = levels[j];
1836 status = dcerpc_lsa_QueryTrustedDomainInfo(p, tctx, &q);
1837 if (!NT_STATUS_IS_OK(status) && ok[j]) {
1838 printf("QueryTrustedDomainInfo level %d failed - %s\n",
1839 levels[j], nt_errstr(status));
1841 } else if (NT_STATUS_IS_OK(status) && !ok[j]) {
1842 printf("QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
1843 levels[j], nt_errstr(status));
1848 status = dcerpc_lsa_CloseTrustedDomainEx(p, tctx, &c_trust);
1849 if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED)) {
1850 printf("Expected CloseTrustedDomainEx to return NT_STATUS_NOT_IMPLEMENTED, instead - %s\n", nt_errstr(status));
1854 c.in.handle = &trustdom_handle;
1855 c.out.handle = &handle2;
1857 status = dcerpc_lsa_Close(p, tctx, &c);
1858 if (!NT_STATUS_IS_OK(status)) {
1859 printf("Close of trusted domain failed - %s\n", nt_errstr(status));
1863 for (j=0; j < ARRAY_SIZE(levels); j++) {
1864 struct lsa_QueryTrustedDomainInfoBySid q;
1865 union lsa_TrustedDomainInfo *info = NULL;
1867 if (!domains->domains[i].sid) {
1871 q.in.handle = handle;
1872 q.in.dom_sid = domains->domains[i].sid;
1873 q.in.level = levels[j];
1876 status = dcerpc_lsa_QueryTrustedDomainInfoBySid(p, tctx, &q);
1877 if (!NT_STATUS_IS_OK(status) && ok[j]) {
1878 printf("QueryTrustedDomainInfoBySid level %d failed - %s\n",
1879 levels[j], nt_errstr(status));
1881 } else if (NT_STATUS_IS_OK(status) && !ok[j]) {
1882 printf("QueryTrustedDomainInfoBySid level %d unexpectedly succeeded - %s\n",
1883 levels[j], nt_errstr(status));
1889 trust_by_name.in.handle = handle;
1890 trust_by_name.in.name.string = domains->domains[i].name.string;
1891 trust_by_name.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1892 trust_by_name.out.trustdom_handle = &trustdom_handle;
1894 status = dcerpc_lsa_OpenTrustedDomainByName(p, tctx, &trust_by_name);
1896 if (!NT_STATUS_IS_OK(status)) {
1897 printf("OpenTrustedDomainByName failed - %s\n", nt_errstr(status));
1901 for (j=0; j < ARRAY_SIZE(levels); j++) {
1902 struct lsa_QueryTrustedDomainInfo q;
1903 union lsa_TrustedDomainInfo *info = NULL;
1904 q.in.trustdom_handle = &trustdom_handle;
1905 q.in.level = levels[j];
1907 status = dcerpc_lsa_QueryTrustedDomainInfo(p, tctx, &q);
1908 if (!NT_STATUS_IS_OK(status) && ok[j]) {
1909 printf("QueryTrustedDomainInfo level %d failed - %s\n",
1910 levels[j], nt_errstr(status));
1912 } else if (NT_STATUS_IS_OK(status) && !ok[j]) {
1913 printf("QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
1914 levels[j], nt_errstr(status));
1919 c.in.handle = &trustdom_handle;
1920 c.out.handle = &handle2;
1922 status = dcerpc_lsa_Close(p, tctx, &c);
1923 if (!NT_STATUS_IS_OK(status)) {
1924 printf("Close of trusted domain failed - %s\n", nt_errstr(status));
1928 for (j=0; j < ARRAY_SIZE(levels); j++) {
1929 struct lsa_QueryTrustedDomainInfoByName q;
1930 union lsa_TrustedDomainInfo *info = NULL;
1931 struct lsa_String name;
1933 name.string = domains->domains[i].name.string;
1935 q.in.handle = handle;
1936 q.in.trusted_domain = &name;
1937 q.in.level = levels[j];
1939 status = dcerpc_lsa_QueryTrustedDomainInfoByName(p, tctx, &q);
1940 if (!NT_STATUS_IS_OK(status) && ok[j]) {
1941 printf("QueryTrustedDomainInfoByName level %d failed - %s\n",
1942 levels[j], nt_errstr(status));
1944 } else if (NT_STATUS_IS_OK(status) && !ok[j]) {
1945 printf("QueryTrustedDomainInfoByName level %d unexpectedly succeeded - %s\n",
1946 levels[j], nt_errstr(status));
1954 static bool test_EnumTrustDom(struct dcerpc_pipe *p,
1955 struct torture_context *tctx,
1956 struct policy_handle *handle)
1958 struct lsa_EnumTrustDom r;
1959 struct lsa_EnumTrustedDomainsEx r_ex;
1960 NTSTATUS enum_status;
1961 uint32_t resume_handle = 0;
1962 struct lsa_DomainList domains;
1963 struct lsa_DomainListEx domains_ex;
1966 printf("\nTesting EnumTrustDom\n");
1968 r.in.handle = handle;
1969 r.in.resume_handle = &resume_handle;
1971 r.out.domains = &domains;
1972 r.out.resume_handle = &resume_handle;
1974 enum_status = dcerpc_lsa_EnumTrustDom(p, tctx, &r);
1976 if (NT_STATUS_IS_OK(enum_status)) {
1977 if (domains.count == 0) {
1978 printf("EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
1981 } else if (!(NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES) || NT_STATUS_EQUAL(enum_status, NT_STATUS_NO_MORE_ENTRIES))) {
1982 printf("EnumTrustDom of zero size failed - %s\n", nt_errstr(enum_status));
1986 /* Start from the bottom again */
1990 r.in.handle = handle;
1991 r.in.resume_handle = &resume_handle;
1992 r.in.max_size = LSA_ENUM_TRUST_DOMAIN_MULTIPLIER * 3;
1993 r.out.domains = &domains;
1994 r.out.resume_handle = &resume_handle;
1996 enum_status = dcerpc_lsa_EnumTrustDom(p, tctx, &r);
1998 /* NO_MORE_ENTRIES is allowed */
1999 if (NT_STATUS_EQUAL(enum_status, NT_STATUS_NO_MORE_ENTRIES)) {
2000 if (domains.count == 0) {
2003 printf("EnumTrustDom failed - should have returned 0 trusted domains with 'NT_STATUS_NO_MORE_ENTRIES'\n");
2005 } else if (NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES)) {
2006 /* Windows 2003 gets this off by one on the first run */
2007 if (r.out.domains->count < 3 || r.out.domains->count > 4) {
2008 printf("EnumTrustDom didn't fill the buffer we "
2009 "asked it to (got %d, expected %d / %d == %d entries)\n",
2010 r.out.domains->count, LSA_ENUM_TRUST_DOMAIN_MULTIPLIER * 3,
2011 LSA_ENUM_TRUST_DOMAIN_MULTIPLIER, r.in.max_size);
2014 } else if (!NT_STATUS_IS_OK(enum_status)) {
2015 printf("EnumTrustDom failed - %s\n", nt_errstr(enum_status));
2019 if (domains.count == 0) {
2020 printf("EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2024 ret &= test_query_each_TrustDom(p, tctx, handle, &domains);
2026 } while ((NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES)));
2028 printf("\nTesting EnumTrustedDomainsEx\n");
2030 r_ex.in.handle = handle;
2031 r_ex.in.resume_handle = &resume_handle;
2032 r_ex.in.max_size = LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER * 3;
2033 r_ex.out.domains = &domains_ex;
2034 r_ex.out.resume_handle = &resume_handle;
2036 enum_status = dcerpc_lsa_EnumTrustedDomainsEx(p, tctx, &r_ex);
2038 if (!(NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES) || NT_STATUS_EQUAL(enum_status, NT_STATUS_NO_MORE_ENTRIES))) {
2039 printf("EnumTrustedDomainEx of zero size failed - %s\n", nt_errstr(enum_status));
2045 r_ex.in.handle = handle;
2046 r_ex.in.resume_handle = &resume_handle;
2047 r_ex.in.max_size = LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER * 3;
2048 r_ex.out.domains = &domains_ex;
2049 r_ex.out.resume_handle = &resume_handle;
2051 enum_status = dcerpc_lsa_EnumTrustedDomainsEx(p, tctx, &r_ex);
2053 /* NO_MORE_ENTRIES is allowed */
2054 if (NT_STATUS_EQUAL(enum_status, NT_STATUS_NO_MORE_ENTRIES)) {
2055 if (domains_ex.count == 0) {
2058 printf("EnumTrustDomainsEx failed - should have returned 0 trusted domains with 'NT_STATUS_NO_MORE_ENTRIES'\n");
2060 } else if (NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES)) {
2061 /* Windows 2003 gets this off by one on the first run */
2062 if (r_ex.out.domains->count < 3 || r_ex.out.domains->count > 4) {
2063 printf("EnumTrustDom didn't fill the buffer we "
2064 "asked it to (got %d, expected %d / %d == %d entries)\n",
2065 r_ex.out.domains->count,
2067 LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER,
2068 r_ex.in.max_size / LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER);
2070 } else if (!NT_STATUS_IS_OK(enum_status)) {
2071 printf("EnumTrustedDomainEx failed - %s\n", nt_errstr(enum_status));
2075 if (domains_ex.count == 0) {
2076 printf("EnumTrustDomainEx failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
2080 ret &= test_query_each_TrustDomEx(p, tctx, handle, &domains_ex);
2082 } while ((NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES)));
2087 static bool test_CreateTrustedDomain(struct dcerpc_pipe *p,
2088 struct torture_context *tctx,
2089 struct policy_handle *handle)
2093 struct lsa_CreateTrustedDomain r;
2094 struct lsa_DomainInfo trustinfo;
2095 struct dom_sid *domsid[12];
2096 struct policy_handle trustdom_handle[12];
2097 struct lsa_QueryTrustedDomainInfo q;
2098 union lsa_TrustedDomainInfo *info = NULL;
2101 printf("\nTesting CreateTrustedDomain for 12 domains\n");
2103 if (!test_EnumTrustDom(p, tctx, handle)) {
2107 for (i=0; i< 12; i++) {
2108 char *trust_name = talloc_asprintf(tctx, "torturedom%02d", i);
2109 char *trust_sid = talloc_asprintf(tctx, "S-1-5-21-97398-379795-100%02d", i);
2111 domsid[i] = dom_sid_parse_talloc(tctx, trust_sid);
2113 trustinfo.sid = domsid[i];
2114 init_lsa_String((struct lsa_String *)&trustinfo.name, trust_name);
2116 r.in.policy_handle = handle;
2117 r.in.info = &trustinfo;
2118 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2119 r.out.trustdom_handle = &trustdom_handle[i];
2121 status = dcerpc_lsa_CreateTrustedDomain(p, tctx, &r);
2122 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
2123 test_DeleteTrustedDomain(p, tctx, handle, trustinfo.name);
2124 status = dcerpc_lsa_CreateTrustedDomain(p, tctx, &r);
2126 if (!NT_STATUS_IS_OK(status)) {
2127 printf("CreateTrustedDomain failed - %s\n", nt_errstr(status));
2131 q.in.trustdom_handle = &trustdom_handle[i];
2132 q.in.level = LSA_TRUSTED_DOMAIN_INFO_INFO_EX;
2134 status = dcerpc_lsa_QueryTrustedDomainInfo(p, tctx, &q);
2135 if (!NT_STATUS_IS_OK(status)) {
2136 printf("QueryTrustedDomainInfo level 1 failed - %s\n", nt_errstr(status));
2138 } else if (!q.out.info) {
2141 if (strcmp(info->info_ex.netbios_name.string, trustinfo.name.string) != 0) {
2142 printf("QueryTrustedDomainInfo returned inconsistant short name: %s != %s\n",
2143 info->info_ex.netbios_name.string, trustinfo.name.string);
2146 if (info->info_ex.trust_type != LSA_TRUST_TYPE_DOWNLEVEL) {
2147 printf("QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
2148 trust_name, info->info_ex.trust_type, LSA_TRUST_TYPE_DOWNLEVEL);
2151 if (info->info_ex.trust_attributes != 0) {
2152 printf("QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
2153 trust_name, info->info_ex.trust_attributes, 0);
2156 if (info->info_ex.trust_direction != LSA_TRUST_DIRECTION_OUTBOUND) {
2157 printf("QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
2158 trust_name, info->info_ex.trust_direction, LSA_TRUST_DIRECTION_OUTBOUND);
2165 /* now that we have some domains to look over, we can test the enum calls */
2166 if (!test_EnumTrustDom(p, tctx, handle)) {
2170 for (i=0; i<12; i++) {
2171 if (!test_DeleteTrustedDomainBySid(p, tctx, handle, domsid[i])) {
2179 static bool test_CreateTrustedDomainEx2(struct dcerpc_pipe *p,
2180 struct torture_context *tctx,
2181 struct policy_handle *handle)
2185 struct lsa_CreateTrustedDomainEx2 r;
2186 struct lsa_TrustDomainInfoInfoEx trustinfo;
2187 struct lsa_TrustDomainInfoAuthInfoInternal authinfo;
2188 struct trustDomainPasswords auth_struct;
2189 DATA_BLOB auth_blob;
2190 struct dom_sid *domsid[12];
2191 struct policy_handle trustdom_handle[12];
2192 struct lsa_QueryTrustedDomainInfo q;
2193 union lsa_TrustedDomainInfo *info = NULL;
2194 DATA_BLOB session_key;
2195 enum ndr_err_code ndr_err;
2198 printf("\nTesting CreateTrustedDomainEx2 for 12 domains\n");
2200 status = dcerpc_fetch_session_key(p, &session_key);
2201 if (!NT_STATUS_IS_OK(status)) {
2202 printf("dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
2206 for (i=0; i< 12; i++) {
2207 char *trust_name = talloc_asprintf(tctx, "torturedom%02d", i);
2208 char *trust_name_dns = talloc_asprintf(tctx, "torturedom%02d.samba.example.com", i);
2209 char *trust_sid = talloc_asprintf(tctx, "S-1-5-21-97398-379795-100%02d", i);
2211 domsid[i] = dom_sid_parse_talloc(tctx, trust_sid);
2213 trustinfo.sid = domsid[i];
2214 trustinfo.netbios_name.string = trust_name;
2215 trustinfo.domain_name.string = trust_name_dns;
2217 /* Create inbound, some outbound, and some
2218 * bi-directional trusts in a repeating pattern based
2221 /* 1 == inbound, 2 == outbound, 3 == both */
2222 trustinfo.trust_direction = (i % 3) + 1;
2224 /* Try different trust types too */
2226 /* 1 == downlevel (NT4), 2 == uplevel (ADS), 3 == MIT (kerberos but not AD) */
2227 trustinfo.trust_type = (((i / 3) + 1) % 3) + 1;
2229 trustinfo.trust_attributes = LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION;
2231 generate_random_buffer(auth_struct.confounder, sizeof(auth_struct.confounder));
2233 auth_struct.outgoing.count = 0;
2234 auth_struct.incoming.count = 0;
2236 ndr_err = ndr_push_struct_blob(&auth_blob, tctx, lp_iconv_convenience(tctx->lp_ctx), &auth_struct,
2237 (ndr_push_flags_fn_t)ndr_push_trustDomainPasswords);
2238 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2239 printf("ndr_push_struct_blob of trustDomainPasswords structure failed");
2243 arcfour_crypt_blob(auth_blob.data, auth_blob.length, &session_key);
2245 authinfo.auth_blob.size = auth_blob.length;
2246 authinfo.auth_blob.data = auth_blob.data;
2248 r.in.policy_handle = handle;
2249 r.in.info = &trustinfo;
2250 r.in.auth_info = &authinfo;
2251 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2252 r.out.trustdom_handle = &trustdom_handle[i];
2254 status = dcerpc_lsa_CreateTrustedDomainEx2(p, tctx, &r);
2255 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
2256 test_DeleteTrustedDomain(p, tctx, handle, trustinfo.netbios_name);
2257 status = dcerpc_lsa_CreateTrustedDomainEx2(p, tctx, &r);
2259 if (!NT_STATUS_IS_OK(status)) {
2260 printf("CreateTrustedDomainEx failed2 - %s\n", nt_errstr(status));
2264 q.in.trustdom_handle = &trustdom_handle[i];
2265 q.in.level = LSA_TRUSTED_DOMAIN_INFO_INFO_EX;
2267 status = dcerpc_lsa_QueryTrustedDomainInfo(p, tctx, &q);
2268 if (!NT_STATUS_IS_OK(status)) {
2269 printf("QueryTrustedDomainInfo level 1 failed - %s\n", nt_errstr(status));
2271 } else if (!q.out.info) {
2272 printf("QueryTrustedDomainInfo level 1 failed to return an info pointer\n");
2275 if (strcmp(info->info_ex.netbios_name.string, trustinfo.netbios_name.string) != 0) {
2276 printf("QueryTrustedDomainInfo returned inconsistant short name: %s != %s\n",
2277 info->info_ex.netbios_name.string, trustinfo.netbios_name.string);
2280 if (info->info_ex.trust_type != trustinfo.trust_type) {
2281 printf("QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
2282 trust_name, info->info_ex.trust_type, trustinfo.trust_type);
2285 if (info->info_ex.trust_attributes != LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION) {
2286 printf("QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
2287 trust_name, info->info_ex.trust_attributes, LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION);
2290 if (info->info_ex.trust_direction != trustinfo.trust_direction) {
2291 printf("QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
2292 trust_name, info->info_ex.trust_direction, trustinfo.trust_direction);
2299 /* now that we have some domains to look over, we can test the enum calls */
2300 if (!test_EnumTrustDom(p, tctx, handle)) {
2301 printf("test_EnumTrustDom failed\n");
2305 for (i=0; i<12; i++) {
2306 if (!test_DeleteTrustedDomainBySid(p, tctx, handle, domsid[i])) {
2307 printf("test_DeleteTrustedDomainBySid failed\n");
2315 static bool test_QueryDomainInfoPolicy(struct dcerpc_pipe *p,
2316 struct torture_context *tctx,
2317 struct policy_handle *handle)
2319 struct lsa_QueryDomainInformationPolicy r;
2320 union lsa_DomainInformationPolicy *info = NULL;
2325 printf("\nTesting QueryDomainInformationPolicy\n");
2328 r.in.handle = handle;
2332 printf("\nTrying QueryDomainInformationPolicy level %d\n", i);
2334 status = dcerpc_lsa_QueryDomainInformationPolicy(p, tctx, &r);
2336 /* If the server does not support EFS, then this is the correct return */
2337 if (i == LSA_DOMAIN_INFO_POLICY_EFS && NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
2339 } else if (!NT_STATUS_IS_OK(status)) {
2340 printf("QueryDomainInformationPolicy failed - %s\n", nt_errstr(status));
2350 static bool test_QueryInfoPolicyCalls( bool version2,
2351 struct dcerpc_pipe *p,
2352 struct torture_context *tctx,
2353 struct policy_handle *handle)
2355 struct lsa_QueryInfoPolicy r;
2356 union lsa_PolicyInformation *info = NULL;
2362 printf("\nTesting QueryInfoPolicy2\n");
2364 printf("\nTesting QueryInfoPolicy\n");
2366 for (i=1;i<=14;i++) {
2367 r.in.handle = handle;
2372 printf("\nTrying QueryInfoPolicy2 level %d\n", i);
2374 printf("\nTrying QueryInfoPolicy level %d\n", i);
2377 /* We can perform the cast, because both types are
2378 structurally equal */
2379 status = dcerpc_lsa_QueryInfoPolicy2(p, tctx,
2380 (struct lsa_QueryInfoPolicy2*) &r);
2382 status = dcerpc_lsa_QueryInfoPolicy(p, tctx, &r);
2385 case LSA_POLICY_INFO_MOD:
2386 case LSA_POLICY_INFO_AUDIT_FULL_SET:
2387 case LSA_POLICY_INFO_AUDIT_FULL_QUERY:
2388 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
2389 printf("Server should have failed level %u: %s\n", i, nt_errstr(status));
2393 case LSA_POLICY_INFO_DOMAIN:
2394 case LSA_POLICY_INFO_ACCOUNT_DOMAIN:
2395 case LSA_POLICY_INFO_L_ACCOUNT_DOMAIN:
2396 case LSA_POLICY_INFO_DNS_INT:
2397 case LSA_POLICY_INFO_DNS:
2398 case LSA_POLICY_INFO_REPLICA:
2399 case LSA_POLICY_INFO_QUOTA:
2400 case LSA_POLICY_INFO_ROLE:
2401 case LSA_POLICY_INFO_AUDIT_LOG:
2402 case LSA_POLICY_INFO_AUDIT_EVENTS:
2403 case LSA_POLICY_INFO_PD:
2404 if (!NT_STATUS_IS_OK(status)) {
2406 printf("QueryInfoPolicy2 failed - %s\n", nt_errstr(status));
2408 printf("QueryInfoPolicy failed - %s\n", nt_errstr(status));
2413 if (torture_setting_bool(tctx, "samba4", false)) {
2414 /* Other levels not implemented yet */
2415 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_INFO_CLASS)) {
2417 printf("QueryInfoPolicy2 failed - %s\n", nt_errstr(status));
2419 printf("QueryInfoPolicy failed - %s\n", nt_errstr(status));
2422 } else if (!NT_STATUS_IS_OK(status)) {
2424 printf("QueryInfoPolicy2 failed - %s\n", nt_errstr(status));
2426 printf("QueryInfoPolicy failed - %s\n", nt_errstr(status));
2432 if (NT_STATUS_IS_OK(status) && (i == LSA_POLICY_INFO_DNS
2433 || i == LSA_POLICY_INFO_DNS_INT)) {
2434 /* Let's look up some of these names */
2436 struct lsa_TransNameArray tnames;
2438 tnames.names = talloc_zero_array(tctx, struct lsa_TranslatedName, tnames.count);
2439 tnames.names[0].name.string = info->dns.name.string;
2440 tnames.names[0].sid_type = SID_NAME_DOMAIN;
2441 tnames.names[1].name.string = info->dns.dns_domain.string;
2442 tnames.names[1].sid_type = SID_NAME_DOMAIN;
2443 tnames.names[2].name.string = talloc_asprintf(tctx, "%s\\", info->dns.name.string);
2444 tnames.names[2].sid_type = SID_NAME_DOMAIN;
2445 tnames.names[3].name.string = talloc_asprintf(tctx, "%s\\", info->dns.dns_domain.string);
2446 tnames.names[3].sid_type = SID_NAME_DOMAIN;
2447 tnames.names[4].name.string = talloc_asprintf(tctx, "%s\\guest", info->dns.name.string);
2448 tnames.names[4].sid_type = SID_NAME_USER;
2449 tnames.names[5].name.string = talloc_asprintf(tctx, "%s\\krbtgt", info->dns.name.string);
2450 tnames.names[5].sid_type = SID_NAME_USER;
2451 tnames.names[6].name.string = talloc_asprintf(tctx, "%s\\guest", info->dns.dns_domain.string);
2452 tnames.names[6].sid_type = SID_NAME_USER;
2453 tnames.names[7].name.string = talloc_asprintf(tctx, "%s\\krbtgt", info->dns.dns_domain.string);
2454 tnames.names[7].sid_type = SID_NAME_USER;
2455 tnames.names[8].name.string = talloc_asprintf(tctx, "krbtgt@%s", info->dns.name.string);
2456 tnames.names[8].sid_type = SID_NAME_USER;
2457 tnames.names[9].name.string = talloc_asprintf(tctx, "krbtgt@%s", info->dns.dns_domain.string);
2458 tnames.names[9].sid_type = SID_NAME_USER;
2459 tnames.names[10].name.string = talloc_asprintf(tctx, "%s\\"TEST_MACHINENAME "$", info->dns.name.string);
2460 tnames.names[10].sid_type = SID_NAME_USER;
2461 tnames.names[11].name.string = talloc_asprintf(tctx, "%s\\"TEST_MACHINENAME "$", info->dns.dns_domain.string);
2462 tnames.names[11].sid_type = SID_NAME_USER;
2463 tnames.names[12].name.string = talloc_asprintf(tctx, TEST_MACHINENAME "$@%s", info->dns.name.string);
2464 tnames.names[12].sid_type = SID_NAME_USER;
2465 tnames.names[13].name.string = talloc_asprintf(tctx, TEST_MACHINENAME "$@%s", info->dns.dns_domain.string);
2466 tnames.names[13].sid_type = SID_NAME_USER;
2467 ret &= test_LookupNames(p, tctx, handle, &tnames);
2475 static bool test_QueryInfoPolicy(struct dcerpc_pipe *p,
2476 struct torture_context *tctx,
2477 struct policy_handle *handle)
2479 return test_QueryInfoPolicyCalls(false, p, tctx, handle);
2482 static bool test_QueryInfoPolicy2(struct dcerpc_pipe *p,
2483 struct torture_context *tctx,
2484 struct policy_handle *handle)
2486 return test_QueryInfoPolicyCalls(true, p, tctx, handle);
2489 static bool test_GetUserName(struct dcerpc_pipe *p,
2490 struct torture_context *tctx)
2492 struct lsa_GetUserName r;
2495 struct lsa_String *authority_name_p = NULL;
2496 struct lsa_String *account_name_p = NULL;
2498 printf("\nTesting GetUserName\n");
2500 r.in.system_name = "\\";
2501 r.in.account_name = &account_name_p;
2502 r.in.authority_name = NULL;
2503 r.out.account_name = &account_name_p;
2505 status = dcerpc_lsa_GetUserName(p, tctx, &r);
2507 if (!NT_STATUS_IS_OK(status)) {
2508 printf("GetUserName failed - %s\n", nt_errstr(status));
2512 account_name_p = NULL;
2513 r.in.account_name = &account_name_p;
2514 r.in.authority_name = &authority_name_p;
2515 r.out.account_name = &account_name_p;
2517 status = dcerpc_lsa_GetUserName(p, tctx, &r);
2519 if (!NT_STATUS_IS_OK(status)) {
2520 printf("GetUserName failed - %s\n", nt_errstr(status));
2527 bool test_lsa_Close(struct dcerpc_pipe *p,
2528 struct torture_context *tctx,
2529 struct policy_handle *handle)
2533 struct policy_handle handle2;
2535 printf("\nTesting Close\n");
2537 r.in.handle = handle;
2538 r.out.handle = &handle2;
2540 status = dcerpc_lsa_Close(p, tctx, &r);
2541 if (!NT_STATUS_IS_OK(status)) {
2542 printf("Close failed - %s\n", nt_errstr(status));
2546 status = dcerpc_lsa_Close(p, tctx, &r);
2547 /* its really a fault - we need a status code for rpc fault */
2548 if (!NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
2549 printf("Close failed - %s\n", nt_errstr(status));
2558 bool torture_rpc_lsa(struct torture_context *tctx)
2561 struct dcerpc_pipe *p;
2563 struct policy_handle *handle;
2564 struct test_join *join = NULL;
2565 struct cli_credentials *machine_creds;
2567 status = torture_rpc_connection(tctx, &p, &ndr_table_lsarpc);
2568 if (!NT_STATUS_IS_OK(status)) {
2572 if (!test_OpenPolicy(p, tctx)) {
2576 if (!test_lsa_OpenPolicy2(p, tctx, &handle)) {
2581 join = torture_join_domain(tctx, TEST_MACHINENAME, ACB_WSTRUST, &machine_creds);
2585 if (!test_LookupNames_wellknown(p, tctx, handle)) {
2589 if (!test_LookupNames_bogus(p, tctx, handle)) {
2593 if (!test_LookupSids_async(p, tctx, handle)) {
2597 if (!test_QueryDomainInfoPolicy(p, tctx, handle)) {
2601 if (!test_CreateAccount(p, tctx, handle)) {
2605 if (!test_CreateSecret(p, tctx, handle)) {
2608 if (!test_CreateTrustedDomain(p, tctx, handle)) {
2612 if (!test_CreateTrustedDomainEx2(p, tctx, handle)) {
2616 if (!test_EnumAccounts(p, tctx, handle)) {
2620 if (!test_EnumPrivs(p, tctx, handle)) {
2624 if (!test_QueryInfoPolicy(p, tctx, handle)) {
2628 if (!test_QueryInfoPolicy2(p, tctx, handle)) {
2632 if (!test_Delete(p, tctx, handle)) {
2636 if (!test_many_LookupSids(p, tctx, handle)) {
2640 if (!test_lsa_Close(p, tctx, handle)) {
2644 torture_leave_domain(tctx, join);
2647 if (!test_many_LookupSids(p, tctx, handle)) {
2652 if (!test_GetUserName(p, tctx)) {
2659 bool torture_rpc_lsa_get_user(struct torture_context *tctx)
2662 struct dcerpc_pipe *p;
2665 status = torture_rpc_connection(tctx, &p, &ndr_table_lsarpc);
2666 if (!NT_STATUS_IS_OK(status)) {
2670 if (!test_GetUserName(p, tctx)) {