Fix reading rest of user/global known hosts files when the first one is not readable.

https://bugzilla.redhat.com/show_bug.cgi?id=541423#c2

As a side effect, this simplifies things somewhat and grabs user and
global known hosts filenames from config files with one command
instead of doing one for each.
This commit is contained in:
Ville Skyttä 2009-11-26 21:53:02 +02:00
parent a9717be57b
commit 6f921d563b
2 changed files with 8 additions and 15 deletions

View File

@ -24,7 +24,7 @@ bash-completion (2.x)
* Apply pine completion to alpine too. * Apply pine completion to alpine too.
* Remove many unnecessary short option completions where long ones exist. * Remove many unnecessary short option completions where long ones exist.
* Improve configure, cvs, gkrellm, lftp, mdadm, modprobe, mplayer, * Improve configure, cvs, gkrellm, lftp, mdadm, modprobe, mplayer,
mysqladmin, service, and ssh completions. mysqladmin, service, ssh, and general hostname completions.
* Add abook and wtf completion, based on work by Raphaël Droz. * Add abook and wtf completion, based on work by Raphaël Droz.
* Add k3b and lftpget completion. * Add k3b and lftpget completion.
* Don't overwrite other host completions when completing from multiple * Don't overwrite other host completions when completing from multiple

View File

@ -1223,7 +1223,7 @@ _known_hosts()
_known_hosts_real() _known_hosts_real()
{ {
local configfile flag prefix local configfile flag prefix
local cur curd awkcur user suffix aliases global_kh user_kh hosts i host local cur curd awkcur user suffix aliases hosts i host
local -a kh khd config local -a kh khd config
local OPTIND=1 local OPTIND=1
@ -1258,22 +1258,17 @@ _known_hosts_real()
if [ ${#config[@]} -gt 0 ]; then if [ ${#config[@]} -gt 0 ]; then
local OIFS=$IFS IFS=$'\n' local OIFS=$IFS IFS=$'\n'
# expand path (if present) to global known hosts file local -a tmpkh
global_kh=($( sed -ne 's/^[ \t]*[Gg][Ll][Oo][Bb][Aa][Ll][Kk][Nn][Oo][Ww][Nn][Hh][Oo][Ss][Tt][Ss][Ff][Ii][Ll][Ee]['"$'\t '"']*\(.*\)$/"\1"/p' "${config[@]}" )) # expand paths (if present) to global and user known hosts files
for (( i=0; i < ${#global_kh[@]}; i++ )); do tmpkh=( $( sed -ne 's/^[ \t]*\([Gg][Ll][Oo][Bb][Aa][Ll]\|[Uu][Ss][Ee][Rr]\)[Kk][Nn][Oo][Ww][Nn][Hh][Oo][Ss][Tt][Ss][Ff][Ii][Ll][Ee]['"$'\t '"']*\(.*\)$/"\2"/p' "${config[@]}" ) )
global_kh[i]=$(echo "${global_kh[i]//\"/}") for i in "${tmpkh[@]}"; do
done i=$( echo "${i//\"/}" )
# expand path (if present) to user known hosts file [ -r "$i" ] && kh=( "${kh[@]}" "$i" )
user_kh=($( sed -ne 's/^[ \t]*[Uu][Ss][Ee][Rr][Kk][Nn][Oo][Ww][Nn][Hh][Oo][Ss][Tt][Ss][Ff][Ii][Ll][Ee]['"$'\t '"']*\(.*\)$/"\1"/p' "${config[@]}" ))
for (( i=0; i < ${#user_kh[@]}; i++ )); do
user_kh[i]=$(echo "${user_kh[i]//\"/}")
done done
IFS=$OIFS IFS=$OIFS
fi fi
# Global known_hosts files # Global known_hosts files
[ -r "$global_kh" ] &&
kh=( "${kh[@]}" "${global_kh[@]}" )
if [ -z "$configfile" ]; then if [ -z "$configfile" ]; then
[ -r /etc/ssh/ssh_known_hosts ] && [ -r /etc/ssh/ssh_known_hosts ] &&
kh=( "${kh[@]}" /etc/ssh/ssh_known_hosts ) kh=( "${kh[@]}" /etc/ssh/ssh_known_hosts )
@ -1288,8 +1283,6 @@ _known_hosts_real()
fi fi
# User known_hosts files # User known_hosts files
[ -r "$user_kh" ] &&
kh=( "${kh[@]}" "${user_kh[@]}" )
if [ -z "$configfile" ]; then if [ -z "$configfile" ]; then
[ -r ~/.ssh/known_hosts ] && [ -r ~/.ssh/known_hosts ] &&
kh=( "${kh[@]}" ~/.ssh/known_hosts ) kh=( "${kh[@]}" ~/.ssh/known_hosts )