basic/user-util: always use base 10 for user/group numbers
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 31 May 2020 16:21:09 +0000 (18:21 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 23 Jun 2020 09:31:16 +0000 (11:31 +0200)
commit9498903de6c1f7b0c3e5f1654d0ee451a304c59d
treeb50550a9ea28be872fee93022ec7eb89cc6129a0
parent64126925181809e7c0b8916471186c0bfa19d6ce
basic/user-util: always use base 10 for user/group numbers

We would parse numbers with base prefixes as user identifiers. For example,
"0x2b3bfa0" would be interpreted as UID==45334432 and "01750" would be
interpreted as UID==1000. This parsing was used also in cases where either a
user/group name or number may be specified. This means that names like
0x2b3bfa0 would be ambiguous: they are a valid user name according to our
documented relaxed rules, but they would also be parsed as numeric uids.

This behaviour is definitely not expected by users, since tools generally only
accept decimal numbers (e.g. id, getent passwd), while other tools only accept
user names and thus will interpret such strings as user names without even
attempting to convert them to numbers (su, ssh). So let's follow suit and only
accept numbers in decimal notation. Effectively this means that we will reject
such strings as a username/uid/groupname/gid where strict mode is used, and try
to look up a user/group with such a name in relaxed mode.

Since the function changed is fairly low-level and fairly widely used, this
affects multiple tools: loginctl show-user/enable-linger/disable-linger foo',
the third argument in sysusers.d, fourth and fifth arguments in tmpfiles.d,
etc.

Fixes #15985.

(cherry picked from commit 156a5fd297b61bce31630d7a52c15614bf784843)
src/basic/user-util.c
src/test/test-user-util.c