Removed
Link Here
|
1 |
#! /bin/sh |
2 |
# |
3 |
# $FreeBSD: ports/net/isc-dhcp3-server/files/isc-dhcpd.sh.sample,v 1.15 2006/02/20 20:47:25 dougb Exp $ |
4 |
# |
5 |
# PROVIDE: dhcpd |
6 |
# REQUIRE: DAEMON |
7 |
# BEFORE: LOGIN |
8 |
# KEYWORD: shutdown |
9 |
# |
10 |
# Add the following line to /etc/rc.conf to enable dhcpd: |
11 |
# |
12 |
# dhcpd_enable="YES" |
13 |
# |
14 |
|
15 |
. %%RC_SUBR%% |
16 |
|
17 |
name=dhcpd |
18 |
paranoia=%%PARANOIA%% # compiled in paranoia? |
19 |
jail=%%JAIL%% # compiled in jail? |
20 |
|
21 |
load_rc_config $name |
22 |
|
23 |
# override these variables in /etc/rc.conf |
24 |
dhcpd_enable=${dhcpd_enable:-"NO"} |
25 |
dhcpd_flags=${dhcpd_flags:-} # -q -early_chroot # command option(s) |
26 |
dhcpd_conf=${dhcpd_conf:-%%PREFIX%%/etc/${name}.conf} # configuration file |
27 |
dhcpd_ifaces=${dhcpd_ifaces:-} # ethernet interface(s) |
28 |
dhcpd_withumask=${dhcpd_withumask:-022} # file creation mask |
29 |
|
30 |
dhcpd_chuser_enable=${dhcpd_chuser_enable:-"%%PARANOIA%%"} # runs w/o privileges? |
31 |
dhcpd_withuser=${dhcpd_withuser:-${name}} # user name to run as |
32 |
dhcpd_withgroup=${dhcpd_withgroup:-${name}} # group name to run as |
33 |
|
34 |
dhcpd_chroot_enable=${dhcpd_chroot_enable:-"NO"} # runs chrooted? |
35 |
dhcpd_devfs_enable=${dhcpd_devfs_enable:-"YES"} # devfs if available? |
36 |
dhcpd_makedev_enable=${dhcpd_makedev_enable:-"NO"} # MAKEDEV instead of devfs? |
37 |
dhcpd_rootdir=${dhcpd_rootdir:-/var/db/${name}} # directory to run in |
38 |
dhcpd_includedir=${dhcpd_includedir:-} # directory for included config files |
39 |
|
40 |
# untested |
41 |
dhcpd_jail_enable=${dhcpd_jail_enable:-"NO"} # runs imprisoned? |
42 |
dhcpd_hostname=${dhcpd_hostname:-} # jail hostname |
43 |
dhcpd_ipaddress=${dhcpd_ipaddress:-} # jail ip address |
44 |
|
45 |
safe_run () # rc command [args...] |
46 |
{ |
47 |
local _rc |
48 |
|
49 |
_rc=$1 |
50 |
shift |
51 |
|
52 |
if [ "${_rc}" -eq 0 ]; then |
53 |
debug safe_run: "$@" |
54 |
"$@" || _rc=1 |
55 |
else |
56 |
warn safe_run: "$@" |
57 |
fi |
58 |
return ${_rc} |
59 |
} |
60 |
|
61 |
precious () # entry... |
62 |
{ |
63 |
local _entry _rc |
64 |
|
65 |
_rc=0 |
66 |
for _entry; do |
67 |
# do nothing if /dev, /var/run or /var/db |
68 |
echo ${_entry} | egrep -q '^//*(dev|var//*(run|db))?/*$' || _rc=1 |
69 |
done |
70 |
debug precious: "$@" rc=${_rc} |
71 |
return ${_rc} |
72 |
} |
73 |
|
74 |
lsmod () # user group file... |
75 |
{ |
76 |
local _entry _user _group _rc |
77 |
|
78 |
_user=$1 _group=$2 |
79 |
shift 2 |
80 |
|
81 |
_rc=0 |
82 |
for _entry; do |
83 |
ls -ld ${_entry} 2> /dev/null | |
84 |
awk -v u=${_user} -v g=${_group} '{ |
85 |
exit ((u && $3 != u) || (g && $4 != g)) |
86 |
}' || _rc=1 |
87 |
done |
88 |
debug lsmod: "$@" rc=${_rc} |
89 |
return ${_rc} |
90 |
} |
91 |
|
92 |
safe_chmog () # entry... |
93 |
{ |
94 |
local _entry _user _group _usergroup _rc |
95 |
|
96 |
_user=${dhcpd_withuser} |
97 |
_group=${dhcpd_withgroup} |
98 |
|
99 |
_rc=0 |
100 |
if [ -n "${_user}" -o -n "${_group}" ]; then |
101 |
_usergroup=${_user}${_group:+:${_group}} |
102 |
for _entry; do |
103 |
if [ -d ${_entry} ] && mounted ${_entry}; then |
104 |
continue |
105 |
fi |
106 |
if [ -e ${_entry} ] && |
107 |
! precious ${_entry} && |
108 |
! lsmod ${_user} ${_group} ${_entry} && |
109 |
! safe_run ${_rc} chown ${_usergroup} ${_entry}; then |
110 |
warn "unable to change permissions of ${_entry}" |
111 |
_rc=1 |
112 |
fi |
113 |
done |
114 |
fi |
115 |
return ${_rc} |
116 |
} |
117 |
|
118 |
safe_mkdir () # dir... |
119 |
{ |
120 |
local _dir _rc |
121 |
|
122 |
_rc=0 |
123 |
for _dir; do |
124 |
if [ ! -d ${_dir} ] && |
125 |
! precious ${_dir} && |
126 |
! safe_run ${_rc} mkdir -p ${_dir}; then |
127 |
err 1 "unable to create directory ${_dir}" |
128 |
_rc=1 |
129 |
fi |
130 |
done |
131 |
safe_run ${_rc} safe_chmog "$@" || _rc=1 |
132 |
return ${_rc} |
133 |
} |
134 |
|
135 |
safe_rmdir () # dir... |
136 |
{ |
137 |
local _dir _rc |
138 |
|
139 |
_rc=0 |
140 |
for _dir; do |
141 |
if [ -d ${_dir} ] && |
142 |
! precious ${_dir} && |
143 |
! mounted ${_dir}; then |
144 |
if safe_run ${_rc} rmdir ${_dir}; then |
145 |
safe_run ${_rc} safe_rmdir ${_dir%/*} || _rc=1 |
146 |
else |
147 |
warn "unable to remove directory ${_dir}" |
148 |
_rc=1 |
149 |
fi |
150 |
fi |
151 |
done |
152 |
return ${_rc} |
153 |
} |
154 |
|
155 |
safe_touch () # file... |
156 |
{ |
157 |
local _file _rc |
158 |
|
159 |
_rc=0 |
160 |
for _file; do |
161 |
if [ ! -e ${_file} ] && |
162 |
! safe_run ${_rc} touch ${_file}; then |
163 |
err 1 "unable to create file ${_file}" |
164 |
_rc=1 |
165 |
fi |
166 |
done |
167 |
safe_run ${_rc} safe_chmog "$@" || _rc=1 |
168 |
return ${_rc} |
169 |
} |
170 |
|
171 |
safe_remove () # entry... |
172 |
{ |
173 |
local _entry _rc |
174 |
|
175 |
_rc=0 |
176 |
for _entry; do |
177 |
if [ -f ${_entry} ]; then |
178 |
if ! safe_run ${_rc} rm -f ${_entry}; then |
179 |
warn "unable to remove file ${_entry}" |
180 |
_rc=1 |
181 |
fi |
182 |
elif [ -d ${_entry} ] && |
183 |
! precious ${_entry} && |
184 |
! mounted ${_entry}; then |
185 |
if ! safe_run ${_rc} rm -rf ${_entry}; then |
186 |
warn "unable to remove directory ${_entry}" |
187 |
_rc=1 |
188 |
fi |
189 |
fi |
190 |
done |
191 |
return ${_rc} |
192 |
} |
193 |
|
194 |
safe_copy () # src dst |
195 |
{ |
196 |
local _src _dst _rc |
197 |
|
198 |
_src=$1 _dst=$2 |
199 |
|
200 |
_rc=0 |
201 |
if [ -f ${_src} ]; then |
202 |
if ! safe_run ${_rc} safe_remove ${_dst} || |
203 |
! safe_run ${_rc} cp -p ${_src} ${_dst}; then |
204 |
err 1 "unable to copy file ${_src} to ${_dst}" |
205 |
_rc=1 |
206 |
fi |
207 |
safe_run ${_rc} safe_chmog ${_dst} || _rc=1 |
208 |
elif [ -d ${_src} ] && |
209 |
! precious ${_dst} && |
210 |
! mounted ${_dst}; then |
211 |
if ! safe_run ${_rc} pax -rw -pe -ts "|^${_src}||" \ |
212 |
${_src} ${_dst}; then |
213 |
err 1 "unable to copy directory ${_src} to ${_dst}" |
214 |
_rc=1 |
215 |
fi |
216 |
else |
217 |
err 1 "unable to copy ${_src} to ${_dst}" \ |
218 |
"-- not a file or a directory" |
219 |
_rc=1 |
220 |
fi |
221 |
return ${_rc} |
222 |
} |
223 |
|
224 |
mounted () # dir... |
225 |
{ |
226 |
local _rc |
227 |
|
228 |
_rc=1 |
229 |
if checkyesno dhcpd_devfs_enable || |
230 |
checkyesno dhcpd_jail_enable; then |
231 |
mount -t devfs | awk ' |
232 |
BEGIN { n = ARGC; ARGC = 2 } |
233 |
{ for (i = 2; i != n; i++) if ($3 == ARGV[i]) exit 1 } |
234 |
' - "$@" || _rc=0 |
235 |
fi |
236 |
debug mounted: "$@" rc=${_rc} |
237 |
return ${_rc} |
238 |
} |
239 |
|
240 |
safe_mount () # dir |
241 |
{ |
242 |
local _dir _rc |
243 |
|
244 |
_dir=$1 |
245 |
|
246 |
_rc=0 |
247 |
if checkyesno dhcpd_devfs_enable && |
248 |
! mounted ${_dir} && |
249 |
! safe_run ${_rc} mount -t devfs devfs ${_dir}; then |
250 |
err 1 "unable to mount ${_dir}" |
251 |
_rc=1 |
252 |
fi |
253 |
return ${_rc} |
254 |
} |
255 |
|
256 |
safe_umount () # dir |
257 |
{ |
258 |
local _dir _rc |
259 |
|
260 |
_dir=$1 |
261 |
|
262 |
_rc=0 |
263 |
if checkyesno dhcpd_devfs_enable && |
264 |
mounted ${_dir} && |
265 |
! safe_run ${_rc} umount ${_dir}; then |
266 |
warn "unable to unmount ${_dir}" |
267 |
_rc=1 |
268 |
fi |
269 |
return ${_rc} |
270 |
} |
271 |
|
272 |
safe_useradd () |
273 |
{ |
274 |
local _user _group _home _shell _gecos |
275 |
|
276 |
_user=$1 _group=$2 _gecos=${3:-"& daemon"} |
277 |
_home=${4:-/nonexistent} _shell=${5:-%%NOLOGIN%%} |
278 |
|
279 |
if [ -n "${_group}" ]; then |
280 |
if pw group show ${_group} 2>/dev/null; then |
281 |
echo "You already have a group \"${_group}\"," \ |
282 |
"so I will use it." |
283 |
elif pw groupadd ${_group} -h -; then |
284 |
echo "Added group \"${_group}\"." |
285 |
else |
286 |
echo "Adding group \"${_group}\" failed..." |
287 |
echo "Please create it, and try again." |
288 |
exit 1 |
289 |
fi |
290 |
fi |
291 |
if [ -n "${_user}" ]; then |
292 |
if pw user show ${_user} 2>/dev/null; then |
293 |
echo "You already have a user \"${_user}\"," \ |
294 |
"so I will use it." |
295 |
elif pw useradd ${_user} -g ${_group} -h - \ |
296 |
-d ${_home} -s ${_shell} -c "${_gecos}"; then |
297 |
echo "Added user \"${_user}\"." |
298 |
else |
299 |
echo "Adding user \"${_user}\" failed..." |
300 |
echo "Please create it, and try again." |
301 |
exit 1 |
302 |
fi |
303 |
fi |
304 |
} |
305 |
|
306 |
check_chuser () |
307 |
{ |
308 |
if checkyesno paranoia; then |
309 |
if checkyesno dhcpd_chuser_enable && |
310 |
[ -z "${dhcpd_withuser}" -a -z "${dhcpd_withgroup}" ]; then |
311 |
err 1 "one of dhcpd_withuser and dhcpd_withgroup" \ |
312 |
"must be set if dhcpd_chuser_enable is enabled" |
313 |
fi |
314 |
else |
315 |
if checkyesno dhcpd_chuser_enable; then |
316 |
warn "dhcpd_chuser_enable disabled -- not compiled in" |
317 |
dhcpd_chuser_enable=NO |
318 |
fi |
319 |
fi |
320 |
} |
321 |
|
322 |
check_jail () |
323 |
{ |
324 |
if checkyesno paranoia && checkyesno jail; then |
325 |
if checkyesno dhcpd_jail_enable && |
326 |
! checkyesno dhcpd_chroot_enable; then |
327 |
warn "dhcpd_chroot_enable implied by dhcpd_jail_enable" |
328 |
dhcpd_chroot_enable=YES |
329 |
fi |
330 |
if checkyesno dhcpd_jail_enable && |
331 |
[ -n "${dhcpd_hostname}" -a -z "${dhcpd_ipaddress}" ] || |
332 |
[ -z "${dhcpd_hostname}" -a -n "${dhcpd_ipaddress}" ]; then |
333 |
err 1 "both dhcpd_hostname and dhcpd_ipaddress" \ |
334 |
"must be set if dhcpd_jail_enable is enabled" |
335 |
fi |
336 |
else |
337 |
if checkyesno dhcpd_jail_enable; then |
338 |
warn "dhcpd_jail_enable disabled -- not compiled in" |
339 |
dhcpd_jail_enable=NO |
340 |
fi |
341 |
fi |
342 |
} |
343 |
|
344 |
check_chroot () |
345 |
{ |
346 |
if checkyesno paranoia; then |
347 |
if checkyesno dhcpd_chroot_enable; then |
348 |
if [ -z "${dhcpd_rootdir}" ]; then |
349 |
err 1 "dhcpd_rootdir must be set" \ |
350 |
"if dhcpd_chroot_enable is enabled" |
351 |
fi |
352 |
if checkyesno dhcpd_devfs_enable && |
353 |
checkyesno dhcpd_makedev_enable; then |
354 |
err 1 "dhcpd_devfs_enable and dhcpd_makedev_enable" \ |
355 |
"are mutually exclusive. enable only one!" |
356 |
fi |
357 |
if checkyesno dhcpd_devfs_enable && |
358 |
! ( type mount_devfs ) > /dev/null 2>&1; then |
359 |
warn "dhcpd_devfs_enable disabled" \ |
360 |
"-- not available" |
361 |
dhcpd_devfs_enable=NO |
362 |
fi |
363 |
if checkyesno dhcpd_makedev_enable && |
364 |
! [ -x ${__dhcpd_devdir}/MAKEDEV ]; then |
365 |
warn "dhcpd_makedev_enable disabled" \ |
366 |
"-- not available" |
367 |
dhcpd_makedev_enable=NO |
368 |
fi |
369 |
else |
370 |
dhcpd_devfs_enable=NO |
371 |
dhcpd_makedev_enable=NO |
372 |
fi |
373 |
else |
374 |
if checkyesno dhcpd_chroot_enable; then |
375 |
warn "dhcpd_chroot_enable disabled -- not compiled in" |
376 |
dhcpd_chroot_enable=NO |
377 |
fi |
378 |
dhcpd_devfs_enable=NO |
379 |
dhcpd_makedev_enable=NO |
380 |
fi |
381 |
} |
382 |
|
383 |
rcvar_chuser () |
384 |
{ |
385 |
if checkyesno paranoia && checkyesno dhcpd_chuser_enable; then |
386 |
dhcpd_piddir=${__dhcpd_piddir}/${name} |
387 |
dhcpd_leasesdir=${__dhcpd_leasesdir}/${name} |
388 |
else |
389 |
dhcpd_withuser= dhcpd_withgroup= |
390 |
fi |
391 |
} |
392 |
|
393 |
rcvar_jail () |
394 |
{ |
395 |
if ! checkyesno paranoia || ! checkyesno jail || |
396 |
! checkyesno dhcpd_jail_enable; then |
397 |
dhcpd_hostname= dhcpd_ipaddress= |
398 |
fi |
399 |
} |
400 |
|
401 |
rcvar_chroot () |
402 |
{ |
403 |
if ! checkyesno paranoia || ! checkyesno dhcpd_chroot_enable; then |
404 |
dhcpd_rootdir= |
405 |
elif checkyesno paranoia && checkyesno dhcpd_chroot_enable; then |
406 |
dhcpd_devdir=${__dhcpd_devdir} |
407 |
dhcpd_etcdir=${__dhcpd_etcdir} |
408 |
fi |
409 |
} |
410 |
|
411 |
rcvar_pidnleases () |
412 |
{ |
413 |
if ! checkyesno dhcpd_chuser_enable; then |
414 |
dhcpd_piddir=${__dhcpd_piddir} |
415 |
dhcpd_leasesdir=${__dhcpd_leasesdir} |
416 |
fi |
417 |
dhcpd_pidfile=${dhcpd_piddir}/${name}.pid |
418 |
dhcpd_leasesfile=${dhcpd_leasesdir}/${name}.leases |
419 |
dhcpd_conffile=${dhcpd_conf} # for convenience only |
420 |
dhcpd_confdir=$(dirname ${dhcpd_conffile}) |
421 |
} |
422 |
|
423 |
rcvar_rooted () |
424 |
{ |
425 |
_dhcpd_rootdir=${dhcpd_rootdir} |
426 |
_dhcpd_devdir=${dhcpd_rootdir}${dhcpd_devdir} |
427 |
_dhcpd_etcdir=${dhcpd_rootdir}${dhcpd_etcdir} |
428 |
_dhcpd_confdir=${dhcpd_rootdir}${dhcpd_confdir} |
429 |
_dhcpd_includedir=${dhcpd_rootdir}${dhcpd_includedir} |
430 |
_dhcpd_piddir=${dhcpd_rootdir}${dhcpd_piddir} |
431 |
_dhcpd_leasesdir=${dhcpd_rootdir}${dhcpd_leasesdir} |
432 |
_dhcpd_conffile=${dhcpd_rootdir}${dhcpd_conffile} |
433 |
_dhcpd_pidfile=${dhcpd_rootdir}${dhcpd_pidfile} |
434 |
_dhcpd_leasesfile=${dhcpd_rootdir}${dhcpd_leasesfile} |
435 |
} |
436 |
|
437 |
setup_compat () |
438 |
{ |
439 |
local dhcpd_rcconf |
440 |
|
441 |
# suck in old configuration file and variables |
442 |
# |
443 |
dhcpd_rcconf=${dhcpd_confdir}/rc.isc-dhcpd.conf |
444 |
|
445 |
if [ -f ${dhcpd_rcconf} ]; then |
446 |
warn "${dhcpd_rcconf} is obsolete, use /etc/rc.conf and/or" \ |
447 |
"/etc/rc.conf.d/${name} instead." |
448 |
. ${dhcpd_rcconf} |
449 |
|
450 |
if [ -n "${dhcpd_options}" -a -z "${rc_flags}" ]; then |
451 |
warn "dhcpd_options is obsolete," \ |
452 |
"use dhcpd_flags instead." |
453 |
rc_flags=${dhcpd_options} |
454 |
fi |
455 |
fi |
456 |
} |
457 |
|
458 |
setup_umask () |
459 |
{ |
460 |
if [ -n "${dhcpd_withumask}" ]; then |
461 |
umask ${dhcpd_withumask} |
462 |
fi |
463 |
} |
464 |
|
465 |
setup_chroot () |
466 |
{ |
467 |
local _mdev _hconf _hosts _ltime _rconf |
468 |
|
469 |
_mdev=MAKEDEV |
470 |
_hconf=host.conf |
471 |
_hosts=hosts |
472 |
_ltime=localtime |
473 |
_rconf=resolv.conf |
474 |
|
475 |
if checkyesno paranoia && checkyesno dhcpd_chroot_enable; then |
476 |
if ! mounted ${_dhcpd_devdir}; then |
477 |
safe_mkdir ${_dhcpd_devdir}/_ |
478 |
# XXX /_ hack! so, .../dev is root owned. |
479 |
fi |
480 |
safe_mkdir ${_dhcpd_rootdir} ${_dhcpd_etcdir}/_ ${_dhcpd_confdir} |
481 |
# XXX /_ hack! so, .../etc is root owned. |
482 |
if checkyesno dhcpd_devfs_enable; then |
483 |
safe_mount ${_dhcpd_devdir} |
484 |
elif checkyesno dhcpd_makedev_enable; then |
485 |
safe_copy ${dhcpd_devdir}/$_mdev ${_dhcpd_devdir}/$_mdev |
486 |
safe_run 0 sh -c "cd ${_dhcpd_devdir} && ./$_mdev jail bpf4" |
487 |
else |
488 |
safe_copy ${dhcpd_devdir} ${_dhcpd_devdir} |
489 |
fi |
490 |
safe_copy ${dhcpd_conffile} ${_dhcpd_conffile} |
491 |
safe_copy ${dhcpd_etcdir}/$_hconf ${_dhcpd_etcdir}/$_hconf |
492 |
safe_copy ${dhcpd_etcdir}/$_hosts ${_dhcpd_etcdir}/$_hosts |
493 |
safe_copy ${dhcpd_etcdir}/$_ltime ${_dhcpd_etcdir}/$_ltime |
494 |
safe_copy ${dhcpd_etcdir}/$_rconf ${_dhcpd_etcdir}/$_rconf |
495 |
# copy dhcpd_includedir if defined and available |
496 |
if [ -d "${dhcpd_includedir}" ]; then |
497 |
safe_mkdir ${_dhcpd_includedir} |
498 |
safe_copy ${dhcpd_includedir} ${_dhcpd_includedir} |
499 |
fi |
500 |
fi |
501 |
} |
502 |
|
503 |
setup_chuser () |
504 |
{ |
505 |
if checkyesno paranoia && { |
506 |
checkyesno dhcpd_chuser_enable || checkyesno dhcpd_chroot_enable |
507 |
}; then |
508 |
safe_mkdir ${_dhcpd_piddir} ${_dhcpd_leasesdir} |
509 |
fi |
510 |
} |
511 |
|
512 |
setup_leases () |
513 |
{ |
514 |
safe_touch ${_dhcpd_leasesfile} |
515 |
} |
516 |
|
517 |
setup_flags () |
518 |
{ |
519 |
if [ -n "${dhcpd_conf}" ]; then |
520 |
rc_flags="${rc_flags} -cf ${dhcpd_conf}" |
521 |
fi |
522 |
if [ -n "${dhcpd_leasesfile}" ]; then |
523 |
rc_flags="${rc_flags} -lf ${dhcpd_leasesfile}" |
524 |
fi |
525 |
if [ -n "${dhcpd_pidfile}" ]; then |
526 |
rc_flags="${rc_flags} -pf ${dhcpd_pidfile}" |
527 |
fi |
528 |
if [ -n "${dhcpd_withuser}" ]; then |
529 |
rc_flags="${rc_flags} -user ${dhcpd_withuser}" |
530 |
fi |
531 |
if [ -n "${dhcpd_withgroup}" ]; then |
532 |
rc_flags="${rc_flags} -group ${dhcpd_withgroup}" |
533 |
fi |
534 |
if [ -n "${dhcpd_rootdir}" ]; then |
535 |
rc_flags="${rc_flags} -chroot ${dhcpd_rootdir}" |
536 |
fi |
537 |
if [ -n "${dhcpd_hostname}" -a -n "${dhcpd_ipaddress}" ]; then |
538 |
rc_flags="${rc_flags} -jail ${dhcpd_hostname} ${dhcpd_ipaddress}" |
539 |
fi |
540 |
rc_flags="${rc_flags} ${dhcpd_ifaces}" |
541 |
} |
542 |
|
543 |
cleanup_chroot () |
544 |
{ |
545 |
if checkyesno paranoia && checkyesno dhcpd_chroot_enable; then |
546 |
safe_umount ${_dhcpd_devdir} |
547 |
fi |
548 |
} |
549 |
|
550 |
dhcpd_stop () |
551 |
{ |
552 |
if sh $0 forcestatus; then |
553 |
sh $0 forcestop |
554 |
fi |
555 |
} |
556 |
|
557 |
remove_pid () |
558 |
{ |
559 |
if [ -e ${_dhcpd_pidfile} ]; then |
560 |
warn "${_dhcpd_pidfile} still exists! -- removing anyway" |
561 |
fi |
562 |
safe_remove ${_dhcpd_pidfile} |
563 |
} |
564 |
|
565 |
remove_leases () |
566 |
{ |
567 |
if [ -s ${_dhcpd_leasesfile} ]; then |
568 |
warn "${_dhcpd_leasesfile} not empty -- not removed --" \ |
569 |
"futher warning messages expected, don't care." |
570 |
else |
571 |
safe_remove ${_dhcpd_leasesfile} ${_dhcpd_leasesfile}~ |
572 |
fi |
573 |
} |
574 |
|
575 |
remove_chuser () |
576 |
{ |
577 |
if checkyesno paranoia && { |
578 |
checkyesno dhcpd_chuser_enable || checkyesno dhcpd_chroot_enable |
579 |
}; then |
580 |
safe_rmdir ${_dhcpd_piddir} ${_dhcpd_leasesdir} |
581 |
fi |
582 |
} |
583 |
|
584 |
remove_chroot () |
585 |
{ |
586 |
if checkyesno paranoia && checkyesno dhcpd_chroot_enable; then |
587 |
safe_remove ${_dhcpd_conffile} ${_dhcpd_includedir} \ |
588 |
${_dhcpd_etcdir} |
589 |
if checkyesno dhcpd_devfs_enable; then |
590 |
safe_umount ${_dhcpd_devdir} |
591 |
safe_rmdir ${_dhcpd_devdir}/_ # XXX /_ hack! |
592 |
elif checkyesno dhcpd_jail_enable; then |
593 |
if ! mounted ${_dhcpd_devdir}; then |
594 |
safe_remove ${_dhcpd_devdir} |
595 |
fi |
596 |
else |
597 |
safe_remove ${_dhcpd_devdir} |
598 |
fi |
599 |
safe_rmdir ${_dhcpd_confdir} ${_dhcpd_rootdir} # XXX /_ hack! |
600 |
fi |
601 |
} |
602 |
|
603 |
dhcpd_check () |
604 |
{ |
605 |
check_chuser |
606 |
check_jail |
607 |
check_chroot |
608 |
} |
609 |
|
610 |
dhcpd_rcvar () |
611 |
{ |
612 |
rcvar_chuser |
613 |
rcvar_jail |
614 |
rcvar_chroot |
615 |
rcvar_pidnleases |
616 |
rcvar_rooted |
617 |
} |
618 |
|
619 |
dhcpd_precmd () |
620 |
{ |
621 |
setup_compat |
622 |
setup_umask |
623 |
setup_chroot |
624 |
setup_chuser |
625 |
setup_leases |
626 |
setup_flags |
627 |
} |
628 |
|
629 |
dhcpd_postcmd () |
630 |
{ |
631 |
cleanup_chroot |
632 |
} |
633 |
|
634 |
dhcpd_install () |
635 |
{ |
636 |
if checkyesno paranoia; then |
637 |
safe_useradd "${dhcpd_withuser}" "${dhcpd_withgroup}" \ |
638 |
"DHCP Daemon" |
639 |
fi |
640 |
} |
641 |
|
642 |
_dhcpd_uninstall () # user group root |
643 |
{ |
644 |
local _user _group _root |
645 |
|
646 |
_user=$1 _group=$2 _root=$3 |
647 |
|
648 |
if [ -n "${_user}" -o -n "${_group}" ]; then |
649 |
dhcpd_chuser_enable=YES |
650 |
dhcpd_withuser=${_user} |
651 |
dhcpd_withgroup=${_group} |
652 |
else |
653 |
dhcpd_chuser_enable=NO |
654 |
fi |
655 |
if [ -n "${_root}" ]; then |
656 |
dhcpd_chroot_enable=YES |
657 |
dhcpd_rootdir=${_root} |
658 |
else |
659 |
dhcpd_chroot_enable=NO |
660 |
fi |
661 |
dhcpd_check |
662 |
dhcpd_rcvar |
663 |
dhcpd_uninstall |
664 |
} |
665 |
|
666 |
dhcpd_uninstall () |
667 |
{ |
668 |
if checkyesno __dhcpd_uninstall; then |
669 |
dhcpd_stop |
670 |
remove_pid |
671 |
remove_leases |
672 |
remove_chuser |
673 |
remove_chroot |
674 |
else |
675 |
local _user _group _root |
676 |
|
677 |
__dhcpd_uninstall=YES |
678 |
|
679 |
_user=${dhcpd_withuser} |
680 |
_group=${dhcpd_withgroup} |
681 |
_root=${dhcpd_rootdir} |
682 |
|
683 |
_dhcpd_uninstall "" "" "" |
684 |
|
685 |
if checkyesno paranoia; then |
686 |
if [ -n "${_user}" -o -n "${_group}" ]; then |
687 |
_dhcpd_uninstall "${_user}" "${_group}" "" |
688 |
fi |
689 |
if [ -n "${_root}" ]; then |
690 |
_dhcpd_uninstall "" "" "${_root}" |
691 |
fi |
692 |
if [ -n "${_user}" -o -n "${_group}" ] && |
693 |
[ -n "${_root}" ]; then |
694 |
_dhcpd_uninstall "${_user}" "${_group}" "${_root}" |
695 |
fi |
696 |
fi |
697 |
fi |
698 |
} |
699 |
|
700 |
rcvar=$(set_rcvar) |
701 |
load_rc_config ${name} |
702 |
|
703 |
__dhcpd_uninstall="NO" # internal use only |
704 |
__dhcpd_devdir=/dev # devices directory |
705 |
__dhcpd_etcdir=/etc # etc directory |
706 |
__dhcpd_piddir=/var/run # pid file directory |
707 |
__dhcpd_leasesdir=/var/db # leases file directory |
708 |
#__dhcpd_rootdir=/var/db/${name} # root directory |
709 |
|
710 |
dhcpd_check |
711 |
dhcpd_rcvar |
712 |
|
713 |
command=%%PREFIX%%/sbin/${name} |
714 |
pidfile=${_dhcpd_pidfile} |
715 |
required_files=${dhcpd_conf} |
716 |
start_precmd=${name}_precmd |
717 |
stop_postcmd=${name}_postcmd |
718 |
install_cmd=dhcpd_install |
719 |
uninstall_cmd=dhcpd_uninstall |
720 |
extra_commands="install uninstall" |
721 |
|
722 |
run_rc_command "$1" |