chroot: fix gid being set by uid with --userspec #10307#10465
chroot: fix gid being set by uid with --userspec #10307#10465ChrisDryden merged 6 commits intouutils:mainfrom
Conversation
|
GNU testsuite comparison: |
|
please add a test to make sure we won't regress, thanks! |
|
GNU testsuite comparison: |
b265ce1 to
5e7eccd
Compare
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
tests/by-util/test_chroot.rs
Outdated
There was a problem hiding this comment.
Were you able to get this test to run? This is missing a format! and is interpreting it as a string literal
stdout_is(format!("{gid}"))
There was a problem hiding this comment.
You are correct.
I wasn't aware that the chroot tests were behind a feature wall. I had run the tests without the feature flags so for me no errors appeared.
Sorry for that oversight
src/uu/chroot/src/chroot.rs
Outdated
There was a problem hiding this comment.
I think this is incorrect fallback logic:
| let gid = usr_name_to_gid(user)?; | |
| let gid = Passwd::locate(uid) | |
| .map(|p| p.gid) | |
| .map_err(|_| ChrootError::NoGroupSpecified(uid))?; |
You can see the difference with GNU with the params --userspec=99999 --groups=root
There was a problem hiding this comment.
Thanks for the tip. I will leave the abstraction of usr2gid that is being used in alot of other places too and change the map_err at this location.
58441e7 to
0219fbe
Compare
|
GNU testsuite comparison: |
…#10465) * chroot: fix gid being set by uid with --userspec * chroot: check using sync user that has uid != gid * chroot: correct Error response on failure case * chroot: fix test * chroot: test failure output --------- Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
Fix: #10307
Instead of blindly taking the uid as gid we will parse it out of passwd instead.
I am not sure how to write a test in the by_util/chroot.rs file as i dont see any precedence of how to create a user so im not sure how i could set up a test of a user with a different gid to their uid, happy to take pointers how this could be done in the testing framework.