Skip to content

Commit 62d35fb

Browse files
committed
Adds support to config warnings
1 parent bf87f11 commit 62d35fb

File tree

17 files changed

+1158
-900
lines changed

17 files changed

+1158
-900
lines changed

Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ TESTS+=test/test-cases/regression/config-body_limits.json
127127
TESTS+=test/test-cases/regression/config-calling_phases_by_name.json
128128
TESTS+=test/test-cases/regression/config-include-bad.json
129129
TESTS+=test/test-cases/regression/config-include.json
130+
TESTS+=test/test-cases/regression/config-warning.json
130131
TESTS+=test/test-cases/regression/config-remove_by_id.json
131132
TESTS+=test/test-cases/regression/config-remove_by_msg.json
132133
TESTS+=test/test-cases/regression/config-remove_by_tag.json

examples/multiprocess_c/multi.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ int main (int argc, char **argv)
9797
{
9898
int ret;
9999
const char *error = NULL;
100+
const char *warn = NULL;
100101
int i = 0;
101102
pid_t pid;
102103
int f;
@@ -108,7 +109,7 @@ int main (int argc, char **argv)
108109

109110
rules = msc_create_rules_set();
110111

111-
ret = msc_rules_add_file(rules, main_rule_uri, &error);
112+
ret = msc_rules_add_file(rules, main_rule_uri, &warn, &error);
112113
if (ret < 0) {
113114
fprintf(stderr, "Problems loading the rules --\n");
114115
fprintf(stderr, "%s\n", error);

examples/simple_example_using_c/test.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ int main (int argc, char **argv)
2727
{
2828
int ret;
2929
const char *error = NULL;
30+
const char *warn = NULL;
3031
ModSecurity *modsec;
3132
Transaction *transaction = NULL;
3233
RulesSet *rules;
@@ -38,7 +39,7 @@ int main (int argc, char **argv)
3839

3940
rules = msc_create_rules_set();
4041

41-
ret = msc_rules_add_file(rules, main_rule_uri, &error);
42+
ret = msc_rules_add_file(rules, main_rule_uri, &warn, &error);
4243
if (ret < 0) {
4344
fprintf(stderr, "Problems loading the rules --\n");
4445
fprintf(stderr, "%s\n", error);
@@ -48,7 +49,7 @@ int main (int argc, char **argv)
4849

4950
ret = msc_rules_add_remote(rules, "test",
5051
"https://www.modsecurity.org/modsecurity-regression-test-secremoterules.txt",
51-
&error);
52+
&warn, &error);
5253
if (ret < 0) {
5354
fprintf(stderr, "Problems loading the rules --\n");
5455
fprintf(stderr, "%s\n", error);

headers/modsecurity/actions/action.h

+13
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,19 @@ class Action {
120120
}
121121
};
122122

123+
class ActionNotSupported : public Action {
124+
public:
125+
ActionNotSupported() : Action()
126+
{ };
127+
128+
explicit ActionNotSupported(const std::string& action)
129+
: Action(action)
130+
{ };
131+
132+
ActionNotSupported(const ActionNotSupported &other) = delete;
133+
ActionNotSupported &operator=(const ActionNotSupported& a) = delete;
134+
};
135+
123136

124137
} // namespace actions
125138
} // namespace modsecurity

headers/modsecurity/rules_set.h

+8-4
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class RulesSet : public RulesSetProperties {
7575
int evaluate(int phase, Transaction *transaction);
7676

7777
std::string getParserError();
78+
std::string getParserWarnings();
7879

7980
void debug(int level, const std::string &id, const std::string &uri,
8081
const std::string &msg);
@@ -95,11 +96,14 @@ extern "C" {
9596

9697
RulesSet *msc_create_rules_set(void);
9798
void msc_rules_dump(RulesSet *rules);
98-
int msc_rules_merge(RulesSet *rules_dst, RulesSet *rules_from, const char **error);
99+
int msc_rules_merge(RulesSet *rules_dst, RulesSet *rules_from,
100+
const char **warn, const char **error);
99101
int msc_rules_add_remote(RulesSet *rules, const char *key, const char *uri,
100-
const char **error);
101-
int msc_rules_add_file(RulesSet *rules, const char *file, const char **error);
102-
int msc_rules_add(RulesSet *rules, const char *plain_rules, const char **error);
102+
const char **warn, const char **error);
103+
int msc_rules_add_file(RulesSet *rules, const char *file,
104+
const char **warn, const char **error);
105+
int msc_rules_add(RulesSet *rules, const char *plain_rules,
106+
const char **warn, const char **error);
103107
int msc_rules_cleanup(RulesSet *rules);
104108

105109
#ifdef __cplusplus

headers/modsecurity/rules_set_properties.h

+1
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ class RulesSetProperties {
457457
RulesExceptions m_exceptions;
458458
std::list<std::string> m_components;
459459
std::ostringstream m_parserError;
460+
std::ostringstream m_parserWarn;
460461
ConfigSet m_responseBodyTypeToBeInspected;
461462
ConfigString m_httpblKey;
462463
ConfigString m_uploadDirectory;

src/parser/driver.cc

+26-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ int Driver::addSecRule(std::unique_ptr<RuleWithActions> r) {
180180
*/
181181
if (rule->getId() == 0) {
182182
m_parserError << "Rules must have an ID. File: ";
183-
m_parserError << rule->getFileName() << " at line: ";
183+
m_parserError << *rule->getFileName() << " at line: ";
184184
m_parserError << std::to_string(rule->getLineNumber()) << std::endl;
185185
return false;
186186
}
@@ -282,5 +282,30 @@ void Driver::error(const yy::location& l, const std::string& m,
282282
}
283283

284284

285+
void Driver::warn(const yy::location& l, const std::string& m) {
286+
warn(l, m, "");
287+
}
288+
289+
290+
void Driver::warn(const yy::location& l, const std::string& m,
291+
const std::string& c) {
292+
if (m_parserWarn.tellp() != 0) {
293+
m_parserWarn << std::endl;
294+
}
295+
m_parserWarn << "Warning. ";
296+
m_parserWarn << "File: " << *l.end.filename << ". ";
297+
m_parserWarn << "Line: " << l.end.line << ". ";
298+
m_parserWarn << "Column: " << l.end.column - 1 << ". ";
299+
300+
if (m.empty() == false) {
301+
m_parserWarn << "" << m << " ";
302+
}
303+
304+
if (c.empty() == false) {
305+
m_parserWarn << c;
306+
}
307+
}
308+
309+
285310
} // namespace Parser
286311
} // namespace modsecurity

src/parser/driver.h

+4
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ class Driver : public RulesSetProperties {
8686
void error(const yy::location& l, const std::string& m,
8787
const std::string& c);
8888

89+
void warn(const yy::location& l, const std::string& m);
90+
void warn(const yy::location& l, const std::string& m,
91+
const std::string& c);
92+
8993
std::list<yy::location *> loc;
9094

9195
std::string buffer;

0 commit comments

Comments
 (0)