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