Skip to content

Commit 18b1e59

Browse files
bingbing8manojampalam
authored andcommitted
multiple fixes for win7 (#206)
1. fix some exception when appverifier is enabled on win7 (https://gitthub.com/PowerShell/Win32-OpenSSH/issues/872) 2. enable sshdconfig tests on win7(PowerShell/Win32-OpenSSH#873) 3. fix for PowerShell/Win32-OpenSSH#874 ( ReadFile does not return on win7 when no content in console ) 4. Remove logging to console in Readthread because write hangs here since write thread already closed (PowerShell/Win32-OpenSSH#879) 5. fix VCTargetsPath
1 parent 8793187 commit 18b1e59

File tree

5 files changed

+28
-25
lines changed

5 files changed

+28
-25
lines changed

contrib/win32/openssh/OpenSSHBuildHelper.psm1

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ function Start-OpenSSHBootstrap
217217
[Environment]::SetEnvironmentVariable('Path', $newMachineEnvironmentPath, 'MACHINE')
218218
}
219219

220-
$VCTargetsPath = "${env:ProgramFiles(x86)}\MSBuild\Microsoft.Cpp\v4.0\V140"
220+
$VCTargetsPath = "${env:ProgramFiles(x86)}\MSBuild\Microsoft.Cpp\v4.0\V140\"
221221
if([Environment]::GetEnvironmentVariable('VCTargetsPath', 'MACHINE') -eq $null)
222222
{
223223
[Environment]::SetEnvironmentVariable('VCTargetsPath', $VCTargetsPath, 'MACHINE')

contrib/win32/win32compat/misc_internal.h

+3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
} while(0)
1313
#define NULL_DEVICE "/dev/null"
1414

15+
#define IsWin7OrLess() (!IsWindows8OrGreater())
16+
1517
#define IS_INVALID_HANDLE(h) ( ((NULL == h) || (INVALID_HANDLE_VALUE == h)) ? 1 : 0 )
18+
#define IS_VALID_HANDLE(h) (!IS_INVALID_HANDLE(h))
1619

1720
/* removes first '/' for Windows paths that are unix styled. Ex: /c:/ab.cd */
1821
char * sanitized_path(const char *);

contrib/win32/win32compat/termio.c

+10-9
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,8 @@ ReadThread(_In_ LPVOID lpParameter)
106106
}
107107

108108
if (!ReadFile(WINHANDLE(pio), pio->read_details.buf,
109-
pio->read_details.buf_size, &read_status.transferred, NULL)) {
110-
read_status.error = GetLastError();
111-
debug("ReadThread - ReadFile failed %d, io:%p", GetLastError(), pio);
109+
pio->read_details.buf_size, &read_status.transferred, NULL)) {
110+
read_status.error = GetLastError();
112111
return -1;
113112
}
114113

@@ -127,13 +126,11 @@ ReadThread(_In_ LPVOID lpParameter)
127126
} else {
128127
if (!ReadFile(WINHANDLE(pio), pio->read_details.buf,
129128
pio->read_details.buf_size, &read_status.transferred, NULL)) {
130-
read_status.error = GetLastError();
131-
debug("ReadThread - ReadFile failed %d, io:%p", GetLastError(), pio);
129+
read_status.error = GetLastError();
132130
return -1;
133131
}
134132
}
135-
if (0 == QueueUserAPC(ReadAPCProc, main_thread, (ULONG_PTR)pio)) {
136-
debug3("TermRead thread - ERROR QueueUserAPC failed %d, io:%p", GetLastError(), pio);
133+
if (0 == QueueUserAPC(ReadAPCProc, main_thread, (ULONG_PTR)pio)) {
137134
pio->read_details.pending = FALSE;
138135
pio->read_details.error = GetLastError();
139136
DebugBreak();
@@ -256,8 +253,12 @@ syncio_close(struct w32_io* pio)
256253

257254
/* If io is pending, let worker threads exit. */
258255
if (pio->read_details.pending) {
259-
/* For console - the read thread is blocked so terminate it. */
260-
if (FILETYPE(pio) == FILE_TYPE_CHAR && in_raw_mode)
256+
/*
257+
Terminate the read thread at the below situations:
258+
1. For console - the read thread is blocked by the while loop on raw mode
259+
2. Function ReadFile on Win7 machine dees not return when no content to read in non-interactive mode.
260+
*/
261+
if (FILETYPE(pio) == FILE_TYPE_CHAR && (IsWin7OrLess() || in_raw_mode))
261262
TerminateThread(pio->read_overlapped.hEvent, 0);
262263
else
263264
WaitForSingleObject(pio->read_overlapped.hEvent, INFINITE);

contrib/win32/win32compat/w32fd.c

+11-12
Original file line numberDiff line numberDiff line change
@@ -556,17 +556,17 @@ w32_io_process_fd_flags(struct w32_io* pio, int flags)
556556

557557
shi_flags = (flags & FD_CLOEXEC) ? 0 : HANDLE_FLAG_INHERIT;
558558

559-
if (SetHandleInformation(WINHANDLE(pio), HANDLE_FLAG_INHERIT, shi_flags) == FALSE) {
560-
/*
561-
* Ignore if handle is not valid yet. It will not be valid for
562-
* UF_UNIX sockets that are not connected yet
563-
*/
564-
if (GetLastError() != ERROR_INVALID_HANDLE) {
565-
debug3("fcntl - SetHandleInformation failed %d, io:%p",
566-
GetLastError(), pio);
567-
errno = EOTHER;
568-
return -1;
569-
}
559+
HANDLE h = WINHANDLE(pio);
560+
561+
/*
562+
* Ignore if handle is not valid yet. It will not be valid for
563+
* UF_UNIX sockets that are not connected yet
564+
*/
565+
if (IS_VALID_HANDLE(h) && (SetHandleInformation(h, HANDLE_FLAG_INHERIT, shi_flags) == FALSE)) {
566+
debug3("fcntl - SetHandleInformation failed with error:%d, io:%p",
567+
GetLastError(), pio);
568+
errno = EOTHER;
569+
return -1;
570570
}
571571

572572
pio->fd_flags = flags;
@@ -797,7 +797,6 @@ w32_select(int fds, w32_fd_set* readfds, w32_fd_set* writefds, w32_fd_set* excep
797797

798798
debug5("select - returning %d", out_ready_fds);
799799
return out_ready_fds;
800-
801800
}
802801

803802
int

regress/pesterTests/SSHDConfig.tests.ps1

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Describe "Tests of sshd_config" -Tags "CI" {
2525
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
2626
$ContextName = $env:COMPUTERNAME
2727
$ContextType = [System.DirectoryServices.AccountManagement.ContextType]::Machine
28-
$PrincipalContext = [System.DirectoryServices.AccountManagement.PrincipalContext]::new($ContextType, $ContextName)
28+
$PrincipalContext = new-object -TypeName System.DirectoryServices.AccountManagement.PrincipalContext -ArgumentList @($ContextType, $ContextName)
2929
$IdentityType = [System.DirectoryServices.AccountManagement.IdentityType]::SamAccountName
3030

3131
function Add-LocalUser
@@ -35,7 +35,7 @@ Describe "Tests of sshd_config" -Tags "CI" {
3535
if($user -eq $null)
3636
{
3737
try {
38-
$user = [System.DirectoryServices.AccountManagement.UserPrincipal]::new($PrincipalContext,$UserName,$Password, $true)
38+
$user = new-object -TypeName System.DirectoryServices.AccountManagement.UserPrincipal -ArgumentList @($PrincipalContext,$UserName,$Password, $true)
3939
$user.Save()
4040
}
4141
finally {
@@ -51,7 +51,7 @@ Describe "Tests of sshd_config" -Tags "CI" {
5151
if($group -eq $null)
5252
{
5353
try {
54-
$group = [System.DirectoryServices.AccountManagement.GroupPrincipal]::new($PrincipalContext,$groupName)
54+
$group = new-object -TypeName System.DirectoryServices.AccountManagement.GroupPrincipal -ArgumentList @($PrincipalContext,$groupName)
5555
$group.Save()
5656
}
5757
finally {

0 commit comments

Comments
 (0)