Bug 541423 - tab completion of hosts in known_hosts files produce errors
tab completion of hosts in known_hosts files produce errors
Status: CLOSED CURRENTRELEASE
Product: Fedora
Classification: Fedora
Component: bash-completion (Show other bugs)
12
All Linux
low Severity medium
: ---
: ---
Assigned To: Ville Skyttä
Fedora Extras Quality Assurance
: Triaged
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2009-11-25 16:15 EST by S.A. Hartsuiker
Modified: 2010-10-25 12:34 EDT (History)
2 users (show)

See Also:
Fixed In Version: 1.2-1
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2010-07-01 15:35:28 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
patch to add support for multiple userknownhostsfile entries in ssh config files (1.13 KB, patch)
2009-11-25 16:15 EST, S.A. Hartsuiker
no flags Details | Diff

  None (edit)
Description S.A. Hartsuiker 2009-11-25 16:15:24 EST
Created attachment 373827 [details]
patch to add support for multiple userknownhostsfile entries in ssh config files

Description of problem:
When more than one userknownhostsfile is defined in the ~/.ssh/config file then bash_completion produces errors and completion doesn't work.
As a possible extra side effect is that at least the second userknownhostsfile is executed, if an executable bit is set, with the permission of the user.

Version-Release number of selected component (if applicable):
bash-completion-1.0-5.fc12.noarch

How reproducible:

add entries to a personal ssh config like the following:
host a
    userknownhostsfile a
host b
    userknownhostsfile b

then try tab-completion. As far as I can tell it is perfectly allowed to have multiple userknownhostsfile entries in your config. Whether or not it is usefull to do so is another discussion.

Steps to Reproduce:
1. add entries like above
2. try tab-completion on one of the hosts
3.
  
Actual results:
$ ssh ar/home/shartsuiker/.ssh/artreides/known_hosts: line 1: cvs.fedoraproject.org: command not found
/home/shartsuiker/.ssh/artreides/known_hosts: line 1: cvs.fedoraproject.org: command not found


Expected results:
$ ssh artreides

Additional info:

I have written a little patch that, at least for me, fixes having multiple userknownhostsfile entries.
Comment 1 Ville Skyttä 2009-11-25 16:39:11 EST
This should already be fixed in bash-completion-1.1-3.fc12 which is currently in updates-testing, could you try it out? https://admin.fedoraproject.org/updates/F12/FEDORA-2009-11854
Comment 2 S.A. Hartsuiker 2009-11-25 17:25:02 EST
nope, doesn't quite fix my issue. While the error is no longer generated, the behaviour is not what is expected.
Using my own example again, hosts mentioned only in userknownhostsfile b are not completed.
This is due to the fact that in the newer version, although on line 1215 of /etc/bash_completion $user_kh is assigned to as an array (and thus as such defined)
the test at line 1239 still treats it as a string variable causing the test to fail and thus not assigning all values of $user_kh[@] to $kh[@].

Even if that is fixed (I took a shortcut and disabled the test) the awk statement on 1273 still doesn't find the hosts in the second userknownhostsfile b
Comment 3 Ville Skyttä 2009-11-26 15:11:45 EST
(In reply to comment #2)

> the test at line 1239 still treats it as a string variable causing the test 
> to fail and thus not assigning all values of $user_kh[@] to $kh[@].

That's right, but only if the first entry in user_kh is not readable (using it as a simple string variable is the same as using the first value in it).

There are actually multiple issues at play here.  The biggest one is that *KnownHostsFile entries starting with ~ do not currently work because the tilde ends up being used as a literal tilde and not expanded to the user's home dir (I suppose we need to bring back the eval).  I'm guessing you have such entries in your ssh config file?

Anyway, current upstream git HEAD no longer fails to read rest of the user known hosts files if the first one is not readable for whatever reason.  (Ditto global known hosts ones.)

I'll try to get known hosts files starting with a ~ fixed as well.
Comment 4 S.A. Hartsuiker 2009-11-26 15:32:40 EST
yes, some of my userknownhostsfile entries start indeed with a ~.

As a side note, I also saw that duplicate userknownhostsfile entries are not reduced to just one, ie using a 'sort|uniq'. Although this doesn't affect the useablility, I can imagine large files could benefit from this.
Comment 6 S.A. Hartsuiker 2009-11-26 18:01:53 EST
:)
Works for me.
Thanks a lot :)
Comment 7 Fedora Update System 2010-06-20 06:56:59 EDT
bash-completion-1.2-1.fc13 has been submitted as an update for Fedora 13.
http://admin.fedoraproject.org/updates/bash-completion-1.2-1.fc13
Comment 8 Fedora Update System 2010-07-01 14:59:54 EDT
bash-completion-1.2-2.fc13 has been pushed to the Fedora 13 stable repository.  If problems still persist, please make note of it in this bug report.
Comment 9 Fedora Update System 2010-10-04 13:27:48 EDT
bash-completion-1.2-3.el5 has been submitted as an update for Fedora EPEL 5.
https://admin.fedoraproject.org/updates/bash-completion-1.2-3.el5
Comment 10 Fedora Update System 2010-10-25 12:34:20 EDT
bash-completion-1.2-4.el5 has been pushed to the Fedora EPEL 5 stable repository.  If problems still persist, please make note of it in this bug report.

Note You need to log in before you can comment on or make changes to this bug.