本文整理汇总了PHP中ldap_control_paged_result函数的典型用法代码示例。如果您正苦于以下问题:PHP ldap_control_paged_result函数的具体用法?PHP ldap_control_paged_result怎么用?PHP ldap_control_paged_result使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ldap_control_paged_result函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadPage
protected function loadPage()
{
if (!ldap_control_paged_result($this->connection, $this->pageSize, true, $this->pageToken)) {
throw new SearchException("Unable to set paged control pageSize: " . $this->pageSize);
}
$search = ldap_search($this->connection, $this->baseDn, $this->filter, is_array($this->attributes) ? $this->attributes : []);
if (!$search) {
// Something went wrong in search
throw Connection::createLdapSearchException(ldap_errno($this->connection), $this->baseDn, $this->filter, $this->pageSize);
}
$this->entries = ldap_get_entries($this->connection, $search);
$this->entriesPosition = 0;
if (!$this->entries) {
throw Connection::createLdapSearchException(ldap_errno($this->connection), $this->baseDn, $this->filter, $this->pageSize);
}
// check if on first page
if (empty($this->pageToken)) {
$this->currentPage = 0;
} else {
$this->currentPage++;
}
// Ok go to next page
ldap_control_paged_result_response($this->connection, $search, $this->pageToken);
if (empty($this->pageToken)) {
$this->isLastPage = true;
}
}
示例2: getAvailableValues
public function getAvailableValues()
{
if (!empty($this->fields['values'])) {
$ldap_values = json_decode($this->fields['values']);
$ldap_dropdown = new RuleRightParameter();
if (!$ldap_dropdown->getFromDB($ldap_values->ldap_attribute)) {
return array();
}
$attribute = array($ldap_dropdown->fields['value']);
$config_ldap = new AuthLDAP();
if (!$config_ldap->getFromDB($ldap_values->ldap_auth)) {
return array();
}
if (!function_exists('warning_handler')) {
function warning_handler($errno, $errstr, $errfile, $errline, array $errcontext)
{
if (0 === error_reporting()) {
return false;
}
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
}
set_error_handler("warning_handler", E_WARNING);
try {
$tab_values = array();
$ds = $config_ldap->connect();
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
$cookie = '';
do {
if (AuthLDAP::isLdapPageSizeAvailable($config_ldap)) {
ldap_control_paged_result($ds, $config_ldap->fields['pagesize'], true, $cookie);
}
$result = ldap_search($ds, $config_ldap->fields['basedn'], $ldap_values->ldap_filter, $attribute);
$entries = ldap_get_entries($ds, $result);
array_shift($entries);
foreach ($entries as $id => $attr) {
if (isset($attr[$attribute[0]]) && !in_array($attr[$attribute[0]][0], $tab_values)) {
$tab_values[$id] = $attr[$attribute[0]][0];
}
}
if (AuthLDAP::isLdapPageSizeAvailable($config_ldap)) {
ldap_control_paged_result_response($ds, $result, $cookie);
}
} while ($cookie !== null && $cookie != '');
if ($this->fields['show_empty']) {
$tab_values = array('' => '-----') + $tab_values;
}
asort($tab_values);
return $tab_values;
} catch (Exception $e) {
return array();
}
restore_error_handler();
} else {
return array();
}
}
示例3: searchAll
/**
* Search LDAP registry for entries matching filter and optional attributes
* and return ALL values, including those beyond the usual 1000 entries, as an array.
*
* @param string $filter
* @param array $attributes -OPTIONAL
* @return array
* @throws Exception\LdapException
*/
public function searchAll($filter, array $attributes = [])
{
$ldap = $this->getResource();
// $ds is a valid link identifier (see ldap_connect)
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
$cookie = '';
$result = [];
do {
ldap_control_paged_result($ldap, self::PAGE_SIZE, true, $cookie);
Stdlib\ErrorHandler::start(E_WARNING);
$search = ldap_search($ldap, $this->getBaseDn(), $filter, $attributes);
Stdlib\ErrorHandler::stop();
if ($search === false) {
throw new Lp\Exception\LdapException($this, 'searching: ' . $filter);
}
$entries = $this->createCollection(new Lp\Collection\DefaultIterator($this, $search), null);
foreach ($entries as $es) {
$result[] = $es;
}
ldap_control_paged_result_response($ldap, $search, $cookie);
} while ($cookie !== null && $cookie != '');
return $result;
}
示例4: controlPagedResult
/**
* Send LDAP pagination control.
*
* @param int $pageSize
* @param bool $isCritical
* @param string $cookie
*
* @return bool
*
* @throws AdldapException
*/
public function controlPagedResult($pageSize = 1000, $isCritical = false, $cookie = '')
{
if ($this->isPagingSupported()) {
if ($this->suppressErrors) {
return @ldap_control_paged_result($this->getConnection(), $pageSize, $isCritical, $cookie);
}
return ldap_control_paged_result($this->getConnection(), $pageSize, $isCritical, $cookie);
}
$message = 'LDAP Pagination is not supported on your current PHP installation.';
throw new AdldapException($message);
}
示例5: getGroupsFromLDAP
/**
* @since version 0.84 new parameter $limitexceeded
*
* @param $ldap_connection
* @param $config_ldap
* @param $filter
* @param $search_in_groups (true by default)
* @param $groups array
* @param $limitexceeded
**/
static function getGroupsFromLDAP($ldap_connection, $config_ldap, $filter, $search_in_groups = true, $groups = array(), &$limitexceeded)
{
global $DB;
//First look for groups in group objects
$extra_attribute = $search_in_groups ? "cn" : $config_ldap->fields["group_field"];
$attrs = array("dn", $extra_attribute);
if ($filter == '') {
if ($search_in_groups) {
$filter = !empty($config_ldap->fields['group_condition']) ? $config_ldap->fields['group_condition'] : "(objectclass=*)";
} else {
$filter = !empty($config_ldap->fields['condition']) ? $config_ldap->fields['condition'] : "(objectclass=*)";
}
}
$cookie = '';
$count = 0;
do {
if (self::isLdapPageSizeAvailable($config_ldap)) {
ldap_control_paged_result($ldap_connection, $config_ldap->fields['pagesize'], true, $cookie);
}
$filter = Toolbox::unclean_cross_side_scripting_deep($filter);
$sr = @ldap_search($ldap_connection, $config_ldap->fields['basedn'], $filter, $attrs);
if ($sr) {
if (in_array(ldap_errno($ldap_connection), array(4, 11))) {
// openldap return 4 for Size limit exceeded
$limitexceeded = true;
}
$infos = self::get_entries_clean($ldap_connection, $sr);
if (in_array(ldap_errno($ldap_connection), array(4, 11))) {
// openldap return 4 for Size limit exceeded
$limitexceeded = true;
}
$count += $infos['count'];
//If page results are enabled and the number of results is greater than the maximum allowed
//warn user that limit is exceeded and stop search
if (self::isLdapPageSizeAvailable($config_ldap) && $config_ldap->fields['ldap_maxlimit'] && $count > $config_ldap->fields['ldap_maxlimit']) {
$limitexceeded = true;
break;
}
for ($ligne = 0; $ligne < $infos["count"]; $ligne++) {
if ($search_in_groups) {
// No cn : not a real object
if (isset($infos[$ligne]["cn"][0])) {
$cn = $infos[$ligne]["cn"][0];
$groups[$infos[$ligne]["dn"]] = array("cn" => $infos[$ligne]["cn"][0], "search_type" => "groups");
}
} else {
if (isset($infos[$ligne][$extra_attribute])) {
if ($config_ldap->fields["group_field"] == 'dn' || in_array('ou', $groups)) {
$dn = $infos[$ligne][$extra_attribute];
$ou = array();
for ($tmp = $dn; count($tmptab = explode(',', $tmp, 2)) == 2; $tmp = $tmptab[1]) {
$ou[] = $tmptab[1];
}
/// Search in DB for group with ldap_group_dn
if ($config_ldap->fields["group_field"] == 'dn' && count($ou) > 0) {
$query = "SELECT `ldap_value`\n FROM `glpi_groups`\n WHERE `ldap_group_dn`\n IN ('" . implode("', '", Toolbox::addslashes_deep($ou)) . "')";
foreach ($DB->request($query) as $group) {
$groups[$group['ldap_value']] = array("cn" => $group['ldap_value'], "search_type" => "users");
}
}
} else {
for ($ligne_extra = 0; $ligne_extra < $infos[$ligne][$extra_attribute]["count"]; $ligne_extra++) {
$groups[$infos[$ligne][$extra_attribute][$ligne_extra]] = array("cn" => self::getGroupCNByDn($ldap_connection, $infos[$ligne][$extra_attribute][$ligne_extra]), "search_type" => "users");
}
}
}
}
}
}
if (self::isLdapPageSizeAvailable($config_ldap)) {
ldap_control_paged_result_response($ldap_connection, $sr, $cookie);
}
} while ($cookie !== null && $cookie != '');
return $groups;
}
示例6: ldap_mod_del
$dn = "cn=groupname,cn=groups,dc=example,dc=com";
echo "\nModDel " . $dn;
$entry['memberuid'] = "username";
ldap_mod_del($ds, $dn, $entry);
/* #### MOD REPLACE ### */
$dn = "cn=groupname,cn=groups,dc=example,dc=com";
echo "\nModReplace " . $dn;
$entry['memberuid'] = "username";
ldap_mod_replace($ds, $dn, $entry);
/* ### SEARCH ### */
$dn = "o=My Company, c=USs";
echo "\nSearch " . $dn;
$filter = "(|(sn=jeantet)(givenname=jeantet*))";
$justthese = array("ou", "sn", "givenname", "mail");
$cookie = 'cookie';
ldap_control_paged_result($ds, 23, true, $cookie);
$sr = ldap_search($ds, $dn, $filter, $justthese);
$info = ldap_get_entries($ds, $sr);
echo "\n\t" . $info["count"] . " entries returned";
// ldap_control_paged_result_response($ds, $sr, $cookie);
/* ### COMPARE ### */
$dn = "cn=Matti Meikku, ou=My Unit, o=My Company, c=FI";
echo "\nCompare " . $dn;
// Préparation des données
$value = "secretpassword";
$attr = "password";
// Comparaison des valeurs
$r = ldap_compare($ds, $dn, $attr, $value);
if ($r === -1) {
echo "Error: " . ldap_error($ds);
} elseif ($r === true) {
示例7: checkBeforeSave
/**
* Validate form fields before add or update a question
*
* @param Array $input Datas used to add the item
*
* @return Array The modified $input array
*
* @param [type] $input [description]
* @return [type] [description]
*/
private function checkBeforeSave($input)
{
// Control fields values :
// - name is required
if (empty($input['name'])) {
Session::addMessageAfterRedirect(__('The title is required', 'formcreator'), false, ERROR);
return array();
}
// - field type is required
if (empty($input['fieldtype'])) {
Session::addMessageAfterRedirect(__('The field type is required', 'formcreator'), false, ERROR);
return array();
}
// - section is required
if (empty($input['plugin_formcreator_sections_id'])) {
Session::addMessageAfterRedirect(__('The section is required', 'formcreator'), false, ERROR);
return array();
}
// Values are required for GLPI dropdowns, dropdowns, multiple dropdowns, checkboxes, radios, LDAP
$itemtypes = array('select', 'multiselect', 'checkboxes', 'radios', 'ldap');
if (empty($input['values']) && in_array($input['fieldtype'], $itemtypes)) {
Session::addMessageAfterRedirect(__('The field value is required:', 'formcreator') . ' ' . $input['name'], false, ERROR);
return array();
}
// Fields are differents for dropdown lists, so we need to replace these values into the good ones
if ($input['fieldtype'] == 'dropdown') {
if (empty($input['dropdown_values'])) {
Session::addMessageAfterRedirect(__('The field value is required:', 'formcreator') . ' ' . $input['name'], false, ERROR);
return array();
}
$input['values'] = $input['dropdown_values'];
$input['default_values'] = isset($input['dropdown_default_value']) ? $input['dropdown_default_value'] : '';
}
// Fields are differents for GLPI object lists, so we need to replace these values into the good ones
if ($input['fieldtype'] == 'glpiselect') {
if (empty($input['glpi_objects'])) {
Session::addMessageAfterRedirect(__('The field value is required:', 'formcreator') . ' ' . $input['name'], false, ERROR);
return array();
}
$input['values'] = $input['glpi_objects'];
$input['default_values'] = isset($input['dropdown_default_value']) ? $input['dropdown_default_value'] : '';
}
// A description field should have a description
if ($input['fieldtype'] == 'description' && empty($input['description'])) {
Session::addMessageAfterRedirect(__('A description field should have a description:', 'formcreator') . ' ' . $input['name'], false, ERROR);
return array();
}
// format values for numbers
if ($input['fieldtype'] == 'integer' || $input['fieldtype'] == 'float') {
$input['default_values'] = !empty($input['default_values']) ? (double) str_replace(',', '.', $input['default_values']) : null;
$input['range_min'] = !empty($input['range_min']) ? (double) str_replace(',', '.', $input['range_min']) : null;
$input['range_max'] = !empty($input['range_max']) ? (double) str_replace(',', '.', $input['range_max']) : null;
}
// LDAP fields validation
if ($input['fieldtype'] == 'ldapselect') {
// Fields are differents for dropdown lists, so we need to replace these values into the good ones
if (!empty($input['ldap_auth'])) {
$config_ldap = new AuthLDAP();
$config_ldap->getFromDB($input['ldap_auth']);
$ldap_dropdown = new RuleRightParameter();
$ldap_dropdown->getFromDB($input['ldap_attribute']);
$attribute = array($ldap_dropdown->fields['value']);
// Set specific error handler too catch LDAP errors
if (!function_exists('warning_handler')) {
function warning_handler($errno, $errstr, $errfile, $errline, array $errcontext)
{
if (0 === error_reporting()) {
return false;
}
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
}
set_error_handler("warning_handler", E_WARNING);
try {
$ds = $config_ldap->connect();
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_control_paged_result($ds, 1);
$sn = ldap_search($ds, $config_ldap->fields['basedn'], $input['ldap_filter'], $attribute);
$entries = ldap_get_entries($ds, $sn);
} catch (Exception $e) {
Session::addMessageAfterRedirect(__('Cannot recover LDAP informations!', 'formcreator'), false, ERROR);
}
restore_error_handler();
$input['values'] = json_encode(array('ldap_auth' => $input['ldap_auth'], 'ldap_filter' => $input['ldap_filter'], 'ldap_attribute' => strtolower($input['ldap_attribute'])));
}
}
// Add leading and trailing regex marker automaticaly
if (!empty($input['regex'])) {
if (substr($input['regex'], 0, 1) != '/') {
if (substr($input['regex'], 0, 1) != '^') {
//.........这里部分代码省略.........
示例8: searchRaw
public function searchRaw($search = "*")
{
if (!$this->adldap->getLdapBind()) {
return false;
}
// Perform the search and grab all their details
$filter = "(&(objectClass=user)(samaccounttype=" . adLDAP::ADLDAP_NORMAL_ACCOUNT . ")(objectCategory=person)(cn=" . $search . "))";
$fields = array("samaccountname", "displayname");
$pageSize = 25;
$cookie = '';
ldap_control_paged_result($this->adldap->getLdapConnection(), $pageSize, true, $cookie);
$sr = ldap_search($this->adldap->getLdapConnection(), $this->adldap->getBaseDn(), $filter, $fields);
$entries = ldap_get_entries($this->adldap->getLdapConnection(), $sr);
ldap_control_paged_result_response($this->adldap->getLdapConnection(), $sr, $cookie);
$return = [];
foreach ($entries as $k => $r) {
$comp = explode(",", $r['dn']);
$cn = '';
$ou = '';
$dc = '';
foreach ($comp as $c) {
$x = explode("=", "{$c}");
switch ($x[0]) {
case 'CN':
$cn = $x[1];
break;
case 'OU':
$ou = $x[1];
break;
case 'DC':
$dc .= $x[1] . ".";
break;
}
}
if (count($r['samaccountname']) == 0) {
continue;
}
$return[] = ['fullname' => isset($r['displayname']) ? @$r['displayname'][0] : @$r['samaccountname'][0], 'username' => @$r['samaccountname'][0], 'cn' => $cn, 'dc' => $dc, 'ou' => $ou];
}
return $return;
}
示例9: resetPagingControl
/**
* Resets the paging control so that read operations work after a paging operation is used.
*
* @throws LdapConnectionException
*/
public function resetPagingControl()
{
// Per RFC 2696, to abandon a paged search you should send a size of 0 along with the cookie used in the search.
// However, testing this it doesn't seem to completely work. Perhaps a PHP bug?
if (!@ldap_control_paged_result($this->connection->getConnection(), 0, false, $this->cookie)) {
throw new LdapConnectionException(sprintf('Unable to reset paged results control for read operation: %s', $this->connection->getLastError()));
}
}
示例10: controlPagedResult
/**
* @link http://php.net/manual/en/function.ldap-control-paged-result.php
* @param $link
* @param $pagesize
* @param bool $iscritical
* @param string $cookie
* @return bool
*/
public function controlPagedResult($link, $pagesize, $iscritical = false, $cookie = "")
{
return ldap_control_paged_result($link, $pagesize, $iscritical, $cookie);
}
示例11: setControlPagedResult
/**
* Send LDAP pagination control.
* @param int $pageSize
* @param bool $isCritical
* @param string $cookie
* @return bool
*/
public function setControlPagedResult($cookie)
{
return ldap_control_paged_result($this->resource, $this->pageSize, false, $cookie);
}
示例12: ldap
public function ldap()
{
set_time_limit(0);
//$this->db->query("truncate px_tmp");
$host = "192.168.5.3";
$user = "zldcgroup\\zldc";
$pswd = "zldc@8888";
$cookie = '';
$result = [];
$result['count'] = 0;
do {
$ad = ldap_connect($host) or die("Could not connect!");
//var_dump($ad);
if ($ad) {
//璁剧疆鍙傛暟
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ad, LDAP_OPT_REFERRALS, 0);
// bool ldap_bind ( resource $link_identifier [, string $bind_rdn = NULL [, string $bind_password = NULL ]] )
$bd = ldap_bind($ad, $user, $pswd) or die("Could not bind");
ldap_control_paged_result($ad, 500, true, $cookie);
$attrs = array("displayname", "name", "sAMAccountName", "userPrincipalName", "objectclass");
//鎸囧畾闇�鏌ヨ鐨勭敤鎴疯寖鍥�
$filter = "(objectclass=*)";
//ldap_search ( resource $link_identifier , string $base_dn , string $filter [, array $attributes [, int $attrsonly [, int $sizelimit [, int $timelimit [, int $deref ]]]]] )
$search = ldap_search($ad, 'ou=中梁集团,DC=zldcgroup,DC=com', $filter, $attrs, 0, 0, 0) or die("ldap search failed");
$entries = ldap_get_entries($ad, $search);
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3);
$result = array_merge($result, $entries);
ldap_control_paged_result_response($ad, $search, $cookie);
//echo json_encode($entries);
// var_dump($entries);
$data = array();
if ($entries["count"] > 0) {
//echo '返回记录数:'.$entries["count"];
for ($i = 0; $i < $entries["count"]; $i++) {
//所要获取的字段,都必须小写
//if(isset($entries[$i]["displayname"])){
// echo "<p>name: ".$entries[$i]["name"][0]."<br />";//用户名
// echo "<p>sAMAccountName: ".@$entries[$i]["samaccountname"][0]."<br />";//用户名
if (isset($entries[$i]["dn"][0])) {
// echo "dn: ".$entries[$i]["dn"]."<br />";//用户名字
$is_user = in_array('user', $entries[$i]["objectclass"]) ? 1 : 0;
if ($is_user == 0) {
continue;
}
$dn = $entries[$i]["dn"];
$dn = explode(",", $dn);
$area = array();
foreach ($dn as $v) {
if (strpos($v, 'OU=') !== false) {
array_push($area, str_replace("OU=", "", $v));
//有的抬头不是OU
} else {
if (strpos($v, 'CN=') !== false) {
array_push($area, str_replace("CN=", "", $v));
//有的抬头不是CN
} else {
if (strpos($v, 'DC=') !== false) {
array_push($area, str_replace("DC=", "", $v));
//有的抬头不是DC
}
}
}
}
$area = array_reverse($area);
$insertArr = array();
$flag = 1;
if (is_array($area)) {
$flag = count($area, COUNT_NORMAL);
}
// var_dump($area);
// list($f6,$f5,$f4,$f3,$f2,$f1) = $area;
foreach ($area as $val) {
$keyStr = 'F' . $flag;
$flag--;
$insertArr[$keyStr] = $val;
}
$insertArr['FISUSER'] = 1;
$insertArr['FNUMBER'] = $entries[$i]["samaccountname"][0];
$insertArr['FNAME'] = $entries[$i]["name"][0];
$insertArr['FORG'] = 'test';
if (is_array($area)) {
if (count($area, COUNT_NORMAL) >= 7) {
//echo "test 5 ";
}
}
$where = 'FNUMBER = ' . $entries[$i]["samaccountname"][0];
$tableName = 'T_USER';
$this->db->select('*');
$this->db->where('FNUMBER', $entries[$i]["samaccountname"][0]);
$row = $this->db->get('T_USER')->row_array();
if (isset($row)) {
$result = $this->Tools->updateDataWithFID($insertArr, $tableName, $row['FID']);
} else {
$result = $this->Tools->addData($insertArr, $tableName);
}
}
}
//}
} else {
//.........这里部分代码省略.........
示例13: group_info
/**
* Group Information. Returns an array of information about a group.
* The group name is case sensitive
*
* @param string $group_name The group name to retrieve info about
* @param array $fields Fields to retrieve
* @return array
*/
public function group_info($group_name, $fields = NULL)
{
if ($group_name === NULL) {
return false;
}
if (!$this->_bind) {
return false;
}
if (stristr($group_name, '+')) {
$group_name = stripslashes($group_name);
}
$filter = "(&(objectCategory=group)(name=" . $this->ldap_slashes($group_name) . "))";
//echo ($filter."!!!<br>");
if ($fields === NULL) {
$fields = array("member", "memberof", "cn", "description", "distinguishedname", "objectcategory", "samaccountname");
}
// Let's use paging if available
if (function_exists('ldap_control_paged_result')) {
$pageSize = 500;
$cookie = '';
$entries = array();
$entries_page = array();
do {
ldap_control_paged_result($this->_conn, $pageSize, true, $cookie);
$sr = ldap_search($this->_conn, $this->_base_dn, $filter, $fields);
$entries_page = ldap_get_entries($this->_conn, $sr);
if (!is_array($entries_page)) {
return false;
}
$entries = array_merge($entries, $entries_page);
ldap_control_paged_result_response($this->_conn, $sr, $cookie);
} while ($cookie !== null && $cookie != '');
$entries['count'] = count($entries) - 1;
// Set a new count value !important!
ldap_control_paged_result($this->_conn, $pageSize, true, $cookie);
// RESET is important
} else {
// Non-Paged version
$sr = ldap_search($this->_conn, $this->_base_dn, $filter, $fields);
$entries = ldap_get_entries($this->_conn, $sr);
}
//print_r($entries);
return $entries;
}
示例14: initPagedSearch
/**
* @brief prepares a paged search, if possible
* @param $filter the LDAP filter for the search
* @param $base the LDAP subtree that shall be searched
* @param $attr optional, when a certain attribute shall be filtered outside
* @param $limit
* @param $offset
*
*/
private function initPagedSearch($filter, $base, $attr, $limit, $offset)
{
$pagedSearchOK = false;
if ($this->connection->hasPagedResultSupport && !is_null($limit)) {
$offset = intval($offset);
//can be null
\OCP\Util::writeLog('user_ldap', 'initializing paged search for Filter' . $filter . ' base ' . $base . ' attr ' . print_r($attr, true) . ' limit ' . $limit . ' offset ' . $offset, \OCP\Util::DEBUG);
//get the cookie from the search for the previous search, required by LDAP
$cookie = $this->getPagedResultCookie($filter, $limit, $offset);
if (empty($cookie) && $offset > 0) {
//no cookie known, although the offset is not 0. Maybe cache run out. We need to start all over *sigh* (btw, Dear Reader, did you need LDAP paged searching was designed by MSFT?)
$reOffset = $offset - $limit < 0 ? 0 : $offset - $limit;
//a bit recursive, $offset of 0 is the exit
\OCP\Util::writeLog('user_ldap', 'Looking for cookie L/O ' . $limit . '/' . $reOffset, \OCP\Util::INFO);
$this->search($filter, $base, $attr, $limit, $reOffset, true);
$cookie = $this->getPagedResultCookie($filter, $limit, $offset);
//still no cookie? obviously, the server does not like us. Let's skip paging efforts.
//TODO: remember this, probably does not change in the next request...
if (empty($cookie)) {
$cookie = null;
}
}
if (!is_null($cookie)) {
if ($offset > 0) {
\OCP\Util::writeLog('user_ldap', 'Cookie ' . $cookie, \OCP\Util::INFO);
}
$pagedSearchOK = ldap_control_paged_result($this->connection->getConnectionResource(), $limit, false, $cookie);
\OCP\Util::writeLog('user_ldap', 'Ready for a paged search', \OCP\Util::INFO);
} else {
\OCP\Util::writeLog('user_ldap', 'No paged search for us, Cpt., Limit ' . $limit . ' Offset ' . $offset, \OCP\Util::INFO);
}
}
return $pagedSearchOK;
}
示例15: retrieve
/**
* The core of ORM behavior for this bundle: retrieve data
* from LDAP and convert results into objects.
*
* Options maybe:
*
* attributes (array): array of attribute types (strings)
*
* filter (LdapFilter): a filter array or a correctly formatted filter string
*
* max (integer): the maximum limit of entries to return
*
* searchDn (string): the search DN
*
* subentryNodes (array): parameters for the left hand side of a searchDN, useful for mining subentries.
*
* pageSize (integer): employ pagination and return pages of the given size
*
* pageCookie (opaque): The opaque stucture sent by the LDAP server to maintain pagination state. Default is empty string.
*
* pageCritical (boolean): if pagination employed, force paging and return no results on service which do not provide it. Default is true.
*
* checkOnly (boolean): Only check result existence; don't convert search results to Symfony entities. Default is false.
*
* @param string $entityName
* @param array $options
* @return array
* @throws MissingSearchDnException
*/
public function retrieve($entityName, $options = array())
{
$paging = !empty($options['pageSize']);
$instanceMetadataCollection = $this->getClassMetadata($entityName);
// Discern max result size
$max = empty($options['max']) ? self::DEFAULT_MAX_RESULT_COUNT : $options['max'];
// Employ results paging if requested with pageSize option
if ($paging) {
if (!isset($options['pageCritical'])) {
$options['pageCritical'] = FALSE;
}
if (isset($options['pageCookie'])) {
$this->pageCookie = $options['pageCookie'];
}
ldap_control_paged_result($this->client->getLdapResource(), $options['pageSize'], $options['pageCritical'], $this->pageCookie);
}
// Discern subentryNodes for substituing into searchDN
$subentryNodes = empty($options['subentryNodes']) ? array() : $options['subentryNodes'];
// Discern search DN
if (isset($options['searchDn'])) {
$searchDn = $options['searchDn'];
} else {
$searchDn = $instanceMetadataCollection->getSearchDn();
}
if (empty($searchDn)) {
throw new MissingSearchDnException('Could not discern search DN while searching for ' . $entityName);
}
// Discern LDAP filter
$objectClass = $instanceMetadataCollection->getObjectClass();
if (empty($options['filter'])) {
$filter = '(objectClass=' . $objectClass . ')';
} else {
if (is_array($options['filter'])) {
$options['filter'] = array('&' => array('objectClass' => $objectClass, $options['filter']));
$ldapFilter = new LdapFilter($options['filter']);
$filter = $ldapFilter->format();
} else {
if (is_a($options['filter'], LdapFilter::class)) {
$options['filter']->setFilterArray(array('&' => array('objectClass' => $objectClass, $options['filter']->getFilterArray())));
$filter = $options['filter']->format();
} else {
// assume pre-formatted scale/string filter value
$filter = '(&(objectClass=' . $objectClass . ')' . $options['filter'] . ')';
}
}
}
// Discern attributes to retrieve
if (empty($options['attributes'])) {
$attributes = array_values($instanceMetadataCollection->getMetadatas());
} else {
$attributes = $options['attributes'];
}
// Search LDAP
$searchResult = $this->doRawLdapSearch($filter, $attributes, $max, $searchDn);
$entries = @ldap_get_entries($this->client->getLdapResource(), $searchResult);
if (!empty($options['checkOnly']) && $options['checkOnly'] == true) {
return $entries['count'] > 0;
}
$entities = array();
foreach ($entries as $entry) {
if (is_array($entry)) {
$entities[] = $this->entryToEntity($entityName, $entry);
}
}
if ($paging) {
ldap_control_paged_result_response($this->client->getLdapResource(), $searchResult, $this->pageCookie);
$this->pageMore = !empty($this->pageCookie);
}
if ($entries['count'] == 1) {
return $entities[0];
}
//.........这里部分代码省略.........