s4: allow python code to dump NTACL object as well
[Samba/ekacnet.git] / source4 / torture / rpc / srvsvc.c
blob1e5b44c43f3e31691f3c01773e2d8dccf67d6ce7
1 /*
2 Unix SMB/CIFS implementation.
3 test suite for srvsvc rpc operations
5 Copyright (C) Stefan (metze) Metzmacher 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 3 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, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "librpc/gen_ndr/ndr_srvsvc_c.h"
23 #include "torture/rpc/rpc.h"
25 /**************************/
26 /* srvsvc_NetCharDev */
27 /**************************/
28 static bool test_NetCharDevGetInfo(struct dcerpc_pipe *p, struct torture_context *tctx,
29 const char *devname)
31 NTSTATUS status;
32 struct srvsvc_NetCharDevGetInfo r;
33 union srvsvc_NetCharDevInfo info;
34 uint32_t levels[] = {0, 1};
35 int i;
37 r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
38 r.in.device_name = devname;
39 r.out.info = &info;
41 for (i=0;i<ARRAY_SIZE(levels);i++) {
42 r.in.level = levels[i];
43 torture_comment(tctx, "testing NetCharDevGetInfo level %u on device '%s'\n",
44 r.in.level, r.in.device_name);
45 status = dcerpc_srvsvc_NetCharDevGetInfo(p, tctx, &r);
46 torture_assert_ntstatus_ok(tctx, status, "NetCharDevGetInfo failed");
47 torture_assert_werr_ok(tctx, r.out.result, "NetCharDevGetInfo failed");
50 return true;
53 static bool test_NetCharDevControl(struct dcerpc_pipe *p, struct torture_context *tctx,
54 const char *devname)
56 NTSTATUS status;
57 struct srvsvc_NetCharDevControl r;
58 uint32_t opcodes[] = {0, 1};
59 int i;
61 r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
62 r.in.device_name = devname;
64 for (i=0;i<ARRAY_SIZE(opcodes);i++) {
65 ZERO_STRUCT(r.out);
66 r.in.opcode = opcodes[i];
67 torture_comment(tctx, "testing NetCharDevControl opcode %u on device '%s'\n",
68 r.in.opcode, r.in.device_name);
69 status = dcerpc_srvsvc_NetCharDevControl(p, tctx, &r);
70 torture_assert_ntstatus_ok(tctx, status, "NetCharDevControl failed");
71 torture_assert_werr_ok(tctx, r.out.result, "NetCharDevControl failed");
74 return true;
77 static bool test_NetCharDevEnum(struct torture_context *tctx,
78 struct dcerpc_pipe *p)
80 NTSTATUS status;
81 struct srvsvc_NetCharDevEnum r;
82 struct srvsvc_NetCharDevInfoCtr info_ctr;
83 struct srvsvc_NetCharDevCtr0 c0;
84 struct srvsvc_NetCharDevCtr0 c1;
85 uint32_t totalentries = 0;
86 uint32_t levels[] = {0, 1};
87 int i;
89 ZERO_STRUCT(info_ctr);
91 r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
92 r.in.info_ctr = &info_ctr;
93 r.in.max_buffer = (uint32_t)-1;
94 r.in.resume_handle = NULL;
95 r.out.info_ctr = &info_ctr;
96 r.out.totalentries = &totalentries;
98 for (i=0;i<ARRAY_SIZE(levels);i++) {
99 int j;
101 info_ctr.level = levels[i];
103 switch(info_ctr.level) {
104 case 0:
105 ZERO_STRUCT(c0);
106 info_ctr.ctr.ctr0 = &c0;
107 break;
108 case 1:
109 ZERO_STRUCT(c1);
110 info_ctr.ctr.ctr0 = &c1;
111 break;
114 torture_comment(tctx, "testing NetCharDevEnum level %u\n", info_ctr.level);
115 status = dcerpc_srvsvc_NetCharDevEnum(p, tctx, &r);
116 torture_assert_ntstatus_ok(tctx, status, "NetCharDevEnum failed");
117 if (!W_ERROR_IS_OK(r.out.result)) {
118 torture_comment(tctx, "NetCharDevEnum failed: %s\n", win_errstr(r.out.result));
119 continue;
122 /* call test_NetCharDevGetInfo and test_NetCharDevControl for each returned share */
123 if (info_ctr.level == 1) {
124 for (j=0;j<r.out.info_ctr->ctr.ctr1->count;j++) {
125 const char *device;
126 device = r.out.info_ctr->ctr.ctr1->array[j].device;
127 if (!test_NetCharDevGetInfo(p, tctx, device)) {
128 return false;
130 if (!test_NetCharDevControl(p, tctx, device)) {
131 return false;
137 return true;
140 /**************************/
141 /* srvsvc_NetCharDevQ */
142 /**************************/
143 static bool test_NetCharDevQGetInfo(struct dcerpc_pipe *p, struct torture_context *tctx,
144 const char *devicequeue)
146 NTSTATUS status;
147 struct srvsvc_NetCharDevQGetInfo r;
148 union srvsvc_NetCharDevQInfo info;
149 uint32_t levels[] = {0, 1};
150 int i;
152 r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
153 r.in.queue_name = devicequeue;
154 r.in.user = talloc_asprintf(tctx,"Administrator");
155 r.out.info = &info;
157 for (i=0;i<ARRAY_SIZE(levels);i++) {
158 r.in.level = levels[i];
159 torture_comment(tctx, "testing NetCharDevQGetInfo level %u on devicequeue '%s'\n",
160 r.in.level, r.in.queue_name);
161 status = dcerpc_srvsvc_NetCharDevQGetInfo(p, tctx, &r);
162 torture_assert_ntstatus_ok(tctx, status, "NetCharDevQGetInfo failed");
163 torture_assert_werr_ok(tctx, r.out.result, "NetCharDevQGetInfo failed");
166 return true;
169 #if 0
170 static bool test_NetCharDevQSetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
171 const char *devicequeue)
173 NTSTATUS status;
174 struct srvsvc_NetCharDevQSetInfo r;
175 uint32_t parm_error;
176 uint32_t levels[] = {0, 1};
177 int i;
178 bool ret = true;
180 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
181 r.in.queue_name = devicequeue;
183 for (i=0;i<ARRAY_SIZE(levels);i++) {
184 ZERO_STRUCT(r.out);
185 parm_error = 0;
186 r.in.level = levels[i];
187 d_printf("testing NetCharDevQSetInfo level %u on devicequeue '%s'\n",
188 r.in.level, devicequeue);
189 switch (r.in.level) {
190 case 0:
191 r.in.info.info0 = talloc(mem_ctx, struct srvsvc_NetCharDevQInfo0);
192 r.in.info.info0->device = r.in.queue_name;
193 break;
194 case 1:
195 r.in.info.info1 = talloc(mem_ctx, struct srvsvc_NetCharDevQInfo1);
196 r.in.info.info1->device = r.in.queue_name;
197 r.in.info.info1->priority = 0x000;
198 r.in.info.info1->devices = r.in.queue_name;
199 r.in.info.info1->users = 0x000;
200 r.in.info.info1->num_ahead = 0x000;
201 break;
202 default:
203 break;
205 r.in.parm_error = &parm_error;
206 status = dcerpc_srvsvc_NetCharDevQSetInfo(p, mem_ctx, &r);
207 if (!NT_STATUS_IS_OK(status)) {
208 d_printf("NetCharDevQSetInfo level %u on devicequeue '%s' failed - %s\n",
209 r.in.level, r.in.queue_name, nt_errstr(status));
210 ret = false;
211 continue;
213 if (!W_ERROR_IS_OK(r.out.result)) {
214 d_printf("NetCharDevQSetInfo level %u on devicequeue '%s' failed - %s\n",
215 r.in.level, r.in.queue_name, win_errstr(r.out.result));
216 continue;
220 return ret;
222 #endif
224 static bool test_NetCharDevQEnum(struct torture_context *tctx,
225 struct dcerpc_pipe *p)
227 NTSTATUS status;
228 struct srvsvc_NetCharDevQEnum r;
229 struct srvsvc_NetCharDevQInfoCtr info_ctr;
230 struct srvsvc_NetCharDevQCtr0 c0;
231 struct srvsvc_NetCharDevQCtr1 c1;
232 uint32_t totalentries = 0;
233 uint32_t levels[] = {0, 1};
234 int i;
236 ZERO_STRUCT(info_ctr);
238 r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
239 r.in.user = talloc_asprintf(tctx,"%s","Administrator");
240 r.in.info_ctr = &info_ctr;
241 r.in.max_buffer = (uint32_t)-1;
242 r.in.resume_handle = NULL;
243 r.out.totalentries = &totalentries;
244 r.out.info_ctr = &info_ctr;
246 for (i=0;i<ARRAY_SIZE(levels);i++) {
247 int j;
249 info_ctr.level = levels[i];
251 switch (info_ctr.level) {
252 case 0:
253 ZERO_STRUCT(c0);
254 info_ctr.ctr.ctr0 = &c0;
255 break;
256 case 1:
257 ZERO_STRUCT(c1);
258 info_ctr.ctr.ctr1 = &c1;
259 break;
261 torture_comment(tctx, "testing NetCharDevQEnum level %u\n", info_ctr.level);
262 status = dcerpc_srvsvc_NetCharDevQEnum(p, tctx, &r);
263 torture_assert_ntstatus_ok(tctx, status, "NetCharDevQEnum failed");
264 if (!W_ERROR_IS_OK(r.out.result)) {
265 torture_comment(tctx, "NetCharDevQEnum failed: %s\n", win_errstr(r.out.result));
266 continue;
269 /* call test_NetCharDevGetInfo and test_NetCharDevControl for each returned share */
270 if (info_ctr.level == 1) {
271 for (j=0;j<r.out.info_ctr->ctr.ctr1->count;j++) {
272 const char *device;
273 device = r.out.info_ctr->ctr.ctr1->array[j].device;
274 if (!test_NetCharDevQGetInfo(p, tctx, device)) {
275 return false;
281 return true;
284 /**************************/
285 /* srvsvc_NetConn */
286 /**************************/
287 static bool test_NetConnEnum(struct torture_context *tctx,
288 struct dcerpc_pipe *p)
290 NTSTATUS status;
291 struct srvsvc_NetConnEnum r;
292 struct srvsvc_NetConnInfoCtr info_ctr;
293 struct srvsvc_NetConnCtr0 c0;
294 struct srvsvc_NetConnCtr1 c1;
295 uint32_t totalentries = 0;
296 uint32_t levels[] = {0, 1};
297 int i;
299 ZERO_STRUCT(info_ctr);
301 r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
302 r.in.path = talloc_asprintf(tctx,"%s","ADMIN$");
303 r.in.info_ctr = &info_ctr;
304 r.in.max_buffer = (uint32_t)-1;
305 r.in.resume_handle = NULL;
306 r.out.totalentries = &totalentries;
307 r.out.info_ctr = &info_ctr;
309 for (i=0;i<ARRAY_SIZE(levels);i++) {
310 info_ctr.level = levels[i];
312 switch (info_ctr.level) {
313 case 0:
314 ZERO_STRUCT(c0);
315 info_ctr.ctr.ctr0 = &c0;
316 break;
317 case 1:
318 ZERO_STRUCT(c1);
319 info_ctr.ctr.ctr1 = &c1;
320 break;
323 torture_comment(tctx, "testing NetConnEnum level %u\n", info_ctr.level);
324 status = dcerpc_srvsvc_NetConnEnum(p, tctx, &r);
325 torture_assert_ntstatus_ok(tctx, status, "NetConnEnum failed");
326 if (!W_ERROR_IS_OK(r.out.result)) {
327 torture_comment(tctx, "NetConnEnum failed: %s\n", win_errstr(r.out.result));
331 return true;
334 /**************************/
335 /* srvsvc_NetFile */
336 /**************************/
337 static bool test_NetFileEnum(struct torture_context *tctx,
338 struct dcerpc_pipe *p)
340 NTSTATUS status;
341 struct srvsvc_NetFileEnum r;
342 struct srvsvc_NetFileInfoCtr info_ctr;
343 struct srvsvc_NetFileCtr2 c2;
344 struct srvsvc_NetFileCtr3 c3;
345 uint32_t totalentries = 0;
346 uint32_t levels[] = {2, 3};
347 int i;
349 ZERO_STRUCT(info_ctr);
351 r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
352 r.in.path = NULL;
353 r.in.user = NULL;
354 r.in.info_ctr = &info_ctr;
355 r.in.max_buffer = (uint32_t)4096;
356 r.in.resume_handle = NULL;
357 r.out.totalentries = &totalentries;
358 r.out.info_ctr = &info_ctr;
360 for (i=0;i<ARRAY_SIZE(levels);i++) {
361 info_ctr.level = levels[i];
363 switch (info_ctr.level) {
364 case 2:
365 ZERO_STRUCT(c2);
366 info_ctr.ctr.ctr2 = &c2;
367 break;
368 case 3:
369 ZERO_STRUCT(c3);
370 info_ctr.ctr.ctr3 = &c3;
371 break;
373 torture_comment(tctx, "testing NetFileEnum level %u\n", info_ctr.level);
374 status = dcerpc_srvsvc_NetFileEnum(p, tctx, &r);
375 torture_assert_ntstatus_ok(tctx, status, "NetFileEnum failed");
376 if (!W_ERROR_IS_OK(r.out.result)) {
377 torture_comment(tctx, "NetFileEnum failed: %s\n", win_errstr(r.out.result));
381 return true;
384 /**************************/
385 /* srvsvc_NetSess */
386 /**************************/
387 static bool test_NetSessEnum(struct torture_context *tctx,
388 struct dcerpc_pipe *p)
390 NTSTATUS status;
391 struct srvsvc_NetSessEnum r;
392 struct srvsvc_NetSessInfoCtr info_ctr;
393 struct srvsvc_NetSessCtr0 c0;
394 struct srvsvc_NetSessCtr1 c1;
395 struct srvsvc_NetSessCtr2 c2;
396 struct srvsvc_NetSessCtr10 c10;
397 struct srvsvc_NetSessCtr502 c502;
398 uint32_t totalentries = 0;
399 uint32_t levels[] = {0, 1, 2, 10, 502};
400 int i;
402 ZERO_STRUCT(info_ctr);
404 r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
405 r.in.client = NULL;
406 r.in.user = NULL;
407 r.in.info_ctr = &info_ctr;
408 r.in.max_buffer = (uint32_t)-1;
409 r.in.resume_handle = NULL;
410 r.out.totalentries = &totalentries;
411 r.out.info_ctr = &info_ctr;
413 for (i=0;i<ARRAY_SIZE(levels);i++) {
414 info_ctr.level = levels[i];
416 switch (info_ctr.level) {
417 case 0:
418 ZERO_STRUCT(c0);
419 info_ctr.ctr.ctr0 = &c0;
420 break;
421 case 1:
422 ZERO_STRUCT(c1);
423 info_ctr.ctr.ctr1 = &c1;
424 break;
425 case 2:
426 ZERO_STRUCT(c2);
427 info_ctr.ctr.ctr2 = &c2;
428 break;
429 case 10:
430 ZERO_STRUCT(c10);
431 info_ctr.ctr.ctr10 = &c10;
432 break;
433 case 502:
434 ZERO_STRUCT(c502);
435 info_ctr.ctr.ctr502 = &c502;
436 break;
439 torture_comment(tctx, "testing NetSessEnum level %u\n", info_ctr.level);
440 status = dcerpc_srvsvc_NetSessEnum(p, tctx, &r);
441 torture_assert_ntstatus_ok(tctx, status, "NetSessEnum failed");
442 if (!W_ERROR_IS_OK(r.out.result)) {
443 torture_comment(tctx, "NetSessEnum failed: %s\n", win_errstr(r.out.result));
447 return true;
450 /**************************/
451 /* srvsvc_NetShare */
452 /**************************/
453 static bool test_NetShareCheck(struct dcerpc_pipe *p, struct torture_context *tctx,
454 const char *device_name)
456 NTSTATUS status;
457 struct srvsvc_NetShareCheck r;
458 enum srvsvc_ShareType type;
460 r.in.server_unc = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
461 r.in.device_name = device_name;
462 r.out.type = &type;
464 torture_comment(tctx,
465 "testing NetShareCheck on device '%s'\n", r.in.device_name);
467 status = dcerpc_srvsvc_NetShareCheck(p, tctx, &r);
468 torture_assert_ntstatus_ok(tctx, status, "dcerpc_srvsvc_NetShareCheck failed");
469 torture_assert_werr_ok(tctx, r.out.result, "NetShareCheck failed");
471 return true;
474 static bool test_NetShareGetInfo(struct torture_context *tctx,
475 struct dcerpc_pipe *p,
476 const char *sharename, bool admin)
478 NTSTATUS status;
479 struct srvsvc_NetShareGetInfo r;
480 union srvsvc_NetShareInfo info;
481 struct {
482 uint32_t level;
483 WERROR anon_status;
484 WERROR admin_status;
485 } levels[] = {
486 { 0, WERR_OK, WERR_OK },
487 { 1, WERR_OK, WERR_OK },
488 { 2, WERR_ACCESS_DENIED, WERR_OK },
489 { 501, WERR_OK, WERR_OK },
490 { 502, WERR_ACCESS_DENIED, WERR_OK },
491 { 1005, WERR_OK, WERR_OK },
493 int i;
495 r.in.server_unc = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
496 r.in.share_name = sharename;
497 r.out.info = &info;
499 for (i=0;i<ARRAY_SIZE(levels);i++) {
500 WERROR expected;
502 r.in.level = levels[i].level;
503 expected = levels[i].anon_status;
504 if (admin) expected = levels[i].admin_status;
506 torture_comment(tctx, "testing NetShareGetInfo level %u on share '%s'\n",
507 r.in.level, r.in.share_name);
509 status = dcerpc_srvsvc_NetShareGetInfo(p, tctx, &r);
510 torture_assert_ntstatus_ok(tctx, status, "NetShareGetInfo failed");
511 torture_assert_werr_equal(tctx, r.out.result, expected, "NetShareGetInfo failed");
513 if (r.in.level != 2) continue;
514 if (!r.out.info->info2 || !r.out.info->info2->path) continue;
515 if (!test_NetShareCheck(p, tctx, r.out.info->info2->path)) {
516 return false;
520 return true;
523 static bool test_NetShareGetInfoAdminFull(struct torture_context *tctx,
524 struct dcerpc_pipe *p)
526 return test_NetShareGetInfo(tctx, p, "ADMIN$", true);
529 static bool test_NetShareGetInfoAdminAnon(struct torture_context *tctx,
530 struct dcerpc_pipe *p)
532 return test_NetShareGetInfo(tctx, p, "ADMIN$", false);
535 static bool test_NetShareAddSetDel(struct torture_context *tctx,
536 struct dcerpc_pipe *p)
538 NTSTATUS status;
539 struct srvsvc_NetShareAdd a;
540 struct srvsvc_NetShareSetInfo r;
541 struct srvsvc_NetShareGetInfo q;
542 struct srvsvc_NetShareDel d;
543 struct sec_desc_buf sd_buf;
544 union srvsvc_NetShareInfo info;
545 struct {
546 uint32_t level;
547 WERROR expected;
548 } levels[] = {
549 { 0, WERR_UNKNOWN_LEVEL },
550 { 1, WERR_OK },
551 { 2, WERR_OK },
552 { 501, WERR_UNKNOWN_LEVEL },
553 { 502, WERR_OK },
554 { 1004, WERR_OK },
555 { 1005, WERR_OK },
556 { 1006, WERR_OK },
557 /* { 1007, WERR_OK }, */
558 { 1501, WERR_OK },
560 int i;
562 a.in.server_unc = r.in.server_unc = q.in.server_unc = d.in.server_unc =
563 talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
564 r.in.share_name = talloc_strdup(tctx, "testshare");
566 info.info2 = talloc(tctx, struct srvsvc_NetShareInfo2);
567 info.info2->name = r.in.share_name;
568 info.info2->type = STYPE_DISKTREE;
569 info.info2->comment = talloc_strdup(tctx, "test comment");
570 info.info2->permissions = 123434566;
571 info.info2->max_users = -1;
572 info.info2->current_users = 0;
573 info.info2->path = talloc_strdup(tctx, "C:\\");
574 info.info2->password = NULL;
576 a.in.info = &info;
577 a.in.level = 2;
578 a.in.parm_error = NULL;
580 status = dcerpc_srvsvc_NetShareAdd(p, tctx, &a);
581 torture_assert_ntstatus_ok(tctx, status, "NetShareAdd level 2 on share 'testshare' failed");
582 torture_assert_werr_ok(tctx, a.out.result, "NetShareAdd level 2 on share 'testshare' failed");
584 r.in.parm_error = NULL;
586 q.in.level = 502;
588 for (i = 0; i < ARRAY_SIZE(levels); i++) {
590 r.in.level = levels[i].level;
591 ZERO_STRUCT(r.out);
593 torture_comment(tctx, "testing NetShareSetInfo level %u on share '%s'\n",
594 r.in.level, r.in.share_name);
596 switch (levels[i].level) {
597 case 0:
598 info.info0 = talloc(tctx, struct srvsvc_NetShareInfo0);
599 info.info0->name = r.in.share_name;
600 break;
601 case 1:
602 info.info1 = talloc(tctx, struct srvsvc_NetShareInfo1);
603 info.info1->name = r.in.share_name;
604 info.info1->type = STYPE_DISKTREE;
605 info.info1->comment = talloc_strdup(tctx, "test comment 1");
606 break;
607 case 2:
608 info.info2 = talloc(tctx, struct srvsvc_NetShareInfo2);
609 info.info2->name = r.in.share_name;
610 info.info2->type = STYPE_DISKTREE;
611 info.info2->comment = talloc_strdup(tctx, "test comment 2");
612 info.info2->permissions = 0;
613 info.info2->max_users = 2;
614 info.info2->current_users = 1;
615 info.info2->path = talloc_strdup(tctx, "::BLaH::"); /* "C:\\"); */
616 info.info2->password = NULL;
617 break;
618 case 501:
619 info.info501 = talloc(tctx, struct srvsvc_NetShareInfo501);
620 info.info501->name = r.in.share_name;
621 info.info501->type = STYPE_DISKTREE;
622 info.info501->comment = talloc_strdup(tctx, "test comment 501");
623 info.info501->csc_policy = 0;
624 break;
625 case 502:
626 ZERO_STRUCT(sd_buf);
627 info.info502 = talloc(tctx, struct srvsvc_NetShareInfo502);
628 info.info502->name = r.in.share_name;
629 info.info502->type = STYPE_DISKTREE;
630 info.info502->comment = talloc_strdup(tctx, "test comment 502");
631 info.info502->permissions = 0;
632 info.info502->max_users = 502;
633 info.info502->current_users = 1;
634 info.info502->path = talloc_strdup(tctx, "C:\\");
635 info.info502->password = NULL;
636 info.info502->sd_buf = sd_buf;
637 break;
638 case 1004:
639 info.info1004 = talloc(tctx, struct srvsvc_NetShareInfo1004);
640 info.info1004->comment = talloc_strdup(tctx, "test comment 1004");
641 break;
642 case 1005:
643 info.info1005 = talloc(tctx, struct srvsvc_NetShareInfo1005);
644 info.info1005->dfs_flags = 0;
645 break;
646 case 1006:
647 info.info1006 = talloc(tctx, struct srvsvc_NetShareInfo1006);
648 info.info1006->max_users = 1006;
649 break;
650 /* case 1007:
651 info.info1007 = talloc(tctx, struct srvsvc_NetShareInfo1007);
652 info.info1007->flags = 0;
653 info.info1007->alternate_directory_name = talloc_strdup(tctx, "test");
654 break;
656 case 1501:
657 info.info1501 = talloc_zero(tctx, struct sec_desc_buf);
658 break;
661 r.in.info = &info;
663 status = dcerpc_srvsvc_NetShareSetInfo(p, tctx, &r);
664 torture_assert_ntstatus_ok(tctx, status, "NetShareGetInfo failed");
665 torture_assert_werr_equal(tctx, r.out.result, levels[i].expected, "NetShareSetInfo failed");
667 q.in.share_name = r.in.share_name;
668 q.out.info = &info;
670 status = dcerpc_srvsvc_NetShareGetInfo(p, tctx, &q);
671 torture_assert_ntstatus_ok(tctx, status, "NetShareGetInfo failed");
672 torture_assert_werr_ok(tctx, q.out.result, "NetShareGetInfo failed");
674 torture_assert_str_equal(tctx, q.out.info->info502->name, r.in.share_name,
675 "share name invalid");
677 switch (levels[i].level) {
678 case 0:
679 break;
680 case 1:
681 torture_assert_str_equal(tctx, q.out.info->info502->comment, "test comment 1", "comment");
682 break;
683 case 2:
684 torture_assert_str_equal(tctx, q.out.info->info2->comment, "test comment 2", "comment");
685 torture_assert_int_equal(tctx, q.out.info->info2->max_users, 2, "max users");
686 torture_assert_str_equal(tctx, q.out.info->info2->path, "C:\\", "path");
687 break;
688 case 501:
689 torture_assert_str_equal(tctx, q.out.info->info501->comment, "test comment 501", "comment");
690 break;
691 case 502:
692 torture_assert_str_equal(tctx, q.out.info->info502->comment, "test comment 502", "comment");
693 torture_assert_int_equal(tctx, q.out.info->info502->max_users, 502, "max users");
694 torture_assert_str_equal(tctx, q.out.info->info502->path, "C:\\", "path");
695 break;
696 case 1004:
697 torture_assert_str_equal(tctx, q.out.info->info1004->comment, "test comment 1004",
698 "comment");
699 break;
700 case 1005:
701 break;
702 case 1006:
703 torture_assert_int_equal(tctx, q.out.info->info1006->max_users, 1006, "Max users");
704 break;
705 /* case 1007:
706 break;
708 case 1501:
709 break;
713 d.in.share_name = r.in.share_name;
714 d.in.reserved = 0;
716 status = dcerpc_srvsvc_NetShareDel(p, tctx, &d);
717 torture_assert_ntstatus_ok(tctx, status, "NetShareDel on share 'testshare502' failed");
718 torture_assert_werr_ok(tctx, a.out.result, "NetShareDel on share 'testshare502' failed");
720 return true;
723 /**************************/
724 /* srvsvc_NetShare */
725 /**************************/
726 static bool test_NetShareEnumAll(struct torture_context *tctx,
727 struct dcerpc_pipe *p,
728 bool admin)
730 NTSTATUS status;
731 struct srvsvc_NetShareEnumAll r;
732 struct srvsvc_NetShareInfoCtr info_ctr;
733 struct srvsvc_NetShareCtr0 c0;
734 struct srvsvc_NetShareCtr1 c1;
735 struct srvsvc_NetShareCtr2 c2;
736 struct srvsvc_NetShareCtr501 c501;
737 struct srvsvc_NetShareCtr502 c502;
738 uint32_t totalentries = 0;
739 struct {
740 uint32_t level;
741 WERROR anon_status;
742 WERROR admin_status;
743 } levels[] = {
744 { 0, WERR_OK, WERR_OK },
745 { 1, WERR_OK, WERR_OK },
746 { 2, WERR_ACCESS_DENIED, WERR_OK },
747 { 501, WERR_ACCESS_DENIED, WERR_OK },
748 { 502, WERR_ACCESS_DENIED, WERR_OK },
750 int i;
751 uint32_t resume_handle;
753 ZERO_STRUCT(info_ctr);
755 r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
756 r.in.info_ctr = &info_ctr;
757 r.in.max_buffer = (uint32_t)-1;
758 r.in.resume_handle = &resume_handle;
759 r.out.resume_handle = &resume_handle;
760 r.out.totalentries = &totalentries;
761 r.out.info_ctr = &info_ctr;
763 for (i=0;i<ARRAY_SIZE(levels);i++) {
765 int j;
766 WERROR expected;
768 info_ctr.level = levels[i].level;
770 switch (info_ctr.level) {
771 case 0:
772 ZERO_STRUCT(c0);
773 info_ctr.ctr.ctr0 = &c0;
774 break;
775 case 1:
776 ZERO_STRUCT(c1);
777 info_ctr.ctr.ctr1 = &c1;
778 break;
779 case 2:
780 ZERO_STRUCT(c2);
781 info_ctr.ctr.ctr2 = &c2;
782 break;
783 case 501:
784 ZERO_STRUCT(c501);
785 info_ctr.ctr.ctr501 = &c501;
786 break;
787 case 502:
788 ZERO_STRUCT(c502);
789 info_ctr.ctr.ctr502 = &c502;
790 break;
793 expected = levels[i].anon_status;
794 if (admin) expected = levels[i].admin_status;
796 resume_handle = 0;
798 torture_comment(tctx, "testing NetShareEnumAll level %u\n", info_ctr.level);
799 status = dcerpc_srvsvc_NetShareEnumAll(p, tctx, &r);
800 torture_assert_ntstatus_ok(tctx, status, "NetShareEnumAll failed");
801 torture_assert_werr_equal(tctx, r.out.result, expected, "NetShareEnumAll failed");
803 /* call srvsvc_NetShareGetInfo for each returned share */
804 if (info_ctr.level == 2 && r.out.info_ctr->ctr.ctr2) {
805 for (j=0;j<r.out.info_ctr->ctr.ctr2->count;j++) {
806 const char *name;
807 name = r.out.info_ctr->ctr.ctr2->array[j].name;
808 if (!test_NetShareGetInfo(tctx, p, name, admin)) {
809 return false;
815 return true;
818 static bool test_NetShareEnumAllFull(struct torture_context *tctx,
819 struct dcerpc_pipe *p)
821 return test_NetShareEnumAll(tctx, p, true);
824 static bool test_NetShareEnumAllAnon(struct torture_context *tctx,
825 struct dcerpc_pipe *p)
827 return test_NetShareEnumAll(tctx, p, false);
830 static bool test_NetShareEnum(struct torture_context *tctx,
831 struct dcerpc_pipe *p, bool admin)
833 NTSTATUS status;
834 struct srvsvc_NetShareEnum r;
835 struct srvsvc_NetShareInfoCtr info_ctr;
836 struct srvsvc_NetShareCtr0 c0;
837 struct srvsvc_NetShareCtr1 c1;
838 struct srvsvc_NetShareCtr2 c2;
839 struct srvsvc_NetShareCtr501 c501;
840 struct srvsvc_NetShareCtr502 c502;
841 uint32_t totalentries = 0;
842 struct {
843 uint32_t level;
844 WERROR anon_status;
845 WERROR admin_status;
846 } levels[] = {
847 { 0, WERR_OK, WERR_OK },
848 { 1, WERR_OK, WERR_OK },
849 { 2, WERR_ACCESS_DENIED, WERR_OK },
850 { 501, WERR_UNKNOWN_LEVEL, WERR_UNKNOWN_LEVEL },
851 { 502, WERR_ACCESS_DENIED, WERR_OK },
853 int i;
855 r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
856 r.in.info_ctr = &info_ctr;
857 r.in.max_buffer = (uint32_t)-1;
858 r.in.resume_handle = NULL;
859 r.out.totalentries = &totalentries;
860 r.out.info_ctr = &info_ctr;
862 for (i=0;i<ARRAY_SIZE(levels);i++) {
863 WERROR expected;
865 info_ctr.level = levels[i].level;
867 switch (info_ctr.level) {
868 case 0:
869 ZERO_STRUCT(c0);
870 info_ctr.ctr.ctr0 = &c0;
871 break;
872 case 1:
873 ZERO_STRUCT(c1);
874 info_ctr.ctr.ctr1 = &c1;
875 break;
876 case 2:
877 ZERO_STRUCT(c2);
878 info_ctr.ctr.ctr2 = &c2;
879 break;
880 case 501:
881 ZERO_STRUCT(c501);
882 info_ctr.ctr.ctr501 = &c501;
883 break;
884 case 502:
885 ZERO_STRUCT(c502);
886 info_ctr.ctr.ctr502 = &c502;
887 break;
890 expected = levels[i].anon_status;
891 if (admin) expected = levels[i].admin_status;
893 torture_comment(tctx, "testing NetShareEnum level %u\n", info_ctr.level);
894 status = dcerpc_srvsvc_NetShareEnum(p, tctx, &r);
895 torture_assert_ntstatus_ok(tctx, status, "NetShareEnum failed");
896 torture_assert_werr_equal(tctx, r.out.result, expected, "NetShareEnum failed");
899 return true;
902 static bool test_NetShareEnumFull(struct torture_context *tctx,
903 struct dcerpc_pipe *p)
905 return test_NetShareEnum(tctx, p, true);
908 static bool test_NetShareEnumAnon(struct torture_context *tctx,
909 struct dcerpc_pipe *p)
911 return test_NetShareEnum(tctx, p, false);
914 /**************************/
915 /* srvsvc_NetSrv */
916 /**************************/
917 static bool test_NetSrvGetInfo(struct torture_context *tctx,
918 struct dcerpc_pipe *p)
920 NTSTATUS status;
921 struct srvsvc_NetSrvGetInfo r;
922 union srvsvc_NetSrvInfo info;
923 uint32_t levels[] = {100, 101, 102, 502, 503};
924 int i;
926 r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
928 for (i=0;i<ARRAY_SIZE(levels);i++) {
929 r.in.level = levels[i];
930 r.out.info = &info;
931 torture_comment(tctx, "testing NetSrvGetInfo level %u\n", r.in.level);
932 status = dcerpc_srvsvc_NetSrvGetInfo(p, tctx, &r);
933 torture_assert_ntstatus_ok(tctx, status, "NetSrvGetInfo failed");
934 if (!W_ERROR_IS_OK(r.out.result)) {
935 torture_comment(tctx, "NetSrvGetInfo failed: %s\n", win_errstr(r.out.result));
939 return true;
942 /**************************/
943 /* srvsvc_NetDisk */
944 /**************************/
945 static bool test_NetDiskEnum(struct torture_context *tctx,
946 struct dcerpc_pipe *p)
948 NTSTATUS status;
949 struct srvsvc_NetDiskEnum r;
950 struct srvsvc_NetDiskInfo info;
951 uint32_t totalentries = 0;
952 uint32_t levels[] = {0};
953 int i;
954 uint32_t resume_handle=0;
956 ZERO_STRUCT(info);
958 r.in.server_unc = NULL;
959 r.in.resume_handle = &resume_handle;
960 r.in.info = &info;
961 r.out.info = &info;
962 r.out.totalentries = &totalentries;
963 r.out.resume_handle = &resume_handle;
965 for (i=0;i<ARRAY_SIZE(levels);i++) {
966 ZERO_STRUCTP(r.out.info);
967 r.in.level = levels[i];
968 torture_comment(tctx, "testing NetDiskEnum level %u\n", r.in.level);
969 status = dcerpc_srvsvc_NetDiskEnum(p, tctx, &r);
970 torture_assert_ntstatus_ok(tctx, status, "NetDiskEnum failed");
971 torture_assert_werr_ok(tctx, r.out.result, "NetDiskEnum failed");
974 return true;
977 /**************************/
978 /* srvsvc_NetTransport */
979 /**************************/
980 static bool test_NetTransportEnum(struct torture_context *tctx,
981 struct dcerpc_pipe *p)
983 NTSTATUS status;
984 struct srvsvc_NetTransportEnum r;
985 struct srvsvc_NetTransportInfoCtr transports;
986 struct srvsvc_NetTransportCtr0 ctr0;
987 struct srvsvc_NetTransportCtr1 ctr1;
989 uint32_t totalentries = 0;
990 uint32_t levels[] = {0, 1};
991 int i;
993 ZERO_STRUCT(transports);
995 r.in.server_unc = talloc_asprintf(tctx,"\\\\%s", dcerpc_server_name(p));
996 r.in.transports = &transports;
997 r.in.max_buffer = (uint32_t)-1;
998 r.in.resume_handle = NULL;
999 r.out.totalentries = &totalentries;
1000 r.out.transports = &transports;
1002 for (i=0;i<ARRAY_SIZE(levels);i++) {
1003 transports.level = levels[i];
1004 switch (transports.level) {
1005 case 0:
1006 ZERO_STRUCT(ctr0);
1007 transports.ctr.ctr0 = &ctr0;
1008 break;
1009 case 1:
1010 ZERO_STRUCT(ctr1);
1011 transports.ctr.ctr1 = &ctr1;
1012 break;
1014 torture_comment(tctx, "testing NetTransportEnum level %u\n", transports.level);
1015 status = dcerpc_srvsvc_NetTransportEnum(p, tctx, &r);
1016 torture_assert_ntstatus_ok(tctx, status, "NetTransportEnum failed");
1017 if (!W_ERROR_IS_OK(r.out.result)) {
1018 torture_comment(tctx, "unexpected result: %s\n", win_errstr(r.out.result));
1022 return true;
1025 /**************************/
1026 /* srvsvc_NetRemoteTOD */
1027 /**************************/
1028 static bool test_NetRemoteTOD(struct torture_context *tctx,
1029 struct dcerpc_pipe *p)
1031 NTSTATUS status;
1032 struct srvsvc_NetRemoteTOD r;
1033 struct srvsvc_NetRemoteTODInfo *info = NULL;
1035 r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
1036 r.out.info = &info;
1038 torture_comment(tctx, "testing NetRemoteTOD\n");
1039 status = dcerpc_srvsvc_NetRemoteTOD(p, tctx, &r);
1040 torture_assert_ntstatus_ok(tctx, status, "NetRemoteTOD failed");
1041 torture_assert_werr_ok(tctx, r.out.result, "NetRemoteTOD failed");
1043 return true;
1046 /**************************/
1047 /* srvsvc_NetName */
1048 /**************************/
1050 static bool test_NetNameValidate(struct torture_context *tctx,
1051 struct dcerpc_pipe *p)
1053 NTSTATUS status;
1054 struct srvsvc_NetNameValidate r;
1055 char *invalidc;
1056 char *name;
1057 int i, n, min, max;
1059 r.in.server_unc = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
1060 r.in.flags = 0x0;
1062 d_printf("testing NetNameValidate\n");
1064 /* valid path types only between 1 and 13 */
1065 for (i = 1; i < 14; i++) {
1067 again:
1068 /* let's limit ourselves to a maximum of 4096 bytes */
1069 r.in.name = name = talloc_array(tctx, char, 4097);
1070 max = 4096;
1071 min = 0;
1072 n = max;
1074 while (1) {
1076 /* Find maximum length accepted by this type */
1077 ZERO_STRUCT(r.out);
1078 r.in.name_type = i;
1079 memset(name, 'A', n);
1080 name[n] = '\0';
1082 status = dcerpc_srvsvc_NetNameValidate(p, tctx, &r);
1083 if (!NT_STATUS_IS_OK(status)) {
1084 d_printf("NetNameValidate failed while checking maximum size (%s)\n",
1085 nt_errstr(status));
1086 break;
1089 if (W_ERROR_IS_OK(r.out.result)) {
1090 min = n;
1091 n += (max - min + 1)/2;
1092 continue;
1094 } else {
1095 if ((min + 1) >= max) break; /* found it */
1097 max = n;
1098 n -= (max - min)/2;
1099 continue;
1103 talloc_free(name);
1105 d_printf("Maximum length for type %2d, flags %08x: %d\n", i, r.in.flags, max);
1107 /* find invalid chars for this type check only ASCII between 0x20 and 0x7e */
1109 invalidc = talloc_strdup(tctx, "");
1111 for (n = 0x20; n < 0x7e; n++) {
1112 r.in.name = name = talloc_asprintf(tctx, "%c", (char)n);
1114 status = dcerpc_srvsvc_NetNameValidate(p, tctx, &r);
1115 if (!NT_STATUS_IS_OK(status)) {
1116 d_printf("NetNameValidate failed while checking valid chars (%s)\n",
1117 nt_errstr(status));
1118 break;
1121 if (!W_ERROR_IS_OK(r.out.result)) {
1122 invalidc = talloc_asprintf_append_buffer(invalidc, "%c", (char)n);
1125 talloc_free(name);
1128 d_printf(" Invalid chars for type %2d, flags %08x: \"%s\"\n", i, r.in.flags, invalidc);
1130 /* only two values are accepted for flags: 0x0 and 0x80000000 */
1131 if (r.in.flags == 0x0) {
1132 r.in.flags = 0x80000000;
1133 goto again;
1136 r.in.flags = 0x0;
1139 return true;
1142 struct torture_suite *torture_rpc_srvsvc(TALLOC_CTX *mem_ctx)
1144 struct torture_suite *suite = torture_suite_create(mem_ctx, "SRVSVC");
1145 struct torture_rpc_tcase *tcase;
1146 struct torture_test *test;
1148 tcase = torture_suite_add_rpc_iface_tcase(suite, "srvsvc (admin access)", &ndr_table_srvsvc);
1150 torture_rpc_tcase_add_test(tcase, "NetCharDevEnum", test_NetCharDevEnum);
1151 torture_rpc_tcase_add_test(tcase, "NetCharDevQEnum", test_NetCharDevQEnum);
1152 torture_rpc_tcase_add_test(tcase, "NetConnEnum", test_NetConnEnum);
1153 torture_rpc_tcase_add_test(tcase, "NetFileEnum", test_NetFileEnum);
1154 torture_rpc_tcase_add_test(tcase, "NetSessEnum", test_NetSessEnum);
1155 torture_rpc_tcase_add_test(tcase, "NetShareEnumAll", test_NetShareEnumAllFull);
1156 torture_rpc_tcase_add_test(tcase, "NetSrvGetInfo", test_NetSrvGetInfo);
1157 torture_rpc_tcase_add_test(tcase, "NetDiskEnum", test_NetDiskEnum);
1158 torture_rpc_tcase_add_test(tcase, "NetTransportEnum", test_NetTransportEnum);
1159 torture_rpc_tcase_add_test(tcase, "NetRemoteTOD", test_NetRemoteTOD);
1160 torture_rpc_tcase_add_test(tcase, "NetShareEnum", test_NetShareEnumFull);
1161 torture_rpc_tcase_add_test(tcase, "NetShareGetInfo", test_NetShareGetInfoAdminFull);
1162 test = torture_rpc_tcase_add_test(tcase, "NetShareAddSetDel",
1163 test_NetShareAddSetDel);
1164 test->dangerous = true;
1165 torture_rpc_tcase_add_test(tcase, "NetNameValidate", test_NetNameValidate);
1167 tcase = torture_suite_add_anon_rpc_iface_tcase(suite,
1168 "srvsvc anonymous access",
1169 &ndr_table_srvsvc);
1171 torture_rpc_tcase_add_test(tcase, "NetShareEnumAll",
1172 test_NetShareEnumAllAnon);
1173 torture_rpc_tcase_add_test(tcase, "NetShareEnum",
1174 test_NetShareEnumAnon);
1175 torture_rpc_tcase_add_test(tcase, "NetShareGetInfo",
1176 test_NetShareGetInfoAdminAnon);
1178 return suite;