Enable privilege dropping of FreeBSD

Privilege dropping works on FreeBSD too, so only the caps parts need to
be Linux-only.
This commit is contained in:
sghctoma 2018-08-30 10:33:48 +02:00
parent ac7a0aa038
commit 67188b7cba
1 changed files with 4 additions and 2 deletions

View File

@ -366,13 +366,15 @@ int main(int argc, char **argv) {
return 1; return 1;
} }
#ifdef __linux__ #if defined(__linux__) || defined(__FreeBSD__)
if (getuid() != geteuid() || getgid() != getegid()) { if (getuid() != geteuid() || getgid() != getegid()) {
#ifdef __linux__
// Retain capabilities after setuid() // Retain capabilities after setuid()
if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0)) { if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0)) {
wlr_log(WLR_ERROR, "Cannot keep caps after setuid()"); wlr_log(WLR_ERROR, "Cannot keep caps after setuid()");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#endif
suid = true; suid = true;
} }
#endif #endif
@ -382,7 +384,7 @@ int main(int argc, char **argv) {
detect_proprietary(); detect_proprietary();
detect_raspi(); detect_raspi();
#ifdef __linux__ #if defined(__linux__) || defined(__FreeBSD__)
drop_permissions(suid); drop_permissions(suid);
#endif #endif
// handle SIGTERM signals // handle SIGTERM signals