Adds new method for rule merge

IMPORTANT: SecDefaultAction specified on a child configuration will
overwrite the ones specified on the parent; Previously it was
concatenating.
This commit is contained in:
Felipe Zimmerle
2020-04-14 11:33:17 -03:00
parent 73c3731c9d
commit 1518015687
114 changed files with 2130 additions and 1511 deletions

View File

@@ -31,6 +31,46 @@ using modsecurity::Utils::HttpsClient;
namespace modsecurity {
void Rules::fixDefaultActions() {
for (size_t i = 0; i < m_rules.size(); i++) {
auto &rule = m_rules[i];
RuleWithActions *r = dynamic_cast<RuleWithActions *>(rule.get());
if (!r) {
continue;
}
if (dynamic_cast<RuleWithOperator *>(rule.get())) {
RuleWithOperator *op = new RuleWithOperator(*dynamic_cast<RuleWithOperator *>(rule.get()));
std::unique_ptr<RuleWithOperator> nrp(op);
m_rules[i] = std::move(nrp);
} else if (dynamic_cast<RuleUnconditional *>(rule.get())) {
RuleUnconditional *un = new RuleUnconditional(*dynamic_cast<RuleUnconditional *>(rule.get()));
std::unique_ptr<RuleUnconditional> nrp(un);
m_rules[i] = std::move(nrp);
} else if (dynamic_cast<RuleScript *>(rule.get())) {
RuleScript *rs = new RuleScript(*dynamic_cast<RuleScript *>(rule.get()));
std::unique_ptr<RuleScript> nrp(rs);
m_rules[i] = std::move(nrp);
} else {
RuleWithActions *nr = new RuleWithActions(*dynamic_cast<RuleWithActions *>(rule.get()));
std::unique_ptr<RuleWithActions> nrp(nr);
m_rules[i] = std::move(nrp);
}
RuleWithActions *nr = dynamic_cast<RuleWithActions *>(m_rules[i].get());
nr->clearDefaultActions();
for (auto a : m_defaultActions) {
nr->addDefaultAction(a);
}
for (auto a : m_defaultTransformations) {
nr->addDefaultTransformation(a);
}
}
}
/**
* @name loadFromUri