Skip to content

Commit b304ab1

Browse files
author
Felipe Zimmerle
committed
Improves SecRemoteRules messages on IIS
IIS was not displaying correctly the error messages and the amount of loaded rules while the operator SecRemoteRules was used.
1 parent f7c7a30 commit b304ab1

File tree

5 files changed

+46
-13
lines changed

5 files changed

+46
-13
lines changed

apache2/mod_security2.c

+4-9
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ static int hook_post_config(apr_pool_t *mp, apr_pool_t *mp_log, apr_pool_t *mp_t
752752
real_server_signature);
753753
}
754754

755-
#ifndef WIN32
755+
#ifndef VERSION_IIS
756756
if (status_engine_state != STATUS_ENGINE_DISABLED) {
757757
msc_status_engine_call();
758758
}
@@ -767,18 +767,12 @@ static int hook_post_config(apr_pool_t *mp, apr_pool_t *mp_log, apr_pool_t *mp_t
767767
/**
768768
* Checking if it is not the first time that we are in this very function.
769769
* We want to show the messages below during the start and the reload.
770-
*
771-
* Turns out that IIS version does not hit it twice, thus, we have to show
772-
* the message in the first (and unique) opportunity.
773770
*/
774-
#ifdef VERSION_IIS
775-
if (first_time == 1)
776-
{
777-
#else
771+
#ifndef VERSION_IIS
778772
if (first_time != 1)
779773
{
780-
#endif
781774
#ifdef WITH_REMOTE_RULES
775+
782776
if (remote_rules_server != NULL)
783777
{
784778
if (remote_rules_server->amount_of_rules == 1)
@@ -804,6 +798,7 @@ static int hook_post_config(apr_pool_t *mp, apr_pool_t *mp_log, apr_pool_t *mp_t
804798
remote_rules_fail_message);
805799
}
806800
}
801+
#endif
807802

808803
srand((unsigned int)(time(NULL) * getpid()));
809804

iis/mymodule.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -797,8 +797,12 @@ CMyHttpModule::OnBeginRequest(
797797
goto Finished;
798798
}
799799

800-
modsecStatusEngineCall();
801-
800+
modsecReportRemoteLoadedRules();
801+
if (this->status_call_already_sent == false)
802+
{
803+
this->status_call_already_sent = true;
804+
modsecStatusEngineCall();
805+
}
802806
}
803807
delete apppath;
804808
}
@@ -1254,6 +1258,8 @@ CMyHttpModule::CMyHttpModule()
12541258
GetSystemInfo(&sysInfo);
12551259
m_dwPageSize = sysInfo.dwPageSize;
12561260

1261+
this->status_call_already_sent = false;
1262+
12571263
InitializeCriticalSection(&m_csLock);
12581264

12591265
modsecSetLogHook(this, Log);

iis/mymodule.h

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class CMyHttpModule : public CHttpModule
5252
void Dispose();
5353

5454
BOOL WriteEventViewerLog(LPCSTR szNotification, WORD category = EVENTLOG_INFORMATION_TYPE);
55+
BOOL status_call_already_sent;
5556
};
5657

5758
#endif

standalone/api.c

+31-1
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ const char *modsecIsServerSignatureAvailale(void) {
705705
return new_server_signature;
706706
}
707707

708-
#ifdef WIN32
708+
#ifdef VERSION_IIS
709709
void modsecStatusEngineCall()
710710
{
711711
if (status_engine_state != STATUS_ENGINE_DISABLED) {
@@ -717,4 +717,34 @@ void modsecStatusEngineCall()
717717
"SecStatusEngine to On.\n");
718718
}
719719
}
720+
721+
void modsecReportRemoteLoadedRules()
722+
{
723+
#ifdef WITH_REMOTE_RULES
724+
if (remote_rules_server != NULL)
725+
{
726+
if (remote_rules_server->amount_of_rules == 1)
727+
{
728+
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL,
729+
"ModSecurity: Loaded %d rule from: '%s'.",
730+
remote_rules_server->amount_of_rules,
731+
remote_rules_server->uri);
732+
}
733+
else
734+
{
735+
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL,
736+
"ModSecurity: Loaded %d rules from: '%s'.",
737+
remote_rules_server->amount_of_rules,
738+
remote_rules_server->uri);
739+
}
740+
}
741+
#endif
742+
if (remote_rules_fail_message != NULL)
743+
{
744+
ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, NULL, "ModSecurity: " \
745+
"Problems loading external resources: %s",
746+
remote_rules_fail_message);
747+
}
748+
749+
}
720750
#endif

standalone/api.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ void modsecSetConfigForIISRequestBody(request_rec *r);
119119

120120
const char *modsecIsServerSignatureAvailale(void);
121121

122-
#ifdef WIN32
122+
#ifdef VERSION_IIS
123123
void modsecStatusEngineCall(void);
124+
void modsecReportRemoteLoadedRules(void);
124125
#endif
125126

126127
#ifdef __cplusplus

0 commit comments

Comments
 (0)