From 7c59c0849e4c54be7473151dd45468c68b957ec4 Mon Sep 17 00:00:00 2001 From: Harshavardhana Ranganath Date: Mon, 22 Feb 2010 04:37:47 +0000 Subject: Add new gf_strstr dropin replacement for "strstr" Signed-off-by: Harshavardhana Signed-off-by: Anand V. Avati BUG: 609 (Add new "conf-dir" option) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=609 --- libglusterfs/src/common-utils.c | 36 +++++++++++++++++++++++++++ libglusterfs/src/common-utils.h | 2 ++ xlators/protocol/server/src/server-protocol.c | 5 ++-- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 3f52a90a010..7b5e02a344c 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -565,6 +565,42 @@ free_exit: } int +gf_strstr (const char *str, const char *delim, const char *match) +{ + char *tmp = NULL; + char *save_ptr = NULL; + char *tmp_str = NULL; + + int ret = 0; + + tmp_str = strdup (str); + + if (str == NULL || delim == NULL || match == NULL || tmp_str == NULL) { + ret = -1; + goto out; + } + + + tmp = strtok_r (tmp_str, delim, &save_ptr); + + while (tmp) { + ret = strcmp (tmp, match); + + if (ret == 0) + break; + + tmp = strtok_r (NULL, delim, &save_ptr); + } + +out: + if (tmp_str) + free (tmp_str); + + return ret; + +} + +int gf_volume_name_validate (const char *volume_name) { const char *vname = NULL; diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index 48788d29545..05acfd83d29 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -313,6 +313,8 @@ int gf_string2uint16 (const char *str, uint16_t *n); int gf_string2uint32 (const char *str, uint32_t *n); int gf_string2uint64 (const char *str, uint64_t *n); +int gf_strstr (const char *str, const char *delim, const char *match); + int gf_string2ulong_base10 (const char *str, unsigned long *n); int gf_string2uint_base10 (const char *str, unsigned int *n); int gf_string2uint8_base10 (const char *str, uint8_t *n); diff --git a/xlators/protocol/server/src/server-protocol.c b/xlators/protocol/server/src/server-protocol.c index 993323a1d4e..608b3151358 100644 --- a/xlators/protocol/server/src/server-protocol.c +++ b/xlators/protocol/server/src/server-protocol.c @@ -5239,7 +5239,8 @@ build_volfile_path (xlator_t *this, const char *key, char *path, /* Make sure that conf-dir doesn't * contain ".." in path */ - if (strstr (conf_dir_data->data, "..")) { + if ((gf_strstr (conf_dir_data->data, + "/", "..")) == -1) { ret = -1; gf_log (this->name, GF_LOG_ERROR, "%s: invalid conf_dir", @@ -5251,7 +5252,7 @@ build_volfile_path (xlator_t *this, const char *key, char *path, * contain "../" in path */ - if (strstr (key, "../")) { + if ((gf_strstr (key, "/", "..")) == -1) { ret = -1; gf_log (this->name, GF_LOG_ERROR, "%s: invalid key", key); -- cgit