ogham / rust-users

Library for Unix users and groups in Rust.
https://crates.io/crates/users
MIT License
99 stars 37 forks source link

Got an error while building to SunOS #36

Open KrutNA opened 4 years ago

KrutNA commented 4 years ago

Steps to reproduce:

Try to build users crate to sparcv9-sun-solaris or x86_64-sun-solaris archs. I'm trying to cross compile fselect and used cross for cross compiling to other archs

Expected:

Compiled successfully.

Got:

   Compiling users v0.9.1
error[E0425]: cannot find function `getgrouplist` in crate `libc`
   --> /cargo/registry/src/github.com-1ecc6299db9ec823/users-0.9.1/src/base.rs:707:15
    |
707 |         libc::getgrouplist(name.as_ptr(), gid, buff.as_mut_ptr(), &mut count)
    |               ^^^^^^^^^^^^ help: a function with a similar name exists: `getgroups`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0425`.
error: could not compile `users`.
warning: build failed, waiting for other jobs to finish...
error: build failed

As I checked crate libc, I found in documentation: there is no functions getgrouplist for this archs. libc/platform-specific-documentation

ogham commented 3 years ago

I did some digging into this. Oracle's libc documentation has a page for getgrouplist, but I've seen references to other projects saying Solaris doesn't have that function, so there must be a reason why it's missing from Rust's libc.

If we can't use getgrouplist, then, we'd have to write our own version. However — and this is where it gets difficult — we'd have to iterate through the groups list using getgrent/setgrent/endgrent, which mutates a structure internal to libc that's effectively global. See the doc comment for all_users for why this is so annoying. As this is meant to be a library, rather than an application, we have no way of ensuring that our getgrouplist replacement is the only code using those three functions exclusively.

I'll have to mark this one as "help wanted" until a better solution comes along. The only workaround I can offer is to add a feature flag to omit all the functions that use getgrouplist, but that doesn't help you if you're trying to port an existing application.

Toasterson commented 2 years ago

@papertigers @jclulow can we push that function on the illumos side into libc? I think this library is the only one implementing user related functionality in rust so some better support is good for rust projects wanting to check/modify os user configs.

I get this error aswell on illumos

papertigers commented 2 years ago

It's there now: https://rust-lang.github.io/libc/x86_64-unknown-illumos/doc/libc/fn.getgrouplist.html And the corresponding illumos commit: https://github.com/illumos/illumos-gate/commit/f2c438c5058c64b7373448f239156bf60009abcb

Toasterson commented 2 years ago

Awesome thanks. Now with a modern enough version of libc and your PR it compiled. Up to testing metadata agent on bhyve :)

nospam3089 commented 2 years ago

For what it's worth, the addition of getgrouplist was mentioned in the Release Notes for r151038.

Toasterson commented 2 years ago

Ping @ogham getgrouplist has been added for illumos libc in rust. do you need anything else?