mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-11-18 02:10:36 +03:00
actions: Compute the rule association during rules load
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include "modsecurity/modsecurity.h"
|
||||
#include "modsecurity/transaction.h"
|
||||
#include "src/variables/variable.h"
|
||||
#include "src/variables/rule_variable.h"
|
||||
|
||||
|
||||
#ifndef SRC_RUN_TIME_STRING_H_
|
||||
@@ -34,29 +35,72 @@ namespace modsecurity {
|
||||
|
||||
class RunTimeElementHolder {
|
||||
public:
|
||||
RunTimeElementHolder() :
|
||||
m_string("") {
|
||||
m_var.reset(NULL);
|
||||
}
|
||||
std::unique_ptr<modsecurity::variables::Variable> m_var;
|
||||
RunTimeElementHolder()
|
||||
: m_string(""),
|
||||
m_variable(nullptr)
|
||||
{ };
|
||||
|
||||
|
||||
RunTimeElementHolder(const RunTimeElementHolder &other)
|
||||
: m_string(other.m_string),
|
||||
m_variable(other.m_variable) {
|
||||
variables::RuleVariable *rv = dynamic_cast<variables::RuleVariable *>(m_variable.get());
|
||||
if (rv != nullptr) {
|
||||
auto nrv = rv->clone();
|
||||
rv = dynamic_cast<variables::RuleVariable *>(nrv);
|
||||
rv->populate(nullptr);
|
||||
m_variable = std::unique_ptr<variables::Variable>(nrv);
|
||||
}
|
||||
};
|
||||
|
||||
/* protected: */
|
||||
std::string m_string;
|
||||
std::shared_ptr<variables::Variable> m_variable;
|
||||
};
|
||||
|
||||
class RunTimeString {
|
||||
public:
|
||||
RunTimeString() :
|
||||
m_containsMacro(false) { }
|
||||
RunTimeString()
|
||||
: m_containsMacro(false),
|
||||
m_elements()
|
||||
{ };
|
||||
|
||||
|
||||
RunTimeString(const RunTimeString &other)
|
||||
: m_containsMacro(other.m_containsMacro),
|
||||
m_elements()
|
||||
{
|
||||
for (auto &m : other.m_elements) {
|
||||
m_elements.push_back(std::unique_ptr<RunTimeElementHolder>(new RunTimeElementHolder(*m.get())));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void appendText(const std::string &text);
|
||||
void appendVar(std::unique_ptr<modsecurity::variables::Variable> var);
|
||||
|
||||
|
||||
std::string evaluate(Transaction *t);
|
||||
std::string evaluate(Transaction *t, Rule *r);
|
||||
std::string evaluate() {
|
||||
|
||||
inline std::string evaluate() {
|
||||
return evaluate(NULL);
|
||||
}
|
||||
inline bool containsMacro() const { return m_containsMacro; }
|
||||
bool m_containsMacro;
|
||||
|
||||
protected:
|
||||
|
||||
inline bool containsMacro() const { return m_containsMacro; }
|
||||
|
||||
|
||||
void populate(RuleWithActions *rule) {
|
||||
for (auto &a : m_elements) {
|
||||
modsecurity::variables::RuleVariable *vrule = dynamic_cast<variables::RuleVariable *>(a->m_variable.get());
|
||||
if (vrule != nullptr) {
|
||||
vrule->populate(rule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_containsMacro;
|
||||
std::list<std::unique_ptr<RunTimeElementHolder>> m_elements;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user