- (dtucker) [platform.c session.c] Move the PAM credential establishment for
[openssh-git.git] / opensshd.init.in
blobd0aff7794873d6460ee134df33932105cf20c9b0
1 #!@STARTUP_SCRIPT_SHELL@
2 # Donated code that was put under PD license.
4 # Stripped PRNGd out of it for the time being.
6 umask 022
8 CAT=@CAT@
9 KILL=@KILL@
11 prefix=@prefix@
12 sysconfdir=@sysconfdir@
13 piddir=@piddir@
15 SSHD=$prefix/sbin/sshd
16 PIDFILE=$piddir/sshd.pid
17 PidFile=`grep "^PidFile" ${sysconfdir}/sshd_config | tr "=" " " | awk '{print $2}'`
18 [ X$PidFile = X ]  ||  PIDFILE=$PidFile
19 SSH_KEYGEN=$prefix/bin/ssh-keygen
20 HOST_KEY_RSA1=$sysconfdir/ssh_host_key
21 HOST_KEY_DSA=$sysconfdir/ssh_host_dsa_key
22 HOST_KEY_RSA=$sysconfdir/ssh_host_rsa_key
25 checkkeys() {
26     if [ ! -f $HOST_KEY_RSA1 ]; then
27         ${SSH_KEYGEN} -t rsa1 -f ${HOST_KEY_RSA1} -N ""
28     fi
29     if [ ! -f $HOST_KEY_DSA ]; then
30         ${SSH_KEYGEN} -t dsa -f ${HOST_KEY_DSA} -N ""
31     fi
32     if [ ! -f $HOST_KEY_RSA ]; then
33         ${SSH_KEYGEN} -t rsa -f ${HOST_KEY_RSA} -N ""
34     fi
37 stop_service() {
38     if [  -r $PIDFILE  -a  ! -z ${PIDFILE}  ]; then
39         PID=`${CAT} ${PIDFILE}`
40     fi
41     if [  ${PID:=0} -gt 1 -a  ! "X$PID" = "X "  ]; then
42         ${KILL} ${PID}
43     else
44         echo "Unable to read PID file"
45     fi
48 start_service() {
49     # XXX We really should check if the service is already going, but
50     # XXX we will opt out at this time. - Bal
52     # Check to see if we have keys that need to be made
53     checkkeys
55     # Start SSHD
56     echo "starting $SSHD... \c"         ; $SSHD
58     sshd_rc=$?
59     if [ $sshd_rc -ne 0 ]; then
60         echo "$0: Error ${sshd_rc} starting ${SSHD}... bailing."
61         exit $sshd_rc
62     fi
63     echo done.
66 case $1 in
68 'start')
69     start_service
70     ;;
72 'stop')
73     stop_service
74     ;;
76 'restart')
77     stop_service
78     start_service
79     ;;
82     echo "$0:  usage:  $0 {start|stop|restart}"
83     ;;
84 esac