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 /ssh.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 'ssh.c')
-rw-r--r-- | ssh.c | 56 |
1 files changed, 41 insertions, 15 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssh.c,v 1.464 2017/09/21 19:16:53 markus Exp $ */ | 1 | /* $OpenBSD: ssh.c,v 1.465 2017/10/21 23:06:24 millert Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -203,7 +203,7 @@ usage(void) | |||
203 | " [-J [user@]host[:port]] [-L address] [-l login_name] [-m mac_spec]\n" | 203 | " [-J [user@]host[:port]] [-L address] [-l login_name] [-m mac_spec]\n" |
204 | " [-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address]\n" | 204 | " [-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address]\n" |
205 | " [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]]\n" | 205 | " [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]]\n" |
206 | " [user@]hostname [command]\n" | 206 | " destination [command]\n" |
207 | ); | 207 | ); |
208 | exit(255); | 208 | exit(255); |
209 | } | 209 | } |
@@ -846,14 +846,18 @@ main(int ac, char **av) | |||
846 | options.control_master = SSHCTL_MASTER_YES; | 846 | options.control_master = SSHCTL_MASTER_YES; |
847 | break; | 847 | break; |
848 | case 'p': | 848 | case 'p': |
849 | options.port = a2port(optarg); | 849 | if (options.port == -1) { |
850 | if (options.port <= 0) { | 850 | options.port = a2port(optarg); |
851 | fprintf(stderr, "Bad port '%s'\n", optarg); | 851 | if (options.port <= 0) { |
852 | exit(255); | 852 | fprintf(stderr, "Bad port '%s'\n", |
853 | optarg); | ||
854 | exit(255); | ||
855 | } | ||
853 | } | 856 | } |
854 | break; | 857 | break; |
855 | case 'l': | 858 | case 'l': |
856 | options.user = optarg; | 859 | if (options.user == NULL) |
860 | options.user = optarg; | ||
857 | break; | 861 | break; |
858 | 862 | ||
859 | case 'L': | 863 | case 'L': |
@@ -933,16 +937,38 @@ main(int ac, char **av) | |||
933 | av += optind; | 937 | av += optind; |
934 | 938 | ||
935 | if (ac > 0 && !host) { | 939 | if (ac > 0 && !host) { |
936 | if (strrchr(*av, '@')) { | 940 | int tport; |
941 | char *tuser; | ||
942 | switch (parse_ssh_uri(*av, &tuser, &host, &tport)) { | ||
943 | case -1: | ||
944 | usage(); | ||
945 | break; | ||
946 | case 0: | ||
947 | if (options.user == NULL) { | ||
948 | options.user = tuser; | ||
949 | tuser = NULL; | ||
950 | } | ||
951 | free(tuser); | ||
952 | if (options.port == -1 && tport != -1) | ||
953 | options.port = tport; | ||
954 | break; | ||
955 | default: | ||
937 | p = xstrdup(*av); | 956 | p = xstrdup(*av); |
938 | cp = strrchr(p, '@'); | 957 | cp = strrchr(p, '@'); |
939 | if (cp == NULL || cp == p) | 958 | if (cp != NULL) { |
940 | usage(); | 959 | if (cp == p) |
941 | options.user = p; | 960 | usage(); |
942 | *cp = '\0'; | 961 | if (options.user == NULL) { |
943 | host = xstrdup(++cp); | 962 | options.user = p; |
944 | } else | 963 | p = NULL; |
945 | host = xstrdup(*av); | 964 | } |
965 | *cp++ = '\0'; | ||
966 | host = xstrdup(cp); | ||
967 | free(p); | ||
968 | } else | ||
969 | host = p; | ||
970 | break; | ||
971 | } | ||
946 | if (ac > 1 && !opt_terminated) { | 972 | if (ac > 1 && !opt_terminated) { |
947 | optind = optreset = 1; | 973 | optind = optreset = 1; |
948 | goto again; | 974 | goto again; |