From: Georgios Kontaxis Date: Tue, 22 May 2018 21:25:23 +0000 (-0700) Subject: Fall back to an in-addr.arpa hostname when a PTR record is not available. X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=refs%2Fheads%2Fdev%2F2018-05_up2speed;p=starttls.git Fall back to an in-addr.arpa hostname when a PTR record is not available. --- diff --git a/scan/_Makefile b/scan/_Makefile index 2f6f491..ef568b6 100644 --- a/scan/_Makefile +++ b/scan/_Makefile @@ -1,6 +1,6 @@ .PHONY: all clean -hostname = "\"www.example.com\"" +hostname = "\"localhost.\"" all: \ bin/smtp_ssl3 bin/smtp_ssl3_god bin/smtp_tls1 bin/smtp_tls1_god \ diff --git a/scan/configure.sh b/scan/configure.sh index b6842e2..29f3548 100755 --- a/scan/configure.sh +++ b/scan/configure.sh @@ -1,18 +1,32 @@ #!/bin/bash -# make sure we have all the tools lying around - SEDBIN=`which sed `; if [ "${SEDBIN}" == "" ]; then \ - >&2 echo "FATAL. $0 FAILED. Missing sed."; exit -1; fi +# Make sure we have all the tools available. CURLBIN=`which curl `; if [ "${CURLBIN}" == "" ]; then \ >&2 echo "FATAL. $0 FAILED. Missing curl."; exit -1; fi -XARGSBIN=`which xargs`; if [ "${XARGSBIN}" == "" ]; then \ - >&2 echo "FATAL. $0 FAILED. Missing xargs."; exit -1; fi DIGBIN=`which dig `; if [ "${DIGBIN}" == "" ]; then \ >&2 echo "FATAL. $0 FAILED. Missing dig."; exit -1; fi + AWKBIN=`which awk `; if [ "${AWKBIN}" == "" ]; then \ + >&2 echo "FATAL. $0 FAILED. Missing awk."; exit -1; fi + SEDBIN=`which sed `; if [ "${SEDBIN}" == "" ]; then \ + >&2 echo "FATAL. $0 FAILED. Missing sed."; exit -1; fi + +# Update the hostname variable in the Makefile with the FQDN of this host. +myipaddr=$(curl -s --max-time 5 https://tools.100tx.org/myipaddress/) +if [ "$myipaddr" == "" ]; then + myipaddr="127.0.0.1" +fi + +myfqdn=$(dig +short -x $myipaddr 2> /dev/null) +if [ "$myfqdn" == "" ]; then + myfqdn=$(echo "$myipaddr" | awk -F \. \ + '{ + for (i = NF; i > 1; i--) { + printf("%s.", $i); + } + printf("%s.in-addr.arpa.\n", $1); + }' + ) +fi -# update the hostname variable in the Makefile with the actual name of this -# host (so that reverse lookups match, ideally there's an MX record too but -# that's may be asking too much) -sed s/"^hostname = .*\$"/"hostname = \"\\\\\"`curl -s \ - https://tools.100tx.org/myipaddress/ \ - | xargs dig +short -x | sed s/"\.\$"//g`\\\\\"\""/g _Makefile > Makefile +sed s/"^hostname = .*\$"/"hostname = \"\\\\\"$myfqdn\\\\\"\""/g \ + _Makefile > Makefile