r1527: add NetCharDev torture tests
[metze/samba/wip.git] / source4 / torture / rpc / srvsvc.c
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 2 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, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23
24 /**************************/
25 /* srvsvc_NetCharDev      */
26 /**************************/
27 static BOOL test_NetCharDevGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
28                                 const char *devname)
29 {
30         NTSTATUS status;
31         struct srvsvc_NetCharDevGetInfo r;
32         uint32_t levels[] = {0, 1};
33         int i;
34         BOOL ret = True;
35
36         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
37         r.in.device_name = devname;
38
39         for (i=0;i<ARRAY_SIZE(levels);i++) {
40                 ZERO_STRUCT(r.out);
41                 r.in.level = levels[i];
42                 printf("testing NetCharDevGetInfo level %u on device '%s'\n",
43                         r.in.level, r.in.device_name);
44                 status = dcerpc_srvsvc_NetCharDevGetInfo(p, mem_ctx, &r);
45                 if (!NT_STATUS_IS_OK(status)) {
46                         printf("NetCharDevGetInfo level %u on device '%s' failed - %s\n",
47                                 r.in.level, r.in.device_name, nt_errstr(status));
48                         ret = False;
49                         continue;
50                 }
51                 if (!W_ERROR_IS_OK(r.out.result)) {
52                         printf("NetCharDevGetInfo level %u on device '%s' failed - %s\n",
53                                 r.in.level, r.in.device_name, win_errstr(r.out.result));
54                         continue;
55                 }
56         }
57
58         return ret;
59 }
60
61 static BOOL test_NetCharDevControl(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
62                                 const char *devname)
63 {
64         NTSTATUS status;
65         struct srvsvc_NetCharDevControl r;
66         uint32_t opcodes[] = {0, 1};
67         int i;
68         BOOL ret = True;
69
70         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
71         r.in.device_name = devname;
72
73         for (i=0;i<ARRAY_SIZE(opcodes);i++) {
74                 ZERO_STRUCT(r.out);
75                 r.in.opcode = opcodes[i];
76                 printf("testing NetCharDevControl opcode %u on device '%s'\n", 
77                         r.in.opcode, r.in.device_name);
78                 status = dcerpc_srvsvc_NetCharDevControl(p, mem_ctx, &r);
79                 if (!NT_STATUS_IS_OK(status)) {
80                         printf("NetCharDevControl opcode %u failed - %s\n", r.in.opcode, nt_errstr(status));
81                         ret = False;
82                         continue;
83                 }
84                 if (!W_ERROR_IS_OK(r.out.result)) {
85                         printf("NetCharDevControl opcode %u failed - %s\n", r.in.opcode, win_errstr(r.out.result));
86                         continue;
87                 }
88         }
89
90         return ret;
91 }
92
93 static BOOL test_NetCharDevEnum(struct dcerpc_pipe *p, 
94                            TALLOC_CTX *mem_ctx)
95 {
96         NTSTATUS status;
97         struct srvsvc_NetCharDevEnum r;
98         struct srvsvc_NetCharDevCtr0 c0;
99         uint32 levels[] = {0, 1};
100         int i;
101         BOOL ret = True;
102
103         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
104         r.in.ctr.ctr0 = &c0;
105         r.in.ctr.ctr0->count = 0;
106         r.in.ctr.ctr0->array = NULL;
107         r.in.max_buffer = (uint32)-1;
108         r.in.resume_handle = NULL;
109
110         for (i=0;i<ARRAY_SIZE(levels);i++) {
111                 int j;
112
113
114                 ZERO_STRUCT(r.out);
115                 r.in.level = levels[i];
116                 printf("testing NetCharDevEnum level %u\n", r.in.level);
117                 status = dcerpc_srvsvc_NetCharDevEnum(p, mem_ctx, &r);
118                 if (!NT_STATUS_IS_OK(status)) {
119                         printf("NetCharDevEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
120                         ret = False;
121                         continue;
122                 }
123                 if (!W_ERROR_IS_OK(r.out.result)) {
124                         printf("NetCharDevEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
125                         continue;
126                 }
127
128                 /* call test_NetCharDevGetInfo and test_NetCharDevControl for each returned share */
129                 if (r.in.level == 1) {
130                         for (j=0;j<r.out.ctr.ctr1->count;j++) {
131                                 const char *device;
132                                 device = r.out.ctr.ctr1->array[j].device;
133                                 if (!test_NetCharDevGetInfo(p, mem_ctx, device)) {
134                                         ret = False;
135                                 }
136                                 if (!test_NetCharDevControl(p, mem_ctx, device)) {
137                                         ret = False;
138                                 }
139                         }
140                 }
141         }
142
143         return ret;
144 }
145
146 static BOOL test_NetConnEnum(struct dcerpc_pipe *p, 
147                            TALLOC_CTX *mem_ctx)
148 {
149         NTSTATUS status;
150         struct srvsvc_NetConnEnum r;
151         struct srvsvc_NetConnCtr0 c0;
152         uint32_t levels[] = {0, 1};
153         int i;
154         BOOL ret = True;
155
156         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
157         r.in.path = talloc_asprintf(mem_ctx,"%s","ADMIN$");
158         r.in.ctr.ctr0 = &c0;
159         r.in.ctr.ctr0->count = 0;
160         r.in.ctr.ctr0->array = NULL;
161         r.in.max_buffer = (uint32_t)-1;
162         r.in.resume_handle = NULL;
163
164         for (i=0;i<ARRAY_SIZE(levels);i++) {
165                 ZERO_STRUCT(r.out);
166                 r.in.level = levels[i];
167                 printf("testing NetConnEnum level %u\n", r.in.level);
168                 status = dcerpc_srvsvc_NetConnEnum(p, mem_ctx, &r);
169                 if (!NT_STATUS_IS_OK(status)) {
170                         printf("NetConnEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
171                         ret = False;
172                         continue;
173                 }
174                 if (!W_ERROR_IS_OK(r.out.result)) {
175                         printf("NetConnEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
176                         continue;
177                 }
178         }
179
180         return True;
181 }
182
183 static BOOL test_NetFileEnum(struct dcerpc_pipe *p, 
184                            TALLOC_CTX *mem_ctx)
185 {
186         NTSTATUS status;
187         struct srvsvc_NetFileEnum r;
188         struct srvsvc_NetFileCtr3 c3;
189         uint32_t levels[] = {2, 3};
190         int i;
191         BOOL ret = True;
192
193         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
194         r.in.path = NULL;
195         r.in.user = NULL;
196         r.in.ctr.ctr3 = &c3;
197         r.in.ctr.ctr3->count = 0;
198         r.in.ctr.ctr3->array = NULL;
199         r.in.max_buffer = (uint32_t)4096;
200         r.in.resume_handle = NULL;
201
202         for (i=0;i<ARRAY_SIZE(levels);i++) {
203                 ZERO_STRUCT(r.out);
204                 r.in.level = levels[i];
205                 printf("testing NetFileEnum level %u\n", r.in.level);
206                 status = dcerpc_srvsvc_NetFileEnum(p, mem_ctx, &r);
207                 if (!NT_STATUS_IS_OK(status)) {
208                         printf("NetFileEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
209                         ret = False;
210                         continue;
211                 }
212                 if (!W_ERROR_IS_OK(r.out.result)) {
213                         printf("NetFileEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
214                         continue;
215                 }
216         }
217
218         return True;
219 }
220
221 static BOOL test_NetSessEnum(struct dcerpc_pipe *p, 
222                            TALLOC_CTX *mem_ctx)
223 {
224         NTSTATUS status;
225         struct srvsvc_NetSessEnum r;
226         struct srvsvc_NetSessCtr0 c0;
227         uint32_t levels[] = {0, 1, 2, 10, 502};
228         int i;
229         BOOL ret = True;
230
231         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
232         r.in.client = NULL;
233         r.in.user = NULL;
234         r.in.ctr.ctr0 = &c0;
235         r.in.ctr.ctr0->count = 0;
236         r.in.ctr.ctr0->array = NULL;
237         r.in.max_buffer = (uint32_t)-1;
238         r.in.resume_handle = NULL;
239
240         for (i=0;i<ARRAY_SIZE(levels);i++) {
241                 ZERO_STRUCT(r.out);
242                 r.in.level = levels[i];
243                 printf("testing NetSessEnum level %u\n", r.in.level);
244                 status = dcerpc_srvsvc_NetSessEnum(p, mem_ctx, &r);
245                 if (!NT_STATUS_IS_OK(status)) {
246                         printf("NetSessEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
247                         ret = False;
248                         continue;
249                 }
250                 if (!W_ERROR_IS_OK(r.out.result)) {
251                         printf("NetSessEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
252                         continue;
253                 }
254         }
255
256         return True;
257 }
258
259 /**************************/
260 /* srvsvc_NetShare        */
261 /**************************/
262 static BOOL test_NetShareGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
263                                  const char *sharename)
264 {
265         NTSTATUS status;
266         struct srvsvc_NetShareGetInfo r;
267         uint32_t levels[] = {0, 1, 2, 501, 502, 1005};
268         int i;
269         BOOL ret = True;
270
271         r.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
272         r.in.share_name = sharename;
273
274         for (i=0;i<ARRAY_SIZE(levels);i++) {
275                 ZERO_STRUCT(r.out);
276                 r.in.level = levels[i];
277
278                 printf("testing NetShareGetInfo level %u on share '%s'\n", 
279                        r.in.level, r.in.share_name);
280
281                 status = dcerpc_srvsvc_NetShareGetInfo(p, mem_ctx, &r);
282                 if (!NT_STATUS_IS_OK(status)) {
283                         printf("NetShareGetInfo level %u on share '%s' failed - %s\n",
284                                 r.in.level, r.in.share_name, nt_errstr(status));
285                         ret = False;
286                         continue;
287                 }
288                 if (!W_ERROR_IS_OK(r.out.result)) {
289                         printf("NetShareGetInfo level %u on share '%s' failed - %s\n",
290                                 r.in.level, r.in.share_name, win_errstr(r.out.result));
291                         continue;
292                 }
293         }
294
295         return ret;
296 }
297
298 static BOOL test_NetShareEnumAll(struct dcerpc_pipe *p, 
299                                  TALLOC_CTX *mem_ctx)
300 {
301         NTSTATUS status;
302         struct srvsvc_NetShareEnumAll r;
303         struct srvsvc_NetShareCtr0 c0;
304         uint32_t levels[] = {0, 1, 2, 501, 502};
305         int i;
306         BOOL ret = True;
307         uint32_t resume_handle;
308
309         ZERO_STRUCT(c0);
310
311         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
312         r.in.ctr.ctr0 = &c0;
313         r.in.max_buffer = (uint32_t)-1;
314         r.in.resume_handle = &resume_handle;
315         r.out.resume_handle = &resume_handle;
316
317         for (i=0;i<ARRAY_SIZE(levels);i++) {
318                 int j;
319
320                 ZERO_STRUCT(r.out);
321                 resume_handle = 0;
322                 r.in.level = levels[i];
323                 printf("testing NetShareEnumAll level %u\n", r.in.level);
324                 status = dcerpc_srvsvc_NetShareEnumAll(p, mem_ctx, &r);
325                 if (!NT_STATUS_IS_OK(status)) {
326                         printf("NetShareEnumAll level %u failed - %s\n", r.in.level, nt_errstr(status));
327                         ret = False;
328                         continue;
329                 }
330                 if (!W_ERROR_IS_OK(r.out.result)) {
331                         printf("NetShareEnumAll level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
332                         continue;
333                 }
334
335                 /* call srvsvc_NetShareGetInfo for each returned share */
336                 if (r.in.level == 1) {
337                         for (j=0;j<r.out.ctr.ctr1->count;j++) {
338                                 const char *name;
339                                 name = r.out.ctr.ctr1->array[j].name;
340                                 if (!test_NetShareGetInfo(p, mem_ctx, name)) {
341                                         ret = False;
342                                 }
343                         }
344                 }
345         }
346
347         return ret;
348 }
349
350 static BOOL test_NetShareEnum(struct dcerpc_pipe *p, 
351                            TALLOC_CTX *mem_ctx)
352 {
353         NTSTATUS status;
354         struct srvsvc_NetShareEnum r;
355         struct srvsvc_NetShareCtr0 c0;
356         uint32_t levels[] = {0, 1, 2, 502};
357         int i;
358         BOOL ret = True;
359
360         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
361         r.in.ctr.ctr0 = &c0;
362         r.in.ctr.ctr0->count = 0;
363         r.in.ctr.ctr0->array = NULL;
364         r.in.max_buffer = (uint32_t)-1;
365         r.in.resume_handle = NULL;
366
367         for (i=0;i<ARRAY_SIZE(levels);i++) {
368                 int j;
369
370                 ZERO_STRUCT(r.out);
371                 r.in.level = levels[i];
372                 printf("testing NetShareEnum level %u\n", r.in.level);
373                 status = dcerpc_srvsvc_NetShareEnum(p, mem_ctx, &r);
374                 if (!NT_STATUS_IS_OK(status)) {
375                         printf("NetShareEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
376                         ret = False;
377                         continue;
378                 }
379                 if (!W_ERROR_IS_OK(r.out.result)) {
380                         printf("NetShareEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
381                         continue;
382                 }
383
384                 /* call srvsvc_NetShareGetInfo for each returned share */
385                 if (r.in.level == 1) {
386                         for (j=0;j<r.out.ctr.ctr1->count;j++) {
387                                 const char *name;
388                                 name = r.out.ctr.ctr1->array[j].name;
389                                 if (!test_NetShareGetInfo(p, mem_ctx, name)) {
390                                         ret = False;
391                                 }
392                         }
393                 }
394         }
395
396         return True;
397 }
398
399 /**************************/
400 /* srvsvc_NetDisk         */
401 /**************************/
402 static BOOL test_NetDiskEnum(struct dcerpc_pipe *p, 
403                            TALLOC_CTX *mem_ctx)
404 {
405         NTSTATUS status;
406         struct srvsvc_NetDiskEnum r;
407         uint32_t levels[] = {0};
408         int i;
409         BOOL ret = True;
410         uint32_t resume_handle=0;
411
412         r.in.server_unc = NULL;
413         r.in.unknown = 0;
414         r.in.resume_handle = &resume_handle;
415         r.in.ctr.ctr0 = NULL;
416
417         for (i=0;i<ARRAY_SIZE(levels);i++) {
418                 ZERO_STRUCT(r.out);
419                 r.in.level = levels[i];
420                 printf("testing NetDiskEnum level %u\n", r.in.level);
421                 status = dcerpc_srvsvc_NetDiskEnum(p, mem_ctx, &r);
422                 if (!NT_STATUS_IS_OK(status)) {
423                         NDR_PRINT_OUT_DEBUG(srvsvc_NetDiskEnum, &r);
424                         printf("NetDiskEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
425                         ret = False;
426                         continue;
427                 }
428                 if (!W_ERROR_IS_OK(r.out.result)) {
429                         printf("NetDiskEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
430                         continue;
431                 }
432         }
433
434         return ret;
435 }
436
437 /**************************/
438 /* srvsvc_NetTransport    */
439 /**************************/
440 static BOOL test_NetTransportEnum(struct dcerpc_pipe *p, 
441                            TALLOC_CTX *mem_ctx)
442 {
443         NTSTATUS status;
444         struct srvsvc_NetTransportEnum r;
445         struct srvsvc_NetTransportCtr0 c0;
446         uint32_t levels[] = {0, 1};
447         int i;
448         BOOL ret = True;
449
450         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
451         r.in.ctr.ctr0 = &c0;
452         r.in.ctr.ctr0->count = 0;
453         r.in.ctr.ctr0->array = NULL;
454         r.in.max_buffer = (uint32_t)-1;
455         r.in.resume_handle = NULL;
456
457         for (i=0;i<ARRAY_SIZE(levels);i++) {
458                 ZERO_STRUCT(r.out);
459                 r.in.level = levels[i];
460                 printf("testing NetTransportEnum level %u\n", r.in.level);
461                 status = dcerpc_srvsvc_NetTransportEnum(p, mem_ctx, &r);
462                 if (!NT_STATUS_IS_OK(status)) {
463                         printf("NetTransportEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
464                         ret = False;
465                         continue;
466                 }
467                 if (!W_ERROR_IS_OK(r.out.result)) {
468                         printf("NetTransportEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
469                         continue;
470                 }
471         }
472
473         return ret;
474 }
475
476 BOOL torture_rpc_srvsvc(int dummy)
477 {
478         NTSTATUS status;
479         struct dcerpc_pipe *p;
480         TALLOC_CTX *mem_ctx;
481         BOOL ret = True;
482
483         mem_ctx = talloc_init("torture_rpc_srvsvc");
484
485         status = torture_rpc_connection(&p,
486                                         DCERPC_SRVSVC_NAME,
487                                         DCERPC_SRVSVC_UUID,
488                                         DCERPC_SRVSVC_VERSION);
489         if (!NT_STATUS_IS_OK(status)) {
490                 return False;
491         }
492
493         if (!test_NetCharDevEnum(p, mem_ctx)) {
494                 ret = False;
495         }
496
497         if (!test_NetConnEnum(p, mem_ctx)) {
498                 ret = False;
499         }
500
501         if (!test_NetFileEnum(p, mem_ctx)) {
502                 ret = False;
503         }
504
505         if (!test_NetSessEnum(p, mem_ctx)) {
506                 ret = False;
507         }
508
509         if (!test_NetShareEnumAll(p, mem_ctx)) {
510                 ret = False;
511         }
512
513         if (!test_NetDiskEnum(p, mem_ctx)) {
514                 ret = False;
515         }
516
517         if (!test_NetTransportEnum(p, mem_ctx)) {
518                 ret = False;
519         }
520
521         if (!test_NetShareEnum(p, mem_ctx)) {
522                 ret = False;
523         }
524
525         talloc_destroy(mem_ctx);
526
527         torture_rpc_close(p);
528
529         return ret;
530 }