]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/capability-util.h
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / basic / capability-util.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
05d3a176 2#pragma once
7f110ff9
LP
3
4/***
5 This file is part of systemd.
6
d7832d2c 7 Copyright 2010 Lennart Poettering
7f110ff9
LP
8
9 systemd is free software; you can redistribute it and/or modify it
5430f7f2
LP
10 under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
7f110ff9
LP
12 (at your option) any later version.
13
14 systemd is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5430f7f2 17 Lesser General Public License for more details.
7f110ff9 18
5430f7f2 19 You should have received a copy of the GNU Lesser General Public License
7f110ff9
LP
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21***/
22
ec8927ca 23#include <stdbool.h>
11c3a366 24#include <stdint.h>
5ce70e5b 25#include <sys/capability.h>
11c3a366 26#include <sys/types.h>
5ce70e5b 27
11c3a366 28#include "macro.h"
5ce70e5b 29#include "util.h"
ec8927ca 30
a103496c
IP
31#define CAP_ALL (uint64_t) -1
32
d7832d2c
KS
33unsigned long cap_last_cap(void);
34int have_effective_cap(int value);
a103496c
IP
35int capability_bounding_set_drop(uint64_t keep, bool right_now);
36int capability_bounding_set_drop_usermode(uint64_t keep);
5ce70e5b 37
755d4b67
IP
38int capability_ambient_set_apply(uint64_t set, bool also_inherit);
39int capability_update_inherited_set(cap_t caps, uint64_t ambient_set);
40
45afd519 41int drop_privileges(uid_t uid, gid_t gid, uint64_t keep_capabilities);
966bff26 42
dd5ae4c3
PK
43int drop_capability(cap_value_t cv);
44
5ce70e5b
ZJS
45DEFINE_TRIVIAL_CLEANUP_FUNC(cap_t, cap_free);
46#define _cleanup_cap_free_ _cleanup_(cap_freep)
47
48static 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)
a103496c
IP
53
54static inline bool cap_test_all(uint64_t caps) {
55 uint64_t m;
56 m = (UINT64_C(1) << (cap_last_cap() + 1)) - 1;
57 return (caps & m) == m;
58}
39f608e4
LP
59
60bool ambient_capabilities_supported(void);