vfs_gpfs: Implement CAP_DAC_OVERRIDE for fstat
authorChristof Schmitt <cs@samba.org>
Thu, 26 Oct 2023 21:45:34 +0000 (14:45 -0700)
committerJule Anger <janger@samba.org>
Sat, 25 Nov 2023 18:27:15 +0000 (18:27 +0000)
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 cbdc16a7cfa225d1cf9109fafe85e9d14729700e)

source3/modules/vfs_gpfs.c

index 6c3c217b5dd4e997d82dcc358a6aaff3c6fd5361..1e708454f6d7aee9567b413c16ddddbe3f526c86 100644 (file)
@@ -1670,6 +1670,29 @@ static int vfs_gpfs_stat(struct vfs_handle_struct *handle,
        return ret;
 }
 
+static int vfs_gpfs_fstat(struct vfs_handle_struct *handle,
+                         struct files_struct *fsp,
+                         SMB_STRUCT_STAT *sbuf)
+{
+       int ret;
+
+       ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
+       if (ret == -1 && errno == EACCES) {
+               bool fake_dctime =
+                       lp_fake_directory_create_times(SNUM(handle->conn));
+
+               DBG_DEBUG("fstat for %s failed with EACCES. Trying with "
+                         "CAP_DAC_OVERRIDE.\n", fsp->fsp_name->base_name);
+               ret = fstatat_with_cap_dac_override(fsp_get_pathref_fd(fsp),
+                                                   "",
+                                                   sbuf,
+                                                   AT_EMPTY_PATH,
+                                                   fake_dctime);
+       }
+
+       return ret;
+}
+
 static int vfs_gpfs_lstat(struct vfs_handle_struct *handle,
                          struct smb_filename *smb_fname)
 {
@@ -2625,6 +2648,7 @@ static struct vfs_fn_pointers vfs_gpfs_fns = {
        .fchmod_fn = vfs_gpfs_fchmod,
        .close_fn = vfs_gpfs_close,
        .stat_fn = vfs_gpfs_stat,
+       .fstat_fn = vfs_gpfs_fstat,
        .lstat_fn = vfs_gpfs_lstat,
        .fntimes_fn = vfs_gpfs_fntimes,
        .aio_force_fn = vfs_gpfs_aio_force,