summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmar Tumballi <amar@gluster.com>2010-08-13 07:10:25 +0000
committerAnand V. Avati <avati@dev.gluster.com>2010-08-13 11:25:28 -0700
commit57af0c92e351516c4056404ce0f2255c06b3c032 (patch)
tree61973ec05607d795846fccc9eea4c6ba1f3efc86
parentbce6e99400713a4ece37996376d28146aeebc3d4 (diff)
gluster create volume: cli validation added
Signed-off-by: Amar Tumballi <amar@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 1267 () URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1267
-rw-r--r--cli/src/cli-cmd-parser.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index 3d843680dee..96d1d197614 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -43,10 +43,11 @@ cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options
char *volname = NULL;
int ret = -1;
gf1_cluster_type type = GF_CLUSTER_TYPE_NONE;
- int count = 0;
+ int count = 1;
int brick_count = 0, brick_index = 0;
int brick_list_size = 1;
char brick_list[120000] = {0,};
+ int i = 0;
GF_ASSERT (words);
GF_ASSERT (options);
@@ -63,8 +64,24 @@ cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options
GF_ASSERT (volname);
- ret = dict_set_str (dict, "volname", volname);
+ /* Validate the volume name here itself */
+ {
+ if (volname[0] == '-')
+ goto out;
+
+ if (strchr (volname, '/'))
+ goto out;
+
+ if (strlen (volname) > 512)
+ goto out;
+ for (i = 0; i < strlen (volname); i++)
+ if (!isalnum (volname[i]))
+ goto out;
+ }
+
+
+ ret = dict_set_str (dict, "volname", volname);
if (ret)
goto out;
@@ -139,6 +156,13 @@ cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options
*/
}
+ /* If brick-count is not valid when replica or stripe is
+ given, exit here */
+ if (brick_count % count) {
+ ret = -1;
+ goto out;
+ }
+
ret = dict_set_str (dict, "bricks", brick_list);
if (ret)
goto out;