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 4ffdacc90cfba3d7a0987c7f571e6267d7de90f1..f772a9f93160221a4e4c05567bb5b6d743af4de9 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 5d3ffb733912c816a19d661e759d0faaea92a0b5..bea2cd4272ff3c8d07995e5b95d5b10cb085d2a7 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 9ea4e752fddfb61fde3ea5c04ec8ddb45924afe2..6a6c8656f36b16c476b4e7465c73810c6c3fa91f 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 2e8ca1877b7df11a17055c851a0a05f5b24e59bc..6dc257b331aa72da96ebd556f260483b84b1e920 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 0c0cf83bdee495a00d5526e3d20a097c775601bc..26841062fb5f20c6d77d235c2eb07f8082af5f28 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 fa47b3c25a934bf2a9921bf907e9cbd2513b7f4d..92b69b17dd0efa0cd634b95432d7e22afd0c418f 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 f96455cfb0430b120cac42065e7f752743326ec5..479c2c213ae1bb7bd22383eda5150d34ecbb6d73 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 9f42e5f52a32cf59d084564d93f3019d791e5e5c..7f06fb737e8b6106868122abb982fb396e90917b 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 2e1b623cf30fea81980239038b27926fbee09d29..e61c39dd8015979c5a1c7cb46101f620e193c132 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 64592a7e1001c722948e1fd61d9ed57ea995a766..fbb0bcb806f4c637b98e6f177caea73967351a49 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 137bf72a093c67d77875827b657c9275c9efdf4d..5aa6a30ed8f934688bd7f25218599de90ace28c6 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 3cd8c65942adb06f0f5cc1a427f696e28248cfdb..49cfa0c3c078c4cbd892c70635f9834c244bb142 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 d51e8cecbdb6736929386b3d65e8b3fbade1c15c..43a88082e38e64707bed6ab4e9713f615ec7a104 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 20e6717fa9bbf8988adef4925b039fb2f8e8cf32..c98e48091fa2f03e4432bd302457c66120792dac 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 1616b4eac17a4865413699ea92039705b408769a..af7fd17e58f2e6be1a2b24b414e0ff6ad0525aeb 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 5c8fab8acf35be3e99f7b40d0a335f0c91bab338..fca0d130f524ff24f30c0c6f1f2a3161c45790c0 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 786cee9288ef1c910349087f5a70306444407b6c..6a54862bf2a744adc323c4a11720b7cacf22288f 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 d8f9f34fc7343c20006f38f71c0d31820ee92595..aaaf62627e4aa092226d32acb196529696207450 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 27fc8a96cb80d47f9aa1343c889ff56a59f80352..1aaf44eb34c375c1a0293af16dead4224183d46b 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 5f5e296fcf8f749e190b936c4b5b03251c883a3c..0a0f5eb1cca1941e6eec60d3c6a92077ec8cb7f5 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 95ca67a0406f56493efa073b563bb15a76c694d4..948f154acd77fd7f837cdc6a90622ee234df830e 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 191d39feab970c5f0c0aece0d53a82cf3b709f63..65e4d4cbbcd0f64cc44f1c218e92fa0bf078cc9f 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 ecc211c0a625176eb4b82128b5bbfd7e3b3ac25f..60761c2b306177180e30215e02b884c8395801a3 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 3d0349ea196b515bdcaf6974bdb1f71b26ff49f3..efa7bed11049763b72081485eaf948eff8c43b56 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 336af81f61e7812307cfd6eb015088ab8becb5ec..ac296e24ea0e987cffa59a11e9e5341299cf614b 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 584039faad6b09f6fd74c907d2c907dc006ae38b..2477003e7e2cbd363599b56c59fcddc22d752a20 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 02260eada58443d9aca77b37d9c3e29ea2d4dc1b..9221107f9fc5a00b5dff641f66db61377f986696 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 0bc6dbcd5ac2ef47834f81471d0a36cf2a766d85..3e6371407f549a40c97acbf3dd9530bbfad63f98 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;
        }