Page 1 of 1
User Name Change Inconsistency
Posted: Thu May 01, 2025 6:58 am
by George MX
When setting up a new user in latest MX Linux, capital and lower case letters can be applied in the name (the preferred option). However, when changing the user's name in MX User Manager, only lower case letters can be used. Is there a workaround?
Re: User Name Change Inconsistency
Posted: Thu May 01, 2025 7:20 am
by j2mcgreg
You need to post the output from the QSI utility. The Quick System Info (QSI) utility is located in MX Tools and its output is automatically formatted for use here in the forum. Run the QSI utility, click “Copy for Forum” at the bottom and then just paste it here in your thread.
Forum Rules
Re: User Name Change Inconsistency
Posted: Thu May 01, 2025 7:52 am
by Adrian
No need for QSI, I checked mx-user and indeed for some reason I requested lower case for renaming the user, I will fix that.
Re: User Name Change Inconsistency
Posted: Thu May 01, 2025 8:55 am
by fehlix
Trying to rename "newuser" to "newuser-01" creates an invalid user account.
Seems there is an issue, with hyphens within username:
The renamed user is non working, due to some regexp issues as indicated by this generated line within passwd:
Code: Select all
newuser-01-01:x:1001:1001:newuser-01,,,:/home/newuser-01-01:/usr/bin/bash
Similar, regexp issues, when trying to rename
anotheruser-test to
anotheruser, shows a popop "User already exist".
So, suggest to get the "hyphen" "-" issue sorted, e.g. "grep -w" is not covering "-" as word boundary.
Re: User Name Change Inconsistency
Posted: Thu May 01, 2025 11:53 am
by Adrian
I think I was able to fix that hyphen issue.
Re: User Name Change Inconsistency
Posted: Thu May 01, 2025 12:52 pm
by fehlix
Adrian wrote: Thu May 01, 2025 11:53 am
I think I was able to fix that hyphen issue.
The culprit was this one:
Code: Select all
shell->runAsRoot("sed -i 's/\\b" + old_name + "\\b/" + new_name + "/g' /etc/passwd");
ok, The fix now offer this:
Code: Select all
shell->runAsRoot("sed -i 's/" + QRegularExpression::escape(old_name) + "/" + QRegularExpression::escape(new_name) + "/g' /etc/passwd");
Which looks to me won't fix it. b/c after the user account was renamed, from e.g from "newuser" to "newuser-01"
the line looks like this:
Code: Select all
newuser-01:x:1001:1001:newuser,,,:/home/newuser-01:/usr/bin/bash
now, the sed, tries to fix the the comment-field
with the new regex, the sed would look like:
Code: Select all
sed -i 's/newuser/newuser-01/g' /etc/passwd
and would make an invalid account line again.
To fix:
Add at begin and end an anchor regexp e.g. like NotAllowedAtStartExp and on NotAllowedAtEndReExp
with something like
Code: Select all
NotAllowedAtStartExp = "[^-A-Za-z0-9_]"
and
Code: Select all
NotAllowedAtEndReExp = "[^-A-Za-z0-9_$]"
and capture those chars back into the replacemen and do this only for the renamed user-line not for all other:
Code: Select all
shell->runAsRoot("sed -i -r '/^"+ QRegularExpression::escape(new_name) + ":/s/(" +NotAllowedAtStartExp +") "+ QRegularExpression::escape(old_name) + "(" + NotAllowedAtEndReExp +")"/\\1" + QRegularExpression::escape(new_name) + "\\2"/g' /etc/passwd");
Probaly simlar way exists.
Re: User Name Change Inconsistency
Posted: Thu May 01, 2025 1:20 pm
by Adrian
fehlix wrote: Thu May 01, 2025 12:52 pm
now, the sed, tries to fix the the comment-field
with the new regex, the sed would look like:
Code: Select all
sed -i 's/newuser/newuser-01/g' /etc/passwd
Are you sure? since it uses "QRegularExpression::escape" it should be:
Code: Select all
sed -i 's/newuser/newuser\-01/g' /etc/passwd
Re: User Name Change Inconsistency
Posted: Thu May 01, 2025 1:37 pm
by fehlix
Adrian wrote: Thu May 01, 2025 1:20 pm
fehlix wrote: Thu May 01, 2025 12:52 pm
now, the sed, tries to fix the the comment-field
with the new regex, the sed would look like:
Code: Select all
sed -i 's/newuser/newuser-01/g' /etc/passwd
Are you sure? since it uses "QRegularExpression::escape" it should be:
Code: Select all
sed -i 's/newuser/newuser\-01/g' /etc/passwd
Yes, the line you want to change is this:
Code: Select all
newuser-01:x:1001:1001:newuser,,,:/home/newuser-01:/usr/bin/bash
Check it:
Code: Select all
echo "newuser-01:x:1001:1001:newuser,,,:/home/newuser-01:/usr/bin/bash" | sed 's/newuser/newuser\-01/g'
gives
Code: Select all
newuser-01-01:x:1001:1001:newuser-01,,,:/home/newuser-01-01:/usr/bin/bash
also as mentioned, better try replacemen on the the new user line to avoid any side effect with something like this:
Code: Select all
sed -i '/^newuser\-01:/s/newuser/newuser\-01/g' /etc/passwd
Re: User Name Change Inconsistency
Posted: Thu May 01, 2025 3:11 pm
by Adrian
Can you please send me a PR on github? I think the cmd in runAsRoot() is not properly formatted.
Re: User Name Change Inconsistency
Posted: Thu May 01, 2025 3:50 pm
by fehlix
Adrian wrote: Thu May 01, 2025 3:11 pm
Can you please send me a PR on github? I think the cmd in runAsRoot() is not properly formatted.
Oh, the command posted, yes, that was only freestyle, without any testing. But you got the idea ... probably faster then me testing the stuff and sending a PR.
Maybe a shorter version, in case that helps to clarify:
Code: Select all
SRex = "([^-_[:alnum:]])";
ERex = "([^-_[:alnum:]$])";
NN = QRegularExpression::escape(new_name);
ON = QRegularExpression::escape(old_name);
shell->runAsRoot("sed -i -r '/^" + NN + ":/s/" + SRex + ON + ERex + "/\\1" + NN + "\\2"/g' /etc/passwd");
still freestyle, but guess you spot any typos.
Re: User Name Change Inconsistency [Solved]
Posted: Thu May 01, 2025 6:38 pm
by Adrian
Thanks, seems to be working fine in my tests, I will push 25.5.01 soon.