mirror of
https://github.com/upa/mscp.git
synced 2026-02-04 03:24:58 +08:00
expand remote paths including '~' (partially)
The current code does not adopt expand-path@openssh.com, thus expanding paths like `~user` is still not supported.
This commit is contained in:
32
src/main.c
32
src/main.c
@@ -205,7 +205,7 @@ struct target *validate_targets(char **arg, int len)
|
||||
*/
|
||||
|
||||
struct target *t, *t0;
|
||||
int n;
|
||||
int n, nslash;
|
||||
|
||||
if ((t = calloc(len, sizeof(struct target))) == NULL) {
|
||||
pr_err("calloc: %s", strerrno());
|
||||
@@ -223,9 +223,33 @@ struct target *validate_targets(char **arg, int len)
|
||||
}
|
||||
}
|
||||
|
||||
/* check all user@host are identical. t[len - 1] is destination,
|
||||
* so we need to check t[0] to t[len - 2] having the identical
|
||||
* remote notation */
|
||||
/* expand remote path, e.g., empty dst path and '~' */
|
||||
for (n = 0; n < len; n++) {
|
||||
if (!t[n].host)
|
||||
continue;
|
||||
|
||||
/* this target is a remote path. check the path and
|
||||
* expand it. this part is derived from
|
||||
* openssh-portal prepare_remote_path() function.
|
||||
*/
|
||||
char *path = t[n].path;
|
||||
if (*path == '\0' || strcmp(path, "~") == 0)
|
||||
t[n].path = strdup(".");
|
||||
else if (strncmp(path, "~/", 2) == 0) {
|
||||
if ((nslash = strspn(path + 2, "/")) == strlen(path + 2))
|
||||
t[n].path = strdup(".");
|
||||
else
|
||||
t[n].path = strdup(path + 2 + nslash);
|
||||
}
|
||||
if (!t[n].path) {
|
||||
pr_err("strdup failed: %s", strerrno());
|
||||
goto free_target_out;
|
||||
}
|
||||
}
|
||||
|
||||
/* check all user@host are identical. t[len - 1] is the
|
||||
* destination, so we need to check t[0] to t[len - 2] having
|
||||
* the identical remote notation */
|
||||
t0 = &t[0];
|
||||
for (n = 1; n < len - 1; n++) {
|
||||
if (compare_remote(t0, &t[n]) != 0)
|
||||
|
||||
10
src/mscp.c
10
src/mscp.c
@@ -329,10 +329,12 @@ int mscp_set_dst_path(struct mscp *m, const char *dst_path)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!non_null_string(dst_path))
|
||||
strncpy(m->dst_path, ".", 1);
|
||||
else
|
||||
strncpy(m->dst_path, dst_path, PATH_MAX);
|
||||
if (!non_null_string(dst_path)) {
|
||||
priv_set_errv("empty dst path");
|
||||
return -1;
|
||||
}
|
||||
|
||||
strncpy(m->dst_path, dst_path, PATH_MAX);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user