Changing username schema

Hi there! I know this is a rather unusual support request, but all I need is a code hint. Here is the problem: right now, I have the username schema set to domain_user. However, due to a merger and to streamline documentation and support, I want to change it to user@domain. I know this has implications with Postfix, which is why Virtualmin duplicates users, one with user-domain and the other with user@domain. So I thought I make use of that for a transitional period, and basically added duplicate users in user@domain format for all my domain_user users. So this works fine as far as logins go, however in the Virtualmin users list the users show up twice, because the duplicate user is in domain_user format and not user-domain. So I digged around in the code and came along this one in virtual-server-lib-funcs.pl, where I replaced

sub replace_atsign
{
local $rv = $_[0];
$rv =~ s/\@/-/g;
return $rv;
}

with

sub replace_atsign
{
local $rv = $_[0];
my @altusr = split /@/, $rv;
return join "_", $altusr[1], $altusr[0];
}

So this has the desired effect in that the users are no longer showing up twice in the user lists, and also creating new users works fine in that two users with user@domain and domain_user are created and the virtual address is properly setup in postfix also. There is one remaining problem however: for some reason, the users show up as if not having email enabled, even though it is. The behavior is correct though if I revert the patch and create a new user, that user shows up fine. So I guess there is some other code I need to touch, but was not able to find which one. Are you able to give me a hint here? Not asking for any code change, I am perfectly happy with running a patched Virtualmin for 1-2 months until all users have switched their clients to use the new username format.

Status: 
Active

Comments

Howdy -- the user@domain format is actually what I use on my own personal systems. That's my favorite format :-)

It is indeed possible to login using a user with the user@domain format.

What I believe won't work is email delivery.

So first off, I'd recommend verifying that everything is working properly in your case there, including email delivery.

However, I'm not sure I understand what your usernames look like in your case there.

Can you share an example of a particular user, and what usernames are associated with that account? Thanks!

OK @andreychek, I think I didn't explain myself well enough.

My situation right now: all users are in domain_user format, however I want them to be able to login as user@domain as well. So I switched the config to user@domain, created a user and had a look how Virtualmin managed that. It creates two unix users with the same ID, one with user@domain, and one with user-domain. Mail delivery is done to user-domain. So far so good. So I wrote up a quick script which altered /etc/shadow and /etc/passwd to add one user@domain user for each domain_user of mine. This also works, users are now able to log in both ways.

But now I had a problem: Virtualmin Validation would complain about duplicate unix users, and also in the user list in the GUI and in the CLI the users show up twice. So I though, there must be some mechanism in Virtualmin where when he has a user@domain and user-domain user, it won't act up. That's how I found that replace_atsign method and modified it, as described in my original post.

Now the validator does not complain anymore, and the users don't show up twice anymore in the user lists. However there is a small problem remaining: the users show up as having no mail.

So with my patch and this in /etc/passwd:

someuser@somedomain.tld:x:1234:5678:Some User:/home/somedomain.tld/homes/someuser:/dev/null
somedomain.tld_someuser:x:1234:5678:Some User:/home/somedomain.tld/homes/someuser:/dev/null

I get this:

root@poo:~# virtualmin list-users --domain somedomain.tld
User                 Real name            Mail FTP        DBs  Quota
-------------------- -------------------- ---- ---------- ---- ---------------
someuser         Some User            No   No         No   1.50 GB

However, mail delivery is active and working perfectly. It appears to be just a cosmetic issue, which has implications on trying to modify the user.

Now, if I revert my patch, I have this in /etc/passwd:

someuser@somedomain.tld:x:1234:5678:Some User:/home/somedomain.tld/homes/someuser:/dev/null
someuser-somedomain.tld:x:1234:5678:Some User:/home/somedomain.tld/homes/someuser:/dev/null

I get this:

root@poo:~# virtualmin list-users --domain somedomain.tld
User                 Real name            Mail FTP        DBs  Quota
-------------------- -------------------- ---- ---------- ---- ---------------
someuser         Some User            Yes No         No   1.50 GB

So I figured that my patch is not enough, that there must be some other piece of code telling Virtualmin how to handle those duplicate users. As I am not that familiar with Perl, I have not been able to find out yet.

Maybe who coded this could give me an advice? I know tampering with the code is not a good idea, but this will just be temporary for 1-2 months until clients have switched over to using the new user@domain. Once that is the case, I will revert my patch, switch the domain_user to user-domain in /etc/passwd, /etc/shadow and /etc/virtual, and all will be fine. But until then I need some kind of solution...

Thanks!

Okay, I gotcha.

We need to be able to login as user_domain, and user@domain.tld.

However, the users are appearing as if email isn't enabled.

Where is this showing up as not enabled -- are you referring to the screen in Edit Users -> USERNAME -> Email Settings -> Primary email address enabled? Are you saying that is set to "No" for these users?

Exactly! Except it us domain_user, not user_domain :)

I'm unfortunately not quite sure. I wasn't able to determine how to go about that... but Jamie may have some thoughts!

I didn't want to get your hopes up though, I'm also not sure that this is going to be simple (or possible).

But we'll see what Jamie has to say on the subject.

Unfortunately, if you're using user@domain format, the only other format that users is user-domain. There's no way to configure this in Virtualmin.