sshd revision 1.23
11.1Slukem#!/bin/sh
21.1Slukem#
31.23Schristos# $NetBSD: sshd,v 1.23 2014/10/19 16:33:01 christos Exp $
41.5Sjwise#
51.1Slukem
61.6Slukem# PROVIDE: sshd
71.6Slukem# REQUIRE: LOGIN
81.1Slukem
91.20Smycroft$_rc_subr_loaded . /etc/rc.subr
101.1Slukem
111.1Slukemname="sshd"
121.8Slukemrcvar=$name
131.6Slukemcommand="/usr/sbin/${name}"
141.7Slukempidfile="/var/run/${name}.pid"
151.18Slukemrequired_files="/etc/ssh/sshd_config"
161.7Slukemextra_commands="keygen reload"
171.3Sjwise
181.6Slukemsshd_keygen()
191.6Slukem{
201.23Schristos(
211.23Schristos	keygen="/usr/bin/ssh-keygen"
221.11Slukem	umask 022
231.23Schristos	while read type bits filename version name;  do
241.23Schristos		f="/etc/ssh/$filename"
251.23Schristos		if [ -f "$f" ]; then
261.23Schristos			echo "You already have an $name host key in $f"
271.23Schristos			echo "Skipping protocol version $version $name" \
281.23Schristos			    "Key Generation"
291.23Schristos		else
301.23Schristos			case "${bits}" in
311.23Schristos			-1)	bitarg=;;
321.23Schristos			0)	bitarg="${ssh_keygen_flags}";;
331.23Schristos			*)	bitarg="-b ${bits}";;
341.23Schristos			esac
351.23Schristos			"${keygen}" -t "${type}" ${bitarg} -f "${f}" -N ''
361.23Schristos		fi
371.23Schristos	done << _EOF
381.23Schristosrsa1	0	ssh_host_key		1	RSA
391.23Schristosdsa	1024	ssh_host_dsa_key	2	DSA
401.23Schristosecdsa	521	ssh_host_ecdsa_key	1	ECDSA
411.23Schristosed25519	-1	ssh_host_ed25519_key	1	ED25519
421.23Schristosrsa	0	ssh_host_rsa_key	2	RSA
431.23Schristos_EOF
441.23Schristos)
451.3Sjwise}
461.3Sjwise
471.6Slukemsshd_precmd()
481.6Slukem{
491.17Slukem	if [ ! -f /etc/ssh/ssh_host_key -o \
501.17Slukem	    ! -f /etc/ssh/ssh_host_dsa_key -o \
511.21Schristos	    ! -f /etc/ssh/ssh_host_ecdsa_key -o \
521.23Schristos	    ! -f /etc/ssh/ssh_host_ed25519_key -o \
531.17Slukem	    ! -f /etc/ssh/ssh_host_rsa_key ]; then
541.16Senami		run_rc_command keygen
551.3Sjwise	fi
561.3Sjwise}
571.3Sjwise
581.3Sjwisekeygen_cmd=sshd_keygen
591.5Sjwisestart_precmd=sshd_precmd
601.3Sjwise
611.3Sjwiseload_rc_config $name
621.3Sjwiserun_rc_command "$1"
63