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 printf("LookupSids3 failed - %s\n", nt_errstr(status));
351 if (!test_LookupNames3(p, mem_ctx, handle, &names)) {
358 static BOOL test_many_LookupSids(struct dcerpc_pipe *p,
360 struct policy_handle *handle)
362 struct lsa_LookupSids r;
363 struct lsa_TransNameArray names;
366 struct lsa_SidArray sids;
369 printf("\nTesting LookupSids with lots of SIDs\n");
376 sids.sids = talloc_array_p(mem_ctx, struct lsa_SidPtr, sids.num_sids);
378 for (i=0; i<sids.num_sids; i++) {
379 const char *sidstr = "S-1-5-32-545";
380 sids.sids[i].sid = dom_sid_parse_talloc(mem_ctx, sidstr);
383 count = sids.num_sids;
385 r.in.handle = handle;
389 r.in.count = &names.count;
390 r.out.count = &count;
391 r.out.names = &names;
393 status = dcerpc_lsa_LookupSids(p, mem_ctx, &r);
394 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
395 printf("LookupSids failed - %s\n", nt_errstr(status));
401 if (!test_LookupNames(p, mem_ctx, handle, &names)) {
408 static BOOL test_LookupPrivValue(struct dcerpc_pipe *p,
410 struct policy_handle *handle,
411 struct lsa_String *name)
414 struct lsa_LookupPrivValue r;
415 struct lsa_LUID luid;
417 r.in.handle = handle;
421 status = dcerpc_lsa_LookupPrivValue(p, mem_ctx, &r);
422 if (!NT_STATUS_IS_OK(status)) {
423 printf("\nLookupPrivValue failed - %s\n", nt_errstr(status));
430 static BOOL test_LookupPrivName(struct dcerpc_pipe *p,
432 struct policy_handle *handle,
433 struct lsa_LUID *luid)
436 struct lsa_LookupPrivName r;
438 r.in.handle = handle;
441 status = dcerpc_lsa_LookupPrivName(p, mem_ctx, &r);
442 if (!NT_STATUS_IS_OK(status)) {
443 printf("\nLookupPrivName failed - %s\n", nt_errstr(status));
450 static BOOL test_RemovePrivilegesFromAccount(struct dcerpc_pipe *p,
452 struct policy_handle *acct_handle,
453 struct lsa_LUID *luid)
456 struct lsa_RemovePrivilegesFromAccount r;
457 struct lsa_PrivilegeSet privs;
460 printf("Testing RemovePrivilegesFromAccount\n");
462 r.in.handle = acct_handle;
468 privs.set = talloc_array_p(mem_ctx, struct lsa_LUIDAttribute, 1);
469 privs.set[0].luid = *luid;
470 privs.set[0].attribute = 0;
472 status = dcerpc_lsa_RemovePrivilegesFromAccount(p, mem_ctx, &r);
473 if (!NT_STATUS_IS_OK(status)) {
474 printf("RemovePrivilegesFromAccount failed - %s\n", nt_errstr(status));
481 static BOOL test_AddPrivilegesToAccount(struct dcerpc_pipe *p,
483 struct policy_handle *acct_handle,
484 struct lsa_LUID *luid)
487 struct lsa_AddPrivilegesToAccount r;
488 struct lsa_PrivilegeSet privs;
491 printf("Testing AddPrivilegesToAccount\n");
493 r.in.handle = acct_handle;
498 privs.set = talloc_array_p(mem_ctx, struct lsa_LUIDAttribute, 1);
499 privs.set[0].luid = *luid;
500 privs.set[0].attribute = 0;
502 status = dcerpc_lsa_AddPrivilegesToAccount(p, mem_ctx, &r);
503 if (!NT_STATUS_IS_OK(status)) {
504 printf("AddPrivilegesToAccount failed - %s\n", nt_errstr(status));
511 static BOOL test_EnumPrivsAccount(struct dcerpc_pipe *p,
513 struct policy_handle *handle,
514 struct policy_handle *acct_handle)
517 struct lsa_EnumPrivsAccount r;
520 printf("Testing EnumPrivsAccount\n");
522 r.in.handle = acct_handle;
524 status = dcerpc_lsa_EnumPrivsAccount(p, mem_ctx, &r);
525 if (!NT_STATUS_IS_OK(status)) {
526 printf("EnumPrivsAccount failed - %s\n", nt_errstr(status));
530 if (r.out.privs && r.out.privs->count > 0) {
532 for (i=0;i<r.out.privs->count;i++) {
533 test_LookupPrivName(p, mem_ctx, handle,
534 &r.out.privs->set[i].luid);
537 ret &= test_RemovePrivilegesFromAccount(p, mem_ctx, acct_handle,
538 &r.out.privs->set[0].luid);
539 ret &= test_AddPrivilegesToAccount(p, mem_ctx, acct_handle,
540 &r.out.privs->set[0].luid);
546 static BOOL test_Delete(struct dcerpc_pipe *p,
548 struct policy_handle *handle)
553 printf("\ntesting Delete\n");
555 r.in.handle = handle;
556 status = dcerpc_lsa_Delete(p, mem_ctx, &r);
557 if (!NT_STATUS_IS_OK(status)) {
558 printf("Delete failed - %s\n", nt_errstr(status));
568 static BOOL test_CreateAccount(struct dcerpc_pipe *p,
570 struct policy_handle *handle)
573 struct lsa_CreateAccount r;
574 struct dom_sid2 *newsid;
575 struct policy_handle acct_handle;
577 newsid = dom_sid_parse_talloc(mem_ctx, "S-1-5-12349876-4321-2854");
579 printf("Testing CreateAccount\n");
581 r.in.handle = handle;
583 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
584 r.out.acct_handle = &acct_handle;
586 status = dcerpc_lsa_CreateAccount(p, mem_ctx, &r);
587 if (!NT_STATUS_IS_OK(status)) {
588 printf("CreateAccount failed - %s\n", nt_errstr(status));
592 if (!test_Delete(p, mem_ctx, &acct_handle)) {
600 static BOOL test_CreateTrustedDomain(struct dcerpc_pipe *p,
602 struct policy_handle *handle)
605 struct lsa_CreateTrustedDomain r;
606 struct lsa_TrustInformation trustinfo;
607 struct dom_sid *domsid;
608 struct policy_handle dom_handle;
610 printf("Testing CreateTrustedDomain\n");
612 domsid = dom_sid_parse_talloc(mem_ctx, "S-1-5-21-97398-379795-12345");
614 trustinfo.sid = domsid;
615 init_lsa_String(&trustinfo.name, "torturedomain");
617 r.in.handle = handle;
618 r.in.info = &trustinfo;
619 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
620 r.out.dom_handle = &dom_handle;
622 status = dcerpc_lsa_CreateTrustedDomain(p, mem_ctx, &r);
623 if (!NT_STATUS_IS_OK(status)) {
624 printf("CreateTrustedDomain failed - %s\n", nt_errstr(status));
628 if (!test_Delete(p, mem_ctx, &dom_handle)) {
635 static BOOL test_CreateSecret(struct dcerpc_pipe *p,
637 struct policy_handle *handle)
640 struct lsa_CreateSecret r;
641 struct lsa_OpenSecret r2;
642 struct lsa_SetSecret r3;
643 struct lsa_QuerySecret r4;
644 struct policy_handle sec_handle, sec_handle2;
646 struct lsa_DATA_BUF buf1;
647 struct lsa_DATA_BUF_PTR bufp1;
650 DATA_BLOB session_key;
651 NTTIME old_mtime, new_mtime;
652 DATA_BLOB blob1, blob2;
653 const char *secret1 = "abcdef12345699qwerty";
657 printf("Testing CreateSecret\n");
659 asprintf(&secname, "torturesecret-%u", (uint_t)random());
661 init_lsa_String(&r.in.name, secname);
663 r.in.handle = handle;
664 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
665 r.out.sec_handle = &sec_handle;
667 status = dcerpc_lsa_CreateSecret(p, mem_ctx, &r);
668 if (!NT_STATUS_IS_OK(status)) {
669 printf("CreateSecret failed - %s\n", nt_errstr(status));
673 r2.in.handle = handle;
674 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
675 r2.in.name = r.in.name;
676 r2.out.sec_handle = &sec_handle2;
678 printf("Testing OpenSecret\n");
680 status = dcerpc_lsa_OpenSecret(p, mem_ctx, &r2);
681 if (!NT_STATUS_IS_OK(status)) {
682 printf("OpenSecret failed - %s\n", nt_errstr(status));
686 status = dcerpc_fetch_session_key(p, &session_key);
687 if (!NT_STATUS_IS_OK(status)) {
688 printf("dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
692 enc_key = sess_encrypt_string(secret1, &session_key);
694 r3.in.handle = &sec_handle;
695 r3.in.new_val = &buf1;
696 r3.in.old_val = NULL;
697 r3.in.new_val->data = enc_key.data;
698 r3.in.new_val->length = enc_key.length;
699 r3.in.new_val->size = enc_key.length;
701 printf("Testing SetSecret\n");
703 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r3);
704 if (!NT_STATUS_IS_OK(status)) {
705 printf("SetSecret failed - %s\n", nt_errstr(status));
709 data_blob_free(&enc_key);
711 ZERO_STRUCT(new_mtime);
712 ZERO_STRUCT(old_mtime);
714 /* fetch the secret back again */
715 r4.in.handle = &sec_handle;
716 r4.in.new_val = &bufp1;
717 r4.in.new_mtime = &new_mtime;
718 r4.in.old_val = NULL;
719 r4.in.old_mtime = NULL;
723 status = dcerpc_lsa_QuerySecret(p, mem_ctx, &r4);
724 if (!NT_STATUS_IS_OK(status)) {
725 printf("QuerySecret failed - %s\n", nt_errstr(status));
729 if (r4.out.new_val->buf == NULL) {
730 printf("No secret buffer returned\n");
733 blob1.data = r4.out.new_val->buf->data;
734 blob1.length = r4.out.new_val->buf->length;
736 blob2 = data_blob(NULL, blob1.length);
738 secret2 = sess_decrypt_string(&blob1, &session_key);
740 printf("returned secret '%s'\n", secret2);
742 if (strcmp(secret1, secret2) != 0) {
743 printf("Returned secret doesn't match\n");
748 if (!test_Delete(p, mem_ctx, &sec_handle)) {
752 d.in.handle = &sec_handle2;
753 status = dcerpc_lsa_Delete(p, mem_ctx, &d);
754 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
755 printf("Second delete expected INVALID_HANDLE - %s\n", nt_errstr(status));
763 static BOOL test_EnumAccountRights(struct dcerpc_pipe *p,
765 struct policy_handle *acct_handle,
769 struct lsa_EnumAccountRights r;
770 struct lsa_RightSet rights;
772 printf("Testing EnumAccountRights\n");
774 r.in.handle = acct_handle;
776 r.out.rights = &rights;
778 status = dcerpc_lsa_EnumAccountRights(p, mem_ctx, &r);
779 if (!NT_STATUS_IS_OK(status)) {
780 printf("EnumAccountRights failed - %s\n", nt_errstr(status));
788 static BOOL test_QuerySecurity(struct dcerpc_pipe *p,
790 struct policy_handle *handle,
791 struct policy_handle *acct_handle)
794 struct lsa_QuerySecurity r;
796 printf("Testing QuerySecurity\n");
798 r.in.handle = acct_handle;
801 status = dcerpc_lsa_QuerySecurity(p, mem_ctx, &r);
802 if (!NT_STATUS_IS_OK(status)) {
803 printf("QuerySecurity failed - %s\n", nt_errstr(status));
810 static BOOL test_OpenAccount(struct dcerpc_pipe *p,
812 struct policy_handle *handle,
816 struct lsa_OpenAccount r;
817 struct policy_handle acct_handle;
819 printf("Testing OpenAccount\n");
821 r.in.handle = handle;
823 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
824 r.out.acct_handle = &acct_handle;
826 status = dcerpc_lsa_OpenAccount(p, mem_ctx, &r);
827 if (!NT_STATUS_IS_OK(status)) {
828 printf("OpenAccount failed - %s\n", nt_errstr(status));
832 if (!test_EnumPrivsAccount(p, mem_ctx, handle, &acct_handle)) {
836 if (!test_QuerySecurity(p, mem_ctx, handle, &acct_handle)) {
843 static BOOL test_EnumAccounts(struct dcerpc_pipe *p,
845 struct policy_handle *handle)
848 struct lsa_EnumAccounts r;
849 struct lsa_SidArray sids1, sids2;
850 uint32_t resume_handle = 0;
853 printf("\ntesting EnumAccounts\n");
855 r.in.handle = handle;
856 r.in.resume_handle = &resume_handle;
857 r.in.num_entries = 100;
858 r.out.resume_handle = &resume_handle;
863 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
864 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
867 if (!NT_STATUS_IS_OK(status)) {
868 printf("EnumAccounts failed - %s\n", nt_errstr(status));
872 if (!test_LookupSids(p, mem_ctx, handle, &sids1)) {
876 if (!test_LookupSids2(p, mem_ctx, handle, &sids1)) {
880 if (!test_LookupSids3(p, mem_ctx, handle, &sids1)) {
884 printf("testing all accounts\n");
885 for (i=0;i<sids1.num_sids;i++) {
886 test_OpenAccount(p, mem_ctx, handle, sids1.sids[i].sid);
887 test_EnumAccountRights(p, mem_ctx, handle, sids1.sids[i].sid);
892 if (sids1.num_sids < 3) {
896 printf("trying EnumAccounts partial listing (asking for 1 at 2)\n");
898 r.in.num_entries = 1;
901 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
902 if (!NT_STATUS_IS_OK(status)) {
903 printf("EnumAccounts failed - %s\n", nt_errstr(status));
907 if (sids2.num_sids != 1) {
908 printf("Returned wrong number of entries (%d)\n", sids2.num_sids);
915 static BOOL test_LookupPrivDisplayName(struct dcerpc_pipe *p,
917 struct policy_handle *handle,
918 struct lsa_String *priv_name)
920 struct lsa_LookupPrivDisplayName r;
922 /* produce a reasonable range of language output without screwing up
924 uint16 language_id = (random() % 4) + 0x409;
926 printf("testing LookupPrivDisplayName(%s)\n", priv_name->string);
928 r.in.handle = handle;
929 r.in.name = priv_name;
930 r.in.language_id = &language_id;
931 r.out.language_id = &language_id;
934 status = dcerpc_lsa_LookupPrivDisplayName(p, mem_ctx, &r);
935 if (!NT_STATUS_IS_OK(status)) {
936 printf("LookupPrivDisplayName failed - %s\n", nt_errstr(status));
939 printf("%s -> \"%s\" (language 0x%x/0x%x)\n",
940 priv_name->string, r.out.disp_name->string,
941 *r.in.language_id, *r.out.language_id);
946 static BOOL test_EnumAccountsWithUserRight(struct dcerpc_pipe *p,
948 struct policy_handle *handle,
949 struct lsa_String *priv_name)
951 struct lsa_EnumAccountsWithUserRight r;
952 struct lsa_SidArray sids;
957 printf("testing EnumAccountsWithUserRight(%s)\n", priv_name->string);
959 r.in.handle = handle;
960 r.in.name = priv_name;
963 status = dcerpc_lsa_EnumAccountsWithUserRight(p, mem_ctx, &r);
965 /* NT_STATUS_NO_MORE_ENTRIES means noone has this privilege */
966 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
970 if (!NT_STATUS_IS_OK(status)) {
971 printf("EnumAccountsWithUserRight failed - %s\n", nt_errstr(status));
979 static BOOL test_EnumPrivs(struct dcerpc_pipe *p,
981 struct policy_handle *handle)
984 struct lsa_EnumPrivs r;
985 struct lsa_PrivArray privs1;
986 uint32_t resume_handle = 0;
990 printf("\ntesting EnumPrivs\n");
992 r.in.handle = handle;
993 r.in.resume_handle = &resume_handle;
994 r.in.max_count = 100;
995 r.out.resume_handle = &resume_handle;
996 r.out.privs = &privs1;
999 status = dcerpc_lsa_EnumPrivs(p, mem_ctx, &r);
1000 if (!NT_STATUS_IS_OK(status)) {
1001 printf("EnumPrivs failed - %s\n", nt_errstr(status));
1005 for (i = 0; i< privs1.count; i++) {
1006 test_LookupPrivDisplayName(p, mem_ctx, handle, &privs1.privs[i].name);
1007 test_LookupPrivValue(p, mem_ctx, handle, &privs1.privs[i].name);
1008 if (!test_EnumAccountsWithUserRight(p, mem_ctx, handle, &privs1.privs[i].name)) {
1017 static BOOL test_EnumTrustDom(struct dcerpc_pipe *p,
1018 TALLOC_CTX *mem_ctx,
1019 struct policy_handle *handle)
1021 struct lsa_EnumTrustDom r;
1023 uint32_t resume_handle = 0;
1024 struct lsa_DomainList domains;
1028 printf("\nTesting EnumTrustDom\n");
1030 r.in.handle = handle;
1031 r.in.resume_handle = &resume_handle;
1032 r.in.num_entries = 100;
1033 r.out.domains = &domains;
1034 r.out.resume_handle = &resume_handle;
1036 status = dcerpc_lsa_EnumTrustDom(p, mem_ctx, &r);
1038 /* NO_MORE_ENTRIES is allowed */
1039 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
1043 if (!NT_STATUS_IS_OK(status)) {
1044 printf("EnumTrustDom failed - %s\n", nt_errstr(status));
1048 printf("\nTesting OpenTrustedDomain, OpenTrustedDomainByName and QueryInfoTrustedDomain\n");
1050 for (i=0; i< domains.count; i++) {
1051 struct lsa_OpenTrustedDomain trust;
1052 struct lsa_OpenTrustedDomainByName trust_by_name;
1053 struct policy_handle trustdom_handle;
1054 struct policy_handle handle2;
1056 int levels [] = {1, 3, 6, 8, 12};
1058 trust.in.handle = handle;
1059 trust.in.sid = domains.domains[i].sid;
1060 trust.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1061 trust.out.trustdom_handle = &trustdom_handle;
1063 status = dcerpc_lsa_OpenTrustedDomain(p, mem_ctx, &trust);
1065 if (!NT_STATUS_IS_OK(status)) {
1066 printf("OpenTrustedDomain failed - %s\n", nt_errstr(status));
1070 c.in.handle = &trustdom_handle;
1071 c.out.handle = &handle2;
1073 for (j=0; j < ARRAY_SIZE(levels); j++) {
1074 struct lsa_QueryTrustedDomainInfo q;
1075 union lsa_TrustedDomainInfo info;
1076 q.in.trustdom_handle = &trustdom_handle;
1077 q.in.level = levels[j];
1079 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
1080 if (!NT_STATUS_IS_OK(status)) {
1081 printf("QueryTrustedDomainInfo level %d failed - %s\n",
1082 levels[j], nt_errstr(status));
1087 status = dcerpc_lsa_Close(p, mem_ctx, &c);
1088 if (!NT_STATUS_IS_OK(status)) {
1089 printf("Close of trusted domain failed - %s\n", nt_errstr(status));
1093 trust_by_name.in.handle = handle;
1094 trust_by_name.in.name = domains.domains[i].name;
1095 trust_by_name.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1096 trust_by_name.out.trustdom_handle = &trustdom_handle;
1098 status = dcerpc_lsa_OpenTrustedDomainByName(p, mem_ctx, &trust_by_name);
1100 if (!NT_STATUS_IS_OK(status)) {
1101 printf("OpenTrustedDomainByName failed - %s\n", nt_errstr(status));
1105 for (j=0; j < ARRAY_SIZE(levels); j++) {
1106 struct lsa_QueryTrustedDomainInfo q;
1107 union lsa_TrustedDomainInfo info;
1108 q.in.trustdom_handle = &trustdom_handle;
1109 q.in.level = levels[j];
1111 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
1112 if (!NT_STATUS_IS_OK(status)) {
1113 printf("QueryTrustedDomainInfo level %d failed - %s\n",
1114 levels[j], nt_errstr(status));
1119 c.in.handle = &trustdom_handle;
1120 c.out.handle = &handle2;
1122 status = dcerpc_lsa_Close(p, mem_ctx, &c);
1123 if (!NT_STATUS_IS_OK(status)) {
1124 printf("Close of trusted domain failed - %s\n", nt_errstr(status));
1128 for (j=0; j < ARRAY_SIZE(levels); j++) {
1129 struct lsa_QueryTrustedDomainInfoBySid q;
1130 union lsa_TrustedDomainInfo info;
1131 q.in.handle = handle;
1132 q.in.dom_sid = domains.domains[i].sid;
1133 q.in.level = levels[j];
1135 status = dcerpc_lsa_QueryTrustedDomainInfoBySid(p, mem_ctx, &q);
1136 if (!NT_STATUS_IS_OK(status)) {
1137 printf("QueryTrustedDomainInfoBySid level %d failed - %s\n",
1138 levels[j], nt_errstr(status));
1143 for (j=0; j < ARRAY_SIZE(levels); j++) {
1144 struct lsa_QueryTrustedDomainInfoByName q;
1145 union lsa_TrustedDomainInfo info;
1146 q.in.handle = handle;
1147 q.in.trusted_domain = domains.domains[i].name;
1148 q.in.level = levels[j];
1150 status = dcerpc_lsa_QueryTrustedDomainInfoByName(p, mem_ctx, &q);
1151 if (!NT_STATUS_IS_OK(status)) {
1152 printf("QueryTrustedDomainInfoByName level %d failed - %s\n",
1153 levels[j], nt_errstr(status));
1165 static BOOL test_QueryInfoPolicy(struct dcerpc_pipe *p,
1166 TALLOC_CTX *mem_ctx,
1167 struct policy_handle *handle)
1169 struct lsa_QueryInfoPolicy r;
1173 printf("\nTesting QueryInfoPolicy\n");
1175 for (i=1;i<13;i++) {
1176 r.in.handle = handle;
1179 printf("\ntrying QueryInfoPolicy level %d\n", i);
1181 status = dcerpc_lsa_QueryInfoPolicy(p, mem_ctx, &r);
1183 if ((i == 9 || i == 10 || i == 11) &&
1184 NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
1185 printf("server failed level %u (OK)\n", i);
1189 if (!NT_STATUS_IS_OK(status)) {
1190 printf("QueryInfoPolicy failed - %s\n", nt_errstr(status));
1199 static BOOL test_QueryInfoPolicy2(struct dcerpc_pipe *p,
1200 TALLOC_CTX *mem_ctx,
1201 struct policy_handle *handle)
1203 struct lsa_QueryInfoPolicy2 r;
1207 printf("\nTesting QueryInfoPolicy2\n");
1209 for (i=1;i<13;i++) {
1210 r.in.handle = handle;
1213 printf("\ntrying QueryInfoPolicy2 level %d\n", i);
1215 status = dcerpc_lsa_QueryInfoPolicy2(p, mem_ctx, &r);
1217 if ((i == 9 || i == 10 || i == 11) &&
1218 NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
1219 printf("server failed level %u (OK)\n", i);
1223 if (!NT_STATUS_IS_OK(status)) {
1224 printf("QueryInfoPolicy2 failed - %s\n", nt_errstr(status));
1233 static BOOL test_GetUserName(struct dcerpc_pipe *p,
1234 TALLOC_CTX *mem_ctx,
1235 struct policy_handle *handle)
1237 struct lsa_GetUserName r;
1240 struct lsa_StringPointer authority_name_p;
1242 printf("\nTesting GetUserName\n");
1244 r.in.system_name = "\\";
1245 r.in.account_name = NULL;
1246 r.in.authority_name = &authority_name_p;
1247 authority_name_p.string = NULL;
1249 status = dcerpc_lsa_GetUserName(p, mem_ctx, &r);
1251 if (!NT_STATUS_IS_OK(status)) {
1252 printf("GetUserName failed - %s\n", nt_errstr(status));
1259 static BOOL test_Close(struct dcerpc_pipe *p,
1260 TALLOC_CTX *mem_ctx,
1261 struct policy_handle *handle)
1265 struct policy_handle handle2;
1267 printf("\ntesting Close\n");
1269 r.in.handle = handle;
1270 r.out.handle = &handle2;
1272 status = dcerpc_lsa_Close(p, mem_ctx, &r);
1273 if (!NT_STATUS_IS_OK(status)) {
1274 printf("Close failed - %s\n", nt_errstr(status));
1278 status = dcerpc_lsa_Close(p, mem_ctx, &r);
1279 /* its really a fault - we need a status code for rpc fault */
1280 if (!NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
1281 printf("Close failed - %s\n", nt_errstr(status));
1290 BOOL torture_rpc_lsa(void)
1293 struct dcerpc_pipe *p;
1294 TALLOC_CTX *mem_ctx;
1296 struct policy_handle handle;
1298 mem_ctx = talloc_init("torture_rpc_lsa");
1300 status = torture_rpc_connection(&p,
1303 DCERPC_LSARPC_VERSION);
1304 if (!NT_STATUS_IS_OK(status)) {
1308 if (!test_OpenPolicy(p, mem_ctx)) {
1312 if (!test_OpenPolicy2(p, mem_ctx, &handle)) {
1316 if (!test_many_LookupSids(p, mem_ctx, &handle)) {
1320 if (!test_CreateAccount(p, mem_ctx, &handle)) {
1324 if (!test_CreateSecret(p, mem_ctx, &handle)) {
1328 if (!test_CreateTrustedDomain(p, mem_ctx, &handle)) {
1332 if (!test_EnumAccounts(p, mem_ctx, &handle)) {
1336 if (!test_EnumPrivs(p, mem_ctx, &handle)) {
1340 if (!test_EnumTrustDom(p, mem_ctx, &handle)) {
1344 if (!test_QueryInfoPolicy(p, mem_ctx, &handle)) {
1348 if (!test_QueryInfoPolicy2(p, mem_ctx, &handle)) {
1352 if (!test_GetUserName(p, mem_ctx, &handle)) {
1357 if (!test_Delete(p, mem_ctx, &handle)) {
1362 if (!test_Close(p, mem_ctx, &handle)) {
1366 talloc_destroy(mem_ctx);
1368 torture_rpc_close(p);