1 1.1 lukem #!/bin/sh 2 1.1 lukem # 3 1.13 christos # $NetBSD: named,v 1.13 2004/05/21 15:40:22 christos Exp $ 4 1.1 lukem # 5 1.1 lukem 6 1.1 lukem # PROVIDE: named 7 1.2 lukem # REQUIRE: SERVERS 8 1.10 thorpej # BEFORE: DAEMON 9 1.11 lukem # KEYWORD: chrootdir 10 1.1 lukem 11 1.1 lukem . /etc/rc.subr 12 1.1 lukem 13 1.1 lukem name="named" 14 1.6 lukem rcvar=$name 15 1.1 lukem command="/usr/sbin/${name}" 16 1.1 lukem pidfile="/var/run/${name}.pid" 17 1.7 lukem start_precmd="named_precmd" 18 1.7 lukem extra_commands="reload" 19 1.7 lukem required_dirs="$named_chrootdir" # if it is set, it must exist 20 1.7 lukem 21 1.7 lukem named_precmd() 22 1.7 lukem { 23 1.7 lukem if [ -z "$named_chrootdir" ]; then 24 1.7 lukem return 0; 25 1.7 lukem fi 26 1.7 lukem 27 1.7 lukem # If running in a chroot cage, ensure that the appropriate files 28 1.7 lukem # exist inside the cage, as well as helper symlinks into the cage 29 1.7 lukem # from outside. 30 1.7 lukem # 31 1.7 lukem # As this is called after the is_running and required_dir checks 32 1.7 lukem # are made in run_rc_command(), we can safely assume ${named_chrootdir} 33 1.7 lukem # exists and named isn't running at this point (unless forcestart 34 1.7 lukem # is used). 35 1.7 lukem # 36 1.12 christos case "$($command -v)" in 37 1.12 christos BIND*) # 9 no group, named-xfer, or ndc 38 1.12 christos ;; 39 1.12 christos named*) # 4 and 8 40 1.12 christos rc_flags="-g named $rc_flags" 41 1.12 christos if [ ! -x "${named_chrootdir}/usr/libexec/named-xfer" -o \ 42 1.12 christos "${named_chrootdir}/usr/libexec/named-xfer" -ot \ 43 1.12 christos /usr/libexec/named-xfer ]; then 44 1.12 christos rm -f "${named_chrootdir}/usr/libexec/named-xfer" 45 1.12 christos cp -p /usr/libexec/named-xfer \ 46 1.12 christos "${named_chrootdir}/usr/libexec" 47 1.12 christos fi 48 1.12 christos ln -fs "${named_chrootdir}/var/run/ndc" /var/run/ndc 49 1.12 christos ;; 50 1.12 christos esac 51 1.12 christos 52 1.13 christos for i in null random 53 1.13 christos do 54 1.13 christos if [ ! -c "${named_chrootdir}/dev/$i" ]; then 55 1.13 christos rm -f "${named_chrootdir}/dev/$i" 56 1.13 christos (cd /dev && 57 1.13 christos /bin/pax -rw -pe "$i" "${named_chrootdir}/dev") 58 1.13 christos fi 59 1.13 christos done 60 1.4 lukem 61 1.7 lukem if [ -f /etc/localtime ]; then 62 1.7 lukem cmp -s /etc/localtime "${named_chrootdir}/etc/localtime" || \ 63 1.7 lukem cp -p /etc/localtime "${named_chrootdir}/etc/localtime" 64 1.7 lukem fi 65 1.8 lukem ln -fs "${named_chrootdir}/var/run/named.pid" /var/run/named.pid 66 1.7 lukem 67 1.7 lukem # Change run_rc_commands()'s internal copy of $named_flags 68 1.7 lukem # 69 1.12 christos rc_flags="-u named -t ${named_chrootdir} $rc_flags" 70 1.7 lukem } 71 1.1 lukem 72 1.5 lukem load_rc_config $name 73 1.3 lukem run_rc_command "$1" 74