24 RCSID(
"$Id: f396b80d37df6781361d0f2e963ad20101793c8d $")
26 #ifdef HAVE_CAPABILITY_H
27 #include <freeradius-devel/util/cap.h>
28 #include <freeradius-devel/util/strerror.h>
29 #include <freeradius-devel/util/syserror.h>
30 #include <freeradius-devel/util/table.h>
31 #include <freeradius-devel/util/talloc.h>
36 {
L(
"effective"), CAP_EFFECTIVE },
37 {
L(
"inherited"), CAP_INHERITABLE },
38 {
L(
"permitted"), CAP_PERMITTED }
40 static size_t cap_set_table_len =
NUM_ELEMENTS(cap_set_table);
59 bool fr_cap_is_enabled(cap_value_t cap, cap_flag_t set)
62 cap_flag_value_t state = CAP_CLEAR;
64 pthread_mutex_lock(&cap_mutex);
66 caps = cap_get_proc();
72 if (cap_get_flag(caps, cap, CAP_EFFECTIVE, &state) < 0) {
73 char *cap_name = cap_to_name(cap);
83 pthread_mutex_unlock(&cap_mutex);
85 if (caps) cap_free(caps);
87 return (state == CAP_SET);
106 int fr_cap_enable(cap_value_t cap, cap_flag_t set)
110 cap_flag_value_t state;
120 pthread_mutex_lock(&cap_mutex);
122 if (set == CAP_PERMITTED) {
127 caps = cap_get_proc();
133 if (cap_get_flag(caps, cap, CAP_PERMITTED, &state) < 0) {
134 char *cap_name = cap_to_name(cap);
143 if (state == CAP_CLEAR) {
144 char *cap_name = cap_to_name(cap);
149 fr_strerror_printf(
"Use \"setcap %s+ep <path_to_binary>\" to grant the %s capability",
155 if (cap_get_flag(caps, cap, set, &state) < 0) {
156 char *cap_name = cap_to_name(cap);
170 if (state == CAP_CLEAR) {
171 cap_value_t
const to_set[] = {
175 if (cap_set_flag(caps, set,
NUM_ELEMENTS(to_set), to_set, CAP_SET) < 0) {
176 char *cap_name = cap_to_name(cap);
185 if (cap_set_proc(caps) < 0) {
186 char *cap_name = cap_to_name(cap);
199 }
else if (state == CAP_SET) {
204 pthread_mutex_unlock(&cap_mutex);
206 if (caps) cap_free(caps);
222 int fr_cap_disable(cap_value_t cap, cap_flag_t set)
226 cap_flag_value_t state;
236 pthread_mutex_lock(&cap_mutex);
238 caps = cap_get_proc();
244 if (cap_get_flag(caps, cap, set, &state) < 0) {
245 char *cap_name = cap_to_name(cap);
254 if (state == CAP_SET) {
255 if (cap_clear_flag(caps, set) < 0) {
256 char *cap_name = cap_to_name(cap);
265 if (cap_set_proc(caps) < 0) {
266 char *cap_name = cap_to_name(cap);
281 pthread_mutex_unlock(&cap_mutex);
283 if (caps) cap_free(caps);
293 ssize_t fr_cap_set_to_str(TALLOC_CTX *ctx,
char **
out)
299 caps = cap_get_proc();
304 tmp = cap_to_text(caps, &slen);
#define L(_str)
Helper for initialising arrays of string literals.
char const * fr_syserror(int num)
Guaranteed to be thread-safe version of strerror.
#define fr_table_str_by_value(_table, _number, _def)
Convert an integer to a string.
An element in a lexicographically sorted array of name to num mappings.
char * talloc_bstrndup(TALLOC_CTX *ctx, char const *in, size_t inlen)
Binary safe strndup function.
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
#define fr_strerror_const(_msg)
static size_t char ** out