named revision 1.16
11.1Slukem#!/bin/sh
21.1Slukem#
31.16Schristos# $NetBSD: named,v 1.16 2005/07/17 16:30:57 christos Exp $
41.1Slukem#
51.1Slukem
61.1Slukem# PROVIDE: named
71.2Slukem# REQUIRE: SERVERS
81.10Sthorpej# BEFORE:  DAEMON
91.11Slukem# KEYWORD: chrootdir
101.1Slukem
111.14Smycroft$_rc_subr_loaded . /etc/rc.subr
121.1Slukem
131.1Slukemname="named"
141.6Slukemrcvar=$name
151.1Slukemcommand="/usr/sbin/${name}"
161.1Slukempidfile="/var/run/${name}.pid"
171.7Slukemstart_precmd="named_precmd"
181.7Slukemextra_commands="reload"
191.7Slukemrequired_dirs="$named_chrootdir"	# if it is set, it must exist
201.7Slukem
211.7Slukemnamed_precmd()
221.7Slukem{
231.7Slukem	if [ -z "$named_chrootdir" ]; then
241.7Slukem		return 0;
251.7Slukem	fi
261.7Slukem
271.7Slukem	# If running in a chroot cage, ensure that the appropriate files
281.7Slukem	# exist inside the cage, as well as helper symlinks into the cage 
291.7Slukem	# from outside.
301.7Slukem	#
311.7Slukem	# As this is called after the is_running and required_dir checks
321.7Slukem	# are made in run_rc_command(), we can safely assume ${named_chrootdir}
331.7Slukem	# exists and named isn't running at this point (unless forcestart
341.7Slukem	# is used).
351.7Slukem	#
361.12Schristos	case "$($command -v)" in
371.12Schristos	BIND*)	# 9 no group, named-xfer, or ndc
381.12Schristos		;;
391.12Schristos	named*)	# 4 and 8
401.12Schristos		rc_flags="-g named $rc_flags"
411.12Schristos		if [ ! -x "${named_chrootdir}/usr/libexec/named-xfer" -o \
421.12Schristos		    "${named_chrootdir}/usr/libexec/named-xfer" -ot \
431.12Schristos		    /usr/libexec/named-xfer ]; then
441.12Schristos			rm -f "${named_chrootdir}/usr/libexec/named-xfer"
451.12Schristos			cp -p /usr/libexec/named-xfer \
461.12Schristos			    "${named_chrootdir}/usr/libexec"
471.12Schristos		fi
481.12Schristos		ln -fs "${named_chrootdir}/var/run/ndc" /var/run/ndc
491.12Schristos		;;
501.12Schristos	esac
511.12Schristos
521.13Schristos	for i in null random
531.13Schristos	do
541.13Schristos		if [ ! -c "${named_chrootdir}/dev/$i" ]; then
551.13Schristos			rm -f "${named_chrootdir}/dev/$i"
561.13Schristos			(cd /dev && 
571.13Schristos			    /bin/pax -rw -pe "$i" "${named_chrootdir}/dev")
581.13Schristos		fi
591.13Schristos	done
601.4Slukem
611.16Schristos	if [ -d /etc/namedb ]; then
621.16Schristos		(cd /etc/namedb && for i in *; do
631.16Schristos			j=${named_chrootdir}/etc/namedb/$i
641.16Schristos			if [ ! -r $j ]; then
651.16Schristos				cp -rp $i $j
661.16Schristos			fi
671.16Schristos		done)
681.16Schristos	fi
691.16Schristos	if [ \( ! -r ${named_chrootdir}/etc/named.conf \) -a \
701.16Schristos	    \( -r ${named_chrootdir}/etc/namedb/named.conf \) ]; then
711.16Schristos		ln -s namedb/named.conf ${named_chrootdir}/etc
721.16Schristos	fi
731.16Schristos
741.7Slukem	if [ -f /etc/localtime ]; then
751.7Slukem		cmp -s /etc/localtime "${named_chrootdir}/etc/localtime" || \
761.7Slukem		    cp -p /etc/localtime "${named_chrootdir}/etc/localtime"
771.7Slukem	fi
781.15Stron	ln -fs "${named_chrootdir}${pidfile}" ${pidfile}
791.7Slukem
801.7Slukem	#	Change run_rc_commands()'s internal copy of $named_flags
811.7Slukem	#
821.12Schristos	rc_flags="-u named -t ${named_chrootdir} $rc_flags"
831.7Slukem}
841.1Slukem
851.5Slukemload_rc_config $name
861.3Slukemrun_rc_command "$1"
87