[PATCH]Extending user at host syntax
Torsten Foertsch
torsten.foertsch at gmx.net
Thu Sep 9 01:35:30 EST 2004
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
the following patch extends the user at host syntax on the ssh command line to
allow an additional HostKeyAlias and Port to be given as a single argument, eg:
ssh user at localhost%8022,www.tdl.com
is equivalent to
ssh -o 'HostKeyAlias www.tdl.com' -p 8022 user at localhost
The patch is particularly useful when ssh is called from other programs or
scripts and the ssh connection is to be established on top of a tunnel.
Consider for example a CVS repository that is connected using ssh through
a tunnel. The CVS/Root file contains the path to the CVS root as:
user at www.tld.com:/path/to/cvs
There is no way to specify a port number or a HostKeyAlias. With the patch
the CVS/Root can contain:
user at localhost%8022,www.tld.com:/path/to/cvs
and the connection is made through the tunnel.
I know I can achieve a similar result using .ssh/config:
Host host_nickname
Hostname localhost
Port 8022
HostKeyAlias www.tld.com
and specify the CVS root as user at host_nickname:/path/to/cvs
However, I think my patch is rather a feature than a bug. Are there any
chances to get it included in openssh?
Torsten
diff -Naur openssh-3.9p1/ssh.c openssh-3.9p1.new/ssh.c
- --- openssh-3.9p1/ssh.c 2004-08-15 09:23:34.000000000 +0200
+++ openssh-3.9p1.new/ssh.c 2004-09-08 16:12:58.000000000 +0200
@@ -157,7 +157,8 @@
"usage: ssh [-1246AaCfghkMNnqsTtVvXxY] [-b bind_address] [-c cipher_spec]\n"
" [-D port] [-e escape_char] [-F configfile] [-i identity_file]\n"
" [-L port:host:hostport] [-l login_name] [-m mac_spec] [-o option]\n"
- -" [-p port] [-R port:host:hostport] [-S ctl] [user@]hostname [command]\n"
+" [-p port] [-R port:host:hostport] [-S ctl]\n"
+" [user@]hostname[%%port][,host_key_alias] [command]\n"
);
exit(1);
}
@@ -176,7 +177,7 @@
int i, opt, exit_status;
u_short fwd_port, fwd_host_port;
char sfwd_port[6], sfwd_host_port[6];
- - char *p, *cp, *line, buf[256];
+ char *p, *cp, *line, buf[256], *host_key_aliasp;
struct stat st;
struct passwd *pw;
int dummy;
@@ -474,6 +475,28 @@
host = ++cp;
} else
host = *av;
+
+ host_key_aliasp = 0;
+ if (strrchr(host, '%')) {
+ cp = strrchr(host, '%');
+ *cp++ = '\0';
+ if (strrchr(cp, ',')) {
+ host_key_aliasp = strrchr(cp, ',');
+ *host_key_aliasp++ = '\0';
+ }
+ options.port = a2port(cp);
+ if (options.port == 0) {
+ fprintf(stderr, "Bad port '%s'\n", cp);
+ exit(1);
+ }
+ } else if (strrchr(host, ',')) {
+ host_key_aliasp = strrchr(host, ',');
+ *host_key_aliasp++ = '\0';
+ }
+
+ if (host_key_aliasp)
+ options.host_key_alias = xstrdup(host_key_aliasp);
+
if (ac > 1) {
optind = optreset = 1;
goto again;
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFBPybHwicyCTir8T4RAjo+AKCS/aowItuYao9OVIWtOx1KrEKdpgCfX7ev
DpGUBfblAUpXfJSWsgSdwo0=
=nnlY
-----END PGP SIGNATURE-----
More information about the openssh-unix-dev
mailing list