]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3: torture: Add test for cli_ftruncate calling cli_smb2_ftruncate.
authorJeremy Allison <jra@samba.org>
Tue, 3 Jan 2017 23:37:03 +0000 (15:37 -0800)
committerKarolin Seeger <kseeger@samba.org>
Mon, 9 Jan 2017 13:18:46 +0000 (14:18 +0100)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12479

Back-port from cherry pick from commit b92cac857823ac2d29133fba2fde57cf58805b45)

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Uri Simchoni <uri@samba.org>
Autobuild-User(v4-4-test): Karolin Seeger <kseeger@samba.org>
Autobuild-Date(v4-4-test): Mon Jan  9 14:18:47 CET 2017 on sn-devel-144

source3/selftest/tests.py
source3/torture/proto.h
source3/torture/test_smb2.c
source3/torture/torture.c

index d2b2009125b26c4a16e023a527be6f292d43252c..e389fae9ae41e420ee90129bc8113e6935ffef7b 100755 (executable)
@@ -53,7 +53,7 @@ tests = ["FDPASS", "LOCK1", "LOCK2", "LOCK3", "LOCK4", "LOCK5", "LOCK6", "LOCK7"
         "CHAIN3",
         "GETADDRINFO", "UID-REGRESSION-TEST", "SHORTNAME-TEST",
         "CASE-INSENSITIVE-CREATE", "SMB2-BASIC", "NTTRANS-FSCTL", "SMB2-NEGPROT",
-        "SMB2-SESSION-REAUTH", "SMB2-SESSION-RECONNECT",
+        "SMB2-SESSION-REAUTH", "SMB2-SESSION-RECONNECT", "SMB2-FTRUNCATE",
         "CLEANUP1",
         "CLEANUP2",
         "CLEANUP4",
index fc7c33f2d231ebcdd2865d6c75d571000834539e..32ad8231b49bb8c6012bd8a1bb1b105d74b6869b 100644 (file)
@@ -98,6 +98,7 @@ bool run_smb2_session_reconnect(int dummy);
 bool run_smb2_tcon_dependence(int dummy);
 bool run_smb2_multi_channel(int dummy);
 bool run_smb2_session_reauth(int dummy);
+bool run_smb2_ftruncate(int dummy);
 bool run_chain3(int dummy);
 bool run_local_conv_auth_info(int dummy);
 bool run_local_sprintf_append(int dummy);
index 6871f4c22721d1243eaa168852a184637bfd5857..4db8c772b5308d2dbe7c812281abed0b497e7f3e 100644 (file)
@@ -27,6 +27,7 @@
 #include "auth/gensec/gensec.h"
 #include "auth_generic.h"
 #include "../librpc/ndr/libndr.h"
+#include "libsmb/clirap.h"
 
 extern fstring host, workgroup, share, password, username, myname;
 
@@ -1961,3 +1962,162 @@ bool run_smb2_session_reauth(int dummy)
 
        return true;
 }
+
+static NTSTATUS check_size(struct cli_state *cli,
+                               uint16_t fnum,
+                               const char *fname,
+                               size_t size)
+{
+       off_t size_read = 0;
+
+       NTSTATUS status = cli_qfileinfo_basic(cli,
+                               fnum,
+                               NULL,
+                               &size_read,
+                               NULL,
+                               NULL,
+                               NULL,
+                               NULL,
+                               NULL);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_smb2_qfileinfo_basic of %s failed (%s)\n",
+                       fname,
+                       nt_errstr(status));
+               return status;
+       }
+
+       if (size != size_read) {
+               printf("size (%u) != size_read(%u) for %s\n",
+                       (unsigned int)size,
+                       (unsigned int)size_read,
+                       fname);
+               /* Use EOF to mean bad size. */
+               return NT_STATUS_END_OF_FILE;
+       }
+       return NT_STATUS_OK;
+}
+
+/* Ensure cli_ftruncate() works for SMB2. */
+
+bool run_smb2_ftruncate(int dummy)
+{
+       struct cli_state *cli = NULL;
+       const char *fname = "smb2_ftruncate.txt";
+       uint16_t fnum = (uint16_t)-1;
+       bool correct = false;
+       size_t buflen = 1024*1024;
+       uint8_t *buf = NULL;
+       unsigned int i;
+       NTSTATUS status;
+
+       printf("Starting SMB2-FTRUNCATE\n");
+
+       if (!torture_init_connection(&cli)) {
+               return false;
+       }
+
+       status = smbXcli_negprot(cli->conn, cli->timeout,
+                                PROTOCOL_SMB2_02, PROTOCOL_SMB2_02);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("smbXcli_negprot returned %s\n", nt_errstr(status));
+               return false;
+       }
+
+       status = cli_session_setup(cli, username,
+                                  password, strlen(password),
+                                  password, strlen(password),
+                                  workgroup);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_session_setup returned %s\n", nt_errstr(status));
+               return false;
+       }
+
+       status = cli_tree_connect(cli, share, "?????", "", 0);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_tree_connect returned %s\n", nt_errstr(status));
+               return false;
+       }
+
+       cli_setatr(cli, fname, 0, 0);
+       cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+
+       status = cli_ntcreate(cli,
+                               fname,
+                               0,
+                               GENERIC_ALL_ACCESS,
+                               FILE_ATTRIBUTE_NORMAL,
+                               FILE_SHARE_NONE,
+                               FILE_CREATE,
+                               0,
+                               0,
+                               &fnum,
+                               NULL);
+
+        if (!NT_STATUS_IS_OK(status)) {
+                printf("open of %s failed (%s)\n", fname, nt_errstr(status));
+                goto fail;
+        }
+
+       buf = talloc_zero_array(cli, uint8_t, buflen);
+       if (buf == NULL) {
+               goto fail;
+       }
+
+       /* Write 1MB. */
+       status = cli_writeall(cli,
+                               fnum,
+                               0,
+                               buf,
+                               0,
+                               buflen,
+                               NULL);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("write of %u to %s failed (%s)\n",
+                       (unsigned int)buflen,
+                       fname,
+                       nt_errstr(status));
+               goto fail;
+       }
+
+       status = check_size(cli, fnum, fname, buflen);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto fail;
+       }
+
+       /* Now ftruncate. */
+       for ( i = 0; i < 10; i++) {
+               status = cli_ftruncate(cli, fnum, i*1024);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("cli_ftruncate %u of %s failed (%s)\n",
+                               (unsigned int)i*1024,
+                               fname,
+                               nt_errstr(status));
+                       goto fail;
+               }
+               status = check_size(cli, fnum, fname, i*1024);
+               if (!NT_STATUS_IS_OK(status)) {
+                       goto fail;
+               }
+       }
+
+       correct = true;
+
+  fail:
+
+       if (cli == NULL) {
+               return false;
+       }
+
+       if (fnum != (uint16_t)-1) {
+               cli_close(cli, fnum);
+       }
+       cli_setatr(cli, fname, 0, 0);
+       cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+
+       if (!torture_close_connection(cli)) {
+               correct = false;
+       }
+       return correct;
+}
index e3230699248dcc3451379c62dc77c3eeb5267e69..cfe33a81b61f1640b8bea8eda66098cd3b88843f 100644 (file)
@@ -10070,6 +10070,7 @@ static struct {
        { "SMB2-TCON-DEPENDENCE", run_smb2_tcon_dependence },
        { "SMB2-MULTI-CHANNEL", run_smb2_multi_channel },
        { "SMB2-SESSION-REAUTH", run_smb2_session_reauth },
+       { "SMB2-FTRUNCATE", run_smb2_ftruncate },
        { "CLEANUP1", run_cleanup1 },
        { "CLEANUP2", run_cleanup2 },
        { "CLEANUP3", run_cleanup3 },