fixed compilation error with disable_debug_log flag

This commit is contained in:
Izik Abramov 2017-12-05 15:35:26 +02:00 committed by Felipe Zimmerle
parent cb182b0dc5
commit cb8d0b068d
5 changed files with 32 additions and 4 deletions

View File

@ -50,8 +50,9 @@ bool Exec::init(std::string *error) {
bool Exec::evaluate(Rule *rule, Transaction *t) { bool Exec::evaluate(Rule *rule, Transaction *t) {
#ifndef NO_LOGS
t->debug(8, "Running script... " + m_script); t->debug(8, "Running script... " + m_script);
#endif
m_lua.run(t); m_lua.run(t);
return true; return true;
} }

View File

@ -274,7 +274,9 @@ bool AuditLog::saveIfRelevant(Transaction *transaction) {
bool AuditLog::saveIfRelevant(Transaction *transaction, int parts) { bool AuditLog::saveIfRelevant(Transaction *transaction, int parts) {
bool saveAnyway = false; bool saveAnyway = false;
if (m_status == OffAuditLogStatus || m_status == NotSetLogStatus) { if (m_status == OffAuditLogStatus || m_status == NotSetLogStatus) {
#ifndef NO_LOGS
transaction->debug(5, "Audit log engine was not set."); transaction->debug(5, "Audit log engine was not set.");
#endif
return true; return true;
} }

View File

@ -153,7 +153,9 @@ int Lua::run(Transaction *t) {
break; break;
} }
e.append(lua_tostring(L, -1)); e.append(lua_tostring(L, -1));
#ifndef NO_LOGS
t->debug(2, e); t->debug(2, e);
#endif
ret = false; ret = false;
goto err; goto err;
} }
@ -167,7 +169,9 @@ int Lua::run(Transaction *t) {
e.append(" - "); e.append(" - ");
e.append(luaerr); e.append(luaerr);
} }
#ifndef NO_LOGS
t->debug(2, e); t->debug(2, e);
#endif
ret = false; ret = false;
goto err; goto err;
} }
@ -183,7 +187,9 @@ int Lua::run(Transaction *t) {
e.append(" - "); e.append(" - ");
e.append(luaerr); e.append(luaerr);
} }
#ifndef NO_LOGS
t->debug(2, e); t->debug(2, e);
#endif
ret = false; ret = false;
goto err; goto err;
} }
@ -192,8 +198,9 @@ int Lua::run(Transaction *t) {
if (a != NULL) { if (a != NULL) {
luaRet.assign(a); luaRet.assign(a);
} }
#ifndef NO_LOGS
t->debug(9, "Returning from lua script: " + luaRet); t->debug(9, "Returning from lua script: " + luaRet);
#endif
if (luaRet.size() == 0) { if (luaRet.size() == 0) {
ret = false; ret = false;
@ -206,7 +213,9 @@ err:
return ret; return ret;
#else #else
#ifndef NO_LOGS
t->debug(9, "Lua support was not enabled."); t->debug(9, "Lua support was not enabled.");
#endif
return false; return false;
#endif #endif
} }
@ -228,7 +237,9 @@ int Lua::log(lua_State *L) {
/* Log message. */ /* Log message. */
if (t != NULL) { if (t != NULL) {
#ifndef NO_LOGS
t->debug(level, text); t->debug(level, text);
#endif
} }
return 0; return 0;
@ -320,7 +331,9 @@ int Lua::setvar(lua_State *L) {
if (nargs != 2) { if (nargs != 2) {
#ifndef NO_LOGS
t->debug(8, "m.setvar: Failed m.setvar funtion must has 2 arguments"); t->debug(8, "m.setvar: Failed m.setvar funtion must has 2 arguments");
#endif
return -1; return -1;
} }
var_value = luaL_checkstring(L, 2); var_value = luaL_checkstring(L, 2);
@ -341,8 +354,10 @@ int Lua::setvar(lua_State *L) {
std::string::npos); std::string::npos);
} else { } else {
#ifndef NO_LOGS
t->debug(8, "m.setvar: Must specify a collection using dot character" \ t->debug(8, "m.setvar: Must specify a collection using dot character" \
" - ie m.setvar(tx.myvar,mydata)"); " - ie m.setvar(tx.myvar,mydata)");
#endif
return -1; return -1;
} }
@ -380,8 +395,10 @@ std::string Lua::applyTransformations(lua_State *L, Transaction *t,
if (tfn) { if (tfn) {
newVar = tfn->evaluate(newVar, t); newVar = tfn->evaluate(newVar, t);
} else { } else {
#ifndef NO_LOGS
t->debug(1, "SecRuleScript: Invalid transformation function: " \ t->debug(1, "SecRuleScript: Invalid transformation function: " \
+ std::string(name)); + std::string(name));
#endif
} }
delete tfn; delete tfn;
} }
@ -402,17 +419,19 @@ std::string Lua::applyTransformations(lua_State *L, Transaction *t,
newVar = tfn->evaluate(newVar, t); newVar = tfn->evaluate(newVar, t);
delete tfn; delete tfn;
} else { } else {
#ifndef NO_LOGS
t->debug(1, "SecRuleScript: Invalid transformation function: " \ t->debug(1, "SecRuleScript: Invalid transformation function: " \
+ std::string(name)); + std::string(name));
#endif
} }
return newVar; return newVar;
} }
#ifndef NO_LOGS
t->debug(8, "SecRuleScript: Transformation parameter must be a " \ t->debug(8, "SecRuleScript: Transformation parameter must be a " \
"transformation name or array of transformation names, but found " \ "transformation name or array of transformation names, but found " \
"" + std::string(lua_typename(L, idx)) + " (type " \ "" + std::string(lua_typename(L, idx)) + " (type " \
+ std::to_string(lua_type(L, idx)) + ")"); + std::to_string(lua_type(L, idx)) + ")");
#endif
return newVar; return newVar;
} }
#endif #endif

View File

@ -104,15 +104,19 @@ bool FuzzyHash::evaluate(Transaction *t, const std::string &str) {
if (fuzzy_hash_buf((const unsigned char*)str.c_str(), if (fuzzy_hash_buf((const unsigned char*)str.c_str(),
str.size(), result)) { str.size(), result)) {
#ifndef NO_LOGS
t->debug(4, "Problems generating fuzzy hash"); t->debug(4, "Problems generating fuzzy hash");
#endif
return false; return false;
} }
while (chunk != NULL) { while (chunk != NULL) {
int i = fuzzy_compare(chunk->data, result); int i = fuzzy_compare(chunk->data, result);
if (i >= m_threshold) { if (i >= m_threshold) {
#ifndef NO_LOGS
t->debug(4, "Fuzzy hash: matched " \ t->debug(4, "Fuzzy hash: matched " \
"with score: " + std::to_string(i) + "."); "with score: " + std::to_string(i) + ".");
#endif
return true; return true;
} }
chunk = chunk->next; chunk = chunk->next;

View File

@ -24,7 +24,9 @@ bool RuleScript::init(std::string *err) {
bool RuleScript::evaluate(Transaction *trans, bool RuleScript::evaluate(Transaction *trans,
std::shared_ptr<RuleMessage> ruleMessage) { std::shared_ptr<RuleMessage> ruleMessage) {
#ifndef NO_LOGS
trans->debug(4, " Executing script: " + m_name + "."); trans->debug(4, " Executing script: " + m_name + ".");
#endif
bool containsDisruptive = false; bool containsDisruptive = false;
if (ruleMessage == NULL) { if (ruleMessage == NULL) {