Skip to main content

MockPwdGrpProvider

Struct MockPwdGrpProvider 

Source
pub struct MockPwdGrpProvider(/* private fields */);
Expand description

Mock provider of passwd/group data

An implementor of PwdGrpProvider which doesn’t look at the real system databases.

The Default contains just dummy entries for root.

You can pre-program it with passwd and group data.

The mock provider has interior mutability, so the trait can take non-mut references.

Note: this affects only the methods on PwdGrpProvider, not the plain functions in the pwd-grp crate toplevel.

§Example

use pwd_grp::Group;
use pwd_grp::mock::MockPwdGrpProvider;
use pwd_grp::PwdGrpProvider as _;

let mock = MockPwdGrpProvider::new();
assert_eq!(mock.getgrnam::<String>("root").unwrap().unwrap().gid, 0);

mock.add_to_groups([Group {
    name: "wombats".to_string(),
    passwd: "*".to_string(),
    gid: 42,
    mem: vec!["alice".to_string()].into(),
    ..Group::blank()
}]);
let grent: Group = mock.getgrgid(42).unwrap().unwrap();
assert_eq!(grent.passwd, "*");

Implementations§

Source§

impl MockPwdGrpProvider

Source

pub fn new() -> Self

Create a new MockPwdGrpProvider containing dummy entries for root

Source§

impl MockPwdGrpProvider

Source

pub fn new_empty() -> Self

Create a new empty MockPwdGrpProvider

All lookups will return None

Source

pub fn add_to_passwds<I>(&self, data: impl IntoIterator<Item = I>)
where I: Into<Passwd<Box<[u8]>>>,

Append entries to the mock passwd database

Source

pub fn add_to_groups<I>(&self, data: impl IntoIterator<Item = I>)
where I: Into<Group<Box<[u8]>>>,

Append entries to the mock group database

Source

pub fn set_uids(&self, uids: RealEffectiveSavedIds)

Set the mock uids

Source

pub fn set_gids(&self, gids: RealEffectiveSavedIds)

Set the mock gids

Source

pub fn set_supplementary_groups(&self, supplementary_groups: Vec<uid_t>)

Set the mock supplementary_groups

Trait Implementations§

Source§

impl Clone for MockPwdGrpProvider

Source§

fn clone(&self) -> MockPwdGrpProvider

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MockPwdGrpProvider

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MockPwdGrpProvider

Source§

fn default() -> MockPwdGrpProvider

Returns the “default value” for a type. Read more
Source§

impl PwdGrpProvider for MockPwdGrpProvider

Source§

fn getpwnam<S: PwdGrpString>( &self, name: impl AsRef<<S as Deref>::Target>, ) -> Result<Option<Passwd<S>>>

Look up a passwd entry by name, returning strings as S
Source§

fn getpwuid<S: PwdGrpString>(&self, uid: uid_t) -> Result<Option<Passwd<S>>>

Look up a passwd entry by uid, returning strings as S
Source§

fn getgrnam<S: PwdGrpString>( &self, name: impl AsRef<<S as Deref>::Target>, ) -> Result<Option<Group<S>>>

Look up a group entry by name, returning strings as S
Source§

fn getgrgid<S: PwdGrpString>(&self, gid: uid_t) -> Result<Option<Group<S>>>

Look up a group entry by gid, returning strings as S
Source§

fn getuid(&self) -> uid_t

Get the current process’s (real) uid Read more
Source§

fn geteuid(&self) -> uid_t

Get the current process’s effective uid Read more
Source§

fn getresuid(&self) -> (uid_t, uid_t, uid_t)

Get the current process’s real, effective and saved set-uid Read more
Source§

fn getgid(&self) -> uid_t

Get the current process’s (real) gid Read more
Source§

fn getegid(&self) -> uid_t

Get the current process’s effective gid Read more
Source§

fn getresgid(&self) -> (uid_t, uid_t, uid_t)

Get the current process’s real, effective and saved set-gid Read more
Source§

fn getgroups(&self) -> Result<Vec<uid_t>>

Get the current process’s supplementary group list

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.