2 /* vim: set expandtab tabstop=4 shiftwidth=4: */
4 * File containing the Net_LDAP2_RootDSE interface class.
10 * @author Jan Wagner <wagner@netsols.de>
11 * @copyright 2009 Jan Wagner
12 * @license http://www.gnu.org/licenses/lgpl-3.0.txt LGPLv3
13 * @version SVN: $Id: RootDSE.php 286718 2009-08-03 07:30:49Z beni $
14 * @link http://pear.php.net/package/Net_LDAP2/
20 require_once 'PEAR.php';
23 * Getting the rootDSE entry of a LDAP server
27 * @author Jan Wagner <wagner@netsols.de>
28 * @license http://www.gnu.org/copyleft/lesser.html LGPL
29 * @link http://pear.php.net/package/Net_LDAP22/
31 class Net_LDAP2_RootDSE extends PEAR
35 * @var object Net_LDAP2_Entry
42 * @param Net_LDAP2_Entry &$entry Net_LDAP2_Entry object of the RootDSE
44 protected function __construct(&$entry)
46 $this->_entry = $entry;
50 * Fetches a RootDSE object from an LDAP connection
52 * @param Net_LDAP2 $ldap Directory from which the RootDSE should be fetched
53 * @param array $attrs Array of attributes to search for
56 * @return Net_LDAP2_RootDSE|Net_LDAP2_Error
58 public static function fetch($ldap, $attrs = null)
60 if (!$ldap instanceof Net_LDAP2) {
61 return PEAR::raiseError("Unable to fetch Schema: Parameter \$ldap must be a Net_LDAP2 object!");
64 if (is_array($attrs) && count($attrs) > 0 ) {
67 $attributes = array('vendorName',
73 'supportedSASLMechanisms',
74 'supportedLDAPVersion',
75 'subschemaSubentry' );
77 $result = $ldap->search('', '(objectClass=*)', array('attributes' => $attributes, 'scope' => 'base'));
78 if (self::isError($result)) {
81 $entry = $result->shiftEntry();
82 if (false === $entry) {
83 return PEAR::raiseError('Could not fetch RootDSE entry');
85 $ret = new Net_LDAP2_RootDSE($entry);
90 * Gets the requested attribute value
92 * Same usuage as {@link Net_LDAP2_Entry::getValue()}
94 * @param string $attr Attribute name
95 * @param array $options Array of options
98 * @return mixed Net_LDAP2_Error object or attribute values
99 * @see Net_LDAP2_Entry::get_value()
101 public function getValue($attr = '', $options = '')
103 return $this->_entry->get_value($attr, $options);
107 * Alias function of getValue() for perl-ldap interface
112 public function get_value()
114 $args = func_get_args();
115 return call_user_func_array(array( &$this, 'getValue' ), $args);
119 * Determines if the extension is supported
121 * @param array $oids Array of oids to check
126 public function supportedExtension($oids)
128 return $this->checkAttr($oids, 'supportedExtension');
132 * Alias function of supportedExtension() for perl-ldap interface
134 * @see supportedExtension()
137 public function supported_extension()
139 $args = func_get_args();
140 return call_user_func_array(array( &$this, 'supportedExtension'), $args);
144 * Determines if the version is supported
146 * @param array $versions Versions to check
151 public function supportedVersion($versions)
153 return $this->checkAttr($versions, 'supportedLDAPVersion');
157 * Alias function of supportedVersion() for perl-ldap interface
159 * @see supportedVersion()
162 public function supported_version()
164 $args = func_get_args();
165 return call_user_func_array(array(&$this, 'supportedVersion'), $args);
169 * Determines if the control is supported
171 * @param array $oids Control oids to check
176 public function supportedControl($oids)
178 return $this->checkAttr($oids, 'supportedControl');
182 * Alias function of supportedControl() for perl-ldap interface
184 * @see supportedControl()
187 public function supported_control()
189 $args = func_get_args();
190 return call_user_func_array(array(&$this, 'supportedControl' ), $args);
194 * Determines if the sasl mechanism is supported
196 * @param array $mechlist SASL mechanisms to check
201 public function supportedSASLMechanism($mechlist)
203 return $this->checkAttr($mechlist, 'supportedSASLMechanisms');
207 * Alias function of supportedSASLMechanism() for perl-ldap interface
209 * @see supportedSASLMechanism()
212 public function supported_sasl_mechanism()
214 $args = func_get_args();
215 return call_user_func_array(array(&$this, 'supportedSASLMechanism'), $args);
219 * Checks for existance of value in attribute
221 * @param array $values values to check
222 * @param string $attr attribute name
227 protected function checkAttr($values, $attr)
229 if (!is_array($values)) $values = array($values);
231 foreach ($values as $value) {
232 if (!@in_array($value, $this->get_value($attr, 'all'))) {