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