diff options
author | Jeremy Allison <jra@samba.org> | 2016-03-01 16:20:25 -0800 |
---|---|---|
committer | Ralph Boehme <slow@samba.org> | 2016-03-03 09:04:14 +0100 |
commit | ac8fba6ef7093836eb6988e749325b69e7a7fde1 (patch) | |
tree | 576c296d7bc49192f7cb333f034d4721f075b261 | |
parent | d7ca174744001fabdc32e1c334dad347bb985756 (diff) | |
download | samba-ac8fba6ef7093836eb6988e749325b69e7a7fde1.tar.gz |
VFS: Modify chmod to take a const struct smb_filename * instead of const char *
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, 248 insertions, 105 deletions
diff --git a/examples/VFS/skel_opaque.c b/examples/VFS/skel_opaque.c index 4ffdacc90cf..f772a9f9316 100644 --- a/examples/VFS/skel_opaque.c +++ b/examples/VFS/skel_opaque.c @@ -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; diff --git a/examples/VFS/skel_transparent.c b/examples/VFS/skel_transparent.c index 5d3ffb73391..bea2cd4272f 100644 --- a/examples/VFS/skel_transparent.c +++ b/examples/VFS/skel_transparent.c @@ -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, diff --git a/source3/include/vfs.h b/source3/include/vfs.h index 9ea4e752fdd..6a6c8656f36 100644 --- a/source3/include/vfs.h +++ b/source3/include/vfs.h @@ -180,6 +180,8 @@ /* 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, diff --git a/source3/include/vfs_macros.h b/source3/include/vfs_macros.h index 2e8ca1877b7..6dc257b331a 100644 --- a/source3/include/vfs_macros.h +++ b/source3/include/vfs_macros.h @@ -241,10 +241,10 @@ #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)) diff --git a/source3/modules/vfs_acl_common.c b/source3/modules/vfs_acl_common.c index 0c0cf83bdee..26841062fb5 100644 --- a/source3/modules/vfs_acl_common.c +++ b/source3/modules/vfs_acl_common.c @@ -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; } diff --git a/source3/modules/vfs_audit.c b/source3/modules/vfs_audit.c index fa47b3c25a9..92b69b17dd0 100644 --- a/source3/modules/vfs_audit.c +++ b/source3/modules/vfs_audit.c @@ -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) : ""); diff --git a/source3/modules/vfs_cap.c b/source3/modules/vfs_cap.c index f96455cfb04..479c2c213ae 100644 --- a/source3/modules/vfs_cap.c +++ b/source3/modules/vfs_cap.c @@ -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) diff --git a/source3/modules/vfs_catia.c b/source3/modules/vfs_catia.c index 9f42e5f52a3..7f06fb737e8 100644 --- a/source3/modules/vfs_catia.c +++ b/source3/modules/vfs_catia.c @@ -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; } diff --git a/source3/modules/vfs_ceph.c b/source3/modules/vfs_ceph.c index 2e1b623cf30..e61c39dd801 100644 --- a/source3/modules/vfs_ceph.c +++ b/source3/modules/vfs_ceph.c @@ -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); } diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c index 64592a7e100..fbb0bcb806f 100644 --- a/source3/modules/vfs_default.c +++ b/source3/modules/vfs_default.c @@ -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; } diff --git a/source3/modules/vfs_extd_audit.c b/source3/modules/vfs_extd_audit.c index 137bf72a093..5aa6a30ed8f 100644 --- a/source3/modules/vfs_extd_audit.c +++ b/source3/modules/vfs_extd_audit.c @@ -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) : "")); diff --git a/source3/modules/vfs_fruit.c b/source3/modules/vfs_fruit.c index 3cd8c65942a..49cfa0c3c07 100644 --- a/source3/modules/vfs_fruit.c +++ b/source3/modules/vfs_fruit.c @@ -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); } diff --git a/source3/modules/vfs_full_audit.c b/source3/modules/vfs_full_audit.c index d51e8cecbdb..43a88082e38 100644 --- a/source3/modules/vfs_full_audit.c +++ b/source3/modules/vfs_full_audit.c @@ -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; } diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c index 20e6717fa9b..c98e48091fa 100644 --- a/source3/modules/vfs_glusterfs.c +++ b/source3/modules/vfs_glusterfs.c @@ -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, diff --git a/source3/modules/vfs_gpfs.c b/source3/modules/vfs_gpfs.c index 1616b4eac17..af7fd17e58f 100644 --- a/source3/modules/vfs_gpfs.c +++ b/source3/modules/vfs_gpfs.c @@ -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; } diff --git a/source3/modules/vfs_linux_xfs_sgid.c b/source3/modules/vfs_linux_xfs_sgid.c index 5c8fab8acf3..fca0d130f52 100644 --- a/source3/modules/vfs_linux_xfs_sgid.c +++ b/source3/modules/vfs_linux_xfs_sgid.c @@ -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(); diff --git a/source3/modules/vfs_media_harmony.c b/source3/modules/vfs_media_harmony.c index 786cee9288e..6a54862bf2a 100644 --- a/source3/modules/vfs_media_harmony.c +++ b/source3/modules/vfs_media_harmony.c @@ -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; } diff --git a/source3/modules/vfs_netatalk.c b/source3/modules/vfs_netatalk.c index d8f9f34fc73..aaaf62627e4 100644 --- a/source3/modules/vfs_netatalk.c +++ b/source3/modules/vfs_netatalk.c @@ -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)); diff --git a/source3/modules/vfs_shadow_copy2.c b/source3/modules/vfs_shadow_copy2.c index 27fc8a96cb8..1aaf44eb34c 100644 --- a/source3/modules/vfs_shadow_copy2.c +++ b/source3/modules/vfs_shadow_copy2.c @@ -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, - ×tamp, &stripped)) { + if (!shadow_copy2_strip_snapshot(talloc_tos(), + handle, + smb_fname->base_name, + ×tamp, + &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; } diff --git a/source3/modules/vfs_snapper.c b/source3/modules/vfs_snapper.c index 5f5e296fcf8..0a0f5eb1cca 100644 --- a/source3/modules/vfs_snapper.c +++ b/source3/modules/vfs_snapper.c @@ -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, - ×tamp, &stripped)) { + if (!snapper_gmt_strip_snapshot(talloc_tos(), + handle, + smb_fname->base_name, + ×tamp, + &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; } diff --git a/source3/modules/vfs_time_audit.c b/source3/modules/vfs_time_audit.c index 95ca67a0406..948f154acd7 100644 --- a/source3/modules/vfs_time_audit.c +++ b/source3/modules/vfs_time_audit.c @@ -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; diff --git a/source3/modules/vfs_unityed_media.c b/source3/modules/vfs_unityed_media.c index 191d39feab9..65e4d4cbbcd 100644 --- a/source3/modules/vfs_unityed_media.c +++ b/source3/modules/vfs_unityed_media.c @@ -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; } diff --git a/source3/smbd/dosmode.c b/source3/smbd/dosmode.c index ecc211c0a62..60761c2b306 100644 --- a/source3/smbd/dosmode.c +++ b/source3/smbd/dosmode.c @@ -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, diff --git a/source3/smbd/open.c b/source3/smbd/open.c index 3d0349ea196..efa7bed1104 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -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; diff --git a/source3/smbd/posix_acls.c b/source3/smbd/posix_acls.c index 336af81f61e..ac296e24ea0 100644 --- a/source3/smbd/posix_acls.c +++ b/source3/smbd/posix_acls.c @@ -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(); } diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c index 584039faad6..2477003e7e2 100644 --- a/source3/smbd/trans2.c +++ b/source3/smbd/trans2.c @@ -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); diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c index 02260eada58..9221107f9fc 100644 --- a/source3/smbd/vfs.c +++ b/source3/smbd/vfs.c @@ -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, diff --git a/source3/torture/cmd_vfs.c b/source3/torture/cmd_vfs.c index 0bc6dbcd5ac..3e6371407f5 100644 --- a/source3/torture/cmd_vfs.c +++ b/source3/torture/cmd_vfs.c @@ -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; } |