chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
everywhere: port everything to sigprocmask_many() and friends
[elogind.git]
/
src
/
shared
/
capability.c
diff --git
a/src/shared/capability.c
b/src/shared/capability.c
index 3f2f27e23fe4234c2660da30e5d99f76549aff14..58f00e6daec180c910bb72ff4cf83efd0c7c1ec3 100644
(file)
--- a/
src/shared/capability.c
+++ b/
src/shared/capability.c
@@
-19,14
+19,9
@@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-#include <assert.h>
-#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
-#include <sys/types.h>
-#include <stdarg.h>
-#include <ctype.h>
#include <sys/capability.h>
#include <sys/prctl.h>
#include "grp.h"
#include <sys/capability.h>
#include <sys/prctl.h>
#include "grp.h"
@@
-55,7
+50,7
@@
unsigned long cap_last_cap(void) {
static thread_local unsigned long saved;
static thread_local bool valid = false;
_cleanup_free_ char *content = NULL;
static thread_local unsigned long saved;
static thread_local bool valid = false;
_cleanup_free_ char *content = NULL;
- unsigned long p;
+ unsigned long p
= 0
;
int r;
if (valid)
int r;
if (valid)
@@
-269,12
+264,16
@@
int drop_privileges(uid_t uid, gid_t gid, uint64_t keep_capabilities) {
return log_oom();
if (keep_capabilities) {
return log_oom();
if (keep_capabilities) {
- cap_value_t bits[
log2u64(keep_capabilities)
];
+ cap_value_t bits[
u64log2(keep_capabilities) + 1
];
for (i = 0; i < ELEMENTSOF(bits); i++)
if (keep_capabilities & (1ULL << i))
bits[j++] = i;
for (i = 0; i < ELEMENTSOF(bits); i++)
if (keep_capabilities & (1ULL << i))
bits[j++] = i;
- assert((keep_capabilities & (~1ULL << i)) == 0);
+
+ /* use enough bits */
+ assert(i == 64 || (keep_capabilities >> i) == 0);
+ /* don't use too many bits */
+ assert(keep_capabilities & (1ULL << (i - 1)));
if (cap_set_flag(d, CAP_EFFECTIVE, j, bits, CAP_SET) < 0 ||
cap_set_flag(d, CAP_PERMITTED, j, bits, CAP_SET) < 0) {
if (cap_set_flag(d, CAP_EFFECTIVE, j, bits, CAP_SET) < 0 ||
cap_set_flag(d, CAP_PERMITTED, j, bits, CAP_SET) < 0) {