Skip to content
This repository has been archived by the owner on Jun 20, 2019. It is now read-only.

add features: flowing authentication info, hosting environment variab… #102

Merged
merged 1 commit into from
May 24, 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
3 changes: 1 addition & 2 deletions src/AspNetCore/AspNetCore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
<ClInclude Include="Inc\application.h" />
<ClInclude Include="Inc\applicationmanager.h" />
<ClInclude Include="Inc\aspnetcoreconfig.h" />
<ClInclude Include="Inc\aspnetcoreutils.h" />
<ClInclude Include="Inc\environmentvariablehash.h" />
<ClInclude Include="Inc\debugutil.h" />
<ClInclude Include="Inc\filewatcher.h" />
<ClInclude Include="Inc\forwarderconnection.h" />
Expand All @@ -177,7 +177,6 @@
<ClCompile Include="Src\application.cxx" />
<ClCompile Include="Src\applicationmanager.cxx" />
<ClCompile Include="Src\aspnetcoreconfig.cxx" />
<ClCompile Include="Src\aspnetcoreutils.cxx" />
<ClCompile Include="Src\dllmain.cpp" />
<ClCompile Include="Src\filewatcher.cxx" />
<ClCompile Include="Src\forwarderconnection.cxx" />
Expand Down
21 changes: 14 additions & 7 deletions src/AspNetCore/Inc/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,28 @@ class APP_OFFLINE_HTM
VOID
)
{
BOOL fResult = FALSE;
BOOL fResult = TRUE;
LARGE_INTEGER li = {0};
CHAR *pszBuff = NULL;
HANDLE handle = CreateFile( m_Path.QueryStr(),
HANDLE handle = INVALID_HANDLE_VALUE;

handle = CreateFile( m_Path.QueryStr(),
GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL );

if( handle == NULL )
if( handle == INVALID_HANDLE_VALUE )
{
if ( GetLastError() == ERROR_FILE_NOT_FOUND )
{
fResult = FALSE;
}

// This Load() member function is supposed be called only when the change notification event of file creation or file modification happens.
// If file is currenlty locked exclusively by other processes, we might get INVALID_HANDLE_VALUE even though the file exists. In that case, we should return TRUE here.
goto Finished;
}

Expand All @@ -91,8 +100,6 @@ class APP_OFFLINE_HTM
goto Finished;
}

fResult = TRUE;

if( li.HighPart != 0 )
{
// > 4gb file size not supported
Expand All @@ -113,10 +120,10 @@ class APP_OFFLINE_HTM
}

Finished:
if( handle )
if( handle != INVALID_HANDLE_VALUE )
{
CloseHandle(handle);
handle = NULL;
handle = INVALID_HANDLE_VALUE;
}

if( pszBuff != NULL )
Expand Down
65 changes: 44 additions & 21 deletions src/AspNetCore/Inc/aspnetcoreconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#define CS_ROOTWEB_CONFIG L"MACHINE/WEBROOT/APPHOST/"
#define CS_ROOTWEB_CONFIG_LEN _countof(CS_ROOTWEB_CONFIG)-1
#define CS_ASPNETCORE_SECTION L"system.webServer/aspNetCore"
#define CS_WINDOWS_AUTHENTICATION_SECTION L"system.webServer/security/authentication/windowsAuthentication"
#define CS_BASIC_AUTHENTICATION_SECTION L"system.webServer/security/authentication/basicAuthentication"
#define CS_ANONYMOUS_AUTHENTICATION_SECTION L"system.webServer/security/authentication/anonymousAuthentication"
#define CS_AUTHENTICATION_ENABLED L"enabled"
#define CS_ASPNETCORE_PROCESS_EXE_PATH L"processPath"
#define CS_ASPNETCORE_PROCESS_ARGUMENTS L"arguments"
#define CS_ASPNETCORE_PROCESS_STARTUP_TIME_LIMIT L"startupTimeLimit"
Expand Down Expand Up @@ -34,7 +38,6 @@
extern HTTP_MODULE_ID g_pModuleId;
extern IHttpServer * g_pHttpServer;


class ASPNETCORE_CONFIG : IHttpStoredContext
{
public:
Expand All @@ -54,13 +57,13 @@ class ASPNETCORE_CONFIG : IHttpStoredContext
_In_ IHttpContext *pHttpContext,
_Out_ ASPNETCORE_CONFIG **ppAspNetCoreConfig
);

MULTISZ*
ENVIRONMENT_VAR_HASH*
QueryEnvironmentVariables(
VOID
)
{
return &m_mszEnvironment;
return m_pEnvironmentVariables;
}

DWORD
Expand Down Expand Up @@ -139,6 +142,24 @@ class ASPNETCORE_CONFIG : IHttpStoredContext
return m_fForwardWindowsAuthToken;
}

BOOL
QueryWindowsAuthEnabled()
{
return m_fWindowsAuthEnabled;
}

BOOL
QueryBasicAuthEnabled()
{
return m_fBasicAuthEnabled;
}

BOOL
QueryAnonymousAuthEnabled()
{
return m_fAnonymousAuthEnabled;
}

BOOL
QueryDisableStartUpErrorPage()
{
Expand All @@ -155,10 +176,10 @@ class ASPNETCORE_CONFIG : IHttpStoredContext

//
// private constructor
//

//
ASPNETCORE_CONFIG():
m_fStdoutLogEnabled( FALSE )
m_fStdoutLogEnabled( FALSE ),
m_pEnvironmentVariables( NULL )
{
}

Expand All @@ -167,18 +188,20 @@ class ASPNETCORE_CONFIG : IHttpStoredContext
IHttpContext *pHttpContext
);

DWORD m_dwRequestTimeoutInMS;
DWORD m_dwStartupTimeLimitInMS;
DWORD m_dwShutdownTimeLimitInMS;
MULTISZ m_mszEnvironment;
DWORD m_dwRapidFailsPerMinute;
STRU m_struApplication;
STRU m_struArguments;
STRU m_struProcessPath;
BOOL m_fStdoutLogEnabled;
STRU m_struStdoutLogFile;
DWORD m_dwProcessesPerApplication;
BOOL m_fForwardWindowsAuthToken;
BOOL m_fDisableStartUpErrorPage;
MULTISZ m_mszRecycleOnFileChangeFiles;
DWORD m_dwRequestTimeoutInMS;
DWORD m_dwStartupTimeLimitInMS;
DWORD m_dwShutdownTimeLimitInMS;
DWORD m_dwRapidFailsPerMinute;
DWORD m_dwProcessesPerApplication;
STRU m_struApplication;
STRU m_struArguments;
STRU m_struProcessPath;
STRU m_struStdoutLogFile;
BOOL m_fStdoutLogEnabled;
BOOL m_fForwardWindowsAuthToken;
BOOL m_fDisableStartUpErrorPage;
BOOL m_fWindowsAuthEnabled;
BOOL m_fBasicAuthEnabled;
BOOL m_fAnonymousAuthEnabled;
ENVIRONMENT_VAR_HASH* m_pEnvironmentVariables;
};
25 changes: 0 additions & 25 deletions src/AspNetCore/Inc/aspnetcoreutils.h

This file was deleted.

146 changes: 146 additions & 0 deletions src/AspNetCore/Inc/environmentvariablehash.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

#pragma once

//
// The key used for hash-table lookups, consists of the port on which the http process is created.
//

class ENVIRONMENT_VAR_ENTRY
{
public:
ENVIRONMENT_VAR_ENTRY():
_cRefs(1)
{
}

HRESULT
Initialize(
PCWSTR pszName,
PCWSTR pszValue
)
{
HRESULT hr = S_OK;
if (FAILED(hr = _strName.Copy(pszName)) ||
FAILED(hr = _strValue.Copy(pszValue)))
{
}
return hr;
}

VOID
Reference() const
{
InterlockedIncrement(&_cRefs);
}

VOID
Dereference() const
{
if (InterlockedDecrement(&_cRefs) == 0)
{
delete this;
}
}

PWSTR const
QueryName()
{
return _strName.QueryStr();
}

PWSTR const
QueryValue()
{
return _strValue.QueryStr();
}

private:
~ENVIRONMENT_VAR_ENTRY()
{
}

STRU _strName;
STRU _strValue;
mutable LONG _cRefs;
};

class ENVIRONMENT_VAR_HASH : public HASH_TABLE<ENVIRONMENT_VAR_ENTRY, PWSTR>
{
public:
ENVIRONMENT_VAR_HASH()
{}

PWSTR
ExtractKey(
ENVIRONMENT_VAR_ENTRY * pEntry
)
{
return pEntry->QueryName();
}

DWORD
CalcKeyHash(
PWSTR pszName
)
{
return HashStringNoCase(pszName);
}

BOOL
EqualKeys(
PWSTR pszName1,
PWSTR pszName2
)
{
return (_wcsicmp(pszName1, pszName2) == 0);
}

VOID
ReferenceRecord(
ENVIRONMENT_VAR_ENTRY * pEntry
)
{
pEntry->Reference();
}

VOID
DereferenceRecord(
ENVIRONMENT_VAR_ENTRY * pEntry
)
{
pEntry->Dereference();
}

static
VOID
CopyToMultiSz(
ENVIRONMENT_VAR_ENTRY * pEntry,
PVOID pvData
)
{
STRU strTemp;
MULTISZ *pMultiSz = static_cast<MULTISZ *>(pvData);
strTemp.Copy(pEntry->QueryName());
strTemp.Append(pEntry->QueryValue());
pMultiSz->Append(strTemp.QueryStr());
}

static
VOID
CopyToTable(
ENVIRONMENT_VAR_ENTRY * pEntry,
PVOID pvData
)
{
ENVIRONMENT_VAR_ENTRY * pNewEntry = new ENVIRONMENT_VAR_ENTRY();
pNewEntry->Initialize(pEntry->QueryName(), pEntry->QueryValue());
ENVIRONMENT_VAR_HASH *pHash = static_cast<ENVIRONMENT_VAR_HASH *>(pvData);
pHash->InsertRecord(pNewEntry);
}

private:
ENVIRONMENT_VAR_HASH(const ENVIRONMENT_VAR_HASH &);
void operator=(const ENVIRONMENT_VAR_HASH &);
};
Loading