From: Ralph Boehme Date: Tue, 3 Nov 2020 06:57:03 +0000 (+0100) Subject: vfs: add and use fget_ea_dos_attribute() X-Git-Tag: samba-4.14.0rc1~262 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d466ba6d61365f72618dd3093706b8706b8f7c93;p=thirdparty%2Fsamba.git vfs: add and use fget_ea_dos_attribute() Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c index 9de7e9caffa..a9eb7798f0d 100644 --- a/source3/modules/vfs_default.c +++ b/source3/modules/vfs_default.c @@ -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, diff --git a/source3/smbd/dosmode.c b/source3/smbd/dosmode.c index a4a764bc179..b6abbe57688 100644 --- a/source3/smbd/dosmode.c +++ b/source3/smbd/dosmode.c @@ -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. diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 38d31839104..2af994922d5 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -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);