2 Unix SMB/CIFS implementation.
3 test suite for lsa rpc operations
5 Copyright (C) Andrew Tridgell 2003
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "librpc/gen_ndr/ndr_lsa.h"
25 static void init_lsa_String(struct lsa_String *name, const char *s)
30 static BOOL test_OpenPolicy(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
32 struct lsa_ObjectAttribute attr;
33 struct policy_handle handle;
34 struct lsa_QosInfo qos;
35 struct lsa_OpenPolicy r;
37 uint16_t system_name = '\\';
39 printf("\ntesting OpenPolicy\n");
42 qos.impersonation_level = 2;
44 qos.effective_only = 0;
48 attr.object_name = NULL;
53 r.in.system_name = &system_name;
55 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
56 r.out.handle = &handle;
58 status = dcerpc_lsa_OpenPolicy(p, mem_ctx, &r);
59 if (!NT_STATUS_IS_OK(status)) {
60 printf("OpenPolicy failed - %s\n", nt_errstr(status));
68 static BOOL test_OpenPolicy2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
69 struct policy_handle *handle)
71 struct lsa_ObjectAttribute attr;
72 struct lsa_QosInfo qos;
73 struct lsa_OpenPolicy2 r;
76 printf("\ntesting OpenPolicy2\n");
79 qos.impersonation_level = 2;
81 qos.effective_only = 0;
85 attr.object_name = NULL;
90 r.in.system_name = "\\";
92 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
93 r.out.handle = handle;
95 status = dcerpc_lsa_OpenPolicy2(p, mem_ctx, &r);
96 if (!NT_STATUS_IS_OK(status)) {
97 printf("OpenPolicy2 failed - %s\n", nt_errstr(status));
104 static BOOL test_LookupNames(struct dcerpc_pipe *p,
106 struct policy_handle *handle,
107 struct lsa_TransNameArray *tnames)
109 struct lsa_LookupNames r;
110 struct lsa_TransSidArray sids;
111 struct lsa_String *names;
116 printf("\nTesting LookupNames with %d names\n", tnames->count);
121 names = talloc_array_p(mem_ctx, struct lsa_String, tnames->count);
122 for (i=0;i<tnames->count;i++) {
123 init_lsa_String(&names[i], tnames->names[i].name.string);
126 r.in.handle = handle;
127 r.in.num_names = tnames->count;
132 r.out.count = &count;
135 status = dcerpc_lsa_LookupNames(p, mem_ctx, &r);
136 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
137 printf("LookupNames failed - %s\n", nt_errstr(status));
146 static BOOL test_LookupNames2(struct dcerpc_pipe *p,
148 struct policy_handle *handle,
149 struct lsa_TransNameArray2 *tnames)
151 struct lsa_LookupNames2 r;
152 struct lsa_TransSidArray2 sids;
153 struct lsa_String *names;
158 printf("\nTesting LookupNames2 with %d names\n", tnames->count);
163 names = talloc_array_p(mem_ctx, struct lsa_String, tnames->count);
164 for (i=0;i<tnames->count;i++) {
165 init_lsa_String(&names[i], tnames->names[i].name.string);
168 r.in.handle = handle;
169 r.in.num_names = tnames->count;
176 r.out.count = &count;
179 status = dcerpc_lsa_LookupNames2(p, mem_ctx, &r);
180 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
181 printf("LookupNames2 failed - %s\n", nt_errstr(status));
191 static BOOL test_LookupNames3(struct dcerpc_pipe *p,
193 struct policy_handle *handle,
194 struct lsa_TransNameArray2 *tnames)
196 struct lsa_LookupNames3 r;
197 struct lsa_TransSidArray3 sids;
198 struct lsa_String *names;
203 printf("\nTesting LookupNames3 with %d names\n", tnames->count);
208 names = talloc_array_p(mem_ctx, struct lsa_String, tnames->count);
209 for (i=0;i<tnames->count;i++) {
210 init_lsa_String(&names[i], tnames->names[i].name.string);
213 r.in.handle = handle;
214 r.in.num_names = tnames->count;
221 r.out.count = &count;
224 status = dcerpc_lsa_LookupNames3(p, mem_ctx, &r);
225 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
226 printf("LookupNames3 failed - %s\n", nt_errstr(status));
236 static BOOL test_LookupSids(struct dcerpc_pipe *p,
238 struct policy_handle *handle,
239 struct lsa_SidArray *sids)
241 struct lsa_LookupSids r;
242 struct lsa_TransNameArray names;
243 uint32_t count = sids->num_sids;
246 printf("\nTesting LookupSids\n");
251 r.in.handle = handle;
256 r.out.count = &count;
257 r.out.names = &names;
259 status = dcerpc_lsa_LookupSids(p, mem_ctx, &r);
260 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
261 printf("LookupSids failed - %s\n", nt_errstr(status));
267 if (!test_LookupNames(p, mem_ctx, handle, &names)) {
275 static BOOL test_LookupSids2(struct dcerpc_pipe *p,
277 struct policy_handle *handle,
278 struct lsa_SidArray *sids)
280 struct lsa_LookupSids2 r;
281 struct lsa_TransNameArray2 names;
282 uint32_t count = sids->num_sids;
285 printf("\nTesting LookupSids2\n");
290 r.in.handle = handle;
297 r.out.count = &count;
298 r.out.names = &names;
300 status = dcerpc_lsa_LookupSids2(p, mem_ctx, &r);
301 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
302 printf("LookupSids2 failed - %s\n", nt_errstr(status));
308 if (!test_LookupNames2(p, mem_ctx, handle, &names)) {
312 if (!test_LookupNames3(p, mem_ctx, handle, &names)) {
319 static BOOL test_LookupSids3(struct dcerpc_pipe *p,
321 struct policy_handle *handle,
322 struct lsa_SidArray *sids)
324 struct lsa_LookupSids3 r;
325 struct lsa_TransNameArray2 names;
326 uint32_t count = sids->num_sids;
329 printf("\nTesting LookupSids3\n");
340 r.out.count = &count;
341 r.out.names = &names;
343 status = dcerpc_lsa_LookupSids3(p, mem_ctx, &r);
344 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
345 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
346 NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
347 printf("not considering %s to be an error\n", nt_errstr(status));
350 printf("LookupSids3 failed - %s - not considered an error\n",
357 if (!test_LookupNames3(p, mem_ctx, handle, &names)) {
364 static BOOL test_many_LookupSids(struct dcerpc_pipe *p,
366 struct policy_handle *handle)
368 struct lsa_LookupSids r;
369 struct lsa_TransNameArray names;
372 struct lsa_SidArray sids;
375 printf("\nTesting LookupSids with lots of SIDs\n");
382 sids.sids = talloc_array_p(mem_ctx, struct lsa_SidPtr, sids.num_sids);
384 for (i=0; i<sids.num_sids; i++) {
385 const char *sidstr = "S-1-5-32-545";
386 sids.sids[i].sid = dom_sid_parse_talloc(mem_ctx, sidstr);
389 count = sids.num_sids;
391 r.in.handle = handle;
395 r.in.count = &names.count;
396 r.out.count = &count;
397 r.out.names = &names;
399 status = dcerpc_lsa_LookupSids(p, mem_ctx, &r);
400 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
401 printf("LookupSids failed - %s\n", nt_errstr(status));
407 if (!test_LookupNames(p, mem_ctx, handle, &names)) {
414 static BOOL test_LookupPrivValue(struct dcerpc_pipe *p,
416 struct policy_handle *handle,
417 struct lsa_String *name)
420 struct lsa_LookupPrivValue r;
421 struct lsa_LUID luid;
423 r.in.handle = handle;
427 status = dcerpc_lsa_LookupPrivValue(p, mem_ctx, &r);
428 if (!NT_STATUS_IS_OK(status)) {
429 printf("\nLookupPrivValue failed - %s\n", nt_errstr(status));
436 static BOOL test_LookupPrivName(struct dcerpc_pipe *p,
438 struct policy_handle *handle,
439 struct lsa_LUID *luid)
442 struct lsa_LookupPrivName r;
444 r.in.handle = handle;
447 status = dcerpc_lsa_LookupPrivName(p, mem_ctx, &r);
448 if (!NT_STATUS_IS_OK(status)) {
449 printf("\nLookupPrivName failed - %s\n", nt_errstr(status));
456 static BOOL test_RemovePrivilegesFromAccount(struct dcerpc_pipe *p,
458 struct policy_handle *acct_handle,
459 struct lsa_LUID *luid)
462 struct lsa_RemovePrivilegesFromAccount r;
463 struct lsa_PrivilegeSet privs;
466 printf("Testing RemovePrivilegesFromAccount\n");
468 r.in.handle = acct_handle;
474 privs.set = talloc_array_p(mem_ctx, struct lsa_LUIDAttribute, 1);
475 privs.set[0].luid = *luid;
476 privs.set[0].attribute = 0;
478 status = dcerpc_lsa_RemovePrivilegesFromAccount(p, mem_ctx, &r);
479 if (!NT_STATUS_IS_OK(status)) {
480 printf("RemovePrivilegesFromAccount failed - %s\n", nt_errstr(status));
487 static BOOL test_AddPrivilegesToAccount(struct dcerpc_pipe *p,
489 struct policy_handle *acct_handle,
490 struct lsa_LUID *luid)
493 struct lsa_AddPrivilegesToAccount r;
494 struct lsa_PrivilegeSet privs;
497 printf("Testing AddPrivilegesToAccount\n");
499 r.in.handle = acct_handle;
504 privs.set = talloc_array_p(mem_ctx, struct lsa_LUIDAttribute, 1);
505 privs.set[0].luid = *luid;
506 privs.set[0].attribute = 0;
508 status = dcerpc_lsa_AddPrivilegesToAccount(p, mem_ctx, &r);
509 if (!NT_STATUS_IS_OK(status)) {
510 printf("AddPrivilegesToAccount failed - %s\n", nt_errstr(status));
517 static BOOL test_EnumPrivsAccount(struct dcerpc_pipe *p,
519 struct policy_handle *handle,
520 struct policy_handle *acct_handle)
523 struct lsa_EnumPrivsAccount r;
526 printf("Testing EnumPrivsAccount\n");
528 r.in.handle = acct_handle;
530 status = dcerpc_lsa_EnumPrivsAccount(p, mem_ctx, &r);
531 if (!NT_STATUS_IS_OK(status)) {
532 printf("EnumPrivsAccount failed - %s\n", nt_errstr(status));
536 if (r.out.privs && r.out.privs->count > 0) {
538 for (i=0;i<r.out.privs->count;i++) {
539 test_LookupPrivName(p, mem_ctx, handle,
540 &r.out.privs->set[i].luid);
543 ret &= test_RemovePrivilegesFromAccount(p, mem_ctx, acct_handle,
544 &r.out.privs->set[0].luid);
545 ret &= test_AddPrivilegesToAccount(p, mem_ctx, acct_handle,
546 &r.out.privs->set[0].luid);
552 static BOOL test_Delete(struct dcerpc_pipe *p,
554 struct policy_handle *handle)
559 printf("\ntesting Delete\n");
561 r.in.handle = handle;
562 status = dcerpc_lsa_Delete(p, mem_ctx, &r);
563 if (!NT_STATUS_IS_OK(status)) {
564 printf("Delete failed - %s\n", nt_errstr(status));
574 static BOOL test_CreateAccount(struct dcerpc_pipe *p,
576 struct policy_handle *handle)
579 struct lsa_CreateAccount r;
580 struct dom_sid2 *newsid;
581 struct policy_handle acct_handle;
583 newsid = dom_sid_parse_talloc(mem_ctx, "S-1-5-12349876-4321-2854");
585 printf("Testing CreateAccount\n");
587 r.in.handle = handle;
589 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
590 r.out.acct_handle = &acct_handle;
592 status = dcerpc_lsa_CreateAccount(p, mem_ctx, &r);
593 if (!NT_STATUS_IS_OK(status)) {
594 printf("CreateAccount failed - %s\n", nt_errstr(status));
598 if (!test_Delete(p, mem_ctx, &acct_handle)) {
605 static BOOL test_DeleteTrustedDomain(struct dcerpc_pipe *p,
607 struct policy_handle *handle,
608 struct lsa_String name)
611 struct lsa_OpenTrustedDomainByName r;
612 struct policy_handle trustdom_handle;
614 r.in.handle = handle;
616 r.in.access_mask = SEC_STD_DELETE;
617 r.out.trustdom_handle = &trustdom_handle;
619 status = dcerpc_lsa_OpenTrustedDomainByName(p, mem_ctx, &r);
620 if (!NT_STATUS_IS_OK(status)) {
621 printf("lsa_OpenTrustedDomainByName failed - %s\n", nt_errstr(status));
625 if (!test_Delete(p, mem_ctx, &trustdom_handle)) {
633 static BOOL test_CreateTrustedDomain(struct dcerpc_pipe *p,
635 struct policy_handle *handle)
638 struct lsa_CreateTrustedDomain r;
639 struct lsa_TrustInformation trustinfo;
640 struct dom_sid *domsid;
641 struct policy_handle dom_handle;
643 printf("Testing CreateTrustedDomain\n");
645 domsid = dom_sid_parse_talloc(mem_ctx, "S-1-5-21-97398-379795-12345");
647 trustinfo.sid = domsid;
648 init_lsa_String(&trustinfo.name, "torturedomain");
650 r.in.handle = handle;
651 r.in.info = &trustinfo;
652 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
653 r.out.dom_handle = &dom_handle;
655 status = dcerpc_lsa_CreateTrustedDomain(p, mem_ctx, &r);
656 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
657 test_DeleteTrustedDomain(p, mem_ctx, handle, trustinfo.name);
658 status = dcerpc_lsa_CreateTrustedDomain(p, mem_ctx, &r);
660 if (!NT_STATUS_IS_OK(status)) {
661 printf("CreateTrustedDomain failed - %s\n", nt_errstr(status));
665 if (!test_Delete(p, mem_ctx, &dom_handle)) {
672 static BOOL test_CreateSecret(struct dcerpc_pipe *p,
674 struct policy_handle *handle)
677 struct lsa_CreateSecret r;
678 struct lsa_OpenSecret r2;
679 struct lsa_SetSecret r3;
680 struct lsa_QuerySecret r4;
681 struct policy_handle sec_handle, sec_handle2;
683 struct lsa_DATA_BUF buf1;
684 struct lsa_DATA_BUF_PTR bufp1;
687 DATA_BLOB session_key;
688 NTTIME old_mtime, new_mtime;
689 DATA_BLOB blob1, blob2;
690 const char *secret1 = "abcdef12345699qwerty";
696 secname[0] = talloc_asprintf(mem_ctx, "torturesecret-%u", (uint_t)random());
697 secname[1] = talloc_asprintf(mem_ctx, "G$torturesecret-%u", (uint_t)random());
699 for (i=0; i< 2; i++) {
700 printf("Testing CreateSecret of %s\n", secname[i]);
702 init_lsa_String(&r.in.name, secname[i]);
704 r.in.handle = handle;
705 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
706 r.out.sec_handle = &sec_handle;
708 status = dcerpc_lsa_CreateSecret(p, mem_ctx, &r);
709 if (!NT_STATUS_IS_OK(status)) {
710 printf("CreateSecret failed - %s\n", nt_errstr(status));
714 r2.in.handle = handle;
715 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
716 r2.in.name = r.in.name;
717 r2.out.sec_handle = &sec_handle2;
719 printf("Testing OpenSecret\n");
721 status = dcerpc_lsa_OpenSecret(p, mem_ctx, &r2);
722 if (!NT_STATUS_IS_OK(status)) {
723 printf("OpenSecret failed - %s\n", nt_errstr(status));
727 status = dcerpc_fetch_session_key(p, &session_key);
728 if (!NT_STATUS_IS_OK(status)) {
729 printf("dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
733 enc_key = sess_encrypt_string(secret1, &session_key);
735 r3.in.handle = &sec_handle;
736 r3.in.new_val = &buf1;
737 r3.in.old_val = NULL;
738 r3.in.new_val->data = enc_key.data;
739 r3.in.new_val->length = enc_key.length;
740 r3.in.new_val->size = enc_key.length;
742 printf("Testing SetSecret\n");
744 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r3);
745 if (!NT_STATUS_IS_OK(status)) {
746 printf("SetSecret failed - %s\n", nt_errstr(status));
750 data_blob_free(&enc_key);
752 ZERO_STRUCT(new_mtime);
753 ZERO_STRUCT(old_mtime);
755 /* fetch the secret back again */
756 r4.in.handle = &sec_handle;
757 r4.in.new_val = &bufp1;
758 r4.in.new_mtime = &new_mtime;
759 r4.in.old_val = NULL;
760 r4.in.old_mtime = NULL;
764 status = dcerpc_lsa_QuerySecret(p, mem_ctx, &r4);
765 if (!NT_STATUS_IS_OK(status)) {
766 printf("QuerySecret failed - %s\n", nt_errstr(status));
770 if (r4.out.new_val->buf == NULL) {
771 printf("No secret buffer returned\n");
774 blob1.data = r4.out.new_val->buf->data;
775 blob1.length = r4.out.new_val->buf->length;
777 blob2 = data_blob(NULL, blob1.length);
779 secret2 = sess_decrypt_string(&blob1, &session_key);
781 printf("returned secret '%s'\n", secret2);
783 if (strcmp(secret1, secret2) != 0) {
784 printf("Returned secret doesn't match\n");
789 if (!test_Delete(p, mem_ctx, &sec_handle)) {
793 d.in.handle = &sec_handle2;
794 status = dcerpc_lsa_Delete(p, mem_ctx, &d);
795 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
796 printf("Second delete expected INVALID_HANDLE - %s\n", nt_errstr(status));
805 static BOOL test_EnumAccountRights(struct dcerpc_pipe *p,
807 struct policy_handle *acct_handle,
811 struct lsa_EnumAccountRights r;
812 struct lsa_RightSet rights;
814 printf("Testing EnumAccountRights\n");
816 r.in.handle = acct_handle;
818 r.out.rights = &rights;
820 status = dcerpc_lsa_EnumAccountRights(p, mem_ctx, &r);
821 if (!NT_STATUS_IS_OK(status)) {
822 printf("EnumAccountRights failed - %s\n", nt_errstr(status));
830 static BOOL test_QuerySecurity(struct dcerpc_pipe *p,
832 struct policy_handle *handle,
833 struct policy_handle *acct_handle)
836 struct lsa_QuerySecurity r;
838 printf("Testing QuerySecurity\n");
840 r.in.handle = acct_handle;
843 status = dcerpc_lsa_QuerySecurity(p, mem_ctx, &r);
844 if (!NT_STATUS_IS_OK(status)) {
845 printf("QuerySecurity failed - %s\n", nt_errstr(status));
852 static BOOL test_OpenAccount(struct dcerpc_pipe *p,
854 struct policy_handle *handle,
858 struct lsa_OpenAccount r;
859 struct policy_handle acct_handle;
861 printf("Testing OpenAccount\n");
863 r.in.handle = handle;
865 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
866 r.out.acct_handle = &acct_handle;
868 status = dcerpc_lsa_OpenAccount(p, mem_ctx, &r);
869 if (!NT_STATUS_IS_OK(status)) {
870 printf("OpenAccount failed - %s\n", nt_errstr(status));
874 if (!test_EnumPrivsAccount(p, mem_ctx, handle, &acct_handle)) {
878 if (!test_QuerySecurity(p, mem_ctx, handle, &acct_handle)) {
885 static BOOL test_EnumAccounts(struct dcerpc_pipe *p,
887 struct policy_handle *handle)
890 struct lsa_EnumAccounts r;
891 struct lsa_SidArray sids1, sids2;
892 uint32_t resume_handle = 0;
895 printf("\ntesting EnumAccounts\n");
897 r.in.handle = handle;
898 r.in.resume_handle = &resume_handle;
899 r.in.num_entries = 100;
900 r.out.resume_handle = &resume_handle;
905 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
906 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
909 if (!NT_STATUS_IS_OK(status)) {
910 printf("EnumAccounts failed - %s\n", nt_errstr(status));
914 if (!test_LookupSids(p, mem_ctx, handle, &sids1)) {
918 if (!test_LookupSids2(p, mem_ctx, handle, &sids1)) {
922 if (!test_LookupSids3(p, mem_ctx, handle, &sids1)) {
926 printf("testing all accounts\n");
927 for (i=0;i<sids1.num_sids;i++) {
928 test_OpenAccount(p, mem_ctx, handle, sids1.sids[i].sid);
929 test_EnumAccountRights(p, mem_ctx, handle, sids1.sids[i].sid);
934 if (sids1.num_sids < 3) {
938 printf("trying EnumAccounts partial listing (asking for 1 at 2)\n");
940 r.in.num_entries = 1;
943 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
944 if (!NT_STATUS_IS_OK(status)) {
945 printf("EnumAccounts failed - %s\n", nt_errstr(status));
949 if (sids2.num_sids != 1) {
950 printf("Returned wrong number of entries (%d)\n", sids2.num_sids);
957 static BOOL test_LookupPrivDisplayName(struct dcerpc_pipe *p,
959 struct policy_handle *handle,
960 struct lsa_String *priv_name)
962 struct lsa_LookupPrivDisplayName r;
964 /* produce a reasonable range of language output without screwing up
966 uint16 language_id = (random() % 4) + 0x409;
968 printf("testing LookupPrivDisplayName(%s)\n", priv_name->string);
970 r.in.handle = handle;
971 r.in.name = priv_name;
972 r.in.language_id = &language_id;
973 r.out.language_id = &language_id;
976 status = dcerpc_lsa_LookupPrivDisplayName(p, mem_ctx, &r);
977 if (!NT_STATUS_IS_OK(status)) {
978 printf("LookupPrivDisplayName failed - %s\n", nt_errstr(status));
981 printf("%s -> \"%s\" (language 0x%x/0x%x)\n",
982 priv_name->string, r.out.disp_name->string,
983 *r.in.language_id, *r.out.language_id);
988 static BOOL test_EnumAccountsWithUserRight(struct dcerpc_pipe *p,
990 struct policy_handle *handle,
991 struct lsa_String *priv_name)
993 struct lsa_EnumAccountsWithUserRight r;
994 struct lsa_SidArray sids;
999 printf("testing EnumAccountsWithUserRight(%s)\n", priv_name->string);
1001 r.in.handle = handle;
1002 r.in.name = priv_name;
1005 status = dcerpc_lsa_EnumAccountsWithUserRight(p, mem_ctx, &r);
1007 /* NT_STATUS_NO_MORE_ENTRIES means noone has this privilege */
1008 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
1012 if (!NT_STATUS_IS_OK(status)) {
1013 printf("EnumAccountsWithUserRight failed - %s\n", nt_errstr(status));
1021 static BOOL test_EnumPrivs(struct dcerpc_pipe *p,
1022 TALLOC_CTX *mem_ctx,
1023 struct policy_handle *handle)
1026 struct lsa_EnumPrivs r;
1027 struct lsa_PrivArray privs1;
1028 uint32_t resume_handle = 0;
1032 printf("\ntesting EnumPrivs\n");
1034 r.in.handle = handle;
1035 r.in.resume_handle = &resume_handle;
1036 r.in.max_count = 100;
1037 r.out.resume_handle = &resume_handle;
1038 r.out.privs = &privs1;
1041 status = dcerpc_lsa_EnumPrivs(p, mem_ctx, &r);
1042 if (!NT_STATUS_IS_OK(status)) {
1043 printf("EnumPrivs failed - %s\n", nt_errstr(status));
1047 for (i = 0; i< privs1.count; i++) {
1048 test_LookupPrivDisplayName(p, mem_ctx, handle, &privs1.privs[i].name);
1049 test_LookupPrivValue(p, mem_ctx, handle, &privs1.privs[i].name);
1050 if (!test_EnumAccountsWithUserRight(p, mem_ctx, handle, &privs1.privs[i].name)) {
1059 static BOOL test_EnumTrustDom(struct dcerpc_pipe *p,
1060 TALLOC_CTX *mem_ctx,
1061 struct policy_handle *handle)
1063 struct lsa_EnumTrustDom r;
1065 uint32_t resume_handle = 0;
1066 struct lsa_DomainList domains;
1070 printf("\nTesting EnumTrustDom\n");
1072 r.in.handle = handle;
1073 r.in.resume_handle = &resume_handle;
1074 r.in.num_entries = 100;
1075 r.out.domains = &domains;
1076 r.out.resume_handle = &resume_handle;
1078 status = dcerpc_lsa_EnumTrustDom(p, mem_ctx, &r);
1080 /* NO_MORE_ENTRIES is allowed */
1081 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
1085 if (!NT_STATUS_IS_OK(status)) {
1086 printf("EnumTrustDom failed - %s\n", nt_errstr(status));
1090 printf("\nTesting OpenTrustedDomain, OpenTrustedDomainByName and QueryInfoTrustedDomain\n");
1092 for (i=0; i< domains.count; i++) {
1093 struct lsa_OpenTrustedDomain trust;
1094 struct lsa_OpenTrustedDomainByName trust_by_name;
1095 struct policy_handle trustdom_handle;
1096 struct policy_handle handle2;
1098 int levels [] = {1, 3, 6, 8, 12};
1100 trust.in.handle = handle;
1101 trust.in.sid = domains.domains[i].sid;
1102 trust.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1103 trust.out.trustdom_handle = &trustdom_handle;
1105 status = dcerpc_lsa_OpenTrustedDomain(p, mem_ctx, &trust);
1107 if (!NT_STATUS_IS_OK(status)) {
1108 printf("OpenTrustedDomain failed - %s\n", nt_errstr(status));
1112 c.in.handle = &trustdom_handle;
1113 c.out.handle = &handle2;
1115 for (j=0; j < ARRAY_SIZE(levels); j++) {
1116 struct lsa_QueryTrustedDomainInfo q;
1117 union lsa_TrustedDomainInfo info;
1118 q.in.trustdom_handle = &trustdom_handle;
1119 q.in.level = levels[j];
1121 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
1122 if (!NT_STATUS_IS_OK(status)) {
1123 printf("QueryTrustedDomainInfo level %d failed - %s\n",
1124 levels[j], nt_errstr(status));
1129 status = dcerpc_lsa_Close(p, mem_ctx, &c);
1130 if (!NT_STATUS_IS_OK(status)) {
1131 printf("Close of trusted domain failed - %s\n", nt_errstr(status));
1135 trust_by_name.in.handle = handle;
1136 trust_by_name.in.name = domains.domains[i].name;
1137 trust_by_name.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1138 trust_by_name.out.trustdom_handle = &trustdom_handle;
1140 status = dcerpc_lsa_OpenTrustedDomainByName(p, mem_ctx, &trust_by_name);
1142 if (!NT_STATUS_IS_OK(status)) {
1143 printf("OpenTrustedDomainByName failed - %s\n", nt_errstr(status));
1147 for (j=0; j < ARRAY_SIZE(levels); j++) {
1148 struct lsa_QueryTrustedDomainInfo q;
1149 union lsa_TrustedDomainInfo info;
1150 q.in.trustdom_handle = &trustdom_handle;
1151 q.in.level = levels[j];
1153 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
1154 if (!NT_STATUS_IS_OK(status)) {
1155 printf("QueryTrustedDomainInfo level %d failed - %s\n",
1156 levels[j], nt_errstr(status));
1161 c.in.handle = &trustdom_handle;
1162 c.out.handle = &handle2;
1164 status = dcerpc_lsa_Close(p, mem_ctx, &c);
1165 if (!NT_STATUS_IS_OK(status)) {
1166 printf("Close of trusted domain failed - %s\n", nt_errstr(status));
1170 for (j=0; j < ARRAY_SIZE(levels); j++) {
1171 struct lsa_QueryTrustedDomainInfoBySid q;
1172 union lsa_TrustedDomainInfo info;
1173 q.in.handle = handle;
1174 q.in.dom_sid = domains.domains[i].sid;
1175 q.in.level = levels[j];
1177 status = dcerpc_lsa_QueryTrustedDomainInfoBySid(p, mem_ctx, &q);
1178 if (!NT_STATUS_IS_OK(status)) {
1179 printf("QueryTrustedDomainInfoBySid level %d failed - %s\n",
1180 levels[j], nt_errstr(status));
1185 for (j=0; j < ARRAY_SIZE(levels); j++) {
1186 struct lsa_QueryTrustedDomainInfoByName q;
1187 union lsa_TrustedDomainInfo info;
1188 q.in.handle = handle;
1189 q.in.trusted_domain = domains.domains[i].name;
1190 q.in.level = levels[j];
1192 status = dcerpc_lsa_QueryTrustedDomainInfoByName(p, mem_ctx, &q);
1193 if (!NT_STATUS_IS_OK(status)) {
1194 printf("QueryTrustedDomainInfoByName level %d failed - %s\n",
1195 levels[j], nt_errstr(status));
1207 static BOOL test_QueryInfoPolicy(struct dcerpc_pipe *p,
1208 TALLOC_CTX *mem_ctx,
1209 struct policy_handle *handle)
1211 struct lsa_QueryInfoPolicy r;
1215 printf("\nTesting QueryInfoPolicy\n");
1217 for (i=1;i<13;i++) {
1218 r.in.handle = handle;
1221 printf("\ntrying QueryInfoPolicy level %d\n", i);
1223 status = dcerpc_lsa_QueryInfoPolicy(p, mem_ctx, &r);
1225 if ((i == 9 || i == 10 || i == 11) &&
1226 NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
1227 printf("server failed level %u (OK)\n", i);
1231 if (!NT_STATUS_IS_OK(status)) {
1232 printf("QueryInfoPolicy failed - %s\n", nt_errstr(status));
1241 static BOOL test_QueryInfoPolicy2(struct dcerpc_pipe *p,
1242 TALLOC_CTX *mem_ctx,
1243 struct policy_handle *handle)
1245 struct lsa_QueryInfoPolicy2 r;
1249 printf("\nTesting QueryInfoPolicy2\n");
1251 for (i=1;i<13;i++) {
1252 r.in.handle = handle;
1255 printf("\ntrying QueryInfoPolicy2 level %d\n", i);
1257 status = dcerpc_lsa_QueryInfoPolicy2(p, mem_ctx, &r);
1259 if ((i == 9 || i == 10 || i == 11) &&
1260 NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
1261 printf("server failed level %u (OK)\n", i);
1265 if (!NT_STATUS_IS_OK(status)) {
1266 printf("QueryInfoPolicy2 failed - %s\n", nt_errstr(status));
1275 static BOOL test_GetUserName(struct dcerpc_pipe *p,
1276 TALLOC_CTX *mem_ctx,
1277 struct policy_handle *handle)
1279 struct lsa_GetUserName r;
1282 struct lsa_StringPointer authority_name_p;
1284 printf("\nTesting GetUserName\n");
1286 r.in.system_name = "\\";
1287 r.in.account_name = NULL;
1288 r.in.authority_name = &authority_name_p;
1289 authority_name_p.string = NULL;
1291 status = dcerpc_lsa_GetUserName(p, mem_ctx, &r);
1293 if (!NT_STATUS_IS_OK(status)) {
1294 printf("GetUserName failed - %s\n", nt_errstr(status));
1301 static BOOL test_Close(struct dcerpc_pipe *p,
1302 TALLOC_CTX *mem_ctx,
1303 struct policy_handle *handle)
1307 struct policy_handle handle2;
1309 printf("\ntesting Close\n");
1311 r.in.handle = handle;
1312 r.out.handle = &handle2;
1314 status = dcerpc_lsa_Close(p, mem_ctx, &r);
1315 if (!NT_STATUS_IS_OK(status)) {
1316 printf("Close failed - %s\n", nt_errstr(status));
1320 status = dcerpc_lsa_Close(p, mem_ctx, &r);
1321 /* its really a fault - we need a status code for rpc fault */
1322 if (!NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
1323 printf("Close failed - %s\n", nt_errstr(status));
1332 BOOL torture_rpc_lsa(void)
1335 struct dcerpc_pipe *p;
1336 TALLOC_CTX *mem_ctx;
1338 struct policy_handle handle;
1340 mem_ctx = talloc_init("torture_rpc_lsa");
1342 status = torture_rpc_connection(&p,
1345 DCERPC_LSARPC_VERSION);
1346 if (!NT_STATUS_IS_OK(status)) {
1350 if (!test_OpenPolicy(p, mem_ctx)) {
1354 if (!test_OpenPolicy2(p, mem_ctx, &handle)) {
1358 if (!test_many_LookupSids(p, mem_ctx, &handle)) {
1362 if (!test_CreateAccount(p, mem_ctx, &handle)) {
1366 if (!test_CreateSecret(p, mem_ctx, &handle)) {
1370 if (!test_CreateTrustedDomain(p, mem_ctx, &handle)) {
1374 if (!test_EnumAccounts(p, mem_ctx, &handle)) {
1378 if (!test_EnumPrivs(p, mem_ctx, &handle)) {
1382 if (!test_EnumTrustDom(p, mem_ctx, &handle)) {
1386 if (!test_QueryInfoPolicy(p, mem_ctx, &handle)) {
1390 if (!test_QueryInfoPolicy2(p, mem_ctx, &handle)) {
1394 if (!test_GetUserName(p, mem_ctx, &handle)) {
1399 if (!test_Delete(p, mem_ctx, &handle)) {
1404 if (!test_Close(p, mem_ctx, &handle)) {
1408 talloc_destroy(mem_ctx);
1410 torture_rpc_close(p);