Skip to content

Commit 095c380

Browse files
committed
Removed support to build without libxml2, which is a mandatory dependency.
1 parent 878682f commit 095c380

File tree

14 files changed

+66
-165
lines changed

14 files changed

+66
-165
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ jobs:
2222
- {label: "wo curl", opt: "--without-curl" }
2323
- {label: "wo lua", opt: "--without-lua" }
2424
- {label: "wo maxmind", opt: "--without-maxmind" }
25-
- {label: "wo libxml", opt: "--without-libxml" }
2625
- {label: "wo geoip", opt: "--without-geoip" }
2726
- {label: "wo ssdeep", opt: "--without-ssdeep" }
2827
- {label: "with lmdb", opt: "--with-lmdb" }
@@ -83,7 +82,6 @@ jobs:
8382
- {label: "wo curl", opt: "--without-curl" }
8483
- {label: "wo lua", opt: "--without-lua" }
8584
- {label: "wo maxmind", opt: "--without-maxmind" }
86-
- {label: "wo libxml", opt: "--without-libxml" }
8785
- {label: "wo geoip", opt: "--without-geoip" }
8886
- {label: "wo ssdeep", opt: "--without-ssdeep" }
8987
- {label: "with lmdb", opt: "--with-lmdb" }
@@ -95,10 +93,10 @@ jobs:
9593
run: |
9694
brew install automake \
9795
yajl \
96+
libxml2 \
9897
lmdb \
9998
lua \
10099
libmaxminddb \
101-
libxml2 \
102100
geoip \
103101
ssdeep \
104102
pcre \
@@ -132,7 +130,6 @@ jobs:
132130
- {label: "wo lmdb", opt: "-DWITHOUT_LMDB=ON" }
133131
- {label: "wo lua", opt: "-DWITHOUT_LUA=ON" }
134132
- {label: "wo maxmind", opt: "-DWITHOUT_MAXMIND=ON" }
135-
- {label: "wo libxml", opt: "-WITHOUT_LIBXML2=ON" }
136133
steps:
137134
- uses: actions/checkout@v4
138135
with:

build/libxml.m4

Lines changed: 45 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,14 @@ dnl Sets:
44
dnl LIBXML2_CFLAGS
55
dnl LIBXML2_LIBS
66

7-
AC_DEFUN([CHECK_XML2CONFIG], [
8-
9-
AC_MSG_CHECKING([for libxml2 config script])
10-
11-
for x in ${test_paths}; do
12-
dnl # Determine if the script was specified and use it directly
13-
if test ! -d "$x" -a -e "$x"; then
14-
LIBXML2_CONFIG=$x
15-
libxml2_path="no"
16-
break
17-
fi
18-
19-
dnl # Try known config script names/locations
20-
for LIBXML2_CONFIG in xml2-config xml-2-config xml-config; do
21-
if test -e "${x}/bin/${LIBXML2_CONFIG}"; then
22-
libxml2_path="${x}/bin"
23-
break
24-
elif test -e "${x}/${LIBXML2_CONFIG}"; then
25-
libxml2_path="${x}"
26-
break
27-
else
28-
libxml2_path=""
29-
fi
30-
done
31-
if test -n "$libxml2_path"; then
32-
break
33-
fi
34-
done
35-
36-
if test -n "${libxml2_path}"; then
37-
if test "${libxml2_path}" != "no"; then
38-
LIBXML2_CONFIG="${libxml2_path}/${LIBXML2_CONFIG}"
39-
fi
7+
AC_DEFUN([CHECK_FOR_LIBXML2_AT], [
8+
libxml2_path=$1
9+
if test "${libxml2_path}" != "no"; then
10+
LIBXML2_CONFIG="${libxml2_path}/${LIBXML2_CONFIG}"
4011
AC_MSG_RESULT([${LIBXML2_CONFIG}])
4112
LIBXML2_VERSION=`${LIBXML2_CONFIG} --version | sed 's/^[[^0-9]][[^[:space:]]][[^[:space:]]]*[[[:space:]]]*//'`
4213
if test ! -z "${LIBXML2_VERSION}"; then AC_MSG_NOTICE(xml VERSION: $LIBXML2_VERSION); fi
43-
LIBXML2_CFLAGS="`${LIBXML2_CONFIG} --cflags` -DWITH_LIBXML2"
14+
LIBXML2_CFLAGS="`${LIBXML2_CONFIG} --cflags`"
4415
if test ! -z "${LIBXML2_CFLAGS}"; then AC_MSG_NOTICE(xml CFLAGS: $LIBXML2_CFLAGS); fi
4516
LIBXML2_LDADD="`${LIBXML2_CONFIG} --libs`"
4617
if test ! -z "${LIBXML2_LDADD}"; then AC_MSG_NOTICE(xml LDADD: $LIBXML2_LDADD); fi
@@ -54,11 +25,8 @@ if test -n "${libxml2_path}"; then
5425
AC_MSG_RESULT([no, $LIBXML2_VERSION])
5526
AC_MSG_ERROR([NOTE: libxml2 library must be at least ${LIBXML2_MIN_VERSION}])
5627
fi
57-
58-
else
59-
AC_MSG_RESULT([no])
6028
fi
61-
])
29+
]) # AC_DEFUN [CHECK_FOR_LIBXML2_AT]
6230

6331
AC_DEFUN([CHECK_LIBXML2], [
6432
@@ -73,16 +41,19 @@ LIBXML2_PKG_NAME="libxml-2.0"
7341
LIBXML2_CONFIG=""
7442
LIBXML2_VERSION=""
7543
LIBXML2_CFLAGS=""
76-
LIBXML2_CPPFLAGS=""
7744
LIBXML2_LDADD=""
7845
LIBXML2_LDFLAGS=""
7946
80-
if test "x${with_libxml}" != "xno"; then
47+
LIBXML2_MANDATORY=yes
48+
AC_MSG_NOTICE([libxml2 is mandatory])
49+
50+
if test "x${with_libxml}" == "x" || test "x${with_libxml}" == "xyes"; then
51+
# Nothing about libxml was informed, using the pkg-config to figure things out.
8152
if test -n "${PKG_CONFIG}"; then
8253
AC_MSG_CHECKING([for libxml2 >= ${LIBXML2_MIN_VERSION} via pkg-config])
8354
if `${PKG_CONFIG} --exists "${LIBXML2_PKG_NAME} >= ${LIBXML2_MIN_VERSION}"`; then
8455
LIBXML2_VERSION="`${PKG_CONFIG} --modversion ${LIBXML2_PKG_NAME}`"
85-
LIBXML2_CFLAGS="`${PKG_CONFIG} --cflags ${LIBXML2_PKG_NAME}` -DWITH_LIBXML2"
56+
LIBXML2_CFLAGS="`${PKG_CONFIG} --cflags ${LIBXML2_PKG_NAME}`"
8657
LIBXML2_LDADD="`${PKG_CONFIG} --libs-only-l ${LIBXML2_PKG_NAME}`"
8758
LIBXML2_LDFLAGS="`${PKG_CONFIG} --libs-only-L --libs-only-other ${LIBXML2_PKG_NAME}`"
8859
AC_MSG_RESULT([found version ${LIBXML2_VERSION}])
@@ -92,44 +63,48 @@ if test "x${with_libxml}" != "xno"; then
9263
fi
9364
9465
if test -z "${LIBXML2_VERSION}"; then
95-
CHECK_XML2CONFIG
96-
fi
97-
fi
98-
99-
AC_SUBST(LIBXML2_CONFIG)
100-
AC_SUBST(LIBXML2_VERSION)
101-
AC_SUBST(LIBXML2_CFLAGS)
102-
AC_SUBST(LIBXML2_CPPFLAGS)
103-
AC_SUBST(LIBXML2_LDADD)
104-
AC_SUBST(LIBXML2_LDFLAGS)
105-
106-
107-
if test "x${with_libxml}" == "xno"; then
108-
LIBXML2_DISABLED=yes
109-
else
110-
if test "x${with_libxml}" != "x"; then
111-
LIBXML2_MANDATORY=yes
66+
# If pkg-config did not find anything useful, go over file lookup.
67+
AC_MSG_CHECKING([for libxml2 config script])
68+
69+
for x in ${test_paths}; do
70+
dnl # Try known config script names/locations
71+
for LIBXML2_CONFIG in xml2-config xml-2-config xml-config; do
72+
if test -e "${x}/bin/${LIBXML2_CONFIG}"; then
73+
libxml2_path="${x}/bin"
74+
break
75+
elif test -e "${x}/${LIBXML2_CONFIG}"; then
76+
libxml2_path="${x}"
77+
break
78+
else
79+
libxml2_path=""
80+
fi
81+
done
82+
if test -n "$libxml2_path"; then
83+
CHECK_FOR_LIBXML2_AT(${libxml2_path})
84+
if test -n "${LIBXML2_VERSION}"; then
85+
break
86+
fi
87+
fi
88+
done
11289
fi
90+
elif test "x${with_libxml}" != "x"; then
91+
# A specific path was informed, let's check.
92+
CHECK_FOR_LIBXML2_AT(${with_libxml})
11393
fi
11494
11595
if test -z "${LIBXML2_VERSION}"; then
116-
AC_MSG_NOTICE([*** libxml2 library not found.])
117-
if test -z "${LIBXML2_MANDATORY}"; then
118-
if test -z "${LIBXML2_DISABLED}"; then
119-
LIBXML2_FOUND=0
120-
else
121-
LIBXML2_FOUND=2
122-
fi
123-
else
124-
AC_MSG_ERROR([Libxml2 was explicitly referenced but it was not found])
125-
LIBXML2_FOUND=-1
126-
fi
96+
AC_MSG_ERROR([libxml2 is mandatory but it was not found])
97+
LIBXML2_FOUND=-1
12798
else
12899
LIBXML2_FOUND=1
129100
AC_MSG_NOTICE([using libxml2 v${LIBXML2_VERSION}])
101+
AC_SUBST(LIBXML2_VERSION)
102+
AC_SUBST(LIBXML2_CFLAGS)
103+
AC_SUBST(LIBXML2_LDADD)
104+
AC_SUBST(LIBXML2_LDFLAGS)
130105
LIBXML2_DISPLAY="${LIBXML2_LDADD}, ${LIBXML2_CFLAGS}"
106+
AC_SUBST(LIBXML2_DISPLAY)
131107
fi
132108
133109
AC_SUBST(LIBXML2_FOUND)
134-
AC_SUBST(LIBXML2_DISPLAY)
135110
])

build/win32/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ set(BASE_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
44

55
option(WITHOUT_LMDB "Include LMDB support" OFF)
66
option(WITHOUT_LUA "Include LUA support" OFF)
7-
option(WITHOUT_LIBXML2 "Include LibXML2 support" OFF)
87
option(WITHOUT_MAXMIND "Include MaxMind support" OFF)
98
option(WITHOUT_CURL "Include CURL support" OFF)
109

@@ -62,6 +61,7 @@ set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
6261
set(PACKAGE_TARNAME "${PACKAGE_NAME}")
6362

6463
set(HAVE_YAJL 1) # should always be one, mandatory dependency
64+
set(HAVE_LIBXML2 1) # should always be one, mandatory dependency
6565
set(HAVE_GEOIP 0) # should always be zero, no conan package available
6666
set(HAVE_SSDEEP 0) # should always be zero, no conan package available
6767

@@ -75,7 +75,6 @@ endmacro()
7575

7676
enable_feature(HAVE_LMDB ${WITHOUT_LMDB})
7777
enable_feature(HAVE_LUA ${WITHOUT_LUA})
78-
enable_feature(HAVE_LIBXML2 ${WITHOUT_LIBXML2})
7978
enable_feature(HAVE_MAXMIND ${WITHOUT_MAXMIND})
8079
enable_feature(HAVE_CURL ${WITHOUT_CURL})
8180

@@ -142,6 +141,7 @@ function(setTestTargetProperties executable)
142141
target_include_directories(${executable} PRIVATE ${BASE_DIR} ${BASE_DIR}/headers)
143142
target_link_libraries(${executable} PRIVATE libModSecurity pcre2::pcre2 dirent::dirent)
144143
add_package_dependency(${executable} WITH_YAJL yajl::yajl HAVE_YAJL)
144+
add_package_dependency(${executable} WITH_LIBXML2 LibXml2::LibXml2 HAVE_LIBXML2)
145145
endfunction()
146146

147147
# unit tests

configure.ac

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ AC_DEFUN([SECLANG_TEST_VERSION], m4_esyscmd_s(cd "test/test-cases/secrules-langu
8383
# Check for yajl
8484
CHECK_YAJL
8585

86+
# Check for LibXML
87+
CHECK_LIBXML2
88+
8689
# Check for LibGeoIP
8790
PROG_GEOIP
8891
AM_CONDITIONAL([GEOIP_CFLAGS], [test "GEOIP_CFLAGS" != ""])
@@ -115,12 +118,6 @@ if ! test -z "${CURL_VERSION}"; then
115118
fi
116119

117120

118-
#
119-
# Check for LibXML
120-
#
121-
CHECK_LIBXML2
122-
123-
124121
#
125122
# Check for libpcre
126123
#
@@ -415,6 +412,16 @@ else
415412
fi
416413
echo " ${YAJL_DISPLAY}"
417414

415+
## libxml2
416+
AS_ECHO_N(" + LibXML2 ....")
417+
if ! test "x$LIBXML2_VERSION" = "x"; then
418+
echo "v${LIBXML2_VERSION}"
419+
else
420+
echo ""
421+
fi
422+
echo " ${LIBXML2_DISPLAY}"
423+
424+
418425
AS_ECHO_N(" + libInjection ....")
419426
echo LIBINJECTION_VERSION
420427
AS_ECHO_N(" + SecLang tests ....")
@@ -482,24 +489,6 @@ if test "x$LMDB_FOUND" = "x2"; then
482489
fi
483490

484491

485-
## libxml2
486-
if test "x$LIBXML2_FOUND" = "x0"; then
487-
echo " + LibXML2 ....not found"
488-
fi
489-
if test "x$LIBXML2_FOUND" = "x1"; then
490-
AS_ECHO_N(" + LibXML2 ....found ")
491-
if ! test "x$LIBXML2_VERSION" = "x"; then
492-
echo "v${LIBXML2_VERSION}"
493-
else
494-
echo ""
495-
fi
496-
echo " ${LIBXML2_DISPLAY}"
497-
fi
498-
if test "x$LIBXML2_FOUND" = "x2"; then
499-
echo " + LibXML2 ....disabled"
500-
fi
501-
502-
503492
## SSDEEP
504493
if test "x$SSDEEP_FOUND" = "x0"; then
505494
echo " + SSDEEP ....not found"

src/modsecurity.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919

2020
#include <yajl/yajl_tree.h>
2121
#include <yajl/yajl_gen.h>
22-
#ifdef WITH_LIBXML2
2322
#include <libxml/xmlschemas.h>
2423
#include <libxml/xpath.h>
25-
#endif
2624
#ifdef MSC_WITH_CURL
2725
#include <curl/curl.h>
2826
#endif
@@ -83,9 +81,7 @@ ModSecurity::ModSecurity()
8381
#ifdef MSC_WITH_CURL
8482
curl_global_init(CURL_GLOBAL_ALL);
8583
#endif
86-
#ifdef WITH_LIBXML2
8784
xmlInitParser();
88-
#endif
8985
}
9086

9187

@@ -96,9 +92,7 @@ ModSecurity::~ModSecurity() {
9692
#ifdef WITH_GEOIP
9793
Utils::GeoLookup::getInstance().cleanUp();
9894
#endif
99-
#ifdef WITH_LIBXML2
10095
xmlCleanupParser();
101-
#endif
10296
delete m_global_collection;
10397
delete m_resource_collection;
10498
delete m_ip_collection;

src/operators/validate_dtd.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
namespace modsecurity {
2525
namespace operators {
2626

27-
#ifdef WITH_LIBXML2
2827
bool ValidateDTD::init(const std::string &file, std::string *error) {
2928
std::string err;
3029
m_resource = utils::find_resource(m_param, file, &err);
@@ -48,7 +47,7 @@ bool ValidateDTD::evaluate(Transaction *transaction, const std::string &str) {
4847
XmlDtdPtrManager dtd(xmlParseDTD(NULL, (const xmlChar *)m_resource.c_str()));
4948
if (dtd.get() == NULL) {
5049
std::string err = std::string("XML: Failed to load DTD: ") \
51-
+ m_resource;
50+
+ m_resource; // cppcheck-suppress unreadVariable
5251
ms_dbg_a(transaction, 4, err);
5352
return true;
5453
}
@@ -99,7 +98,6 @@ bool ValidateDTD::evaluate(Transaction *transaction, const std::string &str) {
9998

10099
return false;
101100
}
102-
#endif
103101

104102
} // namespace operators
105103
} // namespace modsecurity

0 commit comments

Comments
 (0)