1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
27 #include <sys/types.h>
30 #include <sys/capability.h>
31 #include <sys/prctl.h>
34 #include "capability.h"
38 int have_effective_cap(int value) {
43 if (!(cap = cap_get_proc()))
46 if (cap_get_flag(cap, value, CAP_EFFECTIVE, &fv) < 0)
55 unsigned long cap_last_cap(void) {
56 static __thread unsigned long saved;
57 static __thread bool valid = false;
63 p = (unsigned long) CAP_LAST_CAP;
65 if (prctl(PR_CAPBSET_READ, p) < 0) {
67 /* Hmm, look downwards, until we find one that
69 for (p--; p > 0; p --)
70 if (prctl(PR_CAPBSET_READ, p) >= 0)
75 /* Hmm, look upwards, until we find one that doesn't
78 if (prctl(PR_CAPBSET_READ, p+1) < 0)