[PATCH] fix %n expansion in LocalCommand
Bert Wesarg
bert.wesarg at googlemail.com
Thu Jan 6 08:22:44 EST 2011
After the commit titled "expand %h to the hostname in ssh_config Hostname
options" (2010-07-16), %n always got the same value as %h in the LocalCommand
config option. Fix this and add a regression test.
---
regress/Makefile | 6 ++++--
regress/host-expand.sh | 18 ++++++++++++++++++
ssh.c | 6 ++++--
3 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/regress/Makefile b/regress/Makefile
index 9ebb250..20c40a0 100644
--- a/regress/Makefile
+++ b/regress/Makefile
@@ -56,7 +56,8 @@ LTESTS= connect \
keytype \
kextype \
cert-hostkey \
- cert-userkey
+ cert-userkey \
+ host-expand
INTEROP_TESTS= putty-transfer putty-ciphers putty-kex conch-ciphers
#INTEROP_TESTS+=ssh-com ssh-com-client ssh-com-keygen ssh-com-sftp
@@ -75,7 +76,8 @@ CLEANFILES= t2.out t6.out1 t6.out2 t7.out t7.out.pub copy.1 copy.2 \
sshd_proxy_bak rsa_ssh2_cr.prv rsa_ssh2_crnl.prv \
known_hosts-cert host_ca_key* cert_host_key* \
putty.rsa2 sshd_proxy_orig \
- authorized_principals_${USER}
+ authorized_principals_${USER} \
+ expect actual
# Enable all malloc(3) randomisations and checks
TEST_ENV= "MALLOC_OPTIONS=AFGJPRX"
diff --git a/regress/host-expand.sh b/regress/host-expand.sh
new file mode 100644
index 0000000..cd4e03c
--- /dev/null
+++ b/regress/host-expand.sh
@@ -0,0 +1,18 @@
+# Placed in the Public Domain.
+
+tid="expand %h and %n"
+
+echo 'PermitLocalCommand yes' >> $OBJ/ssh_proxy
+printf 'LocalCommand printf "%%%%s\\n" "%%n" "%%h"\n' >> $OBJ/ssh_proxy
+
+cat >expect <<EOE
+somehost
+127.0.0.1
+EOE
+
+for p in 1 2; do
+ verbose "test $tid: proto $p"
+ ${SSH} -F $OBJ/ssh_proxy -$p somehost true >actual
+ diff -u expect actual || fail "$tid proto $p"
+done
+
diff --git a/ssh.c b/ssh.c
index ec690ae..a11e0ae 100644
--- a/ssh.c
+++ b/ssh.c
@@ -221,7 +221,7 @@ int
main(int ac, char **av)
{
int i, r, opt, exit_status, use_syslog;
- char *p, *cp, *line, *argv0, buf[MAXPATHLEN];
+ char *p, *cp, *line, *argv0, buf[MAXPATHLEN], *host_arg;
struct stat st;
struct passwd *pw;
int dummy, timeout_ms;
@@ -693,6 +693,8 @@ main(int ac, char **av)
options.port = sp ? ntohs(sp->s_port) : SSH_DEFAULT_PORT;
}
+ /* preserve host name given on command line for %n expansion */
+ host_arg = host;
if (options.hostname != NULL) {
host = percent_expand(options.hostname,
"h", host, (char *)NULL);
@@ -707,7 +709,7 @@ main(int ac, char **av)
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, "r", options.user,
+ "h", host, "l", thishost, "n", host_arg, "r", options.user,
"p", buf, "u", pw->pw_name, (char *)NULL);
debug3("expanded LocalCommand: %s", options.local_command);
xfree(cp);
--
tg: (6457603..) bw/fix-percent-n (depends on: master)
More information about the openssh-unix-dev
mailing list