Changes debuglogs schema to avoid unecessary str allocation

This commit is contained in:
Felipe Zimmerle
2018-10-19 16:56:33 -03:00
parent 23e0d35d2d
commit ef7f65db90
57 changed files with 1100 additions and 1374 deletions

View File

@@ -31,9 +31,7 @@ namespace actions {
bool Block::evaluate(Rule *rule, Transaction *transaction,
std::shared_ptr<RuleMessage> rm) {
#ifndef NO_LOGS
transaction->debug(8, "Marking request as disruptive.");
#endif
ms_dbg_a(transaction, 8, "Marking request as disruptive.");
for (Action *a : transaction->m_rules->m_defaultActions[rule->m_phase]) {
if (a->isDisruptive() == false) {

View File

@@ -19,6 +19,7 @@
#include <string>
#include "modsecurity/rules_properties.h"
#include "modsecurity/rules.h"
#include "modsecurity/transaction.h"
namespace modsecurity {
@@ -50,9 +51,7 @@ bool RuleEngine::evaluate(Rule *rule, Transaction *transaction) {
a << modsecurity::RulesProperties::ruleEngineStateString(m_ruleEngine);
a << " as requested by a ctl:ruleEngine action";
#ifndef NO_LOGS
transaction->debug(8, a.str());
#endif
ms_dbg_a(transaction, 8, a.str());
transaction->m_secRuleEngine = m_ruleEngine;
return true;

View File

@@ -20,6 +20,7 @@
#include "modsecurity/transaction.h"
#include "modsecurity/rule.h"
#include "modsecurity/rules.h"
#include "src/utils/string.h"
#include "modsecurity/modsecurity.h"
@@ -49,11 +50,9 @@ bool Allow::init(std::string *error) {
bool Allow::evaluate(Rule *rule, Transaction *transaction) {
#ifndef NO_LOGS
transaction->debug(4, "Dropping the evaluation of upcoming rules " \
ms_dbg_a(transaction, 4, "Dropping the evaluation of upcoming rules " \
"in favor of an `allow' action of type: " \
+ allowTypeToName(m_allowType));
#endif
transaction->m_allowType = m_allowType;

View File

@@ -30,9 +30,7 @@ namespace disruptive {
bool Deny::evaluate(Rule *rule, Transaction *transaction,
std::shared_ptr<RuleMessage> rm) {
#ifndef NO_LOGS
transaction->debug(8, "Running action deny");
#endif
ms_dbg_a(transaction, 8, "Running action deny");
if (transaction->m_it.status == 200) {
transaction->m_it.status = 403;

View File

@@ -18,6 +18,7 @@
#include "modsecurity/actions/action.h"
#include "modsecurity/transaction.h"
#include "modsecurity/rules.h"
#include "modsecurity/rule_message.h"
#ifndef SRC_ACTIONS_DISRUPTIVE_DENY_H_

View File

@@ -21,6 +21,7 @@
#include "modsecurity/transaction.h"
#include "modsecurity/rule.h"
#include "modsecurity/rules.h"
#include "modsecurity/rule_message.h"
namespace modsecurity {
@@ -33,9 +34,7 @@ bool Pass::evaluate(Rule *rule, Transaction *transaction,
intervention::free(&transaction->m_it);
intervention::reset(&transaction->m_it);
#ifndef NO_LOGS
transaction->debug(8, "Running action pass");
#endif
ms_dbg_a(transaction, 8, "Running action pass");
return true;
}

View File

@@ -21,6 +21,7 @@
#include "modsecurity/actions/action.h"
#include "modsecurity/transaction.h"
#include "modsecurity/rule.h"
#include "modsecurity/rules.h"
#include "src/utils/system.h"
#include "src/engine/lua.h"
@@ -49,9 +50,7 @@ bool Exec::init(std::string *error) {
bool Exec::evaluate(Rule *rule, Transaction *t) {
#ifndef NO_LOGS
t->debug(8, "Running script... " + m_script);
#endif
ms_dbg_a(t, 8, "Running script... " + m_script);
m_lua.run(t);
return true;
}

View File

@@ -67,10 +67,8 @@ bool InitCol::evaluate(Rule *rule, Transaction *t) {
return false;
}
#ifndef NO_LOGS
t->debug(5, "Collection `" + m_collection_key + "' initialized with " \
ms_dbg_a(t, 5, "Collection `" + m_collection_key + "' initialized with " \
"value: " + collectionName);
#endif
return true;
}

View File

@@ -30,9 +30,7 @@ namespace actions {
bool Log::evaluate(Rule *rule, Transaction *transaction,
std::shared_ptr<RuleMessage> rm) {
#ifndef NO_LOGS
transaction->debug(9, "Saving transaction to logs");
#endif
ms_dbg_a(transaction, 9, "Saving transaction to logs");
rm->m_saveMessage = true;
return true;
}

View File

@@ -50,9 +50,7 @@ bool Msg::evaluate(Rule *rule, Transaction *transaction,
std::shared_ptr<RuleMessage> rm) {
std::string msg = data(transaction);
rm->m_message = msg;
#ifndef NO_LOGS
transaction->debug(9, "Saving msg: " + msg);
#endif
ms_dbg_a(transaction, 9, "Saving msg: " + msg);
return true;
}

View File

@@ -34,10 +34,8 @@ bool SetENV::init(std::string *error) {
bool SetENV::evaluate(Rule *rule, Transaction *t) {
std::string colNameExpanded(m_string->evaluate(t));
#ifndef NO_LOGS
t->debug(8, "Setting envoriment variable: "
ms_dbg_a(t, 8, "Setting envoriment variable: "
+ colNameExpanded + ".");
#endif
putenv((char *)colNameExpanded.c_str());

View File

@@ -33,11 +33,8 @@ bool SetRSC::init(std::string *error) {
bool SetRSC::evaluate(Rule *rule, Transaction *t) {
std::string colNameExpanded(m_string->evaluate(t));
#ifndef NO_LOGS
t->debug(8, "RESOURCE initiated with value: \'"
ms_dbg_a(t, 8, "RESOURCE initiated with value: \'"
+ colNameExpanded + "\'.");
#endif
t->m_collections.m_resource_collection_key = colNameExpanded;
t->m_variableResource.set(colNameExpanded, t->m_variableOffset);

View File

@@ -33,11 +33,8 @@ bool SetSID::init(std::string *error) {
bool SetSID::evaluate(Rule *rule, Transaction *t) {
std::string colNameExpanded(m_string->evaluate(t));
#ifndef NO_LOGS
t->debug(8, "Session ID initiated with value: \'"
ms_dbg_a(t, 8, "Session ID initiated with value: \'"
+ colNameExpanded + "\'.");
#endif
t->m_collections.m_session_collection_key = colNameExpanded;
t->m_variableSessionID.set(colNameExpanded, t->m_variableOffset);

View File

@@ -33,11 +33,8 @@ bool SetUID::init(std::string *error) {
bool SetUID::evaluate(Rule *rule, Transaction *t) {
std::string colNameExpanded(m_string->evaluate(t));
#ifndef NO_LOGS
t->debug(8, "User collection initiated with value: \'"
ms_dbg_a(t, 8, "User collection initiated with value: \'"
+ colNameExpanded + "\'.");
#endif
t->m_collections.m_user_collection_key = colNameExpanded;
t->m_variableUserID.set(colNameExpanded, t->m_variableOffset);

View File

@@ -133,30 +133,30 @@ bool SetVar::evaluate(Rule *rule, Transaction *t) {
}
}
#ifndef NO_LOGS
t->debug(8, "Saving variable: " + m_variable->m_collectionName \
ms_dbg_a(t, 8, "Saving variable: " + m_variable->m_collectionName \
+ ":" + m_variableNameExpanded + " with value: " + targetValue);
#endif
if (tx) {
tx->storeOrUpdateFirst(t, m_variableNameExpanded, targetValue);
} else if (session) {
session->storeOrUpdateFirst(t, m_variableNameExpanded, targetValue);
} else if (ip) {
ip->storeOrUpdateFirst(t, m_variableNameExpanded, targetValue);
} else if (resource) {
resource->storeOrUpdateFirst(t, m_variableNameExpanded, targetValue);
} else if (global) {
global->storeOrUpdateFirst(t, m_variableNameExpanded, targetValue);
} else if (user) {
user->storeOrUpdateFirst(t, m_variableNameExpanded, targetValue);
} else {
// ?
}
/*
t->m_collections.storeOrUpdateFirst(m_variable->m_collectionName,
m_variableNameExpanded,
t->m_rules->m_secWebAppId.m_value, targetValue);
*/
if (tx) {
tx->storeOrUpdateFirst(t, m_variableNameExpanded, targetValue);
} else if (session) {
session->storeOrUpdateFirst(t, m_variableNameExpanded, targetValue);
} else if (ip) {
ip->storeOrUpdateFirst(t, m_variableNameExpanded, targetValue);
} else if (resource) {
resource->storeOrUpdateFirst(t, m_variableNameExpanded, targetValue);
} else if (global) {
global->storeOrUpdateFirst(t, m_variableNameExpanded, targetValue);
} else if (user) {
user->storeOrUpdateFirst(t, m_variableNameExpanded, targetValue);
} else {
// ?
}
/*
t->m_collections.storeOrUpdateFirst(m_variable->m_collectionName,
m_variableNameExpanded,
t->m_rules->m_secWebAppId.m_value, targetValue);
*/
end:
return true;
}

View File

@@ -22,6 +22,7 @@
#include "modsecurity/actions/action.h"
#include "modsecurity/transaction.h"
#include "modsecurity/rule.h"
#include "modsecurity/rules.h"
#include "src/utils/string.h"
#include "modsecurity/rule_message.h"
@@ -72,11 +73,9 @@ bool Severity::init(std::string *error) {
bool Severity::evaluate(Rule *rule, Transaction *transaction,
std::shared_ptr<RuleMessage> rm) {
#ifndef NO_LOGS
transaction->debug(9, "This rule severity is: " + \
ms_dbg_a(transaction, 9, "This rule severity is: " + \
std::to_string(this->m_severity) + " current transaction is: " + \
std::to_string(transaction->m_highestSeverityAction));
#endif
rm->m_severity = m_severity;

View File

@@ -20,7 +20,7 @@
#include "modsecurity/actions/action.h"
#include "modsecurity/transaction.h"
#include "modsecurity/rules.h"
namespace modsecurity {
namespace actions {
@@ -39,10 +39,9 @@ bool Skip::init(std::string *error) {
bool Skip::evaluate(Rule *rule, Transaction *transaction) {
#ifndef NO_LOGS
transaction->debug(5, "Skipping the next " + std::to_string(m_skip_next) \
+ " rules.");
#endif
ms_dbg_a(transaction, 5, "Skipping the next " + \
std::to_string(m_skip_next) + " rules.");
transaction->m_skip_next = m_skip_next;
return true;

View File

@@ -20,6 +20,7 @@
#include "modsecurity/actions/action.h"
#include "modsecurity/transaction.h"
#include "modsecurity/rules.h"
namespace modsecurity {
@@ -27,9 +28,7 @@ namespace actions {
bool SkipAfter::evaluate(Rule *rule, Transaction *transaction) {
#ifndef NO_LOGS
transaction->debug(5, "Setting skipAfter for: " + m_parser_payload);
#endif
ms_dbg_a(transaction, 5, "Setting skipAfter for: " + m_parser_payload);
transaction->m_marker = m_parser_payload;
return true;
}

View File

@@ -59,10 +59,7 @@ std::string Tag::getName(Transaction *transaction) {
bool Tag::evaluate(Rule *rule, Transaction *transaction,
std::shared_ptr<RuleMessage> rm) {
std::string tag = getName(transaction);
#ifndef NO_LOGS
transaction->debug(9, "Rule tag: " + tag);
#endif
ms_dbg_a(transaction, 9, "Rule tag: " + tag);
rm->m_tags.push_back(tag);