1 .\" Copyright (c) 2013 The FreeBSD Foundation
2 .\" All rights reserved.
4 .\" This documentation was written by Pawel Jakub Dawidek under sponsorship
5 .\" from the FreeBSD Foundation.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
16 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 .Nd "library for handling application capabilities"
50 .Fd #define WITH_CASPER
56 .Fn cap_wrap "int sock" "int flags"
58 .Fn cap_unwrap "cap_channel_t *chan" "int *flags"
60 .Fn cap_sock "const cap_channel_t *chan"
62 .Fn cap_clone "const cap_channel_t *chan"
64 .Fn cap_close "cap_channel_t *chan"
66 .Fn cap_limit_get "const cap_channel_t *chan" "nvlist_t **limitsp"
68 .Fn cap_limit_set "const cap_channel_t *chan" "nvlist_t *limits"
70 .Fn cap_send_nvlist "const cap_channel_t *chan" "const nvlist_t *nvl"
72 .Fn cap_recv_nvlist "const cap_channel_t *chan"
74 .Fn cap_xfer_nvlist "const cap_channel_t *chan" "nvlist_t *nvl"
76 .Fn cap_service_open "const cap_channel_t *chan" "const char *name"
80 library allows to manage application capabilities through the casper process.
82 The application capability (represented by the
84 type) is a communication channel between the caller and the casper process
85 daemon or an instance of one of its services.
86 A capability to the casper process obtained with the
88 function allows to create capabilities to casper's services via the
94 function opens capability to the casper process.
100 based on the given socket.
101 The function is used when capability is inherited through
105 domain socket as a regular file descriptor and has to be represented as
110 argument defines the channel behavior.
111 The supported flags are:
112 .Bl -ohang -offset indent
114 The communication between process and casper uses no unique version of nvlist.
119 function is the opposite of the
124 structure and returns
126 domain socket associated with it.
130 function clones the given capability.
134 function closes the given capability.
140 domain socket descriptor associated with the given capability for use with
149 function stores current limits of the given capability in the
152 If the function return
158 it means there are no limits set.
162 function sets limits for the given capability.
163 The limits are provided as nvlist.
164 The exact format depends on the service the capability represents.
168 function sends the given nvlist over the given capability.
169 This is low level interface to communicate with casper services.
170 Most services should provide higher level API.
174 function receives the given nvlist over the given capability.
178 function sends the given nvlist, destroys it and receives new nvlist in
179 response over the given capability.
180 It does not matter if the function succeeds or fails, the nvlist given
181 for sending will always be destroyed once the function returns.
185 function opens casper service of the given name through casper capability
189 The function returns capability that provides access to opened service.
190 Casper supports the following services in the base system:
191 .Bl -tag -width "system.random" -compact -offset indent
194 provides DNS libc compatible API
204 allows to obtain entropy from
218 .Fn cap_recv_nvlist ,
219 .Fn cap_service_open ,
245 functions always succeed.
247 The following example first opens capability to the casper then using this
248 capability creates new capability to the
250 casper service and uses the latter capability to resolve IP address.
252 cap_channel_t *capcas, *capdns;
254 const char *ipstr = "127.0.0.1";
258 /* Open capability to the Casper. */
261 err(1, "Unable to contact Casper");
263 /* Enter capability mode sandbox. */
264 if (cap_enter() < 0 && errno != ENOSYS)
265 err(1, "Unable to enter capability mode");
267 /* Use Casper capability to create capability to the system.dns service. */
268 capdns = cap_service_open(capcas, "system.dns");
270 err(1, "Unable to open system.dns service");
272 /* Close Casper capability, we don't need it anymore. */
275 /* Limit system.dns to reverse DNS lookups and IPv4 addresses. */
276 limits = nvlist_create(0);
277 nvlist_add_string(limits, "type", "ADDR");
278 nvlist_add_number(limits, "family", (uint64_t)AF_INET);
279 if (cap_limit_set(capdns, limits) < 0)
280 err(1, "Unable to limit access to the system.dns service");
282 /* Convert IP address in C-string to in_addr. */
283 if (!inet_aton(ipstr, &ip))
284 errx(1, "Unable to parse IP address %s.", ipstr);
286 /* Find hostname for the given IP address. */
287 hp = cap_gethostbyaddr(capdns, (const void *)&ip, sizeof(ip), AF_INET);
289 errx(1, "No name associated with %s.", ipstr);
291 printf("Name associated with %s is %s.\\n", ipstr, hp->h_name);
299 .Xr cap_gethostbyaddr 3 ,
301 .Xr gethostbyaddr 3 ,
309 library was implemented by
310 .An Pawel Jakub Dawidek Aq Mt pawel@dawidek.net
311 under sponsorship from the FreeBSD Foundation.
314 new architecture was implemented by
315 .An Mariusz Zaborski Aq Mt oshogbo@FreeBSD.org