Skip to content

Commit

Permalink
Adds support to LUA in configure scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe Zimmerle committed Oct 31, 2017
1 parent 9369efc commit 1189e9b
Show file tree
Hide file tree
Showing 13 changed files with 224 additions and 0 deletions.
152 changes: 152 additions & 0 deletions 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]



22 changes: 22 additions & 0 deletions configure.ac
Expand Up @@ -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
#
Expand Down Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions examples/multiprocess_c/Makefile.am
Expand Up @@ -12,6 +12,7 @@ multi_LDADD = \
$(YAJL_LDFLAGS) \
$(GEOIP_LDFLAGS) \
$(SSDEEP_LDFLAGS) $(SSDEEP_LDADD) \
$(LUA_LDFLAGS) $(LUA_LDADD) \
$(GLOBAL_LDADD)

multi_CFLAGS = \
Expand Down
2 changes: 2 additions & 0 deletions examples/reading_logs_via_rule_message/Makefile.am
Expand Up @@ -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)

Expand All @@ -32,6 +33,7 @@ simple_request_CPPFLAGS = \
$(MODSEC_NO_LOGS) \
$(YAJL_CFLAGS) \
$(LMDB_CFLAGS) \
$(LUA_CFLAGS) \
$(PCRE_CFLAGS) \
$(LIBXML2_CFLAGS)

Expand Down
2 changes: 2 additions & 0 deletions examples/reading_logs_with_offset/Makefile.am
Expand Up @@ -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)

Expand All @@ -31,6 +32,7 @@ read_CPPFLAGS = \
$(MODSEC_NO_LOGS) \
$(YAJL_CFLAGS) \
$(LMDB_CFLAGS) \
$(LUA_CFLAGS) \
$(PCRE_CFLAGS) \
$(LIBXML2_CFLAGS)

Expand Down
1 change: 1 addition & 0 deletions examples/simple_example_using_c/Makefile.am
Expand Up @@ -11,6 +11,7 @@ test_LDADD = \
$(YAJL_LDFLAGS) \
$(GEOIP_LDFLAGS) \
$(SSDEEP_LDFLAGS) $(SSDEEP_LDADD) \
$(LUA_LDFLAGS) $(LUA_LDADD) \
$(GLOBAL_LDADD)

test_CFLAGS = \
Expand Down
2 changes: 2 additions & 0 deletions examples/using_bodies_in_chunks/Makefile.am
Expand Up @@ -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)

Expand All @@ -32,6 +33,7 @@ simple_request_CPPFLAGS = \
$(MODSEC_NO_LOGS) \
$(YAJL_CFLAGS) \
$(LMDB_CFLAGS) \
$(LUA_CFLAGS) \
$(PCRE_CFLAGS) \
$(LIBXML2_CFLAGS)

Expand Down
7 changes: 7 additions & 0 deletions src/Makefile.am
Expand Up @@ -78,6 +78,10 @@ noinst_HEADERS = \
*.h


ENGINES = \
engines/lua.cc


VARIABLES = \
variables/duration.cc \
variables/env.cc \
Expand Down Expand Up @@ -273,6 +277,7 @@ libmodsecurity_la_SOURCES = \
rules_exceptions.cc \
${BODY_PROCESSORS} \
${ACTIONS} \
${ENGINES} \
${COLLECTION} \
${OPERATORS} \
${UTILS} \
Expand All @@ -298,6 +303,7 @@ libmodsecurity_la_CPPFLAGS = \
$(LMDB_CFLAGS) \
$(PCRE_CFLAGS) \
$(SSDEEP_CFLAGS) \
$(LUA_CFLAGS) \
$(LIBXML2_CFLAGS)

libmodsecurity_la_LIBADD = \
Expand All @@ -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
Expand Down
32 changes: 32 additions & 0 deletions 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 <lua.hpp>


#endif

#ifndef SRC_ENGINES_LUA_H_
#define SRC_ENGINES_LUA_H_



#endif // SRC_ENGINES_LUA_H_
Empty file added src/engines/lua.h
Empty file.
1 change: 1 addition & 0 deletions test/benchmark/Makefile.am
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions test/fuzzer/Makefile.am
Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions tools/rules-check/Makefile.am
Expand Up @@ -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)

Expand Down

0 comments on commit 1189e9b

Please sign in to comment.