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