RootDSE.php 6.1 KB

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