mirror of
https://gitlab.com/openconnect/ocserv.git
synced 2026-02-10 16:57:00 +08:00
correctly print the IP of addresses added to ban list
This commit is contained in:
@@ -106,6 +106,7 @@ static void massage_ipv6_address(ban_entry_st *t)
|
||||
}
|
||||
|
||||
/* returns -1 if the user is already banned, and zero otherwise */
|
||||
static
|
||||
int add_ip_to_ban_list(main_server_st *s, const unsigned char *ip, unsigned ip_size, unsigned score)
|
||||
{
|
||||
struct htable *db = s->ban_db;
|
||||
@@ -114,6 +115,8 @@ int add_ip_to_ban_list(main_server_st *s, const unsigned char *ip, unsigned ip_s
|
||||
time_t now = time(0);
|
||||
time_t expiration = now + s->config->min_reauth_time;
|
||||
int ret = 0;
|
||||
char str_ip[MAX_IP_STR];
|
||||
const char *p_str_ip = NULL;
|
||||
unsigned print_msg;
|
||||
|
||||
if (db == NULL || s->config->max_ban_score == 0 || ip == NULL || (ip_size != 4 && ip_size != 16))
|
||||
@@ -157,12 +160,19 @@ int add_ip_to_ban_list(main_server_st *s, const unsigned char *ip, unsigned ip_s
|
||||
print_msg = 1;
|
||||
e->score += score;
|
||||
|
||||
if (ip_size == 4)
|
||||
p_str_ip = inet_ntop(AF_INET, ip, str_ip, sizeof(str_ip));
|
||||
else
|
||||
p_str_ip = inet_ntop(AF_INET6, ip, str_ip, sizeof(str_ip));
|
||||
|
||||
if (s->config->max_ban_score > 0 && e->score >= s->config->max_ban_score) {
|
||||
if (print_msg)
|
||||
mslog(s, NULL, LOG_INFO, "added IP '%s' (with score %d) to ban list, will be reset at: %s", ip, e->score, ctime(&e->expires));
|
||||
if (print_msg && p_str_ip) {
|
||||
mslog(s, NULL, LOG_INFO, "added IP '%s' (with score %d) to ban list, will be reset at: %s", str_ip, e->score, ctime(&e->expires));
|
||||
}
|
||||
ret = -1;
|
||||
} else {
|
||||
mslog(s, NULL, LOG_DEBUG, "added %d points (total %d) for IP '%s' to ban list", score, e->score, ip);
|
||||
if (p_str_ip)
|
||||
mslog(s, NULL, LOG_DEBUG, "added %d points (total %d) for IP '%s' to ban list", score, e->score, str_ip);
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ typedef struct ban_entry_st {
|
||||
|
||||
void cleanup_banned_entries(main_server_st *s);
|
||||
unsigned check_if_banned(main_server_st *s, struct sockaddr_storage *addr, socklen_t addr_size);
|
||||
int add_ip_to_ban_list(main_server_st *s, const unsigned char *ip, unsigned ip_size, unsigned score);
|
||||
int add_str_ip_to_ban_list(main_server_st *s, const char *ip, unsigned score);
|
||||
int remove_ip_from_ban_list(main_server_st *s, const uint8_t *ip, unsigned size);
|
||||
unsigned main_ban_db_elems(main_server_st *s);
|
||||
|
||||
Reference in New Issue
Block a user