Debian Codegraph @

src/cap-ng.h

raw
1 /* libcap-ng.h --
2 * Copyright 2009,2013,2020-26 Red Hat Inc.
3 * All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program; see the file COPYING.LIB. If not, write to the
17 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor
18 * Boston, MA 02110-1335, USA.
19 *
20 * Authors:
21 * Steve Grubb <[email protected]>
22 */
23
24 #ifndef LIBCAP_NG_HEADER
25 #define LIBCAP_NG_HEADER
26
27 #include <stdint.h>
28 #include <stddef.h>
29 #include <linux/capability.h>
30 #include <unistd.h>
31
32 // The next 2 macros originate in sys/cdefs.h
33 // gcc-analyzer notation
34 #ifndef __attr_dealloc_free
35 # define __attr_dealloc_free
36 #endif
37
38 // Warn unused result
39 #ifndef __wur
40 # define __wur
41 #endif
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47 typedef enum { CAPNG_DROP, CAPNG_ADD } capng_act_t;
48 typedef enum { CAPNG_EFFECTIVE=1, CAPNG_PERMITTED=2,
49 CAPNG_INHERITABLE=4, CAPNG_BOUNDING_SET=8,
50 CAPNG_AMBIENT=16 } capng_type_t;
51 typedef enum { CAPNG_SELECT_CAPS = 16, CAPNG_SELECT_BOUNDS = 32,
52 CAPNG_SELECT_BOTH = 48, CAPNG_SELECT_AMBIENT = 64,
53 CAPNG_SELECT_ALL = 112 } capng_select_t;
54 typedef enum { CAPNG_FAIL=-1, CAPNG_NONE, CAPNG_PARTIAL,
55 CAPNG_FULL } capng_results_t;
56 typedef enum { CAPNG_PRINT_STDOUT, CAPNG_PRINT_BUFFER } capng_print_t;
57 typedef enum { CAPNG_NO_FLAG=0, CAPNG_DROP_SUPP_GRP=1,
58 CAPNG_CLEAR_BOUNDING=2, CAPNG_INIT_SUPP_GRP=4,
59 CAPNG_CLEAR_AMBIENT=8,
60 CAPNG_APPLY_STAGED_GROUPS=16,
61 CAPNG_APPLY_BOUNDING=32 } capng_flags_t;
62
63 #define CAPNG_UNSET_ROOTID -1
64 #define CAPNG_SUPPORTS_AMBIENT 1
65
66 // These functions manipulate process capabilities
67 void capng_clear(capng_select_t set);
68 void capng_fill(capng_select_t set);
69 void capng_setpid(int pid);
70 int capng_get_caps_process(void) __wur;
71 int capng_update(capng_act_t action, capng_type_t type,unsigned int capability);
72 int capng_updatev(capng_act_t action, capng_type_t type,
73 unsigned int capability, ...);
74
75 // These functions apply the capabilities previously setup to a process
76 int capng_apply(capng_select_t set) __wur;
77 int capng_lock(void) __wur;
78 int capng_change_id(int uid, int gid, capng_flags_t flag) __wur;
79 int capng_stage_additional_groups(const gid_t *gids, size_t count) __wur;
80
81 // These functions are used for file based capabilities
82 int capng_get_rootid(void);
83 int capng_set_rootid(int rootid);
84 int capng_get_caps_fd(int fd) __wur;
85 int capng_apply_caps_fd(int fd) __wur;
86
87 // These functions check capability bits
88 capng_results_t capng_have_capabilities(capng_select_t set);
89 capng_results_t capng_have_permitted_capabilities(void);
90 int capng_have_capability(capng_type_t which, unsigned int capability);
91
92 // These functions printout capabilities
93 char *capng_print_caps_numeric(capng_print_t where, capng_select_t set);
94 char *capng_print_caps_text(capng_print_t where, capng_type_t which);
95
96 // These functions convert between numeric and text string
97 int capng_name_to_capability(const char *name);
98 const char *capng_capability_to_name(unsigned int capability);
99
100 // These function should be used when you suspect a third party library
101 // may use libcap-ng also and want to make sure it doesn't alter something
102 // important. Otherwise you shouldn't need to call these.
103 void capng_restore_state(void **state);
104 void *capng_save_state(void);
105
106 #ifdef __cplusplus
107 }
108 #endif
109
110
111 #endif