@@ -31,8 +31,8 @@ int have_effective_cap(int value) {
31
31
return fv == CAP_SET ;
32
32
}
33
33
34
- unsigned long cap_last_cap (void ) {
35
- static thread_local unsigned long saved ;
34
+ unsigned cap_last_cap (void ) {
35
+ static thread_local unsigned saved ;
36
36
static thread_local bool valid = false;
37
37
_cleanup_free_ char * content = NULL ;
38
38
unsigned long p = 0 ;
@@ -65,7 +65,7 @@ unsigned long cap_last_cap(void) {
65
65
if (prctl (PR_CAPBSET_READ , p ) < 0 ) {
66
66
67
67
/* Hmm, look downwards, until we find one that works */
68
- for (p -- ; p > 0 ; p -- )
68
+ for (p -- ; p > 0 ; p -- )
69
69
if (prctl (PR_CAPBSET_READ , p ) >= 0 )
70
70
break ;
71
71
@@ -84,12 +84,10 @@ unsigned long cap_last_cap(void) {
84
84
}
85
85
86
86
int capability_update_inherited_set (cap_t caps , uint64_t set ) {
87
- unsigned long i ;
88
-
89
87
/* Add capabilities in the set to the inherited caps, drops capabilities not in the set.
90
88
* Do not apply them yet. */
91
89
92
- for (i = 0 ; i <= cap_last_cap (); i ++ ) {
90
+ for (unsigned i = 0 ; i <= cap_last_cap (); i ++ ) {
93
91
cap_flag_value_t flag = set & (UINT64_C (1 ) << i ) ? CAP_SET : CAP_CLEAR ;
94
92
cap_value_t v ;
95
93
@@ -104,11 +102,10 @@ int capability_update_inherited_set(cap_t caps, uint64_t set) {
104
102
105
103
int capability_ambient_set_apply (uint64_t set , bool also_inherit ) {
106
104
_cleanup_cap_free_ cap_t caps = NULL ;
107
- unsigned long i ;
108
105
int r ;
109
106
110
107
/* Remove capabilities requested in ambient set, but not in the bounding set */
111
- for (i = 0 ; i <= cap_last_cap (); i ++ ) {
108
+ for (unsigned i = 0 ; i <= cap_last_cap (); i ++ ) {
112
109
if (set == 0 )
113
110
break ;
114
111
@@ -140,7 +137,7 @@ int capability_ambient_set_apply(uint64_t set, bool also_inherit) {
140
137
return - errno ;
141
138
}
142
139
143
- for (i = 0 ; i <= cap_last_cap (); i ++ ) {
140
+ for (unsigned i = 0 ; i <= cap_last_cap (); i ++ ) {
144
141
145
142
if (set & (UINT64_C (1 ) << i )) {
146
143
@@ -167,7 +164,6 @@ int capability_ambient_set_apply(uint64_t set, bool also_inherit) {
167
164
int capability_bounding_set_drop (uint64_t keep , bool right_now ) {
168
165
_cleanup_cap_free_ cap_t before_cap = NULL , after_cap = NULL ;
169
166
cap_flag_value_t fv ;
170
- unsigned long i ;
171
167
int r ;
172
168
173
169
/* If we are run as PID 1 we will lack CAP_SETPCAP by default
@@ -204,7 +200,7 @@ int capability_bounding_set_drop(uint64_t keep, bool right_now) {
204
200
if (!after_cap )
205
201
return - errno ;
206
202
207
- for (i = 0 ; i <= cap_last_cap (); i ++ ) {
203
+ for (unsigned i = 0 ; i <= cap_last_cap (); i ++ ) {
208
204
cap_value_t v ;
209
205
210
206
if ((keep & (UINT64_C (1 ) << i )))
@@ -390,7 +386,6 @@ bool ambient_capabilities_supported(void) {
390
386
}
391
387
392
388
bool capability_quintet_mangle (CapabilityQuintet * q ) {
393
- unsigned long i ;
394
389
uint64_t combined , drop = 0 ;
395
390
bool ambient_supported ;
396
391
@@ -402,7 +397,7 @@ bool capability_quintet_mangle(CapabilityQuintet *q) {
402
397
if (ambient_supported )
403
398
combined |= q -> ambient ;
404
399
405
- for (i = 0 ; i <= cap_last_cap (); i ++ ) {
400
+ for (unsigned i = 0 ; i <= cap_last_cap (); i ++ ) {
406
401
unsigned long bit = UINT64_C (1 ) << i ;
407
402
if (!FLAGS_SET (combined , bit ))
408
403
continue ;
@@ -431,16 +426,15 @@ int capability_quintet_enforce(const CapabilityQuintet *q) {
431
426
int r ;
432
427
433
428
if (q -> ambient != (uint64_t ) -1 ) {
434
- unsigned long i ;
435
429
bool changed = false;
436
430
437
431
c = cap_get_proc ();
438
432
if (!c )
439
433
return - errno ;
440
434
441
- /* In order to raise the ambient caps set we first need to raise the matching inheritable + permitted
442
- * cap */
443
- for (i = 0 ; i <= cap_last_cap (); i ++ ) {
435
+ /* In order to raise the ambient caps set we first need to raise the matching
436
+ * inheritable + permitted cap */
437
+ for (unsigned i = 0 ; i <= cap_last_cap (); i ++ ) {
444
438
uint64_t m = UINT64_C (1 ) << i ;
445
439
cap_value_t cv = (cap_value_t ) i ;
446
440
cap_flag_value_t old_value_inheritable , old_value_permitted ;
@@ -475,15 +469,14 @@ int capability_quintet_enforce(const CapabilityQuintet *q) {
475
469
476
470
if (q -> inheritable != (uint64_t ) -1 || q -> permitted != (uint64_t ) -1 || q -> effective != (uint64_t ) -1 ) {
477
471
bool changed = false;
478
- unsigned long i ;
479
472
480
473
if (!c ) {
481
474
c = cap_get_proc ();
482
475
if (!c )
483
476
return - errno ;
484
477
}
485
478
486
- for (i = 0 ; i <= cap_last_cap (); i ++ ) {
479
+ for (unsigned i = 0 ; i <= cap_last_cap (); i ++ ) {
487
480
uint64_t m = UINT64_C (1 ) << i ;
488
481
cap_value_t cv = (cap_value_t ) i ;
489
482
0 commit comments