Skip to content

Commit 6f7fdd9

Browse files
author
Felipe Zimmerle
committed
Using direct variable access instead m_collections
1 parent 43bba3f commit 6f7fdd9

File tree

17 files changed

+247
-447
lines changed

17 files changed

+247
-447
lines changed

headers/modsecurity/collection/collections.h

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -43,69 +43,12 @@ typedef struct Collections_t Collections;
4343
namespace modsecurity {
4444
namespace collection {
4545

46-
class Collections :
47-
public std::unordered_map<std::string, Collection *> {
46+
class Collections {
4847
public:
4948
Collections(Collection *global, Collection *ip, Collection *session,
5049
Collection *user, Collection *resource);
5150
~Collections();
5251

53-
void store(std::string key, std::string value);
54-
void storeOrUpdateFirst(const std::string& collectionName,
55-
const std::string& variableName,
56-
const std::string& targetValue);
57-
void storeOrUpdateFirst(const std::string& collectionName,
58-
const std::string& variableName,
59-
const std::string& appid,
60-
const std::string& targetValue);
61-
bool storeOrUpdateFirst(const std::string &key, const std::string &value);
62-
bool updateFirst(const std::string &key, const std::string &value);
63-
void del(const std::string& key);
64-
std::unique_ptr<std::string> resolveFirst(const std::string& var);
65-
std::unique_ptr<std::string> resolveFirst(const std::string& collectionName,
66-
const std::string& var);
67-
std::unique_ptr<std::string> resolveFirst(const std::string& collectionName,
68-
const std::string &appid, const std::string& var);
69-
70-
void resolveSingleMatch(const std::string& var,
71-
std::vector<const Variable *> *l);
72-
void resolveSingleMatch(const std::string& var,
73-
const std::string& collection,
74-
std::vector<const Variable *> *l);
75-
void resolveSingleMatch(const std::string& var,
76-
const std::string& collection,
77-
const std::string& appid,
78-
std::vector<const Variable *> *l);
79-
80-
void resolveMultiMatches(const std::string& var,
81-
std::vector<const Variable *> *l);
82-
void resolveMultiMatches(const std::string& var,
83-
const std::string& collection,
84-
std::vector<const Variable *> *l);
85-
void resolveMultiMatches(const std::string& var,
86-
const std::string& collection,
87-
const std::string& appid,
88-
std::vector<const Variable *> *l);
89-
90-
void resolveRegularExpression(const std::string& var,
91-
std::vector<const Variable *> *l);
92-
void resolveRegularExpression(const std::string& var,
93-
const std::string& collection,
94-
std::vector<const Variable *> *l);
95-
void resolveRegularExpression(const std::string& var,
96-
const std::string& collection,
97-
const std::string& appid,
98-
std::vector<const Variable *> *l);
99-
100-
/**
101-
* This is a special collection to host the transaction variables.
102-
*
103-
* It exists independent of initialization and it is only valid during a transaction.
104-
*
105-
* Notice that it is not the TX collection.
106-
*/
107-
Collection *m_transient;
108-
10952
std::string m_global_collection_key;
11053
std::string m_ip_collection_key;
11154
std::string m_session_collection_key;
@@ -117,6 +60,7 @@ class Collections :
11760
Collection *m_session_collection;
11861
Collection *m_user_collection;
11962
Collection *m_resource_collection;
63+
Collection *m_tx_collection;
12064
};
12165

12266
} // namespace collection

src/actions/log_data.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ bool LogData::evaluate(Rule *rule, Transaction *transaction,
3333
std::shared_ptr<RuleMessage> rm) {
3434
rm->m_data = data(transaction);
3535

36-
transaction->m_collections.storeOrUpdateFirst("RULE:logdata", rm->m_data);
36+
transaction->m_variableRule.set("logdata", rm->m_data, 0);
37+
3738
return true;
3839
}
3940

src/actions/msg.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ bool Msg::evaluate(Rule *rule, Transaction *transaction,
5454
transaction->debug(9, "Saving msg: " + msg);
5555
#endif
5656

57-
transaction->m_collections.storeOrUpdateFirst("RULE:msg", msg);
57+
transaction->m_variableRule.set("msg", msg, 0);
5858

5959
return true;
6060
}

src/actions/set_var.cc

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,21 @@ bool SetVar::evaluate(Rule *rule, Transaction *t) {
7979
} else if (m_operation == setToOneOperation) {
8080
targetValue = std::string("1");
8181
} else if (m_operation == unsetOperation) {
82-
t->m_collections.del(m_variable->m_collectionName + ":" +
83-
m_variableNameExpanded);
82+
if (tx) {
83+
tx->del(t, m_variableNameExpanded);
84+
} else if (session) {
85+
session->del(t, m_variableNameExpanded);
86+
} else if (ip) {
87+
ip->del(t, m_variableNameExpanded);
88+
} else if (resource) {
89+
resource->del(t, m_variableNameExpanded);
90+
} else if (global) {
91+
global->del(t, m_variableNameExpanded);
92+
} else if (user) {
93+
user->del(t, m_variableNameExpanded);
94+
} else {
95+
// ?
96+
}
8497
goto end;
8598
} else {
8699
int pre = 0;
@@ -118,9 +131,26 @@ bool SetVar::evaluate(Rule *rule, Transaction *t) {
118131
t->debug(8, "Saving variable: " + m_variable->m_collectionName \
119132
+ ":" + m_variableNameExpanded + " with value: " + targetValue);
120133
#endif
134+
if (tx) {
135+
tx->storeOrUpdateFirst(t, m_variableNameExpanded, targetValue);
136+
} else if (session) {
137+
session->storeOrUpdateFirst(t, m_variableNameExpanded, targetValue);
138+
} else if (ip) {
139+
ip->storeOrUpdateFirst(t, m_variableNameExpanded, targetValue);
140+
} else if (resource) {
141+
resource->storeOrUpdateFirst(t, m_variableNameExpanded, targetValue);
142+
} else if (global) {
143+
global->storeOrUpdateFirst(t, m_variableNameExpanded, targetValue);
144+
} else if (user) {
145+
user->storeOrUpdateFirst(t, m_variableNameExpanded, targetValue);
146+
} else {
147+
// ?
148+
}
149+
/*
121150
t->m_collections.storeOrUpdateFirst(m_variable->m_collectionName,
122151
m_variableNameExpanded,
123152
t->m_rules->m_secWebAppId.m_value, targetValue);
153+
*/
124154
end:
125155
return true;
126156
}

src/actions/severity.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ bool Severity::evaluate(Rule *rule, Transaction *transaction,
8484
transaction->m_highestSeverityAction = this->m_severity;
8585
}
8686

87-
transaction->m_collections.storeOrUpdateFirst("RULE:severity",
88-
std::to_string(m_severity));
87+
transaction->m_variableRule.set("severity", std::to_string(m_severity), 0);
88+
8989
return true;
9090
}
9191

0 commit comments

Comments
 (0)