forked from memcached/memcached
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework pledge support after seccomp support has been added
- Loading branch information
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <errno.h> | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
#include "memcached.h" | ||
|
||
/* | ||
* this section of code will drop all (OpenBSD) privileges including | ||
* those normally granted to all userland process (basic privileges). The | ||
* effect of this is that after running this code, the process will not able | ||
* to fork(), exec(), etc. See pledge(2) for more information. | ||
*/ | ||
void drop_privileges() { | ||
extern char *__progname; | ||
|
||
if (settings.socketpath != NULL) { | ||
if (pledge("stdio unix", NULL) == -1) { | ||
fprintf(stderr, "%s: pledge: %s\n", __progname, strerror(errno)); | ||
exit(EXIT_FAILURE); | ||
} | ||
} else { | ||
if (pledge("stdio inet", NULL) == -1) { | ||
fprintf(stderr, "%s: pledge: %s\n", __progname, strerror(errno)); | ||
exit(EXIT_FAILURE); | ||
} | ||
} | ||
} |