r5941: Commit this patch much earlier than I would normally prefer, but metze needs...
[Samba/aatanasov.git] / source / torture / rpc / dfs.c
blob4e33f921facb80841a110e2fbe3acaf54d0b5ef7
1 /*
2 Unix SMB/CIFS implementation.
3 test suite for lsa dfs operations
5 Copyright (C) Andrew Tridgell 2003
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.
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.
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.
22 #include "includes.h"
23 #include "librpc/gen_ndr/ndr_dfs.h"
26 static BOOL test_GetManagerVersion(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
28 NTSTATUS status;
29 struct dfs_GetManagerVersion r;
30 uint32_t exist = 0;
32 r.out.exist_flag = ∃
34 status = dcerpc_dfs_GetManagerVersion(p, mem_ctx, &r);
35 if (!NT_STATUS_IS_OK(status)) {
36 printf("GetManagerVersion failed - %s\n", nt_errstr(status));
37 return False;
40 return True;
43 static BOOL test_InfoLevel(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint16_t level,
44 const char *root)
46 NTSTATUS status;
47 struct dfs_GetInfo r;
49 r.in.path = root;
50 r.in.server = NULL;
51 r.in.share = NULL;
52 r.in.level = level;
54 printf("Testing GetInfo level %u on '%s'\n", level, root);
56 status = dcerpc_dfs_GetInfo(p, mem_ctx, &r);
57 if (!NT_STATUS_IS_OK(status)) {
58 printf("Info failed - %s\n", nt_errstr(status));
59 return False;
62 return True;
65 static BOOL test_Info(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, const char *root)
67 BOOL ret = True;
68 uint16_t levels[] = {1, 2, 3, 4, 100, 101, 102, 200, 300};
69 int i;
70 for (i=0;i<ARRAY_SIZE(levels);i++) {
71 if (!test_InfoLevel(p, mem_ctx, levels[i], root)) {
72 ret = False;
75 return ret;
78 static BOOL test_EnumLevel(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint16_t level)
80 NTSTATUS status;
81 struct dfs_Enum r;
82 uint32_t total=0;
83 struct dfs_EnumStruct e;
84 struct dfs_Info1 s;
85 struct dfs_EnumArray1 e1;
86 BOOL ret = True;
88 r.in.level = level;
89 r.in.bufsize = (uint32_t)-1;
90 r.in.total = &total;
91 r.in.unknown = &total;
92 r.in.info = &e;
94 e.level = r.in.level;
95 e.e.info1 = &e1;
96 e.e.info1->count = 0;
97 e.e.info1->s = &s;
98 s.path = NULL;
100 status = dcerpc_dfs_Enum(p, mem_ctx, &r);
101 if (!NT_STATUS_IS_OK(status)) {
102 printf("Enum failed - %s\n", nt_errstr(status));
103 return False;
106 if (level == 1 && r.out.total) {
107 int i;
108 for (i=0;i<*r.out.total;i++) {
109 const char *root = r.out.info->e.info1->s[i].path;
110 if (!test_Info(p, mem_ctx, root)) {
111 ret = False;
117 return ret;
121 static BOOL test_Enum(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
123 BOOL ret = True;
124 uint16_t levels[] = {1, 2, 3, 4, 200, 300};
125 int i;
126 for (i=0;i<ARRAY_SIZE(levels);i++) {
127 if (!test_EnumLevel(p, mem_ctx, levels[i])) {
128 ret = False;
131 return ret;
134 #if 0
135 static BOOL test_Add(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
137 NTSTATUS status;
138 struct dfs_Add add;
139 struct dfs_Remove rem;
141 add.in.path = "\\\\win2003\\2nd root\\test";
142 add.in.server = "win2003";
143 add.in.share = "e$";
144 add.in.comment = "a test comment";
145 add.in.flags = 1;
147 status = dcerpc_dfs_Add(p, mem_ctx, &add);
148 if (!NT_STATUS_IS_OK(status)) {
149 printf("Add failed - %s\n", nt_errstr(status));
150 return False;
153 rem.in.path = add.in.path;
154 rem.in.server = add.in.server;
155 rem.in.share = add.in.share;
157 status = dcerpc_dfs_Remove(p, mem_ctx, &rem);
158 if (!NT_STATUS_IS_OK(status)) {
159 printf("Add failed - %s\n", nt_errstr(status));
160 return False;
163 return True;
165 #endif
167 BOOL torture_rpc_dfs(void)
169 NTSTATUS status;
170 struct dcerpc_pipe *p;
171 TALLOC_CTX *mem_ctx;
172 BOOL ret = True;
174 mem_ctx = talloc_init("torture_rpc_dfs");
176 status = torture_rpc_connection(mem_ctx,
177 &p,
178 DCERPC_NETDFS_NAME,
179 DCERPC_NETDFS_UUID,
180 DCERPC_NETDFS_VERSION);
181 if (!NT_STATUS_IS_OK(status)) {
182 return False;
185 if (!test_GetManagerVersion(p, mem_ctx)) {
186 ret = False;
189 #if 0
190 if (!test_Add(p, mem_ctx)) {
191 ret = False;
193 #endif
195 if (!test_Enum(p, mem_ctx)) {
196 ret = False;
199 talloc_free(mem_ctx);
201 return ret;