1use alpm_sys::*;
2use std::ffi::CString;
3
4use crate::{Alpm, Result};
5
6impl Alpm {
7 #[cfg(not(feature = "git"))]
8 pub fn sandbox_setup_child<S: Into<Vec<u8>>>(&mut self, user: S, path: S) -> Result<()> {
9 let user = CString::new(user).unwrap();
10 let path = CString::new(path).unwrap();
11 let ret = unsafe { alpm_sandbox_setup_child(self.as_ptr(), user.as_ptr(), path.as_ptr()) };
12 self.check_ret(ret)
13 }
14
15 #[cfg(feature = "git")]
16 pub fn sandbox_setup_child<S: Into<Vec<u8>>>(
17 &mut self,
18 user: S,
19 path: S,
20 restrict_syscalls: bool,
21 ) -> Result<()> {
22 let user = CString::new(user).unwrap();
23 let path = CString::new(path).unwrap();
24 let ret = unsafe {
25 alpm_sandbox_setup_child(
26 self.as_ptr(),
27 user.as_ptr(),
28 path.as_ptr(),
29 restrict_syscalls,
30 )
31 };
32 self.check_ret(ret)
33 }
34
35 #[cfg(feature = "git")]
36 #[doc(alias = "disable_sandbox")]
37 pub fn sandbox_disabled(&self) -> bool {
38 unsafe { alpm_option_get_disable_sandbox(self.as_ptr()) != 0 }
39 }
40}
41
42#[cfg(test)]
43mod tests {
44 use super::*;
45
46 #[test]
47 fn test_sandbox() {
48 let mut handle = Alpm::new("/", "tests/db/").unwrap();
49 if cfg!(feature = "git") {
50 assert_eq!(handle.sandbox_user(), Some("root"));
51 } else {
52 assert_eq!(handle.sandbox_user(), None);
53 }
54 handle.set_sandbox_user(Some("foo")).unwrap();
55 assert_eq!(handle.sandbox_user(), Some("foo"));
56 handle.set_sandbox_user(Option::<&str>::None).unwrap();
57 assert_eq!(handle.sandbox_user(), None);
58 }
59}