本文整理汇总了PHP中ldap_get_values_len函数的典型用法代码示例。如果您正苦于以下问题:PHP ldap_get_values_len函数的具体用法?PHP ldap_get_values_len怎么用?PHP ldap_get_values_len使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ldap_get_values_len函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: count
/**
* get the number of values
*
* @return the number of values
*/
public final function count()
{
$arr = [];
if ($this->get_node()->get_changed()) {
$this->get_node()->refresh_entry();
}
$data = @ldap_get_values_len($this->get_ldapconn()->get_conn(), $this->get_node()->get_entry(), $this->get_name());
return $data['count'];
}
开发者ID:michaelvienna,项目名称:ldapclient,代码行数:14,代码来源:NodeAttribute.php
示例2: getObjectSid
function getObjectSid($adConn, $dn, $distname)
{
//Select which attributes wa want
$attrs = array("objectsid");
//Filter creation
$filter = "distinguishedname=" . addslashes($distname);
//Do the seacrh!
$search = ldap_search($adConn, $dn, $filter, $attrs) or die("**** happens, no connection!");
$entry = ldap_first_entry($adConn, $search);
$vals = ldap_get_values_len($adConn, $entry, "objectsid");
return bin2hex($vals[0]);
}
开发者ID:analogrithems,项目名称:idbroker,代码行数:12,代码来源:active_directory.php
示例3: readEntry
/**
* Read an LDAP entry.
*
* @param resource $ds
* LDAP connection resource.
* @param resource $entryId
* LDAP entry resource.
* @param string[] $binaryFields
* Names of binary attributes.
*
* @return array
* Attributes for an LDAP entry.
*/
public static function readEntry($ds, $entryId, $binaryFields = array())
{
$data = array();
for ($attribute = ldap_first_attribute($ds, $entryId, $attributeId); $attribute !== false; $attribute = ldap_next_attribute($ds, $entryId, $attributeId)) {
$fieldValues = ldap_get_values($ds, $entryId, $attribute);
if (in_array($attribute, $binaryFields)) {
$fieldValues = ldap_get_values_len($ds, $entryId, $attribute);
}
if ($fieldValues['count'] == 1) {
$data[$attribute] = $fieldValues[0];
} else {
for ($i = 0; $i < $fieldValues['count']; $i++) {
$data[$attribute][$i] = $fieldValues[$i];
}
}
}
return $data;
}
开发者ID:grom358,项目名称:php-ldap,代码行数:31,代码来源:Utils.php
示例4: getUserLdapPhoto
protected function getUserLdapPhoto($contactID)
{
$ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn'];
$justthese = array("dn", 'jpegPhoto', 'givenName', 'sn');
$this->getLdapCatalog()->ldapConnect(true);
$ds = $this->getLdapCatalog()->ds;
if ($ds) {
$resource = @ldap_read($ds, $contactID, "phpgwaccounttype=u");
$n_entries = @ldap_count_entries($ds, $resource);
if ($n_entries == 1) {
$first_entry = ldap_first_entry($ds, $resource);
$obj = ldap_get_attributes($ds, $first_entry);
if ($obj['jpegPhoto']) {
return ldap_get_values_len($ds, $first_entry, "jpegPhoto");
}
}
}
return false;
}
开发者ID:cjvaz,项目名称:expressomail,代码行数:19,代码来源:CatalogAdapter.php
示例5: hydrateFromResult
/**
* I cannot imagine a lib being more crap than PHP LDAP one.
* Structure information is melt with data, all functions need a
* connection handler, there are 367 ways of doing the things but only one
* works (at least with binary results) without failures nor error
* messages. Result keys change with automatic pagination without notice
* and so does values when they have accentuated characters.
* It has been a pain to write and a hell to debug, thanks to the
* obsolutely non informative documentation.
*
* hydrateFromResult
*
* Create an entity instance from a LDAP result.
*
* @param Resource $ldap_entry
* @return Entity
*/
protected function hydrateFromResult($ldap_entry)
{
if ($ldap_entry === false) {
return false;
}
$values = array();
foreach ($this->getAttributes($ldap_entry) as $ldap_attribute) {
$attribute = strpos($ldap_attribute, ';') === false ? $ldap_attribute : substr($ldap_attribute, 0, strpos($ldap_attribute, ';'));
if ($this->map->getAttributeModifiers($attribute) & EntityMap::FIELD_BINARY) {
$value = @ldap_get_values_len($this->handler, $ldap_entry, sprintf("%s", $ldap_attribute));
} else {
$value = @ldap_get_values($this->handler, $ldap_entry, $ldap_attribute);
}
if (is_array($value)) {
if ($this->map->getAttributeModifiers($attribute) & EntityMap::FIELD_MULTIVALUED) {
unset($value['count']);
if (!$this->map->getAttributeModifiers($attribute) & EntityMap::FIELD_BINARY) {
$values[$attribute] = array_map(function ($val) {
if ($val === base64_encode(base64_decode($val, true))) {
return base64_decode($val);
}
return $val;
}, $value);
} else {
$values[$attribute] = $value;
}
} else {
if ($value[0] === base64_encode(base64_decode($value[0], true))) {
$values[$attribute] = $value[0];
} else {
$values[$attribute] = $value[0];
}
}
}
}
$values['dn'] = ldap_get_dn($this->handler, $ldap_entry);
return $this->map->createObject($values);
}
开发者ID:chanmix51,项目名称:slapom,代码行数:55,代码来源:Collection.php
示例6: _getAccount
/**
* @param array $attrs An array of names of desired attributes
* @return array An array of the attributes representing the account
* @throws Zend_Ldap_Exception
*/
private function _getAccount($acctname, $attrs = null)
{
$baseDn = $this->_getBaseDn();
if (!$baseDn) {
/**
* @see Zend_Ldap_Exception
*/
require_once 'Zend/Ldap/Exception.php';
throw new Zend_Ldap_Exception(null, 'Base DN not set');
}
$accountFilter = $this->_getAccountFilter($acctname);
if (!$accountFilter) {
/**
* @see Zend_Ldap_Exception
*/
require_once 'Zend/Ldap/Exception.php';
throw new Zend_Ldap_Exception(null, 'Invalid account filter');
}
if (!is_resource($this->_resource))
$this->bind();
$resource = $this->_resource;
$str = $accountFilter;
$code = 0;
/**
* @todo break out search operation into simple function (private for now)
*/
if (!extension_loaded('ldap')) {
/**
* @see Zend_Ldap_Exception
*/
require_once 'Zend/Ldap/Exception.php';
throw new Zend_Ldap_Exception(null, 'LDAP extension not loaded');
}
$result = @ldap_search($resource,
$baseDn,
$accountFilter,
$attrs);
if (is_resource($result) === true) {
$count = @ldap_count_entries($resource, $result);
if ($count == 1) {
$entry = @ldap_first_entry($resource, $result);
if ($entry) {
$acct = array('dn' => @ldap_get_dn($resource, $entry));
$name = @ldap_first_attribute($resource, $entry, $berptr);
while ($name) {
$data = @ldap_get_values_len($resource, $entry, $name);
$acct[$name] = $data;
$name = @ldap_next_attribute($resource, $entry, $berptr);
}
@ldap_free_result($result);
return $acct;
}
} else if ($count == 0) {
/**
* @see Zend_Ldap_Exception
*/
require_once 'Zend/Ldap/Exception.php';
$code = Zend_Ldap_Exception::LDAP_NO_SUCH_OBJECT;
} else {
/**
* @todo limit search to 1 record and remove some of this logic?
*/
$resource = null;
$str = "$accountFilter: Unexpected result count: $count";
/**
* @see Zend_Ldap_Exception
*/
require_once 'Zend/Ldap/Exception.php';
$code = Zend_Ldap_Exception::LDAP_OPERATIONS_ERROR;
}
@ldap_free_result($result);
}
/**
* @see Zend_Ldap_Exception
*/
require_once 'Zend/Ldap/Exception.php';
throw new Zend_Ldap_Exception($resource, $str, $code);
}
开发者ID:jorgenils,项目名称:zend-framework,代码行数:92,代码来源:Ldap.php
示例7: ldap_get_users_scalable
/**
* fill a database table with usernames from al LDAP directory
* searching parameters are defined in configuration
* DOES NOT SUPPORT PAGED RESULTS if more than a 1000 (AD)
* @param string tablename
* @param string columnname
* @param string $extrafilter if present returns only users having some values in some LDAP attribute
* @return integer (nb of records added) or false in case of error
*/
private function ldap_get_users_scalable($tablename, $columnname = 'username', $extrafilter = '')
{
global $CFG;
execute_sql('TRUNCATE TABLE ' . $tablename);
$ldapconnection = $this->ldap_connect();
if (!$ldapconnection) {
return false;
}
$filter = "(" . $this->config['user_attribute'] . "=*)";
if (!empty($this->config['objectclass'])) {
$filter .= "&(" . $this->config['objectclass'] . "))";
}
if ($extrafilter) {
$filter = "(&{$filter}({$extrafilter}))";
}
// get all contexts and look for first matching user
$ldap_contexts = explode(";", $this->config['contexts']);
$ldapuserfields = $this->get_ldap_user_fields();
$fieldstoimport = array_values($ldapuserfields);
$fieldstoimport[] = $this->config['user_attribute'];
// Lowercase all the fields to avoid case mismatch issues
$ldapuserfields = array_map('strtolower', $ldapuserfields);
log_info('retrieving these fields: ' . implode(',', $fieldstoimport) . "\n");
$nbadded = 0;
foreach ($ldap_contexts as $context) {
$context = trim($context);
if (empty($context)) {
continue;
}
if ($this->config['search_sub'] == 'yes') {
// use ldap_search to find first user from subtree
$ldap_result = ldap_search($ldapconnection, $context, $filter, $fieldstoimport);
} else {
// search only in this context
$ldap_result = ldap_list($ldapconnection, $context, $filter, $fieldstoimport);
}
if ($entry = ldap_first_entry($ldapconnection, $ldap_result)) {
do {
$value = ldap_get_values_len($ldapconnection, $entry, $this->config['user_attribute']);
$value = $value[0];
// let's convert all keys to lowercase, to avoid case sensitivity issues
$ldaprec = array_change_key_case(ldap_get_attributes($ldapconnection, $entry));
$todb = new stdClass();
$todb->{$columnname} = $value;
foreach ($ldapuserfields as $dbfield => $ldapfield) {
if (array_key_exists($ldapfield, $ldaprec)) {
$todb->{$dbfield} = $ldaprec[$ldapfield][0];
} else {
log_warn("Ldap record contained no {$ldapfield} field to map to DB {$dbfield}");
}
}
insert_record($tablename, $todb, false, false);
$nbadded++;
if ($nbadded % 100 == 0) {
echo '.';
}
} while ($entry = ldap_next_entry($ldapconnection, $entry));
echo "\n";
}
ldap_free_result($ldap_result);
// free mem
}
$this->ldap_close($ldapconnection);
return $nbadded;
}
开发者ID:vohung96,项目名称:mahara,代码行数:74,代码来源:lib.php
示例8: getValuesLen
/**
* Get all binary values from the specified result entry.
*
* @param $entry
* @param $attribute
*
* @return array
*/
public function getValuesLen($entry, $attribute)
{
if ($this->suppressErrors) {
return @ldap_get_values_len($this->getConnection(), $entry, $attribute);
}
return ldap_get_values_len($this->getConnection(), $entry, $attribute);
}
开发者ID:HarkiratGhotra,项目名称:application,代码行数:15,代码来源:Ldap.php
示例9: getEntries
/**
* Wrapper for ldap_get_entries
*
* @access private
*
*/
private function getEntries()
{
return $this->entries = @ldap_get_entries($this->ldap_handle, $this->result);
// this way ldap_get_entries is binary safe
$i = 0;
$tmp_entries = array();
$entry = ldap_first_entry($this->ldap_handle, $this->result);
do {
$attributes = @ldap_get_attributes($this->ldap_handle, $entry);
for ($j = 0; $j < $attributes['count']; $j++) {
$values = ldap_get_values_len($this->ldap_handle, $entry, $attributes[$j]);
$tmp_entries[$i][strtolower($attributes[$j])] = $values;
}
$i++;
} while ($entry = @ldap_next_entry($this->ldap_handle, $entry));
if ($i) {
$tmp_entries['count'] = $i;
}
$this->entries = $tmp_entries;
return $this->entries;
}
开发者ID:arlendotcn,项目名称:ilias,代码行数:27,代码来源:class.ilLDAPResult.php
示例10: getObjectSid
/**
* Recupere le SID de l'utilisateur
* Required by Active Directory
*
* @param string $ldapUser Login de l'utilisateur
* @return string Sid
*/
function getObjectSid($ldapUser)
{
$criteria = '(' . $this->getUserIdentifier() . '=' . $ldapUser . ')';
$justthese = array("objectsid");
// if the directory is AD, then bind first with the search user first
if ($this->serverType == "activedirectory") {
$this->bindauth($this->searchUser, $this->searchPassword);
}
$i = 0;
$searchDN = $this->people;
while ($i <= 2) {
$ldapSearchResult = @ldap_search($this->connection, $searchDN, $criteria, $justthese);
if (!$ldapSearchResult) {
$this->error = ldap_errno($this->connection) . " " . ldap_error($this->connection);
return -1;
}
$entry = ldap_first_entry($this->connection, $ldapSearchResult);
if (!$entry) {
// Si pas de resultat on cherche dans le domaine
$searchDN = $this->domain;
$i++;
} else {
$i++;
$i++;
}
}
if ($entry) {
$ldapBinary = ldap_get_values_len($this->connection, $entry, "objectsid");
$SIDText = $this->binSIDtoText($ldapBinary[0]);
return $SIDText;
} else {
$this->error = ldap_errno($this->connection) . " " . ldap_error($this->connection);
return '?';
}
}
开发者ID:Samara94,项目名称:dolibarr,代码行数:42,代码来源:ldap.class.php
示例11: ldap_get_entries
/**
* return entries from ldap
*
* Returns values like ldap_get_entries but is
* binary compatible and return all attributes as array
*
* @return array ldap-entries
*/
function ldap_get_entries($conn, $searchresult)
{
//Returns values like ldap_get_entries but is
//binary compatible
$i = 0;
$fresult = array();
$entry = ldap_first_entry($conn, $searchresult);
do {
$attributes = @ldap_get_attributes($conn, $entry);
for ($j = 0; $j < $attributes['count']; $j++) {
$values = ldap_get_values_len($conn, $entry, $attributes[$j]);
if (is_array($values)) {
$fresult[$i][strtolower($attributes[$j])] = $values;
} else {
$fresult[$i][strtolower($attributes[$j])] = array($values);
}
}
$i++;
} while ($entry = @ldap_next_entry($conn, $entry));
//were done
return $fresult;
}
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:30,代码来源:auth.php
示例12: getValuesLen
/**
* {@inheritdoc}
*/
public function getValuesLen($entry, $attribute)
{
return ldap_get_values_len($this->getConnection(), $entry, $attribute);
}
开发者ID:adldap2,项目名称:adldap2,代码行数:7,代码来源:Ldap.php
示例13: __construct
public function __construct($ldap, $entry, array $fieldMap)
{
$ldapEntry = ldap_get_attributes($ldap, $entry);
$this->dn = ldap_get_dn($ldap, $entry);
$this->fieldMap = $fieldMap;
$this->attributes = array();
for ($i = 0; $i < $ldapEntry['count']; $i++) {
$attribute = $ldapEntry[$i];
$attrib = strtolower($attribute);
$count = $ldapEntry[$attribute]['count'];
if ($attrib == $this->fieldMap['photodata']) {
if ($data = @ldap_get_values_len($ldap, $entry, $attribute)) {
$this->attributes[$attrib] = $data;
// Get binary photo data
}
} else {
$this->attributes[$attrib] = array();
for ($j = 0; $j < $count; $j++) {
if (!in_array($ldapEntry[$attribute][$j], $this->attributes[$attrib])) {
$this->attributes[$attrib][] = str_replace('$', "\n", $ldapEntry[$attribute][$j]);
}
}
}
}
}
开发者ID:nncsang,项目名称:Kurogo,代码行数:25,代码来源:LDAPPeopleRetriever.php
示例14: QueryArray
function QueryArray($str = '(ObjectClass=*)', $fields = false)
{
global $APPLICATION;
if (strlen($this->arFields['BASE_DN']) <= 0) {
return false;
}
$arBaseDNs = explode(";", $this->arFields['BASE_DN']);
$info = false;
$i = 0;
if ($this->arFields["CONVERT_UTF8"] == "Y") {
$str = $APPLICATION->ConvertCharset($str, SITE_CHARSET, "utf-8");
}
foreach ($arBaseDNs as $BaseDN) {
global $APPLICATION;
$BaseDN = trim($BaseDN);
if ($BaseDN == "") {
continue;
}
if ($this->arFields["CONVERT_UTF8"] == "Y") {
$BaseDN = $APPLICATION->ConvertCharset($BaseDN, SITE_CHARSET, "utf-8");
}
$defaultMaxPageSizeAD = 1000;
$pageSize = isset($this->arFields['MAX_PAGE_SIZE']) && intval($this->arFields['MAX_PAGE_SIZE'] > 0) ? intval($this->arFields['MAX_PAGE_SIZE']) : $defaultMaxPageSizeAD;
$cookie = '';
do {
if (CLdapUtil::isLdapPaginationAviable()) {
ldap_control_paged_result($this->conn, $pageSize, false, $cookie);
}
if ($fields === false) {
$sr = @ldap_search($this->conn, $BaseDN, $str);
} else {
$sr = @ldap_search($this->conn, $BaseDN, $str, $fields);
}
if ($sr) {
$entry = ldap_first_entry($this->conn, $sr);
if ($entry) {
if (!is_array($info)) {
$info = array();
$i = 0;
}
do {
$attributes = ldap_get_attributes($this->conn, $entry);
for ($j = 0; $j < $attributes['count']; $j++) {
$values = @ldap_get_values_len($this->conn, $entry, $attributes[$j]);
if ($values === false) {
continue;
}
$bPhotoAttr = in_array($attributes[$j], self::$PHOTO_ATTRIBS);
$info[$i][strtolower($attributes[$j])] = $bPhotoAttr ? $values : $this->WorkAttr($values);
}
if (!is_set($info[$i], 'dn')) {
if ($this->arFields["CONVERT_UTF8"] == "Y") {
$info[$i]['dn'] = $APPLICATION->ConvertCharset(ldap_get_dn($this->conn, $entry), "utf-8", SITE_CHARSET);
} else {
$info[$i]['dn'] = ldap_get_dn($this->conn, $entry);
}
}
$i++;
} while ($entry = ldap_next_entry($this->conn, $entry));
}
} elseif ($sr === false) {
$APPLICATION->ThrowException("LDAP_SEARCH_ERROR");
}
if (CLdapUtil::isLdapPaginationAviable()) {
ldap_control_paged_result_response($this->conn, $sr, $cookie);
}
} while ($cookie !== null && $cookie != '');
}
return $info;
}
开发者ID:DarneoStudio,项目名称:bitrix,代码行数:70,代码来源:ldap.php
示例15: ldap_get_entries
/**
* Return entries from ldap
*
* Returns values like ldap_get_entries but is binary compatible and return
* all attributes as array
*
* @return array ldap-entries
*/
private function ldap_get_entries($conn, $searchresult)
{
$i = 0;
$fresult = array();
$entry = ldap_first_entry($conn, $searchresult);
do {
$attributes = @ldap_get_attributes($conn, $entry);
for ($j = 0; $j < $attributes['count']; $j++) {
$values = ldap_get_values_len($conn, $entry, $attributes[$j]);
if (is_array($values)) {
$fresult[$i][$attributes[$j]] = $values;
} else {
$fresult[$i][$attributes[$j]] = array($values);
}
}
$i++;
} while ($entry = @ldap_next_entry($conn, $entry));
// We're done
return $fresult;
}
开发者ID:Br3nda,项目名称:mahara,代码行数:28,代码来源:lib.php
示例16: ldap_get_entries
$sr = @ldap_search($ds, $ldap_basedn, '(uid=*)');
$info = ldap_get_entries($ds, $sr);
for ($key = 0; $key < $info["count"]; $key++) {
echo "<pre>";
print_r($info[$key]);
echo "</pre>";
$lastname = api_utf8_decode($info[$key]["sn"][0]);
$firstname = api_utf8_decode($info[$key]["givenname"][0]);
$email = $info[$key]["mail"][0];
// Get uid from dn
$dn_array = ldap_explode_dn($info[$key]["dn"], 1);
$username = $dn_array[0];
// uid is first key
$outab[] = $info[$key]["edupersonprimaryaffiliation"][0];
// Ici "student"
$val = ldap_get_values_len($ds, $sr, "userPassword");
$password = $val[0];
// Pour faciliter la gestion on ajoute le code "etape-annee"
$official_code = $etape . "-" . $annee;
$auth_source = "ldap";
// Pas de date d'expiration d'etudiant (a recuperer par rapport au shadow expire LDAP)
$expiration_date = '0000-00-00 00:00:00';
$active = 1;
// Ajout de l'utilisateur
if (UserManager::is_username_available($username)) {
$user_id = UserManager::create_user($firstname, $lastname, $status, $email, $username, $password, $official_code, api_get_setting('language.platform_language'), $phone, $picture_uri, $auth_source, $expiration_date, $active);
$UserAdd[] = $user_id;
} else {
$user = api_get_user_info_from_username($username);
$user_id = $user['user_id'];
UserManager::update_user($user_id, $firstname, $lastname, $username, null, null, $email, $status, $official_code, $phone, $picture_uri, $expiration_date, $active);
开发者ID:omaoibrahim,项目名称:chamilo-lms,代码行数:31,代码来源:ldap_synchro.php
示例17: sync_users
/**
* Syncronizes user fron external LDAP server to moodle user table
*
* Sync is now using username attribute.
*
* Syncing users removes or suspends users that dont exists anymore in external LDAP.
* Creates new users and updates coursecreator status of users.
*
* @param bool $do_updates will do pull in data updates from LDAP if relevant
*/
function sync_users($do_updates = true)
{
global $CFG, $DB;
print_string('connectingldap', 'auth_ldap');
$ldapconnection = $this->ldap_connect();
$dbman = $DB->get_manager();
/// Define table user to be created
$table = new xmldb_table('tmp_extuser');
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('username', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
$table->add_field('mnethostid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_index('username', XMLDB_INDEX_UNIQUE, array('mnethostid', 'username'));
print_string('creatingtemptable', 'auth_ldap', 'tmp_extuser');
$dbman->create_temp_table($table);
////
//// get user's list from ldap to sql in a scalable fashion
////
// prepare some data we'll need
$filter = '(&(' . $this->config->user_attribute . '=*)' . $this->config->objectclass . ')';
$contexts = explode(';', $this->config->contexts);
if (!empty($this->config->create_context)) {
array_push($contexts, $this->config->create_context);
}
$ldap_pagedresults = ldap_paged_results_supported($this->config->ldap_version);
$ldap_cookie = '';
foreach ($contexts as $context) {
$context = trim($context);
if (empty($context)) {
continue;
}
do {
if ($ldap_pagedresults) {
ldap_control_paged_result($ldapconnection, $this->config->pagesize, true, $ldap_cookie);
}
if ($this->config->search_sub) {
// Use ldap_search to find first user from subtree.
$ldap_result = ldap_search($ldapconnection, $context, $filter, array($this->config->user_attribute));
} else {
// Search only in this context.
$ldap_result = ldap_list($ldapconnection, $context, $filter, array($this->config->user_attribute));
}
if (!$ldap_result) {
continue;
}
if ($ldap_pagedresults) {
ldap_control_paged_result_response($ldapconnection, $ldap_result, $ldap_cookie);
}
if ($entry = @ldap_first_entry($ldapconnection, $ldap_result)) {
do {
$value = ldap_get_values_len($ldapconnection, $entry, $this->config->user_attribute);
$value = core_text::convert($value[0], $this->config->ldapencoding, 'utf-8');
$value = trim($value);
$this->ldap_bulk_insert($value);
} while ($entry = ldap_next_entry($ldapconnection, $entry));
}
unset($ldap_result);
// Free mem.
} while ($ldap_pagedresults && $ldap_cookie !== null && $ldap_cookie != '');
}
// If LDAP paged results were used, the current connection must be completely
// closed and a new one created, to work without paged results from here on.
if ($ldap_pagedresults) {
$this->ldap_close(true);
$ldapconnection = $this->ldap_connect();
}
/// preserve our user database
/// if the temp table is empty, it probably means that something went wrong, exit
/// so as to avoid mass deletion of users; which is hard to undo
$count = $DB->count_records_sql('SELECT COUNT(username) AS count, 1 FROM {tmp_extuser}');
if ($count < 1) {
print_string('didntgetusersfromldap', 'auth_ldap');
exit;
} else {
print_string('gotcountrecordsfromldap', 'auth_ldap', $count);
}
/// User removal
// Find users in DB that aren't in ldap -- to be removed!
// this is still not as scalable (but how often do we mass delete?)
if ($this->config->removeuser == AUTH_REMOVEUSER_FULLDELETE) {
$sql = "SELECT u.*\n FROM {user} u\n LEFT JOIN {tmp_extuser} e ON (u.username = e.username AND u.mnethostid = e.mnethostid)\n WHERE u.auth = :auth\n AND u.deleted = 0\n AND e.username IS NULL";
$remove_users = $DB->get_records_sql($sql, array('auth' => $this->authtype));
if (!empty($remove_users)) {
print_string('userentriestoremove', 'auth_ldap', count($remove_users));
foreach ($remove_users as $user) {
if (delete_user($user)) {
echo "\t";
print_string('auth_dbdeleteuser', 'auth_db', array('name' => $user->username, 'id' => $user->id));
echo "\n";
} else {
//.........这里部分代码省略.........
开发者ID:jeffthestampede,项目名称:excelsior,代码行数:101,代码来源:auth.php
示例18: username2guid
/**
* Converts a username (samAccountName) to a GUID
*
* @param string $username The username to query
* @return string
*/
public function username2guid($username)
{
if (!$this->_bind) {
return false;
}
if ($username === null) {
return "Missing compulsory field [username]";
}
$filter = "samaccountname=" . $username;
$fields = array("objectGUID");
$sr = @ldap_search($this->_conn, $this->_base_dn, $filter, $fields);
if (ldap_count_entries($this->_conn, $sr) > 0) {
$entry = @ldap_first_entry($this->_conn, $sr);
$guid = @ldap_get_values_len($this->_conn, $entry, 'objectGUID');
$strGUID = $this->binary2text($guid[0]);
return $strGUID;
} else {
return false;
}
}
开发者ID:hcgonzalezpr,项目名称:codeigniter-adldap,代码行数:26,代码来源:Adldap.php
示例19: getValuesBin
/**
* Get all the binary values from the entry
*
* Used to read all the values of the attribute in the entry
*
* I renamed the get_values_len to getValuesBin as it seemed more logical
*
* Returns an array of values for the attribute on success and FALSE on error.
*
* @link http://www.php.net/ldap_get_values_len
* @param string $attr The attribute you want to read
* @return array
*/
function getValuesBin($attr)
{
if ($arr = @ldap_get_values_len($this->connection, $this->entry, $attr)) {
return $arr;
}
$this->setErrVars();
return false;
}
开发者ID:ruNovel,项目名称:sams2,代码行数:21,代码来源:ldap.php
示例20: ldap_get_users_scalable
/**
* fill a database table with usernames from al LDAP directory
* searching parameters are defined in configuration
* DOES NOT SUPPORT PAGED RESULTS if more than a 1000 (AD)
* @param string tablename
* @param string columnname
* @param string $extrafilter if present returns only users having some values in some LDAP attribute
* @return integer (nb of records added) or false in case of error
*/
public function ldap_get_users_scalable($tablename, $columname = 'username', $extrafilter = '')
{
global $CFG;
execute_sql('TRUNCATE TABLE ' . $tablename);
$ldapconnection = $this->ldap_connect();
if ($CFG->debug_ldap_groupes) {
moodle_print_object("connexion ldap: ", $ldapconnection);
}
if (!$ldapconnection) {
return false;
}
$filter = "(" . $this->config['user_attribute'] . "=*)";
if (!empty($this->config['objectclass'])) {
$filter .= "&(" . $this->config['objectclass'] . "))";
}
if ($extrafilter) {
$filter = "(&{$filter}({$extrafilter}))";
}
if ($CFG->debug_ldap_groupes) {
moodle_print_object("filter users ldap: ", $filter);
}
// get all contexts and look for first matching user
$ldap_contexts = explode(";", $this->config['contexts']);
$nbadded = 0;
foreach ($ldap_contexts as $context) {
$context = trim($context);
if (empty($context)) {
continue;
}
if ($this->config['search_sub'] == 'yes') {
// use ldap_search to find first user from subtree
$ldap_result = ldap_search($ldapconnection, $context, $filter, array($this->config['user_attribute']));
} else {
// search only in this context
$ldap_result = ldap_list($ldapconnection, $filter, array($this->config['user_attribute']));
}
if ($entry = ldap_first_entry($ldapconnection, $ldap_result)) {
do {
$value = ldap_get_values_len($ldapconnection, $entry, $this->config['user_attribute']);
$value = $value[0];
//array_push($ret, $value);
insert_record($tablename, array($columname => addslashes($value)), false, false);
$nbadded++;
} while ($entry = ldap_next_entry($ldapconnection, $entry));
}
unset($ldap_result);
// free mem
}
@ldap_close($ldapconnection);
return $nbadded;
}
开发者ID:ebugnet,项目名称:mahara_ldap_sync,代码行数:60,代码来源:lib.php
注:本文中的ldap_get_values_len函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论