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_RIGHTS_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_RIGHTS_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(mem_ctx, tnames->count * sizeof(names[0]));
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));
147 static BOOL test_LookupSids(struct dcerpc_pipe *p,
149 struct policy_handle *handle,
150 struct lsa_SidArray *sids)
152 struct lsa_LookupSids r;
153 struct lsa_TransNameArray names;
154 uint32_t count = sids->num_sids;
157 printf("\nTesting LookupSids\n");
162 r.in.handle = handle;
167 r.out.count = &count;
168 r.out.names = &names;
170 status = dcerpc_lsa_LookupSids(p, mem_ctx, &r);
171 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
172 printf("LookupSids failed - %s\n", nt_errstr(status));
178 if (!test_LookupNames(p, mem_ctx, handle, &names)) {
185 static BOOL test_many_LookupSids(struct dcerpc_pipe *p,
187 struct policy_handle *handle)
189 struct lsa_LookupSids r;
190 struct lsa_TransNameArray names;
193 struct lsa_SidArray sids;
196 printf("\nTesting LookupSids with lots of SIDs\n");
201 sids.num_sids = 1000;
203 sids.sids = talloc_array_p(mem_ctx, struct lsa_SidPtr, sids.num_sids);
205 for (i=0; i<sids.num_sids; i++) {
206 const char *sidstr = "S-1-5-32-545";
207 sids.sids[i].sid = dom_sid_parse_talloc(mem_ctx, sidstr);
210 count = sids.num_sids;
212 r.in.handle = handle;
216 r.in.count = &names.count;
217 r.out.count = &count;
218 r.out.names = &names;
220 status = dcerpc_lsa_LookupSids(p, mem_ctx, &r);
221 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
222 printf("LookupSids failed - %s\n", nt_errstr(status));
228 if (!test_LookupNames(p, mem_ctx, handle, &names)) {
235 static BOOL test_LookupPrivName(struct dcerpc_pipe *p,
237 struct policy_handle *handle,
238 struct lsa_LUID *luid)
241 struct lsa_LookupPrivName r;
243 r.in.handle = handle;
246 status = dcerpc_lsa_LookupPrivName(p, mem_ctx, &r);
247 if (!NT_STATUS_IS_OK(status)) {
248 printf("\nLookupPrivName failed - %s\n", nt_errstr(status));
255 static BOOL test_EnumPrivsAccount(struct dcerpc_pipe *p,
257 struct policy_handle *handle,
258 struct policy_handle *acct_handle)
261 struct lsa_EnumPrivsAccount r;
263 printf("Testing EnumPrivsAccount\n");
265 r.in.handle = acct_handle;
267 status = dcerpc_lsa_EnumPrivsAccount(p, mem_ctx, &r);
268 if (!NT_STATUS_IS_OK(status)) {
269 printf("EnumPrivsAccount failed - %s\n", nt_errstr(status));
275 for (i=0;i<r.out.privs->count;i++) {
276 test_LookupPrivName(p, mem_ctx, handle,
277 &r.out.privs->set[i].luid);
284 static BOOL test_Delete(struct dcerpc_pipe *p,
286 struct policy_handle *handle)
291 printf("\ntesting Delete\n");
293 r.in.handle = handle;
294 status = dcerpc_lsa_Delete(p, mem_ctx, &r);
295 if (!NT_STATUS_IS_OK(status)) {
296 printf("Delete failed - %s\n", nt_errstr(status));
306 static BOOL test_CreateAccount(struct dcerpc_pipe *p,
308 struct policy_handle *handle)
311 struct lsa_CreateAccount r;
312 struct dom_sid2 *newsid;
313 struct policy_handle acct_handle;
315 newsid = dom_sid_parse_talloc(mem_ctx, "S-1-5-12349876-4321-2854");
317 printf("Testing CreateAccount\n");
319 r.in.handle = handle;
321 r.in.access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
322 r.out.acct_handle = &acct_handle;
324 status = dcerpc_lsa_CreateAccount(p, mem_ctx, &r);
325 if (!NT_STATUS_IS_OK(status)) {
326 printf("CreateAccount failed - %s\n", nt_errstr(status));
330 if (!test_Delete(p, mem_ctx, &acct_handle)) {
338 static BOOL test_CreateTrustedDomain(struct dcerpc_pipe *p,
340 struct policy_handle *handle)
343 struct lsa_CreateTrustedDomain r;
344 struct lsa_TrustInformation trustinfo;
345 struct dom_sid *domsid;
346 struct policy_handle dom_handle;
348 printf("Testing CreateTrustedDomain\n");
350 domsid = dom_sid_parse_talloc(mem_ctx, "S-1-5-21-97398-379795-12345");
352 trustinfo.sid = domsid;
353 init_lsa_String(&trustinfo.name, "torturedomain");
355 r.in.handle = handle;
356 r.in.info = &trustinfo;
357 r.in.access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
358 r.out.dom_handle = &dom_handle;
360 status = dcerpc_lsa_CreateTrustedDomain(p, mem_ctx, &r);
361 if (!NT_STATUS_IS_OK(status)) {
362 printf("CreateTrustedDomain failed - %s\n", nt_errstr(status));
366 if (!test_Delete(p, mem_ctx, &dom_handle)) {
373 static BOOL test_CreateSecret(struct dcerpc_pipe *p,
375 struct policy_handle *handle)
378 struct lsa_CreateSecret r;
379 struct lsa_OpenSecret r2;
380 struct lsa_SetSecret r3;
381 struct lsa_QuerySecret r4;
382 struct policy_handle sec_handle, sec_handle2;
384 struct lsa_DATA_BUF buf1;
385 struct lsa_DATA_BUF_PTR bufp1;
388 DATA_BLOB session_key;
389 NTTIME old_mtime, new_mtime;
390 DATA_BLOB blob1, blob2;
391 const char *secret1 = "abcdef12345699qwerty";
395 printf("Testing CreateSecret\n");
397 asprintf(&secname, "torturesecret-%u", (uint_t)random());
399 init_lsa_String(&r.in.name, secname);
401 r.in.handle = handle;
402 r.in.access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
403 r.out.sec_handle = &sec_handle;
405 status = dcerpc_lsa_CreateSecret(p, mem_ctx, &r);
406 if (!NT_STATUS_IS_OK(status)) {
407 printf("CreateSecret failed - %s\n", nt_errstr(status));
411 r2.in.handle = handle;
412 r2.in.access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
413 r2.in.name = r.in.name;
414 r2.out.sec_handle = &sec_handle2;
416 printf("Testing OpenSecret\n");
418 status = dcerpc_lsa_OpenSecret(p, mem_ctx, &r2);
419 if (!NT_STATUS_IS_OK(status)) {
420 printf("OpenSecret failed - %s\n", nt_errstr(status));
424 status = dcerpc_fetch_session_key(p, &session_key);
425 if (!NT_STATUS_IS_OK(status)) {
426 printf("dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
430 enc_key = sess_encrypt_string(secret1, &session_key);
432 r3.in.handle = &sec_handle;
433 r3.in.new_val = &buf1;
434 r3.in.old_val = NULL;
435 r3.in.new_val->data = enc_key.data;
436 r3.in.new_val->length = enc_key.length;
437 r3.in.new_val->size = enc_key.length;
439 printf("Testing SetSecret\n");
441 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r3);
442 if (!NT_STATUS_IS_OK(status)) {
443 printf("SetSecret failed - %s\n", nt_errstr(status));
447 data_blob_free(&enc_key);
449 ZERO_STRUCT(new_mtime);
450 ZERO_STRUCT(old_mtime);
452 /* fetch the secret back again */
453 r4.in.handle = &sec_handle;
454 r4.in.new_val = &bufp1;
455 r4.in.new_mtime = &new_mtime;
456 r4.in.old_val = NULL;
457 r4.in.old_mtime = NULL;
461 status = dcerpc_lsa_QuerySecret(p, mem_ctx, &r4);
462 if (!NT_STATUS_IS_OK(status)) {
463 printf("QuerySecret failed - %s\n", nt_errstr(status));
467 if (r4.out.new_val->buf == NULL) {
468 printf("No secret buffer returned\n");
471 blob1.data = r4.out.new_val->buf->data;
472 blob1.length = r4.out.new_val->buf->length;
474 blob2 = data_blob(NULL, blob1.length);
476 secret2 = sess_decrypt_string(&blob1, &session_key);
478 printf("returned secret '%s'\n", secret2);
480 if (strcmp(secret1, secret2) != 0) {
481 printf("Returned secret doesn't match\n");
486 if (!test_Delete(p, mem_ctx, &sec_handle)) {
490 d.in.handle = &sec_handle2;
491 status = dcerpc_lsa_Delete(p, mem_ctx, &d);
492 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
493 printf("Second delete expected INVALID_HANDLE - %s\n", nt_errstr(status));
501 static BOOL test_EnumAccountRights(struct dcerpc_pipe *p,
503 struct policy_handle *acct_handle,
507 struct lsa_EnumAccountRights r;
508 struct lsa_RightSet rights;
510 printf("Testing EnumAccountRights\n");
512 r.in.handle = acct_handle;
514 r.out.rights = &rights;
516 status = dcerpc_lsa_EnumAccountRights(p, mem_ctx, &r);
517 if (!NT_STATUS_IS_OK(status)) {
518 printf("EnumAccountRights failed - %s\n", nt_errstr(status));
526 static BOOL test_QuerySecurity(struct dcerpc_pipe *p,
528 struct policy_handle *handle,
529 struct policy_handle *acct_handle)
532 struct lsa_QuerySecurity r;
534 printf("Testing QuerySecuriy\n");
536 r.in.handle = acct_handle;
539 status = dcerpc_lsa_QuerySecurity(p, mem_ctx, &r);
540 if (!NT_STATUS_IS_OK(status)) {
541 printf("QuerySecurity failed - %s\n", nt_errstr(status));
548 static BOOL test_OpenAccount(struct dcerpc_pipe *p,
550 struct policy_handle *handle,
554 struct lsa_OpenAccount r;
555 struct policy_handle acct_handle;
557 printf("Testing OpenAccount\n");
559 r.in.handle = handle;
561 r.in.access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
562 r.out.acct_handle = &acct_handle;
564 status = dcerpc_lsa_OpenAccount(p, mem_ctx, &r);
565 if (!NT_STATUS_IS_OK(status)) {
566 printf("OpenAccount failed - %s\n", nt_errstr(status));
570 if (!test_EnumPrivsAccount(p, mem_ctx, handle, &acct_handle)) {
574 if (!test_QuerySecurity(p, mem_ctx, handle, &acct_handle)) {
581 static BOOL test_EnumAccounts(struct dcerpc_pipe *p,
583 struct policy_handle *handle)
586 struct lsa_EnumAccounts r;
587 struct lsa_SidArray sids1, sids2;
588 uint32_t resume_handle = 0;
591 printf("\ntesting EnumAccounts\n");
593 r.in.handle = handle;
594 r.in.resume_handle = &resume_handle;
595 r.in.num_entries = 100;
596 r.out.resume_handle = &resume_handle;
600 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
601 if (!NT_STATUS_IS_OK(status)) {
602 printf("EnumAccounts failed - %s\n", nt_errstr(status));
606 if (!test_LookupSids(p, mem_ctx, handle, &sids1)) {
610 printf("testing all accounts\n");
611 for (i=0;i<sids1.num_sids;i++) {
612 test_OpenAccount(p, mem_ctx, handle, sids1.sids[i].sid);
613 test_EnumAccountRights(p, mem_ctx, handle, sids1.sids[i].sid);
617 if (sids1.num_sids < 3) {
621 printf("trying EnumAccounts partial listing (asking for 1 at 2)\n");
623 r.in.num_entries = 1;
626 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
627 if (!NT_STATUS_IS_OK(status)) {
628 printf("EnumAccounts failed - %s\n", nt_errstr(status));
632 if (sids2.num_sids != 1) {
633 printf("Returned wrong number of entries (%d)\n", sids2.num_sids);
640 static BOOL test_LookupPrivDisplayName(struct dcerpc_pipe *p,
642 struct policy_handle *handle,
643 struct lsa_String *priv_name)
645 struct lsa_LookupPrivDisplayName r;
647 /* produce a reasonable range of language output without screwing up
649 uint16 language_id = (random() % 4) + 0x409;
651 printf("testing LookupPrivDisplayName(%s)\n", priv_name->string);
653 r.in.handle = handle;
654 r.in.name = priv_name;
655 r.in.language_id = &language_id;
656 r.out.language_id = &language_id;
659 status = dcerpc_lsa_LookupPrivDisplayName(p, mem_ctx, &r);
660 if (!NT_STATUS_IS_OK(status)) {
661 printf("LookupPrivDisplayName failed - %s\n", nt_errstr(status));
664 printf("%s -> \"%s\" (language 0x%x/0x%x)\n",
665 priv_name->string, r.out.disp_name->string,
666 *r.in.language_id, *r.out.language_id);
671 static BOOL test_EnumAccountsWithUserRight(struct dcerpc_pipe *p,
673 struct policy_handle *handle,
674 struct lsa_String *priv_name)
676 struct lsa_EnumAccountsWithUserRight r;
677 struct lsa_SidArray sids;
682 printf("testing EnumAccountsWithUserRight(%s)\n", priv_name->string);
684 r.in.handle = handle;
685 r.in.name = priv_name;
688 status = dcerpc_lsa_EnumAccountsWithUserRight(p, mem_ctx, &r);
690 /* NT_STATUS_NO_MORE_ENTRIES means noone has this privilege */
691 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
695 if (!NT_STATUS_IS_OK(status)) {
696 printf("EnumAccountsWithUserRight failed - %s\n", nt_errstr(status));
704 static BOOL test_EnumPrivs(struct dcerpc_pipe *p,
706 struct policy_handle *handle)
709 struct lsa_EnumPrivs r;
710 struct lsa_PrivArray privs1;
711 uint32_t resume_handle = 0;
715 printf("\ntesting EnumPrivs\n");
717 r.in.handle = handle;
718 r.in.resume_handle = &resume_handle;
719 r.in.max_count = 1000;
720 r.out.resume_handle = &resume_handle;
721 r.out.privs = &privs1;
724 status = dcerpc_lsa_EnumPrivs(p, mem_ctx, &r);
725 if (!NT_STATUS_IS_OK(status)) {
726 printf("EnumPrivs failed - %s\n", nt_errstr(status));
730 for (i = 0; i< privs1.count; i++) {
731 test_LookupPrivDisplayName(p, mem_ctx, handle, &privs1.privs[i].name);
732 if (!test_EnumAccountsWithUserRight(p, mem_ctx, handle, &privs1.privs[i].name)) {
741 static BOOL test_EnumTrustDom(struct dcerpc_pipe *p,
743 struct policy_handle *handle)
745 struct lsa_EnumTrustDom r;
747 uint32_t resume_handle = 0;
748 struct lsa_DomainList domains;
752 printf("\nTesting EnumTrustDom\n");
754 r.in.handle = handle;
755 r.in.resume_handle = &resume_handle;
756 r.in.num_entries = 1000;
757 r.out.domains = &domains;
758 r.out.resume_handle = &resume_handle;
760 status = dcerpc_lsa_EnumTrustDom(p, mem_ctx, &r);
762 /* NO_MORE_ENTRIES is allowed */
763 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
767 if (!NT_STATUS_IS_OK(status)) {
768 printf("EnumTrustDom failed - %s\n", nt_errstr(status));
772 printf("\nTesting OpenTrustedDomain, OpenTrustedDomainByName and QueryInfoTrustedDomain\n");
774 for (i=0; i< domains.count; i++) {
775 struct lsa_OpenTrustedDomain trust;
776 struct lsa_OpenTrustedDomainByName trust_by_name;
777 struct policy_handle trustdom_handle;
778 struct policy_handle handle2;
780 int levels [] = {1, 3, 6};
782 trust.in.handle = handle;
783 trust.in.sid = domains.domains[i].sid;
784 trust.in.access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
785 trust.out.trustdom_handle = &trustdom_handle;
787 status = dcerpc_lsa_OpenTrustedDomain(p, mem_ctx, &trust);
789 if (!NT_STATUS_IS_OK(status)) {
790 printf("OpenTrustedDomain failed - %s\n", nt_errstr(status));
794 c.in.handle = &trustdom_handle;
795 c.out.handle = &handle2;
797 for (j=0; j < ARRAY_SIZE(levels); j++) {
798 struct lsa_QueryTrustedDomainInfo q;
799 union lsa_TrustedDomainInfo info;
800 q.in.trustdom_handle = &trustdom_handle;
801 q.in.level = levels[j];
803 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
804 if (!NT_STATUS_IS_OK(status)) {
805 printf("QueryTrustedDomainInfo level %d failed - %s\n",
806 levels[j], nt_errstr(status));
811 status = dcerpc_lsa_Close(p, mem_ctx, &c);
812 if (!NT_STATUS_IS_OK(status)) {
813 printf("Close of trusted domain failed - %s\n", nt_errstr(status));
817 trust_by_name.in.handle = handle;
818 trust_by_name.in.name = domains.domains[i].name;
819 trust_by_name.in.access_mask = SEC_RIGHTS_MAXIMUM_ALLOWED;
820 trust_by_name.out.trustdom_handle = &trustdom_handle;
822 status = dcerpc_lsa_OpenTrustedDomainByName(p, mem_ctx, &trust_by_name);
824 if (!NT_STATUS_IS_OK(status)) {
825 printf("OpenTrustedDomainByName failed - %s\n", nt_errstr(status));
829 for (j=0; j < ARRAY_SIZE(levels); j++) {
830 struct lsa_QueryTrustedDomainInfo q;
831 union lsa_TrustedDomainInfo info;
832 q.in.trustdom_handle = &trustdom_handle;
833 q.in.level = levels[j];
835 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
836 if (!NT_STATUS_IS_OK(status)) {
837 printf("QueryTrustedDomainInfo level %d failed - %s\n",
838 levels[j], nt_errstr(status));
843 c.in.handle = &trustdom_handle;
844 c.out.handle = &handle2;
846 status = dcerpc_lsa_Close(p, mem_ctx, &c);
847 if (!NT_STATUS_IS_OK(status)) {
848 printf("Close of trusted domain failed - %s\n", nt_errstr(status));
852 for (j=0; j < ARRAY_SIZE(levels); j++) {
853 struct lsa_QueryTrustedDomainInfoBySid q;
854 union lsa_TrustedDomainInfo info;
855 q.in.handle = handle;
856 q.in.dom_sid = domains.domains[i].sid;
857 q.in.level = levels[j];
859 status = dcerpc_lsa_QueryTrustedDomainInfoBySid(p, mem_ctx, &q);
860 if (!NT_STATUS_IS_OK(status)) {
861 printf("QueryTrustedDomainInfoBySid level %d failed - %s\n",
862 levels[j], nt_errstr(status));
867 for (j=0; j < ARRAY_SIZE(levels); j++) {
868 struct lsa_QueryTrustedDomainInfoByName q;
869 union lsa_TrustedDomainInfo info;
870 q.in.handle = handle;
871 q.in.trusted_domain = domains.domains[i].name;
872 q.in.level = levels[j];
874 status = dcerpc_lsa_QueryTrustedDomainInfoByName(p, mem_ctx, &q);
875 if (!NT_STATUS_IS_OK(status)) {
876 printf("QueryTrustedDomainInfoByName level %d failed - %s\n",
877 levels[j], nt_errstr(status));
889 static BOOL test_QueryInfoPolicy(struct dcerpc_pipe *p,
891 struct policy_handle *handle)
893 struct lsa_QueryInfoPolicy r;
897 printf("\nTesting QueryInfoPolicy\n");
900 r.in.handle = handle;
903 printf("\ntrying QueryInfoPolicy level %d\n", i);
905 status = dcerpc_lsa_QueryInfoPolicy(p, mem_ctx, &r);
907 if ((i == 9 || i == 10 || i == 11) &&
908 NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
909 printf("server failed level %u (OK)\n", i);
913 if (!NT_STATUS_IS_OK(status)) {
914 printf("QueryInfoPolicy failed - %s\n", nt_errstr(status));
923 static BOOL test_QueryInfoPolicy2(struct dcerpc_pipe *p,
925 struct policy_handle *handle)
927 struct lsa_QueryInfoPolicy2 r;
931 printf("\nTesting QueryInfoPolicy2\n");
934 r.in.handle = handle;
937 printf("\ntrying QueryInfoPolicy2 level %d\n", i);
939 status = dcerpc_lsa_QueryInfoPolicy2(p, mem_ctx, &r);
941 if ((i == 9 || i == 10 || i == 11) &&
942 NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
943 printf("server failed level %u (OK)\n", i);
947 if (!NT_STATUS_IS_OK(status)) {
948 printf("QueryInfoPolicy2 failed - %s\n", nt_errstr(status));
957 static BOOL test_Close(struct dcerpc_pipe *p,
959 struct policy_handle *handle)
963 struct policy_handle handle2;
965 printf("\ntesting Close\n");
967 r.in.handle = handle;
968 r.out.handle = &handle2;
970 status = dcerpc_lsa_Close(p, mem_ctx, &r);
971 if (!NT_STATUS_IS_OK(status)) {
972 printf("Close failed - %s\n", nt_errstr(status));
976 status = dcerpc_lsa_Close(p, mem_ctx, &r);
977 /* its really a fault - we need a status code for rpc fault */
978 if (!NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
979 printf("Close failed - %s\n", nt_errstr(status));
988 BOOL torture_rpc_lsa(void)
991 struct dcerpc_pipe *p;
994 struct policy_handle handle;
996 mem_ctx = talloc_init("torture_rpc_lsa");
998 status = torture_rpc_connection(&p,
1001 DCERPC_LSARPC_VERSION);
1002 if (!NT_STATUS_IS_OK(status)) {
1006 if (!test_OpenPolicy(p, mem_ctx)) {
1010 if (!test_OpenPolicy2(p, mem_ctx, &handle)) {
1014 if (!test_many_LookupSids(p, mem_ctx, &handle)) {
1018 if (!test_CreateAccount(p, mem_ctx, &handle)) {
1022 if (!test_CreateSecret(p, mem_ctx, &handle)) {
1026 if (!test_CreateTrustedDomain(p, mem_ctx, &handle)) {
1030 if (!test_EnumAccounts(p, mem_ctx, &handle)) {
1034 if (!test_EnumPrivs(p, mem_ctx, &handle)) {
1038 if (!test_EnumTrustDom(p, mem_ctx, &handle)) {
1042 if (!test_QueryInfoPolicy(p, mem_ctx, &handle)) {
1046 if (!test_QueryInfoPolicy2(p, mem_ctx, &handle)) {
1051 if (!test_Delete(p, mem_ctx, &handle)) {
1056 if (!test_Close(p, mem_ctx, &handle)) {
1060 talloc_destroy(mem_ctx);
1062 torture_rpc_close(p);