pub mod error;
pub mod http;
pub mod sandbox; pub mod profile;
pub mod result;
pub(crate) mod arch;
pub(crate) mod sys;
pub mod landlock;
pub mod seccomp;
pub(crate) mod resource;
pub(crate) mod network;
pub mod context;
pub(crate) mod vdso;
pub(crate) mod random;
pub(crate) mod time;
pub(crate) mod cow;
pub(crate) mod checkpoint;
pub(crate) mod freeze;
pub mod netlink;
pub(crate) mod procfs;
pub(crate) mod port_remap;
pub mod pipeline;
pub mod policy_fn;
pub mod image;
pub mod fork;
pub(crate) mod chroot;
pub mod dry_run;
pub(crate) mod http_acl;
pub use error::SandlockError;
pub use sys::structs::{SeccompData, SeccompNotif};
pub use checkpoint::Checkpoint;
pub use sandbox::{Confinement, ConfinementBuilder, Sandbox, SandboxBuilder};
pub use result::{RunResult, ExitStatus};
pub use pipeline::{Stage, Pipeline, Gather};
pub use dry_run::{Change, ChangeKind, DryRunResult};
pub use crate::profile::{ProfileInput, ProgramSpec};
pub use seccomp::dispatch::{Handler, HandlerCtx, HandlerError};
pub use seccomp::syscall::{Syscall, SyscallError};
pub fn landlock_abi_version() -> Result<u32, error::ConfinementError> {
landlock::abi_version()
}
pub const MIN_LANDLOCK_ABI: u32 = landlock::MIN_ABI;
pub fn confine(confinement: &Confinement) -> Result<(), SandlockError> {
if unsafe { libc::prctl(libc::PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) } != 0 {
return Err(SandlockError::Runtime(
error::SandboxRuntimeError::Confinement(
error::ConfinementError::Landlock(format!(
"prctl(PR_SET_NO_NEW_PRIVS): {}",
std::io::Error::last_os_error()
))
)
));
}
let mut builder = Sandbox::builder();
for path in &confinement.fs_readable {
builder = builder.fs_read(path.clone());
}
for path in &confinement.fs_writable {
builder = builder.fs_write(path.clone());
}
let stripped = builder.build()?;
landlock::confine_filesystem(&stripped)
}