vfs: add and use fget_ea_dos_attribute()
authorRalph Boehme <slow@samba.org>
Tue, 3 Nov 2020 06:57:03 +0000 (07:57 +0100)
committerRalph Boehme <slow@samba.org>
Wed, 16 Dec 2020 09:08:32 +0000 (09:08 +0000)
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/modules/vfs_default.c
source3/smbd/dosmode.c
source3/smbd/proto.h

index 9de7e9caffa174c9052062419d7e74e4062fcd3f..a9eb7798f0d898c7071c1b99c05efa49638215ee 100644 (file)
@@ -1894,7 +1894,7 @@ static NTSTATUS vfswrap_fget_dos_attributes(struct vfs_handle_struct *handle,
                *dosmode |= FILE_ATTRIBUTE_OFFLINE;
        }
 
-       return get_ea_dos_attribute(handle->conn, fsp->fsp_name, dosmode);
+       return fget_ea_dos_attribute(fsp, dosmode);
 }
 
 static NTSTATUS vfswrap_set_dos_attributes(struct vfs_handle_struct *handle,
index a4a764bc1793fe1350adafaf4f1964e6bfee0a90..b6abbe57688ee02ed6f5bb4cc7fba2fa9328633e 100644 (file)
@@ -436,6 +436,43 @@ NTSTATUS get_ea_dos_attribute(connection_struct *conn,
        return NT_STATUS_OK;
 }
 
+NTSTATUS fget_ea_dos_attribute(struct files_struct *fsp,
+                             uint32_t *pattr)
+{
+       DATA_BLOB blob;
+       ssize_t sizeret;
+       fstring attrstr;
+       NTSTATUS status;
+
+       if (!lp_store_dos_attributes(SNUM(fsp->conn))) {
+               return NT_STATUS_NOT_IMPLEMENTED;
+       }
+
+       /* Don't reset pattr to zero as we may already have filename-based attributes we
+          need to preserve. */
+
+       sizeret = SMB_VFS_FGETXATTR(fsp->base_fsp ? fsp->base_fsp : fsp,
+                                   SAMBA_XATTR_DOS_ATTRIB,
+                                   attrstr,
+                                   sizeof(attrstr));
+       if (sizeret == -1) {
+               DBG_INFO("Cannot get attribute "
+                        "from EA on file %s: Error = %s\n",
+                        fsp_str_dbg(fsp), strerror(errno));
+               return map_nt_error_from_unix(errno);
+       }
+
+       blob.data = (uint8_t *)attrstr;
+       blob.length = sizeret;
+
+       status = parse_dos_attribute_blob(fsp->fsp_name, blob, pattr);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       return NT_STATUS_OK;
+}
+
 /****************************************************************************
  Set DOS attributes in an EA.
  Also sets the create time.
index 38d31839104d95a92a56a35f03e617929e8e4da3..2af994922d5119d3ec3c9a2986b0dad53bd57927 100644 (file)
@@ -290,6 +290,8 @@ bool set_sticky_write_time_fsp(struct files_struct *fsp,
 NTSTATUS get_ea_dos_attribute(connection_struct *conn,
                              struct smb_filename *smb_fname,
                              uint32_t *pattr);
+NTSTATUS fget_ea_dos_attribute(struct files_struct *fsp,
+                             uint32_t *pattr);
 NTSTATUS set_ea_dos_attribute(connection_struct *conn,
                              const struct smb_filename *smb_fname,
                              uint32_t dosmode);