From 45c973576d6356dbe4da897e9f0528eac7529d48 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Tue, 25 Jul 2017 09:25:53 +0200 Subject: nfs: use "/" as subdir for volume mounts For cases where subdir mounting is checked, it makes it much easier to return a subdir of "/" in case no subdir is passed. This reduces the number of corner cases where permissions are checked for subdir mounts, but not for volume mounts (or the other way around). The problem was identified by WebNFS mounting a volume, which got denied after commit e3f48fa2. Handling this would require an exception for non-subdir mounts, or make non-subdir mounts equal to subdir mounts. This change takes the 2nd approach. Change-Id: I0d810ae90b267a2cc3eac8d55368a0f1b0787f6a Fixes: e3f48fa2 ("nfs: add permission checking for mounting over WebNFS") BUG: 1468291 Signed-off-by: Niels de Vos Reviewed-on: https://review.gluster.org/17898 Smoke: Gluster Build System Reviewed-by: soumya k CentOS-regression: Gluster Build System Reviewed-by: jiffin tony Thottan --- xlators/nfs/server/src/mount3.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'xlators/nfs') diff --git a/xlators/nfs/server/src/mount3.c b/xlators/nfs/server/src/mount3.c index a05c08cc606..64f10948425 100644 --- a/xlators/nfs/server/src/mount3.c +++ b/xlators/nfs/server/src/mount3.c @@ -947,18 +947,26 @@ err: char * mnt3_get_volume_subdir (char *dirpath, char **volname) { - char *subdir = NULL; - int volname_len = 0; + /* subdir points to the first / after the volume name while dirpath + * points to the first char of the volume name. + */ + char *subdir = NULL; + int volname_len = 0; + static char *root = "/"; - if (!dirpath) - return NULL; + /* all callers are expected to pass a valid *dirpath */ + GF_ASSERT (dirpath); if (dirpath[0] == '/') dirpath++; subdir = index (dirpath, (int)'/'); - if (!subdir) - goto out; + if (!subdir) { + subdir = root; + volname_len = strlen (dirpath); + } else { + volname_len = subdir - dirpath; + } if (!volname) goto out; @@ -966,10 +974,6 @@ mnt3_get_volume_subdir (char *dirpath, char **volname) if (!*volname) goto out; - /* subdir points to the first / after the volume name while dirpath - * points to the first char of the volume name. - */ - volname_len = subdir - dirpath; strncpy (*volname, dirpath, volname_len); *(*volname + volname_len) = '\0'; out: @@ -1588,8 +1592,6 @@ mnt3_resolve_export_subdir (rpcsvc_request_t *req, struct mount3_state *ms, return ret; volume_subdir = mnt3_get_volume_subdir (exp->expname, NULL); - if (!volume_subdir) - goto err; ret = mnt3_resolve_subdir (req, ms, exp, volume_subdir, _gf_true); if (ret < 0) { @@ -1788,11 +1790,6 @@ mnt3_parse_dir_exports (rpcsvc_request_t *req, struct mount3_state *ms, volname_ptr = volname; subdir = mnt3_get_volume_subdir (path, &volname_ptr); - if (!subdir) { - gf_msg_trace (GF_MNT, 0, "Could not parse volname/subdir from " - "%s", path); - goto err; - } /* first try to match the full export/subdir */ exp = mnt3_mntpath_to_export (ms, path, _gf_false); -- cgit