[PATCH] Fix chmod and chmod_acl VFS functions to take struct smb_filename * instead of const char *

Jeremy Allison jra at samba.org
Wed Mar 2 22:50:56 UTC 2016


Two patches fixing a couple more functions fixed in my
quest to exterminate lp_posix_pathnames() :-).

VFS functions left:

chown()
lchown()

The following only ever act on POSIX pathnames:

chdir()
getwd()
readlink()
link()
symlink()
mknod()
realpath()
chflags()

So I think it's best to leave them taking
const char *.

Once chown and lchown are done I can
start pushing smb_filename into the
lower-level functions until they're
available all cases where lp_posix_pathnames()
is called - then I'll add the bool to
struct smb_filename and convert the
global call to a struct lookup,

AND ONE MORE GLOBAL WILL HAVE BITTEN
THE DUST ! :-) :-).

(Hurrah!).

Please review and push if happy !

Cheers,

	Jeremy.
-------------- next part --------------
From aa5a6a9b20d1942e9f79fc06caf6f467e2c90f1c Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Tue, 1 Mar 2016 16:20:25 -0800
Subject: [PATCH 1/2] 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 at samba.org>
---
 examples/VFS/skel_opaque.c           |  4 +++-
 examples/VFS/skel_transparent.c      |  6 ++++--
 source3/include/vfs.h                | 11 ++++++++---
 source3/include/vfs_macros.h         |  8 ++++----
 source3/modules/vfs_acl_common.c     |  5 +++--
 source3/modules/vfs_audit.c          |  8 +++++---
 source3/modules/vfs_cap.c            | 27 ++++++++++++++++++++++++---
 source3/modules/vfs_catia.c          | 27 ++++++++++++++++++++++-----
 source3/modules/vfs_ceph.c           | 16 ++++++++++++----
 source3/modules/vfs_default.c        | 11 ++++++++---
 source3/modules/vfs_extd_audit.c     | 10 ++++++----
 source3/modules/vfs_fruit.c          | 21 +++++++++++++++++----
 source3/modules/vfs_full_audit.c     |  9 ++++++---
 source3/modules/vfs_glusterfs.c      |  5 +++--
 source3/modules/vfs_gpfs.c           | 14 ++++++++++----
 source3/modules/vfs_linux_xfs_sgid.c |  2 +-
 source3/modules/vfs_media_harmony.c  | 25 +++++++++++--------------
 source3/modules/vfs_netatalk.c       | 20 ++++++++++++++------
 source3/modules/vfs_shadow_copy2.c   | 33 +++++++++++++++++++++++++--------
 source3/modules/vfs_snapper.c        | 33 +++++++++++++++++++++++++--------
 source3/modules/vfs_time_audit.c     |  9 ++++++---
 source3/modules/vfs_unityed_media.c  | 20 +++++++++++---------
 source3/smbd/dosmode.c               |  2 +-
 source3/smbd/open.c                  |  2 +-
 source3/smbd/posix_acls.c            |  4 ++--
 source3/smbd/trans2.c                |  2 +-
 source3/smbd/vfs.c                   |  7 ++++---
 source3/torture/cmd_vfs.c            | 12 +++++++++++-
 28 files changed, 248 insertions(+), 105 deletions(-)

diff --git a/examples/VFS/skel_opaque.c b/examples/VFS/skel_opaque.c
index 4ffdacc..f772a9f 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 5d3ffb7..bea2cd4 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 9ea4e75..6a6c865 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 2e8ca18..6dc257b 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 0c0cf83..2684106 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 fa47b3c..92b69b1 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 f96455c..479c2c2 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 9f42e5f..7f06fb7 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 2e1b623..e61c39d 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 64592a7..fbb0bcb 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 137bf72..5aa6a30 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 3cd8c65..49cfa0c 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 d51e8ce..43a8808 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 20e6717..c98e480 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 1616b4e..af7fd17 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 5c8fab8..fca0d13 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 786cee9..6a54862 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 d8f9f34..aaaf626 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 27fc8a9..1aaf44e 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,
-					 &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;
 }
diff --git a/source3/modules/vfs_snapper.c b/source3/modules/vfs_snapper.c
index 5f5e296..86952ef 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_fname *smb_fname,
+			mode_t mode)
 {
 	time_t timestamp;
-	char *stripped;
+	char *stripped = NULL;
 	int ret, saved_errno;
-	char *conv;
+	char *conv = NULL;
+	struct smb_fname *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;
 }
diff --git a/source3/modules/vfs_time_audit.c b/source3/modules/vfs_time_audit.c
index 95ca67a..948f154 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 191d39f..65e4d4c 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 ecc211c..60761c2 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 3d0349e..efa7bed 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 336af81..ac296e2 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 0002f06..dbc9f66 100644
--- a/source3/smbd/trans2.c
+++ b/source3/smbd/trans2.c
@@ -7566,7 +7566,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 02260ea..9221107 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 0bc6dbc..3e63714 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;
 	}
-- 
2.7.0.rc3.207.g0ac5344


From efbb33edfaed1bed94be5e98056266439ccb8c32 Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Tue, 1 Mar 2016 17:25:25 -0800
Subject: [PATCH 2/2] VFS: Modify chmod_acl 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 at samba.org>
---
 examples/VFS/skel_opaque.c           |  5 +++--
 examples/VFS/skel_transparent.c      |  7 ++++---
 source3/include/vfs.h                | 11 ++++++++---
 source3/include/vfs_macros.h         |  8 ++++----
 source3/modules/vfs_acl_common.c     |  5 +++--
 source3/modules/vfs_audit.c          |  8 +++++---
 source3/modules/vfs_cap.c            | 26 +++++++++++++++++++++++---
 source3/modules/vfs_catia.c          | 22 +++++++++++++++++++---
 source3/modules/vfs_ceph.c           |  6 ++++--
 source3/modules/vfs_default.c        | 12 ++++++++----
 source3/modules/vfs_extd_audit.c     | 10 ++++++----
 source3/modules/vfs_full_audit.c     |  7 ++++---
 source3/modules/vfs_linux_xfs_sgid.c |  3 ++-
 source3/modules/vfs_media_harmony.c  | 25 +++++++++++--------------
 source3/modules/vfs_shadow_copy2.c   | 27 +++++++++++++++++++++------
 source3/modules/vfs_snapper.c        | 25 ++++++++++++++++++++-----
 source3/modules/vfs_time_audit.c     |  9 ++++++---
 source3/modules/vfs_unityed_media.c  | 22 +++++++++++++---------
 source3/smbd/vfs.c                   |  7 ++++---
 source3/torture/cmd_vfs.c            | 12 +++++++++++-
 20 files changed, 179 insertions(+), 78 deletions(-)

diff --git a/examples/VFS/skel_opaque.c b/examples/VFS/skel_opaque.c
index f772a9f..e7bb645 100644
--- a/examples/VFS/skel_opaque.c
+++ b/examples/VFS/skel_opaque.c
@@ -692,8 +692,9 @@ static NTSTATUS skel_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
 	return NT_STATUS_NOT_IMPLEMENTED;
 }
 
-static int skel_chmod_acl(vfs_handle_struct *handle, const char *name,
-			  mode_t mode)
+static int skel_chmod_acl(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 bea2cd4..fe2356a 100644
--- a/examples/VFS/skel_transparent.c
+++ b/examples/VFS/skel_transparent.c
@@ -823,10 +823,11 @@ static NTSTATUS skel_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
 	return SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
 }
 
-static int skel_chmod_acl(vfs_handle_struct *handle, const char *name,
-			  mode_t mode)
+static int skel_chmod_acl(vfs_handle_struct *handle,
+			const struct smb_filename *smb_fname,
+			mode_t mode)
 {
-	return SMB_VFS_NEXT_CHMOD_ACL(handle, name, mode);
+	return SMB_VFS_NEXT_CHMOD_ACL(handle, smb_fname, mode);
 }
 
 static int skel_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp,
diff --git a/source3/include/vfs.h b/source3/include/vfs.h
index 6a6c865..9aa45fa 100644
--- a/source3/include/vfs.h
+++ b/source3/include/vfs.h
@@ -182,6 +182,8 @@
 /* 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 * */
+/* Version 35 - Change chmod_acl from const char *, to
+		const struct smb_filename * */
 
 #define SMB_VFS_INTERFACE_VERSION 35
 
@@ -787,7 +789,9 @@ struct vfs_fn_pointers {
 
 	/* POSIX ACL operations. */
 
-	int (*chmod_acl_fn)(struct vfs_handle_struct *handle, const char *name, mode_t mode);
+	int (*chmod_acl_fn)(struct vfs_handle_struct *handle,
+					const struct smb_filename *smb_fname,
+					mode_t mode);
 	int (*fchmod_acl_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, mode_t mode);
 
 	SMB_ACL_T (*sys_acl_get_file_fn)(struct vfs_handle_struct *handle,
@@ -1230,8 +1234,9 @@ NTSTATUS smb_vfs_call_audit_file(struct vfs_handle_struct *handle,
 				 struct security_acl *sacl,
 				 uint32_t access_requested,
 				 uint32_t access_denied);
-int smb_vfs_call_chmod_acl(struct vfs_handle_struct *handle, const char *name,
-			   mode_t mode);
+int smb_vfs_call_chmod_acl(struct vfs_handle_struct *handle,
+				const struct smb_filename *file,
+				mode_t mode);
 int smb_vfs_call_fchmod_acl(struct vfs_handle_struct *handle,
 			    struct files_struct *fsp, mode_t mode);
 SMB_ACL_T smb_vfs_call_sys_acl_get_file(struct vfs_handle_struct *handle,
diff --git a/source3/include/vfs_macros.h b/source3/include/vfs_macros.h
index 6dc257b..e5e3c99 100644
--- a/source3/include/vfs_macros.h
+++ b/source3/include/vfs_macros.h
@@ -452,10 +452,10 @@
 #define SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd) \
 	smb_vfs_call_fset_nt_acl((handle)->next, (fsp), (security_info_sent), (psd))
 
-#define SMB_VFS_CHMOD_ACL(conn, name, mode) \
-	smb_vfs_call_chmod_acl((conn)->vfs_handles, (name), (mode))
-#define SMB_VFS_NEXT_CHMOD_ACL(handle, name, mode) \
-	smb_vfs_call_chmod_acl((handle)->next, (name), (mode))
+#define SMB_VFS_CHMOD_ACL(conn, smb_fname, mode) \
+	smb_vfs_call_chmod_acl((conn)->vfs_handles, (smb_fname), (mode))
+#define SMB_VFS_NEXT_CHMOD_ACL(handle, smb_fname, mode) \
+	smb_vfs_call_chmod_acl((handle)->next, (smb_fname), (mode))
 
 #define SMB_VFS_FCHMOD_ACL(fsp, mode) \
 	smb_vfs_call_fchmod_acl((fsp)->conn->vfs_handles, (fsp), (mode))
diff --git a/source3/modules/vfs_acl_common.c b/source3/modules/vfs_acl_common.c
index 2684106..ba93e7b 100644
--- a/source3/modules/vfs_acl_common.c
+++ b/source3/modules/vfs_acl_common.c
@@ -1105,11 +1105,12 @@ static int fchmod_acl_module_common(struct vfs_handle_struct *handle,
 }
 
 static int chmod_acl_acl_module_common(struct vfs_handle_struct *handle,
-			const char *name, 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_ACL(handle, name, mode);
+		return SMB_VFS_NEXT_CHMOD_ACL(handle, smb_fname, mode);
 	}
 	return 0;
 }
diff --git a/source3/modules/vfs_audit.c b/source3/modules/vfs_audit.c
index 92b69b1..cef3bb5 100644
--- a/source3/modules/vfs_audit.c
+++ b/source3/modules/vfs_audit.c
@@ -233,14 +233,16 @@ static int audit_chmod(vfs_handle_struct *handle,
 	return result;
 }
 
-static int audit_chmod_acl(vfs_handle_struct *handle, const char *path, mode_t mode)
+static int audit_chmod_acl(vfs_handle_struct *handle,
+			const struct smb_filename *smb_fname,
+			mode_t mode)
 {
 	int result;
 
-	result = SMB_VFS_NEXT_CHMOD_ACL(handle, path, mode);
+	result = SMB_VFS_NEXT_CHMOD_ACL(handle, smb_fname, mode);
 
 	syslog(audit_syslog_priority(handle), "chmod_acl %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 479c2c2..0bb943d 100644
--- a/source3/modules/vfs_cap.c
+++ b/source3/modules/vfs_cap.c
@@ -461,16 +461,36 @@ static char *cap_realpath(vfs_handle_struct *handle, const char *path)
 	return SMB_VFS_NEXT_REALPATH(handle, cappath);
 }
 
-static int cap_chmod_acl(vfs_handle_struct *handle, const char *path, mode_t mode)
+static int cap_chmod_acl(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 the underlying VFS doesn't have ACL support... */
 	if (!cappath) {
 		errno = ENOMEM;
 		return -1;
 	}
-	return SMB_VFS_NEXT_CHMOD_ACL(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_ACL(handle, cap_smb_fname, mode);
+	saved_errno = errno;
+	TALLOC_FREE(cappath);
+	TALLOC_FREE(cap_smb_fname);
+	errno = saved_errno;
+	return ret;
 }
 
 static SMB_ACL_T cap_sys_acl_get_file(vfs_handle_struct *handle,
diff --git a/source3/modules/vfs_catia.c b/source3/modules/vfs_catia.c
index 7f06fb7..e142cce 100644
--- a/source3/modules/vfs_catia.c
+++ b/source3/modules/vfs_catia.c
@@ -871,22 +871,38 @@ catia_get_nt_acl(struct vfs_handle_struct *handle,
 
 static int
 catia_chmod_acl(vfs_handle_struct *handle,
-		const char *path,
+		const struct smb_filename *smb_fname,
 		mode_t mode)
 {
 	char *mapped_name = NULL;
+	struct smb_filename *mapped_smb_fname = NULL;
 	NTSTATUS status;
 	int ret;
+	int saved_errno;
 
 	status = catia_string_replace_allocate(handle->conn,
-				path, &mapped_name, vfs_translate_to_unix);
+				smb_fname->base_name,
+				&mapped_name,
+				vfs_translate_to_unix);
 	if (!NT_STATUS_IS_OK(status)) {
 		errno = map_errno_from_nt_status(status);
 		return -1;
 	}
 
-	ret = SMB_VFS_NEXT_CHMOD_ACL(handle, mapped_name, mode);
+	mapped_smb_fname = synthetic_smb_fname(talloc_tos(),
+					mapped_name,
+					NULL,
+					NULL);
+	if (mapped_smb_fname == NULL) {
+		TALLOC_FREE(mapped_name);
+		errno = ENOMEM;
+		return -1;
+	}
+	ret = SMB_VFS_NEXT_CHMOD_ACL(handle, mapped_smb_fname, mode);
+	saved_errno = errno;
 	TALLOC_FREE(mapped_name);
+	TALLOC_FREE(mapped_smb_fname);
+	errno = saved_errno;
 	return ret;
 }
 
diff --git a/source3/modules/vfs_ceph.c b/source3/modules/vfs_ceph.c
index e61c39d..82e15c8 100644
--- a/source3/modules/vfs_ceph.c
+++ b/source3/modules/vfs_ceph.c
@@ -362,8 +362,10 @@ static int cephwrap_mkdir(struct vfs_handle_struct *handle,
 		 * mess up any inherited ACL bits that were set. JRA.
 		 */
 		int saved_errno = errno; /* We may get ENOSYS */
-		if ((SMB_VFS_CHMOD_ACL(handle->conn, path, mode) == -1) && (errno == ENOSYS))
+		if ((SMB_VFS_CHMOD_ACL(handle->conn, smb_fname, mode) == -1) &&
+				(errno == ENOSYS)) {
 			errno = saved_errno;
+		}
 	}
 
 	return result;
@@ -650,7 +652,7 @@ static int cephwrap_chmod(struct vfs_handle_struct *handle,
 	{
 		int saved_errno = errno; /* We might get ENOSYS */
 		result = SMB_VFS_CHMOD_ACL(handle->conn,
-					smb_fname->base_name,
+					smb_fname,
 					mode);
 		if (result == 0) {
 			return result;
diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c
index fbb0bcb..bb55fac 100644
--- a/source3/modules/vfs_default.c
+++ b/source3/modules/vfs_default.c
@@ -498,8 +498,10 @@ static int vfswrap_mkdir(vfs_handle_struct *handle,
 		 * mess up any inherited ACL bits that were set. JRA.
 		 */
 		int saved_errno = errno; /* We may get ENOSYS */
-		if ((SMB_VFS_CHMOD_ACL(handle->conn, path, mode) == -1) && (errno == ENOSYS))
+		if ((SMB_VFS_CHMOD_ACL(handle->conn, smb_fname, mode) == -1) &&
+				(errno == ENOSYS)) {
 			errno = saved_errno;
+		}
 	}
 
 	END_PROFILE(syscall_mkdir);
@@ -1694,7 +1696,7 @@ static int vfswrap_chmod(vfs_handle_struct *handle,
 	{
 		int saved_errno = errno; /* We might get ENOSYS */
 		result = SMB_VFS_CHMOD_ACL(handle->conn,
-				smb_fname->base_name,
+				smb_fname,
 				mode);
 		if (result == 0) {
 			END_PROFILE(syscall_chmod);
@@ -2362,7 +2364,9 @@ static NTSTATUS vfswrap_audit_file(struct vfs_handle_struct *handle,
 	return NT_STATUS_OK; /* Nothing to do here ... */
 }
 
-static int vfswrap_chmod_acl(vfs_handle_struct *handle, const char *name, mode_t mode)
+static int vfswrap_chmod_acl(vfs_handle_struct *handle,
+				const struct smb_filename *smb_fname,
+				mode_t mode)
 {
 #ifdef HAVE_NO_ACL
 	errno = ENOSYS;
@@ -2371,7 +2375,7 @@ static int vfswrap_chmod_acl(vfs_handle_struct *handle, const char *name, mode_t
 	int result;
 
 	START_PROFILE(chmod_acl);
-	result = chmod_acl(handle->conn, name, mode);
+	result = chmod_acl(handle->conn, smb_fname->base_name, mode);
 	END_PROFILE(chmod_acl);
 	return result;
 #endif
diff --git a/source3/modules/vfs_extd_audit.c b/source3/modules/vfs_extd_audit.c
index 5aa6a30..0d8ca59 100644
--- a/source3/modules/vfs_extd_audit.c
+++ b/source3/modules/vfs_extd_audit.c
@@ -292,20 +292,22 @@ static int audit_chmod(vfs_handle_struct *handle,
 	return result;
 }
 
-static int audit_chmod_acl(vfs_handle_struct *handle, const char *path, mode_t mode)
+static int audit_chmod_acl(vfs_handle_struct *handle,
+			const struct smb_filename *smb_fname,
+			mode_t mode)
 {
 	int result;
 
-	result = SMB_VFS_NEXT_CHMOD_ACL(handle, path, mode);
+	result = SMB_VFS_NEXT_CHMOD_ACL(handle, smb_fname, mode);
 
 	if (lp_syslog() > 0) {
 		syslog(audit_syslog_priority(handle), "chmod_acl %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_acl %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_full_audit.c b/source3/modules/vfs_full_audit.c
index 43a8808..4a7b358 100644
--- a/source3/modules/vfs_full_audit.c
+++ b/source3/modules/vfs_full_audit.c
@@ -1951,14 +1951,15 @@ static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_stru
 }
 
 static int smb_full_audit_chmod_acl(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_ACL(handle, path, mode);
+	result = SMB_VFS_NEXT_CHMOD_ACL(handle, smb_fname, mode);
 
 	do_log(SMB_VFS_OP_CHMOD_ACL, (result >= 0), handle,
-	       "%s|%o", path, mode);
+	       "%s|%o", smb_fname->base_name, mode);
 
 	return result;
 }
diff --git a/source3/modules/vfs_linux_xfs_sgid.c b/source3/modules/vfs_linux_xfs_sgid.c
index fca0d13..0c0507b 100644
--- a/source3/modules/vfs_linux_xfs_sgid.c
+++ b/source3/modules/vfs_linux_xfs_sgid.c
@@ -96,7 +96,8 @@ static int linux_xfs_sgid_mkdir(vfs_handle_struct *handle,
 }
 
 static int linux_xfs_sgid_chmod_acl(vfs_handle_struct *handle,
-				    const char *name, mode_t mode)
+			const struct smb_filename *smb_fname,
+			mode_t mode)
 {
 	errno = ENOSYS;
 	return -1;
diff --git a/source3/modules/vfs_media_harmony.c b/source3/modules/vfs_media_harmony.c
index 6a54862..e1f05cc 100644
--- a/source3/modules/vfs_media_harmony.c
+++ b/source3/modules/vfs_media_harmony.c
@@ -2073,33 +2073,30 @@ out:
  * Failure: set errno, return -1
  */
 static int mh_chmod_acl(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_acl\n"));
-	if (!is_in_media_files(path))
+	if (!is_in_media_files(smb_fname->base_name))
 	{
-		status = SMB_VFS_NEXT_CHMOD_ACL(handle, path, mode);
+		status = SMB_VFS_NEXT_CHMOD_ACL(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_ACL(handle, clientPath, mode);
+	status = SMB_VFS_NEXT_CHMOD_ACL(handle, clientFname, mode);
 err:
-	TALLOC_FREE(clientPath);
+	TALLOC_FREE(clientFname);
 out:
 	return status;
 }
diff --git a/source3/modules/vfs_shadow_copy2.c b/source3/modules/vfs_shadow_copy2.c
index 1aaf44e..c83ce1e 100644
--- a/source3/modules/vfs_shadow_copy2.c
+++ b/source3/modules/vfs_shadow_copy2.c
@@ -1809,29 +1809,44 @@ static int shadow_copy2_setxattr(struct vfs_handle_struct *handle,
 }
 
 static int shadow_copy2_chmod_acl(vfs_handle_struct *handle,
-				  const char *fname, mode_t mode)
+			const struct smb_filename *smb_fname,
+			mode_t mode)
 {
 	time_t timestamp;
 	char *stripped;
 	ssize_t ret;
 	int saved_errno;
-	char *conv;
+	char *conv = NULL;
+	struct smb_filename *conv_smb_fname = NULL;
 
-	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_ACL(handle, fname, mode);
+		return SMB_VFS_NEXT_CHMOD_ACL(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_ACL(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_ACL(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 86952ef..2e04a48 100644
--- a/source3/modules/vfs_snapper.c
+++ b/source3/modules/vfs_snapper.c
@@ -2741,29 +2741,44 @@ static int snapper_gmt_setxattr(struct vfs_handle_struct *handle,
 }
 
 static int snapper_gmt_chmod_acl(vfs_handle_struct *handle,
-				 const char *fname, mode_t mode)
+			const struct smb_filename *smb_fname,
+			mode_t mode)
 {
 	time_t timestamp;
 	char *stripped;
 	ssize_t ret;
 	int saved_errno;
 	char *conv;
+	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_ACL(handle, fname, mode);
+		return SMB_VFS_NEXT_CHMOD_ACL(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_ACL(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_ACL(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 948f154..944251d 100644
--- a/source3/modules/vfs_time_audit.c
+++ b/source3/modules/vfs_time_audit.c
@@ -1941,19 +1941,22 @@ static NTSTATUS smb_time_audit_fset_nt_acl(vfs_handle_struct *handle,
 }
 
 static int smb_time_audit_chmod_acl(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_ACL(handle, path, mode);
+	result = SMB_VFS_NEXT_CHMOD_ACL(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_acl", timediff, path);
+		smb_time_audit_log_fname("chmod_acl",
+			timediff,
+			smb_fname->base_name);
 	}
 
 	return result;
diff --git a/source3/modules/vfs_unityed_media.c b/source3/modules/vfs_unityed_media.c
index 65e4d4c..dd6dc33 100644
--- a/source3/modules/vfs_unityed_media.c
+++ b/source3/modules/vfs_unityed_media.c
@@ -1571,28 +1571,32 @@ err:
 }
 
 static int um_chmod_acl(vfs_handle_struct *handle,
-			const char *path,
+			const struct smb_filename *smb_fname,
 			mode_t mode)
 {
 	int status;
-	char *client_path = NULL;
+	int saved_errno;
+	struct smb_filename *client_fname = NULL;
 
 	DEBUG(10, ("Entering um_chmod_acl\n"));
 
-	if (!is_in_media_files(path)) {
-		return SMB_VFS_NEXT_CHMOD_ACL(handle, path, mode);
+	if (!is_in_media_files(smb_fname->base_name)) {
+		return SMB_VFS_NEXT_CHMOD_ACL(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_ACL(handle, client_path, mode);
+	status = SMB_VFS_NEXT_CHMOD_ACL(handle, client_fname, mode);
 
 err:
-	TALLOC_FREE(client_path);
+	saved_errno = errno;
+	TALLOC_FREE(client_fname);
+	errno = saved_errno;
 	return status;
 }
 
diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c
index 9221107..02a94e8 100644
--- a/source3/smbd/vfs.c
+++ b/source3/smbd/vfs.c
@@ -2301,11 +2301,12 @@ NTSTATUS smb_vfs_call_audit_file(struct vfs_handle_struct *handle,
 					  access_denied);
 }
 
-int smb_vfs_call_chmod_acl(struct vfs_handle_struct *handle, const char *name,
-			   mode_t mode)
+int smb_vfs_call_chmod_acl(struct vfs_handle_struct *handle,
+		const struct smb_filename *smb_fname,
+		mode_t mode)
 {
 	VFS_FIND(chmod_acl);
-	return handle->fns->chmod_acl_fn(handle, name, mode);
+	return handle->fns->chmod_acl_fn(handle, smb_fname, mode);
 }
 
 int smb_vfs_call_fchmod_acl(struct vfs_handle_struct *handle,
diff --git a/source3/torture/cmd_vfs.c b/source3/torture/cmd_vfs.c
index 3e63714..a7e70b3 100644
--- a/source3/torture/cmd_vfs.c
+++ b/source3/torture/cmd_vfs.c
@@ -896,6 +896,7 @@ static NTSTATUS cmd_fchmod(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
 
 static NTSTATUS cmd_chmod_acl(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_acl <path> <mode>\n");
@@ -903,7 +904,16 @@ static NTSTATUS cmd_chmod_acl(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int ar
 	}
 
 	mode = atoi(argv[2]);
-	if (SMB_VFS_CHMOD_ACL(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_ACL(vfs->conn, smb_fname, mode) == -1) {
 		printf("chmod_acl: error=%d (%s)\n", errno, strerror(errno));
 		return NT_STATUS_UNSUCCESSFUL;
 	}
-- 
2.7.0.rc3.207.g0ac5344



More information about the samba-technical mailing list