diff --git a/configure b/configure index df4f80a..24f52c4 100755 --- a/configure +++ b/configure @@ -376,10 +376,13 @@ case $OPERATINGSYSTEM in add_def LINUX echo "Configuring for " $SYSTEM ;; - FreeBSD) EXTRA_OBJECTS="sys_generic.o sys_netbsd.o sys_timex.o" add_def FREEBSD + if [ $feat_droproot = "1" ]; then + add_def FEAT_PRIVDROP + priv_ops="ADJUSTTIME ADJUSTTIMEX SETTIME BINDSOCKET" + fi echo "Configuring for $SYSTEM" ;; NetBSD) diff --git a/sys.c b/sys.c index f3844c6..bd3441e 100644 --- a/sys.c +++ b/sys.c @@ -90,7 +90,7 @@ void SYS_DropRoot(uid_t uid, gid_t gid) { #if defined(LINUX) && defined (FEAT_PRIVDROP) SYS_Linux_DropRoot(uid, gid); -#elif defined(NETBSD) && defined(FEAT_PRIVDROP) +#elif (defined(NETBSD) || defined(FREEBSD)) && defined(FEAT_PRIVDROP) SYS_NetBSD_DropRoot(uid, gid); #elif defined(MACOSX) && defined(FEAT_PRIVDROP) SYS_MacOSX_DropRoot(uid, gid); diff --git a/sys_netbsd.c b/sys_netbsd.c index e0b5b50..407be84 100644 --- a/sys_netbsd.c +++ b/sys_netbsd.c @@ -23,7 +23,7 @@ ======================================================================= - Driver file for the NetBSD operating system. + Driver file for the NetBSD and FreeBSD operating system. */ #include "config.h" @@ -63,14 +63,14 @@ accrue_offset(double offset, double corr_rate) UTI_DoubleToTimeval(-offset, &newadj); - if (adjtime(&newadj, &oldadj) < 0) + if (PRV_AdjustTime(&newadj, &oldadj) < 0) LOG_FATAL(LOGF_SysNetBSD, "adjtime() failed"); /* Add the old remaining adjustment if not zero */ UTI_TimevalToDouble(&oldadj, &offset); if (offset != 0.0) { UTI_AddDoubleToTimeval(&newadj, offset, &newadj); - if (adjtime(&newadj, NULL) < 0) + if (PRV_AdjustTime(&newadj, NULL) < 0) LOG_FATAL(LOGF_SysNetBSD, "adjtime() failed"); } } @@ -84,7 +84,7 @@ get_offset_correction(struct timeval *raw, struct timeval remadj; double adjustment_remaining; - if (adjtime(NULL, &remadj) < 0) + if (PRV_AdjustTime(NULL, &remadj) < 0) LOG_FATAL(LOGF_SysNetBSD, "adjtime() failed"); UTI_TimevalToDouble(&remadj, &adjustment_remaining); @@ -123,16 +123,22 @@ SYS_NetBSD_Finalise(void) void SYS_NetBSD_DropRoot(uid_t uid, gid_t gid) { +#ifdef NETBSD int fd; +#endif + /* On NetBSD the helper is used only for socket binding, but on FreeBSD + it's used also for setting and adjusting the system clock */ PRV_StartHelper(); UTI_DropRoot(uid, gid); +#ifdef NETBSD /* Check if we have write access to /dev/clockctl */ fd = open("/dev/clockctl", O_WRONLY); if (fd < 0) LOG_FATAL(LOGF_SysNetBSD, "Can't write to /dev/clockctl"); close(fd); +#endif } #endif