]> git.ipfire.org Git - thirdparty/shadow.git/commit
lib/chkname.c: login_name_max_size(): Put limits for LOGIN_NAME_MAX and sysconf(_SC_L...
authorAlejandro Colomar <alx@kernel.org>
Sat, 4 Jan 2025 12:10:48 +0000 (13:10 +0100)
committerAlejandro Colomar <alx@kernel.org>
Tue, 7 Jan 2025 14:25:31 +0000 (15:25 +0100)
commit8b36662205ed6ab0ec93a7e07f9fea66a8b4fd6d
tree07983c2a0ab9e700bb1ae4d6f6e9d94cf0a78d24
parent0b30e1ed29893018e5e3f3f8fd061b970429d560
lib/chkname.c: login_name_max_size(): Put limits for LOGIN_NAME_MAX and sysconf(_SC_LOGIN_NAME_MAX)

GNU Hurd doesn't define LOGIN_NAME_MAX.  GNU Hurd recommends having no
system limits.  When a program needs a limit, because it needs to
validate user input, it is recommended that each program defines its own
limit macros.  The rationale is that this avoids hard-coded limits in
ABIs, which cannot be modified ever.

However, that doesn't mean that programs should have no limits at all.
We use this limit for validating user input, and so we shouldn't allow
anything just because the system doesn't want to set a limit.

So, when sysconf(2) returns -1, either due to an error or due to a claim
for no limits, we must fall back to the LOGIN_NAME_MAX value.  And if
the system doesn't define that value, we must define it ourselves (we're
more or less free to choose any value, so let's pick the one that glibc
provides nowadays).

Fixes: 6a1f45d932c8 (2024-02-04; "lib/chkname.c: Support unlimited user name lengths")
Closes: <https://github.com/shadow-maint/shadow/issues/1166>
Cc: Chris Hofstaedtler <zeha@debian.org>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Reviewed-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/chkname.c