Passed
Push — master ( 0e6e80...9658bc )
by Daniel
18:05 queued 11s
created
apps/user_ldap/lib/Access.php 2 patches
Indentation   +1988 added lines, -1988 removed lines patch added patch discarded remove patch
@@ -67,1774 +67,1774 @@  discard block
 block discarded – undo
67 67
  * @package OCA\User_LDAP
68 68
  */
69 69
 class Access extends LDAPUtility {
70
-	public const UUID_ATTRIBUTES = ['entryuuid', 'nsuniqueid', 'objectguid', 'guid', 'ipauniqueid'];
71
-
72
-	/** @var \OCA\User_LDAP\Connection */
73
-	public $connection;
74
-	/** @var Manager */
75
-	public $userManager;
76
-	//never ever check this var directly, always use getPagedSearchResultState
77
-	protected $pagedSearchedSuccessful;
78
-
79
-	/**
80
-	 * @var UserMapping $userMapper
81
-	 */
82
-	protected $userMapper;
83
-
84
-	/**
85
-	 * @var AbstractMapping $userMapper
86
-	 */
87
-	protected $groupMapper;
88
-
89
-	/**
90
-	 * @var \OCA\User_LDAP\Helper
91
-	 */
92
-	private $helper;
93
-	/** @var IConfig */
94
-	private $config;
95
-	/** @var IUserManager */
96
-	private $ncUserManager;
97
-	/** @var string */
98
-	private $lastCookie = '';
99
-
100
-	public function __construct(
101
-		Connection $connection,
102
-		ILDAPWrapper $ldap,
103
-		Manager $userManager,
104
-		Helper $helper,
105
-		IConfig $config,
106
-		IUserManager $ncUserManager
107
-	) {
108
-		parent::__construct($ldap);
109
-		$this->connection = $connection;
110
-		$this->userManager = $userManager;
111
-		$this->userManager->setLdapAccess($this);
112
-		$this->helper = $helper;
113
-		$this->config = $config;
114
-		$this->ncUserManager = $ncUserManager;
115
-	}
116
-
117
-	/**
118
-	 * sets the User Mapper
119
-	 *
120
-	 * @param AbstractMapping $mapper
121
-	 */
122
-	public function setUserMapper(AbstractMapping $mapper) {
123
-		$this->userMapper = $mapper;
124
-	}
125
-
126
-	/**
127
-	 * @throws \Exception
128
-	 */
129
-	public function getUserMapper(): UserMapping {
130
-		if (is_null($this->userMapper)) {
131
-			throw new \Exception('UserMapper was not assigned to this Access instance.');
132
-		}
133
-		return $this->userMapper;
134
-	}
135
-
136
-	/**
137
-	 * sets the Group Mapper
138
-	 *
139
-	 * @param AbstractMapping $mapper
140
-	 */
141
-	public function setGroupMapper(AbstractMapping $mapper) {
142
-		$this->groupMapper = $mapper;
143
-	}
144
-
145
-	/**
146
-	 * returns the Group Mapper
147
-	 *
148
-	 * @return AbstractMapping
149
-	 * @throws \Exception
150
-	 */
151
-	public function getGroupMapper() {
152
-		if (is_null($this->groupMapper)) {
153
-			throw new \Exception('GroupMapper was not assigned to this Access instance.');
154
-		}
155
-		return $this->groupMapper;
156
-	}
157
-
158
-	/**
159
-	 * @return bool
160
-	 */
161
-	private function checkConnection() {
162
-		return ($this->connection instanceof Connection);
163
-	}
164
-
165
-	/**
166
-	 * returns the Connection instance
167
-	 *
168
-	 * @return \OCA\User_LDAP\Connection
169
-	 */
170
-	public function getConnection() {
171
-		return $this->connection;
172
-	}
173
-
174
-	/**
175
-	 * reads a given attribute for an LDAP record identified by a DN
176
-	 *
177
-	 * @param string $dn the record in question
178
-	 * @param string $attr the attribute that shall be retrieved
179
-	 *        if empty, just check the record's existence
180
-	 * @param string $filter
181
-	 * @return array|false an array of values on success or an empty
182
-	 *          array if $attr is empty, false otherwise
183
-	 * @throws ServerNotAvailableException
184
-	 */
185
-	public function readAttribute($dn, $attr, $filter = 'objectClass=*') {
186
-		if (!$this->checkConnection()) {
187
-			\OCP\Util::writeLog('user_ldap',
188
-				'No LDAP Connector assigned, access impossible for readAttribute.',
189
-				ILogger::WARN);
190
-			return false;
191
-		}
192
-		$cr = $this->connection->getConnectionResource();
193
-		if (!$this->ldap->isResource($cr)) {
194
-			//LDAP not available
195
-			\OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', ILogger::DEBUG);
196
-			return false;
197
-		}
198
-		//Cancel possibly running Paged Results operation, otherwise we run in
199
-		//LDAP protocol errors
200
-		$this->abandonPagedSearch();
201
-		// openLDAP requires that we init a new Paged Search. Not needed by AD,
202
-		// but does not hurt either.
203
-		$pagingSize = (int)$this->connection->ldapPagingSize;
204
-		// 0 won't result in replies, small numbers may leave out groups
205
-		// (cf. #12306), 500 is default for paging and should work everywhere.
206
-		$maxResults = $pagingSize > 20 ? $pagingSize : 500;
207
-		$attr = mb_strtolower($attr, 'UTF-8');
208
-		// the actual read attribute later may contain parameters on a ranged
209
-		// request, e.g. member;range=99-199. Depends on server reply.
210
-		$attrToRead = $attr;
211
-
212
-		$values = [];
213
-		$isRangeRequest = false;
214
-		do {
215
-			$result = $this->executeRead($cr, $dn, $attrToRead, $filter, $maxResults);
216
-			if (is_bool($result)) {
217
-				// when an exists request was run and it was successful, an empty
218
-				// array must be returned
219
-				return $result ? [] : false;
220
-			}
221
-
222
-			if (!$isRangeRequest) {
223
-				$values = $this->extractAttributeValuesFromResult($result, $attr);
224
-				if (!empty($values)) {
225
-					return $values;
226
-				}
227
-			}
228
-
229
-			$isRangeRequest = false;
230
-			$result = $this->extractRangeData($result, $attr);
231
-			if (!empty($result)) {
232
-				$normalizedResult = $this->extractAttributeValuesFromResult(
233
-					[$attr => $result['values']],
234
-					$attr
235
-				);
236
-				$values = array_merge($values, $normalizedResult);
237
-
238
-				if ($result['rangeHigh'] === '*') {
239
-					// when server replies with * as high range value, there are
240
-					// no more results left
241
-					return $values;
242
-				} else {
243
-					$low = $result['rangeHigh'] + 1;
244
-					$attrToRead = $result['attributeName'] . ';range=' . $low . '-*';
245
-					$isRangeRequest = true;
246
-				}
247
-			}
248
-		} while ($isRangeRequest);
249
-
250
-		\OCP\Util::writeLog('user_ldap', 'Requested attribute ' . $attr . ' not found for ' . $dn, ILogger::DEBUG);
251
-		return false;
252
-	}
253
-
254
-	/**
255
-	 * Runs an read operation against LDAP
256
-	 *
257
-	 * @param resource $cr the LDAP connection
258
-	 * @param string $dn
259
-	 * @param string $attribute
260
-	 * @param string $filter
261
-	 * @param int $maxResults
262
-	 * @return array|bool false if there was any error, true if an exists check
263
-	 *                    was performed and the requested DN found, array with the
264
-	 *                    returned data on a successful usual operation
265
-	 * @throws ServerNotAvailableException
266
-	 */
267
-	public function executeRead($cr, $dn, $attribute, $filter, $maxResults) {
268
-		try {
269
-			$this->initPagedSearch($filter, $dn, [$attribute], $maxResults, 0);
270
-		} catch (NoMoreResults $e) {
271
-			// does not happen, no pagination here since offset is 0, but the
272
-			// previous call is needed for a potential reset of the state.
273
-			// Tools would still point out a possible NoMoreResults exception.
274
-			return false;
275
-		}
276
-		$dn = $this->helper->DNasBaseParameter($dn);
277
-		$rr = @$this->invokeLDAPMethod('read', $cr, $dn, $filter, [$attribute]);
278
-		if (!$this->ldap->isResource($rr)) {
279
-			if ($attribute !== '') {
280
-				//do not throw this message on userExists check, irritates
281
-				\OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN ' . $dn, ILogger::DEBUG);
282
-			}
283
-			//in case an error occurs , e.g. object does not exist
284
-			return false;
285
-		}
286
-		if ($attribute === '' && ($filter === 'objectclass=*' || $this->invokeLDAPMethod('countEntries', $cr, $rr) === 1)) {
287
-			\OCP\Util::writeLog('user_ldap', 'readAttribute: ' . $dn . ' found', ILogger::DEBUG);
288
-			return true;
289
-		}
290
-		$er = $this->invokeLDAPMethod('firstEntry', $cr, $rr);
291
-		if (!$this->ldap->isResource($er)) {
292
-			//did not match the filter, return false
293
-			return false;
294
-		}
295
-		//LDAP attributes are not case sensitive
296
-		$result = \OCP\Util::mb_array_change_key_case(
297
-			$this->invokeLDAPMethod('getAttributes', $cr, $er), MB_CASE_LOWER, 'UTF-8');
298
-
299
-		return $result;
300
-	}
301
-
302
-	/**
303
-	 * Normalizes a result grom getAttributes(), i.e. handles DNs and binary
304
-	 * data if present.
305
-	 *
306
-	 * @param array $result from ILDAPWrapper::getAttributes()
307
-	 * @param string $attribute the attribute name that was read
308
-	 * @return string[]
309
-	 */
310
-	public function extractAttributeValuesFromResult($result, $attribute) {
311
-		$values = [];
312
-		if (isset($result[$attribute]) && $result[$attribute]['count'] > 0) {
313
-			$lowercaseAttribute = strtolower($attribute);
314
-			for ($i = 0; $i < $result[$attribute]['count']; $i++) {
315
-				if ($this->resemblesDN($attribute)) {
316
-					$values[] = $this->helper->sanitizeDN($result[$attribute][$i]);
317
-				} elseif ($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') {
318
-					$values[] = $this->convertObjectGUID2Str($result[$attribute][$i]);
319
-				} else {
320
-					$values[] = $result[$attribute][$i];
321
-				}
322
-			}
323
-		}
324
-		return $values;
325
-	}
326
-
327
-	/**
328
-	 * Attempts to find ranged data in a getAttribute results and extracts the
329
-	 * returned values as well as information on the range and full attribute
330
-	 * name for further processing.
331
-	 *
332
-	 * @param array $result from ILDAPWrapper::getAttributes()
333
-	 * @param string $attribute the attribute name that was read. Without ";range=…"
334
-	 * @return array If a range was detected with keys 'values', 'attributeName',
335
-	 *               'attributeFull' and 'rangeHigh', otherwise empty.
336
-	 */
337
-	public function extractRangeData($result, $attribute) {
338
-		$keys = array_keys($result);
339
-		foreach ($keys as $key) {
340
-			if ($key !== $attribute && strpos($key, $attribute) === 0) {
341
-				$queryData = explode(';', $key);
342
-				if (strpos($queryData[1], 'range=') === 0) {
343
-					$high = substr($queryData[1], 1 + strpos($queryData[1], '-'));
344
-					$data = [
345
-						'values' => $result[$key],
346
-						'attributeName' => $queryData[0],
347
-						'attributeFull' => $key,
348
-						'rangeHigh' => $high,
349
-					];
350
-					return $data;
351
-				}
352
-			}
353
-		}
354
-		return [];
355
-	}
356
-
357
-	/**
358
-	 * Set password for an LDAP user identified by a DN
359
-	 *
360
-	 * @param string $userDN the user in question
361
-	 * @param string $password the new password
362
-	 * @return bool
363
-	 * @throws HintException
364
-	 * @throws \Exception
365
-	 */
366
-	public function setPassword($userDN, $password) {
367
-		if ((int)$this->connection->turnOnPasswordChange !== 1) {
368
-			throw new \Exception('LDAP password changes are disabled.');
369
-		}
370
-		$cr = $this->connection->getConnectionResource();
371
-		if (!$this->ldap->isResource($cr)) {
372
-			//LDAP not available
373
-			\OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', ILogger::DEBUG);
374
-			return false;
375
-		}
376
-		try {
377
-			// try PASSWD extended operation first
378
-			return @$this->invokeLDAPMethod('exopPasswd', $cr, $userDN, '', $password) ||
379
-				@$this->invokeLDAPMethod('modReplace', $cr, $userDN, $password);
380
-		} catch (ConstraintViolationException $e) {
381
-			throw new HintException('Password change rejected.', \OC::$server->getL10N('user_ldap')->t('Password change rejected. Hint: ') . $e->getMessage(), $e->getCode());
382
-		}
383
-	}
384
-
385
-	/**
386
-	 * checks whether the given attributes value is probably a DN
387
-	 *
388
-	 * @param string $attr the attribute in question
389
-	 * @return boolean if so true, otherwise false
390
-	 */
391
-	private function resemblesDN($attr) {
392
-		$resemblingAttributes = [
393
-			'dn',
394
-			'uniquemember',
395
-			'member',
396
-			// memberOf is an "operational" attribute, without a definition in any RFC
397
-			'memberof'
398
-		];
399
-		return in_array($attr, $resemblingAttributes);
400
-	}
401
-
402
-	/**
403
-	 * checks whether the given string is probably a DN
404
-	 *
405
-	 * @param string $string
406
-	 * @return boolean
407
-	 */
408
-	public function stringResemblesDN($string) {
409
-		$r = $this->ldap->explodeDN($string, 0);
410
-		// if exploding a DN succeeds and does not end up in
411
-		// an empty array except for $r[count] being 0.
412
-		return (is_array($r) && count($r) > 1);
413
-	}
414
-
415
-	/**
416
-	 * returns a DN-string that is cleaned from not domain parts, e.g.
417
-	 * cn=foo,cn=bar,dc=foobar,dc=server,dc=org
418
-	 * becomes dc=foobar,dc=server,dc=org
419
-	 *
420
-	 * @param string $dn
421
-	 * @return string
422
-	 */
423
-	public function getDomainDNFromDN($dn) {
424
-		$allParts = $this->ldap->explodeDN($dn, 0);
425
-		if ($allParts === false) {
426
-			//not a valid DN
427
-			return '';
428
-		}
429
-		$domainParts = [];
430
-		$dcFound = false;
431
-		foreach ($allParts as $part) {
432
-			if (!$dcFound && strpos($part, 'dc=') === 0) {
433
-				$dcFound = true;
434
-			}
435
-			if ($dcFound) {
436
-				$domainParts[] = $part;
437
-			}
438
-		}
439
-		return implode(',', $domainParts);
440
-	}
441
-
442
-	/**
443
-	 * returns the LDAP DN for the given internal Nextcloud name of the group
444
-	 *
445
-	 * @param string $name the Nextcloud name in question
446
-	 * @return string|false LDAP DN on success, otherwise false
447
-	 */
448
-	public function groupname2dn($name) {
449
-		return $this->groupMapper->getDNByName($name);
450
-	}
451
-
452
-	/**
453
-	 * returns the LDAP DN for the given internal Nextcloud name of the user
454
-	 *
455
-	 * @param string $name the Nextcloud name in question
456
-	 * @return string|false with the LDAP DN on success, otherwise false
457
-	 */
458
-	public function username2dn($name) {
459
-		$fdn = $this->userMapper->getDNByName($name);
460
-
461
-		//Check whether the DN belongs to the Base, to avoid issues on multi-
462
-		//server setups
463
-		if (is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
464
-			return $fdn;
465
-		}
466
-
467
-		return false;
468
-	}
469
-
470
-	/**
471
-	 * returns the internal Nextcloud name for the given LDAP DN of the group, false on DN outside of search DN or failure
472
-	 *
473
-	 * @param string $fdn the dn of the group object
474
-	 * @param string $ldapName optional, the display name of the object
475
-	 * @return string|false with the name to use in Nextcloud, false on DN outside of search DN
476
-	 * @throws \Exception
477
-	 */
478
-	public function dn2groupname($fdn, $ldapName = null) {
479
-		//To avoid bypassing the base DN settings under certain circumstances
480
-		//with the group support, check whether the provided DN matches one of
481
-		//the given Bases
482
-		if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) {
483
-			return false;
484
-		}
485
-
486
-		return $this->dn2ocname($fdn, $ldapName, false);
487
-	}
488
-
489
-	/**
490
-	 * returns the internal Nextcloud name for the given LDAP DN of the user, false on DN outside of search DN or failure
491
-	 *
492
-	 * @param string $dn the dn of the user object
493
-	 * @param string $ldapName optional, the display name of the object
494
-	 * @return string|false with with the name to use in Nextcloud
495
-	 * @throws \Exception
496
-	 */
497
-	public function dn2username($fdn, $ldapName = null) {
498
-		//To avoid bypassing the base DN settings under certain circumstances
499
-		//with the group support, check whether the provided DN matches one of
500
-		//the given Bases
501
-		if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
502
-			return false;
503
-		}
504
-
505
-		return $this->dn2ocname($fdn, $ldapName, true);
506
-	}
507
-
508
-	/**
509
-	 * returns an internal Nextcloud name for the given LDAP DN, false on DN outside of search DN
510
-	 *
511
-	 * @param string $fdn the dn of the user object
512
-	 * @param string|null $ldapName optional, the display name of the object
513
-	 * @param bool $isUser optional, whether it is a user object (otherwise group assumed)
514
-	 * @param bool|null $newlyMapped
515
-	 * @param array|null $record
516
-	 * @return false|string with with the name to use in Nextcloud
517
-	 * @throws \Exception
518
-	 */
519
-	public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped = null, array $record = null) {
520
-		$newlyMapped = false;
521
-		if ($isUser) {
522
-			$mapper = $this->getUserMapper();
523
-			$nameAttribute = $this->connection->ldapUserDisplayName;
524
-			$filter = $this->connection->ldapUserFilter;
525
-		} else {
526
-			$mapper = $this->getGroupMapper();
527
-			$nameAttribute = $this->connection->ldapGroupDisplayName;
528
-			$filter = $this->connection->ldapGroupFilter;
529
-		}
530
-
531
-		//let's try to retrieve the Nextcloud name from the mappings table
532
-		$ncName = $mapper->getNameByDN($fdn);
533
-		if (is_string($ncName)) {
534
-			return $ncName;
535
-		}
536
-
537
-		//second try: get the UUID and check if it is known. Then, update the DN and return the name.
538
-		$uuid = $this->getUUID($fdn, $isUser, $record);
539
-		if (is_string($uuid)) {
540
-			$ncName = $mapper->getNameByUUID($uuid);
541
-			if (is_string($ncName)) {
542
-				$mapper->setDNbyUUID($fdn, $uuid);
543
-				return $ncName;
544
-			}
545
-		} else {
546
-			//If the UUID can't be detected something is foul.
547
-			\OCP\Util::writeLog('user_ldap', 'Cannot determine UUID for ' . $fdn . '. Skipping.', ILogger::INFO);
548
-			return false;
549
-		}
550
-
551
-		if (is_null($ldapName)) {
552
-			$ldapName = $this->readAttribute($fdn, $nameAttribute, $filter);
553
-			if (!isset($ldapName[0]) && empty($ldapName[0])) {
554
-				\OCP\Util::writeLog('user_ldap', 'No or empty name for ' . $fdn . ' with filter ' . $filter . '.', ILogger::DEBUG);
555
-				return false;
556
-			}
557
-			$ldapName = $ldapName[0];
558
-		}
559
-
560
-		if ($isUser) {
561
-			$usernameAttribute = (string)$this->connection->ldapExpertUsernameAttr;
562
-			if ($usernameAttribute !== '') {
563
-				$username = $this->readAttribute($fdn, $usernameAttribute);
564
-				$username = $username[0];
565
-			} else {
566
-				$username = $uuid;
567
-			}
568
-			try {
569
-				$intName = $this->sanitizeUsername($username);
570
-			} catch (\InvalidArgumentException $e) {
571
-				\OC::$server->getLogger()->logException($e, [
572
-					'app' => 'user_ldap',
573
-					'level' => ILogger::WARN,
574
-				]);
575
-				// we don't attempt to set a username here. We can go for
576
-				// for an alternative 4 digit random number as we would append
577
-				// otherwise, however it's likely not enough space in bigger
578
-				// setups, and most importantly: this is not intended.
579
-				return false;
580
-			}
581
-		} else {
582
-			$intName = $ldapName;
583
-		}
584
-
585
-		//a new user/group! Add it only if it doesn't conflict with other backend's users or existing groups
586
-		//disabling Cache is required to avoid that the new user is cached as not-existing in fooExists check
587
-		//NOTE: mind, disabling cache affects only this instance! Using it
588
-		// outside of core user management will still cache the user as non-existing.
589
-		$originalTTL = $this->connection->ldapCacheTTL;
590
-		$this->connection->setConfiguration(['ldapCacheTTL' => 0]);
591
-		if ($intName !== ''
592
-			&& (($isUser && !$this->ncUserManager->userExists($intName))
593
-				|| (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName))
594
-			)
595
-		) {
596
-			$this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);
597
-			$newlyMapped = $this->mapAndAnnounceIfApplicable($mapper, $fdn, $intName, $uuid, $isUser);
598
-			if ($newlyMapped) {
599
-				return $intName;
600
-			}
601
-		}
602
-
603
-		$this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);
604
-		$altName = $this->createAltInternalOwnCloudName($intName, $isUser);
605
-		if (is_string($altName)) {
606
-			if ($this->mapAndAnnounceIfApplicable($mapper, $fdn, $altName, $uuid, $isUser)) {
607
-				$newlyMapped = true;
608
-				return $altName;
609
-			}
610
-		}
611
-
612
-		//if everything else did not help..
613
-		\OCP\Util::writeLog('user_ldap', 'Could not create unique name for ' . $fdn . '.', ILogger::INFO);
614
-		return false;
615
-	}
616
-
617
-	public function mapAndAnnounceIfApplicable(
618
-		AbstractMapping $mapper,
619
-		string $fdn,
620
-		string $name,
621
-		string $uuid,
622
-		bool $isUser
623
-	): bool {
624
-		if ($mapper->map($fdn, $name, $uuid)) {
625
-			if ($this->ncUserManager instanceof PublicEmitter && $isUser) {
626
-				$this->cacheUserExists($name);
627
-				$this->ncUserManager->emit('\OC\User', 'assignedUserId', [$name]);
628
-			} elseif (!$isUser) {
629
-				$this->cacheGroupExists($name);
630
-			}
631
-			return true;
632
-		}
633
-		return false;
634
-	}
635
-
636
-	/**
637
-	 * gives back the user names as they are used ownClod internally
638
-	 *
639
-	 * @param array $ldapUsers as returned by fetchList()
640
-	 * @return array an array with the user names to use in Nextcloud
641
-	 *
642
-	 * gives back the user names as they are used ownClod internally
643
-	 * @throws \Exception
644
-	 */
645
-	public function nextcloudUserNames($ldapUsers) {
646
-		return $this->ldap2NextcloudNames($ldapUsers, true);
647
-	}
648
-
649
-	/**
650
-	 * gives back the group names as they are used ownClod internally
651
-	 *
652
-	 * @param array $ldapGroups as returned by fetchList()
653
-	 * @return array an array with the group names to use in Nextcloud
654
-	 *
655
-	 * gives back the group names as they are used ownClod internally
656
-	 * @throws \Exception
657
-	 */
658
-	public function nextcloudGroupNames($ldapGroups) {
659
-		return $this->ldap2NextcloudNames($ldapGroups, false);
660
-	}
661
-
662
-	/**
663
-	 * @param array $ldapObjects as returned by fetchList()
664
-	 * @param bool $isUsers
665
-	 * @return array
666
-	 * @throws \Exception
667
-	 */
668
-	private function ldap2NextcloudNames($ldapObjects, $isUsers) {
669
-		if ($isUsers) {
670
-			$nameAttribute = $this->connection->ldapUserDisplayName;
671
-			$sndAttribute = $this->connection->ldapUserDisplayName2;
672
-		} else {
673
-			$nameAttribute = $this->connection->ldapGroupDisplayName;
674
-		}
675
-		$nextcloudNames = [];
676
-
677
-		foreach ($ldapObjects as $ldapObject) {
678
-			$nameByLDAP = null;
679
-			if (isset($ldapObject[$nameAttribute])
680
-				&& is_array($ldapObject[$nameAttribute])
681
-				&& isset($ldapObject[$nameAttribute][0])
682
-			) {
683
-				// might be set, but not necessarily. if so, we use it.
684
-				$nameByLDAP = $ldapObject[$nameAttribute][0];
685
-			}
686
-
687
-			$ncName = $this->dn2ocname($ldapObject['dn'][0], $nameByLDAP, $isUsers);
688
-			if ($ncName) {
689
-				$nextcloudNames[] = $ncName;
690
-				if ($isUsers) {
691
-					$this->updateUserState($ncName);
692
-					//cache the user names so it does not need to be retrieved
693
-					//again later (e.g. sharing dialogue).
694
-					if (is_null($nameByLDAP)) {
695
-						continue;
696
-					}
697
-					$sndName = isset($ldapObject[$sndAttribute][0])
698
-						? $ldapObject[$sndAttribute][0] : '';
699
-					$this->cacheUserDisplayName($ncName, $nameByLDAP, $sndName);
700
-				} elseif ($nameByLDAP !== null) {
701
-					$this->cacheGroupDisplayName($ncName, $nameByLDAP);
702
-				}
703
-			}
704
-		}
705
-		return $nextcloudNames;
706
-	}
707
-
708
-	/**
709
-	 * removes the deleted-flag of a user if it was set
710
-	 *
711
-	 * @param string $ncname
712
-	 * @throws \Exception
713
-	 */
714
-	public function updateUserState($ncname) {
715
-		$user = $this->userManager->get($ncname);
716
-		if ($user instanceof OfflineUser) {
717
-			$user->unmark();
718
-		}
719
-	}
720
-
721
-	/**
722
-	 * caches the user display name
723
-	 *
724
-	 * @param string $ocName the internal Nextcloud username
725
-	 * @param string|false $home the home directory path
726
-	 */
727
-	public function cacheUserHome($ocName, $home) {
728
-		$cacheKey = 'getHome' . $ocName;
729
-		$this->connection->writeToCache($cacheKey, $home);
730
-	}
731
-
732
-	/**
733
-	 * caches a user as existing
734
-	 *
735
-	 * @param string $ocName the internal Nextcloud username
736
-	 */
737
-	public function cacheUserExists($ocName) {
738
-		$this->connection->writeToCache('userExists' . $ocName, true);
739
-	}
740
-
741
-	/**
742
-	 * caches a group as existing
743
-	 */
744
-	public function cacheGroupExists(string $gid): void {
745
-		$this->connection->writeToCache('groupExists' . $gid, true);
746
-	}
747
-
748
-	/**
749
-	 * caches the user display name
750
-	 *
751
-	 * @param string $ocName the internal Nextcloud username
752
-	 * @param string $displayName the display name
753
-	 * @param string $displayName2 the second display name
754
-	 * @throws \Exception
755
-	 */
756
-	public function cacheUserDisplayName($ocName, $displayName, $displayName2 = '') {
757
-		$user = $this->userManager->get($ocName);
758
-		if ($user === null) {
759
-			return;
760
-		}
761
-		$displayName = $user->composeAndStoreDisplayName($displayName, $displayName2);
762
-		$cacheKeyTrunk = 'getDisplayName';
763
-		$this->connection->writeToCache($cacheKeyTrunk . $ocName, $displayName);
764
-	}
765
-
766
-	public function cacheGroupDisplayName(string $ncName, string $displayName): void {
767
-		$cacheKey = 'group_getDisplayName' . $ncName;
768
-		$this->connection->writeToCache($cacheKey, $displayName);
769
-	}
770
-
771
-	/**
772
-	 * creates a unique name for internal Nextcloud use for users. Don't call it directly.
773
-	 *
774
-	 * @param string $name the display name of the object
775
-	 * @return string|false with with the name to use in Nextcloud or false if unsuccessful
776
-	 *
777
-	 * Instead of using this method directly, call
778
-	 * createAltInternalOwnCloudName($name, true)
779
-	 */
780
-	private function _createAltInternalOwnCloudNameForUsers($name) {
781
-		$attempts = 0;
782
-		//while loop is just a precaution. If a name is not generated within
783
-		//20 attempts, something else is very wrong. Avoids infinite loop.
784
-		while ($attempts < 20) {
785
-			$altName = $name . '_' . rand(1000, 9999);
786
-			if (!$this->ncUserManager->userExists($altName)) {
787
-				return $altName;
788
-			}
789
-			$attempts++;
790
-		}
791
-		return false;
792
-	}
793
-
794
-	/**
795
-	 * creates a unique name for internal Nextcloud use for groups. Don't call it directly.
796
-	 *
797
-	 * @param string $name the display name of the object
798
-	 * @return string|false with with the name to use in Nextcloud or false if unsuccessful.
799
-	 *
800
-	 * Instead of using this method directly, call
801
-	 * createAltInternalOwnCloudName($name, false)
802
-	 *
803
-	 * Group names are also used as display names, so we do a sequential
804
-	 * numbering, e.g. Developers_42 when there are 41 other groups called
805
-	 * "Developers"
806
-	 */
807
-	private function _createAltInternalOwnCloudNameForGroups($name) {
808
-		$usedNames = $this->groupMapper->getNamesBySearch($name, "", '_%');
809
-		if (!$usedNames || count($usedNames) === 0) {
810
-			$lastNo = 1; //will become name_2
811
-		} else {
812
-			natsort($usedNames);
813
-			$lastName = array_pop($usedNames);
814
-			$lastNo = (int)substr($lastName, strrpos($lastName, '_') + 1);
815
-		}
816
-		$altName = $name . '_' . (string)($lastNo + 1);
817
-		unset($usedNames);
818
-
819
-		$attempts = 1;
820
-		while ($attempts < 21) {
821
-			// Check to be really sure it is unique
822
-			// while loop is just a precaution. If a name is not generated within
823
-			// 20 attempts, something else is very wrong. Avoids infinite loop.
824
-			if (!\OC::$server->getGroupManager()->groupExists($altName)) {
825
-				return $altName;
826
-			}
827
-			$altName = $name . '_' . ($lastNo + $attempts);
828
-			$attempts++;
829
-		}
830
-		return false;
831
-	}
832
-
833
-	/**
834
-	 * creates a unique name for internal Nextcloud use.
835
-	 *
836
-	 * @param string $name the display name of the object
837
-	 * @param boolean $isUser whether name should be created for a user (true) or a group (false)
838
-	 * @return string|false with with the name to use in Nextcloud or false if unsuccessful
839
-	 */
840
-	private function createAltInternalOwnCloudName($name, $isUser) {
841
-		$originalTTL = $this->connection->ldapCacheTTL;
842
-		$this->connection->setConfiguration(['ldapCacheTTL' => 0]);
843
-		if ($isUser) {
844
-			$altName = $this->_createAltInternalOwnCloudNameForUsers($name);
845
-		} else {
846
-			$altName = $this->_createAltInternalOwnCloudNameForGroups($name);
847
-		}
848
-		$this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);
849
-
850
-		return $altName;
851
-	}
852
-
853
-	/**
854
-	 * fetches a list of users according to a provided loginName and utilizing
855
-	 * the login filter.
856
-	 */
857
-	public function fetchUsersByLoginName(string $loginName, array $attributes = ['dn']): array {
858
-		$loginName = $this->escapeFilterPart($loginName);
859
-		$filter = str_replace('%uid', $loginName, $this->connection->ldapLoginFilter);
860
-		return $this->fetchListOfUsers($filter, $attributes);
861
-	}
862
-
863
-	/**
864
-	 * counts the number of users according to a provided loginName and
865
-	 * utilizing the login filter.
866
-	 *
867
-	 * @param string $loginName
868
-	 * @return int
869
-	 */
870
-	public function countUsersByLoginName($loginName) {
871
-		$loginName = $this->escapeFilterPart($loginName);
872
-		$filter = str_replace('%uid', $loginName, $this->connection->ldapLoginFilter);
873
-		return $this->countUsers($filter);
874
-	}
875
-
876
-	/**
877
-	 * @throws \Exception
878
-	 */
879
-	public function fetchListOfUsers(string $filter, array $attr, int $limit = null, int $offset = null, bool $forceApplyAttributes = false): array {
880
-		$ldapRecords = $this->searchUsers($filter, $attr, $limit, $offset);
881
-		$recordsToUpdate = $ldapRecords;
882
-		if (!$forceApplyAttributes) {
883
-			$isBackgroundJobModeAjax = $this->config
884
-					->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'ajax';
885
-			$listOfDNs = array_reduce($ldapRecords, function ($listOfDNs, $entry) {
886
-				$listOfDNs[] = $entry['dn'][0];
887
-				return $listOfDNs;
888
-			}, []);
889
-			$idsByDn = $this->userMapper->getListOfIdsByDn($listOfDNs);
890
-			$recordsToUpdate = array_filter($ldapRecords, function ($record) use ($isBackgroundJobModeAjax, $idsByDn) {
891
-				$newlyMapped = false;
892
-				$uid = $idsByDn[$record['dn'][0]] ?? null;
893
-				if ($uid === null) {
894
-					$uid = $this->dn2ocname($record['dn'][0], null, true, $newlyMapped, $record);
895
-				}
896
-				if (is_string($uid)) {
897
-					$this->cacheUserExists($uid);
898
-				}
899
-				return ($uid !== false) && ($newlyMapped || $isBackgroundJobModeAjax);
900
-			});
901
-		}
902
-		$this->batchApplyUserAttributes($recordsToUpdate);
903
-		return $this->fetchList($ldapRecords, $this->manyAttributes($attr));
904
-	}
905
-
906
-	/**
907
-	 * provided with an array of LDAP user records the method will fetch the
908
-	 * user object and requests it to process the freshly fetched attributes and
909
-	 * and their values
910
-	 *
911
-	 * @param array $ldapRecords
912
-	 * @throws \Exception
913
-	 */
914
-	public function batchApplyUserAttributes(array $ldapRecords) {
915
-		$displayNameAttribute = strtolower($this->connection->ldapUserDisplayName);
916
-		foreach ($ldapRecords as $userRecord) {
917
-			if (!isset($userRecord[$displayNameAttribute])) {
918
-				// displayName is obligatory
919
-				continue;
920
-			}
921
-			$ocName = $this->dn2ocname($userRecord['dn'][0], null, true);
922
-			if ($ocName === false) {
923
-				continue;
924
-			}
925
-			$this->updateUserState($ocName);
926
-			$user = $this->userManager->get($ocName);
927
-			if ($user !== null) {
928
-				$user->processAttributes($userRecord);
929
-			} else {
930
-				\OC::$server->getLogger()->debug(
931
-					"The ldap user manager returned null for $ocName",
932
-					['app' => 'user_ldap']
933
-				);
934
-			}
935
-		}
936
-	}
937
-
938
-	/**
939
-	 * @param string $filter
940
-	 * @param string|string[] $attr
941
-	 * @param int $limit
942
-	 * @param int $offset
943
-	 * @return array
944
-	 */
945
-	public function fetchListOfGroups($filter, $attr, $limit = null, $offset = null) {
946
-		$groupRecords = $this->searchGroups($filter, $attr, $limit, $offset);
947
-
948
-		$listOfDNs = array_reduce($groupRecords, function ($listOfDNs, $entry) {
949
-			$listOfDNs[] = $entry['dn'][0];
950
-			return $listOfDNs;
951
-		}, []);
952
-		$idsByDn = $this->groupMapper->getListOfIdsByDn($listOfDNs);
953
-
954
-		array_walk($groupRecords, function ($record) use ($idsByDn) {
955
-			$newlyMapped = false;
956
-			$gid = $idsByDn[$record['dn'][0]] ?? null;
957
-			if ($gid === null) {
958
-				$gid = $this->dn2ocname($record['dn'][0], null, false, $newlyMapped, $record);
959
-			}
960
-			if (!$newlyMapped && is_string($gid)) {
961
-				$this->cacheGroupExists($gid);
962
-			}
963
-		});
964
-		return $this->fetchList($groupRecords, $this->manyAttributes($attr));
965
-	}
966
-
967
-	/**
968
-	 * @param array $list
969
-	 * @param bool $manyAttributes
970
-	 * @return array
971
-	 */
972
-	private function fetchList($list, $manyAttributes) {
973
-		if (is_array($list)) {
974
-			if ($manyAttributes) {
975
-				return $list;
976
-			} else {
977
-				$list = array_reduce($list, function ($carry, $item) {
978
-					$attribute = array_keys($item)[0];
979
-					$carry[] = $item[$attribute][0];
980
-					return $carry;
981
-				}, []);
982
-				return array_unique($list, SORT_LOCALE_STRING);
983
-			}
984
-		}
985
-
986
-		//error cause actually, maybe throw an exception in future.
987
-		return [];
988
-	}
989
-
990
-	/**
991
-	 * @throws ServerNotAvailableException
992
-	 */
993
-	public function searchUsers(string $filter, array $attr = null, int $limit = null, int $offset = null): array {
994
-		$result = [];
995
-		foreach ($this->connection->ldapBaseUsers as $base) {
996
-			$result = array_merge($result, $this->search($filter, $base, $attr, $limit, $offset));
997
-		}
998
-		return $result;
999
-	}
1000
-
1001
-	/**
1002
-	 * @param string $filter
1003
-	 * @param string|string[] $attr
1004
-	 * @param int $limit
1005
-	 * @param int $offset
1006
-	 * @return false|int
1007
-	 * @throws ServerNotAvailableException
1008
-	 */
1009
-	public function countUsers($filter, $attr = ['dn'], $limit = null, $offset = null) {
1010
-		$result = false;
1011
-		foreach ($this->connection->ldapBaseUsers as $base) {
1012
-			$count = $this->count($filter, [$base], $attr, $limit, $offset);
1013
-			$result = is_int($count) ? (int)$result + $count : $result;
1014
-		}
1015
-		return $result;
1016
-	}
1017
-
1018
-	/**
1019
-	 * executes an LDAP search, optimized for Groups
1020
-	 *
1021
-	 * @param string $filter the LDAP filter for the search
1022
-	 * @param string|string[] $attr optional, when a certain attribute shall be filtered out
1023
-	 * @param integer $limit
1024
-	 * @param integer $offset
1025
-	 * @return array with the search result
1026
-	 *
1027
-	 * Executes an LDAP search
1028
-	 * @throws ServerNotAvailableException
1029
-	 */
1030
-	public function searchGroups($filter, $attr = null, $limit = null, $offset = null) {
1031
-		$result = [];
1032
-		foreach ($this->connection->ldapBaseGroups as $base) {
1033
-			$result = array_merge($result, $this->search($filter, $base, $attr, $limit, $offset));
1034
-		}
1035
-		return $result;
1036
-	}
1037
-
1038
-	/**
1039
-	 * returns the number of available groups
1040
-	 *
1041
-	 * @param string $filter the LDAP search filter
1042
-	 * @param string[] $attr optional
1043
-	 * @param int|null $limit
1044
-	 * @param int|null $offset
1045
-	 * @return int|bool
1046
-	 * @throws ServerNotAvailableException
1047
-	 */
1048
-	public function countGroups($filter, $attr = ['dn'], $limit = null, $offset = null) {
1049
-		$result = false;
1050
-		foreach ($this->connection->ldapBaseGroups as $base) {
1051
-			$count = $this->count($filter, [$base], $attr, $limit, $offset);
1052
-			$result = is_int($count) ? (int)$result + $count : $result;
1053
-		}
1054
-		return $result;
1055
-	}
1056
-
1057
-	/**
1058
-	 * returns the number of available objects on the base DN
1059
-	 *
1060
-	 * @param int|null $limit
1061
-	 * @param int|null $offset
1062
-	 * @return int|bool
1063
-	 * @throws ServerNotAvailableException
1064
-	 */
1065
-	public function countObjects($limit = null, $offset = null) {
1066
-		$result = false;
1067
-		foreach ($this->connection->ldapBase as $base) {
1068
-			$count = $this->count('objectclass=*', [$base], ['dn'], $limit, $offset);
1069
-			$result = is_int($count) ? (int)$result + $count : $result;
1070
-		}
1071
-		return $result;
1072
-	}
1073
-
1074
-	/**
1075
-	 * Returns the LDAP handler
1076
-	 *
1077
-	 * @throws \OC\ServerNotAvailableException
1078
-	 */
1079
-
1080
-	/**
1081
-	 * @return mixed
1082
-	 * @throws \OC\ServerNotAvailableException
1083
-	 */
1084
-	private function invokeLDAPMethod() {
1085
-		$arguments = func_get_args();
1086
-		$command = array_shift($arguments);
1087
-		$cr = array_shift($arguments);
1088
-		if (!method_exists($this->ldap, $command)) {
1089
-			return null;
1090
-		}
1091
-		array_unshift($arguments, $cr);
1092
-		// php no longer supports call-time pass-by-reference
1093
-		// thus cannot support controlPagedResultResponse as the third argument
1094
-		// is a reference
1095
-		$doMethod = function () use ($command, &$arguments) {
1096
-			if ($command == 'controlPagedResultResponse') {
1097
-				throw new \InvalidArgumentException('Invoker does not support controlPagedResultResponse, call LDAP Wrapper directly instead.');
1098
-			} else {
1099
-				return call_user_func_array([$this->ldap, $command], $arguments);
1100
-			}
1101
-		};
1102
-		try {
1103
-			$ret = $doMethod();
1104
-		} catch (ServerNotAvailableException $e) {
1105
-			/* Server connection lost, attempt to reestablish it
70
+    public const UUID_ATTRIBUTES = ['entryuuid', 'nsuniqueid', 'objectguid', 'guid', 'ipauniqueid'];
71
+
72
+    /** @var \OCA\User_LDAP\Connection */
73
+    public $connection;
74
+    /** @var Manager */
75
+    public $userManager;
76
+    //never ever check this var directly, always use getPagedSearchResultState
77
+    protected $pagedSearchedSuccessful;
78
+
79
+    /**
80
+     * @var UserMapping $userMapper
81
+     */
82
+    protected $userMapper;
83
+
84
+    /**
85
+     * @var AbstractMapping $userMapper
86
+     */
87
+    protected $groupMapper;
88
+
89
+    /**
90
+     * @var \OCA\User_LDAP\Helper
91
+     */
92
+    private $helper;
93
+    /** @var IConfig */
94
+    private $config;
95
+    /** @var IUserManager */
96
+    private $ncUserManager;
97
+    /** @var string */
98
+    private $lastCookie = '';
99
+
100
+    public function __construct(
101
+        Connection $connection,
102
+        ILDAPWrapper $ldap,
103
+        Manager $userManager,
104
+        Helper $helper,
105
+        IConfig $config,
106
+        IUserManager $ncUserManager
107
+    ) {
108
+        parent::__construct($ldap);
109
+        $this->connection = $connection;
110
+        $this->userManager = $userManager;
111
+        $this->userManager->setLdapAccess($this);
112
+        $this->helper = $helper;
113
+        $this->config = $config;
114
+        $this->ncUserManager = $ncUserManager;
115
+    }
116
+
117
+    /**
118
+     * sets the User Mapper
119
+     *
120
+     * @param AbstractMapping $mapper
121
+     */
122
+    public function setUserMapper(AbstractMapping $mapper) {
123
+        $this->userMapper = $mapper;
124
+    }
125
+
126
+    /**
127
+     * @throws \Exception
128
+     */
129
+    public function getUserMapper(): UserMapping {
130
+        if (is_null($this->userMapper)) {
131
+            throw new \Exception('UserMapper was not assigned to this Access instance.');
132
+        }
133
+        return $this->userMapper;
134
+    }
135
+
136
+    /**
137
+     * sets the Group Mapper
138
+     *
139
+     * @param AbstractMapping $mapper
140
+     */
141
+    public function setGroupMapper(AbstractMapping $mapper) {
142
+        $this->groupMapper = $mapper;
143
+    }
144
+
145
+    /**
146
+     * returns the Group Mapper
147
+     *
148
+     * @return AbstractMapping
149
+     * @throws \Exception
150
+     */
151
+    public function getGroupMapper() {
152
+        if (is_null($this->groupMapper)) {
153
+            throw new \Exception('GroupMapper was not assigned to this Access instance.');
154
+        }
155
+        return $this->groupMapper;
156
+    }
157
+
158
+    /**
159
+     * @return bool
160
+     */
161
+    private function checkConnection() {
162
+        return ($this->connection instanceof Connection);
163
+    }
164
+
165
+    /**
166
+     * returns the Connection instance
167
+     *
168
+     * @return \OCA\User_LDAP\Connection
169
+     */
170
+    public function getConnection() {
171
+        return $this->connection;
172
+    }
173
+
174
+    /**
175
+     * reads a given attribute for an LDAP record identified by a DN
176
+     *
177
+     * @param string $dn the record in question
178
+     * @param string $attr the attribute that shall be retrieved
179
+     *        if empty, just check the record's existence
180
+     * @param string $filter
181
+     * @return array|false an array of values on success or an empty
182
+     *          array if $attr is empty, false otherwise
183
+     * @throws ServerNotAvailableException
184
+     */
185
+    public function readAttribute($dn, $attr, $filter = 'objectClass=*') {
186
+        if (!$this->checkConnection()) {
187
+            \OCP\Util::writeLog('user_ldap',
188
+                'No LDAP Connector assigned, access impossible for readAttribute.',
189
+                ILogger::WARN);
190
+            return false;
191
+        }
192
+        $cr = $this->connection->getConnectionResource();
193
+        if (!$this->ldap->isResource($cr)) {
194
+            //LDAP not available
195
+            \OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', ILogger::DEBUG);
196
+            return false;
197
+        }
198
+        //Cancel possibly running Paged Results operation, otherwise we run in
199
+        //LDAP protocol errors
200
+        $this->abandonPagedSearch();
201
+        // openLDAP requires that we init a new Paged Search. Not needed by AD,
202
+        // but does not hurt either.
203
+        $pagingSize = (int)$this->connection->ldapPagingSize;
204
+        // 0 won't result in replies, small numbers may leave out groups
205
+        // (cf. #12306), 500 is default for paging and should work everywhere.
206
+        $maxResults = $pagingSize > 20 ? $pagingSize : 500;
207
+        $attr = mb_strtolower($attr, 'UTF-8');
208
+        // the actual read attribute later may contain parameters on a ranged
209
+        // request, e.g. member;range=99-199. Depends on server reply.
210
+        $attrToRead = $attr;
211
+
212
+        $values = [];
213
+        $isRangeRequest = false;
214
+        do {
215
+            $result = $this->executeRead($cr, $dn, $attrToRead, $filter, $maxResults);
216
+            if (is_bool($result)) {
217
+                // when an exists request was run and it was successful, an empty
218
+                // array must be returned
219
+                return $result ? [] : false;
220
+            }
221
+
222
+            if (!$isRangeRequest) {
223
+                $values = $this->extractAttributeValuesFromResult($result, $attr);
224
+                if (!empty($values)) {
225
+                    return $values;
226
+                }
227
+            }
228
+
229
+            $isRangeRequest = false;
230
+            $result = $this->extractRangeData($result, $attr);
231
+            if (!empty($result)) {
232
+                $normalizedResult = $this->extractAttributeValuesFromResult(
233
+                    [$attr => $result['values']],
234
+                    $attr
235
+                );
236
+                $values = array_merge($values, $normalizedResult);
237
+
238
+                if ($result['rangeHigh'] === '*') {
239
+                    // when server replies with * as high range value, there are
240
+                    // no more results left
241
+                    return $values;
242
+                } else {
243
+                    $low = $result['rangeHigh'] + 1;
244
+                    $attrToRead = $result['attributeName'] . ';range=' . $low . '-*';
245
+                    $isRangeRequest = true;
246
+                }
247
+            }
248
+        } while ($isRangeRequest);
249
+
250
+        \OCP\Util::writeLog('user_ldap', 'Requested attribute ' . $attr . ' not found for ' . $dn, ILogger::DEBUG);
251
+        return false;
252
+    }
253
+
254
+    /**
255
+     * Runs an read operation against LDAP
256
+     *
257
+     * @param resource $cr the LDAP connection
258
+     * @param string $dn
259
+     * @param string $attribute
260
+     * @param string $filter
261
+     * @param int $maxResults
262
+     * @return array|bool false if there was any error, true if an exists check
263
+     *                    was performed and the requested DN found, array with the
264
+     *                    returned data on a successful usual operation
265
+     * @throws ServerNotAvailableException
266
+     */
267
+    public function executeRead($cr, $dn, $attribute, $filter, $maxResults) {
268
+        try {
269
+            $this->initPagedSearch($filter, $dn, [$attribute], $maxResults, 0);
270
+        } catch (NoMoreResults $e) {
271
+            // does not happen, no pagination here since offset is 0, but the
272
+            // previous call is needed for a potential reset of the state.
273
+            // Tools would still point out a possible NoMoreResults exception.
274
+            return false;
275
+        }
276
+        $dn = $this->helper->DNasBaseParameter($dn);
277
+        $rr = @$this->invokeLDAPMethod('read', $cr, $dn, $filter, [$attribute]);
278
+        if (!$this->ldap->isResource($rr)) {
279
+            if ($attribute !== '') {
280
+                //do not throw this message on userExists check, irritates
281
+                \OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN ' . $dn, ILogger::DEBUG);
282
+            }
283
+            //in case an error occurs , e.g. object does not exist
284
+            return false;
285
+        }
286
+        if ($attribute === '' && ($filter === 'objectclass=*' || $this->invokeLDAPMethod('countEntries', $cr, $rr) === 1)) {
287
+            \OCP\Util::writeLog('user_ldap', 'readAttribute: ' . $dn . ' found', ILogger::DEBUG);
288
+            return true;
289
+        }
290
+        $er = $this->invokeLDAPMethod('firstEntry', $cr, $rr);
291
+        if (!$this->ldap->isResource($er)) {
292
+            //did not match the filter, return false
293
+            return false;
294
+        }
295
+        //LDAP attributes are not case sensitive
296
+        $result = \OCP\Util::mb_array_change_key_case(
297
+            $this->invokeLDAPMethod('getAttributes', $cr, $er), MB_CASE_LOWER, 'UTF-8');
298
+
299
+        return $result;
300
+    }
301
+
302
+    /**
303
+     * Normalizes a result grom getAttributes(), i.e. handles DNs and binary
304
+     * data if present.
305
+     *
306
+     * @param array $result from ILDAPWrapper::getAttributes()
307
+     * @param string $attribute the attribute name that was read
308
+     * @return string[]
309
+     */
310
+    public function extractAttributeValuesFromResult($result, $attribute) {
311
+        $values = [];
312
+        if (isset($result[$attribute]) && $result[$attribute]['count'] > 0) {
313
+            $lowercaseAttribute = strtolower($attribute);
314
+            for ($i = 0; $i < $result[$attribute]['count']; $i++) {
315
+                if ($this->resemblesDN($attribute)) {
316
+                    $values[] = $this->helper->sanitizeDN($result[$attribute][$i]);
317
+                } elseif ($lowercaseAttribute === 'objectguid' || $lowercaseAttribute === 'guid') {
318
+                    $values[] = $this->convertObjectGUID2Str($result[$attribute][$i]);
319
+                } else {
320
+                    $values[] = $result[$attribute][$i];
321
+                }
322
+            }
323
+        }
324
+        return $values;
325
+    }
326
+
327
+    /**
328
+     * Attempts to find ranged data in a getAttribute results and extracts the
329
+     * returned values as well as information on the range and full attribute
330
+     * name for further processing.
331
+     *
332
+     * @param array $result from ILDAPWrapper::getAttributes()
333
+     * @param string $attribute the attribute name that was read. Without ";range=…"
334
+     * @return array If a range was detected with keys 'values', 'attributeName',
335
+     *               'attributeFull' and 'rangeHigh', otherwise empty.
336
+     */
337
+    public function extractRangeData($result, $attribute) {
338
+        $keys = array_keys($result);
339
+        foreach ($keys as $key) {
340
+            if ($key !== $attribute && strpos($key, $attribute) === 0) {
341
+                $queryData = explode(';', $key);
342
+                if (strpos($queryData[1], 'range=') === 0) {
343
+                    $high = substr($queryData[1], 1 + strpos($queryData[1], '-'));
344
+                    $data = [
345
+                        'values' => $result[$key],
346
+                        'attributeName' => $queryData[0],
347
+                        'attributeFull' => $key,
348
+                        'rangeHigh' => $high,
349
+                    ];
350
+                    return $data;
351
+                }
352
+            }
353
+        }
354
+        return [];
355
+    }
356
+
357
+    /**
358
+     * Set password for an LDAP user identified by a DN
359
+     *
360
+     * @param string $userDN the user in question
361
+     * @param string $password the new password
362
+     * @return bool
363
+     * @throws HintException
364
+     * @throws \Exception
365
+     */
366
+    public function setPassword($userDN, $password) {
367
+        if ((int)$this->connection->turnOnPasswordChange !== 1) {
368
+            throw new \Exception('LDAP password changes are disabled.');
369
+        }
370
+        $cr = $this->connection->getConnectionResource();
371
+        if (!$this->ldap->isResource($cr)) {
372
+            //LDAP not available
373
+            \OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', ILogger::DEBUG);
374
+            return false;
375
+        }
376
+        try {
377
+            // try PASSWD extended operation first
378
+            return @$this->invokeLDAPMethod('exopPasswd', $cr, $userDN, '', $password) ||
379
+                @$this->invokeLDAPMethod('modReplace', $cr, $userDN, $password);
380
+        } catch (ConstraintViolationException $e) {
381
+            throw new HintException('Password change rejected.', \OC::$server->getL10N('user_ldap')->t('Password change rejected. Hint: ') . $e->getMessage(), $e->getCode());
382
+        }
383
+    }
384
+
385
+    /**
386
+     * checks whether the given attributes value is probably a DN
387
+     *
388
+     * @param string $attr the attribute in question
389
+     * @return boolean if so true, otherwise false
390
+     */
391
+    private function resemblesDN($attr) {
392
+        $resemblingAttributes = [
393
+            'dn',
394
+            'uniquemember',
395
+            'member',
396
+            // memberOf is an "operational" attribute, without a definition in any RFC
397
+            'memberof'
398
+        ];
399
+        return in_array($attr, $resemblingAttributes);
400
+    }
401
+
402
+    /**
403
+     * checks whether the given string is probably a DN
404
+     *
405
+     * @param string $string
406
+     * @return boolean
407
+     */
408
+    public function stringResemblesDN($string) {
409
+        $r = $this->ldap->explodeDN($string, 0);
410
+        // if exploding a DN succeeds and does not end up in
411
+        // an empty array except for $r[count] being 0.
412
+        return (is_array($r) && count($r) > 1);
413
+    }
414
+
415
+    /**
416
+     * returns a DN-string that is cleaned from not domain parts, e.g.
417
+     * cn=foo,cn=bar,dc=foobar,dc=server,dc=org
418
+     * becomes dc=foobar,dc=server,dc=org
419
+     *
420
+     * @param string $dn
421
+     * @return string
422
+     */
423
+    public function getDomainDNFromDN($dn) {
424
+        $allParts = $this->ldap->explodeDN($dn, 0);
425
+        if ($allParts === false) {
426
+            //not a valid DN
427
+            return '';
428
+        }
429
+        $domainParts = [];
430
+        $dcFound = false;
431
+        foreach ($allParts as $part) {
432
+            if (!$dcFound && strpos($part, 'dc=') === 0) {
433
+                $dcFound = true;
434
+            }
435
+            if ($dcFound) {
436
+                $domainParts[] = $part;
437
+            }
438
+        }
439
+        return implode(',', $domainParts);
440
+    }
441
+
442
+    /**
443
+     * returns the LDAP DN for the given internal Nextcloud name of the group
444
+     *
445
+     * @param string $name the Nextcloud name in question
446
+     * @return string|false LDAP DN on success, otherwise false
447
+     */
448
+    public function groupname2dn($name) {
449
+        return $this->groupMapper->getDNByName($name);
450
+    }
451
+
452
+    /**
453
+     * returns the LDAP DN for the given internal Nextcloud name of the user
454
+     *
455
+     * @param string $name the Nextcloud name in question
456
+     * @return string|false with the LDAP DN on success, otherwise false
457
+     */
458
+    public function username2dn($name) {
459
+        $fdn = $this->userMapper->getDNByName($name);
460
+
461
+        //Check whether the DN belongs to the Base, to avoid issues on multi-
462
+        //server setups
463
+        if (is_string($fdn) && $this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
464
+            return $fdn;
465
+        }
466
+
467
+        return false;
468
+    }
469
+
470
+    /**
471
+     * returns the internal Nextcloud name for the given LDAP DN of the group, false on DN outside of search DN or failure
472
+     *
473
+     * @param string $fdn the dn of the group object
474
+     * @param string $ldapName optional, the display name of the object
475
+     * @return string|false with the name to use in Nextcloud, false on DN outside of search DN
476
+     * @throws \Exception
477
+     */
478
+    public function dn2groupname($fdn, $ldapName = null) {
479
+        //To avoid bypassing the base DN settings under certain circumstances
480
+        //with the group support, check whether the provided DN matches one of
481
+        //the given Bases
482
+        if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) {
483
+            return false;
484
+        }
485
+
486
+        return $this->dn2ocname($fdn, $ldapName, false);
487
+    }
488
+
489
+    /**
490
+     * returns the internal Nextcloud name for the given LDAP DN of the user, false on DN outside of search DN or failure
491
+     *
492
+     * @param string $dn the dn of the user object
493
+     * @param string $ldapName optional, the display name of the object
494
+     * @return string|false with with the name to use in Nextcloud
495
+     * @throws \Exception
496
+     */
497
+    public function dn2username($fdn, $ldapName = null) {
498
+        //To avoid bypassing the base DN settings under certain circumstances
499
+        //with the group support, check whether the provided DN matches one of
500
+        //the given Bases
501
+        if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseUsers)) {
502
+            return false;
503
+        }
504
+
505
+        return $this->dn2ocname($fdn, $ldapName, true);
506
+    }
507
+
508
+    /**
509
+     * returns an internal Nextcloud name for the given LDAP DN, false on DN outside of search DN
510
+     *
511
+     * @param string $fdn the dn of the user object
512
+     * @param string|null $ldapName optional, the display name of the object
513
+     * @param bool $isUser optional, whether it is a user object (otherwise group assumed)
514
+     * @param bool|null $newlyMapped
515
+     * @param array|null $record
516
+     * @return false|string with with the name to use in Nextcloud
517
+     * @throws \Exception
518
+     */
519
+    public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped = null, array $record = null) {
520
+        $newlyMapped = false;
521
+        if ($isUser) {
522
+            $mapper = $this->getUserMapper();
523
+            $nameAttribute = $this->connection->ldapUserDisplayName;
524
+            $filter = $this->connection->ldapUserFilter;
525
+        } else {
526
+            $mapper = $this->getGroupMapper();
527
+            $nameAttribute = $this->connection->ldapGroupDisplayName;
528
+            $filter = $this->connection->ldapGroupFilter;
529
+        }
530
+
531
+        //let's try to retrieve the Nextcloud name from the mappings table
532
+        $ncName = $mapper->getNameByDN($fdn);
533
+        if (is_string($ncName)) {
534
+            return $ncName;
535
+        }
536
+
537
+        //second try: get the UUID and check if it is known. Then, update the DN and return the name.
538
+        $uuid = $this->getUUID($fdn, $isUser, $record);
539
+        if (is_string($uuid)) {
540
+            $ncName = $mapper->getNameByUUID($uuid);
541
+            if (is_string($ncName)) {
542
+                $mapper->setDNbyUUID($fdn, $uuid);
543
+                return $ncName;
544
+            }
545
+        } else {
546
+            //If the UUID can't be detected something is foul.
547
+            \OCP\Util::writeLog('user_ldap', 'Cannot determine UUID for ' . $fdn . '. Skipping.', ILogger::INFO);
548
+            return false;
549
+        }
550
+
551
+        if (is_null($ldapName)) {
552
+            $ldapName = $this->readAttribute($fdn, $nameAttribute, $filter);
553
+            if (!isset($ldapName[0]) && empty($ldapName[0])) {
554
+                \OCP\Util::writeLog('user_ldap', 'No or empty name for ' . $fdn . ' with filter ' . $filter . '.', ILogger::DEBUG);
555
+                return false;
556
+            }
557
+            $ldapName = $ldapName[0];
558
+        }
559
+
560
+        if ($isUser) {
561
+            $usernameAttribute = (string)$this->connection->ldapExpertUsernameAttr;
562
+            if ($usernameAttribute !== '') {
563
+                $username = $this->readAttribute($fdn, $usernameAttribute);
564
+                $username = $username[0];
565
+            } else {
566
+                $username = $uuid;
567
+            }
568
+            try {
569
+                $intName = $this->sanitizeUsername($username);
570
+            } catch (\InvalidArgumentException $e) {
571
+                \OC::$server->getLogger()->logException($e, [
572
+                    'app' => 'user_ldap',
573
+                    'level' => ILogger::WARN,
574
+                ]);
575
+                // we don't attempt to set a username here. We can go for
576
+                // for an alternative 4 digit random number as we would append
577
+                // otherwise, however it's likely not enough space in bigger
578
+                // setups, and most importantly: this is not intended.
579
+                return false;
580
+            }
581
+        } else {
582
+            $intName = $ldapName;
583
+        }
584
+
585
+        //a new user/group! Add it only if it doesn't conflict with other backend's users or existing groups
586
+        //disabling Cache is required to avoid that the new user is cached as not-existing in fooExists check
587
+        //NOTE: mind, disabling cache affects only this instance! Using it
588
+        // outside of core user management will still cache the user as non-existing.
589
+        $originalTTL = $this->connection->ldapCacheTTL;
590
+        $this->connection->setConfiguration(['ldapCacheTTL' => 0]);
591
+        if ($intName !== ''
592
+            && (($isUser && !$this->ncUserManager->userExists($intName))
593
+                || (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName))
594
+            )
595
+        ) {
596
+            $this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);
597
+            $newlyMapped = $this->mapAndAnnounceIfApplicable($mapper, $fdn, $intName, $uuid, $isUser);
598
+            if ($newlyMapped) {
599
+                return $intName;
600
+            }
601
+        }
602
+
603
+        $this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);
604
+        $altName = $this->createAltInternalOwnCloudName($intName, $isUser);
605
+        if (is_string($altName)) {
606
+            if ($this->mapAndAnnounceIfApplicable($mapper, $fdn, $altName, $uuid, $isUser)) {
607
+                $newlyMapped = true;
608
+                return $altName;
609
+            }
610
+        }
611
+
612
+        //if everything else did not help..
613
+        \OCP\Util::writeLog('user_ldap', 'Could not create unique name for ' . $fdn . '.', ILogger::INFO);
614
+        return false;
615
+    }
616
+
617
+    public function mapAndAnnounceIfApplicable(
618
+        AbstractMapping $mapper,
619
+        string $fdn,
620
+        string $name,
621
+        string $uuid,
622
+        bool $isUser
623
+    ): bool {
624
+        if ($mapper->map($fdn, $name, $uuid)) {
625
+            if ($this->ncUserManager instanceof PublicEmitter && $isUser) {
626
+                $this->cacheUserExists($name);
627
+                $this->ncUserManager->emit('\OC\User', 'assignedUserId', [$name]);
628
+            } elseif (!$isUser) {
629
+                $this->cacheGroupExists($name);
630
+            }
631
+            return true;
632
+        }
633
+        return false;
634
+    }
635
+
636
+    /**
637
+     * gives back the user names as they are used ownClod internally
638
+     *
639
+     * @param array $ldapUsers as returned by fetchList()
640
+     * @return array an array with the user names to use in Nextcloud
641
+     *
642
+     * gives back the user names as they are used ownClod internally
643
+     * @throws \Exception
644
+     */
645
+    public function nextcloudUserNames($ldapUsers) {
646
+        return $this->ldap2NextcloudNames($ldapUsers, true);
647
+    }
648
+
649
+    /**
650
+     * gives back the group names as they are used ownClod internally
651
+     *
652
+     * @param array $ldapGroups as returned by fetchList()
653
+     * @return array an array with the group names to use in Nextcloud
654
+     *
655
+     * gives back the group names as they are used ownClod internally
656
+     * @throws \Exception
657
+     */
658
+    public function nextcloudGroupNames($ldapGroups) {
659
+        return $this->ldap2NextcloudNames($ldapGroups, false);
660
+    }
661
+
662
+    /**
663
+     * @param array $ldapObjects as returned by fetchList()
664
+     * @param bool $isUsers
665
+     * @return array
666
+     * @throws \Exception
667
+     */
668
+    private function ldap2NextcloudNames($ldapObjects, $isUsers) {
669
+        if ($isUsers) {
670
+            $nameAttribute = $this->connection->ldapUserDisplayName;
671
+            $sndAttribute = $this->connection->ldapUserDisplayName2;
672
+        } else {
673
+            $nameAttribute = $this->connection->ldapGroupDisplayName;
674
+        }
675
+        $nextcloudNames = [];
676
+
677
+        foreach ($ldapObjects as $ldapObject) {
678
+            $nameByLDAP = null;
679
+            if (isset($ldapObject[$nameAttribute])
680
+                && is_array($ldapObject[$nameAttribute])
681
+                && isset($ldapObject[$nameAttribute][0])
682
+            ) {
683
+                // might be set, but not necessarily. if so, we use it.
684
+                $nameByLDAP = $ldapObject[$nameAttribute][0];
685
+            }
686
+
687
+            $ncName = $this->dn2ocname($ldapObject['dn'][0], $nameByLDAP, $isUsers);
688
+            if ($ncName) {
689
+                $nextcloudNames[] = $ncName;
690
+                if ($isUsers) {
691
+                    $this->updateUserState($ncName);
692
+                    //cache the user names so it does not need to be retrieved
693
+                    //again later (e.g. sharing dialogue).
694
+                    if (is_null($nameByLDAP)) {
695
+                        continue;
696
+                    }
697
+                    $sndName = isset($ldapObject[$sndAttribute][0])
698
+                        ? $ldapObject[$sndAttribute][0] : '';
699
+                    $this->cacheUserDisplayName($ncName, $nameByLDAP, $sndName);
700
+                } elseif ($nameByLDAP !== null) {
701
+                    $this->cacheGroupDisplayName($ncName, $nameByLDAP);
702
+                }
703
+            }
704
+        }
705
+        return $nextcloudNames;
706
+    }
707
+
708
+    /**
709
+     * removes the deleted-flag of a user if it was set
710
+     *
711
+     * @param string $ncname
712
+     * @throws \Exception
713
+     */
714
+    public function updateUserState($ncname) {
715
+        $user = $this->userManager->get($ncname);
716
+        if ($user instanceof OfflineUser) {
717
+            $user->unmark();
718
+        }
719
+    }
720
+
721
+    /**
722
+     * caches the user display name
723
+     *
724
+     * @param string $ocName the internal Nextcloud username
725
+     * @param string|false $home the home directory path
726
+     */
727
+    public function cacheUserHome($ocName, $home) {
728
+        $cacheKey = 'getHome' . $ocName;
729
+        $this->connection->writeToCache($cacheKey, $home);
730
+    }
731
+
732
+    /**
733
+     * caches a user as existing
734
+     *
735
+     * @param string $ocName the internal Nextcloud username
736
+     */
737
+    public function cacheUserExists($ocName) {
738
+        $this->connection->writeToCache('userExists' . $ocName, true);
739
+    }
740
+
741
+    /**
742
+     * caches a group as existing
743
+     */
744
+    public function cacheGroupExists(string $gid): void {
745
+        $this->connection->writeToCache('groupExists' . $gid, true);
746
+    }
747
+
748
+    /**
749
+     * caches the user display name
750
+     *
751
+     * @param string $ocName the internal Nextcloud username
752
+     * @param string $displayName the display name
753
+     * @param string $displayName2 the second display name
754
+     * @throws \Exception
755
+     */
756
+    public function cacheUserDisplayName($ocName, $displayName, $displayName2 = '') {
757
+        $user = $this->userManager->get($ocName);
758
+        if ($user === null) {
759
+            return;
760
+        }
761
+        $displayName = $user->composeAndStoreDisplayName($displayName, $displayName2);
762
+        $cacheKeyTrunk = 'getDisplayName';
763
+        $this->connection->writeToCache($cacheKeyTrunk . $ocName, $displayName);
764
+    }
765
+
766
+    public function cacheGroupDisplayName(string $ncName, string $displayName): void {
767
+        $cacheKey = 'group_getDisplayName' . $ncName;
768
+        $this->connection->writeToCache($cacheKey, $displayName);
769
+    }
770
+
771
+    /**
772
+     * creates a unique name for internal Nextcloud use for users. Don't call it directly.
773
+     *
774
+     * @param string $name the display name of the object
775
+     * @return string|false with with the name to use in Nextcloud or false if unsuccessful
776
+     *
777
+     * Instead of using this method directly, call
778
+     * createAltInternalOwnCloudName($name, true)
779
+     */
780
+    private function _createAltInternalOwnCloudNameForUsers($name) {
781
+        $attempts = 0;
782
+        //while loop is just a precaution. If a name is not generated within
783
+        //20 attempts, something else is very wrong. Avoids infinite loop.
784
+        while ($attempts < 20) {
785
+            $altName = $name . '_' . rand(1000, 9999);
786
+            if (!$this->ncUserManager->userExists($altName)) {
787
+                return $altName;
788
+            }
789
+            $attempts++;
790
+        }
791
+        return false;
792
+    }
793
+
794
+    /**
795
+     * creates a unique name for internal Nextcloud use for groups. Don't call it directly.
796
+     *
797
+     * @param string $name the display name of the object
798
+     * @return string|false with with the name to use in Nextcloud or false if unsuccessful.
799
+     *
800
+     * Instead of using this method directly, call
801
+     * createAltInternalOwnCloudName($name, false)
802
+     *
803
+     * Group names are also used as display names, so we do a sequential
804
+     * numbering, e.g. Developers_42 when there are 41 other groups called
805
+     * "Developers"
806
+     */
807
+    private function _createAltInternalOwnCloudNameForGroups($name) {
808
+        $usedNames = $this->groupMapper->getNamesBySearch($name, "", '_%');
809
+        if (!$usedNames || count($usedNames) === 0) {
810
+            $lastNo = 1; //will become name_2
811
+        } else {
812
+            natsort($usedNames);
813
+            $lastName = array_pop($usedNames);
814
+            $lastNo = (int)substr($lastName, strrpos($lastName, '_') + 1);
815
+        }
816
+        $altName = $name . '_' . (string)($lastNo + 1);
817
+        unset($usedNames);
818
+
819
+        $attempts = 1;
820
+        while ($attempts < 21) {
821
+            // Check to be really sure it is unique
822
+            // while loop is just a precaution. If a name is not generated within
823
+            // 20 attempts, something else is very wrong. Avoids infinite loop.
824
+            if (!\OC::$server->getGroupManager()->groupExists($altName)) {
825
+                return $altName;
826
+            }
827
+            $altName = $name . '_' . ($lastNo + $attempts);
828
+            $attempts++;
829
+        }
830
+        return false;
831
+    }
832
+
833
+    /**
834
+     * creates a unique name for internal Nextcloud use.
835
+     *
836
+     * @param string $name the display name of the object
837
+     * @param boolean $isUser whether name should be created for a user (true) or a group (false)
838
+     * @return string|false with with the name to use in Nextcloud or false if unsuccessful
839
+     */
840
+    private function createAltInternalOwnCloudName($name, $isUser) {
841
+        $originalTTL = $this->connection->ldapCacheTTL;
842
+        $this->connection->setConfiguration(['ldapCacheTTL' => 0]);
843
+        if ($isUser) {
844
+            $altName = $this->_createAltInternalOwnCloudNameForUsers($name);
845
+        } else {
846
+            $altName = $this->_createAltInternalOwnCloudNameForGroups($name);
847
+        }
848
+        $this->connection->setConfiguration(['ldapCacheTTL' => $originalTTL]);
849
+
850
+        return $altName;
851
+    }
852
+
853
+    /**
854
+     * fetches a list of users according to a provided loginName and utilizing
855
+     * the login filter.
856
+     */
857
+    public function fetchUsersByLoginName(string $loginName, array $attributes = ['dn']): array {
858
+        $loginName = $this->escapeFilterPart($loginName);
859
+        $filter = str_replace('%uid', $loginName, $this->connection->ldapLoginFilter);
860
+        return $this->fetchListOfUsers($filter, $attributes);
861
+    }
862
+
863
+    /**
864
+     * counts the number of users according to a provided loginName and
865
+     * utilizing the login filter.
866
+     *
867
+     * @param string $loginName
868
+     * @return int
869
+     */
870
+    public function countUsersByLoginName($loginName) {
871
+        $loginName = $this->escapeFilterPart($loginName);
872
+        $filter = str_replace('%uid', $loginName, $this->connection->ldapLoginFilter);
873
+        return $this->countUsers($filter);
874
+    }
875
+
876
+    /**
877
+     * @throws \Exception
878
+     */
879
+    public function fetchListOfUsers(string $filter, array $attr, int $limit = null, int $offset = null, bool $forceApplyAttributes = false): array {
880
+        $ldapRecords = $this->searchUsers($filter, $attr, $limit, $offset);
881
+        $recordsToUpdate = $ldapRecords;
882
+        if (!$forceApplyAttributes) {
883
+            $isBackgroundJobModeAjax = $this->config
884
+                    ->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'ajax';
885
+            $listOfDNs = array_reduce($ldapRecords, function ($listOfDNs, $entry) {
886
+                $listOfDNs[] = $entry['dn'][0];
887
+                return $listOfDNs;
888
+            }, []);
889
+            $idsByDn = $this->userMapper->getListOfIdsByDn($listOfDNs);
890
+            $recordsToUpdate = array_filter($ldapRecords, function ($record) use ($isBackgroundJobModeAjax, $idsByDn) {
891
+                $newlyMapped = false;
892
+                $uid = $idsByDn[$record['dn'][0]] ?? null;
893
+                if ($uid === null) {
894
+                    $uid = $this->dn2ocname($record['dn'][0], null, true, $newlyMapped, $record);
895
+                }
896
+                if (is_string($uid)) {
897
+                    $this->cacheUserExists($uid);
898
+                }
899
+                return ($uid !== false) && ($newlyMapped || $isBackgroundJobModeAjax);
900
+            });
901
+        }
902
+        $this->batchApplyUserAttributes($recordsToUpdate);
903
+        return $this->fetchList($ldapRecords, $this->manyAttributes($attr));
904
+    }
905
+
906
+    /**
907
+     * provided with an array of LDAP user records the method will fetch the
908
+     * user object and requests it to process the freshly fetched attributes and
909
+     * and their values
910
+     *
911
+     * @param array $ldapRecords
912
+     * @throws \Exception
913
+     */
914
+    public function batchApplyUserAttributes(array $ldapRecords) {
915
+        $displayNameAttribute = strtolower($this->connection->ldapUserDisplayName);
916
+        foreach ($ldapRecords as $userRecord) {
917
+            if (!isset($userRecord[$displayNameAttribute])) {
918
+                // displayName is obligatory
919
+                continue;
920
+            }
921
+            $ocName = $this->dn2ocname($userRecord['dn'][0], null, true);
922
+            if ($ocName === false) {
923
+                continue;
924
+            }
925
+            $this->updateUserState($ocName);
926
+            $user = $this->userManager->get($ocName);
927
+            if ($user !== null) {
928
+                $user->processAttributes($userRecord);
929
+            } else {
930
+                \OC::$server->getLogger()->debug(
931
+                    "The ldap user manager returned null for $ocName",
932
+                    ['app' => 'user_ldap']
933
+                );
934
+            }
935
+        }
936
+    }
937
+
938
+    /**
939
+     * @param string $filter
940
+     * @param string|string[] $attr
941
+     * @param int $limit
942
+     * @param int $offset
943
+     * @return array
944
+     */
945
+    public function fetchListOfGroups($filter, $attr, $limit = null, $offset = null) {
946
+        $groupRecords = $this->searchGroups($filter, $attr, $limit, $offset);
947
+
948
+        $listOfDNs = array_reduce($groupRecords, function ($listOfDNs, $entry) {
949
+            $listOfDNs[] = $entry['dn'][0];
950
+            return $listOfDNs;
951
+        }, []);
952
+        $idsByDn = $this->groupMapper->getListOfIdsByDn($listOfDNs);
953
+
954
+        array_walk($groupRecords, function ($record) use ($idsByDn) {
955
+            $newlyMapped = false;
956
+            $gid = $idsByDn[$record['dn'][0]] ?? null;
957
+            if ($gid === null) {
958
+                $gid = $this->dn2ocname($record['dn'][0], null, false, $newlyMapped, $record);
959
+            }
960
+            if (!$newlyMapped && is_string($gid)) {
961
+                $this->cacheGroupExists($gid);
962
+            }
963
+        });
964
+        return $this->fetchList($groupRecords, $this->manyAttributes($attr));
965
+    }
966
+
967
+    /**
968
+     * @param array $list
969
+     * @param bool $manyAttributes
970
+     * @return array
971
+     */
972
+    private function fetchList($list, $manyAttributes) {
973
+        if (is_array($list)) {
974
+            if ($manyAttributes) {
975
+                return $list;
976
+            } else {
977
+                $list = array_reduce($list, function ($carry, $item) {
978
+                    $attribute = array_keys($item)[0];
979
+                    $carry[] = $item[$attribute][0];
980
+                    return $carry;
981
+                }, []);
982
+                return array_unique($list, SORT_LOCALE_STRING);
983
+            }
984
+        }
985
+
986
+        //error cause actually, maybe throw an exception in future.
987
+        return [];
988
+    }
989
+
990
+    /**
991
+     * @throws ServerNotAvailableException
992
+     */
993
+    public function searchUsers(string $filter, array $attr = null, int $limit = null, int $offset = null): array {
994
+        $result = [];
995
+        foreach ($this->connection->ldapBaseUsers as $base) {
996
+            $result = array_merge($result, $this->search($filter, $base, $attr, $limit, $offset));
997
+        }
998
+        return $result;
999
+    }
1000
+
1001
+    /**
1002
+     * @param string $filter
1003
+     * @param string|string[] $attr
1004
+     * @param int $limit
1005
+     * @param int $offset
1006
+     * @return false|int
1007
+     * @throws ServerNotAvailableException
1008
+     */
1009
+    public function countUsers($filter, $attr = ['dn'], $limit = null, $offset = null) {
1010
+        $result = false;
1011
+        foreach ($this->connection->ldapBaseUsers as $base) {
1012
+            $count = $this->count($filter, [$base], $attr, $limit, $offset);
1013
+            $result = is_int($count) ? (int)$result + $count : $result;
1014
+        }
1015
+        return $result;
1016
+    }
1017
+
1018
+    /**
1019
+     * executes an LDAP search, optimized for Groups
1020
+     *
1021
+     * @param string $filter the LDAP filter for the search
1022
+     * @param string|string[] $attr optional, when a certain attribute shall be filtered out
1023
+     * @param integer $limit
1024
+     * @param integer $offset
1025
+     * @return array with the search result
1026
+     *
1027
+     * Executes an LDAP search
1028
+     * @throws ServerNotAvailableException
1029
+     */
1030
+    public function searchGroups($filter, $attr = null, $limit = null, $offset = null) {
1031
+        $result = [];
1032
+        foreach ($this->connection->ldapBaseGroups as $base) {
1033
+            $result = array_merge($result, $this->search($filter, $base, $attr, $limit, $offset));
1034
+        }
1035
+        return $result;
1036
+    }
1037
+
1038
+    /**
1039
+     * returns the number of available groups
1040
+     *
1041
+     * @param string $filter the LDAP search filter
1042
+     * @param string[] $attr optional
1043
+     * @param int|null $limit
1044
+     * @param int|null $offset
1045
+     * @return int|bool
1046
+     * @throws ServerNotAvailableException
1047
+     */
1048
+    public function countGroups($filter, $attr = ['dn'], $limit = null, $offset = null) {
1049
+        $result = false;
1050
+        foreach ($this->connection->ldapBaseGroups as $base) {
1051
+            $count = $this->count($filter, [$base], $attr, $limit, $offset);
1052
+            $result = is_int($count) ? (int)$result + $count : $result;
1053
+        }
1054
+        return $result;
1055
+    }
1056
+
1057
+    /**
1058
+     * returns the number of available objects on the base DN
1059
+     *
1060
+     * @param int|null $limit
1061
+     * @param int|null $offset
1062
+     * @return int|bool
1063
+     * @throws ServerNotAvailableException
1064
+     */
1065
+    public function countObjects($limit = null, $offset = null) {
1066
+        $result = false;
1067
+        foreach ($this->connection->ldapBase as $base) {
1068
+            $count = $this->count('objectclass=*', [$base], ['dn'], $limit, $offset);
1069
+            $result = is_int($count) ? (int)$result + $count : $result;
1070
+        }
1071
+        return $result;
1072
+    }
1073
+
1074
+    /**
1075
+     * Returns the LDAP handler
1076
+     *
1077
+     * @throws \OC\ServerNotAvailableException
1078
+     */
1079
+
1080
+    /**
1081
+     * @return mixed
1082
+     * @throws \OC\ServerNotAvailableException
1083
+     */
1084
+    private function invokeLDAPMethod() {
1085
+        $arguments = func_get_args();
1086
+        $command = array_shift($arguments);
1087
+        $cr = array_shift($arguments);
1088
+        if (!method_exists($this->ldap, $command)) {
1089
+            return null;
1090
+        }
1091
+        array_unshift($arguments, $cr);
1092
+        // php no longer supports call-time pass-by-reference
1093
+        // thus cannot support controlPagedResultResponse as the third argument
1094
+        // is a reference
1095
+        $doMethod = function () use ($command, &$arguments) {
1096
+            if ($command == 'controlPagedResultResponse') {
1097
+                throw new \InvalidArgumentException('Invoker does not support controlPagedResultResponse, call LDAP Wrapper directly instead.');
1098
+            } else {
1099
+                return call_user_func_array([$this->ldap, $command], $arguments);
1100
+            }
1101
+        };
1102
+        try {
1103
+            $ret = $doMethod();
1104
+        } catch (ServerNotAvailableException $e) {
1105
+            /* Server connection lost, attempt to reestablish it
1106 1106
 			 * Maybe implement exponential backoff?
1107 1107
 			 * This was enough to get solr indexer working which has large delays between LDAP fetches.
1108 1108
 			 */
1109
-			\OCP\Util::writeLog('user_ldap', "Connection lost on $command, attempting to reestablish.", ILogger::DEBUG);
1110
-			$this->connection->resetConnectionResource();
1111
-			$cr = $this->connection->getConnectionResource();
1112
-
1113
-			if (!$this->ldap->isResource($cr)) {
1114
-				// Seems like we didn't find any resource.
1115
-				\OCP\Util::writeLog('user_ldap', "Could not $command, because resource is missing.", ILogger::DEBUG);
1116
-				throw $e;
1117
-			}
1118
-
1119
-			$arguments[0] = $cr;
1120
-			$ret = $doMethod();
1121
-		}
1122
-		return $ret;
1123
-	}
1124
-
1125
-	/**
1126
-	 * retrieved. Results will according to the order in the array.
1127
-	 *
1128
-	 * @param string $filter
1129
-	 * @param string $base
1130
-	 * @param string[] $attr
1131
-	 * @param int|null $limit optional, maximum results to be counted
1132
-	 * @param int|null $offset optional, a starting point
1133
-	 * @return array|false array with the search result as first value and pagedSearchOK as
1134
-	 * second | false if not successful
1135
-	 * @throws ServerNotAvailableException
1136
-	 */
1137
-	private function executeSearch(
1138
-		string $filter,
1139
-		string $base,
1140
-		?array &$attr,
1141
-		?int $limit,
1142
-		?int $offset
1143
-	) {
1144
-		// See if we have a resource, in case not cancel with message
1145
-		$cr = $this->connection->getConnectionResource();
1146
-		if (!$this->ldap->isResource($cr)) {
1147
-			// Seems like we didn't find any resource.
1148
-			// Return an empty array just like before.
1149
-			\OCP\Util::writeLog('user_ldap', 'Could not search, because resource is missing.', ILogger::DEBUG);
1150
-			return false;
1151
-		}
1152
-
1153
-		//check whether paged search should be attempted
1154
-		try {
1155
-			$pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, (int)$limit, (int)$offset);
1156
-		} catch (NoMoreResults $e) {
1157
-			// beyond last results page
1158
-			return false;
1159
-		}
1160
-
1161
-		$sr = $this->invokeLDAPMethod('search', $cr, $base, $filter, $attr);
1162
-		// cannot use $cr anymore, might have changed in the previous call!
1163
-		$error = $this->ldap->errno($this->connection->getConnectionResource());
1164
-		if (!$this->ldap->isResource($sr) || $error !== 0) {
1165
-			\OCP\Util::writeLog('user_ldap', 'Attempt for Paging?  ' . print_r($pagedSearchOK, true), ILogger::ERROR);
1166
-			return false;
1167
-		}
1168
-
1169
-		return [$sr, $pagedSearchOK];
1170
-	}
1171
-
1172
-	/**
1173
-	 * processes an LDAP paged search operation
1174
-	 *
1175
-	 * @param resource $sr the array containing the LDAP search resources
1176
-	 * @param int $foundItems number of results in the single search operation
1177
-	 * @param int $limit maximum results to be counted
1178
-	 * @param bool $pagedSearchOK whether a paged search has been executed
1179
-	 * @param bool $skipHandling required for paged search when cookies to
1180
-	 * prior results need to be gained
1181
-	 * @return bool cookie validity, true if we have more pages, false otherwise.
1182
-	 * @throws ServerNotAvailableException
1183
-	 */
1184
-	private function processPagedSearchStatus(
1185
-		$sr,
1186
-		int $foundItems,
1187
-		int $limit,
1188
-		bool $pagedSearchOK,
1189
-		bool $skipHandling
1190
-	): bool {
1191
-		$cookie = null;
1192
-		if ($pagedSearchOK) {
1193
-			$cr = $this->connection->getConnectionResource();
1194
-			if ($this->ldap->controlPagedResultResponse($cr, $sr, $cookie)) {
1195
-				$this->lastCookie = $cookie;
1196
-			}
1197
-
1198
-			//browsing through prior pages to get the cookie for the new one
1199
-			if ($skipHandling) {
1200
-				return false;
1201
-			}
1202
-			// if count is bigger, then the server does not support
1203
-			// paged search. Instead, he did a normal search. We set a
1204
-			// flag here, so the callee knows how to deal with it.
1205
-			if ($foundItems <= $limit) {
1206
-				$this->pagedSearchedSuccessful = true;
1207
-			}
1208
-		} else {
1209
-			if (!is_null($limit) && (int)$this->connection->ldapPagingSize !== 0) {
1210
-				\OC::$server->getLogger()->debug(
1211
-					'Paged search was not available',
1212
-					['app' => 'user_ldap']
1213
-				);
1214
-			}
1215
-		}
1216
-		/* ++ Fixing RHDS searches with pages with zero results ++
1109
+            \OCP\Util::writeLog('user_ldap', "Connection lost on $command, attempting to reestablish.", ILogger::DEBUG);
1110
+            $this->connection->resetConnectionResource();
1111
+            $cr = $this->connection->getConnectionResource();
1112
+
1113
+            if (!$this->ldap->isResource($cr)) {
1114
+                // Seems like we didn't find any resource.
1115
+                \OCP\Util::writeLog('user_ldap', "Could not $command, because resource is missing.", ILogger::DEBUG);
1116
+                throw $e;
1117
+            }
1118
+
1119
+            $arguments[0] = $cr;
1120
+            $ret = $doMethod();
1121
+        }
1122
+        return $ret;
1123
+    }
1124
+
1125
+    /**
1126
+     * retrieved. Results will according to the order in the array.
1127
+     *
1128
+     * @param string $filter
1129
+     * @param string $base
1130
+     * @param string[] $attr
1131
+     * @param int|null $limit optional, maximum results to be counted
1132
+     * @param int|null $offset optional, a starting point
1133
+     * @return array|false array with the search result as first value and pagedSearchOK as
1134
+     * second | false if not successful
1135
+     * @throws ServerNotAvailableException
1136
+     */
1137
+    private function executeSearch(
1138
+        string $filter,
1139
+        string $base,
1140
+        ?array &$attr,
1141
+        ?int $limit,
1142
+        ?int $offset
1143
+    ) {
1144
+        // See if we have a resource, in case not cancel with message
1145
+        $cr = $this->connection->getConnectionResource();
1146
+        if (!$this->ldap->isResource($cr)) {
1147
+            // Seems like we didn't find any resource.
1148
+            // Return an empty array just like before.
1149
+            \OCP\Util::writeLog('user_ldap', 'Could not search, because resource is missing.', ILogger::DEBUG);
1150
+            return false;
1151
+        }
1152
+
1153
+        //check whether paged search should be attempted
1154
+        try {
1155
+            $pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, (int)$limit, (int)$offset);
1156
+        } catch (NoMoreResults $e) {
1157
+            // beyond last results page
1158
+            return false;
1159
+        }
1160
+
1161
+        $sr = $this->invokeLDAPMethod('search', $cr, $base, $filter, $attr);
1162
+        // cannot use $cr anymore, might have changed in the previous call!
1163
+        $error = $this->ldap->errno($this->connection->getConnectionResource());
1164
+        if (!$this->ldap->isResource($sr) || $error !== 0) {
1165
+            \OCP\Util::writeLog('user_ldap', 'Attempt for Paging?  ' . print_r($pagedSearchOK, true), ILogger::ERROR);
1166
+            return false;
1167
+        }
1168
+
1169
+        return [$sr, $pagedSearchOK];
1170
+    }
1171
+
1172
+    /**
1173
+     * processes an LDAP paged search operation
1174
+     *
1175
+     * @param resource $sr the array containing the LDAP search resources
1176
+     * @param int $foundItems number of results in the single search operation
1177
+     * @param int $limit maximum results to be counted
1178
+     * @param bool $pagedSearchOK whether a paged search has been executed
1179
+     * @param bool $skipHandling required for paged search when cookies to
1180
+     * prior results need to be gained
1181
+     * @return bool cookie validity, true if we have more pages, false otherwise.
1182
+     * @throws ServerNotAvailableException
1183
+     */
1184
+    private function processPagedSearchStatus(
1185
+        $sr,
1186
+        int $foundItems,
1187
+        int $limit,
1188
+        bool $pagedSearchOK,
1189
+        bool $skipHandling
1190
+    ): bool {
1191
+        $cookie = null;
1192
+        if ($pagedSearchOK) {
1193
+            $cr = $this->connection->getConnectionResource();
1194
+            if ($this->ldap->controlPagedResultResponse($cr, $sr, $cookie)) {
1195
+                $this->lastCookie = $cookie;
1196
+            }
1197
+
1198
+            //browsing through prior pages to get the cookie for the new one
1199
+            if ($skipHandling) {
1200
+                return false;
1201
+            }
1202
+            // if count is bigger, then the server does not support
1203
+            // paged search. Instead, he did a normal search. We set a
1204
+            // flag here, so the callee knows how to deal with it.
1205
+            if ($foundItems <= $limit) {
1206
+                $this->pagedSearchedSuccessful = true;
1207
+            }
1208
+        } else {
1209
+            if (!is_null($limit) && (int)$this->connection->ldapPagingSize !== 0) {
1210
+                \OC::$server->getLogger()->debug(
1211
+                    'Paged search was not available',
1212
+                    ['app' => 'user_ldap']
1213
+                );
1214
+            }
1215
+        }
1216
+        /* ++ Fixing RHDS searches with pages with zero results ++
1217 1217
 		 * Return cookie status. If we don't have more pages, with RHDS
1218 1218
 		 * cookie is null, with openldap cookie is an empty string and
1219 1219
 		 * to 386ds '0' is a valid cookie. Even if $iFoundItems == 0
1220 1220
 		 */
1221
-		return !empty($cookie) || $cookie === '0';
1222
-	}
1223
-
1224
-	/**
1225
-	 * executes an LDAP search, but counts the results only
1226
-	 *
1227
-	 * @param string $filter the LDAP filter for the search
1228
-	 * @param array $bases an array containing the LDAP subtree(s) that shall be searched
1229
-	 * @param string|string[] $attr optional, array, one or more attributes that shall be
1230
-	 * retrieved. Results will according to the order in the array.
1231
-	 * @param int $limit optional, maximum results to be counted
1232
-	 * @param int $offset optional, a starting point
1233
-	 * @param bool $skipHandling indicates whether the pages search operation is
1234
-	 * completed
1235
-	 * @return int|false Integer or false if the search could not be initialized
1236
-	 * @throws ServerNotAvailableException
1237
-	 */
1238
-	private function count(
1239
-		string $filter,
1240
-		array $bases,
1241
-		$attr = null,
1242
-		?int $limit = null,
1243
-		?int $offset = null,
1244
-		bool $skipHandling = false
1245
-	) {
1246
-		\OC::$server->getLogger()->debug('Count filter: {filter}', [
1247
-			'app' => 'user_ldap',
1248
-			'filter' => $filter
1249
-		]);
1250
-
1251
-		if (!is_null($attr) && !is_array($attr)) {
1252
-			$attr = [mb_strtolower($attr, 'UTF-8')];
1253
-		}
1254
-
1255
-		$limitPerPage = (int)$this->connection->ldapPagingSize;
1256
-		if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1257
-			$limitPerPage = $limit;
1258
-		}
1259
-
1260
-		$counter = 0;
1261
-		$count = null;
1262
-		$this->connection->getConnectionResource();
1263
-
1264
-		foreach ($bases as $base) {
1265
-			do {
1266
-				$search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset);
1267
-				if ($search === false) {
1268
-					return $counter > 0 ? $counter : false;
1269
-				}
1270
-				[$sr, $pagedSearchOK] = $search;
1271
-
1272
-				/* ++ Fixing RHDS searches with pages with zero results ++
1221
+        return !empty($cookie) || $cookie === '0';
1222
+    }
1223
+
1224
+    /**
1225
+     * executes an LDAP search, but counts the results only
1226
+     *
1227
+     * @param string $filter the LDAP filter for the search
1228
+     * @param array $bases an array containing the LDAP subtree(s) that shall be searched
1229
+     * @param string|string[] $attr optional, array, one or more attributes that shall be
1230
+     * retrieved. Results will according to the order in the array.
1231
+     * @param int $limit optional, maximum results to be counted
1232
+     * @param int $offset optional, a starting point
1233
+     * @param bool $skipHandling indicates whether the pages search operation is
1234
+     * completed
1235
+     * @return int|false Integer or false if the search could not be initialized
1236
+     * @throws ServerNotAvailableException
1237
+     */
1238
+    private function count(
1239
+        string $filter,
1240
+        array $bases,
1241
+        $attr = null,
1242
+        ?int $limit = null,
1243
+        ?int $offset = null,
1244
+        bool $skipHandling = false
1245
+    ) {
1246
+        \OC::$server->getLogger()->debug('Count filter: {filter}', [
1247
+            'app' => 'user_ldap',
1248
+            'filter' => $filter
1249
+        ]);
1250
+
1251
+        if (!is_null($attr) && !is_array($attr)) {
1252
+            $attr = [mb_strtolower($attr, 'UTF-8')];
1253
+        }
1254
+
1255
+        $limitPerPage = (int)$this->connection->ldapPagingSize;
1256
+        if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1257
+            $limitPerPage = $limit;
1258
+        }
1259
+
1260
+        $counter = 0;
1261
+        $count = null;
1262
+        $this->connection->getConnectionResource();
1263
+
1264
+        foreach ($bases as $base) {
1265
+            do {
1266
+                $search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset);
1267
+                if ($search === false) {
1268
+                    return $counter > 0 ? $counter : false;
1269
+                }
1270
+                [$sr, $pagedSearchOK] = $search;
1271
+
1272
+                /* ++ Fixing RHDS searches with pages with zero results ++
1273 1273
 				 * countEntriesInSearchResults() method signature changed
1274 1274
 				 * by removing $limit and &$hasHitLimit parameters
1275 1275
 				 */
1276
-				$count = $this->countEntriesInSearchResults($sr);
1277
-				$counter += $count;
1276
+                $count = $this->countEntriesInSearchResults($sr);
1277
+                $counter += $count;
1278 1278
 
1279
-				$hasMorePages = $this->processPagedSearchStatus($sr, $count, $limitPerPage, $pagedSearchOK, $skipHandling);
1280
-				$offset += $limitPerPage;
1281
-				/* ++ Fixing RHDS searches with pages with zero results ++
1279
+                $hasMorePages = $this->processPagedSearchStatus($sr, $count, $limitPerPage, $pagedSearchOK, $skipHandling);
1280
+                $offset += $limitPerPage;
1281
+                /* ++ Fixing RHDS searches with pages with zero results ++
1282 1282
 				 * Continue now depends on $hasMorePages value
1283 1283
 				 */
1284
-				$continue = $pagedSearchOK && $hasMorePages;
1285
-			} while ($continue && (is_null($limit) || $limit <= 0 || $limit > $counter));
1286
-		}
1287
-
1288
-		return $counter;
1289
-	}
1290
-
1291
-	/**
1292
-	 * @param resource $sr
1293
-	 * @return int
1294
-	 * @throws ServerNotAvailableException
1295
-	 */
1296
-	private function countEntriesInSearchResults($sr): int {
1297
-		return (int)$this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $sr);
1298
-	}
1299
-
1300
-	/**
1301
-	 * Executes an LDAP search
1302
-	 *
1303
-	 * @throws ServerNotAvailableException
1304
-	 */
1305
-	public function search(
1306
-		string $filter,
1307
-		string $base,
1308
-		?array $attr = null,
1309
-		?int $limit = null,
1310
-		?int $offset = null,
1311
-		bool $skipHandling = false
1312
-	): array {
1313
-		$limitPerPage = (int)$this->connection->ldapPagingSize;
1314
-		if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1315
-			$limitPerPage = $limit;
1316
-		}
1317
-
1318
-		if (!is_null($attr) && !is_array($attr)) {
1319
-			$attr = [mb_strtolower($attr, 'UTF-8')];
1320
-		}
1321
-
1322
-		/* ++ Fixing RHDS searches with pages with zero results ++
1284
+                $continue = $pagedSearchOK && $hasMorePages;
1285
+            } while ($continue && (is_null($limit) || $limit <= 0 || $limit > $counter));
1286
+        }
1287
+
1288
+        return $counter;
1289
+    }
1290
+
1291
+    /**
1292
+     * @param resource $sr
1293
+     * @return int
1294
+     * @throws ServerNotAvailableException
1295
+     */
1296
+    private function countEntriesInSearchResults($sr): int {
1297
+        return (int)$this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $sr);
1298
+    }
1299
+
1300
+    /**
1301
+     * Executes an LDAP search
1302
+     *
1303
+     * @throws ServerNotAvailableException
1304
+     */
1305
+    public function search(
1306
+        string $filter,
1307
+        string $base,
1308
+        ?array $attr = null,
1309
+        ?int $limit = null,
1310
+        ?int $offset = null,
1311
+        bool $skipHandling = false
1312
+    ): array {
1313
+        $limitPerPage = (int)$this->connection->ldapPagingSize;
1314
+        if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1315
+            $limitPerPage = $limit;
1316
+        }
1317
+
1318
+        if (!is_null($attr) && !is_array($attr)) {
1319
+            $attr = [mb_strtolower($attr, 'UTF-8')];
1320
+        }
1321
+
1322
+        /* ++ Fixing RHDS searches with pages with zero results ++
1323 1323
 		 * As we can have pages with zero results and/or pages with less
1324 1324
 		 * than $limit results but with a still valid server 'cookie',
1325 1325
 		 * loops through until we get $continue equals true and
1326 1326
 		 * $findings['count'] < $limit
1327 1327
 		 */
1328
-		$findings = [];
1329
-		$savedoffset = $offset;
1330
-		$iFoundItems = 0;
1331
-
1332
-		do {
1333
-			$search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset);
1334
-			if ($search === false) {
1335
-				return [];
1336
-			}
1337
-			[$sr, $pagedSearchOK] = $search;
1338
-			$cr = $this->connection->getConnectionResource();
1339
-
1340
-			if ($skipHandling) {
1341
-				//i.e. result do not need to be fetched, we just need the cookie
1342
-				//thus pass 1 or any other value as $iFoundItems because it is not
1343
-				//used
1344
-				$this->processPagedSearchStatus($sr, 1, $limitPerPage, $pagedSearchOK, $skipHandling);
1345
-				return [];
1346
-			}
1347
-
1348
-			$findings = array_merge($findings, $this->invokeLDAPMethod('getEntries', $cr, $sr));
1349
-			$iFoundItems = max($iFoundItems, $findings['count']);
1350
-			unset($findings['count']);
1351
-
1352
-			$continue = $this->processPagedSearchStatus($sr, $iFoundItems, $limitPerPage, $pagedSearchOK, $skipHandling);
1353
-			$offset += $limitPerPage;
1354
-		} while ($continue && $pagedSearchOK && ($limit === null || count($findings) < $limit));
1355
-
1356
-		// resetting offset
1357
-		$offset = $savedoffset;
1358
-
1359
-		// if we're here, probably no connection resource is returned.
1360
-		// to make Nextcloud behave nicely, we simply give back an empty array.
1361
-		if (is_null($findings)) {
1362
-			return [];
1363
-		}
1364
-
1365
-		if (!is_null($attr)) {
1366
-			$selection = [];
1367
-			$i = 0;
1368
-			foreach ($findings as $item) {
1369
-				if (!is_array($item)) {
1370
-					continue;
1371
-				}
1372
-				$item = \OCP\Util::mb_array_change_key_case($item, MB_CASE_LOWER, 'UTF-8');
1373
-				foreach ($attr as $key) {
1374
-					if (isset($item[$key])) {
1375
-						if (is_array($item[$key]) && isset($item[$key]['count'])) {
1376
-							unset($item[$key]['count']);
1377
-						}
1378
-						if ($key !== 'dn') {
1379
-							if ($this->resemblesDN($key)) {
1380
-								$selection[$i][$key] = $this->helper->sanitizeDN($item[$key]);
1381
-							} elseif ($key === 'objectguid' || $key === 'guid') {
1382
-								$selection[$i][$key] = [$this->convertObjectGUID2Str($item[$key][0])];
1383
-							} else {
1384
-								$selection[$i][$key] = $item[$key];
1385
-							}
1386
-						} else {
1387
-							$selection[$i][$key] = [$this->helper->sanitizeDN($item[$key])];
1388
-						}
1389
-					}
1390
-				}
1391
-				$i++;
1392
-			}
1393
-			$findings = $selection;
1394
-		}
1395
-		//we slice the findings, when
1396
-		//a) paged search unsuccessful, though attempted
1397
-		//b) no paged search, but limit set
1398
-		if ((!$this->getPagedSearchResultState()
1399
-				&& $pagedSearchOK)
1400
-			|| (
1401
-				!$pagedSearchOK
1402
-				&& !is_null($limit)
1403
-			)
1404
-		) {
1405
-			$findings = array_slice($findings, (int)$offset, $limit);
1406
-		}
1407
-		return $findings;
1408
-	}
1409
-
1410
-	/**
1411
-	 * @param string $name
1412
-	 * @return string
1413
-	 * @throws \InvalidArgumentException
1414
-	 */
1415
-	public function sanitizeUsername($name) {
1416
-		$name = trim($name);
1417
-
1418
-		if ($this->connection->ldapIgnoreNamingRules) {
1419
-			return $name;
1420
-		}
1421
-
1422
-		// Transliteration to ASCII
1423
-		$transliterated = @iconv('UTF-8', 'ASCII//TRANSLIT', $name);
1424
-		if ($transliterated !== false) {
1425
-			// depending on system config iconv can work or not
1426
-			$name = $transliterated;
1427
-		}
1428
-
1429
-		// Replacements
1430
-		$name = str_replace(' ', '_', $name);
1431
-
1432
-		// Every remaining disallowed characters will be removed
1433
-		$name = preg_replace('/[^a-zA-Z0-9_.@-]/u', '', $name);
1434
-
1435
-		if ($name === '') {
1436
-			throw new \InvalidArgumentException('provided name template for username does not contain any allowed characters');
1437
-		}
1438
-
1439
-		return $name;
1440
-	}
1441
-
1442
-	/**
1443
-	 * escapes (user provided) parts for LDAP filter
1444
-	 *
1445
-	 * @param string $input , the provided value
1446
-	 * @param bool $allowAsterisk whether in * at the beginning should be preserved
1447
-	 * @return string the escaped string
1448
-	 */
1449
-	public function escapeFilterPart($input, $allowAsterisk = false): string {
1450
-		$asterisk = '';
1451
-		if ($allowAsterisk && strlen($input) > 0 && $input[0] === '*') {
1452
-			$asterisk = '*';
1453
-			$input = mb_substr($input, 1, null, 'UTF-8');
1454
-		}
1455
-		$search = ['*', '\\', '(', ')'];
1456
-		$replace = ['\\*', '\\\\', '\\(', '\\)'];
1457
-		return $asterisk . str_replace($search, $replace, $input);
1458
-	}
1459
-
1460
-	/**
1461
-	 * combines the input filters with AND
1462
-	 *
1463
-	 * @param string[] $filters the filters to connect
1464
-	 * @return string the combined filter
1465
-	 */
1466
-	public function combineFilterWithAnd($filters): string {
1467
-		return $this->combineFilter($filters, '&');
1468
-	}
1469
-
1470
-	/**
1471
-	 * combines the input filters with OR
1472
-	 *
1473
-	 * @param string[] $filters the filters to connect
1474
-	 * @return string the combined filter
1475
-	 * Combines Filter arguments with OR
1476
-	 */
1477
-	public function combineFilterWithOr($filters) {
1478
-		return $this->combineFilter($filters, '|');
1479
-	}
1480
-
1481
-	/**
1482
-	 * combines the input filters with given operator
1483
-	 *
1484
-	 * @param string[] $filters the filters to connect
1485
-	 * @param string $operator either & or |
1486
-	 * @return string the combined filter
1487
-	 */
1488
-	private function combineFilter($filters, $operator) {
1489
-		$combinedFilter = '(' . $operator;
1490
-		foreach ($filters as $filter) {
1491
-			if ($filter !== '' && $filter[0] !== '(') {
1492
-				$filter = '(' . $filter . ')';
1493
-			}
1494
-			$combinedFilter .= $filter;
1495
-		}
1496
-		$combinedFilter .= ')';
1497
-		return $combinedFilter;
1498
-	}
1499
-
1500
-	/**
1501
-	 * creates a filter part for to perform search for users
1502
-	 *
1503
-	 * @param string $search the search term
1504
-	 * @return string the final filter part to use in LDAP searches
1505
-	 */
1506
-	public function getFilterPartForUserSearch($search) {
1507
-		return $this->getFilterPartForSearch($search,
1508
-			$this->connection->ldapAttributesForUserSearch,
1509
-			$this->connection->ldapUserDisplayName);
1510
-	}
1511
-
1512
-	/**
1513
-	 * creates a filter part for to perform search for groups
1514
-	 *
1515
-	 * @param string $search the search term
1516
-	 * @return string the final filter part to use in LDAP searches
1517
-	 */
1518
-	public function getFilterPartForGroupSearch($search) {
1519
-		return $this->getFilterPartForSearch($search,
1520
-			$this->connection->ldapAttributesForGroupSearch,
1521
-			$this->connection->ldapGroupDisplayName);
1522
-	}
1523
-
1524
-	/**
1525
-	 * creates a filter part for searches by splitting up the given search
1526
-	 * string into single words
1527
-	 *
1528
-	 * @param string $search the search term
1529
-	 * @param string[] $searchAttributes needs to have at least two attributes,
1530
-	 * otherwise it does not make sense :)
1531
-	 * @return string the final filter part to use in LDAP searches
1532
-	 * @throws DomainException
1533
-	 */
1534
-	private function getAdvancedFilterPartForSearch($search, $searchAttributes) {
1535
-		if (!is_array($searchAttributes) || count($searchAttributes) < 2) {
1536
-			throw new DomainException('searchAttributes must be an array with at least two string');
1537
-		}
1538
-		$searchWords = explode(' ', trim($search));
1539
-		$wordFilters = [];
1540
-		foreach ($searchWords as $word) {
1541
-			$word = $this->prepareSearchTerm($word);
1542
-			//every word needs to appear at least once
1543
-			$wordMatchOneAttrFilters = [];
1544
-			foreach ($searchAttributes as $attr) {
1545
-				$wordMatchOneAttrFilters[] = $attr . '=' . $word;
1546
-			}
1547
-			$wordFilters[] = $this->combineFilterWithOr($wordMatchOneAttrFilters);
1548
-		}
1549
-		return $this->combineFilterWithAnd($wordFilters);
1550
-	}
1551
-
1552
-	/**
1553
-	 * creates a filter part for searches
1554
-	 *
1555
-	 * @param string $search the search term
1556
-	 * @param string[]|null $searchAttributes
1557
-	 * @param string $fallbackAttribute a fallback attribute in case the user
1558
-	 * did not define search attributes. Typically the display name attribute.
1559
-	 * @return string the final filter part to use in LDAP searches
1560
-	 */
1561
-	private function getFilterPartForSearch($search, $searchAttributes, $fallbackAttribute) {
1562
-		$filter = [];
1563
-		$haveMultiSearchAttributes = (is_array($searchAttributes) && count($searchAttributes) > 0);
1564
-		if ($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) {
1565
-			try {
1566
-				return $this->getAdvancedFilterPartForSearch($search, $searchAttributes);
1567
-			} catch (DomainException $e) {
1568
-				// Creating advanced filter for search failed, falling back to simple method. Edge case, but valid.
1569
-			}
1570
-		}
1571
-
1572
-		$search = $this->prepareSearchTerm($search);
1573
-		if (!is_array($searchAttributes) || count($searchAttributes) === 0) {
1574
-			if ($fallbackAttribute === '') {
1575
-				return '';
1576
-			}
1577
-			$filter[] = $fallbackAttribute . '=' . $search;
1578
-		} else {
1579
-			foreach ($searchAttributes as $attribute) {
1580
-				$filter[] = $attribute . '=' . $search;
1581
-			}
1582
-		}
1583
-		if (count($filter) === 1) {
1584
-			return '(' . $filter[0] . ')';
1585
-		}
1586
-		return $this->combineFilterWithOr($filter);
1587
-	}
1588
-
1589
-	/**
1590
-	 * returns the search term depending on whether we are allowed
1591
-	 * list users found by ldap with the current input appended by
1592
-	 * a *
1593
-	 *
1594
-	 * @return string
1595
-	 */
1596
-	private function prepareSearchTerm($term) {
1597
-		$config = \OC::$server->getConfig();
1598
-
1599
-		$allowEnum = $config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes');
1600
-
1601
-		$result = $term;
1602
-		if ($term === '') {
1603
-			$result = '*';
1604
-		} elseif ($allowEnum !== 'no') {
1605
-			$result = $term . '*';
1606
-		}
1607
-		return $result;
1608
-	}
1609
-
1610
-	/**
1611
-	 * returns the filter used for counting users
1612
-	 *
1613
-	 * @return string
1614
-	 */
1615
-	public function getFilterForUserCount() {
1616
-		$filter = $this->combineFilterWithAnd([
1617
-			$this->connection->ldapUserFilter,
1618
-			$this->connection->ldapUserDisplayName . '=*'
1619
-		]);
1620
-
1621
-		return $filter;
1622
-	}
1623
-
1624
-	/**
1625
-	 * @param string $name
1626
-	 * @param string $password
1627
-	 * @return bool
1628
-	 */
1629
-	public function areCredentialsValid($name, $password) {
1630
-		$name = $this->helper->DNasBaseParameter($name);
1631
-		$testConnection = clone $this->connection;
1632
-		$credentials = [
1633
-			'ldapAgentName' => $name,
1634
-			'ldapAgentPassword' => $password
1635
-		];
1636
-		if (!$testConnection->setConfiguration($credentials)) {
1637
-			return false;
1638
-		}
1639
-		return $testConnection->bind();
1640
-	}
1641
-
1642
-	/**
1643
-	 * reverse lookup of a DN given a known UUID
1644
-	 *
1645
-	 * @param string $uuid
1646
-	 * @return string
1647
-	 * @throws \Exception
1648
-	 */
1649
-	public function getUserDnByUuid($uuid) {
1650
-		$uuidOverride = $this->connection->ldapExpertUUIDUserAttr;
1651
-		$filter = $this->connection->ldapUserFilter;
1652
-		$bases = $this->connection->ldapBaseUsers;
1653
-
1654
-		if ($this->connection->ldapUuidUserAttribute === 'auto' && $uuidOverride === '') {
1655
-			// Sacrebleu! The UUID attribute is unknown :( We need first an
1656
-			// existing DN to be able to reliably detect it.
1657
-			foreach ($bases as $base) {
1658
-				$result = $this->search($filter, $base, ['dn'], 1);
1659
-				if (!isset($result[0]) || !isset($result[0]['dn'])) {
1660
-					continue;
1661
-				}
1662
-				$dn = $result[0]['dn'][0];
1663
-				if ($hasFound = $this->detectUuidAttribute($dn, true)) {
1664
-					break;
1665
-				}
1666
-			}
1667
-			if (!isset($hasFound) || !$hasFound) {
1668
-				throw new \Exception('Cannot determine UUID attribute');
1669
-			}
1670
-		} else {
1671
-			// The UUID attribute is either known or an override is given.
1672
-			// By calling this method we ensure that $this->connection->$uuidAttr
1673
-			// is definitely set
1674
-			if (!$this->detectUuidAttribute('', true)) {
1675
-				throw new \Exception('Cannot determine UUID attribute');
1676
-			}
1677
-		}
1678
-
1679
-		$uuidAttr = $this->connection->ldapUuidUserAttribute;
1680
-		if ($uuidAttr === 'guid' || $uuidAttr === 'objectguid') {
1681
-			$uuid = $this->formatGuid2ForFilterUser($uuid);
1682
-		}
1683
-
1684
-		$filter = $uuidAttr . '=' . $uuid;
1685
-		$result = $this->searchUsers($filter, ['dn'], 2);
1686
-		if (is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) {
1687
-			// we put the count into account to make sure that this is
1688
-			// really unique
1689
-			return $result[0]['dn'][0];
1690
-		}
1691
-
1692
-		throw new \Exception('Cannot determine UUID attribute');
1693
-	}
1694
-
1695
-	/**
1696
-	 * auto-detects the directory's UUID attribute
1697
-	 *
1698
-	 * @param string $dn a known DN used to check against
1699
-	 * @param bool $isUser
1700
-	 * @param bool $force the detection should be run, even if it is not set to auto
1701
-	 * @param array|null $ldapRecord
1702
-	 * @return bool true on success, false otherwise
1703
-	 * @throws ServerNotAvailableException
1704
-	 */
1705
-	private function detectUuidAttribute($dn, $isUser = true, $force = false, array $ldapRecord = null) {
1706
-		if ($isUser) {
1707
-			$uuidAttr = 'ldapUuidUserAttribute';
1708
-			$uuidOverride = $this->connection->ldapExpertUUIDUserAttr;
1709
-		} else {
1710
-			$uuidAttr = 'ldapUuidGroupAttribute';
1711
-			$uuidOverride = $this->connection->ldapExpertUUIDGroupAttr;
1712
-		}
1713
-
1714
-		if (!$force) {
1715
-			if ($this->connection->$uuidAttr !== 'auto') {
1716
-				return true;
1717
-			} elseif (is_string($uuidOverride) && trim($uuidOverride) !== '') {
1718
-				$this->connection->$uuidAttr = $uuidOverride;
1719
-				return true;
1720
-			}
1721
-
1722
-			$attribute = $this->connection->getFromCache($uuidAttr);
1723
-			if (!$attribute === null) {
1724
-				$this->connection->$uuidAttr = $attribute;
1725
-				return true;
1726
-			}
1727
-		}
1728
-
1729
-		foreach (self::UUID_ATTRIBUTES as $attribute) {
1730
-			if ($ldapRecord !== null) {
1731
-				// we have the info from LDAP already, we don't need to talk to the server again
1732
-				if (isset($ldapRecord[$attribute])) {
1733
-					$this->connection->$uuidAttr = $attribute;
1734
-					return true;
1735
-				}
1736
-			}
1737
-
1738
-			$value = $this->readAttribute($dn, $attribute);
1739
-			if (is_array($value) && isset($value[0]) && !empty($value[0])) {
1740
-				\OC::$server->getLogger()->debug(
1741
-					'Setting {attribute} as {subject}',
1742
-					[
1743
-						'app' => 'user_ldap',
1744
-						'attribute' => $attribute,
1745
-						'subject' => $uuidAttr
1746
-					]
1747
-				);
1748
-				$this->connection->$uuidAttr = $attribute;
1749
-				$this->connection->writeToCache($uuidAttr, $attribute);
1750
-				return true;
1751
-			}
1752
-		}
1753
-		\OC::$server->getLogger()->debug('Could not autodetect the UUID attribute', ['app' => 'user_ldap']);
1754
-
1755
-		return false;
1756
-	}
1757
-
1758
-	/**
1759
-	 * @param string $dn
1760
-	 * @param bool $isUser
1761
-	 * @param null $ldapRecord
1762
-	 * @return bool|string
1763
-	 * @throws ServerNotAvailableException
1764
-	 */
1765
-	public function getUUID($dn, $isUser = true, $ldapRecord = null) {
1766
-		if ($isUser) {
1767
-			$uuidAttr = 'ldapUuidUserAttribute';
1768
-			$uuidOverride = $this->connection->ldapExpertUUIDUserAttr;
1769
-		} else {
1770
-			$uuidAttr = 'ldapUuidGroupAttribute';
1771
-			$uuidOverride = $this->connection->ldapExpertUUIDGroupAttr;
1772
-		}
1773
-
1774
-		$uuid = false;
1775
-		if ($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) {
1776
-			$attr = $this->connection->$uuidAttr;
1777
-			$uuid = isset($ldapRecord[$attr]) ? $ldapRecord[$attr] : $this->readAttribute($dn, $attr);
1778
-			if (!is_array($uuid)
1779
-				&& $uuidOverride !== ''
1780
-				&& $this->detectUuidAttribute($dn, $isUser, true, $ldapRecord)) {
1781
-				$uuid = isset($ldapRecord[$this->connection->$uuidAttr])
1782
-					? $ldapRecord[$this->connection->$uuidAttr]
1783
-					: $this->readAttribute($dn, $this->connection->$uuidAttr);
1784
-			}
1785
-			if (is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) {
1786
-				$uuid = $uuid[0];
1787
-			}
1788
-		}
1789
-
1790
-		return $uuid;
1791
-	}
1792
-
1793
-	/**
1794
-	 * converts a binary ObjectGUID into a string representation
1795
-	 *
1796
-	 * @param string $oguid the ObjectGUID in it's binary form as retrieved from AD
1797
-	 * @return string
1798
-	 * @link https://www.php.net/manual/en/function.ldap-get-values-len.php#73198
1799
-	 */
1800
-	private function convertObjectGUID2Str($oguid) {
1801
-		$hex_guid = bin2hex($oguid);
1802
-		$hex_guid_to_guid_str = '';
1803
-		for ($k = 1; $k <= 4; ++$k) {
1804
-			$hex_guid_to_guid_str .= substr($hex_guid, 8 - 2 * $k, 2);
1805
-		}
1806
-		$hex_guid_to_guid_str .= '-';
1807
-		for ($k = 1; $k <= 2; ++$k) {
1808
-			$hex_guid_to_guid_str .= substr($hex_guid, 12 - 2 * $k, 2);
1809
-		}
1810
-		$hex_guid_to_guid_str .= '-';
1811
-		for ($k = 1; $k <= 2; ++$k) {
1812
-			$hex_guid_to_guid_str .= substr($hex_guid, 16 - 2 * $k, 2);
1813
-		}
1814
-		$hex_guid_to_guid_str .= '-' . substr($hex_guid, 16, 4);
1815
-		$hex_guid_to_guid_str .= '-' . substr($hex_guid, 20);
1816
-
1817
-		return strtoupper($hex_guid_to_guid_str);
1818
-	}
1819
-
1820
-	/**
1821
-	 * the first three blocks of the string-converted GUID happen to be in
1822
-	 * reverse order. In order to use it in a filter, this needs to be
1823
-	 * corrected. Furthermore the dashes need to be replaced and \\ preprended
1824
-	 * to every two hax figures.
1825
-	 *
1826
-	 * If an invalid string is passed, it will be returned without change.
1827
-	 *
1828
-	 * @param string $guid
1829
-	 * @return string
1830
-	 */
1831
-	public function formatGuid2ForFilterUser($guid) {
1832
-		if (!is_string($guid)) {
1833
-			throw new \InvalidArgumentException('String expected');
1834
-		}
1835
-		$blocks = explode('-', $guid);
1836
-		if (count($blocks) !== 5) {
1837
-			/*
1328
+        $findings = [];
1329
+        $savedoffset = $offset;
1330
+        $iFoundItems = 0;
1331
+
1332
+        do {
1333
+            $search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset);
1334
+            if ($search === false) {
1335
+                return [];
1336
+            }
1337
+            [$sr, $pagedSearchOK] = $search;
1338
+            $cr = $this->connection->getConnectionResource();
1339
+
1340
+            if ($skipHandling) {
1341
+                //i.e. result do not need to be fetched, we just need the cookie
1342
+                //thus pass 1 or any other value as $iFoundItems because it is not
1343
+                //used
1344
+                $this->processPagedSearchStatus($sr, 1, $limitPerPage, $pagedSearchOK, $skipHandling);
1345
+                return [];
1346
+            }
1347
+
1348
+            $findings = array_merge($findings, $this->invokeLDAPMethod('getEntries', $cr, $sr));
1349
+            $iFoundItems = max($iFoundItems, $findings['count']);
1350
+            unset($findings['count']);
1351
+
1352
+            $continue = $this->processPagedSearchStatus($sr, $iFoundItems, $limitPerPage, $pagedSearchOK, $skipHandling);
1353
+            $offset += $limitPerPage;
1354
+        } while ($continue && $pagedSearchOK && ($limit === null || count($findings) < $limit));
1355
+
1356
+        // resetting offset
1357
+        $offset = $savedoffset;
1358
+
1359
+        // if we're here, probably no connection resource is returned.
1360
+        // to make Nextcloud behave nicely, we simply give back an empty array.
1361
+        if (is_null($findings)) {
1362
+            return [];
1363
+        }
1364
+
1365
+        if (!is_null($attr)) {
1366
+            $selection = [];
1367
+            $i = 0;
1368
+            foreach ($findings as $item) {
1369
+                if (!is_array($item)) {
1370
+                    continue;
1371
+                }
1372
+                $item = \OCP\Util::mb_array_change_key_case($item, MB_CASE_LOWER, 'UTF-8');
1373
+                foreach ($attr as $key) {
1374
+                    if (isset($item[$key])) {
1375
+                        if (is_array($item[$key]) && isset($item[$key]['count'])) {
1376
+                            unset($item[$key]['count']);
1377
+                        }
1378
+                        if ($key !== 'dn') {
1379
+                            if ($this->resemblesDN($key)) {
1380
+                                $selection[$i][$key] = $this->helper->sanitizeDN($item[$key]);
1381
+                            } elseif ($key === 'objectguid' || $key === 'guid') {
1382
+                                $selection[$i][$key] = [$this->convertObjectGUID2Str($item[$key][0])];
1383
+                            } else {
1384
+                                $selection[$i][$key] = $item[$key];
1385
+                            }
1386
+                        } else {
1387
+                            $selection[$i][$key] = [$this->helper->sanitizeDN($item[$key])];
1388
+                        }
1389
+                    }
1390
+                }
1391
+                $i++;
1392
+            }
1393
+            $findings = $selection;
1394
+        }
1395
+        //we slice the findings, when
1396
+        //a) paged search unsuccessful, though attempted
1397
+        //b) no paged search, but limit set
1398
+        if ((!$this->getPagedSearchResultState()
1399
+                && $pagedSearchOK)
1400
+            || (
1401
+                !$pagedSearchOK
1402
+                && !is_null($limit)
1403
+            )
1404
+        ) {
1405
+            $findings = array_slice($findings, (int)$offset, $limit);
1406
+        }
1407
+        return $findings;
1408
+    }
1409
+
1410
+    /**
1411
+     * @param string $name
1412
+     * @return string
1413
+     * @throws \InvalidArgumentException
1414
+     */
1415
+    public function sanitizeUsername($name) {
1416
+        $name = trim($name);
1417
+
1418
+        if ($this->connection->ldapIgnoreNamingRules) {
1419
+            return $name;
1420
+        }
1421
+
1422
+        // Transliteration to ASCII
1423
+        $transliterated = @iconv('UTF-8', 'ASCII//TRANSLIT', $name);
1424
+        if ($transliterated !== false) {
1425
+            // depending on system config iconv can work or not
1426
+            $name = $transliterated;
1427
+        }
1428
+
1429
+        // Replacements
1430
+        $name = str_replace(' ', '_', $name);
1431
+
1432
+        // Every remaining disallowed characters will be removed
1433
+        $name = preg_replace('/[^a-zA-Z0-9_.@-]/u', '', $name);
1434
+
1435
+        if ($name === '') {
1436
+            throw new \InvalidArgumentException('provided name template for username does not contain any allowed characters');
1437
+        }
1438
+
1439
+        return $name;
1440
+    }
1441
+
1442
+    /**
1443
+     * escapes (user provided) parts for LDAP filter
1444
+     *
1445
+     * @param string $input , the provided value
1446
+     * @param bool $allowAsterisk whether in * at the beginning should be preserved
1447
+     * @return string the escaped string
1448
+     */
1449
+    public function escapeFilterPart($input, $allowAsterisk = false): string {
1450
+        $asterisk = '';
1451
+        if ($allowAsterisk && strlen($input) > 0 && $input[0] === '*') {
1452
+            $asterisk = '*';
1453
+            $input = mb_substr($input, 1, null, 'UTF-8');
1454
+        }
1455
+        $search = ['*', '\\', '(', ')'];
1456
+        $replace = ['\\*', '\\\\', '\\(', '\\)'];
1457
+        return $asterisk . str_replace($search, $replace, $input);
1458
+    }
1459
+
1460
+    /**
1461
+     * combines the input filters with AND
1462
+     *
1463
+     * @param string[] $filters the filters to connect
1464
+     * @return string the combined filter
1465
+     */
1466
+    public function combineFilterWithAnd($filters): string {
1467
+        return $this->combineFilter($filters, '&');
1468
+    }
1469
+
1470
+    /**
1471
+     * combines the input filters with OR
1472
+     *
1473
+     * @param string[] $filters the filters to connect
1474
+     * @return string the combined filter
1475
+     * Combines Filter arguments with OR
1476
+     */
1477
+    public function combineFilterWithOr($filters) {
1478
+        return $this->combineFilter($filters, '|');
1479
+    }
1480
+
1481
+    /**
1482
+     * combines the input filters with given operator
1483
+     *
1484
+     * @param string[] $filters the filters to connect
1485
+     * @param string $operator either & or |
1486
+     * @return string the combined filter
1487
+     */
1488
+    private function combineFilter($filters, $operator) {
1489
+        $combinedFilter = '(' . $operator;
1490
+        foreach ($filters as $filter) {
1491
+            if ($filter !== '' && $filter[0] !== '(') {
1492
+                $filter = '(' . $filter . ')';
1493
+            }
1494
+            $combinedFilter .= $filter;
1495
+        }
1496
+        $combinedFilter .= ')';
1497
+        return $combinedFilter;
1498
+    }
1499
+
1500
+    /**
1501
+     * creates a filter part for to perform search for users
1502
+     *
1503
+     * @param string $search the search term
1504
+     * @return string the final filter part to use in LDAP searches
1505
+     */
1506
+    public function getFilterPartForUserSearch($search) {
1507
+        return $this->getFilterPartForSearch($search,
1508
+            $this->connection->ldapAttributesForUserSearch,
1509
+            $this->connection->ldapUserDisplayName);
1510
+    }
1511
+
1512
+    /**
1513
+     * creates a filter part for to perform search for groups
1514
+     *
1515
+     * @param string $search the search term
1516
+     * @return string the final filter part to use in LDAP searches
1517
+     */
1518
+    public function getFilterPartForGroupSearch($search) {
1519
+        return $this->getFilterPartForSearch($search,
1520
+            $this->connection->ldapAttributesForGroupSearch,
1521
+            $this->connection->ldapGroupDisplayName);
1522
+    }
1523
+
1524
+    /**
1525
+     * creates a filter part for searches by splitting up the given search
1526
+     * string into single words
1527
+     *
1528
+     * @param string $search the search term
1529
+     * @param string[] $searchAttributes needs to have at least two attributes,
1530
+     * otherwise it does not make sense :)
1531
+     * @return string the final filter part to use in LDAP searches
1532
+     * @throws DomainException
1533
+     */
1534
+    private function getAdvancedFilterPartForSearch($search, $searchAttributes) {
1535
+        if (!is_array($searchAttributes) || count($searchAttributes) < 2) {
1536
+            throw new DomainException('searchAttributes must be an array with at least two string');
1537
+        }
1538
+        $searchWords = explode(' ', trim($search));
1539
+        $wordFilters = [];
1540
+        foreach ($searchWords as $word) {
1541
+            $word = $this->prepareSearchTerm($word);
1542
+            //every word needs to appear at least once
1543
+            $wordMatchOneAttrFilters = [];
1544
+            foreach ($searchAttributes as $attr) {
1545
+                $wordMatchOneAttrFilters[] = $attr . '=' . $word;
1546
+            }
1547
+            $wordFilters[] = $this->combineFilterWithOr($wordMatchOneAttrFilters);
1548
+        }
1549
+        return $this->combineFilterWithAnd($wordFilters);
1550
+    }
1551
+
1552
+    /**
1553
+     * creates a filter part for searches
1554
+     *
1555
+     * @param string $search the search term
1556
+     * @param string[]|null $searchAttributes
1557
+     * @param string $fallbackAttribute a fallback attribute in case the user
1558
+     * did not define search attributes. Typically the display name attribute.
1559
+     * @return string the final filter part to use in LDAP searches
1560
+     */
1561
+    private function getFilterPartForSearch($search, $searchAttributes, $fallbackAttribute) {
1562
+        $filter = [];
1563
+        $haveMultiSearchAttributes = (is_array($searchAttributes) && count($searchAttributes) > 0);
1564
+        if ($haveMultiSearchAttributes && strpos(trim($search), ' ') !== false) {
1565
+            try {
1566
+                return $this->getAdvancedFilterPartForSearch($search, $searchAttributes);
1567
+            } catch (DomainException $e) {
1568
+                // Creating advanced filter for search failed, falling back to simple method. Edge case, but valid.
1569
+            }
1570
+        }
1571
+
1572
+        $search = $this->prepareSearchTerm($search);
1573
+        if (!is_array($searchAttributes) || count($searchAttributes) === 0) {
1574
+            if ($fallbackAttribute === '') {
1575
+                return '';
1576
+            }
1577
+            $filter[] = $fallbackAttribute . '=' . $search;
1578
+        } else {
1579
+            foreach ($searchAttributes as $attribute) {
1580
+                $filter[] = $attribute . '=' . $search;
1581
+            }
1582
+        }
1583
+        if (count($filter) === 1) {
1584
+            return '(' . $filter[0] . ')';
1585
+        }
1586
+        return $this->combineFilterWithOr($filter);
1587
+    }
1588
+
1589
+    /**
1590
+     * returns the search term depending on whether we are allowed
1591
+     * list users found by ldap with the current input appended by
1592
+     * a *
1593
+     *
1594
+     * @return string
1595
+     */
1596
+    private function prepareSearchTerm($term) {
1597
+        $config = \OC::$server->getConfig();
1598
+
1599
+        $allowEnum = $config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes');
1600
+
1601
+        $result = $term;
1602
+        if ($term === '') {
1603
+            $result = '*';
1604
+        } elseif ($allowEnum !== 'no') {
1605
+            $result = $term . '*';
1606
+        }
1607
+        return $result;
1608
+    }
1609
+
1610
+    /**
1611
+     * returns the filter used for counting users
1612
+     *
1613
+     * @return string
1614
+     */
1615
+    public function getFilterForUserCount() {
1616
+        $filter = $this->combineFilterWithAnd([
1617
+            $this->connection->ldapUserFilter,
1618
+            $this->connection->ldapUserDisplayName . '=*'
1619
+        ]);
1620
+
1621
+        return $filter;
1622
+    }
1623
+
1624
+    /**
1625
+     * @param string $name
1626
+     * @param string $password
1627
+     * @return bool
1628
+     */
1629
+    public function areCredentialsValid($name, $password) {
1630
+        $name = $this->helper->DNasBaseParameter($name);
1631
+        $testConnection = clone $this->connection;
1632
+        $credentials = [
1633
+            'ldapAgentName' => $name,
1634
+            'ldapAgentPassword' => $password
1635
+        ];
1636
+        if (!$testConnection->setConfiguration($credentials)) {
1637
+            return false;
1638
+        }
1639
+        return $testConnection->bind();
1640
+    }
1641
+
1642
+    /**
1643
+     * reverse lookup of a DN given a known UUID
1644
+     *
1645
+     * @param string $uuid
1646
+     * @return string
1647
+     * @throws \Exception
1648
+     */
1649
+    public function getUserDnByUuid($uuid) {
1650
+        $uuidOverride = $this->connection->ldapExpertUUIDUserAttr;
1651
+        $filter = $this->connection->ldapUserFilter;
1652
+        $bases = $this->connection->ldapBaseUsers;
1653
+
1654
+        if ($this->connection->ldapUuidUserAttribute === 'auto' && $uuidOverride === '') {
1655
+            // Sacrebleu! The UUID attribute is unknown :( We need first an
1656
+            // existing DN to be able to reliably detect it.
1657
+            foreach ($bases as $base) {
1658
+                $result = $this->search($filter, $base, ['dn'], 1);
1659
+                if (!isset($result[0]) || !isset($result[0]['dn'])) {
1660
+                    continue;
1661
+                }
1662
+                $dn = $result[0]['dn'][0];
1663
+                if ($hasFound = $this->detectUuidAttribute($dn, true)) {
1664
+                    break;
1665
+                }
1666
+            }
1667
+            if (!isset($hasFound) || !$hasFound) {
1668
+                throw new \Exception('Cannot determine UUID attribute');
1669
+            }
1670
+        } else {
1671
+            // The UUID attribute is either known or an override is given.
1672
+            // By calling this method we ensure that $this->connection->$uuidAttr
1673
+            // is definitely set
1674
+            if (!$this->detectUuidAttribute('', true)) {
1675
+                throw new \Exception('Cannot determine UUID attribute');
1676
+            }
1677
+        }
1678
+
1679
+        $uuidAttr = $this->connection->ldapUuidUserAttribute;
1680
+        if ($uuidAttr === 'guid' || $uuidAttr === 'objectguid') {
1681
+            $uuid = $this->formatGuid2ForFilterUser($uuid);
1682
+        }
1683
+
1684
+        $filter = $uuidAttr . '=' . $uuid;
1685
+        $result = $this->searchUsers($filter, ['dn'], 2);
1686
+        if (is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) {
1687
+            // we put the count into account to make sure that this is
1688
+            // really unique
1689
+            return $result[0]['dn'][0];
1690
+        }
1691
+
1692
+        throw new \Exception('Cannot determine UUID attribute');
1693
+    }
1694
+
1695
+    /**
1696
+     * auto-detects the directory's UUID attribute
1697
+     *
1698
+     * @param string $dn a known DN used to check against
1699
+     * @param bool $isUser
1700
+     * @param bool $force the detection should be run, even if it is not set to auto
1701
+     * @param array|null $ldapRecord
1702
+     * @return bool true on success, false otherwise
1703
+     * @throws ServerNotAvailableException
1704
+     */
1705
+    private function detectUuidAttribute($dn, $isUser = true, $force = false, array $ldapRecord = null) {
1706
+        if ($isUser) {
1707
+            $uuidAttr = 'ldapUuidUserAttribute';
1708
+            $uuidOverride = $this->connection->ldapExpertUUIDUserAttr;
1709
+        } else {
1710
+            $uuidAttr = 'ldapUuidGroupAttribute';
1711
+            $uuidOverride = $this->connection->ldapExpertUUIDGroupAttr;
1712
+        }
1713
+
1714
+        if (!$force) {
1715
+            if ($this->connection->$uuidAttr !== 'auto') {
1716
+                return true;
1717
+            } elseif (is_string($uuidOverride) && trim($uuidOverride) !== '') {
1718
+                $this->connection->$uuidAttr = $uuidOverride;
1719
+                return true;
1720
+            }
1721
+
1722
+            $attribute = $this->connection->getFromCache($uuidAttr);
1723
+            if (!$attribute === null) {
1724
+                $this->connection->$uuidAttr = $attribute;
1725
+                return true;
1726
+            }
1727
+        }
1728
+
1729
+        foreach (self::UUID_ATTRIBUTES as $attribute) {
1730
+            if ($ldapRecord !== null) {
1731
+                // we have the info from LDAP already, we don't need to talk to the server again
1732
+                if (isset($ldapRecord[$attribute])) {
1733
+                    $this->connection->$uuidAttr = $attribute;
1734
+                    return true;
1735
+                }
1736
+            }
1737
+
1738
+            $value = $this->readAttribute($dn, $attribute);
1739
+            if (is_array($value) && isset($value[0]) && !empty($value[0])) {
1740
+                \OC::$server->getLogger()->debug(
1741
+                    'Setting {attribute} as {subject}',
1742
+                    [
1743
+                        'app' => 'user_ldap',
1744
+                        'attribute' => $attribute,
1745
+                        'subject' => $uuidAttr
1746
+                    ]
1747
+                );
1748
+                $this->connection->$uuidAttr = $attribute;
1749
+                $this->connection->writeToCache($uuidAttr, $attribute);
1750
+                return true;
1751
+            }
1752
+        }
1753
+        \OC::$server->getLogger()->debug('Could not autodetect the UUID attribute', ['app' => 'user_ldap']);
1754
+
1755
+        return false;
1756
+    }
1757
+
1758
+    /**
1759
+     * @param string $dn
1760
+     * @param bool $isUser
1761
+     * @param null $ldapRecord
1762
+     * @return bool|string
1763
+     * @throws ServerNotAvailableException
1764
+     */
1765
+    public function getUUID($dn, $isUser = true, $ldapRecord = null) {
1766
+        if ($isUser) {
1767
+            $uuidAttr = 'ldapUuidUserAttribute';
1768
+            $uuidOverride = $this->connection->ldapExpertUUIDUserAttr;
1769
+        } else {
1770
+            $uuidAttr = 'ldapUuidGroupAttribute';
1771
+            $uuidOverride = $this->connection->ldapExpertUUIDGroupAttr;
1772
+        }
1773
+
1774
+        $uuid = false;
1775
+        if ($this->detectUuidAttribute($dn, $isUser, false, $ldapRecord)) {
1776
+            $attr = $this->connection->$uuidAttr;
1777
+            $uuid = isset($ldapRecord[$attr]) ? $ldapRecord[$attr] : $this->readAttribute($dn, $attr);
1778
+            if (!is_array($uuid)
1779
+                && $uuidOverride !== ''
1780
+                && $this->detectUuidAttribute($dn, $isUser, true, $ldapRecord)) {
1781
+                $uuid = isset($ldapRecord[$this->connection->$uuidAttr])
1782
+                    ? $ldapRecord[$this->connection->$uuidAttr]
1783
+                    : $this->readAttribute($dn, $this->connection->$uuidAttr);
1784
+            }
1785
+            if (is_array($uuid) && isset($uuid[0]) && !empty($uuid[0])) {
1786
+                $uuid = $uuid[0];
1787
+            }
1788
+        }
1789
+
1790
+        return $uuid;
1791
+    }
1792
+
1793
+    /**
1794
+     * converts a binary ObjectGUID into a string representation
1795
+     *
1796
+     * @param string $oguid the ObjectGUID in it's binary form as retrieved from AD
1797
+     * @return string
1798
+     * @link https://www.php.net/manual/en/function.ldap-get-values-len.php#73198
1799
+     */
1800
+    private function convertObjectGUID2Str($oguid) {
1801
+        $hex_guid = bin2hex($oguid);
1802
+        $hex_guid_to_guid_str = '';
1803
+        for ($k = 1; $k <= 4; ++$k) {
1804
+            $hex_guid_to_guid_str .= substr($hex_guid, 8 - 2 * $k, 2);
1805
+        }
1806
+        $hex_guid_to_guid_str .= '-';
1807
+        for ($k = 1; $k <= 2; ++$k) {
1808
+            $hex_guid_to_guid_str .= substr($hex_guid, 12 - 2 * $k, 2);
1809
+        }
1810
+        $hex_guid_to_guid_str .= '-';
1811
+        for ($k = 1; $k <= 2; ++$k) {
1812
+            $hex_guid_to_guid_str .= substr($hex_guid, 16 - 2 * $k, 2);
1813
+        }
1814
+        $hex_guid_to_guid_str .= '-' . substr($hex_guid, 16, 4);
1815
+        $hex_guid_to_guid_str .= '-' . substr($hex_guid, 20);
1816
+
1817
+        return strtoupper($hex_guid_to_guid_str);
1818
+    }
1819
+
1820
+    /**
1821
+     * the first three blocks of the string-converted GUID happen to be in
1822
+     * reverse order. In order to use it in a filter, this needs to be
1823
+     * corrected. Furthermore the dashes need to be replaced and \\ preprended
1824
+     * to every two hax figures.
1825
+     *
1826
+     * If an invalid string is passed, it will be returned without change.
1827
+     *
1828
+     * @param string $guid
1829
+     * @return string
1830
+     */
1831
+    public function formatGuid2ForFilterUser($guid) {
1832
+        if (!is_string($guid)) {
1833
+            throw new \InvalidArgumentException('String expected');
1834
+        }
1835
+        $blocks = explode('-', $guid);
1836
+        if (count($blocks) !== 5) {
1837
+            /*
1838 1838
 			 * Why not throw an Exception instead? This method is a utility
1839 1839
 			 * called only when trying to figure out whether a "missing" known
1840 1840
 			 * LDAP user was or was not renamed on the LDAP server. And this
@@ -1845,247 +1845,247 @@  discard block
 block discarded – undo
1845 1845
 			 * an exception here would kill the experience for a valid, acting
1846 1846
 			 * user. Instead we write a log message.
1847 1847
 			 */
1848
-			\OC::$server->getLogger()->info(
1849
-				'Passed string does not resemble a valid GUID. Known UUID ' .
1850
-				'({uuid}) probably does not match UUID configuration.',
1851
-				['app' => 'user_ldap', 'uuid' => $guid]
1852
-			);
1853
-			return $guid;
1854
-		}
1855
-		for ($i = 0; $i < 3; $i++) {
1856
-			$pairs = str_split($blocks[$i], 2);
1857
-			$pairs = array_reverse($pairs);
1858
-			$blocks[$i] = implode('', $pairs);
1859
-		}
1860
-		for ($i = 0; $i < 5; $i++) {
1861
-			$pairs = str_split($blocks[$i], 2);
1862
-			$blocks[$i] = '\\' . implode('\\', $pairs);
1863
-		}
1864
-		return implode('', $blocks);
1865
-	}
1866
-
1867
-	/**
1868
-	 * gets a SID of the domain of the given dn
1869
-	 *
1870
-	 * @param string $dn
1871
-	 * @return string|bool
1872
-	 * @throws ServerNotAvailableException
1873
-	 */
1874
-	public function getSID($dn) {
1875
-		$domainDN = $this->getDomainDNFromDN($dn);
1876
-		$cacheKey = 'getSID-' . $domainDN;
1877
-		$sid = $this->connection->getFromCache($cacheKey);
1878
-		if (!is_null($sid)) {
1879
-			return $sid;
1880
-		}
1881
-
1882
-		$objectSid = $this->readAttribute($domainDN, 'objectsid');
1883
-		if (!is_array($objectSid) || empty($objectSid)) {
1884
-			$this->connection->writeToCache($cacheKey, false);
1885
-			return false;
1886
-		}
1887
-		$domainObjectSid = $this->convertSID2Str($objectSid[0]);
1888
-		$this->connection->writeToCache($cacheKey, $domainObjectSid);
1889
-
1890
-		return $domainObjectSid;
1891
-	}
1892
-
1893
-	/**
1894
-	 * converts a binary SID into a string representation
1895
-	 *
1896
-	 * @param string $sid
1897
-	 * @return string
1898
-	 */
1899
-	public function convertSID2Str($sid) {
1900
-		// The format of a SID binary string is as follows:
1901
-		// 1 byte for the revision level
1902
-		// 1 byte for the number n of variable sub-ids
1903
-		// 6 bytes for identifier authority value
1904
-		// n*4 bytes for n sub-ids
1905
-		//
1906
-		// Example: 010400000000000515000000a681e50e4d6c6c2bca32055f
1907
-		//  Legend: RRNNAAAAAAAAAAAA11111111222222223333333344444444
1908
-		$revision = ord($sid[0]);
1909
-		$numberSubID = ord($sid[1]);
1910
-
1911
-		$subIdStart = 8; // 1 + 1 + 6
1912
-		$subIdLength = 4;
1913
-		if (strlen($sid) !== $subIdStart + $subIdLength * $numberSubID) {
1914
-			// Incorrect number of bytes present.
1915
-			return '';
1916
-		}
1917
-
1918
-		// 6 bytes = 48 bits can be represented using floats without loss of
1919
-		// precision (see https://gist.github.com/bantu/886ac680b0aef5812f71)
1920
-		$iav = number_format(hexdec(bin2hex(substr($sid, 2, 6))), 0, '', '');
1921
-
1922
-		$subIDs = [];
1923
-		for ($i = 0; $i < $numberSubID; $i++) {
1924
-			$subID = unpack('V', substr($sid, $subIdStart + $subIdLength * $i, $subIdLength));
1925
-			$subIDs[] = sprintf('%u', $subID[1]);
1926
-		}
1927
-
1928
-		// Result for example above: S-1-5-21-249921958-728525901-1594176202
1929
-		return sprintf('S-%d-%s-%s', $revision, $iav, implode('-', $subIDs));
1930
-	}
1931
-
1932
-	/**
1933
-	 * checks if the given DN is part of the given base DN(s)
1934
-	 *
1935
-	 * @param string $dn the DN
1936
-	 * @param string[] $bases array containing the allowed base DN or DNs
1937
-	 * @return bool
1938
-	 */
1939
-	public function isDNPartOfBase($dn, $bases) {
1940
-		$belongsToBase = false;
1941
-		$bases = $this->helper->sanitizeDN($bases);
1942
-
1943
-		foreach ($bases as $base) {
1944
-			$belongsToBase = true;
1945
-			if (mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8') - mb_strlen($base, 'UTF-8'))) {
1946
-				$belongsToBase = false;
1947
-			}
1948
-			if ($belongsToBase) {
1949
-				break;
1950
-			}
1951
-		}
1952
-		return $belongsToBase;
1953
-	}
1954
-
1955
-	/**
1956
-	 * resets a running Paged Search operation
1957
-	 *
1958
-	 * @throws ServerNotAvailableException
1959
-	 */
1960
-	private function abandonPagedSearch() {
1961
-		if ($this->lastCookie === '') {
1962
-			return;
1963
-		}
1964
-		$cr = $this->connection->getConnectionResource();
1965
-		$this->invokeLDAPMethod('controlPagedResult', $cr, 0, false);
1966
-		$this->getPagedSearchResultState();
1967
-		$this->lastCookie = '';
1968
-	}
1969
-
1970
-	/**
1971
-	 * checks whether an LDAP paged search operation has more pages that can be
1972
-	 * retrieved, typically when offset and limit are provided.
1973
-	 *
1974
-	 * Be very careful to use it: the last cookie value, which is inspected, can
1975
-	 * be reset by other operations. Best, call it immediately after a search(),
1976
-	 * searchUsers() or searchGroups() call. count-methods are probably safe as
1977
-	 * well. Don't rely on it with any fetchList-method.
1978
-	 *
1979
-	 * @return bool
1980
-	 */
1981
-	public function hasMoreResults() {
1982
-		if (empty($this->lastCookie) && $this->lastCookie !== '0') {
1983
-			// as in RFC 2696, when all results are returned, the cookie will
1984
-			// be empty.
1985
-			return false;
1986
-		}
1987
-
1988
-		return true;
1989
-	}
1990
-
1991
-	/**
1992
-	 * Check whether the most recent paged search was successful. It flushed the state var. Use it always after a possible paged search.
1993
-	 *
1994
-	 * @return boolean|null true on success, null or false otherwise
1995
-	 */
1996
-	public function getPagedSearchResultState() {
1997
-		$result = $this->pagedSearchedSuccessful;
1998
-		$this->pagedSearchedSuccessful = null;
1999
-		return $result;
2000
-	}
2001
-
2002
-	/**
2003
-	 * Prepares a paged search, if possible
2004
-	 *
2005
-	 * @param string $filter the LDAP filter for the search
2006
-	 * @param string[] $bases an array containing the LDAP subtree(s) that shall be searched
2007
-	 * @param string[] $attr optional, when a certain attribute shall be filtered outside
2008
-	 * @param int $limit
2009
-	 * @param int $offset
2010
-	 * @return bool|true
2011
-	 * @throws ServerNotAvailableException
2012
-	 * @throws NoMoreResults
2013
-	 */
2014
-	private function initPagedSearch(
2015
-		string $filter,
2016
-		string $base,
2017
-		?array $attr,
2018
-		int $limit,
2019
-		int $offset
2020
-	): bool {
2021
-		$pagedSearchOK = false;
2022
-		if ($limit !== 0) {
2023
-			\OC::$server->getLogger()->debug(
2024
-				'initializing paged search for filter {filter}, base {base}, attr {attr}, limit {limit}, offset {offset}',
2025
-				[
2026
-					'app' => 'user_ldap',
2027
-					'filter' => $filter,
2028
-					'base' => $base,
2029
-					'attr' => $attr,
2030
-					'limit' => $limit,
2031
-					'offset' => $offset
2032
-				]
2033
-			);
2034
-			//get the cookie from the search for the previous search, required by LDAP
2035
-			if (empty($this->lastCookie) && $this->lastCookie !== "0" && ($offset > 0)) {
2036
-				// no cookie known from a potential previous search. We need
2037
-				// to start from 0 to come to the desired page. cookie value
2038
-				// of '0' is valid, because 389ds
2039
-				$reOffset = ($offset - $limit) < 0 ? 0 : $offset - $limit;
2040
-				$this->search($filter, $base, $attr, $limit, $reOffset, true);
2041
-				if (!$this->hasMoreResults()) {
2042
-					// when the cookie is reset with != 0 offset, there are no further
2043
-					// results, so stop.
2044
-					throw new NoMoreResults();
2045
-				}
2046
-			}
2047
-			if ($this->lastCookie !== '' && $offset === 0) {
2048
-				//since offset = 0, this is a new search. We abandon other searches that might be ongoing.
2049
-				$this->abandonPagedSearch();
2050
-			}
2051
-			$pagedSearchOK = true === $this->invokeLDAPMethod(
2052
-					'controlPagedResult', $this->connection->getConnectionResource(), $limit, false
2053
-				);
2054
-			if ($pagedSearchOK) {
2055
-				\OC::$server->getLogger()->debug('Ready for a paged search', ['app' => 'user_ldap']);
2056
-			}
2057
-			/* ++ Fixing RHDS searches with pages with zero results ++
1848
+            \OC::$server->getLogger()->info(
1849
+                'Passed string does not resemble a valid GUID. Known UUID ' .
1850
+                '({uuid}) probably does not match UUID configuration.',
1851
+                ['app' => 'user_ldap', 'uuid' => $guid]
1852
+            );
1853
+            return $guid;
1854
+        }
1855
+        for ($i = 0; $i < 3; $i++) {
1856
+            $pairs = str_split($blocks[$i], 2);
1857
+            $pairs = array_reverse($pairs);
1858
+            $blocks[$i] = implode('', $pairs);
1859
+        }
1860
+        for ($i = 0; $i < 5; $i++) {
1861
+            $pairs = str_split($blocks[$i], 2);
1862
+            $blocks[$i] = '\\' . implode('\\', $pairs);
1863
+        }
1864
+        return implode('', $blocks);
1865
+    }
1866
+
1867
+    /**
1868
+     * gets a SID of the domain of the given dn
1869
+     *
1870
+     * @param string $dn
1871
+     * @return string|bool
1872
+     * @throws ServerNotAvailableException
1873
+     */
1874
+    public function getSID($dn) {
1875
+        $domainDN = $this->getDomainDNFromDN($dn);
1876
+        $cacheKey = 'getSID-' . $domainDN;
1877
+        $sid = $this->connection->getFromCache($cacheKey);
1878
+        if (!is_null($sid)) {
1879
+            return $sid;
1880
+        }
1881
+
1882
+        $objectSid = $this->readAttribute($domainDN, 'objectsid');
1883
+        if (!is_array($objectSid) || empty($objectSid)) {
1884
+            $this->connection->writeToCache($cacheKey, false);
1885
+            return false;
1886
+        }
1887
+        $domainObjectSid = $this->convertSID2Str($objectSid[0]);
1888
+        $this->connection->writeToCache($cacheKey, $domainObjectSid);
1889
+
1890
+        return $domainObjectSid;
1891
+    }
1892
+
1893
+    /**
1894
+     * converts a binary SID into a string representation
1895
+     *
1896
+     * @param string $sid
1897
+     * @return string
1898
+     */
1899
+    public function convertSID2Str($sid) {
1900
+        // The format of a SID binary string is as follows:
1901
+        // 1 byte for the revision level
1902
+        // 1 byte for the number n of variable sub-ids
1903
+        // 6 bytes for identifier authority value
1904
+        // n*4 bytes for n sub-ids
1905
+        //
1906
+        // Example: 010400000000000515000000a681e50e4d6c6c2bca32055f
1907
+        //  Legend: RRNNAAAAAAAAAAAA11111111222222223333333344444444
1908
+        $revision = ord($sid[0]);
1909
+        $numberSubID = ord($sid[1]);
1910
+
1911
+        $subIdStart = 8; // 1 + 1 + 6
1912
+        $subIdLength = 4;
1913
+        if (strlen($sid) !== $subIdStart + $subIdLength * $numberSubID) {
1914
+            // Incorrect number of bytes present.
1915
+            return '';
1916
+        }
1917
+
1918
+        // 6 bytes = 48 bits can be represented using floats without loss of
1919
+        // precision (see https://gist.github.com/bantu/886ac680b0aef5812f71)
1920
+        $iav = number_format(hexdec(bin2hex(substr($sid, 2, 6))), 0, '', '');
1921
+
1922
+        $subIDs = [];
1923
+        for ($i = 0; $i < $numberSubID; $i++) {
1924
+            $subID = unpack('V', substr($sid, $subIdStart + $subIdLength * $i, $subIdLength));
1925
+            $subIDs[] = sprintf('%u', $subID[1]);
1926
+        }
1927
+
1928
+        // Result for example above: S-1-5-21-249921958-728525901-1594176202
1929
+        return sprintf('S-%d-%s-%s', $revision, $iav, implode('-', $subIDs));
1930
+    }
1931
+
1932
+    /**
1933
+     * checks if the given DN is part of the given base DN(s)
1934
+     *
1935
+     * @param string $dn the DN
1936
+     * @param string[] $bases array containing the allowed base DN or DNs
1937
+     * @return bool
1938
+     */
1939
+    public function isDNPartOfBase($dn, $bases) {
1940
+        $belongsToBase = false;
1941
+        $bases = $this->helper->sanitizeDN($bases);
1942
+
1943
+        foreach ($bases as $base) {
1944
+            $belongsToBase = true;
1945
+            if (mb_strripos($dn, $base, 0, 'UTF-8') !== (mb_strlen($dn, 'UTF-8') - mb_strlen($base, 'UTF-8'))) {
1946
+                $belongsToBase = false;
1947
+            }
1948
+            if ($belongsToBase) {
1949
+                break;
1950
+            }
1951
+        }
1952
+        return $belongsToBase;
1953
+    }
1954
+
1955
+    /**
1956
+     * resets a running Paged Search operation
1957
+     *
1958
+     * @throws ServerNotAvailableException
1959
+     */
1960
+    private function abandonPagedSearch() {
1961
+        if ($this->lastCookie === '') {
1962
+            return;
1963
+        }
1964
+        $cr = $this->connection->getConnectionResource();
1965
+        $this->invokeLDAPMethod('controlPagedResult', $cr, 0, false);
1966
+        $this->getPagedSearchResultState();
1967
+        $this->lastCookie = '';
1968
+    }
1969
+
1970
+    /**
1971
+     * checks whether an LDAP paged search operation has more pages that can be
1972
+     * retrieved, typically when offset and limit are provided.
1973
+     *
1974
+     * Be very careful to use it: the last cookie value, which is inspected, can
1975
+     * be reset by other operations. Best, call it immediately after a search(),
1976
+     * searchUsers() or searchGroups() call. count-methods are probably safe as
1977
+     * well. Don't rely on it with any fetchList-method.
1978
+     *
1979
+     * @return bool
1980
+     */
1981
+    public function hasMoreResults() {
1982
+        if (empty($this->lastCookie) && $this->lastCookie !== '0') {
1983
+            // as in RFC 2696, when all results are returned, the cookie will
1984
+            // be empty.
1985
+            return false;
1986
+        }
1987
+
1988
+        return true;
1989
+    }
1990
+
1991
+    /**
1992
+     * Check whether the most recent paged search was successful. It flushed the state var. Use it always after a possible paged search.
1993
+     *
1994
+     * @return boolean|null true on success, null or false otherwise
1995
+     */
1996
+    public function getPagedSearchResultState() {
1997
+        $result = $this->pagedSearchedSuccessful;
1998
+        $this->pagedSearchedSuccessful = null;
1999
+        return $result;
2000
+    }
2001
+
2002
+    /**
2003
+     * Prepares a paged search, if possible
2004
+     *
2005
+     * @param string $filter the LDAP filter for the search
2006
+     * @param string[] $bases an array containing the LDAP subtree(s) that shall be searched
2007
+     * @param string[] $attr optional, when a certain attribute shall be filtered outside
2008
+     * @param int $limit
2009
+     * @param int $offset
2010
+     * @return bool|true
2011
+     * @throws ServerNotAvailableException
2012
+     * @throws NoMoreResults
2013
+     */
2014
+    private function initPagedSearch(
2015
+        string $filter,
2016
+        string $base,
2017
+        ?array $attr,
2018
+        int $limit,
2019
+        int $offset
2020
+    ): bool {
2021
+        $pagedSearchOK = false;
2022
+        if ($limit !== 0) {
2023
+            \OC::$server->getLogger()->debug(
2024
+                'initializing paged search for filter {filter}, base {base}, attr {attr}, limit {limit}, offset {offset}',
2025
+                [
2026
+                    'app' => 'user_ldap',
2027
+                    'filter' => $filter,
2028
+                    'base' => $base,
2029
+                    'attr' => $attr,
2030
+                    'limit' => $limit,
2031
+                    'offset' => $offset
2032
+                ]
2033
+            );
2034
+            //get the cookie from the search for the previous search, required by LDAP
2035
+            if (empty($this->lastCookie) && $this->lastCookie !== "0" && ($offset > 0)) {
2036
+                // no cookie known from a potential previous search. We need
2037
+                // to start from 0 to come to the desired page. cookie value
2038
+                // of '0' is valid, because 389ds
2039
+                $reOffset = ($offset - $limit) < 0 ? 0 : $offset - $limit;
2040
+                $this->search($filter, $base, $attr, $limit, $reOffset, true);
2041
+                if (!$this->hasMoreResults()) {
2042
+                    // when the cookie is reset with != 0 offset, there are no further
2043
+                    // results, so stop.
2044
+                    throw new NoMoreResults();
2045
+                }
2046
+            }
2047
+            if ($this->lastCookie !== '' && $offset === 0) {
2048
+                //since offset = 0, this is a new search. We abandon other searches that might be ongoing.
2049
+                $this->abandonPagedSearch();
2050
+            }
2051
+            $pagedSearchOK = true === $this->invokeLDAPMethod(
2052
+                    'controlPagedResult', $this->connection->getConnectionResource(), $limit, false
2053
+                );
2054
+            if ($pagedSearchOK) {
2055
+                \OC::$server->getLogger()->debug('Ready for a paged search', ['app' => 'user_ldap']);
2056
+            }
2057
+            /* ++ Fixing RHDS searches with pages with zero results ++
2058 2058
 			 * We coudn't get paged searches working with our RHDS for login ($limit = 0),
2059 2059
 			 * due to pages with zero results.
2060 2060
 			 * So we added "&& !empty($this->lastCookie)" to this test to ignore pagination
2061 2061
 			 * if we don't have a previous paged search.
2062 2062
 			 */
2063
-		} elseif ($limit === 0 && !empty($this->lastCookie)) {
2064
-			// a search without limit was requested. However, if we do use
2065
-			// Paged Search once, we always must do it. This requires us to
2066
-			// initialize it with the configured page size.
2067
-			$this->abandonPagedSearch();
2068
-			// in case someone set it to 0 … use 500, otherwise no results will
2069
-			// be returned.
2070
-			$pageSize = (int)$this->connection->ldapPagingSize > 0 ? (int)$this->connection->ldapPagingSize : 500;
2071
-			$pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult',
2072
-				$this->connection->getConnectionResource(),
2073
-				$pageSize, false);
2074
-		}
2075
-
2076
-		return $pagedSearchOK;
2077
-	}
2078
-
2079
-	/**
2080
-	 * Is more than one $attr used for search?
2081
-	 *
2082
-	 * @param string|string[]|null $attr
2083
-	 * @return bool
2084
-	 */
2085
-	private function manyAttributes($attr): bool {
2086
-		if (\is_array($attr)) {
2087
-			return \count($attr) > 1;
2088
-		}
2089
-		return false;
2090
-	}
2063
+        } elseif ($limit === 0 && !empty($this->lastCookie)) {
2064
+            // a search without limit was requested. However, if we do use
2065
+            // Paged Search once, we always must do it. This requires us to
2066
+            // initialize it with the configured page size.
2067
+            $this->abandonPagedSearch();
2068
+            // in case someone set it to 0 … use 500, otherwise no results will
2069
+            // be returned.
2070
+            $pageSize = (int)$this->connection->ldapPagingSize > 0 ? (int)$this->connection->ldapPagingSize : 500;
2071
+            $pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult',
2072
+                $this->connection->getConnectionResource(),
2073
+                $pageSize, false);
2074
+        }
2075
+
2076
+        return $pagedSearchOK;
2077
+    }
2078
+
2079
+    /**
2080
+     * Is more than one $attr used for search?
2081
+     *
2082
+     * @param string|string[]|null $attr
2083
+     * @return bool
2084
+     */
2085
+    private function manyAttributes($attr): bool {
2086
+        if (\is_array($attr)) {
2087
+            return \count($attr) > 1;
2088
+        }
2089
+        return false;
2090
+    }
2091 2091
 }
Please login to merge, or discard this patch.
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 		$this->abandonPagedSearch();
201 201
 		// openLDAP requires that we init a new Paged Search. Not needed by AD,
202 202
 		// but does not hurt either.
203
-		$pagingSize = (int)$this->connection->ldapPagingSize;
203
+		$pagingSize = (int) $this->connection->ldapPagingSize;
204 204
 		// 0 won't result in replies, small numbers may leave out groups
205 205
 		// (cf. #12306), 500 is default for paging and should work everywhere.
206 206
 		$maxResults = $pagingSize > 20 ? $pagingSize : 500;
@@ -241,13 +241,13 @@  discard block
 block discarded – undo
241 241
 					return $values;
242 242
 				} else {
243 243
 					$low = $result['rangeHigh'] + 1;
244
-					$attrToRead = $result['attributeName'] . ';range=' . $low . '-*';
244
+					$attrToRead = $result['attributeName'].';range='.$low.'-*';
245 245
 					$isRangeRequest = true;
246 246
 				}
247 247
 			}
248 248
 		} while ($isRangeRequest);
249 249
 
250
-		\OCP\Util::writeLog('user_ldap', 'Requested attribute ' . $attr . ' not found for ' . $dn, ILogger::DEBUG);
250
+		\OCP\Util::writeLog('user_ldap', 'Requested attribute '.$attr.' not found for '.$dn, ILogger::DEBUG);
251 251
 		return false;
252 252
 	}
253 253
 
@@ -278,13 +278,13 @@  discard block
 block discarded – undo
278 278
 		if (!$this->ldap->isResource($rr)) {
279 279
 			if ($attribute !== '') {
280 280
 				//do not throw this message on userExists check, irritates
281
-				\OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN ' . $dn, ILogger::DEBUG);
281
+				\OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN '.$dn, ILogger::DEBUG);
282 282
 			}
283 283
 			//in case an error occurs , e.g. object does not exist
284 284
 			return false;
285 285
 		}
286 286
 		if ($attribute === '' && ($filter === 'objectclass=*' || $this->invokeLDAPMethod('countEntries', $cr, $rr) === 1)) {
287
-			\OCP\Util::writeLog('user_ldap', 'readAttribute: ' . $dn . ' found', ILogger::DEBUG);
287
+			\OCP\Util::writeLog('user_ldap', 'readAttribute: '.$dn.' found', ILogger::DEBUG);
288 288
 			return true;
289 289
 		}
290 290
 		$er = $this->invokeLDAPMethod('firstEntry', $cr, $rr);
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
 	 * @throws \Exception
365 365
 	 */
366 366
 	public function setPassword($userDN, $password) {
367
-		if ((int)$this->connection->turnOnPasswordChange !== 1) {
367
+		if ((int) $this->connection->turnOnPasswordChange !== 1) {
368 368
 			throw new \Exception('LDAP password changes are disabled.');
369 369
 		}
370 370
 		$cr = $this->connection->getConnectionResource();
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
 			return @$this->invokeLDAPMethod('exopPasswd', $cr, $userDN, '', $password) ||
379 379
 				@$this->invokeLDAPMethod('modReplace', $cr, $userDN, $password);
380 380
 		} catch (ConstraintViolationException $e) {
381
-			throw new HintException('Password change rejected.', \OC::$server->getL10N('user_ldap')->t('Password change rejected. Hint: ') . $e->getMessage(), $e->getCode());
381
+			throw new HintException('Password change rejected.', \OC::$server->getL10N('user_ldap')->t('Password change rejected. Hint: ').$e->getMessage(), $e->getCode());
382 382
 		}
383 383
 	}
384 384
 
@@ -544,21 +544,21 @@  discard block
 block discarded – undo
544 544
 			}
545 545
 		} else {
546 546
 			//If the UUID can't be detected something is foul.
547
-			\OCP\Util::writeLog('user_ldap', 'Cannot determine UUID for ' . $fdn . '. Skipping.', ILogger::INFO);
547
+			\OCP\Util::writeLog('user_ldap', 'Cannot determine UUID for '.$fdn.'. Skipping.', ILogger::INFO);
548 548
 			return false;
549 549
 		}
550 550
 
551 551
 		if (is_null($ldapName)) {
552 552
 			$ldapName = $this->readAttribute($fdn, $nameAttribute, $filter);
553 553
 			if (!isset($ldapName[0]) && empty($ldapName[0])) {
554
-				\OCP\Util::writeLog('user_ldap', 'No or empty name for ' . $fdn . ' with filter ' . $filter . '.', ILogger::DEBUG);
554
+				\OCP\Util::writeLog('user_ldap', 'No or empty name for '.$fdn.' with filter '.$filter.'.', ILogger::DEBUG);
555 555
 				return false;
556 556
 			}
557 557
 			$ldapName = $ldapName[0];
558 558
 		}
559 559
 
560 560
 		if ($isUser) {
561
-			$usernameAttribute = (string)$this->connection->ldapExpertUsernameAttr;
561
+			$usernameAttribute = (string) $this->connection->ldapExpertUsernameAttr;
562 562
 			if ($usernameAttribute !== '') {
563 563
 				$username = $this->readAttribute($fdn, $usernameAttribute);
564 564
 				$username = $username[0];
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
 		}
611 611
 
612 612
 		//if everything else did not help..
613
-		\OCP\Util::writeLog('user_ldap', 'Could not create unique name for ' . $fdn . '.', ILogger::INFO);
613
+		\OCP\Util::writeLog('user_ldap', 'Could not create unique name for '.$fdn.'.', ILogger::INFO);
614 614
 		return false;
615 615
 	}
616 616
 
@@ -725,7 +725,7 @@  discard block
 block discarded – undo
725 725
 	 * @param string|false $home the home directory path
726 726
 	 */
727 727
 	public function cacheUserHome($ocName, $home) {
728
-		$cacheKey = 'getHome' . $ocName;
728
+		$cacheKey = 'getHome'.$ocName;
729 729
 		$this->connection->writeToCache($cacheKey, $home);
730 730
 	}
731 731
 
@@ -735,14 +735,14 @@  discard block
 block discarded – undo
735 735
 	 * @param string $ocName the internal Nextcloud username
736 736
 	 */
737 737
 	public function cacheUserExists($ocName) {
738
-		$this->connection->writeToCache('userExists' . $ocName, true);
738
+		$this->connection->writeToCache('userExists'.$ocName, true);
739 739
 	}
740 740
 
741 741
 	/**
742 742
 	 * caches a group as existing
743 743
 	 */
744 744
 	public function cacheGroupExists(string $gid): void {
745
-		$this->connection->writeToCache('groupExists' . $gid, true);
745
+		$this->connection->writeToCache('groupExists'.$gid, true);
746 746
 	}
747 747
 
748 748
 	/**
@@ -760,11 +760,11 @@  discard block
 block discarded – undo
760 760
 		}
761 761
 		$displayName = $user->composeAndStoreDisplayName($displayName, $displayName2);
762 762
 		$cacheKeyTrunk = 'getDisplayName';
763
-		$this->connection->writeToCache($cacheKeyTrunk . $ocName, $displayName);
763
+		$this->connection->writeToCache($cacheKeyTrunk.$ocName, $displayName);
764 764
 	}
765 765
 
766 766
 	public function cacheGroupDisplayName(string $ncName, string $displayName): void {
767
-		$cacheKey = 'group_getDisplayName' . $ncName;
767
+		$cacheKey = 'group_getDisplayName'.$ncName;
768 768
 		$this->connection->writeToCache($cacheKey, $displayName);
769 769
 	}
770 770
 
@@ -782,7 +782,7 @@  discard block
 block discarded – undo
782 782
 		//while loop is just a precaution. If a name is not generated within
783 783
 		//20 attempts, something else is very wrong. Avoids infinite loop.
784 784
 		while ($attempts < 20) {
785
-			$altName = $name . '_' . rand(1000, 9999);
785
+			$altName = $name.'_'.rand(1000, 9999);
786 786
 			if (!$this->ncUserManager->userExists($altName)) {
787 787
 				return $altName;
788 788
 			}
@@ -811,9 +811,9 @@  discard block
 block discarded – undo
811 811
 		} else {
812 812
 			natsort($usedNames);
813 813
 			$lastName = array_pop($usedNames);
814
-			$lastNo = (int)substr($lastName, strrpos($lastName, '_') + 1);
814
+			$lastNo = (int) substr($lastName, strrpos($lastName, '_') + 1);
815 815
 		}
816
-		$altName = $name . '_' . (string)($lastNo + 1);
816
+		$altName = $name.'_'.(string) ($lastNo + 1);
817 817
 		unset($usedNames);
818 818
 
819 819
 		$attempts = 1;
@@ -824,7 +824,7 @@  discard block
 block discarded – undo
824 824
 			if (!\OC::$server->getGroupManager()->groupExists($altName)) {
825 825
 				return $altName;
826 826
 			}
827
-			$altName = $name . '_' . ($lastNo + $attempts);
827
+			$altName = $name.'_'.($lastNo + $attempts);
828 828
 			$attempts++;
829 829
 		}
830 830
 		return false;
@@ -882,12 +882,12 @@  discard block
 block discarded – undo
882 882
 		if (!$forceApplyAttributes) {
883 883
 			$isBackgroundJobModeAjax = $this->config
884 884
 					->getAppValue('core', 'backgroundjobs_mode', 'ajax') === 'ajax';
885
-			$listOfDNs = array_reduce($ldapRecords, function ($listOfDNs, $entry) {
885
+			$listOfDNs = array_reduce($ldapRecords, function($listOfDNs, $entry) {
886 886
 				$listOfDNs[] = $entry['dn'][0];
887 887
 				return $listOfDNs;
888 888
 			}, []);
889 889
 			$idsByDn = $this->userMapper->getListOfIdsByDn($listOfDNs);
890
-			$recordsToUpdate = array_filter($ldapRecords, function ($record) use ($isBackgroundJobModeAjax, $idsByDn) {
890
+			$recordsToUpdate = array_filter($ldapRecords, function($record) use ($isBackgroundJobModeAjax, $idsByDn) {
891 891
 				$newlyMapped = false;
892 892
 				$uid = $idsByDn[$record['dn'][0]] ?? null;
893 893
 				if ($uid === null) {
@@ -945,13 +945,13 @@  discard block
 block discarded – undo
945 945
 	public function fetchListOfGroups($filter, $attr, $limit = null, $offset = null) {
946 946
 		$groupRecords = $this->searchGroups($filter, $attr, $limit, $offset);
947 947
 
948
-		$listOfDNs = array_reduce($groupRecords, function ($listOfDNs, $entry) {
948
+		$listOfDNs = array_reduce($groupRecords, function($listOfDNs, $entry) {
949 949
 			$listOfDNs[] = $entry['dn'][0];
950 950
 			return $listOfDNs;
951 951
 		}, []);
952 952
 		$idsByDn = $this->groupMapper->getListOfIdsByDn($listOfDNs);
953 953
 
954
-		array_walk($groupRecords, function ($record) use ($idsByDn) {
954
+		array_walk($groupRecords, function($record) use ($idsByDn) {
955 955
 			$newlyMapped = false;
956 956
 			$gid = $idsByDn[$record['dn'][0]] ?? null;
957 957
 			if ($gid === null) {
@@ -974,7 +974,7 @@  discard block
 block discarded – undo
974 974
 			if ($manyAttributes) {
975 975
 				return $list;
976 976
 			} else {
977
-				$list = array_reduce($list, function ($carry, $item) {
977
+				$list = array_reduce($list, function($carry, $item) {
978 978
 					$attribute = array_keys($item)[0];
979 979
 					$carry[] = $item[$attribute][0];
980 980
 					return $carry;
@@ -1010,7 +1010,7 @@  discard block
 block discarded – undo
1010 1010
 		$result = false;
1011 1011
 		foreach ($this->connection->ldapBaseUsers as $base) {
1012 1012
 			$count = $this->count($filter, [$base], $attr, $limit, $offset);
1013
-			$result = is_int($count) ? (int)$result + $count : $result;
1013
+			$result = is_int($count) ? (int) $result + $count : $result;
1014 1014
 		}
1015 1015
 		return $result;
1016 1016
 	}
@@ -1049,7 +1049,7 @@  discard block
 block discarded – undo
1049 1049
 		$result = false;
1050 1050
 		foreach ($this->connection->ldapBaseGroups as $base) {
1051 1051
 			$count = $this->count($filter, [$base], $attr, $limit, $offset);
1052
-			$result = is_int($count) ? (int)$result + $count : $result;
1052
+			$result = is_int($count) ? (int) $result + $count : $result;
1053 1053
 		}
1054 1054
 		return $result;
1055 1055
 	}
@@ -1066,7 +1066,7 @@  discard block
 block discarded – undo
1066 1066
 		$result = false;
1067 1067
 		foreach ($this->connection->ldapBase as $base) {
1068 1068
 			$count = $this->count('objectclass=*', [$base], ['dn'], $limit, $offset);
1069
-			$result = is_int($count) ? (int)$result + $count : $result;
1069
+			$result = is_int($count) ? (int) $result + $count : $result;
1070 1070
 		}
1071 1071
 		return $result;
1072 1072
 	}
@@ -1092,7 +1092,7 @@  discard block
 block discarded – undo
1092 1092
 		// php no longer supports call-time pass-by-reference
1093 1093
 		// thus cannot support controlPagedResultResponse as the third argument
1094 1094
 		// is a reference
1095
-		$doMethod = function () use ($command, &$arguments) {
1095
+		$doMethod = function() use ($command, &$arguments) {
1096 1096
 			if ($command == 'controlPagedResultResponse') {
1097 1097
 				throw new \InvalidArgumentException('Invoker does not support controlPagedResultResponse, call LDAP Wrapper directly instead.');
1098 1098
 			} else {
@@ -1152,7 +1152,7 @@  discard block
 block discarded – undo
1152 1152
 
1153 1153
 		//check whether paged search should be attempted
1154 1154
 		try {
1155
-			$pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, (int)$limit, (int)$offset);
1155
+			$pagedSearchOK = $this->initPagedSearch($filter, $base, $attr, (int) $limit, (int) $offset);
1156 1156
 		} catch (NoMoreResults $e) {
1157 1157
 			// beyond last results page
1158 1158
 			return false;
@@ -1162,7 +1162,7 @@  discard block
 block discarded – undo
1162 1162
 		// cannot use $cr anymore, might have changed in the previous call!
1163 1163
 		$error = $this->ldap->errno($this->connection->getConnectionResource());
1164 1164
 		if (!$this->ldap->isResource($sr) || $error !== 0) {
1165
-			\OCP\Util::writeLog('user_ldap', 'Attempt for Paging?  ' . print_r($pagedSearchOK, true), ILogger::ERROR);
1165
+			\OCP\Util::writeLog('user_ldap', 'Attempt for Paging?  '.print_r($pagedSearchOK, true), ILogger::ERROR);
1166 1166
 			return false;
1167 1167
 		}
1168 1168
 
@@ -1206,7 +1206,7 @@  discard block
 block discarded – undo
1206 1206
 				$this->pagedSearchedSuccessful = true;
1207 1207
 			}
1208 1208
 		} else {
1209
-			if (!is_null($limit) && (int)$this->connection->ldapPagingSize !== 0) {
1209
+			if (!is_null($limit) && (int) $this->connection->ldapPagingSize !== 0) {
1210 1210
 				\OC::$server->getLogger()->debug(
1211 1211
 					'Paged search was not available',
1212 1212
 					['app' => 'user_ldap']
@@ -1252,7 +1252,7 @@  discard block
 block discarded – undo
1252 1252
 			$attr = [mb_strtolower($attr, 'UTF-8')];
1253 1253
 		}
1254 1254
 
1255
-		$limitPerPage = (int)$this->connection->ldapPagingSize;
1255
+		$limitPerPage = (int) $this->connection->ldapPagingSize;
1256 1256
 		if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1257 1257
 			$limitPerPage = $limit;
1258 1258
 		}
@@ -1294,7 +1294,7 @@  discard block
 block discarded – undo
1294 1294
 	 * @throws ServerNotAvailableException
1295 1295
 	 */
1296 1296
 	private function countEntriesInSearchResults($sr): int {
1297
-		return (int)$this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $sr);
1297
+		return (int) $this->invokeLDAPMethod('countEntries', $this->connection->getConnectionResource(), $sr);
1298 1298
 	}
1299 1299
 
1300 1300
 	/**
@@ -1310,7 +1310,7 @@  discard block
 block discarded – undo
1310 1310
 		?int $offset = null,
1311 1311
 		bool $skipHandling = false
1312 1312
 	): array {
1313
-		$limitPerPage = (int)$this->connection->ldapPagingSize;
1313
+		$limitPerPage = (int) $this->connection->ldapPagingSize;
1314 1314
 		if (!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
1315 1315
 			$limitPerPage = $limit;
1316 1316
 		}
@@ -1402,7 +1402,7 @@  discard block
 block discarded – undo
1402 1402
 				&& !is_null($limit)
1403 1403
 			)
1404 1404
 		) {
1405
-			$findings = array_slice($findings, (int)$offset, $limit);
1405
+			$findings = array_slice($findings, (int) $offset, $limit);
1406 1406
 		}
1407 1407
 		return $findings;
1408 1408
 	}
@@ -1454,7 +1454,7 @@  discard block
 block discarded – undo
1454 1454
 		}
1455 1455
 		$search = ['*', '\\', '(', ')'];
1456 1456
 		$replace = ['\\*', '\\\\', '\\(', '\\)'];
1457
-		return $asterisk . str_replace($search, $replace, $input);
1457
+		return $asterisk.str_replace($search, $replace, $input);
1458 1458
 	}
1459 1459
 
1460 1460
 	/**
@@ -1486,10 +1486,10 @@  discard block
 block discarded – undo
1486 1486
 	 * @return string the combined filter
1487 1487
 	 */
1488 1488
 	private function combineFilter($filters, $operator) {
1489
-		$combinedFilter = '(' . $operator;
1489
+		$combinedFilter = '('.$operator;
1490 1490
 		foreach ($filters as $filter) {
1491 1491
 			if ($filter !== '' && $filter[0] !== '(') {
1492
-				$filter = '(' . $filter . ')';
1492
+				$filter = '('.$filter.')';
1493 1493
 			}
1494 1494
 			$combinedFilter .= $filter;
1495 1495
 		}
@@ -1542,7 +1542,7 @@  discard block
 block discarded – undo
1542 1542
 			//every word needs to appear at least once
1543 1543
 			$wordMatchOneAttrFilters = [];
1544 1544
 			foreach ($searchAttributes as $attr) {
1545
-				$wordMatchOneAttrFilters[] = $attr . '=' . $word;
1545
+				$wordMatchOneAttrFilters[] = $attr.'='.$word;
1546 1546
 			}
1547 1547
 			$wordFilters[] = $this->combineFilterWithOr($wordMatchOneAttrFilters);
1548 1548
 		}
@@ -1574,14 +1574,14 @@  discard block
 block discarded – undo
1574 1574
 			if ($fallbackAttribute === '') {
1575 1575
 				return '';
1576 1576
 			}
1577
-			$filter[] = $fallbackAttribute . '=' . $search;
1577
+			$filter[] = $fallbackAttribute.'='.$search;
1578 1578
 		} else {
1579 1579
 			foreach ($searchAttributes as $attribute) {
1580
-				$filter[] = $attribute . '=' . $search;
1580
+				$filter[] = $attribute.'='.$search;
1581 1581
 			}
1582 1582
 		}
1583 1583
 		if (count($filter) === 1) {
1584
-			return '(' . $filter[0] . ')';
1584
+			return '('.$filter[0].')';
1585 1585
 		}
1586 1586
 		return $this->combineFilterWithOr($filter);
1587 1587
 	}
@@ -1602,7 +1602,7 @@  discard block
 block discarded – undo
1602 1602
 		if ($term === '') {
1603 1603
 			$result = '*';
1604 1604
 		} elseif ($allowEnum !== 'no') {
1605
-			$result = $term . '*';
1605
+			$result = $term.'*';
1606 1606
 		}
1607 1607
 		return $result;
1608 1608
 	}
@@ -1615,7 +1615,7 @@  discard block
 block discarded – undo
1615 1615
 	public function getFilterForUserCount() {
1616 1616
 		$filter = $this->combineFilterWithAnd([
1617 1617
 			$this->connection->ldapUserFilter,
1618
-			$this->connection->ldapUserDisplayName . '=*'
1618
+			$this->connection->ldapUserDisplayName.'=*'
1619 1619
 		]);
1620 1620
 
1621 1621
 		return $filter;
@@ -1681,7 +1681,7 @@  discard block
 block discarded – undo
1681 1681
 			$uuid = $this->formatGuid2ForFilterUser($uuid);
1682 1682
 		}
1683 1683
 
1684
-		$filter = $uuidAttr . '=' . $uuid;
1684
+		$filter = $uuidAttr.'='.$uuid;
1685 1685
 		$result = $this->searchUsers($filter, ['dn'], 2);
1686 1686
 		if (is_array($result) && isset($result[0]) && isset($result[0]['dn']) && count($result) === 1) {
1687 1687
 			// we put the count into account to make sure that this is
@@ -1811,8 +1811,8 @@  discard block
 block discarded – undo
1811 1811
 		for ($k = 1; $k <= 2; ++$k) {
1812 1812
 			$hex_guid_to_guid_str .= substr($hex_guid, 16 - 2 * $k, 2);
1813 1813
 		}
1814
-		$hex_guid_to_guid_str .= '-' . substr($hex_guid, 16, 4);
1815
-		$hex_guid_to_guid_str .= '-' . substr($hex_guid, 20);
1814
+		$hex_guid_to_guid_str .= '-'.substr($hex_guid, 16, 4);
1815
+		$hex_guid_to_guid_str .= '-'.substr($hex_guid, 20);
1816 1816
 
1817 1817
 		return strtoupper($hex_guid_to_guid_str);
1818 1818
 	}
@@ -1846,7 +1846,7 @@  discard block
 block discarded – undo
1846 1846
 			 * user. Instead we write a log message.
1847 1847
 			 */
1848 1848
 			\OC::$server->getLogger()->info(
1849
-				'Passed string does not resemble a valid GUID. Known UUID ' .
1849
+				'Passed string does not resemble a valid GUID. Known UUID '.
1850 1850
 				'({uuid}) probably does not match UUID configuration.',
1851 1851
 				['app' => 'user_ldap', 'uuid' => $guid]
1852 1852
 			);
@@ -1859,7 +1859,7 @@  discard block
 block discarded – undo
1859 1859
 		}
1860 1860
 		for ($i = 0; $i < 5; $i++) {
1861 1861
 			$pairs = str_split($blocks[$i], 2);
1862
-			$blocks[$i] = '\\' . implode('\\', $pairs);
1862
+			$blocks[$i] = '\\'.implode('\\', $pairs);
1863 1863
 		}
1864 1864
 		return implode('', $blocks);
1865 1865
 	}
@@ -1873,7 +1873,7 @@  discard block
 block discarded – undo
1873 1873
 	 */
1874 1874
 	public function getSID($dn) {
1875 1875
 		$domainDN = $this->getDomainDNFromDN($dn);
1876
-		$cacheKey = 'getSID-' . $domainDN;
1876
+		$cacheKey = 'getSID-'.$domainDN;
1877 1877
 		$sid = $this->connection->getFromCache($cacheKey);
1878 1878
 		if (!is_null($sid)) {
1879 1879
 			return $sid;
@@ -2067,7 +2067,7 @@  discard block
 block discarded – undo
2067 2067
 			$this->abandonPagedSearch();
2068 2068
 			// in case someone set it to 0 … use 500, otherwise no results will
2069 2069
 			// be returned.
2070
-			$pageSize = (int)$this->connection->ldapPagingSize > 0 ? (int)$this->connection->ldapPagingSize : 500;
2070
+			$pageSize = (int) $this->connection->ldapPagingSize > 0 ? (int) $this->connection->ldapPagingSize : 500;
2071 2071
 			$pagedSearchOK = $this->invokeLDAPMethod('controlPagedResult',
2072 2072
 				$this->connection->getConnectionResource(),
2073 2073
 				$pageSize, false);
Please login to merge, or discard this patch.
apps/user_ldap/composer/composer/autoload_static.php 1 patch
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -6,96 +6,96 @@
 block discarded – undo
6 6
 
7 7
 class ComposerStaticInitUser_LDAP
8 8
 {
9
-    public static $prefixLengthsPsr4 = array (
9
+    public static $prefixLengthsPsr4 = array(
10 10
         'O' => 
11
-        array (
11
+        array(
12 12
             'OCA\\User_LDAP\\' => 14,
13 13
         ),
14 14
     );
15 15
 
16
-    public static $prefixDirsPsr4 = array (
16
+    public static $prefixDirsPsr4 = array(
17 17
         'OCA\\User_LDAP\\' => 
18
-        array (
19
-            0 => __DIR__ . '/..' . '/../lib',
18
+        array(
19
+            0 => __DIR__.'/..'.'/../lib',
20 20
         ),
21 21
     );
22 22
 
23
-    public static $classMap = array (
24
-        'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
25
-        'OCA\\User_LDAP\\Access' => __DIR__ . '/..' . '/../lib/Access.php',
26
-        'OCA\\User_LDAP\\AccessFactory' => __DIR__ . '/..' . '/../lib/AccessFactory.php',
27
-        'OCA\\User_LDAP\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
28
-        'OCA\\User_LDAP\\BackendUtility' => __DIR__ . '/..' . '/../lib/BackendUtility.php',
29
-        'OCA\\User_LDAP\\Command\\CheckUser' => __DIR__ . '/..' . '/../lib/Command/CheckUser.php',
30
-        'OCA\\User_LDAP\\Command\\CreateEmptyConfig' => __DIR__ . '/..' . '/../lib/Command/CreateEmptyConfig.php',
31
-        'OCA\\User_LDAP\\Command\\DeleteConfig' => __DIR__ . '/..' . '/../lib/Command/DeleteConfig.php',
32
-        'OCA\\User_LDAP\\Command\\ResetUser' => __DIR__ . '/..' . '/../lib/Command/ResetUser.php',
33
-        'OCA\\User_LDAP\\Command\\Search' => __DIR__ . '/..' . '/../lib/Command/Search.php',
34
-        'OCA\\User_LDAP\\Command\\SetConfig' => __DIR__ . '/..' . '/../lib/Command/SetConfig.php',
35
-        'OCA\\User_LDAP\\Command\\ShowConfig' => __DIR__ . '/..' . '/../lib/Command/ShowConfig.php',
36
-        'OCA\\User_LDAP\\Command\\ShowRemnants' => __DIR__ . '/..' . '/../lib/Command/ShowRemnants.php',
37
-        'OCA\\User_LDAP\\Command\\TestConfig' => __DIR__ . '/..' . '/../lib/Command/TestConfig.php',
38
-        'OCA\\User_LDAP\\Configuration' => __DIR__ . '/..' . '/../lib/Configuration.php',
39
-        'OCA\\User_LDAP\\Connection' => __DIR__ . '/..' . '/../lib/Connection.php',
40
-        'OCA\\User_LDAP\\ConnectionFactory' => __DIR__ . '/..' . '/../lib/ConnectionFactory.php',
41
-        'OCA\\User_LDAP\\Controller\\ConfigAPIController' => __DIR__ . '/..' . '/../lib/Controller/ConfigAPIController.php',
42
-        'OCA\\User_LDAP\\Controller\\RenewPasswordController' => __DIR__ . '/..' . '/../lib/Controller/RenewPasswordController.php',
43
-        'OCA\\User_LDAP\\Events\\GroupBackendRegistered' => __DIR__ . '/..' . '/../lib/Events/GroupBackendRegistered.php',
44
-        'OCA\\User_LDAP\\Events\\UserBackendRegistered' => __DIR__ . '/..' . '/../lib/Events/UserBackendRegistered.php',
45
-        'OCA\\User_LDAP\\Exceptions\\AttributeNotSet' => __DIR__ . '/..' . '/../lib/Exceptions/AttributeNotSet.php',
46
-        'OCA\\User_LDAP\\Exceptions\\ConstraintViolationException' => __DIR__ . '/..' . '/../lib/Exceptions/ConstraintViolationException.php',
47
-        'OCA\\User_LDAP\\Exceptions\\NoMoreResults' => __DIR__ . '/..' . '/../lib/Exceptions/NoMoreResults.php',
48
-        'OCA\\User_LDAP\\Exceptions\\NotOnLDAP' => __DIR__ . '/..' . '/../lib/Exceptions/NotOnLDAP.php',
49
-        'OCA\\User_LDAP\\FilesystemHelper' => __DIR__ . '/..' . '/../lib/FilesystemHelper.php',
50
-        'OCA\\User_LDAP\\GroupPluginManager' => __DIR__ . '/..' . '/../lib/GroupPluginManager.php',
51
-        'OCA\\User_LDAP\\Group_LDAP' => __DIR__ . '/..' . '/../lib/Group_LDAP.php',
52
-        'OCA\\User_LDAP\\Group_Proxy' => __DIR__ . '/..' . '/../lib/Group_Proxy.php',
53
-        'OCA\\User_LDAP\\Handler\\ExtStorageConfigHandler' => __DIR__ . '/..' . '/../lib/Handler/ExtStorageConfigHandler.php',
54
-        'OCA\\User_LDAP\\Helper' => __DIR__ . '/..' . '/../lib/Helper.php',
55
-        'OCA\\User_LDAP\\IGroupLDAP' => __DIR__ . '/..' . '/../lib/IGroupLDAP.php',
56
-        'OCA\\User_LDAP\\ILDAPGroupPlugin' => __DIR__ . '/..' . '/../lib/ILDAPGroupPlugin.php',
57
-        'OCA\\User_LDAP\\ILDAPUserPlugin' => __DIR__ . '/..' . '/../lib/ILDAPUserPlugin.php',
58
-        'OCA\\User_LDAP\\ILDAPWrapper' => __DIR__ . '/..' . '/../lib/ILDAPWrapper.php',
59
-        'OCA\\User_LDAP\\IUserLDAP' => __DIR__ . '/..' . '/../lib/IUserLDAP.php',
60
-        'OCA\\User_LDAP\\Jobs\\CleanUp' => __DIR__ . '/..' . '/../lib/Jobs/CleanUp.php',
61
-        'OCA\\User_LDAP\\Jobs\\Sync' => __DIR__ . '/..' . '/../lib/Jobs/Sync.php',
62
-        'OCA\\User_LDAP\\Jobs\\UpdateGroups' => __DIR__ . '/..' . '/../lib/Jobs/UpdateGroups.php',
63
-        'OCA\\User_LDAP\\LDAP' => __DIR__ . '/..' . '/../lib/LDAP.php',
64
-        'OCA\\User_LDAP\\LDAPProvider' => __DIR__ . '/..' . '/../lib/LDAPProvider.php',
65
-        'OCA\\User_LDAP\\LDAPProviderFactory' => __DIR__ . '/..' . '/../lib/LDAPProviderFactory.php',
66
-        'OCA\\User_LDAP\\LDAPUtility' => __DIR__ . '/..' . '/../lib/LDAPUtility.php',
67
-        'OCA\\User_LDAP\\LogWrapper' => __DIR__ . '/..' . '/../lib/LogWrapper.php',
68
-        'OCA\\User_LDAP\\Mapping\\AbstractMapping' => __DIR__ . '/..' . '/../lib/Mapping/AbstractMapping.php',
69
-        'OCA\\User_LDAP\\Mapping\\GroupMapping' => __DIR__ . '/..' . '/../lib/Mapping/GroupMapping.php',
70
-        'OCA\\User_LDAP\\Mapping\\UserMapping' => __DIR__ . '/..' . '/../lib/Mapping/UserMapping.php',
71
-        'OCA\\User_LDAP\\Migration\\RemoveRefreshTime' => __DIR__ . '/..' . '/../lib/Migration/RemoveRefreshTime.php',
72
-        'OCA\\User_LDAP\\Migration\\SetDefaultProvider' => __DIR__ . '/..' . '/../lib/Migration/SetDefaultProvider.php',
73
-        'OCA\\User_LDAP\\Migration\\UUIDFix' => __DIR__ . '/..' . '/../lib/Migration/UUIDFix.php',
74
-        'OCA\\User_LDAP\\Migration\\UUIDFixGroup' => __DIR__ . '/..' . '/../lib/Migration/UUIDFixGroup.php',
75
-        'OCA\\User_LDAP\\Migration\\UUIDFixInsert' => __DIR__ . '/..' . '/../lib/Migration/UUIDFixInsert.php',
76
-        'OCA\\User_LDAP\\Migration\\UUIDFixUser' => __DIR__ . '/..' . '/../lib/Migration/UUIDFixUser.php',
77
-        'OCA\\User_LDAP\\Migration\\Version1010Date20200630192842' => __DIR__ . '/..' . '/../lib/Migration/Version1010Date20200630192842.php',
78
-        'OCA\\User_LDAP\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php',
79
-        'OCA\\User_LDAP\\PagedResults\\IAdapter' => __DIR__ . '/..' . '/../lib/PagedResults/IAdapter.php',
80
-        'OCA\\User_LDAP\\PagedResults\\Php73' => __DIR__ . '/..' . '/../lib/PagedResults/Php73.php',
81
-        'OCA\\User_LDAP\\PagedResults\\TLinkId' => __DIR__ . '/..' . '/../lib/PagedResults/TLinkId.php',
82
-        'OCA\\User_LDAP\\Proxy' => __DIR__ . '/..' . '/../lib/Proxy.php',
83
-        'OCA\\User_LDAP\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php',
84
-        'OCA\\User_LDAP\\Settings\\Section' => __DIR__ . '/..' . '/../lib/Settings/Section.php',
85
-        'OCA\\User_LDAP\\UserPluginManager' => __DIR__ . '/..' . '/../lib/UserPluginManager.php',
86
-        'OCA\\User_LDAP\\User\\DeletedUsersIndex' => __DIR__ . '/..' . '/../lib/User/DeletedUsersIndex.php',
87
-        'OCA\\User_LDAP\\User\\Manager' => __DIR__ . '/..' . '/../lib/User/Manager.php',
88
-        'OCA\\User_LDAP\\User\\OfflineUser' => __DIR__ . '/..' . '/../lib/User/OfflineUser.php',
89
-        'OCA\\User_LDAP\\User\\User' => __DIR__ . '/..' . '/../lib/User/User.php',
90
-        'OCA\\User_LDAP\\User_LDAP' => __DIR__ . '/..' . '/../lib/User_LDAP.php',
91
-        'OCA\\User_LDAP\\User_Proxy' => __DIR__ . '/..' . '/../lib/User_Proxy.php',
92
-        'OCA\\User_LDAP\\Wizard' => __DIR__ . '/..' . '/../lib/Wizard.php',
93
-        'OCA\\User_LDAP\\WizardResult' => __DIR__ . '/..' . '/../lib/WizardResult.php',
23
+    public static $classMap = array(
24
+        'Composer\\InstalledVersions' => __DIR__.'/..'.'/composer/InstalledVersions.php',
25
+        'OCA\\User_LDAP\\Access' => __DIR__.'/..'.'/../lib/Access.php',
26
+        'OCA\\User_LDAP\\AccessFactory' => __DIR__.'/..'.'/../lib/AccessFactory.php',
27
+        'OCA\\User_LDAP\\AppInfo\\Application' => __DIR__.'/..'.'/../lib/AppInfo/Application.php',
28
+        'OCA\\User_LDAP\\BackendUtility' => __DIR__.'/..'.'/../lib/BackendUtility.php',
29
+        'OCA\\User_LDAP\\Command\\CheckUser' => __DIR__.'/..'.'/../lib/Command/CheckUser.php',
30
+        'OCA\\User_LDAP\\Command\\CreateEmptyConfig' => __DIR__.'/..'.'/../lib/Command/CreateEmptyConfig.php',
31
+        'OCA\\User_LDAP\\Command\\DeleteConfig' => __DIR__.'/..'.'/../lib/Command/DeleteConfig.php',
32
+        'OCA\\User_LDAP\\Command\\ResetUser' => __DIR__.'/..'.'/../lib/Command/ResetUser.php',
33
+        'OCA\\User_LDAP\\Command\\Search' => __DIR__.'/..'.'/../lib/Command/Search.php',
34
+        'OCA\\User_LDAP\\Command\\SetConfig' => __DIR__.'/..'.'/../lib/Command/SetConfig.php',
35
+        'OCA\\User_LDAP\\Command\\ShowConfig' => __DIR__.'/..'.'/../lib/Command/ShowConfig.php',
36
+        'OCA\\User_LDAP\\Command\\ShowRemnants' => __DIR__.'/..'.'/../lib/Command/ShowRemnants.php',
37
+        'OCA\\User_LDAP\\Command\\TestConfig' => __DIR__.'/..'.'/../lib/Command/TestConfig.php',
38
+        'OCA\\User_LDAP\\Configuration' => __DIR__.'/..'.'/../lib/Configuration.php',
39
+        'OCA\\User_LDAP\\Connection' => __DIR__.'/..'.'/../lib/Connection.php',
40
+        'OCA\\User_LDAP\\ConnectionFactory' => __DIR__.'/..'.'/../lib/ConnectionFactory.php',
41
+        'OCA\\User_LDAP\\Controller\\ConfigAPIController' => __DIR__.'/..'.'/../lib/Controller/ConfigAPIController.php',
42
+        'OCA\\User_LDAP\\Controller\\RenewPasswordController' => __DIR__.'/..'.'/../lib/Controller/RenewPasswordController.php',
43
+        'OCA\\User_LDAP\\Events\\GroupBackendRegistered' => __DIR__.'/..'.'/../lib/Events/GroupBackendRegistered.php',
44
+        'OCA\\User_LDAP\\Events\\UserBackendRegistered' => __DIR__.'/..'.'/../lib/Events/UserBackendRegistered.php',
45
+        'OCA\\User_LDAP\\Exceptions\\AttributeNotSet' => __DIR__.'/..'.'/../lib/Exceptions/AttributeNotSet.php',
46
+        'OCA\\User_LDAP\\Exceptions\\ConstraintViolationException' => __DIR__.'/..'.'/../lib/Exceptions/ConstraintViolationException.php',
47
+        'OCA\\User_LDAP\\Exceptions\\NoMoreResults' => __DIR__.'/..'.'/../lib/Exceptions/NoMoreResults.php',
48
+        'OCA\\User_LDAP\\Exceptions\\NotOnLDAP' => __DIR__.'/..'.'/../lib/Exceptions/NotOnLDAP.php',
49
+        'OCA\\User_LDAP\\FilesystemHelper' => __DIR__.'/..'.'/../lib/FilesystemHelper.php',
50
+        'OCA\\User_LDAP\\GroupPluginManager' => __DIR__.'/..'.'/../lib/GroupPluginManager.php',
51
+        'OCA\\User_LDAP\\Group_LDAP' => __DIR__.'/..'.'/../lib/Group_LDAP.php',
52
+        'OCA\\User_LDAP\\Group_Proxy' => __DIR__.'/..'.'/../lib/Group_Proxy.php',
53
+        'OCA\\User_LDAP\\Handler\\ExtStorageConfigHandler' => __DIR__.'/..'.'/../lib/Handler/ExtStorageConfigHandler.php',
54
+        'OCA\\User_LDAP\\Helper' => __DIR__.'/..'.'/../lib/Helper.php',
55
+        'OCA\\User_LDAP\\IGroupLDAP' => __DIR__.'/..'.'/../lib/IGroupLDAP.php',
56
+        'OCA\\User_LDAP\\ILDAPGroupPlugin' => __DIR__.'/..'.'/../lib/ILDAPGroupPlugin.php',
57
+        'OCA\\User_LDAP\\ILDAPUserPlugin' => __DIR__.'/..'.'/../lib/ILDAPUserPlugin.php',
58
+        'OCA\\User_LDAP\\ILDAPWrapper' => __DIR__.'/..'.'/../lib/ILDAPWrapper.php',
59
+        'OCA\\User_LDAP\\IUserLDAP' => __DIR__.'/..'.'/../lib/IUserLDAP.php',
60
+        'OCA\\User_LDAP\\Jobs\\CleanUp' => __DIR__.'/..'.'/../lib/Jobs/CleanUp.php',
61
+        'OCA\\User_LDAP\\Jobs\\Sync' => __DIR__.'/..'.'/../lib/Jobs/Sync.php',
62
+        'OCA\\User_LDAP\\Jobs\\UpdateGroups' => __DIR__.'/..'.'/../lib/Jobs/UpdateGroups.php',
63
+        'OCA\\User_LDAP\\LDAP' => __DIR__.'/..'.'/../lib/LDAP.php',
64
+        'OCA\\User_LDAP\\LDAPProvider' => __DIR__.'/..'.'/../lib/LDAPProvider.php',
65
+        'OCA\\User_LDAP\\LDAPProviderFactory' => __DIR__.'/..'.'/../lib/LDAPProviderFactory.php',
66
+        'OCA\\User_LDAP\\LDAPUtility' => __DIR__.'/..'.'/../lib/LDAPUtility.php',
67
+        'OCA\\User_LDAP\\LogWrapper' => __DIR__.'/..'.'/../lib/LogWrapper.php',
68
+        'OCA\\User_LDAP\\Mapping\\AbstractMapping' => __DIR__.'/..'.'/../lib/Mapping/AbstractMapping.php',
69
+        'OCA\\User_LDAP\\Mapping\\GroupMapping' => __DIR__.'/..'.'/../lib/Mapping/GroupMapping.php',
70
+        'OCA\\User_LDAP\\Mapping\\UserMapping' => __DIR__.'/..'.'/../lib/Mapping/UserMapping.php',
71
+        'OCA\\User_LDAP\\Migration\\RemoveRefreshTime' => __DIR__.'/..'.'/../lib/Migration/RemoveRefreshTime.php',
72
+        'OCA\\User_LDAP\\Migration\\SetDefaultProvider' => __DIR__.'/..'.'/../lib/Migration/SetDefaultProvider.php',
73
+        'OCA\\User_LDAP\\Migration\\UUIDFix' => __DIR__.'/..'.'/../lib/Migration/UUIDFix.php',
74
+        'OCA\\User_LDAP\\Migration\\UUIDFixGroup' => __DIR__.'/..'.'/../lib/Migration/UUIDFixGroup.php',
75
+        'OCA\\User_LDAP\\Migration\\UUIDFixInsert' => __DIR__.'/..'.'/../lib/Migration/UUIDFixInsert.php',
76
+        'OCA\\User_LDAP\\Migration\\UUIDFixUser' => __DIR__.'/..'.'/../lib/Migration/UUIDFixUser.php',
77
+        'OCA\\User_LDAP\\Migration\\Version1010Date20200630192842' => __DIR__.'/..'.'/../lib/Migration/Version1010Date20200630192842.php',
78
+        'OCA\\User_LDAP\\Notification\\Notifier' => __DIR__.'/..'.'/../lib/Notification/Notifier.php',
79
+        'OCA\\User_LDAP\\PagedResults\\IAdapter' => __DIR__.'/..'.'/../lib/PagedResults/IAdapter.php',
80
+        'OCA\\User_LDAP\\PagedResults\\Php73' => __DIR__.'/..'.'/../lib/PagedResults/Php73.php',
81
+        'OCA\\User_LDAP\\PagedResults\\TLinkId' => __DIR__.'/..'.'/../lib/PagedResults/TLinkId.php',
82
+        'OCA\\User_LDAP\\Proxy' => __DIR__.'/..'.'/../lib/Proxy.php',
83
+        'OCA\\User_LDAP\\Settings\\Admin' => __DIR__.'/..'.'/../lib/Settings/Admin.php',
84
+        'OCA\\User_LDAP\\Settings\\Section' => __DIR__.'/..'.'/../lib/Settings/Section.php',
85
+        'OCA\\User_LDAP\\UserPluginManager' => __DIR__.'/..'.'/../lib/UserPluginManager.php',
86
+        'OCA\\User_LDAP\\User\\DeletedUsersIndex' => __DIR__.'/..'.'/../lib/User/DeletedUsersIndex.php',
87
+        'OCA\\User_LDAP\\User\\Manager' => __DIR__.'/..'.'/../lib/User/Manager.php',
88
+        'OCA\\User_LDAP\\User\\OfflineUser' => __DIR__.'/..'.'/../lib/User/OfflineUser.php',
89
+        'OCA\\User_LDAP\\User\\User' => __DIR__.'/..'.'/../lib/User/User.php',
90
+        'OCA\\User_LDAP\\User_LDAP' => __DIR__.'/..'.'/../lib/User_LDAP.php',
91
+        'OCA\\User_LDAP\\User_Proxy' => __DIR__.'/..'.'/../lib/User_Proxy.php',
92
+        'OCA\\User_LDAP\\Wizard' => __DIR__.'/..'.'/../lib/Wizard.php',
93
+        'OCA\\User_LDAP\\WizardResult' => __DIR__.'/..'.'/../lib/WizardResult.php',
94 94
     );
95 95
 
96 96
     public static function getInitializer(ClassLoader $loader)
97 97
     {
98
-        return \Closure::bind(function () use ($loader) {
98
+        return \Closure::bind(function() use ($loader) {
99 99
             $loader->prefixLengthsPsr4 = ComposerStaticInitUser_LDAP::$prefixLengthsPsr4;
100 100
             $loader->prefixDirsPsr4 = ComposerStaticInitUser_LDAP::$prefixDirsPsr4;
101 101
             $loader->classMap = ComposerStaticInitUser_LDAP::$classMap;
Please login to merge, or discard this patch.
apps/user_ldap/composer/composer/autoload_classmap.php 1 patch
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -6,74 +6,74 @@
 block discarded – undo
6 6
 $baseDir = $vendorDir;
7 7
 
8 8
 return array(
9
-    'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
10
-    'OCA\\User_LDAP\\Access' => $baseDir . '/../lib/Access.php',
11
-    'OCA\\User_LDAP\\AccessFactory' => $baseDir . '/../lib/AccessFactory.php',
12
-    'OCA\\User_LDAP\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
13
-    'OCA\\User_LDAP\\BackendUtility' => $baseDir . '/../lib/BackendUtility.php',
14
-    'OCA\\User_LDAP\\Command\\CheckUser' => $baseDir . '/../lib/Command/CheckUser.php',
15
-    'OCA\\User_LDAP\\Command\\CreateEmptyConfig' => $baseDir . '/../lib/Command/CreateEmptyConfig.php',
16
-    'OCA\\User_LDAP\\Command\\DeleteConfig' => $baseDir . '/../lib/Command/DeleteConfig.php',
17
-    'OCA\\User_LDAP\\Command\\ResetUser' => $baseDir . '/../lib/Command/ResetUser.php',
18
-    'OCA\\User_LDAP\\Command\\Search' => $baseDir . '/../lib/Command/Search.php',
19
-    'OCA\\User_LDAP\\Command\\SetConfig' => $baseDir . '/../lib/Command/SetConfig.php',
20
-    'OCA\\User_LDAP\\Command\\ShowConfig' => $baseDir . '/../lib/Command/ShowConfig.php',
21
-    'OCA\\User_LDAP\\Command\\ShowRemnants' => $baseDir . '/../lib/Command/ShowRemnants.php',
22
-    'OCA\\User_LDAP\\Command\\TestConfig' => $baseDir . '/../lib/Command/TestConfig.php',
23
-    'OCA\\User_LDAP\\Configuration' => $baseDir . '/../lib/Configuration.php',
24
-    'OCA\\User_LDAP\\Connection' => $baseDir . '/../lib/Connection.php',
25
-    'OCA\\User_LDAP\\ConnectionFactory' => $baseDir . '/../lib/ConnectionFactory.php',
26
-    'OCA\\User_LDAP\\Controller\\ConfigAPIController' => $baseDir . '/../lib/Controller/ConfigAPIController.php',
27
-    'OCA\\User_LDAP\\Controller\\RenewPasswordController' => $baseDir . '/../lib/Controller/RenewPasswordController.php',
28
-    'OCA\\User_LDAP\\Events\\GroupBackendRegistered' => $baseDir . '/../lib/Events/GroupBackendRegistered.php',
29
-    'OCA\\User_LDAP\\Events\\UserBackendRegistered' => $baseDir . '/../lib/Events/UserBackendRegistered.php',
30
-    'OCA\\User_LDAP\\Exceptions\\AttributeNotSet' => $baseDir . '/../lib/Exceptions/AttributeNotSet.php',
31
-    'OCA\\User_LDAP\\Exceptions\\ConstraintViolationException' => $baseDir . '/../lib/Exceptions/ConstraintViolationException.php',
32
-    'OCA\\User_LDAP\\Exceptions\\NoMoreResults' => $baseDir . '/../lib/Exceptions/NoMoreResults.php',
33
-    'OCA\\User_LDAP\\Exceptions\\NotOnLDAP' => $baseDir . '/../lib/Exceptions/NotOnLDAP.php',
34
-    'OCA\\User_LDAP\\FilesystemHelper' => $baseDir . '/../lib/FilesystemHelper.php',
35
-    'OCA\\User_LDAP\\GroupPluginManager' => $baseDir . '/../lib/GroupPluginManager.php',
36
-    'OCA\\User_LDAP\\Group_LDAP' => $baseDir . '/../lib/Group_LDAP.php',
37
-    'OCA\\User_LDAP\\Group_Proxy' => $baseDir . '/../lib/Group_Proxy.php',
38
-    'OCA\\User_LDAP\\Handler\\ExtStorageConfigHandler' => $baseDir . '/../lib/Handler/ExtStorageConfigHandler.php',
39
-    'OCA\\User_LDAP\\Helper' => $baseDir . '/../lib/Helper.php',
40
-    'OCA\\User_LDAP\\IGroupLDAP' => $baseDir . '/../lib/IGroupLDAP.php',
41
-    'OCA\\User_LDAP\\ILDAPGroupPlugin' => $baseDir . '/../lib/ILDAPGroupPlugin.php',
42
-    'OCA\\User_LDAP\\ILDAPUserPlugin' => $baseDir . '/../lib/ILDAPUserPlugin.php',
43
-    'OCA\\User_LDAP\\ILDAPWrapper' => $baseDir . '/../lib/ILDAPWrapper.php',
44
-    'OCA\\User_LDAP\\IUserLDAP' => $baseDir . '/../lib/IUserLDAP.php',
45
-    'OCA\\User_LDAP\\Jobs\\CleanUp' => $baseDir . '/../lib/Jobs/CleanUp.php',
46
-    'OCA\\User_LDAP\\Jobs\\Sync' => $baseDir . '/../lib/Jobs/Sync.php',
47
-    'OCA\\User_LDAP\\Jobs\\UpdateGroups' => $baseDir . '/../lib/Jobs/UpdateGroups.php',
48
-    'OCA\\User_LDAP\\LDAP' => $baseDir . '/../lib/LDAP.php',
49
-    'OCA\\User_LDAP\\LDAPProvider' => $baseDir . '/../lib/LDAPProvider.php',
50
-    'OCA\\User_LDAP\\LDAPProviderFactory' => $baseDir . '/../lib/LDAPProviderFactory.php',
51
-    'OCA\\User_LDAP\\LDAPUtility' => $baseDir . '/../lib/LDAPUtility.php',
52
-    'OCA\\User_LDAP\\LogWrapper' => $baseDir . '/../lib/LogWrapper.php',
53
-    'OCA\\User_LDAP\\Mapping\\AbstractMapping' => $baseDir . '/../lib/Mapping/AbstractMapping.php',
54
-    'OCA\\User_LDAP\\Mapping\\GroupMapping' => $baseDir . '/../lib/Mapping/GroupMapping.php',
55
-    'OCA\\User_LDAP\\Mapping\\UserMapping' => $baseDir . '/../lib/Mapping/UserMapping.php',
56
-    'OCA\\User_LDAP\\Migration\\RemoveRefreshTime' => $baseDir . '/../lib/Migration/RemoveRefreshTime.php',
57
-    'OCA\\User_LDAP\\Migration\\SetDefaultProvider' => $baseDir . '/../lib/Migration/SetDefaultProvider.php',
58
-    'OCA\\User_LDAP\\Migration\\UUIDFix' => $baseDir . '/../lib/Migration/UUIDFix.php',
59
-    'OCA\\User_LDAP\\Migration\\UUIDFixGroup' => $baseDir . '/../lib/Migration/UUIDFixGroup.php',
60
-    'OCA\\User_LDAP\\Migration\\UUIDFixInsert' => $baseDir . '/../lib/Migration/UUIDFixInsert.php',
61
-    'OCA\\User_LDAP\\Migration\\UUIDFixUser' => $baseDir . '/../lib/Migration/UUIDFixUser.php',
62
-    'OCA\\User_LDAP\\Migration\\Version1010Date20200630192842' => $baseDir . '/../lib/Migration/Version1010Date20200630192842.php',
63
-    'OCA\\User_LDAP\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php',
64
-    'OCA\\User_LDAP\\PagedResults\\IAdapter' => $baseDir . '/../lib/PagedResults/IAdapter.php',
65
-    'OCA\\User_LDAP\\PagedResults\\Php73' => $baseDir . '/../lib/PagedResults/Php73.php',
66
-    'OCA\\User_LDAP\\PagedResults\\TLinkId' => $baseDir . '/../lib/PagedResults/TLinkId.php',
67
-    'OCA\\User_LDAP\\Proxy' => $baseDir . '/../lib/Proxy.php',
68
-    'OCA\\User_LDAP\\Settings\\Admin' => $baseDir . '/../lib/Settings/Admin.php',
69
-    'OCA\\User_LDAP\\Settings\\Section' => $baseDir . '/../lib/Settings/Section.php',
70
-    'OCA\\User_LDAP\\UserPluginManager' => $baseDir . '/../lib/UserPluginManager.php',
71
-    'OCA\\User_LDAP\\User\\DeletedUsersIndex' => $baseDir . '/../lib/User/DeletedUsersIndex.php',
72
-    'OCA\\User_LDAP\\User\\Manager' => $baseDir . '/../lib/User/Manager.php',
73
-    'OCA\\User_LDAP\\User\\OfflineUser' => $baseDir . '/../lib/User/OfflineUser.php',
74
-    'OCA\\User_LDAP\\User\\User' => $baseDir . '/../lib/User/User.php',
75
-    'OCA\\User_LDAP\\User_LDAP' => $baseDir . '/../lib/User_LDAP.php',
76
-    'OCA\\User_LDAP\\User_Proxy' => $baseDir . '/../lib/User_Proxy.php',
77
-    'OCA\\User_LDAP\\Wizard' => $baseDir . '/../lib/Wizard.php',
78
-    'OCA\\User_LDAP\\WizardResult' => $baseDir . '/../lib/WizardResult.php',
9
+    'Composer\\InstalledVersions' => $vendorDir.'/composer/InstalledVersions.php',
10
+    'OCA\\User_LDAP\\Access' => $baseDir.'/../lib/Access.php',
11
+    'OCA\\User_LDAP\\AccessFactory' => $baseDir.'/../lib/AccessFactory.php',
12
+    'OCA\\User_LDAP\\AppInfo\\Application' => $baseDir.'/../lib/AppInfo/Application.php',
13
+    'OCA\\User_LDAP\\BackendUtility' => $baseDir.'/../lib/BackendUtility.php',
14
+    'OCA\\User_LDAP\\Command\\CheckUser' => $baseDir.'/../lib/Command/CheckUser.php',
15
+    'OCA\\User_LDAP\\Command\\CreateEmptyConfig' => $baseDir.'/../lib/Command/CreateEmptyConfig.php',
16
+    'OCA\\User_LDAP\\Command\\DeleteConfig' => $baseDir.'/../lib/Command/DeleteConfig.php',
17
+    'OCA\\User_LDAP\\Command\\ResetUser' => $baseDir.'/../lib/Command/ResetUser.php',
18
+    'OCA\\User_LDAP\\Command\\Search' => $baseDir.'/../lib/Command/Search.php',
19
+    'OCA\\User_LDAP\\Command\\SetConfig' => $baseDir.'/../lib/Command/SetConfig.php',
20
+    'OCA\\User_LDAP\\Command\\ShowConfig' => $baseDir.'/../lib/Command/ShowConfig.php',
21
+    'OCA\\User_LDAP\\Command\\ShowRemnants' => $baseDir.'/../lib/Command/ShowRemnants.php',
22
+    'OCA\\User_LDAP\\Command\\TestConfig' => $baseDir.'/../lib/Command/TestConfig.php',
23
+    'OCA\\User_LDAP\\Configuration' => $baseDir.'/../lib/Configuration.php',
24
+    'OCA\\User_LDAP\\Connection' => $baseDir.'/../lib/Connection.php',
25
+    'OCA\\User_LDAP\\ConnectionFactory' => $baseDir.'/../lib/ConnectionFactory.php',
26
+    'OCA\\User_LDAP\\Controller\\ConfigAPIController' => $baseDir.'/../lib/Controller/ConfigAPIController.php',
27
+    'OCA\\User_LDAP\\Controller\\RenewPasswordController' => $baseDir.'/../lib/Controller/RenewPasswordController.php',
28
+    'OCA\\User_LDAP\\Events\\GroupBackendRegistered' => $baseDir.'/../lib/Events/GroupBackendRegistered.php',
29
+    'OCA\\User_LDAP\\Events\\UserBackendRegistered' => $baseDir.'/../lib/Events/UserBackendRegistered.php',
30
+    'OCA\\User_LDAP\\Exceptions\\AttributeNotSet' => $baseDir.'/../lib/Exceptions/AttributeNotSet.php',
31
+    'OCA\\User_LDAP\\Exceptions\\ConstraintViolationException' => $baseDir.'/../lib/Exceptions/ConstraintViolationException.php',
32
+    'OCA\\User_LDAP\\Exceptions\\NoMoreResults' => $baseDir.'/../lib/Exceptions/NoMoreResults.php',
33
+    'OCA\\User_LDAP\\Exceptions\\NotOnLDAP' => $baseDir.'/../lib/Exceptions/NotOnLDAP.php',
34
+    'OCA\\User_LDAP\\FilesystemHelper' => $baseDir.'/../lib/FilesystemHelper.php',
35
+    'OCA\\User_LDAP\\GroupPluginManager' => $baseDir.'/../lib/GroupPluginManager.php',
36
+    'OCA\\User_LDAP\\Group_LDAP' => $baseDir.'/../lib/Group_LDAP.php',
37
+    'OCA\\User_LDAP\\Group_Proxy' => $baseDir.'/../lib/Group_Proxy.php',
38
+    'OCA\\User_LDAP\\Handler\\ExtStorageConfigHandler' => $baseDir.'/../lib/Handler/ExtStorageConfigHandler.php',
39
+    'OCA\\User_LDAP\\Helper' => $baseDir.'/../lib/Helper.php',
40
+    'OCA\\User_LDAP\\IGroupLDAP' => $baseDir.'/../lib/IGroupLDAP.php',
41
+    'OCA\\User_LDAP\\ILDAPGroupPlugin' => $baseDir.'/../lib/ILDAPGroupPlugin.php',
42
+    'OCA\\User_LDAP\\ILDAPUserPlugin' => $baseDir.'/../lib/ILDAPUserPlugin.php',
43
+    'OCA\\User_LDAP\\ILDAPWrapper' => $baseDir.'/../lib/ILDAPWrapper.php',
44
+    'OCA\\User_LDAP\\IUserLDAP' => $baseDir.'/../lib/IUserLDAP.php',
45
+    'OCA\\User_LDAP\\Jobs\\CleanUp' => $baseDir.'/../lib/Jobs/CleanUp.php',
46
+    'OCA\\User_LDAP\\Jobs\\Sync' => $baseDir.'/../lib/Jobs/Sync.php',
47
+    'OCA\\User_LDAP\\Jobs\\UpdateGroups' => $baseDir.'/../lib/Jobs/UpdateGroups.php',
48
+    'OCA\\User_LDAP\\LDAP' => $baseDir.'/../lib/LDAP.php',
49
+    'OCA\\User_LDAP\\LDAPProvider' => $baseDir.'/../lib/LDAPProvider.php',
50
+    'OCA\\User_LDAP\\LDAPProviderFactory' => $baseDir.'/../lib/LDAPProviderFactory.php',
51
+    'OCA\\User_LDAP\\LDAPUtility' => $baseDir.'/../lib/LDAPUtility.php',
52
+    'OCA\\User_LDAP\\LogWrapper' => $baseDir.'/../lib/LogWrapper.php',
53
+    'OCA\\User_LDAP\\Mapping\\AbstractMapping' => $baseDir.'/../lib/Mapping/AbstractMapping.php',
54
+    'OCA\\User_LDAP\\Mapping\\GroupMapping' => $baseDir.'/../lib/Mapping/GroupMapping.php',
55
+    'OCA\\User_LDAP\\Mapping\\UserMapping' => $baseDir.'/../lib/Mapping/UserMapping.php',
56
+    'OCA\\User_LDAP\\Migration\\RemoveRefreshTime' => $baseDir.'/../lib/Migration/RemoveRefreshTime.php',
57
+    'OCA\\User_LDAP\\Migration\\SetDefaultProvider' => $baseDir.'/../lib/Migration/SetDefaultProvider.php',
58
+    'OCA\\User_LDAP\\Migration\\UUIDFix' => $baseDir.'/../lib/Migration/UUIDFix.php',
59
+    'OCA\\User_LDAP\\Migration\\UUIDFixGroup' => $baseDir.'/../lib/Migration/UUIDFixGroup.php',
60
+    'OCA\\User_LDAP\\Migration\\UUIDFixInsert' => $baseDir.'/../lib/Migration/UUIDFixInsert.php',
61
+    'OCA\\User_LDAP\\Migration\\UUIDFixUser' => $baseDir.'/../lib/Migration/UUIDFixUser.php',
62
+    'OCA\\User_LDAP\\Migration\\Version1010Date20200630192842' => $baseDir.'/../lib/Migration/Version1010Date20200630192842.php',
63
+    'OCA\\User_LDAP\\Notification\\Notifier' => $baseDir.'/../lib/Notification/Notifier.php',
64
+    'OCA\\User_LDAP\\PagedResults\\IAdapter' => $baseDir.'/../lib/PagedResults/IAdapter.php',
65
+    'OCA\\User_LDAP\\PagedResults\\Php73' => $baseDir.'/../lib/PagedResults/Php73.php',
66
+    'OCA\\User_LDAP\\PagedResults\\TLinkId' => $baseDir.'/../lib/PagedResults/TLinkId.php',
67
+    'OCA\\User_LDAP\\Proxy' => $baseDir.'/../lib/Proxy.php',
68
+    'OCA\\User_LDAP\\Settings\\Admin' => $baseDir.'/../lib/Settings/Admin.php',
69
+    'OCA\\User_LDAP\\Settings\\Section' => $baseDir.'/../lib/Settings/Section.php',
70
+    'OCA\\User_LDAP\\UserPluginManager' => $baseDir.'/../lib/UserPluginManager.php',
71
+    'OCA\\User_LDAP\\User\\DeletedUsersIndex' => $baseDir.'/../lib/User/DeletedUsersIndex.php',
72
+    'OCA\\User_LDAP\\User\\Manager' => $baseDir.'/../lib/User/Manager.php',
73
+    'OCA\\User_LDAP\\User\\OfflineUser' => $baseDir.'/../lib/User/OfflineUser.php',
74
+    'OCA\\User_LDAP\\User\\User' => $baseDir.'/../lib/User/User.php',
75
+    'OCA\\User_LDAP\\User_LDAP' => $baseDir.'/../lib/User_LDAP.php',
76
+    'OCA\\User_LDAP\\User_Proxy' => $baseDir.'/../lib/User_Proxy.php',
77
+    'OCA\\User_LDAP\\Wizard' => $baseDir.'/../lib/Wizard.php',
78
+    'OCA\\User_LDAP\\WizardResult' => $baseDir.'/../lib/WizardResult.php',
79 79
 );
Please login to merge, or discard this patch.