1180740Sdes#!/sbin/sh
2180740Sdes
3180740Sdes#
4180740Sdes# sshd.rc: SSH daemon start-up and shutdown script
5180740Sdes#
6180740Sdes
7180740Sdes# Allowed exit values:
8180740Sdes#	0 = success; causes "OK" to show up in checklist.
9180740Sdes#	1 = failure; causes "FAIL" to show up in checklist.
10180740Sdes#	2 = skip; causes "N/A" to show up in the checklist.
11180740Sdes#           Use this value if execution of this script is overridden
12180740Sdes#	    by the use of a control variable, or if this script is not
13180740Sdes#	    appropriate to execute for some other reason.
14180740Sdes#       3 = reboot; causes the system to be rebooted after execution.
15180740Sdes
16180740Sdes# Input and output:
17180740Sdes#	stdin is redirected from /dev/null
18180740Sdes#
19180740Sdes#	stdout and stderr are redirected to the /etc/rc.log file
20180740Sdes#	during checklist mode, or to the console in raw mode.
21180740Sdes
22180740SdesPATH=/usr/sbin:/usr/bin:/sbin
23180740Sdesexport PATH
24180740Sdes
25180740SdesWHAT='OpenSSH'
26180740SdesWHAT_PATH=/opt/openssh/sbin/sshd
27180740SdesWHAT_PID=/var/run/sshd.pid
28180740SdesWHAT_CONFIG=/etc/rc.config.d/sshd
29180740Sdes
30180740Sdes# NOTE: If your script executes in run state 0 or state 1, then /usr might
31180740Sdes#	not be available.  Do not attempt to access commands or files in
32180740Sdes#	/usr unless your script executes in run state 2 or greater.  Other
33180740Sdes#	file systems typically not mounted until run state 2 include /var
34180740Sdes#	and /opt.
35180740Sdes
36180740Sdesrval=0
37180740Sdes
38180740Sdes# Check the exit value of a command run by this script.  If non-zero, the
39180740Sdes# exit code is echoed to the log file and the return value of this script
40180740Sdes# is set to indicate failure.
41180740Sdes
42180740Sdesset_return() {
43180740Sdes	x=$?
44180740Sdes	if [ $x -ne 0 ]; then
45180740Sdes		echo "EXIT CODE: $x"
46180740Sdes		rval=1	# script FAILed
47180740Sdes	fi
48180740Sdes}
49180740Sdes
50180740Sdescase $1 in
51180740Sdes'start_msg')
52180740Sdes	echo "Starting $WHAT"
53180740Sdes	;;
54180740Sdes
55180740Sdes'stop_msg')
56180740Sdes	echo "Stopping $WHAT"
57180740Sdes	;;
58180740Sdes
59180740Sdes'start')
60180740Sdes	if [ -f $WHAT_CONFIG ] ; then
61180740Sdes		. $WHAT_CONFIG
62180740Sdes	else
63180740Sdes		echo "ERROR: $WHAT_CONFIG defaults file MISSING"
64180740Sdes	fi
65180740Sdes	
66180740Sdes	if [ "$SSHD_START" -eq 1 -a -x "$WHAT_PATH" ]; then
67180740Sdes		$WHAT_PATH $SSHD_ARGS && echo "$WHAT started"
68180740Sdes		set_return
69180740Sdes	else
70180740Sdes		rval=2
71180740Sdes	fi
72180740Sdes	;;
73180740Sdes
74180740Sdes'stop')
75180740Sdes	if kill `cat $WHAT_PID`; then
76180740Sdes		echo "$WHAT stopped"
77180740Sdes	else
78180740Sdes		rval=1
79180740Sdes		echo "Unable to stop $WHAT"
80180740Sdes	fi
81180740Sdes	set_return
82180740Sdes	;;
83180740Sdes
84180740Sdes*)
85180740Sdes	echo "usage: $0 {start|stop|start_msg|stop_msg}"
86180740Sdes	rval=1
87180740Sdes	;;
88180740Sdesesac
89180740Sdes
90180740Sdesexit $rval
91