You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

683 lines
19 KiB

9 years ago
9 years ago
10 years ago
11 years ago
LDAP User Cleanup: Port from stable7 without further adjustements LDAP User Cleanup background job for user clean up adjust user backend for clean up register background job remove dead code dependency injection make Helper non-static for proper testing check whether it is OK to run clean up job. Do not forget to pass arguments. use correct method to get the config from server methods can be private, proper indirect testing is given no automatic user deletion make limit readable for test purposes make method less complex add first tests let preferences accept limit and offset for getUsersForValue DI via constructor does not work for background jobs after detecting, now we have retrieving deleted users and their details we need this method to be public for now finalize export method, add missing getter clean up namespaces and get rid of unnecessary files helper is not static anymore cleanup according to scrutinizer add cli tool to show deleted users uses are necessary after recent namespace change also remove user from mappings table on deletion add occ command to delete users fix use statement improve output big fixes / improvements PHP doc return true in userExists early for cleaning up deleted users bump version control state and interval with one config.php setting, now ldapUserCleanupInterval. 0 will disable it. enabled by default. improve doc rename cli method to be consistent with others introduce ldapUserCleanupInterval in sample config don't show last login as unix epoche start when no login happend less log output consistent namespace for OfflineUser rename GarbageCollector to DeletedUsersIndex and move it to user subdir fix unit tests add tests for deleteUser more test adjustements Conflicts: apps/user_ldap/ajax/clearMappings.php apps/user_ldap/appinfo/app.php apps/user_ldap/lib/access.php apps/user_ldap/lib/helper.php apps/user_ldap/tests/helper.php core/register_command.php lib/private/preferences.php lib/private/user.php add ldap:check-user to check user existance on the fly Conflicts: apps/user_ldap/lib/helper.php forgotten file PHPdoc fixes, no code change and don't forget to adjust tests
11 years ago
9 years ago
  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. * @property string ldapExtStorageHomeAttribute
  61. * @property string homeFolderNamingRule
  62. */
  63. class Connection extends LDAPUtility {
  64. private $ldapConnectionRes = null;
  65. private $configPrefix;
  66. private $configID;
  67. private $configured = false;
  68. //whether connection should be kept on __destruct
  69. private $dontDestruct = false;
  70. /**
  71. * @var bool runtime flag that indicates whether supported primary groups are available
  72. */
  73. public $hasPrimaryGroups = true;
  74. /**
  75. * @var bool runtime flag that indicates whether supported POSIX gidNumber are available
  76. */
  77. public $hasGidNumber = true;
  78. //cache handler
  79. protected $cache;
  80. /** @var Configuration settings handler **/
  81. protected $configuration;
  82. protected $doNotValidate = false;
  83. protected $ignoreValidation = false;
  84. protected $bindResult = [];
  85. /**
  86. * Constructor
  87. * @param ILDAPWrapper $ldap
  88. * @param string $configPrefix a string with the prefix for the configkey column (appconfig table)
  89. * @param string|null $configID a string with the value for the appid column (appconfig table) or null for on-the-fly connections
  90. */
  91. public function __construct(ILDAPWrapper $ldap, $configPrefix = '', $configID = 'user_ldap') {
  92. parent::__construct($ldap);
  93. $this->configPrefix = $configPrefix;
  94. $this->configID = $configID;
  95. $this->configuration = new Configuration($configPrefix,
  96. !is_null($configID));
  97. $memcache = \OC::$server->getMemCacheFactory();
  98. if($memcache->isAvailable()) {
  99. $this->cache = $memcache->createDistributed();
  100. }
  101. $helper = new Helper(\OC::$server->getConfig());
  102. $this->doNotValidate = !in_array($this->configPrefix,
  103. $helper->getServerConfigurationPrefixes());
  104. }
  105. public function __destruct() {
  106. if(!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) {
  107. @$this->ldap->unbind($this->ldapConnectionRes);
  108. $this->bindResult = [];
  109. }
  110. }
  111. /**
  112. * defines behaviour when the instance is cloned
  113. */
  114. public function __clone() {
  115. $this->configuration = new Configuration($this->configPrefix,
  116. !is_null($this->configID));
  117. if(count($this->bindResult) !== 0 && $this->bindResult['result'] === true) {
  118. $this->bindResult = [];
  119. }
  120. $this->ldapConnectionRes = null;
  121. $this->dontDestruct = true;
  122. }
  123. /**
  124. * @param string $name
  125. * @return bool|mixed
  126. */
  127. public function __get($name) {
  128. if(!$this->configured) {
  129. $this->readConfiguration();
  130. }
  131. return $this->configuration->$name;
  132. }
  133. /**
  134. * @param string $name
  135. * @param mixed $value
  136. */
  137. public function __set($name, $value) {
  138. $this->doNotValidate = false;
  139. $before = $this->configuration->$name;
  140. $this->configuration->$name = $value;
  141. $after = $this->configuration->$name;
  142. if($before !== $after) {
  143. if ($this->configID !== '' && $this->configID !== null) {
  144. $this->configuration->saveConfiguration();
  145. }
  146. $this->validateConfiguration();
  147. }
  148. }
  149. /**
  150. * @param string $rule
  151. * @return array
  152. * @throws \RuntimeException
  153. */
  154. public function resolveRule($rule) {
  155. return $this->configuration->resolveRule($rule);
  156. }
  157. /**
  158. * sets whether the result of the configuration validation shall
  159. * be ignored when establishing the connection. Used by the Wizard
  160. * in early configuration state.
  161. * @param bool $state
  162. */
  163. public function setIgnoreValidation($state) {
  164. $this->ignoreValidation = (bool)$state;
  165. }
  166. /**
  167. * initializes the LDAP backend
  168. * @param bool $force read the config settings no matter what
  169. */
  170. public function init($force = false) {
  171. $this->readConfiguration($force);
  172. $this->establishConnection();
  173. }
  174. /**
  175. * Returns the LDAP handler
  176. */
  177. public function getConnectionResource() {
  178. if(!$this->ldapConnectionRes) {
  179. $this->init();
  180. } else if(!$this->ldap->isResource($this->ldapConnectionRes)) {
  181. $this->ldapConnectionRes = null;
  182. $this->establishConnection();
  183. }
  184. if(is_null($this->ldapConnectionRes)) {
  185. \OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server ' . $this->configuration->ldapHost, ILogger::ERROR);
  186. throw new ServerNotAvailableException('Connection to LDAP server could not be established');
  187. }
  188. return $this->ldapConnectionRes;
  189. }
  190. /**
  191. * resets the connection resource
  192. */
  193. public function resetConnectionResource() {
  194. if(!is_null($this->ldapConnectionRes)) {
  195. @$this->ldap->unbind($this->ldapConnectionRes);
  196. $this->ldapConnectionRes = null;
  197. $this->bindResult = [];
  198. }
  199. }
  200. /**
  201. * @param string|null $key
  202. * @return string
  203. */
  204. private function getCacheKey($key) {
  205. $prefix = 'LDAP-'.$this->configID.'-'.$this->configPrefix.'-';
  206. if(is_null($key)) {
  207. return $prefix;
  208. }
  209. return $prefix.hash('sha256', $key);
  210. }
  211. /**
  212. * @param string $key
  213. * @return mixed|null
  214. */
  215. public function getFromCache($key) {
  216. if(!$this->configured) {
  217. $this->readConfiguration();
  218. }
  219. if(is_null($this->cache) || !$this->configuration->ldapCacheTTL) {
  220. return null;
  221. }
  222. $key = $this->getCacheKey($key);
  223. return json_decode(base64_decode($this->cache->get($key)), true);
  224. }
  225. /**
  226. * @param string $key
  227. * @param mixed $value
  228. *
  229. * @return string
  230. */
  231. public function writeToCache($key, $value) {
  232. if(!$this->configured) {
  233. $this->readConfiguration();
  234. }
  235. if(is_null($this->cache)
  236. || !$this->configuration->ldapCacheTTL
  237. || !$this->configuration->ldapConfigurationActive) {
  238. return null;
  239. }
  240. $key = $this->getCacheKey($key);
  241. $value = base64_encode(json_encode($value));
  242. $this->cache->set($key, $value, $this->configuration->ldapCacheTTL);
  243. }
  244. public function clearCache() {
  245. if(!is_null($this->cache)) {
  246. $this->cache->clear($this->getCacheKey(null));
  247. }
  248. }
  249. /**
  250. * Caches the general LDAP configuration.
  251. * @param bool $force optional. true, if the re-read should be forced. defaults
  252. * to false.
  253. * @return null
  254. */
  255. private function readConfiguration($force = false) {
  256. if((!$this->configured || $force) && !is_null($this->configID)) {
  257. $this->configuration->readConfiguration();
  258. $this->configured = $this->validateConfiguration();
  259. }
  260. }
  261. /**
  262. * set LDAP configuration with values delivered by an array, not read from configuration
  263. * @param array $config array that holds the config parameters in an associated array
  264. * @param array &$setParameters optional; array where the set fields will be given to
  265. * @return boolean true if config validates, false otherwise. Check with $setParameters for detailed success on single parameters
  266. */
  267. public function setConfiguration($config, &$setParameters = null) {
  268. if(is_null($setParameters)) {
  269. $setParameters = array();
  270. }
  271. $this->doNotValidate = false;
  272. $this->configuration->setConfiguration($config, $setParameters);
  273. if(count($setParameters) > 0) {
  274. $this->configured = $this->validateConfiguration();
  275. }
  276. return $this->configured;
  277. }
  278. /**
  279. * saves the current Configuration in the database and empties the
  280. * cache
  281. * @return null
  282. */
  283. public function saveConfiguration() {
  284. $this->configuration->saveConfiguration();
  285. $this->clearCache();
  286. }
  287. /**
  288. * get the current LDAP configuration
  289. * @return array
  290. */
  291. public function getConfiguration() {
  292. $this->readConfiguration();
  293. $config = $this->configuration->getConfiguration();
  294. $cta = $this->configuration->getConfigTranslationArray();
  295. $result = array();
  296. foreach($cta as $dbkey => $configkey) {
  297. switch($configkey) {
  298. case 'homeFolderNamingRule':
  299. if(strpos($config[$configkey], 'attr:') === 0) {
  300. $result[$dbkey] = substr($config[$configkey], 5);
  301. } else {
  302. $result[$dbkey] = '';
  303. }
  304. break;
  305. case 'ldapBase':
  306. case 'ldapBaseUsers':
  307. case 'ldapBaseGroups':
  308. case 'ldapAttributesForUserSearch':
  309. case 'ldapAttributesForGroupSearch':
  310. if(is_array($config[$configkey])) {
  311. $result[$dbkey] = implode("\n", $config[$configkey]);
  312. break;
  313. } //else follows default
  314. default:
  315. $result[$dbkey] = $config[$configkey];
  316. }
  317. }
  318. return $result;
  319. }
  320. private function doSoftValidation() {
  321. //if User or Group Base are not set, take over Base DN setting
  322. foreach(array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) {
  323. $val = $this->configuration->$keyBase;
  324. if(empty($val)) {
  325. $this->configuration->$keyBase = $this->configuration->ldapBase;
  326. }
  327. }
  328. foreach(array('ldapExpertUUIDUserAttr' => 'ldapUuidUserAttribute',
  329. 'ldapExpertUUIDGroupAttr' => 'ldapUuidGroupAttribute')
  330. as $expertSetting => $effectiveSetting) {
  331. $uuidOverride = $this->configuration->$expertSetting;
  332. if(!empty($uuidOverride)) {
  333. $this->configuration->$effectiveSetting = $uuidOverride;
  334. } else {
  335. $uuidAttributes = Access::UUID_ATTRIBUTES;
  336. array_unshift($uuidAttributes, 'auto');
  337. if(!in_array($this->configuration->$effectiveSetting,
  338. $uuidAttributes)
  339. && (!is_null($this->configID))) {
  340. $this->configuration->$effectiveSetting = 'auto';
  341. $this->configuration->saveConfiguration();
  342. \OCP\Util::writeLog('user_ldap',
  343. 'Illegal value for the '.
  344. $effectiveSetting.', '.'reset to '.
  345. 'autodetect.', ILogger::INFO);
  346. }
  347. }
  348. }
  349. $backupPort = (int)$this->configuration->ldapBackupPort;
  350. if ($backupPort <= 0) {
  351. $this->configuration->backupPort = $this->configuration->ldapPort;
  352. }
  353. //make sure empty search attributes are saved as simple, empty array
  354. $saKeys = array('ldapAttributesForUserSearch',
  355. 'ldapAttributesForGroupSearch');
  356. foreach($saKeys as $key) {
  357. $val = $this->configuration->$key;
  358. if(is_array($val) && count($val) === 1 && empty($val[0])) {
  359. $this->configuration->$key = array();
  360. }
  361. }
  362. if((stripos($this->configuration->ldapHost, 'ldaps://') === 0)
  363. && $this->configuration->ldapTLS) {
  364. $this->configuration->ldapTLS = false;
  365. \OCP\Util::writeLog(
  366. 'user_ldap',
  367. 'LDAPS (already using secure connection) and TLS do not work together. Switched off TLS.',
  368. ILogger::INFO
  369. );
  370. }
  371. }
  372. /**
  373. * @return bool
  374. */
  375. private function doCriticalValidation() {
  376. $configurationOK = true;
  377. $errorStr = 'Configuration Error (prefix '.
  378. (string)$this->configPrefix .'): ';
  379. //options that shall not be empty
  380. $options = array('ldapHost', 'ldapPort', 'ldapUserDisplayName',
  381. 'ldapGroupDisplayName', 'ldapLoginFilter');
  382. foreach($options as $key) {
  383. $val = $this->configuration->$key;
  384. if(empty($val)) {
  385. switch($key) {
  386. case 'ldapHost':
  387. $subj = 'LDAP Host';
  388. break;
  389. case 'ldapPort':
  390. $subj = 'LDAP Port';
  391. break;
  392. case 'ldapUserDisplayName':
  393. $subj = 'LDAP User Display Name';
  394. break;
  395. case 'ldapGroupDisplayName':
  396. $subj = 'LDAP Group Display Name';
  397. break;
  398. case 'ldapLoginFilter':
  399. $subj = 'LDAP Login Filter';
  400. break;
  401. default:
  402. $subj = $key;
  403. break;
  404. }
  405. $configurationOK = false;
  406. \OCP\Util::writeLog(
  407. 'user_ldap',
  408. $errorStr.'No '.$subj.' given!',
  409. ILogger::WARN
  410. );
  411. }
  412. }
  413. //combinations
  414. $agent = $this->configuration->ldapAgentName;
  415. $pwd = $this->configuration->ldapAgentPassword;
  416. if (
  417. ($agent === '' && $pwd !== '')
  418. || ($agent !== '' && $pwd === '')
  419. ) {
  420. \OCP\Util::writeLog(
  421. 'user_ldap',
  422. $errorStr.'either no password is given for the user ' .
  423. 'agent or a password is given, but not an LDAP agent.',
  424. ILogger::WARN);
  425. $configurationOK = false;
  426. }
  427. $base = $this->configuration->ldapBase;
  428. $baseUsers = $this->configuration->ldapBaseUsers;
  429. $baseGroups = $this->configuration->ldapBaseGroups;
  430. if(empty($base) && empty($baseUsers) && empty($baseGroups)) {
  431. \OCP\Util::writeLog(
  432. 'user_ldap',
  433. $errorStr.'Not a single Base DN given.',
  434. ILogger::WARN
  435. );
  436. $configurationOK = false;
  437. }
  438. if(mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8')
  439. === false) {
  440. \OCP\Util::writeLog(
  441. 'user_ldap',
  442. $errorStr.'login filter does not contain %uid place holder.',
  443. ILogger::WARN
  444. );
  445. $configurationOK = false;
  446. }
  447. return $configurationOK;
  448. }
  449. /**
  450. * Validates the user specified configuration
  451. * @return bool true if configuration seems OK, false otherwise
  452. */
  453. private function validateConfiguration() {
  454. if($this->doNotValidate) {
  455. //don't do a validation if it is a new configuration with pure
  456. //default values. Will be allowed on changes via __set or
  457. //setConfiguration
  458. return false;
  459. }
  460. // first step: "soft" checks: settings that are not really
  461. // necessary, but advisable. If left empty, give an info message
  462. $this->doSoftValidation();
  463. //second step: critical checks. If left empty or filled wrong, mark as
  464. //not configured and give a warning.
  465. return $this->doCriticalValidation();
  466. }
  467. /**
  468. * Connects and Binds to LDAP
  469. *
  470. * @throws ServerNotAvailableException
  471. */
  472. private function establishConnection() {
  473. if(!$this->configuration->ldapConfigurationActive) {
  474. return null;
  475. }
  476. static $phpLDAPinstalled = true;
  477. if(!$phpLDAPinstalled) {
  478. return false;
  479. }
  480. if(!$this->ignoreValidation && !$this->configured) {
  481. \OCP\Util::writeLog(
  482. 'user_ldap',
  483. 'Configuration is invalid, cannot connect',
  484. ILogger::WARN
  485. );
  486. return false;
  487. }
  488. if(!$this->ldapConnectionRes) {
  489. if(!$this->ldap->areLDAPFunctionsAvailable()) {
  490. $phpLDAPinstalled = false;
  491. \OCP\Util::writeLog(
  492. 'user_ldap',
  493. 'function ldap_connect is not available. Make sure that the PHP ldap module is installed.',
  494. ILogger::ERROR
  495. );
  496. return false;
  497. }
  498. if($this->configuration->turnOffCertCheck) {
  499. if(putenv('LDAPTLS_REQCERT=never')) {
  500. \OCP\Util::writeLog('user_ldap',
  501. 'Turned off SSL certificate validation successfully.',
  502. ILogger::DEBUG);
  503. } else {
  504. \OCP\Util::writeLog(
  505. 'user_ldap',
  506. 'Could not turn off SSL certificate validation.',
  507. ILogger::WARN
  508. );
  509. }
  510. }
  511. $isOverrideMainServer = ($this->configuration->ldapOverrideMainServer
  512. || $this->getFromCache('overrideMainServer'));
  513. $isBackupHost = (trim($this->configuration->ldapBackupHost) !== "");
  514. $bindStatus = false;
  515. try {
  516. if (!$isOverrideMainServer) {
  517. $this->doConnect($this->configuration->ldapHost,
  518. $this->configuration->ldapPort);
  519. return $this->bind();
  520. }
  521. } catch (ServerNotAvailableException $e) {
  522. if(!$isBackupHost) {
  523. throw $e;
  524. }
  525. }
  526. //if LDAP server is not reachable, try the Backup (Replica!) Server
  527. if($isBackupHost || $isOverrideMainServer) {
  528. $this->doConnect($this->configuration->ldapBackupHost,
  529. $this->configuration->ldapBackupPort);
  530. $this->bindResult = [];
  531. $bindStatus = $this->bind();
  532. $error = $this->ldap->isResource($this->ldapConnectionRes) ?
  533. $this->ldap->errno($this->ldapConnectionRes) : -1;
  534. if($bindStatus && $error === 0 && !$this->getFromCache('overrideMainServer')) {
  535. //when bind to backup server succeeded and failed to main server,
  536. //skip contacting him until next cache refresh
  537. $this->writeToCache('overrideMainServer', true);
  538. }
  539. }
  540. return $bindStatus;
  541. }
  542. return null;
  543. }
  544. /**
  545. * @param string $host
  546. * @param string $port
  547. * @return bool
  548. * @throws \OC\ServerNotAvailableException
  549. */
  550. private function doConnect($host, $port) {
  551. if ($host === '') {
  552. return false;
  553. }
  554. $this->ldapConnectionRes = $this->ldap->connect($host, $port);
  555. if(!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) {
  556. throw new ServerNotAvailableException('Could not set required LDAP Protocol version.');
  557. }
  558. if(!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) {
  559. throw new ServerNotAvailableException('Could not disable LDAP referrals.');
  560. }
  561. if($this->configuration->ldapTLS) {
  562. if(!$this->ldap->startTls($this->ldapConnectionRes)) {
  563. throw new ServerNotAvailableException('Start TLS failed, when connecting to LDAP host ' . $host . '.');
  564. }
  565. }
  566. return true;
  567. }
  568. /**
  569. * Binds to LDAP
  570. */
  571. public function bind() {
  572. if(!$this->configuration->ldapConfigurationActive) {
  573. return false;
  574. }
  575. $cr = $this->ldapConnectionRes;
  576. if(!$this->ldap->isResource($cr)) {
  577. $cr = $this->getConnectionResource();
  578. }
  579. if(
  580. count($this->bindResult) !== 0
  581. && $this->bindResult['dn'] === $this->configuration->ldapAgentName
  582. && \OC::$server->getHasher()->verify(
  583. $this->configPrefix . $this->configuration->ldapAgentPassword,
  584. $this->bindResult['hash']
  585. )
  586. ) {
  587. // don't attempt to bind again with the same data as before
  588. // bind might have been invoked via getConnectionResource(),
  589. // but we need results specifically for e.g. user login
  590. return $this->bindResult['result'];
  591. }
  592. $ldapLogin = @$this->ldap->bind($cr,
  593. $this->configuration->ldapAgentName,
  594. $this->configuration->ldapAgentPassword);
  595. $this->bindResult = [
  596. 'dn' => $this->configuration->ldapAgentName,
  597. 'hash' => \OC::$server->getHasher()->hash($this->configPrefix . $this->configuration->ldapAgentPassword),
  598. 'result' => $ldapLogin,
  599. ];
  600. if(!$ldapLogin) {
  601. $errno = $this->ldap->errno($cr);
  602. \OCP\Util::writeLog('user_ldap',
  603. 'Bind failed: ' . $errno . ': ' . $this->ldap->error($cr),
  604. ILogger::WARN);
  605. // Set to failure mode, if LDAP error code is not LDAP_SUCCESS or LDAP_INVALID_CREDENTIALS
  606. if($errno !== 0x00 && $errno !== 0x31) {
  607. $this->ldapConnectionRes = null;
  608. }
  609. return false;
  610. }
  611. return true;
  612. }
  613. }