3 # Copyright 2010 Sun Microsystems, Inc. All rights reserved.
4 # Use is subject to license terms.
6 # Copyright 2016 Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
9 .
/lib
/svc
/share
/ipf_include.sh
10 .
/lib
/svc
/share
/smf_include.sh
13 KEYGEN
="/usr/bin/ssh-keygen -q"
14 PIDFILE
=/var
/run
/sshd.pid
16 # Checks to see if RSA, and DSA host keys are available
17 # if any of these keys are not present, the respective keys are created.
23 if [ ! -f $keypath ]; then
25 # HostKey keywords in sshd_config may be preceded or
26 # followed by a mix of any number of space or tabs,
27 # and optionally have an = between keyword and
28 # argument. We use two grep invocations such that we
29 # can match HostKey case insensitively but still have
30 # the case of the path name be significant, keeping
31 # the pattern somewhat more readable.
33 # The character classes below contain one literal
34 # space and one literal tab.
36 grep -i "^[ ]*HostKey[ ]*=\{0,1\}[ ]*$keypath" \
37 $SSHDIR/sshd_config |
grep "$keypath" > /dev
/null
2>&1
40 echo Creating new
$keytype public
/private
host key pair
41 $KEYGEN -f $keypath -t $keytype -N ''
43 echo "Could not create $keytype key: $keypath"
44 exit $SMF_EXIT_ERR_CONFIG
53 ipf_file
=`fmri_to_file ${FMRI} $IPF_SUFFIX`
54 ipf6_file
=`fmri_to_file ${FMRI} $IPF6_SUFFIX`
55 policy
=`get_policy ${FMRI}`
58 # Get port from /etc/ssh/sshd_config
60 tports
=`grep "^Port" /etc/ssh/sshd_config 2>/dev/null | \
63 echo "# $FMRI" >$ipf_file
64 echo "# $FMRI" >$ipf6_file
65 for port
in $tports; do
66 generate_rules
$FMRI $policy "tcp" $port $ipf_file
67 generate_rules
$FMRI $policy "tcp" $port $ipf6_file _6
71 # This script is being used for two purposes: as part of an SMF
72 # start/stop/refresh method, and as a sysidconfig(1M)/sys-unconfig(1M)
75 # Both, the SMF methods and sysidconfig/sys-unconfig use different
79 # sysidconfig/sys-unconfig arguments (-c and -u)
81 /usr
/bin
/ssh-keygen
-A
83 create_key
$SSHDIR/ssh_host_rsa_key rsa
84 create_key
$SSHDIR/ssh_host_dsa_key dsa
89 # sys-unconfig(1M) knows how to remove ssh host keys, so there's
94 # SMF arguments (start and restart [really "refresh"])
102 # If host keys don't exist when the service is started, create
103 # them; sysidconfig is not run in every situation (such as on
104 # the install media).
106 /usr
/bin
/ssh-keygen
-A
107 if [ $?
-ne 0 ]; then
108 create_key
$SSHDIR/ssh_host_rsa_key rsa
109 create_key
$SSHDIR/ssh_host_dsa_key dsa
116 if [ -f "$PIDFILE" ]; then
117 /usr
/bin
/kill -HUP `/usr/bin/cat $PIDFILE`
122 echo "Usage: $0 { start | restart }"