diff --git a/src/Makefile.am b/src/Makefile.am index d7d3d7cb..60ca9423 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -100,13 +100,13 @@ ACTIONS = \ actions/block.cc \ actions/capture.cc \ actions/chain.cc \ - actions/ctl_audit_log_parts.cc \ - actions/ctl_request_body_processor_json.cc \ - actions/ctl_request_body_processor_xml.cc \ - actions/ctl_rule_remove_target_by_tag.cc \ - actions/ctl_rule_remove_target_by_id.cc \ - actions/ctl_rule_remove_by_id.cc \ - actions/ctl_request_body_access.cc\ + actions/ctl/audit_log_parts.cc \ + actions/ctl/request_body_processor_json.cc \ + actions/ctl/request_body_processor_xml.cc \ + actions/ctl/rule_remove_target_by_tag.cc \ + actions/ctl/rule_remove_target_by_id.cc \ + actions/ctl/rule_remove_by_id.cc \ + actions/ctl/request_body_access.cc\ actions/init_col.cc \ actions/deny.cc \ actions/log.cc \ diff --git a/src/actions/ctl_audit_log_parts.cc b/src/actions/ctl/audit_log_parts.cc similarity index 84% rename from src/actions/ctl_audit_log_parts.cc rename to src/actions/ctl/audit_log_parts.cc index 136bb05e..d4150a00 100644 --- a/src/actions/ctl_audit_log_parts.cc +++ b/src/actions/ctl/audit_log_parts.cc @@ -13,7 +13,7 @@ * */ -#include "actions/ctl_audit_log_parts.h" +#include "actions/ctl/audit_log_parts.h" #include #include @@ -22,8 +22,10 @@ namespace modsecurity { namespace actions { +namespace ctl { -bool CtlAuditLogParts::init(std::string *error) { + +bool AuditLogParts::init(std::string *error) { std::string what(m_parser_payload, 14, 1); mParts = std::string(m_parser_payload, 15, m_parser_payload.length()-15); if (what == "+") { @@ -35,11 +37,13 @@ bool CtlAuditLogParts::init(std::string *error) { return true; } -bool CtlAuditLogParts::evaluate(Rule *rule, Transaction *transaction) { +bool AuditLogParts::evaluate(Rule *rule, Transaction *transaction) { transaction->m_auditLogModifier.push_back( std::make_pair(mPartsAction, mParts)); return true; } + +} // namespace ctl } // namespace actions } // namespace modsecurity diff --git a/src/actions/ctl_audit_log_parts.h b/src/actions/ctl/audit_log_parts.h similarity index 90% rename from src/actions/ctl_audit_log_parts.h rename to src/actions/ctl/audit_log_parts.h index 44d92027..21bb5fe8 100644 --- a/src/actions/ctl_audit_log_parts.h +++ b/src/actions/ctl/audit_log_parts.h @@ -23,11 +23,12 @@ namespace modsecurity { namespace actions { +namespace ctl { -class CtlAuditLogParts : public Action { +class AuditLogParts : public Action { public: - explicit CtlAuditLogParts(std::string action) + explicit AuditLogParts(std::string action) : Action(action, RunTimeOnlyIfMatchKind), mPartsAction(0), mParts("") { } @@ -40,6 +41,8 @@ class CtlAuditLogParts : public Action { std::string mParts; }; + +} // namespace ctl } // namespace actions } // namespace modsecurity diff --git a/src/actions/ctl_request_body_access.cc b/src/actions/ctl/request_body_access.cc similarity index 86% rename from src/actions/ctl_request_body_access.cc rename to src/actions/ctl/request_body_access.cc index ab467732..ca6775c9 100644 --- a/src/actions/ctl_request_body_access.cc +++ b/src/actions/ctl/request_body_access.cc @@ -13,7 +13,7 @@ * */ -#include "actions/ctl_request_body_access.h" +#include "actions/ctl/request_body_access.h" #include #include @@ -23,8 +23,10 @@ namespace modsecurity { namespace actions { +namespace ctl { -bool CtlRequestBodyAccess::init(std::string *error) { + +bool RequestBodyAccess::init(std::string *error) { std::string what(m_parser_payload, 18, m_parser_payload.size() - 18); if (what == "true") { @@ -40,7 +42,7 @@ bool CtlRequestBodyAccess::init(std::string *error) { return true; } -bool CtlRequestBodyAccess::evaluate(Rule *rule, Transaction *transaction) { +bool RequestBodyAccess::evaluate(Rule *rule, Transaction *transaction) { if (m_request_body_access) { transaction->m_requestBodyAccess = RulesProperties::TrueConfigBoolean; } else { @@ -50,5 +52,7 @@ bool CtlRequestBodyAccess::evaluate(Rule *rule, Transaction *transaction) { return true; } + +} // namespace ctl } // namespace actions } // namespace modsecurity diff --git a/src/actions/ctl_request_body_access.h b/src/actions/ctl/request_body_access.h similarity index 89% rename from src/actions/ctl_request_body_access.h rename to src/actions/ctl/request_body_access.h index 33563693..508c8cb0 100644 --- a/src/actions/ctl_request_body_access.h +++ b/src/actions/ctl/request_body_access.h @@ -24,11 +24,12 @@ namespace modsecurity { namespace actions { +namespace ctl { -class CtlRequestBodyAccess : public Action { +class RequestBodyAccess : public Action { public: - explicit CtlRequestBodyAccess(std::string action) + explicit RequestBodyAccess(std::string action) : Action(action, RunTimeOnlyIfMatchKind), m_request_body_access(false) { } @@ -38,6 +39,8 @@ class CtlRequestBodyAccess : public Action { bool m_request_body_access; }; + +} // namespace ctl } // namespace actions } // namespace modsecurity diff --git a/src/actions/ctl_request_body_processor_json.cc b/src/actions/ctl/request_body_processor_json.cc similarity index 86% rename from src/actions/ctl_request_body_processor_json.cc rename to src/actions/ctl/request_body_processor_json.cc index 6cc9bc2f..8da95875 100644 --- a/src/actions/ctl_request_body_processor_json.cc +++ b/src/actions/ctl/request_body_processor_json.cc @@ -13,7 +13,7 @@ * */ -#include "actions/ctl_request_body_processor_json.h" +#include "actions/ctl/request_body_processor_json.h" #include #include @@ -22,9 +22,10 @@ namespace modsecurity { namespace actions { +namespace ctl { -bool CtlRequestBodyProcessorJSON::evaluate(Rule *rule, +bool RequestBodyProcessorJSON::evaluate(Rule *rule, Transaction *transaction) { transaction->m_requestBodyProcessor = Transaction::JSONRequestBody; transaction->m_collections.store("REQBODY_PROCESSOR", "JSON"); @@ -33,5 +34,6 @@ bool CtlRequestBodyProcessorJSON::evaluate(Rule *rule, } +} // namespace ctl } // namespace actions } // namespace modsecurity diff --git a/src/actions/ctl_request_body_processor_json.h b/src/actions/ctl/request_body_processor_json.h similarity index 87% rename from src/actions/ctl_request_body_processor_json.h rename to src/actions/ctl/request_body_processor_json.h index e3e0c5af..8b309b08 100644 --- a/src/actions/ctl_request_body_processor_json.h +++ b/src/actions/ctl/request_body_processor_json.h @@ -23,16 +23,19 @@ namespace modsecurity { namespace actions { +namespace ctl { -class CtlRequestBodyProcessorJSON : public Action { +class RequestBodyProcessorJSON : public Action { public: - explicit CtlRequestBodyProcessorJSON(std::string action) + explicit RequestBodyProcessorJSON(std::string action) : Action(action, RunTimeOnlyIfMatchKind) { } bool evaluate(Rule *rule, Transaction *transaction) override; }; + +} // namespace ctl } // namespace actions } // namespace modsecurity diff --git a/src/actions/ctl_request_body_processor_xml.cc b/src/actions/ctl/request_body_processor_xml.cc similarity index 86% rename from src/actions/ctl_request_body_processor_xml.cc rename to src/actions/ctl/request_body_processor_xml.cc index d90a483c..83e57f13 100644 --- a/src/actions/ctl_request_body_processor_xml.cc +++ b/src/actions/ctl/request_body_processor_xml.cc @@ -13,7 +13,7 @@ * */ -#include "actions/ctl_request_body_processor_xml.h" +#include "actions/ctl/request_body_processor_xml.h" #include #include @@ -22,9 +22,10 @@ namespace modsecurity { namespace actions { +namespace ctl { -bool CtlRequestBodyProcessorXML::evaluate(Rule *rule, +bool RequestBodyProcessorXML::evaluate(Rule *rule, Transaction *transaction) { transaction->m_requestBodyProcessor = Transaction::XMLRequestBody; transaction->m_collections.store("REQBODY_PROCESSOR", "XML"); @@ -33,5 +34,6 @@ bool CtlRequestBodyProcessorXML::evaluate(Rule *rule, } +} // namespace ctl } // namespace actions } // namespace modsecurity diff --git a/src/actions/ctl_request_body_processor_xml.h b/src/actions/ctl/request_body_processor_xml.h similarity index 87% rename from src/actions/ctl_request_body_processor_xml.h rename to src/actions/ctl/request_body_processor_xml.h index eaf7f480..2ad5cd72 100644 --- a/src/actions/ctl_request_body_processor_xml.h +++ b/src/actions/ctl/request_body_processor_xml.h @@ -23,16 +23,19 @@ namespace modsecurity { namespace actions { +namespace ctl { -class CtlRequestBodyProcessorXML : public Action { +class RequestBodyProcessorXML : public Action { public: - explicit CtlRequestBodyProcessorXML(std::string action) + explicit RequestBodyProcessorXML(std::string action) : Action(action, RunTimeOnlyIfMatchKind) { } bool evaluate(Rule *rule, Transaction *transaction) override; }; + +} // namespace ctl } // namespace actions } // namespace modsecurity diff --git a/src/actions/ctl_rule_remove_by_id.cc b/src/actions/ctl/rule_remove_by_id.cc similarity index 83% rename from src/actions/ctl_rule_remove_by_id.cc rename to src/actions/ctl/rule_remove_by_id.cc index 2aae590d..65c5003d 100644 --- a/src/actions/ctl_rule_remove_by_id.cc +++ b/src/actions/ctl/rule_remove_by_id.cc @@ -13,7 +13,7 @@ * */ -#include "actions/ctl_rule_remove_by_id.h" +#include "actions/ctl/rule_remove_by_id.h" #include #include @@ -22,8 +22,10 @@ namespace modsecurity { namespace actions { +namespace ctl { -bool CtlRuleRemoveById::init(std::string *error) { + +bool RuleRemoveById::init(std::string *error) { std::string what(m_parser_payload, 15, m_parser_payload.size() - 15); try { @@ -37,10 +39,12 @@ bool CtlRuleRemoveById::init(std::string *error) { return true; } -bool CtlRuleRemoveById::evaluate(Rule *rule, Transaction *transaction) { +bool RuleRemoveById::evaluate(Rule *rule, Transaction *transaction) { transaction->m_ruleRemoveById.push_back(m_id); return true; } + +} // namespace ctl } // namespace actions } // namespace modsecurity diff --git a/src/actions/ctl_rule_remove_by_id.h b/src/actions/ctl/rule_remove_by_id.h similarity index 89% rename from src/actions/ctl_rule_remove_by_id.h rename to src/actions/ctl/rule_remove_by_id.h index c659d589..499407e1 100644 --- a/src/actions/ctl_rule_remove_by_id.h +++ b/src/actions/ctl/rule_remove_by_id.h @@ -24,11 +24,12 @@ namespace modsecurity { namespace actions { +namespace ctl { -class CtlRuleRemoveById : public Action { +class RuleRemoveById : public Action { public: - explicit CtlRuleRemoveById(std::string action) + explicit RuleRemoveById(std::string action) : Action(action, RunTimeOnlyIfMatchKind) { } bool init(std::string *error) override; @@ -37,6 +38,8 @@ class CtlRuleRemoveById : public Action { int m_id; }; + +} // namespace ctl } // namespace actions } // namespace modsecurity diff --git a/src/actions/ctl_rule_remove_target_by_id.cc b/src/actions/ctl/rule_remove_target_by_id.cc similarity index 85% rename from src/actions/ctl_rule_remove_target_by_id.cc rename to src/actions/ctl/rule_remove_target_by_id.cc index 7ad5cff6..929304d9 100644 --- a/src/actions/ctl_rule_remove_target_by_id.cc +++ b/src/actions/ctl/rule_remove_target_by_id.cc @@ -13,7 +13,7 @@ * */ -#include "actions/ctl_rule_remove_target_by_id.h" +#include "actions/ctl/rule_remove_target_by_id.h" #include #include @@ -23,8 +23,10 @@ namespace modsecurity { namespace actions { +namespace ctl { -bool CtlRuleRemoveTargetById::init(std::string *error) { + +bool RuleRemoveTargetById::init(std::string *error) { std::string what(m_parser_payload, 21, m_parser_payload.size() - 21); std::vector param = split(what, ';'); @@ -46,11 +48,13 @@ bool CtlRuleRemoveTargetById::init(std::string *error) { return true; } -bool CtlRuleRemoveTargetById::evaluate(Rule *rule, Transaction *transaction) { +bool RuleRemoveTargetById::evaluate(Rule *rule, Transaction *transaction) { transaction->m_ruleRemoveTargetById.push_back( std::make_pair(m_id, m_target)); return true; } + +} // namespace ctl } // namespace actions } // namespace modsecurity diff --git a/src/actions/ctl_rule_remove_target_by_id.h b/src/actions/ctl/rule_remove_target_by_id.h similarity index 89% rename from src/actions/ctl_rule_remove_target_by_id.h rename to src/actions/ctl/rule_remove_target_by_id.h index 3e644736..2bfdddc9 100644 --- a/src/actions/ctl_rule_remove_target_by_id.h +++ b/src/actions/ctl/rule_remove_target_by_id.h @@ -24,11 +24,12 @@ namespace modsecurity { namespace actions { +namespace ctl { -class CtlRuleRemoveTargetById : public Action { +class RuleRemoveTargetById : public Action { public: - explicit CtlRuleRemoveTargetById(std::string action) + explicit RuleRemoveTargetById(std::string action) : Action(action, RunTimeOnlyIfMatchKind) { } bool init(std::string *error) override; @@ -38,6 +39,8 @@ class CtlRuleRemoveTargetById : public Action { std::string m_target; }; + +} // namespace ctl } // namespace actions } // namespace modsecurity diff --git a/src/actions/ctl_rule_remove_target_by_tag.cc b/src/actions/ctl/rule_remove_target_by_tag.cc similarity index 83% rename from src/actions/ctl_rule_remove_target_by_tag.cc rename to src/actions/ctl/rule_remove_target_by_tag.cc index 03b57242..198adabd 100644 --- a/src/actions/ctl_rule_remove_target_by_tag.cc +++ b/src/actions/ctl/rule_remove_target_by_tag.cc @@ -13,7 +13,7 @@ * */ -#include "actions/ctl_rule_remove_target_by_tag.h" +#include "actions/ctl/rule_remove_target_by_tag.h" #include #include @@ -23,8 +23,10 @@ namespace modsecurity { namespace actions { +namespace ctl { -bool CtlRuleRemoveTargetByTag::init(std::string *error) { + +bool RuleRemoveTargetByTag::init(std::string *error) { std::string what(m_parser_payload, 22, m_parser_payload.size() - 22); std::vector param = split(what, ';'); @@ -39,11 +41,13 @@ bool CtlRuleRemoveTargetByTag::init(std::string *error) { return true; } -bool CtlRuleRemoveTargetByTag::evaluate(Rule *rule, Transaction *transaction) { +bool RuleRemoveTargetByTag::evaluate(Rule *rule, Transaction *transaction) { transaction->m_ruleRemoveTargetByTag.push_back( std::make_pair(m_tag, m_target)); return true; } + +} // namespace ctl } // namespace actions } // namespace modsecurity diff --git a/src/actions/ctl_rule_remove_target_by_tag.h b/src/actions/ctl/rule_remove_target_by_tag.h similarity index 88% rename from src/actions/ctl_rule_remove_target_by_tag.h rename to src/actions/ctl/rule_remove_target_by_tag.h index 37397fdf..793fe7e5 100644 --- a/src/actions/ctl_rule_remove_target_by_tag.h +++ b/src/actions/ctl/rule_remove_target_by_tag.h @@ -24,11 +24,12 @@ namespace modsecurity { namespace actions { +namespace ctl { -class CtlRuleRemoveTargetByTag : public Action { +class RuleRemoveTargetByTag : public Action { public: - explicit CtlRuleRemoveTargetByTag(std::string action) + explicit RuleRemoveTargetByTag(std::string action) : Action(action, RunTimeOnlyIfMatchKind) { } bool init(std::string *error) override; @@ -38,6 +39,8 @@ class CtlRuleRemoveTargetByTag : public Action { std::string m_target; }; + +} // namespace ctl } // namespace actions } // namespace modsecurity diff --git a/src/parser/seclang-parser.yy b/src/parser/seclang-parser.yy index 3287bf56..fabd42f4 100644 --- a/src/parser/seclang-parser.yy +++ b/src/parser/seclang-parser.yy @@ -24,13 +24,13 @@ class Driver; #include "actions/action.h" #include "actions/allow.h" #include "actions/audit_log.h" -#include "actions/ctl_audit_log_parts.h" -#include "actions/ctl_request_body_access.h" -#include "actions/ctl_request_body_processor_json.h" -#include "actions/ctl_request_body_processor_xml.h" -#include "actions/ctl_rule_remove_by_id.h" -#include "actions/ctl_rule_remove_target_by_id.h" -#include "actions/ctl_rule_remove_target_by_tag.h" +#include "actions/ctl/audit_log_parts.h" +#include "actions/ctl/request_body_access.h" +#include "actions/ctl/request_body_processor_json.h" +#include "actions/ctl/request_body_processor_xml.h" +#include "actions/ctl/rule_remove_by_id.h" +#include "actions/ctl/rule_remove_target_by_id.h" +#include "actions/ctl/rule_remove_target_by_tag.h" #include "actions/init_col.h" #include "actions/log_data.h" #include "actions/maturity.h" @@ -102,9 +102,9 @@ using modsecurity::Variables::XML; using modsecurity::actions::Accuracy; using modsecurity::actions::Action; using modsecurity::actions::Allow; -using modsecurity::actions::CtlAuditLogParts; -using modsecurity::actions::CtlRequestBodyProcessorJSON; -using modsecurity::actions::CtlRequestBodyProcessorXML; +using modsecurity::actions::ctl::AuditLogParts; +using modsecurity::actions::ctl::RequestBodyProcessorJSON; +using modsecurity::actions::ctl::RequestBodyProcessorXML; using modsecurity::actions::InitCol; using modsecurity::actions::LogData; using modsecurity::actions::Maturity; @@ -1200,16 +1200,16 @@ act: } | ACTION_CTL_BDY_XML { - $$ = new modsecurity::actions::CtlRequestBodyProcessorXML($1); + $$ = new modsecurity::actions::ctl::RequestBodyProcessorXML($1); } | ACTION_CTL_BDY_JSON { - $$ = new modsecurity::actions::CtlRequestBodyProcessorJSON($1); + $$ = new modsecurity::actions::ctl::RequestBodyProcessorJSON($1); } | ACTION_CTL_RULE_REMOVE_TARGET_BY_TAG { std::string error; - $$ = new modsecurity::actions::CtlRuleRemoveTargetByTag($1); + $$ = new modsecurity::actions::ctl::RuleRemoveTargetByTag($1); if ($$->init(&error) == false) { driver.error(@0, error); YYERROR; @@ -1218,7 +1218,7 @@ act: | ACTION_CTL_RULE_REMOVE_TARGET_BY_ID { std::string error; - $$ = new modsecurity::actions::CtlRuleRemoveTargetById($1); + $$ = new modsecurity::actions::ctl::RuleRemoveTargetById($1); if ($$->init(&error) == false) { driver.error(@0, error); YYERROR; @@ -1227,7 +1227,7 @@ act: | ACTION_CTL_RULE_REMOVE_BY_ID { std::string error; - $$ = new modsecurity::actions::CtlRuleRemoveById($1); + $$ = new modsecurity::actions::ctl::RuleRemoveById($1); if ($$->init(&error) == false) { driver.error(@0, error); YYERROR; @@ -1236,7 +1236,7 @@ act: | ACTION_CTL_AUDIT_LOG_PARTS { std::string error; - $$ = new CtlAuditLogParts($1); + $$ = new AuditLogParts($1); if ($$->init(&error) == false) { driver.error(@0, error); YYERROR; @@ -1245,7 +1245,7 @@ act: | ACTION_CTL_REQUEST_BODY_ACCESS CONFIG_VALUE_ON { std::string error; - $$ = new modsecurity::actions::CtlRequestBodyAccess($1 + "true"); + $$ = new modsecurity::actions::ctl::RequestBodyAccess($1 + "true"); if ($$->init(&error) == false) { driver.error(@0, error); YYERROR; @@ -1254,7 +1254,7 @@ act: | ACTION_CTL_REQUEST_BODY_ACCESS CONFIG_VALUE_OFF { std::string error; - $$ = new modsecurity::actions::CtlRequestBodyAccess($1 + "false"); + $$ = new modsecurity::actions::ctl::RequestBodyAccess($1 + "false"); if ($$->init(&error) == false) { driver.error(@0, error); YYERROR;