websocket enabled check (#612)

This commit is contained in:
pan-wang 2018-02-27 11:28:27 -08:00 committed by GitHub
parent 792b72e71a
commit 71b90a31a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 66 additions and 8 deletions

View File

@ -148,6 +148,7 @@ ASPNETCORE_CONFIG::Populate(
IAppHostElement *pWindowsAuthenticationElement = NULL; IAppHostElement *pWindowsAuthenticationElement = NULL;
IAppHostElement *pBasicAuthenticationElement = NULL; IAppHostElement *pBasicAuthenticationElement = NULL;
IAppHostElement *pAnonymousAuthenticationElement = NULL; IAppHostElement *pAnonymousAuthenticationElement = NULL;
IAppHostElement *pWebSocketElement = NULL;
IAppHostElement *pEnvVarList = NULL; IAppHostElement *pEnvVarList = NULL;
IAppHostElement *pEnvVar = NULL; IAppHostElement *pEnvVar = NULL;
IAppHostElementCollection *pEnvVarCollection = NULL; IAppHostElementCollection *pEnvVarCollection = NULL;
@ -161,6 +162,7 @@ ASPNETCORE_CONFIG::Populate(
BSTR bstrBasicAuthSection = NULL; BSTR bstrBasicAuthSection = NULL;
BSTR bstrAnonymousAuthSection = NULL; BSTR bstrAnonymousAuthSection = NULL;
BSTR bstrAspNetCoreSection = NULL; BSTR bstrAspNetCoreSection = NULL;
BSTR bstrWebsocketSection = NULL;
m_pEnvironmentVariables = new ENVIRONMENT_VAR_HASH(); m_pEnvironmentVariables = new ENVIRONMENT_VAR_HASH();
if (m_pEnvironmentVariables == NULL) if (m_pEnvironmentVariables == NULL)
@ -235,7 +237,7 @@ ASPNETCORE_CONFIG::Populate(
else else
{ {
hr = GetElementBoolProperty(pWindowsAuthenticationElement, hr = GetElementBoolProperty(pWindowsAuthenticationElement,
CS_AUTHENTICATION_ENABLED, CS_ENABLED,
&m_fWindowsAuthEnabled); &m_fWindowsAuthEnabled);
if (FAILED(hr)) if (FAILED(hr))
{ {
@ -259,7 +261,7 @@ ASPNETCORE_CONFIG::Populate(
else else
{ {
hr = GetElementBoolProperty(pBasicAuthenticationElement, hr = GetElementBoolProperty(pBasicAuthenticationElement,
CS_AUTHENTICATION_ENABLED, CS_ENABLED,
&m_fBasicAuthEnabled); &m_fBasicAuthEnabled);
if (FAILED(hr)) if (FAILED(hr))
{ {
@ -282,7 +284,7 @@ ASPNETCORE_CONFIG::Populate(
else else
{ {
hr = GetElementBoolProperty(pAnonymousAuthenticationElement, hr = GetElementBoolProperty(pAnonymousAuthenticationElement,
CS_AUTHENTICATION_ENABLED, CS_ENABLED,
&m_fAnonymousAuthEnabled); &m_fAnonymousAuthEnabled);
if (FAILED(hr)) if (FAILED(hr))
{ {
@ -290,6 +292,31 @@ ASPNETCORE_CONFIG::Populate(
} }
} }
bstrWebsocketSection = SysAllocString(CS_WEBSOCKET_SECTION);
if (bstrWebsocketSection == NULL)
{
hr = E_OUTOFMEMORY;
goto Finished;
}
hr = pAdminManager->GetAdminSection(bstrWebsocketSection,
m_struConfigPath.QueryStr(),
&pWebSocketElement);
if (FAILED(hr))
{
m_fWebSocketEnabled = FALSE;
}
else
{
hr = GetElementBoolProperty(pWebSocketElement,
CS_ENABLED,
&m_fWebSocketEnabled);
if (FAILED(hr))
{
goto Finished;
}
}
bstrAspNetCoreSection = SysAllocString(CS_ASPNETCORE_SECTION); bstrAspNetCoreSection = SysAllocString(CS_ASPNETCORE_SECTION);
if (bstrAspNetCoreSection == NULL) if (bstrAspNetCoreSection == NULL)
{ {
@ -500,6 +527,30 @@ Finished:
pAspNetCoreElement = NULL; pAspNetCoreElement = NULL;
} }
if (pWebSocketElement != NULL)
{
pWebSocketElement->Release();
pWebSocketElement = NULL;
}
if (pWindowsAuthenticationElement != NULL)
{
pWindowsAuthenticationElement->Release();
pWindowsAuthenticationElement = NULL;
}
if (pAnonymousAuthenticationElement!= NULL)
{
pAnonymousAuthenticationElement->Release();
pAnonymousAuthenticationElement = NULL;
}
if (pBasicAuthenticationElement != NULL)
{
pBasicAuthenticationElement->Release();
pBasicAuthenticationElement = NULL;
}
if (pEnvVarList != NULL) if (pEnvVarList != NULL)
{ {
pEnvVarList->Release(); pEnvVarList->Release();

View File

@ -8,7 +8,8 @@
#define CS_WINDOWS_AUTHENTICATION_SECTION L"system.webServer/security/authentication/windowsAuthentication" #define CS_WINDOWS_AUTHENTICATION_SECTION L"system.webServer/security/authentication/windowsAuthentication"
#define CS_BASIC_AUTHENTICATION_SECTION L"system.webServer/security/authentication/basicAuthentication" #define CS_BASIC_AUTHENTICATION_SECTION L"system.webServer/security/authentication/basicAuthentication"
#define CS_ANONYMOUS_AUTHENTICATION_SECTION L"system.webServer/security/authentication/anonymousAuthentication" #define CS_ANONYMOUS_AUTHENTICATION_SECTION L"system.webServer/security/authentication/anonymousAuthentication"
#define CS_AUTHENTICATION_ENABLED L"enabled" #define CS_WEBSOCKET_SECTION L"system.webServer/webSocket"
#define CS_ENABLED L"enabled"
#define CS_ASPNETCORE_PROCESS_EXE_PATH L"processPath" #define CS_ASPNETCORE_PROCESS_EXE_PATH L"processPath"
#define CS_ASPNETCORE_PROCESS_ARGUMENTS L"arguments" #define CS_ASPNETCORE_PROCESS_ARGUMENTS L"arguments"
#define CS_ASPNETCORE_PROCESS_STARTUP_TIME_LIMIT L"startupTimeLimit" #define CS_ASPNETCORE_PROCESS_STARTUP_TIME_LIMIT L"startupTimeLimit"
@ -154,7 +155,7 @@ public:
STRU* STRU*
QueryProcessPath( QueryProcessPath(
VOID VOID
) )
{ {
return &m_struProcessPath; return &m_struProcessPath;
} }
@ -168,11 +169,17 @@ public:
} }
BOOL BOOL
QueryStdoutLogEnabled() QueryStdoutLogEnabled()
{ {
return m_fStdoutLogEnabled; return m_fStdoutLogEnabled;
} }
BOOL
QueryWebSocketEnabled()
{
return m_fWebSocketEnabled;
}
BOOL BOOL
QueryForwardWindowsAuthToken() QueryForwardWindowsAuthToken()
{ {
@ -315,7 +322,7 @@ private:
BOOL m_fWindowsAuthEnabled; BOOL m_fWindowsAuthEnabled;
BOOL m_fBasicAuthEnabled; BOOL m_fBasicAuthEnabled;
BOOL m_fAnonymousAuthEnabled; BOOL m_fAnonymousAuthEnabled;
BOOL m_fIsStandAloneApplication; BOOL m_fWebSocketEnabled;
APP_HOSTING_MODEL m_hostingModel; APP_HOSTING_MODEL m_hostingModel;
ENVIRONMENT_VAR_HASH* m_pEnvironmentVariables; ENVIRONMENT_VAR_HASH* m_pEnvironmentVariables;
STRU m_struHostFxrLocation; STRU m_struHostFxrLocation;

View File

@ -165,7 +165,7 @@ FORWARDING_HANDLER::OnExecuteRequestHandler()
// //
// Mark request as websocket if upgrade header is present. // Mark request as websocket if upgrade header is present.
// //
if (g_fWebSocketSupported) if (pApplication->QueryConfig()->QueryWebSocketEnabled())
{ {
USHORT cchHeader = 0; USHORT cchHeader = 0;
PCSTR pszWebSocketHeader = pRequest->GetHeader("Upgrade", &cchHeader); PCSTR pszWebSocketHeader = pRequest->GetHeader("Upgrade", &cchHeader);