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 3 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,
47 struct torture_context *tctx,
49 const char *sharename,
53 struct srvsvc_NetShareInfo2 i;
54 struct libnet_context* libnetctx;
55 struct libnet_AddShare r;
57 printf("Creating share %s\n", sharename);
59 if (!(libnetctx = libnet_context_init(tctx->ev, tctx->lp_ctx))) {
63 libnetctx->cred = cmdline_credentials;
66 i.type = STYPE_DISKTREE;
68 i.max_users = (uint32_t) -1;
69 i.comment = "created by smbtorture";
72 i.current_users = 0x0;
75 r.in.server_name = host;
78 status = libnet_AddShare(libnetctx, mem_ctx, &r);
79 if (!NT_STATUS_IS_OK(status)) {
80 d_printf("Failed to add new share: %s (%s)\n",
81 nt_errstr(status), r.out.error_string);
88 static bool test_NetShareDel(TALLOC_CTX *mem_ctx,
89 struct torture_context *tctx,
91 const char *sharename)
94 struct libnet_context* libnetctx;
95 struct libnet_DelShare r;
97 printf("Deleting share %s\n", sharename);
99 if (!(libnetctx = libnet_context_init(tctx->ev, tctx->lp_ctx))) {
103 libnetctx->cred = cmdline_credentials;
105 r.in.share_name = sharename;
106 r.in.server_name = host;
108 status = libnet_DelShare(libnetctx, mem_ctx, &r);
109 if (!NT_STATUS_IS_OK(status)) {
110 d_printf("Failed to delete share: %s (%s)\n",
111 nt_errstr(status), r.out.error_string);
118 static bool test_CreateDir(TALLOC_CTX *mem_ctx,
119 struct smbcli_state **cli,
120 struct torture_context *tctx,
125 printf("Creating directory %s\n", dir);
127 if (!torture_open_connection_share(mem_ctx, cli, tctx, host, share, tctx->ev)) {
131 if (!torture_setup_dir(*cli, dir)) {
138 static bool test_DeleteDir(struct smbcli_state *cli,
141 printf("Deleting directory %s\n", dir);
143 if (smbcli_deltree(cli->tree, dir) == -1) {
144 printf("Unable to delete dir %s - %s\n", dir,
145 smbcli_errstr(cli->tree));
152 static bool test_GetManagerVersion(struct dcerpc_pipe *p,
154 enum dfs_ManagerVersion *version)
157 struct dfs_GetManagerVersion r;
159 r.out.version = version;
161 status = dcerpc_dfs_GetManagerVersion(p, mem_ctx, &r);
162 if (!NT_STATUS_IS_OK(status)) {
163 printf("GetManagerVersion failed - %s\n", nt_errstr(status));
170 static bool test_ManagerInitialize(struct dcerpc_pipe *p,
175 enum dfs_ManagerVersion version;
176 struct dfs_ManagerInitialize r;
178 printf("Testing ManagerInitialize\n");
180 if (!test_GetManagerVersion(p, mem_ctx, &version)) {
184 r.in.servername = host;
187 status = dcerpc_dfs_ManagerInitialize(p, mem_ctx, &r);
188 if (!NT_STATUS_IS_OK(status)) {
189 printf("ManagerInitialize failed - %s\n", nt_errstr(status));
191 } else if (!W_ERROR_IS_OK(r.out.result)) {
192 printf("dfs_ManagerInitialize failed - %s\n",
193 win_errstr(r.out.result));
194 IS_DFS_VERSION_UNSUPPORTED_CALL_W2K3(version, r.out.result);
201 static bool test_GetInfoLevel(struct dcerpc_pipe *p,
207 struct dfs_GetInfo r;
210 printf("Testing GetInfo level %u on '%s'\n", level, root);
212 r.in.dfs_entry_path = talloc_strdup(mem_ctx, root);
213 r.in.servername = NULL;
214 r.in.sharename = NULL;
218 status = dcerpc_dfs_GetInfo(p, mem_ctx, &r);
219 if (!NT_STATUS_IS_OK(status)) {
220 printf("GetInfo failed - %s\n", nt_errstr(status));
222 } else if (!W_ERROR_IS_OK(r.out.result) &&
223 !W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, r.out.result)) {
224 printf("dfs_GetInfo failed - %s\n", win_errstr(r.out.result));
231 static bool test_GetInfo(struct dcerpc_pipe *p,
236 /* 103, 104, 105, 106 is only available on Set */
237 uint16_t levels[] = {1, 2, 3, 4, 5, 6, 7, 100, 101, 102, 103, 104, 105, 106};
240 for (i=0;i<ARRAY_SIZE(levels);i++) {
241 if (!test_GetInfoLevel(p, mem_ctx, levels[i], root)) {
248 static bool test_EnumLevelEx(struct dcerpc_pipe *p,
251 const char *dfs_name)
254 struct dfs_EnumEx rex;
256 struct dfs_EnumStruct e;
258 struct dfs_EnumArray1 e1;
261 rex.in.level = level;
262 rex.in.bufsize = (uint32_t)-1;
263 rex.in.total = &total;
265 rex.in.dfs_name = dfs_name;
267 e.level = rex.in.level;
269 e.e.info1->count = 0;
273 printf("Testing EnumEx level %u on '%s'\n", level, dfs_name);
275 status = dcerpc_dfs_EnumEx(p, mem_ctx, &rex);
276 if (!NT_STATUS_IS_OK(status)) {
277 printf("EnumEx failed - %s\n", nt_errstr(status));
281 if (level == 1 && rex.out.total) {
283 for (i=0;i<*rex.out.total;i++) {
284 const char *root = talloc_strdup(mem_ctx,
285 rex.out.info->e.info1->s[i].path);
286 if (!test_GetInfo(p, mem_ctx, root)) {
292 if (level == 300 && rex.out.total) {
294 for (i=0;i<*rex.out.total;i++) {
295 uint16_t levels[] = {1, 2, 3, 4, 200}; /* 300 */
296 const char *root = talloc_strdup(mem_ctx,
297 rex.out.info->e.info300->s[i].dom_root);
298 for (k=0;k<ARRAY_SIZE(levels);k++) {
299 if (!test_EnumLevelEx(p, mem_ctx,
305 if (!test_GetInfo(p, mem_ctx, root)) {
315 static bool test_EnumLevel(struct dcerpc_pipe *p,
322 struct dfs_EnumStruct e;
324 struct dfs_EnumArray1 e1;
328 r.in.bufsize = (uint32_t)-1;
332 e.level = r.in.level;
334 e.e.info1->count = 0;
338 printf("Testing Enum level %u\n", level);
340 status = dcerpc_dfs_Enum(p, mem_ctx, &r);
341 if (!NT_STATUS_IS_OK(status)) {
342 printf("Enum failed - %s\n", nt_errstr(status));
344 } else if (!W_ERROR_IS_OK(r.out.result) &&
345 !W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, r.out.result)) {
346 printf("dfs_Enum failed - %s\n", win_errstr(r.out.result));
350 if (level == 1 && r.out.total) {
352 for (i=0;i<*r.out.total;i++) {
353 const char *root = r.out.info->e.info1->s[i].path;
354 if (!test_GetInfo(p, mem_ctx, root)) {
365 static bool test_Enum(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
368 uint16_t levels[] = {1, 2, 3, 4, 5, 6, 200, 300};
371 for (i=0;i<ARRAY_SIZE(levels);i++) {
372 if (!test_EnumLevel(p, mem_ctx, levels[i])) {
380 static bool test_EnumEx(struct dcerpc_pipe *p,
385 uint16_t levels[] = {1, 2, 3, 4, 5, 6, 200, 300};
388 for (i=0;i<ARRAY_SIZE(levels);i++) {
389 if (!test_EnumLevelEx(p, mem_ctx, levels[i], host)) {
397 static bool test_RemoveStdRoot(struct dcerpc_pipe *p,
400 const char *sharename)
402 struct dfs_RemoveStdRoot r;
405 printf("Testing RemoveStdRoot\n");
407 r.in.servername = host;
408 r.in.rootshare = sharename;
411 status = dcerpc_dfs_RemoveStdRoot(p, mem_ctx, &r);
412 if (!NT_STATUS_IS_OK(status)) {
413 printf("RemoveStdRoot failed - %s\n", nt_errstr(status));
415 } else if (!W_ERROR_IS_OK(r.out.result)) {
416 printf("dfs_RemoveStdRoot failed - %s\n",
417 win_errstr(r.out.result));
424 static bool test_AddStdRoot(struct dcerpc_pipe *p,
427 const char *sharename)
430 struct dfs_AddStdRoot r;
432 printf("Testing AddStdRoot\n");
434 r.in.servername = host;
435 r.in.rootshare = sharename;
436 r.in.comment = "standard dfs standalone DFS root created by smbtorture (dfs_AddStdRoot)";
439 status = dcerpc_dfs_AddStdRoot(p, mem_ctx, &r);
440 if (!NT_STATUS_IS_OK(status)) {
441 printf("AddStdRoot failed - %s\n", nt_errstr(status));
443 } else if (!W_ERROR_IS_OK(r.out.result)) {
444 printf("dfs_AddStdRoot failed - %s\n",
445 win_errstr(r.out.result));
452 static bool test_AddStdRootForced(struct dcerpc_pipe *p,
455 const char *sharename)
458 struct dfs_AddStdRootForced r;
459 enum dfs_ManagerVersion version;
461 printf("Testing AddStdRootForced\n");
463 if (!test_GetManagerVersion(p, mem_ctx, &version)) {
467 r.in.servername = host;
468 r.in.rootshare = sharename;
469 r.in.comment = "standard dfs forced standalone DFS root created by smbtorture (dfs_AddStdRootForced)";
470 r.in.store = SMBTORTURE_DFS_PATHNAME;
472 status = dcerpc_dfs_AddStdRootForced(p, mem_ctx, &r);
473 if (!NT_STATUS_IS_OK(status)) {
474 printf("AddStdRootForced failed - %s\n", nt_errstr(status));
476 } else if (!W_ERROR_IS_OK(r.out.result)) {
477 printf("dfs_AddStdRootForced failed - %s\n",
478 win_errstr(r.out.result));
479 IS_DFS_VERSION_UNSUPPORTED_CALL_W2K3(version, r.out.result);
483 return test_RemoveStdRoot(p, mem_ctx, host, sharename);
486 static void test_cleanup_stdroot(struct dcerpc_pipe *p,
488 struct torture_context *tctx,
490 const char *sharename,
493 struct smbcli_state *cli;
495 printf("Cleaning up StdRoot\n");
497 test_RemoveStdRoot(p, mem_ctx, host, sharename);
498 test_NetShareDel(mem_ctx, tctx, host, sharename);
499 torture_open_connection_share(mem_ctx, &cli, tctx, host, "C$", tctx->ev);
500 test_DeleteDir(cli, dir);
501 torture_close_connection(cli);
504 static bool test_StdRoot(struct dcerpc_pipe *p,
506 struct torture_context *tctx,
509 const char *sharename = SMBTORTURE_DFS_SHARENAME;
510 const char *dir = SMBTORTURE_DFS_DIRNAME;
511 const char *path = SMBTORTURE_DFS_PATHNAME;
512 struct smbcli_state *cli;
515 printf("Testing StdRoot\n");
517 test_cleanup_stdroot(p, mem_ctx, tctx, host, sharename, dir);
519 ret &= test_CreateDir(mem_ctx, &cli, tctx, host, "C$", dir);
520 ret &= test_NetShareAdd(mem_ctx, tctx, host, sharename, path);
521 ret &= test_AddStdRoot(p, mem_ctx, host, sharename);
522 ret &= test_RemoveStdRoot(p, mem_ctx, host, sharename);
523 ret &= test_AddStdRootForced(p, mem_ctx, host, sharename);
524 ret &= test_NetShareDel(mem_ctx, tctx, host, sharename);
525 ret &= test_DeleteDir(cli, dir);
527 torture_close_connection(cli);
532 static bool test_GetDcAddress(struct dcerpc_pipe *p,
537 struct dfs_GetDcAddress r;
542 printf("Testing GetDcAddress\n");
546 r.in.servername = host;
547 r.in.server_fullname = r.out.server_fullname = &ptr;
548 r.in.is_root = r.out.is_root = &is_root;
549 r.in.ttl = r.out.ttl = &ttl;
551 status = dcerpc_dfs_GetDcAddress(p, mem_ctx, &r);
552 if (!NT_STATUS_IS_OK(status)) {
553 printf("GetDcAddress failed - %s\n", nt_errstr(status));
555 } else if (!W_ERROR_IS_OK(r.out.result)) {
556 printf("dfs_GetDcAddress failed - %s\n",
557 win_errstr(r.out.result));
564 static bool test_SetDcAddress(struct dcerpc_pipe *p,
569 struct dfs_SetDcAddress r;
571 printf("Testing SetDcAddress\n");
573 r.in.servername = host;
574 r.in.server_fullname = host;
578 status = dcerpc_dfs_SetDcAddress(p, mem_ctx, &r);
579 if (!NT_STATUS_IS_OK(status)) {
580 printf("SetDcAddress failed - %s\n", nt_errstr(status));
582 } else if (!W_ERROR_IS_OK(r.out.result)) {
583 printf("dfs_SetDcAddress failed - %s\n",
584 win_errstr(r.out.result));
591 static bool test_DcAddress(struct dcerpc_pipe *p,
595 if (!test_GetDcAddress(p, mem_ctx, host)) {
599 if (!test_SetDcAddress(p, mem_ctx, host)) {
606 static bool test_FlushFtTable(struct dcerpc_pipe *p,
609 const char *sharename)
612 struct dfs_FlushFtTable r;
613 enum dfs_ManagerVersion version;
615 printf("Testing FlushFtTable\n");
617 if (!test_GetManagerVersion(p, mem_ctx, &version)) {
621 r.in.servername = host;
622 r.in.rootshare = sharename;
624 status = dcerpc_dfs_FlushFtTable(p, mem_ctx, &r);
625 if (!NT_STATUS_IS_OK(status)) {
626 printf("FlushFtTable failed - %s\n", nt_errstr(status));
628 } else if (!W_ERROR_IS_OK(r.out.result)) {
629 printf("dfs_FlushFtTable failed - %s\n",
630 win_errstr(r.out.result));
631 IS_DFS_VERSION_UNSUPPORTED_CALL_W2K3(version, r.out.result);
638 static bool test_FtRoot(struct dcerpc_pipe *p,
642 const char *sharename = SMBTORTURE_DFS_SHARENAME;
644 return test_FlushFtTable(p, mem_ctx, host, sharename);
647 bool torture_rpc_dfs(struct torture_context *torture)
650 struct dcerpc_pipe *p;
652 enum dfs_ManagerVersion version;
653 const char *host = torture_setting_string(torture, "host", NULL);
655 status = torture_rpc_connection(torture, &p, &ndr_table_netdfs);
656 torture_assert_ntstatus_ok(torture, status, "Unable to connect");
658 ret &= test_GetManagerVersion(p, torture, &version);
659 ret &= test_ManagerInitialize(p, torture, host);
660 ret &= test_Enum(p, torture);
661 ret &= test_EnumEx(p, torture, host);
662 ret &= test_StdRoot(p, torture, torture, host);
663 ret &= test_FtRoot(p, torture, host);
664 ret &= test_DcAddress(p, torture, host);