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