diff --git a/api/src/Accounts/Ads.php b/api/src/Accounts/Ads.php index c3f7bceca4..e8420a0c8f 100644 --- a/api/src/Accounts/Ads.php +++ b/api/src/Accounts/Ads.php @@ -228,7 +228,7 @@ class Ads * @param int $account_id * @return string|NULL */ - protected function get_sid($account_id=null) + public function get_sid($account_id=null) { static $domain_sid = null; if (!isset($domain_sid)) diff --git a/api/src/Contacts/Ads.php b/api/src/Contacts/Ads.php index 733cd2e820..22cef304b6 100644 --- a/api/src/Contacts/Ads.php +++ b/api/src/Contacts/Ads.php @@ -171,6 +171,31 @@ class Ads extends Ldap return '(objectguid='.($this->is_samba4 ? $contact_id : $this->accounts_ads->objectguid2hex($contact_id)).')'; } + /** + * Return LDAP filter for (multiple) account ids + * + * @param int|int[]|null $ids + * @return string + */ + protected function account_ids_filter($ids) + { + $filter = ''; + if (is_null($ids)) + { + $filter = '(!(objectsid=*))'; + } + elseif ($ids) + { + if (is_array($ids)) $filter = '(|'; + foreach((array)$ids as $account_id) + { + $filter .= '(objectsid='.$this->accounts_ads->get_sid($account_id).')'; + } + if (is_array($ids)) $filter .= ')'; + } + return $filter; + } + /** * Reads contact data * @@ -202,7 +227,7 @@ class Ads extends Ldap } /** - * Special handling for mapping data of ADA user objectclass to eGW contact + * Special handling for mapping data of ADS user objectclass to eGW contact * * Please note: all regular fields are already copied! * diff --git a/api/src/Contacts/Ldap.php b/api/src/Contacts/Ldap.php index 9598a69c95..a870671190 100644 --- a/api/src/Contacts/Ldap.php +++ b/api/src/Contacts/Ldap.php @@ -480,6 +480,29 @@ class Ldap return '(|'.implode('', $filter).')'; } + /** + * Return LDAP filter for (multiple) account ids + * + * @param int|int[]|null $ids + * @return string + */ + protected function account_ids_filter($ids) + { + $filter = ''; + if (is_null($ids)) + { + $filter = '(!(uidNumber=*))'; + } + elseif ($ids) + { + $filter = $this->ids_filter(array_map(static function($account_id) + { + return $GLOBALS['egw']->accounts->id2name($account_id, 'person_id'); + }, (array)$ids)); + } + return $filter; + } + /** * reads contact data * @@ -1030,19 +1053,7 @@ class Ldap break; case 'account_id': - if (is_null($value)) - { - $filters .= '(!(uidNumber=*))'; - } - elseif ($value) - { - if (is_array($value)) $filters .= '(|'; - foreach((array)$value as $val) - { - $filters .= '(uidNumber='.(int)$val.')'; - } - if (is_array($value)) $filters .= ')'; - } + $filters .= $this->account_ids_filter($value); break; case 'cat_id':