1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* Query, remove, or restore a Solaris privilege.
5 Copyright (C) 2009-2013 Free Software Foundation, Inc.
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 Written by David Bartley. */
24 #define PRIV_SET_INLINE _GL_EXTERN_INLINE
28 #if HAVE_GETPPRIV && HAVE_PRIV_H
34 /* Holds a (cached) copy of the effective set. */
35 static priv_set_t *eff_set;
37 /* Holds a set of privileges that we have removed. */
38 static priv_set_t *rem_set;
40 static bool initialized;
43 priv_set_initialize (void)
47 eff_set = priv_allocset ();
52 rem_set = priv_allocset ();
55 priv_freeset (eff_set);
58 if (getppriv (PRIV_EFFECTIVE, eff_set) != 0)
60 priv_freeset (eff_set);
61 priv_freeset (rem_set);
64 priv_emptyset (rem_set);
72 /* Check if priv is in the effective set.
73 Returns 1 if priv is a member and 0 if not.
74 Returns -1 on error with errno set appropriately. */
76 priv_set_ismember (const char *priv)
78 if (! initialized && priv_set_initialize () != 0)
81 return priv_ismember (eff_set, priv);
85 /* Try to remove priv from the effective set.
86 Returns 0 if priv was removed.
87 Returns -1 on error with errno set appropriately. */
89 priv_set_remove (const char *priv)
91 if (! initialized && priv_set_initialize () != 0)
94 if (priv_ismember (eff_set, priv))
96 /* priv_addset/priv_delset can only fail if priv is invalid, which is
97 checked above by the priv_ismember call. */
98 priv_delset (eff_set, priv);
99 if (setppriv (PRIV_SET, PRIV_EFFECTIVE, eff_set) != 0)
101 priv_addset (eff_set, priv);
104 priv_addset (rem_set, priv);
116 /* Try to restore priv to the effective set.
117 Returns 0 if priv was re-added to the effective set (after being previously
118 removed by a call to priv_set_remove).
119 Returns -1 on error with errno set appropriately. */
121 priv_set_restore (const char *priv)
123 if (! initialized && priv_set_initialize () != 0)
126 if (priv_ismember (rem_set, priv))
128 /* priv_addset/priv_delset can only fail if priv is invalid, which is
129 checked above by the priv_ismember call. */
130 priv_addset (eff_set, priv);
131 if (setppriv (PRIV_SET, PRIV_EFFECTIVE, eff_set) != 0)
133 priv_delset (eff_set, priv);
136 priv_delset (rem_set, priv);