Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit baf1899

Browse files
committedOct 21, 2020
Having RuleWithActionsProperties()
1 parent e20462f commit baf1899

33 files changed

+905
-493
lines changed
 

‎src/Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ libmodsecurity_la_SOURCES = \
287287
rules.cc \
288288
rule_unconditional.cc \
289289
rule_with_actions.cc \
290+
rule_with_actions_properties.cc \
290291
rule_with_operator.cc \
291292
rule_message.cc \
292293
rule_script.cc \

‎src/actions/action_with_run_time_string.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ class ActionWithRunTimeString : public virtual Action {
4343
return *this;
4444
}
4545

46-
virtual void populate(RuleWithActions *rule) {
46+
virtual void populate(const RuleWithActions *rule) {
4747
if (m_string) {
4848
m_string->populate(rule);
4949
}
5050
}
5151

5252
std::string getEvaluatedRunTimeString(const Transaction *transaction) const noexcept {
53-
return (m_string == nullptr)?"":m_string->evaluate(transaction);
53+
return (!m_string)?"":m_string->evaluate(transaction);
5454
}
5555

5656
bool hasRunTimeString() const noexcept {

‎src/actions/audit_log.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class AuditLog : public ActionTypeRuleMetaData,
3636
{ }
3737

3838
void configure(RuleWithActions *rule) override {
39-
rule->setHasAuditLogAction(true);
39+
rule->setAuditLog(true);
4040
}
4141
};
4242

‎src/actions/block.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Block : public ActionTypeRuleMetaData,
3737
{ }
3838

3939
void configure(RuleWithActions *rule) override {
40-
rule->setHasBlockAction(true);
40+
rule->setBlock(true);
4141
}
4242
};
4343

‎src/actions/capture.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Capture : public ActionTypeRuleMetaData {
3333
: Action("capture") { }
3434

3535
void configure(RuleWithActions *rule) override {
36-
rule->setHasCaptureAction(true);
36+
rule->setHasCapture(true);
3737
}
3838
};
3939

‎src/actions/log.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Log : public ActionTypeRuleMetaData,
3737
{ }
3838

3939
void configure(RuleWithActions *rule) override {
40-
rule->setHasLogAction(true);
40+
rule->setLog(true);
4141
}
4242

4343
};

‎src/actions/multi_match.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class MultiMatch : public ActionTypeRuleMetaData {
3434

3535

3636
void configure(RuleWithActions *rule) override {
37-
rule->setHasMultimatchAction(true);
37+
rule->setMultiMatch(true);
3838
}
3939
};
4040

‎src/actions/no_audit_log.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class NoAuditLog : public ActionTypeRuleMetaData,
3636
{ }
3737

3838
void configure(RuleWithActions *rule) override {
39-
rule->setHasNoAuditLogAction(true);
39+
rule->setNoAuditLog(true);
4040
}
4141
};
4242

‎src/actions/no_log.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class NoLog : public ActionTypeRuleMetaData,
3636
{ }
3737

3838
void configure(RuleWithActions *rule) override {
39-
rule->setHasNoLogAction(true);
39+
rule->setNoLog(true);
4040
}
4141
};
4242

‎src/actions/set_var.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class SetVar : public ActionWithRunTimeString, public ActionWithExecution {
8787

8888
bool execute(Transaction *transaction) const noexcept override;
8989

90-
void populate(RuleWithActions *rule) override {
90+
void populate(const RuleWithActions *rule) override {
9191
ActionWithRunTimeString::populate(rule);
9292
variables::RuleVariable *rulev =
9393
dynamic_cast<variables::RuleVariable *>(

‎src/actions/tag.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Tag : public ActionWithRunTimeString,
4747

4848
bool execute(Transaction *transaction) const noexcept override;
4949

50-
inline std::string getTagName(Transaction *transaction) const {
50+
inline std::string getTagName(const Transaction *transaction) const {
5151
return getEvaluatedRunTimeString(transaction);
5252
}
5353

‎src/operators/detect_sqli.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ bool DetectSQLi::evaluate(Transaction *transaction,
4545
ms_dbg_a(transaction, 4, "detected SQLi using libinjection with " \
4646
"fingerprint '" + std::string(fingerprint) + "' at: '" +
4747
input.to_string() + "'");
48-
if (rule && rule->hasCaptureAction()) {
48+
if (rule && rule->hasCapture()) {
4949
transaction->m_collections.m_tx_collection->storeOrUpdateFirst(
5050
"0", std::string(fingerprint));
5151
ms_dbg_a(transaction, 7, "Added DetectSQLi match TX.0: " + \

‎src/operators/detect_xss.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ bool DetectXSS::evaluate(Transaction *transaction,
3737
if (transaction) {
3838
if (is_xss) {
3939
ms_dbg_a(transaction, 5, "detected XSS using libinjection.");
40-
if (rule && rule->hasCaptureAction()) {
40+
if (rule && rule->hasCapture()) {
4141
transaction->m_collections.m_tx_collection->storeOrUpdateFirst(
4242
"0", std::string(input));
4343
ms_dbg_a(transaction, 7, "Added DetectXSS match TX.0: " + \

‎src/operators/pm.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ bool Pm::evaluate(Transaction *transaction,
105105
logOffset(ruleMessage, rc - match_.size() + 1, match_.size());
106106
transaction->m_matched.push_back(match_);
107107

108-
if (rule && rule->hasCaptureAction()) {
108+
if (rule && rule->hasCapture()) {
109109
transaction->m_collections.m_tx_collection->storeOrUpdateFirst("0",
110110
match_);
111111
ms_dbg_a(transaction, 7, "Added pm match TX.0: " + \

‎src/operators/rbl.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ bool Rbl::evaluate(Transaction *transaction,
229229
furtherInfo(sin, str.c_str(), transaction, m_provider);
230230

231231
freeaddrinfo(info);
232-
if (rule && transaction && rule->hasCaptureAction()) {
232+
if (rule && transaction && rule->hasCapture()) {
233233
transaction->m_collections.m_tx_collection->storeOrUpdateFirst(
234234
"0", std::string(str));
235235
ms_dbg_a(transaction, 7, "Added RXL match TX.0: " + \

‎src/operators/rx.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ bool Rx::evaluate(Transaction *transaction,
5858
std::vector<Utils::SMatchCapture> captures;
5959
// FIXME: searchOneMatch should accept string_view.
6060
re->searchOneMatch(input.c_str(), captures);
61-
if (rule && rule->hasCaptureAction() && transaction) {
61+
if (rule && rule->hasCapture() && transaction) {
6262
for (const Utils::SMatchCapture& capture : captures) {
6363
const std::string capture_substring(input.substr(capture.m_offset,capture.m_length));
6464
transaction->m_collections.m_tx_collection->storeOrUpdateFirst(

‎src/operators/verify_cc.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ bool VerifyCC::evaluate(Transaction *transaction,
145145
int is_cc = luhnVerify(match.c_str(), match.size());
146146
if (is_cc) {
147147
if (transaction) {
148-
if (rule && rule->hasCaptureAction()) {
148+
if (rule && rule->hasCapture()) {
149149
transaction->m_collections.m_tx_collection->storeOrUpdateFirst(
150150
"0", std::string(match));
151151
ms_dbg_a(transaction, 7, "Added VerifyCC match TX.0: " + \

‎src/operators/verify_cpf.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ bool VerifyCPF::evaluate(Transaction *transaction,
128128
is_cpf = verify(m.str().c_str(), m.str().size());
129129
if (is_cpf) {
130130
logOffset(ruleMessage, m.offset(), m.str().size());
131-
if (rule && transaction && rule->hasCaptureAction()) {
131+
if (rule && transaction && rule->hasCapture()) {
132132
transaction->m_collections.m_tx_collection->storeOrUpdateFirst(
133133
"0", m.str());
134134
ms_dbg_a(transaction, 7, "Added VerifyCPF match TX.0: " + \

‎src/operators/verify_ssn.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ bool VerifySSN::evaluate(Transaction *transaction,
130130
is_ssn = verify(j.str().c_str(), j.str().size());
131131
if (is_ssn) {
132132
logOffset(ruleMessage, j.offset(), j.str().size());
133-
if (rule && transaction && rule->hasCaptureAction()) {
133+
if (rule && transaction && rule->hasCapture()) {
134134
transaction->m_collections.m_tx_collection->storeOrUpdateFirst(
135135
"0", j.str());
136136
ms_dbg_a(transaction, 7, "Added VerifySSN match TX.0: " + \

‎src/operators/verify_svnr.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ bool VerifySVNR::evaluate(Transaction *t,
9797
is_svnr = verify(j.str().c_str(), j.str().size());
9898
if (is_svnr) {
9999
logOffset(ruleMessage, j.offset(), j.str().size());
100-
if (rule && t && rule->hasCaptureAction()) {
100+
if (rule && t && rule->hasCapture()) {
101101
t->m_collections.m_tx_collection->storeOrUpdateFirst(
102102
"0", j.str());
103103
ms_dbg_a(t, 7, "Added VerifySVNR match TX.0: " + \

‎src/parser/driver.cc

+21-18
Original file line numberDiff line numberDiff line change
@@ -109,59 +109,62 @@ int Driver::addSecRule(std::unique_ptr<RuleWithActions> r) {
109109
);
110110
firstRule->setLogDataAction(nullptr);
111111
}
112-
if (firstRule->hasSeverityAction()) {
112+
if (firstRule->hasSeverity()) {
113113
firstRule->getChainedParent()->setSeverity(
114114
firstRule->getSeverity()
115115
);
116116
}
117-
if (firstRule->hasRevisionAction()) {
117+
if (firstRule->hasRevision()) {
118118
firstRule->getChainedParent()->setRevision(
119119
firstRule->getRevision()
120120
);
121121
}
122-
if (firstRule->hasVersionAction()) {
122+
if (firstRule->hasVersion()) {
123123
firstRule->getChainedParent()->setVersion(
124124
firstRule->getVersion()
125125
);
126126
}
127-
if (firstRule->hasAccuracyAction()) {
127+
if (firstRule->hasAccuracy()) {
128128
firstRule->getChainedParent()->setAccuracy(
129129
firstRule->getAccuracy()
130130
);
131131
}
132-
if (firstRule->hasMaturityAction()) {
132+
if (firstRule->hasMaturity()) {
133133
firstRule->getChainedParent()->setMaturity(
134134
firstRule->getMaturity()
135135
);
136136
}
137137

138-
if (firstRule->hasTagAction()) {
138+
if (firstRule->hasTags()) {
139139
firstRule->getChainedParent()->setTags(
140-
firstRule->getTagsAction()
140+
firstRule->getTags()
141141
);
142-
firstRule->cleanTags();
142+
firstRule->clearTags();
143143
}
144144

145+
/* disruptive can only be set on the first rule
145146
if (firstRule->hasDisruptiveAction()) {
146147
firstRule->getChainedParent()->setDisruptiveAction(
147148
firstRule->getDisruptiveAction()
148149
);
149150
firstRule->setDisruptiveAction(nullptr);
150151
}
151-
firstRule->getChainedParent()->setHasBlockAction(
152-
firstRule->hasBlockAction()
152+
*/
153+
154+
firstRule->getChainedParent()->setBlock(
155+
firstRule->hasBlock()
153156
);
154-
firstRule->getChainedParent()->setHasLogAction(
155-
firstRule->hasLogAction()
157+
firstRule->getChainedParent()->setLog(
158+
firstRule->hasLog()
156159
);
157-
firstRule->getChainedParent()->setHasLogAction(
158-
firstRule->hasNoLogAction()
160+
firstRule->getChainedParent()->setNoLog(
161+
firstRule->hasNoLog()
159162
);
160-
firstRule->getChainedParent()->setHasAuditLogAction(
161-
firstRule->hasAuditLogAction()
163+
firstRule->getChainedParent()->setAuditLog(
164+
firstRule->hasAuditLog()
162165
);
163-
firstRule->getChainedParent()->setHasNoAuditLogAction(
164-
firstRule->hasNoAuditLogAction()
166+
firstRule->getChainedParent()->setNoAuditLog(
167+
firstRule->hasNoAuditLog()
165168
);
166169
firstRule = firstRule->getChainedParent();
167170
}

‎src/rule_message.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ std::string RuleMessage::getUri() const {
218218

219219
bool RuleMessage::isDisruptive() const {
220220
if (m_rule) {
221-
return m_rule->hasDisruptiveAction();
221+
return m_rule->isDisruptive();
222222
}
223223
return 0;
224224
}

0 commit comments

Comments
 (0)
Please sign in to comment.