Skip to content

Commit 61427f9

Browse files
zimmerleWGH-
authored andcommitted
Makes re2 detectable by the build scripts
1 parent 18f0e6d commit 61427f9

File tree

13 files changed

+299
-28
lines changed

13 files changed

+299
-28
lines changed

build/re2.m4

+166
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
dnl Check for RE2 Libraries
2+
dnl CHECK_RE2(ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND])
3+
4+
AC_DEFUN([PROG_RE2], [
5+
6+
# Needed if pkg-config will be used.
7+
AC_REQUIRE([PKG_PROG_PKG_CONFIG])
8+
9+
# Possible names for the re2 library/package (pkg-config)
10+
RE2_POSSIBLE_LIB_NAMES="re2"
11+
12+
# Possible extensions for the library
13+
RE2_POSSIBLE_EXTENSIONS="so la sl dll dylib"
14+
15+
# Possible paths (if pkg-config was not found, proceed with the file lookup)
16+
RE2_POSSIBLE_PATHS="/usr/lib /usr/local/lib /usr/local/libre2 /usr/local/re2 /usr/local /opt/libre2 /opt/re2 /opt /usr /usr/lib64"
17+
18+
# Variables to be set by this very own script.
19+
RE2_VERSION=""
20+
RE2_CFLAGS=""
21+
RE2_CPPFLAGS=""
22+
RE2_LDADD=""
23+
RE2_LDFLAGS=""
24+
25+
AC_ARG_WITH(
26+
re2,
27+
AC_HELP_STRING(
28+
[--with-re2=PATH],
29+
[Path to re2 prefix or config script]
30+
)
31+
)
32+
33+
if test "x${with_re2}" == "xno"; then
34+
AC_DEFINE(HAVE_RE2, 0, [Support for RE2 was disabled by the utilization of --without-re2 or --with-re2=no])
35+
AC_MSG_NOTICE([Support for RE2 was disabled by the utilization of --without-re2 or --with-re2=no])
36+
RE2_DISABLED=yes
37+
else
38+
if test "x${with_re2}" == "xyes"; then
39+
RE2_MANDATORY=yes
40+
AC_MSG_NOTICE([RE2 support was marked as mandatory by the utilization of --with-re2=yes])
41+
fi
42+
if test "x${with_re2}" == "x" || test "x${with_re2}" == "xyes"; then
43+
# Nothing about RE2 was informed, using the pkg-config to figure things out.
44+
if test -n "${PKG_CONFIG}"; then
45+
RE2_PKG_NAME=""
46+
for x in ${RE2_POSSIBLE_LIB_NAMES}; do
47+
if ${PKG_CONFIG} --exists ${x}; then
48+
RE2_PKG_NAME="$x"
49+
break
50+
fi
51+
done
52+
fi
53+
AC_MSG_NOTICE([Nothing about RE2 was informed during the configure phase. Trying to detect it on the platform...])
54+
if test -n "${RE2_PKG_NAME}"; then
55+
# Package was found using the pkg-config scripts
56+
RE2_VERSION="`${PKG_CONFIG} ${RE2_PKG_NAME} --modversion`"
57+
RE2_CFLAGS="`${PKG_CONFIG} ${RE2_PKG_NAME} --cflags`"
58+
RE2_LDADD="`${PKG_CONFIG} ${RE2_PKG_NAME} --libs-only-l`"
59+
RE2_LDFLAGS="`${PKG_CONFIG} ${RE2_PKG_NAME} --libs-only-L --libs-only-other`"
60+
RE2_DISPLAY="${RE2_LDADD}, ${RE2_CFLAGS}"
61+
else
62+
# If pkg-config did not find anything useful, go over file lookup.
63+
for x in ${RE2_POSSIBLE_PATHS}; do
64+
CHECK_FOR_RE2_AT(${x})
65+
if test -n "${RE2_VERSION}"; then
66+
break
67+
fi
68+
done
69+
fi
70+
fi
71+
if test "x${with_re2}" != "x"; then
72+
# An specific path was informed, lets check.
73+
RE2_MANDATORY=yes
74+
CHECK_FOR_RE2_AT(${with_re2})
75+
fi
76+
fi
77+
78+
if test -z "${RE2_LDADD}"; then
79+
if test -z "${RE2_MANDATORY}"; then
80+
if test -z "${RE2_DISABLED}"; then
81+
AC_MSG_NOTICE([RE2 library was not found])
82+
RE2_FOUND=0
83+
else
84+
RE2_FOUND=2
85+
fi
86+
else
87+
AC_MSG_ERROR([RE2 was explicitly referenced but it was not found])
88+
RE2_FOUND=-1
89+
fi
90+
else
91+
RE2_FOUND=1
92+
AC_MSG_NOTICE([using RE2 v${RE2_VERSION}])
93+
RE2_CFLAGS="-DWITH_RE2 ${RE2_CFLAGS}"
94+
RE2_DISPLAY="${RE2_LDADD}, ${RE2_CFLAGS}"
95+
AC_SUBST(RE2_VERSION)
96+
AC_SUBST(RE2_LDADD)
97+
AC_SUBST(RE2_LIBS)
98+
AC_SUBST(RE2_LDFLAGS)
99+
AC_SUBST(RE2_CFLAGS)
100+
AC_SUBST(RE2_DISPLAY)
101+
fi
102+
103+
104+
105+
AC_SUBST(RE2_FOUND)
106+
107+
]) # AC_DEFUN [PROG_RE2]
108+
109+
110+
AC_DEFUN([CHECK_FOR_RE2_AT], [
111+
path=$1
112+
for y in ${RE2_POSSIBLE_EXTENSIONS}; do
113+
for z in ${RE2_POSSIBLE_LIB_NAMES}; do
114+
if test -e "${path}/${z}.${y}"; then
115+
re2_lib_path="${path}/"
116+
re2_lib_name="${z}"
117+
re2_lib_file="${re2_lib_path}/${z}.${y}"
118+
break
119+
fi
120+
if test -e "${path}/lib${z}.${y}"; then
121+
re2_lib_path="${path}/"
122+
re2_lib_name="${z}"
123+
re2_lib_file="${re2_lib_path}/lib${z}.${y}"
124+
break
125+
fi
126+
if test -e "${path}/lib/lib${z}.${y}"; then
127+
re2_lib_path="${path}/lib/"
128+
re2_lib_name="${z}"
129+
re2_lib_file="${re2_lib_path}/lib${z}.${y}"
130+
break
131+
fi
132+
if test -e "${path}/lib/x86_64-linux-gnu/lib${z}.${y}"; then
133+
re2_lib_path="${path}/lib/x86_64-linux-gnu/"
134+
re2_lib_name="${z}"
135+
re2_lib_file="${re2_lib_path}/lib${z}.${y}"
136+
break
137+
fi
138+
done
139+
if test -n "$re2_lib_path"; then
140+
break
141+
fi
142+
done
143+
if test -e "${path}/include/re2.h"; then
144+
re2_inc_path="${path}/include"
145+
elif test -e "${path}/re2.h"; then
146+
re2_inc_path="${path}"
147+
elif test -e "${path}/include/re2/re2.h"; then
148+
re2_inc_path="${path}/include"
149+
fi
150+
151+
if test -n "${re2_lib_path}"; then
152+
AC_MSG_NOTICE([RE2 library found at: ${re2_lib_file}])
153+
fi
154+
155+
if test -n "${re2_inc_path}"; then
156+
AC_MSG_NOTICE([RE2 headers found at: ${re2_inc_path}])
157+
fi
158+
159+
if test -n "${re2_lib_path}" -a -n "${re2_inc_path}"; then
160+
# TODO: Compile a piece of code to check the version.
161+
RE2_CFLAGS="-I${re2_inc_path}"
162+
RE2_LDADD="-l${re2_lib_name}"
163+
RE2_LDFLAGS="-L${re2_lib_path}"
164+
RE2_DISPLAY="${re2_lib_file}, ${re2_inc_path}"
165+
fi
166+
]) # AC_DEFUN [CHECK_FOR_RE2_AT]

configure.ac

+65
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ AM_CONDITIONAL([SSDEEP_CFLAGS], [test "SSDEEP_CFLAGS" != ""])
105105
CHECK_LUA
106106
AM_CONDITIONAL([LUA_CFLAGS], [test "LUA_CFLAGS" != ""])
107107

108+
# Check for RE2
109+
PROG_RE2
110+
AM_CONDITIONAL([RE2_CFLAGS], [test "RE2_CFLAGS" != ""])
108111

109112
#
110113
# Check for curl
@@ -549,6 +552,68 @@ if test "x$LUA_FOUND" = "x2"; then
549552
fi
550553

551554

555+
## REGEX
556+
echo " + Regular expression engine"
557+
558+
REGEX_SELECTED_RE2=" "
559+
REGEX_SELECTED_PCRE=" "
560+
561+
if test "x$RE2_FOUND" = "x1"; then
562+
MSC_REGEX_ENG="re2"
563+
fi
564+
if test "x$PCRE_FOUND" = "x1"; then
565+
MSC_REGEX_ENG="pcre"
566+
fi
567+
568+
AC_SUBST(MSC_REGEX_ENG)
569+
570+
if test "x$MSC_REGEX_ENG" = "xpcre"; then
571+
MSC_REGEX_ENG_IS_PCRE=1
572+
REGEX_SELECTED_PCRE="[[selected]]"
573+
AC_SUBST(MSC_REGEX_ENG_IS_PCRE)
574+
fi
575+
if test "x$MSC_REGEX_ENG" = "xre2"; then
576+
MSC_REGEX_ENG_IS_RE2=1
577+
REGEX_SELECTED_PCRE="[[selected]]"
578+
AC_SUBST(MSC_REGEX_ENG_IS_RE2)
579+
fi
580+
581+
582+
#### RE2
583+
if test "x$RE2_FOUND" = "x0"; then
584+
echo " * RE2 (experimental) ....not found"
585+
fi
586+
if test "x$RE2_FOUND" = "x1"; then
587+
echo -n " * RE2 (experimental) ${REGEX_SELECTED_RE2} ....found "
588+
if ! test "x$RE2_VERSION" = "x"; then
589+
echo "v${RE2_VERSION}"
590+
else
591+
echo ""
592+
fi
593+
echo " ${RE2_DISPLAY}"
594+
fi
595+
if test "x$RE2_FOUND" = "x2"; then
596+
echo " * RE2 (experimental) ....disabled"
597+
fi
598+
599+
#### PCRE
600+
if test "x$PCRE_FOUND" = "x0"; then
601+
echo " * PCRE ....not found"
602+
fi
603+
if test "x$PCRE_FOUND" = "x1"; then
604+
echo -n " * PCRE ${REGEX_SELECTED_PCRE} ....found "
605+
if ! test "x$PCRE_VERSION" = "x"; then
606+
echo "v${PCRE_VERSION}"
607+
else
608+
echo ""
609+
fi
610+
echo " ${PCRE_DISPLAY}"
611+
fi
612+
if test "x$PCRE_FOUND" = "x2"; then
613+
echo " * PCRE ....disabled"
614+
fi
615+
616+
552617
echo " "
553618
echo " Other Options"
554619
if test $buildTestUtilities = true; then

examples/reading_logs_via_rule_message/Makefile.am

+6-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ simple_request_LDADD = \
1515
$(LUA_LDADD) \
1616
$(PCRE_LDADD) \
1717
$(SSDEEP_LDADD) \
18-
$(YAJL_LDADD)
18+
$(YAJL_LDADD) \
19+
$(RE2_LDADD)
1920

2021
simple_request_LDFLAGS = \
2122
-L$(top_builddir)/src/.libs/ \
@@ -28,7 +29,8 @@ simple_request_LDFLAGS = \
2829
$(LUA_LDFLAGS) \
2930
$(MAXMIND_LDFLAGS) \
3031
$(SSDEEP_LDFLAGS) \
31-
$(YAJL_LDFLAGS)
32+
$(YAJL_LDFLAGS) \
33+
$(RE2_LDFLAGS)
3234

3335
simple_request_CPPFLAGS = \
3436
$(GLOBAL_CFLAGS) \
@@ -46,7 +48,8 @@ simple_request_CPPFLAGS = \
4648
$(LMDB_CFLAGS) \
4749
$(LUA_CFLAGS) \
4850
$(PCRE_CFLAGS) \
49-
$(LIBXML2_CFLAGS)
51+
$(LIBXML2_CFLAGS) \
52+
$(RE2_CFLAGS)
5053

5154

5255
MAINTAINERCLEANFILES = \

examples/reading_logs_with_offset/Makefile.am

+6-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ read_LDADD = \
1515
$(LUA_LDADD) \
1616
$(PCRE_LDADD) \
1717
$(SSDEEP_LDADD) \
18-
$(YAJL_LDADD)
18+
$(YAJL_LDADD) \
19+
$(RE2_LDADD)
1920

2021
read_LDFLAGS = \
2122
-L$(top_builddir)/src/.libs/ \
@@ -28,7 +29,8 @@ read_LDFLAGS = \
2829
$(LUA_LDFLAGS) \
2930
$(SSDEEP_LDFLAGS) \
3031
$(MAXMIND_LDFLAGS) \
31-
$(YAJL_LDFLAGS)
32+
$(YAJL_LDFLAGS) \
33+
$(RE2_LDFLAGS)
3234

3335
read_CPPFLAGS = \
3436
$(GLOBAL_CFLAGS) \
@@ -47,7 +49,8 @@ read_CPPFLAGS = \
4749
$(LMDB_CFLAGS) \
4850
$(LUA_CFLAGS) \
4951
$(PCRE_CFLAGS) \
50-
$(LIBXML2_CFLAGS)
52+
$(LIBXML2_CFLAGS) \
53+
$(RE2_CFLAGS)
5154

5255

5356
MAINTAINERCLEANFILES = \

examples/using_bodies_in_chunks/Makefile.am

+6-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ simple_request_LDADD = \
1515
$(LUA_LDADD) \
1616
$(PCRE_LDADD) \
1717
$(SSDEEP_LDADD) \
18-
$(YAJL_LDADD)
18+
$(YAJL_LDADD) \
19+
$(RE2_LDADD)
1920

2021
simple_request_LDFLAGS = \
2122
-L$(top_builddir)/src/.libs/ \
@@ -29,7 +30,8 @@ simple_request_LDFLAGS = \
2930
-lpthread \
3031
$(LUA_LDFLAGS) \
3132
$(SSDEEP_LDFLAGS) \
32-
$(YAJL_LDFLAGS)
33+
$(YAJL_LDFLAGS) \
34+
$(RE2_LDFLAGS)
3335

3436
simple_request_CPPFLAGS = \
3537
$(GLOBAL_CFLAGS) \
@@ -48,7 +50,8 @@ simple_request_CPPFLAGS = \
4850
$(LMDB_CFLAGS) \
4951
$(LUA_CFLAGS) \
5052
$(PCRE_CFLAGS) \
51-
$(LIBXML2_CFLAGS)
53+
$(LIBXML2_CFLAGS) \
54+
$(RE2_CFLAGS)
5255

5356
MAINTAINERCLEANFILES = \
5457
Makefile.in

src/Makefile.am

+5-2
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,8 @@ libmodsecurity_la_CPPFLAGS = \
328328
$(SSDEEP_CFLAGS) \
329329
$(MAXMIND_CFLAGS) \
330330
$(LUA_CFLAGS) \
331-
$(LIBXML2_CFLAGS)
331+
$(LIBXML2_CFLAGS) \
332+
$(RE2_CFLAGS)
332333

333334

334335
libmodsecurity_la_LDFLAGS = \
@@ -343,6 +344,7 @@ libmodsecurity_la_LDFLAGS = \
343344
$(SSDEEP_LDFLAGS) \
344345
$(MAXMIND_LDFLAGS) \
345346
$(YAJL_LDFLAGS) \
347+
$(RE2_LDFLAGS) \
346348
-version-info @MSC_VERSION_INFO@
347349

348350

@@ -358,5 +360,6 @@ libmodsecurity_la_LIBADD = \
358360
$(PCRE_LDADD) \
359361
$(MAXMIND_LDADD) \
360362
$(SSDEEP_LDADD) \
361-
$(YAJL_LDADD)
363+
$(YAJL_LDADD) \
364+
$(RE2_LDADD)
362365

src/parser/Makefile.am

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ libmodsec_parser_la_CPPFLAGS = \
2626
$(YAJL_CFLAGS) \
2727
$(LMDB_CFLAGS) \
2828
$(PCRE_CFLAGS) \
29-
$(LIBXML2_CFLAGS)
29+
$(LIBXML2_CFLAGS) \
30+
$(RE2_CFLAGS)
3031

3132
test.cc: seclang-parser.hh
3233
cat seclang-parser.hh | sed "s/return \*new (yyas_<T> ()) T (t)/return *new (yyas_<T> ()) T (std::move((T\&)t))/g" > seclang-parser.hh.fix && mv seclang-parser.hh.fix seclang-parser.hh

src/regex/backend/pcre.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <fstream>
1919
#include <string>
2020
#include <list>
21-
#include <pcre.h>
21+
2222

2323
#include "src/regex/backend/pcre.h"
2424
#include "src/regex/regex_match.h"
@@ -28,6 +28,7 @@ namespace modsecurity {
2828
namespace regex {
2929
namespace backend {
3030

31+
#ifdef WITH_PCRE
3132

3233
#if PCRE_HAVE_JIT
3334
#define pcre_study_opt PCRE_STUDY_JIT_COMPILE
@@ -140,6 +141,7 @@ int Pcre::search(const std::string& s) const {
140141
s.size(), 0, 0, ovector, OVECCOUNT) > 0;
141142
}
142143

144+
#endif
143145

144146
} // namespace backend
145147
} // namespace regex

0 commit comments

Comments
 (0)