Completed
Pull Request — master (#7195)
by Jan-Christoph
17:09 queued 02:45
created
apps/user_ldap/lib/Mapping/GroupMapping.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -29,12 +29,12 @@
 block discarded – undo
29 29
 */
30 30
 class GroupMapping extends AbstractMapping {
31 31
 
32
-	/**
33
-	* returns the DB table name which holds the mappings
34
-	* @return string
35
-	*/
36
-	protected function getTableName() {
37
-		return '*PREFIX*ldap_group_mapping';
38
-	}
32
+    /**
33
+     * returns the DB table name which holds the mappings
34
+     * @return string
35
+     */
36
+    protected function getTableName() {
37
+        return '*PREFIX*ldap_group_mapping';
38
+    }
39 39
 
40 40
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/Mapping/UserMapping.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -29,12 +29,12 @@
 block discarded – undo
29 29
 */
30 30
 class UserMapping extends AbstractMapping {
31 31
 
32
-	/**
33
-	 * returns the DB table name which holds the mappings
34
-	 * @return string
35
-	 */
36
-	protected function getTableName() {
37
-		return '*PREFIX*ldap_user_mapping';
38
-	}
32
+    /**
33
+     * returns the DB table name which holds the mappings
34
+     * @return string
35
+     */
36
+    protected function getTableName() {
37
+        return '*PREFIX*ldap_user_mapping';
38
+    }
39 39
 
40 40
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/LDAP.php 2 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -52,12 +52,12 @@  discard block
 block discarded – undo
52 52
 	 * @return mixed
53 53
 	 */
54 54
 	public function connect($host, $port) {
55
-		if(strpos($host, '://') === false) {
56
-			$host = 'ldap://' . $host;
55
+		if (strpos($host, '://') === false) {
56
+			$host = 'ldap://'.$host;
57 57
 		}
58
-		if(strpos($host, ':', strpos($host, '://') + 1) === false) {
58
+		if (strpos($host, ':', strpos($host, '://') + 1) === false) {
59 59
 			//ldap_connect ignores port parameter when URLs are passed
60
-			$host .= ':' . $port;
60
+			$host .= ':'.$port;
61 61
 		}
62 62
 		return $this->invokeLDAPMethod('connect', $host);
63 63
 	}
@@ -267,13 +267,13 @@  discard block
 block discarded – undo
267 267
 	 * @return bool
268 268
 	 */
269 269
 	protected function isResultFalse($result) {
270
-		if($result === false) {
270
+		if ($result === false) {
271 271
 			return true;
272 272
 		}
273 273
 
274
-		if($this->curFunc === 'ldap_search' && is_array($result)) {
274
+		if ($this->curFunc === 'ldap_search' && is_array($result)) {
275 275
 			foreach ($result as $singleResult) {
276
-				if($singleResult === false) {
276
+				if ($singleResult === false) {
277 277
 					return true;
278 278
 				}
279 279
 			}
@@ -287,8 +287,8 @@  discard block
 block discarded – undo
287 287
 	 */
288 288
 	protected function invokeLDAPMethod() {
289 289
 		$arguments = func_get_args();
290
-		$func = 'ldap_' . array_shift($arguments);
291
-		if(function_exists($func)) {
290
+		$func = 'ldap_'.array_shift($arguments);
291
+		if (function_exists($func)) {
292 292
 			$this->preFunctionCall($func, $arguments);
293 293
 			$result = call_user_func_array($func, $arguments);
294 294
 			if ($this->isResultFalse($result)) {
@@ -318,12 +318,12 @@  discard block
 block discarded – undo
318 318
 	 */
319 319
 	private function processLDAPError($resource) {
320 320
 		$errorCode = ldap_errno($resource);
321
-		if($errorCode === 0) {
321
+		if ($errorCode === 0) {
322 322
 			return;
323 323
 		}
324
-		$errorMsg  = ldap_error($resource);
324
+		$errorMsg = ldap_error($resource);
325 325
 
326
-		if($this->curFunc === 'ldap_get_entries'
326
+		if ($this->curFunc === 'ldap_get_entries'
327 327
 			&& $errorCode === -4) {
328 328
 		} else if ($errorCode === 32) {
329 329
 			//for now
@@ -337,10 +337,10 @@  discard block
 block discarded – undo
337 337
 			throw new \Exception('LDAP Operations error', $errorCode);
338 338
 		} else if ($errorCode === 19) {
339 339
 			ldap_get_option($this->curArgs[0], LDAP_OPT_ERROR_STRING, $extended_error);
340
-			throw new ConstraintViolationException(!empty($extended_error)?$extended_error:$errorMsg, $errorCode);
340
+			throw new ConstraintViolationException(!empty($extended_error) ? $extended_error : $errorMsg, $errorCode);
341 341
 		} else {
342 342
 			\OCP\Util::writeLog('user_ldap',
343
-				'LDAP error '.$errorMsg.' (' .
343
+				'LDAP error '.$errorMsg.' ('.
344 344
 				$errorCode.') after calling '.
345 345
 				$this->curFunc,
346 346
 				\OCP\Util::DEBUG);
@@ -351,9 +351,9 @@  discard block
 block discarded – undo
351 351
 	 * Called after an ldap method is run to act on LDAP error if necessary
352 352
 	 */
353 353
 	private function postFunctionCall() {
354
-		if($this->isResource($this->curArgs[0])) {
354
+		if ($this->isResource($this->curArgs[0])) {
355 355
 			$resource = $this->curArgs[0];
356
-		} else if(
356
+		} else if (
357 357
 			   $this->curFunc === 'ldap_search'
358 358
 			&& is_array($this->curArgs[0])
359 359
 			&& $this->isResource($this->curArgs[0][0])
Please login to merge, or discard this patch.
Indentation   +337 added lines, -337 removed lines patch added patch discarded remove patch
@@ -33,341 +33,341 @@
 block discarded – undo
33 33
 use OCA\User_LDAP\Exceptions\ConstraintViolationException;
34 34
 
35 35
 class LDAP implements ILDAPWrapper {
36
-	protected $curFunc = '';
37
-	protected $curArgs = array();
38
-
39
-	/**
40
-	 * @param resource $link
41
-	 * @param string $dn
42
-	 * @param string $password
43
-	 * @return bool|mixed
44
-	 */
45
-	public function bind($link, $dn, $password) {
46
-		return $this->invokeLDAPMethod('bind', $link, $dn, $password);
47
-	}
48
-
49
-	/**
50
-	 * @param string $host
51
-	 * @param string $port
52
-	 * @return mixed
53
-	 */
54
-	public function connect($host, $port) {
55
-		if(strpos($host, '://') === false) {
56
-			$host = 'ldap://' . $host;
57
-		}
58
-		if(strpos($host, ':', strpos($host, '://') + 1) === false) {
59
-			//ldap_connect ignores port parameter when URLs are passed
60
-			$host .= ':' . $port;
61
-		}
62
-		return $this->invokeLDAPMethod('connect', $host);
63
-	}
64
-
65
-	/**
66
-	 * @param LDAP $link
67
-	 * @param LDAP $result
68
-	 * @param string $cookie
69
-	 * @return bool|LDAP
70
-	 */
71
-	public function controlPagedResultResponse($link, $result, &$cookie) {
72
-		$this->preFunctionCall('ldap_control_paged_result_response',
73
-			array($link, $result, $cookie));
74
-		$result = ldap_control_paged_result_response($link, $result, $cookie);
75
-		$this->postFunctionCall();
76
-
77
-		return $result;
78
-	}
79
-
80
-	/**
81
-	 * @param LDAP $link
82
-	 * @param int $pageSize
83
-	 * @param bool $isCritical
84
-	 * @param string $cookie
85
-	 * @return mixed|true
86
-	 */
87
-	public function controlPagedResult($link, $pageSize, $isCritical, $cookie) {
88
-		return $this->invokeLDAPMethod('control_paged_result', $link, $pageSize,
89
-										$isCritical, $cookie);
90
-	}
91
-
92
-	/**
93
-	 * @param LDAP $link
94
-	 * @param LDAP $result
95
-	 * @return mixed
96
-	 */
97
-	public function countEntries($link, $result) {
98
-		return $this->invokeLDAPMethod('count_entries', $link, $result);
99
-	}
100
-
101
-	/**
102
-	 * @param LDAP $link
103
-	 * @return integer
104
-	 */
105
-	public function errno($link) {
106
-		return $this->invokeLDAPMethod('errno', $link);
107
-	}
108
-
109
-	/**
110
-	 * @param LDAP $link
111
-	 * @return string
112
-	 */
113
-	public function error($link) {
114
-		return $this->invokeLDAPMethod('error', $link);
115
-	}
116
-
117
-	/**
118
-	 * Splits DN into its component parts
119
-	 * @param string $dn
120
-	 * @param int @withAttrib
121
-	 * @return array|false
122
-	 * @link http://www.php.net/manual/en/function.ldap-explode-dn.php
123
-	 */
124
-	public function explodeDN($dn, $withAttrib) {
125
-		return $this->invokeLDAPMethod('explode_dn', $dn, $withAttrib);
126
-	}
127
-
128
-	/**
129
-	 * @param LDAP $link
130
-	 * @param LDAP $result
131
-	 * @return mixed
132
-	 */
133
-	public function firstEntry($link, $result) {
134
-		return $this->invokeLDAPMethod('first_entry', $link, $result);
135
-	}
136
-
137
-	/**
138
-	 * @param LDAP $link
139
-	 * @param LDAP $result
140
-	 * @return array|mixed
141
-	 */
142
-	public function getAttributes($link, $result) {
143
-		return $this->invokeLDAPMethod('get_attributes', $link, $result);
144
-	}
145
-
146
-	/**
147
-	 * @param LDAP $link
148
-	 * @param LDAP $result
149
-	 * @return mixed|string
150
-	 */
151
-	public function getDN($link, $result) {
152
-		return $this->invokeLDAPMethod('get_dn', $link, $result);
153
-	}
154
-
155
-	/**
156
-	 * @param LDAP $link
157
-	 * @param LDAP $result
158
-	 * @return array|mixed
159
-	 */
160
-	public function getEntries($link, $result) {
161
-		return $this->invokeLDAPMethod('get_entries', $link, $result);
162
-	}
163
-
164
-	/**
165
-	 * @param LDAP $link
166
-	 * @param resource $result
167
-	 * @return mixed
168
-	 */
169
-	public function nextEntry($link, $result) {
170
-		return $this->invokeLDAPMethod('next_entry', $link, $result);
171
-	}
172
-
173
-	/**
174
-	 * @param LDAP $link
175
-	 * @param string $baseDN
176
-	 * @param string $filter
177
-	 * @param array $attr
178
-	 * @return mixed
179
-	 */
180
-	public function read($link, $baseDN, $filter, $attr) {
181
-		return $this->invokeLDAPMethod('read', $link, $baseDN, $filter, $attr);
182
-	}
183
-
184
-	/**
185
-	 * @param LDAP $link
186
-	 * @param string $baseDN
187
-	 * @param string $filter
188
-	 * @param array $attr
189
-	 * @param int $attrsOnly
190
-	 * @param int $limit
191
-	 * @return mixed
192
-	 */
193
-	public function search($link, $baseDN, $filter, $attr, $attrsOnly = 0, $limit = 0) {
194
-		return $this->invokeLDAPMethod('search', $link, $baseDN, $filter, $attr, $attrsOnly, $limit);
195
-	}
196
-
197
-	/**
198
-	 * @param LDAP $link
199
-	 * @param string $userDN
200
-	 * @param string $password
201
-	 * @return bool
202
-	 */
203
-	public function modReplace($link, $userDN, $password) {
204
-		return $this->invokeLDAPMethod('mod_replace', $link, $userDN, array('userPassword' => $password));
205
-	}
206
-
207
-	/**
208
-	 * @param LDAP $link
209
-	 * @param string $option
210
-	 * @param int $value
211
-	 * @return bool|mixed
212
-	 */
213
-	public function setOption($link, $option, $value) {
214
-		return $this->invokeLDAPMethod('set_option', $link, $option, $value);
215
-	}
216
-
217
-	/**
218
-	 * @param LDAP $link
219
-	 * @return mixed|true
220
-	 */
221
-	public function startTls($link) {
222
-		return $this->invokeLDAPMethod('start_tls', $link);
223
-	}
224
-
225
-	/**
226
-	 * @param resource $link
227
-	 * @return bool|mixed
228
-	 */
229
-	public function unbind($link) {
230
-		return $this->invokeLDAPMethod('unbind', $link);
231
-	}
232
-
233
-	/**
234
-	 * Checks whether the server supports LDAP
235
-	 * @return boolean if it the case, false otherwise
236
-	 * */
237
-	public function areLDAPFunctionsAvailable() {
238
-		return function_exists('ldap_connect');
239
-	}
240
-
241
-	/**
242
-	 * Checks whether PHP supports LDAP Paged Results
243
-	 * @return boolean if it the case, false otherwise
244
-	 * */
245
-	public function hasPagedResultSupport() {
246
-		$hasSupport = function_exists('ldap_control_paged_result')
247
-			&& function_exists('ldap_control_paged_result_response');
248
-		return $hasSupport;
249
-	}
250
-
251
-	/**
252
-	 * Checks whether the submitted parameter is a resource
253
-	 * @param Resource $resource the resource variable to check
254
-	 * @return bool true if it is a resource, false otherwise
255
-	 */
256
-	public function isResource($resource) {
257
-		return is_resource($resource);
258
-	}
259
-
260
-	/**
261
-	 * Checks whether the return value from LDAP is wrong or not.
262
-	 *
263
-	 * When using ldap_search we provide an array, in case multiple bases are
264
-	 * configured. Thus, we need to check the array elements.
265
-	 *
266
-	 * @param $result
267
-	 * @return bool
268
-	 */
269
-	protected function isResultFalse($result) {
270
-		if($result === false) {
271
-			return true;
272
-		}
273
-
274
-		if($this->curFunc === 'ldap_search' && is_array($result)) {
275
-			foreach ($result as $singleResult) {
276
-				if($singleResult === false) {
277
-					return true;
278
-				}
279
-			}
280
-		}
281
-
282
-		return false;
283
-	}
284
-
285
-	/**
286
-	 * @return mixed
287
-	 */
288
-	protected function invokeLDAPMethod() {
289
-		$arguments = func_get_args();
290
-		$func = 'ldap_' . array_shift($arguments);
291
-		if(function_exists($func)) {
292
-			$this->preFunctionCall($func, $arguments);
293
-			$result = call_user_func_array($func, $arguments);
294
-			if ($this->isResultFalse($result)) {
295
-				$this->postFunctionCall();
296
-			}
297
-			return $result;
298
-		}
299
-		return null;
300
-	}
301
-
302
-	/**
303
-	 * @param string $functionName
304
-	 * @param array $args
305
-	 */
306
-	private function preFunctionCall($functionName, $args) {
307
-		$this->curFunc = $functionName;
308
-		$this->curArgs = $args;
309
-	}
310
-
311
-	/**
312
-	 * Analyzes the returned LDAP error and acts accordingly if not 0
313
-	 *
314
-	 * @param resource $resource the LDAP Connection resource
315
-	 * @throws ConstraintViolationException
316
-	 * @throws ServerNotAvailableException
317
-	 * @throws \Exception
318
-	 */
319
-	private function processLDAPError($resource) {
320
-		$errorCode = ldap_errno($resource);
321
-		if($errorCode === 0) {
322
-			return;
323
-		}
324
-		$errorMsg  = ldap_error($resource);
325
-
326
-		if($this->curFunc === 'ldap_get_entries'
327
-			&& $errorCode === -4) {
328
-		} else if ($errorCode === 32) {
329
-			//for now
330
-		} else if ($errorCode === 10) {
331
-			//referrals, we switch them off, but then there is AD :)
332
-		} else if ($errorCode === -1) {
333
-			throw new ServerNotAvailableException('Lost connection to LDAP server.');
334
-		} else if ($errorCode === 48) {
335
-			throw new \Exception('LDAP authentication method rejected', $errorCode);
336
-		} else if ($errorCode === 1) {
337
-			throw new \Exception('LDAP Operations error', $errorCode);
338
-		} else if ($errorCode === 19) {
339
-			ldap_get_option($this->curArgs[0], LDAP_OPT_ERROR_STRING, $extended_error);
340
-			throw new ConstraintViolationException(!empty($extended_error)?$extended_error:$errorMsg, $errorCode);
341
-		} else {
342
-			\OCP\Util::writeLog('user_ldap',
343
-				'LDAP error '.$errorMsg.' (' .
344
-				$errorCode.') after calling '.
345
-				$this->curFunc,
346
-				\OCP\Util::DEBUG);
347
-		}
348
-	}
349
-
350
-	/**
351
-	 * Called after an ldap method is run to act on LDAP error if necessary
352
-	 */
353
-	private function postFunctionCall() {
354
-		if($this->isResource($this->curArgs[0])) {
355
-			$resource = $this->curArgs[0];
356
-		} else if(
357
-			   $this->curFunc === 'ldap_search'
358
-			&& is_array($this->curArgs[0])
359
-			&& $this->isResource($this->curArgs[0][0])
360
-		) {
361
-			// we use always the same LDAP connection resource, is enough to
362
-			// take the first one.
363
-			$resource = $this->curArgs[0][0];
364
-		} else {
365
-			return;
366
-		}
367
-
368
-		$this->processLDAPError($resource);
369
-
370
-		$this->curFunc = '';
371
-		$this->curArgs = [];
372
-	}
36
+    protected $curFunc = '';
37
+    protected $curArgs = array();
38
+
39
+    /**
40
+     * @param resource $link
41
+     * @param string $dn
42
+     * @param string $password
43
+     * @return bool|mixed
44
+     */
45
+    public function bind($link, $dn, $password) {
46
+        return $this->invokeLDAPMethod('bind', $link, $dn, $password);
47
+    }
48
+
49
+    /**
50
+     * @param string $host
51
+     * @param string $port
52
+     * @return mixed
53
+     */
54
+    public function connect($host, $port) {
55
+        if(strpos($host, '://') === false) {
56
+            $host = 'ldap://' . $host;
57
+        }
58
+        if(strpos($host, ':', strpos($host, '://') + 1) === false) {
59
+            //ldap_connect ignores port parameter when URLs are passed
60
+            $host .= ':' . $port;
61
+        }
62
+        return $this->invokeLDAPMethod('connect', $host);
63
+    }
64
+
65
+    /**
66
+     * @param LDAP $link
67
+     * @param LDAP $result
68
+     * @param string $cookie
69
+     * @return bool|LDAP
70
+     */
71
+    public function controlPagedResultResponse($link, $result, &$cookie) {
72
+        $this->preFunctionCall('ldap_control_paged_result_response',
73
+            array($link, $result, $cookie));
74
+        $result = ldap_control_paged_result_response($link, $result, $cookie);
75
+        $this->postFunctionCall();
76
+
77
+        return $result;
78
+    }
79
+
80
+    /**
81
+     * @param LDAP $link
82
+     * @param int $pageSize
83
+     * @param bool $isCritical
84
+     * @param string $cookie
85
+     * @return mixed|true
86
+     */
87
+    public function controlPagedResult($link, $pageSize, $isCritical, $cookie) {
88
+        return $this->invokeLDAPMethod('control_paged_result', $link, $pageSize,
89
+                                        $isCritical, $cookie);
90
+    }
91
+
92
+    /**
93
+     * @param LDAP $link
94
+     * @param LDAP $result
95
+     * @return mixed
96
+     */
97
+    public function countEntries($link, $result) {
98
+        return $this->invokeLDAPMethod('count_entries', $link, $result);
99
+    }
100
+
101
+    /**
102
+     * @param LDAP $link
103
+     * @return integer
104
+     */
105
+    public function errno($link) {
106
+        return $this->invokeLDAPMethod('errno', $link);
107
+    }
108
+
109
+    /**
110
+     * @param LDAP $link
111
+     * @return string
112
+     */
113
+    public function error($link) {
114
+        return $this->invokeLDAPMethod('error', $link);
115
+    }
116
+
117
+    /**
118
+     * Splits DN into its component parts
119
+     * @param string $dn
120
+     * @param int @withAttrib
121
+     * @return array|false
122
+     * @link http://www.php.net/manual/en/function.ldap-explode-dn.php
123
+     */
124
+    public function explodeDN($dn, $withAttrib) {
125
+        return $this->invokeLDAPMethod('explode_dn', $dn, $withAttrib);
126
+    }
127
+
128
+    /**
129
+     * @param LDAP $link
130
+     * @param LDAP $result
131
+     * @return mixed
132
+     */
133
+    public function firstEntry($link, $result) {
134
+        return $this->invokeLDAPMethod('first_entry', $link, $result);
135
+    }
136
+
137
+    /**
138
+     * @param LDAP $link
139
+     * @param LDAP $result
140
+     * @return array|mixed
141
+     */
142
+    public function getAttributes($link, $result) {
143
+        return $this->invokeLDAPMethod('get_attributes', $link, $result);
144
+    }
145
+
146
+    /**
147
+     * @param LDAP $link
148
+     * @param LDAP $result
149
+     * @return mixed|string
150
+     */
151
+    public function getDN($link, $result) {
152
+        return $this->invokeLDAPMethod('get_dn', $link, $result);
153
+    }
154
+
155
+    /**
156
+     * @param LDAP $link
157
+     * @param LDAP $result
158
+     * @return array|mixed
159
+     */
160
+    public function getEntries($link, $result) {
161
+        return $this->invokeLDAPMethod('get_entries', $link, $result);
162
+    }
163
+
164
+    /**
165
+     * @param LDAP $link
166
+     * @param resource $result
167
+     * @return mixed
168
+     */
169
+    public function nextEntry($link, $result) {
170
+        return $this->invokeLDAPMethod('next_entry', $link, $result);
171
+    }
172
+
173
+    /**
174
+     * @param LDAP $link
175
+     * @param string $baseDN
176
+     * @param string $filter
177
+     * @param array $attr
178
+     * @return mixed
179
+     */
180
+    public function read($link, $baseDN, $filter, $attr) {
181
+        return $this->invokeLDAPMethod('read', $link, $baseDN, $filter, $attr);
182
+    }
183
+
184
+    /**
185
+     * @param LDAP $link
186
+     * @param string $baseDN
187
+     * @param string $filter
188
+     * @param array $attr
189
+     * @param int $attrsOnly
190
+     * @param int $limit
191
+     * @return mixed
192
+     */
193
+    public function search($link, $baseDN, $filter, $attr, $attrsOnly = 0, $limit = 0) {
194
+        return $this->invokeLDAPMethod('search', $link, $baseDN, $filter, $attr, $attrsOnly, $limit);
195
+    }
196
+
197
+    /**
198
+     * @param LDAP $link
199
+     * @param string $userDN
200
+     * @param string $password
201
+     * @return bool
202
+     */
203
+    public function modReplace($link, $userDN, $password) {
204
+        return $this->invokeLDAPMethod('mod_replace', $link, $userDN, array('userPassword' => $password));
205
+    }
206
+
207
+    /**
208
+     * @param LDAP $link
209
+     * @param string $option
210
+     * @param int $value
211
+     * @return bool|mixed
212
+     */
213
+    public function setOption($link, $option, $value) {
214
+        return $this->invokeLDAPMethod('set_option', $link, $option, $value);
215
+    }
216
+
217
+    /**
218
+     * @param LDAP $link
219
+     * @return mixed|true
220
+     */
221
+    public function startTls($link) {
222
+        return $this->invokeLDAPMethod('start_tls', $link);
223
+    }
224
+
225
+    /**
226
+     * @param resource $link
227
+     * @return bool|mixed
228
+     */
229
+    public function unbind($link) {
230
+        return $this->invokeLDAPMethod('unbind', $link);
231
+    }
232
+
233
+    /**
234
+     * Checks whether the server supports LDAP
235
+     * @return boolean if it the case, false otherwise
236
+     * */
237
+    public function areLDAPFunctionsAvailable() {
238
+        return function_exists('ldap_connect');
239
+    }
240
+
241
+    /**
242
+     * Checks whether PHP supports LDAP Paged Results
243
+     * @return boolean if it the case, false otherwise
244
+     * */
245
+    public function hasPagedResultSupport() {
246
+        $hasSupport = function_exists('ldap_control_paged_result')
247
+            && function_exists('ldap_control_paged_result_response');
248
+        return $hasSupport;
249
+    }
250
+
251
+    /**
252
+     * Checks whether the submitted parameter is a resource
253
+     * @param Resource $resource the resource variable to check
254
+     * @return bool true if it is a resource, false otherwise
255
+     */
256
+    public function isResource($resource) {
257
+        return is_resource($resource);
258
+    }
259
+
260
+    /**
261
+     * Checks whether the return value from LDAP is wrong or not.
262
+     *
263
+     * When using ldap_search we provide an array, in case multiple bases are
264
+     * configured. Thus, we need to check the array elements.
265
+     *
266
+     * @param $result
267
+     * @return bool
268
+     */
269
+    protected function isResultFalse($result) {
270
+        if($result === false) {
271
+            return true;
272
+        }
273
+
274
+        if($this->curFunc === 'ldap_search' && is_array($result)) {
275
+            foreach ($result as $singleResult) {
276
+                if($singleResult === false) {
277
+                    return true;
278
+                }
279
+            }
280
+        }
281
+
282
+        return false;
283
+    }
284
+
285
+    /**
286
+     * @return mixed
287
+     */
288
+    protected function invokeLDAPMethod() {
289
+        $arguments = func_get_args();
290
+        $func = 'ldap_' . array_shift($arguments);
291
+        if(function_exists($func)) {
292
+            $this->preFunctionCall($func, $arguments);
293
+            $result = call_user_func_array($func, $arguments);
294
+            if ($this->isResultFalse($result)) {
295
+                $this->postFunctionCall();
296
+            }
297
+            return $result;
298
+        }
299
+        return null;
300
+    }
301
+
302
+    /**
303
+     * @param string $functionName
304
+     * @param array $args
305
+     */
306
+    private function preFunctionCall($functionName, $args) {
307
+        $this->curFunc = $functionName;
308
+        $this->curArgs = $args;
309
+    }
310
+
311
+    /**
312
+     * Analyzes the returned LDAP error and acts accordingly if not 0
313
+     *
314
+     * @param resource $resource the LDAP Connection resource
315
+     * @throws ConstraintViolationException
316
+     * @throws ServerNotAvailableException
317
+     * @throws \Exception
318
+     */
319
+    private function processLDAPError($resource) {
320
+        $errorCode = ldap_errno($resource);
321
+        if($errorCode === 0) {
322
+            return;
323
+        }
324
+        $errorMsg  = ldap_error($resource);
325
+
326
+        if($this->curFunc === 'ldap_get_entries'
327
+            && $errorCode === -4) {
328
+        } else if ($errorCode === 32) {
329
+            //for now
330
+        } else if ($errorCode === 10) {
331
+            //referrals, we switch them off, but then there is AD :)
332
+        } else if ($errorCode === -1) {
333
+            throw new ServerNotAvailableException('Lost connection to LDAP server.');
334
+        } else if ($errorCode === 48) {
335
+            throw new \Exception('LDAP authentication method rejected', $errorCode);
336
+        } else if ($errorCode === 1) {
337
+            throw new \Exception('LDAP Operations error', $errorCode);
338
+        } else if ($errorCode === 19) {
339
+            ldap_get_option($this->curArgs[0], LDAP_OPT_ERROR_STRING, $extended_error);
340
+            throw new ConstraintViolationException(!empty($extended_error)?$extended_error:$errorMsg, $errorCode);
341
+        } else {
342
+            \OCP\Util::writeLog('user_ldap',
343
+                'LDAP error '.$errorMsg.' (' .
344
+                $errorCode.') after calling '.
345
+                $this->curFunc,
346
+                \OCP\Util::DEBUG);
347
+        }
348
+    }
349
+
350
+    /**
351
+     * Called after an ldap method is run to act on LDAP error if necessary
352
+     */
353
+    private function postFunctionCall() {
354
+        if($this->isResource($this->curArgs[0])) {
355
+            $resource = $this->curArgs[0];
356
+        } else if(
357
+                $this->curFunc === 'ldap_search'
358
+            && is_array($this->curArgs[0])
359
+            && $this->isResource($this->curArgs[0][0])
360
+        ) {
361
+            // we use always the same LDAP connection resource, is enough to
362
+            // take the first one.
363
+            $resource = $this->curArgs[0][0];
364
+        } else {
365
+            return;
366
+        }
367
+
368
+        $this->processLDAPError($resource);
369
+
370
+        $this->curFunc = '';
371
+        $this->curArgs = [];
372
+    }
373 373
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/User/DeletedUsersIndex.php 2 patches
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -31,84 +31,84 @@
 block discarded – undo
31 31
  * @package OCA\User_LDAP
32 32
  */
33 33
 class DeletedUsersIndex {
34
-	/**
35
-	 * @var \OCP\IConfig $config
36
-	 */
37
-	protected $config;
34
+    /**
35
+     * @var \OCP\IConfig $config
36
+     */
37
+    protected $config;
38 38
 
39
-	/**
40
-	 * @var \OCP\IDBConnection $db
41
-	 */
42
-	protected $db;
39
+    /**
40
+     * @var \OCP\IDBConnection $db
41
+     */
42
+    protected $db;
43 43
 
44
-	/**
45
-	 * @var \OCA\User_LDAP\Mapping\UserMapping $mapping
46
-	 */
47
-	protected $mapping;
44
+    /**
45
+     * @var \OCA\User_LDAP\Mapping\UserMapping $mapping
46
+     */
47
+    protected $mapping;
48 48
 
49
-	/**
50
-	 * @var array $deletedUsers
51
-	 */
52
-	protected $deletedUsers;
49
+    /**
50
+     * @var array $deletedUsers
51
+     */
52
+    protected $deletedUsers;
53 53
 
54
-	/**
55
-	 * @param \OCP\IConfig $config
56
-	 * @param \OCP\IDBConnection $db
57
-	 * @param \OCA\User_LDAP\Mapping\UserMapping $mapping
58
-	 */
59
-	public function __construct(\OCP\IConfig $config, \OCP\IDBConnection $db, UserMapping $mapping) {
60
-		$this->config = $config;
61
-		$this->db = $db;
62
-		$this->mapping = $mapping;
63
-	}
54
+    /**
55
+     * @param \OCP\IConfig $config
56
+     * @param \OCP\IDBConnection $db
57
+     * @param \OCA\User_LDAP\Mapping\UserMapping $mapping
58
+     */
59
+    public function __construct(\OCP\IConfig $config, \OCP\IDBConnection $db, UserMapping $mapping) {
60
+        $this->config = $config;
61
+        $this->db = $db;
62
+        $this->mapping = $mapping;
63
+    }
64 64
 
65
-	/**
66
-	 * reads LDAP users marked as deleted from the database
67
-	 * @return \OCA\User_LDAP\User\OfflineUser[]
68
-	 */
69
-	private function fetchDeletedUsers() {
70
-		$deletedUsers = $this->config->getUsersForUserValue(
71
-			'user_ldap', 'isDeleted', '1');
65
+    /**
66
+     * reads LDAP users marked as deleted from the database
67
+     * @return \OCA\User_LDAP\User\OfflineUser[]
68
+     */
69
+    private function fetchDeletedUsers() {
70
+        $deletedUsers = $this->config->getUsersForUserValue(
71
+            'user_ldap', 'isDeleted', '1');
72 72
 
73
-		$userObjects = array();
74
-		foreach($deletedUsers as $user) {
75
-			$userObjects[] = new OfflineUser($user, $this->config, $this->db, $this->mapping);
76
-		}
77
-		$this->deletedUsers = $userObjects;
73
+        $userObjects = array();
74
+        foreach($deletedUsers as $user) {
75
+            $userObjects[] = new OfflineUser($user, $this->config, $this->db, $this->mapping);
76
+        }
77
+        $this->deletedUsers = $userObjects;
78 78
 
79
-		return $this->deletedUsers;
80
-	}
79
+        return $this->deletedUsers;
80
+    }
81 81
 
82
-	/**
83
-	 * returns all LDAP users that are marked as deleted
84
-	 * @return \OCA\User_LDAP\User\OfflineUser[]
85
-	 */
86
-	public function getUsers() {
87
-		if(is_array($this->deletedUsers)) {
88
-			return $this->deletedUsers;
89
-		}
90
-		return $this->fetchDeletedUsers();
91
-	}
82
+    /**
83
+     * returns all LDAP users that are marked as deleted
84
+     * @return \OCA\User_LDAP\User\OfflineUser[]
85
+     */
86
+    public function getUsers() {
87
+        if(is_array($this->deletedUsers)) {
88
+            return $this->deletedUsers;
89
+        }
90
+        return $this->fetchDeletedUsers();
91
+    }
92 92
 
93
-	/**
94
-	 * whether at least one user was detected as deleted
95
-	 * @return bool
96
-	 */
97
-	public function hasUsers() {
98
-		if($this->deletedUsers === false) {
99
-			$this->fetchDeletedUsers();
100
-		}
101
-		if(is_array($this->deletedUsers) && count($this->deletedUsers) > 0) {
102
-			return true;
103
-		}
104
-		return false;
105
-	}
93
+    /**
94
+     * whether at least one user was detected as deleted
95
+     * @return bool
96
+     */
97
+    public function hasUsers() {
98
+        if($this->deletedUsers === false) {
99
+            $this->fetchDeletedUsers();
100
+        }
101
+        if(is_array($this->deletedUsers) && count($this->deletedUsers) > 0) {
102
+            return true;
103
+        }
104
+        return false;
105
+    }
106 106
 
107
-	/**
108
-	 * marks a user as deleted
109
-	 * @param string $ocName
110
-	 */
111
-	public function markUser($ocName) {
112
-		$this->config->setUserValue($ocName, 'user_ldap', 'isDeleted', '1');
113
-	}
107
+    /**
108
+     * marks a user as deleted
109
+     * @param string $ocName
110
+     */
111
+    public function markUser($ocName) {
112
+        $this->config->setUserValue($ocName, 'user_ldap', 'isDeleted', '1');
113
+    }
114 114
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 			'user_ldap', 'isDeleted', '1');
72 72
 
73 73
 		$userObjects = array();
74
-		foreach($deletedUsers as $user) {
74
+		foreach ($deletedUsers as $user) {
75 75
 			$userObjects[] = new OfflineUser($user, $this->config, $this->db, $this->mapping);
76 76
 		}
77 77
 		$this->deletedUsers = $userObjects;
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 	 * @return \OCA\User_LDAP\User\OfflineUser[]
85 85
 	 */
86 86
 	public function getUsers() {
87
-		if(is_array($this->deletedUsers)) {
87
+		if (is_array($this->deletedUsers)) {
88 88
 			return $this->deletedUsers;
89 89
 		}
90 90
 		return $this->fetchDeletedUsers();
@@ -95,10 +95,10 @@  discard block
 block discarded – undo
95 95
 	 * @return bool
96 96
 	 */
97 97
 	public function hasUsers() {
98
-		if($this->deletedUsers === false) {
98
+		if ($this->deletedUsers === false) {
99 99
 			$this->fetchDeletedUsers();
100 100
 		}
101
-		if(is_array($this->deletedUsers) && count($this->deletedUsers) > 0) {
101
+		if (is_array($this->deletedUsers) && count($this->deletedUsers) > 0) {
102 102
 			return true;
103 103
 		}
104 104
 		return false;
Please login to merge, or discard this patch.
apps/user_ldap/lib/User/IUserTools.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -30,13 +30,13 @@
 block discarded – undo
30 30
  * defines methods that are required by User class for LDAP interaction
31 31
  */
32 32
 interface IUserTools {
33
-	public function getConnection();
33
+    public function getConnection();
34 34
 
35
-	public function readAttribute($dn, $attr, $filter = 'objectClass=*');
35
+    public function readAttribute($dn, $attr, $filter = 'objectClass=*');
36 36
 
37
-	public function stringResemblesDN($string);
37
+    public function stringResemblesDN($string);
38 38
 
39
-	public function dn2username($dn, $ldapname = null);
39
+    public function dn2username($dn, $ldapname = null);
40 40
 
41
-	public function username2dn($name);
41
+    public function username2dn($name);
42 42
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/User/OfflineUser.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -179,14 +179,14 @@  discard block
 block discarded – undo
179 179
 	 * reads the user details
180 180
 	 */
181 181
 	protected function fetchDetails() {
182
-		$properties = array (
182
+		$properties = array(
183 183
 			'displayName' => 'user_ldap',
184 184
 			'uid'         => 'user_ldap',
185 185
 			'homePath'    => 'user_ldap',
186 186
 			'email'       => 'settings',
187 187
 			'lastLogin'   => 'login'
188 188
 		);
189
-		foreach($properties as $property => $app) {
189
+		foreach ($properties as $property => $app) {
190 190
 			$this->$property = $this->config->getUserValue($this->ocName, $app, $property, '');
191 191
 		}
192 192
 
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 		', 1);
210 210
 		$query->execute(array($this->ocName));
211 211
 		$sResult = $query->fetchColumn(0);
212
-		if(intval($sResult) === 1) {
212
+		if (intval($sResult) === 1) {
213 213
 			$this->hasActiveShares = true;
214 214
 			return;
215 215
 		}
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 		', 1);
222 222
 		$query->execute(array($this->ocName));
223 223
 		$sResult = $query->fetchColumn(0);
224
-		if(intval($sResult) === 1) {
224
+		if (intval($sResult) === 1) {
225 225
 			$this->hasActiveShares = true;
226 226
 			return;
227 227
 		}
Please login to merge, or discard this patch.
Indentation   +193 added lines, -193 removed lines patch added patch discarded remove patch
@@ -29,205 +29,205 @@
 block discarded – undo
29 29
 use OCP\IDBConnection;
30 30
 
31 31
 class OfflineUser {
32
-	/**
33
-	 * @var string $ocName
34
-	 */
35
-	protected $ocName;
36
-	/**
37
-	 * @var string $dn
38
-	 */
39
-	protected $dn;
40
-	/**
41
-	 * @var string $uid the UID as provided by LDAP
42
-	 */
43
-	protected $uid;
44
-	/**
45
-	 * @var string $displayName
46
-	 */
47
-	protected $displayName;
48
-	/**
49
-	 * @var string $homePath
50
-	 */
51
-	protected $homePath;
52
-	/**
53
-	 * @var string $lastLogin the timestamp of the last login
54
-	 */
55
-	protected $lastLogin;
56
-	/**
57
-	 * @var string $email
58
-	 */
59
-	protected $email;
60
-	/**
61
-	 * @var bool $hasActiveShares
62
-	 */
63
-	protected $hasActiveShares;
64
-	/**
65
-	 * @var IConfig $config
66
-	 */
67
-	protected $config;
68
-	/**
69
-	 * @var IDBConnection $db
70
-	 */
71
-	protected $db;
72
-	/**
73
-	 * @var \OCA\User_LDAP\Mapping\UserMapping
74
-	 */
75
-	protected $mapping;
76
-
77
-	/**
78
-	 * @param string $ocName
79
-	 * @param IConfig $config
80
-	 * @param IDBConnection $db
81
-	 * @param \OCA\User_LDAP\Mapping\UserMapping $mapping
82
-	 */
83
-	public function __construct($ocName, IConfig $config, IDBConnection $db, UserMapping $mapping) {
84
-		$this->ocName = $ocName;
85
-		$this->config = $config;
86
-		$this->db = $db;
87
-		$this->mapping = $mapping;
88
-		$this->fetchDetails();
89
-	}
90
-
91
-	/**
92
-	 * remove the Delete-flag from the user.
93
-	 */
94
-	public function unmark() {
95
-		$this->config->setUserValue($this->ocName, 'user_ldap', 'isDeleted', '0');
96
-	}
97
-
98
-	/**
99
-	 * exports the user details in an assoc array
100
-	 * @return array
101
-	 */
102
-	public function export() {
103
-		$data = array();
104
-		$data['ocName'] = $this->getOCName();
105
-		$data['dn'] = $this->getDN();
106
-		$data['uid'] = $this->getUID();
107
-		$data['displayName'] = $this->getDisplayName();
108
-		$data['homePath'] = $this->getHomePath();
109
-		$data['lastLogin'] = $this->getLastLogin();
110
-		$data['email'] = $this->getEmail();
111
-		$data['hasActiveShares'] = $this->getHasActiveShares();
112
-
113
-		return $data;
114
-	}
115
-
116
-	/**
117
-	 * getter for Nextcloud internal name
118
-	 * @return string
119
-	 */
120
-	public function getOCName() {
121
-		return $this->ocName;
122
-	}
123
-
124
-	/**
125
-	 * getter for LDAP uid
126
-	 * @return string
127
-	 */
128
-	public function getUID() {
129
-		return $this->uid;
130
-	}
131
-
132
-	/**
133
-	 * getter for LDAP DN
134
-	 * @return string
135
-	 */
136
-	public function getDN() {
137
-		return $this->dn;
138
-	}
139
-
140
-	/**
141
-	 * getter for display name
142
-	 * @return string
143
-	 */
144
-	public function getDisplayName() {
145
-		return $this->displayName;
146
-	}
147
-
148
-	/**
149
-	 * getter for email
150
-	 * @return string
151
-	 */
152
-	public function getEmail() {
153
-		return $this->email;
154
-	}
155
-
156
-	/**
157
-	 * getter for home directory path
158
-	 * @return string
159
-	 */
160
-	public function getHomePath() {
161
-		return $this->homePath;
162
-	}
163
-
164
-	/**
165
-	 * getter for the last login timestamp
166
-	 * @return int
167
-	 */
168
-	public function getLastLogin() {
169
-		return intval($this->lastLogin);
170
-	}
171
-
172
-	/**
173
-	 * getter for having active shares
174
-	 * @return bool
175
-	 */
176
-	public function getHasActiveShares() {
177
-		return $this->hasActiveShares;
178
-	}
179
-
180
-	/**
181
-	 * reads the user details
182
-	 */
183
-	protected function fetchDetails() {
184
-		$properties = array (
185
-			'displayName' => 'user_ldap',
186
-			'uid'         => 'user_ldap',
187
-			'homePath'    => 'user_ldap',
188
-			'email'       => 'settings',
189
-			'lastLogin'   => 'login'
190
-		);
191
-		foreach($properties as $property => $app) {
192
-			$this->$property = $this->config->getUserValue($this->ocName, $app, $property, '');
193
-		}
194
-
195
-		$dn = $this->mapping->getDNByName($this->ocName);
196
-		$this->dn = ($dn !== false) ? $dn : '';
197
-
198
-		$this->determineShares();
199
-	}
200
-
201
-
202
-	/**
203
-	 * finds out whether the user has active shares. The result is stored in
204
-	 * $this->hasActiveShares
205
-	 */
206
-	protected function determineShares() {
207
-		$query = $this->db->prepare('
32
+    /**
33
+     * @var string $ocName
34
+     */
35
+    protected $ocName;
36
+    /**
37
+     * @var string $dn
38
+     */
39
+    protected $dn;
40
+    /**
41
+     * @var string $uid the UID as provided by LDAP
42
+     */
43
+    protected $uid;
44
+    /**
45
+     * @var string $displayName
46
+     */
47
+    protected $displayName;
48
+    /**
49
+     * @var string $homePath
50
+     */
51
+    protected $homePath;
52
+    /**
53
+     * @var string $lastLogin the timestamp of the last login
54
+     */
55
+    protected $lastLogin;
56
+    /**
57
+     * @var string $email
58
+     */
59
+    protected $email;
60
+    /**
61
+     * @var bool $hasActiveShares
62
+     */
63
+    protected $hasActiveShares;
64
+    /**
65
+     * @var IConfig $config
66
+     */
67
+    protected $config;
68
+    /**
69
+     * @var IDBConnection $db
70
+     */
71
+    protected $db;
72
+    /**
73
+     * @var \OCA\User_LDAP\Mapping\UserMapping
74
+     */
75
+    protected $mapping;
76
+
77
+    /**
78
+     * @param string $ocName
79
+     * @param IConfig $config
80
+     * @param IDBConnection $db
81
+     * @param \OCA\User_LDAP\Mapping\UserMapping $mapping
82
+     */
83
+    public function __construct($ocName, IConfig $config, IDBConnection $db, UserMapping $mapping) {
84
+        $this->ocName = $ocName;
85
+        $this->config = $config;
86
+        $this->db = $db;
87
+        $this->mapping = $mapping;
88
+        $this->fetchDetails();
89
+    }
90
+
91
+    /**
92
+     * remove the Delete-flag from the user.
93
+     */
94
+    public function unmark() {
95
+        $this->config->setUserValue($this->ocName, 'user_ldap', 'isDeleted', '0');
96
+    }
97
+
98
+    /**
99
+     * exports the user details in an assoc array
100
+     * @return array
101
+     */
102
+    public function export() {
103
+        $data = array();
104
+        $data['ocName'] = $this->getOCName();
105
+        $data['dn'] = $this->getDN();
106
+        $data['uid'] = $this->getUID();
107
+        $data['displayName'] = $this->getDisplayName();
108
+        $data['homePath'] = $this->getHomePath();
109
+        $data['lastLogin'] = $this->getLastLogin();
110
+        $data['email'] = $this->getEmail();
111
+        $data['hasActiveShares'] = $this->getHasActiveShares();
112
+
113
+        return $data;
114
+    }
115
+
116
+    /**
117
+     * getter for Nextcloud internal name
118
+     * @return string
119
+     */
120
+    public function getOCName() {
121
+        return $this->ocName;
122
+    }
123
+
124
+    /**
125
+     * getter for LDAP uid
126
+     * @return string
127
+     */
128
+    public function getUID() {
129
+        return $this->uid;
130
+    }
131
+
132
+    /**
133
+     * getter for LDAP DN
134
+     * @return string
135
+     */
136
+    public function getDN() {
137
+        return $this->dn;
138
+    }
139
+
140
+    /**
141
+     * getter for display name
142
+     * @return string
143
+     */
144
+    public function getDisplayName() {
145
+        return $this->displayName;
146
+    }
147
+
148
+    /**
149
+     * getter for email
150
+     * @return string
151
+     */
152
+    public function getEmail() {
153
+        return $this->email;
154
+    }
155
+
156
+    /**
157
+     * getter for home directory path
158
+     * @return string
159
+     */
160
+    public function getHomePath() {
161
+        return $this->homePath;
162
+    }
163
+
164
+    /**
165
+     * getter for the last login timestamp
166
+     * @return int
167
+     */
168
+    public function getLastLogin() {
169
+        return intval($this->lastLogin);
170
+    }
171
+
172
+    /**
173
+     * getter for having active shares
174
+     * @return bool
175
+     */
176
+    public function getHasActiveShares() {
177
+        return $this->hasActiveShares;
178
+    }
179
+
180
+    /**
181
+     * reads the user details
182
+     */
183
+    protected function fetchDetails() {
184
+        $properties = array (
185
+            'displayName' => 'user_ldap',
186
+            'uid'         => 'user_ldap',
187
+            'homePath'    => 'user_ldap',
188
+            'email'       => 'settings',
189
+            'lastLogin'   => 'login'
190
+        );
191
+        foreach($properties as $property => $app) {
192
+            $this->$property = $this->config->getUserValue($this->ocName, $app, $property, '');
193
+        }
194
+
195
+        $dn = $this->mapping->getDNByName($this->ocName);
196
+        $this->dn = ($dn !== false) ? $dn : '';
197
+
198
+        $this->determineShares();
199
+    }
200
+
201
+
202
+    /**
203
+     * finds out whether the user has active shares. The result is stored in
204
+     * $this->hasActiveShares
205
+     */
206
+    protected function determineShares() {
207
+        $query = $this->db->prepare('
208 208
 			SELECT COUNT(`uid_owner`)
209 209
 			FROM `*PREFIX*share`
210 210
 			WHERE `uid_owner` = ?
211 211
 		', 1);
212
-		$query->execute(array($this->ocName));
213
-		$sResult = $query->fetchColumn(0);
214
-		if(intval($sResult) === 1) {
215
-			$this->hasActiveShares = true;
216
-			return;
217
-		}
218
-
219
-		$query = $this->db->prepare('
212
+        $query->execute(array($this->ocName));
213
+        $sResult = $query->fetchColumn(0);
214
+        if(intval($sResult) === 1) {
215
+            $this->hasActiveShares = true;
216
+            return;
217
+        }
218
+
219
+        $query = $this->db->prepare('
220 220
 			SELECT COUNT(`owner`)
221 221
 			FROM `*PREFIX*share_external`
222 222
 			WHERE `owner` = ?
223 223
 		', 1);
224
-		$query->execute(array($this->ocName));
225
-		$sResult = $query->fetchColumn(0);
226
-		if(intval($sResult) === 1) {
227
-			$this->hasActiveShares = true;
228
-			return;
229
-		}
230
-
231
-		$this->hasActiveShares = false;
232
-	}
224
+        $query->execute(array($this->ocName));
225
+        $sResult = $query->fetchColumn(0);
226
+        if(intval($sResult) === 1) {
227
+            $this->hasActiveShares = true;
228
+            return;
229
+        }
230
+
231
+        $this->hasActiveShares = false;
232
+    }
233 233
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/IUserLDAP.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -24,26 +24,26 @@
 block discarded – undo
24 24
 
25 25
 interface IUserLDAP {
26 26
 
27
-	//Functions used by LDAPProvider
27
+    //Functions used by LDAPProvider
28 28
 	
29
-	/**
30
-	 * Return access for LDAP interaction.
31
-	 * @param string $uid
32
-	 * @return Access instance of Access for LDAP interaction
33
-	 */
34
-	public function getLDAPAccess($uid);
29
+    /**
30
+     * Return access for LDAP interaction.
31
+     * @param string $uid
32
+     * @return Access instance of Access for LDAP interaction
33
+     */
34
+    public function getLDAPAccess($uid);
35 35
 	
36
-	/**
37
-	 * Return a new LDAP connection for the specified user.
38
-	 * @param string $uid
39
-	 * @return resource of the LDAP connection
40
-	 */
41
-	public function getNewLDAPConnection($uid);
36
+    /**
37
+     * Return a new LDAP connection for the specified user.
38
+     * @param string $uid
39
+     * @return resource of the LDAP connection
40
+     */
41
+    public function getNewLDAPConnection($uid);
42 42
 
43
-	/**
44
-	 * Return the username for the given LDAP DN, if available.
45
-	 * @param string $dn
46
-	 * @return string|false with the username
47
-	 */
48
-	public function dn2UserName($dn);
43
+    /**
44
+     * Return the username for the given LDAP DN, if available.
45
+     * @param string $dn
46
+     * @return string|false with the username
47
+     */
48
+    public function dn2UserName($dn);
49 49
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/Controller/ConfigAPIController.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -147,12 +147,12 @@  discard block
 block discarded – undo
147 147
 	public function delete($configID) {
148 148
 		try {
149 149
 			$this->ensureConfigIDExists($configID);
150
-			if(!$this->ldapHelper->deleteServerConfiguration($configID)) {
150
+			if (!$this->ldapHelper->deleteServerConfiguration($configID)) {
151 151
 				throw new OCSException('Could not delete configuration');
152 152
 			}
153
-		} catch(OCSException $e) {
153
+		} catch (OCSException $e) {
154 154
 			throw $e;
155
-		} catch(\Exception $e) {
155
+		} catch (\Exception $e) {
156 156
 			$this->logger->logException($e);
157 157
 			throw new OCSException('An issue occurred when deleting the config.');
158 158
 		}
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 		try {
188 188
 			$this->ensureConfigIDExists($configID);
189 189
 
190
-			if(!is_array($configData)) {
190
+			if (!is_array($configData)) {
191 191
 				throw new OCSBadRequestException('configData is not properly set');
192 192
 			}
193 193
 
@@ -195,13 +195,13 @@  discard block
 block discarded – undo
195 195
 			$configKeys = $configuration->getConfigTranslationArray();
196 196
 
197 197
 			foreach ($configKeys as $i => $key) {
198
-				if(isset($configData[$key])) {
198
+				if (isset($configData[$key])) {
199 199
 					$configuration->$key = $configData[$key];
200 200
 				}
201 201
 			}
202 202
 
203 203
 			$configuration->saveConfiguration();
204
-		} catch(OCSException $e) {
204
+		} catch (OCSException $e) {
205 205
 			throw $e;
206 206
 		} catch (\Exception $e) {
207 207
 			$this->logger->logException($e);
@@ -288,16 +288,16 @@  discard block
 block discarded – undo
288 288
 
289 289
 			$config = new Configuration($configID);
290 290
 			$data = $config->getConfiguration();
291
-			if(!boolval(intval($showPassword))) {
291
+			if (!boolval(intval($showPassword))) {
292 292
 				$data['ldapAgentPassword'] = '***';
293 293
 			}
294 294
 			foreach ($data as $key => $value) {
295
-				if(is_array($value)) {
295
+				if (is_array($value)) {
296 296
 					$value = implode(';', $value);
297 297
 					$data[$key] = $value;
298 298
 				}
299 299
 			}
300
-		} catch(OCSException $e) {
300
+		} catch (OCSException $e) {
301 301
 			throw $e;
302 302
 		} catch (\Exception $e) {
303 303
 			$this->logger->logException($e);
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 	 */
316 316
 	private function ensureConfigIDExists($configID) {
317 317
 		$prefixes = $this->ldapHelper->getServerConfigurationPrefixes();
318
-		if(!in_array($configID, $prefixes, true)) {
318
+		if (!in_array($configID, $prefixes, true)) {
319 319
 			throw new OCSNotFoundException('Config ID not found');
320 320
 		}
321 321
 	}
Please login to merge, or discard this patch.
Indentation   +260 added lines, -260 removed lines patch added patch discarded remove patch
@@ -39,281 +39,281 @@
 block discarded – undo
39 39
 
40 40
 class ConfigAPIController extends OCSController {
41 41
 
42
-	/** @var Helper */
43
-	private $ldapHelper;
42
+    /** @var Helper */
43
+    private $ldapHelper;
44 44
 
45
-	/** @var ILogger */
46
-	private $logger;
45
+    /** @var ILogger */
46
+    private $logger;
47 47
 
48
-	public function __construct(
49
-		$appName,
50
-		IRequest $request,
51
-		CapabilitiesManager $capabilitiesManager,
52
-		IUserSession $userSession,
53
-		IUserManager $userManager,
54
-		Manager $keyManager,
55
-		Helper $ldapHelper,
56
-		ILogger $logger
57
-	) {
58
-		parent::__construct(
59
-			$appName,
60
-			$request,
61
-			$capabilitiesManager,
62
-			$userSession,
63
-			$userManager,
64
-			$keyManager
65
-		);
48
+    public function __construct(
49
+        $appName,
50
+        IRequest $request,
51
+        CapabilitiesManager $capabilitiesManager,
52
+        IUserSession $userSession,
53
+        IUserManager $userManager,
54
+        Manager $keyManager,
55
+        Helper $ldapHelper,
56
+        ILogger $logger
57
+    ) {
58
+        parent::__construct(
59
+            $appName,
60
+            $request,
61
+            $capabilitiesManager,
62
+            $userSession,
63
+            $userManager,
64
+            $keyManager
65
+        );
66 66
 
67 67
 
68
-		$this->ldapHelper = $ldapHelper;
69
-		$this->logger = $logger;
70
-	}
68
+        $this->ldapHelper = $ldapHelper;
69
+        $this->logger = $logger;
70
+    }
71 71
 
72
-	/**
73
-	 * creates a new (empty) configuration and returns the resulting prefix
74
-	 *
75
-	 * Example: curl -X POST -H "OCS-APIREQUEST: true"  -u $admin:$password \
76
-	 *   https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config
77
-	 *
78
-	 * results in:
79
-	 *
80
-	 * <?xml version="1.0"?>
81
-	 * <ocs>
82
-	 *   <meta>
83
-	 *     <status>ok</status>
84
-	 *     <statuscode>200</statuscode>
85
-	 *     <message>OK</message>
86
-	 *   </meta>
87
-	 *   <data>
88
-	 *     <configID>s40</configID>
89
-	 *   </data>
90
-	 * </ocs>
91
-	 *
92
-	 * Failing example: if an exception is thrown (e.g. Database connection lost)
93
-	 * the detailed error will be logged. The output will then look like:
94
-	 *
95
-	 * <?xml version="1.0"?>
96
-	 * <ocs>
97
-	 *   <meta>
98
-	 *     <status>failure</status>
99
-	 *     <statuscode>999</statuscode>
100
-	 *     <message>An issue occurred when creating the new config.</message>
101
-	 *   </meta>
102
-	 *   <data/>
103
-	 * </ocs>
104
-	 *
105
-	 * For JSON output provide the format=json parameter
106
-	 *
107
-	 * @return DataResponse
108
-	 * @throws OCSException
109
-	 */
110
-	public function create() {
111
-		try {
112
-			$configPrefix = $this->ldapHelper->getNextServerConfigurationPrefix();
113
-			$configHolder = new Configuration($configPrefix);
114
-			$configHolder->saveConfiguration();
115
-		} catch (\Exception $e) {
116
-			$this->logger->logException($e);
117
-			throw new OCSException('An issue occurred when creating the new config.');
118
-		}
119
-		return new DataResponse(['configID' => $configPrefix]);
120
-	}
72
+    /**
73
+     * creates a new (empty) configuration and returns the resulting prefix
74
+     *
75
+     * Example: curl -X POST -H "OCS-APIREQUEST: true"  -u $admin:$password \
76
+     *   https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config
77
+     *
78
+     * results in:
79
+     *
80
+     * <?xml version="1.0"?>
81
+     * <ocs>
82
+     *   <meta>
83
+     *     <status>ok</status>
84
+     *     <statuscode>200</statuscode>
85
+     *     <message>OK</message>
86
+     *   </meta>
87
+     *   <data>
88
+     *     <configID>s40</configID>
89
+     *   </data>
90
+     * </ocs>
91
+     *
92
+     * Failing example: if an exception is thrown (e.g. Database connection lost)
93
+     * the detailed error will be logged. The output will then look like:
94
+     *
95
+     * <?xml version="1.0"?>
96
+     * <ocs>
97
+     *   <meta>
98
+     *     <status>failure</status>
99
+     *     <statuscode>999</statuscode>
100
+     *     <message>An issue occurred when creating the new config.</message>
101
+     *   </meta>
102
+     *   <data/>
103
+     * </ocs>
104
+     *
105
+     * For JSON output provide the format=json parameter
106
+     *
107
+     * @return DataResponse
108
+     * @throws OCSException
109
+     */
110
+    public function create() {
111
+        try {
112
+            $configPrefix = $this->ldapHelper->getNextServerConfigurationPrefix();
113
+            $configHolder = new Configuration($configPrefix);
114
+            $configHolder->saveConfiguration();
115
+        } catch (\Exception $e) {
116
+            $this->logger->logException($e);
117
+            throw new OCSException('An issue occurred when creating the new config.');
118
+        }
119
+        return new DataResponse(['configID' => $configPrefix]);
120
+    }
121 121
 
122
-	/**
123
-	 * Deletes a LDAP configuration, if present.
124
-	 *
125
-	 * Example:
126
-	 *   curl -X DELETE -H "OCS-APIREQUEST: true" -u $admin:$password \
127
-	 *    https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config/s60
128
-	 *
129
-	 * <?xml version="1.0"?>
130
-	 * <ocs>
131
-	 *   <meta>
132
-	 *     <status>ok</status>
133
-	 *     <statuscode>200</statuscode>
134
-	 *     <message>OK</message>
135
-	 *   </meta>
136
-	 *   <data/>
137
-	 * </ocs>
138
-	 *
139
-	 * @param string $configID
140
-	 * @return DataResponse
141
-	 * @throws OCSBadRequestException
142
-	 * @throws OCSException
143
-	 */
144
-	public function delete($configID) {
145
-		try {
146
-			$this->ensureConfigIDExists($configID);
147
-			if(!$this->ldapHelper->deleteServerConfiguration($configID)) {
148
-				throw new OCSException('Could not delete configuration');
149
-			}
150
-		} catch(OCSException $e) {
151
-			throw $e;
152
-		} catch(\Exception $e) {
153
-			$this->logger->logException($e);
154
-			throw new OCSException('An issue occurred when deleting the config.');
155
-		}
122
+    /**
123
+     * Deletes a LDAP configuration, if present.
124
+     *
125
+     * Example:
126
+     *   curl -X DELETE -H "OCS-APIREQUEST: true" -u $admin:$password \
127
+     *    https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config/s60
128
+     *
129
+     * <?xml version="1.0"?>
130
+     * <ocs>
131
+     *   <meta>
132
+     *     <status>ok</status>
133
+     *     <statuscode>200</statuscode>
134
+     *     <message>OK</message>
135
+     *   </meta>
136
+     *   <data/>
137
+     * </ocs>
138
+     *
139
+     * @param string $configID
140
+     * @return DataResponse
141
+     * @throws OCSBadRequestException
142
+     * @throws OCSException
143
+     */
144
+    public function delete($configID) {
145
+        try {
146
+            $this->ensureConfigIDExists($configID);
147
+            if(!$this->ldapHelper->deleteServerConfiguration($configID)) {
148
+                throw new OCSException('Could not delete configuration');
149
+            }
150
+        } catch(OCSException $e) {
151
+            throw $e;
152
+        } catch(\Exception $e) {
153
+            $this->logger->logException($e);
154
+            throw new OCSException('An issue occurred when deleting the config.');
155
+        }
156 156
 
157
-		return new DataResponse();
158
-	}
157
+        return new DataResponse();
158
+    }
159 159
 
160
-	/**
161
-	 * modifies a configuration
162
-	 *
163
-	 * Example:
164
-	 *   curl -X PUT -d "configData[ldapHost]=ldaps://my.ldap.server&configData[ldapPort]=636" \
165
-	 *    -H "OCS-APIREQUEST: true" -u $admin:$password \
166
-	 *    https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config/s60
167
-	 *
168
-	 * <?xml version="1.0"?>
169
-	 * <ocs>
170
-	 *   <meta>
171
-	 *     <status>ok</status>
172
-	 *     <statuscode>200</statuscode>
173
-	 *     <message>OK</message>
174
-	 *   </meta>
175
-	 *   <data/>
176
-	 * </ocs>
177
-	 *
178
-	 * @param string $configID
179
-	 * @param array $configData
180
-	 * @return DataResponse
181
-	 * @throws OCSException
182
-	 */
183
-	public function modify($configID, $configData) {
184
-		try {
185
-			$this->ensureConfigIDExists($configID);
160
+    /**
161
+     * modifies a configuration
162
+     *
163
+     * Example:
164
+     *   curl -X PUT -d "configData[ldapHost]=ldaps://my.ldap.server&configData[ldapPort]=636" \
165
+     *    -H "OCS-APIREQUEST: true" -u $admin:$password \
166
+     *    https://nextcloud.server/ocs/v2.php/apps/user_ldap/api/v1/config/s60
167
+     *
168
+     * <?xml version="1.0"?>
169
+     * <ocs>
170
+     *   <meta>
171
+     *     <status>ok</status>
172
+     *     <statuscode>200</statuscode>
173
+     *     <message>OK</message>
174
+     *   </meta>
175
+     *   <data/>
176
+     * </ocs>
177
+     *
178
+     * @param string $configID
179
+     * @param array $configData
180
+     * @return DataResponse
181
+     * @throws OCSException
182
+     */
183
+    public function modify($configID, $configData) {
184
+        try {
185
+            $this->ensureConfigIDExists($configID);
186 186
 
187
-			if(!is_array($configData)) {
188
-				throw new OCSBadRequestException('configData is not properly set');
189
-			}
187
+            if(!is_array($configData)) {
188
+                throw new OCSBadRequestException('configData is not properly set');
189
+            }
190 190
 
191
-			$configuration = new Configuration($configID);
192
-			$configKeys = $configuration->getConfigTranslationArray();
191
+            $configuration = new Configuration($configID);
192
+            $configKeys = $configuration->getConfigTranslationArray();
193 193
 
194
-			foreach ($configKeys as $i => $key) {
195
-				if(isset($configData[$key])) {
196
-					$configuration->$key = $configData[$key];
197
-				}
198
-			}
194
+            foreach ($configKeys as $i => $key) {
195
+                if(isset($configData[$key])) {
196
+                    $configuration->$key = $configData[$key];
197
+                }
198
+            }
199 199
 
200
-			$configuration->saveConfiguration();
201
-		} catch(OCSException $e) {
202
-			throw $e;
203
-		} catch (\Exception $e) {
204
-			$this->logger->logException($e);
205
-			throw new OCSException('An issue occurred when modifying the config.');
206
-		}
200
+            $configuration->saveConfiguration();
201
+        } catch(OCSException $e) {
202
+            throw $e;
203
+        } catch (\Exception $e) {
204
+            $this->logger->logException($e);
205
+            throw new OCSException('An issue occurred when modifying the config.');
206
+        }
207 207
 
208
-		return new DataResponse();
209
-	}
208
+        return new DataResponse();
209
+    }
210 210
 
211
-	/**
212
-	 * retrieves a configuration
213
-	 *
214
-	 * <?xml version="1.0"?>
215
-	 * <ocs>
216
-	 *   <meta>
217
-	 *     <status>ok</status>
218
-	 *     <statuscode>200</statuscode>
219
-	 *     <message>OK</message>
220
-	 *   </meta>
221
-	 *   <data>
222
-	 *     <ldapHost>ldaps://my.ldap.server</ldapHost>
223
-	 *     <ldapPort>7770</ldapPort>
224
-	 *     <ldapBackupHost></ldapBackupHost>
225
-	 *     <ldapBackupPort></ldapBackupPort>
226
-	 *     <ldapBase>ou=small,dc=my,dc=ldap,dc=server</ldapBase>
227
-	 *     <ldapBaseUsers>ou=users,ou=small,dc=my,dc=ldap,dc=server</ldapBaseUsers>
228
-	 *     <ldapBaseGroups>ou=small,dc=my,dc=ldap,dc=server</ldapBaseGroups>
229
-	 *     <ldapAgentName>cn=root,dc=my,dc=ldap,dc=server</ldapAgentName>
230
-	 *     <ldapAgentPassword>clearTextWithShowPassword=1</ldapAgentPassword>
231
-	 *     <ldapTLS>1</ldapTLS>
232
-	 *     <turnOffCertCheck>0</turnOffCertCheck>
233
-	 *     <ldapIgnoreNamingRules/>
234
-	 *     <ldapUserDisplayName>displayname</ldapUserDisplayName>
235
-	 *     <ldapUserDisplayName2>uid</ldapUserDisplayName2>
236
-	 *     <ldapUserFilterObjectclass>inetOrgPerson</ldapUserFilterObjectclass>
237
-	 *     <ldapUserFilterGroups></ldapUserFilterGroups>
238
-	 *     <ldapUserFilter>(&amp;(objectclass=nextcloudUser)(nextcloudEnabled=TRUE))</ldapUserFilter>
239
-	 *     <ldapUserFilterMode>1</ldapUserFilterMode>
240
-	 *     <ldapGroupFilter>(&amp;(|(objectclass=nextcloudGroup)))</ldapGroupFilter>
241
-	 *     <ldapGroupFilterMode>0</ldapGroupFilterMode>
242
-	 *     <ldapGroupFilterObjectclass>nextcloudGroup</ldapGroupFilterObjectclass>
243
-	 *     <ldapGroupFilterGroups></ldapGroupFilterGroups>
244
-	 *     <ldapGroupDisplayName>cn</ldapGroupDisplayName>
245
-	 *     <ldapGroupMemberAssocAttr>memberUid</ldapGroupMemberAssocAttr>
246
-	 *     <ldapLoginFilter>(&amp;(|(objectclass=inetOrgPerson))(uid=%uid))</ldapLoginFilter>
247
-	 *     <ldapLoginFilterMode>0</ldapLoginFilterMode>
248
-	 *     <ldapLoginFilterEmail>0</ldapLoginFilterEmail>
249
-	 *     <ldapLoginFilterUsername>1</ldapLoginFilterUsername>
250
-	 *     <ldapLoginFilterAttributes></ldapLoginFilterAttributes>
251
-	 *     <ldapQuotaAttribute></ldapQuotaAttribute>
252
-	 *     <ldapQuotaDefault></ldapQuotaDefault>
253
-	 *     <ldapEmailAttribute>mail</ldapEmailAttribute>
254
-	 *     <ldapCacheTTL>20</ldapCacheTTL>
255
-	 *     <ldapUuidUserAttribute>auto</ldapUuidUserAttribute>
256
-	 *     <ldapUuidGroupAttribute>auto</ldapUuidGroupAttribute>
257
-	 *     <ldapOverrideMainServer></ldapOverrideMainServer>
258
-	 *     <ldapConfigurationActive>1</ldapConfigurationActive>
259
-	 *     <ldapAttributesForUserSearch>uid;sn;givenname</ldapAttributesForUserSearch>
260
-	 *     <ldapAttributesForGroupSearch></ldapAttributesForGroupSearch>
261
-	 *     <ldapExperiencedAdmin>0</ldapExperiencedAdmin>
262
-	 *     <homeFolderNamingRule></homeFolderNamingRule>
263
-	 *     <hasPagedResultSupport></hasPagedResultSupport>
264
-	 *     <hasMemberOfFilterSupport></hasMemberOfFilterSupport>
265
-	 *     <useMemberOfToDetectMembership>1</useMemberOfToDetectMembership>
266
-	 *     <ldapExpertUsernameAttr>uid</ldapExpertUsernameAttr>
267
-	 *     <ldapExpertUUIDUserAttr>uid</ldapExpertUUIDUserAttr>
268
-	 *     <ldapExpertUUIDGroupAttr></ldapExpertUUIDGroupAttr>
269
-	 *     <lastJpegPhotoLookup>0</lastJpegPhotoLookup>
270
-	 *     <ldapNestedGroups>0</ldapNestedGroups>
271
-	 *     <ldapPagingSize>500</ldapPagingSize>
272
-	 *     <turnOnPasswordChange>1</turnOnPasswordChange>
273
-	 *     <ldapDynamicGroupMemberURL></ldapDynamicGroupMemberURL>
274
-	 *   </data>
275
-	 * </ocs>
276
-	 *
277
-	 * @param string $configID
278
-	 * @param bool|string $showPassword
279
-	 * @return DataResponse
280
-	 * @throws OCSException
281
-	 */
282
-	public function show($configID, $showPassword = false) {
283
-		try {
284
-			$this->ensureConfigIDExists($configID);
211
+    /**
212
+     * retrieves a configuration
213
+     *
214
+     * <?xml version="1.0"?>
215
+     * <ocs>
216
+     *   <meta>
217
+     *     <status>ok</status>
218
+     *     <statuscode>200</statuscode>
219
+     *     <message>OK</message>
220
+     *   </meta>
221
+     *   <data>
222
+     *     <ldapHost>ldaps://my.ldap.server</ldapHost>
223
+     *     <ldapPort>7770</ldapPort>
224
+     *     <ldapBackupHost></ldapBackupHost>
225
+     *     <ldapBackupPort></ldapBackupPort>
226
+     *     <ldapBase>ou=small,dc=my,dc=ldap,dc=server</ldapBase>
227
+     *     <ldapBaseUsers>ou=users,ou=small,dc=my,dc=ldap,dc=server</ldapBaseUsers>
228
+     *     <ldapBaseGroups>ou=small,dc=my,dc=ldap,dc=server</ldapBaseGroups>
229
+     *     <ldapAgentName>cn=root,dc=my,dc=ldap,dc=server</ldapAgentName>
230
+     *     <ldapAgentPassword>clearTextWithShowPassword=1</ldapAgentPassword>
231
+     *     <ldapTLS>1</ldapTLS>
232
+     *     <turnOffCertCheck>0</turnOffCertCheck>
233
+     *     <ldapIgnoreNamingRules/>
234
+     *     <ldapUserDisplayName>displayname</ldapUserDisplayName>
235
+     *     <ldapUserDisplayName2>uid</ldapUserDisplayName2>
236
+     *     <ldapUserFilterObjectclass>inetOrgPerson</ldapUserFilterObjectclass>
237
+     *     <ldapUserFilterGroups></ldapUserFilterGroups>
238
+     *     <ldapUserFilter>(&amp;(objectclass=nextcloudUser)(nextcloudEnabled=TRUE))</ldapUserFilter>
239
+     *     <ldapUserFilterMode>1</ldapUserFilterMode>
240
+     *     <ldapGroupFilter>(&amp;(|(objectclass=nextcloudGroup)))</ldapGroupFilter>
241
+     *     <ldapGroupFilterMode>0</ldapGroupFilterMode>
242
+     *     <ldapGroupFilterObjectclass>nextcloudGroup</ldapGroupFilterObjectclass>
243
+     *     <ldapGroupFilterGroups></ldapGroupFilterGroups>
244
+     *     <ldapGroupDisplayName>cn</ldapGroupDisplayName>
245
+     *     <ldapGroupMemberAssocAttr>memberUid</ldapGroupMemberAssocAttr>
246
+     *     <ldapLoginFilter>(&amp;(|(objectclass=inetOrgPerson))(uid=%uid))</ldapLoginFilter>
247
+     *     <ldapLoginFilterMode>0</ldapLoginFilterMode>
248
+     *     <ldapLoginFilterEmail>0</ldapLoginFilterEmail>
249
+     *     <ldapLoginFilterUsername>1</ldapLoginFilterUsername>
250
+     *     <ldapLoginFilterAttributes></ldapLoginFilterAttributes>
251
+     *     <ldapQuotaAttribute></ldapQuotaAttribute>
252
+     *     <ldapQuotaDefault></ldapQuotaDefault>
253
+     *     <ldapEmailAttribute>mail</ldapEmailAttribute>
254
+     *     <ldapCacheTTL>20</ldapCacheTTL>
255
+     *     <ldapUuidUserAttribute>auto</ldapUuidUserAttribute>
256
+     *     <ldapUuidGroupAttribute>auto</ldapUuidGroupAttribute>
257
+     *     <ldapOverrideMainServer></ldapOverrideMainServer>
258
+     *     <ldapConfigurationActive>1</ldapConfigurationActive>
259
+     *     <ldapAttributesForUserSearch>uid;sn;givenname</ldapAttributesForUserSearch>
260
+     *     <ldapAttributesForGroupSearch></ldapAttributesForGroupSearch>
261
+     *     <ldapExperiencedAdmin>0</ldapExperiencedAdmin>
262
+     *     <homeFolderNamingRule></homeFolderNamingRule>
263
+     *     <hasPagedResultSupport></hasPagedResultSupport>
264
+     *     <hasMemberOfFilterSupport></hasMemberOfFilterSupport>
265
+     *     <useMemberOfToDetectMembership>1</useMemberOfToDetectMembership>
266
+     *     <ldapExpertUsernameAttr>uid</ldapExpertUsernameAttr>
267
+     *     <ldapExpertUUIDUserAttr>uid</ldapExpertUUIDUserAttr>
268
+     *     <ldapExpertUUIDGroupAttr></ldapExpertUUIDGroupAttr>
269
+     *     <lastJpegPhotoLookup>0</lastJpegPhotoLookup>
270
+     *     <ldapNestedGroups>0</ldapNestedGroups>
271
+     *     <ldapPagingSize>500</ldapPagingSize>
272
+     *     <turnOnPasswordChange>1</turnOnPasswordChange>
273
+     *     <ldapDynamicGroupMemberURL></ldapDynamicGroupMemberURL>
274
+     *   </data>
275
+     * </ocs>
276
+     *
277
+     * @param string $configID
278
+     * @param bool|string $showPassword
279
+     * @return DataResponse
280
+     * @throws OCSException
281
+     */
282
+    public function show($configID, $showPassword = false) {
283
+        try {
284
+            $this->ensureConfigIDExists($configID);
285 285
 
286
-			$config = new Configuration($configID);
287
-			$data = $config->getConfiguration();
288
-			if(!boolval(intval($showPassword))) {
289
-				$data['ldapAgentPassword'] = '***';
290
-			}
291
-			foreach ($data as $key => $value) {
292
-				if(is_array($value)) {
293
-					$value = implode(';', $value);
294
-					$data[$key] = $value;
295
-				}
296
-			}
297
-		} catch(OCSException $e) {
298
-			throw $e;
299
-		} catch (\Exception $e) {
300
-			$this->logger->logException($e);
301
-			throw new OCSException('An issue occurred when modifying the config.');
302
-		}
286
+            $config = new Configuration($configID);
287
+            $data = $config->getConfiguration();
288
+            if(!boolval(intval($showPassword))) {
289
+                $data['ldapAgentPassword'] = '***';
290
+            }
291
+            foreach ($data as $key => $value) {
292
+                if(is_array($value)) {
293
+                    $value = implode(';', $value);
294
+                    $data[$key] = $value;
295
+                }
296
+            }
297
+        } catch(OCSException $e) {
298
+            throw $e;
299
+        } catch (\Exception $e) {
300
+            $this->logger->logException($e);
301
+            throw new OCSException('An issue occurred when modifying the config.');
302
+        }
303 303
 
304
-		return new DataResponse($data);
305
-	}
304
+        return new DataResponse($data);
305
+    }
306 306
 
307
-	/**
308
-	 * if the given config ID is not available, an exception is thrown
309
-	 *
310
-	 * @param string $configID
311
-	 * @throws OCSNotFoundException
312
-	 */
313
-	private function ensureConfigIDExists($configID) {
314
-		$prefixes = $this->ldapHelper->getServerConfigurationPrefixes();
315
-		if(!in_array($configID, $prefixes, true)) {
316
-			throw new OCSNotFoundException('Config ID not found');
317
-		}
318
-	}
307
+    /**
308
+     * if the given config ID is not available, an exception is thrown
309
+     *
310
+     * @param string $configID
311
+     * @throws OCSNotFoundException
312
+     */
313
+    private function ensureConfigIDExists($configID) {
314
+        $prefixes = $this->ldapHelper->getServerConfigurationPrefixes();
315
+        if(!in_array($configID, $prefixes, true)) {
316
+            throw new OCSNotFoundException('Config ID not found');
317
+        }
318
+    }
319 319
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/BackendUtility.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -27,13 +27,13 @@
 block discarded – undo
27 27
 
28 28
 
29 29
 abstract class BackendUtility {
30
-	protected $access;
30
+    protected $access;
31 31
 
32
-	/**
33
-	 * constructor, make sure the subclasses call this one!
34
-	 * @param Access $access an instance of Access for LDAP interaction
35
-	 */
36
-	public function __construct(Access $access) {
37
-		$this->access = $access;
38
-	}
32
+    /**
33
+     * constructor, make sure the subclasses call this one!
34
+     * @param Access $access an instance of Access for LDAP interaction
35
+     */
36
+    public function __construct(Access $access) {
37
+        $this->access = $access;
38
+    }
39 39
 }
Please login to merge, or discard this patch.