Skip to content

Commit 3a048ee

Browse files
michaelgranzow-aviFelipe Zimmerle
authored and
Felipe Zimmerle
committed
Support --enable-debug-logs=no option of configure script (#2)
* Support --enable-debug-logs=no option of configure script * Undo unintended white space changes * Undo more unintended white space changes * Address review comments - thanks Mirko * Address more review comments - thanks Mirko
1 parent 1d3c4c6 commit 3a048ee

22 files changed

+305
-4
lines changed

src/actions/ctl/rule_engine.cc

+2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ bool RuleEngine::evaluate(Rule *rule, Transaction *transaction) {
5050
a << modsecurity::RulesProperties::ruleEngineStateString(m_ruleEngine);
5151
a << " as requested by a ctl:ruleEngine action";
5252

53+
#ifndef NO_LOGS
5354
transaction->debug(8, a.str());
55+
#endif
5456

5557
transaction->m_secRuleEngine = m_ruleEngine;
5658
return true;

src/actions/disruptive/allow.cc

+2
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ bool Allow::init(std::string *error) {
4949

5050

5151
bool Allow::evaluate(Rule *rule, Transaction *transaction) {
52+
#ifndef NO_LOGS
5253
transaction->debug(4, "Dropping the evaluation of upcoming rules " \
5354
"in favor of an `allow' action of type: " \
5455
+ allowTypeToName(m_allowType));
56+
#endif
5557

5658
transaction->m_allowType = m_allowType;
5759

src/actions/disruptive/block.cc

+2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ namespace disruptive {
3232

3333
bool Block::evaluate(Rule *rule, Transaction *transaction,
3434
std::shared_ptr<RuleMessage> rm) {
35+
#ifndef NO_LOGS
3536
transaction->debug(8, "Marking request as disruptive.");
37+
#endif
3638

3739
for (Action *a : transaction->m_rules->m_defaultActions[rule->m_phase]) {
3840
if (a->isDisruptive() == false) {

src/actions/disruptive/pass.cc

+2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ bool Pass::evaluate(Rule *rule, Transaction *transaction,
3333
intervention::free(&transaction->m_it);
3434
intervention::reset(&transaction->m_it);
3535

36+
#ifndef NO_LOGS
3637
transaction->debug(8, "Running action pass");
38+
#endif
3739

3840
return true;
3941
}

src/actions/init_col.cc

+2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ bool InitCol::evaluate(Rule *rule, Transaction *t) {
7171
return false;
7272
}
7373

74+
#ifndef NO_LOGS
7475
t->debug(5, "Collection `" + m_collection_key + "' initialized with " \
7576
"value: " + collectionName);
77+
#endif
7678

7779
return true;
7880
}

src/actions/log.cc

+2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ namespace actions {
3030

3131
bool Log::evaluate(Rule *rule, Transaction *transaction,
3232
std::shared_ptr<RuleMessage> rm) {
33+
#ifndef NO_LOGS
3334
transaction->debug(9, "Saving transaction to logs");
35+
#endif
3436
rm->m_saveMessage = true;
3537
return true;
3638
}

src/actions/msg.cc

+2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ bool Msg::evaluate(Rule *rule, Transaction *transaction,
5151
std::shared_ptr<RuleMessage> rm) {
5252
std::string msg = data(transaction);
5353
rm->m_message = msg;
54+
#ifndef NO_LOGS
5455
transaction->debug(9, "Saving msg: " + msg);
56+
#endif
5557

5658
transaction->m_collections.storeOrUpdateFirst("RULE:msg", msg);
5759

src/audit_log/audit_log.cc

+8
Original file line numberDiff line numberDiff line change
@@ -282,26 +282,34 @@ bool AuditLog::saveIfRelevant(Transaction *transaction, int parts) {
282282
if ((m_status == RelevantOnlyAuditLogStatus
283283
&& this->isRelevant(transaction->m_httpCodeReturned) == false)
284284
&& saveAnyway == false) {
285+
#ifndef NO_LOGS
285286
transaction->debug(9, "Return code `" +
286287
std::to_string(transaction->m_httpCodeReturned) + "'" \
287288
" is not interesting to audit logs, relevant code(s): `" +
288289
m_relevant + "'.");
290+
#endif
289291

290292
return false;
291293
}
292294

293295
if (parts == -1) {
294296
parts = m_parts;
295297
}
298+
#ifndef NO_LOGS
296299
transaction->debug(5, "Saving this request as part " \
297300
"of the audit logs.");
301+
#endif
298302
if (m_writer == NULL) {
303+
#ifndef NO_LOGS
299304
transaction->debug(1, "Internal error, audit log writer is null");
305+
#endif
300306
} else {
301307
std::string error;
302308
bool a = m_writer->write(transaction, parts, &error);
303309
if (a == false) {
310+
#ifndef NO_LOGS
304311
transaction->debug(1, "Cannot save the audit log: " + error);
312+
#endif
305313
return false;
306314
}
307315
}

src/audit_log/writer/https.cc

+2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ bool Https::init(std::string *error) {
4747

4848
bool Https::write(Transaction *transaction, int parts, std::string *error) {
4949
Utils::HttpsClient m_http_client;
50+
#ifndef NO_LOGS
5051
transaction->debug(7, "Sending logs to: " + m_audit->m_path1);
52+
#endif
5153

5254
std::string log = transaction->toJSON(parts);
5355
m_http_client.setRequestType("application/json");

src/macro_expansion.cc

+2
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,14 @@ std::string MacroExpansion::expand(const std::string& input,
301301
}
302302
}
303303

304+
#ifndef NO_LOGS
304305
if (variableValue) {
305306
transaction->debug(6, "Resolving: " + variable + " to: " +
306307
*variableValue);
307308
} else {
308309
transaction->debug(6, "Resolving: " + variable + " to: NULL");
309310
}
311+
#endif
310312
res.erase(start, end - start + 1);
311313
if (res[start] == '%') {
312314
res.erase(start, 1);

src/operators/pm.cc

+2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,10 @@ bool Pm::evaluate(Transaction *transaction, Rule *rule,
9999
if (capture && transaction && rc) {
100100
transaction->m_collections.storeOrUpdateFirst("TX", "0",
101101
std::string(match));
102+
#ifndef NO_LOGS
102103
transaction->debug(7, "Added pm match TX.0: " + \
103104
std::string(match));
105+
#endif
104106
}
105107

106108
return rc > 0;

src/operators/rx.cc

+2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ bool Rx::evaluate(Transaction *transaction, Rule *rule,
4545
for (const SMatch& a : matches) {
4646
transaction->m_collections.storeOrUpdateFirst("TX",
4747
std::to_string(i), a.match);
48+
#ifndef NO_LOGS
4849
transaction->debug(7, "Added regex subexpression TX." +
4950
std::to_string(i) + ": " + a.match);
51+
#endif
5052
transaction->m_matched.push_back(a.match);
5153
i++;
5254
}

src/operators/validate_dtd.cc

+12
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,25 @@ bool ValidateDTD::evaluate(Transaction *t, const std::string &str) {
5050
if (m_dtd == NULL) {
5151
std::string err = std::string("XML: Failed to load DTD: ") \
5252
+ m_resource;
53+
#ifndef NO_LOGS
5354
t->debug(4, err);
55+
#endif
5456
return true;
5557
}
5658

5759
if (t->m_xml->m_data.doc == NULL) {
60+
#ifndef NO_LOGS
5861
t->debug(4, "XML document tree could not "\
5962
"be found for DTD validation.");
63+
#endif
6064
return true;
6165
}
6266

6367
if (t->m_xml->m_data.well_formed != 1) {
68+
#ifndef NO_LOGS
6469
t->debug(4, "XML: DTD validation failed because " \
6570
"content is not well formed.");
71+
#endif
6672
return true;
6773
}
6874

@@ -78,7 +84,9 @@ bool ValidateDTD::evaluate(Transaction *t, const std::string &str) {
7884

7985
cvp = xmlNewValidCtxt();
8086
if (cvp == NULL) {
87+
#ifndef NO_LOGS
8188
t->debug(4, "XML: Failed to create a validation context.");
89+
#endif
8290
return true;
8391
}
8492

@@ -88,13 +96,17 @@ bool ValidateDTD::evaluate(Transaction *t, const std::string &str) {
8896
cvp->userData = t;
8997

9098
if (!xmlValidateDtd(cvp, t->m_xml->m_data.doc, m_dtd)) {
99+
#ifndef NO_LOGS
91100
t->debug(4, "XML: DTD validation failed.");
101+
#endif
92102
xmlFreeValidCtxt(cvp);
93103
return true;
94104
}
95105

106+
#ifndef NO_LOGS
96107
t->debug(4, std::string("XML: Successfully validated " \
97108
"payload against DTD: ") + m_resource);
109+
#endif
98110

99111
xmlFreeValidCtxt(cvp);
100112

src/operators/validate_dtd.h

+4
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ class ValidateDTD : public Operator {
6262
if (len > 0) {
6363
s = "XML Error: " + std::string(buf);
6464
}
65+
#ifndef NO_LOGS
6566
t->debug(4, s);
67+
#endif
6668
}
6769

6870

@@ -79,7 +81,9 @@ class ValidateDTD : public Operator {
7981
if (len > 0) {
8082
s = "XML Warning: " + std::string(buf);
8183
}
84+
#ifndef NO_LOGS
8285
t->debug(4, s);
86+
#endif
8387
}
8488

8589

src/operators/validate_schema.cc

+17-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ bool ValidateSchema::evaluate(Transaction *t,
5050
if (m_err.empty() == false) {
5151
err << m_err;
5252
}
53+
#ifndef NO_LOGS
5354
t->debug(4, err.str());
55+
#endif
5456
return true;
5557
}
5658

@@ -73,7 +75,9 @@ bool ValidateSchema::evaluate(Transaction *t,
7375
if (m_err.empty() == false) {
7476
err << " " << m_err;
7577
}
78+
#ifndef NO_LOGS
7679
t->debug(4, err.str());
80+
#endif
7781
xmlSchemaFreeParserCtxt(m_parserCtx);
7882
return true;
7983
}
@@ -84,7 +88,9 @@ bool ValidateSchema::evaluate(Transaction *t,
8488
if (m_err.empty() == false) {
8589
err << " " << m_err;
8690
}
91+
#ifndef NO_LOGS
8792
t->debug(4, err.str());
93+
#endif
8894
return true;
8995
}
9096

@@ -94,36 +100,46 @@ bool ValidateSchema::evaluate(Transaction *t,
94100
(xmlSchemaValidityWarningFunc)warn_runtime, t);
95101

96102
if (t->m_xml->m_data.doc == NULL) {
103+
#ifndef NO_LOGS
97104
t->debug(4, "XML document tree could not be found for " \
98105
"schema validation.");
106+
#endif
99107
return true;
100108
}
101109

102110
if (t->m_xml->m_data.well_formed != 1) {
111+
#ifndef NO_LOGS
103112
t->debug(4, "XML: Schema validation failed because " \
104113
"content is not well formed.");
114+
#endif
105115
return true;
106116
}
107117

108118
/* Make sure there were no other generic processing errors */
109119
/*
110120
if (msr->msc_reqbody_error) {
121+
#ifndef NO_LOGS
111122
t->debug(4, "XML: Schema validation could not proceed due to previous"
112123
" processing errors.");
124+
#endif
113125
return true;
114126
}
115127
*/
116128

117129
rc = xmlSchemaValidateDoc(m_validCtx, t->m_xml->m_data.doc);
118130
if (rc != 0) {
119-
t->debug(4, "XML: Schema validation failed.");
131+
#ifndef NO_LOGS
132+
t->debug(4, "XML: Schema validation failed.");
133+
#endif
120134
xmlSchemaFree(m_schema);
121135
xmlSchemaFreeParserCtxt(m_parserCtx);
122136
return true; /* No match. */
123137
}
124138

139+
#ifndef NO_LOGS
125140
t->debug(4, "XML: Successfully validated payload against " \
126141
"Schema: " + m_resource);
142+
#endif
127143

128144
return false;
129145
}

src/operators/validate_schema.h

+4
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ class ValidateSchema : public Operator {
103103
if (len > 0) {
104104
s = "XML Error: " + std::string(buf);
105105
}
106+
#ifndef NO_LOGS
106107
t->debug(4, s);
108+
#endif
107109
}
108110

109111

@@ -120,7 +122,9 @@ class ValidateSchema : public Operator {
120122
if (len > 0) {
121123
s = "XML Warning: " + std::string(buf);
122124
}
125+
#ifndef NO_LOGS
123126
t->debug(4, s);
127+
#endif
124128
}
125129

126130
static void null_error(void *ctx, const char *msg, ...) {

src/request_body_processor/json.cc

+12
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ int JSON::yajl_map_key(void *ctx, const unsigned char *key, size_t length) {
4848
*/
4949
safe_key.assign((const char *)key, length);
5050

51+
#ifndef NO_LOGS
5152
tthis->debug(9, "New JSON hash key '" + safe_key + "'");
53+
#endif
5254

5355
/**
5456
* TODO: How do we free the previously string value stored here?
@@ -128,8 +130,10 @@ int JSON::yajl_start_map(void *ctx) {
128130
tthis->m_data.prefix.assign(tthis->m_data.current_key);
129131
}
130132

133+
#ifndef NO_LOGS
131134
tthis->debug(9, "New JSON hash context (prefix '" + \
132135
tthis->m_data.prefix + "')");
136+
#endif
133137

134138
return 1;
135139
}
@@ -176,7 +180,9 @@ int JSON::addArgument(const std::string& value) {
176180
* to reference this argument; for now we simply ignore these
177181
*/
178182
if (m_data.current_key.empty()) {
183+
#ifndef NO_LOGS
179184
debug(3, "Cannot add scalar value without an associated key");
185+
#endif
180186
return 1;
181187
}
182188

@@ -245,7 +251,9 @@ JSON::JSON(Transaction *transaction) : m_transaction(transaction) {
245251
};
246252

247253

254+
#ifndef NO_LOGS
248255
debug(9, "JSON parser initialization");
256+
#endif
249257

250258
/**
251259
* Prefix and current key are initially empty
@@ -261,15 +269,19 @@ JSON::JSON(Transaction *transaction) : m_transaction(transaction) {
261269
*
262270
* TODO: make UTF8 validation optional, as it depends on Content-Encoding
263271
*/
272+
#ifndef NO_LOGS
264273
debug(9, "yajl JSON parsing callback initialization");
274+
#endif
265275
m_data.handle = yajl_alloc(&callbacks, NULL, this);
266276

267277
yajl_config(m_data.handle, yajl_allow_partial_values, 0);
268278
}
269279

270280

271281
JSON::~JSON() {
282+
#ifndef NO_LOGS
272283
debug(9, "JSON: Cleaning up JSON results");
284+
#endif
273285
yajl_free(m_data.handle);
274286
}
275287

0 commit comments

Comments
 (0)