#!/sbin/sh
#	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
#	  All Rights Reserved

#	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
#	The copyright notice above does not evidence any
#	actual or intended publication of such source code.

# 	This file "borrows" some orignal parts of the "rootusr" file.

#ident	"@(#)rootskip	1.4 98/10/05 Sun Microsystems"

# Make sure that the libraries essential
# to this stage of booting can be found.
LD_LIBRARY_PATH=/etc/lib; export LD_LIBRARY_PATH

#
# Sanity check of the current config directory
#
skipdir="/etc/skip/"; export skipdir

arch=`/sbin/skiphost -I 2>/dev/null`

if [ $? != 0 ]
then
	# SKIP is maybe not supported on this system
	#
	skipok=no
else
	if [ -f /kernel/strmod/$arch/skip_es ] && \
				[ -f /kernel/drv/$arch/skip_key ]
	then
		skipok=yes
	else
		skipok=no
	fi
fi

if [ ! -d "$skipdir" ]
then
	echo "WARNING: SKIP config directory $skipdir does not exist"
fi

if [ $skipok = no ]
then
	echo  "WARNING: SKIP not properly installed."
fi

if [ -d "$skipdir" ] && [ $skipok = yes ]
then
#
# SKIP is ok - try to secure the boot window
#

# Instruct the SKIP tools that we are in the boot sequence
#
SKIP_NOCHECK=yes; export SKIP_NOCHECK

#
# Get the list of network interfaces to configure by breaking 
# /etc/hostname.* into separate args by using "." as a shell separator 
# character, then step through args and ifconfig every other arg.
# Set the netmask along the way using local "/etc/netmasks" file.
# This also sets up the streams plumbing for the interface.
# With an empty /etc/hostname.* file this only sets up the streams plumbing
# allowing the ifconfig auto-revarp command will attempt to set the address.
#
interface_names="`echo /etc/hostname.*[0-9] 2>/dev/null`"
if test "$interface_names" != "/etc/hostname.*[0-9]"
then
        (
	IFS="$IFS."
	set `echo /etc/hostname\.*[0-9]`
	while test $# -ge 2
	do
		shift
		if [ "$1" != "xx0" ]; then
			#
			# Plumb the interface
			#
			/sbin/ifconfig $1 plumb

			#
			# Check if SKIP must be plumbed too
			#
			if [ -f "/etc/rc2.d/S63skipes" -a \
				-f "$skipdir/acl.$1" ]; then

				# Check if we will be able to push the SKIP
				# module on this  device
				#
				/sbin/skiphost -i $1 -p >/dev/null
				if [ $? != 0 ]
				then
					echo "WARNING: $1 not in secure mode."
				else
					echo "Adding SKIP on $1."
					/sbin/sh "$skipdir/acl.$1" >/dev/null
				fi
			fi

		fi
		shift
	done
        )
fi

else
	echo "WARNING: system is booted without SKIP."
fi
# end if check config/directory

# Reset the library path now that we are
# past the critical stage.
LD_LIBRARY_PATH=/usr/lib; export LD_LIBRARY_PATH
