mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-13 21:36:00 +03:00
Implement support for Lua 5.1
This commit is contained in:
parent
eed6b5f86d
commit
dee9898449
18
build/lua.m4
18
build/lua.m4
@ -6,7 +6,7 @@ AC_DEFUN([CHECK_LUA],
|
|||||||
[dnl
|
[dnl
|
||||||
|
|
||||||
# Possible names for the lua library/package (pkg-config)
|
# Possible names for the lua library/package (pkg-config)
|
||||||
LUA_POSSIBLE_LIB_NAMES="lua lua53 lua5.3 lua52 lua5.2"
|
LUA_POSSIBLE_LIB_NAMES="lua lua53 lua5.3 lua52 lua5.2 lua51 lua5.1"
|
||||||
|
|
||||||
# Possible extensions for the library
|
# Possible extensions for the library
|
||||||
LUA_POSSIBLE_EXTENSIONS="so so0 la sl dll dylib so.0.0.0"
|
LUA_POSSIBLE_EXTENSIONS="so so0 la sl dll dylib so.0.0.0"
|
||||||
@ -88,10 +88,6 @@ if test -z "${LUA_CFLAGS}"; then
|
|||||||
LUA_FOUND=-1
|
LUA_FOUND=-1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if test "${lua_5_1}" = 1 && test "x${LUA_MANDATORY}" == "xyes" ; then
|
|
||||||
AC_MSG_ERROR([LUA was explicitly referenced but LUA v5.1 was found and it is not currently supported on libModSecurity. LUA_VERSION: ${LUA_VERSION}])
|
|
||||||
LUA_FOUND=-1
|
|
||||||
fi
|
|
||||||
if test -z "${LUA_MANDATORY}" || test "x${LUA_MANDATORY}" == "xno"; then
|
if test -z "${LUA_MANDATORY}" || test "x${LUA_MANDATORY}" == "xno"; then
|
||||||
LUA_FOUND=1
|
LUA_FOUND=1
|
||||||
AC_MSG_NOTICE([using LUA ${LUA_LDADD}])
|
AC_MSG_NOTICE([using LUA ${LUA_LDADD}])
|
||||||
@ -113,15 +109,6 @@ else
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test "${lua_5_1}" = 1 ; then
|
|
||||||
AC_MSG_NOTICE([LUA 5.1 was found and it is not currently supported on libModSecurity. LUA_VERSION: ${LUA_VERSION}. LUA build disabled.])
|
|
||||||
LUA_FOUND=2
|
|
||||||
LUA_CFLAGS=
|
|
||||||
LUA_DISPLAY=
|
|
||||||
LUA_LDADD=
|
|
||||||
LUA_LDFLAGS=
|
|
||||||
fi
|
|
||||||
|
|
||||||
AC_SUBST(LUA_FOUND)
|
AC_SUBST(LUA_FOUND)
|
||||||
|
|
||||||
]) # AC_DEFUN [CHECK_LUA]
|
]) # AC_DEFUN [CHECK_LUA]
|
||||||
@ -179,6 +166,9 @@ AC_DEFUN([CHECK_FOR_LUA_AT], [
|
|||||||
elif test -e "${path}/include/lua5.2/lua.h"; then
|
elif test -e "${path}/include/lua5.2/lua.h"; then
|
||||||
lua_inc_path="${path}/include/lua5.2"
|
lua_inc_path="${path}/include/lua5.2"
|
||||||
LUA_VERSION=502
|
LUA_VERSION=502
|
||||||
|
elif test -e "${path}/include/lua5.1/lua.h"; then
|
||||||
|
lua_inc_path="${path}/include/lua5.1"
|
||||||
|
LUA_VERSION=501
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test -n "${lua_lib_path}"; then
|
if test -n "${lua_lib_path}"; then
|
||||||
|
@ -82,7 +82,7 @@ bool Lua::load(std::string script, std::string *err) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WITH_LUA_5_2
|
#if defined (WITH_LUA_5_2) || defined (WITH_LUA_5_1)
|
||||||
if (lua_dump(L, Lua::blob_keeper, reinterpret_cast<void *>(&m_blob))) {
|
if (lua_dump(L, Lua::blob_keeper, reinterpret_cast<void *>(&m_blob))) {
|
||||||
#else
|
#else
|
||||||
if (lua_dump(L, Lua::blob_keeper, reinterpret_cast<void *>(&m_blob), 0)) {
|
if (lua_dump(L, Lua::blob_keeper, reinterpret_cast<void *>(&m_blob), 0)) {
|
||||||
@ -138,8 +138,12 @@ int Lua::run(Transaction *t) {
|
|||||||
luaL_setfuncs(L, mscLuaLib, 0);
|
luaL_setfuncs(L, mscLuaLib, 0);
|
||||||
lua_setglobal(L, "m");
|
lua_setglobal(L, "m");
|
||||||
|
|
||||||
|
#ifdef WITH_LUA_5_1
|
||||||
|
int rc = lua_load(L, Lua::blob_reader, &m_blob, m_scriptName.c_str());
|
||||||
|
#else
|
||||||
int rc = lua_load(L, Lua::blob_reader, &m_blob, m_scriptName.c_str(),
|
int rc = lua_load(L, Lua::blob_reader, &m_blob, m_scriptName.c_str(),
|
||||||
NULL);
|
NULL);
|
||||||
|
#endif
|
||||||
if (rc != LUA_OK) {
|
if (rc != LUA_OK) {
|
||||||
std::string e;
|
std::string e;
|
||||||
e.assign("Failed to execute lua script: " + m_scriptName + ". ");
|
e.assign("Failed to execute lua script: " + m_scriptName + ". ");
|
||||||
@ -150,9 +154,11 @@ int Lua::run(Transaction *t) {
|
|||||||
case LUA_ERRMEM:
|
case LUA_ERRMEM:
|
||||||
e.assign("Memory error. ");
|
e.assign("Memory error. ");
|
||||||
break;
|
break;
|
||||||
|
#ifndef WITH_LUA_5_1
|
||||||
case LUA_ERRGCMM:
|
case LUA_ERRGCMM:
|
||||||
e.assign("Garbage Collector error. ");
|
e.assign("Garbage Collector error. ");
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
e.append(lua_tostring(L, -1));
|
e.append(lua_tostring(L, -1));
|
||||||
#ifndef NO_LOGS
|
#ifndef NO_LOGS
|
||||||
@ -402,7 +408,11 @@ std::string Lua::applyTransformations(lua_State *L, Transaction *t,
|
|||||||
|
|
||||||
if (lua_istable(L, idx)) {
|
if (lua_istable(L, idx)) {
|
||||||
const char *name = NULL;
|
const char *name = NULL;
|
||||||
|
#ifdef WITH_LUA_5_1
|
||||||
|
int i, n = lua_objlen(L, idx);
|
||||||
|
#else
|
||||||
int i, n = lua_rawlen(L, idx);
|
int i, n = lua_rawlen(L, idx);
|
||||||
|
#endif
|
||||||
|
|
||||||
for (i = 1; i <= n; i++) {
|
for (i = 1; i <= n; i++) {
|
||||||
lua_rawgeti(L, idx, i);
|
lua_rawgeti(L, idx, i);
|
||||||
|
@ -101,4 +101,29 @@ static const struct luaL_Reg mscLuaLib[] = {
|
|||||||
} // namespace engine
|
} // namespace engine
|
||||||
} // namespace modsecurity
|
} // namespace modsecurity
|
||||||
|
|
||||||
|
#ifdef WITH_LUA
|
||||||
|
#if defined LUA_VERSION_NUM && LUA_VERSION_NUM < 502
|
||||||
|
/*
|
||||||
|
** Adapted from Lua 5.2.0
|
||||||
|
*/
|
||||||
|
#define LUA_OK 0
|
||||||
|
|
||||||
|
static void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup) {
|
||||||
|
luaL_checkstack(L, nup + 1, "too many upvalues");
|
||||||
|
|
||||||
|
for (; l->name != NULL; l++) { /* fill the table with given functions */
|
||||||
|
int i;
|
||||||
|
lua_pushstring(L, l->name);
|
||||||
|
for (i = 0; i < nup; i++) /* copy upvalues to the top */
|
||||||
|
lua_pushvalue(L, -(nup + 1));
|
||||||
|
lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */
|
||||||
|
lua_settable(L, -(nup + 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_pop(L, nup); /* remove upvalues */
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif // SRC_ENGINE_LUA_H_
|
#endif // SRC_ENGINE_LUA_H_
|
||||||
|
Loading…
x
Reference in New Issue
Block a user