Skip to content

Commit 7fa5ca9

Browse files
author
Felipe Zimmerle
committed
Makes lua optional
1 parent e52bd7d commit 7fa5ca9

File tree

6 files changed

+55
-17
lines changed

6 files changed

+55
-17
lines changed

build/lua.m4

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,14 @@ if test -z "${LUA_CFLAGS}"; then
6363
fi
6464
else
6565
if test -z "${LUA_MANDATORY}" || test "x${LUA_MANDATORY}" == "xno"; then
66-
LUA_FOUND=2
67-
AC_MSG_NOTICE([LUA is disabled by default.])
66+
LUA_FOUND=1
67+
AC_MSG_NOTICE([using LUA v${LUA_VERSION}])
68+
LUA_CFLAGS="-DWITH_LUA ${LUA_CFLAGS}"
69+
LUA_DISPLAY="${LUA_LDADD} ${LUA_LDFLAGS}, ${LUA_CFLAGS}"
70+
AC_SUBST(LUA_LDFLAGS)
71+
AC_SUBST(LUA_LDADD)
72+
AC_SUBST(LUA_CFLAGS)
73+
AC_SUBST(LUA_DISPLAY)
6874
else
6975
LUA_FOUND=1
7076
AC_MSG_NOTICE([using LUA v${LUA_VERSION}])

src/engine/lua.cc

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ namespace engine {
4141

4242

4343
bool Lua::isCompatible(std::string script, Lua *l, std::string *error) {
44+
#ifdef WITH_LUA
4445
std::string lua(".lua");
4546
std::string err;
4647

@@ -57,10 +58,15 @@ bool Lua::isCompatible(std::string script, Lua *l, std::string *error) {
5758
}
5859

5960
return true;
61+
#else
62+
error->assign("Lua support was not enabled.");
63+
return false;
64+
#endif
6065
}
6166

6267

6368
bool Lua::load(std::string script, std::string *err) {
69+
#ifdef WITH_LUA
6470
lua_State *L = NULL;
6571
L = luaL_newstate();
6672
luaL_openlibs(L);
@@ -93,9 +99,13 @@ bool Lua::load(std::string script, std::string *err) {
9399

94100
lua_close(L);
95101
return true;
102+
#else
103+
err->assign("Lua support was not enabled.");
104+
return false;
105+
#endif
96106
}
97107

98-
108+
#ifdef WITH_LUA
99109
int Lua::blob_keeper(lua_State *L, const void *p, size_t sz, void *ud) {
100110
LuaScriptBlob *lsb = static_cast<LuaScriptBlob *>(ud);
101111
lsb->write(p, sz);
@@ -108,9 +118,10 @@ const char *Lua::blob_reader(lua_State *L, void *ud, size_t *size) {
108118
const char *data = lsb->read(size);
109119
return data;
110120
}
111-
121+
#endif
112122

113123
int Lua::run(Transaction *t) {
124+
#ifdef WITH_LUA
114125
std::string luaRet;
115126
lua_State *L = luaL_newstate();
116127
luaL_openlibs(L);
@@ -188,9 +199,14 @@ int Lua::run(Transaction *t) {
188199
}
189200

190201
return true;
202+
#else
203+
t->debug(9, "Lua support was not enabled.");
204+
return false;
205+
#endif
191206
}
192207

193208

209+
#ifdef WITH_LUA
194210
int Lua::log(lua_State *L) {
195211
Transaction *t = NULL;
196212
const char *text;
@@ -371,7 +387,7 @@ std::string Lua::applyTransformations(lua_State *L, Transaction *t, int idx, std
371387

372388
return newVar;
373389
}
374-
390+
#endif
375391

376392
} // namespace engines
377393
} // namespace modsecurity

src/engine/lua.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
*/
1515

1616
#ifdef WITH_LUA
17-
#endif
1817
#include <lua.hpp>
18+
#endif
1919

2020
#include <iostream>
2121
#include <cstdint>
@@ -29,6 +29,7 @@ namespace modsecurity {
2929
class Transaction;
3030
namespace engine {
3131

32+
#ifdef WITH_LUA
3233
class LuaScriptBlob {
3334
public:
3435
LuaScriptBlob() :
@@ -61,7 +62,7 @@ class LuaScriptBlob {
6162
unsigned char *m_data;
6263
size_t m_len;
6364
};
64-
65+
#endif
6566

6667
class Lua {
6768
public:
@@ -71,6 +72,7 @@ class Lua {
7172
int run(Transaction *t);
7273
static bool isCompatible(std::string script, Lua *l, std::string *error);
7374

75+
#ifdef WITH_LUA
7476
static int blob_keeper(lua_State *L, const void *p, size_t sz, void *ud);
7577
static const char *blob_reader(lua_State *L, void *us, size_t *size);
7678

@@ -82,18 +84,19 @@ class Lua {
8284
std::string var);
8385

8486
LuaScriptBlob m_blob;
87+
#endif
8588
std::string m_scriptName;
8689
};
8790

88-
91+
#ifdef WITH_LUA
8992
static const struct luaL_Reg mscLuaLib[] = {
9093
{ "log", Lua::log },
9194
{ "getvar", Lua::getvar },
9295
{ "getvars", Lua::getvars },
9396
{ "setvar", Lua::setvar },
9497
{ NULL, NULL }
9598
};
96-
99+
#endif
97100

98101
} // namespace engines
99102
} // namespace modsecurity

test/regression/regression.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,9 @@ int main(int argc, char **argv) {
435435
#ifdef WITH_SSDEEP
436436
resources.push_back("ssdeep");
437437
#endif
438+
#ifdef WITH_LUA
439+
resources.push_back("lua");
440+
#endif
438441

439442
#ifdef NO_LOGS
440443
std::cout << "Test utility cannot work without logging support." \

test/test-cases/regression/action-exec.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"enabled":1,
44
"version_min":300000,
55
"version_max":0,
6+
"resource":"lua",
67
"title":"Testing action :: exec (1/3)",
78
"client":{
89
"ip":"200.249.12.31",
@@ -51,6 +52,7 @@
5152
"enabled":1,
5253
"version_min":300000,
5354
"version_max":0,
55+
"resource":"lua",
5456
"title":"Testing action :: exec (2/2)",
5557
"client":{
5658
"ip":"200.249.12.31",
@@ -98,6 +100,7 @@
98100
"enabled":1,
99101
"version_min":300000,
100102
"version_max":0,
103+
"resource":"lua",
101104
"title":"Testing action :: exec (3/3)",
102105
"client":{
103106
"ip":"200.249.12.31",

test/test-cases/regression/operator-inpectFile.json

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
{
7979
"enabled":1,
8080
"version_min":300000,
81-
"title":"Testing Operator :: @inspectFile (2/3)",
81+
"title":"Testing Operator :: @inspectFile (3/3)",
8282
"client":{
8383
"ip":"200.249.12.31",
8484
"port":123
@@ -116,7 +116,8 @@
116116
{
117117
"enabled":1,
118118
"version_min":300000,
119-
"title":"Testing Operator :: @inspectFile - lua (1/1)",
119+
"resource":"lua",
120+
"title":"Testing Operator :: @inspectFile - lua (1/7)",
120121
"client":{
121122
"ip":"200.249.12.31",
122123
"port":123
@@ -154,7 +155,8 @@
154155
{
155156
"enabled":1,
156157
"version_min":300000,
157-
"title":"Testing Operator :: @inspectFile - lua (2/2)",
158+
"resource":"lua",
159+
"title":"Testing Operator :: @inspectFile - lua (2/7)",
158160
"client":{
159161
"ip":"200.249.12.31",
160162
"port":123
@@ -192,7 +194,8 @@
192194
{
193195
"enabled":1,
194196
"version_min":300000,
195-
"title":"Testing Operator :: @inspectFile - lua (3/3)",
197+
"resource":"lua",
198+
"title":"Testing Operator :: @inspectFile - lua (3/7)",
196199
"client":{
197200
"ip":"200.249.12.31",
198201
"port":123
@@ -231,7 +234,8 @@
231234
{
232235
"enabled":1,
233236
"version_min":300000,
234-
"title":"Testing Operator :: @inspectFile - lua (4/4)",
237+
"resource":"lua",
238+
"title":"Testing Operator :: @inspectFile - lua (4/7)",
235239
"client":{
236240
"ip":"200.249.12.31",
237241
"port":123
@@ -270,7 +274,8 @@
270274
{
271275
"enabled":1,
272276
"version_min":300000,
273-
"title":"Testing Operator :: @inspectFile - lua (5/5)",
277+
"resource":"lua",
278+
"title":"Testing Operator :: @inspectFile - lua (5/7)",
274279
"client":{
275280
"ip":"200.249.12.31",
276281
"port":123
@@ -309,7 +314,8 @@
309314
{
310315
"enabled":1,
311316
"version_min":300000,
312-
"title":"Testing Operator :: @inspectFile - lua (6/?)",
317+
"resource":"lua",
318+
"title":"Testing Operator :: @inspectFile - lua (6/7)",
313319
"client":{
314320
"ip":"200.249.12.31",
315321
"port":123
@@ -348,7 +354,8 @@
348354
{
349355
"enabled":1,
350356
"version_min":300000,
351-
"title":"Testing Operator :: @inspectFile - lua (7/?)",
357+
"resource":"lua",
358+
"title":"Testing Operator :: @inspectFile - lua (7/7)",
352359
"client":{
353360
"ip":"200.249.12.31",
354361
"port":123

0 commit comments

Comments
 (0)