Struct redox_users::User

source ·
pub struct User<A> {
    pub user: String,
    pub uid: usize,
    pub gid: usize,
    pub name: String,
    pub home: String,
    pub shell: String,
    /* private fields */
}
Expand description

A struct representing a Redox user. Currently maps to an entry in the /etc/passwd file.

A should be a type from crate::auth.

§Unset vs. Blank Passwords

A note on unset passwords vs. blank passwords. A blank password is a hash field that is completely blank (aka, ""). According to this crate, successful login is only allowed if the input password is blank as well.

An unset password is one whose hash is not empty (""), but also not a valid serialized argon2rs hashing session. This hash always returns false upon attempted verification. The most commonly used hash for an unset password is "!", but this crate makes no distinction. The most common way to unset the password is to use User::unset_passwd.

Fields§

§user: String

Username (login name)

§uid: usize

User id

§gid: usize

Group id

§name: String

Real name (human readable, can contain spaces)

§home: String

Home directory path

§shell: String

Shell path

Implementations§

source§

impl<A: Default> User<A>

source

pub fn shell_cmd(&self) -> Command

Get a Command to run the user’s default shell (see User::login_cmd for more docs).

source

pub fn login_cmd<T>(&self, cmd: T) -> Command
where T: AsRef<OsStr> + AsRef<str>,

Provide a login command for the user, which is any entry point for starting a user’s session, whether a shell (use User::shell_cmd instead) or a graphical init.

The Command will use the user’s uid and gid, its current_dir will be set to the user’s home directory, and the follwing enviroment variables will be populated:

  • USER set to the user’s user field.
  • UID set to the user’s uid field.
  • GROUPS set the user’s gid field.
  • HOME set to the user’s home field.
  • SHELL set to the user’s shell field.
source§

impl User<Full>

source

pub fn set_passwd(&mut self, password: impl AsRef<str>) -> Result<(), Error>

Set the password for a user. Make sure that password is actually what the user wants as their password (this doesn’t).

To set the password blank, pass "" as password.

Note that password is taken as a reference, so it is up to the caller to properly zero sensitive memory (see zeroize on crates.io).

source

pub fn unset_passwd(&mut self)

Unset the password (User::verify_passwd always returns false).

source

pub fn verify_passwd(&self, password: impl AsRef<str>) -> bool

Verify the password. If the hash is empty, this only returns true if password is also empty.

Note that this is a blocking operation if the password is incorrect. See Config::auth_delay to set the wait time. Default is 3 seconds.

Note that password is taken as a reference, so it is up to the caller to properly zero sensitive memory (see zeroize on crates.io).

source

pub fn is_passwd_blank(&self) -> bool

Determine if the hash for the password is blank (User::verify_passwd returns true only when the password is blank).

source

pub fn is_passwd_unset(&self) -> bool

Determine if the hash for the password is unset (User::verify_passwd returns false regardless of input).

Trait Implementations§

source§

impl<A: Debug> Debug for User<A>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<A> Freeze for User<A>
where A: Freeze,

§

impl<A> RefUnwindSafe for User<A>
where A: RefUnwindSafe,

§

impl<A> Send for User<A>
where A: Send,

§

impl<A> Sync for User<A>
where A: Sync,

§

impl<A> Unpin for User<A>
where A: Unpin,

§

impl<A> UnwindSafe for User<A>
where A: UnwindSafe,

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.