summaryrefslogtreecommitdiffstats
path: root/usr.bin/ssh/ssh.c
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2017-10-21 23:06:24 +0000
committermillert <millert@openbsd.org>2017-10-21 23:06:24 +0000
commit42c96bd6479cfb243e38d8975a1a29f22e637931 (patch)
tree0917436f022281c4ff750042cd314f90832d3906 /usr.bin/ssh/ssh.c
parentEven though letting the firmware handle the handshake is nice from (diff)
downloadwireguard-openbsd-42c96bd6479cfb243e38d8975a1a29f22e637931.tar.xz
wireguard-openbsd-42c96bd6479cfb243e38d8975a1a29f22e637931.zip
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@
Diffstat (limited to 'usr.bin/ssh/ssh.c')
-rw-r--r--usr.bin/ssh/ssh.c56
1 files changed, 41 insertions, 15 deletions
diff --git a/usr.bin/ssh/ssh.c b/usr.bin/ssh/ssh.c
index d4c25ea5088..b411635279e 100644
--- a/usr.bin/ssh/ssh.c
+++ b/usr.bin/ssh/ssh.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh.c,v 1.464 2017/09/21 19:16:53 markus Exp $ */
+/* $OpenBSD: ssh.c,v 1.465 2017/10/21 23:06:24 millert Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -187,7 +187,7 @@ usage(void)
" [-J [user@]host[:port]] [-L address] [-l login_name] [-m mac_spec]\n"
" [-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address]\n"
" [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]]\n"
-" [user@]hostname [command]\n"
+" destination [command]\n"
);
exit(255);
}
@@ -815,14 +815,18 @@ main(int ac, char **av)
options.control_master = SSHCTL_MASTER_YES;
break;
case 'p':
- options.port = a2port(optarg);
- if (options.port <= 0) {
- fprintf(stderr, "Bad port '%s'\n", optarg);
- exit(255);
+ if (options.port == -1) {
+ options.port = a2port(optarg);
+ if (options.port <= 0) {
+ fprintf(stderr, "Bad port '%s'\n",
+ optarg);
+ exit(255);
+ }
}
break;
case 'l':
- options.user = optarg;
+ if (options.user == NULL)
+ options.user = optarg;
break;
case 'L':
@@ -902,16 +906,38 @@ main(int ac, char **av)
av += optind;
if (ac > 0 && !host) {
- if (strrchr(*av, '@')) {
+ int tport;
+ char *tuser;
+ switch (parse_ssh_uri(*av, &tuser, &host, &tport)) {
+ case -1:
+ usage();
+ break;
+ case 0:
+ if (options.user == NULL) {
+ options.user = tuser;
+ tuser = NULL;
+ }
+ free(tuser);
+ if (options.port == -1 && tport != -1)
+ options.port = tport;
+ break;
+ default:
p = xstrdup(*av);
cp = strrchr(p, '@');
- if (cp == NULL || cp == p)
- usage();
- options.user = p;
- *cp = '\0';
- host = xstrdup(++cp);
- } else
- host = xstrdup(*av);
+ if (cp != NULL) {
+ if (cp == p)
+ usage();
+ if (options.user == NULL) {
+ options.user = p;
+ p = NULL;
+ }
+ *cp++ = '\0';
+ host = xstrdup(cp);
+ free(p);
+ } else
+ host = p;
+ break;
+ }
if (ac > 1 && !opt_terminated) {
optind = optreset = 1;
goto again;