priv_sep

Privilege separation library.
git clone https://git.philomathiclife.com/repos/priv_sep
Log | Files | Refs | README

commit 117806ecce6ae432f64d2a6ea4b18a2940ae2248
parent 7d4e2592af3a990ccb167b24df0cf92b820891a0
Author: Zack Newman <zack@philomathiclife.com>
Date:   Sun, 17 Sep 2023 10:04:52 -0600

change pledge to take slice.

Diffstat:
MCargo.toml | 2+-
MREADME.md | 4++--
Msrc/lib.rs | 9+++++----
3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0" name = "priv_sep" readme = "README.md" repository = "https://git.philomathiclife.com/repos/priv_sep/" -version = "0.5.1" +version = "0.6.0" [lib] name = "priv_sep" diff --git a/README.md b/README.md @@ -42,13 +42,13 @@ laptop$ cargo build --release Compiling semver v1.0.18 Compiling libc v0.2.148 Compiling rustc_version v0.4.0 - Compiling priv_sep v0.5.0 (/home/zack/priv_sep) + Compiling priv_sep v0.6.0 (/home/zack/priv_sep) Finished release [optimized] target(s) in 1.90s laptop$ touch /home/zack/foo.txt && cargo t && rm /home/zack/foo.txt Compiling semver v1.0.18 Compiling libc v0.2.148 Compiling rustc_version v0.4.0 - Compiling priv_sep v0.5.0 (/home/zack/priv_sep) + Compiling priv_sep v0.6.0 (/home/zack/priv_sep) Finished test [unoptimized + debuginfo] target(s) in 1.43s Running unittests src/lib.rs (target/debug/deps/priv_sep-dcb151b099a76f20) diff --git a/src/lib.rs b/src/lib.rs @@ -41,6 +41,7 @@ clippy::arithmetic_side_effects, clippy::blanket_clippy_restriction_lints, clippy::implicit_return, + clippy::into_iter_on_ref, clippy::min_ident_chars, clippy::missing_trait_methods, clippy::unseparated_literal_suffix @@ -140,7 +141,7 @@ pub enum Promise { impl Display for Promise { #[inline] fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - match self { + match *self { Audio => f.write_str("pledge(2) 'audio' promise"), Bpf => f.write_str("pledge(2) 'bpf' promise"), Chown => f.write_str("pledge(2) 'chown' promise"), @@ -189,7 +190,7 @@ impl Display for Promise { /// Returns [`io::Error`] iff `pledge(2)` errors. #[inline] #[allow(unsafe_code, clippy::indexing_slicing, clippy::option_if_let_else)] -pub fn pledge<const N: usize>(promises: Option<[Promise; N]>) -> Result<(), io::Error> { +pub fn pledge(promises: Option<&[Promise]>) -> Result<(), io::Error> { extern "C" { fn pledge(promises: *const c_char, execpromises: *const c_char) -> c_int; } @@ -197,7 +198,7 @@ pub fn pledge<const N: usize>(promises: Option<[Promise; N]>) -> Result<(), io:: let ptr = if let Some(prom) = promises { let mut p = Vec::new(); prom.into_iter().fold((), |(), promise| { - p.extend_from_slice(match promise { + p.extend_from_slice(match *promise { Audio => b"audio ", Bpf => b"bpf ", Chown => b"chown ", @@ -278,7 +279,7 @@ pub enum Permission { impl Display for Permission { #[inline] fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - match self { + match *self { Self::Create => f.write_str("unveil(2) 'c' permission"), Self::Execute => f.write_str("unveil(2) 'x' permission"), Self::Read => f.write_str("unveil(2) 'r' permission"),