Completed
Push — stable8.2 ( 36c43b...aa408d )
by
unknown
14:32
created

Connection::resetConnectionResource()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 6
1
<?php
2
/**
3
 * @author Arthur Schiwon <[email protected]>
4
 * @author Bart Visscher <[email protected]>
5
 * @author Jörn Friedrich Dreyer <[email protected]>
6
 * @author Lukas Reschke <[email protected]>
7
 * @author Lyonel Vincent <[email protected]>
8
 * @author Morris Jobke <[email protected]>
9
 * @author Robin Appelman <[email protected]>
10
 * @author Robin McCorkell <[email protected]>
11
 * @author Scrutinizer Auto-Fixer <[email protected]>
12
 *
13
 * @copyright Copyright (c) 2015, ownCloud, Inc.
14
 * @license AGPL-3.0
15
 *
16
 * This code is free software: you can redistribute it and/or modify
17
 * it under the terms of the GNU Affero General Public License, version 3,
18
 * as published by the Free Software Foundation.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
 * GNU Affero General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU Affero General Public License, version 3,
26
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
27
 *
28
 */
29
30
namespace OCA\user_ldap\lib;
31
32
use OC\ServerNotAvailableException;
33
34
/**
35
 * magic properties (incomplete)
36
 * responsible for LDAP connections in context with the provided configuration
37
 *
38
 * @property string ldapUserFilter
39
 * @property string ldapUserDisplayName
40
 * @property string ldapUserDisplayName2
41
 * @property boolean hasPagedResultSupport
42
 * @property string[] ldapBaseUsers
43
 * @property int|string ldapPagingSize holds an integer
44
 * @property bool|mixed|void ldapGroupMemberAssocAttr
45
 */
46
class Connection extends LDAPUtility {
47
	private $ldapConnectionRes = null;
48
	private $configPrefix;
49
	private $configID;
50
	private $configured = false;
51
52
	//whether connection should be kept on __destruct
53
	private $dontDestruct = false;
54
	private $hasPagedResultSupport = true;
55
56
	/**
57
	 * @var bool runtime flag that indicates whether supported primary groups are available
58
	 */
59
	public $hasPrimaryGroups = true;
60
61
	//cache handler
62
	protected $cache;
63
64
	/** @var Configuration settings handler **/
65
	protected $configuration;
66
67
	protected $doNotValidate = false;
68
69
	protected $ignoreValidation = false;
70
71
	/**
72
	 * Constructor
73
	 * @param ILDAPWrapper $ldap
74
	 * @param string $configPrefix a string with the prefix for the configkey column (appconfig table)
75
	 * @param string|null $configID a string with the value for the appid column (appconfig table) or null for on-the-fly connections
76
	 */
77 100
	public function __construct(ILDAPWrapper $ldap, $configPrefix = '', $configID = 'user_ldap') {
78 100
		parent::__construct($ldap);
79 100
		$this->configPrefix = $configPrefix;
80 100
		$this->configID = $configID;
81 100
		$this->configuration = new Configuration($configPrefix,
82 100
												 !is_null($configID));
83 100
		$memcache = \OC::$server->getMemCacheFactory();
84 100
		if($memcache->isAvailable()) {
85 100
			$this->cache = $memcache->create();
86 100
		}
87 100
		$this->hasPagedResultSupport =
88 100
			$this->ldap->hasPagedResultSupport();
89 100
		$helper = new Helper();
90 100
		$this->doNotValidate = !in_array($this->configPrefix,
91 100
			$helper->getServerConfigurationPrefixes());
92 100
	}
93
94 9
	public function __destruct() {
95 9
		if(!$this->dontDestruct &&
96 9
			$this->ldap->isResource($this->ldapConnectionRes)) {
97
			@$this->ldap->unbind($this->ldapConnectionRes);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
98 9
		};
99 9
	}
100
101
	/**
102
	 * defines behaviour when the instance is cloned
103
	 */
104 1
	public function __clone() {
105
		//a cloned instance inherits the connection resource. It may use it,
106
		//but it may not disconnect it
107 1
		$this->dontDestruct = true;
108 1
		$this->configuration = new Configuration($this->configPrefix,
109 1
												 !is_null($this->configID));
110 1
	}
111
112
	/**
113
	 * @param string $name
114
	 * @return bool|mixed|void
115
	 */
116 3
	public function __get($name) {
117 3
		if(!$this->configured) {
118 3
			$this->readConfiguration();
119 3
		}
120
121 3
		if($name === 'hasPagedResultSupport') {
122
			return $this->hasPagedResultSupport;
123
		}
124
125 3
		return $this->configuration->$name;
126
	}
127
128
	/**
129
	 * @param string $name
130
	 * @param mixed $value
131
	 */
132
	public function __set($name, $value) {
133
		$this->doNotValidate = false;
134
		$before = $this->configuration->$name;
135
		$this->configuration->$name = $value;
136
		$after = $this->configuration->$name;
137
		if($before !== $after) {
138
			if(!empty($this->configID)) {
139
				$this->configuration->saveConfiguration();
140
			}
141
			$this->validateConfiguration();
142
		}
143
	}
144
145
	/**
146
	 * sets whether the result of the configuration validation shall
147
	 * be ignored when establishing the connection. Used by the Wizard
148
	 * in early configuration state.
149
	 * @param bool $state
150
	 */
151
	public function setIgnoreValidation($state) {
152
		$this->ignoreValidation = (bool)$state;
153
	}
154
155
	/**
156
	 * initializes the LDAP backend
157
	 * @param bool $force read the config settings no matter what
158
	 */
159
	public function init($force = false) {
160
		$this->readConfiguration($force);
161
		$this->establishConnection();
162
	}
163
164
	/**
165
	 * Returns the LDAP handler
166
	 */
167
	public function getConnectionResource() {
168
		if(!$this->ldapConnectionRes) {
169
			$this->init();
170
		} else if(!$this->ldap->isResource($this->ldapConnectionRes)) {
171
			$this->ldapConnectionRes = null;
172
			$this->establishConnection();
173
		}
174
		if(is_null($this->ldapConnectionRes)) {
175
			\OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server ' . $this->configuration->ldapHost, \OCP\Util::ERROR);
0 ignored issues
show
Documentation introduced by
The property ldapHost does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
176
			throw new ServerNotAvailableException('Connection to LDAP server could not be established');
177
		}
178
		return $this->ldapConnectionRes;
179
	}
180
181
	/**
182
	 * resets the connection resource
183
	 */
184
	public function resetConnectionResource() {
185
		if(!is_null($this->ldapConnectionRes)) {
186
			@$this->ldap->unbind($this->ldapConnectionRes);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
187
			$this->ldapConnectionRes = null;
188
		}
189
	}
190
191
	/**
192
	 * @param string|null $key
193
	 * @return string
194
	 */
195
	private function getCacheKey($key) {
196
		$prefix = 'LDAP-'.$this->configID.'-'.$this->configPrefix.'-';
197
		if(is_null($key)) {
198
			return $prefix;
199
		}
200
		return $prefix.md5($key);
201
	}
202
203
	/**
204
	 * @param string $key
205
	 * @return mixed|null
206
	 */
207
	public function getFromCache($key) {
208
		if(!$this->configured) {
209
			$this->readConfiguration();
210
		}
211
		if(is_null($this->cache) || !$this->configuration->ldapCacheTTL) {
0 ignored issues
show
Documentation introduced by
The property ldapCacheTTL does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
212
			return null;
213
		}
214
		if(!$this->isCached($key)) {
215
			return null;
216
217
		}
218
		$key = $this->getCacheKey($key);
219
220
		return json_decode(base64_decode($this->cache->get($key)), true);
221
	}
222
223
	/**
224
	 * @param string $key
225
	 * @return bool
226
	 */
227
	public function isCached($key) {
228
		if(!$this->configured) {
229
			$this->readConfiguration();
230
		}
231
		if(is_null($this->cache) || !$this->configuration->ldapCacheTTL) {
0 ignored issues
show
Documentation introduced by
The property ldapCacheTTL does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
232
			return false;
233
		}
234
		$key = $this->getCacheKey($key);
235
		return $this->cache->hasKey($key);
236
	}
237
238
	/**
239
	 * @param string $key
240
	 * @param mixed $value
241
	 *
242
	 * @return string
243
	 */
244
	public function writeToCache($key, $value) {
245
		if(!$this->configured) {
246
			$this->readConfiguration();
247
		}
248
		if(is_null($this->cache)
249
			|| !$this->configuration->ldapCacheTTL
0 ignored issues
show
Documentation introduced by
The property ldapCacheTTL does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
250
			|| !$this->configuration->ldapConfigurationActive) {
0 ignored issues
show
Bug introduced by
The property ldapConfigurationActive does not seem to exist. Did you mean config?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
251
			return null;
252
		}
253
		$key   = $this->getCacheKey($key);
254
		$value = base64_encode(json_encode($value));
255
		$this->cache->set($key, $value, $this->configuration->ldapCacheTTL);
0 ignored issues
show
Documentation introduced by
The property ldapCacheTTL does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
256
	}
257
258
	public function clearCache() {
259
		if(!is_null($this->cache)) {
260 3
			$this->cache->clear($this->getCacheKey(null));
261 3
		}
262
	}
263
264
	/**
265 3
	 * Caches the general LDAP configuration.
266
	 * @param bool $force optional. true, if the re-read should be forced. defaults
267
	 * to false.
268
	 * @return null
269
	 */
270
	private function readConfiguration($force = false) {
271
		if((!$this->configured || $force) && !is_null($this->configID)) {
272
			$this->configuration->readConfiguration();
273 2
			$this->configured = $this->validateConfiguration();
274 2
		}
275 2
	}
276 2
277 2
	/**
278 2
	 * set LDAP configuration with values delivered by an array, not read from configuration
279 2
	 * @param array $config array that holds the config parameters in an associated array
280 2
	 * @param array &$setParameters optional; array where the set fields will be given to
281 2
	 * @return boolean true if config validates, false otherwise. Check with $setParameters for detailed success on single parameters
282
	 */
283
	public function setConfiguration($config, &$setParameters = null) {
284 2
		if(is_null($setParameters)) {
285
			$setParameters = array();
286
		}
287
		$this->doNotValidate = false;
288
		$this->configuration->setConfiguration($config, $setParameters);
289
		if(count($setParameters) > 0) {
290
			$this->configured = $this->validateConfiguration();
291
		}
292
293
294
		return $this->configured;
295
	}
296
297
	/**
298
	 * saves the current Configuration in the database and empties the
299
	 * cache
300
	 * @return null
301
	 */
302
	public function saveConfiguration() {
303
		$this->configuration->saveConfiguration();
304
		$this->clearCache();
305
	}
306
307
	/**
308
	 * get the current LDAP configuration
309
	 * @return array
310
	 */
311
	public function getConfiguration() {
312
		$this->readConfiguration();
313
		$config = $this->configuration->getConfiguration();
314
		$cta = $this->configuration->getConfigTranslationArray();
315
		$result = array();
316
		foreach($cta as $dbkey => $configkey) {
317
			switch($configkey) {
318
				case 'homeFolderNamingRule':
319
					if(strpos($config[$configkey], 'attr:') === 0) {
320
						$result[$dbkey] = substr($config[$configkey], 5);
321
					} else {
322
						$result[$dbkey] = '';
323
					}
324
					break;
325
				case 'ldapBase':
326
				case 'ldapBaseUsers':
327
				case 'ldapBaseGroups':
328
				case 'ldapAttributesForUserSearch':
329
				case 'ldapAttributesForGroupSearch':
330
					if(is_array($config[$configkey])) {
331 2
						$result[$dbkey] = implode("\n", $config[$configkey]);
332
						break;
333 2
					} //else follows default
334 2
				default:
335 2
					$result[$dbkey] = $config[$configkey];
336 2
			}
337 2
		}
338 2
		return $result;
339 2
	}
340 2
341 2
	private function doSoftValidation() {
342 2
		//if User or Group Base are not set, take over Base DN setting
343 2
		foreach(array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) {
344
			$val = $this->configuration->$keyBase;
345 2
			if(empty($val)) {
346 2
				$obj = strpos('Users', $keyBase) !== false ? 'Users' : 'Groups';
347 2
				\OCP\Util::writeLog('user_ldap',
348 2
									'Base tree for '.$obj.
349 2
									' is empty, using Base DN',
350
									\OCP\Util::INFO);
351
				$this->configuration->$keyBase = $this->configuration->ldapBase;
0 ignored issues
show
Documentation introduced by
The property ldapBase does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
352 2
			}
353 2
		}
354 2
355 2
		foreach(array('ldapExpertUUIDUserAttr'  => 'ldapUuidUserAttribute',
356 2
					  'ldapExpertUUIDGroupAttr' => 'ldapUuidGroupAttribute')
357
				as $expertSetting => $effectiveSetting) {
358
			$uuidOverride = $this->configuration->$expertSetting;
359
			if(!empty($uuidOverride)) {
360
				$this->configuration->$effectiveSetting = $uuidOverride;
361
			} else {
362
				$uuidAttributes = array('auto', 'entryuuid', 'nsuniqueid',
363
										'objectguid', 'guid');
364
				if(!in_array($this->configuration->$effectiveSetting,
365
							$uuidAttributes)
366 2
					&& (!is_null($this->configID))) {
367
					$this->configuration->$effectiveSetting = 'auto';
368 2
					$this->configuration->saveConfiguration();
369 2
					\OCP\Util::writeLog('user_ldap',
370 2
										'Illegal value for the '.
371 2
										$effectiveSetting.', '.'reset to '.
372
										'autodetect.', \OCP\Util::INFO);
373
				}
374 2
375 2
			}
376 2
		}
377 2
378 2
		$backupPort = $this->configuration->ldapBackupPort;
0 ignored issues
show
Documentation introduced by
The property ldapBackupPort does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
379
		if(empty($backupPort)) {
380
			$this->configuration->backupPort = $this->configuration->ldapPort;
0 ignored issues
show
Documentation introduced by
The property backupPort does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property ldapPort does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
381 2
		}
382
383 2
		//make sure empty search attributes are saved as simple, empty array
384 2
		$saKeys = array('ldapAttributesForUserSearch',
385
						'ldapAttributesForGroupSearch');
386
		foreach($saKeys as $key) {
387
			$val = $this->configuration->$key;
388
			if(is_array($val) && count($val) === 1 && empty($val[0])) {
389
				$this->configuration->$key = array();
390
			}
391 2
		}
392
393
		if((stripos($this->configuration->ldapHost, 'ldaps://') === 0)
0 ignored issues
show
Documentation introduced by
The property ldapHost does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
394
			&& $this->configuration->ldapTLS) {
0 ignored issues
show
Documentation introduced by
The property ldapTLS does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
395
			$this->configuration->ldapTLS = false;
0 ignored issues
show
Documentation introduced by
The property ldapTLS does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
396 2
			\OCP\Util::writeLog('user_ldap',
397 2
								'LDAPS (already using secure connection) and '.
398
								'TLS do not work together. Switched off TLS.',
399 2
								\OCP\Util::INFO);
400
		}
401
	}
402 2
403 2
	/**
404 2
	 * @return bool
405 2
	 */
406 2
	private function doCriticalValidation() {
407
		$configurationOK = true;
408 2
		$errorStr = 'Configuration Error (prefix '.
409 2
					strval($this->configPrefix).'): ';
410 2
411 2
		//options that shall not be empty
412 2
		$options = array('ldapHost', 'ldapPort', 'ldapUserDisplayName',
413 2
						 'ldapGroupDisplayName', 'ldapLoginFilter');
414 2
		foreach($options as $key) {
415 2
			$val = $this->configuration->$key;
416 2
			if(empty($val)) {
417 2
				switch($key) {
418 2
					case 'ldapHost':
419 2
						$subj = 'LDAP Host';
420 2
						break;
421 2
					case 'ldapPort':
422 2
						$subj = 'LDAP Port';
423
						break;
424
					case 'ldapUserDisplayName':
425
						$subj = 'LDAP User Display Name';
426
						break;
427 2
					case 'ldapGroupDisplayName':
428 2
						$subj = 'LDAP Group Display Name';
429 2
						break;
430 2
					case 'ldapLoginFilter':
431 2
						$subj = 'LDAP Login Filter';
432 2
						break;
433
					default:
434
						$subj = $key;
435 2
						break;
436 2
				}
437 2
				$configurationOK = false;
438
				\OCP\Util::writeLog('user_ldap',
439
									$errorStr.'No '.$subj.' given!',
440
									\OCP\Util::WARN);
441
			}
442
		}
443
444
		//combinations
445
		$agent = $this->configuration->ldapAgentName;
0 ignored issues
show
Documentation introduced by
The property ldapAgentName does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
446 2
		$pwd = $this->configuration->ldapAgentPassword;
0 ignored issues
show
Documentation introduced by
The property ldapAgentPassword does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
447 2
		if((empty($agent) && !empty($pwd)) || (!empty($agent) && empty($pwd))) {
448 2
			\OCP\Util::writeLog('user_ldap',
449
								$errorStr.'either no password is given for the'.
450 2
								'user agent or a password is given, but not an'.
451 2
								'LDAP agent.',
452 2
				\OCP\Util::WARN);
453 2
			$configurationOK = false;
454 2
		}
455 2
456
		$base = $this->configuration->ldapBase;
0 ignored issues
show
Documentation introduced by
The property ldapBase does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
457 2
		$baseUsers = $this->configuration->ldapBaseUsers;
0 ignored issues
show
Documentation introduced by
The property ldapBaseUsers does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
458 2
		$baseGroups = $this->configuration->ldapBaseGroups;
0 ignored issues
show
Documentation introduced by
The property ldapBaseGroups does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
459 2
460 2
		if(empty($base) && empty($baseUsers) && empty($baseGroups)) {
461 2
			\OCP\Util::writeLog('user_ldap',
462 2
								$errorStr.'Not a single Base DN given.',
463 2
								\OCP\Util::WARN);
464 2
			$configurationOK = false;
465
		}
466 2
467
		if(mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8')
0 ignored issues
show
Documentation introduced by
The property ldapLoginFilter does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
468
		   === false) {
469
			\OCP\Util::writeLog('user_ldap',
470
								$errorStr.'login filter does not contain %uid '.
471
								'place holder.',
472
								\OCP\Util::WARN);
473 2
			$configurationOK = false;
474
		}
475 2
476
		return $configurationOK;
477
	}
478
479
	/**
480
	 * Validates the user specified configuration
481
	 * @return bool true if configuration seems OK, false otherwise
482
	 */
483
	private function validateConfiguration() {
484 2
485
		if($this->doNotValidate) {
486
			//don't do a validation if it is a new configuration with pure
487
			//default values. Will be allowed on changes via __set or
488 2
			//setConfiguration
489
			return false;
490
		}
491
492
		// first step: "soft" checks: settings that are not really
493
		// necessary, but advisable. If left empty, give an info message
494
		$this->doSoftValidation();
495
496
		//second step: critical checks. If left empty or filled wrong, mark as
497
		//not configured and give a warning.
498
		return $this->doCriticalValidation();
499
	}
500
501
502
	/**
503
	 * Connects and Binds to LDAP
504
	 */
505
	private function establishConnection() {
506
		if(!$this->configuration->ldapConfigurationActive) {
0 ignored issues
show
Bug introduced by
The property ldapConfigurationActive does not seem to exist. Did you mean config?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
507
			return null;
508
		}
509
		static $phpLDAPinstalled = true;
510
		if(!$phpLDAPinstalled) {
511
			return false;
512
		}
513
		if(!$this->ignoreValidation && !$this->configured) {
514
			\OCP\Util::writeLog('user_ldap',
515
								'Configuration is invalid, cannot connect',
516
								\OCP\Util::WARN);
517
			return false;
518
		}
519
		if(!$this->ldapConnectionRes) {
520
			if(!$this->ldap->areLDAPFunctionsAvailable()) {
521
				$phpLDAPinstalled = false;
522
				\OCP\Util::writeLog('user_ldap',
523
									'function ldap_connect is not available. Make '.
524
									'sure that the PHP ldap module is installed.',
525
									\OCP\Util::ERROR);
526
527
				return false;
528
			}
529
			if($this->configuration->turnOffCertCheck) {
0 ignored issues
show
Documentation introduced by
The property turnOffCertCheck does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
530
				if(putenv('LDAPTLS_REQCERT=never')) {
531
					\OCP\Util::writeLog('user_ldap',
532
						'Turned off SSL certificate validation successfully.',
533
						\OCP\Util::DEBUG);
534
				} else {
535
					\OCP\Util::writeLog('user_ldap',
536
										'Could not turn off SSL certificate validation.',
537
										\OCP\Util::WARN);
538
				}
539
			}
540
541
			$bindStatus = false;
542
			$error = -1;
543
			try {
544
				if (!$this->configuration->ldapOverrideMainServer
0 ignored issues
show
Documentation introduced by
The property ldapOverrideMainServer does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
545
					&& !$this->getFromCache('overrideMainServer')
546
				) {
547
					$this->doConnect($this->configuration->ldapHost,
0 ignored issues
show
Documentation introduced by
The property ldapHost does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
548
						$this->configuration->ldapPort);
0 ignored issues
show
Documentation introduced by
The property ldapPort does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
549
					$bindStatus = $this->bind();
550
					$error = $this->ldap->isResource($this->ldapConnectionRes) ?
0 ignored issues
show
Documentation introduced by
$this->ldapConnectionRes is of type null, but the function expects a resource.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
551
						$this->ldap->errno($this->ldapConnectionRes) : -1;
0 ignored issues
show
Documentation introduced by
$this->ldapConnectionRes is of type null, but the function expects a resource.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
552
				}
553
				if($bindStatus === true) {
554
					return $bindStatus;
555
				}
556
			} catch (\OC\ServerNotAvailableException $e) {
557
				if(trim($this->configuration->ldapBackupHost) === "") {
0 ignored issues
show
Documentation introduced by
The property ldapBackupHost does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
558
					throw $e;
559
				}
560
			}
561
562
			//if LDAP server is not reachable, try the Backup (Replica!) Server
563
			if(    $error !== 0
564
				|| $this->configuration->ldapOverrideMainServer
0 ignored issues
show
Documentation introduced by
The property ldapOverrideMainServer does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
565
				|| $this->getFromCache('overrideMainServer'))
566
			{
567
				$this->doConnect($this->configuration->ldapBackupHost,
0 ignored issues
show
Documentation introduced by
The property ldapBackupHost does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
568
								 $this->configuration->ldapBackupPort);
0 ignored issues
show
Documentation introduced by
The property ldapBackupPort does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
569
				$bindStatus = $this->bind();
570
				if($bindStatus && $error === -1 && !$this->getFromCache('overrideMainServer')) {
571
					//when bind to backup server succeeded and failed to main server,
572
					//skip contacting him until next cache refresh
573
					$this->writeToCache('overrideMainServer', true);
574
				}
575
			}
576
			return $bindStatus;
577
		}
578
	}
579
580
	/**
581
	 * @param string $host
582
	 * @param string $port
583
	 * @return false|void
584
	 */
585
	private function doConnect($host, $port) {
586
		if(empty($host)) {
587
			return false;
588
		}
589
		$this->ldapConnectionRes = $this->ldap->connect($host, $port);
590
		if($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) {
591
			if($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) {
592
				if($this->configuration->ldapTLS) {
0 ignored issues
show
Documentation introduced by
The property ldapTLS does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
593
					$this->ldap->startTls($this->ldapConnectionRes);
594
				}
595
			}
596
		}
597
	}
598
599
	/**
600
	 * Binds to LDAP
601
	 */
602
	public function bind() {
603
		static $getConnectionResourceAttempt = false;
604
		if(!$this->configuration->ldapConfigurationActive) {
0 ignored issues
show
Bug introduced by
The property ldapConfigurationActive does not seem to exist. Did you mean config?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
605
			return false;
606
		}
607
		if($getConnectionResourceAttempt) {
608
			$getConnectionResourceAttempt = false;
609
			return false;
610
		}
611
		$getConnectionResourceAttempt = true;
612
		$cr = $this->getConnectionResource();
613
		$getConnectionResourceAttempt = false;
614
		if(!$this->ldap->isResource($cr)) {
615
			return false;
616
		}
617
		$ldapLogin = @$this->ldap->bind($cr,
618
										$this->configuration->ldapAgentName,
0 ignored issues
show
Documentation introduced by
The property ldapAgentName does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
619
										$this->configuration->ldapAgentPassword);
0 ignored issues
show
Documentation introduced by
The property ldapAgentPassword does not exist on object<OCA\user_ldap\lib\Configuration>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
620
		if(!$ldapLogin) {
621
			\OCP\Util::writeLog('user_ldap',
622
				'Bind failed: ' . $this->ldap->errno($cr) . ': ' . $this->ldap->error($cr),
623
				\OCP\Util::WARN);
624
			$this->ldapConnectionRes = null;
625
			return false;
626
		}
627
		return true;
628
	}
629
630
}
631