Add getRdn() and parentDn() helper functions

This commit is contained in:
Benjamin Renard 2023-03-20 18:26:29 +01:00
parent 1825ce429e
commit d387052068
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC

View file

@ -405,6 +405,35 @@ function sumDn($dn1,$dn2) {
return $basedn;
}
/**
* Extract and retreive RDN from DN
* @param string $dn
* @param bool $with_attr If true, include the RDN attribute name (optional, default: true)
* @return string|null|false The parent object DN, null if no parent or false in case of error
*/
function getRdn($dn, $with_attr=true) {
$parts = ldap_explode_dn($dn, 0);
if (!is_array($parts) || !isset($parts['count'])) return false;
if ($with_attr)
return $parts[0];
$equal_pos = strpos($parts[0], '=');
if ($equal_pos !== false)
return substr($parts[0], $equal_pos+1);
return $parts[0];
}
/**
* Retreive parent object DN
* @param string $dn
* @return string|null|false The parent object DN, null if no parent or false in case of error
*/
function parentDn($dn) {
$parts = ldap_explode_dn($dn, 0);
if (!is_array($parts) || !isset($parts['count'])) return false;
if ($parts['count'] == 1) return null;
return implode(',', array_slice($parts, 2));
}
function checkEmail($value,$domain=NULL,$checkDns=true) {
$log = LSlog :: get_logger('checkEmail');
$regex = '/^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/';