Driver class is extending the Rules class instead of duplicate elements

This commit is contained in:
Felipe Zimmerle 2015-07-23 00:08:57 -03:00
parent dc0b13ad74
commit d3eb0fd913
6 changed files with 25 additions and 55 deletions

View File

@ -32,8 +32,6 @@ typedef struct Assay_t Assay;
#include "modsecurity/modsecurity.h" #include "modsecurity/modsecurity.h"
#include "modsecurity/assay.h" #include "modsecurity/assay.h"
#include "modsecurity/debug_log.h"
#ifdef __cplusplus #ifdef __cplusplus
class Driver; class Driver;
@ -144,7 +142,7 @@ class Rules {
int requestBodyLimitAction; int requestBodyLimitAction;
int responseBodyLimitAction; int responseBodyLimitAction;
std::string parserError; std::ostringstream parserError;
AuditLog *audit_log; AuditLog *audit_log;

View File

@ -109,7 +109,6 @@ bool AuditLog::init() {
if (m_type == ParallelAuditLogType) { if (m_type == ParallelAuditLogType) {
m_writer = new AuditLogWriterParallel(this); m_writer = new AuditLogWriterParallel(this);
} }
if (m_type == SerialAuditLogType) { if (m_type == SerialAuditLogType) {
m_writer = new AuditLogWriterSerial(this); m_writer = new AuditLogWriterSerial(this);
} }

View File

@ -16,14 +16,14 @@
#include "parser/driver.h" #include "parser/driver.h"
#include "parser/seclang-parser.hh" #include "parser/seclang-parser.hh"
#include "src/audit_log.h"
Driver::Driver() Driver::Driver()
: trace_scanning(false), : trace_scanning(false),
trace_parsing(false), trace_parsing(false) {
requestBodyLimit(0), audit_log = new ModSecurity::AuditLog();
responseBodyLimit(0), }
audit_log(new ModSecurity::AuditLog()) {
}
Driver::~Driver() { Driver::~Driver() {
@ -74,7 +74,7 @@ int Driver::parse(const std::string &f) {
int res = parser.parse(); int res = parser.parse();
if (this->audit_log->init() == false) { if (audit_log->init() == false) {
return false; return false;
} }

View File

@ -26,11 +26,13 @@
#include "modsecurity/modsecurity.h" #include "modsecurity/modsecurity.h"
#include "src/rule.h" #include "src/rule.h"
#include "modsecurity/rules.h"
#include "src/audit_log.h" #include "src/audit_log.h"
#include "parser/seclang-parser.hh" #include "parser/seclang-parser.hh"
using ModSecurity::Rule; using ModSecurity::Rule;
using ModSecurity::Rules;
# define YY_DECL \ # define YY_DECL \
yy::seclang_parser::symbol_type yylex(Driver& driver) yy::seclang_parser::symbol_type yylex(Driver& driver)
@ -45,7 +47,7 @@ typedef struct Driver_t Driver;
#endif #endif
class Driver { class Driver : public Rules {
/** /**
* @todo Place driver and parser under the correct namespace. * @todo Place driver and parser under the correct namespace.
* *
@ -79,28 +81,8 @@ class Driver {
// Error handling. // Error handling.
void error(const yy::location& l, const std::string& m); void error(const yy::location& l, const std::string& m);
void parser_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); void error(const yy::location& l, const std::string& m,
const std::string& c);
std::vector<Rule *> 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<std::string> components;
std::ostringstream parserError;
std::ostringstream syntaxError;
ModSecurity::AuditLog *audit_log;
int debug_level;
}; };
#endif // SRC_PARSER_DRIVER_H_ #endif // SRC_PARSER_DRIVER_H_

View File

@ -16,6 +16,7 @@ class Driver;
#include "operators/operator.h" #include "operators/operator.h"
#include "rule.h" #include "rule.h"
#include "utils/geo_lookup.h" #include "utils/geo_lookup.h"
#include "audit_log.h"
#include "variables/duration.h" #include "variables/duration.h"
#include "variables/env.h" #include "variables/env.h"

View File

@ -101,7 +101,7 @@ int Rules::loadFromUri(char *uri) {
Rules::~Rules() { Rules::~Rules() {
audit_log->refCountDecreaseAndCheck(); // audit_log->refCountDecreaseAndCheck();
} }
@ -124,7 +124,7 @@ int Rules::load(const char *plain_rules) {
Driver *driver = new Driver(); Driver *driver = new Driver();
if (driver->parse("/tmp/modsec_ugly_hack.txt")) { if (driver->parse("/tmp/modsec_ugly_hack.txt")) {
ret = false; ret = false;
parserError = driver->parserError.str(); parserError << driver->parserError.rdbuf();
} }
this->merge(driver); this->merge(driver);
delete driver; delete driver;
@ -134,7 +134,7 @@ int Rules::load(const char *plain_rules) {
std::string Rules::getParserError() { 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->requestBodyLimitAction = from->requestBodyLimitAction;
this->responseBodyLimitAction = from->responseBodyLimitAction; 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();
}
/* this->audit_log = from->audit_log;
if (from->debug_log->isConfigured())
{ this->debug_log->setDebugLevel(this->debug_level);
if (this->debug_log_path.compare(from->debug_log_path) != 0) this->debug_log->setOutputFile(this->debug_log_path);
{
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
{
}
*/
return 0; return 0;
} }