Added provision to intercept crt header inclusion (https://github.com/PowerShell/Win32-OpenSSH/issues/490)

This commit is contained in:
Manoj Ampalam 2017-01-21 20:14:08 -08:00 committed by GitHub
parent 98a3cff539
commit d34edc89db
10 changed files with 61 additions and 24 deletions

3
.gitignore vendored
View File

@ -283,4 +283,5 @@ __pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/
# tools/
contrib/win32/win32compat/inc/crtheaders.h

View File

@ -0,0 +1,19 @@
Param($Config_h_vs, $Config_h, $VCIncludePath, $OutCRTHeader)
Copy-Item $Config_h_vs $Config_h -Force
if (Test-Path $OutCRTHeader) {exit}
$headers = ("stdio.h", "string.h")
$paths = $VCIncludePath.Split(";")
Set-Content -Path $OutCRTHeader -Value "/*`r`n * DO NOT EDIT - AutoGenerated by config.ps1`r`n */`r`n" -Force
foreach ($header in $headers) {
foreach ($path in $paths)
{
if ($path -and (Test-Path (Join-Path $path $header)))
{
$entry = "#define " + $header.ToUpper().Replace(".","_") + " `"" + (Join-Path $path $header) + "`""
Add-Content -Path $OutCRTHeader -Value $entry
break
}
}
}

View File

@ -2,7 +2,7 @@
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="paths.targets" />
<PropertyGroup>
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
</PropertyGroup>
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
@ -112,7 +112,7 @@
<AdditionalLibraryDirectories>$(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-Win32-Debug-Path)lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
<PreBuildEvent>
<Command>copy /Y $(SolutionDir)config.h.vs $(OpenSSH-Src-Path)\config.h</Command>
<Command>powershell.exe -Executionpolicy Bypass "$(SolutionDir)config.ps1" -Config_h_vs '$(SolutionDir)config.h.vs' -Config_h '$(OpenSSH-Src-Path)config.h' -VCIncludePath '$(VC_IncludePath)' -OutCRTHeader '$(OpenSSH-Src-Path)contrib\win32\win32compat\inc\crtheaders.h'</Command>
</PreBuildEvent>
<PreBuildEvent>
<Message>Setup config.h in openssh source path for visual studio</Message>
@ -136,7 +136,7 @@
<AdditionalLibraryDirectories>$(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-x64-Debug-Path)lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
<PreBuildEvent>
<Command>copy /Y $(SolutionDir)config.h.vs $(OpenSSH-Src-Path)\config.h</Command>
<Command>powershell.exe -Executionpolicy Bypass "$(SolutionDir)config.ps1" -Config_h_vs '$(SolutionDir)config.h.vs' -Config_h '$(OpenSSH-Src-Path)config.h' -VCIncludePath '$(VC_IncludePath)' -OutCRTHeader '$(OpenSSH-Src-Path)contrib\win32\win32compat\inc\crtheaders.h'</Command>
</PreBuildEvent>
<PreBuildEvent>
<Message>Setup config.h in openssh source path for visual studio</Message>
@ -164,7 +164,7 @@
<AdditionalLibraryDirectories>$(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-Win32-Release-Path)lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
<PreBuildEvent>
<Command>copy /Y $(SolutionDir)config.h.vs $(OpenSSH-Src-Path)\config.h</Command>
<Command>powershell.exe -Executionpolicy Bypass "$(SolutionDir)config.ps1" -Config_h_vs '$(SolutionDir)config.h.vs' -Config_h '$(OpenSSH-Src-Path)config.h' -VCIncludePath '$(VC_IncludePath)' -OutCRTHeader '$(OpenSSH-Src-Path)contrib\win32\win32compat\inc\crtheaders.h'</Command>
</PreBuildEvent>
<PreBuildEvent>
<Message>Setup config.h in openssh source path for visual studio</Message>
@ -192,7 +192,7 @@
<AdditionalLibraryDirectories>$(OpenSSH-Lib-Path)$(Platform)\$(Configuration);$(OpenSSL-x64-Release-Path)lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
<PreBuildEvent>
<Command>copy /Y $(SolutionDir)config.h.vs $(OpenSSH-Src-Path)\config.h</Command>
<Command>powershell.exe -Executionpolicy Bypass "$(SolutionDir)config.ps1" -Config_h_vs '$(SolutionDir)config.h.vs' -Config_h '$(OpenSSH-Src-Path)config.h' -VCIncludePath '$(VC_IncludePath)' -OutCRTHeader '$(OpenSSH-Src-Path)contrib\win32\win32compat\inc\crtheaders.h'</Command>
</PreBuildEvent>
<PreBuildEvent>
<Message>Setup config.h in openssh source path for visual studio</Message>

View File

@ -288,7 +288,7 @@
<ClCompile Include="$(OpenSSH-Src-Path)contrib\win32\win32compat\ttymodes_windows.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\digest-openssl.c">
<ClCompile Include="$(OpenSSH-Src-Path)digest-openssl.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>

View File

@ -199,6 +199,8 @@
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\dirent.h" />
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\pwd.h" />
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\misc_internal.h" />
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\stdio.h" />
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\string.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@ -14,11 +14,11 @@
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\win32_dirent.c" />
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\no-ops.c" />
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\win32_zlib.c" />
<ClCompile Include="..\win32compat\ansiprsr.c" />
<ClCompile Include="..\win32compat\conio.c" />
<ClCompile Include="..\win32compat\console.c" />
<ClCompile Include="..\win32compat\tncon.c" />
<ClCompile Include="..\win32compat\tnnet.c" />
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\ansiprsr.c" />
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\conio.c" />
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\console.c" />
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\tncon.c" />
<ClCompile Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\tnnet.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\w32fd.h" />
@ -117,7 +117,13 @@
<Filter>inc</Filter>
</ClInclude>
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\pwd.h" />
<ClInclude Include="..\win32compat\misc_internal.h" />
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\misc_internal.h" />
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\stdio.h">
<Filter>inc</Filter>
</ClInclude>
<ClInclude Include="$(OpenSSH-Src-Path)\contrib\win32\win32compat\inc\string.h">
<Filter>inc</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="inc">

View File

@ -0,0 +1,9 @@
#include "crtheaders.h"
#include STDIO_H
/* stdio.h overrides */
#define fopen w32_fopen_utf8
/* stdio.h additional definitions */
#define popen _popen
#define pclose _pclose

View File

@ -0,0 +1,8 @@
#include "crtheaders.h"
#include STRING_H
/* string.h overrides */
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
char *w32_strerror(int);
#define strerror w32_strerror

View File

@ -151,16 +151,5 @@ struct iovec
void
explicit_bzero(void *b, size_t len);
/* string.h overrides */
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
char *w32_strerror(int);
#define strerror w32_strerror
/* stdio.h overrides */
#define fopen w32_fopen_utf8
#define popen _popen
#define pclose _pclose
void convertToBackslash(char *str);
void convertToForwardslash(char *str);

View File

@ -47,6 +47,7 @@
static
int errno_from_WSAError(int wsaerrno)
{
/* TODO - create a mapping table - more efficient */
switch (wsaerrno) {
case WSAEWOULDBLOCK:
return EAGAIN;
@ -64,6 +65,8 @@ int errno_from_WSAError(int wsaerrno)
return ECONNRESET;
case WSAENOTCONN:
return ENOTCONN;
case WSAECONNRESET:
return ECONNRESET;
default:
/* */
return wsaerrno - 10000;