a3470f
From 6d6e3a4100fcb9333d82618d64e96e49ddddcbf4 Mon Sep 17 00:00:00 2001
a3470f
From: Amar Tumballi <amarts@redhat.com>
a3470f
Date: Mon, 16 Oct 2017 11:44:59 +0530
a3470f
Subject: [PATCH 37/74] protocol-auth: use the proper validation method
a3470f
a3470f
Currently, server protocol's init and glusterd's option
a3470f
validation methods are different, causing an issue. They
a3470f
should be same for having consistent behavior
a3470f
a3470f
> Upstream:
a3470f
> Change-Id: Ibbf9a18c7192b2d77f9b7675ae7da9b8d2fe5de4
a3470f
> URL: https://review.gluster.org/#/c/18489/
a3470f
a3470f
Change-Id: Id595a1032b14233ca8f31d20813dca98476b2468
a3470f
Signed-off-by: Amar Tumballi <amarts@redhat.com>
a3470f
Reviewed-on: https://code.engineering.redhat.com/gerrit/120558
a3470f
Tested-by: RHGS Build Bot <nigelb@redhat.com>
a3470f
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
a3470f
---
a3470f
 libglusterfs/src/options.c           |  4 ++--
a3470f
 libglusterfs/src/options.h           |  5 +++++
a3470f
 tests/features/subdir-mount.t        |  4 ++++
a3470f
 xlators/protocol/server/src/server.c | 40 +++++++-----------------------------
a3470f
 4 files changed, 18 insertions(+), 35 deletions(-)
a3470f
a3470f
diff --git a/libglusterfs/src/options.c b/libglusterfs/src/options.c
a3470f
index f0292ea..a0f04c7 100644
a3470f
--- a/libglusterfs/src/options.c
a3470f
+++ b/libglusterfs/src/options.c
a3470f
@@ -590,7 +590,7 @@ xlator_option_validate_addr (xlator_t *xl, const char *key, const char *value,
a3470f
         return ret;
a3470f
 }
a3470f
 
a3470f
-static int
a3470f
+int
a3470f
 xlator_option_validate_addr_list (xlator_t *xl, const char *key,
a3470f
                                   const char *value, volume_option_t *opt,
a3470f
                                   char **op_errstr)
a3470f
@@ -668,7 +668,7 @@ xlator_option_validate_addr_list (xlator_t *xl, const char *key,
a3470f
 out:
a3470f
         if (ret) {
a3470f
                 snprintf (errstr, sizeof (errstr), "option %s %s: '%s' is not "
a3470f
-                "a valid internet-address-list", key, value, value);
a3470f
+                          "a valid internet-address-list", key, value, value);
a3470f
                 gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s",
a3470f
                         errstr);
a3470f
                 if (op_errstr)
a3470f
diff --git a/libglusterfs/src/options.h b/libglusterfs/src/options.h
a3470f
index 3154dce..d259d44 100644
a3470f
--- a/libglusterfs/src/options.h
a3470f
+++ b/libglusterfs/src/options.h
a3470f
@@ -87,6 +87,11 @@ int xlator_options_validate_list (xlator_t *xl, dict_t *options,
a3470f
 int xlator_option_validate (xlator_t *xl, char *key, char *value,
a3470f
                             volume_option_t *opt, char **op_errstr);
a3470f
 int xlator_options_validate (xlator_t *xl, dict_t *options, char **errstr);
a3470f
+
a3470f
+int xlator_option_validate_addr_list (xlator_t *xl, const char *key,
a3470f
+                                      const char *value, volume_option_t *opt,
a3470f
+                                      char **op_errstr);
a3470f
+
a3470f
 volume_option_t *
a3470f
 xlator_volume_option_get (xlator_t *xl, const char *key);
a3470f
 
a3470f
diff --git a/tests/features/subdir-mount.t b/tests/features/subdir-mount.t
a3470f
index 2fb0be4..ab7ef35 100644
a3470f
--- a/tests/features/subdir-mount.t
a3470f
+++ b/tests/features/subdir-mount.t
a3470f
@@ -78,6 +78,10 @@ TEST ! $CLI volume set $V0 auth.allow "subdir2\(1.2.3.4\)"
a3470f
 # support subdir inside subdir
a3470f
 TEST $CLI volume set $V0 auth.allow '/subdir1/subdir1.1/subdir1.2/\(1.2.3.4\|::1\),/\(192.168.10.1\|192.168.11.1\),/subdir2\(1.2.3.4\)'
a3470f
 
a3470f
+TEST $CLI volume stop $V0
a3470f
+
a3470f
+TEST $CLI volume start $V0
a3470f
+
a3470f
 # /subdir2 has not allowed IP
a3470f
 TEST $GFS --subdir-mount /subdir2 -s $H0 --volfile-id $V0 $M1
a3470f
 TEST stat $M1
a3470f
diff --git a/xlators/protocol/server/src/server.c b/xlators/protocol/server/src/server.c
a3470f
index e47acb2..6dc9d0f 100644
a3470f
--- a/xlators/protocol/server/src/server.c
a3470f
+++ b/xlators/protocol/server/src/server.c
a3470f
@@ -386,9 +386,6 @@ _check_for_auth_option (dict_t *d, char *k, data_t *v,
a3470f
         int       ret           = 0;
a3470f
         xlator_t *xl            = NULL;
a3470f
         char     *tail          = NULL;
a3470f
-        char     *tmp_addr_list = NULL;
a3470f
-        char     *addr          = NULL;
a3470f
-        char     *tmp_str       = NULL;
a3470f
 
a3470f
         xl = tmp;
a3470f
 
a3470f
@@ -417,38 +414,15 @@ _check_for_auth_option (dict_t *d, char *k, data_t *v,
a3470f
                  * valid auth.allow.<xlator>
a3470f
                  * Now we verify the ip address
a3470f
                  */
a3470f
-                if (!strcmp (v->data, "*")) {
a3470f
-                        ret = 0;
a3470f
-                        goto out;
a3470f
-                }
a3470f
-
a3470f
-                /* TODO-SUBDIR-MOUNT: fix the format */
a3470f
-                tmp_addr_list = gf_strdup (v->data);
a3470f
-                addr = strtok_r (tmp_addr_list, ",", &tmp_str);
a3470f
-                if (!addr)
a3470f
-                        addr = v->data;
a3470f
-
a3470f
-                while (addr) {
a3470f
-                        if (valid_internet_address (addr, _gf_true)) {
a3470f
-                                ret = 0;
a3470f
-                        } else {
a3470f
-                                ret = -1;
a3470f
-                                gf_msg (xl->name, GF_LOG_ERROR, 0,
a3470f
-                                        PS_MSG_INTERNET_ADDR_ERROR,
a3470f
-                                        "internet address '%s'"
a3470f
-                                        " does not conform to"
a3470f
-                                        " standards.", addr);
a3470f
-                                goto out;
a3470f
-                        }
a3470f
-                        if (tmp_str)
a3470f
-                                addr = strtok_r (NULL, ",", &tmp_str);
a3470f
-                        else
a3470f
-                                addr = NULL;
a3470f
-                }
a3470f
+                ret = xlator_option_validate_addr_list (xl, "auth-*", v->data,
a3470f
+                                                        NULL, NULL);
a3470f
+                if (ret)
a3470f
+                        gf_msg (xl->name, GF_LOG_ERROR, 0,
a3470f
+                                PS_MSG_INTERNET_ADDR_ERROR,
a3470f
+                                "internet address '%s' does not conform "
a3470f
+                                "to standards.", v->data);
a3470f
         }
a3470f
 out:
a3470f
-        GF_FREE (tmp_addr_list);
a3470f
-
a3470f
         return ret;
a3470f
 }
a3470f
 
a3470f
-- 
a3470f
1.8.3.1
a3470f