sshd revision 1.14
1#!/bin/sh
2#
3# $NetBSD: sshd,v 1.14 2002/03/27 09:15:54 lukem Exp $
4#
5
6# PROVIDE: sshd
7# REQUIRE: LOGIN
8
9. /etc/rc.subr
10
11name="sshd"
12rcvar=$name
13command="/usr/sbin/${name}"
14command_args='-f ${sshd_conf_dir}/${name}.conf'
15pidfile="/var/run/${name}.pid"
16load_rc_config $name
17required_files="${sshd_conf_dir}/${name}.conf"
18extra_commands="keygen reload"
19
20sshd_keygen()
21{
22	(
23	umask 022
24	if [ -f ${sshd_conf_dir}/ssh_host_key ]; then
25		echo "You already have an RSA host key in ${sshd_conf_dir}/ssh_host_key"
26		echo "Skipping protocol version 1 RSA Key Generation"
27	else
28		/usr/bin/ssh-keygen -t rsa1 -b 1024 -f ${sshd_conf_dir}/ssh_host_key -N ''
29	fi
30
31	if [ -f ${sshd_conf_dir}/ssh_host_dsa_key ]; then
32		echo "You already have a DSA host key in ${sshd_conf_dir}/ssh_host_dsa_key"
33		echo "Skipping protocol version 2 DSA Key Generation"
34	else
35		/usr/bin/ssh-keygen -t dsa -f ${sshd_conf_dir}/ssh_host_dsa_key -N ''
36	fi
37
38	if [ -f ${sshd_conf_dir}/ssh_host_rsa_key ]; then
39		echo "You already have a RSA host key in ${sshd_conf_dir}/ssh_host_rsa_key"
40		echo "Skipping protocol version 2 RSA Key Generation"
41	else
42		/usr/bin/ssh-keygen -t rsa -f ${sshd_conf_dir}/ssh_host_rsa_key -N ''
43	fi
44	)
45}
46
47sshd_precmd()
48{
49	if [ ! -f ${sshd_conf_dir}/ssh_host_key -o ! -f ${sshd_conf_dir}/ssh_host_dsa_key -o \
50	     ! -f ${sshd_conf_dir}/ssh_host_rsa_key ]; then
51		$0 keygen
52	fi
53}
54
55keygen_cmd=sshd_keygen
56start_precmd=sshd_precmd
57
58load_rc_config $name
59run_rc_command "$1"
60