#!/bin/sh
#
# check_dns - check the name resolver on this host
#
# $Id: check_dns,v 1.7 2022/12/26 23:09:39 root Exp root $
#
# Check DNS for
# - smtp.urlfilterdb.com
# - cgibin.urlfilterdb.com

if [ -d /usr/xpg4/bin ]
then
   # to get a standard 'grep' on Solaris:
   PATH=/usr/xpg4/bin:$PATH
   export PATH
fi

ME=check_dns

NSLOOKUP="$1"
HOST="$2"
DIG="$3"

if [ "$1" != "no"  -a  "$1" != "" ]
then
   LOOKUPCMD="$1"
elif [ "$2" != "no"  -a  "$2" != "" ]
then
   LOOKUPCMD="$2"
else
   LOOKUPCMD="$3"
fi
export LOOKUPCMD

ERROR=no

LC_ALL=C
LC_CTYPE=C
export LC_ALL LC_CTYPE

for host in   \
	updates.urlfilterdb.com  \
	cgibin.urlfilterdb.com  
do
   result=`$LOOKUPCMD $host 2>/dev/null | grep -i -E -e "canonical name ="  -e "is an alias for"  -e "IN.*CNAME"  -e "Name:.*$host"  -e " has address "  -e "^$host.*IN.*A" `
   if [ "$result" = "" ]
   then
      ERROR=yes
      echo "cannot resolve hostname \"$host\" using $LOOKUPCMD"
   fi
done

if [ $ERROR = yes ]
then
   echo "*****   Check the name resolver on this system.  *****"
   echo "*****   ufdbGuard does not function properly if it cannot resolve public hostnames.  *****"
   echo
fi

exit 0

