Refactoring: Renames RulesProperties to RulesSetProperties

This commit is contained in:
Felipe Zimmerle
2018-11-13 16:08:27 -03:00
parent bad5892b93
commit 6a742cdf76
27 changed files with 675 additions and 628 deletions

View File

@@ -45,8 +45,8 @@ pkginclude_HEADERS = \
../headers/modsecurity/rule_message.h \
../headers/modsecurity/rules.h \
../headers/modsecurity/rules_set.h \
../headers/modsecurity/rules_set_properties.h \
../headers/modsecurity/rules_exceptions.h \
../headers/modsecurity/rules_properties.h \
../headers/modsecurity/transaction.h \
../headers/modsecurity/variable_origin.h \
../headers/modsecurity/variable_value.h
@@ -274,7 +274,8 @@ libmodsecurity_la_SOURCES = \
audit_log/writer/serial.cc \
audit_log/writer/parallel.cc \
modsecurity.cc \
rules.cc \
rules_set.cc \
rules_set_properties.cc \
debug_log/debug_log.cc \
debug_log/debug_log_writer.cc \
run_time_string.cc \
@@ -283,7 +284,6 @@ libmodsecurity_la_SOURCES = \
rule_script.cc \
unique_id.cc \
rules_exceptions.cc \
rules_properties.cc \
${BODY_PROCESSORS} \
${ACTIONS} \
${ENGINES} \

View File

@@ -18,7 +18,7 @@
#include <iostream>
#include <string>
#include "modsecurity/rules_properties.h"
#include "modsecurity/rules_set_properties.h"
#include "modsecurity/transaction.h"
namespace modsecurity {
@@ -44,9 +44,9 @@ bool RequestBodyAccess::init(std::string *error) {
bool RequestBodyAccess::evaluate(Rule *rule, Transaction *transaction) {
if (m_request_body_access) {
transaction->m_requestBodyAccess = RulesProperties::TrueConfigBoolean;
transaction->m_requestBodyAccess = RulesSetProperties::TrueConfigBoolean;
} else {
transaction->m_requestBodyAccess = RulesProperties::FalseConfigBoolean;
transaction->m_requestBodyAccess = RulesSetProperties::FalseConfigBoolean;
}
return true;

View File

@@ -18,8 +18,8 @@
#include <iostream>
#include <string>
#include "modsecurity/rules_set_properties.h"
#include "modsecurity/rules_set.h"
#include "modsecurity/rules_properties.h"
#include "modsecurity/transaction.h"
namespace modsecurity {
@@ -31,11 +31,11 @@ bool RuleEngine::init(std::string *error) {
std::string what(m_parser_payload, 11, m_parser_payload.size() - 11);
if (what == "on") {
m_ruleEngine = RulesProperties::EnabledRuleEngine;
m_ruleEngine = RulesSetProperties::EnabledRuleEngine;
} else if (what == "off") {
m_ruleEngine = RulesProperties::DisabledRuleEngine;
m_ruleEngine = RulesSetProperties::DisabledRuleEngine;
} else if (what == "detectiononly") {
m_ruleEngine = RulesProperties::DetectionOnlyRuleEngine;
m_ruleEngine = RulesSetProperties::DetectionOnlyRuleEngine;
} else {
error->assign("Internal error. Expected: On, Off or DetectionOnly; " \
"got: " + m_parser_payload);
@@ -48,7 +48,7 @@ bool RuleEngine::init(std::string *error) {
bool RuleEngine::evaluate(Rule *rule, Transaction *transaction) {
std::stringstream a;
a << "Setting SecRuleEngine to ";
a << modsecurity::RulesProperties::ruleEngineStateString(m_ruleEngine);
a << modsecurity::RulesSetProperties::ruleEngineStateString(m_ruleEngine);
a << " as requested by a ctl:ruleEngine action";
ms_dbg_a(transaction, 8, a.str());

View File

@@ -15,9 +15,9 @@
#include <string>
#include "modsecurity/rules_set_properties.h"
#include "modsecurity/actions/action.h"
#include "modsecurity/transaction.h"
#include "modsecurity/rules_properties.h"
#ifndef SRC_ACTIONS_CTL_RULE_ENGINE_H_
@@ -32,12 +32,12 @@ class RuleEngine : public Action {
public:
explicit RuleEngine(const std::string &action)
: Action(action, RunTimeOnlyIfMatchKind),
m_ruleEngine(RulesProperties::PropertyNotSetRuleEngine) { }
m_ruleEngine(RulesSetProperties::PropertyNotSetRuleEngine) { }
bool init(std::string *error) override;
bool evaluate(Rule *rule, Transaction *transaction) override;
RulesProperties::RuleEngine m_ruleEngine;
RulesSetProperties::RuleEngine m_ruleEngine;
};

View File

@@ -25,12 +25,12 @@
#include <locale>
#include <cstring>
#include "modsecurity/rules_set_properties.h"
#include "modsecurity/rules_set.h"
#include "modsecurity/transaction.h"
#include "src/actions/transformations/transformation.h"
#include "src/utils/string.h"
#include "src/utils/system.h"
#include "modsecurity/rules_properties.h"
namespace modsecurity {

View File

@@ -15,8 +15,8 @@
#include <string>
#include "modsecurity/rules_set_properties.h"
#include "modsecurity/actions/action.h"
#include "modsecurity/rules_properties.h"
#include "src/actions/transformations/transformation.h"
#ifndef SRC_ACTIONS_TRANSFORMATIONS_URL_DECODE_UNI_H_

View File

@@ -7,7 +7,9 @@
#include "modsecurity/rule.h"
#include "modsecurity/rule_message.h"
#include "modsecurity/rules_properties.h"
#include "modsecurity/rules_set_properties.h"
namespace modsecurity {
namespace operators {

View File

@@ -15,8 +15,9 @@
#include "src/parser/driver.h"
#include "modsecurity/rules_set_properties.h"
#include "src/parser/seclang-parser.hh"
#include "modsecurity/audit_log.h"
#include "modsecurity/rules_properties.h"
using modsecurity::audit_log::AuditLog;
using modsecurity::Rule;
@@ -25,7 +26,7 @@ namespace modsecurity {
namespace Parser {
Driver::Driver()
: RulesProperties(),
: RulesSetProperties(),
trace_scanning(false),
trace_parsing(false),
lastRule(NULL) { }

View File

@@ -27,7 +27,7 @@
#include "modsecurity/modsecurity.h"
#include "modsecurity/rules_set.h"
#include "modsecurity/rules_properties.h"
#include "modsecurity/rules_set_properties.h"
#include "modsecurity/audit_log.h"
#include "src/rule_script.h"
#ifndef MS_CPPCHECK_DISABLED_FOR_PARSER
@@ -61,7 +61,7 @@ typedef struct Driver_t Driver;
* driver class.
*
**/
class Driver : public RulesProperties {
class Driver : public RulesSetProperties {
public:
Driver();
virtual ~Driver();

View File

@@ -1847,7 +1847,7 @@ namespace yy {
case 21:
#line 803 "seclang-parser.yy"
{
driver.m_uploadKeepFiles = modsecurity::RulesProperties::TrueConfigBoolean;
driver.m_uploadKeepFiles = modsecurity::RulesSetProperties::TrueConfigBoolean;
}
#line 1853 "seclang-parser.cc"
break;
@@ -1855,7 +1855,7 @@ namespace yy {
case 22:
#line 807 "seclang-parser.yy"
{
driver.m_uploadKeepFiles = modsecurity::RulesProperties::FalseConfigBoolean;
driver.m_uploadKeepFiles = modsecurity::RulesSetProperties::FalseConfigBoolean;
}
#line 1861 "seclang-parser.cc"
break;
@@ -1899,7 +1899,7 @@ namespace yy {
case 27:
#line 831 "seclang-parser.yy"
{
driver.m_tmpSaveUploadedFiles = modsecurity::RulesProperties::TrueConfigBoolean;
driver.m_tmpSaveUploadedFiles = modsecurity::RulesSetProperties::TrueConfigBoolean;
}
#line 1905 "seclang-parser.cc"
break;
@@ -1907,7 +1907,7 @@ namespace yy {
case 28:
#line 835 "seclang-parser.yy"
{
driver.m_tmpSaveUploadedFiles = modsecurity::RulesProperties::FalseConfigBoolean;
driver.m_tmpSaveUploadedFiles = modsecurity::RulesSetProperties::FalseConfigBoolean;
}
#line 1913 "seclang-parser.cc"
break;
@@ -2495,7 +2495,7 @@ namespace yy {
case 83:
#line 1223 "seclang-parser.yy"
{
driver.m_secRequestBodyAccess = modsecurity::RulesProperties::TrueConfigBoolean;
driver.m_secRequestBodyAccess = modsecurity::RulesSetProperties::TrueConfigBoolean;
}
#line 2501 "seclang-parser.cc"
break;
@@ -2503,7 +2503,7 @@ namespace yy {
case 84:
#line 1227 "seclang-parser.yy"
{
driver.m_secRequestBodyAccess = modsecurity::RulesProperties::FalseConfigBoolean;
driver.m_secRequestBodyAccess = modsecurity::RulesSetProperties::FalseConfigBoolean;
}
#line 2509 "seclang-parser.cc"
break;
@@ -2511,7 +2511,7 @@ namespace yy {
case 85:
#line 1231 "seclang-parser.yy"
{
driver.m_secResponseBodyAccess = modsecurity::RulesProperties::TrueConfigBoolean;
driver.m_secResponseBodyAccess = modsecurity::RulesSetProperties::TrueConfigBoolean;
}
#line 2517 "seclang-parser.cc"
break;
@@ -2519,7 +2519,7 @@ namespace yy {
case 86:
#line 1235 "seclang-parser.yy"
{
driver.m_secResponseBodyAccess = modsecurity::RulesProperties::FalseConfigBoolean;
driver.m_secResponseBodyAccess = modsecurity::RulesSetProperties::FalseConfigBoolean;
}
#line 2525 "seclang-parser.cc"
break;
@@ -3127,7 +3127,7 @@ namespace yy {
case 142:
#line 1640 "seclang-parser.yy"
{
driver.m_secXMLExternalEntity = modsecurity::RulesProperties::FalseConfigBoolean;
driver.m_secXMLExternalEntity = modsecurity::RulesSetProperties::FalseConfigBoolean;
}
#line 3133 "seclang-parser.cc"
break;
@@ -3135,7 +3135,7 @@ namespace yy {
case 143:
#line 1644 "seclang-parser.yy"
{
driver.m_secXMLExternalEntity = modsecurity::RulesProperties::TrueConfigBoolean;
driver.m_secXMLExternalEntity = modsecurity::RulesSetProperties::TrueConfigBoolean;
}
#line 3141 "seclang-parser.cc"
break;

View File

@@ -187,7 +187,7 @@ class Driver;
#include "modsecurity/audit_log.h"
#include "modsecurity/modsecurity.h"
#include "modsecurity/rules_properties.h"
#include "modsecurity/rules_set_properties.h"
#include "modsecurity/rule.h"
#include "src/operators/operator.h"
#include "src/utils/geo_lookup.h"

View File

@@ -149,7 +149,7 @@ class Driver;
#include "modsecurity/audit_log.h"
#include "modsecurity/modsecurity.h"
#include "modsecurity/rules_properties.h"
#include "modsecurity/rules_set_properties.h"
#include "modsecurity/rule.h"
#include "src/operators/operator.h"
#include "src/utils/geo_lookup.h"
@@ -801,11 +801,11 @@ audit_log:
/* Upload */
| CONFIG_UPDLOAD_KEEP_FILES CONFIG_VALUE_ON
{
driver.m_uploadKeepFiles = modsecurity::RulesProperties::TrueConfigBoolean;
driver.m_uploadKeepFiles = modsecurity::RulesSetProperties::TrueConfigBoolean;
}
| CONFIG_UPDLOAD_KEEP_FILES CONFIG_VALUE_OFF
{
driver.m_uploadKeepFiles = modsecurity::RulesProperties::FalseConfigBoolean;
driver.m_uploadKeepFiles = modsecurity::RulesSetProperties::FalseConfigBoolean;
}
| CONFIG_UPDLOAD_KEEP_FILES CONFIG_VALUE_RELEVANT_ONLY
{
@@ -829,11 +829,11 @@ audit_log:
}
| CONFIG_UPDLOAD_SAVE_TMP_FILES CONFIG_VALUE_ON
{
driver.m_tmpSaveUploadedFiles = modsecurity::RulesProperties::TrueConfigBoolean;
driver.m_tmpSaveUploadedFiles = modsecurity::RulesSetProperties::TrueConfigBoolean;
}
| CONFIG_UPDLOAD_SAVE_TMP_FILES CONFIG_VALUE_OFF
{
driver.m_tmpSaveUploadedFiles = modsecurity::RulesProperties::FalseConfigBoolean;
driver.m_tmpSaveUploadedFiles = modsecurity::RulesSetProperties::FalseConfigBoolean;
}
;
@@ -1221,19 +1221,19 @@ expression:
}
| CONFIG_DIR_REQ_BODY CONFIG_VALUE_ON
{
driver.m_secRequestBodyAccess = modsecurity::RulesProperties::TrueConfigBoolean;
driver.m_secRequestBodyAccess = modsecurity::RulesSetProperties::TrueConfigBoolean;
}
| CONFIG_DIR_REQ_BODY CONFIG_VALUE_OFF
{
driver.m_secRequestBodyAccess = modsecurity::RulesProperties::FalseConfigBoolean;
driver.m_secRequestBodyAccess = modsecurity::RulesSetProperties::FalseConfigBoolean;
}
| CONFIG_DIR_RES_BODY CONFIG_VALUE_ON
{
driver.m_secResponseBodyAccess = modsecurity::RulesProperties::TrueConfigBoolean;
driver.m_secResponseBodyAccess = modsecurity::RulesSetProperties::TrueConfigBoolean;
}
| CONFIG_DIR_RES_BODY CONFIG_VALUE_OFF
{
driver.m_secResponseBodyAccess = modsecurity::RulesProperties::FalseConfigBoolean;
driver.m_secResponseBodyAccess = modsecurity::RulesSetProperties::FalseConfigBoolean;
}
| CONFIG_SEC_ARGUMENT_SEPARATOR
{
@@ -1638,11 +1638,11 @@ expression:
}
| CONFIG_XML_EXTERNAL_ENTITY CONFIG_VALUE_OFF
{
driver.m_secXMLExternalEntity = modsecurity::RulesProperties::FalseConfigBoolean;
driver.m_secXMLExternalEntity = modsecurity::RulesSetProperties::FalseConfigBoolean;
}
| CONFIG_XML_EXTERNAL_ENTITY CONFIG_VALUE_ON
{
driver.m_secXMLExternalEntity = modsecurity::RulesProperties::TrueConfigBoolean;
driver.m_secXMLExternalEntity = modsecurity::RulesSetProperties::TrueConfigBoolean;
}
| CONGIG_DIR_SEC_TMP_DIR
{

View File

@@ -73,12 +73,12 @@ Multipart::Multipart(const std::string &header, Transaction *transaction)
Multipart::~Multipart() {
ms_dbg_a(m_transaction, 4,
"Multipart: Cleanup started (keep files set to " \
+ RulesProperties::configBooleanString(
+ RulesSetProperties::configBooleanString(
m_transaction->m_rules->m_uploadKeepFiles) \
+ ")");
if (m_transaction->m_rules->m_uploadKeepFiles
!= RulesProperties::TrueConfigBoolean) {
!= RulesSetProperties::TrueConfigBoolean) {
for (MultipartPart *m : m_parts) {
if (m->m_type == MULTIPART_FILE) {
if (!m->m_tmp_file_name.empty()) {
@@ -514,9 +514,9 @@ int Multipart::process_part_data(std::string *error, size_t offset) {
/* add data to the part we are building */
if (m_mpp->m_type == MULTIPART_FILE) {
bool extract = m_transaction->m_rules->m_uploadKeepFiles \
== RulesProperties::TrueConfigBoolean \
== RulesSetProperties::TrueConfigBoolean \
|| m_transaction->m_rules->m_tmpSaveUploadedFiles \
== RulesProperties::TrueConfigBoolean;
== RulesSetProperties::TrueConfigBoolean;
/* remember where we started */
if (m_mpp->m_length == 0) {

View File

@@ -48,7 +48,7 @@ XML::~XML() {
bool XML::init() {
//xmlParserInputBufferCreateFilenameFunc entity;
if (m_transaction->m_rules->m_secXMLExternalEntity
== RulesProperties::TrueConfigBoolean) {
== RulesSetProperties::TrueConfigBoolean) {
/*entity = */xmlParserInputBufferCreateFilenameDefault(
__xmlParserInputBufferCreateFilename);
} else {

View File

@@ -223,8 +223,8 @@ int RulesSet::evaluate(int phase, Transaction *t) {
int RulesSet::merge(Driver *from) {
int amount_of_rules = 0;
amount_of_rules = mergeProperties(
dynamic_cast<RulesProperties *>(from),
dynamic_cast<RulesProperties *>(this),
dynamic_cast<RulesSetProperties *>(from),
dynamic_cast<RulesSetProperties *>(this),
&m_parserError);
return amount_of_rules;
@@ -234,8 +234,8 @@ int RulesSet::merge(Driver *from) {
int RulesSet::merge(RulesSet *from) {
int amount_of_rules = 0;
amount_of_rules = mergeProperties(
dynamic_cast<RulesProperties *>(from),
dynamic_cast<RulesProperties *>(this),
dynamic_cast<RulesSetProperties *>(from),
dynamic_cast<RulesSetProperties *>(this),
&m_parserError);
return amount_of_rules;

View File

@@ -13,10 +13,9 @@
*
*/
#include "modsecurity/rules_properties.h"
#include <string>
#include "modsecurity/rules_set_properties.h"
#include "src/utils/string.h"
#include "src/variables/variable.h"
@@ -24,7 +23,7 @@ namespace modsecurity {
void ConfigUnicodeMap::loadConfig(std::string f, double configCodePage,
RulesProperties *driver, std::string *errg) {
RulesSetProperties *driver, std::string *errg) {
char *buf = NULL;
char *hmap = NULL;
char *p = NULL;

View File

@@ -49,7 +49,7 @@
#include "src/utils/random.h"
#include "modsecurity/rule.h"
#include "modsecurity/rule_message.h"
#include "modsecurity/rules_properties.h"
#include "modsecurity/rules_set_properties.h"
#include "src/actions/disruptive/allow.h"
#include "src/variables/remote_user.h"
@@ -147,7 +147,7 @@ Transaction::Transaction(ModSecurity *ms, RulesSet *rules, void *logCbData)
#else
m_json(NULL),
#endif
m_secRuleEngine(RulesProperties::PropertyNotSetRuleEngine),
m_secRuleEngine(RulesSetProperties::PropertyNotSetRuleEngine),
m_variableDuration(""),
m_variableEnvs(),
m_variableHighestSeverityAction(""),
@@ -220,7 +220,7 @@ Transaction::Transaction(ModSecurity *ms, RulesSet *rules, char *id, void *logCb
#else
m_json(NULL),
#endif
m_secRuleEngine(RulesProperties::PropertyNotSetRuleEngine),
m_secRuleEngine(RulesSetProperties::PropertyNotSetRuleEngine),
m_variableDuration(""),
m_variableEnvs(),
m_variableHighestSeverityAction(""),
@@ -778,7 +778,7 @@ int Transaction::addRequestHeader(const unsigned char *key, size_t key_n,
int Transaction::processRequestBody() {
ms_dbg(4, "Starting phase REQUEST_BODY. (SecRules 2)");
if (getRuleEngineState() == RulesProperties::DisabledRuleEngine) {
if (getRuleEngineState() == RulesSetProperties::DisabledRuleEngine) {
ms_dbg(4, "Rule engine disabled, returning...");
return true;
}
@@ -891,8 +891,8 @@ int Transaction::processRequestBody() {
m_variableReqbodyProcessorError.set("0", m_variableOffset);
}
if (m_rules->m_secRequestBodyAccess == RulesProperties::FalseConfigBoolean) {
if (m_requestBodyAccess != RulesProperties::TrueConfigBoolean) {
if (m_rules->m_secRequestBodyAccess == RulesSetProperties::FalseConfigBoolean) {
if (m_requestBodyAccess != RulesSetProperties::TrueConfigBoolean) {
ms_dbg(4, "Request body processing is disabled");
return true;
} else {
@@ -901,7 +901,7 @@ int Transaction::processRequestBody() {
"action");
}
} else {
if (m_requestBodyAccess == RulesProperties::FalseConfigBoolean) {
if (m_requestBodyAccess == RulesSetProperties::FalseConfigBoolean) {
ms_dbg(4, "Request body processing is enabled, but " \
"disabled to this transaction due to ctl:requestBodyAccess " \
"action");
@@ -1189,7 +1189,7 @@ int Transaction::processResponseBody() {
return true;
}
if (m_rules->m_secResponseBodyAccess != RulesProperties::TrueConfigBoolean) {
if (m_rules->m_secResponseBodyAccess != RulesSetProperties::TrueConfigBoolean) {
ms_dbg(4, "Response body is disabled, returning... " + std::to_string(m_rules->m_secResponseBodyAccess));
return true;
}
@@ -1729,7 +1729,7 @@ std::string Transaction::toJSON(int parts) {
/* producer > engine state */
LOGFY_ADD("secrules_engine",
RulesSet::ruleEngineStateString(
(RulesProperties::RuleEngine) getRuleEngineState()));
(RulesSetProperties::RuleEngine) getRuleEngineState()));
/* producer > components */
yajl_gen_string(g,
@@ -1816,7 +1816,7 @@ void Transaction::serverLog(std::shared_ptr<RuleMessage> rm) {
int Transaction::getRuleEngineState() const {
if (m_secRuleEngine == RulesProperties::PropertyNotSetRuleEngine) {
if (m_secRuleEngine == RulesSetProperties::PropertyNotSetRuleEngine) {
return m_rules->m_secRuleEngine;
}

View File

@@ -36,7 +36,7 @@
#include <utility>
#include "modsecurity/transaction.h"
#include "modsecurity/rules_properties.h"
#include "modsecurity/rules_set_properties.h"
#include "modsecurity/rules_set.h"
#include "src/request_body_processor/xml.h"