2008-03-03 02:44:01 +05:30
|
|
|
#!@PREFIX@/sbin/runscript
|
2008-01-11 21:01:10 +05:30
|
|
|
# Copyright 2007-2008 Roy Marples <roy@marples.name>
|
|
|
|
# All rights reserved. Released under the 2-clause BSD license.
|
2007-11-23 17:34:11 +05:30
|
|
|
|
|
|
|
command=/usr/sbin/named
|
2009-04-27 17:36:54 +05:30
|
|
|
command_args=$named_args
|
2008-04-28 18:18:20 +05:30
|
|
|
pidfile=@VARBASE@/run/named.pid
|
2007-11-23 17:34:11 +05:30
|
|
|
name="Domain Name server"
|
2007-11-29 21:53:59 +05:30
|
|
|
extra_started_commands="reload"
|
2007-11-23 17:34:11 +05:30
|
|
|
|
|
|
|
namedb=/etc/namedb
|
2008-04-28 18:18:20 +05:30
|
|
|
uid=named
|
2009-04-27 17:36:54 +05:30
|
|
|
case "$RC_UNAME" in
|
2008-04-28 18:18:20 +05:30
|
|
|
FreeBSD)
|
|
|
|
uid=bind
|
|
|
|
pidfile=@VARBASE@/run/named/pid
|
|
|
|
;;
|
|
|
|
Linux)
|
|
|
|
uid=bind
|
|
|
|
;;
|
|
|
|
esac
|
2009-04-27 17:36:54 +05:30
|
|
|
: ${named_uid:=${uid}}
|
2007-11-23 17:34:11 +05:30
|
|
|
|
2008-01-11 17:48:05 +05:30
|
|
|
depend()
|
|
|
|
{
|
2007-11-23 17:34:11 +05:30
|
|
|
provide dns
|
|
|
|
need localmount
|
|
|
|
after bootmisc
|
|
|
|
}
|
|
|
|
|
2008-01-11 17:48:05 +05:30
|
|
|
start_pre()
|
|
|
|
{
|
2009-04-27 17:36:54 +05:30
|
|
|
if [ -n "$named_chroot" ]; then
|
2007-11-23 17:34:11 +05:30
|
|
|
# Create (or update) the chroot directory structure
|
|
|
|
if [ -r /etc/mtree/BIND.chroot.dist ]; then
|
2009-04-27 17:36:54 +05:30
|
|
|
mtree -deU -f /etc/mtree/BIND.chroot.dist -p "$named_chroot"
|
2007-11-23 17:34:11 +05:30
|
|
|
else
|
|
|
|
ewarn "/etc/mtree/BIND.chroot.dist missing,"
|
|
|
|
ewarn "chroot directory structure not updated"
|
|
|
|
fi
|
|
|
|
|
2009-04-27 17:36:54 +05:30
|
|
|
if [ ! -d "$named_chroot"/. ]; then
|
|
|
|
eerror "chroot directory $named_chroot missing"
|
2007-11-23 17:34:11 +05:30
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Create /etc/namedb symlink
|
2009-04-27 17:36:54 +05:30
|
|
|
if [ ! -L "$namedb" ]; then
|
|
|
|
if [ -d "$namedb" ]; then
|
|
|
|
ewarn "named chroot: $namedb is a directory!"
|
|
|
|
elif [ -e "$namedb" ]; then
|
|
|
|
ewarn "named chroot: $namedb exists!"
|
2007-11-23 17:34:11 +05:30
|
|
|
else
|
2009-04-27 17:36:54 +05:30
|
|
|
ln -s "$named_chroot$namedb" "$namedb"
|
2007-11-23 17:34:11 +05:30
|
|
|
fi
|
|
|
|
else
|
|
|
|
# Make sure it points to the right place.
|
2009-04-27 17:36:54 +05:30
|
|
|
ln -shf "$named_chroot$namedb" "$namedb"
|
2007-11-23 17:34:11 +05:30
|
|
|
fi
|
|
|
|
|
2009-04-27 17:36:54 +05:30
|
|
|
case "$RC_UNAME" in
|
2007-11-23 17:34:11 +05:30
|
|
|
*BSD|DragonFly)
|
|
|
|
# Mount a devfs in the chroot directory if needed
|
2009-04-27 17:36:54 +05:30
|
|
|
umount "$named_chroot"/dev 2>/dev/null
|
|
|
|
mount -t devfs dev "$named_chroot"/dev
|
|
|
|
devfs -m "$named_chroot"/dev \
|
|
|
|
ruleset devfsrules_hide_all
|
|
|
|
devfs -m "$named_chroot"/dev \
|
|
|
|
rule apply path null unhide
|
|
|
|
devfs -m "$named_chroot"/dev \
|
|
|
|
rule apply path random unhide
|
2007-11-23 17:34:11 +05:30
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Copy local timezone information if it is not up to date.
|
|
|
|
if [ -r /etc/localtime ]; then
|
2009-04-27 17:36:54 +05:30
|
|
|
cmp -s /etc/localtime "$named_chroot/etc/localtime" ||
|
|
|
|
cp -p /etc/localtime "$named_chroot/etc/localtime"
|
2007-11-23 17:34:11 +05:30
|
|
|
fi
|
|
|
|
|
2009-04-27 17:36:54 +05:30
|
|
|
command_args="$command_args -t $named_chroot"
|
2007-11-23 17:34:11 +05:30
|
|
|
|
2009-04-27 17:36:54 +05:30
|
|
|
ln -fs "$named_chroot$pidfile" "$pidfile"
|
2007-11-23 17:34:11 +05:30
|
|
|
fi
|
|
|
|
|
2009-04-27 17:36:54 +05:30
|
|
|
if [ ! -s "$named_chroot$namedb/rndc.conf" ]; then
|
|
|
|
local confgen="${command%/named}/rndc-confgen -a -b256 -u $named_uid \
|
|
|
|
-c $named_chrootdir/etc/namedb/rndc.key"
|
|
|
|
if [ -s "$named_chroot$namedb/rndc.key" ]; then
|
2007-11-23 17:34:11 +05:30
|
|
|
local getuser="stat -f%Su"
|
2009-04-27 17:36:54 +05:30
|
|
|
[ "$RC_UNAME" = Linux ] && getuser="stat -c%U"
|
|
|
|
case $(${getuser} "$named_chroot$namedb"/rndc.key) in
|
|
|
|
root|"$named_uid");;
|
|
|
|
*) $confgen;;
|
2007-11-23 17:34:11 +05:30
|
|
|
esac
|
|
|
|
else
|
2009-04-27 17:36:54 +05:30
|
|
|
$confgen
|
2007-11-23 17:34:11 +05:30
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2008-01-11 17:48:05 +05:30
|
|
|
reload()
|
|
|
|
{
|
2007-11-23 17:34:11 +05:30
|
|
|
rndc reload
|
|
|
|
}
|
|
|
|
|
2008-01-11 17:48:05 +05:30
|
|
|
stop_post()
|
|
|
|
{
|
2009-04-27 17:36:54 +05:30
|
|
|
if [ -n "$named_chroot" -a -c "$named_chroot"/dev/null ]; then
|
|
|
|
umount "$named_chroot"/dev 2>/dev/null || true
|
2007-11-23 17:34:11 +05:30
|
|
|
fi
|
|
|
|
}
|