diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2017-12-18 17:28:55 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2017-12-18 17:28:55 +0000 |
commit | 288b041d5110c83ec4a2e521afad6aedb14e5f0e (patch) | |
tree | 682ad78572f295413e2968bec8461ec1a335607c /usr.bin/ssh/scp.c | |
parent | bc40d27401a689fa4455b53bd2e7d1d8b94340cf (diff) |
Add helper function for uri handing in scp where a missing path
simply means ".". Also fix exit code and add warnings when an
invalid uri is encountered. OK otto@
Diffstat (limited to 'usr.bin/ssh/scp.c')
-rw-r--r-- | usr.bin/ssh/scp.c | 47 |
1 files changed, 36 insertions, 11 deletions
diff --git a/usr.bin/ssh/scp.c b/usr.bin/ssh/scp.c index e8b62cab982..5bc49723022 100644 --- a/usr.bin/ssh/scp.c +++ b/usr.bin/ssh/scp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scp.c,v 1.193 2017/10/21 23:06:24 millert Exp $ */ +/* $OpenBSD: scp.c,v 1.194 2017/12/18 17:28:54 millert Exp $ */ /* * scp - secure remote copy. This is basically patched BSD rcp which * uses ssh to do the data transfer (instead of using rcmd). @@ -583,6 +583,18 @@ do_times(int fd, int verb, const struct stat *sb) return (response()); } +static int +parse_scp_uri(const char *uri, char **userp, char **hostp, int *portp, + char **pathp) +{ + int r; + + r = parse_uri("scp", uri, userp, hostp, portp, pathp); + if (r == 0 && *pathp == NULL) + *pathp = xstrdup("."); + return r; +} + void toremote(int argc, char **argv) { @@ -597,27 +609,39 @@ toremote(int argc, char **argv) alist.list = NULL; /* Parse target */ - r = parse_uri("scp", argv[argc - 1], &tuser, &thost, &tport, &targ); - if (r == -1) - goto out; /* invalid URI */ + r = parse_scp_uri(argv[argc - 1], &tuser, &thost, &tport, &targ); + if (r == -1) { + fmprintf(stderr, "%s: invalid uri\n", argv[argc - 1]); + ++errs; + goto out; + } if (r != 0) { if (parse_user_host_path(argv[argc - 1], &tuser, &thost, - &targ) == -1) + &targ) == -1) { + fmprintf(stderr, "%s: invalid target\n", argv[argc - 1]); + ++errs; goto out; + } } - if (tuser != NULL && !okname(tuser)) + if (tuser != NULL && !okname(tuser)) { + ++errs; goto out; + } /* Parse source files */ for (i = 0; i < argc - 1; i++) { free(suser); free(host); free(src); - r = parse_uri("scp", argv[i], &suser, &host, &sport, &src); - if (r == -1) - continue; /* invalid URI */ - if (r != 0) + r = parse_scp_uri(argv[i], &suser, &host, &sport, &src); + if (r == -1) { + fmprintf(stderr, "%s: invalid uri\n", argv[i]); + ++errs; + continue; + } + if (r != 0) { parse_user_host_path(argv[i], &suser, &host, &src); + } if (suser != NULL && !okname(suser)) { ++errs; continue; @@ -707,8 +731,9 @@ tolocal(int argc, char **argv) free(suser); free(host); free(src); - r = parse_uri("scp", argv[i], &suser, &host, &sport, &src); + r = parse_scp_uri(argv[i], &suser, &host, &sport, &src); if (r == -1) { + fmprintf(stderr, "%s: invalid uri\n", argv[i]); ++errs; continue; } |