From: Ralph Boehme Date: Thu, 15 Oct 2020 13:36:42 +0000 (+0200) Subject: s3/torture: add POSIX-STAT test X-Git-Tag: samba-4.14.0rc1~326 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a63a39729489be073e0fe882a1f470f82dddfce6;p=thirdparty%2Fsamba.git s3/torture: add POSIX-STAT test Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py index b9f449c5550..c7280c630dc 100755 --- a/source3/selftest/tests.py +++ b/source3/selftest/tests.py @@ -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: diff --git a/source3/torture/proto.h b/source3/torture/proto.h index 01ef479a8e9..521c662e2fb 100644 --- a/source3/torture/proto.h +++ b/source3/torture/proto.h @@ -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); diff --git a/source3/torture/test_posix.c b/source3/torture/test_posix.c index fc2580825b5..415460cf86c 100644 --- a/source3/torture/test_posix.c +++ b/source3/torture/test_posix.c @@ -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; +} diff --git a/source3/torture/torture.c b/source3/torture/torture.c index de2afdb8ebf..cdf5d5ca3aa 100644 --- a/source3/torture/torture.c +++ b/source3/torture/torture.c @@ -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,