Skip to content

Commit

Permalink
multiple fixes for win7 (#206)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bingbing8 authored and manojampalam committed Sep 16, 2017
1 parent 8793187 commit 18b1e59
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 25 deletions.
2 changes: 1 addition & 1 deletion contrib/win32/openssh/OpenSSHBuildHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
3 changes: 3 additions & 0 deletions contrib/win32/win32compat/misc_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down
19 changes: 10 additions & 9 deletions contrib/win32/win32compat/termio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
23 changes: 11 additions & 12 deletions contrib/win32/win32compat/w32fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions regress/pesterTests/SSHDConfig.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 18b1e59

Please sign in to comment.