1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-02 09:47:23 +03:00

s3: vfs: Use the new VFS functions for setting and getting DOS attributes.

This will make it easier to support those systems and file systems that
can store DOS attributes.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Richard Sharpe <rsharpe@samba.org>

Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Sun Mar 27 09:23:42 CEST 2016 on sn-devel-144
This commit is contained in:
Jeremy Allison 2016-03-25 15:32:09 -07:00
parent a4e6250442
commit 82801f9ec8

View File

@ -27,7 +27,7 @@
#include "lib/param/loadparm.h" #include "lib/param/loadparm.h"
static NTSTATUS get_file_handle_for_metadata(connection_struct *conn, static NTSTATUS get_file_handle_for_metadata(connection_struct *conn,
struct smb_filename *smb_fname, const struct smb_filename *smb_fname,
files_struct **ret_fsp, files_struct **ret_fsp,
bool *need_close); bool *need_close);
@ -260,9 +260,9 @@ static uint32_t dos_mode_from_sbuf(connection_struct *conn,
This can also pull the create time into the stat struct inside smb_fname. This can also pull the create time into the stat struct inside smb_fname.
****************************************************************************/ ****************************************************************************/
static bool get_ea_dos_attribute(connection_struct *conn, NTSTATUS get_ea_dos_attribute(connection_struct *conn,
struct smb_filename *smb_fname, struct smb_filename *smb_fname,
uint32_t *pattr) uint32_t *pattr)
{ {
struct xattr_DOSATTRIB dosattrib; struct xattr_DOSATTRIB dosattrib;
enum ndr_err_code ndr_err; enum ndr_err_code ndr_err;
@ -272,7 +272,7 @@ static bool get_ea_dos_attribute(connection_struct *conn,
uint32_t dosattr; uint32_t dosattr;
if (!lp_store_dos_attributes(SNUM(conn))) { if (!lp_store_dos_attributes(SNUM(conn))) {
return False; return NT_STATUS_NOT_IMPLEMENTED;
} }
/* Don't reset pattr to zero as we may already have filename-based attributes we /* Don't reset pattr to zero as we may already have filename-based attributes we
@ -285,7 +285,7 @@ static bool get_ea_dos_attribute(connection_struct *conn,
DBG_INFO("Cannot get attribute " DBG_INFO("Cannot get attribute "
"from EA on file %s: Error = %s\n", "from EA on file %s: Error = %s\n",
smb_fname_str_dbg(smb_fname), strerror(errno)); smb_fname_str_dbg(smb_fname), strerror(errno));
return False; return map_nt_error_from_unix(errno);
} }
blob.data = (uint8_t *)attrstr; blob.data = (uint8_t *)attrstr;
@ -299,7 +299,7 @@ static bool get_ea_dos_attribute(connection_struct *conn,
"from EA on file %s: Error = %s\n", "from EA on file %s: Error = %s\n",
smb_fname_str_dbg(smb_fname), smb_fname_str_dbg(smb_fname),
ndr_errstr(ndr_err))); ndr_errstr(ndr_err)));
return false; return ndr_map_error2ntstatus(ndr_err);
} }
DEBUG(10,("get_ea_dos_attribute: %s attr = %s\n", DEBUG(10,("get_ea_dos_attribute: %s attr = %s\n",
@ -352,7 +352,8 @@ static bool get_ea_dos_attribute(connection_struct *conn,
DEBUG(1,("get_ea_dos_attribute: Badly formed DOSATTRIB on " DEBUG(1,("get_ea_dos_attribute: Badly formed DOSATTRIB on "
"file %s - %s\n", smb_fname_str_dbg(smb_fname), "file %s - %s\n", smb_fname_str_dbg(smb_fname),
attrstr)); attrstr));
return false; /* Should this be INTERNAL_ERROR? */
return NT_STATUS_INVALID_PARAMETER;
} }
if (S_ISDIR(smb_fname->st.st_ex_mode)) { if (S_ISDIR(smb_fname->st.st_ex_mode)) {
@ -363,7 +364,7 @@ static bool get_ea_dos_attribute(connection_struct *conn,
dos_mode_debug_print(__func__, *pattr); dos_mode_debug_print(__func__, *pattr);
return True; return NT_STATUS_OK;
} }
/**************************************************************************** /****************************************************************************
@ -371,14 +372,18 @@ static bool get_ea_dos_attribute(connection_struct *conn,
Also sets the create time. Also sets the create time.
****************************************************************************/ ****************************************************************************/
static bool set_ea_dos_attribute(connection_struct *conn, NTSTATUS set_ea_dos_attribute(connection_struct *conn,
struct smb_filename *smb_fname, const struct smb_filename *smb_fname,
uint32_t dosmode) uint32_t dosmode)
{ {
struct xattr_DOSATTRIB dosattrib; struct xattr_DOSATTRIB dosattrib;
enum ndr_err_code ndr_err; enum ndr_err_code ndr_err;
DATA_BLOB blob; DATA_BLOB blob;
if (!lp_store_dos_attributes(SNUM(conn))) {
return NT_STATUS_NOT_IMPLEMENTED;
}
ZERO_STRUCT(dosattrib); ZERO_STRUCT(dosattrib);
ZERO_STRUCT(blob); ZERO_STRUCT(blob);
@ -401,17 +406,18 @@ static bool set_ea_dos_attribute(connection_struct *conn,
if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
DEBUG(5, ("create_acl_blob: ndr_push_xattr_DOSATTRIB failed: %s\n", DEBUG(5, ("create_acl_blob: ndr_push_xattr_DOSATTRIB failed: %s\n",
ndr_errstr(ndr_err))); ndr_errstr(ndr_err)));
return false; return ndr_map_error2ntstatus(ndr_err);
} }
if (blob.data == NULL || blob.length == 0) { if (blob.data == NULL || blob.length == 0) {
return false; /* Should this be INTERNAL_ERROR? */
return NT_STATUS_INVALID_PARAMETER;
} }
if (SMB_VFS_SETXATTR(conn, smb_fname->base_name, if (SMB_VFS_SETXATTR(conn, smb_fname->base_name,
SAMBA_XATTR_DOS_ATTRIB, blob.data, blob.length, SAMBA_XATTR_DOS_ATTRIB, blob.data, blob.length,
0) == -1) { 0) == -1) {
bool ret = false; NTSTATUS status = NT_STATUS_OK;
bool need_close = false; bool need_close = false;
files_struct *fsp = NULL; files_struct *fsp = NULL;
@ -419,7 +425,7 @@ static bool set_ea_dos_attribute(connection_struct *conn,
DBG_INFO("Cannot set " DBG_INFO("Cannot set "
"attribute EA on file %s: Error = %s\n", "attribute EA on file %s: Error = %s\n",
smb_fname_str_dbg(smb_fname), strerror(errno)); smb_fname_str_dbg(smb_fname), strerror(errno));
return false; return map_nt_error_from_unix(errno);
} }
/* We want DOS semantics, ie allow non owner with write permission to change the /* We want DOS semantics, ie allow non owner with write permission to change the
@ -428,10 +434,10 @@ static bool set_ea_dos_attribute(connection_struct *conn,
/* Check if we have write access. */ /* Check if we have write access. */
if(!CAN_WRITE(conn) || !lp_dos_filemode(SNUM(conn))) if(!CAN_WRITE(conn) || !lp_dos_filemode(SNUM(conn)))
return false; return NT_STATUS_ACCESS_DENIED;
if (!can_write_to_file(conn, smb_fname)) { if (!can_write_to_file(conn, smb_fname)) {
return false; return NT_STATUS_ACCESS_DENIED;
} }
/* /*
@ -439,29 +445,30 @@ static bool set_ea_dos_attribute(connection_struct *conn,
* metadata operation under root. * metadata operation under root.
*/ */
if (!NT_STATUS_IS_OK(get_file_handle_for_metadata(conn, status = get_file_handle_for_metadata(conn,
smb_fname, smb_fname,
&fsp, &fsp,
&need_close))) { &need_close);
return false; if (!NT_STATUS_IS_OK(status)) {
return status;
} }
become_root(); become_root();
if (SMB_VFS_FSETXATTR(fsp, if (SMB_VFS_FSETXATTR(fsp,
SAMBA_XATTR_DOS_ATTRIB, blob.data, SAMBA_XATTR_DOS_ATTRIB, blob.data,
blob.length, 0) == 0) { blob.length, 0) == 0) {
ret = true; status = NT_STATUS_OK;
} }
unbecome_root(); unbecome_root();
if (need_close) { if (need_close) {
close_file(NULL, fsp, NORMAL_CLOSE); close_file(NULL, fsp, NORMAL_CLOSE);
} }
return ret; return status;
} }
DEBUG(10,("set_ea_dos_attribute: set EA 0x%x on file %s\n", DEBUG(10,("set_ea_dos_attribute: set EA 0x%x on file %s\n",
(unsigned int)dosmode, (unsigned int)dosmode,
smb_fname_str_dbg(smb_fname))); smb_fname_str_dbg(smb_fname)));
return true; return NT_STATUS_OK;
} }
/**************************************************************************** /****************************************************************************
@ -565,6 +572,7 @@ uint32_t dos_mode(connection_struct *conn, struct smb_filename *smb_fname)
{ {
uint32_t result = 0; uint32_t result = 0;
bool offline; bool offline;
NTSTATUS status = NT_STATUS_OK;
DEBUG(8,("dos_mode: %s\n", smb_fname_str_dbg(smb_fname))); DEBUG(8,("dos_mode: %s\n", smb_fname_str_dbg(smb_fname)));
@ -589,8 +597,9 @@ uint32_t dos_mode(connection_struct *conn, struct smb_filename *smb_fname)
} }
} }
/* Get the DOS attributes from an EA by preference. */ /* Get the DOS attributes via the VFS if we can */
if (!get_ea_dos_attribute(conn, smb_fname, &result)) { status = SMB_VFS_GET_DOS_ATTRIBUTES(conn, smb_fname, &result);
if (!NT_STATUS_IS_OK(status)) {
result |= dos_mode_from_sbuf(conn, smb_fname); result |= dos_mode_from_sbuf(conn, smb_fname);
} }
@ -601,8 +610,8 @@ uint32_t dos_mode(connection_struct *conn, struct smb_filename *smb_fname)
if (conn->fs_capabilities & FILE_FILE_COMPRESSION) { if (conn->fs_capabilities & FILE_FILE_COMPRESSION) {
bool compressed = false; bool compressed = false;
NTSTATUS status = dos_mode_check_compressed(conn, smb_fname, status = dos_mode_check_compressed(conn, smb_fname,
&compressed); &compressed);
if (NT_STATUS_IS_OK(status) && compressed) { if (NT_STATUS_IS_OK(status) && compressed) {
result |= FILE_ATTRIBUTE_COMPRESSED; result |= FILE_ATTRIBUTE_COMPRESSED;
} }
@ -696,23 +705,27 @@ int file_set_dosmode(connection_struct *conn, struct smb_filename *smb_fname,
smb_fname->st.st_ex_btime = new_create_timespec; smb_fname->st.st_ex_btime = new_create_timespec;
/* Store the DOS attributes in an EA by preference. */ /* Store the DOS attributes in an EA by preference. */
if (lp_store_dos_attributes(SNUM(conn))) { status = SMB_VFS_SET_DOS_ATTRIBUTES(conn, smb_fname, dosmode);
/* if (NT_STATUS_IS_OK(status)) {
* Don't fall back to using UNIX modes. Finally
* follow the smb.conf manpage.
*/
if (!set_ea_dos_attribute(conn, smb_fname, dosmode)) {
return -1;
}
if (!newfile) { if (!newfile) {
notify_fname(conn, NOTIFY_ACTION_MODIFIED, notify_fname(conn, NOTIFY_ACTION_MODIFIED,
FILE_NOTIFY_CHANGE_ATTRIBUTES, FILE_NOTIFY_CHANGE_ATTRIBUTES,
smb_fname->base_name); smb_fname->base_name);
} }
smb_fname->st.st_ex_mode = unixmode; smb_fname->st.st_ex_mode = unixmode;
return 0; return 0;
} else {
/*
* Only fall back to using UNIX modes if
* we get NOT_IMPLEMENTED.
*/
if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED)) {
errno = map_errno_from_nt_status(status);
return -1;
}
} }
/* Fall back to UNIX modes. */
unixmode = unix_mode(conn, dosmode, smb_fname, parent_dir); unixmode = unix_mode(conn, dosmode, smb_fname, parent_dir);
/* preserve the file type bits */ /* preserve the file type bits */
@ -896,12 +909,9 @@ NTSTATUS file_set_sparse(connection_struct *conn,
} }
/* Store the DOS attributes in an EA. */ /* Store the DOS attributes in an EA. */
if (!set_ea_dos_attribute(conn, fsp->fsp_name, status = SMB_VFS_FSET_DOS_ATTRIBUTES(conn, fsp, new_dosmode);
new_dosmode)) { if (!NT_STATUS_IS_OK(status)) {
if (errno == 0) { return status;
errno = EIO;
}
return map_nt_error_from_unix(errno);
} }
notify_fname(conn, NOTIFY_ACTION_MODIFIED, notify_fname(conn, NOTIFY_ACTION_MODIFIED,
@ -1080,13 +1090,14 @@ struct timespec get_change_timespec(connection_struct *conn,
****************************************************************************/ ****************************************************************************/
static NTSTATUS get_file_handle_for_metadata(connection_struct *conn, static NTSTATUS get_file_handle_for_metadata(connection_struct *conn,
struct smb_filename *smb_fname, const struct smb_filename *smb_fname,
files_struct **ret_fsp, files_struct **ret_fsp,
bool *need_close) bool *need_close)
{ {
NTSTATUS status; NTSTATUS status;
files_struct *fsp; files_struct *fsp;
struct file_id file_id; struct file_id file_id;
struct smb_filename *smb_fname_cp = NULL;
*need_close = false; *need_close = false;
@ -1105,12 +1116,18 @@ static NTSTATUS get_file_handle_for_metadata(connection_struct *conn,
} }
} }
smb_fname_cp = cp_smb_filename(talloc_tos(),
smb_fname);
if (smb_fname_cp == NULL) {
return NT_STATUS_NO_MEMORY;
}
/* Opens an INTERNAL_OPEN_ONLY write handle. */ /* Opens an INTERNAL_OPEN_ONLY write handle. */
status = SMB_VFS_CREATE_FILE( status = SMB_VFS_CREATE_FILE(
conn, /* conn */ conn, /* conn */
NULL, /* req */ NULL, /* req */
0, /* root_dir_fid */ 0, /* root_dir_fid */
smb_fname, /* fname */ smb_fname_cp, /* fname */
FILE_WRITE_DATA, /* access_mask */ FILE_WRITE_DATA, /* access_mask */
(FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */ (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
FILE_SHARE_DELETE), FILE_SHARE_DELETE),
@ -1127,6 +1144,8 @@ static NTSTATUS get_file_handle_for_metadata(connection_struct *conn,
NULL, /* pinfo */ NULL, /* pinfo */
NULL, NULL); /* create context */ NULL, NULL); /* create context */
TALLOC_FREE(smb_fname_cp);
if (NT_STATUS_IS_OK(status)) { if (NT_STATUS_IS_OK(status)) {
*need_close = true; *need_close = true;
} }