]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - lib/libc/gen/cap_rights_get.3
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / lib / libc / gen / cap_rights_get.3
1 .\"
2 .\" Copyright (c) 2013 The FreeBSD Foundation
3 .\" All rights reserved.
4 .\"
5 .\" This documentation was written by Pawel Jakub Dawidek under sponsorship
6 .\" from the FreeBSD Foundation.
7 .\"
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
10 .\" are met:
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\"    notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\"    notice, this list of conditions and the following disclaimer in the
15 .\"    documentation and/or other materials provided with the distribution.
16 .\"
17 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 .\" SUCH DAMAGE.
28 .\"
29 .\" $FreeBSD$
30 .\"
31 .Dd September 23, 2013
32 .Dt CAP_RIGHTS_GET 3
33 .Os
34 .Sh NAME
35 .Nm cap_rights_get
36 .Nd obtain capability rights
37 .Sh LIBRARY
38 .Lb libc
39 .Sh SYNOPSIS
40 .In sys/capability.h
41 .Ft int
42 .Fn cap_rights_get "int fd" "cap_rights_t *rights"
43 .Sh DESCRIPTION
44 The
45 .Nm cap_rights_get
46 function allows to obtain current capability rights for the given descriptor.
47 The function will fill the
48 .Fa rights
49 argument with all capability rights if they were not limited or capability
50 rights configured during the last successful call of
51 .Xr cap_rights_limit 2
52 on the given descriptor.
53 .Pp
54 The
55 .Fa rights
56 argument can be inspected using
57 .Xr cap_rights_init 3
58 family of functions.
59 .Pp
60 The complete list of the capability rights can be found in the
61 .Xr rights 4
62 manual page.
63 .Sh RETURN VALUES
64 .Rv -std
65 .Sh EXAMPLES
66 The following example demonstrates how to limit file descriptor capability
67 rights and how to obtain them.
68 .Bd -literal
69 cap_rights_t setrights, getrights;
70 int fd;
71
72 memset(&setrights, 0, sizeof(setrights));
73 memset(&getrights, 0, sizeof(getrights));
74
75 fd = open("/tmp/foo", O_RDONLY);
76 if (fd < 0)
77         err(1, "open() failed");
78
79 cap_rights_init(&setrights, CAP_FSTAT, CAP_READ);
80 if (cap_rights_limit(fd, &setrights) < 0 && errno != ENOSYS)
81         err(1, "cap_rights_limit() failed");
82
83 if (cap_rights_get(fd, &getrights) < 0 && errno != ENOSYS)
84         err(1, "cap_rights_get() failed");
85
86 assert(memcmp(&setrights, &getrights, sizeof(setrights)) == 0);
87 .Ed
88 .Sh ERRORS
89 .Fn cap_rights_get
90 succeeds unless:
91 .Bl -tag -width Er
92 .It Bq Er EBADF
93 The
94 .Fa fd
95 argument is not a valid active descriptor.
96 .It Bq Er EFAULT
97 The
98 .Fa rights
99 argument points at an invalid address.
100 .El
101 .Sh SEE ALSO
102 .Xr cap_rights_limit 2 ,
103 .Xr cap_rights_init 3 ,
104 .Xr errno 2 ,
105 .Xr open 2 ,
106 .Xr assert 3 ,
107 .Xr err 3 ,
108 .Xr memcmp 3 ,
109 .Xr memset 3 ,
110 .Xr capsicum 4 ,
111 .Xr rights 4
112 .Sh HISTORY
113 Support for capabilities and capabilities mode was developed as part of the
114 .Tn TrustedBSD
115 Project.
116 .Sh AUTHORS
117 This function was created by
118 .An Pawel Jakub Dawidek Aq pawel@dawidek.net
119 under sponsorship of the FreeBSD Foundation.