diff options
author | Harshavardhana Ranganath <harsha@gluster.com> | 2010-02-11 10:29:11 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2010-02-20 02:55:11 -0800 |
commit | 2cf958fd48129f682c19645ef007f9b1fe9fcd82 (patch) | |
tree | 7ffc77bc15c07fa45869c9d90c5b0fec7868f1b2 /xlators | |
parent | 54b77d368f5a0e7cef6da6754c14a16d05dc7dda (diff) |
Support new option "conf-dir"
Addresses fetching volume files from a non standard directory right
now it is hardcoded to "CONFDIR" which is build time constant.
Signed-off-by: Harshavardhana <harsha@gluster.com>
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 609 (Add new "conf-dir" option)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=609
Diffstat (limited to 'xlators')
-rw-r--r-- | xlators/protocol/server/src/server-protocol.c | 79 |
1 files changed, 60 insertions, 19 deletions
diff --git a/xlators/protocol/server/src/server-protocol.c b/xlators/protocol/server/src/server-protocol.c index c3b8d31d6d8..993323a1d4e 100644 --- a/xlators/protocol/server/src/server-protocol.c +++ b/xlators/protocol/server/src/server-protocol.c @@ -5195,10 +5195,14 @@ size_t build_volfile_path (xlator_t *this, const char *key, char *path, size_t path_len) { - int ret = -1; - int free_filename = 0; - char *filename = NULL; - char data_key[256] = {0,}; + int ret = -1; + int free_filename = 0; + int free_conf_dir = 0; + char *filename = NULL; + char *conf_dir = CONFDIR; + struct stat buf = {0,}; + data_t * conf_dir_data = NULL; + char data_key[256] = {0,}; /* Inform users that this option is changed now */ ret = dict_get_str (this->options, "client-volume-filename", @@ -5216,24 +5220,54 @@ build_volfile_path (xlator_t *this, const char *key, char *path, if (key && !filename) { sprintf (data_key, "volume-filename.%s", key); ret = dict_get_str (this->options, data_key, &filename); + if (ret < 0) { - /* Make sure that key doesn't contain - * "../" in path - */ - if (!strstr (key, "../")) { - ret = asprintf (&filename, "%s/%s.vol", - CONFDIR, key); - if (-1 == ret) { + + conf_dir_data = dict_get (this->options, "conf-dir"); + if (conf_dir_data) { + /* Check whether the specified directory exists, + or directory specified is non standard */ + ret = stat (conf_dir_data->data, &buf); + if ((ret != 0) || !S_ISDIR (buf.st_mode)) { gf_log (this->name, GF_LOG_ERROR, - "asprintf failed to get " - "volume file path"); - } else { - free_filename = 1; + "Directory '%s' doesn't" + "exist, exiting.", + conf_dir_data->data); + ret = -1; + goto out; } - } else { - gf_log (this->name, GF_LOG_DEBUG, - "%s: invalid key", key); + /* Make sure that conf-dir doesn't + * contain ".." in path + */ + if (strstr (conf_dir_data->data, "..")) { + ret = -1; + gf_log (this->name, GF_LOG_ERROR, + "%s: invalid conf_dir", + conf_dir_data->data); + goto out; + } + + /* Make sure that key doesn't + * contain "../" in path + */ + + if (strstr (key, "../")) { + ret = -1; + gf_log (this->name, GF_LOG_ERROR, + "%s: invalid key", key); + goto out; + } + + conf_dir = strdup (conf_dir_data->data); + free_conf_dir = 1; } + + ret = asprintf (&filename, "%s/%s.vol", + conf_dir, key); + if (-1 == ret) + goto out; + + free_filename = 1; } } @@ -5244,17 +5278,21 @@ build_volfile_path (xlator_t *this, const char *key, char *path, gf_log (this->name, GF_LOG_DEBUG, "no default volume filename given, " "defaulting to %s", DEFAULT_VOLUME_FILE_PATH); - filename = DEFAULT_VOLUME_FILE_PATH; } } ret = -1; + if ((filename) && (path_len > strlen (filename))) { strcpy (path, filename); ret = strlen (filename); } +out: + if (free_conf_dir) + free (conf_dir); + if (free_filename) free (filename); @@ -6825,6 +6863,9 @@ struct volume_options options[] = { { .key = {"trace"}, .type = GF_OPTION_TYPE_BOOL }, + { .key = {"conf-dir"}, + .type = GF_OPTION_TYPE_PATH, + }, { .key = {NULL} }, }; |