300
|
1 |
#!/sbin/sh
|
|
2 |
#
|
|
3 |
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
|
|
4 |
# Use is subject to license terms.
|
|
5 |
#
|
|
6 |
# ident "@(#)sshd 1.4 04/11/17 SMI"
|
|
7 |
|
|
8 |
SSHDIR=/etc/ssh
|
|
9 |
KEYGEN="/usr/bin/ssh-keygen -q"
|
|
10 |
PIDFILE=/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.
|
|
14 |
create_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 |
|
|
38 |
case $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 |
if [ -f /.livecd ] && [ ! -f $SSHDIR/ssh_host_rsa_key ]; then
|
|
54 |
create_key $SSHDIR/ssh_host_rsa_key rsa
|
|
55 |
create_key $SSHDIR/ssh_host_dsa_key dsa
|
|
56 |
fi
|
|
57 |
/usr/lib/ssh/sshd
|
|
58 |
;;
|
|
59 |
|
|
60 |
'restart')
|
|
61 |
if [ -f "$PIDFILE" ]; then
|
|
62 |
/usr/bin/kill -HUP `/usr/bin/cat $PIDFILE`
|
|
63 |
fi
|
|
64 |
;;
|
|
65 |
|
|
66 |
*)
|
|
67 |
echo "Usage: $0 { start | restart }"
|
|
68 |
exit 1
|
|
69 |
;;
|
|
70 |
esac
|
|
71 |
|
|
72 |
exit $?
|