event "auth user changed", optimize core_user_changed_groups() to only perform local_group_set() when there are changes needed. found while working on https://github.com/opnsense/core/issues/4411

This commit is contained in:
Ad Schellevis 2020-10-13 17:54:42 +02:00
parent 9731dc8fa7
commit 51489f83de

View File

@ -281,10 +281,10 @@ function core_user_changed_groups($verbose = false, $username)
$current_groups = explode(" ", $out[0]);
}
foreach ($config['system']['group'] as $group) {
if (
in_array($group['name'], $current_groups) ||
(!empty($group['member']) && in_array($user['uid'], $group['member']))
) {
$in_group = !empty($group['member']) && in_array($user['uid'], $group['member']);
$to_remove = in_array($group['name'], $current_groups) && !$in_group;
$to_add = !in_array($group['name'], $current_groups) && $in_group;
if ($to_remove || $to_add) {
local_group_set($group);
}
}