components/openssh/sources/sshd.sh
author Sean Wilcox <sean.wilcox@oracle.com>
Tue, 08 Nov 2016 11:16:49 -0700
changeset 7262 19860fd7b64f
parent 5820 cef0da89f9ee
permissions -rw-r--r--
24692363 restart of nova-compute went to maintenance
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5544
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
     1
#!/usr/sbin/sh
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
     2
#
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
     3
# Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved.
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
     4
#
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
     5
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
     6
. /lib/svc/share/smf_include.sh
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
     7
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
     8
SSHDIR=/etc/ssh
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
     9
KEYGEN="/usr/bin/ssh-keygen -q"
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    10
PIDFILE=$SMF_SYSVOL_FS/sshd.pid
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    11
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    12
# Checks to see if RSA, and DSA host keys are available
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    13
# if any of these keys are not present, the respective keys are created.
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    14
create_key()
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    15
{
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    16
	keypath=$1
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    17
	keytype=$2
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    18
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    19
	if [ ! -f $keypath ]; then
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    20
		# 
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    21
		# HostKey keywords in sshd_config may be preceded or
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    22
		# followed by a mix of any number of space or tabs,
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    23
		# and optionally have an = between keyword and
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    24
		# argument.  We use two grep invocations such that we
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    25
		# can match HostKey case insensitively but still have
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    26
		# the case of the path name be significant, keeping
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    27
		# the pattern somewhat more readable.
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    28
		#
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    29
		# The character classes below contain one literal
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    30
		# space and one literal tab.
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    31
		#
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    32
		grep -i "^[ 	]*HostKey[ 	]*=\{0,1\}[ 	]*$keypath" \
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    33
		    $SSHDIR/sshd_config | grep "$keypath" > /dev/null 2>&1
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    34
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    35
		if [ $? -eq 0 ]; then
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    36
			echo Creating new $keytype public/private host key pair
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    37
			$KEYGEN -f $keypath -t $keytype -N ''
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    38
			if [ $? -ne 0 ]; then
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    39
				echo "Could not create $keytype key: $keypath"
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    40
				exit $SMF_EXIT_ERR_CONFIG
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    41
			fi
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    42
		fi
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    43
	fi
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    44
}
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    45
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    46
remove_key()
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    47
{
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    48
        keypath=$1
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    49
        if [ -f $keypath ]; then
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    50
                grep -i "^[     ]*HostKey[      ]*=\{0,1\}[     ]*$keypath" \
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    51
                    $SSHDIR/sshd_config | grep "$keypath" > /dev/null 2>&1
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    52
                if [ $? -eq 0 ]; then
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    53
                        rm -f ${keypath} ${keypath}.pub
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    54
                fi
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    55
        fi
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    56
}
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    57
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    58
#
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    59
# Makes sure, that /etc/ssh/sshd_config does not contain single line
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    60
# 'ListenAddress ::'. 
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    61
#
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    62
# This used to be part of default SunSSH sshd_config and instructed SunSSH
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    63
# to listen on all interfaces. For OpenSSH, the same line means listen on all
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    64
# IPv6 interfaces.
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    65
#
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    66
fix_listenaddress()
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    67
{
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    68
	fbackup="$SSHDIR/sshd_config.pre_listenaddress_fix"
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    69
	reason4change="#\n\
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    70
# Historically default sshd_config was shipped with 'ListenAddress ::',\n\
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    71
# which means 'listen on all interfaces' in SunSSH.\n\
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    72
# In OpenSSH this setting means 'listen on all IPv6 interfaces'.\n\
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    73
# To avoid loss of service after transitioning to OpenSSH, the following\n\
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    74
# line was commented out by the network/ssh service method script on\n\
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    75
#     $(date).\n\
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    76
# Original file was backed up to $fbackup\n\
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    77
#\n\
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    78
# "
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    79
	expl4log="Historically default sshd_config was shipped with \
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    80
'ListenAddress ::', which means 'listen on all interfaces' in SunSSH. \
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    81
In OpenSSH this setting means 'listen on all IPv6 interfaces'. \
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    82
For both SunSSH and OpenSSH the default behavior when no ListenAddress \
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    83
is specified is to listen on all interfaces (both IPv4 and IPv6)."
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    84
	msg_not_removed="Custom ListenAddress setting detected in \
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    85
$SSHDIR/sshd_config, the file will not be modified. Please, check your \
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    86
ListenAddress settings. $expl4log"
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    87
	msg_removed="Removing 'ListenAddress ::'. $expl4log Original file has \
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    88
been backed up to $fbackup"
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    89
	
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    90
	# only modify sshd_config, if ssh implementation is OpenSSH
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    91
	if [[ "$(ssh -V 2>&1)" == Sun_SSH_* ]]; then
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    92
		return 0;
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    93
	fi
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    94
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    95
	# comment '# IPv4 & IPv6' indicates an old default sshd_config
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    96
	grep -q '^# IPv4 & IPv6$' $SSHDIR/sshd_config || return 0;
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    97
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    98
	# backup
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
    99
	cp $SSHDIR/sshd_config $fbackup
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   100
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   101
	# if 'ListenAddress ::' is the only ListenAddress line, comment it out
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   102
	listen_address=$(grep -i '^[ \t]*ListenAddress' $SSHDIR/sshd_config)
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   103
	if [[ "$listen_address" == 'ListenAddress ::' ]]; then
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   104
		echo $msg_removed
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   105
		awk_prog="/^ListenAddress ::$/ {printf(\"$reason4change\")}\
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   106
			  !/^# IPv4 & IPv6$/   {print}"
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   107
	elif [[ -z "$listen_address" ]]; then
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   108
		# no ListenAddress setting => OK, silently remove comment
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   109
		awk_prog="!/^# IPv4 & IPv6$/   {print}"
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   110
	else
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   111
		# send warning message both to log and console
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   112
		echo $msg_not_removed | smf_console
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   113
		awk_prog="!/^# IPv4 & IPv6$/   {print}"
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   114
	fi;
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   115
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   116
	sshd_config=$(nawk "$awk_prog" $SSHDIR/sshd_config)
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   117
	if [[ $? -ne 0 ]]; then
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   118
		echo "Update error! Check your ListenAddress settings."
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   119
		return 1;
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   120
	else
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   121
		# write the fixed content to the file
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   122
		echo "$sshd_config" > $SSHDIR/sshd_config
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   123
		return 0;
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   124
	fi
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   125
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   126
}
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   127
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   128
# This script is being used for two purposes: as part of an SMF
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   129
# start/stop/refresh method, and as a sysidconfig(1M)/sys-unconfig(1M)
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   130
# application.
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   131
#
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   132
# Both, the SMF methods and sysidconfig/sys-unconfig use different
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   133
# arguments..
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   134
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   135
case $1 in 
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   136
	# sysidconfig/sys-unconfig arguments (-c and -u)
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   137
'-c')
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   138
	create_key $SSHDIR/ssh_host_rsa_key rsa
5820
cef0da89f9ee PSARC/2016/216 OpenSSH 7.2p2 upgrade. Host keys and moduli updates
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 5647
diff changeset
   139
	create_key $SSHDIR/ssh_host_ed25519_key ed25519
5544
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   140
	;;
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   141
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   142
'-u')
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   143
	# sysconfig unconfigure to remove the sshd host keys
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   144
	remove_key $SSHDIR/ssh_host_rsa_key
5820
cef0da89f9ee PSARC/2016/216 OpenSSH 7.2p2 upgrade. Host keys and moduli updates
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 5647
diff changeset
   145
	remove_key $SSHDIR/ssh_host_ed25519_key
5544
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   146
	;;
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   147
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   148
	# SMF arguments (start and restart [really "refresh"])
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   149
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   150
'start')
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   151
	#
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   152
	# If host keys don't exist when the service is started, create
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   153
	# them; sysidconfig is not run in every situation (such as on
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   154
	# the install media).
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   155
	# 
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   156
	create_key $SSHDIR/ssh_host_rsa_key rsa
5820
cef0da89f9ee PSARC/2016/216 OpenSSH 7.2p2 upgrade. Host keys and moduli updates
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 5647
diff changeset
   157
	create_key $SSHDIR/ssh_host_ed25519_key ed25519
5544
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   158
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   159
	#
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   160
	# Make sure, that /etc/ssh/sshd_config does not contain single line
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   161
	# 'ListenAddress ::'.
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   162
	#
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   163
	fix_listenaddress
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   164
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   165
	/usr/lib/ssh/sshd
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   166
	;;
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   167
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   168
'restart')
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   169
	if [ -f "$PIDFILE" ]; then
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   170
		/usr/bin/kill -HUP `/usr/bin/cat $PIDFILE`
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   171
	fi
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   172
	;;
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   173
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   174
*)
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   175
	echo "Usage: $0 { start | restart }"
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   176
	exit 1
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   177
	;;
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   178
esac	
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   179
16204c8a93ff PSARC 2015/227 SunSSH EOF and Removal
Huie-Ying Lee <huieying.lee@oracle.com>
parents:
diff changeset
   180
exit $?