#include "torture/torture.h"
#include "torture/basic/proto.h"
#include "libcli/libcli.h"
+#include "torture/util.h"
#include "system/filesys.h"
#include "system/time.h"
#include "libcli/resolve/resolve.h"
test whether fnums and tids open on one VC are available on another (a major
security hole)
*/
-static BOOL run_fdpasstest(void)
+static BOOL run_fdpasstest(struct torture_context *torture)
{
struct smbcli_state *cli1, *cli2;
const char *fname = "\\fdpass.tst";
/**
This checks how the getatr calls works
*/
-static BOOL run_attrtest(void)
+static BOOL run_attrtest(struct torture_context *torture)
{
struct smbcli_state *cli;
int fnum;
/**
This checks a couple of trans2 calls
*/
-static BOOL run_trans2test(void)
+static BOOL run_trans2test(struct torture_context *torture)
{
struct smbcli_state *cli;
int fnum;
}
/* send smb negprot commands, not reading the response */
-static BOOL run_negprot_nowait(void)
+static BOOL run_negprot_nowait(struct torture_context *torture)
{
int i;
struct smbcli_state *cli, *cli2;
this checks to see if a secondary tconx can use open files from an
earlier tconx
*/
-static BOOL run_tcon_test(void)
+static BOOL run_tcon_test(struct torture_context *torture)
{
struct smbcli_state *cli;
const char *fname = "\\tcontest.tmp";
/**
checks for correct tconX support
*/
-static BOOL run_tcon_devtype_test(void)
+static BOOL run_tcon_devtype_test(struct torture_context *torture)
{
struct smbcli_state *cli1 = NULL;
NTSTATUS status;
#define BOOLSTR(b) ((b) ? "Yes" : "No")
-static BOOL run_readwritetest(void)
+static BOOL run_readwritetest(struct torture_context *torture)
{
struct smbcli_state *cli1, *cli2;
BOOL test1, test2 = True;
Try with a wrong vuid and check error message.
*/
-static BOOL run_vuidtest(void)
+static BOOL run_vuidtest(struct torture_context *torture)
{
struct smbcli_state *cli;
const char *fname = "\\vuid.tst";
/*
Test open mode returns on read-only files.
*/
- static BOOL run_opentest(void)
+ static BOOL run_opentest(struct torture_context *torture)
{
static struct smbcli_state *cli1;
static struct smbcli_state *cli2;
/**
Test ntcreate calls made by xcopy
*/
-static BOOL run_xcopy(void)
+static BOOL run_xcopy(struct torture_context *torture)
{
struct smbcli_state *cli1;
const char *fname = "\\test.txt";
return correct;
}
+static BOOL run_iometer(struct torture_context *torture)
+{
+ struct smbcli_state *cli;
+ const char *fname = "\\iobw.tst";
+ int fnum;
+ size_t filesize;
+ NTSTATUS status;
+ char buf[2048];
+ int ops;
+ BOOL result = False;
+
+ printf("Starting iometer test\n");
+
+ memset(buf, 0, sizeof(buf));
+
+ if (!torture_open_connection(&cli)) {
+ return False;
+ }
+
+ status = smbcli_getatr(cli->tree, fname, NULL, &filesize, NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("smbcli_getatr failed: %s\n", nt_errstr(status));
+ goto done;
+ }
+
+ printf("size: %d\n", filesize);
+
+ filesize -= (sizeof(buf) - 1);
+
+ fnum = smbcli_nt_create_full(cli->tree, fname, 0x16,
+ 0x2019f, 0, 0x3, 3, 0x42, 0x3);
+ if (fnum == -1) {
+ printf("open failed: %s\n", smbcli_errstr(cli->tree));
+ goto done;
+ }
+
+ ops = 0;
+
+ while (True) {
+ int i, num_reads, num_writes;
+
+ num_reads = random() % 10;
+ num_writes = random() % 3;
+
+ for (i=0; i<num_reads; i++) {
+ ssize_t res;
+ if (ops++ > torture_numops) {
+ result = True;
+ goto done;
+ }
+ res = smbcli_read(cli->tree, fnum, buf,
+ random() % filesize, sizeof(buf));
+ if (res != sizeof(buf)) {
+ printf("read failed: %s\n",
+ smbcli_errstr(cli->tree));
+ goto done;
+ }
+ }
+ for (i=0; i<num_writes; i++) {
+ ssize_t res;
+ if (ops++ > torture_numops) {
+ result = True;
+ goto done;
+ }
+ res = smbcli_write(cli->tree, fnum, 0, buf,
+ random() % filesize, sizeof(buf));
+ if (res != sizeof(buf)) {
+ printf("read failed: %s\n",
+ smbcli_errstr(cli->tree));
+ goto done;
+ }
+ }
+ }
+
+ result = True;
+ done:
+
+ if (!torture_close_connection(cli)) {
+ printf("close_connection failed: %s\n",
+ smbcli_errstr(cli->tree));
+ return False;
+ }
+
+ return result;
+}
+
/**
tries variants of chkpath
*/
-static BOOL torture_chkpath_test(void)
+static BOOL torture_chkpath_test(struct torture_context *torture)
{
struct smbcli_state *cli;
int fnum;
return ret;
}
+/*
+ * This is a test to excercise some weird Samba3 error paths.
+ */
+static BOOL torture_samba3_errorpaths(struct torture_context *torture)
+{
+ BOOL nt_status_support;
+ struct smbcli_state *cli_nt = NULL, *cli_dos = NULL;
+ BOOL result = False;
+ int fnum;
+ const char *os2_fname = ".+,;=[].";
+ const char *dirname = "samba3_errordir";
+ union smb_open io;
+ TALLOC_CTX *mem_ctx = talloc_init(NULL);
+ NTSTATUS status;
+
+ if (mem_ctx == NULL) {
+ printf("talloc_init failed\n");
+ return False;
+ }
+
+ nt_status_support = lp_nt_status_support();
+
+ if (!lp_set_cmdline("nt status support", "yes")) {
+ printf("Could not set 'nt status support = yes'\n");
+ goto fail;
+ }
+
+ if (!torture_open_connection(&cli_nt)) {
+ goto fail;
+ }
+
+ if (!lp_set_cmdline("nt status support", "no")) {
+ printf("Could not set 'nt status support = yes'\n");
+ goto fail;
+ }
+
+ if (!torture_open_connection(&cli_dos)) {
+ goto fail;
+ }
+
+ if (!lp_set_cmdline("nt status support",
+ nt_status_support ? "yes":"no")) {
+ printf("Could not reset 'nt status support = yes'");
+ goto fail;
+ }
+
+ smbcli_unlink(cli_nt->tree, os2_fname);
+ smbcli_rmdir(cli_nt->tree, dirname);
+
+ if (!NT_STATUS_IS_OK(smbcli_mkdir(cli_nt->tree, dirname))) {
+ printf("smbcli_mkdir(%s) failed: %s\n", dirname,
+ smbcli_errstr(cli_nt->tree));
+ goto fail;
+ }
+
+ io.generic.level = RAW_OPEN_NTCREATEX;
+ io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
+ io.ntcreatex.in.root_fid = 0;
+ io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
+ io.ntcreatex.in.alloc_size = 1024*1024;
+ io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
+ io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
+ io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
+ io.ntcreatex.in.create_options = 0;
+ io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
+ io.ntcreatex.in.security_flags = 0;
+ io.ntcreatex.in.fname = dirname;
+
+ status = smb_raw_open(cli_nt->tree, mem_ctx, &io);
+ if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
+ printf("(%s) incorrect status %s should be %s\n",
+ __location__, nt_errstr(status),
+ nt_errstr(NT_STATUS_OBJECT_NAME_COLLISION));
+ goto fail;
+ }
+ status = smb_raw_open(cli_dos->tree, mem_ctx, &io);
+ if (!NT_STATUS_EQUAL(status, NT_STATUS_DOS(ERRDOS, ERRfilexists))) {
+ printf("(%s) incorrect status %s should be %s\n",
+ __location__, nt_errstr(status),
+ nt_errstr(NT_STATUS_DOS(ERRDOS, ERRfilexists)));
+ goto fail;
+ }
+
+ status = smbcli_mkdir(cli_nt->tree, dirname);
+ if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
+ printf("(%s) incorrect status %s should be %s\n",
+ __location__, nt_errstr(status),
+ nt_errstr(NT_STATUS_OBJECT_NAME_COLLISION));
+ goto fail;
+ }
+ status = smbcli_mkdir(cli_dos->tree, dirname);
+ if (!NT_STATUS_EQUAL(status, NT_STATUS_DOS(ERRDOS, ERRnoaccess))) {
+ printf("(%s) incorrect status %s should be %s\n",
+ __location__, nt_errstr(status),
+ nt_errstr(NT_STATUS_DOS(ERRDOS, ERRnoaccess)));
+ goto fail;
+ }
+
+ {
+ /* Test an invalid DOS deny mode */
+ const char *fname = "test.txt";
+
+ fnum = smbcli_open(cli_nt->tree, fname, O_RDWR | O_CREAT, 5);
+ if (fnum != -1) {
+ printf("Open(%s) with invalid deny mode succeeded -- "
+ "expected failure\n", fname);
+ smbcli_close(cli_nt->tree, fnum);
+ goto fail;
+ }
+ if (!NT_STATUS_EQUAL(smbcli_nt_error(cli_nt->tree),
+ NT_STATUS_DOS(ERRDOS,ERRbadaccess))) {
+ printf("Expected DOS error ERRDOS/ERRbadaccess, "
+ "got %s\n", smbcli_errstr(cli_nt->tree));
+ goto fail;
+ }
+
+ fnum = smbcli_open(cli_dos->tree, fname, O_RDWR | O_CREAT, 5);
+ if (fnum != -1) {
+ printf("Open(%s) with invalid deny mode succeeded -- "
+ "expected failure\n", fname);
+ smbcli_close(cli_nt->tree, fnum);
+ goto fail;
+ }
+ if (!NT_STATUS_EQUAL(smbcli_nt_error(cli_nt->tree),
+ NT_STATUS_DOS(ERRDOS,ERRbadaccess))) {
+ printf("Expected DOS error ERRDOS:ERRbadaccess, "
+ "got %s\n", smbcli_errstr(cli_nt->tree));
+ goto fail;
+ }
+ }
+
+ if (!lp_parm_bool(-1, "target", "samba3", False)) {
+ goto done;
+ }
+
+ fnum = smbcli_open(cli_dos->tree, os2_fname,
+ O_RDWR | O_CREAT | O_TRUNC,
+ DENY_NONE);
+ if (fnum != -1) {
+ printf("Open(%s) succeeded -- expected failure\n",
+ os2_fname);
+ smbcli_close(cli_dos->tree, fnum);
+ goto fail;
+ }
+
+ if (!NT_STATUS_EQUAL(smbcli_nt_error(cli_dos->tree),
+ NT_STATUS_DOS(ERRDOS, ERRcannotopen))) {
+ printf("Expected DOS error ERRDOS/ERRcannotopen, got %s\n",
+ smbcli_errstr(cli_dos->tree));
+ goto fail;
+ }
+
+ fnum = smbcli_open(cli_nt->tree, os2_fname,
+ O_RDWR | O_CREAT | O_TRUNC,
+ DENY_NONE);
+ if (fnum != -1) {
+ printf("Open(%s) succeeded -- expected failure\n",
+ os2_fname);
+ smbcli_close(cli_nt->tree, fnum);
+ goto fail;
+ }
+
+ if (!NT_STATUS_EQUAL(smbcli_nt_error(cli_nt->tree),
+ NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
+ printf("Expected error NT_STATUS_OBJECT_NAME_NOT_FOUND, "
+ "got %s\n", smbcli_errstr(cli_nt->tree));
+ goto fail;
+ }
+
+ done:
+ result = True;
+
+ fail:
+ if (cli_dos != NULL) {
+ torture_close_connection(cli_dos);
+ }
+ if (cli_nt != NULL) {
+ torture_close_connection(cli_nt);
+ }
+
+ return result;
+}
NTSTATUS torture_base_init(void)
register_torture_op("BASE-OPEN", run_opentest, 0);
register_torture_op("BASE-DEFER_OPEN", NULL, run_deferopen);
register_torture_op("BASE-XCOPY", run_xcopy, 0);
+ register_torture_op("BASE-IOMETER", run_iometer, 0);
register_torture_op("BASE-RENAME", torture_test_rename, 0);
register_torture_op("BASE-DELETE", torture_test_delete, 0);
register_torture_op("BASE-PROPERTIES", torture_test_properties, 0);
register_torture_op("BASE-SECLEAK", torture_sec_leak, 0);
register_torture_op("BASE-DISCONNECT", torture_disconnect, 0);
register_torture_op("BASE-DELAYWRITE", torture_delay_write, 0);
+ register_torture_op("BASE-SAMBA3ERROR", torture_samba3_errorpaths, 0);
register_torture_op("SCAN-CASETABLE", torture_casetable, 0);
register_torture_op("SCAN-UTABLE", torture_utable, 0);