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