[BACK]Return to sshd CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / etc / rc.d

File: [cvs.NetBSD.org] / src / etc / rc.d / sshd (download)

Revision 1.22.10.1, Sat May 2 18:04:37 2015 UTC (8 years, 11 months ago) by martin
Branch: netbsd-7
CVS Tags: netbsd-7-nhusb-base-20170116, netbsd-7-nhusb-base, netbsd-7-nhusb, netbsd-7-2-RELEASE, netbsd-7-1-RELEASE, netbsd-7-1-RC2, netbsd-7-1-RC1, netbsd-7-1-2-RELEASE, netbsd-7-1-1-RELEASE, netbsd-7-1, netbsd-7-0-RELEASE, netbsd-7-0-RC3, netbsd-7-0-RC2, netbsd-7-0-RC1, netbsd-7-0-2-RELEASE, netbsd-7-0-1-RELEASE, netbsd-7-0
Changes since 1.22: +26 -38 lines

Pull up following revision(s) (requested by nakayama in ticket #728):
	etc/rc.d/sshd: revision 1.23
Add new keytype, replace duplicated code with loop

#!/bin/sh
#
# $NetBSD: sshd,v 1.22.10.1 2015/05/02 18:04:37 martin Exp $
#

# PROVIDE: sshd
# REQUIRE: LOGIN

$_rc_subr_loaded . /etc/rc.subr

name="sshd"
rcvar=$name
command="/usr/sbin/${name}"
pidfile="/var/run/${name}.pid"
required_files="/etc/ssh/sshd_config"
extra_commands="keygen reload"

sshd_keygen()
{
(
	keygen="/usr/bin/ssh-keygen"
	umask 022
	while read type bits filename version name;  do
		f="/etc/ssh/$filename"
		if [ -f "$f" ]; then
			echo "You already have an $name host key in $f"
			echo "Skipping protocol version $version $name" \
			    "Key Generation"
		else
			case "${bits}" in
			-1)	bitarg=;;
			0)	bitarg="${ssh_keygen_flags}";;
			*)	bitarg="-b ${bits}";;
			esac
			"${keygen}" -t "${type}" ${bitarg} -f "${f}" -N ''
		fi
	done << _EOF
rsa1	0	ssh_host_key		1	RSA
dsa	1024	ssh_host_dsa_key	2	DSA
ecdsa	521	ssh_host_ecdsa_key	1	ECDSA
ed25519	-1	ssh_host_ed25519_key	1	ED25519
rsa	0	ssh_host_rsa_key	2	RSA
_EOF
)
}

sshd_precmd()
{
	if [ ! -f /etc/ssh/ssh_host_key -o \
	    ! -f /etc/ssh/ssh_host_dsa_key -o \
	    ! -f /etc/ssh/ssh_host_ecdsa_key -o \
	    ! -f /etc/ssh/ssh_host_ed25519_key -o \
	    ! -f /etc/ssh/ssh_host_rsa_key ]; then
		run_rc_command keygen
	fi
}

keygen_cmd=sshd_keygen
start_precmd=sshd_precmd

load_rc_config $name
run_rc_command "$1"