You've already forked rust-users
mirror of
https://github.com/uutils/rust-users.git
synced 2026-06-10 15:48:37 -07:00
Add change and expire accessors
This commit is contained in:
@@ -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 don’t 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
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user