summaryrefslogtreecommitdiffstats
path: root/modules-available/sysconfig/inc/ldap.inc.php
blob: e974a8a3c481e4da8a6053a105ac032a7b275950 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php

class Ldap
{

	public static function normalizeDn(string $dn): string
	{
		return trim(preg_replace('/[,;]\s*/', ',', $dn));
	}

	public static function getSelfSearchBase($binddn, $searchbase)
	{
		// To find ourselves we try to figure out the proper search base, since the given one
		// might be just for users, not for functional or utility accounts
		if (preg_match('/^\w+=[^=]+,(.*)$/i', Ldap::normalizeDn($binddn), $out)) {
			$searchbase = $out[1];
		}
		return $searchbase;
	}

}