xref: /dragonfly/etc/rc.d/sshd (revision 0bb9290e)
1#!/bin/sh
2#
3# $NetBSD: sshd,v 1.18 2002/04/29 08:23:34 lukem Exp $
4# $FreeBSD: src/etc/rc.d/sshd,v 1.3 2003/07/13 01:49:07 mtm Exp $
5# $DragonFly: src/etc/rc.d/sshd,v 1.3 2005/11/19 21:47:32 swildner Exp $
6#
7
8# PROVIDE: sshd
9# REQUIRE: LOGIN
10
11. /etc/rc.subr
12
13name="sshd"
14rcvar=`set_rcvar`
15keygen_cmd="sshd_keygen"
16start_precmd="sshd_precmd"
17pidfile="/var/run/${name}.pid"
18extra_commands="keygen reload"
19
20sshd_keygen()
21{
22	(
23	umask 022
24
25	# Can't do anything if ssh is not installed
26	[ -x /usr/bin/ssh-keygen ] || {
27		warn "/usr/bin/ssh-keygen does not exist."
28		return 1
29	}
30
31	if [ -f /etc/ssh/ssh_host_key ]; then
32		echo "You already have an RSA host key" \
33		    "in /etc/ssh/ssh_host_key"
34		echo "Skipping protocol version 1 RSA Key Generation"
35	else
36		/usr/bin/ssh-keygen -t rsa1 -b 1024 \
37		    -f /etc/ssh/ssh_host_key -N ''
38	fi
39
40	if [ -f /etc/ssh/ssh_host_dsa_key ]; then
41		echo "You already have a DSA host key" \
42		    "in /etc/ssh/ssh_host_dsa_key"
43		echo "Skipping protocol version 2 DSA Key Generation"
44	else
45		/usr/bin/ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
46	fi
47
48	if [ -f /etc/ssh/ssh_host_rsa_key ]; then
49		echo "You already have a RSA host key" \
50		    "in /etc/ssh/ssh_host_rsa_key"
51		echo "Skipping protocol version 2 RSA Key Generation"
52	else
53		/usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
54	fi
55	)
56}
57
58sshd_precmd()
59{
60	if [ ! -f /etc/ssh/ssh_host_key -o \
61	    ! -f /etc/ssh/ssh_host_dsa_key -o \
62	    ! -f /etc/ssh/ssh_host_rsa_key ]; then
63		run_rc_command keygen
64	fi
65}
66
67load_rc_config $name
68run_rc_command "$1"
69