Blob Blame History Raw
From d681e7bddba62b90a52c21423097280071cb6e44 Mon Sep 17 00:00:00 2001
From: Niels de Vos <ndevos@redhat.com>
Date: Tue, 1 Aug 2017 10:42:59 +0200
Subject: [PATCH 584/587] 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.

Cherry picked from commit 45c973576d6356dbe4da897e9f0528eac7529d48:
> Change-Id: I0d810ae90b267a2cc3eac8d55368a0f1b0787f6a
> Fixes: e3f48fa2 ("nfs: add permission checking for mounting over WebNFS")
> BUG: 1468291
> Signed-off-by: Niels de Vos <ndevos@redhat.com>
> Reviewed-on: https://review.gluster.org/17898
> Smoke: Gluster Build System <jenkins@build.gluster.org>
> Reviewed-by: soumya k <skoduri@redhat.com>
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
> Reviewed-by: jiffin tony Thottan <jthottan@redhat.com>

Change-Id: I0d810ae90b267a2cc3eac8d55368a0f1b0787f6a
BUG: 1472773
Signed-off-by: Niels de Vos <ndevos@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/113998
Reviewed-by: Jiffin Thottan <jthottan@redhat.com>
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
---
 xlators/nfs/server/src/mount3.c | 31 ++++++++++++++-----------------
 1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/xlators/nfs/server/src/mount3.c b/xlators/nfs/server/src/mount3.c
index a5b081b..376331c 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:
@@ -1589,8 +1593,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) {
@@ -1777,11 +1779,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);
-- 
1.8.3.1