xref: /titanic_50/usr/src/cmd/ssh/etc/sshd (revision ae115bc77f6fcde83175c75b4206dc2e50747966)
1#!/sbin/sh
2#
3# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
4# Use is subject to license terms.
5#
6# ident	"%Z%%M%	%I%	%E% SMI"
7
8SSHDIR=/etc/ssh
9KEYGEN="/usr/bin/ssh-keygen -q"
10PIDFILE=/var/run/sshd.pid
11
12# Checks to see if RSA, and DSA host keys are available
13# if any of these keys are not present, the respective keys are created.
14create_key()
15{
16	keypath=$1
17	keytype=$2
18
19	if [ ! -f $keypath ]; then
20		grep "^HostKey $keypath" $SSHDIR/sshd_config > /dev/null 2>&1
21		if [ $? -eq 0 ]; then
22			echo Creating new $keytype public/private host key pair
23			$KEYGEN -f $keypath -t $keytype -N ''
24			return $?
25		fi
26	fi
27
28	return 0
29}
30
31# This script is being used for two purposes: as part of an SMF
32# start/stop/refresh method, and as a sysidconfig(1M)/sys-unconfig(1M)
33# application.
34#
35# Both, the SMF methods and sysidconfig/sys-unconfig use different
36# arguments..
37
38case $1 in
39	# sysidconfig/sys-unconfig arguments (-c and -u)
40'-c')
41	create_key $SSHDIR/ssh_host_rsa_key rsa
42	create_key $SSHDIR/ssh_host_dsa_key dsa
43	;;
44
45'-u')
46	# sys-unconfig(1M) knows how to remove ssh host keys, so there's
47	# nothing to do here.
48	:
49	;;
50
51	# SMF arguments (start and restart [really "refresh"])
52'start')
53	/usr/lib/ssh/sshd
54	;;
55
56'restart')
57	if [ -f "$PIDFILE" ]; then
58		/usr/bin/kill -HUP `/usr/bin/cat $PIDFILE`
59	fi
60	;;
61
62*)
63	echo "Usage: $0 { start | restart }"
64	exit 1
65	;;
66esac
67
68exit $?
69