source4/torture/raw: Fix prototypes for all functions.
[gd/samba-autobuild/.git] / source4 / torture / raw / open.c
index f8fa4ff8febb8290de07a58444703878ae32a9f4..89042d77dc2cc74fed6051e3ed301421e66a73bf 100644 (file)
 */
 
 #include "includes.h"
-#include "torture/torture.h"
 #include "libcli/raw/libcliraw.h"
 #include "system/time.h"
 #include "system/filesys.h"
-#include "librpc/gen_ndr/security.h"
 #include "lib/events/events.h"
 #include "libcli/libcli.h"
 #include "torture/util.h"
-#include "auth/credentials/credentials.h"
-#include "lib/cmdline/popt_common.h"
+#include "torture/raw/proto.h"
 
 /* enum for whether reads/writes are possible on a file */
 enum rdwr_mode {RDWR_NONE, RDWR_RDONLY, RDWR_WRONLY, RDWR_RDWR};
@@ -40,8 +37,8 @@ enum rdwr_mode {RDWR_NONE, RDWR_RDONLY, RDWR_WRONLY, RDWR_RDWR};
 static enum rdwr_mode check_rdwr(struct smbcli_tree *tree, int fnum)
 {
        uint8_t c = 1;
-       BOOL can_read  = (smbcli_read(tree, fnum, &c, 0, 1) == 1);
-       BOOL can_write = (smbcli_write(tree, fnum, 0, &c, 0, 1) == 1);
+       bool can_read  = (smbcli_read(tree, fnum, &c, 0, 1) == 1);
+       bool can_write = (smbcli_write(tree, fnum, 0, &c, 0, 1) == 1);
        if ( can_read &&  can_write) return RDWR_RDWR;
        if ( can_read && !can_write) return RDWR_RDONLY;
        if (!can_read &&  can_write) return RDWR_WRONLY;
@@ -64,78 +61,86 @@ static const char *rdwr_string(enum rdwr_mode m)
 
 #define CHECK_STATUS(status, correct) do { \
        if (!NT_STATUS_EQUAL(status, correct)) { \
-               printf("(%s) Incorrect status %s - should be %s\n", \
+               torture_result(tctx, TORTURE_FAIL, \
+                       "(%s) Incorrect status %s - should be %s\n", \
                       __location__, nt_errstr(status), nt_errstr(correct)); \
-               ret = False; \
+               ret = false; \
                goto done; \
        }} while (0)
 
 #define CREATE_FILE do { \
-       fnum = create_complex_file(cli, mem_ctx, fname); \
+       fnum = create_complex_file(cli, tctx, fname); \
        if (fnum == -1) { \
-               printf("(%s) Failed to create %s - %s\n", __location__, fname, smbcli_errstr(cli->tree)); \
-               ret = False; \
+               torture_result(tctx, TORTURE_FAIL, \
+                       "(%s) Failed to create %s - %s\n", \
+                        __location__, fname, smbcli_errstr(cli->tree)); \
+               ret = false; \
                goto done; \
        }} while (0)
 
 #define CHECK_RDWR(fnum, correct) do { \
        enum rdwr_mode m = check_rdwr(cli->tree, fnum); \
        if (m != correct) { \
-               printf("(%s) Incorrect readwrite mode %s - expected %s\n", \
+               torture_result(tctx, TORTURE_FAIL, \
+                      "(%s) Incorrect readwrite mode %s - expected %s\n", \
                       __location__, rdwr_string(m), rdwr_string(correct)); \
-               ret = False; \
+               ret = false; \
        }} while (0)
 
 #define CHECK_TIME(t, field) do { \
        time_t t1, t2; \
        finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
        finfo.all_info.in.file.path = fname; \
-       status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo); \
+       status = smb_raw_pathinfo(cli->tree, tctx, &finfo); \
        CHECK_STATUS(status, NT_STATUS_OK); \
        t1 = t & ~1; \
        t2 = nt_time_to_unix(finfo.all_info.out.field) & ~1; \
        if (abs(t1-t2) > 2) { \
-               printf("(%s) wrong time for field %s  %s - %s\n", \
+               torture_result(tctx, TORTURE_FAIL, \
+                      "(%s) wrong time for field %s  %s - %s\n", \
                       __location__, #field, \
-                      timestring(mem_ctx, t1), \
-                      timestring(mem_ctx, t2)); \
-               dump_all_info(mem_ctx, &finfo); \
-               ret = False; \
+                      timestring(tctx, t1), \
+                      timestring(tctx, t2)); \
+               dump_all_info(tctx, &finfo); \
+               ret = false; \
        }} while (0)
 
 #define CHECK_NTTIME(t, field) do { \
        NTTIME t2; \
        finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
        finfo.all_info.in.file.path = fname; \
-       status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo); \
+       status = smb_raw_pathinfo(cli->tree, tctx, &finfo); \
        CHECK_STATUS(status, NT_STATUS_OK); \
        t2 = finfo.all_info.out.field; \
        if (t != t2) { \
-               printf("(%s) wrong time for field %s  %s - %s\n", \
+               torture_result(tctx, TORTURE_FAIL, \
+                      "(%s) wrong time for field %s  %s - %s\n", \
                       __location__, #field, \
-                      nt_time_string(mem_ctx, t), \
-                      nt_time_string(mem_ctx, t2)); \
-               dump_all_info(mem_ctx, &finfo); \
-               ret = False; \
+                      nt_time_string(tctx, t), \
+                      nt_time_string(tctx, t2)); \
+               dump_all_info(tctx, &finfo); \
+               ret = false; \
        }} while (0)
 
 #define CHECK_ALL_INFO(v, field) do { \
        finfo.all_info.level = RAW_FILEINFO_ALL_INFO; \
        finfo.all_info.in.file.path = fname; \
-       status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo); \
+       status = smb_raw_pathinfo(cli->tree, tctx, &finfo); \
        CHECK_STATUS(status, NT_STATUS_OK); \
        if ((v) != (finfo.all_info.out.field)) { \
-               printf("(%s) wrong value for field %s  0x%x - 0x%x\n", \
+               torture_result(tctx, TORTURE_FAIL, \
+                      "(%s) wrong value for field %s  0x%x - 0x%x\n", \
                       __location__, #field, (int)v, (int)(finfo.all_info.out.field)); \
-               dump_all_info(mem_ctx, &finfo); \
-               ret = False; \
+               dump_all_info(tctx, &finfo); \
+               ret = false; \
        }} while (0)
 
 #define CHECK_VAL(v, correct) do { \
        if ((v) != (correct)) { \
-               printf("(%s) wrong value for %s  0x%x - should be 0x%x\n", \
+               torture_result(tctx, TORTURE_FAIL, \
+                      "(%s) wrong value for %s  0x%x - should be 0x%x\n", \
                       __location__, #v, (int)(v), (int)correct); \
-               ret = False; \
+               ret = false; \
        }} while (0)
 
 #define SET_ATTRIB(sattrib) do { \
@@ -146,29 +151,31 @@ static const char *rdwr_string(enum rdwr_mode m)
        sfinfo.basic_info.in.attrib = sattrib; \
        status = smb_raw_setpathinfo(cli->tree, &sfinfo); \
        if (!NT_STATUS_IS_OK(status)) { \
-               printf("(%s) Failed to set attrib 0x%x on %s\n", \
+               torture_warning(tctx, "(%s) Failed to set attrib 0x%x on %s\n", \
                       __location__, sattrib, fname); \
        }} while (0)
 
 /*
   test RAW_OPEN_OPEN
 */
-static BOOL test_open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_open(struct torture_context *tctx, struct smbcli_state *cli)
 {
        union smb_open io;
        union smb_fileinfo finfo;
        const char *fname = BASEDIR "\\torture_open.txt";
        NTSTATUS status;
        int fnum = -1, fnum2;
-       BOOL ret = True;
+       bool ret = true;
 
-       printf("Checking RAW_OPEN_OPEN\n");
+       if (!torture_setup_dir(cli, BASEDIR)) {
+               return false;
+       }
 
        io.openold.level = RAW_OPEN_OPEN;
        io.openold.in.fname = fname;
        io.openold.in.open_mode = OPEN_FLAGS_FCB;
        io.openold.in.search_attrs = 0;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
        fnum = io.openold.out.file.fnum;
 
@@ -176,12 +183,12 @@ static BOOL test_open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        CREATE_FILE;
        smbcli_close(cli->tree, fnum);
 
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = io.openold.out.file.fnum;
        CHECK_RDWR(fnum, RDWR_RDWR);
 
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum2 = io.openold.out.file.fnum;
        CHECK_RDWR(fnum2, RDWR_RDWR);
@@ -194,21 +201,21 @@ static BOOL test_open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        io.openold.in.search_attrs = 0;
 
        io.openold.in.open_mode = OPEN_FLAGS_OPEN_READ;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = io.openold.out.file.fnum;
        CHECK_RDWR(fnum, RDWR_RDONLY);
        smbcli_close(cli->tree, fnum);
 
        io.openold.in.open_mode = OPEN_FLAGS_OPEN_WRITE;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = io.openold.out.file.fnum;
        CHECK_RDWR(fnum, RDWR_WRONLY);
        smbcli_close(cli->tree, fnum);
 
        io.openold.in.open_mode = OPEN_FLAGS_OPEN_RDWR;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = io.openold.out.file.fnum;
        CHECK_RDWR(fnum, RDWR_RDWR);
@@ -216,22 +223,22 @@ static BOOL test_open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        /* check the share modes roughly - not a complete matrix */
        io.openold.in.open_mode = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_WRITE;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = io.openold.out.file.fnum;
        CHECK_RDWR(fnum, RDWR_RDWR);
        
        if (io.openold.in.open_mode != io.openold.out.rmode) {
-               printf("(%s) rmode should equal open_mode - 0x%x 0x%x\n",
+               torture_warning(tctx, "(%s) rmode should equal open_mode - 0x%x 0x%x\n",
                       __location__, io.openold.out.rmode, io.openold.in.open_mode);
        }
 
        io.openold.in.open_mode = OPEN_FLAGS_OPEN_RDWR | OPEN_FLAGS_DENY_NONE;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
 
        io.openold.in.open_mode = OPEN_FLAGS_OPEN_READ | OPEN_FLAGS_DENY_NONE;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum2 = io.openold.out.file.fnum;
        CHECK_RDWR(fnum2, RDWR_RDONLY);
@@ -244,7 +251,7 @@ static BOOL test_open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        io.openold.in.fname = fname;
        io.openold.in.search_attrs = 0;
        io.openold.in.open_mode = OPEN_FLAGS_OPEN_READ;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = io.openold.out.file.fnum;
 
@@ -255,7 +262,7 @@ static BOOL test_open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
 done:
        smbcli_close(cli->tree, fnum);
-       smbcli_unlink(cli->tree, fname);
+       smbcli_deltree(cli->tree, BASEDIR);
 
        return ret;
 }
@@ -264,7 +271,7 @@ done:
 /*
   test RAW_OPEN_OPENX
 */
-static BOOL test_openx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_openx(struct torture_context *tctx, struct smbcli_state *cli)
 {
        union smb_open io;
        union smb_fileinfo finfo;
@@ -272,30 +279,31 @@ static BOOL test_openx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        const char *fname_exe = BASEDIR "\\torture_openx.exe";
        NTSTATUS status;
        int fnum = -1, fnum2;
-       BOOL ret = True;
+       bool ret = true;
        int i;
        struct timeval tv;
        struct {
                uint16_t open_func;
-               BOOL with_file;
+               bool with_file;
                NTSTATUS correct_status;
        } open_funcs[] = {
-               { OPENX_OPEN_FUNC_OPEN,                           True,  NT_STATUS_OK },
-               { OPENX_OPEN_FUNC_OPEN,                           False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
-               { OPENX_OPEN_FUNC_OPEN  | OPENX_OPEN_FUNC_CREATE, True,  NT_STATUS_OK },
-               { OPENX_OPEN_FUNC_OPEN  | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
-               { OPENX_OPEN_FUNC_FAIL,                           True,  NT_STATUS_DOS(ERRDOS, ERRbadaccess) },
-               { OPENX_OPEN_FUNC_FAIL,                           False, NT_STATUS_DOS(ERRDOS, ERRbadaccess) },
-               { OPENX_OPEN_FUNC_FAIL  | OPENX_OPEN_FUNC_CREATE, True,  NT_STATUS_OBJECT_NAME_COLLISION },
-               { OPENX_OPEN_FUNC_FAIL  | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
-               { OPENX_OPEN_FUNC_TRUNC,                          True,  NT_STATUS_OK },
-               { OPENX_OPEN_FUNC_TRUNC,                          False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
-               { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, True,  NT_STATUS_OK },
-               { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
+               { OPENX_OPEN_FUNC_OPEN,                           true,  NT_STATUS_OK },
+               { OPENX_OPEN_FUNC_OPEN,                           false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
+               { OPENX_OPEN_FUNC_OPEN  | OPENX_OPEN_FUNC_CREATE, true,  NT_STATUS_OK },
+               { OPENX_OPEN_FUNC_OPEN  | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
+               { OPENX_OPEN_FUNC_FAIL,                           true,  NT_STATUS_DOS(ERRDOS, ERRbadaccess) },
+               { OPENX_OPEN_FUNC_FAIL,                           false, NT_STATUS_DOS(ERRDOS, ERRbadaccess) },
+               { OPENX_OPEN_FUNC_FAIL  | OPENX_OPEN_FUNC_CREATE, true,  NT_STATUS_OBJECT_NAME_COLLISION },
+               { OPENX_OPEN_FUNC_FAIL  | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
+               { OPENX_OPEN_FUNC_TRUNC,                          true,  NT_STATUS_OK },
+               { OPENX_OPEN_FUNC_TRUNC,                          false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
+               { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, true,  NT_STATUS_OK },
+               { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
        };
 
-       printf("Checking RAW_OPEN_OPENX\n");
-       smbcli_unlink(cli->tree, fname);
+       if (!torture_setup_dir(cli, BASEDIR)) {
+               return false;
+       }
 
        io.openx.level = RAW_OPEN_OPENX;
        io.openx.in.fname = fname;
@@ -310,21 +318,27 @@ static BOOL test_openx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        /* check all combinations of open_func */
        for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
                if (open_funcs[i].with_file) {
-                       fnum = create_complex_file(cli, mem_ctx, fname);
+                       fnum = create_complex_file(cli, tctx, fname);
                        if (fnum == -1) {
-                               d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
-                               ret = False;
+                               torture_result(tctx, TORTURE_FAIL,
+                                       "Failed to create file %s - %s\n",
+                                       fname, smbcli_errstr(cli->tree));
+                               ret = false;
                                goto done;
                        }
                        smbcli_close(cli->tree, fnum);
                }
                io.openx.in.open_func = open_funcs[i].open_func;
-               status = smb_raw_open(cli->tree, mem_ctx, &io);
+               status = smb_raw_open(cli->tree, tctx, &io);
                if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
-                       printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_func=0x%x)\n", 
-                              __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
-                              i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_func);
-                       ret = False;
+                       torture_result(tctx, TORTURE_FAIL,
+                               "(%s) incorrect status %s should be %s "
+                               "(i=%d with_file=%d open_func=0x%x)\n",
+                               __location__, nt_errstr(status),
+                               nt_errstr(open_funcs[i].correct_status),
+                               i, (int)open_funcs[i].with_file,
+                               (int)open_funcs[i].open_func);
+                       ret = false;
                }
                if (NT_STATUS_IS_OK(status)) {
                        smbcli_close(cli->tree, io.openx.out.file.fnum);
@@ -338,7 +352,7 @@ static BOOL test_openx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        /* check the basic return fields */
        io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = io.openx.out.file.fnum;
 
@@ -355,15 +369,15 @@ static BOOL test_openx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        smbcli_unlink(cli->tree, fname);
 
        /* check the fields when the file already existed */
-       fnum2 = create_complex_file(cli, mem_ctx, fname);
+       fnum2 = create_complex_file(cli, tctx, fname);
        if (fnum2 == -1) {
-               ret = False;
+               ret = false;
                goto done;
        }
        smbcli_close(cli->tree, fnum2);
 
        io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = io.openx.out.file.fnum;
 
@@ -379,12 +393,12 @@ static BOOL test_openx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN, attrib);
 
        io.openx.in.search_attrs = FILE_ATTRIBUTE_HIDDEN;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        smbcli_close(cli->tree, io.openx.out.file.fnum);
 
        io.openx.in.search_attrs = 0;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        smbcli_close(cli->tree, io.openx.out.file.fnum);
 
@@ -395,9 +409,9 @@ static BOOL test_openx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        io.openx.in.open_func = OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE;
        io.openx.in.search_attrs = 0;
        io.openx.in.file_attrs = FILE_ATTRIBUTE_SYSTEM;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
-       if (lp_parm_bool(-1, "torture", "samba3", False)) {
+       if (torture_setting_bool(tctx, "samba3", false)) {
                CHECK_ALL_INFO(FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_ARCHIVE, 
                               attrib & ~(FILE_ATTRIBUTE_NONINDEXED|
                                          FILE_ATTRIBUTE_SPARSE));
@@ -413,19 +427,21 @@ static BOOL test_openx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
        io.openx.in.file_attrs = 0;
        io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = io.openx.out.file.fnum;
 
        io.openx.in.timeout = 20000;
        tv = timeval_current();
        io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_NONE;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
        if (timeval_elapsed(&tv) > 3.0) {
-               printf("(%s) Incorrect timing in openx with timeout - waited %.2f seconds\n",
-                      __location__, timeval_elapsed(&tv));
-               ret = False;
+               torture_result(tctx, TORTURE_FAIL,
+                       "(%s) Incorrect timing in openx with timeout "
+                       "- waited %.2f seconds\n",
+                       __location__, timeval_elapsed(&tv));
+               ret = false;
        }
        smbcli_close(cli->tree, fnum);
        smbcli_unlink(cli->tree, fname);
@@ -440,27 +456,27 @@ static BOOL test_openx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        io.openx.in.write_time = 0;
        io.openx.in.size = 0;
        io.openx.in.timeout = 0;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        smbcli_close(cli->tree, io.openx.out.file.fnum);
 
        /* check the extended return flag */
        io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO | OPENX_FLAGS_EXTENDED_RETURN;
        io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        CHECK_VAL(io.openx.out.access_mask, SEC_STD_ALL);
        smbcli_close(cli->tree, io.openx.out.file.fnum);
 
        io.openx.in.fname = "\\A.+,;=[].B";
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
 
        /* Check the mapping for open exec. */
 
        /* First create an .exe file. */
        smbcli_unlink(cli->tree, fname_exe);
-       fnum = create_complex_file(cli, mem_ctx, fname_exe);
+       fnum = create_complex_file(cli, tctx, fname_exe);
        smbcli_close(cli->tree, fnum);
 
        io.openx.level = RAW_OPEN_OPENX;
@@ -472,7 +488,7 @@ static BOOL test_openx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        io.openx.in.write_time = 0;
        io.openx.in.size = 0;
        io.openx.in.timeout = 0;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
 
        /* Can we read and write ? */
@@ -482,8 +498,7 @@ static BOOL test_openx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
 done:
        smbcli_close(cli->tree, fnum);
-       smbcli_unlink(cli->tree, fname_exe);
-       smbcli_unlink(cli->tree, fname);
+       smbcli_deltree(cli->tree, BASEDIR);
 
        return ret;
 }
@@ -494,7 +509,7 @@ done:
 
   many thanks to kukks for a sniff showing how this works with os2->w2k
 */
-static BOOL test_t2open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_t2open(struct torture_context *tctx, struct smbcli_state *cli)
 {
        union smb_open io;
        union smb_fileinfo finfo;
@@ -503,37 +518,41 @@ static BOOL test_t2open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        const char *fname = BASEDIR "\\torture_t2open_3.txt";
        NTSTATUS status;
        int fnum;
-       BOOL ret = True;
+       bool ret = true;
        int i;
        struct {
                uint16_t open_func;
-               BOOL with_file;
+               bool with_file;
                NTSTATUS correct_status;
        } open_funcs[] = {
-               { OPENX_OPEN_FUNC_OPEN,                           True,  NT_STATUS_OK },
-               { OPENX_OPEN_FUNC_OPEN,                           False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
-               { OPENX_OPEN_FUNC_OPEN  | OPENX_OPEN_FUNC_CREATE, True,  NT_STATUS_OK },
-               { OPENX_OPEN_FUNC_OPEN  | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
-               { OPENX_OPEN_FUNC_FAIL,                           True,  NT_STATUS_OBJECT_NAME_COLLISION },
-               { OPENX_OPEN_FUNC_FAIL,                           False, NT_STATUS_OBJECT_NAME_COLLISION },
-               { OPENX_OPEN_FUNC_FAIL  | OPENX_OPEN_FUNC_CREATE, True,  NT_STATUS_OBJECT_NAME_COLLISION },
-               { OPENX_OPEN_FUNC_FAIL  | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OBJECT_NAME_COLLISION },
-               { OPENX_OPEN_FUNC_TRUNC,                          True,  NT_STATUS_OK },
-               { OPENX_OPEN_FUNC_TRUNC,                          False, NT_STATUS_OK },
-               { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, True,  NT_STATUS_OK },
-               { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, False, NT_STATUS_OK },
+               { OPENX_OPEN_FUNC_OPEN,                           true,  NT_STATUS_OK },
+               { OPENX_OPEN_FUNC_OPEN,                           false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
+               { OPENX_OPEN_FUNC_OPEN  | OPENX_OPEN_FUNC_CREATE, true,  NT_STATUS_OK },
+               { OPENX_OPEN_FUNC_OPEN  | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
+               { OPENX_OPEN_FUNC_FAIL,                           true,  NT_STATUS_OBJECT_NAME_COLLISION },
+               { OPENX_OPEN_FUNC_FAIL,                           false, NT_STATUS_OBJECT_NAME_COLLISION },
+               { OPENX_OPEN_FUNC_FAIL  | OPENX_OPEN_FUNC_CREATE, true,  NT_STATUS_OBJECT_NAME_COLLISION },
+               { OPENX_OPEN_FUNC_FAIL  | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OBJECT_NAME_COLLISION },
+               { OPENX_OPEN_FUNC_TRUNC,                          true,  NT_STATUS_OK },
+               { OPENX_OPEN_FUNC_TRUNC,                          false, NT_STATUS_OK },
+               { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, true,  NT_STATUS_OK },
+               { OPENX_OPEN_FUNC_TRUNC | OPENX_OPEN_FUNC_CREATE, false, NT_STATUS_OK },
        };
 
-       fnum = create_complex_file(cli, mem_ctx, fname1);
+       if (!torture_setup_dir(cli, BASEDIR)) {
+               return false;
+       }
+
+       fnum = create_complex_file(cli, tctx, fname1);
        if (fnum == -1) {
-               d_printf("Failed to create file %s - %s\n", fname1, smbcli_errstr(cli->tree));
-               ret = False;
+               torture_result(tctx, TORTURE_FAIL,
+                       "(%s): Failed to create file %s - %s\n",
+                       __location__, fname1, smbcli_errstr(cli->tree));
+               ret = false;
                goto done;
        }
        smbcli_close(cli->tree, fnum);
 
-       printf("Checking RAW_OPEN_T2OPEN\n");
-
        io.t2open.level = RAW_OPEN_T2OPEN;
        io.t2open.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
        io.t2open.in.open_mode = OPENX_MODE_DENY_NONE | OPENX_MODE_ACCESS_RDWR;
@@ -545,16 +564,16 @@ static BOOL test_t2open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        io.t2open.in.timeout = 0;
 
        io.t2open.in.num_eas = 3;
-       io.t2open.in.eas = talloc_array(mem_ctx, struct ea_struct, io.t2open.in.num_eas);
+       io.t2open.in.eas = talloc_array(tctx, struct ea_struct, io.t2open.in.num_eas);
        io.t2open.in.eas[0].flags = 0;
        io.t2open.in.eas[0].name.s = ".CLASSINFO";
-       io.t2open.in.eas[0].value = data_blob_talloc(mem_ctx, "first value", 11);
+       io.t2open.in.eas[0].value = data_blob_talloc(tctx, "first value", 11);
        io.t2open.in.eas[1].flags = 0;
        io.t2open.in.eas[1].name.s = "EA TWO";
-       io.t2open.in.eas[1].value = data_blob_talloc(mem_ctx, "foo", 3);
+       io.t2open.in.eas[1].value = data_blob_talloc(tctx, "foo", 3);
        io.t2open.in.eas[2].flags = 0;
        io.t2open.in.eas[2].name.s = "X THIRD";
-       io.t2open.in.eas[2].value = data_blob_talloc(mem_ctx, "xy", 2);
+       io.t2open.in.eas[2].value = data_blob_talloc(tctx, "xy", 2);
 
        /* check all combinations of open_func */
        for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
@@ -565,21 +584,26 @@ static BOOL test_t2open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
                        io.t2open.in.fname = fname2;
                }
                io.t2open.in.open_func = open_funcs[i].open_func;
-               status = smb_raw_open(cli->tree, mem_ctx, &io);
+               status = smb_raw_open(cli->tree, tctx, &io);
                if ((io.t2open.in.num_eas != 0)
                    && NT_STATUS_EQUAL(status, NT_STATUS_EAS_NOT_SUPPORTED)
-                   && lp_parm_bool(-1, "torture", "samba3", False)) {
-                       printf("(%s) EAs not supported, not treating as fatal "
-                              "in Samba3 test\n", __location__);
+                   && torture_setting_bool(tctx, "samba3", false)) {
+                       torture_warning(tctx, "(%s) EAs not supported, not "
+                               "treating as fatal in Samba3 test\n",
+                               __location__);
                        io.t2open.in.num_eas = 0;
                        goto again;
                }
 
                if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
-                       printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_func=0x%x)\n", 
-                              __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
-                              i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_func);
-                       ret = False;
+                       torture_result(tctx, TORTURE_FAIL,
+                               "(%s) incorrect status %s should be %s "
+                               "(i=%d with_file=%d open_func=0x%x)\n",
+                                __location__, nt_errstr(status),
+                               nt_errstr(open_funcs[i].correct_status),
+                               i, (int)open_funcs[i].with_file,
+                               (int)open_funcs[i].open_func);
+                       ret = false;
                }
                if (NT_STATUS_IS_OK(status)) {
                        smbcli_close(cli->tree, io.t2open.out.file.fnum);
@@ -593,7 +617,7 @@ static BOOL test_t2open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        io.t2open.in.open_func = OPENX_OPEN_FUNC_OPEN | OPENX_OPEN_FUNC_CREATE;
        io.t2open.in.write_time = 0;
        io.t2open.in.fname = fname;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = io.t2open.out.file.fnum;
 
@@ -623,11 +647,11 @@ static BOOL test_t2open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        SET_ATTRIB(FILE_ATTRIBUTE_HIDDEN);
        CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN, attrib);
 
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        smbcli_close(cli->tree, io.t2open.out.file.fnum);
 
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        smbcli_close(cli->tree, io.t2open.out.file.fnum);
 
@@ -637,7 +661,7 @@ static BOOL test_t2open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        /* and check attrib on create */
        io.t2open.in.open_func = OPENX_OPEN_FUNC_FAIL | OPENX_OPEN_FUNC_CREATE;
        io.t2open.in.file_attrs = FILE_ATTRIBUTE_SYSTEM;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
 
        /* check timeout on create - win2003 ignores the timeout! */
@@ -645,12 +669,12 @@ static BOOL test_t2open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        io.t2open.in.file_attrs = 0;
        io.t2open.in.timeout = 20000;
        io.t2open.in.open_mode = OPENX_MODE_ACCESS_RDWR | OPENX_MODE_DENY_ALL;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION);
 
 done:
        smbcli_close(cli->tree, fnum);
-       smbcli_unlink(cli->tree, fname);
+       smbcli_deltree(cli->tree, BASEDIR);
 
        return ret;
 }
@@ -659,7 +683,7 @@ done:
 /*
   test RAW_OPEN_NTCREATEX
 */
-static BOOL test_ntcreatex(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_ntcreatex(struct torture_context *tctx, struct smbcli_state *cli)
 {
        union smb_open io;
        union smb_fileinfo finfo;
@@ -667,35 +691,37 @@ static BOOL test_ntcreatex(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        const char *dname = BASEDIR "\\torture_ntcreatex.dir";
        NTSTATUS status;
        int fnum = -1;
-       BOOL ret = True;
+       bool ret = true;
        int i;
        struct {
                uint32_t open_disp;
-               BOOL with_file;
+               bool with_file;
                NTSTATUS correct_status;
        } open_funcs[] = {
-               { NTCREATEX_DISP_SUPERSEDE,     True,  NT_STATUS_OK },
-               { NTCREATEX_DISP_SUPERSEDE,     False, NT_STATUS_OK },
-               { NTCREATEX_DISP_OPEN,          True,  NT_STATUS_OK },
-               { NTCREATEX_DISP_OPEN,          False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
-               { NTCREATEX_DISP_CREATE,        True,  NT_STATUS_OBJECT_NAME_COLLISION },
-               { NTCREATEX_DISP_CREATE,        False, NT_STATUS_OK },
-               { NTCREATEX_DISP_OPEN_IF,       True,  NT_STATUS_OK },
-               { NTCREATEX_DISP_OPEN_IF,       False, NT_STATUS_OK },
-               { NTCREATEX_DISP_OVERWRITE,     True,  NT_STATUS_OK },
-               { NTCREATEX_DISP_OVERWRITE,     False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
-               { NTCREATEX_DISP_OVERWRITE_IF,  True,  NT_STATUS_OK },
-               { NTCREATEX_DISP_OVERWRITE_IF,  False, NT_STATUS_OK },
-               { 6,                            True,  NT_STATUS_INVALID_PARAMETER },
-               { 6,                            False, NT_STATUS_INVALID_PARAMETER },
+               { NTCREATEX_DISP_SUPERSEDE,     true,  NT_STATUS_OK },
+               { NTCREATEX_DISP_SUPERSEDE,     false, NT_STATUS_OK },
+               { NTCREATEX_DISP_OPEN,          true,  NT_STATUS_OK },
+               { NTCREATEX_DISP_OPEN,          false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
+               { NTCREATEX_DISP_CREATE,        true,  NT_STATUS_OBJECT_NAME_COLLISION },
+               { NTCREATEX_DISP_CREATE,        false, NT_STATUS_OK },
+               { NTCREATEX_DISP_OPEN_IF,       true,  NT_STATUS_OK },
+               { NTCREATEX_DISP_OPEN_IF,       false, NT_STATUS_OK },
+               { NTCREATEX_DISP_OVERWRITE,     true,  NT_STATUS_OK },
+               { NTCREATEX_DISP_OVERWRITE,     false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
+               { NTCREATEX_DISP_OVERWRITE_IF,  true,  NT_STATUS_OK },
+               { NTCREATEX_DISP_OVERWRITE_IF,  false, NT_STATUS_OK },
+               { 6,                            true,  NT_STATUS_INVALID_PARAMETER },
+               { 6,                            false, NT_STATUS_INVALID_PARAMETER },
        };
 
-       printf("Checking RAW_OPEN_NTCREATEX\n");
+       if (!torture_setup_dir(cli, BASEDIR)) {
+               return false;
+       }
 
        /* reasonable default parameters */
        io.generic.level = RAW_OPEN_NTCREATEX;
        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
-       io.ntcreatex.in.root_fid = 0;
+       io.ntcreatex.in.root_fid.fnum = 0;
        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
        io.ntcreatex.in.alloc_size = 1024*1024;
        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
@@ -711,19 +737,25 @@ static BOOL test_ntcreatex(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
                if (open_funcs[i].with_file) {
                        fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR|O_TRUNC, DENY_NONE);
                        if (fnum == -1) {
-                               d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
-                               ret = False;
+                               torture_result(tctx, TORTURE_FAIL,
+                                       "Failed to create file %s - %s\n",
+                                       fname, smbcli_errstr(cli->tree));
+                               ret = false;
                                goto done;
                        }
                        smbcli_close(cli->tree, fnum);
                }
                io.ntcreatex.in.open_disposition = open_funcs[i].open_disp;
-               status = smb_raw_open(cli->tree, mem_ctx, &io);
+               status = smb_raw_open(cli->tree, tctx, &io);
                if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
-                       printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_disp=%d)\n", 
-                              __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
-                              i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_disp);
-                       ret = False;
+                       torture_result(tctx, TORTURE_FAIL,
+                               "(%s) incorrect status %s should be %s "
+                               "(i=%d with_file=%d open_disp=%d)\n",
+                               __location__, nt_errstr(status),
+                               nt_errstr(open_funcs[i].correct_status),
+                               i, (int)open_funcs[i].with_file,
+                               (int)open_funcs[i].open_disp);
+                       ret = false;
                }
                if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) {
                        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
@@ -734,7 +766,7 @@ static BOOL test_ntcreatex(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        /* basic field testing */
        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
 
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = io.ntcreatex.out.file.fnum;
 
@@ -753,15 +785,15 @@ static BOOL test_ntcreatex(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        /* check fields when the file already existed */
        smbcli_close(cli->tree, fnum);
        smbcli_unlink(cli->tree, fname);
-       fnum = create_complex_file(cli, mem_ctx, fname);
+       fnum = create_complex_file(cli, tctx, fname);
        if (fnum == -1) {
-               ret = False;
+               ret = false;
                goto done;
        }
        smbcli_close(cli->tree, fnum);
 
        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = io.ntcreatex.out.file.fnum;
 
@@ -798,7 +830,7 @@ static BOOL test_ntcreatex(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = io.ntcreatex.out.file.fnum;
 
@@ -823,7 +855,7 @@ static BOOL test_ntcreatex(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
 done:
        smbcli_close(cli->tree, fnum);
-       smbcli_unlink(cli->tree, fname);
+       smbcli_deltree(cli->tree, BASEDIR);
 
        return ret;
 }
@@ -832,7 +864,7 @@ done:
 /*
   test RAW_OPEN_NTTRANS_CREATE
 */
-static BOOL test_nttrans_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_nttrans_create(struct torture_context *tctx, struct smbcli_state *cli)
 {
        union smb_open io;
        union smb_fileinfo finfo;
@@ -840,35 +872,39 @@ static BOOL test_nttrans_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        const char *dname = BASEDIR "\\torture_ntcreatex.dir";
        NTSTATUS status;
        int fnum = -1;
-       BOOL ret = True;
+       bool ret = true;
        int i;
+       uint32_t ok_mask, not_supported_mask, invalid_parameter_mask;
+       uint32_t not_a_directory_mask, unexpected_mask;
        struct {
                uint32_t open_disp;
-               BOOL with_file;
+               bool with_file;
                NTSTATUS correct_status;
        } open_funcs[] = {
-               { NTCREATEX_DISP_SUPERSEDE,     True,  NT_STATUS_OK },
-               { NTCREATEX_DISP_SUPERSEDE,     False, NT_STATUS_OK },
-               { NTCREATEX_DISP_OPEN,          True,  NT_STATUS_OK },
-               { NTCREATEX_DISP_OPEN,          False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
-               { NTCREATEX_DISP_CREATE,        True,  NT_STATUS_OBJECT_NAME_COLLISION },
-               { NTCREATEX_DISP_CREATE,        False, NT_STATUS_OK },
-               { NTCREATEX_DISP_OPEN_IF,       True,  NT_STATUS_OK },
-               { NTCREATEX_DISP_OPEN_IF,       False, NT_STATUS_OK },
-               { NTCREATEX_DISP_OVERWRITE,     True,  NT_STATUS_OK },
-               { NTCREATEX_DISP_OVERWRITE,     False, NT_STATUS_OBJECT_NAME_NOT_FOUND },
-               { NTCREATEX_DISP_OVERWRITE_IF,  True,  NT_STATUS_OK },
-               { NTCREATEX_DISP_OVERWRITE_IF,  False, NT_STATUS_OK },
-               { 6,                            True,  NT_STATUS_INVALID_PARAMETER },
-               { 6,                            False, NT_STATUS_INVALID_PARAMETER },
+               { NTCREATEX_DISP_SUPERSEDE,     true,  NT_STATUS_OK },
+               { NTCREATEX_DISP_SUPERSEDE,     false, NT_STATUS_OK },
+               { NTCREATEX_DISP_OPEN,          true,  NT_STATUS_OK },
+               { NTCREATEX_DISP_OPEN,          false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
+               { NTCREATEX_DISP_CREATE,        true,  NT_STATUS_OBJECT_NAME_COLLISION },
+               { NTCREATEX_DISP_CREATE,        false, NT_STATUS_OK },
+               { NTCREATEX_DISP_OPEN_IF,       true,  NT_STATUS_OK },
+               { NTCREATEX_DISP_OPEN_IF,       false, NT_STATUS_OK },
+               { NTCREATEX_DISP_OVERWRITE,     true,  NT_STATUS_OK },
+               { NTCREATEX_DISP_OVERWRITE,     false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
+               { NTCREATEX_DISP_OVERWRITE_IF,  true,  NT_STATUS_OK },
+               { NTCREATEX_DISP_OVERWRITE_IF,  false, NT_STATUS_OK },
+               { 6,                            true,  NT_STATUS_INVALID_PARAMETER },
+               { 6,                            false, NT_STATUS_INVALID_PARAMETER },
        };
 
-       printf("Checking RAW_OPEN_NTTRANS_CREATE\n");
+       if (!torture_setup_dir(cli, BASEDIR)) {
+               return false;
+       }
 
        /* reasonable default parameters */
        io.generic.level = RAW_OPEN_NTTRANS_CREATE;
        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
-       io.ntcreatex.in.root_fid = 0;
+       io.ntcreatex.in.root_fid.fnum = 0;
        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
        io.ntcreatex.in.alloc_size = 1024*1024;
        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
@@ -886,19 +922,25 @@ static BOOL test_nttrans_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
                if (open_funcs[i].with_file) {
                        fnum = smbcli_open(cli->tree, fname, O_CREAT|O_RDWR|O_TRUNC, DENY_NONE);
                        if (fnum == -1) {
-                               d_printf("Failed to create file %s - %s\n", fname, smbcli_errstr(cli->tree));
-                               ret = False;
+                               torture_result(tctx, TORTURE_FAIL,
+                                       "Failed to create file %s - %s\n",
+                                       fname, smbcli_errstr(cli->tree));
+                               ret = false;
                                goto done;
                        }
                        smbcli_close(cli->tree, fnum);
                }
                io.ntcreatex.in.open_disposition = open_funcs[i].open_disp;
-               status = smb_raw_open(cli->tree, mem_ctx, &io);
+               status = smb_raw_open(cli->tree, tctx, &io);
                if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
-                       printf("(%s) incorrect status %s should be %s (i=%d with_file=%d open_disp=%d)\n", 
-                              __location__, nt_errstr(status), nt_errstr(open_funcs[i].correct_status),
-                              i, (int)open_funcs[i].with_file, (int)open_funcs[i].open_disp);
-                       ret = False;
+                       torture_result(tctx, TORTURE_FAIL,
+                               "(%s) incorrect status %s should be %s "
+                               "(i=%d with_file=%d open_disp=%d)\n",
+                               __location__, nt_errstr(status),
+                               nt_errstr(open_funcs[i].correct_status),
+                               i, (int)open_funcs[i].with_file,
+                               (int)open_funcs[i].open_disp);
+                       ret = false;
                }
                if (NT_STATUS_IS_OK(status) || open_funcs[i].with_file) {
                        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
@@ -909,7 +951,7 @@ static BOOL test_nttrans_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        /* basic field testing */
        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
 
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = io.ntcreatex.out.file.fnum;
 
@@ -928,15 +970,15 @@ static BOOL test_nttrans_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        /* check fields when the file already existed */
        smbcli_close(cli->tree, fnum);
        smbcli_unlink(cli->tree, fname);
-       fnum = create_complex_file(cli, mem_ctx, fname);
+       fnum = create_complex_file(cli, tctx, fname);
        if (fnum == -1) {
-               ret = False;
+               ret = false;
                goto done;
        }
        smbcli_close(cli->tree, fnum);
 
        io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = io.ntcreatex.out.file.fnum;
 
@@ -952,6 +994,95 @@ static BOOL test_nttrans_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
        CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
        smbcli_close(cli->tree, fnum);
+
+       /* check no-recall - don't pull a file from tape on a HSM */
+       io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_NO_RECALL;
+       status = smb_raw_open(cli->tree, tctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       fnum = io.ntcreatex.out.file.fnum;
+
+       CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
+       CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
+       CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
+       CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
+       CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
+       CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
+       CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
+       CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
+       CHECK_ALL_INFO(io.ntcreatex.out.size, size);
+       CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
+       CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
+       smbcli_close(cli->tree, fnum);
+
+       /* Check some create options (these all should be ignored) */
+       for (i=0; i < 32; i++) {
+               uint32_t create_option = (1 << i) & NTCREATEX_OPTIONS_MUST_IGNORE_MASK;
+               if (create_option == 0) {
+                       continue;
+               }
+               io.ntcreatex.in.create_options = create_option;
+               status = smb_raw_open(cli->tree, tctx, &io);
+               if (!NT_STATUS_IS_OK(status)) {
+                       torture_warning(tctx, "ntcreatex create option 0x%08x "
+                               "gave %s - should give NT_STATUS_OK\n",
+                               create_option, nt_errstr(status));
+               }
+               CHECK_STATUS(status, NT_STATUS_OK);
+               fnum = io.ntcreatex.out.file.fnum;
+
+               CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
+               CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_EXISTED);
+               CHECK_NTTIME(io.ntcreatex.out.create_time, create_time);
+               CHECK_NTTIME(io.ntcreatex.out.access_time, access_time);
+               CHECK_NTTIME(io.ntcreatex.out.write_time, write_time);
+               CHECK_NTTIME(io.ntcreatex.out.change_time, change_time);
+               CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
+               CHECK_ALL_INFO(io.ntcreatex.out.alloc_size, alloc_size);
+               CHECK_ALL_INFO(io.ntcreatex.out.size, size);
+               CHECK_ALL_INFO(io.ntcreatex.out.is_directory, directory);
+               CHECK_VAL(io.ntcreatex.out.file_type, FILE_TYPE_DISK);
+               smbcli_close(cli->tree, fnum);
+       }
+
+       io.ntcreatex.in.file_attr = 0;
+       io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF;
+       io.ntcreatex.in.access_mask     = SEC_FLAG_MAXIMUM_ALLOWED;
+
+       /* Check for options that should return NOT_SUPPORTED, OK or INVALID_PARAMETER */
+       ok_mask = 0;
+       not_supported_mask = 0;
+       invalid_parameter_mask = 0;
+       not_a_directory_mask = 0;
+       unexpected_mask = 0;
+       for (i=0; i < 32; i++) {
+               uint32_t create_option = 1<<i;
+               if (create_option & NTCREATEX_OPTIONS_DELETE_ON_CLOSE) {
+                       continue;
+               }
+               io.ntcreatex.in.create_options = create_option;
+               status = smb_raw_open(cli->tree, tctx, &io);
+               if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_SUPPORTED)) {
+                       not_supported_mask |= create_option;
+               } else if (NT_STATUS_EQUAL(status, NT_STATUS_OK)) {
+                       ok_mask |= create_option;
+                       smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
+               } else if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) {
+                       invalid_parameter_mask |= create_option;
+               } else if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_A_DIRECTORY)) {
+                       not_a_directory_mask |= 1<<i;
+               } else {
+                       unexpected_mask |= 1<<i;
+                       torture_comment(tctx, "create option 0x%08x returned %s\n",
+                                       create_option, nt_errstr(status));
+               }
+       }
+
+       CHECK_VAL(ok_mask,                0x00efcfce);
+       CHECK_VAL(not_a_directory_mask,   0x00000001);
+       CHECK_VAL(not_supported_mask,     0x00002000);
+       CHECK_VAL(invalid_parameter_mask, 0xff100030);
+       CHECK_VAL(unexpected_mask,        0x00000000);
+
        smbcli_unlink(cli->tree, fname);
 
 
@@ -973,7 +1104,7 @@ static BOOL test_nttrans_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = io.ntcreatex.out.file.fnum;
 
@@ -998,7 +1129,7 @@ static BOOL test_nttrans_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
 done:
        smbcli_close(cli->tree, fnum);
-       smbcli_unlink(cli->tree, fname);
+       smbcli_deltree(cli->tree, BASEDIR);
 
        return ret;
 }
@@ -1011,20 +1142,24 @@ done:
   open_disposition==NTCREATEX_DISP_OVERWRITE_IF. Windows 2003 allows the
   second open.
 */
-static BOOL test_ntcreatex_brlocked(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_ntcreatex_brlocked(struct torture_context *tctx, struct smbcli_state *cli)
 {
        union smb_open io, io1;
        union smb_lock io2;
        struct smb_lock_entry lock[1];
        const char *fname = BASEDIR "\\torture_ntcreatex.txt";
        NTSTATUS status;
-       BOOL ret = True;
+       bool ret = true;
+
+       if (!torture_setup_dir(cli, BASEDIR)) {
+               return false;
+       }
 
-       printf("Testing ntcreatex with a byte range locked file\n");
+       torture_comment(tctx, "Testing ntcreatex with a byte range locked file\n");
 
        io.generic.level = RAW_OPEN_NTCREATEX;
        io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
-       io.ntcreatex.in.root_fid = 0;
+       io.ntcreatex.in.root_fid.fnum = 0;
        io.ntcreatex.in.access_mask = 0x2019f;
        io.ntcreatex.in.alloc_size = 0;
        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
@@ -1037,7 +1172,7 @@ static BOOL test_ntcreatex_brlocked(struct smbcli_state *cli, TALLOC_CTX *mem_ct
                NTCREATEX_SECURITY_ALL;
        io.ntcreatex.in.fname = fname;
 
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
 
        io2.lockx.level = RAW_LOCK_LOCKX;
@@ -1055,7 +1190,7 @@ static BOOL test_ntcreatex_brlocked(struct smbcli_state *cli, TALLOC_CTX *mem_ct
 
        io1.generic.level = RAW_OPEN_NTCREATEX;
        io1.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
-       io1.ntcreatex.in.root_fid = 0;
+       io1.ntcreatex.in.root_fid.fnum = 0;
        io1.ntcreatex.in.access_mask = 0x20196;
        io1.ntcreatex.in.alloc_size = 0;
        io1.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
@@ -1068,40 +1203,42 @@ static BOOL test_ntcreatex_brlocked(struct smbcli_state *cli, TALLOC_CTX *mem_ct
                NTCREATEX_SECURITY_ALL;
        io1.ntcreatex.in.fname = fname;
 
-       status = smb_raw_open(cli->tree, mem_ctx, &io1);
+       status = smb_raw_open(cli->tree, tctx, &io1);
        CHECK_STATUS(status, NT_STATUS_OK);
 
  done:
        smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
        smbcli_close(cli->tree, io1.ntcreatex.out.file.fnum);
-       smbcli_unlink(cli->tree, fname);
+       smbcli_deltree(cli->tree, BASEDIR);
        return ret;
 }
 
 /*
   test RAW_OPEN_MKNEW
 */
-static BOOL test_mknew(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_mknew(struct torture_context *tctx, struct smbcli_state *cli)
 {
        union smb_open io;
        const char *fname = BASEDIR "\\torture_mknew.txt";
        NTSTATUS status;
        int fnum = -1;
-       BOOL ret = True;
+       bool ret = true;
        time_t basetime = (time(NULL) + 3600*24*3) & ~1;
        union smb_fileinfo finfo;
 
-       printf("Checking RAW_OPEN_MKNEW\n");
+       if (!torture_setup_dir(cli, BASEDIR)) {
+               return false;
+       }
 
        io.mknew.level = RAW_OPEN_MKNEW;
        io.mknew.in.attrib = 0;
        io.mknew.in.write_time = 0;
        io.mknew.in.fname = fname;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = io.mknew.out.file.fnum;
 
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
 
        smbcli_close(cli->tree, fnum);
@@ -1109,7 +1246,7 @@ static BOOL test_mknew(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        /* make sure write_time works */
        io.mknew.in.write_time = basetime;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = io.mknew.out.file.fnum;
        CHECK_TIME(basetime, write_time);
@@ -1119,7 +1256,7 @@ static BOOL test_mknew(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        /* make sure file_attrs works */
        io.mknew.in.attrib = FILE_ATTRIBUTE_HIDDEN;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = io.mknew.out.file.fnum;
        CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE, 
@@ -1127,7 +1264,7 @@ static BOOL test_mknew(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        
 done:
        smbcli_close(cli->tree, fnum);
-       smbcli_unlink(cli->tree, fname);
+       smbcli_deltree(cli->tree, BASEDIR);
 
        return ret;
 }
@@ -1136,27 +1273,29 @@ done:
 /*
   test RAW_OPEN_CREATE
 */
-static BOOL test_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_create(struct torture_context *tctx, struct smbcli_state *cli)
 {
        union smb_open io;
        const char *fname = BASEDIR "\\torture_create.txt";
        NTSTATUS status;
        int fnum = -1;
-       BOOL ret = True;
+       bool ret = true;
        time_t basetime = (time(NULL) + 3600*24*3) & ~1;
        union smb_fileinfo finfo;
 
-       printf("Checking RAW_OPEN_CREATE\n");
+       if (!torture_setup_dir(cli, BASEDIR)) {
+               return false;
+       }
 
        io.create.level = RAW_OPEN_CREATE;
        io.create.in.attrib = 0;
        io.create.in.write_time = 0;
        io.create.in.fname = fname;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = io.create.out.file.fnum;
 
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
 
        smbcli_close(cli->tree, io.create.out.file.fnum);
@@ -1165,7 +1304,7 @@ static BOOL test_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        /* make sure write_time works */
        io.create.in.write_time = basetime;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = io.create.out.file.fnum;
        CHECK_TIME(basetime, write_time);
@@ -1175,7 +1314,7 @@ static BOOL test_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        /* make sure file_attrs works */
        io.create.in.attrib = FILE_ATTRIBUTE_HIDDEN;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = io.create.out.file.fnum;
        CHECK_ALL_INFO(FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_ARCHIVE, 
@@ -1183,7 +1322,7 @@ static BOOL test_create(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        
 done:
        smbcli_close(cli->tree, fnum);
-       smbcli_unlink(cli->tree, fname);
+       smbcli_deltree(cli->tree, BASEDIR);
 
        return ret;
 }
@@ -1192,23 +1331,25 @@ done:
 /*
   test RAW_OPEN_CTEMP
 */
-static BOOL test_ctemp(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_ctemp(struct torture_context *tctx, struct smbcli_state *cli)
 {
        union smb_open io;
        NTSTATUS status;
        int fnum = -1;
-       BOOL ret = True;
+       bool ret = true;
        time_t basetime = (time(NULL) + 3600*24*3) & ~1;
        union smb_fileinfo finfo;
        const char *name, *fname = NULL;
 
-       printf("Checking RAW_OPEN_CTEMP\n");
+       if (!torture_setup_dir(cli, BASEDIR)) {
+               return false;
+       }
 
        io.ctemp.level = RAW_OPEN_CTEMP;
        io.ctemp.in.attrib = FILE_ATTRIBUTE_HIDDEN;
        io.ctemp.in.write_time = basetime;
        io.ctemp.in.directory = BASEDIR;
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = io.ctemp.out.file.fnum;
 
@@ -1216,17 +1357,15 @@ static BOOL test_ctemp(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        finfo.generic.level = RAW_FILEINFO_NAME_INFO;
        finfo.generic.in.file.fnum = fnum;
-       status = smb_raw_fileinfo(cli->tree, mem_ctx, &finfo);
+       status = smb_raw_fileinfo(cli->tree, tctx, &finfo);
        CHECK_STATUS(status, NT_STATUS_OK);
 
        fname = finfo.name_info.out.fname.s;
-       d_printf("ctemp name=%s  real name=%s\n", name, fname);
+       torture_comment(tctx, "ctemp name=%s  real name=%s\n", name, fname);
 
 done:
        smbcli_close(cli->tree, fnum);
-       if (fname) {
-               smbcli_unlink(cli->tree, fname);
-       }
+       smbcli_deltree(cli->tree, BASEDIR);
 
        return ret;
 }
@@ -1235,20 +1374,21 @@ done:
 /*
   test chained RAW_OPEN_OPENX_READX
 */
-static BOOL test_chained(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_chained(struct torture_context *tctx, struct smbcli_state *cli)
 {
        union smb_open io;
        const char *fname = BASEDIR "\\torture_chained.txt";
        NTSTATUS status;
        int fnum = -1;
-       BOOL ret = True;
+       bool ret = true;
        const char *buf = "test";
        char buf2[4];
 
-       printf("Checking RAW_OPEN_OPENX chained with READX\n");
-       smbcli_unlink(cli->tree, fname);
+       if (!torture_setup_dir(cli, BASEDIR)) {
+               return false;
+       }
 
-       fnum = create_complex_file(cli, mem_ctx, fname);
+       fnum = create_complex_file(cli, tctx, fname);
 
        smbcli_write(cli->tree, fnum, 0, buf, 0, sizeof(buf));
 
@@ -1271,18 +1411,19 @@ static BOOL test_chained(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        io.openxreadx.in.remaining = 0;
        io.openxreadx.out.data = (uint8_t *)buf2;
 
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = io.openxreadx.out.file.fnum;
 
        if (memcmp(buf, buf2, sizeof(buf)) != 0) {
-               d_printf("wrong data in reply buffer\n");
-               ret = False;
+               torture_result(tctx, TORTURE_FAIL,
+                       "wrong data in reply buffer\n");
+               ret = false;
        }
 
 done:
        smbcli_close(cli->tree, fnum);
-       smbcli_unlink(cli->tree, fname);
+       smbcli_deltree(cli->tree, BASEDIR);
 
        return ret;
 }
@@ -1292,24 +1433,27 @@ done:
   NetApp filers are known to fail on this.
   
 */
-static BOOL test_no_leading_slash(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_no_leading_slash(struct torture_context *tctx, struct smbcli_state *cli)
 {
        union smb_open io;
        const char *fname = BASEDIR "\\torture_no_leading_slash.txt";
        NTSTATUS status;
        int fnum = -1;
-       BOOL ret = True;
+       bool ret = true;
        const char *buf = "test";
 
-       printf("Checking RAW_OPEN_OPENX without leading slash on path\n");
+       if (!torture_setup_dir(cli, BASEDIR)) {
+               return false;
+       }
+
        smbcli_unlink(cli->tree, fname);
 
-        /* Create the file */
-       fnum = create_complex_file(cli, mem_ctx, fname);
+       /* Create the file */
+       fnum = create_complex_file(cli, tctx, fname);
        smbcli_write(cli->tree, fnum, 0, buf, 0, sizeof(buf));
        smbcli_close(cli->tree, fnum);  
 
-        /* Prepare to open the file using path without leading slash */
+       /* Prepare to open the file using path without leading slash */
        io.openx.level = RAW_OPEN_OPENX;
        io.openx.in.fname = fname + 1;
        io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
@@ -1321,61 +1465,108 @@ static BOOL test_no_leading_slash(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        io.openx.in.size = 1024*1024;
        io.openx.in.timeout = 0;
 
-       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       status = smb_raw_open(cli->tree, tctx, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = io.openx.out.file.fnum;
 
 done:
        smbcli_close(cli->tree, fnum);
-       smbcli_unlink(cli->tree, fname);
+       smbcli_deltree(cli->tree, BASEDIR);
 
        return ret;
 }
 
+/*
+  test RAW_OPEN_OPENX against an existing directory to
+  ensure it returns NT_STATUS_FILE_IS_A_DIRECTORY.
+  Samba 3.2.0 - 3.2.6 are known to fail this.
+  
+*/
+static bool test_openx_over_dir(struct torture_context *tctx, struct smbcli_state *cli)
+{
+       union smb_open io;
+       const char *fname = BASEDIR "\\openx_over_dir";
+       NTSTATUS status;
+       int d_fnum = -1;
+       int fnum = -1;
+       bool ret = true;
+
+       if (!torture_setup_dir(cli, BASEDIR)) {
+               return false;
+       }
+
+       /* Create the Directory */
+       status = create_directory_handle(cli->tree, fname, &d_fnum);
+       smbcli_close(cli->tree, d_fnum);        
+
+       /* Prepare to open the file over the directory. */
+       io.openx.level = RAW_OPEN_OPENX;
+       io.openx.in.fname = fname;
+       io.openx.in.flags = OPENX_FLAGS_ADDITIONAL_INFO;
+       io.openx.in.open_mode = OPENX_MODE_ACCESS_RDWR;
+       io.openx.in.open_func = OPENX_OPEN_FUNC_OPEN;
+       io.openx.in.search_attrs = 0;
+       io.openx.in.file_attrs = 0;
+       io.openx.in.write_time = 0;
+       io.openx.in.size = 1024*1024;
+       io.openx.in.timeout = 0;
+
+       status = smb_raw_open(cli->tree, tctx, &io);
+       CHECK_STATUS(status, NT_STATUS_FILE_IS_A_DIRECTORY);
+       fnum = io.openx.out.file.fnum;
+
+done:
+       smbcli_close(cli->tree, fnum);
+       smbcli_deltree(cli->tree, BASEDIR);
+
+       return ret;
+}
+
+
 /* A little torture test to expose a race condition in Samba 3.0.20 ... :-) */
 
-static BOOL test_raw_open_multi(void)
+static bool test_raw_open_multi(struct torture_context *tctx, struct smbcli_state *cli_ignored)
 {
        struct smbcli_state *cli;
        TALLOC_CTX *mem_ctx = talloc_init("torture_test_oplock_multi");
        const char *fname = "\\test_oplock.dat";
        NTSTATUS status;
-       BOOL ret = True;
+       bool ret = true;
        union smb_open io;
        struct smbcli_state **clients;
        struct smbcli_request **requests;
        union smb_open *ios;
-       const char *host = lp_parm_string(-1, "torture", "host");
-       const char *share = lp_parm_string(-1, "torture", "share");
+       const char *host = torture_setting_string(tctx, "host", NULL);
+       const char *share = torture_setting_string(tctx, "share", NULL);
        int i, num_files = 3;
-       struct event_context *ev;
        int num_ok = 0;
        int num_collision = 0;
        
-       ev = cli_credentials_get_event_context(cmdline_credentials);
        clients = talloc_array(mem_ctx, struct smbcli_state *, num_files);
        requests = talloc_array(mem_ctx, struct smbcli_request *, num_files);
        ios = talloc_array(mem_ctx, union smb_open, num_files);
-       if ((ev == NULL) || (clients == NULL) || (requests == NULL) ||
+       if ((tctx->ev == NULL) || (clients == NULL) || (requests == NULL) ||
            (ios == NULL)) {
-               DEBUG(0, ("talloc failed\n"));
-               return False;
+               torture_result(tctx, TORTURE_FAIL, "(%s): talloc failed\n",
+                               __location__);
+               return false;
        }
 
-       if (!torture_open_connection_share(mem_ctx, &cli, host, share, ev)) {
-               return False;
+       if (!torture_open_connection_share(mem_ctx, &cli, tctx, host, share, tctx->ev)) {
+               return false;
        }
 
-       cli->tree->session->transport->options.request_timeout = 60000;
+       cli->tree->session->transport->options.request_timeout = 60;
 
        for (i=0; i<num_files; i++) {
                if (!torture_open_connection_share(mem_ctx, &(clients[i]),
-                                                  host, share, ev)) {
-                       DEBUG(0, ("Could not open %d'th connection\n", i));
-                       return False;
+                                                  tctx, host, share, tctx->ev)) {
+                       torture_result(tctx, TORTURE_FAIL,
+                                      "(%s): Could not open %d'th connection\n",
+                                      __location__, i);
+                       return false;
                }
-               clients[i]->tree->session->transport->
-                       options.request_timeout = 60000;
+               clients[i]->tree->session->transport->options.request_timeout = 60;
        }
 
        /* cleanup */
@@ -1385,7 +1576,7 @@ static BOOL test_raw_open_multi(void)
          base ntcreatex parms
        */
        io.generic.level = RAW_OPEN_NTCREATEX;
-       io.ntcreatex.in.root_fid = 0;
+       io.ntcreatex.in.root_fid.fnum = 0;
        io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
        io.ntcreatex.in.alloc_size = 0;
        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
@@ -1403,27 +1594,29 @@ static BOOL test_raw_open_multi(void)
                ios[i] = io;
                requests[i] = smb_raw_open_send(clients[i]->tree, &ios[i]);
                if (requests[i] == NULL) {
-                       DEBUG(0, ("could not send %d'th request\n", i));
-                       return False;
+                       torture_result(tctx, TORTURE_FAIL,
+                               "(%s): could not send %d'th request\n",
+                               __location__, i);
+                       return false;
                }
        }
 
-       DEBUG(10, ("waiting for replies\n"));
+       torture_comment(tctx, "waiting for replies\n");
        while (1) {
-               BOOL unreplied = False;
+               bool unreplied = false;
                for (i=0; i<num_files; i++) {
                        if (requests[i] == NULL) {
                                continue;
                        }
                        if (requests[i]->state < SMBCLI_REQUEST_DONE) {
-                               unreplied = True;
+                               unreplied = true;
                                break;
                        }
                        status = smb_raw_open_recv(requests[i], mem_ctx,
                                                   &ios[i]);
 
-                       DEBUG(0, ("File %d returned status %s\n", i,
-                                 nt_errstr(status)));
+                       torture_comment(tctx, "File %d returned status %s\n", i,
+                                 nt_errstr(status));
 
                        if (NT_STATUS_IS_OK(status)) {
                                num_ok += 1;
@@ -1440,14 +1633,15 @@ static BOOL test_raw_open_multi(void)
                        break;
                }
 
-               if (event_loop_once(ev) != 0) {
-                       DEBUG(0, ("event_loop_once failed\n"));
-                       return False;
+               if (event_loop_once(tctx->ev) != 0) {
+                       torture_result(tctx, TORTURE_FAIL,
+                               "(%s): event_loop_once failed\n", __location__);
+                       return false;
                }
        }
 
        if ((num_ok != 1) || (num_ok + num_collision != num_files)) {
-               ret = False;
+               ret = false;
        }
 
        for (i=0; i<num_files; i++) {
@@ -1457,31 +1651,444 @@ static BOOL test_raw_open_multi(void)
        return ret;
 }
 
-/* basic testing of all RAW_OPEN_* calls 
+/*
+  test opening for delete on a read-only attribute file.
 */
-bool torture_raw_open(struct torture_context *torture, struct smbcli_state *cli)
+static bool test_open_for_delete(struct torture_context *tctx, struct smbcli_state *cli)
 {
+       union smb_open io;
+       union smb_fileinfo finfo;
+       const char *fname = BASEDIR "\\torture_open_for_delete.txt";
+       NTSTATUS status;
+       int fnum = -1;
+       bool ret = true;
+
+       if (!torture_setup_dir(cli, BASEDIR)) {
+               return false;
+       }
+
+       /* reasonable default parameters */
+       io.generic.level = RAW_OPEN_NTCREATEX;
+       io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
+       io.ntcreatex.in.root_fid.fnum = 0;
+       io.ntcreatex.in.alloc_size = 0;
+       io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
+       io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_READONLY;
+       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 = fname;
+
+       /* Create the readonly file. */
+
+       status = smb_raw_open(cli->tree, tctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       fnum = io.ntcreatex.out.file.fnum;
+
+       CHECK_VAL(io.ntcreatex.out.oplock_level, 0);
+       io.ntcreatex.in.create_options = 0;
+       CHECK_VAL(io.ntcreatex.out.create_action, NTCREATEX_ACTION_CREATED);
+       CHECK_ALL_INFO(io.ntcreatex.out.attrib, attrib);
+       smbcli_close(cli->tree, fnum);
+
+       /* Now try and open for delete only - should succeed. */
+       io.ntcreatex.in.access_mask = SEC_STD_DELETE;
+       io.ntcreatex.in.file_attr = 0;
+       io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE;
+       io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
+       status = smb_raw_open(cli->tree, tctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+
+       smbcli_unlink(cli->tree, fname);
+
+done:
+       smbcli_close(cli->tree, fnum);
+       smbcli_deltree(cli->tree, BASEDIR);
+
+       return ret;
+}
+
+/*
+  test chained RAW_OPEN_NTCREATEX_READX
+  Send chained NTCREATEX_READX on a file that doesn't exist, then create
+  the file and try again.
+*/
+static bool test_chained_ntcreatex_readx(struct torture_context *tctx, struct smbcli_state *cli)
+{
+       TALLOC_CTX *mem_ctx = talloc_new(tctx);
+       union smb_open io;
+       const char *fname = BASEDIR "\\torture_chained.txt";
+       NTSTATUS status;
+       int fnum = -1;
        bool ret = true;
+       const char *buf = "test";
+       char buf2[4];
 
        if (!torture_setup_dir(cli, BASEDIR)) {
                return false;
        }
 
-       ret &= test_ntcreatex_brlocked(cli, torture);
-       ret &= test_open(cli, torture);
-       ret &= test_raw_open_multi();
-       ret &= test_openx(cli, torture);
-       ret &= test_ntcreatex(cli, torture);
-       ret &= test_nttrans_create(cli, torture);
-       ret &= test_t2open(cli, torture);
-       ret &= test_mknew(cli, torture);
-       ret &= test_create(cli, torture);
-       ret &= test_ctemp(cli, torture);
-       ret &= test_chained(cli, torture);
-       ret &= test_no_leading_slash(cli, torture);
-
-       smb_raw_exit(cli->session);
+       torture_comment(tctx, "Checking RAW_NTCREATEX_READX chained on "
+                             "non-existant file \n");
+
+       /* ntcreatex parameters */
+       io.generic.level = RAW_OPEN_NTCREATEX_READX;
+       io.ntcreatexreadx.in.flags = 0;
+       io.ntcreatexreadx.in.root_fid.fnum = 0;
+       io.ntcreatexreadx.in.access_mask = SEC_FILE_READ_DATA;
+       io.ntcreatexreadx.in.alloc_size = 0;
+       io.ntcreatexreadx.in.file_attr = FILE_ATTRIBUTE_NORMAL;
+       io.ntcreatexreadx.in.share_access = NTCREATEX_SHARE_ACCESS_READ |
+               NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE;
+       io.ntcreatexreadx.in.open_disposition = NTCREATEX_DISP_OPEN;
+       io.ntcreatexreadx.in.create_options = 0;
+       io.ntcreatexreadx.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION;
+       io.ntcreatexreadx.in.security_flags = 0;
+       io.ntcreatexreadx.in.fname = fname;
+
+       /* readx parameters */
+       io.ntcreatexreadx.in.offset = 0;
+       io.ntcreatexreadx.in.mincnt = sizeof(buf);
+       io.ntcreatexreadx.in.maxcnt = sizeof(buf);
+       io.ntcreatexreadx.in.remaining = 0;
+       io.ntcreatexreadx.out.data = (uint8_t *)buf2;
+
+       /* try to open the non-existant file */
+       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
+       fnum = io.ntcreatexreadx.out.file.fnum;
+
+       smbcli_close(cli->tree, fnum);
+       smbcli_unlink(cli->tree, fname);
+
+       torture_comment(tctx, "Checking RAW_NTCREATEX_READX chained on "
+                             "existing file \n");
+
+       fnum = create_complex_file(cli, mem_ctx, fname);
+       smbcli_write(cli->tree, fnum, 0, buf, 0, sizeof(buf));
+       smbcli_close(cli->tree, fnum);
+
+       status = smb_raw_open(cli->tree, mem_ctx, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       fnum = io.ntcreatexreadx.out.file.fnum;
+
+       if (memcmp(buf, buf2, sizeof(buf)) != 0) {
+               torture_result(tctx, TORTURE_FAIL,
+                       "(%s): wrong data in reply buffer\n", __location__);
+               ret = false;
+       }
+
+done:
+       smbcli_close(cli->tree, fnum);
        smbcli_deltree(cli->tree, BASEDIR);
+       talloc_free(mem_ctx);
 
        return ret;
 }
+
+static bool test_ntcreatex_opendisp_dir(struct torture_context *tctx,
+                                       struct smbcli_state *cli)
+{
+       const char *dname = BASEDIR "\\torture_ntcreatex_opendisp_dir";
+       NTSTATUS status;
+       bool ret = true;
+       int i;
+       struct {
+               uint32_t open_disp;
+               bool dir_exists;
+               NTSTATUS correct_status;
+       } open_funcs_dir[] = {
+               { NTCREATEX_DISP_SUPERSEDE,     true,  NT_STATUS_INVALID_PARAMETER },
+               { NTCREATEX_DISP_SUPERSEDE,     false, NT_STATUS_INVALID_PARAMETER },
+               { NTCREATEX_DISP_OPEN,          true,  NT_STATUS_OK },
+               { NTCREATEX_DISP_OPEN,          false, NT_STATUS_OBJECT_NAME_NOT_FOUND },
+               { NTCREATEX_DISP_CREATE,        true,  NT_STATUS_OBJECT_NAME_COLLISION },
+               { NTCREATEX_DISP_CREATE,        false, NT_STATUS_OK },
+               { NTCREATEX_DISP_OPEN_IF,       true,  NT_STATUS_OK },
+               { NTCREATEX_DISP_OPEN_IF,       false, NT_STATUS_OK },
+               { NTCREATEX_DISP_OVERWRITE,     true,  NT_STATUS_INVALID_PARAMETER },
+               { NTCREATEX_DISP_OVERWRITE,     false, NT_STATUS_INVALID_PARAMETER },
+               { NTCREATEX_DISP_OVERWRITE_IF,  true,  NT_STATUS_INVALID_PARAMETER },
+               { NTCREATEX_DISP_OVERWRITE_IF,  false, NT_STATUS_INVALID_PARAMETER },
+               { 6,                            true,  NT_STATUS_INVALID_PARAMETER },
+               { 6,                            false, NT_STATUS_INVALID_PARAMETER },
+       };
+       union smb_open io;
+
+       ZERO_STRUCT(io);
+       io.generic.level = RAW_OPEN_NTCREATEX;
+       io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
+       io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
+       io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
+       io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
+       io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
+       io.ntcreatex.in.fname = dname;
+
+       if (!torture_setup_dir(cli, BASEDIR)) {
+               return false;
+       }
+
+       smbcli_rmdir(cli->tree, dname);
+       smbcli_unlink(cli->tree, dname);
+
+       /* test the open disposition for directories */
+       torture_comment(tctx, "Testing open dispositions for directories...\n");
+
+       for (i=0; i<ARRAY_SIZE(open_funcs_dir); i++) {
+               if (open_funcs_dir[i].dir_exists) {
+                       status = smbcli_mkdir(cli->tree, dname);
+                       if (!NT_STATUS_IS_OK(status)) {
+                               torture_result(tctx, TORTURE_FAIL,
+                                       "(%s): Failed to make directory "
+                                       "%s - %s\n", __location__, dname,
+                                       smbcli_errstr(cli->tree));
+                               ret = false;
+                               goto done;
+                       }
+               }
+
+               io.ntcreatex.in.open_disposition = open_funcs_dir[i].open_disp;
+               status = smb_raw_open(cli->tree, tctx, &io);
+               if (!NT_STATUS_EQUAL(status, open_funcs_dir[i].correct_status)) {
+                       torture_result(tctx, TORTURE_FAIL,
+                               "(%s) incorrect status %s should be %s "
+                               "(i=%d dir_exists=%d open_disp=%d)\n",
+                               __location__, nt_errstr(status),
+                               nt_errstr(open_funcs_dir[i].correct_status),
+                               i, (int)open_funcs_dir[i].dir_exists,
+                               (int)open_funcs_dir[i].open_disp);
+                       ret = false;
+               }
+               if (NT_STATUS_IS_OK(status) || open_funcs_dir[i].dir_exists) {
+                       smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
+                       smbcli_rmdir(cli->tree, dname);
+               }
+       }
+
+done:
+       smbcli_deltree(cli->tree, BASEDIR);
+
+       return ret;
+}
+
+/**
+ * Test what happens when trying to open a file with directory parameters and
+ * vice-versa.  Also test that NTCREATEX_OPTIONS_DIRECTORY is treated as
+ * mandatory and FILE_ATTRIBUTE_DIRECTORY is advisory for directory
+ * creation/opening.
+ */
+static bool test_ntcreatexdir(struct torture_context *tctx,
+    struct smbcli_state *cli)
+{
+       union smb_open io;
+       const char *fname = BASEDIR "\\torture_ntcreatex.txt";
+       const char *dname = BASEDIR "\\torture_ntcreatex_dir";
+       NTSTATUS status;
+       int i;
+
+       struct {
+               uint32_t open_disp;
+               uint32_t file_attr;
+               uint32_t create_options;
+               NTSTATUS correct_status;
+       } open_funcs[] = {
+               { NTCREATEX_DISP_SUPERSEDE,     0, NTCREATEX_OPTIONS_DIRECTORY,
+                 NT_STATUS_INVALID_PARAMETER },
+               { NTCREATEX_DISP_OPEN,          0, NTCREATEX_OPTIONS_DIRECTORY,
+                 NT_STATUS_OBJECT_NAME_NOT_FOUND },
+               { NTCREATEX_DISP_CREATE,        0, NTCREATEX_OPTIONS_DIRECTORY,
+                 NT_STATUS_OK },
+               { NTCREATEX_DISP_OPEN_IF,       0, NTCREATEX_OPTIONS_DIRECTORY,
+                 NT_STATUS_OK },
+               { NTCREATEX_DISP_OVERWRITE,     0, NTCREATEX_OPTIONS_DIRECTORY,
+                 NT_STATUS_INVALID_PARAMETER },
+               { NTCREATEX_DISP_OVERWRITE_IF,  0, NTCREATEX_OPTIONS_DIRECTORY,
+                 NT_STATUS_INVALID_PARAMETER },
+               { NTCREATEX_DISP_SUPERSEDE,     FILE_ATTRIBUTE_DIRECTORY, 0,
+                 NT_STATUS_OK },
+               { NTCREATEX_DISP_OPEN,          FILE_ATTRIBUTE_DIRECTORY, 0,
+                 NT_STATUS_OBJECT_NAME_NOT_FOUND },
+               { NTCREATEX_DISP_CREATE,        FILE_ATTRIBUTE_DIRECTORY, 0,
+                 NT_STATUS_OK },
+               { NTCREATEX_DISP_OPEN_IF,       FILE_ATTRIBUTE_DIRECTORY, 0,
+                 NT_STATUS_OK },
+               { NTCREATEX_DISP_OVERWRITE,     FILE_ATTRIBUTE_DIRECTORY, 0,
+                 NT_STATUS_OBJECT_NAME_NOT_FOUND },
+               { NTCREATEX_DISP_OVERWRITE_IF,  FILE_ATTRIBUTE_DIRECTORY, 0,
+                 NT_STATUS_OK },
+
+       };
+
+       if (!torture_setup_dir(cli, BASEDIR)) {
+               return false;
+       }
+
+       /* setup some base params. */
+       io.generic.level = RAW_OPEN_NTCREATEX;
+       io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
+       io.ntcreatex.in.root_fid.fnum = 0;
+       io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
+       io.ntcreatex.in.alloc_size = 0;
+       io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
+       io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
+       io.ntcreatex.in.security_flags = 0;
+       io.ntcreatex.in.fname = fname;
+
+       /*
+        * Test the validity checking for create dispositions, which is done
+        * against the requested parameters rather than what's actually on
+        * disk.
+        */
+       for (i=0; i<ARRAY_SIZE(open_funcs); i++) {
+               io.ntcreatex.in.open_disposition = open_funcs[i].open_disp;
+               io.ntcreatex.in.file_attr = open_funcs[i].file_attr;
+               io.ntcreatex.in.create_options = open_funcs[i].create_options;
+               status = smb_raw_open(cli->tree, tctx, &io);
+               if (!NT_STATUS_EQUAL(status, open_funcs[i].correct_status)) {
+                       torture_result(tctx, TORTURE_FAIL,
+                               "(%s) incorrect status %s should be %s "
+                               "(i=%d open_disp=%d)\n",
+                               __location__, nt_errstr(status),
+                               nt_errstr(open_funcs[i].correct_status),
+                               i, (int)open_funcs[i].open_disp);
+                       return false;
+               }
+               /* Close and delete the file. */
+               if (NT_STATUS_IS_OK(status)) {
+                       if (open_funcs[i].create_options != 0) {
+                               /* out attrib should be a directory. */
+                               torture_assert_int_equal(tctx,
+                                   io.ntcreatex.out.attrib,
+                                   FILE_ATTRIBUTE_DIRECTORY, "should have "
+                                   "created a directory");
+
+                               smbcli_close(cli->tree,
+                                   io.ntcreatex.out.file.fnum);
+
+                               /* Make sure unlink fails. */
+                               status = smbcli_unlink(cli->tree, fname);
+                               torture_assert_ntstatus_equal(tctx, status,
+                                   NT_STATUS_FILE_IS_A_DIRECTORY,
+                                   "unlink should fail for a directory");
+
+                               status = smbcli_rmdir(cli->tree, fname);
+                               torture_assert_ntstatus_ok(tctx, status,
+                                   "rmdir failed");
+                       } else {
+                               torture_assert_int_equal(tctx,
+                                   io.ntcreatex.out.attrib,
+                                   FILE_ATTRIBUTE_ARCHIVE, "should not have "
+                                   "created a directory");
+
+                               smbcli_close(cli->tree,
+                                   io.ntcreatex.out.file.fnum);
+
+                               /* Make sure rmdir fails. */
+                               status = smbcli_rmdir(cli->tree, fname);
+                               torture_assert_ntstatus_equal(tctx, status,
+                                   NT_STATUS_NOT_A_DIRECTORY,
+                                   "rmdir should fail for a file");
+
+                               status = smbcli_unlink(cli->tree, fname);
+                               torture_assert_ntstatus_ok(tctx, status,
+                                   "unlink failed");
+                       }
+               }
+       }
+
+       /* Create a file. */
+       io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
+       io.ntcreatex.in.create_options = 0;
+       io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
+       status = smb_raw_open(cli->tree, tctx, &io);
+       torture_assert_ntstatus_ok(tctx, status, "Failed to create file.");
+       smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
+
+       /* Try and open the file with file_attr_dir and check the error. */
+       io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
+       io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
+
+       status = smb_raw_open(cli->tree, tctx, &io);
+       torture_assert_ntstatus_ok(tctx, status, "FILE_ATTRIBUTE_DIRECTORY "
+           "doesn't produce a hard failure.");
+       smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
+
+       /* Try and open file with createx_option_dir and check the error. */
+       io.ntcreatex.in.file_attr = 0;
+       io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
+
+       status = smb_raw_open(cli->tree, tctx, &io);
+       torture_assert_ntstatus_equal(tctx, status, NT_STATUS_NOT_A_DIRECTORY,
+           "NTCREATEX_OPTIONS_DIRECTORY will a file from being opened.");
+       smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
+
+       /* Delete the file and move onto directory testing. */
+       smbcli_unlink(cli->tree, fname);
+
+       /* Now try some tests on a directory. */
+       io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
+       io.ntcreatex.in.file_attr = 0;
+       io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY;
+       io.ntcreatex.in.fname = dname;
+
+       status = smb_raw_open(cli->tree, tctx, &io);
+       torture_assert_ntstatus_ok(tctx, status, "Failed to create dir.");
+
+       /* out attrib should be a directory. */
+       torture_assert_int_equal(tctx, io.ntcreatex.out.attrib,
+           FILE_ATTRIBUTE_DIRECTORY, "should have created a directory");
+
+       smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
+
+       /* Try and open it with normal attr and check the error. */
+       io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
+       io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN;
+
+       status = smb_raw_open(cli->tree, tctx, &io);
+       torture_assert_ntstatus_ok(tctx, status, "FILE_ATTRIBUTE_NORMAL "
+           "doesn't produce a hard failure.");
+       smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
+
+       /* Try and open it with file create_options and check the error. */
+       io.ntcreatex.in.file_attr = 0;
+       io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_NON_DIRECTORY_FILE;
+
+       status = smb_raw_open(cli->tree, tctx, &io);
+       torture_assert_ntstatus_equal(tctx, status,
+           NT_STATUS_FILE_IS_A_DIRECTORY,
+           "NTCREATEX_OPTIONS_NON_DIRECTORY_FILE should be returned ");
+       smbcli_close(cli->tree, io.ntcreatex.out.file.fnum);
+
+       smbcli_deltree(cli->tree, BASEDIR);
+
+       return true;
+}
+
+/* basic testing of all RAW_OPEN_* calls
+*/
+struct torture_suite *torture_raw_open(TALLOC_CTX *mem_ctx)
+{
+       struct torture_suite *suite = torture_suite_create(mem_ctx, "open");
+
+       torture_suite_add_1smb_test(suite, "brlocked", test_ntcreatex_brlocked);
+       torture_suite_add_1smb_test(suite, "open", test_open);
+       torture_suite_add_1smb_test(suite, "open-multi", test_raw_open_multi);
+       torture_suite_add_1smb_test(suite, "openx", test_openx);
+       torture_suite_add_1smb_test(suite, "ntcreatex", test_ntcreatex);
+       torture_suite_add_1smb_test(suite, "nttrans-create", test_nttrans_create);
+       torture_suite_add_1smb_test(suite, "t2open", test_t2open);
+       torture_suite_add_1smb_test(suite, "mknew", test_mknew);
+       torture_suite_add_1smb_test(suite, "create", test_create);
+       torture_suite_add_1smb_test(suite, "ctemp", test_ctemp);
+       torture_suite_add_1smb_test(suite, "chained-openx", test_chained);
+       torture_suite_add_1smb_test(suite, "chained-ntcreatex", test_chained_ntcreatex_readx);
+       torture_suite_add_1smb_test(suite, "no-leading-slash", test_no_leading_slash);
+       torture_suite_add_1smb_test(suite, "openx-over-dir", test_openx_over_dir);
+       torture_suite_add_1smb_test(suite, "open-for-delete", test_open_for_delete);
+       torture_suite_add_1smb_test(suite, "opendisp-dir", test_ntcreatex_opendisp_dir);
+       torture_suite_add_1smb_test(suite, "ntcreatedir", test_ntcreatexdir);
+
+       return suite;
+}