210-dnssec-improve-timestamp-heuristic.patch 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. From 79e60e145f8a595bca5a784c00b437216d51de68 Mon Sep 17 00:00:00 2001
  2. From: Steven Barth <steven@midlink.org>
  3. Date: Mon, 13 Apr 2015 09:45:20 +0200
  4. Subject: [PATCH] dnssec: improve timestamp heuristic
  5. Signed-off-by: Steven Barth <steven@midlink.org>
  6. ---
  7. src/dnssec.c | 15 +++++++++++----
  8. 1 file changed, 11 insertions(+), 4 deletions(-)
  9. --- a/src/dnssec.c
  10. +++ b/src/dnssec.c
  11. @@ -462,17 +462,24 @@ static time_t timestamp_time;
  12. int setup_timestamp(void)
  13. {
  14. struct stat statbuf;
  15. + time_t now;
  16. + time_t base = 1420070400; /* 1-1-2015 */
  17. daemon->back_to_the_future = 0;
  18. if (!daemon->timestamp_file)
  19. return 0;
  20. +
  21. + now = time(NULL);
  22. +
  23. + if (!stat("/proc/self/exe", &statbuf) && difftime(statbuf.st_mtime, base) > 0)
  24. + base = statbuf.st_mtime;
  25. if (stat(daemon->timestamp_file, &statbuf) != -1)
  26. {
  27. timestamp_time = statbuf.st_mtime;
  28. check_and_exit:
  29. - if (difftime(timestamp_time, time(0)) <= 0)
  30. + if (difftime(now, base) >= 0 && difftime(timestamp_time, now) <= 0)
  31. {
  32. /* time already OK, update timestamp, and do key checking from the start. */
  33. if (utime(daemon->timestamp_file, NULL) == -1)
  34. @@ -493,7 +500,7 @@ int setup_timestamp(void)
  35. close(fd);
  36. - timestamp_time = timbuf.actime = timbuf.modtime = 1420070400; /* 1-1-2015 */
  37. + timestamp_time = timbuf.actime = timbuf.modtime = base;
  38. if (utime(daemon->timestamp_file, &timbuf) == 0)
  39. goto check_and_exit;
  40. }