2 .\" Copyright (c) 2008-2010 Robert N. M. Watson
3 .\" Copyright (c) 2012-2013 The FreeBSD Foundation
4 .\" All rights reserved.
6 .\" This software was developed at the University of Cambridge Computer
7 .\" Laboratory with support from a grant from Google, Inc.
9 .\" Portions of this documentation were written by Pawel Jakub Dawidek
10 .\" under sponsorship from the FreeBSD Foundation.
12 .\" Redistribution and use in source and binary forms, with or without
13 .\" modification, are permitted provided that the following conditions
15 .\" 1. Redistributions of source code must retain the above copyright
16 .\" notice, this list of conditions and the following disclaimer.
17 .\" 2. Redistributions in binary form must reproduce the above copyright
18 .\" notice, this list of conditions and the following disclaimer in the
19 .\" documentation and/or other materials provided with the distribution.
21 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 .Dt CAP_RIGHTS_LIMIT 2
40 .Nd limit capability rights
46 .Fn cap_rights_limit "int fd" "const cap_rights_t *rights"
48 When a file descriptor is created by a function such as
62 it is assigned all capability rights.
63 Those rights can be reduced (but never expanded) by using the
66 Once capability rights are reduced, operations on the file descriptor will be
67 limited to those permitted by
72 argument should be prepared using
76 Capability rights assigned to a file descriptor can be obtained with the
80 The complete list of the capability rights can be found in the
86 The following example demonstrates how to limit file descriptor capability
87 rights to allow reading only.
89 cap_rights_t setrights;
93 fd = open("/tmp/foo", O_RDWR);
95 err(1, "open() failed");
98 err(1, "cap_enter() failed");
100 cap_rights_init(&setrights, CAP_READ);
101 if (cap_rights_limit(fd, &setrights) < 0)
102 err(1, "cap_rights_limit() failed");
106 if (write(fd, buf, sizeof(buf)) > 0)
107 errx(1, "write() succeeded!");
109 if (read(fd, buf, sizeof(buf)) < 0)
110 err(1, "read() failed");
119 argument is not a valid active descriptor.
121 An invalid right has been requested in
123 .It Bq Er ENOTCAPABLE
126 argument contains capability rights not present for the given file descriptor.
127 Capability rights list can only be reduced, never expanded.
145 .Xr cap_rights_get 3 ,
146 .Xr cap_rights_init 3 ,
153 function first appeared in
155 Support for capabilities and capabilities mode was developed as part of the
159 This function was created by
160 .An Pawel Jakub Dawidek Aq Mt pawel@dawidek.net
161 under sponsorship of the FreeBSD Foundation.