Commit Graph

48 Commits

Author SHA1 Message Date
Ben S 9dadca8993 Move user-switching functions to their own module
Remove `c_int` from the libc public exports list while I'm at it. This might break someone's code, but it shouldn't have been used from this library anyway (only for user switching functions!)
2016-01-26 19:10:48 +00:00
Ben S 80e0c7d6f2 Move large parts of lib into base 2016-01-26 19:05:10 +00:00
Ben S 5e4967a377 Move the traits into their own module 2016-01-26 18:57:39 +00:00
Ben S 543925889c Stop using 'object' terminology! 2016-01-26 18:55:21 +00:00
Benjamin Sago 28d4d68daf Add Default impl for OSUsers 2016-01-16 12:13:17 -10:00
Benjamin Sago 052cf245f4 Split Users trait into Users and Groups traits
It was getting crowded in there! Not only are two groups of six easier to manage than one group of twelve, but the groups functions didn't actually have anything to do with users...
2016-01-14 23:15:53 -10:00
Benjamin Sago aa94ee89db Return Arcs instead of clones, and take &self
The primary goal of this commit was to avoid having to clone the users and groups it produces. The old implementation was written by me when I hadn't *fully* internalised how lifetimes worked, and just used `clone` to get around the error messages. It was only later that I realised how inefficient this actually is -- the values stored in the cache are never used, only their clones are!

Several attempt at this later, I settled on using `Arc` for everything and cloning *those* values instead.

All the gory details of what happened are written in a comment in the OS module. The short version is that it's now possible to change the `Users` trait's methods from taking `&mut self` to just taking `&self`. This is within the allowed uses of `Cell`: implementation details of a method that does actually return the same thing each time, which this is.

The main casualty is that the user now has to know about `Arc` and initialise a user with a username in such a container, which I hope to solve in a later commit.
2016-01-14 23:15:02 -10:00
Benjamin Sago 6a829c7b7d Extract bi-map groups into BiMap struct
The pairing of forward and backward maps was repeated twice: once for users, and once for groups. This commit refactors them into a BiMap struct that contains HashMaps of the relevant types.

Note that these new structs are just dumb structs: they don't implement any BiMap functionality, and all the other pieces of code don't do anything different with the maps -- they just refer to the struct's fields, making this a smaller change than it could be.
2016-01-13 18:01:08 +13:00
Benjamin Sago 04f52c4de9 Remove unnecessary 'pub's in C structs
These structures are all private to the current module anyway, so these `pub`s do nothing.
2016-01-10 21:15:50 +13:00
Benjamin Sago bb1299a288 Extract OS functions to os module
This commit does two things:

Firstly, it swaps the locations in the code where the actual, unsafe C library operations are done from being done in the OSUsers struct to in the stand-alone functions. This makes more sense, as previously, the stand-alone functions would instantiate a new cache, run a method on it, and then immediately discard the cache. Now the cache uses the methods, not the other way round.

Secondly, it extracts all of the caching methods to its own module, leaving `lib` with a bare-bones users implementation.
2016-01-10 21:14:05 +13:00
Benjamin Sago 83ddcc886c io::Error -> IOError, io::Result -> IOResult 2015-12-22 20:07:05 +11:00
Ben S 0e76551aa3 README improvements
- Stylistic changes
- Fix installation instructions
- Add mock docs
- Upgrade required version of libc
2015-11-27 01:54:53 +00:00
Ben S 4c966938db Achieve independence from gated features!
This commit makes rust-users runnable on Rust Stable and Beta!

- ToOwned in the collections crate can be imported by `std::borrow::ToOwned`
  instead, removing the collections flag.
- `as_ref` on raw pointers can be null-checked manually, then dereferenced,
  removing the ptr_as_ref flag. The new code reads better, too.
2015-08-02 16:41:19 +01:00
Ben S de6a1601db Update broken comment link... 2015-08-02 15:35:25 +01:00
Konstantin Stepanov 5cab91cf73 fix docs for switch_user_group 2015-07-23 01:40:53 +03:00
Konstantin Stepanov 7c19c92fd7 switch effective uid only 2015-07-21 12:55:44 +03:00
Konstantin Stepanov 184bd434e1 fixes 2015-07-21 12:19:45 +03:00
Konstantin Stepanov d52a2bcd8c update mock 2015-07-21 11:48:49 +03:00
Konstantin Stepanov fd73810619 security warnings 2015-07-21 11:43:10 +03:00
Konstantin Stepanov 0cabf243bd add switch user/group functionality 2015-07-21 11:39:32 +03:00
Konstantin Stepanov 6e2e00f287 add functions to set user and group 2015-07-21 11:32:22 +03:00
Konstantin Stepanov f5d3838e75 add methods to get effective user and group info 2015-07-21 11:22:58 +03:00
Konstantin Stepanov 825062139b import other gid/uid functions 2015-07-21 11:07:56 +03:00
Florian Wilkens 35903983ff Added missing feature flag and remove obsolete one 2015-06-20 16:22:59 +02:00
Michael Neumann 968fc14738 Fix build for DragonFly BSD 2015-06-16 13:41:54 +02:00