login: Fix no-pam authorization regression #1174
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A regression in
/etc/login.access
parsing could allow or deny more users than configured. It affects shadow 4.17.x.The regression takes place in
login
tool if compiled without PAM support. Basically all distributions ship either with PAM support or use util-linux login, so this affects rather few systems, let alone it requires theEXCEPT
keyword in/etc/login.access
. Affected right now:And these distributions could be affected depending on compile configuration, but have older unaffected versions:
The
list_match
function handlesEXCEPT
entries in/etc/login.access
through recursive calls. It calls itself withNULL
, which was then passed tostrtok
so parsing continued at current position.Replacing
strtok
withstrsep
, this means thatEXCEPT
entries never match, becausestrsep(NULL, ...)
always returnsNULL
, i.e. the code treats everything afterEXCEPT
as non-existing.Fix this by passing current list pointer to recursive call.
Proof of Concept:
--without-libpam
, no need to install login into system/etc/login.access
file (replacemyuser
with a user which is okay if access is denied):If you try to log in as denied user, you can actually log in. This happens because the first rule matches
myuser
because EXCEPT handling is broken. With this patch,myuser
is correctly blocked because the first rule does not match, but the second.Fixes: 90afe61 (2024-07-04; "lib/, src/: Use strsep(3) instead of strtok(3)")