public function LdapServer::search in Lightweight Directory Access Protocol (LDAP) 7.2
Same name and namespace in other branches
- 8.2 ldap_servers/LdapServer.class.php \LdapServer::search()
- 7 ldap_servers/LdapServer.class.php \LdapServer::search()
Perform an LDAP search.
@remaining params mimick ldap_search() function params
Parameters
string $basedn: 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".
Return value
An array of matching entries->attributes (will have 0 elements if search returns no results), or FALSE on error.
6 calls to LdapServer::search()
- LdapServer::groupMembershipsFromEntryRecursive in ldap_servers/
LdapServer.class.php - Recurse through all groups, adding parent groups to $all_group_dns array.
- LdapServer::groupMembersResursive in ldap_servers/
LdapServer.class.php - NOT IMPLEMENTED recurse through all child groups and add members.
- LdapServer::groupUserMembershipsFromEntry in ldap_servers/
LdapServer.class.php - Get list of all groups that a user is a member of by querying groups.
- LdapServer::groupUserMembershipsFromUserAttr in ldap_servers/
LdapServer.class.php - Get list of all groups that a user is a member of by using memberOf attribute first, then if nesting is true, using group entries to find parent groups.
- LdapServer::searchAllBaseDns in ldap_servers/
LdapServer.class.php - Perform an LDAP search on all base dns and aggregate into one result.
1 method overrides LdapServer::search()
- LdapServerTest::search in ldap_test/
LdapServerTest.class.php - Perform an LDAP search.
File
- ldap_servers/
LdapServer.class.php, line 795 - Defines server classes and related functions.
Class
- LdapServer
- LDAP Server Class.
Code
public function search($base_dn = NULL, $filter, $attributes = [], $attrsonly = 0, $sizelimit = 0, $timelimit = 0, $deref = NULL, $scope = LDAP_SCOPE_SUBTREE) {
/**
* pagingation issues:
* -- see documentation queue: http://markmail.org/message/52w24iae3g43ikix#query:+page:1+mid:bez5vpl6smgzmymy+state:results
* -- wait for php 5.4? https://svn.php.net/repository/php/php-src/tags/php_5_4_0RC6/NEWS (ldap_control_paged_result
* -- http://sgehrig.wordpress.com/2009/11/06/reading-paged-ldap-results-with-php-is-a-show-stopper/
*/
if ($base_dn == NULL) {
if (count($this->basedn) == 1) {
$base_dn = $this->basedn[0];
}
else {
return FALSE;
}
}
$attr_display = is_array($attributes) ? join(',', $attributes) : 'none';
$query = 'ldap_search() call: ' . join(",\n", [
'base_dn: ' . $base_dn,
'filter = ' . $filter,
'attributes: ' . $attr_display,
'attrsonly = ' . $attrsonly,
'sizelimit = ' . $sizelimit,
'timelimit = ' . $timelimit,
'deref = ' . $deref,
'scope = ' . $scope,
]);
if ($this->detailed_watchdog_log) {
watchdog('ldap_servers', $query, []);
}
// When checking multiple servers, there's a chance we might not be connected yet.
if (!$this->connection) {
$this
->connect();
$this
->bind();
}
$ldap_query_params = [
'connection' => $this->connection,
'base_dn' => $base_dn,
'filter' => $filter,
'attributes' => $attributes,
'attrsonly' => $attrsonly,
'sizelimit' => $sizelimit,
'timelimit' => $timelimit,
'deref' => $deref,
'query_display' => $query,
'scope' => $scope,
];
if ($this->searchPagination && $this->paginationEnabled) {
$aggregated_entries = $this
->pagedLdapQuery($ldap_query_params);
return $aggregated_entries;
}
else {
$result = $this
->ldapQuery($scope, $ldap_query_params);
if ($result && $this
->countEntries($result) !== FALSE) {
$entries = ldap_get_entries($this->connection, $result);
drupal_alter('ldap_server_search_results', $entries, $ldap_query_params);
return is_array($entries) ? $entries : FALSE;
}
elseif ($this
->ldapErrorNumber()) {
$watchdog_tokens = [
'%basedn' => $ldap_query_params['base_dn'],
'%filter' => $ldap_query_params['filter'],
'%attributes' => print_r($ldap_query_params['attributes'], TRUE),
'%errmsg' => $this
->errorMsg('ldap'),
'%errno' => $this
->ldapErrorNumber(),
];
watchdog('ldap_servers', "LDAP ldap_search error. basedn: %basedn| filter: %filter| attributes:\n %attributes| errmsg: %errmsg| ldap err no: %errno|", $watchdog_tokens);
return FALSE;
}
else {
return FALSE;
}
}
}