From 698d0fa6c3930f949f12bbddb024876cd3e4f896 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 17 Jun 2022 17:49:43 -0700 Subject: [PATCH 1/2] s3: tests: Add test that shows smbd crashes using vfs_fruit with fruit:resource = stream on deleting a file. Add knownfail. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15099 Signed-off-by: Jeremy Allison Reviewed-by: Noel Power (backported from commit 238b2cbb8f352375c448d86b462f13752640e16b) --- selftest/knownfail.d/fruit_resource_stream | 1 + selftest/target/Samba3.pm | 9 ++++ .../tests/test_fruit_resource_stream.sh | 41 +++++++++++++++++++ source3/selftest/tests.py | 4 ++ 4 files changed, 55 insertions(+) create mode 100644 selftest/knownfail.d/fruit_resource_stream create mode 100755 source3/script/tests/test_fruit_resource_stream.sh diff --git a/selftest/knownfail.d/fruit_resource_stream b/selftest/knownfail.d/fruit_resource_stream new file mode 100644 index 00000000000..081edb983ee --- /dev/null +++ b/selftest/knownfail.d/fruit_resource_stream @@ -0,0 +1 @@ +^samba3.blackbox.fruit.resource_stream.resource_stream\(fileserver\) diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm index e578791a2ee..43bce06c6d9 100755 --- a/selftest/target/Samba3.pm +++ b/selftest/target/Samba3.pm @@ -2422,6 +2422,9 @@ sub provision($$) my $local_symlinks_shrdir="$shrdir/local_symlinks"; push(@dirs,$local_symlinks_shrdir); + my $fruit_resource_stream_shrdir="$shrdir/fruit_resource_stream"; + push(@dirs,$fruit_resource_stream_shrdir); + # this gets autocreated by winbindd my $wbsockdir="$prefix_abs/wbsock"; @@ -2982,6 +2985,12 @@ sub provision($$) fruit:metadata = stream fruit:zero_file_id=yes +[fruit_resource_stream] + path = $fruit_resource_stream_shrdir + vfs objects = fruit streams_xattr acl_xattr xattr_tdb + fruit:resource = stream + fruit:metadata = stream + [badname-tmp] path = $badnames_shrdir guest ok = yes diff --git a/source3/script/tests/test_fruit_resource_stream.sh b/source3/script/tests/test_fruit_resource_stream.sh new file mode 100755 index 00000000000..7e99ea3de5c --- /dev/null +++ b/source3/script/tests/test_fruit_resource_stream.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +# this tests copying a file and then deleting it +# to a share using fruit:resource = stream +# BUG: https://bugzilla.samba.org/show_bug.cgi?id=15099 + +if [ $# -lt 6 ]; then + cat </dev/null 2>&1 +} + +rm -f "$LOCAL_PATH/src" +rm -f "$LOCAL_PATH/dst" +touch "$LOCAL_PATH/src" + +testit "resource_stream" put_then_delete_file || failed=$((failed + 1)) + +rm -f "$LOCAL_PATH/src" +rm -f "$LOCAL_PATH/dst" + +testok "$0" "$failed" diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py index d7ee1ab6200..376e356ba3d 100755 --- a/source3/selftest/tests.py +++ b/source3/selftest/tests.py @@ -657,6 +657,10 @@ for env in ["fileserver"]: plantestsuite("samba3.blackbox.fifo", env, [os.path.join(samba3srcdir, "script/tests/test_fifo.sh"), '$SERVER', '$DOMAIN', 'gooduser', '$PASSWORD', '$PREFIX', env, smbclient3]) + plantestsuite("samba3.blackbox.fruit.resource_stream", env, + [os.path.join(samba3srcdir, "script/tests/test_fruit_resource_stream.sh"), + '$SERVER', 'fruit_resource_stream', '$USERNAME', '$PASSWORD', + '$LOCAL_PATH/fruit_resource_stream', smbclient3]) for env in ["fileserver:local"]: plantestsuite("samba3.blackbox.net_usershare", env, [os.path.join(samba3srcdir, "script/tests/test_net_usershare.sh"), '$SERVER', '$SERVER_IP', '$USERNAME', '$PASSWORD', smbclient3]) -- 2.35.3 From 606ca9e1eb3976cb2e234f0bd9066f5c8418d7ed Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 17 Jun 2022 17:51:35 -0700 Subject: [PATCH 2/2] s3: VFS: streams_xattr: Add the same accommodation to streams_xattr_unlinkat() as used in streams_xattr_renameat(). vfs_fruit passes a synthetic filename here where smb_fname->fsp==NULL when configured to use "fruit:resource = stream" so we need to use synthetic_pathref() to get an fsp on the smb_fname->base_name in order to call SMB_VFS_FREMOVEXATTR(). This is the same change we already use in streams_xattr_renameat() and streams_xattr_stat(), the other pathname operations we implement here. Remove knownfail. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15099 Signed-off-by: Jeremy Allison Reviewed-by: Noel Power Autobuild-User(master): Noel Power Autobuild-Date(master): Mon Jun 20 14:24:20 UTC 2022 on sn-devel-184 (backported from commit 808a7b8b76dbcaac1db0508fd410d0bcf702af7a) --- selftest/knownfail.d/fruit_resource_stream | 1 - source3/modules/vfs_streams_xattr.c | 25 +++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) delete mode 100644 selftest/knownfail.d/fruit_resource_stream diff --git a/selftest/knownfail.d/fruit_resource_stream b/selftest/knownfail.d/fruit_resource_stream deleted file mode 100644 index 081edb983ee..00000000000 --- a/selftest/knownfail.d/fruit_resource_stream +++ /dev/null @@ -1 +0,0 @@ -^samba3.blackbox.fruit.resource_stream.resource_stream\(fileserver\) diff --git a/source3/modules/vfs_streams_xattr.c b/source3/modules/vfs_streams_xattr.c index 558bf228794..e2c67e84cec 100644 --- a/source3/modules/vfs_streams_xattr.c +++ b/source3/modules/vfs_streams_xattr.c @@ -481,6 +481,8 @@ static int streams_xattr_unlink_internal(vfs_handle_struct *handle, NTSTATUS status; int ret = -1; char *xattr_name = NULL; + struct smb_filename *pathref = NULL; + struct files_struct *fsp = smb_fname->fsp; if (!is_named_stream(smb_fname)) { return SMB_VFS_NEXT_UNLINKAT(handle, @@ -496,10 +498,26 @@ static int streams_xattr_unlink_internal(vfs_handle_struct *handle, goto fail; } - SMB_ASSERT(smb_fname->fsp != NULL); - SMB_ASSERT(smb_fname->fsp->base_fsp != NULL); + if (fsp == NULL) { + status = synthetic_pathref(talloc_tos(), + handle->conn->cwd_fsp, + smb_fname->base_name, + NULL, + NULL, + smb_fname->twrp, + smb_fname->flags, + &pathref); + if (!NT_STATUS_IS_OK(status)) { + errno = ENOENT; + goto fail; + } + fsp = pathref->fsp; + } else { + SMB_ASSERT(fsp_is_alternate_stream(smb_fname->fsp)); + fsp = fsp->base_fsp; + } - ret = SMB_VFS_FREMOVEXATTR(smb_fname->fsp->base_fsp, xattr_name); + ret = SMB_VFS_FREMOVEXATTR(fsp, xattr_name); if ((ret == -1) && (errno == ENOATTR)) { errno = ENOENT; @@ -510,6 +528,7 @@ static int streams_xattr_unlink_internal(vfs_handle_struct *handle, fail: TALLOC_FREE(xattr_name); + TALLOC_FREE(pathref); return ret; } -- 2.35.3