s4 torture: Add lockread_supported based off of CAP_LOCK_AND_READ
[samba.git] / source4 / torture / raw / read.c
index c8420c279eb43b5f19ac5150ddae96589d90baab..efdd04045196a05d0d174f0329f9b0d5c4646bd7 100644 (file)
 */
 
 #include "includes.h"
-#include "torture/torture.h"
 #include "libcli/raw/libcliraw.h"
-#include "libcli/raw/raw_proto.h"
 #include "system/time.h"
 #include "system/filesys.h"
 #include "libcli/libcli.h"
 #include "torture/util.h"
-#include "param/param.h"
 
 #define CHECK_STATUS(status, correct) do { \
        if (!NT_STATUS_EQUAL(status, correct)) { \
@@ -97,13 +94,18 @@ static bool test_read(struct torture_context *tctx, struct smbcli_state *cli)
 
        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;
        }
 
        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));
@@ -222,6 +224,11 @@ static bool test_lockread(struct torture_context *tctx,
        const char *test_data = "TEST DATA";
        uint_t seed = time(NULL);
 
+       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)) {
@@ -460,11 +467,50 @@ static bool test_readx(struct torture_context *tctx, struct smbcli_state *cli)
                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.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;
@@ -483,8 +529,9 @@ static bool test_readx(struct torture_context *tctx, struct smbcli_state *cli)
        CHECK_STATUS(status, NT_STATUS_OK);
        CHECK_VALUE(io.readx.out.remaining, 0xFFFF);
        CHECK_VALUE(io.readx.out.compaction_mode, 0);
-       if (torture_setting_bool(tctx, "samba3", false)) {
-               printf("SAMBA3: large read extension\n");
+       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);
@@ -527,8 +574,9 @@ static bool test_readx(struct torture_context *tctx, struct smbcli_state *cli)
                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)) {
-                       printf("SAMBA3: large read extension\n");
+               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);
@@ -537,12 +585,15 @@ static bool test_readx(struct torture_context *tctx, struct smbcli_state *cli)
                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)) {
-                       printf("SAMBA3: large read extension\n");
+               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");
@@ -606,6 +657,11 @@ static bool test_readbraw(struct torture_context *tctx,
        const char *test_data = "TEST DATA";
        uint_t seed = time(NULL);
 
+       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)) {
@@ -789,7 +845,7 @@ static bool test_read_for_execute(struct torture_context *tctx,
        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;
@@ -820,7 +876,7 @@ static bool test_read_for_execute(struct torture_context *tctx,
 
        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;
@@ -867,7 +923,7 @@ static bool test_read_for_execute(struct torture_context *tctx,
 
        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;