From 7f27e3163d779e461c15c4350db32e266abd4eb7 Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Wed, 26 Dec 2007 00:51:22 +0100 Subject: [PATCH] Never allow a duplicate kline; always allow a wider kline. Duplicate klines are now disallowed regardless of no_redundant_klines. There is a somewhat hackish check to see if the new kline is wider than the existing one. --- modules/m_kline.c | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/modules/m_kline.c b/modules/m_kline.c index 3f96220b..68fe587b 100644 --- a/modules/m_kline.c +++ b/modules/m_kline.c @@ -693,13 +693,16 @@ valid_comment(struct Client *source_p, char *comment) static int already_placed_kline(struct Client *source_p, const char *luser, const char *lhost, int tkline) { - const char *reason; + const char *reason, *p; struct irc_sockaddr_storage iphost, *piphost; struct ConfItem *aconf; - int t; - if(ConfigFileEntry.non_redundant_klines) + int t, bits; + + aconf = find_exact_conf_by_address(lhost, CONF_KILL, luser); + if (aconf == NULL && ConfigFileEntry.non_redundant_klines) { - if((t = parse_netmask(lhost, (struct sockaddr *)&iphost, NULL)) != HM_HOST) + bits = 0; + if((t = parse_netmask(lhost, (struct sockaddr *)&iphost, &bits)) != HM_HOST) { #ifdef IPV6 if(t == HM_IPV6) @@ -713,19 +716,31 @@ already_placed_kline(struct Client *source_p, const char *luser, const char *lho else piphost = NULL; - if((aconf = find_conf_by_address(lhost, NULL, NULL, (struct sockaddr *)piphost, CONF_KILL, t, luser))) + aconf = find_conf_by_address(lhost, NULL, NULL, (struct sockaddr *)piphost, CONF_KILL, t, luser); + if (aconf != NULL) { - /* setting a tkline, or existing one is perm */ - if(tkline || ((aconf->flags & CONF_FLAGS_TEMPORARY) == 0)) - { - reason = aconf->passwd ? aconf->passwd : ""; + /* The above was really a lookup of a single IP, + * so check if the new kline is wider than the + * existing one. + * -- jilles + */ + p = strchr(aconf->host, '/'); + if (bits > 0 && (p == NULL || bits < atoi(p + 1))) + aconf = NULL; + } + } + if (aconf != NULL) + { + /* setting a tkline, or existing one is perm */ + if(tkline || ((aconf->flags & CONF_FLAGS_TEMPORARY) == 0)) + { + 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 1; - } + sendto_one_notice(source_p, + ":[%s@%s] already K-Lined by [%s@%s] - %s", + luser, lhost, aconf->user, + aconf->host, reason); + return 1; } }