Skip to content

Commit

Permalink
drop privileges, FreeBSD.
Browse files Browse the repository at this point in the history
Expand on sandboxing support, assuming memcached
does not support end of life versions (available
since FreeBSD 10.x ~2014).
  • Loading branch information
devnexen authored and dormando committed Sep 28, 2019
1 parent d3f15bb commit 480fc66
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions freebsd_priv.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,33 @@
* in FreeBSD vocabulary.
*/
void drop_privileges() {
cap_rights_t wd, rd;

if (cap_rights_init(&wd, CAP_WRITE, CAP_READ) == NULL) {
fprintf(stderr, "cap_rights_init write protection failed: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}

if (cap_rights_init(&rd, CAP_FCNTL, CAP_READ, CAP_EVENT) == NULL) {
fprintf(stderr, "cap_rights_init read protection failed: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}

if (cap_rights_limit(STDIN_FILENO, &rd) != 0) {
fprintf(stderr, "cap_rights_limit stdin failed: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}

if (cap_rights_limit(STDOUT_FILENO, &wd) != 0) {
fprintf(stderr, "cap_rights_limit stdout failed: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}

if (cap_rights_limit(STDERR_FILENO, &wd) != 0) {
fprintf(stderr, "cap_rights_limit stderr failed: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}

if (cap_enter() != 0) {
fprintf(stderr, "cap_enter failed: %s\n", strerror(errno));
exit(EXIT_FAILURE);
Expand Down

0 comments on commit 480fc66

Please sign in to comment.