@@ -36,13 +36,13 @@ discard block |
||
36 | 36 | $l = \OC::$server->getL10N('user_ldap'); |
37 | 37 | |
38 | 38 | if(!isset($_POST['action'])) { |
39 | - \OCP\JSON::error(array('message' => $l->t('No action specified'))); |
|
39 | + \OCP\JSON::error(array('message' => $l->t('No action specified'))); |
|
40 | 40 | } |
41 | 41 | $action = (string)$_POST['action']; |
42 | 42 | |
43 | 43 | |
44 | 44 | if(!isset($_POST['ldap_serverconfig_chooser'])) { |
45 | - \OCP\JSON::error(array('message' => $l->t('No configuration specified'))); |
|
45 | + \OCP\JSON::error(array('message' => $l->t('No configuration specified'))); |
|
46 | 46 | } |
47 | 47 | $prefix = (string)$_POST['ldap_serverconfig_chooser']; |
48 | 48 | |
@@ -55,95 +55,95 @@ discard block |
||
55 | 55 | $con->setIgnoreValidation(true); |
56 | 56 | |
57 | 57 | $userManager = new \OCA\User_LDAP\User\Manager( |
58 | - \OC::$server->getConfig(), |
|
59 | - new \OCA\User_LDAP\FilesystemHelper(), |
|
60 | - new \OCA\User_LDAP\LogWrapper(), |
|
61 | - \OC::$server->getAvatarManager(), |
|
62 | - new \OCP\Image(), |
|
63 | - \OC::$server->getDatabaseConnection(), |
|
64 | - \OC::$server->getUserManager(), |
|
65 | - \OC::$server->getNotificationManager()); |
|
58 | + \OC::$server->getConfig(), |
|
59 | + new \OCA\User_LDAP\FilesystemHelper(), |
|
60 | + new \OCA\User_LDAP\LogWrapper(), |
|
61 | + \OC::$server->getAvatarManager(), |
|
62 | + new \OCP\Image(), |
|
63 | + \OC::$server->getDatabaseConnection(), |
|
64 | + \OC::$server->getUserManager(), |
|
65 | + \OC::$server->getNotificationManager()); |
|
66 | 66 | |
67 | 67 | $access = new \OCA\User_LDAP\Access( |
68 | - $con, |
|
69 | - $ldapWrapper, |
|
70 | - $userManager, |
|
71 | - new \OCA\User_LDAP\Helper(\OC::$server->getConfig()), |
|
72 | - \OC::$server->getConfig() |
|
68 | + $con, |
|
69 | + $ldapWrapper, |
|
70 | + $userManager, |
|
71 | + new \OCA\User_LDAP\Helper(\OC::$server->getConfig()), |
|
72 | + \OC::$server->getConfig() |
|
73 | 73 | ); |
74 | 74 | |
75 | 75 | $wizard = new \OCA\User_LDAP\Wizard($configuration, $ldapWrapper, $access); |
76 | 76 | |
77 | 77 | switch($action) { |
78 | - case 'guessPortAndTLS': |
|
79 | - case 'guessBaseDN': |
|
80 | - case 'detectEmailAttribute': |
|
81 | - case 'detectUserDisplayNameAttribute': |
|
82 | - case 'determineGroupMemberAssoc': |
|
83 | - case 'determineUserObjectClasses': |
|
84 | - case 'determineGroupObjectClasses': |
|
85 | - case 'determineGroupsForUsers': |
|
86 | - case 'determineGroupsForGroups': |
|
87 | - case 'determineAttributes': |
|
88 | - case 'getUserListFilter': |
|
89 | - case 'getUserLoginFilter': |
|
90 | - case 'getGroupFilter': |
|
91 | - case 'countUsers': |
|
92 | - case 'countGroups': |
|
93 | - case 'countInBaseDN': |
|
94 | - try { |
|
95 | - $result = $wizard->$action(); |
|
96 | - if($result !== false) { |
|
97 | - OCP\JSON::success($result->getResultArray()); |
|
98 | - exit; |
|
99 | - } |
|
100 | - } catch (\Exception $e) { |
|
101 | - \OCP\JSON::error(array('message' => $e->getMessage(), 'code' => $e->getCode())); |
|
102 | - exit; |
|
103 | - } |
|
104 | - \OCP\JSON::error(); |
|
105 | - exit; |
|
106 | - break; |
|
78 | + case 'guessPortAndTLS': |
|
79 | + case 'guessBaseDN': |
|
80 | + case 'detectEmailAttribute': |
|
81 | + case 'detectUserDisplayNameAttribute': |
|
82 | + case 'determineGroupMemberAssoc': |
|
83 | + case 'determineUserObjectClasses': |
|
84 | + case 'determineGroupObjectClasses': |
|
85 | + case 'determineGroupsForUsers': |
|
86 | + case 'determineGroupsForGroups': |
|
87 | + case 'determineAttributes': |
|
88 | + case 'getUserListFilter': |
|
89 | + case 'getUserLoginFilter': |
|
90 | + case 'getGroupFilter': |
|
91 | + case 'countUsers': |
|
92 | + case 'countGroups': |
|
93 | + case 'countInBaseDN': |
|
94 | + try { |
|
95 | + $result = $wizard->$action(); |
|
96 | + if($result !== false) { |
|
97 | + OCP\JSON::success($result->getResultArray()); |
|
98 | + exit; |
|
99 | + } |
|
100 | + } catch (\Exception $e) { |
|
101 | + \OCP\JSON::error(array('message' => $e->getMessage(), 'code' => $e->getCode())); |
|
102 | + exit; |
|
103 | + } |
|
104 | + \OCP\JSON::error(); |
|
105 | + exit; |
|
106 | + break; |
|
107 | 107 | |
108 | - case 'testLoginName': { |
|
109 | - try { |
|
110 | - $loginName = $_POST['ldap_test_loginname']; |
|
111 | - $result = $wizard->$action($loginName); |
|
112 | - if($result !== false) { |
|
113 | - OCP\JSON::success($result->getResultArray()); |
|
114 | - exit; |
|
115 | - } |
|
116 | - } catch (\Exception $e) { |
|
117 | - \OCP\JSON::error(array('message' => $e->getMessage())); |
|
118 | - exit; |
|
119 | - } |
|
120 | - \OCP\JSON::error(); |
|
121 | - exit; |
|
122 | - break; |
|
123 | - } |
|
108 | + case 'testLoginName': { |
|
109 | + try { |
|
110 | + $loginName = $_POST['ldap_test_loginname']; |
|
111 | + $result = $wizard->$action($loginName); |
|
112 | + if($result !== false) { |
|
113 | + OCP\JSON::success($result->getResultArray()); |
|
114 | + exit; |
|
115 | + } |
|
116 | + } catch (\Exception $e) { |
|
117 | + \OCP\JSON::error(array('message' => $e->getMessage())); |
|
118 | + exit; |
|
119 | + } |
|
120 | + \OCP\JSON::error(); |
|
121 | + exit; |
|
122 | + break; |
|
123 | + } |
|
124 | 124 | |
125 | - case 'save': |
|
126 | - $key = isset($_POST['cfgkey']) ? $_POST['cfgkey'] : false; |
|
127 | - $val = isset($_POST['cfgval']) ? $_POST['cfgval'] : null; |
|
128 | - if($key === false || is_null($val)) { |
|
129 | - \OCP\JSON::error(array('message' => $l->t('No data specified'))); |
|
130 | - exit; |
|
131 | - } |
|
132 | - $cfg = array($key => $val); |
|
133 | - $setParameters = array(); |
|
134 | - $configuration->setConfiguration($cfg, $setParameters); |
|
135 | - if(!in_array($key, $setParameters)) { |
|
136 | - \OCP\JSON::error(array('message' => $l->t($key. |
|
137 | - ' Could not set configuration %s', $setParameters[0]))); |
|
138 | - exit; |
|
139 | - } |
|
140 | - $configuration->saveConfiguration(); |
|
141 | - //clear the cache on save |
|
142 | - $connection = new \OCA\User_LDAP\Connection($ldapWrapper, $prefix); |
|
143 | - $connection->clearCache(); |
|
144 | - OCP\JSON::success(); |
|
145 | - break; |
|
146 | - default: |
|
147 | - \OCP\JSON::error(array('message' => $l->t('Action does not exist'))); |
|
148 | - break; |
|
125 | + case 'save': |
|
126 | + $key = isset($_POST['cfgkey']) ? $_POST['cfgkey'] : false; |
|
127 | + $val = isset($_POST['cfgval']) ? $_POST['cfgval'] : null; |
|
128 | + if($key === false || is_null($val)) { |
|
129 | + \OCP\JSON::error(array('message' => $l->t('No data specified'))); |
|
130 | + exit; |
|
131 | + } |
|
132 | + $cfg = array($key => $val); |
|
133 | + $setParameters = array(); |
|
134 | + $configuration->setConfiguration($cfg, $setParameters); |
|
135 | + if(!in_array($key, $setParameters)) { |
|
136 | + \OCP\JSON::error(array('message' => $l->t($key. |
|
137 | + ' Could not set configuration %s', $setParameters[0]))); |
|
138 | + exit; |
|
139 | + } |
|
140 | + $configuration->saveConfiguration(); |
|
141 | + //clear the cache on save |
|
142 | + $connection = new \OCA\User_LDAP\Connection($ldapWrapper, $prefix); |
|
143 | + $connection->clearCache(); |
|
144 | + OCP\JSON::success(); |
|
145 | + break; |
|
146 | + default: |
|
147 | + \OCP\JSON::error(array('message' => $l->t('Action does not exist'))); |
|
148 | + break; |
|
149 | 149 | } |
@@ -58,582 +58,582 @@ |
||
58 | 58 | * @property string ldapExpertUUIDGroupAttr |
59 | 59 | */ |
60 | 60 | class Connection extends LDAPUtility { |
61 | - private $ldapConnectionRes = null; |
|
62 | - private $configPrefix; |
|
63 | - private $configID; |
|
64 | - private $configured = false; |
|
65 | - private $hasPagedResultSupport = true; |
|
66 | - //whether connection should be kept on __destruct |
|
67 | - private $dontDestruct = false; |
|
68 | - |
|
69 | - /** |
|
70 | - * @var bool runtime flag that indicates whether supported primary groups are available |
|
71 | - */ |
|
72 | - public $hasPrimaryGroups = true; |
|
73 | - |
|
74 | - /** |
|
75 | - * @var bool runtime flag that indicates whether supported POSIX gidNumber are available |
|
76 | - */ |
|
77 | - public $hasGidNumber = true; |
|
78 | - |
|
79 | - //cache handler |
|
80 | - protected $cache; |
|
81 | - |
|
82 | - /** @var Configuration settings handler **/ |
|
83 | - protected $configuration; |
|
84 | - |
|
85 | - protected $doNotValidate = false; |
|
86 | - |
|
87 | - protected $ignoreValidation = false; |
|
88 | - |
|
89 | - /** |
|
90 | - * Constructor |
|
91 | - * @param ILDAPWrapper $ldap |
|
92 | - * @param string $configPrefix a string with the prefix for the configkey column (appconfig table) |
|
93 | - * @param string|null $configID a string with the value for the appid column (appconfig table) or null for on-the-fly connections |
|
94 | - */ |
|
95 | - public function __construct(ILDAPWrapper $ldap, $configPrefix = '', $configID = 'user_ldap') { |
|
96 | - parent::__construct($ldap); |
|
97 | - $this->configPrefix = $configPrefix; |
|
98 | - $this->configID = $configID; |
|
99 | - $this->configuration = new Configuration($configPrefix, |
|
100 | - !is_null($configID)); |
|
101 | - $memcache = \OC::$server->getMemCacheFactory(); |
|
102 | - if($memcache->isAvailable()) { |
|
103 | - $this->cache = $memcache->create(); |
|
104 | - } |
|
105 | - $helper = new Helper(\OC::$server->getConfig()); |
|
106 | - $this->doNotValidate = !in_array($this->configPrefix, |
|
107 | - $helper->getServerConfigurationPrefixes()); |
|
108 | - $this->hasPagedResultSupport = |
|
109 | - intval($this->configuration->ldapPagingSize) !== 0 |
|
110 | - || $this->ldap->hasPagedResultSupport(); |
|
111 | - } |
|
112 | - |
|
113 | - public function __destruct() { |
|
114 | - if(!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) { |
|
115 | - @$this->ldap->unbind($this->ldapConnectionRes); |
|
116 | - }; |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * defines behaviour when the instance is cloned |
|
121 | - */ |
|
122 | - public function __clone() { |
|
123 | - $this->configuration = new Configuration($this->configPrefix, |
|
124 | - !is_null($this->configID)); |
|
125 | - $this->ldapConnectionRes = null; |
|
126 | - $this->dontDestruct = true; |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * @param string $name |
|
131 | - * @return bool|mixed |
|
132 | - */ |
|
133 | - public function __get($name) { |
|
134 | - if(!$this->configured) { |
|
135 | - $this->readConfiguration(); |
|
136 | - } |
|
137 | - |
|
138 | - if($name === 'hasPagedResultSupport') { |
|
139 | - return $this->hasPagedResultSupport; |
|
140 | - } |
|
141 | - |
|
142 | - return $this->configuration->$name; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * @param string $name |
|
147 | - * @param mixed $value |
|
148 | - */ |
|
149 | - public function __set($name, $value) { |
|
150 | - $this->doNotValidate = false; |
|
151 | - $before = $this->configuration->$name; |
|
152 | - $this->configuration->$name = $value; |
|
153 | - $after = $this->configuration->$name; |
|
154 | - if($before !== $after) { |
|
155 | - if ($this->configID !== '' && $this->configID !== null) { |
|
156 | - $this->configuration->saveConfiguration(); |
|
157 | - } |
|
158 | - $this->validateConfiguration(); |
|
159 | - } |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * sets whether the result of the configuration validation shall |
|
164 | - * be ignored when establishing the connection. Used by the Wizard |
|
165 | - * in early configuration state. |
|
166 | - * @param bool $state |
|
167 | - */ |
|
168 | - public function setIgnoreValidation($state) { |
|
169 | - $this->ignoreValidation = (bool)$state; |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * initializes the LDAP backend |
|
174 | - * @param bool $force read the config settings no matter what |
|
175 | - */ |
|
176 | - public function init($force = false) { |
|
177 | - $this->readConfiguration($force); |
|
178 | - $this->establishConnection(); |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Returns the LDAP handler |
|
183 | - */ |
|
184 | - public function getConnectionResource() { |
|
185 | - if(!$this->ldapConnectionRes) { |
|
186 | - $this->init(); |
|
187 | - } else if(!$this->ldap->isResource($this->ldapConnectionRes)) { |
|
188 | - $this->ldapConnectionRes = null; |
|
189 | - $this->establishConnection(); |
|
190 | - } |
|
191 | - if(is_null($this->ldapConnectionRes)) { |
|
192 | - \OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server ' . $this->configuration->ldapHost, \OCP\Util::ERROR); |
|
193 | - throw new ServerNotAvailableException('Connection to LDAP server could not be established'); |
|
194 | - } |
|
195 | - return $this->ldapConnectionRes; |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * resets the connection resource |
|
200 | - */ |
|
201 | - public function resetConnectionResource() { |
|
202 | - if(!is_null($this->ldapConnectionRes)) { |
|
203 | - @$this->ldap->unbind($this->ldapConnectionRes); |
|
204 | - $this->ldapConnectionRes = null; |
|
205 | - } |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * @param string|null $key |
|
210 | - * @return string |
|
211 | - */ |
|
212 | - private function getCacheKey($key) { |
|
213 | - $prefix = 'LDAP-'.$this->configID.'-'.$this->configPrefix.'-'; |
|
214 | - if(is_null($key)) { |
|
215 | - return $prefix; |
|
216 | - } |
|
217 | - return $prefix.md5($key); |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * @param string $key |
|
222 | - * @return mixed|null |
|
223 | - */ |
|
224 | - public function getFromCache($key) { |
|
225 | - if(!$this->configured) { |
|
226 | - $this->readConfiguration(); |
|
227 | - } |
|
228 | - if(is_null($this->cache) || !$this->configuration->ldapCacheTTL) { |
|
229 | - return null; |
|
230 | - } |
|
231 | - $key = $this->getCacheKey($key); |
|
232 | - |
|
233 | - return json_decode(base64_decode($this->cache->get($key)), true); |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * @param string $key |
|
238 | - * @param mixed $value |
|
239 | - * |
|
240 | - * @return string |
|
241 | - */ |
|
242 | - public function writeToCache($key, $value) { |
|
243 | - if(!$this->configured) { |
|
244 | - $this->readConfiguration(); |
|
245 | - } |
|
246 | - if(is_null($this->cache) |
|
247 | - || !$this->configuration->ldapCacheTTL |
|
248 | - || !$this->configuration->ldapConfigurationActive) { |
|
249 | - return null; |
|
250 | - } |
|
251 | - $key = $this->getCacheKey($key); |
|
252 | - $value = base64_encode(json_encode($value)); |
|
253 | - $this->cache->set($key, $value, $this->configuration->ldapCacheTTL); |
|
254 | - } |
|
255 | - |
|
256 | - public function clearCache() { |
|
257 | - if(!is_null($this->cache)) { |
|
258 | - $this->cache->clear($this->getCacheKey(null)); |
|
259 | - } |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Caches the general LDAP configuration. |
|
264 | - * @param bool $force optional. true, if the re-read should be forced. defaults |
|
265 | - * to false. |
|
266 | - * @return null |
|
267 | - */ |
|
268 | - private function readConfiguration($force = false) { |
|
269 | - if((!$this->configured || $force) && !is_null($this->configID)) { |
|
270 | - $this->configuration->readConfiguration(); |
|
271 | - $this->configured = $this->validateConfiguration(); |
|
272 | - } |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * set LDAP configuration with values delivered by an array, not read from configuration |
|
277 | - * @param array $config array that holds the config parameters in an associated array |
|
278 | - * @param array &$setParameters optional; array where the set fields will be given to |
|
279 | - * @return boolean true if config validates, false otherwise. Check with $setParameters for detailed success on single parameters |
|
280 | - */ |
|
281 | - public function setConfiguration($config, &$setParameters = null) { |
|
282 | - if(is_null($setParameters)) { |
|
283 | - $setParameters = array(); |
|
284 | - } |
|
285 | - $this->doNotValidate = false; |
|
286 | - $this->configuration->setConfiguration($config, $setParameters); |
|
287 | - if(count($setParameters) > 0) { |
|
288 | - $this->configured = $this->validateConfiguration(); |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - return $this->configured; |
|
293 | - } |
|
294 | - |
|
295 | - /** |
|
296 | - * saves the current Configuration in the database and empties the |
|
297 | - * cache |
|
298 | - * @return null |
|
299 | - */ |
|
300 | - public function saveConfiguration() { |
|
301 | - $this->configuration->saveConfiguration(); |
|
302 | - $this->clearCache(); |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * get the current LDAP configuration |
|
307 | - * @return array |
|
308 | - */ |
|
309 | - public function getConfiguration() { |
|
310 | - $this->readConfiguration(); |
|
311 | - $config = $this->configuration->getConfiguration(); |
|
312 | - $cta = $this->configuration->getConfigTranslationArray(); |
|
313 | - $result = array(); |
|
314 | - foreach($cta as $dbkey => $configkey) { |
|
315 | - switch($configkey) { |
|
316 | - case 'homeFolderNamingRule': |
|
317 | - if(strpos($config[$configkey], 'attr:') === 0) { |
|
318 | - $result[$dbkey] = substr($config[$configkey], 5); |
|
319 | - } else { |
|
320 | - $result[$dbkey] = ''; |
|
321 | - } |
|
322 | - break; |
|
323 | - case 'ldapBase': |
|
324 | - case 'ldapBaseUsers': |
|
325 | - case 'ldapBaseGroups': |
|
326 | - case 'ldapAttributesForUserSearch': |
|
327 | - case 'ldapAttributesForGroupSearch': |
|
328 | - if(is_array($config[$configkey])) { |
|
329 | - $result[$dbkey] = implode("\n", $config[$configkey]); |
|
330 | - break; |
|
331 | - } //else follows default |
|
332 | - default: |
|
333 | - $result[$dbkey] = $config[$configkey]; |
|
334 | - } |
|
335 | - } |
|
336 | - return $result; |
|
337 | - } |
|
338 | - |
|
339 | - private function doSoftValidation() { |
|
340 | - //if User or Group Base are not set, take over Base DN setting |
|
341 | - foreach(array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) { |
|
342 | - $val = $this->configuration->$keyBase; |
|
343 | - if(empty($val)) { |
|
344 | - $this->configuration->$keyBase = $this->configuration->ldapBase; |
|
345 | - } |
|
346 | - } |
|
347 | - |
|
348 | - foreach(array('ldapExpertUUIDUserAttr' => 'ldapUuidUserAttribute', |
|
349 | - 'ldapExpertUUIDGroupAttr' => 'ldapUuidGroupAttribute') |
|
350 | - as $expertSetting => $effectiveSetting) { |
|
351 | - $uuidOverride = $this->configuration->$expertSetting; |
|
352 | - if(!empty($uuidOverride)) { |
|
353 | - $this->configuration->$effectiveSetting = $uuidOverride; |
|
354 | - } else { |
|
355 | - $uuidAttributes = Access::UUID_ATTRIBUTES; |
|
356 | - array_unshift($uuidAttributes, 'auto'); |
|
357 | - if(!in_array($this->configuration->$effectiveSetting, |
|
358 | - $uuidAttributes) |
|
359 | - && (!is_null($this->configID))) { |
|
360 | - $this->configuration->$effectiveSetting = 'auto'; |
|
361 | - $this->configuration->saveConfiguration(); |
|
362 | - \OCP\Util::writeLog('user_ldap', |
|
363 | - 'Illegal value for the '. |
|
364 | - $effectiveSetting.', '.'reset to '. |
|
365 | - 'autodetect.', \OCP\Util::INFO); |
|
366 | - } |
|
367 | - |
|
368 | - } |
|
369 | - } |
|
370 | - |
|
371 | - $backupPort = intval($this->configuration->ldapBackupPort); |
|
372 | - if ($backupPort <= 0) { |
|
373 | - $this->configuration->backupPort = $this->configuration->ldapPort; |
|
374 | - } |
|
375 | - |
|
376 | - //make sure empty search attributes are saved as simple, empty array |
|
377 | - $saKeys = array('ldapAttributesForUserSearch', |
|
378 | - 'ldapAttributesForGroupSearch'); |
|
379 | - foreach($saKeys as $key) { |
|
380 | - $val = $this->configuration->$key; |
|
381 | - if(is_array($val) && count($val) === 1 && empty($val[0])) { |
|
382 | - $this->configuration->$key = array(); |
|
383 | - } |
|
384 | - } |
|
385 | - |
|
386 | - if((stripos($this->configuration->ldapHost, 'ldaps://') === 0) |
|
387 | - && $this->configuration->ldapTLS) { |
|
388 | - $this->configuration->ldapTLS = false; |
|
389 | - \OCP\Util::writeLog('user_ldap', |
|
390 | - 'LDAPS (already using secure connection) and '. |
|
391 | - 'TLS do not work together. Switched off TLS.', |
|
392 | - \OCP\Util::INFO); |
|
393 | - } |
|
394 | - } |
|
395 | - |
|
396 | - /** |
|
397 | - * @return bool |
|
398 | - */ |
|
399 | - private function doCriticalValidation() { |
|
400 | - $configurationOK = true; |
|
401 | - $errorStr = 'Configuration Error (prefix '. |
|
402 | - strval($this->configPrefix).'): '; |
|
403 | - |
|
404 | - //options that shall not be empty |
|
405 | - $options = array('ldapHost', 'ldapPort', 'ldapUserDisplayName', |
|
406 | - 'ldapGroupDisplayName', 'ldapLoginFilter'); |
|
407 | - foreach($options as $key) { |
|
408 | - $val = $this->configuration->$key; |
|
409 | - if(empty($val)) { |
|
410 | - switch($key) { |
|
411 | - case 'ldapHost': |
|
412 | - $subj = 'LDAP Host'; |
|
413 | - break; |
|
414 | - case 'ldapPort': |
|
415 | - $subj = 'LDAP Port'; |
|
416 | - break; |
|
417 | - case 'ldapUserDisplayName': |
|
418 | - $subj = 'LDAP User Display Name'; |
|
419 | - break; |
|
420 | - case 'ldapGroupDisplayName': |
|
421 | - $subj = 'LDAP Group Display Name'; |
|
422 | - break; |
|
423 | - case 'ldapLoginFilter': |
|
424 | - $subj = 'LDAP Login Filter'; |
|
425 | - break; |
|
426 | - default: |
|
427 | - $subj = $key; |
|
428 | - break; |
|
429 | - } |
|
430 | - $configurationOK = false; |
|
431 | - \OCP\Util::writeLog('user_ldap', |
|
432 | - $errorStr.'No '.$subj.' given!', |
|
433 | - \OCP\Util::WARN); |
|
434 | - } |
|
435 | - } |
|
436 | - |
|
437 | - //combinations |
|
438 | - $agent = $this->configuration->ldapAgentName; |
|
439 | - $pwd = $this->configuration->ldapAgentPassword; |
|
440 | - if ( |
|
441 | - ($agent === '' && $pwd !== '') |
|
442 | - || ($agent !== '' && $pwd === '') |
|
443 | - ) { |
|
444 | - \OCP\Util::writeLog('user_ldap', |
|
445 | - $errorStr.'either no password is given for the '. |
|
446 | - 'user agent or a password is given, but not an '. |
|
447 | - 'LDAP agent.', |
|
448 | - \OCP\Util::WARN); |
|
449 | - $configurationOK = false; |
|
450 | - } |
|
451 | - |
|
452 | - $base = $this->configuration->ldapBase; |
|
453 | - $baseUsers = $this->configuration->ldapBaseUsers; |
|
454 | - $baseGroups = $this->configuration->ldapBaseGroups; |
|
455 | - |
|
456 | - if(empty($base) && empty($baseUsers) && empty($baseGroups)) { |
|
457 | - \OCP\Util::writeLog('user_ldap', |
|
458 | - $errorStr.'Not a single Base DN given.', |
|
459 | - \OCP\Util::WARN); |
|
460 | - $configurationOK = false; |
|
461 | - } |
|
462 | - |
|
463 | - if(mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
464 | - === false) { |
|
465 | - \OCP\Util::writeLog('user_ldap', |
|
466 | - $errorStr.'login filter does not contain %uid '. |
|
467 | - 'place holder.', |
|
468 | - \OCP\Util::WARN); |
|
469 | - $configurationOK = false; |
|
470 | - } |
|
471 | - |
|
472 | - return $configurationOK; |
|
473 | - } |
|
474 | - |
|
475 | - /** |
|
476 | - * Validates the user specified configuration |
|
477 | - * @return bool true if configuration seems OK, false otherwise |
|
478 | - */ |
|
479 | - private function validateConfiguration() { |
|
480 | - |
|
481 | - if($this->doNotValidate) { |
|
482 | - //don't do a validation if it is a new configuration with pure |
|
483 | - //default values. Will be allowed on changes via __set or |
|
484 | - //setConfiguration |
|
485 | - return false; |
|
486 | - } |
|
487 | - |
|
488 | - // first step: "soft" checks: settings that are not really |
|
489 | - // necessary, but advisable. If left empty, give an info message |
|
490 | - $this->doSoftValidation(); |
|
491 | - |
|
492 | - //second step: critical checks. If left empty or filled wrong, mark as |
|
493 | - //not configured and give a warning. |
|
494 | - return $this->doCriticalValidation(); |
|
495 | - } |
|
496 | - |
|
497 | - |
|
498 | - /** |
|
499 | - * Connects and Binds to LDAP |
|
500 | - */ |
|
501 | - private function establishConnection() { |
|
502 | - if(!$this->configuration->ldapConfigurationActive) { |
|
503 | - return null; |
|
504 | - } |
|
505 | - static $phpLDAPinstalled = true; |
|
506 | - if(!$phpLDAPinstalled) { |
|
507 | - return false; |
|
508 | - } |
|
509 | - if(!$this->ignoreValidation && !$this->configured) { |
|
510 | - \OCP\Util::writeLog('user_ldap', |
|
511 | - 'Configuration is invalid, cannot connect', |
|
512 | - \OCP\Util::WARN); |
|
513 | - return false; |
|
514 | - } |
|
515 | - if(!$this->ldapConnectionRes) { |
|
516 | - if(!$this->ldap->areLDAPFunctionsAvailable()) { |
|
517 | - $phpLDAPinstalled = false; |
|
518 | - \OCP\Util::writeLog('user_ldap', |
|
519 | - 'function ldap_connect is not available. Make '. |
|
520 | - 'sure that the PHP ldap module is installed.', |
|
521 | - \OCP\Util::ERROR); |
|
522 | - |
|
523 | - return false; |
|
524 | - } |
|
525 | - if($this->configuration->turnOffCertCheck) { |
|
526 | - if(putenv('LDAPTLS_REQCERT=never')) { |
|
527 | - \OCP\Util::writeLog('user_ldap', |
|
528 | - 'Turned off SSL certificate validation successfully.', |
|
529 | - \OCP\Util::DEBUG); |
|
530 | - } else { |
|
531 | - \OCP\Util::writeLog('user_ldap', |
|
532 | - 'Could not turn off SSL certificate validation.', |
|
533 | - \OCP\Util::WARN); |
|
534 | - } |
|
535 | - } |
|
536 | - |
|
537 | - $isOverrideMainServer = ($this->configuration->ldapOverrideMainServer |
|
538 | - || $this->getFromCache('overrideMainServer')); |
|
539 | - $isBackupHost = (trim($this->configuration->ldapBackupHost) !== ""); |
|
540 | - $bindStatus = false; |
|
541 | - $error = -1; |
|
542 | - try { |
|
543 | - if (!$isOverrideMainServer) { |
|
544 | - $this->doConnect($this->configuration->ldapHost, |
|
545 | - $this->configuration->ldapPort); |
|
546 | - $bindStatus = $this->bind(); |
|
547 | - $error = $this->ldap->isResource($this->ldapConnectionRes) ? |
|
548 | - $this->ldap->errno($this->ldapConnectionRes) : -1; |
|
549 | - } |
|
550 | - if($bindStatus === true) { |
|
551 | - return $bindStatus; |
|
552 | - } |
|
553 | - } catch (ServerNotAvailableException $e) { |
|
554 | - if(!$isBackupHost) { |
|
555 | - throw $e; |
|
556 | - } |
|
557 | - } |
|
558 | - |
|
559 | - //if LDAP server is not reachable, try the Backup (Replica!) Server |
|
560 | - if($isBackupHost && ($error !== 0 || $isOverrideMainServer)) { |
|
561 | - $this->doConnect($this->configuration->ldapBackupHost, |
|
562 | - $this->configuration->ldapBackupPort); |
|
563 | - $bindStatus = $this->bind(); |
|
564 | - $error = $this->ldap->isResource($this->ldapConnectionRes) ? |
|
565 | - $this->ldap->errno($this->ldapConnectionRes) : -1; |
|
566 | - if($bindStatus && $error === 0 && !$this->getFromCache('overrideMainServer')) { |
|
567 | - //when bind to backup server succeeded and failed to main server, |
|
568 | - //skip contacting him until next cache refresh |
|
569 | - $this->writeToCache('overrideMainServer', true); |
|
570 | - } |
|
571 | - } |
|
572 | - |
|
573 | - return $bindStatus; |
|
574 | - } |
|
575 | - return null; |
|
576 | - } |
|
577 | - |
|
578 | - /** |
|
579 | - * @param string $host |
|
580 | - * @param string $port |
|
581 | - * @return bool |
|
582 | - * @throws \OC\ServerNotAvailableException |
|
583 | - */ |
|
584 | - private function doConnect($host, $port) { |
|
585 | - if ($host === '') { |
|
586 | - return false; |
|
587 | - } |
|
588 | - |
|
589 | - $this->ldapConnectionRes = $this->ldap->connect($host, $port); |
|
590 | - |
|
591 | - if(!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) { |
|
592 | - throw new ServerNotAvailableException('Could not set required LDAP Protocol version.'); |
|
593 | - } |
|
594 | - |
|
595 | - if(!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) { |
|
596 | - throw new ServerNotAvailableException('Could not disable LDAP referrals.'); |
|
597 | - } |
|
598 | - |
|
599 | - if($this->configuration->ldapTLS) { |
|
600 | - if(!$this->ldap->startTls($this->ldapConnectionRes)) { |
|
601 | - throw new ServerNotAvailableException('Start TLS failed, when connecting to LDAP host ' . $host . '.'); |
|
602 | - } |
|
603 | - } |
|
604 | - |
|
605 | - return true; |
|
606 | - } |
|
607 | - |
|
608 | - /** |
|
609 | - * Binds to LDAP |
|
610 | - */ |
|
611 | - public function bind() { |
|
612 | - if(!$this->configuration->ldapConfigurationActive) { |
|
613 | - return false; |
|
614 | - } |
|
615 | - $cr = $this->getConnectionResource(); |
|
616 | - if(!$this->ldap->isResource($cr)) { |
|
617 | - return false; |
|
618 | - } |
|
619 | - $ldapLogin = @$this->ldap->bind($cr, |
|
620 | - $this->configuration->ldapAgentName, |
|
621 | - $this->configuration->ldapAgentPassword); |
|
622 | - if(!$ldapLogin) { |
|
623 | - $errno = $this->ldap->errno($cr); |
|
624 | - |
|
625 | - \OCP\Util::writeLog('user_ldap', |
|
626 | - 'Bind failed: ' . $errno . ': ' . $this->ldap->error($cr), |
|
627 | - \OCP\Util::WARN); |
|
628 | - |
|
629 | - // Set to failure mode, if LDAP error code is not LDAP_SUCCESS or LDAP_INVALID_CREDENTIALS |
|
630 | - if($errno !== 0x00 && $errno !== 0x31) { |
|
631 | - $this->ldapConnectionRes = null; |
|
632 | - } |
|
633 | - |
|
634 | - return false; |
|
635 | - } |
|
636 | - return true; |
|
637 | - } |
|
61 | + private $ldapConnectionRes = null; |
|
62 | + private $configPrefix; |
|
63 | + private $configID; |
|
64 | + private $configured = false; |
|
65 | + private $hasPagedResultSupport = true; |
|
66 | + //whether connection should be kept on __destruct |
|
67 | + private $dontDestruct = false; |
|
68 | + |
|
69 | + /** |
|
70 | + * @var bool runtime flag that indicates whether supported primary groups are available |
|
71 | + */ |
|
72 | + public $hasPrimaryGroups = true; |
|
73 | + |
|
74 | + /** |
|
75 | + * @var bool runtime flag that indicates whether supported POSIX gidNumber are available |
|
76 | + */ |
|
77 | + public $hasGidNumber = true; |
|
78 | + |
|
79 | + //cache handler |
|
80 | + protected $cache; |
|
81 | + |
|
82 | + /** @var Configuration settings handler **/ |
|
83 | + protected $configuration; |
|
84 | + |
|
85 | + protected $doNotValidate = false; |
|
86 | + |
|
87 | + protected $ignoreValidation = false; |
|
88 | + |
|
89 | + /** |
|
90 | + * Constructor |
|
91 | + * @param ILDAPWrapper $ldap |
|
92 | + * @param string $configPrefix a string with the prefix for the configkey column (appconfig table) |
|
93 | + * @param string|null $configID a string with the value for the appid column (appconfig table) or null for on-the-fly connections |
|
94 | + */ |
|
95 | + public function __construct(ILDAPWrapper $ldap, $configPrefix = '', $configID = 'user_ldap') { |
|
96 | + parent::__construct($ldap); |
|
97 | + $this->configPrefix = $configPrefix; |
|
98 | + $this->configID = $configID; |
|
99 | + $this->configuration = new Configuration($configPrefix, |
|
100 | + !is_null($configID)); |
|
101 | + $memcache = \OC::$server->getMemCacheFactory(); |
|
102 | + if($memcache->isAvailable()) { |
|
103 | + $this->cache = $memcache->create(); |
|
104 | + } |
|
105 | + $helper = new Helper(\OC::$server->getConfig()); |
|
106 | + $this->doNotValidate = !in_array($this->configPrefix, |
|
107 | + $helper->getServerConfigurationPrefixes()); |
|
108 | + $this->hasPagedResultSupport = |
|
109 | + intval($this->configuration->ldapPagingSize) !== 0 |
|
110 | + || $this->ldap->hasPagedResultSupport(); |
|
111 | + } |
|
112 | + |
|
113 | + public function __destruct() { |
|
114 | + if(!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) { |
|
115 | + @$this->ldap->unbind($this->ldapConnectionRes); |
|
116 | + }; |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * defines behaviour when the instance is cloned |
|
121 | + */ |
|
122 | + public function __clone() { |
|
123 | + $this->configuration = new Configuration($this->configPrefix, |
|
124 | + !is_null($this->configID)); |
|
125 | + $this->ldapConnectionRes = null; |
|
126 | + $this->dontDestruct = true; |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * @param string $name |
|
131 | + * @return bool|mixed |
|
132 | + */ |
|
133 | + public function __get($name) { |
|
134 | + if(!$this->configured) { |
|
135 | + $this->readConfiguration(); |
|
136 | + } |
|
137 | + |
|
138 | + if($name === 'hasPagedResultSupport') { |
|
139 | + return $this->hasPagedResultSupport; |
|
140 | + } |
|
141 | + |
|
142 | + return $this->configuration->$name; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * @param string $name |
|
147 | + * @param mixed $value |
|
148 | + */ |
|
149 | + public function __set($name, $value) { |
|
150 | + $this->doNotValidate = false; |
|
151 | + $before = $this->configuration->$name; |
|
152 | + $this->configuration->$name = $value; |
|
153 | + $after = $this->configuration->$name; |
|
154 | + if($before !== $after) { |
|
155 | + if ($this->configID !== '' && $this->configID !== null) { |
|
156 | + $this->configuration->saveConfiguration(); |
|
157 | + } |
|
158 | + $this->validateConfiguration(); |
|
159 | + } |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * sets whether the result of the configuration validation shall |
|
164 | + * be ignored when establishing the connection. Used by the Wizard |
|
165 | + * in early configuration state. |
|
166 | + * @param bool $state |
|
167 | + */ |
|
168 | + public function setIgnoreValidation($state) { |
|
169 | + $this->ignoreValidation = (bool)$state; |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * initializes the LDAP backend |
|
174 | + * @param bool $force read the config settings no matter what |
|
175 | + */ |
|
176 | + public function init($force = false) { |
|
177 | + $this->readConfiguration($force); |
|
178 | + $this->establishConnection(); |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Returns the LDAP handler |
|
183 | + */ |
|
184 | + public function getConnectionResource() { |
|
185 | + if(!$this->ldapConnectionRes) { |
|
186 | + $this->init(); |
|
187 | + } else if(!$this->ldap->isResource($this->ldapConnectionRes)) { |
|
188 | + $this->ldapConnectionRes = null; |
|
189 | + $this->establishConnection(); |
|
190 | + } |
|
191 | + if(is_null($this->ldapConnectionRes)) { |
|
192 | + \OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server ' . $this->configuration->ldapHost, \OCP\Util::ERROR); |
|
193 | + throw new ServerNotAvailableException('Connection to LDAP server could not be established'); |
|
194 | + } |
|
195 | + return $this->ldapConnectionRes; |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * resets the connection resource |
|
200 | + */ |
|
201 | + public function resetConnectionResource() { |
|
202 | + if(!is_null($this->ldapConnectionRes)) { |
|
203 | + @$this->ldap->unbind($this->ldapConnectionRes); |
|
204 | + $this->ldapConnectionRes = null; |
|
205 | + } |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * @param string|null $key |
|
210 | + * @return string |
|
211 | + */ |
|
212 | + private function getCacheKey($key) { |
|
213 | + $prefix = 'LDAP-'.$this->configID.'-'.$this->configPrefix.'-'; |
|
214 | + if(is_null($key)) { |
|
215 | + return $prefix; |
|
216 | + } |
|
217 | + return $prefix.md5($key); |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * @param string $key |
|
222 | + * @return mixed|null |
|
223 | + */ |
|
224 | + public function getFromCache($key) { |
|
225 | + if(!$this->configured) { |
|
226 | + $this->readConfiguration(); |
|
227 | + } |
|
228 | + if(is_null($this->cache) || !$this->configuration->ldapCacheTTL) { |
|
229 | + return null; |
|
230 | + } |
|
231 | + $key = $this->getCacheKey($key); |
|
232 | + |
|
233 | + return json_decode(base64_decode($this->cache->get($key)), true); |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * @param string $key |
|
238 | + * @param mixed $value |
|
239 | + * |
|
240 | + * @return string |
|
241 | + */ |
|
242 | + public function writeToCache($key, $value) { |
|
243 | + if(!$this->configured) { |
|
244 | + $this->readConfiguration(); |
|
245 | + } |
|
246 | + if(is_null($this->cache) |
|
247 | + || !$this->configuration->ldapCacheTTL |
|
248 | + || !$this->configuration->ldapConfigurationActive) { |
|
249 | + return null; |
|
250 | + } |
|
251 | + $key = $this->getCacheKey($key); |
|
252 | + $value = base64_encode(json_encode($value)); |
|
253 | + $this->cache->set($key, $value, $this->configuration->ldapCacheTTL); |
|
254 | + } |
|
255 | + |
|
256 | + public function clearCache() { |
|
257 | + if(!is_null($this->cache)) { |
|
258 | + $this->cache->clear($this->getCacheKey(null)); |
|
259 | + } |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Caches the general LDAP configuration. |
|
264 | + * @param bool $force optional. true, if the re-read should be forced. defaults |
|
265 | + * to false. |
|
266 | + * @return null |
|
267 | + */ |
|
268 | + private function readConfiguration($force = false) { |
|
269 | + if((!$this->configured || $force) && !is_null($this->configID)) { |
|
270 | + $this->configuration->readConfiguration(); |
|
271 | + $this->configured = $this->validateConfiguration(); |
|
272 | + } |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * set LDAP configuration with values delivered by an array, not read from configuration |
|
277 | + * @param array $config array that holds the config parameters in an associated array |
|
278 | + * @param array &$setParameters optional; array where the set fields will be given to |
|
279 | + * @return boolean true if config validates, false otherwise. Check with $setParameters for detailed success on single parameters |
|
280 | + */ |
|
281 | + public function setConfiguration($config, &$setParameters = null) { |
|
282 | + if(is_null($setParameters)) { |
|
283 | + $setParameters = array(); |
|
284 | + } |
|
285 | + $this->doNotValidate = false; |
|
286 | + $this->configuration->setConfiguration($config, $setParameters); |
|
287 | + if(count($setParameters) > 0) { |
|
288 | + $this->configured = $this->validateConfiguration(); |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + return $this->configured; |
|
293 | + } |
|
294 | + |
|
295 | + /** |
|
296 | + * saves the current Configuration in the database and empties the |
|
297 | + * cache |
|
298 | + * @return null |
|
299 | + */ |
|
300 | + public function saveConfiguration() { |
|
301 | + $this->configuration->saveConfiguration(); |
|
302 | + $this->clearCache(); |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * get the current LDAP configuration |
|
307 | + * @return array |
|
308 | + */ |
|
309 | + public function getConfiguration() { |
|
310 | + $this->readConfiguration(); |
|
311 | + $config = $this->configuration->getConfiguration(); |
|
312 | + $cta = $this->configuration->getConfigTranslationArray(); |
|
313 | + $result = array(); |
|
314 | + foreach($cta as $dbkey => $configkey) { |
|
315 | + switch($configkey) { |
|
316 | + case 'homeFolderNamingRule': |
|
317 | + if(strpos($config[$configkey], 'attr:') === 0) { |
|
318 | + $result[$dbkey] = substr($config[$configkey], 5); |
|
319 | + } else { |
|
320 | + $result[$dbkey] = ''; |
|
321 | + } |
|
322 | + break; |
|
323 | + case 'ldapBase': |
|
324 | + case 'ldapBaseUsers': |
|
325 | + case 'ldapBaseGroups': |
|
326 | + case 'ldapAttributesForUserSearch': |
|
327 | + case 'ldapAttributesForGroupSearch': |
|
328 | + if(is_array($config[$configkey])) { |
|
329 | + $result[$dbkey] = implode("\n", $config[$configkey]); |
|
330 | + break; |
|
331 | + } //else follows default |
|
332 | + default: |
|
333 | + $result[$dbkey] = $config[$configkey]; |
|
334 | + } |
|
335 | + } |
|
336 | + return $result; |
|
337 | + } |
|
338 | + |
|
339 | + private function doSoftValidation() { |
|
340 | + //if User or Group Base are not set, take over Base DN setting |
|
341 | + foreach(array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) { |
|
342 | + $val = $this->configuration->$keyBase; |
|
343 | + if(empty($val)) { |
|
344 | + $this->configuration->$keyBase = $this->configuration->ldapBase; |
|
345 | + } |
|
346 | + } |
|
347 | + |
|
348 | + foreach(array('ldapExpertUUIDUserAttr' => 'ldapUuidUserAttribute', |
|
349 | + 'ldapExpertUUIDGroupAttr' => 'ldapUuidGroupAttribute') |
|
350 | + as $expertSetting => $effectiveSetting) { |
|
351 | + $uuidOverride = $this->configuration->$expertSetting; |
|
352 | + if(!empty($uuidOverride)) { |
|
353 | + $this->configuration->$effectiveSetting = $uuidOverride; |
|
354 | + } else { |
|
355 | + $uuidAttributes = Access::UUID_ATTRIBUTES; |
|
356 | + array_unshift($uuidAttributes, 'auto'); |
|
357 | + if(!in_array($this->configuration->$effectiveSetting, |
|
358 | + $uuidAttributes) |
|
359 | + && (!is_null($this->configID))) { |
|
360 | + $this->configuration->$effectiveSetting = 'auto'; |
|
361 | + $this->configuration->saveConfiguration(); |
|
362 | + \OCP\Util::writeLog('user_ldap', |
|
363 | + 'Illegal value for the '. |
|
364 | + $effectiveSetting.', '.'reset to '. |
|
365 | + 'autodetect.', \OCP\Util::INFO); |
|
366 | + } |
|
367 | + |
|
368 | + } |
|
369 | + } |
|
370 | + |
|
371 | + $backupPort = intval($this->configuration->ldapBackupPort); |
|
372 | + if ($backupPort <= 0) { |
|
373 | + $this->configuration->backupPort = $this->configuration->ldapPort; |
|
374 | + } |
|
375 | + |
|
376 | + //make sure empty search attributes are saved as simple, empty array |
|
377 | + $saKeys = array('ldapAttributesForUserSearch', |
|
378 | + 'ldapAttributesForGroupSearch'); |
|
379 | + foreach($saKeys as $key) { |
|
380 | + $val = $this->configuration->$key; |
|
381 | + if(is_array($val) && count($val) === 1 && empty($val[0])) { |
|
382 | + $this->configuration->$key = array(); |
|
383 | + } |
|
384 | + } |
|
385 | + |
|
386 | + if((stripos($this->configuration->ldapHost, 'ldaps://') === 0) |
|
387 | + && $this->configuration->ldapTLS) { |
|
388 | + $this->configuration->ldapTLS = false; |
|
389 | + \OCP\Util::writeLog('user_ldap', |
|
390 | + 'LDAPS (already using secure connection) and '. |
|
391 | + 'TLS do not work together. Switched off TLS.', |
|
392 | + \OCP\Util::INFO); |
|
393 | + } |
|
394 | + } |
|
395 | + |
|
396 | + /** |
|
397 | + * @return bool |
|
398 | + */ |
|
399 | + private function doCriticalValidation() { |
|
400 | + $configurationOK = true; |
|
401 | + $errorStr = 'Configuration Error (prefix '. |
|
402 | + strval($this->configPrefix).'): '; |
|
403 | + |
|
404 | + //options that shall not be empty |
|
405 | + $options = array('ldapHost', 'ldapPort', 'ldapUserDisplayName', |
|
406 | + 'ldapGroupDisplayName', 'ldapLoginFilter'); |
|
407 | + foreach($options as $key) { |
|
408 | + $val = $this->configuration->$key; |
|
409 | + if(empty($val)) { |
|
410 | + switch($key) { |
|
411 | + case 'ldapHost': |
|
412 | + $subj = 'LDAP Host'; |
|
413 | + break; |
|
414 | + case 'ldapPort': |
|
415 | + $subj = 'LDAP Port'; |
|
416 | + break; |
|
417 | + case 'ldapUserDisplayName': |
|
418 | + $subj = 'LDAP User Display Name'; |
|
419 | + break; |
|
420 | + case 'ldapGroupDisplayName': |
|
421 | + $subj = 'LDAP Group Display Name'; |
|
422 | + break; |
|
423 | + case 'ldapLoginFilter': |
|
424 | + $subj = 'LDAP Login Filter'; |
|
425 | + break; |
|
426 | + default: |
|
427 | + $subj = $key; |
|
428 | + break; |
|
429 | + } |
|
430 | + $configurationOK = false; |
|
431 | + \OCP\Util::writeLog('user_ldap', |
|
432 | + $errorStr.'No '.$subj.' given!', |
|
433 | + \OCP\Util::WARN); |
|
434 | + } |
|
435 | + } |
|
436 | + |
|
437 | + //combinations |
|
438 | + $agent = $this->configuration->ldapAgentName; |
|
439 | + $pwd = $this->configuration->ldapAgentPassword; |
|
440 | + if ( |
|
441 | + ($agent === '' && $pwd !== '') |
|
442 | + || ($agent !== '' && $pwd === '') |
|
443 | + ) { |
|
444 | + \OCP\Util::writeLog('user_ldap', |
|
445 | + $errorStr.'either no password is given for the '. |
|
446 | + 'user agent or a password is given, but not an '. |
|
447 | + 'LDAP agent.', |
|
448 | + \OCP\Util::WARN); |
|
449 | + $configurationOK = false; |
|
450 | + } |
|
451 | + |
|
452 | + $base = $this->configuration->ldapBase; |
|
453 | + $baseUsers = $this->configuration->ldapBaseUsers; |
|
454 | + $baseGroups = $this->configuration->ldapBaseGroups; |
|
455 | + |
|
456 | + if(empty($base) && empty($baseUsers) && empty($baseGroups)) { |
|
457 | + \OCP\Util::writeLog('user_ldap', |
|
458 | + $errorStr.'Not a single Base DN given.', |
|
459 | + \OCP\Util::WARN); |
|
460 | + $configurationOK = false; |
|
461 | + } |
|
462 | + |
|
463 | + if(mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
464 | + === false) { |
|
465 | + \OCP\Util::writeLog('user_ldap', |
|
466 | + $errorStr.'login filter does not contain %uid '. |
|
467 | + 'place holder.', |
|
468 | + \OCP\Util::WARN); |
|
469 | + $configurationOK = false; |
|
470 | + } |
|
471 | + |
|
472 | + return $configurationOK; |
|
473 | + } |
|
474 | + |
|
475 | + /** |
|
476 | + * Validates the user specified configuration |
|
477 | + * @return bool true if configuration seems OK, false otherwise |
|
478 | + */ |
|
479 | + private function validateConfiguration() { |
|
480 | + |
|
481 | + if($this->doNotValidate) { |
|
482 | + //don't do a validation if it is a new configuration with pure |
|
483 | + //default values. Will be allowed on changes via __set or |
|
484 | + //setConfiguration |
|
485 | + return false; |
|
486 | + } |
|
487 | + |
|
488 | + // first step: "soft" checks: settings that are not really |
|
489 | + // necessary, but advisable. If left empty, give an info message |
|
490 | + $this->doSoftValidation(); |
|
491 | + |
|
492 | + //second step: critical checks. If left empty or filled wrong, mark as |
|
493 | + //not configured and give a warning. |
|
494 | + return $this->doCriticalValidation(); |
|
495 | + } |
|
496 | + |
|
497 | + |
|
498 | + /** |
|
499 | + * Connects and Binds to LDAP |
|
500 | + */ |
|
501 | + private function establishConnection() { |
|
502 | + if(!$this->configuration->ldapConfigurationActive) { |
|
503 | + return null; |
|
504 | + } |
|
505 | + static $phpLDAPinstalled = true; |
|
506 | + if(!$phpLDAPinstalled) { |
|
507 | + return false; |
|
508 | + } |
|
509 | + if(!$this->ignoreValidation && !$this->configured) { |
|
510 | + \OCP\Util::writeLog('user_ldap', |
|
511 | + 'Configuration is invalid, cannot connect', |
|
512 | + \OCP\Util::WARN); |
|
513 | + return false; |
|
514 | + } |
|
515 | + if(!$this->ldapConnectionRes) { |
|
516 | + if(!$this->ldap->areLDAPFunctionsAvailable()) { |
|
517 | + $phpLDAPinstalled = false; |
|
518 | + \OCP\Util::writeLog('user_ldap', |
|
519 | + 'function ldap_connect is not available. Make '. |
|
520 | + 'sure that the PHP ldap module is installed.', |
|
521 | + \OCP\Util::ERROR); |
|
522 | + |
|
523 | + return false; |
|
524 | + } |
|
525 | + if($this->configuration->turnOffCertCheck) { |
|
526 | + if(putenv('LDAPTLS_REQCERT=never')) { |
|
527 | + \OCP\Util::writeLog('user_ldap', |
|
528 | + 'Turned off SSL certificate validation successfully.', |
|
529 | + \OCP\Util::DEBUG); |
|
530 | + } else { |
|
531 | + \OCP\Util::writeLog('user_ldap', |
|
532 | + 'Could not turn off SSL certificate validation.', |
|
533 | + \OCP\Util::WARN); |
|
534 | + } |
|
535 | + } |
|
536 | + |
|
537 | + $isOverrideMainServer = ($this->configuration->ldapOverrideMainServer |
|
538 | + || $this->getFromCache('overrideMainServer')); |
|
539 | + $isBackupHost = (trim($this->configuration->ldapBackupHost) !== ""); |
|
540 | + $bindStatus = false; |
|
541 | + $error = -1; |
|
542 | + try { |
|
543 | + if (!$isOverrideMainServer) { |
|
544 | + $this->doConnect($this->configuration->ldapHost, |
|
545 | + $this->configuration->ldapPort); |
|
546 | + $bindStatus = $this->bind(); |
|
547 | + $error = $this->ldap->isResource($this->ldapConnectionRes) ? |
|
548 | + $this->ldap->errno($this->ldapConnectionRes) : -1; |
|
549 | + } |
|
550 | + if($bindStatus === true) { |
|
551 | + return $bindStatus; |
|
552 | + } |
|
553 | + } catch (ServerNotAvailableException $e) { |
|
554 | + if(!$isBackupHost) { |
|
555 | + throw $e; |
|
556 | + } |
|
557 | + } |
|
558 | + |
|
559 | + //if LDAP server is not reachable, try the Backup (Replica!) Server |
|
560 | + if($isBackupHost && ($error !== 0 || $isOverrideMainServer)) { |
|
561 | + $this->doConnect($this->configuration->ldapBackupHost, |
|
562 | + $this->configuration->ldapBackupPort); |
|
563 | + $bindStatus = $this->bind(); |
|
564 | + $error = $this->ldap->isResource($this->ldapConnectionRes) ? |
|
565 | + $this->ldap->errno($this->ldapConnectionRes) : -1; |
|
566 | + if($bindStatus && $error === 0 && !$this->getFromCache('overrideMainServer')) { |
|
567 | + //when bind to backup server succeeded and failed to main server, |
|
568 | + //skip contacting him until next cache refresh |
|
569 | + $this->writeToCache('overrideMainServer', true); |
|
570 | + } |
|
571 | + } |
|
572 | + |
|
573 | + return $bindStatus; |
|
574 | + } |
|
575 | + return null; |
|
576 | + } |
|
577 | + |
|
578 | + /** |
|
579 | + * @param string $host |
|
580 | + * @param string $port |
|
581 | + * @return bool |
|
582 | + * @throws \OC\ServerNotAvailableException |
|
583 | + */ |
|
584 | + private function doConnect($host, $port) { |
|
585 | + if ($host === '') { |
|
586 | + return false; |
|
587 | + } |
|
588 | + |
|
589 | + $this->ldapConnectionRes = $this->ldap->connect($host, $port); |
|
590 | + |
|
591 | + if(!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) { |
|
592 | + throw new ServerNotAvailableException('Could not set required LDAP Protocol version.'); |
|
593 | + } |
|
594 | + |
|
595 | + if(!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) { |
|
596 | + throw new ServerNotAvailableException('Could not disable LDAP referrals.'); |
|
597 | + } |
|
598 | + |
|
599 | + if($this->configuration->ldapTLS) { |
|
600 | + if(!$this->ldap->startTls($this->ldapConnectionRes)) { |
|
601 | + throw new ServerNotAvailableException('Start TLS failed, when connecting to LDAP host ' . $host . '.'); |
|
602 | + } |
|
603 | + } |
|
604 | + |
|
605 | + return true; |
|
606 | + } |
|
607 | + |
|
608 | + /** |
|
609 | + * Binds to LDAP |
|
610 | + */ |
|
611 | + public function bind() { |
|
612 | + if(!$this->configuration->ldapConfigurationActive) { |
|
613 | + return false; |
|
614 | + } |
|
615 | + $cr = $this->getConnectionResource(); |
|
616 | + if(!$this->ldap->isResource($cr)) { |
|
617 | + return false; |
|
618 | + } |
|
619 | + $ldapLogin = @$this->ldap->bind($cr, |
|
620 | + $this->configuration->ldapAgentName, |
|
621 | + $this->configuration->ldapAgentPassword); |
|
622 | + if(!$ldapLogin) { |
|
623 | + $errno = $this->ldap->errno($cr); |
|
624 | + |
|
625 | + \OCP\Util::writeLog('user_ldap', |
|
626 | + 'Bind failed: ' . $errno . ': ' . $this->ldap->error($cr), |
|
627 | + \OCP\Util::WARN); |
|
628 | + |
|
629 | + // Set to failure mode, if LDAP error code is not LDAP_SUCCESS or LDAP_INVALID_CREDENTIALS |
|
630 | + if($errno !== 0x00 && $errno !== 0x31) { |
|
631 | + $this->ldapConnectionRes = null; |
|
632 | + } |
|
633 | + |
|
634 | + return false; |
|
635 | + } |
|
636 | + return true; |
|
637 | + } |
|
638 | 638 | |
639 | 639 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | $this->configuration = new Configuration($configPrefix, |
100 | 100 | !is_null($configID)); |
101 | 101 | $memcache = \OC::$server->getMemCacheFactory(); |
102 | - if($memcache->isAvailable()) { |
|
102 | + if ($memcache->isAvailable()) { |
|
103 | 103 | $this->cache = $memcache->create(); |
104 | 104 | } |
105 | 105 | $helper = new Helper(\OC::$server->getConfig()); |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | } |
112 | 112 | |
113 | 113 | public function __destruct() { |
114 | - if(!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) { |
|
114 | + if (!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) { |
|
115 | 115 | @$this->ldap->unbind($this->ldapConnectionRes); |
116 | 116 | }; |
117 | 117 | } |
@@ -131,11 +131,11 @@ discard block |
||
131 | 131 | * @return bool|mixed |
132 | 132 | */ |
133 | 133 | public function __get($name) { |
134 | - if(!$this->configured) { |
|
134 | + if (!$this->configured) { |
|
135 | 135 | $this->readConfiguration(); |
136 | 136 | } |
137 | 137 | |
138 | - if($name === 'hasPagedResultSupport') { |
|
138 | + if ($name === 'hasPagedResultSupport') { |
|
139 | 139 | return $this->hasPagedResultSupport; |
140 | 140 | } |
141 | 141 | |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | $before = $this->configuration->$name; |
152 | 152 | $this->configuration->$name = $value; |
153 | 153 | $after = $this->configuration->$name; |
154 | - if($before !== $after) { |
|
154 | + if ($before !== $after) { |
|
155 | 155 | if ($this->configID !== '' && $this->configID !== null) { |
156 | 156 | $this->configuration->saveConfiguration(); |
157 | 157 | } |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | * @param bool $state |
167 | 167 | */ |
168 | 168 | public function setIgnoreValidation($state) { |
169 | - $this->ignoreValidation = (bool)$state; |
|
169 | + $this->ignoreValidation = (bool) $state; |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
@@ -182,14 +182,14 @@ discard block |
||
182 | 182 | * Returns the LDAP handler |
183 | 183 | */ |
184 | 184 | public function getConnectionResource() { |
185 | - if(!$this->ldapConnectionRes) { |
|
185 | + if (!$this->ldapConnectionRes) { |
|
186 | 186 | $this->init(); |
187 | - } else if(!$this->ldap->isResource($this->ldapConnectionRes)) { |
|
187 | + } else if (!$this->ldap->isResource($this->ldapConnectionRes)) { |
|
188 | 188 | $this->ldapConnectionRes = null; |
189 | 189 | $this->establishConnection(); |
190 | 190 | } |
191 | - if(is_null($this->ldapConnectionRes)) { |
|
192 | - \OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server ' . $this->configuration->ldapHost, \OCP\Util::ERROR); |
|
191 | + if (is_null($this->ldapConnectionRes)) { |
|
192 | + \OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server '.$this->configuration->ldapHost, \OCP\Util::ERROR); |
|
193 | 193 | throw new ServerNotAvailableException('Connection to LDAP server could not be established'); |
194 | 194 | } |
195 | 195 | return $this->ldapConnectionRes; |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | * resets the connection resource |
200 | 200 | */ |
201 | 201 | public function resetConnectionResource() { |
202 | - if(!is_null($this->ldapConnectionRes)) { |
|
202 | + if (!is_null($this->ldapConnectionRes)) { |
|
203 | 203 | @$this->ldap->unbind($this->ldapConnectionRes); |
204 | 204 | $this->ldapConnectionRes = null; |
205 | 205 | } |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | */ |
212 | 212 | private function getCacheKey($key) { |
213 | 213 | $prefix = 'LDAP-'.$this->configID.'-'.$this->configPrefix.'-'; |
214 | - if(is_null($key)) { |
|
214 | + if (is_null($key)) { |
|
215 | 215 | return $prefix; |
216 | 216 | } |
217 | 217 | return $prefix.md5($key); |
@@ -222,10 +222,10 @@ discard block |
||
222 | 222 | * @return mixed|null |
223 | 223 | */ |
224 | 224 | public function getFromCache($key) { |
225 | - if(!$this->configured) { |
|
225 | + if (!$this->configured) { |
|
226 | 226 | $this->readConfiguration(); |
227 | 227 | } |
228 | - if(is_null($this->cache) || !$this->configuration->ldapCacheTTL) { |
|
228 | + if (is_null($this->cache) || !$this->configuration->ldapCacheTTL) { |
|
229 | 229 | return null; |
230 | 230 | } |
231 | 231 | $key = $this->getCacheKey($key); |
@@ -240,10 +240,10 @@ discard block |
||
240 | 240 | * @return string |
241 | 241 | */ |
242 | 242 | public function writeToCache($key, $value) { |
243 | - if(!$this->configured) { |
|
243 | + if (!$this->configured) { |
|
244 | 244 | $this->readConfiguration(); |
245 | 245 | } |
246 | - if(is_null($this->cache) |
|
246 | + if (is_null($this->cache) |
|
247 | 247 | || !$this->configuration->ldapCacheTTL |
248 | 248 | || !$this->configuration->ldapConfigurationActive) { |
249 | 249 | return null; |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | } |
255 | 255 | |
256 | 256 | public function clearCache() { |
257 | - if(!is_null($this->cache)) { |
|
257 | + if (!is_null($this->cache)) { |
|
258 | 258 | $this->cache->clear($this->getCacheKey(null)); |
259 | 259 | } |
260 | 260 | } |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | * @return null |
267 | 267 | */ |
268 | 268 | private function readConfiguration($force = false) { |
269 | - if((!$this->configured || $force) && !is_null($this->configID)) { |
|
269 | + if ((!$this->configured || $force) && !is_null($this->configID)) { |
|
270 | 270 | $this->configuration->readConfiguration(); |
271 | 271 | $this->configured = $this->validateConfiguration(); |
272 | 272 | } |
@@ -279,12 +279,12 @@ discard block |
||
279 | 279 | * @return boolean true if config validates, false otherwise. Check with $setParameters for detailed success on single parameters |
280 | 280 | */ |
281 | 281 | public function setConfiguration($config, &$setParameters = null) { |
282 | - if(is_null($setParameters)) { |
|
282 | + if (is_null($setParameters)) { |
|
283 | 283 | $setParameters = array(); |
284 | 284 | } |
285 | 285 | $this->doNotValidate = false; |
286 | 286 | $this->configuration->setConfiguration($config, $setParameters); |
287 | - if(count($setParameters) > 0) { |
|
287 | + if (count($setParameters) > 0) { |
|
288 | 288 | $this->configured = $this->validateConfiguration(); |
289 | 289 | } |
290 | 290 | |
@@ -311,10 +311,10 @@ discard block |
||
311 | 311 | $config = $this->configuration->getConfiguration(); |
312 | 312 | $cta = $this->configuration->getConfigTranslationArray(); |
313 | 313 | $result = array(); |
314 | - foreach($cta as $dbkey => $configkey) { |
|
315 | - switch($configkey) { |
|
314 | + foreach ($cta as $dbkey => $configkey) { |
|
315 | + switch ($configkey) { |
|
316 | 316 | case 'homeFolderNamingRule': |
317 | - if(strpos($config[$configkey], 'attr:') === 0) { |
|
317 | + if (strpos($config[$configkey], 'attr:') === 0) { |
|
318 | 318 | $result[$dbkey] = substr($config[$configkey], 5); |
319 | 319 | } else { |
320 | 320 | $result[$dbkey] = ''; |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | case 'ldapBaseGroups': |
326 | 326 | case 'ldapAttributesForUserSearch': |
327 | 327 | case 'ldapAttributesForGroupSearch': |
328 | - if(is_array($config[$configkey])) { |
|
328 | + if (is_array($config[$configkey])) { |
|
329 | 329 | $result[$dbkey] = implode("\n", $config[$configkey]); |
330 | 330 | break; |
331 | 331 | } //else follows default |
@@ -338,23 +338,23 @@ discard block |
||
338 | 338 | |
339 | 339 | private function doSoftValidation() { |
340 | 340 | //if User or Group Base are not set, take over Base DN setting |
341 | - foreach(array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) { |
|
341 | + foreach (array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) { |
|
342 | 342 | $val = $this->configuration->$keyBase; |
343 | - if(empty($val)) { |
|
343 | + if (empty($val)) { |
|
344 | 344 | $this->configuration->$keyBase = $this->configuration->ldapBase; |
345 | 345 | } |
346 | 346 | } |
347 | 347 | |
348 | - foreach(array('ldapExpertUUIDUserAttr' => 'ldapUuidUserAttribute', |
|
348 | + foreach (array('ldapExpertUUIDUserAttr' => 'ldapUuidUserAttribute', |
|
349 | 349 | 'ldapExpertUUIDGroupAttr' => 'ldapUuidGroupAttribute') |
350 | 350 | as $expertSetting => $effectiveSetting) { |
351 | 351 | $uuidOverride = $this->configuration->$expertSetting; |
352 | - if(!empty($uuidOverride)) { |
|
352 | + if (!empty($uuidOverride)) { |
|
353 | 353 | $this->configuration->$effectiveSetting = $uuidOverride; |
354 | 354 | } else { |
355 | 355 | $uuidAttributes = Access::UUID_ATTRIBUTES; |
356 | 356 | array_unshift($uuidAttributes, 'auto'); |
357 | - if(!in_array($this->configuration->$effectiveSetting, |
|
357 | + if (!in_array($this->configuration->$effectiveSetting, |
|
358 | 358 | $uuidAttributes) |
359 | 359 | && (!is_null($this->configID))) { |
360 | 360 | $this->configuration->$effectiveSetting = 'auto'; |
@@ -376,14 +376,14 @@ discard block |
||
376 | 376 | //make sure empty search attributes are saved as simple, empty array |
377 | 377 | $saKeys = array('ldapAttributesForUserSearch', |
378 | 378 | 'ldapAttributesForGroupSearch'); |
379 | - foreach($saKeys as $key) { |
|
379 | + foreach ($saKeys as $key) { |
|
380 | 380 | $val = $this->configuration->$key; |
381 | - if(is_array($val) && count($val) === 1 && empty($val[0])) { |
|
381 | + if (is_array($val) && count($val) === 1 && empty($val[0])) { |
|
382 | 382 | $this->configuration->$key = array(); |
383 | 383 | } |
384 | 384 | } |
385 | 385 | |
386 | - if((stripos($this->configuration->ldapHost, 'ldaps://') === 0) |
|
386 | + if ((stripos($this->configuration->ldapHost, 'ldaps://') === 0) |
|
387 | 387 | && $this->configuration->ldapTLS) { |
388 | 388 | $this->configuration->ldapTLS = false; |
389 | 389 | \OCP\Util::writeLog('user_ldap', |
@@ -404,10 +404,10 @@ discard block |
||
404 | 404 | //options that shall not be empty |
405 | 405 | $options = array('ldapHost', 'ldapPort', 'ldapUserDisplayName', |
406 | 406 | 'ldapGroupDisplayName', 'ldapLoginFilter'); |
407 | - foreach($options as $key) { |
|
407 | + foreach ($options as $key) { |
|
408 | 408 | $val = $this->configuration->$key; |
409 | - if(empty($val)) { |
|
410 | - switch($key) { |
|
409 | + if (empty($val)) { |
|
410 | + switch ($key) { |
|
411 | 411 | case 'ldapHost': |
412 | 412 | $subj = 'LDAP Host'; |
413 | 413 | break; |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | $agent = $this->configuration->ldapAgentName; |
439 | 439 | $pwd = $this->configuration->ldapAgentPassword; |
440 | 440 | if ( |
441 | - ($agent === '' && $pwd !== '') |
|
441 | + ($agent === '' && $pwd !== '') |
|
442 | 442 | || ($agent !== '' && $pwd === '') |
443 | 443 | ) { |
444 | 444 | \OCP\Util::writeLog('user_ldap', |
@@ -453,14 +453,14 @@ discard block |
||
453 | 453 | $baseUsers = $this->configuration->ldapBaseUsers; |
454 | 454 | $baseGroups = $this->configuration->ldapBaseGroups; |
455 | 455 | |
456 | - if(empty($base) && empty($baseUsers) && empty($baseGroups)) { |
|
456 | + if (empty($base) && empty($baseUsers) && empty($baseGroups)) { |
|
457 | 457 | \OCP\Util::writeLog('user_ldap', |
458 | 458 | $errorStr.'Not a single Base DN given.', |
459 | 459 | \OCP\Util::WARN); |
460 | 460 | $configurationOK = false; |
461 | 461 | } |
462 | 462 | |
463 | - if(mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
463 | + if (mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
464 | 464 | === false) { |
465 | 465 | \OCP\Util::writeLog('user_ldap', |
466 | 466 | $errorStr.'login filter does not contain %uid '. |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | */ |
479 | 479 | private function validateConfiguration() { |
480 | 480 | |
481 | - if($this->doNotValidate) { |
|
481 | + if ($this->doNotValidate) { |
|
482 | 482 | //don't do a validation if it is a new configuration with pure |
483 | 483 | //default values. Will be allowed on changes via __set or |
484 | 484 | //setConfiguration |
@@ -499,21 +499,21 @@ discard block |
||
499 | 499 | * Connects and Binds to LDAP |
500 | 500 | */ |
501 | 501 | private function establishConnection() { |
502 | - if(!$this->configuration->ldapConfigurationActive) { |
|
502 | + if (!$this->configuration->ldapConfigurationActive) { |
|
503 | 503 | return null; |
504 | 504 | } |
505 | 505 | static $phpLDAPinstalled = true; |
506 | - if(!$phpLDAPinstalled) { |
|
506 | + if (!$phpLDAPinstalled) { |
|
507 | 507 | return false; |
508 | 508 | } |
509 | - if(!$this->ignoreValidation && !$this->configured) { |
|
509 | + if (!$this->ignoreValidation && !$this->configured) { |
|
510 | 510 | \OCP\Util::writeLog('user_ldap', |
511 | 511 | 'Configuration is invalid, cannot connect', |
512 | 512 | \OCP\Util::WARN); |
513 | 513 | return false; |
514 | 514 | } |
515 | - if(!$this->ldapConnectionRes) { |
|
516 | - if(!$this->ldap->areLDAPFunctionsAvailable()) { |
|
515 | + if (!$this->ldapConnectionRes) { |
|
516 | + if (!$this->ldap->areLDAPFunctionsAvailable()) { |
|
517 | 517 | $phpLDAPinstalled = false; |
518 | 518 | \OCP\Util::writeLog('user_ldap', |
519 | 519 | 'function ldap_connect is not available. Make '. |
@@ -522,8 +522,8 @@ discard block |
||
522 | 522 | |
523 | 523 | return false; |
524 | 524 | } |
525 | - if($this->configuration->turnOffCertCheck) { |
|
526 | - if(putenv('LDAPTLS_REQCERT=never')) { |
|
525 | + if ($this->configuration->turnOffCertCheck) { |
|
526 | + if (putenv('LDAPTLS_REQCERT=never')) { |
|
527 | 527 | \OCP\Util::writeLog('user_ldap', |
528 | 528 | 'Turned off SSL certificate validation successfully.', |
529 | 529 | \OCP\Util::DEBUG); |
@@ -547,23 +547,23 @@ discard block |
||
547 | 547 | $error = $this->ldap->isResource($this->ldapConnectionRes) ? |
548 | 548 | $this->ldap->errno($this->ldapConnectionRes) : -1; |
549 | 549 | } |
550 | - if($bindStatus === true) { |
|
550 | + if ($bindStatus === true) { |
|
551 | 551 | return $bindStatus; |
552 | 552 | } |
553 | 553 | } catch (ServerNotAvailableException $e) { |
554 | - if(!$isBackupHost) { |
|
554 | + if (!$isBackupHost) { |
|
555 | 555 | throw $e; |
556 | 556 | } |
557 | 557 | } |
558 | 558 | |
559 | 559 | //if LDAP server is not reachable, try the Backup (Replica!) Server |
560 | - if($isBackupHost && ($error !== 0 || $isOverrideMainServer)) { |
|
560 | + if ($isBackupHost && ($error !== 0 || $isOverrideMainServer)) { |
|
561 | 561 | $this->doConnect($this->configuration->ldapBackupHost, |
562 | 562 | $this->configuration->ldapBackupPort); |
563 | 563 | $bindStatus = $this->bind(); |
564 | 564 | $error = $this->ldap->isResource($this->ldapConnectionRes) ? |
565 | 565 | $this->ldap->errno($this->ldapConnectionRes) : -1; |
566 | - if($bindStatus && $error === 0 && !$this->getFromCache('overrideMainServer')) { |
|
566 | + if ($bindStatus && $error === 0 && !$this->getFromCache('overrideMainServer')) { |
|
567 | 567 | //when bind to backup server succeeded and failed to main server, |
568 | 568 | //skip contacting him until next cache refresh |
569 | 569 | $this->writeToCache('overrideMainServer', true); |
@@ -588,17 +588,17 @@ discard block |
||
588 | 588 | |
589 | 589 | $this->ldapConnectionRes = $this->ldap->connect($host, $port); |
590 | 590 | |
591 | - if(!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) { |
|
591 | + if (!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) { |
|
592 | 592 | throw new ServerNotAvailableException('Could not set required LDAP Protocol version.'); |
593 | 593 | } |
594 | 594 | |
595 | - if(!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) { |
|
595 | + if (!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) { |
|
596 | 596 | throw new ServerNotAvailableException('Could not disable LDAP referrals.'); |
597 | 597 | } |
598 | 598 | |
599 | - if($this->configuration->ldapTLS) { |
|
600 | - if(!$this->ldap->startTls($this->ldapConnectionRes)) { |
|
601 | - throw new ServerNotAvailableException('Start TLS failed, when connecting to LDAP host ' . $host . '.'); |
|
599 | + if ($this->configuration->ldapTLS) { |
|
600 | + if (!$this->ldap->startTls($this->ldapConnectionRes)) { |
|
601 | + throw new ServerNotAvailableException('Start TLS failed, when connecting to LDAP host '.$host.'.'); |
|
602 | 602 | } |
603 | 603 | } |
604 | 604 | |
@@ -609,25 +609,25 @@ discard block |
||
609 | 609 | * Binds to LDAP |
610 | 610 | */ |
611 | 611 | public function bind() { |
612 | - if(!$this->configuration->ldapConfigurationActive) { |
|
612 | + if (!$this->configuration->ldapConfigurationActive) { |
|
613 | 613 | return false; |
614 | 614 | } |
615 | 615 | $cr = $this->getConnectionResource(); |
616 | - if(!$this->ldap->isResource($cr)) { |
|
616 | + if (!$this->ldap->isResource($cr)) { |
|
617 | 617 | return false; |
618 | 618 | } |
619 | 619 | $ldapLogin = @$this->ldap->bind($cr, |
620 | 620 | $this->configuration->ldapAgentName, |
621 | 621 | $this->configuration->ldapAgentPassword); |
622 | - if(!$ldapLogin) { |
|
622 | + if (!$ldapLogin) { |
|
623 | 623 | $errno = $this->ldap->errno($cr); |
624 | 624 | |
625 | 625 | \OCP\Util::writeLog('user_ldap', |
626 | - 'Bind failed: ' . $errno . ': ' . $this->ldap->error($cr), |
|
626 | + 'Bind failed: '.$errno.': '.$this->ldap->error($cr), |
|
627 | 627 | \OCP\Util::WARN); |
628 | 628 | |
629 | 629 | // Set to failure mode, if LDAP error code is not LDAP_SUCCESS or LDAP_INVALID_CREDENTIALS |
630 | - if($errno !== 0x00 && $errno !== 0x31) { |
|
630 | + if ($errno !== 0x00 && $errno !== 0x31) { |
|
631 | 631 | $this->ldapConnectionRes = null; |
632 | 632 | } |
633 | 633 |
@@ -37,502 +37,502 @@ |
||
37 | 37 | * @property int ldapPagingSize holds an integer |
38 | 38 | */ |
39 | 39 | class Configuration { |
40 | - protected $configPrefix = null; |
|
41 | - protected $configRead = false; |
|
42 | - /** |
|
43 | - * @var string[] pre-filled with one reference key so that at least one entry is written on save request and |
|
44 | - * the config ID is registered |
|
45 | - */ |
|
46 | - protected $unsavedChanges = ['ldapConfigurationActive' => 'ldapConfigurationActive']; |
|
40 | + protected $configPrefix = null; |
|
41 | + protected $configRead = false; |
|
42 | + /** |
|
43 | + * @var string[] pre-filled with one reference key so that at least one entry is written on save request and |
|
44 | + * the config ID is registered |
|
45 | + */ |
|
46 | + protected $unsavedChanges = ['ldapConfigurationActive' => 'ldapConfigurationActive']; |
|
47 | 47 | |
48 | - //settings |
|
49 | - protected $config = array( |
|
50 | - 'ldapHost' => null, |
|
51 | - 'ldapPort' => null, |
|
52 | - 'ldapBackupHost' => null, |
|
53 | - 'ldapBackupPort' => null, |
|
54 | - 'ldapBase' => null, |
|
55 | - 'ldapBaseUsers' => null, |
|
56 | - 'ldapBaseGroups' => null, |
|
57 | - 'ldapAgentName' => null, |
|
58 | - 'ldapAgentPassword' => null, |
|
59 | - 'ldapTLS' => null, |
|
60 | - 'turnOffCertCheck' => null, |
|
61 | - 'ldapIgnoreNamingRules' => null, |
|
62 | - 'ldapUserDisplayName' => null, |
|
63 | - 'ldapUserDisplayName2' => null, |
|
64 | - 'ldapGidNumber' => null, |
|
65 | - 'ldapUserFilterObjectclass' => null, |
|
66 | - 'ldapUserFilterGroups' => null, |
|
67 | - 'ldapUserFilter' => null, |
|
68 | - 'ldapUserFilterMode' => null, |
|
69 | - 'ldapGroupFilter' => null, |
|
70 | - 'ldapGroupFilterMode' => null, |
|
71 | - 'ldapGroupFilterObjectclass' => null, |
|
72 | - 'ldapGroupFilterGroups' => null, |
|
73 | - 'ldapGroupDisplayName' => null, |
|
74 | - 'ldapGroupMemberAssocAttr' => null, |
|
75 | - 'ldapLoginFilter' => null, |
|
76 | - 'ldapLoginFilterMode' => null, |
|
77 | - 'ldapLoginFilterEmail' => null, |
|
78 | - 'ldapLoginFilterUsername' => null, |
|
79 | - 'ldapLoginFilterAttributes' => null, |
|
80 | - 'ldapQuotaAttribute' => null, |
|
81 | - 'ldapQuotaDefault' => null, |
|
82 | - 'ldapEmailAttribute' => null, |
|
83 | - 'ldapCacheTTL' => null, |
|
84 | - 'ldapUuidUserAttribute' => 'auto', |
|
85 | - 'ldapUuidGroupAttribute' => 'auto', |
|
86 | - 'ldapOverrideMainServer' => false, |
|
87 | - 'ldapConfigurationActive' => false, |
|
88 | - 'ldapAttributesForUserSearch' => null, |
|
89 | - 'ldapAttributesForGroupSearch' => null, |
|
90 | - 'ldapExperiencedAdmin' => false, |
|
91 | - 'homeFolderNamingRule' => null, |
|
92 | - 'hasPagedResultSupport' => false, |
|
93 | - 'hasMemberOfFilterSupport' => false, |
|
94 | - 'useMemberOfToDetectMembership' => true, |
|
95 | - 'ldapExpertUsernameAttr' => null, |
|
96 | - 'ldapExpertUUIDUserAttr' => null, |
|
97 | - 'ldapExpertUUIDGroupAttr' => null, |
|
98 | - 'lastJpegPhotoLookup' => null, |
|
99 | - 'ldapNestedGroups' => false, |
|
100 | - 'ldapPagingSize' => null, |
|
101 | - 'turnOnPasswordChange' => false, |
|
102 | - 'ldapDynamicGroupMemberURL' => null, |
|
103 | - 'ldapDefaultPPolicyDN' => null, |
|
104 | - ); |
|
48 | + //settings |
|
49 | + protected $config = array( |
|
50 | + 'ldapHost' => null, |
|
51 | + 'ldapPort' => null, |
|
52 | + 'ldapBackupHost' => null, |
|
53 | + 'ldapBackupPort' => null, |
|
54 | + 'ldapBase' => null, |
|
55 | + 'ldapBaseUsers' => null, |
|
56 | + 'ldapBaseGroups' => null, |
|
57 | + 'ldapAgentName' => null, |
|
58 | + 'ldapAgentPassword' => null, |
|
59 | + 'ldapTLS' => null, |
|
60 | + 'turnOffCertCheck' => null, |
|
61 | + 'ldapIgnoreNamingRules' => null, |
|
62 | + 'ldapUserDisplayName' => null, |
|
63 | + 'ldapUserDisplayName2' => null, |
|
64 | + 'ldapGidNumber' => null, |
|
65 | + 'ldapUserFilterObjectclass' => null, |
|
66 | + 'ldapUserFilterGroups' => null, |
|
67 | + 'ldapUserFilter' => null, |
|
68 | + 'ldapUserFilterMode' => null, |
|
69 | + 'ldapGroupFilter' => null, |
|
70 | + 'ldapGroupFilterMode' => null, |
|
71 | + 'ldapGroupFilterObjectclass' => null, |
|
72 | + 'ldapGroupFilterGroups' => null, |
|
73 | + 'ldapGroupDisplayName' => null, |
|
74 | + 'ldapGroupMemberAssocAttr' => null, |
|
75 | + 'ldapLoginFilter' => null, |
|
76 | + 'ldapLoginFilterMode' => null, |
|
77 | + 'ldapLoginFilterEmail' => null, |
|
78 | + 'ldapLoginFilterUsername' => null, |
|
79 | + 'ldapLoginFilterAttributes' => null, |
|
80 | + 'ldapQuotaAttribute' => null, |
|
81 | + 'ldapQuotaDefault' => null, |
|
82 | + 'ldapEmailAttribute' => null, |
|
83 | + 'ldapCacheTTL' => null, |
|
84 | + 'ldapUuidUserAttribute' => 'auto', |
|
85 | + 'ldapUuidGroupAttribute' => 'auto', |
|
86 | + 'ldapOverrideMainServer' => false, |
|
87 | + 'ldapConfigurationActive' => false, |
|
88 | + 'ldapAttributesForUserSearch' => null, |
|
89 | + 'ldapAttributesForGroupSearch' => null, |
|
90 | + 'ldapExperiencedAdmin' => false, |
|
91 | + 'homeFolderNamingRule' => null, |
|
92 | + 'hasPagedResultSupport' => false, |
|
93 | + 'hasMemberOfFilterSupport' => false, |
|
94 | + 'useMemberOfToDetectMembership' => true, |
|
95 | + 'ldapExpertUsernameAttr' => null, |
|
96 | + 'ldapExpertUUIDUserAttr' => null, |
|
97 | + 'ldapExpertUUIDGroupAttr' => null, |
|
98 | + 'lastJpegPhotoLookup' => null, |
|
99 | + 'ldapNestedGroups' => false, |
|
100 | + 'ldapPagingSize' => null, |
|
101 | + 'turnOnPasswordChange' => false, |
|
102 | + 'ldapDynamicGroupMemberURL' => null, |
|
103 | + 'ldapDefaultPPolicyDN' => null, |
|
104 | + ); |
|
105 | 105 | |
106 | - /** |
|
107 | - * @param string $configPrefix |
|
108 | - * @param bool $autoRead |
|
109 | - */ |
|
110 | - public function __construct($configPrefix, $autoRead = true) { |
|
111 | - $this->configPrefix = $configPrefix; |
|
112 | - if($autoRead) { |
|
113 | - $this->readConfiguration(); |
|
114 | - } |
|
115 | - } |
|
106 | + /** |
|
107 | + * @param string $configPrefix |
|
108 | + * @param bool $autoRead |
|
109 | + */ |
|
110 | + public function __construct($configPrefix, $autoRead = true) { |
|
111 | + $this->configPrefix = $configPrefix; |
|
112 | + if($autoRead) { |
|
113 | + $this->readConfiguration(); |
|
114 | + } |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * @param string $name |
|
119 | - * @return mixed|null |
|
120 | - */ |
|
121 | - public function __get($name) { |
|
122 | - if(isset($this->config[$name])) { |
|
123 | - return $this->config[$name]; |
|
124 | - } |
|
125 | - return null; |
|
126 | - } |
|
117 | + /** |
|
118 | + * @param string $name |
|
119 | + * @return mixed|null |
|
120 | + */ |
|
121 | + public function __get($name) { |
|
122 | + if(isset($this->config[$name])) { |
|
123 | + return $this->config[$name]; |
|
124 | + } |
|
125 | + return null; |
|
126 | + } |
|
127 | 127 | |
128 | - /** |
|
129 | - * @param string $name |
|
130 | - * @param mixed $value |
|
131 | - */ |
|
132 | - public function __set($name, $value) { |
|
133 | - $this->setConfiguration(array($name => $value)); |
|
134 | - } |
|
128 | + /** |
|
129 | + * @param string $name |
|
130 | + * @param mixed $value |
|
131 | + */ |
|
132 | + public function __set($name, $value) { |
|
133 | + $this->setConfiguration(array($name => $value)); |
|
134 | + } |
|
135 | 135 | |
136 | - /** |
|
137 | - * @return array |
|
138 | - */ |
|
139 | - public function getConfiguration() { |
|
140 | - return $this->config; |
|
141 | - } |
|
136 | + /** |
|
137 | + * @return array |
|
138 | + */ |
|
139 | + public function getConfiguration() { |
|
140 | + return $this->config; |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * set LDAP configuration with values delivered by an array, not read |
|
145 | - * from configuration. It does not save the configuration! To do so, you |
|
146 | - * must call saveConfiguration afterwards. |
|
147 | - * @param array $config array that holds the config parameters in an associated |
|
148 | - * array |
|
149 | - * @param array &$applied optional; array where the set fields will be given to |
|
150 | - * @return false|null |
|
151 | - */ |
|
152 | - public function setConfiguration($config, &$applied = null) { |
|
153 | - if(!is_array($config)) { |
|
154 | - return false; |
|
155 | - } |
|
143 | + /** |
|
144 | + * set LDAP configuration with values delivered by an array, not read |
|
145 | + * from configuration. It does not save the configuration! To do so, you |
|
146 | + * must call saveConfiguration afterwards. |
|
147 | + * @param array $config array that holds the config parameters in an associated |
|
148 | + * array |
|
149 | + * @param array &$applied optional; array where the set fields will be given to |
|
150 | + * @return false|null |
|
151 | + */ |
|
152 | + public function setConfiguration($config, &$applied = null) { |
|
153 | + if(!is_array($config)) { |
|
154 | + return false; |
|
155 | + } |
|
156 | 156 | |
157 | - $cta = $this->getConfigTranslationArray(); |
|
158 | - foreach($config as $inputKey => $val) { |
|
159 | - if(strpos($inputKey, '_') !== false && array_key_exists($inputKey, $cta)) { |
|
160 | - $key = $cta[$inputKey]; |
|
161 | - } elseif(array_key_exists($inputKey, $this->config)) { |
|
162 | - $key = $inputKey; |
|
163 | - } else { |
|
164 | - continue; |
|
165 | - } |
|
157 | + $cta = $this->getConfigTranslationArray(); |
|
158 | + foreach($config as $inputKey => $val) { |
|
159 | + if(strpos($inputKey, '_') !== false && array_key_exists($inputKey, $cta)) { |
|
160 | + $key = $cta[$inputKey]; |
|
161 | + } elseif(array_key_exists($inputKey, $this->config)) { |
|
162 | + $key = $inputKey; |
|
163 | + } else { |
|
164 | + continue; |
|
165 | + } |
|
166 | 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 | - return null; |
|
199 | - } |
|
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 | + return null; |
|
199 | + } |
|
200 | 200 | |
201 | - public function readConfiguration() { |
|
202 | - if(!$this->configRead && !is_null($this->configPrefix)) { |
|
203 | - $cta = array_flip($this->getConfigTranslationArray()); |
|
204 | - foreach($this->config as $key => $val) { |
|
205 | - if(!isset($cta[$key])) { |
|
206 | - //some are determined |
|
207 | - continue; |
|
208 | - } |
|
209 | - $dbKey = $cta[$key]; |
|
210 | - switch($key) { |
|
211 | - case 'ldapBase': |
|
212 | - case 'ldapBaseUsers': |
|
213 | - case 'ldapBaseGroups': |
|
214 | - case 'ldapAttributesForUserSearch': |
|
215 | - case 'ldapAttributesForGroupSearch': |
|
216 | - case 'ldapUserFilterObjectclass': |
|
217 | - case 'ldapUserFilterGroups': |
|
218 | - case 'ldapGroupFilterObjectclass': |
|
219 | - case 'ldapGroupFilterGroups': |
|
220 | - case 'ldapLoginFilterAttributes': |
|
221 | - $readMethod = 'getMultiLine'; |
|
222 | - break; |
|
223 | - case 'ldapIgnoreNamingRules': |
|
224 | - $readMethod = 'getSystemValue'; |
|
225 | - $dbKey = $key; |
|
226 | - break; |
|
227 | - case 'ldapAgentPassword': |
|
228 | - $readMethod = 'getPwd'; |
|
229 | - break; |
|
230 | - case 'ldapUserDisplayName2': |
|
231 | - case 'ldapGroupDisplayName': |
|
232 | - $readMethod = 'getLcValue'; |
|
233 | - break; |
|
234 | - case 'ldapUserDisplayName': |
|
235 | - default: |
|
236 | - // user display name does not lower case because |
|
237 | - // we rely on an upper case N as indicator whether to |
|
238 | - // auto-detect it or not. FIXME |
|
239 | - $readMethod = 'getValue'; |
|
240 | - break; |
|
241 | - } |
|
242 | - $this->config[$key] = $this->$readMethod($dbKey); |
|
243 | - } |
|
244 | - $this->configRead = true; |
|
245 | - } |
|
246 | - } |
|
201 | + public function readConfiguration() { |
|
202 | + if(!$this->configRead && !is_null($this->configPrefix)) { |
|
203 | + $cta = array_flip($this->getConfigTranslationArray()); |
|
204 | + foreach($this->config as $key => $val) { |
|
205 | + if(!isset($cta[$key])) { |
|
206 | + //some are determined |
|
207 | + continue; |
|
208 | + } |
|
209 | + $dbKey = $cta[$key]; |
|
210 | + switch($key) { |
|
211 | + case 'ldapBase': |
|
212 | + case 'ldapBaseUsers': |
|
213 | + case 'ldapBaseGroups': |
|
214 | + case 'ldapAttributesForUserSearch': |
|
215 | + case 'ldapAttributesForGroupSearch': |
|
216 | + case 'ldapUserFilterObjectclass': |
|
217 | + case 'ldapUserFilterGroups': |
|
218 | + case 'ldapGroupFilterObjectclass': |
|
219 | + case 'ldapGroupFilterGroups': |
|
220 | + case 'ldapLoginFilterAttributes': |
|
221 | + $readMethod = 'getMultiLine'; |
|
222 | + break; |
|
223 | + case 'ldapIgnoreNamingRules': |
|
224 | + $readMethod = 'getSystemValue'; |
|
225 | + $dbKey = $key; |
|
226 | + break; |
|
227 | + case 'ldapAgentPassword': |
|
228 | + $readMethod = 'getPwd'; |
|
229 | + break; |
|
230 | + case 'ldapUserDisplayName2': |
|
231 | + case 'ldapGroupDisplayName': |
|
232 | + $readMethod = 'getLcValue'; |
|
233 | + break; |
|
234 | + case 'ldapUserDisplayName': |
|
235 | + default: |
|
236 | + // user display name does not lower case because |
|
237 | + // we rely on an upper case N as indicator whether to |
|
238 | + // auto-detect it or not. FIXME |
|
239 | + $readMethod = 'getValue'; |
|
240 | + break; |
|
241 | + } |
|
242 | + $this->config[$key] = $this->$readMethod($dbKey); |
|
243 | + } |
|
244 | + $this->configRead = true; |
|
245 | + } |
|
246 | + } |
|
247 | 247 | |
248 | - /** |
|
249 | - * saves the current config changes in the database |
|
250 | - */ |
|
251 | - public function saveConfiguration() { |
|
252 | - $cta = array_flip($this->getConfigTranslationArray()); |
|
253 | - foreach($this->unsavedChanges as $key) { |
|
254 | - $value = $this->config[$key]; |
|
255 | - switch ($key) { |
|
256 | - case 'ldapAgentPassword': |
|
257 | - $value = base64_encode($value); |
|
258 | - break; |
|
259 | - case 'ldapBase': |
|
260 | - case 'ldapBaseUsers': |
|
261 | - case 'ldapBaseGroups': |
|
262 | - case 'ldapAttributesForUserSearch': |
|
263 | - case 'ldapAttributesForGroupSearch': |
|
264 | - case 'ldapUserFilterObjectclass': |
|
265 | - case 'ldapUserFilterGroups': |
|
266 | - case 'ldapGroupFilterObjectclass': |
|
267 | - case 'ldapGroupFilterGroups': |
|
268 | - case 'ldapLoginFilterAttributes': |
|
269 | - if(is_array($value)) { |
|
270 | - $value = implode("\n", $value); |
|
271 | - } |
|
272 | - break; |
|
273 | - //following options are not stored but detected, skip them |
|
274 | - case 'ldapIgnoreNamingRules': |
|
275 | - case 'hasPagedResultSupport': |
|
276 | - case 'ldapUuidUserAttribute': |
|
277 | - case 'ldapUuidGroupAttribute': |
|
278 | - continue 2; |
|
279 | - } |
|
280 | - if(is_null($value)) { |
|
281 | - $value = ''; |
|
282 | - } |
|
283 | - $this->saveValue($cta[$key], $value); |
|
284 | - } |
|
285 | - $this->saveValue('_lastChange', time()); |
|
286 | - $this->unsavedChanges = []; |
|
287 | - } |
|
248 | + /** |
|
249 | + * saves the current config changes in the database |
|
250 | + */ |
|
251 | + public function saveConfiguration() { |
|
252 | + $cta = array_flip($this->getConfigTranslationArray()); |
|
253 | + foreach($this->unsavedChanges as $key) { |
|
254 | + $value = $this->config[$key]; |
|
255 | + switch ($key) { |
|
256 | + case 'ldapAgentPassword': |
|
257 | + $value = base64_encode($value); |
|
258 | + break; |
|
259 | + case 'ldapBase': |
|
260 | + case 'ldapBaseUsers': |
|
261 | + case 'ldapBaseGroups': |
|
262 | + case 'ldapAttributesForUserSearch': |
|
263 | + case 'ldapAttributesForGroupSearch': |
|
264 | + case 'ldapUserFilterObjectclass': |
|
265 | + case 'ldapUserFilterGroups': |
|
266 | + case 'ldapGroupFilterObjectclass': |
|
267 | + case 'ldapGroupFilterGroups': |
|
268 | + case 'ldapLoginFilterAttributes': |
|
269 | + if(is_array($value)) { |
|
270 | + $value = implode("\n", $value); |
|
271 | + } |
|
272 | + break; |
|
273 | + //following options are not stored but detected, skip them |
|
274 | + case 'ldapIgnoreNamingRules': |
|
275 | + case 'hasPagedResultSupport': |
|
276 | + case 'ldapUuidUserAttribute': |
|
277 | + case 'ldapUuidGroupAttribute': |
|
278 | + continue 2; |
|
279 | + } |
|
280 | + if(is_null($value)) { |
|
281 | + $value = ''; |
|
282 | + } |
|
283 | + $this->saveValue($cta[$key], $value); |
|
284 | + } |
|
285 | + $this->saveValue('_lastChange', time()); |
|
286 | + $this->unsavedChanges = []; |
|
287 | + } |
|
288 | 288 | |
289 | - /** |
|
290 | - * @param string $varName |
|
291 | - * @return array|string |
|
292 | - */ |
|
293 | - protected function getMultiLine($varName) { |
|
294 | - $value = $this->getValue($varName); |
|
295 | - if(empty($value)) { |
|
296 | - $value = ''; |
|
297 | - } else { |
|
298 | - $value = preg_split('/\r\n|\r|\n/', $value); |
|
299 | - } |
|
289 | + /** |
|
290 | + * @param string $varName |
|
291 | + * @return array|string |
|
292 | + */ |
|
293 | + protected function getMultiLine($varName) { |
|
294 | + $value = $this->getValue($varName); |
|
295 | + if(empty($value)) { |
|
296 | + $value = ''; |
|
297 | + } else { |
|
298 | + $value = preg_split('/\r\n|\r|\n/', $value); |
|
299 | + } |
|
300 | 300 | |
301 | - return $value; |
|
302 | - } |
|
301 | + return $value; |
|
302 | + } |
|
303 | 303 | |
304 | - /** |
|
305 | - * Sets multi-line values as arrays |
|
306 | - * |
|
307 | - * @param string $varName name of config-key |
|
308 | - * @param array|string $value to set |
|
309 | - */ |
|
310 | - protected function setMultiLine($varName, $value) { |
|
311 | - if(empty($value)) { |
|
312 | - $value = ''; |
|
313 | - } else if (!is_array($value)) { |
|
314 | - $value = preg_split('/\r\n|\r|\n|;/', $value); |
|
315 | - if($value === false) { |
|
316 | - $value = ''; |
|
317 | - } |
|
318 | - } |
|
304 | + /** |
|
305 | + * Sets multi-line values as arrays |
|
306 | + * |
|
307 | + * @param string $varName name of config-key |
|
308 | + * @param array|string $value to set |
|
309 | + */ |
|
310 | + protected function setMultiLine($varName, $value) { |
|
311 | + if(empty($value)) { |
|
312 | + $value = ''; |
|
313 | + } else if (!is_array($value)) { |
|
314 | + $value = preg_split('/\r\n|\r|\n|;/', $value); |
|
315 | + if($value === false) { |
|
316 | + $value = ''; |
|
317 | + } |
|
318 | + } |
|
319 | 319 | |
320 | - if(!is_array($value)) { |
|
321 | - $finalValue = trim($value); |
|
322 | - } else { |
|
323 | - $finalValue = []; |
|
324 | - foreach($value as $key => $val) { |
|
325 | - if(is_string($val)) { |
|
326 | - $val = trim($val); |
|
327 | - if ($val !== '') { |
|
328 | - //accidental line breaks are not wanted and can cause |
|
329 | - // odd behaviour. Thus, away with them. |
|
330 | - $finalValue[] = $val; |
|
331 | - } |
|
332 | - } else { |
|
333 | - $finalValue[] = $val; |
|
334 | - } |
|
335 | - } |
|
336 | - } |
|
320 | + if(!is_array($value)) { |
|
321 | + $finalValue = trim($value); |
|
322 | + } else { |
|
323 | + $finalValue = []; |
|
324 | + foreach($value as $key => $val) { |
|
325 | + if(is_string($val)) { |
|
326 | + $val = trim($val); |
|
327 | + if ($val !== '') { |
|
328 | + //accidental line breaks are not wanted and can cause |
|
329 | + // odd behaviour. Thus, away with them. |
|
330 | + $finalValue[] = $val; |
|
331 | + } |
|
332 | + } else { |
|
333 | + $finalValue[] = $val; |
|
334 | + } |
|
335 | + } |
|
336 | + } |
|
337 | 337 | |
338 | - $this->setRawValue($varName, $finalValue); |
|
339 | - } |
|
338 | + $this->setRawValue($varName, $finalValue); |
|
339 | + } |
|
340 | 340 | |
341 | - /** |
|
342 | - * @param string $varName |
|
343 | - * @return string |
|
344 | - */ |
|
345 | - protected function getPwd($varName) { |
|
346 | - return base64_decode($this->getValue($varName)); |
|
347 | - } |
|
341 | + /** |
|
342 | + * @param string $varName |
|
343 | + * @return string |
|
344 | + */ |
|
345 | + protected function getPwd($varName) { |
|
346 | + return base64_decode($this->getValue($varName)); |
|
347 | + } |
|
348 | 348 | |
349 | - /** |
|
350 | - * @param string $varName |
|
351 | - * @return string |
|
352 | - */ |
|
353 | - protected function getLcValue($varName) { |
|
354 | - return mb_strtolower($this->getValue($varName), 'UTF-8'); |
|
355 | - } |
|
349 | + /** |
|
350 | + * @param string $varName |
|
351 | + * @return string |
|
352 | + */ |
|
353 | + protected function getLcValue($varName) { |
|
354 | + return mb_strtolower($this->getValue($varName), 'UTF-8'); |
|
355 | + } |
|
356 | 356 | |
357 | - /** |
|
358 | - * @param string $varName |
|
359 | - * @return string |
|
360 | - */ |
|
361 | - protected function getSystemValue($varName) { |
|
362 | - //FIXME: if another system value is added, softcode the default value |
|
363 | - return \OC::$server->getConfig()->getSystemValue($varName, false); |
|
364 | - } |
|
357 | + /** |
|
358 | + * @param string $varName |
|
359 | + * @return string |
|
360 | + */ |
|
361 | + protected function getSystemValue($varName) { |
|
362 | + //FIXME: if another system value is added, softcode the default value |
|
363 | + return \OC::$server->getConfig()->getSystemValue($varName, false); |
|
364 | + } |
|
365 | 365 | |
366 | - /** |
|
367 | - * @param string $varName |
|
368 | - * @return string |
|
369 | - */ |
|
370 | - protected function getValue($varName) { |
|
371 | - static $defaults; |
|
372 | - if(is_null($defaults)) { |
|
373 | - $defaults = $this->getDefaults(); |
|
374 | - } |
|
375 | - return \OCP\Config::getAppValue('user_ldap', |
|
376 | - $this->configPrefix.$varName, |
|
377 | - $defaults[$varName]); |
|
378 | - } |
|
366 | + /** |
|
367 | + * @param string $varName |
|
368 | + * @return string |
|
369 | + */ |
|
370 | + protected function getValue($varName) { |
|
371 | + static $defaults; |
|
372 | + if(is_null($defaults)) { |
|
373 | + $defaults = $this->getDefaults(); |
|
374 | + } |
|
375 | + return \OCP\Config::getAppValue('user_ldap', |
|
376 | + $this->configPrefix.$varName, |
|
377 | + $defaults[$varName]); |
|
378 | + } |
|
379 | 379 | |
380 | - /** |
|
381 | - * Sets a scalar value. |
|
382 | - * |
|
383 | - * @param string $varName name of config key |
|
384 | - * @param mixed $value to set |
|
385 | - */ |
|
386 | - protected function setValue($varName, $value) { |
|
387 | - if(is_string($value)) { |
|
388 | - $value = trim($value); |
|
389 | - } |
|
390 | - $this->config[$varName] = $value; |
|
391 | - } |
|
380 | + /** |
|
381 | + * Sets a scalar value. |
|
382 | + * |
|
383 | + * @param string $varName name of config key |
|
384 | + * @param mixed $value to set |
|
385 | + */ |
|
386 | + protected function setValue($varName, $value) { |
|
387 | + if(is_string($value)) { |
|
388 | + $value = trim($value); |
|
389 | + } |
|
390 | + $this->config[$varName] = $value; |
|
391 | + } |
|
392 | 392 | |
393 | - /** |
|
394 | - * Sets a scalar value without trimming. |
|
395 | - * |
|
396 | - * @param string $varName name of config key |
|
397 | - * @param mixed $value to set |
|
398 | - */ |
|
399 | - protected function setRawValue($varName, $value) { |
|
400 | - $this->config[$varName] = $value; |
|
401 | - } |
|
393 | + /** |
|
394 | + * Sets a scalar value without trimming. |
|
395 | + * |
|
396 | + * @param string $varName name of config key |
|
397 | + * @param mixed $value to set |
|
398 | + */ |
|
399 | + protected function setRawValue($varName, $value) { |
|
400 | + $this->config[$varName] = $value; |
|
401 | + } |
|
402 | 402 | |
403 | - /** |
|
404 | - * @param string $varName |
|
405 | - * @param string $value |
|
406 | - * @return bool |
|
407 | - */ |
|
408 | - protected function saveValue($varName, $value) { |
|
409 | - \OC::$server->getConfig()->setAppValue( |
|
410 | - 'user_ldap', |
|
411 | - $this->configPrefix.$varName, |
|
412 | - $value |
|
413 | - ); |
|
414 | - return true; |
|
415 | - } |
|
403 | + /** |
|
404 | + * @param string $varName |
|
405 | + * @param string $value |
|
406 | + * @return bool |
|
407 | + */ |
|
408 | + protected function saveValue($varName, $value) { |
|
409 | + \OC::$server->getConfig()->setAppValue( |
|
410 | + 'user_ldap', |
|
411 | + $this->configPrefix.$varName, |
|
412 | + $value |
|
413 | + ); |
|
414 | + return true; |
|
415 | + } |
|
416 | 416 | |
417 | - /** |
|
418 | - * @return array an associative array with the default values. Keys are correspond |
|
419 | - * to config-value entries in the database table |
|
420 | - */ |
|
421 | - public function getDefaults() { |
|
422 | - return array( |
|
423 | - 'ldap_host' => '', |
|
424 | - 'ldap_port' => '', |
|
425 | - 'ldap_backup_host' => '', |
|
426 | - 'ldap_backup_port' => '', |
|
427 | - 'ldap_override_main_server' => '', |
|
428 | - 'ldap_dn' => '', |
|
429 | - 'ldap_agent_password' => '', |
|
430 | - 'ldap_base' => '', |
|
431 | - 'ldap_base_users' => '', |
|
432 | - 'ldap_base_groups' => '', |
|
433 | - 'ldap_userlist_filter' => '', |
|
434 | - 'ldap_user_filter_mode' => 0, |
|
435 | - 'ldap_userfilter_objectclass' => '', |
|
436 | - 'ldap_userfilter_groups' => '', |
|
437 | - 'ldap_login_filter' => '', |
|
438 | - 'ldap_login_filter_mode' => 0, |
|
439 | - 'ldap_loginfilter_email' => 0, |
|
440 | - 'ldap_loginfilter_username' => 1, |
|
441 | - 'ldap_loginfilter_attributes' => '', |
|
442 | - 'ldap_group_filter' => '', |
|
443 | - 'ldap_group_filter_mode' => 0, |
|
444 | - 'ldap_groupfilter_objectclass' => '', |
|
445 | - 'ldap_groupfilter_groups' => '', |
|
446 | - 'ldap_gid_number' => 'gidNumber', |
|
447 | - 'ldap_display_name' => 'displayName', |
|
448 | - 'ldap_user_display_name_2' => '', |
|
449 | - 'ldap_group_display_name' => 'cn', |
|
450 | - 'ldap_tls' => 0, |
|
451 | - 'ldap_quota_def' => '', |
|
452 | - 'ldap_quota_attr' => '', |
|
453 | - 'ldap_email_attr' => '', |
|
454 | - 'ldap_group_member_assoc_attribute' => 'uniqueMember', |
|
455 | - 'ldap_cache_ttl' => 600, |
|
456 | - 'ldap_uuid_user_attribute' => 'auto', |
|
457 | - 'ldap_uuid_group_attribute' => 'auto', |
|
458 | - 'home_folder_naming_rule' => '', |
|
459 | - 'ldap_turn_off_cert_check' => 0, |
|
460 | - 'ldap_configuration_active' => 0, |
|
461 | - 'ldap_attributes_for_user_search' => '', |
|
462 | - 'ldap_attributes_for_group_search' => '', |
|
463 | - 'ldap_expert_username_attr' => '', |
|
464 | - 'ldap_expert_uuid_user_attr' => '', |
|
465 | - 'ldap_expert_uuid_group_attr' => '', |
|
466 | - 'has_memberof_filter_support' => 0, |
|
467 | - 'use_memberof_to_detect_membership' => 1, |
|
468 | - 'last_jpegPhoto_lookup' => 0, |
|
469 | - 'ldap_nested_groups' => 0, |
|
470 | - 'ldap_paging_size' => 500, |
|
471 | - 'ldap_turn_on_pwd_change' => 0, |
|
472 | - 'ldap_experienced_admin' => 0, |
|
473 | - 'ldap_dynamic_group_member_url' => '', |
|
474 | - 'ldap_default_ppolicy_dn' => '', |
|
475 | - ); |
|
476 | - } |
|
417 | + /** |
|
418 | + * @return array an associative array with the default values. Keys are correspond |
|
419 | + * to config-value entries in the database table |
|
420 | + */ |
|
421 | + public function getDefaults() { |
|
422 | + return array( |
|
423 | + 'ldap_host' => '', |
|
424 | + 'ldap_port' => '', |
|
425 | + 'ldap_backup_host' => '', |
|
426 | + 'ldap_backup_port' => '', |
|
427 | + 'ldap_override_main_server' => '', |
|
428 | + 'ldap_dn' => '', |
|
429 | + 'ldap_agent_password' => '', |
|
430 | + 'ldap_base' => '', |
|
431 | + 'ldap_base_users' => '', |
|
432 | + 'ldap_base_groups' => '', |
|
433 | + 'ldap_userlist_filter' => '', |
|
434 | + 'ldap_user_filter_mode' => 0, |
|
435 | + 'ldap_userfilter_objectclass' => '', |
|
436 | + 'ldap_userfilter_groups' => '', |
|
437 | + 'ldap_login_filter' => '', |
|
438 | + 'ldap_login_filter_mode' => 0, |
|
439 | + 'ldap_loginfilter_email' => 0, |
|
440 | + 'ldap_loginfilter_username' => 1, |
|
441 | + 'ldap_loginfilter_attributes' => '', |
|
442 | + 'ldap_group_filter' => '', |
|
443 | + 'ldap_group_filter_mode' => 0, |
|
444 | + 'ldap_groupfilter_objectclass' => '', |
|
445 | + 'ldap_groupfilter_groups' => '', |
|
446 | + 'ldap_gid_number' => 'gidNumber', |
|
447 | + 'ldap_display_name' => 'displayName', |
|
448 | + 'ldap_user_display_name_2' => '', |
|
449 | + 'ldap_group_display_name' => 'cn', |
|
450 | + 'ldap_tls' => 0, |
|
451 | + 'ldap_quota_def' => '', |
|
452 | + 'ldap_quota_attr' => '', |
|
453 | + 'ldap_email_attr' => '', |
|
454 | + 'ldap_group_member_assoc_attribute' => 'uniqueMember', |
|
455 | + 'ldap_cache_ttl' => 600, |
|
456 | + 'ldap_uuid_user_attribute' => 'auto', |
|
457 | + 'ldap_uuid_group_attribute' => 'auto', |
|
458 | + 'home_folder_naming_rule' => '', |
|
459 | + 'ldap_turn_off_cert_check' => 0, |
|
460 | + 'ldap_configuration_active' => 0, |
|
461 | + 'ldap_attributes_for_user_search' => '', |
|
462 | + 'ldap_attributes_for_group_search' => '', |
|
463 | + 'ldap_expert_username_attr' => '', |
|
464 | + 'ldap_expert_uuid_user_attr' => '', |
|
465 | + 'ldap_expert_uuid_group_attr' => '', |
|
466 | + 'has_memberof_filter_support' => 0, |
|
467 | + 'use_memberof_to_detect_membership' => 1, |
|
468 | + 'last_jpegPhoto_lookup' => 0, |
|
469 | + 'ldap_nested_groups' => 0, |
|
470 | + 'ldap_paging_size' => 500, |
|
471 | + 'ldap_turn_on_pwd_change' => 0, |
|
472 | + 'ldap_experienced_admin' => 0, |
|
473 | + 'ldap_dynamic_group_member_url' => '', |
|
474 | + 'ldap_default_ppolicy_dn' => '', |
|
475 | + ); |
|
476 | + } |
|
477 | 477 | |
478 | - /** |
|
479 | - * @return array that maps internal variable names to database fields |
|
480 | - */ |
|
481 | - public function getConfigTranslationArray() { |
|
482 | - //TODO: merge them into one representation |
|
483 | - static $array = array( |
|
484 | - 'ldap_host' => 'ldapHost', |
|
485 | - 'ldap_port' => 'ldapPort', |
|
486 | - 'ldap_backup_host' => 'ldapBackupHost', |
|
487 | - 'ldap_backup_port' => 'ldapBackupPort', |
|
488 | - 'ldap_override_main_server' => 'ldapOverrideMainServer', |
|
489 | - 'ldap_dn' => 'ldapAgentName', |
|
490 | - 'ldap_agent_password' => 'ldapAgentPassword', |
|
491 | - 'ldap_base' => 'ldapBase', |
|
492 | - 'ldap_base_users' => 'ldapBaseUsers', |
|
493 | - 'ldap_base_groups' => 'ldapBaseGroups', |
|
494 | - 'ldap_userfilter_objectclass' => 'ldapUserFilterObjectclass', |
|
495 | - 'ldap_userfilter_groups' => 'ldapUserFilterGroups', |
|
496 | - 'ldap_userlist_filter' => 'ldapUserFilter', |
|
497 | - 'ldap_user_filter_mode' => 'ldapUserFilterMode', |
|
498 | - 'ldap_login_filter' => 'ldapLoginFilter', |
|
499 | - 'ldap_login_filter_mode' => 'ldapLoginFilterMode', |
|
500 | - 'ldap_loginfilter_email' => 'ldapLoginFilterEmail', |
|
501 | - 'ldap_loginfilter_username' => 'ldapLoginFilterUsername', |
|
502 | - 'ldap_loginfilter_attributes' => 'ldapLoginFilterAttributes', |
|
503 | - 'ldap_group_filter' => 'ldapGroupFilter', |
|
504 | - 'ldap_group_filter_mode' => 'ldapGroupFilterMode', |
|
505 | - 'ldap_groupfilter_objectclass' => 'ldapGroupFilterObjectclass', |
|
506 | - 'ldap_groupfilter_groups' => 'ldapGroupFilterGroups', |
|
507 | - 'ldap_gid_number' => 'ldapGidNumber', |
|
508 | - 'ldap_display_name' => 'ldapUserDisplayName', |
|
509 | - 'ldap_user_display_name_2' => 'ldapUserDisplayName2', |
|
510 | - 'ldap_group_display_name' => 'ldapGroupDisplayName', |
|
511 | - 'ldap_tls' => 'ldapTLS', |
|
512 | - 'ldap_quota_def' => 'ldapQuotaDefault', |
|
513 | - 'ldap_quota_attr' => 'ldapQuotaAttribute', |
|
514 | - 'ldap_email_attr' => 'ldapEmailAttribute', |
|
515 | - 'ldap_group_member_assoc_attribute' => 'ldapGroupMemberAssocAttr', |
|
516 | - 'ldap_cache_ttl' => 'ldapCacheTTL', |
|
517 | - 'home_folder_naming_rule' => 'homeFolderNamingRule', |
|
518 | - 'ldap_turn_off_cert_check' => 'turnOffCertCheck', |
|
519 | - 'ldap_configuration_active' => 'ldapConfigurationActive', |
|
520 | - 'ldap_attributes_for_user_search' => 'ldapAttributesForUserSearch', |
|
521 | - 'ldap_attributes_for_group_search' => 'ldapAttributesForGroupSearch', |
|
522 | - 'ldap_expert_username_attr' => 'ldapExpertUsernameAttr', |
|
523 | - 'ldap_expert_uuid_user_attr' => 'ldapExpertUUIDUserAttr', |
|
524 | - 'ldap_expert_uuid_group_attr' => 'ldapExpertUUIDGroupAttr', |
|
525 | - 'has_memberof_filter_support' => 'hasMemberOfFilterSupport', |
|
526 | - 'use_memberof_to_detect_membership' => 'useMemberOfToDetectMembership', |
|
527 | - 'last_jpegPhoto_lookup' => 'lastJpegPhotoLookup', |
|
528 | - 'ldap_nested_groups' => 'ldapNestedGroups', |
|
529 | - 'ldap_paging_size' => 'ldapPagingSize', |
|
530 | - 'ldap_turn_on_pwd_change' => 'turnOnPasswordChange', |
|
531 | - 'ldap_experienced_admin' => 'ldapExperiencedAdmin', |
|
532 | - 'ldap_dynamic_group_member_url' => 'ldapDynamicGroupMemberURL', |
|
533 | - 'ldap_default_ppolicy_dn' => 'ldapDefaultPPolicyDN', |
|
534 | - ); |
|
535 | - return $array; |
|
536 | - } |
|
478 | + /** |
|
479 | + * @return array that maps internal variable names to database fields |
|
480 | + */ |
|
481 | + public function getConfigTranslationArray() { |
|
482 | + //TODO: merge them into one representation |
|
483 | + static $array = array( |
|
484 | + 'ldap_host' => 'ldapHost', |
|
485 | + 'ldap_port' => 'ldapPort', |
|
486 | + 'ldap_backup_host' => 'ldapBackupHost', |
|
487 | + 'ldap_backup_port' => 'ldapBackupPort', |
|
488 | + 'ldap_override_main_server' => 'ldapOverrideMainServer', |
|
489 | + 'ldap_dn' => 'ldapAgentName', |
|
490 | + 'ldap_agent_password' => 'ldapAgentPassword', |
|
491 | + 'ldap_base' => 'ldapBase', |
|
492 | + 'ldap_base_users' => 'ldapBaseUsers', |
|
493 | + 'ldap_base_groups' => 'ldapBaseGroups', |
|
494 | + 'ldap_userfilter_objectclass' => 'ldapUserFilterObjectclass', |
|
495 | + 'ldap_userfilter_groups' => 'ldapUserFilterGroups', |
|
496 | + 'ldap_userlist_filter' => 'ldapUserFilter', |
|
497 | + 'ldap_user_filter_mode' => 'ldapUserFilterMode', |
|
498 | + 'ldap_login_filter' => 'ldapLoginFilter', |
|
499 | + 'ldap_login_filter_mode' => 'ldapLoginFilterMode', |
|
500 | + 'ldap_loginfilter_email' => 'ldapLoginFilterEmail', |
|
501 | + 'ldap_loginfilter_username' => 'ldapLoginFilterUsername', |
|
502 | + 'ldap_loginfilter_attributes' => 'ldapLoginFilterAttributes', |
|
503 | + 'ldap_group_filter' => 'ldapGroupFilter', |
|
504 | + 'ldap_group_filter_mode' => 'ldapGroupFilterMode', |
|
505 | + 'ldap_groupfilter_objectclass' => 'ldapGroupFilterObjectclass', |
|
506 | + 'ldap_groupfilter_groups' => 'ldapGroupFilterGroups', |
|
507 | + 'ldap_gid_number' => 'ldapGidNumber', |
|
508 | + 'ldap_display_name' => 'ldapUserDisplayName', |
|
509 | + 'ldap_user_display_name_2' => 'ldapUserDisplayName2', |
|
510 | + 'ldap_group_display_name' => 'ldapGroupDisplayName', |
|
511 | + 'ldap_tls' => 'ldapTLS', |
|
512 | + 'ldap_quota_def' => 'ldapQuotaDefault', |
|
513 | + 'ldap_quota_attr' => 'ldapQuotaAttribute', |
|
514 | + 'ldap_email_attr' => 'ldapEmailAttribute', |
|
515 | + 'ldap_group_member_assoc_attribute' => 'ldapGroupMemberAssocAttr', |
|
516 | + 'ldap_cache_ttl' => 'ldapCacheTTL', |
|
517 | + 'home_folder_naming_rule' => 'homeFolderNamingRule', |
|
518 | + 'ldap_turn_off_cert_check' => 'turnOffCertCheck', |
|
519 | + 'ldap_configuration_active' => 'ldapConfigurationActive', |
|
520 | + 'ldap_attributes_for_user_search' => 'ldapAttributesForUserSearch', |
|
521 | + 'ldap_attributes_for_group_search' => 'ldapAttributesForGroupSearch', |
|
522 | + 'ldap_expert_username_attr' => 'ldapExpertUsernameAttr', |
|
523 | + 'ldap_expert_uuid_user_attr' => 'ldapExpertUUIDUserAttr', |
|
524 | + 'ldap_expert_uuid_group_attr' => 'ldapExpertUUIDGroupAttr', |
|
525 | + 'has_memberof_filter_support' => 'hasMemberOfFilterSupport', |
|
526 | + 'use_memberof_to_detect_membership' => 'useMemberOfToDetectMembership', |
|
527 | + 'last_jpegPhoto_lookup' => 'lastJpegPhotoLookup', |
|
528 | + 'ldap_nested_groups' => 'ldapNestedGroups', |
|
529 | + 'ldap_paging_size' => 'ldapPagingSize', |
|
530 | + 'ldap_turn_on_pwd_change' => 'turnOnPasswordChange', |
|
531 | + 'ldap_experienced_admin' => 'ldapExperiencedAdmin', |
|
532 | + 'ldap_dynamic_group_member_url' => 'ldapDynamicGroupMemberURL', |
|
533 | + 'ldap_default_ppolicy_dn' => 'ldapDefaultPPolicyDN', |
|
534 | + ); |
|
535 | + return $array; |
|
536 | + } |
|
537 | 537 | |
538 | 538 | } |