Completed
Push — master ( 1bf486...a077c1 )
by Morris
18:02
created

Connection::saveConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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