-
Notifications
You must be signed in to change notification settings - Fork 242
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
base: develop
Are you sure you want to change the base?
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. |
:
.: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.