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
32 .Nm fileargs_cinitnv ,
39 .Nd "library for handling files in capability mode"
45 .In casper/cap_fileargs.h
47 .Fn fileargs_init "int argc" "char *argv[]" "int flags" "mode_t mode" "cap_rights_t *rightsp" "int operations"
49 .Fn fileargs_cinit "cap_channel_t *cas" "int argc" "char *argv[]" "int flags" "mode_t mode" "cap_rights_t *rightsp" "int operations"
51 .Fn fileargs_cinitnv "cap_channel_t *cas" "nvlist_t *limits"
53 .Fn fileargs_initnv "nvlist_t *limits"
55 .Fn fileargs_free "fileargs_t *fa"
57 .Fn fileargs_lstat "fileargs_t *fa" "const char *path" "struct stat *sb"
59 .Fn fileargs_open "fileargs_t *fa" "const char *name"
61 .Fn fileargs_fopen "fileargs_t *fa" "const char *name" "const char *mode"
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
124 except that the connection to the Casper needs to be provided.
130 are respectively equivalent to
134 expect that all arguments all provided as
141 close connection to the
143 service and free are structures.
157 are respectively equivalent to
161 expect that all arguments are fetched from the
165 This section describe which values and types should be used to pass arguments to the
174 for that functions must contain the following values and types:
175 .Bl -ohang -offset indent
176 .It flags ( NV_TYPE_NUMBER )
179 limits opened files for either execution or reading and/or writing.
180 .It mode (NV_TYPE_NUMBER)
191 argument tells which what mode file should be created.
192 .It operations (NV_TYPE_NUMBER)
195 limits the usable operations for
196 .Fa system.fileargs .
197 The possible values are explained as
205 for that functions may contain the following values and types:
206 .Bl -ohang -offset indent
207 .It cap_rights ( NV_TYPE_BINARY )
210 argument contains a list of the capability rights which file should be limited to.
214 where the name of the element is name of the file which can be opened.
216 The following example first parse some options and then create the
218 service with remaining arguments.
224 while ((ch = getopt(argc, argv, "h")) != -1) {
235 /* Create capability to the system.fileargs service. */
236 fa = fileargs_init(argc, argv, O_RDONLY, 0,
237 cap_rights_init(&rights, CAP_READ), FA_OPEN);
239 err(1, "unable to open system.fileargs service");
241 /* Enter capability mode sandbox. */
242 if (cap_enter() < 0 && errno != ENOSYS)
243 err(1, "unable to enter capability mode");
246 for (i = 0; i < argc; i++) {
247 fd = fileargs_open(fa, argv[i]);
249 err(1, "unable to open file %s", argv[i]);
250 printf("File %s opened in capability mode\en", argv[i]);
260 .Xr cap_rights_init 3 ,
269 service first appeared in
276 is considered experimental, and should not be deployed in production
277 environments without careful consideration of the risks associated with
278 the use of experimental operating system features.
280 .An Mariusz Zaborski Aq Mt oshogbo@FreeBSD.org