useradd: Correctly set subuid/subgid when using -F#1511
useradd: Correctly set subuid/subgid when using -F#1511acdn-ndostert wants to merge 1 commit intoshadow-maint:masterfrom
Conversation
0066ad0 to
4ecf680
Compare
The -F flag should bypass the UID check and always add entries to the sub[ud]id while the -r flag should still be used in addition with the UID check. Closes: <shadow-maint#1255> Signed-off-by: ndostert <crawax@cwxlab.fr>
4ecf680 to
1185c23
Compare
| subuid_count > 0 && sub_uid_file_present () && | ||
| (!rflg || Fflg) && | ||
| (!user_id || (user_id <= uid_max && user_id >= uid_min)); | ||
| (!rflg && (!user_id || (user_id <= uid_max && user_id >= uid_min))) || Fflg; |
There was a problem hiding this comment.
This seems brittle. It is affected by the fact that && has more precedence than ||, which is something not well known.
There was a problem hiding this comment.
Sorry I'm more a Python person, I can mostly read C code but not really write it.
Doesn't the parenthesis group the tests so there is not && and || in the same test ?
(
!rflg && (
!user_id || (
user_id <= uid_max && user_id >= uid_min
)
)
) || Fflg;
There was a problem hiding this comment.
Yes, but you have the full expression (see lines 2513 and above) as
a && b && && c && (...) || eThose && and || don't necessarily interact as you'd expect.
There was a problem hiding this comment.
Yes, but you have the full expression (see lines 2513 and above) as
a && b && && c && (...) || eThose && and || don't necessarily interact as you'd expect.
Ah yes I see, well I'm out of my depth on that.
I will see if I can either "prove" this work or fix it.
And also, thanks for your help !
There was a problem hiding this comment.
If I were you, I'd start from the original code, and do the minimal changes that achieve what you want. Don't try to make it look nice. The smaller the diff, the easier it will be to review. I can clean up the code afterwards to make it look good.
There was a problem hiding this comment.
Github is eating my comments. Grr.
There was a problem hiding this comment.
Please rebase. We've made it much easier to read and modify.
|
Yeah, I think this is correct. But let's let it settle a bit longer, I'd like to take another look at the logic on a different day with a clear head. |
|
I think @alejandro-colomar is correct the fix is not right as the I wrote this to test the operators: And running it print |
|
Let's try adding the comment as not-a-reply. I think it's clearest if you move the decision into a function. That leaves main easier to read, and gives you more space to clearly write out the decision to be made |
Agree. I will publish a PR that refactors the current code. We can merge that ASAP, so that @acdn-ndostert can then rebase, and do a minimal change to that function. |
Fixes #1255
I was not able to run the tests as described in doc/contributions/tests.md at the moment but I was able to build and test that
useradd -Fwork as intended.