s4: allow python code to dump NTACL object as well
[Samba/ekacnet.git] / source4 / torture / rpc / dfs.c
blobfca1c54fdb3916ef2c1c05508866c7085053a639
1 /*
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.
22 #include "includes.h"
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");\
38 return false;\
40 return true;\
43 static bool test_NetShareAdd(TALLOC_CTX *mem_ctx,
44 struct torture_context *tctx,
45 const char *host,
46 const char *sharename,
47 const char *dir)
49 NTSTATUS status;
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))) {
57 return false;
60 libnetctx->cred = cmdline_credentials;
62 i.name = sharename;
63 i.type = STYPE_DISKTREE;
64 i.path = dir;
65 i.max_users = (uint32_t) -1;
66 i.comment = "created by smbtorture";
67 i.password = NULL;
68 i.permissions = 0x0;
69 i.current_users = 0x0;
71 r.level = 2;
72 r.in.server_name = host;
73 r.in.share = i;
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);
79 return false;
82 return true;
85 static bool test_NetShareDel(TALLOC_CTX *mem_ctx,
86 struct torture_context *tctx,
87 const char *host,
88 const char *sharename)
90 NTSTATUS status;
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))) {
97 return false;
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);
109 return false;
112 return true;
115 static bool test_CreateDir(TALLOC_CTX *mem_ctx,
116 struct smbcli_state **cli,
117 struct torture_context *tctx,
118 const char *host,
119 const char *share,
120 const char *dir)
122 printf("Creating directory %s\n", dir);
124 if (!torture_open_connection_share(mem_ctx, cli, tctx, host, share, tctx->ev)) {
125 return false;
128 if (!torture_setup_dir(*cli, dir)) {
129 return false;
132 return true;
135 static bool test_DeleteDir(struct smbcli_state *cli,
136 const char *dir)
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));
143 return false;
146 return true;
149 static bool test_GetManagerVersion(struct dcerpc_pipe *p,
150 TALLOC_CTX *mem_ctx,
151 enum dfs_ManagerVersion *version)
153 NTSTATUS status;
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));
161 return false;
164 return true;
167 static bool test_ManagerInitialize(struct dcerpc_pipe *p,
168 TALLOC_CTX *mem_ctx,
169 const char *host)
171 NTSTATUS status;
172 enum dfs_ManagerVersion version;
173 struct dfs_ManagerInitialize r;
175 printf("Testing ManagerInitialize\n");
177 if (!test_GetManagerVersion(p, mem_ctx, &version)) {
178 return false;
181 r.in.servername = host;
182 r.in.flags = 0;
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));
187 return false;
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);
192 return false;
195 return true;
198 static bool test_GetInfoLevel(struct dcerpc_pipe *p,
199 TALLOC_CTX *mem_ctx,
200 uint16_t level,
201 const char *root)
203 NTSTATUS status;
204 struct dfs_GetInfo r;
205 union dfs_Info info;
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;
212 r.in.level = level;
213 r.out.info = &info;
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));
218 return false;
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));
222 return false;
225 return true;
228 static bool test_GetInfo(struct dcerpc_pipe *p,
229 TALLOC_CTX *mem_ctx,
230 const char *root)
232 bool ret = true;
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};
235 int i;
237 for (i=0;i<ARRAY_SIZE(levels);i++) {
238 if (!test_GetInfoLevel(p, mem_ctx, levels[i], root)) {
239 ret = false;
242 return ret;
245 static bool test_EnumLevelEx(struct dcerpc_pipe *p,
246 TALLOC_CTX *mem_ctx,
247 uint16_t level,
248 const char *dfs_name)
250 NTSTATUS status;
251 struct dfs_EnumEx rex;
252 uint32_t total=0;
253 struct dfs_EnumStruct e;
254 struct dfs_Info1 s;
255 struct dfs_EnumArray1 e1;
256 bool ret = true;
258 rex.in.level = level;
259 rex.in.bufsize = (uint32_t)-1;
260 rex.in.total = &total;
261 rex.in.info = &e;
262 rex.in.dfs_name = dfs_name;
264 e.level = rex.in.level;
265 e.e.info1 = &e1;
266 e.e.info1->count = 0;
267 e.e.info1->s = &s;
268 s.path = NULL;
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));
275 return false;
278 if (level == 1 && rex.out.total) {
279 int i;
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)) {
284 ret = false;
289 if (level == 300 && rex.out.total) {
290 int i,k;
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,
297 levels[k], root))
299 ret = false;
302 if (!test_GetInfo(p, mem_ctx, root)) {
303 ret = false;
308 return ret;
312 static bool test_EnumLevel(struct dcerpc_pipe *p,
313 TALLOC_CTX *mem_ctx,
314 uint16_t level)
316 NTSTATUS status;
317 struct dfs_Enum r;
318 uint32_t total=0;
319 struct dfs_EnumStruct e;
320 struct dfs_Info1 s;
321 struct dfs_EnumArray1 e1;
322 bool ret = true;
324 r.in.level = level;
325 r.in.bufsize = (uint32_t)-1;
326 r.in.total = &total;
327 r.in.info = &e;
329 e.level = r.in.level;
330 e.e.info1 = &e1;
331 e.e.info1->count = 0;
332 e.e.info1->s = &s;
333 s.path = NULL;
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));
340 return false;
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));
344 return false;
347 if (level == 1 && r.out.total) {
348 int i;
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)) {
352 ret = false;
358 return ret;
362 static bool test_Enum(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
364 bool ret = true;
365 uint16_t levels[] = {1, 2, 3, 4, 5, 6, 200, 300};
366 int i;
368 for (i=0;i<ARRAY_SIZE(levels);i++) {
369 if (!test_EnumLevel(p, mem_ctx, levels[i])) {
370 ret = false;
374 return ret;
377 static bool test_EnumEx(struct dcerpc_pipe *p,
378 TALLOC_CTX *mem_ctx,
379 const char *host)
381 bool ret = true;
382 uint16_t levels[] = {1, 2, 3, 4, 5, 6, 200, 300};
383 int i;
385 for (i=0;i<ARRAY_SIZE(levels);i++) {
386 if (!test_EnumLevelEx(p, mem_ctx, levels[i], host)) {
387 ret = false;
391 return ret;
394 static bool test_RemoveStdRoot(struct dcerpc_pipe *p,
395 TALLOC_CTX *mem_ctx,
396 const char *host,
397 const char *sharename)
399 struct dfs_RemoveStdRoot r;
400 NTSTATUS status;
402 printf("Testing RemoveStdRoot\n");
404 r.in.servername = host;
405 r.in.rootshare = sharename;
406 r.in.flags = 0;
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));
411 return false;
412 } else if (!W_ERROR_IS_OK(r.out.result)) {
413 printf("dfs_RemoveStdRoot failed - %s\n",
414 win_errstr(r.out.result));
415 return false;
418 return true;
421 static bool test_AddStdRoot(struct dcerpc_pipe *p,
422 TALLOC_CTX *mem_ctx,
423 const char *host,
424 const char *sharename)
426 NTSTATUS status;
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)";
434 r.in.flags = 0;
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));
439 return false;
440 } else if (!W_ERROR_IS_OK(r.out.result)) {
441 printf("dfs_AddStdRoot failed - %s\n",
442 win_errstr(r.out.result));
443 return false;
446 return true;
449 static bool test_AddStdRootForced(struct dcerpc_pipe *p,
450 TALLOC_CTX *mem_ctx,
451 const char *host,
452 const char *sharename)
454 NTSTATUS status;
455 struct dfs_AddStdRootForced r;
456 enum dfs_ManagerVersion version;
458 printf("Testing AddStdRootForced\n");
460 if (!test_GetManagerVersion(p, mem_ctx, &version)) {
461 return false;
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));
472 return false;
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);
477 return false;
480 return test_RemoveStdRoot(p, mem_ctx, host, sharename);
483 static void test_cleanup_stdroot(struct dcerpc_pipe *p,
484 TALLOC_CTX *mem_ctx,
485 struct torture_context *tctx,
486 const char *host,
487 const char *sharename,
488 const char *dir)
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,
502 TALLOC_CTX *mem_ctx,
503 struct torture_context *tctx,
504 const char *host)
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;
510 bool ret = true;
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);
526 return ret;
529 static bool test_GetDcAddress(struct dcerpc_pipe *p,
530 TALLOC_CTX *mem_ctx,
531 const char *host)
533 NTSTATUS status;
534 struct dfs_GetDcAddress r;
535 uint8_t is_root = 0;
536 uint32_t ttl = 0;
537 const char *ptr;
539 printf("Testing GetDcAddress\n");
541 ptr = host;
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));
551 return false;
552 } else if (!W_ERROR_IS_OK(r.out.result)) {
553 printf("dfs_GetDcAddress failed - %s\n",
554 win_errstr(r.out.result));
555 return false;
558 return true;
561 static bool test_SetDcAddress(struct dcerpc_pipe *p,
562 TALLOC_CTX *mem_ctx,
563 const char *host)
565 NTSTATUS status;
566 struct dfs_SetDcAddress r;
568 printf("Testing SetDcAddress\n");
570 r.in.servername = host;
571 r.in.server_fullname = host;
572 r.in.flags = 0;
573 r.in.ttl = 1000;
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));
578 return false;
579 } else if (!W_ERROR_IS_OK(r.out.result)) {
580 printf("dfs_SetDcAddress failed - %s\n",
581 win_errstr(r.out.result));
582 return false;
585 return true;
588 static bool test_DcAddress(struct dcerpc_pipe *p,
589 TALLOC_CTX *mem_ctx,
590 const char *host)
592 if (!test_GetDcAddress(p, mem_ctx, host)) {
593 return false;
596 if (!test_SetDcAddress(p, mem_ctx, host)) {
597 return false;
600 return true;
603 static bool test_FlushFtTable(struct dcerpc_pipe *p,
604 TALLOC_CTX *mem_ctx,
605 const char *host,
606 const char *sharename)
608 NTSTATUS status;
609 struct dfs_FlushFtTable r;
610 enum dfs_ManagerVersion version;
612 printf("Testing FlushFtTable\n");
614 if (!test_GetManagerVersion(p, mem_ctx, &version)) {
615 return false;
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));
624 return false;
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);
629 return false;
632 return true;
635 static bool test_FtRoot(struct dcerpc_pipe *p,
636 TALLOC_CTX *mem_ctx,
637 const char *host)
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)
646 NTSTATUS status;
647 struct dcerpc_pipe *p;
648 bool ret = true;
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);
663 return ret;