LIBCASPER(3)
β¨ NAME β¨
okay bestie, welcome to libcasper(3) β literally the library for handling application capabilities π
. The whole squad is here: cap_init, cap_wrap, cap_unwrap, cap_sock, cap_clone, cap_close, cap_limit_get, cap_limit_set, cap_send_nvlist, cap_recv_nvlist, cap_xfer_nvlist, and cap_service_open π«Ά.
π LIBRARY π
library βlibcasperβ β¨
π¦ SYNOPSIS π¦
#define WITH_CASPER
#include <sys/nv.h>
#include <libcasper.h>
cap_channel_t *
cap_init(void);
cap_channel_t *
cap_wrap(int sock, int flags);
int
cap_unwrap(cap_channel_t *chan, int *flags);
int
cap_sock(const cap_channel_t *chan);
cap_channel_t *
cap_clone(const cap_channel_t *chan);
void
cap_close(cap_channel_t *chan);
int
cap_limit_get(const cap_channel_t *chan, nvlist_t **limitsp);
int
cap_limit_set(const cap_channel_t *chan, nvlist_t *limits);
int
cap_send_nvlist(const cap_channel_t *chan, const nvlist_t *nvl);
nvlist_t *
cap_recv_nvlist(const cap_channel_t *chan);
nvlist_t *
cap_xfer_nvlist(const cap_channel_t *chan, nvlist_t *nvl);
cap_channel_t *
cap_service_open(const cap_channel_t *chan, const char *name);
π DESCRIPTION π
so the libcasper library is all about controlling application capabilities through the casper process β¨.
An application capability β represented by the cap_channel_t type β is a communication channel between the caller and the casper daemon, or an instance of one of the daemonβs services π«Ά. A capability to the casper process, obtained with the cap_init() function, lets a program create capabilities to access the casper daemonβs services via the cap_service_open() function. slay.
The cap_init() function instantiates a capability to allow a program to access the casper daemon πΈ.
The cap_wrap() function creates a cap_channel_t based on the socket supplied in the call. Itβs used when a capability is inherited through the execve(2) system call, or sent over a unix(4) domain socket as a file descriptor, and has to be converted into a cap_channel_t π. The flags argument defines the channel behavior. The supported flags are:
CASPER_NO_UNIQβ the communication between the process and the casper daemon uses no unique version of nvlist π
The cap_unwrap() function returns the unix(4) domain socket used by the daemon service, and frees the cap_channel_t structure π
.
The cap_clone() function returns a clone of the capability passed as its only argument π¦.
The cap_close() function closes, and frees, the given capability β¨.
The cap_sock() function returns the unix(4) domain socket descriptor associated with the given capability for use with system calls such as: kevent(2), poll(2), and select(2) π.
The cap_limit_get() function stores the current limits of the given capability in the limitsp argument. If the function returns 0 and NULL is stored in the limitsp argument, there are no limits set β.
The cap_limit_set() function sets limits for the given capability. The limits are provided as an nvlist(9) π. The exact format of the limits depends on the service that the capability represents. cap_limit_set() frees the limits passed to the call, whether or not the operation succeeds or fails β no cap, that part matters π.
The cap_send_nvlist() function sends the given nvlist(9) over the given capability. This is a low level interface to communicate with casper services. It is expected that most services will provide a higher level API π«Ά.
The cap_recv_nvlist() function receives the given nvlist(9) over the given capability π.
The cap_xfer_nvlist() function sends the given nvlist(9), destroys it, and receives a new nvlist(9) in response over the given capability π₯. It does not matter if the function succeeds or fails β the nvlist(9) given for sending will always be destroyed before the function returns. periodt.
The cap_service_open() function opens the casper service named in the call using the casper capability obtained via the cap_init() function. cap_service_open() returns a capability that provides access to the opened service π. Casper supports the following services in the base system:
system.dnsβ provides libc compatible DNS APIsystem.fileargsβ provides an API for opening files specified on a command linesystem.grpβ provides agetgrent(3)compatible APIsystem.netβ provides a libc compatible network APIsystem.netdbβ provides libc compatible network proto APIsystem.pwdβ provides agetpwent(3)compatible APIsystem.sysctlβ provides asysctlbyname(3)compatible APIsystem.syslogβ provides asyslog(3)compatible API
okay so thread-safety tea β: cap_init() must be called from a single-threaded context. cap_clone(), cap_close(), cap_limit_get(), cap_limit_set(), cap_send_nvlist(), cap_recv_nvlist(), and cap_service_open() are reentrant but not thread-safe. That is, they may be called from separate threads only with different cap_channel_t arguments or with synchronization π.
bestie, that last bit is not a vibe suggestion β itβs literally the rule π.
π RETURN VALUES π
cap_clone(),cap_init(),cap_recv_nvlist(),cap_service_open(),cap_wrap(), andcap_xfer_nvlist()returnNULLand set theerrnovariable on failure π.cap_limit_get(),cap_limit_set(), andcap_send_nvlist()return-1and set theerrnovariable on failure π.cap_close(),cap_sock(), andcap_unwrap()always succeed β¨.
π¦ SEE ALSO π¦
errno(2), execve(2), kevent(2), poll(2), select(2), cap_dns(3), cap_fileargs(3), cap_grp(3), cap_net(3), cap_netdb(3), cap_pwd(3), cap_sysctl(3), cap_syslog(3), libcasper_service(3), capsicum(4), unix(4), nv(9) π.
πΈ HISTORY πΈ
The libcasper library first appeared in FreeBSD 10.3 π.
π AUTHORS π
The libcasper library was implemented by Pawel Jakub Dawidek <pawel@dawidek.net> under sponsorship from the FreeBSD Foundation π«Ά. The libcasper new architecture was implemented by Mariusz Zaborski <oshogbo@FreeBSD.org> π.
and thatβs the page, bestie π
. the footer energy is Debian, December 6, 2023, LIBCASPER(3) β iconic, no cap πβ¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 2013 The FreeBSD Foundation
- Copyright (c) 2018 Mariusz Zaborski <oshogbo@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms