use crate::bubblewrap::{launch, HasNeither};
use crate::global::ChrootVerified;
use crate::GlobalsFinal;
use anyhow::Result as AResult;
use std::path::PathBuf;
pub(super) struct BWParams {
pub(super) chroot: ChrootVerified,
pub(super) tmpfs_size: usize,
pub(super) command: String,
pub(super) mounts: Vec<(PathBuf, PathBuf)>,
}
impl BWParams {
pub(super) fn dispatch(self, globals: &GlobalsFinal) -> AResult<()> {
let tag = format!("{}", self.chroot);
let mut args = HasNeither::new()
.namespace(&NSCONF)
.capabilities(&CAPABS)
.usercfg(&USRCONF)
.sysmounts(&SYSMOUNTS)
.add_var("GENPAC", &tag)
.tmpfs(self.tmpfs_size)
.resolve()
.chroot(&self.chroot)
.command(&self.command);
for (src, dest) in &self.mounts {
args = args.add_mount(src, dest);
}
let args = args.build();
launch(args, globals)?;
Ok(())
}
}
const NSCONF: [&str; 3] = ["--unshare-all", "--unshare-user", "--share-net"];
const USRCONF: [&str; 4] = ["--uid", "0", "--gid", "0"];
const SYSMOUNTS: [&str; 8] = [
"--dev", "/dev", "--proc", "/proc", "--perms", "1777", "--tmpfs", "/dev/shm",
];
const CAPABS: [&str; 8] = [
"CAP_SYS_ADMIN",
"CAP_NET_ADMIN",
"CAP_CHOWN",
"CAP_FOWNER",
"CAP_DAC_OVERRIDE",
"CAP_SETUID",
"CAP_SETGID",
"CAP_SETFCAP",
];