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

Sharing dialog returns duplicate entries #6807

Closed
rogerfv1 opened this issue Oct 10, 2017 · 5 comments
Closed

Sharing dialog returns duplicate entries #6807

rogerfv1 opened this issue Oct 10, 2017 · 5 comments

Comments

@rogerfv1
Copy link

Steps to reproduce

  1. Configure ldap_expert_uuid_user_attr = uid on user_ldap plugin
  2. Use numeric/values for uid atribute in LDAP Server

Expected behaviour

Sharing dialog should display unique users/contacts.

Actual behaviour

Sharing dialog returns some duplicate users/contacts entries.

Server configuration

Operating system: Debian 8

Web server: Apache 2.4

Database: Postgresql 9.4

PHP version: php 5.6

Nextcloud version: 12.0.3

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

Are you using encryption: no

Are you using an external user-backend, if yes which one: LDAP

We looked at the source code and we found a issue when using numeric/integer values for 'uid'.
An array of users, groups and contacts is created on every search. Before it is shown to the enduser, the array values are compared in search of duplicated entries. The function "hasUserInResult" isn't working properly when the uid attribute from AD/LDAP is a integer. The problem seems to be that PHP is type casting the LDAP attribute 'uid' from string to integer.

File: /var/www/nextcloud/apps/files_sharing/lib/Controller/ShareesAPIController.php

    protected function hasUserInResult($userId) {
            foreach ($this->result['exact']['users'] as $result) {
                    if ($result['value']['shareWith'] === $userId) {
                            return true;
                    }
            }
            foreach ($this->result['users'] as $result) {
                    if ($result['value']['shareWith'] === $userId) { //  <---- sometimes we get identical values but different types INTEGER  === STRING
                            return true;
                    }
            }
            return false;
    }

    protected function getUsers($search) {
                    .....
                    .....
                    // Search in all users
                    $usersTmp = $this->userManager->searchDisplayName($search, $this->limit, $this->offset);

                    foreach ($usersTmp as $user) {
                            $users[$user->getUID()] = $user->getDisplayName();  //  <---- creating keys with type integer
                    }
                    .....
                    .....
    }

Example Code to simulate the issue:

<?php
$all = Array (
    'users' => Array (
                 0 => Array (
                     'label' => 'Mary',
                     'value' => Array ( 'shareType' => 0, 'shareWith' => '02222222222' )
                 ),
                 1 => Array (
                     'label' => 'Jean',
                     'value' => Array ( 'shareType' => 0, 'shareWith' => '22222222222' )
                 )
             )
         );
foreach ($all['users'] as $user) {
  $uid = $user['value']['shareWith'];
  $users[$uid] = 'nome';
}
foreach ($users as $key => $value) {
  echo "keyValue:".$key." keyType:".gettype($key)."\n";
}
?>

Workaround:

Maybe change the comparison operator in hasUserInResult function to "==".
$result['value']['shareWith'] == $userId
@rogerfv1
Copy link
Author

Hi,

We can reproduce creating local accounts.

Steps to reproduce:

  1. Create a local user.
    Username: 22222222222
    Password: password@123

  2. Add a Email to account.
    Email: [email protected]

  3. Search by "22222222222" in sharing dialog.

@blizzz
Copy link
Member

blizzz commented Oct 12, 2017

Use numeric/values for uid atribute in LDAP Server

@nickvergessen wasnt there a fix about numerical usernames recently?

@snab
Copy link

snab commented Jan 13, 2018

We have the same issue, but with slightly different config:

  • Nextcloud 12.0.4, on Nextcloud 12.0.0 it was fine
  • we use the USER_SQL Backend for users, all of them with numerical usernames as well.

The suggested workaround from the first post seems to work for us, but if it would be fixed upstream, it would be nice.

@snab
Copy link

snab commented Mar 1, 2018

This problem seems to be solved with Nextcloud 13. :-) 👍

@blizzz
Copy link
Member

blizzz commented Mar 2, 2018

thansk for the feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants