Skip to content

Conversation

@acdn-ndostert
Copy link

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 -F work as intended.

@acdn-ndostert acdn-ndostert force-pushed the useradd_subuid branch 2 times, most recently from 0066ad0 to 4ecf680 Compare January 17, 2026 17:19
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>
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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems brittle. It is affected by the fact that && has more precedence than ||, which is something not well known.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Collaborator

@alejandro-colomar alejandro-colomar Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but you have the full expression (see lines 2513 and above) as

a && b && && c && (...) || e

Those && and || don't necessarily interact as you'd expect.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but you have the full expression (see lines 2513 and above) as

a && b && && c && (...) || e

Those && 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 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

useradd: specifying UID for system users breaks -F

2 participants