Home | History | Annotate | Download | only in openssh
      1 #!@STARTUP_SCRIPT_SHELL@
      2 # Donated code that was put under PD license.
      3 #
      4 # Stripped PRNGd out of it for the time being.
      5 
      6 umask 022
      7 
      8 CAT=@CAT@
      9 KILL=@KILL@
     10 
     11 prefix=@prefix@
     12 sysconfdir=@sysconfdir@
     13 piddir=@piddir@
     14 
     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
     23 @COMMENT_OUT_ECC@HOST_KEY_ECDSA=$sysconfdir/ssh_host_ecdsa_key
     24 HOST_KEY_ED25519=$sysconfdir/ssh_host_ed25519_key
     25 
     26 
     27 checkkeys() {
     28     if [ ! -f $HOST_KEY_RSA1 ]; then
     29 	${SSH_KEYGEN} -t rsa1 -f ${HOST_KEY_RSA1} -N ""
     30     fi
     31     if [ ! -f $HOST_KEY_DSA ]; then
     32 	${SSH_KEYGEN} -t dsa -f ${HOST_KEY_DSA} -N ""
     33     fi
     34     if [ ! -f $HOST_KEY_RSA ]; then
     35 	${SSH_KEYGEN} -t rsa -f ${HOST_KEY_RSA} -N ""
     36     fi
     37 @COMMENT_OUT_ECC@    if [ ! -f $HOST_KEY_ECDSA ]; then
     38 @COMMENT_OUT_ECC@	${SSH_KEYGEN} -t ecdsa -f ${HOST_KEY_ECDSA} -N ""
     39 @COMMENT_OUT_ECC@    fi
     40     if [ ! -f $HOST_KEY_ED25519 ]; then
     41 	${SSH_KEYGEN} -t ed25519 -f ${HOST_KEY_ED25519} -N ""
     42     fi
     43 }
     44 
     45 stop_service() {
     46     if [  -r $PIDFILE  -a  ! -z ${PIDFILE}  ]; then
     47 	PID=`${CAT} ${PIDFILE}`
     48     fi
     49     if [  ${PID:=0} -gt 1 -a  ! "X$PID" = "X "  ]; then
     50 	${KILL} ${PID}
     51     else
     52 	echo "Unable to read PID file"
     53     fi
     54 }
     55 
     56 start_service() {
     57     # XXX We really should check if the service is already going, but
     58     # XXX we will opt out at this time. - Bal
     59 
     60     # Check to see if we have keys that need to be made
     61     checkkeys
     62 
     63     # Start SSHD
     64     echo "starting $SSHD... \c"         ; $SSHD
     65 
     66     sshd_rc=$?
     67     if [ $sshd_rc -ne 0 ]; then
     68 	echo "$0: Error ${sshd_rc} starting ${SSHD}... bailing."
     69 	exit $sshd_rc
     70     fi
     71     echo done.
     72 }
     73 
     74 case $1 in
     75 
     76 'start')
     77     start_service
     78     ;;
     79 
     80 'stop')
     81     stop_service
     82     ;;
     83 
     84 'restart')
     85     stop_service
     86     start_service
     87     ;;
     88 
     89 *)
     90     echo "$0:  usage:  $0 {start|stop|restart}"
     91     ;;
     92 esac
     93