capability-util: move several definitions

This commit is contained in:
Yu Watanabe
2025-10-24 01:52:59 +09:00
parent 7de349c1ed
commit 50053a0212
2 changed files with 37 additions and 30 deletions
+15 -15
View File
@@ -20,21 +20,6 @@
#include "stat-util.h"
#include "user-util.h"
int have_effective_cap(int value) {
_cleanup_cap_free_ cap_t cap = NULL;
cap_flag_value_t fv = CAP_CLEAR; /* To avoid false-positive use-of-uninitialized-value error reported
* by fuzzers. */
cap = cap_get_proc();
if (!cap)
return -errno;
if (cap_get_flag(cap, value, CAP_EFFECTIVE, &fv) < 0)
return -errno;
return fv == CAP_SET;
}
unsigned cap_last_cap(void) {
static atomic_int saved = INT_MAX;
int r, c;
@@ -89,6 +74,21 @@ unsigned cap_last_cap(void) {
return c;
}
int have_effective_cap(int value) {
_cleanup_cap_free_ cap_t cap = NULL;
cap_flag_value_t fv = CAP_CLEAR; /* To avoid false-positive use-of-uninitialized-value error reported
* by fuzzers. */
cap = cap_get_proc();
if (!cap)
return -errno;
if (cap_get_flag(cap, value, CAP_EFFECTIVE, &fv) < 0)
return -errno;
return fv == CAP_SET;
}
int capability_update_inherited_set(cap_t caps, uint64_t set) {
/* Add capabilities in the set to the inherited caps, drops capabilities not in the set.
* Do not apply them yet. */