Blame openbsd_priv.c

Packit 4e8bc4
#include <errno.h>
Packit 4e8bc4
#include <stdlib.h>
Packit 4e8bc4
#include <stdio.h>
Packit 4e8bc4
#include <string.h>
Packit 4e8bc4
#include <unistd.h>
Packit 4e8bc4
#include "memcached.h"
Packit 4e8bc4
Packit 4e8bc4
/*
Packit 4e8bc4
 * this section of code will drop all (OpenBSD) privileges including
Packit 4e8bc4
 * those normally granted to all userland process (basic privileges). The
Packit 4e8bc4
 * effect of this is that after running this code, the process will not able
Packit 4e8bc4
 * to fork(), exec(), etc.  See pledge(2) for more information.
Packit 4e8bc4
 */
Packit 4e8bc4
void drop_privileges() {
Packit 4e8bc4
    extern char *__progname;
Packit 4e8bc4
Packit 4e8bc4
    if (settings.socketpath != NULL) {
Packit 4e8bc4
       if (pledge("stdio unix", NULL) == -1) {
Packit 4e8bc4
          fprintf(stderr, "%s: pledge: %s\n", __progname, strerror(errno));
Packit 4e8bc4
          exit(EXIT_FAILURE);
Packit 4e8bc4
       }
Packit 4e8bc4
    } else {
Packit 4e8bc4
       if (pledge("stdio inet", NULL) == -1) {
Packit 4e8bc4
          fprintf(stderr, "%s: pledge: %s\n", __progname, strerror(errno));
Packit 4e8bc4
          exit(EXIT_FAILURE);
Packit 4e8bc4
       }
Packit 4e8bc4
     }
Packit 4e8bc4
}
Packit 4e8bc4
Packit 4e8bc4
void setup_privilege_violations_handler(void) {
Packit 4e8bc4
   // not needed
Packit 4e8bc4
}