Bug 541423 - tab completion of hosts in known_hosts files produce errors
Summary: tab completion of hosts in known_hosts files produce errors
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Fedora
Classification: Fedora
Component: bash-completion
Version: 12
Hardware: All
OS: Linux
low
medium
Target Milestone: ---
Assignee: Ville Skyttä
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2009-11-25 21:15 UTC by S.A. Hartsuiker
Modified: 2010-10-25 16:34 UTC (History)
2 users (show)

Fixed In Version: 1.2-1
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2010-07-01 19:35:28 UTC


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

Description S.A. Hartsuiker 2009-11-25 21:15:24 UTC
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 21:39:11 UTC
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 22:25:02 UTC
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 20:11:45 UTC
(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 20:32:40 UTC
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 23:01:53 UTC
:)
Works for me.
Thanks a lot :)

Comment 7 Fedora Update System 2010-06-20 10:56:59 UTC
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 18:59:54 UTC
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 17:27:48 UTC
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 16:34:20 UTC
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.