diff options
-rw-r--r-- | usr.bin/ssh/ssh.c | 28 | ||||
-rw-r--r-- | usr.bin/ssh/ssh_config.5 | 17 |
2 files changed, 26 insertions, 19 deletions
diff --git a/usr.bin/ssh/ssh.c b/usr.bin/ssh/ssh.c index dd3b6b426c6..b3efce3026c 100644 --- a/usr.bin/ssh/ssh.c +++ b/usr.bin/ssh/ssh.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ssh.c,v 1.357 2011/04/17 22:42:42 djm Exp $ */ +/* $OpenBSD: ssh.c,v 1.358 2011/05/06 21:18:02 djm Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland @@ -214,6 +214,7 @@ main(int ac, char **av) { int i, r, opt, exit_status, use_syslog; char *p, *cp, *line, *argv0, buf[MAXPATHLEN], *host_arg; + char thishost[NI_MAXHOST], shorthost[NI_MAXHOST], portstr[NI_MAXSERV]; struct stat st; struct passwd *pw; int dummy, timeout_ms; @@ -687,17 +688,19 @@ main(int ac, char **av) "h", host, (char *)NULL); } - if (options.local_command != NULL) { - char thishost[NI_MAXHOST]; + if (gethostname(thishost, sizeof(thishost)) == -1) + fatal("gethostname: %s", strerror(errno)); + strlcpy(shorthost, thishost, sizeof(shorthost)); + shorthost[strcspn(thishost, ".")] = '\0'; + snprintf(portstr, sizeof(portstr), "%d", options.port); - if (gethostname(thishost, sizeof(thishost)) == -1) - fatal("gethostname: %s", strerror(errno)); - snprintf(buf, sizeof(buf), "%d", options.port); + if (options.local_command != NULL) { debug3("expanding LocalCommand: %s", options.local_command); cp = options.local_command; options.local_command = percent_expand(cp, "d", pw->pw_dir, "h", host, "l", thishost, "n", host_arg, "r", options.user, - "p", buf, "u", pw->pw_name, (char *)NULL); + "p", portstr, "u", pw->pw_name, "L", shorthost, + (char *)NULL); debug3("expanded LocalCommand: %s", options.local_command); xfree(cp); } @@ -721,16 +724,13 @@ main(int ac, char **av) } if (options.control_path != NULL) { - char thishost[NI_MAXHOST]; - - if (gethostname(thishost, sizeof(thishost)) == -1) - fatal("gethostname: %s", strerror(errno)); - snprintf(buf, sizeof(buf), "%d", options.port); cp = tilde_expand_filename(options.control_path, original_real_uid); xfree(options.control_path); - options.control_path = percent_expand(cp, "p", buf, "h", host, - "r", options.user, "l", thishost, (char *)NULL); + options.control_path = percent_expand(cp, "h", host, + "l", thishost, "n", host_arg, "r", options.user, + "p", portstr, "u", pw->pw_name, "L", shorthost, + (char *)NULL); xfree(cp); } if (muxclient_command != 0 && options.control_path == NULL) diff --git a/usr.bin/ssh/ssh_config.5 b/usr.bin/ssh/ssh_config.5 index 50bcae82f66..a5bad8cc791 100644 --- a/usr.bin/ssh/ssh_config.5 +++ b/usr.bin/ssh/ssh_config.5 @@ -33,8 +33,8 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.\" $OpenBSD: ssh_config.5,v 1.146 2010/12/08 04:02:47 djm Exp $ -.Dd $Mdocdate: December 8 2010 $ +.\" $OpenBSD: ssh_config.5,v 1.147 2011/05/06 21:18:02 djm Exp $ +.Dd $Mdocdate: May 6 2011 $ .Dt SSH_CONFIG 5 .Os .Sh NAME @@ -305,14 +305,21 @@ section above or the string .Dq none to disable connection sharing. In the path, +.Ql %L +will be substituted by the first component of the local host name, .Ql %l -will be substituted by the local host name, +will be substituted by the local host name (including any domain name), .Ql %h will be substituted by the target host name, +.Ql %h +will be substituted by original target host name specified on the commandline, .Ql %p -the port, and +the port, .Ql %r -by the remote login username. +by the remote login username, and +.Ql %u +by the username of the user running +.Xr ssh 1 . It is recommended that any .Cm ControlPath used for opportunistic connection sharing include |