aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2009-02-02 10:48:06 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2009-02-02 10:48:06 +0000
commit04158e04591efea20f34c8dc83002e19056a5590 (patch)
tree1deace5081207ddefa831e024e5914a11a8aaeeb /networking
parent512c8ae0537ad2ffcb70db03ca50b532781ae799 (diff)
downloadbusybox-w32-04158e04591efea20f34c8dc83002e19056a5590.tar.gz
busybox-w32-04158e04591efea20f34c8dc83002e19056a5590.tar.bz2
busybox-w32-04158e04591efea20f34c8dc83002e19056a5590.zip
udhcpd: add code which rejects lease files with suspicious or old timestamp.
*: s/time(0)/time(NULL)/g
Diffstat (limited to 'networking')
-rw-r--r--networking/httpd.c2
-rw-r--r--networking/udhcp/dhcpd.c4
-rw-r--r--networking/udhcp/files.c32
3 files changed, 20 insertions, 18 deletions
diff --git a/networking/httpd.c b/networking/httpd.c
index 3a2e6b14b..fc8b51240 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -969,7 +969,7 @@ static void send_headers(int responseNum)
969 const char *error_page = NULL; 969 const char *error_page = NULL;
970#endif 970#endif
971 unsigned i; 971 unsigned i;
972 time_t timer = time(0); 972 time_t timer = time(NULL);
973 char tmp_str[80]; 973 char tmp_str[80];
974 int len; 974 int len;
975 975
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c
index d0a1eba81..ebf30178a 100644
--- a/networking/udhcp/dhcpd.c
+++ b/networking/udhcp/dhcpd.c
@@ -255,13 +255,13 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
255 DEBUG("Received DECLINE"); 255 DEBUG("Received DECLINE");
256 if (lease) { 256 if (lease) {
257 memset(lease->chaddr, 0, 16); 257 memset(lease->chaddr, 0, 16);
258 lease->expires = time(0) + server_config.decline_time; 258 lease->expires = time(NULL) + server_config.decline_time;
259 } 259 }
260 break; 260 break;
261 case DHCPRELEASE: 261 case DHCPRELEASE:
262 DEBUG("Received RELEASE"); 262 DEBUG("Received RELEASE");
263 if (lease) 263 if (lease)
264 lease->expires = time(0); 264 lease->expires = time(NULL);
265 break; 265 break;
266 case DHCPINFORM: 266 case DHCPINFORM:
267 DEBUG("Received INFORM"); 267 DEBUG("Received INFORM");
diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c
index 64edcbb25..fb6fe01ae 100644
--- a/networking/udhcp/files.c
+++ b/networking/udhcp/files.c
@@ -36,6 +36,7 @@ static int read_ip(const char *line, void *arg)
36 return 1; 36 return 1;
37} 37}
38 38
39
39static int read_mac(const char *line, void *arg) 40static int read_mac(const char *line, void *arg)
40{ 41{
41 return NULL == ether_aton_r(line, (struct ether_addr *)arg); 42 return NULL == ether_aton_r(line, (struct ether_addr *)arg);
@@ -362,7 +363,7 @@ void FAST_FUNC write_leases(void)
362 if (leases[i].yiaddr == 0) 363 if (leases[i].yiaddr == 0)
363 continue; 364 continue;
364 365
365 /* screw with the time in the struct, for easier writing */ 366 /* Screw with the time in the struct, for easier writing */
366 tmp_time = leases[i].expires; 367 tmp_time = leases[i].expires;
367 368
368 leases[i].expires -= curr; 369 leases[i].expires -= curr;
@@ -374,7 +375,7 @@ void FAST_FUNC write_leases(void)
374 * we lose some leases on restart. Oh well. */ 375 * we lose some leases on restart. Oh well. */
375 full_write(fd, &leases[i], sizeof(leases[i])); 376 full_write(fd, &leases[i], sizeof(leases[i]));
376 377
377 /* then restore it when done */ 378 /* Then restore it when done */
378 leases[i].expires = tmp_time; 379 leases[i].expires = tmp_time;
379 } 380 }
380 close(fd); 381 close(fd);
@@ -390,10 +391,10 @@ void FAST_FUNC write_leases(void)
390 391
391void FAST_FUNC read_leases(const char *file) 392void FAST_FUNC read_leases(const char *file)
392{ 393{
393 int fd;
394 unsigned i;
395 struct dhcpOfferedAddr lease; 394 struct dhcpOfferedAddr lease;
396 int64_t written_at, curr; 395 int64_t written_at, time_passed;
396 int fd;
397 USE_UDHCP_DEBUG(unsigned i;)
397 398
398 fd = open_or_warn(file, O_RDONLY); 399 fd = open_or_warn(file, O_RDONLY);
399 if (fd < 0) 400 if (fd < 0)
@@ -402,18 +403,19 @@ void FAST_FUNC read_leases(const char *file)
402 if (full_read(fd, &written_at, sizeof(written_at)) != sizeof(written_at)) 403 if (full_read(fd, &written_at, sizeof(written_at)) != sizeof(written_at))
403 goto ret; 404 goto ret;
404 written_at = ntoh64(written_at); 405 written_at = ntoh64(written_at);
405 curr = time(NULL); 406
406 if (curr < written_at) 407 time_passed = time(NULL) - written_at;
407 written_at = curr; /* lease file from future! :) */ 408 /* Strange written_at, or lease file from old version of udhcpd
408 409 * which had no "written_at" field? */
409 i = 0; 410 if ((uint64_t)time_passed > 12 * 60 * 60)
410 while (i < server_config.max_leases 411 goto ret;
411 && full_read(fd, &lease, sizeof(lease)) == sizeof(lease) 412
412 ) { 413 USE_UDHCP_DEBUG(i = 0;)
414 while (full_read(fd, &lease, sizeof(lease)) == sizeof(lease)) {
413 /* ADDME: what if it matches some static lease? */ 415 /* ADDME: what if it matches some static lease? */
414 uint32_t y = ntohl(lease.yiaddr); 416 uint32_t y = ntohl(lease.yiaddr);
415 if (y >= server_config.start_ip && y <= server_config.end_ip) { 417 if (y >= server_config.start_ip && y <= server_config.end_ip) {
416 int64_t expires = ntohl(lease.expires) + written_at - curr; 418 signed_leasetime_t expires = ntohl(lease.expires) - (signed_leasetime_t)time_passed;
417 if (expires <= 0) 419 if (expires <= 0)
418 continue; 420 continue;
419 /* NB: add_lease takes "relative time", IOW, 421 /* NB: add_lease takes "relative time", IOW,
@@ -422,7 +424,7 @@ void FAST_FUNC read_leases(const char *file)
422 bb_error_msg("too many leases while loading %s", file); 424 bb_error_msg("too many leases while loading %s", file);
423 break; 425 break;
424 } 426 }
425 i++; 427 USE_UDHCP_DEBUG(i++;)
426 } 428 }
427 } 429 }
428 DEBUG("Read %d leases", i); 430 DEBUG("Read %d leases", i);