X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;ds=sidebyside;f=src%2Fban.c;h=8e5e3954f470b2351b83bb48d5721dcc74f829a2;hb=cac4b71f9ea600608b421127df1f80407182e405;hp=5e2d2654b53f3209c1ada5d1db9211dc216f2448;hpb=cd7783013d9870192bff4fa57e79e735ade68ed5;p=umurmur.git diff --git a/src/ban.c b/src/ban.c index 5e2d265..8e5e395 100644 --- a/src/ban.c +++ b/src/ban.c @@ -1,5 +1,5 @@ -/* Copyright (C) 2009-2012, Martin Johansson - Copyright (C) 2005-2012, Thorvald Natvig +/* Copyright (C) 2009-2013, Martin Johansson + Copyright (C) 2005-2013, Thorvald Natvig All rights reserved. @@ -59,7 +59,7 @@ void Ban_deinit(void) /* Save banlist */ if (getStrConf(BANFILE) != NULL) Ban_saveBanFile(); - + Ban_clearBanList(); } @@ -89,8 +89,7 @@ void Ban_UserBan(client_t *client, char *reason) 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); } @@ -227,7 +226,7 @@ void Ban_putBanList(message_t *msg, int n_bans) 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++; @@ -254,17 +253,19 @@ static void Ban_saveBanFile(void) 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; @@ -275,7 +276,7 @@ static void Ban_readBanFile(void) 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, ","); @@ -305,13 +306,16 @@ static void Ban_readBanFile(void) 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); }