xref: /dragonfly/etc/rc.d/sshd (revision 9dbf638f)
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.1 2003/07/24 06:35:37 dillon Exp $
6#
7
8# PROVIDE: sshd
9# REQUIRE: LOGIN
10# KEYWORD: DragonFly FreeBSD NetBSD
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"
20case ${OSTYPE} in
21NetBSD)
22	command="/usr/sbin/${name}"
23	required_files="/etc/ssh/sshd_config"
24	;;
25esac
26
27sshd_keygen()
28{
29	(
30	umask 022
31
32	# Can't do anything if ssh is not installed
33	[ -x /usr/bin/ssh-keygen ] || {
34		warn "/usr/bin/ssh-keygen does not exist."
35		return 1
36	}
37
38	if [ -f /etc/ssh/ssh_host_key ]; then
39		echo "You already have an RSA host key" \
40		    "in /etc/ssh/ssh_host_key"
41		echo "Skipping protocol version 1 RSA Key Generation"
42	else
43		/usr/bin/ssh-keygen -t rsa1 -b 1024 \
44		    -f /etc/ssh/ssh_host_key -N ''
45	fi
46
47	if [ -f /etc/ssh/ssh_host_dsa_key ]; then
48		echo "You already have a DSA host key" \
49		    "in /etc/ssh/ssh_host_dsa_key"
50		echo "Skipping protocol version 2 DSA Key Generation"
51	else
52		/usr/bin/ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
53	fi
54
55	if [ -f /etc/ssh/ssh_host_rsa_key ]; then
56		echo "You already have a RSA host key" \
57		    "in /etc/ssh/ssh_host_rsa_key"
58		echo "Skipping protocol version 2 RSA Key Generation"
59	else
60		/usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
61	fi
62	)
63}
64
65sshd_precmd()
66{
67	if [ ! -f /etc/ssh/ssh_host_key -o \
68	    ! -f /etc/ssh/ssh_host_dsa_key -o \
69	    ! -f /etc/ssh/ssh_host_rsa_key ]; then
70		run_rc_command keygen
71	fi
72}
73
74load_rc_config $name
75run_rc_command "$1"
76