]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3: torture: Add regression test for renaming SMB1+POSIX symlinks, dangling and real.
authorJeremy Allison <jra@samba.org>
Fri, 21 May 2021 18:14:19 +0000 (11:14 -0700)
committerNoel Power <npower@samba.org>
Mon, 24 May 2021 16:57:37 +0000 (16:57 +0000)
Mark as knownfail.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Noel Power <noel.power@suse.com>
selftest/knownfail.d/posix_symlink_rename [new file with mode: 0644]
source3/selftest/tests.py
source3/torture/proto.h
source3/torture/test_posix.c
source3/torture/torture.c

diff --git a/selftest/knownfail.d/posix_symlink_rename b/selftest/knownfail.d/posix_symlink_rename
new file mode 100644 (file)
index 0000000..b0889e7
--- /dev/null
@@ -0,0 +1,2 @@
+^samba3.smbtorture_s3.plain.POSIX-SYMLINK-RENAME.smbtorture\(nt4_dc_smb1\)
+^samba3.smbtorture_s3.crypt.POSIX-SYMLINK-RENAME.smbtorture\(nt4_dc_smb1\)
index 13f0466802e62b51ba4750d4454df6ce346e41cd..d4f9ea27ba63d4077b11e336dd6b283628771f03 100755 (executable)
@@ -265,6 +265,7 @@ posix_tests = ["POSIX", "POSIX-APPEND", "POSIX-SYMLINK-ACL", "POSIX-SYMLINK-EA",
                "POSIX-SYMLINK-PARENT",
                "POSIX-SYMLINK-CHMOD",
                "POSIX-DIR-DEFAULT-ACL",
+               "POSIX-SYMLINK-RENAME",
               ]
 
 for t in posix_tests:
index bc2d8c7b3f2309abee6e182f7d106b39ac0e2957..4e813c473b18b4d10d009b633ff1b5215785b2e0 100644 (file)
@@ -93,6 +93,7 @@ bool run_posix_symlink_parent_test(int dummy);
 bool run_posix_symlink_chmod_test(int dummy);
 bool run_posix_dir_default_acl_test(int dummy);
 bool run_case_insensitive_create(int dummy);
+bool run_posix_symlink_rename_test(int dummy);
 
 bool run_nbench2(int dummy);
 bool run_async_echo(int dummy);
index 8c1306c5066fa9bfafe69041ed7f713e9c49945b..dc25db4c985e1e6a6da311645e4fec721d2f0e47 100644 (file)
@@ -1309,3 +1309,137 @@ out:
        TALLOC_FREE(frame);
        return correct;
 }
+
+/*
+  Ensure we can rename a symlink whether it is
+  pointing to a real object or dangling.
+ */
+bool run_posix_symlink_rename_test(int dummy)
+{
+       TALLOC_CTX *frame = NULL;
+       struct cli_state *cli_unix = NULL;
+       NTSTATUS status;
+       uint16_t fnum = (uint16_t)-1;
+       const char *fname_real = "file_real";
+       const char *fname_real_symlink = "file_real_symlink";
+       const char *fname_real_symlink_newname = "rename_file_real_symlink";
+       const char *nonexist = "nonexist";
+       const char *nonexist_symlink = "dangling_symlink";
+       const char *nonexist_symlink_newname = "dangling_symlink_rename";
+       bool correct = false;
+
+       frame = talloc_stackframe();
+
+       printf("Starting POSIX-SYMLINK-RENAME test\n");
+
+       if (!torture_open_connection(&cli_unix, 0)) {
+               TALLOC_FREE(frame);
+               return false;
+       }
+
+       torture_conn_set_sockopt(cli_unix);
+
+       status = torture_setup_unix_extensions(cli_unix);
+       if (!NT_STATUS_IS_OK(status)) {
+               TALLOC_FREE(frame);
+               return false;
+       }
+
+       /* Start with a clean slate. */
+       cli_posix_unlink(cli_unix, fname_real);
+       cli_posix_unlink(cli_unix, fname_real_symlink);
+       cli_posix_unlink(cli_unix, fname_real_symlink_newname);
+       cli_posix_unlink(cli_unix, nonexist);
+       cli_posix_unlink(cli_unix, nonexist_symlink);
+       cli_posix_unlink(cli_unix, nonexist_symlink_newname);
+
+       /* Create a real file. */
+       status = cli_posix_open(cli_unix,
+                               fname_real,
+                               O_RDWR|O_CREAT,
+                               0644,
+                               &fnum);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_posix_open of %s failed error %s\n",
+                      fname_real,
+                      nt_errstr(status));
+               goto out;
+       }
+       status = cli_close(cli_unix, fnum);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_close failed %s\n", nt_errstr(status));
+               goto out;
+       }
+       fnum = (uint16_t)-1;
+
+       /* Create symlink to real target. */
+       status = cli_posix_symlink(cli_unix,
+                                  fname_real,
+                                  fname_real_symlink);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_posix_symlink of %s -> %s failed error %s\n",
+                      fname_real_symlink,
+                      fname_real,
+                      nt_errstr(status));
+               goto out;
+       }
+
+       /* Ensure we can rename the symlink to the real file. */
+       status = cli_rename(cli_unix,
+                               fname_real_symlink,
+                               fname_real_symlink_newname,
+                               false);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_rename of %s -> %s failed %s\n",
+                       fname_real_symlink,
+                       fname_real_symlink_newname,
+                       nt_errstr(status));
+               goto out;
+       }
+
+       /* Now create symlink to non-existing target. */
+       status = cli_posix_symlink(cli_unix,
+                                  nonexist,
+                                  nonexist_symlink);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_posix_symlink of %s -> %s failed error %s\n",
+                      nonexist_symlink,
+                      nonexist,
+                      nt_errstr(status));
+               goto out;
+       }
+
+       /* Ensure we can rename the dangling symlink. */
+       status = cli_rename(cli_unix,
+                               nonexist_symlink,
+                               nonexist_symlink_newname,
+                               false);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_rename of %s -> %s failed %s\n",
+                       nonexist_symlink,
+                       nonexist_symlink_newname,
+                       nt_errstr(status));
+               goto out;
+       }
+
+       printf("POSIX-SYMLINK-RENAME test passed\n");
+       correct = true;
+
+out:
+       if (fnum != (uint16_t)-1) {
+               cli_close(cli_unix, fnum);
+       }
+       cli_posix_unlink(cli_unix, fname_real);
+       cli_posix_unlink(cli_unix, fname_real_symlink);
+       cli_posix_unlink(cli_unix, fname_real_symlink_newname);
+       cli_posix_unlink(cli_unix, nonexist);
+       cli_posix_unlink(cli_unix, nonexist_symlink);
+       cli_posix_unlink(cli_unix, nonexist_symlink_newname);
+
+       if (!torture_close_connection(cli_unix)) {
+               correct = false;
+       }
+
+       TALLOC_FREE(frame);
+       return correct;
+}
index 06bb44943e63b2246b2a4866d8f3a979ea3da999..914c7705fafaf875f3ab21420c7c120a843060fa 100644 (file)
@@ -14955,6 +14955,10 @@ static struct {
                .name  = "POSIX-SYMLINK-CHMOD",
                .fn    = run_posix_symlink_chmod_test,
        },
+       {
+               .name  = "POSIX-SYMLINK-RENAME",
+               .fn    = run_posix_symlink_rename_test,
+       },
        {
                .name  = "POSIX-DIR-DEFAULT-ACL",
                .fn    = run_posix_dir_default_acl_test,