CAP_CLEAR(3)
β¨ CAP_CLEAR π (the Linux Programmer's Manual girlies' edition)
okay so bestie, welcome to the little corner of libcap where we poke at capability data objects π this is CAP_CLEAR(3) from the Linux Programmer's Manual and it's lowkey one of the most useful pages ever, no cap.
πΈ NAME πΈ
cap_clear, cap_clear_flag, cap_get_flag, cap_set_flag, cap_fill_flag, cap_fill, cap_compare, cap_max_bits β capability data object manipulation β¨
it's giving "we're gonna mess with capabilities in working storage" and honestly? iconic.
π¦ SYNOPSIS π¦
#include <sys/capability.h>
int cap_clear(cap_t cap_p);
int cap_clear_flag(cap_t cap_p, cap_flag_t flag);
int cap_get_flag(cap_t cap_p, cap_value_t cap,
cap_flag_t flag, cap_flag_value_t *value_p);
int cap_set_flag(cap_t cap_p, cap_flag_t flag, int ncap,
const cap_value_t *caps, cap_flag_value_t value);
int cap_fill_flag(cap_t cap_p, cap_flag_t to,
const cap_t ref, cap_flag_t from);
int cap_fill(cap_t cap_p, cap_flag_t to, cap_flag_t from);
int cap_compare(cap_t cap_a, cap_t cap_b);
cap_value_t cap_max_bits();
Link with -lcap.
π friendly reminder: link with -lcap or the linker will simply not know her. periodt.
π DESCRIPTION π
so these functions all work on a capability state held in working storage. a cap_t holds info about the capabilities in each of the three flags β Permitted, Inheritable, and Effective. and every single capability in a set can be either clear (disabled, 0) or set (enabled, 1). that's it, that's the vibe check πΈ
π the data types, bestie (know them, love them)
cap_value_tβ identifies a capability, such asCAP_CHOWN. yeah, that's the girl.cap_flag_tβ identifies one of the three flags associated with a capability (i.e., it identifies one of the three capability dimensions π). valid values for this type areCAP_EFFECTIVE,CAP_INHERITABLEorCAP_PERMITTED.cap_flag_value_tβ identifies the setting of a particular capability flag (i.e, the value of a capability in a set). valid values for this type areCAP_CLEAR(0) orCAP_SET(1).
π§ and now the functions, one by one
cap_clear()β initializes the capability state in working storage identified bycap_pso that all capability flags are cleared. a full reset, a clean slate, main character energy β¨cap_clear_flag()β clears all of the capabilities of the specified capability flag,flag. just that one flag, not the whole girl.cap_get_flag()β obtains the current value of the capability flag,flag, of the capability,cap, from the capability state identified bycap_pand places it in the location pointed to byvalue_p. yes bestie it writes through the pointer, that's the whole point πcap_set_flag()β sets the flag,flag, of each capability in the arraycapsin the capability state identified bycap_ptovalue. the argument,ncap, is used to specify the number of capabilities in the array,caps. so like, how many are in the group chat π«Άcap_fill_flag()β fills thetoflag of one capability set, with the values in thefromflag of a reference capability set. copying, but make it cap-flavoured.cap_fill()β fills thetoflag values by copying all of thefromflag values. the glow-up transfer πcap_compare()β compares two full capability sets and, in the spirit ofmemcmp(), returns zero if the two capability sets are identical. a positive return value indicates there is a difference between them. the returned value carries further information about thecap_flag_tflag differences. Specifically, the macroCAP_DIFFERS (value, flag)evaluates to non-zero if the returned value differs in its flag components. iykyk π₯cap_max_bits()β returns the number of capability values known to the running kernel. this may differ from libcap's list known at compilation time. Unnamed, at compilation time, capabilites can be referred to numerically and libcap will handle them appropriately. Note, the running kernel wins and it gets to define what "all" capabilities means. she's the boss, fr fr π
π RETURN VALUE π
cap_clear(), cap_clear_flag(), cap_get_flag() cap_set_flag() and cap_compare() return zero on success, and -1 on failure. Other return values for cap_compare() are described above. The function cap_max_bits() returns a numeric value of type cap_value_t that is one larger than the largest actual value known to the running kernel.
On failure, errno is set to EINVAL, indicating that one of the arguments is invalid. so like, check your args bestie, don't be that girl π
π CONFORMING TO π
These functions are mostly as per specified in the withdrawn POSIX.1e draft specification. The following are Linux extensions: cap_fill(), cap_fill_flag(), cap_clear_flag(), cap_compare() and cap_max_bits(). yes, withdrawn β we still love her though π
π SEE ALSO π
libcap(3), cap_copy_ext(3), cap_from_text(3), cap_get_file(3), cap_get_proc(3), cap_init(3), capabilities(7)
okay that's the whole page bestie, you ate π
this one's from 2022-10-16, and it's CAP_CLEAR(3) β part of the Linux Programmer's Manual β signing off with love and no cap π¦β¨π
π¦ where this page comes from
- alpine 3.22: libcap-doc 2.78-r0 Β· BSD-3-Clause OR GPL-2.0-only
- alpine 3.23: libcap-doc 2.78-r0 Β· BSD-3-Clause OR GPL-2.0-only
- alpine 3.24: libcap-doc 2.78-r0 Β· BSD-3-Clause OR GPL-2.0-only
- arch rolling: libcap 2.78-1 Β· BSD-3-Clause OR GPL-2.0-only
- centos-stream 10: libcap-devel 2.69-7.el10 Β· BSD-3-Clause OR GPL-2.0-only
- debian trixie: libcap-dev 1:2.75-10+deb13u1+b3 Β· BSD-3-Clause OR GPL-2.0-only
- fedora 43: libcap-devel 2.76-3.fc43 Β· BSD-3-Clause OR GPL-2.0-only
- fedora 43: libcap-devel 2.76-3.fc43 Β· BSD-3-Clause OR GPL-2.0-only
- fedora 43: libcap-devel 2.76-4.fc43 Β· BSD-3-Clause OR GPL-2.0-only
- fedora 43: libcap-devel 2.76-4.fc43 Β· BSD-3-Clause OR GPL-2.0-only
- fedora 44: libcap-devel 2.77-2.fc44 Β· BSD-3-Clause OR GPL-2.0-only
- fedora 44: libcap-devel 2.77-2.fc44 Β· BSD-3-Clause OR GPL-2.0-only
- fedora 44: libcap-devel 2.78-1.fc44 Β· BSD-3-Clause OR GPL-2.0-only
- fedora 44: libcap-devel 2.78-1.fc44 Β· BSD-3-Clause OR GPL-2.0-only
- nixpkgs unstable: libcap 2.78
- opensuse-leap 16.0: libcap-devel 2.73-160000.3.1 Β· BSD-3-Clause OR GPL-2.0-only
- opensuse-leap 16.0: libcap-devel 2.73-160000.3.1 Β· BSD-3-Clause OR GPL-2.0-only
- opensuse-leap 16.0: libcap-devel 2.73-160000.3.1 Β· BSD-3-Clause OR GPL-2.0-only
- opensuse-leap 16.0: libcap-devel 2.73-160000.3.1 Β· BSD-3-Clause OR GPL-2.0-only
- ubuntu questing: libcap-dev 1:2.75-7ubuntu2
- ubuntu questing: libcap-dev 1:2.75-7ubuntu2.2
- ubuntu resolute: libcap-dev 1:2.75-10ubuntu2 Β· BSD-3-Clause OR GPL-2.0-only
- ubuntu stonking: libcap-dev 1:2.78-1ubuntu1 Β· BSD-3-Clause OR GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms