This source file includes following definitions.
- priv_set_initialize
- priv_set_ismember
- priv_set_remove
- priv_set_restore
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include <config.h>
21
22 #define PRIV_SET_INLINE _GL_EXTERN_INLINE
23
24 #include "priv-set.h"
25
26 #if HAVE_GETPPRIV && HAVE_PRIV_H
27
28 # include <errno.h>
29 # include <stdbool.h>
30 # include <priv.h>
31
32
33 static priv_set_t *eff_set;
34
35
36 static priv_set_t *rem_set;
37
38 static bool initialized;
39
40 static int
41 priv_set_initialize (void)
42 {
43 if (! initialized)
44 {
45 eff_set = priv_allocset ();
46 if (!eff_set)
47 {
48 return -1;
49 }
50 rem_set = priv_allocset ();
51 if (!rem_set)
52 {
53 priv_freeset (eff_set);
54 return -1;
55 }
56 if (getppriv (PRIV_EFFECTIVE, eff_set) != 0)
57 {
58 priv_freeset (eff_set);
59 priv_freeset (rem_set);
60 return -1;
61 }
62 priv_emptyset (rem_set);
63 initialized = true;
64 }
65
66 return 0;
67 }
68
69
70
71
72
73 int
74 priv_set_ismember (const char *priv)
75 {
76 if (! initialized && priv_set_initialize () != 0)
77 return -1;
78
79 return priv_ismember (eff_set, priv);
80 }
81
82
83
84
85
86 int
87 priv_set_remove (const char *priv)
88 {
89 if (! initialized && priv_set_initialize () != 0)
90 return -1;
91
92 if (priv_ismember (eff_set, priv))
93 {
94
95
96 priv_delset (eff_set, priv);
97 if (setppriv (PRIV_SET, PRIV_EFFECTIVE, eff_set) != 0)
98 {
99 priv_addset (eff_set, priv);
100 return -1;
101 }
102 priv_addset (rem_set, priv);
103 }
104 else
105 {
106 errno = EINVAL;
107 return -1;
108 }
109
110 return 0;
111 }
112
113
114
115
116
117
118 int
119 priv_set_restore (const char *priv)
120 {
121 if (! initialized && priv_set_initialize () != 0)
122 return -1;
123
124 if (priv_ismember (rem_set, priv))
125 {
126
127
128 priv_addset (eff_set, priv);
129 if (setppriv (PRIV_SET, PRIV_EFFECTIVE, eff_set) != 0)
130 {
131 priv_delset (eff_set, priv);
132 return -1;
133 }
134 priv_delset (rem_set, priv);
135 }
136 else
137 {
138 errno = EINVAL;
139 return -1;
140 }
141
142 return 0;
143 }
144
145 #endif