]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s4: test: Add samba4.libsmbclient.rename test. Currently fails for SMB3.
authorJeremy Allison <jra@samba.org>
Wed, 2 Feb 2022 18:49:17 +0000 (10:49 -0800)
committerJule Anger <janger@samba.org>
Sun, 6 Feb 2022 11:38:17 +0000 (11:38 +0000)
Add knownfail.d/libsmbclient_rename

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14938

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
(cherry picked from commit 0ecc58858360bcc0181a02e52ada3e8327f97c5b)

selftest/knownfail.d/libsmbclient_rename [new file with mode: 0644]
source4/torture/libsmbclient/libsmbclient.c

diff --git a/selftest/knownfail.d/libsmbclient_rename b/selftest/knownfail.d/libsmbclient_rename
new file mode 100644 (file)
index 0000000..88343b7
--- /dev/null
@@ -0,0 +1 @@
+^samba4.libsmbclient.rename.SMB3.rename\(nt4_dc\)
index 97c2268aa81ecdb8479e9cfbdbc692e61f7c6c45..430be7188ae1e74b20ee76814ed15601dff688be 100644 (file)
@@ -1302,6 +1302,115 @@ out:
        return ok;
 }
 
+static bool torture_libsmbclient_rename(struct torture_context *tctx)
+{
+       SMBCCTX *ctx = NULL;
+       int fhandle = -1;
+       bool success = false;
+       const char *filename_src = NULL;
+       const char *filename_dst = NULL;
+       int ret;
+       const char *smburl = torture_setting_string(tctx, "smburl", NULL);
+
+       if (smburl == NULL) {
+               torture_fail(tctx,
+                       "option --option=torture:smburl="
+                       "smb://user:password@server/share missing\n");
+       }
+
+       torture_assert_goto(tctx,
+                               torture_libsmbclient_init_context(tctx, &ctx),
+                               success,
+                               done,
+                               "");
+
+       smbc_set_context(ctx);
+
+       filename_src = talloc_asprintf(tctx,
+                       "%s/src",
+                       smburl);
+       if (filename_src == NULL) {
+               torture_fail_goto(tctx, done, "talloc fail\n");
+       }
+
+       filename_dst = talloc_asprintf(tctx,
+                       "%s/dst",
+                       smburl);
+       if (filename_dst == NULL) {
+               torture_fail_goto(tctx, done, "talloc fail\n");
+       }
+
+       /* Ensure the files don't exist. */
+       smbc_unlink(filename_src);
+       smbc_unlink(filename_dst);
+
+       /* Create them. */
+       fhandle = smbc_creat(filename_src, 0666);
+       if (fhandle < 0) {
+               torture_fail_goto(tctx,
+                       done,
+                       talloc_asprintf(tctx,
+                               "failed to create file '%s': %s",
+                               filename_src,
+                               strerror(errno)));
+       }
+       ret = smbc_close(fhandle);
+       torture_assert_int_equal_goto(tctx,
+               ret,
+               0,
+               success,
+               done,
+               talloc_asprintf(tctx,
+                       "failed to close handle for '%s'",
+                       filename_src));
+
+       fhandle = smbc_creat(filename_dst, 0666);
+       if (fhandle < 0) {
+               torture_fail_goto(tctx,
+                       done,
+                       talloc_asprintf(tctx,
+                               "failed to create file '%s': %s",
+                               filename_dst,
+                               strerror(errno)));
+       }
+       ret = smbc_close(fhandle);
+       torture_assert_int_equal_goto(tctx,
+               ret,
+               0,
+               success,
+               done,
+               talloc_asprintf(tctx,
+                       "failed to close handle for '%s'",
+                       filename_dst));
+
+       ret = smbc_rename(filename_src, filename_dst);
+
+       /*
+        * BUG: https://bugzilla.samba.org/show_bug.cgi?id=14938
+        * gives ret == -1, but errno = 0 for overwrite renames
+        * over SMB2.
+        */
+       torture_assert_int_equal_goto(tctx,
+               ret,
+               0,
+               success,
+               done,
+               talloc_asprintf(tctx,
+                       "smbc_rename '%s' -> '%s' failed with %s\n",
+                       filename_src,
+                       filename_dst,
+                       strerror(errno)));
+
+       /* Remove them again. */
+       smbc_unlink(filename_src);
+       smbc_unlink(filename_dst);
+       success = true;
+
+  done:
+       smbc_free_context(ctx, 1);
+       return success;
+}
+
 NTSTATUS torture_libsmbclient_init(TALLOC_CTX *ctx)
 {
        struct torture_suite *suite;
@@ -1325,6 +1434,9 @@ NTSTATUS torture_libsmbclient_init(TALLOC_CTX *ctx)
                suite, "utimes", torture_libsmbclient_utimes);
        torture_suite_add_simple_test(
                suite, "noanon_list", torture_libsmbclient_noanon_list);
+       torture_suite_add_simple_test(suite,
+                                       "rename",
+                                       torture_libsmbclient_rename);
 
        suite->description = talloc_strdup(suite, "libsmbclient interface tests");