Skip to content

Commit 1189e9b

Browse files
author
Felipe Zimmerle
committed
Adds support to LUA in configure scripts
1 parent 9369efc commit 1189e9b

File tree

13 files changed

+224
-0
lines changed

13 files changed

+224
-0
lines changed

build/lua.m4

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
dnl Check for LUA Libraries
2+
dnl CHECK_LUA(ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND])
3+
4+
5+
AC_DEFUN([CHECK_LUA],
6+
[dnl
7+
8+
# Possible names for the lua library/package (pkg-config)
9+
LUA_POSSIBLE_LIB_NAMES="lua"
10+
11+
# Possible extensions for the library
12+
LUA_POSSIBLE_EXTENSIONS="so so0 la sl dll dylib so.0.0.0"
13+
14+
# Possible paths (if pkg-config was not found, proceed with the file lookup)
15+
LUA_POSSIBLE_PATHS="/usr/lib /usr/local/lib /usr/local/lua /usr/local/liblua /usr/local /opt /usr /usr/lib64 /opt/local"
16+
17+
# Variables to be set by this very own script.
18+
LUA_CFLAGS=""
19+
LUA_LDFLAGS=""
20+
LUA_LDADD=""
21+
LUA_DISPLAY=""
22+
23+
AC_ARG_WITH(
24+
lua,
25+
AC_HELP_STRING(
26+
[--with-lua=PATH],
27+
[Path to lua prefix]
28+
)
29+
)
30+
31+
32+
if test "x${with_lua}" == "xno"; then
33+
AC_DEFINE(HAVE_LUA, 0, [Support for LUA was disabled by the utilization of --without-lua or --with-lua=no])
34+
AC_MSG_NOTICE([Support for LUA was disabled by the utilization of --without-lua or --with-lua=no])
35+
LUA_DISABLED=yes
36+
else
37+
if test "x${with_lua}" == "xyes"; then
38+
LUA_MANDATORY=yes
39+
AC_MSG_NOTICE([LUA support was marked as mandatory by the utilization of --with-lua=yes])
40+
else
41+
LUA_MANDATORY=no
42+
fi
43+
for x in ${LUA_POSSIBLE_PATHS}; do
44+
CHECK_FOR_LUA_AT(${x})
45+
if test -n "${LUA_CFLAGS}"; then
46+
break
47+
fi
48+
done
49+
fi
50+
51+
52+
if test -z "${LUA_CFLAGS}"; then
53+
if test -z "${LUA_MANDATORY}" || test "x${LUA_MANDATORY}" == "xno"; then
54+
if test -z "${LUA_DISABLED}"; then
55+
AC_MSG_NOTICE([LUA library was not found])
56+
LUA_FOUND=0
57+
else
58+
LUA_FOUND=2
59+
fi
60+
else
61+
AC_MSG_ERROR([LUA was explicitly referenced but it was not found])
62+
LUA_FOUND=-1
63+
fi
64+
else
65+
if test -z "${LUA_MANDATORY}" || test "x${LUA_MANDATORY}" == "xno"; then
66+
LUA_FOUND=2
67+
AC_MSG_NOTICE([LUA is disabled by default.])
68+
else
69+
LUA_FOUND=1
70+
AC_MSG_NOTICE([using LUA v${LUA_VERSION}])
71+
LUA_CFLAGS="-DWITH_LUA ${LUA_CFLAGS}"
72+
LUA_DISPLAY="${LUA_LDADD} ${LUA_LDFLAGS}, ${LUA_CFLAGS}"
73+
AC_SUBST(LUA_LDFLAGS)
74+
AC_SUBST(LUA_LDADD)
75+
AC_SUBST(LUA_CFLAGS)
76+
AC_SUBST(LUA_DISPLAY)
77+
fi
78+
fi
79+
80+
81+
AC_SUBST(LUA_FOUND)
82+
83+
]) # AC_DEFUN [CHECK_LUA]
84+
85+
86+
AC_DEFUN([CHECK_FOR_LUA_AT], [
87+
path=$1
88+
echo "*** LOOKING AT PATH: " ${path}
89+
for y in ${LUA_POSSIBLE_EXTENSIONS}; do
90+
for z in ${LUA_POSSIBLE_LIB_NAMES}; do
91+
if test -e "${path}/${z}.${y}"; then
92+
lua_lib_path="${path}/"
93+
lua_lib_name="${z}"
94+
lua_lib_file="${lua_lib_path}/${z}.${y}"
95+
break
96+
fi
97+
if test -e "${path}/lib${z}.${y}"; then
98+
lua_lib_path="${path}/"
99+
lua_lib_name="${z}"
100+
lua_lib_file="${lua_lib_path}/lib${z}.${y}"
101+
break
102+
fi
103+
if test -e "${path}/lib/lib${z}.${y}"; then
104+
lua_lib_path="${path}/lib/"
105+
lua_lib_name="${z}"
106+
lua_lib_file="${lua_lib_path}/lib${z}.${y}"
107+
break
108+
fi
109+
if test -e "${path}/lib/x86_64-linux-gnu/lib${z}.${y}"; then
110+
lua_lib_path="${path}/lib/x86_64-linux-gnu/"
111+
lua_lib_name="${z}"
112+
lua_lib_file="${lua_lib_path}/lib${z}.${y}"
113+
break
114+
fi
115+
if test -e "${path}/lib/i386-linux-gnu/lib${z}.${y}"; then
116+
lua_lib_path="${path}/lib/i386-linux-gnu/"
117+
lua_lib_name="${z}"
118+
lua_lib_file="${lua_lib_path}/lib${z}.${y}"
119+
break
120+
fi
121+
done
122+
if test -n "$lua_lib_path"; then
123+
break
124+
fi
125+
done
126+
if test -e "${path}/include/fuzzy.h"; then
127+
lua_inc_path="${path}/include"
128+
elif test -e "${path}/fuzzy.h"; then
129+
lua_inc_path="${path}"
130+
elif test -e "${path}/include/fuzzy/fuzzy.h"; then
131+
lua_inc_path="${path}/include"
132+
fi
133+
134+
if test -n "${lua_lib_path}"; then
135+
AC_MSG_NOTICE([LUA library found at: ${lua_lib_file}])
136+
fi
137+
138+
if test -n "${lua_inc_path}"; then
139+
AC_MSG_NOTICE([LUA headers found at: ${lua_inc_path}])
140+
fi
141+
142+
if test -n "${lua_lib_path}" -a -n "${lua_inc_path}"; then
143+
# TODO: Compile a piece of code to check the version.
144+
LUA_CFLAGS="-I${lua_inc_path}"
145+
LUA_LDADD="-l${lua_lib_name}"
146+
LUA_LDFLAGS="-L${lua_lib_path}"
147+
LUA_DISPLAY="${lua_lib_file}, ${lua_inc_path}"
148+
fi
149+
]) # AC_DEFUN [CHECK_FOR_LUA_AT]
150+
151+
152+

configure.ac

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ AM_CONDITIONAL([LMDB_CFLAGS], [test "LMDB_CFLAGS" != ""])
9090
CHECK_SSDEEP
9191
AM_CONDITIONAL([SSDEEP_CFLAGS], [test "SSDEEP_CFLAGS" != ""])
9292

93+
# Check for LUA
94+
CHECK_LUA
95+
AM_CONDITIONAL([LUA_CFLAGS], [test "LUA_CFLAGS" != ""])
96+
97+
9398
#
9499
# Check for curl
95100
#
@@ -504,6 +509,23 @@ if test "x$SSDEEP_FOUND" = "x2"; then
504509
echo " + SSDEEP ....disabled"
505510
fi
506511

512+
## LUA
513+
if test "x$LUA_FOUND" = "x0"; then
514+
echo " + LUA ....not found"
515+
fi
516+
if test "x$LUA_FOUND" = "x1"; then
517+
echo -n " + LUA ....found "
518+
if ! test "x$LUA_VERSION" = "x"; then
519+
echo "v${LUA_VERSION}"
520+
else
521+
echo ""
522+
fi
523+
echo " ${LUA_DISPLAY}"
524+
fi
525+
if test "x$LUA_FOUND" = "x2"; then
526+
echo " + LUA ....disabled"
527+
fi
528+
507529

508530
echo " "
509531
echo " Other Options"

examples/multiprocess_c/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ multi_LDADD = \
1212
$(YAJL_LDFLAGS) \
1313
$(GEOIP_LDFLAGS) \
1414
$(SSDEEP_LDFLAGS) $(SSDEEP_LDADD) \
15+
$(LUA_LDFLAGS) $(LUA_LDADD) \
1516
$(GLOBAL_LDADD)
1617

1718
multi_CFLAGS = \

examples/reading_logs_via_rule_message/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ simple_request_LDADD = \
1414
$(YAJL_LDFLAGS) $(YAJL_LDADD) \
1515
$(LMDB_LDFLAGS) $(LMDB_LDADD) \
1616
$(SSDEEP_LDFLAGS) $(SSDEEP_LDADD) \
17+
$(LUA_LDFLAGS) $(LUA_LDADD) \
1718
$(LIBXML2_LDADD) \
1819
$(GLOBAL_LDADD)
1920

@@ -32,6 +33,7 @@ simple_request_CPPFLAGS = \
3233
$(MODSEC_NO_LOGS) \
3334
$(YAJL_CFLAGS) \
3435
$(LMDB_CFLAGS) \
36+
$(LUA_CFLAGS) \
3537
$(PCRE_CFLAGS) \
3638
$(LIBXML2_CFLAGS)
3739

examples/reading_logs_with_offset/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ read_LDADD = \
1313
$(YAJL_LDFLAGS) $(YAJL_LDADD) \
1414
$(LMDB_LDFLAGS) $(LMDB_LDADD) \
1515
$(SSDEEP_LDFLAGS) $(SSDEEP_LDADD) \
16+
$(LUA_LDFLAGS) $(LUA_LDADD) \
1617
$(LIBXML2_LDADD) \
1718
$(GLOBAL_LDADD)
1819

@@ -31,6 +32,7 @@ read_CPPFLAGS = \
3132
$(MODSEC_NO_LOGS) \
3233
$(YAJL_CFLAGS) \
3334
$(LMDB_CFLAGS) \
35+
$(LUA_CFLAGS) \
3436
$(PCRE_CFLAGS) \
3537
$(LIBXML2_CFLAGS)
3638

examples/simple_example_using_c/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ test_LDADD = \
1111
$(YAJL_LDFLAGS) \
1212
$(GEOIP_LDFLAGS) \
1313
$(SSDEEP_LDFLAGS) $(SSDEEP_LDADD) \
14+
$(LUA_LDFLAGS) $(LUA_LDADD) \
1415
$(GLOBAL_LDADD)
1516

1617
test_CFLAGS = \

examples/using_bodies_in_chunks/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ simple_request_LDADD = \
1414
$(YAJL_LDFLAGS) $(YAJL_LDADD) \
1515
$(LMDB_LDFLAGS) $(LMDB_LDADD) \
1616
$(SSDEEP_LDFLAGS) $(SSDEEP_LDADD) \
17+
$(LUA_LDFLAGS) $(LUA_LDADD) \
1718
$(LIBXML2_LDADD) \
1819
$(GLOBAL_LDADD)
1920

@@ -32,6 +33,7 @@ simple_request_CPPFLAGS = \
3233
$(MODSEC_NO_LOGS) \
3334
$(YAJL_CFLAGS) \
3435
$(LMDB_CFLAGS) \
36+
$(LUA_CFLAGS) \
3537
$(PCRE_CFLAGS) \
3638
$(LIBXML2_CFLAGS)
3739

src/Makefile.am

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ noinst_HEADERS = \
7878
*.h
7979

8080

81+
ENGINES = \
82+
engines/lua.cc
83+
84+
8185
VARIABLES = \
8286
variables/duration.cc \
8387
variables/env.cc \
@@ -273,6 +277,7 @@ libmodsecurity_la_SOURCES = \
273277
rules_exceptions.cc \
274278
${BODY_PROCESSORS} \
275279
${ACTIONS} \
280+
${ENGINES} \
276281
${COLLECTION} \
277282
${OPERATORS} \
278283
${UTILS} \
@@ -298,6 +303,7 @@ libmodsecurity_la_CPPFLAGS = \
298303
$(LMDB_CFLAGS) \
299304
$(PCRE_CFLAGS) \
300305
$(SSDEEP_CFLAGS) \
306+
$(LUA_CFLAGS) \
301307
$(LIBXML2_CFLAGS)
302308

303309
libmodsecurity_la_LIBADD = \
@@ -308,6 +314,7 @@ libmodsecurity_la_LIBADD = \
308314
$(YAJL_LDFLAGS) $(YAJL_LDADD) \
309315
$(LMDB_LDFLAGS) $(LMDB_LDADD) \
310316
$(SSDEEP_LDFLAGS) $(SSDEEP_LDADD) \
317+
$(LUA_LDFLAGS) $(LUA_LDADD) \
311318
$(LIBXML2_LDADD) \
312319
../others/libinjection.la \
313320
../others/libmbedtls.la

src/engines/lua.cc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* ModSecurity, http://www.modsecurity.org/
3+
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
4+
*
5+
* You may not use this file except in compliance with
6+
* the License. You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* If any of the files related to licensing are missing or if you have any
11+
* other questions related to licensing please contact Trustwave Holdings, Inc.
12+
* directly using the email address security@modsecurity.org.
13+
*
14+
*/
15+
16+
17+
#include "modsecurity/modsecurity.h"
18+
#include "src/engines/lua.h"
19+
20+
21+
#ifdef WITH_LUA
22+
#include <lua.hpp>
23+
24+
25+
#endif
26+
27+
#ifndef SRC_ENGINES_LUA_H_
28+
#define SRC_ENGINES_LUA_H_
29+
30+
31+
32+
#endif // SRC_ENGINES_LUA_H_

src/engines/lua.h

Whitespace-only changes.

0 commit comments

Comments
 (0)