Completed
Push — master ( af20f1...8ccb99 )
by Morris
78:09 queued 53:18
created

Connection::resolveRule()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Arthur Schiwon <[email protected]>
6
 * @author Bart Visscher <[email protected]>
7
 * @author Brent Bloxam <[email protected]>
8
 * @author Jarkko Lehtoranta <[email protected]>
9
 * @author Joas Schilling <[email protected]>
10
 * @author Jörn Friedrich Dreyer <[email protected]>
11
 * @author Lukas Reschke <[email protected]>
12
 * @author Lyonel Vincent <[email protected]>
13
 * @author Morris Jobke <[email protected]>
14
 * @author Robin Appelman <[email protected]>
15
 * @author Robin McCorkell <[email protected]>
16
 * @author Roeland Jago Douma <[email protected]>
17
 * @author root <[email protected]>
18
 * @author Victor Dubiniuk <[email protected]>
19
 * @author Xuanwo <[email protected]>
20
 *
21
 * @license AGPL-3.0
22
 *
23
 * This code is free software: you can redistribute it and/or modify
24
 * it under the terms of the GNU Affero General Public License, version 3,
25
 * as published by the Free Software Foundation.
26
 *
27
 * This program is distributed in the hope that it will be useful,
28
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30
 * GNU Affero General Public License for more details.
31
 *
32
 * You should have received a copy of the GNU Affero General Public License, version 3,
33
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
34
 *
35
 */
36
37
namespace OCA\User_LDAP;
38
39
use OC\ServerNotAvailableException;
40
use OCP\ILogger;
41
42
/**
43
 * magic properties (incomplete)
44
 * responsible for LDAP connections in context with the provided configuration
45
 *
46
 * @property string ldapHost
47
 * @property string ldapPort holds the port number
48
 * @property string ldapUserFilter
49
 * @property string ldapUserDisplayName
50
 * @property string ldapUserDisplayName2
51
 * @property string ldapUserAvatarRule
52
 * @property boolean turnOnPasswordChange
53
 * @property boolean hasPagedResultSupport
54
 * @property string[] ldapBaseUsers
55
 * @property int|null ldapPagingSize holds an integer
56
 * @property bool|mixed|void ldapGroupMemberAssocAttr
57
 * @property string ldapUuidUserAttribute
58
 * @property string ldapUuidGroupAttribute
59
 * @property string ldapExpertUUIDUserAttr
60
 * @property string ldapExpertUUIDGroupAttr
61
 * @property string ldapQuotaAttribute
62
 * @property string ldapQuotaDefault
63
 * @property string ldapEmailAttribute
64
 */
65
class Connection extends LDAPUtility {
66
	private $ldapConnectionRes = null;
67
	private $configPrefix;
68
	private $configID;
69
	private $configured = false;
70
	private $hasPagedResultSupport = true;
71
	//whether connection should be kept on __destruct
72
	private $dontDestruct = false;
73
74
	/**
75
	 * @var bool runtime flag that indicates whether supported primary groups are available
76
	 */
77
	public $hasPrimaryGroups = true;
78
79
	/**
80
	 * @var bool runtime flag that indicates whether supported POSIX gidNumber are available
81
	 */
82
	public $hasGidNumber = true;
83
84
	//cache handler
85
	protected $cache;
86
87
	/** @var Configuration settings handler **/
88
	protected $configuration;
89
90
	protected $doNotValidate = false;
91
92
	protected $ignoreValidation = false;
93
94
	protected $bindResult = [];
95
96
	/**
97
	 * Constructor
98
	 * @param ILDAPWrapper $ldap
99
	 * @param string $configPrefix a string with the prefix for the configkey column (appconfig table)
100
	 * @param string|null $configID a string with the value for the appid column (appconfig table) or null for on-the-fly connections
101
	 */
102
	public function __construct(ILDAPWrapper $ldap, $configPrefix = '', $configID = 'user_ldap') {
103
		parent::__construct($ldap);
104
		$this->configPrefix = $configPrefix;
105
		$this->configID = $configID;
106
		$this->configuration = new Configuration($configPrefix,
107
												 !is_null($configID));
108
		$memcache = \OC::$server->getMemCacheFactory();
109
		if($memcache->isAvailable()) {
110
			$this->cache = $memcache->createDistributed();
111
		}
112
		$helper = new Helper(\OC::$server->getConfig());
113
		$this->doNotValidate = !in_array($this->configPrefix,
114
			$helper->getServerConfigurationPrefixes());
115
		$this->hasPagedResultSupport =
116
			(int)$this->configuration->ldapPagingSize !== 0
117
			|| $this->ldap->hasPagedResultSupport();
118
	}
119
120
	public function __destruct() {
121
		if(!$this->dontDestruct && $this->ldap->isResource($this->ldapConnectionRes)) {
122
			@$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...
123
			$this->bindResult = [];
124
		}
125
	}
126
127
	/**
128
	 * defines behaviour when the instance is cloned
129
	 */
130
	public function __clone() {
131
		$this->configuration = new Configuration($this->configPrefix,
132
												 !is_null($this->configID));
133
		if(count($this->bindResult) !== 0 && $this->bindResult['result'] === true) {
134
			$this->bindResult = [];
135
		}
136
		$this->ldapConnectionRes = null;
137
		$this->dontDestruct = true;
138
	}
139
140
	/**
141
	 * @param string $name
142
	 * @return bool|mixed
143
	 */
144
	public function __get($name) {
145
		if(!$this->configured) {
146
			$this->readConfiguration();
147
		}
148
149
		if($name === 'hasPagedResultSupport') {
150
			return $this->hasPagedResultSupport;
151
		}
152
153
		return $this->configuration->$name;
154
	}
155
156
	/**
157
	 * @param string $name
158
	 * @param mixed $value
159
	 */
160
	public function __set($name, $value) {
161
		$this->doNotValidate = false;
162
		$before = $this->configuration->$name;
163
		$this->configuration->$name = $value;
164
		$after = $this->configuration->$name;
165
		if($before !== $after) {
166
			if ($this->configID !== '' && $this->configID !== null) {
167
				$this->configuration->saveConfiguration();
168
			}
169
			$this->validateConfiguration();
170
		}
171
	}
172
173
	/**
174
	 * @param string $rule
175
	 * @return array
176
	 * @throws \RuntimeException
177
	 */
178
	public function resolveRule($rule) {
179
		return $this->configuration->resolveRule($rule);
180
	}
181
182
	/**
183
	 * sets whether the result of the configuration validation shall
184
	 * be ignored when establishing the connection. Used by the Wizard
185
	 * in early configuration state.
186
	 * @param bool $state
187
	 */
188
	public function setIgnoreValidation($state) {
189
		$this->ignoreValidation = (bool)$state;
190
	}
191
192
	/**
193
	 * initializes the LDAP backend
194
	 * @param bool $force read the config settings no matter what
195
	 */
196
	public function init($force = false) {
197
		$this->readConfiguration($force);
198
		$this->establishConnection();
199
	}
200
201
	/**
202
	 * Returns the LDAP handler
203
	 */
204
	public function getConnectionResource() {
205
		if(!$this->ldapConnectionRes) {
206
			$this->init();
207
		} else if(!$this->ldap->isResource($this->ldapConnectionRes)) {
208
			$this->ldapConnectionRes = null;
209
			$this->establishConnection();
210
		}
211
		if(is_null($this->ldapConnectionRes)) {
212
			\OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server ' . $this->configuration->ldapHost, ILogger::ERROR);
0 ignored issues
show
Documentation introduced by
The property ldapHost does not exist on object<OCA\User_LDAP\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...
213
			throw new ServerNotAvailableException('Connection to LDAP server could not be established');
214
		}
215
		return $this->ldapConnectionRes;
216
	}
217
218
	/**
219
	 * resets the connection resource
220
	 */
221
	public function resetConnectionResource() {
222
		if(!is_null($this->ldapConnectionRes)) {
223
			@$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...
224
			$this->ldapConnectionRes = null;
225
			$this->bindResult = [];
226
		}
227
	}
228
229
	/**
230
	 * @param string|null $key
231
	 * @return string
232
	 */
233
	private function getCacheKey($key) {
234
		$prefix = 'LDAP-'.$this->configID.'-'.$this->configPrefix.'-';
235
		if(is_null($key)) {
236
			return $prefix;
237
		}
238
		return $prefix.hash('sha256', $key);
239
	}
240
241
	/**
242
	 * @param string $key
243
	 * @return mixed|null
244
	 */
245
	public function getFromCache($key) {
246
		if(!$this->configured) {
247
			$this->readConfiguration();
248
		}
249
		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\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
			return null;
251
		}
252
		$key = $this->getCacheKey($key);
253
254
		return json_decode(base64_decode($this->cache->get($key)), true);
255
	}
256
257
	/**
258
	 * @param string $key
259
	 * @param mixed $value
260
	 *
261
	 * @return string
262
	 */
263
	public function writeToCache($key, $value) {
264
		if(!$this->configured) {
265
			$this->readConfiguration();
266
		}
267
		if(is_null($this->cache)
268
			|| !$this->configuration->ldapCacheTTL
0 ignored issues
show
Documentation introduced by
The property ldapCacheTTL does not exist on object<OCA\User_LDAP\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...
269
			|| !$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...
270
			return null;
271
		}
272
		$key   = $this->getCacheKey($key);
273
		$value = base64_encode(json_encode($value));
274
		$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\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...
275
	}
276
277
	public function clearCache() {
278
		if(!is_null($this->cache)) {
279
			$this->cache->clear($this->getCacheKey(null));
280
		}
281
	}
282
283
	/**
284
	 * Caches the general LDAP configuration.
285
	 * @param bool $force optional. true, if the re-read should be forced. defaults
286
	 * to false.
287
	 * @return null
288
	 */
289
	private function readConfiguration($force = false) {
290
		if((!$this->configured || $force) && !is_null($this->configID)) {
291
			$this->configuration->readConfiguration();
292
			$this->configured = $this->validateConfiguration();
293
		}
294
	}
295
296
	/**
297
	 * set LDAP configuration with values delivered by an array, not read from configuration
298
	 * @param array $config array that holds the config parameters in an associated array
299
	 * @param array &$setParameters optional; array where the set fields will be given to
300
	 * @return boolean true if config validates, false otherwise. Check with $setParameters for detailed success on single parameters
301
	 */
302
	public function setConfiguration($config, &$setParameters = null) {
303
		if(is_null($setParameters)) {
304
			$setParameters = array();
305
		}
306
		$this->doNotValidate = false;
307
		$this->configuration->setConfiguration($config, $setParameters);
308
		if(count($setParameters) > 0) {
309
			$this->configured = $this->validateConfiguration();
310
		}
311
312
313
		return $this->configured;
314
	}
315
316
	/**
317
	 * saves the current Configuration in the database and empties the
318
	 * cache
319
	 * @return null
320
	 */
321
	public function saveConfiguration() {
322
		$this->configuration->saveConfiguration();
323
		$this->clearCache();
324
	}
325
326
	/**
327
	 * get the current LDAP configuration
328
	 * @return array
329
	 */
330
	public function getConfiguration() {
331
		$this->readConfiguration();
332
		$config = $this->configuration->getConfiguration();
333
		$cta = $this->configuration->getConfigTranslationArray();
334
		$result = array();
335
		foreach($cta as $dbkey => $configkey) {
336
			switch($configkey) {
337
				case 'homeFolderNamingRule':
338
					if(strpos($config[$configkey], 'attr:') === 0) {
339
						$result[$dbkey] = substr($config[$configkey], 5);
340
					} else {
341
						$result[$dbkey] = '';
342
					}
343
					break;
344
				case 'ldapBase':
345
				case 'ldapBaseUsers':
346
				case 'ldapBaseGroups':
347
				case 'ldapAttributesForUserSearch':
348
				case 'ldapAttributesForGroupSearch':
349
					if(is_array($config[$configkey])) {
350
						$result[$dbkey] = implode("\n", $config[$configkey]);
351
						break;
352
					} //else follows default
353
				default:
354
					$result[$dbkey] = $config[$configkey];
355
			}
356
		}
357
		return $result;
358
	}
359
360
	private function doSoftValidation() {
361
		//if User or Group Base are not set, take over Base DN setting
362
		foreach(array('ldapBaseUsers', 'ldapBaseGroups') as $keyBase) {
363
			$val = $this->configuration->$keyBase;
364
			if(empty($val)) {
365
				$this->configuration->$keyBase = $this->configuration->ldapBase;
0 ignored issues
show
Documentation introduced by
The property ldapBase does not exist on object<OCA\User_LDAP\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...
366
			}
367
		}
368
369
		foreach(array('ldapExpertUUIDUserAttr'  => 'ldapUuidUserAttribute',
370
					  'ldapExpertUUIDGroupAttr' => 'ldapUuidGroupAttribute')
371
				as $expertSetting => $effectiveSetting) {
372
			$uuidOverride = $this->configuration->$expertSetting;
373
			if(!empty($uuidOverride)) {
374
				$this->configuration->$effectiveSetting = $uuidOverride;
375
			} else {
376
				$uuidAttributes = Access::UUID_ATTRIBUTES;
377
				array_unshift($uuidAttributes, 'auto');
378
				if(!in_array($this->configuration->$effectiveSetting,
379
							$uuidAttributes)
380
					&& (!is_null($this->configID))) {
381
					$this->configuration->$effectiveSetting = 'auto';
382
					$this->configuration->saveConfiguration();
383
					\OCP\Util::writeLog('user_ldap',
384
										'Illegal value for the '.
385
										$effectiveSetting.', '.'reset to '.
386
										'autodetect.', ILogger::INFO);
387
				}
388
389
			}
390
		}
391
392
		$backupPort = (int)$this->configuration->ldapBackupPort;
0 ignored issues
show
Documentation introduced by
The property ldapBackupPort does not exist on object<OCA\User_LDAP\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...
393
		if ($backupPort <= 0) {
394
			$this->configuration->backupPort = $this->configuration->ldapPort;
0 ignored issues
show
Documentation introduced by
The property backupPort does not exist on object<OCA\User_LDAP\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\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...
395
		}
396
397
		//make sure empty search attributes are saved as simple, empty array
398
		$saKeys = array('ldapAttributesForUserSearch',
399
						'ldapAttributesForGroupSearch');
400
		foreach($saKeys as $key) {
401
			$val = $this->configuration->$key;
402
			if(is_array($val) && count($val) === 1 && empty($val[0])) {
403
				$this->configuration->$key = array();
404
			}
405
		}
406
407
		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\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...
408
			&& $this->configuration->ldapTLS) {
0 ignored issues
show
Documentation introduced by
The property ldapTLS does not exist on object<OCA\User_LDAP\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...
409
			$this->configuration->ldapTLS = false;
0 ignored issues
show
Documentation introduced by
The property ldapTLS does not exist on object<OCA\User_LDAP\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...
410
			\OCP\Util::writeLog(
411
				'user_ldap',
412
				'LDAPS (already using secure connection) and TLS do not work together. Switched off TLS.',
413
				ILogger::INFO
414
			);
415
		}
416
	}
417
418
	/**
419
	 * @return bool
420
	 */
421
	private function doCriticalValidation() {
422
		$configurationOK = true;
423
		$errorStr = 'Configuration Error (prefix '.
424
			(string)$this->configPrefix .'): ';
425
426
		//options that shall not be empty
427
		$options = array('ldapHost', 'ldapPort', 'ldapUserDisplayName',
428
						 'ldapGroupDisplayName', 'ldapLoginFilter');
429
		foreach($options as $key) {
430
			$val = $this->configuration->$key;
431
			if(empty($val)) {
432
				switch($key) {
433
					case 'ldapHost':
434
						$subj = 'LDAP Host';
435
						break;
436
					case 'ldapPort':
437
						$subj = 'LDAP Port';
438
						break;
439
					case 'ldapUserDisplayName':
440
						$subj = 'LDAP User Display Name';
441
						break;
442
					case 'ldapGroupDisplayName':
443
						$subj = 'LDAP Group Display Name';
444
						break;
445
					case 'ldapLoginFilter':
446
						$subj = 'LDAP Login Filter';
447
						break;
448
					default:
449
						$subj = $key;
450
						break;
451
				}
452
				$configurationOK = false;
453
				\OCP\Util::writeLog(
454
					'user_ldap',
455
					$errorStr.'No '.$subj.' given!',
456
					ILogger::WARN
457
				);
458
			}
459
		}
460
461
		//combinations
462
		$agent = $this->configuration->ldapAgentName;
0 ignored issues
show
Documentation introduced by
The property ldapAgentName does not exist on object<OCA\User_LDAP\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...
463
		$pwd = $this->configuration->ldapAgentPassword;
0 ignored issues
show
Documentation introduced by
The property ldapAgentPassword does not exist on object<OCA\User_LDAP\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...
464
		if (
465
			($agent === ''  && $pwd !== '')
466
			|| ($agent !== '' && $pwd === '')
467
		) {
468
			\OCP\Util::writeLog(
469
				'user_ldap',
470
				$errorStr.'either no password is given for the user ' .
471
					'agent or a password is given, but not an LDAP agent.',
472
				ILogger::WARN);
473
			$configurationOK = false;
474
		}
475
476
		$base = $this->configuration->ldapBase;
0 ignored issues
show
Documentation introduced by
The property ldapBase does not exist on object<OCA\User_LDAP\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...
477
		$baseUsers = $this->configuration->ldapBaseUsers;
0 ignored issues
show
Documentation introduced by
The property ldapBaseUsers does not exist on object<OCA\User_LDAP\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...
478
		$baseGroups = $this->configuration->ldapBaseGroups;
0 ignored issues
show
Documentation introduced by
The property ldapBaseGroups does not exist on object<OCA\User_LDAP\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...
479
480
		if(empty($base) && empty($baseUsers) && empty($baseGroups)) {
481
			\OCP\Util::writeLog(
482
				'user_ldap',
483
				$errorStr.'Not a single Base DN given.',
484
				ILogger::WARN
485
			);
486
			$configurationOK = false;
487
		}
488
489
		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\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...
490
		   === false) {
491
			\OCP\Util::writeLog(
492
				'user_ldap',
493
				$errorStr.'login filter does not contain %uid place holder.',
494
				ILogger::WARN
495
			);
496
			$configurationOK = false;
497
		}
498
499
		return $configurationOK;
500
	}
501
502
	/**
503
	 * Validates the user specified configuration
504
	 * @return bool true if configuration seems OK, false otherwise
505
	 */
506
	private function validateConfiguration() {
507
508
		if($this->doNotValidate) {
509
			//don't do a validation if it is a new configuration with pure
510
			//default values. Will be allowed on changes via __set or
511
			//setConfiguration
512
			return false;
513
		}
514
515
		// first step: "soft" checks: settings that are not really
516
		// necessary, but advisable. If left empty, give an info message
517
		$this->doSoftValidation();
518
519
		//second step: critical checks. If left empty or filled wrong, mark as
520
		//not configured and give a warning.
521
		return $this->doCriticalValidation();
522
	}
523
524
525
	/**
526
	 * Connects and Binds to LDAP
527
	 *
528
	 * @throws ServerNotAvailableException
529
	 */
530
	private function establishConnection() {
531
		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...
532
			return null;
533
		}
534
		static $phpLDAPinstalled = true;
535
		if(!$phpLDAPinstalled) {
536
			return false;
537
		}
538
		if(!$this->ignoreValidation && !$this->configured) {
539
			\OCP\Util::writeLog(
540
				'user_ldap',
541
				'Configuration is invalid, cannot connect',
542
				ILogger::WARN
543
			);
544
			return false;
545
		}
546
		if(!$this->ldapConnectionRes) {
547
			if(!$this->ldap->areLDAPFunctionsAvailable()) {
548
				$phpLDAPinstalled = false;
549
				\OCP\Util::writeLog(
550
					'user_ldap',
551
					'function ldap_connect is not available. Make sure that the PHP ldap module is installed.',
552
					ILogger::ERROR
553
				);
554
555
				return false;
556
			}
557
			if($this->configuration->turnOffCertCheck) {
0 ignored issues
show
Documentation introduced by
The property turnOffCertCheck does not exist on object<OCA\User_LDAP\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
				if(putenv('LDAPTLS_REQCERT=never')) {
559
					\OCP\Util::writeLog('user_ldap',
560
						'Turned off SSL certificate validation successfully.',
561
						ILogger::DEBUG);
562
				} else {
563
					\OCP\Util::writeLog(
564
						'user_ldap',
565
						'Could not turn off SSL certificate validation.',
566
						ILogger::WARN
567
					);
568
				}
569
			}
570
571
			$isOverrideMainServer = ($this->configuration->ldapOverrideMainServer
0 ignored issues
show
Documentation introduced by
The property ldapOverrideMainServer does not exist on object<OCA\User_LDAP\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...
572
				|| $this->getFromCache('overrideMainServer'));
573
			$isBackupHost = (trim($this->configuration->ldapBackupHost) !== "");
0 ignored issues
show
Documentation introduced by
The property ldapBackupHost does not exist on object<OCA\User_LDAP\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...
574
			$bindStatus = false;
575
			try {
576
				if (!$isOverrideMainServer) {
577
					$this->doConnect($this->configuration->ldapHost,
0 ignored issues
show
Documentation introduced by
The property ldapHost does not exist on object<OCA\User_LDAP\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...
578
						$this->configuration->ldapPort);
0 ignored issues
show
Documentation introduced by
The property ldapPort does not exist on object<OCA\User_LDAP\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...
579
				}
580
				return $this->bind();
581
			} catch (ServerNotAvailableException $e) {
582
				if(!$isBackupHost) {
583
					throw $e;
584
				}
585
			}
586
587
			//if LDAP server is not reachable, try the Backup (Replica!) Server
588
			if($isBackupHost || $isOverrideMainServer) {
589
				$this->doConnect($this->configuration->ldapBackupHost,
0 ignored issues
show
Documentation introduced by
The property ldapBackupHost does not exist on object<OCA\User_LDAP\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...
590
								 $this->configuration->ldapBackupPort);
0 ignored issues
show
Documentation introduced by
The property ldapBackupPort does not exist on object<OCA\User_LDAP\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...
591
				$this->bindResult = [];
592
				$bindStatus = $this->bind();
593
				$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...
594
					$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...
595
				if($bindStatus && $error === 0 && !$this->getFromCache('overrideMainServer')) {
596
					//when bind to backup server succeeded and failed to main server,
597
					//skip contacting him until next cache refresh
598
					$this->writeToCache('overrideMainServer', true);
599
				}
600
			}
601
602
			return $bindStatus;
603
		}
604
		return null;
605
	}
606
607
	/**
608
	 * @param string $host
609
	 * @param string $port
610
	 * @return bool
611
	 * @throws \OC\ServerNotAvailableException
612
	 */
613
	private function doConnect($host, $port) {
614
		if ($host === '') {
615
			return false;
616
		}
617
618
		$this->ldapConnectionRes = $this->ldap->connect($host, $port);
619
620
		if(!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) {
621
			throw new ServerNotAvailableException('Could not set required LDAP Protocol version.');
622
		}
623
624
		if(!$this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) {
625
			throw new ServerNotAvailableException('Could not disable LDAP referrals.');
626
		}
627
628
		if($this->configuration->ldapTLS) {
0 ignored issues
show
Documentation introduced by
The property ldapTLS does not exist on object<OCA\User_LDAP\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...
629
			if(!$this->ldap->startTls($this->ldapConnectionRes)) {
630
				throw new ServerNotAvailableException('Start TLS failed, when connecting to LDAP host ' . $host . '.');
631
			}
632
		}
633
634
		return true;
635
	}
636
637
	/**
638
	 * Binds to LDAP
639
	 */
640
	public function bind() {
641
		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...
642
			return false;
643
		}
644
		$cr = $this->ldapConnectionRes;
645
		if(!$this->ldap->isResource($cr)) {
0 ignored issues
show
Documentation introduced by
$cr 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...
646
			$cr = $this->getConnectionResource();
647
		}
648
649
		if(
650
			count($this->bindResult) !== 0
651
			&& $this->bindResult['dn'] === $this->configuration->ldapAgentName
0 ignored issues
show
Documentation introduced by
The property ldapAgentName does not exist on object<OCA\User_LDAP\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...
652
			&& \OC::$server->getHasher()->verify(
653
				$this->configPrefix . $this->configuration->ldapAgentPassword,
0 ignored issues
show
Documentation introduced by
The property ldapAgentPassword does not exist on object<OCA\User_LDAP\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...
654
				$this->bindResult['hash']
655
			)
656
		) {
657
			// don't attempt to bind again with the same data as before
658
			// bind might have been invoked via getConnectionResource(),
659
			// but we need results specifically for e.g. user login
660
			return $this->bindResult['result'];
661
		}
662
663
		$ldapLogin = @$this->ldap->bind($cr,
0 ignored issues
show
Documentation introduced by
$cr 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...
664
										$this->configuration->ldapAgentName,
0 ignored issues
show
Documentation introduced by
The property ldapAgentName does not exist on object<OCA\User_LDAP\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...
665
										$this->configuration->ldapAgentPassword);
0 ignored issues
show
Documentation introduced by
The property ldapAgentPassword does not exist on object<OCA\User_LDAP\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...
666
667
		$this->bindResult = [
668
			'dn' => $this->configuration->ldapAgentName,
0 ignored issues
show
Documentation introduced by
The property ldapAgentName does not exist on object<OCA\User_LDAP\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...
669
			'hash' => \OC::$server->getHasher()->hash($this->configPrefix . $this->configuration->ldapAgentPassword),
0 ignored issues
show
Documentation introduced by
The property ldapAgentPassword does not exist on object<OCA\User_LDAP\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...
670
			'result' => $ldapLogin,
671
		];
672
673
		if(!$ldapLogin) {
674
			$errno = $this->ldap->errno($cr);
0 ignored issues
show
Documentation introduced by
$cr 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...
675
676
			\OCP\Util::writeLog('user_ldap',
677
				'Bind failed: ' . $errno . ': ' . $this->ldap->error($cr),
0 ignored issues
show
Documentation introduced by
$cr 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...
678
				ILogger::WARN);
679
680
			// Set to failure mode, if LDAP error code is not LDAP_SUCCESS or LDAP_INVALID_CREDENTIALS
681
			if($errno !== 0x00 && $errno !== 0x31) {
682
				$this->ldapConnectionRes = null;
683
			}
684
685
			return false;
686
		}
687
		return true;
688
	}
689
690
}
691