当前位置: 首页>>代码示例>>PHP>>正文


PHP ldap_control_paged_result_response函数代码示例

本文整理汇总了PHP中ldap_control_paged_result_response函数的典型用法代码示例。如果您正苦于以下问题:PHP ldap_control_paged_result_response函数的具体用法?PHP ldap_control_paged_result_response怎么用?PHP ldap_control_paged_result_response使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ldap_control_paged_result_response函数的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;
     }
 }
开发者ID:81square,项目名称:ldap,代码行数:27,代码来源:SearchIterator.php

示例2: controlPagedResultResponse

 /**
  * @param LDAP $link
  * @param LDAP $result
  * @param string $cookie
  * @return bool|LDAP
  */
 public function controlPagedResultResponse($link, $result, &$cookie)
 {
     $this->preFunctionCall('ldap_control_paged_result_response', array($link, $result, $cookie));
     $result = ldap_control_paged_result_response($link, $result, $cookie);
     $this->postFunctionCall();
     return $result;
 }
开发者ID:Kevin-ZK,项目名称:vaneDisk,代码行数:13,代码来源:ldap.php

示例3: controlPagedResult

 /**
  * @param int $estimated
  * @return string
  * @throws PaginationFailureException
  */
 public function controlPagedResult(&$estimated = null)
 {
     if (!ldap_control_paged_result_response($this->link, $this->result, $cookie, $estimated)) {
         throw new PaginationFailureException(ldap_error($this->link), ldap_errno($this->link));
     }
     return $cookie;
 }
开发者ID:daverandom,项目名称:ldapi,代码行数:12,代码来源:ResultSet.php

示例4: 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();
     }
 }
开发者ID:CHCI74,项目名称:formcreator,代码行数:57,代码来源:ldapselect-field.class.php

示例5: pagedResultResponse

 /**
  * Retrieve the LDAP pagination cookie
  *
  * @param  string       $key    Optionally return only one of the keys: 'cookie' or 'estimated'
  * @return array|mixed          Array with two keys: 'cookie' and 'estimated' or, if `$key` was
  *                              specified, returns the value of only that key
  */
 public function pagedResultResponse($key = null)
 {
     $cookie = null;
     $estimated = null;
     @ldap_control_paged_result_response($this->link, $this->resource, $cookie, $estimated);
     switch ($key) {
         case 'cookie':
             return $cookie;
         case 'estimated':
             return $estimated;
         default:
             return ['cookie' => $cookie, 'estimated' => $estimated];
     }
 }
开发者ID:dreamscapes,项目名称:ldap-core,代码行数:21,代码来源:Result.php

示例6: __construct

 public function __construct(Ldap $link, $result = null)
 {
     $this->result = $result;
     if (is_resource($result)) {
         // Get the status code, matched DN and referrals from the response
         ldap_parse_result($link->resource(), $result, $this->code, $this->matchedDN, $this->message, $this->referrals);
         // Get the string representation of the status code
         $this->message = ldap_err2str($this->code);
         // Extract the data from the resource
         $this->data = ldap_get_entries($link->resource(), $result);
         $this->data = $this->cleanup_result($this->data);
         // Remove the referrals array if there's nothing inside
         count($this->referrals) == 0 && ($this->referrals = null);
         // Try to extract pagination cookie and estimated number of objects to be returned
         // Since there's no way to tell if pagination has been enabled or not, I am suppressing php errors
         @ldap_control_paged_result_response($link->resource(), $result, $this->cookie, $this->estimated);
     } else {
         $this->code = ldap_errno($link->resource());
         $this->message = ldap_error($link->resource());
     }
     // Active Directory conceals some additional error codes in the ErrorMessage of the response
     // that we cannot get to with ldap_errno() in authentication failures - let's try to
     // extract them!
     if ($this->code == 49) {
         $message = null;
         ldap_get_option($link->resource(), Option::ErrorString, $message);
         if (stripos($message, 'AcceptSecurityContext') !== false) {
             $message = explode(', ', $message);
             end($message);
             $message = prev($message);
             $this->code = explode(' ', $message)[1];
             // For compatibility reasons with standard ldap, if the error code
             // is 52e let's replace it with 49 ( their meanings are equal, it's just
             // Microsoft doing it its own way again )
             if ($this->code == '52e') {
                 $this->code = ResponseCode::InvalidCredentials;
             }
         }
     }
 }
开发者ID:alaneor,项目名称:ldap,代码行数:40,代码来源:Response.php

示例7: 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;
 }
开发者ID:diskerror,项目名称:utilities,代码行数:32,代码来源:Ldap.php

示例8: findLdapUsers

 /**
  * Searches LDAP
  *
  * @author [A. Gianotto] [<snipe@snipe.net>]
  * @since [v3.0]
  * @param $ldapatttibutes
  * @return array|bool
  */
 static function findLdapUsers()
 {
     $ldapconn = Ldap::connectToLdap();
     $ldap_bind = Ldap::bindAdminToLdap($ldapconn);
     $base_dn = Setting::getSettings()->ldap_basedn;
     $filter = Setting::getSettings()->ldap_filter;
     // Set up LDAP pagination for very large databases
     // @author Richard Hofman
     $page_size = 500;
     $cookie = '';
     $result_set = array();
     $global_count = 0;
     // Perform the search
     do {
         // Paginate (non-critical, if not supported by server)
         ldap_control_paged_result($ldapconn, $page_size, false, $cookie);
         $search_results = ldap_search($ldapconn, $base_dn, '(' . $filter . ')');
         if (!$search_results) {
             return redirect()->route('users')->with('error', trans('admin/users/message.error.ldap_could_not_search') . ldap_error($ldapconn));
         }
         // Get results from page
         $results = ldap_get_entries($ldapconn, $search_results);
         if (!$results) {
             return redirect()->route('users')->with('error', trans('admin/users/message.error.ldap_could_not_get_entries') . ldap_error($ldapconn));
         }
         // Add results to result set
         $global_count += $results['count'];
         $result_set = array_merge($result_set, $results);
         ldap_control_paged_result_response($ldapconn, $search_results, $cookie);
     } while ($cookie !== null && $cookie != '');
     // Clean up after search
     $result_set['count'] = $global_count;
     $results = $result_set;
     ldap_control_paged_result($ldapconn, 0);
     return $results;
 }
开发者ID:jbirdkerr,项目名称:snipe-it,代码行数:44,代码来源:Ldap.php

示例9: ldap_control_paged_result_response

 /**
  * Wrapper function for ldap_control_paged_result_response().
  *
  * @param resource $link
  *   An LDAP link identifier.
  * @param resouce $result
  *   An LDAP search result identifier.
  * @param string $cookie
  *   An opaque structure sent by the server.
  * @param int $estimated
  *   The estimated number of entries to retrieve.
  *
  * @return boolean
  *   TRUE on success.
  *
  * @throw SimpleLdapException
  */
 public static function ldap_control_paged_result_response($link, $result, &$cookie = NULL, &$estimated = NULL)
 {
     // Devel debugging.
     if (variable_get('simple_ldap_devel', FALSE)) {
         dpm(__FUNCTION__);
         dpm(array('$result' => $result, '$cookie' => $cookie, '$estimated' => $estimated));
     }
     // Wrapped function call.
     $return = @ldap_control_paged_result_response($link, $result, $cookie, $estimated);
     // Debugging.
     if (variable_get('simple_ldap_debug', FALSE)) {
         $message = __FUNCTION__ . '($link = @link, $result = @result, $cookie = @cookie, $estimated = @estimated) returns @return';
         $variables = array('@link' => print_r($link, TRUE), '@result' => print_r($result, TRUE), '@cookie' => print_r($cookie, TRUE), '@estimated' => print_r($estimated, TRUE), '@return' => print_r($return, TRUE));
         watchdog('simple_ldap', $message, $variables, WATCHDOG_DEBUG);
     }
     return $return;
 }
开发者ID:vidiecan,项目名称:drupal_simple_ldap,代码行数:34,代码来源:SimpleLdap.class.php

示例10: controlPagedResultResponse

 /**
  * Retrieve a paginated result response.
  *
  * @param resource $result
  * @paaram string $cookie
  *
  * @return bool
  *
  * @throws AdldapException
  */
 public function controlPagedResultResponse($result, &$cookie)
 {
     if ($this->isPagingSupported()) {
         if ($this->suppressErrors) {
             return @ldap_control_paged_result_response($this->getConnection(), $result, $cookie);
         }
         return ldap_control_paged_result_response($this->getConnection(), $result, $cookie);
     }
     $message = 'LDAP Pagination is not supported on your current PHP installation.';
     throw new AdldapException($message);
 }
开发者ID:HarkiratGhotra,项目名称:application,代码行数:21,代码来源:Ldap.php

示例11: 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;
 }
开发者ID:euqip,项目名称:glpi-smartcities,代码行数:85,代码来源:authldap.class.php

示例12: 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;
 }
开发者ID:reggi49,项目名称:plansys,代码行数:41,代码来源:adLDAPUsers.php

示例13: 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 {
//.........这里部分代码省略.........
开发者ID:hardcao,项目名称:CiProject,代码行数:101,代码来源:Ldap.php

示例14: 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;
 }
开发者ID:kc596,项目名称:cse.nits.ac.in,代码行数:52,代码来源:adLDAP.php

示例15: search

 /**
  * @brief executes an LDAP search
  * @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 out
  * @returns array with the search result
  *
  * Executes an LDAP search
  */
 private function search($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false)
 {
     if (!is_null($attr) && !is_array($attr)) {
         $attr = array(mb_strtolower($attr, 'UTF-8'));
     }
     // See if we have a resource, in case not cancel with message
     $link_resource = $this->connection->getConnectionResource();
     if (!is_resource($link_resource)) {
         // Seems like we didn't find any resource.
         // Return an empty array just like before.
         \OCP\Util::writeLog('user_ldap', 'Could not search, because resource is missing.', \OCP\Util::DEBUG);
         return array();
     }
     //check wether paged search should be attempted
     $pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, $limit, $offset);
     $sr = ldap_search($link_resource, $base, $filter, $attr);
     if (!$sr) {
         \OCP\Util::writeLog('user_ldap', 'Error when searching: ' . ldap_error($link_resource) . ' code ' . ldap_errno($link_resource), \OCP\Util::ERROR);
         \OCP\Util::writeLog('user_ldap', 'Attempt for Paging?  ' . print_r($pagedSearchOK, true), \OCP\Util::ERROR);
         return array();
     }
     $findings = ldap_get_entries($link_resource, $sr);
     if ($pagedSearchOK) {
         \OCP\Util::writeLog('user_ldap', 'Paged search successful', \OCP\Util::INFO);
         ldap_control_paged_result_response($link_resource, $sr, $cookie);
         \OCP\Util::writeLog('user_ldap', 'Set paged search cookie ' . $cookie, \OCP\Util::INFO);
         $this->setPagedResultCookie($filter, $limit, $offset, $cookie);
         //browsing through prior pages to get the cookie for the new one
         if ($skipHandling) {
             return;
         }
         //if count is bigger, then the server does not support paged search. Instead, he did a normal search. We set a flag here, so the callee knows how to deal with it.
         if ($findings['count'] <= $limit) {
             $this->pagedSearchedSuccessful = true;
         }
     } else {
         \OCP\Util::writeLog('user_ldap', 'Paged search failed :(', \OCP\Util::INFO);
     }
     // if we're here, probably no connection resource is returned.
     // to make ownCloud behave nicely, we simply give back an empty array.
     if (is_null($findings)) {
         return array();
     }
     if (!is_null($attr)) {
         $selection = array();
         $multiarray = false;
         if (count($attr) > 1) {
             $multiarray = true;
             $i = 0;
         }
         foreach ($findings as $item) {
             if (!is_array($item)) {
                 continue;
             }
             $item = \OCP\Util::mb_array_change_key_case($item, MB_CASE_LOWER, 'UTF-8');
             if ($multiarray) {
                 foreach ($attr as $key) {
                     $key = mb_strtolower($key, 'UTF-8');
                     if (isset($item[$key])) {
                         if ($key != 'dn') {
                             $selection[$i][$key] = $this->resemblesDN($key) ? $this->sanitizeDN($item[$key][0]) : $item[$key][0];
                         } else {
                             $selection[$i][$key] = $this->sanitizeDN($item[$key]);
                         }
                     }
                 }
                 $i++;
             } else {
                 //tribute to case insensitivity
                 $key = mb_strtolower($attr[0], 'UTF-8');
                 if (isset($item[$key])) {
                     if ($this->resemblesDN($key)) {
                         $selection[] = $this->sanitizeDN($item[$key]);
                     } else {
                         $selection[] = $item[$key];
                     }
                 }
             }
         }
         $findings = $selection;
     }
     //we slice the findings, when
     //a) paged search insuccessful, though attempted
     //b) no paged search, but limit set
     if (!$this->pagedSearchedSuccessful && $pagedSearchOK || !$pagedSearchOK && !is_null($limit)) {
         $findings = array_slice($findings, intval($offset), $limit);
     }
     return $findings;
 }
开发者ID:ryanshoover,项目名称:core,代码行数:98,代码来源:access.php


注:本文中的ldap_control_paged_result_response函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。