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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. @@ -432,17 +432,24 @@ static int back_to_the_future;
  12. int setup_timestamp(void)
  13. {
  14. struct stat statbuf;
  15. -
  16. + time_t now;
  17. + time_t base = 1420070400; /* 1-1-2015 */
  18. +
  19. back_to_the_future = 0;
  20. if (!daemon->timestamp_file)
  21. return 0;
  22. -
  23. +
  24. + now = time(NULL);
  25. +
  26. + if (!stat("/proc/self/exe", &statbuf) && difftime(statbuf.st_mtime, base) > 0)
  27. + base = statbuf.st_mtime;
  28. +
  29. if (stat(daemon->timestamp_file, &statbuf) != -1)
  30. {
  31. timestamp_time = statbuf.st_mtime;
  32. check_and_exit:
  33. - if (difftime(timestamp_time, time(0)) <= 0)
  34. + if (difftime(now, base) >= 0 && difftime(timestamp_time, now) <= 0)
  35. {
  36. /* time already OK, update timestamp, and do key checking from the start. */
  37. if (utime(daemon->timestamp_file, NULL) == -1)
  38. @@ -463,7 +470,7 @@ int setup_timestamp(void)
  39. close(fd);
  40. - timestamp_time = timbuf.actime = timbuf.modtime = 1420070400; /* 1-1-2015 */
  41. + timestamp_time = timbuf.actime = timbuf.modtime = base;
  42. if (utime(daemon->timestamp_file, &timbuf) == 0)
  43. goto check_and_exit;
  44. }