diff --git a/src/collection/backend/lmdb.cc b/src/collection/backend/lmdb.cc index af73afa5aa..53acf935d8 100644 --- a/src/collection/backend/lmdb.cc +++ b/src/collection/backend/lmdb.cc @@ -27,7 +27,6 @@ #undef LMDB_STDOUT_COUT - namespace modsecurity { namespace collection { namespace backend { @@ -35,8 +34,8 @@ namespace backend { #ifdef WITH_LMDB - -LMDB::LMDB() : Collection(""), m_env(NULL) { +LMDB::LMDB(std::string name) : + Collection(name), m_env(NULL) { mdb_env_create(&m_env); mdb_env_open(m_env, "./modsec-shared-collections", MDB_WRITEMAP | MDB_NOSUBDIR, 0664); @@ -121,7 +120,7 @@ void LMDB::lmdb_debug(int rc, std::string op, std::string scope) { } std::cout << std::endl; } else if (op == "del") { - td::cout << scope << ", delete procedure failed: "; + std::cout << scope << ", delete procedure failed: "; switch (rc) { case EACCES: std::cout << "an attempt was made to write in a "; @@ -494,22 +493,40 @@ void LMDB::resolveMultiMatches(const std::string& var, } while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { - if (key.mv_size <= keySize + 1) { - continue; - } + // + // I don't see what's the reason of this clause + // + // eg: + // looking for the variable: 'test', keySize will 4 + // found key: 'test', key.mv_size will 4 + // key.mv_size IS LESS than keySize+1, so we will continue? + // + //if (key.mv_size <= keySize + 1) { + // continue; + //} char *a = reinterpret_cast(key.mv_data); - if (a[keySize] != ':') { - continue; - } + // + // also don't understand this part + // + // key.mv_data will 'test', but there isn't ':' at the end, + // so we will skip it? + // + //if (a[keySize] != ':') { + // continue; + //} + + // this will never evaluate with the two statements above, + // but I think this is the only required check if (strncmp(var.c_str(), a, keySize) != 0) { continue; } - VariableValue *v = new VariableValue( - new std::string(reinterpret_cast(key.mv_data), + l->insert(l->begin(), new VariableValue( + &m_name, + new std::string(reinterpret_cast(key.mv_data), key.mv_size), - new std::string(reinterpret_cast(data.mv_data), - data.mv_size)); - l->insert(l->begin(), v); + new std::string(reinterpret_cast(data.mv_data), + data.mv_size)) + ); } mdb_cursor_close(cursor); diff --git a/src/collection/backend/lmdb.h b/src/collection/backend/lmdb.h index a829414b09..edd4de7bd2 100644 --- a/src/collection/backend/lmdb.h +++ b/src/collection/backend/lmdb.h @@ -50,7 +50,7 @@ namespace backend { class LMDB : public Collection { public: - LMDB(); + LMDB(std::string name); ~LMDB(); void store(std::string key, std::string value) override; diff --git a/src/modsecurity.cc b/src/modsecurity.cc index 5560d79436..b079d0188d 100644 --- a/src/modsecurity.cc +++ b/src/modsecurity.cc @@ -63,11 +63,11 @@ ModSecurity::ModSecurity() : m_connector(""), m_whoami(""), #ifdef WITH_LMDB - m_global_collection(new collection::backend::LMDB()), - m_resource_collection(new collection::backend::LMDB()), - m_ip_collection(new collection::backend::LMDB()), - m_session_collection(new collection::backend::LMDB()), - m_user_collection(new collection::backend::LMDB()), + m_global_collection(new collection::backend::LMDB("GLOBAL")), + m_resource_collection(new collection::backend::LMDB("RESOURCE")), + m_ip_collection(new collection::backend::LMDB("IP")), + m_session_collection(new collection::backend::LMDB("SESSION")), + m_user_collection(new collection::backend::LMDB("USER")), #else m_global_collection(new collection::backend::InMemoryPerProcess("GLOBAL")), m_ip_collection(new collection::backend::InMemoryPerProcess("IP")),