diff --git a/src/includes/functions.php b/src/includes/functions.php index 58c2fb97..09574e54 100644 --- a/src/includes/functions.php +++ b/src/includes/functions.php @@ -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\-]+))$/';