Implemented two VFS operations(set/fset dos attribute) for vxfs plugin.
Trapping set/clear of read-only attribute.
Signed-off-by: Pooja Mahadik <pooja.mahadik@veritas.com>
Reviewed-by: Ralph Böhme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Sat Sep 30 06:42:10 CEST 2017 on sn-devel-144
#include "smbd/smbd.h"
#include "system/filesys.h"
#include "string.h"
+#include "vfs_vxfs.h"
/*
* Available under GPL at
size_t *len);
static int (*vxfs_removexattr_fd_func) (int fd, const char *name);
static int (*vxfs_listxattr_fd_func) (int fd, void *value, size_t *len);
+static int (*vxfs_setwxattr_fd_func) (int fd);
+static int (*vxfs_clearwxattr_fd_func) (int fd);
+static int (*vxfs_checkwxattr_fd_func) (int fd);
int vxfs_setxattr_fd(int fd, const char *name, const void *value,
size_t len, int flags)
return ret;
}
+int vxfs_setwxattr_fd(int fd)
+{
+ int ret = 0;
+
+ if (vxfs_setwxattr_fd_func == NULL) {
+ errno = ENOSYS;
+ return -1;
+ }
+ ret = vxfs_setwxattr_fd_func(fd);
+ DBG_DEBUG("ret = %d\n", ret);
+ if (ret != 0) {
+ errno = ret;
+ ret = -1;
+ }
+
+ return ret;
+}
+
+int vxfs_setwxattr_path(const char *path)
+{
+ int ret, fd = -1;
+
+ fd = open(path, O_WRONLY);
+ if (fd == -1) {
+ DBG_DEBUG("file %s not opened, errno:%s\n",
+ path, strerror(errno));
+ return -1;
+ }
+
+ ret = vxfs_setwxattr_fd(fd);
+ DBG_DEBUG("ret = %d\n", ret);
+ close(fd);
+
+ return ret;
+}
+
+int vxfs_clearwxattr_fd(int fd)
+{
+ int ret;
+ if (vxfs_clearwxattr_fd_func == NULL) {
+ errno = ENOSYS;
+ return -1;
+ }
+ ret = vxfs_clearwxattr_fd_func(fd);
+ DBG_DEBUG("ret = %d\n", ret);
+ if (ret != 0) {
+ errno = ret;
+ ret = -1;
+ }
+
+ return ret;
+}
+
+int vxfs_clearwxattr_path(const char *path)
+{
+ int ret, fd = -1;
+
+ fd = open(path, O_WRONLY);
+ if (fd == -1) {
+ DBG_DEBUG("file %s not opened, errno:%s\n",
+ path, strerror(errno));
+ return -1;
+ }
+ ret = vxfs_clearwxattr_fd(fd);
+ DBG_DEBUG("ret = %d\n", ret);
+ close(fd);
+
+ return ret;
+}
+
+int vxfs_checkwxattr_fd(int fd)
+{
+ int ret;
+
+ if (vxfs_checkwxattr_fd_func == NULL) {
+ errno = ENOSYS;
+ return -1;
+ }
+ ret = vxfs_checkwxattr_fd_func(fd);
+ DBG_DEBUG("ret = %d\n", ret);
+ if (ret != 0) {
+ errno = ret;
+ ret = -1;
+ }
+ return ret;
+}
+
+int vxfs_checkwxattr_path(const char *path)
+{
+ int ret, fd = -1;
+
+ fd = open(path, O_WRONLY);
+ if (fd == -1) {
+ DBG_DEBUG("file %s not opened, errno:%s\n",
+ path, strerror(errno));
+ return -1;
+ }
+ ret = vxfs_checkwxattr_fd(fd);
+ close(fd);
+
+ return ret;
+}
+
static bool load_lib_vxfs_function(void *lib_handle, void *fn_ptr,
const char *fnc_name)
{
"vxfs_nxattr_remove");
load_lib_vxfs_function(&lib_handle, &vxfs_listxattr_fd_func,
"vxfs_nxattr_list");
+ load_lib_vxfs_function(&lib_handle, &vxfs_setwxattr_fd_func,
+ "vxfs_wattr_set");
+ load_lib_vxfs_function(&lib_handle, &vxfs_clearwxattr_fd_func,
+ "vxfs_wattr_clear");
+ load_lib_vxfs_function(&lib_handle, &vxfs_checkwxattr_fd_func,
+ "vxfs_wattr_check");
}
return result;
}
+static NTSTATUS vxfs_set_ea_dos_attributes(struct vfs_handle_struct *handle,
+ const struct smb_filename *smb_fname,
+ uint32_t dosmode)
+{
+ NTSTATUS err;
+ int ret = 0;
+ bool attrset = false;
+
+ DBG_DEBUG("Entered function\n");
+
+ if (!(dosmode & FILE_ATTRIBUTE_READONLY)) {
+ ret = vxfs_checkwxattr_path(smb_fname->base_name);
+ if (ret == -1) {
+ DBG_DEBUG("ret:%d\n", ret);
+ if ((errno != EOPNOTSUPP) && (errno != ENOENT)) {
+ return map_nt_error_from_unix(errno);
+ }
+ }
+ }
+ if (dosmode & FILE_ATTRIBUTE_READONLY) {
+ ret = vxfs_setwxattr_path(smb_fname->base_name);
+ DBG_DEBUG("ret:%d\n", ret);
+ if (ret == -1) {
+ if ((errno != EOPNOTSUPP) && (errno != EINVAL)) {
+ return map_nt_error_from_unix(errno);
+ }
+ } else {
+ attrset = true;
+ }
+ }
+ err = SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle, smb_fname, dosmode);
+ if (!NT_STATUS_IS_OK(err)) {
+ if (attrset) {
+ ret = vxfs_clearwxattr_path(smb_fname->base_name);
+ DBG_DEBUG("ret:%d\n", ret);
+ if ((ret == -1) && (errno != ENOENT)) {
+ return map_nt_error_from_unix(errno);
+ }
+ }
+ }
+
+ return err;
+}
+
+static NTSTATUS vxfs_fset_ea_dos_attributes(struct vfs_handle_struct *handle,
+ struct files_struct *fsp,
+ uint32_t dosmode)
+{
+ NTSTATUS err;
+ int ret = 0;
+ bool attrset = false;
+
+ DBG_DEBUG("Entered function\n");
+
+ if (!(dosmode & FILE_ATTRIBUTE_READONLY)) {
+ ret = vxfs_checkwxattr_fd(fsp->fh->fd);
+ if (ret == -1) {
+ DBG_DEBUG("ret:%d\n", ret);
+ if ((errno != EOPNOTSUPP) && (errno != ENOENT)) {
+ return map_nt_error_from_unix(errno);
+ }
+ }
+ }
+ if (dosmode & FILE_ATTRIBUTE_READONLY) {
+ ret = vxfs_setwxattr_fd(fsp->fh->fd);
+ DBG_DEBUG("ret:%d\n", ret);
+ if (ret == -1) {
+ if ((errno != EOPNOTSUPP) && (errno != EINVAL)) {
+ return map_nt_error_from_unix(errno);
+ }
+ } else {
+ attrset = true;
+ }
+ }
+ err = SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle, fsp, dosmode);
+ if (!NT_STATUS_IS_OK(err)) {
+ if (attrset) {
+ ret = vxfs_clearwxattr_fd(fsp->fh->fd);
+ DBG_DEBUG("ret:%d\n", ret);
+ if ((ret == -1) && (errno != ENOENT)) {
+ return map_nt_error_from_unix(errno);
+ }
+ }
+ }
+ return err;
+}
+
static int vfs_vxfs_connect(struct vfs_handle_struct *handle,
const char *service, const char *user)
{
.sys_acl_set_fd_fn = vxfs_sys_acl_set_fd,
#endif
+ .set_dos_attributes_fn = vxfs_set_ea_dos_attributes,
+ .fset_dos_attributes_fn = vxfs_fset_ea_dos_attributes,
.getxattr_fn = vxfs_get_xattr,
.fgetxattr_fn = vxfs_fget_xattr,
.listxattr_fn = vxfs_listxattr,
int vxfs_listxattr_path(const char *, char *, size_t);
int vxfs_listxattr_fd(int, char *, size_t);
+int vxfs_setwxattr_path(const char *);
+int vxfs_setwxattr_fd(int);
+
+int vxfs_clearwxattr_path(const char *);
+int vxfs_clearwxattr_fd(int);
+
+int vxfs_checkwxattr_path(const char *);
+int vxfs_checkwxattr_fd(int);
+
void vxfs_init(void);