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 "librpc/gen_ndr/ndr_srvsvc.h"
25 /**************************/
26 /* srvsvc_NetCharDev */
27 /**************************/
28 static BOOL test_NetCharDevGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
32 struct srvsvc_NetCharDevGetInfo r;
33 uint32_t levels[] = {0, 1};
37 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
38 r.in.device_name = devname;
40 for (i=0;i<ARRAY_SIZE(levels);i++) {
42 r.in.level = levels[i];
43 printf("testing NetCharDevGetInfo level %u on device '%s'\n",
44 r.in.level, r.in.device_name);
45 status = dcerpc_srvsvc_NetCharDevGetInfo(p, mem_ctx, &r);
46 if (!NT_STATUS_IS_OK(status)) {
47 printf("NetCharDevGetInfo level %u on device '%s' failed - %s\n",
48 r.in.level, r.in.device_name, nt_errstr(status));
52 if (!W_ERROR_IS_OK(r.out.result)) {
53 printf("NetCharDevGetInfo level %u on device '%s' failed - %s\n",
54 r.in.level, r.in.device_name, win_errstr(r.out.result));
62 static BOOL test_NetCharDevControl(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
66 struct srvsvc_NetCharDevControl r;
67 uint32_t opcodes[] = {0, 1};
71 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
72 r.in.device_name = devname;
74 for (i=0;i<ARRAY_SIZE(opcodes);i++) {
76 r.in.opcode = opcodes[i];
77 printf("testing NetCharDevControl opcode %u on device '%s'\n",
78 r.in.opcode, r.in.device_name);
79 status = dcerpc_srvsvc_NetCharDevControl(p, mem_ctx, &r);
80 if (!NT_STATUS_IS_OK(status)) {
81 printf("NetCharDevControl opcode %u failed - %s\n", r.in.opcode, nt_errstr(status));
85 if (!W_ERROR_IS_OK(r.out.result)) {
86 printf("NetCharDevControl opcode %u failed - %s\n", r.in.opcode, win_errstr(r.out.result));
94 static BOOL test_NetCharDevEnum(struct dcerpc_pipe *p,
98 struct srvsvc_NetCharDevEnum r;
99 struct srvsvc_NetCharDevCtr0 c0;
100 uint32_t levels[] = {0, 1};
104 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
106 r.in.ctr.ctr0->count = 0;
107 r.in.ctr.ctr0->array = NULL;
108 r.in.max_buffer = (uint32)-1;
109 r.in.resume_handle = NULL;
111 for (i=0;i<ARRAY_SIZE(levels);i++) {
116 r.in.level = levels[i];
117 printf("testing NetCharDevEnum level %u\n", r.in.level);
118 status = dcerpc_srvsvc_NetCharDevEnum(p, mem_ctx, &r);
119 if (!NT_STATUS_IS_OK(status)) {
120 printf("NetCharDevEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
124 if (!W_ERROR_IS_OK(r.out.result)) {
125 printf("NetCharDevEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
129 /* call test_NetCharDevGetInfo and test_NetCharDevControl for each returned share */
130 if (r.in.level == 1) {
131 for (j=0;j<r.out.ctr.ctr1->count;j++) {
133 device = r.out.ctr.ctr1->array[j].device;
134 if (!test_NetCharDevGetInfo(p, mem_ctx, device)) {
137 if (!test_NetCharDevControl(p, mem_ctx, device)) {
147 /**************************/
148 /* srvsvc_NetCharDevQ */
149 /**************************/
150 static BOOL test_NetCharDevQGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
151 const char *devicequeue)
154 struct srvsvc_NetCharDevQGetInfo r;
155 uint32_t levels[] = {0, 1};
159 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
160 r.in.queue_name = devicequeue;
161 r.in.user = talloc_asprintf(mem_ctx,"Administrator");
163 for (i=0;i<ARRAY_SIZE(levels);i++) {
165 r.in.level = levels[i];
166 printf("testing NetCharDevQGetInfo level %u on devicequeue '%s'\n",
167 r.in.level, r.in.queue_name);
168 status = dcerpc_srvsvc_NetCharDevQGetInfo(p, mem_ctx, &r);
169 if (!NT_STATUS_IS_OK(status)) {
170 printf("NetCharDevQGetInfo level %u on devicequeue '%s' failed - %s\n",
171 r.in.level, r.in.queue_name, nt_errstr(status));
175 if (!W_ERROR_IS_OK(r.out.result)) {
176 printf("NetCharDevQGetInfo level %u on devicequeue '%s' failed - %s\n",
177 r.in.level, r.in.queue_name, win_errstr(r.out.result));
186 static BOOL test_NetCharDevQSetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
187 const char *devicequeue)
190 struct srvsvc_NetCharDevQSetInfo r;
192 uint32_t levels[] = {0, 1};
196 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
197 r.in.queue_name = devicequeue;
199 for (i=0;i<ARRAY_SIZE(levels);i++) {
202 r.in.level = levels[i];
203 printf("testing NetCharDevQSetInfo level %u on devicequeue '%s'\n",
204 r.in.level, devicequeue);
205 switch (r.in.level) {
207 r.in.info.info0 = talloc(mem_ctx, struct srvsvc_NetCharDevQInfo0);
208 r.in.info.info0->device = r.in.queue_name;
211 r.in.info.info1 = talloc(mem_ctx, struct srvsvc_NetCharDevQInfo1);
212 r.in.info.info1->device = r.in.queue_name;
213 r.in.info.info1->priority = 0x000;
214 r.in.info.info1->devices = r.in.queue_name;
215 r.in.info.info1->users = 0x000;
216 r.in.info.info1->num_ahead = 0x000;
221 r.in.parm_error = &parm_error;
222 status = dcerpc_srvsvc_NetCharDevQSetInfo(p, mem_ctx, &r);
223 if (!NT_STATUS_IS_OK(status)) {
224 printf("NetCharDevQSetInfo level %u on devicequeue '%s' failed - %s\n",
225 r.in.level, r.in.queue_name, nt_errstr(status));
229 if (!W_ERROR_IS_OK(r.out.result)) {
230 printf("NetCharDevQSetInfo level %u on devicequeue '%s' failed - %s\n",
231 r.in.level, r.in.queue_name, win_errstr(r.out.result));
240 static BOOL test_NetCharDevQEnum(struct dcerpc_pipe *p,
244 struct srvsvc_NetCharDevQEnum r;
245 struct srvsvc_NetCharDevQCtr0 c0;
246 uint32_t levels[] = {0, 1};
250 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
251 r.in.user = talloc_asprintf(mem_ctx,"%s","Administrator");
253 r.in.ctr.ctr0->count = 0;
254 r.in.ctr.ctr0->array = NULL;
255 r.in.max_buffer = (uint32)-1;
256 r.in.resume_handle = NULL;
258 for (i=0;i<ARRAY_SIZE(levels);i++) {
262 r.in.level = levels[i];
263 printf("testing NetCharDevQEnum level %u\n", r.in.level);
264 status = dcerpc_srvsvc_NetCharDevQEnum(p, mem_ctx, &r);
265 if (!NT_STATUS_IS_OK(status)) {
266 printf("NetCharDevQEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
270 if (!W_ERROR_IS_OK(r.out.result)) {
271 printf("NetCharDevQEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
275 /* call test_NetCharDevGetInfo and test_NetCharDevControl for each returned share */
276 if (r.in.level == 1) {
277 for (j=0;j<r.out.ctr.ctr1->count;j++) {
279 device = r.out.ctr.ctr1->array[j].device;
280 if (!test_NetCharDevQGetInfo(p, mem_ctx, device)) {
290 /**************************/
292 /**************************/
293 static BOOL test_NetConnEnum(struct dcerpc_pipe *p,
297 struct srvsvc_NetConnEnum r;
298 struct srvsvc_NetConnCtr0 c0;
299 uint32_t levels[] = {0, 1};
303 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
304 r.in.path = talloc_asprintf(mem_ctx,"%s","ADMIN$");
306 r.in.ctr.ctr0->count = 0;
307 r.in.ctr.ctr0->array = NULL;
308 r.in.max_buffer = (uint32_t)-1;
309 r.in.resume_handle = NULL;
311 for (i=0;i<ARRAY_SIZE(levels);i++) {
313 r.in.level = levels[i];
314 printf("testing NetConnEnum level %u\n", r.in.level);
315 status = dcerpc_srvsvc_NetConnEnum(p, mem_ctx, &r);
316 if (!NT_STATUS_IS_OK(status)) {
317 printf("NetConnEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
321 if (!W_ERROR_IS_OK(r.out.result)) {
322 printf("NetConnEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
330 /**************************/
332 /**************************/
333 static BOOL test_NetFileEnum(struct dcerpc_pipe *p,
337 struct srvsvc_NetFileEnum r;
338 struct srvsvc_NetFileCtr3 c3;
339 uint32_t levels[] = {2, 3};
343 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
347 r.in.ctr.ctr3->count = 0;
348 r.in.ctr.ctr3->array = NULL;
349 r.in.max_buffer = (uint32_t)4096;
350 r.in.resume_handle = NULL;
352 for (i=0;i<ARRAY_SIZE(levels);i++) {
354 r.in.level = levels[i];
355 printf("testing NetFileEnum level %u\n", r.in.level);
356 status = dcerpc_srvsvc_NetFileEnum(p, mem_ctx, &r);
357 if (!NT_STATUS_IS_OK(status)) {
358 printf("NetFileEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
362 if (!W_ERROR_IS_OK(r.out.result)) {
363 printf("NetFileEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
371 /**************************/
373 /**************************/
374 static BOOL test_NetSessEnum(struct dcerpc_pipe *p,
378 struct srvsvc_NetSessEnum r;
379 struct srvsvc_NetSessCtr0 c0;
380 uint32_t levels[] = {0, 1, 2, 10, 502};
384 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
388 r.in.ctr.ctr0->count = 0;
389 r.in.ctr.ctr0->array = NULL;
390 r.in.max_buffer = (uint32_t)-1;
391 r.in.resume_handle = NULL;
393 for (i=0;i<ARRAY_SIZE(levels);i++) {
395 r.in.level = levels[i];
396 printf("testing NetSessEnum level %u\n", r.in.level);
397 status = dcerpc_srvsvc_NetSessEnum(p, mem_ctx, &r);
398 if (!NT_STATUS_IS_OK(status)) {
399 printf("NetSessEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
403 if (!W_ERROR_IS_OK(r.out.result)) {
404 printf("NetSessEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
412 /**************************/
413 /* srvsvc_NetShare */
414 /**************************/
415 static BOOL test_NetShareGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
416 const char *sharename)
419 struct srvsvc_NetShareGetInfo r;
420 uint32_t levels[] = {0, 1, 2, 501, 502, 1005};
424 r.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
425 r.in.share_name = sharename;
427 for (i=0;i<ARRAY_SIZE(levels);i++) {
429 r.in.level = levels[i];
431 printf("testing NetShareGetInfo level %u on share '%s'\n",
432 r.in.level, r.in.share_name);
434 status = dcerpc_srvsvc_NetShareGetInfo(p, mem_ctx, &r);
435 if (!NT_STATUS_IS_OK(status)) {
436 printf("NetShareGetInfo level %u on share '%s' failed - %s\n",
437 r.in.level, r.in.share_name, nt_errstr(status));
441 if (!W_ERROR_IS_OK(r.out.result)) {
442 printf("NetShareGetInfo level %u on share '%s' failed - %s\n",
443 r.in.level, r.in.share_name, win_errstr(r.out.result));
451 static BOOL test_NetShareCheck(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
452 const char *device_name)
455 struct srvsvc_NetShareCheck r;
458 r.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
459 r.in.device_name = device_name;
461 printf("testing NetShareCheck on device '%s'\n", r.in.device_name);
463 status = dcerpc_srvsvc_NetShareCheck(p, mem_ctx, &r);
464 if (!NT_STATUS_IS_OK(status)) {
465 printf("dcerpc_srvsvc_NetShareCheck on device '%s' failed - %s\n",
466 r.in.device_name, nt_errstr(status));
468 } else if (!W_ERROR_IS_OK(r.out.result)) {
469 printf("NetShareCheck on device '%s' failed - %s\n",
470 r.in.device_name, win_errstr(r.out.result));
477 /**************************/
478 /* srvsvc_NetShare */
479 /**************************/
480 static BOOL test_NetShareEnumAll(struct dcerpc_pipe *p,
484 struct srvsvc_NetShareEnumAll r;
485 struct srvsvc_NetShareCtr0 c0;
486 uint32_t levels[] = {0, 1, 2, 501, 502};
489 uint32_t resume_handle;
493 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
495 r.in.max_buffer = (uint32_t)-1;
496 r.in.resume_handle = &resume_handle;
497 r.out.resume_handle = &resume_handle;
499 for (i=0;i<ARRAY_SIZE(levels);i++) {
504 r.in.level = levels[i];
505 printf("testing NetShareEnumAll level %u\n", r.in.level);
506 status = dcerpc_srvsvc_NetShareEnumAll(p, mem_ctx, &r);
507 if (!NT_STATUS_IS_OK(status)) {
508 printf("NetShareEnumAll level %u failed - %s\n", r.in.level, nt_errstr(status));
512 if (!W_ERROR_IS_OK(r.out.result)) {
513 printf("NetShareEnumAll level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
517 /* call srvsvc_NetShareGetInfo for each returned share */
518 if (r.in.level == 2) {
519 for (j=0;j<r.out.ctr.ctr2->count;j++) {
522 name = r.out.ctr.ctr2->array[j].name;
523 if (!test_NetShareGetInfo(p, mem_ctx, name)) {
526 device = r.out.ctr.ctr2->array[j].path;
527 if (!test_NetShareCheck(p, mem_ctx, device)) {
537 static BOOL test_NetShareEnum(struct dcerpc_pipe *p,
541 struct srvsvc_NetShareEnum r;
542 struct srvsvc_NetShareCtr0 c0;
543 uint32_t levels[] = {0, 1, 2, 502};
547 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
549 r.in.ctr.ctr0->count = 0;
550 r.in.ctr.ctr0->array = NULL;
551 r.in.max_buffer = (uint32_t)-1;
552 r.in.resume_handle = NULL;
554 for (i=0;i<ARRAY_SIZE(levels);i++) {
556 r.in.level = levels[i];
557 printf("testing NetShareEnum level %u\n", r.in.level);
558 status = dcerpc_srvsvc_NetShareEnum(p, mem_ctx, &r);
559 if (!NT_STATUS_IS_OK(status)) {
560 printf("NetShareEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
564 if (!W_ERROR_IS_OK(r.out.result)) {
565 printf("NetShareEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
573 /**************************/
575 /**************************/
576 static BOOL test_NetSrvGetInfo(struct dcerpc_pipe *p,
580 struct srvsvc_NetSrvGetInfo r;
581 struct srvsvc_NetSrvInfo503 i503;
582 uint32_t levels[] = {100, 101, 102, 502, 503};
585 uint32_t resume_handle;
589 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
591 for (i=0;i<ARRAY_SIZE(levels);i++) {
594 r.in.level = levels[i];
595 printf("testing NetSrvGetInfo level %u\n", r.in.level);
596 status = dcerpc_srvsvc_NetSrvGetInfo(p, mem_ctx, &r);
597 if (!NT_STATUS_IS_OK(status)) {
598 printf("NetSrvGetInfo level %u failed - %s\n", r.in.level, nt_errstr(status));
602 if (!W_ERROR_IS_OK(r.out.result)) {
603 printf("NetSrvGetInfo level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
611 /**************************/
613 /**************************/
614 static BOOL test_NetDiskEnum(struct dcerpc_pipe *p,
618 struct srvsvc_NetDiskEnum r;
619 uint32_t levels[] = {0};
622 uint32_t resume_handle=0;
624 r.in.server_unc = NULL;
626 r.in.resume_handle = &resume_handle;
627 r.in.ctr.ctr0 = NULL;
629 for (i=0;i<ARRAY_SIZE(levels);i++) {
631 r.in.level = levels[i];
632 printf("testing NetDiskEnum level %u\n", r.in.level);
633 status = dcerpc_srvsvc_NetDiskEnum(p, mem_ctx, &r);
634 if (!NT_STATUS_IS_OK(status)) {
635 NDR_PRINT_OUT_DEBUG(srvsvc_NetDiskEnum, &r);
636 printf("NetDiskEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
640 if (!W_ERROR_IS_OK(r.out.result)) {
641 printf("NetDiskEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
649 /**************************/
650 /* srvsvc_NetTransport */
651 /**************************/
652 static BOOL test_NetTransportEnum(struct dcerpc_pipe *p,
656 struct srvsvc_NetTransportEnum r;
657 struct srvsvc_NetTransportCtr0 c0;
658 uint32_t levels[] = {0, 1};
662 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
664 r.in.ctr.ctr0->count = 0;
665 r.in.ctr.ctr0->array = NULL;
666 r.in.max_buffer = (uint32_t)-1;
667 r.in.resume_handle = NULL;
669 for (i=0;i<ARRAY_SIZE(levels);i++) {
671 r.in.level = levels[i];
672 printf("testing NetTransportEnum level %u\n", r.in.level);
673 status = dcerpc_srvsvc_NetTransportEnum(p, mem_ctx, &r);
674 if (!NT_STATUS_IS_OK(status)) {
675 printf("NetTransportEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
679 if (!W_ERROR_IS_OK(r.out.result)) {
680 printf("NetTransportEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
688 /**************************/
689 /* srvsvc_NetRemoteTOD */
690 /**************************/
691 static BOOL test_NetRemoteTOD(struct dcerpc_pipe *p,
695 struct srvsvc_NetRemoteTOD r;
698 r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
701 printf("testing NetRemoteTOD\n");
702 status = dcerpc_srvsvc_NetRemoteTOD(p, mem_ctx, &r);
703 if (!NT_STATUS_IS_OK(status)) {
704 printf("NetRemoteTOD failed - %s\n", nt_errstr(status));
707 if (!W_ERROR_IS_OK(r.out.result)) {
708 printf("NetRemoteTOD failed - %s\n", win_errstr(r.out.result));
714 BOOL torture_rpc_srvsvc(void)
717 struct dcerpc_pipe *p;
721 mem_ctx = talloc_init("torture_rpc_srvsvc");
723 status = torture_rpc_connection(&p,
726 DCERPC_SRVSVC_VERSION);
727 if (!NT_STATUS_IS_OK(status)) {
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);
777 torture_rpc_close(p);