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/torture_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(struct torture_context *tctx,
45 const char *sharename
,
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(tctx
->ev
, tctx
->lp_ctx
))) {
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
, tctx
, &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(struct torture_context
*tctx
,
86 const char *sharename
)
89 struct libnet_context
* libnetctx
;
90 struct libnet_DelShare r
;
92 torture_comment(tctx
, "Deleting share %s\n", sharename
);
94 if (!(libnetctx
= libnet_context_init(tctx
->ev
, tctx
->lp_ctx
))) {
98 libnetctx
->cred
= cmdline_credentials
;
100 r
.in
.share_name
= sharename
;
101 r
.in
.server_name
= host
;
103 status
= libnet_DelShare(libnetctx
, tctx
, &r
);
104 if (!NT_STATUS_IS_OK(status
)) {
105 d_printf("Failed to delete share: %s (%s)\n",
106 nt_errstr(status
), r
.out
.error_string
);
113 static bool test_CreateDir(TALLOC_CTX
*mem_ctx
,
114 struct smbcli_state
**cli
,
115 struct torture_context
*tctx
,
120 printf("Creating directory %s\n", dir
);
122 if (!torture_open_connection_share(mem_ctx
, cli
, tctx
, host
, share
, tctx
->ev
)) {
126 if (!torture_setup_dir(*cli
, dir
)) {
133 static bool test_DeleteDir(struct torture_context
*tctx
,
134 struct smbcli_state
*cli
,
137 torture_comment(tctx
, "Deleting directory %s\n", dir
);
139 if (smbcli_deltree(cli
->tree
, dir
) == -1) {
140 printf("Unable to delete dir %s - %s\n", dir
,
141 smbcli_errstr(cli
->tree
));
148 static bool test_GetManagerVersion_opts(struct torture_context
*tctx
,
149 struct dcerpc_binding_handle
*b
,
150 enum dfs_ManagerVersion
*version_p
)
152 struct dfs_GetManagerVersion r
;
153 enum dfs_ManagerVersion version
;
155 r
.out
.version
= &version
;
157 torture_assert_ntstatus_ok(tctx
,
158 dcerpc_dfs_GetManagerVersion_r(b
, tctx
, &r
),
159 "GetManagerVersion failed");
162 *version_p
= version
;
169 static bool test_GetManagerVersion(struct torture_context
*tctx
,
170 struct dcerpc_pipe
*p
)
172 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
174 return test_GetManagerVersion_opts(tctx
, b
, NULL
);
177 static bool test_ManagerInitialize(struct torture_context
*tctx
,
178 struct dcerpc_pipe
*p
)
180 enum dfs_ManagerVersion version
;
181 struct dfs_ManagerInitialize r
;
182 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
183 const char *host
= torture_setting_string(tctx
, "host", NULL
);
185 torture_comment(tctx
, "Testing ManagerInitialize\n");
188 test_GetManagerVersion_opts(tctx
, b
, &version
),
189 "GetManagerVersion failed");
191 r
.in
.servername
= host
;
194 torture_assert_ntstatus_ok(tctx
,
195 dcerpc_dfs_ManagerInitialize_r(b
, tctx
, &r
),
196 "ManagerInitialize failed");
197 if (!W_ERROR_IS_OK(r
.out
.result
)) {
198 torture_warning(tctx
, "dfs_ManagerInitialize failed - %s\n",
199 win_errstr(r
.out
.result
));
200 IS_DFS_VERSION_UNSUPPORTED_CALL_W2K3(version
, r
.out
.result
);
207 static bool test_GetInfoLevel(struct torture_context
*tctx
,
208 struct dcerpc_binding_handle
*b
,
212 struct dfs_GetInfo r
;
215 torture_comment(tctx
, "Testing GetInfo level %u on '%s'\n", level
, root
);
217 r
.in
.dfs_entry_path
= root
;
218 r
.in
.servername
= NULL
;
219 r
.in
.sharename
= NULL
;
223 torture_assert_ntstatus_ok(tctx
,
224 dcerpc_dfs_GetInfo_r(b
, tctx
, &r
),
227 if (!W_ERROR_IS_OK(r
.out
.result
) &&
228 !W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, r
.out
.result
)) {
229 torture_warning(tctx
, "dfs_GetInfo failed - %s\n", win_errstr(r
.out
.result
));
236 static bool test_GetInfo(struct torture_context
*tctx
,
237 struct dcerpc_binding_handle
*b
,
241 /* 103, 104, 105, 106 is only available on Set */
242 uint16_t levels
[] = {1, 2, 3, 4, 5, 6, 7, 100, 101, 102, 103, 104, 105, 106};
245 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
246 if (!test_GetInfoLevel(tctx
, b
, levels
[i
], root
)) {
253 static bool test_EnumLevelEx(struct torture_context
*tctx
,
254 struct dcerpc_binding_handle
*b
,
256 const char *dfs_name
)
258 struct dfs_EnumEx rex
;
260 struct dfs_EnumStruct e
;
262 struct dfs_EnumArray1 e1
;
265 rex
.in
.level
= level
;
266 rex
.in
.bufsize
= (uint32_t)-1;
267 rex
.in
.total
= &total
;
269 rex
.in
.dfs_name
= dfs_name
;
271 e
.level
= rex
.in
.level
;
273 e
.e
.info1
->count
= 0;
277 torture_comment(tctx
, "Testing EnumEx level %u on '%s'\n", level
, dfs_name
);
279 torture_assert_ntstatus_ok(tctx
,
280 dcerpc_dfs_EnumEx_r(b
, tctx
, &rex
),
282 torture_assert_werr_ok(tctx
, rex
.out
.result
,
285 if (level
== 1 && rex
.out
.total
) {
287 for (i
=0;i
<*rex
.out
.total
;i
++) {
288 const char *root
= rex
.out
.info
->e
.info1
->s
[i
].path
;
289 if (!test_GetInfo(tctx
, b
, root
)) {
295 if (level
== 300 && rex
.out
.total
) {
297 for (i
=0;i
<*rex
.out
.total
;i
++) {
298 uint16_t levels
[] = {1, 2, 3, 4, 200}; /* 300 */
299 const char *root
= rex
.out
.info
->e
.info300
->s
[i
].dom_root
;
300 for (k
=0;k
<ARRAY_SIZE(levels
);k
++) {
301 if (!test_EnumLevelEx(tctx
, b
,
307 if (!test_GetInfo(tctx
, b
, root
)) {
317 static bool test_EnumLevel(struct torture_context
*tctx
,
318 struct dcerpc_binding_handle
*b
,
323 struct dfs_EnumStruct e
;
325 struct dfs_EnumArray1 e1
;
329 r
.in
.bufsize
= (uint32_t)-1;
333 e
.level
= r
.in
.level
;
335 e
.e
.info1
->count
= 0;
339 torture_comment(tctx
, "Testing Enum level %u\n", level
);
341 torture_assert_ntstatus_ok(tctx
,
342 dcerpc_dfs_Enum_r(b
, tctx
, &r
),
345 if (!W_ERROR_IS_OK(r
.out
.result
) &&
346 !W_ERROR_EQUAL(WERR_NO_MORE_ITEMS
, r
.out
.result
)) {
347 torture_warning(tctx
, "dfs_Enum failed - %s\n", win_errstr(r
.out
.result
));
351 if (level
== 1 && r
.out
.total
) {
353 for (i
=0;i
<*r
.out
.total
;i
++) {
354 const char *root
= r
.out
.info
->e
.info1
->s
[i
].path
;
355 if (!test_GetInfo(tctx
, b
, root
)) {
365 static bool test_Enum(struct torture_context
*tctx
,
366 struct dcerpc_pipe
*p
)
369 uint16_t levels
[] = {1, 2, 3, 4, 5, 6, 200, 300};
371 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
373 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
374 if (!test_EnumLevel(tctx
, b
, levels
[i
])) {
382 static bool test_EnumEx(struct torture_context
*tctx
,
383 struct dcerpc_pipe
*p
)
386 uint16_t levels
[] = {1, 2, 3, 4, 5, 6, 200, 300};
388 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
389 const char *host
= torture_setting_string(tctx
, "host", NULL
);
391 for (i
=0;i
<ARRAY_SIZE(levels
);i
++) {
392 if (!test_EnumLevelEx(tctx
, b
, levels
[i
], host
)) {
400 static bool test_RemoveStdRoot(struct torture_context
*tctx
,
401 struct dcerpc_binding_handle
*b
,
403 const char *sharename
)
405 struct dfs_RemoveStdRoot r
;
407 torture_comment(tctx
, "Testing RemoveStdRoot\n");
409 r
.in
.servername
= host
;
410 r
.in
.rootshare
= sharename
;
413 torture_assert_ntstatus_ok(tctx
,
414 dcerpc_dfs_RemoveStdRoot_r(b
, tctx
, &r
),
415 "RemoveStdRoot failed");
416 torture_assert_werr_ok(tctx
, r
.out
.result
,
417 "dfs_RemoveStdRoot failed");
422 static bool test_AddStdRoot(struct torture_context
*tctx
,
423 struct dcerpc_binding_handle
*b
,
425 const char *sharename
)
427 struct dfs_AddStdRoot r
;
429 torture_comment(tctx
, "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 torture_assert_ntstatus_ok(tctx
,
437 dcerpc_dfs_AddStdRoot_r(b
, tctx
, &r
),
438 "AddStdRoot failed");
439 torture_assert_werr_ok(tctx
, r
.out
.result
,
440 "AddStdRoot failed");
445 static bool test_AddStdRootForced(struct torture_context
*tctx
,
446 struct dcerpc_binding_handle
*b
,
448 const char *sharename
)
450 struct dfs_AddStdRootForced r
;
451 enum dfs_ManagerVersion version
;
453 torture_comment(tctx
, "Testing AddStdRootForced\n");
456 test_GetManagerVersion_opts(tctx
, b
, &version
),
457 "GetManagerVersion failed");
459 r
.in
.servername
= host
;
460 r
.in
.rootshare
= sharename
;
461 r
.in
.comment
= "standard dfs forced standalone DFS root created by smbtorture (dfs_AddStdRootForced)";
462 r
.in
.store
= SMBTORTURE_DFS_PATHNAME
;
464 torture_assert_ntstatus_ok(tctx
,
465 dcerpc_dfs_AddStdRootForced_r(b
, tctx
, &r
),
466 "AddStdRootForced failed");
467 if (!W_ERROR_IS_OK(r
.out
.result
)) {
468 torture_warning(tctx
, "dfs_AddStdRootForced failed - %s\n",
469 win_errstr(r
.out
.result
));
470 IS_DFS_VERSION_UNSUPPORTED_CALL_W2K3(version
, r
.out
.result
);
474 return test_RemoveStdRoot(tctx
, b
, host
, sharename
);
477 static void test_cleanup_stdroot(struct torture_context
*tctx
,
478 struct dcerpc_binding_handle
*b
,
480 const char *sharename
,
483 struct smbcli_state
*cli
;
485 torture_comment(tctx
, "Cleaning up StdRoot\n");
487 test_RemoveStdRoot(tctx
, b
, host
, sharename
);
488 test_NetShareDel(tctx
, host
, sharename
);
489 if (torture_open_connection_share(tctx
, &cli
, tctx
, host
, "C$", tctx
->ev
)) {
490 test_DeleteDir(tctx
, cli
, dir
);
491 torture_close_connection(cli
);
495 static bool test_StdRoot(struct torture_context
*tctx
,
496 struct dcerpc_pipe
*p
)
498 const char *sharename
= SMBTORTURE_DFS_SHARENAME
;
499 const char *dir
= SMBTORTURE_DFS_DIRNAME
;
500 const char *path
= SMBTORTURE_DFS_PATHNAME
;
501 struct smbcli_state
*cli
;
503 const char *host
= torture_setting_string(tctx
, "host", NULL
);
504 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
506 torture_comment(tctx
, "Testing StdRoot\n");
508 test_cleanup_stdroot(tctx
, b
, host
, sharename
, dir
);
511 test_CreateDir(tctx
, &cli
, tctx
, host
, "C$", dir
),
512 "failed to connect C$ share and to create directory");
514 test_NetShareAdd(tctx
, host
, sharename
, path
),
515 "failed to create new share");
517 ret
&= test_AddStdRoot(tctx
, b
, host
, sharename
);
518 ret
&= test_RemoveStdRoot(tctx
, b
, host
, sharename
);
519 ret
&= test_AddStdRootForced(tctx
, b
, host
, sharename
);
520 ret
&= test_NetShareDel(tctx
, host
, sharename
);
521 ret
&= test_DeleteDir(tctx
, cli
, dir
);
523 torture_close_connection(cli
);
528 static bool test_GetDcAddress(struct torture_context
*tctx
,
529 struct dcerpc_binding_handle
*b
,
532 struct dfs_GetDcAddress r
;
537 torture_comment(tctx
, "Testing GetDcAddress\n");
541 r
.in
.servername
= host
;
542 r
.in
.server_fullname
= r
.out
.server_fullname
= &ptr
;
543 r
.in
.is_root
= r
.out
.is_root
= &is_root
;
544 r
.in
.ttl
= r
.out
.ttl
= &ttl
;
546 torture_assert_ntstatus_ok(tctx
,
547 dcerpc_dfs_GetDcAddress_r(b
, tctx
, &r
),
548 "GetDcAddress failed");
549 torture_assert_werr_ok(tctx
, r
.out
.result
,
550 "dfs_GetDcAddress failed");
555 static bool test_SetDcAddress(struct torture_context
*tctx
,
556 struct dcerpc_binding_handle
*b
,
559 struct dfs_SetDcAddress r
;
561 torture_comment(tctx
, "Testing SetDcAddress\n");
563 r
.in
.servername
= host
;
564 r
.in
.server_fullname
= host
;
568 torture_assert_ntstatus_ok(tctx
,
569 dcerpc_dfs_SetDcAddress_r(b
, tctx
, &r
),
570 "SetDcAddress failed");
571 torture_assert_werr_ok(tctx
, r
.out
.result
,
572 "dfs_SetDcAddress failed");
577 static bool test_DcAddress(struct torture_context
*tctx
,
578 struct dcerpc_pipe
*p
)
580 const char *host
= torture_setting_string(tctx
, "host", NULL
);
581 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
583 if (!test_GetDcAddress(tctx
, b
, host
)) {
587 if (!test_SetDcAddress(tctx
, b
, host
)) {
594 static bool test_FlushFtTable(struct torture_context
*tctx
,
595 struct dcerpc_binding_handle
*b
,
597 const char *sharename
)
599 struct dfs_FlushFtTable r
;
600 enum dfs_ManagerVersion version
;
602 torture_comment(tctx
, "Testing FlushFtTable\n");
605 test_GetManagerVersion_opts(tctx
, b
, &version
),
606 "GetManagerVersion failed");
608 r
.in
.servername
= host
;
609 r
.in
.rootshare
= sharename
;
611 torture_assert_ntstatus_ok(tctx
,
612 dcerpc_dfs_FlushFtTable_r(b
, tctx
, &r
),
613 "FlushFtTable failed");
614 if (!W_ERROR_IS_OK(r
.out
.result
)) {
615 torture_warning(tctx
, "dfs_FlushFtTable failed - %s\n",
616 win_errstr(r
.out
.result
));
617 IS_DFS_VERSION_UNSUPPORTED_CALL_W2K3(version
, r
.out
.result
);
624 static bool test_FtRoot(struct torture_context
*tctx
,
625 struct dcerpc_pipe
*p
)
627 const char *sharename
= SMBTORTURE_DFS_SHARENAME
;
628 const char *host
= torture_setting_string(tctx
, "host", NULL
);
629 struct dcerpc_binding_handle
*b
= p
->binding_handle
;
631 return test_FlushFtTable(tctx
, b
, host
, sharename
);
634 struct torture_suite
*torture_rpc_dfs(TALLOC_CTX
*mem_ctx
)
636 struct torture_rpc_tcase
*tcase
;
637 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "dfs");
639 tcase
= torture_suite_add_rpc_iface_tcase(suite
, "netdfs",
642 torture_rpc_tcase_add_test(tcase
, "GetManagerVersion", test_GetManagerVersion
);
643 torture_rpc_tcase_add_test(tcase
, "ManagerInitialize", test_ManagerInitialize
);
644 torture_rpc_tcase_add_test(tcase
, "Enum", test_Enum
);
645 torture_rpc_tcase_add_test(tcase
, "EnumEx", test_EnumEx
);
646 torture_rpc_tcase_add_test(tcase
, "StdRoot", test_StdRoot
);
647 torture_rpc_tcase_add_test(tcase
, "FtRoot", test_FtRoot
);
648 torture_rpc_tcase_add_test(tcase
, "DcAddress", test_DcAddress
);