diff --git a/configure.ac b/configure.ac index b3ef4fbf..929bd4a0 100644 --- a/configure.ac +++ b/configure.ac @@ -94,6 +94,10 @@ PROG_GEOIP AM_CONDITIONAL([GEOIP_CFLAGS], [test "GEOIP_CFLAGS" != ""]) +# Check for LMDB +PROG_LMDB +AM_CONDITIONAL([LMDB_CFLAGS], [test "LMDB_CFLAGS" != ""]) + # # Check for curl # @@ -373,6 +377,24 @@ if test "x$YAJL_FOUND" = "x2"; then fi +## LMDB +if test "x$LMDB_FOUND" = "x0"; then + echo " + LMDB ....not found" +fi +if test "x$LMDB_FOUND" = "x1"; then + echo -n " + LMDB ....found " + if ! test "x$LMDB_VERSION" = "x"; then + echo "v${LMDB_VERSION}" + else + echo "" + fi + echo " ${LMDB_DISPLAY}" +fi +if test "x$LMDB_FOUND" = "x2"; then + echo " + LMDB ....disabled" +fi + + ## libxml2 if test "x$LIBXML2_FOUND" = "x0"; then echo " + LibXML2 ....not found" diff --git a/src/Makefile.am b/src/Makefile.am index 8ffd39bf..480d876c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -200,7 +200,8 @@ UTILS = \ COLLECTION = \ collection/collections.cc \ - collection/backend/in_memory-per_process.cc + collection/backend/in_memory-per_process.cc \ + collection/backend/lmdb.cc BODY_PROCESSORS = \ @@ -250,6 +251,7 @@ libmodsecurity_la_CPPFLAGS = \ $(GLOBAL_CPPFLAGS) \ $(MODSEC_NO_LOGS) \ $(YAJL_CFLAGS) \ + $(LMDB_CFLAGS) \ $(PCRE_CFLAGS) \ $(LIBXML2_CFLAGS) @@ -260,6 +262,7 @@ libmodsecurity_la_LIBADD = \ @LEXLIB@ \ $(PCRE_LDADD) \ $(YAJL_LDFLAGS) $(YAJL_LDADD) \ + $(LMDB_LDFLAGS) $(LMDB_LDADD) \ $(LIBXML2_LDADD) \ ../others/libinjection.la \ libmbedtls.la diff --git a/src/collection/backend/lmdb.cc b/src/collection/backend/lmdb.cc new file mode 100644 index 00000000..16a21afe --- /dev/null +++ b/src/collection/backend/lmdb.cc @@ -0,0 +1,81 @@ +/* + * 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 "src/collection/backend/lmdb.h" + +#include "lmdb.h" + +#include + +#include "modsecurity/collection/variable.h" +#include "src/utils.h" + +namespace modsecurity { +namespace collection { +namespace backend { + + +LMDB::LMDB() { +} + +LMDB::~LMDB() { +} + +void LMDB::store(std::string key, std::string value) { + +} + + +bool LMDB::storeOrUpdateFirst(const std::string &key, + const std::string &value) { + return true; +} + + +bool LMDB::updateFirst(const std::string &key, + const std::string &value) { + +} + + +void LMDB::del(const std::string& key) { +} + + +void LMDB::resolveSingleMatch(const std::string& var, + std::vector *l) { + +} + + +void LMDB::resolveMultiMatches(const std::string& var, + std::vector *l) { + +} + + +void LMDB::resolveRegularExpression(const std::string& var, + std::vector *l) { +} + + +std::string* LMDB::resolveFirst(const std::string& var) { +} + + +} // namespace backend +} // namespace collection +} // namespace modsecurity diff --git a/src/collection/backend/lmdb.h b/src/collection/backend/lmdb.h new file mode 100644 index 00000000..d0e99373 --- /dev/null +++ b/src/collection/backend/lmdb.h @@ -0,0 +1,76 @@ +/* + * 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. + * + */ + + +#ifdef __cplusplus +#include +#include +#include +#include +#include +#include +#endif + +#include + +#include "modsecurity/collection/variable.h" +#include "modsecurity/collection/collection.h" + +#ifndef SRC_COLLECTION_BACKEND_LMDB_H_ +#define SRC_COLLECTION_BACKEND_LMDB_H_ + +#ifdef __cplusplus +namespace modsecurity { +namespace collection { +namespace backend { + +class LMDB : + public Collection { + public: + LMDB(); + ~LMDB(); + void store(std::string key, std::string value) override; + + bool storeOrUpdateFirst(const std::string &key, + const std::string &value) override; + + bool updateFirst(const std::string &key, + const std::string &value) override; + + void del(const std::string& key) override; + + std::string* resolveFirst(const std::string& var) override; + + void resolveSingleMatch(const std::string& var, + std::vector *l) override; + void resolveMultiMatches(const std::string& var, + std::vector *l) override; + void resolveRegularExpression(const std::string& var, + std::vector *l) override; + + private: + MDB_env *m_env; + MDB_dbi m_dbi; + MDB_txn *m_txn; + +}; + +} // namespace backend +} // namespace collection +} // namespace modsecurity +#endif + + +#endif // SRC_COLLECTION_BACKEND_LMDB_H_ diff --git a/test/Makefile.am b/test/Makefile.am index 6c5ab3b5..60830e8d 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -35,6 +35,7 @@ unit_tests_LDADD = \ $(GEOIP_LDFLAGS) $(GEOIP_LDADD) \ $(PCRE_LDADD) \ $(YAJL_LDFLAGS) $(YAJL_LDADD) \ + $(LMDB_LDFLAGS) $(LMDB_LDADD) \ $(LIBXML2_LDADD) @@ -49,6 +50,7 @@ unit_tests_CPPFLAGS = \ $(MODSEC_NO_LOGS) \ $(GEOIP_CFLAGS) \ $(GLOBAL_CPPFLAGS) \ + $(LMDB_CFLAGS) \ $(PCRE_CFLAGS) \ $(YAJL_CFLAGS) \ $(LIBXML2_CFLAGS) @@ -69,6 +71,7 @@ regression_tests_LDADD = \ $(GEOIP_LDFLAGS) $(GEOIP_LDADD) \ $(PCRE_LDADD) \ $(YAJL_LDFLAGS) $(YAJL_LDADD) \ + $(LMDB_LDFLAGS) $(LMDB_LDADD) \ $(LIBXML2_LDADD) @@ -83,6 +86,7 @@ regression_tests_CPPFLAGS = \ $(MODSEC_NO_LOGS) \ $(GEOIP_CFLAGS) \ $(GLOBAL_CPPFLAGS) \ + $(LMDB_CFLAGS) \ $(PCRE_CFLAGS) \ $(YAJL_CFLAGS) \ $(LIBXML2_CFLAGS) @@ -102,6 +106,7 @@ rules_optimization_LDADD = \ $(GEOIP_LDFLAGS) $(GEOIP_LDADD) \ $(PCRE_LDADD) \ $(YAJL_LDFLAGS) $(YAJL_LDADD) \ + $(LMDB_LDFLAGS) $(LMDB_LDADD) \ $(LIBXML2_LDADD) @@ -116,6 +121,7 @@ rules_optimization_CPPFLAGS = \ $(MODSEC_NO_LOGS) \ $(GEOIP_CFLAGS) \ $(GLOBAL_CPPFLAGS) \ + $(LMDB_CFLAGS) \ $(PCRE_CFLAGS) \ $(YAJL_CFLAGS) \ $(LIBXML2_CFLAGS) diff --git a/test/benchmark/Makefile.am b/test/benchmark/Makefile.am index 83f04fa5..370d802d 100644 --- a/test/benchmark/Makefile.am +++ b/test/benchmark/Makefile.am @@ -12,6 +12,7 @@ benchmark_LDADD = \ $(GEOIP_LDFLAGS) $(GEOIP_LDADD) \ $(PCRE_LDADD) \ $(YAJL_LDFLAGS) $(YAJL_LDADD) \ + $(LMDB_LDFLAGS) $(LMDB_LDADD) \ $(LIBXML2_LDADD) benchmark_CPPFLAGS = \ @@ -19,9 +20,9 @@ benchmark_CPPFLAGS = \ -I$(top_builddir)/headers \ $(GLOBAL_CPPFLAGS) \ $(PCRE_CFLAGS) \ + $(LMDB_CFLAGS) \ $(LIBXML2_CFLAGS) - MAINTAINERCLEANFILES = \ Makefile.in