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_LookupSids(struct dcerpc_pipe *p,
193 struct policy_handle *handle,
194 struct lsa_SidArray *sids)
196 struct lsa_LookupSids r;
197 struct lsa_TransNameArray names;
198 uint32_t count = sids->num_sids;
201 printf("\nTesting LookupSids\n");
206 r.in.handle = handle;
211 r.out.count = &count;
212 r.out.names = &names;
214 status = dcerpc_lsa_LookupSids(p, mem_ctx, &r);
215 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
216 printf("LookupSids failed - %s\n", nt_errstr(status));
222 if (!test_LookupNames(p, mem_ctx, handle, &names)) {
230 static BOOL test_LookupSids2(struct dcerpc_pipe *p,
232 struct policy_handle *handle,
233 struct lsa_SidArray *sids)
235 struct lsa_LookupSids2 r;
236 struct lsa_TransNameArray2 names;
237 uint32_t count = sids->num_sids;
240 printf("\nTesting LookupSids2\n");
245 r.in.handle = handle;
252 r.out.count = &count;
253 r.out.names = &names;
255 status = dcerpc_lsa_LookupSids2(p, mem_ctx, &r);
256 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
257 printf("LookupSids2 failed - %s\n", nt_errstr(status));
263 if (!test_LookupNames2(p, mem_ctx, handle, &names)) {
270 static BOOL test_many_LookupSids(struct dcerpc_pipe *p,
272 struct policy_handle *handle)
274 struct lsa_LookupSids r;
275 struct lsa_TransNameArray names;
278 struct lsa_SidArray sids;
281 printf("\nTesting LookupSids with lots of SIDs\n");
288 sids.sids = talloc_array_p(mem_ctx, struct lsa_SidPtr, sids.num_sids);
290 for (i=0; i<sids.num_sids; i++) {
291 const char *sidstr = "S-1-5-32-545";
292 sids.sids[i].sid = dom_sid_parse_talloc(mem_ctx, sidstr);
295 count = sids.num_sids;
297 r.in.handle = handle;
301 r.in.count = &names.count;
302 r.out.count = &count;
303 r.out.names = &names;
305 status = dcerpc_lsa_LookupSids(p, mem_ctx, &r);
306 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
307 printf("LookupSids failed - %s\n", nt_errstr(status));
313 if (!test_LookupNames(p, mem_ctx, handle, &names)) {
320 static BOOL test_LookupPrivValue(struct dcerpc_pipe *p,
322 struct policy_handle *handle,
323 struct lsa_String *name)
326 struct lsa_LookupPrivValue r;
328 r.in.handle = handle;
331 status = dcerpc_lsa_LookupPrivValue(p, mem_ctx, &r);
332 if (!NT_STATUS_IS_OK(status)) {
333 printf("\nLookupPrivValue failed - %s\n", nt_errstr(status));
340 static BOOL test_LookupPrivName(struct dcerpc_pipe *p,
342 struct policy_handle *handle,
343 struct lsa_LUID *luid)
346 struct lsa_LookupPrivName r;
348 r.in.handle = handle;
351 status = dcerpc_lsa_LookupPrivName(p, mem_ctx, &r);
352 if (!NT_STATUS_IS_OK(status)) {
353 printf("\nLookupPrivName failed - %s\n", nt_errstr(status));
360 static BOOL test_RemovePrivilegesFromAccount(struct dcerpc_pipe *p,
362 struct policy_handle *acct_handle,
363 struct lsa_LUID *luid)
366 struct lsa_RemovePrivilegesFromAccount r;
367 struct lsa_PrivilegeSet privs;
370 printf("Testing RemovePrivilegesFromAccount\n");
372 r.in.handle = acct_handle;
378 privs.set = talloc_array_p(mem_ctx, struct lsa_LUIDAttribute, 1);
379 privs.set[0].luid = *luid;
380 privs.set[0].attribute = 0;
382 status = dcerpc_lsa_RemovePrivilegesFromAccount(p, mem_ctx, &r);
383 if (!NT_STATUS_IS_OK(status)) {
384 printf("RemovePrivilegesFromAccount failed - %s\n", nt_errstr(status));
391 static BOOL test_AddPrivilegesToAccount(struct dcerpc_pipe *p,
393 struct policy_handle *acct_handle,
394 struct lsa_LUID *luid)
397 struct lsa_AddPrivilegesToAccount r;
398 struct lsa_PrivilegeSet privs;
401 printf("Testing AddPrivilegesToAccount\n");
403 r.in.handle = acct_handle;
408 privs.set = talloc_array_p(mem_ctx, struct lsa_LUIDAttribute, 1);
409 privs.set[0].luid = *luid;
410 privs.set[0].attribute = 0;
412 status = dcerpc_lsa_AddPrivilegesToAccount(p, mem_ctx, &r);
413 if (!NT_STATUS_IS_OK(status)) {
414 printf("AddPrivilegesToAccount failed - %s\n", nt_errstr(status));
421 static BOOL test_EnumPrivsAccount(struct dcerpc_pipe *p,
423 struct policy_handle *handle,
424 struct policy_handle *acct_handle)
427 struct lsa_EnumPrivsAccount r;
430 printf("Testing EnumPrivsAccount\n");
432 r.in.handle = acct_handle;
434 status = dcerpc_lsa_EnumPrivsAccount(p, mem_ctx, &r);
435 if (!NT_STATUS_IS_OK(status)) {
436 printf("EnumPrivsAccount failed - %s\n", nt_errstr(status));
440 if (r.out.privs && r.out.privs->count > 0) {
442 for (i=0;i<r.out.privs->count;i++) {
443 test_LookupPrivName(p, mem_ctx, handle,
444 &r.out.privs->set[i].luid);
447 ret &= test_RemovePrivilegesFromAccount(p, mem_ctx, acct_handle,
448 &r.out.privs->set[0].luid);
449 ret &= test_AddPrivilegesToAccount(p, mem_ctx, acct_handle,
450 &r.out.privs->set[0].luid);
456 static BOOL test_Delete(struct dcerpc_pipe *p,
458 struct policy_handle *handle)
463 printf("\ntesting Delete\n");
465 r.in.handle = handle;
466 status = dcerpc_lsa_Delete(p, mem_ctx, &r);
467 if (!NT_STATUS_IS_OK(status)) {
468 printf("Delete failed - %s\n", nt_errstr(status));
478 static BOOL test_CreateAccount(struct dcerpc_pipe *p,
480 struct policy_handle *handle)
483 struct lsa_CreateAccount r;
484 struct dom_sid2 *newsid;
485 struct policy_handle acct_handle;
487 newsid = dom_sid_parse_talloc(mem_ctx, "S-1-5-12349876-4321-2854");
489 printf("Testing CreateAccount\n");
491 r.in.handle = handle;
493 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
494 r.out.acct_handle = &acct_handle;
496 status = dcerpc_lsa_CreateAccount(p, mem_ctx, &r);
497 if (!NT_STATUS_IS_OK(status)) {
498 printf("CreateAccount failed - %s\n", nt_errstr(status));
502 if (!test_Delete(p, mem_ctx, &acct_handle)) {
510 static BOOL test_CreateTrustedDomain(struct dcerpc_pipe *p,
512 struct policy_handle *handle)
515 struct lsa_CreateTrustedDomain r;
516 struct lsa_TrustInformation trustinfo;
517 struct dom_sid *domsid;
518 struct policy_handle dom_handle;
520 printf("Testing CreateTrustedDomain\n");
522 domsid = dom_sid_parse_talloc(mem_ctx, "S-1-5-21-97398-379795-12345");
524 trustinfo.sid = domsid;
525 init_lsa_String(&trustinfo.name, "torturedomain");
527 r.in.handle = handle;
528 r.in.info = &trustinfo;
529 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
530 r.out.dom_handle = &dom_handle;
532 status = dcerpc_lsa_CreateTrustedDomain(p, mem_ctx, &r);
533 if (!NT_STATUS_IS_OK(status)) {
534 printf("CreateTrustedDomain failed - %s\n", nt_errstr(status));
538 if (!test_Delete(p, mem_ctx, &dom_handle)) {
545 static BOOL test_CreateSecret(struct dcerpc_pipe *p,
547 struct policy_handle *handle)
550 struct lsa_CreateSecret r;
551 struct lsa_OpenSecret r2;
552 struct lsa_SetSecret r3;
553 struct lsa_QuerySecret r4;
554 struct policy_handle sec_handle, sec_handle2;
556 struct lsa_DATA_BUF buf1;
557 struct lsa_DATA_BUF_PTR bufp1;
560 DATA_BLOB session_key;
561 NTTIME old_mtime, new_mtime;
562 DATA_BLOB blob1, blob2;
563 const char *secret1 = "abcdef12345699qwerty";
567 printf("Testing CreateSecret\n");
569 asprintf(&secname, "torturesecret-%u", (uint_t)random());
571 init_lsa_String(&r.in.name, secname);
573 r.in.handle = handle;
574 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
575 r.out.sec_handle = &sec_handle;
577 status = dcerpc_lsa_CreateSecret(p, mem_ctx, &r);
578 if (!NT_STATUS_IS_OK(status)) {
579 printf("CreateSecret failed - %s\n", nt_errstr(status));
583 r2.in.handle = handle;
584 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
585 r2.in.name = r.in.name;
586 r2.out.sec_handle = &sec_handle2;
588 printf("Testing OpenSecret\n");
590 status = dcerpc_lsa_OpenSecret(p, mem_ctx, &r2);
591 if (!NT_STATUS_IS_OK(status)) {
592 printf("OpenSecret failed - %s\n", nt_errstr(status));
596 status = dcerpc_fetch_session_key(p, &session_key);
597 if (!NT_STATUS_IS_OK(status)) {
598 printf("dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
602 enc_key = sess_encrypt_string(secret1, &session_key);
604 r3.in.handle = &sec_handle;
605 r3.in.new_val = &buf1;
606 r3.in.old_val = NULL;
607 r3.in.new_val->data = enc_key.data;
608 r3.in.new_val->length = enc_key.length;
609 r3.in.new_val->size = enc_key.length;
611 printf("Testing SetSecret\n");
613 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r3);
614 if (!NT_STATUS_IS_OK(status)) {
615 printf("SetSecret failed - %s\n", nt_errstr(status));
619 data_blob_free(&enc_key);
621 ZERO_STRUCT(new_mtime);
622 ZERO_STRUCT(old_mtime);
624 /* fetch the secret back again */
625 r4.in.handle = &sec_handle;
626 r4.in.new_val = &bufp1;
627 r4.in.new_mtime = &new_mtime;
628 r4.in.old_val = NULL;
629 r4.in.old_mtime = NULL;
633 status = dcerpc_lsa_QuerySecret(p, mem_ctx, &r4);
634 if (!NT_STATUS_IS_OK(status)) {
635 printf("QuerySecret failed - %s\n", nt_errstr(status));
639 if (r4.out.new_val->buf == NULL) {
640 printf("No secret buffer returned\n");
643 blob1.data = r4.out.new_val->buf->data;
644 blob1.length = r4.out.new_val->buf->length;
646 blob2 = data_blob(NULL, blob1.length);
648 secret2 = sess_decrypt_string(&blob1, &session_key);
650 printf("returned secret '%s'\n", secret2);
652 if (strcmp(secret1, secret2) != 0) {
653 printf("Returned secret doesn't match\n");
658 if (!test_Delete(p, mem_ctx, &sec_handle)) {
662 d.in.handle = &sec_handle2;
663 status = dcerpc_lsa_Delete(p, mem_ctx, &d);
664 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
665 printf("Second delete expected INVALID_HANDLE - %s\n", nt_errstr(status));
673 static BOOL test_EnumAccountRights(struct dcerpc_pipe *p,
675 struct policy_handle *acct_handle,
679 struct lsa_EnumAccountRights r;
680 struct lsa_RightSet rights;
682 printf("Testing EnumAccountRights\n");
684 r.in.handle = acct_handle;
686 r.out.rights = &rights;
688 status = dcerpc_lsa_EnumAccountRights(p, mem_ctx, &r);
689 if (!NT_STATUS_IS_OK(status)) {
690 printf("EnumAccountRights failed - %s\n", nt_errstr(status));
698 static BOOL test_QuerySecurity(struct dcerpc_pipe *p,
700 struct policy_handle *handle,
701 struct policy_handle *acct_handle)
704 struct lsa_QuerySecurity r;
706 printf("Testing QuerySecurity\n");
708 r.in.handle = acct_handle;
711 status = dcerpc_lsa_QuerySecurity(p, mem_ctx, &r);
712 if (!NT_STATUS_IS_OK(status)) {
713 printf("QuerySecurity failed - %s\n", nt_errstr(status));
720 static BOOL test_OpenAccount(struct dcerpc_pipe *p,
722 struct policy_handle *handle,
726 struct lsa_OpenAccount r;
727 struct policy_handle acct_handle;
729 printf("Testing OpenAccount\n");
731 r.in.handle = handle;
733 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
734 r.out.acct_handle = &acct_handle;
736 status = dcerpc_lsa_OpenAccount(p, mem_ctx, &r);
737 if (!NT_STATUS_IS_OK(status)) {
738 printf("OpenAccount failed - %s\n", nt_errstr(status));
742 if (!test_EnumPrivsAccount(p, mem_ctx, handle, &acct_handle)) {
746 if (!test_QuerySecurity(p, mem_ctx, handle, &acct_handle)) {
753 static BOOL test_EnumAccounts(struct dcerpc_pipe *p,
755 struct policy_handle *handle)
758 struct lsa_EnumAccounts r;
759 struct lsa_SidArray sids1, sids2;
760 uint32_t resume_handle = 0;
763 printf("\ntesting EnumAccounts\n");
765 r.in.handle = handle;
766 r.in.resume_handle = &resume_handle;
767 r.in.num_entries = 100;
768 r.out.resume_handle = &resume_handle;
773 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
774 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
777 if (!NT_STATUS_IS_OK(status)) {
778 printf("EnumAccounts failed - %s\n", nt_errstr(status));
782 if (!test_LookupSids(p, mem_ctx, handle, &sids1)) {
786 if (!test_LookupSids2(p, mem_ctx, handle, &sids1)) {
790 printf("testing all accounts\n");
791 for (i=0;i<sids1.num_sids;i++) {
792 test_OpenAccount(p, mem_ctx, handle, sids1.sids[i].sid);
793 test_EnumAccountRights(p, mem_ctx, handle, sids1.sids[i].sid);
798 if (sids1.num_sids < 3) {
802 printf("trying EnumAccounts partial listing (asking for 1 at 2)\n");
804 r.in.num_entries = 1;
807 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
808 if (!NT_STATUS_IS_OK(status)) {
809 printf("EnumAccounts failed - %s\n", nt_errstr(status));
813 if (sids2.num_sids != 1) {
814 printf("Returned wrong number of entries (%d)\n", sids2.num_sids);
821 static BOOL test_LookupPrivDisplayName(struct dcerpc_pipe *p,
823 struct policy_handle *handle,
824 struct lsa_String *priv_name)
826 struct lsa_LookupPrivDisplayName r;
828 /* produce a reasonable range of language output without screwing up
830 uint16 language_id = (random() % 4) + 0x409;
832 printf("testing LookupPrivDisplayName(%s)\n", priv_name->string);
834 r.in.handle = handle;
835 r.in.name = priv_name;
836 r.in.language_id = &language_id;
837 r.out.language_id = &language_id;
840 status = dcerpc_lsa_LookupPrivDisplayName(p, mem_ctx, &r);
841 if (!NT_STATUS_IS_OK(status)) {
842 printf("LookupPrivDisplayName failed - %s\n", nt_errstr(status));
845 printf("%s -> \"%s\" (language 0x%x/0x%x)\n",
846 priv_name->string, r.out.disp_name->string,
847 *r.in.language_id, *r.out.language_id);
852 static BOOL test_EnumAccountsWithUserRight(struct dcerpc_pipe *p,
854 struct policy_handle *handle,
855 struct lsa_String *priv_name)
857 struct lsa_EnumAccountsWithUserRight r;
858 struct lsa_SidArray sids;
863 printf("testing EnumAccountsWithUserRight(%s)\n", priv_name->string);
865 r.in.handle = handle;
866 r.in.name = priv_name;
869 status = dcerpc_lsa_EnumAccountsWithUserRight(p, mem_ctx, &r);
871 /* NT_STATUS_NO_MORE_ENTRIES means noone has this privilege */
872 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
876 if (!NT_STATUS_IS_OK(status)) {
877 printf("EnumAccountsWithUserRight failed - %s\n", nt_errstr(status));
885 static BOOL test_EnumPrivs(struct dcerpc_pipe *p,
887 struct policy_handle *handle)
890 struct lsa_EnumPrivs r;
891 struct lsa_PrivArray privs1;
892 uint32_t resume_handle = 0;
896 printf("\ntesting EnumPrivs\n");
898 r.in.handle = handle;
899 r.in.resume_handle = &resume_handle;
900 r.in.max_count = 100;
901 r.out.resume_handle = &resume_handle;
902 r.out.privs = &privs1;
905 status = dcerpc_lsa_EnumPrivs(p, mem_ctx, &r);
906 if (!NT_STATUS_IS_OK(status)) {
907 printf("EnumPrivs failed - %s\n", nt_errstr(status));
911 for (i = 0; i< privs1.count; i++) {
912 test_LookupPrivDisplayName(p, mem_ctx, handle, &privs1.privs[i].name);
913 test_LookupPrivValue(p, mem_ctx, handle, &privs1.privs[i].name);
914 if (!test_EnumAccountsWithUserRight(p, mem_ctx, handle, &privs1.privs[i].name)) {
923 static BOOL test_EnumTrustDom(struct dcerpc_pipe *p,
925 struct policy_handle *handle)
927 struct lsa_EnumTrustDom r;
929 uint32_t resume_handle = 0;
930 struct lsa_DomainList domains;
934 printf("\nTesting EnumTrustDom\n");
936 r.in.handle = handle;
937 r.in.resume_handle = &resume_handle;
938 r.in.num_entries = 100;
939 r.out.domains = &domains;
940 r.out.resume_handle = &resume_handle;
942 status = dcerpc_lsa_EnumTrustDom(p, mem_ctx, &r);
944 /* NO_MORE_ENTRIES is allowed */
945 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
949 if (!NT_STATUS_IS_OK(status)) {
950 printf("EnumTrustDom failed - %s\n", nt_errstr(status));
954 printf("\nTesting OpenTrustedDomain, OpenTrustedDomainByName and QueryInfoTrustedDomain\n");
956 for (i=0; i< domains.count; i++) {
957 struct lsa_OpenTrustedDomain trust;
958 struct lsa_OpenTrustedDomainByName trust_by_name;
959 struct policy_handle trustdom_handle;
960 struct policy_handle handle2;
962 int levels [] = {1, 3, 6, 8, 12};
964 trust.in.handle = handle;
965 trust.in.sid = domains.domains[i].sid;
966 trust.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
967 trust.out.trustdom_handle = &trustdom_handle;
969 status = dcerpc_lsa_OpenTrustedDomain(p, mem_ctx, &trust);
971 if (!NT_STATUS_IS_OK(status)) {
972 printf("OpenTrustedDomain failed - %s\n", nt_errstr(status));
976 c.in.handle = &trustdom_handle;
977 c.out.handle = &handle2;
979 for (j=0; j < ARRAY_SIZE(levels); j++) {
980 struct lsa_QueryTrustedDomainInfo q;
981 union lsa_TrustedDomainInfo info;
982 q.in.trustdom_handle = &trustdom_handle;
983 q.in.level = levels[j];
985 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
986 if (!NT_STATUS_IS_OK(status)) {
987 printf("QueryTrustedDomainInfo level %d failed - %s\n",
988 levels[j], nt_errstr(status));
993 status = dcerpc_lsa_Close(p, mem_ctx, &c);
994 if (!NT_STATUS_IS_OK(status)) {
995 printf("Close of trusted domain failed - %s\n", nt_errstr(status));
999 trust_by_name.in.handle = handle;
1000 trust_by_name.in.name = domains.domains[i].name;
1001 trust_by_name.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1002 trust_by_name.out.trustdom_handle = &trustdom_handle;
1004 status = dcerpc_lsa_OpenTrustedDomainByName(p, mem_ctx, &trust_by_name);
1006 if (!NT_STATUS_IS_OK(status)) {
1007 printf("OpenTrustedDomainByName failed - %s\n", nt_errstr(status));
1011 for (j=0; j < ARRAY_SIZE(levels); j++) {
1012 struct lsa_QueryTrustedDomainInfo q;
1013 union lsa_TrustedDomainInfo info;
1014 q.in.trustdom_handle = &trustdom_handle;
1015 q.in.level = levels[j];
1017 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
1018 if (!NT_STATUS_IS_OK(status)) {
1019 printf("QueryTrustedDomainInfo level %d failed - %s\n",
1020 levels[j], nt_errstr(status));
1025 c.in.handle = &trustdom_handle;
1026 c.out.handle = &handle2;
1028 status = dcerpc_lsa_Close(p, mem_ctx, &c);
1029 if (!NT_STATUS_IS_OK(status)) {
1030 printf("Close of trusted domain failed - %s\n", nt_errstr(status));
1034 for (j=0; j < ARRAY_SIZE(levels); j++) {
1035 struct lsa_QueryTrustedDomainInfoBySid q;
1036 union lsa_TrustedDomainInfo info;
1037 q.in.handle = handle;
1038 q.in.dom_sid = domains.domains[i].sid;
1039 q.in.level = levels[j];
1041 status = dcerpc_lsa_QueryTrustedDomainInfoBySid(p, mem_ctx, &q);
1042 if (!NT_STATUS_IS_OK(status)) {
1043 printf("QueryTrustedDomainInfoBySid level %d failed - %s\n",
1044 levels[j], nt_errstr(status));
1049 for (j=0; j < ARRAY_SIZE(levels); j++) {
1050 struct lsa_QueryTrustedDomainInfoByName q;
1051 union lsa_TrustedDomainInfo info;
1052 q.in.handle = handle;
1053 q.in.trusted_domain = domains.domains[i].name;
1054 q.in.level = levels[j];
1056 status = dcerpc_lsa_QueryTrustedDomainInfoByName(p, mem_ctx, &q);
1057 if (!NT_STATUS_IS_OK(status)) {
1058 printf("QueryTrustedDomainInfoByName level %d failed - %s\n",
1059 levels[j], nt_errstr(status));
1071 static BOOL test_QueryInfoPolicy(struct dcerpc_pipe *p,
1072 TALLOC_CTX *mem_ctx,
1073 struct policy_handle *handle)
1075 struct lsa_QueryInfoPolicy r;
1079 printf("\nTesting QueryInfoPolicy\n");
1081 for (i=1;i<13;i++) {
1082 r.in.handle = handle;
1085 printf("\ntrying QueryInfoPolicy level %d\n", i);
1087 status = dcerpc_lsa_QueryInfoPolicy(p, mem_ctx, &r);
1089 if ((i == 9 || i == 10 || i == 11) &&
1090 NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
1091 printf("server failed level %u (OK)\n", i);
1095 if (!NT_STATUS_IS_OK(status)) {
1096 printf("QueryInfoPolicy failed - %s\n", nt_errstr(status));
1105 static BOOL test_QueryInfoPolicy2(struct dcerpc_pipe *p,
1106 TALLOC_CTX *mem_ctx,
1107 struct policy_handle *handle)
1109 struct lsa_QueryInfoPolicy2 r;
1113 printf("\nTesting QueryInfoPolicy2\n");
1115 for (i=1;i<13;i++) {
1116 r.in.handle = handle;
1119 printf("\ntrying QueryInfoPolicy2 level %d\n", i);
1121 status = dcerpc_lsa_QueryInfoPolicy2(p, mem_ctx, &r);
1123 if ((i == 9 || i == 10 || i == 11) &&
1124 NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
1125 printf("server failed level %u (OK)\n", i);
1129 if (!NT_STATUS_IS_OK(status)) {
1130 printf("QueryInfoPolicy2 failed - %s\n", nt_errstr(status));
1139 static BOOL test_Close(struct dcerpc_pipe *p,
1140 TALLOC_CTX *mem_ctx,
1141 struct policy_handle *handle)
1145 struct policy_handle handle2;
1147 printf("\ntesting Close\n");
1149 r.in.handle = handle;
1150 r.out.handle = &handle2;
1152 status = dcerpc_lsa_Close(p, mem_ctx, &r);
1153 if (!NT_STATUS_IS_OK(status)) {
1154 printf("Close failed - %s\n", nt_errstr(status));
1158 status = dcerpc_lsa_Close(p, mem_ctx, &r);
1159 /* its really a fault - we need a status code for rpc fault */
1160 if (!NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
1161 printf("Close failed - %s\n", nt_errstr(status));
1170 BOOL torture_rpc_lsa(void)
1173 struct dcerpc_pipe *p;
1174 TALLOC_CTX *mem_ctx;
1176 struct policy_handle handle;
1178 mem_ctx = talloc_init("torture_rpc_lsa");
1180 status = torture_rpc_connection(&p,
1183 DCERPC_LSARPC_VERSION);
1184 if (!NT_STATUS_IS_OK(status)) {
1188 if (!test_OpenPolicy(p, mem_ctx)) {
1192 if (!test_OpenPolicy2(p, mem_ctx, &handle)) {
1196 if (!test_many_LookupSids(p, mem_ctx, &handle)) {
1200 if (!test_CreateAccount(p, mem_ctx, &handle)) {
1204 if (!test_CreateSecret(p, mem_ctx, &handle)) {
1208 if (!test_CreateTrustedDomain(p, mem_ctx, &handle)) {
1212 if (!test_EnumAccounts(p, mem_ctx, &handle)) {
1216 if (!test_EnumPrivs(p, mem_ctx, &handle)) {
1220 if (!test_EnumTrustDom(p, mem_ctx, &handle)) {
1224 if (!test_QueryInfoPolicy(p, mem_ctx, &handle)) {
1228 if (!test_QueryInfoPolicy2(p, mem_ctx, &handle)) {
1233 if (!test_Delete(p, mem_ctx, &handle)) {
1238 if (!test_Close(p, mem_ctx, &handle)) {
1242 talloc_destroy(mem_ctx);
1244 torture_rpc_close(p);