2 Unix SMB/CIFS implementation.
3 test suite for lsa rpc operations
5 Copyright (C) Andrew Tridgell 2003
6 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2004-2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "torture/torture.h"
25 #include "librpc/gen_ndr/ndr_lsa.h"
26 #include "librpc/gen_ndr/ndr_lsa_c.h"
27 #include "lib/events/events.h"
28 #include "libcli/security/proto.h"
29 #include "libcli/auth/libcli_auth.h"
30 #include "torture/rpc/rpc.h"
32 static void init_lsa_String(struct lsa_String *name, const char *s)
37 static BOOL test_OpenPolicy(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
39 struct lsa_ObjectAttribute attr;
40 struct policy_handle handle;
41 struct lsa_QosInfo qos;
42 struct lsa_OpenPolicy r;
44 uint16_t system_name = '\\';
46 printf("\ntesting OpenPolicy\n");
49 qos.impersonation_level = 2;
51 qos.effective_only = 0;
55 attr.object_name = NULL;
60 r.in.system_name = &system_name;
62 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
63 r.out.handle = &handle;
65 status = dcerpc_lsa_OpenPolicy(p, mem_ctx, &r);
66 if (!NT_STATUS_IS_OK(status)) {
67 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
68 NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
69 printf("not considering %s to be an error\n", nt_errstr(status));
72 printf("OpenPolicy failed - %s\n", nt_errstr(status));
80 BOOL test_lsa_OpenPolicy2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
81 struct policy_handle **handle)
83 struct lsa_ObjectAttribute attr;
84 struct lsa_QosInfo qos;
85 struct lsa_OpenPolicy2 r;
88 printf("\ntesting OpenPolicy2\n");
90 *handle = talloc(mem_ctx, struct policy_handle);
96 qos.impersonation_level = 2;
98 qos.effective_only = 0;
101 attr.root_dir = NULL;
102 attr.object_name = NULL;
104 attr.sec_desc = NULL;
107 r.in.system_name = "\\";
109 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
110 r.out.handle = *handle;
112 status = dcerpc_lsa_OpenPolicy2(p, mem_ctx, &r);
113 if (!NT_STATUS_IS_OK(status)) {
114 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
115 NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
116 printf("not considering %s to be an error\n", nt_errstr(status));
117 talloc_free(*handle);
121 printf("OpenPolicy2 failed - %s\n", nt_errstr(status));
128 static BOOL test_LookupNames(struct dcerpc_pipe *p,
130 struct policy_handle *handle,
131 struct lsa_TransNameArray *tnames)
133 struct lsa_LookupNames r;
134 struct lsa_TransSidArray sids;
135 struct lsa_String *names;
140 printf("\nTesting LookupNames with %d names\n", tnames->count);
145 names = talloc_array(mem_ctx, struct lsa_String, tnames->count);
146 for (i=0;i<tnames->count;i++) {
147 init_lsa_String(&names[i], tnames->names[i].name.string);
150 r.in.handle = handle;
151 r.in.num_names = tnames->count;
156 r.out.count = &count;
159 status = dcerpc_lsa_LookupNames(p, mem_ctx, &r);
160 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
161 printf("LookupNames failed - %s\n", nt_errstr(status));
170 static BOOL test_LookupNames2(struct dcerpc_pipe *p,
172 struct policy_handle *handle,
173 struct lsa_TransNameArray2 *tnames)
175 struct lsa_LookupNames2 r;
176 struct lsa_TransSidArray2 sids;
177 struct lsa_String *names;
182 printf("\nTesting LookupNames2 with %d names\n", tnames->count);
187 names = talloc_array(mem_ctx, struct lsa_String, tnames->count);
188 for (i=0;i<tnames->count;i++) {
189 init_lsa_String(&names[i], tnames->names[i].name.string);
192 r.in.handle = handle;
193 r.in.num_names = tnames->count;
200 r.out.count = &count;
203 status = dcerpc_lsa_LookupNames2(p, mem_ctx, &r);
204 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
205 printf("LookupNames2 failed - %s\n", nt_errstr(status));
215 static BOOL test_LookupNames3(struct dcerpc_pipe *p,
217 struct policy_handle *handle,
218 struct lsa_TransNameArray2 *tnames)
220 struct lsa_LookupNames3 r;
221 struct lsa_TransSidArray3 sids;
222 struct lsa_String *names;
227 printf("\nTesting LookupNames3 with %d names\n", tnames->count);
232 names = talloc_array(mem_ctx, struct lsa_String, tnames->count);
233 for (i=0;i<tnames->count;i++) {
234 init_lsa_String(&names[i], tnames->names[i].name.string);
237 r.in.handle = handle;
238 r.in.num_names = tnames->count;
245 r.out.count = &count;
248 status = dcerpc_lsa_LookupNames3(p, mem_ctx, &r);
249 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
250 printf("LookupNames3 failed - %s\n", nt_errstr(status));
259 static BOOL test_LookupNames4(struct dcerpc_pipe *p,
261 struct lsa_TransNameArray2 *tnames)
263 struct lsa_LookupNames4 r;
264 struct lsa_TransSidArray3 sids;
265 struct lsa_String *names;
270 printf("\nTesting LookupNames4 with %d names\n", tnames->count);
275 names = talloc_array(mem_ctx, struct lsa_String, tnames->count);
276 for (i=0;i<tnames->count;i++) {
277 init_lsa_String(&names[i], tnames->names[i].name.string);
280 r.in.num_names = tnames->count;
287 r.out.count = &count;
290 status = dcerpc_lsa_LookupNames4(p, mem_ctx, &r);
291 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
292 printf("LookupNames4 failed - %s\n", nt_errstr(status));
302 static BOOL test_LookupSids(struct dcerpc_pipe *p,
304 struct policy_handle *handle,
305 struct lsa_SidArray *sids)
307 struct lsa_LookupSids r;
308 struct lsa_TransNameArray names;
309 uint32_t count = sids->num_sids;
312 printf("\nTesting LookupSids\n");
317 r.in.handle = handle;
322 r.out.count = &count;
323 r.out.names = &names;
325 status = dcerpc_lsa_LookupSids(p, mem_ctx, &r);
326 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
327 printf("LookupSids failed - %s\n", nt_errstr(status));
333 if (!test_LookupNames(p, mem_ctx, handle, &names)) {
341 static BOOL test_LookupSids2(struct dcerpc_pipe *p,
343 struct policy_handle *handle,
344 struct lsa_SidArray *sids)
346 struct lsa_LookupSids2 r;
347 struct lsa_TransNameArray2 names;
348 uint32_t count = sids->num_sids;
351 printf("\nTesting LookupSids2\n");
356 r.in.handle = handle;
363 r.out.count = &count;
364 r.out.names = &names;
366 status = dcerpc_lsa_LookupSids2(p, mem_ctx, &r);
367 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
368 printf("LookupSids2 failed - %s\n", nt_errstr(status));
374 if (!test_LookupNames2(p, mem_ctx, handle, &names)) {
378 if (!test_LookupNames3(p, mem_ctx, handle, &names)) {
385 static BOOL test_LookupSids3(struct dcerpc_pipe *p,
387 struct lsa_SidArray *sids)
389 struct lsa_LookupSids3 r;
390 struct lsa_TransNameArray2 names;
391 uint32_t count = sids->num_sids;
394 printf("\nTesting LookupSids3\n");
405 r.out.count = &count;
406 r.out.names = &names;
408 status = dcerpc_lsa_LookupSids3(p, mem_ctx, &r);
409 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
410 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
411 NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
412 printf("not considering %s to be an error\n", nt_errstr(status));
415 printf("LookupSids3 failed - %s - not considered an error\n",
422 if (!test_LookupNames4(p, mem_ctx, &names)) {
429 BOOL test_many_LookupSids(struct dcerpc_pipe *p,
431 struct policy_handle *handle)
435 struct lsa_SidArray sids;
438 printf("\nTesting LookupSids with lots of SIDs\n");
442 sids.sids = talloc_array(mem_ctx, struct lsa_SidPtr, sids.num_sids);
444 for (i=0; i<sids.num_sids; i++) {
445 const char *sidstr = "S-1-5-32-545";
446 sids.sids[i].sid = dom_sid_parse_talloc(mem_ctx, sidstr);
449 count = sids.num_sids;
452 struct lsa_LookupSids r;
453 struct lsa_TransNameArray names;
457 r.in.handle = handle;
461 r.in.count = &names.count;
462 r.out.count = &count;
463 r.out.names = &names;
465 status = dcerpc_lsa_LookupSids(p, mem_ctx, &r);
466 if (!NT_STATUS_IS_OK(status) &&
467 !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
468 printf("LookupSids failed - %s\n", nt_errstr(status));
474 if (!test_LookupNames(p, mem_ctx, handle, &names)) {
478 struct lsa_LookupSids3 r;
479 struct lsa_TransNameArray2 names;
484 printf("\nTesting LookupSids3\n");
492 r.out.count = &count;
493 r.out.names = &names;
495 status = dcerpc_lsa_LookupSids3(p, mem_ctx, &r);
496 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
497 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
498 NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
499 printf("not considering %s to be an error\n", nt_errstr(status));
502 printf("LookupSids3 failed - %s\n",
506 if (!test_LookupNames4(p, mem_ctx, &names)) {
518 #define NUM_ASYNC_REQUESTS 1000
520 static void lookupsids_cb(struct rpc_request *req)
522 int *replies = (int *)req->async.private;
525 status = dcerpc_ndr_request_recv(req);
526 DEBUG(3, ("lookupsids returned %s\n", nt_errstr(status)));
527 if (!NT_STATUS_IS_OK(status)) {
534 static BOOL test_LookupSids_async(struct dcerpc_pipe *p,
536 struct policy_handle *handle)
538 struct lsa_SidArray sids;
539 struct lsa_SidPtr sidptr;
541 uint32_t count[NUM_ASYNC_REQUESTS];
542 struct lsa_TransNameArray names[NUM_ASYNC_REQUESTS];
543 struct lsa_LookupSids r[NUM_ASYNC_REQUESTS];
544 struct rpc_request **req;
549 printf("\nTesting %d async lookupsids request\n", 100);
551 req = talloc_array(mem_ctx, struct rpc_request *, NUM_ASYNC_REQUESTS);
555 sidptr.sid = dom_sid_parse_talloc(mem_ctx, "S-1-5-32-545");
559 for (i=0; i<NUM_ASYNC_REQUESTS; i++) {
562 names[i].names = NULL;
564 r[i].in.handle = handle;
565 r[i].in.sids = &sids;
566 r[i].in.names = &names[i];
568 r[i].in.count = &names[i].count;
569 r[i].out.count = &count[i];
570 r[i].out.names = &names[i];
572 req[i] = dcerpc_lsa_LookupSids_send(p, req, &r[i]);
573 if (req[i] == NULL) {
578 req[i]->async.callback = lookupsids_cb;
579 req[i]->async.private = &replies;
582 while (replies < NUM_ASYNC_REQUESTS) {
583 event_loop_once(p->conn->event_ctx);
595 static BOOL test_LookupPrivValue(struct dcerpc_pipe *p,
597 struct policy_handle *handle,
598 struct lsa_String *name)
601 struct lsa_LookupPrivValue r;
602 struct lsa_LUID luid;
604 r.in.handle = handle;
608 status = dcerpc_lsa_LookupPrivValue(p, mem_ctx, &r);
609 if (!NT_STATUS_IS_OK(status)) {
610 printf("\nLookupPrivValue failed - %s\n", nt_errstr(status));
617 static BOOL test_LookupPrivName(struct dcerpc_pipe *p,
619 struct policy_handle *handle,
620 struct lsa_LUID *luid)
623 struct lsa_LookupPrivName r;
625 r.in.handle = handle;
628 status = dcerpc_lsa_LookupPrivName(p, mem_ctx, &r);
629 if (!NT_STATUS_IS_OK(status)) {
630 printf("\nLookupPrivName failed - %s\n", nt_errstr(status));
637 static BOOL test_RemovePrivilegesFromAccount(struct dcerpc_pipe *p,
639 struct policy_handle *acct_handle,
640 struct lsa_LUID *luid)
643 struct lsa_RemovePrivilegesFromAccount r;
644 struct lsa_PrivilegeSet privs;
647 printf("Testing RemovePrivilegesFromAccount\n");
649 r.in.handle = acct_handle;
655 privs.set = talloc_array(mem_ctx, struct lsa_LUIDAttribute, 1);
656 privs.set[0].luid = *luid;
657 privs.set[0].attribute = 0;
659 status = dcerpc_lsa_RemovePrivilegesFromAccount(p, mem_ctx, &r);
660 if (!NT_STATUS_IS_OK(status)) {
661 printf("RemovePrivilegesFromAccount failed - %s\n", nt_errstr(status));
668 static BOOL test_AddPrivilegesToAccount(struct dcerpc_pipe *p,
670 struct policy_handle *acct_handle,
671 struct lsa_LUID *luid)
674 struct lsa_AddPrivilegesToAccount r;
675 struct lsa_PrivilegeSet privs;
678 printf("Testing AddPrivilegesToAccount\n");
680 r.in.handle = acct_handle;
685 privs.set = talloc_array(mem_ctx, struct lsa_LUIDAttribute, 1);
686 privs.set[0].luid = *luid;
687 privs.set[0].attribute = 0;
689 status = dcerpc_lsa_AddPrivilegesToAccount(p, mem_ctx, &r);
690 if (!NT_STATUS_IS_OK(status)) {
691 printf("AddPrivilegesToAccount failed - %s\n", nt_errstr(status));
698 static BOOL test_EnumPrivsAccount(struct dcerpc_pipe *p,
700 struct policy_handle *handle,
701 struct policy_handle *acct_handle)
704 struct lsa_EnumPrivsAccount r;
707 printf("Testing EnumPrivsAccount\n");
709 r.in.handle = acct_handle;
711 status = dcerpc_lsa_EnumPrivsAccount(p, mem_ctx, &r);
712 if (!NT_STATUS_IS_OK(status)) {
713 printf("EnumPrivsAccount failed - %s\n", nt_errstr(status));
717 if (r.out.privs && r.out.privs->count > 0) {
719 for (i=0;i<r.out.privs->count;i++) {
720 test_LookupPrivName(p, mem_ctx, handle,
721 &r.out.privs->set[i].luid);
724 ret &= test_RemovePrivilegesFromAccount(p, mem_ctx, acct_handle,
725 &r.out.privs->set[0].luid);
726 ret &= test_AddPrivilegesToAccount(p, mem_ctx, acct_handle,
727 &r.out.privs->set[0].luid);
733 static BOOL test_Delete(struct dcerpc_pipe *p,
735 struct policy_handle *handle)
740 printf("testing Delete\n");
742 r.in.handle = handle;
743 status = dcerpc_lsa_Delete(p, mem_ctx, &r);
744 if (!NT_STATUS_IS_OK(status)) {
745 printf("Delete failed - %s\n", nt_errstr(status));
753 static BOOL test_CreateAccount(struct dcerpc_pipe *p,
755 struct policy_handle *handle)
758 struct lsa_CreateAccount r;
759 struct dom_sid2 *newsid;
760 struct policy_handle acct_handle;
762 newsid = dom_sid_parse_talloc(mem_ctx, "S-1-5-12349876-4321-2854");
764 printf("Testing CreateAccount\n");
766 r.in.handle = handle;
768 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
769 r.out.acct_handle = &acct_handle;
771 status = dcerpc_lsa_CreateAccount(p, mem_ctx, &r);
772 if (!NT_STATUS_IS_OK(status)) {
773 printf("CreateAccount failed - %s\n", nt_errstr(status));
777 if (!test_Delete(p, mem_ctx, &acct_handle)) {
784 static BOOL test_DeleteTrustedDomain(struct dcerpc_pipe *p,
786 struct policy_handle *handle,
787 struct lsa_StringLarge name)
790 struct lsa_OpenTrustedDomainByName r;
791 struct policy_handle trustdom_handle;
793 r.in.handle = handle;
794 r.in.name.string = name.string;
795 r.in.access_mask = SEC_STD_DELETE;
796 r.out.trustdom_handle = &trustdom_handle;
798 status = dcerpc_lsa_OpenTrustedDomainByName(p, mem_ctx, &r);
799 if (!NT_STATUS_IS_OK(status)) {
800 printf("lsa_OpenTrustedDomainByName failed - %s\n", nt_errstr(status));
804 if (!test_Delete(p, mem_ctx, &trustdom_handle)) {
812 static BOOL test_CreateSecret(struct dcerpc_pipe *p,
814 struct policy_handle *handle)
817 struct lsa_CreateSecret r;
818 struct lsa_OpenSecret r2;
819 struct lsa_SetSecret r3;
820 struct lsa_QuerySecret r4;
821 struct lsa_SetSecret r5;
822 struct lsa_QuerySecret r6;
823 struct lsa_SetSecret r7;
824 struct lsa_QuerySecret r8;
825 struct policy_handle sec_handle, sec_handle2, sec_handle3;
827 struct lsa_DATA_BUF buf1;
828 struct lsa_DATA_BUF_PTR bufp1;
829 struct lsa_DATA_BUF_PTR bufp2;
832 DATA_BLOB session_key;
833 NTTIME old_mtime, new_mtime;
834 DATA_BLOB blob1, blob2;
835 const char *secret1 = "abcdef12345699qwerty";
837 const char *secret3 = "ABCDEF12345699QWERTY";
839 const char *secret5 = "NEW-SAMBA4-SECRET";
844 const int GLOBAL = 1;
846 secname[LOCAL] = talloc_asprintf(mem_ctx, "torturesecret-%u", (uint_t)random());
847 secname[GLOBAL] = talloc_asprintf(mem_ctx, "G$torturesecret-%u", (uint_t)random());
849 for (i=0; i< 2; i++) {
850 printf("Testing CreateSecret of %s\n", secname[i]);
852 init_lsa_String(&r.in.name, secname[i]);
854 r.in.handle = handle;
855 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
856 r.out.sec_handle = &sec_handle;
858 status = dcerpc_lsa_CreateSecret(p, mem_ctx, &r);
859 if (!NT_STATUS_IS_OK(status)) {
860 printf("CreateSecret failed - %s\n", nt_errstr(status));
864 r.in.handle = handle;
865 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
866 r.out.sec_handle = &sec_handle3;
868 status = dcerpc_lsa_CreateSecret(p, mem_ctx, &r);
869 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
870 printf("CreateSecret should have failed OBJECT_NAME_COLLISION - %s\n", nt_errstr(status));
874 r2.in.handle = handle;
875 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
876 r2.in.name = r.in.name;
877 r2.out.sec_handle = &sec_handle2;
879 printf("Testing OpenSecret\n");
881 status = dcerpc_lsa_OpenSecret(p, mem_ctx, &r2);
882 if (!NT_STATUS_IS_OK(status)) {
883 printf("OpenSecret failed - %s\n", nt_errstr(status));
887 status = dcerpc_fetch_session_key(p, &session_key);
888 if (!NT_STATUS_IS_OK(status)) {
889 printf("dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
893 enc_key = sess_encrypt_string(secret1, &session_key);
895 r3.in.sec_handle = &sec_handle;
896 r3.in.new_val = &buf1;
897 r3.in.old_val = NULL;
898 r3.in.new_val->data = enc_key.data;
899 r3.in.new_val->length = enc_key.length;
900 r3.in.new_val->size = enc_key.length;
902 printf("Testing SetSecret\n");
904 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r3);
905 if (!NT_STATUS_IS_OK(status)) {
906 printf("SetSecret failed - %s\n", nt_errstr(status));
910 r3.in.sec_handle = &sec_handle;
911 r3.in.new_val = &buf1;
912 r3.in.old_val = NULL;
913 r3.in.new_val->data = enc_key.data;
914 r3.in.new_val->length = enc_key.length;
915 r3.in.new_val->size = enc_key.length;
917 /* break the encrypted data */
920 printf("Testing SetSecret with broken key\n");
922 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r3);
923 if (!NT_STATUS_EQUAL(status, NT_STATUS_UNKNOWN_REVISION)) {
924 printf("SetSecret should have failed UNKNOWN_REVISION - %s\n", nt_errstr(status));
928 data_blob_free(&enc_key);
930 ZERO_STRUCT(new_mtime);
931 ZERO_STRUCT(old_mtime);
933 /* fetch the secret back again */
934 r4.in.sec_handle = &sec_handle;
935 r4.in.new_val = &bufp1;
936 r4.in.new_mtime = &new_mtime;
937 r4.in.old_val = NULL;
938 r4.in.old_mtime = NULL;
942 printf("Testing QuerySecret\n");
943 status = dcerpc_lsa_QuerySecret(p, mem_ctx, &r4);
944 if (!NT_STATUS_IS_OK(status)) {
945 printf("QuerySecret failed - %s\n", nt_errstr(status));
948 if (r4.out.new_val == NULL || r4.out.new_val->buf == NULL) {
949 printf("No secret buffer returned\n");
952 blob1.data = r4.out.new_val->buf->data;
953 blob1.length = r4.out.new_val->buf->size;
955 blob2 = data_blob_talloc(mem_ctx, NULL, blob1.length);
957 secret2 = sess_decrypt_string(&blob1, &session_key);
959 if (strcmp(secret1, secret2) != 0) {
960 printf("Returned secret '%s' doesn't match '%s'\n",
967 enc_key = sess_encrypt_string(secret3, &session_key);
969 r5.in.sec_handle = &sec_handle;
970 r5.in.new_val = &buf1;
971 r5.in.old_val = NULL;
972 r5.in.new_val->data = enc_key.data;
973 r5.in.new_val->length = enc_key.length;
974 r5.in.new_val->size = enc_key.length;
976 printf("Testing SetSecret (existing value should move to old)\n");
978 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r5);
979 if (!NT_STATUS_IS_OK(status)) {
980 printf("SetSecret failed - %s\n", nt_errstr(status));
984 data_blob_free(&enc_key);
986 ZERO_STRUCT(new_mtime);
987 ZERO_STRUCT(old_mtime);
989 /* fetch the secret back again */
990 r6.in.sec_handle = &sec_handle;
991 r6.in.new_val = &bufp1;
992 r6.in.new_mtime = &new_mtime;
993 r6.in.old_val = &bufp2;
994 r6.in.old_mtime = &old_mtime;
999 status = dcerpc_lsa_QuerySecret(p, mem_ctx, &r6);
1000 if (!NT_STATUS_IS_OK(status)) {
1001 printf("QuerySecret failed - %s\n", nt_errstr(status));
1006 if (r6.out.new_val->buf == NULL || r6.out.old_val->buf == NULL
1007 || r6.out.new_mtime == NULL || r6.out.old_mtime == NULL) {
1008 printf("Both secret buffers and both times not returned\n");
1012 blob1.data = r6.out.new_val->buf->data;
1013 blob1.length = r6.out.new_val->buf->size;
1015 blob2 = data_blob_talloc(mem_ctx, NULL, blob1.length);
1017 secret4 = sess_decrypt_string(&blob1, &session_key);
1019 if (strcmp(secret3, secret4) != 0) {
1020 printf("Returned NEW secret %s doesn't match %s\n", secret4, secret3);
1024 blob1.data = r6.out.old_val->buf->data;
1025 blob1.length = r6.out.old_val->buf->length;
1027 blob2 = data_blob_talloc(mem_ctx, NULL, blob1.length);
1029 secret2 = sess_decrypt_string(&blob1, &session_key);
1031 if (strcmp(secret1, secret2) != 0) {
1032 printf("Returned OLD secret %s doesn't match %s\n", secret2, secret1);
1036 if (*r6.out.new_mtime == *r6.out.old_mtime) {
1037 printf("Returned secret %s had same mtime for both secrets: %s\n",
1039 nt_time_string(mem_ctx, *r6.out.new_mtime));
1045 enc_key = sess_encrypt_string(secret5, &session_key);
1047 r7.in.sec_handle = &sec_handle;
1048 r7.in.old_val = &buf1;
1049 r7.in.old_val->data = enc_key.data;
1050 r7.in.old_val->length = enc_key.length;
1051 r7.in.old_val->size = enc_key.length;
1052 r7.in.new_val = NULL;
1054 printf("Testing SetSecret of old Secret only\n");
1056 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r7);
1057 if (!NT_STATUS_IS_OK(status)) {
1058 printf("SetSecret failed - %s\n", nt_errstr(status));
1062 data_blob_free(&enc_key);
1064 /* fetch the secret back again */
1065 r8.in.sec_handle = &sec_handle;
1066 r8.in.new_val = &bufp1;
1067 r8.in.new_mtime = &new_mtime;
1068 r8.in.old_val = &bufp2;
1069 r8.in.old_mtime = &old_mtime;
1074 status = dcerpc_lsa_QuerySecret(p, mem_ctx, &r8);
1075 if (!NT_STATUS_IS_OK(status)) {
1076 printf("QuerySecret failed - %s\n", nt_errstr(status));
1079 if (!r8.out.new_val || !r8.out.old_val) {
1080 printf("in/out pointers not returned, despite being set on in for QuerySecret\n");
1082 } else if (r8.out.new_val->buf == NULL) {
1084 printf("NEW secret buffer not returned after GLOBAL OLD set\n");
1087 } else if (r8.out.old_val->buf == NULL) {
1088 printf("OLD secret buffer not returned after OLD set\n");
1090 } else if (r8.out.new_mtime == NULL || r8.out.old_mtime == NULL) {
1091 printf("Both times not returned after OLD set\n");
1095 printf("NEW secret buffer should not be returned after LOCAL OLD set\n");
1098 blob1.data = r8.out.new_val->buf->data;
1099 blob1.length = r8.out.new_val->buf->length;
1101 blob2 = data_blob_talloc(mem_ctx, NULL, blob1.length);
1103 secret6 = sess_decrypt_string(&blob1, &session_key);
1105 if (strcmp(secret3, secret4) != 0) {
1106 printf("Returned NEW secret '%s' doesn't match '%s'\n", secret4, secret3);
1110 blob1.data = r8.out.old_val->buf->data;
1111 blob1.length = r8.out.old_val->buf->size;
1113 blob2 = data_blob_talloc(mem_ctx, NULL, blob1.length);
1115 secret6 = sess_decrypt_string(&blob1, &session_key);
1117 if (strcmp(secret5, secret6) != 0) {
1118 printf("Returned OLD secret %s doesn't match %s\n", secret5, secret6);
1122 if (*r8.out.new_mtime == *r8.out.old_mtime) {
1124 printf("Returned secret %s had same mtime for both secrets: %s\n",
1126 nt_time_string(mem_ctx, *r8.out.new_mtime));
1130 printf("Returned secret %s should have had same mtime for both secrets: %s != %s\n",
1132 nt_time_string(mem_ctx, *r8.out.old_mtime),
1133 nt_time_string(mem_ctx, *r8.out.new_mtime));
1139 if (!test_Delete(p, mem_ctx, &sec_handle)) {
1143 d.in.handle = &sec_handle2;
1144 status = dcerpc_lsa_Delete(p, mem_ctx, &d);
1145 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1146 printf("Second delete expected INVALID_HANDLE - %s\n", nt_errstr(status));
1150 printf("Testing OpenSecret of just-deleted secret\n");
1152 status = dcerpc_lsa_OpenSecret(p, mem_ctx, &r2);
1153 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
1154 printf("OpenSecret expected OBJECT_NAME_NOT_FOUND - %s\n", nt_errstr(status));
1165 static BOOL test_EnumAccountRights(struct dcerpc_pipe *p,
1166 TALLOC_CTX *mem_ctx,
1167 struct policy_handle *acct_handle,
1168 struct dom_sid *sid)
1171 struct lsa_EnumAccountRights r;
1172 struct lsa_RightSet rights;
1174 printf("Testing EnumAccountRights\n");
1176 r.in.handle = acct_handle;
1178 r.out.rights = &rights;
1180 status = dcerpc_lsa_EnumAccountRights(p, mem_ctx, &r);
1181 if (!NT_STATUS_IS_OK(status)) {
1182 printf("EnumAccountRights failed - %s\n", nt_errstr(status));
1190 static BOOL test_QuerySecurity(struct dcerpc_pipe *p,
1191 TALLOC_CTX *mem_ctx,
1192 struct policy_handle *handle,
1193 struct policy_handle *acct_handle)
1196 struct lsa_QuerySecurity r;
1198 printf("Testing QuerySecurity\n");
1200 r.in.handle = acct_handle;
1203 status = dcerpc_lsa_QuerySecurity(p, mem_ctx, &r);
1204 if (!NT_STATUS_IS_OK(status)) {
1205 printf("QuerySecurity failed - %s\n", nt_errstr(status));
1212 static BOOL test_OpenAccount(struct dcerpc_pipe *p,
1213 TALLOC_CTX *mem_ctx,
1214 struct policy_handle *handle,
1215 struct dom_sid *sid)
1218 struct lsa_OpenAccount r;
1219 struct policy_handle acct_handle;
1221 printf("Testing OpenAccount\n");
1223 r.in.handle = handle;
1225 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1226 r.out.acct_handle = &acct_handle;
1228 status = dcerpc_lsa_OpenAccount(p, mem_ctx, &r);
1229 if (!NT_STATUS_IS_OK(status)) {
1230 printf("OpenAccount failed - %s\n", nt_errstr(status));
1234 if (!test_EnumPrivsAccount(p, mem_ctx, handle, &acct_handle)) {
1238 if (!test_QuerySecurity(p, mem_ctx, handle, &acct_handle)) {
1245 static BOOL test_EnumAccounts(struct dcerpc_pipe *p,
1246 TALLOC_CTX *mem_ctx,
1247 struct policy_handle *handle)
1250 struct lsa_EnumAccounts r;
1251 struct lsa_SidArray sids1, sids2;
1252 uint32_t resume_handle = 0;
1255 printf("\ntesting EnumAccounts\n");
1257 r.in.handle = handle;
1258 r.in.resume_handle = &resume_handle;
1259 r.in.num_entries = 100;
1260 r.out.resume_handle = &resume_handle;
1261 r.out.sids = &sids1;
1265 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
1266 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
1269 if (!NT_STATUS_IS_OK(status)) {
1270 printf("EnumAccounts failed - %s\n", nt_errstr(status));
1274 if (!test_LookupSids(p, mem_ctx, handle, &sids1)) {
1278 if (!test_LookupSids2(p, mem_ctx, handle, &sids1)) {
1282 if (!test_LookupSids3(p, mem_ctx, &sids1)) {
1286 printf("testing all accounts\n");
1287 for (i=0;i<sids1.num_sids;i++) {
1288 test_OpenAccount(p, mem_ctx, handle, sids1.sids[i].sid);
1289 test_EnumAccountRights(p, mem_ctx, handle, sids1.sids[i].sid);
1294 if (sids1.num_sids < 3) {
1298 printf("trying EnumAccounts partial listing (asking for 1 at 2)\n");
1300 r.in.num_entries = 1;
1301 r.out.sids = &sids2;
1303 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
1304 if (!NT_STATUS_IS_OK(status)) {
1305 printf("EnumAccounts failed - %s\n", nt_errstr(status));
1309 if (sids2.num_sids != 1) {
1310 printf("Returned wrong number of entries (%d)\n", sids2.num_sids);
1317 static BOOL test_LookupPrivDisplayName(struct dcerpc_pipe *p,
1318 TALLOC_CTX *mem_ctx,
1319 struct policy_handle *handle,
1320 struct lsa_String *priv_name)
1322 struct lsa_LookupPrivDisplayName r;
1324 /* produce a reasonable range of language output without screwing up
1326 uint16_t language_id = (random() % 4) + 0x409;
1328 printf("testing LookupPrivDisplayName(%s)\n", priv_name->string);
1330 r.in.handle = handle;
1331 r.in.name = priv_name;
1332 r.in.language_id = &language_id;
1333 r.out.language_id = &language_id;
1336 status = dcerpc_lsa_LookupPrivDisplayName(p, mem_ctx, &r);
1337 if (!NT_STATUS_IS_OK(status)) {
1338 printf("LookupPrivDisplayName failed - %s\n", nt_errstr(status));
1341 printf("%s -> \"%s\" (language 0x%x/0x%x)\n",
1342 priv_name->string, r.out.disp_name->string,
1343 *r.in.language_id, *r.out.language_id);
1348 static BOOL test_EnumAccountsWithUserRight(struct dcerpc_pipe *p,
1349 TALLOC_CTX *mem_ctx,
1350 struct policy_handle *handle,
1351 struct lsa_String *priv_name)
1353 struct lsa_EnumAccountsWithUserRight r;
1354 struct lsa_SidArray sids;
1359 printf("testing EnumAccountsWithUserRight(%s)\n", priv_name->string);
1361 r.in.handle = handle;
1362 r.in.name = priv_name;
1365 status = dcerpc_lsa_EnumAccountsWithUserRight(p, mem_ctx, &r);
1367 /* NT_STATUS_NO_MORE_ENTRIES means noone has this privilege */
1368 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
1372 if (!NT_STATUS_IS_OK(status)) {
1373 printf("EnumAccountsWithUserRight failed - %s\n", nt_errstr(status));
1381 static BOOL test_EnumPrivs(struct dcerpc_pipe *p,
1382 TALLOC_CTX *mem_ctx,
1383 struct policy_handle *handle)
1386 struct lsa_EnumPrivs r;
1387 struct lsa_PrivArray privs1;
1388 uint32_t resume_handle = 0;
1392 printf("\ntesting EnumPrivs\n");
1394 r.in.handle = handle;
1395 r.in.resume_handle = &resume_handle;
1396 r.in.max_count = 100;
1397 r.out.resume_handle = &resume_handle;
1398 r.out.privs = &privs1;
1401 status = dcerpc_lsa_EnumPrivs(p, mem_ctx, &r);
1402 if (!NT_STATUS_IS_OK(status)) {
1403 printf("EnumPrivs failed - %s\n", nt_errstr(status));
1407 for (i = 0; i< privs1.count; i++) {
1408 test_LookupPrivDisplayName(p, mem_ctx, handle, (struct lsa_String *)&privs1.privs[i].name);
1409 test_LookupPrivValue(p, mem_ctx, handle, (struct lsa_String *)&privs1.privs[i].name);
1410 if (!test_EnumAccountsWithUserRight(p, mem_ctx, handle, (struct lsa_String *)&privs1.privs[i].name)) {
1418 static BOOL test_query_each_TrustDom(struct dcerpc_pipe *p,
1419 TALLOC_CTX *mem_ctx,
1420 struct policy_handle *handle,
1421 struct lsa_DomainList *domains)
1427 printf("\nTesting OpenTrustedDomain, OpenTrustedDomainByName and QueryInfoTrustedDomain\n");
1428 for (i=0; i< domains->count; i++) {
1429 struct lsa_OpenTrustedDomain trust;
1430 struct lsa_OpenTrustedDomainByName trust_by_name;
1431 struct policy_handle trustdom_handle;
1432 struct policy_handle handle2;
1434 int levels [] = {1, 3, 6, 8, 12};
1436 if (domains->domains[i].sid) {
1437 trust.in.handle = handle;
1438 trust.in.sid = domains->domains[i].sid;
1439 trust.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1440 trust.out.trustdom_handle = &trustdom_handle;
1442 status = dcerpc_lsa_OpenTrustedDomain(p, mem_ctx, &trust);
1444 if (!NT_STATUS_IS_OK(status)) {
1445 printf("OpenTrustedDomain failed - %s\n", nt_errstr(status));
1449 c.in.handle = &trustdom_handle;
1450 c.out.handle = &handle2;
1452 for (j=0; j < ARRAY_SIZE(levels); j++) {
1453 struct lsa_QueryTrustedDomainInfo q;
1454 union lsa_TrustedDomainInfo info;
1455 q.in.trustdom_handle = &trustdom_handle;
1456 q.in.level = levels[j];
1458 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
1459 if (!NT_STATUS_IS_OK(status)) {
1460 printf("QueryTrustedDomainInfo level %d failed - %s\n",
1461 levels[j], nt_errstr(status));
1466 status = dcerpc_lsa_Close(p, mem_ctx, &c);
1467 if (!NT_STATUS_IS_OK(status)) {
1468 printf("Close of trusted domain failed - %s\n", nt_errstr(status));
1473 trust_by_name.in.handle = handle;
1474 trust_by_name.in.name.string = domains->domains[i].name.string;
1475 trust_by_name.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1476 trust_by_name.out.trustdom_handle = &trustdom_handle;
1478 status = dcerpc_lsa_OpenTrustedDomainByName(p, mem_ctx, &trust_by_name);
1480 if (!NT_STATUS_IS_OK(status)) {
1481 printf("OpenTrustedDomainByName failed - %s\n", nt_errstr(status));
1485 for (j=0; j < ARRAY_SIZE(levels); j++) {
1486 struct lsa_QueryTrustedDomainInfo q;
1487 union lsa_TrustedDomainInfo info;
1488 q.in.trustdom_handle = &trustdom_handle;
1489 q.in.level = levels[j];
1491 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
1492 if (!NT_STATUS_IS_OK(status)) {
1493 printf("QueryTrustedDomainInfo level %d failed - %s\n",
1494 levels[j], nt_errstr(status));
1499 c.in.handle = &trustdom_handle;
1500 c.out.handle = &handle2;
1502 status = dcerpc_lsa_Close(p, mem_ctx, &c);
1503 if (!NT_STATUS_IS_OK(status)) {
1504 printf("Close of trusted domain failed - %s\n", nt_errstr(status));
1508 for (j=0; j < ARRAY_SIZE(levels); j++) {
1509 struct lsa_QueryTrustedDomainInfoBySid q;
1510 union lsa_TrustedDomainInfo info;
1512 if (!domains->domains[i].sid) {
1516 q.in.handle = handle;
1517 q.in.dom_sid = domains->domains[i].sid;
1518 q.in.level = levels[j];
1520 status = dcerpc_lsa_QueryTrustedDomainInfoBySid(p, mem_ctx, &q);
1521 if (!NT_STATUS_IS_OK(status)) {
1522 printf("QueryTrustedDomainInfoBySid level %d failed - %s\n",
1523 levels[j], nt_errstr(status));
1528 for (j=0; j < ARRAY_SIZE(levels); j++) {
1529 struct lsa_QueryTrustedDomainInfoByName q;
1530 union lsa_TrustedDomainInfo info;
1531 q.in.handle = handle;
1532 q.in.trusted_domain.string = domains->domains[i].name.string;
1533 q.in.level = levels[j];
1535 status = dcerpc_lsa_QueryTrustedDomainInfoByName(p, mem_ctx, &q);
1536 if (!NT_STATUS_IS_OK(status)) {
1537 printf("QueryTrustedDomainInfoByName level %d failed - %s\n",
1538 levels[j], nt_errstr(status));
1546 static BOOL test_EnumTrustDom(struct dcerpc_pipe *p,
1547 TALLOC_CTX *mem_ctx,
1548 struct policy_handle *handle)
1550 struct lsa_EnumTrustDom r;
1551 NTSTATUS enum_status;
1552 uint32_t resume_handle = 0;
1553 struct lsa_DomainList domains;
1556 printf("\nTesting EnumTrustDom\n");
1559 r.in.handle = handle;
1560 r.in.resume_handle = &resume_handle;
1561 r.in.max_size = LSA_ENUM_TRUST_DOMAIN_MULTIPLIER * 3;
1562 r.out.domains = &domains;
1563 r.out.resume_handle = &resume_handle;
1565 enum_status = dcerpc_lsa_EnumTrustDom(p, mem_ctx, &r);
1567 /* NO_MORE_ENTRIES is allowed */
1568 if (NT_STATUS_EQUAL(enum_status, NT_STATUS_NO_MORE_ENTRIES)) {
1570 } else if (NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES)) {
1571 /* Windows 2003 gets this off by one on the first run */
1572 if (r.out.domains->count < 3 || r.out.domains->count > 4) {
1573 printf("EnumTrustDom didn't fill the buffer we "
1574 "asked it to (got %d, expected %d / %d == %d entries)\n",
1575 r.out.domains->count, LSA_ENUM_TRUST_DOMAIN_MULTIPLIER * 3,
1576 LSA_ENUM_TRUST_DOMAIN_MULTIPLIER, r.in.max_size);
1579 } else if (!NT_STATUS_IS_OK(enum_status)) {
1580 printf("EnumTrustDom failed - %s\n", nt_errstr(enum_status));
1584 ret &= test_query_each_TrustDom(p, mem_ctx, handle, &domains);
1586 } while ((NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES)));
1591 static BOOL test_CreateTrustedDomain(struct dcerpc_pipe *p,
1592 TALLOC_CTX *mem_ctx,
1593 struct policy_handle *handle)
1597 struct lsa_CreateTrustedDomain r;
1598 struct lsa_TrustInformation trustinfo;
1599 struct dom_sid *domsid[12];
1600 struct policy_handle trustdom_handle[12];
1601 struct lsa_QueryTrustedDomainInfo q;
1604 printf("Testing CreateTrustedDomain for 12 domains\n");
1606 for (i=0; i< 12; i++) {
1607 char *trust_name = talloc_asprintf(mem_ctx, "torturedom%02d", i);
1608 char *trust_sid = talloc_asprintf(mem_ctx, "S-1-5-21-97398-379795-100%02d", i);
1610 domsid[i] = dom_sid_parse_talloc(mem_ctx, trust_sid);
1612 trustinfo.sid = domsid[i];
1613 init_lsa_String((struct lsa_String *)&trustinfo.name, trust_name);
1615 r.in.handle = handle;
1616 r.in.info = &trustinfo;
1617 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1618 r.out.trustdom_handle = &trustdom_handle[i];
1620 status = dcerpc_lsa_CreateTrustedDomain(p, mem_ctx, &r);
1621 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
1622 test_DeleteTrustedDomain(p, mem_ctx, handle, trustinfo.name);
1623 status = dcerpc_lsa_CreateTrustedDomain(p, mem_ctx, &r);
1625 if (!NT_STATUS_IS_OK(status)) {
1626 printf("CreateTrustedDomain failed - %s\n", nt_errstr(status));
1630 q.in.trustdom_handle = &trustdom_handle[i];
1631 q.in.level = LSA_TRUSTED_DOMAIN_INFO_NAME;
1632 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
1633 if (!NT_STATUS_IS_OK(status)) {
1634 printf("QueryTrustedDomainInfo level 1 failed - %s\n", nt_errstr(status));
1636 } else if (!q.out.info) {
1639 if (strcmp(q.out.info->name.netbios_name.string, trustinfo.name.string) != 0) {
1640 printf("QueryTrustedDomainInfo returned inconsistant short name: %s != %s\n",
1641 q.out.info->name.netbios_name.string, trustinfo.name.string);
1648 /* now that we have some domains to look over, we can test the enum calls */
1649 if (!test_EnumTrustDom(p, mem_ctx, handle)) {
1653 for (i=0; i<12; i++) {
1654 if (!test_Delete(p, mem_ctx, &trustdom_handle[i])) {
1662 static BOOL test_QueryDomainInfoPolicy(struct dcerpc_pipe *p,
1663 TALLOC_CTX *mem_ctx,
1664 struct policy_handle *handle)
1666 struct lsa_QueryDomainInformationPolicy r;
1670 printf("\nTesting QueryDomainInformationPolicy\n");
1673 r.in.handle = handle;
1676 printf("\ntrying QueryDomainInformationPolicy level %d\n", i);
1678 status = dcerpc_lsa_QueryDomainInformationPolicy(p, mem_ctx, &r);
1680 if (!NT_STATUS_IS_OK(status)) {
1681 printf("QueryDomainInformationPolicy failed - %s\n", nt_errstr(status));
1691 static BOOL test_QueryInfoPolicy(struct dcerpc_pipe *p,
1692 TALLOC_CTX *mem_ctx,
1693 struct policy_handle *handle)
1695 struct lsa_QueryInfoPolicy r;
1699 printf("\nTesting QueryInfoPolicy\n");
1701 for (i=1;i<13;i++) {
1702 r.in.handle = handle;
1705 printf("\ntrying QueryInfoPolicy level %d\n", i);
1707 status = dcerpc_lsa_QueryInfoPolicy(p, mem_ctx, &r);
1709 if ((i == 9 || i == 10 || i == 11) &&
1710 NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
1711 printf("server failed level %u (OK)\n", i);
1715 if (!NT_STATUS_IS_OK(status)) {
1716 printf("QueryInfoPolicy failed - %s\n", nt_errstr(status));
1725 static BOOL test_QueryInfoPolicy2(struct dcerpc_pipe *p,
1726 TALLOC_CTX *mem_ctx,
1727 struct policy_handle *handle)
1729 struct lsa_QueryInfoPolicy2 r;
1733 printf("\nTesting QueryInfoPolicy2\n");
1735 for (i=1;i<13;i++) {
1736 r.in.handle = handle;
1739 printf("\ntrying QueryInfoPolicy2 level %d\n", i);
1741 status = dcerpc_lsa_QueryInfoPolicy2(p, mem_ctx, &r);
1743 if ((i == 9 || i == 10 || i == 11) &&
1744 NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
1745 printf("server failed level %u (OK)\n", i);
1749 if (!NT_STATUS_IS_OK(status)) {
1750 printf("QueryInfoPolicy2 failed - %s\n", nt_errstr(status));
1759 static BOOL test_GetUserName(struct dcerpc_pipe *p,
1760 TALLOC_CTX *mem_ctx,
1761 struct policy_handle *handle)
1763 struct lsa_GetUserName r;
1766 struct lsa_StringPointer authority_name_p;
1768 printf("\nTesting GetUserName\n");
1770 r.in.system_name = "\\";
1771 r.in.account_name = NULL;
1772 r.in.authority_name = &authority_name_p;
1773 authority_name_p.string = NULL;
1775 status = dcerpc_lsa_GetUserName(p, mem_ctx, &r);
1777 if (!NT_STATUS_IS_OK(status)) {
1778 printf("GetUserName failed - %s\n", nt_errstr(status));
1785 BOOL test_lsa_Close(struct dcerpc_pipe *p,
1786 TALLOC_CTX *mem_ctx,
1787 struct policy_handle *handle)
1791 struct policy_handle handle2;
1793 printf("\ntesting Close\n");
1795 r.in.handle = handle;
1796 r.out.handle = &handle2;
1798 status = dcerpc_lsa_Close(p, mem_ctx, &r);
1799 if (!NT_STATUS_IS_OK(status)) {
1800 printf("Close failed - %s\n", nt_errstr(status));
1804 status = dcerpc_lsa_Close(p, mem_ctx, &r);
1805 /* its really a fault - we need a status code for rpc fault */
1806 if (!NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
1807 printf("Close failed - %s\n", nt_errstr(status));
1816 BOOL torture_rpc_lsa(void)
1819 struct dcerpc_pipe *p;
1820 TALLOC_CTX *mem_ctx;
1822 struct policy_handle *handle;
1824 mem_ctx = talloc_init("torture_rpc_lsa");
1826 status = torture_rpc_connection(mem_ctx, &p, &dcerpc_table_lsarpc);
1827 if (!NT_STATUS_IS_OK(status)) {
1828 talloc_free(mem_ctx);
1832 if (!test_OpenPolicy(p, mem_ctx)) {
1836 if (!test_lsa_OpenPolicy2(p, mem_ctx, &handle)) {
1841 if (!test_LookupSids_async(p, mem_ctx, handle)) {
1845 if (!test_QueryDomainInfoPolicy(p, mem_ctx, handle)) {
1849 if (!test_CreateAccount(p, mem_ctx, handle)) {
1853 if (!test_CreateSecret(p, mem_ctx, handle)) {
1857 if (!test_CreateTrustedDomain(p, mem_ctx, handle)) {
1861 if (!test_EnumAccounts(p, mem_ctx, handle)) {
1865 if (!test_EnumPrivs(p, mem_ctx, handle)) {
1869 if (!test_QueryInfoPolicy(p, mem_ctx, handle)) {
1873 if (!test_QueryInfoPolicy2(p, mem_ctx, handle)) {
1877 if (!test_GetUserName(p, mem_ctx, handle)) {
1882 if (!test_Delete(p, mem_ctx, handle)) {
1887 if (!test_many_LookupSids(p, mem_ctx, handle)) {
1891 if (!test_lsa_Close(p, mem_ctx, handle)) {
1895 if (!test_many_LookupSids(p, mem_ctx, handle)) {
1900 talloc_free(mem_ctx);