1 use std::ffi::OsStr;
2 use std::sync::Arc;
3 
4 use libc::{uid_t, gid_t};
5 
6 use base::{User, Group};
7 
8 
9 /// Trait for producers of users.
10 pub trait Users {
11 
12     /// Returns a `User` if one exists for the given user ID; otherwise, returns `None`.
get_user_by_uid(&self, uid: uid_t) -> Option<Arc<User>>13     fn get_user_by_uid(&self, uid: uid_t) -> Option<Arc<User>>;
14 
15     /// Returns a `User` if one exists for the given username; otherwise, returns `None`.
get_user_by_name<S: AsRef<OsStr> + ?Sized>(&self, username: &S) -> Option<Arc<User>>16     fn get_user_by_name<S: AsRef<OsStr> + ?Sized>(&self, username: &S) -> Option<Arc<User>>;
17 
18     /// Returns the user ID for the user running the process.
get_current_uid(&self) -> uid_t19     fn get_current_uid(&self) -> uid_t;
20 
21     /// Returns the username of the user running the process.
get_current_username(&self) -> Option<Arc<OsStr>>22     fn get_current_username(&self) -> Option<Arc<OsStr>>;
23 
24     /// Returns the effective user id.
get_effective_uid(&self) -> uid_t25     fn get_effective_uid(&self) -> uid_t;
26 
27     /// Returns the effective username.
get_effective_username(&self) -> Option<Arc<OsStr>>28     fn get_effective_username(&self) -> Option<Arc<OsStr>>;
29 }
30 
31 /// Trait for producers of groups.
32 pub trait Groups {
33 
34     /// Returns a `Group` if one exists for the given group ID; otherwise, returns `None`.
get_group_by_gid(&self, gid: gid_t) -> Option<Arc<Group>>35     fn get_group_by_gid(&self, gid: gid_t) -> Option<Arc<Group>>;
36 
37     /// Returns a `Group` if one exists for the given groupname; otherwise, returns `None`.
get_group_by_name<S: AsRef<OsStr> + ?Sized>(&self, group_name: &S) -> Option<Arc<Group>>38     fn get_group_by_name<S: AsRef<OsStr> + ?Sized>(&self, group_name: &S) -> Option<Arc<Group>>;
39 
40     /// Returns the group ID for the user running the process.
get_current_gid(&self) -> gid_t41     fn get_current_gid(&self) -> gid_t;
42 
43     /// Returns the group name of the user running the process.
get_current_groupname(&self) -> Option<Arc<OsStr>>44     fn get_current_groupname(&self) -> Option<Arc<OsStr>>;
45 
46     /// Returns the effective group id.
get_effective_gid(&self) -> gid_t47     fn get_effective_gid(&self) -> gid_t;
48 
49     /// Returns the effective group name.
get_effective_groupname(&self) -> Option<Arc<OsStr>>50     fn get_effective_groupname(&self) -> Option<Arc<OsStr>>;
51 }
52