From 10df26d08f3b8c4f2a6e68c71d6c785e6babbff9 Mon Sep 17 00:00:00 2001 From: Ed Kellett Date: Sat, 25 Nov 2017 22:17:50 +0000 Subject: [PATCH 1/6] Add check_one_kline, expose notify_banned_client --- include/client.h | 8 ++++++ ircd/client.c | 74 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 75 insertions(+), 7 deletions(-) diff --git a/include/client.h b/include/client.h index f00cfad4..7db9f620 100644 --- a/include/client.h +++ b/include/client.h @@ -578,9 +578,16 @@ struct ListClient #define SHOW_IP 1 #define MASK_IP 2 +enum +{ + D_LINED, + K_LINED +}; + extern void check_banned_lines(void); extern void check_klines_event(void *unused); extern void check_klines(void); +extern void check_one_kline(struct ConfItem *kline); extern void check_dlines(void); extern void check_xlines(void); extern void resv_nick_fnc(const char *mask, const char *reason, int temp_time); @@ -592,6 +599,7 @@ extern void init_client(void); extern struct Client *make_client(struct Client *from); extern void free_pre_client(struct Client *client); +extern void notify_banned_client(struct Client *, struct ConfItem *, int ban); extern int exit_client(struct Client *, struct Client *, struct Client *, const char *); extern void error_exit_client(struct Client *, int); diff --git a/ircd/client.c b/ircd/client.c index 3378bc4a..b25092d5 100644 --- a/ircd/client.c +++ b/ircd/client.c @@ -80,12 +80,6 @@ static uint32_t current_connid = 0; rb_dictionary *nd_dict = NULL; -enum -{ - D_LINED, - K_LINED -}; - rb_dlink_list dead_list; #ifdef DEBUG_EXITED_CLIENTS static rb_dlink_list dead_remote_list; @@ -487,7 +481,7 @@ check_unknowns_list(rb_dlink_list * list) } } -static void +void notify_banned_client(struct Client *client_p, struct ConfItem *aconf, int ban) { static const char conn_closed[] = "Connection closed"; @@ -587,6 +581,72 @@ check_klines(void) } } + +/* check_one_kline() + * + * inputs - pointer to kline to check + * outputs - + * side effects - all clients will be checked against given kline + */ +void +check_one_kline(struct ConfItem *kline) +{ + struct Client *client_p; + rb_dlink_node *ptr; + rb_dlink_node *next_ptr; + + RB_DLINK_FOREACH_SAFE(ptr, next_ptr, lclient_list.head) + { + client_p = ptr->data; + + if(IsMe(client_p) || !IsPerson(client_p)) + continue; + + if(!match(kline->user, client_p->username)) + continue; + + /* match one kline */ + { + int matched = 0; + int masktype; + int bits; + struct rb_sockaddr_storage sockaddr; + + masktype = parse_netmask(kline->host, (struct sockaddr *)&sockaddr, &bits); + + switch (masktype) { + case HM_IPV4: + case HM_IPV6: + if(comp_with_mask_sock((struct sockaddr *)&client_p->localClient->ip, + (struct sockaddr *)&sockaddr, bits)) + matched = 1; + case HM_HOST: + if (match(kline->host, client_p->orighost)) + matched = 1; + } + + if (!matched) + continue; + } + + if(IsExemptKline(client_p)) + { + sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, + "KLINE over-ruled for %s, client is kline_exempt [%s@%s]", + get_client_name(client_p, HIDE_IP), + kline->user, kline->host); + continue; + } + + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "KLINE active for %s", + get_client_name(client_p, HIDE_IP)); + + notify_banned_client(client_p, kline, K_LINED); + } +} + + /* check_dlines() * * inputs - From b068a4b51855e82f547fd7d52386e3617e016827 Mon Sep 17 00:00:00 2001 From: Ed Kellett Date: Sat, 25 Nov 2017 01:31:34 +0000 Subject: [PATCH 2/6] m_kline: check only the added K-line --- modules/m_kline.c | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/modules/m_kline.c b/modules/m_kline.c index abcfa1e7..cd58b656 100644 --- a/modules/m_kline.c +++ b/modules/m_kline.c @@ -85,6 +85,7 @@ static void remove_permkline_match(struct Client *, struct ConfItem *); static bool remove_temp_kline(struct Client *, struct ConfItem *); static void remove_prop_kline(struct Client *, struct ConfItem *); + /* mo_kline() * * parv[1] - temp time or user@host @@ -215,17 +216,7 @@ mo_kline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source else apply_kline(source_p, aconf, reason, oper_reason); - if(ConfigFileEntry.kline_delay) - { - if(!kline_queued) - { - rb_event_addonce("check_klines", check_klines_event, NULL, - ConfigFileEntry.kline_delay); - kline_queued = true; - } - } - else - check_klines(); + check_one_kline(aconf); } /* ms_kline() @@ -325,17 +316,7 @@ handle_remote_kline(struct Client *source_p, int tkline_time, else apply_kline(source_p, aconf, reason, oper_reason); - if(ConfigFileEntry.kline_delay) - { - if(!kline_queued) - { - rb_event_addonce("check_klines", check_klines_event, NULL, - ConfigFileEntry.kline_delay); - kline_queued = true; - } - } - else - check_klines(); + check_one_kline(aconf); } /* mo_unkline() From 43037e1af3ebd420a49e48bcfeea05c658c2e8e3 Mon Sep 17 00:00:00 2001 From: Ed Kellett Date: Sat, 27 Apr 2019 14:51:04 +0100 Subject: [PATCH 3/6] m_ban: check only the added K-line --- modules/core/m_ban.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/modules/core/m_ban.c b/modules/core/m_ban.c index 94c18f2d..43e6fc9e 100644 --- a/modules/core/m_ban.c +++ b/modules/core/m_ban.c @@ -286,20 +286,7 @@ ms_ban(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p else { add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf); - if(ConfigFileEntry.kline_delay || - (IsServer(source_p) && - !HasSentEob(source_p))) - { - if(kline_queued == 0) - { - rb_event_addonce("check_klines", check_klines_event, NULL, - ConfigFileEntry.kline_delay ? - ConfigFileEntry.kline_delay : 1); - kline_queued = 1; - } - } - else - check_klines(); + check_one_kline(aconf); } break; case CONF_XLINE: From 9834d3d5baa75cf46ab8c6fbadd7ddc337728abd Mon Sep 17 00:00:00 2001 From: Ed Kellett Date: Sat, 27 Apr 2019 14:51:27 +0100 Subject: [PATCH 4/6] Remove unused kline delay machinery --- include/client.h | 1 - ircd/client.c | 13 ------------- 2 files changed, 14 deletions(-) diff --git a/include/client.h b/include/client.h index 7db9f620..9ded2c87 100644 --- a/include/client.h +++ b/include/client.h @@ -585,7 +585,6 @@ enum }; extern void check_banned_lines(void); -extern void check_klines_event(void *unused); extern void check_klines(void); extern void check_one_kline(struct ConfItem *kline); extern void check_dlines(void); diff --git a/ircd/client.c b/ircd/client.c index b25092d5..7b68f949 100644 --- a/ircd/client.c +++ b/ircd/client.c @@ -526,19 +526,6 @@ check_banned_lines(void) check_xlines(); } -/* check_klines_event() - * - * inputs - - * outputs - - * side effects - check_klines() is called, kline_queued unset - */ -void -check_klines_event(void *unused) -{ - kline_queued = false; - check_klines(); -} - /* check_klines * * inputs - From 6ca9ff0ea124fa77f33195ba114013b10b5fa0dd Mon Sep 17 00:00:00 2001 From: Ed Kellett Date: Sat, 27 Apr 2019 14:53:04 +0100 Subject: [PATCH 5/6] Remove unused kline_delay config option --- doc/ircd.conf.example | 1 - doc/reference.conf | 6 ------ include/s_conf.h | 1 - ircd/newconf.c | 10 ---------- ircd/s_conf.c | 1 - modules/m_info.c | 6 ------ 6 files changed, 25 deletions(-) diff --git a/doc/ircd.conf.example b/doc/ircd.conf.example index bfd91714..bd237946 100644 --- a/doc/ircd.conf.example +++ b/doc/ircd.conf.example @@ -579,7 +579,6 @@ general { resv_fnc = yes; global_snotices = yes; dline_with_reason = yes; - kline_delay = 0 seconds; kline_with_reason = yes; kline_reason = "K-Lined"; identify_service = "NickServ@services.int"; diff --git a/doc/reference.conf b/doc/reference.conf index c174abee..ae6060ad 100644 --- a/doc/reference.conf +++ b/doc/reference.conf @@ -1173,12 +1173,6 @@ general { */ dline_with_reason = yes; - /* kline delay: delay the checking of klines until a specified time. - * Useful if large kline lists are applied often to prevent the - * server eating CPU. - */ - kline_delay = 0 seconds; - /* kline reason: show the user the reason why they are k/dlined * on exit. may give away who set k/dline when set via tcm. */ diff --git a/include/s_conf.h b/include/s_conf.h index 0faa1bce..9744eb92 100644 --- a/include/s_conf.h +++ b/include/s_conf.h @@ -178,7 +178,6 @@ struct config_file_entry int ts_warn_delta; int dline_with_reason; int kline_with_reason; - int kline_delay; int warn_no_nline; int nick_delay; int non_redundant_klines; diff --git a/ircd/newconf.c b/ircd/newconf.c index d8b528aa..a1988545 100644 --- a/ircd/newconf.c +++ b/ircd/newconf.c @@ -1616,15 +1616,6 @@ conf_set_general_hide_error_messages(void *data) conf_report_error("Invalid setting '%s' for general::hide_error_messages.", val); } -static void -conf_set_general_kline_delay(void *data) -{ - ConfigFileEntry.kline_delay = *(unsigned int *) data; - - /* THIS MUST BE HERE to stop us being unable to check klines */ - kline_queued = false; -} - static void conf_set_general_stats_k_oper_only(void *data) { @@ -2732,7 +2723,6 @@ static struct ConfEntry conf_general_table[] = { "compression_level", CF_INT, conf_set_general_compression_level, 0, NULL }, { "havent_read_conf", CF_YESNO, conf_set_general_havent_read_conf, 0, NULL }, { "hide_error_messages",CF_STRING, conf_set_general_hide_error_messages,0, NULL }, - { "kline_delay", CF_TIME, conf_set_general_kline_delay, 0, NULL }, { "stats_k_oper_only", CF_STRING, conf_set_general_stats_k_oper_only, 0, NULL }, { "stats_i_oper_only", CF_STRING, conf_set_general_stats_i_oper_only, 0, NULL }, { "default_umodes", CF_QSTRING, conf_set_general_default_umodes, 0, NULL }, diff --git a/ircd/s_conf.c b/ircd/s_conf.c index 329129cb..a828c1aa 100644 --- a/ircd/s_conf.c +++ b/ircd/s_conf.c @@ -707,7 +707,6 @@ set_default_conf(void) ConfigFileEntry.client_exit = true; ConfigFileEntry.dline_with_reason = true; ConfigFileEntry.kline_with_reason = true; - ConfigFileEntry.kline_delay = 0; ConfigFileEntry.warn_no_nline = true; ConfigFileEntry.non_redundant_klines = true; ConfigFileEntry.stats_e_disabled = false; diff --git a/modules/m_info.c b/modules/m_info.c index 81d69a96..0f08d04d 100644 --- a/modules/m_info.c +++ b/modules/m_info.c @@ -284,12 +284,6 @@ static struct InfoStruct info_table[] = { &ConfigFileEntry.hide_spoof_ips, "Hide IPs of spoofed users" }, - { - "kline_delay", - OUTPUT_DECIMAL, - &ConfigFileEntry.kline_delay, - "Duration of time to delay kline checking" - }, { "kline_reason", OUTPUT_STRING, From b18dba6da8782fd6372d174eb25ef6976923f682 Mon Sep 17 00:00:00 2001 From: Simon Arlott Date: Sat, 31 Aug 2019 15:04:33 +0100 Subject: [PATCH 6/6] Document the process shared by check_one_kline() and find_kline() --- ircd/client.c | 2 ++ ircd/hostmask.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/ircd/client.c b/ircd/client.c index 7b68f949..9c8913d8 100644 --- a/ircd/client.c +++ b/ircd/client.c @@ -570,6 +570,8 @@ check_klines(void) /* check_one_kline() + * + * This process needs to be kept in sync with find_kline() aka find_conf_by_address(). * * inputs - pointer to kline to check * outputs - diff --git a/ircd/hostmask.c b/ircd/hostmask.c index c6e124aa..aa68603a 100644 --- a/ircd/hostmask.c +++ b/ircd/hostmask.c @@ -198,6 +198,9 @@ get_mask_hash(const char *text) /* struct ConfItem* find_conf_by_address(const char*, struct rb_sockaddr_storage*, * int type, int fam, const char *username) + * + * This process needs to be kept in sync with check_one_kline(). + * * Input: The hostname, the address, the type of mask to find, the address * family, the username. * Output: The matching value with the highest precedence.