From 00abd9e6c86fbd46954db918777fced50c177abb Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Mon, 30 Apr 2018 16:59:40 +0200 Subject: [PATCH] miniupnpd: store UNIX time in lease_file fixes #295 --- miniupnpd/upnpredirect.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/miniupnpd/upnpredirect.c b/miniupnpd/upnpredirect.c index f4071ef..a56a13a 100644 --- a/miniupnpd/upnpredirect.c +++ b/miniupnpd/upnpredirect.c @@ -109,6 +109,10 @@ lease_file_add(unsigned short eport, return -1; } + /* convert our time to unix time */ + timestamp -= upnp_time(); + timestamp += time(NULL); + fprintf(fd, "%s:%hu:%s:%hu:%u:%s\n", proto_itoa(proto), eport, iaddr, iport, timestamp, desc); @@ -190,6 +194,7 @@ int reload_from_lease_file() unsigned int leaseduration; unsigned int timestamp; time_t current_time; + time_t current_unix_time; char line[128]; int r; @@ -204,6 +209,7 @@ int reload_from_lease_file() } current_time = upnp_time(); + current_unix_time = time(NULL); while(fgets(line, sizeof(line), fd)) { syslog(LOG_DEBUG, "parsing lease file line '%s'", line); proto = line; @@ -251,11 +257,12 @@ int reload_from_lease_file() *(p--) = '\0'; if(timestamp > 0) { - if(timestamp <= (unsigned int)current_time) { + if(timestamp <= (unsigned int)current_unix_time) { syslog(LOG_NOTICE, "already expired lease in lease file"); continue; } else { - leaseduration = timestamp - current_time; + leaseduration = timestamp - current_unix_time; + timestamp = lease_duration + current_time; } } else { leaseduration = 0; /* default value */