xref: /titanic_41/usr/src/cmd/tsol/labeld/svc-labeld (revision 7800901e60d340b6af88e94a2149805dcfcaaf56)
1#!/sbin/sh
2#
3# CDDL HEADER START
4#
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.
8#
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.
13#
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]
19#
20# CDDL HEADER END
21#
22# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23# Use is subject to license terms.
24#
25#ident	"%Z%%M%	%I%	%E% SMI"
26
27. /lib/svc/share/smf_include.sh
28
29ROOT_PATH=""
30if [ $# -gt 1 ]; then
31	if [ $# -ne 3 -o "$2" != "-R" ]; then
32		echo "$0: invalid syntax"
33		exit $SMF_EXIT_ERR_CONFIG
34	fi
35	if [ "$3" != "/" ]; then
36		ROOT_PATH=$3
37	fi
38fi
39if [ -n "$ROOT_PATH" -a "$1" != "start" ]; then
40	echo "$0: invalid syntax: -R allowed for start method only"
41	exit $SMF_EXIT_ERR_CONFIG
42fi
43if [ -n "$ROOT_PATH" -a ! -d "$ROOT_PATH" ]; then
44	echo "$0: invalid -R rootpath dir specified"
45	exit $SMF_EXIT_ERR_CONFIG
46fi
47
48if smf_is_nonglobalzone; then
49	echo "$0: not supported in a local zone"
50	exit $SMF_EXIT_ERR_CONFIG
51fi
52
53do_logindev()
54{
55	# Comment out audio and usb device entries in /etc/logindevperm.
56	LOGINDEVPERM=$ROOT_PATH/etc/logindevperm
57	if [ -f $LOGINDEVPERM ]; then
58		line="\/dev\/console	0600	\/dev\/sound\/\*"
59		sed -e "s/^$line/#$line/" $LOGINDEVPERM > /tmp/tmp.$$
60		cp /tmp/tmp.$$ $LOGINDEVPERM
61		line="\/dev\/console	0600	\/dev\/usb\/\[0-9a-f\]+\[.\]\[0-9a-f\]+\/\[0-9\]+\/\*"
62		sed -e "s/^$line/#$line/" $LOGINDEVPERM > /tmp/tmp.$$
63		cp /tmp/tmp.$$ $LOGINDEVPERM
64		rm -f /tmp/tmp.$$
65	fi
66}
67
68do_otherservices()
69{
70	# Setup dependent services
71	cat >> $ROOT_PATH/var/svc/profile/upgrade <<\__ENABLE_OTHERS
72		/usr/sbin/svcadm enable -s svc:/network/tnd:default
73		/usr/sbin/svcadm enable -s svc:/system/tsol-zones:default
74		/usr/sbin/svccfg -s svc:/application/x11/x11-server \
75		    setprop options/tcp_listen = true
76		/usr/sbin/svcadm enable svc:/network/rpc/rstat:default
77__ENABLE_OTHERS
78
79}
80
81do_bsmconv()
82{
83	# Run bsmconv so audit and device allocation is enabled by
84	# default with Trusted Extensions.
85	if [ "$ROOT_PATH" = "/" -o "$ROOT_PATH" = "" ]; then
86		BSMDIR=""
87	else
88		BSMDIR=$ROOT_PATH
89	fi
90	echo "Running bsmconv ..."
91	echo `TEXTDOMAIN="SUNW_OST_OSCMD" gettext "y"` | \
92	    $ROOT_PATH/etc/security/bsmconv $ROOT_PATH
93}
94
95do_nscd()
96{
97# For Trusted Extensions, make nscd service transient in local zones.
98cat >> $ROOT_PATH/var/svc/profile/upgrade <<\_DEL_LOCAL_NSCD
99	if [ `/sbin/zonename` != "global" ]; then
100		nscd="svc:/system/name-service-cache"
101		duration=""
102		if /bin/svcprop -q -c -p startd/duration $nscd ; then
103			duration=`/bin/svcprop -c -p startd/duration $nscd`
104		fi
105		if [ "$duration" != "transient" ]; then
106			/usr/sbin/svccfg -s $nscd addpg startd framework
107			/usr/sbin/svccfg -s $nscd setprop \
108			    startd/duration = astring: transient
109			/usr/sbin/svccfg -s $nscd setprop stop/exec = :true
110			/usr/sbin/svcadm refresh $nscd
111		fi
112	fi
113_DEL_LOCAL_NSCD
114}
115
116do_bootupd()
117{
118	if [ -f $ROOT_PATH/platform/`/sbin/uname -m`/boot_archive ]; then
119		if [ -z "$ROOT_PATH" -o "$ROOT_PATH" = "/" ]; then
120			/sbin/bootadm update-archive
121		else
122			/sbin/bootadm update-archive -R $ROOT_PATH
123		fi
124	fi
125}
126
127do_commonstart()
128{
129	echo "$0: Updating $ROOT_PATH/etc/system..."
130	if [ ! -f ${ROOT_PATH}/etc/system ]; then
131		touch ${ROOT_PATH}/etc/system
132	fi
133
134	# Set sys_labeling in etc/system
135	grep -v "sys_labeling=" ${ROOT_PATH}/etc/system > /tmp/etc.system.$$
136	echo "set sys_labeling=1" >> /tmp/etc.system.$$
137	mv /tmp/etc.system.$$ ${ROOT_PATH}/etc/system
138	grep "set sys_labeling=1" ${ROOT_PATH}/etc/system > /dev/null 2>&1
139	if [ $? -ne 0 ]; then
140    		echo "$0: ERROR: cannot set sys_labeling in $ROOT_PATH/etc/system"
141		exit $SMF_EXIT_ERR_FATAL
142	fi
143
144	do_bootupd
145
146	# Setup dependent services
147	do_otherservices
148
149	do_logindev
150	do_bsmconv
151	do_nscd
152}
153
154
155daemon_start()
156{
157	# If a labeld door exists, check for a labeld process and exit
158	# if the daemon is already running.
159	if [ -r /var/tsol/doors/labeld ]; then
160		if /usr/bin/pgrep -x -u 0 -P 1 labeld >/dev/null 2>&1; then
161			echo "$0: labeld is already running"
162			exit $SMF_EXIT_ERR_FATAL
163		fi
164	fi
165	/usr/bin/rm -f /var/tsol/doors/labeld
166	/usr/lib/labeld
167}
168
169PATH=/usr/sbin:/usr/bin; export PATH
170
171case "$1" in
172'start')
173	if [ -z "$ROOT_PATH" -o "$ROOT_PATH" = "/" ]; then
174		# native
175
176		if [ -z "$SMF_FMRI" ]; then
177			echo "$0: this script can only be invoked by smf(5)"
178			exit $SMF_EXIT_ERR_NOSMF
179		fi
180
181		tx_enabled=`/usr/bin/svcprop -c -p general/enabled $SMF_FMRI`
182		if [ "$tx_enabled" = "false" ]; then
183			# A sign of trying temporary enablement...no-no
184			echo "$0: Temporarily enabling Trusted Extensions is not allowed."
185			exit $SMF_EXIT_ERR_CONFIG
186		fi
187
188		if (smf_is_system_labeled); then
189			daemon_start
190			exit $SMF_EXIT_OK
191		fi
192
193		# Make changes to enable Trusted Extensions
194		grep "^set sys_labeling=1" ${ROOT_PATH}/etc/system > /dev/null 2>&1
195		if [ $? -eq 0 ]; then
196			echo "$0: already enabled. Exiting."
197			exit $SMF_EXIT_OK
198		fi
199
200		if [ "`/usr/sbin/zoneadm list -c`" != "global" ]; then
201			echo "$0: Must remove zones before enabling Trusted Extensions."
202			exit $SMF_EXIT_ERR_CONFIG
203		fi
204
205		do_commonstart
206
207		# start daemon proccess so our service doesn't go into
208		# maintenance state
209		daemon_start
210
211		echo "$0: Started.  Must reboot and configure Trusted Extensions."
212	else
213		# Support jumpstart etc
214
215		# Make changes to enable Trusted Extensions
216		grep "^set sys_labeling=1" ${ROOT_PATH}/etc/system > /dev/null 2>&1
217		if [ $? -eq 0 ]; then
218			echo "$0: already enabled. Exiting."
219			exit $SMF_EXIT_OK
220		fi
221
222		# Setup dependent services
223		cat >> $ROOT_PATH/var/svc/profile/upgrade <<\__TRUSTED_ENABLE
224			/usr/sbin/svcadm enable -s svc:/system/labeld:default
225__TRUSTED_ENABLE
226
227		do_commonstart
228		echo "$0: Started.  Must configure Trusted Extensions before booting."
229	fi
230	;;
231
232'stop')
233	tx_enabled=`/usr/bin/svcprop -c -p general/enabled $SMF_FMRI`
234	if [ "$tx_enabled" = "true" ]; then
235		/usr/bin/pkill -x -u 0 -P 1 -z `smf_zonename` labeld
236		exit $SMF_EXIT_OK
237	fi
238
239	if [ "`/usr/sbin/zoneadm list -c`" != "global" ]; then
240		echo "$0: Must remove zones before disabling Trusted Extensions."
241		exit $SMF_EXIT_ERR_CONFIG
242	fi
243
244	# Stop Trusted services.
245	/usr/sbin/svcadm disable svc:/system/tsol-zones:default 2>/dev/null
246	/usr/sbin/svcadm disable svc:/network/tnd:default 2>/dev/null
247
248	# Uncomment audio and usb device entries in /etc/logindevperm.
249	LOGINDEVPERM=$ROOT_PATH/etc/logindevperm
250	if [ -f $LOGINDEVPERM ]; then
251		line="\/dev\/console	0600	\/dev\/sound\/\*"
252		sed -e "s/^#$line/$line/" $LOGINDEVPERM > /tmp/tmp.$$
253		cp /tmp/tmp.$$ $LOGINDEVPERM
254		line="\/dev\/console	0600	\/dev\/usb\/\[0-9a-f\]+\[.\]\[0-9a-f\]+\/\[0-9\]+\/\*"
255		sed -e "s/^#$line/$line/" $LOGINDEVPERM > /tmp/tmp.$$
256		cp /tmp/tmp.$$ $LOGINDEVPERM
257		rm -f /tmp/tmp.$$
258	fi
259
260	# Remove sys_labeling from /etc/system
261	grep -v "sys_labeling" ${ROOT_PATH}/etc/system > /tmp/etc.system.$$
262	mv /tmp/etc.system.$$ ${ROOT_PATH}/etc/system
263	grep "sys_labeling" ${ROOT_PATH}/etc/system > /dev/null 2>&1
264	if [ $? -eq 0 ]; then
265    		echo "$0: ERROR: cannot remove sys_labeling in $ROOT_PATH/etc/system"
266		exit $SMF_EXIT_ERR_FATAL
267	fi
268
269	do_bootupd
270
271	/usr/bin/pkill -x -u 0 -P 1 -z `smf_zonename` labeld
272	echo "$0: Stopped.  Will take effect at next boot."
273	;;
274
275*)
276	echo "Usage: $0 { start | stop }"
277	exit 1
278	;;
279esac
280
281exit $SMF_EXIT_OK
282
283