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 protection;
10pub mod seccomp;
11pub(crate) mod resource;
12pub(crate) mod network;
13pub mod context;
14pub(crate) mod resolved;
15pub(crate) mod seccomp_plan;
16pub(crate) mod vdso;
17pub(crate) mod random;
18pub(crate) mod time;
19pub(crate) mod cow;
20pub(crate) mod checkpoint;
21pub(crate) mod freeze;
22pub mod netlink;
23pub(crate) mod procfs;
24pub(crate) mod port_remap;
25pub mod pipeline;
26pub mod policy_fn;
27pub mod image;
28pub mod fork;
29pub(crate) mod ca_inject;
30pub(crate) mod chroot;
31pub mod dry_run;
32mod transparent_proxy;
33
34pub use error::SandlockError;
35pub use sys::structs::{SeccompData, SeccompNotif};
36pub use checkpoint::Checkpoint;
37pub use protection::{Protection, ProtectionState, ProtectionPolicy, ProtectionStatus};
38pub use sandbox::{Confinement, ConfinementBuilder, Sandbox, SandboxBuilder};
39pub use result::{RunResult, ExitStatus};
40pub use pipeline::{Stage, Pipeline, Gather};
41pub use dry_run::{Change, ChangeKind, DryRunResult};
42pub use crate::profile::{ProfileInput, ProgramSpec};
45
46pub use seccomp::dispatch::{Handler, HandlerCtx, HandlerError};
48pub use seccomp::syscall::{Syscall, SyscallError};
49
50pub fn landlock_abi_version() -> Result<u32, error::ConfinementError> {
52 landlock::abi_version()
53}
54
55pub const MIN_LANDLOCK_ABI: u32 = landlock::MIN_ABI;
57
58pub fn confine(confinement: &Confinement) -> Result<(), SandlockError> {
66 if unsafe { libc::prctl(libc::PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) } != 0 {
68 return Err(SandlockError::Runtime(
69 error::SandboxRuntimeError::Confinement(
70 error::ConfinementError::Landlock(format!(
71 "prctl(PR_SET_NO_NEW_PRIVS): {}",
72 std::io::Error::last_os_error()
73 ))
74 )
75 ));
76 }
77
78 let mut builder = Sandbox::builder();
79 for path in &confinement.fs_readable {
80 builder = builder.fs_read(path.clone());
81 }
82 for path in &confinement.fs_writable {
83 builder = builder.fs_write(path.clone());
84 }
85 let stripped = builder.build()?;
86
87 landlock::confine_filesystem(&stripped)
89}