diff --git a/configure b/configure index 1f92f01..94bab22 100755 --- a/configure +++ b/configure @@ -224,6 +224,9 @@ int main(void) { persistmethod() { [ -z "$WITHOUT_TIMESTAMP" ] && { printf '#define USE_TIMESTAMP\n' >>$CONFIG_H + printf '#ifdef __freebsd__\n' >>$CONFIG_H + printf '# define TIMESTAMP_DIR "/var/run/doas"\n' >>$CONFIG_H + printf '#endif\n' >>$CONFIG_H printf 'SRCS += timestamp.c\n' >>$CONFIG_MK printf 'timestamp\n' return 0 diff --git a/timestamp.c b/timestamp.c index bca260d..d17be0a 100644 --- a/timestamp.c +++ b/timestamp.c @@ -62,7 +62,10 @@ #include #include -#include +#ifndef __freebsd__ +# include +#endif + #if !defined(timespecisset) || \ !defined(timespeccmp) || \ @@ -95,7 +98,22 @@ # endif #endif -#ifdef __linux__ +#if defined(__freebsd__) +#include +#include +#include +#include + +static int +proc_info(pid_t pid, int *ttynr, unsigned long long *starttime) +{ + struct kinfo_proc *ki = kinfo_getproc(pid); + *ttynr = ki->ki_tdev; + *starttime = ki->ki_start.tv_usec; + free(ki); + return 0; +} +#elif defined(__linux__) /* Use tty_nr from /proc/self/stat instead of using * ttyname(3), stdin, stdout and stderr are user * controllable and would allow to reuse timestamps @@ -221,8 +239,13 @@ timestamp_check(int fd, int secs) if (fstat(fd, &st) == -1) err(1, "fstat"); +#ifdef __freebsd__ + if (st.st_uid != 0 || st.st_gid != 0 || st.st_mode != (S_IFREG | 0000)) + errx(1, "timestamp uid, gid or mode wrong"); +#else if (st.st_uid != 0 || st.st_gid != getgid() || st.st_mode != (S_IFREG | 0000)) errx(1, "timestamp uid, gid or mode wrong"); +#endif /* this timestamp was created but never set, invalid but no error */ if (!timespecisset(&st.st_atim) || !timespecisset(&st.st_mtim))