diff options
author | vmallika <vmallika@redhat.com> | 2016-02-09 18:11:24 +0530 |
---|---|---|
committer | Rajesh Joseph <rjoseph@redhat.com> | 2016-02-15 00:20:39 -0800 |
commit | fa3df1f5eaf3104c0eb597b954dd17b1a067db8c (patch) | |
tree | dbc5458abfba05d2e40e8473acdb273414df4d03 /xlators/mgmt/glusterd/src | |
parent | 87faa0d763e1c416f12becc84b4c62cf6d545d1d (diff) |
uss: validate USS option features.snapshot-directory
This is a backport of http://review.gluster.org/#/c/9209
USS option features.snapshot-directory
contains only 'alphanum, -, _, .'
starts with dot (.)
value cannot exceed 255 characters
and throws error for any other argument.
> Change-Id: Iad64635206ddf5599351020d99aafb3dd9d17bc1
> BUG: 1168819
> Signed-off-by: vmallika <vmallika@redhat.com>
> Reviewed-on: http://review.gluster.org/9209
> Smoke: Gluster Build System <jenkins@build.gluster.com>
> Reviewed-by: Avra Sengupta <asengupt@redhat.com>
> Reviewed-by: Manikandan Selvaganesh <mselvaga@redhat.com>
> Reviewed-by: Rajesh Joseph <rjoseph@redhat.com>
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
> CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
Change-Id: I1b85d6851a223b51714c0498b457c41db99f5f58
BUG: 1305868
Signed-off-by: vmallika <vmallika@redhat.com>
Reviewed-on: http://review.gluster.org/13409
Smoke: Gluster Build System <jenkins@build.gluster.com>
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Rajesh Joseph <rjoseph@redhat.com>
Diffstat (limited to 'xlators/mgmt/glusterd/src')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volume-set.c | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-set.c b/xlators/mgmt/glusterd/src/glusterd-volume-set.c index 09ee73aba66..7a81fad13ae 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volume-set.c +++ b/xlators/mgmt/glusterd/src/glusterd-volume-set.c @@ -634,6 +634,57 @@ out: } static int +validate_uss_dir (glusterd_volinfo_t *volinfo, dict_t *dict, char *key, + char *value, char **op_errstr) +{ + char errstr[2048] = ""; + int ret = -1; + int i = 0; + xlator_t *this = NULL; + + this = THIS; + GF_ASSERT (this); + + i = strlen (value); + if (i > NAME_MAX) { + snprintf (errstr, sizeof (errstr), "value of %s exceedes %d " + "characters", key, NAME_MAX); + goto out; + } else if (i < 2) { + snprintf (errstr, sizeof (errstr), "value of %s too short, " + "expects atleast two characters", key); + goto out; + } + + if (value[0] != '.') { + snprintf (errstr, sizeof (errstr), "%s expects value starting " + "with '.' ", key); + goto out; + } + + for (i = 1; value[i]; i++) { + if (isalnum (value[i]) || value[i] == '_' || value[i] == '-') + continue; + + snprintf (errstr, sizeof (errstr), "%s expects value to" + " contain only '0-9a-z-_'", key); + goto out; + } + + ret = 0; +out: + if (ret) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + GD_MSG_INVALID_ENTRY, "%s", errstr); + *op_errstr = gf_strdup (errstr); + } + + gf_msg_debug (this->name, 0, "Returning %d", ret); + + return ret; +} + +static int validate_stripe (glusterd_volinfo_t *volinfo, dict_t *dict, char *key, char *value, char **op_errstr) { @@ -1677,7 +1728,10 @@ struct volopt_map_entry glusterd_volopt_map[] = { .op_version = GD_OP_VERSION_3_6_0, .value = ".snaps", .flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_XLATOR_OPT, - .description = "Entry point directory for entering snapshot world" + .validate_fn = validate_uss_dir, + .description = "Entry point directory for entering snapshot world. " + "Value can have only [0-9a-z-_] and starts with " + "dot (.) and cannot exceed 255 character" }, { .key = "features.show-snapshot-directory", |