From 6a359ce9271f6a69529730f4c4edbfc865165f98 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 11 Apr 2018 08:41:00 -0700 Subject: [PATCH 1/3] s3: vfs: vfs_streams_xattr: Don't blindly re-use the base file mode bits. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When returning the stat struct for an xattr stream, we originally base the st_ex_mode field on the value from the base file containing the xattr. If the base file is a directory, it will have S_IFDIR set in st_ex_mode, but streams can never be directories, they must be reported as regular files. The original code OR'ed in S_IFREG, but neglected to AND out S_IFDIR. Note this is not a complete to fix bug 13380 as it doesn't fix the generic case with all streams modules. See later fix and regression test. Found in real-world use case by Andrew Walker . BUG: https://bugzilla.samba.org/show_bug.cgi?id=13380 Signed-off-by: Jeremy Allison Reviewed-by: Volker Lendecke Reviewed-by: Ralph Böhme (cherry picked from commit 4d839d0f46b723ed6809bb932b9ebe4ead2cec82) --- source3/modules/vfs_streams_xattr.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source3/modules/vfs_streams_xattr.c b/source3/modules/vfs_streams_xattr.c index 580ecd0e5ff..c653656e5f8 100644 --- a/source3/modules/vfs_streams_xattr.c +++ b/source3/modules/vfs_streams_xattr.c @@ -277,6 +277,7 @@ static int streams_xattr_fstat(vfs_handle_struct *handle, files_struct *fsp, sbuf->st_ex_ino = stream_inode(sbuf, io->xattr_name); sbuf->st_ex_mode &= ~S_IFMT; + sbuf->st_ex_mode &= ~S_IFDIR; sbuf->st_ex_mode |= S_IFREG; sbuf->st_ex_blocks = sbuf->st_ex_size / STAT_ST_BLOCKSIZE + 1; @@ -331,6 +332,7 @@ static int streams_xattr_stat(vfs_handle_struct *handle, smb_fname->st.st_ex_ino = stream_inode(&smb_fname->st, xattr_name); smb_fname->st.st_ex_mode &= ~S_IFMT; + smb_fname->st.st_ex_mode &= ~S_IFDIR; smb_fname->st.st_ex_mode |= S_IFREG; smb_fname->st.st_ex_blocks = smb_fname->st.st_ex_size / STAT_ST_BLOCKSIZE + 1; -- 2.14.1 From af006bdf0891c7ca6892d742a23aa145470bd7d7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 11 Apr 2018 11:05:14 -0700 Subject: [PATCH 2/3] s3: smbd. Generic fix for incorrect reporting of stream dos attributes on a directory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According to MS-FSA a stream name does not have separate DOS attribute metadata, so we must return the DOS attribute from the base filename. With one caveat, a non-default stream name can never be a directory. As this is common to all streams data stores, we handle it here instead of inside all stream VFS modules. Otherwise identical logic would have to be added to all streams modules in their [f]get_dos_attribute_fn() VFS calls. Found in real-world use case by Andrew Walker . BUG: https://bugzilla.samba.org/show_bug.cgi?id=13380 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Böhme (cherry picked from commit 118e77d86a7171f589f805fa4f63246b0cb63672) --- source3/smbd/dosmode.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/source3/smbd/dosmode.c b/source3/smbd/dosmode.c index 8a11c8fd62a..7ac876a47bf 100644 --- a/source3/smbd/dosmode.c +++ b/source3/smbd/dosmode.c @@ -681,6 +681,28 @@ uint32_t dos_mode(connection_struct *conn, struct smb_filename *smb_fname) } } + /* + * According to MS-FSA a stream name does not have + * separate DOS attribute metadata, so we must return + * the DOS attribute from the base filename. With one caveat, + * a non-default stream name can never be a directory. + * + * As this is common to all streams data stores, we handle + * it here instead of inside all stream VFS modules. + * + * BUG: https://bugzilla.samba.org/show_bug.cgi?id=13380 + */ + + if (is_ntfs_stream_smb_fname(smb_fname)) { + /* is_ntfs_stream_smb_fname() returns false for a POSIX path. */ + if (!is_ntfs_default_stream_smb_fname(smb_fname)) { + /* + * Non-default stream name, not a posix path. + */ + result &= ~(FILE_ATTRIBUTE_DIRECTORY); + } + } + if (conn->fs_capabilities & FILE_FILE_COMPRESSION) { bool compressed = false; status = dos_mode_check_compressed(conn, smb_fname, -- 2.14.1 From f3195d8fa3558da308fc34a61916c0869d53362e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 11 Apr 2018 10:33:22 -0700 Subject: [PATCH 3/3] s3: tests: Regression test to ensure we can never return a DIRECTORY attribute on a stream. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tests streams_xattr and also streams_depot. Inspired from a real-world test case by Andrew Walker . BUG: https://bugzilla.samba.org/show_bug.cgi?id=13380 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Böhme Autobuild-User(master): Jeremy Allison Autobuild-Date(master): Thu Apr 12 02:04:28 CEST 2018 on sn-devel-144 (cherry picked from commit 82beaf868f252c4bc975ddafd80240af6f679b83) --- selftest/target/Samba3.pm | 4 ++ source3/script/tests/test_smbclient_s3.sh | 76 +++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm index 7e4224a4578..1f80f86945b 100755 --- a/selftest/target/Samba3.pm +++ b/selftest/target/Samba3.pm @@ -2173,6 +2173,10 @@ sub provision($$$$$$$$$) kernel oplocks = yes vfs objects = streams_xattr xattr_tdb +[streams_xattr] + copy = tmp + vfs objects = streams_xattr xattr_tdb + [compound_find] copy = tmp smbd:find async delay usec = 10000 diff --git a/source3/script/tests/test_smbclient_s3.sh b/source3/script/tests/test_smbclient_s3.sh index e48ad30617a..706023b7d19 100755 --- a/source3/script/tests/test_smbclient_s3.sh +++ b/source3/script/tests/test_smbclient_s3.sh @@ -1598,6 +1598,78 @@ EOF return 0 } +# Test xattr_stream correctly reports mode. +# BUG: https://bugzilla.samba.org/show_bug.cgi?id=13380 + +test_stream_directory_xattr() +{ + tmpfile=$PREFIX/smbclient_interactive_prompt_commands +# +# Test against streams_xattr +# + cat > $tmpfile < $tmpfile <