diff --git a/build/lua.m4 b/build/lua.m4 new file mode 100644 index 00000000..29301202 --- /dev/null +++ b/build/lua.m4 @@ -0,0 +1,152 @@ +dnl Check for LUA Libraries +dnl CHECK_LUA(ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]) + + +AC_DEFUN([CHECK_LUA], +[dnl + +# Possible names for the lua library/package (pkg-config) +LUA_POSSIBLE_LIB_NAMES="lua" + +# Possible extensions for the library +LUA_POSSIBLE_EXTENSIONS="so so0 la sl dll dylib so.0.0.0" + +# Possible paths (if pkg-config was not found, proceed with the file lookup) +LUA_POSSIBLE_PATHS="/usr/lib /usr/local/lib /usr/local/lua /usr/local/liblua /usr/local /opt /usr /usr/lib64 /opt/local" + +# Variables to be set by this very own script. +LUA_CFLAGS="" +LUA_LDFLAGS="" +LUA_LDADD="" +LUA_DISPLAY="" + +AC_ARG_WITH( + lua, + AC_HELP_STRING( + [--with-lua=PATH], + [Path to lua prefix] + ) +) + + +if test "x${with_lua}" == "xno"; then + AC_DEFINE(HAVE_LUA, 0, [Support for LUA was disabled by the utilization of --without-lua or --with-lua=no]) + AC_MSG_NOTICE([Support for LUA was disabled by the utilization of --without-lua or --with-lua=no]) + LUA_DISABLED=yes +else + if test "x${with_lua}" == "xyes"; then + LUA_MANDATORY=yes + AC_MSG_NOTICE([LUA support was marked as mandatory by the utilization of --with-lua=yes]) + else + LUA_MANDATORY=no + fi + for x in ${LUA_POSSIBLE_PATHS}; do + CHECK_FOR_LUA_AT(${x}) + if test -n "${LUA_CFLAGS}"; then + break + fi + done +fi + + +if test -z "${LUA_CFLAGS}"; then + if test -z "${LUA_MANDATORY}" || test "x${LUA_MANDATORY}" == "xno"; then + if test -z "${LUA_DISABLED}"; then + AC_MSG_NOTICE([LUA library was not found]) + LUA_FOUND=0 + else + LUA_FOUND=2 + fi + else + AC_MSG_ERROR([LUA was explicitly referenced but it was not found]) + LUA_FOUND=-1 + fi +else + if test -z "${LUA_MANDATORY}" || test "x${LUA_MANDATORY}" == "xno"; then + LUA_FOUND=2 + AC_MSG_NOTICE([LUA is disabled by default.]) + else + 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) + fi +fi + + +AC_SUBST(LUA_FOUND) + +]) # AC_DEFUN [CHECK_LUA] + + +AC_DEFUN([CHECK_FOR_LUA_AT], [ + path=$1 + echo "*** LOOKING AT PATH: " ${path} + for y in ${LUA_POSSIBLE_EXTENSIONS}; do + for z in ${LUA_POSSIBLE_LIB_NAMES}; do + if test -e "${path}/${z}.${y}"; then + lua_lib_path="${path}/" + lua_lib_name="${z}" + lua_lib_file="${lua_lib_path}/${z}.${y}" + break + fi + if test -e "${path}/lib${z}.${y}"; then + lua_lib_path="${path}/" + lua_lib_name="${z}" + lua_lib_file="${lua_lib_path}/lib${z}.${y}" + break + fi + if test -e "${path}/lib/lib${z}.${y}"; then + lua_lib_path="${path}/lib/" + lua_lib_name="${z}" + lua_lib_file="${lua_lib_path}/lib${z}.${y}" + break + fi + if test -e "${path}/lib/x86_64-linux-gnu/lib${z}.${y}"; then + lua_lib_path="${path}/lib/x86_64-linux-gnu/" + lua_lib_name="${z}" + lua_lib_file="${lua_lib_path}/lib${z}.${y}" + break + fi + if test -e "${path}/lib/i386-linux-gnu/lib${z}.${y}"; then + lua_lib_path="${path}/lib/i386-linux-gnu/" + lua_lib_name="${z}" + lua_lib_file="${lua_lib_path}/lib${z}.${y}" + break + fi + done + if test -n "$lua_lib_path"; then + break + fi + done + if test -e "${path}/include/fuzzy.h"; then + lua_inc_path="${path}/include" + elif test -e "${path}/fuzzy.h"; then + lua_inc_path="${path}" + elif test -e "${path}/include/fuzzy/fuzzy.h"; then + lua_inc_path="${path}/include" + fi + + if test -n "${lua_lib_path}"; then + AC_MSG_NOTICE([LUA library found at: ${lua_lib_file}]) + fi + + if test -n "${lua_inc_path}"; then + AC_MSG_NOTICE([LUA headers found at: ${lua_inc_path}]) + fi + + if test -n "${lua_lib_path}" -a -n "${lua_inc_path}"; then + # TODO: Compile a piece of code to check the version. + LUA_CFLAGS="-I${lua_inc_path}" + LUA_LDADD="-l${lua_lib_name}" + LUA_LDFLAGS="-L${lua_lib_path}" + LUA_DISPLAY="${lua_lib_file}, ${lua_inc_path}" + fi +]) # AC_DEFUN [CHECK_FOR_LUA_AT] + + + diff --git a/configure.ac b/configure.ac index 820b526e..88c9220a 100644 --- a/configure.ac +++ b/configure.ac @@ -90,6 +90,11 @@ AM_CONDITIONAL([LMDB_CFLAGS], [test "LMDB_CFLAGS" != ""]) CHECK_SSDEEP AM_CONDITIONAL([SSDEEP_CFLAGS], [test "SSDEEP_CFLAGS" != ""]) +# Check for LUA +CHECK_LUA +AM_CONDITIONAL([LUA_CFLAGS], [test "LUA_CFLAGS" != ""]) + + # # Check for curl # @@ -504,6 +509,23 @@ if test "x$SSDEEP_FOUND" = "x2"; then echo " + SSDEEP ....disabled" fi +## LUA +if test "x$LUA_FOUND" = "x0"; then + echo " + LUA ....not found" +fi +if test "x$LUA_FOUND" = "x1"; then + echo -n " + LUA ....found " + if ! test "x$LUA_VERSION" = "x"; then + echo "v${LUA_VERSION}" + else + echo "" + fi + echo " ${LUA_DISPLAY}" +fi +if test "x$LUA_FOUND" = "x2"; then + echo " + LUA ....disabled" +fi + echo " " echo " Other Options" diff --git a/examples/multiprocess_c/Makefile.am b/examples/multiprocess_c/Makefile.am index dd78e38f..8c7aac91 100644 --- a/examples/multiprocess_c/Makefile.am +++ b/examples/multiprocess_c/Makefile.am @@ -12,6 +12,7 @@ multi_LDADD = \ $(YAJL_LDFLAGS) \ $(GEOIP_LDFLAGS) \ $(SSDEEP_LDFLAGS) $(SSDEEP_LDADD) \ + $(LUA_LDFLAGS) $(LUA_LDADD) \ $(GLOBAL_LDADD) multi_CFLAGS = \ diff --git a/examples/reading_logs_via_rule_message/Makefile.am b/examples/reading_logs_via_rule_message/Makefile.am index 07c655ee..57b33335 100644 --- a/examples/reading_logs_via_rule_message/Makefile.am +++ b/examples/reading_logs_via_rule_message/Makefile.am @@ -14,6 +14,7 @@ simple_request_LDADD = \ $(YAJL_LDFLAGS) $(YAJL_LDADD) \ $(LMDB_LDFLAGS) $(LMDB_LDADD) \ $(SSDEEP_LDFLAGS) $(SSDEEP_LDADD) \ + $(LUA_LDFLAGS) $(LUA_LDADD) \ $(LIBXML2_LDADD) \ $(GLOBAL_LDADD) @@ -32,6 +33,7 @@ simple_request_CPPFLAGS = \ $(MODSEC_NO_LOGS) \ $(YAJL_CFLAGS) \ $(LMDB_CFLAGS) \ + $(LUA_CFLAGS) \ $(PCRE_CFLAGS) \ $(LIBXML2_CFLAGS) diff --git a/examples/reading_logs_with_offset/Makefile.am b/examples/reading_logs_with_offset/Makefile.am index 8be37fcd..855bd660 100644 --- a/examples/reading_logs_with_offset/Makefile.am +++ b/examples/reading_logs_with_offset/Makefile.am @@ -13,6 +13,7 @@ read_LDADD = \ $(YAJL_LDFLAGS) $(YAJL_LDADD) \ $(LMDB_LDFLAGS) $(LMDB_LDADD) \ $(SSDEEP_LDFLAGS) $(SSDEEP_LDADD) \ + $(LUA_LDFLAGS) $(LUA_LDADD) \ $(LIBXML2_LDADD) \ $(GLOBAL_LDADD) @@ -31,6 +32,7 @@ read_CPPFLAGS = \ $(MODSEC_NO_LOGS) \ $(YAJL_CFLAGS) \ $(LMDB_CFLAGS) \ + $(LUA_CFLAGS) \ $(PCRE_CFLAGS) \ $(LIBXML2_CFLAGS) diff --git a/examples/simple_example_using_c/Makefile.am b/examples/simple_example_using_c/Makefile.am index cc681e4a..0979e265 100644 --- a/examples/simple_example_using_c/Makefile.am +++ b/examples/simple_example_using_c/Makefile.am @@ -11,6 +11,7 @@ test_LDADD = \ $(YAJL_LDFLAGS) \ $(GEOIP_LDFLAGS) \ $(SSDEEP_LDFLAGS) $(SSDEEP_LDADD) \ + $(LUA_LDFLAGS) $(LUA_LDADD) \ $(GLOBAL_LDADD) test_CFLAGS = \ diff --git a/examples/using_bodies_in_chunks/Makefile.am b/examples/using_bodies_in_chunks/Makefile.am index 07c655ee..57b33335 100644 --- a/examples/using_bodies_in_chunks/Makefile.am +++ b/examples/using_bodies_in_chunks/Makefile.am @@ -14,6 +14,7 @@ simple_request_LDADD = \ $(YAJL_LDFLAGS) $(YAJL_LDADD) \ $(LMDB_LDFLAGS) $(LMDB_LDADD) \ $(SSDEEP_LDFLAGS) $(SSDEEP_LDADD) \ + $(LUA_LDFLAGS) $(LUA_LDADD) \ $(LIBXML2_LDADD) \ $(GLOBAL_LDADD) @@ -32,6 +33,7 @@ simple_request_CPPFLAGS = \ $(MODSEC_NO_LOGS) \ $(YAJL_CFLAGS) \ $(LMDB_CFLAGS) \ + $(LUA_CFLAGS) \ $(PCRE_CFLAGS) \ $(LIBXML2_CFLAGS) diff --git a/src/Makefile.am b/src/Makefile.am index 6ed13d57..1d48167c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -78,6 +78,10 @@ noinst_HEADERS = \ *.h +ENGINES = \ + engines/lua.cc + + VARIABLES = \ variables/duration.cc \ variables/env.cc \ @@ -273,6 +277,7 @@ libmodsecurity_la_SOURCES = \ rules_exceptions.cc \ ${BODY_PROCESSORS} \ ${ACTIONS} \ + ${ENGINES} \ ${COLLECTION} \ ${OPERATORS} \ ${UTILS} \ @@ -298,6 +303,7 @@ libmodsecurity_la_CPPFLAGS = \ $(LMDB_CFLAGS) \ $(PCRE_CFLAGS) \ $(SSDEEP_CFLAGS) \ + $(LUA_CFLAGS) \ $(LIBXML2_CFLAGS) libmodsecurity_la_LIBADD = \ @@ -308,6 +314,7 @@ libmodsecurity_la_LIBADD = \ $(YAJL_LDFLAGS) $(YAJL_LDADD) \ $(LMDB_LDFLAGS) $(LMDB_LDADD) \ $(SSDEEP_LDFLAGS) $(SSDEEP_LDADD) \ + $(LUA_LDFLAGS) $(LUA_LDADD) \ $(LIBXML2_LDADD) \ ../others/libinjection.la \ ../others/libmbedtls.la diff --git a/src/engines/lua.cc b/src/engines/lua.cc new file mode 100644 index 00000000..9df08c07 --- /dev/null +++ b/src/engines/lua.cc @@ -0,0 +1,32 @@ +/* + * ModSecurity, http://www.modsecurity.org/ + * Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/) + * + * You may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * If any of the files related to licensing are missing or if you have any + * other questions related to licensing please contact Trustwave Holdings, Inc. + * directly using the email address security@modsecurity.org. + * + */ + + +#include "modsecurity/modsecurity.h" +#include "src/engines/lua.h" + + +#ifdef WITH_LUA +#include + + +#endif + +#ifndef SRC_ENGINES_LUA_H_ +#define SRC_ENGINES_LUA_H_ + + + +#endif // SRC_ENGINES_LUA_H_ diff --git a/src/engines/lua.h b/src/engines/lua.h new file mode 100644 index 00000000..e69de29b diff --git a/test/benchmark/Makefile.am b/test/benchmark/Makefile.am index 176dab95..7bc92669 100644 --- a/test/benchmark/Makefile.am +++ b/test/benchmark/Makefile.am @@ -13,6 +13,7 @@ benchmark_LDADD = \ $(YAJL_LDFLAGS) $(YAJL_LDADD) \ $(LMDB_LDFLAGS) $(LMDB_LDADD) \ $(SSDEEP_LDFLAGS) $(SSDEEP_LDADD) \ + $(LUA_LDFLAGS) $(LUA_LDADD) \ $(LIBXML2_LDADD) \ $(GLOBAL_LDADD) diff --git a/test/fuzzer/Makefile.am b/test/fuzzer/Makefile.am index df4313b8..5b1dc08a 100644 --- a/test/fuzzer/Makefile.am +++ b/test/fuzzer/Makefile.am @@ -21,6 +21,7 @@ afl_fuzzer_LDADD = \ $(YAJL_LDFLAGS) $(YAJL_LDADD) \ $(LMDB_LDFLAGS) $(LMDB_LDADD) \ $(SSDEEP_LDFLAGS) $(SSDEEP_LDADD) \ + $(LUA_LDFLAGS) $(LUA_LDADD) \ $(LIBXML2_LDADD) \ $(top_builddir)/src/.libs/libmodsecurity.a \ $(top_builddir)/others/libinjection.la \ diff --git a/tools/rules-check/Makefile.am b/tools/rules-check/Makefile.am index ba469a7c..0fa6d64a 100644 --- a/tools/rules-check/Makefile.am +++ b/tools/rules-check/Makefile.am @@ -13,6 +13,7 @@ modsec_rules_check_LDADD = \ $(YAJL_LDFLAGS) $(YAJL_LDADD) \ $(LMDB_LDFLAGS) $(LMDB_LDADD) \ $(SSDEEP_LDFLAGS) $(SSDEEP_LDADD) \ + $(LUA_LDFLAGS) $(LUA_LDADD) \ $(LIBXML2_LDADD) \ $(GLOBAL_LDADD)