Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/utils/geo_lookup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ bool GeoLookup::setDataBase(const std::string& filePath,
std::string intGeo;
#endif

/* A database may have been loaded already -- GeoLookup is a process wide
* singleton and SecGeoLookupDb can be used more than once, including on
* every re-parse of the configuration. Release it before loading the new
* one, otherwise the previous handle (and the mmap'ed database file) is
* leaked. */
cleanUp();

#ifdef WITH_MAXMIND
int status = MMDB_open(filePath.c_str(), MMDB_MODE_MMAP, &mmdb);
if (status != MMDB_SUCCESS) {
Expand Down
51 changes: 51 additions & 0 deletions test/test-cases/regression/config-secgeolookupdb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[
{
"enabled": 1,
"version_min": 300000,
"title": "Testing SecGeoLookupDb :: database informed twice [maxmind]",
"resource": "maxmind",
"client": {
"ip": "200.249.12.31",
"port": 123
},
"server": {
"ip": "200.249.12.31",
"port": 80
},
"request": {
"headers": {
"Host": "localhost",
"User-Agent": "curl/7.38.0",
"Accept": "*/*",
"Content-Length": "0"
},
"uri": "/?key=value&key=other_value",
"method": "GET",
"body": [
""
]
},
"response": {
"headers": {
"Date": "Mon, 13 Jul 2015 20:02:41 GMT",
"Last-Modified": "Sun, 26 Oct 2014 22:33:37 GMT",
"Content-Type": "text/html",
"Content-Length": "8"
},
"body": [
"no need."
]
},
"expected": {
"debug_log": "Target value: \"Brazil\" \\(Variable: GEO:COUNTRY_NAME\\)",
"http_code": 200
},
"rules": [
"SecRuleEngine On",
"SecGeoLookupDb test-cases/data/GeoIP2-City-Test.mmdb",
"SecGeoLookupDb test-cases/data/GeoIP2-City-Test.mmdb",
"SecRule REMOTE_ADDR \"@geoLookup\" \"id:1,pass,t:trim\"",
"SecRule GEO \"@contains test \" \"id:2,pass,t:trim\""
]
}
]
1 change: 1 addition & 0 deletions test/test-suite.in
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ TESTS+=test/test-cases/regression/config-remove_by_msg.json
TESTS+=test/test-cases/regression/config-remove_by_tag.json
TESTS+=test/test-cases/regression/config-response_type.json
TESTS+=test/test-cases/regression/config-secdefaultaction.json
TESTS+=test/test-cases/regression/config-secgeolookupdb.json
TESTS+=test/test-cases/regression/config-secremoterules.json
TESTS+=test/test-cases/regression/config-update-action-by-id.json
TESTS+=test/test-cases/regression/config-update-target-by-id.json
Expand Down
Loading