1 .\" Copyright (c) 2018 Mariusz Zaborski <oshogbo@FreeBSD.org>
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 .Nm cap_grp_limit_cmds ,
39 .Nm cap_grp_limit_fields ,
40 .Nm cap_grp_limit_groups
41 .Nd "library for group database operations in capability mode"
49 .Fn cap_getgrent "cap_channel_t *chan"
51 .Fn cap_getgrnam "cap_channel_t *chan" "const char *name"
53 .Fn cap_getgrgid "cap_channel_t *chan" "gid_t gid"
55 .Fn cap_getgrent_r "cap_channel_t *chan" "struct group *grp" "char *buffer" "size_t bufsize" "struct group **result"
57 .Fn cap_getgrnam_r "cap_channel_t *chan" "const char *name" "struct group *grp" "char *buffer" "size_t bufsize" "struct group **result"
59 .Fn cap_getgrgid_r "cap_channel_t *chan" "gid_t gid" "struct group *grp" "char *buffer" "size_t bufsize" "struct group **result"
61 .Fn cap_setgroupent "cap_channel_t *chan" "int stayopen"
63 .Fn cap_setgrent "cap_channel_t *chan"
65 .Fn cap_endgrent "cap_channel_t *chan"
67 .Fn cap_grp_limit_cmds "cap_channel_t *chan" "const char * const *cmds" "size_t ncmds"
69 .Fn cap_grp_limit_fields "cap_channel_t *chan" "const char * const *fields" "size_t nfields"
71 .Fn cap_grp_limit_groups "cap_channel_t *chan" "const char * const *names" "size_t nnames" "const gid_t *gids" "size_t ngids"
84 are respectively equivalent to
95 except that the connection to the
97 service needs to be provided.
100 .Fn cap_grp_limit_cmds
101 function limits the functions allowed in the service.
104 variable can be set to
115 which will allow to use the function associated with the name.
118 variable contains the number of
123 .Fn cap_grp_limit_fields
124 function allows limit fields returned in the structure
128 variable can be set to
134 The field which was set as the limit will be returned, while the rest of the
135 values not set this way will have default values.
138 variable contains the number of
143 .Fn cap_grp_limit_groups
144 function allows to limit access to groups.
147 variable allows to limit groups by name and the
149 variable by the group number.
154 variables provide numbers of limited names and gids.
156 The following example first opens a capability to casper and then uses this
157 capability to create the
159 casper service and uses it to get a group name.
161 cap_channel_t *capcas, *capgrp;
162 const char *cmds[] = { "getgrgid" };
163 const char *fields[] = { "gr_name" };
164 const gid_t gid[] = { 1 };
167 /* Open capability to Casper. */
170 err(1, "Unable to contact Casper");
172 /* Enter capability mode sandbox. */
173 if (cap_enter() < 0 && errno != ENOSYS)
174 err(1, "Unable to enter capability mode");
176 /* Use Casper capability to create capability to the system.grp service. */
177 capgrp = cap_service_open(capcas, "system.grp");
179 err(1, "Unable to open system.grp service");
181 /* Close Casper capability, we don't need it anymore. */
184 /* Limit service to one single function. */
185 if (cap_grp_limit_cmds(capgrp, cmds, nitems(cmds)))
186 err(1, "Unable to limit access to system.grp service");
188 /* Limit service to one field as we only need name of the group. */
189 if (cap_grp_limit_fields(capgrp, fields, nitems(fields)))
190 err(1, "Unable to limit access to system.grp service");
192 /* Limit service to one gid. */
193 if (cap_grp_limit_groups(capgrp, NULL, 0, gid, nitems(gid)))
194 err(1, "Unable to limit access to system.grp service");
196 group = cap_getgrgid(capgrp, gid[0]);
198 err(1, "Unable to get name of group");
200 printf("GID %d is associated with name %s.\\n", gid[0], group->gr_name);
221 service first appeared in
226 service was implemented by
227 .An Pawel Jakub Dawidek Aq Mt pawel@dawidek.net
228 under sponsorship from the FreeBSD Foundation.
230 This manual page was written by
231 .An Mariusz Zaborski Aq Mt oshogbo@FreeBSD.org .