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):
add entries to a personal ssh config like the following:
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
$ 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
$ ssh artreides
I have written a little patch that, at least for me, fixes having multiple userknownhostsfile entries.
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
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
(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.
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.
Ok, issues with ~ and weeding out those duplicates are now done upstream. If you wish to test, the patches fixing things found here should apply to 1.1-3 with some line offsets.
Works for me.
Thanks a lot :)
bash-completion-1.2-1.fc13 has been submitted as an update for Fedora 13.
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.
bash-completion-1.2-3.el5 has been submitted as an update for Fedora EPEL 5.
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.