mirror of
https://github.com/sheumann/hush.git
synced 2025-01-15 03:33:06 +00:00
not sure who made this change, but it certainly mucks things up (note 'fwrite(leases, ...'), adds a bit more code, and some stack overhead. Anywho, this fixes it, and retains the spirit of what the submitter of this change was attempting to acheive (the entire lease is written at once in a struct)
This commit is contained in:
parent
62419df95c
commit
8f43126934
@ -229,7 +229,7 @@ void write_leases(void)
|
|||||||
unsigned int i;
|
unsigned int i;
|
||||||
char buf[255];
|
char buf[255];
|
||||||
time_t curr = time(0);
|
time_t curr = time(0);
|
||||||
unsigned long lease_time;
|
unsigned long tmp_time;
|
||||||
|
|
||||||
if (!(fp = fopen(server_config.lease_file, "w"))) {
|
if (!(fp = fopen(server_config.lease_file, "w"))) {
|
||||||
LOG(LOG_ERR, "Unable to open %s for writing", server_config.lease_file);
|
LOG(LOG_ERR, "Unable to open %s for writing", server_config.lease_file);
|
||||||
@ -237,17 +237,21 @@ void write_leases(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < server_config.max_leases; i++) {
|
for (i = 0; i < server_config.max_leases; i++) {
|
||||||
struct dhcpOfferedAddr lease;
|
|
||||||
if (leases[i].yiaddr != 0) {
|
if (leases[i].yiaddr != 0) {
|
||||||
|
|
||||||
|
/* screw with the time in the struct, for easier writing */
|
||||||
|
tmp_time = leases[i].expires;
|
||||||
|
|
||||||
if (server_config.remaining) {
|
if (server_config.remaining) {
|
||||||
if (lease_expired(&(leases[i])))
|
if (lease_expired(&(leases[i])))
|
||||||
lease_time = 0;
|
leases[i].expires = 0;
|
||||||
else lease_time = leases[i].expires - curr;
|
else leases[i].expires -= curr;
|
||||||
} else lease_time = leases[i].expires;
|
} /* else stick with the time we got */
|
||||||
lease.expires = htonl(lease_time);
|
leases[i].expires = htonl(leases[i].expires);
|
||||||
memcpy(lease.chaddr, leases[i].chaddr, 16);
|
fwrite(leases[i], sizeof(sturct dhcpOfferedAddr), 1, fp);
|
||||||
lease.yiaddr = leases[i].yiaddr;
|
|
||||||
fwrite(leases, sizeof(lease), 1, fp);
|
/* Then restore it when done. */
|
||||||
|
leases[i].expires = tmp_time;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user