From 1c7cdad0fffad976a3236136888117ed848076e5 Mon Sep 17 00:00:00 2001 From: Ben S Date: Tue, 5 May 2015 20:06:55 +0100 Subject: [PATCH] Have different c_passwd structs for different OSes --- Cargo.toml | 2 +- src/lib.rs | 26 ++++++++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 629fd6a..ca86e36 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ documentation = "http://bsago.me/doc/users/" homepage = "https://github.com/ogham/rust-users" license = "MIT" readme = "README.md" -version = "0.4.0" +version = "0.4.1" [dependencies] libc = "0.1.1" diff --git a/src/lib.rs b/src/lib.rs index 6374042..ce2ae27 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -127,6 +127,7 @@ use std::collections::hash_map::Entry::{Occupied, Vacant}; pub mod mock; + /// The trait for the `OSUsers` object. pub trait Users { @@ -149,20 +150,33 @@ pub trait Users { fn get_current_username(&mut self) -> Option; } +#[cfg(any(target_os = "macos", target_os = "freebsd"))] #[repr(C)] struct c_passwd { - pub pw_name: *const c_char, // login name - pub pw_passwd: *const c_char, + pub pw_name: *const c_char, // user name + pub pw_passwd: *const c_char, // password field pub pw_uid: uid_t, // user ID pub pw_gid: gid_t, // group ID - pub pw_gecos: *const c_char, // full name - pub pw_dir: *const c_char, // login dir - pub pw_shell: *const c_char, // login shell - pub pw_change: time_t, + pub pw_change: time_t, // password change time pub pw_class: *const c_char, + pub pw_gecos: *const c_char, + pub pw_dir: *const c_char, // user's home directory + pub pw_shell: *const c_char, // user's shell pub pw_expire: time_t, // password expiry time } +#[cfg(target_os = "linux")] +#[repr(C)] +struct c_passwd { + pub pw_name: *const c_char, // user name + pub pw_passwd: *const c_char, // password field + pub pw_uid: uid_t, // user ID + pub pw_gid: gid_t, // group ID + pub pw_gecos: *const c_char, + pub pw_dir: *const c_char, // user's home directory + pub pw_shell: *const c_char, // user's shell +} + #[repr(C)] struct c_group { pub gr_name: *const c_char, // group name