1#!/bin/sh 2# 3# $NetBSD: named,v 1.22 2009/08/03 17:45:48 perry Exp $ 4# 5 6# PROVIDE: named 7# REQUIRE: NETWORKING mountcritremote syslogd 8# BEFORE: DAEMON 9# KEYWORD: chrootdir 10 11$_rc_subr_loaded . /etc/rc.subr 12 13name="named" 14rcvar=$name 15command="/usr/sbin/${name}" 16pidfile="/var/run/${name}/${name}.pid" 17start_precmd="named_precmd" 18extra_commands="reload" 19required_dirs="$named_chrootdir" # if it is set, it must exist 20 21named_migrate() 22{ 23 local src=$1 24 local dst=$2$1 25 echo "Migrating $src to $dst" 26( 27 diff=false 28 cd $src 29 for f in $(find . -type f) 30 do 31 f=${f##./} 32 case $f in 33 */*) 34 d=$dst/$(dirname $f) 35 ;; 36 *) d=$dst 37 ;; 38 esac 39 mkdir -p $d 40 if [ -r "$dst/$f" ] 41 then 42 if ! cmp $f $dst/$f; then 43 diff=true 44 fi 45 else 46 cp -p $f $dst/$f 47 fi 48 done 49 if $diff; then 50 echo "Cannot complete migration because files are different" 51 echo "Run 'diff -r $src $dst' resolve the differences" 52 else 53 rm -fr $src 54 ln -s $dst $src 55 fi 56) 57} 58 59named_precmd() 60{ 61 if [ -z "$named_chrootdir" ]; then 62 return 0; 63 fi 64 65 # If running in a chroot cage, ensure that the appropriate files 66 # exist inside the cage, as well as helper symlinks into the cage 67 # from outside. 68 # 69 # As this is called after the is_running and required_dir checks 70 # are made in run_rc_command(), we can safely assume ${named_chrootdir} 71 # exists and named isn't running at this point (unless forcestart 72 # is used). 73 # 74 case "$($command -v)" in 75 BIND*) # 9 no group, named-xfer, or ndc 76 ;; 77 named*) # 4 and 8 78 rc_flags="-g named $rc_flags" 79 if [ ! -x "${named_chrootdir}/usr/libexec/named-xfer" -o \ 80 "${named_chrootdir}/usr/libexec/named-xfer" -ot \ 81 /usr/libexec/named-xfer ]; then 82 rm -f "${named_chrootdir}/usr/libexec/named-xfer" 83 cp -p /usr/libexec/named-xfer \ 84 "${named_chrootdir}/usr/libexec" 85 fi 86 ln -fs "${named_chrootdir}/var/run/ndc" /var/run/ndc 87 ;; 88 esac 89 90 for i in null random 91 do 92 if [ ! -c "${named_chrootdir}/dev/$i" ]; then 93 rm -f "${named_chrootdir}/dev/$i" 94 (cd /dev && 95 /bin/pax -rw -pe "$i" "${named_chrootdir}/dev") 96 fi 97 done 98 99 if [ ! -h /etc/namedb ]; then 100 named_migrate /etc/namedb ${named_chrootdir} 101 fi 102 if [ \( -r /etc/named.conf \) -a \( ! -h /etc/named.conf \) -a \ 103 \( ! -r ${named_chrootdir}/etc/named.conf \) ] 104 then 105 mv /etc/named.conf ${named_chrootdir}/etc/named.conf 106 ln -s ${named_chrootdir}/etc/named.conf /etc/named.conf 107 fi 108 if [ \( ! -r ${named_chrootdir}/etc/named.conf \) -a \ 109 \( -r ${named_chrootdir}/etc/namedb/named.conf \) ]; then 110 ln -s namedb/named.conf ${named_chrootdir}/etc 111 fi 112 113 if [ -f /etc/localtime ]; then 114 cmp -s /etc/localtime "${named_chrootdir}/etc/localtime" || \ 115 cp -p /etc/localtime "${named_chrootdir}/etc/localtime" 116 fi 117 118 local piddir="$(dirname "${pidfile}")" 119 mkdir -p "${named_chrootdir}${piddir}" "${piddir}" 120 chmod 755 "${named_chrootdir}${piddir}" "${piddir}" 121 chown named:named "${named_chrootdir}${piddir}" "${piddir}" 122 ln -fs "${named_chrootdir}${pidfile}" "${pidfile}" 123 124 # Change run_rc_commands()'s internal copy of $named_flags 125 # 126 rc_flags="-u named -t ${named_chrootdir} $rc_flags" 127} 128 129load_rc_config $name 130run_rc_command "$1" 131