IIS: no lock on ProcessRequest. No reload of config. (#24)

IIS: no lock on ProcessRequest. No reload of config.
This commit is contained in:
Allan Boll 2018-06-06 20:08:03 -07:00 committed by Felipe Zimmerle
parent 6bc838eeaf
commit 51a9717601
No known key found for this signature in database
GPG Key ID: E6DFB08CE8B11277
3 changed files with 26 additions and 46 deletions

View File

@ -466,11 +466,8 @@ MODSECURITY_STORED_CONTEXT::~MODSECURITY_STORED_CONTEXT()
MODSECURITY_STORED_CONTEXT::MODSECURITY_STORED_CONTEXT(): MODSECURITY_STORED_CONTEXT::MODSECURITY_STORED_CONTEXT():
m_bIsEnabled ( FALSE ), m_bIsEnabled ( FALSE ),
m_pszPath( NULL ), m_pszPath( NULL ),
m_Config( NULL ), m_Config( NULL )
m_dwLastCheck( 0 )
{ {
m_LastChange.dwLowDateTime = 0;
m_LastChange.dwHighDateTime = 0;
} }
DWORD DWORD

View File

@ -68,8 +68,6 @@ class MODSECURITY_STORED_CONTEXT : public IHttpStoredContext
USHORT* pdwLengthDestination ); USHORT* pdwLengthDestination );
void* m_Config; void* m_Config;
DWORD m_dwLastCheck;
FILETIME m_LastChange;
private: private:
HRESULT HRESULT

View File

@ -818,11 +818,7 @@ CMyHttpModule::OnBeginRequest(
goto Finished; goto Finished;
} }
// every 3 seconds we check for changes in config file if(pConfig->m_Config == NULL)
//
DWORD ctime = GetTickCount();
if(pConfig->m_Config == NULL || (ctime - pConfig->m_dwLastCheck) > 3000)
{ {
char *path; char *path;
USHORT pathlen; USHORT pathlen;
@ -835,55 +831,42 @@ CMyHttpModule::OnBeginRequest(
goto Finished; goto Finished;
} }
WIN32_FILE_ATTRIBUTE_DATA fdata; pConfig->m_Config = modsecGetDefaultConfig();
BOOL ret;
ret = GetFileAttributesEx(path, GetFileExInfoStandard, &fdata); PCWSTR servpath = pHttpContext->GetApplication()->GetApplicationPhysicalPath();
char *apppath;
USHORT apppathlen;
pConfig->m_dwLastCheck = ctime; hr = pConfig->GlobalWideCharToMultiByte((WCHAR *)servpath, wcslen(servpath), &apppath, &apppathlen);
if(pConfig->m_Config == NULL || (ret != 0 && (pConfig->m_LastChange.dwLowDateTime != fdata.ftLastWriteTime.dwLowDateTime || if ( FAILED( hr ) )
pConfig->m_LastChange.dwHighDateTime != fdata.ftLastWriteTime.dwHighDateTime)))
{ {
pConfig->m_LastChange.dwLowDateTime = fdata.ftLastWriteTime.dwLowDateTime; delete path;
pConfig->m_LastChange.dwHighDateTime = fdata.ftLastWriteTime.dwHighDateTime; hr = E_UNEXPECTED;
goto Finished;
}
pConfig->m_Config = modsecGetDefaultConfig(); if(path[0] != 0)
{
const char * err = modsecProcessConfig((directory_config *)pConfig->m_Config, path, apppath);
PCWSTR servpath = pHttpContext->GetApplication()->GetApplicationPhysicalPath(); if(err != NULL)
char *apppath;
USHORT apppathlen;
hr = pConfig->GlobalWideCharToMultiByte((WCHAR *)servpath, wcslen(servpath), &apppath, &apppathlen);
if ( FAILED( hr ) )
{ {
WriteEventViewerLog(err, EVENTLOG_ERROR_TYPE);
delete apppath;
delete path; delete path;
hr = E_UNEXPECTED;
goto Finished; goto Finished;
} }
if(path[0] != 0) modsecReportRemoteLoadedRules();
if (this->status_call_already_sent == false)
{ {
const char * err = modsecProcessConfig((directory_config *)pConfig->m_Config, path, apppath); this->status_call_already_sent = true;
modsecStatusEngineCall();
if(err != NULL)
{
WriteEventViewerLog(err, EVENTLOG_ERROR_TYPE);
delete apppath;
delete path;
goto Finished;
}
modsecReportRemoteLoadedRules();
if (this->status_call_already_sent == false)
{
this->status_call_already_sent = true;
modsecStatusEngineCall();
}
} }
delete apppath;
} }
delete apppath;
delete path; delete path;
} }
@ -1140,7 +1123,9 @@ CMyHttpModule::OnBeginRequest(
#endif #endif
c->remote_host = NULL; c->remote_host = NULL;
LeaveCriticalSection(&m_csLock);
int status = modsecProcessRequest(r); int status = modsecProcessRequest(r);
EnterCriticalSection(&m_csLock);
if(status != DECLINED) if(status != DECLINED)
{ {