Compare commits
2 Commits
800a097903
...
7498b283ce
Author | SHA1 | Date | |
---|---|---|---|
7498b283ce | |||
0b3ed37c38 |
@ -69,14 +69,12 @@ pub fn pledge(
|
||||
pub struct UnveilPerms(CString);
|
||||
|
||||
impl UnveilPerms {
|
||||
pub fn new(permissions: Vec<char>) -> Self {
|
||||
if permissions.is_empty() {
|
||||
return UnveilPerms(CString::new("").unwrap());
|
||||
}
|
||||
|
||||
UnveilPerms(
|
||||
CString::new(permissions.iter().collect::<String>()).unwrap()
|
||||
)
|
||||
pub fn new<T: IntoIterator<Item = char>>(permissions: T) -> Self {
|
||||
let perms = CString::new(
|
||||
permissions.into_iter().collect::<String>()
|
||||
).unwrap();
|
||||
|
||||
UnveilPerms(perms)
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,9 +85,9 @@ pub fn unveil(
|
||||
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 arg2 = permissions
|
||||
.map(|p| p.0.into_raw() as *const c_char)
|
||||
.unwrap_or(null());
|
||||
let arg2 = permissions.map(|p| {
|
||||
p.0.into_raw() as *const c_char
|
||||
}).unwrap_or(null());
|
||||
|
||||
unsafe {
|
||||
match openbsd::unveil(arg1, arg2) {
|
||||
|
@ -115,7 +115,7 @@ fn main() -> ExitCode {
|
||||
|
||||
#[cfg(target_os="openbsd")] {
|
||||
for input in &ins {
|
||||
let perms = UnveilPerms::new(vec!['r']);
|
||||
let perms = UnveilPerms::new(['r']);
|
||||
|
||||
if let Err(e) = unveil(Some(&input), Some(perms)) {
|
||||
return err(&argv[0], e, Some(EX_OSERR));
|
||||
@ -123,7 +123,7 @@ fn main() -> ExitCode {
|
||||
}
|
||||
|
||||
for output in &outs {
|
||||
let perms = UnveilPerms::new(vec!['c', 'w']);
|
||||
let perms = UnveilPerms::new(['c', 'w']);
|
||||
|
||||
if let Err(e) = unveil(Some(&output), Some(perms)) {
|
||||
return err(&argv[0], e, Some(EX_OSERR));
|
||||
|
Loading…
Reference in New Issue
Block a user