]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3: torture: Add an SMB1 POSIX specific test POSIX-SYMLINK-PARENT.
authorJeremy Allison <jra@samba.org>
Tue, 6 Apr 2021 18:46:23 +0000 (11:46 -0700)
committerRalph Boehme <slow@samba.org>
Wed, 7 Apr 2021 14:36:37 +0000 (14:36 +0000)
This creates a directory, then a symlink to a directory,
and then checks we can POSIX create and delete file, directory,
symlink and hardlink filesystem objects under the symlink
parent directory.

Mark as knownfail until next commit.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
selftest/knownfail.d/symlink_parent [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/symlink_parent b/selftest/knownfail.d/symlink_parent
new file mode 100644 (file)
index 0000000..752bab9
--- /dev/null
@@ -0,0 +1,2 @@
+^samba3.smbtorture_s3.plain.*POSIX-SYMLINK-PARENT
+^samba3.smbtorture_s3.crypt.*POSIX-SYMLINK-PARENT
index 450a7159ef95fd5981804e1afb0d5cd8af5b2cc4..6cbed8cc8e2f67567a3b9eca890e7fbd2854e50e 100755 (executable)
@@ -262,6 +262,7 @@ posix_tests = ["POSIX", "POSIX-APPEND", "POSIX-SYMLINK-ACL", "POSIX-SYMLINK-EA",
                "POSIX-LS-SINGLE",
                "POSIX-READLINK",
                "POSIX-STAT",
+               "POSIX-SYMLINK-PARENT",
               ]
 
 for t in posix_tests:
index 794a6044427b22c6d51ec8b130a1352845460ee0..dc27467ba64df5979bdb9646fd0e6d927c6f7966 100644 (file)
@@ -89,6 +89,7 @@ bool run_posix_ls_wildcard_test(int dummy);
 bool run_posix_ls_single_test(int dummy);
 bool run_posix_readlink_test(int dummy);
 bool run_posix_stat_test(int dummy);
+bool run_posix_symlink_parent_test(int dummy);
 bool run_case_insensitive_create(int dummy);
 
 bool run_nbench2(int dummy);
index 3ccb51d222b683650e912c9a50f5b6a1f9fbb213..c2ce392ca767219be2532ff771b2556889c7bdc9 100644 (file)
@@ -734,3 +734,181 @@ out:
        TALLOC_FREE(frame);
        return correct;
 }
+
+/*
+  Test Creating files and directories directly
+  under a symlink.
+ */
+bool run_posix_symlink_parent_test(int dummy)
+{
+       TALLOC_CTX *frame = NULL;
+       struct cli_state *cli_unix = NULL;
+       uint16_t fnum = (uint16_t)-1;
+       NTSTATUS status;
+       const char *parent_dir = "target_dir";
+       const char *parent_symlink = "symlink_to_target_dir";
+       const char *fname_real = "target_dir/file";
+       const char *dname_real = "target_dir/dir";
+       const char *fname_link = "symlink_to_target_dir/file";
+       const char *dname_link = "symlink_to_target_dir/dir";
+       const char *sname_link = "symlink_to_target_dir/symlink";
+       const char *hname_link = "symlink_to_target_dir/hardlink";
+       bool correct = false;
+
+       frame = talloc_stackframe();
+
+       printf("Starting POSIX-SYMLINK-PARENT 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_rmdir(cli_unix, dname_real);
+       cli_posix_unlink(cli_unix, fname_link);
+       cli_posix_rmdir(cli_unix, dname_link);
+       cli_posix_unlink(cli_unix, sname_link);
+       cli_posix_unlink(cli_unix, hname_link);
+       cli_posix_unlink(cli_unix, parent_symlink);
+       cli_posix_rmdir(cli_unix, parent_dir);
+
+       /* Create parent_dir. */
+       status = cli_posix_mkdir(cli_unix, parent_dir, 0777);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_posix_mkdir of %s failed error %s\n",
+                      parent_dir,
+                      nt_errstr(status));
+               goto out;
+       }
+       /* Create symlink to parent_dir. */
+       status = cli_posix_symlink(cli_unix,
+                                  parent_dir,
+                                  parent_symlink);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_posix_symlink of %s -> %s failed error %s\n",
+                      parent_symlink,
+                      parent_dir,
+                      nt_errstr(status));
+               goto out;
+       }
+       /* Try and create a directory under the symlink. */
+       status = cli_posix_mkdir(cli_unix, dname_link, 0777);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_posix_mkdir of %s failed error %s\n",
+                      dname_link,
+                      nt_errstr(status));
+               goto out;
+       }
+       /* Try and create a file under the symlink. */
+       status = cli_posix_open(cli_unix,
+                               fname_link,
+                               O_RDWR|O_CREAT,
+                               0666,
+                               &fnum);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_posix_open of %s failed error %s\n",
+                      fname_link,
+                      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;
+
+       /* Try and create a symlink to the file under the symlink. */
+       status = cli_posix_symlink(cli_unix,
+                                  fname_link,
+                                  sname_link);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_posix_symlink of %s -> %s failed error %s\n",
+                       sname_link,
+                       fname_link,
+                       nt_errstr(status));
+               goto out;
+       }
+
+       /* Try and create a hardlink to the file under the symlink. */
+       status = cli_posix_hardlink(cli_unix,
+                                  fname_link,
+                                  hname_link);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_posix_hardlink of %s -> %s failed error %s\n",
+                       hname_link,
+                       fname_link,
+                       nt_errstr(status));
+               goto out;
+       }
+
+       /* Ensure we can delete the symlink via the parent symlink */
+       status = cli_posix_unlink(cli_unix, sname_link);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_posix_unlink of %s failed error %s\n",
+                      sname_link,
+                      nt_errstr(status));
+               goto out;
+       }
+
+       /* Ensure we can delete the hardlink via the parent symlink */
+       status = cli_posix_unlink(cli_unix, hname_link);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_posix_unlink of %s failed error %s\n",
+                      hname_link,
+                      nt_errstr(status));
+               goto out;
+       }
+
+       /* Ensure we can delete the directory via the parent symlink */
+       status = cli_posix_rmdir(cli_unix, dname_link);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_posix_rmdir of %s failed error %s\n",
+                      dname_link,
+                      nt_errstr(status));
+               goto out;
+       }
+       /* Ensure we can delete the file via the parent symlink */
+       status = cli_posix_unlink(cli_unix, fname_link);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_posix_unlink of %s failed error %s\n",
+                      fname_link,
+                      nt_errstr(status));
+               goto out;
+       }
+
+       printf("POSIX-SYMLINK-PARENT 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_rmdir(cli_unix, dname_real);
+       cli_posix_unlink(cli_unix, fname_link);
+       cli_posix_rmdir(cli_unix, dname_link);
+       cli_posix_unlink(cli_unix, sname_link);
+       cli_posix_unlink(cli_unix, hname_link);
+       cli_posix_unlink(cli_unix, parent_symlink);
+       cli_posix_rmdir(cli_unix, parent_dir);
+
+       if (!torture_close_connection(cli_unix)) {
+               correct = false;
+       }
+
+       TALLOC_FREE(frame);
+       return correct;
+}
+
+
index 2a78fb92bc415d6c7ce0bdf5ba8ab6339ccfddc5..a46a252bc1963033f70367a88199fae3d564f350 100644 (file)
@@ -14947,6 +14947,10 @@ static struct {
                .name  = "POSIX-STAT",
                .fn    = run_posix_stat_test,
        },
+       {
+               .name  = "POSIX-SYMLINK-PARENT",
+               .fn    = run_posix_symlink_parent_test,
+       },
        {
                .name  = "WINDOWS-BAD-SYMLINK",
                .fn    = run_symlink_open_test,