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