View | Details | Raw Unified | Return to bug 102489 | Differences between
and this patch

Collapse All | Expand All

(-)Makefile (-28 / +13 lines)
Lines 7-14 Link Here
7
#
7
#
8
8
9
PORTNAME=	dhcp
9
PORTNAME=	dhcp
10
PORTVERSION=	3.0.4
10
PORTVERSION=	3.0.5.r1
11
PORTREVISION=	2
12
CATEGORIES=	net
11
CATEGORIES=	net
13
MASTER_SITES=	${MASTER_SITE_ISC}
12
MASTER_SITES=	${MASTER_SITE_ISC}
14
MASTER_SITE_SUBDIR=	dhcp dhcp/dhcp-3.0-history
13
MASTER_SITE_SUBDIR=	dhcp dhcp/dhcp-3.0-history
Lines 19-26 Link Here
19
MAINTAINER=	Joerg.Pulz@frm2.tum.de
18
MAINTAINER=	Joerg.Pulz@frm2.tum.de
20
COMMENT?=	The ISC Dynamic Host Configuration Protocol server
19
COMMENT?=	The ISC Dynamic Host Configuration Protocol server
21
20
22
USE_RC_SUBR=	yes
23
24
SUBSYS?=	server
21
SUBSYS?=	server
25
22
26
UNIQUENAME=	${PKGNAMEPREFIX}${PORTNAME}${PKGNAMESUFFIX}
23
UNIQUENAME=	${PKGNAMEPREFIX}${PORTNAME}${PKGNAMESUFFIX}
Lines 141-147 Link Here
141
DATA_FILES=	dhclient.leases
138
DATA_FILES=	dhclient.leases
142
.elif ${SUBSYS} == server
139
.elif ${SUBSYS} == server
143
BIN_FILES=	dhcpd omshell
140
BIN_FILES=	dhcpd omshell
144
RC_FILES=	isc-dhcpd
141
USE_RC_SUBR=	isc-dhcpd
145
SAMP_FILES=	server/dhcpd.conf
142
SAMP_FILES=	server/dhcpd.conf
146
DATA_FILES=	dhcpd.leases
143
DATA_FILES=	dhcpd.leases
147
.if defined(WITH_DHCP_LDAP)
144
.if defined(WITH_DHCP_LDAP)
Lines 151-163 Link Here
151
.endif
148
.endif
152
.elif ${SUBSYS} == relay
149
.elif ${SUBSYS} == relay
153
BIN_FILES=	dhcrelay
150
BIN_FILES=	dhcrelay
154
RC_FILES=	isc-dhcrelay
151
USE_RC_SUBR=	isc-dhcrelay
155
.endif
152
.endif
156
153
157
SAMP_SUFX=	.sample
154
SAMP_SUFX=	.sample
158
155
159
CONF_DIR=	${PREFIX}/etc
156
CONF_DIR=	${PREFIX}/etc
160
RC_DIR=		${PREFIX}/etc/rc.d
161
SCHEMA_DIR=	${PREFIX}/share/${PKGBASE}
157
SCHEMA_DIR=	${PREFIX}/share/${PKGBASE}
162
DOCSDIR=	${PREFIX}/share/doc/${PKGBASE}
158
DOCSDIR=	${PREFIX}/share/doc/${PKGBASE}
163
DATADIR=	/var/db
159
DATADIR=	/var/db
Lines 169-189 Link Here
169
PLIST_SUB+=	LDAP="@comment "
165
PLIST_SUB+=	LDAP="@comment "
170
.endif
166
.endif
171
REINPLACE_SUB=	PREFIX=${PREFIX}
167
REINPLACE_SUB=	PREFIX=${PREFIX}
172
RCSCRIPTS_SUB=	PREFIX=${PREFIX} RC_SUBR=${RC_SUBR}
173
.if ${OSVERSION} >= 502100
168
.if ${OSVERSION} >= 502100
174
RCSCRIPTS_SUB+=	NOLOGIN=/usr/sbin/nologin
169
SUB_LIST+=	NOLOGIN=/usr/sbin/nologin
175
.else
170
.else
176
RCSCRIPTS_SUB+=	NOLOGIN=/sbin/nologin
171
SUB_LIST+=	NOLOGIN=/sbin/nologin
177
.endif
172
.endif
178
.if !defined(WITHOUT_DHCP_PARANOIA)
173
.if !defined(WITHOUT_DHCP_PARANOIA)
179
RCSCRIPTS_SUB+=	PARANOIA=YES
174
SUB_LIST+=	PARANOIA=YES
180
.else
175
.else
181
RCSCRIPTS_SUB+=	PARANOIA=NO
176
SUB_LIST+=	PARANOIA=NO
182
.endif
177
.endif
183
.if !defined(WITHOUT_DHCP_JAIL)
178
.if !defined(WITHOUT_DHCP_JAIL)
184
RCSCRIPTS_SUB+=	JAIL=YES
179
SUB_LIST+=	JAIL=YES
185
.else
180
.else
186
RCSCRIPTS_SUB+=	JAIL=NO
181
SUB_LIST+=	JAIL=NO
187
.endif
182
.endif
188
PKGMESSAGE_SUB=	PREFIX="${PREFIX}" MAN1PREFIX="${MAN1PREFIX}" \
183
PKGMESSAGE_SUB=	PREFIX="${PREFIX}" MAN1PREFIX="${MAN1PREFIX}" \
189
		DOCSDIR="${DOCSDIR}" SCHEMA_DIR="${SCHEMA_DIR}"
184
		DOCSDIR="${DOCSDIR}" SCHEMA_DIR="${SCHEMA_DIR}"
Lines 208-214 Link Here
208
post-patch: patch-scripts patch-makefile-conf \
203
post-patch: patch-scripts patch-makefile-conf \
209
	    patch-makefiles-dist patch-man-pages \
204
	    patch-makefiles-dist patch-man-pages \
210
	    patch-pkgmessage patch-site-conf \
205
	    patch-pkgmessage patch-site-conf \
211
	    patch-rc-scripts patch-dlq
206
	    patch-dlq
212
207
213
patch-scripts:
208
patch-scripts:
214
	@${REINPLACE_CMD} ${REINPLACE_SUB:S/$/!g/:S/^/ -e s!%%/:S/=/%%!/} \
209
	@${REINPLACE_CMD} ${REINPLACE_SUB:S/$/!g/:S/^/ -e s!%%/:S/=/%%!/} \
Lines 254-265 Link Here
254
patch-man-pages:
249
patch-man-pages:
255
	@${REINPLACE_CMD} -e '/^\.Fd$$/d' ${WRKSRC}/dhcpctl/dhcpctl.3
250
	@${REINPLACE_CMD} -e '/^\.Fd$$/d' ${WRKSRC}/dhcpctl/dhcpctl.3
256
251
257
patch-rc-scripts:
258
.for f in ${RC_FILES}
259
	@${SED} ${RCSCRIPTS_SUB:S/$/!g/:S/^/ -e s!%%/:S/=/%%!/} \
260
		${FILESDIR}/${f}.sh${SAMP_SUFX} > ${WRKDIR}/${f}.sh
261
.endfor
262
263
patch-pkgmessage:
252
patch-pkgmessage:
264
.if ${SUBSYS} != devel
253
.if ${SUBSYS} != devel
265
	@${SED} ${PKGMESSAGE_SUB:S/$/!g/:S/^/ -e s!%%/:S/=/%%!/} \
254
	@${SED} ${PKGMESSAGE_SUB:S/$/!g/:S/^/ -e s!%%/:S/=/%%!/} \
Lines 283-294 Link Here
283
# Post-install
272
# Post-install
284
#
273
#
285
274
286
POST-INSTALL=	parallel-post-install configure-package display-message
275
POST-INSTALL=	parallel-post-install install-rc-script configure-package \
276
		display-message
287
.ORDER: ${POST-INSTALL}
277
.ORDER: ${POST-INSTALL}
288
post-install: ${POST-INSTALL}
278
post-install: ${POST-INSTALL}
289
279
290
parallel-post-install: \
280
parallel-post-install: \
291
	strip-binary-files install-startup-files \
281
	strip-binary-files \
292
	install-doc-files install-ldap-files install-sample-files \
282
	install-doc-files install-ldap-files install-sample-files \
293
	create-conf-files create-data-files
283
	create-conf-files create-data-files
294
284
Lines 302-312 Link Here
302
.endif
292
.endif
303
.endfor
293
.endfor
304
294
305
install-startup-files:
306
.for f in ${RC_FILES}
307
	@${INSTALL_SCRIPT} ${WRKDIR}/${f}.sh ${RC_DIR}
308
.endfor
309
310
install-doc-files:
295
install-doc-files:
311
.if !defined(NOPORTDOCS)
296
.if !defined(NOPORTDOCS)
312
	@${MKDIR} ${DOCSDIR}
297
	@${MKDIR} ${DOCSDIR}
(-)distinfo (-9 / +9 lines)
Lines 1-9 Link Here
1
MD5 (dhcp-3.0.4.tar.gz) = 004ef935fd54b8046b16bdde31a9e151
1
MD5 (dhcp-3.0.5rc1.tar.gz) = 0e2769a9a883f41c5130f2d3cbbf3a21
2
SHA256 (dhcp-3.0.4.tar.gz) = 89171155b7a9225f5eb81c83ff63f071168b87eacab05fb859b8397d36809bf7
2
SHA256 (dhcp-3.0.5rc1.tar.gz) = b46d94db0c74c8f42c35bc98bec2fac7bcb431b2082f3e8f2541bd5a422e0218
3
SIZE (dhcp-3.0.4.tar.gz) = 883245
3
SIZE (dhcp-3.0.5rc1.tar.gz) = 882983
4
MD5 (dhcp-3.0.4-ldap-patch) = ad88faab5a2d134d7e96e9a984d6535b
4
MD5 (dhcp-3.0.5rc1-ldap-patch) = 53d4e9c657283e4018e68521b35c6a7a
5
SHA256 (dhcp-3.0.4-ldap-patch) = e90aecfd57f4a60fb7775b72a73e637c8b481fea5c34956bf95bd0b39b1441be
5
SHA256 (dhcp-3.0.5rc1-ldap-patch) = 406a8e19fc8407385c350f0f09075721ac0cea342c7ff7fe21d83d68f15c7dc9
6
SIZE (dhcp-3.0.4-ldap-patch) = 154663
6
SIZE (dhcp-3.0.5rc1-ldap-patch) = 285970
7
MD5 (dhcp-3.0.4-dlq-patch) = 0e071945cc986d7ecdfd9b41fc4a102b
7
MD5 (dhcp-3.0.5rc1-dlq-patch) = 0e071945cc986d7ecdfd9b41fc4a102b
8
SHA256 (dhcp-3.0.4-dlq-patch) = c3fd3200eaf00fa80cb37f19bd3b9edb89497c235b5fa594a0f6f60050f64108
8
SHA256 (dhcp-3.0.5rc1-dlq-patch) = c3fd3200eaf00fa80cb37f19bd3b9edb89497c235b5fa594a0f6f60050f64108
9
SIZE (dhcp-3.0.4-dlq-patch) = 7655
9
SIZE (dhcp-3.0.5rc1-dlq-patch) = 7655
(-)pkg-install (-2 / +10 lines)
Lines 9-18 Link Here
9
9
10
case $2 in
10
case $2 in
11
POST-INSTALL)
11
POST-INSTALL)
12
	${PKG_PREFIX}/etc/rc.d/isc-dhcpd.sh forceinstall
12
	if [ ${PKG_PREFIX}/etc/rc.d/isc-dhcpd ]; then
13
		${PKG_PREFIX}/etc/rc.d/isc-dhcpd forceinstall
14
	else
15
		${PKG_PREFIX}/etc/rc.d/isc-dhcpd.sh forceinstall
16
	fi
13
	;;
17
	;;
14
DEINSTALL)
18
DEINSTALL)
15
	${PKG_PREFIX}/etc/rc.d/isc-dhcpd.sh forceuninstall
19
	if [ ${PKG_PREFIX}/etc/rc.d/isc-dhcpd ]; then
20
		${PKG_PREFIX}/etc/rc.d/isc-dhcpd forceuninstall
21
	else
22
		${PKG_PREFIX}/etc/rc.d/isc-dhcpd.sh forceuninstall
23
	fi
16
	;;
24
	;;
17
POST-DEINSTALL|PRE-INSTALL)
25
POST-DEINSTALL|PRE-INSTALL)
18
	;;
26
	;;
(-)pkg-plist (-1 / +2 lines)
Lines 1-8 Link Here
1
@comment $FreeBSD: ports/net/isc-dhcp3-server/pkg-plist,v 1.30 2004/10/13 00:15:01 edwin Exp $
1
@comment $FreeBSD: ports/net/isc-dhcp3-server/pkg-plist,v 1.30 2004/10/13 00:15:01 edwin Exp $
2
@unexec %D/etc/rc.d/isc-dhcpd.sh forcestop 2>/dev/null || true
3
@unexec %D/etc/rc.d/isc-dhcpd forcestop 2>/dev/null || true
2
bin/omshell
4
bin/omshell
3
%%LDAP%%bin/dhcpd-conf-to-ldap.pl
5
%%LDAP%%bin/dhcpd-conf-to-ldap.pl
4
etc/dhcpd.conf.sample
6
etc/dhcpd.conf.sample
5
etc/rc.d/isc-dhcpd.sh
6
sbin/dhcpd
7
sbin/dhcpd
7
%%LDAP%%%%SCHEMA_DIR%%/dhcp.schema
8
%%LDAP%%%%SCHEMA_DIR%%/dhcp.schema
8
%%LDAP%%@dirrm %%SCHEMA_DIR%%
9
%%LDAP%%@dirrm %%SCHEMA_DIR%%
(-)files/isc-dhcpd.in (+722 lines)
Added Link Here
1
#! /bin/sh
2
#
3
# $FreeBSD$
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=${name}_enable
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"
(-)files/isc-dhcpd.sh.sample (-722 lines)
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"
(-)files/isc-dhcrelay.in (+57 lines)
Added Link Here
1
#! /bin/sh
2
#
3
# $FreeBSD$
4
#
5
# PROVIDE: dhcrelay
6
# REQUIRE: DAEMON
7
#
8
# Add the following line to /etc/rc.conf to enable dhcrelay:
9
#
10
# dhcrelay_enable="YES"
11
#
12
13
# override these variables in /etc/rc.conf
14
dhcrelay_enable=${dhcrelay_enable:-"NO"}
15
dhcrelay_flags=${dhcrelay_flags:-}			# command option(s)
16
dhcrelay_servers=${dhcrelay_servers:-}			# dhcrelay server(s)
17
dhcrelay_ifaces=${dhcrelay_ifaces:-}			# ethernet interface(s)
18
19
dhcrelay_precmd ()
20
{
21
	local ifaces
22
23
	dhcrelay_rcconf=%%PREFIX%%/etc/rc.isc-dhcrelay.conf
24
25
	if [ -f ${dhcrelay_rcconf} ]; then
26
		warn "${dhcrelay_rcconf} is obsolete, use /etc/rc.conf instead."
27
		. ${dhcrelay_rcconf}
28
29
		if [ -n "${dhcrelay_options}" -a -z "${rc_flags}" ]; then
30
			warn "dhcrelay_options is obsolete, use dhcrelay_flags instead."
31
			rc_flags=${dhcrelay_options}
32
		fi
33
	fi
34
35
	if [ -z "${dhcrelay_servers}" ]; then
36
		err 1 "no dhcrelay server(s) configured."
37
	fi
38
39
	ifaces=
40
	for iface in ${dhcrelay_ifaces}; do
41
		ifaces="${ifaces} -i ${iface}"
42
	done
43
44
	rc_flags="${rc_flags} ${ifaces} ${dhcrelay_servers}"
45
}
46
47
. %%RC_SUBR%%
48
49
name=dhcrelay
50
rcvar=${name}_enable
51
52
command=%%PREFIX%%/sbin/${name}
53
pidfile=/var/run/${name}.pid
54
start_precmd=${name}_precmd
55
56
load_rc_config ${name}
57
run_rc_command "$1"
(-)files/isc-dhcrelay.sh.sample (-57 lines)
Removed Link Here
1
#! /bin/sh
2
#
3
# $FreeBSD: ports/net/isc-dhcp3-server/files/isc-dhcrelay.sh.sample,v 1.4 2006/02/20 20:47:25 dougb Exp $
4
#
5
# PROVIDE: dhcrelay
6
# REQUIRE: DAEMON
7
#
8
# Add the following line to /etc/rc.conf to enable dhcrelay:
9
#
10
# dhcrelay_enable="YES"
11
#
12
13
# override these variables in /etc/rc.conf
14
dhcrelay_enable=${dhcrelay_enable:-"NO"}
15
dhcrelay_flags=${dhcrelay_flags:-}			# command option(s)
16
dhcrelay_servers=${dhcrelay_servers:-}			# dhcrelay server(s)
17
dhcrelay_ifaces=${dhcrelay_ifaces:-}			# ethernet interface(s)
18
19
dhcrelay_precmd ()
20
{
21
	local ifaces
22
23
	dhcrelay_rcconf=%%PREFIX%%/etc/rc.isc-dhcrelay.conf
24
25
	if [ -f ${dhcrelay_rcconf} ]; then
26
		warn "${dhcrelay_rcconf} is obsolete, use /etc/rc.conf instead."
27
		. ${dhcrelay_rcconf}
28
29
		if [ -n "${dhcrelay_options}" -a -z "${rc_flags}" ]; then
30
			warn "dhcrelay_options is obsolete, use dhcrelay_flags instead."
31
			rc_flags=${dhcrelay_options}
32
		fi
33
	fi
34
35
	if [ -z "${dhcrelay_servers}" ]; then
36
		err 1 "no dhcrelay server(s) configured."
37
	fi
38
39
	ifaces=
40
	for iface in ${dhcrelay_ifaces}; do
41
		ifaces="${ifaces} -i ${iface}"
42
	done
43
44
	rc_flags="${rc_flags} ${ifaces} ${dhcrelay_servers}"
45
}
46
47
. %%RC_SUBR%%
48
49
name=dhcrelay
50
rcvar=$(set_rcvar)
51
52
command=%%PREFIX%%/sbin/${name}
53
pidfile=/var/run/${name}.pid
54
start_precmd=${name}_precmd
55
56
load_rc_config ${name}
57
run_rc_command "$1"
(-)files/patch-server::dhcp.c (-53 lines)
Removed Link Here
1
--- server/dhcp.c.orig	Wed Feb 22 23:43:27 2006
2
+++ server/dhcp.c	Mon May 22 01:39:59 2006
3
@@ -2442,6 +2442,7 @@
4
 		offered_lease_time =
5
 			state -> offered_expiry - cur_time;
6
 
7
+		state -> expiry = 0;
8
 		putULong ((unsigned char *)&state -> expiry,
9
 			  (unsigned long)offered_lease_time);
10
 		i = DHO_DHCP_LEASE_TIME;
11
@@ -2452,7 +2453,7 @@
12
 		if (option_cache_allocate (&oc, MDL)) {
13
 			if (make_const_data (&oc -> expression,
14
 					     (unsigned char *)&state -> expiry,
15
-					     sizeof state -> expiry,
16
+					     4,
17
 					     0, 0, MDL)) {
18
 				oc -> option = dhcp_universe.options [i];
19
 				save_option (&dhcp_universe,
20
@@ -2463,6 +2464,7 @@
21
 
22
 		/* Renewal time is lease time * 0.5. */
23
 		offered_lease_time /= 2;
24
+		state -> renewal = 0;
25
 		putULong ((unsigned char *)&state -> renewal,
26
 			  (unsigned long)offered_lease_time);
27
 		i = DHO_DHCP_RENEWAL_TIME;
28
@@ -2474,7 +2476,7 @@
29
 			if (make_const_data (&oc -> expression,
30
 					     (unsigned char *)
31
 					     &state -> renewal,
32
-					     sizeof state -> renewal,
33
+					     4,
34
 					     0, 0, MDL)) {
35
 				oc -> option = dhcp_universe.options [i];
36
 				save_option (&dhcp_universe,
37
@@ -2486,6 +2488,7 @@
38
 		/* Rebinding time is lease time * 0.875. */
39
 		offered_lease_time += (offered_lease_time / 2
40
 				       + offered_lease_time / 4);
41
+		state -> rebind = 0;
42
 		putULong ((unsigned char *)&state -> rebind,
43
 			  (unsigned)offered_lease_time);
44
 		i = DHO_DHCP_REBINDING_TIME;
45
@@ -2496,7 +2499,7 @@
46
 		if (option_cache_allocate (&oc, MDL)) {
47
 			if (make_const_data (&oc -> expression,
48
 					     (unsigned char *)&state -> rebind,
49
-					     sizeof state -> rebind,
50
+					     4,
51
 					     0, 0, MDL)) {
52
 				oc -> option = dhcp_universe.options [i];
53
 				save_option (&dhcp_universe,

Return to bug 102489