Connection.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Bart Visscher <bartv@thisnet.nl>
  7. * @author Brent Bloxam <brent.bloxam@gmail.com>
  8. * @author Jarkko Lehtoranta <devel@jlranta.com>
  9. * @author Joas Schilling <coding@schilljs.com>
  10. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  11. * @author Lukas Reschke <lukas@statuscode.ch>
  12. * @author Lyonel Vincent <lyonel@ezix.org>
  13. * @author Morris Jobke <hey@morrisjobke.de>
  14. * @author Robin Appelman <robin@icewind.nl>
  15. * @author Robin McCorkell <robin@mccorkell.me.uk>
  16. * @author Roeland Jago Douma <roeland@famdouma.nl>
  17. * @author root <root@localhost.localdomain>
  18. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  19. * @author Xuanwo <xuanwo@yunify.com>
  20. *
  21. * @license AGPL-3.0
  22. *
  23. * This code is free software: you can redistribute it and/or modify
  24. * it under the terms of the GNU Affero General Public License, version 3,
  25. * as published by the Free Software Foundation.
  26. *
  27. * This program is distributed in the hope that it will be useful,
  28. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  30. * GNU Affero General Public License for more details.
  31. *
  32. * You should have received a copy of the GNU Affero General Public License, version 3,
  33. * along with this program. If not, see <http://www.gnu.org/licenses/>
  34. *
  35. */
  36. namespace OCA\User_LDAP;
  37. use OC\ServerNotAvailableException;
  38. use OCP\ILogger;
  39. /**
  40. * magic properties (incomplete)
  41. * responsible for LDAP connections in context with the provided configuration
  42. *
  43. * @property string ldapHost
  44. * @property string ldapPort holds the port number
  45. * @property string ldapUserFilter
  46. * @property string ldapUserDisplayName
  47. * @property string ldapUserDisplayName2
  48. * @property boolean turnOnPasswordChange
  49. * @property boolean hasPagedResultSupport
  50. * @property string[] ldapBaseUsers
  51. * @property int|null ldapPagingSize holds an integer
  52. * @property bool|mixed|void ldapGroupMemberAssocAttr
  53. * @property string ldapUuidUserAttribute
  54. * @property string ldapUuidGroupAttribute
  55. * @property string ldapExpertUUIDUserAttr
  56. * @property string ldapExpertUUIDGroupAttr
  57. */
  58. class Connection extends LDAPUtility {
  59. private $ldapConnectionRes = null;
  60. private $configPrefix;
  61. private $configID;
  62. private $configured = false;
  63. private $hasPagedResultSupport = true;
  64. //whether connection should be kept on __destruct
  65. private $dontDestruct = false;
  66. /**
  67. * @var bool runtime flag that indicates whether supported primary groups are available
  68. */
  69. public $hasPrimaryGroups = true;
  70. /**
  71. * @var bool runtime flag that indicates whether supported POSIX gidNumber are available
  72. */
  73. public $hasGidNumber = true;
  74. //cache handler
  75. protected $cache;
  76. /** @var Configuration settings handler **/
  77. protected $configuration;
  78. protected $doNotValidate = false;
  79. protected $ignoreValidation = false;
  80. protected $bindResult = [];
  81. /**
  82. * Constructor
  83. * @param ILDAPWrapper $ldap
  84. * @param string $configPrefix a string with the prefix for the configkey column (appconfig table)
  85. * @param string|null $configID a string with the value for the appid column (appconfig table) or null for on-the-fly connections
  86. */
  87. public function __construct(ILDAPWrapper $ldap, $configPrefix = '', $configID = 'user_ldap') {
  88. parent::__construct($ldap);
  89. $this->configPrefix = $configPrefix;
  90. $this->configID = $configID;
  91. $this->configuration = new Configuration($configPrefix,
  92. !is_null($configID));
  93. $memcache = \OC::$server->getMemCacheFactory();
  94. if($memcache->isAvailable()) {
  95. $this->cache = $memcache->createDistributed();
  96. }
  97. $helper = new Helper(\OC::$server->getConfig());
  98. $this->doNotValidate = !in_array($this->configPrefix,
  99. $helper->getServerConfigurationPrefixes());
  100. $this->hasPagedResultSupport =
  101. (int)$this->configuration->ldapPagingSize !== 0
  102. || $this->ldap->hasPagedResultSupport();
  103. }
  104. public function __destruct() {
  105. if(!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) {
  106. @$this->ldap->unbind($this->ldapConnectionRes);
  107. $this->bindResult = [];
  108. }
  109. }
  110. /**
  111. * defines behaviour when the instance is cloned
  112. */
  113. public function __clone() {
  114. $this->configuration = new Configuration($this->configPrefix,
  115. !is_null($this->configID));
  116. if(count($this->bindResult) !== 0 && $this->bindResult['result'] === true) {
  117. $this->bindResult = [];
  118. }
  119. $this->ldapConnectionRes = null;
  120. $this->dontDestruct = true;
  121. }
  122. /**
  123. * @param string $name
  124. * @return bool|mixed
  125. */
  126. public function __get($name) {
  127. if(!$this->configured) {
  128. $this->readConfiguration();
  129. }
  130. if($name === 'hasPagedResultSupport') {
  131. return $this->hasPagedResultSupport;
  132. }
  133. return $this->configuration->$name;
  134. }
  135. /**
  136. * @param string $name
  137. * @param mixed $value
  138. */
  139. public function __set($name, $value) {
  140. $this->doNotValidate = false;
  141. $before = $this->configuration->$name;
  142. $this->configuration->$name = $value;
  143. $after = $this->configuration->$name;
  144. if($before !== $after) {
  145. if ($this->configID !== '' && $this->configID !== null) {
  146. $this->configuration->saveConfiguration();
  147. }
  148. $this->validateConfiguration();
  149. }
  150. }
  151. /**
  152. * sets whether the result of the configuration validation shall
  153. * be ignored when establishing the connection. Used by the Wizard
  154. * in early configuration state.
  155. * @param bool $state
  156. */
  157. public function setIgnoreValidation($state) {
  158. $this->ignoreValidation = (bool)$state;
  159. }
  160. /**
  161. * initializes the LDAP backend
  162. * @param bool $force read the config settings no matter what
  163. */
  164. public function init($force = false) {
  165. $this->readConfiguration($force);
  166. $this->establishConnection();
  167. }
  168. /**
  169. * Returns the LDAP handler
  170. */
  171. public function getConnectionResource() {
  172. if(!$this->ldapConnectionRes) {
  173. $this->init();
  174. } else if(!$this->ldap->isResource($this->ldapConnectionRes)) {
  175. $this->ldapConnectionRes = null;
  176. $this->establishConnection();
  177. }
  178. if(is_null($this->ldapConnectionRes)) {
  179. \OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server ' . $this->configuration->ldapHost, ILogger::ERROR);
  180. throw new ServerNotAvailableException('Connection to LDAP server could not be established');
  181. }
  182. return $this->ldapConnectionRes;
  183. }
  184. /**
  185. * resets the connection resource
  186. */
  187. public function resetConnectionResource() {
  188. if(!is_null($this->ldapConnectionRes)) {
  189. @$this->ldap->unbind($this->ldapConnectionRes);
  190. $this->ldapConnectionRes = null;
  191. $this->bindResult = [];
  192. }
  193. }
  194. /**
  195. * @param string|null $key
  196. * @return string
  197. */
  198. private function getCacheKey($key) {
  199. $prefix = 'LDAP-'.$this->configID.'-'.$this->configPrefix.'-';
  200. if(is_null($key)) {
  201. return $prefix;
  202. }
  203. return $prefix.hash('sha256', $key);
  204. }
  205. /**
  206. * @param string $key
  207. * @return mixed|null
  208. */
  209. public function getFromCache($key) {
  210. if(!$this->configured) {
  211. $this->readConfiguration();
  212. }
  213. if(is_null($this->cache) || !$this->configuration->ldapCacheTTL) {
  214. return null;
  215. }
  216. $key = $this->getCacheKey($key);
  217. return json_decode(base64_decode($this->cache->get($key)), true);
  218. }
  219. /**
  220. * @param string $key
  221. * @param mixed $value
  222. *
  223. * @return string
  224. */
  225. public function writeToCache($key, $value) {
  226. if(!$this->configured) {
  227. $this->readConfiguration();
  228. }
  229. if(is_null($this->cache)
  230. || !$this->configuration->ldapCacheTTL
  231. || !$this->configuration->ldapConfigurationActive) {
  232. return null;
  233. }
  234. $key = $this->getCacheKey($key);
  235. $value = base64_encode(json_encode($value));
  236. $this->cache->set($key, $value, $this->configuration->ldapCacheTTL);
  237. }
  238. public function clearCache() {
  239. if(!is_null($this->cache)) {
  240. $this->cache->clear($this->getCacheKey(null));
  241. }
  242. }
  243. /**
  244. * Caches the general LDAP configuration.
  245. * @param bool $force optional. true, if the re-read should be forced. defaults
  246. * to false.
  247. * @return null
  248. */
  249. private function readConfiguration($force = false) {
  250. if((!$this->configured || $force) && !is_null($this->configID)) {
  251. $this->configuration->readConfiguration();
  252. $this->configured = $this->validateConfiguration();
  253. }
  254. }
  255. /**
  256. * set LDAP configuration with values delivered by an array, not read from configuration
  257. * @param array $config array that holds the config parameters in an associated array
  258. * @param array &$setParameters optional; array where the set fields will be given to
  259. * @return boolean true if config validates, false otherwise. Check with $setParameters for detailed success on single parameters
  260. */
  261. public function setConfiguration($config, &$setParameters = null) {
  262. if(is_null($setParameters)) {
  263. $setParameters = array();
  264. }
  265. $this->doNotValidate = false;
  266. $this->configuration->setConfiguration($config, $setParameters);
  267. if(count($setParameters) > 0) {
  268. $this->configured = $this->validateConfiguration();
  269. }
  270. return $this->configured;
  271. }
  272. /**
  273. * saves the current Configuration in the database and empties the
  274. * cache
  275. * @return null
  276. */
  277. public function saveConfiguration() {
  278. $this->configuration->saveConfiguration();
  279. $this->clearCache();
  280. }
  281. /**
  282. * get the current LDAP configuration
  283. * @return array
  284. */
  285. public function getConfiguration() {
  286. $this->readConfiguration();
  287. $config = $this->configuration->getConfiguration();
  288. $cta = $this->configuration->getConfigTranslationArray();
  289. $result = array();
  290. foreach($cta as $dbkey => $configkey) {
  291. switch($configkey) {
  292. case 'homeFolderNamingRule':
  293. if(strpos($config[$configkey], 'attr:') === 0) {
  294. $result[$dbkey] = substr($config[$configkey], 5);
  295. } else {
  296. $result[$dbkey] = '';
  297. }
  298. break;
  299. case 'ldapBase':
  300. case 'ldapBaseUsers':
  301. case 'ldapBaseGroups':
  302. case 'ldapAttributesForUserSearch':
  303. case 'ldapAttributesForGroupSearch':
  304. if(is_array($config[$configkey])) {
  305. $result[$dbkey] = implode("\n", $config[$configkey]);
  306. break;
  307. } //else follows default
  308. default:
  309. $result[$dbkey] = $config[$configkey];
  310. }
  311. }
  312. return $result;
  313. }
  314. private function doSoftValidation() {
  315. //if User or Group Base are not set, take over Base DN setting
  316. foreach(array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) {
  317. $val = $this->configuration->$keyBase;
  318. if(empty($val)) {
  319. $this->configuration->$keyBase = $this->configuration->ldapBase;
  320. }
  321. }
  322. foreach(array('ldapExpertUUIDUserAttr' => 'ldapUuidUserAttribute',
  323. 'ldapExpertUUIDGroupAttr' => 'ldapUuidGroupAttribute')
  324. as $expertSetting => $effectiveSetting) {
  325. $uuidOverride = $this->configuration->$expertSetting;
  326. if(!empty($uuidOverride)) {
  327. $this->configuration->$effectiveSetting = $uuidOverride;
  328. } else {
  329. $uuidAttributes = Access::UUID_ATTRIBUTES;
  330. array_unshift($uuidAttributes, 'auto');
  331. if(!in_array($this->configuration->$effectiveSetting,
  332. $uuidAttributes)
  333. && (!is_null($this->configID))) {
  334. $this->configuration->$effectiveSetting = 'auto';
  335. $this->configuration->saveConfiguration();
  336. \OCP\Util::writeLog('user_ldap',
  337. 'Illegal value for the '.
  338. $effectiveSetting.', '.'reset to '.
  339. 'autodetect.', ILogger::INFO);
  340. }
  341. }
  342. }
  343. $backupPort = (int)$this->configuration->ldapBackupPort;
  344. if ($backupPort <= 0) {
  345. $this->configuration->backupPort = $this->configuration->ldapPort;
  346. }
  347. //make sure empty search attributes are saved as simple, empty array
  348. $saKeys = array('ldapAttributesForUserSearch',
  349. 'ldapAttributesForGroupSearch');
  350. foreach($saKeys as $key) {
  351. $val = $this->configuration->$key;
  352. if(is_array($val) && count($val) === 1 && empty($val[0])) {
  353. $this->configuration->$key = array();
  354. }
  355. }
  356. if((stripos($this->configuration->ldapHost, 'ldaps://') === 0)
  357. && $this->configuration->ldapTLS) {
  358. $this->configuration->ldapTLS = false;
  359. \OCP\Util::writeLog(
  360. 'user_ldap',
  361. 'LDAPS (already using secure connection) and TLS do not work together. Switched off TLS.',
  362. ILogger::INFO
  363. );
  364. }
  365. }
  366. /**
  367. * @return bool
  368. */
  369. private function doCriticalValidation() {
  370. $configurationOK = true;
  371. $errorStr = 'Configuration Error (prefix '.
  372. (string)$this->configPrefix .'): ';
  373. //options that shall not be empty
  374. $options = array('ldapHost', 'ldapPort', 'ldapUserDisplayName',
  375. 'ldapGroupDisplayName', 'ldapLoginFilter');
  376. foreach($options as $key) {
  377. $val = $this->configuration->$key;
  378. if(empty($val)) {
  379. switch($key) {
  380. case 'ldapHost':
  381. $subj = 'LDAP Host';
  382. break;
  383. case 'ldapPort':
  384. $subj = 'LDAP Port';
  385. break;
  386. case 'ldapUserDisplayName':
  387. $subj = 'LDAP User Display Name';
  388. break;
  389. case 'ldapGroupDisplayName':
  390. $subj = 'LDAP Group Display Name';
  391. break;
  392. case 'ldapLoginFilter':
  393. $subj = 'LDAP Login Filter';
  394. break;
  395. default:
  396. $subj = $key;
  397. break;
  398. }
  399. $configurationOK = false;
  400. \OCP\Util::writeLog(
  401. 'user_ldap',
  402. $errorStr.'No '.$subj.' given!',
  403. ILogger::WARN
  404. );
  405. }
  406. }
  407. //combinations
  408. $agent = $this->configuration->ldapAgentName;
  409. $pwd = $this->configuration->ldapAgentPassword;
  410. if (
  411. ($agent === '' && $pwd !== '')
  412. || ($agent !== '' && $pwd === '')
  413. ) {
  414. \OCP\Util::writeLog(
  415. 'user_ldap',
  416. $errorStr.'either no password is given for the user ' .
  417. 'agent or a password is given, but not an LDAP agent.',
  418. ILogger::WARN);
  419. $configurationOK = false;
  420. }
  421. $base = $this->configuration->ldapBase;
  422. $baseUsers = $this->configuration->ldapBaseUsers;
  423. $baseGroups = $this->configuration->ldapBaseGroups;
  424. if(empty($base) && empty($baseUsers) && empty($baseGroups)) {
  425. \OCP\Util::writeLog(
  426. 'user_ldap',
  427. $errorStr.'Not a single Base DN given.',
  428. ILogger::WARN
  429. );
  430. $configurationOK = false;
  431. }
  432. if(mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8')
  433. === false) {
  434. \OCP\Util::writeLog(
  435. 'user_ldap',
  436. $errorStr.'login filter does not contain %uid place holder.',
  437. ILogger::WARN
  438. );
  439. $configurationOK = false;
  440. }
  441. return $configurationOK;
  442. }
  443. /**
  444. * Validates the user specified configuration
  445. * @return bool true if configuration seems OK, false otherwise
  446. */
  447. private function validateConfiguration() {
  448. if($this->doNotValidate) {
  449. //don't do a validation if it is a new configuration with pure
  450. //default values. Will be allowed on changes via __set or
  451. //setConfiguration
  452. return false;
  453. }
  454. // first step: "soft" checks: settings that are not really
  455. // necessary, but advisable. If left empty, give an info message
  456. $this->doSoftValidation();
  457. //second step: critical checks. If left empty or filled wrong, mark as
  458. //not configured and give a warning.
  459. return $this->doCriticalValidation();
  460. }
  461. /**
  462. * Connects and Binds to LDAP
  463. */
  464. private function establishConnection() {
  465. if(!$this->configuration->ldapConfigurationActive) {
  466. return null;
  467. }
  468. static $phpLDAPinstalled = true;
  469. if(!$phpLDAPinstalled) {
  470. return false;
  471. }
  472. if(!$this->ignoreValidation && !$this->configured) {
  473. \OCP\Util::writeLog(
  474. 'user_ldap',
  475. 'Configuration is invalid, cannot connect',
  476. ILogger::WARN
  477. );
  478. return false;
  479. }
  480. if(!$this->ldapConnectionRes) {
  481. if(!$this->ldap->areLDAPFunctionsAvailable()) {
  482. $phpLDAPinstalled = false;
  483. \OCP\Util::writeLog(
  484. 'user_ldap',
  485. 'function ldap_connect is not available. Make sure that the PHP ldap module is installed.',
  486. ILogger::ERROR
  487. );
  488. return false;
  489. }
  490. if($this->configuration->turnOffCertCheck) {
  491. if(putenv('LDAPTLS_REQCERT=never')) {
  492. \OCP\Util::writeLog('user_ldap',
  493. 'Turned off SSL certificate validation successfully.',
  494. ILogger::DEBUG);
  495. } else {
  496. \OCP\Util::writeLog(
  497. 'user_ldap',
  498. 'Could not turn off SSL certificate validation.',
  499. ILogger::WARN
  500. );
  501. }
  502. }
  503. $isOverrideMainServer = ($this->configuration->ldapOverrideMainServer
  504. || $this->getFromCache('overrideMainServer'));
  505. $isBackupHost = (trim($this->configuration->ldapBackupHost) !== "");
  506. $bindStatus = false;
  507. $error = -1;
  508. try {
  509. if (!$isOverrideMainServer) {
  510. $this->doConnect($this->configuration->ldapHost,
  511. $this->configuration->ldapPort);
  512. $bindStatus = $this->bind();
  513. $error = $this->ldap->isResource($this->ldapConnectionRes) ?
  514. $this->ldap->errno($this->ldapConnectionRes) : -1;
  515. }
  516. if($bindStatus === true) {
  517. return $bindStatus;
  518. }
  519. } catch (ServerNotAvailableException $e) {
  520. if(!$isBackupHost) {
  521. throw $e;
  522. }
  523. }
  524. //if LDAP server is not reachable, try the Backup (Replica!) Server
  525. if($isBackupHost && ($error !== 0 || $isOverrideMainServer)) {
  526. $this->doConnect($this->configuration->ldapBackupHost,
  527. $this->configuration->ldapBackupPort);
  528. $this->bindResult = [];
  529. $bindStatus = $this->bind();
  530. $error = $this->ldap->isResource($this->ldapConnectionRes) ?
  531. $this->ldap->errno($this->ldapConnectionRes) : -1;
  532. if($bindStatus && $error === 0 && !$this->getFromCache('overrideMainServer')) {
  533. //when bind to backup server succeeded and failed to main server,
  534. //skip contacting him until next cache refresh
  535. $this->writeToCache('overrideMainServer', true);
  536. }
  537. }
  538. return $bindStatus;
  539. }
  540. return null;
  541. }
  542. /**
  543. * @param string $host
  544. * @param string $port
  545. * @return bool
  546. * @throws \OC\ServerNotAvailableException
  547. */
  548. private function doConnect($host, $port) {
  549. if ($host === '') {
  550. return false;
  551. }
  552. $this->ldapConnectionRes = $this->ldap->connect($host, $port);
  553. if(!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) {
  554. throw new ServerNotAvailableException('Could not set required LDAP Protocol version.');
  555. }
  556. if(!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) {
  557. throw new ServerNotAvailableException('Could not disable LDAP referrals.');
  558. }
  559. if($this->configuration->ldapTLS) {
  560. if(!$this->ldap->startTls($this->ldapConnectionRes)) {
  561. throw new ServerNotAvailableException('Start TLS failed, when connecting to LDAP host ' . $host . '.');
  562. }
  563. }
  564. return true;
  565. }
  566. /**
  567. * Binds to LDAP
  568. */
  569. public function bind() {
  570. if(!$this->configuration->ldapConfigurationActive) {
  571. return false;
  572. }
  573. $cr = $this->ldapConnectionRes;
  574. if(!$this->ldap->isResource($cr)) {
  575. $cr = $this->getConnectionResource();
  576. }
  577. if(
  578. count($this->bindResult) !== 0
  579. && $this->bindResult['dn'] === $this->configuration->ldapAgentName
  580. && \OC::$server->getHasher()->verify(
  581. $this->configPrefix . $this->configuration->ldapAgentPassword,
  582. $this->bindResult['hash']
  583. )
  584. ) {
  585. // don't attempt to bind again with the same data as before
  586. // bind might have been invoked via getConnectionResource(),
  587. // but we need results specifically for e.g. user login
  588. return $this->bindResult['result'];
  589. }
  590. $ldapLogin = @$this->ldap->bind($cr,
  591. $this->configuration->ldapAgentName,
  592. $this->configuration->ldapAgentPassword);
  593. $this->bindResult = [
  594. 'dn' => $this->configuration->ldapAgentName,
  595. 'hash' => \OC::$server->getHasher()->hash($this->configPrefix . $this->configuration->ldapAgentPassword),
  596. 'result' => $ldapLogin,
  597. ];
  598. if(!$ldapLogin) {
  599. $errno = $this->ldap->errno($cr);
  600. \OCP\Util::writeLog('user_ldap',
  601. 'Bind failed: ' . $errno . ': ' . $this->ldap->error($cr),
  602. ILogger::WARN);
  603. // Set to failure mode, if LDAP error code is not LDAP_SUCCESS or LDAP_INVALID_CREDENTIALS
  604. if($errno !== 0x00 && $errno !== 0x31) {
  605. $this->ldapConnectionRes = null;
  606. }
  607. return false;
  608. }
  609. return true;
  610. }
  611. }