Skip to content

multiple fixes for win7 #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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