1use alpm_sys::*;
2use std::ffi::CString;
3
4use crate::{Alpm, Result};
5
6impl Alpm {
7 pub fn sandbox_setup_child<S: Into<Vec<u8>>>(
8 &mut self,
9 user: S,
10 path: S,
11 restrict_syscalls: bool,
12 ) -> Result<()> {
13 let user = CString::new(user).unwrap();
14 let path = CString::new(path).unwrap();
15 let ret = unsafe {
16 alpm_sandbox_setup_child(
17 self.as_ptr(),
18 user.as_ptr(),
19 path.as_ptr(),
20 restrict_syscalls,
21 )
22 };
23 self.check_ret(ret)
24 }
25}
26
27#[cfg(test)]
28mod tests {
29 use super::*;
30
31 #[test]
32 fn test_sandbox() {
33 let mut handle = Alpm::new("/", "tests/db/").unwrap();
34 assert_eq!(handle.sandbox_user(), None);
35 if handle.set_sandbox_user(Some("foo")).is_ok() {
36 assert_eq!(handle.sandbox_user(), Some("foo"));
37 handle.set_sandbox_user(Option::<&str>::None).unwrap();
38 assert_eq!(handle.sandbox_user(), None);
39 }
40 }
41}