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(https://github.com/PowerShell/Win32-OpenSSH/issues/873)
3. fix for https://github.com/PowerShell/Win32-OpenSSH/issues/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 (https://github.com/PowerShell/Win32-OpenSSH/issues/879)
5. fix VCTargetsPath
This commit is contained in:
Yanbing 2017-09-15 21:25:42 -07:00 committed by Manoj Ampalam
parent 879318721c
commit 18b1e5935b
5 changed files with 28 additions and 25 deletions

View File

@ -217,7 +217,7 @@ function Start-OpenSSHBootstrap
[Environment]::SetEnvironmentVariable('Path', $newMachineEnvironmentPath, 'MACHINE')
}
$VCTargetsPath = "${env:ProgramFiles(x86)}\MSBuild\Microsoft.Cpp\v4.0\V140"
$VCTargetsPath = "${env:ProgramFiles(x86)}\MSBuild\Microsoft.Cpp\v4.0\V140\"
if([Environment]::GetEnvironmentVariable('VCTargetsPath', 'MACHINE') -eq $null)
{
[Environment]::SetEnvironmentVariable('VCTargetsPath', $VCTargetsPath, 'MACHINE')

View File

@ -12,7 +12,10 @@
} while(0)
#define NULL_DEVICE "/dev/null"
#define IsWin7OrLess() (!IsWindows8OrGreater())
#define IS_INVALID_HANDLE(h) ( ((NULL == h) || (INVALID_HANDLE_VALUE == h)) ? 1 : 0 )
#define IS_VALID_HANDLE(h) (!IS_INVALID_HANDLE(h))
/* removes first '/' for Windows paths that are unix styled. Ex: /c:/ab.cd */
char * sanitized_path(const char *);

View File

@ -106,9 +106,8 @@ ReadThread(_In_ LPVOID lpParameter)
}
if (!ReadFile(WINHANDLE(pio), pio->read_details.buf,
pio->read_details.buf_size, &read_status.transferred, NULL)) {
read_status.error = GetLastError();
debug("ReadThread - ReadFile failed %d, io:%p", GetLastError(), pio);
pio->read_details.buf_size, &read_status.transferred, NULL)) {
read_status.error = GetLastError();
return -1;
}
@ -127,13 +126,11 @@ ReadThread(_In_ LPVOID lpParameter)
} else {
if (!ReadFile(WINHANDLE(pio), pio->read_details.buf,
pio->read_details.buf_size, &read_status.transferred, NULL)) {
read_status.error = GetLastError();
debug("ReadThread - ReadFile failed %d, io:%p", GetLastError(), pio);
read_status.error = GetLastError();
return -1;
}
}
if (0 == QueueUserAPC(ReadAPCProc, main_thread, (ULONG_PTR)pio)) {
debug3("TermRead thread - ERROR QueueUserAPC failed %d, io:%p", GetLastError(), pio);
if (0 == QueueUserAPC(ReadAPCProc, main_thread, (ULONG_PTR)pio)) {
pio->read_details.pending = FALSE;
pio->read_details.error = GetLastError();
DebugBreak();
@ -256,8 +253,12 @@ syncio_close(struct w32_io* pio)
/* If io is pending, let worker threads exit. */
if (pio->read_details.pending) {
/* For console - the read thread is blocked so terminate it. */
if (FILETYPE(pio) == FILE_TYPE_CHAR && in_raw_mode)
/*
Terminate the read thread at the below situations:
1. For console - the read thread is blocked by the while loop on raw mode
2. Function ReadFile on Win7 machine dees not return when no content to read in non-interactive mode.
*/
if (FILETYPE(pio) == FILE_TYPE_CHAR && (IsWin7OrLess() || in_raw_mode))
TerminateThread(pio->read_overlapped.hEvent, 0);
else
WaitForSingleObject(pio->read_overlapped.hEvent, INFINITE);

View File

@ -556,17 +556,17 @@ w32_io_process_fd_flags(struct w32_io* pio, int flags)
shi_flags = (flags & FD_CLOEXEC) ? 0 : HANDLE_FLAG_INHERIT;
if (SetHandleInformation(WINHANDLE(pio), HANDLE_FLAG_INHERIT, shi_flags) == FALSE) {
/*
* Ignore if handle is not valid yet. It will not be valid for
* UF_UNIX sockets that are not connected yet
*/
if (GetLastError() != ERROR_INVALID_HANDLE) {
debug3("fcntl - SetHandleInformation failed %d, io:%p",
GetLastError(), pio);
errno = EOTHER;
return -1;
}
HANDLE h = WINHANDLE(pio);
/*
* Ignore if handle is not valid yet. It will not be valid for
* UF_UNIX sockets that are not connected yet
*/
if (IS_VALID_HANDLE(h) && (SetHandleInformation(h, HANDLE_FLAG_INHERIT, shi_flags) == FALSE)) {
debug3("fcntl - SetHandleInformation failed with error:%d, io:%p",
GetLastError(), pio);
errno = EOTHER;
return -1;
}
pio->fd_flags = flags;
@ -797,7 +797,6 @@ w32_select(int fds, w32_fd_set* readfds, w32_fd_set* writefds, w32_fd_set* excep
debug5("select - returning %d", out_ready_fds);
return out_ready_fds;
}
int

View File

@ -25,7 +25,7 @@ Describe "Tests of sshd_config" -Tags "CI" {
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$ContextName = $env:COMPUTERNAME
$ContextType = [System.DirectoryServices.AccountManagement.ContextType]::Machine
$PrincipalContext = [System.DirectoryServices.AccountManagement.PrincipalContext]::new($ContextType, $ContextName)
$PrincipalContext = new-object -TypeName System.DirectoryServices.AccountManagement.PrincipalContext -ArgumentList @($ContextType, $ContextName)
$IdentityType = [System.DirectoryServices.AccountManagement.IdentityType]::SamAccountName
function Add-LocalUser
@ -35,7 +35,7 @@ Describe "Tests of sshd_config" -Tags "CI" {
if($user -eq $null)
{
try {
$user = [System.DirectoryServices.AccountManagement.UserPrincipal]::new($PrincipalContext,$UserName,$Password, $true)
$user = new-object -TypeName System.DirectoryServices.AccountManagement.UserPrincipal -ArgumentList @($PrincipalContext,$UserName,$Password, $true)
$user.Save()
}
finally {
@ -51,7 +51,7 @@ Describe "Tests of sshd_config" -Tags "CI" {
if($group -eq $null)
{
try {
$group = [System.DirectoryServices.AccountManagement.GroupPrincipal]::new($PrincipalContext,$groupName)
$group = new-object -TypeName System.DirectoryServices.AccountManagement.GroupPrincipal -ArgumentList @($PrincipalContext,$groupName)
$group.Save()
}
finally {