blob: 212254dc8bcb96fc8a25205080fc96847b14d110 [file] [log] [blame]
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +00001#!/sbin/sh
2# Donated code that was put under PD license.
3#
4# Stripped PRNGd out of it for the time being.
5
6AWK=/usr/bin/awk
7CAT=/usr/bin/cat
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +00008KILL=/usr/bin/kill
9PS=/usr/bin/ps
Ben Lindstromf2366b52001-10-19 20:36:23 +000010XARGS=/usr/bin/xargs
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +000011
Ben Lindstrom7a973392001-10-12 21:52:39 +000012prefix=%%openSSHDir%%
13etcdir=%%configDir%%
Ben Lindstromf2366b52001-10-19 20:36:23 +000014piddir=%%pidDir%%
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +000015
Ben Lindstrom7a973392001-10-12 21:52:39 +000016SSHD=$prefix/sbin/sshd
Ben Lindstromf2366b52001-10-19 20:36:23 +000017PIDFILE=$piddir/sshd.pid
Ben Lindstrom7a973392001-10-12 21:52:39 +000018SSH_KEYGEN=$prefix/bin/ssh-keygen
19HOST_KEY_RSA1=$etcdir/ssh_host_key
20HOST_KEY_DSA=$etcdir/ssh_host_dsa_key
21HOST_KEY_RSA=$etcdir/ssh_host_rsa_key
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +000022
23killproc() {
24 _procname=$1
25 _signal=$2
Ben Lindstromf2366b52001-10-19 20:36:23 +000026 ${PS} -u root | ${AWK} '/'"$_procname"'$/ {print $1}' | ${XARGS} ${KILL}
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +000027}
28
29
30checkkeys() {
31 if [ ! -f $HOST_KEY_RSA1 ]; then
Ben Lindstromf2366b52001-10-19 20:36:23 +000032 ${SSH_KEYGEN} -t rsa1 -f ${HOST_KEY_RSA1} -N ""
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +000033 fi
34 if [ ! -f $HOST_KEY_DSA ]; then
Ben Lindstromf2366b52001-10-19 20:36:23 +000035 ${SSH_KEYGEN} -t dsa -f ${HOST_KEY_DSA} -N ""
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +000036 fi
37 if [ ! -f $HOST_KEY_RSA ]; then
Ben Lindstromf2366b52001-10-19 20:36:23 +000038 ${SSH_KEYGEN} -t rsa -f ${HOST_KEY_RSA} -N ""
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +000039 fi
40}
41
42stop_service() {
43 if [ -r $PIDFILE -a ! -z ${PIDFILE} ]; then
Ben Lindstromf2366b52001-10-19 20:36:23 +000044 PID=`${CAT} ${PIDFILE}`
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +000045 fi
46 if [ ${PID:=0} -gt 1 -a ! "X$PID" = "X " ]; then
Ben Lindstromf2366b52001-10-19 20:36:23 +000047 ${KILL} ${PID}
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +000048 else
49 echo "Unable to read PID file, killing using alternate method"
50 killproc sshd TERM
51 fi
52}
53
54start_service() {
55 # XXX We really should check if the service is already going, but
56 # XXX we will opt out at this time. - Bal
57
58 # Check to see if we have keys that need to be made
59 checkkeys
60
61 # Start SSHD
62 echo "starting $SSHD... \c" ; $SSHD
63
64 sshd_rc=$?
65 if [ $sshd_rc -ne 0 ]; then
66 echo "$0: Error ${sshd_rc} starting ${SSHD}... bailing."
67 exit $sshd_rc
68 fi
69 echo done.
70}
71
72case $1 in
73
74'start')
75 start_service
76 ;;
77
78'stop')
79 stop_service
80 ;;
81
82'restart')
83 stop_service
84 start_service
85 ;;
86
87*)
88 echo "$0: usage: $0 {start|stop|restart}"
89 ;;
90esac