Compare commits

..

No commits in common. "7498b283ce2dd9dcc7ae1d404884f49eb09aa91d" and "800a097903d3eeedd1eccba1ae663a419206fbc5" have entirely different histories.

2 changed files with 13 additions and 11 deletions

View File

@ -69,12 +69,14 @@ pub fn pledge(
pub struct UnveilPerms(CString); pub struct UnveilPerms(CString);
impl UnveilPerms { impl UnveilPerms {
pub fn new<T: IntoIterator<Item = char>>(permissions: T) -> Self { pub fn new(permissions: Vec<char>) -> Self {
let perms = CString::new( if permissions.is_empty() {
permissions.into_iter().collect::<String>() return UnveilPerms(CString::new("").unwrap());
).unwrap(); }
UnveilPerms(perms) UnveilPerms(
CString::new(permissions.iter().collect::<String>()).unwrap()
)
} }
} }
@ -85,9 +87,9 @@ pub fn unveil(
let path_c = path.map(CString::new).map(Result::unwrap); let path_c = path.map(CString::new).map(Result::unwrap);
let arg1 = path_c.map(|p| p.into_raw() as *const c_char).unwrap_or(null()); let arg1 = path_c.map(|p| p.into_raw() as *const c_char).unwrap_or(null());
let arg2 = permissions.map(|p| { let arg2 = permissions
p.0.into_raw() as *const c_char .map(|p| p.0.into_raw() as *const c_char)
}).unwrap_or(null()); .unwrap_or(null());
unsafe { unsafe {
match openbsd::unveil(arg1, arg2) { match openbsd::unveil(arg1, arg2) {

View File

@ -115,7 +115,7 @@ fn main() -> ExitCode {
#[cfg(target_os="openbsd")] { #[cfg(target_os="openbsd")] {
for input in &ins { for input in &ins {
let perms = UnveilPerms::new(['r']); let perms = UnveilPerms::new(vec!['r']);
if let Err(e) = unveil(Some(&input), Some(perms)) { if let Err(e) = unveil(Some(&input), Some(perms)) {
return err(&argv[0], e, Some(EX_OSERR)); return err(&argv[0], e, Some(EX_OSERR));
@ -123,7 +123,7 @@ fn main() -> ExitCode {
} }
for output in &outs { for output in &outs {
let perms = UnveilPerms::new(['c', 'w']); let perms = UnveilPerms::new(vec!['c', 'w']);
if let Err(e) = unveil(Some(&output), Some(perms)) { if let Err(e) = unveil(Some(&output), Some(perms)) {
return err(&argv[0], e, Some(EX_OSERR)); return err(&argv[0], e, Some(EX_OSERR));