]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3/torture: add POSIX-LS-SINGLE test
authorRalph Boehme <slow@samba.org>
Thu, 15 Oct 2020 13:24:11 +0000 (15:24 +0200)
committerRalph Boehme <slow@samba.org>
Wed, 16 Dec 2020 09:08:31 +0000 (09:08 +0000)
Note that uses SMB2 for the "Windows client" (aka non-POSIX) connection as SMB1
directory listing code translates a directory listing with a search mask that
matches an existing file to a CREATE which won't cut it for our test as we're
targetting the directory listing code.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
selftest/knownfail.d/samba3.smbtorture_s3
source3/selftest/tests.py
source3/torture/proto.h
source3/torture/test_posix.c
source3/torture/torture.c

index f56cf2327e9b8b77fdf5737d5cf18f1518d36cf9..388980c2c740f4191b61932b7bc3a4a92ee72bc1 100644 (file)
@@ -1,2 +1,4 @@
 ^samba3.smbtorture_s3.plain.POSIX-LS-WILDCARD.smbtorture\(nt4_dc_smb1\)
 ^samba3.smbtorture_s3.crypt.POSIX-LS-WILDCARD.smbtorture\(nt4_dc_smb1\)
+^samba3.smbtorture_s3.plain.POSIX-LS-SINGLE.smbtorture\(nt4_dc_smb1\)
+^samba3.smbtorture_s3.crypt.POSIX-LS-SINGLE.smbtorture\(nt4_dc_smb1\)
index 3d4eb0ca1090559338942664b15c043ee8c4b533..da2d3470a6a7193045e29a565ebe83456af2fd41 100755 (executable)
@@ -244,6 +244,7 @@ posix_tests = ["POSIX", "POSIX-APPEND", "POSIX-SYMLINK-ACL", "POSIX-SYMLINK-EA",
                "POSIX-ACL-OPLOCK",
                "POSIX-ACL-SHAREROOT",
                "POSIX-LS-WILDCARD",
+               "POSIX-LS-SINGLE",
               ]
 
 for t in posix_tests:
index ba0cb9a0d1700bac696a8299b6ac8ba330bebd60..87d80d930e44546de98ace5cd4cca78d7f5b58cf 100644 (file)
@@ -86,6 +86,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_case_insensitive_create(int dummy);
 
 bool run_nbench2(int dummy);
index b7a89cf83c6afc50fae6e94f67c0c7455227bd24..2ce1f61b951995827666835fc100a48fab047091 100644 (file)
 #include "libsmb/libsmb.h"
 #include "libsmb/clirap.h"
 #include "libsmb/proto.h"
+#include "../libcli/smb/smbXcli_base.h"
+
+extern struct cli_credentials *torture_creds;
+extern fstring host, workgroup, share, password, username, myname;
 
 struct posix_test_entry {
        const char *name;
@@ -248,3 +252,186 @@ out:
        TALLOC_FREE(frame);
        return correct;
 }
+
+/*
+  Test non-POSIX vs POSIX ls single of symlinks
+ */
+bool run_posix_ls_single_test(int dummy)
+{
+       TALLOC_CTX *frame = NULL;
+       struct cli_state *cli_unix = NULL;
+       struct cli_state *cli_win = 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-LS-SINGLE test\n");
+
+       if (!torture_open_connection(&cli_unix, 0)) {
+               TALLOC_FREE(frame);
+               return false;
+       }
+
+       if (!torture_init_connection(&cli_win)) {
+               TALLOC_FREE(frame);
+               return false;
+       }
+
+       status = smbXcli_negprot(cli_win->conn,
+                                cli_win->timeout,
+                                lp_client_min_protocol(),
+                                lp_client_max_protocol());
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("smbXcli_negprot returned %s\n", nt_errstr(status));
+               TALLOC_FREE(frame);
+               return false;
+       }
+
+       status = cli_session_setup_creds(cli_win, torture_creds);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("smb2cli_sesssetup returned %s\n", nt_errstr(status));
+               TALLOC_FREE(frame);
+               return false;
+       }
+
+       status = cli_tree_connect(cli_win, share, "?????", NULL);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("cli_tree_connect returned %s\n", nt_errstr(status));
+               TALLOC_FREE(frame);
+               return false;
+       }
+       torture_conn_set_sockopt(cli_unix);
+       torture_conn_set_sockopt(cli_win);
+
+       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;
+               }
+       }
+
+       printf("Doing Windows ls single\n");
+
+       cli_list(cli_win, symlnk_dangling, 0, posix_ls_fn, state);
+       cli_list(cli_win, symlnk_outside_share, 0, posix_ls_fn, state);
+       cli_list(cli_win, symlnk_in_share, 0, posix_ls_fn, state);
+
+       if (!posix_test_entry_check(state, symlnk_dangling, false, 0)) {
+               goto out;
+       }
+       if (!posix_test_entry_check(state, symlnk_outside_share, false, 0)) {
+               goto out;
+       }
+       if (!posix_test_entry_check(state, symlnk_in_share, true, 0)) {
+               goto out;
+       }
+
+       posix_test_entries_reset(state);
+
+       printf("Doing POSIX ls single\n");
+
+       cli_list(cli_unix, symlnk_dangling, 0, posix_ls_fn, state);
+       cli_list(cli_unix, symlnk_outside_share, 0, posix_ls_fn, state);
+       cli_list(cli_unix, symlnk_in_share, 0, posix_ls_fn, state);
+
+       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-LS-SINGLE 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;
+       }
+       if (!torture_close_connection(cli_win)) {
+               correct = false;
+       }
+
+       TALLOC_FREE(frame);
+       return correct;
+}
index f80d8c467e7ee9bbb8055da483375864e13098d7..102363bddf18a1d9357655a3feb0adc8b7968a24 100644 (file)
@@ -14918,6 +14918,10 @@ static struct {
                .name  = "POSIX-LS-WILDCARD",
                .fn    = run_posix_ls_wildcard_test,
        },
+       {
+               .name  = "POSIX-LS-SINGLE",
+               .fn    = run_posix_ls_single_test,
+       },
        {
                .name  = "WINDOWS-BAD-SYMLINK",
                .fn    = run_symlink_open_test,