1
0

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 string ldapUserAvatarRule
  49. * @property boolean turnOnPasswordChange
  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. * @property string ldapQuotaAttribute
  58. * @property string ldapQuotaDefault
  59. * @property string ldapEmailAttribute
  60. */
  61. class Connection extends LDAPUtility {
  62. private $ldapConnectionRes = null;
  63. private $configPrefix;
  64. private $configID;
  65. private $configured = false;
  66. //whether connection should be kept on __destruct
  67. private $dontDestruct = false;
  68. /**
  69. * @var bool runtime flag that indicates whether supported primary groups are available
  70. */
  71. public $hasPrimaryGroups = true;
  72. /**
  73. * @var bool runtime flag that indicates whether supported POSIX gidNumber are available
  74. */
  75. public $hasGidNumber = true;
  76. //cache handler
  77. protected $cache;
  78. /** @var Configuration settings handler **/
  79. protected $configuration;
  80. protected $doNotValidate = false;
  81. protected $ignoreValidation = false;
  82. protected $bindResult = [];
  83. /**
  84. * Constructor
  85. * @param ILDAPWrapper $ldap
  86. * @param string $configPrefix a string with the prefix for the configkey column (appconfig table)
  87. * @param string|null $configID a string with the value for the appid column (appconfig table) or null for on-the-fly connections
  88. */
  89. public function __construct(ILDAPWrapper $ldap, $configPrefix = '', $configID = 'user_ldap') {
  90. parent::__construct($ldap);
  91. $this->configPrefix = $configPrefix;
  92. $this->configID = $configID;
  93. $this->configuration = new Configuration($configPrefix,
  94. !is_null($configID));
  95. $memcache = \OC::$server->getMemCacheFactory();
  96. if($memcache->isAvailable()) {
  97. $this->cache = $memcache->createDistributed();
  98. }
  99. $helper = new Helper(\OC::$server->getConfig());
  100. $this->doNotValidate = !in_array($this->configPrefix,
  101. $helper->getServerConfigurationPrefixes());
  102. }
  103. public function __destruct() {
  104. if(!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) {
  105. @$this->ldap->unbind($this->ldapConnectionRes);
  106. $this->bindResult = [];
  107. }
  108. }
  109. /**
  110. * defines behaviour when the instance is cloned
  111. */
  112. public function __clone() {
  113. $this->configuration = new Configuration($this->configPrefix,
  114. !is_null($this->configID));
  115. if(count($this->bindResult) !== 0 && $this->bindResult['result'] === true) {
  116. $this->bindResult = [];
  117. }
  118. $this->ldapConnectionRes = null;
  119. $this->dontDestruct = true;
  120. }
  121. /**
  122. * @param string $name
  123. * @return bool|mixed
  124. */
  125. public function __get($name) {
  126. if(!$this->configured) {
  127. $this->readConfiguration();
  128. }
  129. return $this->configuration->$name;
  130. }
  131. /**
  132. * @param string $name
  133. * @param mixed $value
  134. */
  135. public function __set($name, $value) {
  136. $this->doNotValidate = false;
  137. $before = $this->configuration->$name;
  138. $this->configuration->$name = $value;
  139. $after = $this->configuration->$name;
  140. if($before !== $after) {
  141. if ($this->configID !== '' && $this->configID !== null) {
  142. $this->configuration->saveConfiguration();
  143. }
  144. $this->validateConfiguration();
  145. }
  146. }
  147. /**
  148. * @param string $rule
  149. * @return array
  150. * @throws \RuntimeException
  151. */
  152. public function resolveRule($rule) {
  153. return $this->configuration->resolveRule($rule);
  154. }
  155. /**
  156. * sets whether the result of the configuration validation shall
  157. * be ignored when establishing the connection. Used by the Wizard
  158. * in early configuration state.
  159. * @param bool $state
  160. */
  161. public function setIgnoreValidation($state) {
  162. $this->ignoreValidation = (bool)$state;
  163. }
  164. /**
  165. * initializes the LDAP backend
  166. * @param bool $force read the config settings no matter what
  167. */
  168. public function init($force = false) {
  169. $this->readConfiguration($force);
  170. $this->establishConnection();
  171. }
  172. /**
  173. * Returns the LDAP handler
  174. */
  175. public function getConnectionResource() {
  176. if(!$this->ldapConnectionRes) {
  177. $this->init();
  178. } else if(!$this->ldap->isResource($this->ldapConnectionRes)) {
  179. $this->ldapConnectionRes = null;
  180. $this->establishConnection();
  181. }
  182. if(is_null($this->ldapConnectionRes)) {
  183. \OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server ' . $this->configuration->ldapHost, ILogger::ERROR);
  184. throw new ServerNotAvailableException('Connection to LDAP server could not be established');
  185. }
  186. return $this->ldapConnectionRes;
  187. }
  188. /**
  189. * resets the connection resource
  190. */
  191. public function resetConnectionResource() {
  192. if(!is_null($this->ldapConnectionRes)) {
  193. @$this->ldap->unbind($this->ldapConnectionRes);
  194. $this->ldapConnectionRes = null;
  195. $this->bindResult = [];
  196. }
  197. }
  198. /**
  199. * @param string|null $key
  200. * @return string
  201. */
  202. private function getCacheKey($key) {
  203. $prefix = 'LDAP-'.$this->configID.'-'.$this->configPrefix.'-';
  204. if(is_null($key)) {
  205. return $prefix;
  206. }
  207. return $prefix.hash('sha256', $key);
  208. }
  209. /**
  210. * @param string $key
  211. * @return mixed|null
  212. */
  213. public function getFromCache($key) {
  214. if(!$this->configured) {
  215. $this->readConfiguration();
  216. }
  217. if(is_null($this->cache) || !$this->configuration->ldapCacheTTL) {
  218. return null;
  219. }
  220. $key = $this->getCacheKey($key);
  221. return json_decode(base64_decode($this->cache->get($key)), true);
  222. }
  223. /**
  224. * @param string $key
  225. * @param mixed $value
  226. *
  227. * @return string
  228. */
  229. public function writeToCache($key, $value) {
  230. if(!$this->configured) {
  231. $this->readConfiguration();
  232. }
  233. if(is_null($this->cache)
  234. || !$this->configuration->ldapCacheTTL
  235. || !$this->configuration->ldapConfigurationActive) {
  236. return null;
  237. }
  238. $key = $this->getCacheKey($key);
  239. $value = base64_encode(json_encode($value));
  240. $this->cache->set($key, $value, $this->configuration->ldapCacheTTL);
  241. }
  242. public function clearCache() {
  243. if(!is_null($this->cache)) {
  244. $this->cache->clear($this->getCacheKey(null));
  245. }
  246. }
  247. /**
  248. * Caches the general LDAP configuration.
  249. * @param bool $force optional. true, if the re-read should be forced. defaults
  250. * to false.
  251. * @return null
  252. */
  253. private function readConfiguration($force = false) {
  254. if((!$this->configured || $force) && !is_null($this->configID)) {
  255. $this->configuration->readConfiguration();
  256. $this->configured = $this->validateConfiguration();
  257. }
  258. }
  259. /**
  260. * set LDAP configuration with values delivered by an array, not read from configuration
  261. * @param array $config array that holds the config parameters in an associated array
  262. * @param array &$setParameters optional; array where the set fields will be given to
  263. * @return boolean true if config validates, false otherwise. Check with $setParameters for detailed success on single parameters
  264. */
  265. public function setConfiguration($config, &$setParameters = null) {
  266. if(is_null($setParameters)) {
  267. $setParameters = array();
  268. }
  269. $this->doNotValidate = false;
  270. $this->configuration->setConfiguration($config, $setParameters);
  271. if(count($setParameters) > 0) {
  272. $this->configured = $this->validateConfiguration();
  273. }
  274. return $this->configured;
  275. }
  276. /**
  277. * saves the current Configuration in the database and empties the
  278. * cache
  279. * @return null
  280. */
  281. public function saveConfiguration() {
  282. $this->configuration->saveConfiguration();
  283. $this->clearCache();
  284. }
  285. /**
  286. * get the current LDAP configuration
  287. * @return array
  288. */
  289. public function getConfiguration() {
  290. $this->readConfiguration();
  291. $config = $this->configuration->getConfiguration();
  292. $cta = $this->configuration->getConfigTranslationArray();
  293. $result = array();
  294. foreach($cta as $dbkey => $configkey) {
  295. switch($configkey) {
  296. case 'homeFolderNamingRule':
  297. if(strpos($config[$configkey], 'attr:') === 0) {
  298. $result[$dbkey] = substr($config[$configkey], 5);
  299. } else {
  300. $result[$dbkey] = '';
  301. }
  302. break;
  303. case 'ldapBase':
  304. case 'ldapBaseUsers':
  305. case 'ldapBaseGroups':
  306. case 'ldapAttributesForUserSearch':
  307. case 'ldapAttributesForGroupSearch':
  308. if(is_array($config[$configkey])) {
  309. $result[$dbkey] = implode("\n", $config[$configkey]);
  310. break;
  311. } //else follows default
  312. default:
  313. $result[$dbkey] = $config[$configkey];
  314. }
  315. }
  316. return $result;
  317. }
  318. private function doSoftValidation() {
  319. //if User or Group Base are not set, take over Base DN setting
  320. foreach(array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) {
  321. $val = $this->configuration->$keyBase;
  322. if(empty($val)) {
  323. $this->configuration->$keyBase = $this->configuration->ldapBase;
  324. }
  325. }
  326. foreach(array('ldapExpertUUIDUserAttr' => 'ldapUuidUserAttribute',
  327. 'ldapExpertUUIDGroupAttr' => 'ldapUuidGroupAttribute')
  328. as $expertSetting => $effectiveSetting) {
  329. $uuidOverride = $this->configuration->$expertSetting;
  330. if(!empty($uuidOverride)) {
  331. $this->configuration->$effectiveSetting = $uuidOverride;
  332. } else {
  333. $uuidAttributes = Access::UUID_ATTRIBUTES;
  334. array_unshift($uuidAttributes, 'auto');
  335. if(!in_array($this->configuration->$effectiveSetting,
  336. $uuidAttributes)
  337. && (!is_null($this->configID))) {
  338. $this->configuration->$effectiveSetting = 'auto';
  339. $this->configuration->saveConfiguration();
  340. \OCP\Util::writeLog('user_ldap',
  341. 'Illegal value for the '.
  342. $effectiveSetting.', '.'reset to '.
  343. 'autodetect.', ILogger::INFO);
  344. }
  345. }
  346. }
  347. $backupPort = (int)$this->configuration->ldapBackupPort;
  348. if ($backupPort <= 0) {
  349. $this->configuration->backupPort = $this->configuration->ldapPort;
  350. }
  351. //make sure empty search attributes are saved as simple, empty array
  352. $saKeys = array('ldapAttributesForUserSearch',
  353. 'ldapAttributesForGroupSearch');
  354. foreach($saKeys as $key) {
  355. $val = $this->configuration->$key;
  356. if(is_array($val) && count($val) === 1 && empty($val[0])) {
  357. $this->configuration->$key = array();
  358. }
  359. }
  360. if((stripos($this->configuration->ldapHost, 'ldaps://') === 0)
  361. && $this->configuration->ldapTLS) {
  362. $this->configuration->ldapTLS = false;
  363. \OCP\Util::writeLog(
  364. 'user_ldap',
  365. 'LDAPS (already using secure connection) and TLS do not work together. Switched off TLS.',
  366. ILogger::INFO
  367. );
  368. }
  369. }
  370. /**
  371. * @return bool
  372. */
  373. private function doCriticalValidation() {
  374. $configurationOK = true;
  375. $errorStr = 'Configuration Error (prefix '.
  376. (string)$this->configPrefix .'): ';
  377. //options that shall not be empty
  378. $options = array('ldapHost', 'ldapPort', 'ldapUserDisplayName',
  379. 'ldapGroupDisplayName', 'ldapLoginFilter');
  380. foreach($options as $key) {
  381. $val = $this->configuration->$key;
  382. if(empty($val)) {
  383. switch($key) {
  384. case 'ldapHost':
  385. $subj = 'LDAP Host';
  386. break;
  387. case 'ldapPort':
  388. $subj = 'LDAP Port';
  389. break;
  390. case 'ldapUserDisplayName':
  391. $subj = 'LDAP User Display Name';
  392. break;
  393. case 'ldapGroupDisplayName':
  394. $subj = 'LDAP Group Display Name';
  395. break;
  396. case 'ldapLoginFilter':
  397. $subj = 'LDAP Login Filter';
  398. break;
  399. default:
  400. $subj = $key;
  401. break;
  402. }
  403. $configurationOK = false;
  404. \OCP\Util::writeLog(
  405. 'user_ldap',
  406. $errorStr.'No '.$subj.' given!',
  407. ILogger::WARN
  408. );
  409. }
  410. }
  411. //combinations
  412. $agent = $this->configuration->ldapAgentName;
  413. $pwd = $this->configuration->ldapAgentPassword;
  414. if (
  415. ($agent === '' && $pwd !== '')
  416. || ($agent !== '' && $pwd === '')
  417. ) {
  418. \OCP\Util::writeLog(
  419. 'user_ldap',
  420. $errorStr.'either no password is given for the user ' .
  421. 'agent or a password is given, but not an LDAP agent.',
  422. ILogger::WARN);
  423. $configurationOK = false;
  424. }
  425. $base = $this->configuration->ldapBase;
  426. $baseUsers = $this->configuration->ldapBaseUsers;
  427. $baseGroups = $this->configuration->ldapBaseGroups;
  428. if(empty($base) && empty($baseUsers) && empty($baseGroups)) {
  429. \OCP\Util::writeLog(
  430. 'user_ldap',
  431. $errorStr.'Not a single Base DN given.',
  432. ILogger::WARN
  433. );
  434. $configurationOK = false;
  435. }
  436. if(mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8')
  437. === false) {
  438. \OCP\Util::writeLog(
  439. 'user_ldap',
  440. $errorStr.'login filter does not contain %uid place holder.',
  441. ILogger::WARN
  442. );
  443. $configurationOK = false;
  444. }
  445. return $configurationOK;
  446. }
  447. /**
  448. * Validates the user specified configuration
  449. * @return bool true if configuration seems OK, false otherwise
  450. */
  451. private function validateConfiguration() {
  452. if($this->doNotValidate) {
  453. //don't do a validation if it is a new configuration with pure
  454. //default values. Will be allowed on changes via __set or
  455. //setConfiguration
  456. return false;
  457. }
  458. // first step: "soft" checks: settings that are not really
  459. // necessary, but advisable. If left empty, give an info message
  460. $this->doSoftValidation();
  461. //second step: critical checks. If left empty or filled wrong, mark as
  462. //not configured and give a warning.
  463. return $this->doCriticalValidation();
  464. }
  465. /**
  466. * Connects and Binds to LDAP
  467. *
  468. * @throws ServerNotAvailableException
  469. */
  470. private function establishConnection() {
  471. if(!$this->configuration->ldapConfigurationActive) {
  472. return null;
  473. }
  474. static $phpLDAPinstalled = true;
  475. if(!$phpLDAPinstalled) {
  476. return false;
  477. }
  478. if(!$this->ignoreValidation && !$this->configured) {
  479. \OCP\Util::writeLog(
  480. 'user_ldap',
  481. 'Configuration is invalid, cannot connect',
  482. ILogger::WARN
  483. );
  484. return false;
  485. }
  486. if(!$this->ldapConnectionRes) {
  487. if(!$this->ldap->areLDAPFunctionsAvailable()) {
  488. $phpLDAPinstalled = false;
  489. \OCP\Util::writeLog(
  490. 'user_ldap',
  491. 'function ldap_connect is not available. Make sure that the PHP ldap module is installed.',
  492. ILogger::ERROR
  493. );
  494. return false;
  495. }
  496. if($this->configuration->turnOffCertCheck) {
  497. if(putenv('LDAPTLS_REQCERT=never')) {
  498. \OCP\Util::writeLog('user_ldap',
  499. 'Turned off SSL certificate validation successfully.',
  500. ILogger::DEBUG);
  501. } else {
  502. \OCP\Util::writeLog(
  503. 'user_ldap',
  504. 'Could not turn off SSL certificate validation.',
  505. ILogger::WARN
  506. );
  507. }
  508. }
  509. $isOverrideMainServer = ($this->configuration->ldapOverrideMainServer
  510. || $this->getFromCache('overrideMainServer'));
  511. $isBackupHost = (trim($this->configuration->ldapBackupHost) !== "");
  512. $bindStatus = false;
  513. try {
  514. if (!$isOverrideMainServer) {
  515. $this->doConnect($this->configuration->ldapHost,
  516. $this->configuration->ldapPort);
  517. return $this->bind();
  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 || $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. }