public function Server::search in Lightweight Directory Access Protocol (LDAP) 8.3
Perform an LDAP search.
@remaining params mimick ldap_search() function params @TODO: Remove coding standard violation.
Parameters
string $base_dn: The search base. If NULL, we use $this->basedn. should not be esacaped.
string $filter: The search filter. such as sAMAccountName=jbarclay. attribute values (e.g. jbarclay) should be esacaped before calling.
array $attributes: List of desired attributes. If omitted, we only return "dn".
int $attrsonly: Attributes.
int $sizelimit: Size limit.
int $timelimit: Time limit.
null $deref: Dereference.
int $scope: Scope.
Return value
array|bool An array of matching entries->attributes (will have 0 elements if search returns no results), or FALSE on error.
5 calls to Server::search()
- Server::getNestedGroupDnFilters in ldap_servers/
src/ Entity/ Server.php - Search within the nested groups for further filters.
- Server::groupMembershipsFromEntryRecursive in ldap_servers/
src/ Entity/ Server.php - Recurse through all groups, adding parent groups to $all_group_dns array.
- Server::groupUserMembershipsFromEntry in ldap_servers/
src/ Entity/ Server.php - Get list of all groups that a user is a member of by querying groups.
- Server::matchUsernameToExistingLdapEntry in ldap_servers/
src/ Entity/ Server.php - Queries LDAP server for the user.
- Server::searchAllBaseDns in ldap_servers/
src/ Entity/ Server.php - Perform an LDAP search on all base dns and aggregate into one result.
File
- ldap_servers/
src/ Entity/ Server.php, line 731
Class
- Server
- Defines the Server entity.
Namespace
Drupal\ldap_servers\EntityCode
public function search($base_dn = NULL, $filter, array $attributes = [], $attrsonly = 0, $sizelimit = 0, $timelimit = 0, $deref = NULL, $scope = NULL) {
// @codingStandardsIgnoreEnd
if ($scope == NULL) {
$scope = Server::SCOPE_SUBTREE;
}
if ($base_dn == NULL) {
if (count($this
->getBaseDn()) == 1) {
$base_dn = $this
->getBaseDn()[0];
}
else {
return FALSE;
}
}
$this->detailLog
->log("LDAP search call with base_dn '%base_dn'. Filter is '%filter' with attributes '%attributes'. Only attributes %attrs_only, size limit %size_limit, time limit %time_limit, dereference %deref, scope %scope.", [
'%base_dn' => $base_dn,
'%filter' => $filter,
'%attributes' => is_array($attributes) ? implode(',', $attributes) : 'none',
'%attrs_only' => $attrsonly,
'%size_limit' => $sizelimit,
'%time_limit' => $timelimit,
'%deref' => $deref ? $deref : 'null',
'%scope' => $scope ? $scope : 'null',
]);
// When checking multiple servers, there's a chance we might not be
// connected yet.
$this
->connectAndBindIfNotAlready();
$ldapQueryParams = [
'connection' => $this->connection,
'base_dn' => $base_dn,
'filter' => $filter,
'attributes' => $attributes,
'attrsonly' => $attrsonly,
'sizelimit' => $sizelimit,
'timelimit' => $timelimit,
'deref' => $deref,
'scope' => $scope,
];
if ($this
->get('search_pagination')) {
$aggregated_entries = $this
->pagedLdapQuery($ldapQueryParams);
return $aggregated_entries;
}
else {
$result = $this
->ldapQuery($scope, $ldapQueryParams);
if ($result && $this
->countEntries($result) !== FALSE) {
$entries = ldap_get_entries($this->connection, $result);
\Drupal::moduleHandler()
->alter('ldap_server_search_results', $entries, $ldapQueryParams);
return is_array($entries) ? $entries : FALSE;
}
elseif ($this
->hasError()) {
$this->logger
->notice("LDAP search error: %error. Context is base DN: %base_dn | filter: %filter| attributes: %attributes", [
'%base_dn' => $ldapQueryParams['base_dn'],
'%filter' => $ldapQueryParams['filter'],
'%attributes' => json_encode($ldapQueryParams['attributes']),
'%error' => $this
->formattedError($this
->ldapErrorNumber()),
]);
return FALSE;
}
else {
return FALSE;
}
}
}