-/* Copyright (C) 2009-2012, Martin Johansson <martin@fatbob.nu>
- Copyright (C) 2005-2012, Thorvald Natvig <thorvald@natvig.com>
+/* Copyright (C) 2009-2014, Martin Johansson <martin@fatbob.nu>
+ Copyright (C) 2005-2014, Thorvald Natvig <thorvald@natvig.com>
All rights reserved.
void Ban_deinit(void)
{
- /* Save banlist */
+ /* Save banlist */
if (getStrConf(BANFILE) != NULL)
Ban_saveBanFile();
-
+
Ban_clearBanList();
}
if (ban == NULL)
Log_fatal("Out of memory");
memset(ban, 0, sizeof(ban_t));
-
+
memcpy(ban->hash, client->hash, 20);
memcpy(&ban->address, &client->remote_tcp.sin_addr, sizeof(in_addr_t));
ban->mask = 128;
banlist_changed = true;
if(getBoolConf(SYNC_BANFILE))
Ban_saveBanFile();
-
+
SSLi_hash2hex(ban->hash, hexhash);
Log_info_client(client, "User kickbanned. Reason: '%s' Hash: %s IP: %s Banned for: %d seconds",
- ban->name, ban->reason, hexhash, inet_ntoa(*((struct in_addr *)&ban->address)),
- ban->duration);
+ ban->reason, hexhash, inet_ntoa(*((struct in_addr *)&ban->address)), ban->duration);
}
ban_t *ban;
char hexhash[41];
uint64_t bantime_long;
-
+
list_iterate(itr, &banlist) {
ban = list_get_entry(itr, ban_t, node);
bantime_long = ban->duration * 1000000LL;
ban_t *ban;
list_iterate(itr, &banlist) {
ban = list_get_entry(itr, ban_t, node);
- if (memcmp(ban->hash, client->hash, 20) == 0)
+ if (memcmp(ban->hash, client->hash, 20) == 0)
return true;
}
return false;
-
+
}
bool_t Ban_isBannedAddr(in_addr_t *addr)
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;
tempaddr1 &= (2 ^ mask) - 1;
tempaddr2 &= (2 ^ mask) - 1;
}
- if (memcmp(&tempaddr1, &tempaddr2, sizeof(in_addr_t)) == 0)
+ if (memcmp(&tempaddr1, &tempaddr2, sizeof(in_addr_t)) == 0)
return true;
}
return false;
char timestr[32];
char hexhash[41];
uint8_t address[16];
-
+
msg = Msg_banList_create(bancount);
list_iterate(itr, &banlist) {
ban = list_get_entry(itr, ban_t, node);
char *hexhash, *name, *reason, *start;
uint32_t duration, mask;
uint8_t *address;
-
+
for (i = 0; i < n_bans; i++) {
Msg_banList_getEntry(msg, i, &address, &mask, &name, &hexhash, &reason, &start, &duration);
ban = malloc(sizeof(ban_t));
ban->name = strdup(name);
strptime(start, "%Y-%m-%dT%H:%M:%S", ×pec);
ban->time = mktime(×pec);
- Timer_init(&ban->startTime);
+ ban->startTime = ban->time * 1000000LL;
ban->duration = duration;
list_add_tail(&ban->node, &banlist);
bancount++;
list_iterate(itr, &banlist) {
ban = list_get_entry(itr, ban_t, node);
SSLi_hash2hex(ban->hash, hexhash);
- fprintf(file, "%s,%s,%d,%d,%d,%s,%s\n", hexhash, inet_ntoa(*((struct in_addr *)&ban->address)),
- ban->mask, ban->time, ban->duration, ban->name, ban->reason);
+ fprintf(file, "%s,%s,%d,%ld,%d,%s,%s\n", hexhash, inet_ntoa(*((struct in_addr *)&ban->address)),
+ ban->mask, (long int)ban->time, ban->duration, ban->name, ban->reason);
}
fclose(file);
+ banlist_changed = false;
+ Log_info("Banlist file '%s': %d entries written", getStrConf(BANFILE), bancount);
}
static void Ban_readBanFile(void)
{
struct dlist *itr;
ban_t *ban;
- char line[512], *hexhash, *address, *name, *reason;
+ char line[1024], *hexhash, *address, *name, *reason;
uint32_t mask, duration;
time_t time;
char *p;
Log_warn("Could not read banlist file %s: %s", getStrConf(BANFILE), strerror(errno));
return;
}
- while (fgets(line, 512, file) != NULL) {
+ while (fgets(line, 1024, file) != NULL) {
p = strtok(line, ",");
hexhash = p;
p = strtok(NULL, ",");
p = strtok(NULL, "\n");
if (p == NULL) break;
reason = p;
-
+
ban = malloc(sizeof(ban_t));
if (ban == NULL)
Log_fatal("Out of memory");
inet_aton(address, (struct in_addr *)&ban->address);
ban->name = strdup(name);
ban->reason = strdup(reason);
+ if (ban->name == NULL || ban->reason == NULL)
+ Log_fatal("Out of memory");
ban->time = time;
ban->duration = duration;
ban->mask = mask;
- Timer_init(&ban->startTime);
+ ban->startTime = ban->time * 1000000LL;
list_add_tail(&ban->node, &banlist);
bancount++;
Log_debug("Banfile: H = '%s' A = '%s' M = %d U = '%s' R = '%s'", hexhash, address, ban->mask, ban->name, ban->reason);
}
fclose(file);
+ Log_info("Banlist file '%s': %d entries read", getStrConf(BANFILE), bancount);
}