PATCH: Round 3: RH initscripts backward compatibility
Jim Knoble
jmknoble at jmknoble.cx
Mon Feb 19 21:48:13 EST 2001
Circa 2001-Feb-19 05:45:20 -0500 dixit Jim Knoble:
: Attached is Round 3
Except that the mail client forgot to check for the word 'attach' in
the message text again, and allowed me to send it out attachmentless.
:S
--
jim knoble | jmknoble at jmknoble.cx | http://www.jmknoble.cx/
-------------- next part --------------
--- ./openssh-SNAP-20010219/contrib/redhat/sshd.init.orig-init Mon Nov 13 06:57:27 2000
+++ ./openssh-SNAP-20010219/contrib/redhat/sshd.init Mon Feb 19 05:40:17 2001
@@ -1,5 +1,5 @@
#!/bin/bash
-
+#
# Init file for OpenSSH server daemon
#
# chkconfig: 2345 55 25
@@ -13,105 +13,144 @@
# pidfile: /var/run/sshd.pid
# source function library
-. /etc/rc.d/init.d/functions
+# If the file exists, but is not readable, it's an error.
+# Likewise, if the fallback file doesn't exist, it's an error.
+if [ -f /etc/init.d/sshd-functions ]; then
+ . /etc/init.d/functions
+else
+ . /etc/rc.d/init.d/functions
+fi
+if [ $? -ne 0 ]; then
+ exit 1
+fi
+
+# Define compatibility functions used in this init script
+# If the file exists, but is not readable, it's an error.
+# Likewise, if the fallback file doesn't exist, it's an error.
+if [ -f /etc/init.d/sshd-functions ]; then
+ . /etc/init.d/sshd-functions
+else
+ . /etc/rc.d/init.d/sshd-functions
+fi
+if [ $? -ne 0 ]; then
+ exit 1
+fi
RETVAL=0
-# Some functions to make the below more readable
+PROG=sshd
+SSHD=/usr/sbin/sshd
KEYGEN=/usr/bin/ssh-keygen
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
+LOCKFILE=/var/lock/subsys/sshd
+
+# Define some functions to make the below more readable
+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"
+ if "${KEYGEN}" -q -t rsa1 -f "${RSA1_KEY}" -C '' -N '' \
+ &>/dev/null
+ then
+ my_success "RSA1 key generation"
echo
else
- failure "RSA1 key generation"
+ my_failure "RSA1 key generation"
echo
exit 1
fi
fi
}
-do_rsa_keygen() {
- if ! test -f $RSA_KEY ; then
+
+sshd_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"
+ if "${KEYGEN}" -q -t rsa -f "${RSA_KEY}" -C '' -N '' \
+ &>/dev/null
+ then
+ my_success "RSA key generation"
echo
else
- failure "RSA key generation"
+ my_failure "RSA key generation"
echo
exit 1
fi
fi
}
-do_dsa_keygen() {
- if ! test -f $DSA_KEY ; then
+
+sshd_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"
+ if "${KEYGEN}" -q -t dsa -f "${DSA_KEY}" -C '' -N '' \
+ &>/dev/null
+ then
+ my_success "DSA key generation"
echo
else
- failure "DSA key generation"
+ my_failure "DSA key generation"
echo
exit 1
fi
fi
}
+sshd_start()
+{
+ # Create keys if necessary
+ sshd_do_rsa1_keygen
+ sshd_do_rsa_keygen
+ sshd_do_dsa_keygen
+
+ my_action "Starting ${PROG}: " "${PROG}" "" "${SSHD}"
+ RETVAL=$?
+ [ "${RETVAL}" = 0 ] && touch "${LOCKFILE}"
+}
+
+sshd_stop()
+{
+ echo -n "Stopping ${PROG}: "
+ killproc "${SSHD}"
+ RETVAL=$?
+ echo
+ [ "${RETVAL}" = 0 ] && rm -f "${LOCKFILE}"
+}
+
+sshd_reload()
+{
+ echo -n "Reloading ${PROG}: "
+ killproc "${SSHD}" -HUP
+ RETVAL=$?
+ echo
+}
+
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
+ sshd_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
+ sshd_stop
;;
restart)
- $0 stop
- $0 start
- RETVAL=$?
+ sshd_stop
+ sshd_start
+ ;;
+ reload)
+ sshd_reload
;;
condrestart)
- if [ -f /var/lock/subsys/sshd ] ; then
- $0 stop
- $0 start
- RETVAL=$?
+ if [ -f "${LOCKFILE}" ] ; then
+ sshd_stop
+ sshd_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
+exit ${RETVAL}
--- ./openssh-SNAP-20010219/contrib/redhat/openssh.spec.orig-init Sat Feb 17 23:43:07 2001
+++ ./openssh-SNAP-20010219/contrib/redhat/openssh.spec Mon Feb 19 05:24:02 2001
@@ -57,7 +57,6 @@
Group: System Environment/Daemons
Obsoletes: ssh-server
PreReq: openssh = %{version}-%{release}, chkconfig >= 0.9
-Requires: initscripts >= 4.16
%package askpass
Summary: OpenSSH X11 passphrase dialog
@@ -195,6 +194,7 @@
install -m644 contrib/redhat/sshd.pam-7.x $RPM_BUILD_ROOT/etc/pam.d/sshd
%endif
install -m755 contrib/redhat/sshd.init $RPM_BUILD_ROOT/etc/rc.d/init.d/sshd
+install -m644 contrib/redhat/sshd-functions $RPM_BUILD_ROOT/etc/rc.d/init.d/sshd-functions
%if ! %{no_x11_askpass}
install -s x11-ssh-askpass-%{aversion}/x11-ssh-askpass $RPM_BUILD_ROOT/usr/libexec/openssh/x11-ssh-askpass
@@ -261,6 +261,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
@@ -279,6 +280,9 @@
%endif
%changelog
+* Mon Feb 19 2001 Jim Knoble <jmknoble at jmknoble.cx>
+- Added compatibility functions for sshd initscript in sshd-functions.
+- Removed dependency on initscripts >= 4.16.
* Mon Oct 18 2000 Damien Miller <djm at mindrot.org>
- Merge some of Nalin Dahyabhai <nalin at redhat.com> changes from the
Redhat 7.0 spec file
--- ./openssh-SNAP-20010219/contrib/redhat/sshd-functions.orig-init Mon Feb 19 05:22:40 2001
+++ ./openssh-SNAP-20010219/contrib/redhat/sshd-functions Mon Feb 19 05:22:33 2001
@@ -0,0 +1,83 @@
+#!/bin/bash
+#
+# Compability functions for sshd initscript
+# Parts of my_action() are derived from Red Hat Linux 6.x initscripts.
+
+# Indicate success, using success() function if available;
+# otherwise, use method compatible with initscripts < 4.0
+# (Red Hat Linux <= 5.2).
+# PARAMETERS:
+# $1 => message to pass to success()
+# $2 => message to display in compatibility mode, if different
+# from default of "done"
+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
+}
+
+# Indicate failure, using failure() function if available;
+# otherwise, use method compatible with initscripts < 4.0
+# (Red Hat Linux <= 5.2).
+# PARAMETERS:
+# $1 => message to pass to failure()
+# $2 => message to display in compatibility mode, if different
+# from default of "FAILED"
+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
+}
+
+# Perform an action, using the action() function (which logs output)
+# if available. If unavailable, perform the action and indicate
+# success or failure appropriately.
+# PARAMETERS:
+# $1 => message to display and log in action(), or to display
+# while performing action in compatibility mode
+# $2 => message to display on success in compatibility mode
+# $3 => message to display on failure in compatibility mode
+my_action() {
+ local status
+ local msg="$1"
+ local success_msg="$2"
+ local failure_msg="$3"
+ shift 3
+ case "$(type -type action)" in
+ function)
+ action "${msg}" "$@"
+ status=$?
+ ;;
+ *)
+ echo -n "${msg}"
+ "$@" && my_success "${msg}" "${success_msg}" \
+ || my_failure "${msg}" "${failure_msg}"
+ status=$?
+ echo
+ ;;
+ esac
+ return ${status}
+}
+
More information about the openssh-unix-dev
mailing list