propperly import group names with non-printable chars

This commit is contained in:
Uwe Steinmann 2024-02-17 13:03:29 +01:00
parent 98984619f6
commit 17dbfcf2c7

View File

@ -47,9 +47,21 @@ class SeedDMS_LdapAuthentication extends SeedDMS_Authentication {
if(isset($ldapgroups['count']))
$count = (int) $ldapgroups['count'];
for ($i = 0; $i < $count; $i++) {
if(0) {
/* ldap_explode_dn() turns all utf-8 chars into \xx
* This needs to be undone with the following regex.
*/
$tmp = ldap_explode_dn($ldapgroups[$i], 1);
$tmp[0] = preg_replace_callback('/\\\([0-9A-Fa-f]{2})/', function ($matches) { return chr(hexdec($matches[1])); }, $tmp[0]);
} else {
/* Second option would be to not using ldap_explode_dn()
* and just extract the cn with
* preg_match('/[^cn=]([^,]*)/i', $ldapgroups[$i], $tmp);
*/
preg_match('/[^cn=]([^,]*)/i', $ldapgroups[$i], $tmp);
}
if (!in_array($tmp[0], $groupnames)) {
$groupnames[] = $tmp[0];
$groupnames[] = preg_replace_callback('/\\\([0-9A-Fa-f]{2})/', function ($matches) { return chr(hexdec($matches[1])); }, $tmp[0]);
}
}