Bug#570951: zsh: ssh completes to non-resolvable hostname from .ssh/known_hosts

2010-02-28 Thread Clint Adams
On Mon, Feb 22, 2010 at 02:09:15PM +0100, Vincent Lefevre wrote:
 When I do ssh pru[TAB], ssh completes to a non-resolvable hostname
 from the .ssh/known_hosts file: prunille.vinc17.org
 
 In fact this machine is resolvable only from my local network, and
 it is an error to assume that a host key in .ssh/known_hosts is
 necessarily resolvable (it may be there just to check the key thanks
 to a HostKeyAlias declaration). IMHO, if the key is listed as an alias
 from .ssh/config but not as a Host identifier, it should be discarded.
 Hosts from .ssh/config should be used instead. The algorithm would be:
 
 1. Take all host identifiers after Host declarations from .ssh/config
(strings with '?' and/or '*' should not be taken into account).
 2. Add all hosts from .ssh/known_hosts that are not an argument of
a HostKeyAlias declaration (if hosts are in fact hashes, due to
HashKnownHosts, they should not be taken into account).
 
 For instance, if .ssh/config has:
 
 Host myhost
   HostKeyAlias my-real-host-name.mydomain
   Hostname gateway.mydomain
   Port 12345
 
 then ssh my[TAB] should complete to myhost only.
 
 Of course, as a workaround to the current behavior, the user could
 write:
 
 Host myhost my-real-host-name.mydomain
   HostKeyAlias my-real-host-name.mydomain
   Hostname gateway.mydomain
   Port 12345
 
 but this can make maintenance of the config file less easy.

One other potentially-complicated issue is the known_hosts file
gaining syntax in the form of

[localhost]:,[127.0.0.1]: ssh-rsa keyfingerprintblahblah id

resulting in tab completion of \[localhost\]: as a host.

I'm sure there is a better solution, but dropping entries with brackets
seems like an improvement over the status quo.

Index: Completion/Unix/Type/_hosts
===
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_hosts,v
retrieving revision 1.10
diff -u -r1.10 _hosts
--- Completion/Unix/Type/_hosts 5 Apr 2006 10:04:32 -   1.10
+++ Completion/Unix/Type/_hosts 28 Feb 2010 21:35:11 -
@@ -41,9 +41,9 @@
 
 for khostfile in $khostfiles; do
   if [[ -r $khostfile ]]; then
-khosts=(${(s:,:)${(j:,:)${(u)${(f)$($khostfile)}%%[ |#]*}}})
+khosts=(${${(s:,:)${(j:,:)${(u)${(f)$($khostfile)}%%[ 
|#]*}}}:#*[\[\]]*})
 if [[ -z $useip ]]; then
- 
khosts=(${${khosts:#(#s)[0-9]##.[0-9]##.[0-9]##.[0-9]##(#e)}:#(#s)[0-9a-f:]##(#e)})
+ 
khosts=(${${${khosts:#(#s)[0-9]##.[0-9]##.[0-9]##.[0-9]##(#e)}:#(#s)[0-9a-f:]##(#e)}:#*[\[\]]*})
 fi
 _cache_hosts+=($khosts)
   fi



-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Bug#570951: zsh: ssh completes to non-resolvable hostname from .ssh/known_hosts

2010-02-22 Thread Vincent Lefevre
Package: zsh
Version: 4.3.10-11
Severity: normal

When I do ssh pru[TAB], ssh completes to a non-resolvable hostname
from the .ssh/known_hosts file: prunille.vinc17.org

In fact this machine is resolvable only from my local network, and
it is an error to assume that a host key in .ssh/known_hosts is
necessarily resolvable (it may be there just to check the key thanks
to a HostKeyAlias declaration). IMHO, if the key is listed as an alias
from .ssh/config but not as a Host identifier, it should be discarded.
Hosts from .ssh/config should be used instead. The algorithm would be:

1. Take all host identifiers after Host declarations from .ssh/config
   (strings with '?' and/or '*' should not be taken into account).
2. Add all hosts from .ssh/known_hosts that are not an argument of
   a HostKeyAlias declaration (if hosts are in fact hashes, due to
   HashKnownHosts, they should not be taken into account).

For instance, if .ssh/config has:

Host myhost
  HostKeyAlias my-real-host-name.mydomain
  Hostname gateway.mydomain
  Port 12345

then ssh my[TAB] should complete to myhost only.

Of course, as a workaround to the current behavior, the user could
write:

Host myhost my-real-host-name.mydomain
  HostKeyAlias my-real-host-name.mydomain
  Hostname gateway.mydomain
  Port 12345

but this can make maintenance of the config file less easy.

-- System Information:
Debian Release: squeeze/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'testing')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.30-2-amd64 (SMP w/8 CPU cores)
Locale: LANG=POSIX, LC_CTYPE=en_US.ISO8859-1 (charmap=ISO-8859-1)
Shell: /bin/sh linked to /bin/dash

Versions of packages zsh depends on:
ii  libc6 2.10.2-6   Embedded GNU C Library: Shared lib
ii  libcap2   1:2.17-2   support for getting/setting POSIX.
ii  libncursesw5  5.7+20090803-2 shared libraries for terminal hand

Versions of packages zsh recommends:
ii  libc6 2.10.2-6   Embedded GNU C Library: Shared lib
ii  libpcre3  7.8-3  Perl 5 Compatible Regular Expressi

Versions of packages zsh suggests:
ii  zsh-doc   4.3.10-11  zsh documentation - info/HTML form

-- no debconf information



-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org