Skip to content
Newer
Older
100644 45 lines (36 sloc) 1.23 KB
69aa542 Drop privileges when running on Solaris
Trond Norbye authored Mar 3, 2009
1 #include <stdlib.h>
2 #include <priv.h>
3 #include <stdio.h>
3fa3137 Remove compilation errors from gcc on Solaris
Trond Norbye authored Aug 20, 2009
4 #include "memcached.h"
69aa542 Drop privileges when running on Solaris
Trond Norbye authored Mar 3, 2009
5
6 /*
7 * this section of code will drop all (Solaris) privileges including
8 * those normally granted to all userland process (basic privileges). The
9 * effect of this is that after running this code, the process will not able
10 * to fork(), exec(), etc. See privileges(5) for more information.
11 */
3fa3137 Remove compilation errors from gcc on Solaris
Trond Norbye authored Aug 20, 2009
12 void drop_privileges(void) {
69aa542 Drop privileges when running on Solaris
Trond Norbye authored Mar 3, 2009
13 priv_set_t *privs = priv_str_to_set("basic", ",", NULL);
14
15 if (privs == NULL) {
16 perror("priv_str_to_set");
17 exit(EXIT_FAILURE);
18 }
19
20 (void)priv_delset(privs, PRIV_FILE_LINK_ANY);
21 (void)priv_delset(privs, PRIV_PROC_EXEC);
22 (void)priv_delset(privs, PRIV_PROC_FORK);
23 (void)priv_delset(privs, PRIV_PROC_INFO);
24 (void)priv_delset(privs, PRIV_PROC_SESSION);
25
26 if (setppriv(PRIV_SET, PRIV_PERMITTED, privs) != 0) {
27 perror("setppriv(PRIV_SET, PRIV_PERMITTED)");
28 exit(EXIT_FAILURE);
29 }
30
31 priv_emptyset(privs);
32
33 if (setppriv(PRIV_SET, PRIV_INHERITABLE, privs) != 0) {
34 perror("setppriv(PRIV_SET, PRIV_INHERITABLE)");
35 exit(EXIT_FAILURE);
36 }
37
38 if (setppriv(PRIV_SET, PRIV_LIMIT, privs) != 0) {
39 perror("setppriv(PRIV_SET, PRIV_LIMIT)");
40 exit(EXIT_FAILURE);
41 }
42
43 priv_freeset(privs);
44 }
Something went wrong with that request. Please try again.