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.
24 static BOOL test_OpenPolicy(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
26 struct lsa_ObjectAttribute attr;
27 struct policy_handle handle;
28 struct lsa_QosInfo qos;
29 struct lsa_OpenPolicy r;
31 uint16 system_name = '\\';
33 printf("\ntesting OpenPolicy\n");
36 qos.impersonation_level = 2;
38 qos.effective_only = 0;
42 attr.object_name = NULL;
47 r.in.system_name = &system_name;
49 r.in.desired_access = SEC_RIGHTS_MAXIMUM_ALLOWED;
50 r.out.handle = &handle;
52 status = dcerpc_lsa_OpenPolicy(p, mem_ctx, &r);
53 if (!NT_STATUS_IS_OK(status)) {
54 printf("OpenPolicy failed - %s\n", nt_errstr(status));
62 static BOOL test_OpenPolicy2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
63 struct policy_handle *handle)
65 struct lsa_ObjectAttribute attr;
66 struct lsa_QosInfo qos;
67 struct lsa_OpenPolicy2 r;
70 printf("\ntesting OpenPolicy2\n");
73 qos.impersonation_level = 2;
75 qos.effective_only = 0;
79 attr.object_name = NULL;
84 r.in.system_name = "\\";
86 r.in.desired_access = SEC_RIGHTS_MAXIMUM_ALLOWED;
87 r.out.handle = handle;
89 status = dcerpc_lsa_OpenPolicy2(p, mem_ctx, &r);
90 if (!NT_STATUS_IS_OK(status)) {
91 printf("OpenPolicy2 failed - %s\n", nt_errstr(status));
98 static BOOL test_LookupNames(struct dcerpc_pipe *p,
100 struct policy_handle *handle,
101 struct lsa_TransNameArray *tnames)
103 struct lsa_LookupNames r;
104 struct lsa_TransSidArray sids;
105 struct lsa_Name *names;
110 printf("\nTesting LookupNames\n");
115 names = talloc(mem_ctx, tnames->count * sizeof(names[0]));
116 for (i=0;i<tnames->count;i++) {
117 names[i].name_len = 2*strlen(tnames->names[i].name.name);
118 names[i].name_size = 2*strlen(tnames->names[i].name.name);
119 names[i].name = tnames->names[i].name.name;
122 r.in.handle = handle;
123 r.in.num_names = tnames->count;
128 r.out.count = &count;
131 status = dcerpc_lsa_LookupNames(p, mem_ctx, &r);
132 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
133 printf("LookupNames failed - %s\n", nt_errstr(status));
137 NDR_PRINT_BOTH_DEBUG(lsa_LookupNames, &r);
145 static BOOL test_LookupSids(struct dcerpc_pipe *p,
147 struct policy_handle *handle,
148 struct lsa_SidArray *sids)
150 struct lsa_LookupSids r;
151 struct lsa_TransNameArray names;
152 uint32 count = sids->num_sids;
155 printf("\nTesting LookupSids\n");
160 r.in.handle = handle;
165 r.out.count = &count;
166 r.out.names = &names;
168 status = dcerpc_lsa_LookupSids(p, mem_ctx, &r);
169 if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, STATUS_SOME_UNMAPPED)) {
170 printf("LookupSids failed - %s\n", nt_errstr(status));
174 NDR_PRINT_BOTH_DEBUG(lsa_LookupSids, &r);
178 if (!test_LookupNames(p, mem_ctx, handle, &names)) {
185 static BOOL test_LookupPrivName(struct dcerpc_pipe *p,
187 struct policy_handle *handle,
188 struct lsa_LUID *luid)
191 struct lsa_LookupPrivName r;
193 r.in.handle = handle;
196 status = dcerpc_lsa_LookupPrivName(p, mem_ctx, &r);
197 if (!NT_STATUS_IS_OK(status)) {
198 printf("\nLookupPrivName failed - %s\n", nt_errstr(status));
202 NDR_PRINT_BOTH_DEBUG(lsa_LookupPrivName, &r);
207 static BOOL test_EnumPrivsAccount(struct dcerpc_pipe *p,
209 struct policy_handle *handle,
210 struct policy_handle *acct_handle)
213 struct lsa_EnumPrivsAccount r;
215 printf("Testing EnumPrivsAccount\n");
217 r.in.handle = acct_handle;
219 status = dcerpc_lsa_EnumPrivsAccount(p, mem_ctx, &r);
220 if (!NT_STATUS_IS_OK(status)) {
221 printf("EnumPrivsAccount failed - %s\n", nt_errstr(status));
225 NDR_PRINT_BOTH_DEBUG(lsa_EnumPrivsAccount, &r);
229 for (i=0;i<r.out.privs->count;i++) {
230 test_LookupPrivName(p, mem_ctx, handle,
231 &r.out.privs->set[i].luid);
238 static BOOL test_EnumAccountRights(struct dcerpc_pipe *p,
240 struct policy_handle *acct_handle,
244 struct lsa_EnumAccountRights r;
245 struct lsa_RightSet rights;
247 printf("Testing EnumAccountRights\n");
249 r.in.handle = acct_handle;
251 r.out.rights = &rights;
253 status = dcerpc_lsa_EnumAccountRights(p, mem_ctx, &r);
254 if (!NT_STATUS_IS_OK(status)) {
255 printf("EnumAccountRights failed - %s\n", nt_errstr(status));
259 NDR_PRINT_BOTH_DEBUG(lsa_EnumAccountRights, &r);
265 static BOOL test_QuerySecObj(struct dcerpc_pipe *p,
267 struct policy_handle *handle,
268 struct policy_handle *acct_handle)
271 struct lsa_QuerySecObj r;
273 printf("Testing QuerySecObj\n");
275 r.in.handle = acct_handle;
278 status = dcerpc_lsa_QuerySecObj(p, mem_ctx, &r);
279 if (!NT_STATUS_IS_OK(status)) {
280 printf("QuerySecObj failed - %s\n", nt_errstr(status));
284 NDR_PRINT_BOTH_DEBUG(lsa_QuerySecObj, &r);
289 static BOOL test_OpenAccount(struct dcerpc_pipe *p,
291 struct policy_handle *handle,
295 struct lsa_OpenAccount r;
296 struct policy_handle acct_handle;
298 printf("Testing OpenAccount\n");
300 r.in.handle = handle;
302 r.in.desired_access = SEC_RIGHTS_MAXIMUM_ALLOWED;
303 r.out.acct_handle = &acct_handle;
305 status = dcerpc_lsa_OpenAccount(p, mem_ctx, &r);
306 if (!NT_STATUS_IS_OK(status)) {
307 printf("OpenAccount failed - %s\n", nt_errstr(status));
311 if (!test_EnumPrivsAccount(p, mem_ctx, handle, &acct_handle)) {
315 if (!test_QuerySecObj(p, mem_ctx, handle, &acct_handle)) {
322 static BOOL test_EnumAccounts(struct dcerpc_pipe *p,
324 struct policy_handle *handle)
327 struct lsa_EnumAccounts r;
328 struct lsa_SidArray sids1, sids2;
329 uint32 resume_handle = 0;
332 printf("\ntesting EnumAccounts\n");
334 r.in.handle = handle;
335 r.in.resume_handle = &resume_handle;
336 r.in.num_entries = 100;
337 r.out.resume_handle = &resume_handle;
341 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
342 if (!NT_STATUS_IS_OK(status)) {
343 printf("EnumAccounts failed - %s\n", nt_errstr(status));
347 NDR_PRINT_BOTH_DEBUG(lsa_EnumAccounts, &r);
349 if (!test_LookupSids(p, mem_ctx, handle, &sids1)) {
353 printf("testing all accounts\n");
354 for (i=0;i<sids1.num_sids;i++) {
355 test_OpenAccount(p, mem_ctx, handle, sids1.sids[i].sid);
356 test_EnumAccountRights(p, mem_ctx, handle, sids1.sids[i].sid);
360 if (sids1.num_sids < 3) {
364 printf("trying EnumAccounts partial listing (asking for 1 at 2)\n");
366 r.in.num_entries = 1;
369 status = dcerpc_lsa_EnumAccounts(p, mem_ctx, &r);
370 if (!NT_STATUS_IS_OK(status)) {
371 printf("EnumAccounts failed - %s\n", nt_errstr(status));
375 NDR_PRINT_BOTH_DEBUG(lsa_EnumAccounts, &r);
377 if (sids2.num_sids != 1) {
378 printf("Returned wrong number of entries (%d)\n", sids2.num_sids);
386 static BOOL test_EnumPrivs(struct dcerpc_pipe *p,
388 struct policy_handle *handle)
391 struct lsa_EnumPrivs r;
392 struct lsa_PrivArray privs1;
393 uint32 resume_handle = 0;
395 printf("\ntesting EnumPrivs\n");
397 r.in.handle = handle;
398 r.in.resume_handle = &resume_handle;
399 r.in.max_count = 1000;
400 r.out.resume_handle = &resume_handle;
401 r.out.privs = &privs1;
404 status = dcerpc_lsa_EnumPrivs(p, mem_ctx, &r);
405 if (!NT_STATUS_IS_OK(status)) {
406 printf("EnumPrivs failed - %s\n", nt_errstr(status));
410 NDR_PRINT_BOTH_DEBUG(lsa_EnumPrivs, &r);
416 static BOOL test_EnumTrustDom(struct dcerpc_pipe *p,
418 struct policy_handle *handle)
420 struct lsa_EnumTrustDom r;
422 uint32 resume_handle = 0;
423 struct lsa_DomainList domains;
425 printf("\nTesting EnumTrustDom\n");
427 r.in.handle = handle;
428 r.in.resume_handle = &resume_handle;
429 r.in.num_entries = 1000;
430 r.out.domains = &domains;
431 r.out.resume_handle = &resume_handle;
433 status = dcerpc_lsa_EnumTrustDom(p, mem_ctx, &r);
434 if (!NT_STATUS_IS_OK(status)) {
435 printf("EnumTrustDom failed - %s\n", nt_errstr(status));
439 NDR_PRINT_BOTH_DEBUG(lsa_EnumTrustDom, &r);
444 static BOOL test_QueryInfoPolicy(struct dcerpc_pipe *p,
446 struct policy_handle *handle)
448 struct lsa_QueryInfoPolicy r;
453 printf("\nTesting QueryInfoPolicy\n");
456 r.in.handle = handle;
459 printf("\ntrying QueryInfoPolicy level %d\n", i);
461 status = dcerpc_lsa_QueryInfoPolicy(p, mem_ctx, &r);
462 if (!NT_STATUS_IS_OK(status)) {
463 printf("QueryInfoPolicy failed - %s\n", nt_errstr(status));
468 NDR_PRINT_BOTH_DEBUG(lsa_QueryInfoPolicy, &r);
474 static BOOL test_Delete(struct dcerpc_pipe *p,
476 struct policy_handle *handle)
481 printf("\ntesting Delete - but what does it do?\n");
483 r.in.handle = handle;
484 status = dcerpc_lsa_Delete(p, mem_ctx, &r);
485 if (!NT_STATUS_IS_OK(status)) {
486 printf("Delete failed - %s\n", nt_errstr(status));
495 static BOOL test_Close(struct dcerpc_pipe *p,
497 struct policy_handle *handle)
501 struct policy_handle handle2;
503 printf("\ntesting Close\n");
505 r.in.handle = handle;
506 r.out.handle = &handle2;
508 status = dcerpc_lsa_Close(p, mem_ctx, &r);
509 if (!NT_STATUS_IS_OK(status)) {
510 printf("Close failed - %s\n", nt_errstr(status));
514 status = dcerpc_lsa_Close(p, mem_ctx, &r);
515 /* its really a fault - we need a status code for rpc fault */
516 if (!NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
517 printf("Close failed - %s\n", nt_errstr(status));
526 BOOL torture_rpc_lsa(int dummy)
529 struct dcerpc_pipe *p;
532 struct policy_handle handle;
534 mem_ctx = talloc_init("torture_rpc_lsa");
536 status = torture_rpc_connection(&p, "lsarpc");
537 if (!NT_STATUS_IS_OK(status)) {
541 if (!test_OpenPolicy(p, mem_ctx)) {
545 if (!test_OpenPolicy2(p, mem_ctx, &handle)) {
549 if (!test_EnumAccounts(p, mem_ctx, &handle)) {
553 if (!test_EnumPrivs(p, mem_ctx, &handle)) {
557 if (!test_EnumTrustDom(p, mem_ctx, &handle)) {
561 if (!test_QueryInfoPolicy(p, mem_ctx, &handle)) {
566 if (!test_Delete(p, mem_ctx, &handle)) {
571 if (!test_Close(p, mem_ctx, &handle)) {
575 torture_rpc_close(p);