named revision 1.12
11.1Slukem#!/bin/sh
21.1Slukem#
31.12Schristos# $NetBSD: named,v 1.12 2003/12/18 18:30:18 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.1Slukem. /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.4Slukem
531.7Slukem	if [ ! -c "${named_chrootdir}/dev/null" ]; then
541.7Slukem		rm -f "${named_chrootdir}/dev/null"
551.7Slukem		( cd /dev ; /bin/pax -rw -pe null "${named_chrootdir}/dev" )
561.7Slukem	fi
571.7Slukem	if [ -f /etc/localtime ]; then
581.7Slukem		cmp -s /etc/localtime "${named_chrootdir}/etc/localtime" || \
591.7Slukem		    cp -p /etc/localtime "${named_chrootdir}/etc/localtime"
601.7Slukem	fi
611.8Slukem	ln -fs "${named_chrootdir}/var/run/named.pid" /var/run/named.pid
621.7Slukem
631.7Slukem	#	Change run_rc_commands()'s internal copy of $named_flags
641.7Slukem	#
651.12Schristos	rc_flags="-u named -t ${named_chrootdir} $rc_flags"
661.7Slukem}
671.1Slukem
681.5Slukemload_rc_config $name
691.3Slukemrun_rc_command "$1"
70