diff --git a/headers/modsecurity/rules.h b/headers/modsecurity/rules.h index dcb9c445..ba511832 100644 --- a/headers/modsecurity/rules.h +++ b/headers/modsecurity/rules.h @@ -32,8 +32,6 @@ typedef struct Assay_t Assay; #include "modsecurity/modsecurity.h" #include "modsecurity/assay.h" -#include "modsecurity/debug_log.h" - #ifdef __cplusplus class Driver; @@ -144,7 +142,7 @@ class Rules { int requestBodyLimitAction; int responseBodyLimitAction; - std::string parserError; + std::ostringstream parserError; AuditLog *audit_log; diff --git a/src/audit_log.cc b/src/audit_log.cc index a051d041..7975a156 100644 --- a/src/audit_log.cc +++ b/src/audit_log.cc @@ -109,7 +109,6 @@ bool AuditLog::init() { if (m_type == ParallelAuditLogType) { m_writer = new AuditLogWriterParallel(this); } - if (m_type == SerialAuditLogType) { m_writer = new AuditLogWriterSerial(this); } diff --git a/src/parser/driver.cc b/src/parser/driver.cc index 3762d3eb..777fb7d0 100644 --- a/src/parser/driver.cc +++ b/src/parser/driver.cc @@ -16,14 +16,14 @@ #include "parser/driver.h" #include "parser/seclang-parser.hh" +#include "src/audit_log.h" + Driver::Driver() : trace_scanning(false), - trace_parsing(false), - requestBodyLimit(0), - responseBodyLimit(0), - audit_log(new ModSecurity::AuditLog()) { -} + trace_parsing(false) { + audit_log = new ModSecurity::AuditLog(); + } Driver::~Driver() { @@ -74,7 +74,7 @@ int Driver::parse(const std::string &f) { int res = parser.parse(); - if (this->audit_log->init() == false) { + if (audit_log->init() == false) { return false; } diff --git a/src/parser/driver.h b/src/parser/driver.h index 56c670ef..5b7ed81d 100644 --- a/src/parser/driver.h +++ b/src/parser/driver.h @@ -26,11 +26,13 @@ #include "modsecurity/modsecurity.h" #include "src/rule.h" +#include "modsecurity/rules.h" #include "src/audit_log.h" #include "parser/seclang-parser.hh" using ModSecurity::Rule; +using ModSecurity::Rules; # define YY_DECL \ yy::seclang_parser::symbol_type yylex(Driver& driver) @@ -45,7 +47,7 @@ typedef struct Driver_t Driver; #endif -class Driver { +class Driver : public Rules { /** * @todo Place driver and parser under the correct namespace. * @@ -79,28 +81,8 @@ class Driver { // Error handling. void error(const yy::location& l, const std::string& m); void parser_error(const yy::location& l, const std::string& m); - void error(const yy::location& l, const std::string& m, const std::string& c); - - std::vector rules[7]; // Number of Phases. - - ModSecurity::Rules::RuleEngine secRuleEngine; - int sec_audit_type; - bool sec_audit_engine; - bool sec_request_body_access; - bool sec_response_body_access; - int requestBodyLimit; - int responseBodyLimit; - int requestBodyLimitAction; - int responseBodyLimitAction; - - std::string debug_log_path; - std::list components; - std::ostringstream parserError; - std::ostringstream syntaxError; - - ModSecurity::AuditLog *audit_log; - - int debug_level; + void error(const yy::location& l, const std::string& m, + const std::string& c); }; #endif // SRC_PARSER_DRIVER_H_ diff --git a/src/parser/seclang-parser.yy b/src/parser/seclang-parser.yy index 0468be9a..09955d21 100644 --- a/src/parser/seclang-parser.yy +++ b/src/parser/seclang-parser.yy @@ -16,6 +16,7 @@ class Driver; #include "operators/operator.h" #include "rule.h" #include "utils/geo_lookup.h" +#include "audit_log.h" #include "variables/duration.h" #include "variables/env.h" diff --git a/src/rules.cc b/src/rules.cc index 7f01dfa8..a6ff0a62 100644 --- a/src/rules.cc +++ b/src/rules.cc @@ -101,7 +101,7 @@ int Rules::loadFromUri(char *uri) { Rules::~Rules() { - audit_log->refCountDecreaseAndCheck(); + // audit_log->refCountDecreaseAndCheck(); } @@ -124,7 +124,7 @@ int Rules::load(const char *plain_rules) { Driver *driver = new Driver(); if (driver->parse("/tmp/modsec_ugly_hack.txt")) { ret = false; - parserError = driver->parserError.str(); + parserError << driver->parserError.rdbuf(); } this->merge(driver); delete driver; @@ -134,7 +134,7 @@ int Rules::load(const char *plain_rules) { std::string Rules::getParserError() { - return this->parserError; + return this->parserError.str(); } @@ -216,26 +216,16 @@ int Rules::merge(Rules *from) { this->requestBodyLimitAction = from->requestBodyLimitAction; this->responseBodyLimitAction = from->responseBodyLimitAction; - this->debug_log = from->debug_log; + if (m_custom_debug_log) { + this->debug_log = m_custom_debug_log->new_instance(); + } else { + this->debug_log = new DebugLog(); + } - /* - if (from->debug_log->isConfigured()) - { - if (this->debug_log_path.compare(from->debug_log_path) != 0) - { - this->debug_log = new DebugLog(); - this->debug_log->setDebugLevel(from->debug_level); - this->debug_log->setOutputFile(this->debug_log_path); - } - if (this->debug_level != from->debug_level) - { - this->debug_log->setDebugLevel(this->debug_log); - } - } - else - { - } - */ + this->audit_log = from->audit_log; + + this->debug_log->setDebugLevel(this->debug_level); + this->debug_log->setOutputFile(this->debug_log_path); return 0; }