s4 torture: Add lockread_supported based off of CAP_LOCK_AND_READ
[samba.git] / source4 / torture / raw / read.c
index 81955ecafac4af93c8f54f2c35c01429988256db..efdd04045196a05d0d174f0329f9b0d5c4646bd7 100644 (file)
@@ -5,7 +5,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
-#include "torture/torture.h"
 #include "libcli/raw/libcliraw.h"
 #include "system/time.h"
 #include "system/filesys.h"
@@ -30,7 +28,7 @@
        if (!NT_STATUS_EQUAL(status, correct)) { \
                printf("(%s) Incorrect status %s - should be %s\n", \
                       __location__, nt_errstr(status), nt_errstr(correct)); \
-               ret = False; \
+               ret = false; \
                goto done; \
        }} while (0)
 
        if ((v) != (correct)) { \
                printf("(%s) Incorrect value %s=%ld - should be %ld\n", \
                       __location__, #v, (long)v, (long)correct); \
-               ret = False; \
+               ret = false; \
                goto done; \
        }} while (0)
 
 #define CHECK_BUFFER(buf, seed, len) do { \
        if (!check_buffer(buf, seed, len, __LINE__)) { \
-               ret = False; \
+               ret = false; \
                goto done; \
        }} while (0)
 
@@ -64,7 +62,7 @@ static void setup_buffer(uint8_t *buf, uint_t seed, int len)
 /*
   check a random buffer based on a seed
 */
-static BOOL check_buffer(uint8_t *buf, uint_t seed, int len, int line)
+static bool check_buffer(uint8_t *buf, uint_t seed, int len, int line)
 {
        int i;
        srandom(seed);
@@ -73,20 +71,20 @@ static BOOL check_buffer(uint8_t *buf, uint_t seed, int len, int line)
                if (buf[i] != v) {
                        printf("Buffer incorrect at line %d! ofs=%d v1=0x%x v2=0x%x\n", 
                               line, i, buf[i], v);
-                       return False;
+                       return false;
                }
        }
-       return True;
+       return true;
 }
 
 /*
   test read ops
 */
-static BOOL test_read(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_read(struct torture_context *tctx, struct smbcli_state *cli)
 {
        union smb_read io;
        NTSTATUS status;
-       BOOL ret = True;
+       bool ret = true;
        int fnum;
        uint8_t *buf;
        const int maxsize = 90000;
@@ -94,19 +92,24 @@ static BOOL test_read(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        const char *test_data = "TEST DATA";
        uint_t seed = time(NULL);
 
-       buf = talloc_zero_size(mem_ctx, maxsize);
+       buf = talloc_zero_array(tctx, uint8_t, maxsize);
+
+       if (!torture_setting_bool(tctx, "read_support", true)) {
+               printf("server refuses to support READ\n");
+               return true;
+       }
 
        if (!torture_setup_dir(cli, BASEDIR)) {
-               return False;
+               return false;
        }
 
        printf("Testing RAW_READ_READ\n");
        io.generic.level = RAW_READ_READ;
-       
+
        fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
        if (fnum == -1) {
                printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -144,7 +147,7 @@ static BOOL test_read(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        CHECK_STATUS(status, NT_STATUS_OK);
        CHECK_VALUE(io.read.out.nread, strlen(test_data));
        if (memcmp(buf, test_data, strlen(test_data)) != 0) {
-               ret = False;
+               ret = false;
                printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data, buf);
                goto done;
        }
@@ -156,17 +159,19 @@ static BOOL test_read(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        CHECK_STATUS(status, NT_STATUS_OK);
        CHECK_VALUE(io.read.out.nread, strlen(test_data)-1);
        if (memcmp(buf, test_data+1, strlen(test_data)-1) != 0) {
-               ret = False;
+               ret = false;
                printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data+1, buf);
                goto done;
        }
 
-       printf("Trying max offset\n");
-       io.read.in.offset = ~0;
-       io.read.in.count = strlen(test_data);
-       status = smb_raw_read(cli->tree, &io);
-       CHECK_STATUS(status, NT_STATUS_OK);
-       CHECK_VALUE(io.read.out.nread, 0);
+       if (cli->transport->negotiate.capabilities & CAP_LARGE_FILES) {
+               printf("Trying max offset\n");
+               io.read.in.offset = ~0;
+               io.read.in.count = strlen(test_data);
+               status = smb_raw_read(cli->tree, &io);
+               CHECK_STATUS(status, NT_STATUS_OK);
+               CHECK_VALUE(io.read.out.nread, 0);
+       }
 
        setup_buffer(buf, seed, maxsize);
        smbcli_write(cli->tree, fnum, 0, buf, 0, maxsize);
@@ -184,7 +189,7 @@ static BOOL test_read(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        cli->session->pid++;
        if (NT_STATUS_IS_ERR(smbcli_lock(cli->tree, fnum, 103, 1, 0, WRITE_LOCK))) {
                printf("Failed to lock file at %d\n", __LINE__);
-               ret = False;
+               ret = false;
                goto done;
        }
        cli->session->pid--;
@@ -206,11 +211,12 @@ done:
 /*
   test lockread ops
 */
-static BOOL test_lockread(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_lockread(struct torture_context *tctx, 
+                                                 struct smbcli_state *cli)
 {
        union smb_read io;
        NTSTATUS status;
-       BOOL ret = True;
+       bool ret = true;
        int fnum;
        uint8_t *buf;
        const int maxsize = 90000;
@@ -218,10 +224,15 @@ static BOOL test_lockread(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        const char *test_data = "TEST DATA";
        uint_t seed = time(NULL);
 
-       buf = talloc_zero_size(mem_ctx, maxsize);
+       if (!cli->transport->negotiate.lockread_supported) {
+               printf("Server does not support lockread - skipping\n");
+               return true;
+       }
+
+       buf = talloc_zero_array(tctx, uint8_t, maxsize);
 
        if (!torture_setup_dir(cli, BASEDIR)) {
-               return False;
+               return false;
        }
 
        printf("Testing RAW_READ_LOCKREAD\n");
@@ -230,7 +241,7 @@ static BOOL test_lockread(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
        if (fnum == -1) {
                printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -280,7 +291,7 @@ static BOOL test_lockread(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        CHECK_STATUS(status, NT_STATUS_OK);
        CHECK_VALUE(io.lockread.out.nread, strlen(test_data));
        if (memcmp(buf, test_data, strlen(test_data)) != 0) {
-               ret = False;
+               ret = false;
                printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data, buf);
                goto done;
        }
@@ -296,17 +307,19 @@ static BOOL test_lockread(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        CHECK_VALUE(io.lockread.out.nread, strlen(test_data)-1);
        if (memcmp(buf, test_data+1, strlen(test_data)-1) != 0) {
-               ret = False;
+               ret = false;
                printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data+1, buf);
                goto done;
        }
 
-       printf("Trying max offset\n");
-       io.lockread.in.offset = ~0;
-       io.lockread.in.count = strlen(test_data);
-       status = smb_raw_read(cli->tree, &io);
-       CHECK_STATUS(status, NT_STATUS_OK);
-       CHECK_VALUE(io.lockread.out.nread, 0);
+       if (cli->transport->negotiate.capabilities & CAP_LARGE_FILES) {
+               printf("Trying max offset\n");
+               io.lockread.in.offset = ~0;
+               io.lockread.in.count = strlen(test_data);
+               status = smb_raw_read(cli->tree, &io);
+               CHECK_STATUS(status, NT_STATUS_OK);
+               CHECK_VALUE(io.lockread.out.nread, 0);
+       }
 
        setup_buffer(buf, seed, maxsize);
        smbcli_write(cli->tree, fnum, 0, buf, 0, maxsize);
@@ -328,7 +341,7 @@ static BOOL test_lockread(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        cli->session->pid++;
        if (NT_STATUS_IS_ERR(smbcli_lock(cli->tree, fnum, 103, 1, 0, WRITE_LOCK))) {
                printf("Failed to lock file at %d\n", __LINE__);
-               ret = False;
+               ret = false;
                goto done;
        }
        cli->session->pid--;
@@ -349,11 +362,11 @@ done:
 /*
   test readx ops
 */
-static BOOL test_readx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_readx(struct torture_context *tctx, struct smbcli_state *cli)
 {
        union smb_read io;
        NTSTATUS status;
-       BOOL ret = True;
+       bool ret = true;
        int fnum;
        uint8_t *buf;
        const int maxsize = 90000;
@@ -361,10 +374,10 @@ static BOOL test_readx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        const char *test_data = "TEST DATA";
        uint_t seed = time(NULL);
 
-       buf = talloc_zero_size(mem_ctx, maxsize);
+       buf = talloc_zero_array(tctx, uint8_t, maxsize);
 
        if (!torture_setup_dir(cli, BASEDIR)) {
-               return False;
+               return false;
        }
 
        printf("Testing RAW_READ_READX\n");
@@ -372,7 +385,7 @@ static BOOL test_readx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
        if (fnum == -1) {
                printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -383,7 +396,7 @@ static BOOL test_readx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        io.readx.in.maxcnt = 1;
        io.readx.in.offset = 0;
        io.readx.in.remaining = 0;
-       io.readx.in.read_for_execute = False;
+       io.readx.in.read_for_execute = false;
        io.readx.out.data = buf;
        status = smb_raw_read(cli->tree, &io);
 
@@ -413,7 +426,7 @@ static BOOL test_readx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        io.readx.in.file.fnum = fnum;
        io.readx.in.offset = 0;
        io.readx.in.remaining = 0;
-       io.readx.in.read_for_execute = False;
+       io.readx.in.read_for_execute = false;
        io.readx.in.mincnt = strlen(test_data);
        io.readx.in.maxcnt = strlen(test_data);
        status = smb_raw_read(cli->tree, &io);
@@ -422,7 +435,7 @@ static BOOL test_readx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
        CHECK_VALUE(io.readx.out.compaction_mode, 0);
        if (memcmp(buf, test_data, strlen(test_data)) != 0) {
-               ret = False;
+               ret = false;
                printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data, buf);
                goto done;
        }
@@ -437,26 +450,67 @@ static BOOL test_readx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
        CHECK_VALUE(io.readx.out.compaction_mode, 0);
        if (memcmp(buf, test_data+1, strlen(test_data)-1) != 0) {
-               ret = False;
+               ret = false;
                printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data+1, buf);
                goto done;
        }
 
-       printf("Trying max offset\n");
-       io.readx.in.offset = 0xffffffff;
-       io.readx.in.mincnt = strlen(test_data);
-       io.readx.in.maxcnt = strlen(test_data);
+       if (cli->transport->negotiate.capabilities & CAP_LARGE_FILES) {
+               printf("Trying max offset\n");
+               io.readx.in.offset = 0xffffffff;
+               io.readx.in.mincnt = strlen(test_data);
+               io.readx.in.maxcnt = strlen(test_data);
+               status = smb_raw_read(cli->tree, &io);
+               CHECK_STATUS(status, NT_STATUS_OK);
+               CHECK_VALUE(io.readx.out.nread, 0);
+               CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
+               CHECK_VALUE(io.readx.out.compaction_mode, 0);
+       }
+
+       printf("Trying mincnt past EOF\n");
+       memset(buf, 0, maxsize);
+       io.readx.in.offset = 0;
+       io.readx.in.mincnt = 100;
+       io.readx.in.maxcnt = 110;
        status = smb_raw_read(cli->tree, &io);
        CHECK_STATUS(status, NT_STATUS_OK);
-       CHECK_VALUE(io.readx.out.nread, 0);
        CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
        CHECK_VALUE(io.readx.out.compaction_mode, 0);
+       CHECK_VALUE(io.readx.out.nread, strlen(test_data));
+       if (memcmp(buf, test_data, strlen(test_data)) != 0) {
+               ret = false;
+               printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data, buf);
+               goto done;
+       }
+
 
        setup_buffer(buf, seed, maxsize);
        smbcli_write(cli->tree, fnum, 0, buf, 0, maxsize);
        memset(buf, 0, maxsize);
 
-       printf("Trying large read\n");
+       printf("Trying page sized read\n");
+       io.readx.in.offset = 0;
+       io.readx.in.mincnt = 0x1000;
+       io.readx.in.maxcnt = 0x1000;
+       status = smb_raw_read(cli->tree, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
+       CHECK_VALUE(io.readx.out.compaction_mode, 0);
+       CHECK_VALUE(io.readx.out.nread, io.readx.in.maxcnt);
+       CHECK_BUFFER(buf, seed, io.readx.out.nread);
+
+       printf("Trying page + 1 sized read (check alignment)\n");
+       io.readx.in.offset = 0;
+       io.readx.in.mincnt = 0x1001;
+       io.readx.in.maxcnt = 0x1001;
+       status = smb_raw_read(cli->tree, &io);
+       CHECK_STATUS(status, NT_STATUS_OK);
+       CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
+       CHECK_VALUE(io.readx.out.compaction_mode, 0);
+       CHECK_VALUE(io.readx.out.nread, io.readx.in.maxcnt);
+       CHECK_BUFFER(buf, seed, io.readx.out.nread);
+
+       printf("Trying large read (UINT16_MAX)\n");
        io.readx.in.offset = 0;
        io.readx.in.mincnt = 0xFFFF;
        io.readx.in.maxcnt = 0xFFFF;
@@ -475,9 +529,10 @@ static BOOL test_readx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        CHECK_STATUS(status, NT_STATUS_OK);
        CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
        CHECK_VALUE(io.readx.out.compaction_mode, 0);
-       if (lp_parm_bool(-1, "target", "samba3", False)) {
-               printf("SAMBA3: ignore wrong nread[%d] should be [%d]\n",
-                       io.readx.out.nread, 0);
+       if (torture_setting_bool(tctx, "samba3", false) ||
+           torture_setting_bool(tctx, "samba4", false)) {
+               printf("SAMBA: large read extension\n");
+               CHECK_VALUE(io.readx.out.nread, 80000);
        } else {
                CHECK_VALUE(io.readx.out.nread, 0);
        }
@@ -507,11 +562,45 @@ static BOOL test_readx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        CHECK_VALUE(io.readx.out.nread, io.readx.in.maxcnt);
        CHECK_BUFFER(buf, seed, io.readx.out.nread);
 
+       if (cli->transport->negotiate.capabilities & CAP_LARGE_READX) {
+               printf("Trying large readx\n");
+               io.readx.in.offset = 0;
+               io.readx.in.mincnt = 0;
+               io.readx.in.maxcnt = 0x10000 - 1;
+               status = smb_raw_read(cli->tree, &io);
+               CHECK_STATUS(status, NT_STATUS_OK);
+               CHECK_VALUE(io.readx.out.nread, 0xFFFF);
+
+               io.readx.in.maxcnt = 0x10000;
+               status = smb_raw_read(cli->tree, &io);
+               CHECK_STATUS(status, NT_STATUS_OK);
+               if (torture_setting_bool(tctx, "samba3", false) || 
+                   torture_setting_bool(tctx, "samba4", false)) {
+                       printf("SAMBA: large read extension\n");
+                       CHECK_VALUE(io.readx.out.nread, 0x10000);
+               } else {
+                       CHECK_VALUE(io.readx.out.nread, 0);
+               }
+
+               io.readx.in.maxcnt = 0x10001;
+               status = smb_raw_read(cli->tree, &io);
+               CHECK_STATUS(status, NT_STATUS_OK);
+               if (torture_setting_bool(tctx, "samba3", false) ||
+                   torture_setting_bool(tctx, "samba4", false)) {
+                       printf("SAMBA: large read extension\n");
+                       CHECK_VALUE(io.readx.out.nread, 0x10001);
+               } else {
+                       CHECK_VALUE(io.readx.out.nread, 0);
+               }
+       } else {
+               printf("Server does not support the CAP_LARGE_READX extension\n");
+       }
+
        printf("Trying locked region\n");
        cli->session->pid++;
        if (NT_STATUS_IS_ERR(smbcli_lock(cli->tree, fnum, 103, 1, 0, WRITE_LOCK))) {
                printf("Failed to lock file at %d\n", __LINE__);
-               ret = False;
+               ret = false;
                goto done;
        }
        cli->session->pid--;
@@ -522,6 +611,11 @@ static BOOL test_readx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        status = smb_raw_read(cli->tree, &io);
        CHECK_STATUS(status, NT_STATUS_FILE_LOCK_CONFLICT);     
 
+       if (!(cli->transport->negotiate.capabilities & CAP_LARGE_FILES)) {
+               printf("skipping large file tests - CAP_LARGE_FILES not set\n");
+               goto done;
+       }
+
        printf("Trying large offset read\n");
        io.readx.in.offset = ((uint64_t)0x2) << 32;
        io.readx.in.mincnt = 10;
@@ -532,7 +626,7 @@ static BOOL test_readx(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        if (NT_STATUS_IS_ERR(smbcli_lock64(cli->tree, fnum, io.readx.in.offset, 1, 0, WRITE_LOCK))) {
                printf("Failed to lock file at %d\n", __LINE__);
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -550,11 +644,12 @@ done:
 /*
   test readbraw ops
 */
-static BOOL test_readbraw(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_readbraw(struct torture_context *tctx, 
+                                                 struct smbcli_state *cli)
 {
        union smb_read io;
        NTSTATUS status;
-       BOOL ret = True;
+       bool ret = true;
        int fnum;
        uint8_t *buf;
        const int maxsize = 90000;
@@ -562,10 +657,15 @@ static BOOL test_readbraw(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        const char *test_data = "TEST DATA";
        uint_t seed = time(NULL);
 
-       buf = talloc_zero_size(mem_ctx, maxsize);
+       if (!cli->transport->negotiate.readbraw_supported) {
+               printf("Server does not support readbraw - skipping\n");
+               return true;
+       }
+
+       buf = talloc_zero_array(tctx, uint8_t, maxsize);
 
        if (!torture_setup_dir(cli, BASEDIR)) {
-               return False;
+               return false;
        }
 
        printf("Testing RAW_READ_READBRAW\n");
@@ -573,7 +673,7 @@ static BOOL test_readbraw(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        fnum = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
        if (fnum == -1) {
                printf("Failed to create %s - %s\n", fname, smbcli_errstr(cli->tree));
-               ret = False;
+               ret = false;
                goto done;
        }
 
@@ -615,7 +715,7 @@ static BOOL test_readbraw(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        CHECK_STATUS(status, NT_STATUS_OK);
        CHECK_VALUE(io.readbraw.out.nread, strlen(test_data));
        if (memcmp(buf, test_data, strlen(test_data)) != 0) {
-               ret = False;
+               ret = false;
                printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data, buf);
                goto done;
        }
@@ -628,18 +728,20 @@ static BOOL test_readbraw(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        CHECK_STATUS(status, NT_STATUS_OK);
        CHECK_VALUE(io.readbraw.out.nread, strlen(test_data)-1);
        if (memcmp(buf, test_data+1, strlen(test_data)-1) != 0) {
-               ret = False;
+               ret = false;
                printf("incorrect data at %d!? (%s:%s)\n", __LINE__, test_data+1, buf);
                goto done;
        }
 
-       printf("Trying max offset\n");
-       io.readbraw.in.offset = ~0;
-       io.readbraw.in.mincnt = strlen(test_data);
-       io.readbraw.in.maxcnt = strlen(test_data);
-       status = smb_raw_read(cli->tree, &io);
-       CHECK_STATUS(status, NT_STATUS_OK);
-       CHECK_VALUE(io.readbraw.out.nread, 0);
+       if (cli->transport->negotiate.capabilities & CAP_LARGE_FILES) {
+               printf("Trying max offset\n");
+               io.readbraw.in.offset = ~0;
+               io.readbraw.in.mincnt = strlen(test_data);
+               io.readbraw.in.maxcnt = strlen(test_data);
+               status = smb_raw_read(cli->tree, &io);
+               CHECK_STATUS(status, NT_STATUS_OK);
+               CHECK_VALUE(io.readbraw.out.nread, 0);
+       }
 
        setup_buffer(buf, seed, maxsize);
        smbcli_write(cli->tree, fnum, 0, buf, 0, maxsize);
@@ -678,7 +780,7 @@ static BOOL test_readbraw(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        cli->session->pid++;
        if (NT_STATUS_IS_ERR(smbcli_lock(cli->tree, fnum, 103, 1, 0, WRITE_LOCK))) {
                printf("Failed to lock file at %d\n", __LINE__);
-               ret = False;
+               ret = false;
                goto done;
        }
        cli->session->pid--;
@@ -700,14 +802,16 @@ static BOOL test_readbraw(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        CHECK_STATUS(status, NT_STATUS_OK);
        CHECK_VALUE(io.readbraw.out.nread, 0);
 
-       printf("Trying large offset read\n");
-       io.readbraw.in.offset = ((uint64_t)0x2) << 32;
-       io.readbraw.in.mincnt = 10;
-       io.readbraw.in.maxcnt = 10;
-       io.readbraw.in.timeout = 0;
-       status = smb_raw_read(cli->tree, &io);
-       CHECK_STATUS(status, NT_STATUS_OK);
-       CHECK_VALUE(io.readbraw.out.nread, 0);
+       if (cli->transport->negotiate.capabilities & CAP_LARGE_FILES) {
+               printf("Trying large offset read\n");
+               io.readbraw.in.offset = ((uint64_t)0x2) << 32;
+               io.readbraw.in.mincnt = 10;
+               io.readbraw.in.maxcnt = 10;
+               io.readbraw.in.timeout = 0;
+               status = smb_raw_read(cli->tree, &io);
+               CHECK_STATUS(status, NT_STATUS_OK);
+               CHECK_VALUE(io.readbraw.out.nread, 0);
+       }
 
 done:
        smbcli_close(cli->tree, fnum);
@@ -718,29 +822,30 @@ done:
 /*
   test read for execute
 */
-static BOOL test_read_for_execute(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
+static bool test_read_for_execute(struct torture_context *tctx, 
+                                                                 struct smbcli_state *cli)
 {
        union smb_open op;
        union smb_write wr;
        union smb_read rd;
        NTSTATUS status;
-       BOOL ret = True;
-       int fnum;
+       bool ret = true;
+       int fnum=0;
        uint8_t *buf;
        const int maxsize = 900;
        const char *fname = BASEDIR "\\test.txt";
        const uint8_t data[] = "TEST DATA";
 
-       buf = talloc_zero_size(mem_ctx, maxsize);
+       buf = talloc_zero_array(tctx, uint8_t, maxsize);
 
        if (!torture_setup_dir(cli, BASEDIR)) {
-               return False;
+               return false;
        }
 
        printf("Testing RAW_READ_READX with read_for_execute\n");
 
        op.generic.level = RAW_OPEN_NTCREATEX;
-       op.ntcreatex.in.root_fid = 0;
+       op.ntcreatex.in.root_fid.fnum = 0;
        op.ntcreatex.in.flags = 0;
        op.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
        op.ntcreatex.in.create_options = 0;
@@ -751,7 +856,7 @@ static BOOL test_read_for_execute(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        op.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
        op.ntcreatex.in.security_flags = 0;
        op.ntcreatex.in.fname = fname;
-       status = smb_raw_open(cli->tree, mem_ctx, &op);
+       status = smb_raw_open(cli->tree, tctx, &op);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = op.ntcreatex.out.file.fnum;
 
@@ -771,7 +876,7 @@ static BOOL test_read_for_execute(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        printf("open file with SEC_FILE_EXECUTE\n");
        op.generic.level = RAW_OPEN_NTCREATEX;
-       op.ntcreatex.in.root_fid = 0;
+       op.ntcreatex.in.root_fid.fnum = 0;
        op.ntcreatex.in.flags = 0;
        op.ntcreatex.in.access_mask = SEC_FILE_EXECUTE;
        op.ntcreatex.in.create_options = 0;
@@ -782,7 +887,7 @@ static BOOL test_read_for_execute(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        op.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
        op.ntcreatex.in.security_flags = 0;
        op.ntcreatex.in.fname = fname;
-       status = smb_raw_open(cli->tree, mem_ctx, &op);
+       status = smb_raw_open(cli->tree, tctx, &op);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = op.ntcreatex.out.file.fnum;
 
@@ -793,7 +898,7 @@ static BOOL test_read_for_execute(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        rd.readx.in.maxcnt = maxsize;
        rd.readx.in.offset = 0;
        rd.readx.in.remaining = 0;
-       rd.readx.in.read_for_execute = True;
+       rd.readx.in.read_for_execute = true;
        rd.readx.out.data = buf;
        status = smb_raw_read(cli->tree, &rd);
        CHECK_STATUS(status, NT_STATUS_OK);
@@ -808,7 +913,7 @@ static BOOL test_read_for_execute(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        rd.readx.in.maxcnt = maxsize;
        rd.readx.in.offset = 0;
        rd.readx.in.remaining = 0;
-       rd.readx.in.read_for_execute = False;
+       rd.readx.in.read_for_execute = false;
        rd.readx.out.data = buf;
        status = smb_raw_read(cli->tree, &rd);
        CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
@@ -818,7 +923,7 @@ static BOOL test_read_for_execute(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        printf("open file with SEC_FILE_READ_DATA\n");
        op.generic.level = RAW_OPEN_NTCREATEX;
-       op.ntcreatex.in.root_fid = 0;
+       op.ntcreatex.in.root_fid.fnum = 0;
        op.ntcreatex.in.flags = 0;
        op.ntcreatex.in.access_mask = SEC_FILE_READ_DATA;
        op.ntcreatex.in.create_options = 0;
@@ -829,7 +934,7 @@ static BOOL test_read_for_execute(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        op.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
        op.ntcreatex.in.security_flags = 0;
        op.ntcreatex.in.fname = fname;
-       status = smb_raw_open(cli->tree, mem_ctx, &op);
+       status = smb_raw_open(cli->tree, tctx, &op);
        CHECK_STATUS(status, NT_STATUS_OK);
        fnum = op.ntcreatex.out.file.fnum;
 
@@ -840,7 +945,7 @@ static BOOL test_read_for_execute(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        rd.readx.in.maxcnt = maxsize;
        rd.readx.in.offset = 0;
        rd.readx.in.remaining = 0;
-       rd.readx.in.read_for_execute = True;
+       rd.readx.in.read_for_execute = true;
        rd.readx.out.data = buf;
        status = smb_raw_read(cli->tree, &rd);
        CHECK_STATUS(status, NT_STATUS_OK);
@@ -855,7 +960,7 @@ static BOOL test_read_for_execute(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        rd.readx.in.maxcnt = maxsize;
        rd.readx.in.offset = 0;
        rd.readx.in.remaining = 0;
-       rd.readx.in.read_for_execute = False;
+       rd.readx.in.read_for_execute = false;
        rd.readx.out.data = buf;
        status = smb_raw_read(cli->tree, &rd);
        CHECK_STATUS(status, NT_STATUS_OK);
@@ -873,25 +978,16 @@ done:
 /* 
    basic testing of read calls
 */
-BOOL torture_raw_read(struct torture_context *torture)
+struct torture_suite *torture_raw_read(TALLOC_CTX *mem_ctx)
 {
-       struct smbcli_state *cli;
-       BOOL ret = True;
-       TALLOC_CTX *mem_ctx;
+       struct torture_suite *suite = torture_suite_create(mem_ctx, "READ");
 
-       if (!torture_open_connection(&cli)) {
-               return False;
-       }
-
-       mem_ctx = talloc_init("torture_raw_read");
+       torture_suite_add_1smb_test(suite, "read", test_read);
+       torture_suite_add_1smb_test(suite, "readx", test_readx);
+       torture_suite_add_1smb_test(suite, "lockread", test_lockread);
+       torture_suite_add_1smb_test(suite, "readbraw", test_readbraw);
+       torture_suite_add_1smb_test(suite, "read for execute", 
+                                                               test_read_for_execute);
 
-       ret &= test_read(cli, mem_ctx);
-       ret &= test_readx(cli, mem_ctx);
-       ret &= test_lockread(cli, mem_ctx);
-       ret &= test_readbraw(cli, mem_ctx);
-       ret &= test_read_for_execute(cli, mem_ctx);
-
-       torture_close_connection(cli);
-       talloc_free(mem_ctx);
-       return ret;
+       return suite;
 }