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;
327 struct lsa_LUID luid;
329 r.in.handle = handle;
333 status = dcerpc_lsa_LookupPrivValue(p, mem_ctx, &r);
334 if (!NT_STATUS_IS_OK(status)) {
335 printf("\nLookupPrivValue failed - %s\n", nt_errstr(status));
342 static BOOL test_LookupPrivName(struct dcerpc_pipe *p,
344 struct policy_handle *handle,
345 struct lsa_LUID *luid)
348 struct lsa_LookupPrivName r;
350 r.in.handle = handle;
353 status = dcerpc_lsa_LookupPrivName(p, mem_ctx, &r);
354 if (!NT_STATUS_IS_OK(status)) {
355 printf("\nLookupPrivName failed - %s\n", nt_errstr(status));
362 static BOOL test_RemovePrivilegesFromAccount(struct dcerpc_pipe *p,
364 struct policy_handle *acct_handle,
365 struct lsa_LUID *luid)
368 struct lsa_RemovePrivilegesFromAccount r;
369 struct lsa_PrivilegeSet privs;
372 printf("Testing RemovePrivilegesFromAccount\n");
374 r.in.handle = acct_handle;
380 privs.set = talloc_array_p(mem_ctx, struct lsa_LUIDAttribute, 1);
381 privs.set[0].luid = *luid;
382 privs.set[0].attribute = 0;
384 status = dcerpc_lsa_RemovePrivilegesFromAccount(p, mem_ctx, &r);
385 if (!NT_STATUS_IS_OK(status)) {
386 printf("RemovePrivilegesFromAccount failed - %s\n", nt_errstr(status));
393 static BOOL test_AddPrivilegesToAccount(struct dcerpc_pipe *p,
395 struct policy_handle *acct_handle,
396 struct lsa_LUID *luid)
399 struct lsa_AddPrivilegesToAccount r;
400 struct lsa_PrivilegeSet privs;
403 printf("Testing AddPrivilegesToAccount\n");
405 r.in.handle = acct_handle;
410 privs.set = talloc_array_p(mem_ctx, struct lsa_LUIDAttribute, 1);
411 privs.set[0].luid = *luid;
412 privs.set[0].attribute = 0;
414 status = dcerpc_lsa_AddPrivilegesToAccount(p, mem_ctx, &r);
415 if (!NT_STATUS_IS_OK(status)) {
416 printf("AddPrivilegesToAccount failed - %s\n", nt_errstr(status));
423 static BOOL test_EnumPrivsAccount(struct dcerpc_pipe *p,
425 struct policy_handle *handle,
426 struct policy_handle *acct_handle)
429 struct lsa_EnumPrivsAccount r;
432 printf("Testing EnumPrivsAccount\n");
434 r.in.handle = acct_handle;
436 status = dcerpc_lsa_EnumPrivsAccount(p, mem_ctx, &r);
437 if (!NT_STATUS_IS_OK(status)) {
438 printf("EnumPrivsAccount failed - %s\n", nt_errstr(status));
442 if (r.out.privs && r.out.privs->count > 0) {
444 for (i=0;i<r.out.privs->count;i++) {
445 test_LookupPrivName(p, mem_ctx, handle,
446 &r.out.privs->set[i].luid);
449 ret &= test_RemovePrivilegesFromAccount(p, mem_ctx, acct_handle,
450 &r.out.privs->set[0].luid);
451 ret &= test_AddPrivilegesToAccount(p, mem_ctx, acct_handle,
452 &r.out.privs->set[0].luid);
458 static BOOL test_Delete(struct dcerpc_pipe *p,
460 struct policy_handle *handle)
465 printf("\ntesting Delete\n");
467 r.in.handle = handle;
468 status = dcerpc_lsa_Delete(p, mem_ctx, &r);
469 if (!NT_STATUS_IS_OK(status)) {
470 printf("Delete failed - %s\n", nt_errstr(status));
480 static BOOL test_CreateAccount(struct dcerpc_pipe *p,
482 struct policy_handle *handle)
485 struct lsa_CreateAccount r;
486 struct dom_sid2 *newsid;
487 struct policy_handle acct_handle;
489 newsid = dom_sid_parse_talloc(mem_ctx, "S-1-5-12349876-4321-2854");
491 printf("Testing CreateAccount\n");
493 r.in.handle = handle;
495 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
496 r.out.acct_handle = &acct_handle;
498 status = dcerpc_lsa_CreateAccount(p, mem_ctx, &r);
499 if (!NT_STATUS_IS_OK(status)) {
500 printf("CreateAccount failed - %s\n", nt_errstr(status));
504 if (!test_Delete(p, mem_ctx, &acct_handle)) {
512 static BOOL test_CreateTrustedDomain(struct dcerpc_pipe *p,
514 struct policy_handle *handle)
517 struct lsa_CreateTrustedDomain r;
518 struct lsa_TrustInformation trustinfo;
519 struct dom_sid *domsid;
520 struct policy_handle dom_handle;
522 printf("Testing CreateTrustedDomain\n");
524 domsid = dom_sid_parse_talloc(mem_ctx, "S-1-5-21-97398-379795-12345");
526 trustinfo.sid = domsid;
527 init_lsa_String(&trustinfo.name, "torturedomain");
529 r.in.handle = handle;
530 r.in.info = &trustinfo;
531 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
532 r.out.dom_handle = &dom_handle;
534 status = dcerpc_lsa_CreateTrustedDomain(p, mem_ctx, &r);
535 if (!NT_STATUS_IS_OK(status)) {
536 printf("CreateTrustedDomain failed - %s\n", nt_errstr(status));
540 if (!test_Delete(p, mem_ctx, &dom_handle)) {
547 static BOOL test_CreateSecret(struct dcerpc_pipe *p,
549 struct policy_handle *handle)
552 struct lsa_CreateSecret r;
553 struct lsa_OpenSecret r2;
554 struct lsa_SetSecret r3;
555 struct lsa_QuerySecret r4;
556 struct policy_handle sec_handle, sec_handle2;
558 struct lsa_DATA_BUF buf1;
559 struct lsa_DATA_BUF_PTR bufp1;
562 DATA_BLOB session_key;
563 NTTIME old_mtime, new_mtime;
564 DATA_BLOB blob1, blob2;
565 const char *secret1 = "abcdef12345699qwerty";
569 printf("Testing CreateSecret\n");
571 asprintf(&secname, "torturesecret-%u", (uint_t)random());
573 init_lsa_String(&r.in.name, secname);
575 r.in.handle = handle;
576 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
577 r.out.sec_handle = &sec_handle;
579 status = dcerpc_lsa_CreateSecret(p, mem_ctx, &r);
580 if (!NT_STATUS_IS_OK(status)) {
581 printf("CreateSecret failed - %s\n", nt_errstr(status));
585 r2.in.handle = handle;
586 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
587 r2.in.name = r.in.name;
588 r2.out.sec_handle = &sec_handle2;
590 printf("Testing OpenSecret\n");
592 status = dcerpc_lsa_OpenSecret(p, mem_ctx, &r2);
593 if (!NT_STATUS_IS_OK(status)) {
594 printf("OpenSecret failed - %s\n", nt_errstr(status));
598 status = dcerpc_fetch_session_key(p, &session_key);
599 if (!NT_STATUS_IS_OK(status)) {
600 printf("dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
604 enc_key = sess_encrypt_string(secret1, &session_key);
606 r3.in.handle = &sec_handle;
607 r3.in.new_val = &buf1;
608 r3.in.old_val = NULL;
609 r3.in.new_val->data = enc_key.data;
610 r3.in.new_val->length = enc_key.length;
611 r3.in.new_val->size = enc_key.length;
613 printf("Testing SetSecret\n");
615 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r3);
616 if (!NT_STATUS_IS_OK(status)) {
617 printf("SetSecret failed - %s\n", nt_errstr(status));
621 data_blob_free(&enc_key);
623 ZERO_STRUCT(new_mtime);
624 ZERO_STRUCT(old_mtime);
626 /* fetch the secret back again */
627 r4.in.handle = &sec_handle;
628 r4.in.new_val = &bufp1;
629 r4.in.new_mtime = &new_mtime;
630 r4.in.old_val = NULL;
631 r4.in.old_mtime = NULL;
635 status = dcerpc_lsa_QuerySecret(p, mem_ctx, &r4);
636 if (!NT_STATUS_IS_OK(status)) {
637 printf("QuerySecret failed - %s\n", nt_errstr(status));
641 if (r4.out.new_val->buf == NULL) {
642 printf("No secret buffer returned\n");
645 blob1.data = r4.out.new_val->buf->data;
646 blob1.length = r4.out.new_val->buf->length;
648 blob2 = data_blob(NULL, blob1.length);
650 secret2 = sess_decrypt_string(&blob1, &session_key);
652 printf("returned secret '%s'\n", secret2);
654 if (strcmp(secret1, secret2) != 0) {
655 printf("Returned secret doesn't match\n");
660 if (!test_Delete(p, mem_ctx, &sec_handle)) {
664 d.in.handle = &sec_handle2;
665 status = dcerpc_lsa_Delete(p, mem_ctx, &d);
666 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
667 printf("Second delete expected INVALID_HANDLE - %s\n", nt_errstr(status));
675 static BOOL test_EnumAccountRights(struct dcerpc_pipe *p,
677 struct policy_handle *acct_handle,
681 struct lsa_EnumAccountRights r;
682 struct lsa_RightSet rights;
684 printf("Testing EnumAccountRights\n");
686 r.in.handle = acct_handle;
688 r.out.rights = &rights;
690 status = dcerpc_lsa_EnumAccountRights(p, mem_ctx, &r);
691 if (!NT_STATUS_IS_OK(status)) {
692 printf("EnumAccountRights failed - %s\n", nt_errstr(status));
700 static BOOL test_QuerySecurity(struct dcerpc_pipe *p,
702 struct policy_handle *handle,
703 struct policy_handle *acct_handle)
706 struct lsa_QuerySecurity r;
708 printf("Testing QuerySecurity\n");
710 r.in.handle = acct_handle;
713 status = dcerpc_lsa_QuerySecurity(p, mem_ctx, &r);
714 if (!NT_STATUS_IS_OK(status)) {
715 printf("QuerySecurity failed - %s\n", nt_errstr(status));
722 static BOOL test_OpenAccount(struct dcerpc_pipe *p,
724 struct policy_handle *handle,
728 struct lsa_OpenAccount r;
729 struct policy_handle acct_handle;
731 printf("Testing OpenAccount\n");
733 r.in.handle = handle;
735 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
736 r.out.acct_handle = &acct_handle;
738 status = dcerpc_lsa_OpenAccount(p, mem_ctx, &r);
739 if (!NT_STATUS_IS_OK(status)) {
740 printf("OpenAccount failed - %s\n", nt_errstr(status));
744 if (!test_EnumPrivsAccount(p, mem_ctx, handle, &acct_handle)) {
748 if (!test_QuerySecurity(p, mem_ctx, handle, &acct_handle)) {
755 static BOOL test_EnumAccounts(struct dcerpc_pipe *p,
757 struct policy_handle *handle)
760 struct lsa_EnumAccounts r;
761 struct lsa_SidArray sids1, sids2;
762 uint32_t resume_handle = 0;
765 printf("\ntesting EnumAccounts\n");
767 r.in.handle = handle;
768 r.in.resume_handle = &resume_handle;
769 r.in.num_entries = 100;
770 r.out.resume_handle = &resume_handle;
775 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
776 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
779 if (!NT_STATUS_IS_OK(status)) {
780 printf("EnumAccounts failed - %s\n", nt_errstr(status));
784 if (!test_LookupSids(p, mem_ctx, handle, &sids1)) {
788 if (!test_LookupSids2(p, mem_ctx, handle, &sids1)) {
792 printf("testing all accounts\n");
793 for (i=0;i<sids1.num_sids;i++) {
794 test_OpenAccount(p, mem_ctx, handle, sids1.sids[i].sid);
795 test_EnumAccountRights(p, mem_ctx, handle, sids1.sids[i].sid);
800 if (sids1.num_sids < 3) {
804 printf("trying EnumAccounts partial listing (asking for 1 at 2)\n");
806 r.in.num_entries = 1;
809 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
810 if (!NT_STATUS_IS_OK(status)) {
811 printf("EnumAccounts failed - %s\n", nt_errstr(status));
815 if (sids2.num_sids != 1) {
816 printf("Returned wrong number of entries (%d)\n", sids2.num_sids);
823 static BOOL test_LookupPrivDisplayName(struct dcerpc_pipe *p,
825 struct policy_handle *handle,
826 struct lsa_String *priv_name)
828 struct lsa_LookupPrivDisplayName r;
830 /* produce a reasonable range of language output without screwing up
832 uint16 language_id = (random() % 4) + 0x409;
834 printf("testing LookupPrivDisplayName(%s)\n", priv_name->string);
836 r.in.handle = handle;
837 r.in.name = priv_name;
838 r.in.language_id = &language_id;
839 r.out.language_id = &language_id;
842 status = dcerpc_lsa_LookupPrivDisplayName(p, mem_ctx, &r);
843 if (!NT_STATUS_IS_OK(status)) {
844 printf("LookupPrivDisplayName failed - %s\n", nt_errstr(status));
847 printf("%s -> \"%s\" (language 0x%x/0x%x)\n",
848 priv_name->string, r.out.disp_name->string,
849 *r.in.language_id, *r.out.language_id);
854 static BOOL test_EnumAccountsWithUserRight(struct dcerpc_pipe *p,
856 struct policy_handle *handle,
857 struct lsa_String *priv_name)
859 struct lsa_EnumAccountsWithUserRight r;
860 struct lsa_SidArray sids;
865 printf("testing EnumAccountsWithUserRight(%s)\n", priv_name->string);
867 r.in.handle = handle;
868 r.in.name = priv_name;
871 status = dcerpc_lsa_EnumAccountsWithUserRight(p, mem_ctx, &r);
873 /* NT_STATUS_NO_MORE_ENTRIES means noone has this privilege */
874 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
878 if (!NT_STATUS_IS_OK(status)) {
879 printf("EnumAccountsWithUserRight failed - %s\n", nt_errstr(status));
887 static BOOL test_EnumPrivs(struct dcerpc_pipe *p,
889 struct policy_handle *handle)
892 struct lsa_EnumPrivs r;
893 struct lsa_PrivArray privs1;
894 uint32_t resume_handle = 0;
898 printf("\ntesting EnumPrivs\n");
900 r.in.handle = handle;
901 r.in.resume_handle = &resume_handle;
902 r.in.max_count = 100;
903 r.out.resume_handle = &resume_handle;
904 r.out.privs = &privs1;
907 status = dcerpc_lsa_EnumPrivs(p, mem_ctx, &r);
908 if (!NT_STATUS_IS_OK(status)) {
909 printf("EnumPrivs failed - %s\n", nt_errstr(status));
913 for (i = 0; i< privs1.count; i++) {
914 test_LookupPrivDisplayName(p, mem_ctx, handle, &privs1.privs[i].name);
915 test_LookupPrivValue(p, mem_ctx, handle, &privs1.privs[i].name);
916 if (!test_EnumAccountsWithUserRight(p, mem_ctx, handle, &privs1.privs[i].name)) {
925 static BOOL test_EnumTrustDom(struct dcerpc_pipe *p,
927 struct policy_handle *handle)
929 struct lsa_EnumTrustDom r;
931 uint32_t resume_handle = 0;
932 struct lsa_DomainList domains;
936 printf("\nTesting EnumTrustDom\n");
938 r.in.handle = handle;
939 r.in.resume_handle = &resume_handle;
940 r.in.num_entries = 100;
941 r.out.domains = &domains;
942 r.out.resume_handle = &resume_handle;
944 status = dcerpc_lsa_EnumTrustDom(p, mem_ctx, &r);
946 /* NO_MORE_ENTRIES is allowed */
947 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
951 if (!NT_STATUS_IS_OK(status)) {
952 printf("EnumTrustDom failed - %s\n", nt_errstr(status));
956 printf("\nTesting OpenTrustedDomain, OpenTrustedDomainByName and QueryInfoTrustedDomain\n");
958 for (i=0; i< domains.count; i++) {
959 struct lsa_OpenTrustedDomain trust;
960 struct lsa_OpenTrustedDomainByName trust_by_name;
961 struct policy_handle trustdom_handle;
962 struct policy_handle handle2;
964 int levels [] = {1, 3, 6, 8, 12};
966 trust.in.handle = handle;
967 trust.in.sid = domains.domains[i].sid;
968 trust.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
969 trust.out.trustdom_handle = &trustdom_handle;
971 status = dcerpc_lsa_OpenTrustedDomain(p, mem_ctx, &trust);
973 if (!NT_STATUS_IS_OK(status)) {
974 printf("OpenTrustedDomain failed - %s\n", nt_errstr(status));
978 c.in.handle = &trustdom_handle;
979 c.out.handle = &handle2;
981 for (j=0; j < ARRAY_SIZE(levels); j++) {
982 struct lsa_QueryTrustedDomainInfo q;
983 union lsa_TrustedDomainInfo info;
984 q.in.trustdom_handle = &trustdom_handle;
985 q.in.level = levels[j];
987 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
988 if (!NT_STATUS_IS_OK(status)) {
989 printf("QueryTrustedDomainInfo level %d failed - %s\n",
990 levels[j], nt_errstr(status));
995 status = dcerpc_lsa_Close(p, mem_ctx, &c);
996 if (!NT_STATUS_IS_OK(status)) {
997 printf("Close of trusted domain failed - %s\n", nt_errstr(status));
1001 trust_by_name.in.handle = handle;
1002 trust_by_name.in.name = domains.domains[i].name;
1003 trust_by_name.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1004 trust_by_name.out.trustdom_handle = &trustdom_handle;
1006 status = dcerpc_lsa_OpenTrustedDomainByName(p, mem_ctx, &trust_by_name);
1008 if (!NT_STATUS_IS_OK(status)) {
1009 printf("OpenTrustedDomainByName failed - %s\n", nt_errstr(status));
1013 for (j=0; j < ARRAY_SIZE(levels); j++) {
1014 struct lsa_QueryTrustedDomainInfo q;
1015 union lsa_TrustedDomainInfo info;
1016 q.in.trustdom_handle = &trustdom_handle;
1017 q.in.level = levels[j];
1019 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
1020 if (!NT_STATUS_IS_OK(status)) {
1021 printf("QueryTrustedDomainInfo level %d failed - %s\n",
1022 levels[j], nt_errstr(status));
1027 c.in.handle = &trustdom_handle;
1028 c.out.handle = &handle2;
1030 status = dcerpc_lsa_Close(p, mem_ctx, &c);
1031 if (!NT_STATUS_IS_OK(status)) {
1032 printf("Close of trusted domain failed - %s\n", nt_errstr(status));
1036 for (j=0; j < ARRAY_SIZE(levels); j++) {
1037 struct lsa_QueryTrustedDomainInfoBySid q;
1038 union lsa_TrustedDomainInfo info;
1039 q.in.handle = handle;
1040 q.in.dom_sid = domains.domains[i].sid;
1041 q.in.level = levels[j];
1043 status = dcerpc_lsa_QueryTrustedDomainInfoBySid(p, mem_ctx, &q);
1044 if (!NT_STATUS_IS_OK(status)) {
1045 printf("QueryTrustedDomainInfoBySid level %d failed - %s\n",
1046 levels[j], nt_errstr(status));
1051 for (j=0; j < ARRAY_SIZE(levels); j++) {
1052 struct lsa_QueryTrustedDomainInfoByName q;
1053 union lsa_TrustedDomainInfo info;
1054 q.in.handle = handle;
1055 q.in.trusted_domain = domains.domains[i].name;
1056 q.in.level = levels[j];
1058 status = dcerpc_lsa_QueryTrustedDomainInfoByName(p, mem_ctx, &q);
1059 if (!NT_STATUS_IS_OK(status)) {
1060 printf("QueryTrustedDomainInfoByName level %d failed - %s\n",
1061 levels[j], nt_errstr(status));
1073 static BOOL test_QueryInfoPolicy(struct dcerpc_pipe *p,
1074 TALLOC_CTX *mem_ctx,
1075 struct policy_handle *handle)
1077 struct lsa_QueryInfoPolicy r;
1081 printf("\nTesting QueryInfoPolicy\n");
1083 for (i=1;i<13;i++) {
1084 r.in.handle = handle;
1087 printf("\ntrying QueryInfoPolicy level %d\n", i);
1089 status = dcerpc_lsa_QueryInfoPolicy(p, mem_ctx, &r);
1091 if ((i == 9 || i == 10 || i == 11) &&
1092 NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
1093 printf("server failed level %u (OK)\n", i);
1097 if (!NT_STATUS_IS_OK(status)) {
1098 printf("QueryInfoPolicy failed - %s\n", nt_errstr(status));
1107 static BOOL test_QueryInfoPolicy2(struct dcerpc_pipe *p,
1108 TALLOC_CTX *mem_ctx,
1109 struct policy_handle *handle)
1111 struct lsa_QueryInfoPolicy2 r;
1115 printf("\nTesting QueryInfoPolicy2\n");
1117 for (i=1;i<13;i++) {
1118 r.in.handle = handle;
1121 printf("\ntrying QueryInfoPolicy2 level %d\n", i);
1123 status = dcerpc_lsa_QueryInfoPolicy2(p, mem_ctx, &r);
1125 if ((i == 9 || i == 10 || i == 11) &&
1126 NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
1127 printf("server failed level %u (OK)\n", i);
1131 if (!NT_STATUS_IS_OK(status)) {
1132 printf("QueryInfoPolicy2 failed - %s\n", nt_errstr(status));
1141 static BOOL test_Close(struct dcerpc_pipe *p,
1142 TALLOC_CTX *mem_ctx,
1143 struct policy_handle *handle)
1147 struct policy_handle handle2;
1149 printf("\ntesting Close\n");
1151 r.in.handle = handle;
1152 r.out.handle = &handle2;
1154 status = dcerpc_lsa_Close(p, mem_ctx, &r);
1155 if (!NT_STATUS_IS_OK(status)) {
1156 printf("Close failed - %s\n", nt_errstr(status));
1160 status = dcerpc_lsa_Close(p, mem_ctx, &r);
1161 /* its really a fault - we need a status code for rpc fault */
1162 if (!NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
1163 printf("Close failed - %s\n", nt_errstr(status));
1172 BOOL torture_rpc_lsa(void)
1175 struct dcerpc_pipe *p;
1176 TALLOC_CTX *mem_ctx;
1178 struct policy_handle handle;
1180 mem_ctx = talloc_init("torture_rpc_lsa");
1182 status = torture_rpc_connection(&p,
1185 DCERPC_LSARPC_VERSION);
1186 if (!NT_STATUS_IS_OK(status)) {
1190 if (!test_OpenPolicy(p, mem_ctx)) {
1194 if (!test_OpenPolicy2(p, mem_ctx, &handle)) {
1198 if (!test_many_LookupSids(p, mem_ctx, &handle)) {
1202 if (!test_CreateAccount(p, mem_ctx, &handle)) {
1206 if (!test_CreateSecret(p, mem_ctx, &handle)) {
1210 if (!test_CreateTrustedDomain(p, mem_ctx, &handle)) {
1214 if (!test_EnumAccounts(p, mem_ctx, &handle)) {
1218 if (!test_EnumPrivs(p, mem_ctx, &handle)) {
1222 if (!test_EnumTrustDom(p, mem_ctx, &handle)) {
1226 if (!test_QueryInfoPolicy(p, mem_ctx, &handle)) {
1230 if (!test_QueryInfoPolicy2(p, mem_ctx, &handle)) {
1235 if (!test_Delete(p, mem_ctx, &handle)) {
1240 if (!test_Close(p, mem_ctx, &handle)) {
1244 talloc_destroy(mem_ctx);
1246 torture_rpc_close(p);