From 8d177fb1f42cb80ffbf678669cd726d40f26f123 Mon Sep 17 00:00:00 2001 From: Timo Weingärtner Date: Fri, 4 Jan 2013 21:16:37 +0100 Subject: implement hostname filtering Fixes GH-1. --- update-openssh-known-hosts | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'update-openssh-known-hosts') diff --git a/update-openssh-known-hosts b/update-openssh-known-hosts index 8b77aee..e191f92 100755 --- a/update-openssh-known-hosts +++ b/update-openssh-known-hosts @@ -82,7 +82,32 @@ run-parts --list "${CONFDIR}/sources/" | while read sourcefile; do mv ${source}/new ${source}/current fi if [ -e ${source}/current ]; then - sort -u ${source}/current >&3 + if [ -e "${sourcefile}.filter" ]; then + mapfile -t filter < "${sourcefile}.filter" + for i in ${!filter[@]}; do + if [[ ${filter[$i]} =~ ^($|#) ]]; then + unset filter[$i] + fi + done + while read hostlist rest; do + IFS=, read -a hostarray <<<$hostlist + new_hostlist='' + for host in ${hostarray[@]}; do + for rule in "${filter[@]}"; do + if [[ ${host} =~ ${rule#* } ]]; then + if [[ ${rule%% *} =~ ^[aopy] ]]; then + new_hostlist="${new_hostlist}${host}," + fi + break + fi + done + done + [ "$new_hostlist" ] || continue + echo "${new_hostlist%,} ${rest}" + done < ${source}/current | sort -u >&3 + else + sort -u ${source}/current >&3 + fi fi done 3>| "${OUTFILE}.new" -- cgit v1.2.3