-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite chuser() for simplicity and correctness #1203
Rewrite chuser() for simplicity and correctness #1203
Conversation
I'm OK with this, we might be able to write a unit test in |
- Use unambiguous variable names (w/o package name conflict). - Fail on invalid input such as the empty string or `:`. - Do not change group without user, i.e. fail on `:group`. - Parse input using mnemonic APIs. - Do not juggle between integer types. - Unset supplementary groups. - Use setres[ug]id(2) to match the idiom of OpenBSD base programs. Includes/Supersedes yggdrasil-network#1202. Fixes yggdrasil-network#927. I only tested on OpenBSD (so far), hence the split, but other systems should just work.
2a8ddac
to
3fede90
Compare
I simply replaced the existing code. Looking into tests now... |
Now with macOS building, still looks good on OpenBSD:
|
`-user foo` would fail with an ugly `panic: strconv.Atoi: parsing "foo": invalid syntax` as returned by `user.LookupId()`, whereas `user.Lookup()` nicely says `panic: user: unknown user foo` In chuser() it does not matter whether we check by ID or name first, so flip the order to get sensible logs without `fmt.Errorf()` wrapping.
A bunch of negative cases for the userspace-side parser. Since the actual set*(2) guts require root, skip accordingly.
|
Every user may change its user/group ID to the current one. With an ugly hack, skip the superuser-only part of chuser() to exercise this rest of the code path in regular tests.
Unless you run tests as root (who does that?), there is no way to test all of that code automatically. @neilalexander I've abused an optional function parameter to cover the actual set*id(2) syscalls in CI. |
…e user" https://github.com/yggdrasil-network/yggdrasil-go/actions/runs/11787911199/job/32834078977?pr=1203#step:5:19 shows that it works on Linux, so undo the hack. This reverts commit 12acd71.
Linux drops privileges fine in CI. |
Is this ready for review in that case? |
Yes, this PR is ready as-is, just like the other two. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
:
.:group
.(cannot use setres[ug]id(2) as macOS does not have them.)
Includes/Supersedes #1202.
Fixes #927.
I only tested on OpenBSD (so far), but other systems should just work.