Commit 0f8a8317aef85034207100c06b1fdbe5fb526ca5

Authored by Megan Watson
1 parent 56bb238d

KTC-378

"A Pear fatal error when attempting to create a new authentication provider"
Fixed. Made the isError function static as it inherits from PEAR::isError which was made static.

Committed by: Megan Watson
Reviewed by: Conrad Vermeulen



git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@8112 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 80 additions and 80 deletions
thirdparty/pear/Net/LDAP.php
... ... @@ -31,7 +31,7 @@ require_once('LDAP/Search.php');
31 31  
32 32  
33 33 /**
34   - * Error constants for errors that are not LDAP errors
  34 + * Error constants for errors that are not LDAP errors
35 35 */
36 36  
37 37 define ('NET_LDAP_ERROR', 1000);
... ... @@ -89,7 +89,7 @@ define ('NET_LDAP_ERROR', 1000);
89 89 * @var string
90 90 */
91 91 var $_version = "0.6.6";
92   -
  92 +
93 93 /**
94 94 * Net_LDAP_Schema object
95 95 *
... ... @@ -97,7 +97,7 @@ define ('NET_LDAP_ERROR', 1000);
97 97 * @var object Net_LDAP_Schema
98 98 */
99 99 var $_schema = null;
100   -
  100 +
101 101 /**
102 102 * Cache for attribute encoding checks
103 103 *
... ... @@ -120,17 +120,17 @@ define ('NET_LDAP_ERROR', 1000);
120 120 function Net_LDAP($_config = array())
121 121 {
122 122 $this->PEAR('Net_LDAP_Error');
123   -
  123 +
124 124 foreach ($_config as $k => $v) {
125 125 $this->_config[$k] = $v;
126 126 }
127 127 }
128   -
  128 +
129 129 /**
130 130 * Creates the initial ldap-object
131 131 *
132 132 * Static function that returns either an error object or the new Net_LDAP object.
133   - * Something like a factory. Takes a config array with the needed parameters.
  133 + * Something like a factory. Takes a config array with the needed parameters.
134 134 *
135 135 * @access public
136 136 * @param array Configuration array
... ... @@ -173,20 +173,20 @@ define ('NET_LDAP_ERROR', 1000);
173 173 return $this->raiseError("Host not defined in config. {$this->_config['host']}");
174 174 }
175 175  
176   - if (!$this->_link) {
  176 + if (!$this->_link) {
177 177 // there is no good errorcode for this one! I chose 52.
178 178 return $this->raiseError("Could not connect to server. ldap_connect failed.", 52);
179 179 }
180 180 // You must set the version and start tls BEFORE binding!
181   -
  181 +
182 182 if ($this->_config['version'] != 2 && Net_LDAP::isError($msg = $this->setLDAPVersion())) {
183 183 return $msg;
184 184 }
185   -
  185 +
186 186 if ($this->_config['tls'] && Net_LDAP::isError($msg = $this->startTLS())) {
187 187 return $msg;
188 188 }
189   -
  189 +
190 190 if (isset($this->_config['options']) &&
191 191 is_array($this->_config['options']) &&
192 192 count($this->_config['options']))
... ... @@ -198,7 +198,7 @@ define ('NET_LDAP_ERROR', 1000);
198 198 }
199 199 }
200 200 }
201   -
  201 +
202 202 if (isset($this->_config['dn']) && isset($this->_config['password'])) {
203 203 $bind = @ldap_bind($this->_link, $this->_config['dn'], $this->_config['password']);
204 204 } else {
... ... @@ -223,10 +223,10 @@ define ('NET_LDAP_ERROR', 1000);
223 223 * @return mixed Net_LDAP_Error or true
224 224 * @see $_config
225 225 */
226   -
227   - function reBind ($dn = null, $password = null)
  226 +
  227 + function reBind ($dn = null, $password = null)
228 228 {
229   -
  229 +
230 230 if ($dn && $password ) {
231 231 $bind = @ldap_bind($this->_link, $dn, $password);
232 232 } else {
... ... @@ -238,7 +238,7 @@ define ('NET_LDAP_ERROR', 1000);
238 238 }
239 239 return true;
240 240 }
241   -
  241 +
242 242 /**
243 243 * Starts an encrypted session
244 244 *
... ... @@ -252,13 +252,13 @@ define ('NET_LDAP_ERROR', 1000);
252 252 }
253 253 return true;
254 254 }
255   -
  255 +
256 256 /**
257 257 * alias function of startTLS() for perl-ldap interface
258   - *
  258 + *
259 259 * @see startTLS()
260 260 */
261   - function start_tls()
  261 + function start_tls()
262 262 {
263 263 $args = func_get_args();
264 264 return call_user_func_array(array($this, 'startTLS' ), $args);
... ... @@ -314,7 +314,7 @@ define ('NET_LDAP_ERROR', 1000);
314 314 * @access public
315 315 * @param mixed string or Net_LDAP_Entry
316 316 * @param array
317   - * @return mixed Net_LDAP_Error or true
  317 + * @return mixed Net_LDAP_Error or true
318 318 */
319 319 function delete($dn, $param = array())
320 320 {
... ... @@ -323,13 +323,13 @@ define ('NET_LDAP_ERROR', 1000);
323 323 } else {
324 324 if (!is_string($dn)) {
325 325 // this is what the server would say: invalid_dn_syntax.
326   - return $this->raiseError("$dn not a string nor an entryobject!", 34);
  326 + return $this->raiseError("$dn not a string nor an entryobject!", 34);
327 327 }
328 328 }
329   -
  329 +
330 330 if ($param['recursive'] ) {
331 331 $searchresult = @ldap_list($this->_link, $dn, '(objectClass=*)', array());
332   -
  332 +
333 333 if ($searchresult) {
334 334 $entries = @ldap_get_entries($this->_link, $searchresult);
335 335  
... ... @@ -338,19 +338,19 @@ define ('NET_LDAP_ERROR', 1000);
338 338 if (!$result) {
339 339 $errno = @ldap_errno($this->_link);
340 340 return $this->raiseMessage ("Net_LDAP::delete: " . $this->errorMessage($errno), $errno);
341   - }
  341 + }
342 342 if(PEAR::isError($result)){
343 343 return $result;
344   - }
  344 + }
345 345 }
346 346 }
347 347 }
348 348 if (!@ldap_delete($this->_link, $dn)) {
349   - $error = ldap_errno($this->_link );
  349 + $error = ldap_errno($this->_link );
350 350 if ($error == 66) {
351 351 /* entry has subentries */
352 352 return $this->raiseError('Net_LDAP::delete: Cound not delete entry ' . $dn .
353   - ' because of subentries. Use the recursive param to delete them.');
  353 + ' because of subentries. Use the recursive param to delete them.');
354 354 } else {
355 355 return $this->raiseError("Net_LDAP::delete: Could not delete entry " . $dn ." because: ".
356 356 $this->errorMessage($error), $error);
... ... @@ -462,7 +462,7 @@ define ('NET_LDAP_ERROR', 1000);
462 462 } // end foreach($_params['changes'] AS $option => $atrr) {
463 463 } // end if (is_array($_params['changes'])) {
464 464 // everything went fine :)
465   - return true;
  465 + return true;
466 466  
467 467 /* old broken code see bug#2987
468 468 if (isset($params['changes'])) {
... ... @@ -510,7 +510,7 @@ define ('NET_LDAP_ERROR', 1000);
510 510 // everything went fine :)
511 511 return true;
512 512 */
513   -
  513 +
514 514 }
515 515  
516 516 /**
... ... @@ -520,7 +520,7 @@ define ('NET_LDAP_ERROR', 1000);
520 520 * $base and $filter may be ommitted. BaseDN and default filter will then be used.
521 521 * Params may contain:
522 522 *
523   - * scope: The scope which will be used for searching
  523 + * scope: The scope which will be used for searching
524 524 * base - Just one entry
525 525 * sub - The whole tree
526 526 * one - Immediately below $base
... ... @@ -534,41 +534,41 @@ define ('NET_LDAP_ERROR', 1000);
534 534 * deref: By default aliases are dereferenced to locate the base object for the search, but not when
535 535 * searching subordinates of the base object. This may be changed by specifying one of the
536 536 * following values:
537   - *
  537 + *
538 538 * never - Do not dereference aliases in searching or in locating the base object of the search.
539   - * search - Dereference aliases in subordinates of the base object in searching, but not in
540   - * locating the base object of the search.
  539 + * search - Dereference aliases in subordinates of the base object in searching, but not in
  540 + * locating the base object of the search.
541 541 * find
542 542 * always
543 543 *
544 544 * @access public
545   - * @param string LDAP searchbase
  545 + * @param string LDAP searchbase
546 546 * @param string LDAP search filter
547 547 * @param array Array of options
548 548 * @return object mixed Net_LDAP_Search or Net_LDAP_Error
549 549 */
550 550 function search($base = null, $filter = null, $params = array())
551   - {
  551 + {
552 552 if (is_null($base)) {
553 553 $base = $this->_config['base'];
554 554 }
555 555 if (is_null($filter)) {
556 556 $filter = $this->_config['filter'];
557   - }
558   -
  557 + }
  558 +
559 559 /* setting searchparameters */
560 560 (isset($params['sizelimit'])) ? $sizelimit = $params['sizelimit'] : $sizelimit = 0;
561 561 (isset($params['timelimit'])) ? $timelimit = $params['timelimit'] : $timelimit = 0;
562   - (isset($params['attrsonly'])) ? $attrsonly = $params['attrsonly'] : $attrsonly = 0;
563   - (isset($params['attributes'])) ? $attributes = $params['attributes'] : $attributes = array('');
564   -
  562 + (isset($params['attrsonly'])) ? $attrsonly = $params['attrsonly'] : $attrsonly = 0;
  563 + (isset($params['attributes'])) ? $attributes = $params['attributes'] : $attributes = array('');
  564 +
565 565 if (!is_array($attributes)) {
566 566 $this->raiseError("The param attributes must be an array!");
567 567 }
568   -
569   - /* scoping makes searches faster! */
  568 +
  569 + /* scoping makes searches faster! */
570 570 $scope = (isset($params['scope']) ? $params['scope'] : $this->_config['scope']);
571   -
  571 +
572 572 switch ($scope) {
573 573 case 'one':
574 574 $search_function = 'ldap_list';
... ... @@ -578,9 +578,9 @@ define ('NET_LDAP_ERROR', 1000);
578 578 break;
579 579 default:
580 580 $search_function = 'ldap_search';
581   - }
582   -
583   - $search = @call_user_func($search_function,
  581 + }
  582 +
  583 + $search = @call_user_func($search_function,
584 584 $this->_link,
585 585 $base,
586 586 $filter,
... ... @@ -589,22 +589,22 @@ define ('NET_LDAP_ERROR', 1000);
589 589 $sizelimit,
590 590 $timelimit);
591 591  
592   - if ($err = ldap_errno($this->_link)) {
  592 + if ($err = ldap_errno($this->_link)) {
593 593  
594 594 if ($err == 32) {
595 595 // Errorcode 32 = no such object, i.e. a nullresult.
596   - return $obj =& new Net_LDAP_Search ($search, $this->_link);
597   -
  596 + return $obj =& new Net_LDAP_Search ($search, $this->_link);
  597 +
598 598 // Errorcode 4 = sizelimit exeeded. this will be handled better in time...
599 599 //} elseif ($err == 4) {
600   - // return $obj = & new Net_LDAP_Search ($search, $this->_link);
601   -
  600 + // return $obj = & new Net_LDAP_Search ($search, $this->_link);
  601 +
602 602 } elseif ($err == 87) {
603 603 // bad search filter
604 604 return $this->raiseError($this->errorMessage($err) . "($filter)", $err);
605 605 } else {
606 606 $msg = "\nParameters:\nBase: $base\nFilter: $filter\nScope: $scope";
607   - return $this->raiseError($this->errorMessage($err) . $msg, $err);
  607 + return $this->raiseError($this->errorMessage($err) . $msg, $err);
608 608 }
609 609 } else {
610 610 @$obj =& new Net_LDAP_Search($search, $this->_link);
... ... @@ -630,16 +630,16 @@ define ('NET_LDAP_ERROR', 1000);
630 630 } else {
631 631 $err = @ldap_errno($this->_link);
632 632 if ($err) {
633   - $msg = @ldap_err2str($err);
  633 + $msg = @ldap_err2str($err);
634 634 } else {
635 635 $err = NET_LDAP_ERROR;
636 636 $msg = $this->errorMessage($err);
637   - }
  637 + }
638 638 return $this->raiseError($msg, $err);
639 639 }
640 640 } else {
641 641 return $this->raiseError("Unkown Option requested");
642   - }
  642 + }
643 643 } else {
644 644 return $this->raiseError("No LDAP connection");
645 645 }
... ... @@ -661,16 +661,16 @@ define ('NET_LDAP_ERROR', 1000);
661 661 } else {
662 662 $err = @ldap_errno($this->_link);
663 663 if ($err) {
664   - $msg = @ldap_err2str($err);
  664 + $msg = @ldap_err2str($err);
665 665 } else {
666 666 $err = NET_LDAP_ERROR;
667 667 $msg = $this->errorMessage($err);
668   - }
  668 + }
669 669 return $this->raiseError($msg, $err);
670 670 }
671 671 } else {
672 672 $this->raiseError("Unkown Option requested");
673   - }
  673 + }
674 674 } else {
675 675 $this->raiseError("No LDAP connection");
676 676 }
... ... @@ -709,7 +709,7 @@ define ('NET_LDAP_ERROR', 1000);
709 709 }
710 710  
711 711 /**
712   - * Get the Net_LDAP version.
  712 + * Get the Net_LDAP version.
713 713 *
714 714 * Return the Net_LDAP version
715 715 *
... ... @@ -721,7 +721,7 @@ define ('NET_LDAP_ERROR', 1000);
721 721 }
722 722  
723 723 /**
724   - * Tell if a dn already exists
  724 + * Tell if a dn already exists
725 725 *
726 726 * @param string
727 727 * @return boolean
... ... @@ -731,9 +731,9 @@ define ('NET_LDAP_ERROR', 1000);
731 731 $dns = explode(",",$dn);
732 732 $filter = array_shift($dns);
733 733 $base= implode($dns,',');
734   - //$base = $dn;
  734 + //$base = $dn;
735 735 //$filter = '(objectclass=*)';
736   -
  736 +
737 737 $result = @ldap_list($this->_link, $base, $filter, array(), 1, 1);
738 738 if (ldap_errno($this->_link) == 32) {
739 739 return false;
... ... @@ -746,14 +746,14 @@ define ('NET_LDAP_ERROR', 1000);
746 746 }
747 747 return false;
748 748 }
749   -
  749 +
750 750  
751 751 /**
752 752 * Get a specific entry based on the dn
753 753 *
754 754 * @param string dn
755 755 * @param array Array of Attributes to select
756   - * @return object Net_LDAP_Entry or Net_LDAP_Error
  756 + * @return object Net_LDAP_Entry or Net_LDAP_Error
757 757 */
758 758 function &getEntry($dn, $attr = array(''))
759 759 {
... ... @@ -767,7 +767,7 @@ define ('NET_LDAP_ERROR', 1000);
767 767 }
768 768 return $entry;
769 769 }
770   -
  770 +
771 771  
772 772 /**
773 773 * Returns the string for an ldap errorcode.
... ... @@ -843,7 +843,7 @@ define ('NET_LDAP_ERROR', 1000);
843 843 0x5f => "LDAP_MORE_RESULTS_TO_RETURN",
844 844 0x60 => "LDAP_CLIENT_LOOP",
845 845 0x61 => "LDAP_REFERRAL_LIMIT_EXCEEDED",
846   - 1000 => "Unknown Net_LDAP error"
  846 + 1000 => "Unknown Net_LDAP error"
847 847 );
848 848  
849 849 return isset($errorMessages[$errorcode]) ? $errorMessages[$errorcode] : $errorMessages[NET_LDAP_ERROR];
... ... @@ -853,10 +853,10 @@ define ('NET_LDAP_ERROR', 1000);
853 853 * Tell whether value is a Net_LDAP_Error or not
854 854 *
855 855 * @access public
856   - * @param mixed
  856 + * @param mixed
857 857 * @return boolean
858 858 */
859   - function isError($value)
  859 + static function isError($value)
860 860 {
861 861 return (is_a($value, "Net_LDAP_Error") || parent::isError($value));
862 862 }
... ... @@ -869,10 +869,10 @@ define ('NET_LDAP_ERROR', 1000);
869 869 * @param array Array of attributes to search for
870 870 * @return object mixed Net_LDAP_Error or Net_LDAP_RootDSE
871 871 */
872   - function &rootDse($attrs = null)
  872 + function &rootDse($attrs = null)
873 873 {
874 874 require_once('Net/LDAP/RootDSE.php');
875   -
  875 +
876 876 if (is_array($attrs) && count($attrs) > 0 ) {
877 877 $attributes = $attrs;
878 878 } else {
... ... @@ -892,19 +892,19 @@ define ('NET_LDAP_ERROR', 1000);
892 892  
893 893 return new Net_LDAP_RootDSE($entry);
894 894 }
895   -
  895 +
896 896 /**
897 897 * alias function of rootDse() for perl-ldap interface
898 898 *
899 899 * @access public
900 900 * @see rootDse()
901 901 */
902   - function &root_dse()
  902 + function &root_dse()
903 903 {
904 904 $args = func_get_args();
905 905 return call_user_func_array(array($this, 'rootDse'), $args);
906 906 }
907   -
  907 +
908 908 /**
909 909 * get a schema object
910 910 *
... ... @@ -916,7 +916,7 @@ define ('NET_LDAP_ERROR', 1000);
916 916 function &schema($dn = null)
917 917 {
918 918 require_once('Net/LDAP/Schema.php');
919   -
  919 +
920 920 $schema =& new Net_LDAP_Schema();
921 921  
922 922 if (is_null($dn)) {
... ... @@ -931,8 +931,8 @@ define ('NET_LDAP_ERROR', 1000);
931 931 }
932 932 if (is_null($dn)) {
933 933 $dn = 'cn=Subschema';
934   - }
935   -
  934 + }
  935 +
936 936 // fetch the subschema entry
937 937 $result = $this->search($dn, '(objectClass=*)',
938 938 array('attributes' => array_values($schema->types), 'scope' => 'base'));
... ... @@ -944,7 +944,7 @@ define ('NET_LDAP_ERROR', 1000);
944 944 if (false === $entry) {
945 945 return $this->raiseError('Could not fetch Subschema entry');
946 946 }
947   -
  947 +
948 948 $schema->parse($entry);
949 949  
950 950 return $schema;
... ... @@ -997,9 +997,9 @@ define ('NET_LDAP_ERROR', 1000);
997 997 }
998 998  
999 999 if (is_array($attributes) && count($attributes) > 0) {
1000   -
  1000 +
1001 1001 foreach( $attributes as $k => $v ) {
1002   -
  1002 +
1003 1003 if (!isset($this->_schemaAttrs[$k])) {
1004 1004  
1005 1005 $attr = $this->_schema->get('attribute', $k);
... ... @@ -1011,9 +1011,9 @@ define ('NET_LDAP_ERROR', 1000);
1011 1011 $encode = true;
1012 1012 } else {
1013 1013 $encode = false;
1014   - }
  1014 + }
1015 1015 $this->_schemaAttrs[$k] = $encode;
1016   -
  1016 +
1017 1017 } else {
1018 1018 $encode = $this->_schemaAttrs[$k];
1019 1019 }
... ...