pass 'rdonly' or 'directory' flag to open a directory file.
authorPooja Mahadik <pooja.mahadik@veritas.com>
Tue, 10 Jul 2018 05:47:42 +0000 (11:17 +0530)
committerRalph Boehme <slow@samba.org>
Wed, 11 Jul 2018 00:22:18 +0000 (02:22 +0200)
Signed-off-by: Pooja Mahadik <pooja.mahadik@veritas.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Autobuild-User(master): Ralph Böhme <slow@samba.org>
Autobuild-Date(master): Wed Jul 11 02:22:18 CEST 2018 on sn-devel-144

source3/modules/lib_vxfs.c
source3/modules/vfs_vxfs.c
source3/modules/vfs_vxfs.h

index f9394d6ed331513aa0fdc8bd2c59261723a4f349..dcb5cb304e139128b16c880f25284c522fa69a7c 100644 (file)
@@ -224,11 +224,15 @@ int vxfs_setwxattr_fd(int fd)
        return ret;
 }
 
-int vxfs_setwxattr_path(const char *path)
+int vxfs_setwxattr_path(const char *path, bool is_dir)
 {
        int ret, fd = -1;
 
-       fd = open(path, O_WRONLY);
+       if (is_dir) {
+               fd = open(path, O_RDONLY|O_DIRECTORY);
+       } else {
+               fd = open(path, O_WRONLY);
+       }
        if (fd == -1) {
                DBG_DEBUG("file %s not opened, errno:%s\n",
                           path, strerror(errno));
@@ -259,11 +263,16 @@ int vxfs_clearwxattr_fd(int fd)
        return ret;
 }
 
-int vxfs_clearwxattr_path(const char *path)
+int vxfs_clearwxattr_path(const char *path, bool is_dir)
 {
        int ret, fd = -1;
 
-       fd = open(path, O_WRONLY);
+       if (is_dir) {
+               fd = open(path, O_RDONLY|O_DIRECTORY);
+       } else {
+               fd = open(path, O_WRONLY);
+       }
+
        if (fd == -1) {
                DBG_DEBUG("file %s not opened, errno:%s\n",
                           path, strerror(errno));
@@ -297,7 +306,8 @@ int vxfs_checkwxattr_path(const char *path)
 {
        int ret, fd = -1;
 
-       fd = open(path, O_WRONLY);
+       fd = open(path, O_RDONLY);
+
        if (fd == -1) {
                DBG_DEBUG("file %s not opened, errno:%s\n",
                           path, strerror(errno));
index 3bf3adc620941d4f1f8476cc4c34ff655d1ce981..1295c7541e79ffdd162643ad80583827b1f3ae3f 100644 (file)
@@ -833,11 +833,13 @@ static NTSTATUS vxfs_set_ea_dos_attributes(struct vfs_handle_struct *handle,
                                           uint32_t dosmode)
 {
        NTSTATUS        err;
-       int             ret = 0;
+       int                     ret = 0;
        bool            attrset = false;
+       bool            is_dir = false;
 
        DBG_DEBUG("Entered function\n");
 
+       is_dir = S_ISDIR(smb_fname->st.st_ex_mode);
        if (!(dosmode & FILE_ATTRIBUTE_READONLY)) {
                ret = vxfs_checkwxattr_path(smb_fname->base_name);
                if (ret == -1) {
@@ -848,7 +850,7 @@ static NTSTATUS vxfs_set_ea_dos_attributes(struct vfs_handle_struct *handle,
                }
        }
        if (dosmode & FILE_ATTRIBUTE_READONLY) {
-               ret = vxfs_setwxattr_path(smb_fname->base_name);
+               ret = vxfs_setwxattr_path(smb_fname->base_name, is_dir);
                DBG_DEBUG("ret:%d\n", ret);
                if (ret == -1) {
                        if ((errno != EOPNOTSUPP) && (errno != EINVAL)) {
@@ -861,7 +863,7 @@ static NTSTATUS vxfs_set_ea_dos_attributes(struct vfs_handle_struct *handle,
        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);
+                       ret = vxfs_clearwxattr_path(smb_fname->base_name, is_dir);
                        DBG_DEBUG("ret:%d\n", ret);
                        if ((ret == -1) && (errno != ENOENT)) {
                                return map_nt_error_from_unix(errno);
index f438bad3d9103a72e4d3ad357ca5abc6c31b245d..19755900d7313f09e2f0451cb2b0763d94f513fd 100644 (file)
@@ -31,10 +31,10 @@ int vxfs_removexattr_fd(int, const char *);
 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_path(const char *, bool);
 int vxfs_setwxattr_fd(int);
 
-int vxfs_clearwxattr_path(const char *);
+int vxfs_clearwxattr_path(const char *, bool);
 int vxfs_clearwxattr_fd(int);
 
 int vxfs_checkwxattr_path(const char *);