summaryrefslogtreecommitdiff
path: root/sftp.c
diff options
context:
space:
mode:
authormillert@openbsd.org <millert@openbsd.org>2017-10-21 23:06:24 +0000
committerDamien Miller <djm@mindrot.org>2017-10-23 16:10:08 +1100
commit887669ef032d63cf07f53cada216fa8a0c9a7d72 (patch)
tree089b20255da21a489d7bc796a8ee86bd0b8f028f /sftp.c
parentd27bff293cfeb2252f4c7a58babe5ad3262c6c98 (diff)
upstream commit
Add URI support to ssh, sftp and scp. For example ssh://user@host or sftp://user@host/path. The connection parameters described in draft-ietf-secsh-scp-sftp-ssh-uri-04 are not implemented since the ssh fingerprint format in the draft uses md5 with no way to specify the hash function type. OK djm@ Upstream-ID: 4ba3768b662d6722de59e6ecb00abf2d4bf9cacc
Diffstat (limited to 'sftp.c')
-rw-r--r--sftp.c58
1 files changed, 31 insertions, 27 deletions
diff --git a/sftp.c b/sftp.c
index 67110f73..9aee2faf 100644
--- a/sftp.c
+++ b/sftp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp.c,v 1.180 2017/06/10 06:33:34 djm Exp $ */
+/* $OpenBSD: sftp.c,v 1.181 2017/10/21 23:06:24 millert Exp $ */
/*
* Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
*
@@ -2301,19 +2301,16 @@ usage(void)
"[-i identity_file] [-l limit]\n"
" [-o ssh_option] [-P port] [-R num_requests] "
"[-S program]\n"
- " [-s subsystem | sftp_server] host\n"
- " %s [user@]host[:file ...]\n"
- " %s [user@]host[:dir[/]]\n"
- " %s -b batchfile [user@]host\n",
- __progname, __progname, __progname, __progname);
+ " [-s subsystem | sftp_server] destination\n",
+ __progname);
exit(1);
}
int
main(int argc, char **argv)
{
- int in, out, ch, err;
- char *host = NULL, *userhost, *cp, *file2 = NULL;
+ int in, out, ch, err, tmp, port = -1;
+ char *host = NULL, *user, *cp, *file2 = NULL;
int debug_level = 0, sshver = 2;
char *file1 = NULL, *sftp_server = NULL;
char *ssh_program = _PATH_SSH_PROGRAM, *sftp_direct = NULL;
@@ -2368,7 +2365,9 @@ main(int argc, char **argv)
addargs(&args, "-%c", ch);
break;
case 'P':
- addargs(&args, "-oPort %s", optarg);
+ port = a2port(optarg);
+ if (port <= 0)
+ fatal("Bad port \"%s\"\n", optarg);
break;
case 'v':
if (debug_level < 3) {
@@ -2451,33 +2450,38 @@ main(int argc, char **argv)
if (sftp_direct == NULL) {
if (optind == argc || argc > (optind + 2))
usage();
+ argv += optind;
- userhost = xstrdup(argv[optind]);
- file2 = argv[optind+1];
-
- if ((host = strrchr(userhost, '@')) == NULL)
- host = userhost;
- else {
- *host++ = '\0';
- if (!userhost[0]) {
- fprintf(stderr, "Missing username\n");
- usage();
+ switch (parse_uri("sftp", *argv, &user, &host, &tmp, &file1)) {
+ case -1:
+ usage();
+ break;
+ case 0:
+ if (tmp != -1)
+ port = tmp;
+ break;
+ default:
+ if (parse_user_host_path(*argv, &user, &host,
+ &file1) == -1) {
+ /* Treat as a plain hostname. */
+ host = xstrdup(*argv);
+ host = cleanhostname(host);
}
- addargs(&args, "-l");
- addargs(&args, "%s", userhost);
- }
-
- if ((cp = colon(host)) != NULL) {
- *cp++ = '\0';
- file1 = cp;
+ break;
}
+ file2 = *(argv + 1);
- host = cleanhostname(host);
if (!*host) {
fprintf(stderr, "Missing hostname\n");
usage();
}
+ if (port != -1)
+ addargs(&args, "-oPort %d", port);
+ if (user != NULL) {
+ addargs(&args, "-l");
+ addargs(&args, "%s", user);
+ }
addargs(&args, "-oProtocol %d", sshver);
/* no subsystem if the server-spec contains a '/' */