@@ -63,9 +63,9 @@ |
||
63 | 63 | $configHolder->saveConfiguration(); |
64 | 64 | |
65 | 65 | $prose = ''; |
66 | - if(!$input->getOption('only-print-prefix')) { |
|
66 | + if (!$input->getOption('only-print-prefix')) { |
|
67 | 67 | $prose = 'Created new configuration with configID '; |
68 | 68 | } |
69 | - $output->writeln($prose . "{$configPrefix}"); |
|
69 | + $output->writeln($prose."{$configPrefix}"); |
|
70 | 70 | } |
71 | 71 | } |
@@ -67,9 +67,9 @@ discard block |
||
67 | 67 | protected function execute(InputInterface $input, OutputInterface $output) { |
68 | 68 | $availableConfigs = $this->helper->getServerConfigurationPrefixes(); |
69 | 69 | $configID = $input->getArgument('configID'); |
70 | - if(!is_null($configID)) { |
|
70 | + if (!is_null($configID)) { |
|
71 | 71 | $configIDs[] = $configID; |
72 | - if(!in_array($configIDs[0], $availableConfigs)) { |
|
72 | + if (!in_array($configIDs[0], $availableConfigs)) { |
|
73 | 73 | $output->writeln("Invalid configID"); |
74 | 74 | return; |
75 | 75 | } |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | * @param bool $withPassword Set to TRUE to show plaintext passwords in output |
88 | 88 | */ |
89 | 89 | protected function renderConfigs($configIDs, $output, $withPassword) { |
90 | - foreach($configIDs as $id) { |
|
90 | + foreach ($configIDs as $id) { |
|
91 | 91 | $configHolder = new Configuration($id); |
92 | 92 | $configuration = $configHolder->getConfiguration(); |
93 | 93 | ksort($configuration); |
@@ -95,11 +95,11 @@ discard block |
||
95 | 95 | $table = new Table($output); |
96 | 96 | $table->setHeaders(array('Configuration', $id)); |
97 | 97 | $rows = array(); |
98 | - foreach($configuration as $key => $value) { |
|
99 | - if($key === 'ldapAgentPassword' && !$withPassword) { |
|
98 | + foreach ($configuration as $key => $value) { |
|
99 | + if ($key === 'ldapAgentPassword' && !$withPassword) { |
|
100 | 100 | $value = '***'; |
101 | 101 | } |
102 | - if(is_array($value)) { |
|
102 | + if (is_array($value)) { |
|
103 | 103 | $value = implode(';', $value); |
104 | 104 | } |
105 | 105 | $rows[] = array($key, $value); |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | */ |
102 | 102 | public function __construct($configPrefix, $autoRead = true) { |
103 | 103 | $this->configPrefix = $configPrefix; |
104 | - if($autoRead) { |
|
104 | + if ($autoRead) { |
|
105 | 105 | $this->readConfiguration(); |
106 | 106 | } |
107 | 107 | } |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @return mixed|null |
112 | 112 | */ |
113 | 113 | public function __get($name) { |
114 | - if(isset($this->config[$name])) { |
|
114 | + if (isset($this->config[$name])) { |
|
115 | 115 | return $this->config[$name]; |
116 | 116 | } |
117 | 117 | return null; |
@@ -142,22 +142,22 @@ discard block |
||
142 | 142 | * @return false|null |
143 | 143 | */ |
144 | 144 | public function setConfiguration($config, &$applied = null) { |
145 | - if(!is_array($config)) { |
|
145 | + if (!is_array($config)) { |
|
146 | 146 | return false; |
147 | 147 | } |
148 | 148 | |
149 | 149 | $cta = $this->getConfigTranslationArray(); |
150 | - foreach($config as $inputKey => $val) { |
|
151 | - if(strpos($inputKey, '_') !== false && array_key_exists($inputKey, $cta)) { |
|
150 | + foreach ($config as $inputKey => $val) { |
|
151 | + if (strpos($inputKey, '_') !== false && array_key_exists($inputKey, $cta)) { |
|
152 | 152 | $key = $cta[$inputKey]; |
153 | - } elseif(array_key_exists($inputKey, $this->config)) { |
|
153 | + } elseif (array_key_exists($inputKey, $this->config)) { |
|
154 | 154 | $key = $inputKey; |
155 | 155 | } else { |
156 | 156 | continue; |
157 | 157 | } |
158 | 158 | |
159 | 159 | $setMethod = 'setValue'; |
160 | - switch($key) { |
|
160 | + switch ($key) { |
|
161 | 161 | case 'ldapAgentPassword': |
162 | 162 | $setMethod = 'setRawValue'; |
163 | 163 | break; |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | break; |
182 | 182 | } |
183 | 183 | $this->$setMethod($key, $val); |
184 | - if(is_array($applied)) { |
|
184 | + if (is_array($applied)) { |
|
185 | 185 | $applied[] = $inputKey; |
186 | 186 | } |
187 | 187 | } |
@@ -189,15 +189,15 @@ discard block |
||
189 | 189 | } |
190 | 190 | |
191 | 191 | public function readConfiguration() { |
192 | - if(!$this->configRead && !is_null($this->configPrefix)) { |
|
192 | + if (!$this->configRead && !is_null($this->configPrefix)) { |
|
193 | 193 | $cta = array_flip($this->getConfigTranslationArray()); |
194 | - foreach($this->config as $key => $val) { |
|
195 | - if(!isset($cta[$key])) { |
|
194 | + foreach ($this->config as $key => $val) { |
|
195 | + if (!isset($cta[$key])) { |
|
196 | 196 | //some are determined |
197 | 197 | continue; |
198 | 198 | } |
199 | 199 | $dbKey = $cta[$key]; |
200 | - switch($key) { |
|
200 | + switch ($key) { |
|
201 | 201 | case 'ldapBase': |
202 | 202 | case 'ldapBaseUsers': |
203 | 203 | case 'ldapBaseGroups': |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | */ |
241 | 241 | public function saveConfiguration() { |
242 | 242 | $cta = array_flip($this->getConfigTranslationArray()); |
243 | - foreach($this->config as $key => $value) { |
|
243 | + foreach ($this->config as $key => $value) { |
|
244 | 244 | switch ($key) { |
245 | 245 | case 'ldapAgentPassword': |
246 | 246 | $value = base64_encode($value); |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | case 'ldapGroupFilterObjectclass': |
256 | 256 | case 'ldapGroupFilterGroups': |
257 | 257 | case 'ldapLoginFilterAttributes': |
258 | - if(is_array($value)) { |
|
258 | + if (is_array($value)) { |
|
259 | 259 | $value = implode("\n", $value); |
260 | 260 | } |
261 | 261 | break; |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | case 'ldapUuidGroupAttribute': |
267 | 267 | continue 2; |
268 | 268 | } |
269 | - if(is_null($value)) { |
|
269 | + if (is_null($value)) { |
|
270 | 270 | $value = ''; |
271 | 271 | } |
272 | 272 | $this->saveValue($cta[$key], $value); |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | */ |
280 | 280 | protected function getMultiLine($varName) { |
281 | 281 | $value = $this->getValue($varName); |
282 | - if(empty($value)) { |
|
282 | + if (empty($value)) { |
|
283 | 283 | $value = ''; |
284 | 284 | } else { |
285 | 285 | $value = preg_split('/\r\n|\r|\n/', $value); |
@@ -295,21 +295,21 @@ discard block |
||
295 | 295 | * @param array|string $value to set |
296 | 296 | */ |
297 | 297 | protected function setMultiLine($varName, $value) { |
298 | - if(empty($value)) { |
|
298 | + if (empty($value)) { |
|
299 | 299 | $value = ''; |
300 | 300 | } else if (!is_array($value)) { |
301 | 301 | $value = preg_split('/\r\n|\r|\n|;/', $value); |
302 | - if($value === false) { |
|
302 | + if ($value === false) { |
|
303 | 303 | $value = ''; |
304 | 304 | } |
305 | 305 | } |
306 | 306 | |
307 | - if(!is_array($value)) { |
|
307 | + if (!is_array($value)) { |
|
308 | 308 | $finalValue = trim($value); |
309 | 309 | } else { |
310 | 310 | $finalValue = []; |
311 | - foreach($value as $key => $val) { |
|
312 | - if(is_string($val)) { |
|
311 | + foreach ($value as $key => $val) { |
|
312 | + if (is_string($val)) { |
|
313 | 313 | $val = trim($val); |
314 | 314 | if ($val !== '') { |
315 | 315 | //accidental line breaks are not wanted and can cause |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | */ |
357 | 357 | protected function getValue($varName) { |
358 | 358 | static $defaults; |
359 | - if(is_null($defaults)) { |
|
359 | + if (is_null($defaults)) { |
|
360 | 360 | $defaults = $this->getDefaults(); |
361 | 361 | } |
362 | 362 | return \OCP\Config::getAppValue('user_ldap', |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | * @param mixed $value to set |
372 | 372 | */ |
373 | 373 | protected function setValue($varName, $value) { |
374 | - if(is_string($value)) { |
|
374 | + if (is_string($value)) { |
|
375 | 375 | $value = trim($value); |
376 | 376 | } |
377 | 377 | $this->config[$varName] = $value; |
@@ -62,7 +62,7 @@ |
||
62 | 62 | // assign default values |
63 | 63 | $config = new Configuration('', false); |
64 | 64 | $defaults = $config->getDefaults(); |
65 | - foreach($defaults as $key => $default) { |
|
65 | + foreach ($defaults as $key => $default) { |
|
66 | 66 | $parameters[$key.'_default'] = $default; |
67 | 67 | } |
68 | 68 |
@@ -42,10 +42,10 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function __construct(array $serverConfigPrefixes, ILDAPWrapper $ldap, IConfig $ocConfig) { |
44 | 44 | parent::__construct($ldap); |
45 | - foreach($serverConfigPrefixes as $configPrefix) { |
|
45 | + foreach ($serverConfigPrefixes as $configPrefix) { |
|
46 | 46 | $this->backends[$configPrefix] = |
47 | 47 | new User_LDAP($this->getAccess($configPrefix), $ocConfig); |
48 | - if(is_null($this->refBackend)) { |
|
48 | + if (is_null($this->refBackend)) { |
|
49 | 49 | $this->refBackend = &$this->backends[$configPrefix]; |
50 | 50 | } |
51 | 51 | } |
@@ -60,13 +60,13 @@ discard block |
||
60 | 60 | */ |
61 | 61 | protected function walkBackends($uid, $method, $parameters) { |
62 | 62 | $cacheKey = $this->getUserCacheKey($uid); |
63 | - foreach($this->backends as $configPrefix => $backend) { |
|
63 | + foreach ($this->backends as $configPrefix => $backend) { |
|
64 | 64 | $instance = $backend; |
65 | - if(!method_exists($instance, $method) |
|
65 | + if (!method_exists($instance, $method) |
|
66 | 66 | && method_exists($this->getAccess($configPrefix), $method)) { |
67 | 67 | $instance = $this->getAccess($configPrefix); |
68 | 68 | } |
69 | - if($result = call_user_func_array(array($instance, $method), $parameters)) { |
|
69 | + if ($result = call_user_func_array(array($instance, $method), $parameters)) { |
|
70 | 70 | $this->writeToCache($cacheKey, $configPrefix); |
71 | 71 | return $result; |
72 | 72 | } |
@@ -86,22 +86,22 @@ discard block |
||
86 | 86 | $cacheKey = $this->getUserCacheKey($uid); |
87 | 87 | $prefix = $this->getFromCache($cacheKey); |
88 | 88 | //in case the uid has been found in the past, try this stored connection first |
89 | - if(!is_null($prefix)) { |
|
90 | - if(isset($this->backends[$prefix])) { |
|
89 | + if (!is_null($prefix)) { |
|
90 | + if (isset($this->backends[$prefix])) { |
|
91 | 91 | $instance = $this->backends[$prefix]; |
92 | - if(!method_exists($instance, $method) |
|
92 | + if (!method_exists($instance, $method) |
|
93 | 93 | && method_exists($this->getAccess($prefix), $method)) { |
94 | 94 | $instance = $this->getAccess($prefix); |
95 | 95 | } |
96 | 96 | $result = call_user_func_array(array($instance, $method), $parameters); |
97 | - if($result === $passOnWhen) { |
|
97 | + if ($result === $passOnWhen) { |
|
98 | 98 | //not found here, reset cache to null if user vanished |
99 | 99 | //because sometimes methods return false with a reason |
100 | 100 | $userExists = call_user_func_array( |
101 | 101 | array($this->backends[$prefix], 'userExists'), |
102 | 102 | array($uid) |
103 | 103 | ); |
104 | - if(!$userExists) { |
|
104 | + if (!$userExists) { |
|
105 | 105 | $this->writeToCache($cacheKey, null); |
106 | 106 | } |
107 | 107 | } |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | public function getUsers($search = '', $limit = 10, $offset = 0) { |
144 | 144 | //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends |
145 | 145 | $users = array(); |
146 | - foreach($this->backends as $backend) { |
|
146 | + foreach ($this->backends as $backend) { |
|
147 | 147 | $backendUsers = $backend->getUsers($search, $limit, $offset); |
148 | 148 | if (is_array($backendUsers)) { |
149 | 149 | $users = array_merge($users, $backendUsers); |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | * @return string|false |
192 | 192 | */ |
193 | 193 | public function loginName2UserName($loginName) { |
194 | - $id = 'LOGINNAME,' . $loginName; |
|
194 | + $id = 'LOGINNAME,'.$loginName; |
|
195 | 195 | return $this->handleRequest($id, 'loginName2UserName', array($loginName)); |
196 | 196 | } |
197 | 197 | |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | * @return string|false with the username |
203 | 203 | */ |
204 | 204 | public function dn2UserName($dn) { |
205 | - $id = 'DN,' . $dn; |
|
205 | + $id = 'DN,'.$dn; |
|
206 | 206 | return $this->handleRequest($id, 'dn2UserName', array($dn)); |
207 | 207 | } |
208 | 208 | |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | public function getDisplayNames($search = '', $limit = null, $offset = null) { |
244 | 244 | //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends |
245 | 245 | $users = array(); |
246 | - foreach($this->backends as $backend) { |
|
246 | + foreach ($this->backends as $backend) { |
|
247 | 247 | $backendUsers = $backend->getDisplayNames($search, $limit, $offset); |
248 | 248 | if (is_array($backendUsers)) { |
249 | 249 | $users = $users + $backendUsers; |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | */ |
288 | 288 | public function countUsers() { |
289 | 289 | $users = false; |
290 | - foreach($this->backends as $backend) { |
|
290 | + foreach ($this->backends as $backend) { |
|
291 | 291 | $backendUsers = $backend->countUsers(); |
292 | 292 | if ($backendUsers !== false) { |
293 | 293 | $users += $backendUsers; |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | $this->configuration = new Configuration($configPrefix, |
88 | 88 | !is_null($configID)); |
89 | 89 | $memcache = \OC::$server->getMemCacheFactory(); |
90 | - if($memcache->isAvailable()) { |
|
90 | + if ($memcache->isAvailable()) { |
|
91 | 91 | $this->cache = $memcache->create(); |
92 | 92 | } |
93 | 93 | $helper = new Helper(\OC::$server->getConfig()); |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | } |
100 | 100 | |
101 | 101 | public function __destruct() { |
102 | - if(!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) { |
|
102 | + if (!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) { |
|
103 | 103 | @$this->ldap->unbind($this->ldapConnectionRes); |
104 | 104 | }; |
105 | 105 | } |
@@ -119,11 +119,11 @@ discard block |
||
119 | 119 | * @return bool|mixed|void |
120 | 120 | */ |
121 | 121 | public function __get($name) { |
122 | - if(!$this->configured) { |
|
122 | + if (!$this->configured) { |
|
123 | 123 | $this->readConfiguration(); |
124 | 124 | } |
125 | 125 | |
126 | - if($name === 'hasPagedResultSupport') { |
|
126 | + if ($name === 'hasPagedResultSupport') { |
|
127 | 127 | return $this->hasPagedResultSupport; |
128 | 128 | } |
129 | 129 | |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | $before = $this->configuration->$name; |
140 | 140 | $this->configuration->$name = $value; |
141 | 141 | $after = $this->configuration->$name; |
142 | - if($before !== $after) { |
|
142 | + if ($before !== $after) { |
|
143 | 143 | if ($this->configID !== '') { |
144 | 144 | $this->configuration->saveConfiguration(); |
145 | 145 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @param bool $state |
155 | 155 | */ |
156 | 156 | public function setIgnoreValidation($state) { |
157 | - $this->ignoreValidation = (bool)$state; |
|
157 | + $this->ignoreValidation = (bool) $state; |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
@@ -170,14 +170,14 @@ discard block |
||
170 | 170 | * Returns the LDAP handler |
171 | 171 | */ |
172 | 172 | public function getConnectionResource() { |
173 | - if(!$this->ldapConnectionRes) { |
|
173 | + if (!$this->ldapConnectionRes) { |
|
174 | 174 | $this->init(); |
175 | - } else if(!$this->ldap->isResource($this->ldapConnectionRes)) { |
|
175 | + } else if (!$this->ldap->isResource($this->ldapConnectionRes)) { |
|
176 | 176 | $this->ldapConnectionRes = null; |
177 | 177 | $this->establishConnection(); |
178 | 178 | } |
179 | - if(is_null($this->ldapConnectionRes)) { |
|
180 | - \OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server ' . $this->configuration->ldapHost, \OCP\Util::ERROR); |
|
179 | + if (is_null($this->ldapConnectionRes)) { |
|
180 | + \OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server '.$this->configuration->ldapHost, \OCP\Util::ERROR); |
|
181 | 181 | throw new ServerNotAvailableException('Connection to LDAP server could not be established'); |
182 | 182 | } |
183 | 183 | return $this->ldapConnectionRes; |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * resets the connection resource |
188 | 188 | */ |
189 | 189 | public function resetConnectionResource() { |
190 | - if(!is_null($this->ldapConnectionRes)) { |
|
190 | + if (!is_null($this->ldapConnectionRes)) { |
|
191 | 191 | @$this->ldap->unbind($this->ldapConnectionRes); |
192 | 192 | $this->ldapConnectionRes = null; |
193 | 193 | } |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | */ |
200 | 200 | private function getCacheKey($key) { |
201 | 201 | $prefix = 'LDAP-'.$this->configID.'-'.$this->configPrefix.'-'; |
202 | - if(is_null($key)) { |
|
202 | + if (is_null($key)) { |
|
203 | 203 | return $prefix; |
204 | 204 | } |
205 | 205 | return $prefix.md5($key); |
@@ -210,10 +210,10 @@ discard block |
||
210 | 210 | * @return mixed|null |
211 | 211 | */ |
212 | 212 | public function getFromCache($key) { |
213 | - if(!$this->configured) { |
|
213 | + if (!$this->configured) { |
|
214 | 214 | $this->readConfiguration(); |
215 | 215 | } |
216 | - if(is_null($this->cache) || !$this->configuration->ldapCacheTTL) { |
|
216 | + if (is_null($this->cache) || !$this->configuration->ldapCacheTTL) { |
|
217 | 217 | return null; |
218 | 218 | } |
219 | 219 | $key = $this->getCacheKey($key); |
@@ -228,10 +228,10 @@ discard block |
||
228 | 228 | * @return string |
229 | 229 | */ |
230 | 230 | public function writeToCache($key, $value) { |
231 | - if(!$this->configured) { |
|
231 | + if (!$this->configured) { |
|
232 | 232 | $this->readConfiguration(); |
233 | 233 | } |
234 | - if(is_null($this->cache) |
|
234 | + if (is_null($this->cache) |
|
235 | 235 | || !$this->configuration->ldapCacheTTL |
236 | 236 | || !$this->configuration->ldapConfigurationActive) { |
237 | 237 | return null; |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | } |
243 | 243 | |
244 | 244 | public function clearCache() { |
245 | - if(!is_null($this->cache)) { |
|
245 | + if (!is_null($this->cache)) { |
|
246 | 246 | $this->cache->clear($this->getCacheKey(null)); |
247 | 247 | } |
248 | 248 | } |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | * @return null |
255 | 255 | */ |
256 | 256 | private function readConfiguration($force = false) { |
257 | - if((!$this->configured || $force) && !is_null($this->configID)) { |
|
257 | + if ((!$this->configured || $force) && !is_null($this->configID)) { |
|
258 | 258 | $this->configuration->readConfiguration(); |
259 | 259 | $this->configured = $this->validateConfiguration(); |
260 | 260 | } |
@@ -267,12 +267,12 @@ discard block |
||
267 | 267 | * @return boolean true if config validates, false otherwise. Check with $setParameters for detailed success on single parameters |
268 | 268 | */ |
269 | 269 | public function setConfiguration($config, &$setParameters = null) { |
270 | - if(is_null($setParameters)) { |
|
270 | + if (is_null($setParameters)) { |
|
271 | 271 | $setParameters = array(); |
272 | 272 | } |
273 | 273 | $this->doNotValidate = false; |
274 | 274 | $this->configuration->setConfiguration($config, $setParameters); |
275 | - if(count($setParameters) > 0) { |
|
275 | + if (count($setParameters) > 0) { |
|
276 | 276 | $this->configured = $this->validateConfiguration(); |
277 | 277 | } |
278 | 278 | |
@@ -299,10 +299,10 @@ discard block |
||
299 | 299 | $config = $this->configuration->getConfiguration(); |
300 | 300 | $cta = $this->configuration->getConfigTranslationArray(); |
301 | 301 | $result = array(); |
302 | - foreach($cta as $dbkey => $configkey) { |
|
303 | - switch($configkey) { |
|
302 | + foreach ($cta as $dbkey => $configkey) { |
|
303 | + switch ($configkey) { |
|
304 | 304 | case 'homeFolderNamingRule': |
305 | - if(strpos($config[$configkey], 'attr:') === 0) { |
|
305 | + if (strpos($config[$configkey], 'attr:') === 0) { |
|
306 | 306 | $result[$dbkey] = substr($config[$configkey], 5); |
307 | 307 | } else { |
308 | 308 | $result[$dbkey] = ''; |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | case 'ldapBaseGroups': |
314 | 314 | case 'ldapAttributesForUserSearch': |
315 | 315 | case 'ldapAttributesForGroupSearch': |
316 | - if(is_array($config[$configkey])) { |
|
316 | + if (is_array($config[$configkey])) { |
|
317 | 317 | $result[$dbkey] = implode("\n", $config[$configkey]); |
318 | 318 | break; |
319 | 319 | } //else follows default |
@@ -326,23 +326,23 @@ discard block |
||
326 | 326 | |
327 | 327 | private function doSoftValidation() { |
328 | 328 | //if User or Group Base are not set, take over Base DN setting |
329 | - foreach(array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) { |
|
329 | + foreach (array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) { |
|
330 | 330 | $val = $this->configuration->$keyBase; |
331 | - if(empty($val)) { |
|
331 | + if (empty($val)) { |
|
332 | 332 | $this->configuration->$keyBase = $this->configuration->ldapBase; |
333 | 333 | } |
334 | 334 | } |
335 | 335 | |
336 | - foreach(array('ldapExpertUUIDUserAttr' => 'ldapUuidUserAttribute', |
|
336 | + foreach (array('ldapExpertUUIDUserAttr' => 'ldapUuidUserAttribute', |
|
337 | 337 | 'ldapExpertUUIDGroupAttr' => 'ldapUuidGroupAttribute') |
338 | 338 | as $expertSetting => $effectiveSetting) { |
339 | 339 | $uuidOverride = $this->configuration->$expertSetting; |
340 | - if(!empty($uuidOverride)) { |
|
340 | + if (!empty($uuidOverride)) { |
|
341 | 341 | $this->configuration->$effectiveSetting = $uuidOverride; |
342 | 342 | } else { |
343 | 343 | $uuidAttributes = array('auto', 'entryuuid', 'nsuniqueid', |
344 | 344 | 'objectguid', 'guid', 'ipauniqueid'); |
345 | - if(!in_array($this->configuration->$effectiveSetting, |
|
345 | + if (!in_array($this->configuration->$effectiveSetting, |
|
346 | 346 | $uuidAttributes) |
347 | 347 | && (!is_null($this->configID))) { |
348 | 348 | $this->configuration->$effectiveSetting = 'auto'; |
@@ -364,14 +364,14 @@ discard block |
||
364 | 364 | //make sure empty search attributes are saved as simple, empty array |
365 | 365 | $saKeys = array('ldapAttributesForUserSearch', |
366 | 366 | 'ldapAttributesForGroupSearch'); |
367 | - foreach($saKeys as $key) { |
|
367 | + foreach ($saKeys as $key) { |
|
368 | 368 | $val = $this->configuration->$key; |
369 | - if(is_array($val) && count($val) === 1 && empty($val[0])) { |
|
369 | + if (is_array($val) && count($val) === 1 && empty($val[0])) { |
|
370 | 370 | $this->configuration->$key = array(); |
371 | 371 | } |
372 | 372 | } |
373 | 373 | |
374 | - if((stripos($this->configuration->ldapHost, 'ldaps://') === 0) |
|
374 | + if ((stripos($this->configuration->ldapHost, 'ldaps://') === 0) |
|
375 | 375 | && $this->configuration->ldapTLS) { |
376 | 376 | $this->configuration->ldapTLS = false; |
377 | 377 | \OCP\Util::writeLog('user_ldap', |
@@ -392,10 +392,10 @@ discard block |
||
392 | 392 | //options that shall not be empty |
393 | 393 | $options = array('ldapHost', 'ldapPort', 'ldapUserDisplayName', |
394 | 394 | 'ldapGroupDisplayName', 'ldapLoginFilter'); |
395 | - foreach($options as $key) { |
|
395 | + foreach ($options as $key) { |
|
396 | 396 | $val = $this->configuration->$key; |
397 | - if(empty($val)) { |
|
398 | - switch($key) { |
|
397 | + if (empty($val)) { |
|
398 | + switch ($key) { |
|
399 | 399 | case 'ldapHost': |
400 | 400 | $subj = 'LDAP Host'; |
401 | 401 | break; |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | $agent = $this->configuration->ldapAgentName; |
427 | 427 | $pwd = $this->configuration->ldapAgentPassword; |
428 | 428 | if ( |
429 | - ($agent === '' && $pwd !== '') |
|
429 | + ($agent === '' && $pwd !== '') |
|
430 | 430 | || ($agent !== '' && $pwd === '') |
431 | 431 | ) { |
432 | 432 | \OCP\Util::writeLog('user_ldap', |
@@ -441,14 +441,14 @@ discard block |
||
441 | 441 | $baseUsers = $this->configuration->ldapBaseUsers; |
442 | 442 | $baseGroups = $this->configuration->ldapBaseGroups; |
443 | 443 | |
444 | - if(empty($base) && empty($baseUsers) && empty($baseGroups)) { |
|
444 | + if (empty($base) && empty($baseUsers) && empty($baseGroups)) { |
|
445 | 445 | \OCP\Util::writeLog('user_ldap', |
446 | 446 | $errorStr.'Not a single Base DN given.', |
447 | 447 | \OCP\Util::WARN); |
448 | 448 | $configurationOK = false; |
449 | 449 | } |
450 | 450 | |
451 | - if(mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
451 | + if (mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8') |
|
452 | 452 | === false) { |
453 | 453 | \OCP\Util::writeLog('user_ldap', |
454 | 454 | $errorStr.'login filter does not contain %uid '. |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | */ |
467 | 467 | private function validateConfiguration() { |
468 | 468 | |
469 | - if($this->doNotValidate) { |
|
469 | + if ($this->doNotValidate) { |
|
470 | 470 | //don't do a validation if it is a new configuration with pure |
471 | 471 | //default values. Will be allowed on changes via __set or |
472 | 472 | //setConfiguration |
@@ -487,21 +487,21 @@ discard block |
||
487 | 487 | * Connects and Binds to LDAP |
488 | 488 | */ |
489 | 489 | private function establishConnection() { |
490 | - if(!$this->configuration->ldapConfigurationActive) { |
|
490 | + if (!$this->configuration->ldapConfigurationActive) { |
|
491 | 491 | return null; |
492 | 492 | } |
493 | 493 | static $phpLDAPinstalled = true; |
494 | - if(!$phpLDAPinstalled) { |
|
494 | + if (!$phpLDAPinstalled) { |
|
495 | 495 | return false; |
496 | 496 | } |
497 | - if(!$this->ignoreValidation && !$this->configured) { |
|
497 | + if (!$this->ignoreValidation && !$this->configured) { |
|
498 | 498 | \OCP\Util::writeLog('user_ldap', |
499 | 499 | 'Configuration is invalid, cannot connect', |
500 | 500 | \OCP\Util::WARN); |
501 | 501 | return false; |
502 | 502 | } |
503 | - if(!$this->ldapConnectionRes) { |
|
504 | - if(!$this->ldap->areLDAPFunctionsAvailable()) { |
|
503 | + if (!$this->ldapConnectionRes) { |
|
504 | + if (!$this->ldap->areLDAPFunctionsAvailable()) { |
|
505 | 505 | $phpLDAPinstalled = false; |
506 | 506 | \OCP\Util::writeLog('user_ldap', |
507 | 507 | 'function ldap_connect is not available. Make '. |
@@ -510,8 +510,8 @@ discard block |
||
510 | 510 | |
511 | 511 | return false; |
512 | 512 | } |
513 | - if($this->configuration->turnOffCertCheck) { |
|
514 | - if(putenv('LDAPTLS_REQCERT=never')) { |
|
513 | + if ($this->configuration->turnOffCertCheck) { |
|
514 | + if (putenv('LDAPTLS_REQCERT=never')) { |
|
515 | 515 | \OCP\Util::writeLog('user_ldap', |
516 | 516 | 'Turned off SSL certificate validation successfully.', |
517 | 517 | \OCP\Util::DEBUG); |
@@ -534,24 +534,24 @@ discard block |
||
534 | 534 | $error = $this->ldap->isResource($this->ldapConnectionRes) ? |
535 | 535 | $this->ldap->errno($this->ldapConnectionRes) : -1; |
536 | 536 | } |
537 | - if($bindStatus === true) { |
|
537 | + if ($bindStatus === true) { |
|
538 | 538 | return $bindStatus; |
539 | 539 | } |
540 | 540 | } catch (\OC\ServerNotAvailableException $e) { |
541 | - if(trim($this->configuration->ldapBackupHost) === "") { |
|
541 | + if (trim($this->configuration->ldapBackupHost) === "") { |
|
542 | 542 | throw $e; |
543 | 543 | } |
544 | 544 | } |
545 | 545 | |
546 | 546 | //if LDAP server is not reachable, try the Backup (Replica!) Server |
547 | - if( $error !== 0 |
|
547 | + if ($error !== 0 |
|
548 | 548 | || $this->configuration->ldapOverrideMainServer |
549 | 549 | || $this->getFromCache('overrideMainServer')) |
550 | 550 | { |
551 | 551 | $this->doConnect($this->configuration->ldapBackupHost, |
552 | 552 | $this->configuration->ldapBackupPort); |
553 | 553 | $bindStatus = $this->bind(); |
554 | - if($bindStatus && $error === -1 && !$this->getFromCache('overrideMainServer')) { |
|
554 | + if ($bindStatus && $error === -1 && !$this->getFromCache('overrideMainServer')) { |
|
555 | 555 | //when bind to backup server succeeded and failed to main server, |
556 | 556 | //skip contacting him until next cache refresh |
557 | 557 | $this->writeToCache('overrideMainServer', true); |
@@ -573,9 +573,9 @@ discard block |
||
573 | 573 | return false; |
574 | 574 | } |
575 | 575 | $this->ldapConnectionRes = $this->ldap->connect($host, $port); |
576 | - if($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) { |
|
577 | - if($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) { |
|
578 | - if($this->configuration->ldapTLS) { |
|
576 | + if ($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) { |
|
577 | + if ($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) { |
|
578 | + if ($this->configuration->ldapTLS) { |
|
579 | 579 | $this->ldap->startTls($this->ldapConnectionRes); |
580 | 580 | } |
581 | 581 | } |
@@ -590,25 +590,25 @@ discard block |
||
590 | 590 | */ |
591 | 591 | public function bind() { |
592 | 592 | static $getConnectionResourceAttempt = false; |
593 | - if(!$this->configuration->ldapConfigurationActive) { |
|
593 | + if (!$this->configuration->ldapConfigurationActive) { |
|
594 | 594 | return false; |
595 | 595 | } |
596 | - if($getConnectionResourceAttempt) { |
|
596 | + if ($getConnectionResourceAttempt) { |
|
597 | 597 | $getConnectionResourceAttempt = false; |
598 | 598 | return false; |
599 | 599 | } |
600 | 600 | $getConnectionResourceAttempt = true; |
601 | 601 | $cr = $this->getConnectionResource(); |
602 | 602 | $getConnectionResourceAttempt = false; |
603 | - if(!$this->ldap->isResource($cr)) { |
|
603 | + if (!$this->ldap->isResource($cr)) { |
|
604 | 604 | return false; |
605 | 605 | } |
606 | 606 | $ldapLogin = @$this->ldap->bind($cr, |
607 | 607 | $this->configuration->ldapAgentName, |
608 | 608 | $this->configuration->ldapAgentPassword); |
609 | - if(!$ldapLogin) { |
|
609 | + if (!$ldapLogin) { |
|
610 | 610 | \OCP\Util::writeLog('user_ldap', |
611 | - 'Bind failed: ' . $this->ldap->errno($cr) . ': ' . $this->ldap->error($cr), |
|
611 | + 'Bind failed: '.$this->ldap->errno($cr).': '.$this->ldap->error($cr), |
|
612 | 612 | \OCP\Util::WARN); |
613 | 613 | $this->ldapConnectionRes = null; |
614 | 614 | return false; |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * @return AbstractMapping |
111 | 111 | */ |
112 | 112 | public function getUserMapper() { |
113 | - if(is_null($this->userMapper)) { |
|
113 | + if (is_null($this->userMapper)) { |
|
114 | 114 | throw new \Exception('UserMapper was not assigned to this Access instance.'); |
115 | 115 | } |
116 | 116 | return $this->userMapper; |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | * @return AbstractMapping |
131 | 131 | */ |
132 | 132 | public function getGroupMapper() { |
133 | - if(is_null($this->groupMapper)) { |
|
133 | + if (is_null($this->groupMapper)) { |
|
134 | 134 | throw new \Exception('GroupMapper was not assigned to this Access instance.'); |
135 | 135 | } |
136 | 136 | return $this->groupMapper; |
@@ -161,14 +161,14 @@ discard block |
||
161 | 161 | * array if $attr is empty, false otherwise |
162 | 162 | */ |
163 | 163 | public function readAttribute($dn, $attr, $filter = 'objectClass=*') { |
164 | - if(!$this->checkConnection()) { |
|
164 | + if (!$this->checkConnection()) { |
|
165 | 165 | \OCP\Util::writeLog('user_ldap', |
166 | 166 | 'No LDAP Connector assigned, access impossible for readAttribute.', |
167 | 167 | \OCP\Util::WARN); |
168 | 168 | return false; |
169 | 169 | } |
170 | 170 | $cr = $this->connection->getConnectionResource(); |
171 | - if(!$this->ldap->isResource($cr)) { |
|
171 | + if (!$this->ldap->isResource($cr)) { |
|
172 | 172 | //LDAP not available |
173 | 173 | \OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', \OCP\Util::DEBUG); |
174 | 174 | return false; |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | $isRangeRequest = false; |
192 | 192 | do { |
193 | 193 | $result = $this->executeRead($cr, $dn, $attrToRead, $filter, $maxResults); |
194 | - if(is_bool($result)) { |
|
194 | + if (is_bool($result)) { |
|
195 | 195 | // when an exists request was run and it was successful, an empty |
196 | 196 | // array must be returned |
197 | 197 | return $result ? [] : false; |
@@ -208,22 +208,22 @@ discard block |
||
208 | 208 | $result = $this->extractRangeData($result, $attr); |
209 | 209 | if (!empty($result)) { |
210 | 210 | $normalizedResult = $this->extractAttributeValuesFromResult( |
211 | - [ $attr => $result['values'] ], |
|
211 | + [$attr => $result['values']], |
|
212 | 212 | $attr |
213 | 213 | ); |
214 | 214 | $values = array_merge($values, $normalizedResult); |
215 | 215 | |
216 | - if($result['rangeHigh'] === '*') { |
|
216 | + if ($result['rangeHigh'] === '*') { |
|
217 | 217 | // when server replies with * as high range value, there are |
218 | 218 | // no more results left |
219 | 219 | return $values; |
220 | 220 | } else { |
221 | - $low = $result['rangeHigh'] + 1; |
|
222 | - $attrToRead = $result['attributeName'] . ';range=' . $low . '-*'; |
|
221 | + $low = $result['rangeHigh'] + 1; |
|
222 | + $attrToRead = $result['attributeName'].';range='.$low.'-*'; |
|
223 | 223 | $isRangeRequest = true; |
224 | 224 | } |
225 | 225 | } |
226 | - } while($isRangeRequest); |
|
226 | + } while ($isRangeRequest); |
|
227 | 227 | |
228 | 228 | \OCP\Util::writeLog('user_ldap', 'Requested attribute '.$attr.' not found for '.$dn, \OCP\Util::DEBUG); |
229 | 229 | return false; |
@@ -248,13 +248,13 @@ discard block |
||
248 | 248 | if (!$this->ldap->isResource($rr)) { |
249 | 249 | if ($attribute !== '') { |
250 | 250 | //do not throw this message on userExists check, irritates |
251 | - \OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN ' . $dn, \OCP\Util::DEBUG); |
|
251 | + \OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN '.$dn, \OCP\Util::DEBUG); |
|
252 | 252 | } |
253 | 253 | //in case an error occurs , e.g. object does not exist |
254 | 254 | return false; |
255 | 255 | } |
256 | 256 | if ($attribute === '' && ($filter === 'objectclass=*' || $this->ldap->countEntries($cr, $rr) === 1)) { |
257 | - \OCP\Util::writeLog('user_ldap', 'readAttribute: ' . $dn . ' found', \OCP\Util::DEBUG); |
|
257 | + \OCP\Util::writeLog('user_ldap', 'readAttribute: '.$dn.' found', \OCP\Util::DEBUG); |
|
258 | 258 | return true; |
259 | 259 | } |
260 | 260 | $er = $this->ldap->firstEntry($cr, $rr); |
@@ -279,12 +279,12 @@ discard block |
||
279 | 279 | */ |
280 | 280 | public function extractAttributeValuesFromResult($result, $attribute) { |
281 | 281 | $values = []; |
282 | - if(isset($result[$attribute]) && $result[$attribute]['count'] > 0) { |
|
282 | + if (isset($result[$attribute]) && $result[$attribute]['count'] > 0) { |
|
283 | 283 | $lowercaseAttribute = strtolower($attribute); |
284 | - for($i=0;$i<$result[$attribute]['count'];$i++) { |
|
285 | - if($this->resemblesDN($attribute)) { |
|
284 | + for ($i = 0; $i < $result[$attribute]['count']; $i++) { |
|
285 | + if ($this->resemblesDN($attribute)) { |
|
286 | 286 | $values[] = $this->helper->sanitizeDN($result[$attribute][$i]); |
287 | - } elseif($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') { |
|
287 | + } elseif ($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') { |
|
288 | 288 | $values[] = $this->convertObjectGUID2Str($result[$attribute][$i]); |
289 | 289 | } else { |
290 | 290 | $values[] = $result[$attribute][$i]; |
@@ -306,10 +306,10 @@ discard block |
||
306 | 306 | */ |
307 | 307 | public function extractRangeData($result, $attribute) { |
308 | 308 | $keys = array_keys($result); |
309 | - foreach($keys as $key) { |
|
310 | - if($key !== $attribute && strpos($key, $attribute) === 0) { |
|
309 | + foreach ($keys as $key) { |
|
310 | + if ($key !== $attribute && strpos($key, $attribute) === 0) { |
|
311 | 311 | $queryData = explode(';', $key); |
312 | - if(strpos($queryData[1], 'range=') === 0) { |
|
312 | + if (strpos($queryData[1], 'range=') === 0) { |
|
313 | 313 | $high = substr($queryData[1], 1 + strpos($queryData[1], '-')); |
314 | 314 | $data = [ |
315 | 315 | 'values' => $result[$key], |
@@ -334,11 +334,11 @@ discard block |
||
334 | 334 | * @throws \Exception |
335 | 335 | */ |
336 | 336 | public function setPassword($userDN, $password) { |
337 | - if(intval($this->connection->turnOnPasswordChange) !== 1) { |
|
337 | + if (intval($this->connection->turnOnPasswordChange) !== 1) { |
|
338 | 338 | throw new \Exception('LDAP password changes are disabled.'); |
339 | 339 | } |
340 | 340 | $cr = $this->connection->getConnectionResource(); |
341 | - if(!$this->ldap->isResource($cr)) { |
|
341 | + if (!$this->ldap->isResource($cr)) { |
|
342 | 342 | //LDAP not available |
343 | 343 | \OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', \OCP\Util::DEBUG); |
344 | 344 | return false; |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | |
347 | 347 | try { |
348 | 348 | return $this->ldap->modReplace($cr, $userDN, $password); |
349 | - } catch(ConstraintViolationException $e) { |
|
349 | + } catch (ConstraintViolationException $e) { |
|
350 | 350 | throw new HintException('Password change rejected.', \OC::$server->getL10N('user_ldap')->t('Password change rejected. Hint: ').$e->getMessage(), $e->getCode()); |
351 | 351 | } |
352 | 352 | } |
@@ -388,17 +388,17 @@ discard block |
||
388 | 388 | */ |
389 | 389 | public function getDomainDNFromDN($dn) { |
390 | 390 | $allParts = $this->ldap->explodeDN($dn, 0); |
391 | - if($allParts === false) { |
|
391 | + if ($allParts === false) { |
|
392 | 392 | //not a valid DN |
393 | 393 | return ''; |
394 | 394 | } |
395 | 395 | $domainParts = array(); |
396 | 396 | $dcFound = false; |
397 | - foreach($allParts as $part) { |
|
398 | - if(!$dcFound && strpos($part, 'dc=') === 0) { |
|
397 | + foreach ($allParts as $part) { |
|
398 | + if (!$dcFound && strpos($part, 'dc=') === 0) { |
|
399 | 399 | $dcFound = true; |
400 | 400 | } |
401 | - if($dcFound) { |
|
401 | + if ($dcFound) { |
|
402 | 402 | $domainParts[] = $part; |
403 | 403 | } |
404 | 404 | } |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | |
426 | 426 | //Check whether the DN belongs to the Base, to avoid issues on multi- |
427 | 427 | //server setups |
428 | - if(is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
428 | + if (is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
429 | 429 | return $fdn; |
430 | 430 | } |
431 | 431 | |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | //To avoid bypassing the base DN settings under certain circumstances |
443 | 443 | //with the group support, check whether the provided DN matches one of |
444 | 444 | //the given Bases |
445 | - if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) { |
|
445 | + if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) { |
|
446 | 446 | return false; |
447 | 447 | } |
448 | 448 | |
@@ -459,11 +459,11 @@ discard block |
||
459 | 459 | */ |
460 | 460 | public function groupsMatchFilter($groupDNs) { |
461 | 461 | $validGroupDNs = []; |
462 | - foreach($groupDNs as $dn) { |
|
462 | + foreach ($groupDNs as $dn) { |
|
463 | 463 | $cacheKey = 'groupsMatchFilter-'.$dn; |
464 | 464 | $groupMatchFilter = $this->connection->getFromCache($cacheKey); |
465 | - if(!is_null($groupMatchFilter)) { |
|
466 | - if($groupMatchFilter) { |
|
465 | + if (!is_null($groupMatchFilter)) { |
|
466 | + if ($groupMatchFilter) { |
|
467 | 467 | $validGroupDNs[] = $dn; |
468 | 468 | } |
469 | 469 | continue; |
@@ -471,13 +471,13 @@ discard block |
||
471 | 471 | |
472 | 472 | // Check the base DN first. If this is not met already, we don't |
473 | 473 | // need to ask the server at all. |
474 | - if(!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) { |
|
474 | + if (!$this->isDNPartOfBase($dn, $this->connection->ldapBaseGroups)) { |
|
475 | 475 | $this->connection->writeToCache($cacheKey, false); |
476 | 476 | continue; |
477 | 477 | } |
478 | 478 | |
479 | 479 | $result = $this->readAttribute($dn, 'cn', $this->connection->ldapGroupFilter); |
480 | - if(is_array($result)) { |
|
480 | + if (is_array($result)) { |
|
481 | 481 | $this->connection->writeToCache($cacheKey, true); |
482 | 482 | $validGroupDNs[] = $dn; |
483 | 483 | } else { |
@@ -498,7 +498,7 @@ discard block |
||
498 | 498 | //To avoid bypassing the base DN settings under certain circumstances |
499 | 499 | //with the group support, check whether the provided DN matches one of |
500 | 500 | //the given Bases |
501 | - if(!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
501 | + if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) { |
|
502 | 502 | return false; |
503 | 503 | } |
504 | 504 | |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | * @return string|false with with the name to use in ownCloud |
514 | 514 | */ |
515 | 515 | public function dn2ocname($fdn, $ldapName = null, $isUser = true) { |
516 | - if($isUser) { |
|
516 | + if ($isUser) { |
|
517 | 517 | $mapper = $this->getUserMapper(); |
518 | 518 | $nameAttribute = $this->connection->ldapUserDisplayName; |
519 | 519 | } else { |
@@ -523,15 +523,15 @@ discard block |
||
523 | 523 | |
524 | 524 | //let's try to retrieve the ownCloud name from the mappings table |
525 | 525 | $ocName = $mapper->getNameByDN($fdn); |
526 | - if(is_string($ocName)) { |
|
526 | + if (is_string($ocName)) { |
|
527 | 527 | return $ocName; |
528 | 528 | } |
529 | 529 | |
530 | 530 | //second try: get the UUID and check if it is known. Then, update the DN and return the name. |
531 | 531 | $uuid = $this->getUUID($fdn, $isUser); |
532 | - if(is_string($uuid)) { |
|
532 | + if (is_string($uuid)) { |
|
533 | 533 | $ocName = $mapper->getNameByUUID($uuid); |
534 | - if(is_string($ocName)) { |
|
534 | + if (is_string($ocName)) { |
|
535 | 535 | $mapper->setDNbyUUID($fdn, $uuid); |
536 | 536 | return $ocName; |
537 | 537 | } |
@@ -541,16 +541,16 @@ discard block |
||
541 | 541 | return false; |
542 | 542 | } |
543 | 543 | |
544 | - if(is_null($ldapName)) { |
|
544 | + if (is_null($ldapName)) { |
|
545 | 545 | $ldapName = $this->readAttribute($fdn, $nameAttribute); |
546 | - if(!isset($ldapName[0]) && empty($ldapName[0])) { |
|
546 | + if (!isset($ldapName[0]) && empty($ldapName[0])) { |
|
547 | 547 | \OCP\Util::writeLog('user_ldap', 'No or empty name for '.$fdn.'.', \OCP\Util::INFO); |
548 | 548 | return false; |
549 | 549 | } |
550 | 550 | $ldapName = $ldapName[0]; |
551 | 551 | } |
552 | 552 | |
553 | - if($isUser) { |
|
553 | + if ($isUser) { |
|
554 | 554 | $usernameAttribute = strval($this->connection->ldapExpertUsernameAttr); |
555 | 555 | if ($usernameAttribute !== '') { |
556 | 556 | $username = $this->readAttribute($fdn, $usernameAttribute); |
@@ -569,9 +569,9 @@ discard block |
||
569 | 569 | // outside of core user management will still cache the user as non-existing. |
570 | 570 | $originalTTL = $this->connection->ldapCacheTTL; |
571 | 571 | $this->connection->setConfiguration(array('ldapCacheTTL' => 0)); |
572 | - if(($isUser && !\OCP\User::userExists($intName)) |
|
572 | + if (($isUser && !\OCP\User::userExists($intName)) |
|
573 | 573 | || (!$isUser && !\OC_Group::groupExists($intName))) { |
574 | - if($mapper->map($fdn, $intName, $uuid)) { |
|
574 | + if ($mapper->map($fdn, $intName, $uuid)) { |
|
575 | 575 | $this->connection->setConfiguration(array('ldapCacheTTL' => $originalTTL)); |
576 | 576 | return $intName; |
577 | 577 | } |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | $this->connection->setConfiguration(array('ldapCacheTTL' => $originalTTL)); |
580 | 580 | |
581 | 581 | $altName = $this->createAltInternalOwnCloudName($intName, $isUser); |
582 | - if(is_string($altName) && $mapper->map($fdn, $altName, $uuid)) { |
|
582 | + if (is_string($altName) && $mapper->map($fdn, $altName, $uuid)) { |
|
583 | 583 | return $altName; |
584 | 584 | } |
585 | 585 | |
@@ -616,7 +616,7 @@ discard block |
||
616 | 616 | * @return array |
617 | 617 | */ |
618 | 618 | private function ldap2ownCloudNames($ldapObjects, $isUsers) { |
619 | - if($isUsers) { |
|
619 | + if ($isUsers) { |
|
620 | 620 | $nameAttribute = $this->connection->ldapUserDisplayName; |
621 | 621 | $sndAttribute = $this->connection->ldapUserDisplayName2; |
622 | 622 | } else { |
@@ -624,9 +624,9 @@ discard block |
||
624 | 624 | } |
625 | 625 | $ownCloudNames = array(); |
626 | 626 | |
627 | - foreach($ldapObjects as $ldapObject) { |
|
627 | + foreach ($ldapObjects as $ldapObject) { |
|
628 | 628 | $nameByLDAP = null; |
629 | - if( isset($ldapObject[$nameAttribute]) |
|
629 | + if (isset($ldapObject[$nameAttribute]) |
|
630 | 630 | && is_array($ldapObject[$nameAttribute]) |
631 | 631 | && isset($ldapObject[$nameAttribute][0]) |
632 | 632 | ) { |
@@ -635,12 +635,12 @@ discard block |
||
635 | 635 | } |
636 | 636 | |
637 | 637 | $ocName = $this->dn2ocname($ldapObject['dn'][0], $nameByLDAP, $isUsers); |
638 | - if($ocName) { |
|
638 | + if ($ocName) { |
|
639 | 639 | $ownCloudNames[] = $ocName; |
640 | - if($isUsers) { |
|
640 | + if ($isUsers) { |
|
641 | 641 | //cache the user names so it does not need to be retrieved |
642 | 642 | //again later (e.g. sharing dialogue). |
643 | - if(is_null($nameByLDAP)) { |
|
643 | + if (is_null($nameByLDAP)) { |
|
644 | 644 | continue; |
645 | 645 | } |
646 | 646 | $sndName = isset($ldapObject[$sndAttribute][0]) |
@@ -678,7 +678,7 @@ discard block |
||
678 | 678 | */ |
679 | 679 | public function cacheUserDisplayName($ocName, $displayName, $displayName2 = '') { |
680 | 680 | $user = $this->userManager->get($ocName); |
681 | - if($user === null) { |
|
681 | + if ($user === null) { |
|
682 | 682 | return; |
683 | 683 | } |
684 | 684 | $displayName = $user->composeAndStoreDisplayName($displayName, $displayName2); |
@@ -698,9 +698,9 @@ discard block |
||
698 | 698 | $attempts = 0; |
699 | 699 | //while loop is just a precaution. If a name is not generated within |
700 | 700 | //20 attempts, something else is very wrong. Avoids infinite loop. |
701 | - while($attempts < 20){ |
|
702 | - $altName = $name . '_' . rand(1000,9999); |
|
703 | - if(!\OCP\User::userExists($altName)) { |
|
701 | + while ($attempts < 20) { |
|
702 | + $altName = $name.'_'.rand(1000, 9999); |
|
703 | + if (!\OCP\User::userExists($altName)) { |
|
704 | 704 | return $altName; |
705 | 705 | } |
706 | 706 | $attempts++; |
@@ -722,25 +722,25 @@ discard block |
||
722 | 722 | */ |
723 | 723 | private function _createAltInternalOwnCloudNameForGroups($name) { |
724 | 724 | $usedNames = $this->groupMapper->getNamesBySearch($name, "", '_%'); |
725 | - if(!($usedNames) || count($usedNames) === 0) { |
|
725 | + if (!($usedNames) || count($usedNames) === 0) { |
|
726 | 726 | $lastNo = 1; //will become name_2 |
727 | 727 | } else { |
728 | 728 | natsort($usedNames); |
729 | 729 | $lastName = array_pop($usedNames); |
730 | 730 | $lastNo = intval(substr($lastName, strrpos($lastName, '_') + 1)); |
731 | 731 | } |
732 | - $altName = $name.'_'.strval($lastNo+1); |
|
732 | + $altName = $name.'_'.strval($lastNo + 1); |
|
733 | 733 | unset($usedNames); |
734 | 734 | |
735 | 735 | $attempts = 1; |
736 | - while($attempts < 21){ |
|
736 | + while ($attempts < 21) { |
|
737 | 737 | // Check to be really sure it is unique |
738 | 738 | // while loop is just a precaution. If a name is not generated within |
739 | 739 | // 20 attempts, something else is very wrong. Avoids infinite loop. |
740 | - if(!\OC_Group::groupExists($altName)) { |
|
740 | + if (!\OC_Group::groupExists($altName)) { |
|
741 | 741 | return $altName; |
742 | 742 | } |
743 | - $altName = $name . '_' . ($lastNo + $attempts); |
|
743 | + $altName = $name.'_'.($lastNo + $attempts); |
|
744 | 744 | $attempts++; |
745 | 745 | } |
746 | 746 | return false; |
@@ -755,7 +755,7 @@ discard block |
||
755 | 755 | private function createAltInternalOwnCloudName($name, $isUser) { |
756 | 756 | $originalTTL = $this->connection->ldapCacheTTL; |
757 | 757 | $this->connection->setConfiguration(array('ldapCacheTTL' => 0)); |
758 | - if($isUser) { |
|
758 | + if ($isUser) { |
|
759 | 759 | $altName = $this->_createAltInternalOwnCloudNameForUsers($name); |
760 | 760 | } else { |
761 | 761 | $altName = $this->_createAltInternalOwnCloudNameForGroups($name); |
@@ -813,20 +813,20 @@ discard block |
||
813 | 813 | * and their values |
814 | 814 | * @param array $ldapRecords |
815 | 815 | */ |
816 | - public function batchApplyUserAttributes(array $ldapRecords){ |
|
816 | + public function batchApplyUserAttributes(array $ldapRecords) { |
|
817 | 817 | $displayNameAttribute = strtolower($this->connection->ldapUserDisplayName); |
818 | - foreach($ldapRecords as $userRecord) { |
|
819 | - if(!isset($userRecord[$displayNameAttribute])) { |
|
818 | + foreach ($ldapRecords as $userRecord) { |
|
819 | + if (!isset($userRecord[$displayNameAttribute])) { |
|
820 | 820 | // displayName is obligatory |
821 | 821 | continue; |
822 | 822 | } |
823 | - $ocName = $this->dn2ocname($userRecord['dn'][0]); |
|
824 | - if($ocName === false) { |
|
823 | + $ocName = $this->dn2ocname($userRecord['dn'][0]); |
|
824 | + if ($ocName === false) { |
|
825 | 825 | continue; |
826 | 826 | } |
827 | 827 | $this->cacheUserExists($ocName); |
828 | 828 | $user = $this->userManager->get($ocName); |
829 | - if($user instanceof OfflineUser) { |
|
829 | + if ($user instanceof OfflineUser) { |
|
830 | 830 | $user->unmark(); |
831 | 831 | $user = $this->userManager->get($ocName); |
832 | 832 | } |
@@ -858,8 +858,8 @@ discard block |
||
858 | 858 | * @return array |
859 | 859 | */ |
860 | 860 | private function fetchList($list, $manyAttributes) { |
861 | - if(is_array($list)) { |
|
862 | - if($manyAttributes) { |
|
861 | + if (is_array($list)) { |
|
862 | + if ($manyAttributes) { |
|
863 | 863 | return $list; |
864 | 864 | } else { |
865 | 865 | $list = array_reduce($list, function($carry, $item) { |
@@ -945,13 +945,13 @@ discard block |
||
945 | 945 | * second | false if not successful |
946 | 946 | */ |
947 | 947 | private function executeSearch($filter, $base, &$attr = null, $limit = null, $offset = null) { |
948 | - if(!is_null($attr) && !is_array($attr)) { |
|
948 | + if (!is_null($attr) && !is_array($attr)) { |
|
949 | 949 | $attr = array(mb_strtolower($attr, 'UTF-8')); |
950 | 950 | } |
951 | 951 | |
952 | 952 | // See if we have a resource, in case not cancel with message |
953 | 953 | $cr = $this->connection->getConnectionResource(); |
954 | - if(!$this->ldap->isResource($cr)) { |
|
954 | + if (!$this->ldap->isResource($cr)) { |
|
955 | 955 | // Seems like we didn't find any resource. |
956 | 956 | // Return an empty array just like before. |
957 | 957 | \OCP\Util::writeLog('user_ldap', 'Could not search, because resource is missing.', \OCP\Util::DEBUG); |
@@ -964,7 +964,7 @@ discard block |
||
964 | 964 | $linkResources = array_pad(array(), count($base), $cr); |
965 | 965 | $sr = $this->ldap->search($linkResources, $base, $filter, $attr); |
966 | 966 | $error = $this->ldap->errno($cr); |
967 | - if(!is_array($sr) || $error !== 0) { |
|
967 | + if (!is_array($sr) || $error !== 0) { |
|
968 | 968 | \OCP\Util::writeLog('user_ldap', 'Attempt for Paging? '.print_r($pagedSearchOK, true), \OCP\Util::ERROR); |
969 | 969 | return false; |
970 | 970 | } |
@@ -987,26 +987,26 @@ discard block |
||
987 | 987 | */ |
988 | 988 | private function processPagedSearchStatus($sr, $filter, $base, $iFoundItems, $limit, $offset, $pagedSearchOK, $skipHandling) { |
989 | 989 | $cookie = null; |
990 | - if($pagedSearchOK) { |
|
990 | + if ($pagedSearchOK) { |
|
991 | 991 | $cr = $this->connection->getConnectionResource(); |
992 | - foreach($sr as $key => $res) { |
|
993 | - if($this->ldap->controlPagedResultResponse($cr, $res, $cookie)) { |
|
992 | + foreach ($sr as $key => $res) { |
|
993 | + if ($this->ldap->controlPagedResultResponse($cr, $res, $cookie)) { |
|
994 | 994 | $this->setPagedResultCookie($base[$key], $filter, $limit, $offset, $cookie); |
995 | 995 | } |
996 | 996 | } |
997 | 997 | |
998 | 998 | //browsing through prior pages to get the cookie for the new one |
999 | - if($skipHandling) { |
|
999 | + if ($skipHandling) { |
|
1000 | 1000 | return false; |
1001 | 1001 | } |
1002 | 1002 | // if count is bigger, then the server does not support |
1003 | 1003 | // paged search. Instead, he did a normal search. We set a |
1004 | 1004 | // flag here, so the callee knows how to deal with it. |
1005 | - if($iFoundItems <= $limit) { |
|
1005 | + if ($iFoundItems <= $limit) { |
|
1006 | 1006 | $this->pagedSearchedSuccessful = true; |
1007 | 1007 | } |
1008 | 1008 | } else { |
1009 | - if(!is_null($limit)) { |
|
1009 | + if (!is_null($limit)) { |
|
1010 | 1010 | \OCP\Util::writeLog('user_ldap', 'Paged search was not available', \OCP\Util::INFO); |
1011 | 1011 | } |
1012 | 1012 | } |
@@ -1035,7 +1035,7 @@ discard block |
||
1035 | 1035 | \OCP\Util::writeLog('user_ldap', 'Count filter: '.print_r($filter, true), \OCP\Util::DEBUG); |
1036 | 1036 | |
1037 | 1037 | $limitPerPage = intval($this->connection->ldapPagingSize); |
1038 | - if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) { |
|
1038 | + if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) { |
|
1039 | 1039 | $limitPerPage = $limit; |
1040 | 1040 | } |
1041 | 1041 | |
@@ -1046,7 +1046,7 @@ discard block |
||
1046 | 1046 | do { |
1047 | 1047 | $search = $this->executeSearch($filter, $base, $attr, |
1048 | 1048 | $limitPerPage, $offset); |
1049 | - if($search === false) { |
|
1049 | + if ($search === false) { |
|
1050 | 1050 | return $counter > 0 ? $counter : false; |
1051 | 1051 | } |
1052 | 1052 | list($sr, $pagedSearchOK) = $search; |
@@ -1065,7 +1065,7 @@ discard block |
||
1065 | 1065 | * Continue now depends on $hasMorePages value |
1066 | 1066 | */ |
1067 | 1067 | $continue = $pagedSearchOK && $hasMorePages; |
1068 | - } while($continue && (is_null($limit) || $limit <= 0 || $limit > $counter)); |
|
1068 | + } while ($continue && (is_null($limit) || $limit <= 0 || $limit > $counter)); |
|
1069 | 1069 | |
1070 | 1070 | return $counter; |
1071 | 1071 | } |
@@ -1078,7 +1078,7 @@ discard block |
||
1078 | 1078 | $cr = $this->connection->getConnectionResource(); |
1079 | 1079 | $counter = 0; |
1080 | 1080 | |
1081 | - foreach($searchResults as $res) { |
|
1081 | + foreach ($searchResults as $res) { |
|
1082 | 1082 | $count = intval($this->ldap->countEntries($cr, $res)); |
1083 | 1083 | $counter += $count; |
1084 | 1084 | } |
@@ -1097,7 +1097,7 @@ discard block |
||
1097 | 1097 | * @return array with the search result |
1098 | 1098 | */ |
1099 | 1099 | private function search($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) { |
1100 | - if($limit <= 0) { |
|
1100 | + if ($limit <= 0) { |
|
1101 | 1101 | //otherwise search will fail |
1102 | 1102 | $limit = null; |
1103 | 1103 | } |
@@ -1112,13 +1112,13 @@ discard block |
||
1112 | 1112 | $savedoffset = $offset; |
1113 | 1113 | do { |
1114 | 1114 | $search = $this->executeSearch($filter, $base, $attr, $limit, $offset); |
1115 | - if($search === false) { |
|
1115 | + if ($search === false) { |
|
1116 | 1116 | return array(); |
1117 | 1117 | } |
1118 | 1118 | list($sr, $pagedSearchOK) = $search; |
1119 | 1119 | $cr = $this->connection->getConnectionResource(); |
1120 | 1120 | |
1121 | - if($skipHandling) { |
|
1121 | + if ($skipHandling) { |
|
1122 | 1122 | //i.e. result do not need to be fetched, we just need the cookie |
1123 | 1123 | //thus pass 1 or any other value as $iFoundItems because it is not |
1124 | 1124 | //used |
@@ -1128,8 +1128,8 @@ discard block |
||
1128 | 1128 | return array(); |
1129 | 1129 | } |
1130 | 1130 | |
1131 | - foreach($sr as $res) { |
|
1132 | - $findings = array_merge($findings, $this->ldap->getEntries($cr , $res )); |
|
1131 | + foreach ($sr as $res) { |
|
1132 | + $findings = array_merge($findings, $this->ldap->getEntries($cr, $res)); |
|
1133 | 1133 | } |
1134 | 1134 | |
1135 | 1135 | $continue = $this->processPagedSearchStatus($sr, $filter, $base, $findings['count'], |
@@ -1142,25 +1142,25 @@ discard block |
||
1142 | 1142 | |
1143 | 1143 | // if we're here, probably no connection resource is returned. |
1144 | 1144 | // to make ownCloud behave nicely, we simply give back an empty array. |
1145 | - if(is_null($findings)) { |
|
1145 | + if (is_null($findings)) { |
|
1146 | 1146 | return array(); |
1147 | 1147 | } |
1148 | 1148 | |
1149 | - if(!is_null($attr)) { |
|
1149 | + if (!is_null($attr)) { |
|
1150 | 1150 | $selection = array(); |
1151 | 1151 | $i = 0; |
1152 | - foreach($findings as $item) { |
|
1153 | - if(!is_array($item)) { |
|
1152 | + foreach ($findings as $item) { |
|
1153 | + if (!is_array($item)) { |
|
1154 | 1154 | continue; |
1155 | 1155 | } |
1156 | 1156 | $item = \OCP\Util::mb_array_change_key_case($item, MB_CASE_LOWER, 'UTF-8'); |
1157 | - foreach($attr as $key) { |
|
1157 | + foreach ($attr as $key) { |
|
1158 | 1158 | $key = mb_strtolower($key, 'UTF-8'); |
1159 | - if(isset($item[$key])) { |
|
1160 | - if(is_array($item[$key]) && isset($item[$key]['count'])) { |
|
1159 | + if (isset($item[$key])) { |
|
1160 | + if (is_array($item[$key]) && isset($item[$key]['count'])) { |
|
1161 | 1161 | unset($item[$key]['count']); |
1162 | 1162 | } |
1163 | - if($key !== 'dn') { |
|
1163 | + if ($key !== 'dn') { |
|
1164 | 1164 | $selection[$i][$key] = $this->resemblesDN($key) ? |
1165 | 1165 | $this->helper->sanitizeDN($item[$key]) |
1166 | 1166 | : $item[$key]; |
@@ -1177,7 +1177,7 @@ discard block |
||
1177 | 1177 | //we slice the findings, when |
1178 | 1178 | //a) paged search unsuccessful, though attempted |
1179 | 1179 | //b) no paged search, but limit set |
1180 | - if((!$this->getPagedSearchResultState() |
|
1180 | + if ((!$this->getPagedSearchResultState() |
|
1181 | 1181 | && $pagedSearchOK) |
1182 | 1182 | || ( |
1183 | 1183 | !$pagedSearchOK |
@@ -1194,7 +1194,7 @@ discard block |
||
1194 | 1194 | * @return bool|mixed|string |
1195 | 1195 | */ |
1196 | 1196 | public function sanitizeUsername($name) { |
1197 | - if($this->connection->ldapIgnoreNamingRules) { |
|
1197 | + if ($this->connection->ldapIgnoreNamingRules) { |
|
1198 | 1198 | return $name; |
1199 | 1199 | } |
1200 | 1200 | |
@@ -1219,13 +1219,13 @@ discard block |
||
1219 | 1219 | */ |
1220 | 1220 | public function escapeFilterPart($input, $allowAsterisk = false) { |
1221 | 1221 | $asterisk = ''; |
1222 | - if($allowAsterisk && strlen($input) > 0 && $input[0] === '*') { |
|
1222 | + if ($allowAsterisk && strlen($input) > 0 && $input[0] === '*') { |
|
1223 | 1223 | $asterisk = '*'; |
1224 | 1224 | $input = mb_substr($input, 1, null, 'UTF-8'); |
1225 | 1225 | } |
1226 | 1226 | $search = array('*', '\\', '(', ')'); |
1227 | 1227 | $replace = array('\\*', '\\\\', '\\(', '\\)'); |
1228 | - return $asterisk . str_replace($search, $replace, $input); |
|
1228 | + return $asterisk.str_replace($search, $replace, $input); |
|
1229 | 1229 | } |
1230 | 1230 | |
1231 | 1231 | /** |
@@ -1255,13 +1255,13 @@ discard block |
||
1255 | 1255 | */ |
1256 | 1256 | private function combineFilter($filters, $operator) { |
1257 | 1257 | $combinedFilter = '('.$operator; |
1258 | - foreach($filters as $filter) { |
|
1258 | + foreach ($filters as $filter) { |
|
1259 | 1259 | if ($filter !== '' && $filter[0] !== '(') { |
1260 | 1260 | $filter = '('.$filter.')'; |
1261 | 1261 | } |
1262 | - $combinedFilter.=$filter; |
|
1262 | + $combinedFilter .= $filter; |
|
1263 | 1263 | } |
1264 | - $combinedFilter.=')'; |
|
1264 | + $combinedFilter .= ')'; |
|
1265 | 1265 | return $combinedFilter; |
1266 | 1266 | } |
1267 | 1267 | |
@@ -1297,17 +1297,17 @@ discard block |
||
1297 | 1297 | * @throws \Exception |
1298 | 1298 | */ |
1299 | 1299 | private function getAdvancedFilterPartForSearch($search, $searchAttributes) { |
1300 | - if(!is_array($searchAttributes) || count($searchAttributes) < 2) { |
|
1300 | + if (!is_array($searchAttributes) || count($searchAttributes) < 2) { |
|
1301 | 1301 | throw new \Exception('searchAttributes must be an array with at least two string'); |
1302 | 1302 | } |
1303 | 1303 | $searchWords = explode(' ', trim($search)); |
1304 | 1304 | $wordFilters = array(); |
1305 | - foreach($searchWords as $word) { |
|
1305 | + foreach ($searchWords as $word) { |
|
1306 | 1306 | $word = $this->prepareSearchTerm($word); |
1307 | 1307 | //every word needs to appear at least once |
1308 | 1308 | $wordMatchOneAttrFilters = array(); |
1309 | - foreach($searchAttributes as $attr) { |
|
1310 | - $wordMatchOneAttrFilters[] = $attr . '=' . $word; |
|
1309 | + foreach ($searchAttributes as $attr) { |
|
1310 | + $wordMatchOneAttrFilters[] = $attr.'='.$word; |
|
1311 | 1311 | } |
1312 | 1312 | $wordFilters[] = $this->combineFilterWithOr($wordMatchOneAttrFilters); |
1313 | 1313 | } |
@@ -1325,10 +1325,10 @@ discard block |
||
1325 | 1325 | private function getFilterPartForSearch($search, $searchAttributes, $fallbackAttribute) { |
1326 | 1326 | $filter = array(); |
1327 | 1327 | $haveMultiSearchAttributes = (is_array($searchAttributes) && count($searchAttributes) > 0); |
1328 | - if($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) { |
|
1328 | + if ($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) { |
|
1329 | 1329 | try { |
1330 | 1330 | return $this->getAdvancedFilterPartForSearch($search, $searchAttributes); |
1331 | - } catch(\Exception $e) { |
|
1331 | + } catch (\Exception $e) { |
|
1332 | 1332 | \OCP\Util::writeLog( |
1333 | 1333 | 'user_ldap', |
1334 | 1334 | 'Creating advanced filter for search failed, falling back to simple method.', |
@@ -1338,17 +1338,17 @@ discard block |
||
1338 | 1338 | } |
1339 | 1339 | |
1340 | 1340 | $search = $this->prepareSearchTerm($search); |
1341 | - if(!is_array($searchAttributes) || count($searchAttributes) === 0) { |
|
1341 | + if (!is_array($searchAttributes) || count($searchAttributes) === 0) { |
|
1342 | 1342 | if ($fallbackAttribute === '') { |
1343 | 1343 | return ''; |
1344 | 1344 | } |
1345 | - $filter[] = $fallbackAttribute . '=' . $search; |
|
1345 | + $filter[] = $fallbackAttribute.'='.$search; |
|
1346 | 1346 | } else { |
1347 | - foreach($searchAttributes as $attribute) { |
|
1348 | - $filter[] = $attribute . '=' . $search; |
|
1347 | + foreach ($searchAttributes as $attribute) { |
|
1348 | + $filter[] = $attribute.'='.$search; |
|
1349 | 1349 | } |
1350 | 1350 | } |
1351 | - if(count($filter) === 1) { |
|
1351 | + if (count($filter) === 1) { |
|
1352 | 1352 | return '('.$filter[0].')'; |
1353 | 1353 | } |
1354 | 1354 | return $this->combineFilterWithOr($filter); |
@@ -1369,7 +1369,7 @@ discard block |
||
1369 | 1369 | if ($term === '') { |
1370 | 1370 | $result = '*'; |
1371 | 1371 | } else if ($allowEnum !== 'no') { |
1372 | - $result = $term . '*'; |
|
1372 | + $result = $term.'*'; |
|
1373 | 1373 | } |
1374 | 1374 | return $result; |
1375 | 1375 | } |
@@ -1381,7 +1381,7 @@ discard block |
||
1381 | 1381 | public function getFilterForUserCount() { |
1382 | 1382 | $filter = $this->combineFilterWithAnd(array( |
1383 | 1383 | $this->connection->ldapUserFilter, |
1384 | - $this->connection->ldapUserDisplayName . '=*' |
|
1384 | + $this->connection->ldapUserDisplayName.'=*' |
|
1385 | 1385 | )); |
1386 | 1386 | |
1387 | 1387 | return $filter; |
@@ -1399,7 +1399,7 @@ discard block |
||
1399 | 1399 | 'ldapAgentName' => $name, |
1400 | 1400 | 'ldapAgentPassword' => $password |
1401 | 1401 | ); |
1402 | - if(!$testConnection->setConfiguration($credentials)) { |
|
1402 | + if (!$testConnection->setConfiguration($credentials)) { |
|
1403 | 1403 | return false; |
1404 | 1404 | } |
1405 | 1405 | return $testConnection->bind(); |
@@ -1421,30 +1421,30 @@ discard block |
||
1421 | 1421 | // Sacrebleu! The UUID attribute is unknown :( We need first an |
1422 | 1422 | // existing DN to be able to reliably detect it. |
1423 | 1423 | $result = $this->search($filter, $base, ['dn'], 1); |
1424 | - if(!isset($result[0]) || !isset($result[0]['dn'])) { |
|
1424 | + if (!isset($result[0]) || !isset($result[0]['dn'])) { |
|
1425 | 1425 | throw new \Exception('Cannot determine UUID attribute'); |
1426 | 1426 | } |
1427 | 1427 | $dn = $result[0]['dn'][0]; |
1428 | - if(!$this->detectUuidAttribute($dn, true)) { |
|
1428 | + if (!$this->detectUuidAttribute($dn, true)) { |
|
1429 | 1429 | throw new \Exception('Cannot determine UUID attribute'); |
1430 | 1430 | } |
1431 | 1431 | } else { |
1432 | 1432 | // The UUID attribute is either known or an override is given. |
1433 | 1433 | // By calling this method we ensure that $this->connection->$uuidAttr |
1434 | 1434 | // is definitely set |
1435 | - if(!$this->detectUuidAttribute('', true)) { |
|
1435 | + if (!$this->detectUuidAttribute('', true)) { |
|
1436 | 1436 | throw new \Exception('Cannot determine UUID attribute'); |
1437 | 1437 | } |
1438 | 1438 | } |
1439 | 1439 | |
1440 | 1440 | $uuidAttr = $this->connection->ldapUuidUserAttribute; |
1441 | - if($uuidAttr === 'guid' || $uuidAttr === 'objectguid') { |
|
1441 | + if ($uuidAttr === 'guid' || $uuidAttr === 'objectguid') { |
|
1442 | 1442 | $uuid = $this->formatGuid2ForFilterUser($uuid); |
1443 | 1443 | } |
1444 | 1444 | |
1445 | - $filter = $uuidAttr . '=' . $uuid; |
|
1445 | + $filter = $uuidAttr.'='.$uuid; |
|
1446 | 1446 | $result = $this->searchUsers($filter, ['dn'], 2); |
1447 | - if(is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) { |
|
1447 | + if (is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) { |
|
1448 | 1448 | // we put the count into account to make sure that this is |
1449 | 1449 | // really unique |
1450 | 1450 | return $result[0]['dn'][0]; |
@@ -1461,7 +1461,7 @@ discard block |
||
1461 | 1461 | * @return bool true on success, false otherwise |
1462 | 1462 | */ |
1463 | 1463 | private function detectUuidAttribute($dn, $isUser = true, $force = false) { |
1464 | - if($isUser) { |
|
1464 | + if ($isUser) { |
|
1465 | 1465 | $uuidAttr = 'ldapUuidUserAttribute'; |
1466 | 1466 | $uuidOverride = $this->connection->ldapExpertUUIDUserAttr; |
1467 | 1467 | } else { |
@@ -1469,7 +1469,7 @@ discard block |
||
1469 | 1469 | $uuidOverride = $this->connection->ldapExpertUUIDGroupAttr; |
1470 | 1470 | } |
1471 | 1471 | |
1472 | - if(($this->connection->$uuidAttr !== 'auto') && !$force) { |
|
1472 | + if (($this->connection->$uuidAttr !== 'auto') && !$force) { |
|
1473 | 1473 | return true; |
1474 | 1474 | } |
1475 | 1475 | |
@@ -1481,9 +1481,9 @@ discard block |
||
1481 | 1481 | // for now, supported attributes are entryUUID, nsuniqueid, objectGUID, ipaUniqueID |
1482 | 1482 | $testAttributes = array('entryuuid', 'nsuniqueid', 'objectguid', 'guid', 'ipauniqueid'); |
1483 | 1483 | |
1484 | - foreach($testAttributes as $attribute) { |
|
1484 | + foreach ($testAttributes as $attribute) { |
|
1485 | 1485 | $value = $this->readAttribute($dn, $attribute); |
1486 | - if(is_array($value) && isset($value[0]) && !empty($value[0])) { |
|
1486 | + if (is_array($value) && isset($value[0]) && !empty($value[0])) { |
|
1487 | 1487 | \OCP\Util::writeLog('user_ldap', |
1488 | 1488 | 'Setting '.$attribute.' as '.$uuidAttr, |
1489 | 1489 | \OCP\Util::DEBUG); |
@@ -1504,7 +1504,7 @@ discard block |
||
1504 | 1504 | * @return string|bool |
1505 | 1505 | */ |
1506 | 1506 | public function getUUID($dn, $isUser = true) { |
1507 | - if($isUser) { |
|
1507 | + if ($isUser) { |
|
1508 | 1508 | $uuidAttr = 'ldapUuidUserAttribute'; |
1509 | 1509 | $uuidOverride = $this->connection->ldapExpertUUIDUserAttr; |
1510 | 1510 | } else { |
@@ -1513,15 +1513,15 @@ discard block |
||
1513 | 1513 | } |
1514 | 1514 | |
1515 | 1515 | $uuid = false; |
1516 | - if($this->detectUuidAttribute($dn, $isUser)) { |
|
1516 | + if ($this->detectUuidAttribute($dn, $isUser)) { |
|
1517 | 1517 | $uuid = $this->readAttribute($dn, $this->connection->$uuidAttr); |
1518 | - if( !is_array($uuid) |
|
1518 | + if (!is_array($uuid) |
|
1519 | 1519 | && $uuidOverride !== '' |
1520 | 1520 | && $this->detectUuidAttribute($dn, $isUser, true)) { |
1521 | 1521 | $uuid = $this->readAttribute($dn, |
1522 | 1522 | $this->connection->$uuidAttr); |
1523 | 1523 | } |
1524 | - if(is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) { |
|
1524 | + if (is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) { |
|
1525 | 1525 | $uuid = $uuid[0]; |
1526 | 1526 | } |
1527 | 1527 | } |
@@ -1538,19 +1538,19 @@ discard block |
||
1538 | 1538 | private function convertObjectGUID2Str($oguid) { |
1539 | 1539 | $hex_guid = bin2hex($oguid); |
1540 | 1540 | $hex_guid_to_guid_str = ''; |
1541 | - for($k = 1; $k <= 4; ++$k) { |
|
1541 | + for ($k = 1; $k <= 4; ++$k) { |
|
1542 | 1542 | $hex_guid_to_guid_str .= substr($hex_guid, 8 - 2 * $k, 2); |
1543 | 1543 | } |
1544 | 1544 | $hex_guid_to_guid_str .= '-'; |
1545 | - for($k = 1; $k <= 2; ++$k) { |
|
1545 | + for ($k = 1; $k <= 2; ++$k) { |
|
1546 | 1546 | $hex_guid_to_guid_str .= substr($hex_guid, 12 - 2 * $k, 2); |
1547 | 1547 | } |
1548 | 1548 | $hex_guid_to_guid_str .= '-'; |
1549 | - for($k = 1; $k <= 2; ++$k) { |
|
1549 | + for ($k = 1; $k <= 2; ++$k) { |
|
1550 | 1550 | $hex_guid_to_guid_str .= substr($hex_guid, 16 - 2 * $k, 2); |
1551 | 1551 | } |
1552 | - $hex_guid_to_guid_str .= '-' . substr($hex_guid, 16, 4); |
|
1553 | - $hex_guid_to_guid_str .= '-' . substr($hex_guid, 20); |
|
1552 | + $hex_guid_to_guid_str .= '-'.substr($hex_guid, 16, 4); |
|
1553 | + $hex_guid_to_guid_str .= '-'.substr($hex_guid, 20); |
|
1554 | 1554 | |
1555 | 1555 | return strtoupper($hex_guid_to_guid_str); |
1556 | 1556 | } |
@@ -1567,11 +1567,11 @@ discard block |
||
1567 | 1567 | * @return string |
1568 | 1568 | */ |
1569 | 1569 | public function formatGuid2ForFilterUser($guid) { |
1570 | - if(!is_string($guid)) { |
|
1570 | + if (!is_string($guid)) { |
|
1571 | 1571 | throw new \InvalidArgumentException('String expected'); |
1572 | 1572 | } |
1573 | 1573 | $blocks = explode('-', $guid); |
1574 | - if(count($blocks) !== 5) { |
|
1574 | + if (count($blocks) !== 5) { |
|
1575 | 1575 | /* |
1576 | 1576 | * Why not throw an Exception instead? This method is a utility |
1577 | 1577 | * called only when trying to figure out whether a "missing" known |
@@ -1584,20 +1584,20 @@ discard block |
||
1584 | 1584 | * user. Instead we write a log message. |
1585 | 1585 | */ |
1586 | 1586 | \OC::$server->getLogger()->info( |
1587 | - 'Passed string does not resemble a valid GUID. Known UUID ' . |
|
1587 | + 'Passed string does not resemble a valid GUID. Known UUID '. |
|
1588 | 1588 | '({uuid}) probably does not match UUID configuration.', |
1589 | - [ 'app' => 'user_ldap', 'uuid' => $guid ] |
|
1589 | + ['app' => 'user_ldap', 'uuid' => $guid] |
|
1590 | 1590 | ); |
1591 | 1591 | return $guid; |
1592 | 1592 | } |
1593 | - for($i=0; $i < 3; $i++) { |
|
1593 | + for ($i = 0; $i < 3; $i++) { |
|
1594 | 1594 | $pairs = str_split($blocks[$i], 2); |
1595 | 1595 | $pairs = array_reverse($pairs); |
1596 | 1596 | $blocks[$i] = implode('', $pairs); |
1597 | 1597 | } |
1598 | - for($i=0; $i < 5; $i++) { |
|
1598 | + for ($i = 0; $i < 5; $i++) { |
|
1599 | 1599 | $pairs = str_split($blocks[$i], 2); |
1600 | - $blocks[$i] = '\\' . implode('\\', $pairs); |
|
1600 | + $blocks[$i] = '\\'.implode('\\', $pairs); |
|
1601 | 1601 | } |
1602 | 1602 | return implode('', $blocks); |
1603 | 1603 | } |
@@ -1611,12 +1611,12 @@ discard block |
||
1611 | 1611 | $domainDN = $this->getDomainDNFromDN($dn); |
1612 | 1612 | $cacheKey = 'getSID-'.$domainDN; |
1613 | 1613 | $sid = $this->connection->getFromCache($cacheKey); |
1614 | - if(!is_null($sid)) { |
|
1614 | + if (!is_null($sid)) { |
|
1615 | 1615 | return $sid; |
1616 | 1616 | } |
1617 | 1617 | |
1618 | 1618 | $objectSid = $this->readAttribute($domainDN, 'objectsid'); |
1619 | - if(!is_array($objectSid) || empty($objectSid)) { |
|
1619 | + if (!is_array($objectSid) || empty($objectSid)) { |
|
1620 | 1620 | $this->connection->writeToCache($cacheKey, false); |
1621 | 1621 | return false; |
1622 | 1622 | } |
@@ -1674,12 +1674,12 @@ discard block |
||
1674 | 1674 | $belongsToBase = false; |
1675 | 1675 | $bases = $this->helper->sanitizeDN($bases); |
1676 | 1676 | |
1677 | - foreach($bases as $base) { |
|
1677 | + foreach ($bases as $base) { |
|
1678 | 1678 | $belongsToBase = true; |
1679 | - if(mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8')-mb_strlen($base, 'UTF-8'))) { |
|
1679 | + if (mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8') - mb_strlen($base, 'UTF-8'))) { |
|
1680 | 1680 | $belongsToBase = false; |
1681 | 1681 | } |
1682 | - if($belongsToBase) { |
|
1682 | + if ($belongsToBase) { |
|
1683 | 1683 | break; |
1684 | 1684 | } |
1685 | 1685 | } |
@@ -1690,7 +1690,7 @@ discard block |
||
1690 | 1690 | * resets a running Paged Search operation |
1691 | 1691 | */ |
1692 | 1692 | private function abandonPagedSearch() { |
1693 | - if($this->connection->hasPagedResultSupport) { |
|
1693 | + if ($this->connection->hasPagedResultSupport) { |
|
1694 | 1694 | $cr = $this->connection->getConnectionResource(); |
1695 | 1695 | $this->ldap->controlPagedResult($cr, 0, false, $this->lastCookie); |
1696 | 1696 | $this->getPagedSearchResultState(); |
@@ -1708,16 +1708,16 @@ discard block |
||
1708 | 1708 | * @return string containing the key or empty if none is cached |
1709 | 1709 | */ |
1710 | 1710 | private function getPagedResultCookie($base, $filter, $limit, $offset) { |
1711 | - if($offset === 0) { |
|
1711 | + if ($offset === 0) { |
|
1712 | 1712 | return ''; |
1713 | 1713 | } |
1714 | 1714 | $offset -= $limit; |
1715 | 1715 | //we work with cache here |
1716 | - $cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' . intval($limit) . '-' . intval($offset); |
|
1716 | + $cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.intval($limit).'-'.intval($offset); |
|
1717 | 1717 | $cookie = ''; |
1718 | - if(isset($this->cookies[$cacheKey])) { |
|
1718 | + if (isset($this->cookies[$cacheKey])) { |
|
1719 | 1719 | $cookie = $this->cookies[$cacheKey]; |
1720 | - if(is_null($cookie)) { |
|
1720 | + if (is_null($cookie)) { |
|
1721 | 1721 | $cookie = ''; |
1722 | 1722 | } |
1723 | 1723 | } |
@@ -1735,11 +1735,11 @@ discard block |
||
1735 | 1735 | * @return bool |
1736 | 1736 | */ |
1737 | 1737 | public function hasMoreResults() { |
1738 | - if(!$this->connection->hasPagedResultSupport) { |
|
1738 | + if (!$this->connection->hasPagedResultSupport) { |
|
1739 | 1739 | return false; |
1740 | 1740 | } |
1741 | 1741 | |
1742 | - if(empty($this->lastCookie) && $this->lastCookie !== '0') { |
|
1742 | + if (empty($this->lastCookie) && $this->lastCookie !== '0') { |
|
1743 | 1743 | // as in RFC 2696, when all results are returned, the cookie will |
1744 | 1744 | // be empty. |
1745 | 1745 | return false; |
@@ -1759,8 +1759,8 @@ discard block |
||
1759 | 1759 | */ |
1760 | 1760 | private function setPagedResultCookie($base, $filter, $limit, $offset, $cookie) { |
1761 | 1761 | // allow '0' for 389ds |
1762 | - if(!empty($cookie) || $cookie === '0') { |
|
1763 | - $cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' .intval($limit) . '-' . intval($offset); |
|
1762 | + if (!empty($cookie) || $cookie === '0') { |
|
1763 | + $cacheKey = 'lc'.crc32($base).'-'.crc32($filter).'-'.intval($limit).'-'.intval($offset); |
|
1764 | 1764 | $this->cookies[$cacheKey] = $cookie; |
1765 | 1765 | $this->lastCookie = $cookie; |
1766 | 1766 | } |
@@ -1787,17 +1787,17 @@ discard block |
||
1787 | 1787 | */ |
1788 | 1788 | private function initPagedSearch($filter, $bases, $attr, $limit, $offset) { |
1789 | 1789 | $pagedSearchOK = false; |
1790 | - if($this->connection->hasPagedResultSupport && ($limit !== 0)) { |
|
1790 | + if ($this->connection->hasPagedResultSupport && ($limit !== 0)) { |
|
1791 | 1791 | $offset = intval($offset); //can be null |
1792 | 1792 | \OCP\Util::writeLog('user_ldap', |
1793 | 1793 | 'initializing paged search for Filter '.$filter.' base '.print_r($bases, true) |
1794 | - .' attr '.print_r($attr, true). ' limit ' .$limit.' offset '.$offset, |
|
1794 | + .' attr '.print_r($attr, true).' limit '.$limit.' offset '.$offset, |
|
1795 | 1795 | \OCP\Util::DEBUG); |
1796 | 1796 | //get the cookie from the search for the previous search, required by LDAP |
1797 | - foreach($bases as $base) { |
|
1797 | + foreach ($bases as $base) { |
|
1798 | 1798 | |
1799 | 1799 | $cookie = $this->getPagedResultCookie($base, $filter, $limit, $offset); |
1800 | - if(empty($cookie) && $cookie !== "0" && ($offset > 0)) { |
|
1800 | + if (empty($cookie) && $cookie !== "0" && ($offset > 0)) { |
|
1801 | 1801 | // no cookie known, although the offset is not 0. Maybe cache run out. We need |
1802 | 1802 | // to start all over *sigh* (btw, Dear Reader, did you know LDAP paged |
1803 | 1803 | // searching was designed by MSFT?) |
@@ -1810,18 +1810,18 @@ discard block |
||
1810 | 1810 | $cookie = $this->getPagedResultCookie($base, $filter, $limit, $offset); |
1811 | 1811 | //still no cookie? obviously, the server does not like us. Let's skip paging efforts. |
1812 | 1812 | //TODO: remember this, probably does not change in the next request... |
1813 | - if(empty($cookie) && $cookie !== '0') { |
|
1813 | + if (empty($cookie) && $cookie !== '0') { |
|
1814 | 1814 | // '0' is valid, because 389ds |
1815 | 1815 | $cookie = null; |
1816 | 1816 | } |
1817 | 1817 | } |
1818 | - if(!is_null($cookie)) { |
|
1818 | + if (!is_null($cookie)) { |
|
1819 | 1819 | //since offset = 0, this is a new search. We abandon other searches that might be ongoing. |
1820 | 1820 | $this->abandonPagedSearch(); |
1821 | 1821 | $pagedSearchOK = $this->ldap->controlPagedResult( |
1822 | 1822 | $this->connection->getConnectionResource(), $limit, |
1823 | 1823 | false, $cookie); |
1824 | - if(!$pagedSearchOK) { |
|
1824 | + if (!$pagedSearchOK) { |
|
1825 | 1825 | return false; |
1826 | 1826 | } |
1827 | 1827 | \OCP\Util::writeLog('user_ldap', 'Ready for a paged search', \OCP\Util::DEBUG); |
@@ -1838,7 +1838,7 @@ discard block |
||
1838 | 1838 | * So we added "&& !empty($this->lastCookie)" to this test to ignore pagination |
1839 | 1839 | * if we don't have a previous paged search. |
1840 | 1840 | */ |
1841 | - } else if($this->connection->hasPagedResultSupport && $limit === 0 && !empty($this->lastCookie)) { |
|
1841 | + } else if ($this->connection->hasPagedResultSupport && $limit === 0 && !empty($this->lastCookie)) { |
|
1842 | 1842 | // a search without limit was requested. However, if we do use |
1843 | 1843 | // Paged Search once, we always must do it. This requires us to |
1844 | 1844 | // initialize it with the configured page size. |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | $this->logger = $serverContainer->getLogger(); |
48 | 48 | $this->helper = $helper; |
49 | 49 | $this->deletedUsersIndex = $deletedUsersIndex; |
50 | - foreach ($serverContainer->getUserManager()->getBackends() as $backend){ |
|
50 | + foreach ($serverContainer->getUserManager()->getBackends() as $backend) { |
|
51 | 51 | $this->logger->debug('instance '.get_class($backend).' backend.', ['app' => 'user_ldap']); |
52 | 52 | if ($backend instanceof IUserLDAP) { |
53 | 53 | $this->backend = $backend; |
@@ -64,11 +64,11 @@ discard block |
||
64 | 64 | * @throws \Exception if translation was unsuccessful |
65 | 65 | */ |
66 | 66 | public function getUserDN($uid) { |
67 | - if(!$this->backend->userExists($uid)){ |
|
67 | + if (!$this->backend->userExists($uid)) { |
|
68 | 68 | throw new \Exception('User id not found in LDAP'); |
69 | 69 | } |
70 | 70 | $result = $this->backend->getLDAPAccess($uid)->username2dn($uid); |
71 | - if(!$result){ |
|
71 | + if (!$result) { |
|
72 | 72 | throw new \Exception('Translation to LDAP DN unsuccessful'); |
73 | 73 | } |
74 | 74 | return $result; |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | */ |
84 | 84 | public function getUserName($dn) { |
85 | 85 | $result = $this->backend->dn2UserName($dn); |
86 | - if(!$result){ |
|
86 | + if (!$result) { |
|
87 | 87 | throw new \Exception('Translation to internal user name unsuccessful'); |
88 | 88 | } |
89 | 89 | return $result; |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * @throws \Exception if user id was not found in LDAP |
116 | 116 | */ |
117 | 117 | public function getLDAPConnection($uid) { |
118 | - if(!$this->backend->userExists($uid)){ |
|
118 | + if (!$this->backend->userExists($uid)) { |
|
119 | 119 | throw new \Exception('User id not found in LDAP'); |
120 | 120 | } |
121 | 121 | return $this->backend->getNewLDAPConnection($uid); |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * @throws \Exception if user id was not found in LDAP |
129 | 129 | */ |
130 | 130 | public function getLDAPBaseUsers($uid) { |
131 | - if(!$this->backend->userExists($uid)){ |
|
131 | + if (!$this->backend->userExists($uid)) { |
|
132 | 132 | throw new \Exception('User id not found in LDAP'); |
133 | 133 | } |
134 | 134 | return $this->backend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_users']; |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | * @throws \Exception if user id was not found in LDAP |
142 | 142 | */ |
143 | 143 | public function getLDAPBaseGroups($uid) { |
144 | - if(!$this->backend->userExists($uid)){ |
|
144 | + if (!$this->backend->userExists($uid)) { |
|
145 | 145 | throw new \Exception('User id not found in LDAP'); |
146 | 146 | } |
147 | 147 | return $this->backend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_base_groups']; |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * @throws \Exception if user id was not found in LDAP |
154 | 154 | */ |
155 | 155 | public function clearCache($uid) { |
156 | - if(!$this->backend->userExists($uid)){ |
|
156 | + if (!$this->backend->userExists($uid)) { |
|
157 | 157 | throw new \Exception('User id not found in LDAP'); |
158 | 158 | } |
159 | 159 | $this->backend->getLDAPAccess($uid)->getConnection()->clearCache(); |
@@ -66,10 +66,10 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function canChangeAvatar($uid) { |
68 | 68 | $user = $this->access->userManager->get($uid); |
69 | - if(!$user instanceof User) { |
|
69 | + if (!$user instanceof User) { |
|
70 | 70 | return false; |
71 | 71 | } |
72 | - if($user->getAvatarImage() === false) { |
|
72 | + if ($user->getAvatarImage() === false) { |
|
73 | 73 | return true; |
74 | 74 | } |
75 | 75 | |
@@ -85,14 +85,14 @@ discard block |
||
85 | 85 | public function loginName2UserName($loginName) { |
86 | 86 | $cacheKey = 'loginName2UserName-'.$loginName; |
87 | 87 | $username = $this->access->connection->getFromCache($cacheKey); |
88 | - if(!is_null($username)) { |
|
88 | + if (!is_null($username)) { |
|
89 | 89 | return $username; |
90 | 90 | } |
91 | 91 | |
92 | 92 | try { |
93 | 93 | $ldapRecord = $this->getLDAPUserByLoginName($loginName); |
94 | 94 | $user = $this->access->userManager->get($ldapRecord['dn'][0]); |
95 | - if($user instanceof OfflineUser) { |
|
95 | + if ($user instanceof OfflineUser) { |
|
96 | 96 | // this path is not really possible, however get() is documented |
97 | 97 | // to return User or OfflineUser so we are very defensive here. |
98 | 98 | $this->access->connection->writeToCache($cacheKey, false); |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | //find out dn of the user name |
129 | 129 | $attrs = $this->access->userManager->getAttributes(); |
130 | 130 | $users = $this->access->fetchUsersByLoginName($loginName, $attrs); |
131 | - if(count($users) < 1) { |
|
132 | - throw new NotOnLDAP('No user available for the given login name on ' . |
|
133 | - $this->access->connection->ldapHost . ':' . $this->access->connection->ldapPort); |
|
131 | + if (count($users) < 1) { |
|
132 | + throw new NotOnLDAP('No user available for the given login name on '. |
|
133 | + $this->access->connection->ldapHost.':'.$this->access->connection->ldapPort); |
|
134 | 134 | } |
135 | 135 | return $users[0]; |
136 | 136 | } |
@@ -145,8 +145,8 @@ discard block |
||
145 | 145 | public function checkPassword($uid, $password) { |
146 | 146 | try { |
147 | 147 | $ldapRecord = $this->getLDAPUserByLoginName($uid); |
148 | - } catch(NotOnLDAP $e) { |
|
149 | - if($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) { |
|
148 | + } catch (NotOnLDAP $e) { |
|
149 | + if ($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) { |
|
150 | 150 | \OC::$server->getLogger()->logException($e, ['app' => 'user_ldap']); |
151 | 151 | } |
152 | 152 | return false; |
@@ -154,16 +154,16 @@ discard block |
||
154 | 154 | $dn = $ldapRecord['dn'][0]; |
155 | 155 | $user = $this->access->userManager->get($dn); |
156 | 156 | |
157 | - if(!$user instanceof User) { |
|
157 | + if (!$user instanceof User) { |
|
158 | 158 | Util::writeLog('user_ldap', |
159 | - 'LDAP Login: Could not get user object for DN ' . $dn . |
|
159 | + 'LDAP Login: Could not get user object for DN '.$dn. |
|
160 | 160 | '. Maybe the LDAP entry has no set display name attribute?', |
161 | 161 | Util::WARN); |
162 | 162 | return false; |
163 | 163 | } |
164 | - if($user->getUsername() !== false) { |
|
164 | + if ($user->getUsername() !== false) { |
|
165 | 165 | //are the credentials OK? |
166 | - if(!$this->access->areCredentialsValid($dn, $password)) { |
|
166 | + if (!$this->access->areCredentialsValid($dn, $password)) { |
|
167 | 167 | return false; |
168 | 168 | } |
169 | 169 | |
@@ -186,11 +186,11 @@ discard block |
||
186 | 186 | public function setPassword($uid, $password) { |
187 | 187 | $user = $this->access->userManager->get($uid); |
188 | 188 | |
189 | - if(!$user instanceof User) { |
|
190 | - throw new \Exception('LDAP setPassword: Could not get user object for uid ' . $uid . |
|
189 | + if (!$user instanceof User) { |
|
190 | + throw new \Exception('LDAP setPassword: Could not get user object for uid '.$uid. |
|
191 | 191 | '. Maybe the LDAP entry has no set display name attribute?'); |
192 | 192 | } |
193 | - if($user->getUsername() !== false) { |
|
193 | + if ($user->getUsername() !== false) { |
|
194 | 194 | return $this->access->setPassword($user->getDN(), $password); |
195 | 195 | } |
196 | 196 | |
@@ -211,18 +211,18 @@ discard block |
||
211 | 211 | |
212 | 212 | //check if users are cached, if so return |
213 | 213 | $ldap_users = $this->access->connection->getFromCache($cachekey); |
214 | - if(!is_null($ldap_users)) { |
|
214 | + if (!is_null($ldap_users)) { |
|
215 | 215 | return $ldap_users; |
216 | 216 | } |
217 | 217 | |
218 | 218 | // if we'd pass -1 to LDAP search, we'd end up in a Protocol |
219 | 219 | // error. With a limit of 0, we get 0 results. So we pass null. |
220 | - if($limit <= 0) { |
|
220 | + if ($limit <= 0) { |
|
221 | 221 | $limit = null; |
222 | 222 | } |
223 | 223 | $filter = $this->access->combineFilterWithAnd(array( |
224 | 224 | $this->access->connection->ldapUserFilter, |
225 | - $this->access->connection->ldapUserDisplayName . '=*', |
|
225 | + $this->access->connection->ldapUserDisplayName.'=*', |
|
226 | 226 | $this->access->getFilterPartForUserSearch($search) |
227 | 227 | )); |
228 | 228 | |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | $this->access->userManager->getAttributes(true), |
236 | 236 | $limit, $offset); |
237 | 237 | $ldap_users = $this->access->ownCloudUserNames($ldap_users); |
238 | - Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users). ' Users found', Util::DEBUG); |
|
238 | + Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users).' Users found', Util::DEBUG); |
|
239 | 239 | |
240 | 240 | $this->access->connection->writeToCache($cachekey, $ldap_users); |
241 | 241 | return $ldap_users; |
@@ -251,29 +251,29 @@ discard block |
||
251 | 251 | * @throws \OC\ServerNotAvailableException |
252 | 252 | */ |
253 | 253 | public function userExistsOnLDAP($user) { |
254 | - if(is_string($user)) { |
|
254 | + if (is_string($user)) { |
|
255 | 255 | $user = $this->access->userManager->get($user); |
256 | 256 | } |
257 | - if(is_null($user)) { |
|
257 | + if (is_null($user)) { |
|
258 | 258 | return false; |
259 | 259 | } |
260 | 260 | |
261 | 261 | $dn = $user->getDN(); |
262 | 262 | //check if user really still exists by reading its entry |
263 | - if(!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) { |
|
263 | + if (!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) { |
|
264 | 264 | $lcr = $this->access->connection->getConnectionResource(); |
265 | - if(is_null($lcr)) { |
|
266 | - throw new \Exception('No LDAP Connection to server ' . $this->access->connection->ldapHost); |
|
265 | + if (is_null($lcr)) { |
|
266 | + throw new \Exception('No LDAP Connection to server '.$this->access->connection->ldapHost); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | try { |
270 | 270 | $uuid = $this->access->getUserMapper()->getUUIDByDN($dn); |
271 | - if(!$uuid) { |
|
271 | + if (!$uuid) { |
|
272 | 272 | return false; |
273 | 273 | } |
274 | 274 | $newDn = $this->access->getUserDnByUuid($uuid); |
275 | 275 | //check if renamed user is still valid by reapplying the ldap filter |
276 | - if(!is_array($this->access->readAttribute($newDn, '', $this->access->connection->ldapUserFilter))) { |
|
276 | + if (!is_array($this->access->readAttribute($newDn, '', $this->access->connection->ldapUserFilter))) { |
|
277 | 277 | return false; |
278 | 278 | } |
279 | 279 | $this->access->getUserMapper()->setDNbyUUID($newDn, $uuid); |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | } |
284 | 284 | } |
285 | 285 | |
286 | - if($user instanceof OfflineUser) { |
|
286 | + if ($user instanceof OfflineUser) { |
|
287 | 287 | $user->unmark(); |
288 | 288 | } |
289 | 289 | |
@@ -298,18 +298,18 @@ discard block |
||
298 | 298 | */ |
299 | 299 | public function userExists($uid) { |
300 | 300 | $userExists = $this->access->connection->getFromCache('userExists'.$uid); |
301 | - if(!is_null($userExists)) { |
|
302 | - return (bool)$userExists; |
|
301 | + if (!is_null($userExists)) { |
|
302 | + return (bool) $userExists; |
|
303 | 303 | } |
304 | 304 | //getting dn, if false the user does not exist. If dn, he may be mapped only, requires more checking. |
305 | 305 | $user = $this->access->userManager->get($uid); |
306 | 306 | |
307 | - if(is_null($user)) { |
|
307 | + if (is_null($user)) { |
|
308 | 308 | Util::writeLog('user_ldap', 'No DN found for '.$uid.' on '. |
309 | 309 | $this->access->connection->ldapHost, Util::DEBUG); |
310 | 310 | $this->access->connection->writeToCache('userExists'.$uid, false); |
311 | 311 | return false; |
312 | - } else if($user instanceof OfflineUser) { |
|
312 | + } else if ($user instanceof OfflineUser) { |
|
313 | 313 | //express check for users marked as deleted. Returning true is |
314 | 314 | //necessary for cleanup |
315 | 315 | return true; |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | |
318 | 318 | $result = $this->userExistsOnLDAP($user); |
319 | 319 | $this->access->connection->writeToCache('userExists'.$uid, $result); |
320 | - if($result === true) { |
|
320 | + if ($result === true) { |
|
321 | 321 | $user->update(); |
322 | 322 | } |
323 | 323 | return $result; |
@@ -331,13 +331,13 @@ discard block |
||
331 | 331 | */ |
332 | 332 | public function deleteUser($uid) { |
333 | 333 | $marked = $this->ocConfig->getUserValue($uid, 'user_ldap', 'isDeleted', 0); |
334 | - if(intval($marked) === 0) { |
|
334 | + if (intval($marked) === 0) { |
|
335 | 335 | \OC::$server->getLogger()->notice( |
336 | - 'User '.$uid . ' is not marked as deleted, not cleaning up.', |
|
336 | + 'User '.$uid.' is not marked as deleted, not cleaning up.', |
|
337 | 337 | array('app' => 'user_ldap')); |
338 | 338 | return false; |
339 | 339 | } |
340 | - \OC::$server->getLogger()->info('Cleaning up after user ' . $uid, |
|
340 | + \OC::$server->getLogger()->info('Cleaning up after user '.$uid, |
|
341 | 341 | array('app' => 'user_ldap')); |
342 | 342 | |
343 | 343 | //Get Home Directory out of user preferences so we can return it later, |
@@ -358,27 +358,27 @@ discard block |
||
358 | 358 | * @throws \Exception |
359 | 359 | */ |
360 | 360 | public function getHome($uid) { |
361 | - if(isset($this->homesToKill[$uid]) && !empty($this->homesToKill[$uid])) { |
|
361 | + if (isset($this->homesToKill[$uid]) && !empty($this->homesToKill[$uid])) { |
|
362 | 362 | //a deleted user who needs some clean up |
363 | 363 | return $this->homesToKill[$uid]; |
364 | 364 | } |
365 | 365 | |
366 | 366 | // user Exists check required as it is not done in user proxy! |
367 | - if(!$this->userExists($uid)) { |
|
367 | + if (!$this->userExists($uid)) { |
|
368 | 368 | return false; |
369 | 369 | } |
370 | 370 | |
371 | 371 | $cacheKey = 'getHome'.$uid; |
372 | 372 | $path = $this->access->connection->getFromCache($cacheKey); |
373 | - if(!is_null($path)) { |
|
373 | + if (!is_null($path)) { |
|
374 | 374 | return $path; |
375 | 375 | } |
376 | 376 | |
377 | 377 | $user = $this->access->userManager->get($uid); |
378 | - if(is_null($user) || ($user instanceof OfflineUser && !$this->userExistsOnLDAP($user->getOCName()))) { |
|
379 | - throw new NoUserException($uid . ' is not a valid user anymore'); |
|
378 | + if (is_null($user) || ($user instanceof OfflineUser && !$this->userExistsOnLDAP($user->getOCName()))) { |
|
379 | + throw new NoUserException($uid.' is not a valid user anymore'); |
|
380 | 380 | } |
381 | - if($user instanceof OfflineUser) { |
|
381 | + if ($user instanceof OfflineUser) { |
|
382 | 382 | // apparently this user survived the userExistsOnLDAP check, |
383 | 383 | // we request the user instance again in order to retrieve a User |
384 | 384 | // instance instead |
@@ -396,12 +396,12 @@ discard block |
||
396 | 396 | * @return string|false display name |
397 | 397 | */ |
398 | 398 | public function getDisplayName($uid) { |
399 | - if(!$this->userExists($uid)) { |
|
399 | + if (!$this->userExists($uid)) { |
|
400 | 400 | return false; |
401 | 401 | } |
402 | 402 | |
403 | 403 | $cacheKey = 'getDisplayName'.$uid; |
404 | - if(!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) { |
|
404 | + if (!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) { |
|
405 | 405 | return $displayName; |
406 | 406 | } |
407 | 407 | |
@@ -418,10 +418,10 @@ discard block |
||
418 | 418 | $this->access->username2dn($uid), |
419 | 419 | $this->access->connection->ldapUserDisplayName); |
420 | 420 | |
421 | - if($displayName && (count($displayName) > 0)) { |
|
421 | + if ($displayName && (count($displayName) > 0)) { |
|
422 | 422 | $displayName = $displayName[0]; |
423 | 423 | |
424 | - if (is_array($displayName2)){ |
|
424 | + if (is_array($displayName2)) { |
|
425 | 425 | $displayName2 = count($displayName2) > 0 ? $displayName2[0] : ''; |
426 | 426 | } |
427 | 427 | |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | */ |
451 | 451 | public function getDisplayNames($search = '', $limit = null, $offset = null) { |
452 | 452 | $cacheKey = 'getDisplayNames-'.$search.'-'.$limit.'-'.$offset; |
453 | - if(!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) { |
|
453 | + if (!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) { |
|
454 | 454 | return $displayNames; |
455 | 455 | } |
456 | 456 | |
@@ -472,12 +472,12 @@ discard block |
||
472 | 472 | * compared with OC_USER_BACKEND_CREATE_USER etc. |
473 | 473 | */ |
474 | 474 | public function implementsActions($actions) { |
475 | - return (bool)((Backend::CHECK_PASSWORD |
|
475 | + return (bool) ((Backend::CHECK_PASSWORD |
|
476 | 476 | | Backend::GET_HOME |
477 | 477 | | Backend::GET_DISPLAYNAME |
478 | 478 | | Backend::PROVIDE_AVATAR |
479 | 479 | | Backend::COUNT_USERS |
480 | - | ((intval($this->access->connection->turnOnPasswordChange) === 1)?(Backend::SET_PASSWORD):0)) |
|
480 | + | ((intval($this->access->connection->turnOnPasswordChange) === 1) ? (Backend::SET_PASSWORD) : 0)) |
|
481 | 481 | & $actions); |
482 | 482 | } |
483 | 483 | |
@@ -496,7 +496,7 @@ discard block |
||
496 | 496 | public function countUsers() { |
497 | 497 | $filter = $this->access->getFilterForUserCount(); |
498 | 498 | $cacheKey = 'countUsers-'.$filter; |
499 | - if(!is_null($entries = $this->access->connection->getFromCache($cacheKey))) { |
|
499 | + if (!is_null($entries = $this->access->connection->getFromCache($cacheKey))) { |
|
500 | 500 | return $entries; |
501 | 501 | } |
502 | 502 | $entries = $this->access->countUsers($filter); |
@@ -508,7 +508,7 @@ discard block |
||
508 | 508 | * Backend name to be shown in user management |
509 | 509 | * @return string the name of the backend to be shown |
510 | 510 | */ |
511 | - public function getBackendName(){ |
|
511 | + public function getBackendName() { |
|
512 | 512 | return 'LDAP'; |
513 | 513 | } |
514 | 514 |