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 "lib/events/events.h"
27 #include "libcli/security/security.h"
28 #include "libcli/auth/libcli_auth.h"
29 #include "torture/rpc/rpc.h"
31 static void init_lsa_String(struct lsa_String *name, const char *s)
36 static BOOL test_OpenPolicy(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
38 struct lsa_ObjectAttribute attr;
39 struct policy_handle handle;
40 struct lsa_QosInfo qos;
41 struct lsa_OpenPolicy r;
43 uint16_t system_name = '\\';
45 printf("\ntesting OpenPolicy\n");
48 qos.impersonation_level = 2;
50 qos.effective_only = 0;
54 attr.object_name = NULL;
59 r.in.system_name = &system_name;
61 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
62 r.out.handle = &handle;
64 status = dcerpc_lsa_OpenPolicy(p, mem_ctx, &r);
65 if (!NT_STATUS_IS_OK(status)) {
66 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
67 NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
68 printf("not considering %s to be an error\n", nt_errstr(status));
71 printf("OpenPolicy failed - %s\n", nt_errstr(status));
79 BOOL test_lsa_OpenPolicy2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
80 struct policy_handle **handle)
82 struct lsa_ObjectAttribute attr;
83 struct lsa_QosInfo qos;
84 struct lsa_OpenPolicy2 r;
87 printf("\ntesting OpenPolicy2\n");
89 *handle = talloc(mem_ctx, struct policy_handle);
95 qos.impersonation_level = 2;
97 qos.effective_only = 0;
100 attr.root_dir = NULL;
101 attr.object_name = NULL;
103 attr.sec_desc = NULL;
106 r.in.system_name = "\\";
108 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
109 r.out.handle = *handle;
111 status = dcerpc_lsa_OpenPolicy2(p, mem_ctx, &r);
112 if (!NT_STATUS_IS_OK(status)) {
113 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
114 NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
115 printf("not considering %s to be an error\n", nt_errstr(status));
116 talloc_free(*handle);
120 printf("OpenPolicy2 failed - %s\n", nt_errstr(status));
127 static BOOL test_LookupNames(struct dcerpc_pipe *p,
129 struct policy_handle *handle,
130 struct lsa_TransNameArray *tnames)
132 struct lsa_LookupNames r;
133 struct lsa_TransSidArray sids;
134 struct lsa_String *names;
139 printf("\nTesting LookupNames with %d names\n", tnames->count);
144 names = talloc_array(mem_ctx, struct lsa_String, tnames->count);
145 for (i=0;i<tnames->count;i++) {
146 init_lsa_String(&names[i], tnames->names[i].name.string);
149 r.in.handle = handle;
150 r.in.num_names = tnames->count;
155 r.out.count = &count;
158 status = dcerpc_lsa_LookupNames(p, mem_ctx, &r);
159 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
160 printf("LookupNames failed - %s\n", nt_errstr(status));
169 static BOOL test_LookupNames2(struct dcerpc_pipe *p,
171 struct policy_handle *handle,
172 struct lsa_TransNameArray2 *tnames)
174 struct lsa_LookupNames2 r;
175 struct lsa_TransSidArray2 sids;
176 struct lsa_String *names;
181 printf("\nTesting LookupNames2 with %d names\n", tnames->count);
186 names = talloc_array(mem_ctx, struct lsa_String, tnames->count);
187 for (i=0;i<tnames->count;i++) {
188 init_lsa_String(&names[i], tnames->names[i].name.string);
191 r.in.handle = handle;
192 r.in.num_names = tnames->count;
199 r.out.count = &count;
202 status = dcerpc_lsa_LookupNames2(p, mem_ctx, &r);
203 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
204 printf("LookupNames2 failed - %s\n", nt_errstr(status));
214 static BOOL test_LookupNames3(struct dcerpc_pipe *p,
216 struct policy_handle *handle,
217 struct lsa_TransNameArray2 *tnames)
219 struct lsa_LookupNames3 r;
220 struct lsa_TransSidArray3 sids;
221 struct lsa_String *names;
226 printf("\nTesting LookupNames3 with %d names\n", tnames->count);
231 names = talloc_array(mem_ctx, struct lsa_String, tnames->count);
232 for (i=0;i<tnames->count;i++) {
233 init_lsa_String(&names[i], tnames->names[i].name.string);
236 r.in.handle = handle;
237 r.in.num_names = tnames->count;
244 r.out.count = &count;
247 status = dcerpc_lsa_LookupNames3(p, mem_ctx, &r);
248 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
249 printf("LookupNames3 failed - %s\n", nt_errstr(status));
258 static BOOL test_LookupNames4(struct dcerpc_pipe *p,
260 struct lsa_TransNameArray2 *tnames)
262 struct lsa_LookupNames4 r;
263 struct lsa_TransSidArray3 sids;
264 struct lsa_String *names;
269 printf("\nTesting LookupNames4 with %d names\n", tnames->count);
274 names = talloc_array(mem_ctx, struct lsa_String, tnames->count);
275 for (i=0;i<tnames->count;i++) {
276 init_lsa_String(&names[i], tnames->names[i].name.string);
279 r.in.num_names = tnames->count;
286 r.out.count = &count;
289 status = dcerpc_lsa_LookupNames4(p, mem_ctx, &r);
290 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
291 printf("LookupNames4 failed - %s\n", nt_errstr(status));
301 static BOOL test_LookupSids(struct dcerpc_pipe *p,
303 struct policy_handle *handle,
304 struct lsa_SidArray *sids)
306 struct lsa_LookupSids r;
307 struct lsa_TransNameArray names;
308 uint32_t count = sids->num_sids;
311 printf("\nTesting LookupSids\n");
316 r.in.handle = handle;
321 r.out.count = &count;
322 r.out.names = &names;
324 status = dcerpc_lsa_LookupSids(p, mem_ctx, &r);
325 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
326 printf("LookupSids failed - %s\n", nt_errstr(status));
332 if (!test_LookupNames(p, mem_ctx, handle, &names)) {
340 static BOOL test_LookupSids2(struct dcerpc_pipe *p,
342 struct policy_handle *handle,
343 struct lsa_SidArray *sids)
345 struct lsa_LookupSids2 r;
346 struct lsa_TransNameArray2 names;
347 uint32_t count = sids->num_sids;
350 printf("\nTesting LookupSids2\n");
355 r.in.handle = handle;
362 r.out.count = &count;
363 r.out.names = &names;
365 status = dcerpc_lsa_LookupSids2(p, mem_ctx, &r);
366 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
367 printf("LookupSids2 failed - %s\n", nt_errstr(status));
373 if (!test_LookupNames2(p, mem_ctx, handle, &names)) {
377 if (!test_LookupNames3(p, mem_ctx, handle, &names)) {
384 static BOOL test_LookupSids3(struct dcerpc_pipe *p,
386 struct lsa_SidArray *sids)
388 struct lsa_LookupSids3 r;
389 struct lsa_TransNameArray2 names;
390 uint32_t count = sids->num_sids;
393 printf("\nTesting LookupSids3\n");
404 r.out.count = &count;
405 r.out.names = &names;
407 status = dcerpc_lsa_LookupSids3(p, mem_ctx, &r);
408 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
409 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
410 NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
411 printf("not considering %s to be an error\n", nt_errstr(status));
414 printf("LookupSids3 failed - %s - not considered an error\n",
421 if (!test_LookupNames4(p, mem_ctx, &names)) {
428 BOOL test_many_LookupSids(struct dcerpc_pipe *p,
430 struct policy_handle *handle)
434 struct lsa_SidArray sids;
437 printf("\nTesting LookupSids with lots of SIDs\n");
441 sids.sids = talloc_array(mem_ctx, struct lsa_SidPtr, sids.num_sids);
443 for (i=0; i<sids.num_sids; i++) {
444 const char *sidstr = "S-1-5-32-545";
445 sids.sids[i].sid = dom_sid_parse_talloc(mem_ctx, sidstr);
448 count = sids.num_sids;
451 struct lsa_LookupSids r;
452 struct lsa_TransNameArray names;
456 r.in.handle = handle;
460 r.in.count = &names.count;
461 r.out.count = &count;
462 r.out.names = &names;
464 status = dcerpc_lsa_LookupSids(p, mem_ctx, &r);
465 if (!NT_STATUS_IS_OK(status) &&
466 !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
467 printf("LookupSids failed - %s\n", nt_errstr(status));
473 if (!test_LookupNames(p, mem_ctx, handle, &names)) {
477 struct lsa_LookupSids3 r;
478 struct lsa_TransNameArray2 names;
483 printf("\nTesting LookupSids3\n");
491 r.out.count = &count;
492 r.out.names = &names;
494 status = dcerpc_lsa_LookupSids3(p, mem_ctx, &r);
495 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
496 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
497 NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
498 printf("not considering %s to be an error\n", nt_errstr(status));
501 printf("LookupSids3 failed - %s\n",
505 if (!test_LookupNames4(p, mem_ctx, &names)) {
517 static void lookupsids_cb(struct rpc_request *req)
519 int *replies = (int *)req->async.private_data;
522 status = dcerpc_ndr_request_recv(req);
523 if (!NT_STATUS_IS_OK(status)) {
524 printf("lookupsids returned %s\n", nt_errstr(status));
533 static BOOL test_LookupSids_async(struct dcerpc_pipe *p,
535 struct policy_handle *handle)
537 struct lsa_SidArray sids;
538 struct lsa_SidPtr sidptr;
540 struct lsa_TransNameArray *names;
541 struct lsa_LookupSids *r;
542 struct rpc_request **req;
545 const int num_async_requests = 50;
547 count = talloc_array(mem_ctx, uint32_t, num_async_requests);
548 names = talloc_array(mem_ctx, struct lsa_TransNameArray, num_async_requests);
549 r = talloc_array(mem_ctx, struct lsa_LookupSids, num_async_requests);
551 printf("\nTesting %d async lookupsids request\n", num_async_requests);
553 req = talloc_array(mem_ctx, struct rpc_request *, num_async_requests);
557 sidptr.sid = dom_sid_parse_talloc(mem_ctx, "S-1-5-32-545");
561 for (i=0; i<num_async_requests; i++) {
564 names[i].names = NULL;
566 r[i].in.handle = handle;
567 r[i].in.sids = &sids;
568 r[i].in.names = &names[i];
570 r[i].in.count = &names[i].count;
571 r[i].out.count = &count[i];
572 r[i].out.names = &names[i];
574 req[i] = dcerpc_lsa_LookupSids_send(p, req, &r[i]);
575 if (req[i] == NULL) {
580 req[i]->async.callback = lookupsids_cb;
581 req[i]->async.private_data = &replies;
584 while (replies >= 0 && replies < num_async_requests) {
585 event_loop_once(p->conn->event_ctx);
597 static BOOL test_LookupPrivValue(struct dcerpc_pipe *p,
599 struct policy_handle *handle,
600 struct lsa_String *name)
603 struct lsa_LookupPrivValue r;
604 struct lsa_LUID luid;
606 r.in.handle = handle;
610 status = dcerpc_lsa_LookupPrivValue(p, mem_ctx, &r);
611 if (!NT_STATUS_IS_OK(status)) {
612 printf("\nLookupPrivValue failed - %s\n", nt_errstr(status));
619 static BOOL test_LookupPrivName(struct dcerpc_pipe *p,
621 struct policy_handle *handle,
622 struct lsa_LUID *luid)
625 struct lsa_LookupPrivName r;
627 r.in.handle = handle;
630 status = dcerpc_lsa_LookupPrivName(p, mem_ctx, &r);
631 if (!NT_STATUS_IS_OK(status)) {
632 printf("\nLookupPrivName failed - %s\n", nt_errstr(status));
639 static BOOL test_RemovePrivilegesFromAccount(struct dcerpc_pipe *p,
641 struct policy_handle *acct_handle,
642 struct lsa_LUID *luid)
645 struct lsa_RemovePrivilegesFromAccount r;
646 struct lsa_PrivilegeSet privs;
649 printf("Testing RemovePrivilegesFromAccount\n");
651 r.in.handle = acct_handle;
657 privs.set = talloc_array(mem_ctx, struct lsa_LUIDAttribute, 1);
658 privs.set[0].luid = *luid;
659 privs.set[0].attribute = 0;
661 status = dcerpc_lsa_RemovePrivilegesFromAccount(p, mem_ctx, &r);
662 if (!NT_STATUS_IS_OK(status)) {
663 printf("RemovePrivilegesFromAccount failed - %s\n", nt_errstr(status));
670 static BOOL test_AddPrivilegesToAccount(struct dcerpc_pipe *p,
672 struct policy_handle *acct_handle,
673 struct lsa_LUID *luid)
676 struct lsa_AddPrivilegesToAccount r;
677 struct lsa_PrivilegeSet privs;
680 printf("Testing AddPrivilegesToAccount\n");
682 r.in.handle = acct_handle;
687 privs.set = talloc_array(mem_ctx, struct lsa_LUIDAttribute, 1);
688 privs.set[0].luid = *luid;
689 privs.set[0].attribute = 0;
691 status = dcerpc_lsa_AddPrivilegesToAccount(p, mem_ctx, &r);
692 if (!NT_STATUS_IS_OK(status)) {
693 printf("AddPrivilegesToAccount failed - %s\n", nt_errstr(status));
700 static BOOL test_EnumPrivsAccount(struct dcerpc_pipe *p,
702 struct policy_handle *handle,
703 struct policy_handle *acct_handle)
706 struct lsa_EnumPrivsAccount r;
709 printf("Testing EnumPrivsAccount\n");
711 r.in.handle = acct_handle;
713 status = dcerpc_lsa_EnumPrivsAccount(p, mem_ctx, &r);
714 if (!NT_STATUS_IS_OK(status)) {
715 printf("EnumPrivsAccount failed - %s\n", nt_errstr(status));
719 if (r.out.privs && r.out.privs->count > 0) {
721 for (i=0;i<r.out.privs->count;i++) {
722 test_LookupPrivName(p, mem_ctx, handle,
723 &r.out.privs->set[i].luid);
726 ret &= test_RemovePrivilegesFromAccount(p, mem_ctx, acct_handle,
727 &r.out.privs->set[0].luid);
728 ret &= test_AddPrivilegesToAccount(p, mem_ctx, acct_handle,
729 &r.out.privs->set[0].luid);
735 static BOOL test_Delete(struct dcerpc_pipe *p,
737 struct policy_handle *handle)
742 printf("testing Delete\n");
744 r.in.handle = handle;
745 status = dcerpc_lsa_Delete(p, mem_ctx, &r);
746 if (!NT_STATUS_IS_OK(status)) {
747 printf("Delete failed - %s\n", nt_errstr(status));
755 static BOOL test_CreateAccount(struct dcerpc_pipe *p,
757 struct policy_handle *handle)
760 struct lsa_CreateAccount r;
761 struct dom_sid2 *newsid;
762 struct policy_handle acct_handle;
764 newsid = dom_sid_parse_talloc(mem_ctx, "S-1-5-12349876-4321-2854");
766 printf("Testing CreateAccount\n");
768 r.in.handle = handle;
770 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
771 r.out.acct_handle = &acct_handle;
773 status = dcerpc_lsa_CreateAccount(p, mem_ctx, &r);
774 if (!NT_STATUS_IS_OK(status)) {
775 printf("CreateAccount failed - %s\n", nt_errstr(status));
779 if (!test_Delete(p, mem_ctx, &acct_handle)) {
786 static BOOL test_DeleteTrustedDomain(struct dcerpc_pipe *p,
788 struct policy_handle *handle,
789 struct lsa_StringLarge name)
792 struct lsa_OpenTrustedDomainByName r;
793 struct policy_handle trustdom_handle;
795 r.in.handle = handle;
796 r.in.name.string = name.string;
797 r.in.access_mask = SEC_STD_DELETE;
798 r.out.trustdom_handle = &trustdom_handle;
800 status = dcerpc_lsa_OpenTrustedDomainByName(p, mem_ctx, &r);
801 if (!NT_STATUS_IS_OK(status)) {
802 printf("lsa_OpenTrustedDomainByName failed - %s\n", nt_errstr(status));
806 if (!test_Delete(p, mem_ctx, &trustdom_handle)) {
813 static BOOL test_DeleteTrustedDomainBySid(struct dcerpc_pipe *p,
815 struct policy_handle *handle,
819 struct lsa_DeleteTrustedDomain r;
821 r.in.handle = handle;
824 status = dcerpc_lsa_DeleteTrustedDomain(p, mem_ctx, &r);
825 if (!NT_STATUS_IS_OK(status)) {
826 printf("lsa_DeleteTrustedDomain failed - %s\n", nt_errstr(status));
834 static BOOL test_CreateSecret(struct dcerpc_pipe *p,
836 struct policy_handle *handle)
839 struct lsa_CreateSecret r;
840 struct lsa_OpenSecret r2;
841 struct lsa_SetSecret r3;
842 struct lsa_QuerySecret r4;
843 struct lsa_SetSecret r5;
844 struct lsa_QuerySecret r6;
845 struct lsa_SetSecret r7;
846 struct lsa_QuerySecret r8;
847 struct policy_handle sec_handle, sec_handle2, sec_handle3;
849 struct lsa_DATA_BUF buf1;
850 struct lsa_DATA_BUF_PTR bufp1;
851 struct lsa_DATA_BUF_PTR bufp2;
854 DATA_BLOB session_key;
855 NTTIME old_mtime, new_mtime;
856 DATA_BLOB blob1, blob2;
857 const char *secret1 = "abcdef12345699qwerty";
859 const char *secret3 = "ABCDEF12345699QWERTY";
861 const char *secret5 = "NEW-SAMBA4-SECRET";
866 const int GLOBAL = 1;
868 secname[LOCAL] = talloc_asprintf(mem_ctx, "torturesecret-%u", (uint_t)random());
869 secname[GLOBAL] = talloc_asprintf(mem_ctx, "G$torturesecret-%u", (uint_t)random());
871 for (i=0; i< 2; i++) {
872 printf("Testing CreateSecret of %s\n", secname[i]);
874 init_lsa_String(&r.in.name, secname[i]);
876 r.in.handle = handle;
877 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
878 r.out.sec_handle = &sec_handle;
880 status = dcerpc_lsa_CreateSecret(p, mem_ctx, &r);
881 if (!NT_STATUS_IS_OK(status)) {
882 printf("CreateSecret failed - %s\n", nt_errstr(status));
886 r.in.handle = handle;
887 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
888 r.out.sec_handle = &sec_handle3;
890 status = dcerpc_lsa_CreateSecret(p, mem_ctx, &r);
891 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
892 printf("CreateSecret should have failed OBJECT_NAME_COLLISION - %s\n", nt_errstr(status));
896 r2.in.handle = handle;
897 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
898 r2.in.name = r.in.name;
899 r2.out.sec_handle = &sec_handle2;
901 printf("Testing OpenSecret\n");
903 status = dcerpc_lsa_OpenSecret(p, mem_ctx, &r2);
904 if (!NT_STATUS_IS_OK(status)) {
905 printf("OpenSecret failed - %s\n", nt_errstr(status));
909 status = dcerpc_fetch_session_key(p, &session_key);
910 if (!NT_STATUS_IS_OK(status)) {
911 printf("dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
915 enc_key = sess_encrypt_string(secret1, &session_key);
917 r3.in.sec_handle = &sec_handle;
918 r3.in.new_val = &buf1;
919 r3.in.old_val = NULL;
920 r3.in.new_val->data = enc_key.data;
921 r3.in.new_val->length = enc_key.length;
922 r3.in.new_val->size = enc_key.length;
924 printf("Testing SetSecret\n");
926 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r3);
927 if (!NT_STATUS_IS_OK(status)) {
928 printf("SetSecret failed - %s\n", nt_errstr(status));
932 r3.in.sec_handle = &sec_handle;
933 r3.in.new_val = &buf1;
934 r3.in.old_val = NULL;
935 r3.in.new_val->data = enc_key.data;
936 r3.in.new_val->length = enc_key.length;
937 r3.in.new_val->size = enc_key.length;
939 /* break the encrypted data */
942 printf("Testing SetSecret with broken key\n");
944 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r3);
945 if (!NT_STATUS_EQUAL(status, NT_STATUS_UNKNOWN_REVISION)) {
946 printf("SetSecret should have failed UNKNOWN_REVISION - %s\n", nt_errstr(status));
950 data_blob_free(&enc_key);
952 ZERO_STRUCT(new_mtime);
953 ZERO_STRUCT(old_mtime);
955 /* fetch the secret back again */
956 r4.in.sec_handle = &sec_handle;
957 r4.in.new_val = &bufp1;
958 r4.in.new_mtime = &new_mtime;
959 r4.in.old_val = NULL;
960 r4.in.old_mtime = NULL;
964 printf("Testing QuerySecret\n");
965 status = dcerpc_lsa_QuerySecret(p, mem_ctx, &r4);
966 if (!NT_STATUS_IS_OK(status)) {
967 printf("QuerySecret failed - %s\n", nt_errstr(status));
970 if (r4.out.new_val == NULL || r4.out.new_val->buf == NULL) {
971 printf("No secret buffer returned\n");
974 blob1.data = r4.out.new_val->buf->data;
975 blob1.length = r4.out.new_val->buf->size;
977 blob2 = data_blob_talloc(mem_ctx, NULL, blob1.length);
979 secret2 = sess_decrypt_string(mem_ctx,
980 &blob1, &session_key);
982 if (strcmp(secret1, secret2) != 0) {
983 printf("Returned secret '%s' doesn't match '%s'\n",
990 enc_key = sess_encrypt_string(secret3, &session_key);
992 r5.in.sec_handle = &sec_handle;
993 r5.in.new_val = &buf1;
994 r5.in.old_val = NULL;
995 r5.in.new_val->data = enc_key.data;
996 r5.in.new_val->length = enc_key.length;
997 r5.in.new_val->size = enc_key.length;
999 printf("Testing SetSecret (existing value should move to old)\n");
1001 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r5);
1002 if (!NT_STATUS_IS_OK(status)) {
1003 printf("SetSecret failed - %s\n", nt_errstr(status));
1007 data_blob_free(&enc_key);
1009 ZERO_STRUCT(new_mtime);
1010 ZERO_STRUCT(old_mtime);
1012 /* fetch the secret back again */
1013 r6.in.sec_handle = &sec_handle;
1014 r6.in.new_val = &bufp1;
1015 r6.in.new_mtime = &new_mtime;
1016 r6.in.old_val = &bufp2;
1017 r6.in.old_mtime = &old_mtime;
1022 status = dcerpc_lsa_QuerySecret(p, mem_ctx, &r6);
1023 if (!NT_STATUS_IS_OK(status)) {
1024 printf("QuerySecret failed - %s\n", nt_errstr(status));
1029 if (r6.out.new_val->buf == NULL || r6.out.old_val->buf == NULL
1030 || r6.out.new_mtime == NULL || r6.out.old_mtime == NULL) {
1031 printf("Both secret buffers and both times not returned\n");
1035 blob1.data = r6.out.new_val->buf->data;
1036 blob1.length = r6.out.new_val->buf->size;
1038 blob2 = data_blob_talloc(mem_ctx, NULL, blob1.length);
1040 secret4 = sess_decrypt_string(mem_ctx,
1041 &blob1, &session_key);
1043 if (strcmp(secret3, secret4) != 0) {
1044 printf("Returned NEW secret %s doesn't match %s\n", secret4, secret3);
1048 blob1.data = r6.out.old_val->buf->data;
1049 blob1.length = r6.out.old_val->buf->length;
1051 blob2 = data_blob_talloc(mem_ctx, NULL, blob1.length);
1053 secret2 = sess_decrypt_string(mem_ctx,
1054 &blob1, &session_key);
1056 if (strcmp(secret1, secret2) != 0) {
1057 printf("Returned OLD secret %s doesn't match %s\n", secret2, secret1);
1061 if (*r6.out.new_mtime == *r6.out.old_mtime) {
1062 printf("Returned secret %s had same mtime for both secrets: %s\n",
1064 nt_time_string(mem_ctx, *r6.out.new_mtime));
1070 enc_key = sess_encrypt_string(secret5, &session_key);
1072 r7.in.sec_handle = &sec_handle;
1073 r7.in.old_val = &buf1;
1074 r7.in.old_val->data = enc_key.data;
1075 r7.in.old_val->length = enc_key.length;
1076 r7.in.old_val->size = enc_key.length;
1077 r7.in.new_val = NULL;
1079 printf("Testing SetSecret of old Secret only\n");
1081 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r7);
1082 if (!NT_STATUS_IS_OK(status)) {
1083 printf("SetSecret failed - %s\n", nt_errstr(status));
1087 data_blob_free(&enc_key);
1089 /* fetch the secret back again */
1090 r8.in.sec_handle = &sec_handle;
1091 r8.in.new_val = &bufp1;
1092 r8.in.new_mtime = &new_mtime;
1093 r8.in.old_val = &bufp2;
1094 r8.in.old_mtime = &old_mtime;
1099 status = dcerpc_lsa_QuerySecret(p, mem_ctx, &r8);
1100 if (!NT_STATUS_IS_OK(status)) {
1101 printf("QuerySecret failed - %s\n", nt_errstr(status));
1104 if (!r8.out.new_val || !r8.out.old_val) {
1105 printf("in/out pointers not returned, despite being set on in for QuerySecret\n");
1107 } else if (r8.out.new_val->buf == NULL) {
1109 printf("NEW secret buffer not returned after GLOBAL OLD set\n");
1112 } else if (r8.out.old_val->buf == NULL) {
1113 printf("OLD secret buffer not returned after OLD set\n");
1115 } else if (r8.out.new_mtime == NULL || r8.out.old_mtime == NULL) {
1116 printf("Both times not returned after OLD set\n");
1120 printf("NEW secret buffer should not be returned after LOCAL OLD set\n");
1123 blob1.data = r8.out.new_val->buf->data;
1124 blob1.length = r8.out.new_val->buf->length;
1126 blob2 = data_blob_talloc(mem_ctx, NULL, blob1.length);
1128 secret6 = sess_decrypt_string(mem_ctx,
1129 &blob1, &session_key);
1131 if (strcmp(secret3, secret4) != 0) {
1132 printf("Returned NEW secret '%s' doesn't match '%s'\n", secret4, secret3);
1136 blob1.data = r8.out.old_val->buf->data;
1137 blob1.length = r8.out.old_val->buf->size;
1139 blob2 = data_blob_talloc(mem_ctx, NULL, blob1.length);
1141 secret6 = sess_decrypt_string(mem_ctx,
1142 &blob1, &session_key);
1144 if (strcmp(secret5, secret6) != 0) {
1145 printf("Returned OLD secret %s doesn't match %s\n", secret5, secret6);
1149 if (*r8.out.new_mtime == *r8.out.old_mtime) {
1151 printf("Returned secret %s had same mtime for both secrets: %s\n",
1153 nt_time_string(mem_ctx, *r8.out.new_mtime));
1157 printf("Returned secret %s should have had same mtime for both secrets: %s != %s\n",
1159 nt_time_string(mem_ctx, *r8.out.old_mtime),
1160 nt_time_string(mem_ctx, *r8.out.new_mtime));
1166 if (!test_Delete(p, mem_ctx, &sec_handle)) {
1170 d.in.handle = &sec_handle2;
1171 status = dcerpc_lsa_Delete(p, mem_ctx, &d);
1172 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1173 printf("Second delete expected INVALID_HANDLE - %s\n", nt_errstr(status));
1177 printf("Testing OpenSecret of just-deleted secret\n");
1179 status = dcerpc_lsa_OpenSecret(p, mem_ctx, &r2);
1180 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
1181 printf("OpenSecret expected OBJECT_NAME_NOT_FOUND - %s\n", nt_errstr(status));
1192 static BOOL test_EnumAccountRights(struct dcerpc_pipe *p,
1193 TALLOC_CTX *mem_ctx,
1194 struct policy_handle *acct_handle,
1195 struct dom_sid *sid)
1198 struct lsa_EnumAccountRights r;
1199 struct lsa_RightSet rights;
1201 printf("Testing EnumAccountRights\n");
1203 r.in.handle = acct_handle;
1205 r.out.rights = &rights;
1207 status = dcerpc_lsa_EnumAccountRights(p, mem_ctx, &r);
1208 if (!NT_STATUS_IS_OK(status)) {
1209 printf("EnumAccountRights of %s failed - %s\n",
1210 dom_sid_string(mem_ctx, sid), nt_errstr(status));
1218 static BOOL test_QuerySecurity(struct dcerpc_pipe *p,
1219 TALLOC_CTX *mem_ctx,
1220 struct policy_handle *handle,
1221 struct policy_handle *acct_handle)
1224 struct lsa_QuerySecurity r;
1226 if (lp_parm_bool(-1, "torture", "samba4", False)) {
1227 printf("skipping QuerySecurity test against Samba4\n");
1231 printf("Testing QuerySecurity\n");
1233 r.in.handle = acct_handle;
1236 status = dcerpc_lsa_QuerySecurity(p, mem_ctx, &r);
1237 if (!NT_STATUS_IS_OK(status)) {
1238 printf("QuerySecurity failed - %s\n", nt_errstr(status));
1245 static BOOL test_OpenAccount(struct dcerpc_pipe *p,
1246 TALLOC_CTX *mem_ctx,
1247 struct policy_handle *handle,
1248 struct dom_sid *sid)
1251 struct lsa_OpenAccount r;
1252 struct policy_handle acct_handle;
1254 printf("Testing OpenAccount\n");
1256 r.in.handle = handle;
1258 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1259 r.out.acct_handle = &acct_handle;
1261 status = dcerpc_lsa_OpenAccount(p, mem_ctx, &r);
1262 if (!NT_STATUS_IS_OK(status)) {
1263 printf("OpenAccount failed - %s\n", nt_errstr(status));
1267 if (!test_EnumPrivsAccount(p, mem_ctx, handle, &acct_handle)) {
1271 if (!test_QuerySecurity(p, mem_ctx, handle, &acct_handle)) {
1278 static BOOL test_EnumAccounts(struct dcerpc_pipe *p,
1279 TALLOC_CTX *mem_ctx,
1280 struct policy_handle *handle)
1283 struct lsa_EnumAccounts r;
1284 struct lsa_SidArray sids1, sids2;
1285 uint32_t resume_handle = 0;
1289 printf("\ntesting EnumAccounts\n");
1291 r.in.handle = handle;
1292 r.in.resume_handle = &resume_handle;
1293 r.in.num_entries = 100;
1294 r.out.resume_handle = &resume_handle;
1295 r.out.sids = &sids1;
1299 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
1300 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
1303 if (!NT_STATUS_IS_OK(status)) {
1304 printf("EnumAccounts failed - %s\n", nt_errstr(status));
1308 if (!test_LookupSids(p, mem_ctx, handle, &sids1)) {
1312 if (!test_LookupSids2(p, mem_ctx, handle, &sids1)) {
1316 if (!test_LookupSids3(p, mem_ctx, &sids1)) {
1320 printf("testing all accounts\n");
1321 for (i=0;i<sids1.num_sids;i++) {
1322 ret &= test_OpenAccount(p, mem_ctx, handle, sids1.sids[i].sid);
1323 ret &= test_EnumAccountRights(p, mem_ctx, handle, sids1.sids[i].sid);
1328 if (sids1.num_sids < 3) {
1332 printf("trying EnumAccounts partial listing (asking for 1 at 2)\n");
1334 r.in.num_entries = 1;
1335 r.out.sids = &sids2;
1337 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
1338 if (!NT_STATUS_IS_OK(status)) {
1339 printf("EnumAccounts failed - %s\n", nt_errstr(status));
1343 if (sids2.num_sids != 1) {
1344 printf("Returned wrong number of entries (%d)\n", sids2.num_sids);
1351 static BOOL test_LookupPrivDisplayName(struct dcerpc_pipe *p,
1352 TALLOC_CTX *mem_ctx,
1353 struct policy_handle *handle,
1354 struct lsa_String *priv_name)
1356 struct lsa_LookupPrivDisplayName r;
1358 /* produce a reasonable range of language output without screwing up
1360 uint16_t language_id = (random() % 4) + 0x409;
1362 printf("testing LookupPrivDisplayName(%s)\n", priv_name->string);
1364 r.in.handle = handle;
1365 r.in.name = priv_name;
1366 r.in.language_id = &language_id;
1367 r.out.language_id = &language_id;
1370 status = dcerpc_lsa_LookupPrivDisplayName(p, mem_ctx, &r);
1371 if (!NT_STATUS_IS_OK(status)) {
1372 printf("LookupPrivDisplayName failed - %s\n", nt_errstr(status));
1375 printf("%s -> \"%s\" (language 0x%x/0x%x)\n",
1376 priv_name->string, r.out.disp_name->string,
1377 *r.in.language_id, *r.out.language_id);
1382 static BOOL test_EnumAccountsWithUserRight(struct dcerpc_pipe *p,
1383 TALLOC_CTX *mem_ctx,
1384 struct policy_handle *handle,
1385 struct lsa_String *priv_name)
1387 struct lsa_EnumAccountsWithUserRight r;
1388 struct lsa_SidArray sids;
1393 printf("testing EnumAccountsWithUserRight(%s)\n", priv_name->string);
1395 r.in.handle = handle;
1396 r.in.name = priv_name;
1399 status = dcerpc_lsa_EnumAccountsWithUserRight(p, mem_ctx, &r);
1401 /* NT_STATUS_NO_MORE_ENTRIES means noone has this privilege */
1402 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
1406 if (!NT_STATUS_IS_OK(status)) {
1407 printf("EnumAccountsWithUserRight failed - %s\n", nt_errstr(status));
1415 static BOOL test_EnumPrivs(struct dcerpc_pipe *p,
1416 TALLOC_CTX *mem_ctx,
1417 struct policy_handle *handle)
1420 struct lsa_EnumPrivs r;
1421 struct lsa_PrivArray privs1;
1422 uint32_t resume_handle = 0;
1426 printf("\ntesting EnumPrivs\n");
1428 r.in.handle = handle;
1429 r.in.resume_handle = &resume_handle;
1430 r.in.max_count = 100;
1431 r.out.resume_handle = &resume_handle;
1432 r.out.privs = &privs1;
1435 status = dcerpc_lsa_EnumPrivs(p, mem_ctx, &r);
1436 if (!NT_STATUS_IS_OK(status)) {
1437 printf("EnumPrivs failed - %s\n", nt_errstr(status));
1441 for (i = 0; i< privs1.count; i++) {
1442 test_LookupPrivDisplayName(p, mem_ctx, handle, (struct lsa_String *)&privs1.privs[i].name);
1443 test_LookupPrivValue(p, mem_ctx, handle, (struct lsa_String *)&privs1.privs[i].name);
1444 if (!test_EnumAccountsWithUserRight(p, mem_ctx, handle, (struct lsa_String *)&privs1.privs[i].name)) {
1452 static BOOL test_QueryForestTrustInformation(struct dcerpc_pipe *p,
1453 TALLOC_CTX *mem_ctx,
1454 struct policy_handle *handle,
1455 const char *trusted_domain_name)
1458 struct lsa_lsaRQueryForestTrustInformation r;
1460 struct lsa_String string;
1461 struct lsa_ForestTrustInformation info, *info_ptr;
1462 uint16_t unknown = 0;
1464 printf("\nTesting lsaRQueryForestTrustInformation\n");
1466 if (lp_parm_bool(-1, "torture", "samba4", False)) {
1467 printf("skipping QueryForestTrustInformation against Samba4\n");
1471 ZERO_STRUCT(string);
1473 if (trusted_domain_name) {
1474 init_lsa_String(&string, trusted_domain_name);
1479 r.in.handle = handle;
1480 r.in.trusted_domain_name = &string;
1482 r.out.forest_trust_info = &info_ptr;
1484 status = dcerpc_lsa_lsaRQueryForestTrustInformation(p, mem_ctx, &r);
1486 if (!NT_STATUS_IS_OK(status)) {
1487 printf("lsaRQueryForestTrustInformation failed - %s\n", nt_errstr(status));
1494 static BOOL test_query_each_TrustDomEx(struct dcerpc_pipe *p,
1495 TALLOC_CTX *mem_ctx,
1496 struct policy_handle *handle,
1497 struct lsa_DomainListEx *domains)
1503 for (i=0; i< domains->count; i++) {
1505 if (domains->domains[i].trust_attributes & NETR_TRUST_ATTRIBUTE_FOREST_TRANSITIVE) {
1506 ret &= test_QueryForestTrustInformation(p, mem_ctx, handle,
1507 domains->domains[i].domain_name.string);
1514 static BOOL test_query_each_TrustDom(struct dcerpc_pipe *p,
1515 TALLOC_CTX *mem_ctx,
1516 struct policy_handle *handle,
1517 struct lsa_DomainList *domains)
1523 printf("\nTesting OpenTrustedDomain, OpenTrustedDomainByName and QueryInfoTrustedDomain\n");
1524 for (i=0; i< domains->count; i++) {
1525 struct lsa_OpenTrustedDomain trust;
1526 struct lsa_OpenTrustedDomainByName trust_by_name;
1527 struct policy_handle trustdom_handle;
1528 struct policy_handle handle2;
1530 struct lsa_CloseTrustedDomainEx c_trust;
1531 int levels [] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
1532 int ok[] = {1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1};
1534 if (domains->domains[i].sid) {
1535 trust.in.handle = handle;
1536 trust.in.sid = domains->domains[i].sid;
1537 trust.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1538 trust.out.trustdom_handle = &trustdom_handle;
1540 status = dcerpc_lsa_OpenTrustedDomain(p, mem_ctx, &trust);
1542 if (!NT_STATUS_IS_OK(status)) {
1543 printf("OpenTrustedDomain failed - %s\n", nt_errstr(status));
1547 c.in.handle = &trustdom_handle;
1548 c.out.handle = &handle2;
1550 c_trust.in.handle = &trustdom_handle;
1551 c_trust.out.handle = &handle2;
1553 for (j=0; j < ARRAY_SIZE(levels); j++) {
1554 struct lsa_QueryTrustedDomainInfo q;
1555 union lsa_TrustedDomainInfo info;
1556 q.in.trustdom_handle = &trustdom_handle;
1557 q.in.level = levels[j];
1559 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
1560 if (!NT_STATUS_IS_OK(status) && ok[j]) {
1561 printf("QueryTrustedDomainInfo level %d failed - %s\n",
1562 levels[j], nt_errstr(status));
1564 } else if (NT_STATUS_IS_OK(status) && !ok[j]) {
1565 printf("QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
1566 levels[j], nt_errstr(status));
1571 status = dcerpc_lsa_CloseTrustedDomainEx(p, mem_ctx, &c_trust);
1572 if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED)) {
1573 printf("Expected CloseTrustedDomainEx to return NT_STATUS_NOT_IMPLEMENTED, instead - %s\n", nt_errstr(status));
1577 c.in.handle = &trustdom_handle;
1578 c.out.handle = &handle2;
1580 status = dcerpc_lsa_Close(p, mem_ctx, &c);
1581 if (!NT_STATUS_IS_OK(status)) {
1582 printf("Close of trusted domain failed - %s\n", nt_errstr(status));
1586 for (j=0; j < ARRAY_SIZE(levels); j++) {
1587 struct lsa_QueryTrustedDomainInfoBySid q;
1588 union lsa_TrustedDomainInfo info;
1590 if (!domains->domains[i].sid) {
1594 q.in.handle = handle;
1595 q.in.dom_sid = domains->domains[i].sid;
1596 q.in.level = levels[j];
1598 status = dcerpc_lsa_QueryTrustedDomainInfoBySid(p, mem_ctx, &q);
1599 if (!NT_STATUS_IS_OK(status) && ok[j]) {
1600 printf("QueryTrustedDomainInfoBySid level %d failed - %s\n",
1601 levels[j], nt_errstr(status));
1603 } else if (NT_STATUS_IS_OK(status) && !ok[j]) {
1604 printf("QueryTrustedDomainInfoBySid level %d unexpectedly succeeded - %s\n",
1605 levels[j], nt_errstr(status));
1611 trust_by_name.in.handle = handle;
1612 trust_by_name.in.name.string = domains->domains[i].name.string;
1613 trust_by_name.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1614 trust_by_name.out.trustdom_handle = &trustdom_handle;
1616 status = dcerpc_lsa_OpenTrustedDomainByName(p, mem_ctx, &trust_by_name);
1618 if (!NT_STATUS_IS_OK(status)) {
1619 printf("OpenTrustedDomainByName failed - %s\n", nt_errstr(status));
1623 for (j=0; j < ARRAY_SIZE(levels); j++) {
1624 struct lsa_QueryTrustedDomainInfo q;
1625 union lsa_TrustedDomainInfo info;
1626 q.in.trustdom_handle = &trustdom_handle;
1627 q.in.level = levels[j];
1629 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
1630 if (!NT_STATUS_IS_OK(status) && ok[j]) {
1631 printf("QueryTrustedDomainInfo level %d failed - %s\n",
1632 levels[j], nt_errstr(status));
1634 } else if (NT_STATUS_IS_OK(status) && !ok[j]) {
1635 printf("QueryTrustedDomainInfo level %d unexpectedly succeeded - %s\n",
1636 levels[j], nt_errstr(status));
1641 c.in.handle = &trustdom_handle;
1642 c.out.handle = &handle2;
1644 status = dcerpc_lsa_Close(p, mem_ctx, &c);
1645 if (!NT_STATUS_IS_OK(status)) {
1646 printf("Close of trusted domain failed - %s\n", nt_errstr(status));
1650 for (j=0; j < ARRAY_SIZE(levels); j++) {
1651 struct lsa_QueryTrustedDomainInfoByName q;
1652 union lsa_TrustedDomainInfo info;
1653 q.in.handle = handle;
1654 q.in.trusted_domain.string = domains->domains[i].name.string;
1655 q.in.level = levels[j];
1657 status = dcerpc_lsa_QueryTrustedDomainInfoByName(p, mem_ctx, &q);
1658 if (!NT_STATUS_IS_OK(status) && ok[j]) {
1659 printf("QueryTrustedDomainInfoByName level %d failed - %s\n",
1660 levels[j], nt_errstr(status));
1662 } else if (NT_STATUS_IS_OK(status) && !ok[j]) {
1663 printf("QueryTrustedDomainInfoByName level %d unexpectedly succeeded - %s\n",
1664 levels[j], nt_errstr(status));
1672 static BOOL test_EnumTrustDom(struct dcerpc_pipe *p,
1673 TALLOC_CTX *mem_ctx,
1674 struct policy_handle *handle)
1676 struct lsa_EnumTrustDom r;
1677 struct lsa_EnumTrustedDomainsEx r_ex;
1678 NTSTATUS enum_status;
1679 uint32_t resume_handle = 0;
1680 struct lsa_DomainList domains;
1681 struct lsa_DomainListEx domains_ex;
1684 printf("\nTesting EnumTrustDom\n");
1687 r.in.handle = handle;
1688 r.in.resume_handle = &resume_handle;
1689 r.in.max_size = LSA_ENUM_TRUST_DOMAIN_MULTIPLIER * 3;
1690 r.out.domains = &domains;
1691 r.out.resume_handle = &resume_handle;
1693 enum_status = dcerpc_lsa_EnumTrustDom(p, mem_ctx, &r);
1695 /* NO_MORE_ENTRIES is allowed */
1696 if (NT_STATUS_EQUAL(enum_status, NT_STATUS_NO_MORE_ENTRIES)) {
1698 } else if (NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES)) {
1699 /* Windows 2003 gets this off by one on the first run */
1700 if (r.out.domains->count < 3 || r.out.domains->count > 4) {
1701 printf("EnumTrustDom didn't fill the buffer we "
1702 "asked it to (got %d, expected %d / %d == %d entries)\n",
1703 r.out.domains->count, LSA_ENUM_TRUST_DOMAIN_MULTIPLIER * 3,
1704 LSA_ENUM_TRUST_DOMAIN_MULTIPLIER, r.in.max_size);
1707 } else if (!NT_STATUS_IS_OK(enum_status)) {
1708 printf("EnumTrustDom failed - %s\n", nt_errstr(enum_status));
1712 ret &= test_query_each_TrustDom(p, mem_ctx, handle, &domains);
1714 } while ((NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES)));
1716 printf("\nTesting EnumTrustedDomainsEx\n");
1720 r_ex.in.handle = handle;
1721 r_ex.in.resume_handle = &resume_handle;
1722 r_ex.in.max_size = LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER * 3;
1723 r_ex.out.domains = &domains_ex;
1724 r_ex.out.resume_handle = &resume_handle;
1726 enum_status = dcerpc_lsa_EnumTrustedDomainsEx(p, mem_ctx, &r_ex);
1728 /* NO_MORE_ENTRIES is allowed */
1729 if (NT_STATUS_EQUAL(enum_status, NT_STATUS_NO_MORE_ENTRIES)) {
1731 } else if (NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES)) {
1732 /* Windows 2003 gets this off by one on the first run */
1733 if (r_ex.out.domains->count < 3 || r_ex.out.domains->count > 4) {
1734 printf("EnumTrustDom didn't fill the buffer we "
1735 "asked it to (got %d, expected %d / %d == %d entries)\n",
1736 r_ex.out.domains->count,
1738 LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER,
1739 r_ex.in.max_size / LSA_ENUM_TRUST_DOMAIN_EX_MULTIPLIER);
1743 } else if (!NT_STATUS_IS_OK(enum_status)) {
1744 printf("EnumTrustedDomainEx failed - %s\n", nt_errstr(enum_status));
1748 ret &= test_query_each_TrustDomEx(p, mem_ctx, handle, &domains_ex);
1750 } while ((NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES)));
1755 static BOOL test_CreateTrustedDomain(struct dcerpc_pipe *p,
1756 TALLOC_CTX *mem_ctx,
1757 struct policy_handle *handle)
1761 struct lsa_CreateTrustedDomain r;
1762 struct lsa_DomainInfo trustinfo;
1763 struct dom_sid *domsid[12];
1764 struct policy_handle trustdom_handle[12];
1765 struct lsa_QueryTrustedDomainInfo q;
1768 printf("Testing CreateTrustedDomain for 12 domains\n");
1770 for (i=0; i< 12; i++) {
1771 char *trust_name = talloc_asprintf(mem_ctx, "torturedom%02d", i);
1772 char *trust_sid = talloc_asprintf(mem_ctx, "S-1-5-21-97398-379795-100%02d", i);
1774 domsid[i] = dom_sid_parse_talloc(mem_ctx, trust_sid);
1776 trustinfo.sid = domsid[i];
1777 init_lsa_String((struct lsa_String *)&trustinfo.name, trust_name);
1779 r.in.handle = handle;
1780 r.in.info = &trustinfo;
1781 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1782 r.out.trustdom_handle = &trustdom_handle[i];
1784 status = dcerpc_lsa_CreateTrustedDomain(p, mem_ctx, &r);
1785 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
1786 test_DeleteTrustedDomain(p, mem_ctx, handle, trustinfo.name);
1787 status = dcerpc_lsa_CreateTrustedDomain(p, mem_ctx, &r);
1789 if (!NT_STATUS_IS_OK(status)) {
1790 printf("CreateTrustedDomain failed - %s\n", nt_errstr(status));
1794 q.in.trustdom_handle = &trustdom_handle[i];
1795 q.in.level = LSA_TRUSTED_DOMAIN_INFO_NAME;
1796 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
1797 if (!NT_STATUS_IS_OK(status)) {
1798 printf("QueryTrustedDomainInfo level 1 failed - %s\n", nt_errstr(status));
1800 } else if (!q.out.info) {
1803 if (strcmp(q.out.info->name.netbios_name.string, trustinfo.name.string) != 0) {
1804 printf("QueryTrustedDomainInfo returned inconsistant short name: %s != %s\n",
1805 q.out.info->name.netbios_name.string, trustinfo.name.string);
1812 /* now that we have some domains to look over, we can test the enum calls */
1813 if (!test_EnumTrustDom(p, mem_ctx, handle)) {
1817 for (i=0; i<12; i++) {
1818 if (!test_DeleteTrustedDomainBySid(p, mem_ctx, handle, domsid[i])) {
1826 static BOOL test_QueryDomainInfoPolicy(struct dcerpc_pipe *p,
1827 TALLOC_CTX *mem_ctx,
1828 struct policy_handle *handle)
1830 struct lsa_QueryDomainInformationPolicy r;
1834 if (lp_parm_bool(-1, "torture", "samba4", False)) {
1835 printf("skipping QueryDomainInformationPolicy test against Samba4\n");
1839 printf("\nTesting QueryDomainInformationPolicy\n");
1842 r.in.handle = handle;
1845 printf("\ntrying QueryDomainInformationPolicy level %d\n", i);
1847 status = dcerpc_lsa_QueryDomainInformationPolicy(p, mem_ctx, &r);
1849 if (!NT_STATUS_IS_OK(status)) {
1850 printf("QueryDomainInformationPolicy failed - %s\n", nt_errstr(status));
1860 static BOOL test_QueryInfoPolicy(struct dcerpc_pipe *p,
1861 TALLOC_CTX *mem_ctx,
1862 struct policy_handle *handle)
1864 struct lsa_QueryInfoPolicy r;
1868 printf("\nTesting QueryInfoPolicy\n");
1870 if (lp_parm_bool(-1, "torture", "samba4", False)) {
1871 printf("skipping QueryInfoPolicy against Samba4\n");
1875 for (i=1;i<13;i++) {
1876 r.in.handle = handle;
1879 printf("\ntrying QueryInfoPolicy level %d\n", i);
1881 status = dcerpc_lsa_QueryInfoPolicy(p, mem_ctx, &r);
1883 if ((i == 9 || i == 10 || i == 11) &&
1884 NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
1885 printf("server failed level %u (OK)\n", i);
1889 if (!NT_STATUS_IS_OK(status)) {
1890 printf("QueryInfoPolicy failed - %s\n", nt_errstr(status));
1899 static BOOL test_QueryInfoPolicy2(struct dcerpc_pipe *p,
1900 TALLOC_CTX *mem_ctx,
1901 struct policy_handle *handle)
1903 struct lsa_QueryInfoPolicy2 r;
1907 printf("\nTesting QueryInfoPolicy2\n");
1908 if (lp_parm_bool(-1, "torture", "samba4", False)) {
1909 printf("skipping QueryInfoPolicy2 against Samba4\n");
1913 for (i=1;i<13;i++) {
1914 r.in.handle = handle;
1917 printf("\ntrying QueryInfoPolicy2 level %d\n", i);
1919 status = dcerpc_lsa_QueryInfoPolicy2(p, mem_ctx, &r);
1921 if ((i == 9 || i == 10 || i == 11) &&
1922 NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
1923 printf("server failed level %u (OK)\n", i);
1927 if (!NT_STATUS_IS_OK(status)) {
1928 printf("QueryInfoPolicy2 failed - %s\n", nt_errstr(status));
1937 static BOOL test_GetUserName(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
1939 struct lsa_GetUserName r;
1942 struct lsa_StringPointer authority_name_p;
1944 printf("\nTesting GetUserName\n");
1946 r.in.system_name = "\\";
1947 r.in.account_name = NULL;
1948 r.in.authority_name = &authority_name_p;
1949 authority_name_p.string = NULL;
1951 status = dcerpc_lsa_GetUserName(p, mem_ctx, &r);
1953 if (!NT_STATUS_IS_OK(status)) {
1954 printf("GetUserName failed - %s\n", nt_errstr(status));
1961 BOOL test_lsa_Close(struct dcerpc_pipe *p,
1962 TALLOC_CTX *mem_ctx,
1963 struct policy_handle *handle)
1967 struct policy_handle handle2;
1969 printf("\ntesting Close\n");
1971 r.in.handle = handle;
1972 r.out.handle = &handle2;
1974 status = dcerpc_lsa_Close(p, mem_ctx, &r);
1975 if (!NT_STATUS_IS_OK(status)) {
1976 printf("Close failed - %s\n", nt_errstr(status));
1980 status = dcerpc_lsa_Close(p, mem_ctx, &r);
1981 /* its really a fault - we need a status code for rpc fault */
1982 if (!NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
1983 printf("Close failed - %s\n", nt_errstr(status));
1992 BOOL torture_rpc_lsa(struct torture_context *torture)
1995 struct dcerpc_pipe *p;
1996 TALLOC_CTX *mem_ctx;
1998 struct policy_handle *handle;
2000 mem_ctx = talloc_init("torture_rpc_lsa");
2002 status = torture_rpc_connection(mem_ctx, &p, &dcerpc_table_lsarpc);
2003 if (!NT_STATUS_IS_OK(status)) {
2004 talloc_free(mem_ctx);
2008 if (!test_OpenPolicy(p, mem_ctx)) {
2012 if (!test_lsa_OpenPolicy2(p, mem_ctx, &handle)) {
2017 if (!test_LookupSids_async(p, mem_ctx, handle)) {
2021 if (!test_QueryDomainInfoPolicy(p, mem_ctx, handle)) {
2025 if (!test_CreateAccount(p, mem_ctx, handle)) {
2029 if (!test_CreateSecret(p, mem_ctx, handle)) {
2033 if (!test_CreateTrustedDomain(p, mem_ctx, handle)) {
2037 if (!test_EnumAccounts(p, mem_ctx, handle)) {
2041 if (!test_EnumPrivs(p, mem_ctx, handle)) {
2045 if (!test_QueryInfoPolicy(p, mem_ctx, handle)) {
2049 if (!test_QueryInfoPolicy2(p, mem_ctx, handle)) {
2054 if (!test_Delete(p, mem_ctx, handle)) {
2059 if (!test_many_LookupSids(p, mem_ctx, handle)) {
2063 if (!test_lsa_Close(p, mem_ctx, handle)) {
2067 if (!test_many_LookupSids(p, mem_ctx, handle)) {
2072 if (!test_GetUserName(p, mem_ctx)) {
2076 talloc_free(mem_ctx);
2081 BOOL torture_rpc_lsa_get_user(struct torture_context *torture)
2084 struct dcerpc_pipe *p;
2085 TALLOC_CTX *mem_ctx;
2088 mem_ctx = talloc_init("torture_rpc_lsa_get_user");
2090 status = torture_rpc_connection(mem_ctx, &p, &dcerpc_table_lsarpc);
2091 if (!NT_STATUS_IS_OK(status)) {
2092 talloc_free(mem_ctx);
2096 if (!test_GetUserName(p, mem_ctx)) {
2100 talloc_free(mem_ctx);