don't attempt keeping scores for banning if banning is disabled

This commit is contained in:
Nikos Mavrogiannopoulos
2015-02-27 08:56:54 +01:00
parent b8b1d5a212
commit 4bbf27a1e8
3 changed files with 11 additions and 4 deletions

View File

@@ -109,7 +109,7 @@ int add_ip_to_ban_list(main_server_st *s, const char *ip, unsigned score)
int ret = 0;
unsigned print_msg;
if (db == NULL || ip == NULL || ip[0] == 0)
if (db == NULL || s->config->max_ban_score == 0 || ip == NULL || ip[0] == 0)
return 0;
/* check if the IP is already there */
@@ -193,7 +193,7 @@ unsigned check_if_banned(main_server_st *s, struct sockaddr_storage *addr, sockl
time_t now;
ban_entry_st t, *e;
if (db == NULL)
if (db == NULL || s->config->max_ban_score == 0)
return 0;
if (human_addr2((struct sockaddr*)addr, addr_size, t.ip, sizeof(t.ip), 0) != NULL) {
@@ -206,8 +206,7 @@ unsigned check_if_banned(main_server_st *s, struct sockaddr_storage *addr, sockl
if (now > e->expires)
return 0;
if (s->config->max_ban_score > 0 &&
e->score >= s->config->max_ban_score) {
if (e->score >= s->config->max_ban_score) {
mslog(s, NULL, LOG_INFO, "Rejected connection from banned IP: %s", t.ip);
return 1;
}

View File

@@ -83,6 +83,10 @@ int sec_mod_add_score_to_ip(sec_mod_st *sec, void *pool, const char *ip, unsigne
BanIpReplyMsg *reply = NULL;
PROTOBUF_ALLOCATOR(pa, lpool);
/* no reporting if banning is disabled */
if (sec->config->max_ban_score == 0)
return 0;
msg.ip = (char*)ip;
msg.score = points;

View File

@@ -247,6 +247,10 @@ void ws_add_score_to_ip(worker_st *ws, unsigned points, unsigned final)
BanIpReplyMsg *reply = NULL;
PROTOBUF_ALLOCATOR(pa, ws);
/* no reporting if banning is disabled */
if (ws->config->max_ban_score == 0)
return;
/* In final call, no score added, we simply send */
if (final == 0) {
ws->ban_points += points;