diff --git a/.travis.yml b/.travis.yml index aa57513..2169da6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,7 @@ language: rust -rust: nightly - +matrix: + include: + - rust: nightly + os: linux + - rust: nightly + os: osx diff --git a/examples/example.rs b/examples/example.rs index 2df0cf5..89890a2 100644 --- a/examples/example.rs +++ b/examples/example.rs @@ -1,5 +1,5 @@ -extern crate users; -use users::{Users, Groups, UsersCache}; +extern crate rust_users; +use rust_users::{Users, Groups, UsersCache}; fn main() { let cache = UsersCache::new(); diff --git a/examples/list.rs b/examples/list.rs index 03ff11e..df39826 100644 --- a/examples/list.rs +++ b/examples/list.rs @@ -1,5 +1,5 @@ -extern crate users; -use users::{User, AllUsers}; +extern crate rust_users; +use rust_users::{User, AllUsers}; fn main() { let mut users: Vec = unsafe { AllUsers::new() }.collect(); diff --git a/examples/os.rs b/examples/os.rs index 5829625..0a1dd25 100644 --- a/examples/os.rs +++ b/examples/os.rs @@ -1,6 +1,6 @@ -extern crate users; -use users::{Users, Groups, UsersCache}; -use users::os::unix::{UserExt, GroupExt}; +extern crate rust_users; +use rust_users::{Users, Groups, UsersCache}; +use rust_users::os::unix::{UserExt, GroupExt}; //use users::os::bsd::UserExt as BSDUserExt; fn main() { diff --git a/examples/threading.rs b/examples/threading.rs index a518f4e..1e5f4ba 100644 --- a/examples/threading.rs +++ b/examples/threading.rs @@ -15,8 +15,8 @@ // the code try to access the users cache *without* a Mutex, and see it // spew compile errors at you. -extern crate users; -use users::{Users, UsersCache, uid_t}; +extern crate rust_users; +use rust_users::{Users, UsersCache, uid_t}; use std::sync::{Arc, Mutex}; use std::time::Duration; diff --git a/src/base.rs b/src/base.rs index 4190fed..b2be1a1 100644 --- a/src/base.rs +++ b/src/base.rs @@ -38,6 +38,8 @@ use std::ptr::read; use std::sync::Arc; use libc::{uid_t, gid_t}; +use libc::passwd as c_passwd; +use libc::group as c_group; #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd"))] use libc::{c_char, time_t}; @@ -46,41 +48,6 @@ use libc::{c_char, time_t}; use libc::c_char; -#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd"))] -#[repr(C)] -pub struct c_passwd { - pw_name: *const c_char, // user name - pw_passwd: *const c_char, // password field - pw_uid: uid_t, // user ID - pw_gid: gid_t, // group ID - pw_change: time_t, // password change time - pw_class: *const c_char, - pw_gecos: *const c_char, - pw_dir: *const c_char, // user's home directory - pw_shell: *const c_char, // user's shell - pw_expire: time_t, // password expiry time -} - -#[cfg(target_os = "linux")] -#[repr(C)] -pub struct c_passwd { - pw_name: *const c_char, // user name - pw_passwd: *const c_char, // password field - pw_uid: uid_t, // user ID - pw_gid: gid_t, // group ID - pw_gecos: *const c_char, - pw_dir: *const c_char, // user's home directory - pw_shell: *const c_char, // user's shell -} - -#[repr(C)] -pub struct c_group { - gr_name: *const c_char, // group name - gr_passwd: *const c_char, // password - gr_gid: gid_t, // group id - gr_mem: *const *const c_char, // names of users in the group -} - extern { fn getpwuid(uid: uid_t) -> *const c_passwd; fn getpwnam(user_name: *const c_char) -> *const c_passwd; @@ -277,7 +244,7 @@ unsafe fn struct_to_group(pointer: *const c_group) -> Option { /// `members[1]`, and so on, until that null pointer is reached. It doesn't /// specify whether we should expect a null pointer or a pointer to a null /// pointer, so we check for both here! -unsafe fn members(groups: *const *const c_char) -> Vec { +unsafe fn members(groups: *mut *mut c_char) -> Vec { let mut members = Vec::new(); for i in 0.. { diff --git a/src/cache.rs b/src/cache.rs index ad35449..201b3c9 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -24,7 +24,7 @@ //! value. In this case, switching to `&mut self` would only allow for one user //! to be read at a time! //! -//! ``norun +//! ```norun //! let mut cache = UsersCache::empty_cache(); //! let uid = cache.get_current_uid(); // OK... //! let user = cache.get_user_by_uid(uid).unwrap() // OK... @@ -43,7 +43,7 @@ //! we’re just trying the same trick as earlier. A simplified implementation of //! a user cache lookup would look something like this: //! -//! ``norun +//! ```norun //! fn get_user_by_uid(&self, uid: uid_t) -> Option<&User> { //! let users = self.users.borrow_mut(); //! users.get(uid) diff --git a/src/lib.rs b/src/lib.rs index 7e55ea4..47c1c47 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,7 +32,7 @@ //! Here is a complete example that prints out the current user’s name: //! //! ```rust -//! use users::{get_user_by_uid, get_current_uid}; +//! use rust_users::{get_user_by_uid, get_current_uid}; //! let user = get_user_by_uid(get_current_uid()).unwrap(); //! println!("Hello, {}!", user.name()); //! ``` @@ -63,7 +63,7 @@ //! methods on it. For example: //! //! ```rust -//! use users::{Users, Groups, UsersCache}; +//! use rust_users::{Users, Groups, UsersCache}; //! let mut cache = UsersCache::new(); //! let uid = cache.get_current_uid(); //! let user = cache.get_user_by_uid(uid).unwrap(); @@ -87,7 +87,7 @@ //! And again, a complete example: //! //! ```no_run -//! use users::{Users, Groups, UsersCache}; +//! use rust_users::{Users, Groups, UsersCache}; //! let mut cache = UsersCache::new(); //! let group = cache.get_group_by_name("admin").expect("No such group 'admin'!"); //! println!("The '{}' group has the ID {}", group.name(), group.gid()); diff --git a/src/mock.rs b/src/mock.rs index 3712861..5f85717 100644 --- a/src/mock.rs +++ b/src/mock.rs @@ -17,8 +17,8 @@ //! `add_user` and `add_group` to the object: //! //! ```rust -//! use users::mock::{MockUsers, User, Group}; -//! use users::os::unix::{UserExt, GroupExt}; +//! use rust_users::mock::{MockUsers, User, Group}; +//! use rust_users::os::unix::{UserExt, GroupExt}; //! use std::sync::Arc; //! //! let mut users = MockUsers::with_current_uid(1000); @@ -39,9 +39,9 @@ //! Here's a complete example: //! //! ```rust -//! use users::{Users, UsersCache, User}; -//! use users::os::unix::UserExt; -//! use users::mock::MockUsers; +//! use rust_users::{Users, UsersCache, User}; +//! use rust_users::os::unix::UserExt; +//! use rust_users::mock::MockUsers; //! use std::sync::Arc; //! //! fn print_current_username(users: &mut U) { diff --git a/src/switch.rs b/src/switch.rs index 518af08..68f11b4 100644 --- a/src/switch.rs +++ b/src/switch.rs @@ -125,7 +125,7 @@ impl Drop for SwitchUserGuard { /// ### Examples /// /// ```no_run -/// use users::switch::switch_user_group; +/// use rust_users::switch::switch_user_group; /// /// { /// let _guard = switch_user_group(1001, 1001);