CAP_COPY_EXT(3)
π CAP_COPY_EXT(3) β the Linux Programmer's Manual, but make it make sense π
okay bestie, sit down, hydrate, because today we're talking about cap_copy_ext, cap_size, cap_copy_int, and cap_copy_int_check β the little glue crew from the Linux Programmer's Manual that translates capability states between internal and external form. it's giving translator-girlie energy. πΈ
β¨ NAME β¨
cap_copy_ext, cap_size, cap_copy_int β capability state external representation translation. plus cap_copy_int_check hanging out with them because of course. π
π¦ SYNOPSIS π¦
#include <sys/capability.h>
ssize_t cap_size(cap_t cap_p);
ssize_t cap_copy_ext(void *ext_p, cap_t cap_p, ssize_t size);
cap_t cap_copy_int(const void * ext_p);
cap_t cap_copy_int_check(const void *cap_ext, ssize_t length);
and like, don't forget:
Link with -lcap.
π DESCRIPTION π
so these functions translate between internal and external representations of a capability state. two formats, one glow-up. β¨
the external representation is an exportable, contiguous, persistent representation of a capability state in user-managed space. the internal representation is managed by the capability functions in working storage. literally the same info, different outfit. π
cap_size() returns the total length (in bytes) that the capability state in working storage identified by cap_p would require when converted by cap_copy_ext(). this one is your bestie who measures the room before you move the couch in β it's used primarily to determine the amount of buffer space that must be provided to the cap_copy_ext() function in order to hold the capability data record created from cap_p. no cap. π
cap_copy_ext() copies a capability state in working storage, identified by cap_p, from system-managed space to user-managed space (pointed to by ext_p) and returns the length of the resulting data record. the size parameter represents the maximum size, in bytes, of the resulting data record. and the way that cap_copy_ext() will do any conversions necessary to convert the capability state from the undefined internal format to an exportable, contiguous, persistent data recordβ¦ obsessed. it is the responsibility of the user to allocate a buffer large enough to hold the copied data, bestie. that's on you. the buffer length required to hold the copied data may be obtained by a call to the cap_size() function β that's literally what it's for, go ask it. π«Ά
cap_copy_int() copies a capability state from a capability data record in user-managed space to a new capability state in working storage, allocating any memory necessary, and returning a pointer to the newly created capability state. it initializes the capability state and then copies the capability state from the record pointed to by ext_p into the capability state, converting, if necessary, the data from a contiguous, persistent format to an opaque, internal format. once copied into internal format, the object can be manipulated by the capability state manipulation functions (see cap_clear(3)). π
β οΈ important, and I mean it: note that the record pointed to byext_pmust have been obtained from a previous, successful call tocap_copy_ext()for this function to work successfully. do not just hand it a random blob, queen. π
also, the caller should free any releasable memory, when the capability state in working storage is no longer required, by calling cap_free() with the cap_t as an argument. clean up after yourself, it's self-care. π§
cap_copy_int_check() performs the same operation as cap_copy_int() but additionally checks that the provided external data's size is not larger than the noted length. it's the same girl but with a security detail. π₯
π RETURN VALUE π
cap_size()β returns the length required to hold a capability data record on success, and-1on failure. πcap_copy_ext()β returns the number of bytes placed in the user managed space pointed to byext_pon success, and-1on failure.cap_copy_int()andcap_copy_int_check()β return a pointer to the newly created capability state in working storage on success, andNULLon failure.
on failure,errnois set toEINVAL,ENOMEM, orERANGE. so if things go sideways, checkerrno, that's your group chat receipts. π
β CONFORMING TO β
these functions are specified in the withdrawn POSIX.1e draft specification. yes, withdrawn. we still love her though. π
π SEE ALSO π
and that's the whole page, bestie!! this one's from the Linux Programmer's Manual, dated 2021-03-06, and it lives under CAP_COPY_EXT(3) in section 3. go forth and translate your capability states responsibly. slay, periodt, and always call cap_free(). πβ¨ππ¦
π¦ 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