]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3/torture: add POSIX-READLINK test
authorRalph Boehme <slow@samba.org>
Thu, 15 Oct 2020 13:32:34 +0000 (15:32 +0200)
committerRalph Boehme <slow@samba.org>
Wed, 16 Dec 2020 09:08:31 +0000 (09:08 +0000)
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/selftest/tests.py
source3/torture/proto.h
source3/torture/test_posix.c
source3/torture/torture.c

index da2d3470a6a7193045e29a565ebe83456af2fd41..b9f449c555006fc33a445eb44bcecfc6db55e5f6 100755 (executable)
@@ -245,6 +245,7 @@ posix_tests = ["POSIX", "POSIX-APPEND", "POSIX-SYMLINK-ACL", "POSIX-SYMLINK-EA",
                "POSIX-ACL-SHAREROOT",
                "POSIX-LS-WILDCARD",
                "POSIX-LS-SINGLE",
+               "POSIX-READLINK",
               ]
 
 for t in posix_tests:
index 87d80d930e44546de98ace5cd4cca78d7f5b58cf..01ef479a8e9cbfde6e9a5f204a2606ba9fa361d5 100644 (file)
@@ -87,6 +87,7 @@ bool torture_casetable(int dummy);
 bool run_posix_append(int dummy);
 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_case_insensitive_create(int dummy);
 
 bool run_nbench2(int dummy);
index 2ce1f61b951995827666835fc100a48fab047091..fc2580825b5055a04e918ae33180603efe83a7dc 100644 (file)
@@ -435,3 +435,147 @@ out:
        TALLOC_FREE(frame);
        return correct;
 }
+
+/*
+  Test POSIX readlink of symlinks
+ */
+bool run_posix_readlink_test(int dummy)
+{
+       TALLOC_CTX *frame = NULL;
+       struct cli_state *cli_unix = NULL;
+       uint16_t fnum = (uint16_t)-1;
+       NTSTATUS status;
+       const char *file = "file";
+       const char *symlnk_dangling = "dangling";
+       const char *symlnk_dst_dangling = "xxxxxxx";
+       const char *symlnk_in_share = "symlnk_in_share";
+       const char *symlnk_dst_in_share = file;
+       const char *symlnk_outside_share = "symlnk_outside_share";
+       const char *symlnk_dst_outside_share = "/etc/passwd";
+       struct posix_test_entry state[] = {
+               {
+                       .name = symlnk_dangling,
+                       .target = symlnk_dst_dangling,
+                       .expected = symlnk_dangling,
+               }, {
+                       .name = symlnk_in_share,
+                       .target = symlnk_dst_in_share,
+                       .expected = symlnk_in_share,
+               }, {
+                       .name = symlnk_outside_share,
+                       .target = symlnk_dst_outside_share,
+                       .expected = symlnk_outside_share,
+               }, {
+                       .name = NULL,
+               }
+       };
+       int i;
+       bool correct = false;
+
+       frame = talloc_stackframe();
+
+       printf("Starting POSIX-READLINK 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;
+       }
+
+       cli_posix_unlink(cli_unix, file);
+       cli_posix_unlink(cli_unix, symlnk_dangling);
+       cli_posix_unlink(cli_unix, symlnk_in_share);
+       cli_posix_unlink(cli_unix, symlnk_outside_share);
+
+       status = cli_posix_open(cli_unix,
+                               file,
+                               O_RDWR|O_CREAT,
+                               0666,
+                               &fnum);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_posix_open of %s failed error %s\n",
+                      file,
+                      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;
+
+       for (i = 0; state[i].name != NULL; i++) {
+               status = cli_posix_symlink(cli_unix,
+                                          state[i].target,
+                                          state[i].name);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("POSIX symlink of %s failed (%s)\n",
+                              symlnk_dangling, nt_errstr(status));
+                       goto out;
+               }
+       }
+
+       for (i = 0; state[i].name != NULL; i++) {
+               char *target = NULL;
+
+               status = cli_posix_readlink(cli_unix,
+                                           state[i].name,
+                                           talloc_tos(),
+                                           &target);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("POSIX readlink on %s failed (%s)\n",
+                              state[i].name, nt_errstr(status));
+                       goto out;
+               }
+               if (strequal(target, state[i].target)) {
+                       state[i].ok = true;
+                       state[i].returned_size = strlen(target);
+               }
+       }
+
+       if (!posix_test_entry_check(state,
+                                   symlnk_dangling,
+                                   true,
+                                   strlen(symlnk_dst_dangling)))
+       {
+               goto out;
+       }
+       if (!posix_test_entry_check(state,
+                                   symlnk_outside_share,
+                                   true,
+                                   strlen(symlnk_dst_outside_share)))
+       {
+               goto out;
+       }
+       if (!posix_test_entry_check(state,
+                                   symlnk_in_share,
+                                   true,
+                                   strlen(symlnk_dst_in_share))) {
+               goto out;
+       }
+
+       printf("POSIX-READLINK test passed\n");
+       correct = true;
+
+out:
+       cli_posix_unlink(cli_unix, file);
+       cli_posix_unlink(cli_unix, symlnk_dangling);
+       cli_posix_unlink(cli_unix, symlnk_in_share);
+       cli_posix_unlink(cli_unix, symlnk_outside_share);
+
+       if (!torture_close_connection(cli_unix)) {
+               correct = false;
+       }
+
+       TALLOC_FREE(frame);
+       return correct;
+}
index 102363bddf18a1d9357655a3feb0adc8b7968a24..de2afdb8ebf4931d35cc2a6ff43c54abfb497286 100644 (file)
@@ -14922,6 +14922,10 @@ static struct {
                .name  = "POSIX-LS-SINGLE",
                .fn    = run_posix_ls_single_test,
        },
+       {
+               .name  = "POSIX-READLINK",
+               .fn    = run_posix_readlink_test,
+       },
        {
                .name  = "WINDOWS-BAD-SYMLINK",
                .fn    = run_symlink_open_test,