dealing with RH initscripts backward compatibility

Pekka Savola pekkas at netcore.fi
Sun Feb 18 07:34:26 EST 2001


Hello all,

Continuing the thread:

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

Attached are newer versions of initscripts.  These are smaller and
probably more readable than patches.  Backward compability features
haven't been tested that extensively.

I think the issue of legacy initscripts support should be handled like
with these patches (sshd-functions could be refined, of course), or in
addition:

* in openssh.spec, there would be a %define to enable "backward
compability".  There might even be autodetection for this using
/etc/redhat-release.

* with this defined, sshd-functions would be taken from contrib and
installed in /etc/rc.d/init.d/.

* this would give the implementor of sshd-functions more liberty at how he
could redefine echo/failure/success/action/etc., because he would know
that the changes would only kick in for users using RHL5.2 or earlier
[currently]

With this, there might be no need for the "do we require this" -checks
(~30 first lines of sshd-functions).

What do you think?  IMO, I think the new idea is probably better because
it allows for more freedom when it comes to the implementation.  Also,
there are other issues that will be version-specific (pam, ...).

I could hack the spec file do that.

-- 
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 --------------
#!/bin/bash
#
# Init file for OpenSSH server daemon
#
# chkconfig: 2345 55 25
# description: OpenSSH server daemon
#
# processname: sshd
# config: /etc/ssh/ssh_host_key
# config: /etc/ssh/ssh_host_key.pub
# config: /etc/ssh/ssh_random_seed
# config: /etc/ssh/sshd_config
# pidfile: /var/run/sshd.pid

# source function library
. /etc/rc.d/init.d/functions

# source initscripts backward compatibility functions if they exist
if [ -r /etc/rc.d/init.d/sshd-functions ]; then
  . /etc/rc.d/init.d/sshd-functions
fi

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

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
}

stop()
{
	echo -n $"Stopping $prog: "
	killproc $SSHD
	RETVAL=$?
	echo
	[ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/sshd
}

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"
			echo
		else
			failure $"RSA1 key generation"
			echo
			exit 1
		fi
	fi
}

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"
			echo
		else
			failure $"RSA key generation"
			echo
			exit 1
		fi
	fi
}

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"
			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
-------------- next part --------------
# Backward compability functions for initscripts, parts by Red Hat.

# Find out whether we need to use the local functions
# Unnecessary use should be avoided.

if [ ! "`type -type success`" = "function" ]; then
  success() {
    my_success "$*"
  }
fi

if [ ! "`type -type failure`" = "function" ]; then
  failure() {
    my_failure "$*" 
  }
fi

if [ ! "`type -type action`" = "function" ]; then
  action() {
    my_action "$*" 
  }
fi


case "${BASH_VERSION}" in
  1.*)
    echo() {
      my_echo "$*"
    }
  ;;
esac


# Required for old initscripts < 4.16 or so (RHL5.2)
my_success() {
  local msg
  if [ $# -gt 1 ]; then
    msg="$2"
  else
    msg="done"
  fi
  case "`type -type success`" in
    function)
      success "$1"
    ;;
    *)
      echo -n "${msg}"
    ;;
  esac
}

# Required for old initscripts < 4.16 or so (RHL5.2)
my_failure() {
  local msg
  if [ $# -gt 1 ]; then
    msg="$2"
  else
    msg="FAILED"
  fi
  case "`type -type failure`" in
    function)
      failure "$1"
    ;;
    *)
      echo -n "${msg}"
    ;;
  esac
}

# Required for old initscripts < 4.16 or so (RHL5.2)
my_action() {
  STRING=$1
  echo -n "$STRING "
  shift
  "$*" && success "$STRING" || failure "$STRING"
  rc=$?
  echo
  return $rc
}

# Required for bash1 (RHL6.2 if bash2 package not installed)
my_echo() {
  local args=""
  while [ $# -gt 0 ]; do
    case "$1" in
      --)
	break
        ;;
      -*)
	args="${args} $1"
	shift
        ;;
       *)
	break
        ;;
    esac
  done
  case "${BASH_VERSION}" in
   1.*)
      echo ${args} "$@"
      ;;
     *)
      echo ${args} $"$@"
      ;;
  esac
}
-------------- next part --------------
--- openssh.spec.orig	Sat Feb 17 21:56:43 2001
+++ ossh	Sat Feb 17 21:59:23 2001
@@ -194,6 +194,7 @@
 %else
 install -m644 contrib/redhat/sshd.pam-7.x $RPM_BUILD_ROOT/etc/pam.d/sshd
 %endif
+install -m644 contrib/redhat/sshd-functions $RPM_BUILD_ROOT/etc/rc.d/init.d/sshd-functions
 install -m755 contrib/redhat/sshd.init $RPM_BUILD_ROOT/etc/rc.d/init.d/sshd
 
 %if ! %{no_x11_askpass}
@@ -261,6 +262,7 @@
 %attr(0600,root,root) %config(noreplace) %{_sysconfdir}/sshd_config
 %attr(0600,root,root) %config(noreplace) /etc/pam.d/sshd
 %attr(0755,root,root) %config /etc/rc.d/init.d/sshd
+%attr(0644,root,root) %config /etc/rc.d/init.d/sshd-functions
 
 %if ! %{no_x11_askpass}
 %files askpass


More information about the openssh-unix-dev mailing list