fix not working account_id filter for contacts in ActiveDirectory

This commit is contained in:
ralf 2023-02-15 15:32:44 +01:00
parent 330656c437
commit a769cdad34
3 changed files with 51 additions and 15 deletions

View File

@ -228,7 +228,7 @@ class Ads
* @param int $account_id * @param int $account_id
* @return string|NULL * @return string|NULL
*/ */
protected function get_sid($account_id=null) public function get_sid($account_id=null)
{ {
static $domain_sid = null; static $domain_sid = null;
if (!isset($domain_sid)) if (!isset($domain_sid))

View File

@ -171,6 +171,31 @@ class Ads extends Ldap
return '(objectguid='.($this->is_samba4 ? $contact_id : $this->accounts_ads->objectguid2hex($contact_id)).')'; 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 * 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! * Please note: all regular fields are already copied!
* *

View File

@ -480,6 +480,29 @@ class Ldap
return '(|'.implode('', $filter).')'; 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 * reads contact data
* *
@ -1030,19 +1053,7 @@ class Ldap
break; break;
case 'account_id': case 'account_id':
if (is_null($value)) $filters .= $this->account_ids_filter($value);
{
$filters .= '(!(uidNumber=*))';
}
elseif ($value)
{
if (is_array($value)) $filters .= '(|';
foreach((array)$value as $val)
{
$filters .= '(uidNumber='.(int)$val.')';
}
if (is_array($value)) $filters .= ')';
}
break; break;
case 'cat_id': case 'cat_id':