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_EnumPrivsAccount(struct dcerpc_pipe *p,
362 struct policy_handle *handle,
363 struct policy_handle *acct_handle)
366 struct lsa_EnumPrivsAccount r;
368 printf("Testing EnumPrivsAccount\n");
370 r.in.handle = acct_handle;
372 status = dcerpc_lsa_EnumPrivsAccount(p, mem_ctx, &r);
373 if (!NT_STATUS_IS_OK(status)) {
374 printf("EnumPrivsAccount failed - %s\n", nt_errstr(status));
380 for (i=0;i<r.out.privs->count;i++) {
381 test_LookupPrivName(p, mem_ctx, handle,
382 &r.out.privs->set[i].luid);
389 static BOOL test_Delete(struct dcerpc_pipe *p,
391 struct policy_handle *handle)
396 printf("\ntesting Delete\n");
398 r.in.handle = handle;
399 status = dcerpc_lsa_Delete(p, mem_ctx, &r);
400 if (!NT_STATUS_IS_OK(status)) {
401 printf("Delete failed - %s\n", nt_errstr(status));
411 static BOOL test_CreateAccount(struct dcerpc_pipe *p,
413 struct policy_handle *handle)
416 struct lsa_CreateAccount r;
417 struct dom_sid2 *newsid;
418 struct policy_handle acct_handle;
420 newsid = dom_sid_parse_talloc(mem_ctx, "S-1-5-12349876-4321-2854");
422 printf("Testing CreateAccount\n");
424 r.in.handle = handle;
426 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
427 r.out.acct_handle = &acct_handle;
429 status = dcerpc_lsa_CreateAccount(p, mem_ctx, &r);
430 if (!NT_STATUS_IS_OK(status)) {
431 printf("CreateAccount failed - %s\n", nt_errstr(status));
435 if (!test_Delete(p, mem_ctx, &acct_handle)) {
443 static BOOL test_CreateTrustedDomain(struct dcerpc_pipe *p,
445 struct policy_handle *handle)
448 struct lsa_CreateTrustedDomain r;
449 struct lsa_TrustInformation trustinfo;
450 struct dom_sid *domsid;
451 struct policy_handle dom_handle;
453 printf("Testing CreateTrustedDomain\n");
455 domsid = dom_sid_parse_talloc(mem_ctx, "S-1-5-21-97398-379795-12345");
457 trustinfo.sid = domsid;
458 init_lsa_String(&trustinfo.name, "torturedomain");
460 r.in.handle = handle;
461 r.in.info = &trustinfo;
462 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
463 r.out.dom_handle = &dom_handle;
465 status = dcerpc_lsa_CreateTrustedDomain(p, mem_ctx, &r);
466 if (!NT_STATUS_IS_OK(status)) {
467 printf("CreateTrustedDomain failed - %s\n", nt_errstr(status));
471 if (!test_Delete(p, mem_ctx, &dom_handle)) {
478 static BOOL test_CreateSecret(struct dcerpc_pipe *p,
480 struct policy_handle *handle)
483 struct lsa_CreateSecret r;
484 struct lsa_OpenSecret r2;
485 struct lsa_SetSecret r3;
486 struct lsa_QuerySecret r4;
487 struct policy_handle sec_handle, sec_handle2;
489 struct lsa_DATA_BUF buf1;
490 struct lsa_DATA_BUF_PTR bufp1;
493 DATA_BLOB session_key;
494 NTTIME old_mtime, new_mtime;
495 DATA_BLOB blob1, blob2;
496 const char *secret1 = "abcdef12345699qwerty";
500 printf("Testing CreateSecret\n");
502 asprintf(&secname, "torturesecret-%u", (uint_t)random());
504 init_lsa_String(&r.in.name, secname);
506 r.in.handle = handle;
507 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
508 r.out.sec_handle = &sec_handle;
510 status = dcerpc_lsa_CreateSecret(p, mem_ctx, &r);
511 if (!NT_STATUS_IS_OK(status)) {
512 printf("CreateSecret failed - %s\n", nt_errstr(status));
516 r2.in.handle = handle;
517 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
518 r2.in.name = r.in.name;
519 r2.out.sec_handle = &sec_handle2;
521 printf("Testing OpenSecret\n");
523 status = dcerpc_lsa_OpenSecret(p, mem_ctx, &r2);
524 if (!NT_STATUS_IS_OK(status)) {
525 printf("OpenSecret failed - %s\n", nt_errstr(status));
529 status = dcerpc_fetch_session_key(p, &session_key);
530 if (!NT_STATUS_IS_OK(status)) {
531 printf("dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
535 enc_key = sess_encrypt_string(secret1, &session_key);
537 r3.in.handle = &sec_handle;
538 r3.in.new_val = &buf1;
539 r3.in.old_val = NULL;
540 r3.in.new_val->data = enc_key.data;
541 r3.in.new_val->length = enc_key.length;
542 r3.in.new_val->size = enc_key.length;
544 printf("Testing SetSecret\n");
546 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r3);
547 if (!NT_STATUS_IS_OK(status)) {
548 printf("SetSecret failed - %s\n", nt_errstr(status));
552 data_blob_free(&enc_key);
554 ZERO_STRUCT(new_mtime);
555 ZERO_STRUCT(old_mtime);
557 /* fetch the secret back again */
558 r4.in.handle = &sec_handle;
559 r4.in.new_val = &bufp1;
560 r4.in.new_mtime = &new_mtime;
561 r4.in.old_val = NULL;
562 r4.in.old_mtime = NULL;
566 status = dcerpc_lsa_QuerySecret(p, mem_ctx, &r4);
567 if (!NT_STATUS_IS_OK(status)) {
568 printf("QuerySecret failed - %s\n", nt_errstr(status));
572 if (r4.out.new_val->buf == NULL) {
573 printf("No secret buffer returned\n");
576 blob1.data = r4.out.new_val->buf->data;
577 blob1.length = r4.out.new_val->buf->length;
579 blob2 = data_blob(NULL, blob1.length);
581 secret2 = sess_decrypt_string(&blob1, &session_key);
583 printf("returned secret '%s'\n", secret2);
585 if (strcmp(secret1, secret2) != 0) {
586 printf("Returned secret doesn't match\n");
591 if (!test_Delete(p, mem_ctx, &sec_handle)) {
595 d.in.handle = &sec_handle2;
596 status = dcerpc_lsa_Delete(p, mem_ctx, &d);
597 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
598 printf("Second delete expected INVALID_HANDLE - %s\n", nt_errstr(status));
606 static BOOL test_EnumAccountRights(struct dcerpc_pipe *p,
608 struct policy_handle *acct_handle,
612 struct lsa_EnumAccountRights r;
613 struct lsa_RightSet rights;
615 printf("Testing EnumAccountRights\n");
617 r.in.handle = acct_handle;
619 r.out.rights = &rights;
621 status = dcerpc_lsa_EnumAccountRights(p, mem_ctx, &r);
622 if (!NT_STATUS_IS_OK(status)) {
623 printf("EnumAccountRights failed - %s\n", nt_errstr(status));
631 static BOOL test_QuerySecurity(struct dcerpc_pipe *p,
633 struct policy_handle *handle,
634 struct policy_handle *acct_handle)
637 struct lsa_QuerySecurity r;
639 printf("Testing QuerySecuriy\n");
641 r.in.handle = acct_handle;
644 status = dcerpc_lsa_QuerySecurity(p, mem_ctx, &r);
645 if (!NT_STATUS_IS_OK(status)) {
646 printf("QuerySecurity failed - %s\n", nt_errstr(status));
653 static BOOL test_OpenAccount(struct dcerpc_pipe *p,
655 struct policy_handle *handle,
659 struct lsa_OpenAccount r;
660 struct policy_handle acct_handle;
662 printf("Testing OpenAccount\n");
664 r.in.handle = handle;
666 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
667 r.out.acct_handle = &acct_handle;
669 status = dcerpc_lsa_OpenAccount(p, mem_ctx, &r);
670 if (!NT_STATUS_IS_OK(status)) {
671 printf("OpenAccount failed - %s\n", nt_errstr(status));
675 if (!test_EnumPrivsAccount(p, mem_ctx, handle, &acct_handle)) {
679 if (!test_QuerySecurity(p, mem_ctx, handle, &acct_handle)) {
686 static BOOL test_EnumAccounts(struct dcerpc_pipe *p,
688 struct policy_handle *handle)
691 struct lsa_EnumAccounts r;
692 struct lsa_SidArray sids1, sids2;
693 uint32_t resume_handle = 0;
696 printf("\ntesting EnumAccounts\n");
698 r.in.handle = handle;
699 r.in.resume_handle = &resume_handle;
700 r.in.num_entries = 100;
701 r.out.resume_handle = &resume_handle;
705 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
706 if (!NT_STATUS_IS_OK(status)) {
707 printf("EnumAccounts failed - %s\n", nt_errstr(status));
711 if (!test_LookupSids(p, mem_ctx, handle, &sids1)) {
715 if (!test_LookupSids2(p, mem_ctx, handle, &sids1)) {
719 printf("testing all accounts\n");
720 for (i=0;i<sids1.num_sids;i++) {
721 test_OpenAccount(p, mem_ctx, handle, sids1.sids[i].sid);
722 test_EnumAccountRights(p, mem_ctx, handle, sids1.sids[i].sid);
726 if (sids1.num_sids < 3) {
730 printf("trying EnumAccounts partial listing (asking for 1 at 2)\n");
732 r.in.num_entries = 1;
735 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
736 if (!NT_STATUS_IS_OK(status)) {
737 printf("EnumAccounts failed - %s\n", nt_errstr(status));
741 if (sids2.num_sids != 1) {
742 printf("Returned wrong number of entries (%d)\n", sids2.num_sids);
749 static BOOL test_LookupPrivDisplayName(struct dcerpc_pipe *p,
751 struct policy_handle *handle,
752 struct lsa_String *priv_name)
754 struct lsa_LookupPrivDisplayName r;
756 /* produce a reasonable range of language output without screwing up
758 uint16 language_id = (random() % 4) + 0x409;
760 printf("testing LookupPrivDisplayName(%s)\n", priv_name->string);
762 r.in.handle = handle;
763 r.in.name = priv_name;
764 r.in.language_id = &language_id;
765 r.out.language_id = &language_id;
768 status = dcerpc_lsa_LookupPrivDisplayName(p, mem_ctx, &r);
769 if (!NT_STATUS_IS_OK(status)) {
770 printf("LookupPrivDisplayName failed - %s\n", nt_errstr(status));
773 printf("%s -> \"%s\" (language 0x%x/0x%x)\n",
774 priv_name->string, r.out.disp_name->string,
775 *r.in.language_id, *r.out.language_id);
780 static BOOL test_EnumAccountsWithUserRight(struct dcerpc_pipe *p,
782 struct policy_handle *handle,
783 struct lsa_String *priv_name)
785 struct lsa_EnumAccountsWithUserRight r;
786 struct lsa_SidArray sids;
791 printf("testing EnumAccountsWithUserRight(%s)\n", priv_name->string);
793 r.in.handle = handle;
794 r.in.name = priv_name;
797 status = dcerpc_lsa_EnumAccountsWithUserRight(p, mem_ctx, &r);
799 /* NT_STATUS_NO_MORE_ENTRIES means noone has this privilege */
800 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
804 if (!NT_STATUS_IS_OK(status)) {
805 printf("EnumAccountsWithUserRight failed - %s\n", nt_errstr(status));
813 static BOOL test_EnumPrivs(struct dcerpc_pipe *p,
815 struct policy_handle *handle)
818 struct lsa_EnumPrivs r;
819 struct lsa_PrivArray privs1;
820 uint32_t resume_handle = 0;
824 printf("\ntesting EnumPrivs\n");
826 r.in.handle = handle;
827 r.in.resume_handle = &resume_handle;
828 r.in.max_count = 100;
829 r.out.resume_handle = &resume_handle;
830 r.out.privs = &privs1;
833 status = dcerpc_lsa_EnumPrivs(p, mem_ctx, &r);
834 if (!NT_STATUS_IS_OK(status)) {
835 printf("EnumPrivs failed - %s\n", nt_errstr(status));
839 for (i = 0; i< privs1.count; i++) {
840 test_LookupPrivDisplayName(p, mem_ctx, handle, &privs1.privs[i].name);
841 test_LookupPrivValue(p, mem_ctx, handle, &privs1.privs[i].name);
842 if (!test_EnumAccountsWithUserRight(p, mem_ctx, handle, &privs1.privs[i].name)) {
851 static BOOL test_EnumTrustDom(struct dcerpc_pipe *p,
853 struct policy_handle *handle)
855 struct lsa_EnumTrustDom r;
857 uint32_t resume_handle = 0;
858 struct lsa_DomainList domains;
862 printf("\nTesting EnumTrustDom\n");
864 r.in.handle = handle;
865 r.in.resume_handle = &resume_handle;
866 r.in.num_entries = 100;
867 r.out.domains = &domains;
868 r.out.resume_handle = &resume_handle;
870 status = dcerpc_lsa_EnumTrustDom(p, mem_ctx, &r);
872 /* NO_MORE_ENTRIES is allowed */
873 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
877 if (!NT_STATUS_IS_OK(status)) {
878 printf("EnumTrustDom failed - %s\n", nt_errstr(status));
882 printf("\nTesting OpenTrustedDomain, OpenTrustedDomainByName and QueryInfoTrustedDomain\n");
884 for (i=0; i< domains.count; i++) {
885 struct lsa_OpenTrustedDomain trust;
886 struct lsa_OpenTrustedDomainByName trust_by_name;
887 struct policy_handle trustdom_handle;
888 struct policy_handle handle2;
890 int levels [] = {1, 3, 6, 8, 12};
892 trust.in.handle = handle;
893 trust.in.sid = domains.domains[i].sid;
894 trust.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
895 trust.out.trustdom_handle = &trustdom_handle;
897 status = dcerpc_lsa_OpenTrustedDomain(p, mem_ctx, &trust);
899 if (!NT_STATUS_IS_OK(status)) {
900 printf("OpenTrustedDomain failed - %s\n", nt_errstr(status));
904 c.in.handle = &trustdom_handle;
905 c.out.handle = &handle2;
907 for (j=0; j < ARRAY_SIZE(levels); j++) {
908 struct lsa_QueryTrustedDomainInfo q;
909 union lsa_TrustedDomainInfo info;
910 q.in.trustdom_handle = &trustdom_handle;
911 q.in.level = levels[j];
913 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
914 if (!NT_STATUS_IS_OK(status)) {
915 printf("QueryTrustedDomainInfo level %d failed - %s\n",
916 levels[j], nt_errstr(status));
921 status = dcerpc_lsa_Close(p, mem_ctx, &c);
922 if (!NT_STATUS_IS_OK(status)) {
923 printf("Close of trusted domain failed - %s\n", nt_errstr(status));
927 trust_by_name.in.handle = handle;
928 trust_by_name.in.name = domains.domains[i].name;
929 trust_by_name.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
930 trust_by_name.out.trustdom_handle = &trustdom_handle;
932 status = dcerpc_lsa_OpenTrustedDomainByName(p, mem_ctx, &trust_by_name);
934 if (!NT_STATUS_IS_OK(status)) {
935 printf("OpenTrustedDomainByName failed - %s\n", nt_errstr(status));
939 for (j=0; j < ARRAY_SIZE(levels); j++) {
940 struct lsa_QueryTrustedDomainInfo q;
941 union lsa_TrustedDomainInfo info;
942 q.in.trustdom_handle = &trustdom_handle;
943 q.in.level = levels[j];
945 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
946 if (!NT_STATUS_IS_OK(status)) {
947 printf("QueryTrustedDomainInfo level %d failed - %s\n",
948 levels[j], nt_errstr(status));
953 c.in.handle = &trustdom_handle;
954 c.out.handle = &handle2;
956 status = dcerpc_lsa_Close(p, mem_ctx, &c);
957 if (!NT_STATUS_IS_OK(status)) {
958 printf("Close of trusted domain failed - %s\n", nt_errstr(status));
962 for (j=0; j < ARRAY_SIZE(levels); j++) {
963 struct lsa_QueryTrustedDomainInfoBySid q;
964 union lsa_TrustedDomainInfo info;
965 q.in.handle = handle;
966 q.in.dom_sid = domains.domains[i].sid;
967 q.in.level = levels[j];
969 status = dcerpc_lsa_QueryTrustedDomainInfoBySid(p, mem_ctx, &q);
970 if (!NT_STATUS_IS_OK(status)) {
971 printf("QueryTrustedDomainInfoBySid level %d failed - %s\n",
972 levels[j], nt_errstr(status));
977 for (j=0; j < ARRAY_SIZE(levels); j++) {
978 struct lsa_QueryTrustedDomainInfoByName q;
979 union lsa_TrustedDomainInfo info;
980 q.in.handle = handle;
981 q.in.trusted_domain = domains.domains[i].name;
982 q.in.level = levels[j];
984 status = dcerpc_lsa_QueryTrustedDomainInfoByName(p, mem_ctx, &q);
985 if (!NT_STATUS_IS_OK(status)) {
986 printf("QueryTrustedDomainInfoByName level %d failed - %s\n",
987 levels[j], nt_errstr(status));
999 static BOOL test_QueryInfoPolicy(struct dcerpc_pipe *p,
1000 TALLOC_CTX *mem_ctx,
1001 struct policy_handle *handle)
1003 struct lsa_QueryInfoPolicy r;
1007 printf("\nTesting QueryInfoPolicy\n");
1009 for (i=1;i<13;i++) {
1010 r.in.handle = handle;
1013 printf("\ntrying QueryInfoPolicy level %d\n", i);
1015 status = dcerpc_lsa_QueryInfoPolicy(p, mem_ctx, &r);
1017 if ((i == 9 || i == 10 || i == 11) &&
1018 NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
1019 printf("server failed level %u (OK)\n", i);
1023 if (!NT_STATUS_IS_OK(status)) {
1024 printf("QueryInfoPolicy failed - %s\n", nt_errstr(status));
1033 static BOOL test_QueryInfoPolicy2(struct dcerpc_pipe *p,
1034 TALLOC_CTX *mem_ctx,
1035 struct policy_handle *handle)
1037 struct lsa_QueryInfoPolicy2 r;
1041 printf("\nTesting QueryInfoPolicy2\n");
1043 for (i=1;i<13;i++) {
1044 r.in.handle = handle;
1047 printf("\ntrying QueryInfoPolicy2 level %d\n", i);
1049 status = dcerpc_lsa_QueryInfoPolicy2(p, mem_ctx, &r);
1051 if ((i == 9 || i == 10 || i == 11) &&
1052 NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
1053 printf("server failed level %u (OK)\n", i);
1057 if (!NT_STATUS_IS_OK(status)) {
1058 printf("QueryInfoPolicy2 failed - %s\n", nt_errstr(status));
1067 static BOOL test_Close(struct dcerpc_pipe *p,
1068 TALLOC_CTX *mem_ctx,
1069 struct policy_handle *handle)
1073 struct policy_handle handle2;
1075 printf("\ntesting Close\n");
1077 r.in.handle = handle;
1078 r.out.handle = &handle2;
1080 status = dcerpc_lsa_Close(p, mem_ctx, &r);
1081 if (!NT_STATUS_IS_OK(status)) {
1082 printf("Close failed - %s\n", nt_errstr(status));
1086 status = dcerpc_lsa_Close(p, mem_ctx, &r);
1087 /* its really a fault - we need a status code for rpc fault */
1088 if (!NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
1089 printf("Close failed - %s\n", nt_errstr(status));
1098 BOOL torture_rpc_lsa(void)
1101 struct dcerpc_pipe *p;
1102 TALLOC_CTX *mem_ctx;
1104 struct policy_handle handle;
1106 mem_ctx = talloc_init("torture_rpc_lsa");
1108 status = torture_rpc_connection(&p,
1111 DCERPC_LSARPC_VERSION);
1112 if (!NT_STATUS_IS_OK(status)) {
1116 if (!test_OpenPolicy(p, mem_ctx)) {
1120 if (!test_OpenPolicy2(p, mem_ctx, &handle)) {
1124 if (!test_many_LookupSids(p, mem_ctx, &handle)) {
1128 if (!test_CreateAccount(p, mem_ctx, &handle)) {
1132 if (!test_CreateSecret(p, mem_ctx, &handle)) {
1136 if (!test_CreateTrustedDomain(p, mem_ctx, &handle)) {
1140 if (!test_EnumAccounts(p, mem_ctx, &handle)) {
1144 if (!test_EnumPrivs(p, mem_ctx, &handle)) {
1148 if (!test_EnumTrustDom(p, mem_ctx, &handle)) {
1152 if (!test_QueryInfoPolicy(p, mem_ctx, &handle)) {
1156 if (!test_QueryInfoPolicy2(p, mem_ctx, &handle)) {
1161 if (!test_Delete(p, mem_ctx, &handle)) {
1166 if (!test_Close(p, mem_ctx, &handle)) {
1170 talloc_destroy(mem_ctx);
1172 torture_rpc_close(p);