mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 05:45:59 +03:00
Huge performance improvement: passing variables as pointers avoiding copies
This commit is contained in:
parent
2451bf05d7
commit
076a02951c
@ -92,9 +92,23 @@ class ModSecurityCollectionsVariables :
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class ModSecurityStringVar {
|
||||||
|
public:
|
||||||
|
ModSecurityStringVar(const std::string& key, const std::string& value) :
|
||||||
|
m_key(key),
|
||||||
|
m_value(value) { }
|
||||||
|
std::string m_key;
|
||||||
|
std::string m_value;
|
||||||
|
};
|
||||||
|
|
||||||
class ModSecurityStringVariables :
|
class ModSecurityStringVariables :
|
||||||
public std::unordered_multimap<std::string, std::string> {
|
public std::unordered_multimap<std::string, std::string> {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
ModSecurityStringVariables() {
|
||||||
|
this->reserve(1000);
|
||||||
|
}
|
||||||
|
|
||||||
void storeVariable(std::string key, std::string value) {
|
void storeVariable(std::string key, std::string value) {
|
||||||
this->emplace(key, value);
|
this->emplace(key, value);
|
||||||
}
|
}
|
||||||
@ -123,34 +137,44 @@ class ModSecurityStringVariables :
|
|||||||
this->erase(key);
|
this->erase(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::list<ModSecurityStringVar *>
|
||||||
std::list<std::pair<std::string, std::string>>
|
resolveVariable(const std::string& key,
|
||||||
resolveVariable(const std::string& key) {
|
std::list<ModSecurityStringVar *> *l) {
|
||||||
std::list<std::pair<std::string, std::string>> l;
|
|
||||||
std::pair<std::string, std::string> pair;
|
|
||||||
|
|
||||||
auto range = this->equal_range(key);
|
auto range = this->equal_range(key);
|
||||||
|
|
||||||
for (auto it = range.first; it != range.second; ++it) {
|
for (auto it = range.first; it != range.second; ++it) {
|
||||||
pair = std::make_pair(std::string(key), std::string(it->second));
|
l->push_back(new ModSecurityStringVar(key, it->second));
|
||||||
l.push_back(pair);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (l.size() == 0 && key.find(":") == std::string::npos) {
|
if (key.find(":") == std::string::npos && l->size() == 0) {
|
||||||
|
size_t keySize = key.size() + 1;
|
||||||
for (auto& x : *this) {
|
for (auto& x : *this) {
|
||||||
if ((x.first.substr(0, key.size() + 1).compare(key + ":") != 0)
|
if (x.first.size() <= keySize) {
|
||||||
&& (x.first != key)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
std::list<std::pair<std::string, std::string>> t;
|
if (x.first.at(keySize - 1) != ':') {
|
||||||
t = this->resolveVariable(x.first);
|
continue;
|
||||||
if (t.empty() == false) {
|
|
||||||
l.insert(l.end(), t.begin(), t.end());
|
|
||||||
}
|
}
|
||||||
|
if (x.first.compare(0, keySize, key + ":") != 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//auto range = this->equal_range(x.first);
|
||||||
|
|
||||||
|
//for (auto it = range.first; it != range.second; ++it) {
|
||||||
|
l->push_back(new ModSecurityStringVar(x.first, x.second));
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return l;
|
return *l;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::list<ModSecurityStringVar *>
|
||||||
|
resolveVariable(const std::string& key) {
|
||||||
|
std::list<ModSecurityStringVar *> l;
|
||||||
|
|
||||||
|
return resolveVariable(key, &l);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -225,8 +249,12 @@ class Assay {
|
|||||||
const char *getResponseBody();
|
const char *getResponseBody();
|
||||||
int getResponseBodyLenth();
|
int getResponseBodyLenth();
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
resolve_variable(const std::string& var);
|
resolve_variable(const std::string& var);
|
||||||
|
|
||||||
|
void resolve_variable(const std::string& var,
|
||||||
|
std::list<ModSecurityStringVar *> *);
|
||||||
|
|
||||||
std::string* resolve_variable_first(const std::string& key);
|
std::string* resolve_variable_first(const std::string& key);
|
||||||
std::string* resolve_variable_first(const std::string& collectionName,
|
std::string* resolve_variable_first(const std::string& collectionName,
|
||||||
const std::string& var);
|
const std::string& var);
|
||||||
|
@ -201,8 +201,9 @@ libmodsecurity_la_CPPFLAGS = \
|
|||||||
-I.. \
|
-I.. \
|
||||||
-g \
|
-g \
|
||||||
-fPIC \
|
-fPIC \
|
||||||
-O0 \
|
-O3 \
|
||||||
-I ../headers \
|
-I ../headers \
|
||||||
|
-DNO_LOGS=1 \
|
||||||
$(GEOIP_CFLAGS) \
|
$(GEOIP_CFLAGS) \
|
||||||
$(PCRE_CPPFLAGS)
|
$(PCRE_CPPFLAGS)
|
||||||
|
|
||||||
|
@ -32,34 +32,33 @@ namespace actions {
|
|||||||
|
|
||||||
bool Capture::evaluate(Rule *rule, Assay *assay) {
|
bool Capture::evaluate(Rule *rule, Assay *assay) {
|
||||||
operators::Operator *op = rule->op;
|
operators::Operator *op = rule->op;
|
||||||
std::list<std::string> match;
|
std::list<std::string> *match;
|
||||||
|
|
||||||
operators::Pm *pm = dynamic_cast<operators::Pm *>(op);
|
operators::Pm *pm = dynamic_cast<operators::Pm *>(op);
|
||||||
if (pm != NULL) {
|
if (pm != NULL) {
|
||||||
match = pm->matched;
|
match = &pm->matched;
|
||||||
}
|
}
|
||||||
|
|
||||||
operators::Rx *rx = dynamic_cast<operators::Rx *>(op);
|
operators::Rx *rx = dynamic_cast<operators::Rx *>(op);
|
||||||
if (rx != NULL) {
|
if (rx != NULL) {
|
||||||
match = rx->matched;
|
match = &rx->matched;
|
||||||
}
|
}
|
||||||
|
|
||||||
operators::Contains *contains = dynamic_cast<operators::Contains *>(op);
|
operators::Contains *contains = dynamic_cast<operators::Contains *>(op);
|
||||||
if (contains != NULL) {
|
if (contains != NULL) {
|
||||||
match = contains->matched;
|
match = &contains->matched;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (match.empty()) {
|
if (match->empty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (match.empty() == false) {
|
while (match->empty() == false) {
|
||||||
assay->setCollection("TX", std::to_string(i), match.back());
|
assay->setCollection("TX", std::to_string(i), match->back());
|
||||||
match.pop_back();
|
match->pop_back();
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,30 +116,29 @@ bool SetVar::evaluate(Rule *rule, Assay *assay) {
|
|||||||
value = 0;
|
value = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int pre = 0;
|
|
||||||
try {
|
std::string resolvedPre = MacroExpansion::expand(predicate, assay);
|
||||||
pre = stoi(predicate);
|
if (operation == setOperation) {
|
||||||
} catch (...) {
|
targetValue = resolvedPre;
|
||||||
|
} else {
|
||||||
|
int pre = 0;
|
||||||
try {
|
try {
|
||||||
pre = stoi(MacroExpansion::expand(predicate, assay));
|
pre = stoi(resolvedPre);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
pre = 0;
|
pre = 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
switch (operation) {
|
switch (operation) {
|
||||||
case setOperation:
|
case sumAndSetOperation:
|
||||||
targetValue = MacroExpansion::expand(predicate, assay);
|
targetValue = std::to_string(value + pre);
|
||||||
break;
|
break;
|
||||||
case sumAndSetOperation:
|
case substractAndSetOperation:
|
||||||
targetValue = std::to_string(value + pre);
|
targetValue = std::to_string(value - pre);
|
||||||
break;
|
break;
|
||||||
case substractAndSetOperation:
|
case setToOne:
|
||||||
targetValue = std::to_string(value - pre);
|
targetValue = std::string("1");
|
||||||
break;
|
break;
|
||||||
case setToOne:
|
}
|
||||||
targetValue = std::string("1");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef NO_LOGS
|
#ifndef NO_LOGS
|
||||||
|
@ -35,24 +35,18 @@ namespace transformations {
|
|||||||
|
|
||||||
std::string RemoveNulls::evaluate(std::string value,
|
std::string RemoveNulls::evaluate(std::string value,
|
||||||
Assay *assay) {
|
Assay *assay) {
|
||||||
int64_t i, j;
|
int64_t i;
|
||||||
|
|
||||||
char *input = reinterpret_cast<char *>(malloc(value.size()
|
std::string ret;
|
||||||
* sizeof(char)));
|
|
||||||
memcpy(input, value.c_str(), value.size());
|
|
||||||
|
|
||||||
i = j = 0;
|
i = 0;
|
||||||
while (i < value.size()) {
|
while (i < value.size()) {
|
||||||
if (input[i] != '\0') {
|
if (value.at(i) != '\0') {
|
||||||
input[j] = input[i];
|
ret += value.at(i);
|
||||||
j++;
|
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ret(input, 0, j);
|
|
||||||
free(input);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
28
src/assay.cc
28
src/assay.cc
@ -664,10 +664,12 @@ int Assay::processRequestBody() {
|
|||||||
* computationally intensive.
|
* computationally intensive.
|
||||||
*/
|
*/
|
||||||
std::string fullRequest;
|
std::string fullRequest;
|
||||||
for (auto &a : resolve_variable("REQUEST_HEADERS")) {
|
std::list<ModSecurityStringVar *> l;
|
||||||
|
resolve_variable("REQUEST_HEADERS", &l);
|
||||||
|
for (auto &a : l) {
|
||||||
fullRequest = fullRequest + \
|
fullRequest = fullRequest + \
|
||||||
std::string(a.first, 16, a.first.length() - 16) + ": " \
|
std::string(a->m_key, 16, a->m_key.length() - 16) + ": " \
|
||||||
+ a.second + "\n";
|
+ a->m_value + "\n";
|
||||||
}
|
}
|
||||||
fullRequest = fullRequest + "\n\n";
|
fullRequest = fullRequest + "\n\n";
|
||||||
fullRequest = fullRequest + m_requestBody.str();
|
fullRequest = fullRequest + m_requestBody.str();
|
||||||
@ -1471,23 +1473,25 @@ void Assay::delete_variable(std::string key) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
void Assay::resolve_variable(const std::string& var,
|
||||||
Assay::resolve_variable(const std::string& var) {
|
std::list<ModSecurityStringVar *> *l) {
|
||||||
std::list<std::pair<std::string, std::string>> l;
|
|
||||||
std::pair<std::string, std::string> pair;
|
|
||||||
|
|
||||||
l = m_variables_strings.resolveVariable(var);
|
m_variables_strings.resolveVariable(var, l);
|
||||||
|
|
||||||
size_t ac = var.find(":");
|
size_t ac = var.find(":");
|
||||||
if (ac != std::string::npos) {
|
if (ac != std::string::npos) {
|
||||||
/* It may be a collection */
|
/* It may be a collection */
|
||||||
for (auto &a : collections) {
|
for (auto &a : collections) {
|
||||||
std::list<std::pair<std::string, std::string>> l2 = a.second->resolveVariable(var);
|
a.second->resolveVariable(var, l);
|
||||||
if (l2.empty() == false) {
|
|
||||||
l.insert(l.end(), l2.begin(), l2.end());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::list<ModSecurityStringVar *> *
|
||||||
|
Assay::resolve_variable(const std::string& var) {
|
||||||
|
std::list<ModSecurityStringVar *> *l = new std::list<ModSecurityStringVar *>();
|
||||||
|
|
||||||
|
resolve_variable(var, l);
|
||||||
|
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ bool Rx::evaluate(Assay *assay, const std::string& input) {
|
|||||||
SMatch match;
|
SMatch match;
|
||||||
|
|
||||||
if (regex_search(input, &match, *m_re) && match.size() >= 1) {
|
if (regex_search(input, &match, *m_re) && match.size() >= 1) {
|
||||||
this->matched.push_back(match.match);
|
//this->matched.push_back(match.match);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,8 +37,7 @@ class Rx : public Operator {
|
|||||||
Rx(std::string op, std::string param, bool negation)
|
Rx(std::string op, std::string param, bool negation)
|
||||||
: Operator(op, param, negation),
|
: Operator(op, param, negation),
|
||||||
m_param(param) {
|
m_param(param) {
|
||||||
Regex r(param);
|
m_re = new Regex(param);
|
||||||
m_re = &r;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool evaluate(Assay *assay, const std::string &input);
|
bool evaluate(Assay *assay, const std::string &input);
|
||||||
|
39
src/rule.cc
39
src/rule.cc
@ -276,10 +276,10 @@ bool Rule::evaluate(Assay *assay) {
|
|||||||
Exclusion *exl = dynamic_cast<Exclusion *>(variable);
|
Exclusion *exl = dynamic_cast<Exclusion *>(variable);
|
||||||
|
|
||||||
if (exl != NULL) {
|
if (exl != NULL) {
|
||||||
std::list<std::pair<std::string, std::string>> z =
|
std::list<ModSecurityStringVar *> *z =
|
||||||
variable->evaluate(assay);
|
variable->evaluate(assay);
|
||||||
for (auto &y : z) {
|
for (auto &y : *z) {
|
||||||
exclusions.push_back(y.first);
|
exclusions.push_back(y->m_key);
|
||||||
}
|
}
|
||||||
exclusions.push_back(variable->name);
|
exclusions.push_back(variable->name);
|
||||||
}
|
}
|
||||||
@ -293,19 +293,19 @@ bool Rule::evaluate(Assay *assay) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>> e =
|
std::list<ModSecurityStringVar *> *e =
|
||||||
variable->evaluate(assay);
|
variable->evaluate(assay);
|
||||||
|
|
||||||
for (auto &v : e) {
|
for (auto &v : *e) {
|
||||||
if (std::find(exclusions.begin(), exclusions.end(),
|
if (std::find(exclusions.begin(), exclusions.end(),
|
||||||
v.first) != exclusions.end()) {
|
v->m_key) != exclusions.end()) {
|
||||||
#ifndef NO_LOGS
|
#ifndef NO_LOGS
|
||||||
assay->debug(9, "Variable: " + v.first + " is part of the" +
|
assay->debug(9, "Variable: " + v.m_key + " is part of the" +
|
||||||
" exclusion list, skipping...");
|
" exclusion list, skipping...");
|
||||||
#endif
|
#endif
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
std::string value = v.second;
|
std::string value = v->m_value;
|
||||||
int none = 0;
|
int none = 0;
|
||||||
for (Action *a : this->actions_runtime_pre) {
|
for (Action *a : this->actions_runtime_pre) {
|
||||||
None *z = dynamic_cast<None *>(a);
|
None *z = dynamic_cast<None *>(a);
|
||||||
@ -349,7 +349,7 @@ bool Rule::evaluate(Assay *assay) {
|
|||||||
|
|
||||||
#ifndef NO_LOGS
|
#ifndef NO_LOGS
|
||||||
assay->debug(9, "Target value: \"" + limitTo(80, toHexIfNeeded(value)) + \
|
assay->debug(9, "Target value: \"" + limitTo(80, toHexIfNeeded(value)) + \
|
||||||
"\" (Variable: " + v.first + ")");
|
"\" (Variable: " + v.m_key + ")");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ret = this->op->evaluate(assay, value);
|
ret = this->op->evaluate(assay, value);
|
||||||
@ -397,17 +397,17 @@ bool Rule::evaluate(Assay *assay) {
|
|||||||
assay->store_variable("MATCHED_VAR", value);
|
assay->store_variable("MATCHED_VAR", value);
|
||||||
}
|
}
|
||||||
if (assay->update_variable_first("MATCHED_VAR_NAME",
|
if (assay->update_variable_first("MATCHED_VAR_NAME",
|
||||||
v.first) == false) {
|
v->m_key) == false) {
|
||||||
assay->store_variable("MATCHED_VAR_NAME", v.first);
|
assay->store_variable("MATCHED_VAR_NAME", v->m_key);
|
||||||
}
|
}
|
||||||
assay->store_variable("MATCHED_VARS:" + v.first, value);
|
assay->store_variable("MATCHED_VARS:" + v->m_key, value);
|
||||||
assay->store_variable("MATCHED_VARS_NAMES:" + v.first,
|
assay->store_variable("MATCHED_VARS_NAMES:" + v->m_key,
|
||||||
v.first);
|
v->m_key);
|
||||||
chainResult = this->chainedRule->evaluate(assay);
|
chainResult = this->chainedRule->evaluate(assay);
|
||||||
assay->update_variable_first("MATCHED_VAR", "");
|
assay->update_variable_first("MATCHED_VAR", "");
|
||||||
assay->delete_variable("MATCHED_VARS:" + v.first);
|
assay->delete_variable("MATCHED_VARS:" + v->m_key);
|
||||||
assay->delete_variable("MATCHED_VARS_NAMES:" + v.first);
|
assay->delete_variable("MATCHED_VARS_NAMES:" + v->m_key);
|
||||||
assay->delete_variable("MATCHED_VARS_NAMES:" + v.first);
|
assay->delete_variable("MATCHED_VARS_NAME");
|
||||||
}
|
}
|
||||||
if (this->chained && chainResult == true || !this->chained) {
|
if (this->chained && chainResult == true || !this->chained) {
|
||||||
for (Action *a : assay->m_rules->defaultActions[this->phase]) {
|
for (Action *a : assay->m_rules->defaultActions[this->phase]) {
|
||||||
@ -473,6 +473,11 @@ bool Rule::evaluate(Assay *assay) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (e->empty() == false) {
|
||||||
|
delete e->front();
|
||||||
|
e->pop_front();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -46,15 +46,13 @@ Regex::Regex(const std::string& pattern_)
|
|||||||
|
|
||||||
int regex_search(const std::string& s, SMatch *match,
|
int regex_search(const std::string& s, SMatch *match,
|
||||||
const Regex& regex) {
|
const Regex& regex) {
|
||||||
int *ovector = 0;
|
int ovector[OVECCOUNT];
|
||||||
int ovecsize = 0;
|
return pcre_exec(regex.m_pc, regex.m_pce, s.c_str(), s.size(), 0, 0, ovector, OVECCOUNT) > 0;
|
||||||
return pcre_exec(regex.m_pc, regex.m_pce, s.c_str(), s.size(), 0, 0, ovector, ovecsize) > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int regex_search(const std::string& s, const Regex& regex) {
|
int regex_search(const std::string& s, const Regex& regex) {
|
||||||
int *ovector = 0;
|
int ovector[OVECCOUNT];
|
||||||
int ovecsize = 0;
|
return pcre_exec(regex.m_pc, regex.m_pce, s.c_str(), s.size(), 0, 0, ovector, OVECCOUNT) > 0;
|
||||||
return pcre_exec(regex.m_pc, regex.m_pce, s.c_str(), s.size(), 0, 0, ovector, ovecsize) > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
namespace ModSecurity {
|
namespace ModSecurity {
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
|
#define OVECCOUNT 30
|
||||||
|
|
||||||
class Regex {
|
class Regex {
|
||||||
public:
|
public:
|
||||||
@ -32,7 +33,7 @@ class Regex {
|
|||||||
std::string pattern;
|
std::string pattern;
|
||||||
pcre *m_pc = NULL;
|
pcre *m_pc = NULL;
|
||||||
pcre_extra *m_pce = NULL;
|
pcre_extra *m_pce = NULL;
|
||||||
|
int m_ovector[OVECCOUNT];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,18 +27,16 @@
|
|||||||
namespace ModSecurity {
|
namespace ModSecurity {
|
||||||
namespace Variables {
|
namespace Variables {
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
Duration::evaluate(Assay *assay) {
|
Duration::evaluate(Assay *assay) {
|
||||||
std::list<std::pair<std::string, std::string>> resl;
|
std::list<ModSecurityStringVar *> *resl = new std::list<ModSecurityStringVar *>();
|
||||||
std::string res;
|
std::string res;
|
||||||
std::pair<std::string, std::string> pair;
|
|
||||||
|
|
||||||
double e = cpu_seconds() - assay->start;
|
double e = cpu_seconds() - assay->start;
|
||||||
|
|
||||||
res = std::to_string(e);
|
res = std::to_string(e);
|
||||||
|
|
||||||
pair = std::make_pair(std::string("DURATION"), std::string(res));
|
resl->push_back(new ModSecurityStringVar("DURATION", std::string(res)));
|
||||||
resl.push_back(pair);
|
|
||||||
|
|
||||||
return resl;
|
return resl;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ class Duration : public Variable {
|
|||||||
explicit Duration(std::string _name)
|
explicit Duration(std::string _name)
|
||||||
: Variable(_name) { }
|
: Variable(_name) { }
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
evaluate(Assay *assay) override;
|
evaluate(Assay *assay) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,9 +33,9 @@ extern char **environ;
|
|||||||
namespace ModSecurity {
|
namespace ModSecurity {
|
||||||
namespace Variables {
|
namespace Variables {
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
Env::evaluate(Assay *assay) {
|
Env::evaluate(Assay *assay) {
|
||||||
std::list<std::pair<std::string, std::string>> resl;
|
std::list<ModSecurityStringVar *> *resl = new std::list<ModSecurityStringVar *>();
|
||||||
|
|
||||||
std::map<std::string, std::string> envs;
|
std::map<std::string, std::string> envs;
|
||||||
for (char **current = environ; *current; current++) {
|
for (char **current = environ; *current; current++) {
|
||||||
@ -49,9 +49,7 @@ std::list<std::pair<std::string, std::string>>
|
|||||||
|
|
||||||
envs.insert(std::pair<std::string, std::string>("ENV:" + key, value));
|
envs.insert(std::pair<std::string, std::string>("ENV:" + key, value));
|
||||||
if ("env:" + key == name) {
|
if ("env:" + key == name) {
|
||||||
std::pair<std::string, std::string> pair;
|
resl->push_back(new ModSecurityStringVar(name, value));
|
||||||
pair = std::make_pair(name, value);
|
|
||||||
resl.push_back(pair);
|
|
||||||
return resl;
|
return resl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,9 +59,7 @@ std::list<std::pair<std::string, std::string>>
|
|||||||
&& (x.first != name)) {
|
&& (x.first != name)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
std::pair<std::string, std::string> pair;
|
resl->push_back(new ModSecurityStringVar(x.first, x.second));
|
||||||
pair = std::make_pair(x.first, x.second);
|
|
||||||
resl.push_back(pair);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return resl;
|
return resl;
|
||||||
|
@ -33,7 +33,7 @@ class Env : public Variable {
|
|||||||
explicit Env(std::string _name)
|
explicit Env(std::string _name)
|
||||||
: Variable(_name) { }
|
: Variable(_name) { }
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
evaluate(Assay *assay) override;
|
evaluate(Assay *assay) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -26,14 +26,12 @@
|
|||||||
namespace ModSecurity {
|
namespace ModSecurity {
|
||||||
namespace Variables {
|
namespace Variables {
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
HighestSeverity::evaluate(Assay *assay) {
|
HighestSeverity::evaluate(Assay *assay) {
|
||||||
std::list<std::pair<std::string, std::string>> resl;
|
std::list<ModSecurityStringVar *> *resl = new std::list<ModSecurityStringVar *>();
|
||||||
std::pair<std::string, std::string> pair;
|
|
||||||
|
|
||||||
pair = std::make_pair(std::string("HIGHEST_SEVERITY"),
|
resl->push_back(new ModSecurityStringVar("HIGHEST_SEVERITY",
|
||||||
std::to_string(assay->highest_severity));
|
std::to_string(assay->highest_severity)));
|
||||||
resl.push_back(pair);
|
|
||||||
|
|
||||||
return resl;
|
return resl;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ class HighestSeverity : public Variable {
|
|||||||
explicit HighestSeverity(std::string _name)
|
explicit HighestSeverity(std::string _name)
|
||||||
: Variable(_name) { }
|
: Variable(_name) { }
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
evaluate(Assay *assay) override;
|
evaluate(Assay *assay) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -27,10 +27,9 @@
|
|||||||
namespace ModSecurity {
|
namespace ModSecurity {
|
||||||
namespace Variables {
|
namespace Variables {
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
ModsecBuild::evaluate(Assay *assay) {
|
ModsecBuild::evaluate(Assay *assay) {
|
||||||
std::list<std::pair<std::string, std::string>> resl;
|
std::list<ModSecurityStringVar *> *resl = new std::list<ModSecurityStringVar *>();
|
||||||
std::pair<std::string, std::string> pair;
|
|
||||||
|
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
ss << std::setw(2) << std::setfill('0') << MODSECURITY_MAJOR;
|
ss << std::setw(2) << std::setfill('0') << MODSECURITY_MAJOR;
|
||||||
@ -38,8 +37,7 @@ std::list<std::pair<std::string, std::string>>
|
|||||||
ss << std::setw(2) << std::setfill('0') << MODSECURITY_PATCHLEVEL;
|
ss << std::setw(2) << std::setfill('0') << MODSECURITY_PATCHLEVEL;
|
||||||
ss << std::setw(2) << std::setfill('0') << MODSECURITY_TAG_NUM;
|
ss << std::setw(2) << std::setfill('0') << MODSECURITY_TAG_NUM;
|
||||||
|
|
||||||
pair = std::make_pair(std::string("MODSEC_BUILD"), ss.str());
|
resl->push_back(new ModSecurityStringVar("MODSEC_BUILD", ss.str()));
|
||||||
resl.push_back(pair);
|
|
||||||
|
|
||||||
return resl;
|
return resl;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ class ModsecBuild : public Variable {
|
|||||||
explicit ModsecBuild(std::string _name)
|
explicit ModsecBuild(std::string _name)
|
||||||
: Variable(_name) { }
|
: Variable(_name) { }
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
evaluate(Assay *assay) override;
|
evaluate(Assay *assay) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,10 +33,10 @@
|
|||||||
namespace ModSecurity {
|
namespace ModSecurity {
|
||||||
namespace Variables {
|
namespace Variables {
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
Time::evaluate(Assay *assay) {
|
Time::evaluate(Assay *assay) {
|
||||||
std::list<std::pair<std::string, std::string>> resl;
|
std::list<ModSecurityStringVar *> *resl = new std::list<ModSecurityStringVar *>();
|
||||||
std::pair<std::string, std::string> pair;
|
|
||||||
char tstr[200];
|
char tstr[200];
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
time_t timer;
|
time_t timer;
|
||||||
@ -47,9 +47,7 @@ std::list<std::pair<std::string, std::string>>
|
|||||||
localtime_r(&timer, &timeinfo);
|
localtime_r(&timer, &timeinfo);
|
||||||
strftime(tstr, 200, "%H:%M:%S", &timeinfo);
|
strftime(tstr, 200, "%H:%M:%S", &timeinfo);
|
||||||
|
|
||||||
pair = std::make_pair(std::string("TIME"),
|
resl->push_back(new ModSecurityStringVar("TIME", std::string(tstr)));
|
||||||
std::string(tstr));
|
|
||||||
resl.push_back(pair);
|
|
||||||
|
|
||||||
return resl;
|
return resl;
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ class Time : public Variable {
|
|||||||
explicit Time(std::string _name)
|
explicit Time(std::string _name)
|
||||||
: Variable(_name) { }
|
: Variable(_name) { }
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
evaluate(Assay *assay) override;
|
evaluate(Assay *assay) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,10 +33,10 @@
|
|||||||
namespace ModSecurity {
|
namespace ModSecurity {
|
||||||
namespace Variables {
|
namespace Variables {
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
TimeDay::evaluate(Assay *assay) {
|
TimeDay::evaluate(Assay *assay) {
|
||||||
std::list<std::pair<std::string, std::string>> resl;
|
std::list<ModSecurityStringVar *> *resl = new std::list<ModSecurityStringVar *>();
|
||||||
std::pair<std::string, std::string> pair;
|
|
||||||
char tstr[200];
|
char tstr[200];
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
time_t timer;
|
time_t timer;
|
||||||
@ -47,9 +47,7 @@ std::list<std::pair<std::string, std::string>>
|
|||||||
localtime_r(&timer, &timeinfo);
|
localtime_r(&timer, &timeinfo);
|
||||||
strftime(tstr, 200, "%d", &timeinfo);
|
strftime(tstr, 200, "%d", &timeinfo);
|
||||||
|
|
||||||
pair = std::make_pair(std::string("TIME_DAY"),
|
resl->push_back(new ModSecurityStringVar("TIME_DAY", std::string(tstr)));
|
||||||
std::string(tstr));
|
|
||||||
resl.push_back(pair);
|
|
||||||
|
|
||||||
return resl;
|
return resl;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ class TimeDay : public Variable {
|
|||||||
explicit TimeDay(std::string _name)
|
explicit TimeDay(std::string _name)
|
||||||
: Variable(_name) { }
|
: Variable(_name) { }
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
evaluate(Assay *assay) override;
|
evaluate(Assay *assay) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,14 +33,11 @@
|
|||||||
namespace ModSecurity {
|
namespace ModSecurity {
|
||||||
namespace Variables {
|
namespace Variables {
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
TimeEpoch::evaluate(Assay *assay) {
|
TimeEpoch::evaluate(Assay *assay) {
|
||||||
std::list<std::pair<std::string, std::string>> resl;
|
std::list<ModSecurityStringVar *> *resl = new std::list<ModSecurityStringVar *>();
|
||||||
std::pair<std::string, std::string> pair;
|
|
||||||
|
|
||||||
pair = std::make_pair(std::string("TIME_EPOCH"),
|
resl->push_back(new ModSecurityStringVar("TIME_EPOCH", std::to_string(std::time(nullptr))));
|
||||||
std::to_string(std::time(nullptr)));
|
|
||||||
resl.push_back(pair);
|
|
||||||
|
|
||||||
return resl;
|
return resl;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ class TimeEpoch : public Variable {
|
|||||||
explicit TimeEpoch(std::string _name)
|
explicit TimeEpoch(std::string _name)
|
||||||
: Variable(_name) { }
|
: Variable(_name) { }
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
evaluate(Assay *assay) override;
|
evaluate(Assay *assay) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,10 +33,10 @@
|
|||||||
namespace ModSecurity {
|
namespace ModSecurity {
|
||||||
namespace Variables {
|
namespace Variables {
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
TimeHour::evaluate(Assay *assay) {
|
TimeHour::evaluate(Assay *assay) {
|
||||||
std::list<std::pair<std::string, std::string>> resl;
|
std::list<ModSecurityStringVar *> *resl = new std::list<ModSecurityStringVar *>();
|
||||||
std::pair<std::string, std::string> pair;
|
|
||||||
char tstr[200];
|
char tstr[200];
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
time_t timer;
|
time_t timer;
|
||||||
@ -47,9 +47,7 @@ std::list<std::pair<std::string, std::string>>
|
|||||||
localtime_r(&timer, &timeinfo);
|
localtime_r(&timer, &timeinfo);
|
||||||
strftime(tstr, 200, "%H", &timeinfo);
|
strftime(tstr, 200, "%H", &timeinfo);
|
||||||
|
|
||||||
pair = std::make_pair(std::string("TIME_HOUR"),
|
resl->push_back(new ModSecurityStringVar("TIME_HOUR", std::string(tstr)));
|
||||||
std::string(tstr));
|
|
||||||
resl.push_back(pair);
|
|
||||||
|
|
||||||
return resl;
|
return resl;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ class TimeHour : public Variable {
|
|||||||
explicit TimeHour(std::string _name)
|
explicit TimeHour(std::string _name)
|
||||||
: Variable(_name) { }
|
: Variable(_name) { }
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
evaluate(Assay *assay) override;
|
evaluate(Assay *assay) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,10 +33,10 @@
|
|||||||
namespace ModSecurity {
|
namespace ModSecurity {
|
||||||
namespace Variables {
|
namespace Variables {
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
TimeMin::evaluate(Assay *assay) {
|
TimeMin::evaluate(Assay *assay) {
|
||||||
std::list<std::pair<std::string, std::string>> resl;
|
std::list<ModSecurityStringVar *> *resl = new std::list<ModSecurityStringVar *>();
|
||||||
std::pair<std::string, std::string> pair;
|
|
||||||
char tstr[200];
|
char tstr[200];
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
time_t timer;
|
time_t timer;
|
||||||
@ -47,9 +47,7 @@ std::list<std::pair<std::string, std::string>>
|
|||||||
localtime_r(&timer, &timeinfo);
|
localtime_r(&timer, &timeinfo);
|
||||||
strftime(tstr, 200, "%M", &timeinfo);
|
strftime(tstr, 200, "%M", &timeinfo);
|
||||||
|
|
||||||
pair = std::make_pair(std::string("TIME_MIN"),
|
resl->push_back(new ModSecurityStringVar("TIME_MIN", std::string(tstr)));
|
||||||
std::string(tstr));
|
|
||||||
resl.push_back(pair);
|
|
||||||
|
|
||||||
return resl;
|
return resl;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ class TimeMin : public Variable {
|
|||||||
explicit TimeMin(std::string _name)
|
explicit TimeMin(std::string _name)
|
||||||
: Variable(_name) { }
|
: Variable(_name) { }
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
evaluate(Assay *assay) override;
|
evaluate(Assay *assay) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,10 +33,10 @@
|
|||||||
namespace ModSecurity {
|
namespace ModSecurity {
|
||||||
namespace Variables {
|
namespace Variables {
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
TimeMon::evaluate(Assay *assay) {
|
TimeMon::evaluate(Assay *assay) {
|
||||||
std::list<std::pair<std::string, std::string>> resl;
|
std::list<ModSecurityStringVar *> *resl = new std::list<ModSecurityStringVar *>();
|
||||||
std::pair<std::string, std::string> pair;
|
|
||||||
char tstr[200];
|
char tstr[200];
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
time_t timer;
|
time_t timer;
|
||||||
@ -49,9 +49,7 @@ std::list<std::pair<std::string, std::string>>
|
|||||||
int a = atoi(tstr);
|
int a = atoi(tstr);
|
||||||
a--;
|
a--;
|
||||||
|
|
||||||
pair = std::make_pair(std::string("TIME_MON"),
|
resl->push_back(new ModSecurityStringVar("TIME_MON", std::to_string(a)));
|
||||||
std::to_string(a));
|
|
||||||
resl.push_back(pair);
|
|
||||||
|
|
||||||
return resl;
|
return resl;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ class TimeMon : public Variable {
|
|||||||
explicit TimeMon(std::string _name)
|
explicit TimeMon(std::string _name)
|
||||||
: Variable(_name) { }
|
: Variable(_name) { }
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
evaluate(Assay *assay) override;
|
evaluate(Assay *assay) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,10 +33,10 @@
|
|||||||
namespace ModSecurity {
|
namespace ModSecurity {
|
||||||
namespace Variables {
|
namespace Variables {
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
TimeSec::evaluate(Assay *assay) {
|
TimeSec::evaluate(Assay *assay) {
|
||||||
std::list<std::pair<std::string, std::string>> resl;
|
std::list<ModSecurityStringVar *> *resl = new std::list<ModSecurityStringVar *>();
|
||||||
std::pair<std::string, std::string> pair;
|
|
||||||
char tstr[200];
|
char tstr[200];
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
time_t timer;
|
time_t timer;
|
||||||
@ -47,9 +47,7 @@ std::list<std::pair<std::string, std::string>>
|
|||||||
localtime_r(&timer, &timeinfo);
|
localtime_r(&timer, &timeinfo);
|
||||||
strftime(tstr, 200, "%S", &timeinfo);
|
strftime(tstr, 200, "%S", &timeinfo);
|
||||||
|
|
||||||
pair = std::make_pair(std::string("TIME_SEC"),
|
resl->push_back(new ModSecurityStringVar("TIME_SEC", std::string(tstr)));
|
||||||
std::string(tstr));
|
|
||||||
resl.push_back(pair);
|
|
||||||
|
|
||||||
return resl;
|
return resl;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ class TimeSec : public Variable {
|
|||||||
explicit TimeSec(std::string _name)
|
explicit TimeSec(std::string _name)
|
||||||
: Variable(_name) { }
|
: Variable(_name) { }
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
evaluate(Assay *assay) override;
|
evaluate(Assay *assay) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,10 +33,10 @@
|
|||||||
namespace ModSecurity {
|
namespace ModSecurity {
|
||||||
namespace Variables {
|
namespace Variables {
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
TimeWDay::evaluate(Assay *assay) {
|
TimeWDay::evaluate(Assay *assay) {
|
||||||
std::list<std::pair<std::string, std::string>> resl;
|
std::list<ModSecurityStringVar *> *resl = new std::list<ModSecurityStringVar *>();
|
||||||
std::pair<std::string, std::string> pair;
|
|
||||||
char tstr[200];
|
char tstr[200];
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
time_t timer;
|
time_t timer;
|
||||||
@ -49,9 +49,7 @@ std::list<std::pair<std::string, std::string>>
|
|||||||
int a = atoi(tstr);
|
int a = atoi(tstr);
|
||||||
a--;
|
a--;
|
||||||
|
|
||||||
pair = std::make_pair(std::string("TIME_WDAY"),
|
resl->push_back(new ModSecurityStringVar("TIME_WDAY", std::to_string(a)));
|
||||||
std::to_string(a));
|
|
||||||
resl.push_back(pair);
|
|
||||||
|
|
||||||
return resl;
|
return resl;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ class TimeWDay : public Variable {
|
|||||||
explicit TimeWDay(std::string _name)
|
explicit TimeWDay(std::string _name)
|
||||||
: Variable(_name) { }
|
: Variable(_name) { }
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
evaluate(Assay *assay) override;
|
evaluate(Assay *assay) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,10 +33,10 @@
|
|||||||
namespace ModSecurity {
|
namespace ModSecurity {
|
||||||
namespace Variables {
|
namespace Variables {
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
TimeYear::evaluate(Assay *assay) {
|
TimeYear::evaluate(Assay *assay) {
|
||||||
std::list<std::pair<std::string, std::string>> resl;
|
std::list<ModSecurityStringVar *> *resl = new std::list<ModSecurityStringVar *>();
|
||||||
std::pair<std::string, std::string> pair;
|
|
||||||
char tstr[200];
|
char tstr[200];
|
||||||
struct tm timeinfo;
|
struct tm timeinfo;
|
||||||
time_t timer;
|
time_t timer;
|
||||||
@ -47,9 +47,7 @@ std::list<std::pair<std::string, std::string>>
|
|||||||
localtime_r(&timer, &timeinfo);
|
localtime_r(&timer, &timeinfo);
|
||||||
strftime(tstr, 200, "%Y", &timeinfo);
|
strftime(tstr, 200, "%Y", &timeinfo);
|
||||||
|
|
||||||
pair = std::make_pair(std::string("TIME_YEAR"),
|
resl->push_back(new ModSecurityStringVar("TIME_YEAR", std::string(tstr)));
|
||||||
std::string(tstr));
|
|
||||||
resl.push_back(pair);
|
|
||||||
|
|
||||||
return resl;
|
return resl;
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ class TimeYear : public Variable {
|
|||||||
explicit TimeYear(std::string _name)
|
explicit TimeYear(std::string _name)
|
||||||
: Variable(_name) { }
|
: Variable(_name) { }
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
evaluate(Assay *assay) override;
|
evaluate(Assay *assay) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,15 +33,11 @@
|
|||||||
namespace ModSecurity {
|
namespace ModSecurity {
|
||||||
namespace Variables {
|
namespace Variables {
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
Tx::evaluate(Assay *assay) {
|
Tx::evaluate(Assay *assay) {
|
||||||
std::list<std::pair<std::string, std::string>> resl;
|
std::list<ModSecurityStringVar *> *resl = new std::list<ModSecurityStringVar *>();
|
||||||
std::pair<std::string, std::string> pair;
|
|
||||||
|
|
||||||
pair = std::make_pair(std::string("TX:0"),
|
resl->push_back(new ModSecurityStringVar("TX:0", "teste"));
|
||||||
std::string("teste"));
|
|
||||||
|
|
||||||
resl.push_back(pair);
|
|
||||||
|
|
||||||
return resl;
|
return resl;
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ class Tx : public Variable {
|
|||||||
explicit Tx(std::string _name)
|
explicit Tx(std::string _name)
|
||||||
: Variable(_name) { }
|
: Variable(_name) { }
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
evaluate(Assay *assay) override;
|
evaluate(Assay *assay) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -28,9 +28,11 @@ using ModSecurity::Variables::Variations::Exclusion;
|
|||||||
namespace ModSecurity {
|
namespace ModSecurity {
|
||||||
namespace Variables {
|
namespace Variables {
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
Variable::evaluate(Assay *assay) {
|
Variable::evaluate(Assay *assay) {
|
||||||
return assay->resolve_variable(this->name);
|
std::list<ModSecurityStringVar *> *l = new std::list<ModSecurityStringVar *>();
|
||||||
|
assay->resolve_variable(this->name, l);
|
||||||
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Variable::to_s(
|
std::string Variable::to_s(
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include "modsecurity/assay.h"
|
||||||
|
|
||||||
#ifndef SRC_VARIABLES_VARIABLE_H_
|
#ifndef SRC_VARIABLES_VARIABLE_H_
|
||||||
#define SRC_VARIABLES_VARIABLE_H_
|
#define SRC_VARIABLES_VARIABLE_H_
|
||||||
@ -32,7 +33,7 @@ class Variable {
|
|||||||
: name(_name) { }
|
: name(_name) { }
|
||||||
|
|
||||||
static std::string to_s(std::vector<Variable *> *variables);
|
static std::string to_s(std::vector<Variable *> *variables);
|
||||||
virtual std::list<std::pair<std::string, std::string>>
|
virtual std::list<ModSecurityStringVar *> *
|
||||||
evaluate(Assay *assay);
|
evaluate(Assay *assay);
|
||||||
std::string name;
|
std::string name;
|
||||||
};
|
};
|
||||||
|
@ -28,23 +28,22 @@ namespace ModSecurity {
|
|||||||
namespace Variables {
|
namespace Variables {
|
||||||
namespace Variations {
|
namespace Variations {
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
Count::evaluate(Assay *assay) {
|
Count::evaluate(Assay *assay) {
|
||||||
std::list<std::pair<std::string, std::string>> reslIn;
|
std::list<ModSecurityStringVar *> *reslIn;
|
||||||
std::list<std::pair<std::string, std::string>> reslOut;
|
std::list<ModSecurityStringVar *> *reslOut = new std::list<ModSecurityStringVar *>();
|
||||||
std::pair<std::string, std::string> pair;
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
reslIn = var->evaluate(assay);
|
reslIn = var->evaluate(assay);
|
||||||
|
|
||||||
for (auto &a : reslIn) {
|
for (auto &a : *reslIn) {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string res = std::to_string(count);
|
std::string res = std::to_string(count);
|
||||||
|
|
||||||
pair = std::make_pair(std::string(var->name), std::string(res));
|
reslOut->push_back(new ModSecurityStringVar(std::string(var->name),
|
||||||
reslOut.push_back(pair);
|
std::string(res)));
|
||||||
|
|
||||||
return reslOut;
|
return reslOut;
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ class Count : public Variable {
|
|||||||
: Variable("count(" + v->name + ")"),
|
: Variable("count(" + v->name + ")"),
|
||||||
var(v) { }
|
var(v) { }
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
evaluate(Assay *assay) override;
|
evaluate(Assay *assay) override;
|
||||||
|
|
||||||
Variable *var;
|
Variable *var;
|
||||||
|
@ -29,9 +29,11 @@ namespace Variables {
|
|||||||
namespace Variations {
|
namespace Variations {
|
||||||
|
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
Exclusion::evaluate(Assay *assay) {
|
Exclusion::evaluate(Assay *assay) {
|
||||||
return assay->resolve_variable(this->name);
|
std::list<ModSecurityStringVar *> *l = new std::list<ModSecurityStringVar *>();
|
||||||
|
assay->resolve_variable(this->name, l);
|
||||||
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ class Exclusion : public Variable {
|
|||||||
: Variable(v->name),
|
: Variable(v->name),
|
||||||
var(v) { }
|
var(v) { }
|
||||||
|
|
||||||
std::list<std::pair<std::string, std::string>>
|
std::list<ModSecurityStringVar *> *
|
||||||
evaluate(Assay *assay) override;
|
evaluate(Assay *assay) override;
|
||||||
|
|
||||||
Variable *var;
|
Variable *var;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user