Struct redox_users::AllUsers [−][src]
pub struct AllUsers { /* fields omitted */ }
Struct encapsulating all users on the system
AllUsers
is a struct providing
(borrowed) access to all the users and groups on the system.
Notes
Note that everything in this section also applies to
AllGroups
- If you mutate anything owned by an AllUsers,
you must call the
save
method in order for those changes to be applied to the system. - The API here is kept small on purpose in order to reduce the
surface area for security exploitation. Most mutating actions
can be accomplished via the
get_mut_by_id
andget_mut_by_name
functions.
Shadowfile handling
This implementation of redox-users uses a shadowfile implemented primarily
by this struct. The constructor provided takes a boolean which indicates
to AllUsers
that the shadowfile is nessasary. AllUsers
populates the
hash fields of each user struct that it parses from /etc/passwd
with
info from /et/shadow
. If a user attempts to perform an action that
requires this info while passing false
to AllUsers
, the User
handling
the action will panic.
Methods
impl AllUsers
[src]
impl AllUsers
pub fn new(is_auth_required: bool) -> Result<AllUsers>
[src]
pub fn new(is_auth_required: bool) -> Result<AllUsers>
Create a new AllUsers
Pass true
if you need to authenticate a password, else, false
(see Shadowfile Handling)
pub fn iter(&self) -> Iter<User>
[src]
pub fn iter(&self) -> Iter<User>
Get an iterator over all system users
pub fn iter_mut(&mut self) -> IterMut<User>
[src]
pub fn iter_mut(&mut self) -> IterMut<User>
Mutable version of iter
pub fn get_by_name<T>(&self, username: T) -> Option<&User> where
T: AsRef<str>,
[src]
pub fn get_by_name<T>(&self, username: T) -> Option<&User> where
T: AsRef<str>,
Borrow the User
representing a user for a given username.
Examples
Basic usage:
let users = AllUsers::new(false).unwrap(); let user = users.get_by_id(0).unwrap();
pub fn get_mut_by_name<T>(&mut self, username: T) -> Option<&mut User> where
T: AsRef<str>,
[src]
pub fn get_mut_by_name<T>(&mut self, username: T) -> Option<&mut User> where
T: AsRef<str>,
Mutable version of 'get_by_name'
pub fn get_by_id(&self, uid: usize) -> Option<&User>
[src]
pub fn get_by_id(&self, uid: usize) -> Option<&User>
Borrow the User
representing given user ID.
Examples
Basic usage:
let users = AllUsers::new(false).unwrap(); let user = users.get_by_id(0).unwrap();
pub fn get_mut_by_id(&mut self, uid: usize) -> Option<&mut User>
[src]
pub fn get_mut_by_id(&mut self, uid: usize) -> Option<&mut User>
Mutable version of get_by_id
pub fn get_unique_id(&self) -> Option<usize>
[src]
pub fn get_unique_id(&self) -> Option<usize>
Provides an unused user id, defined as "unused" by the system defaults, between 1000 and 6000
Examples
let users = AllUsers::new(false).unwrap(); let uid = users.get_unique_id().expect("no available uid");
pub fn add_user(
&mut self,
login: &str,
uid: usize,
gid: usize,
name: &str,
home: &str,
shell: &str
) -> Result<()>
[src]
pub fn add_user(
&mut self,
login: &str,
uid: usize,
gid: usize,
name: &str,
home: &str,
shell: &str
) -> Result<()>
Adds a user with the specified attributes to the AllUsers instance. Note that the user's password is set unset (see Unset vs Blank Passwords) during this call.
This function is classified as a mutating operation,
and users must therefore call save
in order for the new user to be applied to the system.
Panics
This function will panic if true
was not passed to
AllUsers::new
(see
Shadowfile handling
)
pub fn remove_by_name<T>(&mut self, name: T) -> Result<()> where
T: AsRef<str>,
[src]
pub fn remove_by_name<T>(&mut self, name: T) -> Result<()> where
T: AsRef<str>,
Remove a user from the system. This is a mutating operation,
and users of the crate must therefore call save
in order for changes to be applied to the system.
pub fn remove_by_id(&mut self, id: usize) -> Result<()>
[src]
pub fn remove_by_id(&mut self, id: usize) -> Result<()>
User-id version of remove_by_name
pub fn save(&self) -> Result<()>
[src]
pub fn save(&self) -> Result<()>
Syncs the data stored in the AllUsers instance to the filesystem. To apply changes to the system from an AllUsers, you MUST call this function! This function currently does a bunch of fs I/O so it is error-prone.