core icon indicating copy to clipboard operation
core copied to clipboard

Not all LDAP users show up in share dialog

Open fder opened this issue 12 years ago • 22 comments

Steps to reproduce

  1. Add LDAP configuration
  2. Add several users to the same LDAP group
  3. Try sharing with all of them directly using “Allow users to only share with users in their groups”
  4. Try sharing with all of them directly using “Allow users to share with anyone”

Expected behaviour

When using setting “Allow users to only share with users in their groups” all users in the same group should appear in sharing dialog.

When using “Allow users to share with anyone” all users in all groups should appear in sharing dialog.

Actual behaviour

When using setting “Allow users to only share with users in their groups” only some users in the same group appear in sharing dialog.

When using “Allow users to share with anyone” all users in all groups appear in sharing dialog, even those who don’t show up if above configuration is used.

All users show up in the Users list and they can all login.

Server configuration

Operating system: Ubuntu 12.04.4 LTS

Web server: Apache/2.2.22

Database: MySQL Ver 14.14 Distrib 5.5.37

PHP version: 5.3.10

ownCloud version: 6.0.3

Updated from an older ownCloud or fresh install: Upgrade from 5.0.12

List of activated apps: Activity, Deleted files, First Run Wizard, Full Text Search, LDAP user and group backend, ownCloud dependencies info, PDF Viewer, Share Files, Text Editor, Versions

The content of config/config.php:

<?php
$CONFIG = array (
  'mail_smtpmode' => 'smtp',
  'mail_smtphost' => 'smtprelay02.company.local’,
  'mail_smtpport' => 587,
  'instanceid' => '519359d35c9e3',
  'passwordsalt' => ‘*’,
  'datadirectory' => '/data',
  'dbtype' => 'mysql',
  'version' => '6.0.3.1',
  'dbname' => ‘ocdb',
  'dbhost' => '127.0.0.1',
  'theme' => ‘oc-dev',
  'dbtableprefix' => 'oc_',
  'dbuser' => ‘ocsql',
  'dbpassword' => ‘*’,
  'installed' => true,
  'ldapIgnoreNamingRules' => false,
  'loglevel' => '0',
  'forcessl' => true,
  'maintenance' => false,
  'appstoreenabled' => false,
  'updatechecker' => false,
  'trusted_domains' =>
  array (
    0 => ‘oc01.company.local’,
  ),
);

Are you using external storage, if yes which one: No

Are you using encryption: HTTPS

Client configuration

Browser: Firefox, Chrome, Internet Explorer

Operating system: Windows 8, Windows 7, MacOS X 10.9.2, Linux Mint Debian Edition

Logs

Web server error log

Nothing happens when trying to share.

ownCloud log (data/owncloud.log)

## Allow users to only share with users in their groups
{"app":"user_ldap","message":"getGroups getGroups-peter--","level":0,"time":"2014-05-10T09:16:54+00:00"}
{"app":"user_ldap","message":"getGroups Filter (&(|(cn=*-ownCloud))(cn=*peter*))","level":0,"time":"2014-05-10T09:16:54+00:00"}
{"app":"user_ldap","message":"Turned off SSL certificate validation successfully.","level":2,"time":"2014-05-10T09:16:54+00:00"}
{"app":"user_ldap","message":"getUsers: Options: search peter limit  offset  Filter: (&(|(memberof=CN=RG-ownCloud,OU=Services,OU=Resource Groups,OU=Groups,OU=COMPANY,DC=company,DC=local))(cn=*peter*))","level":0,"time":"2014-05-10T09:16:54+00:00"}
{"app":"user_ldap","message":"getUsers: 1 Users found","level":0,"time":"2014-05-10T09:16:54+00:00"}

## Allow users to share with anyone
{"app":"user_ldap","message":"getGroups getGroups-peter--","level":0,"time":"2014-05-10T09:18:31+00:00"}
{"app":"user_ldap","message":"getUsers: Options: search peter limit 15 offset 0 Filter: (&(|(memberof=CN=RG-ownCloud,OU=Services,OU=Resource Groups,OU=Groups,OU=COMPANY,DC=company,DC=local))(cn=*peter*))","level":0,"time":"2014-05-10T09:18:31+00:00"}
{"app":"user_ldap","message":"Turned off SSL certificate validation successfully.","level":2,"time":"2014-05-10T09:18:31+00:00"}
{"app":"user_ldap","message":"Paged search was not available","level":1,"time":"2014-05-10T09:18:31+00:00"}
{"app":"user_ldap","message":"getUsers: 1 Users found","level":0,"time":"2014-05-10T09:18:31+00:00"}

fder avatar May 10 '14 09:05 fder

Update:

If I create another LDAP group and add myself and the users who do not show up in the share dialog when using "Allow users to only share with users in their groups", they show up. If I add too many users to the new group they disappear again.

There seems to be some sort of limit for how many users that can exist in the same group and still show up in the sharing dialog.

fder avatar May 14 '14 15:05 fder

When I changed the following in core/ajax/share.php it seems to work:

while ($count < 15 && count($users) == $limit) {
    $limit = 15 - $count;

Change to:

while ($count < 115 && count($users) == $limit) {
    $limit = 115 - $count;

Is there some reason why there is a limit of 15?

fder avatar May 14 '14 17:05 fder

It seems the value in $limit is the one causing the problem. My current configuration: while ($count < 10 && count($users) == $limit) { $limit = 100 - $count; Isn't there a way to set $limit to the number of users in $users?

fder avatar May 20 '14 11:05 fder

I have a part of the solution:

                                $groups = OC_Group::getGroups($_GET['search']);
                                if ($sharePolicy == 'groups_only') {
                                        $usergroups = OC_Group::getUserGroups(OC_User::getUser());
                                        $groups = array_intersect($groups, $usergroups);
                                }
                                $count = 0;
                                $users = array();
                                $limit = 0;
                                $offset = 0;

                                while ($count < 15 && count($users) == $limit) {
                                        //$limit = 15 - $count;
                                       $userlimit = count(OC_Group::usersInGroup($usergroups[0]));
                                       $limit = $userlimit - $count; 

This solution works only for the first group, but it is better then $limit = 2000 - $count;

rolandbu avatar May 21 '14 17:05 rolandbu

next Version, I think it is the solution of the Problem.

                                $groups = OC_Group::getGroups($_GET['search']);
                                if ($sharePolicy == 'groups_only') {
                                        $usergroups = OC_Group::getUserGroups(OC_User::getUser());
                                        $groups = array_intersect($groups, $usergroups);
                                }
                                $count = 0;
                                $users = array();
                                $limit = 0;
                                $offset = 0;

                                for ($i = 0; $i < count($usergroups); $i++) {
                                OC_Log::write('core', 'Group Name : '.$usergroups[$i], OC_Log::DEBUG);
                                OC_Log::write('core', 'Group count : '.count($usergroups), OC_Log::DEBUG);

                                while ($count < 15 && count($users) == $limit) {
                                        //$limit = 15 - $count;
                                       $userlimit = count(OC_Group::usersInGroup($usergroups[$i]));
$limit = $userlimit - $count;
                                        OC_Log::write('core', 'Variable COUNT : '.$count, OC_Log::DEBUG);
                                        OC_Log::write('core', 'Variable LIMIT : '.$limit, OC_Log::DEBUG);
                                        OC_Log::write('core', 'Variable USERLIMIT : '.$userlimit, OC_Log::DEBUG);
                                        if ($sharePolicy == 'groups_only') {
                                                $users = OC_Group::DisplayNamesInGroups($usergroups, $_GET['search'], $limit, $offset);
                                        } else {
                                                $users = OC_User::getDisplayNames($_GET['search'], $limit, $offset);
                                        }
                                        $offset += $limit;
                                        foreach ($users as $uid => $displayName) {
                                                if ((!isset($_GET['itemShares'])
                                                        || !is_array($_GET['itemShares'][OCP\Share::SHARE_TYPE_USER])
                                                        || !in_array($uid, $_GET['itemShares'][OCP\Share::SHARE_TYPE_USER]))
                                                        && $uid != OC_User::getUser()) {
                                                        $shareWith[] = array(
                                                                'label' => $displayName,
                                                                'value' => array(
                                                                        'shareType' => OCP\Share::SHARE_TYPE_USER,
                                                                        'shareWith' => $uid)
                                                        );
                                                        $count++;
                                                }
                                        }
                                }
                                $count = 0;
                                $users = array();
                                $limit = 0;
                                $offset = 0;
                                }

rolandbu avatar May 21 '14 21:05 rolandbu

I've tried the above code and it works. There is a little problem though; if you're a member of two groups and the person you're searching for also is a member of those two groups, that person will show up twice.

fder avatar May 22 '14 06:05 fder

I think this works. It's your code, I just moved some brackets. I have tried it out but please verify @rolandbu.

                               $groups = OC_Group::getGroups($_GET['search']);
                                if ($sharePolicy == 'groups_only') {
                                        $usergroups = OC_Group::getUserGroups(OC_User::getUser());
                                        $groups = array_intersect($groups, $usergroups);
                                }

                                $count = 0;
                                $users = array();
                                $limit = 0;
                                $offset = 0;

                                for ($i = 0; $i < count($usergroups); $i++) {

                                        OC_Log::write('core', 'Group Name : '.$usergroups[$i], OC_Log::DEBUG);
                                        OC_Log::write('core', 'Group count : '.count($usergroups), OC_Log::DEBUG);

                                        $userlimit += count(OC_Group::usersInGroup($usergroups[$i]));

                                }

                                while ($count < 15 && count($users) == $limit) {
                                        // $limit = 15 - $count;
                                        $limit = $userlimit - $count;

                                        OC_Log::write('core', 'Variable COUNT : '.$count, OC_Log::DEBUG);
                                        OC_Log::write('core', 'Variable LIMIT : '.$limit, OC_Log::DEBUG);
                                        OC_Log::write('core', 'Variable USERLIMIT : '.$userlimit, OC_Log::DEBUG);

                                        if ($sharePolicy == 'groups_only') {
                                                $users = OC_Group::DisplayNamesInGroups($usergroups, $_GET['search'], $limit, $offset);
                                        } else {
                                                $users = OC_User::getDisplayNames($_GET['search'], $limit, $offset);
                                        }

                                        $offset += $limit;

                                        foreach ($users as $uid => $displayName) {

                                                if ((!isset($_GET['itemShares'])
                                                        || !is_array($_GET['itemShares'][OCP\Share::SHARE_TYPE_USER])
                                                        || !in_array($uid, $_GET['itemShares'][OCP\Share::SHARE_TYPE_USER]))
                                                        && $uid != OC_User::getUser()) {

                                                        $shareWith[] = array(
                                                                'label' => $displayName,
                                                                'value' => array(
                                                                'shareType' => OCP\Share::SHARE_TYPE_USER,
                                                                'shareWith' => $uid)
                                                        );

                                                        $count++;

                                                }
                                        }
                                }

fder avatar May 22 '14 20:05 fder

You make a mistake with the loops! the loop "for" goes around the loop "while". at the end of the loop "for" you must set the varibale back to 0!

                                $groups = OC_Group::getGroups($_GET['search']);
                                if ($sharePolicy == 'groups_only') {
                                        $usergroups = OC_Group::getUserGroups(OC_User::getUser());
                                        $groups = array_intersect($groups, $usergroups);
                                }
                                $count = 0;
                                $users = array();
                                $limit = 0;
                                $offset = 0;

                                OC_Log::write('core', 'Group count : '.count($usergroups), OC_Log::DEBUG);

                                for ($i = 0; $i < count($usergroups); $i++) {

                                        while ($count < 15 && count($users) == $limit) {
                                                //$limit = 15 - $count;
                                                $userlimit = count(OC_Group::usersInGroup($usergroups[$i]));
                                                $limit = $userlimit - $count;
                                                OC_Log::write('core', 'Variable LIMIT : '.$limit, OC_Log::DEBUG);
                                                OC_Log::write('core', 'Variable USERLIMIT : '.$userlimit, OC_Log::DEBUG);
                                                if ($sharePolicy == 'groups_only') {
                                                        $users = OC_Group::DisplayNamesInGroups($usergroups, $_GET['search'], $limit, $offset);
                                                } else {
                                                        $users = OC_User::getDisplayNames($_GET['search'], $limit, $offset);
                                                }
                                                $offset += $limit;
                                                foreach ($users as $uid => $displayName) {
                                                        if ((!isset($_GET['itemShares'])
                                                                || !is_array($_GET['itemShares'][OCP\Share::SHARE_TYPE_USER])
                                                                || !in_array($uid, $_GET['itemShares'][OCP\Share::SHARE_TYPE_USER]))
                                                                && $uid != OC_User::getUser()) {
                                                                $shareWith[] = array(
                                                                        'label' => $displayName,
                                                                        'value' => array(
                                                                                'shareType' => OCP\Share::SHARE_TYPE_USER,
                                                                                'shareWith' => $uid)
                                                                );
                                                                $count++;
                                                        }
                                                }
                                        }
                                        $count = 0;
                                        $users = array();
                                        $limit = 0;
                                        $offset = 0;
                                }
                                $count = 0;

rolandbu avatar May 23 '14 03:05 rolandbu

Why is that? In the for-loop I get the value used in $limit. Let's say I have two groups; one with 3 users and one with 5 users. The $userlimit value in the while-loop will be 8, which is good because it's all the users that can show up in the share dialog.

for ($i = 0; $i < count($usergroups); $i++) {

    OC_Log::write('core', 'Group Name : '.$usergroups[$i], OC_Log::DEBUG);
    OC_Log::write('core', 'Group count : '.count($usergroups), OC_Log::DEBUG);
    OC_Log::write('core', 'Userlimit : '.$userlimit, OC_Log::DEBUG);

    $userlimit += count(OC_Group::usersInGroup($usergroups[$i]));

}

The $userlimit value is then used in the while-loop instead of a static value, as before.

while ($count < 15 && count($users) == $limit) {
    // $limit = 15 - $count;
    $limit = $userlimit - $count;

    // ...

This should work right?

fder avatar May 23 '14 05:05 fder

hm, for example you have 3 groups:

  1. group staff with 2500 members
  2. group teacher with 20 members
  3. students with 50 members $userlimit need to be <= then the bigest group and yes I think it works.

you meen $limit = 2500 + 20 + 50 are the best way?

I think, $limit need to be always the correct value of group members.

but you need definitely the "for" loop around the "while" loop, because if you dont make this, you would search always in the first group.

Plaese make a test, search one person from the secod group. You will see, with our solution, you dont find this Person.

rolandbu avatar May 23 '14 15:05 rolandbu

The while-loop takes care of all the groups by itself so all users from all groups will show up even without the for-loop (if we set $limit to a higher value than all users in all groups combined):

if ($sharePolicy == 'groups_only') {
        $users = OC_Group::DisplayNamesInGroups($usergroups, $_GET['search'], $limit, $offset);
    } else {
        $users = OC_User::getDisplayNames($_GET['search'], $limit, $offset);
}

The function OC_Group::DisplayNamesInGroups will even merge users that are the same in the groups; have a look in lib/private/group.php.

This means that the only thing we have to do is finding a dynamic value for $limit that isn't less then the amount of users we have in out groups combined. I think we have done that :)

fder avatar May 23 '14 16:05 fder

Sorry, my mistake. Yes we need only $limit

                                for ($i = 0; $i < count($usergroups); $i++) {
                                        OC_Log::write('core', 'Group count : '.count($usergroups), OC_Log::DEBUG);
                                        OC_Log::write('core', 'Group Name : '.$usergroups[$i], OC_Log::DEBUG);
                                        OC_Log::write('core', 'Group Members : '.count(OC_Group::usersInGroup($usergroups[$i])), OC_Log::DEBUG);
                                        $userlimit += count(OC_Group::usersInGroup($usergroups[$i]));
                                        OC_Log::write('core', 'Userlimit : '.$userlimit, OC_Log::DEBUG);
                                }

                                while ($count < 15 && count($users) == $limit) {
                                        //$limit = 1500 - $count;
                                        $limit = $userlimit - $count;

Yes, I think too we have done that :-)

rolandbu avatar May 23 '14 17:05 rolandbu

Ok. So this may have been solved. It needs verification though. How do we proceed? @PVince81

fder avatar May 23 '14 18:05 fder

@fder I haven't read the above message, do you mean it was solved on master or by @rolandbu 's changes ? The best would be for @rolandbu to submit a pull request with these changes so we can merge them into the core code.

CC @blizzz

PVince81 avatar May 24 '14 17:05 PVince81

I did not read the backlog yet, but the PR is not there yet, is it?

blizzz avatar May 26 '14 14:05 blizzz

never mind

blizzz avatar May 26 '14 14:05 blizzz

@blizzz So is this fixed?

karlitschek avatar Jun 24 '14 17:06 karlitschek

This problem persists in 7.0.2. I can still only see the first 15 users in a group from the Share interface.

razyr avatar Aug 29 '14 11:08 razyr

@blizzz @PVince81 I have the same behavior but without LDAP and oC 6.0.5, could be https://github.com/owncloud/core/issues/8528#issuecomment-43109543 a workaround for now? Or this issue is not relevant with my situation?

cdamken avatar Oct 22 '14 13:10 cdamken

Fix will be released with 6.0.6 and 7.0.3. There are two or three different commits related to this, best if you simply wait until they are out. Otherwise, follow the PRs and they're ports as stated in https://github.com/owncloud/core/issues/10513#issuecomment-56356715

blizzz avatar Oct 22 '14 14:10 blizzz