}
-bool_t Ban_isBannedAddr(in_addr_t *addr)
+bool_t Ban_isBannedAddr(struct sockaddr_storage *address)
{
struct dlist *itr;
ban_t *ban;
- int mask;
in_addr_t tempaddr1, tempaddr2;
list_iterate(itr, &banlist) {
ban = list_get_entry(itr, ban_t, node);
- mask = ban->mask - 96;
- if (mask < 32) { /* XXX - only ipv4 support */
- memcpy(&tempaddr1, addr, sizeof(in_addr_t));
- memcpy(&tempaddr2, &ban->address, sizeof(in_addr_t));
- tempaddr1 &= (2 ^ mask) - 1;
- tempaddr2 &= (2 ^ mask) - 1;
+
+ if(ban->mask == sizeof(in_addr_t)) {
+ if(memcmp(ban->address, &((struct sockaddr_in *)address)->sin_addr, ban->mask) == 0)
+ return true;
+ }
+ else {
+ if(memcmp(ban->address, &((struct sockaddr_in6 *)address)->sin6_addr, ban->mask) == 0)
+ return true;
}
- if (memcmp(&tempaddr1, &tempaddr2, sizeof(in_addr_t)) == 0)
- return true;
}
return false;
}
void Ban_UserBan(client_t *client, char *reason);
void Ban_pruneBanned();
bool_t Ban_isBanned(client_t *client);
-bool_t Ban_isBannedAddr(in_addr_t *addr);
+bool_t Ban_isBannedAddr(struct sockaddr_storage *address);
int Ban_getBanCount(void);
message_t *Ban_getBanList(void);
void Ban_putBanList(message_t *msg, int n_bans);
char addressPresentation[INET6_ADDRSTRLEN];
int port;
-#warning FIX BANNING BEFORE RELEASE
-#if 0
- if (Ban_isBannedAddr((in_addr_t *)&remote->sin_addr)) {
- Log_info("Address %s banned. Disconnecting", inet_ntoa(remote->sin_addr));
- return -1;
- }
-#endif
-
- if ((newclient = calloc(1, sizeof(client_t))) == NULL)
- Log_fatal("Out of memory (%s:%s)", __FILE__, __LINE__);
-
if(remote->ss_family == AF_INET) {
inet_ntop(AF_INET, &((struct sockaddr_in*)remote)->sin_addr, addressPresentation, INET6_ADDRSTRLEN);
port = ntohs(((struct sockaddr_in*)remote)->sin_port);
port = ntohs(((struct sockaddr_in6*)remote)->sin6_port);
}
+ if (Ban_isBannedAddr(remote)) {
+ Log_info("Address %s banned. Disconnecting", addressPresentation);
+ return -1;
+ }
+
+ if ((newclient = calloc(1, sizeof(client_t))) == NULL)
+ Log_fatal("Out of memory (%s:%s)", __FILE__, __LINE__);
+
memcpy(newclient->addressString, addressPresentation, INET6_ADDRSTRLEN);
newclient->tcpfd = fd;