chiark / gitweb /
Prep v229: Add missing fixes from upstream [1/6] src/basic
[elogind.git] / src / basic / capability-util.h
1 #pragma once
2
3 /***
4   This file is part of systemd.
5
6   Copyright 2010 Lennart Poettering
7
8   systemd is free software; you can redistribute it and/or modify it
9   under the terms of the GNU Lesser General Public License as published by
10   the Free Software Foundation; either version 2.1 of the License, or
11   (at your option) any later version.
12
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   Lesser General Public License for more details.
17
18   You should have received a copy of the GNU Lesser General Public License
19   along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 ***/
21
22 #include <stdbool.h>
23 #include <stdint.h>
24 #include <sys/capability.h>
25 #include <sys/types.h>
26
27 #include "macro.h"
28 #include "util.h"
29
30 #define CAP_ALL (uint64_t) -1
31
32 unsigned long cap_last_cap(void);
33 #if 0 /// UNNEEDED by elogind
34 int have_effective_cap(int value);
35 int capability_bounding_set_drop(uint64_t keep, bool right_now);
36 int capability_bounding_set_drop_usermode(uint64_t keep);
37
38 int capability_ambient_set_apply(uint64_t set, bool also_inherit);
39 int capability_update_inherited_set(cap_t caps, uint64_t ambient_set);
40
41 int drop_privileges(uid_t uid, gid_t gid, uint64_t keep_capabilities);
42
43 int drop_capability(cap_value_t cv);
44
45 DEFINE_TRIVIAL_CLEANUP_FUNC(cap_t, cap_free);
46 #define _cleanup_cap_free_ _cleanup_(cap_freep)
47
48 static inline void cap_free_charpp(char **p) {
49         if (*p)
50                 cap_free(*p);
51 }
52 #define _cleanup_cap_free_charp_ _cleanup_(cap_free_charpp)
53 #endif // 0
54
55 static inline bool cap_test_all(uint64_t caps) {
56         uint64_t m;
57         m = (UINT64_C(1) << (cap_last_cap() + 1)) - 1;
58         return (caps & m) == m;
59 }