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/>.
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
,
32 struct srvsvc_NetCharDevGetInfo r
;
33 union srvsvc_NetCharDevInfo info
;
34 uint32_t levels
[] = {0, 1};
37 r
.in
.server_unc
= talloc_asprintf(tctx
,"\\\\%s",dcerpc_server_name(p
));
38 r
.in
.device_name
= devname
;
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");
53 static bool test_NetCharDevControl(struct dcerpc_pipe
*p
, struct torture_context
*tctx
,
57 struct srvsvc_NetCharDevControl r
;
58 uint32_t opcodes
[] = {0, 1};
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
++) {
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");
77 static bool test_NetCharDevEnum(struct torture_context
*tctx
,
78 struct dcerpc_pipe
*p
)
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};
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
++) {
101 info_ctr
.level
= levels
[i
];
103 switch(info_ctr
.level
) {
106 info_ctr
.ctr
.ctr0
= &c0
;
110 info_ctr
.ctr
.ctr0
= &c1
;
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
));
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
++) {
126 device
= r
.out
.info_ctr
->ctr
.ctr1
->array
[j
].device
;
127 if (!test_NetCharDevGetInfo(p
, tctx
, device
)) {
130 if (!test_NetCharDevControl(p
, tctx
, device
)) {
140 /**************************/
141 /* srvsvc_NetCharDevQ */
142 /**************************/
143 static bool test_NetCharDevQGetInfo(struct dcerpc_pipe
*p
, struct torture_context
*tctx
,
144 const char *devicequeue
)
147 struct srvsvc_NetCharDevQGetInfo r
;
148 union srvsvc_NetCharDevQInfo info
;
149 uint32_t levels
[] = {0, 1};
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");
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");
170 static bool test_NetCharDevQSetInfo(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
171 const char *devicequeue
)
174 struct srvsvc_NetCharDevQSetInfo r
;
176 uint32_t levels
[] = {0, 1};
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
++) {
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
) {
191 r
.in
.info
.info0
= talloc(mem_ctx
, struct srvsvc_NetCharDevQInfo0
);
192 r
.in
.info
.info0
->device
= r
.in
.queue_name
;
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;
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
));
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
));
224 static bool test_NetCharDevQEnum(struct torture_context
*tctx
,
225 struct dcerpc_pipe
*p
)
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};
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
++) {
249 info_ctr
.level
= levels
[i
];
251 switch (info_ctr
.level
) {
254 info_ctr
.ctr
.ctr0
= &c0
;
258 info_ctr
.ctr
.ctr1
= &c1
;
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
));
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
++) {
273 device
= r
.out
.info_ctr
->ctr
.ctr1
->array
[j
].device
;
274 if (!test_NetCharDevQGetInfo(p
, tctx
, device
)) {
284 /**************************/
286 /**************************/
287 static bool test_NetConnEnum(struct torture_context
*tctx
,
288 struct dcerpc_pipe
*p
)
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};
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
) {
315 info_ctr
.ctr
.ctr0
= &c0
;
319 info_ctr
.ctr
.ctr1
= &c1
;
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
));
334 /**************************/
336 /**************************/
337 static bool test_NetFileEnum(struct torture_context
*tctx
,
338 struct dcerpc_pipe
*p
)
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};
349 ZERO_STRUCT(info_ctr
);
351 r
.in
.server_unc
= talloc_asprintf(tctx
,"\\\\%s",dcerpc_server_name(p
));
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
) {
366 info_ctr
.ctr
.ctr2
= &c2
;
370 info_ctr
.ctr
.ctr3
= &c3
;
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
));
384 /**************************/
386 /**************************/
387 static bool test_NetSessEnum(struct torture_context
*tctx
,
388 struct dcerpc_pipe
*p
)
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};
402 ZERO_STRUCT(info_ctr
);
404 r
.in
.server_unc
= talloc_asprintf(tctx
,"\\\\%s",dcerpc_server_name(p
));
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
) {
419 info_ctr
.ctr
.ctr0
= &c0
;
423 info_ctr
.ctr
.ctr1
= &c1
;
427 info_ctr
.ctr
.ctr2
= &c2
;
431 info_ctr
.ctr
.ctr10
= &c10
;
435 info_ctr
.ctr
.ctr502
= &c502
;
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
));
450 /**************************/
451 /* srvsvc_NetShare */
452 /**************************/
453 static bool test_NetShareCheck(struct dcerpc_pipe
*p
, struct torture_context
*tctx
,
454 const char *device_name
)
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
;
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");
474 static bool test_NetShareGetInfo(struct torture_context
*tctx
,
475 struct dcerpc_pipe
*p
,
476 const char *sharename
, bool admin
)
479 struct srvsvc_NetShareGetInfo r
;
480 union srvsvc_NetShareInfo info
;
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
},
495 r
.in
.server_unc
= talloc_asprintf(tctx
, "\\\\%s", dcerpc_server_name(p
));
496 r
.in
.share_name
= sharename
;
499 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
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
)) {
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
)
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
;
549 { 0, WERR_UNKNOWN_LEVEL
},
552 { 501, WERR_UNKNOWN_LEVEL
},
557 /* { 1007, WERR_OK }, */
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
;
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
;
588 for (i
= 0; i
< ARRAY_SIZE(levels
); i
++) {
590 r
.in
.level
= levels
[i
].level
;
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
) {
598 info
.info0
= talloc(tctx
, struct srvsvc_NetShareInfo0
);
599 info
.info0
->name
= r
.in
.share_name
;
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");
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
;
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;
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
;
639 info
.info1004
= talloc(tctx
, struct srvsvc_NetShareInfo1004
);
640 info
.info1004
->comment
= talloc_strdup(tctx
, "test comment 1004");
643 info
.info1005
= talloc(tctx
, struct srvsvc_NetShareInfo1005
);
644 info
.info1005
->dfs_flags
= 0;
647 info
.info1006
= talloc(tctx
, struct srvsvc_NetShareInfo1006
);
648 info
.info1006
->max_users
= 1006;
651 info.info1007 = talloc(tctx, struct srvsvc_NetShareInfo1007);
652 info.info1007->flags = 0;
653 info.info1007->alternate_directory_name = talloc_strdup(tctx, "test");
657 info
.info1501
= talloc_zero(tctx
, struct sec_desc_buf
);
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
;
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
) {
681 torture_assert_str_equal(tctx
, q
.out
.info
->info502
->comment
, "test comment 1", "comment");
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");
689 torture_assert_str_equal(tctx
, q
.out
.info
->info501
->comment
, "test comment 501", "comment");
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");
697 torture_assert_str_equal(tctx
, q
.out
.info
->info1004
->comment
, "test comment 1004",
703 torture_assert_int_equal(tctx
, q
.out
.info
->info1006
->max_users
, 1006, "Max users");
713 d
.in
.share_name
= r
.in
.share_name
;
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");
723 /**************************/
724 /* srvsvc_NetShare */
725 /**************************/
726 static bool test_NetShareEnumAll(struct torture_context
*tctx
,
727 struct dcerpc_pipe
*p
,
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;
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
},
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
++) {
768 info_ctr
.level
= levels
[i
].level
;
770 switch (info_ctr
.level
) {
773 info_ctr
.ctr
.ctr0
= &c0
;
777 info_ctr
.ctr
.ctr1
= &c1
;
781 info_ctr
.ctr
.ctr2
= &c2
;
785 info_ctr
.ctr
.ctr501
= &c501
;
789 info_ctr
.ctr
.ctr502
= &c502
;
793 expected
= levels
[i
].anon_status
;
794 if (admin
) expected
= levels
[i
].admin_status
;
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
++) {
807 name
= r
.out
.info_ctr
->ctr
.ctr2
->array
[j
].name
;
808 if (!test_NetShareGetInfo(tctx
, p
, name
, admin
)) {
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
)
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;
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
},
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
++) {
865 info_ctr
.level
= levels
[i
].level
;
867 switch (info_ctr
.level
) {
870 info_ctr
.ctr
.ctr0
= &c0
;
874 info_ctr
.ctr
.ctr1
= &c1
;
878 info_ctr
.ctr
.ctr2
= &c2
;
882 info_ctr
.ctr
.ctr501
= &c501
;
886 info_ctr
.ctr
.ctr502
= &c502
;
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");
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 /**************************/
916 /**************************/
917 static bool test_NetSrvGetInfo(struct torture_context
*tctx
,
918 struct dcerpc_pipe
*p
)
921 struct srvsvc_NetSrvGetInfo r
;
922 union srvsvc_NetSrvInfo info
;
923 uint32_t levels
[] = {100, 101, 102, 502, 503};
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
];
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
));
942 /**************************/
944 /**************************/
945 static bool test_NetDiskEnum(struct torture_context
*tctx
,
946 struct dcerpc_pipe
*p
)
949 struct srvsvc_NetDiskEnum r
;
950 struct srvsvc_NetDiskInfo info
;
951 uint32_t totalentries
= 0;
952 uint32_t levels
[] = {0};
954 uint32_t resume_handle
=0;
958 r
.in
.server_unc
= NULL
;
959 r
.in
.resume_handle
= &resume_handle
;
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");
977 /**************************/
978 /* srvsvc_NetTransport */
979 /**************************/
980 static bool test_NetTransportEnum(struct torture_context
*tctx
,
981 struct dcerpc_pipe
*p
)
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};
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
) {
1007 transports
.ctr
.ctr0
= &ctr0
;
1011 transports
.ctr
.ctr1
= &ctr1
;
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
));
1025 /**************************/
1026 /* srvsvc_NetRemoteTOD */
1027 /**************************/
1028 static bool test_NetRemoteTOD(struct torture_context
*tctx
,
1029 struct dcerpc_pipe
*p
)
1032 struct srvsvc_NetRemoteTOD r
;
1033 struct srvsvc_NetRemoteTODInfo
*info
= NULL
;
1035 r
.in
.server_unc
= talloc_asprintf(tctx
,"\\\\%s",dcerpc_server_name(p
));
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");
1046 /**************************/
1047 /* srvsvc_NetName */
1048 /**************************/
1050 static bool test_NetNameValidate(struct torture_context
*tctx
,
1051 struct dcerpc_pipe
*p
)
1054 struct srvsvc_NetNameValidate r
;
1059 r
.in
.server_unc
= talloc_asprintf(tctx
, "\\\\%s", dcerpc_server_name(p
));
1062 d_printf("testing NetNameValidate\n");
1064 /* valid path types only between 1 and 13 */
1065 for (i
= 1; i
< 14; i
++) {
1068 /* let's limit ourselves to a maximum of 4096 bytes */
1069 r
.in
.name
= name
= talloc_array(tctx
, char, 4097);
1076 /* Find maximum length accepted by this type */
1079 memset(name
, 'A', n
);
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",
1089 if (W_ERROR_IS_OK(r
.out
.result
)) {
1091 n
+= (max
- min
+ 1)/2;
1095 if ((min
+ 1) >= max
) break; /* found it */
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",
1121 if (!W_ERROR_IS_OK(r
.out
.result
)) {
1122 invalidc
= talloc_asprintf_append_buffer(invalidc
, "%c", (char)n
);
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;
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",
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
);