Commit ee41bc56 authored by mmn's avatar mmn

Updated LDAP2 extlib to latest version.

parent a6545d09
This diff is collapsed.
......@@ -10,7 +10,7 @@
* @author Benedikt Hallinger <beni@php.net>
* @copyright 2009 Benedikt Hallinger
* @license http://www.gnu.org/licenses/lgpl-3.0.txt LGPLv3
* @version SVN: $Id: LDIF.php 286718 2009-08-03 07:30:49Z beni $
* @version SVN: $Id: LDIF.php 324918 2012-04-06 12:31:04Z clockwerx $
* @link http://pear.php.net/package/Net_LDAP2/
*/
......@@ -340,6 +340,7 @@ class Net_LDAP2_LDIF extends PEAR
+ count($entry_attrs_changes['replace'])
+ count($entry_attrs_changes['delete']);
$is_changed = ($num_of_changes > 0 || $entry->willBeDeleted() || $entry->willBeMoved());
// write version if not done yet
......@@ -556,10 +557,10 @@ class Net_LDAP2_LDIF extends PEAR
$attributes = array();
$dn = false;
foreach ($lines as $line) {
if (preg_match('/^(\w+)(:|::|:<)\s(.+)$/', $line, $matches)) {
$attr =& $matches[1];
$delim =& $matches[2];
$data =& $matches[3];
if (preg_match('/^(\w+(;binary)?)(:|::|:<)\s(.+)$/', $line, $matches)) {
$attr =& $matches[1] . $matches[2];
$delim =& $matches[3];
$data =& $matches[4];
if ($delim == ':') {
// normal data
......@@ -682,20 +683,22 @@ class Net_LDAP2_LDIF extends PEAR
if (preg_match('/^version:\s(.+)$/', $data, $match)) {
// version statement, set version
$this->version($match[1]);
} elseif (preg_match('/^\w+::?\s.+$/', $data)) {
} elseif (preg_match('/^\w+(;binary)?::?\s.+$/', $data)) {
// normal attribute: add line
$commentmode = false;
$this->_lines_next[] = trim($data);
$datalines_read++;
} elseif (preg_match('/^\s(.+)$/', $data, $matches)) {
// wrapped data: unwrap if not in comment mode
// note that the \s above is some more liberal than
// the RFC requests as it also matches tabs etc.
if (!$commentmode) {
if ($datalines_read == 0) {
// first line of entry: wrapped data is illegal
$this->dropError('Net_LDAP2_LDIF error: illegal wrapping at input line '.$this->_input_line, $this->_input_line);
} else {
$last = array_pop($this->_lines_next);
$last = $last.trim($matches[1]);
$last = $last.$matches[1];
$this->_lines_next[] = $last;
$datalines_read++;
}
......
......@@ -11,7 +11,7 @@
* @author Benedikt Hallinger <beni@php.net>
* @copyright 2009 Jan Wagner, Benedikt Hallinger
* @license http://www.gnu.org/licenses/lgpl-3.0.txt LGPLv3
* @version SVN: $Id: Schema.php 286718 2009-08-03 07:30:49Z beni $
* @version SVN: $Id: Schema.php 296515 2010-03-22 14:46:41Z beni $
* @link http://pear.php.net/package/Net_LDAP2/
* @todo see the comment at the end of the file
*/
......@@ -168,12 +168,16 @@ class Net_LDAP2_Schema extends PEAR
array('attributes' => array_values($schema_o->types),
'scope' => 'base'));
if (Net_LDAP2::isError($result)) {
return $result;
return PEAR::raiseError('Could not fetch Subschema entry: '.$result->getMessage());
}
$entry = $result->shiftEntry();
if (!$entry instanceof Net_LDAP2_Entry) {
return PEAR::raiseError('Could not fetch Subschema entry');
if ($entry instanceof Net_LDAP2_Error) {
return PEAR::raiseError('Could not fetch Subschema entry: '.$entry->getMessage());
} else {
return PEAR::raiseError('Could not fetch Subschema entry (search returned '.$result->count().' entries. Check parameter \'basedn\')');
}
}
$schema_o->parse($entry);
......@@ -183,7 +187,7 @@ class Net_LDAP2_Schema extends PEAR
/**
* Return a hash of entries for the given type
*
* Returns a hash of entry for th givene type. Types may be:
* Returns a hash of entry for the givene type. Types may be:
* objectclasses, attributes, ditcontentrules, ditstructurerules, matchingrules,
* matchingruleuses, nameforms, syntaxes
*
......@@ -508,9 +512,111 @@ class Net_LDAP2_Schema extends PEAR
return $return;
}
// [TODO] add method that allows us to see to which objectclasses a certain attribute belongs to
// it should return the result structured, e.g. sorted in "may" and "must". Optionally it should
// be able to return it just "flat", e.g. array_merge()d.
// We could use get_all() to achieve this easily, i think
/**
* See if an schema element exists
*
* @param string $type Type of name, see get()
* @param string $name Name or OID
*
* @return boolean
*/
public function exists($type, $name)
{
$entry = $this->get($type, $name);
if ($entry instanceof Net_LDAP2_ERROR) {
return false;
} else {
return true;
}
}
/**
* See if an attribute is defined in the schema
*
* @param string $attribute Name or OID of the attribute
* @return boolean
*/
public function attributeExists($attribute)
{
return $this->exists('attribute', $attribute);
}
/**
* See if an objectClass is defined in the schema
*
* @param string $ocl Name or OID of the objectClass
* @return boolean
*/
public function objectClassExists($ocl)
{
return $this->exists('objectclass', $ocl);
}
/**
* See to which ObjectClasses an attribute is assigned
*
* The objectclasses are sorted into the keys 'may' and 'must'.
*
* @param string $attribute Name or OID of the attribute
*
* @return array|Net_LDAP2_Error Associative array with OCL names or Error
*/
public function getAssignedOCLs($attribute)
{
$may = array();
$must = array();
// Test if the attribute type is defined in the schema,
// if so, retrieve real name for lookups
$attr_entry = $this->get('attribute', $attribute);
if ($attr_entry instanceof Net_LDAP2_ERROR) {
return PEAR::raiseError("Attribute $attribute not defined in schema: ".$attr_entry->getMessage());
} else {
$attribute = $attr_entry['name'];
}
// We need to get all defined OCLs for this.
$ocls = $this->getAll('objectclasses');
foreach ($ocls as $ocl => $ocl_data) {
// Fetch the may and must attrs and see if our searched attr is contained.
// If so, record it in the corresponding array.
$ocl_may_attrs = $this->may($ocl);
$ocl_must_attrs = $this->must($ocl);
if (is_array($ocl_may_attrs) && in_array($attribute, $ocl_may_attrs)) {
array_push($may, $ocl_data['name']);
}
if (is_array($ocl_must_attrs) && in_array($attribute, $ocl_must_attrs)) {
array_push($must, $ocl_data['name']);
}
}
return array('may' => $may, 'must' => $must);
}
/**
* See if an attribute is available in a set of objectClasses
*
* @param string $attribute Attribute name or OID
* @param array $ocls Names of OCLs to check for
*
* @return boolean TRUE, if the attribute is defined for at least one of the OCLs
*/
public function checkAttribute($attribute, $ocls)
{
foreach ($ocls as $ocl) {
$ocl_entry = $this->get('objectclass', $ocl);
$ocl_may_attrs = $this->may($ocl);
$ocl_must_attrs = $this->must($ocl);
if (is_array($ocl_may_attrs) && in_array($attribute, $ocl_may_attrs)) {
return true;
}
if (is_array($ocl_must_attrs) && in_array($attribute, $ocl_must_attrs)) {
return true;
}
}
return false; // no ocl for the ocls found.
}
}
?>
?>
\ No newline at end of file
......@@ -11,7 +11,7 @@
* @author Benedikt Hallinger <beni@php.net>
* @copyright 2009 Tarjej Huse, Benedikt Hallinger
* @license http://www.gnu.org/licenses/lgpl-3.0.txt LGPLv3
* @version SVN: $Id: Search.php 286718 2009-08-03 07:30:49Z beni $
* @version SVN: $Id: Search.php 328961 2013-01-03 09:04:30Z beni $
* @link http://pear.php.net/package/Net_LDAP2/
*/
......@@ -106,13 +106,22 @@ class Net_LDAP2_Search extends PEAR implements Iterator
/**
* Cache variable for storing entries fetched internally
*
* This currently is only used by {@link pop_entry()}
* This currently is not used by all functions and need consolidation.
*
* @access protected
* @var array
*/
protected $_entry_cache = false;
/**
* Cache variable for count()
*
* @see count()
* @access protected
* @var int
*/
protected $_count_cache = null;
/**
* Constructor
*
......@@ -143,7 +152,7 @@ class Net_LDAP2_Search extends PEAR implements Iterator
}
/**
* Returns an array of entry objects
* Returns an array of entry objects.
*
* @return array Array of entry objects.
*/
......@@ -151,15 +160,19 @@ class Net_LDAP2_Search extends PEAR implements Iterator
{
$entries = array();
while ($entry = $this->shiftEntry()) {
$entries[] = $entry;
if (false === $this->_entry_cache) {
// cache is empty: fetch from LDAP
while ($entry = $this->shiftEntry()) {
$entries[] = $entry;
}
$this->_entry_cache = $entries; // store result in cache
}
return $entries;
return $this->_entry_cache;
}
/**
* Get the next entry in the searchresult.
* Get the next entry in the searchresult from LDAP server.
*
* This will return a valid Net_LDAP2_Entry object or false, so
* you can use this method to easily iterate over the entries inside
......@@ -169,22 +182,20 @@ class Net_LDAP2_Search extends PEAR implements Iterator
*/
public function &shiftEntry()
{
if ($this->count() == 0 ) {
$false = false;
return $false;
}
if (is_null($this->_entry)) {
$this->_entry = @ldap_first_entry($this->_link, $this->_search);
if(!$this->_entry = @ldap_first_entry($this->_link, $this->_search)) {
$false = false;
return $false;
}
$entry = Net_LDAP2_Entry::createConnected($this->_ldap, $this->_entry);
if ($entry instanceof Net_LDAP2_Error) $entry = false;
if ($entry instanceof PEAR_Error) $entry = false;
} else {
if (!$this->_entry = @ldap_next_entry($this->_link, $this->_entry)) {
$false = false;
return $false;
}
$entry = Net_LDAP2_Entry::createConnected($this->_ldap, $this->_entry);
if ($entry instanceof Net_LDAP2_Error) $entry = false;
if ($entry instanceof PEAR_Error) $entry = false;
}
return $entry;
}
......@@ -461,7 +472,13 @@ class Net_LDAP2_Search extends PEAR implements Iterator
if (!$this->_search) {
return 0;
}
return @ldap_count_entries($this->_link, $this->_search);
// ldap_count_entries is slow (see pear bug #18752) with large results,
// so we cache the result internally.
if ($this->_count_cache === null) {
$this->_count_cache = @ldap_count_entries($this->_link, $this->_search);
}
return $this->_count_cache;
}
/**
......
......@@ -10,7 +10,7 @@
* @author Benedikt Hallinger <beni@php.net>
* @copyright 2009 Benedikt Hallinger
* @license http://www.gnu.org/licenses/lgpl-3.0.txt LGPLv3
* @version SVN: $Id: Util.php 286718 2009-08-03 07:30:49Z beni $
* @version SVN: $Id: Util.php 332278 2013-12-05 11:01:15Z beni $
* @link http://pear.php.net/package/Net_LDAP2/
*/
......@@ -525,17 +525,29 @@ class Net_LDAP2_Util extends PEAR
}
/**
* Splits a attribute=value syntax into an array
* Splits an attribute=value syntax into an array
*
* The split will occur at the first unescaped '=' character.
* If escaped delimeters are used, they are returned escaped as well.
* The split will occur at the first unescaped delimeter character.
* In case an invalid delimeter is given, no split will be performed and an
* one element array gets returned.
* Optional also filter-assertion delimeters can be considered (>, <, >=, <=, ~=).
*
* @param string $attr Attribute and Value Syntax
* @param string $attr Attribute and Value Syntax ("foo=bar")
* @param boolean $extended If set to true, also filter-assertion delimeter will be matched
* @param boolean $withDelim If set to true, the return array contains the delimeter at index 1, putting the value to index 2
*
* @return array Indexed array: 0=attribute name, 1=attribute value
* @return array Indexed array: 0=attribute name, 1=attribute value OR ($withDelim=true): 0=attr, 1=delimeter, 2=value
*/
public static function split_attribute_string($attr)
public static function split_attribute_string($attr, $extended=false, $withDelim=false)
{
return preg_split('/(?<!\\\\)=/', $attr, 2);
if ($withDelim) $withDelim = PREG_SPLIT_DELIM_CAPTURE;
if (!$extended) {
return preg_split('/(?<!\\\\)(=)/', $attr, 2, $withDelim);
} else {
return preg_split('/(?<!\\\\)(>=|<=|>|<|~=|=)/', $attr, 2, $withDelim);
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment