1 #include <errno.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <unistd.h>
6 #include "memcached.h"
7 
8 /*
9  * this section of code will drop all (OpenBSD) privileges including
10  * those normally granted to all userland process (basic privileges). The
11  * effect of this is that after running this code, the process will not able
12  * to fork(), exec(), etc.  See pledge(2) for more information.
13  */
drop_privileges()14 void drop_privileges() {
15     extern char *__progname;
16 
17     if (settings.socketpath != NULL) {
18        if (pledge("stdio unix", NULL) == -1) {
19           fprintf(stderr, "%s: pledge: %s\n", __progname, strerror(errno));
20           exit(EXIT_FAILURE);
21        }
22     } else {
23        if (pledge("stdio inet", NULL) == -1) {
24           fprintf(stderr, "%s: pledge: %s\n", __progname, strerror(errno));
25           exit(EXIT_FAILURE);
26        }
27      }
28 }
29 
setup_privilege_violations_handler(void)30 void setup_privilege_violations_handler(void) {
31    // not needed
32 }
33