X-Git-Url: https://jfr.im/git/solanum.git/blobdiff_plain/a92275551218402bf4969a7fe613cab27416c4ef..c1b01bf5ec318463ab076ac2d7c0a4b02631f745:/modules/m_kline.c diff --git a/modules/m_kline.c b/modules/m_kline.c index e478f50d..b5d5acda 100644 --- a/modules/m_kline.c +++ b/modules/m_kline.c @@ -81,10 +81,23 @@ static void apply_prop_kline(struct Client *source_p, struct ConfItem *aconf, static bool already_placed_kline(struct Client *, const char *, const char *, int); static void handle_remote_unkline(struct Client *source_p, const char *user, const char *host); +static void remove_superseded_klines(const char *user, const char *host); 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 *); +static bool +is_local_kline(struct ConfItem *aconf) +{ + return aconf->lifetime == 0; +} + +static bool +is_temporary_kline(struct ConfItem *aconf) +{ + return aconf->lifetime == 0 && (aconf->flags & CONF_FLAGS_TEMPORARY); +} + /* mo_kline() * @@ -152,6 +165,11 @@ mo_kline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source } reason = LOCAL_COPY(parv[loc]); + if(strlen(reason) > BANREASONLEN) + { + sendto_one_notice(source_p, ":K-Line reason exceeds %d characters", BANREASONLEN); + return; + } if(parse_netmask_strict(host, NULL, NULL) == HM_ERROR) { @@ -209,6 +227,9 @@ mo_kline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source if(already_placed_kline(source_p, user, host, tkline_time)) return; + if (!propagated) + remove_superseded_klines(user, host); + rb_set_time(); aconf = make_conf(); aconf->status = CONF_KILL; @@ -218,9 +239,6 @@ mo_kline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source aconf->port = 0; aconf->info.oper = operhash_add(get_oper_name(source_p)); - if(strlen(reason) > BANREASONLEN) - reason[BANREASONLEN] = '\0'; - /* Look for an oper reason */ if((oper_reason = strchr(reason, '|')) != NULL) { @@ -307,6 +325,8 @@ handle_remote_kline(struct Client *source_p, int tkline_time, if(already_placed_kline(source_p, user, host, tkline_time)) return; + remove_superseded_klines(user, host); + aconf = make_conf(); aconf->status = CONF_KILL; @@ -418,25 +438,30 @@ mo_unkline(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *sour cluster_generic(source_p, "UNKLINE", SHARED_UNKLINE, CAP_UNKLN, "%s %s", user, host); - if(aconf == NULL) + bool removed_kline = false; + + while (aconf = find_exact_conf_by_address_filtered(host, CONF_KILL, user, is_local_kline), aconf != NULL) { - sendto_one_notice(source_p, ":No K-Line for %s@%s", user, host); - return; + removed_kline = true; + + if(remove_temp_kline(source_p, aconf)) + continue; + + remove_permkline_match(source_p, aconf); } - if(aconf->lifetime) + aconf = find_exact_conf_by_address(host, CONF_KILL, user); + if (aconf) { - if(propagated) + if (propagated) remove_prop_kline(source_p, aconf); else sendto_one_notice(source_p, ":Cannot remove global K-Line %s@%s on specific servers", user, host); - return; } - - if(remove_temp_kline(source_p, aconf)) - return; - - remove_permkline_match(source_p, aconf); + else if (!removed_kline) + { + sendto_one_notice(source_p, ":No K-Line for %s@%s", user, host); + } } /* ms_unkline() @@ -475,23 +500,22 @@ static void handle_remote_unkline(struct Client *source_p, const char *user, const char *host) { struct ConfItem *aconf; + bool removed_kline = false; - aconf = find_exact_conf_by_address(host, CONF_KILL, user); - if(aconf == NULL) - { - sendto_one_notice(source_p, ":No K-Line for %s@%s", user, host); - return; - } - if(aconf->lifetime) + while (aconf = find_exact_conf_by_address_filtered(host, CONF_KILL, user, is_local_kline), aconf != NULL) { - sendto_one_notice(source_p, ":Cannot remove global K-Line %s@%s on specific servers", user, host); - return; - } + removed_kline = true; - if(remove_temp_kline(source_p, aconf)) - return; + if(remove_temp_kline(source_p, aconf)) + continue; + + remove_permkline_match(source_p, aconf); + } - remove_permkline_match(source_p, aconf); + if (find_exact_conf_by_address(host, CONF_KILL, user)) + sendto_one_notice(source_p, ":Cannot remove global K-Line %s@%s on specific servers", user, host); + else if (!removed_kline) + sendto_one_notice(source_p, ":No K-Line for %s@%s", user, host); } /* apply_kline() @@ -580,7 +604,7 @@ apply_prop_kline(struct Client *source_p, struct ConfItem *aconf, replace_old_ban(aconf); - rb_dlinkAddAlloc(aconf, &prop_bans); + add_prop_ban(aconf); add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf); /* no oper reason.. */ @@ -734,21 +758,46 @@ already_placed_kline(struct Client *source_p, const char *luser, const char *lho aconf = NULL; } } - if(aconf != NULL) + + if (aconf == NULL) + return false; + + /* allow klines to be duplicated by longer ones */ + if ((aconf->flags & CONF_FLAGS_TEMPORARY) && + (tkline == 0 || tkline > aconf->hold - rb_current_time())) + return false; + + reason = aconf->passwd ? aconf->passwd : ""; + + sendto_one_notice(source_p, + ":[%s@%s] already K-Lined by [%s@%s] - %s", + luser, lhost, aconf->user, aconf->host, reason); + return true; +} + +static void +remove_superseded_klines(const char *user, const char *host) +{ + struct ConfItem *aconf; + + while (aconf = find_exact_conf_by_address_filtered(host, CONF_KILL, user, is_temporary_kline), aconf != NULL) { - /* setting a tkline, or existing one is perm */ - if(tkline || ((aconf->flags & CONF_FLAGS_TEMPORARY) == 0)) - { - reason = aconf->passwd ? aconf->passwd : ""; + rb_dlink_node *ptr; + int i; - sendto_one_notice(source_p, - ":[%s@%s] already K-Lined by [%s@%s] - %s", - luser, lhost, aconf->user, aconf->host, reason); - return true; + for (i = 0; i < LAST_TEMP_TYPE; i++) + { + RB_DLINK_FOREACH(ptr, temp_klines[i].head) + { + if (aconf == ptr->data) + { + rb_dlinkDestroy(ptr, &temp_klines[i]); + delete_one_address_conf(aconf->host, aconf); + break; + } + } } } - - return false; } /* remove_permkline_match() @@ -813,11 +862,9 @@ remove_temp_kline(struct Client *source_p, struct ConfItem *aconf) static void remove_prop_kline(struct Client *source_p, struct ConfItem *aconf) { - rb_dlink_node *ptr; time_t now; - ptr = rb_dlinkFind(aconf, &prop_bans); - if (!ptr) + if (!lookup_prop_ban(aconf)) return; sendto_one_notice(source_p, ":Un-klined [%s@%s] from global k-lines", @@ -845,5 +892,5 @@ remove_prop_kline(struct Client *source_p, struct ConfItem *aconf) 0, (int)(aconf->lifetime - aconf->created)); remove_reject_mask(aconf->user, aconf->host); - deactivate_conf(aconf, ptr, now); + deactivate_conf(aconf, now); }