Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[regression] All new LDAP users got 65534+ uid instead of 2000+ #1938

Open
MurzNN opened this issue Jan 10, 2020 · 2 comments
Open

[regression] All new LDAP users got 65534+ uid instead of 2000+ #1938

MurzNN opened this issue Jan 10, 2020 · 2 comments
Labels

Comments

@MurzNN
Copy link

@MurzNN MurzNN commented Jan 10, 2020

Describe the bug
On Zentyal 6.1 default setup, created via Zentyal users got user ids, starting from 65534 (Guest) and increasing (user2 is 65535, user3 is 65536, etc), instead of 2000+, like designed in old Zentyal versions. On Zentyal 4.x user ids was in 2000+ range.

To Reproduce
Steps to reproduce the behavior:

  1. Install Zentyal Domain Controller on clean Ubuntu 18.04 with default settings.
  2. Create new user on Domain Controller.
  3. Lookup at user id, it will be 65535 instead of something near to 2000.

Expected behavior
User ids must be in 2000-3000 range!

Zentyal OS (please complete the following information):

  • Version: 6.1
  • Version of the module which has the bug: zentyal-samba 6.1.2
  • Modules installed: DC

Other OS (please complete the following information):

  • OS: Ubuntu
  • Version: 18.04
@MurzNN MurzNN added the Type: Bug label Jan 10, 2020
@MurzNN

This comment has been minimized.

Copy link
Author

@MurzNN MurzNN commented Jan 10, 2020

Here is forum thread about this bug: https://forum.zentyal.org/index.php/topic,34843.0.html

Seems the source of problem is in /usr/share/perl5/EBox/Samba/User.pm code, that generates new user id:

# Method: lastUid
#
#       Returns the last uid used.
#
# Parameters:
#
#       system - boolean: if true, it returns the last uid for system users,
#                         otherwise the last uid for normal users
#       
# Returns:
#
#       string - last uid
#
sub lastUid
{
    my ($class, $system) = @_;

    my $lastUid = -1;
    my $sambaModule = EBox::Global->modInstance('samba');
    foreach my $user (@{$sambaModule->users($system)}) {
        my $uid = $user->get('uidNumber');
        if ($system) {
            last if ($uid >= MINUID);
        } else {
            next if ($uid < MINUID);
        }
        if ($uid > $lastUid) {
            $lastUid = $uid;
        }
    }
        
    my $ret;
    if ($system) {
        $ret = ($lastUid < SYSMINUID ? SYSMINUID : $lastUid);
    } else {
        $ret = ($lastUid < MINUID ? MINUID : $lastUid);
    }
    return $ret;
}

It lookups to max user id, but Zentyal create Guest user id with hard-coded 65534 id in /usr/share/perl5/EBox/Samba/SecurityPrincipal.pm :

# Method: lastUid
#
#       Returns the last uid used.
#
# Parameters:
#
#       system - boolean: if true, it returns the last uid for system users,
#                         otherwise the last uid for normal users
#       
# Returns:
#
#       string - last uid
#
sub lastUid
{
    my ($class, $system) = @_;

    my $lastUid = -1;
    my $sambaModule = EBox::Global->modInstance('samba');
    foreach my $user (@{$sambaModule->users($system)}) {
        my $uid = $user->get('uidNumber');
        if ($system) {
            last if ($uid >= MINUID);
        } else {
            next if ($uid < MINUID);
        }
        if ($uid > $lastUid) {
            $lastUid = $uid;
        }
    }
        
    my $ret;
    if ($system) {
        $ret = ($lastUid < SYSMINUID ? SYSMINUID : $lastUid);
    } else {
        $ret = ($lastUid < MINUID ? MINUID : $lastUid);
    }
    return $ret;
}

So after creating Guest user on Zentyal default install, all other users got guest uid+1!

What is right way to fix this problem? Maybe exclude Guest user (by name) from MINUID check in function lastUid?

@MurzNN

This comment has been minimized.

Copy link
Author

@MurzNN MurzNN commented Jan 10, 2020

My quick solution for this bug is to check only id's less than 65534, here is modified code:

    foreach my $user (@{$sambaModule->users($system)}) {
        if($user->get('uidNumber') < 65534) {
            my $uid = $user->get('uidNumber');
            if ($system) {
                last if ($uid >= MINUID);
            } else {
                next if ($uid < MINUID);
            }
            if ($uid > $lastUid) {
                $lastUid = $uid;
            }
        }
    }

After this patch, new users got 2501+ id's, that's good!

Is this right way to fix problem? If yes, I can make pull request with this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.