1pub mod error;
2pub mod http;
3pub mod sandbox; pub mod profile;
5pub mod result;
6pub(crate) mod arch;
7pub(crate) mod sys;
8pub mod landlock;
9pub mod seccomp;
10pub(crate) mod resource;
11pub(crate) mod network;
12pub mod context;
13pub(crate) mod vdso;
14pub(crate) mod random;
15pub(crate) mod time;
16pub(crate) mod cow;
17pub(crate) mod checkpoint;
18pub(crate) mod freeze;
19pub mod netlink;
20pub(crate) mod procfs;
21pub(crate) mod port_remap;
22pub mod pipeline;
23pub mod policy_fn;
24pub mod image;
25pub mod fork;
26pub(crate) mod chroot;
27pub mod dry_run;
28pub(crate) mod http_acl;
29
30pub use error::SandlockError;
31pub use sys::structs::{SeccompData, SeccompNotif};
32pub use checkpoint::Checkpoint;
33pub use sandbox::{Confinement, ConfinementBuilder, Sandbox, SandboxBuilder};
34pub use result::{RunResult, ExitStatus};
35pub use pipeline::{Stage, Pipeline, Gather};
36pub use dry_run::{Change, ChangeKind, DryRunResult};
37pub use crate::profile::{ProfileInput, ProgramSpec};
40
41pub use seccomp::dispatch::{Handler, HandlerCtx, HandlerError};
43pub use seccomp::syscall::{Syscall, SyscallError};
44
45pub fn landlock_abi_version() -> Result<u32, error::ConfinementError> {
47 landlock::abi_version()
48}
49
50pub const MIN_LANDLOCK_ABI: u32 = landlock::MIN_ABI;
52
53pub fn confine(confinement: &Confinement) -> Result<(), SandlockError> {
61 if unsafe { libc::prctl(libc::PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) } != 0 {
63 return Err(SandlockError::Runtime(
64 error::SandboxRuntimeError::Confinement(
65 error::ConfinementError::Landlock(format!(
66 "prctl(PR_SET_NO_NEW_PRIVS): {}",
67 std::io::Error::last_os_error()
68 ))
69 )
70 ));
71 }
72
73 let mut builder = Sandbox::builder();
74 for path in &confinement.fs_readable {
75 builder = builder.fs_read(path.clone());
76 }
77 for path in &confinement.fs_writable {
78 builder = builder.fs_write(path.clone());
79 }
80 let stripped = builder.build()?;
81
82 landlock::confine_filesystem(&stripped)
84}