mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-10-01 03:57:47 +03:00
Yet another refactoring in Rule
This commit is contained in:
@@ -44,7 +44,7 @@ Driver::~Driver() {
|
||||
int Driver::addSecMarker(std::string marker) {
|
||||
for (int i = 0; i < modsecurity::Phases::NUMBER_OF_PHASES; i++) {
|
||||
std::unique_ptr<Rule> rule(new Rule(marker));
|
||||
rule->m_phase = i;
|
||||
rule->setPhase(i);
|
||||
m_rulesSetPhases.insert(std::move(rule));
|
||||
}
|
||||
return 0;
|
||||
@@ -52,8 +52,8 @@ int Driver::addSecMarker(std::string marker) {
|
||||
|
||||
|
||||
int Driver::addSecAction(std::unique_ptr<Rule> rule) {
|
||||
if (rule->m_phase >= modsecurity::Phases::NUMBER_OF_PHASES) {
|
||||
m_parserError << "Unknown phase: " << std::to_string(rule->m_phase);
|
||||
if (rule->getPhase() >= modsecurity::Phases::NUMBER_OF_PHASES) {
|
||||
m_parserError << "Unknown phase: " << std::to_string(rule->getPhase());
|
||||
m_parserError << std::endl;
|
||||
return false;
|
||||
}
|
||||
@@ -72,16 +72,16 @@ int Driver::addSecRuleScript(std::unique_ptr<RuleScript> rule) {
|
||||
|
||||
|
||||
int Driver::addSecRule(std::unique_ptr<Rule> r) {
|
||||
if (r->m_phase >= modsecurity::Phases::NUMBER_OF_PHASES) {
|
||||
m_parserError << "Unknown phase: " << std::to_string(r->m_phase);
|
||||
if (r->getPhase() >= modsecurity::Phases::NUMBER_OF_PHASES) {
|
||||
m_parserError << "Unknown phase: " << std::to_string(r->getPhase());
|
||||
m_parserError << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* is it a chained rule? */
|
||||
if (m_lastRule != nullptr && m_lastRule->m_chained) {
|
||||
r->m_phase = m_lastRule->m_phase;
|
||||
if (r->m_theDisruptiveAction) {
|
||||
if (m_lastRule != nullptr && m_lastRule->isChained()) {
|
||||
r->setPhase(m_lastRule->getPhase());
|
||||
if (r->hasDisruptiveAction()) {
|
||||
m_parserError << "Disruptive actions can only be specified by";
|
||||
m_parserError << " chain starter rules.";
|
||||
return false;
|
||||
@@ -148,7 +148,7 @@ int Driver::parse(const std::string &f, const std::string &ref) {
|
||||
*
|
||||
*/
|
||||
/*
|
||||
if (m_lastRule != nullptr && m_lastRule->m_chained) {
|
||||
if (m_lastRule != nullptr && m_lastRule->isChained()) {
|
||||
m_parserError << "Last rule is marked as chained but there " \
|
||||
"isn't a subsequent rule." << std::endl;
|
||||
return false;
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -99,12 +99,12 @@ class Driver;
|
||||
#include "src/actions/skip_after.h"
|
||||
#include "src/actions/skip.h"
|
||||
#include "src/actions/tag.h"
|
||||
#include "src/actions/transformations/none.h"
|
||||
#include "src/actions/transformations/transformation.h"
|
||||
#include "src/actions/transformations/url_decode_uni.h"
|
||||
#include "src/actions/ver.h"
|
||||
#include "src/actions/xmlns.h"
|
||||
|
||||
#include "src/actions/transformations/none.h"
|
||||
#include "src/actions/transformations/transformation.h"
|
||||
#include "src/actions/transformations/url_decode_uni.h"
|
||||
#include "src/actions/transformations/hex_encode.h"
|
||||
#include "src/actions/transformations/parity_even_7bit.h"
|
||||
#include "src/actions/transformations/utf8_to_unicode.h"
|
||||
|
@@ -61,12 +61,12 @@ class Driver;
|
||||
#include "src/actions/skip_after.h"
|
||||
#include "src/actions/skip.h"
|
||||
#include "src/actions/tag.h"
|
||||
#include "src/actions/transformations/none.h"
|
||||
#include "src/actions/transformations/transformation.h"
|
||||
#include "src/actions/transformations/url_decode_uni.h"
|
||||
#include "src/actions/ver.h"
|
||||
#include "src/actions/xmlns.h"
|
||||
|
||||
#include "src/actions/transformations/none.h"
|
||||
#include "src/actions/transformations/transformation.h"
|
||||
#include "src/actions/transformations/url_decode_uni.h"
|
||||
#include "src/actions/transformations/hex_encode.h"
|
||||
#include "src/actions/transformations/parity_even_7bit.h"
|
||||
#include "src/actions/transformations/utf8_to_unicode.h"
|
||||
@@ -1067,8 +1067,13 @@ expression:
|
||||
| DIRECTIVE variables op actions
|
||||
{
|
||||
std::vector<actions::Action *> *a = new std::vector<actions::Action *>();
|
||||
std::vector<actions::transformations::Transformation *> *t = new std::vector<actions::transformations::Transformation *>();
|
||||
for (auto &i : *$4.get()) {
|
||||
a->push_back(i.release());
|
||||
if (dynamic_cast<actions::transformations::Transformation *>(i.get())) {
|
||||
t->push_back(dynamic_cast<actions::transformations::Transformation *>(i.release()));
|
||||
} else {
|
||||
a->push_back(i.release());
|
||||
}
|
||||
}
|
||||
variables::Variables *v = new variables::Variables();
|
||||
for (auto &i : *$2.get()) {
|
||||
@@ -1080,6 +1085,7 @@ expression:
|
||||
/* op */ op,
|
||||
/* variables */ v,
|
||||
/* actions */ a,
|
||||
/* transformations */ t,
|
||||
/* file name */ std::unique_ptr<std::string>(new std::string(*@1.end.filename)),
|
||||
/* line number */ @1.end.line
|
||||
));
|
||||
@@ -1099,6 +1105,7 @@ expression:
|
||||
/* op */ $3.release(),
|
||||
/* variables */ v,
|
||||
/* actions */ NULL,
|
||||
/* transformations */ NULL,
|
||||
/* file name */ std::unique_ptr<std::string>(new std::string(*@1.end.filename)),
|
||||
/* line number */ @1.end.line
|
||||
));
|
||||
@@ -1109,13 +1116,19 @@ expression:
|
||||
| CONFIG_DIR_SEC_ACTION actions
|
||||
{
|
||||
std::vector<actions::Action *> *a = new std::vector<actions::Action *>();
|
||||
std::vector<actions::transformations::Transformation *> *t = new std::vector<actions::transformations::Transformation *>();
|
||||
for (auto &i : *$2.get()) {
|
||||
a->push_back(i.release());
|
||||
if (dynamic_cast<actions::transformations::Transformation *>(i.get())) {
|
||||
t->push_back(dynamic_cast<actions::transformations::Transformation *>(i.release()));
|
||||
} else {
|
||||
a->push_back(i.release());
|
||||
}
|
||||
}
|
||||
std::unique_ptr<Rule> rule(new Rule(
|
||||
/* op */ NULL,
|
||||
/* variables */ NULL,
|
||||
/* actions */ a,
|
||||
/* transformations */ t,
|
||||
/* file name */ std::unique_ptr<std::string>(new std::string(*@1.end.filename)),
|
||||
/* line number */ @1.end.line
|
||||
));
|
||||
@@ -1125,12 +1138,18 @@ expression:
|
||||
{
|
||||
std::string err;
|
||||
std::vector<actions::Action *> *a = new std::vector<actions::Action *>();
|
||||
std::vector<actions::transformations::Transformation *> *t = new std::vector<actions::transformations::Transformation *>();
|
||||
for (auto &i : *$2.get()) {
|
||||
a->push_back(i.release());
|
||||
if (dynamic_cast<actions::transformations::Transformation *>(i.get())) {
|
||||
t->push_back(dynamic_cast<actions::transformations::Transformation *>(i.release()));
|
||||
} else {
|
||||
a->push_back(i.release());
|
||||
}
|
||||
}
|
||||
std::unique_ptr<RuleScript> r(new RuleScript(
|
||||
/* path to script */ $1,
|
||||
/* actions */ a,
|
||||
/* transformations */ t,
|
||||
/* file name */ std::unique_ptr<std::string>(new std::string(*@1.end.filename)),
|
||||
/* line number */ @1.end.line
|
||||
));
|
||||
@@ -1164,7 +1183,7 @@ expression:
|
||||
delete phase;
|
||||
} else if (a->action_kind == actions::Action::RunTimeOnlyIfMatchKind ||
|
||||
a->action_kind == actions::Action::RunTimeBeforeMatchAttemptKind) {
|
||||
actions::transformations::None *none = dynamic_cast<actions::transformations::None *>(a);
|
||||
actions::transformations::None *none = dynamic_cast<actions::transformations::None *>(a);
|
||||
if (none != NULL) {
|
||||
driver.error(@0, "The transformation none is not suitable to be part of the SecDefaultActions");
|
||||
YYERROR;
|
||||
|
Reference in New Issue
Block a user