xref: /illumos-gate/usr/src/cmd/vntsd/svc-vntsd (revision bbf21555)
328b1e50eSSriharsha Basavapatna# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
41ae08745Sheppo# Use is subject to license terms.
61ae08745Sheppo# CDDL HEADER START
81ae08745Sheppo# The contents of this file are subject to the terms of the
91ae08745Sheppo# Common Development and Distribution License (the "License").
101ae08745Sheppo# You may not use this file except in compliance with the License.
121ae08745Sheppo# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
131ae08745Sheppo# or http://www.opensolaris.org/os/licensing.
141ae08745Sheppo# See the License for the specific language governing permissions
151ae08745Sheppo# and limitations under the License.
171ae08745Sheppo# When distributing Covered Code, include this CDDL HEADER in each
181ae08745Sheppo# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
191ae08745Sheppo# If applicable, add the following below this CDDL HEADER, with the
201ae08745Sheppo# fields enclosed by brackets "[]" replaced with your own identifying
211ae08745Sheppo# information: Portions Copyright [yyyy] [name of copyright owner]
231ae08745Sheppo# CDDL HEADER END
251ae08745Sheppo# Start script for vntsd
271ae08745Sheppo# For modifying parameters passed to vntsd, do not edit
28*bbf21555SRichard Lowe# this script. Instead use svccfg(8) to modify the SMF
291ae08745Sheppo# repository. For example:
311ae08745Sheppo# svccfg
321ae08745Sheppo# svc:> select ldoms/vntsd
331ae08745Sheppo# svc:/ldoms/vntsd> setprop vntsd/vcc_device = "virtual-console-concentrator@1"
341ae08745Sheppo# svc:/ldoms/vntsd> setprop vntsd/listen_addr = ""
3528b1e50eSSriharsha Basavapatna# svc:/ldoms/vntsd> setprop vntsd/authorization="true"
361ae08745Sheppo# svc:/ldoms/vntsd> exit
381ae08745Sheppo. /lib/svc/share/smf_include.sh
4028b1e50eSSriharsha BasavapatnaAUTH_ATTR=/etc/security/auth_attr
4128b1e50eSSriharsha BasavapatnaUSER_ATTR=/etc/user_attr
4228b1e50eSSriharsha BasavapatnaGREP=/usr/bin/grep
4328b1e50eSSriharsha BasavapatnaCAT=/usr/bin/cat
4428b1e50eSSriharsha BasavapatnaED=/usr/bin/ed
4528b1e50eSSriharsha BasavapatnaSVCCFG=/usr/sbin/svccfg
4628b1e50eSSriharsha BasavapatnaSVCPROP=/bin/svcprop
4728b1e50eSSriharsha Basavapatna
4828b1e50eSSriharsha Basavapatna#
4928b1e50eSSriharsha Basavapatna# Add LDoms vntsd authorization entries to etc/security/auth_attr if not
5028b1e50eSSriharsha Basavapatna# present. These define authorizations used by LDoms vntsd daemon.
5128b1e50eSSriharsha Basavapatna#
5228b1e50eSSriharsha Basavapatnaadd_auth_entries()
5328b1e50eSSriharsha Basavapatna{
5428b1e50eSSriharsha Basavapatna	# Add entries to auth_attr file, if needed
5528b1e50eSSriharsha Basavapatna	$GREP '^solaris.vntsd.:' ${AUTH_ATTR} >/dev/null 2>&1
5628b1e50eSSriharsha Basavapatna	if  [ $? -ne 0 ] ; then
5728b1e50eSSriharsha Basavapatna		$CAT >>${AUTH_ATTR} << EOF
5828b1e50eSSriharsha Basavapatna# Added by svc-vntsd
5928b1e50eSSriharsha Basavapatnasolaris.vntsd.:::LDoms vntsd Administration::
6028b1e50eSSriharsha Basavapatnasolaris.vntsd.grant:::Delegate LDoms vntsd Administration::
6128b1e50eSSriharsha Basavapatnasolaris.vntsd.consoles:::Access All LDoms Guest Consoles::
6228b1e50eSSriharsha Basavapatna# End of svc-vntsd
6328b1e50eSSriharsha BasavapatnaEOF
6428b1e50eSSriharsha Basavapatna	fi
6528b1e50eSSriharsha Basavapatna}
6628b1e50eSSriharsha Basavapatna
6728b1e50eSSriharsha Basavapatna#
6828b1e50eSSriharsha Basavapatna# Add a LDoms user/role entry to etc/user_attr if not present.
6928b1e50eSSriharsha Basavapatna# This defines user/role used by useradd or roleadd.
7028b1e50eSSriharsha Basavapatna#
7128b1e50eSSriharsha Basavapatnaadd_user_entries()
7228b1e50eSSriharsha Basavapatna{
7328b1e50eSSriharsha Basavapatna	#
7428b1e50eSSriharsha Basavapatna	# Add entries to user_attr file, if needed.
7528b1e50eSSriharsha Basavapatna	#
7628b1e50eSSriharsha Basavapatna	$GREP 'solaris.vntsd.grant' ${USER_ATTR} >/dev/null 2>&1
7728b1e50eSSriharsha Basavapatna
7828b1e50eSSriharsha Basavapatna	if  [ $? -ne 0 ] ; then
7928b1e50eSSriharsha Basavapatna
8028b1e50eSSriharsha Basavapatna		$GREP '^root' ${USER_ATTR} | $GREP 'auths=' >/dev/null 2>&1
8128b1e50eSSriharsha Basavapatna		if  [ $? -eq 0 ] ; then
8228b1e50eSSriharsha Basavapatna		    #
8328b1e50eSSriharsha Basavapatna		    # Add vntsd attribute to an existing root entry.
8428b1e50eSSriharsha Basavapatna		    #
8528b1e50eSSriharsha Basavapatna		    $ED -s ${USER_ATTR} <<- EOF > /dev/null 2>&1
8628b1e50eSSriharsha Basavapatna			g/^root.*auths\=/s/^roo.*auths\=/&solaris.vntsd.grant,/
8728b1e50eSSriharsha Basavapatna			w
8828b1e50eSSriharsha Basavapatna			q
8928b1e50eSSriharsha Basavapatna			EOF
909f84ea46SAndy Fiddaman		else
9128b1e50eSSriharsha Basavapatna		    #
929f84ea46SAndy Fiddaman		    # Add a root entry with vntsd attribute.
9328b1e50eSSriharsha Basavapatna		    #
9428b1e50eSSriharsha Basavapatna		    $CAT >>${USER_ATTR} << EOF
9528b1e50eSSriharsha Basavapatna# Added by svc-vntsd
9628b1e50eSSriharsha Basavapatnaroot::::type=normal;auths=solaris.vntsd.grant;lock_after_retries=0
9728b1e50eSSriharsha Basavapatna# End of svc-vntsd
9828b1e50eSSriharsha BasavapatnaEOF
9928b1e50eSSriharsha Basavapatna		fi
10028b1e50eSSriharsha Basavapatna	fi
10128b1e50eSSriharsha Basavapatna}
10228b1e50eSSriharsha Basavapatna
10328b1e50eSSriharsha Basavapatna#
10428b1e50eSSriharsha Basavapatna# Update 'vntsd' authorizations in the relevant files. Note that adding these
10528b1e50eSSriharsha Basavapatna# entries from this smf script rather than from the pkg install scripts,
10628b1e50eSSriharsha Basavapatna# ensures that they are added only if the vntsd service is being enabled; and
10728b1e50eSSriharsha Basavapatna# hence avoids adding these entries unnecessarily into client guest domains.
10828b1e50eSSriharsha Basavapatna# The functions check before adding, that the entries are not already present.
10928b1e50eSSriharsha Basavapatna#
11028b1e50eSSriharsha Basavapatnaadd_auth_entries
11128b1e50eSSriharsha Basavapatnaadd_user_entries
11228b1e50eSSriharsha Basavapatna
11328b1e50eSSriharsha Basavapatnavcc_device=`$SVCPROP -p vntsd/vcc_device $SMF_FMRI 2>/dev/null`
1141ae08745Sheppoif [ -z "$vcc_device" ]; then
1151ae08745Sheppo	vcc_device="virtual-console-concentrator@0"
1171ae08745Sheppoargs="-i $vcc_device"
11928b1e50eSSriharsha Basavapatnalisten_addr=`$SVCPROP -p vntsd/listen_addr $SMF_FMRI 2>/dev/null`
1201ae08745Sheppoif [ -n "$listen_addr" ]; then
1211ae08745Sheppo	args="$args -p $listen_addr"
12428b1e50eSSriharsha Basavapatnatimeout=`$SVCPROP -p vntsd/timeout_minutes $SMF_FMRI 2>/dev/null`
1251ae08745Sheppoif [ -n "$timeout" ]; then
1261ae08745Sheppo	args="$args -t $timeout"
12928b1e50eSSriharsha Basavapatnaauth=`$SVCPROP -p vntsd/authorization $SMF_FMRI 2>/dev/null`
13028b1e50eSSriharsha Basavapatnaif [ "$auth" = "true" ]; then
13128b1e50eSSriharsha Basavapatna	args="$args -A"
13228b1e50eSSriharsha Basavapatnafi
13328b1e50eSSriharsha Basavapatna
13425b895bcSZach Kissel#
13525b895bcSZach Kissel# If we don't have a vcc device we don't want to try to start vntsd. By default
13625b895bcSZach Kissel# newer versions of the factory settings will try to start vntsd by default.
13725b895bcSZach Kissel# Since we may be installed on a machine with an older firmware we need to make
13825b895bcSZach Kissel# sure that we don't try to start if the virtual console concentrator is not
13925b895bcSZach Kissel# present.
14025b895bcSZach Kissel#
14125b895bcSZach KisselVNTSD_DEV='/devices/virtual-devices@100/channel-devices@200/virtual-console-concentrator@0:ctl'
14225b895bcSZach Kisselif [ ! -c "$VNTSD_DEV" ]; then
14325b895bcSZach Kissel	echo "The Virtual Network Terminal Server service has been disabled" \
14425b895bcSZach Kissel	    "because the system has no virtual console concentrator (vcc)" \
14525b895bcSZach Kissel	    "device."
14625b895bcSZach Kissel	/usr/sbin/svcadm disable -t "$SMF_FMRI"
14725b895bcSZach Kissel	sleep 5 &
14825b895bcSZach Kissel	exit $SMF_EXIT_OK
14925b895bcSZach Kisselfi
15025b895bcSZach Kissel
1511ae08745Sheppoif [ -x /usr/lib/ldoms/vntsd ]; then
1524d39be2bSsg    /usr/lib/ldoms/vntsd $args
1534d39be2bSsg    rc=$?
1544d39be2bSsg    if [ $rc -ne 0 ]; then
1554d39be2bSsg	# if vntsd exited in error with status 1, let SMF restart it
1564d39be2bSsg	# otherwise we want it to go into maintenance.
1574d39be2bSsg	if [ $rc -eq 1 ]; then
1589f84ea46SAndy Fiddaman	    exit $rc
1594d39be2bSsg	else
1609f84ea46SAndy Fiddaman	    exit $SMF_EXIT_ERR_FATAL
1614d39be2bSsg	fi
1624d39be2bSsg    fi
1641ae08745Sheppo    echo "WARNING: /usr/lib/ldoms/vntsd is missing or not executable" >& 2
1651ae08745Sheppo    exit $SMF_EXIT_ERR_CONFIG
1681ae08745Sheppoexit $SMF_EXIT_OK