From c29099df3f8ead3dfcc1ea59b213d98dc044eda9 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Sat, 1 Oct 2016 07:32:40 +0800 Subject: [PATCH] Enable block list by default --- src/acl.h | 4 ++-- src/server.c | 22 +++++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/acl.h b/src/acl.h index f8d70299..e98c8a28 100644 --- a/src/acl.h +++ b/src/acl.h @@ -27,8 +27,8 @@ #define WHITE_LIST 1 #define MAX_TRIES 128 -#define ATTACK 32 -#define BAD 8 +#define ATTACK 8 +#define BAD 4 #define MALFORMED 1 int init_acl(const char *path); diff --git a/src/server.c b/src/server.c index 5f720c74..2d1b9961 100644 --- a/src/server.c +++ b/src/server.c @@ -308,7 +308,7 @@ report_addr(int fd, int err_level) } // Block all requests from this IP, if the err# exceeds 128. if (check_block_list(peer_name, err_level)) { - LOGE("block all requests from %s", peer_name); + LOGE("add %s to block list", peer_name); } } @@ -1419,14 +1419,18 @@ accept_cb(EV_P_ ev_io *w, int revents) return; } - if (acl) { - char *peer_name = get_peer_name(serverfd); - if (peer_name != NULL) { - if (check_block_list(peer_name, 0) - || (get_acl_mode() == BLACK_LIST && acl_match_host(peer_name) == 1) - || (get_acl_mode() == WHITE_LIST && acl_match_host(peer_name) >= 0)) { - if (verbose) - LOGI("Access denied from %s", peer_name); + char *peer_name = get_peer_name(serverfd); + + if (peer_name != NULL) { + if (check_block_list(peer_name, 0)) { + LOGE("block all requests from %s", peer_name); + close(serverfd); + return; + } + if (acl) { + if ((get_acl_mode() == BLACK_LIST && acl_match_host(peer_name) == 1) + || (get_acl_mode() == WHITE_LIST && acl_match_host(peer_name) >= 0)) { + LOGE("Access denied from %s", peer_name); close(serverfd); return; }