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