VFS: Modify chmod to take a const struct smb_filename * instead of const char *
authorJeremy Allison <jra@samba.org>
Wed, 2 Mar 2016 00:20:25 +0000 (16:20 -0800)
committerRalph Boehme <slow@samba.org>
Thu, 3 Mar 2016 08:04:14 +0000 (09:04 +0100)
Preparing to reduce use of lp_posix_pathnames().

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
28 files changed:
examples/VFS/skel_opaque.c
examples/VFS/skel_transparent.c
source3/include/vfs.h
source3/include/vfs_macros.h
source3/modules/vfs_acl_common.c
source3/modules/vfs_audit.c
source3/modules/vfs_cap.c
source3/modules/vfs_catia.c
source3/modules/vfs_ceph.c
source3/modules/vfs_default.c
source3/modules/vfs_extd_audit.c
source3/modules/vfs_fruit.c
source3/modules/vfs_full_audit.c
source3/modules/vfs_glusterfs.c
source3/modules/vfs_gpfs.c
source3/modules/vfs_linux_xfs_sgid.c
source3/modules/vfs_media_harmony.c
source3/modules/vfs_netatalk.c
source3/modules/vfs_shadow_copy2.c
source3/modules/vfs_snapper.c
source3/modules/vfs_time_audit.c
source3/modules/vfs_unityed_media.c
source3/smbd/dosmode.c
source3/smbd/open.c
source3/smbd/posix_acls.c
source3/smbd/trans2.c
source3/smbd/vfs.c
source3/torture/cmd_vfs.c

index 4ffdacc..f772a9f 100644 (file)
@@ -367,7 +367,9 @@ static int skel_unlink(vfs_handle_struct *handle,
        return -1;
 }
 
-static int skel_chmod(vfs_handle_struct *handle, const char *path, mode_t mode)
+static int skel_chmod(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       mode_t mode)
 {
        errno = ENOSYS;
        return -1;
index 5d3ffb7..bea2cd4 100644 (file)
@@ -475,9 +475,11 @@ static int skel_unlink(vfs_handle_struct *handle,
        return SMB_VFS_NEXT_UNLINK(handle, smb_fname);
 }
 
-static int skel_chmod(vfs_handle_struct *handle, const char *path, mode_t mode)
+static int skel_chmod(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       mode_t mode)
 {
-       return SMB_VFS_NEXT_CHMOD(handle, path, mode);
+       return SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
 }
 
 static int skel_fchmod(vfs_handle_struct *handle, files_struct *fsp,
index 9ea4e75..6a6c865 100644 (file)
 /* Version 35 - Change opendir from const char *, to
                const struct smb_filename * */
 /* Version 35 - Wrap aio async funtions args in a struct vfs_aio_state */
+/* Version 35 - Change chmod from const char *, to
+               const struct smb_filename * */
 
 #define SMB_VFS_INTERFACE_VERSION 35
 
@@ -638,7 +640,9 @@ struct vfs_fn_pointers {
        uint64_t (*get_alloc_size_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, const SMB_STRUCT_STAT *sbuf);
        int (*unlink_fn)(struct vfs_handle_struct *handle,
                         const struct smb_filename *smb_fname);
-       int (*chmod_fn)(struct vfs_handle_struct *handle, const char *path, mode_t mode);
+       int (*chmod_fn)(struct vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       mode_t mode);
        int (*fchmod_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, mode_t mode);
        int (*chown_fn)(struct vfs_handle_struct *handle, const char *path, uid_t uid, gid_t gid);
        int (*fchown_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, uid_t uid, gid_t gid);
@@ -1082,8 +1086,9 @@ uint64_t smb_vfs_call_get_alloc_size(struct vfs_handle_struct *handle,
                                     const SMB_STRUCT_STAT *sbuf);
 int smb_vfs_call_unlink(struct vfs_handle_struct *handle,
                        const struct smb_filename *smb_fname);
-int smb_vfs_call_chmod(struct vfs_handle_struct *handle, const char *path,
-                      mode_t mode);
+int smb_vfs_call_chmod(struct vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       mode_t mode);
 int smb_vfs_call_fchmod(struct vfs_handle_struct *handle,
                        struct files_struct *fsp, mode_t mode);
 int smb_vfs_call_chown(struct vfs_handle_struct *handle, const char *path,
index 2e8ca18..6dc257b 100644 (file)
 #define SMB_VFS_NEXT_UNLINK(handle, path) \
        smb_vfs_call_unlink((handle)->next, (path))
 
-#define SMB_VFS_CHMOD(conn, path, mode) \
-       smb_vfs_call_chmod((conn)->vfs_handles, (path), (mode))
-#define SMB_VFS_NEXT_CHMOD(handle, path, mode) \
-       smb_vfs_call_chmod((handle)->next, (path), (mode))
+#define SMB_VFS_CHMOD(conn, smb_fname, mode) \
+       smb_vfs_call_chmod((conn)->vfs_handles, (smb_fname), (mode))
+#define SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode) \
+       smb_vfs_call_chmod((handle)->next, (smb_fname), (mode))
 
 #define SMB_VFS_FCHMOD(fsp, mode) \
        smb_vfs_call_fchmod((fsp)->conn->vfs_handles, (fsp), (mode))
index 0c0cf83..2684106 100644 (file)
@@ -1084,11 +1084,12 @@ static int unlink_acl_common(struct vfs_handle_struct *handle,
 }
 
 static int chmod_acl_module_common(struct vfs_handle_struct *handle,
-                       const char *path, mode_t mode)
+                       const struct smb_filename *smb_fname,
+                       mode_t mode)
 {
        if (lp_posix_pathnames()) {
                /* Only allow this on POSIX pathnames. */
-               return SMB_VFS_NEXT_CHMOD(handle, path, mode);
+               return SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
        }
        return 0;
 }
index fa47b3c..92b69b1 100644 (file)
@@ -217,14 +217,16 @@ static int audit_unlink(vfs_handle_struct *handle,
        return result;
 }
 
-static int audit_chmod(vfs_handle_struct *handle, const char *path, mode_t mode)
+static int audit_chmod(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       mode_t mode)
 {
        int result;
 
-       result = SMB_VFS_NEXT_CHMOD(handle, path, mode);
+       result = SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
 
        syslog(audit_syslog_priority(handle), "chmod %s mode 0x%x %s%s\n",
-              path, mode,
+              smb_fname->base_name, mode,
               (result < 0) ? "failed: " : "",
               (result < 0) ? strerror(errno) : "");
 
index f96455c..479c2c2 100644 (file)
@@ -304,15 +304,36 @@ static int cap_unlink(vfs_handle_struct *handle,
        return ret;
 }
 
-static int cap_chmod(vfs_handle_struct *handle, const char *path, mode_t mode)
+static int cap_chmod(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       mode_t mode)
 {
-       char *cappath = capencode(talloc_tos(), path);
+       struct smb_filename *cap_smb_fname = NULL;
+       char *cappath = capencode(talloc_tos(), smb_fname->base_name);
+       int ret;
+       int saved_errno;
 
        if (!cappath) {
                errno = ENOMEM;
                return -1;
        }
-       return SMB_VFS_NEXT_CHMOD(handle, cappath, mode);
+
+       cap_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       cappath,
+                                       NULL,
+                                       NULL);
+       if (cap_smb_fname == NULL) {
+               TALLOC_FREE(cappath);
+               errno = ENOMEM;
+               return -1;
+       }
+
+       ret = SMB_VFS_NEXT_CHMOD(handle, cap_smb_fname, mode);
+       saved_errno = errno;
+       TALLOC_FREE(cappath);
+       TALLOC_FREE(cap_smb_fname);
+       errno = saved_errno;
+       return ret;
 }
 
 static int cap_chown(vfs_handle_struct *handle, const char *path, uid_t uid, gid_t gid)
index 9f42e5f..7f06fb7 100644 (file)
@@ -565,22 +565,39 @@ static int catia_lchown(vfs_handle_struct *handle,
        return ret;
 }
 
-static int catia_chmod(vfs_handle_struct *handle, const char *path, mode_t mode)
+static int catia_chmod(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       mode_t mode)
 {
        char *name = NULL;
        NTSTATUS status;
        int ret;
+       int saved_errno;
+       struct smb_filename *catia_smb_fname = NULL;
 
-       status = catia_string_replace_allocate(handle->conn, path,
-                                       &name, vfs_translate_to_unix);
+       status = catia_string_replace_allocate(handle->conn,
+                                       smb_fname->base_name,
+                                       &name,
+                                       vfs_translate_to_unix);
        if (!NT_STATUS_IS_OK(status)) {
                errno = map_errno_from_nt_status(status);
                return -1;
        }
+       catia_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       name,
+                                       NULL,
+                                       NULL);
+       if (catia_smb_fname == NULL) {
+               TALLOC_FREE(name);
+               errno = ENOMEM;
+               return -1;
+       }
 
-       ret = SMB_VFS_NEXT_CHMOD(handle, name, mode);
+       ret = SMB_VFS_NEXT_CHMOD(handle, catia_smb_fname, mode);
+       saved_errno = errno;
        TALLOC_FREE(name);
-
+       TALLOC_FREE(catia_smb_fname);
+       errno = saved_errno;
        return ret;
 }
 
index 2e1b623..e61c39d 100644 (file)
@@ -629,11 +629,16 @@ static int cephwrap_unlink(struct vfs_handle_struct *handle,
        WRAP_RETURN(result);
 }
 
-static int cephwrap_chmod(struct vfs_handle_struct *handle,  const char *path, mode_t mode)
+static int cephwrap_chmod(struct vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       mode_t mode)
 {
        int result;
 
-       DEBUG(10, ("[CEPH] chmod(%p, %s, %d)\n", handle, path, mode));
+       DEBUG(10, ("[CEPH] chmod(%p, %s, %d)\n",
+               handle,
+               smb_fname->base_name,
+               mode));
 
        /*
         * We need to do this due to the fact that the default POSIX ACL
@@ -644,14 +649,17 @@ static int cephwrap_chmod(struct vfs_handle_struct *handle,  const char *path, m
 
        {
                int saved_errno = errno; /* We might get ENOSYS */
-               if ((result = SMB_VFS_CHMOD_ACL(handle->conn, path, mode)) == 0) {
+               result = SMB_VFS_CHMOD_ACL(handle->conn,
+                                       smb_fname->base_name,
+                                       mode);
+               if (result == 0) {
                        return result;
                }
                /* Error - return the old errno. */
                errno = saved_errno;
        }
 
-       result = ceph_chmod(handle->data, path, mode);
+       result = ceph_chmod(handle->data, smb_fname->base_name, mode);
        DEBUG(10, ("[CEPH] chmod(...) = %d\n", result));
        WRAP_RETURN(result);
 }
index 64592a7..fbb0bcb 100644 (file)
@@ -1676,7 +1676,9 @@ static int vfswrap_unlink(vfs_handle_struct *handle,
        return result;
 }
 
-static int vfswrap_chmod(vfs_handle_struct *handle, const char *path, mode_t mode)
+static int vfswrap_chmod(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       mode_t mode)
 {
        int result;
 
@@ -1691,7 +1693,10 @@ static int vfswrap_chmod(vfs_handle_struct *handle, const char *path, mode_t mod
 
        {
                int saved_errno = errno; /* We might get ENOSYS */
-               if ((result = SMB_VFS_CHMOD_ACL(handle->conn, path, mode)) == 0) {
+               result = SMB_VFS_CHMOD_ACL(handle->conn,
+                               smb_fname->base_name,
+                               mode);
+               if (result == 0) {
                        END_PROFILE(syscall_chmod);
                        return result;
                }
@@ -1699,7 +1704,7 @@ static int vfswrap_chmod(vfs_handle_struct *handle, const char *path, mode_t mod
                errno = saved_errno;
        }
 
-       result = chmod(path, mode);
+       result = chmod(smb_fname->base_name, mode);
        END_PROFILE(syscall_chmod);
        return result;
 }
index 137bf72..5aa6a30 100644 (file)
@@ -270,20 +270,22 @@ static int audit_unlink(vfs_handle_struct *handle,
        return result;
 }
 
-static int audit_chmod(vfs_handle_struct *handle, const char *path, mode_t mode)
+static int audit_chmod(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       mode_t mode)
 {
        int result;
 
-       result = SMB_VFS_NEXT_CHMOD(handle, path, mode);
+       result = SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
 
        if (lp_syslog() > 0) {
                syslog(audit_syslog_priority(handle), "chmod %s mode 0x%x %s%s\n",
-                      path, mode,
+                      smb_fname->base_name, mode,
                       (result < 0) ? "failed: " : "",
                       (result < 0) ? strerror(errno) : "");
        }
        DEBUG(1, ("vfs_extd_audit: chmod %s mode 0x%x %s %s\n",
-              path, (unsigned int)mode,
+              smb_fname->base_name, (unsigned int)mode,
               (result < 0) ? "failed: " : "",
               (result < 0) ? strerror(errno) : ""));
 
index 3cd8c65..49cfa0c 100644 (file)
@@ -2489,15 +2489,17 @@ static int fruit_unlink(vfs_handle_struct *handle,
 }
 
 static int fruit_chmod(vfs_handle_struct *handle,
-                      const char *path,
+                      const struct smb_filename *smb_fname,
                       mode_t mode)
 {
        int rc = -1;
        char *adp = NULL;
        struct fruit_config_data *config = NULL;
        SMB_STRUCT_STAT sb;
+       const char *path = smb_fname->base_name;
+       struct smb_filename *smb_fname_adp = NULL;
 
-       rc = SMB_VFS_NEXT_CHMOD(handle, path, mode);
+       rc = SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
        if (rc != 0) {
                return rc;
        }
@@ -2522,11 +2524,22 @@ static int fruit_chmod(vfs_handle_struct *handle,
 
        DEBUG(10, ("fruit_chmod: %s\n", adp));
 
-       rc = SMB_VFS_NEXT_CHMOD(handle, adp, mode);
+       smb_fname_adp = synthetic_smb_fname(talloc_tos(),
+                                       adp,
+                                       NULL,
+                                       NULL);
+       if (smb_fname_adp == NULL) {
+               TALLOC_FREE(adp);
+               errno = ENOMEM;
+               return -1;
+       }
+
+       rc = SMB_VFS_NEXT_CHMOD(handle, smb_fname_adp, mode);
        if (errno == ENOENT) {
                rc = 0;
        }
 
+       TALLOC_FREE(smb_fname_adp);
        TALLOC_FREE(adp);
        return rc;
 }
@@ -3644,7 +3657,7 @@ static NTSTATUS fruit_fset_nt_acl(vfs_handle_struct *handle,
                        result = SMB_VFS_FCHMOD(fsp, ms_nfs_mode);
                } else {
                        result = SMB_VFS_CHMOD(fsp->conn,
-                                              fsp->fsp_name->base_name,
+                                              fsp->fsp_name,
                                               ms_nfs_mode);
                }
 
index d51e8ce..43a8808 100644 (file)
@@ -1394,13 +1394,16 @@ static int smb_full_audit_unlink(vfs_handle_struct *handle,
 }
 
 static int smb_full_audit_chmod(vfs_handle_struct *handle,
-                      const char *path, mode_t mode)
+                               const struct smb_filename *smb_fname,
+                               mode_t mode)
 {
        int result;
 
-       result = SMB_VFS_NEXT_CHMOD(handle, path, mode);
+       result = SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
 
-       do_log(SMB_VFS_OP_CHMOD, (result >= 0), handle, "%s|%o", path, mode);
+       do_log(SMB_VFS_OP_CHMOD, (result >= 0), handle, "%s|%o",
+               smb_fname->base_name,
+               mode);
 
        return result;
 }
index 20e6717..c98e480 100644 (file)
@@ -930,9 +930,10 @@ static int vfs_gluster_unlink(struct vfs_handle_struct *handle,
 }
 
 static int vfs_gluster_chmod(struct vfs_handle_struct *handle,
-                            const char *path, mode_t mode)
+                               const struct smb_filename *smb_fname,
+                               mode_t mode)
 {
-       return glfs_chmod(handle->data, path, mode);
+       return glfs_chmod(handle->data, smb_fname->base_name, mode);
 }
 
 static int vfs_gluster_fchmod(struct vfs_handle_struct *handle,
index 1616b4e..af7fd17 100644 (file)
@@ -1396,29 +1396,35 @@ static int gpfsacl_emu_chmod(vfs_handle_struct *handle,
        return 0; /* ok for [f]chmod */
 }
 
-static int vfs_gpfs_chmod(vfs_handle_struct *handle, const char *path, mode_t mode)
+static int vfs_gpfs_chmod(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       mode_t mode)
 {
        struct smb_filename *smb_fname_cpath;
        int rc;
 
-       smb_fname_cpath = synthetic_smb_fname(talloc_tos(), path, NULL, NULL);
+       smb_fname_cpath = cp_smb_fname(talloc_tos(), smb_fname);
        if (smb_fname_cpath == NULL) {
                errno = ENOMEM;
                return -1;
        }
 
        if (SMB_VFS_NEXT_STAT(handle, smb_fname_cpath) != 0) {
+               TALLOC_FREE(smb_fname_cpath);
                return -1;
        }
 
        /* avoid chmod() if possible, to preserve acls */
        if ((smb_fname_cpath->st.st_ex_mode & ~S_IFMT) == mode) {
+               TALLOC_FREE(smb_fname_cpath);
                return 0;
        }
 
-       rc = gpfsacl_emu_chmod(handle, path, mode);
+       rc = gpfsacl_emu_chmod(handle, smb_fname->base_name, mode);
        if (rc == 1)
-               return SMB_VFS_NEXT_CHMOD(handle, path, mode);
+               return SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
+
+       TALLOC_FREE(smb_fname_cpath);
        return rc;
 }
 
index 5c8fab8..fca0d13 100644 (file)
@@ -82,7 +82,7 @@ static int linux_xfs_sgid_mkdir(vfs_handle_struct *handle,
         */
        become_root();
        res = SMB_VFS_NEXT_CHMOD(handle,
-                       smb_fname->base_name,
+                       smb_fname,
                        fname.st.st_ex_mode);
        unbecome_root();
 
index 786cee9..6a54862 100644 (file)
@@ -1547,33 +1547,30 @@ out:
  * Failure: set errno, return -1
  */
 static int mh_chmod(vfs_handle_struct *handle,
-               const char *path,
+               const struct smb_filename *smb_fname,
                mode_t mode)
 {
        int status;
-       char *clientPath;
-       TALLOC_CTX *ctx;
+       struct smb_filename *clientFname = NULL;
 
        DEBUG(MH_INFO_DEBUG, ("Entering mh_chmod\n"));
-       if (!is_in_media_files(path))
+       if (!is_in_media_files(smb_fname->base_name))
        {
-               status = SMB_VFS_NEXT_CHMOD(handle, path, mode);
+               status = SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
                goto out;
        }
 
-       clientPath = NULL;
-       ctx = talloc_tos();
-
-       if ((status = alloc_get_client_path(handle, ctx,
-                               path,
-                               &clientPath)))
-       {
+       status = alloc_get_client_smb_fname(handle,
+                               talloc_tos(),
+                               smb_fname,
+                               &clientFname);
+       if (status != 0) {
                goto err;
        }
 
-       status = SMB_VFS_NEXT_CHMOD(handle, clientPath, mode);
+       status = SMB_VFS_NEXT_CHMOD(handle, clientFname, mode);
 err:
-       TALLOC_FREE(clientPath);
+       TALLOC_FREE(clientFname);
 out:
        return status;
 }
index d8f9f34..aaaf626 100644 (file)
@@ -357,25 +357,33 @@ exit_unlink:
        return ret;
 }
 
-static int atalk_chmod(struct vfs_handle_struct *handle, const char *path, mode_t mode)
+static int atalk_chmod(struct vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       mode_t mode)
 {
        int ret = 0;
+       int ret1 = 0;
        char *adbl_path = 0;
        char *orig_path = 0;
        SMB_STRUCT_STAT adbl_info;
        SMB_STRUCT_STAT orig_info;
        TALLOC_CTX *ctx;
 
-       ret = SMB_VFS_NEXT_CHMOD(handle, path, mode);
-
-       if (!path) return ret;
+       ret = SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
 
        if (!(ctx = talloc_init("chmod_file")))
                return ret;
 
-       if (atalk_build_paths(ctx, handle->conn->cwd, path, &adbl_path,
-                             &orig_path, &adbl_info, &orig_info) != 0)
+       ret1 = atalk_build_paths(ctx,
+                       handle->conn->cwd,
+                       smb_fname->base_name,
+                       &adbl_path,
+                       &orig_path,
+                       &adbl_info,
+                       &orig_info);
+       if (ret1 != 0) {
                goto exit_chmod;
+       }
 
        if (!S_ISDIR(orig_info.st_ex_mode) && !S_ISREG(orig_info.st_ex_mode)) {
                DEBUG(3, ("ATALK: %s has passed..\n", orig_path));              
index 27fc8a9..1aaf44e 100644 (file)
@@ -969,29 +969,46 @@ static int shadow_copy2_unlink(vfs_handle_struct *handle,
        return ret;
 }
 
-static int shadow_copy2_chmod(vfs_handle_struct *handle, const char *fname,
-                             mode_t mode)
+static int shadow_copy2_chmod(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       mode_t mode)
 {
        time_t timestamp;
-       char *stripped;
+       char *stripped = NULL;
        int ret, saved_errno;
-       char *conv;
+       char *conv = NULL;
+       struct smb_filename *conv_smb_fname;
 
-       if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
-                                        &timestamp, &stripped)) {
+       if (!shadow_copy2_strip_snapshot(talloc_tos(),
+                               handle,
+                               smb_fname->base_name,
+                               &timestamp,
+                               &stripped)) {
                return -1;
        }
        if (timestamp == 0) {
-               return SMB_VFS_NEXT_CHMOD(handle, fname, mode);
+               TALLOC_FREE(stripped);
+               return SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
        }
        conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
        TALLOC_FREE(stripped);
        if (conv == NULL) {
                return -1;
        }
-       ret = SMB_VFS_NEXT_CHMOD(handle, conv, mode);
+       conv_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       conv,
+                                       NULL,
+                                       NULL);
+       if (conv_smb_fname == NULL) {
+               TALLOC_FREE(conv);
+               errno = ENOMEM;
+               return -1;
+       }
+
+       ret = SMB_VFS_NEXT_CHMOD(handle, conv_smb_fname, mode);
        saved_errno = errno;
        TALLOC_FREE(conv);
+       TALLOC_FREE(conv_smb_fname);
        errno = saved_errno;
        return ret;
 }
index 5f5e296..0a0f5eb 100644 (file)
@@ -2215,29 +2215,46 @@ static int snapper_gmt_unlink(vfs_handle_struct *handle,
        return ret;
 }
 
-static int snapper_gmt_chmod(vfs_handle_struct *handle, const char *fname,
-                            mode_t mode)
+static int snapper_gmt_chmod(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       mode_t mode)
 {
        time_t timestamp;
-       char *stripped;
+       char *stripped = NULL;
        int ret, saved_errno;
-       char *conv;
+       char *conv = NULL;
+       struct smb_filename *conv_smb_fname = NULL;
 
-       if (!snapper_gmt_strip_snapshot(talloc_tos(), handle, fname,
-                                       &timestamp, &stripped)) {
+       if (!snapper_gmt_strip_snapshot(talloc_tos(),
+                               handle,
+                               smb_fname->base_name,
+                               &timestamp,
+                               &stripped)) {
                return -1;
        }
        if (timestamp == 0) {
-               return SMB_VFS_NEXT_CHMOD(handle, fname, mode);
+               TALLOC_FREE(stripped);
+               return SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
        }
        conv = snapper_gmt_convert(talloc_tos(), handle, stripped, timestamp);
        TALLOC_FREE(stripped);
        if (conv == NULL) {
                return -1;
        }
-       ret = SMB_VFS_NEXT_CHMOD(handle, conv, mode);
+       conv_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       conv,
+                                       NULL,
+                                       NULL);
+       if (conv_smb_fname == NULL) {
+               TALLOC_FREE(conv);
+               errno = ENOMEM;
+               return -1;
+       }
+
+       ret = SMB_VFS_NEXT_CHMOD(handle, conv_smb_fname, mode);
        saved_errno = errno;
        TALLOC_FREE(conv);
+       TALLOC_FREE(conv_smb_fname);
        errno = saved_errno;
        return ret;
 }
index 95ca67a..948f154 100644 (file)
@@ -1102,19 +1102,22 @@ static int smb_time_audit_unlink(vfs_handle_struct *handle,
 }
 
 static int smb_time_audit_chmod(vfs_handle_struct *handle,
-                               const char *path, mode_t mode)
+                       const struct smb_filename *smb_fname,
+                       mode_t mode)
 {
        int result;
        struct timespec ts1,ts2;
        double timediff;
 
        clock_gettime_mono(&ts1);
-       result = SMB_VFS_NEXT_CHMOD(handle, path, mode);
+       result = SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
        clock_gettime_mono(&ts2);
        timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
 
        if (timediff > audit_timeout) {
-               smb_time_audit_log_fname("chmod", timediff, path);
+               smb_time_audit_log_fname("chmod",
+                       timediff,
+                       smb_fname->base_name);
        }
 
        return result;
index 191d39f..65e4d4c 100644 (file)
@@ -1179,28 +1179,30 @@ err:
 }
 
 static int um_chmod(vfs_handle_struct *handle,
-                   const char *path,
-                   mode_t mode)
+                       const struct smb_filename *smb_fname,
+                       mode_t mode)
 {
        int status;
-       char *client_path = NULL;
+       struct smb_filename *client_fname = NULL;
 
        DEBUG(10, ("Entering um_chmod\n"));
 
-       if (!is_in_media_files(path)) {
-               return SMB_VFS_NEXT_CHMOD(handle, path, mode);
+       if (!is_in_media_files(smb_fname->base_name)) {
+               return SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
        }
 
-       status = alloc_get_client_path(handle, talloc_tos(),
-                                      path, &client_path);
+       status = alloc_get_client_smb_fname(handle,
+                               talloc_tos(),
+                               smb_fname,
+                               &client_fname);
        if (status != 0) {
                goto err;
        }
 
-       status = SMB_VFS_NEXT_CHMOD(handle, client_path, mode);
+       status = SMB_VFS_NEXT_CHMOD(handle, client_fname, mode);
 
 err:
-       TALLOC_FREE(client_path);
+       TALLOC_FREE(client_fname);
        return status;
 }
 
index ecc211c..60761c2 100644 (file)
@@ -766,7 +766,7 @@ int file_set_dosmode(connection_struct *conn, struct smb_filename *smb_fname,
                return -1;
        }
 
-       ret = SMB_VFS_CHMOD(conn, smb_fname->base_name, unixmode);
+       ret = SMB_VFS_CHMOD(conn, smb_fname, unixmode);
        if (ret == 0) {
                if(!newfile || (lret != -1)) {
                        notify_fname(conn, NOTIFY_ACTION_MODIFIED,
index 3d0349e..efa7bed 100644 (file)
@@ -3344,7 +3344,7 @@ static NTSTATUS mkdir_internal(connection_struct *conn,
                 */
                if ((mode & ~(S_IRWXU|S_IRWXG|S_IRWXO)) &&
                    (mode & ~smb_dname->st.st_ex_mode)) {
-                       SMB_VFS_CHMOD(conn, smb_dname->base_name,
+                       SMB_VFS_CHMOD(conn, smb_dname,
                                      (smb_dname->st.st_ex_mode |
                                          (mode & ~smb_dname->st.st_ex_mode)));
                        need_re_stat = true;
index 336af81..ac296e2 100644 (file)
@@ -3972,7 +3972,7 @@ NTSTATUS set_nt_acl(files_struct *fsp, uint32_t security_info_sent, const struct
                        if (set_acl_as_root) {
                                become_root();
                        }
-                       sret = SMB_VFS_CHMOD(conn, fsp->fsp_name->base_name,
+                       sret = SMB_VFS_CHMOD(conn, fsp->fsp_name,
                                             posix_perms);
                        if (set_acl_as_root) {
                                unbecome_root();
@@ -3987,7 +3987,7 @@ NTSTATUS set_nt_acl(files_struct *fsp, uint32_t security_info_sent, const struct
 
                                        become_root();
                                        sret = SMB_VFS_CHMOD(conn,
-                                           fsp->fsp_name->base_name,
+                                           fsp->fsp_name,
                                            posix_perms);
                                        unbecome_root();
                                }
index 584039f..2477003 100644 (file)
@@ -7514,7 +7514,7 @@ static NTSTATUS smb_set_file_unix_basic(connection_struct *conn,
                if (fsp && fsp->fh->fd != -1) {
                        ret = SMB_VFS_FCHMOD(fsp, unixmode);
                } else {
-                       ret = SMB_VFS_CHMOD(conn, smb_fname->base_name, unixmode);
+                       ret = SMB_VFS_CHMOD(conn, smb_fname, unixmode);
                }
                if (ret != 0) {
                        return map_nt_error_from_unix(errno);
index 02260ea..9221107 100644 (file)
@@ -1867,11 +1867,12 @@ int smb_vfs_call_unlink(struct vfs_handle_struct *handle,
        return handle->fns->unlink_fn(handle, smb_fname);
 }
 
-int smb_vfs_call_chmod(struct vfs_handle_struct *handle, const char *path,
-                      mode_t mode)
+int smb_vfs_call_chmod(struct vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       mode_t mode)
 {
        VFS_FIND(chmod);
-       return handle->fns->chmod_fn(handle, path, mode);
+       return handle->fns->chmod_fn(handle, smb_fname, mode);
 }
 
 int smb_vfs_call_fchmod(struct vfs_handle_struct *handle,
index 0bc6dbc..3e63714 100644 (file)
@@ -837,6 +837,7 @@ static NTSTATUS cmd_lstat(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
 
 static NTSTATUS cmd_chmod(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
 {
+       struct smb_filename *smb_fname = NULL;
        mode_t mode;
        if (argc != 3) {
                printf("Usage: chmod <path> <mode>\n");
@@ -844,7 +845,16 @@ static NTSTATUS cmd_chmod(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
        }
 
        mode = atoi(argv[2]);
-       if (SMB_VFS_CHMOD(vfs->conn, argv[1], mode) == -1) {
+
+       smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       argv[1],
+                                       NULL,
+                                       NULL);
+       if (smb_fname == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       if (SMB_VFS_CHMOD(vfs->conn, smb_fname, mode) == -1) {
                printf("chmod: error=%d (%s)\n", errno, strerror(errno));
                return NT_STATUS_UNSUCCESSFUL;
        }