From 8816254cc8d0b98fd43ac58a9152609ab19350cb Mon Sep 17 00:00:00 2001 From: Breno Silva Date: Wed, 30 Jan 2013 22:03:15 -0400 Subject: [PATCH] ModSecurity: fixed compiling with lua 5.2 --- apache2/mod_security2.c | 4 ++++ apache2/msc_lua.c | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/apache2/mod_security2.c b/apache2/mod_security2.c index 6b410881..849ca9dc 100644 --- a/apache2/mod_security2.c +++ b/apache2/mod_security2.c @@ -440,7 +440,11 @@ static modsec_rec *create_tx_context(request_rec *r) { #if defined(WITH_LUA) #ifdef CACHE_LUA +#if LUA_VERSION_NUM > 501 + msr->L = luaL_newstate(); +#else msr->L = lua_open(); +#endif luaL_openlibs(msr->L); #endif #endif diff --git a/apache2/msc_lua.c b/apache2/msc_lua.c index 4abf7e5c..6450e778 100644 --- a/apache2/msc_lua.c +++ b/apache2/msc_lua.c @@ -94,7 +94,11 @@ char *lua_compile(msc_script **script, const char *filename, apr_pool_t *pool) { msc_lua_dumpw_t dump; /* Initialise state. */ +#if LUA_VERSION_NUM > 501 + L = luaL_newstate(); +#else L = lua_open(); +#endif luaL_openlibs(L); /* Find script. */ @@ -158,7 +162,11 @@ static apr_array_header_t *resolve_tfns(lua_State *L, int idx, modsec_rec *msr, if (lua_isuserdata(L, idx) || lua_isnoneornil(L, idx)) { /* No second parameter */ return tfn_arr; } else if (lua_istable(L, idx)) { /* Is the second parameter an array? */ +#if LUA_VERSION_NUM > 501 + int i, n = lua_rawlen(L, idx); +#else int i, n = lua_objlen(L, idx); +#endif for(i = 1; i <= n; i++) { lua_rawgeti(L, idx, i); @@ -415,7 +423,11 @@ int lua_execute(msc_script *script, char *param, modsec_rec *msr, msre_rule *rul lua_pop(L, rc); #else /* Create new state. */ +#if LUA_VERSION_NUM > 501 + L = luaL_newstate(); +#else L = lua_open(); +#endif luaL_openlibs(L); #endif @@ -433,7 +445,12 @@ int lua_execute(msc_script *script, char *param, modsec_rec *msr, msre_rule *rul } /* Register functions. */ +#if LUA_VERSION_NUM > 501 + luaL_setfuncs(L,mylib,0); + lua_setglobal(L,"m"); +#else luaL_register(L, "m", mylib); +#endif rc = lua_restore(L, script); if (rc) {