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 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "torture/torture.h"
24 #include "librpc/gen_ndr/ndr_srvsvc.h"
25 #include "torture/rpc/rpc.h"
27 /**************************/
28 /* srvsvc_NetCharDev */
29 /**************************/
30 static BOOL test_NetCharDevGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
34 struct srvsvc_NetCharDevGetInfo r;
35 uint32_t levels[] = {0, 1};
39 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
40 r.in.device_name = devname;
42 for (i=0;i<ARRAY_SIZE(levels);i++) {
44 r.in.level = levels[i];
45 printf("testing NetCharDevGetInfo level %u on device '%s'\n",
46 r.in.level, r.in.device_name);
47 status = dcerpc_srvsvc_NetCharDevGetInfo(p, mem_ctx, &r);
48 if (!NT_STATUS_IS_OK(status)) {
49 printf("NetCharDevGetInfo level %u on device '%s' failed - %s\n",
50 r.in.level, r.in.device_name, nt_errstr(status));
54 if (!W_ERROR_IS_OK(r.out.result)) {
55 printf("NetCharDevGetInfo level %u on device '%s' failed - %s\n",
56 r.in.level, r.in.device_name, win_errstr(r.out.result));
64 static BOOL test_NetCharDevControl(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
68 struct srvsvc_NetCharDevControl r;
69 uint32_t opcodes[] = {0, 1};
73 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
74 r.in.device_name = devname;
76 for (i=0;i<ARRAY_SIZE(opcodes);i++) {
78 r.in.opcode = opcodes[i];
79 printf("testing NetCharDevControl opcode %u on device '%s'\n",
80 r.in.opcode, r.in.device_name);
81 status = dcerpc_srvsvc_NetCharDevControl(p, mem_ctx, &r);
82 if (!NT_STATUS_IS_OK(status)) {
83 printf("NetCharDevControl opcode %u failed - %s\n", r.in.opcode, nt_errstr(status));
87 if (!W_ERROR_IS_OK(r.out.result)) {
88 printf("NetCharDevControl opcode %u failed - %s\n", r.in.opcode, win_errstr(r.out.result));
96 static BOOL test_NetCharDevEnum(struct dcerpc_pipe *p,
100 struct srvsvc_NetCharDevEnum r;
101 struct srvsvc_NetCharDevCtr0 c0;
102 uint32_t levels[] = {0, 1};
106 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
108 r.in.ctr.ctr0->count = 0;
109 r.in.ctr.ctr0->array = NULL;
110 r.in.max_buffer = (uint32_t)-1;
111 r.in.resume_handle = NULL;
113 for (i=0;i<ARRAY_SIZE(levels);i++) {
118 r.in.level = levels[i];
119 printf("testing NetCharDevEnum level %u\n", r.in.level);
120 status = dcerpc_srvsvc_NetCharDevEnum(p, mem_ctx, &r);
121 if (!NT_STATUS_IS_OK(status)) {
122 printf("NetCharDevEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
126 if (!W_ERROR_IS_OK(r.out.result)) {
127 printf("NetCharDevEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
131 /* call test_NetCharDevGetInfo and test_NetCharDevControl for each returned share */
132 if (r.in.level == 1) {
133 for (j=0;j<r.out.ctr.ctr1->count;j++) {
135 device = r.out.ctr.ctr1->array[j].device;
136 if (!test_NetCharDevGetInfo(p, mem_ctx, device)) {
139 if (!test_NetCharDevControl(p, mem_ctx, device)) {
149 /**************************/
150 /* srvsvc_NetCharDevQ */
151 /**************************/
152 static BOOL test_NetCharDevQGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
153 const char *devicequeue)
156 struct srvsvc_NetCharDevQGetInfo r;
157 uint32_t levels[] = {0, 1};
161 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
162 r.in.queue_name = devicequeue;
163 r.in.user = talloc_asprintf(mem_ctx,"Administrator");
165 for (i=0;i<ARRAY_SIZE(levels);i++) {
167 r.in.level = levels[i];
168 printf("testing NetCharDevQGetInfo level %u on devicequeue '%s'\n",
169 r.in.level, r.in.queue_name);
170 status = dcerpc_srvsvc_NetCharDevQGetInfo(p, mem_ctx, &r);
171 if (!NT_STATUS_IS_OK(status)) {
172 printf("NetCharDevQGetInfo level %u on devicequeue '%s' failed - %s\n",
173 r.in.level, r.in.queue_name, nt_errstr(status));
177 if (!W_ERROR_IS_OK(r.out.result)) {
178 printf("NetCharDevQGetInfo level %u on devicequeue '%s' failed - %s\n",
179 r.in.level, r.in.queue_name, win_errstr(r.out.result));
188 static BOOL test_NetCharDevQSetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
189 const char *devicequeue)
192 struct srvsvc_NetCharDevQSetInfo r;
194 uint32_t levels[] = {0, 1};
198 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
199 r.in.queue_name = devicequeue;
201 for (i=0;i<ARRAY_SIZE(levels);i++) {
204 r.in.level = levels[i];
205 printf("testing NetCharDevQSetInfo level %u on devicequeue '%s'\n",
206 r.in.level, devicequeue);
207 switch (r.in.level) {
209 r.in.info.info0 = talloc(mem_ctx, struct srvsvc_NetCharDevQInfo0);
210 r.in.info.info0->device = r.in.queue_name;
213 r.in.info.info1 = talloc(mem_ctx, struct srvsvc_NetCharDevQInfo1);
214 r.in.info.info1->device = r.in.queue_name;
215 r.in.info.info1->priority = 0x000;
216 r.in.info.info1->devices = r.in.queue_name;
217 r.in.info.info1->users = 0x000;
218 r.in.info.info1->num_ahead = 0x000;
223 r.in.parm_error = &parm_error;
224 status = dcerpc_srvsvc_NetCharDevQSetInfo(p, mem_ctx, &r);
225 if (!NT_STATUS_IS_OK(status)) {
226 printf("NetCharDevQSetInfo level %u on devicequeue '%s' failed - %s\n",
227 r.in.level, r.in.queue_name, nt_errstr(status));
231 if (!W_ERROR_IS_OK(r.out.result)) {
232 printf("NetCharDevQSetInfo level %u on devicequeue '%s' failed - %s\n",
233 r.in.level, r.in.queue_name, win_errstr(r.out.result));
242 static BOOL test_NetCharDevQEnum(struct dcerpc_pipe *p,
246 struct srvsvc_NetCharDevQEnum r;
247 struct srvsvc_NetCharDevQCtr0 c0;
248 uint32_t levels[] = {0, 1};
252 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
253 r.in.user = talloc_asprintf(mem_ctx,"%s","Administrator");
255 r.in.ctr.ctr0->count = 0;
256 r.in.ctr.ctr0->array = NULL;
257 r.in.max_buffer = (uint32_t)-1;
258 r.in.resume_handle = NULL;
260 for (i=0;i<ARRAY_SIZE(levels);i++) {
264 r.in.level = levels[i];
265 printf("testing NetCharDevQEnum level %u\n", r.in.level);
266 status = dcerpc_srvsvc_NetCharDevQEnum(p, mem_ctx, &r);
267 if (!NT_STATUS_IS_OK(status)) {
268 printf("NetCharDevQEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
272 if (!W_ERROR_IS_OK(r.out.result)) {
273 printf("NetCharDevQEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
277 /* call test_NetCharDevGetInfo and test_NetCharDevControl for each returned share */
278 if (r.in.level == 1) {
279 for (j=0;j<r.out.ctr.ctr1->count;j++) {
281 device = r.out.ctr.ctr1->array[j].device;
282 if (!test_NetCharDevQGetInfo(p, mem_ctx, device)) {
292 /**************************/
294 /**************************/
295 static BOOL test_NetConnEnum(struct dcerpc_pipe *p,
299 struct srvsvc_NetConnEnum r;
300 struct srvsvc_NetConnCtr0 c0;
301 uint32_t levels[] = {0, 1};
305 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
306 r.in.path = talloc_asprintf(mem_ctx,"%s","ADMIN$");
308 r.in.ctr.ctr0->count = 0;
309 r.in.ctr.ctr0->array = NULL;
310 r.in.max_buffer = (uint32_t)-1;
311 r.in.resume_handle = NULL;
313 for (i=0;i<ARRAY_SIZE(levels);i++) {
315 r.in.level = levels[i];
316 printf("testing NetConnEnum level %u\n", r.in.level);
317 status = dcerpc_srvsvc_NetConnEnum(p, mem_ctx, &r);
318 if (!NT_STATUS_IS_OK(status)) {
319 printf("NetConnEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
323 if (!W_ERROR_IS_OK(r.out.result)) {
324 printf("NetConnEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
332 /**************************/
334 /**************************/
335 static BOOL test_NetFileEnum(struct dcerpc_pipe *p,
339 struct srvsvc_NetFileEnum r;
340 struct srvsvc_NetFileCtr3 c3;
341 uint32_t levels[] = {2, 3};
345 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
349 r.in.ctr.ctr3->count = 0;
350 r.in.ctr.ctr3->array = NULL;
351 r.in.max_buffer = (uint32_t)4096;
352 r.in.resume_handle = NULL;
354 for (i=0;i<ARRAY_SIZE(levels);i++) {
356 r.in.level = levels[i];
357 printf("testing NetFileEnum level %u\n", r.in.level);
358 status = dcerpc_srvsvc_NetFileEnum(p, mem_ctx, &r);
359 if (!NT_STATUS_IS_OK(status)) {
360 printf("NetFileEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
364 if (!W_ERROR_IS_OK(r.out.result)) {
365 printf("NetFileEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
373 /**************************/
375 /**************************/
376 static BOOL test_NetSessEnum(struct dcerpc_pipe *p,
380 struct srvsvc_NetSessEnum r;
381 struct srvsvc_NetSessCtr0 c0;
382 uint32_t levels[] = {0, 1, 2, 10, 502};
386 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
390 r.in.ctr.ctr0->count = 0;
391 r.in.ctr.ctr0->array = NULL;
392 r.in.max_buffer = (uint32_t)-1;
393 r.in.resume_handle = NULL;
395 for (i=0;i<ARRAY_SIZE(levels);i++) {
397 r.in.level = levels[i];
398 printf("testing NetSessEnum level %u\n", r.in.level);
399 status = dcerpc_srvsvc_NetSessEnum(p, mem_ctx, &r);
400 if (!NT_STATUS_IS_OK(status)) {
401 printf("NetSessEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
405 if (!W_ERROR_IS_OK(r.out.result)) {
406 printf("NetSessEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
414 /**************************/
415 /* srvsvc_NetShare */
416 /**************************/
417 static BOOL test_NetShareGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
418 const char *sharename)
421 struct srvsvc_NetShareGetInfo r;
422 uint32_t levels[] = {0, 1, 2, 501, 502, 1005};
426 r.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
427 r.in.share_name = sharename;
429 for (i=0;i<ARRAY_SIZE(levels);i++) {
431 r.in.level = levels[i];
433 printf("testing NetShareGetInfo level %u on share '%s'\n",
434 r.in.level, r.in.share_name);
436 status = dcerpc_srvsvc_NetShareGetInfo(p, mem_ctx, &r);
437 if (!NT_STATUS_IS_OK(status)) {
438 printf("NetShareGetInfo level %u on share '%s' failed - %s\n",
439 r.in.level, r.in.share_name, nt_errstr(status));
443 if (!W_ERROR_IS_OK(r.out.result)) {
444 printf("NetShareGetInfo level %u on share '%s' failed - %s\n",
445 r.in.level, r.in.share_name, win_errstr(r.out.result));
453 static BOOL test_NetShareCheck(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
454 const char *device_name)
457 struct srvsvc_NetShareCheck r;
460 r.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
461 r.in.device_name = device_name;
463 printf("testing NetShareCheck on device '%s'\n", r.in.device_name);
465 status = dcerpc_srvsvc_NetShareCheck(p, mem_ctx, &r);
466 if (!NT_STATUS_IS_OK(status)) {
467 printf("dcerpc_srvsvc_NetShareCheck on device '%s' failed - %s\n",
468 r.in.device_name, nt_errstr(status));
470 } else if (!W_ERROR_IS_OK(r.out.result)) {
471 printf("NetShareCheck on device '%s' failed - %s\n",
472 r.in.device_name, win_errstr(r.out.result));
479 /**************************/
480 /* srvsvc_NetShare */
481 /**************************/
482 static BOOL test_NetShareEnumAll(struct dcerpc_pipe *p,
486 struct srvsvc_NetShareEnumAll r;
487 struct srvsvc_NetShareCtr0 c0;
488 uint32_t levels[] = {0, 1, 2, 501, 502};
491 uint32_t resume_handle;
495 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
497 r.in.max_buffer = (uint32_t)-1;
498 r.in.resume_handle = &resume_handle;
499 r.out.resume_handle = &resume_handle;
501 for (i=0;i<ARRAY_SIZE(levels);i++) {
506 r.in.level = levels[i];
507 printf("testing NetShareEnumAll level %u\n", r.in.level);
508 status = dcerpc_srvsvc_NetShareEnumAll(p, mem_ctx, &r);
509 if (!NT_STATUS_IS_OK(status)) {
510 printf("NetShareEnumAll level %u failed - %s\n", r.in.level, nt_errstr(status));
514 if (!W_ERROR_IS_OK(r.out.result)) {
515 printf("NetShareEnumAll level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
519 /* call srvsvc_NetShareGetInfo for each returned share */
520 if (r.in.level == 2) {
521 for (j=0;j<r.out.ctr.ctr2->count;j++) {
524 name = r.out.ctr.ctr2->array[j].name;
525 if (!test_NetShareGetInfo(p, mem_ctx, name)) {
528 device = r.out.ctr.ctr2->array[j].path;
529 if (!test_NetShareCheck(p, mem_ctx, device)) {
539 static BOOL test_NetShareEnum(struct dcerpc_pipe *p,
543 struct srvsvc_NetShareEnum r;
544 struct srvsvc_NetShareCtr0 c0;
545 uint32_t levels[] = {0, 1, 2, 502};
549 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
551 r.in.ctr.ctr0->count = 0;
552 r.in.ctr.ctr0->array = NULL;
553 r.in.max_buffer = (uint32_t)-1;
554 r.in.resume_handle = NULL;
556 for (i=0;i<ARRAY_SIZE(levels);i++) {
558 r.in.level = levels[i];
559 printf("testing NetShareEnum level %u\n", r.in.level);
560 status = dcerpc_srvsvc_NetShareEnum(p, mem_ctx, &r);
561 if (!NT_STATUS_IS_OK(status)) {
562 printf("NetShareEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
566 if (!W_ERROR_IS_OK(r.out.result)) {
567 printf("NetShareEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
575 /**************************/
577 /**************************/
578 static BOOL test_NetSrvGetInfo(struct dcerpc_pipe *p,
582 struct srvsvc_NetSrvGetInfo r;
583 struct srvsvc_NetSrvInfo503 i503;
584 uint32_t levels[] = {100, 101, 102, 502, 503};
587 uint32_t resume_handle;
591 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
593 for (i=0;i<ARRAY_SIZE(levels);i++) {
596 r.in.level = levels[i];
597 printf("testing NetSrvGetInfo level %u\n", r.in.level);
598 status = dcerpc_srvsvc_NetSrvGetInfo(p, mem_ctx, &r);
599 if (!NT_STATUS_IS_OK(status)) {
600 printf("NetSrvGetInfo level %u failed - %s\n", r.in.level, nt_errstr(status));
604 if (!W_ERROR_IS_OK(r.out.result)) {
605 printf("NetSrvGetInfo level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
613 /**************************/
615 /**************************/
616 static BOOL test_NetDiskEnum(struct dcerpc_pipe *p,
620 struct srvsvc_NetDiskEnum r;
621 uint32_t levels[] = {0};
624 uint32_t resume_handle=0;
626 r.in.server_unc = NULL;
627 r.in.resume_handle = &resume_handle;
628 r.in.disks.discs = NULL;
630 for (i=0;i<ARRAY_SIZE(levels);i++) {
632 r.in.level = levels[i];
633 printf("testing NetDiskEnum level %u\n", r.in.level);
634 status = dcerpc_srvsvc_NetDiskEnum(p, mem_ctx, &r);
635 if (!NT_STATUS_IS_OK(status)) {
636 NDR_PRINT_OUT_DEBUG(srvsvc_NetDiskEnum, &r);
637 printf("NetDiskEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
641 if (!W_ERROR_IS_OK(r.out.result)) {
642 printf("NetDiskEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
650 /**************************/
651 /* srvsvc_NetTransport */
652 /**************************/
653 static BOOL test_NetTransportEnum(struct dcerpc_pipe *p,
657 struct srvsvc_NetTransportEnum r;
658 struct srvsvc_NetTransportCtr0 c0;
659 uint32_t levels[] = {0, 1};
663 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
664 r.in.transports.ctr0 = &c0;
665 r.in.transports.ctr0->count = 0;
666 r.in.transports.ctr0->array = NULL;
667 r.in.max_buffer = (uint32_t)-1;
668 r.in.resume_handle = NULL;
670 for (i=0;i<ARRAY_SIZE(levels);i++) {
672 r.in.level = levels[i];
673 printf("testing NetTransportEnum level %u\n", r.in.level);
674 status = dcerpc_srvsvc_NetTransportEnum(p, mem_ctx, &r);
675 if (!NT_STATUS_IS_OK(status)) {
676 printf("NetTransportEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
680 if (!W_ERROR_IS_OK(r.out.result)) {
681 printf("NetTransportEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
689 /**************************/
690 /* srvsvc_NetRemoteTOD */
691 /**************************/
692 static BOOL test_NetRemoteTOD(struct dcerpc_pipe *p,
696 struct srvsvc_NetRemoteTOD r;
699 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
702 printf("testing NetRemoteTOD\n");
703 status = dcerpc_srvsvc_NetRemoteTOD(p, mem_ctx, &r);
704 if (!NT_STATUS_IS_OK(status)) {
705 printf("NetRemoteTOD failed - %s\n", nt_errstr(status));
708 if (!W_ERROR_IS_OK(r.out.result)) {
709 printf("NetRemoteTOD failed - %s\n", win_errstr(r.out.result));
715 BOOL torture_rpc_srvsvc(void)
718 struct dcerpc_pipe *p;
722 mem_ctx = talloc_init("torture_rpc_srvsvc");
724 status = torture_rpc_connection(mem_ctx, &p, &dcerpc_table_srvsvc);
725 if (!NT_STATUS_IS_OK(status)) {
726 talloc_free(mem_ctx);
730 if (!test_NetCharDevEnum(p, mem_ctx)) {
734 if (!test_NetCharDevQEnum(p, mem_ctx)) {
738 if (!test_NetConnEnum(p, mem_ctx)) {
742 if (!test_NetFileEnum(p, mem_ctx)) {
746 if (!test_NetSessEnum(p, mem_ctx)) {
750 if (!test_NetShareEnumAll(p, mem_ctx)) {
754 if (!test_NetSrvGetInfo(p, mem_ctx)) {
758 if (!test_NetDiskEnum(p, mem_ctx)) {
762 if (!test_NetTransportEnum(p, mem_ctx)) {
766 if (!test_NetRemoteTOD(p, mem_ctx)) {
770 if (!test_NetShareEnum(p, mem_ctx)) {
774 talloc_free(mem_ctx);