<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4: */
/**
-* File containing the Net_LDAP2_Filter interface class.
-*
-* PHP version 5
-*
-* @category Net
-* @package Net_LDAP2
-* @author Benedikt Hallinger <beni@php.net>
-* @copyright 2009 Benedikt Hallinger
-* @license http://www.gnu.org/licenses/lgpl-3.0.txt LGPLv3
-* @version SVN: $Id: Filter.php 289978 2009-10-27 09:56:41Z beni $
-* @link http://pear.php.net/package/Net_LDAP2/
-*/
+ * File containing the Net_LDAP2_Filter interface class.
+ *
+ * PHP version 5
+ *
+ * @category Net
+ * @package Net_LDAP2
+ * @author Benedikt Hallinger <beni@php.net>
+ * @copyright 2009 Benedikt Hallinger
+ * @license http://www.gnu.org/licenses/lgpl-3.0.txt LGPLv3
+ * @version SVN: $Id: Filter.php 289978 2009-10-27 09:56:41Z beni $
+ * @link http://pear.php.net/package/Net_LDAP2/
+ */
/**
-* Includes
-*/
-require_once 'PEAR.php';
-require_once 'Util.php';
+ * Includes
+ */
+#require_once 'PEAR.php';
+#require_once 'Util.php';
/**
-* Object representation of a part of a LDAP filter.
-*
-* This Class is not completely compatible to the PERL interface!
-*
-* The purpose of this class is, that users can easily build LDAP filters
-* without having to worry about right escaping etc.
-* A Filter is built using several independent filter objects
-* which are combined afterwards. This object works in two
-* modes, depending how the object is created.
-* If the object is created using the {@link create()} method, then this is a leaf-object.
-* If the object is created using the {@link combine()} method, then this is a container object.
-*
-* LDAP filters are defined in RFC-2254 and can be found under
-* {@link http://www.ietf.org/rfc/rfc2254.txt}
-*
-* Here a quick copy&paste example:
-* <code>
-* $filter0 = Net_LDAP2_Filter::create('stars', 'equals', '***');
-* $filter_not0 = Net_LDAP2_Filter::combine('not', $filter0);
-*
-* $filter1 = Net_LDAP2_Filter::create('gn', 'begins', 'bar');
-* $filter2 = Net_LDAP2_Filter::create('gn', 'ends', 'baz');
-* $filter_comp = Net_LDAP2_Filter::combine('or',array($filter_not0, $filter1, $filter2));
-*
-* echo $filter_comp->asString();
-* // This will output: (|(!(stars=\0x5c0x2a\0x5c0x2a\0x5c0x2a))(gn=bar*)(gn=*baz))
-* // The stars in $filter0 are treaten as real stars unless you disable escaping.
-* </code>
-*
-* @category Net
-* @package Net_LDAP2
-* @author Benedikt Hallinger <beni@php.net>
-* @license http://www.gnu.org/copyleft/lesser.html LGPL
-* @link http://pear.php.net/package/Net_LDAP2/
-*/
+ * Object representation of a part of a LDAP filter.
+ *
+ * This Class is not completely compatible to the PERL interface!
+ *
+ * The purpose of this class is, that users can easily build LDAP filters
+ * without having to worry about right escaping etc.
+ * A Filter is built using several independent filter objects
+ * which are combined afterwards. This object works in two
+ * modes, depending how the object is created.
+ * If the object is created using the {@link create()} method, then this is a leaf-object.
+ * If the object is created using the {@link combine()} method, then this is a container object.
+ *
+ * LDAP filters are defined in RFC-2254 and can be found under
+ * {@link http://www.ietf.org/rfc/rfc2254.txt}
+ *
+ * Here a quick copy&paste example:
+ * <code>
+ * $filter0 = Net_LDAP2_Filter::create('stars', 'equals', ' * * *');
+ * $filter_not0 = Net_LDAP2_Filter::combine('not', $filter0);
+ *
+ * $filter1 = Net_LDAP2_Filter::create('gn', 'begins', 'bar');
+ * $filter2 = Net_LDAP2_Filter::create('gn', 'ends', 'baz');
+ * $filter_comp = Net_LDAP2_Filter::combine('or',array($filter_not0, $filter1, $filter2));
+ *
+ * echo $filter_comp->asString();
+ * // This will output: (|(!(stars=\0x5c0x2a\0x5c0x2a\0x5c0x2a))(gn=bar *)(gn= *baz))
+ * // The stars in $filter0 are treaten as real stars unless you disable escaping.
+ * </code>
+ *
+ * @category Net
+ * @package Net_LDAP2
+ * @author Benedikt Hallinger <beni@php.net>
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL
+ * @link http://pear.php.net/package/Net_LDAP2/
+ */
class Net_LDAP2_Filter extends PEAR
{
/**
- * Storage for combination of filters
- *
- * This variable holds a array of filter objects
- * that should be combined by this filter object.
- *
- * @access protected
- * @var array
- */
+ * Storage for combination of filters
+ *
+ * This variable holds a array of filter objects
+ * that should be combined by this filter object.
+ *
+ * @access protected
+ * @var array
+ */
protected $_subfilters = array();
/**
- * Match of this filter
- *
- * If this is a leaf filter, then a matching rule is stored,
- * if it is a container, then it is a logical operator
- *
- * @access protected
- * @var string
- */
+ * Match of this filter
+ *
+ * If this is a leaf filter, then a matching rule is stored,
+ * if it is a container, then it is a logical operator
+ *
+ * @access protected
+ * @var string
+ */
protected $_match;
/**
- * Single filter
- *
- * If we operate in leaf filter mode,
- * then the constructing method stores
- * the filter representation here
- *
- * @acces private
- * @var string
- */
+ * Single filter
+ *
+ * If we operate in leaf filter mode,
+ * then the constructing method stores
+ * the filter representation here
+ *
+ * @acces private
+ * @var string
+ */
protected $_filter;
/**
- * Create a new Net_LDAP2_Filter object and parse $filter.
- *
- * This is for PERL Net::LDAP interface.
- * Construction of Net_LDAP2_Filter objects should happen through either
- * {@link create()} or {@link combine()} which give you more control.
- * However, you may use the perl iterface if you already have generated filters.
- *
- * @param string $filter LDAP filter string
- *
- * @see parse()
- */
+ * Create a new Net_LDAP2_Filter object and parse $filter.
+ *
+ * This is for PERL Net::LDAP interface.
+ * Construction of Net_LDAP2_Filter objects should happen through either
+ * {@link create()} or {@link combine()} which give you more control.
+ * However, you may use the perl iterface if you already have generated filters.
+ *
+ * @param string $filter LDAP filter string
+ *
+ * @see parse()
+ */
public function __construct($filter = false)
{
// The optional parameter must remain here, because otherwise create() crashes
}
/**
- * Constructor of a new part of a LDAP filter.
- *
- * The following matching rules exists:
- * - equals: One of the attributes values is exactly $value
- * Please note that case sensitiviness is depends on the
- * attributes syntax configured in the server.
- * - begins: One of the attributes values must begin with $value
- * - ends: One of the attributes values must end with $value
- * - contains: One of the attributes values must contain $value
- * - present | any: The attribute can contain any value but must be existent
- * - greater: The attributes value is greater than $value
- * - less: The attributes value is less than $value
- * - greaterOrEqual: The attributes value is greater or equal than $value
- * - lessOrEqual: The attributes value is less or equal than $value
- * - approx: One of the attributes values is similar to $value
- *
- * If $escape is set to true (default) then $value will be escaped
- * properly. If it is set to false then $value will be treaten as raw filter value string.
- * You should escape yourself using {@link Net_LDAP2_Util::escape_filter_value()}!
- *
- * Examples:
- * <code>
- * // This will find entries that contain an attribute "sn" that ends with "foobar":
- * $filter = new Net_LDAP2_Filter('sn', 'ends', 'foobar');
- *
- * // This will find entries that contain an attribute "sn" that has any value set:
- * $filter = new Net_LDAP2_Filter('sn', 'any');
- * </code>
- *
- * @param string $attr_name Name of the attribute the filter should apply to
- * @param string $match Matching rule (equals, begins, ends, contains, greater, less, greaterOrEqual, lessOrEqual, approx, any)
- * @param string $value (optional) if given, then this is used as a filter
- * @param boolean $escape Should $value be escaped? (default: yes, see {@link Net_LDAP2_Util::escape_filter_value()} for detailed information)
- *
- * @return Net_LDAP2_Filter|Net_LDAP2_Error
- */
+ * Constructor of a new part of a LDAP filter.
+ *
+ * The following matching rules exists:
+ * - equals: One of the attributes values is exactly $value
+ * Please note that case sensitiviness is depends on the
+ * attributes syntax configured in the server.
+ * - begins: One of the attributes values must begin with $value
+ * - ends: One of the attributes values must end with $value
+ * - contains: One of the attributes values must contain $value
+ * - present | any: The attribute can contain any value but must be existent
+ * - greater: The attributes value is greater than $value
+ * - less: The attributes value is less than $value
+ * - greaterOrEqual: The attributes value is greater or equal than $value
+ * - lessOrEqual: The attributes value is less or equal than $value
+ * - approx: One of the attributes values is similar to $value
+ *
+ * If $escape is set to true (default) then $value will be escaped
+ * properly. If it is set to false then $value will be treaten as raw filter value string.
+ * You should escape yourself using {@link Net_LDAP2_Util::escape_filter_value()}!
+ *
+ * Examples:
+ * <code>
+ * // This will find entries that contain an attribute "sn" that ends with "foobar":
+ * $filter = new Net_LDAP2_Filter('sn', 'ends', 'foobar');
+ *
+ * // This will find entries that contain an attribute "sn" that has any value set:
+ * $filter = new Net_LDAP2_Filter('sn', 'any');
+ * </code>
+ *
+ * @param string $attr_name Name of the attribute the filter should apply to
+ * @param string $match Matching rule (equals, begins, ends, contains, greater, less, greaterOrEqual, lessOrEqual, approx, any)
+ * @param string $value (optional) if given, then this is used as a filter
+ * @param boolean $escape Should $value be escaped? (default: yes, see {@link Net_LDAP2_Util::escape_filter_value()} for detailed information)
+ *
+ * @return Net_LDAP2_Filter|Net_LDAP2_Error
+ */
public static function &create($attr_name, $match, $value = '', $escape = true)
{
$leaf_filter = new Net_LDAP2_Filter();
}
/**
- * Combine two or more filter objects using a logical operator
- *
- * This static method combines two or more filter objects and returns one single
- * filter object that contains all the others.
- * Call this method statically: $filter = Net_LDAP2_Filter('or', array($filter1, $filter2))
- * If the array contains filter strings instead of filter objects, we will try to parse them.
- *
- * @param string $log_op The locicall operator. May be "and", "or", "not" or the subsequent logical equivalents "&", "|", "!"
- * @param array|Net_LDAP2_Filter $filters array with Net_LDAP2_Filter objects
- *
- * @return Net_LDAP2_Filter|Net_LDAP2_Error
- * @static
- */
+ * Combine two or more filter objects using a logical operator
+ *
+ * This static method combines two or more filter objects and returns one single
+ * filter object that contains all the others.
+ * Call this method statically: $filter = Net_LDAP2_Filter('or', array($filter1, $filter2))
+ * If the array contains filter strings instead of filter objects, we will try to parse them.
+ *
+ * @param string $log_op The locicall operator. May be "and", "or", "not" or the subsequent logical equivalents "&", "|", "!"
+ * @param array|Net_LDAP2_Filter $filters array with Net_LDAP2_Filter objects
+ *
+ * @return Net_LDAP2_Filter|Net_LDAP2_Error
+ * @static
+ */
public static function &combine($log_op, $filters)
{
if (PEAR::isError($filters)) {
}
/**
- * Parse FILTER into a Net_LDAP2_Filter object
- *
- * This parses an filter string into Net_LDAP2_Filter objects.
- *
- * @param string $FILTER The filter string
- *
- * @access static
- * @return Net_LDAP2_Filter|Net_LDAP2_Error
- * @todo Leaf-mode: Do we need to escape at all? what about *-chars?check for the need of encoding values, tackle problems (see code comments)
- */
+ * Parse FILTER into a Net_LDAP2_Filter object
+ *
+ * This parses an filter string into Net_LDAP2_Filter objects.
+ *
+ * @param string $FILTER The filter string
+ *
+ * @access static
+ * @return Net_LDAP2_Filter|Net_LDAP2_Error
+ * @todo Leaf-mode: Do we need to escape at all? what about *-chars?check for the need of encoding values, tackle problems (see code comments)
+ */
public static function parse($FILTER)
{
if (preg_match('/^\((.+?)\)$/', $FILTER, $matches)) {
}
/**
- * Get the string representation of this filter
- *
- * This method runs through all filter objects and creates
- * the string representation of the filter. If this
- * filter object is a leaf filter, then it will return
- * the string representation of this filter.
- *
- * @return string|Net_LDAP2_Error
- */
+ * Get the string representation of this filter
+ *
+ * This method runs through all filter objects and creates
+ * the string representation of the filter. If this
+ * filter object is a leaf filter, then it will return
+ * the string representation of this filter.
+ *
+ * @return string|Net_LDAP2_Error
+ */
public function asString()
{
if ($this->isLeaf()) {
}
/**
- * Alias for perl interface as_string()
- *
- * @see asString()
- * @return string|Net_LDAP2_Error
- */
+ * Alias for perl interface as_string()
+ *
+ * @see asString()
+ * @return string|Net_LDAP2_Error
+ */
public function as_string()
{
return $this->asString();
}
/**
- * Print the text representation of the filter to FH, or the currently selected output handle if FH is not given
- *
- * This method is only for compatibility to the perl interface.
- * However, the original method was called "print" but due to PHP language restrictions,
- * we can't have a print() method.
- *
- * @param resource $FH (optional) A filehandle resource
- *
- * @return true|Net_LDAP2_Error
- */
+ * Print the text representation of the filter to FH, or the currently selected output handle if FH is not given
+ *
+ * This method is only for compatibility to the perl interface.
+ * However, the original method was called "print" but due to PHP language restrictions,
+ * we can't have a print() method.
+ *
+ * @param resource $FH (optional) A filehandle resource
+ *
+ * @return true|Net_LDAP2_Error
+ */
public function printMe($FH = false)
{
if (!is_resource($FH)) {
}
/**
- * This can be used to escape a string to provide a valid LDAP-Filter.
- *
- * LDAP will only recognise certain characters as the
- * character istself if they are properly escaped. This is
- * what this method does.
- * The method can be called statically, so you can use it outside
- * for your own purposes (eg for escaping only parts of strings)
- *
- * In fact, this is just a shorthand to {@link Net_LDAP2_Util::escape_filter_value()}.
- * For upward compatibiliy reasons you are strongly encouraged to use the escape
- * methods provided by the Net_LDAP2_Util class.
- *
- * @param string $value Any string who should be escaped
- *
- * @static
- * @return string The string $string, but escaped
- * @deprecated Do not use this method anymore, instead use Net_LDAP2_Util::escape_filter_value() directly
- */
+ * This can be used to escape a string to provide a valid LDAP-Filter.
+ *
+ * LDAP will only recognise certain characters as the
+ * character istself if they are properly escaped. This is
+ * what this method does.
+ * The method can be called statically, so you can use it outside
+ * for your own purposes (eg for escaping only parts of strings)
+ *
+ * In fact, this is just a shorthand to {@link Net_LDAP2_Util::escape_filter_value()}.
+ * For upward compatibiliy reasons you are strongly encouraged to use the escape
+ * methods provided by the Net_LDAP2_Util class.
+ *
+ * @param string $value Any string who should be escaped
+ *
+ * @static
+ * @return string The string $string, but escaped
+ * @deprecated Do not use this method anymore, instead use Net_LDAP2_Util::escape_filter_value() directly
+ */
public static function escape($value)
{
$return = Net_LDAP2_Util::escape_filter_value(array($value));
}
/**
- * Is this a container or a leaf filter object?
- *
- * @access protected
- * @return boolean
- */
+ * Is this a container or a leaf filter object?
+ *
+ * @access protected
+ * @return boolean
+ */
protected function isLeaf()
{
if (count($this->_subfilters) > 0) {
<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4: */
/**
-* File containing the Net_LDAP2_LDIF interface class.
-*
-* PHP version 5
-*
-* @category Net
-* @package Net_LDAP2
-* @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 $
-* @link http://pear.php.net/package/Net_LDAP2/
-*/
+ * File containing the Net_LDAP2_LDIF interface class.
+ *
+ * PHP version 5
+ *
+ * @category Net
+ * @package Net_LDAP2
+ * @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 $
+ * @link http://pear.php.net/package/Net_LDAP2/
+ */
/**
-* Includes
-*/
-require_once 'PEAR.php';
-require_once 'Net/LDAP2.php';
-require_once 'Net/LDAP2/Entry.php';
-require_once 'Net/LDAP2/Util.php';
+ * Includes
+ */
+#require_once 'PEAR.php';
+#require_once 'Net/LDAP2.php';
+#require_once 'Net/LDAP2/Entry.php';
+#require_once 'Net/LDAP2/Util.php';
/**
-* LDIF capabilitys for Net_LDAP2, closely taken from PERLs Net::LDAP
-*
-* It provides a means to convert between Net_LDAP2_Entry objects and LDAP entries
-* represented in LDIF format files. Reading and writing are supported and may
-* manipulate single entries or lists of entries.
-*
-* Usage example:
-* <code>
-* // Read and parse an ldif-file into Net_LDAP2_Entry objects
-* // and print out the DNs. Store the entries for later use.
-* require 'Net/LDAP2/LDIF.php';
-* $options = array(
-* 'onerror' => 'die'
-* );
-* $entries = array();
-* $ldif = new Net_LDAP2_LDIF('test.ldif', 'r', $options);
-* do {
-* $entry = $ldif->read_entry();
-* $dn = $entry->dn();
-* echo " done building entry: $dn\n";
-* array_push($entries, $entry);
-* } while (!$ldif->eof());
-* $ldif->done();
-*
-*
-* // write those entries to another file
-* $ldif = new Net_LDAP2_LDIF('test.out.ldif', 'w', $options);
-* $ldif->write_entry($entries);
-* $ldif->done();
-* </code>
-*
-* @category Net
-* @package Net_LDAP2
-* @author Benedikt Hallinger <beni@php.net>
-* @license http://www.gnu.org/copyleft/lesser.html LGPL
-* @link http://pear.php.net/package/Net_LDAP22/
-* @see http://www.ietf.org/rfc/rfc2849.txt
-* @todo Error handling should be PEARified
-* @todo LDAPv3 controls are not implemented yet
-*/
+ * LDIF capabilitys for Net_LDAP2, closely taken from PERLs Net::LDAP
+ *
+ * It provides a means to convert between Net_LDAP2_Entry objects and LDAP entries
+ * represented in LDIF format files. Reading and writing are supported and may
+ * manipulate single entries or lists of entries.
+ *
+ * Usage example:
+ * <code>
+ * // Read and parse an ldif-file into Net_LDAP2_Entry objects
+ * // and print out the DNs. Store the entries for later use.
+ * require 'Net/LDAP2/LDIF.php';
+ * $options = array(
+ * 'onerror' => 'die'
+ * );
+ * $entries = array();
+ * $ldif = new Net_LDAP2_LDIF('test.ldif', 'r', $options);
+ * do {
+ * $entry = $ldif->read_entry();
+ * $dn = $entry->dn();
+ * echo " done building entry: $dn\n";
+ * array_push($entries, $entry);
+ * } while (!$ldif->eof());
+ * $ldif->done();
+ *
+ *
+ * // write those entries to another file
+ * $ldif = new Net_LDAP2_LDIF('test.out.ldif', 'w', $options);
+ * $ldif->write_entry($entries);
+ * $ldif->done();
+ * </code>
+ *
+ * @category Net
+ * @package Net_LDAP2
+ * @author Benedikt Hallinger <beni@php.net>
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL
+ * @link http://pear.php.net/package/Net_LDAP22/
+ * @see http://www.ietf.org/rfc/rfc2849.txt
+ * @todo Error handling should be PEARified
+ * @todo LDAPv3 controls are not implemented yet
+ */
class Net_LDAP2_LDIF extends PEAR
{
/**
- * Options
- *
- * @access protected
- * @var array
- */
+ * Options
+ *
+ * @access protected
+ * @var array
+ */
protected $_options = array('encode' => 'base64',
'onerror' => null,
'change' => 0,
);
/**
- * Errorcache
- *
- * @access protected
- * @var array
- */
+ * Errorcache
+ *
+ * @access protected
+ * @var array
+ */
protected $_error = array('error' => null,
'line' => 0
);
/**
- * Filehandle for read/write
- *
- * @access protected
- * @var array
- */
+ * Filehandle for read/write
+ *
+ * @access protected
+ * @var array
+ */
protected $_FH = null;
/**
- * Says, if we opened the filehandle ourselves
- *
- * @access protected
- * @var array
- */
+ * Says, if we opened the filehandle ourselves
+ *
+ * @access protected
+ * @var array
+ */
protected $_FH_opened = false;
/**
- * Linecounter for input file handle
- *
- * @access protected
- * @var array
- */
+ * Linecounter for input file handle
+ *
+ * @access protected
+ * @var array
+ */
protected $_input_line = 0;
/**
- * counter for processed entries
- *
- * @access protected
- * @var int
- */
+ * counter for processed entries
+ *
+ * @access protected
+ * @var int
+ */
protected $_entrynum = 0;
/**
- * Mode we are working in
- *
- * Either 'r', 'a' or 'w'
- *
- * @access protected
- * @var string
- */
+ * Mode we are working in
+ *
+ * Either 'r', 'a' or 'w'
+ *
+ * @access protected
+ * @var string
+ */
protected $_mode = false;
/**
- * Tells, if the LDIF version string was already written
- *
- * @access protected
- * @var boolean
- */
+ * Tells, if the LDIF version string was already written
+ *
+ * @access protected
+ * @var boolean
+ */
protected $_version_written = false;
/**
- * Cache for lines that have build the current entry
- *
- * @access protected
- * @var boolean
- */
+ * Cache for lines that have build the current entry
+ *
+ * @access protected
+ * @var boolean
+ */
protected $_lines_cur = array();
/**
- * Cache for lines that will build the next entry
- *
- * @access protected
- * @var boolean
- */
+ * Cache for lines that will build the next entry
+ *
+ * @access protected
+ * @var boolean
+ */
protected $_lines_next = array();
/**
- * Open LDIF file for reading or for writing
- *
- * new (FILE):
- * Open the file read-only. FILE may be the name of a file
- * or an already open filehandle.
- * If the file doesn't exist, it will be created if in write mode.
- *
- * new (FILE, MODE, OPTIONS):
- * Open the file with the given MODE (see PHPs fopen()), eg "w" or "a".
- * FILE may be the name of a file or an already open filehandle.
- * PERLs Net_LDAP2 "FILE|" mode does not work curently.
- *
- * OPTIONS is an associative array and may contain:
- * encode => 'none' | 'canonical' | 'base64'
- * Some DN values in LDIF cannot be written verbatim and have to be encoded in some way:
- * 'none' No encoding.
- * 'canonical' See "canonical_dn()" in Net::LDAP::Util.
- * 'base64' Use base64. (default, this differs from the Perl interface.
- * The perl default is "none"!)
- *
- * onerror => 'die' | 'warn' | NULL
- * Specify what happens when an error is detected.
- * 'die' Net_LDAP2_LDIF will croak with an appropriate message.
- * 'warn' Net_LDAP2_LDIF will warn (echo) with an appropriate message.
- * NULL Net_LDAP2_LDIF will not warn (default), use error().
- *
- * change => 1
- * Write entry changes to the LDIF file instead of the entries itself. I.e. write LDAP
- * operations acting on the entries to the file instead of the entries contents.
- * This writes the changes usually carried out by an update() to the LDIF file.
- *
- * lowercase => 1
- * Convert attribute names to lowercase when writing.
- *
- * sort => 1
- * Sort attribute names when writing entries according to the rule:
- * objectclass first then all other attributes alphabetically sorted by attribute name
- *
- * version => '1'
- * Set the LDIF version to write to the resulting LDIF file.
- * According to RFC 2849 currently the only legal value for this option is 1.
- * When this option is set Net_LDAP2_LDIF tries to adhere more strictly to
- * the LDIF specification in RFC2489 in a few places.
- * The default is NULL meaning no version information is written to the LDIF file.
- *
- * wrap => 78
- * Number of columns where output line wrapping shall occur.
- * Default is 78. Setting it to 40 or lower inhibits wrapping.
- *
- * raw => REGEX
- * Use REGEX to denote the names of attributes that are to be
- * considered binary in search results if writing entries.
- * Example: raw => "/(?i:^jpegPhoto|;binary)/i"
- *
- * @param string|ressource $file Filename or filehandle
- * @param string $mode Mode to open filename
- * @param array $options Options like described above
- */
+ * Open LDIF file for reading or for writing
+ *
+ * new (FILE):
+ * Open the file read-only. FILE may be the name of a file
+ * or an already open filehandle.
+ * If the file doesn't exist, it will be created if in write mode.
+ *
+ * new (FILE, MODE, OPTIONS):
+ * Open the file with the given MODE (see PHPs fopen()), eg "w" or "a".
+ * FILE may be the name of a file or an already open filehandle.
+ * PERLs Net_LDAP2 "FILE|" mode does not work curently.
+ *
+ * OPTIONS is an associative array and may contain:
+ * encode => 'none' | 'canonical' | 'base64'
+ * Some DN values in LDIF cannot be written verbatim and have to be encoded in some way:
+ * 'none' No encoding.
+ * 'canonical' See "canonical_dn()" in Net::LDAP::Util.
+ * 'base64' Use base64. (default, this differs from the Perl interface.
+ * The perl default is "none"!)
+ *
+ * onerror => 'die' | 'warn' | NULL
+ * Specify what happens when an error is detected.
+ * 'die' Net_LDAP2_LDIF will croak with an appropriate message.
+ * 'warn' Net_LDAP2_LDIF will warn (echo) with an appropriate message.
+ * NULL Net_LDAP2_LDIF will not warn (default), use error().
+ *
+ * change => 1
+ * Write entry changes to the LDIF file instead of the entries itself. I.e. write LDAP
+ * operations acting on the entries to the file instead of the entries contents.
+ * This writes the changes usually carried out by an update() to the LDIF file.
+ *
+ * lowercase => 1
+ * Convert attribute names to lowercase when writing.
+ *
+ * sort => 1
+ * Sort attribute names when writing entries according to the rule:
+ * objectclass first then all other attributes alphabetically sorted by attribute name
+ *
+ * version => '1'
+ * Set the LDIF version to write to the resulting LDIF file.
+ * According to RFC 2849 currently the only legal value for this option is 1.
+ * When this option is set Net_LDAP2_LDIF tries to adhere more strictly to
+ * the LDIF specification in RFC2489 in a few places.
+ * The default is NULL meaning no version information is written to the LDIF file.
+ *
+ * wrap => 78
+ * Number of columns where output line wrapping shall occur.
+ * Default is 78. Setting it to 40 or lower inhibits wrapping.
+ *
+ * raw => REGEX
+ * Use REGEX to denote the names of attributes that are to be
+ * considered binary in search results if writing entries.
+ * Example: raw => "/(?i:^jpegPhoto|;binary)/i"
+ *
+ * @param string|ressource $file Filename or filehandle
+ * @param string $mode Mode to open filename
+ * @param array $options Options like described above
+ */
public function __construct($file, $mode = 'r', $options = array())
{
$this->PEAR('Net_LDAP2_Error'); // default error class
}
/**
- * Read one entry from the file and return it as a Net::LDAP::Entry object.
- *
- * @return Net_LDAP2_Entry
- */
+ * Read one entry from the file and return it as a Net::LDAP::Entry object.
+ *
+ * @return Net_LDAP2_Entry
+ */
public function read_entry()
{
// read fresh lines, set them as current lines and create the entry
}
/**
- * Returns true when the end of the file is reached.
- *
- * @return boolean
- */
+ * Returns true when the end of the file is reached.
+ *
+ * @return boolean
+ */
public function eof()
{
return feof($this->_FH);
}
/**
- * Write the entry or entries to the LDIF file.
- *
- * If you want to build an LDIF file containing several entries AND
- * you want to call write_entry() several times, you must open the filehandle
- * in append mode ("a"), otherwise you will always get the last entry only.
- *
- * @param Net_LDAP2_Entry|array $entries Entry or array of entries
- *
- * @return void
- * @todo implement operations on whole entries (adding a whole entry)
- */
+ * Write the entry or entries to the LDIF file.
+ *
+ * If you want to build an LDIF file containing several entries AND
+ * you want to call write_entry() several times, you must open the filehandle
+ * in append mode ("a"), otherwise you will always get the last entry only.
+ *
+ * @param Net_LDAP2_Entry|array $entries Entry or array of entries
+ *
+ * @return void
+ * @todo implement operations on whole entries (adding a whole entry)
+ */
public function write_entry($entries)
{
if (!is_array($entries)) {
}
/**
- * Write version to LDIF
- *
- * If the object's version is defined, this method allows to explicitely write the version before an entry is written.
- * If not called explicitely, it gets called automatically when writing the first entry.
- *
- * @return void
- */
+ * Write version to LDIF
+ *
+ * If the object's version is defined, this method allows to explicitely write the version before an entry is written.
+ * If not called explicitely, it gets called automatically when writing the first entry.
+ *
+ * @return void
+ */
public function write_version()
{
$this->_version_written = true;
}
/**
- * Get or set LDIF version
- *
- * If called without arguments it returns the version of the LDIF file or NULL if no version has been set.
- * If called with an argument it sets the LDIF version to VERSION.
- * According to RFC 2849 currently the only legal value for VERSION is 1.
- *
- * @param int $version (optional) LDIF version to set
- *
- * @return int
- */
+ * Get or set LDIF version
+ *
+ * If called without arguments it returns the version of the LDIF file or NULL if no version has been set.
+ * If called with an argument it sets the LDIF version to VERSION.
+ * According to RFC 2849 currently the only legal value for VERSION is 1.
+ *
+ * @param int $version (optional) LDIF version to set
+ *
+ * @return int
+ */
public function version($version = null)
{
if ($version !== null) {
}
/**
- * Returns the file handle the Net_LDAP2_LDIF object reads from or writes to.
- *
- * You can, for example, use this to fetch the content of the LDIF file yourself
- *
- * @return null|resource
- */
+ * Returns the file handle the Net_LDAP2_LDIF object reads from or writes to.
+ *
+ * You can, for example, use this to fetch the content of the LDIF file yourself
+ *
+ * @return null|resource
+ */
public function &handle()
{
if (!is_resource($this->_FH)) {
}
/**
- * Clean up
- *
- * This method signals that the LDIF object is no longer needed.
- * You can use this to free up some memory and close the file handle.
- * The file handle is only closed, if it was opened from Net_LDAP2_LDIF.
- *
- * @return void
- */
+ * Clean up
+ *
+ * This method signals that the LDIF object is no longer needed.
+ * You can use this to free up some memory and close the file handle.
+ * The file handle is only closed, if it was opened from Net_LDAP2_LDIF.
+ *
+ * @return void
+ */
public function done()
{
// close FH if we opened it
}
/**
- * Returns last error message if error was found.
- *
- * Example:
- * <code>
- * $ldif->someAction();
- * if ($ldif->error()) {
- * echo "Error: ".$ldif->error()." at input line: ".$ldif->error_lines();
- * }
- * </code>
- *
- * @param boolean $as_string If set to true, only the message is returned
- *
- * @return false|Net_LDAP2_Error
- */
+ * Returns last error message if error was found.
+ *
+ * Example:
+ * <code>
+ * $ldif->someAction();
+ * if ($ldif->error()) {
+ * echo "Error: ".$ldif->error()." at input line: ".$ldif->error_lines();
+ * }
+ * </code>
+ *
+ * @param boolean $as_string If set to true, only the message is returned
+ *
+ * @return false|Net_LDAP2_Error
+ */
public function error($as_string = false)
{
if (Net_LDAP2::isError($this->_error['error'])) {
}
/**
- * Returns lines that resulted in error.
- *
- * Perl returns an array of faulty lines in list context,
- * but we always just return an int because of PHPs language.
- *
- * @return int
- */
+ * Returns lines that resulted in error.
+ *
+ * Perl returns an array of faulty lines in list context,
+ * but we always just return an int because of PHPs language.
+ *
+ * @return int
+ */
public function error_lines()
{
return $this->_error['line'];
}
/**
- * Returns the current Net::LDAP::Entry object.
- *
- * @return Net_LDAP2_Entry|false
- */
+ * Returns the current Net::LDAP::Entry object.
+ *
+ * @return Net_LDAP2_Entry|false
+ */
public function current_entry()
{
return $this->parseLines($this->current_lines());
}
/**
- * Parse LDIF lines of one entry into an Net_LDAP2_Entry object
- *
- * @param array $lines LDIF lines for one entry
- *
- * @return Net_LDAP2_Entry|false Net_LDAP2_Entry object for those lines
- * @todo what about file inclusions and urls? "jpegphoto:< file:///usr/local/directory/photos/fiona.jpg"
- */
+ * Parse LDIF lines of one entry into an Net_LDAP2_Entry object
+ *
+ * @param array $lines LDIF lines for one entry
+ *
+ * @return Net_LDAP2_Entry|false Net_LDAP2_Entry object for those lines
+ * @todo what about file inclusions and urls? "jpegphoto:< file:///usr/local/directory/photos/fiona.jpg"
+ */
public function parseLines($lines)
{
// parse lines into an array of attributes and build the entry
}
/**
- * Returns the lines that generated the current Net::LDAP::Entry object.
- *
- * Note that this returns an empty array if no lines have been read so far.
- *
- * @return array Array of lines
- */
+ * Returns the lines that generated the current Net::LDAP::Entry object.
+ *
+ * Note that this returns an empty array if no lines have been read so far.
+ *
+ * @return array Array of lines
+ */
public function current_lines()
{
return $this->_lines_cur;
}
/**
- * Returns the lines that will generate the next Net::LDAP::Entry object.
- *
- * If you set $force to TRUE then you can iterate over the lines that build
- * up entries manually. Otherwise, iterating is done using {@link read_entry()}.
- * Force will move the file pointer forward, thus returning the next entries lines.
- *
- * Wrapped lines will be unwrapped. Comments are stripped.
- *
- * @param boolean $force Set this to true if you want to iterate over the lines manually
- *
- * @return array
- */
+ * Returns the lines that will generate the next Net::LDAP::Entry object.
+ *
+ * If you set $force to TRUE then you can iterate over the lines that build
+ * up entries manually. Otherwise, iterating is done using {@link read_entry()}.
+ * Force will move the file pointer forward, thus returning the next entries lines.
+ *
+ * Wrapped lines will be unwrapped. Comments are stripped.
+ *
+ * @param boolean $force Set this to true if you want to iterate over the lines manually
+ *
+ * @return array
+ */
public function next_lines($force = false)
{
// if we already have those lines, just return them, otherwise read
}
/**
- * Convert an attribute and value to LDIF string representation
- *
- * It honors correct encoding of values according to RFC 2849.
- * Line wrapping will occur at the configured maximum but only if
- * the value is greater than 40 chars.
- *
- * @param string $attr_name Name of the attribute
- * @param string $attr_value Value of the attribute
- *
- * @access protected
- * @return string LDIF string for that attribute and value
- */
+ * Convert an attribute and value to LDIF string representation
+ *
+ * It honors correct encoding of values according to RFC 2849.
+ * Line wrapping will occur at the configured maximum but only if
+ * the value is greater than 40 chars.
+ *
+ * @param string $attr_name Name of the attribute
+ * @param string $attr_value Value of the attribute
+ *
+ * @access protected
+ * @return string LDIF string for that attribute and value
+ */
protected function convertAttribute($attr_name, $attr_value)
{
// Handle empty attribute or process
}
/**
- * Convert an entries DN to LDIF string representation
- *
- * It honors correct encoding of values according to RFC 2849.
- *
- * @param string $dn UTF8-Encoded DN
- *
- * @access protected
- * @return string LDIF string for that DN
- * @todo I am not sure, if the UTF8 stuff is correctly handled right now
- */
+ * Convert an entries DN to LDIF string representation
+ *
+ * It honors correct encoding of values according to RFC 2849.
+ *
+ * @param string $dn UTF8-Encoded DN
+ *
+ * @access protected
+ * @return string LDIF string for that DN
+ * @todo I am not sure, if the UTF8 stuff is correctly handled right now
+ */
protected function convertDN($dn)
{
$base64 = false;
}
/**
- * Writes an attribute to the filehandle
- *
- * @param string $attr_name Name of the attribute
- * @param string|array $attr_values Single attribute value or array with attribute values
- *
- * @access protected
- * @return void
- */
+ * Writes an attribute to the filehandle
+ *
+ * @param string $attr_name Name of the attribute
+ * @param string|array $attr_values Single attribute value or array with attribute values
+ *
+ * @access protected
+ * @return void
+ */
protected function writeAttribute($attr_name, $attr_values)
{
// write out attribute content
}
/**
- * Writes a DN to the filehandle
- *
- * @param string $dn DN to write
- *
- * @access protected
- * @return void
- */
+ * Writes a DN to the filehandle
+ *
+ * @param string $dn DN to write
+ *
+ * @access protected
+ * @return void
+ */
protected function writeDN($dn)
{
// prepare DN
}
/**
- * Finishes an LDIF entry
- *
- * @access protected
- * @return void
- */
+ * Finishes an LDIF entry
+ *
+ * @access protected
+ * @return void
+ */
protected function finishEntry()
{
$this->writeLine(PHP_EOL, 'Net_LDAP2_LDIF error: unable to close entry '.$this->_entrynum);
}
/**
- * Just write an arbitary line to the filehandle
- *
- * @param string $line Content to write
- * @param string $error If error occurs, drop this message
- *
- * @access protected
- * @return true|false
- */
+ * Just write an arbitary line to the filehandle
+ *
+ * @param string $line Content to write
+ * @param string $error If error occurs, drop this message
+ *
+ * @access protected
+ * @return true|false
+ */
protected function writeLine($line, $error = 'Net_LDAP2_LDIF error: unable to write to filehandle')
{
if (is_resource($this->handle()) && fwrite($this->handle(), $line, strlen($line)) === false) {
}
/**
- * Optionally raises an error and pushes the error on the error cache
- *
- * @param string $msg Errortext
- * @param int $line Line in the LDIF that caused the error
- *
- * @access protected
- * @return void
- */
+ * Optionally raises an error and pushes the error on the error cache
+ *
+ * @param string $msg Errortext
+ * @param int $line Line in the LDIF that caused the error
+ *
+ * @access protected
+ * @return void
+ */
protected function dropError($msg, $line = null)
{
$this->_error['error'] = new Net_LDAP2_Error($msg);
<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4: */
/**
-* File containing the Net_LDAP2_RootDSE interface class.
-*
-* PHP version 5
-*
-* @category Net
-* @package Net_LDAP2
-* @author Jan Wagner <wagner@netsols.de>
-* @copyright 2009 Jan Wagner
-* @license http://www.gnu.org/licenses/lgpl-3.0.txt LGPLv3
-* @version SVN: $Id: RootDSE.php 286718 2009-08-03 07:30:49Z beni $
-* @link http://pear.php.net/package/Net_LDAP2/
-*/
+ * File containing the Net_LDAP2_RootDSE interface class.
+ *
+ * PHP version 5
+ *
+ * @category Net
+ * @package Net_LDAP2
+ * @author Jan Wagner <wagner@netsols.de>
+ * @copyright 2009 Jan Wagner
+ * @license http://www.gnu.org/licenses/lgpl-3.0.txt LGPLv3
+ * @version SVN: $Id: RootDSE.php 286718 2009-08-03 07:30:49Z beni $
+ * @link http://pear.php.net/package/Net_LDAP2/
+ */
/**
-* Includes
-*/
-require_once 'PEAR.php';
+ * Includes
+ */
+#require_once 'PEAR.php';
/**
-* Getting the rootDSE entry of a LDAP server
-*
-* @category Net
-* @package Net_LDAP2
-* @author Jan Wagner <wagner@netsols.de>
-* @license http://www.gnu.org/copyleft/lesser.html LGPL
-* @link http://pear.php.net/package/Net_LDAP22/
-*/
+ * Getting the rootDSE entry of a LDAP server
+ *
+ * @category Net
+ * @package Net_LDAP2
+ * @author Jan Wagner <wagner@netsols.de>
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL
+ * @link http://pear.php.net/package/Net_LDAP22/
+ */
class Net_LDAP2_RootDSE extends PEAR
{
/**
- * @access protected
- * @var object Net_LDAP2_Entry
- **/
+ * @access protected
+ * @var object Net_LDAP2_Entry
+ **/
protected $_entry;
/**
- * Class constructor
- *
- * @param Net_LDAP2_Entry &$entry Net_LDAP2_Entry object of the RootDSE
- */
+ * Class constructor
+ *
+ * @param Net_LDAP2_Entry &$entry Net_LDAP2_Entry object of the RootDSE
+ */
protected function __construct(&$entry)
{
$this->_entry = $entry;
}
/**
- * Fetches a RootDSE object from an LDAP connection
- *
- * @param Net_LDAP2 $ldap Directory from which the RootDSE should be fetched
- * @param array $attrs Array of attributes to search for
- *
- * @access static
- * @return Net_LDAP2_RootDSE|Net_LDAP2_Error
- */
+ * Fetches a RootDSE object from an LDAP connection
+ *
+ * @param Net_LDAP2 $ldap Directory from which the RootDSE should be fetched
+ * @param array $attrs Array of attributes to search for
+ *
+ * @access static
+ * @return Net_LDAP2_RootDSE|Net_LDAP2_Error
+ */
public static function fetch($ldap, $attrs = null)
{
if (!$ldap instanceof Net_LDAP2) {
}
/**
- * Gets the requested attribute value
- *
- * Same usuage as {@link Net_LDAP2_Entry::getValue()}
- *
- * @param string $attr Attribute name
- * @param array $options Array of options
- *
- * @access public
- * @return mixed Net_LDAP2_Error object or attribute values
- * @see Net_LDAP2_Entry::get_value()
- */
+ * Gets the requested attribute value
+ *
+ * Same usuage as {@link Net_LDAP2_Entry::getValue()}
+ *
+ * @param string $attr Attribute name
+ * @param array $options Array of options
+ *
+ * @access public
+ * @return mixed Net_LDAP2_Error object or attribute values
+ * @see Net_LDAP2_Entry::get_value()
+ */
public function getValue($attr = '', $options = '')
{
return $this->_entry->get_value($attr, $options);
}
/**
- * Alias function of getValue() for perl-ldap interface
- *
- * @see getValue()
- * @return mixed
- */
+ * Alias function of getValue() for perl-ldap interface
+ *
+ * @see getValue()
+ * @return mixed
+ */
public function get_value()
{
$args = func_get_args();
}
/**
- * Determines if the extension is supported
- *
- * @param array $oids Array of oids to check
- *
- * @access public
- * @return boolean
- */
+ * Determines if the extension is supported
+ *
+ * @param array $oids Array of oids to check
+ *
+ * @access public
+ * @return boolean
+ */
public function supportedExtension($oids)
{
return $this->checkAttr($oids, 'supportedExtension');
}
/**
- * Alias function of supportedExtension() for perl-ldap interface
- *
- * @see supportedExtension()
- * @return boolean
- */
+ * Alias function of supportedExtension() for perl-ldap interface
+ *
+ * @see supportedExtension()
+ * @return boolean
+ */
public function supported_extension()
{
$args = func_get_args();
}
/**
- * Determines if the version is supported
- *
- * @param array $versions Versions to check
- *
- * @access public
- * @return boolean
- */
+ * Determines if the version is supported
+ *
+ * @param array $versions Versions to check
+ *
+ * @access public
+ * @return boolean
+ */
public function supportedVersion($versions)
{
return $this->checkAttr($versions, 'supportedLDAPVersion');
}
/**
- * Alias function of supportedVersion() for perl-ldap interface
- *
- * @see supportedVersion()
- * @return boolean
- */
+ * Alias function of supportedVersion() for perl-ldap interface
+ *
+ * @see supportedVersion()
+ * @return boolean
+ */
public function supported_version()
{
$args = func_get_args();
}
/**
- * Determines if the control is supported
- *
- * @param array $oids Control oids to check
- *
- * @access public
- * @return boolean
- */
+ * Determines if the control is supported
+ *
+ * @param array $oids Control oids to check
+ *
+ * @access public
+ * @return boolean
+ */
public function supportedControl($oids)
{
return $this->checkAttr($oids, 'supportedControl');
}
/**
- * Alias function of supportedControl() for perl-ldap interface
- *
- * @see supportedControl()
- * @return boolean
- */
+ * Alias function of supportedControl() for perl-ldap interface
+ *
+ * @see supportedControl()
+ * @return boolean
+ */
public function supported_control()
{
$args = func_get_args();
}
/**
- * Determines if the sasl mechanism is supported
- *
- * @param array $mechlist SASL mechanisms to check
- *
- * @access public
- * @return boolean
- */
+ * Determines if the sasl mechanism is supported
+ *
+ * @param array $mechlist SASL mechanisms to check
+ *
+ * @access public
+ * @return boolean
+ */
public function supportedSASLMechanism($mechlist)
{
return $this->checkAttr($mechlist, 'supportedSASLMechanisms');
}
/**
- * Alias function of supportedSASLMechanism() for perl-ldap interface
- *
- * @see supportedSASLMechanism()
- * @return boolean
- */
+ * Alias function of supportedSASLMechanism() for perl-ldap interface
+ *
+ * @see supportedSASLMechanism()
+ * @return boolean
+ */
public function supported_sasl_mechanism()
{
$args = func_get_args();
}
/**
- * Checks for existance of value in attribute
- *
- * @param array $values values to check
- * @param string $attr attribute name
- *
- * @access protected
- * @return boolean
- */
+ * Checks for existance of value in attribute
+ *
+ * @param array $values values to check
+ * @param string $attr attribute name
+ *
+ * @access protected
+ * @return boolean
+ */
protected function checkAttr($values, $attr)
{
if (!is_array($values)) $values = array($values);
<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4: */
/**
-* File containing the Net_LDAP2_Schema interface class.
-*
-* PHP version 5
-*
-* @category Net
-* @package Net_LDAP2
-* @author Jan Wagner <wagner@netsols.de>
-* @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 $
-* @link http://pear.php.net/package/Net_LDAP2/
-* @todo see the comment at the end of the file
-*/
+ * File containing the Net_LDAP2_Schema interface class.
+ *
+ * PHP version 5
+ *
+ * @category Net
+ * @package Net_LDAP2
+ * @author Jan Wagner <wagner@netsols.de>
+ * @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 $
+ * @link http://pear.php.net/package/Net_LDAP2/
+ * @todo see the comment at the end of the file
+ */
/**
-* Includes
-*/
-require_once 'PEAR.php';
+ * Includes
+ */
+#require_once 'PEAR.php';
/**
-* Syntax definitions
-*
-* Please don't forget to add binary attributes to isBinary() below
-* to support proper value fetching from Net_LDAP2_Entry
-*/
+ * Syntax definitions
+ *
+ * Please don't forget to add binary attributes to isBinary() below
+ * to support proper value fetching from Net_LDAP2_Entry
+ */
define('NET_LDAP2_SYNTAX_BOOLEAN', '1.3.6.1.4.1.1466.115.121.1.7');
define('NET_LDAP2_SYNTAX_DIRECTORY_STRING', '1.3.6.1.4.1.1466.115.121.1.15');
define('NET_LDAP2_SYNTAX_DISTINGUISHED_NAME', '1.3.6.1.4.1.1466.115.121.1.12');
define('NET_LDAP2_SYNTAX_OCTET_STRING', '1.3.6.1.4.1.1466.115.121.1.40');
/**
-* Load an LDAP Schema and provide information
-*
-* This class takes a Subschema entry, parses this information
-* and makes it available in an array. Most of the code has been
-* inspired by perl-ldap( http://perl-ldap.sourceforge.net).
-* You will find portions of their implementation in here.
-*
-* @category Net
-* @package Net_LDAP2
-* @author Jan Wagner <wagner@netsols.de>
-* @author Benedikt Hallinger <beni@php.net>
-* @license http://www.gnu.org/copyleft/lesser.html LGPL
-* @link http://pear.php.net/package/Net_LDAP22/
-*/
+ * Load an LDAP Schema and provide information
+ *
+ * This class takes a Subschema entry, parses this information
+ * and makes it available in an array. Most of the code has been
+ * inspired by perl-ldap( http://perl-ldap.sourceforge.net).
+ * You will find portions of their implementation in here.
+ *
+ * @category Net
+ * @package Net_LDAP2
+ * @author Jan Wagner <wagner@netsols.de>
+ * @author Benedikt Hallinger <beni@php.net>
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL
+ * @link http://pear.php.net/package/Net_LDAP22/
+ */
class Net_LDAP2_Schema extends PEAR
{
/**
- * Map of entry types to ldap attributes of subschema entry
- *
- * @access public
- * @var array
- */
+ * Map of entry types to ldap attributes of subschema entry
+ *
+ * @access public
+ * @var array
+ */
public $types = array(
'attribute' => 'attributeTypes',
'ditcontentrule' => 'dITContentRules',
);
/**
- * Array of entries belonging to this type
- *
- * @access protected
- * @var array
- */
+ * Array of entries belonging to this type
+ *
+ * @access protected
+ * @var array
+ */
protected $_attributeTypes = array();
protected $_matchingRules = array();
protected $_matchingRuleUse = array();
/**
- * hash of all fetched oids
- *
- * @access protected
- * @var array
- */
+ * hash of all fetched oids
+ *
+ * @access protected
+ * @var array
+ */
protected $_oids = array();
/**
- * Tells if the schema is initialized
- *
- * @access protected
- * @var boolean
- * @see parse(), get()
- */
+ * Tells if the schema is initialized
+ *
+ * @access protected
+ * @var boolean
+ * @see parse(), get()
+ */
protected $_initialized = false;
/**
- * Constructor of the class
- *
- * @access protected
- */
+ * Constructor of the class
+ *
+ * @access protected
+ */
protected function __construct()
{
$this->PEAR('Net_LDAP2_Error'); // default error class
}
/**
- * Fetch the Schema from an LDAP connection
- *
- * @param Net_LDAP2 $ldap LDAP connection
- * @param string $dn (optional) Subschema entry dn
- *
- * @access public
- * @return Net_LDAP2_Schema|NET_LDAP2_Error
- */
+ * Fetch the Schema from an LDAP connection
+ *
+ * @param Net_LDAP2 $ldap LDAP connection
+ * @param string $dn (optional) Subschema entry dn
+ *
+ * @access public
+ * @return Net_LDAP2_Schema|NET_LDAP2_Error
+ */
public function fetch($ldap, $dn = null)
{
if (!$ldap instanceof Net_LDAP2) {
}
/**
- * Return a hash of entries for the given type
- *
- * Returns a hash of entry for th givene type. Types may be:
- * objectclasses, attributes, ditcontentrules, ditstructurerules, matchingrules,
- * matchingruleuses, nameforms, syntaxes
- *
- * @param string $type Type to fetch
- *
- * @access public
- * @return array|Net_LDAP2_Error Array or Net_LDAP2_Error
- */
+ * Return a hash of entries for the given type
+ *
+ * Returns a hash of entry for th givene type. Types may be:
+ * objectclasses, attributes, ditcontentrules, ditstructurerules, matchingrules,
+ * matchingruleuses, nameforms, syntaxes
+ *
+ * @param string $type Type to fetch
+ *
+ * @access public
+ * @return array|Net_LDAP2_Error Array or Net_LDAP2_Error
+ */
public function &getAll($type)
{
$map = array('objectclasses' => &$this->_objectClasses,
}
/**
- * Return a specific entry
- *
- * @param string $type Type of name
- * @param string $name Name or OID to fetch
- *
- * @access public
- * @return mixed Entry or Net_LDAP2_Error
- */
+ * Return a specific entry
+ *
+ * @param string $type Type of name
+ * @param string $name Name or OID to fetch
+ *
+ * @access public
+ * @return mixed Entry or Net_LDAP2_Error
+ */
public function &get($type, $name)
{
if ($this->_initialized) {
/**
- * Fetches attributes that MAY be present in the given objectclass
- *
- * @param string $oc Name or OID of objectclass
- *
- * @access public
- * @return array|Net_LDAP2_Error Array with attributes or Net_LDAP2_Error
- */
+ * Fetches attributes that MAY be present in the given objectclass
+ *
+ * @param string $oc Name or OID of objectclass
+ *
+ * @access public
+ * @return array|Net_LDAP2_Error Array with attributes or Net_LDAP2_Error
+ */
public function may($oc)
{
return $this->_getAttr($oc, 'may');
}
/**
- * Fetches attributes that MUST be present in the given objectclass
- *
- * @param string $oc Name or OID of objectclass
- *
- * @access public
- * @return array|Net_LDAP2_Error Array with attributes or Net_LDAP2_Error
- */
+ * Fetches attributes that MUST be present in the given objectclass
+ *
+ * @param string $oc Name or OID of objectclass
+ *
+ * @access public
+ * @return array|Net_LDAP2_Error Array with attributes or Net_LDAP2_Error
+ */
public function must($oc)
{
return $this->_getAttr($oc, 'must');
}
/**
- * Fetches the given attribute from the given objectclass
- *
- * @param string $oc Name or OID of objectclass
- * @param string $attr Name of attribute to fetch
- *
- * @access protected
- * @return array|Net_LDAP2_Error The attribute or Net_LDAP2_Error
- */
+ * Fetches the given attribute from the given objectclass
+ *
+ * @param string $oc Name or OID of objectclass
+ * @param string $attr Name of attribute to fetch
+ *
+ * @access protected
+ * @return array|Net_LDAP2_Error The attribute or Net_LDAP2_Error
+ */
protected function _getAttr($oc, $attr)
{
$oc = strtolower($oc);
}
/**
- * Returns the name(s) of the immediate superclass(es)
- *
- * @param string $oc Name or OID of objectclass
- *
- * @access public
- * @return array|Net_LDAP2_Error Array of names or Net_LDAP2_Error
- */
+ * Returns the name(s) of the immediate superclass(es)
+ *
+ * @param string $oc Name or OID of objectclass
+ *
+ * @access public
+ * @return array|Net_LDAP2_Error Array of names or Net_LDAP2_Error
+ */
public function superclass($oc)
{
$o = $this->get('objectclass', $oc);
}
/**
- * Parses the schema of the given Subschema entry
- *
- * @param Net_LDAP2_Entry &$entry Subschema entry
- *
- * @access public
- * @return void
- */
+ * Parses the schema of the given Subschema entry
+ *
+ * @param Net_LDAP2_Entry &$entry Subschema entry
+ *
+ * @access public
+ * @return void
+ */
public function parse(&$entry)
{
foreach ($this->types as $type => $attr) {
}
/**
- * Parses an attribute value into a schema entry
- *
- * @param string $value Attribute value
- *
- * @access protected
- * @return array|false Schema entry array or false
- */
+ * Parses an attribute value into a schema entry
+ *
+ * @param string $value Attribute value
+ *
+ * @access protected
+ * @return array|false Schema entry array or false
+ */
protected function &_parse_entry($value)
{
// tokens that have no value associated
}
/**
- * Tokenizes the given value into an array of tokens
- *
- * @param string $value String to parse
- *
- * @access protected
- * @return array Array of tokens
- */
+ * Tokenizes the given value into an array of tokens
+ *
+ * @param string $value String to parse
+ *
+ * @access protected
+ * @return array Array of tokens
+ */
protected function _tokenize($value)
{
$tokens = array(); // array of tokens
$pattern = "/\s* (?:([()]) | ([^'\s()]+) | '((?:[^']+|'[^\s)])*)') \s*/x";
/**
- * This one matches one big pattern wherin only one of the three subpatterns matched
- * We are interested in the subpatterns that matched. If it matched its value will be
- * non-empty and so it is a token. Tokens may be round brackets, a string, or a string
- * enclosed by '
- */
+ * This one matches one big pattern wherin only one of the three subpatterns matched
+ * We are interested in the subpatterns that matched. If it matched its value will be
+ * non-empty and so it is a token. Tokens may be round brackets, a string, or a string
+ * enclosed by '
+ */
preg_match_all($pattern, $value, $matches);
for ($i = 0; $i < count($matches[0]); $i++) { // number of tokens (full pattern match)
}
/**
- * Returns wether a attribute syntax is binary or not
- *
- * This method gets used by Net_LDAP2_Entry to decide which
- * PHP function needs to be used to fetch the value in the
- * proper format (e.g. binary or string)
- *
- * @param string $attribute The name of the attribute (eg.: 'sn')
- *
- * @access public
- * @return boolean
- */
+ * Returns wether a attribute syntax is binary or not
+ *
+ * This method gets used by Net_LDAP2_Entry to decide which
+ * PHP function needs to be used to fetch the value in the
+ * proper format (e.g. binary or string)
+ *
+ * @param string $attribute The name of the attribute (eg.: 'sn')
+ *
+ * @access public
+ * @return boolean
+ */
public function isBinary($attribute)
{
$return = false; // default to false
<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4: */
/**
-* File containing the Net_LDAP2_Search interface class.
-*
-* PHP version 5
-*
-* @category Net
-* @package Net_LDAP2
-* @author Tarjej Huse <tarjei@bergfald.no>
-* @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 $
-* @link http://pear.php.net/package/Net_LDAP2/
-*/
+ * File containing the Net_LDAP2_Search interface class.
+ *
+ * PHP version 5
+ *
+ * @category Net
+ * @package Net_LDAP2
+ * @author Tarjej Huse <tarjei@bergfald.no>
+ * @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 $
+ * @link http://pear.php.net/package/Net_LDAP2/
+ */
/**
-* Includes
-*/
-require_once 'PEAR.php';
+ * Includes
+ */
+#require_once 'PEAR.php';
/**
-* Result set of an LDAP search
-*
-* @category Net
-* @package Net_LDAP2
-* @author Tarjej Huse <tarjei@bergfald.no>
-* @author Benedikt Hallinger <beni@php.net>
-* @license http://www.gnu.org/copyleft/lesser.html LGPL
-* @link http://pear.php.net/package/Net_LDAP22/
-*/
+ * Result set of an LDAP search
+ *
+ * @category Net
+ * @package Net_LDAP2
+ * @author Tarjej Huse <tarjei@bergfald.no>
+ * @author Benedikt Hallinger <beni@php.net>
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL
+ * @link http://pear.php.net/package/Net_LDAP22/
+ */
class Net_LDAP2_Search extends PEAR implements Iterator
{
/**
- * Search result identifier
- *
- * @access protected
- * @var resource
- */
+ * Search result identifier
+ *
+ * @access protected
+ * @var resource
+ */
protected $_search;
/**
- * LDAP resource link
- *
- * @access protected
- * @var resource
- */
+ * LDAP resource link
+ *
+ * @access protected
+ * @var resource
+ */
protected $_link;
/**
- * Net_LDAP2 object
- *
- * A reference of the Net_LDAP2 object for passing to Net_LDAP2_Entry
- *
- * @access protected
- * @var object Net_LDAP2
- */
+ * Net_LDAP2 object
+ *
+ * A reference of the Net_LDAP2 object for passing to Net_LDAP2_Entry
+ *
+ * @access protected
+ * @var object Net_LDAP2
+ */
protected $_ldap;
/**
- * Result entry identifier
- *
- * @access protected
- * @var resource
- */
+ * Result entry identifier
+ *
+ * @access protected
+ * @var resource
+ */
protected $_entry = null;
/**
- * The errorcode the search got
- *
- * Some errorcodes might be of interest, but might not be best handled as errors.
- * examples: 4 - LDAP_SIZELIMIT_EXCEEDED - indicates a huge search.
- * Incomplete results are returned. If you just want to check if there's anything in the search.
- * than this is a point to handle.
- * 32 - no such object - search here returns a count of 0.
- *
- * @access protected
- * @var int
- */
+ * The errorcode the search got
+ *
+ * Some errorcodes might be of interest, but might not be best handled as errors.
+ * examples: 4 - LDAP_SIZELIMIT_EXCEEDED - indicates a huge search.
+ * Incomplete results are returned. If you just want to check if there's anything in the search.
+ * than this is a point to handle.
+ * 32 - no such object - search here returns a count of 0.
+ *
+ * @access protected
+ * @var int
+ */
protected $_errorCode = 0; // if not set - sucess!
/**
- * Cache for all entries already fetched from iterator interface
- *
- * @access protected
- * @var array
- */
+ * Cache for all entries already fetched from iterator interface
+ *
+ * @access protected
+ * @var array
+ */
protected $_iteratorCache = array();
/**
- * What attributes we searched for
- *
- * The $attributes array contains the names of the searched attributes and gets
- * passed from $Net_LDAP2->search() so the Net_LDAP2_Search object can tell
- * what attributes was searched for ({@link searchedAttrs())
- *
- * This variable gets set from the constructor and returned
- * from {@link searchedAttrs()}
- *
- * @access protected
- * @var array
- */
+ * What attributes we searched for
+ *
+ * The $attributes array contains the names of the searched attributes and gets
+ * passed from $Net_LDAP2->search() so the Net_LDAP2_Search object can tell
+ * what attributes was searched for ({@link searchedAttrs())
+ *
+ * This variable gets set from the constructor and returned
+ * from {@link searchedAttrs()}
+ *
+ * @access protected
+ * @var array
+ */
protected $_searchedAttrs = array();
/**
- * Cache variable for storing entries fetched internally
- *
- * This currently is only used by {@link pop_entry()}
- *
- * @access protected
- * @var array
- */
+ * Cache variable for storing entries fetched internally
+ *
+ * This currently is only used by {@link pop_entry()}
+ *
+ * @access protected
+ * @var array
+ */
protected $_entry_cache = false;
/**
- * Constructor
- *
- * @param resource &$search Search result identifier
- * @param Net_LDAP2|resource &$ldap Net_LDAP2 object or just a LDAP-Link resource
- * @param array $attributes (optional) Array with searched attribute names. (see {@link $_searchedAttrs})
- *
- * @access public
- */
+ * Constructor
+ *
+ * @param resource &$search Search result identifier
+ * @param Net_LDAP2|resource &$ldap Net_LDAP2 object or just a LDAP-Link resource
+ * @param array $attributes (optional) Array with searched attribute names. (see {@link $_searchedAttrs})
+ *
+ * @access public
+ */
public function __construct(&$search, &$ldap, $attributes = array())
{
$this->PEAR('Net_LDAP2_Error');
}
/**
- * Returns an array of entry objects
- *
- * @return array Array of entry objects.
- */
+ * Returns an array of entry objects
+ *
+ * @return array Array of entry objects.
+ */
public function entries()
{
$entries = array();
}
/**
- * Get the next entry in the searchresult.
- *
- * This will return a valid Net_LDAP2_Entry object or false, so
- * you can use this method to easily iterate over the entries inside
- * a while loop.
- *
- * @return Net_LDAP2_Entry|false Reference to Net_LDAP2_Entry object or false
- */
+ * Get the next entry in the searchresult.
+ *
+ * This will return a valid Net_LDAP2_Entry object or false, so
+ * you can use this method to easily iterate over the entries inside
+ * a while loop.
+ *
+ * @return Net_LDAP2_Entry|false Reference to Net_LDAP2_Entry object or false
+ */
public function &shiftEntry()
{
if ($this->count() == 0 ) {
}
/**
- * Alias function of shiftEntry() for perl-ldap interface
- *
- * @see shiftEntry()
- * @return Net_LDAP2_Entry|false
- */
+ * Alias function of shiftEntry() for perl-ldap interface
+ *
+ * @see shiftEntry()
+ * @return Net_LDAP2_Entry|false
+ */
public function shift_entry()
{
$args = func_get_args();
}
/**
- * Retrieve the next entry in the searchresult, but starting from last entry
- *
- * This is the opposite to {@link shiftEntry()} and is also very useful
- * to be used inside a while loop.
- *
- * @return Net_LDAP2_Entry|false
- */
+ * Retrieve the next entry in the searchresult, but starting from last entry
+ *
+ * This is the opposite to {@link shiftEntry()} and is also very useful
+ * to be used inside a while loop.
+ *
+ * @return Net_LDAP2_Entry|false
+ */
public function popEntry()
{
if (false === $this->_entry_cache) {
}
/**
- * Alias function of popEntry() for perl-ldap interface
- *
- * @see popEntry()
- * @return Net_LDAP2_Entry|false
- */
+ * Alias function of popEntry() for perl-ldap interface
+ *
+ * @see popEntry()
+ * @return Net_LDAP2_Entry|false
+ */
public function pop_entry()
{
$args = func_get_args();
}
/**
- * Return entries sorted as array
- *
- * This returns a array with sorted entries and the values.
- * Sorting is done with PHPs {@link array_multisort()}.
- * This method relies on {@link as_struct()} to fetch the raw data of the entries.
- *
- * Please note that attribute names are case sensitive!
- *
- * Usage example:
- * <code>
- * // to sort entries first by location, then by surename, but descending:
- * $entries = $search->sorted_as_struct(array('locality','sn'), SORT_DESC);
- * </code>
- *
- * @param array $attrs Array of attribute names to sort; order from left to right.
- * @param int $order Ordering direction, either constant SORT_ASC or SORT_DESC
- *
- * @return array|Net_LDAP2_Error Array with sorted entries or error
- * @todo what about server side sorting as specified in http://www.ietf.org/rfc/rfc2891.txt?
- */
+ * Return entries sorted as array
+ *
+ * This returns a array with sorted entries and the values.
+ * Sorting is done with PHPs {@link array_multisort()}.
+ * This method relies on {@link as_struct()} to fetch the raw data of the entries.
+ *
+ * Please note that attribute names are case sensitive!
+ *
+ * Usage example:
+ * <code>
+ * // to sort entries first by location, then by surename, but descending:
+ * $entries = $search->sorted_as_struct(array('locality','sn'), SORT_DESC);
+ * </code>
+ *
+ * @param array $attrs Array of attribute names to sort; order from left to right.
+ * @param int $order Ordering direction, either constant SORT_ASC or SORT_DESC
+ *
+ * @return array|Net_LDAP2_Error Array with sorted entries or error
+ * @todo what about server side sorting as specified in http://www.ietf.org/rfc/rfc2891.txt?
+ */
public function sorted_as_struct($attrs = array('cn'), $order = SORT_ASC)
{
/*
- * Old Code, suitable and fast for single valued sorting
- * This code should be used if we know that single valued sorting is desired,
- * but we need some method to get that knowledge...
- */
+ * Old Code, suitable and fast for single valued sorting
+ * This code should be used if we know that single valued sorting is desired,
+ * but we need some method to get that knowledge...
+ */
/*
$attrs = array_reverse($attrs);
foreach ($attrs as $attribute) {
}*/
/*
- * New code: complete "client side" sorting
- */
+ * New code: complete "client side" sorting
+ */
// first some parameterchecks
if (!is_array($attrs)) {
return PEAR::raiseError("Sorting failed: Parameterlist must be an array!");
}
/**
- * Return entries sorted as objects
- *
- * This returns a array with sorted Net_LDAP2_Entry objects.
- * The sorting is actually done with {@link sorted_as_struct()}.
- *
- * Please note that attribute names are case sensitive!
- * Also note, that it is (depending on server capabilitys) possible to let
- * the server sort your results. This happens through search controls
- * and is described in detail at {@link http://www.ietf.org/rfc/rfc2891.txt}
- *
- * Usage example:
- * <code>
- * // to sort entries first by location, then by surename, but descending:
- * $entries = $search->sorted(array('locality','sn'), SORT_DESC);
- * </code>
- *
- * @param array $attrs Array of sort attributes to sort; order from left to right.
- * @param int $order Ordering direction, either constant SORT_ASC or SORT_DESC
- *
- * @return array|Net_LDAP2_Error Array with sorted Net_LDAP2_Entries or error
- * @todo Entry object construction could be faster. Maybe we could use one of the factorys instead of fetching the entry again
- */
+ * Return entries sorted as objects
+ *
+ * This returns a array with sorted Net_LDAP2_Entry objects.
+ * The sorting is actually done with {@link sorted_as_struct()}.
+ *
+ * Please note that attribute names are case sensitive!
+ * Also note, that it is (depending on server capabilitys) possible to let
+ * the server sort your results. This happens through search controls
+ * and is described in detail at {@link http://www.ietf.org/rfc/rfc2891.txt}
+ *
+ * Usage example:
+ * <code>
+ * // to sort entries first by location, then by surename, but descending:
+ * $entries = $search->sorted(array('locality','sn'), SORT_DESC);
+ * </code>
+ *
+ * @param array $attrs Array of sort attributes to sort; order from left to right.
+ * @param int $order Ordering direction, either constant SORT_ASC or SORT_DESC
+ *
+ * @return array|Net_LDAP2_Error Array with sorted Net_LDAP2_Entries or error
+ * @todo Entry object construction could be faster. Maybe we could use one of the factorys instead of fetching the entry again
+ */
public function sorted($attrs = array('cn'), $order = SORT_ASC)
{
$return = array();
}
/**
- * Return entries as array
- *
- * This method returns the entries and the selected attributes values as
- * array.
- * The first array level contains all found entries where the keys are the
- * DNs of the entries. The second level arrays contian the entries attributes
- * such that the keys is the lowercased name of the attribute and the values
- * are stored in another indexed array. Note that the attribute values are stored
- * in an array even if there is no or just one value.
- *
- * The array has the following structure:
- * <code>
- * $return = array(
- * 'cn=foo,dc=example,dc=com' => array(
- * 'sn' => array('foo'),
- * 'multival' => array('val1', 'val2', 'valN')
- * )
- * 'cn=bar,dc=example,dc=com' => array(
- * 'sn' => array('bar'),
- * 'multival' => array('val1', 'valN')
- * )
- * )
- * </code>
- *
- * @return array associative result array as described above
- */
+ * Return entries as array
+ *
+ * This method returns the entries and the selected attributes values as
+ * array.
+ * The first array level contains all found entries where the keys are the
+ * DNs of the entries. The second level arrays contian the entries attributes
+ * such that the keys is the lowercased name of the attribute and the values
+ * are stored in another indexed array. Note that the attribute values are stored
+ * in an array even if there is no or just one value.
+ *
+ * The array has the following structure:
+ * <code>
+ * $return = array(
+ * 'cn=foo,dc=example,dc=com' => array(
+ * 'sn' => array('foo'),
+ * 'multival' => array('val1', 'val2', 'valN')
+ * )
+ * 'cn=bar,dc=example,dc=com' => array(
+ * 'sn' => array('bar'),
+ * 'multival' => array('val1', 'valN')
+ * )
+ * )
+ * </code>
+ *
+ * @return array associative result array as described above
+ */
public function as_struct()
{
$return = array();
}
/**
- * Set the search objects resource link
- *
- * @param resource &$search Search result identifier
- *
- * @access public
- * @return void
- */
+ * Set the search objects resource link
+ *
+ * @param resource &$search Search result identifier
+ *
+ * @access public
+ * @return void
+ */
public function setSearch(&$search)
{
$this->_search = $search;
}
/**
- * Set the ldap ressource link
- *
- * @param resource &$link Link identifier
- *
- * @access public
- * @return void
- */
+ * Set the ldap ressource link
+ *
+ * @param resource &$link Link identifier
+ *
+ * @access public
+ * @return void
+ */
public function setLink(&$link)
{
$this->_link = $link;
}
/**
- * Returns the number of entries in the searchresult
- *
- * @return int Number of entries in search.
- */
+ * Returns the number of entries in the searchresult
+ *
+ * @return int Number of entries in search.
+ */
public function count()
{
// this catches the situation where OL returned errno 32 = no such object!
}
/**
- * Get the errorcode the object got in its search.
- *
- * @return int The ldap error number.
- */
+ * Get the errorcode the object got in its search.
+ *
+ * @return int The ldap error number.
+ */
public function getErrorCode()
{
return $this->_errorCode;
}
/**
- * Destructor
- *
- * @access protected
- */
+ * Destructor
+ *
+ * @access protected
+ */
public function _Net_LDAP2_Search()
{
@ldap_free_result($this->_search);
}
/**
- * Closes search result
- *
- * @return void
- */
+ * Closes search result
+ *
+ * @return void
+ */
public function done()
{
$this->_Net_LDAP2_Search();
}
/**
- * Return the attribute names this search selected
- *
- * @return array
- * @see $_searchedAttrs
- * @access protected
- */
+ * Return the attribute names this search selected
+ *
+ * @return array
+ * @see $_searchedAttrs
+ * @access protected
+ */
protected function searchedAttrs()
{
return $this->_searchedAttrs;
}
/**
- * Tells if this search exceeds a sizelimit
- *
- * @return boolean
- */
+ * Tells if this search exceeds a sizelimit
+ *
+ * @return boolean
+ */
public function sizeLimitExceeded()
{
return ($this->getErrorCode() == 4);
/*
- * SPL Iterator interface methods.
- * This interface allows to use Net_LDAP2_Search
- * objects directly inside a foreach loop!
- */
+ * SPL Iterator interface methods.
+ * This interface allows to use Net_LDAP2_Search
+ * objects directly inside a foreach loop!
+ */
/**
- * SPL Iterator interface: Return the current element.
- *
- * The SPL Iterator interface allows you to fetch entries inside
- * a foreach() loop: <code>foreach ($search as $dn => $entry) { ...</code>
- *
- * Of course, you may call {@link current()}, {@link key()}, {@link next()},
- * {@link rewind()} and {@link valid()} yourself.
- *
- * If the search throwed an error, it returns false.
- * False is also returned, if the end is reached
- * In case no call to next() was made, we will issue one,
- * thus returning the first entry.
- *
- * @return Net_LDAP2_Entry|false
- */
+ * SPL Iterator interface: Return the current element.
+ *
+ * The SPL Iterator interface allows you to fetch entries inside
+ * a foreach() loop: <code>foreach ($search as $dn => $entry) { ...</code>
+ *
+ * Of course, you may call {@link current()}, {@link key()}, {@link next()},
+ * {@link rewind()} and {@link valid()} yourself.
+ *
+ * If the search throwed an error, it returns false.
+ * False is also returned, if the end is reached
+ * In case no call to next() was made, we will issue one,
+ * thus returning the first entry.
+ *
+ * @return Net_LDAP2_Entry|false
+ */
public function current()
{
if (count($this->_iteratorCache) == 0) {
}
/**
- * SPL Iterator interface: Return the identifying key (DN) of the current entry.
- *
- * @see current()
- * @return string|false DN of the current entry; false in case no entry is returned by current()
- */
+ * SPL Iterator interface: Return the identifying key (DN) of the current entry.
+ *
+ * @see current()
+ * @return string|false DN of the current entry; false in case no entry is returned by current()
+ */
public function key()
{
$entry = $this->current();
}
/**
- * SPL Iterator interface: Move forward to next entry.
- *
- * After a call to {@link next()}, {@link current()} will return
- * the next entry in the result set.
- *
- * @see current()
- * @return void
- */
+ * SPL Iterator interface: Move forward to next entry.
+ *
+ * After a call to {@link next()}, {@link current()} will return
+ * the next entry in the result set.
+ *
+ * @see current()
+ * @return void
+ */
public function next()
{
// fetch next entry.
}
/**
- * SPL Iterator interface: Check if there is a current element after calls to {@link rewind()} or {@link next()}.
- *
- * Used to check if we've iterated to the end of the collection.
- *
- * @see current()
- * @return boolean FALSE if there's nothing more to iterate over
- */
+ * SPL Iterator interface: Check if there is a current element after calls to {@link rewind()} or {@link next()}.
+ *
+ * Used to check if we've iterated to the end of the collection.
+ *
+ * @see current()
+ * @return boolean FALSE if there's nothing more to iterate over
+ */
public function valid()
{
return ($this->current() instanceof Net_LDAP2_Entry);
}
/**
- * SPL Iterator interface: Rewind the Iterator to the first element.
- *
- * After rewinding, {@link current()} will return the first entry in the result set.
- *
- * @see current()
- * @return void
- */
+ * SPL Iterator interface: Rewind the Iterator to the first element.
+ *
+ * After rewinding, {@link current()} will return the first entry in the result set.
+ *
+ * @see current()
+ * @return void
+ */
public function rewind()
{
reset($this->_iteratorCache);
<?php
-/* vim: set expandtab tabstop=4 shiftwidth=4: */
/**
-* File containing the Net_LDAP2_Util interface class.
-*
-* PHP version 5
-*
-* @category Net
-* @package Net_LDAP2
-* @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 $
-* @link http://pear.php.net/package/Net_LDAP2/
-*/
+ * File containing the Net_LDAP2_Util interface class.
+ *
+ * PHP version 5
+ *
+ * @category Net
+ * @package Net_LDAP2
+ * @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 $
+ * @link http://pear.php.net/package/Net_LDAP2/
+ */
/**
-* Includes
-*/
-require_once 'PEAR.php';
+ * Includes
+ */
+#require_once 'PEAR.php';
/**
-* Utility Class for Net_LDAP2
-*
-* This class servers some functionality to the other classes of Net_LDAP2 but most of
-* the methods can be used separately as well.
-*
-* @category Net
-* @package Net_LDAP2
-* @author Benedikt Hallinger <beni@php.net>
-* @license http://www.gnu.org/copyleft/lesser.html LGPL
-* @link http://pear.php.net/package/Net_LDAP22/
-*/
+ * Utility Class for Net_LDAP2
+ *
+ * This class servers some functionality to the other classes of Net_LDAP2 but most of
+ * the methods can be used separately as well.
+ *
+ * @category Net
+ * @package Net_LDAP2
+ * @author Benedikt Hallinger <beni@php.net>
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL
+ * @link http://pear.php.net/package/Net_LDAP22/
+ */
class Net_LDAP2_Util extends PEAR
{
/**
- * Constructor
- *
- * @access public
- */
+ * Constructor
+ *
+ * @access public
+ */
public function __construct()
{
// We do nothing here, since all methods can be called statically.
}
/**
- * Explodes the given DN into its elements
- *
- * {@link http://www.ietf.org/rfc/rfc2253.txt RFC 2253} says, a Distinguished Name is a sequence
- * of Relative Distinguished Names (RDNs), which themselves
- * are sets of Attributes. For each RDN a array is constructed where the RDN part is stored.
- *
- * For example, the DN 'OU=Sales+CN=J. Smith,DC=example,DC=net' is exploded to:
- * <kbd>array( [0] => array([0] => 'OU=Sales', [1] => 'CN=J. Smith'), [2] => 'DC=example', [3] => 'DC=net' )</kbd>
- *
- * [NOT IMPLEMENTED] DNs might also contain values, which are the bytes of the BER encoding of
- * the X.500 AttributeValue rather than some LDAP string syntax. These values are hex-encoded
- * and prefixed with a #. To distinguish such BER values, ldap_explode_dn uses references to
- * the actual values, e.g. '1.3.6.1.4.1.1466.0=#04024869,DC=example,DC=com' is exploded to:
- * [ { '1.3.6.1.4.1.1466.0' => "\004\002Hi" }, { 'DC' => 'example' }, { 'DC' => 'com' } ];
- * See {@link http://www.vijaymukhi.com/vmis/berldap.htm} for more information on BER.
- *
- * It also performs the following operations on the given DN:
- * - Unescape "\" followed by ",", "+", """, "\", "<", ">", ";", "#", "=", " ", or a hexpair
- * and strings beginning with "#".
- * - Removes the leading 'OID.' characters if the type is an OID instead of a name.
- * - If an RDN contains multiple parts, the parts are re-ordered so that the attribute type names are in alphabetical order.
- *
- * OPTIONS is a list of name/value pairs, valid options are:
- * casefold Controls case folding of attribute types names.
- * Attribute values are not affected by this option.
- * The default is to uppercase. Valid values are:
- * lower Lowercase attribute types names.
- * upper Uppercase attribute type names. This is the default.
- * none Do not change attribute type names.
- * reverse If TRUE, the RDN sequence is reversed.
- * onlyvalues If TRUE, then only attributes values are returned ('foo' instead of 'cn=foo')
- *
-
- * @param string $dn The DN that should be exploded
- * @param array $options Options to use
- *
- * @static
- * @return array Parts of the exploded DN
- * @todo implement BER
- */
+ * Explodes the given DN into its elements
+ *
+ * {@link http://www.ietf.org/rfc/rfc2253.txt RFC 2253} says, a Distinguished Name is a sequence
+ * of Relative Distinguished Names (RDNs), which themselves
+ * are sets of Attributes. For each RDN a array is constructed where the RDN part is stored.
+ *
+ * For example, the DN 'OU=Sales+CN=J. Smith,DC=example,DC=net' is exploded to:
+ * <kbd>array( [0] => array([0] => 'OU=Sales', [1] => 'CN=J. Smith'), [2] => 'DC=example', [3] => 'DC=net' )</kbd>
+ *
+ * [NOT IMPLEMENTED] DNs might also contain values, which are the bytes of the BER encoding of
+ * the X.500 AttributeValue rather than some LDAP string syntax. These values are hex-encoded
+ * and prefixed with a #. To distinguish such BER values, ldap_explode_dn uses references to
+ * the actual values, e.g. '1.3.6.1.4.1.1466.0=#04024869,DC=example,DC=com' is exploded to:
+ * [ { '1.3.6.1.4.1.1466.0' => "\004\002Hi" }, { 'DC' => 'example' }, { 'DC' => 'com' } ];
+ * See {@link http://www.vijaymukhi.com/vmis/berldap.htm} for more information on BER.
+ *
+ * It also performs the following operations on the given DN:
+ * - Unescape "\" followed by ",", "+", """, "\", "<", ">", ";", "#", "=", " ", or a hexpair
+ * and strings beginning with "#".
+ * - Removes the leading 'OID.' characters if the type is an OID instead of a name.
+ * - If an RDN contains multiple parts, the parts are re-ordered so that the attribute type names are in alphabetical order.
+ *
+ * OPTIONS is a list of name/value pairs, valid options are:
+ * casefold Controls case folding of attribute types names.
+ * Attribute values are not affected by this option.
+ * The default is to uppercase. Valid values are:
+ * lower Lowercase attribute types names.
+ * upper Uppercase attribute type names. This is the default.
+ * none Do not change attribute type names.
+ * reverse If TRUE, the RDN sequence is reversed.
+ * onlyvalues If TRUE, then only attributes values are returned ('foo' instead of 'cn=foo')
+ *
+
+ * @param string $dn The DN that should be exploded
+ * @param array $options Options to use
+ *
+ * @static
+ * @return array Parts of the exploded DN
+ * @todo implement BER
+ */
public static function ldap_explode_dn($dn, $options = array('casefold' => 'upper'))
{
if (!isset($options['onlyvalues'])) $options['onlyvalues'] = false;
}
/**
- * Escapes a DN value according to RFC 2253
- *
- * Escapes the given VALUES according to RFC 2253 so that they can be safely used in LDAP DNs.
- * The characters ",", "+", """, "\", "<", ">", ";", "#", "=" with a special meaning in RFC 2252
- * are preceeded by ba backslash. Control characters with an ASCII code < 32 are represented as \hexpair.
- * Finally all leading and trailing spaces are converted to sequences of \20.
- *
- * @param array $values An array containing the DN values that should be escaped
- *
- * @static
- * @return array The array $values, but escaped
- */
+ * Escapes a DN value according to RFC 2253
+ *
+ * Escapes the given VALUES according to RFC 2253 so that they can be safely used in LDAP DNs.
+ * The characters ",", "+", """, "\", "<", ">", ";", "#", "=" with a special meaning in RFC 2252
+ * are preceeded by ba backslash. Control characters with an ASCII code < 32 are represented as \hexpair.
+ * Finally all leading and trailing spaces are converted to sequences of \20.
+ *
+ * @param array $values An array containing the DN values that should be escaped
+ *
+ * @static
+ * @return array The array $values, but escaped
+ */
public static function escape_dn_value($values = array())
{
// Parameter validation
}
/**
- * Undoes the conversion done by escape_dn_value().
- *
- * Any escape sequence starting with a baskslash - hexpair or special character -
- * will be transformed back to the corresponding character.
- *
- * @param array $values Array of DN Values
- *
- * @return array Same as $values, but unescaped
- * @static
- */
+ * Undoes the conversion done by escape_dn_value().
+ *
+ * Any escape sequence starting with a baskslash - hexpair or special character -
+ * will be transformed back to the corresponding character.
+ *
+ * @param array $values Array of DN Values
+ *
+ * @return array Same as $values, but unescaped
+ * @static
+ */
public static function unescape_dn_value($values = array())
{
// Parameter validation
}
/**
- * Returns the given DN in a canonical form
- *
- * Returns false if DN is not a valid Distinguished Name.
- * DN can either be a string or an array
- * as returned by ldap_explode_dn, which is useful when constructing a DN.
- * The DN array may have be indexed (each array value is a OCL=VALUE pair)
- * or associative (array key is OCL and value is VALUE).
- *
- * It performs the following operations on the given DN:
- * - Removes the leading 'OID.' characters if the type is an OID instead of a name.
- * - Escapes all RFC 2253 special characters (",", "+", """, "\", "<", ">", ";", "#", "="), slashes ("/"), and any other character where the ASCII code is < 32 as \hexpair.
- * - Converts all leading and trailing spaces in values to be \20.
- * - If an RDN contains multiple parts, the parts are re-ordered so that the attribute type names are in alphabetical order.
- *
- * OPTIONS is a list of name/value pairs, valid options are:
- * casefold Controls case folding of attribute type names.
- * Attribute values are not affected by this option. The default is to uppercase.
- * Valid values are:
- * lower Lowercase attribute type names.
- * upper Uppercase attribute type names. This is the default.
- * none Do not change attribute type names.
- * [NOT IMPLEMENTED] mbcescape If TRUE, characters that are encoded as a multi-octet UTF-8 sequence will be escaped as \(hexpair){2,*}.
- * reverse If TRUE, the RDN sequence is reversed.
- * separator Separator to use between RDNs. Defaults to comma (',').
- *
- * Note: The empty string "" is a valid DN, so be sure not to do a "$can_dn == false" test,
- * because an empty string evaluates to false. Use the "===" operator instead.
- *
- * @param array|string $dn The DN
- * @param array $options Options to use
- *
- * @static
- * @return false|string The canonical DN or FALSE
- * @todo implement option mbcescape
- */
+ * Returns the given DN in a canonical form
+ *
+ * Returns false if DN is not a valid Distinguished Name.
+ * DN can either be a string or an array
+ * as returned by ldap_explode_dn, which is useful when constructing a DN.
+ * The DN array may have be indexed (each array value is a OCL=VALUE pair)
+ * or associative (array key is OCL and value is VALUE).
+ *
+ * It performs the following operations on the given DN:
+ * - Removes the leading 'OID.' characters if the type is an OID instead of a name.
+ * - Escapes all RFC 2253 special characters (",", "+", """, "\", "<", ">", ";", "#", "="), slashes ("/"), and any other character where the ASCII code is < 32 as \hexpair.
+ * - Converts all leading and trailing spaces in values to be \20.
+ * - If an RDN contains multiple parts, the parts are re-ordered so that the attribute type names are in alphabetical order.
+ *
+ * OPTIONS is a list of name/value pairs, valid options are:
+ * casefold Controls case folding of attribute type names.
+ * Attribute values are not affected by this option. The default is to uppercase.
+ * Valid values are:
+ * lower Lowercase attribute type names.
+ * upper Uppercase attribute type names. This is the default.
+ * none Do not change attribute type names.
+ * [NOT IMPLEMENTED] mbcescape If TRUE, characters that are encoded as a multi-octet UTF-8 sequence will be escaped as \(hexpair){2,*}.
+ * reverse If TRUE, the RDN sequence is reversed.
+ * separator Separator to use between RDNs. Defaults to comma (',').
+ *
+ * Note: The empty string "" is a valid DN, so be sure not to do a "$can_dn == false" test,
+ * because an empty string evaluates to false. Use the "===" operator instead.
+ *
+ * @param array|string $dn The DN
+ * @param array $options Options to use
+ *
+ * @static
+ * @return false|string The canonical DN or FALSE
+ * @todo implement option mbcescape
+ */
public static function canonical_dn($dn, $options = array('casefold' => 'upper', 'separator' => ','))
{
if ($dn === '') return $dn; // empty DN is valid!
}
/**
- * Escapes the given VALUES according to RFC 2254 so that they can be safely used in LDAP filters.
- *
- * Any control characters with an ACII code < 32 as well as the characters with special meaning in
- * LDAP filters "*", "(", ")", and "\" (the backslash) are converted into the representation of a
- * backslash followed by two hex digits representing the hexadecimal value of the character.
- *
- * @param array $values Array of values to escape
- *
- * @static
- * @return array Array $values, but escaped
- */
+ * Escapes the given VALUES according to RFC 2254 so that they can be safely used in LDAP filters.
+ *
+ * Any control characters with an ACII code < 32 as well as the characters with special meaning in
+ * LDAP filters "*", "(", ")", and "\" (the backslash) are converted into the representation of a
+ * backslash followed by two hex digits representing the hexadecimal value of the character.
+ *
+ * @param array $values Array of values to escape
+ *
+ * @static
+ * @return array Array $values, but escaped
+ */
public static function escape_filter_value($values = array())
{
// Parameter validation
}
/**
- * Undoes the conversion done by {@link escape_filter_value()}.
- *
- * Converts any sequences of a backslash followed by two hex digits into the corresponding character.
- *
- * @param array $values Array of values to escape
- *
- * @static
- * @return array Array $values, but unescaped
- */
+ * Undoes the conversion done by {@link escape_filter_value()}.
+ *
+ * Converts any sequences of a backslash followed by two hex digits into the corresponding character.
+ *
+ * @param array $values Array of values to escape
+ *
+ * @static
+ * @return array Array $values, but unescaped
+ */
public static function unescape_filter_value($values = array())
{
// Parameter validation
}
/**
- * Converts all ASCII chars < 32 to "\HEX"
- *
- * @param string $string String to convert
- *
- * @static
- * @return string
- */
+ * Converts all ASCII chars < 32 to "\HEX"
+ *
+ * @param string $string String to convert
+ *
+ * @static
+ * @return string
+ */
public static function asc2hex32($string)
{
for ($i = 0; $i < strlen($string); $i++) {
}
/**
- * Converts all Hex expressions ("\HEX") to their original ASCII characters
- *
- * @param string $string String to convert
- *
- * @static
- * @author beni@php.net, heavily based on work from DavidSmith@byu.net
- * @return string
- */
+ * Converts all Hex expressions ("\HEX") to their original ASCII characters
+ *
+ * @param string $string String to convert
+ *
+ * @static
+ * @author beni@php.net, heavily based on work from DavidSmith@byu.net
+ * @return string
+ */
public static function hex2asc($string)
{
$string = preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''", $string);
}
/**
- * Split an multivalued RDN value into an Array
- *
- * A RDN can contain multiple values, spearated by a plus sign.
- * This function returns each separate ocl=value pair of the RDN part.
- *
- * If no multivalued RDN is detected, an array containing only
- * the original rdn part is returned.
- *
- * For example, the multivalued RDN 'OU=Sales+CN=J. Smith' is exploded to:
- * <kbd>array([0] => 'OU=Sales', [1] => 'CN=J. Smith')</kbd>
- *
- * The method trys to be smart if it encounters unescaped "+" characters, but may fail,
- * so ensure escaped "+"es in attr names and attr values.
- *
- * [BUG] If you have a multivalued RDN with unescaped plus characters
- * and there is a unescaped plus sign at the end of an value followed by an
- * attribute name containing an unescaped plus, then you will get wrong splitting:
- * $rdn = 'OU=Sales+C+N=J. Smith';
- * returns:
- * array('OU=Sales+C', 'N=J. Smith');
- * The "C+" is treaten as value of the first pair instead as attr name of the second pair.
- * To prevent this, escape correctly.
- *
- * @param string $rdn Part of an (multivalued) escaped RDN (eg. ou=foo OR ou=foo+cn=bar)
- *
- * @static
- * @return array Array with the components of the multivalued RDN or Error
- */
+ * Split an multivalued RDN value into an Array
+ *
+ * A RDN can contain multiple values, spearated by a plus sign.
+ * This function returns each separate ocl=value pair of the RDN part.
+ *
+ * If no multivalued RDN is detected, an array containing only
+ * the original rdn part is returned.
+ *
+ * For example, the multivalued RDN 'OU=Sales+CN=J. Smith' is exploded to:
+ * <kbd>array([0] => 'OU=Sales', [1] => 'CN=J. Smith')</kbd>
+ *
+ * The method trys to be smart if it encounters unescaped "+" characters, but may fail,
+ * so ensure escaped "+"es in attr names and attr values.
+ *
+ * [BUG] If you have a multivalued RDN with unescaped plus characters
+ * and there is a unescaped plus sign at the end of an value followed by an
+ * attribute name containing an unescaped plus, then you will get wrong splitting:
+ * $rdn = 'OU=Sales+C+N=J. Smith';
+ * returns:
+ * array('OU=Sales+C', 'N=J. Smith');
+ * The "C+" is treaten as value of the first pair instead as attr name of the second pair.
+ * To prevent this, escape correctly.
+ *
+ * @param string $rdn Part of an (multivalued) escaped RDN (eg. ou=foo OR ou=foo+cn=bar)
+ *
+ * @static
+ * @return array Array with the components of the multivalued RDN or Error
+ */
public static function split_rdn_multival($rdn)
{
$rdns = preg_split('/(?<!\\\\)\+/', $rdn);
}
/**
- * Splits a attribute=value syntax into an array
- *
- * The split will occur at the first unescaped '=' character.
- *
- * @param string $attr Attribute and Value Syntax
- *
- * @return array Indexed array: 0=attribute name, 1=attribute value
- */
+ * Splits a attribute=value syntax into an array
+ *
+ * The split will occur at the first unescaped '=' character.
+ *
+ * @param string $attr Attribute and Value Syntax
+ *
+ * @return array Indexed array: 0=attribute name, 1=attribute value
+ */
public static function split_attribute_string($attr)
{
return preg_split('/(?<!\\\\)=/', $attr, 2);
}
/**
- * Corrects splitting of dn parts
- *
- * @param array $dn Raw DN array
- * @param array $separator Separator that was used when splitting
- *
- * @return array Corrected array
- * @access protected
- */
+ * Corrects splitting of dn parts
+ *
+ * @param array $dn Raw DN array
+ * @param array $separator Separator that was used when splitting
+ *
+ * @return array Corrected array
+ * @access protected
+ */
protected static function correct_dn_splitting($dn = array(), $separator = ',')
{
foreach ($dn as $key => $dn_value) {
}
return array_values($dn);
}
-}
-
-?>
+}
\ No newline at end of file