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