#!/bin/sh
#
#pragma ident  "@(#)issec	1.9 96/08/01 SMI"
#
# Copyright (c) 1995 by Sun Microsystems, Inc.
#
# ISDN PPP -- security daemon start/stop script
#

BASEDIR=/opt/SUNWisdn
CONFDIR=/etc/opt/SUNWisdn
LOGDIR=/var/opt/SUNWisdn

BINDIR=$BASEDIR/bin
LIBDIR=$BASEDIR/lib
CONFFILE=$CONFDIR/isppp.cf
LOGFILE=$LOGDIR/log
PARADIGM=$BINDIR/paradigm
binding_domain=al4
SECURED=$BINDIR/secured

DISPLAY=:0.0
export DISPLAY

PATH=$PATH:$BINDIR
export PATH
#
# Bugid: 1260941 (XXXML)
# Solaris 2.3: no /usr/lib/libX11.so.4 (in /usr/openwin/lib)
#
issec_add_path() {
	if [ `uname -r` != "5.3" ]; then
		return
	fi
	LIB_PATH=/usr/openwin/lib
	L_PATH=`echo $LD_LIBRARY_PATH |grep $LIB_PATH`
	if [ -z "$L_PATH" ]; then
		if [ -z "$LD_LIBRARY_PATH" ] ; then
			LD_LIBRARY_PATH=$LIB_PATH
		else
			LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIB_PATH
		fi
	fi
	export LD_LIBRARY_PATH
}

REQ_FILES="$SECURED"

mode=$1

set `id`
if [ $1 != "uid=0(root)" ]; then
	echo "$0: this script must be run as root ... fatal error"
	exit 1
fi

for FILE in $REQ_FILES; do
	if [ ! -f $FILE ]; then
		echo "$0: ISDN PPP has been installed but"
		echo "not configured correctly"
		echo "$0: $FILE not found"
		echo "$0: please refer to the ISDN documentation"
		exit 1
	fi
done

# check if secured is running
check_if_running() {
	pid=`/bin/ps -ef | egrep secured | egrep -v egrep |awk '{print $2}'`
}

case "$mode" in
'start')
# Start secured
	check_if_running
	if test -n "$pid"; then
		echo "secured is already running. Please invoke issec stop"
		exit 1
	fi

	issec_add_path
	$SECURED &
       	;; 

'debug')
# Start secured with -d 9
	check_if_running
	if test -n "$pid"; then
		echo "secured is already running. Please invoke issec stop"
		exit 1
	fi

	issec_add_path
	$SECURED -d 9 &
       	;; 

'stop')
# Stop secured
	check_if_running
	if test -n "$pid"; then
		kill -KILL $pid
		echo "secured stopped"
        else
                echo "secured is not running"
		exit 1
	fi
       	;; 


*)	# usage
	echo "usage: $0 start|debug|stop"
	exit 1
	;;

esac  
