5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
22 # Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
23 # Copyright 2016 Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
24 # Copyright 2023 Gary Mills
26 # smf_method(5) start/stop script required for server DNS
28 .
/lib
/svc
/share
/smf_include.sh
35 if [ -z "${f}" -o ! -f "${f}" -o \
36 -z "${c}" -o ! -d "${c}" ]; then
37 exit ${SMF_EXIT_ERR_CONFIG}
40 umount
${c}/${f} >/dev
/null
2>&1
41 mkdir
-p `dirname ${c}/${f}`
43 mount
-Flofs ${f} ${c}/${f}
52 umount
${c}/${f} >/dev
/null
2>&1
58 configuration_file
=/etc
/named.conf
59 rndc_config_file
=/etc
/rndc.conf
60 rndc_key_file
=/etc
/rndc.key
62 libraries
="/lib/openssl/engines/libpk11.so /usr/lib/security/pkcs11_kernel.so.1"
65 properties
="debug_level ip_interfaces listen_on_port
66 threads chroot_dir configuration_file server user"
68 for prop
in $properties
70 value
=`/usr/bin/svcprop -p options/${prop} ${SMF_FMRI}`
71 if [ -z "${value}" -o "${value}" = '""' ]; then
77 if [ ${value} -gt 0 ]; then
78 cmdopts
="${cmdopts} -d ${value}"
84 cmdopts
="${cmdopts} -4";;
86 cmdopts
="${cmdopts} -6";;
88 : # Default is all, therefore ignore.
91 echo "$I: Unrecognised value in service instance property" >&2
92 echo "$I: options/${prop} : ${value}" >&2
97 if [ ${value} -gt 0 ]; then
98 cmdopts
="${cmdopts} -p ${value}"
102 if [ ${value} -gt 0 ]; then
103 cmdopts
="${cmdopts} -n ${value}"
107 cmdopts
="${cmdopts} -t ${value}"
108 checkopts
="${checkopts} -t ${value}"
111 'configuration_file')
112 cmdopts
="${cmdopts} -c ${value}"
113 checkopts
="${checkopts} ${value}"
114 configuration_file
=${value};
117 set -- `echo ${value} | /usr/bin/sed -e 's/\\\\//g'`
121 cmdopts
="${cmdopts} -u ${value}"
127 configuration_dir
=$
(sed -n -e 's,^[[:space:]]*directory.*"\(.*\)";,\1,p' \
128 ${configuration_file})
129 [ "${configuration_dir}" == "" ] && configuration_dir
=/etc
/namedb
131 configuration_files
=$
(sed -n -e \
132 "s,^[[:space:]]*file.*\"\(.*\)\";,${configuration_dir}/\1,p" \
133 ${configuration_file} |
sort -u)
134 configuration_files
="${configuration_files} ${configuration_file}"
137 result
=${SMF_EXIT_OK}
139 # Read command line arguments
142 contract
="$3" # %{restarter/contract}
144 # Set defaults; SMF_FMRI should have been set, but just in case.
145 if [ -z "$SMF_FMRI" ]; then
146 SMF_FMRI
="svc:/network/dns/server:${instance}"
148 server
="/usr/sbin/named"
149 checkconf
="/usr/sbin/named-checkconf"
150 I
=`/usr/bin/basename $0`
156 # Check configuration file exists.
157 if [ ! -f ${configuration_file} ]; then
158 msg
="$I: Configuration file ${configuration_file} does not exist!"
160 /usr
/bin
/logger
-p daemon.error
${msg}
161 # dns-server should be placed in maintenance state.
162 result
=${SMF_EXIT_ERR_CONFIG}
165 # If chroot option is set, note zones(5) are preferred, then
166 # configuration file lives under chroot directory.
167 if [ "${chroot_dir}" != "" ]; then
168 if [ "${chroot_dir}" = "/" ]; then
169 msg
="$I: chroot_dir must not be /"
171 /usr
/bin
/logger
-p daemon.error
${msg}
172 # dns-server should be placed in maintenance state.
173 exit ${SMF_EXIT_ERR_CONFIG}
176 server
="env LD_NOLAZYLOAD=1 ${server}"
177 checkconf
="env LD_NOLAZYLOAD=1 ${checkconf}"
179 mkdir
-p ${chroot_dir}
181 if [ "${SMF_ZONENAME}" = "global" ]; then
182 for dev
in crypto log null poll random urandom
; do
183 rm -f ${chroot_dir}/dev
/${dev}
184 pax
-rw -H -pe /dev
/${dev} ${chroot_dir}
189 for dev
in crypto null poll random urandom
; do
190 if [ ! -c ${chroot_dir}/dev
/${dev} ]; then
191 missing
="${missing} ${dev}"
195 if [ ! -z "${missing}" ]; then
196 msg
="$I: missing device nodes in ${chroot_dir}: ${missing}"
198 /usr
/bin
/logger
-p daemon.error
${msg}
199 # dns-server should be placed in maintenance state.
200 exit ${SMF_EXIT_ERR_CONFIG}
203 mkdir
-p ${chroot_dir}/etc
/crypto
204 echo "/usr/lib/security/pkcs11_kernel.so.1" > ${chroot_dir}/etc
/crypto
/pkcs11.conf
206 mount_chroot
${chroot_dir} ${configuration_files} ${libraries}
208 mkdir
-p ${chroot_dir}/var
/run
/named
209 chown
${cmduser}:${cmduser} ${chroot_dir}/var
/run
/named
211 configuration_file
=${chroot_dir}${configuration_file}
212 rndc_config_file
=${chroot_dir}${rndc_config_file}
213 rndc_key_file
=${chroot_dir}${rndc_key_file}
214 rndc_cmd_opts
="${rndc_cmd_opts} -t ${chroot_dir}"
217 # Check if the rndc config file exists.
218 if [ ! -f ${rndc_config_file} ]; then
219 # If not, check if the default rndc key file exists.
220 if [ ! -f ${rndc_key_file} ]; then
221 echo "$I: Creating default rndc key file: ${rndc_key_file}." >&2
222 /usr
/sbin
/rndc-confgen
${rndc_cmd_opts}
223 if [ $?
-ne 0 ]; then
224 echo "$I : Warning: rndc configuration failed! Use of 'rndc' to" \
225 "control 'named' may fail and 'named' may report further error" \
226 "messages to the system log. This is not fatal. For more" \
227 "information see rndc(1M) and rndc-confgen(1M)." >&2
232 if [ ${result} = ${SMF_EXIT_OK} ]; then
233 ${checkconf} -z ${checkopts}
235 if [ $result -ne 0 ]; then
236 msg
="$I: named-checkconf failed to verify configuration"
238 /usr
/bin
/logger
-p daemon.error
${msg}
239 if [ "${chroot_dir}" != "" -a "${chroot_dir}" != "/" ]; then
240 umount_chroot
${chroot_dir} ${configuration_files} ${libraries}
242 # dns-server should be placed in maintenance state.
243 exit ${SMF_EXIT_ERR_CONFIG}
247 if [ ${result} = ${SMF_EXIT_OK} ]; then
248 echo "$I: Executing: ${server} ${cmdopts} in '${PWD}'" >&2
249 # Execute named(1M) with relevant command line options. Note
250 # the server forks before reading named.conf(4) and so a
251 # good exit code here does not mean the service is ready.
254 if [ $result -ne 0 ]; then
255 echo "$I : start failed! Check syslog for further information." >&2
258 if [ "${cmduser}" != "" ]; then
260 # Wait for the setuid to complete
262 for N
in 1 1 2 2 4 4 9 9
264 numsec
=`/usr/bin/expr ${numsec} + $N`
266 echo "$I: Process ${cmduser} did not appear"
270 svrpid
=`/usr/bin/pgrep -f -u ${cmduser} /usr/sbin/named`
271 numpids
=`echo ${svrpid} | /usr/bin/wc -l`
272 if [ "${svrpid}" = "" ]; then
275 if [ ${numpids} -eq 1 ]; then
278 if [ ${numpids} -gt 1 ]; then
279 echo "$I: Nameserver is already running"
284 # Set process privileges to allow binding to a privileged port
285 /usr
/bin
/ppriv
-s A
+net_privaddr
${svrpid}
292 smf_kill_contract
${contract} TERM
1
293 [ $?
-ne 0 ] && exit 1
295 if [ "${chroot_dir}" != "" -a "${chroot_dir}" != "/" ]; then
296 umount_chroot
${chroot_dir} ${configuration_files} ${libraries}
301 echo "Usage: $I [stop|start] <instance>" >&2