Configuration.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Alexander Bergolth <leo@strike.wu.ac.at>
  6. * @author Alex Weirig <alex.weirig@technolink.lu>
  7. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  8. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  9. * @author Joas Schilling <coding@schilljs.com>
  10. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  11. * @author Lennart Rosam <hello@takuto.de>
  12. * @author Lukas Reschke <lukas@statuscode.ch>
  13. * @author Morris Jobke <hey@morrisjobke.de>
  14. * @author Robin McCorkell <robin@mccorkell.me.uk>
  15. * @author Roeland Jago Douma <roeland@famdouma.nl>
  16. * @author Roger Szabo <roger.szabo@web.de>
  17. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  18. * @author Xuanwo <xuanwo@yunify.com>
  19. *
  20. * @license AGPL-3.0
  21. *
  22. * This code is free software: you can redistribute it and/or modify
  23. * it under the terms of the GNU Affero General Public License, version 3,
  24. * as published by the Free Software Foundation.
  25. *
  26. * This program is distributed in the hope that it will be useful,
  27. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  29. * GNU Affero General Public License for more details.
  30. *
  31. * You should have received a copy of the GNU Affero General Public License, version 3,
  32. * along with this program. If not, see <http://www.gnu.org/licenses/>
  33. *
  34. */
  35. namespace OCA\User_LDAP;
  36. /**
  37. * @property int ldapPagingSize holds an integer
  38. * @property string ldapUserAvatarRule
  39. */
  40. class Configuration {
  41. public const AVATAR_PREFIX_DEFAULT = 'default';
  42. public const AVATAR_PREFIX_NONE = 'none';
  43. public const AVATAR_PREFIX_DATA_ATTRIBUTE = 'data:';
  44. public const LDAP_SERVER_FEATURE_UNKNOWN = 'unknown';
  45. public const LDAP_SERVER_FEATURE_AVAILABLE = 'available';
  46. public const LDAP_SERVER_FEATURE_UNAVAILABLE = 'unavailable';
  47. /**
  48. * @var string
  49. */
  50. protected $configPrefix;
  51. /**
  52. * @var bool
  53. */
  54. protected $configRead = false;
  55. /**
  56. * @var string[]
  57. */
  58. protected array $unsavedChanges = [];
  59. /**
  60. * @var array<string, mixed> settings
  61. */
  62. protected $config = [
  63. 'ldapHost' => null,
  64. 'ldapPort' => null,
  65. 'ldapBackupHost' => null,
  66. 'ldapBackupPort' => null,
  67. 'ldapBackgroundHost' => null,
  68. 'ldapBackgroundPort' => null,
  69. 'ldapBase' => null,
  70. 'ldapBaseUsers' => null,
  71. 'ldapBaseGroups' => null,
  72. 'ldapAgentName' => null,
  73. 'ldapAgentPassword' => null,
  74. 'ldapTLS' => null,
  75. 'turnOffCertCheck' => null,
  76. 'ldapIgnoreNamingRules' => null,
  77. 'ldapUserDisplayName' => null,
  78. 'ldapUserDisplayName2' => null,
  79. 'ldapUserAvatarRule' => null,
  80. 'ldapGidNumber' => null,
  81. 'ldapUserFilterObjectclass' => null,
  82. 'ldapUserFilterGroups' => null,
  83. 'ldapUserFilter' => null,
  84. 'ldapUserFilterMode' => null,
  85. 'ldapGroupFilter' => null,
  86. 'ldapGroupFilterMode' => null,
  87. 'ldapGroupFilterObjectclass' => null,
  88. 'ldapGroupFilterGroups' => null,
  89. 'ldapGroupDisplayName' => null,
  90. 'ldapGroupMemberAssocAttr' => null,
  91. 'ldapLoginFilter' => null,
  92. 'ldapLoginFilterMode' => null,
  93. 'ldapLoginFilterEmail' => null,
  94. 'ldapLoginFilterUsername' => null,
  95. 'ldapLoginFilterAttributes' => null,
  96. 'ldapQuotaAttribute' => null,
  97. 'ldapQuotaDefault' => null,
  98. 'ldapEmailAttribute' => null,
  99. 'ldapCacheTTL' => null,
  100. 'ldapUuidUserAttribute' => 'auto',
  101. 'ldapUuidGroupAttribute' => 'auto',
  102. 'ldapOverrideMainServer' => false,
  103. 'ldapConfigurationActive' => false,
  104. 'ldapAttributesForUserSearch' => null,
  105. 'ldapAttributesForGroupSearch' => null,
  106. 'ldapExperiencedAdmin' => false,
  107. 'homeFolderNamingRule' => null,
  108. 'hasMemberOfFilterSupport' => false,
  109. 'useMemberOfToDetectMembership' => true,
  110. 'ldapExpertUsernameAttr' => null,
  111. 'ldapExpertUUIDUserAttr' => null,
  112. 'ldapExpertUUIDGroupAttr' => null,
  113. 'lastJpegPhotoLookup' => null,
  114. 'ldapNestedGroups' => false,
  115. 'ldapPagingSize' => null,
  116. 'turnOnPasswordChange' => false,
  117. 'ldapDynamicGroupMemberURL' => null,
  118. 'ldapDefaultPPolicyDN' => null,
  119. 'ldapExtStorageHomeAttribute' => null,
  120. 'ldapMatchingRuleInChainState' => self::LDAP_SERVER_FEATURE_UNKNOWN,
  121. 'ldapConnectionTimeout' => 15,
  122. ];
  123. public function __construct(string $configPrefix, bool $autoRead = true) {
  124. $this->configPrefix = $configPrefix;
  125. if ($autoRead) {
  126. $this->readConfiguration();
  127. }
  128. }
  129. /**
  130. * @param string $name
  131. * @return mixed|null
  132. */
  133. public function __get($name) {
  134. if (isset($this->config[$name])) {
  135. return $this->config[$name];
  136. }
  137. return null;
  138. }
  139. /**
  140. * @param string $name
  141. * @param mixed $value
  142. */
  143. public function __set($name, $value) {
  144. $this->setConfiguration([$name => $value]);
  145. }
  146. public function getConfiguration(): array {
  147. return $this->config;
  148. }
  149. /**
  150. * set LDAP configuration with values delivered by an array, not read
  151. * from configuration. It does not save the configuration! To do so, you
  152. * must call saveConfiguration afterwards.
  153. * @param array $config array that holds the config parameters in an associated
  154. * array
  155. * @param array &$applied optional; array where the set fields will be given to
  156. */
  157. public function setConfiguration(array $config, array &$applied = null): void {
  158. $cta = $this->getConfigTranslationArray();
  159. foreach ($config as $inputKey => $val) {
  160. if (strpos($inputKey, '_') !== false && array_key_exists($inputKey, $cta)) {
  161. $key = $cta[$inputKey];
  162. } elseif (array_key_exists($inputKey, $this->config)) {
  163. $key = $inputKey;
  164. } else {
  165. continue;
  166. }
  167. $setMethod = 'setValue';
  168. switch ($key) {
  169. case 'ldapAgentPassword':
  170. $setMethod = 'setRawValue';
  171. break;
  172. case 'homeFolderNamingRule':
  173. $trimmedVal = trim($val);
  174. if ($trimmedVal !== '' && strpos($val, 'attr:') === false) {
  175. $val = 'attr:'.$trimmedVal;
  176. }
  177. break;
  178. case 'ldapBase':
  179. case 'ldapBaseUsers':
  180. case 'ldapBaseGroups':
  181. case 'ldapAttributesForUserSearch':
  182. case 'ldapAttributesForGroupSearch':
  183. case 'ldapUserFilterObjectclass':
  184. case 'ldapUserFilterGroups':
  185. case 'ldapGroupFilterObjectclass':
  186. case 'ldapGroupFilterGroups':
  187. case 'ldapLoginFilterAttributes':
  188. $setMethod = 'setMultiLine';
  189. break;
  190. }
  191. $this->$setMethod($key, $val);
  192. if (is_array($applied)) {
  193. $applied[] = $inputKey;
  194. // storing key as index avoids duplication, and as value for simplicity
  195. }
  196. $this->unsavedChanges[$key] = $key;
  197. }
  198. }
  199. public function readConfiguration(): void {
  200. if (!$this->configRead) {
  201. $cta = array_flip($this->getConfigTranslationArray());
  202. foreach ($this->config as $key => $val) {
  203. if (!isset($cta[$key])) {
  204. //some are determined
  205. continue;
  206. }
  207. $dbKey = $cta[$key];
  208. switch ($key) {
  209. case 'ldapBase':
  210. case 'ldapBaseUsers':
  211. case 'ldapBaseGroups':
  212. case 'ldapAttributesForUserSearch':
  213. case 'ldapAttributesForGroupSearch':
  214. case 'ldapUserFilterObjectclass':
  215. case 'ldapUserFilterGroups':
  216. case 'ldapGroupFilterObjectclass':
  217. case 'ldapGroupFilterGroups':
  218. case 'ldapLoginFilterAttributes':
  219. $readMethod = 'getMultiLine';
  220. break;
  221. case 'ldapIgnoreNamingRules':
  222. $readMethod = 'getSystemValue';
  223. $dbKey = $key;
  224. break;
  225. case 'ldapAgentPassword':
  226. $readMethod = 'getPwd';
  227. break;
  228. case 'ldapUserDisplayName2':
  229. case 'ldapGroupDisplayName':
  230. $readMethod = 'getLcValue';
  231. break;
  232. case 'ldapUserDisplayName':
  233. default:
  234. // user display name does not lower case because
  235. // we rely on an upper case N as indicator whether to
  236. // auto-detect it or not. FIXME
  237. $readMethod = 'getValue';
  238. break;
  239. }
  240. $this->config[$key] = $this->$readMethod($dbKey);
  241. }
  242. $this->configRead = true;
  243. }
  244. }
  245. /**
  246. * saves the current config changes in the database
  247. */
  248. public function saveConfiguration(): void {
  249. $cta = array_flip($this->getConfigTranslationArray());
  250. $changed = false;
  251. foreach ($this->unsavedChanges as $key) {
  252. $value = $this->config[$key];
  253. switch ($key) {
  254. case 'ldapAgentPassword':
  255. $value = base64_encode($value);
  256. break;
  257. case 'ldapBase':
  258. case 'ldapBaseUsers':
  259. case 'ldapBaseGroups':
  260. case 'ldapAttributesForUserSearch':
  261. case 'ldapAttributesForGroupSearch':
  262. case 'ldapUserFilterObjectclass':
  263. case 'ldapUserFilterGroups':
  264. case 'ldapGroupFilterObjectclass':
  265. case 'ldapGroupFilterGroups':
  266. case 'ldapLoginFilterAttributes':
  267. if (is_array($value)) {
  268. $value = implode("\n", $value);
  269. }
  270. break;
  271. //following options are not stored but detected, skip them
  272. case 'ldapIgnoreNamingRules':
  273. case 'ldapUuidUserAttribute':
  274. case 'ldapUuidGroupAttribute':
  275. continue 2;
  276. }
  277. if (is_null($value)) {
  278. $value = '';
  279. }
  280. $changed = true;
  281. $this->saveValue($cta[$key], $value);
  282. }
  283. if ($changed) {
  284. $this->saveValue('_lastChange', (string)time());
  285. }
  286. $this->unsavedChanges = [];
  287. }
  288. /**
  289. * @param string $varName
  290. * @return array|string
  291. */
  292. protected function getMultiLine($varName) {
  293. $value = $this->getValue($varName);
  294. if (empty($value)) {
  295. $value = '';
  296. } else {
  297. $value = preg_split('/\r\n|\r|\n/', $value);
  298. }
  299. return $value;
  300. }
  301. /**
  302. * Sets multi-line values as arrays
  303. *
  304. * @param string $varName name of config-key
  305. * @param array|string $value to set
  306. */
  307. protected function setMultiLine(string $varName, $value): void {
  308. if (empty($value)) {
  309. $value = '';
  310. } elseif (!is_array($value)) {
  311. $value = preg_split('/\r\n|\r|\n|;/', $value);
  312. if ($value === false) {
  313. $value = '';
  314. }
  315. }
  316. if (!is_array($value)) {
  317. $finalValue = trim($value);
  318. } else {
  319. $finalValue = [];
  320. foreach ($value as $key => $val) {
  321. if (is_string($val)) {
  322. $val = trim($val);
  323. if ($val !== '') {
  324. //accidental line breaks are not wanted and can cause
  325. // odd behaviour. Thus, away with them.
  326. $finalValue[] = $val;
  327. }
  328. } else {
  329. $finalValue[] = $val;
  330. }
  331. }
  332. }
  333. $this->setRawValue($varName, $finalValue);
  334. }
  335. protected function getPwd(string $varName): string {
  336. return base64_decode($this->getValue($varName));
  337. }
  338. protected function getLcValue(string $varName): string {
  339. return mb_strtolower($this->getValue($varName), 'UTF-8');
  340. }
  341. protected function getSystemValue(string $varName): string {
  342. //FIXME: if another system value is added, softcode the default value
  343. return \OC::$server->getConfig()->getSystemValue($varName, false);
  344. }
  345. protected function getValue(string $varName): string {
  346. static $defaults;
  347. if (is_null($defaults)) {
  348. $defaults = $this->getDefaults();
  349. }
  350. return \OC::$server->getConfig()->getAppValue('user_ldap',
  351. $this->configPrefix.$varName,
  352. $defaults[$varName]);
  353. }
  354. /**
  355. * Sets a scalar value.
  356. *
  357. * @param string $varName name of config key
  358. * @param mixed $value to set
  359. */
  360. protected function setValue(string $varName, $value): void {
  361. if (is_string($value)) {
  362. $value = trim($value);
  363. }
  364. $this->config[$varName] = $value;
  365. }
  366. /**
  367. * Sets a scalar value without trimming.
  368. *
  369. * @param string $varName name of config key
  370. * @param mixed $value to set
  371. */
  372. protected function setRawValue(string $varName, $value): void {
  373. $this->config[$varName] = $value;
  374. }
  375. protected function saveValue(string $varName, string $value): bool {
  376. \OC::$server->getConfig()->setAppValue(
  377. 'user_ldap',
  378. $this->configPrefix.$varName,
  379. $value
  380. );
  381. return true;
  382. }
  383. /**
  384. * @return array an associative array with the default values. Keys are correspond
  385. * to config-value entries in the database table
  386. */
  387. public function getDefaults(): array {
  388. return [
  389. 'ldap_host' => '',
  390. 'ldap_port' => '',
  391. 'ldap_backup_host' => '',
  392. 'ldap_backup_port' => '',
  393. 'ldap_background_host' => '',
  394. 'ldap_background_port' => '',
  395. 'ldap_override_main_server' => '',
  396. 'ldap_dn' => '',
  397. 'ldap_agent_password' => '',
  398. 'ldap_base' => '',
  399. 'ldap_base_users' => '',
  400. 'ldap_base_groups' => '',
  401. 'ldap_userlist_filter' => '',
  402. 'ldap_user_filter_mode' => 0,
  403. 'ldap_userfilter_objectclass' => '',
  404. 'ldap_userfilter_groups' => '',
  405. 'ldap_login_filter' => '',
  406. 'ldap_login_filter_mode' => 0,
  407. 'ldap_loginfilter_email' => 0,
  408. 'ldap_loginfilter_username' => 1,
  409. 'ldap_loginfilter_attributes' => '',
  410. 'ldap_group_filter' => '',
  411. 'ldap_group_filter_mode' => 0,
  412. 'ldap_groupfilter_objectclass' => '',
  413. 'ldap_groupfilter_groups' => '',
  414. 'ldap_gid_number' => 'gidNumber',
  415. 'ldap_display_name' => 'displayName',
  416. 'ldap_user_display_name_2' => '',
  417. 'ldap_group_display_name' => 'cn',
  418. 'ldap_tls' => 0,
  419. 'ldap_quota_def' => '',
  420. 'ldap_quota_attr' => '',
  421. 'ldap_email_attr' => '',
  422. 'ldap_group_member_assoc_attribute' => '',
  423. 'ldap_cache_ttl' => 600,
  424. 'ldap_uuid_user_attribute' => 'auto',
  425. 'ldap_uuid_group_attribute' => 'auto',
  426. 'home_folder_naming_rule' => '',
  427. 'ldap_turn_off_cert_check' => 0,
  428. 'ldap_configuration_active' => 0,
  429. 'ldap_attributes_for_user_search' => '',
  430. 'ldap_attributes_for_group_search' => '',
  431. 'ldap_expert_username_attr' => '',
  432. 'ldap_expert_uuid_user_attr' => '',
  433. 'ldap_expert_uuid_group_attr' => '',
  434. 'has_memberof_filter_support' => 0,
  435. 'use_memberof_to_detect_membership' => 1,
  436. 'last_jpegPhoto_lookup' => 0,
  437. 'ldap_nested_groups' => 0,
  438. 'ldap_paging_size' => 500,
  439. 'ldap_turn_on_pwd_change' => 0,
  440. 'ldap_experienced_admin' => 0,
  441. 'ldap_dynamic_group_member_url' => '',
  442. 'ldap_default_ppolicy_dn' => '',
  443. 'ldap_user_avatar_rule' => 'default',
  444. 'ldap_ext_storage_home_attribute' => '',
  445. 'ldap_matching_rule_in_chain_state' => self::LDAP_SERVER_FEATURE_UNKNOWN,
  446. 'ldap_connection_timeout' => 15,
  447. ];
  448. }
  449. /**
  450. * @return array that maps internal variable names to database fields
  451. */
  452. public function getConfigTranslationArray(): array {
  453. //TODO: merge them into one representation
  454. static $array = [
  455. 'ldap_host' => 'ldapHost',
  456. 'ldap_port' => 'ldapPort',
  457. 'ldap_backup_host' => 'ldapBackupHost',
  458. 'ldap_backup_port' => 'ldapBackupPort',
  459. 'ldap_background_host' => 'ldapBackgroundHost',
  460. 'ldap_background_port' => 'ldapBackgroundPort',
  461. 'ldap_override_main_server' => 'ldapOverrideMainServer',
  462. 'ldap_dn' => 'ldapAgentName',
  463. 'ldap_agent_password' => 'ldapAgentPassword',
  464. 'ldap_base' => 'ldapBase',
  465. 'ldap_base_users' => 'ldapBaseUsers',
  466. 'ldap_base_groups' => 'ldapBaseGroups',
  467. 'ldap_userfilter_objectclass' => 'ldapUserFilterObjectclass',
  468. 'ldap_userfilter_groups' => 'ldapUserFilterGroups',
  469. 'ldap_userlist_filter' => 'ldapUserFilter',
  470. 'ldap_user_filter_mode' => 'ldapUserFilterMode',
  471. 'ldap_user_avatar_rule' => 'ldapUserAvatarRule',
  472. 'ldap_login_filter' => 'ldapLoginFilter',
  473. 'ldap_login_filter_mode' => 'ldapLoginFilterMode',
  474. 'ldap_loginfilter_email' => 'ldapLoginFilterEmail',
  475. 'ldap_loginfilter_username' => 'ldapLoginFilterUsername',
  476. 'ldap_loginfilter_attributes' => 'ldapLoginFilterAttributes',
  477. 'ldap_group_filter' => 'ldapGroupFilter',
  478. 'ldap_group_filter_mode' => 'ldapGroupFilterMode',
  479. 'ldap_groupfilter_objectclass' => 'ldapGroupFilterObjectclass',
  480. 'ldap_groupfilter_groups' => 'ldapGroupFilterGroups',
  481. 'ldap_gid_number' => 'ldapGidNumber',
  482. 'ldap_display_name' => 'ldapUserDisplayName',
  483. 'ldap_user_display_name_2' => 'ldapUserDisplayName2',
  484. 'ldap_group_display_name' => 'ldapGroupDisplayName',
  485. 'ldap_tls' => 'ldapTLS',
  486. 'ldap_quota_def' => 'ldapQuotaDefault',
  487. 'ldap_quota_attr' => 'ldapQuotaAttribute',
  488. 'ldap_email_attr' => 'ldapEmailAttribute',
  489. 'ldap_group_member_assoc_attribute' => 'ldapGroupMemberAssocAttr',
  490. 'ldap_cache_ttl' => 'ldapCacheTTL',
  491. 'home_folder_naming_rule' => 'homeFolderNamingRule',
  492. 'ldap_turn_off_cert_check' => 'turnOffCertCheck',
  493. 'ldap_configuration_active' => 'ldapConfigurationActive',
  494. 'ldap_attributes_for_user_search' => 'ldapAttributesForUserSearch',
  495. 'ldap_attributes_for_group_search' => 'ldapAttributesForGroupSearch',
  496. 'ldap_expert_username_attr' => 'ldapExpertUsernameAttr',
  497. 'ldap_expert_uuid_user_attr' => 'ldapExpertUUIDUserAttr',
  498. 'ldap_expert_uuid_group_attr' => 'ldapExpertUUIDGroupAttr',
  499. 'has_memberof_filter_support' => 'hasMemberOfFilterSupport',
  500. 'use_memberof_to_detect_membership' => 'useMemberOfToDetectMembership',
  501. 'last_jpegPhoto_lookup' => 'lastJpegPhotoLookup',
  502. 'ldap_nested_groups' => 'ldapNestedGroups',
  503. 'ldap_paging_size' => 'ldapPagingSize',
  504. 'ldap_turn_on_pwd_change' => 'turnOnPasswordChange',
  505. 'ldap_experienced_admin' => 'ldapExperiencedAdmin',
  506. 'ldap_dynamic_group_member_url' => 'ldapDynamicGroupMemberURL',
  507. 'ldap_default_ppolicy_dn' => 'ldapDefaultPPolicyDN',
  508. 'ldap_ext_storage_home_attribute' => 'ldapExtStorageHomeAttribute',
  509. 'ldap_matching_rule_in_chain_state' => 'ldapMatchingRuleInChainState',
  510. 'ldapIgnoreNamingRules' => 'ldapIgnoreNamingRules', // sysconfig
  511. 'ldap_connection_timeout' => 'ldapConnectionTimeout',
  512. ];
  513. return $array;
  514. }
  515. /**
  516. * @throws \RuntimeException
  517. */
  518. public function resolveRule(string $rule): array {
  519. if ($rule === 'avatar') {
  520. return $this->getAvatarAttributes();
  521. }
  522. throw new \RuntimeException('Invalid rule');
  523. }
  524. public function getAvatarAttributes(): array {
  525. $value = $this->ldapUserAvatarRule ?: self::AVATAR_PREFIX_DEFAULT;
  526. $defaultAttributes = ['jpegphoto', 'thumbnailphoto'];
  527. if ($value === self::AVATAR_PREFIX_NONE) {
  528. return [];
  529. }
  530. if (strpos($value, self::AVATAR_PREFIX_DATA_ATTRIBUTE) === 0) {
  531. $attribute = trim(substr($value, strlen(self::AVATAR_PREFIX_DATA_ATTRIBUTE)));
  532. if ($attribute === '') {
  533. return $defaultAttributes;
  534. }
  535. return [strtolower($attribute)];
  536. }
  537. if ($value !== self::AVATAR_PREFIX_DEFAULT) {
  538. \OC::$server->getLogger()->warning('Invalid config value to ldapUserAvatarRule; falling back to default.');
  539. }
  540. return $defaultAttributes;
  541. }
  542. /**
  543. * Returns TRUE if the ldapHost variable starts with 'ldapi://'
  544. */
  545. public function usesLdapi(): bool {
  546. return (substr($this->config['ldapHost'], 0, strlen('ldapi://')) === 'ldapi://');
  547. }
  548. }