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)) {
315 static BOOL test_LookupSids3(struct dcerpc_pipe *p,
317 struct policy_handle *handle,
318 struct lsa_SidArray *sids)
320 struct lsa_LookupSids3 r;
321 struct lsa_TransNameArray2 names;
322 uint32_t count = sids->num_sids;
325 printf("\nTesting LookupSids3\n");
336 r.out.count = &count;
337 r.out.names = &names;
339 status = dcerpc_lsa_LookupSids3(p, mem_ctx, &r);
340 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
341 printf("LookupSids3 failed - %s\n", nt_errstr(status));
347 if (!test_LookupNames3(p, mem_ctx, handle, &names)) {
354 static BOOL test_many_LookupSids(struct dcerpc_pipe *p,
356 struct policy_handle *handle)
358 struct lsa_LookupSids r;
359 struct lsa_TransNameArray names;
362 struct lsa_SidArray sids;
365 printf("\nTesting LookupSids with lots of SIDs\n");
372 sids.sids = talloc_array_p(mem_ctx, struct lsa_SidPtr, sids.num_sids);
374 for (i=0; i<sids.num_sids; i++) {
375 const char *sidstr = "S-1-5-32-545";
376 sids.sids[i].sid = dom_sid_parse_talloc(mem_ctx, sidstr);
379 count = sids.num_sids;
381 r.in.handle = handle;
385 r.in.count = &names.count;
386 r.out.count = &count;
387 r.out.names = &names;
389 status = dcerpc_lsa_LookupSids(p, mem_ctx, &r);
390 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
391 printf("LookupSids failed - %s\n", nt_errstr(status));
397 if (!test_LookupNames(p, mem_ctx, handle, &names)) {
404 static BOOL test_LookupPrivValue(struct dcerpc_pipe *p,
406 struct policy_handle *handle,
407 struct lsa_String *name)
410 struct lsa_LookupPrivValue r;
411 struct lsa_LUID luid;
413 r.in.handle = handle;
417 status = dcerpc_lsa_LookupPrivValue(p, mem_ctx, &r);
418 if (!NT_STATUS_IS_OK(status)) {
419 printf("\nLookupPrivValue failed - %s\n", nt_errstr(status));
426 static BOOL test_LookupPrivName(struct dcerpc_pipe *p,
428 struct policy_handle *handle,
429 struct lsa_LUID *luid)
432 struct lsa_LookupPrivName r;
434 r.in.handle = handle;
437 status = dcerpc_lsa_LookupPrivName(p, mem_ctx, &r);
438 if (!NT_STATUS_IS_OK(status)) {
439 printf("\nLookupPrivName failed - %s\n", nt_errstr(status));
446 static BOOL test_RemovePrivilegesFromAccount(struct dcerpc_pipe *p,
448 struct policy_handle *acct_handle,
449 struct lsa_LUID *luid)
452 struct lsa_RemovePrivilegesFromAccount r;
453 struct lsa_PrivilegeSet privs;
456 printf("Testing RemovePrivilegesFromAccount\n");
458 r.in.handle = acct_handle;
464 privs.set = talloc_array_p(mem_ctx, struct lsa_LUIDAttribute, 1);
465 privs.set[0].luid = *luid;
466 privs.set[0].attribute = 0;
468 status = dcerpc_lsa_RemovePrivilegesFromAccount(p, mem_ctx, &r);
469 if (!NT_STATUS_IS_OK(status)) {
470 printf("RemovePrivilegesFromAccount failed - %s\n", nt_errstr(status));
477 static BOOL test_AddPrivilegesToAccount(struct dcerpc_pipe *p,
479 struct policy_handle *acct_handle,
480 struct lsa_LUID *luid)
483 struct lsa_AddPrivilegesToAccount r;
484 struct lsa_PrivilegeSet privs;
487 printf("Testing AddPrivilegesToAccount\n");
489 r.in.handle = acct_handle;
494 privs.set = talloc_array_p(mem_ctx, struct lsa_LUIDAttribute, 1);
495 privs.set[0].luid = *luid;
496 privs.set[0].attribute = 0;
498 status = dcerpc_lsa_AddPrivilegesToAccount(p, mem_ctx, &r);
499 if (!NT_STATUS_IS_OK(status)) {
500 printf("AddPrivilegesToAccount failed - %s\n", nt_errstr(status));
507 static BOOL test_EnumPrivsAccount(struct dcerpc_pipe *p,
509 struct policy_handle *handle,
510 struct policy_handle *acct_handle)
513 struct lsa_EnumPrivsAccount r;
516 printf("Testing EnumPrivsAccount\n");
518 r.in.handle = acct_handle;
520 status = dcerpc_lsa_EnumPrivsAccount(p, mem_ctx, &r);
521 if (!NT_STATUS_IS_OK(status)) {
522 printf("EnumPrivsAccount failed - %s\n", nt_errstr(status));
526 if (r.out.privs && r.out.privs->count > 0) {
528 for (i=0;i<r.out.privs->count;i++) {
529 test_LookupPrivName(p, mem_ctx, handle,
530 &r.out.privs->set[i].luid);
533 ret &= test_RemovePrivilegesFromAccount(p, mem_ctx, acct_handle,
534 &r.out.privs->set[0].luid);
535 ret &= test_AddPrivilegesToAccount(p, mem_ctx, acct_handle,
536 &r.out.privs->set[0].luid);
542 static BOOL test_Delete(struct dcerpc_pipe *p,
544 struct policy_handle *handle)
549 printf("\ntesting Delete\n");
551 r.in.handle = handle;
552 status = dcerpc_lsa_Delete(p, mem_ctx, &r);
553 if (!NT_STATUS_IS_OK(status)) {
554 printf("Delete failed - %s\n", nt_errstr(status));
564 static BOOL test_CreateAccount(struct dcerpc_pipe *p,
566 struct policy_handle *handle)
569 struct lsa_CreateAccount r;
570 struct dom_sid2 *newsid;
571 struct policy_handle acct_handle;
573 newsid = dom_sid_parse_talloc(mem_ctx, "S-1-5-12349876-4321-2854");
575 printf("Testing CreateAccount\n");
577 r.in.handle = handle;
579 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
580 r.out.acct_handle = &acct_handle;
582 status = dcerpc_lsa_CreateAccount(p, mem_ctx, &r);
583 if (!NT_STATUS_IS_OK(status)) {
584 printf("CreateAccount failed - %s\n", nt_errstr(status));
588 if (!test_Delete(p, mem_ctx, &acct_handle)) {
596 static BOOL test_CreateTrustedDomain(struct dcerpc_pipe *p,
598 struct policy_handle *handle)
601 struct lsa_CreateTrustedDomain r;
602 struct lsa_TrustInformation trustinfo;
603 struct dom_sid *domsid;
604 struct policy_handle dom_handle;
606 printf("Testing CreateTrustedDomain\n");
608 domsid = dom_sid_parse_talloc(mem_ctx, "S-1-5-21-97398-379795-12345");
610 trustinfo.sid = domsid;
611 init_lsa_String(&trustinfo.name, "torturedomain");
613 r.in.handle = handle;
614 r.in.info = &trustinfo;
615 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
616 r.out.dom_handle = &dom_handle;
618 status = dcerpc_lsa_CreateTrustedDomain(p, mem_ctx, &r);
619 if (!NT_STATUS_IS_OK(status)) {
620 printf("CreateTrustedDomain failed - %s\n", nt_errstr(status));
624 if (!test_Delete(p, mem_ctx, &dom_handle)) {
631 static BOOL test_CreateSecret(struct dcerpc_pipe *p,
633 struct policy_handle *handle)
636 struct lsa_CreateSecret r;
637 struct lsa_OpenSecret r2;
638 struct lsa_SetSecret r3;
639 struct lsa_QuerySecret r4;
640 struct policy_handle sec_handle, sec_handle2;
642 struct lsa_DATA_BUF buf1;
643 struct lsa_DATA_BUF_PTR bufp1;
646 DATA_BLOB session_key;
647 NTTIME old_mtime, new_mtime;
648 DATA_BLOB blob1, blob2;
649 const char *secret1 = "abcdef12345699qwerty";
653 printf("Testing CreateSecret\n");
655 asprintf(&secname, "torturesecret-%u", (uint_t)random());
657 init_lsa_String(&r.in.name, secname);
659 r.in.handle = handle;
660 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
661 r.out.sec_handle = &sec_handle;
663 status = dcerpc_lsa_CreateSecret(p, mem_ctx, &r);
664 if (!NT_STATUS_IS_OK(status)) {
665 printf("CreateSecret failed - %s\n", nt_errstr(status));
669 r2.in.handle = handle;
670 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
671 r2.in.name = r.in.name;
672 r2.out.sec_handle = &sec_handle2;
674 printf("Testing OpenSecret\n");
676 status = dcerpc_lsa_OpenSecret(p, mem_ctx, &r2);
677 if (!NT_STATUS_IS_OK(status)) {
678 printf("OpenSecret failed - %s\n", nt_errstr(status));
682 status = dcerpc_fetch_session_key(p, &session_key);
683 if (!NT_STATUS_IS_OK(status)) {
684 printf("dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
688 enc_key = sess_encrypt_string(secret1, &session_key);
690 r3.in.handle = &sec_handle;
691 r3.in.new_val = &buf1;
692 r3.in.old_val = NULL;
693 r3.in.new_val->data = enc_key.data;
694 r3.in.new_val->length = enc_key.length;
695 r3.in.new_val->size = enc_key.length;
697 printf("Testing SetSecret\n");
699 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r3);
700 if (!NT_STATUS_IS_OK(status)) {
701 printf("SetSecret failed - %s\n", nt_errstr(status));
705 data_blob_free(&enc_key);
707 ZERO_STRUCT(new_mtime);
708 ZERO_STRUCT(old_mtime);
710 /* fetch the secret back again */
711 r4.in.handle = &sec_handle;
712 r4.in.new_val = &bufp1;
713 r4.in.new_mtime = &new_mtime;
714 r4.in.old_val = NULL;
715 r4.in.old_mtime = NULL;
719 status = dcerpc_lsa_QuerySecret(p, mem_ctx, &r4);
720 if (!NT_STATUS_IS_OK(status)) {
721 printf("QuerySecret failed - %s\n", nt_errstr(status));
725 if (r4.out.new_val->buf == NULL) {
726 printf("No secret buffer returned\n");
729 blob1.data = r4.out.new_val->buf->data;
730 blob1.length = r4.out.new_val->buf->length;
732 blob2 = data_blob(NULL, blob1.length);
734 secret2 = sess_decrypt_string(&blob1, &session_key);
736 printf("returned secret '%s'\n", secret2);
738 if (strcmp(secret1, secret2) != 0) {
739 printf("Returned secret doesn't match\n");
744 if (!test_Delete(p, mem_ctx, &sec_handle)) {
748 d.in.handle = &sec_handle2;
749 status = dcerpc_lsa_Delete(p, mem_ctx, &d);
750 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
751 printf("Second delete expected INVALID_HANDLE - %s\n", nt_errstr(status));
759 static BOOL test_EnumAccountRights(struct dcerpc_pipe *p,
761 struct policy_handle *acct_handle,
765 struct lsa_EnumAccountRights r;
766 struct lsa_RightSet rights;
768 printf("Testing EnumAccountRights\n");
770 r.in.handle = acct_handle;
772 r.out.rights = &rights;
774 status = dcerpc_lsa_EnumAccountRights(p, mem_ctx, &r);
775 if (!NT_STATUS_IS_OK(status)) {
776 printf("EnumAccountRights failed - %s\n", nt_errstr(status));
784 static BOOL test_QuerySecurity(struct dcerpc_pipe *p,
786 struct policy_handle *handle,
787 struct policy_handle *acct_handle)
790 struct lsa_QuerySecurity r;
792 printf("Testing QuerySecurity\n");
794 r.in.handle = acct_handle;
797 status = dcerpc_lsa_QuerySecurity(p, mem_ctx, &r);
798 if (!NT_STATUS_IS_OK(status)) {
799 printf("QuerySecurity failed - %s\n", nt_errstr(status));
806 static BOOL test_OpenAccount(struct dcerpc_pipe *p,
808 struct policy_handle *handle,
812 struct lsa_OpenAccount r;
813 struct policy_handle acct_handle;
815 printf("Testing OpenAccount\n");
817 r.in.handle = handle;
819 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
820 r.out.acct_handle = &acct_handle;
822 status = dcerpc_lsa_OpenAccount(p, mem_ctx, &r);
823 if (!NT_STATUS_IS_OK(status)) {
824 printf("OpenAccount failed - %s\n", nt_errstr(status));
828 if (!test_EnumPrivsAccount(p, mem_ctx, handle, &acct_handle)) {
832 if (!test_QuerySecurity(p, mem_ctx, handle, &acct_handle)) {
839 static BOOL test_EnumAccounts(struct dcerpc_pipe *p,
841 struct policy_handle *handle)
844 struct lsa_EnumAccounts r;
845 struct lsa_SidArray sids1, sids2;
846 uint32_t resume_handle = 0;
849 printf("\ntesting EnumAccounts\n");
851 r.in.handle = handle;
852 r.in.resume_handle = &resume_handle;
853 r.in.num_entries = 100;
854 r.out.resume_handle = &resume_handle;
859 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
860 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
863 if (!NT_STATUS_IS_OK(status)) {
864 printf("EnumAccounts failed - %s\n", nt_errstr(status));
868 if (!test_LookupSids(p, mem_ctx, handle, &sids1)) {
872 if (!test_LookupSids2(p, mem_ctx, handle, &sids1)) {
876 if (!test_LookupSids3(p, mem_ctx, handle, &sids1)) {
880 printf("testing all accounts\n");
881 for (i=0;i<sids1.num_sids;i++) {
882 test_OpenAccount(p, mem_ctx, handle, sids1.sids[i].sid);
883 test_EnumAccountRights(p, mem_ctx, handle, sids1.sids[i].sid);
888 if (sids1.num_sids < 3) {
892 printf("trying EnumAccounts partial listing (asking for 1 at 2)\n");
894 r.in.num_entries = 1;
897 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
898 if (!NT_STATUS_IS_OK(status)) {
899 printf("EnumAccounts failed - %s\n", nt_errstr(status));
903 if (sids2.num_sids != 1) {
904 printf("Returned wrong number of entries (%d)\n", sids2.num_sids);
911 static BOOL test_LookupPrivDisplayName(struct dcerpc_pipe *p,
913 struct policy_handle *handle,
914 struct lsa_String *priv_name)
916 struct lsa_LookupPrivDisplayName r;
918 /* produce a reasonable range of language output without screwing up
920 uint16 language_id = (random() % 4) + 0x409;
922 printf("testing LookupPrivDisplayName(%s)\n", priv_name->string);
924 r.in.handle = handle;
925 r.in.name = priv_name;
926 r.in.language_id = &language_id;
927 r.out.language_id = &language_id;
930 status = dcerpc_lsa_LookupPrivDisplayName(p, mem_ctx, &r);
931 if (!NT_STATUS_IS_OK(status)) {
932 printf("LookupPrivDisplayName failed - %s\n", nt_errstr(status));
935 printf("%s -> \"%s\" (language 0x%x/0x%x)\n",
936 priv_name->string, r.out.disp_name->string,
937 *r.in.language_id, *r.out.language_id);
942 static BOOL test_EnumAccountsWithUserRight(struct dcerpc_pipe *p,
944 struct policy_handle *handle,
945 struct lsa_String *priv_name)
947 struct lsa_EnumAccountsWithUserRight r;
948 struct lsa_SidArray sids;
953 printf("testing EnumAccountsWithUserRight(%s)\n", priv_name->string);
955 r.in.handle = handle;
956 r.in.name = priv_name;
959 status = dcerpc_lsa_EnumAccountsWithUserRight(p, mem_ctx, &r);
961 /* NT_STATUS_NO_MORE_ENTRIES means noone has this privilege */
962 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
966 if (!NT_STATUS_IS_OK(status)) {
967 printf("EnumAccountsWithUserRight failed - %s\n", nt_errstr(status));
975 static BOOL test_EnumPrivs(struct dcerpc_pipe *p,
977 struct policy_handle *handle)
980 struct lsa_EnumPrivs r;
981 struct lsa_PrivArray privs1;
982 uint32_t resume_handle = 0;
986 printf("\ntesting EnumPrivs\n");
988 r.in.handle = handle;
989 r.in.resume_handle = &resume_handle;
990 r.in.max_count = 100;
991 r.out.resume_handle = &resume_handle;
992 r.out.privs = &privs1;
995 status = dcerpc_lsa_EnumPrivs(p, mem_ctx, &r);
996 if (!NT_STATUS_IS_OK(status)) {
997 printf("EnumPrivs failed - %s\n", nt_errstr(status));
1001 for (i = 0; i< privs1.count; i++) {
1002 test_LookupPrivDisplayName(p, mem_ctx, handle, &privs1.privs[i].name);
1003 test_LookupPrivValue(p, mem_ctx, handle, &privs1.privs[i].name);
1004 if (!test_EnumAccountsWithUserRight(p, mem_ctx, handle, &privs1.privs[i].name)) {
1013 static BOOL test_EnumTrustDom(struct dcerpc_pipe *p,
1014 TALLOC_CTX *mem_ctx,
1015 struct policy_handle *handle)
1017 struct lsa_EnumTrustDom r;
1019 uint32_t resume_handle = 0;
1020 struct lsa_DomainList domains;
1024 printf("\nTesting EnumTrustDom\n");
1026 r.in.handle = handle;
1027 r.in.resume_handle = &resume_handle;
1028 r.in.num_entries = 100;
1029 r.out.domains = &domains;
1030 r.out.resume_handle = &resume_handle;
1032 status = dcerpc_lsa_EnumTrustDom(p, mem_ctx, &r);
1034 /* NO_MORE_ENTRIES is allowed */
1035 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
1039 if (!NT_STATUS_IS_OK(status)) {
1040 printf("EnumTrustDom failed - %s\n", nt_errstr(status));
1044 printf("\nTesting OpenTrustedDomain, OpenTrustedDomainByName and QueryInfoTrustedDomain\n");
1046 for (i=0; i< domains.count; i++) {
1047 struct lsa_OpenTrustedDomain trust;
1048 struct lsa_OpenTrustedDomainByName trust_by_name;
1049 struct policy_handle trustdom_handle;
1050 struct policy_handle handle2;
1052 int levels [] = {1, 3, 6, 8, 12};
1054 trust.in.handle = handle;
1055 trust.in.sid = domains.domains[i].sid;
1056 trust.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1057 trust.out.trustdom_handle = &trustdom_handle;
1059 status = dcerpc_lsa_OpenTrustedDomain(p, mem_ctx, &trust);
1061 if (!NT_STATUS_IS_OK(status)) {
1062 printf("OpenTrustedDomain failed - %s\n", nt_errstr(status));
1066 c.in.handle = &trustdom_handle;
1067 c.out.handle = &handle2;
1069 for (j=0; j < ARRAY_SIZE(levels); j++) {
1070 struct lsa_QueryTrustedDomainInfo q;
1071 union lsa_TrustedDomainInfo info;
1072 q.in.trustdom_handle = &trustdom_handle;
1073 q.in.level = levels[j];
1075 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
1076 if (!NT_STATUS_IS_OK(status)) {
1077 printf("QueryTrustedDomainInfo level %d failed - %s\n",
1078 levels[j], nt_errstr(status));
1083 status = dcerpc_lsa_Close(p, mem_ctx, &c);
1084 if (!NT_STATUS_IS_OK(status)) {
1085 printf("Close of trusted domain failed - %s\n", nt_errstr(status));
1089 trust_by_name.in.handle = handle;
1090 trust_by_name.in.name = domains.domains[i].name;
1091 trust_by_name.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1092 trust_by_name.out.trustdom_handle = &trustdom_handle;
1094 status = dcerpc_lsa_OpenTrustedDomainByName(p, mem_ctx, &trust_by_name);
1096 if (!NT_STATUS_IS_OK(status)) {
1097 printf("OpenTrustedDomainByName failed - %s\n", nt_errstr(status));
1101 for (j=0; j < ARRAY_SIZE(levels); j++) {
1102 struct lsa_QueryTrustedDomainInfo q;
1103 union lsa_TrustedDomainInfo info;
1104 q.in.trustdom_handle = &trustdom_handle;
1105 q.in.level = levels[j];
1107 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
1108 if (!NT_STATUS_IS_OK(status)) {
1109 printf("QueryTrustedDomainInfo level %d failed - %s\n",
1110 levels[j], nt_errstr(status));
1115 c.in.handle = &trustdom_handle;
1116 c.out.handle = &handle2;
1118 status = dcerpc_lsa_Close(p, mem_ctx, &c);
1119 if (!NT_STATUS_IS_OK(status)) {
1120 printf("Close of trusted domain failed - %s\n", nt_errstr(status));
1124 for (j=0; j < ARRAY_SIZE(levels); j++) {
1125 struct lsa_QueryTrustedDomainInfoBySid q;
1126 union lsa_TrustedDomainInfo info;
1127 q.in.handle = handle;
1128 q.in.dom_sid = domains.domains[i].sid;
1129 q.in.level = levels[j];
1131 status = dcerpc_lsa_QueryTrustedDomainInfoBySid(p, mem_ctx, &q);
1132 if (!NT_STATUS_IS_OK(status)) {
1133 printf("QueryTrustedDomainInfoBySid level %d failed - %s\n",
1134 levels[j], nt_errstr(status));
1139 for (j=0; j < ARRAY_SIZE(levels); j++) {
1140 struct lsa_QueryTrustedDomainInfoByName q;
1141 union lsa_TrustedDomainInfo info;
1142 q.in.handle = handle;
1143 q.in.trusted_domain = domains.domains[i].name;
1144 q.in.level = levels[j];
1146 status = dcerpc_lsa_QueryTrustedDomainInfoByName(p, mem_ctx, &q);
1147 if (!NT_STATUS_IS_OK(status)) {
1148 printf("QueryTrustedDomainInfoByName level %d failed - %s\n",
1149 levels[j], nt_errstr(status));
1161 static BOOL test_QueryInfoPolicy(struct dcerpc_pipe *p,
1162 TALLOC_CTX *mem_ctx,
1163 struct policy_handle *handle)
1165 struct lsa_QueryInfoPolicy r;
1169 printf("\nTesting QueryInfoPolicy\n");
1171 for (i=1;i<13;i++) {
1172 r.in.handle = handle;
1175 printf("\ntrying QueryInfoPolicy level %d\n", i);
1177 status = dcerpc_lsa_QueryInfoPolicy(p, mem_ctx, &r);
1179 if ((i == 9 || i == 10 || i == 11) &&
1180 NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
1181 printf("server failed level %u (OK)\n", i);
1185 if (!NT_STATUS_IS_OK(status)) {
1186 printf("QueryInfoPolicy failed - %s\n", nt_errstr(status));
1195 static BOOL test_QueryInfoPolicy2(struct dcerpc_pipe *p,
1196 TALLOC_CTX *mem_ctx,
1197 struct policy_handle *handle)
1199 struct lsa_QueryInfoPolicy2 r;
1203 printf("\nTesting QueryInfoPolicy2\n");
1205 for (i=1;i<13;i++) {
1206 r.in.handle = handle;
1209 printf("\ntrying QueryInfoPolicy2 level %d\n", i);
1211 status = dcerpc_lsa_QueryInfoPolicy2(p, mem_ctx, &r);
1213 if ((i == 9 || i == 10 || i == 11) &&
1214 NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
1215 printf("server failed level %u (OK)\n", i);
1219 if (!NT_STATUS_IS_OK(status)) {
1220 printf("QueryInfoPolicy2 failed - %s\n", nt_errstr(status));
1229 static BOOL test_GetUserName(struct dcerpc_pipe *p,
1230 TALLOC_CTX *mem_ctx,
1231 struct policy_handle *handle)
1233 struct lsa_GetUserName r;
1236 struct lsa_StringPointer authority_name_p;
1238 printf("\nTesting GetUserName\n");
1240 r.in.system_name = "\\";
1241 r.in.account_name = NULL;
1242 r.in.authority_name = &authority_name_p;
1243 authority_name_p.string = NULL;
1245 status = dcerpc_lsa_GetUserName(p, mem_ctx, &r);
1247 if (!NT_STATUS_IS_OK(status)) {
1248 printf("GetUserName failed - %s\n", nt_errstr(status));
1255 static BOOL test_Close(struct dcerpc_pipe *p,
1256 TALLOC_CTX *mem_ctx,
1257 struct policy_handle *handle)
1261 struct policy_handle handle2;
1263 printf("\ntesting Close\n");
1265 r.in.handle = handle;
1266 r.out.handle = &handle2;
1268 status = dcerpc_lsa_Close(p, mem_ctx, &r);
1269 if (!NT_STATUS_IS_OK(status)) {
1270 printf("Close failed - %s\n", nt_errstr(status));
1274 status = dcerpc_lsa_Close(p, mem_ctx, &r);
1275 /* its really a fault - we need a status code for rpc fault */
1276 if (!NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
1277 printf("Close failed - %s\n", nt_errstr(status));
1286 BOOL torture_rpc_lsa(void)
1289 struct dcerpc_pipe *p;
1290 TALLOC_CTX *mem_ctx;
1292 struct policy_handle handle;
1294 mem_ctx = talloc_init("torture_rpc_lsa");
1296 status = torture_rpc_connection(&p,
1299 DCERPC_LSARPC_VERSION);
1300 if (!NT_STATUS_IS_OK(status)) {
1304 if (!test_OpenPolicy(p, mem_ctx)) {
1308 if (!test_OpenPolicy2(p, mem_ctx, &handle)) {
1312 if (!test_many_LookupSids(p, mem_ctx, &handle)) {
1316 if (!test_CreateAccount(p, mem_ctx, &handle)) {
1320 if (!test_CreateSecret(p, mem_ctx, &handle)) {
1324 if (!test_CreateTrustedDomain(p, mem_ctx, &handle)) {
1328 if (!test_EnumAccounts(p, mem_ctx, &handle)) {
1332 if (!test_EnumPrivs(p, mem_ctx, &handle)) {
1336 if (!test_EnumTrustDom(p, mem_ctx, &handle)) {
1340 if (!test_QueryInfoPolicy(p, mem_ctx, &handle)) {
1344 if (!test_QueryInfoPolicy2(p, mem_ctx, &handle)) {
1348 if (!test_GetUserName(p, mem_ctx, &handle)) {
1353 if (!test_Delete(p, mem_ctx, &handle)) {
1358 if (!test_Close(p, mem_ctx, &handle)) {
1362 talloc_destroy(mem_ctx);
1364 torture_rpc_close(p);