Make paths absolute for in-process, fix relative path check (#513)

This commit is contained in:
Justin Kotalik 2018-01-17 16:43:49 -08:00 committed by GitHub
parent 7b65bdb6ef
commit ab7ec622ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 190 additions and 91 deletions

View File

@ -1,6 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2010
VisualStudioVersion = 15.0.27130.2020
MinimumVisualStudioVersion = 15.0.26730.03
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{04B1EDB6-E967-4D25-89B9-E6F8304038CD}"
ProjectSection(SolutionItems) = preProject
@ -53,7 +54,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CommonLib", "src\CommonLib\
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RequestHandler", "src\RequestHandler\RequestHandler.vcxproj", "{D57EA297-6DC2-4BC0-8C91-334863327863}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.Server.IIS", "src\Microsoft.AspNetCore.Server.IIS\Microsoft.AspNetCore.Server.IIS.csproj", "{46A8612B-418B-4D70-B3A7-A21DD0627473}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.IIS", "src\Microsoft.AspNetCore.Server.IIS\Microsoft.AspNetCore.Server.IIS.csproj", "{46A8612B-418B-4D70-B3A7-A21DD0627473}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -202,16 +203,16 @@ Global
{D57EA297-6DC2-4BC0-8C91-334863327863}.Release|x86.Build.0 = Release|Win32
{46A8612B-418B-4D70-B3A7-A21DD0627473}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{46A8612B-418B-4D70-B3A7-A21DD0627473}.Debug|Any CPU.Build.0 = Debug|Any CPU
{46A8612B-418B-4D70-B3A7-A21DD0627473}.Debug|x64.ActiveCfg = Debug|x64
{46A8612B-418B-4D70-B3A7-A21DD0627473}.Debug|x64.Build.0 = Debug|x64
{46A8612B-418B-4D70-B3A7-A21DD0627473}.Debug|x86.ActiveCfg = Debug|x86
{46A8612B-418B-4D70-B3A7-A21DD0627473}.Debug|x86.Build.0 = Debug|x86
{46A8612B-418B-4D70-B3A7-A21DD0627473}.Debug|x64.ActiveCfg = Debug|Any CPU
{46A8612B-418B-4D70-B3A7-A21DD0627473}.Debug|x64.Build.0 = Debug|Any CPU
{46A8612B-418B-4D70-B3A7-A21DD0627473}.Debug|x86.ActiveCfg = Debug|Any CPU
{46A8612B-418B-4D70-B3A7-A21DD0627473}.Debug|x86.Build.0 = Debug|Any CPU
{46A8612B-418B-4D70-B3A7-A21DD0627473}.Release|Any CPU.ActiveCfg = Release|Any CPU
{46A8612B-418B-4D70-B3A7-A21DD0627473}.Release|Any CPU.Build.0 = Release|Any CPU
{46A8612B-418B-4D70-B3A7-A21DD0627473}.Release|x64.ActiveCfg = Release|x64
{46A8612B-418B-4D70-B3A7-A21DD0627473}.Release|x64.Build.0 = Release|x64
{46A8612B-418B-4D70-B3A7-A21DD0627473}.Release|x86.ActiveCfg = Release|x86
{46A8612B-418B-4D70-B3A7-A21DD0627473}.Release|x86.Build.0 = Release|x86
{46A8612B-418B-4D70-B3A7-A21DD0627473}.Release|x64.ActiveCfg = Release|Any CPU
{46A8612B-418B-4D70-B3A7-A21DD0627473}.Release|x64.Build.0 = Release|Any CPU
{46A8612B-418B-4D70-B3A7-A21DD0627473}.Release|x86.ActiveCfg = Release|Any CPU
{46A8612B-418B-4D70-B3A7-A21DD0627473}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -25,24 +25,21 @@ HOSTFXR_UTILITY::~HOSTFXR_UTILITY()
//
HRESULT
HOSTFXR_UTILITY::GetStandaloneHostfxrParameters(
PCWSTR pwzExePath,
ASPNETCORE_CONFIG *pConfig
)
{
HRESULT hr = S_OK;
STRU struExePath;
STRU struDllPath;
STRU struArguments;
DWORD dwPosition;
hr = UTILITY::ConvertPathToFullPath(pConfig->QueryProcessPath()->QueryStr(),
pConfig->QueryApplicationPhysicalPath()->QueryStr(),
&struExePath);
if (FAILED(hr))
{
goto Finished;
}
if (FAILED(hr = struDllPath.Copy(struExePath)))
if (FAILED(hr = struDllPath.Copy(pwzExePath)))
{
goto Finished;
}
@ -61,7 +58,7 @@ HOSTFXR_UTILITY::GetStandaloneHostfxrParameters(
{
goto Finished;
}
if (!UTILITY::CheckIfFileExists(struDllPath.QueryStr()))
{
// Treat access issue as File not found
@ -76,7 +73,7 @@ HOSTFXR_UTILITY::GetStandaloneHostfxrParameters(
goto Finished;
}
if (FAILED(hr = SetHostFxrArguments(&struArguments, &struExePath, pConfig)))
if (FAILED(hr = SetHostFxrArguments(struArguments.QueryStr(), pwzExePath, pConfig)))
{
goto Finished;
}
@ -94,18 +91,32 @@ HOSTFXR_UTILITY::GetHostFxrParameters(
HRESULT hr = S_OK;
STRU struSystemPathVariable;
STRU struHostFxrPath;
STRU strDotnetExeLocation;
STRU strHostFxrSearchExpression;
STRU strHighestDotnetVersion;
STRU struExeLocation;
STRU struHostFxrSearchExpression;
STRU struHighestDotnetVersion;
std::vector<std::wstring> vVersionFolders;
DWORD dwPosition;
DWORD dwPathLength = MAX_PATH;
DWORD dwDotnetLength = 0;
BOOL fFound = FALSE;
if (UTILITY::CheckIfFileExists(pConfig->QueryProcessPath()->QueryStr()))
// Convert the process path an absolute path.
hr = UTILITY::ConvertPathToFullPath(
pConfig->QueryProcessPath()->QueryStr(),
pConfig->QueryApplicationPhysicalPath()->QueryStr(),
&struExeLocation
);
if (FAILED(hr))
{
hr = UTILITY::ConvertPathToFullPath(L"hostfxr.dll", pConfig->QueryApplicationPath()->QueryStr(), &struHostFxrPath);
goto Finished;
}
if (UTILITY::CheckIfFileExists(struExeLocation.QueryStr()))
{
// Check if hostfxr is in this folder, if it is, we are a standalone application,
// else we assume we received an absolute path to dotnet.exe
hr = UTILITY::ConvertPathToFullPath(L".\\hostfxr.dll", pConfig->QueryApplicationPhysicalPath()->QueryStr(), &struHostFxrPath);
if (FAILED(hr))
{
goto Finished;
@ -119,54 +130,44 @@ HOSTFXR_UTILITY::GetHostFxrParameters(
goto Finished;
}
hr = GetStandaloneHostfxrParameters(pConfig);
hr = GetStandaloneHostfxrParameters(struExeLocation.QueryStr(), pConfig);
goto Finished;
}
else
}
else
{
if (FAILED(hr = struExeLocation.Resize(MAX_PATH)))
{
hr = UTILITY::ConvertPathToFullPath(
pConfig->QueryProcessPath()->QueryStr(),
pConfig->QueryApplicationPath()->QueryStr(),
&strDotnetExeLocation
);
if (FAILED(hr))
goto Finished;
}
while (!fFound)
{
dwDotnetLength = SearchPath(NULL, L"dotnet", L".exe", dwPathLength, struExeLocation.QueryStr(), NULL);
if (dwDotnetLength == 0)
{
hr = GetLastError();
// Could not find dotnet
goto Finished;
}
else if (dwDotnetLength == dwPathLength)
{
// Increase size
dwPathLength *= 2;
if (FAILED(hr = struExeLocation.Resize(dwPathLength)))
{
goto Finished;
}
}
else
{
fFound = TRUE;
}
}
}
if (FAILED(hr = strDotnetExeLocation.Resize(MAX_PATH)))
{
goto Finished;
}
while (!fFound)
{
dwDotnetLength = SearchPath(NULL, L"dotnet", L".exe", dwPathLength, strDotnetExeLocation.QueryStr(), NULL);
if (dwDotnetLength == 0)
{
hr = GetLastError();
// Could not find dotnet
goto Finished;
}
else if (dwDotnetLength == dwPathLength)
{
// Increase size
dwPathLength *= 2;
if (FAILED(hr = strDotnetExeLocation.Resize(dwPathLength)))
{
goto Finished;
}
}
else
{
fFound = TRUE;
}
}
if (FAILED(hr = strDotnetExeLocation.SyncWithBuffer())
|| FAILED(hr = struHostFxrPath.Copy(strDotnetExeLocation)))
if (FAILED(hr = struExeLocation.SyncWithBuffer())
|| FAILED(hr = struHostFxrPath.Copy(struExeLocation)))
{
goto Finished;
}
@ -200,13 +201,13 @@ HOSTFXR_UTILITY::GetHostFxrParameters(
}
// Find all folders under host\\fxr\\ for version numbers.
hr = strHostFxrSearchExpression.Copy(struHostFxrPath);
hr = struHostFxrSearchExpression.Copy(struHostFxrPath);
if (FAILED(hr))
{
goto Finished;
}
hr = strHostFxrSearchExpression.Append(L"\\*");
hr = struHostFxrSearchExpression.Append(L"\\*");
if (FAILED(hr))
{
goto Finished;
@ -214,7 +215,7 @@ HOSTFXR_UTILITY::GetHostFxrParameters(
// As we use the logic from core-setup, we are opting to use std here.
// TODO remove all uses of std?
UTILITY::FindDotNetFolders(strHostFxrSearchExpression.QueryStr(), &vVersionFolders);
UTILITY::FindDotNetFolders(struHostFxrSearchExpression.QueryStr(), &vVersionFolders);
if (vVersionFolders.size() == 0)
{
@ -223,14 +224,14 @@ HOSTFXR_UTILITY::GetHostFxrParameters(
goto Finished;
}
hr = UTILITY::FindHighestDotNetVersion(vVersionFolders, &strHighestDotnetVersion);
hr = UTILITY::FindHighestDotNetVersion(vVersionFolders, &struHighestDotnetVersion);
if (FAILED(hr))
{
goto Finished;
}
if (FAILED(hr = struHostFxrPath.Append(L"\\"))
|| FAILED(hr = struHostFxrPath.Append(strHighestDotnetVersion.QueryStr()))
|| FAILED(hr = struHostFxrPath.Append(struHighestDotnetVersion.QueryStr()))
|| FAILED(hr = struHostFxrPath.Append(L"\\hostfxr.dll")))
{
goto Finished;
@ -241,8 +242,8 @@ HOSTFXR_UTILITY::GetHostFxrParameters(
hr = ERROR_FILE_INVALID;
goto Finished;
}
if (FAILED(hr = SetHostFxrArguments(pConfig->QueryArguments(), &strDotnetExeLocation, pConfig)))
if (FAILED(hr = SetHostFxrArguments(pConfig->QueryArguments()->QueryStr(), struExeLocation.QueryStr(), pConfig)))
{
goto Finished;
}
@ -263,12 +264,12 @@ Finished:
// Arg structure:
// argv[0] = Path to exe activating hostfxr.
// argv[1] = L"exec"
// argv[2] = first argument specified in the arguments portion of aspnetcore config.
// argv[2] = absolute path to dll.
//
HRESULT
HOSTFXR_UTILITY::SetHostFxrArguments(
STRU* struArgumentsFromConfig,
STRU* pstruExePath,
PCWSTR pwzArgumentsFromConfig,
PCWSTR pwzExePath,
ASPNETCORE_CONFIG* pConfig
)
{
@ -276,30 +277,89 @@ HOSTFXR_UTILITY::SetHostFxrArguments(
INT argc = 0;
PCWSTR* argv = NULL;
LPWSTR* pwzArgs = NULL;
STRU struTempPath;
DWORD dwArgsProcessed = 0;
pwzArgs = CommandLineToArgvW(struArgumentsFromConfig->QueryStr(), &argc);
pwzArgs = CommandLineToArgvW(pwzArgumentsFromConfig, &argc);
if (pwzArgs == NULL)
{
goto Finished;
hr = HRESULT_FROM_WIN32(GetLastError());
goto Failure;
}
if (argc < 1)
{
// Invalid arguments
hr = E_INVALIDARG;
goto Failure;
}
argv = new PCWSTR[argc + 2];
if (argv == NULL)
{
hr = E_OUTOFMEMORY;
goto Finished;
goto Failure;
}
argv[0] = SysAllocString(pstruExePath->QueryStr());
argv[1] = SysAllocString(L"exec");
argv[0] = SysAllocString(pwzExePath);
for (INT i = 0; i < argc; i++)
if (argv[0] == NULL)
{
hr = E_OUTOFMEMORY;
goto Failure;
}
dwArgsProcessed++;
argv[1] = SysAllocString(L"exec");
if (argv[1] == NULL)
{
hr = E_OUTOFMEMORY;
goto Failure;
}
dwArgsProcessed++;
// Try to convert the application dll from a relative to an absolute path
// Don't record this failure as pwzArgs[0] may already be an absolute path to the dll.
if (SUCCEEDED(UTILITY::ConvertPathToFullPath(pwzArgs[0], pConfig->QueryApplicationPhysicalPath()->QueryStr(), &struTempPath)))
{
argv[2] = SysAllocString(struTempPath.QueryStr());
}
else
{
argv[2] = SysAllocString(pwzArgs[0]);
}
if (argv[2] == NULL)
{
hr = E_OUTOFMEMORY;
goto Failure;
}
dwArgsProcessed++;
for (INT i = 1; i < argc; i++)
{
argv[i + 2] = SysAllocString(pwzArgs[i]);
if (argv[i + 2] == NULL)
{
hr = E_OUTOFMEMORY;
goto Failure;
}
dwArgsProcessed++;
}
pConfig->SetHostFxrArguments(argc + 2, argv);
goto Finished;
Failure:
if (argv != NULL)
{
for (DWORD i = 0; i < dwArgsProcessed; i++)
{
SysFreeString((BSTR)argv[i]);
}
}
delete[] argv;
Finished:
if (pwzArgs != NULL)
@ -308,4 +368,4 @@ Finished:
DBG_ASSERT(pwzArgs == NULL);
}
return hr;
}
}

View File

@ -23,15 +23,16 @@ private:
static
HRESULT
GetStandaloneHostfxrParameters(
PCWSTR pStruExePath,
ASPNETCORE_CONFIG *pConfig
);
static
HRESULT
SetHostFxrArguments(
STRU * struArguments,
STRU * pstruExePath,
ASPNETCORE_CONFIG *pConfig
PCWSTR struArguments,
PCWSTR pStruExePath,
ASPNETCORE_CONFIG *pConfig
);
};

View File

@ -13,6 +13,7 @@
#include <vector>
#include <shellapi.h>
#include <sstream>
#include "Shlwapi.h"
#include "..\IISLib\hashtable.h"
#include "..\IISLib\stringu.h"
#include "..\IISLib\stringa.h"

View File

@ -384,7 +384,7 @@ UTILITY::ConvertPathToFullPath(
LPWSTR pszFullPath = NULL;
// if relative path, prefix with root path and then convert to absolute path.
if ( pszPath[0] == L'.' )
if ( PathIsRelative(pszPath) )
{
hr = strFileFullPath.Copy(pszRootPath);
if(FAILED(hr))

View File

@ -48,7 +48,13 @@ namespace IISIntegration.IISServerFunctionalTests
ServerConfigTemplateContent = (serverType == ServerType.IISExpress) ? File.ReadAllText("Http.config") : null,
SiteName = "HttpTestSite", // This is configured in the Http.config
TargetFramework = "netcoreapp2.0",
ApplicationType = ApplicationType.Portable
ApplicationType = ApplicationType.Portable,
Configuration =
#if DEBUG
"Debug"
#else
"Release"
#endif
};
using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))

View File

@ -47,6 +47,12 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests
SiteName = "HttpTestSite", // This is configured in the Http.config
TargetFramework = runtimeFlavor == RuntimeFlavor.Clr ? "net461" : "netcoreapp2.0",
ApplicationType = applicationType,
Configuration =
#if DEBUG
"Debug"
#else
"Release"
#endif
};
using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))

View File

@ -21,7 +21,7 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests
{
}
[Fact(Skip = "See https://github.com/aspnet/IISIntegration/issues/424")]
[Fact(Skip = "See https://github.com/aspnet/IISIntegration/issues/515")]
public Task HelloWorld_InProcess_IISExpress_CoreClr_X64_Portable()
{
return HelloWorld(RuntimeFlavor.CoreClr, ApplicationType.Portable);
@ -42,7 +42,13 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests
ServerConfigTemplateContent = (serverType == ServerType.IISExpress) ? File.ReadAllText("Http.config") : null,
SiteName = "HttpTestSite", // This is configured in the Http.config
TargetFramework = runtimeFlavor == RuntimeFlavor.Clr ? "net461" : "netcoreapp2.0",
ApplicationType = applicationType
ApplicationType = applicationType,
Configuration =
#if DEBUG
"Debug"
#else
"Release"
#endif
};
using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))

View File

@ -253,7 +253,7 @@
<add name="ManagedEngine64" image="%windir%\Microsoft.NET\Framework64\v2.0.50727\webengine.dll" preCondition="integratedMode,runtimeVersionv2.0,bitness64" />
<add name="ManagedEngineV4.0_32bit" image="%windir%\Microsoft.NET\Framework\v4.0.30319\webengine4.dll" preCondition="integratedMode,runtimeVersionv4.0,bitness32" />
<add name="ManagedEngineV4.0_64bit" image="%windir%\Microsoft.NET\Framework64\v4.0.30319\webengine4.dll" preCondition="integratedMode,runtimeVersionv4.0,bitness64" />
<add name="AspNetCoreModule" image="%IIS_BIN%\aspnetcore.dll"/>
<add name="AspNetCoreModule" image="[ANCMPath]"/>
</globalModules>
<httpCompression directory="%TEMP%\iisexpress\IIS Temporary Compressed Files">

View File

@ -48,7 +48,13 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests
ServerConfigTemplateContent = (serverType == ServerType.IISExpress) ? File.ReadAllText("Http.config") : null,
SiteName = "HttpTestSite", // This is configured in the Http.config
TargetFramework = runtimeFlavor == RuntimeFlavor.Clr ? "net461" : "netcoreapp2.0",
ApplicationType = applicationType
ApplicationType = applicationType,
Configuration =
#if DEBUG
"Debug"
#else
"Release"
#endif
};
using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))

View File

@ -46,7 +46,13 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests
ServerConfigTemplateContent = (serverType == ServerType.IISExpress) ? File.ReadAllText("Http.config") : null,
SiteName = "HttpTestSite", // This is configured in the Http.config
TargetFramework = "netcoreapp2.0",
ApplicationType = applicationType
ApplicationType = applicationType,
Configuration =
#if DEBUG
"Debug"
#else
"Release"
#endif
};
using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))

View File

@ -42,7 +42,13 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests
ServerConfigTemplateContent = (serverType == ServerType.IISExpress) ? File.ReadAllText("Http.config") : null,
SiteName = "HttpTestSite", // This is configured in the Http.config
TargetFramework = runtimeFlavor == RuntimeFlavor.Clr ? "net461" : "netcoreapp2.0",
ApplicationType = applicationType
ApplicationType = applicationType,
Configuration =
#if DEBUG
"Debug"
#else
"Release"
#endif
};
using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))

View File

@ -16,7 +16,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="$(MicrosoftAspNetCoreServerKestrelPackageVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="$(MicrosoftAspNetCoreHostingPackageVersion)" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="$(MicrosoftAspNetCoreWebUtilitiesPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="$(MicrosoftExtensionsConfigurationEnvironmentVariablesPackageVersion)" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="$(MicrosoftExtensionsConfigurationJsonPackageVersion)" />