From: Ralph Boehme Date: Thu, 11 Aug 2022 15:18:13 +0000 (+0200) Subject: smbd: add and use vfs_fget_dos_attributes() X-Git-Tag: talloc-2.4.0~1386 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3f7d8db9945a325020e4d1574289dea9e8331c29;p=thirdparty%2Fsamba.git smbd: add and use vfs_fget_dos_attributes() Commit d71ef1365cdde47aeb3465699181656b0655fa04 caused a regression where the creation date on streams wasn't updated anymore on the stream fsp. By adding a simple wrapper vfs_fget_dos_attributes() that takes care of - passing only the base_fsp to the VFS, so the VFS can be completely agnostic of all the streams related complexity like fake fds, - propagating any updated btime from the base_fsp->fsp_name to the stream_fsp->fsp_name BUG: https://bugzilla.samba.org/show_bug.cgi?id=15126 MR: https://gitlab.com/samba-team/samba/-/merge_requests/2643 Signed-off-by: Ralph Boehme Reviewed-by: Stefan Metzmacher --- diff --git a/selftest/knownfail.d/smb2.streams b/selftest/knownfail.d/smb2.streams deleted file mode 100644 index 9dcebb0ef80..00000000000 --- a/selftest/knownfail.d/smb2.streams +++ /dev/null @@ -1 +0,0 @@ -^samba3.smb2.streams streams_xattr.attributes2 diff --git a/source3/include/proto.h b/source3/include/proto.h index 6a6edc36dfb..f632cf37c08 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -82,6 +82,9 @@ NTSTATUS vfs_at_fspcwd(TALLOC_CTX *mem_ctx, struct connection_struct *conn, struct files_struct **_fsp); +NTSTATUS vfs_fget_dos_attributes(struct files_struct *fsp, + uint32_t *dosmode); + #include "source3/lib/interface.h" /* The following definitions come from lib/ldap_debug_handler.c */ diff --git a/source3/smbd/dosmode.c b/source3/smbd/dosmode.c index 3d69a35b366..3fe84824a94 100644 --- a/source3/smbd/dosmode.c +++ b/source3/smbd/dosmode.c @@ -727,8 +727,7 @@ uint32_t fdos_mode(struct files_struct *fsp) } /* Get the DOS attributes via the VFS if we can */ - status = SMB_VFS_FGET_DOS_ATTRIBUTES( - fsp->conn, metadata_fsp(fsp), &result); + status = vfs_fget_dos_attributes(fsp, &result); if (!NT_STATUS_IS_OK(status)) { /* * Only fall back to using UNIX modes if we get NOT_IMPLEMENTED. diff --git a/source3/smbd/open.c b/source3/smbd/open.c index d5c2f4c830f..3dd9f69b8cc 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -3651,8 +3651,7 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn, */ uint32_t attr = 0; - status = SMB_VFS_FGET_DOS_ATTRIBUTES( - conn, metadata_fsp(smb_fname->fsp), &attr); + status = vfs_fget_dos_attributes(smb_fname->fsp, &attr); if (NT_STATUS_IS_OK(status)) { existing_dos_attributes = attr; } diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c index 09be625ab5f..5833d1b2ab2 100644 --- a/source3/smbd/vfs.c +++ b/source3/smbd/vfs.c @@ -1509,6 +1509,45 @@ NTSTATUS vfs_at_fspcwd(TALLOC_CTX *mem_ctx, return NT_STATUS_OK; } +NTSTATUS vfs_fget_dos_attributes(struct files_struct *fsp, + uint32_t *dosmode) +{ + NTSTATUS status; + + /* + * First make sure to pass the base_fsp to the VFS + */ + status = SMB_VFS_FGET_DOS_ATTRIBUTES( + fsp->conn, metadata_fsp(fsp), dosmode); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + /* + * If this isn't a stream fsp we're done, ... + */ + if (!fsp_is_alternate_stream(fsp)) { + return NT_STATUS_OK; + } + + /* + * ...otherwise the VFS might have updated the btime, propagate the + * btime from the base_fsp to the stream fsp. + */ + + if (fsp->base_fsp->fsp_name->st.st_ex_iflags & ST_EX_IFLAG_CALCULATED_BTIME) { + /* + * Not a value from backend storage, ignore it + */ + return NT_STATUS_OK; + } + + update_stat_ex_create_time(&fsp->fsp_name->st, + fsp->base_fsp->fsp_name->st.st_ex_btime); + + return NT_STATUS_OK; +} + int smb_vfs_call_connect(struct vfs_handle_struct *handle, const char *service, const char *user) {