summaryrefslogtreecommitdiff
path: root/ssh.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 /ssh.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 'ssh.c')
-rw-r--r--ssh.c56
1 files changed, 41 insertions, 15 deletions
diff --git a/ssh.c b/ssh.c
index ae37432b..213c35e7 100644
--- a/ssh.c
+++ b/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
@@ -203,7 +203,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);
}
@@ -846,14 +846,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':
@@ -933,16 +937,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;