blob: ffa7cdac21ff970d3545d860e37ad658382df29d [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
Tim Rice748fcf92002-11-13 15:50:04 -08006umask 022
7
Tim Rice5af9db92004-06-19 19:31:06 -07008CAT=@CAT@
9KILL=@KILL@
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +000010
Tim Rice5af9db92004-06-19 19:31:06 -070011prefix=@prefix@
12sysconfdir=@sysconfdir@
13piddir=@piddir@
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +000014
Ben Lindstrom7a973392001-10-12 21:52:39 +000015SSHD=$prefix/sbin/sshd
Ben Lindstromf2366b52001-10-19 20:36:23 +000016PIDFILE=$piddir/sshd.pid
Ben Lindstrom7a973392001-10-12 21:52:39 +000017SSH_KEYGEN=$prefix/bin/ssh-keygen
Tim Rice5af9db92004-06-19 19:31:06 -070018HOST_KEY_RSA1=$sysconfdir/ssh_host_key
19HOST_KEY_DSA=$sysconfdir/ssh_host_dsa_key
20HOST_KEY_RSA=$sysconfdir/ssh_host_rsa_key
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +000021
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +000022
23checkkeys() {
24 if [ ! -f $HOST_KEY_RSA1 ]; then
Damien Millera8e06ce2003-11-21 23:48:55 +110025 ${SSH_KEYGEN} -t rsa1 -f ${HOST_KEY_RSA1} -N ""
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +000026 fi
27 if [ ! -f $HOST_KEY_DSA ]; then
Damien Millera8e06ce2003-11-21 23:48:55 +110028 ${SSH_KEYGEN} -t dsa -f ${HOST_KEY_DSA} -N ""
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +000029 fi
30 if [ ! -f $HOST_KEY_RSA ]; then
Damien Millera8e06ce2003-11-21 23:48:55 +110031 ${SSH_KEYGEN} -t rsa -f ${HOST_KEY_RSA} -N ""
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +000032 fi
33}
34
35stop_service() {
36 if [ -r $PIDFILE -a ! -z ${PIDFILE} ]; then
Damien Millera8e06ce2003-11-21 23:48:55 +110037 PID=`${CAT} ${PIDFILE}`
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +000038 fi
39 if [ ${PID:=0} -gt 1 -a ! "X$PID" = "X " ]; then
Damien Millera8e06ce2003-11-21 23:48:55 +110040 ${KILL} ${PID}
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +000041 else
Damien Millera8e06ce2003-11-21 23:48:55 +110042 echo "Unable to read PID file"
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +000043 fi
44}
45
46start_service() {
47 # XXX We really should check if the service is already going, but
48 # XXX we will opt out at this time. - Bal
49
50 # Check to see if we have keys that need to be made
51 checkkeys
52
53 # Start SSHD
54 echo "starting $SSHD... \c" ; $SSHD
55
56 sshd_rc=$?
57 if [ $sshd_rc -ne 0 ]; then
Damien Millera8e06ce2003-11-21 23:48:55 +110058 echo "$0: Error ${sshd_rc} starting ${SSHD}... bailing."
59 exit $sshd_rc
Ben Lindstrom8b5ba1c2001-10-12 20:30:52 +000060 fi
61 echo done.
62}
63
64case $1 in
65
66'start')
67 start_service
68 ;;
69
70'stop')
71 stop_service
72 ;;
73
74'restart')
75 stop_service
76 start_service
77 ;;
78
79*)
80 echo "$0: usage: $0 {start|stop|restart}"
81 ;;
82esac