]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s4: torture: libsmbclient: Add a torture test to ensure smbc_stat() returns ENOENT...
authorJeremy Allison <jra@samba.org>
Mon, 17 Oct 2022 20:14:41 +0000 (13:14 -0700)
committerJeremy Allison <jra@samba.org>
Tue, 18 Oct 2022 23:20:37 +0000 (23:20 +0000)
Add knownfail.

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

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Pavel Filipenský <pfilipensky@samba.org>
selftest/knownfail.d/libsmb_getatr [new file with mode: 0644]
source4/torture/libsmbclient/libsmbclient.c

diff --git a/selftest/knownfail.d/libsmb_getatr b/selftest/knownfail.d/libsmb_getatr
new file mode 100644 (file)
index 0000000..d5fd1e9
--- /dev/null
@@ -0,0 +1,2 @@
+^samba4.libsmbclient.getatr.NT1.getatr\(nt4_dc_smb1_done\)
+^samba4.libsmbclient.getatr.SMB3.getatr\(nt4_dc\)
index 82f64c38b692cc8f024587854d5c8e205f97b797..d335cad3a4e37dd6b5b14a5cd3466680241a8e11 100644 (file)
@@ -1412,6 +1412,67 @@ static bool torture_libsmbclient_rename(struct torture_context *tctx)
        return success;
 }
 
+static bool torture_libsmbclient_getatr(struct torture_context *tctx)
+{
+       const char *smburl = torture_setting_string(tctx, "smburl", NULL);
+       SMBCCTX *ctx = NULL;
+       char *getatr_name = NULL;
+       struct stat st = {0};
+       bool ok;
+       int ret = 0;
+       int err = 0;
+
+       if (smburl == NULL) {
+               torture_fail(tctx,
+                            "option --option=torture:smburl="
+                            "smb://user:password@server missing\n");
+       }
+
+       ok = torture_libsmbclient_init_context(tctx, &ctx);
+       torture_assert(tctx, ok, "Failed to init context");
+       smbc_set_context(ctx);
+
+       getatr_name = talloc_asprintf(tctx,
+                       "%s/noexist",
+                       smburl);
+       if (getatr_name == NULL) {
+               torture_result(tctx,
+                              TORTURE_FAIL,
+                              __location__": %s",
+                              "talloc fail\n");
+               return false;
+       }
+       /* Ensure the file doesn't exist. */
+       smbc_unlink(getatr_name);
+       /*
+        * smbc_stat() internally uses SMBC_getatr().
+        * Make sure doing getatr on a non-existent file gives
+        * an error of -1, errno = ENOENT.
+        */
+
+       ret = smbc_stat(getatr_name, &st);
+       if (ret == -1) {
+               err = errno;
+       }
+       torture_assert_int_equal(tctx,
+                                ret,
+                                -1,
+                                talloc_asprintf(tctx,
+                                       "smbc_stat on '%s' should "
+                                       "get -1, got %d\n",
+                                       getatr_name,
+                                       ret));
+       torture_assert_int_equal(tctx,
+                                err,
+                                ENOENT,
+                                talloc_asprintf(tctx,
+                                       "smbc_stat on '%s' should "
+                                       "get errno = ENOENT, got %s\n",
+                                       getatr_name,
+                                       strerror(err)));
+       return true;
+}
+
 NTSTATUS torture_libsmbclient_init(TALLOC_CTX *ctx)
 {
        struct torture_suite *suite;
@@ -1438,6 +1499,8 @@ NTSTATUS torture_libsmbclient_init(TALLOC_CTX *ctx)
        torture_suite_add_simple_test(suite,
                                        "rename",
                                        torture_libsmbclient_rename);
+       torture_suite_add_simple_test(suite, "getatr",
+               torture_libsmbclient_getatr);
 
        suite->description = talloc_strdup(suite, "libsmbclient interface tests");