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 "lib/events/events.h"
27 #include "libcli/security/proto.h"
28 #include "auth/credentials/credentials.h"
29 #include "libcli/auth/proto.h"
31 static void init_lsa_String(struct lsa_String *name, const char *s)
36 static BOOL test_OpenPolicy(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
38 struct lsa_ObjectAttribute attr;
39 struct policy_handle handle;
40 struct lsa_QosInfo qos;
41 struct lsa_OpenPolicy r;
43 uint16_t system_name = '\\';
45 printf("\ntesting OpenPolicy\n");
48 qos.impersonation_level = 2;
50 qos.effective_only = 0;
54 attr.object_name = NULL;
59 r.in.system_name = &system_name;
61 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
62 r.out.handle = &handle;
64 status = dcerpc_lsa_OpenPolicy(p, mem_ctx, &r);
65 if (!NT_STATUS_IS_OK(status)) {
66 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
67 NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
68 printf("not considering %s to be an error\n", nt_errstr(status));
71 printf("OpenPolicy failed - %s\n", nt_errstr(status));
79 BOOL test_lsa_OpenPolicy2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
80 struct policy_handle **handle)
82 struct lsa_ObjectAttribute attr;
83 struct lsa_QosInfo qos;
84 struct lsa_OpenPolicy2 r;
87 printf("\ntesting OpenPolicy2\n");
89 *handle = talloc(mem_ctx, struct policy_handle);
95 qos.impersonation_level = 2;
97 qos.effective_only = 0;
100 attr.root_dir = NULL;
101 attr.object_name = NULL;
103 attr.sec_desc = NULL;
106 r.in.system_name = "\\";
108 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
109 r.out.handle = *handle;
111 status = dcerpc_lsa_OpenPolicy2(p, mem_ctx, &r);
112 if (!NT_STATUS_IS_OK(status)) {
113 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
114 NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
115 printf("not considering %s to be an error\n", nt_errstr(status));
116 talloc_free(*handle);
120 printf("OpenPolicy2 failed - %s\n", nt_errstr(status));
127 static BOOL test_LookupNames(struct dcerpc_pipe *p,
129 struct policy_handle *handle,
130 struct lsa_TransNameArray *tnames)
132 struct lsa_LookupNames r;
133 struct lsa_TransSidArray sids;
134 struct lsa_String *names;
139 printf("\nTesting LookupNames with %d names\n", tnames->count);
144 names = talloc_array(mem_ctx, struct lsa_String, tnames->count);
145 for (i=0;i<tnames->count;i++) {
146 init_lsa_String(&names[i], tnames->names[i].name.string);
149 r.in.handle = handle;
150 r.in.num_names = tnames->count;
155 r.out.count = &count;
158 status = dcerpc_lsa_LookupNames(p, mem_ctx, &r);
159 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
160 printf("LookupNames failed - %s\n", nt_errstr(status));
169 static BOOL test_LookupNames2(struct dcerpc_pipe *p,
171 struct policy_handle *handle,
172 struct lsa_TransNameArray2 *tnames)
174 struct lsa_LookupNames2 r;
175 struct lsa_TransSidArray2 sids;
176 struct lsa_String *names;
181 printf("\nTesting LookupNames2 with %d names\n", tnames->count);
186 names = talloc_array(mem_ctx, struct lsa_String, tnames->count);
187 for (i=0;i<tnames->count;i++) {
188 init_lsa_String(&names[i], tnames->names[i].name.string);
191 r.in.handle = handle;
192 r.in.num_names = tnames->count;
199 r.out.count = &count;
202 status = dcerpc_lsa_LookupNames2(p, mem_ctx, &r);
203 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
204 printf("LookupNames2 failed - %s\n", nt_errstr(status));
214 static BOOL test_LookupNames3(struct dcerpc_pipe *p,
216 struct policy_handle *handle,
217 struct lsa_TransNameArray2 *tnames)
219 struct lsa_LookupNames3 r;
220 struct lsa_TransSidArray3 sids;
221 struct lsa_String *names;
226 printf("\nTesting LookupNames3 with %d names\n", tnames->count);
231 names = talloc_array(mem_ctx, struct lsa_String, tnames->count);
232 for (i=0;i<tnames->count;i++) {
233 init_lsa_String(&names[i], tnames->names[i].name.string);
236 r.in.handle = handle;
237 r.in.num_names = tnames->count;
244 r.out.count = &count;
247 status = dcerpc_lsa_LookupNames3(p, mem_ctx, &r);
248 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
249 printf("LookupNames3 failed - %s\n", nt_errstr(status));
258 static BOOL test_LookupNames4(struct dcerpc_pipe *p,
260 struct lsa_TransNameArray2 *tnames)
262 struct lsa_LookupNames4 r;
263 struct lsa_TransSidArray3 sids;
264 struct lsa_String *names;
269 printf("\nTesting LookupNames4 with %d names\n", tnames->count);
274 names = talloc_array(mem_ctx, struct lsa_String, tnames->count);
275 for (i=0;i<tnames->count;i++) {
276 init_lsa_String(&names[i], tnames->names[i].name.string);
279 r.in.num_names = tnames->count;
286 r.out.count = &count;
289 status = dcerpc_lsa_LookupNames4(p, mem_ctx, &r);
290 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
291 printf("LookupNames4 failed - %s\n", nt_errstr(status));
301 static BOOL test_LookupSids(struct dcerpc_pipe *p,
303 struct policy_handle *handle,
304 struct lsa_SidArray *sids)
306 struct lsa_LookupSids r;
307 struct lsa_TransNameArray names;
308 uint32_t count = sids->num_sids;
311 printf("\nTesting LookupSids\n");
316 r.in.handle = handle;
321 r.out.count = &count;
322 r.out.names = &names;
324 status = dcerpc_lsa_LookupSids(p, mem_ctx, &r);
325 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
326 printf("LookupSids failed - %s\n", nt_errstr(status));
332 if (!test_LookupNames(p, mem_ctx, handle, &names)) {
340 static BOOL test_LookupSids2(struct dcerpc_pipe *p,
342 struct policy_handle *handle,
343 struct lsa_SidArray *sids)
345 struct lsa_LookupSids2 r;
346 struct lsa_TransNameArray2 names;
347 uint32_t count = sids->num_sids;
350 printf("\nTesting LookupSids2\n");
355 r.in.handle = handle;
362 r.out.count = &count;
363 r.out.names = &names;
365 status = dcerpc_lsa_LookupSids2(p, mem_ctx, &r);
366 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
367 printf("LookupSids2 failed - %s\n", nt_errstr(status));
373 if (!test_LookupNames2(p, mem_ctx, handle, &names)) {
377 if (!test_LookupNames3(p, mem_ctx, handle, &names)) {
384 static BOOL test_LookupSids3(struct dcerpc_pipe *p,
386 struct lsa_SidArray *sids)
388 struct lsa_LookupSids3 r;
389 struct lsa_TransNameArray2 names;
390 uint32_t count = sids->num_sids;
393 printf("\nTesting LookupSids3\n");
404 r.out.count = &count;
405 r.out.names = &names;
407 status = dcerpc_lsa_LookupSids3(p, mem_ctx, &r);
408 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
409 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
410 NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
411 printf("not considering %s to be an error\n", nt_errstr(status));
414 printf("LookupSids3 failed - %s - not considered an error\n",
421 if (!test_LookupNames4(p, mem_ctx, &names)) {
428 BOOL test_many_LookupSids(struct dcerpc_pipe *p,
430 struct policy_handle *handle)
434 struct lsa_SidArray sids;
437 printf("\nTesting LookupSids with lots of SIDs\n");
441 sids.sids = talloc_array(mem_ctx, struct lsa_SidPtr, sids.num_sids);
443 for (i=0; i<sids.num_sids; i++) {
444 const char *sidstr = "S-1-5-32-545";
445 sids.sids[i].sid = dom_sid_parse_talloc(mem_ctx, sidstr);
448 count = sids.num_sids;
451 struct lsa_LookupSids r;
452 struct lsa_TransNameArray names;
456 r.in.handle = handle;
460 r.in.count = &names.count;
461 r.out.count = &count;
462 r.out.names = &names;
464 status = dcerpc_lsa_LookupSids(p, mem_ctx, &r);
465 if (!NT_STATUS_IS_OK(status) &&
466 !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
467 printf("LookupSids failed - %s\n", nt_errstr(status));
473 if (!test_LookupNames(p, mem_ctx, handle, &names)) {
477 struct lsa_LookupSids3 r;
478 struct lsa_TransNameArray2 names;
483 printf("\nTesting LookupSids3\n");
491 r.out.count = &count;
492 r.out.names = &names;
494 status = dcerpc_lsa_LookupSids3(p, mem_ctx, &r);
495 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
496 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) ||
497 NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
498 printf("not considering %s to be an error\n", nt_errstr(status));
501 printf("LookupSids3 failed - %s\n",
505 if (!test_LookupNames4(p, mem_ctx, &names)) {
517 #define NUM_ASYNC_REQUESTS 1000
519 static void lookupsids_cb(struct rpc_request *req)
521 int *replies = (int *)req->async.private;
524 status = dcerpc_ndr_request_recv(req);
525 DEBUG(3, ("lookupsids returned %s\n", nt_errstr(status)));
526 if (!NT_STATUS_IS_OK(status)) {
533 static BOOL test_LookupSids_async(struct dcerpc_pipe *p,
535 struct policy_handle *handle)
537 struct lsa_SidArray sids;
538 struct lsa_SidPtr sidptr;
540 uint32_t count[NUM_ASYNC_REQUESTS];
541 struct lsa_TransNameArray names[NUM_ASYNC_REQUESTS];
542 struct lsa_LookupSids r[NUM_ASYNC_REQUESTS];
543 struct rpc_request **req;
548 printf("\nTesting %d async lookupsids request\n", 100);
550 req = talloc_array(mem_ctx, struct rpc_request *, NUM_ASYNC_REQUESTS);
554 sidptr.sid = dom_sid_parse_talloc(mem_ctx, "S-1-5-32-545");
558 for (i=0; i<NUM_ASYNC_REQUESTS; i++) {
561 names[i].names = NULL;
563 r[i].in.handle = handle;
564 r[i].in.sids = &sids;
565 r[i].in.names = &names[i];
567 r[i].in.count = &names[i].count;
568 r[i].out.count = &count[i];
569 r[i].out.names = &names[i];
571 req[i] = dcerpc_lsa_LookupSids_send(p, req, &r[i]);
572 if (req[i] == NULL) {
577 req[i]->async.callback = lookupsids_cb;
578 req[i]->async.private = &replies;
581 while (replies < NUM_ASYNC_REQUESTS) {
582 event_loop_once(p->conn->event_ctx);
594 static BOOL test_LookupPrivValue(struct dcerpc_pipe *p,
596 struct policy_handle *handle,
597 struct lsa_String *name)
600 struct lsa_LookupPrivValue r;
601 struct lsa_LUID luid;
603 r.in.handle = handle;
607 status = dcerpc_lsa_LookupPrivValue(p, mem_ctx, &r);
608 if (!NT_STATUS_IS_OK(status)) {
609 printf("\nLookupPrivValue failed - %s\n", nt_errstr(status));
616 static BOOL test_LookupPrivName(struct dcerpc_pipe *p,
618 struct policy_handle *handle,
619 struct lsa_LUID *luid)
622 struct lsa_LookupPrivName r;
624 r.in.handle = handle;
627 status = dcerpc_lsa_LookupPrivName(p, mem_ctx, &r);
628 if (!NT_STATUS_IS_OK(status)) {
629 printf("\nLookupPrivName failed - %s\n", nt_errstr(status));
636 static BOOL test_RemovePrivilegesFromAccount(struct dcerpc_pipe *p,
638 struct policy_handle *acct_handle,
639 struct lsa_LUID *luid)
642 struct lsa_RemovePrivilegesFromAccount r;
643 struct lsa_PrivilegeSet privs;
646 printf("Testing RemovePrivilegesFromAccount\n");
648 r.in.handle = acct_handle;
654 privs.set = talloc_array(mem_ctx, struct lsa_LUIDAttribute, 1);
655 privs.set[0].luid = *luid;
656 privs.set[0].attribute = 0;
658 status = dcerpc_lsa_RemovePrivilegesFromAccount(p, mem_ctx, &r);
659 if (!NT_STATUS_IS_OK(status)) {
660 printf("RemovePrivilegesFromAccount failed - %s\n", nt_errstr(status));
667 static BOOL test_AddPrivilegesToAccount(struct dcerpc_pipe *p,
669 struct policy_handle *acct_handle,
670 struct lsa_LUID *luid)
673 struct lsa_AddPrivilegesToAccount r;
674 struct lsa_PrivilegeSet privs;
677 printf("Testing AddPrivilegesToAccount\n");
679 r.in.handle = acct_handle;
684 privs.set = talloc_array(mem_ctx, struct lsa_LUIDAttribute, 1);
685 privs.set[0].luid = *luid;
686 privs.set[0].attribute = 0;
688 status = dcerpc_lsa_AddPrivilegesToAccount(p, mem_ctx, &r);
689 if (!NT_STATUS_IS_OK(status)) {
690 printf("AddPrivilegesToAccount failed - %s\n", nt_errstr(status));
697 static BOOL test_EnumPrivsAccount(struct dcerpc_pipe *p,
699 struct policy_handle *handle,
700 struct policy_handle *acct_handle)
703 struct lsa_EnumPrivsAccount r;
706 printf("Testing EnumPrivsAccount\n");
708 r.in.handle = acct_handle;
710 status = dcerpc_lsa_EnumPrivsAccount(p, mem_ctx, &r);
711 if (!NT_STATUS_IS_OK(status)) {
712 printf("EnumPrivsAccount failed - %s\n", nt_errstr(status));
716 if (r.out.privs && r.out.privs->count > 0) {
718 for (i=0;i<r.out.privs->count;i++) {
719 test_LookupPrivName(p, mem_ctx, handle,
720 &r.out.privs->set[i].luid);
723 ret &= test_RemovePrivilegesFromAccount(p, mem_ctx, acct_handle,
724 &r.out.privs->set[0].luid);
725 ret &= test_AddPrivilegesToAccount(p, mem_ctx, acct_handle,
726 &r.out.privs->set[0].luid);
732 static BOOL test_Delete(struct dcerpc_pipe *p,
734 struct policy_handle *handle)
739 printf("testing Delete\n");
741 r.in.handle = handle;
742 status = dcerpc_lsa_Delete(p, mem_ctx, &r);
743 if (!NT_STATUS_IS_OK(status)) {
744 printf("Delete failed - %s\n", nt_errstr(status));
752 static BOOL test_CreateAccount(struct dcerpc_pipe *p,
754 struct policy_handle *handle)
757 struct lsa_CreateAccount r;
758 struct dom_sid2 *newsid;
759 struct policy_handle acct_handle;
761 newsid = dom_sid_parse_talloc(mem_ctx, "S-1-5-12349876-4321-2854");
763 printf("Testing CreateAccount\n");
765 r.in.handle = handle;
767 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
768 r.out.acct_handle = &acct_handle;
770 status = dcerpc_lsa_CreateAccount(p, mem_ctx, &r);
771 if (!NT_STATUS_IS_OK(status)) {
772 printf("CreateAccount failed - %s\n", nt_errstr(status));
776 if (!test_Delete(p, mem_ctx, &acct_handle)) {
783 static BOOL test_DeleteTrustedDomain(struct dcerpc_pipe *p,
785 struct policy_handle *handle,
786 struct lsa_StringLarge name)
789 struct lsa_OpenTrustedDomainByName r;
790 struct policy_handle trustdom_handle;
792 r.in.handle = handle;
793 r.in.name.string = name.string;
794 r.in.access_mask = SEC_STD_DELETE;
795 r.out.trustdom_handle = &trustdom_handle;
797 status = dcerpc_lsa_OpenTrustedDomainByName(p, mem_ctx, &r);
798 if (!NT_STATUS_IS_OK(status)) {
799 printf("lsa_OpenTrustedDomainByName failed - %s\n", nt_errstr(status));
803 if (!test_Delete(p, mem_ctx, &trustdom_handle)) {
811 static BOOL test_CreateSecret(struct dcerpc_pipe *p,
813 struct policy_handle *handle)
816 struct lsa_CreateSecret r;
817 struct lsa_OpenSecret r2;
818 struct lsa_SetSecret r3;
819 struct lsa_QuerySecret r4;
820 struct lsa_SetSecret r5;
821 struct lsa_QuerySecret r6;
822 struct lsa_SetSecret r7;
823 struct lsa_QuerySecret r8;
824 struct policy_handle sec_handle, sec_handle2, sec_handle3;
826 struct lsa_DATA_BUF buf1;
827 struct lsa_DATA_BUF_PTR bufp1;
828 struct lsa_DATA_BUF_PTR bufp2;
831 DATA_BLOB session_key;
832 NTTIME old_mtime, new_mtime;
833 DATA_BLOB blob1, blob2;
834 const char *secret1 = "abcdef12345699qwerty";
836 const char *secret3 = "ABCDEF12345699QWERTY";
838 const char *secret5 = "NEW-SAMBA4-SECRET";
843 const int GLOBAL = 1;
845 secname[LOCAL] = talloc_asprintf(mem_ctx, "torturesecret-%u", (uint_t)random());
846 secname[GLOBAL] = talloc_asprintf(mem_ctx, "G$torturesecret-%u", (uint_t)random());
848 for (i=0; i< 2; i++) {
849 printf("Testing CreateSecret of %s\n", secname[i]);
851 init_lsa_String(&r.in.name, secname[i]);
853 r.in.handle = handle;
854 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
855 r.out.sec_handle = &sec_handle;
857 status = dcerpc_lsa_CreateSecret(p, mem_ctx, &r);
858 if (!NT_STATUS_IS_OK(status)) {
859 printf("CreateSecret failed - %s\n", nt_errstr(status));
863 r.in.handle = handle;
864 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
865 r.out.sec_handle = &sec_handle3;
867 status = dcerpc_lsa_CreateSecret(p, mem_ctx, &r);
868 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
869 printf("CreateSecret should have failed OBJECT_NAME_COLLISION - %s\n", nt_errstr(status));
873 r2.in.handle = handle;
874 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
875 r2.in.name = r.in.name;
876 r2.out.sec_handle = &sec_handle2;
878 printf("Testing OpenSecret\n");
880 status = dcerpc_lsa_OpenSecret(p, mem_ctx, &r2);
881 if (!NT_STATUS_IS_OK(status)) {
882 printf("OpenSecret failed - %s\n", nt_errstr(status));
886 status = dcerpc_fetch_session_key(p, &session_key);
887 if (!NT_STATUS_IS_OK(status)) {
888 printf("dcerpc_fetch_session_key failed - %s\n", nt_errstr(status));
892 enc_key = sess_encrypt_string(secret1, &session_key);
894 r3.in.sec_handle = &sec_handle;
895 r3.in.new_val = &buf1;
896 r3.in.old_val = NULL;
897 r3.in.new_val->data = enc_key.data;
898 r3.in.new_val->length = enc_key.length;
899 r3.in.new_val->size = enc_key.length;
901 printf("Testing SetSecret\n");
903 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r3);
904 if (!NT_STATUS_IS_OK(status)) {
905 printf("SetSecret failed - %s\n", nt_errstr(status));
909 r3.in.sec_handle = &sec_handle;
910 r3.in.new_val = &buf1;
911 r3.in.old_val = NULL;
912 r3.in.new_val->data = enc_key.data;
913 r3.in.new_val->length = enc_key.length;
914 r3.in.new_val->size = enc_key.length;
916 /* break the encrypted data */
919 printf("Testing SetSecret with broken key\n");
921 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r3);
922 if (!NT_STATUS_EQUAL(status, NT_STATUS_UNKNOWN_REVISION)) {
923 printf("SetSecret should have failed UNKNOWN_REVISION - %s\n", nt_errstr(status));
927 data_blob_free(&enc_key);
929 ZERO_STRUCT(new_mtime);
930 ZERO_STRUCT(old_mtime);
932 /* fetch the secret back again */
933 r4.in.sec_handle = &sec_handle;
934 r4.in.new_val = &bufp1;
935 r4.in.new_mtime = &new_mtime;
936 r4.in.old_val = NULL;
937 r4.in.old_mtime = NULL;
941 printf("Testing QuerySecret\n");
942 status = dcerpc_lsa_QuerySecret(p, mem_ctx, &r4);
943 if (!NT_STATUS_IS_OK(status)) {
944 printf("QuerySecret failed - %s\n", nt_errstr(status));
947 if (r4.out.new_val == NULL || r4.out.new_val->buf == NULL) {
948 printf("No secret buffer returned\n");
951 blob1.data = r4.out.new_val->buf->data;
952 blob1.length = r4.out.new_val->buf->size;
954 blob2 = data_blob_talloc(mem_ctx, NULL, blob1.length);
956 secret2 = sess_decrypt_string(&blob1, &session_key);
958 if (strcmp(secret1, secret2) != 0) {
959 printf("Returned secret '%s' doesn't match '%s'\n",
966 enc_key = sess_encrypt_string(secret3, &session_key);
968 r5.in.sec_handle = &sec_handle;
969 r5.in.new_val = &buf1;
970 r5.in.old_val = NULL;
971 r5.in.new_val->data = enc_key.data;
972 r5.in.new_val->length = enc_key.length;
973 r5.in.new_val->size = enc_key.length;
975 printf("Testing SetSecret (existing value should move to old)\n");
977 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r5);
978 if (!NT_STATUS_IS_OK(status)) {
979 printf("SetSecret failed - %s\n", nt_errstr(status));
983 data_blob_free(&enc_key);
985 ZERO_STRUCT(new_mtime);
986 ZERO_STRUCT(old_mtime);
988 /* fetch the secret back again */
989 r6.in.sec_handle = &sec_handle;
990 r6.in.new_val = &bufp1;
991 r6.in.new_mtime = &new_mtime;
992 r6.in.old_val = &bufp2;
993 r6.in.old_mtime = &old_mtime;
998 status = dcerpc_lsa_QuerySecret(p, mem_ctx, &r6);
999 if (!NT_STATUS_IS_OK(status)) {
1000 printf("QuerySecret failed - %s\n", nt_errstr(status));
1005 if (r6.out.new_val->buf == NULL || r6.out.old_val->buf == NULL
1006 || r6.out.new_mtime == NULL || r6.out.old_mtime == NULL) {
1007 printf("Both secret buffers and both times not returned\n");
1011 blob1.data = r6.out.new_val->buf->data;
1012 blob1.length = r6.out.new_val->buf->size;
1014 blob2 = data_blob_talloc(mem_ctx, NULL, blob1.length);
1016 secret4 = sess_decrypt_string(&blob1, &session_key);
1018 if (strcmp(secret3, secret4) != 0) {
1019 printf("Returned NEW secret %s doesn't match %s\n", secret4, secret3);
1023 blob1.data = r6.out.old_val->buf->data;
1024 blob1.length = r6.out.old_val->buf->length;
1026 blob2 = data_blob_talloc(mem_ctx, NULL, blob1.length);
1028 secret2 = sess_decrypt_string(&blob1, &session_key);
1030 if (strcmp(secret1, secret2) != 0) {
1031 printf("Returned OLD secret %s doesn't match %s\n", secret2, secret1);
1035 if (*r6.out.new_mtime == *r6.out.old_mtime) {
1036 printf("Returned secret %s had same mtime for both secrets: %s\n",
1038 nt_time_string(mem_ctx, *r6.out.new_mtime));
1044 enc_key = sess_encrypt_string(secret5, &session_key);
1046 r7.in.sec_handle = &sec_handle;
1047 r7.in.old_val = &buf1;
1048 r7.in.old_val->data = enc_key.data;
1049 r7.in.old_val->length = enc_key.length;
1050 r7.in.old_val->size = enc_key.length;
1051 r7.in.new_val = NULL;
1053 printf("Testing SetSecret of old Secret only\n");
1055 status = dcerpc_lsa_SetSecret(p, mem_ctx, &r7);
1056 if (!NT_STATUS_IS_OK(status)) {
1057 printf("SetSecret failed - %s\n", nt_errstr(status));
1061 data_blob_free(&enc_key);
1063 /* fetch the secret back again */
1064 r8.in.sec_handle = &sec_handle;
1065 r8.in.new_val = &bufp1;
1066 r8.in.new_mtime = &new_mtime;
1067 r8.in.old_val = &bufp2;
1068 r8.in.old_mtime = &old_mtime;
1073 status = dcerpc_lsa_QuerySecret(p, mem_ctx, &r8);
1074 if (!NT_STATUS_IS_OK(status)) {
1075 printf("QuerySecret failed - %s\n", nt_errstr(status));
1078 if (!r8.out.new_val || !r8.out.old_val) {
1079 printf("in/out pointers not returned, despite being set on in for QuerySecret\n");
1081 } else if (r8.out.new_val->buf == NULL) {
1083 printf("NEW secret buffer not returned after GLOBAL OLD set\n");
1086 } else if (r8.out.old_val->buf == NULL) {
1087 printf("OLD secret buffer not returned after OLD set\n");
1089 } else if (r8.out.new_mtime == NULL || r8.out.old_mtime == NULL) {
1090 printf("Both times not returned after OLD set\n");
1094 printf("NEW secret buffer should not be returned after LOCAL OLD set\n");
1097 blob1.data = r8.out.new_val->buf->data;
1098 blob1.length = r8.out.new_val->buf->length;
1100 blob2 = data_blob_talloc(mem_ctx, NULL, blob1.length);
1102 secret6 = sess_decrypt_string(&blob1, &session_key);
1104 if (strcmp(secret3, secret4) != 0) {
1105 printf("Returned NEW secret '%s' doesn't match '%s'\n", secret4, secret3);
1109 blob1.data = r8.out.old_val->buf->data;
1110 blob1.length = r8.out.old_val->buf->size;
1112 blob2 = data_blob_talloc(mem_ctx, NULL, blob1.length);
1114 secret6 = sess_decrypt_string(&blob1, &session_key);
1116 if (strcmp(secret5, secret6) != 0) {
1117 printf("Returned OLD secret %s doesn't match %s\n", secret5, secret6);
1121 if (*r8.out.new_mtime == *r8.out.old_mtime) {
1123 printf("Returned secret %s had same mtime for both secrets: %s\n",
1125 nt_time_string(mem_ctx, *r8.out.new_mtime));
1129 printf("Returned secret %s should have had same mtime for both secrets: %s != %s\n",
1131 nt_time_string(mem_ctx, *r8.out.old_mtime),
1132 nt_time_string(mem_ctx, *r8.out.new_mtime));
1138 if (!test_Delete(p, mem_ctx, &sec_handle)) {
1142 d.in.handle = &sec_handle2;
1143 status = dcerpc_lsa_Delete(p, mem_ctx, &d);
1144 if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
1145 printf("Second delete expected INVALID_HANDLE - %s\n", nt_errstr(status));
1149 printf("Testing OpenSecret of just-deleted secret\n");
1151 status = dcerpc_lsa_OpenSecret(p, mem_ctx, &r2);
1152 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
1153 printf("OpenSecret expected OBJECT_NAME_NOT_FOUND - %s\n", nt_errstr(status));
1164 static BOOL test_EnumAccountRights(struct dcerpc_pipe *p,
1165 TALLOC_CTX *mem_ctx,
1166 struct policy_handle *acct_handle,
1167 struct dom_sid *sid)
1170 struct lsa_EnumAccountRights r;
1171 struct lsa_RightSet rights;
1173 printf("Testing EnumAccountRights\n");
1175 r.in.handle = acct_handle;
1177 r.out.rights = &rights;
1179 status = dcerpc_lsa_EnumAccountRights(p, mem_ctx, &r);
1180 if (!NT_STATUS_IS_OK(status)) {
1181 printf("EnumAccountRights failed - %s\n", nt_errstr(status));
1189 static BOOL test_QuerySecurity(struct dcerpc_pipe *p,
1190 TALLOC_CTX *mem_ctx,
1191 struct policy_handle *handle,
1192 struct policy_handle *acct_handle)
1195 struct lsa_QuerySecurity r;
1197 printf("Testing QuerySecurity\n");
1199 r.in.handle = acct_handle;
1202 status = dcerpc_lsa_QuerySecurity(p, mem_ctx, &r);
1203 if (!NT_STATUS_IS_OK(status)) {
1204 printf("QuerySecurity failed - %s\n", nt_errstr(status));
1211 static BOOL test_OpenAccount(struct dcerpc_pipe *p,
1212 TALLOC_CTX *mem_ctx,
1213 struct policy_handle *handle,
1214 struct dom_sid *sid)
1217 struct lsa_OpenAccount r;
1218 struct policy_handle acct_handle;
1220 printf("Testing OpenAccount\n");
1222 r.in.handle = handle;
1224 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1225 r.out.acct_handle = &acct_handle;
1227 status = dcerpc_lsa_OpenAccount(p, mem_ctx, &r);
1228 if (!NT_STATUS_IS_OK(status)) {
1229 printf("OpenAccount failed - %s\n", nt_errstr(status));
1233 if (!test_EnumPrivsAccount(p, mem_ctx, handle, &acct_handle)) {
1237 if (!test_QuerySecurity(p, mem_ctx, handle, &acct_handle)) {
1244 static BOOL test_EnumAccounts(struct dcerpc_pipe *p,
1245 TALLOC_CTX *mem_ctx,
1246 struct policy_handle *handle)
1249 struct lsa_EnumAccounts r;
1250 struct lsa_SidArray sids1, sids2;
1251 uint32_t resume_handle = 0;
1254 printf("\ntesting EnumAccounts\n");
1256 r.in.handle = handle;
1257 r.in.resume_handle = &resume_handle;
1258 r.in.num_entries = 100;
1259 r.out.resume_handle = &resume_handle;
1260 r.out.sids = &sids1;
1264 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
1265 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
1268 if (!NT_STATUS_IS_OK(status)) {
1269 printf("EnumAccounts failed - %s\n", nt_errstr(status));
1273 if (!test_LookupSids(p, mem_ctx, handle, &sids1)) {
1277 if (!test_LookupSids2(p, mem_ctx, handle, &sids1)) {
1281 if (!test_LookupSids3(p, mem_ctx, &sids1)) {
1285 printf("testing all accounts\n");
1286 for (i=0;i<sids1.num_sids;i++) {
1287 test_OpenAccount(p, mem_ctx, handle, sids1.sids[i].sid);
1288 test_EnumAccountRights(p, mem_ctx, handle, sids1.sids[i].sid);
1293 if (sids1.num_sids < 3) {
1297 printf("trying EnumAccounts partial listing (asking for 1 at 2)\n");
1299 r.in.num_entries = 1;
1300 r.out.sids = &sids2;
1302 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
1303 if (!NT_STATUS_IS_OK(status)) {
1304 printf("EnumAccounts failed - %s\n", nt_errstr(status));
1308 if (sids2.num_sids != 1) {
1309 printf("Returned wrong number of entries (%d)\n", sids2.num_sids);
1316 static BOOL test_LookupPrivDisplayName(struct dcerpc_pipe *p,
1317 TALLOC_CTX *mem_ctx,
1318 struct policy_handle *handle,
1319 struct lsa_String *priv_name)
1321 struct lsa_LookupPrivDisplayName r;
1323 /* produce a reasonable range of language output without screwing up
1325 uint16_t language_id = (random() % 4) + 0x409;
1327 printf("testing LookupPrivDisplayName(%s)\n", priv_name->string);
1329 r.in.handle = handle;
1330 r.in.name = priv_name;
1331 r.in.language_id = &language_id;
1332 r.out.language_id = &language_id;
1335 status = dcerpc_lsa_LookupPrivDisplayName(p, mem_ctx, &r);
1336 if (!NT_STATUS_IS_OK(status)) {
1337 printf("LookupPrivDisplayName failed - %s\n", nt_errstr(status));
1340 printf("%s -> \"%s\" (language 0x%x/0x%x)\n",
1341 priv_name->string, r.out.disp_name->string,
1342 *r.in.language_id, *r.out.language_id);
1347 static BOOL test_EnumAccountsWithUserRight(struct dcerpc_pipe *p,
1348 TALLOC_CTX *mem_ctx,
1349 struct policy_handle *handle,
1350 struct lsa_String *priv_name)
1352 struct lsa_EnumAccountsWithUserRight r;
1353 struct lsa_SidArray sids;
1358 printf("testing EnumAccountsWithUserRight(%s)\n", priv_name->string);
1360 r.in.handle = handle;
1361 r.in.name = priv_name;
1364 status = dcerpc_lsa_EnumAccountsWithUserRight(p, mem_ctx, &r);
1366 /* NT_STATUS_NO_MORE_ENTRIES means noone has this privilege */
1367 if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
1371 if (!NT_STATUS_IS_OK(status)) {
1372 printf("EnumAccountsWithUserRight failed - %s\n", nt_errstr(status));
1380 static BOOL test_EnumPrivs(struct dcerpc_pipe *p,
1381 TALLOC_CTX *mem_ctx,
1382 struct policy_handle *handle)
1385 struct lsa_EnumPrivs r;
1386 struct lsa_PrivArray privs1;
1387 uint32_t resume_handle = 0;
1391 printf("\ntesting EnumPrivs\n");
1393 r.in.handle = handle;
1394 r.in.resume_handle = &resume_handle;
1395 r.in.max_count = 100;
1396 r.out.resume_handle = &resume_handle;
1397 r.out.privs = &privs1;
1400 status = dcerpc_lsa_EnumPrivs(p, mem_ctx, &r);
1401 if (!NT_STATUS_IS_OK(status)) {
1402 printf("EnumPrivs failed - %s\n", nt_errstr(status));
1406 for (i = 0; i< privs1.count; i++) {
1407 test_LookupPrivDisplayName(p, mem_ctx, handle, (struct lsa_String *)&privs1.privs[i].name);
1408 test_LookupPrivValue(p, mem_ctx, handle, (struct lsa_String *)&privs1.privs[i].name);
1409 if (!test_EnumAccountsWithUserRight(p, mem_ctx, handle, (struct lsa_String *)&privs1.privs[i].name)) {
1417 static BOOL test_query_each_TrustDom(struct dcerpc_pipe *p,
1418 TALLOC_CTX *mem_ctx,
1419 struct policy_handle *handle,
1420 struct lsa_DomainList *domains)
1426 printf("\nTesting OpenTrustedDomain, OpenTrustedDomainByName and QueryInfoTrustedDomain\n");
1427 for (i=0; i< domains->count; i++) {
1428 struct lsa_OpenTrustedDomain trust;
1429 struct lsa_OpenTrustedDomainByName trust_by_name;
1430 struct policy_handle trustdom_handle;
1431 struct policy_handle handle2;
1433 int levels [] = {1, 3, 6, 8, 12};
1435 if (domains->domains[i].sid) {
1436 trust.in.handle = handle;
1437 trust.in.sid = domains->domains[i].sid;
1438 trust.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1439 trust.out.trustdom_handle = &trustdom_handle;
1441 status = dcerpc_lsa_OpenTrustedDomain(p, mem_ctx, &trust);
1443 if (!NT_STATUS_IS_OK(status)) {
1444 printf("OpenTrustedDomain failed - %s\n", nt_errstr(status));
1448 c.in.handle = &trustdom_handle;
1449 c.out.handle = &handle2;
1451 for (j=0; j < ARRAY_SIZE(levels); j++) {
1452 struct lsa_QueryTrustedDomainInfo q;
1453 union lsa_TrustedDomainInfo info;
1454 q.in.trustdom_handle = &trustdom_handle;
1455 q.in.level = levels[j];
1457 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
1458 if (!NT_STATUS_IS_OK(status)) {
1459 printf("QueryTrustedDomainInfo level %d failed - %s\n",
1460 levels[j], nt_errstr(status));
1465 status = dcerpc_lsa_Close(p, mem_ctx, &c);
1466 if (!NT_STATUS_IS_OK(status)) {
1467 printf("Close of trusted domain failed - %s\n", nt_errstr(status));
1472 trust_by_name.in.handle = handle;
1473 trust_by_name.in.name.string = domains->domains[i].name.string;
1474 trust_by_name.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1475 trust_by_name.out.trustdom_handle = &trustdom_handle;
1477 status = dcerpc_lsa_OpenTrustedDomainByName(p, mem_ctx, &trust_by_name);
1479 if (!NT_STATUS_IS_OK(status)) {
1480 printf("OpenTrustedDomainByName failed - %s\n", nt_errstr(status));
1484 for (j=0; j < ARRAY_SIZE(levels); j++) {
1485 struct lsa_QueryTrustedDomainInfo q;
1486 union lsa_TrustedDomainInfo info;
1487 q.in.trustdom_handle = &trustdom_handle;
1488 q.in.level = levels[j];
1490 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
1491 if (!NT_STATUS_IS_OK(status)) {
1492 printf("QueryTrustedDomainInfo level %d failed - %s\n",
1493 levels[j], nt_errstr(status));
1498 c.in.handle = &trustdom_handle;
1499 c.out.handle = &handle2;
1501 status = dcerpc_lsa_Close(p, mem_ctx, &c);
1502 if (!NT_STATUS_IS_OK(status)) {
1503 printf("Close of trusted domain failed - %s\n", nt_errstr(status));
1507 for (j=0; j < ARRAY_SIZE(levels); j++) {
1508 struct lsa_QueryTrustedDomainInfoBySid q;
1509 union lsa_TrustedDomainInfo info;
1511 if (!domains->domains[i].sid) {
1515 q.in.handle = handle;
1516 q.in.dom_sid = domains->domains[i].sid;
1517 q.in.level = levels[j];
1519 status = dcerpc_lsa_QueryTrustedDomainInfoBySid(p, mem_ctx, &q);
1520 if (!NT_STATUS_IS_OK(status)) {
1521 printf("QueryTrustedDomainInfoBySid level %d failed - %s\n",
1522 levels[j], nt_errstr(status));
1527 for (j=0; j < ARRAY_SIZE(levels); j++) {
1528 struct lsa_QueryTrustedDomainInfoByName q;
1529 union lsa_TrustedDomainInfo info;
1530 q.in.handle = handle;
1531 q.in.trusted_domain.string = domains->domains[i].name.string;
1532 q.in.level = levels[j];
1534 status = dcerpc_lsa_QueryTrustedDomainInfoByName(p, mem_ctx, &q);
1535 if (!NT_STATUS_IS_OK(status)) {
1536 printf("QueryTrustedDomainInfoByName level %d failed - %s\n",
1537 levels[j], nt_errstr(status));
1545 static BOOL test_EnumTrustDom(struct dcerpc_pipe *p,
1546 TALLOC_CTX *mem_ctx,
1547 struct policy_handle *handle)
1549 struct lsa_EnumTrustDom r;
1550 NTSTATUS enum_status;
1551 uint32_t resume_handle = 0;
1552 struct lsa_DomainList domains;
1555 printf("\nTesting EnumTrustDom\n");
1558 r.in.handle = handle;
1559 r.in.resume_handle = &resume_handle;
1560 r.in.max_size = LSA_ENUM_TRUST_DOMAIN_MULTIPLIER * 3;
1561 r.out.domains = &domains;
1562 r.out.resume_handle = &resume_handle;
1564 enum_status = dcerpc_lsa_EnumTrustDom(p, mem_ctx, &r);
1566 /* NO_MORE_ENTRIES is allowed */
1567 if (NT_STATUS_EQUAL(enum_status, NT_STATUS_NO_MORE_ENTRIES)) {
1569 } else if (NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES)) {
1570 /* Windows 2003 gets this off by one on the first run */
1571 if (r.out.domains->count < 3 || r.out.domains->count > 4) {
1572 printf("EnumTrustDom didn't fill the buffer we "
1573 "asked it to (got %d, expected %d / %d == %d entries)\n",
1574 r.out.domains->count, LSA_ENUM_TRUST_DOMAIN_MULTIPLIER * 3,
1575 LSA_ENUM_TRUST_DOMAIN_MULTIPLIER, r.in.max_size);
1578 } else if (!NT_STATUS_IS_OK(enum_status)) {
1579 printf("EnumTrustDom failed - %s\n", nt_errstr(enum_status));
1583 ret &= test_query_each_TrustDom(p, mem_ctx, handle, &domains);
1585 } while ((NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES)));
1590 static BOOL test_CreateTrustedDomain(struct dcerpc_pipe *p,
1591 TALLOC_CTX *mem_ctx,
1592 struct policy_handle *handle)
1596 struct lsa_CreateTrustedDomain r;
1597 struct lsa_TrustInformation trustinfo;
1598 struct dom_sid *domsid[12];
1599 struct policy_handle trustdom_handle[12];
1600 struct lsa_QueryTrustedDomainInfo q;
1603 printf("Testing CreateTrustedDomain for 12 domains\n");
1605 for (i=0; i< 12; i++) {
1606 char *trust_name = talloc_asprintf(mem_ctx, "torturedom%02d", i);
1607 char *trust_sid = talloc_asprintf(mem_ctx, "S-1-5-21-97398-379795-100%02d", i);
1609 domsid[i] = dom_sid_parse_talloc(mem_ctx, trust_sid);
1611 trustinfo.sid = domsid[i];
1612 init_lsa_String((struct lsa_String *)&trustinfo.name, trust_name);
1614 r.in.handle = handle;
1615 r.in.info = &trustinfo;
1616 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
1617 r.out.trustdom_handle = &trustdom_handle[i];
1619 status = dcerpc_lsa_CreateTrustedDomain(p, mem_ctx, &r);
1620 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
1621 test_DeleteTrustedDomain(p, mem_ctx, handle, trustinfo.name);
1622 status = dcerpc_lsa_CreateTrustedDomain(p, mem_ctx, &r);
1624 if (!NT_STATUS_IS_OK(status)) {
1625 printf("CreateTrustedDomain failed - %s\n", nt_errstr(status));
1629 q.in.trustdom_handle = &trustdom_handle[i];
1630 q.in.level = LSA_TRUSTED_DOMAIN_INFO_NAME;
1631 status = dcerpc_lsa_QueryTrustedDomainInfo(p, mem_ctx, &q);
1632 if (!NT_STATUS_IS_OK(status)) {
1633 printf("QueryTrustedDomainInfo level 1 failed - %s\n", nt_errstr(status));
1635 } else if (!q.out.info) {
1638 if (strcmp(q.out.info->name.netbios_name.string, trustinfo.name.string) != 0) {
1639 printf("QueryTrustedDomainInfo returned inconsistant short name: %s != %s\n",
1640 q.out.info->name.netbios_name.string, trustinfo.name.string);
1647 /* now that we have some domains to look over, we can test the enum calls */
1648 if (!test_EnumTrustDom(p, mem_ctx, handle)) {
1652 for (i=0; i<12; i++) {
1653 if (!test_Delete(p, mem_ctx, &trustdom_handle[i])) {
1661 static BOOL test_QueryDomainInfoPolicy(struct dcerpc_pipe *p,
1662 TALLOC_CTX *mem_ctx,
1663 struct policy_handle *handle)
1665 struct lsa_QueryDomainInformationPolicy r;
1669 printf("\nTesting QueryDomainInformationPolicy\n");
1672 r.in.handle = handle;
1675 printf("\ntrying QueryDomainInformationPolicy level %d\n", i);
1677 status = dcerpc_lsa_QueryDomainInformationPolicy(p, mem_ctx, &r);
1679 if (!NT_STATUS_IS_OK(status)) {
1680 printf("QueryDomainInformationPolicy failed - %s\n", nt_errstr(status));
1690 static BOOL test_QueryInfoPolicy(struct dcerpc_pipe *p,
1691 TALLOC_CTX *mem_ctx,
1692 struct policy_handle *handle)
1694 struct lsa_QueryInfoPolicy r;
1698 printf("\nTesting QueryInfoPolicy\n");
1700 for (i=1;i<13;i++) {
1701 r.in.handle = handle;
1704 printf("\ntrying QueryInfoPolicy level %d\n", i);
1706 status = dcerpc_lsa_QueryInfoPolicy(p, mem_ctx, &r);
1708 if ((i == 9 || i == 10 || i == 11) &&
1709 NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
1710 printf("server failed level %u (OK)\n", i);
1714 if (!NT_STATUS_IS_OK(status)) {
1715 printf("QueryInfoPolicy failed - %s\n", nt_errstr(status));
1724 static BOOL test_QueryInfoPolicy2(struct dcerpc_pipe *p,
1725 TALLOC_CTX *mem_ctx,
1726 struct policy_handle *handle)
1728 struct lsa_QueryInfoPolicy2 r;
1732 printf("\nTesting QueryInfoPolicy2\n");
1734 for (i=1;i<13;i++) {
1735 r.in.handle = handle;
1738 printf("\ntrying QueryInfoPolicy2 level %d\n", i);
1740 status = dcerpc_lsa_QueryInfoPolicy2(p, mem_ctx, &r);
1742 if ((i == 9 || i == 10 || i == 11) &&
1743 NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
1744 printf("server failed level %u (OK)\n", i);
1748 if (!NT_STATUS_IS_OK(status)) {
1749 printf("QueryInfoPolicy2 failed - %s\n", nt_errstr(status));
1758 static BOOL test_GetUserName(struct dcerpc_pipe *p,
1759 TALLOC_CTX *mem_ctx,
1760 struct policy_handle *handle)
1762 struct lsa_GetUserName r;
1765 struct lsa_StringPointer authority_name_p;
1767 printf("\nTesting GetUserName\n");
1769 r.in.system_name = "\\";
1770 r.in.account_name = NULL;
1771 r.in.authority_name = &authority_name_p;
1772 authority_name_p.string = NULL;
1774 status = dcerpc_lsa_GetUserName(p, mem_ctx, &r);
1776 if (!NT_STATUS_IS_OK(status)) {
1777 printf("GetUserName failed - %s\n", nt_errstr(status));
1784 BOOL test_lsa_Close(struct dcerpc_pipe *p,
1785 TALLOC_CTX *mem_ctx,
1786 struct policy_handle *handle)
1790 struct policy_handle handle2;
1792 printf("\ntesting Close\n");
1794 r.in.handle = handle;
1795 r.out.handle = &handle2;
1797 status = dcerpc_lsa_Close(p, mem_ctx, &r);
1798 if (!NT_STATUS_IS_OK(status)) {
1799 printf("Close failed - %s\n", nt_errstr(status));
1803 status = dcerpc_lsa_Close(p, mem_ctx, &r);
1804 /* its really a fault - we need a status code for rpc fault */
1805 if (!NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
1806 printf("Close failed - %s\n", nt_errstr(status));
1815 BOOL torture_rpc_lsa(void)
1818 struct dcerpc_pipe *p;
1819 TALLOC_CTX *mem_ctx;
1821 struct policy_handle *handle;
1823 mem_ctx = talloc_init("torture_rpc_lsa");
1825 status = torture_rpc_connection(mem_ctx, &p, &dcerpc_table_lsarpc);
1826 if (!NT_STATUS_IS_OK(status)) {
1827 talloc_free(mem_ctx);
1831 if (!test_OpenPolicy(p, mem_ctx)) {
1835 if (!test_lsa_OpenPolicy2(p, mem_ctx, &handle)) {
1840 if (!test_LookupSids_async(p, mem_ctx, handle)) {
1844 if (!test_QueryDomainInfoPolicy(p, mem_ctx, handle)) {
1848 if (!test_CreateAccount(p, mem_ctx, handle)) {
1852 if (!test_CreateSecret(p, mem_ctx, handle)) {
1856 if (!test_CreateTrustedDomain(p, mem_ctx, handle)) {
1860 if (!test_EnumAccounts(p, mem_ctx, handle)) {
1864 if (!test_EnumPrivs(p, mem_ctx, handle)) {
1868 if (!test_QueryInfoPolicy(p, mem_ctx, handle)) {
1872 if (!test_QueryInfoPolicy2(p, mem_ctx, handle)) {
1876 if (!test_GetUserName(p, mem_ctx, handle)) {
1881 if (!test_Delete(p, mem_ctx, handle)) {
1886 if (!test_many_LookupSids(p, mem_ctx, handle)) {
1890 if (!test_lsa_Close(p, mem_ctx, handle)) {
1894 if (!test_many_LookupSids(p, mem_ctx, handle)) {
1899 talloc_free(mem_ctx);