mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-13 21:36:00 +03:00
Refactoring in Rule: Meaningful structures name
This commit is contained in:
parent
96849c07de
commit
b66224853b
@ -44,11 +44,18 @@ class Msg;
|
|||||||
class Rev;
|
class Rev;
|
||||||
class SetVar;
|
class SetVar;
|
||||||
class Tag;
|
class Tag;
|
||||||
|
namespace transformations {
|
||||||
|
class Transformation;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
namespace operators {
|
namespace operators {
|
||||||
class Operator;
|
class Operator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using TransformationResult = std::pair<std::shared_ptr<std::string>,
|
||||||
|
std::shared_ptr<std::string>>;
|
||||||
|
using TransformationResults = std::list<TransformationResult>;
|
||||||
|
|
||||||
class Rule {
|
class Rule {
|
||||||
public:
|
public:
|
||||||
Rule(operators::Operator *_op,
|
Rule(operators::Operator *_op,
|
||||||
@ -68,13 +75,6 @@ class Rule {
|
|||||||
bool containsBlock, std::shared_ptr<RuleMessage> ruleMessage,
|
bool containsBlock, std::shared_ptr<RuleMessage> ruleMessage,
|
||||||
actions::Action *a, bool context);
|
actions::Action *a, bool context);
|
||||||
|
|
||||||
inline void executeTransformation(actions::Action *a,
|
|
||||||
std::shared_ptr<std::string> *value,
|
|
||||||
Transaction *trans,
|
|
||||||
std::list<std::pair<std::shared_ptr<std::string>,
|
|
||||||
std::shared_ptr<std::string>>> *ret,
|
|
||||||
std::string *path,
|
|
||||||
int *nth) const;
|
|
||||||
|
|
||||||
void getVariablesExceptions(Transaction *t,
|
void getVariablesExceptions(Transaction *t,
|
||||||
variables::Variables *exclusion, variables::Variables *addition);
|
variables::Variables *exclusion, variables::Variables *addition);
|
||||||
@ -83,10 +83,6 @@ class Rule {
|
|||||||
void executeActionsAfterFullMatch(Transaction *trasn,
|
void executeActionsAfterFullMatch(Transaction *trasn,
|
||||||
bool containsDisruptive, std::shared_ptr<RuleMessage> ruleMessage);
|
bool containsDisruptive, std::shared_ptr<RuleMessage> ruleMessage);
|
||||||
|
|
||||||
std::list<std::pair<std::shared_ptr<std::string>,
|
|
||||||
std::shared_ptr<std::string>>> executeDefaultTransformations(
|
|
||||||
Transaction *trasn, const std::string &value);
|
|
||||||
|
|
||||||
bool executeOperatorAt(Transaction *trasn, const std::string &key,
|
bool executeOperatorAt(Transaction *trasn, const std::string &key,
|
||||||
std::string value, std::shared_ptr<RuleMessage> rm);
|
std::string value, std::shared_ptr<RuleMessage> rm);
|
||||||
void executeActionsIndependentOfChainedRuleResult(Transaction *trasn,
|
void executeActionsIndependentOfChainedRuleResult(Transaction *trasn,
|
||||||
@ -100,15 +96,17 @@ class Rule {
|
|||||||
bool containsTag(const std::string& name, Transaction *t);
|
bool containsTag(const std::string& name, Transaction *t);
|
||||||
bool containsMsg(const std::string& name, Transaction *t);
|
bool containsMsg(const std::string& name, Transaction *t);
|
||||||
|
|
||||||
|
|
||||||
void executeTransformations(
|
void executeTransformations(
|
||||||
actions::Action *a,
|
Transaction *trasn, const std::string &value, TransformationResults &ret);
|
||||||
std::shared_ptr<std::string> newValue,
|
inline void executeTransformation(
|
||||||
std::shared_ptr<std::string> value,
|
actions::transformations::Transformation *a,
|
||||||
|
std::shared_ptr<std::string> *value,
|
||||||
Transaction *trans,
|
Transaction *trans,
|
||||||
std::list<std::pair<std::shared_ptr<std::string>,
|
TransformationResults *ret,
|
||||||
std::shared_ptr<std::string>>> *ret,
|
std::string *path,
|
||||||
std::shared_ptr<std::string> transStr,
|
int *nth) const;
|
||||||
int nth);
|
|
||||||
|
|
||||||
actions::Action *m_theDisruptiveAction;
|
actions::Action *m_theDisruptiveAction;
|
||||||
actions::LogData *m_logData;
|
actions::LogData *m_logData;
|
||||||
|
@ -2425,7 +2425,7 @@ namespace yy {
|
|||||||
}
|
}
|
||||||
checkedActions.push_back(a);
|
checkedActions.push_back(a);
|
||||||
} else {
|
} else {
|
||||||
driver.error(yystack_[2].location, "The action '" + a->m_name + "' is not suitable to be part of the SecDefaultActions");
|
driver.error(yystack_[2].location, "The action '" + *a->m_name.get() + "' is not suitable to be part of the SecDefaultActions");
|
||||||
YYERROR;
|
YYERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
33
src/rule.cc
33
src/rule.cc
@ -49,7 +49,7 @@ using operators::Operator;
|
|||||||
using actions::Action;
|
using actions::Action;
|
||||||
using variables::Variable;
|
using variables::Variable;
|
||||||
using actions::transformations::None;
|
using actions::transformations::None;
|
||||||
|
using actions::transformations::Transformation;
|
||||||
|
|
||||||
Rule::Rule(const std::string &marker)
|
Rule::Rule(const std::string &marker)
|
||||||
: m_theDisruptiveAction(nullptr),
|
: m_theDisruptiveAction(nullptr),
|
||||||
@ -326,11 +326,11 @@ bool Rule::executeOperatorAt(Transaction *trans, const std::string &key,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline void Rule::executeTransformation(actions::Action *a,
|
inline void Rule::executeTransformation(
|
||||||
|
actions::transformations::Transformation *a,
|
||||||
std::shared_ptr<std::string> *value,
|
std::shared_ptr<std::string> *value,
|
||||||
Transaction *trans,
|
Transaction *trans,
|
||||||
std::list<std::pair<std::shared_ptr<std::string>,
|
TransformationResults *ret,
|
||||||
std::shared_ptr<std::string>>> *ret,
|
|
||||||
std::string *path,
|
std::string *path,
|
||||||
int *nth) const {
|
int *nth) const {
|
||||||
|
|
||||||
@ -359,15 +359,11 @@ inline void Rule::executeTransformation(actions::Action *a,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::list<std::pair<std::shared_ptr<std::string>,
|
void Rule::executeTransformations(
|
||||||
std::shared_ptr<std::string>>>
|
Transaction *trans, const std::string &in, TransformationResults &ret) {
|
||||||
Rule::executeDefaultTransformations(
|
|
||||||
Transaction *trans, const std::string &in) {
|
|
||||||
int none = 0;
|
int none = 0;
|
||||||
int transformations = 0;
|
int transformations = 0;
|
||||||
std::string path("");
|
std::string path("");
|
||||||
std::list<std::pair<std::shared_ptr<std::string>,
|
|
||||||
std::shared_ptr<std::string>>> ret;
|
|
||||||
std::shared_ptr<std::string> value =
|
std::shared_ptr<std::string> value =
|
||||||
std::shared_ptr<std::string>(new std::string(in));
|
std::shared_ptr<std::string>(new std::string(in));
|
||||||
|
|
||||||
@ -394,14 +390,17 @@ std::list<std::pair<std::shared_ptr<std::string>,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
executeTransformation(a.get(), &value, trans, &ret, &path,
|
// FIXME: here the object needs to be a transformation already.
|
||||||
|
Transformation *t = dynamic_cast<Transformation *>(a.get());
|
||||||
|
executeTransformation(t, &value, trans, &ret, &path,
|
||||||
&transformations);
|
&transformations);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Action *a : this->m_actionsRuntimePre) {
|
for (Action *a : this->m_actionsRuntimePre) {
|
||||||
if (none == 0) {
|
if (none == 0) {
|
||||||
executeTransformation(a, &value, trans, &ret, &path,
|
Transformation *t = dynamic_cast<Transformation *>(a);
|
||||||
|
executeTransformation(t, &value, trans, &ret, &path,
|
||||||
&transformations);
|
&transformations);
|
||||||
}
|
}
|
||||||
if (a->m_isNone) {
|
if (a->m_isNone) {
|
||||||
@ -427,7 +426,8 @@ std::list<std::pair<std::shared_ptr<std::string>,
|
|||||||
}
|
}
|
||||||
actions::Action *a = dynamic_cast<actions::Action*>(b.second.get());
|
actions::Action *a = dynamic_cast<actions::Action*>(b.second.get());
|
||||||
if (none == 0) {
|
if (none == 0) {
|
||||||
executeTransformation(a, &value, trans, &ret, &path,
|
Transformation *t = dynamic_cast<Transformation *>(a);
|
||||||
|
executeTransformation(t, &value, trans, &ret, &path,
|
||||||
&transformations);
|
&transformations);
|
||||||
}
|
}
|
||||||
if (a->m_isNone) {
|
if (a->m_isNone) {
|
||||||
@ -446,8 +446,6 @@ std::list<std::pair<std::shared_ptr<std::string>,
|
|||||||
std::shared_ptr<std::string>(new std::string(*value)),
|
std::shared_ptr<std::string>(new std::string(*value)),
|
||||||
std::shared_ptr<std::string>(new std::string(path))));
|
std::shared_ptr<std::string>(new std::string(path))));
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -711,10 +709,9 @@ bool Rule::evaluate(Transaction *trans,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<std::pair<std::shared_ptr<std::string>,
|
TransformationResults values;
|
||||||
std::shared_ptr<std::string>>> values;
|
|
||||||
|
|
||||||
values = executeDefaultTransformations(trans, value);
|
executeTransformations(trans, value, values);
|
||||||
|
|
||||||
for (const auto &valueTemp : values) {
|
for (const auto &valueTemp : values) {
|
||||||
bool ret;
|
bool ret;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user