user-admin icon indicating copy to clipboard operation
user-admin copied to clipboard

Some systems have stricter regex for valid usernames

Open mesov opened this issue 11 months ago • 8 comments

On Debian and Ubuntu, uppercase letters and the dot symbol '.' are not valid User Name characters. So in some cases the User Name will pass the check but user creation will still fail.

https://github.com/zhuyaliang/user-admin/blob/094986c6ac77cad0f4c34048cb51b3d345ca7348/src/user-admin.c#L290-L295

In Ubuntu 22.04 /etc/adduser.conf has #NAME_REGEX="^[a-z][-a-z0-9_]*\$"

mesov avatar Mar 03 '24 13:03 mesov

Please run usermod -l Test -- Test on Debian and Ubuntu and output the results of the run

zhuyaliang avatar Mar 05 '24 02:03 zhuyaliang

Please run usermod -l Test -- Test on Debian and Ubuntu and output the results of the run

On Ubuntu 22.04, after adding a user with User Name "test" and Full Name "Test" I am getting usermod: user 'Test' does not exist. I have no Debian system at hand at the moment.

If I try to add a user "Test"/"Test" instead of "test"/"Test" I am getting this error message and no user is added: running '/usr/sbin/adduser' failed: Child process exited with code 1

mesov avatar Mar 07 '24 14:03 mesov

I don't have Debian and Ubuntu on hand, so I can't verify this issue at the moment. Accountsservice uses /usr/sbin/useradd to create users. usermod - l can detect whether the user name is legal. Please try using useradd - m TestUser to verify if the user name can include uppercase letters. If the problem persists, I will install a virtual machine to fix it

zhuyaliang avatar Mar 08 '24 01:03 zhuyaliang

I can now confirm that the behavior is the same on Debian 12 and Ubuntu 22.04: they both seem to be calling adduser instead of useradd, applying the stricter regex mentioned above that rejects uppercase letters, and throwing the error message.

Running useradd -m TestUser works on both: "TestUser" user is added, no error message, uppercase letters accepted.

mesov avatar Mar 08 '24 17:03 mesov

This Debian patch may explain why accountsservice calls adduser instead of useradd on Debian 12 and Ubuntu 22.04:

https://sources.debian.org/patches/accountsservice/22.08.8-6/0002-create-and-manage-groups-like-on-a-debian-system.patch/

mesov avatar Mar 08 '24 18:03 mesov

Thank you for your detailed explanation. I will try to fix this issue

zhuyaliang avatar Mar 11 '24 00:03 zhuyaliang

Thank you for your prompt replies.

A patch to the Debian package has now been suggested, since the problem was created by a Debian modification to accountsservice: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1065773.

mesov avatar Mar 11 '24 19:03 mesov

I came up with some tentative suggestions to fix the issue, but maybe someone with Debian packaging skills could help with a downstream patch. Is @N0rbert is still around?

mesov avatar Mar 15 '24 23:03 mesov