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 "librpc/gen_ndr/ndr_srvsvc_c.h"
26 #include "torture/rpc/rpc.h"
28 /**************************/
29 /* srvsvc_NetCharDev */
30 /**************************/
31 static BOOL test_NetCharDevGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
35 struct srvsvc_NetCharDevGetInfo r;
36 uint32_t levels[] = {0, 1};
40 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
41 r.in.device_name = devname;
43 for (i=0;i<ARRAY_SIZE(levels);i++) {
45 r.in.level = levels[i];
46 printf("testing NetCharDevGetInfo level %u on device '%s'\n",
47 r.in.level, r.in.device_name);
48 status = dcerpc_srvsvc_NetCharDevGetInfo(p, mem_ctx, &r);
49 if (!NT_STATUS_IS_OK(status)) {
50 printf("NetCharDevGetInfo level %u on device '%s' failed - %s\n",
51 r.in.level, r.in.device_name, nt_errstr(status));
55 if (!W_ERROR_IS_OK(r.out.result)) {
56 printf("NetCharDevGetInfo level %u on device '%s' failed - %s\n",
57 r.in.level, r.in.device_name, win_errstr(r.out.result));
65 static BOOL test_NetCharDevControl(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
69 struct srvsvc_NetCharDevControl r;
70 uint32_t opcodes[] = {0, 1};
74 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
75 r.in.device_name = devname;
77 for (i=0;i<ARRAY_SIZE(opcodes);i++) {
79 r.in.opcode = opcodes[i];
80 printf("testing NetCharDevControl opcode %u on device '%s'\n",
81 r.in.opcode, r.in.device_name);
82 status = dcerpc_srvsvc_NetCharDevControl(p, mem_ctx, &r);
83 if (!NT_STATUS_IS_OK(status)) {
84 printf("NetCharDevControl opcode %u failed - %s\n", r.in.opcode, nt_errstr(status));
88 if (!W_ERROR_IS_OK(r.out.result)) {
89 printf("NetCharDevControl opcode %u failed - %s\n", r.in.opcode, win_errstr(r.out.result));
97 static BOOL test_NetCharDevEnum(struct dcerpc_pipe *p,
101 struct srvsvc_NetCharDevEnum r;
102 struct srvsvc_NetCharDevCtr0 c0;
103 uint32_t levels[] = {0, 1};
107 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
109 r.in.ctr.ctr0->count = 0;
110 r.in.ctr.ctr0->array = NULL;
111 r.in.max_buffer = (uint32_t)-1;
112 r.in.resume_handle = NULL;
114 for (i=0;i<ARRAY_SIZE(levels);i++) {
119 r.in.level = levels[i];
120 printf("testing NetCharDevEnum level %u\n", r.in.level);
121 status = dcerpc_srvsvc_NetCharDevEnum(p, mem_ctx, &r);
122 if (!NT_STATUS_IS_OK(status)) {
123 printf("NetCharDevEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
127 if (!W_ERROR_IS_OK(r.out.result)) {
128 printf("NetCharDevEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
132 /* call test_NetCharDevGetInfo and test_NetCharDevControl for each returned share */
133 if (r.in.level == 1) {
134 for (j=0;j<r.out.ctr.ctr1->count;j++) {
136 device = r.out.ctr.ctr1->array[j].device;
137 if (!test_NetCharDevGetInfo(p, mem_ctx, device)) {
140 if (!test_NetCharDevControl(p, mem_ctx, device)) {
150 /**************************/
151 /* srvsvc_NetCharDevQ */
152 /**************************/
153 static BOOL test_NetCharDevQGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
154 const char *devicequeue)
157 struct srvsvc_NetCharDevQGetInfo r;
158 uint32_t levels[] = {0, 1};
162 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
163 r.in.queue_name = devicequeue;
164 r.in.user = talloc_asprintf(mem_ctx,"Administrator");
166 for (i=0;i<ARRAY_SIZE(levels);i++) {
168 r.in.level = levels[i];
169 printf("testing NetCharDevQGetInfo level %u on devicequeue '%s'\n",
170 r.in.level, r.in.queue_name);
171 status = dcerpc_srvsvc_NetCharDevQGetInfo(p, mem_ctx, &r);
172 if (!NT_STATUS_IS_OK(status)) {
173 printf("NetCharDevQGetInfo level %u on devicequeue '%s' failed - %s\n",
174 r.in.level, r.in.queue_name, nt_errstr(status));
178 if (!W_ERROR_IS_OK(r.out.result)) {
179 printf("NetCharDevQGetInfo level %u on devicequeue '%s' failed - %s\n",
180 r.in.level, r.in.queue_name, win_errstr(r.out.result));
189 static BOOL test_NetCharDevQSetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
190 const char *devicequeue)
193 struct srvsvc_NetCharDevQSetInfo r;
195 uint32_t levels[] = {0, 1};
199 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
200 r.in.queue_name = devicequeue;
202 for (i=0;i<ARRAY_SIZE(levels);i++) {
205 r.in.level = levels[i];
206 printf("testing NetCharDevQSetInfo level %u on devicequeue '%s'\n",
207 r.in.level, devicequeue);
208 switch (r.in.level) {
210 r.in.info.info0 = talloc(mem_ctx, struct srvsvc_NetCharDevQInfo0);
211 r.in.info.info0->device = r.in.queue_name;
214 r.in.info.info1 = talloc(mem_ctx, struct srvsvc_NetCharDevQInfo1);
215 r.in.info.info1->device = r.in.queue_name;
216 r.in.info.info1->priority = 0x000;
217 r.in.info.info1->devices = r.in.queue_name;
218 r.in.info.info1->users = 0x000;
219 r.in.info.info1->num_ahead = 0x000;
224 r.in.parm_error = &parm_error;
225 status = dcerpc_srvsvc_NetCharDevQSetInfo(p, mem_ctx, &r);
226 if (!NT_STATUS_IS_OK(status)) {
227 printf("NetCharDevQSetInfo level %u on devicequeue '%s' failed - %s\n",
228 r.in.level, r.in.queue_name, nt_errstr(status));
232 if (!W_ERROR_IS_OK(r.out.result)) {
233 printf("NetCharDevQSetInfo level %u on devicequeue '%s' failed - %s\n",
234 r.in.level, r.in.queue_name, win_errstr(r.out.result));
243 static BOOL test_NetCharDevQEnum(struct dcerpc_pipe *p,
247 struct srvsvc_NetCharDevQEnum r;
248 struct srvsvc_NetCharDevQCtr0 c0;
249 uint32_t levels[] = {0, 1};
253 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
254 r.in.user = talloc_asprintf(mem_ctx,"%s","Administrator");
256 r.in.ctr.ctr0->count = 0;
257 r.in.ctr.ctr0->array = NULL;
258 r.in.max_buffer = (uint32_t)-1;
259 r.in.resume_handle = NULL;
261 for (i=0;i<ARRAY_SIZE(levels);i++) {
265 r.in.level = levels[i];
266 printf("testing NetCharDevQEnum level %u\n", r.in.level);
267 status = dcerpc_srvsvc_NetCharDevQEnum(p, mem_ctx, &r);
268 if (!NT_STATUS_IS_OK(status)) {
269 printf("NetCharDevQEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
273 if (!W_ERROR_IS_OK(r.out.result)) {
274 printf("NetCharDevQEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
278 /* call test_NetCharDevGetInfo and test_NetCharDevControl for each returned share */
279 if (r.in.level == 1) {
280 for (j=0;j<r.out.ctr.ctr1->count;j++) {
282 device = r.out.ctr.ctr1->array[j].device;
283 if (!test_NetCharDevQGetInfo(p, mem_ctx, device)) {
293 /**************************/
295 /**************************/
296 static BOOL test_NetConnEnum(struct dcerpc_pipe *p,
300 struct srvsvc_NetConnEnum r;
301 struct srvsvc_NetConnCtr0 c0;
302 uint32_t levels[] = {0, 1};
306 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
307 r.in.path = talloc_asprintf(mem_ctx,"%s","ADMIN$");
309 r.in.ctr.ctr0->count = 0;
310 r.in.ctr.ctr0->array = NULL;
311 r.in.max_buffer = (uint32_t)-1;
312 r.in.resume_handle = NULL;
314 for (i=0;i<ARRAY_SIZE(levels);i++) {
316 r.in.level = levels[i];
317 printf("testing NetConnEnum level %u\n", r.in.level);
318 status = dcerpc_srvsvc_NetConnEnum(p, mem_ctx, &r);
319 if (!NT_STATUS_IS_OK(status)) {
320 printf("NetConnEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
324 if (!W_ERROR_IS_OK(r.out.result)) {
325 printf("NetConnEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
333 /**************************/
335 /**************************/
336 static BOOL test_NetFileEnum(struct dcerpc_pipe *p,
340 struct srvsvc_NetFileEnum r;
341 struct srvsvc_NetFileCtr3 c3;
342 uint32_t levels[] = {2, 3};
346 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
350 r.in.ctr.ctr3->count = 0;
351 r.in.ctr.ctr3->array = NULL;
352 r.in.max_buffer = (uint32_t)4096;
353 r.in.resume_handle = NULL;
355 for (i=0;i<ARRAY_SIZE(levels);i++) {
357 r.in.level = levels[i];
358 printf("testing NetFileEnum level %u\n", r.in.level);
359 status = dcerpc_srvsvc_NetFileEnum(p, mem_ctx, &r);
360 if (!NT_STATUS_IS_OK(status)) {
361 printf("NetFileEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
365 if (!W_ERROR_IS_OK(r.out.result)) {
366 printf("NetFileEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
374 /**************************/
376 /**************************/
377 static BOOL test_NetSessEnum(struct dcerpc_pipe *p,
381 struct srvsvc_NetSessEnum r;
382 struct srvsvc_NetSessCtr0 c0;
383 uint32_t levels[] = {0, 1, 2, 10, 502};
387 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
391 r.in.ctr.ctr0->count = 0;
392 r.in.ctr.ctr0->array = NULL;
393 r.in.max_buffer = (uint32_t)-1;
394 r.in.resume_handle = NULL;
396 for (i=0;i<ARRAY_SIZE(levels);i++) {
398 r.in.level = levels[i];
399 printf("testing NetSessEnum level %u\n", r.in.level);
400 status = dcerpc_srvsvc_NetSessEnum(p, mem_ctx, &r);
401 if (!NT_STATUS_IS_OK(status)) {
402 printf("NetSessEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
406 if (!W_ERROR_IS_OK(r.out.result)) {
407 printf("NetSessEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
415 /**************************/
416 /* srvsvc_NetShare */
417 /**************************/
418 static BOOL test_NetShareGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
419 const char *sharename)
422 struct srvsvc_NetShareGetInfo r;
423 uint32_t levels[] = {0, 1, 2, 501, 502, 1005};
427 r.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
428 r.in.share_name = sharename;
430 for (i=0;i<ARRAY_SIZE(levels);i++) {
432 r.in.level = levels[i];
434 printf("testing NetShareGetInfo level %u on share '%s'\n",
435 r.in.level, r.in.share_name);
437 status = dcerpc_srvsvc_NetShareGetInfo(p, mem_ctx, &r);
438 if (!NT_STATUS_IS_OK(status)) {
439 printf("NetShareGetInfo level %u on share '%s' failed - %s\n",
440 r.in.level, r.in.share_name, nt_errstr(status));
444 if (!W_ERROR_IS_OK(r.out.result)) {
445 printf("NetShareGetInfo level %u on share '%s' failed - %s\n",
446 r.in.level, r.in.share_name, win_errstr(r.out.result));
454 static BOOL test_NetShareCheck(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
455 const char *device_name)
458 struct srvsvc_NetShareCheck r;
461 r.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
462 r.in.device_name = device_name;
464 printf("testing NetShareCheck on device '%s'\n", r.in.device_name);
466 status = dcerpc_srvsvc_NetShareCheck(p, mem_ctx, &r);
467 if (!NT_STATUS_IS_OK(status)) {
468 printf("dcerpc_srvsvc_NetShareCheck on device '%s' failed - %s\n",
469 r.in.device_name, nt_errstr(status));
471 } else if (!W_ERROR_IS_OK(r.out.result)) {
472 printf("NetShareCheck on device '%s' failed - %s\n",
473 r.in.device_name, win_errstr(r.out.result));
480 /**************************/
481 /* srvsvc_NetShare */
482 /**************************/
483 static BOOL test_NetShareEnumAll(struct dcerpc_pipe *p,
487 struct srvsvc_NetShareEnumAll r;
488 struct srvsvc_NetShareCtr0 c0;
489 uint32_t levels[] = {0, 1, 2, 501, 502};
492 uint32_t resume_handle;
496 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
498 r.in.max_buffer = (uint32_t)-1;
499 r.in.resume_handle = &resume_handle;
500 r.out.resume_handle = &resume_handle;
502 for (i=0;i<ARRAY_SIZE(levels);i++) {
507 r.in.level = levels[i];
508 printf("testing NetShareEnumAll level %u\n", r.in.level);
509 status = dcerpc_srvsvc_NetShareEnumAll(p, mem_ctx, &r);
510 if (!NT_STATUS_IS_OK(status)) {
511 printf("NetShareEnumAll level %u failed - %s\n", r.in.level, nt_errstr(status));
515 if (!W_ERROR_IS_OK(r.out.result)) {
516 printf("NetShareEnumAll level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
520 /* call srvsvc_NetShareGetInfo for each returned share */
521 if (r.in.level == 2) {
522 for (j=0;j<r.out.ctr.ctr2->count;j++) {
525 name = r.out.ctr.ctr2->array[j].name;
526 if (!test_NetShareGetInfo(p, mem_ctx, name)) {
529 device = r.out.ctr.ctr2->array[j].path;
530 if (!test_NetShareCheck(p, mem_ctx, device)) {
540 static BOOL test_NetShareEnum(struct dcerpc_pipe *p,
544 struct srvsvc_NetShareEnum r;
545 struct srvsvc_NetShareCtr0 c0;
546 uint32_t levels[] = {0, 1, 2, 502};
550 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
552 r.in.ctr.ctr0->count = 0;
553 r.in.ctr.ctr0->array = NULL;
554 r.in.max_buffer = (uint32_t)-1;
555 r.in.resume_handle = NULL;
557 for (i=0;i<ARRAY_SIZE(levels);i++) {
559 r.in.level = levels[i];
560 printf("testing NetShareEnum level %u\n", r.in.level);
561 status = dcerpc_srvsvc_NetShareEnum(p, mem_ctx, &r);
562 if (!NT_STATUS_IS_OK(status)) {
563 printf("NetShareEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
567 if (!W_ERROR_IS_OK(r.out.result)) {
568 printf("NetShareEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
576 /**************************/
578 /**************************/
579 static BOOL test_NetSrvGetInfo(struct dcerpc_pipe *p,
583 struct srvsvc_NetSrvGetInfo r;
584 struct srvsvc_NetSrvInfo503 i503;
585 uint32_t levels[] = {100, 101, 102, 502, 503};
588 uint32_t resume_handle;
592 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
594 for (i=0;i<ARRAY_SIZE(levels);i++) {
597 r.in.level = levels[i];
598 printf("testing NetSrvGetInfo level %u\n", r.in.level);
599 status = dcerpc_srvsvc_NetSrvGetInfo(p, mem_ctx, &r);
600 if (!NT_STATUS_IS_OK(status)) {
601 printf("NetSrvGetInfo level %u failed - %s\n", r.in.level, nt_errstr(status));
605 if (!W_ERROR_IS_OK(r.out.result)) {
606 printf("NetSrvGetInfo level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
614 /**************************/
616 /**************************/
617 static BOOL test_NetDiskEnum(struct dcerpc_pipe *p,
621 struct srvsvc_NetDiskEnum r;
622 uint32_t levels[] = {0};
625 uint32_t resume_handle=0;
627 r.in.server_unc = NULL;
628 r.in.resume_handle = &resume_handle;
629 r.in.disks.discs = NULL;
631 for (i=0;i<ARRAY_SIZE(levels);i++) {
633 r.in.level = levels[i];
634 printf("testing NetDiskEnum level %u\n", r.in.level);
635 status = dcerpc_srvsvc_NetDiskEnum(p, mem_ctx, &r);
636 if (!NT_STATUS_IS_OK(status)) {
637 NDR_PRINT_OUT_DEBUG(srvsvc_NetDiskEnum, &r);
638 printf("NetDiskEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
642 if (!W_ERROR_IS_OK(r.out.result)) {
643 printf("NetDiskEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
651 /**************************/
652 /* srvsvc_NetTransport */
653 /**************************/
654 static BOOL test_NetTransportEnum(struct dcerpc_pipe *p,
658 struct srvsvc_NetTransportEnum r;
659 struct srvsvc_NetTransportCtr0 c0;
660 uint32_t levels[] = {0, 1};
664 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
665 r.in.transports.ctr0 = &c0;
666 r.in.transports.ctr0->count = 0;
667 r.in.transports.ctr0->array = NULL;
668 r.in.max_buffer = (uint32_t)-1;
669 r.in.resume_handle = NULL;
671 for (i=0;i<ARRAY_SIZE(levels);i++) {
673 r.in.level = levels[i];
674 printf("testing NetTransportEnum level %u\n", r.in.level);
675 status = dcerpc_srvsvc_NetTransportEnum(p, mem_ctx, &r);
676 if (!NT_STATUS_IS_OK(status)) {
677 printf("NetTransportEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
681 if (!W_ERROR_IS_OK(r.out.result)) {
682 printf("NetTransportEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
690 /**************************/
691 /* srvsvc_NetRemoteTOD */
692 /**************************/
693 static BOOL test_NetRemoteTOD(struct dcerpc_pipe *p,
697 struct srvsvc_NetRemoteTOD r;
700 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
703 printf("testing NetRemoteTOD\n");
704 status = dcerpc_srvsvc_NetRemoteTOD(p, mem_ctx, &r);
705 if (!NT_STATUS_IS_OK(status)) {
706 printf("NetRemoteTOD failed - %s\n", nt_errstr(status));
709 if (!W_ERROR_IS_OK(r.out.result)) {
710 printf("NetRemoteTOD failed - %s\n", win_errstr(r.out.result));
716 BOOL torture_rpc_srvsvc(struct torture_context *torture)
719 struct dcerpc_pipe *p;
723 mem_ctx = talloc_init("torture_rpc_srvsvc");
725 status = torture_rpc_connection(mem_ctx, &p, &dcerpc_table_srvsvc);
726 if (!NT_STATUS_IS_OK(status)) {
727 talloc_free(mem_ctx);
731 if (!test_NetCharDevEnum(p, mem_ctx)) {
735 if (!test_NetCharDevQEnum(p, mem_ctx)) {
739 if (!test_NetConnEnum(p, mem_ctx)) {
743 if (!test_NetFileEnum(p, mem_ctx)) {
747 if (!test_NetSessEnum(p, mem_ctx)) {
751 if (!test_NetShareEnumAll(p, mem_ctx)) {
755 if (!test_NetSrvGetInfo(p, mem_ctx)) {
759 if (!test_NetDiskEnum(p, mem_ctx)) {
763 if (!test_NetTransportEnum(p, mem_ctx)) {
767 if (!test_NetRemoteTOD(p, mem_ctx)) {
771 if (!test_NetShareEnum(p, mem_ctx)) {
775 talloc_free(mem_ctx);