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
30 .Nm fileargs_cinitnv ,
37 .Nd "library for handling files in capability mode"
43 .In casper/cap_fileargs.h
45 .Fn fileargs_init "int argc" "char *argv[]" "int flags" "mode_t mode" "cap_rights_t *rightsp" "int operations"
47 .Fn fileargs_cinit "cap_channel_t *cas" "int argc" "char *argv[]" "int flags" "mode_t mode" "cap_rights_t *rightsp" "int operations"
49 .Fn fileargs_cinitnv "cap_channel_t *cas" "nvlist_t *limits"
51 .Fn fileargs_initnv "nvlist_t *limits"
53 .Fn fileargs_free "fileargs_t *fa"
55 .Fn fileargs_lstat "fileargs_t *fa" "const char *path" "struct stat *sb"
57 .Fn fileargs_open "fileargs_t *fa" "const char *name"
59 .Fn fileargs_fopen "fileargs_t *fa" "const char *name" "const char *mode"
61 .Fn fileargs_realpath "fileargs_t *fa" "const char *pathname" "char *reserved_path"
63 The library is used to simplify Capsicumizing a tools that are using file system.
64 Idea behind the library is that we are passing a remaining
68 which contains a list of files that should be open for this program.
69 The library will create a service that will serve those files.
73 create a service to the
77 contains a list of files that should be opened.
78 The argument can be set to
80 which will not create a service and all files will be prohibited to be opened.
83 argument contains a number of passed files.
86 argument limits opened files for either execution or reading and/or writing.
89 argument tells which what mode file should be created if the
92 For more details of the
100 argument contains a list of the capability rights which file should be limited to.
101 For more details of the capability rights see
102 .Xr cap_rights_init 3 .
105 argument limits the operations that are available using
106 .Nm system.fileargs .
109 .Bl -ohang -offset indent
120 .Fn fileargs_realpath .
127 except that the connection to the Casper needs to be provided.
133 are respectively equivalent to
137 expect that all arguments all provided as
144 close connection to the
146 service and free are structures.
160 are respectively equivalent to
164 expect that all arguments are fetched from the
169 .Fn fileargs_realpath
173 This section describe which values and types should be used to pass arguments to the
182 for that functions must contain the following values and types:
183 .Bl -ohang -offset indent
184 .It flags ( NV_TYPE_NUMBER )
187 limits opened files for either execution or reading and/or writing.
188 .It mode (NV_TYPE_NUMBER)
199 argument tells which what mode file should be created.
200 .It operations (NV_TYPE_NUMBER)
203 limits the usable operations for
204 .Fa system.fileargs .
205 The possible values are explained as
213 for that functions may contain the following values and types:
214 .Bl -ohang -offset indent
215 .It cap_rights ( NV_TYPE_BINARY )
218 argument contains a list of the capability rights which file should be limited to.
222 where the name of the element is name of the file which can be opened.
225 The following example first parse some options and then create the
227 service with remaining arguments.
233 while ((ch = getopt(argc, argv, "h")) != -1) {
244 /* Create capability to the system.fileargs service. */
245 fa = fileargs_init(argc, argv, O_RDONLY, 0,
246 cap_rights_init(&rights, CAP_READ), FA_OPEN);
248 err(1, "unable to open system.fileargs service");
250 /* Enter capability mode sandbox. */
251 if (cap_enter() < 0 && errno != ENOSYS)
252 err(1, "unable to enter capability mode");
255 for (i = 0; i < argc; i++) {
256 fd = fileargs_open(fa, argv[i]);
258 err(1, "unable to open file %s", argv[i]);
259 printf("File %s opened in capability mode\en", argv[i]);
269 .Xr cap_rights_init 3 ,
279 service first appeared in
282 .An Mariusz Zaborski Aq Mt oshogbo@FreeBSD.org
288 is considered experimental, and should not be deployed in production
289 environments without careful consideration of the risks associated with
290 the use of experimental operating system features.