2 Unix SMB/CIFS implementation.
3 test suite for lsa rpc operations
5 Copyright (C) Andrew Tridgell 2003
6 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2004-2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "torture/torture.h"
24 #include "librpc/gen_ndr/ndr_lsa_c.h"
25 #include "librpc/gen_ndr/netlogon.h"
26 #include "librpc/gen_ndr/ndr_drsblobs.h"
27 #include "lib/events/events.h"
28 #include "libcli/security/security.h"
29 #include "libcli/auth/libcli_auth.h"
30 #include "torture/rpc/rpc.h"
31 #include "param/param.h"
32 #include "../lib/crypto/crypto.h"
33 #define TEST_MACHINENAME "lsatestmach"
35 static void init_lsa_String(struct lsa_String *name, const char *s)
40 static bool test_OpenPolicy(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
42 struct lsa_ObjectAttribute attr;
43 struct policy_handle handle;
44 struct lsa_QosInfo qos;
45 struct lsa_OpenPolicy r;
47 uint16_t system_name = '\\';
49 printf("\ntesting OpenPolicy\n");
52 qos.impersonation_level = 2;
54 qos.effective_only = 0;
58 attr.object_name = NULL;
63 r.in.system_name = &system_name;
65 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
66 r.out.handle = &handle;
68 status = dcerpc_lsa_OpenPolicy(p, mem_ctx, &r);
69 if (!NT_STATUS_IS_OK(status)) {
70 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
71 NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
72 printf("not considering %s to be an error\n", nt_errstr(status));
75 printf("OpenPolicy failed - %s\n", nt_errstr(status));
83 bool test_lsa_OpenPolicy2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
84 struct policy_handle **handle)
86 struct lsa_ObjectAttribute attr;
87 struct lsa_QosInfo qos;
88 struct lsa_OpenPolicy2 r;
91 printf("\ntesting OpenPolicy2\n");
93 *handle = talloc(mem_ctx, struct policy_handle);
99 qos.impersonation_level = 2;
100 qos.context_mode = 1;
101 qos.effective_only = 0;
104 attr.root_dir = NULL;
105 attr.object_name = NULL;
107 attr.sec_desc = NULL;
110 r.in.system_name = "\\";
112 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
113 r.out.handle = *handle;
115 status = dcerpc_lsa_OpenPolicy2(p, mem_ctx, &r);
116 if (!NT_STATUS_IS_OK(status)) {
117 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
118 NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
119 printf("not considering %s to be an error\n", nt_errstr(status));
120 talloc_free(*handle);
124 printf("OpenPolicy2 failed - %s\n", nt_errstr(status));
132 static const char *sid_type_lookup(enum lsa_SidType r)
135 case SID_NAME_USE_NONE: return "SID_NAME_USE_NONE"; break;
136 case SID_NAME_USER: return "SID_NAME_USER"; break;
137 case SID_NAME_DOM_GRP: return "SID_NAME_DOM_GRP"; break;
138 case SID_NAME_DOMAIN: return "SID_NAME_DOMAIN"; break;
139 case SID_NAME_ALIAS: return "SID_NAME_ALIAS"; break;
140 case SID_NAME_WKN_GRP: return "SID_NAME_WKN_GRP"; break;
141 case SID_NAME_DELETED: return "SID_NAME_DELETED"; break;
142 case SID_NAME_INVALID: return "SID_NAME_INVALID"; break;
143 case SID_NAME_UNKNOWN: return "SID_NAME_UNKNOWN"; break;
144 case SID_NAME_COMPUTER: return "SID_NAME_COMPUTER"; break;
146 return "Invalid sid type\n";
149 static bool test_LookupNames(struct dcerpc_pipe *p,
151 struct policy_handle *handle,
152 struct lsa_TransNameArray *tnames)
154 struct lsa_LookupNames r;
155 struct lsa_TransSidArray sids;
156 struct lsa_String *names;
161 printf("\nTesting LookupNames with %d names\n", tnames->count);
166 names = talloc_array(mem_ctx, struct lsa_String, tnames->count);
167 for (i=0;i<tnames->count;i++) {
168 init_lsa_String(&names[i], tnames->names[i].name.string);
171 r.in.handle = handle;
172 r.in.num_names = tnames->count;
177 r.out.count = &count;
180 status = dcerpc_lsa_LookupNames(p, mem_ctx, &r);
182 if (NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED) ||
183 NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED)) {
184 for (i=0;i< tnames->count;i++) {
185 if (i < count && sids.sids[i].sid_type == SID_NAME_UNKNOWN) {
186 printf("LookupName of %s was unmapped\n",
187 tnames->names[i].name.string);
188 } else if (i >=count) {
189 printf("LookupName of %s failed to return a result\n",
190 tnames->names[i].name.string);
193 printf("LookupNames failed - %s\n", nt_errstr(status));
195 } else if (!NT_STATUS_IS_OK(status)) {
196 printf("LookupNames failed - %s\n", nt_errstr(status));
200 for (i=0;i< tnames->count;i++) {
201 if (i < count && sids.sids[i].sid_type != tnames->names[i].sid_type) {
202 printf("LookupName of %s got unexpected name type: %s\n",
203 tnames->names[i].name.string, sid_type_lookup(sids.sids[i].sid_type));
204 } else if (i >=count) {
205 printf("LookupName of %s failed to return a result\n",
206 tnames->names[i].name.string);
214 static bool test_LookupNames_bogus(struct dcerpc_pipe *p,
216 struct policy_handle *handle)
218 struct lsa_LookupNames r;
219 struct lsa_TransSidArray sids;
220 struct lsa_String *names;
225 struct lsa_TranslatedName name[2];
226 struct lsa_TransNameArray tnames;
230 name[0].name.string = "NT AUTHORITY\\BOGUS";
231 name[1].name.string = NULL;
233 printf("\nTesting LookupNames with bogus names\n");
238 names = talloc_array(mem_ctx, struct lsa_String, tnames.count);
239 for (i=0;i<tnames.count;i++) {
240 init_lsa_String(&names[i], tnames.names[i].name.string);
243 r.in.handle = handle;
244 r.in.num_names = tnames.count;
249 r.out.count = &count;
252 status = dcerpc_lsa_LookupNames(p, mem_ctx, &r);
253 if (!NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED)) {
254 printf("LookupNames failed - %s\n", nt_errstr(status));
263 static bool test_LookupNames_wellknown(struct dcerpc_pipe *p,
265 struct policy_handle *handle)
267 struct lsa_TranslatedName name;
268 struct lsa_TransNameArray tnames;
271 printf("Testing LookupNames with well known names\n");
273 tnames.names = &name;
275 name.name.string = "NT AUTHORITY\\SYSTEM";
276 name.sid_type = SID_NAME_WKN_GRP;
277 ret &= test_LookupNames(p, mem_ctx, handle, &tnames);
279 name.name.string = "NT AUTHORITY\\ANONYMOUS LOGON";
280 name.sid_type = SID_NAME_WKN_GRP;
281 ret &= test_LookupNames(p, mem_ctx, handle, &tnames);
283 name.name.string = "NT AUTHORITY\\Authenticated Users";
284 name.sid_type = SID_NAME_WKN_GRP;
285 ret &= test_LookupNames(p, mem_ctx, handle, &tnames);
288 name.name.string = "NT AUTHORITY";
289 ret &= test_LookupNames(p, mem_ctx, handle, &tnames);
291 name.name.string = "NT AUTHORITY\\";
292 ret &= test_LookupNames(p, mem_ctx, handle, &tnames);
295 name.name.string = "BUILTIN\\";
296 name.sid_type = SID_NAME_DOMAIN;
297 ret &= test_LookupNames(p, mem_ctx, handle, &tnames);
299 name.name.string = "BUILTIN\\Administrators";
300 name.sid_type = SID_NAME_ALIAS;
301 ret &= test_LookupNames(p, mem_ctx, handle, &tnames);
303 name.name.string = "SYSTEM";
304 name.sid_type = SID_NAME_WKN_GRP;
305 ret &= test_LookupNames(p, mem_ctx, handle, &tnames);
307 name.name.string = "Everyone";
308 name.sid_type = SID_NAME_WKN_GRP;
309 ret &= test_LookupNames(p, mem_ctx, handle, &tnames);
313 static bool test_LookupNames2(struct dcerpc_pipe *p,
315 struct policy_handle *handle,
316 struct lsa_TransNameArray2 *tnames)
318 struct lsa_LookupNames2 r;
319 struct lsa_TransSidArray2 sids;
320 struct lsa_String *names;
325 printf("\nTesting LookupNames2 with %d names\n", tnames->count);
330 names = talloc_array(mem_ctx, struct lsa_String, tnames->count);
331 for (i=0;i<tnames->count;i++) {
332 init_lsa_String(&names[i], tnames->names[i].name.string);
335 r.in.handle = handle;
336 r.in.num_names = tnames->count;
343 r.out.count = &count;
346 status = dcerpc_lsa_LookupNames2(p, mem_ctx, &r);
347 if (!NT_STATUS_IS_OK(status)) {
348 printf("LookupNames2 failed - %s\n", nt_errstr(status));
358 static bool test_LookupNames3(struct dcerpc_pipe *p,
360 struct policy_handle *handle,
361 struct lsa_TransNameArray2 *tnames)
363 struct lsa_LookupNames3 r;
364 struct lsa_TransSidArray3 sids;
365 struct lsa_String *names;
370 printf("\nTesting LookupNames3 with %d names\n", tnames->count);
375 names = talloc_array(mem_ctx, struct lsa_String, tnames->count);
376 for (i=0;i<tnames->count;i++) {
377 init_lsa_String(&names[i], tnames->names[i].name.string);
380 r.in.handle = handle;
381 r.in.num_names = tnames->count;
388 r.out.count = &count;
391 status = dcerpc_lsa_LookupNames3(p, mem_ctx, &r);
392 if (!NT_STATUS_IS_OK(status)) {
393 printf("LookupNames3 failed - %s\n", nt_errstr(status));
402 static bool test_LookupNames4(struct dcerpc_pipe *p,
404 struct lsa_TransNameArray2 *tnames)
406 struct lsa_LookupNames4 r;
407 struct lsa_TransSidArray3 sids;
408 struct lsa_String *names;
413 printf("\nTesting LookupNames4 with %d names\n", tnames->count);
418 names = talloc_array(mem_ctx, struct lsa_String, tnames->count);
419 for (i=0;i<tnames->count;i++) {
420 init_lsa_String(&names[i], tnames->names[i].name.string);
423 r.in.num_names = tnames->count;
430 r.out.count = &count;
433 status = dcerpc_lsa_LookupNames4(p, mem_ctx, &r);
434 if (!NT_STATUS_IS_OK(status)) {
435 printf("LookupNames4 failed - %s\n", nt_errstr(status));
445 static bool test_LookupSids(struct dcerpc_pipe *p,
447 struct policy_handle *handle,
448 struct lsa_SidArray *sids)
450 struct lsa_LookupSids r;
451 struct lsa_TransNameArray names;
452 uint32_t count = sids->num_sids;
455 printf("\nTesting LookupSids\n");
460 r.in.handle = handle;
465 r.out.count = &count;
466 r.out.names = &names;
468 status = dcerpc_lsa_LookupSids(p, mem_ctx, &r);
469 if (!NT_STATUS_IS_OK(status)) {
470 printf("LookupSids failed - %s\n", nt_errstr(status));
476 if (!test_LookupNames(p, mem_ctx, handle, &names)) {
484 static bool test_LookupSids2(struct dcerpc_pipe *p,
486 struct policy_handle *handle,
487 struct lsa_SidArray *sids)
489 struct lsa_LookupSids2 r;
490 struct lsa_TransNameArray2 names;
491 uint32_t count = sids->num_sids;
494 printf("\nTesting LookupSids2\n");
499 r.in.handle = handle;
506 r.out.count = &count;
507 r.out.names = &names;
509 status = dcerpc_lsa_LookupSids2(p, mem_ctx, &r);
510 if (!NT_STATUS_IS_OK(status)) {
511 printf("LookupSids2 failed - %s\n", nt_errstr(status));
517 if (!test_LookupNames2(p, mem_ctx, handle, &names)) {
521 if (!test_LookupNames3(p, mem_ctx, handle, &names)) {
528 static bool test_LookupSids3(struct dcerpc_pipe *p,
530 struct lsa_SidArray *sids)
532 struct lsa_LookupSids3 r;
533 struct lsa_TransNameArray2 names;
534 uint32_t count = sids->num_sids;
537 printf("\nTesting LookupSids3\n");
548 r.out.count = &count;
549 r.out.names = &names;
551 status = dcerpc_lsa_LookupSids3(p, mem_ctx, &r);
552 if (!NT_STATUS_IS_OK(status)) {
553 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
554 NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
555 printf("not considering %s to be an error\n", nt_errstr(status));
558 printf("LookupSids3 failed - %s - not considered an error\n",
565 if (!test_LookupNames4(p, mem_ctx, &names)) {
572 bool test_many_LookupSids(struct dcerpc_pipe *p,
574 struct policy_handle *handle)
578 struct lsa_SidArray sids;
581 printf("\nTesting LookupSids with lots of SIDs\n");
585 sids.sids = talloc_array(mem_ctx, struct lsa_SidPtr, sids.num_sids);
587 for (i=0; i<sids.num_sids; i++) {
588 const char *sidstr = "S-1-5-32-545";
589 sids.sids[i].sid = dom_sid_parse_talloc(mem_ctx, sidstr);
592 count = sids.num_sids;
595 struct lsa_LookupSids r;
596 struct lsa_TransNameArray names;
600 r.in.handle = handle;
604 r.in.count = &names.count;
605 r.out.count = &count;
606 r.out.names = &names;
608 status = dcerpc_lsa_LookupSids(p, mem_ctx, &r);
609 if (!NT_STATUS_IS_OK(status)) {
610 printf("LookupSids failed - %s\n", nt_errstr(status));
616 if (!test_LookupNames(p, mem_ctx, handle, &names)) {
619 } else if (p->conn->security_state.auth_info->auth_type == DCERPC_AUTH_TYPE_SCHANNEL &&
620 p->conn->security_state.auth_info->auth_level >= DCERPC_AUTH_LEVEL_INTEGRITY) {
621 struct lsa_LookupSids3 r;
622 struct lsa_TransNameArray2 names;
627 printf("\nTesting LookupSids3\n");
635 r.out.count = &count;
636 r.out.names = &names;
638 status = dcerpc_lsa_LookupSids3(p, mem_ctx, &r);
639 if (!NT_STATUS_IS_OK(status)) {
640 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
641 NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
642 printf("not considering %s to be an error\n", nt_errstr(status));
645 printf("LookupSids3 failed - %s\n",
649 if (!test_LookupNames4(p, mem_ctx, &names)) {
661 static void lookupsids_cb(struct rpc_request *req)
663 int *replies = (int *)req->async.private_data;
666 status = dcerpc_ndr_request_recv(req);
667 if (!NT_STATUS_IS_OK(status)) {
668 printf("lookupsids returned %s\n", nt_errstr(status));
677 static bool test_LookupSids_async(struct dcerpc_pipe *p,
679 struct policy_handle *handle)
681 struct lsa_SidArray sids;
682 struct lsa_SidPtr sidptr;
684 struct lsa_TransNameArray *names;
685 struct lsa_LookupSids *r;
686 struct rpc_request **req;
689 const int num_async_requests = 50;
691 count = talloc_array(mem_ctx, uint32_t, num_async_requests);
692 names = talloc_array(mem_ctx, struct lsa_TransNameArray, num_async_requests);
693 r = talloc_array(mem_ctx, struct lsa_LookupSids, num_async_requests);
695 printf("\nTesting %d async lookupsids request\n", num_async_requests);
697 req = talloc_array(mem_ctx, struct rpc_request *, num_async_requests);
701 sidptr.sid = dom_sid_parse_talloc(mem_ctx, "S-1-5-32-545");
705 for (i=0; i<num_async_requests; i++) {
708 names[i].names = NULL;
710 r[i].in.handle = handle;
711 r[i].in.sids = &sids;
712 r[i].in.names = &names[i];
714 r[i].in.count = &names[i].count;
715 r[i].out.count = &count[i];
716 r[i].out.names = &names[i];
718 req[i] = dcerpc_lsa_LookupSids_send(p, req, &r[i]);
719 if (req[i] == NULL) {
724 req[i]->async.callback = lookupsids_cb;
725 req[i]->async.private_data = &replies;
728 while (replies >= 0 && replies < num_async_requests) {
729 event_loop_once(p->conn->event_ctx);
741 static bool test_LookupPrivValue(struct dcerpc_pipe *p,
743 struct policy_handle *handle,
744 struct lsa_String *name)
747 struct lsa_LookupPrivValue r;
748 struct lsa_LUID luid;
750 r.in.handle = handle;
754 status = dcerpc_lsa_LookupPrivValue(p, mem_ctx, &r);
755 if (!NT_STATUS_IS_OK(status)) {
756 printf("\nLookupPrivValue failed - %s\n", nt_errstr(status));
763 static bool test_LookupPrivName(struct dcerpc_pipe *p,
765 struct policy_handle *handle,
766 struct lsa_LUID *luid)
769 struct lsa_LookupPrivName r;
771 r.in.handle = handle;
774 status = dcerpc_lsa_LookupPrivName(p, mem_ctx, &r);
775 if (!NT_STATUS_IS_OK(status)) {
776 printf("\nLookupPrivName failed - %s\n", nt_errstr(status));
783 static bool test_RemovePrivilegesFromAccount(struct dcerpc_pipe *p,
785 struct policy_handle *handle,
786 struct policy_handle *acct_handle,
787 struct lsa_LUID *luid)
790 struct lsa_RemovePrivilegesFromAccount r;
791 struct lsa_PrivilegeSet privs;
794 printf("Testing RemovePrivilegesFromAccount\n");
796 r.in.handle = acct_handle;
802 privs.set = talloc_array(mem_ctx, struct lsa_LUIDAttribute, 1);
803 privs.set[0].luid = *luid;
804 privs.set[0].attribute = 0;
806 status = dcerpc_lsa_RemovePrivilegesFromAccount(p, mem_ctx, &r);
807 if (!NT_STATUS_IS_OK(status)) {
809 struct lsa_LookupPrivName r_name;
811 r_name.in.handle = handle;
812 r_name.in.luid = luid;
814 status = dcerpc_lsa_LookupPrivName(p, mem_ctx, &r_name);
815 if (!NT_STATUS_IS_OK(status)) {
816 printf("\nLookupPrivName failed - %s\n", nt_errstr(status));
819 /* Windows 2008 does not allow this to be removed */
820 if (strcmp("SeAuditPrivilege", r_name.out.name->string) == 0) {
824 printf("RemovePrivilegesFromAccount failed to remove %s - %s\n",
825 r_name.out.name->string,
833 static bool test_AddPrivilegesToAccount(struct dcerpc_pipe *p,
835 struct policy_handle *acct_handle,
836 struct lsa_LUID *luid)
839 struct lsa_AddPrivilegesToAccount r;
840 struct lsa_PrivilegeSet privs;
843 printf("Testing AddPrivilegesToAccount\n");
845 r.in.handle = acct_handle;
850 privs.set = talloc_array(mem_ctx, struct lsa_LUIDAttribute, 1);
851 privs.set[0].luid = *luid;
852 privs.set[0].attribute = 0;
854 status = dcerpc_lsa_AddPrivilegesToAccount(p, mem_ctx, &r);
855 if (!NT_STATUS_IS_OK(status)) {
856 printf("AddPrivilegesToAccount failed - %s\n", nt_errstr(status));
863 static bool test_EnumPrivsAccount(struct dcerpc_pipe *p,
865 struct policy_handle *handle,
866 struct policy_handle *acct_handle)
869 struct lsa_EnumPrivsAccount r;
872 printf("Testing EnumPrivsAccount\n");
874 r.in.handle = acct_handle;
876 status = dcerpc_lsa_EnumPrivsAccount(p, mem_ctx, &r);
877 if (!NT_STATUS_IS_OK(status)) {
878 printf("EnumPrivsAccount failed - %s\n", nt_errstr(status));
882 if (r.out.privs && r.out.privs->count > 0) {
884 for (i=0;i<r.out.privs->count;i++) {
885 test_LookupPrivName(p, mem_ctx, handle,
886 &r.out.privs->set[i].luid);
889 ret &= test_RemovePrivilegesFromAccount(p, mem_ctx, handle, acct_handle,
890 &r.out.privs->set[0].luid);
891 ret &= test_AddPrivilegesToAccount(p, mem_ctx, acct_handle,
892 &r.out.privs->set[0].luid);
898 static bool test_Delete(struct dcerpc_pipe *p,
900 struct policy_handle *handle)
905 printf("testing Delete\n");
907 r.in.handle = handle;
908 status = dcerpc_lsa_Delete(p, mem_ctx, &r);
909 if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
910 printf("Delete should have failed NT_STATUS_NOT_SUPPORTED - %s\n", nt_errstr(status));
917 static bool test_DeleteObject(struct dcerpc_pipe *p,
919 struct policy_handle *handle)
922 struct lsa_DeleteObject r;
924 printf("testing DeleteObject\n");
926 r.in.handle = handle;
927 r.out.handle = handle;
928 status = dcerpc_lsa_DeleteObject(p, mem_ctx, &r);
929 if (!NT_STATUS_IS_OK(status)) {
930 printf("Delete failed - %s\n", nt_errstr(status));
938 static bool test_CreateAccount(struct dcerpc_pipe *p,
940 struct policy_handle *handle)
943 struct lsa_CreateAccount r;
944 struct dom_sid2 *newsid;
945 struct policy_handle acct_handle;
947 newsid = dom_sid_parse_talloc(mem_ctx, "S-1-5-12349876-4321-2854");
949 printf("Testing CreateAccount\n");
951 r.in.handle = handle;
953 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
954 r.out.acct_handle = &acct_handle;
956 status = dcerpc_lsa_CreateAccount(p, mem_ctx, &r);
957 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
958 struct lsa_OpenAccount r_o;
959 r_o.in.handle = handle;
961 r_o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
962 r_o.out.acct_handle = &acct_handle;
964 status = dcerpc_lsa_OpenAccount(p, mem_ctx, &r_o);
965 if (!NT_STATUS_IS_OK(status)) {
966 printf("OpenAccount failed - %s\n", nt_errstr(status));
969 } else if (!NT_STATUS_IS_OK(status)) {
970 printf("CreateAccount failed - %s\n", nt_errstr(status));
974 if (!test_Delete(p, mem_ctx, &acct_handle)) {
978 if (!test_DeleteObject(p, mem_ctx, &acct_handle)) {
985 static bool test_DeleteTrustedDomain(struct dcerpc_pipe *p,
987 struct policy_handle *handle,
988 struct lsa_StringLarge name)
991 struct lsa_OpenTrustedDomainByName r;
992 struct policy_handle trustdom_handle;
994 r.in.handle = handle;
995 r.in.name.string = name.string;
996 r.in.access_mask = SEC_STD_DELETE;
997 r.out.trustdom_handle = &trustdom_handle;
999 status = dcerpc_lsa_OpenTrustedDomainByName(p, mem_ctx, &r);
1000 if (!NT_STATUS_IS_OK(status)) {
1001 printf("lsa_OpenTrustedDomainByName failed - %s\n", nt_errstr(status));
1005 if (!test_Delete(p, mem_ctx, &trustdom_handle)) {
1009 if (!test_DeleteObject(p, mem_ctx, &trustdom_handle)) {
1016 static bool test_DeleteTrustedDomainBySid(struct dcerpc_pipe *p,
1017 TALLOC_CTX *mem_ctx,
1018 struct policy_handle *handle,
1019 struct dom_sid *sid)
1022 struct lsa_DeleteTrustedDomain r;
1024 r.in.handle = handle;
1027 status = dcerpc_lsa_DeleteTrustedDomain(p, mem_ctx, &r);
1028 if (!NT_STATUS_IS_OK(status)) {
1029 printf("lsa_DeleteTrustedDomain failed - %s\n", nt_errstr(status));
1037 static bool test_CreateSecret(struct dcerpc_pipe *p,
1038 TALLOC_CTX *mem_ctx,
1039 struct policy_handle *handle)
1042 struct lsa_CreateSecret r;
1043 struct lsa_OpenSecret r2;
1044 struct lsa_SetSecret r3;
1045 struct lsa_QuerySecret r4;
1046 struct lsa_SetSecret r5;
1047 struct lsa_QuerySecret r6;
1048 struct lsa_SetSecret r7;
1049 struct lsa_QuerySecret r8;
1050 struct policy_handle sec_handle, sec_handle2, sec_handle3;
1051 struct lsa_DeleteObject d_o;
1052 struct lsa_DATA_BUF buf1;
1053 struct lsa_DATA_BUF_PTR bufp1;
1054 struct lsa_DATA_BUF_PTR bufp2;
1057 DATA_BLOB session_key;
1058 NTTIME old_mtime, new_mtime;
1059 DATA_BLOB blob1, blob2;
1060 const char *secret1 = "abcdef12345699qwerty";
1062 const char *secret3 = "ABCDEF12345699QWERTY";
1064 const char *secret5 = "NEW-SAMBA4-SECRET";
1068 const int LOCAL = 0;
1069 const int GLOBAL = 1;
1071 secname[LOCAL] = talloc_asprintf(mem_ctx, "torturesecret-%u", (uint_t)random());
1072 secname[GLOBAL] = talloc_asprintf(mem_ctx, "G$torturesecret-%u", (uint_t)random());
1074 for (i=0; i< 2; i++) {
1075 printf("Testing CreateSecret of %s\n", secname[i]);
1077 init_lsa_String(&r.in.name, secname[i]);
1079 r.in.handle = handle;
1080 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1081 r.out.sec_handle = &sec_handle;
1083 status = dcerpc_lsa_CreateSecret(p, mem_ctx, &r);
1084 if (!NT_STATUS_IS_OK(status)) {
1085 printf("CreateSecret failed - %s\n", nt_errstr(status));
1089 r.in.handle = handle;
1090 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1091 r.out.sec_handle = &sec_handle3;
1093 status = dcerpc_lsa_CreateSecret(p, mem_ctx, &r);
1094 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
1095 printf("CreateSecret should have failed OBJECT_NAME_COLLISION - %s\n", nt_errstr(status));
1099 r2.in.handle = handle;
1100 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1101 r2.in.name = r.in.name;
1102 r2.out.sec_handle = &sec_handle2;
1104 printf("Testing OpenSecret\n");
1106 status = dcerpc_lsa_OpenSecret(p, mem_ctx, &r2);
1107 if (!NT_STATUS_IS_OK(status)) {
1108 printf("OpenSecret failed - %s\n", nt_errstr(status));
1112 status = dcerpc_fetch_session_key(p, &session_key);
1113 if (!NT_STATUS_IS_OK(status)) {
1114 printf("dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
1118 enc_key = sess_encrypt_string(secret1, &session_key);
1120 r3.in.sec_handle = &sec_handle;
1121 r3.in.new_val = &buf1;
1122 r3.in.old_val = NULL;
1123 r3.in.new_val->data = enc_key.data;
1124 r3.in.new_val->length = enc_key.length;
1125 r3.in.new_val->size = enc_key.length;
1127 printf("Testing SetSecret\n");
1129 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r3);
1130 if (!NT_STATUS_IS_OK(status)) {
1131 printf("SetSecret failed - %s\n", nt_errstr(status));
1135 r3.in.sec_handle = &sec_handle;
1136 r3.in.new_val = &buf1;
1137 r3.in.old_val = NULL;
1138 r3.in.new_val->data = enc_key.data;
1139 r3.in.new_val->length = enc_key.length;
1140 r3.in.new_val->size = enc_key.length;
1142 /* break the encrypted data */
1145 printf("Testing SetSecret with broken key\n");
1147 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r3);
1148 if (!NT_STATUS_EQUAL(status, NT_STATUS_UNKNOWN_REVISION)) {
1149 printf("SetSecret should have failed UNKNOWN_REVISION - %s\n", nt_errstr(status));
1153 data_blob_free(&enc_key);
1155 ZERO_STRUCT(new_mtime);
1156 ZERO_STRUCT(old_mtime);
1158 /* fetch the secret back again */
1159 r4.in.sec_handle = &sec_handle;
1160 r4.in.new_val = &bufp1;
1161 r4.in.new_mtime = &new_mtime;
1162 r4.in.old_val = NULL;
1163 r4.in.old_mtime = NULL;
1167 printf("Testing QuerySecret\n");
1168 status = dcerpc_lsa_QuerySecret(p, mem_ctx, &r4);
1169 if (!NT_STATUS_IS_OK(status)) {
1170 printf("QuerySecret failed - %s\n", nt_errstr(status));
1173 if (r4.out.new_val == NULL || r4.out.new_val->buf == NULL) {
1174 printf("No secret buffer returned\n");
1177 blob1.data = r4.out.new_val->buf->data;
1178 blob1.length = r4.out.new_val->buf->size;
1180 blob2 = data_blob_talloc(mem_ctx, NULL, blob1.length);
1182 secret2 = sess_decrypt_string(mem_ctx,
1183 &blob1, &session_key);
1185 if (strcmp(secret1, secret2) != 0) {
1186 printf("Returned secret (r4) '%s' doesn't match '%s'\n",
1193 enc_key = sess_encrypt_string(secret3, &session_key);
1195 r5.in.sec_handle = &sec_handle;
1196 r5.in.new_val = &buf1;
1197 r5.in.old_val = NULL;
1198 r5.in.new_val->data = enc_key.data;
1199 r5.in.new_val->length = enc_key.length;
1200 r5.in.new_val->size = enc_key.length;
1204 printf("Testing SetSecret (existing value should move to old)\n");
1206 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r5);
1207 if (!NT_STATUS_IS_OK(status)) {
1208 printf("SetSecret failed - %s\n", nt_errstr(status));
1212 data_blob_free(&enc_key);
1214 ZERO_STRUCT(new_mtime);
1215 ZERO_STRUCT(old_mtime);
1217 /* fetch the secret back again */
1218 r6.in.sec_handle = &sec_handle;
1219 r6.in.new_val = &bufp1;
1220 r6.in.new_mtime = &new_mtime;
1221 r6.in.old_val = &bufp2;
1222 r6.in.old_mtime = &old_mtime;
1227 status = dcerpc_lsa_QuerySecret(p, mem_ctx, &r6);
1228 if (!NT_STATUS_IS_OK(status)) {
1229 printf("QuerySecret failed - %s\n", nt_errstr(status));
1234 if (r6.out.new_val->buf == NULL || r6.out.old_val->buf == NULL
1235 || r6.out.new_mtime == NULL || r6.out.old_mtime == NULL) {
1236 printf("Both secret buffers and both times not returned\n");
1240 blob1.data = r6.out.new_val->buf->data;
1241 blob1.length = r6.out.new_val->buf->size;
1243 blob2 = data_blob_talloc(mem_ctx, NULL, blob1.length);
1245 secret4 = sess_decrypt_string(mem_ctx,
1246 &blob1, &session_key);
1248 if (strcmp(secret3, secret4) != 0) {
1249 printf("Returned NEW secret %s doesn't match %s\n", secret4, secret3);
1253 blob1.data = r6.out.old_val->buf->data;
1254 blob1.length = r6.out.old_val->buf->length;
1256 blob2 = data_blob_talloc(mem_ctx, NULL, blob1.length);
1258 secret2 = sess_decrypt_string(mem_ctx,
1259 &blob1, &session_key);
1261 if (strcmp(secret1, secret2) != 0) {
1262 printf("Returned OLD secret %s doesn't match %s\n", secret2, secret1);
1266 if (*r6.out.new_mtime == *r6.out.old_mtime) {
1267 printf("Returned secret (r6-%d) %s must not have same mtime for both secrets: %s != %s\n",
1270 nt_time_string(mem_ctx, *r6.out.old_mtime),
1271 nt_time_string(mem_ctx, *r6.out.new_mtime));
1277 enc_key = sess_encrypt_string(secret5, &session_key);
1279 r7.in.sec_handle = &sec_handle;
1280 r7.in.old_val = &buf1;
1281 r7.in.old_val->data = enc_key.data;
1282 r7.in.old_val->length = enc_key.length;
1283 r7.in.old_val->size = enc_key.length;
1284 r7.in.new_val = NULL;
1286 printf("Testing SetSecret of old Secret only\n");
1288 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r7);
1289 if (!NT_STATUS_IS_OK(status)) {
1290 printf("SetSecret failed - %s\n", nt_errstr(status));
1294 data_blob_free(&enc_key);
1296 /* fetch the secret back again */
1297 r8.in.sec_handle = &sec_handle;
1298 r8.in.new_val = &bufp1;
1299 r8.in.new_mtime = &new_mtime;
1300 r8.in.old_val = &bufp2;
1301 r8.in.old_mtime = &old_mtime;
1306 status = dcerpc_lsa_QuerySecret(p, mem_ctx, &r8);
1307 if (!NT_STATUS_IS_OK(status)) {
1308 printf("QuerySecret failed - %s\n", nt_errstr(status));
1311 if (!r8.out.new_val || !r8.out.old_val) {
1312 printf("in/out pointers not returned, despite being set on in for QuerySecret\n");
1314 } else if (r8.out.new_val->buf != NULL) {
1315 printf("NEW secret buffer must not be returned after OLD set\n");
1317 } else if (r8.out.old_val->buf == NULL) {
1318 printf("OLD secret buffer was not returned after OLD set\n");
1320 } else if (r8.out.new_mtime == NULL || r8.out.old_mtime == NULL) {
1321 printf("Both times not returned after OLD set\n");
1324 blob1.data = r8.out.old_val->buf->data;
1325 blob1.length = r8.out.old_val->buf->size;
1327 blob2 = data_blob_talloc(mem_ctx, NULL, blob1.length);
1329 secret6 = sess_decrypt_string(mem_ctx,
1330 &blob1, &session_key);
1332 if (strcmp(secret5, secret6) != 0) {
1333 printf("Returned OLD secret %s doesn't match %s\n", secret5, secret6);
1337 if (*r8.out.new_mtime != *r8.out.old_mtime) {
1338 printf("Returned secret (r8) %s did not had same mtime for both secrets: %s != %s\n",
1340 nt_time_string(mem_ctx, *r8.out.old_mtime),
1341 nt_time_string(mem_ctx, *r8.out.new_mtime));
1347 if (!test_Delete(p, mem_ctx, &sec_handle)) {
1351 if (!test_DeleteObject(p, mem_ctx, &sec_handle)) {
1355 d_o.in.handle = &sec_handle2;
1356 d_o.out.handle = &sec_handle2;
1357 status = dcerpc_lsa_DeleteObject(p, mem_ctx, &d_o);
1358 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1359 printf("Second delete expected INVALID_HANDLE - %s\n", nt_errstr(status));
1363 printf("Testing OpenSecret of just-deleted secret\n");
1365 status = dcerpc_lsa_OpenSecret(p, mem_ctx, &r2);
1366 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
1367 printf("OpenSecret expected OBJECT_NAME_NOT_FOUND - %s\n", nt_errstr(status));
1378 static bool test_EnumAccountRights(struct dcerpc_pipe *p,
1379 TALLOC_CTX *mem_ctx,
1380 struct policy_handle *acct_handle,
1381 struct dom_sid *sid)
1384 struct lsa_EnumAccountRights r;
1385 struct lsa_RightSet rights;
1387 printf("Testing EnumAccountRights\n");
1389 r.in.handle = acct_handle;
1391 r.out.rights = &rights;
1393 status = dcerpc_lsa_EnumAccountRights(p, mem_ctx, &r);
1394 if (!NT_STATUS_IS_OK(status)) {
1395 printf("EnumAccountRights of %s failed - %s\n",
1396 dom_sid_string(mem_ctx, sid), nt_errstr(status));
1404 static bool test_QuerySecurity(struct dcerpc_pipe *p,
1405 struct torture_context *tctx,
1406 struct policy_handle *handle,
1407 struct policy_handle *acct_handle)
1410 struct lsa_QuerySecurity r;
1412 if (torture_setting_bool(tctx, "samba4", false)) {
1413 printf("skipping QuerySecurity test against Samba4\n");
1417 printf("Testing QuerySecurity\n");
1419 r.in.handle = acct_handle;
1422 status = dcerpc_lsa_QuerySecurity(p, tctx, &r);
1423 if (!NT_STATUS_IS_OK(status)) {
1424 printf("QuerySecurity failed - %s\n", nt_errstr(status));
1431 static bool test_OpenAccount(struct dcerpc_pipe *p,
1432 TALLOC_CTX *mem_ctx,
1433 struct policy_handle *handle,
1434 struct dom_sid *sid)
1437 struct lsa_OpenAccount r;
1438 struct policy_handle acct_handle;
1440 printf("Testing OpenAccount\n");
1442 r.in.handle = handle;
1444 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1445 r.out.acct_handle = &acct_handle;
1447 status = dcerpc_lsa_OpenAccount(p, mem_ctx, &r);
1448 if (!NT_STATUS_IS_OK(status)) {
1449 printf("OpenAccount failed - %s\n", nt_errstr(status));
1453 if (!test_EnumPrivsAccount(p, mem_ctx, handle, &acct_handle)) {
1457 if (!test_QuerySecurity(p, mem_ctx, handle, &acct_handle)) {
1464 static bool test_EnumAccounts(struct dcerpc_pipe *p,
1465 TALLOC_CTX *mem_ctx,
1466 struct policy_handle *handle)
1469 struct lsa_EnumAccounts r;
1470 struct lsa_SidArray sids1, sids2;
1471 uint32_t resume_handle = 0;
1475 printf("\ntesting EnumAccounts\n");
1477 r.in.handle = handle;
1478 r.in.resume_handle = &resume_handle;
1479 r.in.num_entries = 100;
1480 r.out.resume_handle = &resume_handle;
1481 r.out.sids = &sids1;
1485 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
1486 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
1489 if (!NT_STATUS_IS_OK(status)) {
1490 printf("EnumAccounts failed - %s\n", nt_errstr(status));
1494 if (!test_LookupSids(p, mem_ctx, handle, &sids1)) {
1498 if (!test_LookupSids2(p, mem_ctx, handle, &sids1)) {
1502 /* Can't test lookupSids3 here, as clearly we must not
1503 * be on schannel, or we would not be able to do the
1506 printf("testing all accounts\n");
1507 for (i=0;i<sids1.num_sids;i++) {
1508 ret &= test_OpenAccount(p, mem_ctx, handle, sids1.sids[i].sid);
1509 ret &= test_EnumAccountRights(p, mem_ctx, handle, sids1.sids[i].sid);
1514 if (sids1.num_sids < 3) {
1518 printf("trying EnumAccounts partial listing (asking for 1 at 2)\n");
1520 r.in.num_entries = 1;
1521 r.out.sids = &sids2;
1523 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
1524 if (!NT_STATUS_IS_OK(status)) {
1525 printf("EnumAccounts failed - %s\n", nt_errstr(status));
1529 if (sids2.num_sids != 1) {
1530 printf("Returned wrong number of entries (%d)\n", sids2.num_sids);
1537 static bool test_LookupPrivDisplayName(struct dcerpc_pipe *p,
1538 TALLOC_CTX *mem_ctx,
1539 struct policy_handle *handle,
1540 struct lsa_String *priv_name)
1542 struct lsa_LookupPrivDisplayName r;
1544 /* produce a reasonable range of language output without screwing up
1546 uint16_t language_id = (random() % 4) + 0x409;
1548 printf("testing LookupPrivDisplayName(%s)\n", priv_name->string);
1550 r.in.handle = handle;
1551 r.in.name = priv_name;
1552 r.in.language_id = &language_id;
1553 r.out.language_id = &language_id;
1556 status = dcerpc_lsa_LookupPrivDisplayName(p, mem_ctx, &r);
1557 if (!NT_STATUS_IS_OK(status)) {
1558 printf("LookupPrivDisplayName failed - %s\n", nt_errstr(status));
1561 printf("%s -> \"%s\" (language 0x%x/0x%x)\n",
1562 priv_name->string, r.out.disp_name->string,
1563 *r.in.language_id, *r.out.language_id);
1568 static bool test_EnumAccountsWithUserRight(struct dcerpc_pipe *p,
1569 TALLOC_CTX *mem_ctx,
1570 struct policy_handle *handle,
1571 struct lsa_String *priv_name)
1573 struct lsa_EnumAccountsWithUserRight r;
1574 struct lsa_SidArray sids;
1579 printf("testing EnumAccountsWithUserRight(%s)\n", priv_name->string);
1581 r.in.handle = handle;
1582 r.in.name = priv_name;
1585 status = dcerpc_lsa_EnumAccountsWithUserRight(p, mem_ctx, &r);
1587 /* NT_STATUS_NO_MORE_ENTRIES means noone has this privilege */
1588 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
1592 if (!NT_STATUS_IS_OK(status)) {
1593 printf("EnumAccountsWithUserRight failed - %s\n", nt_errstr(status));
1601 static bool test_EnumPrivs(struct dcerpc_pipe *p,
1602 TALLOC_CTX *mem_ctx,
1603 struct policy_handle *handle)
1606 struct lsa_EnumPrivs r;
1607 struct lsa_PrivArray privs1;
1608 uint32_t resume_handle = 0;
1612 printf("\ntesting EnumPrivs\n");
1614 r.in.handle = handle;
1615 r.in.resume_handle = &resume_handle;
1616 r.in.max_count = 100;
1617 r.out.resume_handle = &resume_handle;
1618 r.out.privs = &privs1;
1621 status = dcerpc_lsa_EnumPrivs(p, mem_ctx, &r);
1622 if (!NT_STATUS_IS_OK(status)) {
1623 printf("EnumPrivs failed - %s\n", nt_errstr(status));
1627 for (i = 0; i< privs1.count; i++) {
1628 test_LookupPrivDisplayName(p, mem_ctx, handle, (struct lsa_String *)&privs1.privs[i].name);
1629 test_LookupPrivValue(p, mem_ctx, handle, (struct lsa_String *)&privs1.privs[i].name);
1630 if (!test_EnumAccountsWithUserRight(p, mem_ctx, handle, (struct lsa_String *)&privs1.privs[i].name)) {
1638 static bool test_QueryForestTrustInformation(struct dcerpc_pipe *p,
1639 struct torture_context *tctx,
1640 struct policy_handle *handle,
1641 const char *trusted_domain_name)
1644 struct lsa_lsaRQueryForestTrustInformation r;
1646 struct lsa_String string;
1647 struct lsa_ForestTrustInformation info, *info_ptr;
1649 printf("\nTesting lsaRQueryForestTrustInformation\n");
1651 if (torture_setting_bool(tctx, "samba4", false)) {
1652 printf("skipping QueryForestTrustInformation against Samba4\n");
1656 ZERO_STRUCT(string);
1658 if (trusted_domain_name) {
1659 init_lsa_String(&string, trusted_domain_name);
1664 r.in.handle = handle;
1665 r.in.trusted_domain_name = &string;
1667 r.out.forest_trust_info = &info_ptr;
1669 status = dcerpc_lsa_lsaRQueryForestTrustInformation(p, tctx, &r);
1671 if (!NT_STATUS_IS_OK(status)) {
1672 printf("lsaRQueryForestTrustInformation failed - %s\n", nt_errstr(status));
1679 static bool test_query_each_TrustDomEx(struct dcerpc_pipe *p,
1680 TALLOC_CTX *mem_ctx,
1681 struct policy_handle *handle,
1682 struct lsa_DomainListEx *domains)
1687 for (i=0; i< domains->count; i++) {
1689 if (domains->domains[i].trust_attributes & NETR_TRUST_ATTRIBUTE_FOREST_TRANSITIVE) {
1690 ret &= test_QueryForestTrustInformation(p, mem_ctx, handle,
1691 domains->domains[i].domain_name.string);
1698 static bool test_query_each_TrustDom(struct dcerpc_pipe *p,
1699 TALLOC_CTX *mem_ctx,
1700 struct policy_handle *handle,
1701 struct lsa_DomainList *domains)
1707 printf("\nTesting OpenTrustedDomain, OpenTrustedDomainByName and QueryInfoTrustedDomain\n");
1708 for (i=0; i< domains->count; i++) {
1709 struct lsa_OpenTrustedDomain trust;
1710 struct lsa_OpenTrustedDomainByName trust_by_name;
1711 struct policy_handle trustdom_handle;
1712 struct policy_handle handle2;
1714 struct lsa_CloseTrustedDomainEx c_trust;
1715 int levels [] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
1716 int ok[] = {1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1};
1718 if (domains->domains[i].sid) {
1719 trust.in.handle = handle;
1720 trust.in.sid = domains->domains[i].sid;
1721 trust.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1722 trust.out.trustdom_handle = &trustdom_handle;
1724 status = dcerpc_lsa_OpenTrustedDomain(p, mem_ctx, &trust);
1726 if (!NT_STATUS_IS_OK(status)) {
1727 printf("OpenTrustedDomain failed - %s\n", nt_errstr(status));
1731 c.in.handle = &trustdom_handle;
1732 c.out.handle = &handle2;
1734 c_trust.in.handle = &trustdom_handle;
1735 c_trust.out.handle = &handle2;
1737 for (j=0; j < ARRAY_SIZE(levels); j++) {
1738 struct lsa_QueryTrustedDomainInfo q;
1739 union lsa_TrustedDomainInfo info;
1740 q.in.trustdom_handle = &trustdom_handle;
1741 q.in.level = levels[j];
1743 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
1744 if (!NT_STATUS_IS_OK(status) && ok[j]) {
1745 printf("QueryTrustedDomainInfo level %d failed - %s\n",
1746 levels[j], nt_errstr(status));
1748 } else if (NT_STATUS_IS_OK(status) && !ok[j]) {
1749 printf("QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
1750 levels[j], nt_errstr(status));
1755 status = dcerpc_lsa_CloseTrustedDomainEx(p, mem_ctx, &c_trust);
1756 if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED)) {
1757 printf("Expected CloseTrustedDomainEx to return NT_STATUS_NOT_IMPLEMENTED, instead - %s\n", nt_errstr(status));
1761 c.in.handle = &trustdom_handle;
1762 c.out.handle = &handle2;
1764 status = dcerpc_lsa_Close(p, mem_ctx, &c);
1765 if (!NT_STATUS_IS_OK(status)) {
1766 printf("Close of trusted domain failed - %s\n", nt_errstr(status));
1770 for (j=0; j < ARRAY_SIZE(levels); j++) {
1771 struct lsa_QueryTrustedDomainInfoBySid q;
1772 union lsa_TrustedDomainInfo info;
1774 if (!domains->domains[i].sid) {
1778 q.in.handle = handle;
1779 q.in.dom_sid = domains->domains[i].sid;
1780 q.in.level = levels[j];
1782 status = dcerpc_lsa_QueryTrustedDomainInfoBySid(p, mem_ctx, &q);
1783 if (!NT_STATUS_IS_OK(status) && ok[j]) {
1784 printf("QueryTrustedDomainInfoBySid level %d failed - %s\n",
1785 levels[j], nt_errstr(status));
1787 } else if (NT_STATUS_IS_OK(status) && !ok[j]) {
1788 printf("QueryTrustedDomainInfoBySid level %d unexpectedly succeeded - %s\n",
1789 levels[j], nt_errstr(status));
1795 trust_by_name.in.handle = handle;
1796 trust_by_name.in.name.string = domains->domains[i].name.string;
1797 trust_by_name.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1798 trust_by_name.out.trustdom_handle = &trustdom_handle;
1800 status = dcerpc_lsa_OpenTrustedDomainByName(p, mem_ctx, &trust_by_name);
1802 if (!NT_STATUS_IS_OK(status)) {
1803 printf("OpenTrustedDomainByName failed - %s\n", nt_errstr(status));
1807 for (j=0; j < ARRAY_SIZE(levels); j++) {
1808 struct lsa_QueryTrustedDomainInfo q;
1809 union lsa_TrustedDomainInfo info;
1810 q.in.trustdom_handle = &trustdom_handle;
1811 q.in.level = levels[j];
1813 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
1814 if (!NT_STATUS_IS_OK(status) && ok[j]) {
1815 printf("QueryTrustedDomainInfo level %d failed - %s\n",
1816 levels[j], nt_errstr(status));
1818 } else if (NT_STATUS_IS_OK(status) && !ok[j]) {
1819 printf("QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
1820 levels[j], nt_errstr(status));
1825 c.in.handle = &trustdom_handle;
1826 c.out.handle = &handle2;
1828 status = dcerpc_lsa_Close(p, mem_ctx, &c);
1829 if (!NT_STATUS_IS_OK(status)) {
1830 printf("Close of trusted domain failed - %s\n", nt_errstr(status));
1834 for (j=0; j < ARRAY_SIZE(levels); j++) {
1835 struct lsa_QueryTrustedDomainInfoByName q;
1836 union lsa_TrustedDomainInfo info;
1837 q.in.handle = handle;
1838 q.in.trusted_domain.string = domains->domains[i].name.string;
1839 q.in.level = levels[j];
1841 status = dcerpc_lsa_QueryTrustedDomainInfoByName(p, mem_ctx, &q);
1842 if (!NT_STATUS_IS_OK(status) && ok[j]) {
1843 printf("QueryTrustedDomainInfoByName level %d failed - %s\n",
1844 levels[j], nt_errstr(status));
1846 } else if (NT_STATUS_IS_OK(status) && !ok[j]) {
1847 printf("QueryTrustedDomainInfoByName level %d unexpectedly succeeded - %s\n",
1848 levels[j], nt_errstr(status));
1856 static bool test_EnumTrustDom(struct dcerpc_pipe *p,
1857 TALLOC_CTX *mem_ctx,
1858 struct policy_handle *handle)
1860 struct lsa_EnumTrustDom r;
1861 struct lsa_EnumTrustedDomainsEx r_ex;
1862 NTSTATUS enum_status;
1863 uint32_t resume_handle = 0;
1864 struct lsa_DomainList domains;
1865 struct lsa_DomainListEx domains_ex;
1868 printf("\nTesting EnumTrustDom\n");
1870 r.in.handle = handle;
1871 r.in.resume_handle = &resume_handle;
1873 r.out.domains = &domains;
1874 r.out.resume_handle = &resume_handle;
1876 enum_status = dcerpc_lsa_EnumTrustDom(p, mem_ctx, &r);
1878 if (NT_STATUS_IS_OK(enum_status)) {
1879 if (domains.count == 0) {
1880 printf("EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
1883 } else if (!(NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES) || NT_STATUS_EQUAL(enum_status, NT_STATUS_NO_MORE_ENTRIES))) {
1884 printf("EnumTrustDom of zero size failed - %s\n", nt_errstr(enum_status));
1888 /* Start from the bottom again */
1892 r.in.handle = handle;
1893 r.in.resume_handle = &resume_handle;
1894 r.in.max_size = LSA_ENUM_TRUST_DOMAIN_MULTIPLIER * 3;
1895 r.out.domains = &domains;
1896 r.out.resume_handle = &resume_handle;
1898 enum_status = dcerpc_lsa_EnumTrustDom(p, mem_ctx, &r);
1900 /* NO_MORE_ENTRIES is allowed */
1901 if (NT_STATUS_EQUAL(enum_status, NT_STATUS_NO_MORE_ENTRIES)) {
1903 } else if (NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES)) {
1904 /* Windows 2003 gets this off by one on the first run */
1905 if (r.out.domains->count < 3 || r.out.domains->count > 4) {
1906 printf("EnumTrustDom didn't fill the buffer we "
1907 "asked it to (got %d, expected %d / %d == %d entries)\n",
1908 r.out.domains->count, LSA_ENUM_TRUST_DOMAIN_MULTIPLIER * 3,
1909 LSA_ENUM_TRUST_DOMAIN_MULTIPLIER, r.in.max_size);
1912 } else if (!NT_STATUS_IS_OK(enum_status)) {
1913 printf("EnumTrustDom failed - %s\n", nt_errstr(enum_status));
1917 if (domains.count == 0) {
1918 printf("EnumTrustDom failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
1922 ret &= test_query_each_TrustDom(p, mem_ctx, handle, &domains);
1924 } while ((NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES)));
1926 printf("\nTesting EnumTrustedDomainsEx\n");
1928 r_ex.in.handle = handle;
1929 r_ex.in.resume_handle = &resume_handle;
1930 r_ex.in.max_size = LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER * 3;
1931 r_ex.out.domains = &domains_ex;
1932 r_ex.out.resume_handle = &resume_handle;
1934 enum_status = dcerpc_lsa_EnumTrustedDomainsEx(p, mem_ctx, &r_ex);
1936 if (!(NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES) || NT_STATUS_EQUAL(enum_status, NT_STATUS_NO_MORE_ENTRIES))) {
1937 printf("EnumTrustedDomainEx of zero size failed - %s\n", nt_errstr(enum_status));
1943 r_ex.in.handle = handle;
1944 r_ex.in.resume_handle = &resume_handle;
1945 r_ex.in.max_size = LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER * 3;
1946 r_ex.out.domains = &domains_ex;
1947 r_ex.out.resume_handle = &resume_handle;
1949 enum_status = dcerpc_lsa_EnumTrustedDomainsEx(p, mem_ctx, &r_ex);
1951 /* NO_MORE_ENTRIES is allowed */
1952 if (NT_STATUS_EQUAL(enum_status, NT_STATUS_NO_MORE_ENTRIES)) {
1954 } else if (NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES)) {
1955 /* Windows 2003 gets this off by one on the first run */
1956 if (r_ex.out.domains->count < 3 || r_ex.out.domains->count > 4) {
1957 printf("EnumTrustDom didn't fill the buffer we "
1958 "asked it to (got %d, expected %d / %d == %d entries)\n",
1959 r_ex.out.domains->count,
1961 LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER,
1962 r_ex.in.max_size / LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER);
1964 } else if (!NT_STATUS_IS_OK(enum_status)) {
1965 printf("EnumTrustedDomainEx failed - %s\n", nt_errstr(enum_status));
1969 if (domains_ex.count == 0) {
1970 printf("EnumTrustDomainEx failed - should have returned 'NT_STATUS_NO_MORE_ENTRIES' for 0 trusted domains\n");
1974 ret &= test_query_each_TrustDomEx(p, mem_ctx, handle, &domains_ex);
1976 } while ((NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES)));
1981 static bool test_CreateTrustedDomain(struct dcerpc_pipe *p,
1982 TALLOC_CTX *mem_ctx,
1983 struct policy_handle *handle)
1987 struct lsa_CreateTrustedDomain r;
1988 struct lsa_DomainInfo trustinfo;
1989 struct dom_sid *domsid[12];
1990 struct policy_handle trustdom_handle[12];
1991 struct lsa_QueryTrustedDomainInfo q;
1994 printf("Testing CreateTrustedDomain for 12 domains\n");
1996 if (!test_EnumTrustDom(p, mem_ctx, handle)) {
2000 for (i=0; i< 12; i++) {
2001 char *trust_name = talloc_asprintf(mem_ctx, "torturedom%02d", i);
2002 char *trust_sid = talloc_asprintf(mem_ctx, "S-1-5-21-97398-379795-100%02d", i);
2004 domsid[i] = dom_sid_parse_talloc(mem_ctx, trust_sid);
2006 trustinfo.sid = domsid[i];
2007 init_lsa_String((struct lsa_String *)&trustinfo.name, trust_name);
2009 r.in.policy_handle = handle;
2010 r.in.info = &trustinfo;
2011 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2012 r.out.trustdom_handle = &trustdom_handle[i];
2014 status = dcerpc_lsa_CreateTrustedDomain(p, mem_ctx, &r);
2015 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
2016 test_DeleteTrustedDomain(p, mem_ctx, handle, trustinfo.name);
2017 status = dcerpc_lsa_CreateTrustedDomain(p, mem_ctx, &r);
2019 if (!NT_STATUS_IS_OK(status)) {
2020 printf("CreateTrustedDomain failed - %s\n", nt_errstr(status));
2024 q.in.trustdom_handle = &trustdom_handle[i];
2025 q.in.level = LSA_TRUSTED_DOMAIN_INFO_INFO_EX;
2026 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
2027 if (!NT_STATUS_IS_OK(status)) {
2028 printf("QueryTrustedDomainInfo level 1 failed - %s\n", nt_errstr(status));
2030 } else if (!q.out.info) {
2033 if (strcmp(q.out.info->info_ex.netbios_name.string, trustinfo.name.string) != 0) {
2034 printf("QueryTrustedDomainInfo returned inconsistant short name: %s != %s\n",
2035 q.out.info->info_ex.netbios_name.string, trustinfo.name.string);
2038 if (q.out.info->info_ex.trust_type != LSA_TRUST_TYPE_DOWNLEVEL) {
2039 printf("QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
2040 trust_name, q.out.info->info_ex.trust_type, LSA_TRUST_TYPE_DOWNLEVEL);
2043 if (q.out.info->info_ex.trust_attributes != 0) {
2044 printf("QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
2045 trust_name, q.out.info->info_ex.trust_attributes, 0);
2048 if (q.out.info->info_ex.trust_direction != LSA_TRUST_DIRECTION_OUTBOUND) {
2049 printf("QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
2050 trust_name, q.out.info->info_ex.trust_direction, LSA_TRUST_DIRECTION_OUTBOUND);
2057 /* now that we have some domains to look over, we can test the enum calls */
2058 if (!test_EnumTrustDom(p, mem_ctx, handle)) {
2062 for (i=0; i<12; i++) {
2063 if (!test_DeleteTrustedDomainBySid(p, mem_ctx, handle, domsid[i])) {
2071 static bool test_CreateTrustedDomainEx2(struct dcerpc_pipe *p,
2072 struct torture_context *tctx,
2073 TALLOC_CTX *mem_ctx,
2074 struct policy_handle *handle)
2078 struct lsa_CreateTrustedDomainEx2 r;
2079 struct lsa_TrustDomainInfoInfoEx trustinfo;
2080 struct lsa_TrustDomainInfoAuthInfoInternal authinfo;
2081 struct trustDomainPasswords auth_struct;
2082 DATA_BLOB auth_blob;
2083 struct dom_sid *domsid[12];
2084 struct policy_handle trustdom_handle[12];
2085 struct lsa_QueryTrustedDomainInfo q;
2086 DATA_BLOB session_key;
2087 enum ndr_err_code ndr_err;
2090 printf("Testing CreateTrustedDomainEx2 for 12 domains\n");
2092 status = dcerpc_fetch_session_key(p, &session_key);
2093 if (!NT_STATUS_IS_OK(status)) {
2094 printf("dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
2098 for (i=0; i< 12; i++) {
2099 char *trust_name = talloc_asprintf(mem_ctx, "torturedom%02d", i);
2100 char *trust_name_dns = talloc_asprintf(mem_ctx, "torturedom%02d.samba.example.com", i);
2101 char *trust_sid = talloc_asprintf(mem_ctx, "S-1-5-21-97398-379795-100%02d", i);
2103 domsid[i] = dom_sid_parse_talloc(mem_ctx, trust_sid);
2105 trustinfo.sid = domsid[i];
2106 trustinfo.netbios_name.string = trust_name;
2107 trustinfo.domain_name.string = trust_name_dns;
2109 /* Create inbound, some outbound, and some
2110 * bi-directional trusts in a repeating pattern based
2113 /* 1 == inbound, 2 == outbound, 3 == both */
2114 trustinfo.trust_direction = (i % 3) + 1;
2116 /* Try different trust types too */
2118 /* 1 == downleven (NT4), 2 == uplevel (ADS), 3 == MIT (kerberos but not AD) */
2119 trustinfo.trust_type = (((i / 3) + 1) % 3) + 1;
2121 trustinfo.trust_attributes = LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION;
2123 generate_random_buffer(auth_struct.confounder, sizeof(auth_struct.confounder));
2125 auth_struct.outgoing.count = 0;
2126 auth_struct.incoming.count = 0;
2128 ndr_err = ndr_push_struct_blob(&auth_blob, mem_ctx, lp_iconv_convenience(tctx->lp_ctx), &auth_struct,
2129 (ndr_push_flags_fn_t)ndr_push_trustDomainPasswords);
2130 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
2131 printf("ndr_push_struct_blob of trustDomainPasswords structure failed");
2135 arcfour_crypt_blob(auth_blob.data, auth_blob.length, &session_key);
2137 authinfo.auth_blob.size = auth_blob.length;
2138 authinfo.auth_blob.data = auth_blob.data;
2140 r.in.policy_handle = handle;
2141 r.in.info = &trustinfo;
2142 r.in.auth_info = &authinfo;
2143 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
2144 r.out.trustdom_handle = &trustdom_handle[i];
2146 status = dcerpc_lsa_CreateTrustedDomainEx2(p, mem_ctx, &r);
2147 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
2148 test_DeleteTrustedDomain(p, mem_ctx, handle, trustinfo.netbios_name);
2149 status = dcerpc_lsa_CreateTrustedDomainEx2(p, mem_ctx, &r);
2151 if (!NT_STATUS_IS_OK(status)) {
2152 printf("CreateTrustedDomainEx failed2 - %s\n", nt_errstr(status));
2156 q.in.trustdom_handle = &trustdom_handle[i];
2157 q.in.level = LSA_TRUSTED_DOMAIN_INFO_INFO_EX;
2158 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
2159 if (!NT_STATUS_IS_OK(status)) {
2160 printf("QueryTrustedDomainInfo level 1 failed - %s\n", nt_errstr(status));
2162 } else if (!q.out.info) {
2165 if (strcmp(q.out.info->info_ex.netbios_name.string, trustinfo.netbios_name.string) != 0) {
2166 printf("QueryTrustedDomainInfo returned inconsistant short name: %s != %s\n",
2167 q.out.info->info_ex.netbios_name.string, trustinfo.netbios_name.string);
2170 if (q.out.info->info_ex.trust_type != trustinfo.trust_type) {
2171 printf("QueryTrustedDomainInfo of %s returned incorrect trust type %d != %d\n",
2172 trust_name, q.out.info->info_ex.trust_type, trustinfo.trust_type);
2175 if (q.out.info->info_ex.trust_attributes != LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION) {
2176 printf("QueryTrustedDomainInfo of %s returned incorrect trust attributes %d != %d\n",
2177 trust_name, q.out.info->info_ex.trust_attributes, LSA_TRUST_ATTRIBUTE_USES_RC4_ENCRYPTION);
2180 if (q.out.info->info_ex.trust_direction != trustinfo.trust_direction) {
2181 printf("QueryTrustedDomainInfo of %s returned incorrect trust direction %d != %d\n",
2182 trust_name, q.out.info->info_ex.trust_direction, trustinfo.trust_direction);
2189 /* now that we have some domains to look over, we can test the enum calls */
2190 if (!test_EnumTrustDom(p, mem_ctx, handle)) {
2194 for (i=0; i<12; i++) {
2195 if (!test_DeleteTrustedDomainBySid(p, mem_ctx, handle, domsid[i])) {
2203 static bool test_QueryDomainInfoPolicy(struct dcerpc_pipe *p,
2204 struct torture_context *tctx,
2205 struct policy_handle *handle)
2207 struct lsa_QueryDomainInformationPolicy r;
2212 printf("\nTesting QueryDomainInformationPolicy\n");
2215 r.in.handle = handle;
2218 printf("\ntrying QueryDomainInformationPolicy level %d\n", i);
2220 status = dcerpc_lsa_QueryDomainInformationPolicy(p, tctx, &r);
2222 /* If the server does not support EFS, then this is the correct return */
2223 if (i == LSA_DOMAIN_INFO_POLICY_EFS && NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
2225 } else if (!NT_STATUS_IS_OK(status)) {
2226 printf("QueryDomainInformationPolicy failed - %s\n", nt_errstr(status));
2236 static bool test_QueryInfoPolicy(struct dcerpc_pipe *p,
2237 struct torture_context *tctx,
2238 struct policy_handle *handle)
2240 struct lsa_QueryInfoPolicy r;
2244 printf("\nTesting QueryInfoPolicy\n");
2246 for (i=1;i<13;i++) {
2247 r.in.handle = handle;
2250 printf("\ntrying QueryInfoPolicy level %d\n", i);
2252 status = dcerpc_lsa_QueryInfoPolicy(p, tctx, &r);
2255 case LSA_POLICY_INFO_DB:
2256 case LSA_POLICY_INFO_AUDIT_FULL_SET:
2257 case LSA_POLICY_INFO_AUDIT_FULL_QUERY:
2258 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
2259 printf("server should have failed level %u: %s\n", i, nt_errstr(status));
2263 case LSA_POLICY_INFO_DOMAIN:
2264 case LSA_POLICY_INFO_ACCOUNT_DOMAIN:
2265 case LSA_POLICY_INFO_DNS:
2266 if (!NT_STATUS_IS_OK(status)) {
2267 printf("QueryInfoPolicy failed - %s\n", nt_errstr(status));
2272 if (torture_setting_bool(tctx, "samba4", false)) {
2273 /* Other levels not implemented yet */
2274 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_INFO_CLASS)) {
2275 printf("QueryInfoPolicy failed - %s\n", nt_errstr(status));
2278 } else if (!NT_STATUS_IS_OK(status)) {
2279 printf("QueryInfoPolicy failed - %s\n", nt_errstr(status));
2285 if (NT_STATUS_IS_OK(status) && i == LSA_POLICY_INFO_DNS) {
2286 /* Let's look up some of these names */
2288 struct lsa_TransNameArray tnames;
2290 tnames.names = talloc_zero_array(tctx, struct lsa_TranslatedName, tnames.count);
2291 tnames.names[0].name.string = r.out.info->dns.name.string;
2292 tnames.names[0].sid_type = SID_NAME_DOMAIN;
2293 tnames.names[1].name.string = r.out.info->dns.dns_domain.string;
2294 tnames.names[1].sid_type = SID_NAME_DOMAIN;
2295 tnames.names[2].name.string = talloc_asprintf(tctx, "%s\\", r.out.info->dns.name.string);
2296 tnames.names[2].sid_type = SID_NAME_DOMAIN;
2297 tnames.names[3].name.string = talloc_asprintf(tctx, "%s\\", r.out.info->dns.dns_domain.string);
2298 tnames.names[3].sid_type = SID_NAME_DOMAIN;
2299 tnames.names[4].name.string = talloc_asprintf(tctx, "%s\\guest", r.out.info->dns.name.string);
2300 tnames.names[4].sid_type = SID_NAME_USER;
2301 tnames.names[5].name.string = talloc_asprintf(tctx, "%s\\krbtgt", r.out.info->dns.name.string);
2302 tnames.names[5].sid_type = SID_NAME_USER;
2303 tnames.names[6].name.string = talloc_asprintf(tctx, "%s\\guest", r.out.info->dns.dns_domain.string);
2304 tnames.names[6].sid_type = SID_NAME_USER;
2305 tnames.names[7].name.string = talloc_asprintf(tctx, "%s\\krbtgt", r.out.info->dns.dns_domain.string);
2306 tnames.names[7].sid_type = SID_NAME_USER;
2307 tnames.names[8].name.string = talloc_asprintf(tctx, "krbtgt@%s", r.out.info->dns.name.string);
2308 tnames.names[8].sid_type = SID_NAME_USER;
2309 tnames.names[9].name.string = talloc_asprintf(tctx, "krbtgt@%s", r.out.info->dns.dns_domain.string);
2310 tnames.names[9].sid_type = SID_NAME_USER;
2311 tnames.names[10].name.string = talloc_asprintf(tctx, "%s\\"TEST_MACHINENAME "$", r.out.info->dns.name.string);
2312 tnames.names[10].sid_type = SID_NAME_USER;
2313 tnames.names[11].name.string = talloc_asprintf(tctx, "%s\\"TEST_MACHINENAME "$", r.out.info->dns.dns_domain.string);
2314 tnames.names[11].sid_type = SID_NAME_USER;
2315 tnames.names[12].name.string = talloc_asprintf(tctx, TEST_MACHINENAME "$@%s", r.out.info->dns.name.string);
2316 tnames.names[12].sid_type = SID_NAME_USER;
2317 tnames.names[13].name.string = talloc_asprintf(tctx, TEST_MACHINENAME "$@%s", r.out.info->dns.dns_domain.string);
2318 tnames.names[13].sid_type = SID_NAME_USER;
2319 ret &= test_LookupNames(p, tctx, handle, &tnames);
2327 static bool test_QueryInfoPolicy2(struct dcerpc_pipe *p,
2328 struct torture_context *tctx,
2329 struct policy_handle *handle)
2331 struct lsa_QueryInfoPolicy2 r;
2335 printf("\nTesting QueryInfoPolicy2\n");
2336 for (i=1;i<13;i++) {
2337 r.in.handle = handle;
2340 printf("\ntrying QueryInfoPolicy2 level %d\n", i);
2342 status = dcerpc_lsa_QueryInfoPolicy2(p, tctx, &r);
2345 case LSA_POLICY_INFO_DB:
2346 case LSA_POLICY_INFO_AUDIT_FULL_SET:
2347 case LSA_POLICY_INFO_AUDIT_FULL_QUERY:
2348 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
2349 printf("server should have failed level %u: %s\n", i, nt_errstr(status));
2353 case LSA_POLICY_INFO_DOMAIN:
2354 case LSA_POLICY_INFO_ACCOUNT_DOMAIN:
2355 case LSA_POLICY_INFO_DNS:
2356 if (!NT_STATUS_IS_OK(status)) {
2357 printf("QueryInfoPolicy2 failed - %s\n", nt_errstr(status));
2362 if (torture_setting_bool(tctx, "samba4", false)) {
2363 /* Other levels not implemented yet */
2364 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_INFO_CLASS)) {
2365 printf("QueryInfoPolicy2 failed - %s\n", nt_errstr(status));
2368 } else if (!NT_STATUS_IS_OK(status)) {
2369 printf("QueryInfoPolicy2 failed - %s\n", nt_errstr(status));
2379 static bool test_GetUserName(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
2381 struct lsa_GetUserName r;
2384 struct lsa_StringPointer authority_name_p;
2386 printf("\nTesting GetUserName\n");
2388 r.in.system_name = "\\";
2389 r.in.account_name = NULL;
2390 r.in.authority_name = &authority_name_p;
2391 authority_name_p.string = NULL;
2393 status = dcerpc_lsa_GetUserName(p, mem_ctx, &r);
2395 if (!NT_STATUS_IS_OK(status)) {
2396 printf("GetUserName failed - %s\n", nt_errstr(status));
2403 bool test_lsa_Close(struct dcerpc_pipe *p,
2404 TALLOC_CTX *mem_ctx,
2405 struct policy_handle *handle)
2409 struct policy_handle handle2;
2411 printf("\ntesting Close\n");
2413 r.in.handle = handle;
2414 r.out.handle = &handle2;
2416 status = dcerpc_lsa_Close(p, mem_ctx, &r);
2417 if (!NT_STATUS_IS_OK(status)) {
2418 printf("Close failed - %s\n", nt_errstr(status));
2422 status = dcerpc_lsa_Close(p, mem_ctx, &r);
2423 /* its really a fault - we need a status code for rpc fault */
2424 if (!NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
2425 printf("Close failed - %s\n", nt_errstr(status));
2434 bool torture_rpc_lsa(struct torture_context *tctx)
2437 struct dcerpc_pipe *p;
2439 struct policy_handle *handle;
2440 struct test_join *join = NULL;
2441 struct cli_credentials *machine_creds;
2443 status = torture_rpc_connection(tctx, &p, &ndr_table_lsarpc);
2444 if (!NT_STATUS_IS_OK(status)) {
2448 if (!test_OpenPolicy(p, tctx)) {
2452 if (!test_lsa_OpenPolicy2(p, tctx, &handle)) {
2457 join = torture_join_domain(tctx, TEST_MACHINENAME, ACB_WSTRUST, &machine_creds);
2462 if (!test_LookupNames_wellknown(p, tctx, handle)) {
2466 if (!test_LookupNames_bogus(p, tctx, handle)) {
2470 if (!test_LookupSids_async(p, tctx, handle)) {
2474 if (!test_QueryDomainInfoPolicy(p, tctx, handle)) {
2478 if (!test_CreateAccount(p, tctx, handle)) {
2482 if (!test_CreateSecret(p, tctx, handle)) {
2486 if (!test_CreateTrustedDomain(p, tctx, handle)) {
2490 if (!test_CreateTrustedDomainEx2(p, tctx, tctx, handle)) {
2494 if (!test_EnumAccounts(p, tctx, handle)) {
2498 if (!test_EnumPrivs(p, tctx, handle)) {
2502 if (!test_QueryInfoPolicy(p, tctx, handle)) {
2506 if (!test_QueryInfoPolicy2(p, tctx, handle)) {
2510 if (!test_Delete(p, tctx, handle)) {
2514 if (!test_many_LookupSids(p, tctx, handle)) {
2518 if (!test_lsa_Close(p, tctx, handle)) {
2522 torture_leave_domain(tctx, join);
2525 if (!test_many_LookupSids(p, tctx, handle)) {
2530 if (!test_GetUserName(p, tctx)) {
2537 bool torture_rpc_lsa_get_user(struct torture_context *torture)
2540 struct dcerpc_pipe *p;
2541 TALLOC_CTX *mem_ctx;
2544 mem_ctx = talloc_init("torture_rpc_lsa_get_user");
2546 status = torture_rpc_connection(torture, &p, &ndr_table_lsarpc);
2547 if (!NT_STATUS_IS_OK(status)) {
2548 talloc_free(mem_ctx);
2552 if (!test_GetUserName(p, mem_ctx)) {
2556 talloc_free(mem_ctx);