Add change and expire accessors

This commit is contained in:
Ben S
2016-01-28 16:06:54 +00:00
parent d602c1a6d5
commit d65d2180d9
2 changed files with 26 additions and 0 deletions
+6
View File
@@ -1,6 +1,7 @@
extern crate users;
use users::{Users, Groups, UsersCache};
use users::os::unix::{UserExt, GroupExt};
//use users::os::bsd::UserExt as BSDUserExt;
fn main() {
let cache = UsersCache::new();
@@ -13,6 +14,11 @@ fn main() {
println!("Your shell is {}", you.shell().display());
println!("Your home directory is {}", you.home_dir().display());
// The two fields below are only available on BSD systems.
// Linux systems dont have the fields in their `passwd` structs!
//println!("Your password change timestamp is {}", you.password_change_time());
//println!("Your password expiry timestamp is {}", you.password_expire_time());
let primary_group = cache.get_group_by_gid(you.primary_group_id()).expect("No entry for your primary group!");
println!("Your primary group has ID {} and name {}", primary_group.gid(), primary_group.name());
+20
View File
@@ -555,6 +555,26 @@ pub mod os {
}
}
/// BSD-specific accessors for `User`s.
pub trait UserExt {
/// Returns this user's password change timestamp.
fn password_change_time(&self) -> time_t;
/// Returns this user's password expiry timestamp.
fn password_expire_time(&self) -> time_t;
}
impl UserExt for User {
fn password_change_time(&self) -> time_t {
self.extras.change.clone()
}
fn password_expire_time(&self) -> time_t {
self.extras.expire.clone()
}
}
impl Default for UserExtras {
fn default() -> UserExtras {
UserExtras {