summaryrefslogtreecommitdiffstats
path: root/cli/src/cli-cmd-parser.c
diff options
context:
space:
mode:
authorPranith Kumar K <pranithk@gluster.com>2010-08-26 12:17:37 +0000
committerVijay Bellur <vijay@dev.gluster.com>2010-08-27 02:26:22 -0700
commitc97156833355697a381e5e6a1c14142d8c9f3593 (patch)
treee206197819b92f31cb7d23819d2dbfdc570a517e /cli/src/cli-cmd-parser.c
parent228d11a9c91a5f5be9a2827a93cc5b7afef2d96a (diff)
cli, mgmt/glusterd: validate brick
Signed-off-by: Pranith Kumar K <pranithk@gluster.com> Signed-off-by: Vijay Bellur <vijay@dev.gluster.com>
Diffstat (limited to 'cli/src/cli-cmd-parser.c')
-rw-r--r--cli/src/cli-cmd-parser.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index d8464067d..4b8520c67 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -41,6 +41,7 @@ cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options
{
dict_t *dict = NULL;
char *volname = NULL;
+ char *delimiter = NULL;
int ret = -1;
gf1_cluster_type type = GF_CLUSTER_TYPE_NONE;
int count = 1;
@@ -148,8 +149,9 @@ cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options
goto out;
strcpy (brick_list, " ");
while (brick_index < wordcount) {
- GF_ASSERT (words[brick_index]);
- if (!strchr (words[brick_index], ':')) {
+ delimiter = strchr (words[brick_index], ':');
+ if (!delimiter || delimiter == words[brick_index]
+ || *(delimiter+1) != '/') {
gf_log ("cli", GF_LOG_ERROR,
"wrong brick type, use <HOSTNAME>:<export-dir>");
ret = -1;
@@ -296,6 +298,7 @@ cli_cmd_volume_add_brick_parse (const char **words, int wordcount,
{
dict_t *dict = NULL;
char *volname = NULL;
+ char *delimiter = NULL;
int ret = -1;
gf1_cluster_type type = GF_CLUSTER_TYPE_NONE;
int count = 0;
@@ -356,8 +359,9 @@ cli_cmd_volume_add_brick_parse (const char **words, int wordcount,
strcpy (brick_list, " ");
while (brick_index < wordcount) {
- GF_ASSERT (words[brick_index]);
- if (!strchr (words[brick_index], ':')) {
+ delimiter = strchr (words[brick_index], ':');
+ if (!delimiter || delimiter == words[brick_index]
+ || *(delimiter+1) != '/') {
gf_log ("cli", GF_LOG_ERROR,
"wrong brick type, use <HOSTNAME>:<export-dir>");
ret = -1;
@@ -413,6 +417,7 @@ cli_cmd_volume_remove_brick_parse (const char **words, int wordcount,
{
dict_t *dict = NULL;
char *volname = NULL;
+ char *delimiter = NULL;
int ret = -1;
gf1_cluster_type type = GF_CLUSTER_TYPE_NONE;
int count = 0;
@@ -475,7 +480,14 @@ cli_cmd_volume_remove_brick_parse (const char **words, int wordcount,
goto out;
while (brick_index < wordcount) {
- GF_ASSERT (words[brick_index]);
+ delimiter = strchr(words[brick_index], ':');
+ if (!delimiter || delimiter == words[brick_index]
+ || *(delimiter+1) != '/') {
+ gf_log ("cli", GF_LOG_ERROR,
+ "wrong brick type, use <HOSTNAME>:<export-dir>");
+ ret = -1;
+ goto out;
+ }
snprintf (key, 50, "brick%d", ++brick_count);
ret = dict_set_str (dict, key, (char *)words[brick_index++]);
@@ -511,6 +523,7 @@ cli_cmd_volume_replace_brick_parse (const char **words, int wordcount,
int ret = -1;
char *op = NULL;
int op_index = 0;
+ char *delimiter = NULL;
gf1_cli_replace_op replace_op = GF_REPLACE_OP_NONE;
GF_ASSERT (words);
@@ -541,7 +554,9 @@ cli_cmd_volume_replace_brick_parse (const char **words, int wordcount,
goto out;
}
- if (strchr ((char *)words[3], ':')) {
+ delimiter = strchr ((char *)words[3], ':');
+ if (delimiter && delimiter != words[3]
+ && *(delimiter+1) == '/') {
ret = dict_set_str (dict, "src-brick", (char *)words[3]);
if (ret)
@@ -552,6 +567,15 @@ cli_cmd_volume_replace_brick_parse (const char **words, int wordcount,
goto out;
}
+ delimiter = strchr ((char *)words[4], ':');
+ if (!delimiter || delimiter == words[4]
+ || *(delimiter+1) != '/') {
+ gf_log ("cli", GF_LOG_ERROR,
+ "wrong brick type, use <HOSTNAME>:<export-dir>");
+ ret = -1;
+ goto out;
+ }
+
ret = dict_set_str (dict, "dst-brick", (char *)words[4]);
if (ret)