s3: torture: Regression test for smbd trying to open an invalid symlink.
authorJeremy Allison <jra@samba.org>
Tue, 14 Feb 2017 20:59:58 +0000 (12:59 -0800)
committerJeremy Allison <jra@samba.org>
Thu, 16 Feb 2017 21:06:51 +0000 (22:06 +0100)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12572

Pair-programmed-with: Ralph Boehme <slow@samba.org>

Signed-off-by: Jeremy Allison <jra@samba.org>
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Thu Feb 16 22:06:51 CET 2017 on sn-devel-144

selftest/skip
source3/selftest/tests.py
source3/torture/torture.c

index 1e6d311f3c1139ebb0d9510c59dcf9bad82feee9..fd9932a47c00674956f7630c09beefeec7966015 100644 (file)
@@ -48,6 +48,7 @@
 ^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\).WINDOWS-BAD-SYMLINK # Fails against the s4 ntvfs server
 ^samba3.smbtorture_s3.plain\(ad_dc_ntvfs\).RENAME-ACCESS # Fails against the s4 ntvfs server
 ^samba3.smbtorture_s3.plain\(ad_dc_ntvfs\).OWNER-RIGHTS # Don't test against the s4 ntvfs server anymore
 ^samba3.smbtorture_s3.plain\(ad_dc_ntvfs\).PIDHIGH # Fails against the s4 ntvfs server
index 8e1c33d66f0fc2e45b7f2371258398e7b910fba8..4215eb043bf5f4f7194e362eb48e552f4bca6d2d 100755 (executable)
@@ -89,7 +89,7 @@ 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-STREAM-DELETE" ]
+              "POSIX-STREAM-DELETE", "WINDOWS-BAD-SYMLINK" ]
 
 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 1bd7d6e1393da199dd99c1c8b004e540b56a79ba..846b67526611dd8d6013a1351bd499d5d8790b48 100644 (file)
@@ -9643,6 +9643,106 @@ static bool run_pidhigh(int dummy)
        return success;
 }
 
+/*
+  Test Windows open on a bad POSIX symlink.
+ */
+static bool run_symlink_open_test(int dummy)
+{
+       static struct cli_state *cli;
+       const char *fname = "non_existant_file";
+       const char *sname = "dangling_symlink";
+       uint16_t fnum = (uint16_t)-1;
+       bool correct = false;
+       NTSTATUS status;
+       TALLOC_CTX *frame = NULL;
+
+       frame = talloc_stackframe();
+
+       printf("Starting Windows bad symlink open test\n");
+
+       if (!torture_open_connection(&cli, 0)) {
+               TALLOC_FREE(frame);
+               return false;
+       }
+
+       smbXcli_conn_set_sockopt(cli->conn, sockops);
+
+       status = torture_setup_unix_extensions(cli);
+       if (!NT_STATUS_IS_OK(status)) {
+               TALLOC_FREE(frame);
+               return false;
+       }
+
+       /* Ensure nothing exists. */
+       cli_setatr(cli, fname, 0, 0);
+       cli_posix_unlink(cli, fname);
+       cli_setatr(cli, sname, 0, 0);
+       cli_posix_unlink(cli, sname);
+
+       /* Create a symlink pointing nowhere. */
+       status = cli_posix_symlink(cli, fname, sname);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_posix_symlink of %s -> %s failed (%s)\n",
+                       sname,
+                       fname,
+                       nt_errstr(status));
+               goto out;
+       }
+
+       /* Now ensure that a Windows open doesn't hang. */
+       status = cli_ntcreate(cli,
+                       sname,
+                       0,
+                       FILE_READ_DATA|FILE_WRITE_DATA,
+                       0,
+                       FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+                       FILE_OPEN_IF,
+                       0x0,
+                       0x0,
+                       &fnum,
+                       NULL);
+
+       /*
+        * We get either NT_STATUS_OBJECT_NAME_NOT_FOUND or
+        * NT_STATUS_OBJECT_PATH_NOT_FOUND depending on if
+        * we use O_NOFOLLOW on the server or not.
+        */
+       if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND) ||
+           NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_PATH_NOT_FOUND))
+       {
+               correct = true;
+       } else {
+               printf("cli_ntcreate of %s returned %s - should return"
+                               " either (%s) or (%s)\n",
+                       sname,
+                       nt_errstr(status),
+                       nt_errstr(NT_STATUS_OBJECT_NAME_NOT_FOUND),
+                       nt_errstr(NT_STATUS_OBJECT_PATH_NOT_FOUND));
+               goto out;
+       }
+
+       correct = true;
+
+  out:
+
+       if (fnum != (uint16_t)-1) {
+               cli_close(cli, fnum);
+               fnum = (uint16_t)-1;
+       }
+
+       cli_setatr(cli, sname, 0, 0);
+       cli_posix_unlink(cli, sname);
+       cli_setatr(cli, fname, 0, 0);
+       cli_posix_unlink(cli, fname);
+
+       if (!torture_close_connection(cli)) {
+               correct = false;
+       }
+
+       TALLOC_FREE(frame);
+       return correct;
+}
+
 static bool run_local_substitute(int dummy)
 {
        bool ok = true;
@@ -11205,6 +11305,7 @@ static struct {
        {"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},
+       {"WINDOWS-BAD-SYMLINK", run_symlink_open_test, 0},
        {"CASE-INSENSITIVE-CREATE", run_case_insensitive_create, 0},
        {"ASYNC-ECHO", run_async_echo, 0},
        { "UID-REGRESSION-TEST", run_uid_regression_test, 0},