From 4e0f14a0e8bf66bd3d1f974defc9d89d88cb5cd0 Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Wed, 28 Nov 2007 23:59:49 +0100 Subject: [PATCH] Add find_exact_conf_by_address() to find klines etc by exact mask. --- include/hostmask.h | 2 ++ src/hostmask.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/include/hostmask.h b/include/hostmask.h index ebd8bfc..191cce5 100644 --- a/include/hostmask.h +++ b/include/hostmask.h @@ -40,6 +40,8 @@ int parse_netmask(const char *, struct sockaddr *, int *); struct ConfItem *find_conf_by_address(const char *host, const char *sockhost, const char *orighost, struct sockaddr *, int, int, const char *); +struct ConfItem *find_exact_conf_by_address(const char *address, int type, + const char *username); void add_conf_by_address(const char *, int, const char *, struct ConfItem *); void delete_one_address_conf(const char *, struct ConfItem *); void clear_out_address_conf(void); diff --git a/src/hostmask.c b/src/hostmask.c index 334be58..d45dc11 100644 --- a/src/hostmask.c +++ b/src/hostmask.c @@ -432,6 +432,63 @@ find_dline(struct sockaddr *addr, int aftype) return find_conf_by_address(NULL, NULL, NULL, addr, CONF_DLINE | 1, aftype, NULL); } +/* void find_exact_conf_by_address(const char*, int, const char *, + * struct ConfItem *aconf) + * Input: + * Output: ConfItem if found + * Side-effects: None + */ +struct ConfItem * +find_exact_conf_by_address(const char *address, int type, const char *username) +{ + int masktype, bits; + unsigned long hv; + struct AddressRec *arec; + struct irc_sockaddr_storage addr; + + if(address == NULL) + address = "/NOMATCH!/"; + arec = MyMalloc(sizeof(struct AddressRec)); + masktype = parse_netmask(address, (struct sockaddr *)&addr, &bits); +#ifdef IPV6 + if(masktype == HM_IPV6) + { + /* We have to do this, since we do not re-hash for every bit -A1kmm. */ + hv = hash_ipv6((struct sockaddr *)&addr, bits - bits % 16); + } + else +#endif + if(masktype == HM_IPV4) + { + /* We have to do this, since we do not re-hash for every bit -A1kmm. */ + hv = hash_ipv4((struct sockaddr *)&addr, bits - bits % 8); + } + else + { + hv = get_mask_hash(address); + } + for (arec = atable[hv]; arec; arec = arec->next) + { + if (arec->type == type && + arec->masktype == masktype && + !irccmp(arec->username, username)) + { + if (masktype == HM_HOST) + { + if (!irccmp(arec->Mask.hostname, address)) + return arec->aconf; + } + else + { + if (arec->Mask.ipa.bits == bits && + comp_with_mask_sock((struct sockaddr *)&arec->Mask.ipa.addr, (struct sockaddr *)&addr, bits)) + return arec->aconf; + } + } + } + return NULL; +} + /* void add_conf_by_address(const char*, int, const char *, * struct ConfItem *aconf) * Input: