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/rpc/rpc.h"
24 #include "librpc/gen_ndr/ndr_dfs_c.h"
25 #include "libnet/libnet.h"
26 #include "torture/util.h"
27 #include "libcli/libcli.h"
28 #include "lib/cmdline/popt_common.h"
30 #define SMBTORTURE_DFS_SHARENAME "smbtorture_dfs_share"
31 #define SMBTORTURE_DFS_DIRNAME "\\smbtorture_dfs_dir"
32 #define SMBTORTURE_DFS_PATHNAME "C:"SMBTORTURE_DFS_DIRNAME
34 #define IS_DFS_VERSION_UNSUPPORTED_CALL_W2K3(x,y)\
35 if (x == DFS_MANAGER_VERSION_W2K3) {\
36 if (!W_ERROR_EQUAL(y,WERR_NOT_SUPPORTED)) {\
37 printf("expected WERR_NOT_SUPPORTED\n");\
43 static bool test_NetShareAdd(TALLOC_CTX *mem_ctx,
44 struct torture_context
*tctx
,
46 const char *sharename
,
50 struct srvsvc_NetShareInfo2 i
;
51 struct libnet_context
* libnetctx
;
52 struct libnet_AddShare r
;
54 printf("Creating share %s\n", sharename
);
56 if (!(libnetctx
= libnet_context_init(tctx
->ev
, tctx
->lp_ctx
))) {
60 libnetctx
->cred
= cmdline_credentials
;
63 i
.type
= STYPE_DISKTREE
;
65 i
.max_users
= (uint32_t) -1;
66 i
.comment
= "created by smbtorture";
69 i
.current_users
= 0x0;
72 r
.in
.server_name
= host
;
75 status
= libnet_AddShare(libnetctx
, mem_ctx
, &r
);
76 if (!NT_STATUS_IS_OK(status
)) {
77 d_printf("Failed to add new share: %s (%s)\n",
78 nt_errstr(status
), r
.out
.error_string
);
85 static bool test_NetShareDel(TALLOC_CTX
*mem_ctx
,
86 struct torture_context
*tctx
,
88 const char *sharename
)
91 struct libnet_context
* libnetctx
;
92 struct libnet_DelShare r
;
94 printf("Deleting share %s\n", sharename
);
96 if (!(libnetctx
= libnet_context_init(tctx
->ev
, tctx
->lp_ctx
))) {
100 libnetctx
->cred
= cmdline_credentials
;
102 r
.in
.share_name
= sharename
;
103 r
.in
.server_name
= host
;
105 status
= libnet_DelShare(libnetctx
, mem_ctx
, &r
);
106 if (!NT_STATUS_IS_OK(status
)) {
107 d_printf("Failed to delete share: %s (%s)\n",
108 nt_errstr(status
), r
.out
.error_string
);
115 static bool test_CreateDir(TALLOC_CTX
*mem_ctx
,
116 struct smbcli_state
**cli
,
117 struct torture_context
*tctx
,
122 printf("Creating directory %s\n", dir
);
124 if (!torture_open_connection_share(mem_ctx
, cli
, tctx
, host
, share
, tctx
->ev
)) {
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
;
207 printf("Testing GetInfo level %u on '%s'\n", level
, root
);
209 r
.in
.dfs_entry_path
= talloc_strdup(mem_ctx
, root
);
210 r
.in
.servername
= NULL
;
211 r
.in
.sharename
= NULL
;
215 status
= dcerpc_dfs_GetInfo(p
, mem_ctx
, &r
);
216 if (!NT_STATUS_IS_OK(status
)) {
217 printf("GetInfo failed - %s\n", nt_errstr(status
));
219 } else if (!W_ERROR_IS_OK(r
.out
.result
) &&
220 !W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, r
.out
.result
)) {
221 printf("dfs_GetInfo failed - %s\n", win_errstr(r
.out
.result
));
228 static bool test_GetInfo(struct dcerpc_pipe
*p
,
233 /* 103, 104, 105, 106 is only available on Set */
234 uint16_t levels
[] = {1, 2, 3, 4, 5, 6, 7, 100, 101, 102, 103, 104, 105, 106};
237 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
238 if (!test_GetInfoLevel(p
, mem_ctx
, levels
[i
], root
)) {
245 static bool test_EnumLevelEx(struct dcerpc_pipe
*p
,
248 const char *dfs_name
)
251 struct dfs_EnumEx rex
;
253 struct dfs_EnumStruct e
;
255 struct dfs_EnumArray1 e1
;
258 rex
.in
.level
= level
;
259 rex
.in
.bufsize
= (uint32_t)-1;
260 rex
.in
.total
= &total
;
262 rex
.in
.dfs_name
= dfs_name
;
264 e
.level
= rex
.in
.level
;
266 e
.e
.info1
->count
= 0;
270 printf("Testing EnumEx level %u on '%s'\n", level
, dfs_name
);
272 status
= dcerpc_dfs_EnumEx(p
, mem_ctx
, &rex
);
273 if (!NT_STATUS_IS_OK(status
)) {
274 printf("EnumEx failed - %s\n", nt_errstr(status
));
278 if (level
== 1 && rex
.out
.total
) {
280 for (i
=0;i
<*rex
.out
.total
;i
++) {
281 const char *root
= talloc_strdup(mem_ctx
,
282 rex
.out
.info
->e
.info1
->s
[i
].path
);
283 if (!test_GetInfo(p
, mem_ctx
, root
)) {
289 if (level
== 300 && rex
.out
.total
) {
291 for (i
=0;i
<*rex
.out
.total
;i
++) {
292 uint16_t levels
[] = {1, 2, 3, 4, 200}; /* 300 */
293 const char *root
= talloc_strdup(mem_ctx
,
294 rex
.out
.info
->e
.info300
->s
[i
].dom_root
);
295 for (k
=0;k
<ARRAY_SIZE(levels
);k
++) {
296 if (!test_EnumLevelEx(p
, mem_ctx
,
302 if (!test_GetInfo(p
, mem_ctx
, root
)) {
312 static bool test_EnumLevel(struct dcerpc_pipe
*p
,
319 struct dfs_EnumStruct e
;
321 struct dfs_EnumArray1 e1
;
325 r
.in
.bufsize
= (uint32_t)-1;
329 e
.level
= r
.in
.level
;
331 e
.e
.info1
->count
= 0;
335 printf("Testing Enum level %u\n", level
);
337 status
= dcerpc_dfs_Enum(p
, mem_ctx
, &r
);
338 if (!NT_STATUS_IS_OK(status
)) {
339 printf("Enum failed - %s\n", nt_errstr(status
));
341 } else if (!W_ERROR_IS_OK(r
.out
.result
) &&
342 !W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, r
.out
.result
)) {
343 printf("dfs_Enum failed - %s\n", win_errstr(r
.out
.result
));
347 if (level
== 1 && r
.out
.total
) {
349 for (i
=0;i
<*r
.out
.total
;i
++) {
350 const char *root
= r
.out
.info
->e
.info1
->s
[i
].path
;
351 if (!test_GetInfo(p
, mem_ctx
, root
)) {
362 static bool test_Enum(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
)
365 uint16_t levels
[] = {1, 2, 3, 4, 5, 6, 200, 300};
368 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
369 if (!test_EnumLevel(p
, mem_ctx
, levels
[i
])) {
377 static bool test_EnumEx(struct dcerpc_pipe
*p
,
382 uint16_t levels
[] = {1, 2, 3, 4, 5, 6, 200, 300};
385 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
386 if (!test_EnumLevelEx(p
, mem_ctx
, levels
[i
], host
)) {
394 static bool test_RemoveStdRoot(struct dcerpc_pipe
*p
,
397 const char *sharename
)
399 struct dfs_RemoveStdRoot r
;
402 printf("Testing RemoveStdRoot\n");
404 r
.in
.servername
= host
;
405 r
.in
.rootshare
= sharename
;
408 status
= dcerpc_dfs_RemoveStdRoot(p
, mem_ctx
, &r
);
409 if (!NT_STATUS_IS_OK(status
)) {
410 printf("RemoveStdRoot failed - %s\n", nt_errstr(status
));
412 } else if (!W_ERROR_IS_OK(r
.out
.result
)) {
413 printf("dfs_RemoveStdRoot failed - %s\n",
414 win_errstr(r
.out
.result
));
421 static bool test_AddStdRoot(struct dcerpc_pipe
*p
,
424 const char *sharename
)
427 struct dfs_AddStdRoot r
;
429 printf("Testing AddStdRoot\n");
431 r
.in
.servername
= host
;
432 r
.in
.rootshare
= sharename
;
433 r
.in
.comment
= "standard dfs standalone DFS root created by smbtorture (dfs_AddStdRoot)";
436 status
= dcerpc_dfs_AddStdRoot(p
, mem_ctx
, &r
);
437 if (!NT_STATUS_IS_OK(status
)) {
438 printf("AddStdRoot failed - %s\n", nt_errstr(status
));
440 } else if (!W_ERROR_IS_OK(r
.out
.result
)) {
441 printf("dfs_AddStdRoot failed - %s\n",
442 win_errstr(r
.out
.result
));
449 static bool test_AddStdRootForced(struct dcerpc_pipe
*p
,
452 const char *sharename
)
455 struct dfs_AddStdRootForced r
;
456 enum dfs_ManagerVersion version
;
458 printf("Testing AddStdRootForced\n");
460 if (!test_GetManagerVersion(p
, mem_ctx
, &version
)) {
464 r
.in
.servername
= host
;
465 r
.in
.rootshare
= sharename
;
466 r
.in
.comment
= "standard dfs forced standalone DFS root created by smbtorture (dfs_AddStdRootForced)";
467 r
.in
.store
= SMBTORTURE_DFS_PATHNAME
;
469 status
= dcerpc_dfs_AddStdRootForced(p
, mem_ctx
, &r
);
470 if (!NT_STATUS_IS_OK(status
)) {
471 printf("AddStdRootForced failed - %s\n", nt_errstr(status
));
473 } else if (!W_ERROR_IS_OK(r
.out
.result
)) {
474 printf("dfs_AddStdRootForced failed - %s\n",
475 win_errstr(r
.out
.result
));
476 IS_DFS_VERSION_UNSUPPORTED_CALL_W2K3(version
, r
.out
.result
);
480 return test_RemoveStdRoot(p
, mem_ctx
, host
, sharename
);
483 static void test_cleanup_stdroot(struct dcerpc_pipe
*p
,
485 struct torture_context
*tctx
,
487 const char *sharename
,
490 struct smbcli_state
*cli
;
492 printf("Cleaning up StdRoot\n");
494 test_RemoveStdRoot(p
, mem_ctx
, host
, sharename
);
495 test_NetShareDel(mem_ctx
, tctx
, host
, sharename
);
496 torture_open_connection_share(mem_ctx
, &cli
, tctx
, host
, "C$", tctx
->ev
);
497 test_DeleteDir(cli
, dir
);
498 torture_close_connection(cli
);
501 static bool test_StdRoot(struct dcerpc_pipe
*p
,
503 struct torture_context
*tctx
,
506 const char *sharename
= SMBTORTURE_DFS_SHARENAME
;
507 const char *dir
= SMBTORTURE_DFS_DIRNAME
;
508 const char *path
= SMBTORTURE_DFS_PATHNAME
;
509 struct smbcli_state
*cli
;
512 printf("Testing StdRoot\n");
514 test_cleanup_stdroot(p
, mem_ctx
, tctx
, host
, sharename
, dir
);
516 ret
&= test_CreateDir(mem_ctx
, &cli
, tctx
, host
, "C$", dir
);
517 ret
&= test_NetShareAdd(mem_ctx
, tctx
, host
, sharename
, path
);
518 ret
&= test_AddStdRoot(p
, mem_ctx
, host
, sharename
);
519 ret
&= test_RemoveStdRoot(p
, mem_ctx
, host
, sharename
);
520 ret
&= test_AddStdRootForced(p
, mem_ctx
, host
, sharename
);
521 ret
&= test_NetShareDel(mem_ctx
, tctx
, host
, sharename
);
522 ret
&= test_DeleteDir(cli
, dir
);
524 torture_close_connection(cli
);
529 static bool test_GetDcAddress(struct dcerpc_pipe
*p
,
534 struct dfs_GetDcAddress r
;
539 printf("Testing GetDcAddress\n");
543 r
.in
.servername
= host
;
544 r
.in
.server_fullname
= r
.out
.server_fullname
= &ptr
;
545 r
.in
.is_root
= r
.out
.is_root
= &is_root
;
546 r
.in
.ttl
= r
.out
.ttl
= &ttl
;
548 status
= dcerpc_dfs_GetDcAddress(p
, mem_ctx
, &r
);
549 if (!NT_STATUS_IS_OK(status
)) {
550 printf("GetDcAddress failed - %s\n", nt_errstr(status
));
552 } else if (!W_ERROR_IS_OK(r
.out
.result
)) {
553 printf("dfs_GetDcAddress failed - %s\n",
554 win_errstr(r
.out
.result
));
561 static bool test_SetDcAddress(struct dcerpc_pipe
*p
,
566 struct dfs_SetDcAddress r
;
568 printf("Testing SetDcAddress\n");
570 r
.in
.servername
= host
;
571 r
.in
.server_fullname
= host
;
575 status
= dcerpc_dfs_SetDcAddress(p
, mem_ctx
, &r
);
576 if (!NT_STATUS_IS_OK(status
)) {
577 printf("SetDcAddress failed - %s\n", nt_errstr(status
));
579 } else if (!W_ERROR_IS_OK(r
.out
.result
)) {
580 printf("dfs_SetDcAddress failed - %s\n",
581 win_errstr(r
.out
.result
));
588 static bool test_DcAddress(struct dcerpc_pipe
*p
,
592 if (!test_GetDcAddress(p
, mem_ctx
, host
)) {
596 if (!test_SetDcAddress(p
, mem_ctx
, host
)) {
603 static bool test_FlushFtTable(struct dcerpc_pipe
*p
,
606 const char *sharename
)
609 struct dfs_FlushFtTable r
;
610 enum dfs_ManagerVersion version
;
612 printf("Testing FlushFtTable\n");
614 if (!test_GetManagerVersion(p
, mem_ctx
, &version
)) {
618 r
.in
.servername
= host
;
619 r
.in
.rootshare
= sharename
;
621 status
= dcerpc_dfs_FlushFtTable(p
, mem_ctx
, &r
);
622 if (!NT_STATUS_IS_OK(status
)) {
623 printf("FlushFtTable failed - %s\n", nt_errstr(status
));
625 } else if (!W_ERROR_IS_OK(r
.out
.result
)) {
626 printf("dfs_FlushFtTable failed - %s\n",
627 win_errstr(r
.out
.result
));
628 IS_DFS_VERSION_UNSUPPORTED_CALL_W2K3(version
, r
.out
.result
);
635 static bool test_FtRoot(struct dcerpc_pipe
*p
,
639 const char *sharename
= SMBTORTURE_DFS_SHARENAME
;
641 return test_FlushFtTable(p
, mem_ctx
, host
, sharename
);
644 bool torture_rpc_dfs(struct torture_context
*torture
)
647 struct dcerpc_pipe
*p
;
649 enum dfs_ManagerVersion version
;
650 const char *host
= torture_setting_string(torture
, "host", NULL
);
652 status
= torture_rpc_connection(torture
, &p
, &ndr_table_netdfs
);
653 torture_assert_ntstatus_ok(torture
, status
, "Unable to connect");
655 ret
&= test_GetManagerVersion(p
, torture
, &version
);
656 ret
&= test_ManagerInitialize(p
, torture
, host
);
657 ret
&= test_Enum(p
, torture
);
658 ret
&= test_EnumEx(p
, torture
, host
);
659 ret
&= test_StdRoot(p
, torture
, torture
, host
);
660 ret
&= test_FtRoot(p
, torture
, host
);
661 ret
&= test_DcAddress(p
, torture
, host
);