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");
286 sids.num_sids = 1000;
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_LookupPrivName(struct dcerpc_pipe *p,
322 struct policy_handle *handle,
323 struct lsa_LUID *luid)
326 struct lsa_LookupPrivName r;
328 r.in.handle = handle;
331 status = dcerpc_lsa_LookupPrivName(p, mem_ctx, &r);
332 if (!NT_STATUS_IS_OK(status)) {
333 printf("\nLookupPrivName failed - %s\n", nt_errstr(status));
340 static BOOL test_EnumPrivsAccount(struct dcerpc_pipe *p,
342 struct policy_handle *handle,
343 struct policy_handle *acct_handle)
346 struct lsa_EnumPrivsAccount r;
348 printf("Testing EnumPrivsAccount\n");
350 r.in.handle = acct_handle;
352 status = dcerpc_lsa_EnumPrivsAccount(p, mem_ctx, &r);
353 if (!NT_STATUS_IS_OK(status)) {
354 printf("EnumPrivsAccount failed - %s\n", nt_errstr(status));
360 for (i=0;i<r.out.privs->count;i++) {
361 test_LookupPrivName(p, mem_ctx, handle,
362 &r.out.privs->set[i].luid);
369 static BOOL test_Delete(struct dcerpc_pipe *p,
371 struct policy_handle *handle)
376 printf("\ntesting Delete\n");
378 r.in.handle = handle;
379 status = dcerpc_lsa_Delete(p, mem_ctx, &r);
380 if (!NT_STATUS_IS_OK(status)) {
381 printf("Delete failed - %s\n", nt_errstr(status));
391 static BOOL test_CreateAccount(struct dcerpc_pipe *p,
393 struct policy_handle *handle)
396 struct lsa_CreateAccount r;
397 struct dom_sid2 *newsid;
398 struct policy_handle acct_handle;
400 newsid = dom_sid_parse_talloc(mem_ctx, "S-1-5-12349876-4321-2854");
402 printf("Testing CreateAccount\n");
404 r.in.handle = handle;
406 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
407 r.out.acct_handle = &acct_handle;
409 status = dcerpc_lsa_CreateAccount(p, mem_ctx, &r);
410 if (!NT_STATUS_IS_OK(status)) {
411 printf("CreateAccount failed - %s\n", nt_errstr(status));
415 if (!test_Delete(p, mem_ctx, &acct_handle)) {
423 static BOOL test_CreateTrustedDomain(struct dcerpc_pipe *p,
425 struct policy_handle *handle)
428 struct lsa_CreateTrustedDomain r;
429 struct lsa_TrustInformation trustinfo;
430 struct dom_sid *domsid;
431 struct policy_handle dom_handle;
433 printf("Testing CreateTrustedDomain\n");
435 domsid = dom_sid_parse_talloc(mem_ctx, "S-1-5-21-97398-379795-12345");
437 trustinfo.sid = domsid;
438 init_lsa_String(&trustinfo.name, "torturedomain");
440 r.in.handle = handle;
441 r.in.info = &trustinfo;
442 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
443 r.out.dom_handle = &dom_handle;
445 status = dcerpc_lsa_CreateTrustedDomain(p, mem_ctx, &r);
446 if (!NT_STATUS_IS_OK(status)) {
447 printf("CreateTrustedDomain failed - %s\n", nt_errstr(status));
451 if (!test_Delete(p, mem_ctx, &dom_handle)) {
458 static BOOL test_CreateSecret(struct dcerpc_pipe *p,
460 struct policy_handle *handle)
463 struct lsa_CreateSecret r;
464 struct lsa_OpenSecret r2;
465 struct lsa_SetSecret r3;
466 struct lsa_QuerySecret r4;
467 struct policy_handle sec_handle, sec_handle2;
469 struct lsa_DATA_BUF buf1;
470 struct lsa_DATA_BUF_PTR bufp1;
473 DATA_BLOB session_key;
474 NTTIME old_mtime, new_mtime;
475 DATA_BLOB blob1, blob2;
476 const char *secret1 = "abcdef12345699qwerty";
480 printf("Testing CreateSecret\n");
482 asprintf(&secname, "torturesecret-%u", (uint_t)random());
484 init_lsa_String(&r.in.name, secname);
486 r.in.handle = handle;
487 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
488 r.out.sec_handle = &sec_handle;
490 status = dcerpc_lsa_CreateSecret(p, mem_ctx, &r);
491 if (!NT_STATUS_IS_OK(status)) {
492 printf("CreateSecret failed - %s\n", nt_errstr(status));
496 r2.in.handle = handle;
497 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
498 r2.in.name = r.in.name;
499 r2.out.sec_handle = &sec_handle2;
501 printf("Testing OpenSecret\n");
503 status = dcerpc_lsa_OpenSecret(p, mem_ctx, &r2);
504 if (!NT_STATUS_IS_OK(status)) {
505 printf("OpenSecret failed - %s\n", nt_errstr(status));
509 status = dcerpc_fetch_session_key(p, &session_key);
510 if (!NT_STATUS_IS_OK(status)) {
511 printf("dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
515 enc_key = sess_encrypt_string(secret1, &session_key);
517 r3.in.handle = &sec_handle;
518 r3.in.new_val = &buf1;
519 r3.in.old_val = NULL;
520 r3.in.new_val->data = enc_key.data;
521 r3.in.new_val->length = enc_key.length;
522 r3.in.new_val->size = enc_key.length;
524 printf("Testing SetSecret\n");
526 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r3);
527 if (!NT_STATUS_IS_OK(status)) {
528 printf("SetSecret failed - %s\n", nt_errstr(status));
532 data_blob_free(&enc_key);
534 ZERO_STRUCT(new_mtime);
535 ZERO_STRUCT(old_mtime);
537 /* fetch the secret back again */
538 r4.in.handle = &sec_handle;
539 r4.in.new_val = &bufp1;
540 r4.in.new_mtime = &new_mtime;
541 r4.in.old_val = NULL;
542 r4.in.old_mtime = NULL;
546 status = dcerpc_lsa_QuerySecret(p, mem_ctx, &r4);
547 if (!NT_STATUS_IS_OK(status)) {
548 printf("QuerySecret failed - %s\n", nt_errstr(status));
552 if (r4.out.new_val->buf == NULL) {
553 printf("No secret buffer returned\n");
556 blob1.data = r4.out.new_val->buf->data;
557 blob1.length = r4.out.new_val->buf->length;
559 blob2 = data_blob(NULL, blob1.length);
561 secret2 = sess_decrypt_string(&blob1, &session_key);
563 printf("returned secret '%s'\n", secret2);
565 if (strcmp(secret1, secret2) != 0) {
566 printf("Returned secret doesn't match\n");
571 if (!test_Delete(p, mem_ctx, &sec_handle)) {
575 d.in.handle = &sec_handle2;
576 status = dcerpc_lsa_Delete(p, mem_ctx, &d);
577 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
578 printf("Second delete expected INVALID_HANDLE - %s\n", nt_errstr(status));
586 static BOOL test_EnumAccountRights(struct dcerpc_pipe *p,
588 struct policy_handle *acct_handle,
592 struct lsa_EnumAccountRights r;
593 struct lsa_RightSet rights;
595 printf("Testing EnumAccountRights\n");
597 r.in.handle = acct_handle;
599 r.out.rights = &rights;
601 status = dcerpc_lsa_EnumAccountRights(p, mem_ctx, &r);
602 if (!NT_STATUS_IS_OK(status)) {
603 printf("EnumAccountRights failed - %s\n", nt_errstr(status));
611 static BOOL test_QuerySecurity(struct dcerpc_pipe *p,
613 struct policy_handle *handle,
614 struct policy_handle *acct_handle)
617 struct lsa_QuerySecurity r;
619 printf("Testing QuerySecuriy\n");
621 r.in.handle = acct_handle;
624 status = dcerpc_lsa_QuerySecurity(p, mem_ctx, &r);
625 if (!NT_STATUS_IS_OK(status)) {
626 printf("QuerySecurity failed - %s\n", nt_errstr(status));
633 static BOOL test_OpenAccount(struct dcerpc_pipe *p,
635 struct policy_handle *handle,
639 struct lsa_OpenAccount r;
640 struct policy_handle acct_handle;
642 printf("Testing OpenAccount\n");
644 r.in.handle = handle;
646 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
647 r.out.acct_handle = &acct_handle;
649 status = dcerpc_lsa_OpenAccount(p, mem_ctx, &r);
650 if (!NT_STATUS_IS_OK(status)) {
651 printf("OpenAccount failed - %s\n", nt_errstr(status));
655 if (!test_EnumPrivsAccount(p, mem_ctx, handle, &acct_handle)) {
659 if (!test_QuerySecurity(p, mem_ctx, handle, &acct_handle)) {
666 static BOOL test_EnumAccounts(struct dcerpc_pipe *p,
668 struct policy_handle *handle)
671 struct lsa_EnumAccounts r;
672 struct lsa_SidArray sids1, sids2;
673 uint32_t resume_handle = 0;
676 printf("\ntesting EnumAccounts\n");
678 r.in.handle = handle;
679 r.in.resume_handle = &resume_handle;
680 r.in.num_entries = 100;
681 r.out.resume_handle = &resume_handle;
685 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
686 if (!NT_STATUS_IS_OK(status)) {
687 printf("EnumAccounts failed - %s\n", nt_errstr(status));
691 if (!test_LookupSids(p, mem_ctx, handle, &sids1)) {
695 if (!test_LookupSids2(p, mem_ctx, handle, &sids1)) {
699 printf("testing all accounts\n");
700 for (i=0;i<sids1.num_sids;i++) {
701 test_OpenAccount(p, mem_ctx, handle, sids1.sids[i].sid);
702 test_EnumAccountRights(p, mem_ctx, handle, sids1.sids[i].sid);
706 if (sids1.num_sids < 3) {
710 printf("trying EnumAccounts partial listing (asking for 1 at 2)\n");
712 r.in.num_entries = 1;
715 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
716 if (!NT_STATUS_IS_OK(status)) {
717 printf("EnumAccounts failed - %s\n", nt_errstr(status));
721 if (sids2.num_sids != 1) {
722 printf("Returned wrong number of entries (%d)\n", sids2.num_sids);
729 static BOOL test_LookupPrivDisplayName(struct dcerpc_pipe *p,
731 struct policy_handle *handle,
732 struct lsa_String *priv_name)
734 struct lsa_LookupPrivDisplayName r;
736 /* produce a reasonable range of language output without screwing up
738 uint16 language_id = (random() % 4) + 0x409;
740 printf("testing LookupPrivDisplayName(%s)\n", priv_name->string);
742 r.in.handle = handle;
743 r.in.name = priv_name;
744 r.in.language_id = &language_id;
745 r.out.language_id = &language_id;
748 status = dcerpc_lsa_LookupPrivDisplayName(p, mem_ctx, &r);
749 if (!NT_STATUS_IS_OK(status)) {
750 printf("LookupPrivDisplayName failed - %s\n", nt_errstr(status));
753 printf("%s -> \"%s\" (language 0x%x/0x%x)\n",
754 priv_name->string, r.out.disp_name->string,
755 *r.in.language_id, *r.out.language_id);
760 static BOOL test_EnumAccountsWithUserRight(struct dcerpc_pipe *p,
762 struct policy_handle *handle,
763 struct lsa_String *priv_name)
765 struct lsa_EnumAccountsWithUserRight r;
766 struct lsa_SidArray sids;
771 printf("testing EnumAccountsWithUserRight(%s)\n", priv_name->string);
773 r.in.handle = handle;
774 r.in.name = priv_name;
777 status = dcerpc_lsa_EnumAccountsWithUserRight(p, mem_ctx, &r);
779 /* NT_STATUS_NO_MORE_ENTRIES means noone has this privilege */
780 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
784 if (!NT_STATUS_IS_OK(status)) {
785 printf("EnumAccountsWithUserRight failed - %s\n", nt_errstr(status));
793 static BOOL test_EnumPrivs(struct dcerpc_pipe *p,
795 struct policy_handle *handle)
798 struct lsa_EnumPrivs r;
799 struct lsa_PrivArray privs1;
800 uint32_t resume_handle = 0;
804 printf("\ntesting EnumPrivs\n");
806 r.in.handle = handle;
807 r.in.resume_handle = &resume_handle;
808 r.in.max_count = 1000;
809 r.out.resume_handle = &resume_handle;
810 r.out.privs = &privs1;
813 status = dcerpc_lsa_EnumPrivs(p, mem_ctx, &r);
814 if (!NT_STATUS_IS_OK(status)) {
815 printf("EnumPrivs failed - %s\n", nt_errstr(status));
819 for (i = 0; i< privs1.count; i++) {
820 test_LookupPrivDisplayName(p, mem_ctx, handle, &privs1.privs[i].name);
821 if (!test_EnumAccountsWithUserRight(p, mem_ctx, handle, &privs1.privs[i].name)) {
830 static BOOL test_EnumTrustDom(struct dcerpc_pipe *p,
832 struct policy_handle *handle)
834 struct lsa_EnumTrustDom r;
836 uint32_t resume_handle = 0;
837 struct lsa_DomainList domains;
841 printf("\nTesting EnumTrustDom\n");
843 r.in.handle = handle;
844 r.in.resume_handle = &resume_handle;
845 r.in.num_entries = 1000;
846 r.out.domains = &domains;
847 r.out.resume_handle = &resume_handle;
849 status = dcerpc_lsa_EnumTrustDom(p, mem_ctx, &r);
851 /* NO_MORE_ENTRIES is allowed */
852 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
856 if (!NT_STATUS_IS_OK(status)) {
857 printf("EnumTrustDom failed - %s\n", nt_errstr(status));
861 printf("\nTesting OpenTrustedDomain, OpenTrustedDomainByName and QueryInfoTrustedDomain\n");
863 for (i=0; i< domains.count; i++) {
864 struct lsa_OpenTrustedDomain trust;
865 struct lsa_OpenTrustedDomainByName trust_by_name;
866 struct policy_handle trustdom_handle;
867 struct policy_handle handle2;
869 int levels [] = {1, 3, 6, 8, 12};
871 trust.in.handle = handle;
872 trust.in.sid = domains.domains[i].sid;
873 trust.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
874 trust.out.trustdom_handle = &trustdom_handle;
876 status = dcerpc_lsa_OpenTrustedDomain(p, mem_ctx, &trust);
878 if (!NT_STATUS_IS_OK(status)) {
879 printf("OpenTrustedDomain failed - %s\n", nt_errstr(status));
883 c.in.handle = &trustdom_handle;
884 c.out.handle = &handle2;
886 for (j=0; j < ARRAY_SIZE(levels); j++) {
887 struct lsa_QueryTrustedDomainInfo q;
888 union lsa_TrustedDomainInfo info;
889 q.in.trustdom_handle = &trustdom_handle;
890 q.in.level = levels[j];
892 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
893 if (!NT_STATUS_IS_OK(status)) {
894 printf("QueryTrustedDomainInfo level %d failed - %s\n",
895 levels[j], nt_errstr(status));
900 status = dcerpc_lsa_Close(p, mem_ctx, &c);
901 if (!NT_STATUS_IS_OK(status)) {
902 printf("Close of trusted domain failed - %s\n", nt_errstr(status));
906 trust_by_name.in.handle = handle;
907 trust_by_name.in.name = domains.domains[i].name;
908 trust_by_name.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
909 trust_by_name.out.trustdom_handle = &trustdom_handle;
911 status = dcerpc_lsa_OpenTrustedDomainByName(p, mem_ctx, &trust_by_name);
913 if (!NT_STATUS_IS_OK(status)) {
914 printf("OpenTrustedDomainByName failed - %s\n", nt_errstr(status));
918 for (j=0; j < ARRAY_SIZE(levels); j++) {
919 struct lsa_QueryTrustedDomainInfo q;
920 union lsa_TrustedDomainInfo info;
921 q.in.trustdom_handle = &trustdom_handle;
922 q.in.level = levels[j];
924 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
925 if (!NT_STATUS_IS_OK(status)) {
926 printf("QueryTrustedDomainInfo level %d failed - %s\n",
927 levels[j], nt_errstr(status));
932 c.in.handle = &trustdom_handle;
933 c.out.handle = &handle2;
935 status = dcerpc_lsa_Close(p, mem_ctx, &c);
936 if (!NT_STATUS_IS_OK(status)) {
937 printf("Close of trusted domain failed - %s\n", nt_errstr(status));
941 for (j=0; j < ARRAY_SIZE(levels); j++) {
942 struct lsa_QueryTrustedDomainInfoBySid q;
943 union lsa_TrustedDomainInfo info;
944 q.in.handle = handle;
945 q.in.dom_sid = domains.domains[i].sid;
946 q.in.level = levels[j];
948 status = dcerpc_lsa_QueryTrustedDomainInfoBySid(p, mem_ctx, &q);
949 if (!NT_STATUS_IS_OK(status)) {
950 printf("QueryTrustedDomainInfoBySid level %d failed - %s\n",
951 levels[j], nt_errstr(status));
956 for (j=0; j < ARRAY_SIZE(levels); j++) {
957 struct lsa_QueryTrustedDomainInfoByName q;
958 union lsa_TrustedDomainInfo info;
959 q.in.handle = handle;
960 q.in.trusted_domain = domains.domains[i].name;
961 q.in.level = levels[j];
963 status = dcerpc_lsa_QueryTrustedDomainInfoByName(p, mem_ctx, &q);
964 if (!NT_STATUS_IS_OK(status)) {
965 printf("QueryTrustedDomainInfoByName level %d failed - %s\n",
966 levels[j], nt_errstr(status));
978 static BOOL test_QueryInfoPolicy(struct dcerpc_pipe *p,
980 struct policy_handle *handle)
982 struct lsa_QueryInfoPolicy r;
986 printf("\nTesting QueryInfoPolicy\n");
989 r.in.handle = handle;
992 printf("\ntrying QueryInfoPolicy level %d\n", i);
994 status = dcerpc_lsa_QueryInfoPolicy(p, mem_ctx, &r);
996 if ((i == 9 || i == 10 || i == 11) &&
997 NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
998 printf("server failed level %u (OK)\n", i);
1002 if (!NT_STATUS_IS_OK(status)) {
1003 printf("QueryInfoPolicy failed - %s\n", nt_errstr(status));
1012 static BOOL test_QueryInfoPolicy2(struct dcerpc_pipe *p,
1013 TALLOC_CTX *mem_ctx,
1014 struct policy_handle *handle)
1016 struct lsa_QueryInfoPolicy2 r;
1020 printf("\nTesting QueryInfoPolicy2\n");
1022 for (i=1;i<13;i++) {
1023 r.in.handle = handle;
1026 printf("\ntrying QueryInfoPolicy2 level %d\n", i);
1028 status = dcerpc_lsa_QueryInfoPolicy2(p, mem_ctx, &r);
1030 if ((i == 9 || i == 10 || i == 11) &&
1031 NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
1032 printf("server failed level %u (OK)\n", i);
1036 if (!NT_STATUS_IS_OK(status)) {
1037 printf("QueryInfoPolicy2 failed - %s\n", nt_errstr(status));
1046 static BOOL test_Close(struct dcerpc_pipe *p,
1047 TALLOC_CTX *mem_ctx,
1048 struct policy_handle *handle)
1052 struct policy_handle handle2;
1054 printf("\ntesting Close\n");
1056 r.in.handle = handle;
1057 r.out.handle = &handle2;
1059 status = dcerpc_lsa_Close(p, mem_ctx, &r);
1060 if (!NT_STATUS_IS_OK(status)) {
1061 printf("Close failed - %s\n", nt_errstr(status));
1065 status = dcerpc_lsa_Close(p, mem_ctx, &r);
1066 /* its really a fault - we need a status code for rpc fault */
1067 if (!NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
1068 printf("Close failed - %s\n", nt_errstr(status));
1077 BOOL torture_rpc_lsa(void)
1080 struct dcerpc_pipe *p;
1081 TALLOC_CTX *mem_ctx;
1083 struct policy_handle handle;
1085 mem_ctx = talloc_init("torture_rpc_lsa");
1087 status = torture_rpc_connection(&p,
1090 DCERPC_LSARPC_VERSION);
1091 if (!NT_STATUS_IS_OK(status)) {
1095 if (!test_OpenPolicy(p, mem_ctx)) {
1099 if (!test_OpenPolicy2(p, mem_ctx, &handle)) {
1103 if (!test_many_LookupSids(p, mem_ctx, &handle)) {
1107 if (!test_CreateAccount(p, mem_ctx, &handle)) {
1111 if (!test_CreateSecret(p, mem_ctx, &handle)) {
1115 if (!test_CreateTrustedDomain(p, mem_ctx, &handle)) {
1119 if (!test_EnumAccounts(p, mem_ctx, &handle)) {
1123 if (!test_EnumPrivs(p, mem_ctx, &handle)) {
1127 if (!test_EnumTrustDom(p, mem_ctx, &handle)) {
1131 if (!test_QueryInfoPolicy(p, mem_ctx, &handle)) {
1135 if (!test_QueryInfoPolicy2(p, mem_ctx, &handle)) {
1140 if (!test_Delete(p, mem_ctx, &handle)) {
1145 if (!test_Close(p, mem_ctx, &handle)) {
1149 talloc_destroy(mem_ctx);
1151 torture_rpc_close(p);