summaryrefslogtreecommitdiff
path: root/contrib/caldera/sshd.init
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/caldera/sshd.init')
-rwxr-xr-xcontrib/caldera/sshd.init206
1 files changed, 116 insertions, 90 deletions
diff --git a/contrib/caldera/sshd.init b/contrib/caldera/sshd.init
index 17643391b..e60f8afeb 100755
--- a/contrib/caldera/sshd.init
+++ b/contrib/caldera/sshd.init
@@ -1,99 +1,125 @@
1#! /bin/sh 1#! /bin/bash
2# 2#
3# Generic network daemon RC script. If installed as /etc/rc.d/init.d/foobar, 3# $Id: sshd.init,v 1.2 2001/04/27 05:50:50 tim Exp $
4# it source /etc/sysconfig/daemons/foobar and looks at the
5# variable definitions (Bourne shell syntax). Variables marked with an
6# asterisk are required.
7# 4#
8# * IDENT=sshd 5### BEGIN INIT INFO
9# DESCRIPTIVE="@OPENSSH_VERSION@" 6# Provides:
10# * DAEMON=/usr/sbin/sshd 7# Required-Start: $network
11# DAEMON_ARGS="-p some_other_port" 8# Required-Stop:
12# ONBOOT=yes 9# Default-Start: 3 4 5
10# Default-Stop: 0 1 2 6
11# Description: sshd
12# Bring up/down the OpenSSH secure shell daemon.
13### END INIT INFO
13# 14#
15# Written by Miquel van Smoorenburg <miquels@drinkel.ow.org>.
16# Modified for Debian GNU/Linux by Ian Murdock <imurdock@gnu.ai.mit.edu>.
17# Modified for OpenLinux by Raymund Will <ray@caldera.de>
14 18
15# Source networking configuration. 19NAME=sshd
16. /etc/sysconfig/network 20DAEMON=/usr/sbin/$NAME
17 21# Hack-Alert(TM)! This is necessary to get around the 'reload'-problem
18# Check that networking is up. 22# created by recent OpenSSH daemon/ssd combinations. See Caldera internal
19[ ${NETWORKING} = "no" ] && exit 0 23# PR [linux/8278] for details...
20 24PIDF=/var/run/$NAME.pid
21# Source function library, check sysconfig/daemon file and source it. 25NAME=$DAEMON
22. /etc/rc.d/init.d/functions 26
23 27_status() {
24[ -x $DAEMON ] || exit 0 28 [ -z "$1" ] || local pidf="$1"
25 29 local ret=-1
26# Some functions to make the below more readable 30 local pid
27KEYGEN=/usr/bin/ssh-keygen 31 if [ -n "$pidf" ] && [ -r "$pidf" ]; then
28RSA1_KEY=/etc/ssh/ssh_host_key 32 pid=$(head -1 $pidf)
29RSA_KEY=/etc/ssh/ssh_host_rsa_key 33 else
30DSA_KEY=/etc/ssh/ssh_host_dsa_key 34 pid=$(pidof $NAME)
31PID_FILE=/var/run/sshd.pid 35 fi
32do_rsa1_keygen() { 36
33 if ! test -f $RSA1_KEY ; then 37 if [ ! -e $SVIlock ]; then
34 echo -n "Generating SSH1 RSA host key: " 38 # no lock-file => not started == stopped?
35 if $KEYGEN -q -t rsa1 -f $RSA1_KEY -C '' -N '' >&/dev/null; then 39 ret=3
36 echo "RSA1 key generation success" 40 elif { [ -n "$pidf" ] && [ ! -f "$pidf" ] } || [ -z "$pid" ]; then
37 else 41 # pid-file given but not present or no pid => died, but was not stopped
38 echo "RSA1 key generation failure" 42 ret=2
39 exit 1 43 elif [ -r /proc/$pid/cmdline ] &&
40 fi 44 echo -ne $NAME'\000' | cmp -s - /proc/$pid/cmdline; then
41 fi 45 # pid-file given and present or pid found => check process...
42} 46 # but don't compare exe, as this will fail after an update!
43do_rsa_keygen() { 47 # compares OK => all's well, that ends well...
44 if ! test -f $RSA_KEY ; then 48 ret=0
45 echo -n "Generating SSH2 RSA host key: " 49 else
46 if $KEYGEN -q -t rsa -f $RSA_KEY -C '' -N '' >&/dev/null; then 50 # no such process or exe does not match => stale pid-file or process died
47 echo "RSA key generation success" 51 # just recently...
48 else 52 ret=1
49 echo "RSA key generation failure" 53 fi
50 exit 1 54 return $ret
51 fi
52 fi
53}
54do_dsa_keygen() {
55 if ! test -f $DSA_KEY ; then
56 echo -n "Generating SSH2 DSA host key: "
57 if $KEYGEN -q -t dsa -f $DSA_KEY -C '' -N '' >&/dev/null; then
58 echo "DSA key generation success"
59 else
60 echo "DSA key generation failure"
61 exit 1
62 fi
63 fi
64} 55}
65 56
66# See how we were called. 57# Source function library (and set vital variables).
58. @SVIdir@/functions
59
67case "$1" in 60case "$1" in
68 start) 61 start)
69 # Create keys if necessary 62 [ ! -e $SVIlock ] || exit 0
70 do_rsa1_keygen 63 [ -x $DAEMON ] || exit 5
71 do_rsa_keygen 64 SVIemptyConfig @sysconfdir@/sshd_config && exit 6
72 do_dsa_keygen 65
73 66 if [ ! \( -f @sysconfdir@/ssh_host_key -a \
74 # Start daemons. 67 -f @sysconfdir@/ssh_host_key.pub \) -a \
75 [ ! -e $LOCK ] || exit 1 68 ! \( -f @sysconfdir@/ssh_host_rsa_key -a \
76 echo -n "Starting $SUBSYS services: " 69 -f @sysconfdir@/ssh_host_rsa_key.pub \) -a \
77 start-stop-daemon -S -n $IDENT -x $DAEMON -- $DAEMON_ARGS 70 ! \( -f @sysconfdir@/ssh_host_dsa_key -a \
78 sleep 1 71 -f @sysconfdir@/ssh_host_dsa_key.pub \) ]; then
79 echo . 72
80 touch $LOCK 73 echo "$SVIsubsys: host key not initialized: skipped!"
81 ;; 74 echo "$SVIsubsys: use ssh-host-keygen to generate one!"
82 stop) 75 exit 6
83 # Stop daemons. 76 fi
84 [ -e $LOCK ] || exit 0 77
85 echo -n "Stopping $SUBSYS services: " 78 echo -n "Starting $SVIsubsys services: "
86 start-stop-daemon -K -n $IDENT -x $DAEMON 79 ssd -S -x $DAEMON -n $NAME -- $OPTIONS
87 echo 80 ret=$?
88 rm -f $LOCK 81
89 ;; 82 echo "."
90 restart) 83 touch $SVIlock
91 $0 stop 84 ;;
92 $0 start 85
93 ;; 86 stop)
94 *) 87 [ -e $SVIlock ] || exit 0
95 echo "Usage: $SUBSYS {start|stop|restart}" 88
96 exit 1 89 echo -n "Stopping $SVIsubsys services: "
90 ssd -K -p $PIDF -n $NAME
91 ret=$?
92
93 echo "."
94 rm -f $SVIlock
95 ;;
96
97 force-reload|reload)
98 [ -e $SVIlock ] || exit 0
99
100 echo "Reloading $SVIsubsys configuration files: "
101 ssd -K --signal 1 -q -p $PIDF -n $NAME
102 ret=$?
103 echo "done."
104 ;;
105
106 restart)
107 $0 stop
108 $0 start
109 ret=$?
110 ;;
111
112 status)
113 _status $PIDF
114 ret=$?
115 ;;
116
117 *)
118 echo "Usage: $SVIscript {[re]start|stop|[force-]reload|status}"
119 ret=2
120 ;;
121
97esac 122esac
98 123
99exit 0 124exit $ret
125