- (djm) [contrib/cygwin/ssh-host-config] Updated Cygwin ssh-host-config

from Corinna Vinschen, fixing a number of bugs and preparing for
   Cygwin 1.7.30.
This commit is contained in:
Damien Miller 2014-05-27 14:31:58 +10:00
parent eae8874466
commit f9eb5e0734
2 changed files with 105 additions and 64 deletions

View File

@ -1,5 +1,8 @@
20140527 20140527
- (djm) [cipher.c] Fix merge botch. - (djm) [cipher.c] Fix merge botch.
- (djm) [contrib/cygwin/ssh-host-config] Updated Cygwin ssh-host-config
from Corinna Vinschen, fixing a number of bugs and preparing for
Cygwin 1.7.30.
20140522 20140522
- (djm) [Makefile.in] typo in path - (djm) [Makefile.in] typo in path

View File

@ -34,6 +34,7 @@ declare -a csih_required_commands=(
/usr/bin/mv coreutils /usr/bin/mv coreutils
/usr/bin/rm coreutils /usr/bin/rm coreutils
/usr/bin/cygpath cygwin /usr/bin/cygpath cygwin
/usr/bin/mkpasswd cygwin
/usr/bin/mount cygwin /usr/bin/mount cygwin
/usr/bin/ps cygwin /usr/bin/ps cygwin
/usr/bin/setfacl cygwin /usr/bin/setfacl cygwin
@ -59,8 +60,9 @@ PREFIX=/usr
SYSCONFDIR=/etc SYSCONFDIR=/etc
LOCALSTATEDIR=/var LOCALSTATEDIR=/var
sshd_config_configured=no
port_number=22 port_number=22
privsep_configured=no strictmodes=yes
privsep_used=yes privsep_used=yes
cygwin_value="" cygwin_value=""
user_account= user_account=
@ -89,28 +91,8 @@ update_services_file() {
# Depends on the above mount # Depends on the above mount
_wservices=`cygpath -w "${_services}"` _wservices=`cygpath -w "${_services}"`
# Remove sshd 22/port from services
if [ `/usr/bin/grep -q 'sshd[ \t][ \t]*22' "${_services}"; echo $?` -eq 0 ]
then
/usr/bin/grep -v 'sshd[ \t][ \t]*22' "${_services}" > "${_serv_tmp}"
if [ -f "${_serv_tmp}" ]
then
if /usr/bin/mv "${_serv_tmp}" "${_services}"
then
csih_inform "Removing sshd from ${_wservices}"
else
csih_warning "Removing sshd from ${_wservices} failed!"
let ++ret
fi
/usr/bin/rm -f "${_serv_tmp}"
else
csih_warning "Removing sshd from ${_wservices} failed!"
let ++ret
fi
fi
# Add ssh 22/tcp and ssh 22/udp to services # Add ssh 22/tcp and ssh 22/udp to services
if [ `/usr/bin/grep -q 'ssh[ \t][ \t]*22' "${_services}"; echo $?` -ne 0 ] if [ `/usr/bin/grep -q 'ssh[[:space:]][[:space:]]*22' "${_services}"; echo $?` -ne 0 ]
then then
if /usr/bin/awk '{ if ( $2 ~ /^23\/tcp/ ) print "ssh 22/tcp'"${_spaces}"'SSH Remote Login Protocol\nssh 22/udp'"${_spaces}"'SSH Remote Login Protocol"; print $0; }' < "${_services}" > "${_serv_tmp}" if /usr/bin/awk '{ if ( $2 ~ /^23\/tcp/ ) print "ssh 22/tcp'"${_spaces}"'SSH Remote Login Protocol\nssh 22/udp'"${_spaces}"'SSH Remote Login Protocol"; print $0; }' < "${_services}" > "${_serv_tmp}"
then then
@ -131,18 +113,46 @@ update_services_file() {
return $ret return $ret
} # --- End of update_services_file --- # } # --- End of update_services_file --- #
# ======================================================================
# Routine: sshd_strictmodes
# MODIFIES: strictmodes
# ======================================================================
sshd_strictmodes() {
if [ "${sshd_config_configured}" != "yes" ]
then
echo
csih_inform "StrictModes is set to 'yes' by default."
csih_inform "This is the recommended setting, but it requires that the POSIX"
csih_inform "permissions of the user's home directory, the user's .ssh"
csih_inform "directory, and the user's ssh key files are tight so that"
csih_inform "only the user has write permissions."
csih_inform "On the other hand, StrictModes don't work well with default"
csih_inform "Windows permissions of a home directory mounted with the"
csih_inform "'noacl' option, and they don't work at all if the home"
csih_inform "directory is on a FAT or FAT32 partition."
if ! csih_request "Should StrictModes be used?"
then
strictmodes=no
fi
fi
return 0
}
# ====================================================================== # ======================================================================
# Routine: sshd_privsep # Routine: sshd_privsep
# MODIFIES: privsep_configured privsep_used # MODIFIES: privsep_used
# ====================================================================== # ======================================================================
sshd_privsep() { sshd_privsep() {
local sshdconfig_tmp
local ret=0 local ret=0
if [ "${privsep_configured}" != "yes" ] if [ "${sshd_config_configured}" != "yes" ]
then then
csih_inform "Privilege separation is set to yes by default since OpenSSH 3.3." echo
csih_inform "However, this requires a non-privileged account called 'sshd'." csih_inform "Privilege separation is set to 'sandbox' by default since"
csih_inform "OpenSSH 6.1. This is unsupported by Cygwin and has to be set"
csih_inform "to 'yes' or 'no'."
csih_inform "However, using privilege separation requires a non-privileged account"
csih_inform "called 'sshd'."
csih_inform "For more info on privilege separation read /usr/share/doc/openssh/README.privsep." csih_inform "For more info on privilege separation read /usr/share/doc/openssh/README.privsep."
if csih_request "Should privilege separation be used?" if csih_request "Should privilege separation be used?"
then then
@ -159,36 +169,53 @@ sshd_privsep() {
privsep_used=no privsep_used=no
fi fi
fi fi
return $ret
} # --- End of sshd_privsep --- #
# Create default sshd_config from skeleton files in /etc/defaults/etc or # ======================================================================
# modify to add the missing privsep configuration option # Routine: sshd_config_tweak
if /usr/bin/cmp "${SYSCONFDIR}/sshd_config" "${SYSCONFDIR}/defaults/${SYSCONFDIR}/sshd_config" >/dev/null 2>&1 # ======================================================================
then sshd_config_tweak() {
local ret=0
# Modify sshd_config
csih_inform "Updating ${SYSCONFDIR}/sshd_config file" csih_inform "Updating ${SYSCONFDIR}/sshd_config file"
sshdconfig_tmp=${SYSCONFDIR}/sshd_config.$$ if [ "${port_number}" -ne 22 ]
/usr/bin/sed -e "s/^#UsePrivilegeSeparation yes/UsePrivilegeSeparation ${privsep_used}/
s/^#Port 22/Port ${port_number}/
s/^#StrictModes yes/StrictModes no/" \
< ${SYSCONFDIR}/sshd_config \
> "${sshdconfig_tmp}"
if ! /usr/bin/mv "${sshdconfig_tmp}" ${SYSCONFDIR}/sshd_config
then then
csih_warning "Setting privilege separation to 'yes' failed!" /usr/bin/sed -i -e "s/^#\?[[:space:]]*Port[[:space:]].*/Port ${port_number}/" \
${SYSCONFDIR}/sshd_config
if [ $? -ne 0 ]
then
csih_warning "Setting listening port to ${port_number} failed!"
csih_warning "Check your ${SYSCONFDIR}/sshd_config file!" csih_warning "Check your ${SYSCONFDIR}/sshd_config file!"
let ++ret let ++ret
fi fi
elif [ "${privsep_configured}" != "yes" ] fi
if [ "${strictmodes}" = "no" ]
then then
echo >> ${SYSCONFDIR}/sshd_config /usr/bin/sed -i -e "s/^#\?[[:space:]]*StrictModes[[:space:]].*/StrictModes no/" \
if ! echo "UsePrivilegeSeparation ${privsep_used}" >> ${SYSCONFDIR}/sshd_config ${SYSCONFDIR}/sshd_config
if [ $? -ne 0 ]
then then
csih_warning "Setting privilege separation to 'yes' failed!" csih_warning "Setting StrictModes to 'no' failed!"
csih_warning "Check your ${SYSCONFDIR}/sshd_config file!"
let ++ret
fi
fi
if [ "${sshd_config_configured}" != "yes" ]
then
/usr/bin/sed -i -e "
s/^#\?UsePrivilegeSeparation .*/UsePrivilegeSeparation ${privsep_used}/" \
${SYSCONFDIR}/sshd_config
if [ $? -ne 0 ]
then
csih_warning "Setting privilege separation failed!"
csih_warning "Check your ${SYSCONFDIR}/sshd_config file!" csih_warning "Check your ${SYSCONFDIR}/sshd_config file!"
let ++ret let ++ret
fi fi
fi fi
return $ret return $ret
} # --- End of sshd_privsep --- # } # --- End of sshd_config_tweak --- #
# ====================================================================== # ======================================================================
# Routine: update_inetd_conf # Routine: update_inetd_conf
@ -207,11 +234,11 @@ update_inetd_conf() {
# we have inetutils-1.5 inetd.d support # we have inetutils-1.5 inetd.d support
if [ -f "${_inetcnf}" ] if [ -f "${_inetcnf}" ]
then then
/usr/bin/grep -q '^[ \t]*ssh' "${_inetcnf}" && _with_comment=0 /usr/bin/grep -q '^[[:space:]]*ssh' "${_inetcnf}" && _with_comment=0
# check for sshd OR ssh in top-level inetd.conf file, and remove # check for sshd OR ssh in top-level inetd.conf file, and remove
# will be replaced by a file in inetd.d/ # will be replaced by a file in inetd.d/
if [ `/usr/bin/grep -q '^[# \t]*ssh' "${_inetcnf}"; echo $?` -eq 0 ] if [ $(/usr/bin/grep -q '^[# \t]*ssh' "${_inetcnf}"; echo $?) -eq 0 ]
then then
/usr/bin/grep -v '^[# \t]*ssh' "${_inetcnf}" >> "${_inetcnf_tmp}" /usr/bin/grep -v '^[# \t]*ssh' "${_inetcnf}" >> "${_inetcnf_tmp}"
if [ -f "${_inetcnf_tmp}" ] if [ -f "${_inetcnf_tmp}" ]
@ -236,9 +263,9 @@ update_inetd_conf() {
then then
if [ "${_with_comment}" -eq 0 ] if [ "${_with_comment}" -eq 0 ]
then then
/usr/bin/sed -e 's/@COMMENT@[ \t]*//' < "${_sshd_inetd_conf}" > "${_sshd_inetd_conf_tmp}" /usr/bin/sed -e 's/@COMMENT@[[:space:]]*//' < "${_sshd_inetd_conf}" > "${_sshd_inetd_conf_tmp}"
else else
/usr/bin/sed -e 's/@COMMENT@[ \t]*/# /' < "${_sshd_inetd_conf}" > "${_sshd_inetd_conf_tmp}" /usr/bin/sed -e 's/@COMMENT@[[:space:]]*/# /' < "${_sshd_inetd_conf}" > "${_sshd_inetd_conf_tmp}"
fi fi
if /usr/bin/mv "${_sshd_inetd_conf_tmp}" "${_sshd_inetd_conf}" if /usr/bin/mv "${_sshd_inetd_conf_tmp}" "${_sshd_inetd_conf}"
then then
@ -251,13 +278,13 @@ update_inetd_conf() {
elif [ -f "${_inetcnf}" ] elif [ -f "${_inetcnf}" ]
then then
/usr/bin/grep -q '^[ \t]*sshd' "${_inetcnf}" && _with_comment=0 /usr/bin/grep -q '^[[:space:]]*sshd' "${_inetcnf}" && _with_comment=0
# check for sshd in top-level inetd.conf file, and remove # check for sshd in top-level inetd.conf file, and remove
# will be replaced by a file in inetd.d/ # will be replaced by a file in inetd.d/
if [ `/usr/bin/grep -q '^[# \t]*sshd' "${_inetcnf}"; echo $?` -eq 0 ] if [ `/usr/bin/grep -q '^#\?[[:space:]]*sshd' "${_inetcnf}"; echo $?` -eq 0 ]
then then
/usr/bin/grep -v '^[# \t]*sshd' "${_inetcnf}" >> "${_inetcnf_tmp}" /usr/bin/grep -v '^#\?[[:space:]]*sshd' "${_inetcnf}" >> "${_inetcnf_tmp}"
if [ -f "${_inetcnf_tmp}" ] if [ -f "${_inetcnf_tmp}" ]
then then
if /usr/bin/mv "${_inetcnf_tmp}" "${_inetcnf}" if /usr/bin/mv "${_inetcnf_tmp}" "${_inetcnf}"
@ -305,17 +332,26 @@ check_service_files_ownership() {
if [ -z "${run_service_as}" ] if [ -z "${run_service_as}" ]
then then
accnt_name=$(/usr/bin/cygrunsrv -VQ sshd | /usr/bin/sed -ne 's/^Account *: *//gp') accnt_name=$(/usr/bin/cygrunsrv -VQ sshd |
/usr/bin/sed -ne 's/^Account *: *//gp')
if [ "${accnt_name}" = "LocalSystem" ] if [ "${accnt_name}" = "LocalSystem" ]
then then
# Convert "LocalSystem" to "SYSTEM" as is the correct account name # Convert "LocalSystem" to "SYSTEM" as is the correct account name
accnt_name="SYSTEM:" run_service_as="SYSTEM"
elif [[ "${accnt_name}" =~ ^\.\\ ]] else
dom="${accnt_name%%\\*}"
accnt_name="${accnt_name#*\\}"
if [ "${dom}" = '.' ]
then then
# Convert "." domain to local machine name # Check local account
accnt_name="U-${COMPUTERNAME}${accnt_name#.}," run_service_as=$(/usr/bin/mkpasswd -l -u "${accnt_name}" |
/usr/bin/awk -F: '{print $1;}')
else
# Check domain
run_service_as=$(/usr/bin/mkpasswd -d "${dom}" -u "${accnt_name}" |
/usr/bin/awk -F: '{print $1;}')
fi
fi fi
run_service_as=$(/usr/bin/grep -Fi "${accnt_name}" /etc/passwd | /usr/bin/awk -F: '{print $1;}')
if [ -z "${run_service_as}" ] if [ -z "${run_service_as}" ]
then then
csih_warning "Couldn't determine name of user running sshd service from /etc/passwd!" csih_warning "Couldn't determine name of user running sshd service from /etc/passwd!"
@ -672,6 +708,7 @@ then
fi fi
# generate missing host keys # generate missing host keys
csih_inform "Generating missing SSH host keys"
/usr/bin/ssh-keygen -A || let warning_cnt+=$? /usr/bin/ssh-keygen -A || let warning_cnt+=$?
# handle ssh_config # handle ssh_config
@ -690,10 +727,11 @@ fi
csih_install_config "${SYSCONFDIR}/sshd_config" "${SYSCONFDIR}/defaults" || let ++warning_cnt csih_install_config "${SYSCONFDIR}/sshd_config" "${SYSCONFDIR}/defaults" || let ++warning_cnt
if ! /usr/bin/cmp "${SYSCONFDIR}/sshd_config" "${SYSCONFDIR}/defaults/${SYSCONFDIR}/sshd_config" >/dev/null 2>&1 if ! /usr/bin/cmp "${SYSCONFDIR}/sshd_config" "${SYSCONFDIR}/defaults/${SYSCONFDIR}/sshd_config" >/dev/null 2>&1
then then
/usr/bin/grep -q UsePrivilegeSeparation ${SYSCONFDIR}/sshd_config && privsep_configured=yes sshd_config_configured=yes
fi fi
sshd_strictmodes || let warning_cnt+=$?
sshd_privsep || let warning_cnt+=$? sshd_privsep || let warning_cnt+=$?
sshd_config_tweak || let warning_cnt+=$?
update_services_file || let warning_cnt+=$? update_services_file || let warning_cnt+=$?
update_inetd_conf || let warning_cnt+=$? update_inetd_conf || let warning_cnt+=$?
install_service || let warning_cnt+=$? install_service || let warning_cnt+=$?