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(NULL, 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(NULL, 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, NULL)) {
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;
209 printf("Testing GetInfo level %u on '%s'\n", level, root);
211 r.in.dfs_entry_path = talloc_strdup(mem_ctx, root);
212 r.in.servername = NULL;
213 r.in.sharename = NULL;
216 status = dcerpc_dfs_GetInfo(p, mem_ctx, &r);
217 if (!NT_STATUS_IS_OK(status)) {
218 printf("GetInfo failed - %s\n", nt_errstr(status));
220 } else if (!W_ERROR_IS_OK(r.out.result) &&
221 !W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, r.out.result)) {
222 printf("dfs_GetInfo failed - %s\n", win_errstr(r.out.result));
229 static bool test_GetInfo(struct dcerpc_pipe *p,
234 /* 103, 104, 105, 106 is only available on Set */
235 uint16_t levels[] = {1, 2, 3, 4, 5, 6, 7, 100, 101, 102, 103, 104, 105, 106};
238 for (i=0;i<ARRAY_SIZE(levels);i++) {
239 if (!test_GetInfoLevel(p, mem_ctx, levels[i], root)) {
246 static bool test_EnumLevelEx(struct dcerpc_pipe *p,
249 const char *dfs_name)
252 struct dfs_EnumEx rex;
254 struct dfs_EnumStruct e;
256 struct dfs_EnumArray1 e1;
259 rex.in.level = level;
260 rex.in.bufsize = (uint32_t)-1;
261 rex.in.total = &total;
263 rex.in.dfs_name = dfs_name;
265 e.level = rex.in.level;
267 e.e.info1->count = 0;
271 printf("Testing EnumEx level %u on '%s'\n", level, dfs_name);
273 status = dcerpc_dfs_EnumEx(p, mem_ctx, &rex);
274 if (!NT_STATUS_IS_OK(status)) {
275 printf("EnumEx failed - %s\n", nt_errstr(status));
279 if (level == 1 && rex.out.total) {
281 for (i=0;i<*rex.out.total;i++) {
282 const char *root = talloc_strdup(mem_ctx,
283 rex.out.info->e.info1->s[i].path);
284 if (!test_GetInfo(p, mem_ctx, root)) {
290 if (level == 300 && rex.out.total) {
292 for (i=0;i<*rex.out.total;i++) {
293 uint16_t levels[] = {1, 2, 3, 4, 200}; /* 300 */
294 const char *root = talloc_strdup(mem_ctx,
295 rex.out.info->e.info300->s[i].dom_root);
296 for (k=0;k<ARRAY_SIZE(levels);k++) {
297 if (!test_EnumLevelEx(p, mem_ctx,
303 if (!test_GetInfo(p, mem_ctx, root)) {
313 static bool test_EnumLevel(struct dcerpc_pipe *p,
320 struct dfs_EnumStruct e;
322 struct dfs_EnumArray1 e1;
326 r.in.bufsize = (uint32_t)-1;
330 e.level = r.in.level;
332 e.e.info1->count = 0;
336 printf("Testing Enum level %u\n", level);
338 status = dcerpc_dfs_Enum(p, mem_ctx, &r);
339 if (!NT_STATUS_IS_OK(status)) {
340 printf("Enum failed - %s\n", nt_errstr(status));
342 } else if (!W_ERROR_IS_OK(r.out.result) &&
343 !W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, r.out.result)) {
344 printf("dfs_Enum failed - %s\n", win_errstr(r.out.result));
348 if (level == 1 && r.out.total) {
350 for (i=0;i<*r.out.total;i++) {
351 const char *root = r.out.info->e.info1->s[i].path;
352 if (!test_GetInfo(p, mem_ctx, root)) {
363 static bool test_Enum(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
366 uint16_t levels[] = {1, 2, 3, 4, 5, 6, 200, 300};
369 for (i=0;i<ARRAY_SIZE(levels);i++) {
370 if (!test_EnumLevel(p, mem_ctx, levels[i])) {
378 static bool test_EnumEx(struct dcerpc_pipe *p,
383 uint16_t levels[] = {1, 2, 3, 4, 5, 6, 200, 300};
386 for (i=0;i<ARRAY_SIZE(levels);i++) {
387 if (!test_EnumLevelEx(p, mem_ctx, levels[i], host)) {
395 static bool test_RemoveStdRoot(struct dcerpc_pipe *p,
398 const char *sharename)
400 struct dfs_RemoveStdRoot r;
403 printf("Testing RemoveStdRoot\n");
405 r.in.servername = host;
406 r.in.rootshare = sharename;
409 status = dcerpc_dfs_RemoveStdRoot(p, mem_ctx, &r);
410 if (!NT_STATUS_IS_OK(status)) {
411 printf("RemoveStdRoot failed - %s\n", nt_errstr(status));
413 } else if (!W_ERROR_IS_OK(r.out.result)) {
414 printf("dfs_RemoveStdRoot failed - %s\n",
415 win_errstr(r.out.result));
422 static bool test_AddStdRoot(struct dcerpc_pipe *p,
425 const char *sharename)
428 struct dfs_AddStdRoot r;
430 printf("Testing AddStdRoot\n");
432 r.in.servername = host;
433 r.in.rootshare = sharename;
434 r.in.comment = "standard dfs standalone DFS root created by smbtorture (dfs_AddStdRoot)";
437 status = dcerpc_dfs_AddStdRoot(p, mem_ctx, &r);
438 if (!NT_STATUS_IS_OK(status)) {
439 printf("AddStdRoot failed - %s\n", nt_errstr(status));
441 } else if (!W_ERROR_IS_OK(r.out.result)) {
442 printf("dfs_AddStdRoot failed - %s\n",
443 win_errstr(r.out.result));
450 static bool test_AddStdRootForced(struct dcerpc_pipe *p,
453 const char *sharename)
456 struct dfs_AddStdRootForced r;
457 enum dfs_ManagerVersion version;
459 printf("Testing AddStdRootForced\n");
461 if (!test_GetManagerVersion(p, mem_ctx, &version)) {
465 r.in.servername = host;
466 r.in.rootshare = sharename;
467 r.in.comment = "standard dfs forced standalone DFS root created by smbtorture (dfs_AddStdRootForced)";
468 r.in.store = SMBTORTURE_DFS_PATHNAME;
470 status = dcerpc_dfs_AddStdRootForced(p, mem_ctx, &r);
471 if (!NT_STATUS_IS_OK(status)) {
472 printf("AddStdRootForced failed - %s\n", nt_errstr(status));
474 } else if (!W_ERROR_IS_OK(r.out.result)) {
475 printf("dfs_AddStdRootForced failed - %s\n",
476 win_errstr(r.out.result));
477 IS_DFS_VERSION_UNSUPPORTED_CALL_W2K3(version, r.out.result);
481 return test_RemoveStdRoot(p, mem_ctx, host, sharename);
484 static void test_cleanup_stdroot(struct dcerpc_pipe *p,
486 struct torture_context *tctx,
488 const char *sharename,
491 struct smbcli_state *cli;
493 printf("Cleaning up StdRoot\n");
495 test_RemoveStdRoot(p, mem_ctx, host, sharename);
496 test_NetShareDel(mem_ctx, tctx, host, sharename);
497 torture_open_connection_share(mem_ctx, &cli, tctx, host, "C$", NULL);
498 test_DeleteDir(cli, dir);
499 torture_close_connection(cli);
502 static bool test_StdRoot(struct dcerpc_pipe *p,
504 struct torture_context *tctx,
507 const char *sharename = SMBTORTURE_DFS_SHARENAME;
508 const char *dir = SMBTORTURE_DFS_DIRNAME;
509 const char *path = SMBTORTURE_DFS_PATHNAME;
510 struct smbcli_state *cli;
513 printf("Testing StdRoot\n");
515 test_cleanup_stdroot(p, mem_ctx, tctx, host, sharename, dir);
517 ret &= test_CreateDir(mem_ctx, &cli, tctx, host, "C$", dir);
518 ret &= test_NetShareAdd(mem_ctx, tctx, host, sharename, path);
519 ret &= test_AddStdRoot(p, mem_ctx, host, sharename);
520 ret &= test_RemoveStdRoot(p, mem_ctx, host, sharename);
521 ret &= test_AddStdRootForced(p, mem_ctx, host, sharename);
522 ret &= test_NetShareDel(mem_ctx, tctx, host, sharename);
523 ret &= test_DeleteDir(cli, dir);
525 torture_close_connection(cli);
530 static bool test_GetDcAddress(struct dcerpc_pipe *p,
535 struct dfs_GetDcAddress r;
540 printf("Testing GetDcAddress\n");
544 r.in.servername = host;
545 r.in.server_fullname = r.out.server_fullname = &ptr;
546 r.in.is_root = r.out.is_root = &is_root;
547 r.in.ttl = r.out.ttl = &ttl;
549 status = dcerpc_dfs_GetDcAddress(p, mem_ctx, &r);
550 if (!NT_STATUS_IS_OK(status)) {
551 printf("GetDcAddress failed - %s\n", nt_errstr(status));
553 } else if (!W_ERROR_IS_OK(r.out.result)) {
554 printf("dfs_GetDcAddress failed - %s\n",
555 win_errstr(r.out.result));
562 static bool test_SetDcAddress(struct dcerpc_pipe *p,
567 struct dfs_SetDcAddress r;
569 printf("Testing SetDcAddress\n");
571 r.in.servername = host;
572 r.in.server_fullname = host;
576 status = dcerpc_dfs_SetDcAddress(p, mem_ctx, &r);
577 if (!NT_STATUS_IS_OK(status)) {
578 printf("SetDcAddress failed - %s\n", nt_errstr(status));
580 } else if (!W_ERROR_IS_OK(r.out.result)) {
581 printf("dfs_SetDcAddress failed - %s\n",
582 win_errstr(r.out.result));
589 static bool test_DcAddress(struct dcerpc_pipe *p,
593 if (!test_GetDcAddress(p, mem_ctx, host)) {
597 if (!test_SetDcAddress(p, mem_ctx, host)) {
604 static bool test_FlushFtTable(struct dcerpc_pipe *p,
607 const char *sharename)
610 struct dfs_FlushFtTable r;
611 enum dfs_ManagerVersion version;
613 printf("Testing FlushFtTable\n");
615 if (!test_GetManagerVersion(p, mem_ctx, &version)) {
619 r.in.servername = host;
620 r.in.rootshare = sharename;
622 status = dcerpc_dfs_FlushFtTable(p, mem_ctx, &r);
623 if (!NT_STATUS_IS_OK(status)) {
624 printf("FlushFtTable failed - %s\n", nt_errstr(status));
626 } else if (!W_ERROR_IS_OK(r.out.result)) {
627 printf("dfs_FlushFtTable failed - %s\n",
628 win_errstr(r.out.result));
629 IS_DFS_VERSION_UNSUPPORTED_CALL_W2K3(version, r.out.result);
636 static bool test_FtRoot(struct dcerpc_pipe *p,
640 const char *sharename = SMBTORTURE_DFS_SHARENAME;
642 return test_FlushFtTable(p, mem_ctx, host, sharename);
645 bool torture_rpc_dfs(struct torture_context *torture)
648 struct dcerpc_pipe *p;
650 enum dfs_ManagerVersion version;
651 const char *host = torture_setting_string(torture, "host", NULL);
653 status = torture_rpc_connection(torture, &p, &ndr_table_netdfs);
654 torture_assert_ntstatus_ok(torture, status, "Unable to connect");
656 ret &= test_GetManagerVersion(p, torture, &version);
657 ret &= test_ManagerInitialize(p, torture, host);
658 ret &= test_Enum(p, torture);
659 ret &= test_EnumEx(p, torture, host);
660 ret &= test_StdRoot(p, torture, torture, host);
661 ret &= test_FtRoot(p, torture, host);
662 ret &= test_DcAddress(p, torture, host);