mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-13 13:26:01 +03:00
Makes lua optional
This commit is contained in:
parent
e52bd7d635
commit
7fa5ca9ba0
10
build/lua.m4
10
build/lua.m4
@ -63,8 +63,14 @@ if test -z "${LUA_CFLAGS}"; then
|
||||
fi
|
||||
else
|
||||
if test -z "${LUA_MANDATORY}" || test "x${LUA_MANDATORY}" == "xno"; then
|
||||
LUA_FOUND=2
|
||||
AC_MSG_NOTICE([LUA is disabled by default.])
|
||||
LUA_FOUND=1
|
||||
AC_MSG_NOTICE([using LUA v${LUA_VERSION}])
|
||||
LUA_CFLAGS="-DWITH_LUA ${LUA_CFLAGS}"
|
||||
LUA_DISPLAY="${LUA_LDADD} ${LUA_LDFLAGS}, ${LUA_CFLAGS}"
|
||||
AC_SUBST(LUA_LDFLAGS)
|
||||
AC_SUBST(LUA_LDADD)
|
||||
AC_SUBST(LUA_CFLAGS)
|
||||
AC_SUBST(LUA_DISPLAY)
|
||||
else
|
||||
LUA_FOUND=1
|
||||
AC_MSG_NOTICE([using LUA v${LUA_VERSION}])
|
||||
|
@ -41,6 +41,7 @@ namespace engine {
|
||||
|
||||
|
||||
bool Lua::isCompatible(std::string script, Lua *l, std::string *error) {
|
||||
#ifdef WITH_LUA
|
||||
std::string lua(".lua");
|
||||
std::string err;
|
||||
|
||||
@ -57,10 +58,15 @@ bool Lua::isCompatible(std::string script, Lua *l, std::string *error) {
|
||||
}
|
||||
|
||||
return true;
|
||||
#else
|
||||
error->assign("Lua support was not enabled.");
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool Lua::load(std::string script, std::string *err) {
|
||||
#ifdef WITH_LUA
|
||||
lua_State *L = NULL;
|
||||
L = luaL_newstate();
|
||||
luaL_openlibs(L);
|
||||
@ -93,9 +99,13 @@ bool Lua::load(std::string script, std::string *err) {
|
||||
|
||||
lua_close(L);
|
||||
return true;
|
||||
#else
|
||||
err->assign("Lua support was not enabled.");
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#ifdef WITH_LUA
|
||||
int Lua::blob_keeper(lua_State *L, const void *p, size_t sz, void *ud) {
|
||||
LuaScriptBlob *lsb = static_cast<LuaScriptBlob *>(ud);
|
||||
lsb->write(p, sz);
|
||||
@ -108,9 +118,10 @@ const char *Lua::blob_reader(lua_State *L, void *ud, size_t *size) {
|
||||
const char *data = lsb->read(size);
|
||||
return data;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int Lua::run(Transaction *t) {
|
||||
#ifdef WITH_LUA
|
||||
std::string luaRet;
|
||||
lua_State *L = luaL_newstate();
|
||||
luaL_openlibs(L);
|
||||
@ -188,9 +199,14 @@ int Lua::run(Transaction *t) {
|
||||
}
|
||||
|
||||
return true;
|
||||
#else
|
||||
t->debug(9, "Lua support was not enabled.");
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#ifdef WITH_LUA
|
||||
int Lua::log(lua_State *L) {
|
||||
Transaction *t = NULL;
|
||||
const char *text;
|
||||
@ -371,7 +387,7 @@ std::string Lua::applyTransformations(lua_State *L, Transaction *t, int idx, std
|
||||
|
||||
return newVar;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace engines
|
||||
} // namespace modsecurity
|
||||
|
@ -14,8 +14,8 @@
|
||||
*/
|
||||
|
||||
#ifdef WITH_LUA
|
||||
#endif
|
||||
#include <lua.hpp>
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdint>
|
||||
@ -29,6 +29,7 @@ namespace modsecurity {
|
||||
class Transaction;
|
||||
namespace engine {
|
||||
|
||||
#ifdef WITH_LUA
|
||||
class LuaScriptBlob {
|
||||
public:
|
||||
LuaScriptBlob() :
|
||||
@ -61,7 +62,7 @@ class LuaScriptBlob {
|
||||
unsigned char *m_data;
|
||||
size_t m_len;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
class Lua {
|
||||
public:
|
||||
@ -71,6 +72,7 @@ class Lua {
|
||||
int run(Transaction *t);
|
||||
static bool isCompatible(std::string script, Lua *l, std::string *error);
|
||||
|
||||
#ifdef WITH_LUA
|
||||
static int blob_keeper(lua_State *L, const void *p, size_t sz, void *ud);
|
||||
static const char *blob_reader(lua_State *L, void *us, size_t *size);
|
||||
|
||||
@ -82,10 +84,11 @@ class Lua {
|
||||
std::string var);
|
||||
|
||||
LuaScriptBlob m_blob;
|
||||
#endif
|
||||
std::string m_scriptName;
|
||||
};
|
||||
|
||||
|
||||
#ifdef WITH_LUA
|
||||
static const struct luaL_Reg mscLuaLib[] = {
|
||||
{ "log", Lua::log },
|
||||
{ "getvar", Lua::getvar },
|
||||
@ -93,7 +96,7 @@ static const struct luaL_Reg mscLuaLib[] = {
|
||||
{ "setvar", Lua::setvar },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace engines
|
||||
} // namespace modsecurity
|
||||
|
@ -435,6 +435,9 @@ int main(int argc, char **argv) {
|
||||
#ifdef WITH_SSDEEP
|
||||
resources.push_back("ssdeep");
|
||||
#endif
|
||||
#ifdef WITH_LUA
|
||||
resources.push_back("lua");
|
||||
#endif
|
||||
|
||||
#ifdef NO_LOGS
|
||||
std::cout << "Test utility cannot work without logging support." \
|
||||
|
@ -3,6 +3,7 @@
|
||||
"enabled":1,
|
||||
"version_min":300000,
|
||||
"version_max":0,
|
||||
"resource":"lua",
|
||||
"title":"Testing action :: exec (1/3)",
|
||||
"client":{
|
||||
"ip":"200.249.12.31",
|
||||
@ -51,6 +52,7 @@
|
||||
"enabled":1,
|
||||
"version_min":300000,
|
||||
"version_max":0,
|
||||
"resource":"lua",
|
||||
"title":"Testing action :: exec (2/2)",
|
||||
"client":{
|
||||
"ip":"200.249.12.31",
|
||||
@ -98,6 +100,7 @@
|
||||
"enabled":1,
|
||||
"version_min":300000,
|
||||
"version_max":0,
|
||||
"resource":"lua",
|
||||
"title":"Testing action :: exec (3/3)",
|
||||
"client":{
|
||||
"ip":"200.249.12.31",
|
||||
|
@ -78,7 +78,7 @@
|
||||
{
|
||||
"enabled":1,
|
||||
"version_min":300000,
|
||||
"title":"Testing Operator :: @inspectFile (2/3)",
|
||||
"title":"Testing Operator :: @inspectFile (3/3)",
|
||||
"client":{
|
||||
"ip":"200.249.12.31",
|
||||
"port":123
|
||||
@ -116,7 +116,8 @@
|
||||
{
|
||||
"enabled":1,
|
||||
"version_min":300000,
|
||||
"title":"Testing Operator :: @inspectFile - lua (1/1)",
|
||||
"resource":"lua",
|
||||
"title":"Testing Operator :: @inspectFile - lua (1/7)",
|
||||
"client":{
|
||||
"ip":"200.249.12.31",
|
||||
"port":123
|
||||
@ -154,7 +155,8 @@
|
||||
{
|
||||
"enabled":1,
|
||||
"version_min":300000,
|
||||
"title":"Testing Operator :: @inspectFile - lua (2/2)",
|
||||
"resource":"lua",
|
||||
"title":"Testing Operator :: @inspectFile - lua (2/7)",
|
||||
"client":{
|
||||
"ip":"200.249.12.31",
|
||||
"port":123
|
||||
@ -192,7 +194,8 @@
|
||||
{
|
||||
"enabled":1,
|
||||
"version_min":300000,
|
||||
"title":"Testing Operator :: @inspectFile - lua (3/3)",
|
||||
"resource":"lua",
|
||||
"title":"Testing Operator :: @inspectFile - lua (3/7)",
|
||||
"client":{
|
||||
"ip":"200.249.12.31",
|
||||
"port":123
|
||||
@ -231,7 +234,8 @@
|
||||
{
|
||||
"enabled":1,
|
||||
"version_min":300000,
|
||||
"title":"Testing Operator :: @inspectFile - lua (4/4)",
|
||||
"resource":"lua",
|
||||
"title":"Testing Operator :: @inspectFile - lua (4/7)",
|
||||
"client":{
|
||||
"ip":"200.249.12.31",
|
||||
"port":123
|
||||
@ -270,7 +274,8 @@
|
||||
{
|
||||
"enabled":1,
|
||||
"version_min":300000,
|
||||
"title":"Testing Operator :: @inspectFile - lua (5/5)",
|
||||
"resource":"lua",
|
||||
"title":"Testing Operator :: @inspectFile - lua (5/7)",
|
||||
"client":{
|
||||
"ip":"200.249.12.31",
|
||||
"port":123
|
||||
@ -309,7 +314,8 @@
|
||||
{
|
||||
"enabled":1,
|
||||
"version_min":300000,
|
||||
"title":"Testing Operator :: @inspectFile - lua (6/?)",
|
||||
"resource":"lua",
|
||||
"title":"Testing Operator :: @inspectFile - lua (6/7)",
|
||||
"client":{
|
||||
"ip":"200.249.12.31",
|
||||
"port":123
|
||||
@ -348,7 +354,8 @@
|
||||
{
|
||||
"enabled":1,
|
||||
"version_min":300000,
|
||||
"title":"Testing Operator :: @inspectFile - lua (7/?)",
|
||||
"resource":"lua",
|
||||
"title":"Testing Operator :: @inspectFile - lua (7/7)",
|
||||
"client":{
|
||||
"ip":"200.249.12.31",
|
||||
"port":123
|
||||
|
Loading…
x
Reference in New Issue
Block a user