r5298: - got rid of pstring.h from includes.h. This at least makes it a bit
[ira/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 #include "librpc/gen_ndr/ndr_srvsvc.h"
24
25 /**************************/
26 /* srvsvc_NetCharDev      */
27 /**************************/
28 static BOOL test_NetCharDevGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 
29                                 const char *devname)
30 {
31         NTSTATUS status;
32         struct srvsvc_NetCharDevGetInfo r;
33         uint32_t levels[] = {0, 1};
34         int i;
35         BOOL ret = True;
36
37         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
38         r.in.device_name = devname;
39
40         for (i=0;i<ARRAY_SIZE(levels);i++) {
41                 ZERO_STRUCT(r.out);
42                 r.in.level = levels[i];
43                 printf("testing NetCharDevGetInfo level %u on device '%s'\n",
44                         r.in.level, r.in.device_name);
45                 status = dcerpc_srvsvc_NetCharDevGetInfo(p, mem_ctx, &r);
46                 if (!NT_STATUS_IS_OK(status)) {
47                         printf("NetCharDevGetInfo level %u on device '%s' failed - %s\n",
48                                 r.in.level, r.in.device_name, nt_errstr(status));
49                         ret = False;
50                         continue;
51                 }
52                 if (!W_ERROR_IS_OK(r.out.result)) {
53                         printf("NetCharDevGetInfo level %u on device '%s' failed - %s\n",
54                                 r.in.level, r.in.device_name, win_errstr(r.out.result));
55                         continue;
56                 }
57         }
58
59         return ret;
60 }
61
62 static BOOL test_NetCharDevControl(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
63                                 const char *devname)
64 {
65         NTSTATUS status;
66         struct srvsvc_NetCharDevControl r;
67         uint32_t opcodes[] = {0, 1};
68         int i;
69         BOOL ret = True;
70
71         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
72         r.in.device_name = devname;
73
74         for (i=0;i<ARRAY_SIZE(opcodes);i++) {
75                 ZERO_STRUCT(r.out);
76                 r.in.opcode = opcodes[i];
77                 printf("testing NetCharDevControl opcode %u on device '%s'\n", 
78                         r.in.opcode, r.in.device_name);
79                 status = dcerpc_srvsvc_NetCharDevControl(p, mem_ctx, &r);
80                 if (!NT_STATUS_IS_OK(status)) {
81                         printf("NetCharDevControl opcode %u failed - %s\n", r.in.opcode, nt_errstr(status));
82                         ret = False;
83                         continue;
84                 }
85                 if (!W_ERROR_IS_OK(r.out.result)) {
86                         printf("NetCharDevControl opcode %u failed - %s\n", r.in.opcode, win_errstr(r.out.result));
87                         continue;
88                 }
89         }
90
91         return ret;
92 }
93
94 static BOOL test_NetCharDevEnum(struct dcerpc_pipe *p, 
95                            TALLOC_CTX *mem_ctx)
96 {
97         NTSTATUS status;
98         struct srvsvc_NetCharDevEnum r;
99         struct srvsvc_NetCharDevCtr0 c0;
100         uint32_t levels[] = {0, 1};
101         int i;
102         BOOL ret = True;
103
104         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
105         r.in.ctr.ctr0 = &c0;
106         r.in.ctr.ctr0->count = 0;
107         r.in.ctr.ctr0->array = NULL;
108         r.in.max_buffer = (uint32_t)-1;
109         r.in.resume_handle = NULL;
110
111         for (i=0;i<ARRAY_SIZE(levels);i++) {
112                 int j;
113
114
115                 ZERO_STRUCT(r.out);
116                 r.in.level = levels[i];
117                 printf("testing NetCharDevEnum level %u\n", r.in.level);
118                 status = dcerpc_srvsvc_NetCharDevEnum(p, mem_ctx, &r);
119                 if (!NT_STATUS_IS_OK(status)) {
120                         printf("NetCharDevEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
121                         ret = False;
122                         continue;
123                 }
124                 if (!W_ERROR_IS_OK(r.out.result)) {
125                         printf("NetCharDevEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
126                         continue;
127                 }
128
129                 /* call test_NetCharDevGetInfo and test_NetCharDevControl for each returned share */
130                 if (r.in.level == 1) {
131                         for (j=0;j<r.out.ctr.ctr1->count;j++) {
132                                 const char *device;
133                                 device = r.out.ctr.ctr1->array[j].device;
134                                 if (!test_NetCharDevGetInfo(p, mem_ctx, device)) {
135                                         ret = False;
136                                 }
137                                 if (!test_NetCharDevControl(p, mem_ctx, device)) {
138                                         ret = False;
139                                 }
140                         }
141                 }
142         }
143
144         return ret;
145 }
146
147 /**************************/
148 /* srvsvc_NetCharDevQ     */
149 /**************************/
150 static BOOL test_NetCharDevQGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
151                                 const char *devicequeue)
152 {
153         NTSTATUS status;
154         struct srvsvc_NetCharDevQGetInfo r;
155         uint32_t levels[] = {0, 1};
156         int i;
157         BOOL ret = True;
158
159         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
160         r.in.queue_name = devicequeue;
161         r.in.user = talloc_asprintf(mem_ctx,"Administrator");
162
163         for (i=0;i<ARRAY_SIZE(levels);i++) {
164                 ZERO_STRUCT(r.out);
165                 r.in.level = levels[i];
166                 printf("testing NetCharDevQGetInfo level %u on devicequeue '%s'\n",
167                         r.in.level, r.in.queue_name);
168                 status = dcerpc_srvsvc_NetCharDevQGetInfo(p, mem_ctx, &r);
169                 if (!NT_STATUS_IS_OK(status)) {
170                         printf("NetCharDevQGetInfo level %u on devicequeue '%s' failed - %s\n",
171                                 r.in.level, r.in.queue_name, nt_errstr(status));
172                         ret = False;
173                         continue;
174                 }
175                 if (!W_ERROR_IS_OK(r.out.result)) {
176                         printf("NetCharDevQGetInfo level %u on devicequeue '%s' failed - %s\n",
177                                 r.in.level, r.in.queue_name, win_errstr(r.out.result));
178                         continue;
179                 }
180         }
181
182         return ret;
183 }
184
185 #if 0
186 static BOOL test_NetCharDevQSetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
187                                 const char *devicequeue)
188 {
189         NTSTATUS status;
190         struct srvsvc_NetCharDevQSetInfo r;
191         uint32_t parm_error;
192         uint32_t levels[] = {0, 1};
193         int i;
194         BOOL ret = True;
195
196         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
197         r.in.queue_name = devicequeue;
198
199         for (i=0;i<ARRAY_SIZE(levels);i++) {
200                 ZERO_STRUCT(r.out);
201                 parm_error = 0;
202                 r.in.level = levels[i];
203                 printf("testing NetCharDevQSetInfo level %u on devicequeue '%s'\n", 
204                         r.in.level, devicequeue);
205                 switch (r.in.level) {
206                 case 0:
207                         r.in.info.info0 = talloc(mem_ctx, struct srvsvc_NetCharDevQInfo0);
208                         r.in.info.info0->device = r.in.queue_name;
209                         break;
210                 case 1:
211                         r.in.info.info1 = talloc(mem_ctx, struct srvsvc_NetCharDevQInfo1);
212                         r.in.info.info1->device = r.in.queue_name;
213                         r.in.info.info1->priority = 0x000;
214                         r.in.info.info1->devices = r.in.queue_name;
215                         r.in.info.info1->users = 0x000;
216                         r.in.info.info1->num_ahead = 0x000;
217                         break;
218                 default:
219                         break;
220                 }
221                 r.in.parm_error = &parm_error;
222                 status = dcerpc_srvsvc_NetCharDevQSetInfo(p, mem_ctx, &r);
223                 if (!NT_STATUS_IS_OK(status)) {
224                         printf("NetCharDevQSetInfo level %u on devicequeue '%s' failed - %s\n",
225                                 r.in.level, r.in.queue_name, nt_errstr(status));
226                         ret = False;
227                         continue;
228                 }
229                 if (!W_ERROR_IS_OK(r.out.result)) {
230                         printf("NetCharDevQSetInfo level %u on devicequeue '%s' failed - %s\n",
231                                 r.in.level, r.in.queue_name, win_errstr(r.out.result));
232                         continue;
233                 }
234         }
235
236         return ret;
237 }
238 #endif
239
240 static BOOL test_NetCharDevQEnum(struct dcerpc_pipe *p, 
241                            TALLOC_CTX *mem_ctx)
242 {
243         NTSTATUS status;
244         struct srvsvc_NetCharDevQEnum r;
245         struct srvsvc_NetCharDevQCtr0 c0;
246         uint32_t levels[] = {0, 1};
247         int i;
248         BOOL ret = True;
249
250         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
251         r.in.user = talloc_asprintf(mem_ctx,"%s","Administrator");
252         r.in.ctr.ctr0 = &c0;
253         r.in.ctr.ctr0->count = 0;
254         r.in.ctr.ctr0->array = NULL;
255         r.in.max_buffer = (uint32_t)-1;
256         r.in.resume_handle = NULL;
257
258         for (i=0;i<ARRAY_SIZE(levels);i++) {
259                 int j;
260
261                 ZERO_STRUCT(r.out);
262                 r.in.level = levels[i];
263                 printf("testing NetCharDevQEnum level %u\n", r.in.level);
264                 status = dcerpc_srvsvc_NetCharDevQEnum(p, mem_ctx, &r);
265                 if (!NT_STATUS_IS_OK(status)) {
266                         printf("NetCharDevQEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
267                         ret = False;
268                         continue;
269                 }
270                 if (!W_ERROR_IS_OK(r.out.result)) {
271                         printf("NetCharDevQEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
272                         continue;
273                 }
274
275                 /* call test_NetCharDevGetInfo and test_NetCharDevControl for each returned share */
276                 if (r.in.level == 1) {
277                         for (j=0;j<r.out.ctr.ctr1->count;j++) {
278                                 const char *device;
279                                 device = r.out.ctr.ctr1->array[j].device;
280                                 if (!test_NetCharDevQGetInfo(p, mem_ctx, device)) {
281                                         ret = False;
282                                 }
283                         }
284                 }
285         }
286
287         return ret;
288 }
289
290 /**************************/
291 /* srvsvc_NetConn         */
292 /**************************/
293 static BOOL test_NetConnEnum(struct dcerpc_pipe *p, 
294                            TALLOC_CTX *mem_ctx)
295 {
296         NTSTATUS status;
297         struct srvsvc_NetConnEnum r;
298         struct srvsvc_NetConnCtr0 c0;
299         uint32_t levels[] = {0, 1};
300         int i;
301         BOOL ret = True;
302
303         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
304         r.in.path = talloc_asprintf(mem_ctx,"%s","ADMIN$");
305         r.in.ctr.ctr0 = &c0;
306         r.in.ctr.ctr0->count = 0;
307         r.in.ctr.ctr0->array = NULL;
308         r.in.max_buffer = (uint32_t)-1;
309         r.in.resume_handle = NULL;
310
311         for (i=0;i<ARRAY_SIZE(levels);i++) {
312                 ZERO_STRUCT(r.out);
313                 r.in.level = levels[i];
314                 printf("testing NetConnEnum level %u\n", r.in.level);
315                 status = dcerpc_srvsvc_NetConnEnum(p, mem_ctx, &r);
316                 if (!NT_STATUS_IS_OK(status)) {
317                         printf("NetConnEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
318                         ret = False;
319                         continue;
320                 }
321                 if (!W_ERROR_IS_OK(r.out.result)) {
322                         printf("NetConnEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
323                         continue;
324                 }
325         }
326
327         return ret;
328 }
329
330 /**************************/
331 /* srvsvc_NetFile         */
332 /**************************/
333 static BOOL test_NetFileEnum(struct dcerpc_pipe *p, 
334                            TALLOC_CTX *mem_ctx)
335 {
336         NTSTATUS status;
337         struct srvsvc_NetFileEnum r;
338         struct srvsvc_NetFileCtr3 c3;
339         uint32_t levels[] = {2, 3};
340         int i;
341         BOOL ret = True;
342
343         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
344         r.in.path = NULL;
345         r.in.user = NULL;
346         r.in.ctr.ctr3 = &c3;
347         r.in.ctr.ctr3->count = 0;
348         r.in.ctr.ctr3->array = NULL;
349         r.in.max_buffer = (uint32_t)4096;
350         r.in.resume_handle = NULL;
351
352         for (i=0;i<ARRAY_SIZE(levels);i++) {
353                 ZERO_STRUCT(r.out);
354                 r.in.level = levels[i];
355                 printf("testing NetFileEnum level %u\n", r.in.level);
356                 status = dcerpc_srvsvc_NetFileEnum(p, mem_ctx, &r);
357                 if (!NT_STATUS_IS_OK(status)) {
358                         printf("NetFileEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
359                         ret = False;
360                         continue;
361                 }
362                 if (!W_ERROR_IS_OK(r.out.result)) {
363                         printf("NetFileEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
364                         continue;
365                 }
366         }
367
368         return ret;
369 }
370
371 /**************************/
372 /* srvsvc_NetSess         */
373 /**************************/
374 static BOOL test_NetSessEnum(struct dcerpc_pipe *p, 
375                            TALLOC_CTX *mem_ctx)
376 {
377         NTSTATUS status;
378         struct srvsvc_NetSessEnum r;
379         struct srvsvc_NetSessCtr0 c0;
380         uint32_t levels[] = {0, 1, 2, 10, 502};
381         int i;
382         BOOL ret = True;
383
384         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
385         r.in.client = NULL;
386         r.in.user = NULL;
387         r.in.ctr.ctr0 = &c0;
388         r.in.ctr.ctr0->count = 0;
389         r.in.ctr.ctr0->array = NULL;
390         r.in.max_buffer = (uint32_t)-1;
391         r.in.resume_handle = NULL;
392
393         for (i=0;i<ARRAY_SIZE(levels);i++) {
394                 ZERO_STRUCT(r.out);
395                 r.in.level = levels[i];
396                 printf("testing NetSessEnum level %u\n", r.in.level);
397                 status = dcerpc_srvsvc_NetSessEnum(p, mem_ctx, &r);
398                 if (!NT_STATUS_IS_OK(status)) {
399                         printf("NetSessEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
400                         ret = False;
401                         continue;
402                 }
403                 if (!W_ERROR_IS_OK(r.out.result)) {
404                         printf("NetSessEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
405                         continue;
406                 }
407         }
408
409         return ret;
410 }
411
412 /**************************/
413 /* srvsvc_NetShare        */
414 /**************************/
415 static BOOL test_NetShareGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
416                                  const char *sharename)
417 {
418         NTSTATUS status;
419         struct srvsvc_NetShareGetInfo r;
420         uint32_t levels[] = {0, 1, 2, 501, 502, 1005};
421         int i;
422         BOOL ret = True;
423
424         r.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
425         r.in.share_name = sharename;
426
427         for (i=0;i<ARRAY_SIZE(levels);i++) {
428                 ZERO_STRUCT(r.out);
429                 r.in.level = levels[i];
430
431                 printf("testing NetShareGetInfo level %u on share '%s'\n", 
432                        r.in.level, r.in.share_name);
433
434                 status = dcerpc_srvsvc_NetShareGetInfo(p, mem_ctx, &r);
435                 if (!NT_STATUS_IS_OK(status)) {
436                         printf("NetShareGetInfo level %u on share '%s' failed - %s\n",
437                                 r.in.level, r.in.share_name, nt_errstr(status));
438                         ret = False;
439                         continue;
440                 }
441                 if (!W_ERROR_IS_OK(r.out.result)) {
442                         printf("NetShareGetInfo level %u on share '%s' failed - %s\n",
443                                 r.in.level, r.in.share_name, win_errstr(r.out.result));
444                         continue;
445                 }
446         }
447
448         return ret;
449 }
450
451 static BOOL test_NetShareCheck(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
452                                const char *device_name)
453 {
454         NTSTATUS status;
455         struct srvsvc_NetShareCheck r;
456         BOOL ret = True;
457
458         r.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", dcerpc_server_name(p));
459         r.in.device_name = device_name;
460
461         printf("testing NetShareCheck on device '%s'\n", r.in.device_name);
462
463         status = dcerpc_srvsvc_NetShareCheck(p, mem_ctx, &r);
464         if (!NT_STATUS_IS_OK(status)) {
465                 printf("dcerpc_srvsvc_NetShareCheck on device '%s' failed - %s\n",
466                         r.in.device_name, nt_errstr(status));
467                 ret = False;
468         } else if (!W_ERROR_IS_OK(r.out.result)) {
469                 printf("NetShareCheck on device '%s' failed - %s\n",
470                         r.in.device_name, win_errstr(r.out.result));
471                 ret = False;
472         }
473
474         return ret;
475 }
476
477 /**************************/
478 /* srvsvc_NetShare        */
479 /**************************/
480 static BOOL test_NetShareEnumAll(struct dcerpc_pipe *p, 
481                                  TALLOC_CTX *mem_ctx)
482 {
483         NTSTATUS status;
484         struct srvsvc_NetShareEnumAll r;
485         struct srvsvc_NetShareCtr0 c0;
486         uint32_t levels[] = {0, 1, 2, 501, 502};
487         int i;
488         BOOL ret = True;
489         uint32_t resume_handle;
490
491         ZERO_STRUCT(c0);
492
493         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
494         r.in.ctr.ctr0 = &c0;
495         r.in.max_buffer = (uint32_t)-1;
496         r.in.resume_handle = &resume_handle;
497         r.out.resume_handle = &resume_handle;
498
499         for (i=0;i<ARRAY_SIZE(levels);i++) {
500                 int j;
501
502                 ZERO_STRUCT(r.out);
503                 resume_handle = 0;
504                 r.in.level = levels[i];
505                 printf("testing NetShareEnumAll level %u\n", r.in.level);
506                 status = dcerpc_srvsvc_NetShareEnumAll(p, mem_ctx, &r);
507                 if (!NT_STATUS_IS_OK(status)) {
508                         printf("NetShareEnumAll level %u failed - %s\n", r.in.level, nt_errstr(status));
509                         ret = False;
510                         continue;
511                 }
512                 if (!W_ERROR_IS_OK(r.out.result)) {
513                         printf("NetShareEnumAll level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
514                         continue;
515                 }
516
517                 /* call srvsvc_NetShareGetInfo for each returned share */
518                 if (r.in.level == 2) {
519                         for (j=0;j<r.out.ctr.ctr2->count;j++) {
520                                 const char *name;
521                                 const char *device;
522                                 name = r.out.ctr.ctr2->array[j].name;
523                                 if (!test_NetShareGetInfo(p, mem_ctx, name)) {
524                                         ret = False;
525                                 }
526                                 device = r.out.ctr.ctr2->array[j].path;
527                                 if (!test_NetShareCheck(p, mem_ctx, device)) {
528                                         ret = False;
529                                 }
530                         }
531                 }
532         }
533
534         return ret;
535 }
536
537 static BOOL test_NetShareEnum(struct dcerpc_pipe *p, 
538                            TALLOC_CTX *mem_ctx)
539 {
540         NTSTATUS status;
541         struct srvsvc_NetShareEnum r;
542         struct srvsvc_NetShareCtr0 c0;
543         uint32_t levels[] = {0, 1, 2, 502};
544         int i;
545         BOOL ret = True;
546
547         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
548         r.in.ctr.ctr0 = &c0;
549         r.in.ctr.ctr0->count = 0;
550         r.in.ctr.ctr0->array = NULL;
551         r.in.max_buffer = (uint32_t)-1;
552         r.in.resume_handle = NULL;
553
554         for (i=0;i<ARRAY_SIZE(levels);i++) {
555                 ZERO_STRUCT(r.out);
556                 r.in.level = levels[i];
557                 printf("testing NetShareEnum level %u\n", r.in.level);
558                 status = dcerpc_srvsvc_NetShareEnum(p, mem_ctx, &r);
559                 if (!NT_STATUS_IS_OK(status)) {
560                         printf("NetShareEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
561                         ret = False;
562                         continue;
563                 }
564                 if (!W_ERROR_IS_OK(r.out.result)) {
565                         printf("NetShareEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
566                         continue;
567                 }
568         }
569
570         return ret;
571 }
572
573 /**************************/
574 /* srvsvc_NetSrv          */
575 /**************************/
576 static BOOL test_NetSrvGetInfo(struct dcerpc_pipe *p, 
577                                  TALLOC_CTX *mem_ctx)
578 {
579         NTSTATUS status;
580         struct srvsvc_NetSrvGetInfo r;
581         struct srvsvc_NetSrvInfo503 i503;
582         uint32_t levels[] = {100, 101, 102, 502, 503};
583         int i;
584         BOOL ret = True;
585         uint32_t resume_handle;
586
587         ZERO_STRUCT(i503);
588
589         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
590
591         for (i=0;i<ARRAY_SIZE(levels);i++) {
592                 ZERO_STRUCT(r.out);
593                 resume_handle = 0;
594                 r.in.level = levels[i];
595                 printf("testing NetSrvGetInfo level %u\n", r.in.level);
596                 status = dcerpc_srvsvc_NetSrvGetInfo(p, mem_ctx, &r);
597                 if (!NT_STATUS_IS_OK(status)) {
598                         printf("NetSrvGetInfo level %u failed - %s\n", r.in.level, nt_errstr(status));
599                         ret = False;
600                         continue;
601                 }
602                 if (!W_ERROR_IS_OK(r.out.result)) {
603                         printf("NetSrvGetInfo level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
604                         continue;
605                 }
606         }
607
608         return ret;
609 }
610
611 /**************************/
612 /* srvsvc_NetDisk         */
613 /**************************/
614 static BOOL test_NetDiskEnum(struct dcerpc_pipe *p, 
615                            TALLOC_CTX *mem_ctx)
616 {
617         NTSTATUS status;
618         struct srvsvc_NetDiskEnum r;
619         uint32_t levels[] = {0};
620         int i;
621         BOOL ret = True;
622         uint32_t resume_handle=0;
623
624         r.in.server_unc = NULL;
625         r.in.unknown = 0;
626         r.in.resume_handle = &resume_handle;
627         r.in.ctr.ctr0 = NULL;
628
629         for (i=0;i<ARRAY_SIZE(levels);i++) {
630                 ZERO_STRUCT(r.out);
631                 r.in.level = levels[i];
632                 printf("testing NetDiskEnum level %u\n", r.in.level);
633                 status = dcerpc_srvsvc_NetDiskEnum(p, mem_ctx, &r);
634                 if (!NT_STATUS_IS_OK(status)) {
635                         NDR_PRINT_OUT_DEBUG(srvsvc_NetDiskEnum, &r);
636                         printf("NetDiskEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
637                         ret = False;
638                         continue;
639                 }
640                 if (!W_ERROR_IS_OK(r.out.result)) {
641                         printf("NetDiskEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
642                         continue;
643                 }
644         }
645
646         return ret;
647 }
648
649 /**************************/
650 /* srvsvc_NetTransport    */
651 /**************************/
652 static BOOL test_NetTransportEnum(struct dcerpc_pipe *p, 
653                            TALLOC_CTX *mem_ctx)
654 {
655         NTSTATUS status;
656         struct srvsvc_NetTransportEnum r;
657         struct srvsvc_NetTransportCtr0 c0;
658         uint32_t levels[] = {0, 1};
659         int i;
660         BOOL ret = True;
661
662         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
663         r.in.ctr.ctr0 = &c0;
664         r.in.ctr.ctr0->count = 0;
665         r.in.ctr.ctr0->array = NULL;
666         r.in.max_buffer = (uint32_t)-1;
667         r.in.resume_handle = NULL;
668
669         for (i=0;i<ARRAY_SIZE(levels);i++) {
670                 ZERO_STRUCT(r.out);
671                 r.in.level = levels[i];
672                 printf("testing NetTransportEnum level %u\n", r.in.level);
673                 status = dcerpc_srvsvc_NetTransportEnum(p, mem_ctx, &r);
674                 if (!NT_STATUS_IS_OK(status)) {
675                         printf("NetTransportEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
676                         ret = False;
677                         continue;
678                 }
679                 if (!W_ERROR_IS_OK(r.out.result)) {
680                         printf("NetTransportEnum level %u failed - %s\n", r.in.level, win_errstr(r.out.result));
681                         continue;
682                 }
683         }
684
685         return ret;
686 }
687
688 /**************************/
689 /* srvsvc_NetRemoteTOD    */
690 /**************************/
691 static BOOL test_NetRemoteTOD(struct dcerpc_pipe *p, 
692                            TALLOC_CTX *mem_ctx)
693 {
694         NTSTATUS status;
695         struct srvsvc_NetRemoteTOD r;
696         BOOL ret = True;
697
698         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
699
700         ZERO_STRUCT(r.out);
701         printf("testing NetRemoteTOD\n");
702         status = dcerpc_srvsvc_NetRemoteTOD(p, mem_ctx, &r);
703         if (!NT_STATUS_IS_OK(status)) {
704                 printf("NetRemoteTOD failed - %s\n", nt_errstr(status));
705                 ret = False;
706         }
707         if (!W_ERROR_IS_OK(r.out.result)) {
708                 printf("NetRemoteTOD failed - %s\n", win_errstr(r.out.result));
709         }
710
711         return ret;
712 }
713
714 BOOL torture_rpc_srvsvc(void)
715 {
716         NTSTATUS status;
717         struct dcerpc_pipe *p;
718         TALLOC_CTX *mem_ctx;
719         BOOL ret = True;
720
721         mem_ctx = talloc_init("torture_rpc_srvsvc");
722
723         status = torture_rpc_connection(&p,
724                                         DCERPC_SRVSVC_NAME,
725                                         DCERPC_SRVSVC_UUID,
726                                         DCERPC_SRVSVC_VERSION);
727         if (!NT_STATUS_IS_OK(status)) {
728                 return False;
729         }
730
731         if (!test_NetCharDevEnum(p, mem_ctx)) {
732                 ret = False;
733         }
734
735         if (!test_NetCharDevQEnum(p, mem_ctx)) {
736                 ret = False;
737         }
738
739         if (!test_NetConnEnum(p, mem_ctx)) {
740                 ret = False;
741         }
742
743         if (!test_NetFileEnum(p, mem_ctx)) {
744                 ret = False;
745         }
746
747         if (!test_NetSessEnum(p, mem_ctx)) {
748                 ret = False;
749         }
750
751         if (!test_NetShareEnumAll(p, mem_ctx)) {
752                 ret = False;
753         }
754
755         if (!test_NetSrvGetInfo(p, mem_ctx)) {
756                 ret = False;
757         }
758
759         if (!test_NetDiskEnum(p, mem_ctx)) {
760                 ret = False;
761         }
762
763         if (!test_NetTransportEnum(p, mem_ctx)) {
764                 ret = False;
765         }
766
767         if (!test_NetRemoteTOD(p, mem_ctx)) {
768                 ret = False;
769         }
770
771         if (!test_NetShareEnum(p, mem_ctx)) {
772                 ret = False;
773         }
774
775         talloc_free(mem_ctx);
776
777         torture_rpc_close(p);
778
779         return ret;
780 }