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>
impl<A: Default> User<A>
sourcepub fn shell_cmd(&self) -> Command
pub fn shell_cmd(&self) -> Command
Get a Command to run the user’s default shell (see User::login_cmd
for more docs).
sourcepub fn login_cmd<T>(&self, cmd: T) -> Command
pub fn login_cmd<T>(&self, cmd: T) -> Command
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’suser
field.UID
set to the user’suid
field.GROUPS
set the user’sgid
field.HOME
set to the user’shome
field.SHELL
set to the user’sshell
field.
source§impl User<Full>
impl User<Full>
sourcepub fn set_passwd(&mut self, password: impl AsRef<str>) -> Result<(), Error>
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).
sourcepub fn unset_passwd(&mut self)
pub fn unset_passwd(&mut self)
Unset the password (User::verify_passwd
always returns false
).
sourcepub fn verify_passwd(&self, password: impl AsRef<str>) -> bool
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).
sourcepub fn is_passwd_blank(&self) -> bool
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).
sourcepub fn is_passwd_unset(&self) -> bool
pub fn is_passwd_unset(&self) -> bool
Determine if the hash for the password is unset
(User::verify_passwd
returns false
regardless of input).