Skip to content

Commit

Permalink
Fix encoding of users fields fetched from LDAP
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-anne authored and trasher committed Sep 25, 2023
1 parent e7bfc4e commit 11e05d1
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
$groups = getAllDataFromTable('glpi_groups');
foreach ($groups as $group) {
$updated = [];
foreach (['name', 'ldap_group_dn', 'ldap_value'] as $ldap_field) {
foreach (['ldap_group_dn', 'ldap_value'] as $ldap_field) {
if ($group[$ldap_field] !== null && preg_match('/(<|>|(&(?!#?[a-z0-9]+;)))/i', $group[$ldap_field]) === 1) {
$updated[$ldap_field] = Sanitizer::sanitize($group[$ldap_field]);
}
Expand All @@ -62,3 +62,26 @@
}
}
/** /Fix non encoded LDAP fields in groups */

/** Fix non encoded LDAP fields in users */
$users = getAllDataFromTable('glpi_users', ['authtype' => 3]);
foreach ($users as $user) {
$updated = [];
foreach (['user_dn', 'sync_field'] as $ldap_field) {
if ($user[$ldap_field] !== null && preg_match('/(<|>|(&(?!#?[a-z0-9]+;)))/i', $user[$ldap_field]) === 1) {
$updated[$ldap_field] = Sanitizer::sanitize($user[$ldap_field]);
}
}
if (count($updated) > 0) {
$migration->addPostQuery(
$DB->buildUpdate(
'glpi_users',
$updated,
[
'id' => $user['id'],
]
)
);
}
}
/** /Fix non encoded LDAP fields in groups */

0 comments on commit 11e05d1

Please sign in to comment.