]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: add and use vfs_fget_dos_attributes()
authorRalph Boehme <slow@samba.org>
Thu, 11 Aug 2022 15:18:13 +0000 (17:18 +0200)
committerJule Anger <janger@samba.org>
Tue, 6 Sep 2022 06:32:13 +0000 (06:32 +0000)
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 <slow@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
(backported from commit 3f7d8db9945a325020e4d1574289dea9e8331c29)
[slow@samba.org: also update itime and file_id]

selftest/knownfail.d/smb2.streams [deleted file]
source3/include/proto.h
source3/smbd/dosmode.c
source3/smbd/open.c
source3/smbd/vfs.c

diff --git a/selftest/knownfail.d/smb2.streams b/selftest/knownfail.d/smb2.streams
deleted file mode 100644 (file)
index 9dcebb0..0000000
+++ /dev/null
@@ -1 +0,0 @@
-^samba3.smb2.streams streams_xattr.attributes2
index 20d026f83b373c8a1606daad0727a0150cc5946e..f38b286cab1aefa69d07dd0ecb87295c6e4668c9 100644 (file)
@@ -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  */
index 1a38cb3e154a9e107975691bb7063ae12e6101f6..f32401e787b1db65444bd8619ccfd3c93344f297 100644 (file)
@@ -754,8 +754,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.
index 3926f376164e335e2488c46e6ec3b870b7a2c18b..7a91b2a6d5902274783ce6b0d81d4262c71052fe 100644 (file)
@@ -3573,8 +3573,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;
                        }
index a6022902c1dde0ca2762d8efac4c2ffdb0a2e574..f0a5cba8416b63e72a1a26a3293f6a79563b1570 100644 (file)
@@ -1513,6 +1513,60 @@ 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))
+       {
+               update_stat_ex_create_time(
+                       &fsp->fsp_name->st,
+                       fsp->base_fsp->fsp_name->st.st_ex_btime);
+       }
+
+       if (!(fsp->base_fsp->fsp_name->st.st_ex_iflags &
+             ST_EX_IFLAG_CALCULATED_ITIME))
+       {
+               update_stat_ex_itime(
+                       &fsp->fsp_name->st,
+                       fsp->base_fsp->fsp_name->st.st_ex_itime);
+       }
+
+       if (!(fsp->base_fsp->fsp_name->st.st_ex_iflags &
+             ST_EX_IFLAG_CALCULATED_FILE_ID))
+       {
+               update_stat_ex_file_id(
+                       &fsp->fsp_name->st,
+                       fsp->base_fsp->fsp_name->st.st_ex_file_id);
+       }
+
+
+       return NT_STATUS_OK;
+}
+
 int smb_vfs_call_connect(struct vfs_handle_struct *handle,
                         const char *service, const char *user)
 {