xref: /freebsd/contrib/xz/src/xz/sandbox.h (revision 783d3ff6)
1 // SPDX-License-Identifier: 0BSD
2 
3 ///////////////////////////////////////////////////////////////////////////////
4 //
5 /// \file       sandbox.h
6 /// \brief      Sandbox support
7 //
8 //  Author:     Lasse Collin
9 //
10 ///////////////////////////////////////////////////////////////////////////////
11 
12 #if defined(HAVE_PLEDGE) || defined(HAVE_LINUX_LANDLOCK_H) \
13 		|| defined(HAVE_CAP_RIGHTS_LIMIT)
14 #	define ENABLE_SANDBOX 1
15 #endif
16 
17 
18 /// \brief      Enables early sandboxing that can always be enabled
19 ///
20 /// This requires that tuklib_progname() and io_init() have been called.
21 extern void sandbox_init(void);
22 
23 
24 /// \brief      Enable sandboxing that only allows opening files for reading
25 extern void sandbox_enable_read_only(void);
26 
27 
28 /// \brief      Tell sandboxing code that strict sandboxing can be used
29 ///
30 /// This function only sets a flag which will be read by
31 /// sandbox_enable_strict_if_allowed().
32 extern void sandbox_allow_strict(void);
33 
34 
35 /// \brief      Enable sandboxing that allows reading from one file
36 ///
37 /// This does nothing if sandbox_allow_strict() hasn't been called.
38 ///
39 /// \param      src_fd          File descriptor open for reading
40 /// \param      pipe_event_fd   user_abort_pipe[0] from file_io.c
41 /// \param      pipe_write_fd   user_abort_pipe[1] from file_io.c
42 extern void sandbox_enable_strict_if_allowed(
43 		int src_fd, int pipe_event_fd, int pipe_write_fd);
44