From 721983a05aa53f0c1af7ba15a692c83aeeaad89e Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Mon, 31 Oct 2016 13:16:34 -0300 Subject: [PATCH] Adds missing ctl_request_body.* --- src/actions/ctl_request_body_access.cc | 54 ++++++++++++++++++++++++++ src/actions/ctl_request_body_access.h | 44 +++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 src/actions/ctl_request_body_access.cc create mode 100644 src/actions/ctl_request_body_access.h diff --git a/src/actions/ctl_request_body_access.cc b/src/actions/ctl_request_body_access.cc new file mode 100644 index 00000000..ab467732 --- /dev/null +++ b/src/actions/ctl_request_body_access.cc @@ -0,0 +1,54 @@ +/* + * ModSecurity, http://www.modsecurity.org/ + * Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/) + * + * You may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * If any of the files related to licensing are missing or if you have any + * other questions related to licensing please contact Trustwave Holdings, Inc. + * directly using the email address security@modsecurity.org. + * + */ + +#include "actions/ctl_request_body_access.h" + +#include +#include + +#include "modsecurity/rules_properties.h" +#include "modsecurity/transaction.h" + +namespace modsecurity { +namespace actions { + +bool CtlRequestBodyAccess::init(std::string *error) { + std::string what(m_parser_payload, 18, m_parser_payload.size() - 18); + + if (what == "true") { + m_request_body_access = true; + } else if (what == "false") { + m_request_body_access = false; + } else { + error->assign("Internal error. Expected: true or false, got: " \ + + m_parser_payload); + return false; + } + + return true; +} + +bool CtlRequestBodyAccess::evaluate(Rule *rule, Transaction *transaction) { + if (m_request_body_access) { + transaction->m_requestBodyAccess = RulesProperties::TrueConfigBoolean; + } else { + transaction->m_requestBodyAccess = RulesProperties::FalseConfigBoolean; + } + + return true; +} + +} // namespace actions +} // namespace modsecurity diff --git a/src/actions/ctl_request_body_access.h b/src/actions/ctl_request_body_access.h new file mode 100644 index 00000000..33563693 --- /dev/null +++ b/src/actions/ctl_request_body_access.h @@ -0,0 +1,44 @@ +/* + * ModSecurity, http://www.modsecurity.org/ + * Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/) + * + * You may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * If any of the files related to licensing are missing or if you have any + * other questions related to licensing please contact Trustwave Holdings, Inc. + * directly using the email address security@modsecurity.org. + * + */ + +#include + +#include "actions/action.h" +#include "modsecurity/transaction.h" +#include "src/utils.h" + +#ifndef SRC_ACTIONS_CTL_REQUEST_BODY_ACCESS_H_ +#define SRC_ACTIONS_CTL_REQUEST_BODY_ACCESS_H_ + +namespace modsecurity { +namespace actions { + + +class CtlRequestBodyAccess : public Action { + public: + explicit CtlRequestBodyAccess(std::string action) + : Action(action, RunTimeOnlyIfMatchKind), + m_request_body_access(false) { } + + bool init(std::string *error) override; + bool evaluate(Rule *rule, Transaction *transaction) override; + + bool m_request_body_access; +}; + +} // namespace actions +} // namespace modsecurity + +#endif // SRC_ACTIONS_CTL_REQUEST_BODY_ACCESS_H_