Looks for external resources in the same path of the rule

This commit is contained in:
Felipe Zimmerle
2015-10-06 09:21:30 -03:00
parent 5cc9e94505
commit e54ef72051
17 changed files with 96 additions and 27 deletions

View File

@@ -23,7 +23,8 @@ namespace ModSecurity {
namespace operators {
bool IpMatchFromFile::init(const char **error) {
bool IpMatchFromFile::init(const std::string &file,
const char **error) {
std::string e("");
bool res = false;

View File

@@ -29,7 +29,7 @@ class IpMatchFromFile : public IpMatch {
IpMatchFromFile(std::string op, std::string param, bool negation)
: IpMatch(op, param, negation) { }
bool init(const char **error) override;
bool init(const std::string& file, const char **error) override;
};
} // namespace operators

View File

@@ -40,7 +40,10 @@ class Operator {
std::string param;
bool negation;
virtual bool init(const char **error) { return true; }
virtual bool init(const std::string &file, const char **error) {
return true;
}
virtual bool evaluate(Assay *assay);
virtual bool evaluate(Assay *assay, const std::string &str);
static Operator *instantiate(std::string op);

View File

@@ -19,12 +19,13 @@
#include "operators/operator.h"
#include "utils/https_client.h"
#include "src/utils.h"
namespace ModSecurity {
namespace operators {
bool PmFromFile::init(const char **error) {
bool PmFromFile::init(const std::string &config, const char **error) {
std::istream *iss;
if (param.compare(0, 8, "https://") == 0) {
@@ -36,7 +37,8 @@ bool PmFromFile::init(const char **error) {
}
iss = new std::stringstream(client.content);
} else {
iss = new std::ifstream(param, std::ios::in);
std::string resource = find_resource(param, config);
iss = new std::ifstream(resource, std::ios::in);
if (((std::ifstream *)iss)->is_open() == false) {
*error = std::string("Failed to open file: " + param).c_str();

View File

@@ -31,7 +31,7 @@ class PmFromFile : public Pm {
PmFromFile(std::string op, std::string param, bool negation)
: Pm(op, param, negation) { }
bool init(const char **error) override;
bool init(const std::string &file, const char **error) override;
};

View File

@@ -30,6 +30,7 @@ bool Rx::evaluate(Assay *assay, const std::string& input) {
SMatch match;
if (regex_search(input, &match, *m_re) && match.size() >= 1) {
std::cout << "wheee" << std::endl;
// this->matched.push_back(match.match);
return true;
}

View File

@@ -83,7 +83,8 @@ bool ValidateByteRange::getRange(const std::string &rangeRepresentation,
}
bool ValidateByteRange::init(const char **error) {
bool ValidateByteRange::init(const std::string &file,
const char **error) {
size_t pos = param.find_first_of(",");
if (pos == std::string::npos) {

View File

@@ -38,7 +38,7 @@ class ValidateByteRange : public Operator {
bool evaluate(Assay *assay, const std::string &input) override;
bool getRange(const std::string &rangeRepresentation, const char **error);
bool init(const char **error) override;
bool init(const std::string& file, const char **error) override;
private:
std::vector<std::string> ranges;
char table[32];