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
40 .Nm cap_pwd_limit_cmds ,
41 .Nm cap_pwd_limit_fields ,
42 .Nm cap_pwd_limit_users
43 .Nd "library for password database operations in capability mode"
50 .Fn cap_getpwent "cap_channel_t *chan"
52 .Fn cap_getpwnam "cap_channel_t *chan" "const char *login"
54 .Fn cap_getpwuid "cap_channel_t *chan" "uid_t uid"
56 .Fn cap_getpwent_r "cap_channel_t *chan" "struct passwd *pwd" "char *buffer" "size_t bufsize" "struct passwd **result"
58 .Fn cap_getpwnam_r "cap_channel_t *chan" "const char *name" "struct passwd *pwd" "char *buffer" "size_t bufsize" "struct passwd **result"
60 .Fn cap_getpwuid_r "cap_channel_t *chan" "uid_t uid" "struct passwd *pwd" "char *buffer" "size_t bufsize" "struct passwd **result"
62 .Fn cap_setpassent "cap_channel_t *chan" "int stayopen"
64 .Fn cap_setpwent "cap_channel_t *chan"
66 .Fn cap_endpwent "cap_channel_t *chan"
68 .Fn cap_pwd_limit_cmds "cap_channel_t *chan" "const char * const *cmds" "size_t ncmds"
70 .Fn cap_pwd_limit_fields "cap_channel_t *chan" "const char * const *fields" "size_t nfields"
72 .Fn cap_pwd_limit_users "cap_channel_t *chan" "const char * const *names" "size_t nnames" "uid_t *uids" "size_t nuids"
85 are respectively equivalent to
96 except that the connection to the
98 service needs to be provided.
101 .Fn cap_pwd_limit_cmds
102 function limits the functions allowed in the service.
105 variable can be set to
116 which will allow to use the function associated with the name.
119 variable contains the number of
124 .Fn cap_pwd_limit_fields
125 function allows limit fields returned in the structure
129 variable can be set to
142 The field which was set as the limit will be returned, while the rest of the
143 values not set this way will have default values.
146 variable contains the number of
151 .Fn cap_pwd_limit_users
152 function allows to limit access to users.
155 variable allows to limit users by name and the
157 variable by the user number.
162 variables provide numbers of limited names and uids.
164 The following example first opens a capability to casper and then uses this
165 capability to create the
167 casper service and uses it to get a user name.
169 cap_channel_t *capcas, *cappwd;
170 const char *cmds[] = { "getpwuid" };
171 const char *fields[] = { "pw_name" };
173 struct passwd *passwd;
175 /* Open capability to Casper. */
178 err(1, "Unable to contact Casper");
180 /* Enter capability mode sandbox. */
181 if (cap_enter() < 0 && errno != ENOSYS)
182 err(1, "Unable to enter capability mode");
184 /* Use Casper capability to create capability to the system.pwd service. */
185 cappwd = cap_service_open(capcas, "system.pwd");
187 err(1, "Unable to open system.pwd service");
189 /* Close Casper capability, we don't need it anymore. */
192 /* Limit service to one single function. */
193 if (cap_pwd_limit_cmds(cappwd, cmds, nitems(cmds)))
194 err(1, "Unable to limit access to system.pwd service");
196 /* Limit service to one field as we only need name of the user. */
197 if (cap_pwd_limit_fields(cappwd, fields, nitems(fields)))
198 err(1, "Unable to limit access to system.pwd service");
200 /* Limit service to one uid. */
201 if (cap_pwd_limit_users(cappwd, NULL, 0, uid, nitems(uid)))
202 err(1, "Unable to limit access to system.pwd service");
204 passwd = cap_getpwuid(cappwd, uid[0]);
206 err(1, "Unable to get name of user");
208 printf("UID %d is associated with name %s.\\n", uid[0], passwd->pw_name);
229 service first appeared in
234 service was implemented by
235 .An Pawel Jakub Dawidek Aq Mt pawel@dawidek.net
236 under sponsorship from the FreeBSD Foundation.
238 This manual page was written by
239 .An Mariusz Zaborski Aq Mt oshogbo@FreeBSD.org .