s3/torture: add POSIX-STAT test
authorRalph Boehme <slow@samba.org>
Thu, 15 Oct 2020 13:36:42 +0000 (15:36 +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 b9f449c555006fc33a445eb44bcecfc6db55e5f6..c7280c630dc1174ed671c63068a3df206ef85236 100755 (executable)
@@ -246,6 +246,7 @@ posix_tests = ["POSIX", "POSIX-APPEND", "POSIX-SYMLINK-ACL", "POSIX-SYMLINK-EA",
                "POSIX-LS-WILDCARD",
                "POSIX-LS-SINGLE",
                "POSIX-READLINK",
+               "POSIX-STAT",
               ]
 
 for t in posix_tests:
index 01ef479a8e9cbfde6e9a5f204a2606ba9fa361d5..521c662e2fbc99eedc54f869941f4d1d2d8748a0 100644 (file)
@@ -88,6 +88,7 @@ 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_posix_stat_test(int dummy);
 bool run_case_insensitive_create(int dummy);
 
 bool run_nbench2(int dummy);
index fc2580825b5055a04e918ae33180603efe83a7dc..415460cf86ce11bfac1bcedea46f4ea6646446f7 100644 (file)
@@ -579,3 +579,144 @@ out:
        TALLOC_FREE(frame);
        return correct;
 }
+
+/*
+  Test POSIX stat of symlinks
+ */
+bool run_posix_stat_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-STAT 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++) {
+               SMB_STRUCT_STAT sbuf;
+
+               status = cli_posix_stat(cli_unix,
+                                       state[i].name,
+                                       &sbuf);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("POSIX stat on %s failed (%s)\n",
+                              state[i].name, nt_errstr(status));
+                       continue;
+               }
+               state[i].ok = true;
+               state[i].returned_size = sbuf.st_ex_size;
+       }
+
+       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-STAT 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 de2afdb8ebf4931d35cc2a6ff43c54abfb497286..cdf5d5ca3aa3aed7299de08d751077d06a7630f5 100644 (file)
@@ -14926,6 +14926,10 @@ static struct {
                .name  = "POSIX-READLINK",
                .fn    = run_posix_readlink_test,
        },
+       {
+               .name  = "POSIX-STAT",
+               .fn    = run_posix_stat_test,
+       },
        {
                .name  = "WINDOWS-BAD-SYMLINK",
                .fn    = run_symlink_open_test,