summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cli/src/cli-cmd-parser.c6
-rw-r--r--cli/src/cli.c64
-rw-r--r--cli/src/cli.h3
3 files changed, 71 insertions, 2 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index 0097703f6c9..a767dfc35b7 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -75,13 +75,15 @@ cli_cmd_bricks_parse (const char **words, int wordcount, int brick_index,
brick_list_len++;
while (brick_index < wordcount) {
if (validate_brick_name ((char *)words[brick_index])) {
- cli_out ("wrong brick type: %s, use <HOSTNAME>:"
+ cli_out ("Wrong brick type: %s, use <HOSTNAME>:"
"<export-dir-abs-path>", words[brick_index]);
ret = -1;
goto out;
} else {
delimiter = strrchr (words[brick_index], ':');
- cli_path_strip_trailing_slashes (delimiter + 1);
+ ret = cli_canonicalize_path (delimiter + 1);
+ if (ret)
+ goto out;
}
if ((brick_list_len + strlen (words[brick_index]) + 1) > sizeof (brick_list)) {
diff --git a/cli/src/cli.c b/cli/src/cli.c
index 8d37405c614..8a06c8abd76 100644
--- a/cli/src/cli.c
+++ b/cli/src/cli.c
@@ -568,6 +568,70 @@ cli_local_wipe (cli_local_t *local)
return;
}
+/* If the path exists use realpath(3) to handle extra slashes and to resolve
+ * symlinks else strip the extra slashes in the path and return */
+
+int
+cli_canonicalize_path (char *path)
+{
+ struct stat sb = {0};
+ int ret = -1;
+ char *tmppath = NULL;
+ char *dir = NULL;
+ char *tmpstr = NULL;
+ int path_len = 0;
+
+ if (!path)
+ return ret;
+
+ ret = stat (path, &sb);
+ if (ret == -1) {
+ /* Strip the extra slashes and return */
+ tmppath = gf_strdup (path);
+ if (tmppath == NULL) {
+ ret = -1;
+ gf_log ("cli", GF_LOG_ERROR, "Out of memory.");
+ goto out;
+ }
+ bzero (path, strlen(path));
+ path[0] = '/';
+ dir = strtok_r(tmppath, "/", &tmpstr);
+ while (dir) {
+ strncpy ((path + path_len + 1), dir, strlen(dir));
+ path_len = strlen (path);
+ dir = strtok_r(NULL, "/", &tmpstr);
+ if (dir)
+ strncpy((path + path_len), "/", 1);
+ }
+ if (path_len == 0)
+ path[1] = '\0';
+ else
+ path[path_len] = '\0';
+ ret = 0;
+ goto out;
+ } else {
+ tmppath = gf_strdup(path);
+ if (tmppath == NULL) {
+ ret = -1;
+ gf_log ("cli", GF_LOG_ERROR, "Out of memory.");
+ goto out;
+ }
+ if (realpath (tmppath, path) == NULL) {
+ cli_out ("Path manipulation failed: %s",
+ strerror(errno));
+ gf_log ("cli", GF_LOG_ERROR, "Path manipulation "
+ "failed: %s", strerror(errno));
+ ret = -1;
+ goto out;
+ }
+ ret = 0;
+ }
+out:
+ if (tmppath)
+ GF_FREE(tmppath);
+ return ret;
+}
+
void
cli_path_strip_trailing_slashes (char *path)
{
diff --git a/cli/src/cli.h b/cli/src/cli.h
index 0b94d6e36c2..ae4ebe7d99a 100644
--- a/cli/src/cli.h
+++ b/cli/src/cli.h
@@ -237,6 +237,9 @@ cli_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event,
void
cli_path_strip_trailing_slashes (char *path);
+int
+cli_canonicalize_path (char *path);
+
int32_t
cli_cmd_volume_profile_parse (const char **words, int wordcount,
dict_t **options);