Portable build framework for OpenNTPD
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.

43 lines
1.2 KiB

3 years ago
  1. From 063ba13b18c72994a3fdf9a3db04b56cc5a6738c Mon Sep 17 00:00:00 2001
  2. From: Brent Cook <busterb@gmail.com>
  3. Date: Mon, 8 Jun 2020 06:53:53 -0500
  4. Subject: [PATCH 17/18] handle KERN_SECURELVL when available
  5. ---
  6. src/usr.sbin/ntpd/ntpd.c | 8 ++++++--
  7. 1 file changed, 6 insertions(+), 2 deletions(-)
  8. diff --git a/src/usr.sbin/ntpd/ntpd.c b/src/usr.sbin/ntpd/ntpd.c
  9. index bae6abd00f..7ea24dc58c 100644
  10. --- a/src/usr.sbin/ntpd/ntpd.c
  11. +++ b/src/usr.sbin/ntpd/ntpd.c
  12. @@ -23,7 +23,9 @@
  13. #include <sys/types.h>
  14. #include <sys/resource.h>
  15. #include <sys/socket.h>
  16. +#ifdef KERN_SECURELVL
  17. #include <sys/sysctl.h>
  18. +#endif
  19. #include <sys/wait.h>
  20. #include <sys/un.h>
  21. #include <netinet/in.h>
  22. @@ -123,12 +125,14 @@ usage(void)
  23. int
  24. auto_preconditions(const struct ntpd_conf *cnf)
  25. {
  26. + int constraints, securelevel = 0;
  27. +
  28. +#ifdef KERN_SECURELVL
  29. int mib[2] = { CTL_KERN, KERN_SECURELVL };
  30. - int constraints, securelevel;
  31. size_t sz = sizeof(int);
  32. -
  33. if (sysctl(mib, 2, &securelevel, &sz, NULL, 0) == -1)
  34. err(1, "sysctl");
  35. +#endif
  36. constraints = !TAILQ_EMPTY(&cnf->constraints);
  37. return !cnf->settime && (constraints || cnf->trusted_peers ||
  38. conf->trusted_sensors) && securelevel == 0;
  39. --
  40. 2.27.0