PATCH: make contrib/redhat/sshd.init work with older RH releases

Pekka Savola pekkas at netcore.fi
Sun Feb 18 02:45:09 EST 2001


On Sat, 17 Feb 2001, Damien Miller wrote:
> On Fri, 16 Feb 2001, Pekka Savola wrote:
>
> > Speaking of sshd.init.. I think it might be a good idea to mave some stuff
> > under 'case' to their own functions as Red Hat has done in their own
> > openssh package.
> >
> > Maintainability in both directions would be better, and the file hopefully
> > cleaner.
> >
> > I can volunteer for some merging (in pre-2.5.0 timeline) if this is
> > thought to be desirable.
>
> That would be great, thanks.

Ok, here's my initial work.  I have yet to hear back from RH about my
proposed modifications for their file, but I believe this shouldn't take
too long.

A few highlights:
 - $SSHD used (for path + name) instead of sshd
 - supports RHL'isque i18n in a backward-compatible manner (echo $"...)
 - testing for keys clarified, -s used.
 - start/stop functions used, also 'function' keyword for consistency
 - if [ ! -f $PID_FILE ] check removed.
[This might be a bit controversial, but IMO it doesn't make much
sense for stop, and start exits with errorlevel 0 if it's already running
anyway]
 - add reload (does HUP)

For the curious, my mods for RHL (against 2.3.0p1, mind) are also
attached; its virtues:
 - define locations of ssh-keygen etc.
 - separate keygen functions
 - consistent tabbing/whitespacing in 'case'
 - message for reload, not just '[OK] or '[FAILED]'
 - missing RETVAL for status (I believe there should be one there)

Comments are welcome, of course.

If this doesn't go too badly, I might look a bit into other issues, like
.spec file differences (post-2.5.0p1).

-- 
Pekka Savola                  "Tell me of difficulties surmounted,
Netcore Oy                    not those you stumble over and fall"
Systems. Networks. Security.   -- Robert Jordan: A Crown of Swords
-------------- next part --------------
--- ../../openssh_cvs/contrib/redhat/sshd.init	Mon Nov 13 13:57:27 2000
+++ sshd	Sat Feb 17 17:22:38 2001
@@ -1,5 +1,5 @@
 #!/bin/bash
-
+#
 # Init file for OpenSSH server daemon
 #
 # chkconfig: 2345 55 25
@@ -16,41 +16,67 @@
 . /etc/rc.d/init.d/functions
 
 RETVAL=0
+prog="sshd"
 
 # Some functions to make the below more readable
 KEYGEN=/usr/bin/ssh-keygen
+SSHD=/usr/sbin/sshd
 RSA1_KEY=/etc/ssh/ssh_host_key
 RSA_KEY=/etc/ssh/ssh_host_rsa_key
 DSA_KEY=/etc/ssh/ssh_host_dsa_key
 PID_FILE=/var/run/sshd.pid
-do_rsa1_keygen() {
-	if ! test -f $RSA1_KEY ; then
-		echo -n "Generating SSH1 RSA host key: "
+
+function start()
+{
+	# Create keys if necessary
+	do_rsa1_keygen
+	do_rsa_keygen
+	do_dsa_keygen
+
+	action $"Starting $prog: " $SSHD
+	RETVAL=$?
+	[ "$RETVAL" = 0 ] && touch /var/lock/subsys/sshd
+}
+
+function stop()
+{
+	echo -n $"Stopping $prog: "
+	killproc $SSHD
+	RETVAL=$?
+	echo
+	[ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/sshd
+}
+
+function do_rsa1_keygen() {
+	if [ ! -s $RSA1_KEY ]; then
+		echo -n $"Generating SSH1 RSA host key: "
 		if $KEYGEN -q -t rsa1 -f $RSA1_KEY -C '' -N '' >&/dev/null; then
-			success "RSA1 key generation"
+			success $"RSA1 key generation"
 			echo
 		else
-			failure "RSA1 key generation"
+			failure $"RSA1 key generation"
 			echo
 			exit 1
 		fi
 	fi
 }
-do_rsa_keygen() {
-	if ! test -f $RSA_KEY ; then
-		echo -n "Generating SSH2 RSA host key: "
+
+function do_rsa_keygen() {
+	if [ ! -s $RSA_KEY ]; then
+		echo -n $"Generating SSH2 RSA host key: "
 		if $KEYGEN -q -t rsa -f $RSA_KEY -C '' -N '' >&/dev/null; then
-			success "RSA key generation"
+			success $"RSA key generation"
 			echo
 		else
-			failure "RSA key generation"
+			failure $"RSA key generation"
 			echo
 			exit 1
 		fi
 	fi
 }
-do_dsa_keygen() {
-	if ! test -f $DSA_KEY ; then
+
+function do_dsa_keygen() {
+	if [ ! -s $DSA_KEY ]; then
 		echo -n "Generating SSH2 DSA host key: "
 		if $KEYGEN -q -t dsa -f $DSA_KEY -C '' -N '' >&/dev/null; then
 			success "DSA key generation"
@@ -63,55 +89,36 @@
 	fi
 }
 
+
 case "$1" in
 	start)
-		# Create keys if necessary
-		do_rsa1_keygen;
-		do_rsa_keygen;
-		do_dsa_keygen;
-		
-		echo -n "Starting sshd: "
-		if [ ! -f $PID_FILE ] ; then
-			sshd
-			RETVAL=$?
-			if [ "$RETVAL" = "0" ] ; then
-				success "sshd startup"
-				touch /var/lock/subsys/sshd
-			else
-				failure "sshd startup"
-			fi
-		fi
-		echo
+		start
 		;;
 	stop)
-		echo -n "Shutting down sshd: "
-		if [ -f $PID_FILE ] ; then
-			killproc sshd
-			RETVAL=$?
-			[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sshd
-		fi
-		echo
+		stop
 		;;
 	restart)
-		$0 stop
-		$0 start
+		stop
+		start
+		;;
+	reload)
+		echo -n $"Reloading $prog: " 
+		killproc $SSHD -HUP
 		RETVAL=$?
+		echo
 		;;
 	condrestart)
 		if [ -f /var/lock/subsys/sshd ] ; then
-			$0 stop
-			$0 start
-			RETVAL=$?
+			stop
+			start
 		fi
 		;;
 	status)
-		status sshd
+		status $SSHD
 		RETVAL=$?
 		;;
 	*)
-		echo "Usage: sshd {start|stop|restart|status|condrestart}"
-		exit 1
-		;;
+		echo $"Usage: $0 {start|stop|restart|reload|condrestart|status}"
+		RETVAL=1
 esac
-
 exit $RETVAL
-------------- next part --------------
--- openssh.init	Sat Feb 17 00:10:59 2001
+++ sshd-2.3.0p1.init	Sat Feb 17 10:15:44 2001
@@ -18,16 +18,21 @@
 RETVAL=0
 prog="sshd"
 
+# Some functions to make the below more readable
+KEYGEN=/usr/bin/ssh-keygen
+SSHD=/usr/sbin/sshd
+RSA1_KEY=/etc/ssh/ssh_host_key
+RSA_KEY=/etc/ssh/ssh_host_rsa_key
+DSA_KEY=/etc/ssh/ssh_host_dsa_key
+PID_FILE=/var/run/sshd.pid
+
 function start()
 {
-	if [ ! -s /etc/ssh/ssh_host_key ]; then
-		/usr/bin/ssh-keygen -b 1024 -f /etc/ssh/ssh_host_key -N ""
-	fi
-	if [ ! -s /etc/ssh/ssh_host_dsa_key ]; then
-		/usr/bin/ssh-keygen -d -f /etc/ssh/ssh_host_dsa_key -N ""
-	fi
+	# Create keys if necessary
+	do_rsa1_keygen
+	do_dsa_keygen
 
-	action $"Starting $prog: " /usr/sbin/sshd
+	action $"Starting $prog: " $SSHD
 	RETVAL=$?
 	[ "$RETVAL" = 0 ] && touch /var/lock/subsys/sshd
 }
@@ -35,37 +40,70 @@
 function stop()
 {
 	echo -n $"Stopping $prog: "
-	killproc /usr/sbin/sshd
+	killproc $SSHD
 	RETVAL=$?
 	echo
 	[ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/sshd
 }
 
-case "$1" in
-  start)
-	start
-	;;
-  stop)
-	stop
-	;;
-  restart)
-        stop
-        start
-        ;;
-  reload)
-        killproc /usr/sbin/sshd -HUP
-        ;;
-  condrestart)
-	if [ -f /var/lock/subsys/sshd ] ; then
-        	stop
-        	start
+function do_rsa1_keygen() {
+	if [ ! -s $RSA1_KEY ]; then
+		echo -n $"Generating SSH1 RSA host key: "
+		if $KEYGEN -q -b 1024 -f $RSA1_KEY -C '' -N '' >&/dev/null; then
+			success $"RSA1 key generation"
+			echo
+		else
+			failure $"RSA1 key generation"
+			echo
+			exit 1
+		fi
 	fi
-	;;
-  status)
-        status /usr/sbin/sshd
-        ;;
-  *)
-	echo $"Usage: $0 {start|stop|restart|reload|condrestart|status}"
-	RETVAL=1
+}
+
+function do_dsa_keygen() {
+	if [ ! -s $DSA_KEY ]; then
+		echo -n "Generating SSH2 DSA host key: "
+		if $KEYGEN -q -d -f $DSA_KEY -C '' -N '' >&/dev/null; then
+			success "DSA key generation"
+			echo
+		else
+			failure "DSA key generation"
+			echo
+			exit 1
+		fi
+	fi
+}
+
+
+case "$1" in
+	start)
+		start
+		;;
+	stop)
+		stop
+		;;
+	restart)
+		stop
+		start
+		;;
+	reload)
+		echo -n $"Reloading $prog: " 
+		killproc $SSHD -HUP
+		RETVAL=$?
+		echo
+		;;
+	condrestart)
+		if [ -f /var/lock/subsys/sshd ] ; then
+			stop
+			start
+		fi
+		;;
+	status)
+		status $SSHD
+		RETVAL=$?
+		;;
+	*)
+		echo $"Usage: $0 {start|stop|restart|reload|condrestart|status}"
+		RETVAL=1
 esac
 exit $RETVAL


More information about the openssh-unix-dev mailing list