Adds support to setrsc action

This commit is contained in:
Felipe Zimmerle
2017-06-09 10:47:24 -03:00
parent 616a95bfe0
commit 9cb3f23b50
10 changed files with 4568 additions and 4279 deletions

58
src/actions/set_rsc.cc Normal file
View File

@@ -0,0 +1,58 @@
/*
* 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 "src/actions/set_rsc.h"
#include <iostream>
#include <string>
#include "modsecurity/transaction.h"
#include "modsecurity/rule.h"
#include "src/macro_expansion.h"
namespace modsecurity {
namespace actions {
bool SetRSC::init(std::string *error) {
m_collection_key = std::string(m_parser_payload, 0,
m_parser_payload.length());
if (m_collection_key.empty()) {
error->assign("Missing collection key");
return false;
}
return true;
}
bool SetRSC::evaluate(Rule *rule, Transaction *t) {
std::string colNameExpanded = MacroExpansion::expand(m_collection_key, t);
#ifndef NO_LOGS
t->debug(8, "RESOURCE initiated with value: \'"
+ colNameExpanded + "\'.");
#endif
t->m_collections.m_resource_collection_key = colNameExpanded;
t->m_variableResource.set(colNameExpanded, t->m_variableOffset);
return true;
}
} // namespace actions
} // namespace modsecurity

46
src/actions/set_rsc.h Normal file
View File

@@ -0,0 +1,46 @@
/*
* 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 <string>
#include "modsecurity/actions/action.h"
#ifndef SRC_ACTIONS_SET_RSC_H_
#define SRC_ACTIONS_SET_RSC_H_
class Transaction;
namespace modsecurity {
class Transaction;
namespace actions {
class SetRSC : public Action {
public:
explicit SetRSC(std::string _action)
: Action(_action) { }
bool evaluate(Rule *rule, Transaction *transaction) override;
bool init(std::string *error) override;
private:
std::string m_collection_key;
};
} // namespace actions
} // namespace modsecurity
#endif // SRC_ACTIONS_SET_RSC_H_