r14720: Add torture_context argument to all torture tests
[ira/wip.git] / source4 / torture / rpc / dfs.c
1 /* 
2    Unix SMB/CIFS implementation.
3    test suite for lsa dfs operations
4
5    Copyright (C) Andrew Tridgell 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 "torture/torture.h"
24 #include "torture/rpc/rpc.h"
25 #include "librpc/gen_ndr/ndr_dfs_c.h"
26
27
28 static BOOL test_GetManagerVersion(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
29 {
30         NTSTATUS status;
31         struct dfs_GetManagerVersion r;
32         uint32_t exist = 0;
33
34         r.out.exist_flag = ∃
35
36         status = dcerpc_dfs_GetManagerVersion(p, mem_ctx, &r);
37         if (!NT_STATUS_IS_OK(status)) {
38                 printf("GetManagerVersion failed - %s\n", nt_errstr(status));
39                 return False;
40         }
41
42         return True;
43 }
44
45 static BOOL test_InfoLevel(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint16_t level,
46                            const char *root)
47 {
48         NTSTATUS status;
49         struct dfs_GetInfo r;
50         
51         r.in.path = root;
52         r.in.server = NULL;
53         r.in.share = NULL;
54         r.in.level = level;
55
56         printf("Testing GetInfo level %u on '%s'\n", level, root);
57
58         status = dcerpc_dfs_GetInfo(p, mem_ctx, &r);
59         if (!NT_STATUS_IS_OK(status)) {
60                 printf("Info failed - %s\n", nt_errstr(status));
61                 return False;
62         }
63
64         return True;
65 }
66
67 static BOOL test_Info(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, const char *root)
68 {
69         BOOL ret = True;
70         uint16_t levels[] = {1, 2, 3, 4, 100, 101, 102, 200, 300};
71         int i;
72         for (i=0;i<ARRAY_SIZE(levels);i++) {
73                 if (!test_InfoLevel(p, mem_ctx, levels[i], root)) {
74                         ret = False;
75                 }
76         }
77         return ret;
78 }
79
80 static BOOL test_EnumLevel(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint16_t level)
81 {
82         NTSTATUS status;
83         struct dfs_Enum r;
84         uint32_t total=0;
85         struct dfs_EnumStruct e;
86         struct dfs_Info1 s;
87         struct dfs_EnumArray1 e1;
88         BOOL ret = True;
89         
90         r.in.level = level;
91         r.in.bufsize = (uint32_t)-1;
92         r.in.total = &total;
93         r.in.unknown = &total;
94         r.in.info = &e;
95
96         e.level = r.in.level;
97         e.e.info1 = &e1;
98         e.e.info1->count = 0;
99         e.e.info1->s = &s;
100         s.path = NULL;
101         
102         status = dcerpc_dfs_Enum(p, mem_ctx, &r);
103         if (!NT_STATUS_IS_OK(status)) {
104                 printf("Enum failed - %s\n", nt_errstr(status));
105                 return False;
106         }
107
108         if (level == 1 && r.out.total) {
109                 int i;
110                 for (i=0;i<*r.out.total;i++) {
111                         const char *root = r.out.info->e.info1->s[i].path;
112                         if (!test_Info(p, mem_ctx, root)) {
113                                 ret = False;
114                         }
115                 }
116                 
117         }
118
119         return ret;
120 }
121
122
123 static BOOL test_Enum(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
124 {
125         BOOL ret = True;
126         uint16_t levels[] = {1, 2, 3, 4, 200, 300};
127         int i;
128         for (i=0;i<ARRAY_SIZE(levels);i++) {
129                 if (!test_EnumLevel(p, mem_ctx, levels[i])) {
130                         ret = False;
131                 }
132         }
133         return ret;
134 }
135
136 #if 0
137 static BOOL test_Add(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
138 {
139         NTSTATUS status;
140         struct dfs_Add add;
141         struct dfs_Remove rem;
142         
143         add.in.path = "\\\\win2003\\2nd root\\test";
144         add.in.server = "win2003";
145         add.in.share = "e$";
146         add.in.comment = "a test comment";
147         add.in.flags = 1;
148
149         status = dcerpc_dfs_Add(p, mem_ctx, &add);
150         if (!NT_STATUS_IS_OK(status)) {
151                 printf("Add failed - %s\n", nt_errstr(status));
152                 return False;
153         }
154
155         rem.in.path = add.in.path;
156         rem.in.server = add.in.server;
157         rem.in.share = add.in.share;
158         
159         status = dcerpc_dfs_Remove(p, mem_ctx, &rem);
160         if (!NT_STATUS_IS_OK(status)) {
161                 printf("Add failed - %s\n", nt_errstr(status));
162                 return False;
163         }
164
165         return True;
166 }
167 #endif
168
169 BOOL torture_rpc_dfs(struct torture_context *torture)
170 {
171         NTSTATUS status;
172         struct dcerpc_pipe *p;
173         TALLOC_CTX *mem_ctx;
174         BOOL ret = True;
175
176         mem_ctx = talloc_init("torture_rpc_dfs");
177
178         status = torture_rpc_connection(mem_ctx, 
179                                         &p, 
180                                         &dcerpc_table_netdfs);
181         if (!NT_STATUS_IS_OK(status)) {
182                 return False;
183         }
184
185         if (!test_GetManagerVersion(p, mem_ctx)) {
186                 ret = False;
187         }
188
189 #if 0
190         if (!test_Add(p, mem_ctx)) {
191                 ret = False;
192         }
193 #endif
194
195         if (!test_Enum(p, mem_ctx)) {
196                 ret = False;
197         }
198
199         talloc_free(mem_ctx);
200
201         return ret;
202 }