s3: torture: Regression test case to specify exactly how UNIX extensions should act...
authorJeremy Allison <jra@samba.org>
Tue, 19 Jul 2016 16:24:38 +0000 (09:24 -0700)
committerRalph Boehme <slow@samba.org>
Wed, 20 Jul 2016 03:20:29 +0000 (05:20 +0200)
If a stream is open, refuse the unlink. Ensure UNIX unlink
request can remove a file containing streams.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=12021

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Autobuild-User(master): Ralph Böhme <slow@samba.org>
Autobuild-Date(master): Wed Jul 20 05:20:29 CEST 2016 on sn-devel-144

selftest/skip
selftest/target/Samba3.pm
source3/selftest/tests.py
source3/torture/torture.c

index 4ff727460ea2879439d9fc201860ce8e37e49001..ba6718a31aa138aee393e1e58232f127d1f60715 100644 (file)
@@ -47,6 +47,7 @@
 ^samba3.smbtorture_s3.plain\(ad_dc_ntvfs\).POSIX-SYMLINK-ACL # Fails against the s4 ntvfs server
 ^samba3.smbtorture_s3.plain\(ad_dc_ntvfs\).POSIX-SYMLINK-EA # Fails against the s4 ntvfs server
 ^samba3.smbtorture_s3.plain\(ad_dc_ntvfs\).POSIX-OFD-LOCK # Fails against the s4 ntvfs server
+^samba3.smbtorture_s3.plain\(ad_dc_ntvfs\).POSIX-STREAM-DELETE # Fails against the s4 ntvfs server
 ^samba3.smbtorture_s3.plain\(ad_dc_ntvfs\).PIDHIGH # Fails against the s4 ntvfs server
 ^samba3.smbtorture_s3.plain\(ad_dc_ntvfs\).NTTRANS-FSCTL # Fails against the s4 ntvfs server
 ^samba3.smbtorture_s3.plain\(ad_dc_ntvfs\).SMB2-NEGPROT # Fails against the s4 ntvfs server
index 8a49cdb80b9b20e924ea365e7eea89153f0deeea..f5f4c0c3e0181656a9636ea26ab25d820f9a0031 100755 (executable)
@@ -1590,7 +1590,7 @@ sub provision($$$$$$$$)
        force create mode = 0
        directory mask = 0777
        force directory mode = 0
-       vfs objects = xattr_tdb
+       vfs objects = xattr_tdb streams_depot
 [aio]
        copy = tmp
        aio read size = 1
index e4b185bc1248a0b58e2c4f58cf7cce5626f31746..7538f12f74685c36ccc27cfdaff3f7d6821d0c0b 100755 (executable)
@@ -78,7 +78,8 @@ tests = ["RW1", "RW2", "RW3"]
 for t in tests:
     plantestsuite("samba3.smbtorture_s3.vfs_aio_fork(simpleserver).%s" % t, "simpleserver", [os.path.join(samba3srcdir, "script/tests/test_smbtorture_s3.sh"), t, '//$SERVER_IP/vfs_aio_fork', '$USERNAME', '$PASSWORD', smbtorture3, "", "-l $LOCAL_PATH"])
 
-posix_tests = ["POSIX", "POSIX-APPEND", "POSIX-SYMLINK-ACL", "POSIX-SYMLINK-EA", "POSIX-OFD-LOCK" ]
+posix_tests = ["POSIX", "POSIX-APPEND", "POSIX-SYMLINK-ACL", "POSIX-SYMLINK-EA", "POSIX-OFD-LOCK",
+              "POSIX-STREAM-DELETE" ]
 
 for t in posix_tests:
     plantestsuite("samba3.smbtorture_s3.plain(nt4_dc).%s" % t, "nt4_dc", [os.path.join(samba3srcdir, "script/tests/test_smbtorture_s3.sh"), t, '//$SERVER_IP/posix_share', '$USERNAME', '$PASSWORD', smbtorture3, "", "-l $LOCAL_PATH"])
index 09266904bd24a697d4cd06d1e6a8944542c58ba5..f9766bbf1b2f2537cb2e20fc010ca960b7774ba1 100644 (file)
@@ -6013,6 +6013,151 @@ static bool run_acl_symlink_test(int dummy)
        return correct;
 }
 
+/*
+  Test POSIX can delete a file containing streams.
+ */
+static bool run_posix_stream_delete(int dummy)
+{
+       struct cli_state *cli1 = NULL;
+       struct cli_state *cli2 = NULL;
+       const char *fname = "streamfile";
+       const char *stream_fname = "streamfile:Zone.Identifier:$DATA";
+       uint16_t fnum1 = (uint16_t)-1;
+       bool correct = false;
+       NTSTATUS status;
+       TALLOC_CTX *frame = NULL;
+
+       frame = talloc_stackframe();
+
+       printf("Starting POSIX stream delete test\n");
+
+       if (!torture_open_connection(&cli1, 0) ||
+                       !torture_open_connection(&cli2, 1)) {
+               TALLOC_FREE(frame);
+               return false;
+       }
+
+       smbXcli_conn_set_sockopt(cli1->conn, sockops);
+       smbXcli_conn_set_sockopt(cli2->conn, sockops);
+
+       status = torture_setup_unix_extensions(cli2);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto out;
+       }
+
+       cli_setatr(cli1, fname, 0, 0);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+
+       /* Create the file. */
+       status = cli_ntcreate(cli1,
+                       fname,
+                       0,
+                       READ_CONTROL_ACCESS,
+                       0,
+                       FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+                       FILE_CREATE,
+                       0x0,
+                       0x0,
+                       &fnum1,
+                       NULL);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_ntcreate of %s failed (%s)\n",
+                       fname,
+                       nt_errstr(status));
+               goto out;
+       }
+
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_close of %s failed (%s)\n",
+                       fname,
+                       nt_errstr(status));
+               goto out;
+       }
+       fnum1 = (uint16_t)-1;
+
+       /* Now create the stream. */
+       status = cli_ntcreate(cli1,
+                       stream_fname,
+                       0,
+                       FILE_WRITE_DATA,
+                       0,
+                       FILE_SHARE_READ|FILE_SHARE_WRITE,
+                       FILE_CREATE,
+                       0x0,
+                       0x0,
+                       &fnum1,
+                       NULL);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_ntcreate of %s failed (%s)\n",
+                       stream_fname,
+                       nt_errstr(status));
+               goto out;
+       }
+
+       /* Leave the stream handle open... */
+
+       /* POSIX unlink should fail. */
+       status = cli_posix_unlink(cli2, fname);
+       if (NT_STATUS_IS_OK(status)) {
+               printf("cli_posix_unlink of %s succeeded, should have failed\n",
+                       fname);
+               goto out;
+       }
+
+       if (!NT_STATUS_EQUAL(status, NT_STATUS_SHARING_VIOLATION)) {
+               printf("cli_posix_unlink of %s failed with (%s) "
+                       "should have been NT_STATUS_SHARING_VIOLATION\n",
+                       fname,
+                       nt_errstr(status));
+               goto out;
+       }
+
+       /* Close the stream handle. */
+       status = cli_close(cli1, fnum1);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_close of %s failed (%s)\n",
+                       stream_fname,
+                       nt_errstr(status));
+               goto out;
+       }
+       fnum1 = (uint16_t)-1;
+
+       /* POSIX unlink after stream handle closed should succeed. */
+       status = cli_posix_unlink(cli2, fname);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_posix_unlink of %s failed (%s)\n",
+                       fname,
+                       nt_errstr(status));
+               goto out;
+       }
+
+       printf("POSIX stream delete test passed\n");
+       correct = true;
+
+  out:
+
+       if (fnum1 != (uint16_t)-1) {
+               cli_close(cli1, fnum1);
+               fnum1 = (uint16_t)-1;
+       }
+
+       cli_setatr(cli1, fname, 0, 0);
+       cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);
+
+       if (!torture_close_connection(cli1)) {
+               correct = false;
+       }
+       if (!torture_close_connection(cli2)) {
+               correct = false;
+       }
+
+       TALLOC_FREE(frame);
+       return correct;
+}
+
 /*
   Test setting EA's are rejected on symlinks.
  */
@@ -10297,6 +10442,7 @@ static struct {
        {"POSIX-APPEND", run_posix_append, 0},
        {"POSIX-SYMLINK-ACL", run_acl_symlink_test, 0},
        {"POSIX-SYMLINK-EA", run_ea_symlink_test, 0},
+       {"POSIX-STREAM-DELETE", run_posix_stream_delete, 0},
        {"POSIX-OFD-LOCK", run_posix_ofd_lock_test, 0},
        {"CASE-INSENSITIVE-CREATE", run_case_insensitive_create, 0},
        {"ASYNC-ECHO", run_async_echo, 0},