You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
3.0 KiB

  1. #!/bin/sh
  2. ##############################################################################
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License version 2 as
  6. # published by the Free Software Foundation.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # Copyright (C) 2016 Eric Luehrsen
  14. #
  15. ##############################################################################
  16. #
  17. # This component needs to be used within the unbound.sh as an include. It uses
  18. # defaults and UCI scope variables defined there. It will copy root.key back
  19. # to /etc/unbound/ periodically, but avoid ROM flash abuse (UCI option).
  20. #
  21. ##############################################################################
  22. rootzone_uci() {
  23. # TODO: Just structure to real UCI coming soon.
  24. echo
  25. }
  26. ##############################################################################
  27. roothints_update() {
  28. # TODO: Maybe this will not be implemented.
  29. echo
  30. }
  31. ##############################################################################
  32. rootkey_update() {
  33. local basekey_date rootkey_date rootkey_age filestuff
  34. # TODO: Just structure to real UCI coming soon.
  35. if [ "$UNBOUND_N_ROOT_AGE" -gt 90 -o "$UNBOUND_B_DNSSEC" -lt 1 ] ; then
  36. # Feature disabled
  37. return 0
  38. fi
  39. if [ -f /etc/unbound/root.key ] ; then
  40. basekey_date=$( date -r /etc/unbound/root.key +%s )
  41. else
  42. # No persistent storage key
  43. basekey_date=$( date -d 2000-01-01 +%s )
  44. fi
  45. if [ -f "$UNBOUND_KEYFILE" ] ; then
  46. # Unbound maintains it itself
  47. rootkey_date=$( date -r $UNBOUND_KEYFILE +%s )
  48. rootkey_age=$(( (rootkey_date - basekey_date) / 86440 ))
  49. elif [ -x "$UNBOUND_ANCHOR" ] ; then
  50. # No tmpfs key - use unbound-anchor
  51. rootkey_date=$( date -I +%s )
  52. rootkey_age=$(( (rootkey_date - basekey_date) / 86440 ))
  53. $UNBOUND_ANCHOR -a $UNBOUND_KEYFILE
  54. else
  55. # give up
  56. rootkey_age=0
  57. fi
  58. if [ "$rootkey_age" -gt "$UNBOUND_N_ROOT_AGE" ] ; then
  59. filestuff=$( cat $UNBOUND_KEYFILE )
  60. case "$filestuff" in
  61. *NOERROR*)
  62. # Header comment for drill and dig
  63. logger -t unbound -s "root.key updated after $rootkey_age days"
  64. cp -p $UNBOUND_KEYFILE /etc/unbound/root.key
  65. ;;
  66. *"state=2 [ VALID ]"*)
  67. # Comment inline to key for unbound-anchor
  68. logger -t unbound -s "root.key updated after $rootkey_age days"
  69. cp -p $UNBOUND_KEYFILE /etc/unbound/root.key
  70. ;;
  71. *)
  72. logger -t unbound -s "root.key still $rootkey_age days old"
  73. ;;
  74. esac
  75. fi
  76. }
  77. ##############################################################################
  78. rootzone_update() {
  79. rootzone_uci
  80. roothints_update
  81. rootkey_update
  82. }
  83. ##############################################################################