Skip to content

Commit ac2b431

Browse files
committed
Move dig down the row of DNS resolvers
... because there's a higher possibility for the stable branch that people use $HOME/.digrc
1 parent 8d6609f commit ac2b431

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

testssl.sh

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ HAS_AES256_GCM=false
361361
HAS_ZLIB=false
362362
HAS_DIG=false
363363
HAS_DIG_R=true
364-
DIG_R='-r'
364+
DIG_R="-r"
365365
HAS_HOST=false
366366
HAS_DRILL=false
367367
HAS_NSLOOKUP=false
@@ -17910,15 +17910,15 @@ get_a_record() {
1791017910
fatal "Local hostname given but no 'avahi-resolve' or 'dig' available." $ERR_DNSBIN
1791117911
fi
1791217912
fi
17913-
if [[ -z "$ip4" ]] && "$HAS_DIG"; then
17914-
ip4=$(filter_ip4_address $(dig $DIG_R +short +timeout=2 +tries=2 $noidnout -t a "$1" 2>/dev/null | awk '/^[0-9]/ { print $1 }'))
17915-
fi
1791617913
if [[ -z "$ip4" ]] && "$HAS_HOST"; then
1791717914
ip4=$(filter_ip4_address $(host -t a "$1" 2>/dev/null | awk '/address/ { print $NF }'))
1791817915
fi
1791917916
if [[ -z "$ip4" ]] && "$HAS_DRILL"; then
1792017917
ip4=$(filter_ip4_address $(drill a "$1" | awk '/ANSWER SECTION/,/AUTHORITY SECTION/ { print $NF }' | awk '/^[0-9]/'))
1792117918
fi
17919+
if [[ -z "$ip4" ]] && "$HAS_DIG"; then
17920+
ip4=$(filter_ip4_address $(dig $DIG_R +short +timeout=2 +tries=2 $noidnout -t a "$1" 2>/dev/null | awk '/^[0-9]/ { print $1 }'))
17921+
fi
1792217922
if [[ -z "$ip4" ]] && "$HAS_NSLOOKUP"; then
1792317923
ip4=$(filter_ip4_address $(strip_lf "$(nslookup -querytype=a "$1" 2>/dev/null | awk '/^Name/ { getline; print $NF }')"))
1792417924
fi
@@ -17953,12 +17953,12 @@ get_aaaa_record() {
1795317953
else
1795417954
fatal "Local hostname given but no 'avahi-resolve' or 'dig' available." $ERR_DNSBIN
1795517955
fi
17956-
elif "$HAS_DIG"; then
17957-
ip6=$(filter_ip6_address $(dig $DIG_R +short +timeout=2 +tries=2 $noidnout -t aaaa "$1" 2>/dev/null | awk '/^[0-9]/ { print $1 }'))
1795817956
elif "$HAS_HOST"; then
1795917957
ip6=$(filter_ip6_address $(host -t aaaa "$1" | awk '/address/ { print $NF }'))
1796017958
elif "$HAS_DRILL"; then
1796117959
ip6=$(filter_ip6_address $(drill aaaa "$1" | awk '/ANSWER SECTION/,/AUTHORITY SECTION/ { print $NF }' | awk '/^[0-9]/'))
17960+
elif "$HAS_DIG"; then
17961+
ip6=$(filter_ip6_address $(dig $DIG_R +short +timeout=2 +tries=2 $noidnout -t aaaa "$1" 2>/dev/null | awk '/^[0-9]/ { print $1 }'))
1796217962
elif "$HAS_NSLOOKUP"; then
1796317963
ip6=$(filter_ip6_address $(strip_lf "$(nslookup -type=aaaa "$1" 2>/dev/null | awk '/'"^${a}"'.*AAAA/ { print $NF }')"))
1796417964
fi
@@ -17988,16 +17988,16 @@ get_caa_rr_record() {
1798817988
# for dig +short the output always starts with '0 issue [..]' or '\# 19 [..]' so we normalize thereto to keep caa_flag, caa_property
1798917989
# caa_property then has key/value pairs, see https://tools.ietf.org/html/rfc6844#section-3
1799017990
OPENSSL_CONF=""
17991-
if "$HAS_DIG"; then
17992-
raw_caa="$(dig $DIG_R +short +timeout=3 +tries=3 $noidnout type257 "$1" 2>/dev/null | awk '{ print $1" "$2" "$3 }')"
17993-
# empty if no CAA record
17994-
elif "$HAS_DRILL"; then
17991+
if "$HAS_DRILL"; then
1799517992
raw_caa="$(drill $1 type257 | awk '/'"^${1}"'.*CAA/ { print $5,$6,$7 }')"
1799617993
elif "$HAS_HOST"; then
1799717994
raw_caa="$(host -t type257 $1)"
1799817995
if grep -Ewvq "has no CAA|has no TYPE257" <<< "$raw_caa"; then
1799917996
raw_caa="$(sed -e 's/^.*has CAA record //' -e 's/^.*has TYPE257 record //' <<< "$raw_caa")"
1800017997
fi
17998+
elif "$HAS_DIG"; then
17999+
raw_caa="$(dig $DIG_R +short +timeout=3 +tries=3 $noidnout type257 "$1" 2>/dev/null | awk '{ print $1" "$2" "$3 }')"
18000+
# empty if no CAA record
1800118001
elif "$HAS_NSLOOKUP"; then
1800218002
raw_caa="$(strip_lf "$(nslookup -type=type257 $1 | grep -w rdata_257)")"
1800318003
if [[ -n "$raw_caa" ]]; then
@@ -18059,10 +18059,10 @@ get_mx_record() {
1805918059
# we need the last two columns here
1806018060
if "$HAS_HOST"; then
1806118061
mxs="$(host -t MX "$1" 2>/dev/null | awk '/is handled by/ { print $(NF-1), $NF }')"
18062-
elif "$HAS_DIG"; then
18063-
mxs="$(dig $DIG_R +short $noidnout -t MX "$1" 2>/dev/null | awk '/^[0-9]/ { print $1" "$2 }')"
1806418062
elif "$HAS_DRILL"; then
1806518063
mxs="$(drill mx $1 | awk '/IN[ \t]MX[ \t]+/ { print $(NF-1), $NF }')"
18064+
elif "$HAS_DIG"; then
18065+
mxs="$(dig $DIG_R +short $noidnout -t MX "$1" 2>/dev/null | awk '/^[0-9]/ { print $1" "$2 }')"
1806618066
elif "$HAS_NSLOOKUP"; then
1806718067
mxs="$(strip_lf "$(nslookup -type=MX "$1" 2>/dev/null | awk '/mail exchanger/ { print $(NF-1), $NF }')")"
1806818068
else
@@ -18161,13 +18161,13 @@ determine_rdns() {
1816118161
elif "$HAS_DIG"; then
1816218162
rDNS=$(dig $DIG_R -x $nodeip @224.0.0.251 -p 5353 +notcp +noall +answer +short | awk '{ print $1 }')
1816318163
fi
18164-
elif "$HAS_DIG"; then
18165-
# 1+2 should suffice. It's a compromise for if e.g. network is down but we have a docker/localhost server
18166-
rDNS=$(dig $DIG_R -x $nodeip +timeout=1 +tries=2 +noall +answer +short | awk '{ print $1 }') # +short returns also CNAME, e.g. openssl.org
1816718164
elif "$HAS_HOST"; then
1816818165
rDNS=$(host -t PTR $nodeip 2>/dev/null | awk '/pointer/ { print $NF }')
1816918166
elif "$HAS_DRILL"; then
1817018167
rDNS=$(drill -x ptr $nodeip 2>/dev/null | awk '/ANSWER SECTION/ { getline; print $NF }')
18168+
elif "$HAS_DIG"; then
18169+
# 1+2 should suffice. It's a compromise for if e.g. network is down but we have a docker/localhost server
18170+
rDNS=$(dig $DIG_R -x $nodeip +timeout=1 +tries=2 +noall +answer +short | awk '{ print $1 }') # +short returns also CNAME, e.g. openssl.org
1817118171
elif "$HAS_NSLOOKUP"; then
1817218172
rDNS=$(strip_lf "$(nslookup -type=PTR $nodeip 2>/dev/null | grep -v 'canonical name =' | grep 'name = ' | awk '{ print $NF }' | sed 's/\.$//')")
1817318173
fi

0 commit comments

Comments
 (0)