2121
2222#include < fstream>
2323
24+ #include " modsecurity/transaction.h"
2425#include " modsecurity/rule_message.h"
2526#include " src/audit_log/writer/https.h"
2627#include " src/audit_log/writer/parallel.h"
@@ -61,7 +62,8 @@ AuditLog::AuditLog()
6162 m_status(NotSetLogStatus),
6263 m_type(NotSetAuditLogType),
6364 m_relevant(" " ),
64- m_writer(NULL ) { }
65+ m_writer(NULL ),
66+ m_ctlAuditEngineActive(false ) { }
6567
6668
6769AuditLog::~AuditLog () {
@@ -210,7 +212,8 @@ bool AuditLog::setType(AuditLogType audit_type) {
210212bool AuditLog::init (std::string *error) {
211213 audit_log::writer::Writer *tmp_writer;
212214
213- if (m_status == OffAuditLogStatus || m_status == NotSetLogStatus) {
215+ if ((m_status == OffAuditLogStatus || m_status == NotSetLogStatus)
216+ && !m_ctlAuditEngineActive) {
214217 if (m_writer) {
215218 delete m_writer;
216219 m_writer = NULL ;
@@ -275,7 +278,13 @@ bool AuditLog::saveIfRelevant(Transaction *transaction) {
275278
276279bool AuditLog::saveIfRelevant (Transaction *transaction, int parts) {
277280 bool saveAnyway = false ;
278- if (m_status == OffAuditLogStatus || m_status == NotSetLogStatus) {
281+
282+ AuditLogStatus transactionAuditLogStatus (m_status);
283+ if (transaction->m_ctlAuditEngine != NotSetLogStatus) {
284+ transactionAuditLogStatus = transaction->m_ctlAuditEngine ;
285+ }
286+
287+ if (transactionAuditLogStatus == OffAuditLogStatus || transactionAuditLogStatus == NotSetLogStatus) {
279288 ms_dbg_a (transaction, 5 , " Audit log engine was not set." );
280289 return true ;
281290 }
@@ -287,7 +296,7 @@ bool AuditLog::saveIfRelevant(Transaction *transaction, int parts) {
287296 }
288297 }
289298
290- if ((m_status == RelevantOnlyAuditLogStatus
299+ if ((transactionAuditLogStatus == RelevantOnlyAuditLogStatus
291300 && this ->isRelevant (transaction->m_httpCodeReturned ) == false )
292301 && saveAnyway == false ) {
293302 ms_dbg_a (transaction, 9 , " Return code `" +
@@ -353,6 +362,10 @@ bool AuditLog::merge(AuditLog *from, std::string *error) {
353362 m_format = from->m_format ;
354363 }
355364
365+ if (from->m_ctlAuditEngineActive ) {
366+ m_ctlAuditEngineActive = from->m_ctlAuditEngineActive ;
367+ }
368+
356369 return init (error);
357370}
358371
0 commit comments