1
0
mirror of https://github.com/gluster/glusterfs.git synced 2026-02-05 15:48:40 +01:00

cli: Validate invalid slave url

This patch validates the invalid slave url
in cli itself and throws appropriate error.

fixes: bz#1098991
Change-Id: I278e2a04a4d619d2c2d1db0dd56ab5bdf7e7f469
Signed-off-by: Kotresh HR <khiremat@redhat.com>
This commit is contained in:
Kotresh HR
2019-04-23 12:41:32 +05:30
committed by Amar Tumballi
parent b4db967224
commit af4d9131c8
4 changed files with 31 additions and 5 deletions

View File

@@ -2485,6 +2485,17 @@ gsyncd_url_check(const char *w)
return !!strpbrk(w, ":/");
}
static gf_boolean_t
valid_slave_gsyncd_url(const char *w)
{
if (strstr(w, ":::"))
return _gf_false;
else if (strstr(w, "::"))
return _gf_true;
else
return _gf_false;
}
static gf_boolean_t
gsyncd_glob_check(const char *w)
{
@@ -2708,7 +2719,8 @@ out:
}
int32_t
cli_cmd_gsync_set_parse(const char **words, int wordcount, dict_t **options)
cli_cmd_gsync_set_parse(const char **words, int wordcount, dict_t **options,
char **errstr)
{
int32_t ret = -1;
dict_t *dict = NULL;
@@ -2797,8 +2809,11 @@ cli_cmd_gsync_set_parse(const char **words, int wordcount, dict_t **options)
if (masteri && gsyncd_url_check(words[masteri]))
goto out;
if (slavei && !glob && !gsyncd_url_check(words[slavei]))
if (slavei && !glob && !valid_slave_gsyncd_url(words[slavei])) {
gf_asprintf(errstr, "Invalid slave url: %s", words[slavei]);
goto out;
}
w = str_getunamb(words[cmdi], opwords);
if (!w)

View File

@@ -2138,6 +2138,7 @@ cli_cmd_volume_gsync_set_cbk(struct cli_state *state, struct cli_cmd_word *word,
rpc_clnt_procedure_t *proc = NULL;
call_frame_t *frame = NULL;
cli_local_t *local = NULL;
char *errstr = NULL;
#if (USE_EVENTS)
int ret1 = -1;
int cmd_type = -1;
@@ -2155,9 +2156,14 @@ cli_cmd_volume_gsync_set_cbk(struct cli_state *state, struct cli_cmd_word *word,
goto out;
}
ret = cli_cmd_gsync_set_parse(words, wordcount, &options);
ret = cli_cmd_gsync_set_parse(words, wordcount, &options, &errstr);
if (ret) {
cli_usage_out(word->pattern);
if (errstr) {
cli_err("%s", errstr);
GF_FREE(errstr);
} else {
cli_usage_out(word->pattern);
}
parse_err = 1;
goto out;
}

View File

@@ -266,7 +266,8 @@ int32_t
cli_cmd_volume_reset_parse(const char **words, int wordcount, dict_t **opt);
int32_t
cli_cmd_gsync_set_parse(const char **words, int wordcount, dict_t **opt);
cli_cmd_gsync_set_parse(const char **words, int wordcount, dict_t **opt,
char **errstr);
int32_t
cli_cmd_quota_parse(const char **words, int wordcount, dict_t **opt);

View File

@@ -51,6 +51,10 @@ TEST glusterfs -s $H0 --volfile-id $GSV0 $M1
#BASIC GEO-REPLICATION TESTS
############################################################
#Test invalid slave url
TEST ! $GEOREP_CLI $master ${SH0}:${GSV0} create push-pem
TEST ! $GEOREP_CLI $master ${SH0}:::${GSV0} create push-pem
#Create geo-rep session
TEST create_georep_session $master $slave