patch from metze with updates to srvsvc and changes to pidl to allow
[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 static BOOL test_NetConnEnum(struct dcerpc_pipe *p, 
26                            TALLOC_CTX *mem_ctx)
27 {
28         NTSTATUS status;
29         struct srvsvc_NetConnEnum r;
30         struct srvsvc_NetConnCtr0 c0;
31         uint32 levels[] = {0, 1};
32         int i;
33         BOOL ret = True;
34
35         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
36         r.in.path = talloc_asprintf(mem_ctx,"%s","ADMIN$");
37         r.in.ctr.ctr0 = &c0;
38         r.in.ctr.ctr0->count = 0;
39         r.in.ctr.ctr0->array = NULL;
40         r.in.preferred_len = (uint32)-1;
41         r.in.resume_handle = NULL;
42
43         for (i=0;i<ARRAY_SIZE(levels);i++) {
44                 r.in.level = levels[i];
45                 printf("testing NetConnEnum level %u\n", r.in.level);
46                 status = dcerpc_srvsvc_NetConnEnum(p, mem_ctx, &r);
47                 if (!NT_STATUS_IS_OK(status)) {
48                         printf("NetConnEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
49                         ret = False;
50                 }
51         }
52
53         return True;
54 }
55
56 static BOOL test_NetFileEnum(struct dcerpc_pipe *p, 
57                            TALLOC_CTX *mem_ctx)
58 {
59         NTSTATUS status;
60         struct srvsvc_NetFileEnum r;
61         struct srvsvc_NetFileCtr3 c3;
62         uint32 levels[] = {2, 3};
63         int i;
64         BOOL ret = True;
65
66         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
67         r.in.path = NULL;
68         r.in.user = NULL;
69         r.in.ctr.ctr3 = &c3;
70         r.in.ctr.ctr3->count = 0;
71         r.in.ctr.ctr3->array = NULL;
72         r.in.preferred_len = (uint32)4096;
73         r.in.resume_handle = NULL;
74
75         for (i=0;i<ARRAY_SIZE(levels);i++) {
76                 r.in.level = levels[i];
77                 printf("testing NetFileEnum level %u\n", r.in.level);
78                 status = dcerpc_srvsvc_NetFileEnum(p, mem_ctx, &r);
79                 if (!NT_STATUS_IS_OK(status)) {
80                         printf("NetFileEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
81                         ret = False;
82                 }
83         }
84
85         return True;
86 }
87
88 static BOOL test_NetSessEnum(struct dcerpc_pipe *p, 
89                            TALLOC_CTX *mem_ctx)
90 {
91         NTSTATUS status;
92         struct srvsvc_NetSessEnum r;
93         struct srvsvc_NetSessCtr0 c0;
94         uint32 levels[] = {0, 1, 2, 10, 502};
95         int i;
96         BOOL ret = True;
97
98         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
99         r.in.client = NULL;
100         r.in.user = NULL;
101         r.in.ctr.ctr0 = &c0;
102         r.in.ctr.ctr0->count = 0;
103         r.in.ctr.ctr0->array = NULL;
104         r.in.preferred_len = (uint32)-1;
105         r.in.resume_handle = NULL;
106
107         for (i=0;i<ARRAY_SIZE(levels);i++) {
108                 r.in.level = levels[i];
109                 printf("testing NetSessEnum level %u\n", r.in.level);
110                 status = dcerpc_srvsvc_NetSessEnum(p, mem_ctx, &r);
111                 if (!NT_STATUS_IS_OK(status)) {
112                         printf("NetSessEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
113                         ret = False;
114                 }
115         }
116
117         return True;
118 }
119
120 static BOOL test_NetShareEnumAll(struct dcerpc_pipe *p, 
121                                  TALLOC_CTX *mem_ctx)
122 {
123         NTSTATUS status;
124         struct srvsvc_NetShareEnumAll r;
125         struct srvsvc_NetShareCtr0 c0;
126         uint32 levels[] = {0, 1, 2, 501, 502, 1004};
127         int i;
128         BOOL ret = True;
129         uint32 resume_handle;
130
131         ZERO_STRUCT(c0);
132
133         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
134         r.in.ctr.ctr0 = &c0;
135         r.in.max_buffer = (uint32)-1;
136         r.in.resume_handle = &resume_handle;
137         r.out.resume_handle = &resume_handle;
138
139         for (i=0;i<ARRAY_SIZE(levels);i++) {
140                 resume_handle = 0;
141                 r.in.level = levels[i];
142                 printf("testing NetShareEnumAll level %u\n", r.in.level);
143                 status = dcerpc_srvsvc_NetShareEnumAll(p, mem_ctx, &r);
144                 if (!NT_STATUS_IS_OK(status)) {
145                         printf("NetShareEnumAll level %u failed - %s\n", r.in.level, nt_errstr(status));
146                         ret = False;
147                 }
148         }
149
150         return True;
151 }
152
153
154 static BOOL test_NetDiskEnum(struct dcerpc_pipe *p, 
155                            TALLOC_CTX *mem_ctx)
156 {
157         NTSTATUS status;
158         struct srvsvc_NetDiskEnum r;
159         uint32 levels[] = {0};
160         int i;
161         BOOL ret = True;
162
163         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
164         r.in.preferred_len = (uint32)-1;
165         r.in.resume_handle = NULL;
166
167         for (i=0;i<ARRAY_SIZE(levels);i++) {
168                 r.in.level = levels[i];
169                 ZERO_STRUCT(r.out);
170                 printf("testing NetDiskEnum level %u\n", r.in.level);
171                 status = dcerpc_srvsvc_NetDiskEnum(p, mem_ctx, &r);
172                 if (!NT_STATUS_IS_OK(status)) {
173                         NDR_PRINT_OUT_DEBUG(srvsvc_NetDiskEnum, &r);
174                         printf("NetDiskEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
175                         ret = False;
176                 }
177         }
178
179         return True;
180 }
181
182 static BOOL test_NetTransportEnum(struct dcerpc_pipe *p, 
183                            TALLOC_CTX *mem_ctx)
184 {
185         NTSTATUS status;
186         struct srvsvc_NetTransportEnum r;
187         struct srvsvc_NetTransportCtr0 c0;
188         uint32 levels[] = {0, 1};
189         int i;
190         BOOL ret = True;
191
192         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
193         r.in.ctr.ctr0 = &c0;
194         r.in.ctr.ctr0->count = 0;
195         r.in.ctr.ctr0->array = NULL;
196         r.in.preferred_len = (uint32)-1;
197         r.in.resume_handle = NULL;
198
199         for (i=0;i<ARRAY_SIZE(levels);i++) {
200                 r.in.level = levels[i];
201                 printf("testing NetTransportEnum level %u\n", r.in.level);
202                 status = dcerpc_srvsvc_NetTransportEnum(p, mem_ctx, &r);
203                 if (!NT_STATUS_IS_OK(status)) {
204                         printf("NetTransportEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
205                         ret = False;
206                 }
207         }
208
209         return True;
210 }
211
212 static BOOL test_NetShareEnum(struct dcerpc_pipe *p, 
213                            TALLOC_CTX *mem_ctx)
214 {
215         NTSTATUS status;
216         struct srvsvc_NetShareEnum r;
217         struct srvsvc_NetShareCtr0 c0;
218         uint32 levels[] = {0, 1, 2, 502};
219         int i;
220         BOOL ret = True;
221
222         r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
223         r.in.ctr.ctr0 = &c0;
224         r.in.ctr.ctr0->count = 0;
225         r.in.ctr.ctr0->array = NULL;
226         r.in.preferred_len = (uint32)-1;
227         r.in.resume_handle = NULL;
228
229         for (i=0;i<ARRAY_SIZE(levels);i++) {
230                 r.in.level = levels[i];
231                 printf("testing NetShareEnum level %u\n", r.in.level);
232                 status = dcerpc_srvsvc_NetShareEnum(p, mem_ctx, &r);
233                 if (!NT_STATUS_IS_OK(status)) {
234                         printf("NetShareEnum level %u failed - %s\n", r.in.level, nt_errstr(status));
235                         ret = False;
236                 }
237         }
238
239         return True;
240 }
241
242 BOOL torture_rpc_srvsvc(int dummy)
243 {
244         NTSTATUS status;
245         struct dcerpc_pipe *p;
246         TALLOC_CTX *mem_ctx;
247         BOOL ret = True;
248
249         mem_ctx = talloc_init("torture_rpc_srvsvc");
250
251         status = torture_rpc_connection(&p,
252                                         DCERPC_SRVSVC_NAME,
253                                         DCERPC_SRVSVC_UUID,
254                                         DCERPC_SRVSVC_VERSION);
255         if (!NT_STATUS_IS_OK(status)) {
256                 return False;
257         }
258
259         p->flags |= DCERPC_DEBUG_PRINT_BOTH;
260
261         if (!test_NetConnEnum(p, mem_ctx)) {
262                 ret = False;
263         }
264
265         if (!test_NetFileEnum(p, mem_ctx)) {
266                 ret = False;
267         }
268
269         if (!test_NetSessEnum(p, mem_ctx)) {
270                 ret = False;
271         }
272
273         if (!test_NetShareEnumAll(p, mem_ctx)) {
274                 ret = False;
275         }
276 #if 0
277         if (!test_NetDiskEnum(p, mem_ctx)) {
278                 ret = False;
279         }
280 #endif
281         if (!test_NetTransportEnum(p, mem_ctx)) {
282                 ret = False;
283         }
284
285         if (!test_NetShareEnum(p, mem_ctx)) {
286                 ret = False;
287         }
288
289         talloc_destroy(mem_ctx);
290
291         torture_rpc_close(p);
292
293         return ret;
294 }