Index: rc.subr =================================================================== RCS file: /home/ncvs/src/etc/rc.subr,v retrieving revision 1.50 diff -u -r1.50 rc.subr --- rc.subr 23 Mar 2006 16:48:32 -0000 1.50 +++ rc.subr 29 Mar 2006 16:21:03 -0000 @@ -1,7 +1,7 @@ -# $NetBSD: rc.subr,v 1.60 2003/07/26 05:13:47 lukem Exp $ +# $NetBSD: rc.subr,v 1.65 2004/10/12 14:45:29 lukem Exp $ # $FreeBSD: src/etc/rc.subr,v 1.50 2006/03/23 16:48:32 flz Exp $ # -# Copyright (c) 1997-2002 The NetBSD Foundation, Inc. +# Copyright (c) 1997-2004 The NetBSD Foundation, Inc. # All rights reserved. # # This code is derived from software contributed to The NetBSD Foundation @@ -39,6 +39,8 @@ # functions used by various rc scripts # +: ${rcvar_manpage:='rc.conf(5)'} + # # Operating System dependent/independent variables # @@ -138,12 +140,13 @@ return 1 ;; *) - warn "\$${1} is not set properly - see rc.conf(5)." + warn "\$${1} is not set properly - see ${rcvar_manpage}." return 1 ;; esac } +# # reverse_list list # print the list in reverse order # @@ -359,6 +362,10 @@ # rcvar n This is checked with checkyesno to determine # if the action should be run. # +# ${name}_program n Full path to command. +# Meant to be used in /etc/rc.conf to override +# ${command}. +# # ${name}_chroot n Directory to chroot to before running ${command} # Requires /usr to be mounted. # @@ -495,9 +502,6 @@ ;; esac - eval _override_command=\$${name}_program - command=${command:+${_override_command:-$command}} - _keywords="start stop restart rcvar $extra_commands" rc_pid= _pidcmd= @@ -598,7 +602,7 @@ start) if [ -z "$rc_fast" -a -n "$rc_pid" ]; then - echo "${name} already running? (pid=$rc_pid)." + echo 1>&2 "${name} already running? (pid=$rc_pid)." return 1 fi @@ -612,7 +616,7 @@ # for _f in $required_vars; do if ! checkyesno $_f; then - warn "\$${_f} is not set." + warn "\$${_f} is not enabled." if [ -z "$rc_force" ]; then return 1 fi @@ -684,10 +688,10 @@ if [ -z "$rc_pid" ]; then [ -n "$rc_fast" ] && return 0 if [ -n "$pidfile" ]; then - echo \ + echo 1>&2 \ "${name} not running? (check $pidfile)." else - echo "${name} not running?" + echo 1>&2 "${name} not running?" fi return 1 fi @@ -729,10 +733,10 @@ reload) if [ -z "$rc_pid" ]; then if [ -n "$pidfile" ]; then - echo \ + echo 1>&2 \ "${name} not running? (check $pidfile)." else - echo "${name} not running?" + echo 1>&2 "${name} not running?" fi return 1 fi @@ -854,14 +858,16 @@ } # -# load_rc_config -# Source in the configuration file for a given command. +# load_rc_config name +# Source in the configuration file for a given name. # load_rc_config() { - _command=$1 - if [ -z "$_command" ]; then - err 3 'USAGE: load_rc_config command' + local _tmp + + _name=$1 + if [ -z "$_name" ]; then + err 3 'USAGE: load_rc_config name' fi if ${_rc_conf_loaded:-false}; then @@ -877,9 +883,32 @@ fi _rc_conf_loaded=true fi - if [ -f /etc/rc.conf.d/"$_command" ]; then - debug "Sourcing /etc/rc.conf.d/${_command}" - . /etc/rc.conf.d/"$_command" + + eval _override_command=\$${name}_program + command=${command:+${_override_command:-$command}} + + if [ -z "${command}" ]; then + _tmp=`/bin/realpath $0` + prefix=${_tmp%/etc/rc.d/*}/ + else + prefix=${command%/*bin/*}/ + fi + if [ "${prefix}" = "/" -o "${prefix}" = "/usr/" ] ; then + etcdir="/etc" + else + etcdir="${prefix}etc" + fi + + # XXX - Deprecated + if [ -f /etc/rc.conf.d/"$_name" -a ${etcdir} != "/etc" -a ! -f ${etcdir}/rc.conf.d/"$_name" ]; then + debug "Sourcing /etc/rc.conf.d/${_name}" + echo "/etc/rc.conf.d/${_name} is deprecated, please use ${etcdir}/rc.conf.d/${_name} instead." + . /etc/rc.conf.d/"$_name" + fi + + if [ -f ${etcdir}/rc.conf.d/"$_name" ]; then + debug "Sourcing ${etcdir}/rc.conf.d/${_name}" + . ${etcdir}/rc.conf.d/"$_name" fi # XXX - Deprecated variable name support @@ -898,6 +927,25 @@ ;; esac } + +# +# load_rc_config_var cmd var +# Read the rc.conf(5) var for cmd and set in the +# current shell, using load_rc_config in a subshell to prevent +# unwanted side effects from other variable assignments. +# +load_rc_config_var() +{ + if [ $# -ne 2 ]; then + err 3 'USAGE: load_rc_config_var cmd var' + fi + eval $(eval '( + load_rc_config '$1' >/dev/null; + if [ -n "${'$2'}" -o "${'$2'-UNSET}" != "UNSET" ]; then + echo '$2'=\'\''${'$2'}\'\''; + fi + )' ) +} # # rc_usage commands @@ -1065,6 +1113,8 @@ fi } +_rc_subr_loaded=: + # make_symlink src link # Make a symbolic link 'link' to src from basedir. If the # directory in which link is to be created does not exist Index: rc.d/sshd =================================================================== RCS file: /home/ncvs/src/etc/rc.d/sshd,v retrieving revision 1.9 diff -u -r1.9 sshd --- rc.d/sshd 23 Oct 2005 14:06:53 -0000 1.9 +++ rc.d/sshd 29 Mar 2006 16:21:03 -0000 @@ -19,6 +19,8 @@ timeout=300 +load_rc_config $name + user_reseed() { ( @@ -47,47 +49,46 @@ umask 022 # Can't do anything if ssh is not installed - [ -x /usr/bin/ssh-keygen ] || { - warn "/usr/bin/ssh-keygen does not exist." + [ -x ${prefix}/bin/ssh-keygen ] || { + warn "${prefix}/bin/ssh-keygen does not exist." return 1 } - if [ -f /etc/ssh/ssh_host_key ]; then + if [ -f ${etcdir}/ssh/ssh_host_key ]; then echo "You already have an RSA host key" \ - "in /etc/ssh/ssh_host_key" + "in ${etcdir}/ssh/ssh_host_key" echo "Skipping protocol version 1 RSA Key Generation" else - /usr/bin/ssh-keygen -t rsa1 -b 1024 \ - -f /etc/ssh/ssh_host_key -N '' + ${prefix}/bin/ssh-keygen -t rsa1 -b 1024 \ + -f ${etcdir}/ssh/ssh_host_key -N '' fi - if [ -f /etc/ssh/ssh_host_dsa_key ]; then + if [ -f ${etcdir}/ssh/ssh_host_dsa_key ]; then echo "You already have a DSA host key" \ - "in /etc/ssh/ssh_host_dsa_key" + "in ${etcdir}/ssh/ssh_host_dsa_key" echo "Skipping protocol version 2 DSA Key Generation" else - /usr/bin/ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N '' + ${prefix}/bin/ssh-keygen -t dsa -f ${etcdir}/ssh/ssh_host_dsa_key -N '' fi - if [ -f /etc/ssh/ssh_host_rsa_key ]; then + if [ -f ${etcdir}/ssh/ssh_host_rsa_key ]; then echo "You already have a RSA host key" \ - "in /etc/ssh/ssh_host_rsa_key" + "in ${etcdir}/ssh/ssh_host_rsa_key" echo "Skipping protocol version 2 RSA Key Generation" else - /usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N '' + ${prefix}/bin/ssh-keygen -t rsa -f ${etcdir}/ssh/ssh_host_rsa_key -N '' fi ) } sshd_precmd() { - if [ ! -f /etc/ssh/ssh_host_key -o \ - ! -f /etc/ssh/ssh_host_dsa_key -o \ - ! -f /etc/ssh/ssh_host_rsa_key ]; then + if [ ! -f ${etcdir}/ssh/ssh_host_key -o \ + ! -f ${etcdir}/ssh/ssh_host_dsa_key -o \ + ! -f ${etcdir}/ssh/ssh_host_rsa_key ]; then user_reseed run_rc_command keygen fi } -load_rc_config $name run_rc_command "$1"