This is an automated email from the ASF dual-hosted git repository.
jfthomps pushed a commit to branch VCL-1127_updates_for_cygsshd
in repository https://gitbox.apache.org/repos/asf/vcl.git
The following commit(s) were added to refs/heads/VCL-1127_updates_for_cygsshd
by this push:
new b3ef160 VCL-1127 - Make changes to handle Cygwin's change of sshd
service name to cygsshd
b3ef160 is described below
commit b3ef160148b8cb8c50c67dbdd7c3abc3c15d4fb8
Author: Josh Thompson <[email protected]>
AuthorDate: Thu Dec 19 16:24:05 2019 -0500
VCL-1127 - Make changes to handle Cygwin's change of sshd service name to
cygsshd
Windows.pm:
-modified pre_capture: attempt calling set_service_startup_mode for cygsshd
if call for sshd fails
-modified post_load: attempt calling set_service_startup_mode for cygsshd
if call for sshd fails
-modified set_password: set @services array to include both sshd and
cygsshd, use variable to see if setting one of them was successful, give
warning message if neither one worked
-modified reboot: attempt calling set_service_startup_mode for cygsshd if
call for sshd fails
8.pm: modified pre_capture: attempt calling set_service_startup_mode for
cygsshd if call for sshd fails
cygwin-sshd-config.sh:
-attempt to parse sshd service name from "sc queryex type=service
state=all" into a variable ($sshdservice) and default to sshd if cannot
-changed references to "sshd" service name to $sshdservice
-added call to delete registry key based on $sshdservice, left hard coded
registry delete for sshd to clean up old data if cygwin gets upgraded on an
image
-added $sshdservice to echoed statement "Starting Cygwin SSHD service"
gen-node-key.sh: added code after case block where SSHSTART and SSHSTOP are
set that checks for the name of the sshd service and sets SSHSTART and SSHSTOP
to have cygsshd if needed
update_cygwin.cmd: added code to set %sshdservice% variable from service
name and use it when manging sshd service
---
managementnode/bin/cygwin-sshd-config.sh | 17 +++++++++++++----
managementnode/bin/gen-node-key.sh | 10 ++++++++++
managementnode/lib/VCL/Module/OS/Windows.pm | 18 ++++++++++++------
.../lib/VCL/Module/OS/Windows/Version_6/8.pm | 2 +-
managementnode/tools/Windows/Scripts/update_cygwin.cmd | 6 ++++--
5 files changed, 40 insertions(+), 13 deletions(-)
diff --git a/managementnode/bin/cygwin-sshd-config.sh
b/managementnode/bin/cygwin-sshd-config.sh
index c5b7180..88a84b1 100755
--- a/managementnode/bin/cygwin-sshd-config.sh
+++ b/managementnode/bin/cygwin-sshd-config.sh
@@ -131,9 +131,17 @@ if [ $? -ne 0 ]; then die "failed to configure / mount
point"; fi;
mount
print_hr
+sshdservice=$(sc queryex type=service state=all | grep sshd | grep
SERVICE_NAME | awk '{print $2}' | sed 's/
//g')
+
+if [[ $sshdservice == "" ]]; then
+ sshdservice=sshd
+fi
+
+echo "sshd service name is $sshdservice"
+
# Stop and kill all sshd processes
echo Stopping sshd service if it is running
-net stop sshd 2>/dev/null
+net stop $sshdservice 2>/dev/null
print_hr
echo Killing any sshd.exe processes
@@ -146,7 +154,7 @@ print_hr
# Delete the sshd service if it already exists
echo Deleting sshd service if it already exists
-$SYSTEMROOT/system32/sc.exe delete sshd
+$SYSTEMROOT/system32/sc.exe delete $sshdservice
print_hr
# Make sure sshd service registry key is gone
@@ -154,6 +162,7 @@ print_hr
# This prevents the service from being reinstalled
echo Deleting sshd service registry key
reg.exe DELETE 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\sshd' /f
+reg.exe DELETE
"HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\${sshdservice}" /f
print_hr
# Delete sshd user, a new account will be created
@@ -377,8 +386,8 @@ echo rebaseall exit status: %ERRORLEVEL%
IF ERRORLEVEL 1 exit /b %ERRORLEVEL%
echo.
-echo Starting Cygwin SSHD service
-net start sshd
+echo Starting Cygwin SSHD service (${sshdservice})
+net start ${sshdservice}
IF ERRORLEVEL 1 exit /b %ERRORLEVEL%
echo /var/log/sshd.log ending:
diff --git a/managementnode/bin/gen-node-key.sh
b/managementnode/bin/gen-node-key.sh
index 56ae691..8feb0f3 100755
--- a/managementnode/bin/gen-node-key.sh
+++ b/managementnode/bin/gen-node-key.sh
@@ -151,6 +151,16 @@ case $OS in
die "Unsupported OS found, OS call reported $OS";;
esac
+# if OS is CYGWIN, try to determine sshd service name
+if [[ $OS =~ (CYGWIN) ]]; then
+ sshdservice=`ssh $SSH_OPTIONS -i $KEY_PATH root@$NODE "sc queryex
type=service state=all | grep sshd | grep SERVICE_NAME | awk '{print \\$2}' |
sed 's/
//g'"`
+ if [[ $sshdservice != "" && $sshdservice != "sshd" ]]; then
+ echo "Detected CYGWIN with alternate sshd service name:
$sshdservice"
+ SSHSTOP="net stop $sshdservice"
+ SSHSTART="net start $sshdservice"
+ fi
+fi
+
echo Setting PasswordAuthentication to no in sshd_config on $NODE
ssh $SSH_OPTIONS -i $KEY_PATH root@$NODE 'sed -i -r -e "s/^[
#]*(PasswordAuthentication).*/\1 no/"' $SSHDCONFIG
ssh $SSH_OPTIONS -i $KEY_PATH root@$NODE 'grep "^[ #]*PasswordAuthentication"'
$SSHDCONFIG
diff --git a/managementnode/lib/VCL/Module/OS/Windows.pm
b/managementnode/lib/VCL/Module/OS/Windows.pm
index dde48d7..d612447 100644
--- a/managementnode/lib/VCL/Module/OS/Windows.pm
+++ b/managementnode/lib/VCL/Module/OS/Windows.pm
@@ -673,7 +673,7 @@ sub pre_capture {
=cut
- if (!$self->set_service_startup_mode('sshd', 'manual')) {
+ if (!$self->set_service_startup_mode('sshd', 'manual') &&
!$self->set_service_startup_mode('cygsshd', 'manual')) {
notify($ERRORS{'WARNING'}, 0, "unable to set sshd service
startup mode to manual");
return 0;
}
@@ -786,7 +786,7 @@ sub post_load {
=cut
- if (!$self->set_service_startup_mode('sshd', 'auto')) {
+ if (!$self->set_service_startup_mode('sshd', 'auto') &&
!$self->set_service_startup_mode('cygsshd', 'auto')) {
notify($ERRORS{'WARNING'}, 0, "unable to set sshd service
startup mode to auto");
return 0;
}
@@ -2349,15 +2349,21 @@ sub set_password {
# Get the list of services
my @services = $self->get_services_using_login_id($username);
if ($username eq 'root' && !@services) {
- @services = ('sshd');
+ @services = ('sshd', 'cygsshd');
}
+ my $success = 0;
for my $service (@services) {
notify($ERRORS{'DEBUG'}, 0, "$service service is configured to
run as $username, updating service credentials");
- if (!$self->set_service_credentials($service, $username,
$password)) {
- notify($ERRORS{'WARNING'}, 0, "failed to set $service
service credentials to $username ($password)");
+ if ($self->set_service_credentials($service, $username,
$password)) {
+ $success = 1;
+ last;
}
}
+ if(!$success) {
+ my $servicelist = join(', ', @services);
+ notify($ERRORS{'WARNING'}, 0, "failed to set credentials to
$username ($password) for any of $servicelist");
+ }
# Get the scheduled tasks - check if any are configured to run as the
user
my $scheduled_task_info = $self->get_scheduled_task_info();
@@ -3939,7 +3945,7 @@ sub reboot {
}
# Set sshd service startup mode to manual
- if (!$self->set_service_startup_mode('sshd', 'manual'))
{
+ if (!$self->set_service_startup_mode('sshd', 'manual')
&& !$self->set_service_startup_mode('cygsshd', 'manual')) {
notify($ERRORS{'WARNING'}, 0, "reboot not
attempted, unable to set sshd service startup mode to manual");
return 0;
}
diff --git a/managementnode/lib/VCL/Module/OS/Windows/Version_6/8.pm
b/managementnode/lib/VCL/Module/OS/Windows/Version_6/8.pm
index aa9bae8..403c96c 100644
--- a/managementnode/lib/VCL/Module/OS/Windows/Version_6/8.pm
+++ b/managementnode/lib/VCL/Module/OS/Windows/Version_6/8.pm
@@ -134,7 +134,7 @@ sub pre_capture {
}
# Set the sshd service startup mode to disabled so that it does not
start up until properly configured
- if (!$self->set_service_startup_mode('sshd', 'disabled')) {
+ if (!$self->set_service_startup_mode('sshd', 'disabled') &&
!$self->set_service_startup_mode('cygsshd', 'disabled')) {
notify($ERRORS{'WARNING'}, 0, "sshd service could not be
disabled before shutting down computer");
return;
}
diff --git a/managementnode/tools/Windows/Scripts/update_cygwin.cmd
b/managementnode/tools/Windows/Scripts/update_cygwin.cmd
index c09d9dd..8c0d093 100755
--- a/managementnode/tools/Windows/Scripts/update_cygwin.cmd
+++ b/managementnode/tools/Windows/Scripts/update_cygwin.cmd
@@ -172,14 +172,16 @@ echo.
echo ----------------------------------------------------------------------
+sc queryex type=service state=all | findstr "cygsshd" > nul && SET
sshdservice=cygsshd || SET sshdservice=sshd
+
echo %TIME%: Setting sshd service startup mode to auto...
-"%SystemRoot%\System32\sc.exe" config sshd start= auto 2>&1
+"%SystemRoot%\System32\sc.exe" config %sshdservice% start= auto 2>&1
echo ERRORLEVEL: %ERRORLEVEL%
set /A STATUS+=%ERRORLEVEL%
echo.
echo %TIME%: Starting the sshd service...
-"%SystemRoot%\System32\net.exe" start sshd 2>&1
+"%SystemRoot%\System32\net.exe" start %sshdservice% 2>&1
echo ERRORLEVEL: %ERRORLEVEL%
set /A STATUS+=%ERRORLEVEL%
echo.