Skip to content

Commit df169ea

Browse files
author
Felipe Zimmerle
committed
Adds support for libMaxMind
1 parent 7bff76d commit df169ea

File tree

20 files changed

+845
-115
lines changed

20 files changed

+845
-115
lines changed

build/libmaxmind.m4

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
dnl Check for MAXMIND Libraries
2+
dnl CHECK_MAXMIND(ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND])
3+
dnl Sets:
4+
dnl MAXMIND_CFLAGS
5+
dnl MAXMIND_LDADD
6+
dnl MAXMIND_LDFLAGS
7+
dnl MAXMIND_LIBS
8+
dnl MAXMIND_VERSION
9+
10+
AC_DEFUN([PROG_MAXMIND], [
11+
12+
13+
# Needed if pkg-config will be used.
14+
AC_REQUIRE([PKG_PROG_PKG_CONFIG])
15+
16+
17+
# Possible names for the maxmind library/package (pkg-config)
18+
MAXMIND_POSSIBLE_LIB_NAMES="libmaxminddb maxminddb maxmind"
19+
20+
# Possible extensions for the library
21+
MAXMIND_POSSIBLE_EXTENSIONS="so la sl dll dylib"
22+
23+
# Possible paths (if pkg-config was not found, proceed with the file lookup)
24+
MAXMIND_POSSIBLE_PATHS="/usr/local/libmaxmind /usr/local/maxmind /usr/local /opt/libmaxmind /opt/maxmind /opt /usr /opt/local/include /opt/local /usr/lib /usr/local/lib /usr/lib64 /usr"
25+
26+
# Variables to be set by this very own script.
27+
MAXMIND_VERSION=""
28+
MAXMIND_CFLAGS=""
29+
MAXMIND_CPPFLAGS=""
30+
MAXMIND_LDADD=""
31+
MAXMIND_LDFLAGS=""
32+
33+
AC_ARG_WITH(
34+
maxmind,
35+
AS_HELP_STRING(
36+
[--with-maxmind=PATH],
37+
[Path to MaxMind (including headers). Use 'no' to disable MaxMind support.]
38+
)
39+
)
40+
41+
# AS_HELP_STRING(
42+
# [--without-maxmind],
43+
# [Complete dsiables MaxMind support]
44+
# )
45+
46+
47+
if test "x${with_maxmind}" == "xno"; then
48+
AC_DEFINE(HAVE_MAXMIND, 0, [Support for MaxMind was disabled by the utilization of --without-maxmind or --with-maxmind=no])
49+
AC_MSG_NOTICE([Support for MaxMind was disabled by the utilization of --without-maxmind or --with-maxmind=no])
50+
MAXMIND_DISABLED=yes
51+
else
52+
if test "x${with_maxmind}" == "xyes"; then
53+
MAXMIND_MANDATORY=yes
54+
AC_MSG_NOTICE([MaxMind support was marked as mandatory by the utilization of --with-maxmind=yes])
55+
fi
56+
# for x in ${MAXMIND_POSSIBLE_LIB_NAMES}; do
57+
# CHECK_FOR_MAXMIND_AT(${x})
58+
# if test -n "${MAXMIND_VERSION}"; then
59+
# break
60+
# fi
61+
# done
62+
63+
# if test "x${with_maxmind}" != "xyes" or test "x${with_maxmind}" == "xyes"; then
64+
if test "x${with_maxmind}" == "x" || test "x${with_maxmind}" == "xyes"; then
65+
# Nothing about MaxMind was informed, using the pkg-config to figure things out.
66+
if test -n "${PKG_CONFIG}"; then
67+
MAXMIND_PKG_NAME=""
68+
for x in ${MAXMIND_POSSIBLE_LIB_NAMES}; do
69+
if ${PKG_CONFIG} --exists ${x}; then
70+
MAXMIND_PKG_NAME="$x"
71+
break
72+
fi
73+
done
74+
fi
75+
AC_MSG_NOTICE([Nothing about MaxMind was informed during the configure phase. Trying to detect it on the platform...])
76+
if test -n "${MAXMIND_PKG_NAME}"; then
77+
# Package was found using the pkg-config scripts
78+
MAXMIND_VERSION="`${PKG_CONFIG} ${MAXMIND_PKG_NAME} --modversion`"
79+
MAXMIND_CFLAGS="`${PKG_CONFIG} ${MAXMIND_PKG_NAME} --cflags`"
80+
MAXMIND_LDADD="`${PKG_CONFIG} ${MAXMIND_PKG_NAME} --libs-only-l`"
81+
MAXMIND_LDFLAGS="`${PKG_CONFIG} ${MAXMIND_PKG_NAME} --libs-only-L --libs-only-other`"
82+
MAXMIND_DISPLAY="${MAXMIND_LDADD}"
83+
else
84+
# If pkg-config did not find anything useful, go over file lookup.
85+
for x in ${MAXMIND_POSSIBLE_PATHS}; do
86+
CHECK_FOR_MAXMIND_AT(${x})
87+
if test -n "${MAXMIND_VERSION}"; then
88+
break
89+
fi
90+
done
91+
fi
92+
fi
93+
if test "x${with_maxmind}" != "x"; then
94+
# An specific path was informed, lets check.
95+
MAXMIND_MANDATORY=yes
96+
CHECK_FOR_MAXMIND_AT(${with_maxmind})
97+
fi
98+
# fi
99+
fi
100+
101+
if test -z "${MAXMIND_DISPLAY}"; then
102+
if test -z "${MAXMIND_MANDATORY}"; then
103+
if test -z "${MAXMIND_DISABLED}"; then
104+
AC_MSG_NOTICE([MaxMind library was not found])
105+
MAXMIND_FOUND=0
106+
else
107+
MAXMIND_FOUND=2
108+
fi
109+
else
110+
AC_MSG_ERROR([MaxMind was explicit requested but it was not found])
111+
MAXMIND_FOUND=-1
112+
fi
113+
else
114+
MAXMIND_FOUND=1
115+
AC_MSG_NOTICE([using MaxMind v${MAXMIND_VERSION}])
116+
MAXMIND_CFLAGS="-DWITH_MAXMIND ${MAXMIND_CFLAGS}"
117+
if ! test "x$MAXMIND_CFLAGS" = "x"; then
118+
MAXMIND_DISPLAY="${MAXMIND_DISPLAY}, ${MAXMIND_CFLAGS}"
119+
fi
120+
AC_SUBST(MAXMIND_VERSION)
121+
AC_SUBST(MAXMIND_LDADD)
122+
AC_SUBST(MAXMIND_LIBS)
123+
AC_SUBST(MAXMIND_LDFLAGS)
124+
AC_SUBST(MAXMIND_CFLAGS)
125+
AC_SUBST(MAXMIND_DISPLAY)
126+
fi
127+
128+
129+
130+
AC_SUBST(MAXMIND_FOUND)
131+
132+
]) # AC_DEFUN [PROG_MAXMIND]
133+
134+
135+
AC_DEFUN([CHECK_FOR_MAXMIND_AT], [
136+
path=$1
137+
for y in ${MAXMIND_POSSIBLE_EXTENSIONS}; do
138+
for z in ${MAXMIND_POSSIBLE_LIB_NAMES}; do
139+
if test -e "${path}/${z}.${y}"; then
140+
maxmind_lib_path="${path}/"
141+
maxmind_lib_name="${z}"
142+
maxmind_lib_file="${maxmind_lib_path}/${z}.${y}"
143+
break
144+
fi
145+
if test -e "${path}/lib${z}.${y}"; then
146+
maxmind_lib_path="${path}/"
147+
maxmind_lib_name="${z}"
148+
maxmind_lib_file="${maxmind_lib_path}/lib${z}.${y}"
149+
break
150+
fi
151+
if test -e "${path}/lib/lib${z}.${y}"; then
152+
maxmind_lib_path="${path}/lib/"
153+
maxmind_lib_name="${z}"
154+
maxmind_lib_file="${maxmind_lib_path}/lib${z}.${y}"
155+
break
156+
fi
157+
if test -e "${path}/lib64/lib${z}.${y}"; then
158+
maxmind_lib_path="${path}/lib64/"
159+
maxmind_lib_name="${z}"
160+
maxmind_lib_file="${maxmind_lib_path}/lib${z}.${y}"
161+
break
162+
fi
163+
if test -e "${path}/lib/x86_64-linux-gnu/lib${z}.${y}"; then
164+
maxmind_lib_path="${path}/lib/x86_64-linux-gnu/"
165+
maxmind_lib_name="${z}"
166+
maxmind_lib_file="${maxmind_lib_path}/lib${z}.${y}"
167+
break
168+
fi
169+
done
170+
if test -n "$maxmind_lib_path"; then
171+
break
172+
fi
173+
done
174+
if test -e "${path}/include/maxminddb.h"; then
175+
maxmind_inc_path="${path}/include"
176+
elif test -e "${path}/maxminddb.h"; then
177+
maxmind_inc_path="${path}"
178+
fi
179+
180+
181+
if test -n "${maxmind_inc_path}" -a -n "${maxmind_lib_path}"; then
182+
183+
AC_MSG_NOTICE([MaxMind headers found at: ${maxmind_inc_path}])
184+
AC_MSG_NOTICE([MaxMind library found at: ${maxmind_lib_file}])
185+
fi
186+
187+
if test -n "${maxmind_lib_path}" -a -n "${maxmind_inc_path}"; then
188+
# TODO: Compile a piece of code to check the version.
189+
MAXMIND_CFLAGS="-I${maxmind_inc_path}"
190+
MAXMIND_LDADD="-l${maxmind_lib_name}"
191+
MAXMIND_LDFLAGS="-L${maxmind_lib_path}"
192+
MAXMIND_DISPLAY="${maxmind_lib_file}, ${maxmind_inc_path}"
193+
fi
194+
]) # AC_DEFUN [CHECK_FOR_MAXMIND_AT]

configure.ac

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ AM_CONDITIONAL([YAJL_VERSION], [test "$YAJL_VERSION" != ""])
8181
PROG_GEOIP
8282
AM_CONDITIONAL([GEOIP_CFLAGS], [test "GEOIP_CFLAGS" != ""])
8383

84+
# Check for MaxMind
85+
PROG_MAXMIND
86+
AM_CONDITIONAL([MAXMIND_CFLAGS], [test "MAXMIND_CFLAGS" != ""])
87+
8488

8589
# Check for LMDB
8690
PROG_LMDB
@@ -404,21 +408,26 @@ echo SECLANG_TEST_VERSION
404408
echo " "
405409
echo " Optional dependencies"
406410

407-
## GeoIP
408-
if test "x$GEOIP_FOUND" = "x0"; then
409-
echo " + GeoIP ....not found"
411+
412+
413+
## GeoIP - MaxMind
414+
if test "x$GEOIP_FOUND" = "x0" && test "x$MAXMIND_FOUND" = "x0"; then
415+
echo " + GeoIP/MaxMind ....not found"
410416
fi
411-
if test "x$GEOIP_FOUND" = "x1"; then
412-
echo -n " + GeoIP ....found "
413-
if ! test "x$GEOIP_VERSION" = "x"; then
414-
echo "v${GEOIP_VERSION}"
415-
else
416-
echo ""
417+
if test "x$GEOIP_FOUND" = "x1" || test "x$MAXMIND_FOUND" = "x1"; then
418+
echo -n " + GeoIP/MaxMind ....found "
419+
echo ""
420+
if test "x$MAXMIND_FOUND" = "x1"; then
421+
echo " * (MaxMind) v${MAXMIND_VERSION}"
422+
echo " ${MAXMIND_DISPLAY}"
423+
fi
424+
if test "x$GEOIP_FOUND" = "x1"; then
425+
echo " * (GeoIP) v${GEOIP_VERSION}"
426+
echo " ${GEOIP_DISPLAY}"
417427
fi
418-
echo " ${GEOIP_DISPLAY}"
419428
fi
420-
if test "x$GEOIP_FOUND" = "x2"; then
421-
echo " + GeoIP ....disabled"
429+
if test "x$GEOIP_FOUND" = "x2" && test "x$MAXMIND_FOUND" = "x2"; then
430+
echo " + GeoIP/MaxMind ....disabled"
422431
fi
423432

424433

examples/multiprocess_c/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ multi_SOURCES = \
88
multi_LDADD = \
99
$(SSDEEP_LDADD) \
1010
$(LUA_LDADD) \
11+
$(MAXMIND_LDADD) \
1112
$(GLOBAL_LDADD)
1213

1314
multi_LDFLAGS = \
@@ -19,6 +20,7 @@ multi_LDFLAGS = \
1920
-lstdc++ \
2021
$(LUA_LDFLAGS) \
2122
$(SSDEEP_LDFLAGS) \
23+
$(MAXMIND_LDFLAGS) \
2224
$(YAJL_LDFLAGS)
2325

2426
multi_CFLAGS = \

examples/reading_logs_via_rule_message/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ simple_request_LDADD = \
1212
$(GLOBAL_LDADD) \
1313
$(LIBXML2_LDADD) \
1414
$(LMDB_LDADD) \
15+
$(MAXMIND_LDADD) \
1516
$(LUA_LDADD) \
1617
$(PCRE_LDADD) \
1718
$(SSDEEP_LDADD) \
@@ -22,6 +23,7 @@ simple_request_LDFLAGS = \
2223
$(LMDB_LDFLAGS) \
2324
-lpthread \
2425
$(LUA_LDFLAGS) \
26+
$(MAXMIND_LDFLAGS) \
2527
$(SSDEEP_LDFLAGS) \
2628
$(YAJL_LDFLAGS)
2729

examples/reading_logs_with_offset/Makefile.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ read_LDADD = \
99
$(top_builddir)/src/.libs/libmodsecurity.a \
1010
$(CURL_LDADD) \
1111
$(GEOIP_LDADD) \
12+
$(MAXMIND_LDADD) \
1213
$(GLOBAL_LDADD) \
1314
$(LIBXML2_LDADD) \
1415
$(LMDB_LDADD) \
@@ -22,6 +23,7 @@ read_LDFLAGS = \
2223
$(LMDB_LDFLAGS) \
2324
$(LUA_LDFLAGS) \
2425
$(SSDEEP_LDFLAGS) \
26+
$(MAXMIND_LDFLAGS) \
2527
$(YAJL_LDFLAGS)
2628

2729
read_CPPFLAGS = \
@@ -34,6 +36,7 @@ read_CPPFLAGS = \
3436
-fPIC \
3537
-O3 \
3638
$(GEOIP_CFLAGS) \
39+
$(MAXMIND_CFLAGS) \
3740
$(GLOBAL_CPPFLAGS) \
3841
$(MODSEC_NO_LOGS) \
3942
$(YAJL_CFLAGS) \

examples/using_bodies_in_chunks/Makefile.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ simple_request_LDADD = \
99
$(top_builddir)/src/.libs/libmodsecurity.a \
1010
$(CURL_LDADD) \
1111
$(GEOIP_LDADD) \
12+
$(MAXMIND_LDADD) \
1213
$(GLOBAL_LDADD) \
1314
$(LIBXML2_LDADD) \
1415
$(LMDB_LDADD) \
@@ -19,6 +20,7 @@ simple_request_LDADD = \
1920

2021
simple_request_LDFLAGS = \
2122
$(GEOIP_LDFLAGS) \
23+
$(MAXMIND_LDFLAGS) \
2224
$(LMDB_LDFLAGS) \
2325
-lpthread \
2426
$(LUA_LDFLAGS) \
@@ -35,6 +37,7 @@ simple_request_CPPFLAGS = \
3537
-fPIC \
3638
-O3 \
3739
$(GEOIP_CFLAGS) \
40+
$(MAXMIND_CFLAGS) \
3841
$(GLOBAL_CPPFLAGS) \
3942
$(MODSEC_NO_LOGS) \
4043
$(YAJL_CFLAGS) \

src/Makefile.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ libmodsecurity_la_CPPFLAGS = \
304304
$(LMDB_CFLAGS) \
305305
$(PCRE_CFLAGS) \
306306
$(SSDEEP_CFLAGS) \
307+
$(MAXMIND_CFLAGS) \
307308
$(LUA_CFLAGS) \
308309
$(LIBXML2_CFLAGS)
309310

@@ -318,6 +319,7 @@ libmodsecurity_la_LDFLAGS = \
318319
$(LUA_LDFLAGS) \
319320
$(PCRE_LDFLAGS) \
320321
$(SSDEEP_LDFLAGS) \
322+
$(MAXMIND_LDFLAGS) \
321323
$(YAJL_LDFLAGS) \
322324
-version-info @MSC_VERSION_INFO@
323325

@@ -332,6 +334,7 @@ libmodsecurity_la_LIBADD = \
332334
../others/libinjection.la \
333335
../others/libmbedtls.la \
334336
$(PCRE_LDADD) \
337+
$(MAXMIND_LDADD) \
335338
$(SSDEEP_LDADD) \
336339
$(YAJL_LDADD)
337340

0 commit comments

Comments
 (0)