Line data Source code
1 : /*
2 : Unix SMB/CIFS implementation.
3 : test suite for srvsvc rpc operations
4 :
5 : Copyright (C) Stefan (metze) Metzmacher 2003
6 :
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.
11 :
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.
16 :
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/>.
19 : */
20 :
21 : #include "includes.h"
22 : #include "librpc/gen_ndr/ndr_srvsvc_c.h"
23 : #include "torture/rpc/torture_rpc.h"
24 :
25 : /**************************/
26 : /* srvsvc_NetCharDev */
27 : /**************************/
28 0 : static bool test_NetCharDevGetInfo(struct dcerpc_pipe *p, struct torture_context *tctx,
29 : const char *devname)
30 : {
31 0 : NTSTATUS status;
32 0 : struct srvsvc_NetCharDevGetInfo r;
33 0 : union srvsvc_NetCharDevInfo info;
34 0 : uint32_t levels[] = {0, 1};
35 0 : int i;
36 0 : struct dcerpc_binding_handle *b = p->binding_handle;
37 :
38 0 : r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
39 0 : r.in.device_name = devname;
40 0 : r.out.info = &info;
41 :
42 0 : for (i=0;i<ARRAY_SIZE(levels);i++) {
43 0 : r.in.level = levels[i];
44 0 : torture_comment(tctx, "Testing NetCharDevGetInfo level %u on device '%s'\n",
45 : r.in.level, r.in.device_name);
46 0 : status = dcerpc_srvsvc_NetCharDevGetInfo_r(b, tctx, &r);
47 0 : torture_assert_ntstatus_ok(tctx, status, "NetCharDevGetInfo failed");
48 0 : torture_assert_werr_ok(tctx, r.out.result, "NetCharDevGetInfo failed");
49 : }
50 :
51 0 : return true;
52 : }
53 :
54 0 : static bool test_NetCharDevControl(struct dcerpc_pipe *p, struct torture_context *tctx,
55 : const char *devname)
56 : {
57 0 : NTSTATUS status;
58 0 : struct srvsvc_NetCharDevControl r;
59 0 : uint32_t opcodes[] = {0, 1};
60 0 : int i;
61 0 : struct dcerpc_binding_handle *b = p->binding_handle;
62 :
63 0 : r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
64 0 : r.in.device_name = devname;
65 :
66 0 : for (i=0;i<ARRAY_SIZE(opcodes);i++) {
67 0 : ZERO_STRUCT(r.out);
68 0 : r.in.opcode = opcodes[i];
69 0 : torture_comment(tctx, "Testing NetCharDevControl opcode %u on device '%s'\n",
70 : r.in.opcode, r.in.device_name);
71 0 : status = dcerpc_srvsvc_NetCharDevControl_r(b, tctx, &r);
72 0 : torture_assert_ntstatus_ok(tctx, status, "NetCharDevControl failed");
73 0 : torture_assert_werr_ok(tctx, r.out.result, "NetCharDevControl failed");
74 : }
75 :
76 0 : return true;
77 : }
78 :
79 7 : static bool test_NetCharDevEnum(struct torture_context *tctx,
80 : struct dcerpc_pipe *p)
81 : {
82 0 : NTSTATUS status;
83 0 : struct srvsvc_NetCharDevEnum r;
84 0 : struct srvsvc_NetCharDevInfoCtr info_ctr;
85 0 : struct srvsvc_NetCharDevCtr0 c0;
86 0 : struct srvsvc_NetCharDevCtr0 c1;
87 7 : uint32_t totalentries = 0;
88 7 : uint32_t levels[] = {0, 1};
89 0 : int i;
90 7 : struct dcerpc_binding_handle *b = p->binding_handle;
91 :
92 7 : ZERO_STRUCT(info_ctr);
93 :
94 7 : r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
95 7 : r.in.info_ctr = &info_ctr;
96 7 : r.in.max_buffer = (uint32_t)-1;
97 7 : r.in.resume_handle = NULL;
98 7 : r.out.info_ctr = &info_ctr;
99 7 : r.out.totalentries = &totalentries;
100 :
101 13 : for (i=0;i<ARRAY_SIZE(levels);i++) {
102 0 : int j;
103 :
104 10 : info_ctr.level = levels[i];
105 :
106 10 : switch(info_ctr.level) {
107 7 : case 0:
108 7 : ZERO_STRUCT(c0);
109 7 : info_ctr.ctr.ctr0 = &c0;
110 7 : break;
111 3 : case 1:
112 3 : ZERO_STRUCT(c1);
113 3 : info_ctr.ctr.ctr0 = &c1;
114 3 : break;
115 : }
116 :
117 10 : torture_comment(tctx, "Testing NetCharDevEnum level %u\n", info_ctr.level);
118 10 : status = dcerpc_srvsvc_NetCharDevEnum_r(b, tctx, &r);
119 10 : torture_assert_ntstatus_ok(tctx, status, "NetCharDevEnum failed");
120 6 : if (!W_ERROR_IS_OK(r.out.result)) {
121 6 : torture_comment(tctx, "NetCharDevEnum failed: %s\n", win_errstr(r.out.result));
122 6 : continue;
123 : }
124 :
125 : /* call test_NetCharDevGetInfo and test_NetCharDevControl for each returned share */
126 0 : if (info_ctr.level == 1) {
127 0 : for (j=0;j<r.out.info_ctr->ctr.ctr1->count;j++) {
128 0 : const char *device;
129 0 : device = r.out.info_ctr->ctr.ctr1->array[j].device;
130 0 : if (!test_NetCharDevGetInfo(p, tctx, device)) {
131 0 : return false;
132 : }
133 0 : if (!test_NetCharDevControl(p, tctx, device)) {
134 0 : return false;
135 : }
136 : }
137 : }
138 : }
139 :
140 3 : return true;
141 : }
142 :
143 : /**************************/
144 : /* srvsvc_NetCharDevQ */
145 : /**************************/
146 0 : static bool test_NetCharDevQGetInfo(struct dcerpc_pipe *p, struct torture_context *tctx,
147 : const char *devicequeue)
148 : {
149 0 : NTSTATUS status;
150 0 : struct srvsvc_NetCharDevQGetInfo r;
151 0 : union srvsvc_NetCharDevQInfo info;
152 0 : uint32_t levels[] = {0, 1};
153 0 : int i;
154 0 : struct dcerpc_binding_handle *b = p->binding_handle;
155 :
156 0 : r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
157 0 : r.in.queue_name = devicequeue;
158 0 : r.in.user = talloc_asprintf(tctx,"Administrator");
159 0 : r.out.info = &info;
160 :
161 0 : for (i=0;i<ARRAY_SIZE(levels);i++) {
162 0 : r.in.level = levels[i];
163 0 : torture_comment(tctx, "Testing NetCharDevQGetInfo level %u on devicequeue '%s'\n",
164 : r.in.level, r.in.queue_name);
165 0 : status = dcerpc_srvsvc_NetCharDevQGetInfo_r(b, tctx, &r);
166 0 : torture_assert_ntstatus_ok(tctx, status, "NetCharDevQGetInfo failed");
167 0 : torture_assert_werr_ok(tctx, r.out.result, "NetCharDevQGetInfo failed");
168 : }
169 :
170 0 : return true;
171 : }
172 :
173 : #if 0
174 : static bool test_NetCharDevQSetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
175 : const char *devicequeue)
176 : {
177 : NTSTATUS status;
178 : struct srvsvc_NetCharDevQSetInfo r;
179 : uint32_t parm_error;
180 : uint32_t levels[] = {0, 1};
181 : int i;
182 : bool ret = true;
183 : struct dcerpc_binding_handle *b = p->binding_handle;
184 :
185 : r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
186 : r.in.queue_name = devicequeue;
187 :
188 : for (i=0;i<ARRAY_SIZE(levels);i++) {
189 : ZERO_STRUCT(r.out);
190 : parm_error = 0;
191 : r.in.level = levels[i];
192 : d_printf("testing NetCharDevQSetInfo level %u on devicequeue '%s'\n",
193 : r.in.level, devicequeue);
194 : switch (r.in.level) {
195 : case 0:
196 : r.in.info.info0 = talloc(mem_ctx, struct srvsvc_NetCharDevQInfo0);
197 : r.in.info.info0->device = r.in.queue_name;
198 : break;
199 : case 1:
200 : r.in.info.info1 = talloc(mem_ctx, struct srvsvc_NetCharDevQInfo1);
201 : r.in.info.info1->device = r.in.queue_name;
202 : r.in.info.info1->priority = 0x000;
203 : r.in.info.info1->devices = r.in.queue_name;
204 : r.in.info.info1->users = 0x000;
205 : r.in.info.info1->num_ahead = 0x000;
206 : break;
207 : default:
208 : break;
209 : }
210 : r.in.parm_error = &parm_error;
211 : status = dcerpc_srvsvc_NetCharDevQSetInfo_r(b, mem_ctx, &r);
212 : if (!NT_STATUS_IS_OK(status)) {
213 : d_printf("NetCharDevQSetInfo level %u on devicequeue '%s' failed - %s\n",
214 : r.in.level, r.in.queue_name, nt_errstr(status));
215 : ret = false;
216 : continue;
217 : }
218 : if (!W_ERROR_IS_OK(r.out.result)) {
219 : d_printf("NetCharDevQSetInfo level %u on devicequeue '%s' failed - %s\n",
220 : r.in.level, r.in.queue_name, win_errstr(r.out.result));
221 : continue;
222 : }
223 : }
224 :
225 : return ret;
226 : }
227 : #endif
228 :
229 7 : static bool test_NetCharDevQEnum(struct torture_context *tctx,
230 : struct dcerpc_pipe *p)
231 : {
232 0 : NTSTATUS status;
233 0 : struct srvsvc_NetCharDevQEnum r;
234 0 : struct srvsvc_NetCharDevQInfoCtr info_ctr;
235 0 : struct srvsvc_NetCharDevQCtr0 c0;
236 0 : struct srvsvc_NetCharDevQCtr1 c1;
237 7 : uint32_t totalentries = 0;
238 7 : uint32_t levels[] = {0, 1};
239 0 : int i;
240 7 : struct dcerpc_binding_handle *b = p->binding_handle;
241 :
242 7 : ZERO_STRUCT(info_ctr);
243 :
244 7 : r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
245 7 : r.in.user = talloc_asprintf(tctx,"%s","Administrator");
246 7 : r.in.info_ctr = &info_ctr;
247 7 : r.in.max_buffer = (uint32_t)-1;
248 7 : r.in.resume_handle = NULL;
249 7 : r.out.totalentries = &totalentries;
250 7 : r.out.info_ctr = &info_ctr;
251 :
252 13 : for (i=0;i<ARRAY_SIZE(levels);i++) {
253 0 : int j;
254 :
255 10 : info_ctr.level = levels[i];
256 :
257 10 : switch (info_ctr.level) {
258 7 : case 0:
259 7 : ZERO_STRUCT(c0);
260 7 : info_ctr.ctr.ctr0 = &c0;
261 7 : break;
262 3 : case 1:
263 3 : ZERO_STRUCT(c1);
264 3 : info_ctr.ctr.ctr1 = &c1;
265 3 : break;
266 : }
267 10 : torture_comment(tctx, "Testing NetCharDevQEnum level %u\n", info_ctr.level);
268 10 : status = dcerpc_srvsvc_NetCharDevQEnum_r(b, tctx, &r);
269 10 : torture_assert_ntstatus_ok(tctx, status, "NetCharDevQEnum failed");
270 6 : if (!W_ERROR_IS_OK(r.out.result)) {
271 6 : torture_comment(tctx, "NetCharDevQEnum failed: %s\n", win_errstr(r.out.result));
272 6 : continue;
273 : }
274 :
275 : /* call test_NetCharDevGetInfo and test_NetCharDevControl for each returned share */
276 0 : if (info_ctr.level == 1) {
277 0 : for (j=0;j<r.out.info_ctr->ctr.ctr1->count;j++) {
278 0 : const char *device;
279 0 : device = r.out.info_ctr->ctr.ctr1->array[j].device;
280 0 : if (!test_NetCharDevQGetInfo(p, tctx, device)) {
281 0 : return false;
282 : }
283 : }
284 : }
285 : }
286 :
287 3 : return true;
288 : }
289 :
290 : /**************************/
291 : /* srvsvc_NetConn */
292 : /**************************/
293 7 : static bool test_NetConnEnum(struct torture_context *tctx,
294 : struct dcerpc_pipe *p)
295 : {
296 0 : NTSTATUS status;
297 0 : struct srvsvc_NetConnEnum r;
298 0 : struct srvsvc_NetConnInfoCtr info_ctr;
299 0 : struct srvsvc_NetConnCtr0 c0;
300 0 : struct srvsvc_NetConnCtr1 c1;
301 7 : uint32_t totalentries = 0;
302 7 : uint32_t levels[] = {0, 1};
303 0 : int i;
304 7 : struct dcerpc_binding_handle *b = p->binding_handle;
305 :
306 7 : ZERO_STRUCT(info_ctr);
307 :
308 7 : r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
309 7 : r.in.path = talloc_asprintf(tctx,"%s","IPC$");
310 7 : r.in.info_ctr = &info_ctr;
311 7 : r.in.max_buffer = (uint32_t)-1;
312 7 : r.in.resume_handle = NULL;
313 7 : r.out.totalentries = &totalentries;
314 7 : r.out.info_ctr = &info_ctr;
315 :
316 21 : for (i=0;i<ARRAY_SIZE(levels);i++) {
317 14 : info_ctr.level = levels[i];
318 :
319 14 : switch (info_ctr.level) {
320 7 : case 0:
321 7 : ZERO_STRUCT(c0);
322 7 : info_ctr.ctr.ctr0 = &c0;
323 7 : break;
324 7 : case 1:
325 7 : ZERO_STRUCT(c1);
326 7 : info_ctr.ctr.ctr1 = &c1;
327 7 : break;
328 : }
329 :
330 14 : torture_comment(tctx, "Testing NetConnEnum level %u\n", info_ctr.level);
331 14 : status = dcerpc_srvsvc_NetConnEnum_r(b, tctx, &r);
332 14 : torture_assert_ntstatus_ok(tctx, status, "NetConnEnum failed");
333 14 : if (!W_ERROR_IS_OK(r.out.result)) {
334 6 : torture_comment(tctx, "NetConnEnum failed: %s\n", win_errstr(r.out.result));
335 : }
336 : }
337 :
338 7 : return true;
339 : }
340 :
341 : /**************************/
342 : /* srvsvc_NetFile */
343 : /**************************/
344 7 : static bool test_NetFileEnum(struct torture_context *tctx,
345 : struct dcerpc_pipe *p)
346 : {
347 0 : NTSTATUS status;
348 0 : struct srvsvc_NetFileEnum r;
349 0 : struct srvsvc_NetFileInfoCtr info_ctr;
350 0 : struct srvsvc_NetFileCtr2 c2;
351 0 : struct srvsvc_NetFileCtr3 c3;
352 7 : uint32_t totalentries = 0;
353 7 : uint32_t levels[] = {2, 3};
354 0 : int i;
355 7 : struct dcerpc_binding_handle *b = p->binding_handle;
356 :
357 7 : ZERO_STRUCT(info_ctr);
358 :
359 7 : r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
360 7 : r.in.path = NULL;
361 7 : r.in.user = NULL;
362 7 : r.in.info_ctr = &info_ctr;
363 7 : r.in.max_buffer = (uint32_t)4096;
364 7 : r.in.resume_handle = NULL;
365 7 : r.out.totalentries = &totalentries;
366 7 : r.out.info_ctr = &info_ctr;
367 :
368 21 : for (i=0;i<ARRAY_SIZE(levels);i++) {
369 14 : info_ctr.level = levels[i];
370 :
371 14 : switch (info_ctr.level) {
372 7 : case 2:
373 7 : ZERO_STRUCT(c2);
374 7 : info_ctr.ctr.ctr2 = &c2;
375 7 : break;
376 7 : case 3:
377 7 : ZERO_STRUCT(c3);
378 7 : info_ctr.ctr.ctr3 = &c3;
379 7 : break;
380 : }
381 14 : torture_comment(tctx, "Testing NetFileEnum level %u\n", info_ctr.level);
382 14 : status = dcerpc_srvsvc_NetFileEnum_r(b, tctx, &r);
383 14 : torture_assert_ntstatus_ok(tctx, status, "NetFileEnum failed");
384 14 : if (!W_ERROR_IS_OK(r.out.result)) {
385 10 : torture_comment(tctx, "NetFileEnum failed: %s\n", win_errstr(r.out.result));
386 : }
387 : }
388 :
389 7 : return true;
390 : }
391 :
392 : /**************************/
393 : /* srvsvc_NetSess */
394 : /**************************/
395 7 : static bool test_NetSessEnum(struct torture_context *tctx,
396 : struct dcerpc_pipe *p)
397 : {
398 0 : NTSTATUS status;
399 0 : struct srvsvc_NetSessEnum r;
400 0 : struct srvsvc_NetSessInfoCtr info_ctr;
401 0 : struct srvsvc_NetSessCtr0 c0;
402 0 : struct srvsvc_NetSessCtr1 c1;
403 0 : struct srvsvc_NetSessCtr2 c2;
404 0 : struct srvsvc_NetSessCtr10 c10;
405 0 : struct srvsvc_NetSessCtr502 c502;
406 7 : uint32_t totalentries = 0;
407 7 : uint32_t levels[] = {0, 1, 2, 10, 502};
408 0 : int i;
409 7 : struct dcerpc_binding_handle *b = p->binding_handle;
410 :
411 7 : ZERO_STRUCT(info_ctr);
412 :
413 7 : r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
414 7 : r.in.client = NULL;
415 7 : r.in.user = NULL;
416 7 : r.in.info_ctr = &info_ctr;
417 7 : r.in.max_buffer = (uint32_t)-1;
418 7 : r.in.resume_handle = NULL;
419 7 : r.out.totalentries = &totalentries;
420 7 : r.out.info_ctr = &info_ctr;
421 :
422 42 : for (i=0;i<ARRAY_SIZE(levels);i++) {
423 35 : info_ctr.level = levels[i];
424 :
425 35 : switch (info_ctr.level) {
426 7 : case 0:
427 7 : ZERO_STRUCT(c0);
428 7 : info_ctr.ctr.ctr0 = &c0;
429 7 : break;
430 7 : case 1:
431 7 : ZERO_STRUCT(c1);
432 7 : info_ctr.ctr.ctr1 = &c1;
433 7 : break;
434 7 : case 2:
435 7 : ZERO_STRUCT(c2);
436 7 : info_ctr.ctr.ctr2 = &c2;
437 7 : break;
438 7 : case 10:
439 7 : ZERO_STRUCT(c10);
440 7 : info_ctr.ctr.ctr10 = &c10;
441 7 : break;
442 7 : case 502:
443 7 : ZERO_STRUCT(c502);
444 7 : info_ctr.ctr.ctr502 = &c502;
445 7 : break;
446 : }
447 :
448 35 : torture_comment(tctx, "Testing NetSessEnum level %u\n", info_ctr.level);
449 35 : status = dcerpc_srvsvc_NetSessEnum_r(b, tctx, &r);
450 35 : torture_assert_ntstatus_ok(tctx, status, "NetSessEnum failed");
451 35 : if (!W_ERROR_IS_OK(r.out.result)) {
452 27 : torture_comment(tctx, "NetSessEnum failed: %s\n", win_errstr(r.out.result));
453 : }
454 : }
455 :
456 7 : return true;
457 : }
458 :
459 : /**************************/
460 : /* srvsvc_NetShare */
461 : /**************************/
462 50 : static bool test_NetShareCheck(struct dcerpc_pipe *p, struct torture_context *tctx,
463 : const char *device_name)
464 : {
465 0 : NTSTATUS status;
466 0 : struct srvsvc_NetShareCheck r;
467 0 : enum srvsvc_ShareType type;
468 50 : struct dcerpc_binding_handle *b = p->binding_handle;
469 :
470 50 : r.in.server_unc = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
471 50 : r.in.device_name = device_name;
472 50 : r.out.type = &type;
473 :
474 50 : torture_comment(tctx,
475 : "Testing NetShareCheck on device '%s'\n", r.in.device_name);
476 :
477 50 : status = dcerpc_srvsvc_NetShareCheck_r(b, tctx, &r);
478 50 : torture_assert_ntstatus_ok(tctx, status, "dcerpc_srvsvc_NetShareCheck failed");
479 42 : torture_assert_werr_ok(tctx, r.out.result, "NetShareCheck failed");
480 :
481 42 : return true;
482 : }
483 :
484 57 : static bool test_NetShareGetInfo(struct torture_context *tctx,
485 : struct dcerpc_pipe *p,
486 : const char *sharename, bool admin)
487 : {
488 0 : NTSTATUS status;
489 0 : struct srvsvc_NetShareGetInfo r;
490 0 : union srvsvc_NetShareInfo info;
491 0 : struct {
492 : uint32_t level;
493 : WERROR anon_status;
494 : WERROR admin_status;
495 57 : } levels[] = {
496 : { 0, WERR_OK, WERR_OK },
497 : { 1, WERR_OK, WERR_OK },
498 : { 2, WERR_ACCESS_DENIED, WERR_OK },
499 : { 501, WERR_OK, WERR_OK },
500 : { 502, WERR_ACCESS_DENIED, WERR_OK },
501 : { 1005, WERR_OK, WERR_OK },
502 : };
503 0 : int i;
504 57 : struct dcerpc_binding_handle *b = p->binding_handle;
505 :
506 57 : r.in.server_unc = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
507 57 : r.in.share_name = sharename;
508 57 : r.out.info = &info;
509 :
510 351 : for (i=0;i<ARRAY_SIZE(levels);i++) {
511 0 : WERROR expected;
512 :
513 306 : r.in.level = levels[i].level;
514 306 : expected = levels[i].anon_status;
515 306 : if (admin) expected = levels[i].admin_status;
516 :
517 306 : torture_comment(tctx, "Testing NetShareGetInfo level %u on share '%s'\n",
518 : r.in.level, r.in.share_name);
519 :
520 306 : status = dcerpc_srvsvc_NetShareGetInfo_r(b, tctx, &r);
521 306 : torture_assert_ntstatus_ok(tctx, status, "NetShareGetInfo failed");
522 306 : torture_assert_werr_equal(tctx, r.out.result, expected, "NetShareGetInfo failed");
523 :
524 305 : if (r.in.level != 2) continue;
525 53 : if (!r.out.info->info2 || !r.out.info->info2->path) continue;
526 50 : if (!test_NetShareCheck(p, tctx, r.out.info->info2->path)) {
527 8 : return false;
528 : }
529 : }
530 :
531 45 : return true;
532 : }
533 :
534 7 : static bool test_NetShareGetInfoAdminFull(struct torture_context *tctx,
535 : struct dcerpc_pipe *p)
536 : {
537 7 : return test_NetShareGetInfo(tctx, p, "IPC$", true);
538 : }
539 :
540 7 : static bool test_NetShareGetInfoAdminAnon(struct torture_context *tctx,
541 : struct dcerpc_pipe *p)
542 : {
543 7 : return test_NetShareGetInfo(tctx, p, "IPC$", false);
544 : }
545 :
546 0 : static bool test_NetShareAddSetDel(struct torture_context *tctx,
547 : struct dcerpc_pipe *p)
548 : {
549 0 : NTSTATUS status;
550 0 : struct srvsvc_NetShareAdd a;
551 0 : struct srvsvc_NetShareSetInfo r;
552 0 : struct srvsvc_NetShareGetInfo q;
553 0 : struct srvsvc_NetShareDel d;
554 0 : struct sec_desc_buf sd_buf;
555 0 : union srvsvc_NetShareInfo info;
556 0 : struct {
557 : uint32_t level;
558 : WERROR expected;
559 0 : } levels[] = {
560 : { 0, WERR_INVALID_LEVEL },
561 : { 1, WERR_OK },
562 : { 2, WERR_OK },
563 : { 501, WERR_INVALID_LEVEL },
564 : { 502, WERR_OK },
565 : { 1004, WERR_OK },
566 : { 1005, WERR_OK },
567 : { 1006, WERR_OK },
568 : /* { 1007, WERR_OK }, */
569 : { 1501, WERR_OK },
570 : };
571 0 : int i;
572 0 : struct dcerpc_binding_handle *b = p->binding_handle;
573 :
574 0 : a.in.server_unc = r.in.server_unc = q.in.server_unc = d.in.server_unc =
575 0 : talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
576 0 : r.in.share_name = talloc_strdup(tctx, "testshare");
577 :
578 0 : info.info2 = talloc(tctx, struct srvsvc_NetShareInfo2);
579 0 : info.info2->name = r.in.share_name;
580 0 : info.info2->type = STYPE_DISKTREE;
581 0 : info.info2->comment = talloc_strdup(tctx, "test comment");
582 0 : info.info2->permissions = 123434566;
583 0 : info.info2->max_users = -1;
584 0 : info.info2->current_users = 0;
585 0 : info.info2->path = talloc_strdup(tctx, "C:\\");
586 0 : info.info2->password = NULL;
587 :
588 0 : a.in.info = &info;
589 0 : a.in.level = 2;
590 0 : a.in.parm_error = NULL;
591 :
592 0 : status = dcerpc_srvsvc_NetShareAdd_r(b, tctx, &a);
593 0 : torture_assert_ntstatus_ok(tctx, status, "NetShareAdd level 2 on share 'testshare' failed");
594 0 : torture_assert_werr_ok(tctx, a.out.result, "NetShareAdd level 2 on share 'testshare' failed");
595 :
596 0 : r.in.parm_error = NULL;
597 :
598 0 : q.in.level = 502;
599 :
600 0 : for (i = 0; i < ARRAY_SIZE(levels); i++) {
601 :
602 0 : r.in.level = levels[i].level;
603 0 : ZERO_STRUCT(r.out);
604 :
605 0 : torture_comment(tctx, "Testing NetShareSetInfo level %u on share '%s'\n",
606 : r.in.level, r.in.share_name);
607 :
608 0 : switch (levels[i].level) {
609 0 : case 0:
610 0 : info.info0 = talloc(tctx, struct srvsvc_NetShareInfo0);
611 0 : info.info0->name = r.in.share_name;
612 0 : break;
613 0 : case 1:
614 0 : info.info1 = talloc(tctx, struct srvsvc_NetShareInfo1);
615 0 : info.info1->name = r.in.share_name;
616 0 : info.info1->type = STYPE_DISKTREE;
617 0 : info.info1->comment = talloc_strdup(tctx, "test comment 1");
618 0 : break;
619 0 : case 2:
620 0 : info.info2 = talloc(tctx, struct srvsvc_NetShareInfo2);
621 0 : info.info2->name = r.in.share_name;
622 0 : info.info2->type = STYPE_DISKTREE;
623 0 : info.info2->comment = talloc_strdup(tctx, "test comment 2");
624 0 : info.info2->permissions = 0;
625 0 : info.info2->max_users = 2;
626 0 : info.info2->current_users = 1;
627 0 : info.info2->path = talloc_strdup(tctx, "::BLaH::"); /* "C:\\"); */
628 0 : info.info2->password = NULL;
629 0 : break;
630 0 : case 501:
631 0 : info.info501 = talloc(tctx, struct srvsvc_NetShareInfo501);
632 0 : info.info501->name = r.in.share_name;
633 0 : info.info501->type = STYPE_DISKTREE;
634 0 : info.info501->comment = talloc_strdup(tctx, "test comment 501");
635 0 : info.info501->csc_policy = 0;
636 0 : break;
637 0 : case 502:
638 0 : ZERO_STRUCT(sd_buf);
639 0 : info.info502 = talloc(tctx, struct srvsvc_NetShareInfo502);
640 0 : info.info502->name = r.in.share_name;
641 0 : info.info502->type = STYPE_DISKTREE;
642 0 : info.info502->comment = talloc_strdup(tctx, "test comment 502");
643 0 : info.info502->permissions = 0;
644 0 : info.info502->max_users = 502;
645 0 : info.info502->current_users = 1;
646 0 : info.info502->path = talloc_strdup(tctx, "C:\\");
647 0 : info.info502->password = NULL;
648 0 : info.info502->sd_buf = sd_buf;
649 0 : break;
650 0 : case 1004:
651 0 : info.info1004 = talloc(tctx, struct srvsvc_NetShareInfo1004);
652 0 : info.info1004->comment = talloc_strdup(tctx, "test comment 1004");
653 0 : break;
654 0 : case 1005:
655 0 : info.info1005 = talloc(tctx, struct srvsvc_NetShareInfo1005);
656 0 : info.info1005->dfs_flags = 0;
657 0 : break;
658 0 : case 1006:
659 0 : info.info1006 = talloc(tctx, struct srvsvc_NetShareInfo1006);
660 0 : info.info1006->max_users = 1006;
661 0 : break;
662 : /* case 1007:
663 : info.info1007 = talloc(tctx, struct srvsvc_NetShareInfo1007);
664 : info.info1007->flags = 0;
665 : info.info1007->alternate_directory_name = talloc_strdup(tctx, "test");
666 : break;
667 : */
668 0 : case 1501:
669 0 : info.info1501 = talloc_zero(tctx, struct sec_desc_buf);
670 0 : break;
671 : }
672 :
673 0 : r.in.info = &info;
674 :
675 0 : status = dcerpc_srvsvc_NetShareSetInfo_r(b, tctx, &r);
676 0 : torture_assert_ntstatus_ok(tctx, status, "NetShareGetInfo failed");
677 0 : torture_assert_werr_equal(tctx, r.out.result, levels[i].expected, "NetShareSetInfo failed");
678 :
679 0 : q.in.share_name = r.in.share_name;
680 0 : q.out.info = &info;
681 :
682 0 : status = dcerpc_srvsvc_NetShareGetInfo_r(b, tctx, &q);
683 0 : torture_assert_ntstatus_ok(tctx, status, "NetShareGetInfo failed");
684 0 : torture_assert_werr_ok(tctx, q.out.result, "NetShareGetInfo failed");
685 :
686 0 : torture_assert_str_equal(tctx, q.out.info->info502->name, r.in.share_name,
687 : "share name invalid");
688 :
689 0 : switch (levels[i].level) {
690 0 : case 0:
691 0 : break;
692 0 : case 1:
693 0 : torture_assert_str_equal(tctx, q.out.info->info502->comment, "test comment 1", "comment");
694 0 : break;
695 0 : case 2:
696 0 : torture_assert_str_equal(tctx, q.out.info->info2->comment, "test comment 2", "comment");
697 0 : torture_assert_int_equal(tctx, q.out.info->info2->max_users, 2, "max users");
698 0 : torture_assert_str_equal(tctx, q.out.info->info2->path, "C:\\", "path");
699 0 : break;
700 0 : case 501:
701 0 : torture_assert_str_equal(tctx, q.out.info->info501->comment, "test comment 501", "comment");
702 0 : break;
703 0 : case 502:
704 0 : torture_assert_str_equal(tctx, q.out.info->info502->comment, "test comment 502", "comment");
705 0 : torture_assert_int_equal(tctx, q.out.info->info502->max_users, 502, "max users");
706 0 : torture_assert_str_equal(tctx, q.out.info->info502->path, "C:\\", "path");
707 0 : break;
708 0 : case 1004:
709 0 : torture_assert_str_equal(tctx, q.out.info->info1004->comment, "test comment 1004",
710 : "comment");
711 0 : break;
712 0 : case 1005:
713 0 : break;
714 0 : case 1006:
715 0 : torture_assert_int_equal(tctx, q.out.info->info1006->max_users, 1006, "Max users");
716 0 : break;
717 : /* case 1007:
718 : break;
719 : */
720 0 : case 1501:
721 0 : break;
722 : }
723 : }
724 :
725 0 : d.in.share_name = r.in.share_name;
726 0 : d.in.reserved = 0;
727 :
728 0 : status = dcerpc_srvsvc_NetShareDel_r(b, tctx, &d);
729 0 : torture_assert_ntstatus_ok(tctx, status, "NetShareDel on share 'testshare502' failed");
730 0 : torture_assert_werr_ok(tctx, a.out.result, "NetShareDel on share 'testshare502' failed");
731 :
732 0 : return true;
733 : }
734 :
735 : /**************************/
736 : /* srvsvc_NetShare */
737 : /**************************/
738 14 : static bool test_NetShareEnumAll(struct torture_context *tctx,
739 : struct dcerpc_pipe *p,
740 : bool admin)
741 : {
742 0 : NTSTATUS status;
743 0 : struct srvsvc_NetShareEnumAll r;
744 0 : struct srvsvc_NetShareInfoCtr info_ctr;
745 0 : struct srvsvc_NetShareCtr0 c0;
746 0 : struct srvsvc_NetShareCtr1 c1;
747 0 : struct srvsvc_NetShareCtr2 c2;
748 0 : struct srvsvc_NetShareCtr501 c501;
749 0 : struct srvsvc_NetShareCtr502 c502;
750 14 : uint32_t totalentries = 0;
751 0 : struct {
752 : uint32_t level;
753 : WERROR anon_status;
754 : WERROR admin_status;
755 14 : } levels[] = {
756 : { 0, WERR_OK, WERR_OK },
757 : { 1, WERR_OK, WERR_OK },
758 : { 2, WERR_ACCESS_DENIED, WERR_OK },
759 : { 501, WERR_ACCESS_DENIED, WERR_OK },
760 : { 502, WERR_ACCESS_DENIED, WERR_OK },
761 : };
762 0 : int i;
763 0 : uint32_t resume_handle;
764 14 : struct dcerpc_binding_handle *b = p->binding_handle;
765 :
766 14 : ZERO_STRUCT(info_ctr);
767 :
768 14 : r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
769 14 : r.in.info_ctr = &info_ctr;
770 14 : r.in.max_buffer = (uint32_t)-1;
771 14 : r.in.resume_handle = &resume_handle;
772 14 : r.out.resume_handle = &resume_handle;
773 14 : r.out.totalentries = &totalentries;
774 14 : r.out.info_ctr = &info_ctr;
775 :
776 60 : for (i=0;i<ARRAY_SIZE(levels);i++) {
777 :
778 0 : int j;
779 0 : WERROR expected;
780 :
781 54 : info_ctr.level = levels[i].level;
782 :
783 54 : switch (info_ctr.level) {
784 14 : case 0:
785 14 : ZERO_STRUCT(c0);
786 14 : info_ctr.ctr.ctr0 = &c0;
787 14 : break;
788 14 : case 1:
789 14 : ZERO_STRUCT(c1);
790 14 : info_ctr.ctr.ctr1 = &c1;
791 14 : break;
792 14 : case 2:
793 14 : ZERO_STRUCT(c2);
794 14 : info_ctr.ctr.ctr2 = &c2;
795 14 : break;
796 6 : case 501:
797 6 : ZERO_STRUCT(c501);
798 6 : info_ctr.ctr.ctr501 = &c501;
799 6 : break;
800 6 : case 502:
801 6 : ZERO_STRUCT(c502);
802 6 : info_ctr.ctr.ctr502 = &c502;
803 6 : break;
804 : }
805 :
806 54 : expected = levels[i].anon_status;
807 54 : if (admin) expected = levels[i].admin_status;
808 :
809 54 : resume_handle = 0;
810 :
811 54 : torture_comment(tctx, "Testing NetShareEnumAll level %u\n", info_ctr.level);
812 54 : status = dcerpc_srvsvc_NetShareEnumAll_r(b, tctx, &r);
813 54 : torture_assert_ntstatus_ok(tctx, status, "NetShareEnumAll failed");
814 54 : torture_assert_werr_equal(tctx, r.out.result, expected, "NetShareEnumAll failed");
815 :
816 : /* call srvsvc_NetShareGetInfo for each returned share */
817 50 : if (info_ctr.level == 2 && r.out.info_ctr->ctr.ctr2) {
818 49 : for (j=0;j<r.out.info_ctr->ctr.ctr2->count;j++) {
819 0 : const char *name;
820 43 : name = r.out.info_ctr->ctr.ctr2->array[j].name;
821 43 : if (!test_NetShareGetInfo(tctx, p, name, admin)) {
822 4 : return false;
823 : }
824 : }
825 : }
826 : }
827 :
828 6 : return true;
829 : }
830 :
831 7 : static bool test_NetShareEnumAllFull(struct torture_context *tctx,
832 : struct dcerpc_pipe *p)
833 : {
834 7 : return test_NetShareEnumAll(tctx, p, true);
835 : }
836 :
837 7 : static bool test_NetShareEnumAllAnon(struct torture_context *tctx,
838 : struct dcerpc_pipe *p)
839 : {
840 7 : return test_NetShareEnumAll(tctx, p, false);
841 : }
842 :
843 14 : static bool test_NetShareEnum(struct torture_context *tctx,
844 : struct dcerpc_pipe *p, bool admin)
845 : {
846 0 : NTSTATUS status;
847 0 : struct srvsvc_NetShareEnum r;
848 0 : struct srvsvc_NetShareInfoCtr info_ctr;
849 0 : struct srvsvc_NetShareCtr0 c0;
850 0 : struct srvsvc_NetShareCtr1 c1;
851 0 : struct srvsvc_NetShareCtr2 c2;
852 0 : struct srvsvc_NetShareCtr501 c501;
853 0 : struct srvsvc_NetShareCtr502 c502;
854 14 : uint32_t totalentries = 0;
855 0 : struct {
856 : uint32_t level;
857 : WERROR anon_status;
858 : WERROR admin_status;
859 14 : } levels[] = {
860 : { 0, WERR_OK, WERR_OK },
861 : { 1, WERR_OK, WERR_OK },
862 : { 2, WERR_ACCESS_DENIED, WERR_OK },
863 : { 501, WERR_INVALID_LEVEL, WERR_INVALID_LEVEL },
864 : { 502, WERR_ACCESS_DENIED, WERR_OK },
865 : };
866 0 : int i;
867 14 : struct dcerpc_binding_handle *b = p->binding_handle;
868 :
869 14 : r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
870 14 : r.in.info_ctr = &info_ctr;
871 14 : r.in.max_buffer = (uint32_t)-1;
872 14 : r.in.resume_handle = NULL;
873 14 : r.out.totalentries = &totalentries;
874 14 : r.out.info_ctr = &info_ctr;
875 :
876 64 : for (i=0;i<ARRAY_SIZE(levels);i++) {
877 0 : WERROR expected;
878 :
879 58 : info_ctr.level = levels[i].level;
880 :
881 58 : switch (info_ctr.level) {
882 14 : case 0:
883 14 : ZERO_STRUCT(c0);
884 14 : info_ctr.ctr.ctr0 = &c0;
885 14 : break;
886 14 : case 1:
887 14 : ZERO_STRUCT(c1);
888 14 : info_ctr.ctr.ctr1 = &c1;
889 14 : break;
890 14 : case 2:
891 14 : ZERO_STRUCT(c2);
892 14 : info_ctr.ctr.ctr2 = &c2;
893 14 : break;
894 10 : case 501:
895 10 : ZERO_STRUCT(c501);
896 10 : info_ctr.ctr.ctr501 = &c501;
897 10 : break;
898 6 : case 502:
899 6 : ZERO_STRUCT(c502);
900 6 : info_ctr.ctr.ctr502 = &c502;
901 6 : break;
902 : }
903 :
904 58 : expected = levels[i].anon_status;
905 58 : if (admin) expected = levels[i].admin_status;
906 :
907 58 : torture_comment(tctx, "Testing NetShareEnum level %u\n", info_ctr.level);
908 58 : status = dcerpc_srvsvc_NetShareEnum_r(b, tctx, &r);
909 58 : torture_assert_ntstatus_ok(tctx, status, "NetShareEnum failed");
910 58 : torture_assert_werr_equal(tctx, r.out.result, expected, "NetShareEnum failed");
911 : }
912 :
913 6 : return true;
914 : }
915 :
916 7 : static bool test_NetShareEnumFull(struct torture_context *tctx,
917 : struct dcerpc_pipe *p)
918 : {
919 7 : return test_NetShareEnum(tctx, p, true);
920 : }
921 :
922 7 : static bool test_NetShareEnumAnon(struct torture_context *tctx,
923 : struct dcerpc_pipe *p)
924 : {
925 7 : return test_NetShareEnum(tctx, p, false);
926 : }
927 :
928 : /**************************/
929 : /* srvsvc_NetSrv */
930 : /**************************/
931 7 : static bool test_NetSrvGetInfo(struct torture_context *tctx,
932 : struct dcerpc_pipe *p)
933 : {
934 0 : NTSTATUS status;
935 0 : struct srvsvc_NetSrvGetInfo r;
936 0 : union srvsvc_NetSrvInfo info;
937 7 : uint32_t levels[] = {100, 101, 102, 502, 503};
938 0 : int i;
939 7 : struct dcerpc_binding_handle *b = p->binding_handle;
940 :
941 7 : r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
942 :
943 42 : for (i=0;i<ARRAY_SIZE(levels);i++) {
944 35 : r.in.level = levels[i];
945 35 : r.out.info = &info;
946 35 : torture_comment(tctx, "Testing NetSrvGetInfo level %u\n", r.in.level);
947 35 : status = dcerpc_srvsvc_NetSrvGetInfo_r(b, tctx, &r);
948 35 : torture_assert_ntstatus_ok(tctx, status, "NetSrvGetInfo failed");
949 35 : if (!W_ERROR_IS_OK(r.out.result)) {
950 14 : torture_comment(tctx, "NetSrvGetInfo failed: %s\n", win_errstr(r.out.result));
951 : }
952 : }
953 :
954 7 : return true;
955 : }
956 :
957 : /**************************/
958 : /* srvsvc_NetDisk */
959 : /**************************/
960 7 : static bool test_NetDiskEnum(struct torture_context *tctx,
961 : struct dcerpc_pipe *p)
962 : {
963 0 : NTSTATUS status;
964 0 : struct srvsvc_NetDiskEnum r;
965 0 : struct srvsvc_NetDiskInfo info;
966 7 : uint32_t totalentries = 0;
967 7 : uint32_t levels[] = {0};
968 0 : int i;
969 7 : uint32_t resume_handle=0;
970 7 : struct dcerpc_binding_handle *b = p->binding_handle;
971 :
972 7 : ZERO_STRUCT(info);
973 7 : ZERO_STRUCT(r);
974 :
975 7 : r.in.server_unc = NULL;
976 7 : r.in.resume_handle = &resume_handle;
977 7 : r.in.info = &info;
978 7 : r.out.info = &info;
979 7 : r.out.totalentries = &totalentries;
980 7 : r.out.resume_handle = &resume_handle;
981 :
982 14 : for (i=0;i<ARRAY_SIZE(levels);i++) {
983 7 : ZERO_STRUCTP(r.out.info);
984 7 : r.in.level = levels[i];
985 7 : torture_comment(tctx, "Testing NetDiskEnum level %u\n", r.in.level);
986 7 : status = dcerpc_srvsvc_NetDiskEnum_r(b, tctx, &r);
987 7 : torture_assert_ntstatus_ok(tctx, status, "NetDiskEnum failed");
988 7 : torture_assert_werr_ok(tctx, r.out.result, "NetDiskEnum failed");
989 : }
990 :
991 7 : return true;
992 : }
993 :
994 : /**************************/
995 : /* srvsvc_NetTransport */
996 : /**************************/
997 7 : static bool test_NetTransportEnum(struct torture_context *tctx,
998 : struct dcerpc_pipe *p)
999 : {
1000 0 : NTSTATUS status;
1001 0 : struct srvsvc_NetTransportEnum r;
1002 0 : struct srvsvc_NetTransportInfoCtr transports;
1003 0 : struct srvsvc_NetTransportCtr0 ctr0;
1004 0 : struct srvsvc_NetTransportCtr1 ctr1;
1005 :
1006 7 : uint32_t totalentries = 0;
1007 7 : uint32_t levels[] = {0, 1};
1008 0 : int i;
1009 7 : struct dcerpc_binding_handle *b = p->binding_handle;
1010 :
1011 7 : ZERO_STRUCT(transports);
1012 :
1013 7 : r.in.server_unc = talloc_asprintf(tctx,"\\\\%s", dcerpc_server_name(p));
1014 7 : r.in.transports = &transports;
1015 7 : r.in.max_buffer = (uint32_t)-1;
1016 7 : r.in.resume_handle = NULL;
1017 7 : r.out.totalentries = &totalentries;
1018 7 : r.out.transports = &transports;
1019 :
1020 13 : for (i=0;i<ARRAY_SIZE(levels);i++) {
1021 10 : transports.level = levels[i];
1022 10 : switch (transports.level) {
1023 7 : case 0:
1024 7 : ZERO_STRUCT(ctr0);
1025 7 : transports.ctr.ctr0 = &ctr0;
1026 7 : break;
1027 3 : case 1:
1028 3 : ZERO_STRUCT(ctr1);
1029 3 : transports.ctr.ctr1 = &ctr1;
1030 3 : break;
1031 : }
1032 10 : torture_comment(tctx, "Testing NetTransportEnum level %u\n", transports.level);
1033 10 : status = dcerpc_srvsvc_NetTransportEnum_r(b, tctx, &r);
1034 10 : torture_assert_ntstatus_ok(tctx, status, "NetTransportEnum failed");
1035 6 : if (!W_ERROR_IS_OK(r.out.result)) {
1036 6 : torture_comment(tctx, "unexpected result: %s\n", win_errstr(r.out.result));
1037 : }
1038 : }
1039 :
1040 3 : return true;
1041 : }
1042 :
1043 : /**************************/
1044 : /* srvsvc_NetRemoteTOD */
1045 : /**************************/
1046 7 : static bool test_NetRemoteTOD(struct torture_context *tctx,
1047 : struct dcerpc_pipe *p)
1048 : {
1049 0 : NTSTATUS status;
1050 0 : struct srvsvc_NetRemoteTOD r;
1051 7 : struct srvsvc_NetRemoteTODInfo *info = NULL;
1052 7 : struct dcerpc_binding_handle *b = p->binding_handle;
1053 :
1054 7 : r.in.server_unc = talloc_asprintf(tctx,"\\\\%s",dcerpc_server_name(p));
1055 7 : r.out.info = &info;
1056 :
1057 7 : torture_comment(tctx, "Testing NetRemoteTOD\n");
1058 7 : status = dcerpc_srvsvc_NetRemoteTOD_r(b, tctx, &r);
1059 7 : torture_assert_ntstatus_ok(tctx, status, "NetRemoteTOD failed");
1060 7 : torture_assert_werr_ok(tctx, r.out.result, "NetRemoteTOD failed");
1061 :
1062 7 : return true;
1063 : }
1064 :
1065 : /**************************/
1066 : /* srvsvc_NetName */
1067 : /**************************/
1068 :
1069 7 : static bool test_NetNameValidate(struct torture_context *tctx,
1070 : struct dcerpc_pipe *p)
1071 : {
1072 0 : NTSTATUS status;
1073 0 : struct srvsvc_NetNameValidate r;
1074 0 : char *invalidc;
1075 0 : char *name;
1076 0 : int i, n, min, max;
1077 7 : struct dcerpc_binding_handle *b = p->binding_handle;
1078 :
1079 7 : r.in.server_unc = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p));
1080 7 : r.in.flags = 0x0;
1081 :
1082 7 : d_printf("Testing NetNameValidate\n");
1083 :
1084 : /* valid path types only between 1 and 13 */
1085 98 : for (i = 1; i < 14; i++) {
1086 :
1087 117 : again:
1088 : /* let's limit ourselves to a maximum of 4096 bytes */
1089 182 : r.in.name = name = talloc_array(tctx, char, 4097);
1090 182 : max = 4096;
1091 182 : min = 0;
1092 182 : n = max;
1093 :
1094 0 : while (1) {
1095 :
1096 : /* Find maximum length accepted by this type */
1097 2444 : ZERO_STRUCT(r.out);
1098 2444 : r.in.name_type = i;
1099 2444 : memset(name, 'A', n);
1100 2444 : name[n] = '\0';
1101 :
1102 2444 : status = dcerpc_srvsvc_NetNameValidate_r(b, tctx, &r);
1103 2444 : if (!NT_STATUS_IS_OK(status)) {
1104 0 : d_printf("NetNameValidate failed while checking maximum size (%s)\n",
1105 : nt_errstr(status));
1106 0 : break;
1107 : }
1108 :
1109 2444 : if (W_ERROR_IS_OK(r.out.result)) {
1110 26 : min = n;
1111 26 : n += (max - min + 1)/2;
1112 26 : if (n == min) {
1113 : /*
1114 : * We did not move, so
1115 : * do not loop forever
1116 : */
1117 8 : break;
1118 : }
1119 18 : continue;
1120 :
1121 : } else {
1122 2418 : if ((min + 1) >= max) break; /* found it */
1123 :
1124 2244 : max = n;
1125 2244 : n -= (max - min)/2;
1126 2244 : continue;
1127 : }
1128 : }
1129 :
1130 182 : talloc_free(name);
1131 :
1132 182 : d_printf("Maximum length for type %2d, flags %08x: %d\n", i, r.in.flags, max);
1133 :
1134 : /* find invalid chars for this type check only ASCII between 0x20 and 0x7e */
1135 :
1136 182 : invalidc = talloc_strdup(tctx, "");
1137 :
1138 17290 : for (n = 0x20; n < 0x7e; n++) {
1139 17108 : r.in.name = name = talloc_asprintf(tctx, "%c", (char)n);
1140 :
1141 17108 : status = dcerpc_srvsvc_NetNameValidate_r(b, tctx, &r);
1142 17108 : if (!NT_STATUS_IS_OK(status)) {
1143 0 : d_printf("NetNameValidate failed while checking valid chars (%s)\n",
1144 : nt_errstr(status));
1145 0 : break;
1146 : }
1147 :
1148 17108 : if (!W_ERROR_IS_OK(r.out.result)) {
1149 16006 : invalidc = talloc_asprintf_append_buffer(invalidc, "%c", (char)n);
1150 : }
1151 :
1152 17108 : talloc_free(name);
1153 : }
1154 :
1155 182 : d_printf(" Invalid chars for type %2d, flags %08x: \"%s\"\n", i, r.in.flags, invalidc);
1156 :
1157 : /* only two values are accepted for flags: 0x0 and 0x80000000 */
1158 182 : if (r.in.flags == 0x0) {
1159 91 : r.in.flags = 0x80000000;
1160 91 : goto again;
1161 : }
1162 :
1163 91 : r.in.flags = 0x0;
1164 : }
1165 :
1166 7 : return true;
1167 : }
1168 :
1169 2354 : struct torture_suite *torture_rpc_srvsvc(TALLOC_CTX *mem_ctx)
1170 : {
1171 2354 : struct torture_suite *suite = torture_suite_create(mem_ctx, "srvsvc");
1172 125 : struct torture_rpc_tcase *tcase;
1173 125 : struct torture_test *test;
1174 :
1175 2354 : tcase = torture_suite_add_rpc_iface_tcase(suite, "srvsvc (admin access)", &ndr_table_srvsvc);
1176 :
1177 2354 : torture_rpc_tcase_add_test(tcase, "NetCharDevEnum", test_NetCharDevEnum);
1178 2354 : torture_rpc_tcase_add_test(tcase, "NetCharDevQEnum", test_NetCharDevQEnum);
1179 2354 : torture_rpc_tcase_add_test(tcase, "NetConnEnum", test_NetConnEnum);
1180 2354 : torture_rpc_tcase_add_test(tcase, "NetFileEnum", test_NetFileEnum);
1181 2354 : torture_rpc_tcase_add_test(tcase, "NetSessEnum", test_NetSessEnum);
1182 2354 : torture_rpc_tcase_add_test(tcase, "NetShareEnumAll", test_NetShareEnumAllFull);
1183 2354 : torture_rpc_tcase_add_test(tcase, "NetSrvGetInfo", test_NetSrvGetInfo);
1184 2354 : torture_rpc_tcase_add_test(tcase, "NetDiskEnum", test_NetDiskEnum);
1185 2354 : torture_rpc_tcase_add_test(tcase, "NetTransportEnum", test_NetTransportEnum);
1186 2354 : torture_rpc_tcase_add_test(tcase, "NetRemoteTOD", test_NetRemoteTOD);
1187 2354 : torture_rpc_tcase_add_test(tcase, "NetShareEnum", test_NetShareEnumFull);
1188 2354 : torture_rpc_tcase_add_test(tcase, "NetShareGetInfo", test_NetShareGetInfoAdminFull);
1189 2354 : test = torture_rpc_tcase_add_test(tcase, "NetShareAddSetDel",
1190 : test_NetShareAddSetDel);
1191 2354 : test->dangerous = true;
1192 2354 : torture_rpc_tcase_add_test(tcase, "NetNameValidate", test_NetNameValidate);
1193 :
1194 2354 : tcase = torture_suite_add_anon_rpc_iface_tcase(suite,
1195 : "srvsvc anonymous access",
1196 : &ndr_table_srvsvc);
1197 :
1198 2354 : torture_rpc_tcase_add_test(tcase, "NetShareEnumAll",
1199 : test_NetShareEnumAllAnon);
1200 2354 : torture_rpc_tcase_add_test(tcase, "NetShareEnum",
1201 : test_NetShareEnumAnon);
1202 2354 : torture_rpc_tcase_add_test(tcase, "NetShareGetInfo",
1203 : test_NetShareGetInfoAdminAnon);
1204 :
1205 2354 : return suite;
1206 : }
|