vfs_gpfs: Move fstatat with DAC_CAP_OVERRIDE to helper function
authorChristof Schmitt <cs@samba.org>
Thu, 26 Oct 2023 21:39:46 +0000 (14:39 -0700)
committerJule Anger <janger@samba.org>
Sat, 25 Nov 2023 18:28:13 +0000 (18:28 +0000)
Allow reuse of this code.

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

Signed-off-by: Christof Schmitt <cs@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
(cherry picked from commit 95319351e37b8b968b798eee66c93852d9ad2d81)

source3/modules/vfs_gpfs.c

index f8ccbca103823c69fb82e4bd2bc3c745ed79882c..d9361fe906faf49d319e8e8b1042f50f3c0ef359 100644 (file)
@@ -1594,6 +1594,25 @@ static NTSTATUS vfs_gpfs_fset_dos_attributes(struct vfs_handle_struct *handle,
        return NT_STATUS_OK;
 }
 
+static int fstatat_with_cap_dac_override(int fd,
+                                        const char *pathname,
+                                        SMB_STRUCT_STAT *sbuf,
+                                        int flags,
+                                        bool fake_dir_create_times)
+{
+       int ret;
+
+       set_effective_capability(DAC_OVERRIDE_CAPABILITY);
+       ret = sys_fstatat(fd,
+                         pathname,
+                         sbuf,
+                         flags,
+                         fake_dir_create_times);
+       drop_effective_capability(DAC_OVERRIDE_CAPABILITY);
+
+       return ret;
+}
+
 static int stat_with_capability(struct vfs_handle_struct *handle,
                                struct smb_filename *smb_fname, int flag)
 {
@@ -1625,14 +1644,11 @@ static int stat_with_capability(struct vfs_handle_struct *handle,
                return -1;
        }
 
-       set_effective_capability(DAC_OVERRIDE_CAPABILITY);
-       ret = sys_fstatat(fd,
-                               rel_name->base_name,
-                               &smb_fname->st,
-                               flag,
-                               fake_dctime);
-
-       drop_effective_capability(DAC_OVERRIDE_CAPABILITY);
+       ret = fstatat_with_cap_dac_override(fd,
+                                           rel_name->base_name,
+                                           &smb_fname->st,
+                                           flag,
+                                           fake_dctime);
 
        TALLOC_FREE(dir_name);
        close(fd);