zhuyaliang / user-admin

GNU General Public License v3.0
27 stars 16 forks source link

Some systems have stricter regex for valid usernames #62

Open mesov opened 7 months ago

mesov commented 7 months ago

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_]*\$"

zhuyaliang commented 7 months ago

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

mesov commented 7 months ago

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

zhuyaliang commented 7 months ago

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

mesov commented 7 months ago

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 commented 7 months ago

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/

zhuyaliang commented 7 months ago

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

mesov commented 7 months ago

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 commented 7 months ago

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?