From eb8561e302bd83305fb093eb8cca42b4f9f62b22 Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Tue, 21 Sep 2010 10:49:49 +0000 Subject: cli: remove trailing slashes from brick paths Signed-off-by: Pranith Kumar K Signed-off-by: Vijay Bellur BUG: 1659 () URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1659 --- cli/src/cli-cmd-parser.c | 61 ++++++++++++++++++++++++++++++++++++++++-------- cli/src/cli.c | 20 ++++++++++++++++ cli/src/cli.h | 2 ++ 3 files changed, 73 insertions(+), 10 deletions(-) (limited to 'cli') diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 479df9386..2b7cdd9f6 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -189,6 +189,8 @@ cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options "", words[brick_index]); ret = -1; goto out; + } else { + cli_path_strip_trailing_slashes (delimiter + 1); } if ((brick_list_size + strlen (words[brick_index]) + 1) > 120000) { gf_log ("cli", GF_LOG_ERROR, @@ -451,7 +453,10 @@ cli_cmd_volume_add_brick_parse (const char **words, int wordcount, "", words[brick_index]); ret = -1; goto out; + } else { + cli_path_strip_trailing_slashes (delimiter + 1); } + if ((brick_list_size + strlen (words[brick_index]) + 1) > 120000) { gf_log ("cli", GF_LOG_ERROR, "total brick list is larger than a request " @@ -635,7 +640,10 @@ cli_cmd_volume_remove_brick_parse (const char **words, int wordcount, "", words[brick_index]); ret = -1; goto out; + } else { + cli_path_strip_trailing_slashes (delimiter + 1); } + j = tmp_index; strcpy(tmp_brick, words[brick_index]); while ( j < brick_index) { @@ -723,6 +731,7 @@ cli_cmd_volume_replace_brick_parse (const char **words, int wordcount, delimiter = strchr ((char *)words[3], ':'); if (delimiter && delimiter != words[3] && *(delimiter+1) == '/') { + cli_path_strip_trailing_slashes (delimiter + 1); ret = dict_set_str (dict, "src-brick", (char *)words[3]); if (ret) @@ -740,8 +749,11 @@ cli_cmd_volume_replace_brick_parse (const char **words, int wordcount, ":", words[4]); ret = -1; goto out; + } else { + cli_path_strip_trailing_slashes (delimiter + 1); } + ret = dict_set_str (dict, "dst-brick", (char *)words[4]); if (ret) @@ -800,6 +812,7 @@ cli_cmd_log_filename_parse (const char **words, int wordcount, dict_t **options) char *volname = NULL; char *str = NULL; int ret = -1; + char *delimiter = NULL; GF_ASSERT (words); GF_ASSERT (options); @@ -821,6 +834,16 @@ cli_cmd_log_filename_parse (const char **words, int wordcount, dict_t **options) str = (char *)words[4]; if (strchr (str, ':')) { + delimiter = strchr (words[4], ':'); + if (!delimiter || delimiter == words[4] + || *(delimiter+1) != '/') { + cli_out ("wrong brick type: %s, use :" + "", words[4]); + ret = -1; + goto out; + } else { + cli_path_strip_trailing_slashes (delimiter + 1); + } ret = dict_set_str (dict, "brick", str); if (ret) goto out; @@ -851,6 +874,7 @@ cli_cmd_log_locate_parse (const char **words, int wordcount, dict_t **options) char *volname = NULL; char *str = NULL; int ret = -1; + char *delimiter = NULL; GF_ASSERT (words); GF_ASSERT (options); @@ -870,12 +894,20 @@ cli_cmd_log_locate_parse (const char **words, int wordcount, dict_t **options) if (ret) goto out; - str = (char *)words[4]; - if (str && strchr (str, ':')) { - ret = dict_set_str (dict, "brick", str); - if (ret) - goto out; + delimiter = strchr (words[4], ':'); + if (!delimiter || delimiter == words[4] + || *(delimiter+1) != '/') { + cli_out ("wrong brick type: %s, use :" + "", words[4]); + ret = -1; + goto out; + } else { + cli_path_strip_trailing_slashes (delimiter + 1); } + str = (char *)words[4]; + ret = dict_set_str (dict, "brick", str); + if (ret) + goto out; *options = dict; @@ -893,6 +925,7 @@ cli_cmd_log_rotate_parse (const char **words, int wordcount, dict_t **options) char *volname = NULL; char *str = NULL; int ret = -1; + char *delimiter = NULL; GF_ASSERT (words); GF_ASSERT (options); @@ -912,12 +945,20 @@ cli_cmd_log_rotate_parse (const char **words, int wordcount, dict_t **options) if (ret) goto out; - str = (char *)words[4]; - if (str && strchr (str, ':')) { - ret = dict_set_str (dict, "brick", str); - if (ret) - goto out; + delimiter = strchr (words[4], ':'); + if (!delimiter || delimiter == words[4] + || *(delimiter+1) != '/') { + cli_out ("wrong brick type: %s, use :" + "", words[4]); + ret = -1; + goto out; + } else { + cli_path_strip_trailing_slashes (delimiter + 1); } + str = (char *)words[4]; + ret = dict_set_str (dict, "brick", str); + if (ret) + goto out; *options = dict; diff --git a/cli/src/cli.c b/cli/src/cli.c index 8730211bf..a08d2d214 100644 --- a/cli/src/cli.c +++ b/cli/src/cli.c @@ -495,6 +495,26 @@ cli_local_wipe (cli_local_t *local) return; } +void +cli_path_strip_trailing_slashes (char *path) +{ + int i = 0; + int len = 0; + + if (!path) + return; + + len = strlen (path); + for (i = len - 1; i > 0 ; i--) { + if (path[i] != '/') + break; + + } + + if (i < (len - 1)) + path[i + 1] = '\0'; +} + struct cli_state *global_state; int diff --git a/cli/src/cli.h b/cli/src/cli.h index 44f653685..b8aa985b8 100644 --- a/cli/src/cli.h +++ b/cli/src/cli.h @@ -207,4 +207,6 @@ cli_cmd_broadcast_connected (); int cli_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event, void *data); +void +cli_path_strip_trailing_slashes (char *path); #endif /* __CLI_H__ */ -- cgit