dealing with RH initscripts backward compatibility

Jim Knoble jmknoble at jmknoble.cx
Sun Feb 18 17:28:06 EST 2001


Circa 2001-Feb-17 22:34:26 +0200 dixit Pekka Savola:

: 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

--------[file: sshd.init]--------

: #!/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

I don't like this at all.  If this file goes away due to filesystem or
operator error, things will unexplainably break.  Having them break
with an immediate message such as:

  bash: /etc/rc.d/init.d/sshd-functions: No such file or directory

is much easier to diagnose.

: fi
: 
: RETVAL=0
: prog="sshd"
: 
: # Some functions to make the below more readable
   /^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  /
You probably mean to move this line down to where the functions are.

: 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()
: {
  [...]
: exit $RETVAL

--------[file: sshd-functions]--------
  
: # 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 "$*"
               /^^^^^^
	      /
No, no no.  Use "$@", not "$*".  "$*" turns multiple arguments into one
argument---this is almost never what you want, and certainly isn't here.
		
:   }
: 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

If you're going to go about things this way, why do you check whether
'success' is a function twice?  Do it above, or here, but not both.

:     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 "
   /^^^^^^^^^^^^^^^^^^^^
  /
my_success() and my_failure() already echo their string .  Why do you
do it again here?

:   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

Again, why do you do this twice?  Pick one.

:    1.*)
:       echo ${args} "$@"
      /^^^^^^
     /
This won't work at all they way you've done things.  echo() is defined
as my_echo(), which calls echo(), which calls ... ad finitum memoriae.

:       ;;
:      *)
:       echo ${args} $"$@"
:       ;;
:   esac
: }

-- 
jim knoble | jmknoble at jmknoble.cx | http://www.jmknoble.cx/





More information about the openssh-unix-dev mailing list