diff options
author | millert@openbsd.org <millert@openbsd.org> | 2017-10-21 23:06:24 +0000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2017-10-23 16:10:08 +1100 |
commit | 887669ef032d63cf07f53cada216fa8a0c9a7d72 (patch) | |
tree | 089b20255da21a489d7bc796a8ee86bd0b8f028f /sftp.c | |
parent | d27bff293cfeb2252f4c7a58babe5ad3262c6c98 (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.c | 58 |
1 files changed, 31 insertions, 27 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sftp.c,v 1.180 2017/06/10 06:33:34 djm Exp $ */ | 1 | /* $OpenBSD: sftp.c,v 1.181 2017/10/21 23:06:24 millert Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> | 3 | * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> |
4 | * | 4 | * |
@@ -2301,19 +2301,16 @@ usage(void) | |||
2301 | "[-i identity_file] [-l limit]\n" | 2301 | "[-i identity_file] [-l limit]\n" |
2302 | " [-o ssh_option] [-P port] [-R num_requests] " | 2302 | " [-o ssh_option] [-P port] [-R num_requests] " |
2303 | "[-S program]\n" | 2303 | "[-S program]\n" |
2304 | " [-s subsystem | sftp_server] host\n" | 2304 | " [-s subsystem | sftp_server] destination\n", |
2305 | " %s [user@]host[:file ...]\n" | 2305 | __progname); |
2306 | " %s [user@]host[:dir[/]]\n" | ||
2307 | " %s -b batchfile [user@]host\n", | ||
2308 | __progname, __progname, __progname, __progname); | ||
2309 | exit(1); | 2306 | exit(1); |
2310 | } | 2307 | } |
2311 | 2308 | ||
2312 | int | 2309 | int |
2313 | main(int argc, char **argv) | 2310 | main(int argc, char **argv) |
2314 | { | 2311 | { |
2315 | int in, out, ch, err; | 2312 | int in, out, ch, err, tmp, port = -1; |
2316 | char *host = NULL, *userhost, *cp, *file2 = NULL; | 2313 | char *host = NULL, *user, *cp, *file2 = NULL; |
2317 | int debug_level = 0, sshver = 2; | 2314 | int debug_level = 0, sshver = 2; |
2318 | char *file1 = NULL, *sftp_server = NULL; | 2315 | char *file1 = NULL, *sftp_server = NULL; |
2319 | char *ssh_program = _PATH_SSH_PROGRAM, *sftp_direct = NULL; | 2316 | char *ssh_program = _PATH_SSH_PROGRAM, *sftp_direct = NULL; |
@@ -2368,7 +2365,9 @@ main(int argc, char **argv) | |||
2368 | addargs(&args, "-%c", ch); | 2365 | addargs(&args, "-%c", ch); |
2369 | break; | 2366 | break; |
2370 | case 'P': | 2367 | case 'P': |
2371 | addargs(&args, "-oPort %s", optarg); | 2368 | port = a2port(optarg); |
2369 | if (port <= 0) | ||
2370 | fatal("Bad port \"%s\"\n", optarg); | ||
2372 | break; | 2371 | break; |
2373 | case 'v': | 2372 | case 'v': |
2374 | if (debug_level < 3) { | 2373 | if (debug_level < 3) { |
@@ -2451,33 +2450,38 @@ main(int argc, char **argv) | |||
2451 | if (sftp_direct == NULL) { | 2450 | if (sftp_direct == NULL) { |
2452 | if (optind == argc || argc > (optind + 2)) | 2451 | if (optind == argc || argc > (optind + 2)) |
2453 | usage(); | 2452 | usage(); |
2453 | argv += optind; | ||
2454 | 2454 | ||
2455 | userhost = xstrdup(argv[optind]); | 2455 | switch (parse_uri("sftp", *argv, &user, &host, &tmp, &file1)) { |
2456 | file2 = argv[optind+1]; | 2456 | case -1: |
2457 | 2457 | usage(); | |
2458 | if ((host = strrchr(userhost, '@')) == NULL) | 2458 | break; |
2459 | host = userhost; | 2459 | case 0: |
2460 | else { | 2460 | if (tmp != -1) |
2461 | *host++ = '\0'; | 2461 | port = tmp; |
2462 | if (!userhost[0]) { | 2462 | break; |
2463 | fprintf(stderr, "Missing username\n"); | 2463 | default: |
2464 | usage(); | 2464 | if (parse_user_host_path(*argv, &user, &host, |
2465 | &file1) == -1) { | ||
2466 | /* Treat as a plain hostname. */ | ||
2467 | host = xstrdup(*argv); | ||
2468 | host = cleanhostname(host); | ||
2465 | } | 2469 | } |
2466 | addargs(&args, "-l"); | 2470 | break; |
2467 | addargs(&args, "%s", userhost); | ||
2468 | } | ||
2469 | |||
2470 | if ((cp = colon(host)) != NULL) { | ||
2471 | *cp++ = '\0'; | ||
2472 | file1 = cp; | ||
2473 | } | 2471 | } |
2472 | file2 = *(argv + 1); | ||
2474 | 2473 | ||
2475 | host = cleanhostname(host); | ||
2476 | if (!*host) { | 2474 | if (!*host) { |
2477 | fprintf(stderr, "Missing hostname\n"); | 2475 | fprintf(stderr, "Missing hostname\n"); |
2478 | usage(); | 2476 | usage(); |
2479 | } | 2477 | } |
2480 | 2478 | ||
2479 | if (port != -1) | ||
2480 | addargs(&args, "-oPort %d", port); | ||
2481 | if (user != NULL) { | ||
2482 | addargs(&args, "-l"); | ||
2483 | addargs(&args, "%s", user); | ||
2484 | } | ||
2481 | addargs(&args, "-oProtocol %d", sshver); | 2485 | addargs(&args, "-oProtocol %d", sshver); |
2482 | 2486 | ||
2483 | /* no subsystem if the server-spec contains a '/' */ | 2487 | /* no subsystem if the server-spec contains a '/' */ |