vfs_gpfs: Move stat_with_capability to nfs4_acls.c and rename function
authorChristof Schmitt <cs@samba.org>
Thu, 9 Nov 2023 19:20:38 +0000 (12:20 -0700)
committerJule Anger <janger@samba.org>
Sat, 25 Nov 2023 18:28:13 +0000 (18:28 +0000)
All stat CAP_DAC_OVERRIDE code is moving to nfs4_acls.c to allow reuse
by other filesystem modules. Also rename the function to the slightly
more precise name stat_with_cap_dac_overide.

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

Signed-off-by: Christof Schmitt <cs@samba.org>
Reviewed-by: Björn Jacke <bjacke@samba.org>
(cherry picked from commit 6b1e066c4f354f297fbf99ad93acfaf44e3b89cb)

source3/modules/nfs4_acls.c
source3/modules/nfs4_acls.h
source3/modules/vfs_gpfs.c

index 418c34b4a83fdb0479bbdc4846ce86e36c7b0159..0b29191797b8bc1bef4fb98e920fb3bc8d6e87f6 100644 (file)
@@ -135,6 +135,49 @@ int fstatat_with_cap_dac_override(int fd,
        return ret;
 }
 
+int stat_with_cap_dac_override(struct vfs_handle_struct *handle,
+                              struct smb_filename *smb_fname, int flag)
+{
+       bool fake_dctime = lp_fake_directory_create_times(SNUM(handle->conn));
+       int fd = -1;
+       NTSTATUS status;
+       struct smb_filename *dir_name = NULL;
+       struct smb_filename *rel_name = NULL;
+       int ret = -1;
+#ifdef O_PATH
+       int open_flags = O_PATH;
+#else
+       int open_flags = O_RDONLY;
+#endif
+
+       status = SMB_VFS_PARENT_PATHNAME(handle->conn,
+                                        talloc_tos(),
+                                        smb_fname,
+                                        &dir_name,
+                                        &rel_name);
+       if (!NT_STATUS_IS_OK(status)) {
+               errno = map_errno_from_nt_status(status);
+               return -1;
+       }
+
+       fd = open(dir_name->base_name, open_flags, 0);
+       if (fd == -1) {
+               TALLOC_FREE(dir_name);
+               return -1;
+       }
+
+       ret = fstatat_with_cap_dac_override(fd,
+                                           rel_name->base_name,
+                                           &smb_fname->st,
+                                           flag,
+                                           fake_dctime);
+
+       TALLOC_FREE(dir_name);
+       close(fd);
+
+       return ret;
+}
+
 int fstat_with_cap_dac_override(int fd, SMB_STRUCT_STAT *sbuf,
                                bool fake_dir_create_times)
 {
index edb767f1ce86817ec7f4697cada3db7822a0a7ad..828e1da6c39b8499d9139a06a8d298f88c4b9ae0 100644 (file)
@@ -124,6 +124,9 @@ int fstatat_with_cap_dac_override(int fd,
                                  int flags,
                                  bool fake_dir_create_times);
 
+int stat_with_cap_dac_override(struct vfs_handle_struct *handle,
+                              struct smb_filename *smb_fname, int flag);
+
 int fstat_with_cap_dac_override(int fd, SMB_STRUCT_STAT *sbuf,
                                bool fake_dir_create_times);
 
index 7f3dd6e7eb0c20b2c8bd807ace8a87d2b0be5a64..57f3890f66fa408cd22b4bddfd4f6c12d2267adf 100644 (file)
@@ -1594,49 +1594,6 @@ static NTSTATUS vfs_gpfs_fset_dos_attributes(struct vfs_handle_struct *handle,
        return NT_STATUS_OK;
 }
 
-static int stat_with_capability(struct vfs_handle_struct *handle,
-                               struct smb_filename *smb_fname, int flag)
-{
-       bool fake_dctime = lp_fake_directory_create_times(SNUM(handle->conn));
-       int fd = -1;
-       NTSTATUS status;
-       struct smb_filename *dir_name = NULL;
-       struct smb_filename *rel_name = NULL;
-       int ret = -1;
-#ifdef O_PATH
-       int open_flags = O_PATH;
-#else
-       int open_flags = O_RDONLY;
-#endif
-
-       status = SMB_VFS_PARENT_PATHNAME(handle->conn,
-                                        talloc_tos(),
-                                        smb_fname,
-                                        &dir_name,
-                                        &rel_name);
-       if (!NT_STATUS_IS_OK(status)) {
-               errno = map_errno_from_nt_status(status);
-               return -1;
-       }
-
-       fd = open(dir_name->base_name, open_flags, 0);
-       if (fd == -1) {
-               TALLOC_FREE(dir_name);
-               return -1;
-       }
-
-       ret = fstatat_with_cap_dac_override(fd,
-                                           rel_name->base_name,
-                                           &smb_fname->st,
-                                           flag,
-                                           fake_dctime);
-
-       TALLOC_FREE(dir_name);
-       close(fd);
-
-       return ret;
-}
-
 static int vfs_gpfs_stat(struct vfs_handle_struct *handle,
                         struct smb_filename *smb_fname)
 {
@@ -1646,7 +1603,7 @@ static int vfs_gpfs_stat(struct vfs_handle_struct *handle,
        if (ret == -1 && errno == EACCES) {
                DEBUG(10, ("Trying stat with capability for %s\n",
                           smb_fname->base_name));
-               ret = stat_with_capability(handle, smb_fname, 0);
+               ret = stat_with_cap_dac_override(handle, smb_fname, 0);
        }
        return ret;
 }
@@ -1681,8 +1638,8 @@ static int vfs_gpfs_lstat(struct vfs_handle_struct *handle,
        if (ret == -1 && errno == EACCES) {
                DEBUG(10, ("Trying lstat with capability for %s\n",
                           smb_fname->base_name));
-               ret = stat_with_capability(handle, smb_fname,
-                                          AT_SYMLINK_NOFOLLOW);
+               ret = stat_with_cap_dac_override(handle, smb_fname,
+                                                AT_SYMLINK_NOFOLLOW);
        }
        return ret;
 }