#! /bin/bash

#$title$ Internet Domain Name System (DNS) configuration syntax
#$check$ syntax of named configuration file and all files included by it; test load of all master zones
#$ref$ man named-checkconf
#$author$ Rafal Rzeczkowski

level_check long

V=0.50	# initial
V=0.51	# workaround for named-checkconf reporting main configuration errors in STDOUT instead of STDERR

TMP_OUT=$(mktemp)
TMP_ERR=$(mktemp)

IFS=$'\n'
# named-checkconf(8): named-checkconf returns
# an exit status of 1 if errors were detected and 0 otherwise.
if named-checkconf -z 1>$TMP_OUT 2>$TMP_ERR
then
	ZONEs=($(<$TMP_OUT))
	echodebug "test loaded ${#ZONEs[*]} DNS zone(s)"
	ok
else
	if test -s $TMP_ERR
	then
		ERRORs=($(<$TMP_ERR))
	elif test -s $TMP_OUT
	then
		ERRORs=($(<$TMP_OUT))
	else
		ERRORs=('unspecified')
	fi
	fail warning "${#ERRORs[*]} syntax error(s) found: ${ERRORs[0]}"
	helpmsg 'correct the specified error; run {named-checkconf -z} for a full listing'
fi
rm $TMP_OUT $TMP_ERR
exit
