static void test_cleanup_stdroot(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct torture_context *tctx, const char *host, const char *sharename, const char *dir) { struct smbcli_state *cli; printf("Cleaning up StdRoot\n"); test_RemoveStdRoot(p, mem_ctx, host, sharename); test_NetShareDel(mem_ctx, tctx, host, sharename); torture_open_connection_share(mem_ctx, &cli, tctx, host, "C$", tctx->ev); test_DeleteDir(cli, dir); torture_close_connection(cli); }
static bool test_CreateDir(TALLOC_CTX *mem_ctx, struct smbcli_state **cli, struct torture_context *tctx, const char *host, const char *share, const char *dir) { printf("Creating directory %s\n", dir); if (!torture_open_connection_share(mem_ctx, cli, tctx, host, share, tctx->ev)) { return false; } if (!torture_setup_dir(*cli, dir)) { return false; } return true; }
bool torture_samba3_hide(struct torture_context *torture) { struct smbcli_state *cli; const char *fname = "test.txt"; int fnum; NTSTATUS status; struct smbcli_tree *hideunread; struct smbcli_tree *hideunwrite; if (!torture_open_connection_share( torture, &cli, torture, torture_setting_string(torture, "host", NULL), torture_setting_string(torture, "share", NULL), torture->ev)) { torture_fail(torture, "torture_open_connection_share failed\n"); } status = torture_second_tcon(torture, cli->session, "hideunread", &hideunread); torture_assert_ntstatus_ok(torture, status, "second_tcon(hideunread) failed\n"); status = torture_second_tcon(torture, cli->session, "hideunwrite", &hideunwrite); torture_assert_ntstatus_ok(torture, status, "second_tcon(hideunwrite) failed\n"); status = smbcli_unlink(cli->tree, fname); if (NT_STATUS_EQUAL(status, NT_STATUS_CANNOT_DELETE)) { smbcli_setatr(cli->tree, fname, 0, -1); smbcli_unlink(cli->tree, fname); } fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); if (fnum == -1) { torture_fail(torture, talloc_asprintf(torture, "Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree))); } smbcli_close(cli->tree, fnum); if (!smbcli_file_exists(cli->tree, fname)) { torture_fail(torture, talloc_asprintf(torture, "%s does not exist\n", fname)); } /* R/W file should be visible everywhere */ status = smbcli_chmod(cli->tree, fname, UNIX_R_USR|UNIX_W_USR); torture_assert_ntstatus_ok(torture, status, "smbcli_chmod failed\n"); if (!is_writeable(torture, cli->tree, fname)) { torture_fail(torture, "File not writable\n"); } if (!is_readable(cli->tree, fname)) { torture_fail(torture, "File not readable\n"); } if (!is_visible(cli->tree, fname)) { torture_fail(torture, "r/w file not visible via normal share\n"); } if (!is_visible(hideunread, fname)) { torture_fail(torture, "r/w file not visible via hide unreadable\n"); } if (!is_visible(hideunwrite, fname)) { torture_fail(torture, "r/w file not visible via hide unwriteable\n"); } /* R/O file should not be visible via hide unwriteable files */ status = smbcli_chmod(cli->tree, fname, UNIX_R_USR); torture_assert_ntstatus_ok(torture, status, "smbcli_chmod failed\n"); if (is_writeable(torture, cli->tree, fname)) { torture_fail(torture, "r/o is writable\n"); } if (!is_readable(cli->tree, fname)) { torture_fail(torture, "r/o not readable\n"); } if (!is_visible(cli->tree, fname)) { torture_fail(torture, "r/o file not visible via normal share\n"); } if (!is_visible(hideunread, fname)) { torture_fail(torture, "r/o file not visible via hide unreadable\n"); } if (is_visible(hideunwrite, fname)) { torture_fail(torture, "r/o file visible via hide unwriteable\n"); } /* inaccessible file should be only visible on normal share */ status = smbcli_chmod(cli->tree, fname, 0); torture_assert_ntstatus_ok(torture, status, "smbcli_chmod failed\n"); if (is_writeable(torture, cli->tree, fname)) { torture_fail(torture, "inaccessible file is writable\n"); } if (is_readable(cli->tree, fname)) { torture_fail(torture, "inaccessible file is readable\n"); } if (!is_visible(cli->tree, fname)) { torture_fail(torture, "inaccessible file not visible via normal share\n"); } if (is_visible(hideunread, fname)) { torture_fail(torture, "inaccessible file visible via hide unreadable\n"); } if (is_visible(hideunwrite, fname)) { torture_fail(torture, "inaccessible file visible via hide unwriteable\n"); } smbcli_chmod(cli->tree, fname, UNIX_R_USR|UNIX_W_USR); smbcli_unlink(cli->tree, fname); return true; }
bool torture_samba3_checkfsp(struct torture_context *torture) { struct smbcli_state *cli; const char *fname = "test.txt"; const char *dirname = "testdir"; int fnum; NTSTATUS status; bool ret = true; TALLOC_CTX *mem_ctx; ssize_t nread; char buf[16]; struct smbcli_tree *tree2; if ((mem_ctx = talloc_init("torture_samba3_checkfsp")) == NULL) { d_printf("talloc_init failed\n"); return false; } if (!torture_open_connection_share( torture, &cli, torture, torture_setting_string(torture, "host", NULL), torture_setting_string(torture, "share", NULL), torture->ev)) { d_printf("torture_open_connection_share failed\n"); ret = false; goto done; } smbcli_deltree(cli->tree, dirname); status = torture_second_tcon(torture, cli->session, torture_setting_string(torture, "share", NULL), &tree2); CHECK_STATUS(status, NT_STATUS_OK); if (!NT_STATUS_IS_OK(status)) goto done; /* Try a read on an invalid FID */ nread = smbcli_read(cli->tree, 4711, buf, 0, sizeof(buf)); CHECK_STATUS(smbcli_nt_error(cli->tree), NT_STATUS_INVALID_HANDLE); /* Try a read on a directory handle */ status = smbcli_mkdir(cli->tree, dirname); if (!NT_STATUS_IS_OK(status)) { d_printf("smbcli_mkdir failed: %s\n", nt_errstr(status)); ret = false; goto done; } /* Open the directory */ { union smb_open io; io.generic.level = RAW_OPEN_NTCREATEX; io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED; io.ntcreatex.in.root_fid.fnum = 0; io.ntcreatex.in.security_flags = 0; io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE; io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL; io.ntcreatex.in.alloc_size = 0; io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY; io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE; io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN; io.ntcreatex.in.create_options = 0; io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS; io.ntcreatex.in.fname = dirname; status = smb_raw_open(cli->tree, mem_ctx, &io); if (!NT_STATUS_IS_OK(status)) { d_printf("smb_open on the directory failed: %s\n", nt_errstr(status)); ret = false; goto done; } fnum = io.ntcreatex.out.file.fnum; } /* Try a read on the directory */ nread = smbcli_read(cli->tree, fnum, buf, 0, sizeof(buf)); if (nread >= 0) { d_printf("smbcli_read on a directory succeeded, expected " "failure\n"); ret = false; } CHECK_STATUS(smbcli_nt_error(cli->tree), NT_STATUS_INVALID_DEVICE_REQUEST); /* Same test on the second tcon */ nread = smbcli_read(tree2, fnum, buf, 0, sizeof(buf)); if (nread >= 0) { d_printf("smbcli_read on a directory succeeded, expected " "failure\n"); ret = false; } CHECK_STATUS(smbcli_nt_error(tree2), NT_STATUS_INVALID_HANDLE); smbcli_close(cli->tree, fnum); /* Try a normal file read on a second tcon */ fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE); if (fnum == -1) { d_printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree)); ret = false; goto done; } nread = smbcli_read(tree2, fnum, buf, 0, sizeof(buf)); CHECK_STATUS(smbcli_nt_error(tree2), NT_STATUS_INVALID_HANDLE); smbcli_close(cli->tree, fnum); done: smbcli_deltree(cli->tree, dirname); torture_close_connection(cli); talloc_free(mem_ctx); return ret; }