We never return anything higher than 63, so using "long unsigned"
as the type only confused the reader. (We can still use "long unsigned"
and safe_atolu() to parse the kernel file.)
int capability_set_to_string_alloc(uint64_t set, char **s) {
_cleanup_free_ char *str = NULL;
int capability_set_to_string_alloc(uint64_t set, char **s) {
_cleanup_free_ char *str = NULL;
size_t allocated = 0, n = 0;
assert(s);
size_t allocated = 0, n = 0;
assert(s);
- for (i = 0; i <= cap_last_cap(); i++)
+ for (unsigned i = 0; i <= cap_last_cap(); i++)
if (set & (UINT64_C(1) << i)) {
const char *p;
char buf[2 + 16 + 1];
if (set & (UINT64_C(1) << i)) {
const char *p;
char buf[2 + 16 + 1];
p = capability_to_name(i);
if (!p) {
p = capability_to_name(i);
if (!p) {
- xsprintf(buf, "0x%lx", i);
+ xsprintf(buf, "0x%x", i);
-unsigned long cap_last_cap(void) {
- static thread_local unsigned long saved;
+unsigned cap_last_cap(void) {
+ static thread_local unsigned saved;
static thread_local bool valid = false;
_cleanup_free_ char *content = NULL;
unsigned long p = 0;
static thread_local bool valid = false;
_cleanup_free_ char *content = NULL;
unsigned long p = 0;
if (prctl(PR_CAPBSET_READ, p) < 0) {
/* Hmm, look downwards, until we find one that works */
if (prctl(PR_CAPBSET_READ, p) < 0) {
/* Hmm, look downwards, until we find one that works */
if (prctl(PR_CAPBSET_READ, p) >= 0)
break;
if (prctl(PR_CAPBSET_READ, p) >= 0)
break;
}
int capability_update_inherited_set(cap_t caps, uint64_t 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. */
/* Add capabilities in the set to the inherited caps, drops capabilities not in the set.
* Do not apply them yet. */
- for (i = 0; i <= cap_last_cap(); i++) {
+ for (unsigned i = 0; i <= cap_last_cap(); i++) {
cap_flag_value_t flag = set & (UINT64_C(1) << i) ? CAP_SET : CAP_CLEAR;
cap_value_t v;
cap_flag_value_t flag = set & (UINT64_C(1) << i) ? CAP_SET : CAP_CLEAR;
cap_value_t v;
int capability_ambient_set_apply(uint64_t set, bool also_inherit) {
_cleanup_cap_free_ cap_t caps = NULL;
int capability_ambient_set_apply(uint64_t set, bool also_inherit) {
_cleanup_cap_free_ cap_t caps = NULL;
int r;
/* Remove capabilities requested in ambient set, but not in the bounding set */
int r;
/* Remove capabilities requested in ambient set, but not in the bounding set */
- for (i = 0; i <= cap_last_cap(); i++) {
+ for (unsigned i = 0; i <= cap_last_cap(); i++) {
- for (i = 0; i <= cap_last_cap(); i++) {
+ for (unsigned i = 0; i <= cap_last_cap(); i++) {
if (set & (UINT64_C(1) << i)) {
if (set & (UINT64_C(1) << i)) {
int capability_bounding_set_drop(uint64_t keep, bool right_now) {
_cleanup_cap_free_ cap_t before_cap = NULL, after_cap = NULL;
cap_flag_value_t fv;
int capability_bounding_set_drop(uint64_t keep, bool right_now) {
_cleanup_cap_free_ cap_t before_cap = NULL, after_cap = NULL;
cap_flag_value_t fv;
int r;
/* If we are run as PID 1 we will lack CAP_SETPCAP by default
int r;
/* If we are run as PID 1 we will lack CAP_SETPCAP by default
if (!after_cap)
return -errno;
if (!after_cap)
return -errno;
- for (i = 0; i <= cap_last_cap(); i++) {
+ for (unsigned i = 0; i <= cap_last_cap(); i++) {
cap_value_t v;
if ((keep & (UINT64_C(1) << i)))
cap_value_t v;
if ((keep & (UINT64_C(1) << i)))
}
bool capability_quintet_mangle(CapabilityQuintet *q) {
}
bool capability_quintet_mangle(CapabilityQuintet *q) {
uint64_t combined, drop = 0;
bool ambient_supported;
uint64_t combined, drop = 0;
bool ambient_supported;
if (ambient_supported)
combined |= q->ambient;
if (ambient_supported)
combined |= q->ambient;
- for (i = 0; i <= cap_last_cap(); i++) {
+ for (unsigned i = 0; i <= cap_last_cap(); i++) {
unsigned long bit = UINT64_C(1) << i;
if (!FLAGS_SET(combined, bit))
continue;
unsigned long bit = UINT64_C(1) << i;
if (!FLAGS_SET(combined, bit))
continue;
int r;
if (q->ambient != (uint64_t) -1) {
int r;
if (q->ambient != (uint64_t) -1) {
bool changed = false;
c = cap_get_proc();
if (!c)
return -errno;
bool changed = false;
c = cap_get_proc();
if (!c)
return -errno;
- /* In order to raise the ambient caps set we first need to raise the matching inheritable + permitted
- * cap */
- for (i = 0; i <= cap_last_cap(); i++) {
+ /* In order to raise the ambient caps set we first need to raise the matching
+ * inheritable + permitted cap */
+ for (unsigned i = 0; i <= cap_last_cap(); i++) {
uint64_t m = UINT64_C(1) << i;
cap_value_t cv = (cap_value_t) i;
cap_flag_value_t old_value_inheritable, old_value_permitted;
uint64_t m = UINT64_C(1) << i;
cap_value_t cv = (cap_value_t) i;
cap_flag_value_t old_value_inheritable, old_value_permitted;
if (q->inheritable != (uint64_t) -1 || q->permitted != (uint64_t) -1 || q->effective != (uint64_t) -1) {
bool changed = false;
if (q->inheritable != (uint64_t) -1 || q->permitted != (uint64_t) -1 || q->effective != (uint64_t) -1) {
bool changed = false;
if (!c) {
c = cap_get_proc();
if (!c) {
c = cap_get_proc();
- for (i = 0; i <= cap_last_cap(); i++) {
+ for (unsigned i = 0; i <= cap_last_cap(); i++) {
uint64_t m = UINT64_C(1) << i;
cap_value_t cv = (cap_value_t) i;
uint64_t m = UINT64_C(1) << i;
cap_value_t cv = (cap_value_t) i;
#define CAP_ALL (uint64_t) -1
#define CAP_ALL (uint64_t) -1
-unsigned long cap_last_cap(void);
+unsigned cap_last_cap(void);
int have_effective_cap(int value);
int capability_bounding_set_drop(uint64_t keep, bool right_now);
int capability_bounding_set_drop_usermode(uint64_t keep);
int have_effective_cap(int value);
int capability_bounding_set_drop(uint64_t keep, bool right_now);
int capability_bounding_set_drop_usermode(uint64_t keep);
}
static int has_cap(sd_bus_creds *c, size_t offset, int capability) {
}
static int has_cap(sd_bus_creds *c, size_t offset, int capability) {
size_t sz;
assert(c);
assert(capability >= 0);
assert(c->capability);
size_t sz;
assert(c);
assert(capability >= 0);
assert(c->capability);
+ unsigned lc = cap_last_cap();
- if ((unsigned long) capability > lc)
+ if ((unsigned) capability > lc)
return 0;
/* If the last cap is 63, then there are 64 caps defined, and we need 2 entries á 32bit hence. *
return 0;
/* If the last cap is 63, then there are 64 caps defined, and we need 2 entries á 32bit hence. *
assert_se(p <= 63);
/* Also check for the header definition */
assert_se(p <= 63);
/* Also check for the header definition */
- assert_se(CAP_LAST_CAP <= 63);
+ assert_cc(CAP_LAST_CAP <= 63);
}
int main(int argc, char *argv[]) {
}
int main(int argc, char *argv[]) {