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,
48 const char *sharename,
52 struct srvsvc_NetShareInfo2 i;
53 struct libnet_context* libnetctx;
54 struct libnet_AddShare r;
56 printf("Creating share %s\n", sharename);
58 if (!(libnetctx = libnet_context_init(NULL))) {
62 libnetctx->cred = cmdline_credentials;
65 i.type = STYPE_DISKTREE;
67 i.max_users = (uint32_t) -1;
68 i.comment = "created by smbtorture";
71 i.current_users = 0x0;
74 r.in.server_name = host;
77 status = libnet_AddShare(libnetctx, mem_ctx, &r);
78 if (!NT_STATUS_IS_OK(status)) {
79 d_printf("Failed to add new share: %s (%s)\n",
80 nt_errstr(status), r.out.error_string);
87 static bool test_NetShareDel(TALLOC_CTX *mem_ctx,
89 const char *sharename)
92 struct libnet_context* libnetctx;
93 struct libnet_DelShare r;
95 printf("Deleting share %s\n", sharename);
97 if (!(libnetctx = libnet_context_init(NULL))) {
101 libnetctx->cred = cmdline_credentials;
103 r.in.share_name = sharename;
104 r.in.server_name = host;
106 status = libnet_DelShare(libnetctx, mem_ctx, &r);
107 if (!NT_STATUS_IS_OK(status)) {
108 d_printf("Failed to delete share: %s (%s)\n",
109 nt_errstr(status), r.out.error_string);
116 static bool test_CreateDir(TALLOC_CTX *mem_ctx,
117 struct smbcli_state **cli,
122 printf("Creating directory %s\n", dir);
124 if (!torture_open_connection_share(mem_ctx, cli, host, share, NULL)) {
128 if (!torture_setup_dir(*cli, dir)) {
135 static bool test_DeleteDir(struct smbcli_state *cli,
138 printf("Deleting directory %s\n", dir);
140 if (smbcli_deltree(cli->tree, dir) == -1) {
141 printf("Unable to delete dir %s - %s\n", dir,
142 smbcli_errstr(cli->tree));
149 static bool test_GetManagerVersion(struct dcerpc_pipe *p,
151 enum dfs_ManagerVersion *version)
154 struct dfs_GetManagerVersion r;
156 r.out.version = version;
158 status = dcerpc_dfs_GetManagerVersion(p, mem_ctx, &r);
159 if (!NT_STATUS_IS_OK(status)) {
160 printf("GetManagerVersion failed - %s\n", nt_errstr(status));
167 static bool test_ManagerInitialize(struct dcerpc_pipe *p,
172 enum dfs_ManagerVersion version;
173 struct dfs_ManagerInitialize r;
175 printf("Testing ManagerInitialize\n");
177 if (!test_GetManagerVersion(p, mem_ctx, &version)) {
181 r.in.servername = host;
184 status = dcerpc_dfs_ManagerInitialize(p, mem_ctx, &r);
185 if (!NT_STATUS_IS_OK(status)) {
186 printf("ManagerInitialize failed - %s\n", nt_errstr(status));
188 } else if (!W_ERROR_IS_OK(r.out.result)) {
189 printf("dfs_ManagerInitialize failed - %s\n",
190 win_errstr(r.out.result));
191 IS_DFS_VERSION_UNSUPPORTED_CALL_W2K3(version, r.out.result);
198 static bool test_GetInfoLevel(struct dcerpc_pipe *p,
204 struct dfs_GetInfo r;
206 printf("Testing GetInfo level %u on '%s'\n", level, root);
208 r.in.dfs_entry_path = talloc_strdup(mem_ctx, root);
209 r.in.servername = NULL;
210 r.in.sharename = NULL;
213 status = dcerpc_dfs_GetInfo(p, mem_ctx, &r);
214 if (!NT_STATUS_IS_OK(status)) {
215 printf("GetInfo failed - %s\n", nt_errstr(status));
217 } else if (!W_ERROR_IS_OK(r.out.result) &&
218 !W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, r.out.result)) {
219 printf("dfs_GetInfo failed - %s\n", win_errstr(r.out.result));
226 static bool test_GetInfo(struct dcerpc_pipe *p,
231 /* 103, 104, 105, 106 is only available on Set */
232 uint16_t levels[] = {1, 2, 3, 4, 5, 6, 7, 100, 101, 102, 103, 104, 105, 106};
235 for (i=0;i<ARRAY_SIZE(levels);i++) {
236 if (!test_GetInfoLevel(p, mem_ctx, levels[i], root)) {
243 static bool test_EnumLevelEx(struct dcerpc_pipe *p,
246 const char *dfs_name)
249 struct dfs_EnumEx rex;
251 struct dfs_EnumStruct e;
253 struct dfs_EnumArray1 e1;
256 rex.in.level = level;
257 rex.in.bufsize = (uint32_t)-1;
258 rex.in.total = &total;
260 rex.in.dfs_name = dfs_name;
262 e.level = rex.in.level;
264 e.e.info1->count = 0;
268 printf("Testing EnumEx level %u on '%s'\n", level, dfs_name);
270 status = dcerpc_dfs_EnumEx(p, mem_ctx, &rex);
271 if (!NT_STATUS_IS_OK(status)) {
272 printf("EnumEx failed - %s\n", nt_errstr(status));
276 if (level == 1 && rex.out.total) {
278 for (i=0;i<*rex.out.total;i++) {
279 const char *root = talloc_strdup(mem_ctx,
280 rex.out.info->e.info1->s[i].path);
281 if (!test_GetInfo(p, mem_ctx, root)) {
287 if (level == 300 && rex.out.total) {
289 for (i=0;i<*rex.out.total;i++) {
290 uint16_t levels[] = {1, 2, 3, 4, 200}; /* 300 */
291 const char *root = talloc_strdup(mem_ctx,
292 rex.out.info->e.info300->s[i].dom_root);
293 for (k=0;k<ARRAY_SIZE(levels);k++) {
294 if (!test_EnumLevelEx(p, mem_ctx,
300 if (!test_GetInfo(p, mem_ctx, root)) {
310 static bool test_EnumLevel(struct dcerpc_pipe *p,
317 struct dfs_EnumStruct e;
319 struct dfs_EnumArray1 e1;
323 r.in.bufsize = (uint32_t)-1;
327 e.level = r.in.level;
329 e.e.info1->count = 0;
333 printf("Testing Enum level %u\n", level);
335 status = dcerpc_dfs_Enum(p, mem_ctx, &r);
336 if (!NT_STATUS_IS_OK(status)) {
337 printf("Enum failed - %s\n", nt_errstr(status));
339 } else if (!W_ERROR_IS_OK(r.out.result) &&
340 !W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, r.out.result)) {
341 printf("dfs_Enum failed - %s\n", win_errstr(r.out.result));
345 if (level == 1 && r.out.total) {
347 for (i=0;i<*r.out.total;i++) {
348 const char *root = r.out.info->e.info1->s[i].path;
349 if (!test_GetInfo(p, mem_ctx, root)) {
360 static bool test_Enum(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
363 uint16_t levels[] = {1, 2, 3, 4, 5, 6, 200, 300};
366 for (i=0;i<ARRAY_SIZE(levels);i++) {
367 if (!test_EnumLevel(p, mem_ctx, levels[i])) {
375 static bool test_EnumEx(struct dcerpc_pipe *p,
380 uint16_t levels[] = {1, 2, 3, 4, 5, 6, 200, 300};
383 for (i=0;i<ARRAY_SIZE(levels);i++) {
384 if (!test_EnumLevelEx(p, mem_ctx, levels[i], host)) {
392 static bool test_RemoveStdRoot(struct dcerpc_pipe *p,
395 const char *sharename)
397 struct dfs_RemoveStdRoot r;
400 printf("Testing RemoveStdRoot\n");
402 r.in.servername = host;
403 r.in.rootshare = sharename;
406 status = dcerpc_dfs_RemoveStdRoot(p, mem_ctx, &r);
407 if (!NT_STATUS_IS_OK(status)) {
408 printf("RemoveStdRoot failed - %s\n", nt_errstr(status));
410 } else if (!W_ERROR_IS_OK(r.out.result)) {
411 printf("dfs_RemoveStdRoot failed - %s\n",
412 win_errstr(r.out.result));
419 static bool test_AddStdRoot(struct dcerpc_pipe *p,
422 const char *sharename)
425 struct dfs_AddStdRoot r;
427 printf("Testing AddStdRoot\n");
429 r.in.servername = host;
430 r.in.rootshare = sharename;
431 r.in.comment = "standard dfs standalone DFS root created by smbtorture (dfs_AddStdRoot)";
434 status = dcerpc_dfs_AddStdRoot(p, mem_ctx, &r);
435 if (!NT_STATUS_IS_OK(status)) {
436 printf("AddStdRoot failed - %s\n", nt_errstr(status));
438 } else if (!W_ERROR_IS_OK(r.out.result)) {
439 printf("dfs_AddStdRoot failed - %s\n",
440 win_errstr(r.out.result));
447 static bool test_AddStdRootForced(struct dcerpc_pipe *p,
450 const char *sharename)
453 struct dfs_AddStdRootForced r;
454 enum dfs_ManagerVersion version;
456 printf("Testing AddStdRootForced\n");
458 if (!test_GetManagerVersion(p, mem_ctx, &version)) {
462 r.in.servername = host;
463 r.in.rootshare = sharename;
464 r.in.comment = "standard dfs forced standalone DFS root created by smbtorture (dfs_AddStdRootForced)";
465 r.in.store = SMBTORTURE_DFS_PATHNAME;
467 status = dcerpc_dfs_AddStdRootForced(p, mem_ctx, &r);
468 if (!NT_STATUS_IS_OK(status)) {
469 printf("AddStdRootForced failed - %s\n", nt_errstr(status));
471 } else if (!W_ERROR_IS_OK(r.out.result)) {
472 printf("dfs_AddStdRootForced failed - %s\n",
473 win_errstr(r.out.result));
474 IS_DFS_VERSION_UNSUPPORTED_CALL_W2K3(version, r.out.result);
478 return test_RemoveStdRoot(p, mem_ctx, host, sharename);
481 static void test_cleanup_stdroot(struct dcerpc_pipe *p,
484 const char *sharename,
487 struct smbcli_state *cli;
489 printf("Cleaning up StdRoot\n");
491 test_RemoveStdRoot(p, mem_ctx, host, sharename);
492 test_NetShareDel(mem_ctx, host, sharename);
493 torture_open_connection_share(mem_ctx, &cli, host, "C$", NULL);
494 test_DeleteDir(cli, dir);
495 torture_close_connection(cli);
498 static bool test_StdRoot(struct dcerpc_pipe *p,
502 const char *sharename = SMBTORTURE_DFS_SHARENAME;
503 const char *dir = SMBTORTURE_DFS_DIRNAME;
504 const char *path = SMBTORTURE_DFS_PATHNAME;
505 struct smbcli_state *cli;
508 printf("Testing StdRoot\n");
510 test_cleanup_stdroot(p, mem_ctx, host, sharename, dir);
512 ret &= test_CreateDir(mem_ctx, &cli, host, "C$", dir);
513 ret &= test_NetShareAdd(mem_ctx, host, sharename, path);
514 ret &= test_AddStdRoot(p, mem_ctx, host, sharename);
515 ret &= test_RemoveStdRoot(p, mem_ctx, host, sharename);
516 ret &= test_AddStdRootForced(p, mem_ctx, host, sharename);
517 ret &= test_NetShareDel(mem_ctx, host, sharename);
518 ret &= test_DeleteDir(cli, dir);
520 torture_close_connection(cli);
525 static bool test_GetDcAddress(struct dcerpc_pipe *p,
530 struct dfs_GetDcAddress r;
535 printf("Testing GetDcAddress\n");
539 r.in.servername = host;
540 r.in.server_fullname = r.out.server_fullname = &ptr;
541 r.in.is_root = r.out.is_root = &is_root;
542 r.in.ttl = r.out.ttl = &ttl;
544 status = dcerpc_dfs_GetDcAddress(p, mem_ctx, &r);
545 if (!NT_STATUS_IS_OK(status)) {
546 printf("GetDcAddress failed - %s\n", nt_errstr(status));
548 } else if (!W_ERROR_IS_OK(r.out.result)) {
549 printf("dfs_GetDcAddress failed - %s\n",
550 win_errstr(r.out.result));
557 static bool test_SetDcAddress(struct dcerpc_pipe *p,
562 struct dfs_SetDcAddress r;
564 printf("Testing SetDcAddress\n");
566 r.in.servername = host;
567 r.in.server_fullname = host;
571 status = dcerpc_dfs_SetDcAddress(p, mem_ctx, &r);
572 if (!NT_STATUS_IS_OK(status)) {
573 printf("SetDcAddress failed - %s\n", nt_errstr(status));
575 } else if (!W_ERROR_IS_OK(r.out.result)) {
576 printf("dfs_SetDcAddress failed - %s\n",
577 win_errstr(r.out.result));
584 static bool test_DcAddress(struct dcerpc_pipe *p,
588 if (!test_GetDcAddress(p, mem_ctx, host)) {
592 if (!test_SetDcAddress(p, mem_ctx, host)) {
599 static bool test_FlushFtTable(struct dcerpc_pipe *p,
602 const char *sharename)
605 struct dfs_FlushFtTable r;
606 enum dfs_ManagerVersion version;
608 printf("Testing FlushFtTable\n");
610 if (!test_GetManagerVersion(p, mem_ctx, &version)) {
614 r.in.servername = host;
615 r.in.rootshare = sharename;
617 status = dcerpc_dfs_FlushFtTable(p, mem_ctx, &r);
618 if (!NT_STATUS_IS_OK(status)) {
619 printf("FlushFtTable failed - %s\n", nt_errstr(status));
621 } else if (!W_ERROR_IS_OK(r.out.result)) {
622 printf("dfs_FlushFtTable failed - %s\n",
623 win_errstr(r.out.result));
624 IS_DFS_VERSION_UNSUPPORTED_CALL_W2K3(version, r.out.result);
631 static bool test_FtRoot(struct dcerpc_pipe *p,
635 const char *sharename = SMBTORTURE_DFS_SHARENAME;
637 return test_FlushFtTable(p, mem_ctx, host, sharename);
640 bool torture_rpc_dfs(struct torture_context *torture)
643 struct dcerpc_pipe *p;
645 enum dfs_ManagerVersion version;
646 const char *host = torture_setting_string(torture, "host", NULL);
648 status = torture_rpc_connection(torture, &p, &ndr_table_netdfs);
649 torture_assert_ntstatus_ok(torture, status, "Unable to connect");
651 ret &= test_GetManagerVersion(p, torture, &version);
652 ret &= test_ManagerInitialize(p, torture, host);
653 ret &= test_Enum(p, torture);
654 ret &= test_EnumEx(p, torture, host);
655 ret &= test_StdRoot(p, torture, host);
656 ret &= test_FtRoot(p, torture, host);
657 ret &= test_DcAddress(p, torture, host);