2 Unix SMB/CIFS implementation.
3 test suite for rpc 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.
23 #include "torture/torture.h"
24 #include "torture/rpc/rpc.h"
25 #include "librpc/gen_ndr/ndr_dfs_c.h"
26 #include "librpc/gen_ndr/ndr_srvsvc_c.h"
27 #include "libnet/libnet.h"
28 #include "libcli/raw/libcliraw.h"
29 #include "torture/util.h"
30 #include "libcli/libcli.h"
31 #include "lib/cmdline/popt_common.h"
33 #define SMBTORTURE_DFS_SHARENAME "smbtorture_dfs_share"
34 #define SMBTORTURE_DFS_DIRNAME "\\smbtorture_dfs_dir"
35 #define SMBTORTURE_DFS_PATHNAME "C:"SMBTORTURE_DFS_DIRNAME
37 #define IS_DFS_VERSION_UNSUPPORTED_CALL_W2K3(x,y)\
38 if (x == DFS_MANAGER_VERSION_W2K3) {\
39 if (!W_ERROR_EQUAL(y,WERR_NOT_SUPPORTED)) {\
40 printf("expected WERR_NOT_SUPPORTED\n");\
46 static bool test_NetShareAdd(TALLOC_CTX *mem_ctx, const char *host, const char *sharename, const char *dir)
49 struct srvsvc_NetShareInfo2 i;
50 struct libnet_context* libnetctx;
51 struct libnet_AddShare r;
53 printf("Creating share %s\n", sharename);
55 if (!(libnetctx = libnet_context_init(NULL))) {
59 libnetctx->cred = cmdline_credentials;
62 i.type = STYPE_DISKTREE;
64 i.max_users = (uint32_t) -1;
65 i.comment = "created by smbtorture";
68 i.current_users = 0x0;
71 r.in.server_name = host;
74 status = libnet_AddShare(libnetctx, mem_ctx, &r);
75 if (!NT_STATUS_IS_OK(status)) {
76 d_printf("Failed to add new share: %s (%s)\n",
77 nt_errstr(status), r.out.error_string);
84 static bool test_NetShareDel(TALLOC_CTX *mem_ctx, const char *host, const char *sharename)
87 struct libnet_context* libnetctx;
88 struct libnet_DelShare r;
90 printf("Deleting share %s\n", sharename);
92 if (!(libnetctx = libnet_context_init(NULL))) {
96 libnetctx->cred = cmdline_credentials;
98 r.in.share_name = sharename;
99 r.in.server_name = host;
101 status = libnet_DelShare(libnetctx, mem_ctx, &r);
102 if (!NT_STATUS_IS_OK(status)) {
103 d_printf("Failed to delete share: %s (%s)\n",
104 nt_errstr(status), r.out.error_string);
111 static bool test_CreateDir(TALLOC_CTX *mem_ctx,
112 struct smbcli_state **cli,
117 printf("Creating directory %s\n", dir);
119 if (!torture_open_connection_share(mem_ctx, cli, host, share, NULL)) {
123 if (!torture_setup_dir(*cli, dir)) {
130 static bool test_DeleteDir(struct smbcli_state *cli, const char *dir)
132 printf("Deleting directory %s\n", dir);
134 if (smbcli_deltree(cli->tree, dir) == -1) {
135 printf("Unable to delete dir %s - %s\n", dir, smbcli_errstr(cli->tree));
142 static bool test_GetManagerVersion(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, enum dfs_ManagerVersion *version)
145 struct dfs_GetManagerVersion r;
147 r.out.version = version;
149 status = dcerpc_dfs_GetManagerVersion(p, mem_ctx, &r);
150 if (!NT_STATUS_IS_OK(status)) {
151 printf("GetManagerVersion failed - %s\n", nt_errstr(status));
158 static bool test_ManagerInitialize(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, const char *host)
161 enum dfs_ManagerVersion version;
162 struct dfs_ManagerInitialize r;
164 printf("Testing ManagerInitialize\n");
166 if (!test_GetManagerVersion(p, mem_ctx, &version)) {
170 r.in.servername = host;
173 status = dcerpc_dfs_ManagerInitialize(p, mem_ctx, &r);
174 if (!NT_STATUS_IS_OK(status)) {
175 printf("ManagerInitialize failed - %s\n", nt_errstr(status));
177 } else if (!W_ERROR_IS_OK(r.out.result)) {
178 printf("dfs_ManagerInitialize failed - %s\n", win_errstr(r.out.result));
179 IS_DFS_VERSION_UNSUPPORTED_CALL_W2K3(version, r.out.result);
186 static bool test_GetInfoLevel(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint16_t level,
190 struct dfs_GetInfo r;
192 printf("Testing GetInfo level %u on '%s'\n", level, root);
194 r.in.dfs_entry_path = talloc_strdup(mem_ctx, root);
195 r.in.servername = NULL;
196 r.in.sharename = NULL;
199 status = dcerpc_dfs_GetInfo(p, mem_ctx, &r);
200 if (!NT_STATUS_IS_OK(status)) {
201 printf("GetInfo failed - %s\n", nt_errstr(status));
203 } else if (!W_ERROR_IS_OK(r.out.result) &&
204 !W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, r.out.result)) {
205 printf("dfs_GetInfo failed - %s\n", win_errstr(r.out.result));
212 static bool test_GetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, const char *root)
215 /* 103, 104, 105, 106 is only available on Set */
216 uint16_t levels[] = {1, 2, 3, 4, 5, 6, 7, 100, 101, 102, 103, 104, 105, 106};
219 for (i=0;i<ARRAY_SIZE(levels);i++) {
220 if (!test_GetInfoLevel(p, mem_ctx, levels[i], root)) {
227 static bool test_EnumLevelEx(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint16_t level, const char *dfs_name)
230 struct dfs_EnumEx rex;
232 struct dfs_EnumStruct e;
234 struct dfs_EnumArray1 e1;
237 rex.in.level = level;
238 rex.in.bufsize = (uint32_t)-1;
239 rex.in.total = &total;
241 rex.in.dfs_name = dfs_name;
243 e.level = rex.in.level;
245 e.e.info1->count = 0;
249 printf("Testing EnumEx level %u on '%s'\n", level, dfs_name);
251 status = dcerpc_dfs_EnumEx(p, mem_ctx, &rex);
252 if (!NT_STATUS_IS_OK(status)) {
253 printf("EnumEx failed - %s\n", nt_errstr(status));
257 if (level == 1 && rex.out.total) {
259 for (i=0;i<*rex.out.total;i++) {
260 const char *root = talloc_strdup(mem_ctx, rex.out.info->e.info1->s[i].path);
261 if (!test_GetInfo(p, mem_ctx, root)) {
267 if (level == 300 && rex.out.total) {
269 for (i=0;i<*rex.out.total;i++) {
270 uint16_t levels[] = {1, 2, 3, 4, 200}; /* 300 */
271 const char *root = talloc_strdup(mem_ctx, rex.out.info->e.info300->s[i].dom_root);
272 for (k=0;k<ARRAY_SIZE(levels);k++) {
273 if (!test_EnumLevelEx(p, mem_ctx, levels[k], root)) {
277 if (!test_GetInfo(p, mem_ctx, root)) {
287 static bool test_EnumLevel(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint16_t level)
292 struct dfs_EnumStruct e;
294 struct dfs_EnumArray1 e1;
298 r.in.bufsize = (uint32_t)-1;
302 e.level = r.in.level;
304 e.e.info1->count = 0;
308 printf("Testing Enum level %u\n", level);
310 status = dcerpc_dfs_Enum(p, mem_ctx, &r);
311 if (!NT_STATUS_IS_OK(status)) {
312 printf("Enum failed - %s\n", nt_errstr(status));
314 } else if (!W_ERROR_IS_OK(r.out.result) &&
315 !W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, r.out.result)) {
316 printf("dfs_Enum failed - %s\n", win_errstr(r.out.result));
320 if (level == 1 && r.out.total) {
322 for (i=0;i<*r.out.total;i++) {
323 const char *root = r.out.info->e.info1->s[i].path;
324 if (!test_GetInfo(p, mem_ctx, root)) {
335 static bool test_Enum(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
338 uint16_t levels[] = {1, 2, 3, 4, 200, 300};
341 for (i=0;i<ARRAY_SIZE(levels);i++) {
342 if (!test_EnumLevel(p, mem_ctx, levels[i])) {
350 static bool test_EnumEx(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, const char *host)
353 uint16_t levels[] = {1, 2, 3, 4, 200, 300};
356 for (i=0;i<ARRAY_SIZE(levels);i++) {
357 if (!test_EnumLevelEx(p, mem_ctx, levels[i], host)) {
365 static bool test_RemoveStdRoot(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, const char *host, const char *sharename)
367 struct dfs_RemoveStdRoot r;
370 printf("Testing RemoveStdRoot\n");
372 r.in.servername = host;
373 r.in.rootshare = sharename;
376 status = dcerpc_dfs_RemoveStdRoot(p, mem_ctx, &r);
377 if (!NT_STATUS_IS_OK(status)) {
378 printf("RemoveStdRoot failed - %s\n", nt_errstr(status));
380 } else if (!W_ERROR_IS_OK(r.out.result)) {
381 printf("dfs_RemoveStdRoot failed - %s\n", win_errstr(r.out.result));
388 static bool test_AddStdRoot(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, const char *host, const char *sharename)
391 struct dfs_AddStdRoot r;
393 printf("Testing AddStdRoot\n");
395 r.in.servername = host;
396 r.in.rootshare = sharename;
397 r.in.comment = "standard dfs standalone DFS root created by smbtorture (dfs_AddStdRoot)";
400 status = dcerpc_dfs_AddStdRoot(p, mem_ctx, &r);
401 if (!NT_STATUS_IS_OK(status)) {
402 printf("AddStdRoot failed - %s\n", nt_errstr(status));
404 } else if (!W_ERROR_IS_OK(r.out.result)) {
405 printf("dfs_AddStdRoot failed - %s\n", win_errstr(r.out.result));
412 static bool test_AddStdRootForced(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, const char *host, const char *sharename)
415 struct dfs_AddStdRootForced r;
416 enum dfs_ManagerVersion version;
418 printf("Testing AddStdRootForced\n");
420 if (!test_GetManagerVersion(p, mem_ctx, &version)) {
424 r.in.servername = host;
425 r.in.rootshare = sharename;
426 r.in.comment = "standard dfs forced standalone DFS root created by smbtorture (dfs_AddStdRootForced)";
427 r.in.store = SMBTORTURE_DFS_PATHNAME;
429 status = dcerpc_dfs_AddStdRootForced(p, mem_ctx, &r);
430 if (!NT_STATUS_IS_OK(status)) {
431 printf("AddStdRootForced failed - %s\n", nt_errstr(status));
433 } else if (!W_ERROR_IS_OK(r.out.result)) {
434 printf("dfs_AddStdRootForced failed - %s\n", win_errstr(r.out.result));
435 IS_DFS_VERSION_UNSUPPORTED_CALL_W2K3(version, r.out.result);
439 return test_RemoveStdRoot(p, mem_ctx, host, sharename);
442 static void test_cleanup_stdroot(struct dcerpc_pipe *p,
445 const char *sharename,
448 struct smbcli_state *cli;
450 printf("Cleaning up StdRoot\n");
452 test_RemoveStdRoot(p, mem_ctx, host, sharename);
453 test_NetShareDel(mem_ctx, host, sharename);
454 torture_open_connection_share(mem_ctx, &cli, host, "C$", NULL);
455 test_DeleteDir(cli, dir);
456 torture_close_connection(cli);
459 static bool test_StdRoot(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, const char *host)
461 const char *sharename = SMBTORTURE_DFS_SHARENAME;
462 const char *dir = SMBTORTURE_DFS_DIRNAME;
463 const char *path = SMBTORTURE_DFS_PATHNAME;
464 struct smbcli_state *cli;
467 printf("Testing StdRoot\n");
469 test_cleanup_stdroot(p, mem_ctx, host, sharename, dir);
471 ret &= test_CreateDir(mem_ctx, &cli, host, "C$", dir);
472 ret &= test_NetShareAdd(mem_ctx, host, sharename, path);
473 ret &= test_AddStdRoot(p, mem_ctx, host, sharename);
474 ret &= test_RemoveStdRoot(p, mem_ctx, host, sharename);
475 ret &= test_AddStdRootForced(p, mem_ctx, host, sharename);
476 ret &= test_NetShareDel(mem_ctx, host, sharename);
477 ret &= test_DeleteDir(cli, dir);
479 torture_close_connection(cli);
484 bool torture_rpc_dfs(struct torture_context *torture)
487 struct dcerpc_pipe *p;
489 enum dfs_ManagerVersion version;
490 const char *host = torture_setting_string(torture, "host", NULL);
492 status = torture_rpc_connection(torture, &p, &ndr_table_netdfs);
493 torture_assert_ntstatus_ok(torture, status, "Unable to connect");
495 ret &= test_GetManagerVersion(p, torture, &version);
496 ret &= test_ManagerInitialize(p, torture, host);
497 ret &= test_Enum(p, torture);
498 ret &= test_EnumEx(p, torture, host);
499 ret &= test_StdRoot(p, torture, host);