CAP_INIT(3)
π NAME π
okay bestie, gather round, because this is cap_init, cap_free, and cap_dup β aka the capability data object storage management trio π. yes, that's the whole vibe: they make the little storage box, they empty the little storage box, and they make a copy of the little storage box. slay.
β¨ SYNOPSIS β¨
like, here's how you actually get at them:
#include <sys/capability.h>
cap_t cap_init(void);
int cap_free(void *obj_d);
cap_t cap_dup(cap_t cap_p);
and don't forget to link it, bestie:
Link with -lcap.
π¦ DESCRIPTION π¦
okay so here's the thing that lowkey changes everything: the capabilities attached to a file or a process are never edited directly. nope. not ever. instead, you get given some working storage β a whole lil scratch pad β that holds a representation of the capability state. you do all your editing and manipulating inside that working storage area, and that's it. then once you're done editing, that updated capability state gets used to replace the capability state that belongs to the actual file or process. main character workflow fr fr π
cap_init()β this one creates a capability state in working storage and hands you back a pointer to it. the initial value of all flags are cleared, so it's giving fresh-start energy β¨. and the way that you're supposed to free any releasable memory once you don't need that working storage anymore? callcap_free()with thecap_tas an argument. periodt.cap_free()β this one liberates any releasable memory that was allocated to the capability state identified byobj_d. and here's the tea: theobj_dargument may identify either acap_tentity, or achar *entity allocated by thecap_to_text()function. so it's flexible like that, iykyk π.cap_dup()β returns a duplicate capability state in working storage, given by the source objectcap_p, allocating any memory necessary, and returning a pointer to the newly created capability state. once it's duplicated, no operation on either capability state affects the other in any way β they're fully independent, no shared group chat, no overlap, nothing π₯. when the duplicated capability state in working storage is no longer required, the caller should free any releasable memory by callingcap_free()with thecap_tas an argument. same ritual, every time π«Ά.
π RETURN VALUE π
cap_init()andcap_dup()return a non-NULLvalue on success, andNULLon failure. so if you getNULL, that's your sign bestie π.cap_free()returns zero on success, and-1on failure.
and on failure,errnois set toEINVALorENOMEM. so check yourerrno, it's literally telling you what went wrong π.
π CONFORMING TO π
these functions are specified in the withdrawn POSIX.1e draft specification. withdrawn, as in, it's not a current standard anymore β but these functions still live here, iconic behavior honestly πβ¨.
πΈ SEE ALSO πΈ
go read these next, they're all part of the same lil universe:
libcap(3)cap_clear(3)cap_copy_ext(3)cap_from_text(3)cap_get_file(3)cap_get_proc(3)capabilities(7)
okay that's the whole page, bestie!! this one's from the Linux Programmer's Manual, and the date on it is 2021-03-06 β so it's been out here being iconic since then. go forth and manage your capability storage responsibly π§πβ¨
π¦ 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 bookworm: libcap-dev 1:2.66-4+deb12u3+b1 Β· 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 noble: libcap-dev 1:2.66-5ubuntu2 Β· BSD-3-Clause OR GPL-2.0-only
- ubuntu noble: libcap-dev 1:2.66-5ubuntu2.4 Β· 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