Patchwork [BUG:1505,1/3] Volume create hostname should not be localhost

login
register
Submitter shishir gowda
Date 2010-09-04 06:41:34
Message ID <20100904064134.GA4141@dev.gluster.com>
Download mbox | patch
Permalink /patch/4542/
State Accepted
Headers show

Comments

shishir gowda - 2010-09-04 06:41:34
volume create hostname should not be localhost or 127.0.0.1. It
 should be a valid nodeid or ip. This will prevent invalid vol
 files being created on glusterd's when localhost or 127.0.0.1 is
 specified

Signed-off-by: shishir gowda <shishirng@gluster.com>
---
 cli/src/cli-cmd-parser.c                     |   23 +++++++++++++++++++++++
 xlators/mgmt/glusterd/src/glusterd-handler.c |    2 +-
 2 files changed, 24 insertions(+), 1 deletions(-)

Patch

diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index fb3b162..cf9357c 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -52,6 +52,9 @@  cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options
         char    *tmp_list = NULL;
         char    *tmpptr = NULL;
         int     j = 0;
+        char    *host_name = NULL;
+        char    *tmp = NULL;
+        char    *freeptr = NULL;
 
         GF_ASSERT (words);
         GF_ASSERT (options);
@@ -164,6 +167,26 @@  cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options
                         ret = -1;
                         goto out;
                 }
+
+                host_name = gf_strdup(words[brick_index]);
+                if (!host_name) {
+                        ret = -1;
+                        gf_log("cli",GF_LOG_ERROR, "Unable to allocate "
+                               "memory");
+                        goto out;
+                }
+                freeptr = host_name;
+                
+                strtok_r(host_name, ":", &tmp);
+                if (!(strcmp(host_name, "localhost") &&
+                      strcmp (host_name, "127.0.0.1"))) {
+                        cli_out ("Please provide a valid hostname/ip other "
+                                 "localhost or 127.0.0.1");
+                        ret = -1;
+                        GF_FREE(freeptr);
+                        goto out;
+                }
+                GF_FREE (freeptr);
                 tmp_list = strdup(brick_list+1);
                 j = 0;
                 while(( brick_count != 0) && (j < brick_count)) {
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index 4df404e..610d1d2 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -1631,7 +1631,7 @@  glusterd_handle_remove_brick (rpcsvc_request_t *req)
 
         }
 
-        brick_list = GF_MALLOC (120000 * sizeof(brick_list),gf_common_mt_char);
+        brick_list = GF_MALLOC (120000 * sizeof(*brick_list),gf_common_mt_char);
 
         if (!brick_list) {
                 gf_log ("",GF_LOG_ERROR,"glusterd_handle_remove_brick: "