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

@@ -1040,5 +1040,38 @@ std::vector<std::string> expandEnv(const std::string& var, int flags)
}
std::string get_path(const std::string& file) {
size_t found;
found = file.find_last_of("/\\");
if (found > 0) {
return file.substr(0, found);
}
return std::string("");
}
std::string find_resource(const std::string& resource, const std::string& config) {
std::ifstream *iss = NULL;
// Trying absolute or relative to the current dir.
iss = new std::ifstream(resource, std::ios::in);
if (iss->is_open()) {
iss->close();
return resource;
}
// Trying the same path of the configuration file.
std::string f = get_path(config) + "/" + resource;
iss = new std::ifstream(f, std::ios::in);
if (iss->is_open()) {
iss->close();
return f;
}
return std::string("");
}
} // namespace ModSecurity