priv_sep

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

commit 9956396dae9015510928da52617cda3483dd7a5c
parent 74e12a42869dc02ac50828a7064725137c0deca6
Author: Zack Newman <zack@philomathiclife.com>
Date:   Fri, 10 Oct 2025 23:59:24 -0600

better docs. make promise exhaustive

Diffstat:
Msrc/err.rs | 7+++++++
Msrc/lib.rs | 14+++++++++++---
Msrc/openbsd.rs | 1-
3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/err.rs b/src/err.rs @@ -15,6 +15,13 @@ use std::io::Error as StdErr; pub struct OtherErrno(c_int); impl OtherErrno { /// Returns the contained error number. + /// + /// # Examples + /// + /// ``` + /// # use priv_sep::{Errno, OtherErrno}; + /// assert!(matches!(Errno::from_raw(0), Errno::Other(err) if err.into_raw() == 0)); + /// ``` #[inline] #[must_use] pub const fn into_raw(self) -> c_int { diff --git a/src/lib.rs b/src/lib.rs @@ -692,7 +692,7 @@ impl UserInfo { clippy::unnecessary_wraps, reason = "unify with platforms that support `setgroups`" )] - const fn drop_sup_groups() -> Result<(), Errno> { + const fn drop_sup_groups<Never>() -> Result<(), Never> { Ok(()) } /// Helper to unify targets that don't support `setgroups(2)`. @@ -907,6 +907,13 @@ impl PartialEq<UserInfo> for &UserInfo { /// # Errors /// /// Errors iff `setgroups` does. +/// +/// # Examples +/// +/// ```no_run +/// # #[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "linux", target_os = "netbsd", target_os = "openbsd"))] +/// assert!(priv_sep::setgroups(&[]).is_ok()); +/// ``` #[cfg_attr( docsrs, doc(cfg(any( @@ -922,7 +929,8 @@ impl PartialEq<UserInfo> for &UserInfo { target_os = "freebsd", target_os = "linux", target_os = "netbsd", - target_os = "openbsd" + target_os = "openbsd", + all(doc, target_os = "macos") ))] #[expect(unsafe_code, reason = "setgroups(2) takes a pointer")] #[inline] @@ -960,7 +968,7 @@ pub fn setgroups(groups: &[Gid]) -> Result<(), Errno> { /// # Examples /// /// ```no_run -/// # #[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "linux", target_os = "netbsd", target_os = "openbsd"))] +/// # #[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "linux", target_os = "netbsd", target_os = "openbsd"))] /// assert!(priv_sep::drop_supplementary_groups().is_ok()); /// ``` #[cfg_attr( diff --git a/src/openbsd.rs b/src/openbsd.rs @@ -17,7 +17,6 @@ unsafe extern "C" { } /// A `promise` to [`pledge(2)`](https://man.openbsd.org/pledge.2). #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] -#[non_exhaustive] pub enum Promise { /// [`audio`](https://man.openbsd.org/pledge.2#audio). Audio,