1<?php 2/* vim: set expandtab tabstop=4 shiftwidth=4: */ 3/** 4* File containing the Net_LDAP2_RootDSE interface class. 5* 6* PHP version 5 7* 8* @category Net 9* @package Net_LDAP2 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$ 14* @link http://pear.php.net/package/Net_LDAP2/ 15*/ 16 17/** 18* Includes 19*/ 20require_once 'PEAR.php'; 21 22/** 23* Getting the rootDSE entry of a LDAP server 24* 25* @category Net 26* @package Net_LDAP2 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/ 30*/ 31class Net_LDAP2_RootDSE extends PEAR 32{ 33 /** 34 * @access protected 35 * @var object Net_LDAP2_Entry 36 **/ 37 protected $_entry; 38 39 /** 40 * Class constructor 41 * 42 * @param Net_LDAP2_Entry &$entry Net_LDAP2_Entry object of the RootDSE 43 */ 44 public function __construct(&$entry) 45 { 46 $this->_entry = $entry; 47 } 48 49 /** 50 * Fetches a RootDSE object from an LDAP connection 51 * 52 * @param Net_LDAP2 $ldap Directory from which the RootDSE should be fetched 53 * @param array $attrs Array of attributes to search for 54 * 55 * @access static 56 * @return Net_LDAP2_RootDSE|Net_LDAP2_Error 57 */ 58 public static function fetch($ldap, $attrs = null) 59 { 60 if (!$ldap instanceof Net_LDAP2) { 61 return PEAR::raiseError("Unable to fetch Schema: Parameter \$ldap must be a Net_LDAP2 object!"); 62 } 63 64 if (is_array($attrs) && count($attrs) > 0 ) { 65 $attributes = $attrs; 66 } else { 67 $attributes = array('vendorName', 68 'vendorVersion', 69 'namingContexts', 70 'altServer', 71 'supportedExtension', 72 'supportedControl', 73 'supportedSASLMechanisms', 74 'supportedLDAPVersion', 75 'subschemaSubentry' ); 76 } 77 $result = $ldap->search('', '(objectClass=*)', array('attributes' => $attributes, 'scope' => 'base')); 78 if (self::isError($result)) { 79 return $result; 80 } 81 $entry = $result->shiftEntry(); 82 if (false === $entry) { 83 return PEAR::raiseError('Could not fetch RootDSE entry'); 84 } 85 $ret = new Net_LDAP2_RootDSE($entry); 86 return $ret; 87 } 88 89 /** 90 * Gets the requested attribute value 91 * 92 * Same usuage as {@link Net_LDAP2_Entry::getValue()} 93 * 94 * @param string $attr Attribute name 95 * @param array $options Array of options 96 * 97 * @access public 98 * @return mixed Net_LDAP2_Error object or attribute values 99 * @see Net_LDAP2_Entry::get_value() 100 */ 101 public function getValue($attr = '', $options = '') 102 { 103 return $this->_entry->get_value($attr, $options); 104 } 105 106 /** 107 * Alias function of getValue() for perl-ldap interface 108 * 109 * @see getValue() 110 * @return mixed 111 */ 112 public function get_value() 113 { 114 $args = func_get_args(); 115 return call_user_func_array(array( &$this, 'getValue' ), $args); 116 } 117 118 /** 119 * Determines if the extension is supported 120 * 121 * @param array $oids Array of oids to check 122 * 123 * @access public 124 * @return boolean 125 */ 126 public function supportedExtension($oids) 127 { 128 return $this->checkAttr($oids, 'supportedExtension'); 129 } 130 131 /** 132 * Alias function of supportedExtension() for perl-ldap interface 133 * 134 * @see supportedExtension() 135 * @return boolean 136 */ 137 public function supported_extension() 138 { 139 $args = func_get_args(); 140 return call_user_func_array(array( &$this, 'supportedExtension'), $args); 141 } 142 143 /** 144 * Determines if the version is supported 145 * 146 * @param array $versions Versions to check 147 * 148 * @access public 149 * @return boolean 150 */ 151 public function supportedVersion($versions) 152 { 153 return $this->checkAttr($versions, 'supportedLDAPVersion'); 154 } 155 156 /** 157 * Alias function of supportedVersion() for perl-ldap interface 158 * 159 * @see supportedVersion() 160 * @return boolean 161 */ 162 public function supported_version() 163 { 164 $args = func_get_args(); 165 return call_user_func_array(array(&$this, 'supportedVersion'), $args); 166 } 167 168 /** 169 * Determines if the control is supported 170 * 171 * @param array $oids Control oids to check 172 * 173 * @access public 174 * @return boolean 175 */ 176 public function supportedControl($oids) 177 { 178 return $this->checkAttr($oids, 'supportedControl'); 179 } 180 181 /** 182 * Alias function of supportedControl() for perl-ldap interface 183 * 184 * @see supportedControl() 185 * @return boolean 186 */ 187 public function supported_control() 188 { 189 $args = func_get_args(); 190 return call_user_func_array(array(&$this, 'supportedControl' ), $args); 191 } 192 193 /** 194 * Determines if the sasl mechanism is supported 195 * 196 * @param array $mechlist SASL mechanisms to check 197 * 198 * @access public 199 * @return boolean 200 */ 201 public function supportedSASLMechanism($mechlist) 202 { 203 return $this->checkAttr($mechlist, 'supportedSASLMechanisms'); 204 } 205 206 /** 207 * Alias function of supportedSASLMechanism() for perl-ldap interface 208 * 209 * @see supportedSASLMechanism() 210 * @return boolean 211 */ 212 public function supported_sasl_mechanism() 213 { 214 $args = func_get_args(); 215 return call_user_func_array(array(&$this, 'supportedSASLMechanism'), $args); 216 } 217 218 /** 219 * Checks for existance of value in attribute 220 * 221 * @param array $values values to check 222 * @param string $attr attribute name 223 * 224 * @access protected 225 * @return boolean 226 */ 227 protected function checkAttr($values, $attr) 228 { 229 if (!is_array($values)) $values = array($values); 230 231 foreach ($values as $value) { 232 if (!@in_array($value, $this->get_value($attr, 'all'))) { 233 return false; 234 } 235 } 236 return true; 237 } 238} 239 240?> 241