function LdapServer::search in Lightweight Directory Access Protocol (LDAP) 7
Same name and namespace in other branches
- 8.2 ldap_servers/LdapServer.class.php \LdapServer::search()
- 7.2 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, or FALSE if the search is empty.
4 calls to LdapServer::search()
- LdapServer::deriveFromAttrGroupsResursive in ldap_servers/
LdapServer.class.php - not working yet will be ton of permission issues with service accounts need configurable obj type to avoid binding to a million user entries, printers, etc.
- LdapServer::deriveFromEntryGroups in ldap_servers/
LdapServer.class.php - return by reference groups/authorizations when groups are defined from entry
- LdapServer::groupsByEntryIsMember in ldap_servers/
LdapServer.class.php - looking at all members of a child group. only need to determine if member of one of the groups, doesn't matter which one.
- LdapServer::user_lookup in ldap_servers/
LdapServer.class.php - Queries LDAP server for the user.
1 method overrides LdapServer::search()
- LdapServerTest::search in ldap_servers/
tests/ LdapServerTest.class.php - Perform an LDAP search.
File
- ldap_servers/
LdapServer.class.php, line 312 - Defines server classes and related functions.
Class
- LdapServer
- LDAP Server Class
Code
function search($base_dn = NULL, $filter, $attributes = array(), $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", array(
'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_server', $query, array());
}
// When checking multiple servers, there's a chance we might not be connected yet.
if (!$this->connection) {
$this
->connect();
$this
->bind();
}
$ldap_query_params = array(
'connection' => $this->connection,
'base_dn' => $base_dn,
'filter' => $filter,
'attributes' => $attributes,
'attrsonly' => $attrsonly,
'sizelimit' => $sizelimit,
'timelimit' => $timelimit,
'deref' => $deref,
'query_display' => $query,
'scope' => $scope,
);
// dpm($ldap_query_params); dpm("searchPagination=" . $this->searchPagination .",paginationEnabled=". $this->paginationEnabled .", searchPageStart=" . $this->searchPageStart);
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 && ldap_count_entries($this->connection, $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 = array(
'%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', "LDAP ldap_search error. basedn: %basedn| filter: %filter| attributes:\n %attributes| errmsg: %errmsg| ldap err no: %errno|", $watchdog_tokens);
return FALSE;
}
else {
return FALSE;
}
}
}