summaryrefslogtreecommitdiff
path: root/security/openssh/files/sshd.sh
blob: aba871be2ee4d9aca03e5b7b89a7e0c430436487 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!@RCD_SCRIPTS_SHELL@
#
# $NetBSD: sshd.sh,v 1.10 2002/09/20 02:02:00 grant Exp $
#
# PROVIDE: sshd
# REQUIRE: DAEMON LOGIN

if [ -f /etc/rc.subr ]
then
	. /etc/rc.subr
fi

name="sshd"
rcvar=$name
command="@PREFIX@/sbin/${name}"
keygen_command="@PREFIX@/bin/ssh-keygen"
pidfile="@SSH_PID_DIR@/${name}.pid"
required_files="@PKG_SYSCONFDIR@/sshd_config"
extra_commands="keygen reload"

sshd_keygen()
{
	(
	umask 022
	if [ -f @PKG_SYSCONFDIR@/ssh_host_key ]; then
		@ECHO@ "You already have an RSA host key in @PKG_SYSCONFDIR@/ssh_host_key"
		@ECHO@ "Skipping protocol version 1 RSA Key Generation"
	else
		${keygen_command} -t rsa1 -b 1024 -f @PKG_SYSCONFDIR@/ssh_host_key -N ''
	fi

	if [ -f @PKG_SYSCONFDIR@/ssh_host_dsa_key ]; then
		@ECHO@ "You already have a DSA host key in @PKG_SYSCONFDIR@/ssh_host_dsa_key"
		@ECHO@ "Skipping protocol version 2 DSA Key Generation"
	else
		${keygen_command} -t dsa -f @PKG_SYSCONFDIR@/ssh_host_dsa_key -N ''
	fi

	if [ -f @PKG_SYSCONFDIR@/ssh_host_rsa_key ]; then
		@ECHO@ "You already have a RSA host key in @PKG_SYSCONFDIR@/ssh_host_rsa_key"
		@ECHO@ "Skipping protocol version 2 RSA Key Generation"
	else
		${keygen_command} -t rsa -f @PKG_SYSCONFDIR@/ssh_host_rsa_key -N ''
	fi
	)
}

sshd_precmd()
{
	if [ ! -f @PKG_SYSCONFDIR@/ssh_host_key -o \
	     ! -f @PKG_SYSCONFDIR@/ssh_host_dsa_key -o \
	     ! -f @PKG_SYSCONFDIR@/ssh_host_rsa_key ]; then
		$0 keygen
	fi
}

keygen_cmd=sshd_keygen
start_precmd=sshd_precmd

if [ -f /etc/rc.subr -a -f /etc/rc.conf -a -d /etc/rc.d -a -f /etc/rc.d/DAEMON ]
then
	load_rc_config $name
	run_rc_command "$1"
else
	case ${1:-start} in
	start)
		if [ -x ${command} -a -f ${required_files} ]
		then
			@ECHO@ "Starting ${name}."
			eval ${start_precmd}
			eval ${command} ${sshd_flags} ${command_args}
		fi
		;;
	stop)
		if [ -f ${pidfile} ]; then
			pid=`@HEAD@ -1 ${pidfile}`
			@ECHO@ "Stopping ${name}."
			kill -TERM ${pid}
		else
			@ECHO@ "${name} not running?"
		fi
		;;
	restart)
		( $0 stop )
		sleep 1
		$0 start
		;;
	status)
		if [ -f ${pidfile} ]; then
			pid=`@HEAD@ -1 ${pidfile}`
			@ECHO@ "${name} is running as pid ${pid}."
		else
			@ECHO@ "${name} is not running."
		fi
		;;
	keygen)
		eval ${keygen_cmd}
		;;
	esac
fi