Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 1 | #!/sbin/sh |
| 2 | # Donated code that was put under PD license. |
| 3 | # |
| 4 | # Stripped PRNGd out of it for the time being. |
| 5 | |
| 6 | AWK=/usr/bin/awk |
| 7 | CAT=/usr/bin/cat |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 8 | KILL=/usr/bin/kill |
| 9 | PS=/usr/bin/ps |
Ben Lindstrom | f2366b5 | 2001-10-19 20:36:23 +0000 | [diff] [blame^] | 10 | XARGS=/usr/bin/xargs |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 11 | |
Ben Lindstrom | 7a97339 | 2001-10-12 21:52:39 +0000 | [diff] [blame] | 12 | prefix=%%openSSHDir%% |
| 13 | etcdir=%%configDir%% |
Ben Lindstrom | f2366b5 | 2001-10-19 20:36:23 +0000 | [diff] [blame^] | 14 | piddir=%%pidDir%% |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 15 | |
Ben Lindstrom | 7a97339 | 2001-10-12 21:52:39 +0000 | [diff] [blame] | 16 | SSHD=$prefix/sbin/sshd |
Ben Lindstrom | f2366b5 | 2001-10-19 20:36:23 +0000 | [diff] [blame^] | 17 | PIDFILE=$piddir/sshd.pid |
Ben Lindstrom | 7a97339 | 2001-10-12 21:52:39 +0000 | [diff] [blame] | 18 | SSH_KEYGEN=$prefix/bin/ssh-keygen |
| 19 | HOST_KEY_RSA1=$etcdir/ssh_host_key |
| 20 | HOST_KEY_DSA=$etcdir/ssh_host_dsa_key |
| 21 | HOST_KEY_RSA=$etcdir/ssh_host_rsa_key |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 22 | |
| 23 | killproc() { |
| 24 | _procname=$1 |
| 25 | _signal=$2 |
Ben Lindstrom | f2366b5 | 2001-10-19 20:36:23 +0000 | [diff] [blame^] | 26 | ${PS} -u root | ${AWK} '/'"$_procname"'$/ {print $1}' | ${XARGS} ${KILL} |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | |
| 30 | checkkeys() { |
| 31 | if [ ! -f $HOST_KEY_RSA1 ]; then |
Ben Lindstrom | f2366b5 | 2001-10-19 20:36:23 +0000 | [diff] [blame^] | 32 | ${SSH_KEYGEN} -t rsa1 -f ${HOST_KEY_RSA1} -N "" |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 33 | fi |
| 34 | if [ ! -f $HOST_KEY_DSA ]; then |
Ben Lindstrom | f2366b5 | 2001-10-19 20:36:23 +0000 | [diff] [blame^] | 35 | ${SSH_KEYGEN} -t dsa -f ${HOST_KEY_DSA} -N "" |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 36 | fi |
| 37 | if [ ! -f $HOST_KEY_RSA ]; then |
Ben Lindstrom | f2366b5 | 2001-10-19 20:36:23 +0000 | [diff] [blame^] | 38 | ${SSH_KEYGEN} -t rsa -f ${HOST_KEY_RSA} -N "" |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 39 | fi |
| 40 | } |
| 41 | |
| 42 | stop_service() { |
| 43 | if [ -r $PIDFILE -a ! -z ${PIDFILE} ]; then |
Ben Lindstrom | f2366b5 | 2001-10-19 20:36:23 +0000 | [diff] [blame^] | 44 | PID=`${CAT} ${PIDFILE}` |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 45 | fi |
| 46 | if [ ${PID:=0} -gt 1 -a ! "X$PID" = "X " ]; then |
Ben Lindstrom | f2366b5 | 2001-10-19 20:36:23 +0000 | [diff] [blame^] | 47 | ${KILL} ${PID} |
Ben Lindstrom | 8b5ba1c | 2001-10-12 20:30:52 +0000 | [diff] [blame] | 48 | else |
| 49 | echo "Unable to read PID file, killing using alternate method" |
| 50 | killproc sshd TERM |
| 51 | fi |
| 52 | } |
| 53 | |
| 54 | start_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 | |
| 72 | case $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 | ;; |
| 90 | esac |